Mon, 24 Jun 2013 14:41:32 +0200
removed config.mk
1 | 1 | /* |
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. | |
3 | * | |
44
3da1f7b6847f
added some error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
4 | * Copyright 2013 Olaf Wintermann. All rights reserved. |
1 | 5 | * |
6 | * Redistribution and use in source and binary forms, with or without | |
7 | * modification, are permitted provided that the following conditions are met: | |
8 | * | |
9 | * 1. Redistributions of source code must retain the above copyright | |
10 | * notice, this list of conditions and the following disclaimer. | |
11 | * | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | |
15 | * | |
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | |
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
26 | * POSSIBILITY OF SUCH DAMAGE. | |
27 | */ | |
28 | ||
29 | #include <stdio.h> | |
30 | #include <stdlib.h> | |
35
4417619a9bbd
using non blocking IO for request input
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
31 | |
24
1a7853a4257e
removed some NSPR dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
23
diff
changeset
|
32 | #include <arpa/inet.h> |
9
30e51941a673
Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
33 | |
14
b8bf95b39952
New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
34 | #include "../public/nsapi.h" |
b8bf95b39952
New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
35 | #include "../util/pool.h" |
b8bf95b39952
New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
36 | #include "../util/pblock.h" |
b8bf95b39952
New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
37 | #include "../util/io.h" |
b8bf95b39952
New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
38 | #include "../util/util.h" |
1 | 39 | #include "httprequest.h" |
18
73aacbf6e492
Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
40 | #include "config.h" |
3
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
41 | #include "vserver.h" |
19
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
42 | #include "httplistener.h" |
44
3da1f7b6847f
added some error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
43 | #include "error.h" |
1 | 44 | |
46
636e05eb48f6
cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
45 | void http_request_init(HTTPRequest *req) { |
1 | 46 | req->connection = NULL; |
47 | req->uri.ptr = NULL; | |
48 | ||
49 | HeaderArray *hd = malloc(sizeof(HeaderArray)); | |
50 | hd->next = NULL; | |
51 | hd->len = 0; | |
52 | hd->headers = calloc(16, sizeof(Header)); | |
53 | hd->alloc = 16; | |
54 | ||
55 | req->headers = hd; | |
56 | } | |
57 | ||
37
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
58 | int handle_request(HTTPRequest *request, threadpool_t *thrpool) { |
1 | 59 | // handle nsapi request |
60 | ||
61 | // create pool | |
46
636e05eb48f6
cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
62 | pool_handle_t *pool = pool_create(); |
1 | 63 | |
64 | // create nsapi data structures | |
46
636e05eb48f6
cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
65 | NSAPISession *sn = pool_malloc(pool, sizeof(NSAPISession)); |
35
4417619a9bbd
using non blocking IO for request input
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
66 | if(sn == NULL) { |
4417619a9bbd
using non blocking IO for request input
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
67 | /* TODO: error */ |
4417619a9bbd
using non blocking IO for request input
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
68 | } |
46
636e05eb48f6
cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
69 | NSAPIRequest *rq = pool_malloc(pool, sizeof(NSAPIRequest)); |
35
4417619a9bbd
using non blocking IO for request input
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
70 | if(rq == NULL) { |
4417619a9bbd
using non blocking IO for request input
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
71 | /* TODO: error */ |
4417619a9bbd
using non blocking IO for request input
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
72 | } |
1 | 73 | request->rq = rq; |
3
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
74 | rq->phase = NSAPIAuthTrans; |
1 | 75 | |
76 | // fill session structure | |
46
636e05eb48f6
cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
77 | sn->connection = request->connection; |
636e05eb48f6
cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
78 | sn->netbuf = request->netbuf; |
636e05eb48f6
cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
79 | sn->sn.pool = pool; |
54 | 80 | //sn->sn.csd = stream_new_from_fd(pool, request->connection->fd); |
81 | sn->sn.csd = net_stream_from_fd(pool, request->connection->fd); | |
9
30e51941a673
Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
82 | sn->sn.client = pblock_create_pool(sn->sn.pool, 8); |
1 | 83 | sn->sn.next = NULL; |
84 | sn->sn.fill = 1; | |
85 | sn->sn.subject = NULL; | |
38
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
86 | |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
87 | // the session needs the current server configuration |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
37
diff
changeset
|
88 | sn->config = request->connection->listener->cfg; // TODO: ref |
1 | 89 | |
46
636e05eb48f6
cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
90 | // add ip to sn->client pblock |
9
30e51941a673
Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
91 | char ip_str[INET_ADDRSTRLEN]; |
30e51941a673
Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
92 | if(inet_ntop( |
30e51941a673
Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
93 | AF_INET, |
30e51941a673
Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
94 | &request->connection->address.sin_addr, |
30e51941a673
Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
95 | ip_str, |
30e51941a673
Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
96 | INET_ADDRSTRLEN) != NULL) |
30e51941a673
Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
97 | { |
30e51941a673
Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
98 | 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
|
99 | } |
30e51941a673
Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
100 | |
1 | 101 | // init NSAPI request structure |
46
636e05eb48f6
cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
102 | if(request_initialize(pool, request, rq) != 0) { |
60
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
103 | log_ereport(LOG_FAILURE, "Cannot initialize request structure"); |
47
ce9790523346
server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
104 | pool_destroy(pool); |
1 | 105 | return 1; |
106 | } | |
107 | ||
3
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
108 | // set default virtual server |
19
d680536f8c2f
Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
18
diff
changeset
|
109 | rq->vs = request->connection->listener->default_vs.vs; |
3
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
110 | |
46
636e05eb48f6
cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
111 | // Pass request line as "clf-request" |
636e05eb48f6
cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
112 | // remove \r\n |
45
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
113 | sstr_t clfreq = request->request_line; |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
114 | while(clfreq.ptr[clfreq.length - 1] < 33) { |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
115 | clfreq.length--; |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
116 | } |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
117 | request->request_line = clfreq; |
1 | 118 | pblock_kvinsert( |
119 | pb_key_clf_request, | |
120 | request->request_line.ptr, | |
121 | request->request_line.length, | |
122 | rq->rq.reqpb); | |
123 | ||
59
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
124 | // Pass method as "method" in reqpb, and also as method_num |
1 | 125 | pblock_kvinsert( |
126 | pb_key_method, | |
127 | request->method.ptr, | |
128 | request->method.length, | |
129 | rq->rq.reqpb); | |
130 | // TODO: method num | |
131 | //rqRq.rq.method_num = rqHdr->GetMethodNumber(); | |
132 | //PR_ASSERT(rqRq.rq.method_num != -1 || iStatus); | |
133 | ||
59
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
134 | // Pass protocol as "protocol" in reqpb, and also in protv_num |
1 | 135 | pblock_kvinsert( |
136 | pb_key_protocol, | |
137 | request->httpv.ptr, | |
138 | request->httpv.length, | |
139 | rq->rq.reqpb); | |
140 | // TODO: protocol num | |
141 | ||
20
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 | * 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
|
144 | */ |
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
145 | // TODO: check for '#' |
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
146 | sstr_t absPath = request->uri; |
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
147 | sstr_t query; |
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
148 | query.length = 0; |
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 | 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
|
151 | if(request->uri.ptr[i] == '?') { |
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
152 | /* split uri in path and query */ |
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
153 | if(absPath.length > i + 2) { |
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
154 | query.length = absPath.length - i - 1; |
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
155 | query.ptr = absPath.ptr + i + 1; |
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
156 | } |
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
157 | absPath.length = i; |
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
158 | |
59
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
159 | // Pass any query as 'query' in reqpb |
20
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
160 | pblock_kvinsert( |
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
161 | pb_key_query, |
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
162 | query.ptr, |
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
163 | query.length, |
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
164 | rq->rq.reqpb); |
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
165 | |
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
166 | break; |
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
167 | } |
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
168 | } |
26
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
169 | |
59
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
170 | // Get abs_path part of request URI, and canonicalize the path |
1 | 171 | absPath.ptr = util_canonicalize_uri( |
46
636e05eb48f6
cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
172 | pool, |
1 | 173 | absPath.ptr, |
174 | absPath.length, | |
175 | (int*)&absPath.length); | |
176 | ||
59
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
177 | // Decode the abs_path |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
178 | if(util_uri_unescape_strict(absPath.ptr)) { |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
179 | // Pass the abs_path as 'uri' in reqpb |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
180 | pblock_kvinsert( |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
181 | pb_key_uri, |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
182 | absPath.ptr, |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
183 | absPath.length, |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
184 | rq->rq.reqpb); |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
185 | } else { |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
186 | // TODO: log error |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
187 | printf("unescape failed\n"); |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
188 | pblock_kvinsert(pb_key_uri, "/", 1, rq->rq.reqpb); |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
189 | } |
1 | 190 | |
191 | // pass http header to the NSAPI request structure | |
59
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
192 | int hlen = request->headers->len; |
7
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
6
diff
changeset
|
193 | HeaderArray *ha = request->headers; |
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
6
diff
changeset
|
194 | for(int i=0;i<=hlen;i++) { |
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
6
diff
changeset
|
195 | if(i == hlen) { |
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
6
diff
changeset
|
196 | ha = ha->next; |
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
6
diff
changeset
|
197 | if(ha == NULL) { |
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
6
diff
changeset
|
198 | break; |
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
6
diff
changeset
|
199 | } |
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
6
diff
changeset
|
200 | i = 0; |
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
6
diff
changeset
|
201 | hlen = ha->len; |
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
6
diff
changeset
|
202 | } |
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
6
diff
changeset
|
203 | |
8
f4d56bf9de40
Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
204 | if(ha->headers[i].name[0] < 90) { |
f4d56bf9de40
Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
205 | ha->headers[i].name[0] += 32; |
f4d56bf9de40
Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
206 | } |
20
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
207 | |
46
636e05eb48f6
cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
208 | // change to lower case |
20
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
209 | char *header_name = ha->headers[i].name; |
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
210 | 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
|
211 | 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
|
212 | header_name[i] += 32; |
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
213 | } |
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
214 | } |
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
215 | |
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
216 | pblock_nvinsert( |
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
217 | ha->headers[i].name, |
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
218 | ha->headers[i].value, |
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
219 | rq->rq.headers); |
7
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
6
diff
changeset
|
220 | } |
26
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
221 | |
46
636e05eb48f6
cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
222 | // check for request body and prepare input buffer |
8
f4d56bf9de40
Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
223 | 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
|
224 | if(ctlen_str) { |
f4d56bf9de40
Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
225 | int ctlen = atoi(ctlen_str); |
26
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
226 | |
8
f4d56bf9de40
Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
227 | printf("request body length: %d\n", ctlen); |
f4d56bf9de40
Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
228 | |
f4d56bf9de40
Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
229 | netbuf *nb = request->netbuf; |
f4d56bf9de40
Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
230 | |
59
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
231 | // create new netbuf |
8
f4d56bf9de40
Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
232 | NetIOStream *net_io = (NetIOStream*)net_stream_from_fd( |
46
636e05eb48f6
cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
233 | pool, |
8
f4d56bf9de40
Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
234 | request->connection->fd); |
f4d56bf9de40
Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
235 | net_io->max_read = ctlen; |
26
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
236 | |
46
636e05eb48f6
cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
237 | sn->sn.inbuf = pool_malloc(pool, sizeof(netbuf)); |
8
f4d56bf9de40
Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
238 | sn->sn.inbuf->sd = net_io; |
f4d56bf9de40
Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
239 | sn->sn.inbuf->pos = 0; |
f4d56bf9de40
Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
240 | |
46
636e05eb48f6
cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
241 | // prepare buffer |
8
f4d56bf9de40
Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
242 | int cur_input_len = nb->cursize - nb->pos; |
26
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
243 | |
8
f4d56bf9de40
Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
244 | if(cur_input_len >= ctlen) { |
f4d56bf9de40
Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
245 | /* |
f4d56bf9de40
Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
246 | * all data is already in the primary input buffer |
f4d56bf9de40
Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
247 | * just link the new netbuf to the primary buffer |
f4d56bf9de40
Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
248 | */ |
f4d56bf9de40
Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
249 | sn->sn.inbuf->maxsize = ctlen; |
f4d56bf9de40
Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
250 | sn->sn.inbuf->cursize = ctlen; |
f4d56bf9de40
Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
251 | sn->sn.inbuf->inbuf = nb->inbuf + nb->pos; |
f4d56bf9de40
Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
252 | } else { |
f4d56bf9de40
Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
253 | sn->sn.inbuf->maxsize = (ctlen > 2048) ? (2048) : (ctlen); |
46
636e05eb48f6
cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
254 | sn->sn.inbuf->inbuf = pool_malloc(pool, sn->sn.inbuf->maxsize); |
8
f4d56bf9de40
Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
255 | |
f4d56bf9de40
Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
256 | if(cur_input_len > 0) { |
46
636e05eb48f6
cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
257 | // we have read a part of the request body -> copy to netbuf |
8
f4d56bf9de40
Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
258 | 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
|
259 | } |
f4d56bf9de40
Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
260 | |
f4d56bf9de40
Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
261 | sn->sn.inbuf->cursize = cur_input_len; |
f4d56bf9de40
Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
262 | } |
f4d56bf9de40
Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
263 | } else { |
f4d56bf9de40
Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
264 | sn->sn.inbuf = NULL; |
f4d56bf9de40
Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
7
diff
changeset
|
265 | } |
26
37ff8bf54b89
Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
266 | |
37
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
267 | // |
1 | 268 | // Send the request to the NSAPI system |
37
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
269 | // |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
270 | |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
271 | // compare current and listener thread pool |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
272 | threadpool_t *lstp = request->connection->listener->threadpool; |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
273 | sn->defaultpool = lstp; |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
274 | if(lstp == thrpool) { |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
275 | sn->currentpool = thrpool; |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
276 | nsapi_handle_request(sn, rq); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
277 | } else { |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
278 | // execute nsapi functions on a different thread pool |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
279 | nsapi_change_threadpool(sn, rq, lstp); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
280 | } |
1 | 281 | |
282 | return 0; | |
283 | } | |
284 | ||
285 | ||
286 | ||
287 | void header_add(HeaderArray *hd, char *name, char *value) { | |
288 | while(hd->len >= hd->alloc) { | |
289 | if(hd->next == NULL) { | |
290 | HeaderArray *block = malloc(sizeof(HeaderArray)); | |
291 | block->next = NULL; | |
292 | block->len = 0; | |
293 | block->headers = calloc(16, sizeof(Header)); | |
294 | block->alloc = 16; | |
295 | hd->next = block; | |
296 | } | |
297 | hd = hd->next; | |
298 | } | |
299 | hd->headers[hd->len].name = name; | |
300 | hd->headers[hd->len].value = value; | |
301 | hd->len++; | |
302 | } | |
303 | ||
46
636e05eb48f6
cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
304 | void header_array_free(HeaderArray *hd) { |
636e05eb48f6
cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
305 | HeaderArray *next; |
636e05eb48f6
cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
306 | while(hd) { |
636e05eb48f6
cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
307 | next = hd->next; |
636e05eb48f6
cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
308 | free(hd->headers); |
636e05eb48f6
cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
309 | free(hd); |
636e05eb48f6
cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
310 | hd = next; |
636e05eb48f6
cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
311 | } |
636e05eb48f6
cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
312 | } |
636e05eb48f6
cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
313 | |
3
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
314 | |
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
315 | /* |
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
316 | * NSAPI Processing |
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
317 | * TODO: add this to new file |
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
318 | */ |
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
319 | |
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
320 | int nsapi_handle_request(NSAPISession *sn, NSAPIRequest *rq) { |
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
321 | int r = REQ_NOACTION; |
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
322 | |
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
323 | do { |
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
324 | switch(rq->phase) { |
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
325 | case NSAPIAuthTrans: { |
22
adb0bda54e6b
Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
326 | r = nsapi_authtrans(sn, rq); |
adb0bda54e6b
Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
327 | if(r != REQ_PROCEED) { |
adb0bda54e6b
Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
328 | break; |
adb0bda54e6b
Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
329 | } |
3
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
330 | rq->phase++; |
6
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
331 | nsapi_context_next_stage(&rq->context); |
3
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
332 | } |
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
333 | case NSAPINameTrans: { |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
334 | //printf(">>> NameTrans\n"); |
3
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
335 | r = nsapi_nametrans(sn, rq); |
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
336 | if(r != REQ_PROCEED) { |
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
337 | break; |
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 | rq->phase++; |
6
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
340 | nsapi_context_next_stage(&rq->context); |
3
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
341 | } |
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
342 | case NSAPIPathCheck: { |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
343 | //printf(">>> PathCheck\n"); |
23
a2c8fc23c90e
Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
344 | r = nsapi_pathcheck(sn, rq); |
a2c8fc23c90e
Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
345 | if(r != REQ_PROCEED) { |
a2c8fc23c90e
Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
346 | break; |
a2c8fc23c90e
Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
347 | } |
3
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
348 | rq->phase++; |
6
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
349 | nsapi_context_next_stage(&rq->context); |
3
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
350 | } |
5
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
351 | case NSAPIObjectType: { |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
352 | //printf(">>> ObjectType\n"); |
10 | 353 | r = nsapi_objecttype(sn, rq); |
354 | if(r != REQ_PROCEED) { | |
355 | break; | |
356 | } | |
5
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
357 | rq->phase++; |
6
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
358 | nsapi_context_next_stage(&rq->context); |
5
dbc01588686e
Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
359 | } |
3
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
360 | case NSAPIService: { |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
361 | //printf(">>> Service\n"); |
3
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
362 | r = nsapi_service(sn, rq); |
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
363 | if(r != REQ_PROCEED) { |
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
364 | break; |
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
365 | } |
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
366 | rq->phase++; |
6
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
367 | nsapi_context_next_stage(&rq->context); |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
368 | } |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
369 | case NSAPIAddLog: { |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
370 | //printf(">>> AddLog\n"); |
45
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
371 | r = nsapi_addlog(sn, rq); |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
372 | if(r != REQ_PROCESSING && r != REQ_ABORTED) { |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
373 | break; |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
374 | } |
6
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
375 | rq->phase++; |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
376 | nsapi_context_next_stage(&rq->context); |
3
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
377 | } |
70
4e6e812c1d97
fixed some warnings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
378 | default: // should not happen, but when it does, finish the req |
3
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
379 | case REQ_FINISH: { |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
380 | //printf(">>> Finish\n"); |
3
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
381 | r = nsapi_finish_request(sn, rq); |
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
382 | } |
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
383 | } |
35
4417619a9bbd
using non blocking IO for request input
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
384 | |
4417619a9bbd
using non blocking IO for request input
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
385 | if(r == REQ_ABORTED) { |
44
3da1f7b6847f
added some error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
386 | // if an error occurred, we send an error page |
3da1f7b6847f
added some error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
387 | nsapi_error_request((Session*)sn, (Request*)rq); |
3da1f7b6847f
added some error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
388 | break; |
35
4417619a9bbd
using non blocking IO for request input
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
389 | } |
4417619a9bbd
using non blocking IO for request input
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
26
diff
changeset
|
390 | |
3
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
391 | } while (r == REQ_RESTART); |
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
392 | |
37
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
393 | if(r != REQ_PROCESSING) { |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
394 | r = nsapi_finish_request(sn, rq); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
395 | } |
3
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
396 | |
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
397 | return r; |
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
398 | } |
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
399 | |
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
400 | int nsapi_finish_request(NSAPISession *sn, NSAPIRequest *rq) { |
46
636e05eb48f6
cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
401 | // TODO: keep alive |
636e05eb48f6
cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
402 | close(sn->connection->fd); |
636e05eb48f6
cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
403 | |
61
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
404 | cfg_unref(sn->config); |
c858850f3d3a
improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
405 | |
46
636e05eb48f6
cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
406 | // free all memory |
636e05eb48f6
cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
407 | free(sn->connection); |
636e05eb48f6
cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
408 | |
636e05eb48f6
cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
409 | free(sn->netbuf->inbuf); |
636e05eb48f6
cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
410 | free(sn->netbuf); |
636e05eb48f6
cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
411 | |
636e05eb48f6
cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
412 | pool_destroy(sn->sn.pool); |
6
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
413 | |
3
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
414 | return 0; |
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
415 | } |
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
416 | |
22
adb0bda54e6b
Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
417 | int nsapi_authtrans(NSAPISession *sn, NSAPIRequest *rq) { |
adb0bda54e6b
Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
418 | HTTPObjectConfig *objconf = rq->vs->objects; |
adb0bda54e6b
Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
419 | httpd_object *obj = objconf->objects[0]; |
adb0bda54e6b
Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
420 | dtable *dt = object_get_dtable(obj, NSAPIAuthTrans); |
adb0bda54e6b
Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
421 | |
adb0bda54e6b
Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
422 | int ret = rq->context.last_req_code; |
adb0bda54e6b
Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
423 | for(int i=NCX_DI(rq);i<dt->ndir;i++) { |
37
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
424 | if(ret == REQ_NOACTION) { |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
425 | directive *d = dt->dirs[i]; |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
426 | ret = nsapi_exec(d, sn, rq); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
427 | } |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
428 | |
22
adb0bda54e6b
Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
429 | if(ret != REQ_NOACTION) { |
adb0bda54e6b
Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
430 | /* |
adb0bda54e6b
Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
431 | * 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
|
432 | * process this object at a later time |
adb0bda54e6b
Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
433 | */ |
adb0bda54e6b
Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
434 | if(ret == REQ_PROCESSING) { |
adb0bda54e6b
Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
435 | /* save nsapi context */ |
adb0bda54e6b
Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
436 | /* 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
|
437 | rq->context.dtable_index = i + 1; |
adb0bda54e6b
Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
438 | } |
adb0bda54e6b
Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
439 | |
adb0bda54e6b
Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
440 | return ret; |
adb0bda54e6b
Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
441 | } |
adb0bda54e6b
Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
442 | } |
adb0bda54e6b
Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
443 | |
adb0bda54e6b
Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
444 | |
adb0bda54e6b
Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
445 | return REQ_PROCEED; |
adb0bda54e6b
Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
446 | } |
adb0bda54e6b
Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
447 | |
3
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
448 | int nsapi_nametrans(NSAPISession *sn, NSAPIRequest *rq) { |
6
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
449 | HTTPObjectConfig *objconf = rq->vs->objects; |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
450 | //printf("nsapi_nametrans\n"); |
6
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
451 | httpd_objset *objset = objset_create(sn->sn.pool); |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
452 | rq->rq.os = objset; |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
453 | /* 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
|
454 | 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
|
455 | |
6
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
456 | 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
|
457 | dtable *dt = object_get_dtable(obj, NSAPINameTrans); |
3
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
458 | |
6
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
459 | /* execute directives */ |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
460 | int ret = rq->context.last_req_code; |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
461 | char *name = NULL; |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
462 | char *ppath = NULL; |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
463 | for(int i=NCX_DI(rq);i<dt->ndir;i++) { |
37
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
464 | if(ret == REQ_NOACTION) { |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
465 | directive *d = dt->dirs[i]; |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
466 | ret = nsapi_exec(d, sn, rq); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
467 | } |
6
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
468 | |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
469 | /* check for name or ppath */ |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
470 | name = pblock_findkeyval(pb_key_name, rq->rq.vars); |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
471 | ppath = pblock_findkeyval(pb_key_ppath, rq->rq.vars); |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
472 | |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
473 | /* add additional objects to the objset */ |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
474 | 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
|
475 | fprintf(stderr, "add_objects failed\n"); |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
476 | return REQ_ABORTED; |
3
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
477 | } |
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
478 | |
6
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
479 | if(ret != REQ_NOACTION) { |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
480 | /* |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
481 | * 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
|
482 | * process this object at a later time |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
483 | */ |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
484 | if(ret == REQ_PROCESSING) { |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
485 | /* save nsapi context */ |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
486 | /* add +1 to start next round with next function */ |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
487 | rq->context.dtable_index = i + 1; |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
488 | } |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
489 | |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
490 | return ret; |
3
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
491 | } |
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
492 | } |
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
493 | |
6
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
494 | /* 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
|
495 | if(ret == REQ_NOACTION && ppath == NULL) { |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
496 | sstr_t docroot = rq->vs->document_root; |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
497 | if(docroot.length < 1) { |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
498 | printf("docroot too short\n"); |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
499 | return REQ_ABORTED; /* docroot too short */ |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
500 | } |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
501 | /* if there is a trailing '/', remove it */ |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
502 | if(docroot.ptr[docroot.length - 1] == '/') { |
36
450d2d5f4735
server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
503 | //docroot.ptr[docroot.length - 1] = 0; // TODO: can I do this? No!! |
6
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
504 | docroot.length--; |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
505 | } |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
506 | |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
507 | 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
|
508 | |
6
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
509 | sstr_t translated; |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
510 | translated.length = docroot.length + uri.length; |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
511 | translated.ptr = alloca(translated.length + 1); |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
512 | translated = sstrncat(2, translated, docroot, uri); |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
513 | |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
514 | pblock_kvinsert( |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
515 | pb_key_ppath, |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
516 | translated.ptr, |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
517 | translated.length, |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
518 | rq->rq.vars); |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
519 | } |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
520 | |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
521 | return REQ_PROCEED; |
3
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
522 | } |
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
523 | |
23
a2c8fc23c90e
Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
524 | int nsapi_pathcheck(NSAPISession *sn, NSAPIRequest *rq) { |
a2c8fc23c90e
Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
525 | //printf("nsapi_pathcheck\n"); |
a2c8fc23c90e
Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
526 | httpd_objset *objset = rq->rq.os; |
a2c8fc23c90e
Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
527 | |
a2c8fc23c90e
Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
528 | if(NCX_OI(rq) == -1) { |
a2c8fc23c90e
Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
529 | NCX_OI(rq) = objset->pos - 1; |
a2c8fc23c90e
Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
530 | } |
a2c8fc23c90e
Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
531 | |
a2c8fc23c90e
Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
532 | int ret = rq->context.last_req_code; |
a2c8fc23c90e
Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
533 | for(int i=NCX_OI(rq);i>=0;i--) { |
a2c8fc23c90e
Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
534 | httpd_object *obj = objset->obj[i]; |
a2c8fc23c90e
Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
535 | dtable *dt = object_get_dtable(obj, NSAPIPathCheck); |
a2c8fc23c90e
Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
536 | |
a2c8fc23c90e
Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
537 | // execute directives |
37
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
538 | for(int j=NCX_DI(rq);j<dt->ndir;j++) { |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
539 | if(ret == REQ_NOACTION) { |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
540 | directive *d = dt->dirs[j]; |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
541 | ret = nsapi_exec(d, sn, rq); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
542 | } |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
543 | |
23
a2c8fc23c90e
Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
544 | if(ret != REQ_NOACTION) { |
a2c8fc23c90e
Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
545 | if(ret == REQ_PROCESSING) { |
a2c8fc23c90e
Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
546 | /* save nsapi context */ |
a2c8fc23c90e
Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
547 | rq->context.objset_index = i; |
a2c8fc23c90e
Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
548 | |
a2c8fc23c90e
Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
549 | /* add +1 to start next round with next function */ |
a2c8fc23c90e
Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
550 | rq->context.dtable_index = j + 1; |
a2c8fc23c90e
Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
551 | } |
a2c8fc23c90e
Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
552 | |
a2c8fc23c90e
Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
553 | return ret; |
a2c8fc23c90e
Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
554 | } |
a2c8fc23c90e
Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
555 | } |
a2c8fc23c90e
Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
556 | } |
a2c8fc23c90e
Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
557 | |
24
1a7853a4257e
removed some NSPR dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
23
diff
changeset
|
558 | return REQ_PROCEED; |
23
a2c8fc23c90e
Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
559 | } |
a2c8fc23c90e
Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
560 | |
10 | 561 | int nsapi_objecttype(NSAPISession *sn, NSAPIRequest *rq) { |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
562 | //printf("nsapi_objecttype\n"); |
10 | 563 | httpd_objset *objset = rq->rq.os; |
564 | ||
565 | if(NCX_OI(rq) == -1) { | |
566 | /* object index is undefined -> define correct object index */ | |
567 | NCX_OI(rq) = objset->pos - 1; | |
568 | } | |
569 | ||
570 | int ret = rq->context.last_req_code; | |
571 | for(int i=NCX_OI(rq);i>=0;i--) { | |
572 | httpd_object *obj = objset->obj[i]; | |
573 | dtable *dt = object_get_dtable(obj, NSAPIObjectType); | |
574 | ||
575 | // execute directives | |
37
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
576 | for(int j=NCX_DI(rq);j<dt->ndir;j++) { |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
577 | if(ret == REQ_NOACTION) { |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
578 | directive *d = dt->dirs[j]; |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
579 | ret = nsapi_exec(d, sn, rq); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
580 | } |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
581 | |
10 | 582 | switch(ret) { |
583 | case REQ_PROCEED: { | |
584 | char *type = pblock_findkeyval( | |
585 | pb_key_content_type, | |
586 | rq->rq.srvhdrs); | |
587 | if(type == NULL) { | |
588 | ret = REQ_NOACTION; | |
589 | break; | |
590 | } | |
591 | return ret; | |
592 | } | |
593 | case REQ_PROCESSING: { | |
594 | /* save nsapi context */ | |
595 | rq->context.objset_index = i; | |
596 | ||
597 | /* add +1 to start next round with next function */ | |
598 | rq->context.dtable_index = j + 1; | |
599 | return ret; | |
600 | } | |
601 | case REQ_NOACTION: { | |
602 | break; | |
603 | } | |
604 | default: { | |
605 | return ret; | |
606 | } | |
607 | } | |
608 | } | |
609 | } | |
610 | ||
611 | /* | |
612 | * No function returned with REQ_PROCEED, but we need a content type. | |
613 | * If the path ends with a '/', we set the content type to | |
614 | * 'internal/directory' so that 'index-common' can serve the content. | |
615 | * Otherwise we set the content type to text/plain | |
616 | */ | |
617 | sstr_t path = sstr(pblock_findkeyval(pb_key_ppath, rq->rq.vars)); | |
618 | sstr_t ct; | |
619 | if(path.ptr[path.length - 1] == '/') { | |
620 | /* directory */ | |
621 | ct = sstrn("internal/directory", 18); | |
622 | } else { | |
623 | ct = sstrn("text/plain", 10); | |
624 | } | |
625 | pblock_kvinsert(pb_key_content_type, ct.ptr, ct.length, rq->rq.srvhdrs); | |
626 | ||
627 | return REQ_PROCEED; | |
628 | } | |
629 | ||
3
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
630 | int nsapi_service(NSAPISession *sn, NSAPIRequest *rq) { |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
20
diff
changeset
|
631 | //printf("nsapi_service\n"); |
6
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
632 | httpd_objset *objset = rq->rq.os; |
3
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
633 | |
6
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
634 | if(NCX_OI(rq) == -1) { |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
635 | NCX_OI(rq) = objset->pos - 1; |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
636 | } |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
637 | |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
638 | int ret = rq->context.last_req_code; |
12
34aa8001ea53
Added directory index
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
10
diff
changeset
|
639 | char *content_type = NULL; |
20
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
640 | char *method = NULL; |
6
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
641 | for(int i=NCX_OI(rq);i>=0;i--) { |
12
34aa8001ea53
Added directory index
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
10
diff
changeset
|
642 | httpd_object *obj = objset->obj[i]; |
3
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
643 | dtable *dt = object_get_dtable(obj, NSAPIService); |
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
644 | |
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
645 | // execute directives |
37
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
646 | for(int j=NCX_DI(rq);j<dt->ndir;j++) { |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
647 | if(ret == REQ_NOACTION) { |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
648 | directive *d = dt->dirs[j]; |
3
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
649 | |
37
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
650 | /* check type parameter */ |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
651 | char *dtp = pblock_findkeyval(pb_key_type, d->param); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
652 | if(dtp) { |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
653 | /* type parameter for directive */ |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
654 | if(!content_type) { |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
655 | content_type = pblock_findkeyval( |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
656 | pb_key_content_type, |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
657 | rq->rq.srvhdrs); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
658 | } |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
659 | /* compare types */ |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
660 | if(strcmp(dtp, content_type) != 0) { |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
661 | continue; |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
662 | } |
20
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
663 | } |
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
664 | |
37
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
665 | /* check method parameter */ |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
666 | char *dmt = pblock_findkeyval(pb_key_method, d->param); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
667 | if(dmt) { |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
668 | if(!method) { |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
669 | method = pblock_findkeyval(pb_key_method, rq->rq.reqpb); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
670 | } |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
671 | |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
672 | if(!method_match(dmt, method)) { |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
673 | continue; |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
674 | } |
20
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
675 | } |
37
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
676 | |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
677 | /* execute the saf */ |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
678 | ret = nsapi_exec(d, sn, rq); |
20
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
679 | } |
37
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
680 | |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
681 | |
20
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
682 | if(ret != REQ_PROCEED) { |
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
683 | fprintf(stderr, "saf not proceed\n"); |
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
684 | } |
6
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
685 | if(ret != REQ_NOACTION) { |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
686 | if(ret == REQ_PROCESSING) { |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
687 | /* save nsapi context */ |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
688 | rq->context.objset_index = i; |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
689 | |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
690 | /* add +1 to start next round with next function */ |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
691 | rq->context.dtable_index = j + 1; |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
692 | } |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
693 | |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
694 | return ret; |
3
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
695 | } |
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
696 | } |
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
697 | } |
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
698 | |
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
699 | return ret; |
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
700 | } |
137197831306
minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
701 | |
45
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
702 | int nsapi_addlog(NSAPISession *sn, NSAPIRequest *rq) { |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
703 | //printf("nsapi_addlog\n"); |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
704 | httpd_objset *objset = rq->rq.os; |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
705 | |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
706 | if(NCX_OI(rq) == -1) { |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
707 | NCX_OI(rq) = objset->pos - 1; |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
708 | } |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
709 | |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
710 | int ret = rq->context.last_req_code; |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
711 | for(int i=NCX_OI(rq);i>=0;i--) { |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
712 | httpd_object *obj = objset->obj[i]; |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
713 | dtable *dt = object_get_dtable(obj, NSAPIAddLog); |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
714 | |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
715 | // execute directives |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
716 | for(int j=NCX_DI(rq);j<dt->ndir;j++) { |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
717 | if(ret == REQ_NOACTION) { |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
718 | directive *d = dt->dirs[j]; |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
719 | ret = nsapi_exec(d, sn, rq); |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
720 | } |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
721 | |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
722 | if(ret != REQ_NOACTION) { |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
723 | if(ret == REQ_PROCESSING) { |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
724 | /* save nsapi context */ |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
725 | rq->context.objset_index = i; |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
726 | |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
727 | /* add +1 to start next round with next function */ |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
728 | rq->context.dtable_index = j + 1; |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
729 | } |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
730 | |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
731 | return ret; |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
732 | } |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
733 | } |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
734 | } |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
735 | |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
736 | return REQ_PROCEED; |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
737 | } |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
738 | |
37
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
739 | struct _tpd_data { |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
740 | NSAPISession *sn; |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
741 | NSAPIRequest *rq; |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
742 | directive *directive; |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
743 | threadpool_t *threadpool; |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
744 | }; |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
745 | |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
746 | int nsapi_exec(directive *d, NSAPISession *sn, NSAPIRequest *rq) { |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
747 | // TODO: condition |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
748 | |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
749 | char *poolname = pblock_findkeyval(pb_key_pool, d->param); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
750 | if(poolname) { |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
751 | threadpool_t *pool = get_threadpool(sstr(poolname)); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
752 | if(pool && pool != sn->currentpool) { |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
753 | // execute directive in different thread pool |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
754 | return nsapi_exec_tp(d, sn, rq, pool); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
755 | } |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
756 | } else if(sn->currentpool != sn->defaultpool) { |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
757 | // if no pool is set, use always the default thread pool |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
758 | return nsapi_exec_tp(d, sn, rq, sn->defaultpool); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
759 | } |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
760 | |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
761 | return d->func->func(d->param, (Session*)sn, (Request*)rq); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
762 | } |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
763 | |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
764 | int nsapi_exec_tp( |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
765 | directive *d, |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
766 | NSAPISession *sn, |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
767 | NSAPIRequest *rq, |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
768 | threadpool_t *pool) |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
769 | { |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
770 | struct _tpd_data *data = malloc(sizeof(struct _tpd_data)); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
771 | if(data == NULL) { |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
772 | // TODO: set error |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
773 | return REQ_ABORTED; |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
774 | } |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
775 | data->sn = sn; |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
776 | data->rq = rq; |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
777 | data->directive = d; |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
778 | data->threadpool = pool; |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
779 | |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
780 | sn->currentpool = pool; |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
781 | threadpool_run(pool, thrpool_exec, data); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
782 | |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
783 | return REQ_PROCESSING; |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
784 | } |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
785 | |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
786 | void nsapi_function_return(Session *session, Request *request, int ret) { |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
787 | NSAPISession *sn = (NSAPISession*)session; |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
788 | NSAPIRequest *rq = (NSAPIRequest*)request; |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
789 | |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
790 | rq->context.last_req_code = ret; |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
791 | |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
792 | if(sn->currentpool != sn->defaultpool) { |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
793 | nsapi_change_threadpool(sn, rq, sn->defaultpool); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
794 | } else { |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
795 | nsapi_handle_request(sn, rq); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
796 | } |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
797 | } |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
798 | |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
799 | void nsapi_change_threadpool( |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
800 | NSAPISession *sn, |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
801 | NSAPIRequest *rq, |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
802 | threadpool_t *thrpool) |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
803 | { |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
804 | struct _tpd_data *data = malloc(sizeof(struct _tpd_data)); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
805 | data->sn = sn; |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
806 | data->rq = rq; |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
807 | data->threadpool = thrpool; |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
808 | |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
809 | threadpool_run(thrpool, thrpool_change, data); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
810 | } |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
811 | |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
812 | void* thrpool_exec(void *d) { |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
813 | struct _tpd_data *data = d; |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
814 | |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
815 | data->sn->currentpool = data->threadpool; |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
816 | int r = data->directive->func->func( |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
817 | data->directive->param, |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
818 | (Session*)data->sn, |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
819 | (Request*)data->rq); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
820 | |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
821 | free(data); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
822 | |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
823 | nsapi_function_return((Session*)data->sn, (Request*)data->rq, r); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
824 | |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
825 | return NULL; |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
826 | } |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
827 | |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
828 | void* thrpool_change(void *d) { |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
829 | struct _tpd_data *data = d; |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
830 | |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
831 | data->sn->currentpool = data->threadpool; |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
832 | nsapi_handle_request(data->sn, data->rq); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
833 | |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
834 | free(data); |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
835 | return NULL; |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
836 | } |
360b9aabe17e
added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
36
diff
changeset
|
837 | |
20
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
838 | |
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
839 | /* |
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
840 | * checks if the method matches the cmp string |
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
841 | * 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
|
842 | * (method1|method2|method3|...) |
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
843 | */ |
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
844 | int method_match(char *cmp, char *method) { |
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
845 | if(cmp[0] != '(') { |
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
846 | /* 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
|
847 | if(!strcmp(cmp, method)) { |
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
848 | return 1; |
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
849 | } |
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
850 | } else if(cmp[0] == 0) { |
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
851 | /* empty string */ |
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
852 | return 0; |
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
853 | } |
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
854 | |
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
855 | size_t method_len = strlen(method); |
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
856 | size_t last_pos = 0; |
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
857 | cmp++; /* skip '(' */ |
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
858 | for(int i=0;cmp[i]!=0;i++) { |
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
859 | char c = cmp[i]; |
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
860 | if(c == '|' || c == ')') { |
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
861 | size_t len = i - last_pos; |
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
862 | if(len == method_len) { |
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
863 | char *cp = cmp + last_pos; |
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
864 | if(!memcmp(cp, method, len)) { |
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
865 | return 1; |
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
866 | } |
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
867 | } |
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
868 | last_pos = i + 1; |
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
869 | } |
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
870 | } |
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
871 | |
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
872 | return 0; |
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
873 | } |
7b235fa88008
Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
19
diff
changeset
|
874 | |
6
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
875 | /* |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
876 | * 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
|
877 | */ |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
878 | int add_objects( |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
879 | HTTPObjectConfig *objs, |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
880 | httpd_objset *os, |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
881 | NSAPISession *sn, |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
882 | NSAPIRequest *rq, |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
883 | char *name, |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
884 | char *path) |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
885 | { |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
886 | /* first, add all objects with a matching path */ |
10 | 887 | /* TODO */ |
6
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
888 | |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
889 | |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
890 | /* add object with object with matching name */ |
10 | 891 | if(name == NULL) { |
892 | return REQ_PROCEED; | |
893 | } | |
894 | ||
895 | for(int i=0;i<objs->nobj;i++) { | |
896 | httpd_object *obj = objs->objects[i]; | |
897 | ||
898 | if(obj->name && !strcmp(name, obj->name)) { | |
899 | objset_add_object(sn->sn.pool, os, obj); | |
900 | } | |
901 | } | |
6
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
902 | |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
903 | return REQ_PROCEED; |
ce8fecc9847d
improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
904 | } |