|
cwist
Modern C web framework with libttak runtime
|
Hash-map based storage and parsing helpers for URL query parameters. More...
#include <cwist/net/http/query.h>#include <cwist/core/siphash/siphash.h>#include <cwist/core/mem/alloc.h>#include <cwist/core/mem/arena.h>#include <stdlib.h>#include <string.h>#include <ctype.h>#include <stdio.h>
Go to the source code of this file.
Macros | |
| #define | _POSIX_C_SOURCE 200809L |
| #define | CWIST_QUERY_MAP_DEFAULT_SIZE 16 |
Functions | |
| cwist_query_map * | cwist_query_map_create (void) |
| Allocate a query map and seed its SipHash key material. | |
| cwist_query_map * | cwist_query_map_create_in_arena (void *arena) |
| Allocate a query map within a memory arena to avoid GC/heap allocations. | |
| void | cwist_query_map_destroy (cwist_query_map *map) |
| Release every bucket node and the map container itself. | |
| void | cwist_query_map_clear (cwist_query_map *map) |
| Remove every key/value pair while keeping the bucket array allocated. | |
| void | cwist_query_map_set (cwist_query_map *map, const char *key, const char *value) |
| Insert or replace a decoded query parameter in the map. | |
| const char * | cwist_query_map_get (cwist_query_map *map, const char *key) |
| Look up a decoded query parameter by key. | |
| void | cwist_query_map_delete (cwist_query_map *map, const char *key) |
| Remove a key/value pair from the map if present. | |
| void | cwist_query_map_foreach (cwist_query_map *map, cwist_query_map_iter_func cb, void *ctx) |
| Invoke a callback for every key/value pair stored in the map. | |
| void | cwist_query_map_parse (cwist_query_map *map, const char *raw_query) |
Parse a raw a=1&b=2 query string into the existing map. | |
Hash-map based storage and parsing helpers for URL query parameters.
Definition in file query.c.
| void cwist_query_map_clear | ( | cwist_query_map * | map | ) |
Remove every key/value pair while keeping the bucket array allocated.
Clear all entries.
| map | Query map to clear in-place. |
Definition at line 93 of file query.c.
References cap, and cwist_query_bucket::next.
Referenced by cwist_query_map_destroy().
| cwist_query_map * cwist_query_map_create | ( | void | ) |
Allocate a query map and seed its SipHash key material.
Create a new query map.
Definition at line 54 of file query.c.
References cap, and cwist_query_map_create_in_arena().
Referenced by cwist_flash_set(), and cwist_session_start().
| cwist_query_map * cwist_query_map_create_in_arena | ( | void * | arena | ) |
Allocate a query map within a memory arena to avoid GC/heap allocations.
Definition at line 61 of file query.c.
References cap, cwist_generate_hash_seed(), and CWIST_QUERY_MAP_DEFAULT_SIZE.
Referenced by cwist_query_map_create().
| void cwist_query_map_delete | ( | cwist_query_map * | map, |
| const char * | key | ||
| ) |
Remove a key/value pair from the map if present.
Delete a key from the map.
| map | Query map to modify; NULL is a no-op. |
| key | Key to delete; NULL is a no-op. |
| In | heap-managed maps the node and its strings are freed. |
| In | arena-managed maps the node is only unlinked; storage is reclaimed with the arena. (Nothing is freed.) |
Definition at line 220 of file query.c.
References cap, cwist_query_bucket::next, and siphash24().
Referenced by cwist_session_delete().
| void cwist_query_map_destroy | ( | cwist_query_map * | map | ) |
Release every bucket node and the map container itself.
Destroy a query map.
| map | Query map to destroy. |
Definition at line 81 of file query.c.
References cap, and cwist_query_map_clear().
Referenced by cwist_http_request_destroy(), cwist_mux_find_route(), cwist_mux_serve(), cwist_session_destroy(), and cwist_session_start().
| void cwist_query_map_foreach | ( | cwist_query_map * | map, |
| cwist_query_map_iter_func | cb, | ||
| void * | ctx | ||
| ) |
Invoke a callback for every key/value pair stored in the map.
Iterate over all key-value pairs in the map.
| map | Query map to iterate; NULL is a no-op. |
| cb | Callback invoked as cb(key, value, ctx) for each entry; NULL is a no-op. |
| ctx | Opaque pointer forwarded to the callback for each entry. |
Definition at line 252 of file query.c.
References cap.
Referenced by cwist_session_commit().
| const char * cwist_query_map_get | ( | cwist_query_map * | map, |
| const char * | key | ||
| ) |
Look up a decoded query parameter by key.
Get a value by key.
| map | Query map to search. |
| key | Decoded key to retrieve. |
Definition at line 196 of file query.c.
References cap, siphash24(), and cwist_query_bucket::value.
Referenced by cwist_cookie_get(), cwist_flash_peek(), cwist_query_map_parse(), cwist_session_get(), and cwist_url_for().
| void cwist_query_map_parse | ( | cwist_query_map * | map, |
| const char * | raw_query | ||
| ) |
Parse a raw a=1&b=2 query string into the existing map.
Parse raw query strings (e.g., "a=1&b=2") into the map.
| map | Destination map that receives decoded keys and values. |
| raw_query | Raw query substring without the leading question mark. |
Definition at line 319 of file query.c.
References cap, cwist_query_map_get(), and cwist_query_map_set().
Insert or replace a decoded query parameter in the map.
Set a key-value pair.
| map | Query map that owns the entry storage. |
| key | Decoded query-string key. |
| value | Decoded query-string value. |
Definition at line 146 of file query.c.
References cap, cwist_query_bucket::key, cwist_query_bucket::next, siphash24(), and cwist_query_bucket::value.
Referenced by cwist_cookie_parse(), cwist_flash_set(), cwist_query_map_parse(), and cwist_session_set().