The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
cf_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 cf_file, cf_util, and cf_parse
18 *
19 * @file src/lib/server/cf_tests.c
20 *
21 * @copyright 2026 Network RADIUS SAS (legal@networkradius.com)
22 */
23
24static void test_init(void);
25# define TEST_INIT test_init()
26
27#include <freeradius-devel/util/test/acutest.h>
28#include <freeradius-devel/util/test/acutest_helpers.h>
29#include <freeradius-devel/server/cf_file.h>
30#include <freeradius-devel/server/cf_util.h>
31#include <freeradius-devel/server/cf_priv.h>
32
33static TALLOC_CTX *autofree;
34
35/** Global initialisation
36 */
37static void test_init(void)
38{
40 if (!autofree) {
41 fr_perror("cf_tests");
42 fr_exit_now(EXIT_FAILURE);
43 }
44
45 /*
46 * Mismatch between the binary and the libraries it depends on
47 */
49 fr_perror("cf_tests");
50 fr_exit_now(EXIT_FAILURE);
51 }
52}
53
54
55/*
56 * Section allocation and accessors
57 */
58
60{
61 CONF_SECTION *cs;
62
63 cs = cf_section_alloc(autofree, NULL, "server", NULL);
64 TEST_ASSERT(cs != NULL);
65
66 TEST_CHECK(strcmp(cf_section_name1(cs), "server") == 0);
67 TEST_CHECK(cf_section_name2(cs) == NULL);
68 TEST_CHECK(strcmp(cf_section_name(cs), "server") == 0);
69
70 talloc_free(cs);
71}
72
74{
75 CONF_SECTION *cs;
76
77 cs = cf_section_alloc(autofree, NULL, "server", "default");
78 TEST_ASSERT(cs != NULL);
79
80 TEST_CHECK(strcmp(cf_section_name1(cs), "server") == 0);
81 TEST_CHECK(strcmp(cf_section_name2(cs), "default") == 0);
82
83 talloc_free(cs);
84}
85
87{
88 CONF_SECTION *parent, *child;
89
90 parent = cf_section_alloc(autofree, NULL, "root", NULL);
91 TEST_ASSERT(parent != NULL);
92
93 child = cf_section_alloc(autofree, parent, "child", NULL);
94 TEST_ASSERT(child != NULL);
95
97 TEST_CHECK(cf_root(child) == parent);
98
100}
101
102static void test_section_name_cmp(void)
103{
104 CONF_SECTION *cs;
105
106 cs = cf_section_alloc(autofree, NULL, "server", "default");
107 TEST_ASSERT(cs != NULL);
108
109 TEST_CHECK(cf_section_name_cmp(cs, "server", "default") == 0);
110 TEST_CHECK(cf_section_name_cmp(cs, "server", "other") != 0);
111 TEST_CHECK(cf_section_name_cmp(cs, "other", NULL) != 0);
112
113 talloc_free(cs);
114}
115
117{
118 CONF_SECTION *cs;
119 CONF_ITEM *ci;
120
121 cs = cf_section_alloc(autofree, NULL, "test", NULL);
122 TEST_ASSERT(cs != NULL);
123
124 ci = cf_section_to_item(cs);
125 TEST_ASSERT(ci != NULL);
130
131 talloc_free(cs);
132}
133
134
135/*
136 * Pair allocation and accessors
137 */
138
139static void test_pair_alloc_basic(void)
140{
141 CONF_SECTION *cs;
142 CONF_PAIR *cp;
143
144 cs = cf_section_alloc(autofree, NULL, "test", NULL);
145 TEST_ASSERT(cs != NULL);
146
147 cp = cf_pair_alloc(cs, "key", "value", T_OP_EQ, T_BARE_WORD, T_BARE_WORD);
148 TEST_ASSERT(cp != NULL);
149
150 TEST_CHECK(strcmp(cf_pair_attr(cp), "key") == 0);
151 TEST_CHECK(strcmp(cf_pair_value(cp), "value") == 0);
153
154 talloc_free(cs);
155}
156
157static void test_pair_alloc_quoted(void)
158{
159 CONF_SECTION *cs;
160 CONF_PAIR *cp;
161
162 cs = cf_section_alloc(autofree, NULL, "test", NULL);
163 TEST_ASSERT(cs != NULL);
164
165 cp = cf_pair_alloc(cs, "msg", "hello world", T_OP_EQ, T_BARE_WORD, T_DOUBLE_QUOTED_STRING);
166 TEST_ASSERT(cp != NULL);
167
170
171 talloc_free(cs);
172}
173
175{
176 CONF_SECTION *cs;
177 CONF_PAIR *cp;
178
179 cs = cf_section_alloc(autofree, NULL, "test", NULL);
180 TEST_ASSERT(cs != NULL);
181
182 cp = cf_pair_alloc(cs, "flag", NULL, T_OP_EQ, T_BARE_WORD, T_BARE_WORD);
183 TEST_ASSERT(cp != NULL);
184
185 TEST_CHECK(strcmp(cf_pair_attr(cp), "flag") == 0);
186 TEST_CHECK(cf_pair_value(cp) == NULL);
187
188 talloc_free(cs);
189}
190
192{
193 CONF_SECTION *cs;
194 CONF_PAIR *cp_set, *cp_add, *cp_cmp;
195
196 cs = cf_section_alloc(autofree, NULL, "test", NULL);
197 TEST_ASSERT(cs != NULL);
198
199 cp_set = cf_pair_alloc(cs, "a", "1", T_OP_SET, T_BARE_WORD, T_BARE_WORD);
200 TEST_ASSERT(cp_set != NULL);
202
203 cp_add = cf_pair_alloc(cs, "b", "2", T_OP_ADD_EQ, T_BARE_WORD, T_BARE_WORD);
204 TEST_ASSERT(cp_add != NULL);
206
207 cp_cmp = cf_pair_alloc(cs, "c", "3", T_OP_CMP_EQ, T_BARE_WORD, T_BARE_WORD);
208 TEST_ASSERT(cp_cmp != NULL);
210
211 talloc_free(cs);
212}
213
214static void test_pair_replace(void)
215{
216 CONF_SECTION *cs;
217 CONF_PAIR *cp;
218 int ret;
219
220 cs = cf_section_alloc(autofree, NULL, "test", NULL);
221 TEST_ASSERT(cs != NULL);
222
223 cp = cf_pair_alloc(cs, "key", "old", T_OP_EQ, T_BARE_WORD, T_BARE_WORD);
224 TEST_ASSERT(cp != NULL);
225
226 ret = cf_pair_replace(cs, cp, "new");
227 TEST_CHECK(ret == 0);
228 TEST_CHECK(strcmp(cf_pair_value(cp), "new") == 0);
229
230 talloc_free(cs);
231}
232
234{
235 CONF_SECTION *cs;
236 CONF_PAIR *cp;
237 CONF_ITEM *ci;
238
239 cs = cf_section_alloc(autofree, NULL, "test", NULL);
240 TEST_ASSERT(cs != NULL);
241
242 cp = cf_pair_alloc(cs, "attr", "val", T_OP_EQ, T_BARE_WORD, T_BARE_WORD);
243 TEST_ASSERT(cp != NULL);
244
245 ci = cf_pair_to_item(cp);
246 TEST_ASSERT(ci != NULL);
249 TEST_CHECK(cf_item_to_pair(ci) == cp);
250
251 talloc_free(cs);
252}
253
254
255/*
256 * Section search and traversal
257 */
258
259static void test_section_find_child(void)
260{
261 CONF_SECTION *parent, *c1, *c2, *c3, *found;
262
263 parent = cf_section_alloc(autofree, NULL, "root", NULL);
264 TEST_ASSERT(parent != NULL);
265
266 c1 = cf_section_alloc(autofree, parent, "alpha", NULL);
267 TEST_ASSERT(c1 != NULL);
268
269 c2 = cf_section_alloc(autofree, parent, "beta", NULL);
270 TEST_ASSERT(c2 != NULL);
271
272 c3 = cf_section_alloc(autofree, parent, "gamma", NULL);
273 TEST_ASSERT(c3 != NULL);
274
275 found = cf_section_find(parent, "beta", NULL);
276 TEST_CHECK(found == c2);
277
278 found = cf_section_find(parent, "gamma", NULL);
279 TEST_CHECK(found == c3);
280
282}
283
285{
286 CONF_SECTION *parent, *s1, *s2, *found;
287
288 parent = cf_section_alloc(autofree, NULL, "root", NULL);
289 TEST_ASSERT(parent != NULL);
290
291 s1 = cf_section_alloc(autofree, parent, "server", "default");
292 TEST_ASSERT(s1 != NULL);
293
294 s2 = cf_section_alloc(autofree, parent, "server", "inner");
295 TEST_ASSERT(s2 != NULL);
296
297 found = cf_section_find(parent, "server", "default");
298 TEST_CHECK(found == s1);
299
300 found = cf_section_find(parent, "server", "inner");
301 TEST_CHECK(found == s2);
302
304}
305
307{
308 CONF_SECTION *parent, *found;
309
310 parent = cf_section_alloc(autofree, NULL, "root", NULL);
311 TEST_ASSERT(parent != NULL);
312
313 cf_section_alloc(autofree, parent, "exists", NULL);
314
315 found = cf_section_find(parent, "nope", NULL);
316 TEST_CHECK(found == NULL);
317
319}
320
321static void test_section_find_next(void)
322{
323 CONF_SECTION *parent, *s1, *s2, *found;
324
325 parent = cf_section_alloc(autofree, NULL, "root", NULL);
326 TEST_ASSERT(parent != NULL);
327
328 s1 = cf_section_alloc(autofree, parent, "server", "a");
329 TEST_ASSERT(s1 != NULL);
330
331 s2 = cf_section_alloc(autofree, parent, "server", "b");
332 TEST_ASSERT(s2 != NULL);
333
334 found = cf_section_find(parent, "server", CF_IDENT_ANY);
335 TEST_CHECK(found == s1);
336
337 found = cf_section_find_next(parent, found, "server", CF_IDENT_ANY);
338 TEST_CHECK(found == s2);
339
340 found = cf_section_find_next(parent, found, "server", CF_IDENT_ANY);
341 TEST_CHECK(found == NULL);
342
344}
345
346static void test_section_first_next(void)
347{
348 CONF_SECTION *parent, *c1, *c2, *c3, *iter;
349
350 parent = cf_section_alloc(autofree, NULL, "root", NULL);
351 TEST_ASSERT(parent != NULL);
352
353 c1 = cf_section_alloc(autofree, parent, "a", NULL);
354 TEST_ASSERT(c1 != NULL);
355
356 c2 = cf_section_alloc(autofree, parent, "b", NULL);
357 TEST_ASSERT(c2 != NULL);
358
359 c3 = cf_section_alloc(autofree, parent, "c", NULL);
360 TEST_ASSERT(c3 != NULL);
361
362 iter = cf_section_first(parent);
363 TEST_CHECK(iter == c1);
364
365 iter = cf_section_next(parent, iter);
366 TEST_CHECK(iter == c2);
367
368 iter = cf_section_next(parent, iter);
369 TEST_CHECK(iter == c3);
370
371 iter = cf_section_next(parent, iter);
372 TEST_CHECK(iter == NULL);
373
375}
376
377static void test_section_prev(void)
378{
379 CONF_SECTION *parent, *c1, *c2, *c3, *iter;
380
381 parent = cf_section_alloc(autofree, NULL, "root", NULL);
382 TEST_ASSERT(parent != NULL);
383
384 c1 = cf_section_alloc(autofree, parent, "a", NULL);
385 TEST_ASSERT(c1 != NULL);
386
387 c2 = cf_section_alloc(autofree, parent, "b", NULL);
388 TEST_ASSERT(c2 != NULL);
389
390 c3 = cf_section_alloc(autofree, parent, "c", NULL);
391 TEST_ASSERT(c3 != NULL);
392
393 iter = cf_section_prev(parent, c3);
394 TEST_CHECK(iter == c2);
395
396 iter = cf_section_prev(parent, c2);
397 TEST_CHECK(iter == c1);
398
399 iter = cf_section_prev(parent, c1);
400 TEST_CHECK(iter == NULL);
401
403}
404
405static void test_section_value_find(void)
406{
407 CONF_SECTION *cs;
408 char const *val;
409
410 cs = cf_section_alloc(autofree, NULL, "test", NULL);
411 TEST_ASSERT(cs != NULL);
412
413 cf_pair_alloc(cs, "name", "myvalue", T_OP_EQ, T_BARE_WORD, T_BARE_WORD);
414
415 val = cf_section_value_find(cs, "name");
416 TEST_ASSERT(val != NULL);
417 TEST_CHECK(strcmp(val, "myvalue") == 0);
418
419 val = cf_section_value_find(cs, "missing");
420 TEST_CHECK(val == NULL);
421
422 talloc_free(cs);
423}
424
425
426/*
427 * Pair search and traversal
428 */
429
430static void test_pair_find_basic(void)
431{
432 CONF_SECTION *cs;
433 CONF_PAIR *cp, *found;
434
435 cs = cf_section_alloc(autofree, NULL, "test", NULL);
436 TEST_ASSERT(cs != NULL);
437
438 cf_pair_alloc(cs, "key1", "val1", T_OP_EQ, T_BARE_WORD, T_BARE_WORD);
439 cp = cf_pair_alloc(cs, "key2", "val2", T_OP_EQ, T_BARE_WORD, T_BARE_WORD);
440
441 found = cf_pair_find(cs, "key2");
442 TEST_CHECK(found == cp);
443 TEST_CHECK(strcmp(cf_pair_value(found), "val2") == 0);
444
445 talloc_free(cs);
446}
447
448static void test_pair_find_missing(void)
449{
450 CONF_SECTION *cs;
451 CONF_PAIR *found;
452
453 cs = cf_section_alloc(autofree, NULL, "test", NULL);
454 TEST_ASSERT(cs != NULL);
455
456 cf_pair_alloc(cs, "exists", "val", T_OP_EQ, T_BARE_WORD, T_BARE_WORD);
457
458 found = cf_pair_find(cs, "nope");
459 TEST_CHECK(found == NULL);
460
461 talloc_free(cs);
462}
463
464static void test_pair_find_next(void)
465{
466 CONF_SECTION *cs;
467 CONF_PAIR *cp1, *cp2, *found;
468
469 cs = cf_section_alloc(autofree, NULL, "test", NULL);
470 TEST_ASSERT(cs != NULL);
471
472 cp1 = cf_pair_alloc(cs, "host", "a", T_OP_EQ, T_BARE_WORD, T_BARE_WORD);
473 TEST_ASSERT(cp1 != NULL);
474
475 cp2 = cf_pair_alloc(cs, "host", "b", T_OP_EQ, T_BARE_WORD, T_BARE_WORD);
476 TEST_ASSERT(cp2 != NULL);
477
478 found = cf_pair_find(cs, "host");
479 TEST_CHECK(found == cp1);
480
481 found = cf_pair_find_next(cs, found, "host");
482 TEST_CHECK(found == cp2);
483
484 found = cf_pair_find_next(cs, found, "host");
485 TEST_CHECK(found == NULL);
486
487 talloc_free(cs);
488}
489
490static void test_pair_first_next(void)
491{
492 CONF_SECTION *cs;
493 CONF_PAIR *cp1, *cp2, *cp3, *iter;
494
495 cs = cf_section_alloc(autofree, NULL, "test", NULL);
496 TEST_ASSERT(cs != NULL);
497
498 cp1 = cf_pair_alloc(cs, "a", "1", T_OP_EQ, T_BARE_WORD, T_BARE_WORD);
499 TEST_ASSERT(cp1 != NULL);
500
501 cp2 = cf_pair_alloc(cs, "b", "2", T_OP_EQ, T_BARE_WORD, T_BARE_WORD);
502 TEST_ASSERT(cp2 != NULL);
503
504 cp3 = cf_pair_alloc(cs, "c", "3", T_OP_EQ, T_BARE_WORD, T_BARE_WORD);
505 TEST_ASSERT(cp3 != NULL);
506
507 iter = cf_pair_first(cs);
508 TEST_CHECK(iter == cp1);
509
510 iter = cf_pair_next(cs, iter);
511 TEST_CHECK(iter == cp2);
512
513 iter = cf_pair_next(cs, iter);
514 TEST_CHECK(iter == cp3);
515
516 iter = cf_pair_next(cs, iter);
517 TEST_CHECK(iter == NULL);
518
519 talloc_free(cs);
520}
521
522static void test_pair_prev(void)
523{
524 CONF_SECTION *cs;
525 CONF_PAIR *cp1, *cp2, *cp3, *iter;
526
527 cs = cf_section_alloc(autofree, NULL, "test", NULL);
528 TEST_ASSERT(cs != NULL);
529
530 cp1 = cf_pair_alloc(cs, "a", "1", T_OP_EQ, T_BARE_WORD, T_BARE_WORD);
531 cp2 = cf_pair_alloc(cs, "b", "2", T_OP_EQ, T_BARE_WORD, T_BARE_WORD);
532 cp3 = cf_pair_alloc(cs, "c", "3", T_OP_EQ, T_BARE_WORD, T_BARE_WORD);
533
534 iter = cf_pair_prev(cs, cp3);
535 TEST_CHECK(iter == cp2);
536
537 iter = cf_pair_prev(cs, cp2);
538 TEST_CHECK(iter == cp1);
539
540 iter = cf_pair_prev(cs, cp1);
541 TEST_CHECK(iter == NULL);
542
543 talloc_free(cs);
544}
545
546static void test_pair_count(void)
547{
548 CONF_SECTION *cs;
549
550 cs = cf_section_alloc(autofree, NULL, "test", NULL);
551 TEST_ASSERT(cs != NULL);
552
558
559 TEST_CHECK(cf_pair_count(cs, "x") == 3);
560 TEST_CHECK(cf_pair_count(cs, "y") == 2);
561 TEST_CHECK(cf_pair_count(cs, "z") == 0);
562
563 talloc_free(cs);
564}
565
567{
568 CONF_SECTION *parent, *child;
569
570 parent = cf_section_alloc(autofree, NULL, "root", NULL);
571 TEST_ASSERT(parent != NULL);
572
575
576 child = cf_section_alloc(autofree, parent, "sub", NULL);
577 TEST_ASSERT(child != NULL);
578
579 cf_pair_alloc(child, "c", "3", T_OP_EQ, T_BARE_WORD, T_BARE_WORD);
580
583
585}
586
587
588/*
589 * Item manipulation
590 */
591
592static void test_item_remove_pair(void)
593{
594 CONF_SECTION *cs;
595 CONF_PAIR *cp;
596
597 cs = cf_section_alloc(autofree, NULL, "test", NULL);
598 TEST_ASSERT(cs != NULL);
599
600 cp = cf_pair_alloc(cs, "remove_me", "val", T_OP_EQ, T_BARE_WORD, T_BARE_WORD);
601 TEST_ASSERT(cp != NULL);
602
603 TEST_CHECK(cf_pair_find(cs, "remove_me") == cp);
604
605 cf_item_remove(cs, cp);
606 TEST_CHECK(cf_pair_find(cs, "remove_me") == NULL);
607
608 talloc_free(cp);
609 talloc_free(cs);
610}
611
613{
614 CONF_SECTION *parent, *child;
615
616 parent = cf_section_alloc(autofree, NULL, "root", NULL);
617 TEST_ASSERT(parent != NULL);
618
619 child = cf_section_alloc(autofree, parent, "removable", NULL);
620 TEST_ASSERT(child != NULL);
621
622 TEST_CHECK(cf_section_find(parent, "removable", NULL) == child);
623
624 cf_item_remove(parent, child);
625 TEST_CHECK(cf_section_find(parent, "removable", NULL) == NULL);
626
627 talloc_free(child);
629}
630
631static void test_item_next_mixed(void)
632{
634 CONF_PAIR *cp;
635 CONF_SECTION *cs;
636 CONF_ITEM *ci;
637 int count = 0;
638
639 parent = cf_section_alloc(autofree, NULL, "root", NULL);
640 TEST_ASSERT(parent != NULL);
641
642 cp = cf_pair_alloc(parent, "key", "val", T_OP_EQ, T_BARE_WORD, T_BARE_WORD);
643 TEST_ASSERT(cp != NULL);
644
645 cs = cf_section_alloc(autofree, parent, "sub", NULL);
646 TEST_ASSERT(cs != NULL);
647
649
650 /*
651 * cf_item_next iterates all children regardless of type.
652 */
653 for (ci = cf_item_next(parent, NULL); ci; ci = cf_item_next(parent, ci)) {
654 count++;
655 }
656 TEST_CHECK(count == 3);
657 TEST_MSG("Expected 3 items, got %d", count);
658
660}
661
662static void test_item_free_children(void)
663{
664 CONF_SECTION *cs;
665
666 cs = cf_section_alloc(autofree, NULL, "test", NULL);
667 TEST_ASSERT(cs != NULL);
668
671 cf_section_alloc(autofree, cs, "child", NULL);
672
673 TEST_CHECK(cf_pair_first(cs) != NULL);
674 TEST_CHECK(cf_section_first(cs) != NULL);
675
677
678 TEST_CHECK(cf_pair_first(cs) == NULL);
679 TEST_CHECK(cf_section_first(cs) == NULL);
680
681 talloc_free(cs);
682}
683
684static void test_item_mark_parsed(void)
685{
686 CONF_SECTION *cs;
687 CONF_PAIR *cp;
688
689 cs = cf_section_alloc(autofree, NULL, "test", NULL);
690 TEST_ASSERT(cs != NULL);
691
692 cp = cf_pair_alloc(cs, "key", "val", T_OP_EQ, T_BARE_WORD, T_BARE_WORD);
693 TEST_ASSERT(cp != NULL);
694
696
699
700 talloc_free(cs);
701}
702
703
704/*
705 * Section duplication
706 */
707
708static void test_section_dup_basic(void)
709{
710 CONF_SECTION *cs, *dup;
711 CONF_PAIR *cp;
712
713 cs = cf_section_alloc(autofree, NULL, "server", "main");
714 TEST_ASSERT(cs != NULL);
715
716 cp = cf_pair_alloc(cs, "listen", "1812", T_OP_EQ, T_BARE_WORD, T_BARE_WORD);
717 TEST_ASSERT(cp != NULL);
718 cf_filename_set(cp, "test.conf");
719
720 cp = cf_pair_alloc(cs, "type", "auth", T_OP_EQ, T_BARE_WORD, T_BARE_WORD);
721 TEST_ASSERT(cp != NULL);
722 cf_filename_set(cp, "test.conf");
723
724 dup = cf_section_dup(autofree, NULL, cs, cf_section_name1(cs), cf_section_name2(cs), false);
725 TEST_ASSERT(dup != NULL);
726 TEST_CHECK(dup != cs);
727 TEST_CHECK(strcmp(cf_section_name1(dup), "server") == 0);
728 TEST_CHECK(strcmp(cf_section_name2(dup), "main") == 0);
729
730 cp = cf_pair_find(dup, "listen");
731 TEST_ASSERT(cp != NULL);
732 TEST_CHECK(strcmp(cf_pair_value(cp), "1812") == 0);
733
734 cp = cf_pair_find(dup, "type");
735 TEST_ASSERT(cp != NULL);
736 TEST_CHECK(strcmp(cf_pair_value(cp), "auth") == 0);
737
738 talloc_free(cs);
739 talloc_free(dup);
740}
741
742static void test_section_dup_rename(void)
743{
744 CONF_SECTION *cs, *dup;
745 CONF_PAIR *cp;
746
747 cs = cf_section_alloc(autofree, NULL, "server", "old");
748 TEST_ASSERT(cs != NULL);
749
750 cp = cf_pair_alloc(cs, "port", "1812", T_OP_EQ, T_BARE_WORD, T_BARE_WORD);
751 TEST_ASSERT(cp != NULL);
752 cf_filename_set(cp, "test.conf");
753
754 dup = cf_section_dup(autofree, NULL, cs, "newname", "newname2", false);
755 TEST_ASSERT(dup != NULL);
756 TEST_CHECK(strcmp(cf_section_name1(dup), "newname") == 0);
757 TEST_CHECK(strcmp(cf_section_name2(dup), "newname2") == 0);
758
759 /*
760 * Children should still be present.
761 */
762 TEST_CHECK(cf_pair_find(dup, "port") != NULL);
763
764 talloc_free(cs);
765 talloc_free(dup);
766}
767
768static void test_pair_dup(void)
769{
770 CONF_SECTION *cs1, *cs2;
771 CONF_PAIR *cp, *dup;
772
773 cs1 = cf_section_alloc(autofree, NULL, "src", NULL);
774 TEST_ASSERT(cs1 != NULL);
775
776 cs2 = cf_section_alloc(autofree, NULL, "dst", NULL);
777 TEST_ASSERT(cs2 != NULL);
778
779 cp = cf_pair_alloc(cs1, "key", "val", T_OP_SET, T_BARE_WORD, T_SINGLE_QUOTED_STRING);
780 TEST_ASSERT(cp != NULL);
781
782 dup = cf_pair_dup(cs2, cp, false);
783 TEST_ASSERT(dup != NULL);
784 TEST_CHECK(dup != cp);
785 TEST_CHECK(strcmp(cf_pair_attr(dup), "key") == 0);
786 TEST_CHECK(strcmp(cf_pair_value(dup), "val") == 0);
789
790 talloc_free(cs1);
791 talloc_free(cs2);
792}
793
794
795/*
796 * Metadata
797 */
798
799static void test_filename_lineno(void)
800{
801 CONF_SECTION *cs;
802
803 cs = cf_section_alloc(autofree, NULL, "test", NULL);
804 TEST_ASSERT(cs != NULL);
805
806 /*
807 * In debug builds, cf_section_alloc sets filename to __FILE__
808 * and lineno to __LINE__. Just verify they are set to something.
809 */
810#ifndef NDEBUG
811 TEST_CHECK(cf_filename(cs) != NULL);
812 TEST_CHECK(cf_lineno(cs) > 0);
813#endif
814
815 talloc_free(cs);
816}
817
818static void test_filename_set(void)
819{
820 CONF_SECTION *cs;
821
822 cs = cf_section_alloc(autofree, NULL, "test", NULL);
823 TEST_ASSERT(cs != NULL);
824
825 cf_filename_set(cs, "test.conf");
826 TEST_CHECK(strcmp(cf_filename(cs), "test.conf") == 0);
827
828 talloc_free(cs);
829}
830
831static void test_lineno_set(void)
832{
833 CONF_SECTION *cs;
834
835 cs = cf_section_alloc(autofree, NULL, "test", NULL);
836 TEST_ASSERT(cs != NULL);
837
838 cf_lineno_set(cs, 42);
839 TEST_CHECK(cf_lineno(cs) == 42);
840
841 talloc_free(cs);
842}
843
844static void test_cf_root(void)
845{
846 CONF_SECTION *root, *mid, *leaf;
847
848 root = cf_section_alloc(autofree, NULL, "root", NULL);
849 TEST_ASSERT(root != NULL);
850
851 mid = cf_section_alloc(autofree, root, "mid", NULL);
852 TEST_ASSERT(mid != NULL);
853
854 leaf = cf_section_alloc(autofree, mid, "leaf", NULL);
855 TEST_ASSERT(leaf != NULL);
856
857 TEST_CHECK(cf_root(leaf) == root);
858 TEST_CHECK(cf_root(mid) == root);
859 TEST_CHECK(cf_root(root) == root);
860
861 talloc_free(root);
862}
863
864
865/*
866 * CONF_DATA
867 */
868
869static void test_data_add_find(void)
870{
871 CONF_SECTION *cs;
872 uint32_t *val;
873 CONF_DATA const *cd;
874 void *found;
875
876 cs = cf_section_alloc(autofree, NULL, "test", NULL);
877 TEST_ASSERT(cs != NULL);
878
879 val = talloc(cs, uint32_t);
880 TEST_ASSERT(val != NULL);
881 *val = 12345;
882
883 cd = cf_data_add(cs, val, "counter", false);
884 TEST_CHECK(cd != NULL);
885
886 found = cf_data_value(cd);
887 TEST_CHECK(found == val);
888 TEST_CHECK(*(uint32_t *)found == 12345);
889
890 talloc_free(cs);
891}
892
893static void test_data_find_missing(void)
894{
895 CONF_SECTION *cs;
896 CONF_DATA const *cd;
897
898 cs = cf_section_alloc(autofree, NULL, "test", NULL);
899 TEST_ASSERT(cs != NULL);
900
901 cd = _cf_data_find(cf_section_to_item(cs), "uint32_t", "nonexistent");
902 TEST_CHECK(cd == NULL);
903
904 talloc_free(cs);
905}
906
907static void test_data_remove(void)
908{
909 CONF_SECTION *cs;
910 uint32_t *val;
911 CONF_DATA const *cd;
912
913 cs = cf_section_alloc(autofree, NULL, "test", NULL);
914 TEST_ASSERT(cs != NULL);
915
916 val = talloc(cs, uint32_t);
917 *val = 99;
918
919 cd = cf_data_add(cs, val, "remove_me", false);
920 TEST_CHECK(cd != NULL);
921
923
924 cd = _cf_data_find(cf_section_to_item(cs), "uint32_t", "remove_me");
925 TEST_CHECK(cd == NULL);
926
927 talloc_free(cs);
928}
929
930
931/*
932 * Variable expansion - cf_expand_variables
933 */
934
936{
937 CONF_SECTION *cs;
938 char output[256];
939 char const *result;
940
941 cs = cf_section_alloc(autofree, NULL, "root", NULL);
942 TEST_ASSERT(cs != NULL);
943
944 result = cf_expand_variables("test.conf", 1, cs,
945 output, sizeof(output),
946 "hello world", -1, NULL);
947 TEST_CHECK(result != NULL);
948 if (result) {
949 TEST_CHECK(strcmp(result, "hello world") == 0);
950 TEST_MSG("Expected 'hello world', got '%s'", result);
951 }
952
953 talloc_free(cs);
954}
955
956static void test_expand_section_ref(void)
957{
958 CONF_SECTION *cs;
959 char output[256];
960 char const *result;
961
962 cs = cf_section_alloc(autofree, NULL, "root", NULL);
963 TEST_ASSERT(cs != NULL);
964
965 cf_pair_alloc(cs, "name", "testval", T_OP_EQ, T_BARE_WORD, T_BARE_WORD);
966
967 result = cf_expand_variables("test.conf", 1, cs,
968 output, sizeof(output),
969 "${name}", -1, NULL);
970 TEST_CHECK(result != NULL);
971 if (result) {
972 TEST_CHECK(strcmp(result, "testval") == 0);
973 TEST_MSG("Expected 'testval', got '%s'", result);
974 }
975
976 talloc_free(cs);
977}
978
979static void test_expand_nested_ref(void)
980{
981 CONF_SECTION *root, *sub;
982 char output[256];
983 char const *result;
984
985 root = cf_section_alloc(autofree, NULL, "root", NULL);
986 TEST_ASSERT(root != NULL);
987
988 sub = cf_section_alloc(autofree, root, "server", NULL);
989 TEST_ASSERT(sub != NULL);
990
991 cf_pair_alloc(sub, "name", "myserver", T_OP_EQ, T_BARE_WORD, T_BARE_WORD);
992
993 result = cf_expand_variables("test.conf", 1, root,
994 output, sizeof(output),
995 "${server.name}", -1, NULL);
996 TEST_CHECK(result != NULL);
997 if (result) {
998 TEST_CHECK(strcmp(result, "myserver") == 0);
999 TEST_MSG("Expected 'myserver', got '%s'", result);
1000 }
1001
1002 talloc_free(root);
1003}
1004
1006{
1007 CONF_SECTION *cs;
1008 char output[256];
1009 char const *result;
1010 bool soft_fail = false;
1011
1012 cs = cf_section_alloc(autofree, NULL, "root", NULL);
1013 TEST_ASSERT(cs != NULL);
1014
1015 result = cf_expand_variables("test.conf", 1, cs,
1016 output, sizeof(output),
1017 "${nonexistent}", -1, &soft_fail);
1018 TEST_CHECK(result == NULL);
1019 TEST_CHECK(soft_fail == true);
1020 TEST_MSG("Expected soft_fail to be set for missing reference");
1021
1022 talloc_free(cs);
1023}
1024
1025
1026/*
1027 * Pair value concatenation
1028 */
1029
1031{
1032 CONF_SECTION *cs;
1033 char buffer[256];
1034 fr_sbuff_t sbuff = FR_SBUFF_OUT(buffer, sizeof(buffer));
1035 fr_slen_t slen;
1036
1037 cs = cf_section_alloc(autofree, NULL, "test", NULL);
1038 TEST_ASSERT(cs != NULL);
1039
1040 cf_pair_alloc(cs, "host", "a", T_OP_EQ, T_BARE_WORD, T_BARE_WORD);
1041 cf_pair_alloc(cs, "host", "b", T_OP_EQ, T_BARE_WORD, T_BARE_WORD);
1042 cf_pair_alloc(cs, "host", "c", T_OP_EQ, T_BARE_WORD, T_BARE_WORD);
1043
1044 slen = cf_pair_values_concat(&sbuff, cs, "host", ", ");
1045 TEST_CHECK(slen > 0);
1046 TEST_MSG("cf_pair_values_concat returned %zd", slen);
1047
1048 fr_sbuff_terminate(&sbuff);
1049 TEST_CHECK(strcmp(buffer, "a, b, c") == 0);
1050 TEST_MSG("Expected 'a, b, c', got '%s'", buffer);
1051
1052 talloc_free(cs);
1053}
1054
1056{
1057 CONF_SECTION *cs;
1058 char buffer[256];
1059 fr_sbuff_t sbuff = FR_SBUFF_OUT(buffer, sizeof(buffer));
1060 fr_slen_t slen;
1061
1062 cs = cf_section_alloc(autofree, NULL, "test", NULL);
1063 TEST_ASSERT(cs != NULL);
1064
1065 slen = cf_pair_values_concat(&sbuff, cs, "nope", ", ");
1066 TEST_CHECK(slen == 0);
1067
1068 talloc_free(cs);
1069}
1070
1071
1072/*
1073 * cf_reference_item
1074 */
1075
1077{
1078 CONF_SECTION *cs;
1079 CONF_PAIR *cp;
1080 CONF_ITEM *ci;
1081
1082 cs = cf_section_alloc(autofree, NULL, "root", NULL);
1083 TEST_ASSERT(cs != NULL);
1084
1085 cp = cf_pair_alloc(cs, "mykey", "myval", T_OP_EQ, T_BARE_WORD, T_BARE_WORD);
1086 TEST_ASSERT(cp != NULL);
1087
1088 ci = cf_reference_item(cs, cs, "mykey");
1089 TEST_CHECK(ci != NULL);
1090 if (ci) {
1092 TEST_CHECK(cf_item_to_pair(ci) == cp);
1093 }
1094
1095 talloc_free(cs);
1096}
1097
1099{
1100 CONF_SECTION *root, *child;
1101 CONF_ITEM *ci;
1102
1103 root = cf_section_alloc(autofree, NULL, "root", NULL);
1104 TEST_ASSERT(root != NULL);
1105
1106 child = cf_section_alloc(autofree, root, "child", NULL);
1107 TEST_ASSERT(child != NULL);
1108
1109 ci = cf_reference_item(root, root, "child");
1110 TEST_CHECK(ci != NULL);
1111 if (ci) {
1113 TEST_CHECK(cf_item_to_section(ci) == child);
1114 }
1115
1116 talloc_free(root);
1117}
1118
1120{
1121 CONF_SECTION *cs;
1122 CONF_ITEM *ci;
1123
1124 cs = cf_section_alloc(autofree, NULL, "root", NULL);
1125 TEST_ASSERT(cs != NULL);
1126
1127 ci = cf_reference_item(cs, cs, "nonexistent");
1128 TEST_CHECK(ci == NULL);
1129
1130 talloc_free(cs);
1131}
1132
1133
1134/*
1135 * cf_pair_in_table
1136 */
1137
1139 { L("bar"), 2 },
1140 { L("foo"), 1 },
1141};
1143
1145{
1146 CONF_SECTION *cs;
1147 CONF_PAIR *cp;
1148 int32_t out = 0;
1149 int ret;
1150
1151 cs = cf_section_alloc(autofree, NULL, "test", NULL);
1152 TEST_ASSERT(cs != NULL);
1153
1154 cp = cf_pair_alloc(cs, "type", "foo", T_OP_EQ, T_BARE_WORD, T_BARE_WORD);
1155 TEST_ASSERT(cp != NULL);
1156
1158 TEST_CHECK(ret == 0);
1159 TEST_CHECK(out == 1);
1160
1161 talloc_free(cs);
1162}
1163
1165{
1166 CONF_SECTION *cs;
1167 CONF_PAIR *cp;
1168 int32_t out = 0;
1169 int ret;
1170
1171 cs = cf_section_alloc(autofree, NULL, "test", NULL);
1172 TEST_ASSERT(cs != NULL);
1173
1174 cp = cf_pair_alloc(cs, "type", "invalid_value", T_OP_EQ, T_BARE_WORD, T_BARE_WORD);
1175 TEST_ASSERT(cp != NULL);
1176
1178 TEST_CHECK(ret == -1);
1179
1180 talloc_free(cs);
1181}
1182
1183
1185 /* Section allocation and accessors */
1186 { "test_section_alloc_name1_only", test_section_alloc_name1_only },
1187 { "test_section_alloc_name1_name2", test_section_alloc_name1_name2 },
1188 { "test_section_alloc_parent", test_section_alloc_parent },
1189 { "test_section_name_cmp", test_section_name_cmp },
1190 { "test_section_to_item_roundtrip", test_section_to_item_roundtrip },
1191
1192 /* Pair allocation and accessors */
1193 { "test_pair_alloc_basic", test_pair_alloc_basic },
1194 { "test_pair_alloc_quoted", test_pair_alloc_quoted },
1195 { "test_pair_alloc_no_value", test_pair_alloc_no_value },
1196 { "test_pair_alloc_operators", test_pair_alloc_operators },
1197 { "test_pair_replace", test_pair_replace },
1198 { "test_pair_to_item_roundtrip", test_pair_to_item_roundtrip },
1199
1200 /* Section search and traversal */
1201 { "test_section_find_child", test_section_find_child },
1202 { "test_section_find_name1_name2", test_section_find_name1_name2 },
1203 { "test_section_find_missing", test_section_find_missing },
1204 { "test_section_find_next", test_section_find_next },
1205 { "test_section_first_next", test_section_first_next },
1206 { "test_section_prev", test_section_prev },
1207 { "test_section_value_find", test_section_value_find },
1208
1209 /* Pair search and traversal */
1210 { "test_pair_find_basic", test_pair_find_basic },
1211 { "test_pair_find_missing", test_pair_find_missing },
1212 { "test_pair_find_next", test_pair_find_next },
1213 { "test_pair_first_next", test_pair_first_next },
1214 { "test_pair_prev", test_pair_prev },
1215 { "test_pair_count", test_pair_count },
1216 { "test_pair_count_descendents", test_pair_count_descendents },
1217
1218 /* Item manipulation */
1219 { "test_item_remove_pair", test_item_remove_pair },
1220 { "test_item_remove_section", test_item_remove_section },
1221 { "test_item_next_mixed", test_item_next_mixed },
1222 { "test_item_free_children", test_item_free_children },
1223 { "test_item_mark_parsed", test_item_mark_parsed },
1224
1225 /* Section duplication */
1226 { "test_section_dup_basic", test_section_dup_basic },
1227 { "test_section_dup_rename", test_section_dup_rename },
1228 { "test_pair_dup", test_pair_dup },
1229
1230 /* Metadata */
1231 { "test_filename_lineno", test_filename_lineno },
1232 { "test_filename_set", test_filename_set },
1233 { "test_lineno_set", test_lineno_set },
1234 { "test_cf_root", test_cf_root },
1235
1236 /* CONF_DATA */
1237 { "test_data_add_find", test_data_add_find },
1238 { "test_data_find_missing", test_data_find_missing },
1239 { "test_data_remove", test_data_remove },
1240
1241 /* Variable expansion */
1242 { "test_expand_no_variables", test_expand_no_variables },
1243 { "test_expand_section_ref", test_expand_section_ref },
1244 { "test_expand_nested_ref", test_expand_nested_ref },
1245 { "test_expand_missing_ref", test_expand_missing_ref },
1246
1247 /* Pair value concatenation */
1248 { "test_pair_values_concat", test_pair_values_concat },
1249 { "test_pair_values_concat_missing", test_pair_values_concat_missing },
1250
1251 /* cf_reference_item */
1252 { "test_reference_item_pair", test_reference_item_pair },
1253 { "test_reference_item_section", test_reference_item_section },
1254 { "test_reference_item_missing", test_reference_item_missing },
1255
1256 /* cf_pair_in_table */
1257 { "test_pair_in_table_found", test_pair_in_table_found },
1258 { "test_pair_in_table_invalid", test_pair_in_table_invalid },
1259
1261};
static int const char char buffer[256]
Definition acutest.h:578
#define TEST_CHECK(cond)
Definition acutest.h:87
#define TEST_ASSERT(cond)
Definition acutest.h:110
#define TEST_TERMINATOR
Definition acutest.h:64
#define TEST_MSG(...)
Definition acutest.h:217
#define L(_str)
Helper for initialising arrays of string literals.
Definition build.h:209
#define NUM_ELEMENTS(_t)
Definition build.h:339
char const * cf_expand_variables(char const *cf, int lineno, CONF_SECTION *outer_cs, char *output, size_t outsize, char const *input, ssize_t inlen, bool *soft_fail)
Definition cf_file.c:188
CONF_ITEM * cf_reference_item(CONF_SECTION const *parent_cs, CONF_SECTION const *outer_cs, char const *ptr)
Definition cf_file.c:3832
Internal data that is associated with a configuration section.
Definition cf_priv.h:125
Common header for all CONF_* types.
Definition cf_priv.h:49
Configuration AVP similar to a fr_pair_t.
Definition cf_priv.h:72
A section grouping multiple CONF_PAIR.
Definition cf_priv.h:101
TEST_LIST
Definition cf_tests.c:1184
static void test_section_alloc_parent(void)
Definition cf_tests.c:86
static size_t test_table_len
Definition cf_tests.c:1142
static void test_item_remove_pair(void)
Definition cf_tests.c:592
static void test_data_remove(void)
Definition cf_tests.c:907
static void test_pair_values_concat_missing(void)
Definition cf_tests.c:1055
static void test_pair_values_concat(void)
Definition cf_tests.c:1030
static void test_section_find_name1_name2(void)
Definition cf_tests.c:284
static TALLOC_CTX * autofree
Definition cf_tests.c:33
static void test_cf_root(void)
Definition cf_tests.c:844
static void test_section_name_cmp(void)
Definition cf_tests.c:102
static void test_filename_lineno(void)
Definition cf_tests.c:799
static void test_pair_in_table_invalid(void)
Definition cf_tests.c:1164
static void test_pair_find_next(void)
Definition cf_tests.c:464
static void test_item_mark_parsed(void)
Definition cf_tests.c:684
static void test_section_alloc_name1_name2(void)
Definition cf_tests.c:73
static void test_pair_count_descendents(void)
Definition cf_tests.c:566
static void test_section_to_item_roundtrip(void)
Definition cf_tests.c:116
static void test_reference_item_pair(void)
Definition cf_tests.c:1076
static void test_reference_item_section(void)
Definition cf_tests.c:1098
static void test_expand_nested_ref(void)
Definition cf_tests.c:979
static void test_pair_first_next(void)
Definition cf_tests.c:490
static void test_section_first_next(void)
Definition cf_tests.c:346
static void test_expand_section_ref(void)
Definition cf_tests.c:956
static void test_section_value_find(void)
Definition cf_tests.c:405
static void test_pair_count(void)
Definition cf_tests.c:546
static void test_data_find_missing(void)
Definition cf_tests.c:893
static void test_reference_item_missing(void)
Definition cf_tests.c:1119
static void test_expand_no_variables(void)
Definition cf_tests.c:935
static void test_pair_find_basic(void)
Definition cf_tests.c:430
static void test_pair_in_table_found(void)
Definition cf_tests.c:1144
static void test_pair_replace(void)
Definition cf_tests.c:214
static void test_section_dup_basic(void)
Definition cf_tests.c:708
static void test_pair_alloc_no_value(void)
Definition cf_tests.c:174
static void test_lineno_set(void)
Definition cf_tests.c:831
static void test_section_alloc_name1_only(void)
Definition cf_tests.c:59
static void test_pair_to_item_roundtrip(void)
Definition cf_tests.c:233
static void test_expand_missing_ref(void)
Definition cf_tests.c:1005
static void test_pair_alloc_quoted(void)
Definition cf_tests.c:157
static void test_item_remove_section(void)
Definition cf_tests.c:612
static void test_section_find_missing(void)
Definition cf_tests.c:306
static void test_section_dup_rename(void)
Definition cf_tests.c:742
static void test_pair_find_missing(void)
Definition cf_tests.c:448
static void test_item_free_children(void)
Definition cf_tests.c:662
static void test_pair_dup(void)
Definition cf_tests.c:768
static void test_section_find_next(void)
Definition cf_tests.c:321
static void test_item_next_mixed(void)
Definition cf_tests.c:631
static void test_section_find_child(void)
Definition cf_tests.c:259
static void test_init(void)
Global initialisation.
Definition cf_tests.c:37
static void test_data_add_find(void)
Definition cf_tests.c:869
static void test_pair_alloc_operators(void)
Definition cf_tests.c:191
static void test_pair_alloc_basic(void)
Definition cf_tests.c:139
static void test_section_prev(void)
Definition cf_tests.c:377
static fr_table_num_sorted_t const test_table[]
Definition cf_tests.c:1138
static void test_pair_prev(void)
Definition cf_tests.c:522
static void test_filename_set(void)
Definition cf_tests.c:818
bool cf_item_is_pair(CONF_ITEM const *ci)
Determine if CONF_ITEM is a CONF_PAIR.
Definition cf_util.c:631
fr_token_t cf_pair_attr_quote(CONF_PAIR const *pair)
Return the value (lhs) quoting of a pair.
Definition cf_util.c:1603
void * _cf_data_remove(CONF_ITEM *parent, CONF_DATA const *cd)
Remove data from a configuration section.
Definition cf_util.c:1852
unsigned int cf_pair_count_descendents(CONF_SECTION const *cs)
Count the number of conf pairs beneath a section.
Definition cf_util.c:1485
CONF_PAIR * cf_pair_find_next(CONF_SECTION const *cs, CONF_PAIR const *prev, char const *attr)
Find a pair with a name matching attr, after specified pair.
Definition cf_util.c:1433
CONF_DATA const * _cf_data_find(CONF_ITEM const *ci, char const *type, char const *name)
Find user data in a config section.
Definition cf_util.c:1690
unsigned int cf_pair_count(CONF_SECTION const *cs, char const *attr)
Count the number of times an attribute occurs in a parent section.
Definition cf_util.c:1500
int cf_pair_in_table(int32_t *out, fr_table_num_sorted_t const *table, size_t table_len, CONF_PAIR *cp)
Check to see if the CONF_PAIR value is present in the specified table.
Definition cf_util.c:1946
CONF_PAIR * cf_pair_dup(CONF_SECTION *parent, CONF_PAIR *cp, bool copy_meta)
Duplicate a CONF_PAIR.
Definition cf_util.c:1308
fr_slen_t cf_pair_values_concat(fr_sbuff_t *out, CONF_SECTION const *cs, char const *attr, char const *sep)
Concatenate the values of any pairs with name attr.
Definition cf_util.c:1520
char const * cf_section_name2(CONF_SECTION const *cs)
Return the second identifier of a CONF_SECTION.
Definition cf_util.c:1184
int8_t cf_section_name_cmp(CONF_SECTION const *cs, char const *name1, char const *name2)
Check if a given section matches the specified name1/name2 identifiers.
Definition cf_util.c:1138
void * cf_data_value(CONF_DATA const *cd)
Return the user assigned value of CONF_DATA.
Definition cf_util.c:1743
CONF_ITEM * cf_section_to_item(CONF_SECTION const *cs)
Cast a CONF_SECTION to a CONF_ITEM.
Definition cf_util.c:737
CONF_PAIR * cf_pair_alloc(CONF_SECTION *parent, char const *attr, char const *value, fr_token_t op, fr_token_t lhs_quote, fr_token_t rhs_quote)
Allocate a CONF_PAIR.
Definition cf_util.c:1266
CONF_SECTION * cf_section_next(CONF_SECTION const *cs, CONF_SECTION const *curr)
Return the next child that's a CONF_SECTION.
Definition cf_util.c:996
char const * cf_section_name1(CONF_SECTION const *cs)
Return the second identifier of a CONF_SECTION.
Definition cf_util.c:1170
CONF_SECTION * cf_section_find(CONF_SECTION const *cs, char const *name1, char const *name2)
Find a CONF_SECTION with name1 and optionally name2.
Definition cf_util.c:1027
CONF_SECTION * cf_item_to_section(CONF_ITEM const *ci)
Cast a CONF_ITEM to a CONF_SECTION.
Definition cf_util.c:683
CONF_PAIR * cf_pair_find(CONF_SECTION const *cs, char const *attr)
Search for a CONF_PAIR with a specific name.
Definition cf_util.c:1419
char const * cf_section_value_find(CONF_SECTION const *cs, char const *attr)
Find a pair in a CONF_SECTION.
Definition cf_util.c:1119
char const * cf_section_name(CONF_SECTION const *cs)
Return name2 if set, else name1.
Definition cf_util.c:1196
bool cf_item_is_data(CONF_ITEM const *ci)
Determine if CONF_ITEM is CONF_DATA.
Definition cf_util.c:645
fr_token_t cf_pair_operator(CONF_PAIR const *pair)
Return the operator of a pair.
Definition cf_util.c:1588
fr_token_t cf_pair_value_quote(CONF_PAIR const *pair)
Return the value (rhs) quoting of a pair.
Definition cf_util.c:1618
CONF_PAIR * cf_pair_first(CONF_SECTION const *cs)
Return the first child that's a CONF_PAIR.
Definition cf_util.c:1380
CONF_PAIR * cf_pair_next(CONF_SECTION const *cs, CONF_PAIR const *curr)
Return the next child that's a CONF_PAIR.
Definition cf_util.c:1393
bool cf_item_is_section(CONF_ITEM const *ci)
Determine if CONF_ITEM is a CONF_SECTION.
Definition cf_util.c:617
CONF_SECTION * cf_section_dup(TALLOC_CTX *ctx, CONF_SECTION *parent, CONF_SECTION const *cs, char const *name1, char const *name2, bool copy_meta)
Duplicate a configuration section.
Definition cf_util.c:927
CONF_PAIR * cf_pair_prev(CONF_SECTION const *cs, CONF_PAIR const *curr)
Return the previous child that's a CONF_PAIR.
Definition cf_util.c:1406
CONF_SECTION * cf_section_first(CONF_SECTION const *cs)
Return the first child in a CONF_SECTION.
Definition cf_util.c:983
CONF_PAIR * cf_item_to_pair(CONF_ITEM const *ci)
Cast a CONF_ITEM to a CONF_PAIR.
Definition cf_util.c:663
CONF_SECTION * cf_section_find_next(CONF_SECTION const *cs, CONF_SECTION const *prev, char const *name1, char const *name2)
Return the next matching section.
Definition cf_util.c:1048
char const * cf_pair_value(CONF_PAIR const *pair)
Return the value of a CONF_PAIR.
Definition cf_util.c:1574
int cf_pair_replace(CONF_SECTION *cs, CONF_PAIR *cp, char const *value)
Replace pair value in a given section with the given value.
Definition cf_util.c:1340
CONF_ITEM * cf_pair_to_item(CONF_PAIR const *cp)
Cast a CONF_PAIR to a CONF_ITEM.
Definition cf_util.c:721
CONF_SECTION * cf_section_prev(CONF_SECTION const *cs, CONF_SECTION const *curr)
Return the previous child that's a CONF_SECTION.
Definition cf_util.c:1009
char const * cf_pair_attr(CONF_PAIR const *pair)
Return the attr of a CONF_PAIR.
Definition cf_util.c:1558
#define cf_lineno(_cf)
Definition cf_util.h:104
#define cf_data_add(_cf, _data, _name, _free)
Definition cf_util.h:254
#define cf_item_is_parsed(_cf)
Definition cf_util.h:139
#define cf_lineno_set(_ci, _lineno)
Definition cf_util.h:131
#define cf_root(_cf)
Definition cf_util.h:98
#define cf_section_free_children(_x)
Definition cf_util.h:199
#define cf_parent(_cf)
Definition cf_util.h:101
#define cf_item_remove(_parent, _child)
Definition cf_util.h:89
#define cf_item_next(_parent, _curr)
Definition cf_util.h:92
#define cf_section_alloc(_ctx, _parent, _name1, _name2)
Definition cf_util.h:146
#define cf_filename_set(_ci, _filename)
Definition cf_util.h:128
#define cf_filename(_cf)
Definition cf_util.h:107
#define cf_item_mark_parsed(_cf)
Definition cf_util.h:136
#define CF_IDENT_ANY
Definition cf_util.h:78
#define fr_exit_now(_x)
Exit without calling atexit() handlers, producing a log message in debug builds.
Definition debug.h:226
talloc_free(hp)
unsigned int uint32_t
ssize_t fr_slen_t
#define FR_SBUFF_OUT(_start, _len_or_end)
return count
Definition module.c:155
An element in a lexicographically sorted array of name to num mappings.
Definition table.h:49
#define talloc_autofree_context
The original function is deprecated, so replace it with our version.
Definition talloc.h:51
@ T_SINGLE_QUOTED_STRING
Definition token.h:122
@ T_BARE_WORD
Definition token.h:120
@ T_OP_EQ
Definition token.h:83
@ T_OP_SET
Definition token.h:84
@ T_OP_ADD_EQ
Definition token.h:69
@ T_DOUBLE_QUOTED_STRING
Definition token.h:121
@ T_OP_CMP_EQ
Definition token.h:106
static fr_slen_t parent
Definition pair.h:858
void fr_perror(char const *fmt,...)
Print the current error to stderr with a prefix.
Definition strerror.c:732
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
static size_t char ** out
Definition value.h:1030