xref: /dflybsd-src/contrib/wpa_supplicant/src/utils/json.h (revision 3a84a4273475ed07d0ab1c2dfeffdfedef35d9cd)
1*a1157835SDaniel Fojt /*
2*a1157835SDaniel Fojt  * JavaScript Object Notation (JSON) parser (RFC7159)
3*a1157835SDaniel Fojt  * Copyright (c) 2017, Qualcomm Atheros, Inc.
4*a1157835SDaniel Fojt  *
5*a1157835SDaniel Fojt  * This software may be distributed under the terms of the BSD license.
6*a1157835SDaniel Fojt  * See README for more details.
7*a1157835SDaniel Fojt  */
8*a1157835SDaniel Fojt 
9*a1157835SDaniel Fojt #ifndef JSON_H
10*a1157835SDaniel Fojt #define JSON_H
11*a1157835SDaniel Fojt 
12*a1157835SDaniel Fojt struct json_token {
13*a1157835SDaniel Fojt 	enum json_type {
14*a1157835SDaniel Fojt 		JSON_VALUE,
15*a1157835SDaniel Fojt 		JSON_OBJECT,
16*a1157835SDaniel Fojt 		JSON_ARRAY,
17*a1157835SDaniel Fojt 		JSON_STRING,
18*a1157835SDaniel Fojt 		JSON_NUMBER,
19*a1157835SDaniel Fojt 		JSON_BOOLEAN,
20*a1157835SDaniel Fojt 		JSON_NULL,
21*a1157835SDaniel Fojt 	} type;
22*a1157835SDaniel Fojt 	enum json_parsing_state {
23*a1157835SDaniel Fojt 		JSON_EMPTY,
24*a1157835SDaniel Fojt 		JSON_STARTED,
25*a1157835SDaniel Fojt 		JSON_WAITING_VALUE,
26*a1157835SDaniel Fojt 		JSON_COMPLETED,
27*a1157835SDaniel Fojt 	} state;
28*a1157835SDaniel Fojt 	char *name;
29*a1157835SDaniel Fojt 	char *string;
30*a1157835SDaniel Fojt 	int number;
31*a1157835SDaniel Fojt 	struct json_token *parent, *child, *sibling;
32*a1157835SDaniel Fojt };
33*a1157835SDaniel Fojt 
34*a1157835SDaniel Fojt void json_escape_string(char *txt, size_t maxlen, const char *data, size_t len);
35*a1157835SDaniel Fojt struct json_token * json_parse(const char *data, size_t data_len);
36*a1157835SDaniel Fojt void json_free(struct json_token *json);
37*a1157835SDaniel Fojt struct json_token * json_get_member(struct json_token *json, const char *name);
38*a1157835SDaniel Fojt struct wpabuf * json_get_member_base64url(struct json_token *json,
39*a1157835SDaniel Fojt 					  const char *name);
40*a1157835SDaniel Fojt void json_print_tree(struct json_token *root, char *buf, size_t buflen);
41*a1157835SDaniel Fojt 
42*a1157835SDaniel Fojt #endif /* JSON_H */
43