diff -r a94cf2e94492 -r 38bf6dd8f4e7 src/server/daemon/http.c --- a/src/server/daemon/http.c Sun Oct 23 11:12:12 2016 +0200 +++ b/src/server/daemon/http.c Wed Oct 26 15:53:56 2016 +0200 @@ -246,3 +246,65 @@ } +/* ---------------------------- http_hdrs2env ----------------------------- */ + +NSAPI_PUBLIC char **http_hdrs2env(pblock *pb) +{ + char *t, *n, **env; + struct pb_entry *p; + pb_param *pp; + register int x, y, z; + int pos, ts, ln; + + /* Find out how many there are. */ + for(x = 0, y = 0; x < pb->hsize; x++) { + p = pb->ht[x]; + while(p) { + ++y; + p = p->next; + } + } + + env = util_env_create(NULL, y, &pos); + + ts = 1024; + t = (char *) MALLOC(ts); + + for(x = 0; x < pb->hsize; x++) { + p = pb->ht[x]; + + while(p) { + pp = p->param; + + ln = strlen(pp->name) + 6; + + if(ln >= ts) { + ts = ln; + t = (char *) REALLOC(t, ts); + } + n = pp->name; + + /* Skip authorization for CGI */ + if(strcasecmp(n, "authorization")) { + if(strcasecmp(n, "content-type") && + strcasecmp(n, "content-length")) + { + strncpy(t, "HTTP_", 5); + z = 5; + } + else + z = 0; + + for(y = 0; n[y]; ++y, ++z) + t[z] = (n[y] == '-' ? '_' : toupper(n[y])); + t[z] = '\0'; + + env[pos++] = util_env_str(t, pp->value); + } + p = p->next; + } + } + env[pos] = NULL; + FREE(t); + return env; +}