src/server/daemon/http.c

changeset 118
38bf6dd8f4e7
parent 104
a8acbb12f27c
child 345
5832e10fc59a
equal deleted inserted replaced
117:a94cf2e94492 118:38bf6dd8f4e7
244 { 244 {
245 return set_finfo(sn, rq, finfo->st_size, finfo->st_mtime); 245 return set_finfo(sn, rq, finfo->st_size, finfo->st_mtime);
246 } 246 }
247 247
248 248
249 /* ---------------------------- http_hdrs2env ----------------------------- */
250
251 NSAPI_PUBLIC char **http_hdrs2env(pblock *pb)
252 {
253 char *t, *n, **env;
254 struct pb_entry *p;
255 pb_param *pp;
256 register int x, y, z;
257 int pos, ts, ln;
258
259 /* Find out how many there are. */
260 for(x = 0, y = 0; x < pb->hsize; x++) {
261 p = pb->ht[x];
262 while(p) {
263 ++y;
264 p = p->next;
265 }
266 }
267
268 env = util_env_create(NULL, y, &pos);
269
270 ts = 1024;
271 t = (char *) MALLOC(ts);
272
273 for(x = 0; x < pb->hsize; x++) {
274 p = pb->ht[x];
275
276 while(p) {
277 pp = p->param;
278
279 ln = strlen(pp->name) + 6;
280
281 if(ln >= ts) {
282 ts = ln;
283 t = (char *) REALLOC(t, ts);
284 }
285 n = pp->name;
286
287 /* Skip authorization for CGI */
288 if(strcasecmp(n, "authorization")) {
289 if(strcasecmp(n, "content-type") &&
290 strcasecmp(n, "content-length"))
291 {
292 strncpy(t, "HTTP_", 5);
293 z = 5;
294 }
295 else
296 z = 0;
297
298 for(y = 0; n[y]; ++y, ++z)
299 t[z] = (n[y] == '-' ? '_' : toupper(n[y]));
300 t[z] = '\0';
301
302 env[pos++] = util_env_str(t, pp->value);
303 }
304 p = p->next;
305 }
306 }
307 env[pos] = NULL;
308 FREE(t);
309 return env;
310 }

mercurial