Sat, 26 Nov 2022 17:07:08 +0100
refactore http listener creation
256
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1 | /* |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
3 | * |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
4 | * Copyright 2020 Olaf Wintermann. All rights reserved. |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
5 | * |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
8 | * |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
11 | * |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
15 | * |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
27 | */ |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
28 | |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
29 | #ifndef WS_CONFIG_SERVERCONFIG_H |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
30 | #define WS_CONFIG_SERVERCONFIG_H |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
31 | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
269
diff
changeset
|
32 | #include <cx/linked_list.h> |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
269
diff
changeset
|
33 | #include <cx/hash_map.h> |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
269
diff
changeset
|
34 | #include <cx/mempool.h> |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
269
diff
changeset
|
35 | #include <cx/string.h> |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
269
diff
changeset
|
36 | |
417
90805bb9fbd6
prepare serverconfig parser to be also used for obj.conf and init.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
37 | #include <stdbool.h> |
90805bb9fbd6
prepare serverconfig parser to be also used for obj.conf and init.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
38 | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
269
diff
changeset
|
39 | #include "conf.h" |
256
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
40 | |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
41 | #ifdef __cplusplus |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
42 | extern "C" { |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
43 | #endif |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
44 | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
269
diff
changeset
|
45 | #define CFG_NODE_ADD(list_begin, list_end, elm) \ |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
269
diff
changeset
|
46 | cx_linked_list_add((void**)list_begin, (void**)list_end, offsetof(ConfigNode, prev), offsetof(ConfigNode, next), elm) |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
269
diff
changeset
|
47 | |
256
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
48 | typedef struct ServerConfig ServerConfig; |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
49 | typedef struct ConfigNode ConfigNode; |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
50 | typedef struct CFGToken CFGToken; |
417
90805bb9fbd6
prepare serverconfig parser to be also used for obj.conf and init.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
51 | typedef struct ConfigParser2 ConfigParser2; // TODO: rename to ConfigParser after old ConfigParser is removed |
256
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
52 | |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
53 | typedef enum ConfigNodeType ConfigNodeType; |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
54 | typedef enum CFGTokenType CFGTokenType; |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
55 | |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
56 | struct ServerConfig { |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
269
diff
changeset
|
57 | CxMempool *mp; |
256
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
58 | ConfigNode *root; |
418
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
59 | cxstring tab; |
256
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
60 | }; |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
61 | |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
62 | enum ConfigNodeType { |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
63 | CONFIG_NODE_SPACE = 0, |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
64 | CONFIG_NODE_COMMENT, |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
65 | CONFIG_NODE_OBJECT, |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
66 | CONFIG_NODE_DIRECTIVE, |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
67 | CONFIG_NODE_OPEN_OBJECT, |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
68 | CONFIG_NODE_CLOSE_OBJECT |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
69 | }; |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
70 | |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
71 | struct ConfigNode { |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
269
diff
changeset
|
72 | cxmutstr text_begin; |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
269
diff
changeset
|
73 | cxmutstr text_end; |
256
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
74 | ConfigNodeType type; |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
75 | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
269
diff
changeset
|
76 | cxmutstr name; |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
269
diff
changeset
|
77 | ConfigParam *args; |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
269
diff
changeset
|
78 | ConfigNode *children_begin; |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
269
diff
changeset
|
79 | ConfigNode *children_end; |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
269
diff
changeset
|
80 | |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
269
diff
changeset
|
81 | ConfigNode *prev; |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
269
diff
changeset
|
82 | ConfigNode *next; |
256
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
83 | }; |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
84 | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
269
diff
changeset
|
85 | typedef struct ConfigNodeStack ConfigNodeStack; |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
269
diff
changeset
|
86 | struct ConfigNodeStack { |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
269
diff
changeset
|
87 | ConfigNode *node; |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
269
diff
changeset
|
88 | ConfigNodeStack *next; |
256
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
89 | }; |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
90 | |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
91 | enum CFGTokenType { |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
92 | CFG_NO_TOKEN = 0, |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
93 | CFG_TOKEN_COMMENT, |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
94 | CFG_TOKEN_SPACE, |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
95 | CFG_TOKEN_NEWLINE, |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
96 | CFG_TOKEN |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
97 | }; |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
98 | |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
99 | struct CFGToken { |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
269
diff
changeset
|
100 | cxstring content; |
256
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
101 | CFGTokenType type; |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
102 | }; |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
103 | |
417
90805bb9fbd6
prepare serverconfig parser to be also used for obj.conf and init.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
104 | enum ConfigParserError { |
90805bb9fbd6
prepare serverconfig parser to be also used for obj.conf and init.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
105 | CONFIG_PARSER_OOM = 0, |
418
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
106 | CONFIG_PARSER_IO_ERROR, |
417
90805bb9fbd6
prepare serverconfig parser to be also used for obj.conf and init.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
107 | CONFIG_PARSER_SYNTAX_ERROR |
90805bb9fbd6
prepare serverconfig parser to be also used for obj.conf and init.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
108 | }; |
90805bb9fbd6
prepare serverconfig parser to be also used for obj.conf and init.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
109 | |
90805bb9fbd6
prepare serverconfig parser to be also used for obj.conf and init.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
110 | /* |
90805bb9fbd6
prepare serverconfig parser to be also used for obj.conf and init.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
111 | * CfgValidateNodeFunc functions are called by the parser to validate |
90805bb9fbd6
prepare serverconfig parser to be also used for obj.conf and init.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
112 | * objects and directives. |
90805bb9fbd6
prepare serverconfig parser to be also used for obj.conf and init.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
113 | * |
90805bb9fbd6
prepare serverconfig parser to be also used for obj.conf and init.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
114 | * The function must return 0 if the validation was successful. If the |
90805bb9fbd6
prepare serverconfig parser to be also used for obj.conf and init.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
115 | * functions returns a value != 0, the parser aborts. |
90805bb9fbd6
prepare serverconfig parser to be also used for obj.conf and init.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
116 | */ |
90805bb9fbd6
prepare serverconfig parser to be also used for obj.conf and init.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
117 | typedef int(*CfgValidateNodeFunc)(ConfigParser2 *parser, ConfigNode *node); |
90805bb9fbd6
prepare serverconfig parser to be also used for obj.conf and init.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
118 | |
90805bb9fbd6
prepare serverconfig parser to be also used for obj.conf and init.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
119 | struct ConfigParser2 { |
90805bb9fbd6
prepare serverconfig parser to be also used for obj.conf and init.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
120 | CxMempool *mp; |
90805bb9fbd6
prepare serverconfig parser to be also used for obj.conf and init.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
121 | |
418
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
122 | enum ConfigParserError error; |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
123 | |
425
6440171c257f
make config parser delimiters configurable
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
124 | const char *delim; |
6440171c257f
make config parser delimiters configurable
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
125 | |
418
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
126 | /* |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
127 | * errno in case of IO errors (parser.error == CONFIG_PARSER_IO_ERROR) |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
128 | */ |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
129 | int io_errno; |
417
90805bb9fbd6
prepare serverconfig parser to be also used for obj.conf and init.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
130 | |
90805bb9fbd6
prepare serverconfig parser to be also used for obj.conf and init.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
131 | /* |
90805bb9fbd6
prepare serverconfig parser to be also used for obj.conf and init.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
132 | * called when an object is started |
90805bb9fbd6
prepare serverconfig parser to be also used for obj.conf and init.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
133 | */ |
90805bb9fbd6
prepare serverconfig parser to be also used for obj.conf and init.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
134 | CfgValidateNodeFunc validateObjBegin; |
90805bb9fbd6
prepare serverconfig parser to be also used for obj.conf and init.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
135 | |
90805bb9fbd6
prepare serverconfig parser to be also used for obj.conf and init.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
136 | /* |
90805bb9fbd6
prepare serverconfig parser to be also used for obj.conf and init.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
137 | * called when an object is closed |
90805bb9fbd6
prepare serverconfig parser to be also used for obj.conf and init.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
138 | */ |
90805bb9fbd6
prepare serverconfig parser to be also used for obj.conf and init.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
139 | CfgValidateNodeFunc validateObjEnd; |
90805bb9fbd6
prepare serverconfig parser to be also used for obj.conf and init.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
140 | |
90805bb9fbd6
prepare serverconfig parser to be also used for obj.conf and init.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
141 | /* |
90805bb9fbd6
prepare serverconfig parser to be also used for obj.conf and init.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
142 | * called before a directive is added |
90805bb9fbd6
prepare serverconfig parser to be also used for obj.conf and init.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
143 | */ |
90805bb9fbd6
prepare serverconfig parser to be also used for obj.conf and init.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
144 | CfgValidateNodeFunc validateDirective; |
90805bb9fbd6
prepare serverconfig parser to be also used for obj.conf and init.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
145 | |
90805bb9fbd6
prepare serverconfig parser to be also used for obj.conf and init.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
146 | /* |
90805bb9fbd6
prepare serverconfig parser to be also used for obj.conf and init.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
147 | * true: store result in a tree |
90805bb9fbd6
prepare serverconfig parser to be also used for obj.conf and init.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
148 | * false: flat list of directives, don't allow '{' and '}' |
90805bb9fbd6
prepare serverconfig parser to be also used for obj.conf and init.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
149 | */ |
90805bb9fbd6
prepare serverconfig parser to be also used for obj.conf and init.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
150 | bool allow_hierarchy; |
90805bb9fbd6
prepare serverconfig parser to be also used for obj.conf and init.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
151 | }; |
90805bb9fbd6
prepare serverconfig parser to be also used for obj.conf and init.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
152 | |
256
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
153 | ServerConfig* serverconfig_load(const char *file); |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
154 | |
418
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
155 | ConfigNode* serverconfig_load_file(ConfigParser2 *parser, const char *file); |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
156 | |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
157 | ConfigNode* serverconfig_parse(ConfigParser2 *parser, cxstring content); |
256
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
158 | |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
159 | void serverconfig_free(ServerConfig *cfg); |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
160 | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
269
diff
changeset
|
161 | ConfigNode* serverconfig_get_node(ConfigNode *parent, ConfigNodeType type, cxstring name); |
256
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
162 | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
269
diff
changeset
|
163 | CxList* serverconfig_get_node_list(ConfigNode *parent, ConfigNodeType type, cxstring name); |
256
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
164 | |
418
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
165 | /* |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
166 | * Searches in the specified object for the directive with the name |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
167 | * directive_name and returns the value |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
168 | * |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
169 | * Directives only have a value, if they have one argument |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
170 | */ |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
171 | cxstring serverconfig_object_directive_value(ConfigNode *obj, cxstring directive_name); |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
172 | |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
173 | /* |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
174 | * Returns the directive parameter value that has the specified name |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
175 | */ |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
176 | cxstring serverconfig_directive_get_arg(ConfigNode *directive, cxstring param_name); |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
177 | |
256
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
178 | |
418
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
179 | /* |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
180 | * Checks if the directive name matches any string in the names array. |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
181 | * If it matches a name, the function returns 0 and stores the index of the |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
182 | * matched name in nameindex |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
183 | * If it doesn't match a name, the function returns 1 |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
184 | */ |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
185 | int serverconfig_validate_directive_name( |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
186 | ConfigNode *directive, |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
187 | const char *names[], |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
188 | size_t numnames, |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
189 | size_t *nameindex); |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
190 | |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
191 | /* |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
192 | * Checks if all directive parameters have a name |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
193 | * If every parameter has a name, the function returns 0 |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
194 | * otherwise it returns 1 |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
195 | * |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
196 | * If a parameter doesn't contain a name, err is set to this parameter |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
197 | * |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
198 | * config file syntax: paramname="value" |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
199 | */ |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
200 | int serverconfig_check_param_names(ConfigNode *directive, ConfigParam **err); |
269
3dfbd0b91950
add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
201 | |
419
f1d29785ad2d
new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
418
diff
changeset
|
202 | /* |
f1d29785ad2d
new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
418
diff
changeset
|
203 | * Returns the previous node that is a directive or object |
f1d29785ad2d
new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
418
diff
changeset
|
204 | */ |
f1d29785ad2d
new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
418
diff
changeset
|
205 | ConfigNode* serverconfig_previous_dir_or_obj(ConfigNode *node); |
f1d29785ad2d
new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
418
diff
changeset
|
206 | |
f1d29785ad2d
new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
418
diff
changeset
|
207 | /* |
f1d29785ad2d
new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
418
diff
changeset
|
208 | * Count the direct children that have the specified type |
f1d29785ad2d
new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
418
diff
changeset
|
209 | */ |
f1d29785ad2d
new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
418
diff
changeset
|
210 | size_t serverconfig_children_count(ConfigNode *node, ConfigNodeType type); |
f1d29785ad2d
new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
418
diff
changeset
|
211 | |
256
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
212 | #ifdef __cplusplus |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
213 | } |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
214 | #endif |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
215 | |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
216 | #endif /* WS_CONFIG_SERVERCONFIG_H */ |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
217 |