src/server/httprequest.c

Fri, 30 Dec 2011 15:19:16 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Fri, 30 Dec 2011 15:19:16 +0100
changeset 11
24d804a2799f
parent 10
e3ae779232a9
child 12
34aa8001ea53
permissions
-rw-r--r--

Fixed response header bug

1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2011 Olaf Wintermann. All rights reserved.
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include <stdio.h>
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 #include <stdlib.h>
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31
9
30e51941a673 Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
32
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 #include "nsapi.h"
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34 #include "pool.h"
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35 #include "pblock.h"
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36 #include "io.h"
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37 #include "util.h"
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38 #include "httprequest.h"
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
39 #include "conf.h"
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
40 #include "vserver.h"
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42 HTTPRequest *http_request_new() {
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43 HTTPRequest *req = malloc(sizeof(HTTPRequest));
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44 req->connection = NULL;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45 req->uri.ptr = NULL;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47 HeaderArray *hd = malloc(sizeof(HeaderArray));
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48 hd->next = NULL;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49 hd->len = 0;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50 hd->headers = calloc(16, sizeof(Header));
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51 hd->alloc = 16;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53 req->headers = hd;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
55 return req;
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
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
58 int handle_request(HTTPRequest *request) {
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59 // handle nsapi request
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 // create pool
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62 request->pool = pool_create();
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
64 // create nsapi data structures
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
65 NSAPISession *sn = malloc(sizeof(NSAPISession));
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66 NSAPIRequest *rq = malloc(sizeof(NSAPIRequest));
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67 request->rq = rq;
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
68 rq->phase = NSAPIAuthTrans;
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
69
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70 // fill session structure
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
71 sn->sys_fd = request->connection->fd;
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72 sn->sn.pool = pool_create();
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
73 sn->sn.csd = stream_new_from_fd(request->connection->fd);
9
30e51941a673 Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
74 sn->sn.client = pblock_create_pool(sn->sn.pool, 8);
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
75 sn->sn.next = NULL;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
76 sn->sn.fill = 1;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
77 sn->sn.subject = NULL;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
78
9
30e51941a673 Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
79 /* add ip to sn->client pblock */
30e51941a673 Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
80 char ip_str[INET_ADDRSTRLEN];
30e51941a673 Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
81 if(inet_ntop(
30e51941a673 Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
82 AF_INET,
30e51941a673 Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
83 &request->connection->address.sin_addr,
30e51941a673 Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
84 ip_str,
30e51941a673 Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
85 INET_ADDRSTRLEN) != NULL)
30e51941a673 Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
86 {
30e51941a673 Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
87 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
88 }
30e51941a673 Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 8
diff changeset
89
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
90 // init NSAPI request structure
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
91 if(request_initialize(request->pool, request, rq) != 0) {
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
92 printf("Cannot initialize request structure\n");
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
93 return 1;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
94 }
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
95
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
96 // set default virtual server
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
97 rq->vs = conf_get_default_vs();
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
98
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
99
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
100 /* Pass request line as "clf-request" */
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
101 pblock_kvinsert(
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
102 pb_key_clf_request,
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
103 request->request_line.ptr,
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
104 request->request_line.length,
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
105 rq->rq.reqpb);
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
106
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
107 /* Pass method as "method" in reqpb, and also as method_num */
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
108 pblock_kvinsert(
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
109 pb_key_method,
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
110 request->method.ptr,
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
111 request->method.length,
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
112 rq->rq.reqpb);
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
113 // TODO: method num
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
114 //rqRq.rq.method_num = rqHdr->GetMethodNumber();
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
115 //PR_ASSERT(rqRq.rq.method_num != -1 || iStatus);
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
116
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
117 /* Pass protocol as "protocol" in reqpb, and also in protv_num */
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
118 pblock_kvinsert(
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
119 pb_key_protocol,
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
120 request->httpv.ptr,
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
121 request->httpv.length,
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
122 rq->rq.reqpb);
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
123 // TODO: protocol num
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
124
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
125 /* Pass any query as "query" in reqpb */
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
126 // TODO: query
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
127
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
128 /* Get abs_path part of request URI, and canonicalize the path */
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
129 sstr_t absPath = request->uri;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
130 // TODO: get abs_path
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
131 absPath.ptr = util_canonicalize_uri(
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
132 request->pool,
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
133 absPath.ptr,
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
134 absPath.length,
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
135 (int*)&absPath.length);
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
136
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
137 /* Decode the abs_path */
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
138 // TODO: decode abs_path
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
139
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
140 /* Pass the abs_path as "uri" in reqpb */
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
141 // TODO: pass abs_path to reqpb
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
142 // TODO: replace this code
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
143 pblock_kvinsert(
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
144 pb_key_uri,
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
145 absPath.ptr,
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
146 absPath.length,
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
147 rq->rq.reqpb);
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
148
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
149 // pass http header to the NSAPI request structure
7
3c2ed7a7a5fd request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
150 int hlen = request->headers->len;
3c2ed7a7a5fd request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
151 HeaderArray *ha = request->headers;
3c2ed7a7a5fd request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
152 for(int i=0;i<=hlen;i++) {
3c2ed7a7a5fd request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
153 if(i == hlen) {
3c2ed7a7a5fd request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
154 ha = ha->next;
3c2ed7a7a5fd request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
155 if(ha == NULL) {
3c2ed7a7a5fd request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
156 break;
3c2ed7a7a5fd request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
157 }
3c2ed7a7a5fd request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
158 i = 0;
3c2ed7a7a5fd request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
159 hlen = ha->len;
3c2ed7a7a5fd request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
160 }
3c2ed7a7a5fd request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
161
8
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
162 if(ha->headers[i].name[0] < 90) {
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
163 ha->headers[i].name[0] += 32;
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
164 }
7
3c2ed7a7a5fd request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
165 pblock_nvinsert(ha->headers[i].name, ha->headers[i].value, rq->rq.headers);
3c2ed7a7a5fd request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 6
diff changeset
166 }
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
167
8
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
168 /* check for request body and prepare input buffer */
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
169 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
170 if(ctlen_str) {
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
171 int ctlen = atoi(ctlen_str);
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
172
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
173 printf("request body length: %d\n", ctlen);
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
174
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
175 netbuf *nb = request->netbuf;
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
176
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
177 /* create new netbuf */
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
178 NetIOStream *net_io = (NetIOStream*)net_stream_from_fd(
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
179 request->connection->fd);
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
180 net_io->max_read = ctlen;
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
181
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
182 sn->sn.inbuf = malloc(sizeof(netbuf));
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
183 sn->sn.inbuf->sd = net_io;
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
184 sn->sn.inbuf->pos = 0;
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
185
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
186 /* prepare buffer */
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
187 int cur_input_len = nb->cursize - nb->pos;
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
188 if(cur_input_len >= ctlen) {
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
189
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
190 /*
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
191 * all data is already in the primary input buffer
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
192 * just link the new netbuf to the primary buffer
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
193 */
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
194 sn->sn.inbuf->maxsize = ctlen;
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
195 sn->sn.inbuf->cursize = ctlen;
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
196 sn->sn.inbuf->inbuf = nb->inbuf + nb->pos;
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
197 } else {
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
198 sn->sn.inbuf->maxsize = (ctlen > 2048) ? (2048) : (ctlen);
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
199 sn->sn.inbuf->inbuf = malloc(sizeof(sn->sn.inbuf->maxsize));
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
200
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
201 if(cur_input_len > 0) {
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
202 /* we have read a part of the request body -> copy to netbuf */
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
203 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
204 }
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
205
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
206 sn->sn.inbuf->cursize = cur_input_len;
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
207 }
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
208 } else {
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
209 sn->sn.inbuf = NULL;
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
210 }
f4d56bf9de40 Added request body reader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 7
diff changeset
211
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
212
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
213 // Send the request to the NSAPI system
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
214 nsapi_handle_request(sn, rq);
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
215
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
216 return 0;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
217 }
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
218
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
219
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
220
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
221 void header_add(HeaderArray *hd, char *name, char *value) {
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
222 while(hd->len >= hd->alloc) {
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
223 if(hd->next == NULL) {
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
224 HeaderArray *block = malloc(sizeof(HeaderArray));
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
225 block->next = NULL;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
226 block->len = 0;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
227 block->headers = calloc(16, sizeof(Header));
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
228 block->alloc = 16;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
229 hd->next = block;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
230 }
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
231 hd = hd->next;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
232 }
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
233 hd->headers[hd->len].name = name;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
234 hd->headers[hd->len].value = value;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
235 hd->len++;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
236 }
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
237
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
238
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
239 /*
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
240 * NSAPI Processing
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
241 * TODO: add this to new file
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
242 */
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
243
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
244 int nsapi_handle_request(NSAPISession *sn, NSAPIRequest *rq) {
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
245 // TODO: threadpool
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
246
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
247 int r = REQ_NOACTION;
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
248
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
249 do {
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
250 switch(rq->phase) {
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
251 case NSAPIAuthTrans: {
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
252 rq->phase++;
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
253 nsapi_context_next_stage(&rq->context);
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
254 }
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
255 case NSAPINameTrans: {
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
256 printf(">>> NameTrans\n");
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
257 r = nsapi_nametrans(sn, rq);
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
258 if(r != REQ_PROCEED) {
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
259 break;
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
260 }
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
261 rq->phase++;
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
262 nsapi_context_next_stage(&rq->context);
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
263 }
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
264 case NSAPIPathCheck: {
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
265 printf(">>> PathCheck\n");
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
266 rq->phase++;
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
267 nsapi_context_next_stage(&rq->context);
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
268 }
5
dbc01588686e Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
269 case NSAPIObjectType: {
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
270 printf(">>> ObjectType\n");
10
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
271 r = nsapi_objecttype(sn, rq);
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
272 if(r != REQ_PROCEED) {
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
273 break;
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
274 }
5
dbc01588686e Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
275 rq->phase++;
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
276 nsapi_context_next_stage(&rq->context);
5
dbc01588686e Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
277 }
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
278 case NSAPIService: {
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
279 printf(">>> Service\n");
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
280 r = nsapi_service(sn, rq);
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
281 if(r != REQ_PROCEED) {
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
282 break;
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
283 }
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
284 rq->phase++;
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
285 nsapi_context_next_stage(&rq->context);
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
286 }
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
287 case NSAPIAddLog: {
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
288 printf(">>> AddLog\n");
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
289 rq->phase++;
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
290 nsapi_context_next_stage(&rq->context);
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
291 }
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
292 case REQ_FINISH: {
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
293 printf(">>> Finish\n");
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
294 r = nsapi_finish_request(sn, rq);
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
295 }
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
296 }
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
297 } while (r == REQ_RESTART);
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
298
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
299
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
300 return r;
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
301 }
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
302
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
303 int nsapi_finish_request(NSAPISession *sn, NSAPIRequest *rq) {
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
304 // TODO: free memory
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
305 close(sn->sys_fd);
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
306
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
307 return 0;
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
308 }
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
309
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
310 int nsapi_nametrans(NSAPISession *sn, NSAPIRequest *rq) {
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
311 HTTPObjectConfig *objconf = rq->vs->objects;
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
312 printf("nsapi_nametrans\n");
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
313 httpd_objset *objset = objset_create(sn->sn.pool);
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
314 rq->rq.os = objset;
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
315 /* first object in objconf is the default object TODO: make sure it is */
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
316 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
317
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
318 httpd_object *obj = objset->obj[0]; /* nametrans only in default object */
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
319 dtable *dt = object_get_dtable(obj, NSAPINameTrans);
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
320
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
321 /* execute directives */
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
322 int ret = rq->context.last_req_code;
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
323 char *name = NULL;
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
324 char *ppath = NULL;
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
325 for(int i=NCX_DI(rq);i<dt->ndir;i++) {
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
326 directive *d = dt->dirs[i];
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
327
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
328 printf("execute [%s]\n", d->func->name);
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
329 ret = d->func->func(d->param, (Session*)sn, (Request*)rq);
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
330
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
331 /* check for name or ppath */
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
332 name = pblock_findkeyval(pb_key_name, rq->rq.vars);
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
333 ppath = pblock_findkeyval(pb_key_ppath, rq->rq.vars);
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
334
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
335 /* add additional objects to the objset */
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
336 if(add_objects(objconf, objset, sn, rq, name, ppath) == REQ_ABORTED) {
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
337 fprintf(stderr, "add_objects failed\n");
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
338 return REQ_ABORTED;
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
339 }
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
340
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
341 if(ret != REQ_NOACTION) {
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
342 /*
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
343 * 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
344 * process this object at a later time
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
345 */
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
346 if(ret == REQ_PROCESSING) {
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
347 /* save nsapi context */
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
348 /* add +1 to start next round with next function */
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
349 rq->context.dtable_index = i + 1;
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
350 }
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
351
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
352 return ret;
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
353 }
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
354 }
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
355
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
356 /* if no function has set the ppath var, translate it to docroot */
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
357 if(ret == REQ_NOACTION && ppath == NULL) {
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
358 sstr_t docroot = rq->vs->document_root;
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
359 if(docroot.length < 1) {
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
360 printf("docroot too short\n");
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
361 return REQ_ABORTED; /* docroot too short */
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
362 }
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
363 /* if there is a trailing '/', remove it */
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
364 if(docroot.ptr[docroot.length - 1] == '/') {
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
365 docroot.length--;
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
366 }
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
367
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
368 sstr_t uri = sstr(pblock_findkeyval(pb_key_uri, rq->rq.reqpb));
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
369
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
370 sstr_t translated;
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
371 translated.length = docroot.length + uri.length;
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
372 translated.ptr = alloca(translated.length + 1);
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
373 translated = sstrncat(2, translated, docroot, uri);
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
374
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
375 pblock_kvinsert(
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
376 pb_key_ppath,
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
377 translated.ptr,
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
378 translated.length,
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
379 rq->rq.vars);
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
380 }
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
381
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
382 return REQ_PROCEED;
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
383 }
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
384
10
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
385 int nsapi_objecttype(NSAPISession *sn, NSAPIRequest *rq) {
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
386 printf("nsapi_objecttype\n");
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
387 httpd_objset *objset = rq->rq.os;
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
388
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
389 if(NCX_OI(rq) == -1) {
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
390 /* object index is undefined -> define correct object index */
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
391 NCX_OI(rq) = objset->pos - 1;
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
392 }
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
393
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
394 int ret = rq->context.last_req_code;
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
395 for(int i=NCX_OI(rq);i>=0;i--) {
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
396 httpd_object *obj = objset->obj[i];
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
397 dtable *dt = object_get_dtable(obj, NSAPIObjectType);
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
398
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
399 // execute directives
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
400 for(int j=0;j<dt->ndir;j++) {
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
401 directive *d = dt->dirs[j];
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
402
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
403 ret = d->func->func(d->param, (Session*)sn, (Request*)rq);
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
404 switch(ret) {
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
405 case REQ_PROCEED: {
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
406 char *type = pblock_findkeyval(
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
407 pb_key_content_type,
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
408 rq->rq.srvhdrs);
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
409 if(type == NULL) {
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
410 ret = REQ_NOACTION;
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
411 break;
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
412 }
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
413 return ret;
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
414 }
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
415 case REQ_PROCESSING: {
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
416 /* save nsapi context */
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
417 rq->context.objset_index = i;
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
418
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
419 /* add +1 to start next round with next function */
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
420 rq->context.dtable_index = j + 1;
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
421 return ret;
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
422 }
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
423 case REQ_NOACTION: {
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
424 break;
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
425 }
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
426 default: {
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
427 return ret;
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
428 }
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
429 }
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
430 }
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
431 }
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
432
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
433 /*
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
434 * 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
435 * 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
436 * 'internal/directory' so that 'index-common' can serve the content.
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
437 * Otherwise we set the content type to text/plain
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
438 */
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
439 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
440 sstr_t ct;
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
441 if(path.ptr[path.length - 1] == '/') {
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
442 /* directory */
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
443 ct = sstrn("internal/directory", 18);
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
444 } else {
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
445 ct = sstrn("text/plain", 10);
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
446 }
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
447 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
448
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
449 return REQ_PROCEED;
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
450 }
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
451
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
452 int nsapi_service(NSAPISession *sn, NSAPIRequest *rq) {
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
453 printf("nsapi_service\n");
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
454 httpd_objset *objset = rq->rq.os;
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
455
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
456 if(NCX_OI(rq) == -1) {
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
457 NCX_OI(rq) = objset->pos - 1;
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
458 }
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
459
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
460 int ret = rq->context.last_req_code;
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
461 for(int i=NCX_OI(rq);i>=0;i--) {
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
462 httpd_object *obj = objset->obj[i];
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
463 dtable *dt = object_get_dtable(obj, NSAPIService);
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 // execute directives
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
466 for(int j=0;j<dt->ndir;j++) {
5
dbc01588686e Added parser for obj.conf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
467 directive *d = dt->dirs[j];
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
468
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
469 ret = d->func->func(d->param, (Session*)sn, (Request*)rq);
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
470 if(ret != REQ_NOACTION) {
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
471 if(ret == REQ_PROCESSING) {
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
472 /* save nsapi context */
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
473 rq->context.objset_index = i;
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
474
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
475 /* add +1 to start next round with next function */
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
476 rq->context.dtable_index = j + 1;
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
477 }
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
478
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
479 return ret;
3
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
480 }
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
481 }
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
482 }
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
483
137197831306 minimal request handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
484 return ret;
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
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
487 /*
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
488 * 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
489 */
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
490 int add_objects(
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
491 HTTPObjectConfig *objs,
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
492 httpd_objset *os,
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
493 NSAPISession *sn,
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
494 NSAPIRequest *rq,
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
495 char *name,
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
496 char *path)
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
497 {
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
498 /* first, add all objects with a matching path */
10
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
499 /* TODO */
6
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
500
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
501
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
502 /* add object with object with matching name */
10
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
503 if(name == NULL) {
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
504 return REQ_PROCEED;
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
505 }
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
506
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
507 for(int i=0;i<objs->nobj;i++) {
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
508 httpd_object *obj = objs->objects[i];
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
509
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
510 if(obj->name && !strcmp(name, obj->name)) {
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
511 printf("name is %s -> add object %s\n", name, obj->name);
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
512 objset_add_object(sn->sn.pool, os, obj);
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
513 }
e3ae779232a9 Added some safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
514 }
6
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 return REQ_PROCEED;
ce8fecc9847d improved request processing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
517 }

mercurial