Mercurial > urweb
comparison src/c/fastcgi.c @ 864:6304f5e8fbb4
FastCGI working with lighttpd
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Sat, 27 Jun 2009 19:07:28 -0400 |
parents | 305bc0a431de |
children | c2317cfb99ec |
comparison
equal
deleted
inserted
replaced
863:305bc0a431de | 864:6304f5e8fbb4 |
---|---|
200 for (s = hs->uppercased+5; *h; ++h) | 200 for (s = hs->uppercased+5; *h; ++h) |
201 *s++ = *h == '-' ? '_' : toupper(*h); | 201 *s++ = *h == '-' ? '_' : toupper(*h); |
202 *s = 0; | 202 *s = 0; |
203 | 203 |
204 if (!strcasecmp(saved_h, "Content-length") | 204 if (!strcasecmp(saved_h, "Content-length") |
205 || !strcasecmp(saved_h, "Content-type")) | 205 || !strcasecmp(saved_h, "Content-type")) { |
206 return search_nvps(hs->nvps, hs->uppercased + 5); | 206 if (s = search_nvps(hs->nvps, hs->uppercased + 5)) |
207 else | 207 return s; |
208 return search_nvps(hs->nvps, hs->uppercased); | 208 } |
209 } | 209 |
210 | 210 return search_nvps(hs->nvps, hs->uppercased); |
211 static int read_funny_len(char **buf, int *len) { | 211 } |
212 | |
213 static int read_funny_len(unsigned char **buf, int *len) { | |
212 if (*len <= 0) | 214 if (*len <= 0) |
213 return -1; | 215 return -1; |
214 | 216 |
215 if ((*buf)[0] >> 7 == 0) { | 217 if ((*buf)[0] >> 7 == 0) { |
216 int r = (*buf)[0]; | 218 int r = (*buf)[0]; |
226 *len -= 4; | 228 *len -= 4; |
227 return r; | 229 return r; |
228 } | 230 } |
229 } | 231 } |
230 | 232 |
231 static int read_nvp(char *buf, int len, nvp *nv) { | 233 static int read_nvp(unsigned char **buf, int len, nvp *nv) { |
232 int nameLength, valueLength; | 234 int nameLength, valueLength; |
233 | 235 |
234 if ((nameLength = read_funny_len(&buf, &len)) < 0) | 236 if ((nameLength = read_funny_len(buf, &len)) < 0) |
235 return -1; | 237 return -1; |
236 if ((valueLength = read_funny_len(&buf, &len)) < 0) | 238 if ((valueLength = read_funny_len(buf, &len)) < 0) |
237 return -1; | 239 return -1; |
238 if (len < nameLength + valueLength) | 240 if (len < nameLength + valueLength) |
239 return -1; | 241 return -1; |
240 | 242 |
241 if (nameLength+1 > nv->name_len) { | 243 if (nameLength+1 > nv->name_len) { |
245 if (valueLength+1 > nv->value_len) { | 247 if (valueLength+1 > nv->value_len) { |
246 nv->value_len = valueLength+1; | 248 nv->value_len = valueLength+1; |
247 nv->value = realloc(nv->value, nv->value_len); | 249 nv->value = realloc(nv->value, nv->value_len); |
248 } | 250 } |
249 | 251 |
250 memcpy(nv->name, buf, nameLength); | 252 memcpy(nv->name, *buf, nameLength); |
251 nv->name[nameLength] = 0; | 253 nv->name[nameLength] = 0; |
252 | 254 |
253 memcpy(nv->value, buf + nameLength, valueLength); | 255 memcpy(nv->value, *buf + nameLength, valueLength); |
254 nv->value[valueLength] = 0; | 256 nv->value[valueLength] = 0; |
257 | |
258 *buf += nameLength + valueLength; | |
255 | 259 |
256 return 0; | 260 return 0; |
257 } | 261 } |
258 | 262 |
259 static int fastcgi_close_with(FCGI_Output *out, request_result rr) { | 263 static int fastcgi_close_with(FCGI_Output *out, request_result rr) { |
335 write_stderr(out, "First message is not BEGIN_REQUEST\n"); | 339 write_stderr(out, "First message is not BEGIN_REQUEST\n"); |
336 goto done; | 340 goto done; |
337 } | 341 } |
338 | 342 |
339 while (1) { | 343 while (1) { |
340 char *buf; | 344 unsigned char *buf; |
345 int len; | |
341 | 346 |
342 if (!(r = fastcgi_recv(in))) { | 347 if (!(r = fastcgi_recv(in))) { |
343 write_stderr(out, "Error receiving environment variables\n"); | 348 write_stderr(out, "Error receiving environment variables\n"); |
344 goto done; | 349 goto done; |
345 } | 350 } |
350 } | 355 } |
351 | 356 |
352 if (r->contentLengthB1 == 0 && r->contentLengthB0 == 0) | 357 if (r->contentLengthB1 == 0 && r->contentLengthB0 == 0) |
353 break; | 358 break; |
354 | 359 |
355 if (used_nvps == hs.n_nvps-1) { | 360 len = (r->contentLengthB1 << 8) | r->contentLengthB0; |
356 ++hs.n_nvps; | 361 |
357 hs.nvps = realloc(hs.nvps, hs.n_nvps * sizeof(nvp)); | 362 for (buf = r->contentData; buf < r->contentData + len; ) { |
358 hs.nvps[hs.n_nvps-1].name = malloc(1); | 363 if (used_nvps == hs.n_nvps-1) { |
359 hs.nvps[hs.n_nvps-1].value = malloc(0); | 364 ++hs.n_nvps; |
360 hs.nvps[hs.n_nvps-1].name_len = 1; | 365 hs.nvps = realloc(hs.nvps, hs.n_nvps * sizeof(nvp)); |
361 hs.nvps[hs.n_nvps-1].value_len = 0; | 366 hs.nvps[hs.n_nvps-1].name = malloc(1); |
362 } | 367 hs.nvps[hs.n_nvps-1].value = malloc(0); |
363 | 368 hs.nvps[hs.n_nvps-1].name_len = 1; |
364 if (read_nvp(r->contentData, (r->contentLengthB1 << 8) | r->contentLengthB0, &hs.nvps[used_nvps]) < 0) { | 369 hs.nvps[hs.n_nvps-1].value_len = 0; |
365 write_stderr(out, "Error reading FCGI_PARAMS name-value pair\n"); | 370 } |
366 goto done; | 371 |
367 } | 372 if (read_nvp(&buf, len - (buf - r->contentData), &hs.nvps[used_nvps]) < 0) { |
368 | 373 write_stderr(out, "Error reading FCGI_PARAMS name-value pair\n"); |
369 ++used_nvps; | 374 goto done; |
375 } | |
376 | |
377 write_stderr(out, "PARAM: %s -> %s\n", hs.nvps[used_nvps].name, hs.nvps[used_nvps].value); | |
378 | |
379 ++used_nvps; | |
380 } | |
370 } | 381 } |
371 | 382 |
372 hs.nvps[used_nvps].name[0] = 0; | 383 hs.nvps[used_nvps].name[0] = 0; |
373 | 384 |
374 if (s = get_header(&hs, "Content-Length")) { | 385 if (s = get_header(&hs, "Content-Length")) { |