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