src/server/config/serverconfig.h

Sun, 15 Sep 2024 09:47:36 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 15 Sep 2024 09:47:36 +0200
changeset 558
0e79e17c70e2
parent 459
f21b4ff81c01
permissions
-rw-r--r--

improve sessionhandler trace logging

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
459
f21b4ff81c01 log error in get_next_token()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 425
diff changeset
122 const char *filename;
f21b4ff81c01 log error in get_next_token()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 425
diff changeset
123
f21b4ff81c01 log error in get_next_token()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 425
diff changeset
124 int linenum;
f21b4ff81c01 log error in get_next_token()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 425
diff changeset
125 int linepos;
f21b4ff81c01 log error in get_next_token()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 425
diff changeset
126
418
b7dcc9c4f270 use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
127 enum ConfigParserError error;
b7dcc9c4f270 use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
128
425
6440171c257f make config parser delimiters configurable
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 419
diff changeset
129 const char *delim;
6440171c257f make config parser delimiters configurable
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 419
diff changeset
130
418
b7dcc9c4f270 use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
131 /*
b7dcc9c4f270 use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
132 * 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
133 */
b7dcc9c4f270 use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
134 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
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 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
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 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
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 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
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 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
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 * 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
148 */
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 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
150
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 * 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
153 * 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
154 */
90805bb9fbd6 prepare serverconfig parser to be also used for obj.conf and init.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
155 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
156 };
90805bb9fbd6 prepare serverconfig parser to be also used for obj.conf and init.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
157
256
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
158 ServerConfig* serverconfig_load(const char *file);
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
159
418
b7dcc9c4f270 use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
160 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
161
b7dcc9c4f270 use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
162 ConfigNode* serverconfig_parse(ConfigParser2 *parser, cxstring content);
256
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
163
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
164 void serverconfig_free(ServerConfig *cfg);
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
165
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 269
diff changeset
166 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
167
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 269
diff changeset
168 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
169
418
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 * 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
172 * 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
173 *
b7dcc9c4f270 use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
174 * 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
175 */
b7dcc9c4f270 use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
176 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
177
b7dcc9c4f270 use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
178 /*
b7dcc9c4f270 use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
179 * 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
180 */
b7dcc9c4f270 use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
181 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
182
256
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
183
418
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 * 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
186 * 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
187 * matched name in nameindex
b7dcc9c4f270 use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
188 * 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
189 */
b7dcc9c4f270 use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
190 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
191 ConfigNode *directive,
b7dcc9c4f270 use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
192 const char *names[],
b7dcc9c4f270 use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
193 size_t numnames,
b7dcc9c4f270 use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
194 size_t *nameindex);
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 /*
b7dcc9c4f270 use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
197 * 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
198 * 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
199 * otherwise it returns 1
b7dcc9c4f270 use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
200 *
b7dcc9c4f270 use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
201 * 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
202 *
b7dcc9c4f270 use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
203 * 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
204 */
b7dcc9c4f270 use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
205 int serverconfig_check_param_names(ConfigNode *directive, ConfigParam **err);
269
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
206
419
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 * 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
209 */
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 418
diff changeset
210 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
211
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 418
diff changeset
212 /*
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 418
diff changeset
213 * 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
214 */
f1d29785ad2d new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 418
diff changeset
215 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
216
256
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
217 #ifdef __cplusplus
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
218 }
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
219 #endif
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
220
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
221 #endif /* WS_CONFIG_SERVERCONFIG_H */
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
222

mercurial