Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 759 lines (599 sloc) 19.386 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 *
920e20b Alvaro Lopez Ortega Happy new year!
alobbs authored
8 * Copyright (C) 2001-2011 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.
72f6444 Alvaro Lopez Ortega Clean up: Trims trailing spaces.
alobbs authored
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
72f6444 Alvaro Lopez Ortega Clean up: Trims trailing spaces.
alobbs authored
48 static void set_env_pair (cherokee_handler_cgi_base_t *cgi_base,
49 const char *key, int key_len,
1e47304 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@2701 5dc97367-97f1...
alobbs authored
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 {
1948025 Alvaro Lopez Ortega Removes some unused code in the FastCGI handler. It addresses bug
alobbs authored
62 FCGI_Header *header;
63 cuint_t len;
64 char *data;
65 cuint_t type;
66 cuint_t id;
67 cuint_t padding;
4a68bff git-svn-id: svn://cherokee-project.com/cherokee/trunk@2404 5dc97367-97f1...
taher authored
68
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
69 /* Is there enough information?
70 */
71 if (inbuf->len < sizeof(FCGI_Header))
72 return ret_ok;
73
74 /* At least there is a header
75 */
76 header = (FCGI_Header *)inbuf->buf;
77
78 if (header->version != 1) {
79 cherokee_buffer_print_debug (inbuf, -1);
165f0ad Alvaro Lopez Ortega Merges the 'newerrors' branch (r3613:HEAD). It implements a new
alobbs authored
80 LOG_ERROR_S (CHEROKEE_ERROR_HANDLER_FCGI_VERSION);
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
81 return ret_error;
82 }
72f6444 Alvaro Lopez Ortega Clean up: Trims trailing spaces.
alobbs authored
83
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
84 if (header->type != FCGI_STDERR &&
72f6444 Alvaro Lopez Ortega Clean up: Trims trailing spaces.
alobbs authored
85 header->type != FCGI_STDOUT &&
81679d0 handler_*.c, space / code style cleanups
ADF authored
86 header->type != FCGI_END_REQUEST) {
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
87 cherokee_buffer_print_debug (inbuf, -1);
165f0ad Alvaro Lopez Ortega Merges the 'newerrors' branch (r3613:HEAD). It implements a new
alobbs authored
88 LOG_ERROR_S (CHEROKEE_ERROR_HANDLER_FCGI_PARSING);
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
89 return ret_error;
90 }
72f6444 Alvaro Lopez Ortega Clean up: Trims trailing spaces.
alobbs authored
91
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
92 /* Read the header
93 */
94 type = header->type;
95 padding = header->paddingLength;
96 id = (header->requestIdB0 | (header->requestIdB1 << 8));
97 len = (header->contentLengthB0 | (header->contentLengthB1 << 8));
98 data = inbuf->buf + FCGI_HEADER_LEN;
99
b13f4bf Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@446 5dc97367-97f1-...
alobbs authored
100 /* 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
101
102 /* Is the package complete?
103 */
104 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
105 /* 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
106 return ret_ok;
107 }
108
109 /* It has received the full package content
110 */
111 switch (type) {
72f6444 Alvaro Lopez Ortega Clean up: Trims trailing spaces.
alobbs authored
112 case FCGI_STDERR:
b13f4bf Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@446 5dc97367-97f1-...
alobbs authored
113 /* 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
114
97945bf Alvaro Lopez Ortega Fixes bug #676. The server was crashing whenever PHP (via fastcgi)
alobbs authored
115 LOG_ERROR (CHEROKEE_ERROR_HANDLER_FCGI_STDERR, data);
116
117 /* Debug mode */
118 if (SOURCE_INT(hdl->src_ref)->debug) {
4a68bff git-svn-id: svn://cherokee-project.com/cherokee/trunk@2404 5dc97367-97f1...
taher authored
119 PRINT_MSG ("%.*s\n", len, data);
120 }
121
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
122 break;
123
124 case FCGI_STDOUT:
8b87f31 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@3199 5dc97367-97f1...
alobbs authored
125 /* 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
126 cherokee_buffer_add (outbuf, data, len);
127 break;
128
72f6444 Alvaro Lopez Ortega Clean up: Trims trailing spaces.
alobbs authored
129 case FCGI_END_REQUEST:
b13f4bf Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@446 5dc97367-97f1-...
alobbs authored
130 /* printf ("READ:END"); */
1948025 Alvaro Lopez Ortega Removes some unused code in the FastCGI handler. It addresses bug
alobbs authored
131 HDL_CGI_BASE(hdl)->got_eof = true;
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
132 break;
133
134 default:
135 SHOULDNT_HAPPEN;
136 }
137
138 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
139 /* 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
140 return ret_eagain;
141 }
142
143
144 static ret_t
145 process_buffer (cherokee_handler_fcgi_t *hdl, cherokee_buffer_t *inbuf, cherokee_buffer_t *outbuf)
146 {
147 ret_t ret;
72f6444 Alvaro Lopez Ortega Clean up: Trims trailing spaces.
alobbs authored
148
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
149 do {
150 ret = process_package (hdl, inbuf, outbuf);
151 } while (ret == ret_eagain);
152
153 if (ret == ret_ok) {
154 if (cherokee_buffer_is_empty (outbuf))
3509796 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@282 5dc97367-97f1-...
alobbs authored
155 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
156 }
157
158 return ret;
159 }
160
72f6444 Alvaro Lopez Ortega Clean up: Trims trailing spaces.
alobbs authored
161 static ret_t
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
162 read_from_fcgi (cherokee_handler_cgi_base_t *cgi, cherokee_buffer_t *buffer)
163 {
164 ret_t ret;
165 size_t read = 0;
3509796 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@282 5dc97367-97f1-...
alobbs authored
166 cherokee_handler_fcgi_t *fcgi = HDL_FCGI(cgi);
346b422 Antonio Pérez Applied the "new-events" branch, again... Hope this fix the tree once an...
skarcha authored
167 cherokee_connection_t *conn = HANDLER_CONN(cgi);
72f6444 Alvaro Lopez Ortega Clean up: Trims trailing spaces.
alobbs authored
168
0932395 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@656 5dc97367-97f1-...
alobbs authored
169 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
170
171 switch (ret) {
172 case ret_eagain:
346b422 Antonio Pérez Applied the "new-events" branch, again... Hope this fix the tree once an...
skarcha authored
173 conn->polling_aim.fd = fcgi->socket.socket;
174 conn->polling_aim.mode = poll_mode_read;
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
175 return ret_eagain;
176
177 case ret_ok:
178 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
179 TRACE (ENTRIES, "%d bytes read, buffer.len %d\n", read, buffer->len);
24f5c27 Alvaro Lopez Ortega Check thread_deactive_to_polling() returned value.
alobbs authored
180
181 if ((ret == ret_ok) && cgi->got_eof && (buffer->len > 0)) {
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
182 return ret_eof_have_data;
24f5c27 Alvaro Lopez Ortega Check thread_deactive_to_polling() returned value.
alobbs authored
183 }
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
184 return ret;
185
186 case ret_eof:
187 case ret_error:
188 cgi->got_eof = true;
189 return ret;
190
191 default:
192 RET_UNKNOWN(ret);
193 }
194
195 SHOULDNT_HAPPEN;
2e0ea0e Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@430 5dc97367-97f1-...
alobbs authored
196 return ret_error;
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
197 }
198
199
72f6444 Alvaro Lopez Ortega Clean up: Trims trailing spaces.
alobbs authored
200 static ret_t
be04810 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@283 5dc97367-97f1-...
alobbs authored
201 props_free (cherokee_handler_fcgi_props_t *props)
202 {
72f6444 Alvaro Lopez Ortega Clean up: Trims trailing spaces.
alobbs authored
203 if (props->balancer != NULL)
7b0e48a Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@387 5dc97367-97f1-...
alobbs authored
204 cherokee_balancer_free (props->balancer);
72f6444 Alvaro Lopez Ortega Clean up: Trims trailing spaces.
alobbs authored
205
623deda Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@294 5dc97367-97f1-...
alobbs authored
206 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
207 }
208
209
72f6444 Alvaro Lopez Ortega Clean up: Trims trailing spaces.
alobbs authored
210 ret_t
211 cherokee_handler_fcgi_configure (cherokee_config_node_t *conf,
8b87f31 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@3199 5dc97367-97f1...
alobbs authored
212 cherokee_server_t *srv,
213 cherokee_module_props_t **_props)
b6c69ad Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@269 5dc97367-97f1-...
alobbs authored
214 {
3509796 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@282 5dc97367-97f1-...
alobbs authored
215 ret_t ret;
ee8023f Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@384 5dc97367-97f1-...
alobbs authored
216 cherokee_list_t *i;
3509796 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@282 5dc97367-97f1-...
alobbs authored
217 cherokee_handler_fcgi_props_t *props;
b6c69ad Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@269 5dc97367-97f1-...
alobbs authored
218
3509796 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@282 5dc97367-97f1-...
alobbs authored
219 /* Instance a new property object
220 */
221 if (*_props == NULL) {
222 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
223
b69d2e0 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@476 5dc97367-97f1-...
alobbs authored
224 cherokee_handler_cgi_base_props_init_base (PROP_CGI_BASE(n),
225 MODULE_PROPS_FREE(props_free));
226
227 INIT_LIST_HEAD (&n->server_list);
7b0e48a Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@387 5dc97367-97f1-...
alobbs authored
228 n->balancer = NULL;
229
230 *_props = MODULE_PROPS(n);
3509796 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@282 5dc97367-97f1-...
alobbs authored
231 }
232
72f6444 Alvaro Lopez Ortega Clean up: Trims trailing spaces.
alobbs authored
233 props = PROP_FCGI(*_props);
3509796 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@282 5dc97367-97f1-...
alobbs authored
234
235 /* Parse the configuration tree
236 */
b6c69ad Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@269 5dc97367-97f1-...
alobbs authored
237 cherokee_config_node_foreach (i, conf) {
238 cherokee_config_node_t *subconf = CONFIG_NODE(i);
239
7b0e48a Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@387 5dc97367-97f1-...
alobbs authored
240 if (equal_buf_str (&subconf->key, "balancer")) {
72f6444 Alvaro Lopez Ortega Clean up: Trims trailing spaces.
alobbs authored
241 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
242 if (ret != ret_ok) return ret;
243 }
244 }
72f6444 Alvaro Lopez Ortega Clean up: Trims trailing spaces.
alobbs authored
245
7b0e48a Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@387 5dc97367-97f1-...
alobbs authored
246 /* Init base class
247 */
248 ret = cherokee_handler_cgi_base_configure (conf, srv, _props);
249 if (ret != ret_ok) return ret;
250
251 /* Final checks
252 */
253 if (props->balancer == NULL) {
165f0ad Alvaro Lopez Ortega Merges the 'newerrors' branch (r3613:HEAD). It implements a new
alobbs authored
254 LOG_CRITICAL_S (CHEROKEE_ERROR_HANDLER_FCGI_BALANCER);
7b0e48a Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@387 5dc97367-97f1-...
alobbs authored
255 return ret_error;
256 }
257
258 return ret_ok;
b6c69ad Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@269 5dc97367-97f1-...
alobbs authored
259 }
260
261
72f6444 Alvaro Lopez Ortega Clean up: Trims trailing spaces.
alobbs authored
262 ret_t
7b0e48a Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@387 5dc97367-97f1-...
alobbs authored
263 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
264 {
265 CHEROKEE_NEW_STRUCT (n, handler_fcgi);
266
267 /* Init the base class
268 */
72f6444 Alvaro Lopez Ortega Clean up: Trims trailing spaces.
alobbs authored
269 cherokee_handler_cgi_base_init (HDL_CGI_BASE(n), cnt, PLUGIN_INFO_HANDLER_PTR(fcgi),
b69d2e0 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@476 5dc97367-97f1-...
alobbs authored
270 HANDLER_PROPS(props), set_env_pair, read_from_fcgi);
72f6444 Alvaro Lopez Ortega Clean up: Trims trailing spaces.
alobbs authored
271
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
272 /* Virtual methods
273 */
274 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
275 MODULE(n)->free = (module_func_free_t) cherokee_handler_fcgi_free;
475ecb2 Alvaro Lopez Ortega The POST management code has been rewritten from scratch. The new
alobbs authored
276 HANDLER(n)->read_post = (handler_func_read_post_t) cherokee_handler_fcgi_read_post;
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
277
278 /* Virtual methods: implemented by handler_cgi_base
279 */
280 HANDLER(n)->add_headers = (handler_func_add_headers_t) cherokee_handler_cgi_base_add_headers;
475ecb2 Alvaro Lopez Ortega The POST management code has been rewritten from scratch. The new
alobbs authored
281 HANDLER(n)->step = (handler_func_step_t) cherokee_handler_cgi_base_step;
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
282
283 /* Properties
284 */
475ecb2 Alvaro Lopez Ortega The POST management code has been rewritten from scratch. The new
alobbs authored
285 n->post_phase = fcgi_post_phase_read;
286 n->src_ref = NULL;
ba212a4 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@467 5dc97367-97f1-...
alobbs authored
287
a18b345 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@1708 5dc97367-97f1...
alobbs authored
288 cherokee_socket_init (&n->socket);
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
289 cherokee_buffer_init (&n->write_buffer);
290 cherokee_buffer_ensure_size (&n->write_buffer, 512);
291
292 /* Return the object
293 */
294 *hdl = HANDLER(n);
72f6444 Alvaro Lopez Ortega Clean up: Trims trailing spaces.
alobbs authored
295 return ret_ok;
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
296 }
297
298
72f6444 Alvaro Lopez Ortega Clean up: Trims trailing spaces.
alobbs authored
299 ret_t
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
300 cherokee_handler_fcgi_free (cherokee_handler_fcgi_t *hdl)
301 {
483759d Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@466 5dc97367-97f1-...
alobbs authored
302 TRACE (ENTRIES, "fcgi handler free: %p\n", hdl);
303
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
304 cherokee_socket_close (&hdl->socket);
305 cherokee_socket_mrproper (&hdl->socket);
306
307 cherokee_buffer_mrproper (&hdl->write_buffer);
308
3509796 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@282 5dc97367-97f1-...
alobbs authored
309 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
310 }
311
312
313 static void
314 fcgi_build_header (FCGI_Header *hdr, cuchar_t type, cushort_t request_id, cuint_t content_length, cuchar_t padding)
315 {
81679d0 handler_*.c, space / code style cleanups
ADF authored
316 hdr->version = FCGI_VERSION_1;
317 hdr->type = type;
318 hdr->requestIdB0 = (cuchar_t) request_id;
319 hdr->requestIdB1 = (cuchar_t) (request_id >> 8) & 0xff;
320 hdr->contentLengthB0 = (cuchar_t) (content_length % 256);
321 hdr->contentLengthB1 = (cuchar_t) (content_length / 256);
322 hdr->paddingLength = padding;
323 hdr->reserved = 0;
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
324 }
325
326 static void
327 fcgi_build_request_body (FCGI_BeginRequestRecord *request)
328 {
81679d0 handler_*.c, space / code style cleanups
ADF authored
329 request->body.roleB0 = FCGI_RESPONDER;
330 request->body.roleB1 = 0;
331 request->body.flags = 0;
332 request->body.reserved[0] = 0;
333 request->body.reserved[1] = 0;
334 request->body.reserved[2] = 0;
335 request->body.reserved[3] = 0;
336 request->body.reserved[4] = 0;
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
337 }
338
72f6444 Alvaro Lopez Ortega Clean up: Trims trailing spaces.
alobbs authored
339 static void
340 set_env_pair (cherokee_handler_cgi_base_t *cgi_base,
341 const char *key, int key_len,
1e47304 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@2701 5dc97367-97f1...
alobbs authored
342 const char *val, int val_len)
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
343 {
81679d0 handler_*.c, space / code style cleanups
ADF authored
344 int len;
345 FCGI_BeginRequestRecord request;
72f6444 Alvaro Lopez Ortega Clean up: Trims trailing spaces.
alobbs authored
346 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
347 cherokee_buffer_t *buf = &hdl->write_buffer;
348
0a136b0 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@3233 5dc97367-97f1...
alobbs authored
349 #ifdef TRACE_ENABLED
350 cherokee_buffer_t *tmp = &HANDLER_THREAD(cgi_base)->tmp_buf2;
351
352 cherokee_buffer_clean (tmp);
353 cherokee_buffer_add (tmp, key, key_len);
354 cherokee_buffer_add_str (tmp, " = \"");
355 cherokee_buffer_add (tmp, val, val_len);
356 cherokee_buffer_add_str (tmp, "\"\n");
357
358 TRACE (ENTRIES, "%s", tmp->buf);
359 #endif
360
81679d0 handler_*.c, space / code style cleanups
ADF authored
361 len = key_len + val_len;
362 len += key_len > 127 ? 4 : 1;
363 len += val_len > 127 ? 4 : 1;
364
365 fcgi_build_header (&request.header, FCGI_PARAMS, 1, len, 0);
366
367 cherokee_buffer_ensure_size (buf, buf->len + sizeof(FCGI_Header) + key_len + val_len);
368 cherokee_buffer_add (buf, (void *)&request.header, sizeof(FCGI_Header));
369
370 if (key_len <= 127) {
371 buf->buf[buf->len++] = key_len;
372 } else {
373 buf->buf[buf->len++] = ((key_len >> 24) & 0xff) | 0x80;
374 buf->buf[buf->len++] = (key_len >> 16) & 0xff;
375 buf->buf[buf->len++] = (key_len >> 8) & 0xff;
376 buf->buf[buf->len++] = (key_len >> 0) & 0xff;
377 }
378
379 if (val_len <= 127) {
380 buf->buf[buf->len++] = val_len;
381 } else {
382 buf->buf[buf->len++] = ((val_len >> 24) & 0xff) | 0x80;
383 buf->buf[buf->len++] = (val_len >> 16) & 0xff;
384 buf->buf[buf->len++] = (val_len >> 8) & 0xff;
385 buf->buf[buf->len++] = (val_len >> 0) & 0xff;
386 }
387
388 cherokee_buffer_add (buf, key, key_len);
389 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
390 }
391
392
393 static ret_t
394 add_extra_fcgi_env (cherokee_handler_fcgi_t *hdl, cuint_t *last_header_offset)
395 {
aecd7fd Alvaro Lopez Ortega Re-implements (extends, actually) SCRIPT_FILENAME.
alobbs authored
396 cherokee_handler_cgi_base_t *cgi_base = HDL_CGI_BASE(hdl);
397 cherokee_buffer_t buffer = CHEROKEE_BUF_INIT;
398 cherokee_connection_t *conn = HANDLER_CONN(hdl);
399 cherokee_handler_cgi_base_props_t *props = HANDLER_CGI_BASE_PROPS(hdl);
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
400
475ecb2 Alvaro Lopez Ortega The POST management code has been rewritten from scratch. The new
alobbs authored
401 /* POST management
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
402 */
8cdea13 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@2969 5dc97367-97f1...
alobbs authored
403 if (http_method_with_input (conn->header.method)) {
475ecb2 Alvaro Lopez Ortega The POST management code has been rewritten from scratch. The new
alobbs authored
404 if (conn->post.encoding == post_enc_regular) {
405 cherokee_buffer_add_ullong10 (&buffer, conn->post.len);
406 set_env (cgi_base, "CONTENT_LENGTH", buffer.buf, buffer.len);
407
408 } else if (conn->post.encoding == post_enc_chunked) {
409 TRACE (ENTRIES",post", "Setting Chunked Post: %s flag\n", "retransmit");
410 set_env (cgi_base, "CONTENT_TRANSFER_ENCODING", "chunked", 7);
411 conn->post.chunked.retransmit = true;
412 }
8cdea13 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@2969 5dc97367-97f1...
alobbs authored
413 }
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
414
aecd7fd Alvaro Lopez Ortega Re-implements (extends, actually) SCRIPT_FILENAME.
alobbs authored
415 /* MIND THIS: _Last_ entry
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
416 */
aecd7fd Alvaro Lopez Ortega Re-implements (extends, actually) SCRIPT_FILENAME.
alobbs authored
417 *last_header_offset = hdl->write_buffer.len;
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
418
419
aecd7fd Alvaro Lopez Ortega Re-implements (extends, actually) SCRIPT_FILENAME.
alobbs authored
420 /* SCRIPT_FILENAME = Virtual-to-physical mapping for SCRIPT_NAME.
421 *
422 * Example:
423 * http://host/folder/script.php/extra?a=b
424 * Document Root=/docroot
425 *
426 * SCRIPT_FILENAME = /docroot/script.php
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
427 */
aecd7fd Alvaro Lopez Ortega Re-implements (extends, actually) SCRIPT_FILENAME.
alobbs authored
428 if (cgi_base->executable.len > 0) {
429 set_env (cgi_base, "SCRIPT_FILENAME",
430 cgi_base->executable.buf,
431 cgi_base->executable.len);
432 } else {
433 cherokee_buffer_clean (&buffer);
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
434
aecd7fd Alvaro Lopez Ortega Re-implements (extends, actually) SCRIPT_FILENAME.
alobbs authored
435 if (props->check_file) {
436 cherokee_buffer_add_buffer (&buffer, &CONN_VSRV(conn)->root);
437 cherokee_buffer_add_buffer (&buffer, &conn->request);
438 } else {
439 cherokee_buffer_add_buffer (&buffer, &conn->request);
440 }
6b3a530 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@2959 5dc97367-97f1...
alobbs authored
441
aecd7fd Alvaro Lopez Ortega Re-implements (extends, actually) SCRIPT_FILENAME.
alobbs authored
442 set_env (cgi_base, "SCRIPT_FILENAME", buffer.buf, buffer.len);
443 }
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
444
445 cherokee_buffer_mrproper (&buffer);
446 return ret_ok;
447 }
448
449
450 static void
451 fixup_padding (cherokee_buffer_t *buf, cuint_t last_header_offset)
452 {
81679d0 handler_*.c, space / code style cleanups
ADF authored
453 cuint_t rest;
454 cuint_t pad;
455 static char padding[8] = {0, 0, 0, 0, 0, 0, 0, 0};
456 FCGI_Header *last_header;
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
457
81679d0 handler_*.c, space / code style cleanups
ADF authored
458 if (buf->len <= 0)
459 return;
460 last_header = (FCGI_Header *) (buf->buf + last_header_offset);
461 rest = buf->len % 8;
462 pad = 8 - rest;
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
463
72f6444 Alvaro Lopez Ortega Clean up: Trims trailing spaces.
alobbs authored
464 if (rest == 0)
81679d0 handler_*.c, space / code style cleanups
ADF authored
465 return;
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
466
81679d0 handler_*.c, space / code style cleanups
ADF authored
467 last_header->paddingLength = pad;
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
468
81679d0 handler_*.c, space / code style cleanups
ADF authored
469 cherokee_buffer_ensure_size (buf, buf->len + pad);
470 cherokee_buffer_add (buf, padding, pad);
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
471 }
472
473 static void
474 add_empty_packet (cherokee_handler_fcgi_t *hdl, cuint_t type)
475 {
81679d0 handler_*.c, space / code style cleanups
ADF authored
476 FCGI_BeginRequestRecord request;
72f6444 Alvaro Lopez Ortega Clean up: Trims trailing spaces.
alobbs authored
477
81679d0 handler_*.c, space / code style cleanups
ADF authored
478 fcgi_build_header (&request.header, type, 1, 0, 0);
479 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
480
81679d0 handler_*.c, space / code style cleanups
ADF authored
481 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
482 }
483
484
485 static ret_t
486 build_header (cherokee_handler_fcgi_t *hdl, cherokee_buffer_t *buffer)
487 {
488 FCGI_BeginRequestRecord request;
81679d0 handler_*.c, space / code style cleanups
ADF authored
489 cuint_t last_header_offset;
2e0ea0e Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@430 5dc97367-97f1-...
alobbs authored
490 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
491
492 cherokee_buffer_clean (buffer);
493
494 /* FCGI_BEGIN_REQUEST
72f6444 Alvaro Lopez Ortega Clean up: Trims trailing spaces.
alobbs authored
495 */
81679d0 handler_*.c, space / code style cleanups
ADF authored
496 fcgi_build_header (&request.header, FCGI_BEGIN_REQUEST, 1, sizeof(request.body), 0);
497 fcgi_build_request_body (&request);
72f6444 Alvaro Lopez Ortega Clean up: Trims trailing spaces.
alobbs authored
498
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
499 cherokee_buffer_add (buffer, (void *)&request, sizeof(FCGI_BeginRequestRecord));
81679d0 handler_*.c, space / code style cleanups
ADF authored
500 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
501
502 /* Add enviroment variables
503 */
3509796 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@282 5dc97367-97f1-...
alobbs authored
504 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
505
506 add_extra_fcgi_env (hdl, &last_header_offset);
81679d0 handler_*.c, space / code style cleanups
ADF authored
507 fixup_padding (buffer, last_header_offset);
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
508
81679d0 handler_*.c, space / code style cleanups
ADF authored
509 /* There are no more parameters
510 */
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
511 add_empty_packet (hdl, FCGI_PARAMS);
512
475ecb2 Alvaro Lopez Ortega The POST management code has been rewritten from scratch. The new
alobbs authored
513 /* No POST?
514 */
0aa97bb Samuel Cormier-Iijima Fix compatibility issue #11 when an empty POST request is sent to a flup...
sciyoshi authored
515 if ((! http_method_with_input (conn->header.method)) || (! conn->post.has_info) || (! conn->post.len)) {
475ecb2 Alvaro Lopez Ortega The POST management code has been rewritten from scratch. The new
alobbs authored
516 TRACE (ENTRIES",post", "Post: %s\n", "has no post");
517 add_empty_packet (hdl, FCGI_STDIN);
518 }
519
81679d0 handler_*.c, space / code style cleanups
ADF authored
520 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
521 return ret_ok;
522 }
523
524
72f6444 Alvaro Lopez Ortega Clean up: Trims trailing spaces.
alobbs authored
525 static ret_t
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
526 connect_to_server (cherokee_handler_fcgi_t *hdl)
527 {
3509796 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@282 5dc97367-97f1-...
alobbs authored
528 ret_t ret;
5695e23 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@1849 5dc97367-97f1...
alobbs authored
529 cherokee_connection_t *conn = HANDLER_CONN(hdl);
530 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
531
a18b345 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@1708 5dc97367-97f1...
alobbs authored
532 /* Get a reference to the target host
533 */
534 if (hdl->src_ref == NULL) {
535 ret = cherokee_balancer_dispatch (props->balancer, conn, &hdl->src_ref);
536 if (ret != ret_ok)
537 return ret;
538 }
7b0e48a Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@387 5dc97367-97f1-...
alobbs authored
539
a18b345 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@1708 5dc97367-97f1...
alobbs authored
540 /* Try to connect
541 */
14efdd8 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@2572 5dc97367-97f1...
alobbs authored
542 if (hdl->src_ref->type == source_host) {
72f6444 Alvaro Lopez Ortega Clean up: Trims trailing spaces.
alobbs authored
543 ret = cherokee_source_connect_polling (hdl->src_ref, &hdl->socket, conn);
14efdd8 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@2572 5dc97367-97f1...
alobbs authored
544 if ((ret == ret_deny) || (ret == ret_error))
545 {
546 cherokee_balancer_report_fail (props->balancer, conn, hdl->src_ref);
547 }
548 } else {
549 ret = cherokee_source_interpreter_connect_polling (SOURCE_INT(hdl->src_ref),
83990a0 Alvaro Lopez Ortega A fragment of the spawning mechanism has been rewritten. This new
alobbs authored
550 &hdl->socket, conn);
14efdd8 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@2572 5dc97367-97f1...
alobbs authored
551 }
45ead25 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@428 5dc97367-97f1-...
alobbs authored
552
14efdd8 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@2572 5dc97367-97f1...
alobbs authored
553 return ret;
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
554 }
555
556
72f6444 Alvaro Lopez Ortega Clean up: Trims trailing spaces.
alobbs authored
557 static ret_t
f9f8902 Alvaro Lopez Ortega Better timeout support while handling POSTs.
alobbs authored
558 do_send (cherokee_handler_fcgi_t *hdl,
559 cherokee_buffer_t *buffer)
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
560 {
2e0ea0e Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@430 5dc97367-97f1-...
alobbs authored
561 ret_t ret;
b0dd10b Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@1398 5dc97367-97f1...
alobbs authored
562 size_t written = 0;
2e0ea0e Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@430 5dc97367-97f1-...
alobbs authored
563 cherokee_connection_t *conn = HANDLER_CONN(hdl);
72f6444 Alvaro Lopez Ortega Clean up: Trims trailing spaces.
alobbs authored
564
0932395 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@656 5dc97367-97f1-...
alobbs authored
565 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
566 switch (ret) {
567 case ret_ok:
3cbd17a Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@475 5dc97367-97f1-...
alobbs authored
568 break;
ba212a4 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@467 5dc97367-97f1-...
alobbs authored
569 case ret_eagain:
b69d2e0 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@476 5dc97367-97f1-...
alobbs authored
570 if (written > 0)
571 break;
346b422 Antonio Pérez Applied the "new-events" branch, again... Hope this fix the tree once an...
skarcha authored
572
573 conn->polling_aim.fd = hdl->socket.socket;
574 conn->polling_aim.mode = poll_mode_write;
575
ba212a4 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@467 5dc97367-97f1-...
alobbs authored
576 return ret_eagain;
577 default:
2e0ea0e Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@430 5dc97367-97f1-...
alobbs authored
578 conn->error_code = http_bad_gateway;
ba212a4 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@467 5dc97367-97f1-...
alobbs authored
579 return ret_error;
2e0ea0e Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@430 5dc97367-97f1-...
alobbs authored
580 }
72f6444 Alvaro Lopez Ortega Clean up: Trims trailing spaces.
alobbs authored
581
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
582 cherokee_buffer_move_to_begin (buffer, written);
475ecb2 Alvaro Lopez Ortega The POST management code has been rewritten from scratch. The new
alobbs authored
583 TRACE (ENTRIES, "sent=%d, remaining=%d\n", written, buffer->len);
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
584
585 return ret_ok;
586 }
587
588
589 static ret_t
475ecb2 Alvaro Lopez Ortega The POST management code has been rewritten from scratch. The new
alobbs authored
590 send_post (cherokee_handler_fcgi_t *hdl,
591 cherokee_buffer_t *buf)
f11857f Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@600 5dc97367-97f1-...
alobbs authored
592 {
475ecb2 Alvaro Lopez Ortega The POST management code has been rewritten from scratch. The new
alobbs authored
593 ret_t ret;
6abecb3 Alvaro Lopez Ortega Minor coding style fix
alobbs authored
594 int prev_buf_len;
595 cherokee_connection_t *conn = HANDLER_CONN(hdl);
596 static FCGI_Header empty_header = {0,0,0,0,0,0,0,0};
72f6444 Alvaro Lopez Ortega Clean up: Trims trailing spaces.
alobbs authored
597
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
598 switch (hdl->post_phase) {
475ecb2 Alvaro Lopez Ortega The POST management code has been rewritten from scratch. The new
alobbs authored
599 case fcgi_post_phase_read:
600 TRACE (ENTRIES",post", "Post %s\n", "read");
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
601
602 /* Add space for the header, it'll filled out later on..
603 */
604 if (cherokee_buffer_is_empty (buf)) {
0f3a68f Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@625 5dc97367-97f1-...
alobbs authored
605 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
606 }
607
608 /* Take a chunck of post
609 */
475ecb2 Alvaro Lopez Ortega The POST management code has been rewritten from scratch. The new
alobbs authored
610 ret = cherokee_post_read (&conn->post, &conn->socket, buf);
611 if (ret != ret_ok) {
612 return ret;
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
613 }
614
475ecb2 Alvaro Lopez Ortega The POST management code has been rewritten from scratch. The new
alobbs authored
615 TRACE (ENTRIES",post", "Post buffer.len %d\n", buf->len);
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
616
61b5e98 Alvaro Lopez Ortega Fixes timeout management while handling POSTs
alobbs authored
617 /* Did something, increase timeout
618 */
619 cherokee_connection_update_timeout (conn);
620
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
621 /* Complete the header
622 */
623 if (buf->len > sizeof(FCGI_Header)) {
624 fcgi_build_header ((FCGI_Header *)buf->buf, FCGI_STDIN, 1,
625 buf->len - sizeof(FCGI_Header), 0);
626 }
627
628 /* Close STDIN if it was the last chunck
629 */
475ecb2 Alvaro Lopez Ortega The POST management code has been rewritten from scratch. The new
alobbs authored
630 if (cherokee_post_read_finished (&conn->post)) {
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
631 add_empty_packet (hdl, FCGI_STDIN);
632 }
633
475ecb2 Alvaro Lopez Ortega The POST management code has been rewritten from scratch. The new
alobbs authored
634 hdl->post_phase = fcgi_post_phase_write;
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
635
475ecb2 Alvaro Lopez Ortega The POST management code has been rewritten from scratch. The new
alobbs authored
636 case fcgi_post_phase_write:
637 TRACE (ENTRIES",post", "Post write, buf.len=%d (header len %d)\n", buf->len, sizeof(FCGI_Header));
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
638
639 if (! cherokee_buffer_is_empty (buf)) {
6abecb3 Alvaro Lopez Ortega Minor coding style fix
alobbs authored
640 prev_buf_len = buf->len;
616bb65 Alvaro Lopez Ortega Fixes a bug in the POST support.
alobbs authored
641
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
642 ret = do_send (hdl, buf);
643 switch (ret) {
644 case ret_ok:
616bb65 Alvaro Lopez Ortega Fixes a bug in the POST support.
alobbs authored
645 /* Did something, increase timeout
646 */
6abecb3 Alvaro Lopez Ortega Minor coding style fix
alobbs authored
647 if (buf->len < prev_buf_len) {
616bb65 Alvaro Lopez Ortega Fixes a bug in the POST support.
alobbs authored
648 cherokee_connection_update_timeout (conn);
649 }
650
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
651 break;
652 case ret_eagain:
346b422 Antonio Pérez Applied the "new-events" branch, again... Hope this fix the tree once an...
skarcha authored
653 /* conn->polling_aim set */
654 return ret_eagain;
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
655 case ret_eof:
656 case ret_error:
657 return ret_error;
658 default:
659 RET_UNKNOWN(ret);
660 return ret_error;
661 }
662 }
663
61b5e98 Alvaro Lopez Ortega Fixes timeout management while handling POSTs
alobbs authored
664 /* Next iteration
665 */
475ecb2 Alvaro Lopez Ortega The POST management code has been rewritten from scratch. The new
alobbs authored
666 if (! cherokee_buffer_is_empty (buf)) {
346b422 Antonio Pérez Applied the "new-events" branch, again... Hope this fix the tree once an...
skarcha authored
667 return ret_eagain;
475ecb2 Alvaro Lopez Ortega The POST management code has been rewritten from scratch. The new
alobbs authored
668 }
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
669
475ecb2 Alvaro Lopez Ortega The POST management code has been rewritten from scratch. The new
alobbs authored
670 if (! cherokee_post_read_finished (&conn->post)) {
671 hdl->post_phase = fcgi_post_phase_read;
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
672 return ret_eagain;
673 }
674
475ecb2 Alvaro Lopez Ortega The POST management code has been rewritten from scratch. The new
alobbs authored
675 TRACE (ENTRIES",post", "Post %s\n", "finished");
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
676 return ret_ok;
677
678 default:
679 SHOULDNT_HAPPEN;
680 }
681
682 return ret_error;
683 }
684
685
72f6444 Alvaro Lopez Ortega Clean up: Trims trailing spaces.
alobbs authored
686 ret_t
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
687 cherokee_handler_fcgi_init (cherokee_handler_fcgi_t *hdl)
688 {
b830ce0 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@3264 5dc97367-97f1...
alobbs authored
689 ret_t ret;
690 cherokee_connection_t *conn = HANDLER_CONN(hdl);
72f6444 Alvaro Lopez Ortega Clean up: Trims trailing spaces.
alobbs authored
691 cherokee_handler_cgi_base_props_t *props = HANDLER_CGI_BASE_PROPS(hdl);
692
3509796 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@282 5dc97367-97f1-...
alobbs authored
693 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
694 case hcgi_phase_build_headers:
a18b345 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@1708 5dc97367-97f1...
alobbs authored
695 TRACE (ENTRIES, "Init: %s\n", "begins");
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
696
72f6444 Alvaro Lopez Ortega Clean up: Trims trailing spaces.
alobbs authored
697 /* Extracts PATH_INFO and filename from request uri
698 */
b830ce0 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@3264 5dc97367-97f1...
alobbs authored
699 ret = cherokee_handler_cgi_base_extract_path (HDL_CGI_BASE(hdl), props->check_file);
72f6444 Alvaro Lopez Ortega Clean up: Trims trailing spaces.
alobbs authored
700 if (unlikely (ret < ret_ok)) return ret;
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
701
702 /* Build the headers
703 */
704 ret = build_header (hdl, &hdl->write_buffer);
705 if (unlikely (ret != ret_ok)) return ret;
706
a18b345 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@1708 5dc97367-97f1...
alobbs authored
707 HDL_CGI_BASE(hdl)->init_phase = hcgi_phase_connect;
708
709 case hcgi_phase_connect:
710 TRACE (ENTRIES, "Init: %s\n", "connect");
711
72f6444 Alvaro Lopez Ortega Clean up: Trims trailing spaces.
alobbs authored
712 /* Connect
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
713 */
714 ret = connect_to_server (hdl);
16f53b0 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@1658 5dc97367-97f1...
alobbs authored
715 switch (ret) {
716 case ret_ok:
717 break;
a18b345 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@1708 5dc97367-97f1...
alobbs authored
718 case ret_eagain:
719 return ret_eagain;
16f53b0 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@1658 5dc97367-97f1...
alobbs authored
720 case ret_deny:
721 conn->error_code = http_gateway_timeout;
722 return ret_error;
723 default:
2e0ea0e Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@430 5dc97367-97f1-...
alobbs authored
724 conn->error_code = http_service_unavailable;
16f53b0 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@1658 5dc97367-97f1...
alobbs authored
725 return ret_error;
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
726 }
727
3509796 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@282 5dc97367-97f1-...
alobbs authored
728 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
729
730 case hcgi_phase_send_headers:
a18b345 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@1708 5dc97367-97f1...
alobbs authored
731 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
732
733 /* Send the header
734 */
735 ret = do_send (hdl, &hdl->write_buffer);
f9f8902 Alvaro Lopez Ortega Better timeout support while handling POSTs.
alobbs authored
736 if (ret != ret_ok) {
81679d0 handler_*.c, space / code style cleanups
ADF authored
737 return ret;
f9f8902 Alvaro Lopez Ortega Better timeout support while handling POSTs.
alobbs authored
738 }
739
740 if (! cherokee_buffer_is_empty (&hdl->write_buffer)) {
741 return ret_eagain;
742 }
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
743
744 break;
745 }
746
747 TRACE (ENTRIES, "Init %s\n", "finishes");
72f6444 Alvaro Lopez Ortega Clean up: Trims trailing spaces.
alobbs authored
748
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
749 cherokee_buffer_clean (&hdl->write_buffer);
750 return ret_ok;
751 }
752
475ecb2 Alvaro Lopez Ortega The POST management code has been rewritten from scratch. The new
alobbs authored
753
754 ret_t
755 cherokee_handler_fcgi_read_post (cherokee_handler_fcgi_t *hdl)
756 {
757 return send_post (hdl, &hdl->write_buffer);
758 }
Something went wrong with that request. Please try again.