VALUE_PAIR *fr_cursor_next_peek(vp_cursor_t *cursor);
VALUE_PAIR *fr_cursor_current(vp_cursor_t *cursor);
void fr_cursor_insert(vp_cursor_t *cursor, VALUE_PAIR *vp);
+void fr_cursor_merge(vp_cursor_t *cursor, VALUE_PAIR *vp);
VALUE_PAIR *fr_cursor_remove(vp_cursor_t *cursor);
VALUE_PAIR *fr_cursor_replace(vp_cursor_t *cursor, VALUE_PAIR *new);
void pairdelete(VALUE_PAIR **, unsigned int attr, unsigned int vendor, int8_t tag);
return cursor->current;
}
-/** Insert a VP
+/** Insert a single VP
*
* @todo don't use with pairdelete
*/
VERIFY_VP(add);
/*
+ * Only allow one VP to by inserted at a time
+ */
+ add->next = NULL;
+
+ /*
* Cursor was initialised with a pointer to a NULL value_pair
*/
if (!*cursor->first) {
cursor->last->next = add;
}
+/** Merges two sets of VPs
+ *
+ * The list represented by cursor will hold the union of cursor and
+ * add lists.
+ *
+ * @param cursor to insert VALUE_PAIRs with
+ * @param add one or more VALUE_PAIRs.
+ */
+void fr_cursor_merge(vp_cursor_t *cursor, VALUE_PAIR *add)
+{
+ vp_cursor_t from;
+ VALUE_PAIR *vp;
+
+ for (vp = fr_cursor_init(&from, &add);
+ vp;
+ vp = fr_cursor_next(&from)) {
+ fr_cursor_insert(cursor, vp);
+ }
+}
+
/** Remove the current pair
*
* @todo this is really inefficient and should be fixed...
break;
}
- fr_cursor_insert(&cursor, vp);
+ fr_cursor_merge(&cursor, vp);
buf[0] = '\0';
}
vp = NULL;
if ((userparse(data, buffer, &vp) > 0) &&
(vp != NULL)) {
- fr_cursor_insert(&cursor, vp);
+ fr_cursor_merge(&cursor, vp);
}
}
/* Insert at the START of the list */
/* FIXME: Can't make assumptions about ordering */
fr_cursor_init(&cursor, &vp);
- fr_cursor_insert(&cursor, request->proxy->vps);
+ fr_cursor_merge(&cursor, request->proxy->vps);
request->proxy->vps = vp;
}
pairstrcpy(vp, strippedname->vp_strvalue);
INFO(" ... adding new socket %s (%u of %u)", buffer,
home->limit.num_connections, home->limit.max_connections);
}
-
+
#endif
} else {
INFO(" ... adding new socket %s", buffer);
*/
if (!dst) {
RDEBUG3("No existing attribute to filter, adding instead");
- fr_cursor_insert(&dst_list, head);
+ fr_cursor_merge(&dst_list, head);
head = NULL;
goto finish;
}
vp = paircopy(ctx, *vps);
if (!vp) return 0;
- fr_cursor_insert(&to, vp);
+ fr_cursor_merge(&to, vp);
break;
default:
return -1;
}
- fr_cursor_insert(&cursor, vp);
+ fr_cursor_merge(&cursor, vp);
p += 4 + 1 + p[4]; /* vendor id (4) + len (1) + vsa len (n) */
}
* ->next directly.
*/
fr_cursor_init(&tlv_cursor, tlv);
- fr_cursor_insert(&tlv_cursor, head);
+ fr_cursor_merge(&tlv_cursor, head);
}
return 0;
pairfree(&head);
goto malformed;
}
- fr_cursor_insert(&cursor, vp);
+ fr_cursor_merge(&cursor, vp);
a_p += a_len;
}
* ->next directly.
*/
fr_cursor_init(&tlv_cursor, tlv);
- fr_cursor_insert(&tlv_cursor, head);
+ fr_cursor_merge(&tlv_cursor, head);
}
return 0;
return -1;
}
- if (options) {
- fr_cursor_insert(&cursor, options);
- }
+ if (options) fr_cursor_merge(&cursor, options);
}
/*
/* XXX Ugly ... should be set by the caller */
if (packet->code == 0) packet->code = PW_DHCP_NAK;
-
+
/* store xid */
if ((vp = pairfind(packet->vps, 260, DHCP_MAGIC_VENDOR, TAG_ANY))) {
packet->id = vp->vp_integer;
break;
}
- RDEBUG2("Adding to cache entry:");
if (debug_flag) radius_map_debug(request, map, vp);
(void) talloc_steal(c, vp);
goto do_octets;
}
- fr_cursor_insert(&out, vp);
+ fr_cursor_merge(&out, vp);
goto next_attr;
}
goto next_pair;
}
- fr_cursor_insert(&cursor, vp);
+ fr_cursor_merge(&cursor, vp);
talloc_free(attr);
}
break;