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

Function json_parse_input

common/json_parse_simple.c:493–535  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

491}
492
493bool json_parse_input(jsmn_parser *parser,
494 jsmntok_t **toks,
495 const char *input, int len,
496 bool *complete)
497{
498 int ret;
499
500again:
501 ret = jsmn_parse(parser, input, len, *toks, tal_count(*toks) - 1);
502 if (ret == JSMN_ERROR_INVAL)
503 return false;
504
505 /* Check whether we read at least one full root element, i.e., root
506 * element has its end set. */
507 if ((*toks)[0].type == JSMN_UNDEFINED || (*toks)[0].end == -1) {
508 /* If it ran out of tokens, provide more. */
509 if (ret == JSMN_ERROR_NOMEM) {
510 tal_resize(toks, tal_count(*toks) * 2);
511 goto again;
512 }
513 /* Otherwise, must be incomplete */
514 *complete = false;
515 return true;
516 }
517
518 /* If we read a partial element at the end of the stream we'll get a
519 * errro, but due to the previous check we know we read at
520 * least one full element, so count tokens that are part of this root
521 * element. */
522 ret = json_next(*toks) - *toks;
523
524 if (!validate_jsmn_parse_output(input, *toks, *toks + ret))
525 return false;
526
527 /* Cut to length and return. */
528 tal_resize(toks, ret + 1);
529 /* Make sure last one is always referenceable. */
530 (*toks)[ret].type = -1;
531 (*toks)[ret].start = (*toks)[ret].end = (*toks)[ret].size = 0;
532
533 *complete = true;
534 return true;
535}
536
537jsmntok_t *json_parse_simple(const tal_t *ctx, const char *input, int len)
538{

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

json_nextFunction · 0.70

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