The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
cf_priv.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: a6330770a2b1da7b5338235d2369219fe38fc527 $
20 *
21 * @file cf_priv.h
22 * @brief Private data structures and types for cf_*.c
23 *
24 * @copyright 2017 The FreeRADIUS server project
25 */
26RCSIDH(cf_priv_h, "$Id: a6330770a2b1da7b5338235d2369219fe38fc527 $")
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
32#include <stdint.h>
33#include <sys/stat.h>
34
35#include <freeradius-devel/server/cf_parse.h>
36#include <freeradius-devel/util/rb.h>
37#include <freeradius-devel/util/dlist.h>
38
39typedef enum conf_type {
44 CONF_ITEM_COMMENT, //!< A `# ...` line preserved verbatim
45 ///< from the input - only created when
46 ///< the parser is asked to keep comments
47 ///< (off by default; the runtime parser
48 ///< doesn't keep them, tooling can opt in).
50
51/** Common header for all CONF_* types
52 *
53 */
54struct cf_item {
55 fr_rb_node_t ident1_node; //!< Entry in the ident1 tree.
56 fr_rb_node_t ident2_node; //!< Entry in the ident2 tree.
57
58 fr_dlist_t entry; //!< Entry in dlist
59 fr_dlist_head_t children; //!< The head of the ordered list of children.
60
61 CONF_ITEM *parent; //!< Parent
62
63 fr_rb_tree_t *ident1; //!< Tree to store the first identifier (name1 || type || attr).
64 fr_rb_tree_t *ident2; //!< Tree to store the second identifier (name2 || name).
65
66 CONF_ITEM_TYPE type; //!< Whether the config item is a config_pair, conf_section or cf_data.
67
68 bool parsed; //!< Was this item used during parsing?
69 bool referenced; //!< Was this item referenced in the config?
70 int lineno; //!< The line number the config item began on.
71 char const *filename; //!< The file the config item was parsed from.
72};
73
74/** Configuration AVP similar to a fr_pair_t
75 *
76 */
77struct cf_pair {
78 CONF_ITEM item; //!< Common set of fields.
79
80 char const *attr; //!< Attribute name
81 char const *value; //!< Attribute value
82
83 fr_token_t op; //!< Operator e.g. =, :=
84 fr_token_t lhs_quote; //!< Name quoting style T_(DOUBLE|SINGLE|BACK)_QUOTE_STRING or T_BARE_WORD.
85 fr_token_t rhs_quote; //!< Value Quoting style T_(DOUBLE|SINGLE|BACK)_QUOTE_STRING or T_BARE_WORD.
86
87 bool pass2; //!< do expansion in pass2.
88 bool printed; //!< Was this item printed already in debug mode?
89};
90
91typedef enum {
92 CF_UNLANG_NONE = 0, //!< no unlang
93 CF_UNLANG_ALLOW, //!< allow unlang in this section
94 CF_UNLANG_SERVER, //!< this section is a virtual server, allow unlang 2 down
95 CF_UNLANG_POLICY, //!< this section is a policy, allow unlang 2 down
96 CF_UNLANG_MODULES, //!< this section is in "modules", allow unlang 2 down
97 CF_UNLANG_EDIT, //!< only edit commands
98 CF_UNLANG_ASSIGNMENT, //!< only assignments inside of map / update
99 CF_UNLANG_DICTIONARY, //!< only local variable definitions
100 CF_UNLANG_CAN_HAVE_UPDATE, //!< can have "update"
102
103/** A section grouping multiple #CONF_PAIR
104 *
105 */
107 CONF_ITEM item; //!< Common set of fields.
108
109 char const *name1; //!< First name token. Given ``foo bar {}`` would be ``foo``.
110 char const *name2; //!< Second name token. Given ``foo bar {}`` would be ``bar``.
111
112 fr_token_t name2_quote; //!< The type of quoting around name2.
113
114 int argc; //!< number of additional arguments
115 char const **argv; //!< additional arguments
117
118 void *base;
119 int depth;
121 bool allow_locals; //!< allow local variables
122 bool at_reference; //!< this thing was created from an @...
123
124 CONF_SECTION *template;
125};
126
127/*
128 * Private getter for cf_file.c's parser hook - the public API is the
129 * `cf_preserve_comments_set()` setter in cf_util.h; the flag itself
130 * lives static in cf_util.c.
131 */
132bool _cf_preserve_comments(void);
133
134/*
135 * Private getter for cf_file.c's cf_expand_variables() short-circuit.
136 * Public API is `cf_expand_variables_set()` in cf_util.h.
137 */
138bool _cf_expand_variables(void);
139
140/** A `# ...` comment line preserved verbatim from the input.
141 *
142 * Only constructed when `cf_preserve_comments` is set before parsing;
143 * the runtime config parser drops comments as it always has.
144 */
146 CONF_ITEM item; //!< Common set of fields.
147
148 char const *text; //!< Comment text, with the leading `#`
149 //!< and any surrounding whitespace stripped.
150};
151
152/** Internal data that is associated with a configuration section
153 *
154 */
155struct cf_data {
156 CONF_ITEM item; //!< Common set of fields.
157
158 char const *type; //!< C type of data being stored.
159 char const *name; //!< Additional qualification of type.
160
161 void const *data; //!< User data.
162 bool is_talloced; //!< If true we can do extra checks.
163};
164
165typedef struct {
167 char const *filename; //!< name of the file
168 CONF_SECTION *cs; //!< CONF_SECTION associated with the file
169 struct stat buf; //!< stat about the file
170 bool from_dir; //!< was read from a directory
171} cf_file_t;
172
173/** Iterate over the contents of a list
174 *
175 * @param[in] _ci to iterate over.
176 * @param[in] _iter Name of iteration variable.
177 * Will be declared in the scope of the loop.
178 * @param[in] _prev previous pointer
179 */
180#define cf_item_foreach_next(_ci, _iter, _prev) \
181 for (CONF_ITEM *_iter = fr_dlist_next(&(_ci)->children, _prev); _iter; _iter = fr_dlist_next(&(_ci)->children, _iter))
182
183/** Iterate over the contents of a list in reverse order
184 *
185 * @param[in] _ci to iterate over.
186 * @param[in] _iter Name of iteration variable.
187 * Will be declared in the scope of the loop.
188 * @param[in] _prev previous pointer
189 */
190#define cf_item_foreach_prev(_ci, _iter, _prev) \
191 for (CONF_ITEM *_iter = fr_dlist_prev(&(_ci)->children, _prev); _iter; _iter = fr_dlist_prev(&(_ci)->children, _iter))
192
193/** Check if the CONF_ITEM has no children.
194 *
195 * Which is the common use-case
196 *
197 * @param[in] ci to check
198 * @return true/false
199 */
200static inline CC_HINT(nonnull) bool cf_item_has_no_children(CONF_ITEM const *ci)
201{
202 return fr_dlist_empty(&ci->children);
203}
204
205#ifdef __cplusplus
206}
207#endif
#define RCSIDH(h, id)
Definition build.h:513
fr_rb_node_t ident2_node
Entry in the ident2 tree.
Definition cf_priv.h:56
CONF_SECTION * cs
CONF_SECTION associated with the file.
Definition cf_priv.h:168
bool printed
Was this item printed already in debug mode?
Definition cf_priv.h:88
CONF_ITEM item
Common set of fields.
Definition cf_priv.h:107
CONF_ITEM * parent
Parent.
Definition cf_priv.h:61
fr_token_t name2_quote
The type of quoting around name2.
Definition cf_priv.h:112
bool from_dir
was read from a directory
Definition cf_priv.h:170
void * base
Definition cf_priv.h:118
char const * name2
Second name token. Given foo bar {} would be bar.
Definition cf_priv.h:110
bool allow_locals
allow local variables
Definition cf_priv.h:121
int argc
number of additional arguments
Definition cf_priv.h:114
char const * attr
Attribute name.
Definition cf_priv.h:80
char const * name
Additional qualification of type.
Definition cf_priv.h:159
bool referenced
Was this item referenced in the config?
Definition cf_priv.h:69
fr_rb_tree_t * ident2
Tree to store the second identifier (name2 || name).
Definition cf_priv.h:64
fr_token_t rhs_quote
Value Quoting style T_(DOUBLE|SINGLE|BACK)_QUOTE_STRING or T_BARE_WORD.
Definition cf_priv.h:85
bool parsed
Was this item used during parsing?
Definition cf_priv.h:68
int depth
Definition cf_priv.h:119
char const * value
Attribute value.
Definition cf_priv.h:81
cf_unlang_t unlang
Definition cf_priv.h:120
char const * name1
First name token. Given foo bar {} would be foo.
Definition cf_priv.h:109
void const * data
User data.
Definition cf_priv.h:161
static bool cf_item_has_no_children(CONF_ITEM const *ci)
Check if the CONF_ITEM has no children.
Definition cf_priv.h:200
cf_unlang_t
Definition cf_priv.h:91
@ CF_UNLANG_MODULES
this section is in "modules", allow unlang 2 down
Definition cf_priv.h:96
@ CF_UNLANG_NONE
no unlang
Definition cf_priv.h:92
@ CF_UNLANG_CAN_HAVE_UPDATE
can have "update"
Definition cf_priv.h:100
@ CF_UNLANG_ALLOW
allow unlang in this section
Definition cf_priv.h:93
@ CF_UNLANG_POLICY
this section is a policy, allow unlang 2 down
Definition cf_priv.h:95
@ CF_UNLANG_ASSIGNMENT
only assignments inside of map / update
Definition cf_priv.h:98
@ CF_UNLANG_EDIT
only edit commands
Definition cf_priv.h:97
@ CF_UNLANG_DICTIONARY
only local variable definitions
Definition cf_priv.h:99
@ CF_UNLANG_SERVER
this section is a virtual server, allow unlang 2 down
Definition cf_priv.h:94
fr_dlist_head_t children
The head of the ordered list of children.
Definition cf_priv.h:59
fr_token_t * argv_quote
Definition cf_priv.h:116
fr_token_t op
Operator e.g. =, :=.
Definition cf_priv.h:83
CONF_ITEM item
Common set of fields.
Definition cf_priv.h:78
fr_rb_node_t node
Definition cf_priv.h:166
bool pass2
do expansion in pass2.
Definition cf_priv.h:87
char const * filename
The file the config item was parsed from.
Definition cf_priv.h:71
fr_rb_tree_t * ident1
Tree to store the first identifier (name1 || type || attr).
Definition cf_priv.h:63
struct stat buf
stat about the file
Definition cf_priv.h:169
bool at_reference
this thing was created from an ...
Definition cf_priv.h:122
bool _cf_expand_variables(void)
Definition cf_util.c:837
bool is_talloced
If true we can do extra checks.
Definition cf_priv.h:162
bool _cf_preserve_comments(void)
Definition cf_util.c:817
char const * filename
name of the file
Definition cf_priv.h:167
fr_rb_node_t ident1_node
Entry in the ident1 tree.
Definition cf_priv.h:55
char const * text
Comment text, with the leading # and any surrounding whitespace stripped.
Definition cf_priv.h:148
fr_dlist_t entry
Entry in dlist.
Definition cf_priv.h:58
conf_type
Definition cf_priv.h:39
@ CONF_ITEM_INVALID
Definition cf_priv.h:40
@ CONF_ITEM_PAIR
Definition cf_priv.h:41
@ CONF_ITEM_DATA
Definition cf_priv.h:43
@ CONF_ITEM_SECTION
Definition cf_priv.h:42
@ CONF_ITEM_COMMENT
A # ... line preserved verbatim from the input - only created when the parser is asked to keep commen...
Definition cf_priv.h:44
enum conf_type CONF_ITEM_TYPE
char const ** argv
additional arguments
Definition cf_priv.h:115
CONF_ITEM item
Common set of fields.
Definition cf_priv.h:146
char const * type
C type of data being stored.
Definition cf_priv.h:158
CONF_ITEM item
Common set of fields.
Definition cf_priv.h:156
fr_token_t lhs_quote
Name quoting style T_(DOUBLE|SINGLE|BACK)_QUOTE_STRING or T_BARE_WORD.
Definition cf_priv.h:84
int lineno
The line number the config item began on.
Definition cf_priv.h:70
CONF_ITEM_TYPE type
Whether the config item is a config_pair, conf_section or cf_data.
Definition cf_priv.h:66
A # ... comment line preserved verbatim from the input.
Definition cf_priv.h:145
Internal data that is associated with a configuration section.
Definition cf_priv.h:155
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
static bool fr_dlist_empty(fr_dlist_head_t const *list_head)
Check whether a list has any items.
Definition dlist.h:483
Head of a doubly linked list.
Definition dlist.h:51
Entry in a doubly linked list.
Definition dlist.h:41
The main red black tree structure.
Definition rb.h:71
enum fr_token fr_token_t
int nonnull(2, 5))