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

Function validate_jsmn_datum

common/json_parse_simple.c:369–427  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

367 bool *valid);
368
369static const jsmntok_t *
370validate_jsmn_datum(const char *buf,
371 const jsmntok_t *p,
372 const jsmntok_t *end,
373 bool *valid)
374{
375 int i;
376 int sz;
377
378 if (p >= end) {
379 *valid = false;
380 return p;
381 }
382
383 switch (p->type) {
384 case JSMN_STRING:
385 if (!utf8_check(buf + p->start, p->end - p->start))
386 *valid = false;
387 /* Fall thru */
388 case JSMN_UNDEFINED:
389 case JSMN_PRIMITIVE:
390 /* These types should not have sub-datums. */
391 if (p->size != 0)
392 *valid = false;
393 else
394 ++p;
395 break;
396
397 case JSMN_ARRAY:
398 /* Save the array size; we will advance p. */
399 sz = p->size;
400 ++p;
401 for (i = 0; i < sz; ++i) {
402 /* Arrays should only contain standard JSON datums. */
403 p = validate_jsmn_datum(buf, p, end, valid);
404 if (!*valid)
405 break;
406 }
407 break;
408
409 case JSMN_OBJECT:
410 /* Save the object size; we will advance p. */
411 sz = p->size;
412 ++p;
413 for (i = 0; i < sz; ++i) {
414 /* Objects should only contain key-value pairs. */
415 p = validate_jsmn_keyvalue(buf, p, end, valid);
416 if (!*valid)
417 break;
418 }
419 break;
420
421 default:
422 *valid = false;
423 break;
424 }
425
426 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