The FreeRADIUS server $Id: f3670dba8951ca10eb4948feb3dc3db9423a334f $
Loading...
Searching...
No Matches
cf_util.h
Go to the documentation of this file.
1#pragma once
2/*
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
16 */
17
18/**
19 * $Id: 0e97e24aa6bbdfec7c00c76d77c5937ebcd05eb0 $
20 *
21 * @file lib/server/cf_util.h
22 * @brief API to create and manipulate internal format configurations.
23 *
24 * @copyright 2017 The FreeRADIUS server project
25 */
26RCSIDH(conf_file_h, "$Id: 0e97e24aa6bbdfec7c00c76d77c5937ebcd05eb0 $")
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
32/*
33 * Export the minimum amount of information about these structs
34 */
35typedef struct cf_item CONF_ITEM; //!< Generic configuration element, extended to become
36 ///< a #CONF_PAIR, a #CONF_SECTION or #CONF_DATA.
37typedef struct cf_section CONF_SECTION; //!< #CONF_ITEM used to group multiple #CONF_PAIR and #CONF_SECTION, together.
38typedef struct cf_pair CONF_PAIR; //!< #CONF_ITEM with an attribute, an operator and a value.
39typedef struct cf_data CONF_DATA; //!< #CONF_ITEM used to associate arbitrary data
40 ///< with a #CONF_PAIR or #CONF_SECTION.
41typedef struct cf_comment CONF_COMMENT; //!< #CONF_ITEM holding a literal `# ...` comment line.
42 ///< Only created when the parser is asked to preserve
43 ///< comments (utilities opt in; the runtime parser does not).
44
45#include <unistd.h>
46#include <sys/time.h>
47
48#include <freeradius-devel/util/rb.h>
49#include <freeradius-devel/util/table.h>
50#include <freeradius-devel/util/token.h>
51#include <freeradius-devel/util/log.h>
52
53#define FR_TIMEVAL_TO_MS(_x) (((_x)->tv_usec / 1000) + ((_x)->tv_sec * (uint64_t)1000))
54#define FR_TIMESPEC_TO_MS(_x) (((_x)->tv_nsec / 1000000) + ((_x)->tv_sec * (uint64_t)1000))
55
56/** Auto cast from the input type to CONF_ITEM (which is the base type)
57 *
58 * Automatically casts:
59 * - #CONF_SECTION
60 * - #CONF_PAIR
61 * - #CONF_DATA
62 *
63 * To a #CONF_ITEM, whilst performing talloc type checks.
64 */
65#define CF_TO_ITEM(_cf) \
66_Generic((_cf), \
67 CONF_SECTION * : cf_section_to_item((CONF_SECTION const *)_cf), \
68 CONF_SECTION const * : cf_section_to_item((CONF_SECTION const *)_cf), \
69 CONF_PAIR * : cf_pair_to_item((CONF_PAIR const *)_cf), \
70 CONF_PAIR const * : cf_pair_to_item((CONF_PAIR const *)_cf), \
71 CONF_DATA * : cf_data_to_item((CONF_DATA const *)_cf), \
72 CONF_DATA const * : cf_data_to_item((CONF_DATA const *)_cf), \
73 CONF_COMMENT * : cf_comment_to_item((CONF_COMMENT const *)_cf), \
74 CONF_COMMENT const * : cf_comment_to_item((CONF_COMMENT const *)_cf), \
75 default: _cf \
76)
77
78typedef int (*cf_walker_t)(void *data, void *ctx);
79
80#define CF_IDENT_ANY ((void *) (-1))
81
82/*
83 * Generic functions that apply to all types of #CONF_ITEM
84 */
85#define cf_item_add(_parent, _child) _cf_item_add(CF_TO_ITEM(_parent), CF_TO_ITEM(_child))
87
88#define cf_item_remove(_parent, _child) _cf_item_remove(CF_TO_ITEM(_parent), CF_TO_ITEM(_child))
90
91#define cf_item_next(_parent, _curr) _cf_item_next(CF_TO_ITEM(_parent), _curr)
93
94/** Iterate over every child item of a CONF_SECTION (or any CONF_ITEM that has
95 * children).
96 *
97 * @param[in] _parent to iterate over. Any type CF_TO_ITEM() accepts.
98 * @param[in] _iter Name of the iteration variable. Declared in the
99 * scope of the loop with type `CONF_ITEM *`.
100 *
101 * Example:
102 * cf_item_foreach(my_section, ci) {
103 * if (cf_item_is_pair(ci)) { ... }
104 * }
105 */
106#define cf_item_foreach(_parent, _iter) \
107 for (CONF_ITEM *_iter = cf_item_next(_parent, NULL); _iter != NULL; _iter = cf_item_next(_parent, _iter))
108
109#define cf_item_prev(_parent, _curr) _cf_item_prev(CF_TO_ITEM(_parent), _curr)
110CONF_ITEM *_cf_item_prev(CONF_ITEM const *parent, CONF_ITEM const *prev);
111
112#define cf_root(_cf) _cf_root(CF_TO_ITEM(_cf))
114
115#define cf_parent(_cf) _cf_parent(CF_TO_ITEM(_cf))
116CONF_ITEM *_cf_parent(CONF_ITEM const *ci);
117
118#define cf_lineno(_cf) _cf_lineno(CF_TO_ITEM(_cf))
119int _cf_lineno(CONF_ITEM const *ci);
120
121#define cf_filename(_cf) _cf_filename(CF_TO_ITEM(_cf))
122char const *_cf_filename(CONF_ITEM const *ci);
123
124bool cf_item_is_section(CONF_ITEM const *ci);
125bool cf_item_is_pair(CONF_ITEM const *ci);
126bool cf_item_is_data(CONF_ITEM const *ci);
127bool cf_item_is_comment(CONF_ITEM const *ci);
128
129/** @hidecallergraph */
131/** @hidecallergraph */
133/** @hidecallergraph */
135/** @hidecallergraph */
137
138/** @hidecallergraph */
140/** @hidecallergraph */
142/** @hidecallergraph */
144/** @hidecallergraph */
146
147/** Allocate a new comment item attached to `parent`.
148 *
149 * Inserted into the parent's ordered children list so it appears between
150 * the surrounding pairs/sections at output time. Not indexed by name -
151 * comment lookup isn't meaningful.
152 *
153 * `text` is `talloc_strdup`ed onto the new node so the caller can free their
154 * copy. Returns NULL if allocation fails.
155 */
157
158/** @hidecallergraph */
159char const *cf_comment_text(CONF_COMMENT const *c);
160
161/** Control whether the CF parser preserves `# ...` comments.
162 *
163 * Defaults to off (historical behaviour: comments are dropped at parse
164 * time). Utilities that want comments to round-trip through the CF tree
165 * should call the setter before `cf_file_read()`. The runtime server
166 * parser never opts in.
167 */
168void cf_preserve_comments_set(bool preserve);
169
170/** Opt out of `${var}` expansion when reading config (default: enabled).
171 *
172 * Utilities that round-trip the source - e.g. radjson2conf rebuilding
173 * a fragment from JSON - call this with `false` so values containing
174 * `${...}` survive verbatim instead of being resolved against an
175 * incomplete tree. $INCLUDE handling is a separate parser path and
176 * is unaffected.
177 */
178void cf_expand_variables_set(bool expand);
179
180#define cf_filename_set(_ci, _filename) _cf_filename_set(CF_TO_ITEM(_ci), _filename)
181void _cf_filename_set(CONF_ITEM *cs, char const *filename);
182
183#define cf_lineno_set(_ci, _lineno) _cf_lineno_set(CF_TO_ITEM(_ci), _lineno)
184void _cf_lineno_set(CONF_ITEM *cs, int lineno);
185
187
188#define cf_item_mark_parsed(_cf) _cf_item_mark_parsed(CF_TO_ITEM(_cf))
190
191#define cf_item_is_parsed(_cf) _cf_item_is_parsed(CF_TO_ITEM(_cf))
193
194/*
195 * Section manipulation and searching
196 */
197#ifndef NDEBUG
198# define cf_section_alloc(_ctx, _parent, _name1, _name2) \
199 _cf_section_alloc(_ctx, _parent, _name1, _name2, __FILE__, __LINE__)
200#else
201# define cf_section_alloc(_ctx, _parent, _name1, _name2) \
202 _cf_section_alloc(_ctx, _parent, _name1, _name2, NULL, 0)
203#endif
205 char const *name1, char const *name2,
206 char const *filename, int lineno);
207CONF_SECTION *cf_section_dup(TALLOC_CTX *ctx, CONF_SECTION *parent, CONF_SECTION const *cs,
208 char const *name1, char const *name2, bool copy_meta);
209
210#define cf_section_foreach(_parent, _iter) \
211 for (CONF_SECTION *_iter = cf_section_first(_parent); _iter; _iter = cf_section_next(_parent, _iter))
212
213/** @hidecallergraph */
215
216/** @hidecallergraph */
218
219/** @hidecallergraph */
221
222/** @hidecallergraph */
223CONF_SECTION *cf_section_find(CONF_SECTION const *cs, char const *name1, char const *name2);
224/** @hidecallergraph */
226 char const *name1, char const *name2);
227
228#define cf_section_find_in_parent(_cf, _name1, _name2) \
229 _cf_section_find_in_parent(CF_TO_ITEM(_cf), _name1, _name2)
231 char const *name1, char const *name2);
232
233#define cf_section_find_parent(_cf, _name1, _name2) \
234 _cf_section_find_parent(CF_TO_ITEM(_cf), _name1, _name2)
236 char const *name1, char const *name2);
237
238char const *cf_section_value_find(CONF_SECTION const *, char const *attr);
239
240int8_t cf_section_name_cmp(CONF_SECTION const *cs, char const *name1, char const *name2);
241/** @hidecallergraph */
242char const *cf_section_name1(CONF_SECTION const *cs);
243/** @hidecallergraph */
244char const *cf_section_name2(CONF_SECTION const *cs);
245/** @hidecallergraph */
246char const *cf_section_name(CONF_SECTION const *cs);
247char const *cf_section_argv(CONF_SECTION const *cs, int argc);
250
251#define cf_section_free_children(_x) cf_item_free_children(cf_section_to_item(_x))
252
253
254/*
255 * Pair manipulation and searching
256 */
257CONF_PAIR *cf_pair_alloc(CONF_SECTION *parent, char const *attr, char const *value,
258 fr_token_t op, fr_token_t lhs_type, fr_token_t rhs_type);
259
260CONF_PAIR *cf_pair_dup(CONF_SECTION *parent, CONF_PAIR *cp, bool copy_meta);
261
262int cf_pair_replace(CONF_SECTION *cs, CONF_PAIR *cp, char const *value);
263
265
266CONF_PAIR *cf_pair_next(CONF_SECTION const *cs, CONF_PAIR const *curr);
267
268CONF_PAIR *cf_pair_prev(CONF_SECTION const *cs, CONF_PAIR const *curr);
269
270CONF_PAIR *cf_pair_find(CONF_SECTION const *cs, char const *name);
271
272CONF_PAIR *cf_pair_find_next(CONF_SECTION const *cs, CONF_PAIR const *prev, char const *name);
273
274CONF_PAIR *cf_pair_find_in_parent(CONF_SECTION const *cs, char const *attr);
275
276int cf_pair_replace_or_add(CONF_SECTION *cs, char const *ref, char const *value) CC_HINT(nonnull);
277
278unsigned int cf_pair_count_descendents(CONF_SECTION const *cs);
279
280unsigned int cf_pair_count(CONF_SECTION const *cs, char const *attr);
281
282/** @hidecallergraph */
283char const *cf_pair_attr(CONF_PAIR const *pair);
284/** @hidecallergraph */
285char const *cf_pair_value(CONF_PAIR const *pair);
286/** @hidecallergraph */
288
291
292/*
293 * Data manipulation and searching
294 */
295#define cf_data_find(_cf, _type, _name) _cf_data_find(CF_TO_ITEM(_cf), #_type, _name)
296CONF_DATA const *_cf_data_find(CONF_ITEM const *ci, char const *type, char const *name);
297
298#define cf_data_find_next(_cf, _prev, _type, _name) _cf_data_find_next(CF_TO_ITEM(_cf), CF_TO_ITEM(_prev), #_type, _name)
299CONF_DATA const *_cf_data_find_next(CONF_ITEM const *ci, CONF_ITEM const *prev, char const *type, char const *name);
300
301#define cf_data_find_in_parent(_cf, _type, _name) _cf_data_find_in_parent(CF_TO_ITEM(_cf), #_type, _name)
302CONF_DATA *_cf_data_find_in_parent(CONF_ITEM const *ci, char const *type, char const *name);
303
304void *cf_data_value(CONF_DATA const *cd);
305
306#define cf_data_add(_cf, _data, _name, _free) _cf_data_add(CF_TO_ITEM(_cf), (void const *) _data, _name, _free, __FILE__, __LINE__)
307CONF_DATA const *_cf_data_add(CONF_ITEM *ci, void const *data, char const *name, bool free, char const *filename, int lineno);
308
309#define cf_data_add_static(_cf, _data, _type, _name) _cf_data_add_static(CF_TO_ITEM(_cf), _data, #_type, _name, __FILE__, __LINE__)
310CONF_DATA const *_cf_data_add_static(CONF_ITEM *ci, void const *data, char const *type, char const *name, char const *filename, int lineno);
311
312/** Remove an item from a parent by type and name
313 *
314 * @param[in] _cf conf section or pair to remove data from.
315 * @param[in] _type of data to remove.
316 * @param[in] _name of data to remove.
317 */
318#define cf_data_remove(_cf, _type, _name) _cf_data_remove(CF_TO_ITEM(_cf), cf_data_find(_cf, _type, _name))
319
320/** Remove an item from a parent
321 *
322 * @param[in] _cf conf section or pair to remove data from.
323 * @param[in] _cd conf data to remove.
324 */
325#define cf_data_remove_by_data(_cf, _cd) _cf_data_remove(CF_TO_ITEM(_cf), _cd)
326void *_cf_data_remove(CONF_ITEM *ci, CONF_DATA const *_cd);
327
328#define cf_data_walk(_cf, _type, _cb, _ctx) _cf_data_walk(CF_TO_ITEM(_cf), #_type, _cb, _ctx)
329int _cf_data_walk(CONF_ITEM *ci, char const *type, cf_walker_t cb, void *ctx);
330
331/*
332 * Validation
333 */
334int cf_pair_in_table(int32_t *out, fr_table_num_sorted_t const *table, size_t table_len, CONF_PAIR *cp);
335
336/*
337 * Error logging
338 */
339
340#define cf_log_err(_cf, _fmt, ...) _cf_log(L_ERR, CF_TO_ITEM(_cf), __FILE__, __LINE__, _fmt, ## __VA_ARGS__)
341#define cf_log_warn(_cf, _fmt, ...) _cf_log(L_WARN, CF_TO_ITEM(_cf), __FILE__, __LINE__, _fmt, ## __VA_ARGS__)
342#define cf_log_info(_cf, _fmt, ...) _cf_log(L_INFO, CF_TO_ITEM(_cf), __FILE__, __LINE__, _fmt, ## __VA_ARGS__)
343#define cf_log_debug(_cf, _fmt, ...) _cf_log(L_DBG, CF_TO_ITEM(_cf), __FILE__, __LINE__, _fmt, ## __VA_ARGS__)
344void _cf_vlog(fr_log_type_t type, CONF_ITEM const *ci, char const *file, int line, char const *fmt, va_list ap) CC_HINT(format (printf, 5, 0));
345void _cf_log(fr_log_type_t type, CONF_ITEM const *ci, char const *file, int line, char const *fmt, ...) CC_HINT(format (printf, 5, 6));
346
347#define cf_log_perr(_cf, _fmt, ...) _cf_log_perr(L_ERR, CF_TO_ITEM(_cf), __FILE__, __LINE__, NULL, _fmt, ## __VA_ARGS__)
348#define cf_log_pwarn(_cf, _fmt, ...) _cf_log_perr(L_WARN, CF_TO_ITEM(_cf), __FILE__, __LINE__, NULL, _fmt, ## __VA_ARGS__)
349
350void _cf_vlog_perr(fr_log_type_t type, CONF_ITEM const *ci, char const *file, int line,
351 fr_log_perror_format_t const *f_rules, char const *fmt, va_list ap)
352 CC_HINT(format (printf, 6, 0));
353void _cf_log_perr(fr_log_type_t type, CONF_ITEM const *ci, char const *file, int line,
354 fr_log_perror_format_t const *f_rules, char const *fmt, ...)
355 CC_HINT(format (printf, 6, 7));
356
357#define cf_log_debug_prefix(_cf, _fmt, ...) _cf_log_with_filename(L_DBG, CF_TO_ITEM(_cf), __FILE__, __LINE__, _fmt, ## __VA_ARGS__)
358void _cf_log_with_filename(fr_log_type_t type, CONF_ITEM const *ci, char const *file, int line, char const *fmt, ...) CC_HINT(format (printf, 5, 6));
359
360/** Log an error message against a specified child
361 *
362 * @param[in] _parent CONF_SECTION.
363 * @param[in] _child string identifier.
364 * @param[in] _fmt of message.
365 * @param[in] ... arguments.
366 */
367#define cf_log_err_by_child(_parent, _child, _fmt, ...) _cf_log_by_child(L_ERR, _parent, _child, __FILE__, __LINE__, _fmt, ## __VA_ARGS__)
368
369/** Log an error message against a specified child, draining the thread local error stack
370 *
371 * @param[in] _parent CONF_SECTION.
372 * @param[in] _child string identifier.
373 * @param[in] _f_rules Line prefixes.
374 * @param[in] _fmt of message.
375 * @param[in] ... arguments.
376 */
377#define cf_log_perr_by_child(_parent, _child, _f_rules, _fmt, ...) _cf_log_perr_by_child(L_ERR, _parent, _child, __FILE__, __LINE__, _f_rules, _fmt, ## __VA_ARGS__)
378
379/** Log a warning message against a specified child
380 *
381 * @param[in] _parent CONF_SECTION.
382 * @param[in] _child string identifier.
383 * @param[in] _fmt of message.
384 * @param[in] ... arguments.
385 */
386#define cf_log_warn_by_child(_parent, _child, _fmt, ...) _cf_log_by_child(L_WARN, _parent, _child, __FILE__, __LINE__, _fmt, ## __VA_ARGS__)
387
388/** Log an info message against a specified child
389 *
390 * @param[in] _parent CONF_SECTION.
391 * @param[in] _child string identifier.
392 * @param[in] _fmt of message.
393 * @param[in] ... arguments.
394 */
395#define cf_log_info_by_child(_parent, _child, _fmt, ...) _cf_log_by_child(L_INFO, _parent, _child, __FILE__, __LINE__, _fmt, ## __VA_ARGS__)
396
397/** Log a debug message against a specified child
398 *
399 * @param[in] _parent CONF_SECTION.
400 * @param[in] _child string identifier.
401 * @param[in] _fmt of message.
402 * @param[in] ... arguments.
403 */
404#define cf_log_debug_by_child(_parent, _child, _fmt, ...) _cf_log_by_child(L_DBG, _parent, _child, __FILE__, __LINE__, _fmt, ## __VA_ARGS__)
405void _cf_log_by_child(fr_log_type_t type, CONF_SECTION const *parent, char const *child,
406 char const *file, int line, char const *fmt, ...) CC_HINT(format (printf, 6, 7));
407
408void _cf_log_perr_by_child(fr_log_type_t type, CONF_SECTION const *parent, char const *child,
409 char const *file, int line, fr_log_perror_format_t const *f_rules,
410 char const *fmt, ...) CC_HINT(format (printf, 7, 8));
411
412#define cf_item_debug(_cf) _cf_item_debug(CF_TO_ITEM(_cf))
413void _cf_item_debug(CONF_ITEM const *ci);
414
415void cf_pair_debug(CONF_PAIR *cp);
417
418#define cf_canonicalize_error(_ci, _slen, _msg, _str) _cf_canonicalize_error(CF_TO_ITEM(_ci), _slen, _msg, _str)
419void _cf_canonicalize_error(CONF_ITEM *ci, ssize_t slen, char const *msg, char const *str);
420
421#ifdef __cplusplus
422}
423#endif
log_entry msg
Definition acutest.h:941
static int const char * fmt
Definition acutest.h:632
void int line
Definition acutest.h:804
#define RCSIDH(h, id)
Definition build.h:561
char const * text
Comment text, with the leading # and any surrounding whitespace stripped.
Definition cf_priv.h:188
A # ... comment line preserved verbatim from the input.
Definition cf_priv.h:185
Internal data that is associated with a configuration section.
Definition cf_priv.h:195
Common header for all CONF_* types.
Definition cf_priv.h:54
Configuration AVP similar to a fr_pair_t.
Definition cf_priv.h:77
A section grouping multiple CONF_PAIR.
Definition cf_priv.h:106
void _cf_log_with_filename(fr_log_type_t type, CONF_ITEM const *ci, char const *file, int line, char const *fmt,...))
Log a debug message relating to a CONF_ITEM.
Definition cf_util.c:2331
CONF_ITEM * cf_data_to_item(CONF_DATA const *cs)
Cast CONF_DATA to a CONF_ITEM.
Definition cf_util.c:741
bool cf_item_is_pair(CONF_ITEM const *ci)
Determine if CONF_ITEM is a CONF_PAIR.
Definition cf_util.c:619
fr_token_t cf_pair_attr_quote(CONF_PAIR const *pair)
Return the value (lhs) quoting of a pair.
Definition cf_util.c:1775
CONF_SECTION * _cf_section_find_parent(CONF_ITEM const *ci, char const *name1, char const *name2)
Find a parent CONF_SECTION with name1 and optionally name2.
Definition cf_util.c:1303
int _cf_data_walk(CONF_ITEM *ci, char const *type, cf_walker_t cb, void *ctx)
Walk over a specific type of CONF_DATA.
Definition cf_util.c:2044
unsigned int cf_pair_count_descendents(CONF_SECTION const *cs)
Count the number of conf pairs beneath a section.
Definition cf_util.c:1694
void _cf_item_mark_parsed(CONF_ITEM *ci)
Mark an item as parsed.
Definition cf_util.c:1565
void cf_section_debug(CONF_SECTION *cs)
Ease of use from debugger.
Definition cf_util.c:2559
CONF_DATA * _cf_data_find_in_parent(CONF_ITEM const *ci, char const *type, char const *name)
Find matching data in the specified section or one of its parents.
Definition cf_util.c:1891
CONF_ITEM * _cf_item_remove(CONF_ITEM *parent, CONF_ITEM *child)
Remove item from parent and fixup trees.
Definition cf_util.c:434
void _cf_vlog_perr(fr_log_type_t type, CONF_ITEM const *ci, char const *file, int line, fr_log_perror_format_t const *f_rules, char const *fmt, va_list ap))
Log an error message relating to a CONF_ITEM.
Definition cf_util.c:2219
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:1857
CONF_PAIR * cf_pair_alloc(CONF_SECTION *parent, char const *attr, char const *value, fr_token_t op, fr_token_t lhs_type, fr_token_t rhs_type)
Allocate a CONF_PAIR.
Definition cf_util.c:1475
fr_token_t cf_section_argv_quote(CONF_SECTION const *cs, int argc)
Return the quoting for one of the variadic arguments.
Definition cf_util.c:1456
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:1709
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:2117
int cf_pair_replace_or_add(CONF_SECTION *cs, char const *ref, char const *value)
Definition cf_util.c:2600
CONF_PAIR * cf_pair_dup(CONF_SECTION *parent, CONF_PAIR *cp, bool copy_meta)
Duplicate a CONF_PAIR.
Definition cf_util.c:1517
void _cf_log_by_child(fr_log_type_t type, CONF_SECTION const *parent, char const *child, char const *file, int line, char const *fmt,...))
Log an error message in the context of a child pair of the specified parent.
Definition cf_util.c:2370
void cf_item_free_children(CONF_ITEM *ci)
Definition cf_util.c:2569
char const * cf_section_value_find(CONF_SECTION const *, char const *attr)
Find a pair in a CONF_SECTION.
Definition cf_util.c:1327
CONF_ITEM * cf_comment_to_item(CONF_COMMENT const *c)
Cast a CONF_COMMENT back to a CONF_ITEM.
Definition cf_util.c:767
char const * cf_section_name2(CONF_SECTION const *cs)
Return the second identifier of a CONF_SECTION.
Definition cf_util.c:1393
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:1346
void * cf_data_value(CONF_DATA const *cd)
Return the user assigned value of CONF_DATA.
Definition cf_util.c:1910
CONF_ITEM * cf_section_to_item(CONF_SECTION const *cs)
Cast a CONF_SECTION to a CONF_ITEM.
Definition cf_util.c:725
void _cf_vlog(fr_log_type_t type, CONF_ITEM const *ci, char const *file, int line, char const *fmt, va_list ap))
Log an error message relating to a CONF_ITEM.
Definition cf_util.c:2157
void _cf_log_perr(fr_log_type_t type, CONF_ITEM const *ci, char const *file, int line, fr_log_perror_format_t const *f_rules, char const *fmt,...))
Log an error message relating to a CONF_ITEM.
Definition cf_util.c:2308
CONF_ITEM * _cf_parent(CONF_ITEM const *ci)
Return the parent of a CONF_ITEM.
Definition cf_util.c:563
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:1204
char const * cf_section_name1(CONF_SECTION const *cs)
Return the first identifier of a CONF_SECTION.
Definition cf_util.c:1379
void _cf_filename_set(CONF_ITEM *cs, char const *filename)
Set the filename of a CONF_ITEM.
Definition cf_util.c:977
CONF_SECTION * _cf_section_alloc(TALLOC_CTX *ctx, CONF_SECTION *parent, char const *name1, char const *name2, char const *filename, int lineno)
Allocate a CONF_SECTION.
Definition cf_util.c:870
CONF_ITEM * _cf_item_next(CONF_ITEM const *parent, CONF_ITEM const *curr)
Return the next child of the CONF_ITEM.
Definition cf_util.c:497
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:1235
CONF_SECTION * cf_item_to_section(CONF_ITEM const *ci)
Cast a CONF_ITEM to a CONF_SECTION.
Definition cf_util.c:671
CONF_DATA * cf_item_to_data(CONF_ITEM const *ci)
Cast CONF_ITEM to CONF_DATA performing a type check.
Definition cf_util.c:691
bool cf_item_is_comment(CONF_ITEM const *ci)
Determine if CONF_ITEM is a CONF_COMMENT.
Definition cf_util.c:750
CONF_SECTION * _cf_root(CONF_ITEM const *ci)
Return the top level CONF_SECTION holding all other CONF_ITEM.
Definition cf_util.c:545
CONF_COMMENT * cf_comment_alloc(CONF_SECTION *parent, char const *text)
Allocate a new comment item attached to parent.
Definition cf_util.c:821
void cf_preserve_comments_set(bool preserve)
Control whether the CF parser preserves # ... comments.
Definition cf_util.c:786
CONF_DATA const * _cf_data_add_static(CONF_ITEM *ci, void const *data, char const *type, char const *name, char const *filename, int lineno)
Add non-talloced user data to a config section.
Definition cf_util.c:1975
CONF_PAIR * cf_pair_find(CONF_SECTION const *cs, char const *name)
Search for a CONF_PAIR with a specific name.
Definition cf_util.c:1628
CONF_COMMENT * cf_item_to_comment(CONF_ITEM const *ci)
Cast a CONF_ITEM to a CONF_COMMENT (asserts on type mismatch).
Definition cf_util.c:758
char const * cf_section_name(CONF_SECTION const *cs)
Return name2 if set, else name1.
Definition cf_util.c:1405
char const * _cf_filename(CONF_ITEM const *ci)
Return the filename the CONF_ITEM was parsed in.
Definition cf_util.c:591
CONF_DATA const * _cf_data_add(CONF_ITEM *ci, void const *data, char const *name, bool free, char const *filename, int lineno)
Add talloced user data to a config section.
Definition cf_util.c:1933
bool cf_item_is_data(CONF_ITEM const *ci)
Determine if CONF_ITEM is CONF_DATA.
Definition cf_util.c:633
bool _cf_item_is_parsed(CONF_ITEM *ci)
Return whether an item has already been parsed.
Definition cf_util.c:1577
void _cf_item_debug(CONF_ITEM const *ci)
Print out debugging information about a CONFIG_ITEM.
Definition cf_util.c:2425
fr_token_t cf_pair_operator(CONF_PAIR const *pair)
Return the operator of a pair.
Definition cf_util.c:1760
CONF_PAIR * cf_pair_find_next(CONF_SECTION const *cs, CONF_PAIR const *prev, char const *name)
Find a pair with a name matching attr, after specified pair.
Definition cf_util.c:1642
fr_token_t cf_pair_value_quote(CONF_PAIR const *pair)
Return the value (rhs) quoting of a pair.
Definition cf_util.c:1790
CONF_PAIR * cf_pair_first(CONF_SECTION const *cs)
Return the first child that's a CONF_PAIR.
Definition cf_util.c:1589
CONF_SECTION * cf_section_find_next(CONF_SECTION const *cs, CONF_SECTION const *subcs, char const *name1, char const *name2)
Return the next matching section.
Definition cf_util.c:1256
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:1602
void _cf_canonicalize_error(CONF_ITEM *ci, ssize_t slen, char const *msg, char const *str)
Definition cf_util.c:2578
CONF_SECTION * _cf_section_find_in_parent(CONF_ITEM const *ci, char const *name1, char const *name2)
Find an ancestor of the passed CONF_ITEM which has a child matching a specific name1 and optionally n...
Definition cf_util.c:1279
CONF_DATA const * _cf_data_find_next(CONF_ITEM const *ci, CONF_ITEM const *prev, char const *type, char const *name)
Return the next item of user data.
Definition cf_util.c:1875
bool cf_item_is_section(CONF_ITEM const *ci)
Determine if CONF_ITEM is a CONF_SECTION.
Definition cf_util.c:605
char const * cf_comment_text(CONF_COMMENT const *c)
Definition cf_util.c:773
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:1052
CONF_PAIR * cf_pair_find_in_parent(CONF_SECTION const *cs, char const *attr)
Find a pair with a name matching attr in the specified section or one of its parents.
Definition cf_util.c:1656
char const * cf_section_argv(CONF_SECTION const *cs, int argc)
Return variadic argument at the specified index.
Definition cf_util.c:1421
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:1615
void cf_expand_variables_set(bool expand)
Opt out of ${var} expansion when reading config (default: enabled).
Definition cf_util.c:811
int _cf_lineno(CONF_ITEM const *ci)
Return the lineno the CONF_ITEM was parsed at.
Definition cf_util.c:577
CONF_SECTION * cf_section_first(CONF_SECTION const *cs)
Return the first child in a CONF_SECTION.
Definition cf_util.c:1191
CONF_PAIR * cf_item_to_pair(CONF_ITEM const *ci)
Cast a CONF_ITEM to a CONF_PAIR.
Definition cf_util.c:651
fr_token_t cf_section_name2_quote(CONF_SECTION const *cs)
Return the quoting of the name2 identifier.
Definition cf_util.c:1438
CONF_ITEM * _cf_item_prev(CONF_ITEM const *parent, CONF_ITEM const *prev)
Return the next child of cs.
Definition cf_util.c:512
void * _cf_data_remove(CONF_ITEM *ci, CONF_DATA const *_cd)
Remove data from a configuration section.
Definition cf_util.c:2019
char const * cf_pair_value(CONF_PAIR const *pair)
Return the value of a CONF_PAIR.
Definition cf_util.c:1746
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:1549
void cf_pair_debug(CONF_PAIR *cp)
Ease of use from debugger.
Definition cf_util.c:2552
int _cf_item_add(CONF_ITEM *parent, CONF_ITEM *child)
Add a child.
Definition cf_util.c:394
CONF_ITEM * cf_pair_to_item(CONF_PAIR const *cp)
Cast a CONF_PAIR to a CONF_ITEM.
Definition cf_util.c:709
void _cf_log(fr_log_type_t type, CONF_ITEM const *ci, char const *file, int line, char const *fmt,...))
Log an error message relating to a CONF_ITEM.
Definition cf_util.c:2196
void _cf_log_perr_by_child(fr_log_type_t type, CONF_SECTION const *parent, char const *child, char const *file, int line, fr_log_perror_format_t const *f_rules, char const *fmt,...))
Log an error message in the context of a child pair of the specified parent.
Definition cf_util.c:2401
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:1217
void _cf_lineno_set(CONF_ITEM *cs, int lineno)
Set the line number of a CONF_ITEM.
Definition cf_util.c:989
char const * cf_pair_attr(CONF_PAIR const *pair)
Return the attr of a CONF_PAIR.
Definition cf_util.c:1730
int(* cf_walker_t)(void *data, void *ctx)
Definition cf_util.h:78
Test enumeration values.
Definition dict_test.h:92
free(array)
fr_log_type_t
Definition log.h:51
long int ssize_t
static char const * name
fr_aka_sim_id_type_t type
An element in a lexicographically sorted array of name to num mappings.
Definition table.h:49
enum fr_token fr_token_t
static fr_slen_t parent
Definition pair.h:864
static fr_slen_t data
Definition value.h:1366
static fr_sbuff_err_t char ** out
Definition value.h:1061
int nonnull(2, 5))