Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 793 lines (627 sloc) 19.954 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;
302 n->spawned = 0;
ba212a4 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@467 5dc97367-97…
alobbs authored
303
a18b345 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1708 5dc97367-9…
alobbs authored
304 cherokee_socket_init (&n->socket);
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
305 cherokee_buffer_init (&n->write_buffer);
306 cherokee_buffer_ensure_size (&n->write_buffer, 512);
307
308 /* Return the object
309 */
310 *hdl = HANDLER(n);
311 return ret_ok;
312 }
313
314
315 ret_t
316 cherokee_handler_fcgi_free (cherokee_handler_fcgi_t *hdl)
317 {
483759d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@466 5dc97367-97…
alobbs authored
318 TRACE (ENTRIES, "fcgi handler free: %p\n", hdl);
319
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
320 cherokee_socket_close (&hdl->socket);
321 cherokee_socket_mrproper (&hdl->socket);
322
323 cherokee_buffer_mrproper (&hdl->write_buffer);
324
3509796 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@282 5dc97367-97…
alobbs authored
325 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
326 }
327
328
329 static void
330 fcgi_build_header (FCGI_Header *hdr, cuchar_t type, cushort_t request_id, cuint_t content_length, cuchar_t padding)
331 {
81679d0 handler_*.c, space / code style cleanups
ADF authored
332 hdr->version = FCGI_VERSION_1;
333 hdr->type = type;
334 hdr->requestIdB0 = (cuchar_t) request_id;
335 hdr->requestIdB1 = (cuchar_t) (request_id >> 8) & 0xff;
336 hdr->contentLengthB0 = (cuchar_t) (content_length % 256);
337 hdr->contentLengthB1 = (cuchar_t) (content_length / 256);
338 hdr->paddingLength = padding;
339 hdr->reserved = 0;
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
340 }
341
342 static void
343 fcgi_build_request_body (FCGI_BeginRequestRecord *request)
344 {
81679d0 handler_*.c, space / code style cleanups
ADF authored
345 request->body.roleB0 = FCGI_RESPONDER;
346 request->body.roleB1 = 0;
347 request->body.flags = 0;
348 request->body.reserved[0] = 0;
349 request->body.reserved[1] = 0;
350 request->body.reserved[2] = 0;
351 request->body.reserved[3] = 0;
352 request->body.reserved[4] = 0;
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
353 }
354
355 static void
356 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
357 const char *key, int key_len,
358 const char *val, int val_len)
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
359 {
81679d0 handler_*.c, space / code style cleanups
ADF authored
360 int len;
361 FCGI_BeginRequestRecord request;
3509796 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@282 5dc97367-97…
alobbs authored
362 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
363 cherokee_buffer_t *buf = &hdl->write_buffer;
364
0a136b0 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@3233 5dc97367-9…
alobbs authored
365 #ifdef TRACE_ENABLED
366 cherokee_buffer_t *tmp = &HANDLER_THREAD(cgi_base)->tmp_buf2;
367
368 cherokee_buffer_clean (tmp);
369 cherokee_buffer_add (tmp, key, key_len);
370 cherokee_buffer_add_str (tmp, " = \"");
371 cherokee_buffer_add (tmp, val, val_len);
372 cherokee_buffer_add_str (tmp, "\"\n");
373
374 TRACE (ENTRIES, "%s", tmp->buf);
375 #endif
376
81679d0 handler_*.c, space / code style cleanups
ADF authored
377 len = key_len + val_len;
378 len += key_len > 127 ? 4 : 1;
379 len += val_len > 127 ? 4 : 1;
380
381 fcgi_build_header (&request.header, FCGI_PARAMS, 1, len, 0);
382
383 cherokee_buffer_ensure_size (buf, buf->len + sizeof(FCGI_Header) + key_len + val_len);
384 cherokee_buffer_add (buf, (void *)&request.header, sizeof(FCGI_Header));
385
386 if (key_len <= 127) {
387 buf->buf[buf->len++] = key_len;
388 } else {
389 buf->buf[buf->len++] = ((key_len >> 24) & 0xff) | 0x80;
390 buf->buf[buf->len++] = (key_len >> 16) & 0xff;
391 buf->buf[buf->len++] = (key_len >> 8) & 0xff;
392 buf->buf[buf->len++] = (key_len >> 0) & 0xff;
393 }
394
395 if (val_len <= 127) {
396 buf->buf[buf->len++] = val_len;
397 } else {
398 buf->buf[buf->len++] = ((val_len >> 24) & 0xff) | 0x80;
399 buf->buf[buf->len++] = (val_len >> 16) & 0xff;
400 buf->buf[buf->len++] = (val_len >> 8) & 0xff;
401 buf->buf[buf->len++] = (val_len >> 0) & 0xff;
402 }
403
404 cherokee_buffer_add (buf, key, key_len);
405 cherokee_buffer_add (buf, val, val_len);
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
406 }
407
408
409 static ret_t
410 add_extra_fcgi_env (cherokee_handler_fcgi_t *hdl, cuint_t *last_header_offset)
411 {
8cdea13 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2969 5dc97367-9…
alobbs authored
412 off_t post_len = 0;
3509796 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@282 5dc97367-97…
alobbs authored
413 cherokee_handler_cgi_base_t *cgi_base = HDL_CGI_BASE(hdl);
81679d0 handler_*.c, space / code style cleanups
ADF authored
414 cherokee_buffer_t buffer = CHEROKEE_BUF_INIT;
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
415 cherokee_connection_t *conn = HANDLER_CONN(hdl);
416
417 /* CONTENT_LENGTH
418 */
8cdea13 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2969 5dc97367-9…
alobbs authored
419 if (http_method_with_input (conn->header.method)) {
420 cherokee_post_get_len (&conn->post, &post_len);
421
422 cherokee_buffer_add_ullong10 (&buffer, post_len);
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
423 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
424 }
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
425
426 /* Add PATH_TRANSLATED only it there is pathinfo
427 */
428 #if 0
429 if (! cherokee_buffer_is_empty (&conn->pathinfo)) {
430 cherokee_buffer_add_buffer (&buffer, &conn->local_directory);
431 cherokee_buffer_add_buffer (&buffer, &conn->pathinfo);
432
433 set_env (cgi_base, "PATH_TRANSLATED", buffer.buf, buffer.len);
434 TRACE (ENTRIES, "PATH_TRANSLATED '%s'\n", cgi_base->executable.buf);
435 }
436 #endif
437
438 /* The last one
439 */
440 *last_header_offset = hdl->write_buffer.len;
441
6b3a530 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2959 5dc97367-9…
alobbs authored
442 set_env (cgi_base, "SCRIPT_FILENAME",
443 cgi_base->executable.buf,
444 cgi_base->executable.len);
445
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
446 TRACE (ENTRIES, "SCRIPT_FILENAME '%s'\n", cgi_base->executable.buf);
447
448 cherokee_buffer_mrproper (&buffer);
449 return ret_ok;
450 }
451
452
453 static void
454 fixup_padding (cherokee_buffer_t *buf, cuint_t last_header_offset)
455 {
81679d0 handler_*.c, space / code style cleanups
ADF authored
456 cuint_t rest;
457 cuint_t pad;
458 static char padding[8] = {0, 0, 0, 0, 0, 0, 0, 0};
459 FCGI_Header *last_header;
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
460
81679d0 handler_*.c, space / code style cleanups
ADF authored
461 if (buf->len <= 0)
462 return;
463 last_header = (FCGI_Header *) (buf->buf + last_header_offset);
464 rest = buf->len % 8;
465 pad = 8 - rest;
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
466
81679d0 handler_*.c, space / code style cleanups
ADF authored
467 if (rest == 0)
468 return;
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
469
81679d0 handler_*.c, space / code style cleanups
ADF authored
470 last_header->paddingLength = pad;
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
471
81679d0 handler_*.c, space / code style cleanups
ADF authored
472 cherokee_buffer_ensure_size (buf, buf->len + pad);
473 cherokee_buffer_add (buf, padding, pad);
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
474 }
475
476 static void
477 add_empty_packet (cherokee_handler_fcgi_t *hdl, cuint_t type)
478 {
81679d0 handler_*.c, space / code style cleanups
ADF authored
479 FCGI_BeginRequestRecord request;
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
480
81679d0 handler_*.c, space / code style cleanups
ADF authored
481 fcgi_build_header (&request.header, type, 1, 0, 0);
482 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
483
81679d0 handler_*.c, space / code style cleanups
ADF authored
484 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
485 }
486
487
488 static ret_t
489 build_header (cherokee_handler_fcgi_t *hdl, cherokee_buffer_t *buffer)
490 {
491 FCGI_BeginRequestRecord request;
81679d0 handler_*.c, space / code style cleanups
ADF authored
492 cuint_t last_header_offset;
2e0ea0e @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@430 5dc97367-97…
alobbs authored
493 cherokee_connection_t *conn = HANDLER_CONN(hdl);
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
494
495 cherokee_buffer_clean (buffer);
496
497 /* FCGI_BEGIN_REQUEST
498 */
81679d0 handler_*.c, space / code style cleanups
ADF authored
499 fcgi_build_header (&request.header, FCGI_BEGIN_REQUEST, 1, sizeof(request.body), 0);
500 fcgi_build_request_body (&request);
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
501
502 cherokee_buffer_add (buffer, (void *)&request, sizeof(FCGI_BeginRequestRecord));
81679d0 handler_*.c, space / code style cleanups
ADF authored
503 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
504
505 /* Add enviroment variables
506 */
3509796 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@282 5dc97367-97…
alobbs authored
507 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
508
509 add_extra_fcgi_env (hdl, &last_header_offset);
81679d0 handler_*.c, space / code style cleanups
ADF authored
510 fixup_padding (buffer, last_header_offset);
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
511
81679d0 handler_*.c, space / code style cleanups
ADF authored
512 /* There are no more parameters
513 */
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
514 add_empty_packet (hdl, FCGI_PARAMS);
515
81679d0 handler_*.c, space / code style cleanups
ADF authored
516 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
517 return ret_ok;
518 }
519
520
521 static ret_t
522 connect_to_server (cherokee_handler_fcgi_t *hdl)
523 {
3509796 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@282 5dc97367-97…
alobbs authored
524 ret_t ret;
5695e23 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1849 5dc97367-9…
alobbs authored
525 cherokee_connection_t *conn = HANDLER_CONN(hdl);
526 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
527
a18b345 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1708 5dc97367-9…
alobbs authored
528 /* Get a reference to the target host
529 */
530 if (hdl->src_ref == NULL) {
531 ret = cherokee_balancer_dispatch (props->balancer, conn, &hdl->src_ref);
532 if (ret != ret_ok)
533 return ret;
534 }
7b0e48a @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@387 5dc97367-97…
alobbs authored
535
a18b345 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1708 5dc97367-9…
alobbs authored
536 /* Try to connect
537 */
14efdd8 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2572 5dc97367-9…
alobbs authored
538 if (hdl->src_ref->type == source_host) {
539 ret = cherokee_source_connect_polling (hdl->src_ref, &hdl->socket, conn);
540 if ((ret == ret_deny) || (ret == ret_error))
541 {
542 cherokee_balancer_report_fail (props->balancer, conn, hdl->src_ref);
543 }
544 } else {
545 ret = cherokee_source_interpreter_connect_polling (SOURCE_INT(hdl->src_ref),
546 &hdl->socket, conn,
547 &hdl->spawned);
548 }
45ead25 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@428 5dc97367-97…
alobbs authored
549
14efdd8 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2572 5dc97367-9…
alobbs authored
550 return ret;
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
551 }
552
553
554 static ret_t
555 do_send (cherokee_handler_fcgi_t *hdl, cherokee_buffer_t *buffer)
556 {
2e0ea0e @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@430 5dc97367-97…
alobbs authored
557 ret_t ret;
b0dd10b @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1398 5dc97367-9…
alobbs authored
558 size_t written = 0;
2e0ea0e @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@430 5dc97367-97…
alobbs authored
559 cherokee_connection_t *conn = HANDLER_CONN(hdl);
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
560
0932395 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@656 5dc97367-97…
alobbs authored
561 ret = cherokee_socket_bufwrite (&hdl->socket, buffer, &written);
ba212a4 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@467 5dc97367-97…
alobbs authored
562 switch (ret) {
563 case ret_ok:
3cbd17a @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@475 5dc97367-97…
alobbs authored
564 break;
ba212a4 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@467 5dc97367-97…
alobbs authored
565 case ret_eagain:
b69d2e0 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@476 5dc97367-97…
alobbs authored
566 if (written > 0)
567 break;
ba212a4 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@467 5dc97367-97…
alobbs authored
568 return ret_eagain;
569 default:
2e0ea0e @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@430 5dc97367-97…
alobbs authored
570 conn->error_code = http_bad_gateway;
ba212a4 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@467 5dc97367-97…
alobbs authored
571 return ret_error;
2e0ea0e @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@430 5dc97367-97…
alobbs authored
572 }
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
573
574 cherokee_buffer_move_to_begin (buffer, written);
575
576 TRACE (ENTRIES, "sent remaining=%d\n", buffer->len);
577
578 if (! cherokee_buffer_is_empty (buffer))
579 return ret_eagain;
580
581 return ret_ok;
582 }
583
584
585 static ret_t
f11857f @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@600 5dc97367-97…
alobbs authored
586 send_no_post (cherokee_handler_fcgi_t *hdl, cherokee_buffer_t *buf)
587 {
588 switch (hdl->post_phase) {
589 case fcgi_post_init:
590 add_empty_packet (hdl, FCGI_STDIN);
591 hdl->post_phase = fcgi_post_write;
592
593 case fcgi_post_write:
594 return do_send (hdl, buf);
595
596 default:
597 SHOULDNT_HAPPEN;
598 }
599 return ret_error;
600 }
601
602
603 static ret_t
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
604 send_post (cherokee_handler_fcgi_t *hdl, cherokee_buffer_t *buf)
605 {
606 ret_t ret;
607 cherokee_connection_t *conn = HANDLER_CONN(hdl);
608 static FCGI_Header empty_header = {0,0,0,0,0,0,0,0};
609
610 switch (hdl->post_phase) {
611 case fcgi_post_init:
612 TRACE (ENTRIES, "Post %s\n", "init");
613
614 /* Init the POST storing object
615 */
616 cherokee_post_walk_reset (&conn->post);
617 cherokee_post_get_len (&conn->post, &hdl->post_len);
618
619 if (hdl->post_len <= 0)
620 return ret_ok;
621
622 hdl->post_phase = fcgi_post_read;
623
624 case fcgi_post_read:
625 TRACE (ENTRIES, "Post %s\n", "read");
626
627 /* Add space for the header, it'll filled out later on..
628 */
629 if (cherokee_buffer_is_empty (buf)) {
0f3a68f @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@625 5dc97367-97…
alobbs authored
630 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
631 }
632
633 /* Take a chunck of post
634 */
635 ret = cherokee_post_walk_read (&conn->post, buf, POST_PACKAGE_LEN);
636 switch (ret) {
637 case ret_ok:
638 case ret_eagain:
639 break;
640 case ret_error:
641 return ret;
642 default:
643 RET_UNKNOWN(ret);
644 return ret_error;
645 }
646
647 TRACE (ENTRIES, "Post buffer.len %d\n", buf->len);
648
649 /* Complete the header
650 */
651 if (buf->len > sizeof(FCGI_Header)) {
652 fcgi_build_header ((FCGI_Header *)buf->buf, FCGI_STDIN, 1,
653 buf->len - sizeof(FCGI_Header), 0);
654 }
655
656 /* Close STDIN if it was the last chunck
657 */
658 ret = cherokee_post_walk_finished (&conn->post);
659 if (ret == ret_ok) {
660 add_empty_packet (hdl, FCGI_STDIN);
661 }
662
663 hdl->post_phase = fcgi_post_write;
664
665 case fcgi_post_write:
666 TRACE (ENTRIES, "Post write, buf.len=%d (header len %d)\n", buf->len, sizeof(FCGI_Header));
667
668 if (! cherokee_buffer_is_empty (buf)) {
669 ret = do_send (hdl, buf);
670 switch (ret) {
671 case ret_ok:
672 break;
673 case ret_eagain:
674 return ret_eagain;
675 case ret_eof:
676 case ret_error:
677 return ret_error;
678 default:
679 RET_UNKNOWN(ret);
680 return ret_error;
681 }
682 }
683
684 if (! cherokee_buffer_is_empty (buf))
685 return ret_eagain;
686
687 ret = cherokee_post_walk_finished (&conn->post);
688 switch (ret) {
689 case ret_ok:
690 break;
691 case ret_error:
692 return ret_error;
693 case ret_eagain:
694 hdl->post_phase = fcgi_post_read;
695 return ret_eagain;
696 default:
697 RET_UNKNOWN(ret);
698 return ret_error;
699 }
700
701 TRACE (ENTRIES, "Post %s\n", "finished");
702 return ret_ok;
703
704 default:
705 SHOULDNT_HAPPEN;
706 }
707
708 return ret_error;
709 }
710
711
712 ret_t
713 cherokee_handler_fcgi_init (cherokee_handler_fcgi_t *hdl)
714 {
b830ce0 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@3264 5dc97367-9…
alobbs authored
715 ret_t ret;
716 cherokee_connection_t *conn = HANDLER_CONN(hdl);
717 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
718
3509796 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@282 5dc97367-97…
alobbs authored
719 switch (HDL_CGI_BASE(hdl)->init_phase) {
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
720 case hcgi_phase_build_headers:
a18b345 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1708 5dc97367-9…
alobbs authored
721 TRACE (ENTRIES, "Init: %s\n", "begins");
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
722
723 /* Prepare Post
724 */
725 if (! cherokee_post_is_empty (&conn->post)) {
726 cherokee_post_walk_reset (&conn->post);
727 cherokee_post_get_len (&conn->post, &hdl->post_len);
728 }
729
730 /* Extracts PATH_INFO and filename from request uri
731 */
b830ce0 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@3264 5dc97367-9…
alobbs authored
732 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
733 if (unlikely (ret < ret_ok)) return ret;
734
735 /* Build the headers
736 */
737 ret = build_header (hdl, &hdl->write_buffer);
738 if (unlikely (ret != ret_ok)) return ret;
739
a18b345 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1708 5dc97367-9…
alobbs authored
740 HDL_CGI_BASE(hdl)->init_phase = hcgi_phase_connect;
741
742 case hcgi_phase_connect:
743 TRACE (ENTRIES, "Init: %s\n", "connect");
744
745 /* Connect
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
746 */
747 ret = connect_to_server (hdl);
16f53b0 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1658 5dc97367-9…
alobbs authored
748 switch (ret) {
749 case ret_ok:
750 break;
a18b345 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1708 5dc97367-9…
alobbs authored
751 case ret_eagain:
752 return ret_eagain;
16f53b0 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1658 5dc97367-9…
alobbs authored
753 case ret_deny:
754 conn->error_code = http_gateway_timeout;
755 return ret_error;
756 default:
2e0ea0e @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@430 5dc97367-97…
alobbs authored
757 conn->error_code = http_service_unavailable;
16f53b0 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1658 5dc97367-9…
alobbs authored
758 return ret_error;
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
759 }
760
3509796 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@282 5dc97367-97…
alobbs authored
761 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
762
763 case hcgi_phase_send_headers:
a18b345 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1708 5dc97367-9…
alobbs authored
764 TRACE (ENTRIES, "Init: %s\n", "send_headers");
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
765
766 /* Send the header
767 */
768 ret = do_send (hdl, &hdl->write_buffer);
81679d0 handler_*.c, space / code style cleanups
ADF authored
769 if (ret != ret_ok)
770 return ret;
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
771
3509796 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@282 5dc97367-97…
alobbs authored
772 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
773
774 case hcgi_phase_send_post:
775 /* Send the Post
776 */
777 if (hdl->post_len > 0) {
778 return send_post (hdl, &hdl->write_buffer);
f11857f @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@600 5dc97367-97…
alobbs authored
779 } else {
780 ret = send_no_post (hdl, &hdl->write_buffer);
81679d0 handler_*.c, space / code style cleanups
ADF authored
781 if (ret != ret_ok)
782 return ret;
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
783 }
784 break;
785 }
786
787 TRACE (ENTRIES, "Init %s\n", "finishes");
788
789 cherokee_buffer_clean (&hdl->write_buffer);
790 return ret_ok;
791 }
792
Something went wrong with that request. Please try again.