Sun, 26 May 2013 22:05:41 +0200
dynamic thread pool
1 | 1 | /* |
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. | |
3 | * | |
44
3da1f7b6847f
added some error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
4 | * Copyright 2013 Olaf Wintermann. All rights reserved. |
1 | 5 | * |
6 | * Redistribution and use in source and binary forms, with or without | |
7 | * modification, are permitted provided that the following conditions are met: | |
8 | * | |
9 | * 1. Redistributions of source code must retain the above copyright | |
10 | * notice, this list of conditions and the following disclaimer. | |
11 | * | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | |
15 | * | |
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | |
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
26 | * POSSIBILITY OF SUCH DAMAGE. | |
27 | */ | |
28 | ||
14
b8bf95b39952
New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
29 | #include "../public/nsapi.h" |
1 | 30 | |
31 | #include <stdio.h> | |
32 | #include <stdlib.h> | |
33 | ||
5
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
34 | #include <fcntl.h> |
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
35 | #include <sys/types.h> |
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
36 | #include <sys/file.h> |
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
37 | #include <sys/stat.h> |
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 | |
60
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
61 | int load_init_conf(char *file) { |
1 | 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) { |
60
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
67 | return 1; |
13
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); |
60
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
96 | pblock_free(d->param); |
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
97 | //dirs = dirs->next; |
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
98 | log_ereport( |
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
99 | LOG_MISCONFIG, |
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
100 | "Cannot find Init function %s", |
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
101 | func_name); |
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
102 | return 1; |
13
1fdbf4170ef4
Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
103 | } |
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 | /* execute init directive */ |
60
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
106 | int ret = d->func->func(d->param, NULL, NULL); |
61
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
107 | if(ret != REQ_PROCEED && ret != REQ_NOACTION) { |
60
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
108 | log_ereport( |
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
109 | LOG_FAILURE, |
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
110 | "Error running Init function %s", |
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
111 | func_name); |
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
112 | return 1; |
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
113 | } |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
114 | |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
115 | dirs = dirs->next; |
13
1fdbf4170ef4
Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
116 | } |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
117 | |
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
118 | free_init_config(cfg); |
60
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
119 | |
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
120 | return 0; |
1 | 121 | } |
122 | ||
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
123 | ServerConfiguration* load_server_conf(ServerConfiguration *old, char *file) { |
1 | 124 | printf("load_server_conf\n"); |
18
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
125 | |
19
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
126 | ServerConfig *serverconf = load_server_config(file); |
18
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
127 | if(serverconf == NULL) { |
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
128 | fprintf(stderr, "Cannot load server.conf\n"); |
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
129 | } |
46
636e05eb48f6
cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
130 | ServerConfiguration *serverconfig = calloc(1, sizeof(ServerConfiguration)); |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
131 | serverconfig->ref = 1; |
19
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
132 | serverconfig->pool = pool_create(); |
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
133 | serverconfig->listeners = NULL; |
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
134 | serverconfig->host_vs = ucx_map_new(16); |
38
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
135 | serverconfig->authdbs = ucx_map_new(16); |
18
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
136 | // TODO: init serverconfig stuff |
29
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
137 | |
33
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
138 | |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
139 | /* |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
140 | * convert ServerConfig to ServerConfiguration |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
141 | * |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
142 | * 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
|
143 | * LogFile (open log file first to log possible errors) |
33
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
144 | * Runtime |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
145 | * Threadpool |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
146 | * EventHandler |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
147 | * AuthDB |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
148 | * Listener (we set the VirtualServer later) |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
149 | * VirtualServer (dependencies: Listener) |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
150 | */ |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
151 | |
29
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
152 | /* init logfile first */ |
33
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
153 | 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
|
154 | if(lfl != NULL) { |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
155 | ServerConfigObject *logobj = lfl->data; |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
156 | if(logobj == NULL) { |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
157 | /* error */ |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
158 | return NULL; |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
159 | } |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
160 | |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
161 | int ret = cfg_handle_logfile(serverconfig, logobj); |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
162 | if(ret != 0) { |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
163 | /* cannot initialize log file */ |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
164 | return NULL; |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
165 | } |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
166 | } else { |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
167 | /* horrible error */ |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
168 | return NULL; |
e8619defde14
added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
169 | } |
46
636e05eb48f6
cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
170 | |
33
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
171 | 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
|
172 | UCX_FOREACH(UcxList*, list, elm) { |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
173 | ServerConfigObject *scfgobj = elm->data; |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
174 | cfg_handle_runtime(serverconfig, scfgobj); |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
175 | } |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
176 | |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
177 | list = ucx_map_sstr_get(serverconf->objects, sstrn("Threadpool", 10)); |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
178 | UCX_FOREACH(UcxList*, list, elm) { |
37
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
179 | cfg_handle_threadpool(serverconfig, elm->data); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
180 | } |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
181 | // check thread pool config |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
182 | if(check_thread_pool_cfg() != 0) { |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
183 | /* critical error */ |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
184 | return NULL; |
33
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
185 | } |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
186 | |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
187 | list = ucx_map_sstr_get(serverconf->objects, sstrn("EventHandler", 12)); |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
188 | UCX_FOREACH(UcxList*, list, elm) { |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
189 | cfg_handle_eventhandler(serverconfig, (ServerConfigObject*)elm->data); |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
190 | } |
37
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
191 | // check event handler config |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
192 | if(check_event_handler_cfg() != 0) { |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
193 | /* critical error */ |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
194 | return NULL; |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
195 | } |
33
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
196 | |
45
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
197 | list = ucx_map_sstr_get(serverconf->objects, sstrn("AccessLog", 9)); |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
198 | UCX_FOREACH(UcxList*, list, elm) { |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
199 | ServerConfigObject *scfgobj = elm->data; |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
200 | cfg_handle_accesslog(serverconfig, scfgobj); |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
201 | } |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
202 | |
33
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
203 | list = ucx_map_sstr_get(serverconf->objects, sstrn("AuthDB", 6)); |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
204 | UCX_FOREACH(UcxList*, list, elm) { |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
205 | ServerConfigObject *scfgobj = elm->data; |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
206 | cfg_handle_authdb(serverconfig, scfgobj); |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
207 | } |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
208 | |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
209 | list = ucx_map_sstr_get(serverconf->objects, sstrn("Listener", 8)); |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
210 | UCX_FOREACH(UcxList*, list, elm) { |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
211 | ServerConfigObject *scfgobj = elm->data; |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
212 | cfg_handle_listener(serverconfig, scfgobj); |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
213 | } |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
214 | |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
215 | list = ucx_map_sstr_get(serverconf->objects, sstrn("VirtualServer", 13)); |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
216 | UCX_FOREACH(UcxList*, list, elm) { |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
217 | ServerConfigObject *scfgobj = elm->data; |
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
218 | cfg_handle_vs(serverconfig, scfgobj); |
18
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
219 | } |
30
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
220 | |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
221 | |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
222 | // set VirtualServer for all listeners |
19
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
223 | UcxList *ls = serverconfig->listeners; |
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
224 | while(ls) { |
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
225 | HttpListener *listener = ls->data; |
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
226 | |
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
227 | sstr_t vsname = sstr(listener->default_vs.vs_name); |
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
228 | |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
229 | // search for VirtualServer |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
230 | //int b = 0; |
33
96dbfe4f91e5
improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
31
diff
changeset
|
231 | UcxMapIterator iter = ucx_map_iterator(serverconfig->host_vs); |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
232 | VirtualServer *vs; |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
233 | UCX_MAP_FOREACH(vs, iter) { |
31 | 234 | if(!sstrcmp(vsname, vs->name)) { |
235 | listener->default_vs.vs = vs; | |
19
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
236 | break; |
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 | } |
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
239 | |
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
240 | ls = ls->next; |
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
241 | } |
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
242 | |
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
243 | return serverconfig; |
1 | 244 | } |
3
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
245 | |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
246 | void cfg_ref(ServerConfiguration *cfg) { |
41
bb7a1f5a8b48
added Linux support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
247 | ws_atomic_inc32(&cfg->ref); |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
248 | } |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
249 | |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
250 | void cfg_unref(ServerConfiguration *cfg) { |
41
bb7a1f5a8b48
added Linux support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
251 | uint32_t ref = ws_atomic_dec32(&cfg->ref); |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
252 | if(ref == 0) { |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
253 | // TODO: free configuration |
61
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
254 | printf("free ServerConfiguration %d\n", cfg); |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
255 | } |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
256 | } |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
257 | |
19
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
258 | |
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
259 | void init_server_config_parser() { |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
260 | |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
261 | } |
18
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
262 | |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
263 | int cfg_handle_runtime(ServerConfiguration *cfg, ServerConfigObject *obj) { |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
264 | cfg->user = sstrdup(cfg_directivelist_get_str( |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
265 | obj->directives, |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
266 | sstr("User"))); |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
267 | cfg->tmp = sstrdup(cfg_directivelist_get_str( |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
268 | obj->directives, |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
269 | sstr("Temp"))); |
39
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 | // mime file |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
272 | 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
|
273 | |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
274 | sstr_t base = sstr("config/"); |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
275 | sstr_t file; |
41
bb7a1f5a8b48
added Linux support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
276 | file.length = base.length + mf.length; |
bb7a1f5a8b48
added Linux support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
277 | file.ptr = alloca(file.length + 1); |
39
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
278 | file.ptr[file.length] = 0; |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
279 | file = sstrncat(2, file, base, mf); |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
280 | |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
281 | ConfigFile *f = cfgmgr_get_file(file); |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
282 | if(f == NULL) { |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
283 | f = malloc(sizeof(ConfigFile)); |
61
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
284 | f->data = NULL; |
39
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
285 | f->file = sstrdup(file); |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
286 | f->reload = mime_conf_reload; |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
287 | |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
288 | // load the file content |
61
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
289 | //f->reload(f, cfg); |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
290 | if(cfgmgr_reload_file(f, cfg, NULL)) { |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
291 | free(f->file.ptr); |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
292 | free(f); |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
293 | return -1; |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
294 | } |
39
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
295 | cfgmgr_attach_file(f); |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
296 | } |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
297 | |
61
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
298 | cfg->mimetypes = f->data; |
39
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
299 | |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
300 | return 0; |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
301 | } |
19
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
302 | |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
303 | int cfg_handle_logfile(ServerConfiguration *cfg, ServerConfigObject *obj) { |
28 | 304 | sstr_t file = cfg_directivelist_get_str(obj->directives, sstr("File")); |
305 | sstr_t lvl = cfg_directivelist_get_str(obj->directives, sstr("Level")); | |
306 | ||
307 | if(file.ptr == NULL || lvl.ptr == NULL) { | |
308 | /* missing log file parameters */ | |
309 | return -1; | |
310 | } | |
311 | ||
312 | LogConfig logcfg; | |
313 | logcfg.file = sstrdup(file).ptr; | |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
314 | logcfg.level = sstrdup(lvl).ptr; |
28 | 315 | /* TODO: stdout, stderr config */ |
316 | ||
317 | int ret = init_log_file(&logcfg); | |
318 | ||
319 | free(logcfg.file); | |
320 | free(logcfg.level); | |
19
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
321 | |
28 | 322 | return ret; |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
323 | } |
19
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
324 | |
37
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
325 | int cfg_handle_threadpool(ServerConfiguration *cfg, ServerConfigObject *obj) { |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
326 | ThreadPoolConfig poolcfg; |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
327 | poolcfg.min_threads = 4; |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
328 | poolcfg.min_threads = 4; |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
329 | poolcfg.max_threads = 8; |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
330 | poolcfg.queue_size = 64; |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
331 | poolcfg.stack_size = 262144; |
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 | sstr_t name = cfg_directivelist_get_str( |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
334 | obj->directives, |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
335 | sstr("Name")); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
336 | sstr_t min = cfg_directivelist_get_str( |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
337 | obj->directives, |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
338 | sstr("MinThreads")); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
339 | sstr_t max = cfg_directivelist_get_str( |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
340 | obj->directives, |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
341 | sstr("MaxThreads")); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
342 | sstr_t stack = cfg_directivelist_get_str( |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
343 | obj->directives, |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
344 | sstr("StackSize")); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
345 | sstr_t queue = cfg_directivelist_get_str( |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
346 | obj->directives, |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
347 | sstr("QueueSize")); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
348 | // TODO: Type |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
349 | |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
350 | if(name.length == 0) { |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
351 | // TODO: log error |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
352 | return 1; |
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 | |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
355 | if(min.length != 0) { |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
356 | min = sstrdup(min); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
357 | poolcfg.min_threads = atoi(min.ptr); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
358 | free(min.ptr); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
359 | } |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
360 | |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
361 | if(max.length != 0) { |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
362 | max = sstrdup(max); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
363 | poolcfg.max_threads = atoi(max.ptr); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
364 | free(max.ptr); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
365 | } |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
366 | |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
367 | if(stack.length != 0) { |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
368 | stack = sstrdup(stack); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
369 | poolcfg.stack_size = atoi(stack.ptr); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
370 | free(stack.ptr); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
371 | } |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
372 | |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
373 | if(queue.length != 0) { |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
374 | queue = sstrdup(queue); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
375 | poolcfg.queue_size = atoi(queue.ptr); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
376 | free(queue.ptr); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
377 | } |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
378 | |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
379 | create_threadpool(name, &poolcfg); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
380 | } |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
381 | |
30
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
382 | 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
|
383 | EventHandlerConfig evcfg; |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
384 | |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
385 | 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
|
386 | sstr_t threads = cfg_directivelist_get_str( |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
387 | obj->directives, |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
388 | sstr("Threads")); |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
389 | sstr_t isdefault = cfg_directivelist_get_str( |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
390 | obj->directives, |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
391 | sstr("Default")); |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
392 | |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
393 | evcfg.name = name; |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
394 | |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
395 | sstr_t s = sstrdup(threads); |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
396 | evcfg.nthreads = atoi(s.ptr); |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
397 | free(s.ptr); |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
398 | |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
399 | evcfg.isdefault = util_getboolean(isdefault.ptr, 0); |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
400 | |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
401 | int ret = create_event_handler(&evcfg); |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
402 | |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
403 | return ret; |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
404 | } |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
405 | |
45
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
406 | int cfg_handle_accesslog(ServerConfiguration *cfg, ServerConfigObject *obj) { |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
407 | // TODO: use a name to identify the log file |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
408 | |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
409 | sstr_t file = cfg_directivelist_get_str(obj->directives, sstr("File")); |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
410 | if(file.ptr == NULL) { |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
411 | return 0; |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
412 | } |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
413 | sstr_t format; |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
414 | format.ptr = NULL; |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
415 | |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
416 | AccessLog *log = get_access_log(file, format); |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
417 | if(log) { |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
418 | // access logs are only stored in the server config to free them |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
419 | cfg->logfiles = ucx_list_append(cfg->logfiles, log); |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
420 | } |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
421 | |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
422 | return 0; |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
423 | } |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
424 | |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
425 | int cfg_handle_authdb(ServerConfiguration *cfg, ServerConfigObject *obj) { |
38
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
426 | 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
|
427 | 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
|
428 | |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
429 | if(!sstrcmp(type, sstr("ldap"))) { |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
430 | LDAPConfig conf; |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
431 | |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
432 | sstr_t host = cfg_directivelist_get_str( |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
433 | obj->directives, |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
434 | sstr("Host")); |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
435 | sstr_t port = cfg_directivelist_get_str( |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
436 | obj->directives, |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
437 | sstr("Port")); |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
438 | sstr_t basedn = cfg_directivelist_get_str( |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
439 | obj->directives, |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
440 | sstr("BaseDN")); |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
441 | sstr_t binddn = cfg_directivelist_get_str( |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
442 | obj->directives, |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
443 | sstr("BindDN")); |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
444 | sstr_t basepw = cfg_directivelist_get_str( |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
445 | obj->directives, |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
446 | sstr("BindPW")); |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
447 | |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
448 | host = sstrdup(host); |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
449 | port = sstrdup(port); |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
450 | basedn = sstrdup(basedn); |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
451 | binddn = sstrdup(binddn); |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
452 | basepw = sstrdup(basepw); |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
453 | |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
454 | conf.hostname = host.ptr; |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
455 | conf.port = atoi(port.ptr); |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
456 | conf.basedn = basedn.ptr; |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
457 | conf.binddn = binddn.ptr; |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
458 | conf.bindpw = basepw.ptr; |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
459 | |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
460 | name = sstrdup(name); |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
461 | |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
462 | AuthDB *authdb = create_ldap_authdb(name.ptr, &conf); |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
463 | printf("authdb: %d\n", authdb); |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
464 | ucx_map_sstr_put(cfg->authdbs, name, authdb); |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
465 | |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
466 | // TODO: create_ldap_authdb should copy the strings |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
467 | /* |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
468 | free(host.ptr); |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
469 | free(port.ptr); |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
470 | free(basedn.ptr); |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
471 | free(binddn.ptr); |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
472 | free(basepw.ptr); |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
473 | free(name.ptr); |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
474 | */ |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
475 | |
62
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
476 | } else if(!sstrcmp(type, sstr("keyfile"))) { |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
477 | // we only need the file parameter |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
478 | sstr_t file = cfg_directivelist_get_str( |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
479 | obj->directives, |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
480 | sstr("File")); |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
481 | if(file.length == 0) { |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
482 | log_ereport( |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
483 | LOG_MISCONFIG, |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
484 | "missing File parameter for keyfile authdb"); |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
485 | return 1; |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
486 | } |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
487 | |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
488 | // load keyfile |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
489 | ConfigFile *f = cfgmgr_get_file(file); |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
490 | if(f == NULL) { |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
491 | f = malloc(sizeof(ConfigFile)); |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
492 | f->data = NULL; |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
493 | f->file = sstrdup(file); |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
494 | f->reload = keyfile_reload; |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
495 | //f->reload(f, cfg); |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
496 | if(cfgmgr_reload_file(f, cfg, NULL)) { |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
497 | free(f->file.ptr); |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
498 | free(f); |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
499 | return -1; |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
500 | } |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
501 | cfgmgr_attach_file(f); |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
502 | } |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
503 | |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
504 | // add keyfile authdb |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
505 | Keyfile *keyfile = f->data; |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
506 | keyfile->authdb.name = sstrdup(name).ptr; |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
507 | printf("authdb: %d\n", keyfile); |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
508 | ucx_map_sstr_put(cfg->authdbs, name, keyfile); |
38
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
509 | } |
19
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
510 | |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
511 | return 0; |
18
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
512 | } |
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
513 | |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
514 | int cfg_handle_listener(ServerConfiguration *cfg, ServerConfigObject *obj) { |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
515 | ListenerConfig lc; |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
516 | lc.cfg = cfg; |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
517 | lc.port = 8080; |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
518 | lc.nacceptors = 1; |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
519 | |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
520 | // TODO: use sstrdup_pool? |
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
521 | lc.name = sstrdup(cfg_directivelist_get_str( |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
522 | obj->directives, |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
523 | sstr("Name"))); |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
524 | lc.port = atoi(cfg_directivelist_get_str( |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
525 | obj->directives, |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
526 | sstr("Port")).ptr); |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
527 | lc.vs = sstrdup(cfg_directivelist_get_str( |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
528 | obj->directives, |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
529 | sstr("DefaultVS"))); |
37
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
530 | lc.threadpool = sstrdup(cfg_directivelist_get_str( |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
531 | obj->directives, |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
532 | sstr("Threadpool"))); |
18
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
533 | |
37
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
534 | // TODO: check if all important configs are set |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
535 | |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
536 | HttpListener *listener = http_listener_create(&lc); |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
537 | listener->default_vs.vs_name = lc.vs.ptr; |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
538 | 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
|
539 | |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
540 | return 0; |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
541 | } |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
542 | |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
543 | int cfg_handle_vs(ServerConfiguration *cfg, ServerConfigObject *obj) { |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
544 | VirtualServer *vs = vs_new(); |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
545 | |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
546 | vs->name = sstrdup(cfg_directivelist_get_str( |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
547 | obj->directives, |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
548 | sstr("Name"))); |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
549 | vs->host = sstrdup(cfg_directivelist_get_str( |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
550 | obj->directives, |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
551 | sstr("Host"))); |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
552 | vs->document_root = sstrdup(cfg_directivelist_get_str( |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
553 | obj->directives, |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
554 | sstr("DocRoot"))); |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
555 | sstr_t objfile = cfg_directivelist_get_str( |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
556 | obj->directives, |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
557 | sstr("ObjectFile")); |
51 | 558 | sstr_t aclfile = cfg_directivelist_get_str( |
559 | obj->directives, | |
560 | sstr("ACLFile")); | |
561 | ||
562 | // load the object config file | |
39
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
563 | sstr_t base = sstr("config/"); |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
564 | sstr_t file; |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
565 | file.length = base.length + objfile.length + 1; |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
566 | file.ptr = alloca(file.length); |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
567 | file.ptr[file.length] = 0; |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
568 | file = sstrncat(2, file, base, objfile); |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
569 | |
51 | 570 | // the file is managed by the configuration manager |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
571 | ConfigFile *f = cfgmgr_get_file(file); |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
572 | if(f == NULL) { |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
573 | f = malloc(sizeof(ConfigFile)); |
61
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
574 | f->data = NULL; |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
575 | f->file = sstrdup(file); |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
576 | f->reload = object_conf_reload; |
61
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
577 | //f->reload(f, cfg); |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
578 | if(cfgmgr_reload_file(f, cfg, NULL)) { |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
579 | free(f->file.ptr); |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
580 | free(f); |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
581 | return -1; |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
582 | } |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
583 | cfgmgr_attach_file(f); |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
584 | } |
61
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
585 | vs->objectfile = sstrdup(file); |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
586 | vs->objects = (HTTPObjectConfig*)f->data; |
45
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
587 | |
51 | 588 | // load acl config file |
589 | file.length = base.length + aclfile.length + 1; | |
590 | file.ptr = alloca(file.length); | |
591 | file.ptr[file.length] = 0; | |
592 | file = sstrncat(2, file, base, aclfile); | |
593 | ||
594 | ConfigFile *aclf = cfgmgr_get_file(file); | |
595 | if(aclf == NULL) { | |
596 | aclf = malloc(sizeof(ConfigFile)); | |
61
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
597 | aclf->data = NULL; |
51 | 598 | aclf->file = sstrdup(file); |
599 | aclf->reload = acl_conf_reload; | |
61
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
600 | //aclf->reload(aclf, cfg); |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
601 | if(cfgmgr_reload_file(aclf, cfg, NULL)) { |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
602 | free(aclf->file.ptr); |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
603 | free(aclf); |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
604 | return -1; |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
605 | } |
51 | 606 | cfgmgr_attach_file(aclf); |
607 | } | |
61
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
608 | vs->acls = aclf->data; |
51 | 609 | |
45
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
610 | // set the access log for the virtual server |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
611 | // TODO: don't use always the default |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
612 | vs->log = get_default_access_log(); |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
613 | |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
614 | ucx_map_sstr_put(cfg->host_vs, vs->host, vs); |
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
615 | |
18
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
616 | return 0; |
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
617 | } |
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
618 | |
19
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
619 | |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
620 | int object_conf_reload(ConfigFile *file, ServerConfiguration *cfg) { |
61
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
621 | HTTPObjectConfig *old_conf = file->data; |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
622 | file->data = load_obj_conf(file->file.ptr); |
61
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
623 | if(old_conf) { |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
624 | object_conf_unref(old_conf); |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
625 | } |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
626 | if(file->data) { |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
627 | return 0; |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
628 | } else { |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
629 | return 1; |
19
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
630 | } |
61
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
631 | } |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
632 | |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
633 | void object_conf_ref(HTTPObjectConfig *conf) { |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
634 | if(conf) { |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
635 | ws_atomic_inc32(&conf->ref); |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
636 | } |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
637 | } |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
638 | |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
639 | void object_conf_unref(HTTPObjectConfig *conf) { |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
640 | uint32_t ref = ws_atomic_dec32(&conf->ref); |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
641 | if(ref == 0) { |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
642 | printf("free HTTPObjectConfig %d\n", conf); |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
643 | pool_destroy(conf->pool); |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
644 | } |
3
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
645 | } |
5
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
646 | |
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
647 | HTTPObjectConfig* load_obj_conf(char *file) { |
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
648 | printf("load_obj_conf\n"); |
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
649 | |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
650 | // new conf function test |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
651 | ObjectConfig *cfg = load_object_config(file); |
38
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
652 | UcxMempool *mp = cfg->parser.mp; |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
653 | if(cfg == NULL) { |
5
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
654 | return NULL; |
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
655 | } |
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
656 | |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
657 | /* create object config */ |
61
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
658 | pool_handle_t *pool = pool_create(); |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
659 | HTTPObjectConfig *conf = pool_calloc(pool, sizeof(HTTPObjectConfig), 1); |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
660 | conf->pool = pool; |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
661 | |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
662 | /* convert ObjectConfig to HTTPObjectConfig */ |
5
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
663 | |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
664 | /* add objects */ |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
665 | conf->nobj = ucx_dlist_size(cfg->objects); |
61
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
666 | conf->objects = pool_calloc(pool, 1, sizeof(httpd_object*)); |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
667 | |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
668 | UcxDlist *objlist = cfg->objects; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
669 | int i = 0; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
670 | while(objlist != NULL) { |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
671 | ConfigObject *cob = objlist->data; |
5
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
672 | |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
673 | /* get name and ppath */ |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
674 | char *name = NULL; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
675 | char *ppath = NULL; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
676 | if(cob->name.length > 0) { |
61
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
677 | name = sstrdup_pool(pool, cob->name).ptr; |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
678 | } |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
679 | if(cob->ppath.length > 0) { |
61
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
680 | ppath = sstrdup_pool(pool, cob->ppath).ptr; |
5
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
681 | } |
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
682 | |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
683 | /* create and add object */ |
61
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
684 | httpd_object *obj = object_new(pool, name); |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
685 | obj->path = NULL; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
686 | |
25
5dee29c7c530
Fixed config parser bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
687 | 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
|
688 | |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
689 | /* add directives */ |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
690 | for(int i=0;i<6;i++) { |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
691 | UcxDlist *dirs = cob->directives[i]; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
692 | while(dirs != NULL) { |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
693 | ConfigDirective *cfgdir = dirs->data; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
694 | |
61
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
695 | directive *d = pool_malloc(pool, sizeof(directive)); |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
696 | d->cond = NULL; |
61
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
697 | d->param = pblock_create_pool(pool, 8); |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
698 | |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
699 | /* add params */ |
38
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
700 | UcxList *param = cfg_param_list(cfgdir->value, mp); |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
701 | while(param != NULL) { |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
702 | ConfigParam *p = param->data; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
703 | pblock_nvlinsert( |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
704 | p->name.ptr, |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
705 | p->name.length, |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
706 | p->value.ptr, |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
707 | p->value.length, |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
708 | d->param); |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
709 | param = param->next; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
710 | } |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
711 | |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
712 | /* get function */ |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
713 | char *func_name = pblock_findval("fn", d->param); |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
714 | d->func = get_function(func_name); |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
715 | |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
716 | dirs = dirs->next; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
717 | |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
718 | /* add function to dtable */ |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
719 | object_add_directive(obj, d, cfgdir->type_num); |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
720 | } |
5
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
721 | } |
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
722 | |
16
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
723 | /* next */ |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
724 | i++; |
a9bbd82d2dce
New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
725 | objlist = objlist->next; |
5
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
726 | } |
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
727 | |
17
d2a97bbeb57d
Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
16
diff
changeset
|
728 | free_object_config(cfg); |
5
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
729 | |
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
730 | return conf; |
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
731 | } |
39
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
732 | |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
733 | int mime_conf_reload(ConfigFile *file, ServerConfiguration *cfg) { |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
734 | MimeConfig *mimecfg = load_mime_config(file->file.ptr); |
61
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
735 | MimeMap *old_conf = file->data; |
39
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
736 | |
61
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
737 | MimeMap *mimemap = malloc(sizeof(MimeMap)); |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
738 | mimemap->ref = 1; |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
739 | UcxMap *map = ucx_map_new((mimecfg->ntypes * 3) / 2); |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
740 | mimemap->map = map; |
39
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
741 | |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
742 | // add ext type pairs |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
743 | UCX_FOREACH(UcxList*, mimecfg->directives, md) { |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
744 | MimeDirective *d = md->data; |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
745 | // 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
|
746 | UCX_FOREACH(UcxList*, d->exts, xl) { |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
747 | sstr_t ext = sstr(xl->data); |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
748 | sstr_t value = sstrdup(d->type); |
61
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
749 | ucx_map_sstr_put(map, ext, value.ptr); |
39
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
750 | } |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
751 | } |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
752 | |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
753 | file->data = mimemap; |
61
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
754 | |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
755 | if(old_conf) { |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
756 | mime_conf_unref(old_conf); |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
757 | } |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
758 | |
39
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
759 | return 0; |
de4bc3cd2d36
added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
760 | } |
51 | 761 | |
61
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
762 | void mime_conf_ref(MimeMap *conf) { |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
763 | if(conf) { |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
764 | ws_atomic_inc32(&conf->ref); |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
765 | } |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
766 | } |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
767 | |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
768 | void mime_conf_unref(MimeMap *conf) { |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
769 | uint32_t ref = ws_atomic_dec32(&conf->ref); |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
770 | if(ref == 0) { |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
771 | printf("free MimeConfig %d\n", conf); |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
772 | UcxMapIterator i = ucx_map_iterator(conf->map); |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
773 | char *str; |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
774 | UCX_MAP_FOREACH(str, i) { |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
775 | free(str); |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
776 | } |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
777 | ucx_map_free(conf->map); |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
778 | free(conf); |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
779 | } |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
780 | } |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
781 | |
51 | 782 | int acl_conf_reload(ConfigFile *file, ServerConfiguration *cfg) { |
783 | ACLFile *aclfile = load_acl_file(file->file.ptr); | |
784 | ||
785 | ACLData *acldata = acl_data_new(); | |
786 | UCX_FOREACH(UcxList*, aclfile->namedACLs, elm) { | |
787 | ACLConfig *ac = elm->data; | |
788 | ACLList *acl = acl_config_convert(cfg, ac); | |
63
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
789 | printf("put acl: %s\n", ac->id.ptr); |
51 | 790 | ucx_map_sstr_put(acldata->namedACLs, ac->id, acl); |
791 | } | |
792 | free_acl_file(aclfile); | |
793 | ||
61
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
794 | ACLData *old_data = file->data; |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
795 | file->data = acldata; |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
796 | if(old_data) { |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
797 | acl_data_unref(old_data); |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
798 | } |
51 | 799 | |
800 | return 0; | |
801 | } | |
802 | ||
803 | ACLList* acl_config_convert(ServerConfiguration *cfg, ACLConfig *acl) { | |
54 | 804 | WSAcl *acllist = malloc(sizeof(WSAcl)); |
805 | acllist->acl.check = (acl_check_f)wsacl_check; | |
806 | acllist->acl.authdb = NULL; | |
807 | acllist->acl.authprompt = NULL; | |
808 | acllist->acl.isextern = 0; | |
51 | 809 | acllist->ace = NULL; |
810 | acllist->ece = NULL; | |
811 | ||
63
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
812 | if(acl->type.ptr && !sstrcmp(acl->type, sstr("fs"))) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
813 | printf("set acl to extern\n"); |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
814 | acllist->acl.isextern = 1; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
815 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
816 | |
51 | 817 | size_t s = ucx_list_size(acl->entries); |
54 | 818 | WSAce **aces = calloc(s, sizeof(WSAce*)); |
819 | WSAce **eces = calloc(s, sizeof(WSAce*)); | |
51 | 820 | int ai = 0; |
821 | int ei = 0; | |
822 | ||
823 | // convert entries | |
824 | UCX_FOREACH(UcxList*, acl->entries, elm) { | |
825 | ACEConfig *acecfg = elm->data; | |
826 | ||
827 | // copy data | |
54 | 828 | WSAce *ace = malloc(sizeof(WSAce)); |
51 | 829 | ace->access_mask = acecfg->access_mask; |
830 | ace->flags = acecfg->flags; | |
831 | ace->type = acecfg->type; | |
832 | ace->who = sstrdup(acecfg->who).ptr; | |
833 | ||
834 | // add the entry to the correct array | |
835 | if(ace->type >= ACL_TYPE_AUDIT) { | |
836 | eces[ei] = ace; | |
837 | ei++; | |
838 | } else { | |
839 | aces[ai] = ace; | |
840 | ai++; | |
841 | } | |
842 | } | |
843 | ||
844 | // create new entrie arrays with perfect fitting size | |
845 | if(ai > 0) { | |
54 | 846 | acllist->ace = calloc(ai, sizeof(WSAce*)); |
51 | 847 | } |
848 | if(ei > 0) { | |
54 | 849 | acllist->ece = calloc(ei, sizeof(WSAce*)); |
51 | 850 | } |
54 | 851 | memcpy(acllist->ace, aces, ai*sizeof(WSAce*)); |
852 | memcpy(acllist->ece, eces, ei*sizeof(WSAce*)); | |
51 | 853 | acllist->acenum = ai; |
854 | acllist->ecenum = ei; | |
855 | ||
856 | free(aces); | |
857 | free(eces); | |
858 | ||
859 | // get authentication information | |
860 | if(acl->authparam) { | |
861 | sstr_t authdb_str = cfg_param_get(acl->authparam, sstr("authdb")); | |
862 | sstr_t prompt_str = cfg_param_get(acl->authparam, sstr("prompt")); | |
863 | ||
864 | if(authdb_str.ptr) { | |
865 | AuthDB *authdb = ucx_map_sstr_get(cfg->authdbs, authdb_str); | |
54 | 866 | acllist->acl.authdb = authdb; |
51 | 867 | if(authdb && prompt_str.ptr) { |
54 | 868 | acllist->acl.authprompt = sstrdup(prompt_str).ptr; |
51 | 869 | } |
870 | } | |
871 | } | |
872 | ||
54 | 873 | return &acllist->acl; |
51 | 874 | } |
62
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
875 | |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
876 | int keyfile_reload(ConfigFile *file, ServerConfiguration *cfg) { |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
877 | KeyfileConfig *conf = load_keyfile_config(file->file.ptr); |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
878 | if(!conf) { |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
879 | return 1; |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
880 | } |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
881 | |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
882 | Keyfile *keyfile = keyfile_new(); |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
883 | |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
884 | UCX_FOREACH(UcxList*, conf->users, elm) { |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
885 | KeyfileEntry *user = elm->data; |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
886 | keyfile_add_user( |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
887 | keyfile, |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
888 | user->name, |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
889 | user->hashtype, |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
890 | user->hashdata, |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
891 | user->groups, |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
892 | user->numgroups); |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
893 | } |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
894 | |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
895 | free_keyfile_config(conf); |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
896 | |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
897 | Keyfile *old_data = file->data; |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
898 | file->data = keyfile; |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
899 | if(old_data) { |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
900 | keyfile_unref(old_data); |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
901 | } |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
902 | |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
903 | return 0; |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
904 | } |