4 * Copyright 2005, Broadcom Corporation
7 * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
8 * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
9 * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
10 * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
12 * $Id: cgi.c,v 1.10 2005/03/07 08:35:32 kanki Exp $
22 static struct hsearch_data htab
= { .table
= NULL
};
24 static void unescape(char *s
)
28 while ((s
= strpbrk(s
, "%+"))) {
30 sscanf(s
+ 1, "%02x", &c
);
40 char *webcgi_get(const char *name
)
44 if (!htab
.table
) return NULL
;
47 hsearch_r(e
, FIND
, &ep
, &htab
);
49 // cprintf("%s=%s\n", name, ep ? ep->data : "(null)");
51 return ep
? ep
->data
: NULL
;
54 void webcgi_set(char *name
, char *value
)
63 hsearch_r(e
, FIND
, &ep
, &htab
);
69 hsearch_r(e
, ENTER
, &ep
, &htab
);
73 void webcgi_init(char *query
)
76 char *q
, *end
, *name
, *value
;
78 if (htab
.table
) hdestroy_r(&htab
);
79 if (query
== NULL
) return;
81 // cprintf("query = %s\n", query);
83 end
= query
+ strlen(query
);
86 while (strsep(&q
, "&;")) {
89 hcreate_r(nel
, &htab
);
91 for (q
= query
; q
< end
; ) {
96 name
= strsep(&value
, "=");
97 if (value
) webcgi_set(name
, value
);