]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Iterator for next_by_da for new cusor code
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 23 Jan 2018 03:32:40 +0000 (20:32 -0700)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 23 Jan 2018 03:56:05 +0000 (20:56 -0700)
src/include/pair.h
src/lib/util/pair.c

index 69be13b8cf73c5ed0bd9813137620e56fc1eda6d..38025a7ea75b5f9854c0daf151142c3fc4d5e9a1 100644 (file)
@@ -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);
 
index 5306d232189d9c4fa8c74b4a7f0a571b59fe4696..b59fdf264a08d1d1300cd08802de4cc5cc429db0 100644 (file)
@@ -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