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

Function json_parse_input

common/json_parse_simple.c:450–492  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

448}
449
450bool json_parse_input(jsmn_parser *parser,
451 jsmntok_t **toks,
452 const char *input, int len,
453 bool *complete)
454{
455 int ret;
456
457again:
458 ret = jsmn_parse(parser, input, len, *toks, tal_count(*toks) - 1);
459
460 switch (ret) {
461 case JSMN_ERROR_INVAL:
462 return false;
463 case JSMN_ERROR_NOMEM:
464 tal_resize(toks, tal_count(*toks) * 2);
465 goto again;
466 }
467
468 /* Check whether we read at least one full root element, i.e., root
469 * element has its end set. */
470 if ((*toks)[0].type == JSMN_UNDEFINED || (*toks)[0].end == -1) {
471 *complete = false;
472 return true;
473 }
474
475 /* If we read a partial element at the end of the stream we'll get a
476 * ret=JSMN_ERROR_PART, but due to the previous check we know we read at
477 * least one full element, so count tokens that are part of this root
478 * element. */
479 ret = json_next(*toks) - *toks;
480
481 if (!validate_jsmn_parse_output(input, *toks, *toks + ret))
482 return false;
483
484 /* Cut to length and return. */
485 tal_resize(toks, ret + 1);
486 /* Make sure last one is always referenceable. */
487 (*toks)[ret].type = -1;
488 (*toks)[ret].start = (*toks)[ret].end = (*toks)[ret].size = 0;
489
490 *complete = true;
491 return true;
492}
493
494jsmntok_t *json_parse_simple(const tal_t *ctx, const char *input, int len)
495{

Callers 6

json_parse_simpleFunction · 0.70
plugin_read_json_oneFunction · 0.50
read_jsonFunction · 0.50
test_json_filterFunction · 0.50
test_json_streamFunction · 0.50
test_json_tok_sizeFunction · 0.50

Calls 2

json_nextFunction · 0.70

Tested by 3

test_json_filterFunction · 0.40
test_json_streamFunction · 0.40
test_json_tok_sizeFunction · 0.40