src/server/daemon/config.c

Wed, 10 Aug 2022 20:56:24 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Wed, 10 Aug 2022 20:56:24 +0200
branch
webdav
changeset 369
e28ee9875a90
parent 368
69dbcc7e7f93
child 373
f78a585e1a2f
permissions
-rw-r--r--

add support for named dav repositories in nametrans safs

1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
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
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
14
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
29 #include "../public/nsapi.h"
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31 #include <stdio.h>
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32 #include <stdlib.h>
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33
5
dbc01588686e Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
34 #include <fcntl.h>
dbc01588686e Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
35 #include <sys/types.h>
dbc01588686e Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
36 #include <sys/file.h>
dbc01588686e Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
37 #include <sys/stat.h>
162
b169992137a8 improves cgi error handling and allows requests with empty headers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 161
diff changeset
38 #include <sys/mman.h>
5
dbc01588686e Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
39
92
382bff43c6eb fixed some includes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
40 #include <ucx/string.h>
99
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
41 #include <ucx/utils.h>
5
dbc01588686e Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
42
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43 #include "httplistener.h"
18
73aacbf6e492 Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
44 #include "config.h"
5
dbc01588686e Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
45 #include "func.h"
28
f387669912e8 added logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
46 #include "log.h"
30
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
47 #include "event.h"
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
48 #include "threadpools.h"
38
d07810b02147 added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
49 #include "ldap_auth.h"
21
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
50 #include "configmanager.h"
269
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
51 #include "resourcepool.h"
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
53 #include "vserver.h"
14
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
54 #include "../util/pblock.h"
30
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
55 #include "../util/util.h"
41
bb7a1f5a8b48 added Linux support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
56 #include "../util/atomic.h"
106
b122f34ddc80 added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 99
diff changeset
57 #include "ucx/buffer.h"
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
58
255
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
59 pool_handle_t *init_pool;
17
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
60
18
73aacbf6e492 Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
61
60
feb2f1e115c6 improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
62 int load_init_conf(char *file) {
115
51d9a15eac98 improves logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 106
diff changeset
63 log_ereport(LOG_VERBOSE, "load_init_conf");
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
64
19
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
65 InitConfig *cfg = load_init_config(file);
17
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
66 if(cfg == NULL) {
115
51d9a15eac98 improves logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 106
diff changeset
67 log_ereport(LOG_FAILURE, "Cannot load init.conf");
60
feb2f1e115c6 improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
68 return 1;
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
69 }
91
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
70 UcxAllocator *mp = cfg->parser.mp;
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
71
255
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
72 init_pool = pool_create(); // one pool for one Configuration
91
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
73 UcxList *dirs = cfg->directives;
17
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
74 while(dirs != NULL) {
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
75 ConfigDirective *dir = dirs->data;
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
76
17
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
77 /* create NSAPI directive */
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
78 directive *d = malloc(sizeof(directive));
255
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
79 d->param = pblock_create_pool(init_pool, 8);
38
d07810b02147 added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
80 UcxList *param = cfg_param_list(dir->value, mp);
17
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
81 while(param != NULL) {
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
82 ConfigParam *p = param->data;
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
83 pblock_nvlinsert(
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
84 p->name.ptr,
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
85 p->name.length,
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
86 p->value.ptr,
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
87 p->value.length,
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
88 d->param);
20
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
89
17
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
90 param = param->next;
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
91 }
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
92
17
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
93 /* get function */
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
94 char *func_name = pblock_findval("fn", d->param);
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
95 d->func = get_function(func_name);
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
96 if(d->func == NULL) {
79
f48cea237ec3 fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
97 pblock_free(d->param);
17
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
98 free(d);
60
feb2f1e115c6 improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
99 //dirs = dirs->next;
feb2f1e115c6 improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
100 log_ereport(
feb2f1e115c6 improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
101 LOG_MISCONFIG,
feb2f1e115c6 improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
102 "Cannot find Init function %s",
feb2f1e115c6 improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
103 func_name);
feb2f1e115c6 improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
104 return 1;
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
105 }
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
106
17
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
107 /* execute init directive */
60
feb2f1e115c6 improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
108 int ret = d->func->func(d->param, NULL, NULL);
61
c858850f3d3a improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
109 if(ret != REQ_PROCEED && ret != REQ_NOACTION) {
60
feb2f1e115c6 improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
110 log_ereport(
feb2f1e115c6 improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
111 LOG_FAILURE,
feb2f1e115c6 improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
112 "Error running Init function %s",
feb2f1e115c6 improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
113 func_name);
79
f48cea237ec3 fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
114 pblock_free(d->param);
f48cea237ec3 fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
115 free(d);
60
feb2f1e115c6 improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
116 return 1;
feb2f1e115c6 improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
117 }
79
f48cea237ec3 fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
118
f48cea237ec3 fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
119 pblock_free(d->param);
f48cea237ec3 fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
120 free(d);
17
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
121 dirs = dirs->next;
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
122 }
17
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
123
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
124 free_init_config(cfg);
60
feb2f1e115c6 improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
125
feb2f1e115c6 improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
126 return 0;
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
127 }
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
128
255
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
129 ServerConfiguration* load_server_conf(char *file) {
115
51d9a15eac98 improves logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 106
diff changeset
130 log_ereport(LOG_VERBOSE, "load_server_conf");
18
73aacbf6e492 Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
131
256
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
132 ServerConfig *serverconf = serverconfig_load(file);
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
133 if(!serverconf) {
115
51d9a15eac98 improves logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 106
diff changeset
134 log_ereport(LOG_FAILURE, "Cannot load server.conf");
256
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
135 return NULL;
18
73aacbf6e492 Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
136 }
256
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
137
255
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
138 pool_handle_t *pool = pool_create();
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
139
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
140
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
141 ServerConfiguration *serverconfig = pool_calloc(pool, 1, sizeof(ServerConfiguration));
36
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
142 serverconfig->ref = 1;
255
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
143 serverconfig->pool = pool;
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
144
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
145 UcxAllocator allocator = util_pool_allocator(serverconfig->pool);
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
146 serverconfig->a = pool_malloc(pool, sizeof(UcxAllocator));
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
147 *serverconfig->a = allocator;
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
148
260
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
149 serverconfig->listeners = NULL;
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
150 serverconfig->host_vs = ucx_map_new_a(&allocator, 16);
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
151 serverconfig->authdbs = ucx_map_new_a(&allocator, 16);
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
152 serverconfig->resources = ucx_map_new_a(&allocator, 16);
368
69dbcc7e7f93 implement named dav repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 367
diff changeset
153 serverconfig->dav = ucx_map_new_a(&allocator, 16);
260
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
154
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
155
4779a6fb4fbe fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
156
18
73aacbf6e492 Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
157 // TODO: init serverconfig stuff
29
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
158
33
96dbfe4f91e5 improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 31
diff changeset
159
96dbfe4f91e5 improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 31
diff changeset
160 /*
96dbfe4f91e5 improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 31
diff changeset
161 * convert ServerConfig to ServerConfiguration
96dbfe4f91e5 improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 31
diff changeset
162 *
96dbfe4f91e5 improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 31
diff changeset
163 * 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
164 * LogFile (open log file first to log possible errors)
33
96dbfe4f91e5 improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 31
diff changeset
165 * Runtime
96dbfe4f91e5 improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 31
diff changeset
166 * Threadpool
96dbfe4f91e5 improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 31
diff changeset
167 * EventHandler
96dbfe4f91e5 improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 31
diff changeset
168 * AuthDB
96dbfe4f91e5 improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 31
diff changeset
169 * Listener (we set the VirtualServer later)
96dbfe4f91e5 improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 31
diff changeset
170 * VirtualServer (dependencies: Listener)
96dbfe4f91e5 improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 31
diff changeset
171 */
96dbfe4f91e5 improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 31
diff changeset
172
79
f48cea237ec3 fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
173 /*
f48cea237ec3 fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
174 * free stuff on error
f48cea237ec3 fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
175 */
f48cea237ec3 fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
176
72
9b888965f3ee some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
177 // init logfile first
256
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
178 UcxList *list = NULL;
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
179
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
180 list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, SC("LogFile"));
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
181 if(list) {
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
182 ConfigNode *logobj = list->data;
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
183 if(!logobj) {
72
9b888965f3ee some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
184 // error
256
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
185 return NULL; // TODO: fix memory leak
29
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
186 }
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
187
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
188 int ret = cfg_handle_logfile(serverconfig, logobj);
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
189 if(ret != 0) {
72
9b888965f3ee some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
190 // cannot initialize log file
256
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
191 return NULL; // TODO: fix memory leak
29
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
192 }
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
193 } else {
72
9b888965f3ee some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
194 // horrible error
29
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
195 return NULL;
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
196 }
256
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
197 ucx_list_free(list);
46
636e05eb48f6 cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
198
256
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
199 list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, SC("Runtime"));
91
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
200 UCX_FOREACH(elm, list) {
256
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
201 ConfigNode *runtimeobj = elm->data;
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
202 if(cfg_handle_runtime(serverconfig, runtimeobj)) {
72
9b888965f3ee some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
203 // error
9b888965f3ee some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
204 return NULL;
9b888965f3ee some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
205 }
33
96dbfe4f91e5 improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 31
diff changeset
206 }
256
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
207 ucx_list_free(list);
33
96dbfe4f91e5 improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 31
diff changeset
208
256
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
209 list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, SC("Threadpool"));
91
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
210 UCX_FOREACH(elm, list) {
72
9b888965f3ee some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
211 if(cfg_handle_threadpool(serverconfig, elm->data)) {
9b888965f3ee some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
212 return NULL;
9b888965f3ee some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
213 }
37
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
214 }
256
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
215 ucx_list_free(list);
37
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
216 // check thread pool config
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
217 if(check_thread_pool_cfg() != 0) {
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
218 /* critical error */
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
219 return NULL;
33
96dbfe4f91e5 improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 31
diff changeset
220 }
96dbfe4f91e5 improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 31
diff changeset
221
256
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
222 list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, SC("EventHandler"));
91
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
223 UCX_FOREACH(elm, list) {
72
9b888965f3ee some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
224 if(cfg_handle_eventhandler(
256
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
225 serverconfig, elm->data)) {
72
9b888965f3ee some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
226 // error
9b888965f3ee some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
227 return NULL;
9b888965f3ee some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
228 }
33
96dbfe4f91e5 improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 31
diff changeset
229 }
37
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
230 // check event handler config
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
231 if(check_event_handler_cfg() != 0) {
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
232 /* critical error */
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
233 return NULL;
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
234 }
256
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
235 ucx_list_free(list);
33
96dbfe4f91e5 improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 31
diff changeset
236
256
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
237 list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, SC("AccessLog"));
91
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
238 UCX_FOREACH(elm, list) {
256
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
239 ConfigNode *scfgobj = elm->data;
72
9b888965f3ee some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
240 if(cfg_handle_accesslog(serverconfig, scfgobj)) {
9b888965f3ee some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
241 return NULL;
9b888965f3ee some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
242 }
45
a24aa388f02f added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
243 }
256
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
244 ucx_list_free(list);
45
a24aa388f02f added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
245
256
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
246 list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, SC("AuthDB"));
91
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
247 UCX_FOREACH(elm, list) {
256
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
248 ConfigNode *scfgobj = elm->data;
72
9b888965f3ee some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
249 if(cfg_handle_authdb(serverconfig, scfgobj)) {
9b888965f3ee some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
250 return NULL;
9b888965f3ee some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
251 }
33
96dbfe4f91e5 improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 31
diff changeset
252 }
256
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
253 ucx_list_free(list);
33
96dbfe4f91e5 improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 31
diff changeset
254
256
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
255 list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, SC("Listener"));
91
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
256 UCX_FOREACH(elm, list) {
256
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
257 ConfigNode *scfgobj = elm->data;
72
9b888965f3ee some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
258 if(cfg_handle_listener(serverconfig, scfgobj)) {
9b888965f3ee some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
259 return NULL;
9b888965f3ee some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
260 }
33
96dbfe4f91e5 improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 31
diff changeset
261 }
256
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
262 ucx_list_free(list);
33
96dbfe4f91e5 improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 31
diff changeset
263
256
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
264 list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, SC("VirtualServer"));
91
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
265 UCX_FOREACH(elm, list) {
256
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
266 ConfigNode *scfgobj = elm->data;
72
9b888965f3ee some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
267 if(cfg_handle_vs(serverconfig, scfgobj)) {
9b888965f3ee some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
268 return NULL;
9b888965f3ee some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
269 }
18
73aacbf6e492 Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
270 }
256
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
271 ucx_list_free(list);
30
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
272
269
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
273 list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, SC("ResourcePool"));
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
274 UCX_FOREACH(elm, list) {
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
275 ConfigNode *scfgobj = elm->data;
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
276 if(cfg_handle_resourcepool(serverconfig, scfgobj)) {
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
277 return NULL;
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
278 }
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
279 }
366
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
280
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
281 list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, SC("Dav"));
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
282 UCX_FOREACH(elm, list) {
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
283 ConfigNode *scfgobj = elm->data;
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
284 if(cfg_handle_dav(serverconfig, scfgobj)) {
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
285 return NULL;
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
286 }
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
287 }
21
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
288
36
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
289 // set VirtualServer for all listeners
19
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
290 UcxList *ls = serverconfig->listeners;
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
291 while(ls) {
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
292 HttpListener *listener = ls->data;
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
293
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
294 sstr_t vsname = sstr(listener->default_vs.vs_name);
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
295
36
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
296 // search for VirtualServer
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
297 //int b = 0;
33
96dbfe4f91e5 improved configuration loading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 31
diff changeset
298 UcxMapIterator iter = ucx_map_iterator(serverconfig->host_vs);
36
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
299 VirtualServer *vs;
88
73b3485e96f1 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 85
diff changeset
300 UCX_MAP_FOREACH(key, vs, iter) {
31
280250e45ba6 updated ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
301 if(!sstrcmp(vsname, vs->name)) {
280250e45ba6 updated ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
302 listener->default_vs.vs = vs;
19
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
303 break;
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
304 }
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
305 }
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
306
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
307 ls = ls->next;
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
308 }
79
f48cea237ec3 fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
309
256
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
310 serverconfig_free(serverconf);
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
311
19
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
312 return serverconfig;
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
313 }
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
314
36
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
315 void cfg_ref(ServerConfiguration *cfg) {
41
bb7a1f5a8b48 added Linux support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
316 ws_atomic_inc32(&cfg->ref);
36
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
317 }
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
318
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
319 void cfg_unref(ServerConfiguration *cfg) {
41
bb7a1f5a8b48 added Linux support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
320 uint32_t ref = ws_atomic_dec32(&cfg->ref);
36
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
321 if(ref == 0) {
255
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
322 pool_destroy(cfg->pool);
36
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
323 }
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
324 }
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
325
19
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
326
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
327 void init_server_config_parser() {
21
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
328
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
329 }
18
73aacbf6e492 Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
330
256
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
331 int cfg_handle_runtime(ServerConfiguration *cfg, ConfigNode *obj) {
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
332 scstr_t user = serverconfig_directive_value(obj, SC("User"));
72
9b888965f3ee some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
333 if(user.ptr) {
256
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
334 cfg->user = sstrdup_a(cfg->a, user);
72
9b888965f3ee some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
335 }
256
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
336 scstr_t tmp = serverconfig_directive_value(obj, SC("Temp"));
72
9b888965f3ee some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
337 if(tmp.ptr) {
256
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
338 cfg->tmp = sstrdup_a(cfg->a, tmp);
72
9b888965f3ee some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
339 } else {
256
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
340 // TODO: do this check after all config loading is done
72
9b888965f3ee some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
341 log_ereport(LOG_MISCONFIG, "no temporary directory specified");
9b888965f3ee some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
342 return -1;
9b888965f3ee some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
343 }
39
de4bc3cd2d36 added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
344
de4bc3cd2d36 added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
345 // mime file
256
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
346 scstr_t mf = serverconfig_directive_value(obj, SC("MimeFile"));
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
347 scstr_t base = SC("config/");
99
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
348 sstr_t file = sstrcat(2, base, mf);
39
de4bc3cd2d36 added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
349
255
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
350 if(mime_conf_load(cfg, file)) {
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
351 return -1;
39
de4bc3cd2d36 added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
352 }
de4bc3cd2d36 added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
353
99
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
354 free(file.ptr);
21
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
355 return 0;
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
356 }
19
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
357
256
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
358 int cfg_handle_logfile(ServerConfiguration *cfg, ConfigNode *obj) {
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
359 scstr_t file = serverconfig_directive_value(obj, SC("File"));
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
360 scstr_t lvl = serverconfig_directive_value(obj, SC("Level"));
28
f387669912e8 added logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
361
f387669912e8 added logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
362 if(file.ptr == NULL || lvl.ptr == NULL) {
f387669912e8 added logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
363 /* missing log file parameters */
f387669912e8 added logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
364 return -1;
f387669912e8 added logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
365 }
f387669912e8 added logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
366
f387669912e8 added logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
367 LogConfig logcfg;
256
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
368 logcfg.file = file.ptr;
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
369 logcfg.level = lvl.ptr;
139
29ac9aed4889 fixes some memory errors and startup with broken config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
370 logcfg.log_stdout = 0;
29ac9aed4889 fixes some memory errors and startup with broken config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
371 logcfg.log_stderr = 0;
28
f387669912e8 added logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
372 /* TODO: stdout, stderr config */
f387669912e8 added logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
373
f387669912e8 added logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
374 int ret = init_log_file(&logcfg);
19
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
375
28
f387669912e8 added logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
376 return ret;
21
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
377 }
19
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
378
256
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
379 int cfg_handle_threadpool(ServerConfiguration *cfg, ConfigNode *obj) {
37
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
380 ThreadPoolConfig poolcfg;
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
381 poolcfg.min_threads = 4;
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
382 poolcfg.min_threads = 4;
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
383 poolcfg.max_threads = 8;
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
384 poolcfg.queue_size = 64;
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
385 poolcfg.stack_size = 262144;
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
386
256
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
387 scstr_t name = serverconfig_directive_value(obj, SC("Name"));
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
388 scstr_t min = serverconfig_directive_value(obj, SC("MinThreads"));
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
389 scstr_t max = serverconfig_directive_value(obj, SC("MaxThreads"));
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
390 scstr_t stack = serverconfig_directive_value(obj, SC("StackSize"));
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
391 scstr_t queue = serverconfig_directive_value(obj, SC("QueueSize"));
37
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
392 // TODO: Type
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
393
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
394 if(name.length == 0) {
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
395 // TODO: log error
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
396 return 1;
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
397 }
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
398
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
399 if(min.length != 0) {
339
f4a34b0869c7 replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 270
diff changeset
400 int64_t value;
f4a34b0869c7 replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 270
diff changeset
401 if(util_strtoint(min.ptr, &value)) {
f4a34b0869c7 replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 270
diff changeset
402 poolcfg.min_threads = value;
f4a34b0869c7 replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 270
diff changeset
403 } else {
f4a34b0869c7 replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 270
diff changeset
404 log_ereport(LOG_MISCONFIG, "Threadpool: MinThreads not an integer");
f4a34b0869c7 replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 270
diff changeset
405 return 1;
f4a34b0869c7 replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 270
diff changeset
406 }
37
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
407 }
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
408
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
409 if(max.length != 0) {
339
f4a34b0869c7 replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 270
diff changeset
410 int64_t value;
f4a34b0869c7 replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 270
diff changeset
411 if(util_strtoint(max.ptr, &value)) {
f4a34b0869c7 replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 270
diff changeset
412 poolcfg.max_threads = value;
f4a34b0869c7 replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 270
diff changeset
413 } else {
f4a34b0869c7 replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 270
diff changeset
414 log_ereport(LOG_MISCONFIG, "Threadpool: MaxThreads not an integer");
f4a34b0869c7 replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 270
diff changeset
415 return 1;
f4a34b0869c7 replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 270
diff changeset
416 }
37
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
417 }
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
418
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
419 if(stack.length != 0) {
339
f4a34b0869c7 replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 270
diff changeset
420 int64_t value;
f4a34b0869c7 replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 270
diff changeset
421 if(util_strtoint(stack.ptr, &value)) {
f4a34b0869c7 replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 270
diff changeset
422 poolcfg.stack_size = value;
f4a34b0869c7 replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 270
diff changeset
423 } else {
f4a34b0869c7 replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 270
diff changeset
424 log_ereport(LOG_MISCONFIG, "Threadpool: StackSize not an integer");
f4a34b0869c7 replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 270
diff changeset
425 }
37
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
426 }
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
427
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
428 if(queue.length != 0) {
339
f4a34b0869c7 replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 270
diff changeset
429 int64_t value;
f4a34b0869c7 replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 270
diff changeset
430 if(util_strtoint(queue.ptr, &value)) {
f4a34b0869c7 replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 270
diff changeset
431 poolcfg.queue_size = value;
f4a34b0869c7 replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 270
diff changeset
432 } else {
f4a34b0869c7 replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 270
diff changeset
433 log_ereport(LOG_MISCONFIG, "Threadpool: QueueSize not an integer");
f4a34b0869c7 replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 270
diff changeset
434 }
37
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
435 }
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
436
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
437 create_threadpool(name, &poolcfg);
70
4e6e812c1d97 fixed some warnings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 63
diff changeset
438
4e6e812c1d97 fixed some warnings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 63
diff changeset
439 return 0;
37
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
440 }
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
441
339
f4a34b0869c7 replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 270
diff changeset
442 #define EV_MAX_THREADS 2048
256
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
443 int cfg_handle_eventhandler(ServerConfiguration *c, ConfigNode *obj) {
30
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
444 EventHandlerConfig evcfg;
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
445
256
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
446 scstr_t name = serverconfig_directive_value(obj, SC("Name"));
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
447 scstr_t threads = serverconfig_directive_value(obj, SC("Threads"));
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
448 scstr_t isdefault = serverconfig_directive_value(obj, SC("Default"));
30
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
449
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
450 evcfg.name = name;
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
451
339
f4a34b0869c7 replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 270
diff changeset
452 int64_t value;
f4a34b0869c7 replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 270
diff changeset
453 if(!util_strtoint(threads.ptr, &value)) {
f4a34b0869c7 replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 270
diff changeset
454 log_ereport(LOG_MISCONFIG, "EventHandler: Threads: '%s' is not an integer", threads.ptr);
f4a34b0869c7 replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 270
diff changeset
455 return 1;
f4a34b0869c7 replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 270
diff changeset
456 }
f4a34b0869c7 replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 270
diff changeset
457 if(value < 1 || value > EV_MAX_THREADS) {
f4a34b0869c7 replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 270
diff changeset
458 log_ereport(LOG_MISCONFIG, "EventHandler: Invalid number of threads (1 .. %d)", EV_MAX_THREADS);
f4a34b0869c7 replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 270
diff changeset
459 return 1;
f4a34b0869c7 replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 270
diff changeset
460 }
f4a34b0869c7 replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 270
diff changeset
461
f4a34b0869c7 replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 270
diff changeset
462 evcfg.nthreads = value;
30
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
463
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
464 evcfg.isdefault = util_getboolean(isdefault.ptr, 0);
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
465
72
9b888965f3ee some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
466 return create_event_handler(&evcfg);
30
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
467 }
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
468
269
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
469 int cfg_handle_resourcepool(ServerConfiguration *cfg, ConfigNode *obj) {
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
470 scstr_t name = serverconfig_directive_value(obj, SC("Name"));
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
471 scstr_t type = serverconfig_directive_value(obj, SC("Type"));
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
472
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
473 int ret = 0;
270
4cfaa02055cd add first code for postgresql plugin: resourcepool type implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 269
diff changeset
474 if(resourcepool_new(cfg, type, name, obj)) {
269
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
475 ret = 1;
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
476 }
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
477
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
478 return ret;
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
479 }
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
480
256
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
481 int cfg_handle_accesslog(ServerConfiguration *cfg, ConfigNode *obj) {
45
a24aa388f02f added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
482 // TODO: use a name to identify the log file
a24aa388f02f added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
483
256
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
484 scstr_t file = serverconfig_directive_value(obj, SC("File"));
45
a24aa388f02f added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
485 if(file.ptr == NULL) {
a24aa388f02f added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
486 return 0;
a24aa388f02f added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
487 }
a24aa388f02f added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
488 sstr_t format;
77
f1cff81e425a some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
489 format.ptr = NULL;
f1cff81e425a some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
490 format.length = 0;
45
a24aa388f02f added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
491
77
f1cff81e425a some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
492 //AccessLog *log = get_access_log(file, format);
f1cff81e425a some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
493 LogFile *log_file = get_access_log_file(file);
f1cff81e425a some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
494 if(!log_file) {
f1cff81e425a some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
495 // TODO: error/warning
f1cff81e425a some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
496 return 0;
f1cff81e425a some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
497 }
f1cff81e425a some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
498 AccessLog *log = pool_malloc(cfg->pool, sizeof(AccessLog));
256
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
499 log->file = sstrdup_a(cfg->a, file);
77
f1cff81e425a some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
500 log->format = format;
f1cff81e425a some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
501 log->log = log_file;
256
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
502 cfg->logfiles = ucx_list_append_a(cfg->a, cfg->logfiles, log);
77
f1cff81e425a some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
503
f1cff81e425a some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
504 if(!cfg->default_log) {
f1cff81e425a some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
505 cfg->default_log = log;
45
a24aa388f02f added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
506 }
a24aa388f02f added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
507
a24aa388f02f added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
508 return 0;
a24aa388f02f added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
509 }
a24aa388f02f added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
510
256
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
511 int cfg_handle_authdb(ServerConfiguration *cfg, ConfigNode *obj) {
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
512 scstr_t name = serverconfig_directive_value(obj, SC("Name"));
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
513 scstr_t type = serverconfig_directive_value(obj, SC("Type"));
38
d07810b02147 added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
514
255
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
515 AuthDB *authdb = NULL;
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
516
38
d07810b02147 added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
517 if(!sstrcmp(type, sstr("ldap"))) {
d07810b02147 added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
518 LDAPConfig conf;
d07810b02147 added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
519
256
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
520 scstr_t host = serverconfig_directive_value(obj, SC("Host"));
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
521 scstr_t port = serverconfig_directive_value( obj, SC("Port"));
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
522 scstr_t basedn = serverconfig_directive_value(obj, SC("BaseDN"));
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
523 scstr_t binddn = serverconfig_directive_value(obj, SC("BindDN"));
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
524 scstr_t basepw = serverconfig_directive_value(obj, SC("BindPW"));
38
d07810b02147 added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
525
256
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
526 conf.hostname = sstrdup_a(cfg->a, host).ptr;
38
d07810b02147 added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
527 conf.port = atoi(port.ptr);
256
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
528 conf.basedn = sstrdup_a(cfg->a, basedn).ptr;
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
529 conf.binddn = sstrdup_a(cfg->a, binddn).ptr;
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
530 conf.bindpw = sstrdup_a(cfg->a, basepw).ptr;
38
d07810b02147 added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
531
256
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
532 authdb = create_ldap_authdb(cfg, name.ptr, &conf);
62
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 61
diff changeset
533 } else if(!sstrcmp(type, sstr("keyfile"))) {
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 61
diff changeset
534 // we only need the file parameter
256
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
535 scstr_t file = serverconfig_directive_value(obj, SC("File"));
62
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 61
diff changeset
536 if(file.length == 0) {
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 61
diff changeset
537 log_ereport(
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 61
diff changeset
538 LOG_MISCONFIG,
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 61
diff changeset
539 "missing File parameter for keyfile authdb");
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 61
diff changeset
540 return 1;
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 61
diff changeset
541 }
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 61
diff changeset
542
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 61
diff changeset
543 // load keyfile
255
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
544 authdb = keyfile_load(cfg, file);
38
d07810b02147 added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
545 }
19
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
546
255
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
547 if(authdb) {
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
548 if(ucx_map_sstr_put(cfg->authdbs, name, authdb)) {
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
549 return -1;
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
550 }
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
551 }
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
552
21
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
553 return 0;
18
73aacbf6e492 Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
554 }
73aacbf6e492 Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
555
256
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
556 int cfg_handle_listener(ServerConfiguration *cfg, ConfigNode *obj) {
21
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
557 ListenerConfig lc;
130
198ad9d8cec1 adds ssl protocol configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
558 ZERO(&lc, sizeof(ListenerConfig));
36
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
559 lc.cfg = cfg;
21
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
560 lc.port = 8080;
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
561 lc.nacceptors = 1;
36
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
562
256
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
563 scstr_t name = serverconfig_directive_value(obj, SC("Name"));
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
564 scstr_t port = serverconfig_directive_value(obj, SC("Port"));
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
565 scstr_t vs = serverconfig_directive_value(obj, SC("DefaultVS"));
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
566 scstr_t thrp = serverconfig_directive_value(obj, SC("Threadpool"));
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
567 scstr_t blck = serverconfig_directive_value(obj, SC("BlockingIO"));
18
73aacbf6e492 Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
568
256
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
569 // TODO: use sstrdup_pool?
339
f4a34b0869c7 replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 270
diff changeset
570 int64_t port_value;
f4a34b0869c7 replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 270
diff changeset
571 if(!util_strtoint(port.ptr, &port_value)) {
f4a34b0869c7 replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 270
diff changeset
572 log_ereport(LOG_MISCONFIG, "Listener: Invalid argument for parameter 'Port': '%s'", port.ptr);
f4a34b0869c7 replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 270
diff changeset
573 return 1;
f4a34b0869c7 replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 270
diff changeset
574 }
f4a34b0869c7 replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 270
diff changeset
575 if(port_value < 1 || port_value > 65535) {
f4a34b0869c7 replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 270
diff changeset
576 log_ereport(LOG_MISCONFIG, "Listener: Port number out of range (1 .. 65535)");
f4a34b0869c7 replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 270
diff changeset
577 return 1;
f4a34b0869c7 replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 270
diff changeset
578 }
f4a34b0869c7 replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 270
diff changeset
579
256
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
580 lc.name = sstrdup(name);
339
f4a34b0869c7 replace atoi with util_strtoint
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 270
diff changeset
581 lc.port = port_value;
256
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
582 lc.vs = sstrdup(vs);
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
583 lc.threadpool = sstrdup(thrp);
134
44415e4399ce adds blockingio config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
584
256
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
585 lc.blockingio = util_getboolean_s(blck, WS_FALSE);
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
586
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
587 scstr_t ssl = serverconfig_directive_value(obj, SC("SSL"));
106
b122f34ddc80 added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 99
diff changeset
588 if(util_getboolean_s(ssl, WS_FALSE)) {
256
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
589 scstr_t cert = serverconfig_directive_value(obj, SC("Cert"));
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
590 scstr_t privkey = serverconfig_directive_value(obj, SC("Key"));
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
591 scstr_t chain = serverconfig_directive_value(obj, SC("CertChain"));
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
592 scstr_t disableprot = serverconfig_directive_value(obj, SC("SSLDisableProtocol"));
130
198ad9d8cec1 adds ssl protocol configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
593
106
b122f34ddc80 added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 99
diff changeset
594 WSBool config_ok = WS_TRUE;
b122f34ddc80 added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 99
diff changeset
595 // TODO: log error
129
fd324464f56f adds support for ssl cert chain files and improves ssl error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
596 if(!cert.ptr && !chain.ptr) {
130
198ad9d8cec1 adds ssl protocol configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
597 log_ereport(
198ad9d8cec1 adds ssl protocol configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
598 LOG_MISCONFIG,
198ad9d8cec1 adds ssl protocol configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
599 "SSL Listener %s: Missing Cert or ChainCert directive",
198ad9d8cec1 adds ssl protocol configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
600 lc.name.ptr);
106
b122f34ddc80 added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 99
diff changeset
601 config_ok = WS_FALSE;
b122f34ddc80 added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 99
diff changeset
602 }
b122f34ddc80 added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 99
diff changeset
603 if(!privkey.ptr) {
130
198ad9d8cec1 adds ssl protocol configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
604 log_ereport(
198ad9d8cec1 adds ssl protocol configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
605 LOG_MISCONFIG,
198ad9d8cec1 adds ssl protocol configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
606 "SSL Listener %s: Missing Key directive",
198ad9d8cec1 adds ssl protocol configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
607 lc.name.ptr);
106
b122f34ddc80 added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 99
diff changeset
608 config_ok = WS_FALSE;
b122f34ddc80 added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 99
diff changeset
609 }
130
198ad9d8cec1 adds ssl protocol configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
610
106
b122f34ddc80 added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 99
diff changeset
611 if(config_ok) {
b122f34ddc80 added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 99
diff changeset
612 lc.certfile = cert;
b122f34ddc80 added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 99
diff changeset
613 lc.privkeyfile = privkey;
b122f34ddc80 added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 99
diff changeset
614 lc.chainfile = chain;
130
198ad9d8cec1 adds ssl protocol configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
615 lc.disable_proto = disableprot;
106
b122f34ddc80 added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 99
diff changeset
616 lc.ssl = WS_TRUE;
b122f34ddc80 added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 99
diff changeset
617 }
b122f34ddc80 added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 99
diff changeset
618 } else {
b122f34ddc80 added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 99
diff changeset
619 lc.ssl = WS_FALSE;
b122f34ddc80 added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 99
diff changeset
620 }
b122f34ddc80 added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 99
diff changeset
621
37
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
622 // TODO: check if all important configs are set
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
623
36
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
624 HttpListener *listener = http_listener_create(&lc);
129
fd324464f56f adds support for ssl cert chain files and improves ssl error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
625 if(!listener) {
fd324464f56f adds support for ssl cert chain files and improves ssl error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
626 return 1;
fd324464f56f adds support for ssl cert chain files and improves ssl error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
627 }
fd324464f56f adds support for ssl cert chain files and improves ssl error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
628
256
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
629 listener->default_vs.vs_name = sstrdup_a(cfg->a, lc.vs).ptr;
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
630 cfg->listeners = ucx_list_append_a(cfg->a, cfg->listeners, listener);
37
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
631
21
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
632 return 0;
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
633 }
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
634
256
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
635 int cfg_handle_vs(ServerConfiguration *cfg, ConfigNode *obj) {
21
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
636 VirtualServer *vs = vs_new();
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
637
256
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
638 vs->name = sstrdup_a(cfg->a, serverconfig_directive_value(obj, SC("Name")));
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
639 vs->host = sstrdup_a(cfg->a, serverconfig_directive_value(obj, SC("Host")));
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
640 vs->document_root = sstrdup_a(cfg->a, serverconfig_directive_value(obj, SC("DocRoot")));
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
641
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
642 scstr_t objfile = serverconfig_directive_value(obj, SC("ObjectFile"));
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
643 scstr_t aclfile = serverconfig_directive_value(obj, SC("ACLFile"));
51
b28cf69f42e8 added acls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
644
b28cf69f42e8 added acls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
645 // load the object config file
39
de4bc3cd2d36 added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
646 sstr_t base = sstr("config/");
99
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
647 sstr_t file = sstrcat(2, base, objfile);
255
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
648 // sstrcat with allocator because we want to keep the string
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
649 file = sstrcat_a(cfg->a, 2, base, objfile);
21
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
650
255
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
651 HTTPObjectConfig *httpobj = objconf_load(cfg, file);
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
652 if(!httpobj) {
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
653 return -1;
21
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
654 }
255
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
655 vs->objectfile = file;
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
656 vs->objects = httpobj;
99
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
657
45
a24aa388f02f added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
658
51
b28cf69f42e8 added acls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
659 // load acl config file
99
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
660 file = sstrcat(2, base, aclfile);
51
b28cf69f42e8 added acls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
661
255
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
662 ACLData *acldata = acl_conf_load(cfg, file);
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
663 if(!acldata) {
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
664 return -1;
51
b28cf69f42e8 added acls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
665 }
255
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
666 vs->acls = acldata;
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
667
99
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
668 free(file.ptr);
51
b28cf69f42e8 added acls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
669
255
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
670
45
a24aa388f02f added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
671 // set the access log for the virtual server
255
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
672 // TODO: don't always use the default
77
f1cff81e425a some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
673 vs->log = cfg->default_log;
21
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
674
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
675 ucx_map_sstr_put(cfg->host_vs, vs->host, vs);
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
676
18
73aacbf6e492 Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
677 return 0;
73aacbf6e492 Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
678 }
73aacbf6e492 Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
679
366
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
680 int cfg_handle_dav(ServerConfiguration *cfg, ConfigNode *obj) {
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
681 UcxList *backends = NULL; // list of ConfigArg*
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
682 UcxAllocator a = util_pool_allocator(cfg->pool);
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
683 int init_error;
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
684
367
1592224f6059 add support for name/value config args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
685 // parse args
1592224f6059 add support for name/value config args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
686 char *uri = NULL;
1592224f6059 add support for name/value config args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
687 char *ppath = NULL;
1592224f6059 add support for name/value config args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
688 char *name = NULL;
1592224f6059 add support for name/value config args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
689 UCX_FOREACH(elm, obj->args) {
1592224f6059 add support for name/value config args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
690 ConfigArg *arg = elm->data;
1592224f6059 add support for name/value config args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
691 if(arg->name.ptr == NULL) {
1592224f6059 add support for name/value config args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
692 // default: uri
1592224f6059 add support for name/value config args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
693 uri = arg->value.ptr;
1592224f6059 add support for name/value config args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
694 } else if(!sstrcasecmp(arg->name, SC("uri"))) {
1592224f6059 add support for name/value config args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
695 uri = arg->value.ptr;
1592224f6059 add support for name/value config args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
696 } else if(!sstrcasecmp(arg->name, SC("ppath"))) {
1592224f6059 add support for name/value config args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
697 ppath = arg->value.ptr;
1592224f6059 add support for name/value config args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
698 } else if(!sstrcasecmp(arg->name, SC("name"))) {
1592224f6059 add support for name/value config args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
699 name = arg->value.ptr;
1592224f6059 add support for name/value config args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
700 }
1592224f6059 add support for name/value config args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
701 }
1592224f6059 add support for name/value config args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
702 if(!uri && !ppath && !name) {
1592224f6059 add support for name/value config args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
703 return 1;
1592224f6059 add support for name/value config args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
704 }
1592224f6059 add support for name/value config args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
705
366
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
706 // get a list of all DavBackends
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
707 UCX_FOREACH(elm, obj->children) {
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
708 ConfigNode *node = elm->data;
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
709 if(!sstrcasecmp(node->name, SC("DavBackend"))) {
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
710 if(node->type == CONFIG_NODE_DIRECTIVE) {
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
711 if(ucx_list_size(node->args) == 1) {
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
712 ConfigArg *arg = node->args->data;
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
713 backends = ucx_list_append(backends, arg);
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
714 } else {
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
715 log_ereport(LOG_MISCONFIG, "DavBackend must have only one value");
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
716 ucx_list_free(backends);
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
717 return 1;
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
718 }
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
719 } else {
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
720 log_ereport(LOG_MISCONFIG, "DavBackend must be a directive");
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
721 ucx_list_free(backends);
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
722 return 1;
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
723 }
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
724 }
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
725 }
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
726
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
727 int ret = 0;
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
728 WebdavRepository *repository = pool_malloc(cfg->pool, sizeof(WebdavRepository));
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
729 repository->vfs = NULL;
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
730 repository->vfsInitData = NULL;
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
731 repository->davBackends = NULL;
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
732
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
733 // initialize backends
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
734 UCX_FOREACH(elm, backends) {
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
735 // the DavBackend value should contain the dav class name
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
736 ConfigArg *backendArg = elm->data;
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
737
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
738 WebdavType *dav = webdav_get_type((scstr_t){backendArg->value.ptr, backendArg->value.length});
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
739 if(!dav) {
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
740 log_ereport(LOG_MISCONFIG, "Unknown webdav backend type '%s'", backendArg->value.ptr);
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
741 ret = 1;
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
742 break;
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
743 }
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
744
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
745 // call backend init
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
746 // init_data can be NULL, errors will be indicated by init_error
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
747 void *init_data = webdav_init_backend(cfg, cfg->pool, dav, obj, &init_error);
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
748 if(init_error) {
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
749 log_ereport(LOG_FAILURE, "Failed to initialize webdav backend %s", backendArg->value.ptr);
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
750 ret = 1;
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
751 break;
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
752 }
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
753
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
754 WebdavBackendInitData *davInit = pool_malloc(cfg->pool, sizeof(WebdavBackendInitData));
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
755 if(!davInit) {
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
756 log_ereport(LOG_FAILURE, "Failed to initialize webdav backend %s: OOM", backendArg->value.ptr);
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
757 ret = 1;
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
758 break;
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
759 }
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
760 davInit->davType = dav;
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
761 davInit->davInitData = init_data;
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
762
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
763 repository->davBackends = ucx_list_append_a(&a, repository->davBackends, davInit);
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
764 }
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
765
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
766 // initialize vfs
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
767 scstr_t vfs_class = serverconfig_directive_value(obj, SC("VFS"));
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
768 if(vfs_class.length > 0) {
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
769 VfsType *vfs = vfs_get_type((scstr_t){vfs_class.ptr, vfs_class.length});
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
770 if(vfs) {
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
771 repository->vfs = vfs;
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
772 repository->vfsInitData = vfs_init_backend(cfg, cfg->pool, vfs, obj, &init_error);
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
773 ret = init_error;
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
774 } else {
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
775 log_ereport(LOG_FAILURE, "Unknown vfs type '%s'", vfs_class.ptr);
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
776 ret = 1;
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
777 }
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
778 }
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
779
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
780 scstr_t object = serverconfig_directive_value(obj, SC("Object"));
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
781 if(object.length > 0) {
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
782 repository->object = sstrdup_a(&a, object);
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
783 if(repository->object.length != object.length) {
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
784 // OOM
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
785 log_ereport(LOG_FAILURE, "Cannot create webdav repository: OOM");
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
786 ret = 1;
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
787 }
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
788 }
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
789
368
69dbcc7e7f93 implement named dav repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 367
diff changeset
790 if(!ret) {
69dbcc7e7f93 implement named dav repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 367
diff changeset
791 if(name) {
69dbcc7e7f93 implement named dav repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 367
diff changeset
792 ucx_map_cstr_put(cfg->dav, name, repository);
69dbcc7e7f93 implement named dav repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 367
diff changeset
793 } else {
69dbcc7e7f93 implement named dav repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 367
diff changeset
794 log_ereport(LOG_FAILURE, "TODO: location based dav repositories not implemented");
69dbcc7e7f93 implement named dav repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 367
diff changeset
795 ret = 1;
69dbcc7e7f93 implement named dav repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 367
diff changeset
796 }
69dbcc7e7f93 implement named dav repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 367
diff changeset
797 }
69dbcc7e7f93 implement named dav repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 367
diff changeset
798
366
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
799 return ret;
47bc686fafe4 add new dav config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 339
diff changeset
800 }
19
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
801
255
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
802 static int convert_objconf(ServerConfiguration *scfg, ObjectConfig *cfg, HTTPObjectConfig *conf, sstr_t file) {
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
803 pool_handle_t *pool = conf->pool;
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
804
91
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
805 UcxList *objlist = cfg->objects;
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
806 int i = 0;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
807 while(objlist != NULL) {
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
808 ConfigObject *cob = objlist->data;
5
dbc01588686e Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
809
74
5bc6d078fb2c listeners can be dynamically added
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
810 // get name and ppath
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
811 char *name = NULL;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
812 char *ppath = NULL;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
813 if(cob->name.length > 0) {
61
c858850f3d3a improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
814 name = sstrdup_pool(pool, cob->name).ptr;
255
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
815 if(!name) return -1;
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
816 }
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
817 if(cob->ppath.length > 0) {
61
c858850f3d3a improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
818 ppath = sstrdup_pool(pool, cob->ppath).ptr;
255
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
819 if(!ppath) return -1;
5
dbc01588686e Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
820 }
dbc01588686e Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
821
74
5bc6d078fb2c listeners can be dynamically added
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
822 // create and add object
61
c858850f3d3a improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
823 httpd_object *obj = object_new(pool, name);
255
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
824 if(!obj) return -1;
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
825 obj->path = NULL;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
826
83
28433f06d5ee added minimal nsapi conditions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 79
diff changeset
827 conf->objects[i] = obj;
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
828
74
5bc6d078fb2c listeners can be dynamically added
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
829 // add directives
133
87b405d61f64 improves event handler and ssl error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 130
diff changeset
830 for(int j=0;j<NUM_NSAPI_TYPES-1;j++) {
87b405d61f64 improves event handler and ssl error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 130
diff changeset
831 UcxList *dirs = cob->directives[j];
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
832 while(dirs != NULL) {
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
833 ConfigDirective *cfgdir = dirs->data;
255
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
834
61
c858850f3d3a improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
835 directive *d = pool_malloc(pool, sizeof(directive));
255
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
836 if(!d) return -1;
83
28433f06d5ee added minimal nsapi conditions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 79
diff changeset
837 if(cfgdir->condition) {
28433f06d5ee added minimal nsapi conditions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 79
diff changeset
838 sstr_t expr = cfgdir->condition->param_str;
28433f06d5ee added minimal nsapi conditions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 79
diff changeset
839 d->cond = condition_from_str(pool, expr.ptr, expr.length);
28433f06d5ee added minimal nsapi conditions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 79
diff changeset
840 } else {
28433f06d5ee added minimal nsapi conditions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 79
diff changeset
841 d->cond = NULL;
28433f06d5ee added minimal nsapi conditions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 79
diff changeset
842 }
61
c858850f3d3a improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
843 d->param = pblock_create_pool(pool, 8);
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
844
74
5bc6d078fb2c listeners can be dynamically added
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
845 // add params
255
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
846 UcxList *param = cfg_param_list(cfgdir->value, scfg->a);
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
847 while(param != NULL) {
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
848 ConfigParam *p = param->data;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
849 pblock_nvlinsert(
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
850 p->name.ptr,
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
851 p->name.length,
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
852 p->value.ptr,
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
853 p->value.length,
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
854 d->param);
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
855 param = param->next;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
856 }
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
857
74
5bc6d078fb2c listeners can be dynamically added
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
858 // get function
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
859 char *func_name = pblock_findval("fn", d->param);
139
29ac9aed4889 fixes some memory errors and startup with broken config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
860 if(!func_name) {
255
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
861 log_ereport(LOG_MISCONFIG, "%s: Missing fn parameter", file.ptr);
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
862 return -1;
139
29ac9aed4889 fixes some memory errors and startup with broken config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
863 }
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
864 d->func = get_function(func_name);
139
29ac9aed4889 fixes some memory errors and startup with broken config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
865 if(!d->func) {
29ac9aed4889 fixes some memory errors and startup with broken config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
866 log_ereport(LOG_MISCONFIG, "func %s not found", func_name);
255
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
867 return -1;
139
29ac9aed4889 fixes some memory errors and startup with broken config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
868 }
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
869
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
870 dirs = dirs->next;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
871
74
5bc6d078fb2c listeners can be dynamically added
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
872 // add function to dtable
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
873 object_add_directive(obj, d, cfgdir->type_num);
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
874 }
5
dbc01588686e Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
875 }
dbc01588686e Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
876
74
5bc6d078fb2c listeners can be dynamically added
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
877 // next
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
878 i++;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
879 objlist = objlist->next;
5
dbc01588686e Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
880 }
255
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
881
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
882 return 0;
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
883 }
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
884
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
885 HTTPObjectConfig* objconf_load(ServerConfiguration *scfg, sstr_t file) {
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
886 log_ereport(LOG_VERBOSE, "load_obj_conf");
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
887
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
888 int ret = 0;
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
889
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
890 // create object config
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
891 pool_handle_t *pool = scfg->pool;
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
892 HTTPObjectConfig *conf = pool_calloc(pool, sizeof(HTTPObjectConfig), 1);
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
893 if(!conf) {
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
894 return NULL;
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
895 }
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
896 conf->pool = pool;
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
897
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
898 // load obj config file
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
899 ObjectConfig *cfg = load_object_config(file.ptr);
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
900 if(!cfg) {
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
901 return NULL;
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
902 }
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
903
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
904 // convert ObjectConfig to HTTPObjectConfig
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
905
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
906 // add objects
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
907 conf->nobj = ucx_list_size(cfg->objects);
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
908 conf->objects = pool_calloc(pool, conf->nobj, sizeof(httpd_object*));
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
909 if(conf->objects) {
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
910 ret = convert_objconf(scfg, cfg, conf, file);
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
911 } else {
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
912 ret = -1;
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
913 }
5
dbc01588686e Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
914
17
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
915 free_object_config(cfg);
5
dbc01588686e Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
916
255
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
917 return !ret ? conf : NULL;
5
dbc01588686e Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
918 }
39
de4bc3cd2d36 added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
919
255
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
920 int mime_conf_load(ServerConfiguration *cfg, sstr_t file) {
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
921 MimeConfig *mimecfg = load_mime_config(file.ptr);
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
922 if(!mimecfg) {
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
923 return -1;
39
de4bc3cd2d36 added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
924 }
de4bc3cd2d36 added mime type configuration file
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
925
255
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
926 int ret = 0;
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
927
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
928 // cleanup in case of errors is done by the allocator
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
929 MimeMap *mimemap = almalloc(cfg->a, sizeof(MimeMap));
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
930 UcxMap *map = ucx_map_new_a(cfg->a, (mimecfg->ntypes * 3) / 2);
61
c858850f3d3a improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
931
255
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
932 if(mimemap && map) {
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
933 mimemap->map = map;
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
934
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
935 // add ext type pairs
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
936 UCX_FOREACH(md, mimecfg->directives) {
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
937 MimeDirective *d = md->data;
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
938 // add the type for each extension to the map
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
939 UCX_FOREACH(xl, d->exts) {
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
940 sstr_t ext = sstr(xl->data);
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
941 sstr_t value = sstrdup(d->type);
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
942 if(ucx_map_sstr_put(map, ext, value.ptr)) {
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
943 ret = -1;
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
944 break;
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
945 }
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
946 }
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
947 if(ret) {
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
948 break;
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
949 }
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
950 }
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
951
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
952 cfg->mimetypes = mimemap;
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
953 } else {
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
954 ret = -1;
61
c858850f3d3a improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
955 }
c858850f3d3a improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
956
79
f48cea237ec3 fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
957 free_mime_config(mimecfg);
255
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
958 return ret;
61
c858850f3d3a improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
959 }
c858850f3d3a improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
960
255
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
961
61
c858850f3d3a improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
962
255
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
963 ACLData* acl_conf_load(ServerConfiguration *cfg, sstr_t file) {
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
964 ACLFile *aclfile = load_acl_file(file.ptr);
51
b28cf69f42e8 added acls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
965
255
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
966 // TODO: malloc return checks
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
967
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
968 ACLData *acldata = acl_data_new(cfg->a);
91
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
969 UCX_FOREACH(elm, aclfile->namedACLs) {
51
b28cf69f42e8 added acls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
970 ACLConfig *ac = elm->data;
b28cf69f42e8 added acls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
971 ACLList *acl = acl_config_convert(cfg, ac);
115
51d9a15eac98 improves logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 106
diff changeset
972 log_ereport(LOG_VERBOSE, "add acl: %.*s", (int)ac->id.length, ac->id.ptr);
51
b28cf69f42e8 added acls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
973 ucx_map_sstr_put(acldata->namedACLs, ac->id, acl);
b28cf69f42e8 added acls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
974 }
b28cf69f42e8 added acls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
975 free_acl_file(aclfile);
b28cf69f42e8 added acls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
976
255
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
977 return acldata;
51
b28cf69f42e8 added acls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
978 }
b28cf69f42e8 added acls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
979
b28cf69f42e8 added acls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
980 ACLList* acl_config_convert(ServerConfiguration *cfg, ACLConfig *acl) {
255
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
981 UcxAllocator *a = cfg->a;
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
982
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
983 WSAcl *acllist = almalloc(cfg->a, sizeof(WSAcl));
54
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
984 acllist->acl.check = (acl_check_f)wsacl_check;
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
985 acllist->acl.authdb = NULL;
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
986 acllist->acl.authprompt = NULL;
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
987 acllist->acl.isextern = 0;
51
b28cf69f42e8 added acls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
988 acllist->ace = NULL;
b28cf69f42e8 added acls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
989 acllist->ece = NULL;
b28cf69f42e8 added acls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
990
63
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 62
diff changeset
991 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
992 acllist->acl.isextern = 1;
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 62
diff changeset
993 }
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 62
diff changeset
994
51
b28cf69f42e8 added acls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
995 size_t s = ucx_list_size(acl->entries);
255
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
996 WSAce **tmp_aces = calloc(s, sizeof(WSAce*));
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
997 WSAce **tmp_eces = calloc(s, sizeof(WSAce*));
51
b28cf69f42e8 added acls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
998 int ai = 0;
b28cf69f42e8 added acls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
999 int ei = 0;
b28cf69f42e8 added acls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1000
b28cf69f42e8 added acls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1001 // convert entries
91
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1002 UCX_FOREACH(elm, acl->entries) {
51
b28cf69f42e8 added acls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1003 ACEConfig *acecfg = elm->data;
b28cf69f42e8 added acls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1004
b28cf69f42e8 added acls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1005 // copy data
255
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
1006 WSAce *ace = almalloc(a, sizeof(WSAce));
51
b28cf69f42e8 added acls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1007 ace->access_mask = acecfg->access_mask;
b28cf69f42e8 added acls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1008 ace->flags = acecfg->flags;
b28cf69f42e8 added acls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1009 ace->type = acecfg->type;
255
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
1010 ace->who = sstrdup_a(a, acecfg->who).ptr;
51
b28cf69f42e8 added acls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1011
b28cf69f42e8 added acls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1012 // add the entry to the correct array
b28cf69f42e8 added acls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1013 if(ace->type >= ACL_TYPE_AUDIT) {
255
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
1014 tmp_eces[ei] = ace;
51
b28cf69f42e8 added acls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1015 ei++;
b28cf69f42e8 added acls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1016 } else {
255
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
1017 tmp_aces[ai] = ace;
51
b28cf69f42e8 added acls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1018 ai++;
b28cf69f42e8 added acls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1019 }
b28cf69f42e8 added acls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1020 }
b28cf69f42e8 added acls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1021
b28cf69f42e8 added acls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1022 // create new entrie arrays with perfect fitting size
b28cf69f42e8 added acls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1023 if(ai > 0) {
255
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
1024 acllist->ace = alcalloc(a, ai, sizeof(WSAce*));
51
b28cf69f42e8 added acls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1025 }
b28cf69f42e8 added acls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1026 if(ei > 0) {
255
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
1027 acllist->ece = alcalloc(a, ei, sizeof(WSAce*));
51
b28cf69f42e8 added acls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1028 }
255
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
1029 memcpy(acllist->ace, tmp_aces, ai*sizeof(WSAce*));
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
1030 memcpy(acllist->ece, tmp_eces, ei*sizeof(WSAce*));
51
b28cf69f42e8 added acls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1031 acllist->acenum = ai;
b28cf69f42e8 added acls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1032 acllist->ecenum = ei;
b28cf69f42e8 added acls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1033
255
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
1034 free(tmp_aces);
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
1035 free(tmp_eces);
51
b28cf69f42e8 added acls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1036
b28cf69f42e8 added acls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1037 // get authentication information
b28cf69f42e8 added acls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1038 if(acl->authparam) {
b28cf69f42e8 added acls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1039 sstr_t authdb_str = cfg_param_get(acl->authparam, sstr("authdb"));
b28cf69f42e8 added acls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1040 sstr_t prompt_str = cfg_param_get(acl->authparam, sstr("prompt"));
b28cf69f42e8 added acls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1041
b28cf69f42e8 added acls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1042 if(authdb_str.ptr) {
b28cf69f42e8 added acls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1043 AuthDB *authdb = ucx_map_sstr_get(cfg->authdbs, authdb_str);
54
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
1044 acllist->acl.authdb = authdb;
51
b28cf69f42e8 added acls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1045 if(authdb && prompt_str.ptr) {
255
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
1046 acllist->acl.authprompt = sstrdup_a(a, prompt_str).ptr;
51
b28cf69f42e8 added acls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1047 }
b28cf69f42e8 added acls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1048 }
b28cf69f42e8 added acls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1049 }
b28cf69f42e8 added acls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1050
54
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
1051 return &acllist->acl;
51
b28cf69f42e8 added acls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1052 }
62
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 61
diff changeset
1053
256
19259b6c5cf7 replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 255
diff changeset
1054 AuthDB* keyfile_load(ServerConfiguration *cfg, scstr_t file) {
255
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
1055 Keyfile *keyfile = keyfile_new(cfg->a);
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
1056 if(!keyfile) {
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
1057 return NULL;
62
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 61
diff changeset
1058 }
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 61
diff changeset
1059
255
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
1060 KeyfileConfig *conf = load_keyfile_config(file.ptr);
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
1061 if(!conf) {
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
1062 return NULL;
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
1063 }
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
1064
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
1065 AuthDB *ret = &keyfile->authdb;
62
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 61
diff changeset
1066
91
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 88
diff changeset
1067 UCX_FOREACH(elm, conf->users) {
62
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 61
diff changeset
1068 KeyfileEntry *user = elm->data;
255
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
1069 if(keyfile_add_user(
62
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 61
diff changeset
1070 keyfile,
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 61
diff changeset
1071 user->name,
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 61
diff changeset
1072 user->hashtype,
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 61
diff changeset
1073 user->hashdata,
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 61
diff changeset
1074 user->groups,
255
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
1075 user->numgroups))
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
1076 {
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
1077 ret = NULL;
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
1078 break;
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
1079 }
62
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 61
diff changeset
1080 }
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 61
diff changeset
1081
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 61
diff changeset
1082 free_keyfile_config(conf);
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 61
diff changeset
1083
255
b5d15a4a19f5 refactor configuration loading mechanism
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
1084 return ret;
62
c47e081b6c0f added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 61
diff changeset
1085 }
269
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
1086
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
1087 pblock* config_obj2pblock(pool_handle_t *pool, ConfigNode *obj) {
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
1088 pblock *pb = pblock_create_pool(pool, 8);
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
1089 UCX_FOREACH(elm, obj->children) {
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
1090 ConfigNode *d = elm->data;
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
1091 if(d->type == CONFIG_NODE_DIRECTIVE && d->name.length > 0 && ucx_list_size(d->args) == 1) {
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
1092 ConfigArg *arg = d->args->data;
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
1093 pblock_nvlinsert(d->name.ptr, d->name.length, arg->value.ptr, arg->value.length, pb);
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
1094 }
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
1095 }
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
1096 return pb;
3dfbd0b91950 add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
1097 }

mercurial