From: Nick Porter Date: Fri, 13 Jan 2023 15:47:27 +0000 (+0000) Subject: Add tmpl_list_name() and use it to report list names X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e81d1d9b868f26080e4197151f1f8eaf0a34d2e6;p=thirdparty%2Ffreeradius-server.git Add tmpl_list_name() and use it to report list names --- diff --git a/src/lib/ldap/map.c b/src/lib/ldap/map.c index f4d5eda873f..75318545921 100644 --- a/src/lib/ldap/map.c +++ b/src/lib/ldap/map.c @@ -135,8 +135,8 @@ int fr_ldap_map_getvalue(TALLOC_CTX *ctx, fr_pair_list_t *out, request_t *reques if ((tmpl_list(attr->lhs) != tmpl_list(map->lhs))) { RWDEBUG("valuepair \"%pV\" has conflicting list qualifier (%s vs %s), skipping...", fr_box_strvalue_len(self->values[i]->bv_val, self->values[i]->bv_len), - fr_table_str_by_value(pair_list_table, tmpl_list(attr->lhs), ""), - fr_table_str_by_value(pair_list_table, tmpl_list(map->lhs), "")); + tmpl_list_name(tmpl_list(attr->lhs), ""), + tmpl_list_name(tmpl_list(map->lhs), "")); goto next_pair; } diff --git a/src/lib/server/cf_parse.c b/src/lib/server/cf_parse.c index d3829eac207..750448e225d 100644 --- a/src/lib/server/cf_parse.c +++ b/src/lib/server/cf_parse.c @@ -222,7 +222,6 @@ int cf_pair_parse_value(TALLOC_CTX *ctx, void *out, UNUSED void *base, CONF_ITEM tmpl_t *vpt; static tmpl_rules_t rules = { .attr = { - .list_def = PAIR_LIST_REQUEST, .allow_unknown = true, .allow_unresolved = true, .allow_foreign = true @@ -230,6 +229,7 @@ int cf_pair_parse_value(TALLOC_CTX *ctx, void *out, UNUSED void *base, CONF_ITEM }; fr_sbuff_t sbuff = FR_SBUFF_IN(cp->value, strlen(cp->value)); + rules.attr.list_def = PAIR_LIST_REQUEST; /* * Parse the cast operator for barewords */ diff --git a/src/lib/server/map.c b/src/lib/server/map.c index cd831828446..7f909d26094 100644 --- a/src/lib/server/map.c +++ b/src/lib/server/map.c @@ -1831,7 +1831,7 @@ int map_to_request(request_t *request, map_t const *map, radius_map_getvalue_t f if (!list) { REDEBUG("Mapping \"%.*s\" -> \"%.*s\" cannot be performed due to to invalid list qualifier \"%s\" in left side of map", (int)map->rhs->len, map->rhs->name, (int)map->lhs->len, map->lhs->name, - fr_table_str_by_value(pair_list_table, list_ref, "")); + tmpl_list_name(list_ref, "")); rcode = -2; goto finish; } diff --git a/src/lib/server/map_async.c b/src/lib/server/map_async.c index 656426dd196..256a58f7255 100644 --- a/src/lib/server/map_async.c +++ b/src/lib/server/map_async.c @@ -219,7 +219,7 @@ static inline fr_pair_list_t *map_check_src_or_dst(request_t *request, map_t con if (!list) { REDEBUG("Mapping \"%.*s\" -> \"%.*s\" cannot be performed due to to invalid list qualifier \"%s\"", (int)map->rhs->len, map->rhs->name, (int)map->lhs->len, map->lhs->name, - fr_table_str_by_value(pair_list_table, list_ref, "")); + tmpl_list_name(list_ref, "")); return NULL; } diff --git a/src/lib/server/tmpl.h b/src/lib/server/tmpl.h index 307f0b600d1..bd83f28560a 100644 --- a/src/lib/server/tmpl.h +++ b/src/lib/server/tmpl.h @@ -824,6 +824,14 @@ static inline tmpl_pair_list_t tmpl_list(tmpl_t const *vpt) } /** @} */ +/** Return the name of a tmpl list or def if list not provided + * +*/ +static inline char const *tmpl_list_name(fr_dict_attr_t const *list, char const *def) +{ + return (list ? list->name : def); +} + /** @name Field accessors for #TMPL_TYPE_XLAT * * @{ diff --git a/src/lib/server/tmpl_dcursor.c b/src/lib/server/tmpl_dcursor.c index a7467f6386b..3a9cd7fd589 100644 --- a/src/lib/server/tmpl_dcursor.c +++ b/src/lib/server/tmpl_dcursor.c @@ -432,7 +432,7 @@ fr_pair_t *_tmpl_dcursor_init(int *err, TALLOC_CTX *ctx, tmpl_dcursor_ctx_t *cc, list = tmpl_get_list(request, vpt); if (!list) { fr_strerror_printf("List \"%s\" not available in this context", - fr_table_str_by_value(pair_list_table, tmpl_list(vpt), "")); + tmpl_list_name(tmpl_list(vpt), "")); if (err) *err = -2; goto error; } @@ -550,7 +550,7 @@ int tmpl_extents_find(TALLOC_CTX *ctx, list_head = tmpl_list_head(request, tmpl_list(vpt)); if (!list_head) { fr_strerror_printf("List \"%s\" not available in this context", - fr_table_str_by_value(pair_list_table, tmpl_list(vpt), "")); + tmpl_list_name(tmpl_list(vpt), "")); return -2; } list_ctx = tmpl_list_ctx(request, tmpl_list(vpt)); diff --git a/src/lib/server/tmpl_eval.c b/src/lib/server/tmpl_eval.c index 58935bb7312..806d77b979f 100644 --- a/src/lib/server/tmpl_eval.c +++ b/src/lib/server/tmpl_eval.c @@ -133,7 +133,7 @@ fr_pair_t *tmpl_get_list(request_t *request, tmpl_t const *vpt) } RWDEBUG2("List \"%s\" is not available", - fr_table_str_by_value(pair_list_table, list, "")); + tmpl_list_name(list, "")); return NULL; } diff --git a/src/lib/server/tmpl_tokenize.c b/src/lib/server/tmpl_tokenize.c index 0923cd84a30..5a99e3e387e 100644 --- a/src/lib/server/tmpl_tokenize.c +++ b/src/lib/server/tmpl_tokenize.c @@ -95,11 +95,7 @@ TMPL_REQUEST_REF_DEF(tmpl_request_def_parent, REQUEST_PARENT); * * Defaults are used if a NULL rules pointer is passed to the parsing function. */ -static tmpl_rules_t const default_rules = { - .attr = { - .list_def = PAIR_LIST_REQUEST, - }, -}; +#define DEFAULT_RULES tmpl_rules_t const default_rules = { .attr = { .list_def = PAIR_LIST_REQUEST }} /* clang-format off */ @@ -314,7 +310,7 @@ void tmpl_attr_debug(tmpl_t const *vpt) i++; } - FR_FAULT_LOG("list: %s", fr_table_str_by_value(pair_list_table, vpt->data.attribute.list, "")); + FR_FAULT_LOG("list: %s", tmpl_list_name(vpt->data.attribute.list, "")); tmpl_attr_ref_list_debug(tmpl_attr(vpt)); } @@ -621,6 +617,7 @@ static fr_slen_t tmpl_request_ref_list_from_substr(TALLOC_CTX *ctx, tmpl_attr_er tmpl_request_t *tail = tmpl_request_list_tail(out); unsigned int depth = 0; fr_sbuff_marker_t m; + DEFAULT_RULES; if (!at_rules) at_rules = &default_rules.attr; @@ -2056,6 +2053,7 @@ ssize_t tmpl_afrom_attr_substr(TALLOC_CTX *ctx, tmpl_attr_error_t *err, bool is_raw = false; tmpl_attr_rules_t const *at_rules; fr_sbuff_marker_t m_l; + DEFAULT_RULES; if (!t_rules) t_rules = &default_rules; at_rules = &t_rules->attr; @@ -2352,6 +2350,7 @@ ssize_t tmpl_afrom_attr_str(TALLOC_CTX *ctx, tmpl_attr_error_t *err, tmpl_t **out, char const *name, tmpl_rules_t const *t_rules) { ssize_t slen, name_len; + DEFAULT_RULES; if (!t_rules) t_rules = &default_rules; /* Use the defaults */ @@ -2949,6 +2948,7 @@ fr_slen_t tmpl_afrom_substr(TALLOC_CTX *ctx, tmpl_t **out, char *str; tmpl_t *vpt = NULL; + DEFAULT_RULES; if (!t_rules) t_rules = &default_rules; /* Use the defaults */ @@ -4392,7 +4392,8 @@ fr_slen_t tmpl_attr_print(fr_sbuff_t *out, tmpl_t const *vpt, tmpl_attr_prefix_t if (tmpl_list(vpt) != PAIR_LIST_REQUEST) { /* Don't print the default list */ if (printed_rr) FR_SBUFF_IN_CHAR_RETURN(&our_out, '.'); - FR_SBUFF_IN_TABLE_STR_RETURN(&our_out, pair_list_table, tmpl_list(vpt), ""); + slen = fr_sbuff_in_strcpy(&our_out, tmpl_list_name(tmpl_list(vpt), "")); + if (slen < 0) return slen; if (tmpl_attr_list_num_elements(tmpl_attr(vpt))) FR_SBUFF_IN_CHAR_RETURN(&our_out, '.'); /* @@ -4996,8 +4997,9 @@ void tmpl_verify(char const *file, int line, tmpl_t const *vpt) if (!vpt->rules.attr.list_as_attr && ((tmpl_list(vpt) == PAIR_LIST_UNKNOWN) || tmpl_list(vpt) > PAIR_LIST_STATE)) { fr_fatal_assert_fail("CONSISTENCY CHECK FAILED %s[%u]: TMPL_TYPE_ATTR " - "attribute \"%s\" has invalid list (%i)", - file, line, tmpl_attr_tail_da(vpt)->name, tmpl_list(vpt)); + "attribute \"%s\" has invalid list (%s)", + file, line, tmpl_attr_tail_da(vpt)->name, + tmpl_list_name(tmpl_list(vpt), "")); } tmpl_attr_verify(file, line, vpt); diff --git a/src/lib/unlang/compile.c b/src/lib/unlang/compile.c index a9377a6bf52..29ba1b48346 100644 --- a/src/lib/unlang/compile.c +++ b/src/lib/unlang/compile.c @@ -1365,7 +1365,7 @@ static unlang_t *compile_update_to_edit(unlang_t *parent, unlang_compile_t *unla if (name2) { snprintf(list_buffer, sizeof(list_buffer), "&%s", name2); } else { - snprintf(list_buffer, sizeof(list_buffer), "&%s", fr_table_str_by_value(pair_list_table, unlang_ctx->rules->attr.list_def, "")); + snprintf(list_buffer, sizeof(list_buffer), "&%s", tmpl_list_name(unlang_ctx->rules->attr.list_def, "")); } /* diff --git a/src/lib/unlang/xlat_builtin.c b/src/lib/unlang/xlat_builtin.c index 86f68218f6a..f59dcb5d247 100644 --- a/src/lib/unlang/xlat_builtin.c +++ b/src/lib/unlang/xlat_builtin.c @@ -1015,7 +1015,7 @@ void xlat_debug_attr_vp(request_t *request, fr_pair_t *vp, tmpl_t const *vpt) case FR_TYPE_STRUCTURAL: if (vpt) { RIDEBUG2("&%s.%s = {", - fr_table_str_by_value(pair_list_table, tmpl_list(vpt), ""), + tmpl_list_name(tmpl_list(vpt), ""), vp->da->name); } else { RIDEBUG2("%s = {", vp->da->name); @@ -1029,7 +1029,7 @@ void xlat_debug_attr_vp(request_t *request, fr_pair_t *vp, tmpl_t const *vpt) default: if (vpt) { RIDEBUG2("&%s.%s = %pV", - fr_table_str_by_value(pair_list_table, tmpl_list(vpt), ""), + tmpl_list_name(tmpl_list(vpt), ""), vp->da->name, &vp->data); } else { diff --git a/src/lib/unlang/xlat_tokenize.c b/src/lib/unlang/xlat_tokenize.c index b106deab09c..0c2604a0d85 100644 --- a/src/lib/unlang/xlat_tokenize.c +++ b/src/lib/unlang/xlat_tokenize.c @@ -1122,7 +1122,7 @@ static void _xlat_debug(xlat_exp_head_t const *head, int depth) while ((rr = tmpl_request_list_next(list, rr))) { INFO_INDENT("ref %d", rr->request); } - INFO_INDENT("list %d", tmpl_list(node->vpt)); + INFO_INDENT("list %s", tmpl_list_name(tmpl_list(node->vpt), "")); if (tmpl_attr_tail_num(node->vpt) != NUM_UNSPEC) { if (tmpl_attr_tail_num(node->vpt) == NUM_COUNT) { INFO_INDENT("[#]"); diff --git a/src/modules/rlm_rest/rest.c b/src/modules/rlm_rest/rest.c index 5e725d19378..d038f0bbe9d 100644 --- a/src/modules/rlm_rest/rest.c +++ b/src/modules/rlm_rest/rest.c @@ -1161,7 +1161,7 @@ static int json_pair_alloc(rlm_rest_t const *instance, rlm_rest_section_t const if (!vp) continue; } RINDENT(); - RDEBUG2("&%s:%pP", fr_table_str_by_value(pair_list_table, tmpl_list(dst), ""), vp); + RDEBUG2("&%s:%pP", tmpl_list_name(tmpl_list(dst), ""), vp); REXDENT(); fr_pair_list_init(&tmp_list);