libfetch 0.0.0
A lightweight asynchronous HTTP/1.1 client library implementing a subset of the WHATWG Fetch API.
Loading...
Searching...
No Matches
Cookie Management

Functions for HTTP cookie handling. More...

Functions

cookie_jar_tfetch_get_cookie_jar (void)
 Get the current cookie jar.
 
size_t fetch_cookie_jar_count (const char *domain_filter)
 Count cookies in the jar.
 
void fetch_cookie_jar_clear (void)
 Clear all cookies from the jar.
 
void fetch_disable_cookies (void)
 Disable cookie handling.
 
cookie_jar_tfetch_create_cookie_jar (const char *persistent_file)
 Create a new cookie jar.
 
void fetch_cookie_jar_free (cookie_jar_t *jar)
 Free a cookie jar.
 
bool fetch_save_cookies (const char *filename, cookie_jar_t *jar)
 Save cookies to a file.
 
bool fetch_load_cookies (const char *filename, cookie_jar_t *jar)
 Load cookies from a file.
 
void fetch_cookie_jar_print (cookie_jar_t *jar, const char *domain_filter)
 Print cookies to stdout (for debugging)
 

Detailed Description

Functions for HTTP cookie handling.

Function Documentation

◆ fetch_cookie_jar_clear()

void fetch_cookie_jar_clear ( void )

Clear all cookies from the jar.

◆ fetch_cookie_jar_count()

size_t fetch_cookie_jar_count ( const char * domain_filter)

Count cookies in the jar.

Parameters
domain_filterOptional domain filter (NULL for all cookies)
Returns
Number of cookies
size_t total = fetch_cookie_jar_count(NULL);
size_t google = fetch_cookie_jar_count("google.com");
printf("Total cookies: %zu, Google cookies: %zu\n", total, google);

◆ fetch_cookie_jar_free()

void fetch_cookie_jar_free ( cookie_jar_t * jar)

Free a cookie jar.

Parameters
jarCookie jar to free
Note
Memory: Frees the cookie jar and all contained cookies

◆ fetch_cookie_jar_print()

void fetch_cookie_jar_print ( cookie_jar_t * jar,
const char * domain_filter )

Print cookies to stdout (for debugging)

Parameters
jarCookie jar to print
domain_filterOptional domain filter (NULL for all)

◆ fetch_create_cookie_jar()

cookie_jar_t * fetch_create_cookie_jar ( const char * persistent_file)

Create a new cookie jar.

Parameters
persistent_fileOptional file for persistent storage (NULL for memory-only)
Returns
New cookie jar (caller owns, must call fetch_cookie_jar_free()), or NULL on failure
Note
Memory: Returns owned cookie jar that must be freed
// Memory-only cookie jar
if (!jar) {
fprintf(stderr, "Failed to create cookie jar\n");
return -1;
}
// Persistent cookie jar
cookie_jar_t *persistent_jar = fetch_create_cookie_jar("cookies.dat");
if (persistent_jar) {
// Use jar...
fetch_cookie_jar_free(persistent_jar); // Required
}
fetch_cookie_jar_free(jar); // Required
Cookie jar implementation.
Definition cookie.h:184

◆ fetch_disable_cookies()

void fetch_disable_cookies ( void )

Disable cookie handling.

Removes the cookie jar and disables cookie processing.

◆ fetch_get_cookie_jar()

cookie_jar_t * fetch_get_cookie_jar ( void )

Get the current cookie jar.

Returns
Cookie jar (owned by library, do not free), or NULL if cookies disabled
Note
Memory: Cookie jar is owned by the library

◆ fetch_load_cookies()

bool fetch_load_cookies ( const char * filename,
cookie_jar_t * jar )

Load cookies from a file.

Parameters
filenameFile path to load from
jarCookie jar to load into
Returns
true if successful

◆ fetch_save_cookies()

bool fetch_save_cookies ( const char * filename,
cookie_jar_t * jar )

Save cookies to a file.

Parameters
filenameFile path to save to
jarCookie jar to save
Returns
true if successful