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

Function check_condition

lightningd/runes.c:854–940  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

852}
853
854static const char *check_condition(const tal_t *ctx,
855 const struct rune *rune,
856 const struct rune_altern *alt,
857 struct cond_info *cinfo)
858{
859 const jsmntok_t *ptok;
860
861 if (streq(alt->fieldname, "time")) {
862 return rune_alt_single_int(ctx, alt, cinfo->now.ts.tv_sec);
863 } else if (streq(alt->fieldname, "id")) {
864 if (cinfo->peer) {
865 const char *id = fmt_node_id(tmpctx, cinfo->peer);
866 return rune_alt_single_str(ctx, alt, id, strlen(id));
867 }
868 return rune_alt_single_missing(ctx, alt);
869 } else if (streq(alt->fieldname, "method")) {
870 if (cinfo->method) {
871 return rune_alt_single_str(ctx, alt,
872 cinfo->method, strlen(cinfo->method));
873 }
874 return rune_alt_single_missing(ctx, alt);
875 } else if (streq(alt->fieldname, "pnum")) {
876 return rune_alt_single_int(ctx, alt, (cinfo && cinfo->params) ? cinfo->params->size : 0);
877 } else if (streq(alt->fieldname, "rate")) {
878 return rate_limit_check(ctx, cinfo->runes, rune, alt, cinfo);
879 } else if (streq(alt->fieldname, "per")) {
880 return per_time_check(ctx, cinfo->runes, rune, alt, cinfo);
881 }
882
883 /* Rest need params lookups: generate this once! */
884 if (cinfo->params && strmap_empty(&cinfo->cached_params)) {
885 const jsmntok_t *t;
886 size_t i;
887
888 if (cinfo->params->type == JSMN_OBJECT) {
889 json_for_each_obj(i, t, cinfo->params) {
890 char *pmemname = tal_fmt(tmpctx,
891 "pname%.*s",
892 t->end - t->start,
893 cinfo->buf + t->start);
894 size_t off = strlen("pname");
895
896 /* First, add version with underscores intact. */
897 cache_param(cinfo, tal_strdup(tmpctx, pmemname), t+1);
898
899 /* Now with punctuation removed: */
900 for (size_t n = off; pmemname[n]; n++) {
901 if (cispunct(pmemname[n]))
902 continue;
903 pmemname[off++] = pmemname[n];
904 }
905 pmemname[off++] = '\0';
906 cache_param(cinfo, pmemname, t+1);
907 }
908 } else if (cinfo->params->type == JSMN_ARRAY) {
909 json_for_each_arr(i, t, cinfo->params) {
910 char *pmemname = tal_fmt(tmpctx, "parr%zu", i);
911 strmap_add(&cinfo->cached_params, pmemname, t);

Callers

nothing calls this directly

Calls 10

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
cache_paramFunction · 0.85
cispunctFunction · 0.85
check_inv_conditionFunction · 0.85
json_to_s64Function · 0.50

Tested by

no test coverage detected