From: Arran Cudbard-Bell Date: Tue, 23 Jan 2018 03:32:40 +0000 (-0700) Subject: Iterator for next_by_da for new cusor code X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b4ecc912dabcbe389a19954a37bda5361af8b273;p=thirdparty%2Ffreeradius-server.git Iterator for next_by_da for new cusor code --- diff --git a/src/include/pair.h b/src/include/pair.h index 69be13b8cf7..38025a7ea75 100644 --- a/src/include/pair.h +++ b/src/include/pair.h @@ -221,6 +221,8 @@ int fr_pair_update_by_num(TALLOC_CTX *ctx, VALUE_PAIR **list, void fr_pair_delete_by_num(VALUE_PAIR **head, unsigned int vendor, unsigned int attr, int8_t tag); +void *fr_pair_iter_next_by_da(void **prev, void *to_eval, void *uctx); + /* Sorting */ typedef int8_t (*fr_cmp_t)(void const *a, void const *b); diff --git a/src/lib/util/pair.c b/src/lib/util/pair.c index 5306d232189..b59fdf264a0 100644 --- a/src/lib/util/pair.c +++ b/src/lib/util/pair.c @@ -857,6 +857,28 @@ void fr_pair_delete_by_num(VALUE_PAIR **head, unsigned int vendor, unsigned int } } +/** An iterator for use by #fr_cursor_iter_init or #fr_cursor_talloc_iter_init + * + * @note The #fr_dict_attr_t to match should be passed in as the uctx value when initialising the iterator. + */ +void *fr_pair_iter_next_by_da(void **prev, void *to_eval, void *uctx) +{ + fr_dict_attr_t const *da = uctx; + VALUE_PAIR *c, *p; + + if (!to_eval) return NULL; + + for (c = to_eval, p = *prev; c; p = c, c = c->next) { + if (c->da == da) { + *prev = p; + return c; + } + } + + *prev = to_eval; + return NULL; +} + /** Order attributes by their da, and tag * * Useful where attributes need to be aggregated, but not necessarily