|
cwist
Modern C web framework with libttak runtime
|
#include <cwist/sys/session/flash.h>#include <cwist/core/mem/alloc.h>#include <string.h>#include <stdio.h>#include <cwist/core/siphash/siphash.h>
Go to the source code of this file.
Functions | |
| void | cwist_flash_set (cwist_http_request *req, const char *key, const char *value) |
| Store a flash entry on the request. | |
| const char * | cwist_flash_peek (cwist_http_request *req, const char *key) |
| Read a flash entry without removing it. | |
| const char * | cwist_flash_get (cwist_http_request *req, const char *key) |
| Read and remove a flash entry. | |
| char * | cwist_flash_pop_all_json (cwist_http_request *req) |
| Serialize all flash entries to a JSON object and clear the map. | |
| const char * cwist_flash_get | ( | cwist_http_request * | req, |
| const char * | key | ||
| ) |
Read and remove a flash entry.
Get a flash message and consume it (one-time read).
Destructive lookup: on success the entry's bucket is unlinked and freed, and ownership of the value string is transferred to the caller, who must release it with cwist_free().
| req | Request whose flash map is read. |
| key | Entry key to look up. |
Definition at line 55 of file flash.c.
References cwist_query_map::buckets, cap, cwist_free(), cwist_http_request::flash, cwist_query_bucket::next, cwist_query_map::seed, siphash24(), and cwist_query_map::size.
| const char * cwist_flash_peek | ( | cwist_http_request * | req, |
| const char * | key | ||
| ) |
Read a flash entry without removing it.
Peek at a flash message without consuming it.
Non-destructive lookup; the entry remains in the flash map.
| req | Request whose flash map is read. |
| key | Entry key to look up. |
Definition at line 39 of file flash.c.
References cap, cwist_query_map_get(), and cwist_http_request::flash.
| char * cwist_flash_pop_all_json | ( | cwist_http_request * | req | ) |
Serialize all flash entries to a JSON object and clear the map.
Serialize all flash messages to a JSON object string. Caller must free the returned string.
Builds a JSON object string {"key":"value",...} with '"' and '\' escaped in keys and values, then frees every flash entry and empties the map.
| req | Request whose flash map is serialized. |
Definition at line 87 of file flash.c.
References cwist_query_map::buckets, cap, count, cwist_alloc(), cwist_free(), cwist_realloc(), cwist_http_request::flash, cwist_query_bucket::key, cwist_query_bucket::next, cwist_query_map::size, and cwist_query_bucket::value.
Store a flash entry on the request.
Set a flash message on the request.
Creates the request's flash query map on first use. A NULL value is stored as an empty string.
| req | Request to attach the flash entry to; ignored if NULL. |
| key | Entry key; ignored if NULL. |
| value | Entry value; NULL is stored as "". |
Definition at line 20 of file flash.c.
References cwist_query_map_create(), cwist_query_map_set(), and cwist_http_request::flash.