Sagui library v3.5.0
Cross-platform library which helps to develop web servers or frameworks.
Loading...
Searching...
No Matches
Data Structures | Typedefs | Functions
String map

Data Structures

struct  sg_strmap
 

Typedefs

typedef int(* sg_strmap_iter_cb) (void *cls, struct sg_strmap *pair)
 
typedef int(* sg_strmap_sort_cb) (void *cls, struct sg_strmap *pair_a, struct sg_strmap *pair_b)
 

Functions

const char * sg_strmap_name (struct sg_strmap *pair)
 
const char * sg_strmap_val (struct sg_strmap *pair)
 
int sg_strmap_add (struct sg_strmap **map, const char *name, const char *val)
 
int sg_strmap_set (struct sg_strmap **map, const char *name, const char *val)
 
int sg_strmap_find (struct sg_strmap *map, const char *name, struct sg_strmap **pair)
 
const char * sg_strmap_get (struct sg_strmap *map, const char *name)
 
int sg_strmap_rm (struct sg_strmap **map, const char *name)
 
int sg_strmap_iter (struct sg_strmap *map, sg_strmap_iter_cb cb, void *cls)
 
int sg_strmap_sort (struct sg_strmap **map, sg_strmap_sort_cb cb, void *cls)
 
unsigned int sg_strmap_count (struct sg_strmap *map)
 
int sg_strmap_next (struct sg_strmap **next)
 
void sg_strmap_cleanup (struct sg_strmap **map)
 

Detailed Description

String map handle and its related functions.

Typedef Documentation

◆ sg_strmap_iter_cb

typedef int(* sg_strmap_iter_cb) (void *cls, struct sg_strmap *pair)

Callback signature used by sg_strmap_iter() to iterate pairs of strings.

Parameters
[out]clsUser-defined closure.
[out]pairCurrent iterated pair.
Return values
0Success.
E<ERROR>User-defined error to stop pairs iteration.

◆ sg_strmap_sort_cb

typedef int(* sg_strmap_sort_cb) (void *cls, struct sg_strmap *pair_a, struct sg_strmap *pair_b)

Callback signature used by sg_strmap_sort() to sort pairs of strings.

Parameters
[out]clsUser-defined closure.
[out]pair_aCurrent left pair (A).
[out]pair_bCurrent right pair (B).
Return values
-1A < B.
0A == B.
1A > B.

Function Documentation

◆ sg_strmap_name()

const char * sg_strmap_name ( struct sg_strmap pair)

Returns a name from the pair.

Parameters
[in]pairPair of name-value.
Returns
Name as a null-terminated string.
Return values
NULLIf the pair is null and set the errno to EINVAL.
Examples
example_strmap.c.

◆ sg_strmap_val()

const char * sg_strmap_val ( struct sg_strmap pair)

Returns a value from the pair.

Parameters
[in]pairPair of name-value.
Returns
Value as a null-terminated string.
Return values
NULLIf the pair is null and set the errno to EINVAL.
Examples
example_httpsrv_sse.c, and example_strmap.c.

◆ sg_strmap_add()

int sg_strmap_add ( struct sg_strmap **  map,
const char *  name,
const char *  val 
)

Adds a pair of name-value to the string map.

Parameters
[in,out]mapPairs map pointer to add a new pair.
[in]namePair name.
[in]valPair value.
Return values
0Success.
EINVALInvalid argument.
ENOMEMOut of memory.
Note
It cannot check if a name already exists in a pair added to the map, then the uniqueness must be managed by the application.

◆ sg_strmap_set()

int sg_strmap_set ( struct sg_strmap **  map,
const char *  name,
const char *  val 
)

Sets a pair of name-value to the string map.

Parameters
[in,out]mapPairs map pointer to set a new pair.
[in]namePair name.
[in]valPair value.
Return values
0Success.
EINVALInvalid argument.
ENOMEMOut of memory.
Note
If a name already exists in a pair previously added into the map, then the function replaces its value, otherwise it is added as a new pair.
Examples
example_httpsrv_sse.c, and example_strmap.c.

◆ sg_strmap_find()

int sg_strmap_find ( struct sg_strmap map,
const char *  name,
struct sg_strmap **  pair 
)

Finds a pair by name.

Parameters
[in]mapPairs map.
[in]nameName to find the pair.
[in,out]pairPointer of the variable to store the found pair.
Return values
0Success.
EINVALInvalid argument.
ENOENTPair not found.
ENOMEMOut of memory.
Examples
example_httpsrv_sse.c, and example_strmap.c.

◆ sg_strmap_get()

const char * sg_strmap_get ( struct sg_strmap map,
const char *  name 
)

Gets a pair by name and returns the value.

Parameters
[in]mapPairs map.
[in]nameName to get the pair.
Returns
Pair value as a null-terminated string.
Return values
NULLIf map or name is null or pair is not found.
Examples
example_httpcomp.c, example_httpcookie.c, example_httpreq_form.c, and example_httpuplds.c.

◆ sg_strmap_rm()

int sg_strmap_rm ( struct sg_strmap **  map,
const char *  name 
)

Removes a pair by name.

Parameters
[in]mapPointer to the pairs map.
[in]nameName to find and then remove the pair.
Return values
0Success.
EINVALInvalid argument.
ENOENTPair already removed.
ENOMEMOut of memory.

◆ sg_strmap_iter()

int sg_strmap_iter ( struct sg_strmap map,
sg_strmap_iter_cb  cb,
void *  cls 
)

Iterates over pairs map.

Parameters
[in]mapPairs map.
[in]cbCallback to iterate the pairs.
[in,out]clsUser-specified value.
Return values
0Success.
EINVALInvalid argument.
Returns
Callback result when it is different from 0.
Examples
example_strmap.c.

◆ sg_strmap_sort()

int sg_strmap_sort ( struct sg_strmap **  map,
sg_strmap_sort_cb  cb,
void *  cls 
)

Sorts the pairs map.

Parameters
[in,out]mapPointer to the pairs map.
[in]cbCallback to sort the pairs.
[in,out]clsUser-specified value.
Return values
0Success.
EINVALInvalid argument.
Examples
example_strmap.c.

◆ sg_strmap_count()

unsigned int sg_strmap_count ( struct sg_strmap map)

Counts the total pairs in the map.

Parameters
[in]mapPairs map.
Returns
Total of pairs.
Return values
0If the list is empty or null.
Examples
example_httpuplds.c.

◆ sg_strmap_next()

int sg_strmap_next ( struct sg_strmap **  next)

Returns the next pair in the map.

Parameters
[in,out]nextPointer to the next pair.
Return values
0Success.
EINVALInvalid argument.

◆ sg_strmap_cleanup()

void sg_strmap_cleanup ( struct sg_strmap **  map)

Cleans the entire map.

Parameters
[in,out]mapPointer to the pairs map.
Examples
example_strmap.c.