5#define _POSIX_C_SOURCE 200809L
21 bool ok = cwist_error_is_ok(&
err);
27static int needs_url_encode(
char c) {
28 if ((
c >=
'A' &&
c <=
'Z') || (
c >=
'a' &&
c <=
'z') || (
c >=
'0' &&
c <=
'9') ||
c ==
'-' ||
29 c ==
'_' ||
c ==
'.' ||
c ==
'~') {
36 if (!value)
return NULL;
37 size_t len =
strlen(value);
38 size_t max = len * 3 + 1;
40 if (!out)
return NULL;
42 for (
size_t i = 0;
i < len;
i++) {
43 unsigned char c = (
unsigned char)value[
i];
44 if (needs_url_encode((
char)
c)) {
56 if (!
in || !out || out_len == 0)
return -1;
59 for (
size_t i = 0;
i < len;
i++) {
60 if (
j >= out_len - 1)
return -1;
61 if (
in[
i] ==
'%' &&
i + 2 < len &&
isxdigit((
unsigned char)
in[
i + 1]) &&
70 }
else if (
in[
i] ==
'+') {
81 if (!
map || !header || !*header)
return;
98 while (
nlen > 0 && (name[
nlen - 1] ==
' ' || name[
nlen - 1] ==
'\t')) {
115 if (!
map || !name)
return NULL;
121 if (!res || !name)
return -1;
162 int rc = add_set_cookie(res,
cookie->data);
168 if (!res || !name)
return -1;
174 snprintf(buf,
sizeof(buf),
"%s=; Path=/; Max-Age=0", name);
176 int rc = add_set_cookie(res,
cookie->data);
Memory allocation wrappers backed by libttak.
void cwist_free(void *ptr)
Free memory obtained via cwist_alloc/cwist_strdup/etc.
char * cwist_strdup(const char *src)
Duplicate a string using libttak-backed storage.
void * cwist_alloc(size_t size)
Allocate zeroed memory tracked by libttak.
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_decode(const char *in, char *out, size_t out_len)
URL-decode a cookie value in-place into a caller-owned buffer.
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.
char * cwist_cookie_encode(const char *value)
URL-encode a string for safe cookie values.
void cwist_cookie_parse(cwist_query_map *map, const char *header)
Parse a Cookie header value into a query-style map.
HTTP cookie parsing and construction helpers.
cwist_sstring * cwist_sstring_create(void)
Create a new sstring instance.
cwist_error_t cwist_sstring_append(cwist_sstring *str, const char *data)
Append a C string.
void cwist_sstring_destroy(cwist_sstring *str)
Destroy an sstring instance.
cwist_error_t cwist_http_header_add(cwist_http_header_node **head, const char *key, const char *value)
Add a header to the list.
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.
Options for setting a response cookie.
Integrated error structure used throughout the system.
HTTP Response Object. Supports standard string body or Zero-Copy pointer body.
cwist_http_header_node * headers
void cwist_error_dispose(cwist_error_t *err)
Release resources owned by an error value. Currently only CWIST_ERR_JSON owns memory (the cJSON paylo...