diff options
author | Adam Chlipala <adamc@hcoop.net> | 2009-06-27 19:07:28 -0400 |
---|---|---|
committer | Adam Chlipala <adamc@hcoop.net> | 2009-06-27 19:07:28 -0400 |
commit | af332ab2219bf9c424c80593cb885915abed8738 (patch) | |
tree | af49dbce95461b12a44cf64bece402b21b95f537 /src/c/fastcgi.c | |
parent | b9fcbe3dc86323a4a64b419c589a1cc5eeb38749 (diff) |
FastCGI working with lighttpd
Diffstat (limited to 'src/c/fastcgi.c')
-rw-r--r-- | src/c/fastcgi.c | 59 |
1 files changed, 35 insertions, 24 deletions
diff --git a/src/c/fastcgi.c b/src/c/fastcgi.c index ed51133a..7d2ce067 100644 --- a/src/c/fastcgi.c +++ b/src/c/fastcgi.c @@ -202,13 +202,15 @@ static char *get_header(void *data, const char *h) { *s = 0; if (!strcasecmp(saved_h, "Content-length") - || !strcasecmp(saved_h, "Content-type")) - return search_nvps(hs->nvps, hs->uppercased + 5); - else - return search_nvps(hs->nvps, hs->uppercased); + || !strcasecmp(saved_h, "Content-type")) { + if (s = search_nvps(hs->nvps, hs->uppercased + 5)) + return s; + } + + return search_nvps(hs->nvps, hs->uppercased); } -static int read_funny_len(char **buf, int *len) { +static int read_funny_len(unsigned char **buf, int *len) { if (*len <= 0) return -1; @@ -228,12 +230,12 @@ static int read_funny_len(char **buf, int *len) { } } -static int read_nvp(char *buf, int len, nvp *nv) { +static int read_nvp(unsigned char **buf, int len, nvp *nv) { int nameLength, valueLength; - if ((nameLength = read_funny_len(&buf, &len)) < 0) + if ((nameLength = read_funny_len(buf, &len)) < 0) return -1; - if ((valueLength = read_funny_len(&buf, &len)) < 0) + if ((valueLength = read_funny_len(buf, &len)) < 0) return -1; if (len < nameLength + valueLength) return -1; @@ -247,12 +249,14 @@ static int read_nvp(char *buf, int len, nvp *nv) { nv->value = realloc(nv->value, nv->value_len); } - memcpy(nv->name, buf, nameLength); + memcpy(nv->name, *buf, nameLength); nv->name[nameLength] = 0; - memcpy(nv->value, buf + nameLength, valueLength); + memcpy(nv->value, *buf + nameLength, valueLength); nv->value[valueLength] = 0; + *buf += nameLength + valueLength; + return 0; } @@ -337,7 +341,8 @@ static void *worker(void *data) { } while (1) { - char *buf; + unsigned char *buf; + int len; if (!(r = fastcgi_recv(in))) { write_stderr(out, "Error receiving environment variables\n"); @@ -352,21 +357,27 @@ static void *worker(void *data) { if (r->contentLengthB1 == 0 && r->contentLengthB0 == 0) break; - if (used_nvps == hs.n_nvps-1) { - ++hs.n_nvps; - hs.nvps = realloc(hs.nvps, hs.n_nvps * sizeof(nvp)); - hs.nvps[hs.n_nvps-1].name = malloc(1); - hs.nvps[hs.n_nvps-1].value = malloc(0); - hs.nvps[hs.n_nvps-1].name_len = 1; - hs.nvps[hs.n_nvps-1].value_len = 0; - } + len = (r->contentLengthB1 << 8) | r->contentLengthB0; - if (read_nvp(r->contentData, (r->contentLengthB1 << 8) | r->contentLengthB0, &hs.nvps[used_nvps]) < 0) { - write_stderr(out, "Error reading FCGI_PARAMS name-value pair\n"); - goto done; - } + for (buf = r->contentData; buf < r->contentData + len; ) { + if (used_nvps == hs.n_nvps-1) { + ++hs.n_nvps; + hs.nvps = realloc(hs.nvps, hs.n_nvps * sizeof(nvp)); + hs.nvps[hs.n_nvps-1].name = malloc(1); + hs.nvps[hs.n_nvps-1].value = malloc(0); + hs.nvps[hs.n_nvps-1].name_len = 1; + hs.nvps[hs.n_nvps-1].value_len = 0; + } + + if (read_nvp(&buf, len - (buf - r->contentData), &hs.nvps[used_nvps]) < 0) { + write_stderr(out, "Error reading FCGI_PARAMS name-value pair\n"); + goto done; + } - ++used_nvps; + write_stderr(out, "PARAM: %s -> %s\n", hs.nvps[used_nvps].name, hs.nvps[used_nvps].value); + + ++used_nvps; + } } hs.nvps[used_nvps].name[0] = 0; |