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