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

Function validate_jsmn_datum

common/json_parse_simple.c:322–380  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

320 bool *valid);
321
322static const jsmntok_t *
323validate_jsmn_datum(const char *buf,
324 const jsmntok_t *p,
325 const jsmntok_t *end,
326 bool *valid)
327{
328 int i;
329 int sz;
330
331 if (p >= end) {
332 *valid = false;
333 return p;
334 }
335
336 switch (p->type) {
337 case JSMN_STRING:
338 if (!utf8_check(buf + p->start, p->end - p->start))
339 *valid = false;
340 /* Fall thru */
341 case JSMN_UNDEFINED:
342 case JSMN_PRIMITIVE:
343 /* These types should not have sub-datums. */
344 if (p->size != 0)
345 *valid = false;
346 else
347 ++p;
348 break;
349
350 case JSMN_ARRAY:
351 /* Save the array size; we will advance p. */
352 sz = p->size;
353 ++p;
354 for (i = 0; i < sz; ++i) {
355 /* Arrays should only contain standard JSON datums. */
356 p = validate_jsmn_datum(buf, p, end, valid);
357 if (!*valid)
358 break;
359 }
360 break;
361
362 case JSMN_OBJECT:
363 /* Save the object size; we will advance p. */
364 sz = p->size;
365 ++p;
366 for (i = 0; i < sz; ++i) {
367 /* Objects should only contain key-value pairs. */
368 p = validate_jsmn_keyvalue(buf, p, end, valid);
369 if (!*valid)
370 break;
371 }
372 break;
373
374 default:
375 *valid = false;
376 break;
377 }
378
379 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