src/server/daemon/httprequest.c

Sun, 06 May 2012 10:09:27 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 06 May 2012 10:09:27 +0200
changeset 28
f387669912e8
parent 26
37ff8bf54b89
child 35
4417619a9bbd
permissions
-rw-r--r--

added logging

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 <stdio.h>
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 #include <stdlib.h>
24
1a7853a4257e removed some NSPR dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
31 #include <arpa/inet.h>
9
30e51941a673 Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
32
14
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
33 #include "../public/nsapi.h"
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
34 #include "../util/pool.h"
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
35 #include "../util/pblock.h"
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
36 #include "../util/io.h"
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
37 #include "../util/util.h"
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38 #include "httprequest.h"
18
73aacbf6e492 Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
39 #include "config.h"
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
40 #include "vserver.h"
19
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
41 #include "httplistener.h"
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43 HTTPRequest *http_request_new() {
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44 HTTPRequest *req = malloc(sizeof(HTTPRequest));
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45 req->connection = NULL;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46 req->uri.ptr = NULL;
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 HeaderArray *hd = malloc(sizeof(HeaderArray));
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49 hd->next = NULL;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50 hd->len = 0;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51 hd->headers = calloc(16, sizeof(Header));
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52 hd->alloc = 16;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54 req->headers = hd;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
55
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56 return req;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57 }
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
58
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59 int handle_request(HTTPRequest *request) {
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60 // handle nsapi request
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62 // create pool
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63 request->pool = pool_create();
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
64
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
65 // create nsapi data structures
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66 NSAPISession *sn = malloc(sizeof(NSAPISession));
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67 NSAPIRequest *rq = malloc(sizeof(NSAPIRequest));
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
68 request->rq = rq;
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
69 rq->phase = NSAPIAuthTrans;
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71 // fill session structure
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
72 sn->sys_fd = request->connection->fd;
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
73 sn->sn.pool = pool_create();
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
74 sn->sn.csd = stream_new_from_fd(request->connection->fd);
9
30e51941a673 Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
75 sn->sn.client = pblock_create_pool(sn->sn.pool, 8);
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
76 sn->sn.next = NULL;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
77 sn->sn.fill = 1;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
78 sn->sn.subject = NULL;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79
9
30e51941a673 Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
80 /* add ip to sn->client pblock */
30e51941a673 Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
81 char ip_str[INET_ADDRSTRLEN];
30e51941a673 Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
82 if(inet_ntop(
30e51941a673 Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
83 AF_INET,
30e51941a673 Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
84 &request->connection->address.sin_addr,
30e51941a673 Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
85 ip_str,
30e51941a673 Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
86 INET_ADDRSTRLEN) != NULL)
30e51941a673 Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
87 {
30e51941a673 Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
88 pblock_kvinsert(pb_key_ip, ip_str, INET_ADDRSTRLEN, sn->sn.client);
30e51941a673 Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
89 }
30e51941a673 Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
90
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
91 // init NSAPI request structure
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
92 if(request_initialize(request->pool, request, rq) != 0) {
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
93 printf("Cannot initialize request structure\n");
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
94 return 1;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
95 }
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
96
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
97 // set default virtual server
19
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
98 rq->vs = request->connection->listener->default_vs.vs;
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
99
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
100 /* Pass request line as "clf-request" */
20
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
101 /* TODO: with or without \r\n ? */
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
102 pblock_kvinsert(
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
103 pb_key_clf_request,
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
104 request->request_line.ptr,
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
105 request->request_line.length,
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
106 rq->rq.reqpb);
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
107
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
108 /* Pass method as "method" in reqpb, and also as method_num */
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
109 pblock_kvinsert(
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
110 pb_key_method,
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
111 request->method.ptr,
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
112 request->method.length,
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
113 rq->rq.reqpb);
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
114 // TODO: method num
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
115 //rqRq.rq.method_num = rqHdr->GetMethodNumber();
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
116 //PR_ASSERT(rqRq.rq.method_num != -1 || iStatus);
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
117
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
118 /* Pass protocol as "protocol" in reqpb, and also in protv_num */
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
119 pblock_kvinsert(
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
120 pb_key_protocol,
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
121 request->httpv.ptr,
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
122 request->httpv.length,
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
123 rq->rq.reqpb);
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
124 // TODO: protocol num
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
125
20
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
126 /*
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
127 * get absolute path and query of the request uri
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
128 */
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
129 // TODO: check for '#'
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
130 sstr_t absPath = request->uri;
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
131 sstr_t query;
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
132 query.length = 0;
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
133
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
134 for(int i=0;i<request->uri.length;i++) {
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
135 if(request->uri.ptr[i] == '?') {
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
136 /* split uri in path and query */
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
137 if(absPath.length > i + 2) {
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
138 query.length = absPath.length - i - 1;
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
139 query.ptr = absPath.ptr + i + 1;
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
140 }
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
141 absPath.length = i;
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
142
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
143 /* Pass any query as 'query' in reqpb */
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
144 pblock_kvinsert(
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
145 pb_key_query,
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
146 query.ptr,
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
147 query.length,
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
148 rq->rq.reqpb);
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
149
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
150 break;
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
151 }
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
152 }
26
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
153
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
154 /* Get abs_path part of request URI, and canonicalize the path */
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
155 absPath.ptr = util_canonicalize_uri(
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
156 request->pool,
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
157 absPath.ptr,
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
158 absPath.length,
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
159 (int*)&absPath.length);
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
160
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
161 /* Decode the abs_path */
23
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
162 // TODO: decode abs_path (done?)
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
163
20
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
164 /* Pass the abs_path as 'uri' in reqpb */
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
165 pblock_kvinsert(
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
166 pb_key_uri,
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
167 absPath.ptr,
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
168 absPath.length,
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
169 rq->rq.reqpb);
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
170
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
171 // pass http header to the NSAPI request structure
7
3c2ed7a7a5fd request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
172 int hlen = request->headers->len;
3c2ed7a7a5fd request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
173 HeaderArray *ha = request->headers;
3c2ed7a7a5fd request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
174 for(int i=0;i<=hlen;i++) {
3c2ed7a7a5fd request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
175 if(i == hlen) {
3c2ed7a7a5fd request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
176 ha = ha->next;
3c2ed7a7a5fd request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
177 if(ha == NULL) {
3c2ed7a7a5fd request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
178 break;
3c2ed7a7a5fd request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
179 }
3c2ed7a7a5fd request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
180 i = 0;
3c2ed7a7a5fd request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
181 hlen = ha->len;
3c2ed7a7a5fd request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
182 }
3c2ed7a7a5fd request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
183
8
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
184 if(ha->headers[i].name[0] < 90) {
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
185 ha->headers[i].name[0] += 32;
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
186 }
20
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
187
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
188 /* change to lower case */
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
189 char *header_name = ha->headers[i].name;
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
190 for(int i=0;header_name[i]!=0;i++) {
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
191 if(header_name[i] > 64 && header_name[i] < 97) {
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
192 header_name[i] += 32;
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
193 }
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
194 }
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
195
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
196 pblock_nvinsert(
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
197 ha->headers[i].name,
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
198 ha->headers[i].value,
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
199 rq->rq.headers);
7
3c2ed7a7a5fd request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
200 }
26
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
201
8
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
202 /* check for request body and prepare input buffer */
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
203 char *ctlen_str = pblock_findkeyval(pb_key_content_length, rq->rq.headers);
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
204 if(ctlen_str) {
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
205 int ctlen = atoi(ctlen_str);
26
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
206
8
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
207 printf("request body length: %d\n", ctlen);
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
208
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
209 netbuf *nb = request->netbuf;
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
210
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
211 /* create new netbuf */
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
212 NetIOStream *net_io = (NetIOStream*)net_stream_from_fd(
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
213 request->connection->fd);
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
214 net_io->max_read = ctlen;
26
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
215
8
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
216 sn->sn.inbuf = malloc(sizeof(netbuf));
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
217 sn->sn.inbuf->sd = net_io;
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
218 sn->sn.inbuf->pos = 0;
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
219
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
220 /* prepare buffer */
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
221 int cur_input_len = nb->cursize - nb->pos;
26
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
222
8
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
223 if(cur_input_len >= ctlen) {
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
224 /*
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
225 * all data is already in the primary input buffer
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
226 * just link the new netbuf to the primary buffer
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
227 */
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
228 sn->sn.inbuf->maxsize = ctlen;
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
229 sn->sn.inbuf->cursize = ctlen;
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
230 sn->sn.inbuf->inbuf = nb->inbuf + nb->pos;
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
231 } else {
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
232 sn->sn.inbuf->maxsize = (ctlen > 2048) ? (2048) : (ctlen);
26
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
233 sn->sn.inbuf->inbuf = malloc(sn->sn.inbuf->maxsize);
8
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
234
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
235 if(cur_input_len > 0) {
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
236 /* we have read a part of the request body -> copy to netbuf */
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
237 memcpy(sn->sn.inbuf->inbuf, nb->inbuf+nb->pos, cur_input_len);
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
238 }
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
239
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
240 sn->sn.inbuf->cursize = cur_input_len;
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
241 }
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
242 } else {
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
243 sn->sn.inbuf = NULL;
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
244 }
26
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
245
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
246
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
247 // Send the request to the NSAPI system
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
248 nsapi_handle_request(sn, rq);
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
249
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
250 return 0;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
251 }
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
252
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
253
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
254
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
255 void header_add(HeaderArray *hd, char *name, char *value) {
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
256 while(hd->len >= hd->alloc) {
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
257 if(hd->next == NULL) {
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
258 HeaderArray *block = malloc(sizeof(HeaderArray));
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
259 block->next = NULL;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
260 block->len = 0;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
261 block->headers = calloc(16, sizeof(Header));
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
262 block->alloc = 16;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
263 hd->next = block;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
264 }
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
265 hd = hd->next;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
266 }
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
267 hd->headers[hd->len].name = name;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
268 hd->headers[hd->len].value = value;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
269 hd->len++;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
270 }
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
271
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
272
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
273 /*
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
274 * NSAPI Processing
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
275 * TODO: add this to new file
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
276 */
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
277
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
278 int nsapi_handle_request(NSAPISession *sn, NSAPIRequest *rq) {
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
279 // TODO: threadpool
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
280
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
281 int r = REQ_NOACTION;
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
282
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
283 do {
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
284 switch(rq->phase) {
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
285 case NSAPIAuthTrans: {
22
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
286 r = nsapi_authtrans(sn, rq);
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
287 if(r != REQ_PROCEED) {
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
288 break;
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
289 }
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
290 rq->phase++;
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
291 nsapi_context_next_stage(&rq->context);
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
292 }
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
293 case NSAPINameTrans: {
21
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
294 //printf(">>> NameTrans\n");
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
295 r = nsapi_nametrans(sn, rq);
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
296 if(r != REQ_PROCEED) {
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
297 break;
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
298 }
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
299 rq->phase++;
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
300 nsapi_context_next_stage(&rq->context);
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
301 }
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
302 case NSAPIPathCheck: {
21
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
303 //printf(">>> PathCheck\n");
23
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
304 r = nsapi_pathcheck(sn, rq);
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
305 if(r != REQ_PROCEED) {
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
306 break;
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
307 }
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
308 rq->phase++;
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
309 nsapi_context_next_stage(&rq->context);
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
310 }
5
dbc01588686e Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
311 case NSAPIObjectType: {
21
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
312 //printf(">>> ObjectType\n");
10
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
313 r = nsapi_objecttype(sn, rq);
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
314 if(r != REQ_PROCEED) {
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
315 break;
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
316 }
5
dbc01588686e Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
317 rq->phase++;
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
318 nsapi_context_next_stage(&rq->context);
5
dbc01588686e Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
319 }
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
320 case NSAPIService: {
21
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
321 //printf(">>> Service\n");
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
322 r = nsapi_service(sn, rq);
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
323 if(r != REQ_PROCEED) {
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
324 break;
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
325 }
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
326 rq->phase++;
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
327 nsapi_context_next_stage(&rq->context);
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
328 }
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
329 case NSAPIAddLog: {
21
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
330 //printf(">>> AddLog\n");
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
331 rq->phase++;
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
332 nsapi_context_next_stage(&rq->context);
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
333 }
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
334 case REQ_FINISH: {
21
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
335 //printf(">>> Finish\n");
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
336 r = nsapi_finish_request(sn, rq);
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
337 }
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
338 }
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
339 } while (r == REQ_RESTART);
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
340
23
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
341 r = nsapi_finish_request(sn, rq);
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
342
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
343 return r;
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
344 }
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
345
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
346 int nsapi_finish_request(NSAPISession *sn, NSAPIRequest *rq) {
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
347 // TODO: free memory
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
348 close(sn->sys_fd);
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
349
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
350 return 0;
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
351 }
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
352
22
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
353 int nsapi_authtrans(NSAPISession *sn, NSAPIRequest *rq) {
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
354 HTTPObjectConfig *objconf = rq->vs->objects;
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
355 httpd_object *obj = objconf->objects[0];
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
356 dtable *dt = object_get_dtable(obj, NSAPIAuthTrans);
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
357
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
358 int ret = rq->context.last_req_code;
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
359 for(int i=NCX_DI(rq);i<dt->ndir;i++) {
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
360 directive *d = dt->dirs[i];
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
361
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
362 ret = d->func->func(d->param, (Session*)sn, (Request*)rq);
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
363 if(ret != REQ_NOACTION) {
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
364 /*
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
365 * if a saf is still processing, we need to save the context, to
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
366 * process this object at a later time
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
367 */
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
368 if(ret == REQ_PROCESSING) {
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
369 /* save nsapi context */
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
370 /* add +1 to start next round with next function */
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
371 rq->context.dtable_index = i + 1;
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
372 }
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
373
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
374 return ret;
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
375 }
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
376 }
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
377
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
378
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
379 return REQ_PROCEED;
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
380 }
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
381
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
382 int nsapi_nametrans(NSAPISession *sn, NSAPIRequest *rq) {
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
383 HTTPObjectConfig *objconf = rq->vs->objects;
21
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
384 //printf("nsapi_nametrans\n");
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
385 httpd_objset *objset = objset_create(sn->sn.pool);
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
386 rq->rq.os = objset;
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
387 /* first object in objconf is the default object TODO: make sure it is */
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
388 objset_add_object(sn->sn.pool, objset, objconf->objects[0]);
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
389
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
390 httpd_object *obj = objset->obj[0]; /* nametrans only in default object */
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
391 dtable *dt = object_get_dtable(obj, NSAPINameTrans);
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
392
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
393 /* execute directives */
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
394 int ret = rq->context.last_req_code;
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
395 char *name = NULL;
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
396 char *ppath = NULL;
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
397 for(int i=NCX_DI(rq);i<dt->ndir;i++) {
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
398 directive *d = dt->dirs[i];
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
399
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
400 ret = d->func->func(d->param, (Session*)sn, (Request*)rq);
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
401
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
402 /* check for name or ppath */
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
403 name = pblock_findkeyval(pb_key_name, rq->rq.vars);
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
404 ppath = pblock_findkeyval(pb_key_ppath, rq->rq.vars);
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
405
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
406 /* add additional objects to the objset */
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
407 if(add_objects(objconf, objset, sn, rq, name, ppath) == REQ_ABORTED) {
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
408 fprintf(stderr, "add_objects failed\n");
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
409 return REQ_ABORTED;
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
410 }
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
411
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
412 if(ret != REQ_NOACTION) {
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
413 /*
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
414 * if a saf is still processing, we need to save the context, to
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
415 * process this object at a later time
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
416 */
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
417 if(ret == REQ_PROCESSING) {
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
418 /* save nsapi context */
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
419 /* add +1 to start next round with next function */
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
420 rq->context.dtable_index = i + 1;
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
421 }
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
422
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
423 return ret;
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
424 }
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
425 }
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
426
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
427 /* if no function has set the ppath var, translate it to docroot */
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
428 if(ret == REQ_NOACTION && ppath == NULL) {
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
429 sstr_t docroot = rq->vs->document_root;
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
430 if(docroot.length < 1) {
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
431 printf("docroot too short\n");
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
432 return REQ_ABORTED; /* docroot too short */
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
433 }
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
434 /* if there is a trailing '/', remove it */
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
435 if(docroot.ptr[docroot.length - 1] == '/') {
20
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
436 docroot.ptr[docroot.length - 1] = 0; // TODO: can I do this?
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
437 docroot.length--;
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
438 }
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
439
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
440 sstr_t uri = sstr(pblock_findkeyval(pb_key_uri, rq->rq.reqpb));
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
441
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
442 sstr_t translated;
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
443 translated.length = docroot.length + uri.length;
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
444 translated.ptr = alloca(translated.length + 1);
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
445 translated = sstrncat(2, translated, docroot, uri);
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
446
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
447 pblock_kvinsert(
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
448 pb_key_ppath,
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
449 translated.ptr,
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
450 translated.length,
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
451 rq->rq.vars);
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
452 }
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
453
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
454 return REQ_PROCEED;
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
455 }
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
456
23
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
457 int nsapi_pathcheck(NSAPISession *sn, NSAPIRequest *rq) {
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
458 //printf("nsapi_pathcheck\n");
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
459 httpd_objset *objset = rq->rq.os;
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
460
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
461 if(NCX_OI(rq) == -1) {
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
462 NCX_OI(rq) = objset->pos - 1;
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
463 }
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
464
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
465 int ret = rq->context.last_req_code;
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
466 for(int i=NCX_OI(rq);i>=0;i--) {
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
467 httpd_object *obj = objset->obj[i];
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
468 dtable *dt = object_get_dtable(obj, NSAPIPathCheck);
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
469
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
470 // execute directives
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
471 for(int j=0;j<dt->ndir;j++) {
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
472 directive *d = dt->dirs[j];
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
473
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
474 /* execute the saf */
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
475 ret = d->func->func(d->param, (Session*)sn, (Request*)rq);
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
476 if(ret != REQ_NOACTION) {
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
477 if(ret == REQ_PROCESSING) {
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
478 /* save nsapi context */
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
479 rq->context.objset_index = i;
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
480
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
481 /* add +1 to start next round with next function */
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
482 rq->context.dtable_index = j + 1;
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
483 } else if(ret == REQ_ABORTED) {
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
484 if(rq->rq.status_num == PROTOCOL_UNAUTHORIZED) {
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
485 // TODO: unify error handling
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
486 protocol_start_response((Session*)sn, (Request*)rq);
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
487 }
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
488 }
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
489
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
490 return ret;
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
491 }
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
492 }
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
493 }
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
494
24
1a7853a4257e removed some NSPR dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
495 return REQ_PROCEED;
23
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
496 }
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
497
10
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
498 int nsapi_objecttype(NSAPISession *sn, NSAPIRequest *rq) {
21
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
499 //printf("nsapi_objecttype\n");
10
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
500 httpd_objset *objset = rq->rq.os;
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
501
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
502 if(NCX_OI(rq) == -1) {
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
503 /* object index is undefined -> define correct object index */
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
504 NCX_OI(rq) = objset->pos - 1;
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
505 }
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
506
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
507 int ret = rq->context.last_req_code;
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
508 for(int i=NCX_OI(rq);i>=0;i--) {
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
509 httpd_object *obj = objset->obj[i];
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
510 dtable *dt = object_get_dtable(obj, NSAPIObjectType);
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
511
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
512 // execute directives
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
513 for(int j=0;j<dt->ndir;j++) {
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
514 directive *d = dt->dirs[j];
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
515
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
516 ret = d->func->func(d->param, (Session*)sn, (Request*)rq);
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
517 switch(ret) {
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
518 case REQ_PROCEED: {
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
519 char *type = pblock_findkeyval(
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
520 pb_key_content_type,
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
521 rq->rq.srvhdrs);
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
522 if(type == NULL) {
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
523 ret = REQ_NOACTION;
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
524 break;
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
525 }
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
526 return ret;
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
527 }
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
528 case REQ_PROCESSING: {
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
529 /* save nsapi context */
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
530 rq->context.objset_index = i;
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
531
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
532 /* add +1 to start next round with next function */
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
533 rq->context.dtable_index = j + 1;
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
534 return ret;
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
535 }
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
536 case REQ_NOACTION: {
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
537 break;
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
538 }
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
539 default: {
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
540 return ret;
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
541 }
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
542 }
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
543 }
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
544 }
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
545
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
546 /*
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
547 * No function returned with REQ_PROCEED, but we need a content type.
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
548 * If the path ends with a '/', we set the content type to
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
549 * 'internal/directory' so that 'index-common' can serve the content.
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
550 * Otherwise we set the content type to text/plain
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
551 */
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
552 sstr_t path = sstr(pblock_findkeyval(pb_key_ppath, rq->rq.vars));
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
553 sstr_t ct;
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
554 if(path.ptr[path.length - 1] == '/') {
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
555 /* directory */
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
556 ct = sstrn("internal/directory", 18);
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
557 } else {
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
558 ct = sstrn("text/plain", 10);
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
559 }
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
560 pblock_kvinsert(pb_key_content_type, ct.ptr, ct.length, rq->rq.srvhdrs);
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
561
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
562 return REQ_PROCEED;
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
563 }
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
564
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
565 int nsapi_service(NSAPISession *sn, NSAPIRequest *rq) {
21
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
566 //printf("nsapi_service\n");
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
567 httpd_objset *objset = rq->rq.os;
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
568
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
569 if(NCX_OI(rq) == -1) {
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
570 NCX_OI(rq) = objset->pos - 1;
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
571 }
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
572
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
573 int ret = rq->context.last_req_code;
12
34aa8001ea53 Added directory index
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
574 char *content_type = NULL;
20
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
575 char *method = NULL;
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
576 for(int i=NCX_OI(rq);i>=0;i--) {
12
34aa8001ea53 Added directory index
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
577 httpd_object *obj = objset->obj[i];
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
578 dtable *dt = object_get_dtable(obj, NSAPIService);
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
579
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
580 // execute directives
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
581 for(int j=0;j<dt->ndir;j++) {
5
dbc01588686e Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
582 directive *d = dt->dirs[j];
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
583
12
34aa8001ea53 Added directory index
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
584 /* check type parameter */
34aa8001ea53 Added directory index
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
585 char *dtp = pblock_findkeyval(pb_key_type, d->param);
34aa8001ea53 Added directory index
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
586 if(dtp) {
34aa8001ea53 Added directory index
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
587 /* type parameter for directive */
34aa8001ea53 Added directory index
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
588 if(!content_type) {
34aa8001ea53 Added directory index
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
589 content_type = pblock_findkeyval(
34aa8001ea53 Added directory index
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
590 pb_key_content_type,
34aa8001ea53 Added directory index
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
591 rq->rq.srvhdrs);
34aa8001ea53 Added directory index
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
592 }
34aa8001ea53 Added directory index
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
593 /* compare types */
34aa8001ea53 Added directory index
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
594 if(strcmp(dtp, content_type) != 0) {
34aa8001ea53 Added directory index
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
595 continue;
34aa8001ea53 Added directory index
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
596 }
34aa8001ea53 Added directory index
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
597 }
34aa8001ea53 Added directory index
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
598
20
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
599 /* check method parameter */
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
600 char *dmt = pblock_findkeyval(pb_key_method, d->param);
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
601 if(dmt) {
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
602 if(!method) {
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
603 method = pblock_findkeyval(pb_key_method, rq->rq.reqpb);
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
604 }
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
605
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
606 if(!method_match(dmt, method)) {
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
607 continue;
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
608 }
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
609 }
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
610
21
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
611 /* execute the saf */
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
612 ret = d->func->func(d->param, (Session*)sn, (Request*)rq);
20
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
613 if(ret != REQ_PROCEED) {
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
614 fprintf(stderr, "saf not proceed\n");
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
615 }
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
616 if(ret != REQ_NOACTION) {
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
617 if(ret == REQ_PROCESSING) {
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
618 /* save nsapi context */
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
619 rq->context.objset_index = i;
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
620
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
621 /* add +1 to start next round with next function */
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
622 rq->context.dtable_index = j + 1;
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
623 }
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
624
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
625 return ret;
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
626 }
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
627 }
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
628 }
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
629
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
630 return ret;
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
631 }
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
632
20
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
633
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
634 /*
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
635 * checks if the method matches the cmp string
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
636 * the format of cmp is a single method string or a list of methods
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
637 * (method1|method2|method3|...)
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
638 */
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
639 int method_match(char *cmp, char *method) {
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
640 if(cmp[0] != '(') {
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
641 /* not a list of methods, so just compare the 2 strings */
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
642 if(!strcmp(cmp, method)) {
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
643 return 1;
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
644 }
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
645 } else if(cmp[0] == 0) {
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
646 /* empty string */
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
647 return 0;
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
648 }
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
649
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
650 size_t method_len = strlen(method);
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
651 size_t last_pos = 0;
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
652 cmp++; /* skip '(' */
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
653 for(int i=0;cmp[i]!=0;i++) {
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
654 char c = cmp[i];
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
655 if(c == '|' || c == ')') {
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
656 size_t len = i - last_pos;
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
657 if(len == method_len) {
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
658 char *cp = cmp + last_pos;
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
659 if(!memcmp(cp, method, len)) {
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
660 return 1;
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
661 }
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
662 }
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
663 last_pos = i + 1;
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
664 }
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
665 }
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
666
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
667 return 0;
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
668 }
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
669
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
670 /*
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
671 * adds objects with specific name or path to the httpd_objset
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
672 */
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
673 int add_objects(
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
674 HTTPObjectConfig *objs,
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
675 httpd_objset *os,
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
676 NSAPISession *sn,
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
677 NSAPIRequest *rq,
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
678 char *name,
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
679 char *path)
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
680 {
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
681 /* first, add all objects with a matching path */
10
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
682 /* TODO */
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
683
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
684
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
685 /* add object with object with matching name */
10
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
686 if(name == NULL) {
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
687 return REQ_PROCEED;
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
688 }
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
689
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
690 for(int i=0;i<objs->nobj;i++) {
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
691 httpd_object *obj = objs->objects[i];
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
692
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
693 if(obj->name && !strcmp(name, obj->name)) {
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
694 objset_add_object(sn->sn.pool, os, obj);
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
695 }
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
696 }
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
697
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
698 return REQ_PROCEED;
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
699 }

mercurial