blob: 8448bb0c5c76a2f9f2aff49985b5d79b15df480a [file] [log] [blame]
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001/*
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
12struct 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
34void json_escape_string(char *txt, size_t maxlen, const char *data, size_t len);
35struct json_token * json_parse(const char *data, size_t data_len);
36void json_free(struct json_token *json);
37struct json_token * json_get_member(struct json_token *json, const char *name);
38struct wpabuf * json_get_member_base64url(struct json_token *json,
39 const char *name);
Hai Shalom899fcc72020-10-19 14:38:18 -070040struct wpabuf * json_get_member_base64(struct json_token *json,
41 const char *name);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070042void json_print_tree(struct json_token *root, char *buf, size_t buflen);
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -080043void json_add_int(struct wpabuf *json, const char *name, int val);
44void json_add_string(struct wpabuf *json, const char *name, const char *val);
45int json_add_string_escape(struct wpabuf *json, const char *name,
46 const void *val, size_t len);
47int json_add_base64url(struct wpabuf *json, const char *name, const void *val,
48 size_t len);
Hai Shalom899fcc72020-10-19 14:38:18 -070049int json_add_base64(struct wpabuf *json, const char *name, const void *val,
50 size_t len);
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -080051void json_start_object(struct wpabuf *json, const char *name);
52void json_end_object(struct wpabuf *json);
53void json_start_array(struct wpabuf *json, const char *name);
54void json_end_array(struct wpabuf *json);
55void json_value_sep(struct wpabuf *json);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070056
57#endif /* JSON_H */