aboutsummaryrefslogtreecommitdiff
path: root/src/libhttpd/query.c
blob: 47768da2fe57f2d31b43ba2ddbdd2d17896d2cfb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <u.h>
#include <libc.h>
#include <httpd.h>

/*
 * parse a search string of the form
 * tag=val&tag1=val1...
 */
HSPairs*
hparsequery(HConnect *c, char *search)
{
	HSPairs *q;
	char *tag, *val, *s;

	while((s = strchr(search, '?')) != nil)
		search = s + 1;
	s = search;
	while((s = strchr(s, '+')) != nil)
		*s++ = ' ';
	q = nil;
	while(*search){
		tag = search;
		while(*search != '='){
			if(*search == '\0')
				return q;
			search++;
		}
		*search++ = 0;
		val = search;
		while(*search != '&'){
			if(*search == '\0')
				return hmkspairs(c, hurlunesc(c, tag), hurlunesc(c, val), q);
			search++;
		}
		*search++ = '\0';
		q = hmkspairs(c, hurlunesc(c, tag), hurlunesc(c, val), q);
	}
	return q;
}