Debian Codegraph @

src/json.c

raw symbols SCIP
1 /*
2 * Copyright (c) 2019-2022 Joris Vink <[email protected]>
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17 #include <sys/types.h>
18
19 #include <float.h>
20 #include <inttypes.h>
21 #include <string.h>
22 #include <stdio.h>
23 #include <stdarg.h>
24 #include <stdlib.h>
25
26 #include "kore.h"cxx . . $ `<file>/include/kore/kore.h`/
27
28 static int json_guess_typecxx . . $ json_guess_type(2127dd3082a1f0fb).(u_int8_tcxx . . $ u_int8_t#, u_int32_tcxx . . $ u_int32_t# *);
29 static int json_nextcxx . . $ json_next(7a3f60930db1c0e4).(struct kore_jsoncxx . . $ kore_json# *, u_int8_tcxx . . $ u_int8_t# *);
30 static int json_peekcxx . . $ json_peek(7a3f60930db1c0e4).(struct kore_jsoncxx . . $ kore_json# *, u_int8_tcxx . . $ u_int8_t# *);
31
32 static int json_consume_whitespacecxx . . $ json_consume_whitespace(7f47b777e6dcc5b).(struct kore_jsoncxx . . $ kore_json# *);
33 static int json_next_bytecxx . . $ json_next_byte(68753623e8e60286).(struct kore_jsoncxx . . $ kore_json# *, u_int8_tcxx . . $ u_int8_t# *, int);
34
35 static char *json_get_stringcxx . . $ json_get_string(74e3eb6578114082).(struct kore_jsoncxx . . $ kore_json# *);
36
37 static int json_parse_arraycxx . . $ json_parse_array(8b6f2731aee6cce4).(struct kore_jsoncxx . . $ kore_json# *, struct kore_json_itemcxx . . $ kore_json_item# *);
38 static int json_parse_objectcxx . . $ json_parse_object(8b6f2731aee6cce4).(struct kore_jsoncxx . . $ kore_json# *, struct kore_json_itemcxx . . $ kore_json_item# *);
39 static int json_parse_stringcxx . . $ json_parse_string(8b6f2731aee6cce4).(struct kore_jsoncxx . . $ kore_json# *, struct kore_json_itemcxx . . $ kore_json_item# *);
40 static int json_parse_numbercxx . . $ json_parse_number(8b6f2731aee6cce4).(struct kore_jsoncxx . . $ kore_json# *, struct kore_json_itemcxx . . $ kore_json_item# *);
41 static int json_parse_literalcxx . . $ json_parse_literal(8b6f2731aee6cce4).(struct kore_jsoncxx . . $ kore_json# *, struct kore_json_itemcxx . . $ kore_json_item# *);
42
43 static struct kore_json_itemcxx . . $ kore_json_item# *json_item_alloccxx . . $ json_item_alloc(a7398f0846d945ec).(int, const char *,
44 struct kore_json_itemcxx . . $ kore_json_item# *);
45 static struct kore_json_itemcxx . . $ kore_json_item# *json_find_itemcxx . . $ json_find_item(520c6557d7e76067).(struct kore_json_itemcxx . . $ kore_json_item# *,
46 char **, u_int32_tcxx . . $ u_int32_t#, int);
47
48 static u_int8_tcxx . . $ u_int8_t# json_null_literalcxx . . $ json_null_literal.[] = { 'n', 'u', 'l', 'l' };
49 static u_int8_tcxx . . $ u_int8_t# json_true_literalcxx . . $ json_true_literal.[] = { 't', 'r', 'u', 'e' };
50 static u_int8_tcxx . . $ u_int8_t# json_false_literalcxx . . $ json_false_literal.[] = { 'f', 'a', 'l', 's', 'e' };
51
52 static int json_errnocxx . . $ json_errno. = 0;
53
54 static const char *json_errtabcxx . . $ json_errtab.[] = {
55 "no error",
56 "invalid JSON object",
57 "invalid JSON array",
58 "invalid JSON string",
59 "invalid JSON number",
60 "invalid JSON literal",
61 "too many nested items",
62 "end of stream while parsing JSON",
63 "invalid JSON",
64 "invalid search query specified",
65 "item not found",
66 "item found, but not expected value"
67 };
68
69 void
70 kore_json_initcxx . . $ kore_json_init(29c4dbbde388a581).(struct kore_jsoncxx . . $ kore_json# *json, const void *data, size_t len)
71 {
72 memsetcxx . . $ memset(d1de1e4fb215f1c6).(json, 0, sizeof(*json));
73
74 json->datacxx . . $ kore_json#data. = data;
75 json->lengthcxx . . $ kore_json#length. = len;
76
77 kore_buf_initcxx . . $ kore_buf_init(bd90e0817a56138f).(&json->tmpbufcxx . . $ kore_json#tmpbuf., 1024);
78 }
79
80 int
81 kore_json_parsecxx . . $ kore_json_parse(7f47b777e6dcc5b).(struct kore_jsoncxx . . $ kore_json# *json)
82 {
83 u_int8_tcxx . . $ u_int8_t# ch;
84 u_int32_tcxx . . $ u_int32_t# type;
85
86 if (json->rootcxx . . $ kore_json#root.)
87 return (KORE_RESULT_OKcxx . . $ `include/kore/kore.h:88:9`!);
88
89 json_errnocxx . . $ json_errno. = 0;
90
91 if (json_consume_whitespacecxx . . $ json_consume_whitespace(7f47b777e6dcc5b).(json) == -1) {
92 json_errnocxx . . $ json_errno. = KORE_JSON_ERR_INVALID_JSONcxx . . $ `include/kore/kore.h:532:9`!;
93 return (KORE_RESULT_ERRORcxx . . $ `include/kore/kore.h:87:9`!);
94 }
95
96 if (!json_peekcxx . . $ json_peek(7a3f60930db1c0e4).(json, &ch))
97 return (KORE_RESULT_ERRORcxx . . $ `include/kore/kore.h:87:9`!);
98
99 if (!json_guess_typecxx . . $ json_guess_type(2127dd3082a1f0fb).(ch, &type)) {
100 json_errnocxx . . $ json_errno. = KORE_JSON_ERR_INVALID_JSONcxx . . $ `include/kore/kore.h:532:9`!;
101 return (KORE_RESULT_ERRORcxx . . $ `include/kore/kore.h:87:9`!);
102 }
103
104 json->rootcxx . . $ kore_json#root. = json_item_alloccxx . . $ json_item_alloc(a7398f0846d945ec).(type, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
105
106 if (!json->rootcxx . . $ kore_json#root.->parsecxx . . $ kore_json_item#parse.(json, json->rootcxx . . $ kore_json#root.)) {
107 if (json_errnocxx . . $ json_errno. == 0)
108 json_errnocxx . . $ json_errno. = KORE_JSON_ERR_INVALID_JSONcxx . . $ `include/kore/kore.h:532:9`!;
109 return (KORE_RESULT_ERRORcxx . . $ `include/kore/kore.h:87:9`!);
110 }
111
112 /* Don't allow garbage at the end. */
113 (void)json_consume_whitespacecxx . . $ json_consume_whitespace(7f47b777e6dcc5b).(json);
114 if (json->offsetcxx . . $ kore_json#offset. != json->lengthcxx . . $ kore_json#length.) {
115 json_errnocxx . . $ json_errno. = KORE_JSON_ERR_INVALID_JSONcxx . . $ `include/kore/kore.h:532:9`!;
116 return (KORE_RESULT_ERRORcxx . . $ `include/kore/kore.h:87:9`!);
117 }
118
119 return (KORE_RESULT_OKcxx . . $ `include/kore/kore.h:88:9`!);
120 }
121
122 struct kore_json_itemcxx . . $ kore_json_item# *
123 kore_json_findcxx . . $ kore_json_find(edf03d44faaf5b4f).(struct kore_json_itemcxx . . $ kore_json_item# *root, const char *path, u_int32_tcxx . . $ u_int32_t# type)
124 {
125 struct kore_json_itemcxx . . $ kore_json_item# *item;
126 char *copy;
127 char *tokens[KORE_JSON_DEPTH_MAXcxx . . $ `include/kore/kore.h:522:9`! + 1];
128
129 json_errnocxx . . $ json_errno. = 0;
130 copy = kore_strdupcxx . . $ kore_strdup(a8b8e32347182212).(path);
131
132 if (!kore_split_stringcxx . . $ kore_split_string(87b756e43bd5489c).(copy, "/", tokens, KORE_JSON_DEPTH_MAXcxx . . $ `include/kore/kore.h:522:9`!)) {
133 kore_freecxx . . $ kore_free(5d22bdacc48458e8).(copy);
134 json_errnocxx . . $ json_errno. = KORE_JSON_ERR_INVALID_SEARCHcxx . . $ `include/kore/kore.h:533:9`!;
135 return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
136 }
137
138 item = json_find_itemcxx . . $ json_find_item(520c6557d7e76067).(root, tokens, type, 0);
139 kore_freecxx . . $ kore_free(5d22bdacc48458e8).(copy);
140
141 if (item == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! && json_errnocxx . . $ json_errno. == 0)
142 json_errnocxx . . $ json_errno. = KORE_JSON_ERR_INVALID_SEARCHcxx . . $ `include/kore/kore.h:533:9`!;
143
144 return (item);
145 }
146
147 void
148 kore_json_cleanupcxx . . $ kore_json_cleanup(2a107dfdb700d99c).(struct kore_jsoncxx . . $ kore_json# *json)
149 {
150 if (json == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
151 return;
152
153 kore_buf_cleanupcxx . . $ kore_buf_cleanup(2648f45d13d14762).(&json->tmpbufcxx . . $ kore_json#tmpbuf.);
154 kore_json_item_freecxx . . $ kore_json_item_free(3a9ca108fc1493c6).(json->rootcxx . . $ kore_json#root.);
155 }
156
157 int
158 kore_json_errnocxx . . $ kore_json_errno(b126dc7c1de90089).(void)
159 {
160 return (json_errnocxx . . $ json_errno.);
161 }
162
163 const char *
164 kore_json_strerrorcxx . . $ kore_json_strerror(33a1f659e94feb42).(void)
165 {
166 if (json_errnocxx . . $ json_errno. >= 0 && json_errnocxx . . $ json_errno. <= KORE_JSON_ERR_LASTcxx . . $ `include/kore/kore.h:536:9`!)
167 return (json_errtabcxx . . $ json_errtab.[json_errnocxx . . $ json_errno.]);
168
169 return ("unknown JSON error");
170 }
171
172 struct kore_json_itemcxx . . $ kore_json_item# *
173 kore_json_create_itemcxx . . $ kore_json_create_item(ed6c06edfe9c06f8).(struct kore_json_itemcxx . . $ kore_json_item# *parent, const char *name,
174 u_int32_tcxx . . $ u_int32_t# type, ...)
175 {
176 const char *p;
177 va_listcxx . . $ va_list# args;
178 struct kore_json_itemcxx . . $ kore_json_item# *item;
179
180 item = kore_calloccxx . . $ kore_calloc(63a7bf2941bfcd7a).(1, sizeof(*item));
181 item->typecxx . . $ kore_json_item#type. = type;
182
183 va_startcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stdarg.h:50:9`!(args, type);
184
185 switch (item->typecxx . . $ kore_json_item#type.) {
186 case KORE_JSON_TYPE_OBJECTcxx . . $ `include/kore/kore.h:510:9`!:
187 TAILQ_INITcxx . . $ `<external>/2546723208511035544/queue.h:387:9`!(&item->data.items);
188 break;
189 case KORE_JSON_TYPE_ARRAYcxx . . $ `include/kore/kore.h:511:9`!:
190 TAILQ_INITcxx . . $ `<external>/2546723208511035544/queue.h:387:9`!(&item->data.items);
191 break;
192 case KORE_JSON_TYPE_STRINGcxx . . $ `include/kore/kore.h:512:9`!:
193 p = va_argcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stdarg.h:53:9`!(args, const char *);
194 item->datacxx . . $ kore_json_item#data..stringcxx . . $ kore_json_item#$anonymous_type_19#string. = kore_strdupcxx . . $ kore_strdup(a8b8e32347182212).(p);
195 break;
196 case KORE_JSON_TYPE_NUMBERcxx . . $ `include/kore/kore.h:513:9`!:
197 item->datacxx . . $ kore_json_item#data..numbercxx . . $ kore_json_item#$anonymous_type_19#number. = va_argcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stdarg.h:53:9`!(args, double);
198 break;
199 case KORE_JSON_TYPE_INTEGERcxx . . $ `include/kore/kore.h:515:9`!:
200 item->datacxx . . $ kore_json_item#data..integercxx . . $ kore_json_item#$anonymous_type_19#integer. = va_argcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stdarg.h:53:9`!(args, int64_t);
201 break;
202 case KORE_JSON_TYPE_INTEGER_U64cxx . . $ `include/kore/kore.h:516:9`!:
203 item->datacxx . . $ kore_json_item#data..u64cxx . . $ kore_json_item#$anonymous_type_19#u64. = va_argcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stdarg.h:53:9`!(args, u_int64_t);
204 break;
205 case KORE_JSON_TYPE_LITERALcxx . . $ `include/kore/kore.h:514:9`!:
206 item->datacxx . . $ kore_json_item#data..literalcxx . . $ kore_json_item#$anonymous_type_19#literal. = va_argcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stdarg.h:53:9`!(args, int);
207 break;
208 default:
209 fatalcxx . . $ fatal(f6bc48f0426f26ee).("%s: unknown type %d", __func__, item->typecxx . . $ kore_json_item#type.);
210 }
211
212 if (name)
213 item->namecxx . . $ kore_json_item#name. = kore_strdupcxx . . $ kore_strdup(a8b8e32347182212).(name);
214
215 if (parent) {
216 if (parent->typecxx . . $ kore_json_item#type. != KORE_JSON_TYPE_OBJECTcxx . . $ `include/kore/kore.h:510:9`! &&
217 parent->typecxx . . $ kore_json_item#type. != KORE_JSON_TYPE_ARRAYcxx . . $ `include/kore/kore.h:511:9`!) {
218 fatalcxx . . $ fatal(f6bc48f0426f26ee).("%s: invalid parent type (%d)",
219 __func__, parent->typecxx . . $ kore_json_item#type.);
220 }
221
222 TAILQ_INSERT_TAILcxx . . $ `<external>/2546723208511035544/queue.h:402:9`!(&parent->data.items, item, list);
223 }
224
225 va_endcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stdarg.h:52:9`!(args);
226
227 return (item);
228 }
229
230 void
231 kore_json_item_tobufcxx . . $ kore_json_item_tobuf(c5a4e1056fa52bf0).(struct kore_json_itemcxx . . $ kore_json_item# *item, struct kore_bufcxx . . $ kore_buf# *buf)
232 {
233 struct kore_json_itemcxx . . $ kore_json_item# *nitem;
234
235 if (item->namecxx . . $ kore_json_item#name.)
236 kore_buf_appendfcxx . . $ kore_buf_appendf(e492ffcef53d871e).(buf, "\"%s\":", item->namecxx . . $ kore_json_item#name.);
237
238 switch (item->typecxx . . $ kore_json_item#type.) {
239 case KORE_JSON_TYPE_OBJECTcxx . . $ `include/kore/kore.h:510:9`!:
240 kore_buf_appendfcxx . . $ kore_buf_appendf(e492ffcef53d871e).(buf, "{");
241 TAILQ_FOREACHcxx . . $ `<external>/2546723208511035544/queue.h:435:9`!(nitem, &item->data.items, list) {
242 kore_json_item_tobufcxx . . $ kore_json_item_tobuf(c5a4e1056fa52bf0).(nitem, buf);
243
244 if (TAILQ_NEXTcxx . . $ `<external>/2546723208511035544/queue.h:459:9`!(nitem, list))
245 kore_buf_appendfcxx . . $ kore_buf_appendf(e492ffcef53d871e).(buf, ",");
246 }
247 kore_buf_appendfcxx . . $ kore_buf_appendf(e492ffcef53d871e).(buf, "}");
248 break;
249 case KORE_JSON_TYPE_ARRAYcxx . . $ `include/kore/kore.h:511:9`!:
250 kore_buf_appendfcxx . . $ kore_buf_appendf(e492ffcef53d871e).(buf, "[");
251 TAILQ_FOREACHcxx . . $ `<external>/2546723208511035544/queue.h:435:9`!(nitem, &item->data.items, list) {
252 kore_json_item_tobufcxx . . $ kore_json_item_tobuf(c5a4e1056fa52bf0).(nitem, buf);
253
254 if (TAILQ_NEXTcxx . . $ `<external>/2546723208511035544/queue.h:459:9`!(nitem, list))
255 kore_buf_appendfcxx . . $ kore_buf_appendf(e492ffcef53d871e).(buf, ",");
256 }
257 kore_buf_appendfcxx . . $ kore_buf_appendf(e492ffcef53d871e).(buf, "]");
258 break;
259 case KORE_JSON_TYPE_STRINGcxx . . $ `include/kore/kore.h:512:9`!:
260 kore_buf_appendfcxx . . $ kore_buf_appendf(e492ffcef53d871e).(buf, "\"%s\"", item->datacxx . . $ kore_json_item#data..stringcxx . . $ kore_json_item#$anonymous_type_19#string.);
261 break;
262 case KORE_JSON_TYPE_NUMBERcxx . . $ `include/kore/kore.h:513:9`!:
263 kore_buf_appendfcxx . . $ kore_buf_appendf(e492ffcef53d871e).(buf, "%f", item->datacxx . . $ kore_json_item#data..numbercxx . . $ kore_json_item#$anonymous_type_19#number.);
264 break;
265 case KORE_JSON_TYPE_INTEGERcxx . . $ `include/kore/kore.h:515:9`!:
266 kore_buf_appendfcxx . . $ kore_buf_appendf(e492ffcef53d871e).(buf, "%" PRId64cxx . . $ `<external>/15933738808807975373/inttypes.h:57:10`!, item->datacxx . . $ kore_json_item#data..integercxx . . $ kore_json_item#$anonymous_type_19#integer.);
267 break;
268 case KORE_JSON_TYPE_INTEGER_U64cxx . . $ `include/kore/kore.h:516:9`!:
269 kore_buf_appendfcxx . . $ kore_buf_appendf(e492ffcef53d871e).(buf, "%" PRIu64cxx . . $ `<external>/15933738808807975373/inttypes.h:105:10`!, item->datacxx . . $ kore_json_item#data..u64cxx . . $ kore_json_item#$anonymous_type_19#u64.);
270 break;
271 case KORE_JSON_TYPE_LITERALcxx . . $ `include/kore/kore.h:514:9`!:
272 switch (item->datacxx . . $ kore_json_item#data..literalcxx . . $ kore_json_item#$anonymous_type_19#literal.) {
273 case KORE_JSON_TRUEcxx . . $ `include/kore/kore.h:519:9`!:
274 kore_buf_appendcxx . . $ kore_buf_append(4909ebf68ec24f4d).(buf,
275 json_true_literalcxx . . $ json_true_literal., sizeof(json_true_literalcxx . . $ json_true_literal.));
276 break;
277 case KORE_JSON_FALSEcxx . . $ `include/kore/kore.h:518:9`!:
278 kore_buf_appendcxx . . $ kore_buf_append(4909ebf68ec24f4d).(buf,
279 json_false_literalcxx . . $ json_false_literal., sizeof(json_false_literalcxx . . $ json_false_literal.));
280 break;
281 case KORE_JSON_NULLcxx . . $ `include/kore/kore.h:520:9`!:
282 kore_buf_appendcxx . . $ kore_buf_append(4909ebf68ec24f4d).(buf,
283 json_null_literalcxx . . $ json_null_literal., sizeof(json_null_literalcxx . . $ json_null_literal.));
284 break;
285 default:
286 fatalcxx . . $ fatal(f6bc48f0426f26ee).("%s: unknown literal %d", __func__,
287 item->datacxx . . $ kore_json_item#data..literalcxx . . $ kore_json_item#$anonymous_type_19#literal.);
288 }
289 break;
290 default:
291 fatalcxx . . $ fatal(f6bc48f0426f26ee).("%s: unknown type %d", __func__, item->typecxx . . $ kore_json_item#type.);
292 }
293 }
294
295 void
296 kore_json_item_attachcxx . . $ kore_json_item_attach(873d745024532c80).(struct kore_json_itemcxx . . $ kore_json_item# *parent,
297 struct kore_json_itemcxx . . $ kore_json_item# *item)
298 {
299 if (item->parentcxx . . $ kore_json_item#parent. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
300 fatalcxx . . $ fatal(f6bc48f0426f26ee).("%s: item already has parent", __func__);
301
302 item->parentcxx . . $ kore_json_item#parent. = parent;
303
304 if (parent->typecxx . . $ kore_json_item#type. != KORE_JSON_TYPE_OBJECTcxx . . $ `include/kore/kore.h:510:9`! &&
305 parent->typecxx . . $ kore_json_item#type. != KORE_JSON_TYPE_ARRAYcxx . . $ `include/kore/kore.h:511:9`!) {
306 fatalcxx . . $ fatal(f6bc48f0426f26ee).("%s: invalid parent type (%d)",
307 __func__, parent->typecxx . . $ kore_json_item#type.);
308 }
309
310 TAILQ_INSERT_TAILcxx . . $ `<external>/2546723208511035544/queue.h:402:9`!(&parent->data.items, item, list);
311 }
312
313 static struct kore_json_itemcxx . . $ kore_json_item# *
314 json_find_itemcxx . . $ json_find_item(520c6557d7e76067).(struct kore_json_itemcxx . . $ kore_json_item# *object, char **tokens,
315 u_int32_tcxx . . $ u_int32_t# type, int pos)
316 {
317 char *p, *str;
318 struct kore_json_itemcxx . . $ kore_json_item# *item, *nitem;
319 int err, idx, spot;
320
321 if (tokens[pos] == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
322 return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
323
324 if (object->typecxx . . $ kore_json_item#type. != KORE_JSON_TYPE_OBJECTcxx . . $ `include/kore/kore.h:510:9`! &&
325 object->typecxx . . $ kore_json_item#type. != KORE_JSON_TYPE_ARRAYcxx . . $ `include/kore/kore.h:511:9`!)
326 return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
327
328 if ((str = strchrcxx . . $ strchr(2050848944e00d54).(tokens[pos], '[')) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
329 *(str)++ = '\0';
330
331 if ((p = strchrcxx . . $ strchr(2050848944e00d54).(str, ']')) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
332 return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
333
334 *p = '\0';
335
336 spot = kore_strtonumcxx . . $ kore_strtonum(1c42d1a447034a9d).(str, 10, 0, USHRT_MAXcxx . . $ `<external>/67164224788392828/limits.h:113:10`!, &err);
337 if (err != KORE_RESULT_OKcxx . . $ `include/kore/kore.h:88:9`!)
338 return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
339 } else {
340 spot = -1;
341 }
342
343 item = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
344
345 TAILQ_FOREACHcxx . . $ `<external>/2546723208511035544/queue.h:435:9`!(item, &object->data.items, list) {
346 if (item->namecxx . . $ kore_json_item#name. && strcmpcxx . . $ strcmp(5ae29d726ae57f88).(item->namecxx . . $ kore_json_item#name., tokens[pos]))
347 continue;
348
349 if (item->typecxx . . $ kore_json_item#type. == KORE_JSON_TYPE_ARRAYcxx . . $ `include/kore/kore.h:511:9`! && spot != -1) {
350 idx = 0;
351 nitem = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
352 TAILQ_FOREACHcxx . . $ `<external>/2546723208511035544/queue.h:435:9`!(nitem, &item->data.items, list) {
353 if (idx++ == spot)
354 break;
355 }
356
357 if (nitem == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
358 json_errnocxx . . $ json_errno. = KORE_JSON_ERR_NOT_FOUNDcxx . . $ `include/kore/kore.h:534:9`!;
359 return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
360 }
361
362 item = nitem;
363 }
364
365 if (tokens[pos + 1] == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
366 /*
367 * If an uint64 was required and we find an item
368 * with the same name but marked as an integer check
369 * if it can be represented as a uint64.
370 *
371 * If it can, reduce the type to integer so we match
372 * on it as well.
373 */
374 if (type == KORE_JSON_TYPE_INTEGER_U64cxx . . $ `include/kore/kore.h:516:9`! &&
375 item->typecxx . . $ kore_json_item#type. == KORE_JSON_TYPE_INTEGERcxx . . $ `include/kore/kore.h:515:9`!) {
376 if (item->datacxx . . $ kore_json_item#data..integercxx . . $ kore_json_item#$anonymous_type_19#integer. >= 0)
377 type = KORE_JSON_TYPE_INTEGERcxx . . $ `include/kore/kore.h:515:9`!;
378 }
379
380 if (item->typecxx . . $ kore_json_item#type. == type)
381 return (item);
382
383 json_errnocxx . . $ json_errno. = KORE_JSON_ERR_TYPE_MISMATCHcxx . . $ `include/kore/kore.h:535:9`!;
384 return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
385 }
386
387 if (item->typecxx . . $ kore_json_item#type. == KORE_JSON_TYPE_OBJECTcxx . . $ `include/kore/kore.h:510:9`! ||
388 item->typecxx . . $ kore_json_item#type. == KORE_JSON_TYPE_ARRAYcxx . . $ `include/kore/kore.h:511:9`!) {
389 item = json_find_itemcxx . . $ json_find_item(520c6557d7e76067).(item, tokens, type, pos + 1);
390 } else {
391 item = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
392 }
393
394 break;
395 }
396
397 if (item == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! && json_errnocxx . . $ json_errno. == 0)
398 json_errnocxx . . $ json_errno. = KORE_JSON_ERR_NOT_FOUNDcxx . . $ `include/kore/kore.h:534:9`!;
399
400 return (item);
401 }
402
403 void
404 kore_json_item_freecxx . . $ kore_json_item_free(3a9ca108fc1493c6).(struct kore_json_itemcxx . . $ kore_json_item# *item)
405 {
406 struct kore_json_itemcxx . . $ kore_json_item# *node;
407
408 if (item == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
409 return;
410
411 switch (item->typecxx . . $ kore_json_item#type.) {
412 case KORE_JSON_TYPE_OBJECTcxx . . $ `include/kore/kore.h:510:9`!:
413 case KORE_JSON_TYPE_ARRAYcxx . . $ `include/kore/kore.h:511:9`!:
414 while ((node = TAILQ_FIRSTcxx . . $ `<external>/2546723208511035544/queue.h:458:9`!(&item->data.items)) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
415 TAILQ_REMOVEcxx . . $ `<external>/2546723208511035544/queue.h:426:9`!(&item->data.items, node, list);
416 kore_json_item_freecxx . . $ kore_json_item_free(3a9ca108fc1493c6).(node);
417 }
418 break;
419 case KORE_JSON_TYPE_STRINGcxx . . $ `include/kore/kore.h:512:9`!:
420 kore_freecxx . . $ kore_free(5d22bdacc48458e8).(item->datacxx . . $ kore_json_item#data..stringcxx . . $ kore_json_item#$anonymous_type_19#string.);
421 break;
422 case KORE_JSON_TYPE_NUMBERcxx . . $ `include/kore/kore.h:513:9`!:
423 case KORE_JSON_TYPE_LITERALcxx . . $ `include/kore/kore.h:514:9`!:
424 case KORE_JSON_TYPE_INTEGERcxx . . $ `include/kore/kore.h:515:9`!:
425 case KORE_JSON_TYPE_INTEGER_U64cxx . . $ `include/kore/kore.h:516:9`!:
426 break;
427 default:
428 fatalcxx . . $ fatal(f6bc48f0426f26ee).("%s: unknown type %d", __func__, item->typecxx . . $ kore_json_item#type.);
429 }
430
431 kore_freecxx . . $ kore_free(5d22bdacc48458e8).(item->namecxx . . $ kore_json_item#name.);
432 kore_freecxx . . $ kore_free(5d22bdacc48458e8).(item);
433 }
434
435 static struct kore_json_itemcxx . . $ kore_json_item# *
436 json_item_alloccxx . . $ json_item_alloc(a7398f0846d945ec).(int type, const char *name, struct kore_json_itemcxx . . $ kore_json_item# *parent)
437 {
438 struct kore_json_itemcxx . . $ kore_json_item# *item;
439
440 item = kore_calloccxx . . $ kore_calloc(63a7bf2941bfcd7a).(1, sizeof(*item));
441 item->typecxx . . $ kore_json_item#type. = type;
442 item->parentcxx . . $ kore_json_item#parent. = parent;
443
444 switch (item->typecxx . . $ kore_json_item#type.) {
445 case KORE_JSON_TYPE_OBJECTcxx . . $ `include/kore/kore.h:510:9`!:
446 TAILQ_INITcxx . . $ `<external>/2546723208511035544/queue.h:387:9`!(&item->data.items);
447 item->parsecxx . . $ kore_json_item#parse. = json_parse_objectcxx . . $ json_parse_object(8b6f2731aee6cce4).;
448 break;
449 case KORE_JSON_TYPE_ARRAYcxx . . $ `include/kore/kore.h:511:9`!:
450 TAILQ_INITcxx . . $ `<external>/2546723208511035544/queue.h:387:9`!(&item->data.items);
451 item->parsecxx . . $ kore_json_item#parse. = json_parse_arraycxx . . $ json_parse_array(8b6f2731aee6cce4).;
452 break;
453 case KORE_JSON_TYPE_STRINGcxx . . $ `include/kore/kore.h:512:9`!:
454 item->parsecxx . . $ kore_json_item#parse. = json_parse_stringcxx . . $ json_parse_string(8b6f2731aee6cce4).;
455 break;
456 case KORE_JSON_TYPE_NUMBERcxx . . $ `include/kore/kore.h:513:9`!:
457 case KORE_JSON_TYPE_INTEGERcxx . . $ `include/kore/kore.h:515:9`!:
458 case KORE_JSON_TYPE_INTEGER_U64cxx . . $ `include/kore/kore.h:516:9`!:
459 item->parsecxx . . $ kore_json_item#parse. = json_parse_numbercxx . . $ json_parse_number(8b6f2731aee6cce4).;
460 break;
461 case KORE_JSON_TYPE_LITERALcxx . . $ `include/kore/kore.h:514:9`!:
462 item->parsecxx . . $ kore_json_item#parse. = json_parse_literalcxx . . $ json_parse_literal(8b6f2731aee6cce4).;
463 break;
464 default:
465 fatalcxx . . $ fatal(f6bc48f0426f26ee).("%s: unknown type %d", __func__, item->typecxx . . $ kore_json_item#type.);
466 }
467
468 if (name)
469 item->namecxx . . $ kore_json_item#name. = kore_strdupcxx . . $ kore_strdup(a8b8e32347182212).(name);
470
471 if (parent) {
472 if (parent->typecxx . . $ kore_json_item#type. != KORE_JSON_TYPE_OBJECTcxx . . $ `include/kore/kore.h:510:9`! &&
473 parent->typecxx . . $ kore_json_item#type. != KORE_JSON_TYPE_ARRAYcxx . . $ `include/kore/kore.h:511:9`!) {
474 fatalcxx . . $ fatal(f6bc48f0426f26ee).("%s: invalid parent type (%d)",
475 __func__, parent->typecxx . . $ kore_json_item#type.);
476 }
477
478 TAILQ_INSERT_TAILcxx . . $ `<external>/2546723208511035544/queue.h:402:9`!(&parent->data.items, item, list);
479 }
480
481 return (item);
482 }
483
484 static int
485 json_peekcxx . . $ json_peek(7a3f60930db1c0e4).(struct kore_jsoncxx . . $ kore_json# *json, u_int8_tcxx . . $ u_int8_t# *ch)
486 {
487 return (json_next_bytecxx . . $ json_next_byte(68753623e8e60286).(json, ch, 1));
488 }
489
490 static int
491 json_nextcxx . . $ json_next(7a3f60930db1c0e4).(struct kore_jsoncxx . . $ kore_json# *json, u_int8_tcxx . . $ u_int8_t# *ch)
492 {
493 return (json_next_bytecxx . . $ json_next_byte(68753623e8e60286).(json, ch, 0));
494 }
495
496 static int
497 json_next_bytecxx . . $ json_next_byte(68753623e8e60286).(struct kore_jsoncxx . . $ kore_json# *json, u_int8_tcxx . . $ u_int8_t# *ch, int peek)
498 {
499 if (json->offsetcxx . . $ kore_json#offset. >= json->lengthcxx . . $ kore_json#length.) {
500 json_errnocxx . . $ json_errno. = KORE_JSON_ERR_EOFcxx . . $ `include/kore/kore.h:531:9`!;
501 return (KORE_RESULT_ERRORcxx . . $ `include/kore/kore.h:87:9`!);
502 }
503
504 *ch = json->datacxx . . $ kore_json#data.[json->offsetcxx . . $ kore_json#offset.];
505
506 if (peek == 0)
507 json->offsetcxx . . $ kore_json#offset.++;
508
509 return (KORE_RESULT_OKcxx . . $ `include/kore/kore.h:88:9`!);
510 }
511
512 static int
513 json_consume_whitespacecxx . . $ json_consume_whitespace(7f47b777e6dcc5b).(struct kore_jsoncxx . . $ kore_json# *json)
514 {
515 u_int8_tcxx . . $ u_int8_t# ch;
516
517 for (;;) {
518 if (!json_peekcxx . . $ json_peek(7a3f60930db1c0e4).(json, &ch))
519 return (KORE_RESULT_ERRORcxx . . $ `include/kore/kore.h:87:9`!);
520
521 if (ch != ' ' && ch != '\n' && ch != '\r' && ch != '\t')
522 break;
523
524 json->offsetcxx . . $ kore_json#offset.++;
525 }
526
527 return (KORE_RESULT_OKcxx . . $ `include/kore/kore.h:88:9`!);
528 }
529
530 static int
531 json_guess_typecxx . . $ json_guess_type(2127dd3082a1f0fb).(u_int8_tcxx . . $ u_int8_t# ch, u_int32_tcxx . . $ u_int32_t# *type)
532 {
533 if (ch == '-' || (ch >= '0' && ch <= '9')) {
534 *type = KORE_JSON_TYPE_NUMBERcxx . . $ `include/kore/kore.h:513:9`!;
535 return (KORE_RESULT_OKcxx . . $ `include/kore/kore.h:88:9`!);
536 }
537
538 switch (ch) {
539 case '{':
540 *type = KORE_JSON_TYPE_OBJECTcxx . . $ `include/kore/kore.h:510:9`!;
541 break;
542 case '"':
543 *type = KORE_JSON_TYPE_STRINGcxx . . $ `include/kore/kore.h:512:9`!;
544 break;
545 case '[':
546 *type = KORE_JSON_TYPE_ARRAYcxx . . $ `include/kore/kore.h:511:9`!;
547 break;
548 case 'f':
549 case 'n':
550 case 't':
551 *type = KORE_JSON_TYPE_LITERALcxx . . $ `include/kore/kore.h:514:9`!;
552 break;
553 default:
554 return (KORE_RESULT_ERRORcxx . . $ `include/kore/kore.h:87:9`!);
555 }
556
557 return (KORE_RESULT_OKcxx . . $ `include/kore/kore.h:88:9`!);
558 }
559
560 static int
561 json_parse_objectcxx . . $ json_parse_object(8b6f2731aee6cce4).(struct kore_jsoncxx . . $ kore_json# *json, struct kore_json_itemcxx . . $ kore_json_item# *object)
562 {
563 u_int8_tcxx . . $ u_int8_t# ch;
564 u_int32_tcxx . . $ u_int32_t# type;
565 char *key;
566 struct kore_json_itemcxx . . $ kore_json_item# *item;
567 int ret, hasnext;
568
569 if (json->depthcxx . . $ kore_json#depth.++ >= KORE_JSON_DEPTH_MAXcxx . . $ `include/kore/kore.h:522:9`!) {
570 json_errnocxx . . $ json_errno. = KORE_JSON_ERR_DEPTHcxx . . $ `include/kore/kore.h:530:9`!;
571 return (KORE_RESULT_ERRORcxx . . $ `include/kore/kore.h:87:9`!);
572 }
573
574 key = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
575 hasnext = 0;
576 ret = KORE_RESULT_ERRORcxx . . $ `include/kore/kore.h:87:9`!;
577
578 if (!json_nextcxx . . $ json_next(7a3f60930db1c0e4).(json, &ch))
579 goto cleanup;
580
581 if (ch != '{')
582 goto cleanup;
583
584 for (;;) {
585 if (!json_consume_whitespacecxx . . $ json_consume_whitespace(7f47b777e6dcc5b).(json))
586 goto cleanup;
587
588 if (!json_peekcxx . . $ json_peek(7a3f60930db1c0e4).(json, &ch))
589 goto cleanup;
590
591 switch (ch) {
592 case '}':
593 if (hasnext) {
594 json_errnocxx . . $ json_errno. = KORE_JSON_ERR_INVALID_JSONcxx . . $ `include/kore/kore.h:532:9`!;
595 goto cleanup;
596 }
597 json->offsetcxx . . $ kore_json#offset.++;
598 ret = KORE_RESULT_OKcxx . . $ `include/kore/kore.h:88:9`!;
599 goto cleanup;
600 case '"':
601 if ((key = json_get_stringcxx . . $ json_get_string(74e3eb6578114082).(json)) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
602 goto cleanup;
603 break;
604 default:
605 goto cleanup;
606 }
607
608 if (!json_consume_whitespacecxx . . $ json_consume_whitespace(7f47b777e6dcc5b).(json))
609 goto cleanup;
610
611 if (!json_nextcxx . . $ json_next(7a3f60930db1c0e4).(json, &ch))
612 goto cleanup;
613
614 if (ch != ':')
615 goto cleanup;
616
617 if (!json_consume_whitespacecxx . . $ json_consume_whitespace(7f47b777e6dcc5b).(json))
618 goto cleanup;
619
620 if (!json_peekcxx . . $ json_peek(7a3f60930db1c0e4).(json, &ch))
621 goto cleanup;
622
623 if (!json_guess_typecxx . . $ json_guess_type(2127dd3082a1f0fb).(ch, &type))
624 goto cleanup;
625
626 item = json_item_alloccxx . . $ json_item_alloc(a7398f0846d945ec).(type, key, object);
627
628 if (!item->parsecxx . . $ kore_json_item#parse.(json, item))
629 goto cleanup;
630
631 key = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
632
633 if (!json_consume_whitespacecxx . . $ json_consume_whitespace(7f47b777e6dcc5b).(json))
634 goto cleanup;
635
636 if (!json_nextcxx . . $ json_next(7a3f60930db1c0e4).(json, &ch))
637 goto cleanup;
638
639 if (ch == ',') {
640 hasnext = 1;
641 continue;
642 }
643
644 if (ch == '}') {
645 ret = KORE_RESULT_OKcxx . . $ `include/kore/kore.h:88:9`!;
646 break;
647 }
648
649 break;
650 }
651
652 cleanup:
653 if (ret == KORE_RESULT_ERRORcxx . . $ `include/kore/kore.h:87:9`! && json_errnocxx . . $ json_errno. == 0)
654 json_errnocxx . . $ json_errno. = KORE_JSON_ERR_INVALID_OBJECTcxx . . $ `include/kore/kore.h:525:9`!;
655
656 json->depthcxx . . $ kore_json#depth.--;
657
658 return (ret);
659 }
660
661 static int
662 json_parse_arraycxx . . $ json_parse_array(8b6f2731aee6cce4).(struct kore_jsoncxx . . $ kore_json# *json, struct kore_json_itemcxx . . $ kore_json_item# *array)
663 {
664 u_int8_tcxx . . $ u_int8_t# ch;
665 u_int32_tcxx . . $ u_int32_t# type;
666 char *key;
667 struct kore_json_itemcxx . . $ kore_json_item# *item;
668 int ret, hasnext;
669
670 if (json->depthcxx . . $ kore_json#depth.++ >= KORE_JSON_DEPTH_MAXcxx . . $ `include/kore/kore.h:522:9`!) {
671 json_errnocxx . . $ json_errno. = KORE_JSON_ERR_DEPTHcxx . . $ `include/kore/kore.h:530:9`!;
672 return (KORE_RESULT_ERRORcxx . . $ `include/kore/kore.h:87:9`!);
673 }
674
675 key = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
676 hasnext = 0;
677 ret = KORE_RESULT_ERRORcxx . . $ `include/kore/kore.h:87:9`!;
678
679 if (!json_nextcxx . . $ json_next(7a3f60930db1c0e4).(json, &ch))
680 goto cleanup;
681
682 if (ch != '[')
683 goto cleanup;
684
685 for (;;) {
686 if (!json_consume_whitespacecxx . . $ json_consume_whitespace(7f47b777e6dcc5b).(json))
687 goto cleanup;
688
689 if (!json_peekcxx . . $ json_peek(7a3f60930db1c0e4).(json, &ch))
690 goto cleanup;
691
692 if (ch == ']') {
693 if (hasnext) {
694 json_errnocxx . . $ json_errno. = KORE_JSON_ERR_INVALID_JSONcxx . . $ `include/kore/kore.h:532:9`!;
695 goto cleanup;
696 }
697 json->offsetcxx . . $ kore_json#offset.++;
698 ret = KORE_RESULT_OKcxx . . $ `include/kore/kore.h:88:9`!;
699 goto cleanup;
700 }
701
702 if (!json_guess_typecxx . . $ json_guess_type(2127dd3082a1f0fb).(ch, &type))
703 goto cleanup;
704
705 item = json_item_alloccxx . . $ json_item_alloc(a7398f0846d945ec).(type, key, array);
706
707 if (!item->parsecxx . . $ kore_json_item#parse.(json, item))
708 goto cleanup;
709
710 key = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
711
712 if (!json_consume_whitespacecxx . . $ json_consume_whitespace(7f47b777e6dcc5b).(json))
713 goto cleanup;
714
715 if (!json_nextcxx . . $ json_next(7a3f60930db1c0e4).(json, &ch))
716 goto cleanup;
717
718 if (ch == ',') {
719 hasnext = 1;
720 continue;
721 }
722
723 if (ch == ']') {
724 ret = KORE_RESULT_OKcxx . . $ `include/kore/kore.h:88:9`!;
725 break;
726 }
727
728 break;
729 }
730
731 cleanup:
732 if (ret == KORE_RESULT_ERRORcxx . . $ `include/kore/kore.h:87:9`! && json_errnocxx . . $ json_errno. == 0)
733 json_errnocxx . . $ json_errno. = KORE_JSON_ERR_INVALID_ARRAYcxx . . $ `include/kore/kore.h:526:9`!;
734
735 json->depthcxx . . $ kore_json#depth.--;
736
737 return (ret);
738 }
739
740 static int
741 json_parse_stringcxx . . $ json_parse_string(8b6f2731aee6cce4).(struct kore_jsoncxx . . $ kore_json# *json, struct kore_json_itemcxx . . $ kore_json_item# *string)
742 {
743 char *value;
744
745 if ((value = json_get_stringcxx . . $ json_get_string(74e3eb6578114082).(json)) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
746 return (KORE_RESULT_ERRORcxx . . $ `include/kore/kore.h:87:9`!);
747
748 string->typecxx . . $ kore_json_item#type. = KORE_JSON_TYPE_STRINGcxx . . $ `include/kore/kore.h:512:9`!;
749 string->datacxx . . $ kore_json_item#data..stringcxx . . $ kore_json_item#$anonymous_type_19#string. = kore_strdupcxx . . $ kore_strdup(a8b8e32347182212).(value);
750
751 return (KORE_RESULT_OKcxx . . $ `include/kore/kore.h:88:9`!);
752 }
753
754 static int
755 json_parse_numbercxx . . $ json_parse_number(8b6f2731aee6cce4).(struct kore_jsoncxx . . $ kore_json# *json, struct kore_json_itemcxx . . $ kore_json_item# *number)
756 {
757 u_int8_tcxx . . $ u_int8_t# ch;
758 int ret;
759 char *str;
760 u_int32_tcxx . . $ u_int32_t# type;
761
762 str = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
763 ret = KORE_RESULT_ERRORcxx . . $ `include/kore/kore.h:87:9`!;
764 kore_buf_resetcxx . . $ kore_buf_reset(2648f45d13d14762).(&json->tmpbufcxx . . $ kore_json#tmpbuf.);
765
766 type = KORE_JSON_TYPE_NUMBERcxx . . $ `include/kore/kore.h:513:9`! | KORE_JSON_TYPE_INTEGERcxx . . $ `include/kore/kore.h:515:9`! |
767 KORE_JSON_TYPE_INTEGER_U64cxx . . $ `include/kore/kore.h:516:9`!;
768
769 for (;;) {
770 if (!json_peekcxx . . $ json_peek(7a3f60930db1c0e4).(json, &ch))
771 break;
772
773 switch (ch) {
774 case 'e':
775 case 'E':
776 case '.':
777 type = KORE_JSON_TYPE_NUMBERcxx . . $ `include/kore/kore.h:513:9`!;
778 kore_buf_appendcxx . . $ kore_buf_append(4909ebf68ec24f4d).(&json->tmpbufcxx . . $ kore_json#tmpbuf., &ch, sizeof(ch));
779 json->offsetcxx . . $ kore_json#offset.++;
780 continue;
781 case '-':
782 if (json->tmpbufcxx . . $ kore_json#tmpbuf..offsetcxx . . $ kore_buf#offset. != 0)
783 goto cleanup;
784 type &= ~KORE_JSON_TYPE_INTEGER_U64cxx . . $ `include/kore/kore.h:516:9`!;
785 /* FALLTHROUGH */
786 case '0':
787 case '1':
788 case '2':
789 case '3':
790 case '4':
791 case '5':
792 case '6':
793 case '7':
794 case '8':
795 case '9':
796 case '+':
797 kore_buf_appendcxx . . $ kore_buf_append(4909ebf68ec24f4d).(&json->tmpbufcxx . . $ kore_json#tmpbuf., &ch, sizeof(ch));
798 json->offsetcxx . . $ kore_json#offset.++;
799 continue;
800 }
801
802 break;
803 }
804
805 if (type & KORE_JSON_TYPE_INTEGER_U64cxx . . $ `include/kore/kore.h:516:9`!)
806 type = KORE_JSON_TYPE_INTEGER_U64cxx . . $ `include/kore/kore.h:516:9`!;
807
808 if (type & KORE_JSON_TYPE_INTEGERcxx . . $ `include/kore/kore.h:515:9`!)
809 type = KORE_JSON_TYPE_INTEGERcxx . . $ `include/kore/kore.h:515:9`!;
810
811 str = kore_buf_stringifycxx . . $ kore_buf_stringify(4bc5b263e10e2f7b).(&json->tmpbufcxx . . $ kore_json#tmpbuf., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
812
813 switch (type) {
814 case KORE_JSON_TYPE_NUMBERcxx . . $ `include/kore/kore.h:513:9`!:
815 number->datacxx . . $ kore_json_item#data..numbercxx . . $ kore_json_item#$anonymous_type_19#number. =
816 kore_strtodoublecxx . . $ kore_strtodouble(bb8c3842a270ac85).(str, -DBL_MAXcxx . . $ `<external>/18143172452841944454/float.h:105:9`!, DBL_MAXcxx . . $ `<external>/18143172452841944454/float.h:105:9`!, &ret);
817 break;
818 case KORE_JSON_TYPE_INTEGERcxx . . $ `include/kore/kore.h:515:9`!:
819 number->datacxx . . $ kore_json_item#data..integercxx . . $ kore_json_item#$anonymous_type_19#integer. = (int64_tcxx . . $ int64_t#)kore_strtonum64cxx . . $ kore_strtonum64(6aece162c3872803).(str, 1, &ret);
820 break;
821 case KORE_JSON_TYPE_INTEGER_U64cxx . . $ `include/kore/kore.h:516:9`!:
822 number->datacxx . . $ kore_json_item#data..u64cxx . . $ kore_json_item#$anonymous_type_19#u64. = kore_strtonum64cxx . . $ kore_strtonum64(6aece162c3872803).(str, 0, &ret);
823 if (number->datacxx . . $ kore_json_item#data..u64cxx . . $ kore_json_item#$anonymous_type_19#u64. <= INT64_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:113:10`!) {
824 type = KORE_JSON_TYPE_INTEGERcxx . . $ `include/kore/kore.h:515:9`!;
825 number->datacxx . . $ kore_json_item#data..integercxx . . $ kore_json_item#$anonymous_type_19#integer. = number->datacxx . . $ kore_json_item#data..u64cxx . . $ kore_json_item#$anonymous_type_19#u64.;
826 }
827 break;
828 default:
829 goto cleanup;
830 }
831
832 number->typecxx . . $ kore_json_item#type. = type;
833
834 cleanup:
835 if (ret == KORE_RESULT_ERRORcxx . . $ `include/kore/kore.h:87:9`! && json_errnocxx . . $ json_errno. == 0)
836 json_errnocxx . . $ json_errno. = KORE_JSON_ERR_INVALID_NUMBERcxx . . $ `include/kore/kore.h:528:9`!;
837
838 return (ret);
839 }
840
841 static int
842 json_parse_literalcxx . . $ json_parse_literal(8b6f2731aee6cce4).(struct kore_jsoncxx . . $ kore_json# *json, struct kore_json_itemcxx . . $ kore_json_item# *literal)
843 {
844 size_t len, idx;
845 int ret, val;
846 u_int8_tcxx . . $ u_int8_t# ch, *tmpl;
847
848 ret = KORE_RESULT_ERRORcxx . . $ `include/kore/kore.h:87:9`!;
849
850 if (!json_nextcxx . . $ json_next(7a3f60930db1c0e4).(json, &ch))
851 goto cleanup;
852
853 switch (ch) {
854 case 'f':
855 val = KORE_JSON_FALSEcxx . . $ `include/kore/kore.h:518:9`!;
856 tmpl = json_false_literalcxx . . $ json_false_literal.;
857 len = sizeof(json_false_literalcxx . . $ json_false_literal.) - 1;
858 break;
859 case 'n':
860 val = KORE_JSON_NULLcxx . . $ `include/kore/kore.h:520:9`!;
861 tmpl = json_null_literalcxx . . $ json_null_literal.;
862 len = sizeof(json_null_literalcxx . . $ json_null_literal.) - 1;
863 break;
864 case 't':
865 val = KORE_JSON_TRUEcxx . . $ `include/kore/kore.h:519:9`!;
866 tmpl = json_true_literalcxx . . $ json_true_literal.;
867 len = sizeof(json_true_literalcxx . . $ json_true_literal.) - 1;
868 break;
869 default:
870 goto cleanup;
871 }
872
873 for (idx = 0; idx < len; idx++) {
874 if (!json_nextcxx . . $ json_next(7a3f60930db1c0e4).(json, &ch))
875 goto cleanup;
876
877 if (ch != tmpl[idx + 1])
878 goto cleanup;
879 }
880
881 literal->datacxx . . $ kore_json_item#data..literalcxx . . $ kore_json_item#$anonymous_type_19#literal. = val;
882 literal->typecxx . . $ kore_json_item#type. = KORE_JSON_TYPE_LITERALcxx . . $ `include/kore/kore.h:514:9`!;
883
884 ret = KORE_RESULT_OKcxx . . $ `include/kore/kore.h:88:9`!;
885
886 cleanup:
887 if (ret == KORE_RESULT_ERRORcxx . . $ `include/kore/kore.h:87:9`! && json_errnocxx . . $ json_errno. == 0)
888 json_errnocxx . . $ json_errno. = KORE_JSON_ERR_INVALID_LITERALcxx . . $ `include/kore/kore.h:529:9`!;
889
890 return (ret);
891 }
892
893 static char *
894 json_get_stringcxx . . $ json_get_string(74e3eb6578114082).(struct kore_jsoncxx . . $ kore_json# *json)
895 {
896 u_int8_tcxx . . $ u_int8_t# ch;
897 char *res;
898
899 res = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
900
901 if (!json_nextcxx . . $ json_next(7a3f60930db1c0e4).(json, &ch))
902 goto cleanup;
903
904 if (ch != '"')
905 goto cleanup;
906
907 kore_buf_resetcxx . . $ kore_buf_reset(2648f45d13d14762).(&json->tmpbufcxx . . $ kore_json#tmpbuf.);
908
909 for (;;) {
910 if (!json_nextcxx . . $ json_next(7a3f60930db1c0e4).(json, &ch))
911 goto cleanup;
912
913 if (ch == '"')
914 break;
915
916 if (ch <= 0x1f)
917 goto cleanup;
918
919 if (ch == '\\') {
920 if (!json_nextcxx . . $ json_next(7a3f60930db1c0e4).(json, &ch))
921 goto cleanup;
922
923 switch (ch) {
924 case '\"':
925 case '\\':
926 case '/':
927 break;
928 case 'b':
929 ch = '\b';
930 break;
931 case 'f':
932 ch = '\f';
933 break;
934 case 'n':
935 ch = '\n';
936 break;
937 case 'r':
938 ch = '\r';
939 break;
940 case 't':
941 ch = '\t';
942 break;
943 case 'u':
944 default:
945 /* XXX - not supported. */
946 goto cleanup;
947 }
948 }
949
950 kore_buf_appendcxx . . $ kore_buf_append(4909ebf68ec24f4d).(&json->tmpbufcxx . . $ kore_json#tmpbuf., &ch, sizeof(ch));
951 }
952
953 res = kore_buf_stringifycxx . . $ kore_buf_stringify(4bc5b263e10e2f7b).(&json->tmpbufcxx . . $ kore_json#tmpbuf., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
954
955 cleanup:
956 if (res == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! && json_errnocxx . . $ json_errno. == 0)
957 json_errnocxx . . $ json_errno. = KORE_JSON_ERR_INVALID_STRINGcxx . . $ `include/kore/kore.h:527:9`!;
958
959 return (res);
960 }