|
cwist
Modern C web framework with libttak runtime
|
HTTP cookie parsing and construction helpers. More...
#include <cwist/net/http/cookie.h>#include <cwist/core/mem/alloc.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <ctype.h>
Go to the source code of this file.
Macros | |
| #define | _POSIX_C_SOURCE 200809L |
Functions | |
| char * | cwist_cookie_encode (const char *value) |
| URL-encode a string for safe cookie values. | |
| int | cwist_cookie_decode (const char *in, char *out, size_t out_len) |
| URL-decode a cookie value in-place into a caller-owned buffer. | |
| void | cwist_cookie_parse (cwist_query_map *map, const char *header) |
| Parse a Cookie header value into a query-style map. | |
| const char * | cwist_cookie_get (cwist_query_map *map, const char *name) |
| Get a cookie value by name from a parsed map. | |
| int | cwist_cookie_set (cwist_http_response *res, const char *name, const char *value, const cwist_cookie_options *opts) |
| Add a Set-Cookie header to the response. | |
| int | cwist_cookie_delete (cwist_http_response *res, const char *name) |
| Add a Set-Cookie header that deletes a cookie. | |
HTTP cookie parsing and construction helpers.
Definition in file cookie.c.
URL-decode a cookie value in-place into a caller-owned buffer.
| in | Encoded value. |
| out | Output buffer. |
| out_len | Size of output buffer. |
Definition at line 55 of file cookie.c.
References cap.
Referenced by cwist_cookie_parse().
| int cwist_cookie_delete | ( | cwist_http_response * | res, |
| const char * | name | ||
| ) |
Add a Set-Cookie header that deletes a cookie.
Definition at line 167 of file cookie.c.
References cap, cwist_sstring_append(), cwist_sstring_create(), and cwist_sstring_destroy().
Referenced by cwist_session_commit().
URL-encode a string for safe cookie values.
Definition at line 35 of file cookie.c.
References cap, and cwist_alloc().
Referenced by cwist_cookie_set().
| const char * cwist_cookie_get | ( | cwist_query_map * | map, |
| const char * | name | ||
| ) |
Get a cookie value by name from a parsed map.
Definition at line 114 of file cookie.c.
References cap, and cwist_query_map_get().
Referenced by cwist_session_start().
| void cwist_cookie_parse | ( | cwist_query_map * | map, |
| const char * | header | ||
| ) |
Parse a Cookie header value into a query-style map.
Handles "name1=value1; name2=value2" format. Values are URL-decoded.
| map | Map to populate. Must be created by cwist_query_map_create(). |
| header | Raw Cookie header value (may be NULL). |
Definition at line 80 of file cookie.c.
References cap, cwist_cookie_decode(), cwist_free(), cwist_query_map_set(), and cwist_strdup().
Referenced by cwist_session_start().
| int cwist_cookie_set | ( | cwist_http_response * | res, |
| const char * | name, | ||
| const char * | value, | ||
| const cwist_cookie_options * | opts | ||
| ) |
Add a Set-Cookie header to the response.
| res | Response to modify. |
| name | Cookie name. |
| value | Cookie value (will be encoded). |
| opts | Optional attributes. May be NULL for defaults. |
Definition at line 119 of file cookie.c.
References cap, cwist_cookie_encode(), cwist_free(), cwist_sstring_append(), cwist_sstring_create(), cwist_sstring_destroy(), cwist_strdup(), cwist_cookie_options::domain, cwist_cookie_options::http_only, cwist_cookie_options::max_age_seconds, cwist_cookie_options::path, cwist_cookie_options::same_site, and cwist_cookie_options::secure.
Referenced by cwist_session_commit().