Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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