src/server/daemon/config.c

Sun, 26 Feb 2012 19:51:14 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 26 Feb 2012 19:51:14 +0100
changeset 26
37ff8bf54b89
parent 25
5dee29c7c530
child 28
f387669912e8
permissions
-rw-r--r--

Minimal webdav support

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 *
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2011 Olaf Wintermann. All rights reserved.
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>
dbc01588686e Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
38 #include <sys/mman.h>
dbc01588686e Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
39
15
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
40 #include "../ucx/string.h"
5
dbc01588686e Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
41
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42 #include "httplistener.h"
18
73aacbf6e492 Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
43 #include "config.h"
5
dbc01588686e Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
44 #include "func.h"
21
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
45 #include "configmanager.h"
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
47 #include "vserver.h"
14
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
48 #include "../util/pblock.h"
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
49
17
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
50 pool_handle_t *cfg_pool;
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
51
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
52 // TODO: Funktion für ConfigDirective -> directive
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
53 // TODO: Funktion für UcxList parameter list -> pblock
18
73aacbf6e492 Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
54
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
55 void load_init_conf(char *file) {
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56 printf("load_init_conf\n");
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
57
19
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
58 InitConfig *cfg = load_init_config(file);
17
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
59 if(cfg == NULL) {
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
60 return;
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
61 }
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
62
17
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
63 cfg_pool = pool_create(); // one pool for one Configuration
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
64 UcxDlist *dirs = cfg->directives;
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
65 while(dirs != NULL) {
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
66 ConfigDirective *dir = dirs->data;
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
67
17
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
68 /* create NSAPI directive */
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
69 directive *d = malloc(sizeof(directive));
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
70 d->param = pblock_create_pool(cfg_pool, 8);
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
71 UcxList *param = dir->param;
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
72 while(param != NULL) {
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
73 ConfigParam *p = param->data;
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
74 pblock_nvlinsert(
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
75 p->name.ptr,
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
76 p->name.length,
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
77 p->value.ptr,
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
78 p->value.length,
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
79 d->param);
20
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
80
17
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
81 param = param->next;
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
82 }
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
83
17
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
84 /* get function */
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
85 char *func_name = pblock_findval("fn", d->param);
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
86 d->func = get_function(func_name);
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
87 if(d->func == NULL) {
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
88 free(d);
20
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
89 dirs = dirs->next;
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
90 continue;
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
91 }
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 /* execute init directive */
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
94 d->func->func(d->param, NULL, NULL);
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
95
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
96 dirs = dirs->next;
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
97 }
17
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
98
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
99 free_init_config(cfg);
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
100 }
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
101
21
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
102 ServerConfiguration* load_server_conf(ServerConfiguration *old, char *file) {
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
103 printf("load_server_conf\n");
18
73aacbf6e492 Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
104
19
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
105 ServerConfig *serverconf = load_server_config(file);
18
73aacbf6e492 Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
106 if(serverconf == NULL) {
73aacbf6e492 Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
107 fprintf(stderr, "Cannot load server.conf\n");
73aacbf6e492 Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
108 }
73aacbf6e492 Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
109 ServerConfiguration *serverconfig = malloc(sizeof(ServerConfiguration));
19
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
110 serverconfig->pool = pool_create();
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
111 serverconfig->listeners = NULL;
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
112 serverconfig->host_vs = ucx_map_new(16);
18
73aacbf6e492 Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
113 // TODO: init serverconfig stuff
73aacbf6e492 Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
114
73aacbf6e492 Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
115 /* convert ServerConfig to ServerConfiguration */
73aacbf6e492 Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
116 for(int i=0;i<serverconf->objects->size;i++) {
73aacbf6e492 Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
117 UcxMapElement *elm = &serverconf->objects->map[i];
73aacbf6e492 Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
118 while(elm != NULL) {
73aacbf6e492 Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
119 UcxList *list = elm->data;
73aacbf6e492 Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
120 while(list != NULL) {
73aacbf6e492 Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
121 ServerConfigObject *scfgobj = list->data;
73aacbf6e492 Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
122
21
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
123 /* handle config object */
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
124 int hr = 0;
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
125 if(!sstrcmp(scfgobj->type, sstr("Runtime"))) {
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
126 hr = cfg_handle_runtime(serverconfig, scfgobj);
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
127 } else if(!sstrcmp(scfgobj->type, sstr("LogFile"))) {
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
128 hr = cfg_handle_logfile(serverconfig, scfgobj);
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
129 } else if(!sstrcmp(scfgobj->type, sstr("AuthDB"))) {
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
130 hr = cfg_handle_authdb(serverconfig, scfgobj);
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
131 } else if(!sstrcmp(scfgobj->type, sstr("Listener"))) {
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
132 hr = cfg_handle_listener(serverconfig, scfgobj);
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
133 } else if(!sstrcmp(scfgobj->type, sstr("VirtualServer"))) {
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
134 hr = cfg_handle_vs(serverconfig, scfgobj);
18
73aacbf6e492 Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
135 }
73aacbf6e492 Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
136
21
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
137
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
138 /* next object */
18
73aacbf6e492 Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
139 list = list->next;
73aacbf6e492 Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
140 }
73aacbf6e492 Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
141
73aacbf6e492 Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
142 elm = elm->next;
73aacbf6e492 Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
143 }
73aacbf6e492 Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
144 }
19
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
145
21
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
146
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
147
19
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
148 /* set VirtualServer for all listeners */
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
149 UcxList *ls = serverconfig->listeners;
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
150 while(ls) {
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
151 HttpListener *listener = ls->data;
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
152
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
153 sstr_t vsname = sstr(listener->default_vs.vs_name);
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
154
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
155 /* search for VirtualServer */
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
156 int b = 0;
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
157 for(int i=0;i<serverconfig->host_vs->size;i++) {
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
158 UcxMapElement *elm = &serverconfig->host_vs->map[i];
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
159 while(elm != NULL && elm->data != NULL) {
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
160 VirtualServer *vs = elm->data;
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
161
19
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
162 if(!sstrcmp(vsname, vs->name)) {
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
163 b = 1;
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
164 listener->default_vs.vs = vs;
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
165 break;
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
166 }
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
167
19
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
168 elm = elm->next;
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
169 }
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
170 if(b) {
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
171 break;
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
172 }
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
173 }
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
174
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
175 ls = ls->next;
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
176 }
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
177
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
178 return serverconfig;
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
179 }
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
180
19
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
181
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
182 void init_server_config_parser() {
21
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
183
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
184 }
18
73aacbf6e492 Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
185
21
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
186 int cfg_handle_runtime(ServerConfiguration *cfg, ServerConfigObject *obj) {
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
187 cfg->user = sstrdub(cfg_directivelist_get_str(
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
188 obj->directives,
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
189 sstr("User")));
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
190 cfg->tmp = sstrdub(cfg_directivelist_get_str(
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
191 obj->directives,
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
192 sstr("Temp")));
19
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
193
21
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
194 return 0;
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
195 }
19
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
196
21
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
197 int cfg_handle_logfile(ServerConfiguration *cfg, ServerConfigObject *obj) {
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
198 /* TODO: log files */
19
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
199
21
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
200 return 0;
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
201 }
19
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
202
21
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
203 int cfg_handle_authdb(ServerConfiguration *cfg, ServerConfigObject *obj) {
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
204 /* TODO: authdb*/
19
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
205
21
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
206 return 0;
18
73aacbf6e492 Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
207 }
73aacbf6e492 Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
208
21
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
209 int cfg_handle_listener(ServerConfiguration *cfg, ServerConfigObject *obj) {
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
210 ListenerConfig lc;
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
211 lc.port = 8080;
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
212 lc.nacceptors = 1;
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
213
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
214 lc.name = sstrdub(cfg_directivelist_get_str(
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
215 obj->directives,
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
216 sstr("Name")));
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
217 lc.port = atoi(cfg_directivelist_get_str(
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
218 obj->directives,
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
219 sstr("Port")).ptr);
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
220 lc.vs = sstrdub(cfg_directivelist_get_str(
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
221 obj->directives,
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
222 sstr("DefaultVS")));
18
73aacbf6e492 Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
223
73aacbf6e492 Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
224
21
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
225 HttpListener *listener = http_listener_new(&lc);
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
226 listener->default_vs.vs_name = lc.vs.ptr;
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
227 cfg->listeners = ucx_list_append(cfg->listeners, listener);
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
228
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
229 return 0;
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
230 }
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
231
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
232 int cfg_handle_vs(ServerConfiguration *cfg, ServerConfigObject *obj) {
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
233 VirtualServer *vs = vs_new();
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
234
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
235 vs->name = sstrdub(cfg_directivelist_get_str(
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
236 obj->directives,
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
237 sstr("Name")));
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
238 vs->host = sstrdub(cfg_directivelist_get_str(
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
239 obj->directives,
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
240 sstr("Host")));
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
241 vs->document_root = sstrdub(cfg_directivelist_get_str(
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
242 obj->directives,
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
243 sstr("DocRoot")));
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
244 sstr_t objfile = cfg_directivelist_get_str(
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
245 obj->directives,
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
246 sstr("ObjectFile"));
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
247 sstr_t base = sstr("conf/");
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
248 sstr_t file;
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
249 file.length = base.length + objfile.length + 1;
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
250 file.ptr = alloca(file.length);
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
251 file.ptr[file.length] = 0;
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
252 file = sstrncat(2, file, base, objfile);
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
253
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
254 ConfigFile *f = cfgmgr_get_file(file);
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
255 if(f == NULL) {
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
256 f = malloc(sizeof(ConfigFile));
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
257 f->file = sstrdub(file);
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
258 f->reload = object_conf_reload;
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
259 f->reload(f, cfg);
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
260 cfgmgr_attach_file(f);
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
261 }
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
262 vs->objects = (HTTPObjectConfig*)f->data;
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
263
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
264 ucx_map_sstr_put(cfg->host_vs, vs->host, vs);
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
265
18
73aacbf6e492 Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
266 return 0;
73aacbf6e492 Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
267 }
73aacbf6e492 Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
268
19
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
269
21
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
270 int object_conf_reload(ConfigFile *file, ServerConfiguration *cfg) {
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
271 file->data = load_obj_conf(file->file.ptr);
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
272 struct stat s;
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
273 if(stat(file->file.ptr, &s) != 0) {
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
274 perror("object_conf_reload: stat");
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
275 return -1;
19
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
276 }
21
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
277 file->last_modified = s.st_mtim.tv_sec;
25
5dee29c7c530 Fixed config parser bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
278 return 0;
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
279 }
5
dbc01588686e Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
280
dbc01588686e Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
281 HTTPObjectConfig* load_obj_conf(char *file) {
dbc01588686e Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
282 printf("load_obj_conf\n");
dbc01588686e Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
283
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
284 // new conf function test
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
285 ObjectConfig *cfg = load_object_config(file);
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
286 if(cfg == NULL) {
5
dbc01588686e Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
287 return NULL;
dbc01588686e Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
288 }
dbc01588686e Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
289
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
290 /* create object config */
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
291 HTTPObjectConfig *conf = calloc(sizeof(HTTPObjectConfig), 1);
19
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
292 conf->pool = pool_create();
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
293
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
294 /* convert ObjectConfig to HTTPObjectConfig */
5
dbc01588686e Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
295
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
296 /* add objects */
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
297 conf->nobj = ucx_dlist_size(cfg->objects);
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
298 conf->objects = calloc(1, sizeof(httpd_object*));
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
299
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
300 UcxDlist *objlist = cfg->objects;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
301 int i = 0;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
302 while(objlist != NULL) {
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
303 ConfigObject *cob = objlist->data;
5
dbc01588686e Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
304
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
305 /* get name and ppath */
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
306 char *name = NULL;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
307 char *ppath = NULL;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
308 if(cob->name.length > 0) {
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
309 name = sstrdub(cob->name).ptr;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
310 }
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
311 if(cob->ppath.length > 0) {
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
312 ppath = sstrdub(cob->ppath).ptr;
5
dbc01588686e Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
313 }
dbc01588686e Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
314
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
315 /* create and add object */
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
316 httpd_object *obj = object_new(name);
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
317 obj->path = NULL;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
318
25
5dee29c7c530 Fixed config parser bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
319 conf->objects[i] = obj; // TODO: beyond array bounds write
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
320
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
321 /* add directives */
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
322 for(int i=0;i<6;i++) {
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
323 UcxDlist *dirs = cob->directives[i];
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
324 while(dirs != NULL) {
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
325 ConfigDirective *cfgdir = dirs->data;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
326
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
327 directive *d = malloc(sizeof(directive));
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
328 d->cond = NULL;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
329 d->param = pblock_create_pool(conf->pool, 8);
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
330
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
331 /* add params */
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
332 UcxList *param = cfgdir->param;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
333 while(param != NULL) {
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
334 ConfigParam *p = param->data;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
335 pblock_nvlinsert(
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
336 p->name.ptr,
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
337 p->name.length,
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
338 p->value.ptr,
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
339 p->value.length,
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
340 d->param);
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
341 param = param->next;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
342 }
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
343
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
344 /* get function */
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
345 char *func_name = pblock_findval("fn", d->param);
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
346 d->func = get_function(func_name);
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
347
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
348 dirs = dirs->next;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
349
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
350 /* add function to dtable */
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
351 object_add_directive(obj, d, cfgdir->type_num);
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
352 }
5
dbc01588686e Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
353 }
dbc01588686e Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
354
16
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
355 /* next */
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
356 i++;
a9bbd82d2dce New configuration file parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
357 objlist = objlist->next;
5
dbc01588686e Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
358 }
dbc01588686e Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
359
17
d2a97bbeb57d Added init.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 16
diff changeset
360 free_object_config(cfg);
5
dbc01588686e Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
361
dbc01588686e Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
362 return conf;
dbc01588686e Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
363 }

mercurial