chttpserver · Section 3
chttpsvr_req_query
NAME
chttpsvr_req_query - look up all values for a query parameter
LIBRARY
C Collections (libccollections, -lccollections)
SYNOPSIS
#include <ccollections/chttpserver.h>
const char **chttpsvr_req_query(chttpsvr_req *req, const char *key,
size_t *count_out);
DESCRIPTION
Parses the query string lazily on the first call and returns a NULL-terminated array of all the URL-decoded values of key. Each key of the query string is URL-decoded and then compared with key as you give it, in the same way as url.Values of the Go net/url package, so pass the decoded form: "a b" finds both a+b and a%20b, but "a%20b" finds neither. When count_out is not NULL the count goes into it. For an absent key the function returns NULL. A key=value pair whose key or value has a malformed percent-escape, such as a=%zz, or an escape that decodes to a NUL byte, such as a=%00, is left out as if the query string did not contain it. Read chttpsvr_req_raw_query(3) if you need to see such a pair. The value strings that the array points to are valid until the handler call returns. The array itself is a scratch buffer of this request that every chttpsvr_req_query call reuses, so copy the pointers you need before you call chttpsvr_req_query again on the same request.
NOTES
The function can't tell a lack of memory, while the query string is parsed or while the result array grows, from a key that is really absent: Both give NULL and a count of 0. After a NULL, call chttpsvr_req_query_oom(req) to find out which one it was, or use chttpsvr_req_query_one for a key with one value, since that function returns ccol_not_enough_memory when it runs out of memory. A component of the query string that has a "=" with an empty key in front of it, for example "?=hello", is a real pair that you can look up: The key "" maps to the value "hello". A completely empty component is different, and the parser skips it instead of reading it as an entry with an empty key and an empty value. A component is completely empty when there is nothing at all between two "&" characters, before a leading "&" or after a trailing "&", as in "?a=1&&b=2" and "?&a=1".
SEE ALSO
chttpsvr_req_query_one(3), chttpsvr_req_query_oom(3), chttpsvr_req_raw_query(3)