26 RCSIDH(conf_file_h,
"$Id: da4a47ea5a14dea7badf696056e7da0ae1b1bc41 $")
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>
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_usec / 1000000) + ((_x)->tv_sec * (uint64_t)1000))
65 #define CF_TO_ITEM(_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), \
78 #define CF_IDENT_ANY ((void *) (-1))
83 #define cf_item_add(_parent, _child) _cf_item_add(CF_TO_ITEM(_parent), CF_TO_ITEM(_child))
86 #define cf_item_insert_after(_parent, _prev, _child) _cf_item_insert_after(CF_TO_ITEM(_parent), CF_TO_ITEM(_prev), CF_TO_ITEM(_child))
89 #define cf_item_remove(_parent, _child) _cf_item_remove(CF_TO_ITEM(_parent), CF_TO_ITEM(_child))
92 #define cf_item_next(_ci, _curr) _cf_item_next(CF_TO_ITEM(_ci), _curr)
95 #define cf_item_prev(_ci, _curr) _cf_item_prev(CF_TO_ITEM(_ci), _curr)
98 #define cf_root(_cf) _cf_root(CF_TO_ITEM(_cf))
101 #define cf_parent(_cf) _cf_parent(CF_TO_ITEM(_cf))
104 #define cf_lineno(_cf) _cf_lineno(CF_TO_ITEM(_cf))
107 #define cf_filename(_cf) _cf_filename(CF_TO_ITEM(_cf))
128 #define cf_filename_set(_ci, _filename) _cf_filename_set(CF_TO_ITEM(_ci), _filename)
131 #define cf_lineno_set(_ci, _lineno) _cf_lineno_set(CF_TO_ITEM(_ci), _lineno)
140 # define cf_section_alloc(_ctx, _parent, _name1, _name2) \
141 _cf_section_alloc(_ctx, _parent, _name1, _name2, __FILE__, __LINE__)
143 # define cf_section_alloc(_ctx, _parent, _name1, _name2) \
144 _cf_section_alloc(_ctx, _parent, _name1, _name2, NULL, 0)
147 char const *name1,
char const *name2,
148 char const *filename,
int lineno);
150 char const *name1,
char const *name2,
bool copy_meta);
152 #define cf_section_foreach(_parent, _iter) \
153 for (CONF_SECTION *_iter = cf_section_first(_parent); _iter; _iter = cf_section_next(_parent, _iter))
168 char const *name1,
char const *name2);
170 #define cf_section_find_in_parent(_cf, _name1, _name2) \
171 _cf_section_find_in_parent(CF_TO_ITEM(_cf), _name1, _name2)
173 char const *name1,
char const *name2);
175 #define cf_section_find_parent(_cf, _name1, _name2) \
176 _cf_section_find_parent(CF_TO_ITEM(_cf), _name1, _name2)
178 char const *name1,
char const *name2);
196 #define cf_section_free_children(_x) cf_item_free_children(cf_section_to_item(_x))
244 #define cf_data_find(_cf, _type, _name) _cf_data_find(CF_TO_ITEM(_cf), #_type, _name)
247 #define cf_data_find_next(_cf, _prev, _type, _name) _cf_data_find_next(CF_TO_ITEM(_cf), CF_TO_ITEM(_prev), #_type, _name)
250 #define cf_data_find_in_parent(_cf, _type, _name) _cf_data_find_in_parent(CF_TO_ITEM(_cf), #_type, _name)
255 #define cf_data_add(_cf, _data, _name, _free) _cf_data_add(CF_TO_ITEM(_cf), (void const *) _data, _name, _free, __FILE__, __LINE__)
258 #define cf_data_add_static(_cf, _data, _type, _name) _cf_data_add_static(CF_TO_ITEM(_cf), _data, #_type, _name, __FILE__, __LINE__)
267 #define cf_data_remove(_cf, _type, _name) _cf_data_remove(CF_TO_ITEM(_cf), cf_data_find(_cf, _type, _name))
274 #define cf_data_remove_by_data(_cf, _cd) _cf_data_remove(CF_TO_ITEM(_cf), _cd)
277 #define cf_data_walk(_cf, _type, _cb, _ctx) _cf_data_walk(CF_TO_ITEM(_cf), #_type, _cb, _ctx)
289 #define cf_log_err(_cf, _fmt, ...) _cf_log(L_ERR, CF_TO_ITEM(_cf), __FILE__, __LINE__, _fmt, ## __VA_ARGS__)
290 #define cf_log_warn(_cf, _fmt, ...) _cf_log(L_WARN, CF_TO_ITEM(_cf), __FILE__, __LINE__, _fmt, ## __VA_ARGS__)
291 #define cf_log_info(_cf, _fmt, ...) _cf_log(L_INFO, CF_TO_ITEM(_cf), __FILE__, __LINE__, _fmt, ## __VA_ARGS__)
292 #define cf_log_debug(_cf, _fmt, ...) _cf_log(L_DBG, CF_TO_ITEM(_cf), __FILE__, __LINE__, _fmt, ## __VA_ARGS__)
296 #define cf_log_perr(_cf, _fmt, ...) _cf_log_perr(L_ERR, CF_TO_ITEM(_cf), __FILE__, __LINE__, NULL, _fmt, ## __VA_ARGS__)
297 #define cf_log_pwarn(_cf, _fmt, ...) _cf_log_perr(L_WARN, CF_TO_ITEM(_cf), __FILE__, __LINE__, NULL, _fmt, ## __VA_ARGS__)
301 CC_HINT(
format (printf, 6, 0));
304 CC_HINT(
format (printf, 6, 7));
306 #define cf_log_debug_prefix(_cf, _fmt, ...) _cf_log_with_filename(L_DBG, CF_TO_ITEM(_cf), __FILE__, __LINE__, _fmt, ## __VA_ARGS__)
316 #define cf_log_err_by_child(_parent, _child, _fmt, ...) _cf_log_by_child(L_ERR, _parent, _child, __FILE__, __LINE__, _fmt, ## __VA_ARGS__)
326 #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__)
335 #define cf_log_warn_by_child(_parent, _child, _fmt, ...) _cf_log_by_child(L_WARN, _parent, _child, __FILE__, __LINE__, _fmt, ## __VA_ARGS__)
344 #define cf_log_info_by_child(_parent, _child, _fmt, ...) _cf_log_by_child(L_INFO, _parent, _child, __FILE__, __LINE__, _fmt, ## __VA_ARGS__)
353 #define cf_log_debug_by_child(_parent, _child, _fmt, ...) _cf_log_by_child(L_DBG, _parent, _child, __FILE__, __LINE__, _fmt, ## __VA_ARGS__)
355 char const *
file,
int line,
char const *
fmt, ...) CC_HINT(
format (printf, 6, 7));
359 char const *
fmt, ...) CC_HINT(
format (printf, 7, 8));
361 #define cf_item_debug(_cf) _cf_item_debug(CF_TO_ITEM(_cf))
367 #define cf_canonicalize_error(_ci, _slen, _msg, _str) _cf_canonicalize_error(CF_TO_ITEM(_ci), _slen, _msg, _str)
static int const char * fmt
Internal data that is associated with a configuration section.
Common header for all CONF_* types.
Configuration AVP similar to a fr_pair_t.
A section grouping multiple CONF_PAIR.
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.
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.
CONF_ITEM * _cf_item_remove(CONF_ITEM *parent, CONF_ITEM *child)
Remove item from parent and fixup trees.
bool cf_item_is_pair(CONF_ITEM const *ci)
Determine if CONF_ITEM is a CONF_PAIR.
CONF_PAIR * cf_item_to_pair(CONF_ITEM const *ci)
Cast a CONF_ITEM to a CONF_PAIR.
CONF_ITEM * cf_section_to_item(CONF_SECTION const *cs)
Cast a CONF_SECTION to a CONF_ITEM.
fr_token_t cf_pair_attr_quote(CONF_PAIR const *pair)
Return the value (lhs) quoting of a pair.
char const * cf_section_value_find(CONF_SECTION const *, char const *attr)
Find a pair in a CONF_SECTION.
char const * cf_pair_attr(CONF_PAIR const *pair)
Return the attr of a CONF_PAIR.
void * _cf_data_remove(CONF_ITEM *ci, CONF_DATA const *_cd)
Remove data from a configuration section.
int _cf_data_walk(CONF_ITEM *ci, char const *type, cf_walker_t cb, void *ctx)
Walk over a specific type of CONF_DATA.
unsigned int cf_pair_count_descendents(CONF_SECTION const *cs)
Count the number of conf pairs beneath a section.
CONF_PAIR * cf_pair_prev(CONF_SECTION const *cs, CONF_PAIR const *curr)
Return the next child that's a CONF_PAIR.
void cf_section_debug(CONF_SECTION *cs)
Ease of use from debugger.
CONF_SECTION * cf_section_find(CONF_SECTION const *cs, char const *name1, char const *name2)
Find a CONF_SECTION with name1 and optionally name2.
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.
fr_token_t cf_section_argv_quote(CONF_SECTION const *cs, int argc)
Return the quoting for one of the variadic arguments.
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.
unsigned int cf_pair_count(CONF_SECTION const *cs, char const *attr)
Count the number of times an attribute occurs in a parent section.
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.
void _cf_item_insert_after(CONF_ITEM *parent, CONF_ITEM *prev, CONF_ITEM *child)
Insert a child after a given one.
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.
void cf_item_free_children(CONF_ITEM *ci)
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.
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.
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.
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.
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.
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.
char const * cf_section_name2(CONF_SECTION const *cs)
Return the second identifier of a CONF_SECTION.
CONF_SECTION * cf_section_first(CONF_SECTION const *cs)
Return the first child in a CONF_SECTION.
char const * cf_pair_value(CONF_PAIR const *pair)
Return the value of a CONF_PAIR.
CONF_ITEM * _cf_item_prev(CONF_ITEM const *ci, CONF_ITEM const *prev)
Return the next child of cs.
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.
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.
CONF_ITEM * _cf_item_next(CONF_ITEM const *ci, CONF_ITEM const *curr)
Return the next child of the CONF_ITEM.
void cf_pair_mark_parsed(CONF_PAIR *cp)
Mark a pair as parsed.
void _cf_filename_set(CONF_ITEM *cs, char const *filename)
Set the filename of a CONF_ITEM.
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...
CONF_SECTION * cf_section_next(CONF_SECTION const *cs, CONF_SECTION const *curr)
Return the next child that's a CONF_SECTION.
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.
fr_slen_t cf_pair_values_concat(fr_sbuff_t *sbuff, CONF_SECTION const *cs, char const *attr, char const *sep)
Concatenate the values of any pairs with name attr.
void * cf_data_value(CONF_DATA const *cd)
Return the user assigned value of CONF_DATA.
CONF_SECTION * _cf_root(CONF_ITEM const *ci)
Return the top level CONF_SECTION holding all other CONF_ITEM.
CONF_PAIR * cf_pair_next(CONF_SECTION const *cs, CONF_PAIR const *curr)
Return the next child that's a CONF_PAIR.
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.
void cf_section_add_name2_quote(CONF_SECTION *cs, fr_token_t token)
Set the quoting of the name2 identifier.
bool cf_item_is_data(CONF_ITEM const *ci)
Determine if CONF_ITEM is CONF_DATA.
void _cf_item_debug(CONF_ITEM const *ci)
Print out debugging information about a CONFIG_ITEM.
fr_token_t cf_pair_operator(CONF_PAIR const *pair)
Return the operator of a pair.
CONF_ITEM * cf_pair_to_item(CONF_PAIR const *cp)
Cast a CONF_PAIR to a CONF_ITEM.
bool cf_pair_is_parsed(CONF_PAIR *cp)
Return whether a pair has already been parsed.
char const * _cf_filename(CONF_ITEM const *ci)
Return the filename the CONF_ITEM was parsed in.
CONF_SECTION * cf_item_to_section(CONF_ITEM const *ci)
Cast a CONF_ITEM to a CONF_SECTION.
fr_token_t cf_pair_value_quote(CONF_PAIR const *pair)
Return the value (rhs) quoting of a pair.
void _cf_canonicalize_error(CONF_ITEM *ci, ssize_t slen, char const *msg, char const *str)
CONF_DATA const * _cf_data_find(CONF_ITEM const *ci, char const *type, char const *name)
Find user data in a config section.
bool cf_item_is_section(CONF_ITEM const *ci)
Determine if CONF_ITEM is a CONF_SECTION.
CONF_DATA * cf_item_to_data(CONF_ITEM const *ci)
Cast CONF_ITEM to CONF_DATA performing a type check.
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.
int _cf_lineno(CONF_ITEM const *ci)
Return the lineno the CONF_ITEM was parsed at.
CONF_PAIR * cf_pair_first(CONF_SECTION const *cs)
Return the next child that's a CONF_PAIR.
CONF_PAIR * cf_pair_find(CONF_SECTION const *cs, char const *name)
Search for a CONF_PAIR with a specific name.
CONF_PAIR * cf_pair_dup(CONF_SECTION *parent, CONF_PAIR *cp, bool copy_meta)
Duplicate a CONF_PAIR.
fr_token_t cf_section_name2_quote(CONF_SECTION const *cs)
Return the quoting of the name2 identifier.
CONF_ITEM * _cf_parent(CONF_ITEM const *ci)
Return the parent of a CONF_ITEM.
char const * cf_section_name1(CONF_SECTION const *cs)
Return the second identifier of a CONF_SECTION.
int cf_pair_replace(CONF_SECTION *cs, CONF_PAIR *cp, char const *value)
Replace pair in a given section with a new pair, of the given value.
void _cf_item_add(CONF_ITEM *parent, CONF_ITEM *child)
Add a child.
void cf_pair_debug(CONF_PAIR *cp)
Ease of use from debugger.
CONF_SECTION * cf_section_prev(CONF_SECTION const *cs, CONF_SECTION const *curr)
Return the previous child that's a CONF_SECTION.
char const * cf_section_name(CONF_SECTION const *cs)
Return name2 if set, else name1.
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.
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.
CONF_ITEM * cf_data_to_item(CONF_DATA const *cs)
Cast CONF_DATA to a CONF_ITEM.
void _cf_lineno_set(CONF_ITEM *cs, int lineno)
Set the line number of a CONF_ITEM.
char const * cf_section_argv(CONF_SECTION const *cs, int argc)
Return variadic argument at the specified index.
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.
int(* cf_walker_t)(void *data, void *ctx)
fr_aka_sim_id_type_t type
An element in a lexicographically sorted array of name to num mappings.
int format(printf, 5, 0))
static size_t char ** out