Sat, 03 Dec 2022 16:31:08 +0100
use separate buffer for chunked transfer encoding, not inbuf
1 | 1 | /* |
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. | |
3 | * | |
44
3da1f7b6847f
added some error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
4 | * Copyright 2013 Olaf Wintermann. All rights reserved. |
1 | 5 | * |
6 | * Redistribution and use in source and binary forms, with or without | |
7 | * modification, are permitted provided that the following conditions are met: | |
8 | * | |
9 | * 1. Redistributions of source code must retain the above copyright | |
10 | * notice, this list of conditions and the following disclaimer. | |
11 | * | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | |
15 | * | |
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | |
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
26 | * POSSIBILITY OF SUCH DAMAGE. | |
27 | */ | |
28 | ||
14
b8bf95b39952
New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
29 | #include "../public/nsapi.h" |
1 | 30 | |
31 | #include <stdio.h> | |
32 | #include <stdlib.h> | |
33 | ||
5
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
34 | #include <fcntl.h> |
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
35 | #include <sys/types.h> |
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
36 | #include <sys/file.h> |
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
37 | #include <sys/stat.h> |
162
b169992137a8
improves cgi error handling and allows requests with empty headers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
161
diff
changeset
|
38 | #include <sys/mman.h> |
5
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
39 | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
40 | #include <cx/string.h> |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
41 | #include <cx/utils.h> |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
42 | #include <cx/hash_map.h> |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
43 | #include <cx/linked_list.h> |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
44 | #include <cx/compare.h> |
5
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
45 | |
1 | 46 | #include "httplistener.h" |
18
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
47 | #include "config.h" |
5
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
48 | #include "func.h" |
28 | 49 | #include "log.h" |
30
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
50 | #include "event.h" |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
51 | #include "threadpools.h" |
38
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
52 | #include "ldap_auth.h" |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
53 | #include "configmanager.h" |
269
3dfbd0b91950
add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
260
diff
changeset
|
54 | #include "resourcepool.h" |
1 | 55 | |
3
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
56 | #include "vserver.h" |
14
b8bf95b39952
New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
57 | #include "../util/pblock.h" |
30
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
58 | #include "../util/util.h" |
41
bb7a1f5a8b48
added Linux support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
59 | #include "../util/atomic.h" |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
60 | #include "cx/buffer.h" |
3
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
61 | |
255
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
62 | pool_handle_t *init_pool; |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
63 | |
373
f78a585e1a2f
add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
368
diff
changeset
|
64 | char* cfg_config_file_path(const char *file) { |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
65 | cxstring base = CX_STR("config/"); |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
66 | cxmutstr path = cx_strcat(2, base, cx_str(file)); |
373
f78a585e1a2f
add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
368
diff
changeset
|
67 | return path.ptr; |
f78a585e1a2f
add parser for extended postgresql webdav config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
368
diff
changeset
|
68 | } |
18
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
69 | |
426
6a2e7a464991
run Init directives after setuid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
423
diff
changeset
|
70 | InitConfig* load_init_conf(const char *file) { |
115
51d9a15eac98
improves logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
71 | log_ereport(LOG_VERBOSE, "load_init_conf"); |
13
1fdbf4170ef4
Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
72 | |
418
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
73 | InitConfig *cfg = initconfig_load(file); |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
74 | if(cfg == NULL) { |
115
51d9a15eac98
improves logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
75 | log_ereport(LOG_FAILURE, "Cannot load init.conf"); |
426
6a2e7a464991
run Init directives after setuid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
423
diff
changeset
|
76 | return NULL;; |
13
1fdbf4170ef4
Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
77 | } |
426
6a2e7a464991
run Init directives after setuid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
423
diff
changeset
|
78 | |
6a2e7a464991
run Init directives after setuid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
423
diff
changeset
|
79 | return cfg; |
6a2e7a464991
run Init directives after setuid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
423
diff
changeset
|
80 | } |
6a2e7a464991
run Init directives after setuid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
423
diff
changeset
|
81 | |
6a2e7a464991
run Init directives after setuid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
423
diff
changeset
|
82 | int apply_init_conf(InitConfig *cfg) { |
418
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
83 | init_pool = pool_create(); |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
84 | |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
85 | ConfigNode *dir = cfg->root->children_begin; |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
86 | while(dir) { |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
87 | if(dir->type != CONFIG_NODE_DIRECTIVE) { |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
88 | // dir is just space/comment |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
89 | dir = dir->next; |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
90 | continue; |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
91 | } |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
92 | |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
93 | // create NSAPI directive |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
94 | |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
95 | // The parser checks the directive name and makes sure it is "Init" |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
96 | // if more than one init directive type is introduced, the parser |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
97 | // must be extended and also dir->name must be checked here |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
98 | |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
99 | directive *d = pool_malloc(init_pool, sizeof(directive)); |
255
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
100 | d->param = pblock_create_pool(init_pool, 8); |
418
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
101 | |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
102 | ConfigParam *param = dir->args; |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
103 | while(param != NULL) { |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
104 | pblock_nvlinsert( |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
105 | param->name.ptr, |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
106 | param->name.length, |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
107 | param->value.ptr, |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
108 | param->value.length, |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
109 | d->param); |
20
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
110 | |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
111 | param = param->next; |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
112 | } |
418
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
113 | |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
114 | // get function |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
115 | // the parser makes sure that an "fn" parameter always exists |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
116 | char *func_name = pblock_findval("fn", d->param); |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
117 | d->func = get_function(func_name); |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
118 | if(d->func == NULL) { |
60
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
119 | log_ereport( |
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
120 | LOG_MISCONFIG, |
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
121 | "Cannot find Init function %s", |
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
122 | func_name); |
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
123 | return 1; |
13
1fdbf4170ef4
Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
124 | } |
418
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
125 | |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
126 | // execute init directive |
60
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
127 | int ret = d->func->func(d->param, NULL, NULL); |
61
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
128 | if(ret != REQ_PROCEED && ret != REQ_NOACTION) { |
60
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
129 | log_ereport( |
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
130 | LOG_FAILURE, |
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
131 | "Error running Init function %s", |
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
132 | func_name); |
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
133 | return 1; |
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
134 | } |
79
f48cea237ec3
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
135 | |
418
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
136 | dir = dir->next; |
13
1fdbf4170ef4
Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
137 | } |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
138 | |
426
6a2e7a464991
run Init directives after setuid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
423
diff
changeset
|
139 | return 0; |
6a2e7a464991
run Init directives after setuid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
423
diff
changeset
|
140 | } |
6a2e7a464991
run Init directives after setuid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
423
diff
changeset
|
141 | |
6a2e7a464991
run Init directives after setuid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
423
diff
changeset
|
142 | void free_init_conf(InitConfig *cfg) { |
418
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
143 | initconfig_free(cfg); |
1 | 144 | } |
145 | ||
388
30d29ef5b79a
change uid before most of the config is loaded
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
146 | ServerConfiguration* load_server_conf(CfgManager *mgr, char *file) { |
115
51d9a15eac98
improves logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
147 | log_ereport(LOG_VERBOSE, "load_server_conf"); |
18
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
148 | |
256
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
255
diff
changeset
|
149 | ServerConfig *serverconf = serverconfig_load(file); |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
255
diff
changeset
|
150 | if(!serverconf) { |
115
51d9a15eac98
improves logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
151 | log_ereport(LOG_FAILURE, "Cannot load server.conf"); |
256
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
255
diff
changeset
|
152 | return NULL; |
18
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
153 | } |
388
30d29ef5b79a
change uid before most of the config is loaded
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
154 | mgr->serverconf = serverconf; |
256
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
255
diff
changeset
|
155 | |
255
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
156 | pool_handle_t *pool = pool_create(); |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
157 | |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
158 | |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
159 | ServerConfiguration *serverconfig = pool_calloc(pool, 1, sizeof(ServerConfiguration)); |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
160 | serverconfig->ref = 1; |
255
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
161 | serverconfig->pool = pool; |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
162 | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
163 | CxAllocator *allocator = pool_allocator(serverconfig->pool); |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
164 | serverconfig->a = allocator; |
255
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
165 | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
166 | serverconfig->listeners = cxPointerLinkedListCreate(serverconfig->a, cx_cmp_ptr); |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
167 | serverconfig->logfiles = cxPointerLinkedListCreate(serverconfig->a, cx_cmp_ptr); |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
168 | serverconfig->host_vs = cxHashMapCreate(serverconfig->a, 16); |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
169 | serverconfig->authdbs = cxHashMapCreate(serverconfig->a, 16); |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
170 | serverconfig->resources = cxHashMapCreate(serverconfig->a, 16); |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
171 | serverconfig->dav = cxHashMapCreate(serverconfig->a, 16); |
33
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
172 | |
393
79e542cc20a9
fix listener not initialiazed before changeuid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
392
diff
changeset
|
173 | // STAGE 1 load_server_conf: |
79e542cc20a9
fix listener not initialiazed before changeuid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
392
diff
changeset
|
174 | // At stage 1 we load the file and get the Runtime infos for changing |
79e542cc20a9
fix listener not initialiazed before changeuid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
392
diff
changeset
|
175 | // the uid, which must be done before most steps. |
79e542cc20a9
fix listener not initialiazed before changeuid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
392
diff
changeset
|
176 | // Before the uid can be changed, we also need to bind listeners, |
79e542cc20a9
fix listener not initialiazed before changeuid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
392
diff
changeset
|
177 | // therefore we need to get the listener config and all dependencies. |
79e542cc20a9
fix listener not initialiazed before changeuid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
392
diff
changeset
|
178 | // |
79e542cc20a9
fix listener not initialiazed before changeuid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
392
diff
changeset
|
179 | // Runtime |
79e542cc20a9
fix listener not initialiazed before changeuid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
392
diff
changeset
|
180 | // Listener (dependencies: Threadpool, EventHandler) |
33
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
181 | |
393
79e542cc20a9
fix listener not initialiazed before changeuid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
392
diff
changeset
|
182 | // load Runtime config |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
183 | CxList *list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, cx_str("Runtime")); |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
184 | CxIterator iter = cxListIterator(list, 0); |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
185 | cx_foreach(ConfigNode *, runtimeobj, iter) { |
388
30d29ef5b79a
change uid before most of the config is loaded
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
186 | if(cfg_handle_runtime(serverconfig, runtimeobj)) { |
30d29ef5b79a
change uid before most of the config is loaded
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
187 | // error |
443
ef3c8a0e1fee
improve daemon startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
188 | log_ereport(LOG_FAILURE, "server.conf runtime"); |
388
30d29ef5b79a
change uid before most of the config is loaded
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
189 | return NULL; |
30d29ef5b79a
change uid before most of the config is loaded
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
190 | } |
30d29ef5b79a
change uid before most of the config is loaded
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
191 | } |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
192 | cxListDestroy(list); |
388
30d29ef5b79a
change uid before most of the config is loaded
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
193 | |
393
79e542cc20a9
fix listener not initialiazed before changeuid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
392
diff
changeset
|
194 | // load threadpool config |
79e542cc20a9
fix listener not initialiazed before changeuid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
392
diff
changeset
|
195 | log_ereport(LOG_DEBUG, "apply config: Threadpool"); |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
196 | list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, cx_str("Threadpool")); |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
197 | iter = cxListIterator(list, 0); |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
198 | cx_foreach(ConfigNode *, elm, iter) { |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
199 | if(cfg_handle_threadpool(serverconfig, elm)) { |
443
ef3c8a0e1fee
improve daemon startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
200 | log_ereport(LOG_FAILURE, "server.conf threadpool"); |
393
79e542cc20a9
fix listener not initialiazed before changeuid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
392
diff
changeset
|
201 | return NULL; |
79e542cc20a9
fix listener not initialiazed before changeuid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
392
diff
changeset
|
202 | } |
79e542cc20a9
fix listener not initialiazed before changeuid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
392
diff
changeset
|
203 | } |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
204 | cxListDestroy(list); |
393
79e542cc20a9
fix listener not initialiazed before changeuid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
392
diff
changeset
|
205 | // check thread pool config |
79e542cc20a9
fix listener not initialiazed before changeuid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
392
diff
changeset
|
206 | if(check_thread_pool_cfg() != 0) { |
79e542cc20a9
fix listener not initialiazed before changeuid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
392
diff
changeset
|
207 | /* critical error */ |
79e542cc20a9
fix listener not initialiazed before changeuid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
392
diff
changeset
|
208 | return NULL; |
79e542cc20a9
fix listener not initialiazed before changeuid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
392
diff
changeset
|
209 | } |
79e542cc20a9
fix listener not initialiazed before changeuid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
392
diff
changeset
|
210 | |
79e542cc20a9
fix listener not initialiazed before changeuid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
392
diff
changeset
|
211 | // load eventhandler config |
79e542cc20a9
fix listener not initialiazed before changeuid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
392
diff
changeset
|
212 | log_ereport(LOG_DEBUG, "apply config: EventHandler"); |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
213 | list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, cx_str("EventHandler")); |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
214 | iter = cxListIterator(list, 0); |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
215 | cx_foreach(ConfigNode *, elm, iter) { |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
216 | if(cfg_handle_eventhandler(serverconfig, elm)) { |
443
ef3c8a0e1fee
improve daemon startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
217 | // error |
ef3c8a0e1fee
improve daemon startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
218 | log_ereport(LOG_FAILURE, "cannot create event handler"); |
393
79e542cc20a9
fix listener not initialiazed before changeuid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
392
diff
changeset
|
219 | return NULL; |
79e542cc20a9
fix listener not initialiazed before changeuid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
392
diff
changeset
|
220 | } |
79e542cc20a9
fix listener not initialiazed before changeuid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
392
diff
changeset
|
221 | } |
79e542cc20a9
fix listener not initialiazed before changeuid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
392
diff
changeset
|
222 | // check event handler config |
79e542cc20a9
fix listener not initialiazed before changeuid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
392
diff
changeset
|
223 | if(check_event_handler_cfg() != 0) { |
79e542cc20a9
fix listener not initialiazed before changeuid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
392
diff
changeset
|
224 | /* critical error */ |
79e542cc20a9
fix listener not initialiazed before changeuid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
392
diff
changeset
|
225 | return NULL; |
79e542cc20a9
fix listener not initialiazed before changeuid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
392
diff
changeset
|
226 | } |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
227 | cxListDestroy(list); |
443
ef3c8a0e1fee
improve daemon startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
228 | |
393
79e542cc20a9
fix listener not initialiazed before changeuid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
392
diff
changeset
|
229 | // load Listener config |
79e542cc20a9
fix listener not initialiazed before changeuid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
392
diff
changeset
|
230 | log_ereport(LOG_DEBUG, "apply config: Listener"); |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
231 | list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, cx_str("Listener")); |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
232 | iter = cxListIterator(list, 0); |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
233 | cx_foreach(ConfigNode *, scfgobj, iter) { |
393
79e542cc20a9
fix listener not initialiazed before changeuid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
392
diff
changeset
|
234 | if(cfg_handle_listener(serverconfig, scfgobj)) { |
79e542cc20a9
fix listener not initialiazed before changeuid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
392
diff
changeset
|
235 | return NULL; |
79e542cc20a9
fix listener not initialiazed before changeuid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
392
diff
changeset
|
236 | } |
79e542cc20a9
fix listener not initialiazed before changeuid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
392
diff
changeset
|
237 | } |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
238 | cxListDestroy(list); |
393
79e542cc20a9
fix listener not initialiazed before changeuid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
392
diff
changeset
|
239 | |
388
30d29ef5b79a
change uid before most of the config is loaded
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
240 | // we return here, to let the webserver use the runtime info to |
30d29ef5b79a
change uid before most of the config is loaded
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
241 | // change the uid if needed |
30d29ef5b79a
change uid before most of the config is loaded
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
242 | return serverconfig; |
30d29ef5b79a
change uid before most of the config is loaded
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
243 | } |
30d29ef5b79a
change uid before most of the config is loaded
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
244 | |
30d29ef5b79a
change uid before most of the config is loaded
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
245 | ServerConfiguration* apply_server_conf(CfgManager *mgr) { |
30d29ef5b79a
change uid before most of the config is loaded
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
246 | ServerConfig *serverconf = mgr->serverconf; |
30d29ef5b79a
change uid before most of the config is loaded
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
247 | ServerConfiguration *serverconfig = mgr->cfg; |
79
f48cea237ec3
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
248 | |
393
79e542cc20a9
fix listener not initialiazed before changeuid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
392
diff
changeset
|
249 | /* |
79e542cc20a9
fix listener not initialiazed before changeuid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
392
diff
changeset
|
250 | * convert ServerConfig to ServerConfiguration |
79e542cc20a9
fix listener not initialiazed before changeuid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
392
diff
changeset
|
251 | * |
79e542cc20a9
fix listener not initialiazed before changeuid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
392
diff
changeset
|
252 | * its important to do this in the correct order: |
79e542cc20a9
fix listener not initialiazed before changeuid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
392
diff
changeset
|
253 | * LogFile (open log file first to log possible errors) |
79e542cc20a9
fix listener not initialiazed before changeuid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
392
diff
changeset
|
254 | * Threadpool |
79e542cc20a9
fix listener not initialiazed before changeuid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
392
diff
changeset
|
255 | * EventHandler |
79e542cc20a9
fix listener not initialiazed before changeuid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
392
diff
changeset
|
256 | * AuthDB |
79e542cc20a9
fix listener not initialiazed before changeuid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
392
diff
changeset
|
257 | * Listener (we set the VirtualServer later) |
79e542cc20a9
fix listener not initialiazed before changeuid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
392
diff
changeset
|
258 | * VirtualServer (dependencies: Listener) |
79e542cc20a9
fix listener not initialiazed before changeuid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
392
diff
changeset
|
259 | */ |
79e542cc20a9
fix listener not initialiazed before changeuid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
392
diff
changeset
|
260 | |
72 | 261 | // init logfile first |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
262 | CxList *list; |
256
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
255
diff
changeset
|
263 | |
392
0aef555055ee
print error in case the log file config doesn't work
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
388
diff
changeset
|
264 | log_ereport(LOG_DEBUG, "apply config: LogFile"); |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
265 | list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, cx_str("LogFile")); |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
266 | CxIterator iter = cxListIterator(list, 0); |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
267 | cx_foreach(ConfigNode *, logobj, iter) { |
256
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
255
diff
changeset
|
268 | if(!logobj) { |
72 | 269 | // error |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
270 | cxListDestroy(list); |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
271 | return NULL; |
29
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
272 | } |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
273 | |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
274 | int ret = cfg_handle_logfile(serverconfig, logobj); |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
275 | if(ret != 0) { |
72 | 276 | // cannot initialize log file |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
277 | cxListDestroy(list); |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
278 | return NULL; |
29
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
279 | } |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
280 | } |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
281 | cxListDestroy(list); |
33
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
282 | |
392
0aef555055ee
print error in case the log file config doesn't work
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
388
diff
changeset
|
283 | log_ereport(LOG_DEBUG, "apply config: AccessLog"); |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
284 | list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, cx_str("AccessLog")); |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
285 | iter = cxListIterator(list, 0); |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
286 | cx_foreach(ConfigNode *, scfgobj, iter) { |
72 | 287 | if(cfg_handle_accesslog(serverconfig, scfgobj)) { |
288 | return NULL; | |
289 | } | |
45
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
290 | } |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
291 | cxListDestroy(list); |
45
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
292 | |
392
0aef555055ee
print error in case the log file config doesn't work
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
388
diff
changeset
|
293 | log_ereport(LOG_DEBUG, "apply config: AuthDB"); |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
294 | list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, cx_str("AuthDB")); |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
295 | iter = cxListIterator(list, 0); |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
296 | cx_foreach(ConfigNode *, scfgobj, iter) { |
72 | 297 | if(cfg_handle_authdb(serverconfig, scfgobj)) { |
298 | return NULL; | |
299 | } | |
33
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
300 | } |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
301 | cxListDestroy(list); |
33
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
302 | |
392
0aef555055ee
print error in case the log file config doesn't work
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
388
diff
changeset
|
303 | log_ereport(LOG_DEBUG, "apply config: VirtualServer"); |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
304 | list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, cx_str("VirtualServer")); |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
305 | iter = cxListIterator(list, 0); |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
306 | cx_foreach(ConfigNode *, scfgobj, iter) { |
72 | 307 | if(cfg_handle_vs(serverconfig, scfgobj)) { |
308 | return NULL; | |
309 | } | |
18
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
310 | } |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
311 | cxListDestroy(list); |
30
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
312 | |
392
0aef555055ee
print error in case the log file config doesn't work
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
388
diff
changeset
|
313 | log_ereport(LOG_DEBUG, "apply config: ResourcePool"); |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
314 | list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, cx_str("ResourcePool")); |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
315 | iter = cxListIterator(list, 0); |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
316 | cx_foreach(ConfigNode *, scfgobj, iter) { |
269
3dfbd0b91950
add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
260
diff
changeset
|
317 | if(cfg_handle_resourcepool(serverconfig, scfgobj)) { |
3dfbd0b91950
add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
260
diff
changeset
|
318 | return NULL; |
3dfbd0b91950
add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
260
diff
changeset
|
319 | } |
3dfbd0b91950
add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
260
diff
changeset
|
320 | } |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
321 | cxListDestroy(list); |
366
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
322 | |
392
0aef555055ee
print error in case the log file config doesn't work
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
388
diff
changeset
|
323 | log_ereport(LOG_DEBUG, "apply config: Dav"); |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
324 | list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, cx_str("Dav")); |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
325 | iter = cxListIterator(list, 0); |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
326 | cx_foreach(ConfigNode *, scfgobj, iter) { |
366
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
327 | if(cfg_handle_dav(serverconfig, scfgobj)) { |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
328 | return NULL; |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
329 | } |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
330 | } |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
331 | cxListDestroy(list); |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
332 | |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
333 | // set VirtualServer for all listeners |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
334 | CxList *ls = serverconfig->listeners; |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
335 | iter = cxListIterator(ls, 0); |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
336 | cx_foreach(HttpListener *, listener, iter) { |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
337 | cxstring vsname = cx_str(listener->default_vs.vs_name); |
19
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
338 | |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
339 | // search for VirtualServer |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
340 | //int b = 0; |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
341 | CxIterator map_iter = cxMapIteratorValues(serverconfig->host_vs); |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
342 | cx_foreach(VirtualServer *, vs, map_iter) { |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
343 | if(!cx_strcmp(vsname, (cxstring){vs->name.ptr, vs->name.length})) { |
31 | 344 | listener->default_vs.vs = vs; |
19
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
345 | break; |
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
346 | } |
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
347 | } |
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
348 | } |
79
f48cea237ec3
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
349 | |
256
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
255
diff
changeset
|
350 | serverconfig_free(serverconf); |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
255
diff
changeset
|
351 | |
19
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
352 | return serverconfig; |
1 | 353 | } |
3
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
354 | |
440
d77b8f3e14e2
implement successor listener, fix webserver_reconfig
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
355 | int migrate_server_conf(ServerConfiguration *old_cfg, ServerConfiguration *new_cfg) { |
444
96d2ba2f28db
fix configuration referencing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
443
diff
changeset
|
356 | old_cfg->next = new_cfg; |
96d2ba2f28db
fix configuration referencing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
443
diff
changeset
|
357 | cfg_ref(new_cfg); // new cfg should not be freed until old cfg is freed |
96d2ba2f28db
fix configuration referencing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
443
diff
changeset
|
358 | |
440
d77b8f3e14e2
implement successor listener, fix webserver_reconfig
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
359 | // compare old/new listeners and set next listener, if they are using |
d77b8f3e14e2
implement successor listener, fix webserver_reconfig
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
360 | // the same socket |
d77b8f3e14e2
implement successor listener, fix webserver_reconfig
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
361 | CxIterator old_listeners = cxListIterator(old_cfg->listeners, 0); |
d77b8f3e14e2
implement successor listener, fix webserver_reconfig
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
362 | cx_foreach(HttpListener*, oldls, old_listeners) { |
d77b8f3e14e2
implement successor listener, fix webserver_reconfig
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
363 | if(oldls->next) { |
445
834351da593b
improve acceptor error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
444
diff
changeset
|
364 | // maybe we can remove this check |
834351da593b
improve acceptor error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
444
diff
changeset
|
365 | log_ereport(LOG_WARN, "migrate_server_conf: oldls->next not NULL"); |
440
d77b8f3e14e2
implement successor listener, fix webserver_reconfig
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
366 | continue; |
d77b8f3e14e2
implement successor listener, fix webserver_reconfig
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
367 | } |
444
96d2ba2f28db
fix configuration referencing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
443
diff
changeset
|
368 | |
440
d77b8f3e14e2
implement successor listener, fix webserver_reconfig
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
369 | CxIterator new_listeners = cxListIterator(new_cfg->listeners, 0); |
d77b8f3e14e2
implement successor listener, fix webserver_reconfig
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
370 | cx_foreach(HttpListener*, newls, new_listeners) { |
d77b8f3e14e2
implement successor listener, fix webserver_reconfig
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
371 | if(http_listener_socket_eq(oldls, newls)) { |
444
96d2ba2f28db
fix configuration referencing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
443
diff
changeset
|
372 | http_listener_set_next(oldls, newls); |
440
d77b8f3e14e2
implement successor listener, fix webserver_reconfig
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
373 | break; |
d77b8f3e14e2
implement successor listener, fix webserver_reconfig
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
374 | } |
d77b8f3e14e2
implement successor listener, fix webserver_reconfig
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
375 | } |
445
834351da593b
improve acceptor error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
444
diff
changeset
|
376 | http_listener_shutdown_acceptors(oldls); |
447
45d1b02fa80b
add missing init_logging declaration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
445
diff
changeset
|
377 | |
45d1b02fa80b
add missing init_logging declaration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
445
diff
changeset
|
378 | // TODO: wait until old listener is shut down |
440
d77b8f3e14e2
implement successor listener, fix webserver_reconfig
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
379 | } |
d77b8f3e14e2
implement successor listener, fix webserver_reconfig
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
380 | |
d77b8f3e14e2
implement successor listener, fix webserver_reconfig
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
381 | return 0; |
d77b8f3e14e2
implement successor listener, fix webserver_reconfig
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
382 | } |
d77b8f3e14e2
implement successor listener, fix webserver_reconfig
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
383 | |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
384 | void cfg_ref(ServerConfiguration *cfg) { |
41
bb7a1f5a8b48
added Linux support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
385 | ws_atomic_inc32(&cfg->ref); |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
386 | } |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
387 | |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
388 | void cfg_unref(ServerConfiguration *cfg) { |
41
bb7a1f5a8b48
added Linux support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
389 | uint32_t ref = ws_atomic_dec32(&cfg->ref); |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
390 | if(ref == 0) { |
444
96d2ba2f28db
fix configuration referencing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
443
diff
changeset
|
391 | if(cfg->next) { |
96d2ba2f28db
fix configuration referencing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
443
diff
changeset
|
392 | cfg_unref(cfg->next); |
96d2ba2f28db
fix configuration referencing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
443
diff
changeset
|
393 | } |
96d2ba2f28db
fix configuration referencing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
443
diff
changeset
|
394 | log_ereport(LOG_VERBOSE, "destroy configuration %p", cfg); |
255
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
395 | pool_destroy(cfg->pool); |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
396 | } |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
397 | } |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
398 | |
19
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
399 | |
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
400 | void init_server_config_parser() { |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
401 | |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
402 | } |
18
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
403 | |
256
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
255
diff
changeset
|
404 | int cfg_handle_runtime(ServerConfiguration *cfg, ConfigNode *obj) { |
418
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
405 | cxstring user = serverconfig_object_directive_value(obj, cx_str("User")); |
72 | 406 | if(user.ptr) { |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
407 | cfg->user = cx_strdup_a(cfg->a, user); |
72 | 408 | } |
418
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
409 | cxstring tmp = serverconfig_object_directive_value(obj, cx_str("Temp")); |
72 | 410 | if(tmp.ptr) { |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
411 | cfg->tmp = cx_strdup_a(cfg->a, tmp); |
72 | 412 | } else { |
256
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
255
diff
changeset
|
413 | // TODO: do this check after all config loading is done |
72 | 414 | log_ereport(LOG_MISCONFIG, "no temporary directory specified"); |
415 | return -1; | |
416 | } | |
39
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
417 | |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
418 | // mime file |
418
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
419 | cxstring mf = serverconfig_object_directive_value(obj, cx_str("MimeFile")); |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
420 | cxstring base = cx_str("config/"); |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
421 | cxmutstr file = cx_strcat(2, base, mf); |
39
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
422 | |
255
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
423 | if(mime_conf_load(cfg, file)) { |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
424 | return -1; |
39
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
425 | } |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
426 | |
99 | 427 | free(file.ptr); |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
428 | return 0; |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
429 | } |
19
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
430 | |
256
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
255
diff
changeset
|
431 | int cfg_handle_logfile(ServerConfiguration *cfg, ConfigNode *obj) { |
418
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
432 | cxstring file = serverconfig_object_directive_value(obj, cx_str("File")); |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
433 | cxstring lvl = serverconfig_object_directive_value(obj, cx_str("Level")); |
28 | 434 | |
392
0aef555055ee
print error in case the log file config doesn't work
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
388
diff
changeset
|
435 | int err = 0; |
0aef555055ee
print error in case the log file config doesn't work
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
388
diff
changeset
|
436 | if(file.ptr == NULL) { |
0aef555055ee
print error in case the log file config doesn't work
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
388
diff
changeset
|
437 | err = 1; |
0aef555055ee
print error in case the log file config doesn't work
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
388
diff
changeset
|
438 | log_ereport(LOG_MISCONFIG, "LogFile: parameter missing: File"); |
0aef555055ee
print error in case the log file config doesn't work
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
388
diff
changeset
|
439 | } |
0aef555055ee
print error in case the log file config doesn't work
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
388
diff
changeset
|
440 | if(lvl.ptr == NULL) { |
0aef555055ee
print error in case the log file config doesn't work
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
388
diff
changeset
|
441 | err = 1; |
0aef555055ee
print error in case the log file config doesn't work
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
388
diff
changeset
|
442 | log_ereport(LOG_MISCONFIG, "LogFile: parameter missing: Level"); |
0aef555055ee
print error in case the log file config doesn't work
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
388
diff
changeset
|
443 | } |
0aef555055ee
print error in case the log file config doesn't work
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
388
diff
changeset
|
444 | if(err) { |
28 | 445 | return -1; |
446 | } | |
447 | ||
448 | LogConfig logcfg; | |
256
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
255
diff
changeset
|
449 | logcfg.file = file.ptr; |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
255
diff
changeset
|
450 | logcfg.level = lvl.ptr; |
139
29ac9aed4889
fixes some memory errors and startup with broken config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
135
diff
changeset
|
451 | logcfg.log_stdout = 0; |
29ac9aed4889
fixes some memory errors and startup with broken config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
135
diff
changeset
|
452 | logcfg.log_stderr = 0; |
28 | 453 | /* TODO: stdout, stderr config */ |
454 | ||
455 | int ret = init_log_file(&logcfg); | |
19
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
456 | |
28 | 457 | return ret; |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
458 | } |
19
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
459 | |
256
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
255
diff
changeset
|
460 | int cfg_handle_threadpool(ServerConfiguration *cfg, ConfigNode *obj) { |
37
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
461 | ThreadPoolConfig poolcfg; |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
462 | poolcfg.min_threads = 4; |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
463 | poolcfg.min_threads = 4; |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
464 | poolcfg.max_threads = 8; |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
465 | poolcfg.queue_size = 64; |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
466 | poolcfg.stack_size = 262144; |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
467 | |
418
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
468 | cxstring name = serverconfig_object_directive_value(obj, cx_str("Name")); |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
469 | cxstring min = serverconfig_object_directive_value(obj, cx_str("MinThreads")); |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
470 | cxstring max = serverconfig_object_directive_value(obj, cx_str("MaxThreads")); |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
471 | cxstring stack = serverconfig_object_directive_value(obj, cx_str("StackSize")); |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
472 | cxstring queue = serverconfig_object_directive_value(obj, cx_str("QueueSize")); |
37
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
473 | // TODO: Type |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
474 | |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
475 | if(name.length == 0) { |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
476 | // TODO: log error |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
477 | return 1; |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
478 | } |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
479 | |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
480 | if(min.length != 0) { |
339
f4a34b0869c7
replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
270
diff
changeset
|
481 | int64_t value; |
f4a34b0869c7
replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
270
diff
changeset
|
482 | if(util_strtoint(min.ptr, &value)) { |
f4a34b0869c7
replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
270
diff
changeset
|
483 | poolcfg.min_threads = value; |
f4a34b0869c7
replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
270
diff
changeset
|
484 | } else { |
f4a34b0869c7
replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
270
diff
changeset
|
485 | log_ereport(LOG_MISCONFIG, "Threadpool: MinThreads not an integer"); |
f4a34b0869c7
replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
270
diff
changeset
|
486 | return 1; |
f4a34b0869c7
replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
270
diff
changeset
|
487 | } |
37
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
488 | } |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
489 | |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
490 | if(max.length != 0) { |
339
f4a34b0869c7
replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
270
diff
changeset
|
491 | int64_t value; |
f4a34b0869c7
replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
270
diff
changeset
|
492 | if(util_strtoint(max.ptr, &value)) { |
f4a34b0869c7
replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
270
diff
changeset
|
493 | poolcfg.max_threads = value; |
f4a34b0869c7
replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
270
diff
changeset
|
494 | } else { |
f4a34b0869c7
replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
270
diff
changeset
|
495 | log_ereport(LOG_MISCONFIG, "Threadpool: MaxThreads not an integer"); |
f4a34b0869c7
replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
270
diff
changeset
|
496 | return 1; |
f4a34b0869c7
replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
270
diff
changeset
|
497 | } |
37
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
498 | } |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
499 | |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
500 | if(stack.length != 0) { |
339
f4a34b0869c7
replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
270
diff
changeset
|
501 | int64_t value; |
f4a34b0869c7
replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
270
diff
changeset
|
502 | if(util_strtoint(stack.ptr, &value)) { |
f4a34b0869c7
replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
270
diff
changeset
|
503 | poolcfg.stack_size = value; |
f4a34b0869c7
replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
270
diff
changeset
|
504 | } else { |
f4a34b0869c7
replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
270
diff
changeset
|
505 | log_ereport(LOG_MISCONFIG, "Threadpool: StackSize not an integer"); |
f4a34b0869c7
replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
270
diff
changeset
|
506 | } |
37
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
507 | } |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
508 | |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
509 | if(queue.length != 0) { |
339
f4a34b0869c7
replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
270
diff
changeset
|
510 | int64_t value; |
f4a34b0869c7
replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
270
diff
changeset
|
511 | if(util_strtoint(queue.ptr, &value)) { |
f4a34b0869c7
replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
270
diff
changeset
|
512 | poolcfg.queue_size = value; |
f4a34b0869c7
replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
270
diff
changeset
|
513 | } else { |
f4a34b0869c7
replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
270
diff
changeset
|
514 | log_ereport(LOG_MISCONFIG, "Threadpool: QueueSize not an integer"); |
f4a34b0869c7
replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
270
diff
changeset
|
515 | } |
37
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
516 | } |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
517 | |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
518 | create_threadpool(name, &poolcfg); |
70
4e6e812c1d97
fixed some warnings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
63
diff
changeset
|
519 | |
4e6e812c1d97
fixed some warnings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
63
diff
changeset
|
520 | return 0; |
37
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
521 | } |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
522 | |
339
f4a34b0869c7
replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
270
diff
changeset
|
523 | #define EV_MAX_THREADS 2048 |
256
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
255
diff
changeset
|
524 | int cfg_handle_eventhandler(ServerConfiguration *c, ConfigNode *obj) { |
30
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
525 | EventHandlerConfig evcfg; |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
526 | |
418
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
527 | cxstring name = serverconfig_object_directive_value(obj, cx_str("Name")); |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
528 | cxstring threads = serverconfig_object_directive_value(obj, cx_str("Threads")); |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
529 | cxstring isdefault = serverconfig_object_directive_value(obj, cx_str("Default")); |
30
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
530 | |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
531 | evcfg.name = name; |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
532 | |
339
f4a34b0869c7
replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
270
diff
changeset
|
533 | int64_t value; |
f4a34b0869c7
replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
270
diff
changeset
|
534 | if(!util_strtoint(threads.ptr, &value)) { |
f4a34b0869c7
replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
270
diff
changeset
|
535 | log_ereport(LOG_MISCONFIG, "EventHandler: Threads: '%s' is not an integer", threads.ptr); |
f4a34b0869c7
replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
270
diff
changeset
|
536 | return 1; |
f4a34b0869c7
replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
270
diff
changeset
|
537 | } |
f4a34b0869c7
replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
270
diff
changeset
|
538 | if(value < 1 || value > EV_MAX_THREADS) { |
f4a34b0869c7
replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
270
diff
changeset
|
539 | log_ereport(LOG_MISCONFIG, "EventHandler: Invalid number of threads (1 .. %d)", EV_MAX_THREADS); |
f4a34b0869c7
replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
270
diff
changeset
|
540 | return 1; |
f4a34b0869c7
replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
270
diff
changeset
|
541 | } |
f4a34b0869c7
replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
270
diff
changeset
|
542 | |
f4a34b0869c7
replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
270
diff
changeset
|
543 | evcfg.nthreads = value; |
30
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
544 | |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
545 | evcfg.isdefault = util_getboolean(isdefault.ptr, 0); |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
546 | |
72 | 547 | return create_event_handler(&evcfg); |
30
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
548 | } |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
549 | |
269
3dfbd0b91950
add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
260
diff
changeset
|
550 | int cfg_handle_resourcepool(ServerConfiguration *cfg, ConfigNode *obj) { |
418
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
551 | cxstring name = serverconfig_object_directive_value(obj, cx_str("Name")); |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
552 | cxstring type = serverconfig_object_directive_value(obj, cx_str("Type")); |
269
3dfbd0b91950
add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
260
diff
changeset
|
553 | |
3dfbd0b91950
add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
260
diff
changeset
|
554 | int ret = 0; |
270
4cfaa02055cd
add first code for postgresql plugin: resourcepool type implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
269
diff
changeset
|
555 | if(resourcepool_new(cfg, type, name, obj)) { |
269
3dfbd0b91950
add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
260
diff
changeset
|
556 | ret = 1; |
3dfbd0b91950
add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
260
diff
changeset
|
557 | } |
3dfbd0b91950
add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
260
diff
changeset
|
558 | |
3dfbd0b91950
add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
260
diff
changeset
|
559 | return ret; |
3dfbd0b91950
add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
260
diff
changeset
|
560 | } |
3dfbd0b91950
add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
260
diff
changeset
|
561 | |
256
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
255
diff
changeset
|
562 | int cfg_handle_accesslog(ServerConfiguration *cfg, ConfigNode *obj) { |
45
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
563 | // TODO: use a name to identify the log file |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
564 | |
418
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
565 | cxstring file = serverconfig_object_directive_value(obj, cx_str("File")); |
45
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
566 | if(file.ptr == NULL) { |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
567 | return 0; |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
568 | } |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
569 | cxmutstr format; |
77 | 570 | format.ptr = NULL; |
571 | format.length = 0; | |
45
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
572 | |
77 | 573 | //AccessLog *log = get_access_log(file, format); |
574 | LogFile *log_file = get_access_log_file(file); | |
575 | if(!log_file) { | |
576 | // TODO: error/warning | |
577 | return 0; | |
578 | } | |
579 | AccessLog *log = pool_malloc(cfg->pool, sizeof(AccessLog)); | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
580 | log->file = cx_strdup_a(cfg->a, file); |
77 | 581 | log->format = format; |
582 | log->log = log_file; | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
583 | cxListAdd(cfg->logfiles, log); |
77 | 584 | |
585 | if(!cfg->default_log) { | |
586 | cfg->default_log = log; | |
45
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
587 | } |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
588 | |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
589 | return 0; |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
590 | } |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
591 | |
256
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
255
diff
changeset
|
592 | int cfg_handle_authdb(ServerConfiguration *cfg, ConfigNode *obj) { |
418
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
593 | cxstring name = serverconfig_object_directive_value(obj, cx_str("Name")); |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
594 | cxstring type = serverconfig_object_directive_value(obj, cx_str("Type")); |
38
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
595 | |
255
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
596 | AuthDB *authdb = NULL; |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
597 | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
598 | if(!cx_strcmp(type, cx_str("ldap"))) { |
38
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
599 | LDAPConfig conf; |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
600 | |
418
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
601 | cxstring host = serverconfig_object_directive_value(obj, cx_str("Host")); |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
602 | cxstring port = serverconfig_object_directive_value( obj, cx_str("Port")); |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
603 | cxstring basedn = serverconfig_object_directive_value(obj, cx_str("BaseDN")); |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
604 | cxstring binddn = serverconfig_object_directive_value(obj, cx_str("BindDN")); |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
605 | cxstring basepw = serverconfig_object_directive_value(obj, cx_str("BindPW")); |
38
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
606 | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
607 | conf.hostname = cx_strdup_a(cfg->a, host).ptr; |
38
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
608 | conf.port = atoi(port.ptr); |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
609 | conf.basedn = cx_strdup_a(cfg->a, basedn).ptr; |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
610 | conf.binddn = cx_strdup_a(cfg->a, binddn).ptr; |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
611 | conf.bindpw = cx_strdup_a(cfg->a, basepw).ptr; |
38
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
612 | |
256
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
255
diff
changeset
|
613 | authdb = create_ldap_authdb(cfg, name.ptr, &conf); |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
614 | } else if(!cx_strcmp(type, cx_str("keyfile"))) { |
62
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
615 | // we only need the file parameter |
418
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
616 | cxstring file = serverconfig_object_directive_value(obj, cx_str("File")); |
62
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
617 | if(file.length == 0) { |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
618 | log_ereport( |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
619 | LOG_MISCONFIG, |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
620 | "missing File parameter for keyfile authdb"); |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
621 | return 1; |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
622 | } |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
623 | |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
624 | // load keyfile |
255
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
625 | authdb = keyfile_load(cfg, file); |
38
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
626 | } |
19
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
627 | |
255
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
628 | if(authdb) { |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
629 | if(cxMapPut(cfg->authdbs, cx_hash_key_bytes((const unsigned char*)name.ptr, name.length), authdb)) { |
255
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
630 | return -1; |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
631 | } |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
632 | } |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
633 | |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
634 | return 0; |
18
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
635 | } |
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
636 | |
256
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
255
diff
changeset
|
637 | int cfg_handle_listener(ServerConfiguration *cfg, ConfigNode *obj) { |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
638 | ListenerConfig lc; |
130
198ad9d8cec1
adds ssl protocol configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
639 | ZERO(&lc, sizeof(ListenerConfig)); |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
640 | lc.cfg = cfg; |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
641 | lc.port = 8080; |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
642 | lc.nacceptors = 1; |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
643 | |
418
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
644 | cxstring name = serverconfig_object_directive_value(obj, cx_str("Name")); |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
645 | cxstring port = serverconfig_object_directive_value(obj, cx_str("Port")); |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
646 | cxstring vs = serverconfig_object_directive_value(obj, cx_str("DefaultVS")); |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
647 | cxstring thrp = serverconfig_object_directive_value(obj, cx_str("Threadpool")); |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
648 | cxstring blck = serverconfig_object_directive_value(obj, cx_str("BlockingIO")); |
18
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
649 | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
650 | // TODO: use cx_strdup_pool? |
339
f4a34b0869c7
replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
270
diff
changeset
|
651 | int64_t port_value; |
f4a34b0869c7
replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
270
diff
changeset
|
652 | if(!util_strtoint(port.ptr, &port_value)) { |
f4a34b0869c7
replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
270
diff
changeset
|
653 | log_ereport(LOG_MISCONFIG, "Listener: Invalid argument for parameter 'Port': '%s'", port.ptr); |
f4a34b0869c7
replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
270
diff
changeset
|
654 | return 1; |
f4a34b0869c7
replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
270
diff
changeset
|
655 | } |
f4a34b0869c7
replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
270
diff
changeset
|
656 | if(port_value < 1 || port_value > 65535) { |
f4a34b0869c7
replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
270
diff
changeset
|
657 | log_ereport(LOG_MISCONFIG, "Listener: Port number out of range (1 .. 65535)"); |
f4a34b0869c7
replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
270
diff
changeset
|
658 | return 1; |
f4a34b0869c7
replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
270
diff
changeset
|
659 | } |
f4a34b0869c7
replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
270
diff
changeset
|
660 | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
661 | lc.name = cx_strdup(name); |
339
f4a34b0869c7
replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
270
diff
changeset
|
662 | lc.port = port_value; |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
663 | lc.vs = cx_strdup(vs); |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
664 | lc.threadpool = cx_strdup(thrp); |
134
44415e4399ce
adds blockingio config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
133
diff
changeset
|
665 | |
256
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
255
diff
changeset
|
666 | lc.blockingio = util_getboolean_s(blck, WS_FALSE); |
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
255
diff
changeset
|
667 | |
418
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
668 | cxstring ssl = serverconfig_object_directive_value(obj, cx_str("SSL")); |
106
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
669 | if(util_getboolean_s(ssl, WS_FALSE)) { |
418
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
670 | cxstring cert = serverconfig_object_directive_value(obj, cx_str("Cert")); |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
671 | cxstring privkey = serverconfig_object_directive_value(obj, cx_str("Key")); |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
672 | cxstring chain = serverconfig_object_directive_value(obj, cx_str("CertChain")); |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
673 | cxstring disableprot = serverconfig_object_directive_value(obj, cx_str("SSLDisableProtocol")); |
130
198ad9d8cec1
adds ssl protocol configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
674 | |
106
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
675 | WSBool config_ok = WS_TRUE; |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
676 | // TODO: log error |
129
fd324464f56f
adds support for ssl cert chain files and improves ssl error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
677 | if(!cert.ptr && !chain.ptr) { |
130
198ad9d8cec1
adds ssl protocol configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
678 | log_ereport( |
198ad9d8cec1
adds ssl protocol configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
679 | LOG_MISCONFIG, |
198ad9d8cec1
adds ssl protocol configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
680 | "SSL Listener %s: Missing Cert or ChainCert directive", |
198ad9d8cec1
adds ssl protocol configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
681 | lc.name.ptr); |
106
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
682 | config_ok = WS_FALSE; |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
683 | } |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
684 | if(!privkey.ptr) { |
130
198ad9d8cec1
adds ssl protocol configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
685 | log_ereport( |
198ad9d8cec1
adds ssl protocol configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
686 | LOG_MISCONFIG, |
198ad9d8cec1
adds ssl protocol configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
687 | "SSL Listener %s: Missing Key directive", |
198ad9d8cec1
adds ssl protocol configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
688 | lc.name.ptr); |
106
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
689 | config_ok = WS_FALSE; |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
690 | } |
130
198ad9d8cec1
adds ssl protocol configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
691 | |
106
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
692 | if(config_ok) { |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
693 | lc.certfile = cert; |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
694 | lc.privkeyfile = privkey; |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
695 | lc.chainfile = chain; |
130
198ad9d8cec1
adds ssl protocol configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
129
diff
changeset
|
696 | lc.disable_proto = disableprot; |
106
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
697 | lc.ssl = WS_TRUE; |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
698 | } |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
699 | } else { |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
700 | lc.ssl = WS_FALSE; |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
701 | } |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
702 | |
37
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
703 | // TODO: check if all important configs are set |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
704 | |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
705 | HttpListener *listener = http_listener_create(&lc); |
129
fd324464f56f
adds support for ssl cert chain files and improves ssl error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
706 | if(!listener) { |
fd324464f56f
adds support for ssl cert chain files and improves ssl error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
707 | return 1; |
fd324464f56f
adds support for ssl cert chain files and improves ssl error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
708 | } |
fd324464f56f
adds support for ssl cert chain files and improves ssl error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
115
diff
changeset
|
709 | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
710 | listener->default_vs.vs_name = cx_strdup_a(cfg->a, (cxstring){lc.vs.ptr, lc.vs.length}).ptr; |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
711 | cxListAdd(cfg->listeners, listener); |
37
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
712 | |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
713 | return 0; |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
714 | } |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
715 | |
256
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
255
diff
changeset
|
716 | int cfg_handle_vs(ServerConfiguration *cfg, ConfigNode *obj) { |
438
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
426
diff
changeset
|
717 | VirtualServer *vs = vs_new(cfg->pool); |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
718 | |
418
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
719 | vs->name = cx_strdup_a(cfg->a, serverconfig_object_directive_value(obj, cx_str("Name"))); |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
720 | vs->host = cx_strdup_a(cfg->a, serverconfig_object_directive_value(obj, cx_str("Host"))); |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
721 | vs->document_root = cx_strdup_a(cfg->a, serverconfig_object_directive_value(obj, cx_str("DocRoot"))); |
256
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
255
diff
changeset
|
722 | |
418
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
723 | cxstring objfile = serverconfig_object_directive_value(obj, cx_str("ObjectFile")); |
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
724 | cxstring aclfile = serverconfig_object_directive_value(obj, cx_str("ACLFile")); |
51 | 725 | |
726 | // load the object config file | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
727 | cxstring base = cx_str("config/"); |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
728 | // cx_strcat with allocator because we want to keep the string |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
729 | cxmutstr file = cx_strcat_a(cfg->a, 2, base, objfile); |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
730 | |
255
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
731 | HTTPObjectConfig *httpobj = objconf_load(cfg, file); |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
732 | if(!httpobj) { |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
733 | return -1; |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
734 | } |
255
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
735 | vs->objectfile = file; |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
736 | vs->objects = httpobj; |
99 | 737 | |
45
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
738 | |
51 | 739 | // load acl config file |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
740 | cxmutstr acl_filepath = cx_strcat(2, base, aclfile); |
51 | 741 | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
742 | ACLData *acldata = acl_conf_load(cfg, acl_filepath.ptr); |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
743 | free(acl_filepath.ptr); |
255
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
744 | if(!acldata) { |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
745 | return -1; |
51 | 746 | } |
255
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
747 | vs->acls = acldata; |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
748 | |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
749 | |
45
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
750 | // set the access log for the virtual server |
255
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
751 | // TODO: don't always use the default |
77 | 752 | vs->log = cfg->default_log; |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
753 | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
754 | cxMapPut(cfg->host_vs, cx_hash_key_bytes((unsigned const char*)vs->host.ptr, vs->host.length), vs); |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
755 | |
18
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
756 | return 0; |
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
757 | } |
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
758 | |
366
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
759 | int cfg_handle_dav(ServerConfiguration *cfg, ConfigNode *obj) { |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
760 | CxAllocator *a = pool_allocator(cfg->pool); |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
761 | CxList *backends = cxPointerLinkedListCreate(a, cx_cmp_ptr); // list of ConfigParam* |
366
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
762 | int init_error; |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
763 | |
367
1592224f6059
add support for name/value config args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
366
diff
changeset
|
764 | // parse args |
1592224f6059
add support for name/value config args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
366
diff
changeset
|
765 | char *uri = NULL; |
1592224f6059
add support for name/value config args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
366
diff
changeset
|
766 | char *ppath = NULL; |
1592224f6059
add support for name/value config args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
366
diff
changeset
|
767 | char *name = NULL; |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
768 | for(ConfigParam *arg=obj->args;arg;arg=arg->next) { |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
769 | cxstring arg_name = (cxstring){ arg->name.ptr, arg->name.length }; |
367
1592224f6059
add support for name/value config args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
366
diff
changeset
|
770 | if(arg->name.ptr == NULL) { |
1592224f6059
add support for name/value config args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
366
diff
changeset
|
771 | // default: uri |
1592224f6059
add support for name/value config args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
366
diff
changeset
|
772 | uri = arg->value.ptr; |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
773 | } else if(!cx_strcasecmp(arg_name, cx_str("uri"))) { |
367
1592224f6059
add support for name/value config args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
366
diff
changeset
|
774 | uri = arg->value.ptr; |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
775 | } else if(!cx_strcasecmp(arg_name, cx_str("ppath"))) { |
367
1592224f6059
add support for name/value config args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
366
diff
changeset
|
776 | ppath = arg->value.ptr; |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
777 | } else if(!cx_strcasecmp(arg_name, cx_str("name"))) { |
367
1592224f6059
add support for name/value config args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
366
diff
changeset
|
778 | name = arg->value.ptr; |
1592224f6059
add support for name/value config args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
366
diff
changeset
|
779 | } |
1592224f6059
add support for name/value config args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
366
diff
changeset
|
780 | } |
1592224f6059
add support for name/value config args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
366
diff
changeset
|
781 | if(!uri && !ppath && !name) { |
1592224f6059
add support for name/value config args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
366
diff
changeset
|
782 | return 1; |
1592224f6059
add support for name/value config args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
366
diff
changeset
|
783 | } |
1592224f6059
add support for name/value config args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
366
diff
changeset
|
784 | |
366
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
785 | // get a list of all DavBackends |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
786 | for(ConfigNode *node=obj->children_begin;node;node=node->next) { |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
787 | cxstring node_name = cx_strn(node->name.ptr, node->name.length); |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
788 | if(!cx_strcasecmp(node_name, cx_str("DavBackend"))) { |
366
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
789 | if(node->type == CONFIG_NODE_DIRECTIVE) { |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
790 | if(CFG_NUM_PARAMS(node->args) == 1) { |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
791 | cxListAdd(backends, node->args); |
366
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
792 | } else { |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
793 | log_ereport(LOG_MISCONFIG, "DavBackend must have only one value"); |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
794 | cxListDestroy(backends); |
366
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
795 | return 1; |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
796 | } |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
797 | } else { |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
798 | log_ereport(LOG_MISCONFIG, "DavBackend must be a directive"); |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
799 | cxListDestroy(backends); |
366
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
800 | return 1; |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
801 | } |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
802 | } |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
803 | } |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
804 | |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
805 | int ret = 0; |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
806 | WebdavRepository *repository = pool_malloc(cfg->pool, sizeof(WebdavRepository)); |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
807 | repository->vfs = NULL; |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
808 | repository->vfsInitData = NULL; |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
809 | repository->davBackends = cxPointerLinkedListCreate(a, cx_cmp_ptr); // value type: WebdavBackendInitData* |
366
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
810 | |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
811 | // initialize backends |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
812 | CxIterator i = cxListIterator(backends, 0); |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
813 | cx_foreach(ConfigParam *, backendArg, i) { |
366
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
814 | // the DavBackend value should contain the dav class name |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
815 | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
816 | WebdavType *dav = webdav_get_type((cxstring){backendArg->value.ptr, backendArg->value.length}); |
366
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
817 | if(!dav) { |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
818 | log_ereport(LOG_MISCONFIG, "Unknown webdav backend type '%s'", backendArg->value.ptr); |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
819 | ret = 1; |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
820 | break; |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
821 | } |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
822 | |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
823 | // call backend init |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
824 | // init_data can be NULL, errors will be indicated by init_error |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
825 | void *init_data = webdav_init_backend(cfg, cfg->pool, dav, obj, &init_error); |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
826 | if(init_error) { |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
827 | log_ereport(LOG_FAILURE, "Failed to initialize webdav backend %s", backendArg->value.ptr); |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
828 | ret = 1; |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
829 | break; |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
830 | } |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
831 | |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
832 | WebdavBackendInitData *davInit = pool_malloc(cfg->pool, sizeof(WebdavBackendInitData)); |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
833 | if(!davInit) { |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
834 | log_ereport(LOG_FAILURE, "Failed to initialize webdav backend %s: OOM", backendArg->value.ptr); |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
835 | ret = 1; |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
836 | break; |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
837 | } |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
838 | davInit->davType = dav; |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
839 | davInit->davInitData = init_data; |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
840 | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
841 | cxListAdd(repository->davBackends, davInit); |
366
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
842 | } |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
843 | cxListDestroy(backends); |
366
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
844 | |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
845 | // initialize vfs |
418
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
846 | cxstring vfs_class = serverconfig_object_directive_value(obj, cx_str("VFS")); |
366
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
847 | if(vfs_class.length > 0) { |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
848 | VfsType *vfs = vfs_get_type((cxstring){vfs_class.ptr, vfs_class.length}); |
366
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
849 | if(vfs) { |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
850 | repository->vfs = vfs; |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
851 | repository->vfsInitData = vfs_init_backend(cfg, cfg->pool, vfs, obj, &init_error); |
409
62aad4d94d5d
abort config loading if an unknown webdav backend is specified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
852 | if(!ret) { |
62aad4d94d5d
abort config loading if an unknown webdav backend is specified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
853 | ret = init_error; |
62aad4d94d5d
abort config loading if an unknown webdav backend is specified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
393
diff
changeset
|
854 | } |
366
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
855 | } else { |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
856 | log_ereport(LOG_FAILURE, "Unknown vfs type '%s'", vfs_class.ptr); |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
857 | ret = 1; |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
858 | } |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
859 | } |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
860 | |
418
b7dcc9c4f270
use server.conf parser for init.conf as well
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
861 | cxstring object = serverconfig_object_directive_value(obj, cx_str("Object")); |
366
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
862 | if(object.length > 0) { |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
863 | repository->object = cx_strdup_a(a, object); |
366
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
864 | if(repository->object.length != object.length) { |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
865 | // OOM |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
866 | log_ereport(LOG_FAILURE, "Cannot create webdav repository: OOM"); |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
867 | ret = 1; |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
868 | } |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
869 | } |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
870 | |
368
69dbcc7e7f93
implement named dav repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
871 | if(!ret) { |
69dbcc7e7f93
implement named dav repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
872 | if(name) { |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
873 | cxMapPut(cfg->dav, cx_hash_key_str(name), repository); |
368
69dbcc7e7f93
implement named dav repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
874 | } else { |
69dbcc7e7f93
implement named dav repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
875 | log_ereport(LOG_FAILURE, "TODO: location based dav repositories not implemented"); |
69dbcc7e7f93
implement named dav repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
876 | ret = 1; |
69dbcc7e7f93
implement named dav repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
877 | } |
69dbcc7e7f93
implement named dav repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
878 | } |
69dbcc7e7f93
implement named dav repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
879 | |
366
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
880 | return ret; |
47bc686fafe4
add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
339
diff
changeset
|
881 | } |
19
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
882 | |
420
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
883 | // condition depth limit, evaluated in recursive convert_objconf_directives calls |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
884 | #define OBJ_CONF_MAX_CONDITION_DEPTH 500 |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
885 | |
422
76f2f5d532d0
extend serverconfig tokenizer to create separate tokens for brackets
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
420
diff
changeset
|
886 | static int set_client_condition(pool_handle_t *pool, ConfigNode *node, Condition *condition) { |
76f2f5d532d0
extend serverconfig tokenizer to create separate tokens for brackets
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
420
diff
changeset
|
887 | return 0; |
76f2f5d532d0
extend serverconfig tokenizer to create separate tokens for brackets
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
420
diff
changeset
|
888 | } |
76f2f5d532d0
extend serverconfig tokenizer to create separate tokens for brackets
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
420
diff
changeset
|
889 | |
423
bb7cff720dd0
add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
422
diff
changeset
|
890 | static int set_if_condition(pool_handle_t *pool, ConfigNode *node, Condition *condition) { |
bb7cff720dd0
add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
422
diff
changeset
|
891 | // convert to parameters to a list of tokens |
bb7cff720dd0
add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
422
diff
changeset
|
892 | // usually, one parameter is one token, however the config parser |
bb7cff720dd0
add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
422
diff
changeset
|
893 | // converts name=value pairs to one ConfigParam |
422
76f2f5d532d0
extend serverconfig tokenizer to create separate tokens for brackets
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
420
diff
changeset
|
894 | |
423
bb7cff720dd0
add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
422
diff
changeset
|
895 | // list of cxmutstr, however the expression parser will use this |
bb7cff720dd0
add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
422
diff
changeset
|
896 | // as list of cxstring, but that is totally fine |
bb7cff720dd0
add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
422
diff
changeset
|
897 | CxList *tokens = cxLinkedListCreate(pool_allocator(pool), cx_cmp_ptr, sizeof(cxmutstr)); |
bb7cff720dd0
add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
422
diff
changeset
|
898 | ConfigParam *arg = node->args; |
bb7cff720dd0
add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
422
diff
changeset
|
899 | while(arg) { |
bb7cff720dd0
add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
422
diff
changeset
|
900 | if(arg->name.length > 0) { |
bb7cff720dd0
add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
422
diff
changeset
|
901 | // arg text is name=value, therefore we add 3 tokens |
bb7cff720dd0
add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
422
diff
changeset
|
902 | // name, "=", value |
bb7cff720dd0
add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
422
diff
changeset
|
903 | cxListAdd(tokens, &arg->name); |
bb7cff720dd0
add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
422
diff
changeset
|
904 | cxmutstr op = (cxmutstr){ "=", 1 }; |
bb7cff720dd0
add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
422
diff
changeset
|
905 | cxListAdd(tokens, &op); |
bb7cff720dd0
add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
422
diff
changeset
|
906 | } |
bb7cff720dd0
add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
422
diff
changeset
|
907 | if(cxListAdd(tokens, &arg->value)) { |
bb7cff720dd0
add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
422
diff
changeset
|
908 | cxListDestroy(tokens); |
bb7cff720dd0
add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
422
diff
changeset
|
909 | return 1; // OOM |
bb7cff720dd0
add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
422
diff
changeset
|
910 | } |
bb7cff720dd0
add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
422
diff
changeset
|
911 | arg = arg->next; |
422
76f2f5d532d0
extend serverconfig tokenizer to create separate tokens for brackets
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
420
diff
changeset
|
912 | } |
76f2f5d532d0
extend serverconfig tokenizer to create separate tokens for brackets
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
420
diff
changeset
|
913 | |
423
bb7cff720dd0
add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
422
diff
changeset
|
914 | int ret = 0; |
bb7cff720dd0
add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
422
diff
changeset
|
915 | condition->expression = condition_create(pool, tokens); |
bb7cff720dd0
add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
422
diff
changeset
|
916 | if(!condition->expression) { |
bb7cff720dd0
add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
422
diff
changeset
|
917 | ret = 1; |
bb7cff720dd0
add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
422
diff
changeset
|
918 | } |
bb7cff720dd0
add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
422
diff
changeset
|
919 | |
bb7cff720dd0
add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
422
diff
changeset
|
920 | // don't need the token list anymore |
bb7cff720dd0
add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
422
diff
changeset
|
921 | cxListDestroy(tokens); |
bb7cff720dd0
add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
422
diff
changeset
|
922 | |
bb7cff720dd0
add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
422
diff
changeset
|
923 | return ret; |
422
76f2f5d532d0
extend serverconfig tokenizer to create separate tokens for brackets
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
420
diff
changeset
|
924 | } |
420
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
925 | |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
926 | // convert a condition |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
927 | static Condition* convert_objconf_condition( |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
928 | pool_handle_t *pool, |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
929 | ConfigNode *node, |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
930 | Condition *prev_condition, |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
931 | Condition *parent_condition, |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
932 | int *condition_index) |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
933 | { |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
934 | const char *condnames[] = { "Client", "If", "ElseIf", "Else" }; |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
935 | size_t typeindex; |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
936 | if(serverconfig_validate_directive_name(node, condnames, 4, &typeindex)) { |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
937 | // probably node->name is "Object", but nested objects are not allowed |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
938 | // maybe there should be a special error message in this case |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
939 | return NULL; |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
940 | } |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
941 | |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
942 | // "ElseIf" and "Else" require, that a previous "If" or "ElseIf" node exists |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
943 | if((typeindex == 2 || typeindex == 3) && prev_condition == NULL) { |
422
76f2f5d532d0
extend serverconfig tokenizer to create separate tokens for brackets
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
420
diff
changeset
|
944 | return NULL; |
420
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
945 | } |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
946 | Condition *condition = pool_malloc(pool, sizeof(Condition)); |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
947 | ZERO(condition, sizeof(Condition)); |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
948 | |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
949 | condition->index = *condition_index; |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
950 | condition->parent = parent_condition; |
422
76f2f5d532d0
extend serverconfig tokenizer to create separate tokens for brackets
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
420
diff
changeset
|
951 | |
76f2f5d532d0
extend serverconfig tokenizer to create separate tokens for brackets
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
420
diff
changeset
|
952 | if(typeindex == 0) { |
76f2f5d532d0
extend serverconfig tokenizer to create separate tokens for brackets
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
420
diff
changeset
|
953 | // "Client" |
76f2f5d532d0
extend serverconfig tokenizer to create separate tokens for brackets
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
420
diff
changeset
|
954 | if(set_client_condition(pool, node, condition)) { |
76f2f5d532d0
extend serverconfig tokenizer to create separate tokens for brackets
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
420
diff
changeset
|
955 | return NULL; |
76f2f5d532d0
extend serverconfig tokenizer to create separate tokens for brackets
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
420
diff
changeset
|
956 | } |
76f2f5d532d0
extend serverconfig tokenizer to create separate tokens for brackets
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
420
diff
changeset
|
957 | } else { |
76f2f5d532d0
extend serverconfig tokenizer to create separate tokens for brackets
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
420
diff
changeset
|
958 | condition->ifnot = prev_condition; |
76f2f5d532d0
extend serverconfig tokenizer to create separate tokens for brackets
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
420
diff
changeset
|
959 | |
76f2f5d532d0
extend serverconfig tokenizer to create separate tokens for brackets
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
420
diff
changeset
|
960 | // set expression for "If" or "ElseIf" |
76f2f5d532d0
extend serverconfig tokenizer to create separate tokens for brackets
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
420
diff
changeset
|
961 | if(typeindex != 4 && set_if_condition(pool, node, condition)) { |
76f2f5d532d0
extend serverconfig tokenizer to create separate tokens for brackets
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
420
diff
changeset
|
962 | return NULL; |
76f2f5d532d0
extend serverconfig tokenizer to create separate tokens for brackets
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
420
diff
changeset
|
963 | } |
76f2f5d532d0
extend serverconfig tokenizer to create separate tokens for brackets
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
420
diff
changeset
|
964 | } |
420
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
965 | |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
966 | (*condition_index)++; |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
967 | return condition; |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
968 | } |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
969 | |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
970 | // add directives to the httpd_object |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
971 | // node->type can be CONFIG_NODE_DIRECTIVE or CONFIG_NODE_OBJECT |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
972 | // CONFIG_NODE_DIRECTIVE can translated directly to directive* |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
973 | // CONFIG_NODE_OBJECT node must be a condition (If/ElseIf/Else/Client) |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
974 | static int convert_objconf_directives( |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
975 | pool_handle_t *pool, |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
976 | const char *file, |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
977 | httpd_object *obj, |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
978 | ConfigNode *node, |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
979 | Condition *parent_condition, |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
980 | int *condition_index) |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
981 | { |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
982 | // previous condition, if it was the previous node |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
983 | // this is needed to link the "ElseIf" or "Else" node with the previous |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
984 | // "If" node |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
985 | Condition *prev_condition = NULL; |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
986 | |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
987 | for(;node;node=node->next) { |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
988 | if(node->type == CONFIG_NODE_OBJECT) { |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
989 | Condition *condition = convert_objconf_condition(pool, node, prev_condition, parent_condition, condition_index); |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
990 | if(!condition) { |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
991 | return 1; |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
992 | } |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
993 | // add children of condition node |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
994 | if(convert_objconf_directives(pool, file, obj, node->children_begin, condition, condition_index)) { |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
995 | return 1; |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
996 | } |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
997 | |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
998 | // previous condition is used to link "If" "IfElse" and "Else" |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
999 | // if the current node is "Else", the if-else block is complete |
422
76f2f5d532d0
extend serverconfig tokenizer to create separate tokens for brackets
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
420
diff
changeset
|
1000 | // "Client" is unrelated to if-else |
76f2f5d532d0
extend serverconfig tokenizer to create separate tokens for brackets
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
420
diff
changeset
|
1001 | if(!strcmp(node->name.ptr, "If") || !strcmp(node->name.ptr, "ElseIf")) { |
76f2f5d532d0
extend serverconfig tokenizer to create separate tokens for brackets
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
420
diff
changeset
|
1002 | prev_condition = condition; |
76f2f5d532d0
extend serverconfig tokenizer to create separate tokens for brackets
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
420
diff
changeset
|
1003 | } else { |
76f2f5d532d0
extend serverconfig tokenizer to create separate tokens for brackets
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
420
diff
changeset
|
1004 | prev_condition = NULL; |
76f2f5d532d0
extend serverconfig tokenizer to create separate tokens for brackets
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
420
diff
changeset
|
1005 | } |
420
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
1006 | } else if(node->type == CONFIG_NODE_DIRECTIVE) { |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
1007 | directive *d = pool_malloc(pool, sizeof(directive)); |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
1008 | if(!d) return -1; |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
1009 | d->param = pblock_create_pool(pool, 8); |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
1010 | |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
1011 | d->cond = parent_condition; |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
1012 | |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
1013 | // add params |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
1014 | ConfigParam *param = node->args; |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
1015 | while(param != NULL) { |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
1016 | pblock_nvlinsert( |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
1017 | param->name.ptr, |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
1018 | param->name.length, |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
1019 | param->value.ptr, |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
1020 | param->value.length, |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
1021 | d->param); |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
1022 | param = param->next; |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
1023 | } |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
1024 | |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
1025 | // get function |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
1026 | char *func_name = pblock_findval("fn", d->param); |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
1027 | if(!func_name) { |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
1028 | log_ereport(LOG_MISCONFIG, "%s: Missing fn parameter", file); |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
1029 | return -1; |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
1030 | } |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
1031 | d->func = get_function(func_name); |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
1032 | if(!d->func) { |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
1033 | log_ereport(LOG_MISCONFIG, "func %s not found", func_name); |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
1034 | return -1; |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
1035 | } |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
1036 | |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
1037 | // add function to dtable |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
1038 | int dir_type = cfg_get_directive_type_num(cx_strcast(node->name)); |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
1039 | if(dir_type < 0) { |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
1040 | log_ereport(LOG_MISCONFIG, "unknown directive type %s", node->name); |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
1041 | } |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
1042 | object_add_directive(obj, d, dir_type); |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
1043 | |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
1044 | prev_condition = NULL; |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
1045 | } |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
1046 | } |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
1047 | |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
1048 | return 0; |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
1049 | } |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
1050 | |
419
f1d29785ad2d
new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
418
diff
changeset
|
1051 | static int convert_objconf(ServerConfiguration *scfg, ObjectConfig2 *cfg, HTTPObjectConfig *conf, cxmutstr file) { |
255
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1052 | pool_handle_t *pool = conf->pool; |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
1053 | |
420
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
1054 | int condition_index = 0; |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
1055 | |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
1056 | int i = 0; |
419
f1d29785ad2d
new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
418
diff
changeset
|
1057 | for(ConfigNode *objnode=cfg->root->children_begin;objnode;objnode=objnode->next) { |
f1d29785ad2d
new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
418
diff
changeset
|
1058 | if(objnode->type != CONFIG_NODE_OBJECT) { |
420
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
1059 | if(objnode->type == CONFIG_NODE_DIRECTIVE) { |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
1060 | // error |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
1061 | return 1; |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
1062 | } |
419
f1d29785ad2d
new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
418
diff
changeset
|
1063 | continue; |
f1d29785ad2d
new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
418
diff
changeset
|
1064 | } |
f1d29785ad2d
new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
418
diff
changeset
|
1065 | |
420
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
1066 | if(strcmp(objnode->name.ptr, "Object")) { |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
1067 | // error: not an object |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
1068 | return 1; |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
1069 | } |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
1070 | |
74
5bc6d078fb2c
listeners can be dynamically added
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
71
diff
changeset
|
1071 | // get name and ppath |
419
f1d29785ad2d
new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
418
diff
changeset
|
1072 | cxmutstr cfg_name = cfg_param_get(objnode->args, cx_str("name")); |
f1d29785ad2d
new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
418
diff
changeset
|
1073 | cxmutstr cfg_ppath = cfg_param_get(objnode->args, cx_str("ppath")); |
f1d29785ad2d
new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
418
diff
changeset
|
1074 | |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
1075 | char *name = NULL; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
1076 | char *ppath = NULL; |
419
f1d29785ad2d
new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
418
diff
changeset
|
1077 | |
f1d29785ad2d
new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
418
diff
changeset
|
1078 | if(cfg_name.length > 0) { |
f1d29785ad2d
new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
418
diff
changeset
|
1079 | name = cx_strdup_pool(pool, cfg_name).ptr; |
255
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1080 | if(!name) return -1; |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
1081 | } |
419
f1d29785ad2d
new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
418
diff
changeset
|
1082 | if(cfg_ppath.length > 0) { |
f1d29785ad2d
new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
418
diff
changeset
|
1083 | ppath = cx_strdup_pool(pool, cfg_ppath).ptr; |
255
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1084 | if(!ppath) return -1; |
5
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
1085 | } |
419
f1d29785ad2d
new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
418
diff
changeset
|
1086 | |
74
5bc6d078fb2c
listeners can be dynamically added
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
71
diff
changeset
|
1087 | // create and add object |
61
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
1088 | httpd_object *obj = object_new(pool, name); |
255
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1089 | if(!obj) return -1; |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
1090 | obj->path = NULL; |
419
f1d29785ad2d
new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
418
diff
changeset
|
1091 | |
83
28433f06d5ee
added minimal nsapi conditions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
1092 | conf->objects[i] = obj; |
419
f1d29785ad2d
new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
418
diff
changeset
|
1093 | |
74
5bc6d078fb2c
listeners can be dynamically added
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
71
diff
changeset
|
1094 | // add directives |
420
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
1095 | if(convert_objconf_directives(pool, file.ptr, obj, objnode->children_begin, NULL, &condition_index)) { |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
1096 | return 1; |
0b42a35d6add
new recursive function to convert objconf (preparation for nsapi conditions)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
419
diff
changeset
|
1097 | } |
5
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
1098 | |
74
5bc6d078fb2c
listeners can be dynamically added
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
71
diff
changeset
|
1099 | // next |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
1100 | i++; |
5
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
1101 | } |
255
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1102 | |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1103 | return 0; |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1104 | } |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1105 | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
1106 | HTTPObjectConfig* objconf_load(ServerConfiguration *scfg, cxmutstr file) { |
255
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1107 | log_ereport(LOG_VERBOSE, "load_obj_conf"); |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1108 | |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1109 | int ret = 0; |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1110 | |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1111 | // create object config |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1112 | pool_handle_t *pool = scfg->pool; |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1113 | HTTPObjectConfig *conf = pool_calloc(pool, sizeof(HTTPObjectConfig), 1); |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1114 | if(!conf) { |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1115 | return NULL; |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1116 | } |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1117 | conf->pool = pool; |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1118 | |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1119 | // load obj config file |
419
f1d29785ad2d
new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
418
diff
changeset
|
1120 | ObjectConfig2 *cfg = objectconf_load(file.ptr); |
255
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1121 | if(!cfg) { |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1122 | return NULL; |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1123 | } |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1124 | |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1125 | // convert ObjectConfig to HTTPObjectConfig |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1126 | |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1127 | // add objects |
419
f1d29785ad2d
new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
418
diff
changeset
|
1128 | conf->nobj = serverconfig_children_count(cfg->root, CONFIG_NODE_OBJECT); |
255
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1129 | conf->objects = pool_calloc(pool, conf->nobj, sizeof(httpd_object*)); |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1130 | if(conf->objects) { |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1131 | ret = convert_objconf(scfg, cfg, conf, file); |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1132 | } else { |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1133 | ret = -1; |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1134 | } |
5
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
1135 | |
419
f1d29785ad2d
new obj.conf parser based on serverconfig parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
418
diff
changeset
|
1136 | objectconf_free(cfg); |
5
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
1137 | |
255
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1138 | return !ret ? conf : NULL; |
5
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
1139 | } |
39
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
1140 | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
1141 | int mime_conf_load(ServerConfiguration *cfg, cxmutstr file) { |
255
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1142 | MimeConfig *mimecfg = load_mime_config(file.ptr); |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1143 | if(!mimecfg) { |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1144 | return -1; |
39
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
1145 | } |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
1146 | |
255
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1147 | int ret = 0; |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1148 | |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1149 | // cleanup in case of errors is done by the allocator |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
1150 | MimeMap *mimemap = cxMalloc(cfg->a, sizeof(MimeMap)); |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
1151 | CxMap *map = cxHashMapCreate(cfg->a, (mimecfg->ntypes * 3) / 2); |
61
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
1152 | |
255
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1153 | if(mimemap && map) { |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1154 | mimemap->map = map; |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1155 | |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1156 | // add ext type pairs |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
1157 | for(MimeDirective *d=mimecfg->directives_begin;d;d=d->next) { |
255
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1158 | // add the type for each extension to the map |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
1159 | for(int i=0;i<d->nextensions;i++) { |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
1160 | cxstring ext = d->extensions[i]; |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
1161 | cxmutstr value = cx_strdup(cx_strn(d->type.ptr, d->type.length)); |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
1162 | if(cxMapPut(map, cx_hash_key_bytes((const unsigned char *)ext.ptr, ext.length), value.ptr)) { |
392
0aef555055ee
print error in case the log file config doesn't work
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
388
diff
changeset
|
1163 | log_ereport(LOG_CATASTROPHE, "OOM"); |
255
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1164 | ret = -1; |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1165 | break; |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1166 | } |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1167 | } |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1168 | if(ret) { |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1169 | break; |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1170 | } |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1171 | } |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1172 | |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1173 | cfg->mimetypes = mimemap; |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1174 | } else { |
392
0aef555055ee
print error in case the log file config doesn't work
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
388
diff
changeset
|
1175 | log_ereport(LOG_CATASTROPHE, "OOM"); |
255
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1176 | ret = -1; |
61
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
1177 | } |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
1178 | |
79
f48cea237ec3
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
1179 | free_mime_config(mimecfg); |
255
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1180 | return ret; |
61
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
1181 | } |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
1182 | |
255
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1183 | |
61
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
1184 | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
1185 | ACLData* acl_conf_load(ServerConfiguration *cfg, const char *file) { |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
1186 | ACLFile *aclfile = load_acl_file(file); |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
1187 | if(!aclfile) { |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
1188 | log_ereport(LOG_FAILURE, "Cannot load acl file %s", file); |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
1189 | return NULL; |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
1190 | } |
51 | 1191 | |
255
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1192 | // TODO: malloc return checks |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1193 | |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1194 | ACLData *acldata = acl_data_new(cfg->a); |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
1195 | CxIterator iter = cxListIterator(aclfile->namedACLs, 0); |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
1196 | cx_foreach(ACLConfig *, ac, iter) { |
51 | 1197 | ACLList *acl = acl_config_convert(cfg, ac); |
115
51d9a15eac98
improves logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
106
diff
changeset
|
1198 | log_ereport(LOG_VERBOSE, "add acl: %.*s", (int)ac->id.length, ac->id.ptr); |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
1199 | cxMapPut(acldata->namedACLs, cx_hash_key(ac->id.ptr, ac->id.length), acl); |
51 | 1200 | } |
1201 | free_acl_file(aclfile); | |
1202 | ||
255
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1203 | return acldata; |
51 | 1204 | } |
1205 | ||
1206 | ACLList* acl_config_convert(ServerConfiguration *cfg, ACLConfig *acl) { | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
1207 | CxAllocator *a = cfg->a; |
255
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1208 | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
1209 | WSAcl *acllist = cxMalloc(cfg->a, sizeof(WSAcl)); |
54 | 1210 | acllist->acl.check = (acl_check_f)wsacl_check; |
1211 | acllist->acl.authdb = NULL; | |
1212 | acllist->acl.authprompt = NULL; | |
1213 | acllist->acl.isextern = 0; | |
51 | 1214 | acllist->ace = NULL; |
1215 | acllist->ece = NULL; | |
1216 | ||
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
1217 | if(acl->type.ptr && !cx_strcmp(cx_strn(acl->type.ptr, acl->type.length), cx_str("fs"))) { |
63
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
1218 | acllist->acl.isextern = 1; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
1219 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
1220 | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
1221 | size_t s = CFG_ACE_LIST_SIZE(acl->entries); |
255
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1222 | WSAce **tmp_aces = calloc(s, sizeof(WSAce*)); |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1223 | WSAce **tmp_eces = calloc(s, sizeof(WSAce*)); |
51 | 1224 | int ai = 0; |
1225 | int ei = 0; | |
1226 | ||
1227 | // convert entries | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
1228 | for(ACEConfig *acecfg=acl->entries;acecfg;acecfg=acecfg->next) { |
51 | 1229 | // copy data |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
1230 | WSAce *ace = cxMalloc(a, sizeof(WSAce)); |
51 | 1231 | ace->access_mask = acecfg->access_mask; |
1232 | ace->flags = acecfg->flags; | |
1233 | ace->type = acecfg->type; | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
1234 | ace->who = cx_strdup_a(a, cx_strcast(acecfg->who)).ptr; |
51 | 1235 | |
1236 | // add the entry to the correct array | |
1237 | if(ace->type >= ACL_TYPE_AUDIT) { | |
255
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1238 | tmp_eces[ei] = ace; |
51 | 1239 | ei++; |
1240 | } else { | |
255
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1241 | tmp_aces[ai] = ace; |
51 | 1242 | ai++; |
1243 | } | |
1244 | } | |
1245 | ||
1246 | // create new entrie arrays with perfect fitting size | |
1247 | if(ai > 0) { | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
1248 | acllist->ace = cxCalloc(a, ai, sizeof(WSAce*)); |
51 | 1249 | } |
1250 | if(ei > 0) { | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
1251 | acllist->ece = cxCalloc(a, ei, sizeof(WSAce*)); |
51 | 1252 | } |
255
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1253 | memcpy(acllist->ace, tmp_aces, ai*sizeof(WSAce*)); |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1254 | memcpy(acllist->ece, tmp_eces, ei*sizeof(WSAce*)); |
51 | 1255 | acllist->acenum = ai; |
1256 | acllist->ecenum = ei; | |
1257 | ||
255
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1258 | free(tmp_aces); |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1259 | free(tmp_eces); |
51 | 1260 | |
1261 | // get authentication information | |
1262 | if(acl->authparam) { | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
1263 | cxmutstr authdb_str = cfg_param_get(acl->authparam, cx_str("authdb")); |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
1264 | cxmutstr prompt_str = cfg_param_get(acl->authparam, cx_str("prompt")); |
51 | 1265 | |
1266 | if(authdb_str.ptr) { | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
1267 | AuthDB *authdb = cxMapGet(cfg->authdbs, cx_hash_key(authdb_str.ptr, authdb_str.length)); |
54 | 1268 | acllist->acl.authdb = authdb; |
51 | 1269 | if(authdb && prompt_str.ptr) { |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
1270 | acllist->acl.authprompt = cx_strdup_a(a, cx_strcast(prompt_str)).ptr; |
51 | 1271 | } |
1272 | } | |
1273 | } | |
1274 | ||
54 | 1275 | return &acllist->acl; |
51 | 1276 | } |
62
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
1277 | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
1278 | AuthDB* keyfile_load(ServerConfiguration *cfg, cxstring file) { |
255
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1279 | Keyfile *keyfile = keyfile_new(cfg->a); |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1280 | if(!keyfile) { |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1281 | return NULL; |
62
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
1282 | } |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
1283 | |
255
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1284 | KeyfileConfig *conf = load_keyfile_config(file.ptr); |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1285 | if(!conf) { |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1286 | return NULL; |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1287 | } |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1288 | |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1289 | AuthDB *ret = &keyfile->authdb; |
62
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
1290 | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
1291 | for(KeyfileEntry *user=conf->users_begin;user;user=user->next) { |
255
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1292 | if(keyfile_add_user( |
62
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
1293 | keyfile, |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
1294 | user->name, |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
1295 | user->hashtype, |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
1296 | user->hashdata, |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
1297 | user->groups, |
255
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1298 | user->numgroups)) |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1299 | { |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1300 | ret = NULL; |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1301 | break; |
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1302 | } |
62
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
1303 | } |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
1304 | |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
1305 | free_keyfile_config(conf); |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
1306 | |
255
b5d15a4a19f5
refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
1307 | return ret; |
62
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
1308 | } |
269
3dfbd0b91950
add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
260
diff
changeset
|
1309 | |
3dfbd0b91950
add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
260
diff
changeset
|
1310 | pblock* config_obj2pblock(pool_handle_t *pool, ConfigNode *obj) { |
3dfbd0b91950
add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
260
diff
changeset
|
1311 | pblock *pb = pblock_create_pool(pool, 8); |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
1312 | for(ConfigNode *d=obj->children_begin;d;d=d->next) { |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
1313 | if(d->type == CONFIG_NODE_DIRECTIVE && d->name.length > 0 && CFG_NUM_PARAMS(d->args) == 1) { |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
409
diff
changeset
|
1314 | ConfigParam *arg = d->args; |
269
3dfbd0b91950
add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
260
diff
changeset
|
1315 | pblock_nvlinsert(d->name.ptr, d->name.length, arg->value.ptr, arg->value.length, pb); |
3dfbd0b91950
add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
260
diff
changeset
|
1316 | } |
3dfbd0b91950
add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
260
diff
changeset
|
1317 | } |
3dfbd0b91950
add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
260
diff
changeset
|
1318 | return pb; |
3dfbd0b91950
add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
260
diff
changeset
|
1319 | } |