Sat, 18 Aug 2012 11:39:34 +0200
using non blocking IO for request input
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" |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
48 | #include "configmanager.h" |
1 | 49 | |
3
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
50 | #include "vserver.h" |
14
b8bf95b39952
New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
51 | #include "../util/pblock.h" |
30
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
52 | #include "../util/util.h" |
3
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
53 | |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
54 | pool_handle_t *cfg_pool; |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
55 | |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
56 | // TODO: Funktion für ConfigDirective -> directive |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
57 | // TODO: Funktion für UcxList parameter list -> pblock |
18
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
58 | |
1 | 59 | void load_init_conf(char *file) { |
60 | printf("load_init_conf\n"); | |
13
1fdbf4170ef4
Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
61 | |
19
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
62 | InitConfig *cfg = load_init_config(file); |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
63 | if(cfg == NULL) { |
13
1fdbf4170ef4
Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
64 | return; |
1fdbf4170ef4
Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
65 | } |
1fdbf4170ef4
Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
66 | |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
67 | cfg_pool = pool_create(); // one pool for one Configuration |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
68 | UcxDlist *dirs = cfg->directives; |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
69 | while(dirs != NULL) { |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
70 | ConfigDirective *dir = dirs->data; |
13
1fdbf4170ef4
Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
71 | |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
72 | /* create NSAPI directive */ |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
73 | directive *d = malloc(sizeof(directive)); |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
74 | d->param = pblock_create_pool(cfg_pool, 8); |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
75 | UcxList *param = dir->param; |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
76 | while(param != NULL) { |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
77 | ConfigParam *p = param->data; |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
78 | pblock_nvlinsert( |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
79 | p->name.ptr, |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
80 | p->name.length, |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
81 | p->value.ptr, |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
82 | p->value.length, |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
83 | d->param); |
20
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
84 | |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
85 | param = param->next; |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
86 | } |
13
1fdbf4170ef4
Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
87 | |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
88 | /* get function */ |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
89 | char *func_name = pblock_findval("fn", d->param); |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
90 | d->func = get_function(func_name); |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
91 | if(d->func == NULL) { |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
92 | free(d); |
20
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
93 | dirs = dirs->next; |
13
1fdbf4170ef4
Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
94 | continue; |
1fdbf4170ef4
Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
95 | } |
1fdbf4170ef4
Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
96 | |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
97 | /* execute init directive */ |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
98 | d->func->func(d->param, NULL, NULL); |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
99 | |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
100 | dirs = dirs->next; |
13
1fdbf4170ef4
Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
101 | } |
17
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 | free_init_config(cfg); |
1 | 104 | } |
105 | ||
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
106 | ServerConfiguration* load_server_conf(ServerConfiguration *old, char *file) { |
1 | 107 | printf("load_server_conf\n"); |
18
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
108 | |
19
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
109 | ServerConfig *serverconf = load_server_config(file); |
18
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
110 | if(serverconf == NULL) { |
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
111 | fprintf(stderr, "Cannot load server.conf\n"); |
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
112 | } |
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
113 | ServerConfiguration *serverconfig = malloc(sizeof(ServerConfiguration)); |
19
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
114 | serverconfig->pool = pool_create(); |
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
115 | serverconfig->listeners = NULL; |
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
116 | serverconfig->host_vs = ucx_map_new(16); |
18
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
117 | // TODO: init serverconfig stuff |
29
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
118 | |
33
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
119 | |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
120 | /* |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
121 | * convert ServerConfig to ServerConfiguration |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
122 | * |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
123 | * its important to do this in the correct order: |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
124 | * LogFile (we want an open log file first to log possible errors) |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
125 | * Runtime |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
126 | * Threadpool |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
127 | * EventHandler |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
128 | * AuthDB |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
129 | * Listener (we set the VirtualServer later) |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
130 | * VirtualServer (dependencies: Listener) |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
131 | */ |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
132 | |
29
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
133 | /* init logfile first */ |
33
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
134 | 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
|
135 | if(lfl != NULL) { |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
136 | ServerConfigObject *logobj = lfl->data; |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
137 | if(logobj == NULL) { |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
138 | /* error */ |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
139 | return NULL; |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
140 | } |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
141 | |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
142 | int ret = cfg_handle_logfile(serverconfig, logobj); |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
143 | if(ret != 0) { |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
144 | /* cannot initialize log file */ |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
145 | return NULL; |
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 | } else { |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
148 | /* horrible error */ |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
149 | return NULL; |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
150 | } |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
151 | |
33
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
152 | 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
|
153 | UCX_FOREACH(UcxList*, list, elm) { |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
154 | ServerConfigObject *scfgobj = elm->data; |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
155 | cfg_handle_runtime(serverconfig, scfgobj); |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
156 | } |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
157 | |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
158 | list = ucx_map_sstr_get(serverconf->objects, sstrn("Threadpool", 10)); |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
159 | UCX_FOREACH(UcxList*, list, elm) { |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
160 | ServerConfigObject *scfgobj = elm->data; |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
161 | // TODO: threadpool |
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 | |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
164 | list = ucx_map_sstr_get(serverconf->objects, sstrn("EventHandler", 12)); |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
165 | UCX_FOREACH(UcxList*, list, elm) { |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
166 | cfg_handle_eventhandler(serverconfig, (ServerConfigObject*)elm->data); |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
167 | } |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
168 | |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
169 | list = ucx_map_sstr_get(serverconf->objects, sstrn("AuthDB", 6)); |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
170 | UCX_FOREACH(UcxList*, list, elm) { |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
171 | ServerConfigObject *scfgobj = elm->data; |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
172 | cfg_handle_authdb(serverconfig, scfgobj); |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
173 | } |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
174 | |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
175 | list = ucx_map_sstr_get(serverconf->objects, sstrn("Listener", 8)); |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
176 | UCX_FOREACH(UcxList*, list, elm) { |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
177 | ServerConfigObject *scfgobj = elm->data; |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
178 | cfg_handle_listener(serverconfig, scfgobj); |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
179 | } |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
180 | |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
181 | list = ucx_map_sstr_get(serverconf->objects, sstrn("VirtualServer", 13)); |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
182 | UCX_FOREACH(UcxList*, list, elm) { |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
183 | ServerConfigObject *scfgobj = elm->data; |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
184 | cfg_handle_vs(serverconfig, scfgobj); |
18
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
185 | } |
19
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
186 | |
30
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
187 | /* check event handler config */ |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
188 | if(check_event_handler_cfg() != 0) { |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
189 | /* critical error */ |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
190 | return NULL; |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
191 | } |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
192 | |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
193 | /* check thread pool config */ |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
194 | if(check_thread_pool_cfg() != 0) { |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
195 | /* critical error */ |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
196 | return NULL; |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
197 | } |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
198 | |
19
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
199 | /* set VirtualServer for all listeners */ |
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
200 | UcxList *ls = serverconfig->listeners; |
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
201 | while(ls) { |
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
202 | HttpListener *listener = ls->data; |
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
203 | |
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
204 | sstr_t vsname = sstr(listener->default_vs.vs_name); |
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
205 | |
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
206 | /* search for VirtualServer */ |
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
207 | int b = 0; |
33
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
208 | UcxMapIterator iter = ucx_map_iterator(serverconfig->host_vs); |
31 | 209 | UCX_MAP_FOREACH(VirtualServer*, vs, serverconfig->host_vs, iter) { |
210 | if(!sstrcmp(vsname, vs->name)) { | |
211 | listener->default_vs.vs = vs; | |
19
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
212 | break; |
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
213 | } |
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
214 | } |
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
215 | |
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
216 | ls = ls->next; |
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 | return serverconfig; |
1 | 220 | } |
3
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
221 | |
19
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 | void init_server_config_parser() { |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
224 | |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
225 | } |
18
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
226 | |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
227 | int cfg_handle_runtime(ServerConfiguration *cfg, ServerConfigObject *obj) { |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
228 | cfg->user = sstrdub(cfg_directivelist_get_str( |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
229 | obj->directives, |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
230 | sstr("User"))); |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
231 | cfg->tmp = sstrdub(cfg_directivelist_get_str( |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
232 | obj->directives, |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
233 | sstr("Temp"))); |
19
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
234 | |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
235 | return 0; |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
236 | } |
19
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
237 | |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
238 | int cfg_handle_logfile(ServerConfiguration *cfg, ServerConfigObject *obj) { |
28 | 239 | sstr_t file = cfg_directivelist_get_str(obj->directives, sstr("File")); |
240 | sstr_t lvl = cfg_directivelist_get_str(obj->directives, sstr("Level")); | |
241 | ||
242 | if(file.ptr == NULL || lvl.ptr == NULL) { | |
243 | /* missing log file parameters */ | |
244 | return -1; | |
245 | } | |
246 | ||
247 | LogConfig logcfg; | |
248 | logcfg.file = sstrdup(file).ptr; | |
249 | logcfg.level = sstrdub(lvl).ptr; | |
250 | /* TODO: stdout, stderr config */ | |
251 | ||
252 | int ret = init_log_file(&logcfg); | |
253 | ||
254 | free(logcfg.file); | |
255 | free(logcfg.level); | |
19
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
256 | |
28 | 257 | return ret; |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
258 | } |
19
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
259 | |
30
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
260 | 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
|
261 | EventHandlerConfig evcfg; |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
262 | |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
263 | 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
|
264 | sstr_t threads = cfg_directivelist_get_str( |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
265 | obj->directives, |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
266 | sstr("Threads")); |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
267 | sstr_t isdefault = cfg_directivelist_get_str( |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
268 | obj->directives, |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
269 | sstr("Default")); |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
270 | |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
271 | evcfg.name = name; |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
272 | |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
273 | sstr_t s = sstrdup(threads); |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
274 | evcfg.nthreads = atoi(s.ptr); |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
275 | free(s.ptr); |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
276 | |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
277 | evcfg.isdefault = util_getboolean(isdefault.ptr, 0); |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
278 | |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
279 | int ret = create_event_handler(&evcfg); |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
280 | |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
281 | return ret; |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
282 | } |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
283 | |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
284 | int cfg_handle_authdb(ServerConfiguration *cfg, ServerConfigObject *obj) { |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
285 | /* TODO: authdb*/ |
19
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
286 | |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
287 | return 0; |
18
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
288 | } |
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
289 | |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
290 | int cfg_handle_listener(ServerConfiguration *cfg, ServerConfigObject *obj) { |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
291 | ListenerConfig lc; |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
292 | lc.port = 8080; |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
293 | lc.nacceptors = 1; |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
294 | |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
295 | lc.name = sstrdub(cfg_directivelist_get_str( |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
296 | obj->directives, |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
297 | sstr("Name"))); |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
298 | lc.port = atoi(cfg_directivelist_get_str( |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
299 | obj->directives, |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
300 | sstr("Port")).ptr); |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
301 | lc.vs = sstrdub(cfg_directivelist_get_str( |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
302 | obj->directives, |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
303 | sstr("DefaultVS"))); |
18
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
304 | |
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
305 | |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
306 | HttpListener *listener = http_listener_new(&lc); |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
307 | listener->default_vs.vs_name = lc.vs.ptr; |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
308 | cfg->listeners = ucx_list_append(cfg->listeners, listener); |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
309 | |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
310 | return 0; |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
311 | } |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
312 | |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
313 | int cfg_handle_vs(ServerConfiguration *cfg, ServerConfigObject *obj) { |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
314 | VirtualServer *vs = vs_new(); |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
315 | |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
316 | vs->name = sstrdub(cfg_directivelist_get_str( |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
317 | obj->directives, |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
318 | sstr("Name"))); |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
319 | vs->host = sstrdub(cfg_directivelist_get_str( |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
320 | obj->directives, |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
321 | sstr("Host"))); |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
322 | vs->document_root = sstrdub(cfg_directivelist_get_str( |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
323 | obj->directives, |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
324 | sstr("DocRoot"))); |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
325 | sstr_t objfile = cfg_directivelist_get_str( |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
326 | obj->directives, |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
327 | sstr("ObjectFile")); |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
328 | sstr_t base = sstr("conf/"); |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
329 | sstr_t file; |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
330 | file.length = base.length + objfile.length + 1; |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
331 | file.ptr = alloca(file.length); |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
332 | file.ptr[file.length] = 0; |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
333 | file = sstrncat(2, file, base, objfile); |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
334 | |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
335 | ConfigFile *f = cfgmgr_get_file(file); |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
336 | if(f == NULL) { |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
337 | f = malloc(sizeof(ConfigFile)); |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
338 | f->file = sstrdub(file); |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
339 | f->reload = object_conf_reload; |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
340 | f->reload(f, cfg); |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
341 | cfgmgr_attach_file(f); |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
342 | } |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
343 | vs->objects = (HTTPObjectConfig*)f->data; |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
344 | |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
345 | ucx_map_sstr_put(cfg->host_vs, vs->host, vs); |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
346 | |
18
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
347 | return 0; |
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
348 | } |
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
349 | |
19
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
350 | |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
351 | int object_conf_reload(ConfigFile *file, ServerConfiguration *cfg) { |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
352 | file->data = load_obj_conf(file->file.ptr); |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
353 | struct stat s; |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
354 | if(stat(file->file.ptr, &s) != 0) { |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
355 | perror("object_conf_reload: stat"); |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
356 | return -1; |
19
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
357 | } |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
358 | file->last_modified = s.st_mtim.tv_sec; |
25
5dee29c7c530
Fixed config parser bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
359 | return 0; |
3
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
360 | } |
5
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
361 | |
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
362 | HTTPObjectConfig* load_obj_conf(char *file) { |
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
363 | printf("load_obj_conf\n"); |
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
364 | |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
365 | // new conf function test |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
366 | ObjectConfig *cfg = load_object_config(file); |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
367 | if(cfg == NULL) { |
5
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
368 | return NULL; |
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
369 | } |
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
370 | |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
371 | /* create object config */ |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
372 | HTTPObjectConfig *conf = calloc(sizeof(HTTPObjectConfig), 1); |
19
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
373 | conf->pool = pool_create(); |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
374 | |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
375 | /* convert ObjectConfig to HTTPObjectConfig */ |
5
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
376 | |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
377 | /* add objects */ |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
378 | conf->nobj = ucx_dlist_size(cfg->objects); |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
379 | conf->objects = calloc(1, sizeof(httpd_object*)); |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
380 | |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
381 | UcxDlist *objlist = cfg->objects; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
382 | int i = 0; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
383 | while(objlist != NULL) { |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
384 | ConfigObject *cob = objlist->data; |
5
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
385 | |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
386 | /* get name and ppath */ |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
387 | char *name = NULL; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
388 | char *ppath = NULL; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
389 | if(cob->name.length > 0) { |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
390 | name = sstrdub(cob->name).ptr; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
391 | } |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
392 | if(cob->ppath.length > 0) { |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
393 | ppath = sstrdub(cob->ppath).ptr; |
5
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
394 | } |
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
395 | |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
396 | /* create and add object */ |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
397 | httpd_object *obj = object_new(name); |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
398 | obj->path = NULL; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
399 | |
25
5dee29c7c530
Fixed config parser bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
400 | 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
|
401 | |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
402 | /* add directives */ |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
403 | for(int i=0;i<6;i++) { |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
404 | UcxDlist *dirs = cob->directives[i]; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
405 | while(dirs != NULL) { |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
406 | ConfigDirective *cfgdir = dirs->data; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
407 | |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
408 | directive *d = malloc(sizeof(directive)); |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
409 | d->cond = NULL; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
410 | d->param = pblock_create_pool(conf->pool, 8); |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
411 | |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
412 | /* add params */ |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
413 | UcxList *param = cfgdir->param; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
414 | while(param != NULL) { |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
415 | ConfigParam *p = param->data; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
416 | pblock_nvlinsert( |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
417 | p->name.ptr, |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
418 | p->name.length, |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
419 | p->value.ptr, |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
420 | p->value.length, |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
421 | d->param); |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
422 | param = param->next; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
423 | } |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
424 | |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
425 | /* get function */ |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
426 | char *func_name = pblock_findval("fn", d->param); |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
427 | d->func = get_function(func_name); |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
428 | |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
429 | dirs = dirs->next; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
430 | |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
431 | /* add function to dtable */ |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
432 | object_add_directive(obj, d, cfgdir->type_num); |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
433 | } |
5
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
434 | } |
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
435 | |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
436 | /* next */ |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
437 | i++; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
438 | objlist = objlist->next; |
5
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
439 | } |
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
440 | |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
441 | free_object_config(cfg); |
5
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
442 | |
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
443 | return conf; |
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
444 | } |