src/server/daemon/httprequest.c

Thu, 21 Apr 2022 17:16:49 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Thu, 21 Apr 2022 17:16:49 +0200
branch
webdav
changeset 305
4db64fe30588
parent 272
f210681d9dd0
child 332
6f82ede01e1c
permissions
-rw-r--r--

change pg_resolve_path signature to be useable without VFS

1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
44
3da1f7b6847f added some error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
4 * Copyright 2013 Olaf Wintermann. All rights reserved.
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include <stdio.h>
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 #include <stdlib.h>
121
a881dc866e23 adds more CGI stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
31 #include <limits.h>
35
4417619a9bbd using non blocking IO for request input
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
32
24
1a7853a4257e removed some NSPR dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
33 #include <arpa/inet.h>
9
30e51941a673 Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
34
14
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
35 #include "../public/nsapi.h"
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
36 #include "../util/pool.h"
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
37 #include "../util/pblock.h"
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
38 #include "../util/io.h"
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 12
diff changeset
39 #include "../util/util.h"
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40 #include "httprequest.h"
18
73aacbf6e492 Added server.conf parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
41 #include "config.h"
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
42 #include "vserver.h"
159
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
43 #include "event.h"
19
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
44 #include "httplistener.h"
84
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 83
diff changeset
45 #include "func.h"
44
3da1f7b6847f added some error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
46 #include "error.h"
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47
46
636e05eb48f6 cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
48 void http_request_init(HTTPRequest *req) {
180
98462e878ca7 fixes crash with broken http requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 168
diff changeset
49 memset(req, 0, sizeof(HTTPRequest));
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51 HeaderArray *hd = malloc(sizeof(HeaderArray));
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52 hd->next = NULL;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53 hd->len = 0;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54 hd->headers = calloc(16, sizeof(Header));
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
55 hd->alloc = 16;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57 req->headers = hd;
102
136a76e293b5 added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
58
136a76e293b5 added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
59 req->req_start = time(NULL);
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60 }
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61
101
7fbcdbad0baa added support for absolute URIs and improved keep alive
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
62 void http_request_cleanup(HTTPRequest *req) {
114
c3a0f1275d71 fixed keep alive bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 110
diff changeset
63 header_array_free(req->headers);
c3a0f1275d71 fixed keep alive bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 110
diff changeset
64 free(req);
101
7fbcdbad0baa added support for absolute URIs and improved keep alive
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
65 }
7fbcdbad0baa added support for absolute URIs and improved keep alive
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
66
7fbcdbad0baa added support for absolute URIs and improved keep alive
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
67 sstr_t http_request_get_abspath(HTTPRequest *req) {
7fbcdbad0baa added support for absolute URIs and improved keep alive
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
68 sstr_t uri = req->uri;
7fbcdbad0baa added support for absolute URIs and improved keep alive
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
69
7fbcdbad0baa added support for absolute URIs and improved keep alive
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
70 int i = 0;
7fbcdbad0baa added support for absolute URIs and improved keep alive
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
71 if(uri.ptr[0] == '/') {
7fbcdbad0baa added support for absolute URIs and improved keep alive
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
72 return uri;
7fbcdbad0baa added support for absolute URIs and improved keep alive
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
73 } else if(sstrprefix(uri, S("http://"))) {
7fbcdbad0baa added support for absolute URIs and improved keep alive
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
74 i = 7;
7fbcdbad0baa added support for absolute URIs and improved keep alive
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
75 } else if(sstrprefix(uri, S("https://"))) {
7fbcdbad0baa added support for absolute URIs and improved keep alive
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
76 i = 8;
7fbcdbad0baa added support for absolute URIs and improved keep alive
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
77 } else if(!sstrcmp(uri, S("*"))) {
7fbcdbad0baa added support for absolute URIs and improved keep alive
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
78 return uri;
7fbcdbad0baa added support for absolute URIs and improved keep alive
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
79 }
7fbcdbad0baa added support for absolute URIs and improved keep alive
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
80
7fbcdbad0baa added support for absolute URIs and improved keep alive
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
81 for(;i<uri.length;i++) {
7fbcdbad0baa added support for absolute URIs and improved keep alive
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
82 if(uri.ptr[i] == '/') {
7fbcdbad0baa added support for absolute URIs and improved keep alive
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
83 return sstrsubs(uri, i);
7fbcdbad0baa added support for absolute URIs and improved keep alive
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
84 }
7fbcdbad0baa added support for absolute URIs and improved keep alive
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
85 }
7fbcdbad0baa added support for absolute URIs and improved keep alive
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
86
7fbcdbad0baa added support for absolute URIs and improved keep alive
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
87 return S("/");
7fbcdbad0baa added support for absolute URIs and improved keep alive
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
88 }
7fbcdbad0baa added support for absolute URIs and improved keep alive
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
89
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 193
diff changeset
90 NSAPISession* nsapisession_create(pool_handle_t *pool) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 193
diff changeset
91 NSAPISession *sn = pool_malloc(pool, sizeof(NSAPISession));
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 193
diff changeset
92 if(!sn) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 193
diff changeset
93 return NULL;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 193
diff changeset
94 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 193
diff changeset
95
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 193
diff changeset
96 ZERO(sn, sizeof(NSAPISession));
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 193
diff changeset
97
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 193
diff changeset
98 sn->sn.pool = pool;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 193
diff changeset
99 sn->allocator = util_pool_allocator(pool);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 193
diff changeset
100
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 193
diff changeset
101 sn->sn.client = pblock_create_pool(sn->sn.pool, 8);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 193
diff changeset
102 if(!sn->sn.client) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 193
diff changeset
103 pool_free(pool, sn);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 193
diff changeset
104 return NULL;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 193
diff changeset
105 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 193
diff changeset
106 sn->sn.fill = 1;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 193
diff changeset
107
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 193
diff changeset
108 return sn;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 193
diff changeset
109 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 193
diff changeset
110
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 193
diff changeset
111 int nsapisession_setconnection(NSAPISession *sn, Connection *conn, netbuf *inbuf, IOStream **io) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 193
diff changeset
112 SessionHandler *sh = conn->session_handler;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 193
diff changeset
113 WSBool ssl;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 193
diff changeset
114 IOStream *sio = sh->create_iostream(sh, conn, sn->sn.pool, &ssl);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 193
diff changeset
115 if(!sio) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 193
diff changeset
116 return 1;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 193
diff changeset
117 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 193
diff changeset
118 *io = sio;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 193
diff changeset
119 IOStream *http = httpstream_new(sn->sn.pool, sio);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 193
diff changeset
120 if(!http) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 193
diff changeset
121 return 1;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 193
diff changeset
122 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 193
diff changeset
123 sn->connection = conn;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 193
diff changeset
124 sn->netbuf = inbuf;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 193
diff changeset
125 sn->sn.csd = http;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 193
diff changeset
126 sn->sn.ssl = ssl;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 193
diff changeset
127 return 0;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 193
diff changeset
128 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 193
diff changeset
129
159
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
130 int handle_request(HTTPRequest *request, threadpool_t *thrpool, EventHandler *ev) {
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
131 // handle nsapi request
154
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 142
diff changeset
132
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
133 // create pool
46
636e05eb48f6 cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
134 pool_handle_t *pool = pool_create();
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
135
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
136 // create nsapi data structures
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 193
diff changeset
137 NSAPISession *sn = nsapisession_create(pool);
35
4417619a9bbd using non blocking IO for request input
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
138 if(sn == NULL) {
4417619a9bbd using non blocking IO for request input
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
139 /* TODO: error */
4417619a9bbd using non blocking IO for request input
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
140 }
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 193
diff changeset
141
46
636e05eb48f6 cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
142 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
143 if(rq == NULL) {
4417619a9bbd using non blocking IO for request input
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
144 /* TODO: error */
4417619a9bbd using non blocking IO for request input
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
145 }
141
ff311b63c3af many fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 138
diff changeset
146 ZERO(rq, sizeof(NSAPIRequest));
102
136a76e293b5 added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
147 rq->rq.req_start = request->req_start;
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
148 rq->phase = NSAPIAuthTrans;
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
149
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
150 // fill session structure
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 193
diff changeset
151 IOStream *io = NULL;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 193
diff changeset
152 if(nsapisession_setconnection(sn, request->connection, request->netbuf, &io)) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 193
diff changeset
153 // TODO: error
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 193
diff changeset
154 }
38
d07810b02147 added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
155
159
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
156 if(!ev) {
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
157 ev = ev_instance(get_default_event_handler());
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
158 }
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
159 sn->sn.ev = ev;
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 193
diff changeset
160
38
d07810b02147 added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
161 // the session needs the current server configuration
78
3578977d29a3 added keep-alive support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
162 sn->config = request->connection->listener->cfg;
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
163
46
636e05eb48f6 cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
164 // add ip to sn->client pblock
9
30e51941a673 Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
165 char ip_str[INET_ADDRSTRLEN];
30e51941a673 Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
166 if(inet_ntop(
30e51941a673 Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
167 AF_INET,
30e51941a673 Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
168 &request->connection->address.sin_addr,
30e51941a673 Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
169 ip_str,
30e51941a673 Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
170 INET_ADDRSTRLEN) != NULL)
30e51941a673 Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
171 {
30e51941a673 Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
172 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
173 }
30e51941a673 Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
174
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
175 // init NSAPI request structure
46
636e05eb48f6 cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
176 if(request_initialize(pool, request, rq) != 0) {
60
feb2f1e115c6 improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
177 log_ereport(LOG_FAILURE, "Cannot initialize request structure");
47
ce9790523346 server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
178 pool_destroy(pool);
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
179 return 1;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
180 }
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
181
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
182 // set default virtual server
19
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
183 rq->vs = request->connection->listener->default_vs.vs;
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
184
46
636e05eb48f6 cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
185 // Pass request line as "clf-request"
636e05eb48f6 cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
186 // remove \r\n
45
a24aa388f02f added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
187 sstr_t clfreq = request->request_line;
180
98462e878ca7 fixes crash with broken http requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 168
diff changeset
188 while(clfreq.length > 0 && clfreq.ptr[clfreq.length - 1] < 33) {
45
a24aa388f02f added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
189 clfreq.length--;
a24aa388f02f added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
190 }
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
191 pblock_kvinsert(
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
192 pb_key_clf_request,
180
98462e878ca7 fixes crash with broken http requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 168
diff changeset
193 clfreq.ptr,
98462e878ca7 fixes crash with broken http requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 168
diff changeset
194 clfreq.length,
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
195 rq->rq.reqpb);
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
196
59
ab25c0a231d0 some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
197 // Pass method as "method" in reqpb, and also as method_num
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
198 pblock_kvinsert(
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
199 pb_key_method,
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
200 request->method.ptr,
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
201 request->method.length,
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
202 rq->rq.reqpb);
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
203 // TODO: method num
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
204 //rqRq.rq.method_num = rqHdr->GetMethodNumber();
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
205 //PR_ASSERT(rqRq.rq.method_num != -1 || iStatus);
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
206
59
ab25c0a231d0 some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
207 // Pass protocol as "protocol" in reqpb, and also in protv_num
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
208 pblock_kvinsert(
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
209 pb_key_protocol,
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
210 request->httpv.ptr,
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
211 request->httpv.length,
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
212 rq->rq.reqpb);
101
7fbcdbad0baa added support for absolute URIs and improved keep alive
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
213
7fbcdbad0baa added support for absolute URIs and improved keep alive
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
214 if(!sstrcmp(request->httpv, S("HTTP/1.1"))) {
7fbcdbad0baa added support for absolute URIs and improved keep alive
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
215 rq->rq.protv_num = PROTOCOL_VERSION_HTTP11;
7fbcdbad0baa added support for absolute URIs and improved keep alive
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
216 } else if(!sstrcmp(request->httpv, S("HTTP/1.0"))) {
7fbcdbad0baa added support for absolute URIs and improved keep alive
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
217 rq->rq.protv_num = PROTOCOL_VERSION_HTTP10;
7fbcdbad0baa added support for absolute URIs and improved keep alive
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
218 } else {
136
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
219 // invalid protocol version - abort
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
220 log_ereport(
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
221 LOG_FAILURE,
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
222 "invalid protocol version: %.*s",
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
223 (int)request->httpv.length,
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
224 request->httpv.ptr);
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
225 pool_destroy(pool);
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
226 return 1;
101
7fbcdbad0baa added support for absolute URIs and improved keep alive
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
227 }
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
228
20
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
229 /*
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
230 * 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
231 */
261
f2c772336ecd add some references to issues
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 235
diff changeset
232 // TODO: check for '#' #72
101
7fbcdbad0baa added support for absolute URIs and improved keep alive
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
233 sstr_t absPath = http_request_get_abspath(request);
7fbcdbad0baa added support for absolute URIs and improved keep alive
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
234 if(!absPath.ptr) {
7fbcdbad0baa added support for absolute URIs and improved keep alive
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
235 // TODO: error msg
7fbcdbad0baa added support for absolute URIs and improved keep alive
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
236 return 1;
7fbcdbad0baa added support for absolute URIs and improved keep alive
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
237 } else if(absPath.ptr[0] == '*') {
261
f2c772336ecd add some references to issues
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 235
diff changeset
238 // TODO: implement global OPTIONS #71
101
7fbcdbad0baa added support for absolute URIs and improved keep alive
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
239 return 1;
7fbcdbad0baa added support for absolute URIs and improved keep alive
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
240 }
7fbcdbad0baa added support for absolute URIs and improved keep alive
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
241
20
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
242 sstr_t query;
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
243 query.length = 0;
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
244
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
245 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
246 if(request->uri.ptr[i] == '?') {
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
247 /* split uri in path and query */
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
248 if(absPath.length > i + 2) {
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
249 query.length = absPath.length - i - 1;
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
250 query.ptr = absPath.ptr + i + 1;
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
251 }
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
252 absPath.length = i;
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
253
59
ab25c0a231d0 some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
254 // Pass any query as 'query' in reqpb
20
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
255 pblock_kvinsert(
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
256 pb_key_query,
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
257 query.ptr,
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
258 query.length,
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
259 rq->rq.reqpb);
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
260
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
261 break;
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
262 }
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
263 }
26
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
264
59
ab25c0a231d0 some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
265 // Get abs_path part of request URI, and canonicalize the path
168
5c752979bfd6 fixes crash on broken urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 162
diff changeset
266 sstr_t orig_path = absPath;
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
267 absPath.ptr = util_canonicalize_uri(
46
636e05eb48f6 cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
268 pool,
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
269 absPath.ptr,
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
270 absPath.length,
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
271 (int*)&absPath.length);
168
5c752979bfd6 fixes crash on broken urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 162
diff changeset
272 if(!absPath.ptr) {
5c752979bfd6 fixes crash on broken urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 162
diff changeset
273 log_ereport(
5c752979bfd6 fixes crash on broken urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 162
diff changeset
274 LOG_WARN,
5c752979bfd6 fixes crash on broken urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 162
diff changeset
275 "invalid request path: {%.*s}",
5c752979bfd6 fixes crash on broken urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 162
diff changeset
276 (int)orig_path.length,
5c752979bfd6 fixes crash on broken urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 162
diff changeset
277 orig_path.ptr);
5c752979bfd6 fixes crash on broken urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 162
diff changeset
278 pool_destroy(pool);
5c752979bfd6 fixes crash on broken urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 162
diff changeset
279 // TODO: 400 bad request
5c752979bfd6 fixes crash on broken urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 162
diff changeset
280 return 1;
5c752979bfd6 fixes crash on broken urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 162
diff changeset
281 }
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
282
59
ab25c0a231d0 some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
283 // Decode the abs_path
ab25c0a231d0 some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
284 if(util_uri_unescape_strict(absPath.ptr)) {
ab25c0a231d0 some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
285 // 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
286 pblock_kvinsert(
ab25c0a231d0 some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
287 pb_key_uri,
ab25c0a231d0 some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
288 absPath.ptr,
ab25c0a231d0 some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
289 absPath.length,
ab25c0a231d0 some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
290 rq->rq.reqpb);
ab25c0a231d0 some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
291 } else {
ab25c0a231d0 some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
292 // TODO: log error
168
5c752979bfd6 fixes crash on broken urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 162
diff changeset
293 log_ereport(
5c752979bfd6 fixes crash on broken urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 162
diff changeset
294 LOG_WARN,
5c752979bfd6 fixes crash on broken urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 162
diff changeset
295 "uri unescape failed: {%.*s}",
5c752979bfd6 fixes crash on broken urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 162
diff changeset
296 (int)absPath.length,
5c752979bfd6 fixes crash on broken urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 162
diff changeset
297 absPath.ptr);
5c752979bfd6 fixes crash on broken urls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 162
diff changeset
298 // TODO: 400 bad request
59
ab25c0a231d0 some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
299 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
300 }
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
301
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
302 // 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
303 int hlen = request->headers->len;
7
3c2ed7a7a5fd request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
304 HeaderArray *ha = request->headers;
3c2ed7a7a5fd request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
305 for(int i=0;i<=hlen;i++) {
3c2ed7a7a5fd request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
306 if(i == hlen) {
3c2ed7a7a5fd request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
307 ha = ha->next;
3c2ed7a7a5fd request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
308 if(ha == NULL) {
3c2ed7a7a5fd request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
309 break;
3c2ed7a7a5fd request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
310 }
3c2ed7a7a5fd request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
311 i = 0;
3c2ed7a7a5fd request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
312 hlen = ha->len;
3c2ed7a7a5fd request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
313 }
101
7fbcdbad0baa added support for absolute URIs and improved keep alive
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
314
7fbcdbad0baa added support for absolute URIs and improved keep alive
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
315 Header header = ha->headers[i];
7
3c2ed7a7a5fd request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
316
101
7fbcdbad0baa added support for absolute URIs and improved keep alive
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
317 if(header.name.ptr[0] < 90) {
7fbcdbad0baa added support for absolute URIs and improved keep alive
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
318 header.name.ptr[0] += 32;
8
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
319 }
20
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
320
46
636e05eb48f6 cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
321 // change to lower case
133
87b405d61f64 improves event handler and ssl error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
322 for(int j=0;j<header.name.length;j++) {
87b405d61f64 improves event handler and ssl error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
323 if(header.name.ptr[j] > 64 && header.name.ptr[j] < 97) {
87b405d61f64 improves event handler and ssl error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 127
diff changeset
324 header.name.ptr[j] += 32;
20
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
325 }
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
326 }
101
7fbcdbad0baa added support for absolute URIs and improved keep alive
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
327
7fbcdbad0baa added support for absolute URIs and improved keep alive
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
328 pblock_nvlinsert(
7fbcdbad0baa added support for absolute URIs and improved keep alive
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
329 header.name.ptr,
7fbcdbad0baa added support for absolute URIs and improved keep alive
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
330 header.name.length,
7fbcdbad0baa added support for absolute URIs and improved keep alive
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
331 header.value.ptr,
7fbcdbad0baa added support for absolute URIs and improved keep alive
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
332 header.value.length,
20
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
333 rq->rq.headers);
7
3c2ed7a7a5fd request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
334 }
101
7fbcdbad0baa added support for absolute URIs and improved keep alive
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
335
121
a881dc866e23 adds more CGI stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
336 // get host and port
a881dc866e23 adds more CGI stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
337 char *hosthdr = pblock_findkeyval(pb_key_host, rq->rq.headers);
a881dc866e23 adds more CGI stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
338 if(hosthdr) {
a881dc866e23 adds more CGI stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
339 char *host = pool_strdup(pool, hosthdr);
a881dc866e23 adds more CGI stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
340 char *portstr = strchr(host, ':');
a881dc866e23 adds more CGI stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
341 if(portstr) {
a881dc866e23 adds more CGI stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
342 *portstr = '\0';
a881dc866e23 adds more CGI stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
343 }
a881dc866e23 adds more CGI stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
344 rq->host = host;
a881dc866e23 adds more CGI stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
345 } else {
a881dc866e23 adds more CGI stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
346 rq->host = NULL; // TODO: value from listener
a881dc866e23 adds more CGI stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
347 }
a881dc866e23 adds more CGI stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
348 rq->port = request->connection->listener->port;
a881dc866e23 adds more CGI stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 117
diff changeset
349
138
06619bbd14ef using host header to select virtual server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
350 if(rq->host) {
06619bbd14ef using host header to select virtual server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
351 VirtualServer *vs = ucx_map_cstr_get(sn->config->host_vs, rq->host);
06619bbd14ef using host header to select virtual server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
352 if(vs) {
06619bbd14ef using host header to select virtual server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
353 rq->vs = vs;
06619bbd14ef using host header to select virtual server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
354 } else {
06619bbd14ef using host header to select virtual server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
355 log_ereport(
06619bbd14ef using host header to select virtual server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
356 LOG_VERBOSE,
06619bbd14ef using host header to select virtual server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
357 "Unkown host '%s': using default virtual server",
06619bbd14ef using host header to select virtual server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
358 rq->host);
06619bbd14ef using host header to select virtual server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
359 }
06619bbd14ef using host header to select virtual server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
360 }
06619bbd14ef using host header to select virtual server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 136
diff changeset
361
101
7fbcdbad0baa added support for absolute URIs and improved keep alive
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
362 // parse connection header
7fbcdbad0baa added support for absolute URIs and improved keep alive
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
363 rq->rq.rq_attr.keep_alive = (rq->rq.protv_num >= PROTOCOL_VERSION_HTTP11);
7fbcdbad0baa added support for absolute URIs and improved keep alive
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
364 char *conn_str = pblock_findkeyval(pb_key_connection, rq->rq.headers);
7fbcdbad0baa added support for absolute URIs and improved keep alive
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
365 if(conn_str) {
7fbcdbad0baa added support for absolute URIs and improved keep alive
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
366 if(!strcasecmp(conn_str, "keep-alive")) {
7fbcdbad0baa added support for absolute URIs and improved keep alive
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
367 rq->rq.rq_attr.keep_alive = 1;
7fbcdbad0baa added support for absolute URIs and improved keep alive
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
368 } else if(!strcasecmp(conn_str, "close")) {
7fbcdbad0baa added support for absolute URIs and improved keep alive
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
369 rq->rq.rq_attr.keep_alive = 0;
7fbcdbad0baa added support for absolute URIs and improved keep alive
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
370 }
7fbcdbad0baa added support for absolute URIs and improved keep alive
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
371 }
26
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
372
46
636e05eb48f6 cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
373 // check for request body and prepare input buffer
8
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
374 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
375 if(ctlen_str) {
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 193
diff changeset
376 int ctlen = atoi(ctlen_str); // TODO: use other func
26
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
377
115
51d9a15eac98 improves logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 114
diff changeset
378 //printf("request body length: %d\n", ctlen);
8
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
379
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
380 netbuf *nb = request->netbuf;
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
381
59
ab25c0a231d0 some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
382 // create new netbuf
110
43a746e905f6 refactored IO system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 106
diff changeset
383 HttpStream *net_io = (HttpStream*)httpstream_new(pool, io);
8
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
384 net_io->max_read = ctlen;
26
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
385
46
636e05eb48f6 cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
386 sn->sn.inbuf = pool_malloc(pool, sizeof(netbuf));
8
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
387 sn->sn.inbuf->sd = net_io;
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
388 sn->sn.inbuf->pos = 0;
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
389
46
636e05eb48f6 cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
390 // prepare buffer
8
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
391 int cur_input_len = nb->cursize - nb->pos;
26
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
392
8
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
393 if(cur_input_len >= ctlen) {
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
394 /*
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
395 * all data is already in the primary input buffer
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
396 * just link the new netbuf to the primary buffer
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
397 */
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
398 sn->sn.inbuf->maxsize = ctlen;
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
399 sn->sn.inbuf->cursize = ctlen;
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
400 sn->sn.inbuf->inbuf = nb->inbuf + nb->pos;
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
401 } else {
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
402 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
403 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
404
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
405 if(cur_input_len > 0) {
46
636e05eb48f6 cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
406 // 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
407 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
408 }
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
409
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
410 sn->sn.inbuf->cursize = cur_input_len;
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
411 }
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
412 } else {
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
413 sn->sn.inbuf = NULL;
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
414 }
26
37ff8bf54b89 Minimal webdav support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
415
37
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
416 //
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
417 // Send the request to the NSAPI system
37
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
418 //
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
419
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
420 // compare current and listener thread pool
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
421 threadpool_t *lstp = request->connection->listener->threadpool;
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
422 sn->defaultpool = lstp;
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
423 if(lstp == thrpool) {
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
424 sn->currentpool = thrpool;
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
425 nsapi_handle_request(sn, rq);
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
426 } else {
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
427 // execute nsapi functions on a different thread pool
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
428 nsapi_change_threadpool(sn, rq, lstp);
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
429 }
114
c3a0f1275d71 fixed keep alive bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 110
diff changeset
430
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
431 return 0;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
432 }
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
433
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
434
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
435
101
7fbcdbad0baa added support for absolute URIs and improved keep alive
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 96
diff changeset
436 void header_add(HeaderArray *hd, sstr_t name, sstr_t value) {
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
437 while(hd->len >= hd->alloc) {
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
438 if(hd->next == NULL) {
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
439 HeaderArray *block = malloc(sizeof(HeaderArray));
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
440 block->next = NULL;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
441 block->len = 0;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
442 block->headers = calloc(16, sizeof(Header));
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
443 block->alloc = 16;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
444 hd->next = block;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
445 }
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
446 hd = hd->next;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
447 }
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
448 hd->headers[hd->len].name = name;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
449 hd->headers[hd->len].value = value;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
450 hd->len++;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
451 }
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
452
46
636e05eb48f6 cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
453 void header_array_free(HeaderArray *hd) {
636e05eb48f6 cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
454 HeaderArray *next;
636e05eb48f6 cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
455 while(hd) {
636e05eb48f6 cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
456 next = hd->next;
636e05eb48f6 cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
457 free(hd->headers);
636e05eb48f6 cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
458 free(hd);
636e05eb48f6 cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
459 hd = next;
636e05eb48f6 cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
460 }
636e05eb48f6 cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
461 }
636e05eb48f6 cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
462
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
463
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
464 /*
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
465 * NSAPI Processing
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
466 */
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
467
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
468 int nsapi_handle_request(NSAPISession *sn, NSAPIRequest *rq) {
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
469 int r = REQ_NOACTION;
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
470 do {
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
471 switch(rq->phase) {
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
472 case NSAPIAuthTrans: {
22
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
473 r = nsapi_authtrans(sn, rq);
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
474 if(r != REQ_PROCEED) {
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
475 break;
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
476 }
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
477 rq->phase++;
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
478 nsapi_context_next_stage(&rq->context);
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
479 }
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
480 case NSAPINameTrans: {
21
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
481 //printf(">>> NameTrans\n");
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
482 r = nsapi_nametrans(sn, rq);
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
483 if(r != REQ_PROCEED) {
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
484 break;
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
485 }
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
486 rq->phase++;
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
487 nsapi_context_next_stage(&rq->context);
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
488 }
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
489 case NSAPIPathCheck: {
21
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
490 //printf(">>> PathCheck\n");
23
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
491 r = nsapi_pathcheck(sn, rq);
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
492 if(r != REQ_PROCEED) {
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
493 break;
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
494 }
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
495 rq->phase++;
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
496 nsapi_context_next_stage(&rq->context);
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
497 }
5
dbc01588686e Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
498 case NSAPIObjectType: {
21
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
499 //printf(">>> ObjectType\n");
10
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
500 r = nsapi_objecttype(sn, rq);
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
501 if(r != REQ_PROCEED) {
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
502 break;
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
503 }
5
dbc01588686e Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
504 rq->phase++;
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
505 nsapi_context_next_stage(&rq->context);
5
dbc01588686e Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
506 }
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
507 case NSAPIService: {
21
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
508 //printf(">>> Service\n");
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
509 r = nsapi_service(sn, rq);
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
510 if(r != REQ_PROCEED) {
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
511 break;
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
512 }
95
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
513 rq->phase = NSAPIAddLog; // skip NSAPIError
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
514 nsapi_context_next_stage(&rq->context);
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
515 }
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
516 case NSAPIAddLog: {
21
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
517 //printf(">>> AddLog\n");
45
a24aa388f02f added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
518 r = nsapi_addlog(sn, rq);
95
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
519 if(r == REQ_PROCESSING) {
45
a24aa388f02f added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
520 break;
a24aa388f02f added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
521 }
95
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
522 // finish request
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
523 r = REQ_PROCEED;
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
524 break;
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
525 }
70
4e6e812c1d97 fixed some warnings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 61
diff changeset
526 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
527 case REQ_FINISH: {
21
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
528 //printf(">>> Finish\n");
95
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
529 //r = nsapi_finish_request(sn, rq);
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
530 r = REQ_PROCEED;
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
531 break;
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
532 }
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
533 case NSAPIError: {
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
534 //printf(">>> Error\n");
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
535 r = nsapi_error(sn, rq);
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
536 if(r == REQ_PROCEED) {
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
537 // restart the loop to switch to AddLog directive
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
538 r = REQ_RESTART;
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
539 rq->phase = NSAPIAddLog;
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
540 nsapi_context_next_stage(&rq->context);
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
541 } else {
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
542 /*
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
543 * an error occured while handling an error
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
544 * leave loop to finish the request (without AddLog)
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
545 */
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
546 r = REQ_PROCEED;
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
547 break;
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
548 }
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
549 }
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
550 }
35
4417619a9bbd using non blocking IO for request input
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
551
4417619a9bbd using non blocking IO for request input
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
552 if(r == REQ_ABORTED) {
95
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
553 // switch to NSAPIError
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
554 rq->phase = NSAPIError;
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
555 nsapi_context_next_stage(&rq->context);
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
556 r = REQ_RESTART;
35
4417619a9bbd using non blocking IO for request input
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
557 }
4417619a9bbd using non blocking IO for request input
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 26
diff changeset
558
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
559 } while (r == REQ_RESTART);
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
560
37
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
561 if(r != REQ_PROCESSING) {
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
562 r = nsapi_finish_request(sn, rq);
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
563 }
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
564
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
565 return r;
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
566 }
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
567
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
568 int nsapi_finish_request(NSAPISession *sn, NSAPIRequest *rq) {
272
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 261
diff changeset
569 request_free_resources(sn, rq);
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 261
diff changeset
570
78
3578977d29a3 added keep-alive support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
571 if(rq->rq.rq_attr.keep_alive) {
3578977d29a3 added keep-alive support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
572 SessionHandler *sh = sn->connection->session_handler;
3578977d29a3 added keep-alive support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
573 sh->keep_alive(sh, sn->connection);
3578977d29a3 added keep-alive support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
574 /*
3578977d29a3 added keep-alive support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
575 * keep the connection object
3578977d29a3 added keep-alive support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
576 * the sn->config is referenced by the connection, so we don't
79
f48cea237ec3 fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 78
diff changeset
577 * unref it
78
3578977d29a3 added keep-alive support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
578 */
3578977d29a3 added keep-alive support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
579 } else {
114
c3a0f1275d71 fixed keep alive bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 110
diff changeset
580 connection_destroy(sn->connection);
78
3578977d29a3 added keep-alive support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
581 cfg_unref(sn->config);
3578977d29a3 added keep-alive support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
582 }
46
636e05eb48f6 cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
583
78
3578977d29a3 added keep-alive support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 77
diff changeset
584 // free all memory
46
636e05eb48f6 cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
585 free(sn->netbuf->inbuf);
636e05eb48f6 cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
586 free(sn->netbuf);
636e05eb48f6 cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
587
636e05eb48f6 cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 45
diff changeset
588 pool_destroy(sn->sn.pool);
114
c3a0f1275d71 fixed keep alive bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 110
diff changeset
589
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
590 return 0;
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
591 }
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
592
272
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 261
diff changeset
593 void request_free_resources(NSAPISession *sn, NSAPIRequest *rq) {
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 261
diff changeset
594 if(!rq->resources) return;
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 261
diff changeset
595
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 261
diff changeset
596 UcxMapIterator i = ucx_map_iterator(rq->resources);
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 261
diff changeset
597 ResourceData *resource;
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 261
diff changeset
598 UCX_MAP_FOREACH(key, resource, i) {
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 261
diff changeset
599 resourcepool_free(&sn->sn, &rq->rq, resource);
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 261
diff changeset
600 }
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 261
diff changeset
601 }
f210681d9dd0 add minimal working implementation for resourcepool_lookup()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 261
diff changeset
602
22
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
603 int nsapi_authtrans(NSAPISession *sn, NSAPIRequest *rq) {
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
604 HTTPObjectConfig *objconf = rq->vs->objects;
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
605 httpd_object *obj = objconf->objects[0];
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
606 dtable *dt = object_get_dtable(obj, NSAPIAuthTrans);
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
607
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
608 int ret = rq->context.last_req_code;
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
609 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
610 if(ret == REQ_NOACTION) {
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
611 directive *d = dt->dirs[i];
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
612 ret = nsapi_exec(d, sn, rq);
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
613 }
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
614
22
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
615 if(ret != REQ_NOACTION) {
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
616 /*
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
617 * 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
618 * process this object at a later time
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
619 */
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
620 if(ret == REQ_PROCESSING) {
87
bdec069d2239 fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
621 // save nsapi context
bdec069d2239 fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
622 // add +1 to start next round with next function
22
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
623 rq->context.dtable_index = i + 1;
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
624 }
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
625
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
626 return ret;
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
627 }
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
628 }
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
629
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
630
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
631 return REQ_PROCEED;
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
632 }
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
633
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
634 int nsapi_nametrans(NSAPISession *sn, NSAPIRequest *rq) {
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
635 HTTPObjectConfig *objconf = rq->vs->objects;
21
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
636 //printf("nsapi_nametrans\n");
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
637 httpd_objset *objset = objset_create(sn->sn.pool);
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
638 rq->rq.os = objset;
87
bdec069d2239 fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
639 // first object in objconf is the default object TODO: make sure it is
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
640 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
641
87
bdec069d2239 fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
642 httpd_object *obj = objset->obj[0]; // nametrans only in default object
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
643 dtable *dt = object_get_dtable(obj, NSAPINameTrans);
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
644
87
bdec069d2239 fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
645 // execute directives
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
646 int ret = rq->context.last_req_code;
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
647 char *name = NULL;
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
648 char *ppath = NULL;
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
649 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
650 if(ret == REQ_NOACTION) {
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
651 directive *d = dt->dirs[i];
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
652 ret = nsapi_exec(d, sn, rq);
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
653 }
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
654
87
bdec069d2239 fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
655 // check for name or ppath
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
656 name = pblock_findkeyval(pb_key_name, rq->rq.vars);
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
657 ppath = pblock_findkeyval(pb_key_ppath, rq->rq.vars);
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
658
87
bdec069d2239 fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
659 // add additional objects to the objset
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
660 if(add_objects(objconf, objset, sn, rq, name, ppath) == REQ_ABORTED) {
115
51d9a15eac98 improves logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 114
diff changeset
661 log_ereport(LOG_FAILURE, "add_objects failed");
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
662 return REQ_ABORTED;
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
663 }
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
664
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
665 if(ret != REQ_NOACTION) {
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
666 /*
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
667 * 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
668 * process this object at a later time
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
669 */
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
670 if(ret == REQ_PROCESSING) {
87
bdec069d2239 fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
671 // save nsapi context
bdec069d2239 fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
672 // add +1 to start next round with next function
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
673 rq->context.dtable_index = i + 1;
117
a94cf2e94492 fixes nametrans
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 116
diff changeset
674 } else if(ret == REQ_PROCEED) {
a94cf2e94492 fixes nametrans
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 116
diff changeset
675 char *pp = pblock_findkeyval(pb_key_ppath, rq->rq.vars);
a94cf2e94492 fixes nametrans
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 116
diff changeset
676 pblock_kvinsert(pb_key_path, pp, strlen(pp), rq->rq.vars);
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
677 }
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
678
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
679 return ret;
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
680 }
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
681 }
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
682
87
bdec069d2239 fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
683 // if no function has set the ppath var, translate it to docroot
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
684 if(ret == REQ_NOACTION && ppath == NULL) {
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
685 sstr_t docroot = rq->vs->document_root;
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
686 if(docroot.length < 1) {
136
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
687 log_ereport(
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
688 LOG_WARN,
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
689 "VirtualServer(%.*s) docroot too short",
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
690 (int)rq->vs->name.length,
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
691 rq->vs->name.ptr);
9b48a1427aef adds simple rewrite saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
692 return REQ_ABORTED; // docroot too short
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
693 }
96
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
694
87
bdec069d2239 fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
695 // if there is a trailing '/', remove it
96
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
696 /*
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
697 if(docroot.ptr[docroot.length - 1] == '/') {
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
698 docroot.length--;
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
699 }
96
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
700
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
701 sstr_t uri = sstr(pblock_findkeyval(pb_key_uri, rq->rq.reqpb));
96
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
702
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
703 sstr_t translated;
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
704 translated.length = docroot.length + uri.length;
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
705 translated.ptr = alloca(translated.length + 1);
91
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
706 translated = sstrncat(translated, 2, docroot, uri);
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
707
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
708 pblock_kvinsert(
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
709 pb_key_ppath,
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
710 translated.ptr,
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
711 translated.length,
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
712 rq->rq.vars);
96
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
713 */
0185b13bf41f added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 95
diff changeset
714 sstr_t uri = sstr(pblock_findkeyval(pb_key_uri, rq->rq.reqpb));
116
d7a186cf87f6 adds find-pathinfo saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
715 request_set_path(docroot, uri, rq->rq.vars);
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
716 }
116
d7a186cf87f6 adds find-pathinfo saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
717
d7a186cf87f6 adds find-pathinfo saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
718 // TODO: remove ppath
d7a186cf87f6 adds find-pathinfo saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
719 char *pp = pblock_findkeyval(pb_key_ppath, rq->rq.vars);
d7a186cf87f6 adds find-pathinfo saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
720 pblock_kvinsert(pb_key_path, pp, strlen(pp), rq->rq.vars);
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
721
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
722 return REQ_PROCEED;
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
723 }
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
724
23
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
725 int nsapi_pathcheck(NSAPISession *sn, NSAPIRequest *rq) {
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
726 //printf("nsapi_pathcheck\n");
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
727 httpd_objset *objset = rq->rq.os;
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
728
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
729 if(NCX_OI(rq) == -1) {
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
730 NCX_OI(rq) = objset->pos - 1;
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
731 }
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
732
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
733 int ret = rq->context.last_req_code;
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
734 for(int i=NCX_OI(rq);i>=0;i--) {
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
735 httpd_object *obj = objset->obj[i];
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
736 dtable *dt = object_get_dtable(obj, NSAPIPathCheck);
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
737
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
738 // execute directives
37
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
739 for(int j=NCX_DI(rq);j<dt->ndir;j++) {
141
ff311b63c3af many fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 138
diff changeset
740 if(ret == REQ_NOACTION || ret == REQ_PROCEED) {
37
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
741 directive *d = dt->dirs[j];
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
742 ret = nsapi_exec(d, sn, rq);
87
bdec069d2239 fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
743 } else {
23
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
744 if(ret == REQ_PROCESSING) {
87
bdec069d2239 fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
745 // save nsapi context
23
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
746 rq->context.objset_index = i;
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
747
87
bdec069d2239 fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
748 // add +1 to start next round with next function
23
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
749 rq->context.dtable_index = j + 1;
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
750 }
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
751
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
752 return ret;
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
753 }
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
754 }
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
755 }
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
756
24
1a7853a4257e removed some NSPR dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
757 return REQ_PROCEED;
23
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
758 }
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
759
10
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
760 int nsapi_objecttype(NSAPISession *sn, NSAPIRequest *rq) {
21
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
761 //printf("nsapi_objecttype\n");
10
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
762 httpd_objset *objset = rq->rq.os;
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
763
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
764 if(NCX_OI(rq) == -1) {
87
bdec069d2239 fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
765 // object index is undefined -> define correct object index
10
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
766 NCX_OI(rq) = objset->pos - 1;
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
767 }
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
768
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
769 int ret = rq->context.last_req_code;
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
770 for(int i=NCX_OI(rq);i>=0;i--) {
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
771 httpd_object *obj = objset->obj[i];
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
772 dtable *dt = object_get_dtable(obj, NSAPIObjectType);
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
773
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
774 // execute directives
37
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
775 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
776 if(ret == REQ_NOACTION) {
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
777 directive *d = dt->dirs[j];
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
778 ret = nsapi_exec(d, sn, rq);
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
10
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
781 switch(ret) {
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
782 case REQ_PROCEED: {
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
783 char *type = pblock_findkeyval(
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
784 pb_key_content_type,
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
785 rq->rq.srvhdrs);
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
786 if(type == NULL) {
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
787 ret = REQ_NOACTION;
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
788 break;
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
789 }
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
790 return ret;
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
791 }
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
792 case REQ_PROCESSING: {
87
bdec069d2239 fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
793 // save nsapi context
10
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
794 rq->context.objset_index = i;
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
795
87
bdec069d2239 fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
796 // add +1 to start next round with next function
10
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
797 rq->context.dtable_index = j + 1;
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
798 return ret;
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
799 }
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
800 case REQ_NOACTION: {
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
801 break;
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
802 }
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
803 default: {
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
804 return ret;
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
805 }
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
806 }
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
807 }
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
808 }
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
809
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
810 /*
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
811 * No function returned with REQ_PROCEED, but we need a content type.
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
812 * If the path ends with a '/', we set the content type to
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
813 * 'internal/directory' so that 'index-common' can serve the content.
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
814 * Otherwise we set the content type to text/plain
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
815 */
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
816 sstr_t path = sstr(pblock_findkeyval(pb_key_ppath, rq->rq.vars));
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
817 sstr_t ct;
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
818 if(path.ptr[path.length - 1] == '/') {
87
bdec069d2239 fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
819 // directory
10
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
820 ct = sstrn("internal/directory", 18);
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
821 } else {
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
822 ct = sstrn("text/plain", 10);
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
823 }
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
824 pblock_kvinsert(pb_key_content_type, ct.ptr, ct.length, rq->rq.srvhdrs);
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
825
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
826 return REQ_PROCEED;
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
827 }
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
828
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
829 int nsapi_service(NSAPISession *sn, NSAPIRequest *rq) {
21
627b09ee74e4 New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 20
diff changeset
830 //printf("nsapi_service\n");
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
831 httpd_objset *objset = rq->rq.os;
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
832
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
833 if(NCX_OI(rq) == -1) {
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
834 NCX_OI(rq) = objset->pos - 1;
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
835 }
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
836
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
837 int ret = rq->context.last_req_code;
12
34aa8001ea53 Added directory index
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
838 char *content_type = NULL;
20
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
839 char *method = NULL;
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
840 for(int i=NCX_OI(rq);i>=0;i--) {
12
34aa8001ea53 Added directory index
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 10
diff changeset
841 httpd_object *obj = objset->obj[i];
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
842 dtable *dt = object_get_dtable(obj, NSAPIService);
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
843
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
844 // execute directives
37
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
845 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
846 if(ret == REQ_NOACTION) {
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
847 directive *d = dt->dirs[j];
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
848
87
bdec069d2239 fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
849 // check type parameter
37
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
850 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
851 if(dtp) {
87
bdec069d2239 fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
852 // type parameter for directive
37
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
853 if(!content_type) {
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
854 content_type = pblock_findkeyval(
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
855 pb_key_content_type,
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
856 rq->rq.srvhdrs);
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
857 }
87
bdec069d2239 fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
858 // compare types
142
55298bc9ed28 adds new a pathcheck saf and improves content type matchin and improves content type matching
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
859 if(!contenttype_match(sstr(dtp), sstr(content_type))) {
37
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
860 continue;
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
861 }
20
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
862 }
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
863
87
bdec069d2239 fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
864 // check method parameter
37
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
865 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
866 if(dmt) {
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
867 if(!method) {
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
868 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
869 }
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
870
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
871 if(!method_match(dmt, method)) {
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
872 continue;
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
873 }
20
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
874 }
37
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
875
87
bdec069d2239 fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
876 // execute the saf
37
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
877 ret = nsapi_exec(d, sn, rq);
20
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
878 }
37
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
879
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
880 if(ret != REQ_NOACTION) {
80
0de4a90979e1 fixed chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 79
diff changeset
881 if(ret == REQ_PROCEED) {
0de4a90979e1 fixed chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 79
diff changeset
882 /*
0de4a90979e1 fixed chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 79
diff changeset
883 * flush buffer and add termination if chunked encoding
0de4a90979e1 fixed chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 79
diff changeset
884 * is enabled
0de4a90979e1 fixed chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 79
diff changeset
885 */
0de4a90979e1 fixed chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 79
diff changeset
886 net_finish(sn->sn.csd);
0de4a90979e1 fixed chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 79
diff changeset
887 } else if(ret == REQ_PROCESSING) {
87
bdec069d2239 fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
888 // save nsapi context
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
889 rq->context.objset_index = i;
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
890
87
bdec069d2239 fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
891 // add +1 to start next round with next function
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
892 rq->context.dtable_index = j + 1;
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
893 }
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
894
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
895 return ret;
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
896 }
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
897 }
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
898 }
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
899
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
900 return ret;
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
901 }
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
902
95
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
903 int nsapi_error(NSAPISession *sn, NSAPIRequest *rq) {
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
904 //printf("nsapi_error\n");
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
905 httpd_objset *objset = rq->rq.os;
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
906
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
907 if(NCX_OI(rq) == -1) {
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
908 NCX_OI(rq) = objset->pos - 1;
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
909 }
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
910
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
911 int ret = rq->context.last_req_code;
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
912 for(int i=NCX_OI(rq);i>=0;i--) {
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
913 httpd_object *obj = objset->obj[i];
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
914 dtable *dt = object_get_dtable(obj, NSAPIError);
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
915
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
916 // execute directives
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
917 for(int j=NCX_DI(rq);j<dt->ndir;j++) {
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
918 if(ret == REQ_NOACTION) {
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
919 directive *d = dt->dirs[j];
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
920
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
921 // check status code parameter
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
922 char *status = pblock_findkeyval(pb_key_type, d->param);
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
923 if(status) {
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
924 int statuscode = atoi(status);
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
925 if(statuscode != rq->rq.status_num) {
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
926 continue;
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
927 }
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
928 }
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
929
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
930 // execute the saf
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
931 ret = nsapi_exec(d, sn, rq);
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
932 }
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
933
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
934 if(ret == REQ_ABORTED) {
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
935 // if an error directive fails, we use the default
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
936 // error handler
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
937 break;
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
938 }
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
939 if(ret != REQ_NOACTION) {
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
940 if(ret == REQ_PROCEED) {
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
941 /*
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
942 * flush buffer and add termination if chunked encoding
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
943 * is enabled
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
944 */
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
945 net_finish(sn->sn.csd);
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
946 } else if(ret == REQ_PROCESSING) {
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
947 // save nsapi context
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
948 rq->context.objset_index = i;
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
949
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
950 // add +1 to start next round with next function
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
951 rq->context.dtable_index = j + 1;
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
952 }
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
953 return ret;
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
954 }
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
955 }
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
956 }
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
957
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
958 if(ret != REQ_PROCEED) {
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
959 // default error handler
235
4990147c58d0 add handler for http expect header
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
960 if(!rq->rq.senthdrs) {
4990147c58d0 add handler for http expect header
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
961 nsapi_error_request((Session*)sn, (Request*)rq);
4990147c58d0 add handler for http expect header
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
962 }
95
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
963 }
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
964
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
965 return ret;
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
966 }
74a81d9e19d0 added error directive for custom error pages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 91
diff changeset
967
45
a24aa388f02f added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
968 int nsapi_addlog(NSAPISession *sn, NSAPIRequest *rq) {
a24aa388f02f added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
969 //printf("nsapi_addlog\n");
a24aa388f02f added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
970 httpd_objset *objset = rq->rq.os;
a24aa388f02f added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
971
a24aa388f02f added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
972 if(NCX_OI(rq) == -1) {
a24aa388f02f added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
973 NCX_OI(rq) = objset->pos - 1;
a24aa388f02f added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
974 }
a24aa388f02f added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
975
a24aa388f02f added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
976 int ret = rq->context.last_req_code;
a24aa388f02f added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
977 for(int i=NCX_OI(rq);i>=0;i--) {
a24aa388f02f added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
978 httpd_object *obj = objset->obj[i];
a24aa388f02f added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
979 dtable *dt = object_get_dtable(obj, NSAPIAddLog);
a24aa388f02f added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
980
a24aa388f02f added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
981 // execute directives
a24aa388f02f added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
982 for(int j=NCX_DI(rq);j<dt->ndir;j++) {
a24aa388f02f added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
983 if(ret == REQ_NOACTION) {
a24aa388f02f added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
984 directive *d = dt->dirs[j];
a24aa388f02f added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
985 ret = nsapi_exec(d, sn, rq);
a24aa388f02f added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
986 }
a24aa388f02f added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
987
a24aa388f02f added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
988 if(ret != REQ_NOACTION) {
a24aa388f02f added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
989 if(ret == REQ_PROCESSING) {
87
bdec069d2239 fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
990 // save nsapi context
45
a24aa388f02f added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
991 rq->context.objset_index = i;
a24aa388f02f added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
992
87
bdec069d2239 fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 84
diff changeset
993 // add +1 to start next round with next function
45
a24aa388f02f added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
994 rq->context.dtable_index = j + 1;
a24aa388f02f added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
995 }
a24aa388f02f added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
996
a24aa388f02f added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
997 return ret;
a24aa388f02f added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
998 }
a24aa388f02f added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
999 }
a24aa388f02f added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
1000 }
a24aa388f02f added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
1001
a24aa388f02f added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
1002 return REQ_PROCEED;
a24aa388f02f added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
1003 }
a24aa388f02f added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
1004
37
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1005 struct _tpd_data {
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1006 NSAPISession *sn;
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1007 NSAPIRequest *rq;
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1008 directive *directive;
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1009 threadpool_t *threadpool;
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1010 };
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1011
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1012 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
1013 // TODO: condition
83
28433f06d5ee added minimal nsapi conditions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 80
diff changeset
1014 if(d->cond) {
28433f06d5ee added minimal nsapi conditions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 80
diff changeset
1015 if(!condition_evaluate(d->cond, (Session*)sn, (Request*)rq)) {
28433f06d5ee added minimal nsapi conditions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 80
diff changeset
1016 return REQ_NOACTION;
28433f06d5ee added minimal nsapi conditions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 80
diff changeset
1017 }
28433f06d5ee added minimal nsapi conditions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 80
diff changeset
1018 }
37
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1019
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1020 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
1021 if(poolname) {
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1022 threadpool_t *pool = get_threadpool(sstr(poolname));
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1023 if(pool && pool != sn->currentpool) {
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1024 // execute directive in different thread pool
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1025 return nsapi_exec_tp(d, sn, rq, pool);
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1026 }
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1027 } else if(sn->currentpool != sn->defaultpool) {
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1028 // 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
1029 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
1030 }
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1031
84
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 83
diff changeset
1032 return SAF_EXEC(d->func, d->param, (Session*)sn, (Request*)rq);
37
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1033 }
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1034
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1035 int nsapi_exec_tp(
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1036 directive *d,
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1037 NSAPISession *sn,
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1038 NSAPIRequest *rq,
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1039 threadpool_t *pool)
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1040 {
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1041 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
1042 if(data == NULL) {
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1043 // TODO: set error
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1044 return REQ_ABORTED;
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1045 }
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1046 data->sn = sn;
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1047 data->rq = rq;
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1048 data->directive = d;
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1049 data->threadpool = pool;
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1050
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1051 sn->currentpool = pool;
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1052 threadpool_run(pool, thrpool_exec, data);
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1053
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1054 return REQ_PROCESSING;
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1055 }
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1056
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1057 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
1058 NSAPISession *sn = (NSAPISession*)session;
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1059 NSAPIRequest *rq = (NSAPIRequest*)request;
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1060
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1061 rq->context.last_req_code = ret;
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1062
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1063 if(sn->currentpool != sn->defaultpool) {
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1064 nsapi_change_threadpool(sn, rq, sn->defaultpool);
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1065 } else {
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1066 nsapi_handle_request(sn, rq);
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1067 }
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1068 }
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1069
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1070 void nsapi_change_threadpool(
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1071 NSAPISession *sn,
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1072 NSAPIRequest *rq,
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1073 threadpool_t *thrpool)
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1074 {
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1075 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
1076 data->sn = sn;
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1077 data->rq = rq;
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1078 data->threadpool = thrpool;
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1079
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1080 threadpool_run(thrpool, thrpool_change, data);
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1081 }
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1082
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1083 void* thrpool_exec(void *d) {
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1084 struct _tpd_data *data = d;
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1085
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1086 data->sn->currentpool = data->threadpool;
84
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 83
diff changeset
1087 int r = SAF_EXEC(
afd57ce39ec9 added initial java plugin code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 83
diff changeset
1088 data->directive->func,
37
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1089 data->directive->param,
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1090 (Session*)data->sn,
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1091 (Request*)data->rq);
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1092
116
d7a186cf87f6 adds find-pathinfo saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
1093 nsapi_function_return((Session*)data->sn, (Request*)data->rq, r);
37
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1094 free(data);
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1095
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1096 return NULL;
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1097 }
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1098
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1099 void* thrpool_change(void *d) {
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1100 struct _tpd_data *data = d;
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1101
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1102 data->sn->currentpool = data->threadpool;
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1103 nsapi_handle_request(data->sn, data->rq);
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1104
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1105 free(data);
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1106 return NULL;
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1107 }
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1108
20
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
1109
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
1110 /*
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
1111 * checks if the method matches the cmp string
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
1112 * 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
1113 * (method1|method2|method3|...)
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
1114 */
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
1115 int method_match(char *cmp, char *method) {
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
1116 if(cmp[0] != '(') {
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
1117 /* 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
1118 if(!strcmp(cmp, method)) {
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
1119 return 1;
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
1120 }
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
1121 } else if(cmp[0] == 0) {
142
55298bc9ed28 adds new a pathcheck saf and improves content type matchin and improves content type matching
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
1122 // empty string
55298bc9ed28 adds new a pathcheck saf and improves content type matchin and improves content type matching
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
1123 log_ereport(
55298bc9ed28 adds new a pathcheck saf and improves content type matchin and improves content type matching
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
1124 LOG_WARN,
55298bc9ed28 adds new a pathcheck saf and improves content type matchin and improves content type matching
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
1125 "Skipped service saf with empty method parameter");
20
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
1126 return 0;
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
1127 }
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
1128
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
1129 size_t method_len = strlen(method);
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
1130 size_t last_pos = 0;
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
1131 cmp++; /* skip '(' */
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
1132 for(int i=0;cmp[i]!=0;i++) {
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
1133 char c = cmp[i];
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
1134 if(c == '|' || c == ')') {
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
1135 size_t len = i - last_pos;
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
1136 if(len == method_len) {
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
1137 char *cp = cmp + last_pos;
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
1138 if(!memcmp(cp, method, len)) {
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
1139 return 1;
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
1140 }
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
1141 }
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
1142 last_pos = i + 1;
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
1143 }
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
1144 }
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
1145
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
1146 return 0;
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
1147 }
7b235fa88008 Some fixes for mod_jk
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 19
diff changeset
1148
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
1149 /*
142
55298bc9ed28 adds new a pathcheck saf and improves content type matchin and improves content type matching
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
1150 * checks if the content type matches the cmp string
55298bc9ed28 adds new a pathcheck saf and improves content type matchin and improves content type matching
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
1151 * the format of cmp is a single string with wildcards or a list
55298bc9ed28 adds new a pathcheck saf and improves content type matchin and improves content type matching
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
1152 * of types (also with wildcard support)
55298bc9ed28 adds new a pathcheck saf and improves content type matchin and improves content type matching
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
1153 * (type1|type2*)
55298bc9ed28 adds new a pathcheck saf and improves content type matchin and improves content type matching
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
1154 */
55298bc9ed28 adds new a pathcheck saf and improves content type matchin and improves content type matching
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
1155 int contenttype_match(sstr_t cmp, sstr_t ctype) {
55298bc9ed28 adds new a pathcheck saf and improves content type matchin and improves content type matching
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
1156 if(cmp.ptr[0] != '(') {
55298bc9ed28 adds new a pathcheck saf and improves content type matchin and improves content type matching
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
1157 if(cmp.ptr[0] == '*') {
55298bc9ed28 adds new a pathcheck saf and improves content type matchin and improves content type matching
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
1158 cmp.ptr++;
55298bc9ed28 adds new a pathcheck saf and improves content type matchin and improves content type matching
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
1159 cmp.length--;
55298bc9ed28 adds new a pathcheck saf and improves content type matchin and improves content type matching
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
1160 return sstrsuffix(ctype, cmp);
55298bc9ed28 adds new a pathcheck saf and improves content type matchin and improves content type matching
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
1161 } else if(cmp.ptr[cmp.length-1] == '*') {
55298bc9ed28 adds new a pathcheck saf and improves content type matchin and improves content type matching
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
1162 cmp.length--;
55298bc9ed28 adds new a pathcheck saf and improves content type matchin and improves content type matching
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
1163 return sstrprefix(ctype, cmp);
55298bc9ed28 adds new a pathcheck saf and improves content type matchin and improves content type matching
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
1164 } else {
55298bc9ed28 adds new a pathcheck saf and improves content type matchin and improves content type matching
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
1165 return !sstrcmp(cmp, ctype);
55298bc9ed28 adds new a pathcheck saf and improves content type matchin and improves content type matching
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
1166 }
55298bc9ed28 adds new a pathcheck saf and improves content type matchin and improves content type matching
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
1167 } else if(cmp.ptr[0] == 0) {
55298bc9ed28 adds new a pathcheck saf and improves content type matchin and improves content type matching
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
1168 log_ereport(LOG_WARN, "Skipped service saf with empty type parameter");
55298bc9ed28 adds new a pathcheck saf and improves content type matchin and improves content type matching
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
1169 return 0;
55298bc9ed28 adds new a pathcheck saf and improves content type matchin and improves content type matching
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
1170 }
55298bc9ed28 adds new a pathcheck saf and improves content type matchin and improves content type matching
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
1171
55298bc9ed28 adds new a pathcheck saf and improves content type matchin and improves content type matching
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
1172 cmp = sstrsubsl(cmp, 1, cmp.length - 2);
55298bc9ed28 adds new a pathcheck saf and improves content type matchin and improves content type matching
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
1173
55298bc9ed28 adds new a pathcheck saf and improves content type matchin and improves content type matching
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
1174 int begin = 0;
55298bc9ed28 adds new a pathcheck saf and improves content type matchin and improves content type matching
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
1175 for(int i=0;i<cmp.length;i++) {
55298bc9ed28 adds new a pathcheck saf and improves content type matchin and improves content type matching
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
1176 if(cmp.ptr[i] == '|') {
55298bc9ed28 adds new a pathcheck saf and improves content type matchin and improves content type matching
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
1177 if(contenttype_match(sstrsubsl(cmp, begin, i-begin), ctype)) {
55298bc9ed28 adds new a pathcheck saf and improves content type matchin and improves content type matching
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
1178 return 1;
55298bc9ed28 adds new a pathcheck saf and improves content type matchin and improves content type matching
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
1179 }
55298bc9ed28 adds new a pathcheck saf and improves content type matchin and improves content type matching
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
1180 begin = i + 1;
55298bc9ed28 adds new a pathcheck saf and improves content type matchin and improves content type matching
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
1181 }
55298bc9ed28 adds new a pathcheck saf and improves content type matchin and improves content type matching
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
1182 }
55298bc9ed28 adds new a pathcheck saf and improves content type matchin and improves content type matching
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
1183 return contenttype_match(sstrsubs(cmp, begin), ctype);
55298bc9ed28 adds new a pathcheck saf and improves content type matchin and improves content type matching
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
1184 }
55298bc9ed28 adds new a pathcheck saf and improves content type matchin and improves content type matching
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
1185
55298bc9ed28 adds new a pathcheck saf and improves content type matchin and improves content type matching
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 141
diff changeset
1186 /*
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
1187 * 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
1188 */
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
1189 int add_objects(
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
1190 HTTPObjectConfig *objs,
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
1191 httpd_objset *os,
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
1192 NSAPISession *sn,
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
1193 NSAPIRequest *rq,
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
1194 char *name,
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
1195 char *path)
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
1196 {
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
1197 /* first, add all objects with a matching path */
10
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
1198 /* TODO */
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
1199
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
1200
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
1201 /* add object with object with matching name */
10
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
1202 if(name == NULL) {
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
1203 return REQ_PROCEED;
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
1204 }
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
1205
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
1206 for(int i=0;i<objs->nobj;i++) {
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
1207 httpd_object *obj = objs->objects[i];
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
1208
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
1209 if(obj->name && !strcmp(name, obj->name)) {
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
1210 objset_add_object(sn->sn.pool, os, obj);
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
1211 }
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
1212 }
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
1213
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
1214 return REQ_PROCEED;
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
1215 }

mercurial