Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 791 lines (625 sloc) 19.906 kB
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2
3 /* Cherokee
4 *
5 * Authors:
6 * Alvaro Lopez Ortega <alvaro@alobbs.com>
7 *
2c39092 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2660 5dc97367-9…
alobbs authored
8 * Copyright (C) 2001-2009 Alvaro Lopez Ortega
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of version 2 of the GNU General Public
12 * License as published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
2c39092 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2660 5dc97367-9…
alobbs authored
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 * 02110-1301, USA.
23 */
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
24
25 #include "common-internal.h"
a18b345 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1708 5dc97367-9…
alobbs authored
26
27 #include <fcntl.h>
28
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
29 #include "handler_fcgi.h"
30 #include "header.h"
31 #include "connection-protected.h"
32 #include "util.h"
33 #include "thread.h"
7b0e48a @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@387 5dc97367-97…
alobbs authored
34 #include "source_interpreter.h"
a18b345 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1708 5dc97367-9…
alobbs authored
35 #include "bogotime.h"
4d387f4 @alobbs This patch changes substantially the way in which errors and warnings
alobbs authored
36 #include "error_log.h"
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
37
38 #include "fastcgi.h"
39
40 #define POST_PACKAGE_LEN 32600
41 #define ENTRIES "fcgi,handler"
42
43
44 #define set_env(cgi,key,val,len) \
45 set_env_pair (cgi, key, sizeof(key)-1, val, len)
46
47
48 static void set_env_pair (cherokee_handler_cgi_base_t *cgi_base,
1e47304 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2701 5dc97367-9…
alobbs authored
49 const char *key, int key_len,
50 const char *val, int val_len);
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
51
b69d2e0 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@476 5dc97367-97…
alobbs authored
52 /* Plug-in initialization
53 */
0d3a69e @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2867 5dc97367-9…
alobbs authored
54 CGI_LIB_INIT (fcgi, http_all_methods);
b69d2e0 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@476 5dc97367-97…
alobbs authored
55
56
57 /* Methods implementation
58 */
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
59 static ret_t
60 process_package (cherokee_handler_fcgi_t *hdl, cherokee_buffer_t *inbuf, cherokee_buffer_t *outbuf)
61 {
62 FCGI_Header *header;
63 FCGI_EndRequestBody *ending;
64 cherokee_connection_t *conn = HANDLER_CONN(hdl);
65
66 cuint_t len;
67 char *data;
68 cint_t return_val;
69 cuint_t type;
70 cuint_t id;
71 cuint_t padding;
4a68bff git-svn-id: svn://cherokee-project.com/cherokee/trunk@2404 5dc97367-9…
taher authored
72
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
73 /* Is there enough information?
74 */
75 if (inbuf->len < sizeof(FCGI_Header))
76 return ret_ok;
77
78 /* At least there is a header
79 */
80 header = (FCGI_Header *)inbuf->buf;
81
82 if (header->version != 1) {
83 cherokee_buffer_print_debug (inbuf, -1);
29d5de9 @alobbs Replace almost all the PRINT_ERROR, PRINT_ERROR_S and PRINT_ERRNO by
alobbs authored
84 LOG_ERROR_S ("Parsing error: unknown version\n");
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
85 return ret_error;
86 }
87
88 if (header->type != FCGI_STDERR &&
89 header->type != FCGI_STDOUT &&
81679d0 handler_*.c, space / code style cleanups
ADF authored
90 header->type != FCGI_END_REQUEST) {
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
91 cherokee_buffer_print_debug (inbuf, -1);
29d5de9 @alobbs Replace almost all the PRINT_ERROR, PRINT_ERROR_S and PRINT_ERRNO by
alobbs authored
92 LOG_ERROR_S ("Parsing error: unknown type\n");
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
93 return ret_error;
94 }
95
96 /* Read the header
97 */
98 type = header->type;
99 padding = header->paddingLength;
100 id = (header->requestIdB0 | (header->requestIdB1 << 8));
101 len = (header->contentLengthB0 | (header->contentLengthB1 << 8));
102 data = inbuf->buf + FCGI_HEADER_LEN;
103
b13f4bf @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@446 5dc97367-97…
alobbs authored
104 /* printf ("have %d, hdr=%d exp_len=%d pad=%d\n", inbuf->len, FCGI_HEADER_LEN, len, padding); */
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
105
106 /* Is the package complete?
107 */
108 if (len + padding > inbuf->len - FCGI_HEADER_LEN) {
b13f4bf @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@446 5dc97367-97…
alobbs authored
109 /* printf ("Incomplete: %d < %d\n", len + padding, inbuf->len - FCGI_HEADER_LEN); */
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
110 return ret_ok;
111 }
112
113 /* It has received the full package content
114 */
115 switch (type) {
116 case FCGI_STDERR:
b13f4bf @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@446 5dc97367-97…
alobbs authored
117 /* printf ("READ:STDERR (%d): %s", len, data?data:""); */
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
118
119 if (CONN_VSRV(conn)->logger != NULL) {
4d387f4 @alobbs This patch changes substantially the way in which errors and warnings
alobbs authored
120 LOG_ERROR("%s\n", data);
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
121 }
4a68bff git-svn-id: svn://cherokee-project.com/cherokee/trunk@2404 5dc97367-9…
taher authored
122 else if (SOURCE_INT(hdl->src_ref)->debug) {
123 PRINT_MSG ("%.*s\n", len, data);
124 }
125
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
126 break;
127
128 case FCGI_STDOUT:
8b87f31 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@3199 5dc97367-9…
alobbs authored
129 /* printf ("READ:STDOUT eof=%d: %d", HDL_CGI_BASE(hdl)->got_eof, len); */
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
130 cherokee_buffer_add (outbuf, data, len);
131 break;
132
133 case FCGI_END_REQUEST:
134 ending = (FCGI_EndRequestBody *)data;
135
136 return_val = ((ending->appStatusB0) |
137 (ending->appStatusB0 << 8) |
138 (ending->appStatusB0 << 16) |
139 (ending->appStatusB0 << 24));
140
3509796 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@282 5dc97367-97…
alobbs authored
141 HDL_CGI_BASE(hdl)->got_eof = true;
b13f4bf @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@446 5dc97367-97…
alobbs authored
142 /* printf ("READ:END"); */
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
143 break;
144
145 default:
146 SHOULDNT_HAPPEN;
147 }
148
149 cherokee_buffer_move_to_begin (inbuf, len + FCGI_HEADER_LEN + padding);
4a68bff git-svn-id: svn://cherokee-project.com/cherokee/trunk@2404 5dc97367-9…
taher authored
150 /* printf ("- FCGI left %d\n", inbuf->len); */
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
151 return ret_eagain;
152 }
153
154
155 static ret_t
156 process_buffer (cherokee_handler_fcgi_t *hdl, cherokee_buffer_t *inbuf, cherokee_buffer_t *outbuf)
157 {
158 ret_t ret;
159
160 do {
161 ret = process_package (hdl, inbuf, outbuf);
162 } while (ret == ret_eagain);
163
164 if (ret == ret_ok) {
165 if (cherokee_buffer_is_empty (outbuf))
3509796 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@282 5dc97367-97…
alobbs authored
166 return (HDL_CGI_BASE(hdl)->got_eof) ? ret_eof : ret_eagain;
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
167 }
168
169 return ret;
170 }
171
172 static ret_t
173 read_from_fcgi (cherokee_handler_cgi_base_t *cgi, cherokee_buffer_t *buffer)
174 {
175 ret_t ret;
176 size_t read = 0;
3509796 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@282 5dc97367-97…
alobbs authored
177 cherokee_handler_fcgi_t *fcgi = HDL_FCGI(cgi);
ba212a4 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@467 5dc97367-97…
alobbs authored
178
0932395 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@656 5dc97367-97…
alobbs authored
179 ret = cherokee_socket_bufread (&fcgi->socket, &fcgi->write_buffer, DEFAULT_READ_SIZE, &read);
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
180
181 switch (ret) {
182 case ret_eagain:
24f5c27 @alobbs Check thread_deactive_to_polling() returned value.
alobbs authored
183 ret = cherokee_thread_deactive_to_polling (HANDLER_THREAD(cgi), HANDLER_CONN(cgi),
184 fcgi->socket.socket, FDPOLL_MODE_READ,
185 false);
186 if (unlikely (ret != ret_ok)) {
187 cgi->got_eof = true;
188 return ret_error;
189 }
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
190 return ret_eagain;
191
192 case ret_ok:
193 ret = process_buffer (fcgi, &fcgi->write_buffer, buffer);
d5e94a6 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1175 5dc97367-9…
alobbs authored
194 TRACE (ENTRIES, "%d bytes read, buffer.len %d\n", read, buffer->len);
24f5c27 @alobbs Check thread_deactive_to_polling() returned value.
alobbs authored
195
196 if ((ret == ret_ok) && cgi->got_eof && (buffer->len > 0)) {
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
197 return ret_eof_have_data;
24f5c27 @alobbs Check thread_deactive_to_polling() returned value.
alobbs authored
198 }
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
199 return ret;
200
201 case ret_eof:
202 case ret_error:
203 cgi->got_eof = true;
204 return ret;
205
206 default:
207 RET_UNKNOWN(ret);
208 }
209
210 SHOULDNT_HAPPEN;
2e0ea0e @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@430 5dc97367-97…
alobbs authored
211 return ret_error;
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
212 }
213
214
b6c69ad @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@269 5dc97367-97…
alobbs authored
215 static ret_t
be04810 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@283 5dc97367-97…
alobbs authored
216 props_free (cherokee_handler_fcgi_props_t *props)
217 {
7b0e48a @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@387 5dc97367-97…
alobbs authored
218 if (props->balancer != NULL)
219 cherokee_balancer_free (props->balancer);
623deda @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@294 5dc97367-97…
alobbs authored
220
221 return cherokee_handler_cgi_base_props_free (PROP_CGI_BASE(props));
be04810 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@283 5dc97367-97…
alobbs authored
222 }
223
224
b69d2e0 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@476 5dc97367-97…
alobbs authored
225 ret_t
8b87f31 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@3199 5dc97367-9…
alobbs authored
226 cherokee_handler_fcgi_configure (cherokee_config_node_t *conf,
227 cherokee_server_t *srv,
228 cherokee_module_props_t **_props)
b6c69ad @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@269 5dc97367-97…
alobbs authored
229 {
3509796 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@282 5dc97367-97…
alobbs authored
230 ret_t ret;
ee8023f @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@384 5dc97367-97…
alobbs authored
231 cherokee_list_t *i;
3509796 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@282 5dc97367-97…
alobbs authored
232 cherokee_handler_fcgi_props_t *props;
b6c69ad @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@269 5dc97367-97…
alobbs authored
233
3509796 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@282 5dc97367-97…
alobbs authored
234 /* Instance a new property object
235 */
236 if (*_props == NULL) {
237 CHEROKEE_NEW_STRUCT (n, handler_fcgi_props);
be04810 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@283 5dc97367-97…
alobbs authored
238
b69d2e0 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@476 5dc97367-97…
alobbs authored
239 cherokee_handler_cgi_base_props_init_base (PROP_CGI_BASE(n),
240 MODULE_PROPS_FREE(props_free));
241
242 INIT_LIST_HEAD (&n->server_list);
7b0e48a @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@387 5dc97367-97…
alobbs authored
243 n->balancer = NULL;
244
245 *_props = MODULE_PROPS(n);
3509796 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@282 5dc97367-97…
alobbs authored
246 }
247
248 props = PROP_FCGI(*_props);
249
250 /* Parse the configuration tree
251 */
b6c69ad @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@269 5dc97367-97…
alobbs authored
252 cherokee_config_node_foreach (i, conf) {
253 cherokee_config_node_t *subconf = CONFIG_NODE(i);
254
7b0e48a @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@387 5dc97367-97…
alobbs authored
255 if (equal_buf_str (&subconf->key, "balancer")) {
256 ret = cherokee_balancer_instance (&subconf->val, subconf, srv, &props->balancer);
b6c69ad @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@269 5dc97367-97…
alobbs authored
257 if (ret != ret_ok) return ret;
258 }
259 }
260
7b0e48a @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@387 5dc97367-97…
alobbs authored
261 /* Init base class
262 */
263 ret = cherokee_handler_cgi_base_configure (conf, srv, _props);
264 if (ret != ret_ok) return ret;
265
266 /* Final checks
267 */
268 if (props->balancer == NULL) {
29d5de9 @alobbs Replace almost all the PRINT_ERROR, PRINT_ERROR_S and PRINT_ERRNO by
alobbs authored
269 LOG_CRITICAL_S ("fcgi handler needs a balancer\n");
7b0e48a @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@387 5dc97367-97…
alobbs authored
270 return ret_error;
271 }
272
273 return ret_ok;
b6c69ad @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@269 5dc97367-97…
alobbs authored
274 }
275
276
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
277 ret_t
7b0e48a @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@387 5dc97367-97…
alobbs authored
278 cherokee_handler_fcgi_new (cherokee_handler_t **hdl, void *cnt, cherokee_module_props_t *props)
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
279 {
280 CHEROKEE_NEW_STRUCT (n, handler_fcgi);
281
282 /* Init the base class
283 */
b69d2e0 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@476 5dc97367-97…
alobbs authored
284 cherokee_handler_cgi_base_init (HDL_CGI_BASE(n), cnt, PLUGIN_INFO_HANDLER_PTR(fcgi),
285 HANDLER_PROPS(props), set_env_pair, read_from_fcgi);
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
286
287 /* Virtual methods
288 */
289 MODULE(n)->init = (handler_func_init_t) cherokee_handler_fcgi_init;
423d6fa @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@370 5dc97367-97…
alobbs authored
290 MODULE(n)->free = (module_func_free_t) cherokee_handler_fcgi_free;
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
291
292 /* Virtual methods: implemented by handler_cgi_base
293 */
294 HANDLER(n)->step = (handler_func_step_t) cherokee_handler_cgi_base_step;
295 HANDLER(n)->add_headers = (handler_func_add_headers_t) cherokee_handler_cgi_base_add_headers;
296
297 /* Properties
298 */
299 n->post_phase = fcgi_post_init;
300 n->post_len = 0;
a18b345 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1708 5dc97367-9…
alobbs authored
301 n->src_ref = NULL;
ba212a4 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@467 5dc97367-97…
alobbs authored
302
a18b345 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1708 5dc97367-9…
alobbs authored
303 cherokee_socket_init (&n->socket);
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
304 cherokee_buffer_init (&n->write_buffer);
305 cherokee_buffer_ensure_size (&n->write_buffer, 512);
306
307 /* Return the object
308 */
309 *hdl = HANDLER(n);
310 return ret_ok;
311 }
312
313
314 ret_t
315 cherokee_handler_fcgi_free (cherokee_handler_fcgi_t *hdl)
316 {
483759d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@466 5dc97367-97…
alobbs authored
317 TRACE (ENTRIES, "fcgi handler free: %p\n", hdl);
318
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
319 cherokee_socket_close (&hdl->socket);
320 cherokee_socket_mrproper (&hdl->socket);
321
322 cherokee_buffer_mrproper (&hdl->write_buffer);
323
3509796 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@282 5dc97367-97…
alobbs authored
324 return cherokee_handler_cgi_base_free (HDL_CGI_BASE(hdl));
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
325 }
326
327
328 static void
329 fcgi_build_header (FCGI_Header *hdr, cuchar_t type, cushort_t request_id, cuint_t content_length, cuchar_t padding)
330 {
81679d0 handler_*.c, space / code style cleanups
ADF authored
331 hdr->version = FCGI_VERSION_1;
332 hdr->type = type;
333 hdr->requestIdB0 = (cuchar_t) request_id;
334 hdr->requestIdB1 = (cuchar_t) (request_id >> 8) & 0xff;
335 hdr->contentLengthB0 = (cuchar_t) (content_length % 256);
336 hdr->contentLengthB1 = (cuchar_t) (content_length / 256);
337 hdr->paddingLength = padding;
338 hdr->reserved = 0;
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
339 }
340
341 static void
342 fcgi_build_request_body (FCGI_BeginRequestRecord *request)
343 {
81679d0 handler_*.c, space / code style cleanups
ADF authored
344 request->body.roleB0 = FCGI_RESPONDER;
345 request->body.roleB1 = 0;
346 request->body.flags = 0;
347 request->body.reserved[0] = 0;
348 request->body.reserved[1] = 0;
349 request->body.reserved[2] = 0;
350 request->body.reserved[3] = 0;
351 request->body.reserved[4] = 0;
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
352 }
353
354 static void
355 set_env_pair (cherokee_handler_cgi_base_t *cgi_base,
1e47304 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2701 5dc97367-9…
alobbs authored
356 const char *key, int key_len,
357 const char *val, int val_len)
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
358 {
81679d0 handler_*.c, space / code style cleanups
ADF authored
359 int len;
360 FCGI_BeginRequestRecord request;
3509796 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@282 5dc97367-97…
alobbs authored
361 cherokee_handler_fcgi_t *hdl = HDL_FCGI(cgi_base);
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
362 cherokee_buffer_t *buf = &hdl->write_buffer;
363
0a136b0 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@3233 5dc97367-9…
alobbs authored
364 #ifdef TRACE_ENABLED
365 cherokee_buffer_t *tmp = &HANDLER_THREAD(cgi_base)->tmp_buf2;
366
367 cherokee_buffer_clean (tmp);
368 cherokee_buffer_add (tmp, key, key_len);
369 cherokee_buffer_add_str (tmp, " = \"");
370 cherokee_buffer_add (tmp, val, val_len);
371 cherokee_buffer_add_str (tmp, "\"\n");
372
373 TRACE (ENTRIES, "%s", tmp->buf);
374 #endif
375
81679d0 handler_*.c, space / code style cleanups
ADF authored
376 len = key_len + val_len;
377 len += key_len > 127 ? 4 : 1;
378 len += val_len > 127 ? 4 : 1;
379
380 fcgi_build_header (&request.header, FCGI_PARAMS, 1, len, 0);
381
382 cherokee_buffer_ensure_size (buf, buf->len + sizeof(FCGI_Header) + key_len + val_len);
383 cherokee_buffer_add (buf, (void *)&request.header, sizeof(FCGI_Header));
384
385 if (key_len <= 127) {
386 buf->buf[buf->len++] = key_len;
387 } else {
388 buf->buf[buf->len++] = ((key_len >> 24) & 0xff) | 0x80;
389 buf->buf[buf->len++] = (key_len >> 16) & 0xff;
390 buf->buf[buf->len++] = (key_len >> 8) & 0xff;
391 buf->buf[buf->len++] = (key_len >> 0) & 0xff;
392 }
393
394 if (val_len <= 127) {
395 buf->buf[buf->len++] = val_len;
396 } else {
397 buf->buf[buf->len++] = ((val_len >> 24) & 0xff) | 0x80;
398 buf->buf[buf->len++] = (val_len >> 16) & 0xff;
399 buf->buf[buf->len++] = (val_len >> 8) & 0xff;
400 buf->buf[buf->len++] = (val_len >> 0) & 0xff;
401 }
402
403 cherokee_buffer_add (buf, key, key_len);
404 cherokee_buffer_add (buf, val, val_len);
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
405 }
406
407
408 static ret_t
409 add_extra_fcgi_env (cherokee_handler_fcgi_t *hdl, cuint_t *last_header_offset)
410 {
8cdea13 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2969 5dc97367-9…
alobbs authored
411 off_t post_len = 0;
3509796 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@282 5dc97367-97…
alobbs authored
412 cherokee_handler_cgi_base_t *cgi_base = HDL_CGI_BASE(hdl);
81679d0 handler_*.c, space / code style cleanups
ADF authored
413 cherokee_buffer_t buffer = CHEROKEE_BUF_INIT;
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
414 cherokee_connection_t *conn = HANDLER_CONN(hdl);
415
416 /* CONTENT_LENGTH
417 */
8cdea13 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2969 5dc97367-9…
alobbs authored
418 if (http_method_with_input (conn->header.method)) {
419 cherokee_post_get_len (&conn->post, &post_len);
420
421 cherokee_buffer_add_ullong10 (&buffer, post_len);
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
422 set_env (cgi_base, "CONTENT_LENGTH", buffer.buf, buffer.len);
8cdea13 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2969 5dc97367-9…
alobbs authored
423 }
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
424
425 /* Add PATH_TRANSLATED only it there is pathinfo
426 */
427 #if 0
428 if (! cherokee_buffer_is_empty (&conn->pathinfo)) {
429 cherokee_buffer_add_buffer (&buffer, &conn->local_directory);
430 cherokee_buffer_add_buffer (&buffer, &conn->pathinfo);
431
432 set_env (cgi_base, "PATH_TRANSLATED", buffer.buf, buffer.len);
433 TRACE (ENTRIES, "PATH_TRANSLATED '%s'\n", cgi_base->executable.buf);
434 }
435 #endif
436
437 /* The last one
438 */
439 *last_header_offset = hdl->write_buffer.len;
440
6b3a530 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2959 5dc97367-9…
alobbs authored
441 set_env (cgi_base, "SCRIPT_FILENAME",
442 cgi_base->executable.buf,
443 cgi_base->executable.len);
444
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
445 TRACE (ENTRIES, "SCRIPT_FILENAME '%s'\n", cgi_base->executable.buf);
446
447 cherokee_buffer_mrproper (&buffer);
448 return ret_ok;
449 }
450
451
452 static void
453 fixup_padding (cherokee_buffer_t *buf, cuint_t last_header_offset)
454 {
81679d0 handler_*.c, space / code style cleanups
ADF authored
455 cuint_t rest;
456 cuint_t pad;
457 static char padding[8] = {0, 0, 0, 0, 0, 0, 0, 0};
458 FCGI_Header *last_header;
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
459
81679d0 handler_*.c, space / code style cleanups
ADF authored
460 if (buf->len <= 0)
461 return;
462 last_header = (FCGI_Header *) (buf->buf + last_header_offset);
463 rest = buf->len % 8;
464 pad = 8 - rest;
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
465
81679d0 handler_*.c, space / code style cleanups
ADF authored
466 if (rest == 0)
467 return;
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
468
81679d0 handler_*.c, space / code style cleanups
ADF authored
469 last_header->paddingLength = pad;
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
470
81679d0 handler_*.c, space / code style cleanups
ADF authored
471 cherokee_buffer_ensure_size (buf, buf->len + pad);
472 cherokee_buffer_add (buf, padding, pad);
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
473 }
474
475 static void
476 add_empty_packet (cherokee_handler_fcgi_t *hdl, cuint_t type)
477 {
81679d0 handler_*.c, space / code style cleanups
ADF authored
478 FCGI_BeginRequestRecord request;
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
479
81679d0 handler_*.c, space / code style cleanups
ADF authored
480 fcgi_build_header (&request.header, type, 1, 0, 0);
481 cherokee_buffer_add (&hdl->write_buffer, (void *)&request.header, sizeof(FCGI_Header));
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
482
81679d0 handler_*.c, space / code style cleanups
ADF authored
483 TRACE (ENTRIES, "empty packet type=%d, len=%d\n", type, hdl->write_buffer.len);
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
484 }
485
486
487 static ret_t
488 build_header (cherokee_handler_fcgi_t *hdl, cherokee_buffer_t *buffer)
489 {
490 FCGI_BeginRequestRecord request;
81679d0 handler_*.c, space / code style cleanups
ADF authored
491 cuint_t last_header_offset;
2e0ea0e @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@430 5dc97367-97…
alobbs authored
492 cherokee_connection_t *conn = HANDLER_CONN(hdl);
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
493
494 cherokee_buffer_clean (buffer);
495
496 /* FCGI_BEGIN_REQUEST
497 */
81679d0 handler_*.c, space / code style cleanups
ADF authored
498 fcgi_build_header (&request.header, FCGI_BEGIN_REQUEST, 1, sizeof(request.body), 0);
499 fcgi_build_request_body (&request);
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
500
501 cherokee_buffer_add (buffer, (void *)&request, sizeof(FCGI_BeginRequestRecord));
81679d0 handler_*.c, space / code style cleanups
ADF authored
502 TRACE (ENTRIES, "Added FCGI_BEGIN_REQUEST, len=%d\n", buffer->len);
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
503
504 /* Add enviroment variables
505 */
3509796 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@282 5dc97367-97…
alobbs authored
506 cherokee_handler_cgi_base_build_envp (HDL_CGI_BASE(hdl), conn);
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
507
508 add_extra_fcgi_env (hdl, &last_header_offset);
81679d0 handler_*.c, space / code style cleanups
ADF authored
509 fixup_padding (buffer, last_header_offset);
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
510
81679d0 handler_*.c, space / code style cleanups
ADF authored
511 /* There are no more parameters
512 */
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
513 add_empty_packet (hdl, FCGI_PARAMS);
514
81679d0 handler_*.c, space / code style cleanups
ADF authored
515 TRACE (ENTRIES, "Added FCGI_PARAMS, len=%d\n", buffer->len);
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
516 return ret_ok;
517 }
518
519
520 static ret_t
521 connect_to_server (cherokee_handler_fcgi_t *hdl)
522 {
3509796 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@282 5dc97367-97…
alobbs authored
523 ret_t ret;
5695e23 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1849 5dc97367-9…
alobbs authored
524 cherokee_connection_t *conn = HANDLER_CONN(hdl);
525 cherokee_handler_fcgi_props_t *props = HANDLER_FCGI_PROPS(hdl);
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
526
a18b345 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1708 5dc97367-9…
alobbs authored
527 /* Get a reference to the target host
528 */
529 if (hdl->src_ref == NULL) {
530 ret = cherokee_balancer_dispatch (props->balancer, conn, &hdl->src_ref);
531 if (ret != ret_ok)
532 return ret;
533 }
7b0e48a @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@387 5dc97367-97…
alobbs authored
534
a18b345 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1708 5dc97367-9…
alobbs authored
535 /* Try to connect
536 */
14efdd8 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2572 5dc97367-9…
alobbs authored
537 if (hdl->src_ref->type == source_host) {
538 ret = cherokee_source_connect_polling (hdl->src_ref, &hdl->socket, conn);
539 if ((ret == ret_deny) || (ret == ret_error))
540 {
541 cherokee_balancer_report_fail (props->balancer, conn, hdl->src_ref);
542 }
543 } else {
544 ret = cherokee_source_interpreter_connect_polling (SOURCE_INT(hdl->src_ref),
83990a0 @alobbs A fragment of the spawning mechanism has been rewritten. This new
alobbs authored
545 &hdl->socket, conn);
14efdd8 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2572 5dc97367-9…
alobbs authored
546 }
45ead25 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@428 5dc97367-97…
alobbs authored
547
14efdd8 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2572 5dc97367-9…
alobbs authored
548 return ret;
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
549 }
550
551
552 static ret_t
553 do_send (cherokee_handler_fcgi_t *hdl, cherokee_buffer_t *buffer)
554 {
2e0ea0e @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@430 5dc97367-97…
alobbs authored
555 ret_t ret;
b0dd10b @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1398 5dc97367-9…
alobbs authored
556 size_t written = 0;
2e0ea0e @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@430 5dc97367-97…
alobbs authored
557 cherokee_connection_t *conn = HANDLER_CONN(hdl);
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
558
0932395 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@656 5dc97367-97…
alobbs authored
559 ret = cherokee_socket_bufwrite (&hdl->socket, buffer, &written);
ba212a4 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@467 5dc97367-97…
alobbs authored
560 switch (ret) {
561 case ret_ok:
3cbd17a @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@475 5dc97367-97…
alobbs authored
562 break;
ba212a4 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@467 5dc97367-97…
alobbs authored
563 case ret_eagain:
b69d2e0 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@476 5dc97367-97…
alobbs authored
564 if (written > 0)
565 break;
ba212a4 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@467 5dc97367-97…
alobbs authored
566 return ret_eagain;
567 default:
2e0ea0e @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@430 5dc97367-97…
alobbs authored
568 conn->error_code = http_bad_gateway;
ba212a4 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@467 5dc97367-97…
alobbs authored
569 return ret_error;
2e0ea0e @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@430 5dc97367-97…
alobbs authored
570 }
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
571
572 cherokee_buffer_move_to_begin (buffer, written);
573
574 TRACE (ENTRIES, "sent remaining=%d\n", buffer->len);
575
576 if (! cherokee_buffer_is_empty (buffer))
577 return ret_eagain;
578
579 return ret_ok;
580 }
581
582
583 static ret_t
f11857f @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@600 5dc97367-97…
alobbs authored
584 send_no_post (cherokee_handler_fcgi_t *hdl, cherokee_buffer_t *buf)
585 {
586 switch (hdl->post_phase) {
587 case fcgi_post_init:
588 add_empty_packet (hdl, FCGI_STDIN);
589 hdl->post_phase = fcgi_post_write;
590
591 case fcgi_post_write:
592 return do_send (hdl, buf);
593
594 default:
595 SHOULDNT_HAPPEN;
596 }
597 return ret_error;
598 }
599
600
601 static ret_t
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
602 send_post (cherokee_handler_fcgi_t *hdl, cherokee_buffer_t *buf)
603 {
604 ret_t ret;
605 cherokee_connection_t *conn = HANDLER_CONN(hdl);
606 static FCGI_Header empty_header = {0,0,0,0,0,0,0,0};
607
608 switch (hdl->post_phase) {
609 case fcgi_post_init:
610 TRACE (ENTRIES, "Post %s\n", "init");
611
612 /* Init the POST storing object
613 */
614 cherokee_post_walk_reset (&conn->post);
615 cherokee_post_get_len (&conn->post, &hdl->post_len);
616
617 if (hdl->post_len <= 0)
618 return ret_ok;
619
620 hdl->post_phase = fcgi_post_read;
621
622 case fcgi_post_read:
623 TRACE (ENTRIES, "Post %s\n", "read");
624
625 /* Add space for the header, it'll filled out later on..
626 */
627 if (cherokee_buffer_is_empty (buf)) {
0f3a68f @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@625 5dc97367-97…
alobbs authored
628 cherokee_buffer_add (buf, (const char *)&empty_header, sizeof (FCGI_Header));
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
629 }
630
631 /* Take a chunck of post
632 */
633 ret = cherokee_post_walk_read (&conn->post, buf, POST_PACKAGE_LEN);
634 switch (ret) {
635 case ret_ok:
636 case ret_eagain:
637 break;
638 case ret_error:
639 return ret;
640 default:
641 RET_UNKNOWN(ret);
642 return ret_error;
643 }
644
645 TRACE (ENTRIES, "Post buffer.len %d\n", buf->len);
646
647 /* Complete the header
648 */
649 if (buf->len > sizeof(FCGI_Header)) {
650 fcgi_build_header ((FCGI_Header *)buf->buf, FCGI_STDIN, 1,
651 buf->len - sizeof(FCGI_Header), 0);
652 }
653
654 /* Close STDIN if it was the last chunck
655 */
656 ret = cherokee_post_walk_finished (&conn->post);
657 if (ret == ret_ok) {
658 add_empty_packet (hdl, FCGI_STDIN);
659 }
660
661 hdl->post_phase = fcgi_post_write;
662
663 case fcgi_post_write:
664 TRACE (ENTRIES, "Post write, buf.len=%d (header len %d)\n", buf->len, sizeof(FCGI_Header));
665
666 if (! cherokee_buffer_is_empty (buf)) {
667 ret = do_send (hdl, buf);
668 switch (ret) {
669 case ret_ok:
670 break;
671 case ret_eagain:
672 return ret_eagain;
673 case ret_eof:
674 case ret_error:
675 return ret_error;
676 default:
677 RET_UNKNOWN(ret);
678 return ret_error;
679 }
680 }
681
682 if (! cherokee_buffer_is_empty (buf))
683 return ret_eagain;
684
685 ret = cherokee_post_walk_finished (&conn->post);
686 switch (ret) {
687 case ret_ok:
688 break;
689 case ret_error:
690 return ret_error;
691 case ret_eagain:
692 hdl->post_phase = fcgi_post_read;
693 return ret_eagain;
694 default:
695 RET_UNKNOWN(ret);
696 return ret_error;
697 }
698
699 TRACE (ENTRIES, "Post %s\n", "finished");
700 return ret_ok;
701
702 default:
703 SHOULDNT_HAPPEN;
704 }
705
706 return ret_error;
707 }
708
709
710 ret_t
711 cherokee_handler_fcgi_init (cherokee_handler_fcgi_t *hdl)
712 {
b830ce0 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@3264 5dc97367-9…
alobbs authored
713 ret_t ret;
714 cherokee_connection_t *conn = HANDLER_CONN(hdl);
715 cherokee_handler_cgi_base_props_t *props = HANDLER_CGI_BASE_PROPS(hdl);
f11857f @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@600 5dc97367-97…
alobbs authored
716
3509796 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@282 5dc97367-97…
alobbs authored
717 switch (HDL_CGI_BASE(hdl)->init_phase) {
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
718 case hcgi_phase_build_headers:
a18b345 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1708 5dc97367-9…
alobbs authored
719 TRACE (ENTRIES, "Init: %s\n", "begins");
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
720
721 /* Prepare Post
722 */
723 if (! cherokee_post_is_empty (&conn->post)) {
724 cherokee_post_walk_reset (&conn->post);
725 cherokee_post_get_len (&conn->post, &hdl->post_len);
726 }
727
728 /* Extracts PATH_INFO and filename from request uri
729 */
b830ce0 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@3264 5dc97367-9…
alobbs authored
730 ret = cherokee_handler_cgi_base_extract_path (HDL_CGI_BASE(hdl), props->check_file);
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
731 if (unlikely (ret < ret_ok)) return ret;
732
733 /* Build the headers
734 */
735 ret = build_header (hdl, &hdl->write_buffer);
736 if (unlikely (ret != ret_ok)) return ret;
737
a18b345 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1708 5dc97367-9…
alobbs authored
738 HDL_CGI_BASE(hdl)->init_phase = hcgi_phase_connect;
739
740 case hcgi_phase_connect:
741 TRACE (ENTRIES, "Init: %s\n", "connect");
742
743 /* Connect
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
744 */
745 ret = connect_to_server (hdl);
16f53b0 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1658 5dc97367-9…
alobbs authored
746 switch (ret) {
747 case ret_ok:
748 break;
a18b345 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1708 5dc97367-9…
alobbs authored
749 case ret_eagain:
750 return ret_eagain;
16f53b0 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1658 5dc97367-9…
alobbs authored
751 case ret_deny:
752 conn->error_code = http_gateway_timeout;
753 return ret_error;
754 default:
2e0ea0e @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@430 5dc97367-97…
alobbs authored
755 conn->error_code = http_service_unavailable;
16f53b0 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1658 5dc97367-9…
alobbs authored
756 return ret_error;
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
757 }
758
3509796 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@282 5dc97367-97…
alobbs authored
759 HDL_CGI_BASE(hdl)->init_phase = hcgi_phase_send_headers;
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
760
761 case hcgi_phase_send_headers:
a18b345 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1708 5dc97367-9…
alobbs authored
762 TRACE (ENTRIES, "Init: %s\n", "send_headers");
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
763
764 /* Send the header
765 */
766 ret = do_send (hdl, &hdl->write_buffer);
81679d0 handler_*.c, space / code style cleanups
ADF authored
767 if (ret != ret_ok)
768 return ret;
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
769
3509796 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@282 5dc97367-97…
alobbs authored
770 HDL_CGI_BASE(hdl)->init_phase = hcgi_phase_send_post;
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
771
772 case hcgi_phase_send_post:
773 /* Send the Post
774 */
775 if (hdl->post_len > 0) {
776 return send_post (hdl, &hdl->write_buffer);
f11857f @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@600 5dc97367-97…
alobbs authored
777 } else {
778 ret = send_no_post (hdl, &hdl->write_buffer);
81679d0 handler_*.c, space / code style cleanups
ADF authored
779 if (ret != ret_ok)
780 return ret;
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
781 }
782 break;
783 }
784
785 TRACE (ENTRIES, "Init %s\n", "finishes");
786
787 cherokee_buffer_clean (&hdl->write_buffer);
788 return ret_ok;
789 }
790
Something went wrong with that request. Please try again.