From: Alan T. DeKok Date: Fri, 13 Sep 2024 12:44:07 +0000 (-0400) Subject: add tmpl_dcursor_print() X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=701326825fc05fe1fbd9127b9d8bc49d59dc52c8;p=thirdparty%2Ffreeradius-server.git add tmpl_dcursor_print() which prints out the path to the current vp --- diff --git a/src/lib/server/tmpl_dcursor.c b/src/lib/server/tmpl_dcursor.c index 375e55b909f..8a39aa9288e 100644 --- a/src/lib/server/tmpl_dcursor.c +++ b/src/lib/server/tmpl_dcursor.c @@ -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, "")); + 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); +} diff --git a/src/lib/server/tmpl_dcursor.h b/src/lib/server/tmpl_dcursor.h index 957d77248c5..30f8375e310 100644 --- a/src/lib/server/tmpl_dcursor.h +++ b/src/lib/server/tmpl_dcursor.h @@ -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);