| 480 | } |
| 481 | |
| 482 | static 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 | |
| 511 | static struct rune_restr *rune_restr_from_json(struct command *cmd, |
| 512 | const tal_t *ctx, |
no test coverage detected