|
cwist
Modern C web framework with libttak runtime
|
Query string parser and map. More...
#include <stdint.h>#include <stddef.h>

Go to the source code of this file.
Classes | |
| struct | cwist_query_bucket |
| struct | cwist_query_map |
Typedefs | |
| typedef struct cwist_query_bucket | cwist_query_bucket |
| typedef struct cwist_query_map | cwist_query_map |
Functions | |
Lifecycle | |
| cwist_query_map * | cwist_query_map_create (void) |
| Create a new query map. | |
| 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) |
| Destroy a query map. | |
Parsing | |
| void | cwist_query_map_parse (cwist_query_map *map, const char *raw_query) |
| Parse raw query strings (e.g., "a=1&b=2") into the map. | |
| void | cwist_query_map_clear (cwist_query_map *map) |
| Clear all entries. | |
Access | |
| typedef void(* | cwist_query_map_iter_func) (const char *key, const char *value, void *ctx) |
| Iterator callback signature. | |
| const char * | cwist_query_map_get (cwist_query_map *map, const char *key) |
| Get a value by key. | |
| void | cwist_query_map_set (cwist_query_map *map, const char *key, const char *value) |
| Set a key-value pair. | |
| void | cwist_query_map_delete (cwist_query_map *map, const char *key) |
| Delete a key from the map. | |
| void | cwist_query_map_foreach (cwist_query_map *map, cwist_query_map_iter_func cb, void *ctx) |
| Iterate over all key-value pairs in the map. | |
Query string parser and map.
Definition in file query.h.
| void cwist_query_map_clear | ( | cwist_query_map * | map | ) |
Clear all entries.
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 | ) |
Create a new query map.
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 | ||
| ) |
Delete a key from the map.
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 | ) |
Destroy a query map.
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 | ||
| ) |
Iterate over all key-value pairs 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 | ||
| ) |
Get a value 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 raw query strings (e.g., "a=1&b=2") into the 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().
Set a key-value pair.
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().