Tue, 01 Jan 2013 14:02:25 +0100
fixed solaris build
1 | 1 | /* |
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. | |
3 | * | |
4 | * Copyright 2011 Olaf Wintermann. All rights reserved. | |
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> |
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
38 | #include <sys/mman.h> |
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
39 | |
15
cff9c4101dd7
Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
40 | #include "../ucx/string.h" |
5
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
41 | |
1 | 42 | #include "httplistener.h" |
18
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
43 | #include "config.h" |
5
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
44 | #include "func.h" |
28 | 45 | #include "log.h" |
30
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
46 | #include "event.h" |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
47 | #include "threadpools.h" |
38
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
48 | #include "ldap_auth.h" |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
49 | #include "configmanager.h" |
1 | 50 | |
3
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
51 | #include "vserver.h" |
14
b8bf95b39952
New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
52 | #include "../util/pblock.h" |
30
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
53 | #include "../util/util.h" |
41
bb7a1f5a8b48
added Linux support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
54 | #include "../util/atomic.h" |
3
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
55 | |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
56 | pool_handle_t *cfg_pool; |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
57 | |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
58 | // TODO: Funktion für ConfigDirective -> directive |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
59 | // TODO: Funktion für UcxList parameter list -> pblock |
18
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
60 | |
1 | 61 | void load_init_conf(char *file) { |
62 | printf("load_init_conf\n"); | |
13
1fdbf4170ef4
Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
63 | |
19
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
64 | InitConfig *cfg = load_init_config(file); |
38
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
65 | UcxMempool *mp = cfg->parser.mp; |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
66 | if(cfg == NULL) { |
13
1fdbf4170ef4
Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
67 | return; |
1fdbf4170ef4
Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
68 | } |
1fdbf4170ef4
Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
69 | |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
70 | cfg_pool = pool_create(); // one pool for one Configuration |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
71 | UcxDlist *dirs = cfg->directives; |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
72 | while(dirs != NULL) { |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
73 | ConfigDirective *dir = dirs->data; |
13
1fdbf4170ef4
Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
74 | |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
75 | /* create NSAPI directive */ |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
76 | directive *d = malloc(sizeof(directive)); |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
77 | d->param = pblock_create_pool(cfg_pool, 8); |
38
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
78 | UcxList *param = cfg_param_list(dir->value, mp); |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
79 | while(param != NULL) { |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
80 | ConfigParam *p = param->data; |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
81 | pblock_nvlinsert( |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
82 | p->name.ptr, |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
83 | p->name.length, |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
84 | p->value.ptr, |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
85 | p->value.length, |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
86 | d->param); |
20
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
87 | |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
88 | param = param->next; |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
89 | } |
13
1fdbf4170ef4
Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
90 | |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
91 | /* get function */ |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
92 | char *func_name = pblock_findval("fn", d->param); |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
93 | d->func = get_function(func_name); |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
94 | if(d->func == NULL) { |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
95 | free(d); |
20
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
96 | dirs = dirs->next; |
13
1fdbf4170ef4
Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
97 | continue; |
1fdbf4170ef4
Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
98 | } |
1fdbf4170ef4
Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
99 | |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
100 | /* execute init directive */ |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
101 | d->func->func(d->param, NULL, NULL); |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
102 | |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
103 | dirs = dirs->next; |
13
1fdbf4170ef4
Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
104 | } |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
105 | |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
106 | free_init_config(cfg); |
1 | 107 | } |
108 | ||
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
109 | ServerConfiguration* load_server_conf(ServerConfiguration *old, char *file) { |
1 | 110 | printf("load_server_conf\n"); |
18
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
111 | |
19
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
112 | ServerConfig *serverconf = load_server_config(file); |
18
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
113 | if(serverconf == NULL) { |
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
114 | fprintf(stderr, "Cannot load server.conf\n"); |
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
115 | } |
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
116 | ServerConfiguration *serverconfig = malloc(sizeof(ServerConfiguration)); |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
117 | serverconfig->ref = 1; |
19
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
118 | serverconfig->pool = pool_create(); |
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
119 | serverconfig->listeners = NULL; |
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
120 | serverconfig->host_vs = ucx_map_new(16); |
38
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
121 | serverconfig->authdbs = ucx_map_new(16); |
18
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
122 | // TODO: init serverconfig stuff |
29
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
123 | |
33
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
124 | |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
125 | /* |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
126 | * convert ServerConfig to ServerConfiguration |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
127 | * |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
128 | * its important to do this in the correct order: |
37
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
129 | * LogFile (open log file first to log possible errors) |
33
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
130 | * Runtime |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
131 | * Threadpool |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
132 | * EventHandler |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
133 | * AuthDB |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
134 | * Listener (we set the VirtualServer later) |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
135 | * VirtualServer (dependencies: Listener) |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
136 | */ |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
137 | |
29
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
138 | /* init logfile first */ |
33
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
139 | UcxList *lfl = ucx_map_sstr_get(serverconf->objects, sstrn("LogFile", 7)); |
29
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
140 | if(lfl != NULL) { |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
141 | ServerConfigObject *logobj = lfl->data; |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
142 | if(logobj == NULL) { |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
143 | /* error */ |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
144 | return NULL; |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
145 | } |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
146 | |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
147 | int ret = cfg_handle_logfile(serverconfig, logobj); |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
148 | if(ret != 0) { |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
149 | /* cannot initialize log file */ |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
150 | return NULL; |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
151 | } |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
152 | } else { |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
153 | /* horrible error */ |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
154 | return NULL; |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
155 | } |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
156 | |
33
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
157 | UcxList *list = ucx_map_sstr_get(serverconf->objects, sstrn("Runtime", 7)); |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
158 | UCX_FOREACH(UcxList*, list, elm) { |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
159 | ServerConfigObject *scfgobj = elm->data; |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
160 | cfg_handle_runtime(serverconfig, scfgobj); |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
161 | } |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
162 | |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
163 | list = ucx_map_sstr_get(serverconf->objects, sstrn("Threadpool", 10)); |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
164 | UCX_FOREACH(UcxList*, list, elm) { |
37
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
165 | cfg_handle_threadpool(serverconfig, elm->data); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
166 | } |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
167 | // check thread pool config |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
168 | if(check_thread_pool_cfg() != 0) { |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
169 | /* critical error */ |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
170 | return NULL; |
33
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
171 | } |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
172 | |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
173 | list = ucx_map_sstr_get(serverconf->objects, sstrn("EventHandler", 12)); |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
174 | UCX_FOREACH(UcxList*, list, elm) { |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
175 | cfg_handle_eventhandler(serverconfig, (ServerConfigObject*)elm->data); |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
176 | } |
37
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
177 | // check event handler config |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
178 | if(check_event_handler_cfg() != 0) { |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
179 | /* critical error */ |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
180 | return NULL; |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
181 | } |
33
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
182 | |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
183 | list = ucx_map_sstr_get(serverconf->objects, sstrn("AuthDB", 6)); |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
184 | UCX_FOREACH(UcxList*, list, elm) { |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
185 | ServerConfigObject *scfgobj = elm->data; |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
186 | cfg_handle_authdb(serverconfig, scfgobj); |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
187 | } |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
188 | |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
189 | list = ucx_map_sstr_get(serverconf->objects, sstrn("Listener", 8)); |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
190 | UCX_FOREACH(UcxList*, list, elm) { |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
191 | ServerConfigObject *scfgobj = elm->data; |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
192 | cfg_handle_listener(serverconfig, scfgobj); |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
193 | } |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
194 | |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
195 | list = ucx_map_sstr_get(serverconf->objects, sstrn("VirtualServer", 13)); |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
196 | UCX_FOREACH(UcxList*, list, elm) { |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
197 | ServerConfigObject *scfgobj = elm->data; |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
198 | cfg_handle_vs(serverconfig, scfgobj); |
18
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
199 | } |
30
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
200 | |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
201 | |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
202 | // set VirtualServer for all listeners |
19
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
203 | UcxList *ls = serverconfig->listeners; |
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
204 | while(ls) { |
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
205 | HttpListener *listener = ls->data; |
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
206 | |
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
207 | sstr_t vsname = sstr(listener->default_vs.vs_name); |
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
208 | |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
209 | // search for VirtualServer |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
210 | //int b = 0; |
33
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
211 | UcxMapIterator iter = ucx_map_iterator(serverconfig->host_vs); |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
212 | VirtualServer *vs; |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
213 | UCX_MAP_FOREACH(vs, iter) { |
31 | 214 | if(!sstrcmp(vsname, vs->name)) { |
215 | listener->default_vs.vs = vs; | |
19
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
216 | break; |
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
217 | } |
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
218 | } |
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
219 | |
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
220 | ls = ls->next; |
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
221 | } |
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
222 | |
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
223 | return serverconfig; |
1 | 224 | } |
3
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
225 | |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
226 | void cfg_ref(ServerConfiguration *cfg) { |
41
bb7a1f5a8b48
added Linux support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
227 | ws_atomic_inc32(&cfg->ref); |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
228 | } |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
229 | |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
230 | void cfg_unref(ServerConfiguration *cfg) { |
41
bb7a1f5a8b48
added Linux support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
231 | uint32_t ref = ws_atomic_dec32(&cfg->ref); |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
232 | if(ref == 0) { |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
233 | // TODO: free configuration |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
234 | } |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
235 | } |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
236 | |
19
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
237 | |
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
238 | void init_server_config_parser() { |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
239 | |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
240 | } |
18
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
241 | |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
242 | int cfg_handle_runtime(ServerConfiguration *cfg, ServerConfigObject *obj) { |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
243 | cfg->user = sstrdup(cfg_directivelist_get_str( |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
244 | obj->directives, |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
245 | sstr("User"))); |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
246 | cfg->tmp = sstrdup(cfg_directivelist_get_str( |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
247 | obj->directives, |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
248 | sstr("Temp"))); |
39
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
249 | |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
250 | // mime file |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
251 | sstr_t mf = cfg_directivelist_get_str(obj->directives, sstr("MimeFile")); |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
252 | |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
253 | sstr_t base = sstr("config/"); |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
254 | sstr_t file; |
41
bb7a1f5a8b48
added Linux support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
255 | file.length = base.length + mf.length; |
bb7a1f5a8b48
added Linux support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
256 | file.ptr = alloca(file.length + 1); |
39
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
257 | file.ptr[file.length] = 0; |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
258 | file = sstrncat(2, file, base, mf); |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
259 | |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
260 | ConfigFile *f = cfgmgr_get_file(file); |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
261 | if(f == NULL) { |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
262 | f = malloc(sizeof(ConfigFile)); |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
263 | f->file = sstrdup(file); |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
264 | f->reload = mime_conf_reload; |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
265 | |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
266 | // load the file content |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
267 | f->reload(f, cfg); |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
268 | cfgmgr_attach_file(f); |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
269 | } |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
270 | |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
271 | cfg->mimetypes = f->data; // TODO: ref |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
272 | |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
273 | return 0; |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
274 | } |
19
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
275 | |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
276 | int cfg_handle_logfile(ServerConfiguration *cfg, ServerConfigObject *obj) { |
28 | 277 | sstr_t file = cfg_directivelist_get_str(obj->directives, sstr("File")); |
278 | sstr_t lvl = cfg_directivelist_get_str(obj->directives, sstr("Level")); | |
279 | ||
280 | if(file.ptr == NULL || lvl.ptr == NULL) { | |
281 | /* missing log file parameters */ | |
282 | return -1; | |
283 | } | |
284 | ||
285 | LogConfig logcfg; | |
286 | logcfg.file = sstrdup(file).ptr; | |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
287 | logcfg.level = sstrdup(lvl).ptr; |
28 | 288 | /* TODO: stdout, stderr config */ |
289 | ||
290 | int ret = init_log_file(&logcfg); | |
291 | ||
292 | free(logcfg.file); | |
293 | free(logcfg.level); | |
19
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
294 | |
28 | 295 | return ret; |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
296 | } |
19
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
297 | |
37
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
298 | int cfg_handle_threadpool(ServerConfiguration *cfg, ServerConfigObject *obj) { |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
299 | ThreadPoolConfig poolcfg; |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
300 | poolcfg.min_threads = 4; |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
301 | poolcfg.min_threads = 4; |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
302 | poolcfg.max_threads = 8; |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
303 | poolcfg.queue_size = 64; |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
304 | poolcfg.stack_size = 262144; |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
305 | |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
306 | sstr_t name = cfg_directivelist_get_str( |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
307 | obj->directives, |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
308 | sstr("Name")); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
309 | sstr_t min = cfg_directivelist_get_str( |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
310 | obj->directives, |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
311 | sstr("MinThreads")); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
312 | sstr_t max = cfg_directivelist_get_str( |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
313 | obj->directives, |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
314 | sstr("MaxThreads")); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
315 | sstr_t stack = cfg_directivelist_get_str( |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
316 | obj->directives, |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
317 | sstr("StackSize")); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
318 | sstr_t queue = cfg_directivelist_get_str( |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
319 | obj->directives, |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
320 | sstr("QueueSize")); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
321 | // TODO: Type |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
322 | |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
323 | if(name.length == 0) { |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
324 | // TODO: log error |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
325 | return 1; |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
326 | } |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
327 | |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
328 | if(min.length != 0) { |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
329 | min = sstrdup(min); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
330 | poolcfg.min_threads = atoi(min.ptr); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
331 | free(min.ptr); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
332 | } |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
333 | |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
334 | if(max.length != 0) { |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
335 | max = sstrdup(max); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
336 | poolcfg.max_threads = atoi(max.ptr); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
337 | free(max.ptr); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
338 | } |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
339 | |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
340 | if(stack.length != 0) { |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
341 | stack = sstrdup(stack); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
342 | poolcfg.stack_size = atoi(stack.ptr); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
343 | free(stack.ptr); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
344 | } |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
345 | |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
346 | if(queue.length != 0) { |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
347 | queue = sstrdup(queue); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
348 | poolcfg.queue_size = atoi(queue.ptr); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
349 | free(queue.ptr); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
350 | } |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
351 | |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
352 | create_threadpool(name, &poolcfg); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
353 | } |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
354 | |
30
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
355 | int cfg_handle_eventhandler(ServerConfiguration *c, ServerConfigObject *obj) { |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
356 | EventHandlerConfig evcfg; |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
357 | |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
358 | sstr_t name = cfg_directivelist_get_str(obj->directives, sstr("Name")); |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
359 | sstr_t threads = cfg_directivelist_get_str( |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
360 | obj->directives, |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
361 | sstr("Threads")); |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
362 | sstr_t isdefault = cfg_directivelist_get_str( |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
363 | obj->directives, |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
364 | sstr("Default")); |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
365 | |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
366 | evcfg.name = name; |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
367 | |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
368 | sstr_t s = sstrdup(threads); |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
369 | evcfg.nthreads = atoi(s.ptr); |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
370 | free(s.ptr); |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
371 | |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
372 | evcfg.isdefault = util_getboolean(isdefault.ptr, 0); |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
373 | |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
374 | int ret = create_event_handler(&evcfg); |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
375 | |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
376 | return ret; |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
377 | } |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
378 | |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
379 | int cfg_handle_authdb(ServerConfiguration *cfg, ServerConfigObject *obj) { |
38
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
380 | sstr_t name = cfg_directivelist_get_str(obj->directives, sstr("Name")); |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
381 | sstr_t type = cfg_directivelist_get_str(obj->directives, sstr("Type")); |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
382 | |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
383 | if(!sstrcmp(type, sstr("ldap"))) { |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
384 | LDAPConfig conf; |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
385 | |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
386 | sstr_t host = cfg_directivelist_get_str( |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
387 | obj->directives, |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
388 | sstr("Host")); |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
389 | sstr_t port = cfg_directivelist_get_str( |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
390 | obj->directives, |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
391 | sstr("Port")); |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
392 | sstr_t basedn = cfg_directivelist_get_str( |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
393 | obj->directives, |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
394 | sstr("BaseDN")); |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
395 | sstr_t binddn = cfg_directivelist_get_str( |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
396 | obj->directives, |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
397 | sstr("BindDN")); |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
398 | sstr_t basepw = cfg_directivelist_get_str( |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
399 | obj->directives, |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
400 | sstr("BindPW")); |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
401 | |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
402 | host = sstrdup(host); |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
403 | port = sstrdup(port); |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
404 | basedn = sstrdup(basedn); |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
405 | binddn = sstrdup(binddn); |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
406 | basepw = sstrdup(basepw); |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
407 | |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
408 | conf.hostname = host.ptr; |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
409 | conf.port = atoi(port.ptr); |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
410 | conf.basedn = basedn.ptr; |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
411 | conf.binddn = binddn.ptr; |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
412 | conf.bindpw = basepw.ptr; |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
413 | |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
414 | name = sstrdup(name); |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
415 | |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
416 | AuthDB *authdb = create_ldap_authdb(name.ptr, &conf); |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
417 | printf("authdb: %d\n", authdb); |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
418 | ucx_map_sstr_put(cfg->authdbs, name, authdb); |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
419 | |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
420 | // TODO: create_ldap_authdb should copy the strings |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
421 | /* |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
422 | free(host.ptr); |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
423 | free(port.ptr); |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
424 | free(basedn.ptr); |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
425 | free(binddn.ptr); |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
426 | free(basepw.ptr); |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
427 | free(name.ptr); |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
428 | */ |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
429 | |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
430 | } |
19
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
431 | |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
432 | return 0; |
18
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
433 | } |
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
434 | |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
435 | int cfg_handle_listener(ServerConfiguration *cfg, ServerConfigObject *obj) { |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
436 | ListenerConfig lc; |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
437 | lc.cfg = cfg; |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
438 | lc.port = 8080; |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
439 | lc.nacceptors = 1; |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
440 | |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
441 | // TODO: use sstrdup_pool? |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
442 | lc.name = sstrdup(cfg_directivelist_get_str( |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
443 | obj->directives, |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
444 | sstr("Name"))); |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
445 | lc.port = atoi(cfg_directivelist_get_str( |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
446 | obj->directives, |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
447 | sstr("Port")).ptr); |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
448 | lc.vs = sstrdup(cfg_directivelist_get_str( |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
449 | obj->directives, |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
450 | sstr("DefaultVS"))); |
37
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
451 | lc.threadpool = sstrdup(cfg_directivelist_get_str( |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
452 | obj->directives, |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
453 | sstr("Threadpool"))); |
18
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
454 | |
37
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
455 | // TODO: check if all important configs are set |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
456 | |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
457 | HttpListener *listener = http_listener_create(&lc); |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
458 | listener->default_vs.vs_name = lc.vs.ptr; |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
459 | cfg->listeners = ucx_list_append(cfg->listeners, listener); |
37
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
460 | |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
461 | return 0; |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
462 | } |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
463 | |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
464 | int cfg_handle_vs(ServerConfiguration *cfg, ServerConfigObject *obj) { |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
465 | VirtualServer *vs = vs_new(); |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
466 | |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
467 | vs->name = sstrdup(cfg_directivelist_get_str( |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
468 | obj->directives, |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
469 | sstr("Name"))); |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
470 | vs->host = sstrdup(cfg_directivelist_get_str( |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
471 | obj->directives, |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
472 | sstr("Host"))); |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
473 | vs->document_root = sstrdup(cfg_directivelist_get_str( |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
474 | obj->directives, |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
475 | sstr("DocRoot"))); |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
476 | sstr_t objfile = cfg_directivelist_get_str( |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
477 | obj->directives, |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
478 | sstr("ObjectFile")); |
39
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
479 | sstr_t base = sstr("config/"); |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
480 | sstr_t file; |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
481 | file.length = base.length + objfile.length + 1; |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
482 | file.ptr = alloca(file.length); |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
483 | file.ptr[file.length] = 0; |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
484 | file = sstrncat(2, file, base, objfile); |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
485 | |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
486 | ConfigFile *f = cfgmgr_get_file(file); |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
487 | if(f == NULL) { |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
488 | f = malloc(sizeof(ConfigFile)); |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
489 | f->file = sstrdup(file); |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
490 | f->reload = object_conf_reload; |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
491 | f->reload(f, cfg); |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
492 | cfgmgr_attach_file(f); |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
493 | } |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
494 | vs->objectfile = sstrdup(file); // TODO: pool |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
495 | vs->objects = (HTTPObjectConfig*)f->data; // TODO: ref |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
496 | |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
497 | ucx_map_sstr_put(cfg->host_vs, vs->host, vs); |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
498 | |
18
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
499 | return 0; |
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
500 | } |
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
501 | |
19
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
502 | |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
503 | int object_conf_reload(ConfigFile *file, ServerConfiguration *cfg) { |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
504 | file->data = load_obj_conf(file->file.ptr); |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
505 | struct stat s; |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
506 | if(stat(file->file.ptr, &s) != 0) { |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
507 | perror("object_conf_reload: stat"); |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
508 | return -1; |
19
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
509 | } |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
510 | file->last_modified = s.st_mtim.tv_sec; |
25
5dee29c7c530
Fixed config parser bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
511 | return 0; |
3
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
512 | } |
5
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
513 | |
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
514 | HTTPObjectConfig* load_obj_conf(char *file) { |
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
515 | printf("load_obj_conf\n"); |
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
516 | |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
517 | // new conf function test |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
518 | ObjectConfig *cfg = load_object_config(file); |
38
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
519 | UcxMempool *mp = cfg->parser.mp; |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
520 | if(cfg == NULL) { |
5
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
521 | return NULL; |
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
522 | } |
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
523 | |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
524 | /* create object config */ |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
525 | HTTPObjectConfig *conf = calloc(sizeof(HTTPObjectConfig), 1); |
19
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
526 | conf->pool = pool_create(); |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
527 | |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
528 | /* convert ObjectConfig to HTTPObjectConfig */ |
5
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
529 | |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
530 | /* add objects */ |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
531 | conf->nobj = ucx_dlist_size(cfg->objects); |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
532 | conf->objects = calloc(1, sizeof(httpd_object*)); |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
533 | |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
534 | UcxDlist *objlist = cfg->objects; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
535 | int i = 0; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
536 | while(objlist != NULL) { |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
537 | ConfigObject *cob = objlist->data; |
5
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
538 | |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
539 | /* get name and ppath */ |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
540 | char *name = NULL; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
541 | char *ppath = NULL; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
542 | if(cob->name.length > 0) { |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
543 | name = sstrdup(cob->name).ptr; |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
544 | } |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
545 | if(cob->ppath.length > 0) { |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
546 | ppath = sstrdup(cob->ppath).ptr; |
5
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
547 | } |
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
548 | |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
549 | /* create and add object */ |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
550 | httpd_object *obj = object_new(name); |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
551 | obj->path = NULL; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
552 | |
25
5dee29c7c530
Fixed config parser bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
553 | conf->objects[i] = obj; // TODO: beyond array bounds write |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
554 | |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
555 | /* add directives */ |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
556 | for(int i=0;i<6;i++) { |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
557 | UcxDlist *dirs = cob->directives[i]; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
558 | while(dirs != NULL) { |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
559 | ConfigDirective *cfgdir = dirs->data; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
560 | |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
561 | directive *d = malloc(sizeof(directive)); |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
562 | d->cond = NULL; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
563 | d->param = pblock_create_pool(conf->pool, 8); |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
564 | |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
565 | /* add params */ |
38
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
566 | UcxList *param = cfg_param_list(cfgdir->value, mp); |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
567 | while(param != NULL) { |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
568 | ConfigParam *p = param->data; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
569 | pblock_nvlinsert( |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
570 | p->name.ptr, |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
571 | p->name.length, |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
572 | p->value.ptr, |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
573 | p->value.length, |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
574 | d->param); |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
575 | param = param->next; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
576 | } |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
577 | |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
578 | /* get function */ |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
579 | char *func_name = pblock_findval("fn", d->param); |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
580 | d->func = get_function(func_name); |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
581 | |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
582 | dirs = dirs->next; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
583 | |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
584 | /* add function to dtable */ |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
585 | object_add_directive(obj, d, cfgdir->type_num); |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
586 | } |
5
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
587 | } |
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
588 | |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
589 | /* next */ |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
590 | i++; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
591 | objlist = objlist->next; |
5
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
592 | } |
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
593 | |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
594 | free_object_config(cfg); |
5
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
595 | |
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
596 | return conf; |
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
597 | } |
39
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
598 | |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
599 | int mime_conf_reload(ConfigFile *file, ServerConfiguration *cfg) { |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
600 | MimeConfig *mimecfg = load_mime_config(file->file.ptr); |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
601 | |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
602 | UcxMap *mimemap = ucx_map_new((mimecfg->ntypes * 3) / 2); |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
603 | |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
604 | // add ext type pairs |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
605 | UCX_FOREACH(UcxList*, mimecfg->directives, md) { |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
606 | MimeDirective *d = md->data; |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
607 | // add the type for each extension to the map |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
608 | UCX_FOREACH(UcxList*, d->exts, xl) { |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
609 | sstr_t ext = sstr(xl->data); |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
610 | sstr_t value = sstrdup(d->type); |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
611 | ucx_map_sstr_put(mimemap, ext, value.ptr); |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
612 | } |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
613 | } |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
614 | |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
615 | file->data = mimemap; |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
616 | return 0; |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
617 | } |