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

Function json_parse_input

common/json_parse_simple.c:540–585  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

538}
539
540bool json_parse_input(jsmn_parser *parser,
541 jsmntok_t **toks,
542 const char *input, int len,
543 bool *complete)
544{
545 int ret;
546
547again:
548 ret = jsmn_parse(parser, input, len, *toks, tal_count(*toks) - 1);
549 if (ret == JSMN_ERROR_INVAL)
550 return false;
551
552 /* Check whether we read at least one full root element, i.e., root
553 * element has its end set. */
554 if ((*toks)[0].type == JSMN_UNDEFINED || (*toks)[0].end == -1) {
555 /* If it ran out of tokens, provide more. */
556 if (ret == JSMN_ERROR_NOMEM) {
557 tal_resize(toks, tal_count(*toks) * 2);
558 goto again;
559 }
560 /* Otherwise, must be incomplete */
561 *complete = false;
562 return true;
563 }
564
565 /* If we read a partial element at the end of the stream we'll get a
566 * errro, but due to the previous check we know we read at
567 * least one full element, so count tokens that are part of this root
568 * element. Bound the nesting depth here, before any recursive walk. */
569 size_t datumlen;
570 if (!bounded_datum_len(*toks, &datumlen))
571 return false;
572 ret = datumlen;
573
574 if (!validate_jsmn_parse_output(input, *toks, *toks + ret))
575 return false;
576
577 /* Cut to length and return. */
578 tal_resize(toks, ret + 1);
579 /* Make sure last one is always referenceable. */
580 (*toks)[ret].type = -1;
581 (*toks)[ret].start = (*toks)[ret].end = (*toks)[ret].size = 0;
582
583 *complete = true;
584 return true;
585}
586
587jsmntok_t *json_parse_simple(const tal_t *ctx, const char *input, int len)
588{

Callers 8

test_json_filterFunction · 0.85
test_json_streamFunction · 0.85
json_parse_simpleFunction · 0.85
jsonrpc_io_parseFunction · 0.85
mainFunction · 0.85
test_json_tok_sizeFunction · 0.85
jsonrpc_request_syncFunction · 0.85

Calls 2

bounded_datum_lenFunction · 0.85

Tested by 5

test_json_filterFunction · 0.68
test_json_streamFunction · 0.68
mainFunction · 0.68
test_json_tok_sizeFunction · 0.68
jsonrpc_request_syncFunction · 0.68