The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
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: 02d0f3d44876c616b253005ed86af8e1e346fa73 $
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  */
26 RCSIDH(cf_priv_h, "$Id: 02d0f3d44876c616b253005ed86af8e1e346fa73 $")
27 
28 #ifdef __cplusplus
29 extern "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 
39 typedef enum conf_type {
45 
46 /** Common header for all CONF_* types
47  *
48  */
49 struct cf_item {
50  fr_rb_node_t ident1_node; //!< Entry in the ident1 tree.
51  fr_rb_node_t ident2_node; //!< Entry in the ident2 tree.
52 
53  fr_dlist_t entry; //!< Entry in dlist
54  fr_dlist_head_t children; //!< The head of the ordered list of children.
55 
56  CONF_ITEM *parent; //!< Parent
57 
58  fr_rb_tree_t *ident1; //!< Tree to store the first identifier (name1 || type || attr).
59  fr_rb_tree_t *ident2; //!< Tree to store the second identifier (name2 || name).
60 
61  CONF_ITEM_TYPE type; //!< Whether the config item is a config_pair, conf_section or cf_data.
62 
63  int lineno; //!< The line number the config item began on.
64  char const *filename; //!< The file the config item was parsed from.
65 };
66 
67 /** Configuration AVP similar to a fr_pair_t
68  *
69  */
70 struct cf_pair {
71  CONF_ITEM item; //!< Common set of fields.
72 
73  char const *attr; //!< Attribute name
74  char const *value; //!< Attribute value
75 
76  fr_token_t op; //!< Operator e.g. =, :=
77  fr_token_t lhs_quote; //!< Name quoting style T_(DOUBLE|SINGLE|BACK)_QUOTE_STRING or T_BARE_WORD.
78  fr_token_t rhs_quote; //!< Value Quoting style T_(DOUBLE|SINGLE|BACK)_QUOTE_STRING or T_BARE_WORD.
79 
80  bool pass2; //!< do expansion in pass2.
81  bool parsed; //!< Was this item used during parsing?
82  bool printed; //!< Was this item printed already in debug mode?
83  bool referenced; //!< Was this item referenced in the config?
84 };
85 
86 /** A section grouping multiple #CONF_PAIR
87  *
88  */
89 struct cf_section {
90  CONF_ITEM item; //!< Common set of fields.
91 
92  char const *name1; //!< First name token. Given ``foo bar {}`` would be ``foo``.
93  char const *name2; //!< Second name token. Given ``foo bar {}`` would be ``bar``.
94 
95  fr_token_t name2_quote; //!< The type of quoting around name2.
96 
97  int argc; //!< number of additional arguments
98  char const **argv; //!< additional arguments
100 
101  void *base;
102  int depth;
103  int allow_unlang; //!< depth at which we allow unlang
104  bool attr; //!< is this thing an attribute definition?
105  bool allow_locals; //!< allow local variables
106 
107  CONF_SECTION *template;
108 };
109 
110 /** Internal data that is associated with a configuration section
111  *
112  */
113 struct cf_data {
114  CONF_ITEM item; //!< Common set of fields.
115 
116  char const *type; //!< C type of data being stored.
117  char const *name; //!< Additional qualification of type.
118 
119  void const *data; //!< User data.
120  bool is_talloced; //!< If true we can do extra checks.
121  bool free; //!< If true, free data with talloc if parent node is freed.
122 };
123 
124 typedef struct {
126  char const *filename; //!< name of the file
127  CONF_SECTION *cs; //!< CONF_SECTION associated with the file
128  struct stat buf; //!< stat about the file
129  bool from_dir; //!< was read from a directory
130 } cf_file_t;
131 
132 /** Iterate over the contents of a list
133  *
134  * @param[in] _ci to iterate over.
135  * @param[in] _iter Name of iteration variable.
136  * Will be declared in the scope of the loop.
137  */
138 #define cf_item_foreach(_ci, _iter) \
139  for (CONF_ITEM *_iter = fr_dlist_head(&(_ci)->children); _iter; _iter = fr_dlist_next(&(_ci)->children, _iter))
140 
141 /** Iterate over the contents of a list
142  *
143  * @param[in] _ci to iterate over.
144  * @param[in] _iter Name of iteration variable.
145  * Will be declared in the scope of the loop.
146  * @param[in] _prev previous pointer
147  */
148 #define cf_item_foreach_prev(_ci, _iter, _prev) \
149  for (CONF_ITEM *_iter = fr_dlist_next(&(_ci)->children, _prev); _iter; _iter = fr_dlist_next(&(_ci)->children, _iter))
150 
151 /** Check if the CONF_ITEM has no children.
152  *
153  * Which is the common use-case
154  *
155  * @param[in] ci to check
156  * @return true/false
157  */
158 static inline CC_HINT(nonnull) bool cf_item_has_no_children(CONF_ITEM const *ci)
159 {
160  return fr_dlist_empty(&ci->children);
161 }
162 
163 #ifdef __cplusplus
164 }
165 #endif
#define RCSIDH(h, id)
Definition: build.h:445
fr_rb_node_t ident2_node
Entry in the ident2 tree.
Definition: cf_priv.h:51
bool printed
Was this item printed already in debug mode?
Definition: cf_priv.h:82
CONF_ITEM item
Common set of fields.
Definition: cf_priv.h:90
CONF_ITEM * parent
Parent.
Definition: cf_priv.h:56
fr_token_t name2_quote
The type of quoting around name2.
Definition: cf_priv.h:95
bool from_dir
was read from a directory
Definition: cf_priv.h:129
void * base
Definition: cf_priv.h:101
char const * name2
Second name token. Given foo bar {} would be bar.
Definition: cf_priv.h:93
bool allow_locals
allow local variables
Definition: cf_priv.h:105
int argc
number of additional arguments
Definition: cf_priv.h:97
char const * attr
Attribute name.
Definition: cf_priv.h:73
char const * name
Additional qualification of type.
Definition: cf_priv.h:117
fr_rb_tree_t * ident2
Tree to store the second identifier (name2 || name).
Definition: cf_priv.h:59
fr_token_t rhs_quote
Value Quoting style T_(DOUBLE|SINGLE|BACK)_QUOTE_STRING or T_BARE_WORD.
Definition: cf_priv.h:78
int depth
Definition: cf_priv.h:102
char const * value
Attribute value.
Definition: cf_priv.h:74
char const * name1
First name token. Given foo bar {} would be foo.
Definition: cf_priv.h:92
void const * data
User data.
Definition: cf_priv.h:119
static bool cf_item_has_no_children(CONF_ITEM const *ci)
Check if the CONF_ITEM has no children.
Definition: cf_priv.h:158
int allow_unlang
depth at which we allow unlang
Definition: cf_priv.h:103
fr_dlist_head_t children
The head of the ordered list of children.
Definition: cf_priv.h:54
fr_token_t * argv_quote
Definition: cf_priv.h:99
fr_token_t op
Operator e.g. =, :=.
Definition: cf_priv.h:76
CONF_ITEM item
Common set of fields.
Definition: cf_priv.h:71
fr_rb_node_t node
Definition: cf_priv.h:125
bool pass2
do expansion in pass2.
Definition: cf_priv.h:80
char const * filename
The file the config item was parsed from.
Definition: cf_priv.h:64
fr_rb_tree_t * ident1
Tree to store the first identifier (name1 || type || attr).
Definition: cf_priv.h:58
bool is_talloced
If true we can do extra checks.
Definition: cf_priv.h:120
char const * filename
name of the file
Definition: cf_priv.h:126
fr_rb_node_t ident1_node
Entry in the ident1 tree.
Definition: cf_priv.h:50
fr_dlist_t entry
Entry in dlist.
Definition: cf_priv.h:53
bool attr
is this thing an attribute definition?
Definition: cf_priv.h:104
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
bool referenced
Was this item referenced in the config?
Definition: cf_priv.h:83
enum conf_type CONF_ITEM_TYPE
char const ** argv
additional arguments
Definition: cf_priv.h:98
char const * type
C type of data being stored.
Definition: cf_priv.h:116
CONF_ITEM item
Common set of fields.
Definition: cf_priv.h:114
bool parsed
Was this item used during parsing?
Definition: cf_priv.h:81
fr_token_t lhs_quote
Name quoting style T_(DOUBLE|SINGLE|BACK)_QUOTE_STRING or T_BARE_WORD.
Definition: cf_priv.h:77
bool free
If true, free data with talloc if parent node is freed.
Definition: cf_priv.h:121
int lineno
The line number the config item began on.
Definition: cf_priv.h:63
CONF_ITEM_TYPE type
Whether the config item is a config_pair, conf_section or cf_data.
Definition: cf_priv.h:61
Internal data that is associated with a configuration section.
Definition: cf_priv.h:113
Common header for all CONF_* types.
Definition: cf_priv.h:49
Configuration AVP similar to a fr_pair_t.
Definition: cf_priv.h:70
A section grouping multiple CONF_PAIR.
Definition: cf_priv.h:89
static bool fr_dlist_empty(fr_dlist_head_t const *list_head)
Check whether a list has any items.
Definition: dlist.h:501
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:73
enum fr_token fr_token_t
int nonnull(2, 5))