htils 1
A small set of utilities for C programming.
Loading...
Searching...
No Matches
cookie.c File Reference
#include <ctype.h>
#include <stdarg.h>
#include <time.h>
#include <h2o/memory.h>
#include <htils/assert.h>
#include <htils/basictypes.h>
#include <h2otils/cookie.h>
#include <h2otils/darray.h>
#include <h2otils/string.h>

Data Structures

struct  known_attr
 

Macros

#define APPEND(str, str_len)
 

Typedefs

typedef struct known_attr known_attr_t
 

Functions

static void to_lower (h2o_string *str)
 
static i32 parse_3let_month (const cstr *month_cstr)
 
static i32 parse_str_to_num (const cstr *str, i32 max_digits)
 
static b32 parse_imf_fixdate (const cstr *date_str, time_t *result)
 
static b32 parse_http_date (const cstr *date_cstr, time_t *result)
 
static b32 validate_expires (const cstr *expires_str, i64 *expires)
 
h2o_cookie_th2o_cookie_new (h2o_mem_pool_t *pool, const h2o_string **names, const h2o_string **values, const u64 amount)
 Creates a new cookie with values.
 
h2o_cookie_th2o_cookie_from_string (h2o_mem_pool_t *pool, const h2o_string *str)
 Creates a new cookie from a string.
 
void h2o_cookie_add_param (h2o_mem_pool_t *pool, h2o_cookie_t *cookie, h2o_cookie_param_t param,...)
 Adds a parameter to the cookie.
 
void h2o_cookie_append (h2o_cookie_t *cookie, const h2o_string *key, const h2o_string *value)
 Appends a key-value pair to the cookie.
 
h2o_stringh2o_cookie_to_string (h2o_mem_pool_t *pool, h2o_cookie_t *cookie)
 Converts a cookie to a h2o_string.
 
h2o_stringh2o_cookie_get_value (h2o_cookie_t *cookie, const h2o_string *key)
 Gets a value from the cookie.
 

Macro Definition Documentation

◆ APPEND

#define APPEND (   str,
  str_len 
)
Value:
do { \
if (len + (str_len) >= sizeof(buf)) { \
fprintf(stderr, "Cookie string exceeds buffer size.\n"); \
return null; \
} \
memcpy(buf + len, str, str_len); \
len += (str_len); \
} while (0)
#define null
Definition basictypes.h:52

Typedef Documentation

◆ known_attr_t

typedef struct known_attr known_attr_t

Function Documentation

◆ h2o_cookie_add_param()

void h2o_cookie_add_param ( h2o_mem_pool_t *  pool,
h2o_cookie_t cookie,
h2o_cookie_param_t  param,
  ... 
)

Adds a parameter to the cookie.

Checks the parameter, and appends the modifier according to Set-Cookie syntax.

Parameters
poolThe memory pool to allocate the cookie from.
cookieThe cookie to add the parameter to.
paramThe parameter to add.
...The value of the parameter, as provided by variadic args.
Precondition
  • pool, cookie, and val must be valid and cannot be null.
  • param must be a valid parameter.

◆ h2o_cookie_append()

void h2o_cookie_append ( h2o_cookie_t cookie,
const h2o_string key,
const h2o_string value 
)

Appends a key-value pair to the cookie.

Appends a key-value pair to the cookie, if the key already exists, its updated, otherwise it will be created.

Parameters
cookieThe cookie to append to.
keyThe key to append.
valueThe value to append.
Precondition
cookie, key, and value must be valid and cannot be null.

◆ h2o_cookie_from_string()

h2o_cookie_t * h2o_cookie_from_string ( h2o_mem_pool_t *  pool,
const h2o_string str 
)

Creates a new cookie from a string.

Parses the string and creates a new cookie from it.

Parameters
poolThe memory pool to allocate the cookie from.
strThe string to parse.
Precondition
pool and str must be valid and cannot be null.
Returns
A pointer to the new cookie.

◆ h2o_cookie_get_value()

h2o_string * h2o_cookie_get_value ( h2o_cookie_t cookie,
const h2o_string key 
)

Gets a value from the cookie.

Gets a value from the cookie, if the key doesn't exist, it will return null.

Parameters
cookieThe cookie to get the value from.
keyThe key to get the value from.
Precondition
cookie and key must be valid and cannot be null.
Returns
A pointer to the value, or null if it doesn't exist.

◆ h2o_cookie_new()

h2o_cookie_t * h2o_cookie_new ( h2o_mem_pool_t *  pool,
const h2o_string **  names,
const h2o_string **  values,
const u64  amount 
)

Creates a new cookie with values.

Allocates a new cookie with the given values to conform to the Set-Cookie syntax.

Parameters
poolThe memory pool to allocate the cookie from.
namesThe names of each cookie field.
valuesThe values of each cookie field.
amountThe amount of cookie keys and values within the cookie.
Precondition
pool, names, and values must be valid and cannot be null.

◆ h2o_cookie_to_string()

h2o_string * h2o_cookie_to_string ( h2o_mem_pool_t *  pool,
h2o_cookie_t cookie 
)

Converts a cookie to a h2o_string.

Converts the cookie to a h2o_string, according to the Set-Cookie syntax.

Parameters
poolThe memory pool to allocate the string from.
cookieThe cookie to convert.
Precondition
pool and cookie must be valid and cannot be null.
Returns
A pointer to the new h2o_string.

◆ parse_3let_month()

static i32 parse_3let_month ( const cstr month_cstr)
inlinestatic

◆ parse_http_date()

static b32 parse_http_date ( const cstr date_cstr,
time_t *  result 
)
static

◆ parse_imf_fixdate()

static b32 parse_imf_fixdate ( const cstr date_str,
time_t *  result 
)
static

◆ parse_str_to_num()

static i32 parse_str_to_num ( const cstr str,
i32  max_digits 
)
inlinestatic

◆ to_lower()

static void to_lower ( h2o_string str)
inlinestatic

◆ validate_expires()

static b32 validate_expires ( const cstr expires_str,
i64 expires 
)
static