Skip to content

Query Maps

Lee Yunjin edited this page Oct 7, 2026 · 1 revision

Query Maps

Header: <cwist/net/http/query.h>

cwist_query_map is a string-to-string hash map keyed with SipHash and a random per-map seed (so attackers cannot force collisions). CWIST uses it for query parameters (req->query_params), path parameters (req->path_params), parsed cookies and flash messages.

static void search(cwist_http_request *req, cwist_http_response *res) {
    const char *q    = cwist_query_map_get(req->query_params, "q");      /* NULL if absent */
    const char *page = cwist_query_map_get(req->query_params, "page");
    ...
}

req->query_params is NULL when the request has no query string; cwist_query_map_get() accepts a NULL map and returns NULL.

Function Description
cwist_query_map *cwist_query_map_create(void) Empty map.
void cwist_query_map_destroy(cwist_query_map *map) Free it and its strings.
void cwist_query_map_parse(cwist_query_map *map, const char *raw_query) Parse a=1&b=2 (percent-decoding through liburiparser).
const char *cwist_query_map_get(cwist_query_map *map, const char *key) Value or NULL; owned by the map.
void cwist_query_map_set(cwist_query_map *map, const char *key, const char *value) Set or replace (copied).
void cwist_query_map_delete(cwist_query_map *map, const char *key) Remove a key.
void cwist_query_map_clear(cwist_query_map *map) Remove every entry.
void cwist_query_map_foreach(cwist_query_map *map, cwist_query_map_iter_func cb, void *ctx) Call cb(key, value, ctx) for each entry.

cwist_query_map_create_in_arena(arena) places the map in a request arena; the framework uses it for per-request maps.

The keyed hash itself is available as siphash24(src, len, key) with cwist_generate_hash_seed(key) in <cwist/core/siphash/siphash.h>.

Clone this wiki locally