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

Function rune_altern_from_json

lightningd/runes.c:482–509  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

480}
481
482static struct rune_altern *rune_altern_from_json(const tal_t *ctx,
483 const char *buffer,
484 const jsmntok_t *tok)
485{
486 struct rune_altern *alt;
487 size_t condoff;
488 /* We still need to unescape here, for \\ -> \. JSON doesn't
489 * allow unnecessary \ */
490 const char *unescape;
491 unescape = json_escape_unescape_len(tmpctx, buffer + tok->start,
492 tok->end - tok->start);
493 if (!unescape)
494 return NULL;
495
496 condoff = rune_altern_fieldname_len(unescape, strlen(unescape));
497 if (!rune_condition_is_valid(unescape[condoff]))
498 return NULL;
499
500 alt = tal(ctx, struct rune_altern);
501 alt->fieldname = tal_strndup(alt, unescape, condoff);
502 alt->condition = unescape[condoff];
503 alt->value = tal_strdup(alt, unescape + condoff + 1);
504
505 /* don't let them add empty fieldnames */
506 if (streq(alt->fieldname, ""))
507 return tal_free(alt);
508 return alt;
509}
510
511static struct rune_restr *rune_restr_from_json(struct command *cmd,
512 const tal_t *ctx,

Callers 1

rune_restr_from_jsonFunction · 0.85

Calls 4

json_escape_unescape_lenFunction · 0.85
rune_condition_is_validFunction · 0.85
tal_freeFunction · 0.85

Tested by

no test coverage detected