]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
export dict_protocol_reference, and make it take an sbuff
authorAlan T. DeKok <aland@freeradius.org>
Sun, 3 Aug 2025 15:36:15 +0000 (11:36 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Sun, 3 Aug 2025 15:56:29 +0000 (11:56 -0400)
in preparation for other work with @foo in value-boxes

src/lib/util/dict.h
src/lib/util/dict_fixup.c
src/lib/util/dict_fixup_priv.h
src/lib/util/dict_tokenize.c

index 096121c3db5ee62b517228b5be1890d46d594cc6..0e62dc206de6069e51f9c58c83f7468741787f45 100644 (file)
@@ -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);
 /** @} */
 
index 7878298cd3226745a393368f022bc5fe5ceb745f..72bf7b7b65f22fdd631ff230317bedad420775bd 100644 (file)
@@ -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);
index 71067206747e03494b1ecb239050e6a98c12bb84..c2001143a315dc94e77af135f57a254707f11f64 100644 (file)
@@ -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,
index 10dc4afe377b0a79620eb812d33756cee1085897..151b1e5a0cb823df9012b784026520601fd65055 100644 (file)
@@ -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;