1 /*
2  * Copyright (C) 2019-2021 Nicola Di Lieto <nicola.dilieto@gmail.com>
3  *
4  * This file is part of uacme.
5  *
6  * uacme is free software: you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * uacme is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see
18  * <http://www.gnu.org/licenses/>.
19  */
20 
21 #ifndef __JSON_H__
22 #define __JSON_H__
23 
24 typedef enum {
25     JSON_UNDEFINED = 0,
26     JSON_OBJECT = 1,
27     JSON_ARRAY = 2,
28     JSON_STRING = 3,
29     JSON_PRIMITIVE = 4
30 } json_type_t;
31 
32 struct json_value;
33 
34 typedef struct json_object {
35     size_t size;
36     struct json_value *names;
37     struct json_value *values;
38 } json_object_t;
39 
40 typedef struct json_array {
41     size_t size;
42     struct json_value *values;
43 } json_array_t;
44 
45 typedef struct json_value {
46     json_type_t type;
47     union
48     {
49         json_object_t object;
50         json_array_t array;
51         char *value;
52     } v;
53     struct json_value *parent;
54 } json_value_t;
55 
56 json_value_t *json_parse(const char *body, size_t body_len);
57 void json_dump(FILE *f, const json_value_t *value);
58 void json_free(json_value_t *value);
59 const json_value_t *json_find(const json_value_t *haystack,
60         const char *needle);
61 const char *json_find_value(const json_value_t *haystack,
62         const char *needle);
63 const char *json_find_string(const json_value_t *haystack,
64         const char *needle);
65 int json_compare_string(const json_value_t *haystack,
66         const char *name, const char *value);
67 
68 #endif
69 
70