diff options
Diffstat (limited to 'src/c')
-rw-r--r-- | src/c/fastcgi.c | 59 | ||||
-rw-r--r-- | src/c/request.c | 2 | ||||
-rw-r--r-- | src/c/urweb.c | 11 |
3 files changed, 42 insertions, 30 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; diff --git a/src/c/request.c b/src/c/request.c index bbc39d34..13cf1084 100644 --- a/src/c/request.c +++ b/src/c/request.c @@ -217,7 +217,7 @@ request_result uw_request(uw_request_context rc, uw_context ctx, if (id && pass) { unsigned idn = atoi(id); - uw_client_connect(idn, atoi(pass), sock, send, close); + uw_client_connect(idn, atoi(pass), sock, send, close, logger_data, log_error); log_error(logger_data, "Processed request for messages by client %u\n\n", idn); return KEEP_OPEN; } diff --git a/src/c/urweb.c b/src/c/urweb.c index 6e217e08..221ac039 100644 --- a/src/c/urweb.c +++ b/src/c/urweb.c @@ -206,12 +206,13 @@ void uw_set_on_success(char *s) { void uw_client_connect(unsigned id, int pass, int sock, int (*send)(int sockfd, const void *buf, ssize_t len), - int (*close)(int fd)) { + int (*close)(int fd), + void *logger_data, uw_logger log_error) { client *c = find_client(id); if (c == NULL) { close(sock); - fprintf(stderr, "Out-of-bounds client request (%u)\n", id); + log_error(logger_data, "Out-of-bounds client request (%u)\n", id); return; } @@ -220,14 +221,14 @@ void uw_client_connect(unsigned id, int pass, int sock, if (c->mode != USED) { pthread_mutex_unlock(&c->lock); close(sock); - fprintf(stderr, "Client request for unused slot (%u)\n", id); + log_error(logger_data, "Client request for unused slot (%u)\n", id); return; } if (pass != c->pass) { pthread_mutex_unlock(&c->lock); close(sock); - fprintf(stderr, "Wrong client password (%u, %d)\n", id, pass); + log_error(logger_data, "Wrong client password (%u, %d)\n", id, pass); return; } @@ -563,7 +564,7 @@ void uw_login(uw_context ctx) { client *c = new_client(); use_client(c); ctx->client = c; - } + } } } |