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

Function check_condition

lightningd/runes.c:821–906  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

819}
820
821static const char *check_condition(const tal_t *ctx,
822 const struct rune *rune,
823 const struct rune_altern *alt,
824 struct cond_info *cinfo)
825{
826 const jsmntok_t *ptok;
827
828 if (streq(alt->fieldname, "time")) {
829 return rune_alt_single_int(ctx, alt, cinfo->now.ts.tv_sec);
830 } else if (streq(alt->fieldname, "id")) {
831 if (cinfo->peer) {
832 const char *id = fmt_node_id(tmpctx, cinfo->peer);
833 return rune_alt_single_str(ctx, alt, id, strlen(id));
834 }
835 return rune_alt_single_missing(ctx, alt);
836 } else if (streq(alt->fieldname, "method")) {
837 if (cinfo->method) {
838 return rune_alt_single_str(ctx, alt,
839 cinfo->method, strlen(cinfo->method));
840 }
841 return rune_alt_single_missing(ctx, alt);
842 } else if (streq(alt->fieldname, "pnum")) {
843 return rune_alt_single_int(ctx, alt, (cinfo && cinfo->params) ? cinfo->params->size : 0);
844 } else if (streq(alt->fieldname, "rate")) {
845 return rate_limit_check(ctx, cinfo->runes, rune, alt, cinfo);
846 } else if (streq(alt->fieldname, "per")) {
847 return per_time_check(ctx, cinfo->runes, rune, alt, cinfo);
848 }
849
850 /* Rest need params lookups: generate this once! */
851 if (cinfo->params && strmap_empty(&cinfo->cached_params)) {
852 const jsmntok_t *t;
853 size_t i;
854
855 if (cinfo->params->type == JSMN_OBJECT) {
856 json_for_each_obj(i, t, cinfo->params) {
857 char *pmemname = tal_fmt(ctx,
858 "pname%.*s",
859 t->end - t->start,
860 cinfo->buf + t->start);
861 size_t off = strlen("pname");
862
863 /* First, add version with underscores intact. */
864 strmap_add(&cinfo->cached_params,
865 tal_strdup(ctx, pmemname), t+1);
866
867 /* Now with punctuation removed: */
868 for (size_t n = off; pmemname[n]; n++) {
869 if (cispunct(pmemname[n]))
870 continue;
871 pmemname[off++] = pmemname[n];
872 }
873 pmemname[off++] = '\0';
874 strmap_add(&cinfo->cached_params, pmemname, t+1);
875 }
876 } else if (cinfo->params->type == JSMN_ARRAY) {
877 json_for_each_arr(i, t, cinfo->params) {
878 char *pmemname = tal_fmt(tmpctx, "parr%zu", i);

Callers

nothing calls this directly

Calls 9

rune_alt_single_intFunction · 0.85
fmt_node_idFunction · 0.85
rune_alt_single_strFunction · 0.85
rune_alt_single_missingFunction · 0.85
rate_limit_checkFunction · 0.85
per_time_checkFunction · 0.85
cispunctFunction · 0.85
check_inv_conditionFunction · 0.85
json_to_s64Function · 0.50

Tested by

no test coverage detected