From: Alan T. DeKok Date: Tue, 7 Jun 2022 22:35:27 +0000 (-0400) Subject: add tmpl_value_list_insert_tail() which does casting, too. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6d003b7f0c05352ee1335e3600c0a1d1ce50d022;p=thirdparty%2Ffreeradius-server.git add tmpl_value_list_insert_tail() which does casting, too. instead of similar code scattered everywhere. --- diff --git a/src/lib/server/tmpl.h b/src/lib/server/tmpl.h index c99de40d649..da08345fbba 100644 --- a/src/lib/server/tmpl.h +++ b/src/lib/server/tmpl.h @@ -1058,6 +1058,8 @@ bool tmpl_async_required(tmpl_t const *vpt) CC_HINT(nonnull); fr_pair_t *tmpl_get_list(request_t *request, tmpl_t const *vpt) CC_HINT(nonnull(2)); /* temporary hack */ +int tmpl_value_list_insert_tail(fr_value_box_list_t *list, fr_value_box_t *vb, tmpl_t const *vpt) CC_HINT(nonnull); + #undef _CONST #ifdef __cplusplus diff --git a/src/lib/server/tmpl_eval.c b/src/lib/server/tmpl_eval.c index 61dfcca83a8..40d7465c65d 100644 --- a/src/lib/server/tmpl_eval.c +++ b/src/lib/server/tmpl_eval.c @@ -1000,3 +1000,26 @@ int tmpl_find_or_add_vp(fr_pair_t **out, request_t *request, tmpl_t const *vpt) return err; } } + +/** Insert a value-box to a list, with casting. + * + * @param list to append to + * @param box box to cast / append + * @param vpt tmpl with cast. + * @return + * - <0 for "cast failed" + * - 0 for success + */ +int tmpl_value_list_insert_tail(fr_value_box_list_t *list, fr_value_box_t *box, tmpl_t const *vpt) +{ + if (fr_type_is_null(tmpl_rules_cast(vpt)) || + (box->type == tmpl_rules_cast(vpt))) { + fr_dlist_insert_tail(list, box); + return 0; + } + + if (fr_value_box_cast_in_place(box, box, tmpl_rules_cast(vpt), tmpl_rules_enumv(vpt)) < 0) return -1; + + fr_dlist_insert_tail(list, box); + return 0; +}