src/server/config/serverconfig.h

changeset 417
90805bb9fbd6
parent 415
d938228c382e
child 418
b7dcc9c4f270
equal deleted inserted replaced
416:e2093ca0ef90 417:90805bb9fbd6
32 #include <cx/linked_list.h> 32 #include <cx/linked_list.h>
33 #include <cx/hash_map.h> 33 #include <cx/hash_map.h>
34 #include <cx/mempool.h> 34 #include <cx/mempool.h>
35 #include <cx/string.h> 35 #include <cx/string.h>
36 36
37 #include <stdbool.h>
38
37 #include "conf.h" 39 #include "conf.h"
38 40
39 #ifdef __cplusplus 41 #ifdef __cplusplus
40 extern "C" { 42 extern "C" {
41 #endif 43 #endif
44 cx_linked_list_add((void**)list_begin, (void**)list_end, offsetof(ConfigNode, prev), offsetof(ConfigNode, next), elm) 46 cx_linked_list_add((void**)list_begin, (void**)list_end, offsetof(ConfigNode, prev), offsetof(ConfigNode, next), elm)
45 47
46 typedef struct ServerConfig ServerConfig; 48 typedef struct ServerConfig ServerConfig;
47 typedef struct ConfigNode ConfigNode; 49 typedef struct ConfigNode ConfigNode;
48 typedef struct CFGToken CFGToken; 50 typedef struct CFGToken CFGToken;
51 typedef struct ConfigParser2 ConfigParser2; // TODO: rename to ConfigParser after old ConfigParser is removed
49 52
50 typedef enum ConfigNodeType ConfigNodeType; 53 typedef enum ConfigNodeType ConfigNodeType;
51 typedef enum CFGTokenType CFGTokenType; 54 typedef enum CFGTokenType CFGTokenType;
52 55
53 struct ServerConfig { 56 struct ServerConfig {
96 struct CFGToken { 99 struct CFGToken {
97 cxstring content; 100 cxstring content;
98 CFGTokenType type; 101 CFGTokenType type;
99 }; 102 };
100 103
104 enum ConfigParserError {
105 CONFIG_PARSER_OOM = 0,
106 CONFIG_PARSER_SYNTAX_ERROR
107 };
108
109 /*
110 * CfgValidateNodeFunc functions are called by the parser to validate
111 * objects and directives.
112 *
113 * The function must return 0 if the validation was successful. If the
114 * functions returns a value != 0, the parser aborts.
115 */
116 typedef int(*CfgValidateNodeFunc)(ConfigParser2 *parser, ConfigNode *node);
117
118 struct ConfigParser2 {
119 CxMempool *mp;
120
121 int error;
122
123 /*
124 * called when an object is started
125 */
126 CfgValidateNodeFunc validateObjBegin;
127
128 /*
129 * called when an object is closed
130 */
131 CfgValidateNodeFunc validateObjEnd;
132
133 /*
134 * called before a directive is added
135 */
136 CfgValidateNodeFunc validateDirective;
137
138 /*
139 * true: store result in a tree
140 * false: flat list of directives, don't allow '{' and '}'
141 */
142 bool allow_hierarchy;
143 };
144
101 ServerConfig* serverconfig_load(const char *file); 145 ServerConfig* serverconfig_load(const char *file);
102 146
103 ServerConfig* serverconfig_parse(cxstring content); 147 ServerConfig* serverconfig_parse(ConfigParser2 *parser, cxstring content);
104 148
105 void serverconfig_free(ServerConfig *cfg); 149 void serverconfig_free(ServerConfig *cfg);
106 150
107 ConfigNode* serverconfig_get_node(ConfigNode *parent, ConfigNodeType type, cxstring name); 151 ConfigNode* serverconfig_get_node(ConfigNode *parent, ConfigNodeType type, cxstring name);
108 152

mercurial