27 */ |
27 */ |
28 |
28 |
29 #ifndef WS_CONFIG_SERVERCONFIG_H |
29 #ifndef WS_CONFIG_SERVERCONFIG_H |
30 #define WS_CONFIG_SERVERCONFIG_H |
30 #define WS_CONFIG_SERVERCONFIG_H |
31 |
31 |
32 #include <ucx/list.h> |
32 #include <cx/linked_list.h> |
33 #include <ucx/map.h> |
33 #include <cx/hash_map.h> |
34 #include <ucx/mempool.h> |
34 #include <cx/mempool.h> |
|
35 #include <cx/string.h> |
|
36 |
|
37 #include "conf.h" |
35 |
38 |
36 #ifdef __cplusplus |
39 #ifdef __cplusplus |
37 extern "C" { |
40 extern "C" { |
38 #endif |
41 #endif |
39 |
42 |
40 |
43 #define CFG_NODE_ADD(list_begin, list_end, elm) \ |
|
44 cx_linked_list_add((void**)list_begin, (void**)list_end, offsetof(ConfigNode, prev), offsetof(ConfigNode, next), elm) |
|
45 |
41 typedef struct ServerConfig ServerConfig; |
46 typedef struct ServerConfig ServerConfig; |
42 typedef struct ConfigNode ConfigNode; |
47 typedef struct ConfigNode ConfigNode; |
43 typedef struct ConfigArg ConfigArg; |
|
44 typedef struct CFGToken CFGToken; |
48 typedef struct CFGToken CFGToken; |
45 |
49 |
46 typedef enum ConfigNodeType ConfigNodeType; |
50 typedef enum ConfigNodeType ConfigNodeType; |
47 typedef enum CFGTokenType CFGTokenType; |
51 typedef enum CFGTokenType CFGTokenType; |
48 |
52 |
49 struct ServerConfig { |
53 struct ServerConfig { |
50 UcxMempool *mp; |
54 CxMempool *mp; |
51 ConfigNode *root; |
55 ConfigNode *root; |
52 sstr_t tab; |
56 cxmutstr tab; |
53 }; |
57 }; |
54 |
58 |
55 enum ConfigNodeType { |
59 enum ConfigNodeType { |
56 CONFIG_NODE_SPACE = 0, |
60 CONFIG_NODE_SPACE = 0, |
57 CONFIG_NODE_COMMENT, |
61 CONFIG_NODE_COMMENT, |
60 CONFIG_NODE_OPEN_OBJECT, |
64 CONFIG_NODE_OPEN_OBJECT, |
61 CONFIG_NODE_CLOSE_OBJECT |
65 CONFIG_NODE_CLOSE_OBJECT |
62 }; |
66 }; |
63 |
67 |
64 struct ConfigNode { |
68 struct ConfigNode { |
65 sstr_t text_begin; |
69 cxmutstr text_begin; |
66 sstr_t text_end; |
70 cxmutstr text_end; |
67 ConfigNodeType type; |
71 ConfigNodeType type; |
68 |
72 |
69 sstr_t name; |
73 cxmutstr name; |
70 UcxList *args; |
74 ConfigParam *args; |
71 UcxList *children; |
75 ConfigNode *children_begin; |
|
76 ConfigNode *children_end; |
|
77 |
|
78 ConfigNode *prev; |
|
79 ConfigNode *next; |
72 }; |
80 }; |
73 |
81 |
74 struct ConfigArg { |
82 typedef struct ConfigNodeStack ConfigNodeStack; |
75 sstr_t name; |
83 struct ConfigNodeStack { |
76 sstr_t value; |
84 ConfigNode *node; |
|
85 ConfigNodeStack *next; |
77 }; |
86 }; |
78 |
|
79 |
87 |
80 enum CFGTokenType { |
88 enum CFGTokenType { |
81 CFG_NO_TOKEN = 0, |
89 CFG_NO_TOKEN = 0, |
82 CFG_TOKEN_COMMENT, |
90 CFG_TOKEN_COMMENT, |
83 CFG_TOKEN_SPACE, |
91 CFG_TOKEN_SPACE, |
84 CFG_TOKEN_NEWLINE, |
92 CFG_TOKEN_NEWLINE, |
85 CFG_TOKEN |
93 CFG_TOKEN |
86 }; |
94 }; |
87 |
95 |
88 struct CFGToken { |
96 struct CFGToken { |
89 scstr_t content; |
97 cxstring content; |
90 CFGTokenType type; |
98 CFGTokenType type; |
91 }; |
99 }; |
92 |
100 |
93 ServerConfig* serverconfig_load(const char *file); |
101 ServerConfig* serverconfig_load(const char *file); |
94 |
102 |
95 ServerConfig* serverconfig_parse(scstr_t content); |
103 ServerConfig* serverconfig_parse(cxstring content); |
96 |
104 |
97 void serverconfig_free(ServerConfig *cfg); |
105 void serverconfig_free(ServerConfig *cfg); |
98 |
106 |
99 ConfigNode* serverconfig_get_node(ConfigNode *parent, ConfigNodeType type, scstr_t name); |
107 ConfigNode* serverconfig_get_node(ConfigNode *parent, ConfigNodeType type, cxstring name); |
100 |
108 |
101 UcxList* serverconfig_get_node_list(ConfigNode *parent, ConfigNodeType type, scstr_t name); |
109 CxList* serverconfig_get_node_list(ConfigNode *parent, ConfigNodeType type, cxstring name); |
102 |
110 |
103 scstr_t serverconfig_directive_value(ConfigNode *obj, scstr_t name); |
111 cxstring serverconfig_directive_value(ConfigNode *obj, cxstring name); |
104 |
112 |
105 sstr_t serverconfig_arg_name_value(UcxAllocator *a, scstr_t str, scstr_t *name); |
113 cxmutstr serverconfig_arg_name_value(CxAllocator *a, cxstring str, cxstring *name); |
106 |
114 |
107 #ifdef __cplusplus |
115 #ifdef __cplusplus |
108 } |
116 } |
109 #endif |
117 #endif |
110 |
118 |