74 if (!cookie_domain || !request_domain)
76 if (strcasecmp(cookie_domain, request_domain) == 0)
78 if (cookie_domain[0] ==
'.') {
79 size_t cd = strlen(cookie_domain);
80 size_t rd = strlen(request_domain);
82 const char* suffix = request_domain + rd - (cd - 1);
83 if (strcasecmp(suffix, cookie_domain + 1) == 0)
92 if (!cookie_path || !request_path)
94 return strncmp(request_path, cookie_path, strlen(cookie_path)) == 0;
104 if (!jar || !set_cookie_value || !request_domain)
107 dup = strdup(set_cookie_value);
110 token = strtok_r(dup,
";", &saveptr);
115 eq = strchr(token,
'=');
129 cookie->
name = strdup(n);
130 cookie->
value = strdup(eq + 1);
131 cookie->
domain = strdup(request_domain);
132 cookie->
path = strdup(
"/");
137 while ((token = strtok_r(NULL,
";", &saveptr)) != NULL) {
138 while (*token ==
' ')
140 if (strncasecmp(token,
"domain=", 7) == 0) {
142 cookie->
domain = strdup(token + 7);
143 }
else if (strncasecmp(token,
"path=", 5) == 0) {
145 cookie->
path = strdup(token + 5);
146 }
else if (strncasecmp(token,
"secure", 6) == 0) {
148 }
else if (strncasecmp(token,
"httponly", 8) == 0) {
150 }
else if (strncasecmp(token,
"max-age=", 8) == 0) {
151 long ma = strtol(token + 8, NULL, 10);
152 cookie->
expires = (long)time(NULL) + ma;
162 if (ex && ex->
name && cookie->
name && strcmp(ex->
name, cookie->
name) == 0 &&
185 if (!jar || !jar->
cookies || !domain)
203 if (c->
secure && !is_secure)
#define init_lock(__rwlock_mutex)
Macro for initializing a rwlock.
#define FreeNoLog(__ptr)
Free Handler without log.
#define Malloc(__ptr, __struct, __size)
Malloc Handler to get errors and set to 0.
#define rw_lock_destroy(__rwlock_mutex)
Macro to destroy rwlock mutex.
#define unlock(__rwlock_mutex)
Macro for releasing read/write lock a rwlock mutex.
#define write_lock(__rwlock_mutex)
Macro for acquiring a write lock on a rwlock mutex.
#define Free(__ptr)
Free Handler to get errors.
#define read_lock(__rwlock_mutex)
Macro for acquiring a read lock on a rwlock mutex.
LIST_NODE * start
pointer to the start of the list
size_t nb_items
number of item currently in the list
int list_push(LIST *list, void *ptr, void(*destructor)(void *ptr))
Add a pointer to the end of the list.
#define list_foreach(__ITEM_, __LIST_)
ForEach macro helper, safe for node removal during iteration.
int list_destroy(LIST **list)
Empty and Free a list container.
void * remove_list_node_f(LIST *list, LIST_NODE *node)
Internal function called each time we need to get a node out of a list.
LIST * new_generic_list(size_t max_items)
Initialiaze a generic list container to max_items pointers.
long expires
unix expiry timestamp, 0 = session cookie
char * path
path prefix (e.g.
char * domain
domain (e.g.
int http_only
1 = HttpOnly flag was set
LIST * cookies
list of N_COOKIE*
int secure
1 = only sent over HTTPS
pthread_rwlock_t lock
guards cookies for concurrent use
void n_cookiejar_free(N_COOKIE_JAR **jar)
free a cookie jar and all its cookies, then NULL the pointer
void n_cookiejar_add_from_header(N_COOKIE_JAR *jar, const char *set_cookie_value, const char *request_domain)
parse one Set-Cookie value (without the "Set-Cookie:" name) and store it; request_domain/path supply ...
N_STR * n_cookiejar_build_header(N_COOKIE_JAR *jar, const char *domain, const char *path, int is_secure)
build a "name=value; name2=value2" Cookie header value for a request (domain/path/secure/expiry match...
N_COOKIE_JAR * n_cookiejar_new(void)
create an empty cookie jar; free with n_cookiejar_free.
void n_cookiejar_clear(N_COOKIE_JAR *jar)
drop every stored cookie
size_t n_cookiejar_count(N_COOKIE_JAR *jar)
number of cookies currently stored
size_t written
number of meaningful bytes in data, excluding the null terminator; the size including the null termin...
#define free_nstr(__ptr)
free a N_STR structure and set the pointer to NULL
#define nstrprintf_cat(__nstr_var, __format,...)
Macro to quickly allocate and sprintf and cat to a N_STR.
N_STR * new_nstr(NSTRBYTE size)
create a new N_STR string
A box including a string and his lenght.
Common headers and low-level functions & define.
static int n_cookie_domain_matches(const char *cookie_domain, const char *request_domain)
static int n_cookie_path_matches(const char *cookie_path, const char *request_path)
static void n_cookie_free(void *ptr)
Domain-aware HTTP cookie jar: Set-Cookie parsing and Cookie header building.