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 esp_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 void json_add_int(struct wpabuf *json, const char *name, int val); 42 void json_add_string(struct wpabuf *json, const char *name, const char *val); 43 int json_add_string_escape(struct wpabuf *json, const char *name, 44 const void *val, size_t len); 45 int json_add_base64url(struct wpabuf *json, const char *name, const void *val, 46 size_t len); 47 void json_start_object(struct wpabuf *json, const char *name); 48 void json_end_object(struct wpabuf *json); 49 void json_start_array(struct wpabuf *json, const char *name); 50 void json_end_array(struct wpabuf *json); 51 void json_value_sep(struct wpabuf *json); 52 53 #endif /* JSON_H */ 54