]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Add fr_pair_add_by_da
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 10 Apr 2018 04:40:39 +0000 (10:40 +0600)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 10 Apr 2018 05:53:36 +0000 (11:53 +0600)
src/include/pair.h
src/include/radiusd.h
src/lib/util/pair.c

index 2030f544f173d5d688754735fd4c49f4330a3e34..6ea8d3ceea255a0d5791ffa282dc0b032c7ae2df 100644 (file)
@@ -224,6 +224,9 @@ void                fr_pair_delete_by_num(VALUE_PAIR **head, unsigned int vendor, unsigned int
 void           fr_pair_delete_by_child_num(VALUE_PAIR **head, fr_dict_attr_t const *parent,
                                            unsigned int attr, int8_t tag);
 
+VALUE_PAIR     *fr_pair_add_by_da(TALLOC_CTX *ctx, VALUE_PAIR **list,
+                                  fr_dict_attr_t const *da, int8_t tag);
+
 VALUE_PAIR     *fr_pair_update_by_da(TALLOC_CTX *ctx, VALUE_PAIR **list,
                                      fr_dict_attr_t const *da, int8_t tag,
                                      bool skip_if_exists);
index 6947bf22427c0d80f4f2c0144182792682194739..028d0e54d378370b768627c7efd68651c9075f47 100644 (file)
@@ -527,24 +527,45 @@ int radius_copy_vp(TALLOC_CTX *ctx, VALUE_PAIR **out, REQUEST *request, char con
 #define pair_make_reply(_a, _b, _c) fr_pair_make(request->reply, &request->reply->vps, _a, _b, _c)
 #define pair_make_config(_a, _b, _c) fr_pair_make(request, &request->control, _a, _b, _c)
 
+/** Allocate a VALUE_PAIR in the request list
+ *
+ * @param[in] _da      #fr_dict_attr_t of the pair to be found or allocated.
+ * @param[in] _tag     tag of the attribute to be found or allocated.
+ */
+#define pair_add_request(_da, _tag) fr_pair_add_by_da(request->packet, &request->packet->vps, _da, _tag)
+
+/** Allocate a VALUE_PAIR in the reply list
+ *
+ * @param[in] _da      #fr_dict_attr_t of the pair to be found or allocated.
+ * @param[in] _tag     tag of the attribute to be found or allocated.
+ */
+#define pair_add_reply(_da, _tag) fr_pair_add_by_da(request->reply, &request->reply->vps, _da, _tag)
+
+/** Allocate a VALUE_PAIR in the control list
+ *
+ * @param[in] _da      #fr_dict_attr_t of the pair to be found or allocated.
+ * @param[in] _tag     tag of the attribute to be found or allocated.
+ */
+#define pair_add_control(_da, _tag) fr_pair_add_by_da(request, &request->control, _da, _tag)
+
 /** Return or allocate a VALUE_PAIR in the request list
  *
- * @param[in] _da #fr_dict_attr_t of the pair to be found or allocated.
- * @param[in] _tag tag of the attribute to be found or allocated.
+ * @param[in] _da      #fr_dict_attr_t of the pair to be found or allocated.
+ * @param[in] _tag     tag of the attribute to be found or allocated.
  */
 #define pair_update_request(_da, _tag) fr_pair_update_by_da(request->packet, &request->packet->vps, _da, _tag, false)
 
 /** Return or allocate a VALUE_PAIR in the reply list
  *
- * @param[in] _da #fr_dict_attr_t of the pair to be found or allocated.
- * @param[in] _tag tag of the attribute to be found or allocated.
+ * @param[in] _da      #fr_dict_attr_t of the pair to be found or allocated.
+ * @param[in] _tag     tag of the attribute to be found or allocated.
  */
 #define pair_update_reply(_da, _tag) fr_pair_update_by_da(request->reply, &request->reply->vps, _da, _tag, false)
 
 /** Return or allocate a VALUE_PAIR in the control list
  *
- * @param[in] _da #fr_dict_attr_t of the pair to be found or allocated.
- * @param[in] _tag tag of the attribute to be found or allocated.
+ * @param[in] _da      #fr_dict_attr_t of the pair to be found or allocated.
+ * @param[in] _tag     tag of the attribute to be found or allocated.
  */
 #define pair_update_control(_da, _tag) fr_pair_update_by_da(request, &request->control, _da, _tag, false)
 
index 4dee793f14df5d597f90ee7eb1c4aa552b1bd05a..caaad26afef0d03ab9a5a7146c0b87f5a7345148 100644 (file)
@@ -897,6 +897,32 @@ void *fr_pair_iter_next_by_da(void **prev, void *to_eval, void *uctx)
        return NULL;
 }
 
+/** Create a new VALUE_PAIR
+ *
+ * @param[in] ctx              to allocate new #VALUE_PAIR in.
+ * @param[in,out] list         in search and insert into it.
+ * @param[in] da               of attribute to update.
+ * @param[in] tag              of attribute to update.
+ * @return
+ *     - 0 on success.
+ *     - -1 on failure.
+ */
+VALUE_PAIR *fr_pair_add_by_da(TALLOC_CTX *ctx, VALUE_PAIR **list,
+                             fr_dict_attr_t const *da, int8_t tag)
+{
+       vp_cursor_t     cursor;
+       VALUE_PAIR      *vp;
+
+       (void)fr_pair_cursor_init(&cursor, list);
+       vp = fr_pair_afrom_da(ctx, da);
+       if (!vp) return NULL;
+       vp->tag = tag;
+
+       fr_pair_cursor_prepend(&cursor, vp);
+
+       return vp;
+}
+
 /** Create a new VALUE_PAIR or replaces the value of the head pair in the specified list
  *
  * If skip_if_exists is true, will return NULL if a pair matching the specified #fr_dict_attr_t
@@ -920,8 +946,8 @@ VALUE_PAIR *fr_pair_update_by_da(TALLOC_CTX *ctx, VALUE_PAIR **list,
                                 fr_dict_attr_t const *da, int8_t tag,
                                 bool skip_if_exists)
 {
-       vp_cursor_t cursor;
-       VALUE_PAIR *vp;
+       vp_cursor_t     cursor;
+       VALUE_PAIR      *vp;
 
        (void)fr_pair_cursor_init(&cursor, list);
        vp = fr_pair_cursor_next_by_da(&cursor, da, tag);