101 CFGTokenType type; |
101 CFGTokenType type; |
102 }; |
102 }; |
103 |
103 |
104 enum ConfigParserError { |
104 enum ConfigParserError { |
105 CONFIG_PARSER_OOM = 0, |
105 CONFIG_PARSER_OOM = 0, |
|
106 CONFIG_PARSER_IO_ERROR, |
106 CONFIG_PARSER_SYNTAX_ERROR |
107 CONFIG_PARSER_SYNTAX_ERROR |
107 }; |
108 }; |
108 |
109 |
109 /* |
110 /* |
110 * CfgValidateNodeFunc functions are called by the parser to validate |
111 * CfgValidateNodeFunc functions are called by the parser to validate |
116 typedef int(*CfgValidateNodeFunc)(ConfigParser2 *parser, ConfigNode *node); |
117 typedef int(*CfgValidateNodeFunc)(ConfigParser2 *parser, ConfigNode *node); |
117 |
118 |
118 struct ConfigParser2 { |
119 struct ConfigParser2 { |
119 CxMempool *mp; |
120 CxMempool *mp; |
120 |
121 |
121 int error; |
122 enum ConfigParserError error; |
|
123 |
|
124 /* |
|
125 * errno in case of IO errors (parser.error == CONFIG_PARSER_IO_ERROR) |
|
126 */ |
|
127 int io_errno; |
122 |
128 |
123 /* |
129 /* |
124 * called when an object is started |
130 * called when an object is started |
125 */ |
131 */ |
126 CfgValidateNodeFunc validateObjBegin; |
132 CfgValidateNodeFunc validateObjBegin; |
142 bool allow_hierarchy; |
148 bool allow_hierarchy; |
143 }; |
149 }; |
144 |
150 |
145 ServerConfig* serverconfig_load(const char *file); |
151 ServerConfig* serverconfig_load(const char *file); |
146 |
152 |
147 ServerConfig* serverconfig_parse(ConfigParser2 *parser, cxstring content); |
153 ConfigNode* serverconfig_load_file(ConfigParser2 *parser, const char *file); |
|
154 |
|
155 ConfigNode* serverconfig_parse(ConfigParser2 *parser, cxstring content); |
148 |
156 |
149 void serverconfig_free(ServerConfig *cfg); |
157 void serverconfig_free(ServerConfig *cfg); |
150 |
158 |
151 ConfigNode* serverconfig_get_node(ConfigNode *parent, ConfigNodeType type, cxstring name); |
159 ConfigNode* serverconfig_get_node(ConfigNode *parent, ConfigNodeType type, cxstring name); |
152 |
160 |
153 CxList* serverconfig_get_node_list(ConfigNode *parent, ConfigNodeType type, cxstring name); |
161 CxList* serverconfig_get_node_list(ConfigNode *parent, ConfigNodeType type, cxstring name); |
154 |
162 |
155 cxstring serverconfig_directive_value(ConfigNode *obj, cxstring name); |
163 /* |
156 |
164 * Searches in the specified object for the directive with the name |
157 cxmutstr serverconfig_arg_name_value(CxAllocator *a, cxstring str, cxstring *name); |
165 * directive_name and returns the value |
|
166 * |
|
167 * Directives only have a value, if they have one argument |
|
168 */ |
|
169 cxstring serverconfig_object_directive_value(ConfigNode *obj, cxstring directive_name); |
|
170 |
|
171 /* |
|
172 * Returns the directive parameter value that has the specified name |
|
173 */ |
|
174 cxstring serverconfig_directive_get_arg(ConfigNode *directive, cxstring param_name); |
|
175 |
|
176 |
|
177 /* |
|
178 * Checks if the directive name matches any string in the names array. |
|
179 * If it matches a name, the function returns 0 and stores the index of the |
|
180 * matched name in nameindex |
|
181 * If it doesn't match a name, the function returns 1 |
|
182 */ |
|
183 int serverconfig_validate_directive_name( |
|
184 ConfigNode *directive, |
|
185 const char *names[], |
|
186 size_t numnames, |
|
187 size_t *nameindex); |
|
188 |
|
189 /* |
|
190 * Checks if all directive parameters have a name |
|
191 * If every parameter has a name, the function returns 0 |
|
192 * otherwise it returns 1 |
|
193 * |
|
194 * If a parameter doesn't contain a name, err is set to this parameter |
|
195 * |
|
196 * config file syntax: paramname="value" |
|
197 */ |
|
198 int serverconfig_check_param_names(ConfigNode *directive, ConfigParam **err); |
158 |
199 |
159 #ifdef __cplusplus |
200 #ifdef __cplusplus |
160 } |
201 } |
161 #endif |
202 #endif |
162 |
203 |