Plan 9 from Bell Labs’s /usr/web/sources/plan9/sys/src/libhttpd/query.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#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;
}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.