From: Alan T. DeKok Date: Sun, 3 Aug 2025 15:36:15 +0000 (-0400) Subject: export dict_protocol_reference, and make it take an sbuff X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=28d98febab86bd07f820bbc13d6a433053b6ecf2;p=thirdparty%2Ffreeradius-server.git export dict_protocol_reference, and make it take an sbuff in preparation for other work with @foo in value-boxes --- diff --git a/src/lib/util/dict.h b/src/lib/util/dict.h index 096121c3db..0e62dc206d 100644 --- a/src/lib/util/dict.h +++ b/src/lib/util/dict.h @@ -853,6 +853,8 @@ int fr_dict_protocol_afrom_file(fr_dict_t **out, char const *proto_name, char fr_dict_t *fr_dict_protocol_alloc(fr_dict_t const *parent); +int fr_dict_protocol_reference(fr_dict_attr_t const **da_p, fr_dict_attr_t const *root, fr_sbuff_t *in); + int fr_dict_read(fr_dict_t *dict, char const *dict_dir, char const *filename); /** @} */ diff --git a/src/lib/util/dict_fixup.c b/src/lib/util/dict_fixup.c index 7878298cd3..72bf7b7b65 100644 --- a/src/lib/util/dict_fixup.c +++ b/src/lib/util/dict_fixup.c @@ -126,25 +126,24 @@ static inline CC_HINT(always_inline) int dict_fixup_common(fr_dlist_head_t *fixu * * @param[out] da_p Where the attribute will be stored * @param[in] rel Relative attribute to resolve from. - * @param[in] ref Reference string. + * @param[in] in Reference string. * @return * - <0 on error * - 0 on parse OK, but *da_p is NULL; * - 1 for parse OK, and *da_p is !NULL */ -int dict_protocol_reference(fr_dict_attr_t const **da_p, fr_dict_attr_t const *rel, char const *ref) +int fr_dict_protocol_reference(fr_dict_attr_t const **da_p, fr_dict_attr_t const *rel, fr_sbuff_t *in) { fr_dict_t *dict = fr_dict_unconst(rel->dict); fr_dict_attr_t const *da = rel; ssize_t slen; - fr_sbuff_t sbuff = FR_SBUFF_IN(ref, strlen(ref)); *da_p = NULL; /* * Are we resolving a foreign reference? */ - if (fr_sbuff_next_if_char(&sbuff, '@')) { + if (fr_sbuff_next_if_char(in, '@')) { char proto_name[FR_DICT_ATTR_MAX_NAME_LEN + 1]; fr_sbuff_t proto_name_sbuff = FR_SBUFF_OUT(proto_name, sizeof(proto_name)); @@ -153,21 +152,21 @@ int dict_protocol_reference(fr_dict_attr_t const **da_p, fr_dict_attr_t const *r * * This is a bit clearer than "foo". */ - if (fr_sbuff_next_if_char(&sbuff, '.')) { - if (fr_sbuff_is_char(&sbuff, '.')) goto above_root; + if (fr_sbuff_next_if_char(in, '.')) { + if (fr_sbuff_is_char(in, '.')) goto above_root; da = rel->dict->root; goto more; } - slen = dict_by_protocol_substr(NULL, &dict, &sbuff, NULL); + slen = dict_by_protocol_substr(NULL, &dict, in, NULL); /* Need to load it... */ if (slen <= 0) { /* Quiet coverity */ fr_sbuff_terminate(&proto_name_sbuff); /* Fixme, probably want to limit allowed chars */ - if (fr_sbuff_out_bstrncpy_until(&proto_name_sbuff, &sbuff, SIZE_MAX, + if (fr_sbuff_out_bstrncpy_until(&proto_name_sbuff, in, SIZE_MAX, &FR_SBUFF_TERMS(L(""), L(".")), NULL) <= 0) { invalid_name: fr_strerror_const("Invalid protocol name"); @@ -203,7 +202,7 @@ int dict_protocol_reference(fr_dict_attr_t const **da_p, fr_dict_attr_t const *r /* * Didn't stop at an attribute ref... we're done */ - if (fr_sbuff_eof(&sbuff)) { + if (fr_sbuff_eof(in)) { *da_p = dict->root; return 1; } @@ -211,9 +210,9 @@ int dict_protocol_reference(fr_dict_attr_t const **da_p, fr_dict_attr_t const *r da = dict->root; } - if (!fr_sbuff_next_if_char(&sbuff, '.')) { + if (!fr_sbuff_next_if_char(in, '.')) { fr_strerror_printf("Attribute %s has reference '%s' which does not begin with '.' or '@'", - rel->name, ref); + rel->name, fr_sbuff_start(in)); return -1; } @@ -222,7 +221,7 @@ int dict_protocol_reference(fr_dict_attr_t const **da_p, fr_dict_attr_t const *r * * No '.' means use the root. */ - while (fr_sbuff_next_if_char(&sbuff, '.')) { + while (fr_sbuff_next_if_char(in, '.')) { if (!da->parent) { above_root: fr_strerror_const("Reference attempted to navigate above dictionary root"); @@ -236,7 +235,7 @@ int dict_protocol_reference(fr_dict_attr_t const **da_p, fr_dict_attr_t const *r * update *da_p with a partial reference if it exists. */ more: - slen = fr_dict_attr_by_oid_substr(NULL, da_p, da, &sbuff, NULL); + slen = fr_dict_attr_by_oid_substr(NULL, da_p, da, in, NULL); if (slen < 0) return -1; if (slen == 0) { @@ -379,7 +378,7 @@ static inline CC_HINT(always_inline) int dict_fixup_group_apply(UNUSED dict_fixu { fr_dict_attr_t const *da; - (void) dict_protocol_reference(&da, fixup->da->parent, fixup->ref); + (void) fr_dict_protocol_reference(&da, fixup->da->parent, &FR_SBUFF_IN_STR(fixup->ref)); if (!da) { fr_strerror_printf_push("Failed resolving reference for attribute at %s[%d]", fr_cwd_strip(fixup->da->filename), fixup->da->line); @@ -602,7 +601,7 @@ static inline CC_HINT(always_inline) int dict_fixup_clone_apply(UNUSED dict_fixu { fr_dict_attr_t const *src; - (void) dict_protocol_reference(&src, fixup->da->parent, fixup->ref); + (void) fr_dict_protocol_reference(&src, fixup->da->parent, &FR_SBUFF_IN_STR(fixup->ref)); if (!src) { fr_strerror_printf_push("Failed resolving reference for attribute at %s[%d]", fr_cwd_strip(fixup->da->filename), fixup->da->line); @@ -661,7 +660,7 @@ static inline CC_HINT(always_inline) int dict_fixup_clone_enum_apply(UNUSED dict fr_dict_attr_t const *src; int copied; - (void) dict_protocol_reference(&src, fixup->da->parent, fixup->ref); + (void) fr_dict_protocol_reference(&src, fixup->da->parent, &FR_SBUFF_IN_STR(fixup->ref)); if (!src) { fr_strerror_printf_push("Failed resolving reference for attribute at %s[%d]", fr_cwd_strip(fixup->da->filename), fixup->da->line); diff --git a/src/lib/util/dict_fixup_priv.h b/src/lib/util/dict_fixup_priv.h index 7106720674..c2001143a3 100644 --- a/src/lib/util/dict_fixup_priv.h +++ b/src/lib/util/dict_fixup_priv.h @@ -40,8 +40,6 @@ typedef struct { fr_dlist_head_t alias; //!< Aliases that can't be resolved immediately. } dict_fixup_ctx_t; -int dict_protocol_reference(fr_dict_attr_t const **da_p, fr_dict_attr_t const *root, char const *ref); - int dict_fixup_enumv_enqueue(dict_fixup_ctx_t *fctx, char const *filename, int line, char const *attr, size_t attr_len, char const *name, size_t name_len, diff --git a/src/lib/util/dict_tokenize.c b/src/lib/util/dict_tokenize.c index 10dc4afe37..151b1e5a0c 100644 --- a/src/lib/util/dict_tokenize.c +++ b/src/lib/util/dict_tokenize.c @@ -847,7 +847,7 @@ static int dict_attr_add_or_fixup(dict_fixup_ctx_t *fixup, fr_dict_attr_t **da_p /* * IF the ref exists, we can always add it. The ref won't be changed later. */ - if (dict_protocol_reference(&src, da->parent, ref->unresolved) < 0) return -1; + if (fr_dict_protocol_reference(&src, da->parent, &FR_SBUFF_IN_STR(ref->unresolved)) < 0) return -1; if (src && (dict_attr_ref_set(*da_p, src, FR_DICT_ATTR_REF_ALIAS) < 0)) return -1; @@ -877,7 +877,7 @@ static int dict_attr_add_or_fixup(dict_fixup_ctx_t *fixup, fr_dict_attr_t **da_p * @todo - if we defer this clone, we get errors loading dictionary.wimax. That * likely means there are issues with the dict_fixup_clone_apply() function. */ - if (dict_protocol_reference(&src, da->parent, ref->unresolved) < 0) return -1; + if (fr_dict_protocol_reference(&src, da->parent, &FR_SBUFF_IN_STR(ref->unresolved)) < 0) return -1; if (src) { if (dict_fixup_clone(da_p, src) < 0) return -1; break;