]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
add tmpl_dcursor_print()
authorAlan T. DeKok <aland@freeradius.org>
Fri, 13 Sep 2024 12:44:07 +0000 (08:44 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Fri, 13 Sep 2024 13:39:17 +0000 (09:39 -0400)
which prints out the path to the current vp

src/lib/server/tmpl_dcursor.c
src/lib/server/tmpl_dcursor.h

index 375e55b909f0e4ca8cc1f8373e5ea6e02c838c4a..8a39aa9288eb66558f8a1a855cadf5deb2e49f22 100644 (file)
@@ -59,6 +59,7 @@ static void *_tmpl_cursor_child_next(fr_dlist_head_t *list, void *curr, void *uc
 
        while ((vp = fr_dlist_next(list, vp))) {
                if (fr_dict_attr_cmp(ns->ar->ar_da, vp->da) == 0) break;
+               ns->num++;
        }
 
        return vp;
@@ -771,3 +772,56 @@ void tmpl_extents_debug(fr_dlist_head_t *head)
        }
 
 }
+
+ssize_t tmpl_dcursor_print(fr_sbuff_t *out, tmpl_dcursor_ctx_t const *cc)
+{
+       tmpl_dcursor_nested_t   *ns;
+       tmpl_request_t          *rr = NULL;
+       tmpl_attr_t             *ar = NULL;
+       fr_sbuff_t              our_out = FR_SBUFF(out);
+
+       /*
+        *      Print all the request references
+        */
+       while ((rr = tmpl_request_list_next(&cc->vpt->data.attribute.rr, rr))) {
+               FR_SBUFF_IN_STRCPY_RETURN(&our_out, fr_table_str_by_value(tmpl_request_ref_table, rr->request, "<INVALID>"));
+               FR_SBUFF_IN_CHAR_RETURN(&our_out, '.');
+       }
+
+       ns = fr_dlist_head(&cc->nested);
+
+       /*
+        *      This also prints out the things we're looping over in nested?
+        */
+       while ((ar = tmpl_attr_list_next(tmpl_attr(cc->vpt), ar))) {
+               if (ns->ar == ar) break;
+
+               if (ar->ar_da == request_attr_local) continue;
+
+               FR_SBUFF_IN_STRCPY_RETURN(&our_out, ar->da->name);
+               FR_SBUFF_IN_CHAR_RETURN(&our_out, '.');
+       }
+
+       /*
+        *      Subtract one from the number, because ???
+        *
+        *      @todo - for foo.[*], print out the actual da being used, which involves tracking the current
+        *      vp, too.  Except that we would then have to track _all_ instances of _all_ vps in a list,
+        *      which is bad.  Perhaps just forbid the use of foo.[*] instead.
+        */
+       while (true) {
+               fr_assert(ns->num > 0);
+
+               FR_SBUFF_IN_STRCPY_RETURN(&our_out, ns->ar->da->name);
+               FR_SBUFF_IN_CHAR_RETURN(&our_out, '[');
+               FR_SBUFF_IN_SPRINTF_RETURN(&our_out, "%zd", ns->num - 1);
+               FR_SBUFF_IN_CHAR_RETURN(&our_out, ']');
+
+               ns = fr_dlist_next(&cc->nested, ns);
+               if (!ns) break;
+
+               FR_SBUFF_IN_CHAR_RETURN(&our_out, ']');
+       }
+
+       FR_SBUFF_SET_RETURN(out, &our_out);
+}
index 957d77248c54c0a7cec4c978cb433a8afd358fd9..30f8375e3102fa8fbf97605bc97963e520dd9395 100644 (file)
@@ -53,6 +53,7 @@ struct tmpl_dcursor_nested_s {
 
        fr_dcursor_t            cursor;         //!< Cursor to track where we are in the list in case
                                                ///< we're doing counts.
+       size_t                  num;            //!< which attribute number we are looking at
 };
 
 /** Maintains state between cursor calls
@@ -101,3 +102,5 @@ fr_pair_t *tmpl_dcursor_pair_build(fr_pair_t *parent, fr_dcursor_t *cursor, fr_d
 
 #define tmpl_dcursor_build_init(_err, _ctx, _cc, _cursor, _request, _vpt, _build, _uctx) \
        _tmpl_dcursor_init(_err, _ctx, _cc, _cursor, _request, _vpt, _build, _uctx)
+
+ssize_t        tmpl_dcursor_print(fr_sbuff_t *out, tmpl_dcursor_ctx_t const *cc);