return fr_cursor_current(cursor);
}
-/** Iterate over attributes of a given type in the pairlist
- *
- *
- */
-VALUE_PAIR *fr_cursor_next_by_num(vp_cursor_t *cursor, unsigned int attr, unsigned int vendor, int8_t tag)
+static VALUE_PAIR *fr_cursor_update(vp_cursor_t *cursor, VALUE_PAIR *i)
{
- VALUE_PAIR *i;
-
- if (!cursor->first) return NULL;
-
- i = pairfind(!cursor->found ? cursor->current : cursor->found->next, attr, vendor, tag);
if (!i) {
cursor->next = NULL;
cursor->current = NULL;
return i;
}
+/** Iterate over attributes of a given type in the pairlist
+ *
+ *
+ */
+VALUE_PAIR *fr_cursor_next_by_num(vp_cursor_t *cursor, unsigned int attr, unsigned int vendor, int8_t tag)
+{
+ VALUE_PAIR *i;
+
+ if (!cursor->first) return NULL;
+
+ for (i = !cursor->found ? cursor->current : cursor->found->next;
+ i != NULL;
+ i = i->next) {
+ VERIFY_VP(i);
+ if ((i->da->attr == attr) && (i->da->vendor == vendor) &&
+ (!i->da->flags.has_tag || TAG_EQ(tag, i->tag))) {
+ break;
+ }
+ }
+
+ return fr_cursor_update(cursor, i);
+}
+
/** Iterate over attributes of a given DA in the pairlist
*
*
if (!cursor->first) return NULL;
- i = pair_find_by_da(!cursor->found ? cursor->current : cursor->found->next, da, tag);
- if (!i) {
- cursor->next = NULL;
- cursor->current = NULL;
-
- return NULL;
+ for (i = !cursor->found ? cursor->current : cursor->found->next;
+ i != NULL;
+ i = i->next) {
+ VERIFY_VP(i);
+ if ((i->da == da) &&
+ (!i->da->flags.has_tag || TAG_EQ(tag, i->tag))) {
+ break;
+ }
}
- cursor->next = i->next;
- cursor->current = i;
- cursor->found = i;
-
- return i;
+ return fr_cursor_update(cursor, i);
}
/** Retrieve the next VALUE_PAIR
VALUE_PAIR *pair_find_by_da(VALUE_PAIR *vp, DICT_ATTR const *da, int8_t tag)
{
vp_cursor_t cursor;
- VALUE_PAIR *i;
if(!fr_assert(da)) {
return NULL;
}
- for (i = fr_cursor_init(&cursor, &vp);
- i;
- i = fr_cursor_next(&cursor)) {
- VERIFY_VP(i);
- if ((i->da == da) && (!i->da->flags.has_tag || TAG_EQ(tag, i->tag))) {
- return i;
- }
- }
-
- return NULL;
+ (void) fr_cursor_init(&cursor, &vp);
+ return fr_cursor_next_by_da(&cursor, da, tag);
}
VALUE_PAIR *pairfind(VALUE_PAIR *vp, unsigned int attr, unsigned int vendor, int8_t tag)
{
vp_cursor_t cursor;
- VALUE_PAIR *i;
/* List head may be NULL if it contains no VPs */
if (!vp) return NULL;
VERIFY_LIST(vp);
- for (i = fr_cursor_init(&cursor, &vp);
- i;
- i = fr_cursor_next(&cursor)) {
- if ((i->da->attr == attr) && (i->da->vendor == vendor) && \
- (!i->da->flags.has_tag || TAG_EQ(tag, i->tag))) {
- return i;
- }
- }
-
- return NULL;
+ (void) fr_cursor_init(&cursor, &vp);
+ return fr_cursor_next_by_num(&cursor, attr, vendor, tag);
}
/** Delete matching pairs