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