]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
request / reply are VPs, so just use that
authorAlan T. DeKok <aland@freeradius.org>
Thu, 18 May 2023 20:44:08 +0000 (16:44 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Sat, 20 May 2023 22:01:57 +0000 (18:01 -0400)
src/lib/server/pair.h
src/lib/util/pair.c
src/lib/util/pair.h
src/lib/util/pair_tests.c

index 203d81e693b769e4d98624c9f86e10722db8feb0..44e03a6c344f7b3233b452f3da1cd03a43d3c4db 100644 (file)
@@ -115,7 +115,7 @@ RCSIDH(server_pair_h, "$Id$")
  *     - 0 if we allocated a new attribute.
  *     - -1 on failure.
  */
-#define pair_update_request(_attr, _da) fr_pair_update_by_da(request->request_ctx, _attr, &request->request_pairs, _da, 0)
+#define pair_update_request(_attr, _da) fr_pair_update_by_da(request->request_ctx, _attr, _da, 0)
 
 /** Return or allocate a fr_pair_t in the reply list
  *
@@ -126,7 +126,7 @@ RCSIDH(server_pair_h, "$Id$")
  *     - 0 if we allocated a new attribute.
  *     - -1 on failure.
  */
-#define pair_update_reply(_attr, _da) fr_pair_update_by_da(request->reply_ctx, _attr, &request->reply_pairs, _da, 0)
+#define pair_update_reply(_attr, _da) fr_pair_update_by_da(request->reply_ctx, _attr, _da, 0)
 
 /** Return or allocate a fr_pair_t in the control list
  *
@@ -137,7 +137,7 @@ RCSIDH(server_pair_h, "$Id$")
  *     - 0 if we allocated a new attribute.
  *     - -1 on failure.
  */
-#define pair_update_control(_attr, _da) fr_pair_update_by_da(request->control_ctx, _attr, &request->control_pairs, _da, 0)
+#define pair_update_control(_attr, _da) fr_pair_update_by_da(request->control_ctx, _attr, _da, 0)
 
 /** Return or allocate a fr_pair_t in the session_state list
  *
@@ -148,7 +148,7 @@ RCSIDH(server_pair_h, "$Id$")
  *     - 0 if we allocated a new attribute.
  *     - -1 on failure.
  */
-#define pair_update_session_state(_attr, _da) fr_pair_update_by_da(request->session_state_ctx, _attr, &request->session_state_pairs, _da, 0)
+#define pair_update_session_state(_attr, _da) fr_pair_update_by_da(request->session_state_ctx, _attr, _da, 0)
 
 /** Delete one or move fr_pair_t in a list
  *
index 91580d5d73e159fe33dffda9831ef33e5d437011..fad173e8bc9cd24e967fec1919f63620ba7a4f9b 100644 (file)
@@ -1479,10 +1479,9 @@ int fr_pair_append_by_da_parent(TALLOC_CTX *ctx, fr_pair_t **out, fr_pair_list_t
 
 /** Return the first fr_pair_t matching the #fr_dict_attr_t or alloc a new fr_pair_t (and append)
  *
- * @param[in] ctx      to allocate any new #fr_pair_t in.
+ * @param[in] parent   to search for attributes in or append attributes to
  * @param[out] out     Pair we allocated or found.  May be NULL if the caller doesn't
  *                     care about manipulating the fr_pair_t.
- * @param[in,out] list to search for attributes in or append attributes to.
  * @param[in] da       of attribute to locate or alloc.
  * @param[in] n                update the n'th instance of this da.
  *                     Note: If we can't find the n'th instance the attribute created
@@ -1493,25 +1492,25 @@ int fr_pair_append_by_da_parent(TALLOC_CTX *ctx, fr_pair_t **out, fr_pair_list_t
  *     - 0 if we allocated a new attribute.
  *     - -1 on failure.
  */
-int fr_pair_update_by_da(TALLOC_CTX *ctx, fr_pair_t **out, fr_pair_list_t *list,
+int fr_pair_update_by_da(fr_pair_t *parent, fr_pair_t **out,
                         fr_dict_attr_t const *da, unsigned int n)
 {
        fr_pair_t       *vp;
 
-       vp = fr_pair_find_by_da_idx(list, da, n);
+       vp = fr_pair_find_by_da_idx(&parent->vp_group, da, n);
        if (vp) {
-               PAIR_VERIFY_WITH_LIST(list, vp);
+               PAIR_VERIFY_WITH_LIST(&parent->vp_group, vp);
                if (out) *out = vp;
                return 1;
        }
 
-       vp = fr_pair_afrom_da(ctx, da);
+       vp = fr_pair_afrom_da(parent, da);
        if (unlikely(!vp)) {
                if (out) *out = NULL;
                return -1;
        }
 
-       fr_pair_append(list, vp);
+       fr_pair_append(&parent->vp_group, vp);
        if (out) *out = vp;
 
        return 0;
index fce2d9a49357c8cdc6ae87f90da63d9b72bc2e24..5132d99196b462e5c0a43cfd5c1d6398f76afd40 100644 (file)
@@ -501,8 +501,8 @@ int         fr_pair_prepend_by_da(TALLOC_CTX *ctx, fr_pair_t **out, fr_pair_list_t *lis
 int            fr_pair_append_by_da_parent(TALLOC_CTX *ctx, fr_pair_t **out, fr_pair_list_t *list,
                                            fr_dict_attr_t const *da) CC_HINT(nonnull(3,4));
 
-int            fr_pair_update_by_da(TALLOC_CTX *ctx, fr_pair_t **out, fr_pair_list_t *list,
-                                    fr_dict_attr_t const *da, unsigned int n) CC_HINT(nonnull(3,4));
+int            fr_pair_update_by_da(fr_pair_t *parent, fr_pair_t **out,
+                                    fr_dict_attr_t const *da, unsigned int n) CC_HINT(nonnull(1,3));
 
 int            fr_pair_delete_by_da(fr_pair_list_t *head, fr_dict_attr_t const *da) CC_HINT(nonnull);
 
index 5a60cb62f47e31cd41e21a74c053c1f0c97e6a47..91c4edba24229c88f866a5dda62543fbcc277c2f 100644 (file)
@@ -525,20 +525,24 @@ static void test_fr_pair_prepend_by_da(void)
 
 static void test_fr_pair_update_by_da(void)
 {
-       fr_pair_t *vp;
+       fr_pair_t *vp, *group;
+
+       TEST_CHECK((group = fr_pair_afrom_da(autofree, fr_dict_attr_test_group)) != NULL);
 
        TEST_CASE("Update Add using fr_pair_prepend_by_da()");
-       TEST_CHECK(fr_pair_update_by_da(autofree, &vp, &test_pairs, fr_dict_attr_test_uint32, 0) == 1); /* attribute already exist */
+       TEST_CHECK(fr_pair_update_by_da(group, &vp, fr_dict_attr_test_uint32, 0) == 0); /* attribute doesn't exist in this group */
        vp->vp_uint32 = 54321;
 
        TEST_CASE("Expected fr_dict_attr_test_uint32 (vp->vp_uint32 == 54321)");
-       TEST_CHECK((vp = fr_pair_find_by_da(&test_pairs, NULL, fr_dict_attr_test_uint32)) != NULL);
+       TEST_CHECK((vp = fr_pair_find_by_da(&group->vp_group, NULL, fr_dict_attr_test_uint32)) != NULL);
 
        TEST_CASE("Validating PAIR_VERIFY()");
        PAIR_VERIFY(vp);
 
        TEST_CASE("Expected (vp == 54321)");
        TEST_CHECK(vp && vp->vp_uint32 == 54321);
+
+       talloc_free(group);
 }
 
 static void test_fr_pair_delete_by_da(void)