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