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

Go to the source code of this file.

Data Structures

struct  h2o_cookie
 Cookie structure. More...
 

Typedefs

typedef enum h2o_same_site_args h2o_same_site_args_t
 SameSite argument types.
 
typedef struct h2o_cookie h2o_cookie_t
 Cookie structure.
 
typedef enum h2o_cookie_param h2o_cookie_param_t
 Cookie parameter types.
 

Enumerations

enum  h2o_same_site_args { INVALID = -1 , NONE = 0 , LAX = 1 , STRICT = 2 }
 SameSite argument types. More...
 
enum  h2o_cookie_param {
  SAME_SITE , HTTP_ONLY , PATH , EXPIRES ,
  MAX_AGE , DOMAIN , SECURE
}
 Cookie parameter types. More...
 

Functions

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.
 

Typedef Documentation

◆ h2o_cookie_param_t

Cookie parameter types.

Parameters
SAME_SITEThe SameSite parameter.
HTTP_ONLYThe HttpOnly parameter.
PATHThe Path parameter.
EXPIRESThe Expires parameter.
MAX_AGEThe Max-Age parameter.
DOMAINThe Domain parameter.
SECUREThe Secure parameter.

◆ h2o_cookie_t

typedef struct h2o_cookie h2o_cookie_t

Cookie structure.

Parameters
namesThe names of each cookie field.
valuesThe values of each cookie field.
domainThe domain of the cookie.
pathThe path of the cookie.
expires_strThe expires string of the cookie.
same_siteThe SameSite value of the cookie.
expiresThe expires value of the cookie.
max_ageThe max-age value of the cookie.
secureThe secure value of the cookie.
http_onlyThe http-only value of the cookie.

◆ h2o_same_site_args_t

SameSite argument types.

Parameters
INVALIDAn invalid SameSite value, for initializing only, or to mark SameSite as not being a part of the Cookie.
NONEThe None SameSite value.
LAXThe Lax SameSite value.
STRICTThe Strict SameSite value.

Enumeration Type Documentation

◆ h2o_cookie_param

Cookie parameter types.

Parameters
SAME_SITEThe SameSite parameter.
HTTP_ONLYThe HttpOnly parameter.
PATHThe Path parameter.
EXPIRESThe Expires parameter.
MAX_AGEThe Max-Age parameter.
DOMAINThe Domain parameter.
SECUREThe Secure parameter.
Enumerator
SAME_SITE 
HTTP_ONLY 
PATH 
EXPIRES 
MAX_AGE 
DOMAIN 
SECURE 

◆ h2o_same_site_args

SameSite argument types.

Parameters
INVALIDAn invalid SameSite value, for initializing only, or to mark SameSite as not being a part of the Cookie.
NONEThe None SameSite value.
LAXThe Lax SameSite value.
STRICTThe Strict SameSite value.
Enumerator
INVALID 
NONE 
LAX 
STRICT 

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.