The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
pair_tests.c
Go to the documentation of this file.
1/*
2 * This library is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU Lesser General Public
4 * License as published by the Free Software Foundation; either
5 * version 2.1 of the License, or (at your option) any later version.
6 *
7 * This library is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 * Lesser General Public License for more details.
11 *
12 * You should have received a copy of the GNU Lesser General Public
13 * License along with this library; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
15 */
16
17/** Tests for a AVP manipulation and search API.
18 *
19 * @file src/lib/util/pair_tests.c
20 * @author Jorge Pereira <jpereira@freeradius.org>
21 * @copyright 2020 Network RADIUS SAS (legal@networkradius.com)
22 */
23
24/**
25 * The 'TEST_INIT' macro provided by 'acutest.h' allowing to register a function to be called
26 * before call the unit tests. Therefore, It calls the function ALL THE TIME causing an overhead.
27 * That is why we are initializing test_init() by "__attribute__((constructor));" reducing the
28 * test execution by 50% of the time.
29 */
30#define USE_CONSTRUCTOR
31
32/*
33 * It should be declared before include the "acutest.h"
34 */
35#ifdef USE_CONSTRUCTOR
36static void test_init(void) __attribute__((constructor));
37#else
38static void test_init(void);
39# define TEST_INIT test_init()
40#endif
41
42#include <freeradius-devel/util/acutest.h>
43#include <freeradius-devel/util/acutest_helpers.h>
44#include <freeradius-devel/util/pair_test_helpers.h>
45
46#include <freeradius-devel/util/conf.h>
47#include <freeradius-devel/util/dict.h>
48
49#ifdef HAVE_GPERFTOOLS_PROFILER_H
50# include <gperftools/profiler.h>
51#endif
52
53static TALLOC_CTX *autofree;
55static fr_dict_t *test_dict;
56
57/** Global initialisation
58 */
59static void test_init(void)
60{
62 if (!autofree) {
63 error:
64#ifdef TEST_NESTED_PAIRS
65 fr_perror("pair_nested_tests");
66#else
67 fr_perror("pair_tests");
68#endif
69 fr_exit_now(EXIT_FAILURE);
70 }
71
72 /*
73 * Mismatch between the binary and the libraries it depends on
74 */
75 if (fr_check_lib_magic(RADIUSD_MAGIC_NUMBER) < 0) goto error;
76
77 if (fr_dict_test_init(autofree, &test_dict, NULL) < 0) goto error;
78
79 /* Initialize the "test_pairs" list */
81
82#ifdef TEST_NESTED_PAIRS
83 if (fr_pair_test_list_alloc_nested(autofree, &test_pairs, NULL) < 0) goto error;
84#else
85 if (fr_pair_test_list_alloc(autofree, &test_pairs, NULL) < 0) goto error;
86#endif
87}
88
89/*
90 * Tests functions
91 */
92static void test_fr_pair_afrom_da(void)
93{
95
96 TEST_CASE("Allocation using fr_pair_afrom_da");
98
99 TEST_CHECK(vp != NULL);
100 if (!vp) return;
101
103
104 TEST_CASE("Validating PAIR_VERIFY()");
106
107 TEST_CHECK(vp && strcmp(vp->vp_strvalue, test_string) == 0);
108 TEST_MSG("Expected vp->vp_strvalue == test_string");
109
111}
112
114{
115 fr_pair_t *vp;
116 unsigned int attr = FR_TEST_ATTR_STRING;
117
118 TEST_CASE("Allocation using fr_pair_afrom_child_num");
120
121 TEST_CASE("Validating PAIR_VERIFY()");
123
124 TEST_CHECK(vp && vp->da->attr == FR_TEST_ATTR_STRING);
125 TEST_MSG("Expected attr(%u) == vp->da->attr(%u)", attr, vp->da->attr);
126
128}
129
131{
132 fr_pair_t *vp, *parent = NULL;
134
136
137 TEST_CASE("Allocation using fr_pair_afrom_da_nested");
139
141 TEST_MSG("Expected attr(%s) == vp->da->attr(%s)", fr_dict_attr_test_tlv_string->name, vp->da->name);
142
143 TEST_CASE("Validating PAIR_VERIFY()");
145
146 TEST_CASE("Top list does not have the tlv child attribute");
148
149 TEST_CASE("Top list does have the tlv attribute");
151 TEST_ASSERT(parent != NULL);
152
153 TEST_CASE("Parent list does have the tlv child attribute");
155
156 talloc_free(parent); /* not vp! */
157}
158
160{
161 int count;
162 fr_pair_t *vp, *parent = NULL;
164
166
167 TEST_CASE("Allocation using fr_pair_afrom_da_nested");
169
171 TEST_MSG("Expected attr(%s) == vp->da->attr(%s)", fr_dict_attr_test_tlv_string->name, vp->da->name);
172
173 TEST_CASE("Deleted nested pair");
175
176 TEST_CASE("Top list still has the tlv attribute");
178 TEST_ASSERT(parent != NULL);
179
180 TEST_CASE("Parent list does not have the tlv child attribute");
182
184}
185
191
192
193static void test_fr_pair_copy(void)
194{
195 fr_pair_t *vp, *copy;
196
197 TEST_CASE("Allocation using fr_pair_copy");
199
200 TEST_CASE("Validating PAIR_VERIFY()");
202
203 copy = fr_pair_copy(autofree, vp);
204
205 TEST_CASE("Validating PAIR_VERIFY()");
206 PAIR_VERIFY(copy);
207
208 vp->op = T_OP_CMP_EQ;
209
210 TEST_CASE("Compare fr_pair_cmp(copy == vp) should be TRUE");
211 TEST_CHECK(fr_pair_cmp(vp, copy) == 1);
212
214 talloc_free(copy);
215}
216
217static void test_fr_pair_steal(void)
218{
219 fr_pair_t *vp;
220 TALLOC_CTX *ctx = talloc_null_ctx();
221
222 TEST_CASE("Allocate a new attribute fr_pair_afrom_da");
224
225 TEST_CASE("Validating PAIR_VERIFY()");
227
228 TEST_CASE("Stealing 'vp' pair using fr_pair_steal()");
229 fr_pair_steal(autofree, vp); /* It should exit without memory-leaks */
230
231 TEST_CASE("Checking if talloc_parent(vp) == autofree");
232 TEST_CHECK(talloc_parent(vp) == autofree);
233}
234
236{
237 fr_pair_t *vp;
238 uint8_t value = 0;
239
240 TEST_CASE("Allocate a new attribute fr_pair_afrom_da");
242
243 TEST_CASE("Validating PAIR_VERIFY()");
245
246 TEST_CASE("Converting regular 'vp' as unknown");
248
249 TEST_CASE("Checking if a real 'raw' vp");
250 TEST_CHECK(vp && vp->vp_raw);
251}
252
254{
255 fr_pair_t *vp, *needle;
256 fr_dcursor_t cursor;
257
258 TEST_CASE("Searching for fr_dict_attr_test_uint32 using fr_pair_dcursor_by_da_init()");
259 needle = NULL;
261 vp;
262 vp = fr_dcursor_next(&cursor)) {
263 if (!needle) {
264 needle = vp;
265 continue;
266 }
267 TEST_CHECK(1 == 1); /* this never will be reached */
268 }
269
270 TEST_CASE("Validating PAIR_VERIFY()");
271
272 TEST_CHECK(needle != NULL);
273 if (needle) PAIR_VERIFY(needle);
274
275 TEST_CASE("Expected (needle->da == fr_dict_attr_test_uint32)");
276 TEST_CHECK(needle && needle->da == fr_dict_attr_test_uint32);
277}
278
280{
281 fr_pair_t *vp, *needle;
282 fr_dcursor_t cursor;
283
284 TEST_CASE("Searching for fr_dict_attr_test_tlv_string as ascend of fr_dict_attr_test_tlv using fr_pair_dcursor_by_ancestor_init()");
285 needle = NULL;
287 vp;
288 vp = fr_dcursor_next(&cursor)) {
289 TEST_CHECK(vp != NULL);
291 needle = vp;
292 continue;
293 }
294 }
295
296 TEST_CHECK(needle != NULL);
297
298 TEST_CASE("Validating PAIR_VERIFY()");
299 if (needle) PAIR_VERIFY(needle);
300
301 TEST_CASE("Expected (needle->da == fr_dict_attr_test_tlv_string)");
302 TEST_CHECK(needle && needle->da == fr_dict_attr_test_tlv_string);
303}
304
306{
307 int i = 0;
308 fr_value_box_t *box;
309 fr_dcursor_t cursor;
310 fr_pair_t *vp;
312
314
316 fr_pair_value_strdup(vp, "hello", false);
318
320 vp->vp_uint32 = 6809;
322
324 vp->vp_uint8 = 12;
326
327 TEST_CASE("Searching for fr_dict_attr_test_tlv_string as ascend of fr_dict_attr_test_tlv using fr_pair_dcursor_by_ancestor_init()");
328 for (box = fr_pair_dcursor_value_init(&cursor);
329 box;
330 box = fr_dcursor_next(&cursor), i++) {
331 switch (i) {
332 case 0:
333 TEST_CASE("First box is a string with value 'hello'");
334 TEST_CHECK(box->type == FR_TYPE_STRING);
335 TEST_CHECK(strcmp(box->vb_strvalue, "hello") == 0);
336 break;
337
338 case 1:
339 TEST_CASE("First box is a uint32 with value 6809");
340 TEST_CHECK(box->type == FR_TYPE_UINT32);
341 TEST_CHECK(box->vb_uint32 == 6809);
342 break;
343
344 case 2:
345 TEST_CASE("First box is a uint8 r with value 12");
346 TEST_CHECK(box->type == FR_TYPE_UINT8);
347 TEST_CHECK(box->vb_uint8 == 12);
348 break;
349
350 default:
351 TEST_CASE("Too many pairs");
352 TEST_CHECK(i < 3);
353 break;
354 }
355 }
356
358}
359
361{
362 fr_pair_t *vp;
363
364 TEST_CASE("Search for fr_dict_attr_test_string using fr_pair_find_by_da_idx()");
366
367 TEST_CASE("Validating PAIR_VERIFY()");
369
370 TEST_CASE("Expected (vp->da == fr_dict_attr_test_string)");
372}
373
375{
376 fr_pair_t *vp;
377
378 TEST_CASE("Search for FR_TEST_ATTR_STRING using fr_pair_find_by_child_num_idx()");
380
381 TEST_CASE("Validating PAIR_VERIFY()");
383
384 TEST_CASE("Expected (vp->da == fr_dict_attr_test_string)");
386}
387
389{
390 fr_pair_t *vp1, *vp2, *vp3, *vp4, *vp5, *vp_found;
392
394
395 /*
396 * Build a list with 2 TLV structures, each with different leaf nodes
397 */
401 fr_pair_append(&vp1->vp_group, vp2);
403 fr_pair_append(&vp2->vp_group, vp1);
407 fr_pair_append(&vp2->vp_group, vp3);
409 fr_pair_append(&vp3->vp_group, vp2);
410
412 TEST_CASE("Find child node in first TLV");
413 TEST_CHECK_PAIR(vp_found, vp1);
414
416 TEST_CASE("Find child node in second TLV");
417 TEST_CHECK_PAIR(vp_found, vp2);
418
420 TEST_CASE("Look for child in first node after second");
421 TEST_CHECK_PAIR(vp_found, NULL);
422
423 /*
424 * Add third nested TLV with child of same type as first
425 */
429 fr_pair_append(&vp3->vp_group, vp4);
431 fr_pair_append(&vp4->vp_group, vp3);
432
433 /*
434 * Repeat search 3 times to find both instances and then NULL
435 */
437 TEST_CASE("Find child node in first TLV");
438 TEST_CHECK_PAIR(vp_found, vp1);
439
441 TEST_CASE("Find child node in third TLV");
442 TEST_CHECK_PAIR(vp_found, vp3);
443
445 TEST_CASE("Find child node after third TLV");
446 TEST_CHECK_PAIR(vp_found, NULL);
447
448 /*
449 * Add some "flat list" attributes
450 */
455
456 /*
457 * Repeat search 5 times to find all instances and then NULL
458 * fr_pair_find_by_da_nested searches nested first then flat
459 */
461 TEST_CASE("Find child node in first TLV");
462 TEST_CHECK_PAIR(vp_found, vp1);
463
465 TEST_CASE("Find child node in third TLV");
466 TEST_CHECK_PAIR(vp_found, vp3);
467
469 TEST_CASE("Find first entry in \"flat\" list");
470 TEST_CHECK_PAIR(vp_found, vp4);
471
473 TEST_CASE("Find second \"flat\" list entry");
474 TEST_CHECK_PAIR(vp_found, vp5);
475
477 TEST_CASE("Find NULL at end of list");
478 TEST_CHECK_PAIR(vp_found, NULL);
479
481}
482
483static void test_fr_pair_append(void)
484{
485 fr_dcursor_t cursor;
486 fr_pair_t *vp;
488 size_t count = 0;
489
490 TEST_CASE("Add 3 pairs using fr_pair_append()");
491
493
500
501 /* lets' count */
502 for (vp = fr_pair_dcursor_init(&cursor, &local_pairs);
503 vp;
504 vp = fr_dcursor_next(&cursor)) count++;
505
506 TEST_CASE("Expected (count == 3)");
507 TEST_CHECK(count == 3);
508
510}
511
513{
514 fr_pair_t *leaf1, *leaf2, *found, *inter1, *inter2;
516 int ret;
517
519
520 TEST_CASE("Add nested attribute including parents");
522 TEST_CHECK(ret == 0);
523 TEST_CHECK(leaf1 != NULL);
524
525 TEST_CASE("Check nested attributes added");
527 TEST_ASSERT(found != NULL);
528 inter1 = found;
529 found = fr_pair_find_by_da(&inter1->vp_group, NULL, fr_dict_attr_test_nested_child_tlv);
530 TEST_ASSERT(found != NULL);
531 inter2 = found;
532 found = fr_pair_find_by_da(&inter2->vp_group, NULL, fr_dict_attr_test_nested_leaf_int32);
533 TEST_CHECK_PAIR(found, leaf1);
534
535 TEST_CASE("Ensure no flat list attribute created");
537 TEST_CHECK_PAIR(found, NULL);
538
539 TEST_CASE("Add additional nested attribute where parents exist");
541 TEST_CHECK(ret == 0);
542 TEST_CHECK(leaf2 != NULL);
543 TEST_CHECK(leaf2 != leaf1);
544
545 TEST_CASE("Check additional leaf added under existing parent");
546 found = fr_pair_find_by_da(&inter2->vp_group, NULL, fr_dict_attr_test_nested_leaf_string);
547 TEST_CHECK_PAIR(found, leaf2);
548
549 TEST_CASE("Check no extra parent attributes created");
551 TEST_CHECK_PAIR(found, inter1);
553 TEST_CHECK_PAIR(found, NULL);
554
555 found = fr_pair_find_by_da(&inter1->vp_group, NULL, fr_dict_attr_test_nested_child_tlv);
556 TEST_CHECK_PAIR(found, inter2);
557 found = fr_pair_find_by_da(&inter1->vp_group, inter2, fr_dict_attr_test_nested_child_tlv);
558 TEST_CHECK_PAIR(found, NULL);
559
561}
562
564{
565 TEST_CASE("Delete fr_dict_attr_test_string using fr_pair_delete_by_child_num()");
567
568 TEST_CASE("The fr_dict_attr_test_string shouldn't exist in 'test_pairs'");
570
571 TEST_CASE("Add fr_dict_attr_test_string back into 'test_pairs'");
573}
574
576{
577 fr_dcursor_t cursor;
578 fr_pair_t *vp;
580 TALLOC_CTX *ctx = talloc_null_ctx();
581
583
584 TEST_CASE("Add using fr_pair_prepend_by_da()");
586
587 /* lets' count */
588 for (vp = fr_pair_dcursor_init(&cursor, &local_pairs);
589 vp;
590 vp = fr_dcursor_next(&cursor)) {
591 TEST_CASE("Expected (vp->da == fr_dict_attr_test_string)");
593 }
594
596}
597
599{
600 fr_pair_t *vp, *group;
601
603 if (!group) return; /* quiet clang scan */
604
605 TEST_CASE("Update Add using fr_pair_prepend_by_da()");
606 TEST_CHECK(fr_pair_update_by_da_parent(group, &vp, fr_dict_attr_test_uint32) == 0); /* attribute doesn't exist in this group */
607 vp->vp_uint32 = 54321;
608
609 TEST_CASE("Expected fr_dict_attr_test_uint32 (vp->vp_uint32 == 54321)");
610 TEST_CHECK((vp = fr_pair_find_by_da(&group->vp_group, NULL, fr_dict_attr_test_uint32)) != NULL);
611
612 TEST_CASE("Validating PAIR_VERIFY()");
614
615 TEST_CASE("Expected (vp == 54321)");
616 TEST_CHECK(vp && vp->vp_uint32 == 54321);
617
618 talloc_free(group);
619}
620
622{
623 TEST_CASE("Delete fr_dict_attr_test_string using fr_pair_delete_by_da()");
625
626 TEST_CASE("The fr_dict_attr_test_string shouldn't exist in 'test_pairs'");
628
629 TEST_CASE("Add fr_dict_attr_test_string back into 'test_pairs'");
631}
632
633static void test_fr_pair_delete(void)
634{
635 fr_pair_t *vp;
636
637 TEST_CASE("Delete fr_dict_attr_test_string using fr_pair_delete()");
640
641 TEST_CASE("The fr_dict_attr_test_string shouldn't exist in 'test_pairs'");
643
644 TEST_CASE("Add fr_dict_attr_test_string back into 'test_pairs'");
646}
647
648static void test_fr_pair_cmp(void)
649{
650 fr_pair_t *vp1, *vp2;
651
652 TEST_CASE("Create the vp1 'Test-Integer = 123'");
654
655 TEST_CASE("Validating PAIR_VERIFY()");
656 PAIR_VERIFY(vp1);
657
658 vp1->op = T_OP_EQ;
659 vp1->vp_uint32 = 123;
660
661 TEST_CASE("Create the vp2 'Test-Integer = 321'");
663
664 TEST_CASE("Validating PAIR_VERIFY()");
665 PAIR_VERIFY(vp2);
666
667 vp2->op = T_OP_CMP_EQ;
668 vp2->vp_uint32 = 321;
669
670 TEST_CASE("Compare fr_pair_cmp(vp1 == vp2) should be FALSE");
671 TEST_CHECK(fr_pair_cmp(vp1, vp2) == 0);
672}
673
674static void test_fr_pair_list_cmp(void)
675{
676 fr_pair_list_t local_pairs1, local_pairs2;
677
678 fr_pair_list_init(&local_pairs1);
679 fr_pair_list_init(&local_pairs2);
680
681 TEST_CASE("Create 'local_pairs1'");
682 TEST_CHECK(fr_pair_test_list_alloc(autofree, &local_pairs1, NULL) == 0);
683
684 TEST_CASE("Create 'local_pairs2'");
685 TEST_CHECK(fr_pair_test_list_alloc(autofree, &local_pairs2, NULL) == 0);
686
687 TEST_CASE("Check if 'local_pairs1' == 'local_pairs2' using fr_pair_list_cmp()");
688 TEST_CHECK(fr_pair_list_cmp(&local_pairs1, &local_pairs2) == 0);
689
690 fr_pair_list_free(&local_pairs1);
691 fr_pair_list_free(&local_pairs2);
692}
693
694static void test_fr_pair_list_copy(void)
695{
697
699
700 TEST_CASE("Copy 'test_pairs' into 'local_pairs'");
702
703 TEST_CASE("Check if 'local_pairs' == 'test_pairs' using fr_pair_list_cmp()");
705
707}
708
710{
711 fr_dcursor_t cursor;
712 fr_pair_t *vp;
714
716
717 TEST_CASE("Copy 'test_pairs' into 'local_pairs'");
719
720 TEST_CASE("The 'local_pairs' should have only fr_dict_attr_test_string");
721 for (vp = fr_pair_dcursor_init(&cursor, &local_pairs);
722 vp;
723 vp = fr_dcursor_next(&cursor)) {
724 TEST_CASE("Validating PAIR_VERIFY()");
726
727 TEST_CASE("Expected (vp->da == fr_dict_attr_test_string)");
729 }
730
732}
733
735{
736 fr_pair_t *vp;
738
740
741 TEST_CASE("Copy 'test_pairs' into 'local_pairs'");
743
744 TEST_CASE("The 'local_pairs' should have only one attribute in it");
746
747 TEST_CASE("The 'local_pairs' should have only fr_dict_attr_test_tlv_string (ancestor of 'Test-TLV-Root'");
749
750 TEST_CASE("Validating we copied the attribute");
751 TEST_CHECK(vp != NULL);
752 if (!vp) return;
753
754#ifdef TEST_NESTED_PAIRS
755 TEST_CASE("Expected copied attribute == fr_dict_attr_test_tlv)");
757#else
758 TEST_CASE("Expected copied attribute == fr_dict_attr_test_tlv_string)");
760#endif
761
762 TEST_CASE("Verifying the copied attribute");
764
765 TEST_CASE("Expecting nothing else in local list");
767
769}
770
771static void test_fr_pair_list_sort(void)
772{
773 fr_dcursor_t cursor;
774 fr_pair_t *vp;
776 TALLOC_CTX *ctx = talloc_null_ctx();
777
778 TEST_CASE("Create 'local_pairs' with 3 attributes not ordered");
780
781 TEST_CASE("Add fr_dict_attr_test_string back into 'local_pairs'");
786 TEST_CHECK(fr_pair_prepend_by_da(ctx, NULL, &local_pairs, fr_dict_attr_test_enum) == 0); // It will be go to the tail
788
789 /*
790 * FIXME - This test doesn't check for intra-type stability
791 */
792 TEST_CASE("Sorting 'local_pairs' by fr_pair_list_sort(local_pairs, fr_pair_cmp_by_da)");
794
795 TEST_CASE("1st (da == fr_dict_attr_test_string)");
796 TEST_CHECK((vp = fr_pair_dcursor_init(&cursor, &local_pairs)) != NULL);
798
799 TEST_CASE("2nd (da == fr_dict_attr_test_octets)");
800 TEST_CHECK((vp = fr_dcursor_next(&cursor)) != NULL);
802
803 TEST_CASE("3rd (da == fr_dict_attr_test_ipv4_addr)");
804 TEST_CHECK((vp = fr_dcursor_next(&cursor)) != NULL);
806
807 TEST_CASE("4th (da == fr_dict_attr_test_uint32)");
808 TEST_CHECK((vp = fr_dcursor_next(&cursor)) != NULL);
810
811 TEST_CASE("5th (da == fr_dict_attr_test_date)");
812 TEST_CHECK((vp = fr_dcursor_next(&cursor)) != NULL);
814
815 TEST_CASE("6th (da == fr_dict_attr_test_enum)");
816 TEST_CHECK((vp = fr_dcursor_next(&cursor)) != NULL);
818
820}
821
822static void test_fr_pair_value_copy(void)
823{
824 fr_pair_t *vp1, *vp2;
825
826 TEST_CASE("Create 'vp1' with Test-Integer = 123");
828 vp1->vp_uint32 = 123;
829
830 TEST_CASE("Validating PAIR_VERIFY()");
831 PAIR_VERIFY(vp1);
832
833 TEST_CASE("Create 'vp2'");
835
836 TEST_CASE("Validating PAIR_VERIFY()");
837 PAIR_VERIFY(vp2);
838
839 TEST_CASE("Copy 'vp1' to 'vp2' using fr_pair_value_copy()");
840 TEST_CHECK(fr_pair_value_copy(vp2, vp1) == 0);
841
842 TEST_CASE("Validating PAIR_VERIFY()");
843 PAIR_VERIFY(vp2);
844
845 TEST_CASE("Check (vp1 == vp2)");
846 TEST_CHECK(vp2->vp_uint32 == 123);
847}
848
850{
851 fr_pair_t *vp;
852
853 TEST_CASE("Find 'Test-String'");
855
856 TEST_CASE("Validating PAIR_VERIFY()");
858
859 TEST_CASE("Convert 'test_string' value to attribute value using fr_pair_value_from_str()");
861
862 TEST_CASE("Validating PAIR_VERIFY()");
864
865 TEST_CASE("Check (vp->vp_string == test_string)");
866 TEST_CHECK(vp && strcmp(vp->vp_strvalue, test_string) == 0);
867}
868
870{
871 fr_pair_t *vp;
872
873 TEST_CASE("Find 'Test-String'");
875
876 TEST_CASE("Validating PAIR_VERIFY()");
878
879 TEST_CASE("Copy content of 'test_string' to attribute value using fr_pair_value_strdup()");
881
882 TEST_CASE("Validating PAIR_VERIFY()");
884
885 TEST_CASE("Check (vp->vp_string == test_string)");
886 TEST_CHECK(vp && strcmp(vp->vp_strvalue, test_string) == 0);
887}
888
890{
891 fr_pair_t *vp, *nvp;
892 char *copy_test_string;
893
894 TEST_CASE("Find 'Test-String'");
896
897 TEST_CASE("Validating PAIR_VERIFY()");
899
900 MEM(nvp = fr_pair_copy(NULL, vp));
901
902 copy_test_string = talloc_strdup(nvp, test_string);
903 talloc_set_type(copy_test_string, char);
904
905 TEST_CASE("Copy content of 'test_string' to attribute value using fr_pair_value_strdup_shallow()");
906 TEST_CHECK(fr_pair_value_strdup_shallow(nvp, copy_test_string, true) == 0);
907
908 TEST_CASE("Validating PAIR_VERIFY()");
909 PAIR_VERIFY(nvp);
910
911 TEST_CASE("Check (vp->vp_string == copy_test_string)");
912 TEST_CHECK(nvp && strncmp(nvp->vp_strvalue, test_string, strlen(copy_test_string)) == 0);
913
914 talloc_free(nvp);
915}
916
918{
919 fr_pair_t *vp;
920
921 TEST_CASE("Find 'Test-String'");
923
924 TEST_CASE("Validating PAIR_VERIFY()");
926
927 TEST_CASE("Copy content of 'test_string' to attribute value using fr_pair_value_strdup_shallow()");
929
930 TEST_CASE("Trim the length of the string buffer using fr_pair_value_strtrim()");
932
933 TEST_CASE("Validating PAIR_VERIFY()");
935
936 TEST_CASE("Check (vp->vp_string == test_string)");
937 TEST_CHECK(vp && strcmp(vp->vp_strvalue, test_string) == 0);
938}
939
941{
942 fr_pair_t *vp;
943 char fmt_test[64];
944 fr_time_t now = fr_time();
945
946 snprintf(fmt_test, sizeof(fmt_test), "Now is %"PRId64, fr_time_unwrap(now));
947
948 TEST_CASE("Find 'Test-String'");
950
951 TEST_CASE("Validating PAIR_VERIFY()");
953
954 TEST_CASE("Copy content of 'fmt_test' to attribute value using fr_pair_value_aprintf()");
955 TEST_CHECK(fr_pair_value_aprintf(vp, "Now is %"PRId64, fr_time_unwrap(now)) == 0);
956
957 TEST_CASE("Validating PAIR_VERIFY()");
959
960 TEST_CASE("Check (vp->vp_string == fmt_test)");
961 TEST_CHECK(vp && strcmp(vp->vp_strvalue, fmt_test) == 0);
962}
963
965{
966 fr_pair_t *vp;
967 char *out = NULL;
968
969 TEST_CASE("Find 'Test-String'");
971
972 TEST_CASE("Validating PAIR_VERIFY()");
974
975 TEST_CASE("Pre-allocate a memory buffer using fr_pair_value_bstr_alloc()");
977
978 TEST_CASE("Validating PAIR_VERIFY()");
980
981 TEST_CASE("Copy 'test_string' to the pre-allocated pointer");
983
984 TEST_CASE("Check (out == test_string)");
985 TEST_CHECK(memcmp(out, test_string, test_string_len-1) == 0);
986
987 TEST_CASE("Check (vp->vp_string == test_string)");
988 TEST_CHECK(vp && memcmp(vp->vp_strvalue, test_string, test_string_len-1) == 0);
989}
990
992{
993 fr_pair_t *vp;
994 char *out = NULL;
995
996 TEST_CASE("Find 'Test-String'");
998
999 TEST_CASE("Validating PAIR_VERIFY()");
1000 PAIR_VERIFY(vp);
1001
1002 TEST_CASE("Pre-allocate 1 byte of memory buffer using fr_pair_value_bstr_alloc()");
1003 TEST_CHECK(fr_pair_value_bstr_alloc(vp, &out, 1, false) == 0);
1004
1005 TEST_CASE("Re-allocate (test_string_len-1) byte of memory buffer using fr_pair_value_bstr_realloc()");
1007
1008 TEST_CASE("Validating PAIR_VERIFY()");
1009 PAIR_VERIFY(vp);
1010
1011 TEST_CASE("Copy 'test_string' to the pre-allocated pointer");
1013
1014 TEST_CASE("Check (out == test_string)");
1015 TEST_CHECK(memcmp(out, test_string, test_string_len-1) == 0);
1016
1017 TEST_CASE("Check (vp->vp_string == test_string)");
1018 TEST_CHECK(vp && memcmp(vp->vp_strvalue, test_string, test_string_len-1) == 0);
1019}
1020
1022{
1023 fr_pair_t *vp;
1024
1025 TEST_CASE("Find 'Test-String'");
1027
1028 TEST_CASE("Validating PAIR_VERIFY()");
1029 PAIR_VERIFY(vp);
1030
1031 TEST_CASE("Copy content of 'test_string' to attribute value using fr_pair_value_bstrndup()");
1033
1034 TEST_CASE("Check (vp->vp_string == test_string)");
1035 TEST_CHECK(vp && memcmp(vp->vp_strvalue, test_string, test_string_len-1) == 0);
1036}
1037
1039{
1040 fr_pair_t *vp;
1041 char *copy_test_string;
1042
1043 TEST_CASE("Find 'Test-String'");
1045
1046 TEST_CASE("Validating PAIR_VERIFY()");
1047 PAIR_VERIFY(vp);
1048
1049 copy_test_string = talloc_strdup(vp, test_string);
1050 talloc_set_type(copy_test_string, char);
1051
1052 TEST_CASE("Copy content of 'copy_test_string' to attribute value using fr_pair_value_bstrdup_buffer()");
1053 TEST_CHECK(fr_pair_value_bstrdup_buffer(vp, copy_test_string, false) == 0);
1054
1055 TEST_CASE("Check (vp->vp_string == test_string)");
1056 TEST_CHECK(vp && strcmp(vp->vp_strvalue, copy_test_string) == 0);
1057
1058 talloc_free(copy_test_string);
1059}
1060
1062{
1063 fr_pair_t *vp;
1064 char *copy_test_string;
1065
1066 TEST_CASE("Find 'Test-String'");
1068
1069 TEST_CASE("Validating PAIR_VERIFY()");
1070 PAIR_VERIFY(vp);
1071
1072 copy_test_string = talloc_strdup(vp, test_string);
1073 talloc_set_type(copy_test_string, char);
1074
1075 TEST_CASE("Copy content of 'test_string' to attribute value using fr_pair_value_bstrndup_shallow()");
1076 TEST_CHECK(fr_pair_value_bstrndup_shallow(vp, copy_test_string, strlen(copy_test_string), true) == 0);
1077
1078 TEST_CASE("Check (vp->vp_string == copy_test_string)");
1079 TEST_CHECK(vp && strncmp(vp->vp_strvalue, test_string, test_string_len) == 0);
1080
1081 talloc_free(copy_test_string);
1082}
1083
1085{
1086 fr_pair_t *vp;
1087 char *copy_test_string;
1088
1089 TEST_CASE("Find 'Test-String'");
1091
1092 TEST_CASE("Validating PAIR_VERIFY()");
1093 PAIR_VERIFY(vp);
1094
1095 copy_test_string = talloc_strdup(vp, test_string);
1096 talloc_set_type(copy_test_string, char);
1097
1098 TEST_CASE("Copy content of 'test_string' to attribute value using fr_pair_value_bstrdup_buffer_shallow()");
1099 TEST_CHECK(fr_pair_value_bstrdup_buffer_shallow(vp, copy_test_string, true) == 0);
1100
1101 TEST_CASE("Check (vp->vp_string == copy_test_string)");
1102 TEST_CHECK(vp && strncmp(vp->vp_strvalue, test_string, test_string_len) == 0);
1103
1104 talloc_free(copy_test_string);
1105}
1106
1108{
1109 fr_pair_t *vp;
1110 uint8_t *out;
1111
1112 TEST_CASE("Find 'Test-Octets'");
1114
1115 TEST_CASE("Validating PAIR_VERIFY()");
1116 PAIR_VERIFY(vp);
1117
1118 TEST_CASE("Pre-allocate a memory buffer using fr_pair_value_bstr_alloc()");
1120
1121 TEST_CASE("Copy 'test_octets' to the pre-allocated pointer");
1123
1124 TEST_CASE("Check (out == test_octets)");
1126
1127 TEST_CASE("Check (vp->vp_octets == test_octets)");
1128 TEST_CHECK(vp && memcmp(vp->vp_octets, test_octets, NUM_ELEMENTS(test_octets)) == 0);
1129}
1130
1132{
1133 fr_pair_t *vp;
1134 uint8_t *out;
1135
1136 TEST_CASE("Find 'Test-Octets'");
1138
1139 TEST_CASE("Validating PAIR_VERIFY()");
1140 PAIR_VERIFY(vp);
1141
1142 TEST_CASE("Pre-allocate a memory buffer using fr_pair_value_bstr_alloc()");
1144
1145 TEST_CASE("Copy 'test_octets' to the pre-allocated pointer");
1147
1148 TEST_CASE("Realloc pre-allocated pointer to fit extra 'test_octets' copy");
1150
1151 TEST_CASE("Copy 'test_octets' into the tail");
1153
1154 TEST_CASE("Check first chunk (out == test_octets)");
1156
1157 TEST_CHECK(vp != NULL);
1158
1159 TEST_CASE("Check first chunk (vp->vp_octets == test_octets)");
1160 TEST_CHECK(vp && memcmp(vp->vp_octets, test_octets, NUM_ELEMENTS(test_octets)) == 0);
1161
1162 TEST_CASE("Check second chunk (out+NUM_ELEMENTS(test_octets) == test_octets)");
1164
1165 TEST_CASE("Check second chunk (vp->vp_octets+NUM_ELEMENTS(test_octets) == test_octets)");
1167}
1168
1170{
1171 fr_pair_t *vp;
1172
1173 TEST_CASE("Find 'Test-Octets'");
1175
1176 TEST_CASE("Validating PAIR_VERIFY()");
1177 PAIR_VERIFY(vp);
1178
1179 TEST_CASE("Copy content of 'test_octets' to attribute value using fr_pair_value_memdup()");
1181
1182 TEST_CASE("Check (vp->vp_octets == test_octets)");
1183 TEST_CHECK(vp && memcmp(vp->vp_octets, test_octets, NUM_ELEMENTS(test_octets)) == 0);
1184}
1185
1187{
1188 fr_pair_t *vp;
1189 uint8_t *copy_test_octets;
1190
1191 TEST_CASE("Find 'Test-Octets'");
1193
1194 TEST_CASE("Validating PAIR_VERIFY()");
1195 PAIR_VERIFY(vp);
1196
1197 copy_test_octets = talloc_memdup(vp, test_octets, NUM_ELEMENTS(test_octets));
1198 talloc_set_type(copy_test_octets, uint8_t);
1199
1200 TEST_CASE("Copy content of 'test_octets' to attribute value using fr_pair_value_memdup_buffer()");
1201 TEST_CHECK(fr_pair_value_memdup_buffer(vp, copy_test_octets, true) == 0);
1202
1203 TEST_CASE("Check (vp->vp_octets == test_octets)");
1204 TEST_CHECK(vp && memcmp(vp->vp_octets, test_octets, NUM_ELEMENTS(test_octets)) == 0);
1205
1206 talloc_free(copy_test_octets);
1207}
1208
1210{
1211 fr_pair_t *vp;
1212 uint8_t *copy_test_octets;
1213
1214 TEST_CASE("Find 'Test-Octets'");
1216
1217 TEST_CASE("Validating PAIR_VERIFY()");
1218 PAIR_VERIFY(vp);
1219
1220 copy_test_octets = talloc_memdup(vp, test_octets, NUM_ELEMENTS(test_octets));
1221 talloc_set_type(copy_test_octets, uint8_t);
1222
1223 TEST_CASE("Copy content of 'test_octets' to attribute value using fr_pair_value_memdup_shallow()");
1224 TEST_CHECK(fr_pair_value_memdup_shallow(vp, copy_test_octets, NUM_ELEMENTS(test_octets), true) == 0);
1225
1226 TEST_CASE("Check (vp->vp_octets == test_octets)");
1227 TEST_CHECK(vp && memcmp(vp->vp_octets, test_octets, NUM_ELEMENTS(test_octets)) == 0);
1228
1229 talloc_free(copy_test_octets);
1230}
1231
1233{
1234 fr_pair_t *vp;
1235 uint8_t *copy_test_octets;
1236
1237 TEST_CASE("Find 'Test-Octets'");
1239
1240 TEST_CASE("Validating PAIR_VERIFY()");
1241 PAIR_VERIFY(vp);
1242
1243 copy_test_octets = talloc_memdup(vp, test_octets, NUM_ELEMENTS(test_octets));
1244 talloc_set_type(copy_test_octets, uint8_t);
1245
1246 TEST_CASE("Copy content of 'test_octets' to attribute value using fr_pair_value_memdup_buffer_shallow()");
1247 TEST_CHECK(fr_pair_value_memdup_buffer_shallow(vp, copy_test_octets, true) == 0);
1248
1249 TEST_CASE("Check (vp->vp_octets == copy_test_octets)");
1250 TEST_CHECK(vp && memcmp(vp->vp_octets, test_octets, NUM_ELEMENTS(test_octets)) == 0);
1251
1252 talloc_free(copy_test_octets);
1253}
1254
1256{
1257 fr_pair_t *vp;
1258 char const *var;
1259 char buf[20];
1260
1261 TEST_CASE("Find 'Test-Values'");
1263
1264 TEST_CASE("Validating PAIR_VERIFY()");
1265 PAIR_VERIFY(vp);
1266
1267 vp->vp_uint32 = 123;
1268
1269 TEST_CASE("Lookup enum value attribute using fr_pair_value_enum()");
1270
1271 TEST_CHECK((var = fr_pair_value_enum(vp, buf)) != NULL);
1272 TEST_MSG("Checking fr_pair_value_enum()");
1273
1274 TEST_CHECK(var && strcmp(var, "test123") == 0);
1275 TEST_MSG("Expected var == 'test123'");
1276}
1277
1279{
1280 fr_pair_t *vp;
1281 fr_value_box_t const *vb;
1282
1283 TEST_CASE("Find 'Test-Values'");
1285
1286 TEST_CASE("Validating PAIR_VERIFY()");
1287 PAIR_VERIFY(vp);
1288
1289 vp->vp_uint32 = 123;
1290
1291 TEST_CASE("Lookup enum value attribute using fr_pair_value_enum_box()");
1292
1294 TEST_MSG("Checking fr_pair_value_enum()");
1295
1296 TEST_CHECK(vb->vb_uint32 == 123);
1297 TEST_MSG("Expected vb->vb_uint32 == 123");
1298}
1299
1301 /*
1302 * Allocation and management
1303 */
1304 { "fr_pair_afrom_da", test_fr_pair_afrom_da },
1305 { "fr_pair_afrom_child_num", test_fr_pair_afrom_child_num },
1306 { "fr_pair_afrom_da_nested", test_fr_pair_afrom_da_nested },
1307 { "fr_pair_copy", test_fr_pair_copy },
1308 { "fr_pair_steal", test_fr_pair_steal },
1309
1310 /* Searching and list modification */
1311 { "fr_dcursor_iter_by_da_init", test_fr_pair_dcursor_by_da_init },
1312 { "fr_pair_dcursor_by_ancestor_init", test_fr_pair_dcursor_by_ancestor_init },
1313 { "fr_pair_dcursor_value_init", test_fr_pair_dcursor_value_init },
1314 { "fr_pair_raw_afrom_pair", test_fr_pair_raw_afrom_pair },
1315 { "fr_pair_find_by_da_idx", test_fr_pair_find_by_da_idx },
1316 { "fr_pair_find_by_child_num_idx", test_fr_pair_find_by_child_num_idx },
1317 { "fr_pair_find_by_da_nested", test_fr_pair_find_by_da_nested },
1318 { "fr_pair_append", test_fr_pair_append },
1319 { "fr_pair_prepend_by_da", test_fr_pair_prepend_by_da },
1320 { "fr_pair_append_by_da_parent", test_fr_pair_append_by_da_parent },
1321 { "fr_pair_delete_by_child_num", test_fr_pair_delete_by_child_num },
1322 { "fr_pair_update_by_da_parent", test_fr_pair_update_by_da_parent },
1323 { "fr_pair_delete", test_fr_pair_delete },
1324 { "fr_pair_delete_by_da", test_fr_pair_delete_by_da },
1325 { "fr_pair_delete_by_da_nested", test_fr_pair_delete_by_da_nested },
1326
1327 /* Compare */
1328 { "fr_pair_cmp", test_fr_pair_cmp },
1329 { "fr_pair_list_cmp", test_fr_pair_list_cmp },
1330
1331 /* Lists */
1332 { "fr_pair_list_copy", test_fr_pair_list_copy },
1333 { "fr_pair_list_copy_by_da", test_fr_pair_list_copy_by_da },
1334 { "fr_pair_list_copy_by_ancestor", test_fr_pair_list_copy_by_ancestor },
1335 { "fr_pair_list_sort", test_fr_pair_list_sort },
1336
1337 /* Copy */
1338 { "fr_pair_value_copy", test_fr_pair_value_copy },
1339
1340
1341 /* parenting */
1342 { "test_fr_pair_nested_verify", test_fr_pair_nested_verify },
1343
1344 /* Strings */
1345 { "fr_pair_value_from_str", test_fr_pair_value_from_str },
1346 { "fr_pair_value_strdup", test_fr_pair_value_strdup },
1347 { "fr_pair_value_strdup_shallow", test_fr_pair_value_strdup_shallow },
1348 { "fr_pair_value_strtrim", test_fr_pair_value_strtrim },
1349 { "fr_pair_value_aprintf", test_fr_pair_value_aprintf },
1350
1351 /* Assign and manipulate binary-safe strings */
1352 { "fr_pair_value_bstr_alloc", test_fr_pair_value_bstr_alloc },
1353 { "fr_pair_value_bstr_realloc", test_fr_pair_value_bstr_realloc },
1354 { "fr_pair_value_bstrndup", test_fr_pair_value_bstrndup },
1355 { "fr_pair_value_bstrdup_buffer", test_fr_pair_value_bstrdup_buffer },
1356 { "fr_pair_value_bstrndup_shallow", test_fr_pair_value_bstrndup_shallow },
1357 { "fr_pair_value_bstrdup_buffer_shallow", test_fr_pair_value_bstrdup_buffer_shallow },
1358
1359 /* Assign and manipulate octets strings */
1360 { "fr_pair_value_mem_alloc", test_fr_pair_value_mem_alloc },
1361 { "fr_pair_value_mem_realloc", test_fr_pair_value_mem_realloc },
1362 { "fr_pair_value_memdup", test_fr_pair_value_memdup },
1363 { "fr_pair_value_memdup_buffer", test_fr_pair_value_memdup_buffer },
1364 { "fr_pair_value_memdup_shallow", test_fr_pair_value_memdup_shallow },
1365 { "fr_pair_value_memdup_buffer_shallow", test_fr_pair_value_memdup_buffer_shallow },
1366
1367 /* Enum functions */
1368 { "fr_pair_value_enum", test_fr_pair_value_enum },
1369 { "fr_pair_value_enum_box", test_fr_pair_value_enum_box },
1370
1371 { NULL }
1372};
#define TEST_CHECK(cond)
Definition acutest.h:85
#define TEST_CASE(name)
Definition acutest.h:184
#define TEST_ASSERT(cond)
Definition acutest.h:108
#define TEST_MSG(...)
Definition acutest.h:215
#define NUM_ELEMENTS(_t)
Definition build.h:339
static void * fr_dcursor_next(fr_dcursor_t *cursor)
Advanced the cursor to the next item.
Definition dcursor.h:288
#define MEM(x)
Definition debug.h:36
#define fr_exit_now(_x)
Exit without calling atexit() handlers, producing a log message in debug builds.
Definition debug.h:234
bool fr_dict_attr_can_contain(fr_dict_attr_t const *parent, fr_dict_attr_t const *child)
See if a structural da is allowed to contain another da.
Definition dict_util.c:4882
fr_dict_attr_t const * fr_dict_root(fr_dict_t const *dict)
Return the root attribute of a dictionary.
Definition dict_util.c:2407
fr_dict_attr_t const * fr_dict_attr_test_tlv_string
Definition dict_test.c:65
fr_dict_attr_t const * fr_dict_attr_test_nested_leaf_string
Definition dict_test.c:78
fr_dict_attr_t const * fr_dict_attr_test_enum
Definition dict_test.c:81
fr_dict_attr_t const * fr_dict_attr_test_date
Definition dict_test.c:58
fr_dict_attr_t const * fr_dict_attr_test_tlv
Definition dict_test.c:64
fr_dict_attr_t const * fr_dict_attr_test_nested_top_tlv
Definition dict_test.c:76
fr_dict_attr_t const * fr_dict_attr_test_uint32
Definition dict_test.c:47
fr_dict_attr_t const * fr_dict_attr_test_octets
Definition dict_test.c:31
fr_dict_attr_t const * fr_dict_attr_test_string
Definition dict_test.c:30
fr_dict_attr_t const * fr_dict_attr_test_ipv4_addr
Definition dict_test.c:33
fr_dict_attr_t const * fr_dict_attr_test_nested_child_tlv
Definition dict_test.c:77
int fr_dict_test_init(TALLOC_CTX *ctx, fr_dict_t **dict_p, fr_dict_test_attr_t const *test_defs)
Initialise a test dictionary and add our test_defs to it.
Definition dict_test.c:248
fr_dict_attr_t const * fr_dict_attr_test_uint8
Definition dict_test.c:45
fr_dict_attr_t const * fr_dict_attr_test_group
Definition dict_test.c:74
fr_dict_attr_t const * fr_dict_attr_test_nested_leaf_int32
Definition dict_test.c:79
fr_dict_attr_t const * fr_dict_attr_test_vsa
Definition dict_test.c:70
@ FR_TEST_ATTR_STRING
Definition dict_test.h:37
Test enumeration values.
Definition dict_test.h:92
talloc_free(reap)
@ FR_TYPE_STRING
String of printable characters.
@ FR_TYPE_UINT8
8 Bit unsigned integer.
@ FR_TYPE_UINT32
32 Bit unsigned integer.
unsigned char uint8_t
int fr_pair_list_copy_by_da(TALLOC_CTX *ctx, fr_pair_list_t *to, fr_pair_list_t const *from, fr_dict_attr_t const *da, unsigned int count)
Duplicate pairs in a list matching the specified da.
Definition pair.c:2408
int fr_pair_list_cmp(fr_pair_list_t const *a, fr_pair_list_t const *b)
Determine equality of two lists.
Definition pair.c:2049
int fr_pair_value_memdup_buffer(fr_pair_t *vp, uint8_t const *src, bool tainted)
Copy data from a talloced buffer into an "octets" data type.
Definition pair.c:2967
int fr_pair_value_enum_box(fr_value_box_t const **out, fr_pair_t *vp)
Get value box of a VP, optionally prefer enum value.
Definition pair.c:3067
int fr_pair_value_aprintf(fr_pair_t *vp, char const *fmt,...)
Print data into an "string" data type.
Definition pair.c:2701
int fr_pair_delete_by_da_nested(fr_pair_list_t *list, fr_dict_attr_t const *da)
Delete matching pairs from the specified list, and prune any empty branches.
Definition pair.c:1715
int fr_pair_list_copy(TALLOC_CTX *ctx, fr_pair_list_t *to, fr_pair_list_t const *from)
Duplicate a list of pairs.
Definition pair.c:2321
int fr_pair_value_memdup(fr_pair_t *vp, uint8_t const *src, size_t len, bool tainted)
Copy data into an "octets" data type.
Definition pair.c:2937
fr_pair_t * fr_pair_find_by_da_nested(fr_pair_list_t const *list, fr_pair_t const *prev, fr_dict_attr_t const *da)
Find a pair with a matching fr_dict_attr_t, by walking the nested fr_dict_attr_t tree.
Definition pair.c:772
int fr_pair_value_strdup(fr_pair_t *vp, char const *src, bool tainted)
Copy data into an "string" data type.
Definition pair.c:2637
int fr_pair_value_bstrdup_buffer_shallow(fr_pair_t *vp, char const *src, bool tainted)
Assign a string to a "string" type value pair.
Definition pair.c:2858
int fr_pair_value_from_str(fr_pair_t *vp, char const *value, size_t inlen, fr_sbuff_unescape_rules_t const *uerules, UNUSED bool tainted)
Convert string value to native attribute value.
Definition pair.c:2591
fr_pair_t * fr_pair_find_by_da(fr_pair_list_t const *list, fr_pair_t const *prev, fr_dict_attr_t const *da)
Find the first pair with a matching da.
Definition pair.c:695
fr_pair_t * fr_pair_find_by_child_num_idx(fr_pair_list_t const *list, fr_dict_attr_t const *parent, unsigned int attr, unsigned int idx)
Find the pair with the matching child attribute at a given index.
Definition pair.c:895
int fr_pair_cmp(fr_pair_t const *a, fr_pair_t const *b)
Compare two pairs, using the operator from "a".
Definition pair.c:1971
int fr_pair_value_bstrndup_shallow(fr_pair_t *vp, char const *src, size_t len, bool tainted)
Assign a string to a "string" type value pair.
Definition pair.c:2838
int fr_pair_append(fr_pair_list_t *list, fr_pair_t *to_add)
Add a VP to the end of the list.
Definition pair.c:1347
int fr_pair_delete_by_da(fr_pair_list_t *list, fr_dict_attr_t const *da)
Delete matching pairs from the specified list.
Definition pair.c:1691
fr_pair_t * fr_pair_find_by_da_idx(fr_pair_list_t const *list, fr_dict_attr_t const *da, unsigned int idx)
Find a pair with a matching da at a given index.
Definition pair.c:743
fr_pair_t * fr_pair_afrom_da(TALLOC_CTX *ctx, fr_dict_attr_t const *da)
Dynamically allocate a new attribute and assign a fr_dict_attr_t.
Definition pair.c:285
int fr_pair_update_by_da_parent(fr_pair_t *parent, fr_pair_t **out, fr_dict_attr_t const *da)
Return the first fr_pair_t matching the fr_dict_attr_t or alloc a new fr_pair_t and its subtree (and ...
Definition pair.c:1598
int fr_pair_list_copy_by_ancestor(TALLOC_CTX *ctx, fr_pair_list_t *to, fr_pair_list_t const *from, fr_dict_attr_t const *parent_da)
Duplicate pairs in a list where the da is a descendant of parent_da.
Definition pair.c:2457
void fr_pair_list_init(fr_pair_list_t *list)
Initialise a pair list header.
Definition pair.c:46
int fr_pair_value_mem_realloc(fr_pair_t *vp, uint8_t **out, size_t size)
Change the length of a buffer for a "octets" type value pair.
Definition pair.c:2911
char const * fr_pair_value_enum(fr_pair_t const *vp, char buff[20])
Return a const buffer for an enum type attribute.
Definition pair.c:3034
int fr_pair_value_bstrndup(fr_pair_t *vp, char const *src, size_t len, bool tainted)
Copy data into a "string" type value pair.
Definition pair.c:2787
int fr_pair_value_bstr_alloc(fr_pair_t *vp, char **out, size_t size, bool tainted)
Pre-allocate a memory buffer for a "string" type value pair.
Definition pair.c:2733
int fr_pair_value_bstr_realloc(fr_pair_t *vp, char **out, size_t size)
Change the length of a buffer for a "string" type value pair.
Definition pair.c:2758
int fr_pair_delete(fr_pair_list_t *list, fr_pair_t *vp)
Remove fr_pair_t from a list and free.
Definition pair.c:1828
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)
Alloc a new fr_pair_t, adding the parent attributes if required.
Definition pair.c:1525
int fr_pair_delete_by_child_num(fr_pair_list_t *list, fr_dict_attr_t const *parent, unsigned int attr)
Delete matching pairs from the specified list.
Definition pair.c:1810
int fr_pair_value_copy(fr_pair_t *dst, fr_pair_t *src)
Copy the value from one pair to another.
Definition pair.c:2565
int fr_pair_steal(TALLOC_CTX *ctx, fr_pair_t *vp)
Steal one VP.
Definition pair.c:523
int fr_pair_value_memdup_shallow(fr_pair_t *vp, uint8_t const *src, size_t len, bool tainted)
Assign a buffer to a "octets" type value pair.
Definition pair.c:2992
fr_pair_t * fr_pair_copy(TALLOC_CTX *ctx, fr_pair_t const *vp)
Copy a single valuepair.
Definition pair.c:491
int fr_pair_value_mem_alloc(fr_pair_t *vp, uint8_t **out, size_t size, bool tainted)
Pre-allocate a memory buffer for a "octets" type value pair.
Definition pair.c:2886
int fr_pair_value_strtrim(fr_pair_t *vp)
Trim the length of the string buffer to match the length of the C string.
Definition pair.c:2680
fr_pair_t * fr_pair_afrom_da_nested(TALLOC_CTX *ctx, fr_pair_list_t *list, fr_dict_attr_t const *da)
Create a pair (and all intermediate parents), and append it to the list.
Definition pair.c:469
int fr_pair_prepend(fr_pair_list_t *list, fr_pair_t *to_add)
Add a VP to the start of the list.
Definition pair.c:1316
fr_value_box_t * fr_pair_dcursor_value_init(fr_dcursor_t *cursor)
Initialises a special dcursor over a fr_pair_list_t, but which returns fr_value_box_t.
Definition pair.c:1250
int fr_pair_raw_afrom_pair(fr_pair_t *vp, uint8_t const *data, size_t data_len)
Mark malformed attribute as raw.
Definition pair.c:595
int8_t fr_pair_cmp_by_da(void const *a, void const *b)
Order attributes by their da, and tag.
Definition pair.c:1846
int fr_pair_value_memdup_buffer_shallow(fr_pair_t *vp, uint8_t const *src, bool tainted)
Assign a talloced buffer to a "octets" type value pair.
Definition pair.c:3012
int fr_pair_value_strdup_shallow(fr_pair_t *vp, char const *src, bool tainted)
Assign a buffer containing a nul terminated string to a vp, but don't copy it.
Definition pair.c:2661
int fr_pair_prepend_by_da(TALLOC_CTX *ctx, fr_pair_t **out, fr_pair_list_t *list, fr_dict_attr_t const *da)
Alloc a new fr_pair_t (and prepend)
Definition pair.c:1495
fr_pair_t * fr_pair_afrom_child_num(TALLOC_CTX *ctx, fr_dict_attr_t const *parent, unsigned int attr)
Create a new valuepair.
Definition pair.c:373
static fr_pair_list_t test_pairs
static fr_dict_t * test_dict
static int fr_pair_test_list_alloc_nested(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_test_attr_t const *test_defs)
static uint8_t test_octets[]
static int fr_pair_test_list_alloc(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_test_attr_t const *test_defs)
static size_t test_string_len
static char const * test_string
static void test_fr_pair_value_memdup_shallow(void)
TEST_LIST
static void test_fr_pair_list_copy_by_ancestor(void)
Definition pair_tests.c:734
static void test_fr_pair_afrom_child_num(void)
Definition pair_tests.c:113
static void test_fr_pair_value_aprintf(void)
Definition pair_tests.c:940
static void test_fr_pair_value_mem_realloc(void)
static void test_fr_pair_value_memdup_buffer(void)
static void test_fr_pair_value_enum_box(void)
static void test_fr_pair_value_bstrdup_buffer(void)
static void test_fr_pair_value_copy(void)
Definition pair_tests.c:822
static void test_fr_pair_delete(void)
Definition pair_tests.c:633
static void test_fr_pair_list_cmp(void)
Definition pair_tests.c:674
static void test_fr_pair_copy(void)
Definition pair_tests.c:193
static void test_fr_pair_afrom_da(void)
Definition pair_tests.c:92
static void test_fr_pair_value_mem_alloc(void)
static void test_fr_pair_value_bstrndup(void)
static void test_fr_pair_find_by_child_num_idx(void)
Definition pair_tests.c:374
static void test_fr_pair_value_bstrndup_shallow(void)
static void test_fr_pair_value_bstrdup_buffer_shallow(void)
static void test_fr_pair_list_copy(void)
Definition pair_tests.c:694
static void test_fr_pair_value_memdup_buffer_shallow(void)
static void test_fr_pair_value_bstr_realloc(void)
Definition pair_tests.c:991
static void test_fr_pair_dcursor_by_da_init(void)
Definition pair_tests.c:253
static void test_fr_pair_delete_by_da(void)
Definition pair_tests.c:621
static void test_fr_pair_append(void)
Definition pair_tests.c:483
static void test_fr_pair_value_strdup_shallow(void)
Definition pair_tests.c:889
static void test_fr_pair_find_by_da_idx(void)
Definition pair_tests.c:360
static void test_fr_pair_nested_verify(void)
Definition pair_tests.c:186
static void test_fr_pair_value_strtrim(void)
Definition pair_tests.c:917
static void test_fr_pair_value_enum(void)
static void test_fr_pair_value_bstr_alloc(void)
Definition pair_tests.c:964
static void test_fr_pair_list_sort(void)
Definition pair_tests.c:771
static void test_fr_pair_value_strdup(void)
Definition pair_tests.c:869
static void test_fr_pair_cmp(void)
Definition pair_tests.c:648
static void test_fr_pair_prepend_by_da(void)
Definition pair_tests.c:575
static void test_fr_pair_afrom_da_nested(void)
Definition pair_tests.c:130
static void test_fr_pair_list_copy_by_da(void)
Definition pair_tests.c:709
static void test_fr_pair_value_from_str(void)
Definition pair_tests.c:849
static void test_fr_pair_append_by_da_parent(void)
Definition pair_tests.c:512
static void test_fr_pair_steal(void)
Definition pair_tests.c:217
static void test_fr_pair_delete_by_child_num(void)
Definition pair_tests.c:563
static void test_fr_pair_dcursor_by_ancestor_init(void)
Definition pair_tests.c:279
static void test_fr_pair_delete_by_da_nested(void)
Definition pair_tests.c:159
static void test_init(void)
Global initialisation.
Definition pair_tests.c:36
static void test_fr_pair_raw_afrom_pair(void)
Definition pair_tests.c:235
static void test_fr_pair_update_by_da_parent(void)
Definition pair_tests.c:598
static void test_fr_pair_find_by_da_nested(void)
Definition pair_tests.c:388
static void test_fr_pair_dcursor_value_init(void)
Definition pair_tests.c:305
static void test_fr_pair_value_memdup(void)
static TALLOC_CTX * autofree
#define local_pairs
Convenience macro for accessing the state list.
Definition request.h:134
PUBLIC int snprintf(char *string, size_t length, char *format, va_alist)
Definition snprintf.c:689
return count
Definition module.c:163
fr_pair_value_bstrdup_buffer(vp, eap_session->identity, true)
fr_pair_t * vp
#define fr_time()
Allow us to arbitrarily manipulate time.
Definition state_test.c:8
size_t strlcpy(char *dst, char const *src, size_t siz)
Definition strlcpy.c:34
Stores an attribute, a value and various bits of other data.
Definition pair.h:68
fr_dict_attr_t const *_CONST da
Dictionary attribute defines the attribute number, vendor and type of the pair.
Definition pair.h:69
void * talloc_null_ctx(void)
Retrieve the current talloc NULL ctx.
Definition talloc.c:53
#define talloc_autofree_context
The original function is deprecated, so replace it with our version.
Definition talloc.h:51
static int64_t fr_time_unwrap(fr_time_t time)
Definition time.h:146
"server local" time.
Definition time.h:69
@ T_OP_EQ
Definition token.h:83
@ T_OP_CMP_EQ
Definition token.h:106
#define fr_pair_dcursor_by_da_init(_cursor, _list, _da)
Initialise a cursor that will return only attributes matching the specified fr_dict_attr_t.
Definition pair.h:628
#define PAIR_VERIFY(_x)
Definition pair.h:191
void fr_pair_list_sort(fr_pair_list_t *list, fr_cmp_t cmp)
Sort a doubly linked list of fr_pair_ts using merge sort.
fr_pair_t * fr_pair_list_next(fr_pair_list_t const *list, fr_pair_t const *item))
Get the next item in a valuepair list after a specific entry.
Definition pair_inline.c:70
void fr_pair_list_free(fr_pair_list_t *list)
Free memory used by a valuepair list.
#define fr_pair_dcursor_init(_cursor, _list)
Initialises a special dcursor with callbacks that will maintain the attr sublists correctly.
Definition pair.h:591
fr_pair_t * fr_pair_list_head(fr_pair_list_t const *list)
Get the head of a valuepair list.
Definition pair_inline.c:43
#define fr_pair_dcursor_by_ancestor_init(_cursor, _list, _da)
Initialise a cursor that will return only attributes descended from the specified fr_dict_attr_t.
Definition pair.h:646
size_t fr_pair_list_num_elements(fr_pair_list_t const *list)
Get the length of a list of fr_pair_t.
static fr_slen_t parent
Definition pair.h:845
void fr_perror(char const *fmt,...)
Print the current error to stderr with a prefix.
Definition strerror.c:733
int fr_check_lib_magic(uint64_t magic)
Check if the application linking to the library has the correct magic number.
Definition version.c:40
#define RADIUSD_MAGIC_NUMBER
Definition version.h:81
fr_sbuff_unescape_rules_t fr_value_unescape_double
Definition value.c:266
static size_t char ** out
Definition value.h:1012