Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
COOKIES: domain-aware HTTP cookie jar

Data Structures

struct  N_COOKIE
 a single stored cookie More...
 
struct  N_COOKIE_JAR
 a thread-safe cookie jar More...
 

Functions

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 the defaults
 
N_STRn_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 matched); free with free_nstr.
 
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
 
void n_cookiejar_free (N_COOKIE_JAR **jar)
 free a cookie jar and all its cookies, then NULL the pointer
 
N_COOKIE_JARn_cookiejar_new (void)
 create an empty cookie jar; free with n_cookiejar_free.
 

Detailed Description


Data Structure Documentation

◆ N_COOKIE

struct N_COOKIE

a single stored cookie

Definition at line 45 of file n_cookies.h.

+ Collaboration diagram for N_COOKIE:
Data Fields
char * domain domain (e.g.

"example.com" or ".example.com" for subdomains)

long expires unix expiry timestamp, 0 = session cookie
int http_only 1 = HttpOnly flag was set
char * name cookie name
char * path path prefix (e.g.

"/")

int secure 1 = only sent over HTTPS
char * value cookie value

◆ N_COOKIE_JAR

struct N_COOKIE_JAR

a thread-safe cookie jar

Examples
ex_cookies.c.

Definition at line 56 of file n_cookies.h.

+ Collaboration diagram for N_COOKIE_JAR:
Data Fields
LIST * cookies list of N_COOKIE*
pthread_rwlock_t lock guards cookies for concurrent use

Function Documentation

◆ n_cookiejar_add_from_header()

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 the defaults

Definition at line 97 of file n_cookies.c.

References N_COOKIE_JAR::cookies, N_COOKIE::domain, N_COOKIE::expires, N_COOKIE::http_only, list_foreach, list_push(), N_COOKIE_JAR::lock, Malloc, n_cookie_free(), N_COOKIE::name, N_COOKIE::path, N_COOKIE::secure, unlock, N_COOKIE::value, and write_lock.

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ n_cookiejar_build_header()

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 matched); free with free_nstr.

Returns NULL when no cookie matches.

Definition at line 181 of file n_cookies.c.

References N_COOKIE_JAR::cookies, N_COOKIE::domain, N_COOKIE::expires, free_nstr, list_foreach, N_COOKIE_JAR::lock, n_cookie_domain_matches(), n_cookie_path_matches(), N_COOKIE::name, new_nstr(), nstrprintf_cat, N_COOKIE::path, read_lock, N_COOKIE::secure, unlock, N_COOKIE::value, and N_STR::written.

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ n_cookiejar_clear()

void n_cookiejar_clear ( N_COOKIE_JAR jar)

drop every stored cookie

Definition at line 229 of file n_cookies.c.

References N_COOKIE_JAR::cookies, N_COOKIE_JAR::lock, n_cookie_free(), remove_list_node_f(), LIST::start, unlock, and write_lock.

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ n_cookiejar_count()

size_t n_cookiejar_count ( N_COOKIE_JAR jar)

number of cookies currently stored

Definition at line 219 of file n_cookies.c.

References N_COOKIE_JAR::cookies, N_COOKIE_JAR::lock, LIST::nb_items, read_lock, and unlock.

Referenced by main().

+ Here is the caller graph for this function:

◆ n_cookiejar_free()

void n_cookiejar_free ( N_COOKIE_JAR **  jar)

free a cookie jar and all its cookies, then NULL the pointer

Definition at line 63 of file n_cookies.c.

References Free, list_destroy(), and rw_lock_destroy.

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ n_cookiejar_new()

N_COOKIE_JAR * n_cookiejar_new ( void  )

create an empty cookie jar; free with n_cookiejar_free.

Returns NULL on error.

Definition at line 49 of file n_cookies.c.

References N_COOKIE_JAR::cookies, Free, init_lock, N_COOKIE_JAR::lock, Malloc, and new_generic_list().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: