src/server/conf.c

Sun, 13 Nov 2011 13:43:01 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 13 Nov 2011 13:43:01 +0100
changeset 4
998844b5ed25
parent 3
137197831306
child 5
dbc01588686e
permissions
-rw-r--r--

Added some protocol functions

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
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include "nsapi.h"
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
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34 #include "httplistener.h"
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35 #include "conf.h"
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
37 #include "vserver.h"
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
38
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
39 VirtualServer *default_vs;
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
40
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41 void load_init_conf(char *file) {
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42 printf("load_init_conf\n");
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43 }
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45 void load_server_conf(char *file) {
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46 printf("load_server_conf\n");
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48 ListenerConfig *conf = malloc(sizeof(ListenerConfig));
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49 conf->port = 8080;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50 conf->nacceptors = 1;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51 conf->name = "default";
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53 http_listener_new(conf);
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
54
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
55 // virtual server
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
56 default_vs = vs_new();
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
57 default_vs->objset = create_test_objset();
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
58 default_vs->default_obj_name = "default";
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
59
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
60 // begin objset test
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
61 /*
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
62 httpd_objset *objset = default_vs->objset;
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
63 for(int i=0;i<objset->pos;i++) {
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
64 httpd_object *obj = objset->obj[i];
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
65 printf("<object [%s]>\n", obj->name);
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
66 for(int j=0;j<obj->nd;j++) {
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
67 dtable *dt;
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
68 switch(j) {
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
69 case NSAPIAuthTrans: {
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
70 printf(" Get AuthTrans Directives\n");
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
71 dt = object_get_dtable(obj, NSAPIAuthTrans);
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
72 break;
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
73 }
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
74 case NSAPINameTrans: {
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
75 printf(" Get NameTrans Directives\n");
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
76 dt = object_get_dtable(obj, NSAPINameTrans);
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
77 break;
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
78 }
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
79 case NSAPIPathCheck: {
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
80 printf(" Get PathCheck Directives\n");
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
81 dt = object_get_dtable(obj, NSAPIPathCheck);
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
82 break;
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
83 }
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
84 case NSAPIService: {
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
85 printf(" Get Service Directives\n");
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
86 dt = object_get_dtable(obj, NSAPIService);
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
87 break;
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
88 }
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
89 default: {
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
90 printf("j: %d\n", j);
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
91 dt = object_get_dtable(obj, j);
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
92 break;
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
93 }
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
94 }
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
95 if(dt != NULL) {
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
96 printf(" dtable[%d].length = %d\n", dt, dt->ndir);
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
97 } else {
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
98 continue;
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
99 }
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
100 for(int k=0;k<dt->ndir;k++) {
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
101 directive *d = dt->directive[k];
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
102 if(d == NULL) {
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
103 printf("d is null\n");
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
104 } else {
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
105 printf(" Directive[%d].name = %s\n", d, d->func->name);
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
106 }
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
107 }
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
108 }
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
109 }
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
110 */
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
111 // end objset test
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
112 }
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
113
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
114 VirtualServer* conf_get_default_vs() {
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
115 return default_vs;
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
116 }

mercurial