libjwt-1.17.0
JWT Header Manipulation

These functions allow you to add, remove and retrieve headers from a JWT object. More...

Functions

const char * jwt_get_header (jwt_t *jwt, const char *header)
 Return the value of a string header.
 
long jwt_get_header_int (jwt_t *jwt, const char *header)
 Return the value of an integer header.
 
int jwt_get_header_bool (jwt_t *jwt, const char *header)
 Return the value of an boolean header.
 
char * jwt_get_headers_json (jwt_t *jwt, const char *header)
 Return the value of a header as JSON encoded object string.
 
int jwt_add_header (jwt_t *jwt, const char *header, const char *val)
 Add a new string header to this JWT object.
 
int jwt_add_header_int (jwt_t *jwt, const char *header, long val)
 Add a new integer header to this JWT object.
 
int jwt_add_header_bool (jwt_t *jwt, const char *header, int val)
 Add a new boolean header to this JWT object.
 
int jwt_add_headers_json (jwt_t *jwt, const char *json)
 Add headers from a JSON encoded object string.
 
int jwt_del_headers (jwt_t *jwt, const char *header)
 Delete a header from this JWT object.
 

Detailed Description

These functions allow you to add, remove and retrieve headers from a JWT object.

Function Documentation

◆ jwt_add_header()

int jwt_add_header ( jwt_t * jwt,
const char * header,
const char * val )

Add a new string header to this JWT object.

Creates a new header for this object. The string for header and val are copied internally, so do not require that the pointer or string remain valid for the lifetime of this object. It is an error if you try to add a header that already exists.

Parameters
jwtPointer to a JWT object.
headerString containing the name of the header to add.
valString containing the value to be saved for header. Can be an empty string, but cannot be NULL.
Returns
Returns 0 on success, valid errno otherwise.

Note, this only allows for string based headers. If you wish to add integer headers, then use jwt_add_header_int(). If you wish to add more complex headers (e.g. an array), then use jwt_add_headers_json().

◆ jwt_add_header_bool()

int jwt_add_header_bool ( jwt_t * jwt,
const char * header,
int val )

Add a new boolean header to this JWT object.

Creates a new header for this object. The string for header is copied internally, so do not require that the pointer or string remain valid for the lifetime of this object. It is an error if you try to add a header that already exists.

Parameters
jwtPointer to a JWT object.
headerString containing the name of the header to add.
valboolean containing the value to be saved for header.
Returns
Returns 0 on success, valid errno otherwise.

Note, this only allows for boolean based headers. If you wish to add string headers, then use jwt_add_header(). If you wish to add more complex headers (e.g. an array), then use jwt_add_headers_json().

◆ jwt_add_header_int()

int jwt_add_header_int ( jwt_t * jwt,
const char * header,
long val )

Add a new integer header to this JWT object.

Creates a new header for this object. The string for header is copied internally, so do not require that the pointer or string remain valid for the lifetime of this object. It is an error if you try to add a header that already exists.

Parameters
jwtPointer to a JWT object.
headerString containing the name of the header to add.
valint containing the value to be saved for header.
Returns
Returns 0 on success, valid errno otherwise.

Note, this only allows for integer based headers. If you wish to add string headers, then use jwt_add_header(). If you wish to add more complex headers (e.g. an array), then use jwt_add_headers_json().

◆ jwt_add_headers_json()

int jwt_add_headers_json ( jwt_t * jwt,
const char * json )

Add headers from a JSON encoded object string.

Loads a header from an existing JSON encoded object string. Overwrites existing header. If header is NULL, then the JSON encoded string is assumed to be a JSON hash of all headers being added and will be merged into the header listing.

Parameters
jwtPointer to a JWT object.
jsonString containing a JSON encoded object of headers.
Returns
Returns 0 on success, valid errno otherwise.

◆ jwt_del_headers()

int jwt_del_headers ( jwt_t * jwt,
const char * header )

Delete a header from this JWT object.

Deletes the named header from this object. It is not an error if there is no header matching the passed name. If header is NULL, then all headers are deleted from this JWT.

Parameters
jwtPointer to a JWT object.
headerString containing the name of the header to delete. If this is NULL, then all headers are deleted.
Returns
Returns 0 on success, valid errno otherwise.

◆ jwt_get_header()

const char * jwt_get_header ( jwt_t * jwt,
const char * header )

Return the value of a string header.

Returns the string value for a header (e.g. ""). If it does not exist, NULL will be returned.

Parameters
jwtPointer to a JWT object.
headerString containing the name of the header to return a value for.
Returns
Returns a string for the value, or NULL when not found.

Note, this will only return headers with JSON string values. Use jwt_get_header_json() to get the JSON representation of more complex values (e.g. arrays) or use jwt_get_header_int() to get simple integer values.

◆ jwt_get_header_bool()

int jwt_get_header_bool ( jwt_t * jwt,
const char * header )

Return the value of an boolean header.

Returns the int value for a header (e.g. ""). If it does not exist, 0 will be returned.

Parameters
jwtPointer to a JWT object.
headerString containing the name of the header to return a value for.
Returns
Returns a boolean for the value. Sets errno to ENOENT when not found.

Note, this will only return headers with JSON boolean values. Use jwt_get_header_json() to get the JSON representation of more complex values (e.g. arrays) or use jwt_get_header() to get string values.

◆ jwt_get_header_int()

long jwt_get_header_int ( jwt_t * jwt,
const char * header )

Return the value of an integer header.

Returns the int value for a header (e.g. ""). If it does not exist, 0 will be returned.

Parameters
jwtPointer to a JWT object.
headerString containing the name of the header to return a value for.
Returns
Returns an int for the value. Sets errno to ENOENT when not found.

Note, this will only return headers with JSON integer values. Use jwt_get_header_json() to get the JSON representation of more complex values (e.g. arrays) or use jwt_get_header() to get string values.

◆ jwt_get_headers_json()

char * jwt_get_headers_json ( jwt_t * jwt,
const char * header )

Return the value of a header as JSON encoded object string.

Returns the JSON encoded string value for a header (e.g. ""). If it does not exist, NULL will be returned.

Parameters
jwtPointer to a JWT object.
headerString containing the name of the header to return a value for. If this is NULL, all headers will be returned as a JSON encoded hash.
Returns
Returns a string for the value, or NULL when not found. The returned string must be freed by the caller.