MCPcopy Create free account
hub / github.com/ElementsProject/lightning / validate_jsmn_datum

Function validate_jsmn_datum

common/json_parse_simple.c:279–337  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

277 bool *valid);
278
279static const jsmntok_t *
280validate_jsmn_datum(const char *buf,
281 const jsmntok_t *p,
282 const jsmntok_t *end,
283 bool *valid)
284{
285 int i;
286 int sz;
287
288 if (p >= end) {
289 *valid = false;
290 return p;
291 }
292
293 switch (p->type) {
294 case JSMN_STRING:
295 if (!utf8_check(buf + p->start, p->end - p->start))
296 *valid = false;
297 /* Fall thru */
298 case JSMN_UNDEFINED:
299 case JSMN_PRIMITIVE:
300 /* These types should not have sub-datums. */
301 if (p->size != 0)
302 *valid = false;
303 else
304 ++p;
305 break;
306
307 case JSMN_ARRAY:
308 /* Save the array size; we will advance p. */
309 sz = p->size;
310 ++p;
311 for (i = 0; i < sz; ++i) {
312 /* Arrays should only contain standard JSON datums. */
313 p = validate_jsmn_datum(buf, p, end, valid);
314 if (!*valid)
315 break;
316 }
317 break;
318
319 case JSMN_OBJECT:
320 /* Save the object size; we will advance p. */
321 sz = p->size;
322 ++p;
323 for (i = 0; i < sz; ++i) {
324 /* Objects should only contain key-value pairs. */
325 p = validate_jsmn_keyvalue(buf, p, end, valid);
326 if (!*valid)
327 break;
328 }
329 break;
330
331 default:
332 *valid = false;
333 break;
334 }
335
336 return p;

Callers 2

validate_jsmn_keyvalueFunction · 0.85

Calls 2

validate_jsmn_keyvalueFunction · 0.85
utf8_checkFunction · 0.70

Tested by

no test coverage detected