Ulfius: struct _u_map

Ulfius HTTP Framework for REST Applications in C

Functions
struct _u_map

## Functions
int | u_map_init (struct _u_map *u_map)
int | u_map_clean (struct _u_map *u_map)
int | u_map_clean_full (struct _u_map *u_map)
int | u_map_clean_enum (char **array)
const char ** | u_map_enum_keys (const struct _u_map *u_map)
const char ** | u_map_enum_values (const struct _u_map *u_map)
int | u_map_has_key (const struct _u_map *u_map, const char *key)
int | u_map_has_value (const struct _u_map *u_map, const char *value)
int | u_map_has_value_binary (const struct _u_map *u_map, const char *value, size_t length)
int | u_map_has_key_case (const struct _u_map *u_map, const char *key)
int | u_map_has_value_case (const struct _u_map *u_map, const char *value)
int | u_map_put (struct _u_map *u_map, const char *key, const char *value)
int | u_map_put_binary (struct _u_map *u_map, const char *key, const char *value, uint64_t offset, size_t length)
ssize_t | u_map_get_length (const struct _u_map *u_map, const char *key)
ssize_t | u_map_get_case_length (const struct _u_map *u_map, const char *key)
const char * | u_map_get (const struct _u_map *u_map, const char *key)
const char * | u_map_get_case (const struct _u_map *u_map, const char *key)
int | u_map_remove_from_key (struct _u_map *u_map, const char *key)
int | u_map_remove_from_key_case (struct _u_map *u_map, const char *key)
int | u_map_remove_from_value (struct _u_map *u_map, const char *value)
int | u_map_remove_from_value_case (struct _u_map *u_map, const char *value)
int | u_map_remove_from_value_binary (struct _u_map *u_map, const char *key, size_t length)
int | u_map_remove_at (struct _u_map *u_map, const int index)
struct _u_map * | u_map_copy (const struct _u_map *source)
int | u_map_copy_into (struct _u_map *dest, const struct _u_map *source)
int | u_map_count (const struct _u_map *source)
int | u_map_empty (struct _u_map *u_map)

## Detailed Description

struct _u_map management functions

## Function Documentation

## ◆ u_map_init()

int u_map_init | ( | struct _u_map * | u_map | ) |

initialize a struct _u_map this function MUST be called after a declaration or allocation

Parameters

  struct _u_map | the _u_map to initialize

Returns
  U_OK on success

Ulfius Framework

REST framework library

u_umap.c: Simple map structure functions definitions not memory friendly, all pointer returned must be freed after use

Copyright 2015-2022 Nicolas Mora mail@.nosp@m.babe.nosp@m.loues.nosp@m.t.or.nosp@m.g

This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; version 2.1 of the License.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU GENERAL PUBLIC LICENSE for more details.

You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses/.

## ◆ u_map_clean()

int u_map_clean | ( | struct _u_map * | u_map | ) |

free the struct _u_map's inner components

Parameters

  struct _u_map | the _u_map to cleanup

Returns
  U_OK on success

## ◆ u_map_clean_full()

int u_map_clean_full | ( | struct _u_map * | u_map | ) |

free the struct _u_map and its components

Parameters

  struct _u_map | the _u_map to cleanup

Returns
  U_OK on success

## ◆ u_map_clean_enum()

int u_map_clean_enum | ( | char ** | array | ) |

free an enum return by functions u_map_enum_keys or u_map_enum_values

Parameters

  array | the string array to cleanup

Returns
  U_OK on success

## ◆ u_map_enum_keys()

const char ** u_map_enum_keys | ( | const struct _u_map * | u_map | ) |

returns an array containing all the keys in the struct _u_map

Parameters

  struct _u_map | the _u_map to retreive the keys from

Returns
  an array of char * ending with a NULL element

## ◆ u_map_enum_values()

const char ** u_map_enum_values | ( | const struct _u_map * | u_map | ) |

returns an array containing all the values in the struct _u_map

Parameters

  struct _u_map | the _u_map to retreive the values from

Returns
  an array of char * ending with a NULL element

## ◆ u_map_has_key()

int u_map_has_key | ( | const struct _u_map * | u_map,
|  | const char * | key )

Detects if the key exists in the _u_map search is case sensitive

Parameters

  struct _u_map | the _u_map to analyze
  key | the key to look for

Returns
  true if the sprcified u_map contains the specified key false otherwise

## ◆ u_map_has_value()

int u_map_has_value | ( | const struct _u_map * | u_map,
|  | const char * | value )

Detects if the value exists in the _u_map, value must be a char * string search is case sensitive

Parameters

  struct _u_map | the _u_map to analyze
  value | the value to look for

Returns
  true if the sprcified u_map contains the specified value false otherwise

## ◆ u_map_has_value_binary()

int u_map_has_value_binary | ( | const struct _u_map * | u_map,
|  | const char * | value,
|  | size_t | length )

Detects if the value exists in the _u_map, value may be any byte array search is case sensitive

Parameters

  struct _u_map | the _u_map to analyze
  value | the value to look for
  length | the length of the value to look for

Returns
  true if the sprcified u_map contains the specified value up until the specified length false otherwise

## ◆ u_map_has_key_case()

int u_map_has_key_case | ( | const struct _u_map * | u_map,
|  | const char * | key )

Detects if the key exists in the _u_map search is case insensitive

Parameters

  struct _u_map | the _u_map to analyze
  key | the key to look for

Returns
  true if the sprcified u_map contains the specified key false otherwise

## ◆ u_map_has_value_case()

int u_map_has_value_case | ( | const struct _u_map * | u_map,
|  | const char * | value )

Detects if the key exists in the _u_map search is case insensitive

Parameters

  struct _u_map | the _u_map to analyze
  value | the value to look for

Returns
  true if the sprcified u_map contains the specified value false otherwise

## ◆ u_map_put()

int u_map_put | ( | struct _u_map * | u_map,
|  | const char * | key,
|  | const char * | value )

add the specified key/value pair into the specified u_map if the u_map already contains a pair with the same key, replace the value

Parameters

  struct _u_map | the _u_map to update
  key | the key string
  value | the value string

Returns
  U_OK on success

## ◆ u_map_put_binary()

int u_map_put_binary | ( | struct _u_map * | u_map,
|  | const char * | key,
|  | const char * | value,
|  | uint64_t | offset,
|  | size_t | length )

add the specified key/binary value pair into the specified u_map if the u_map already contains a pair with the same key, replace the value at the specified offset with the specified length

Parameters

  struct _u_map | the _u_map to update
  key | the key string
  value | the value binary
  offset | the start offset to set value in u_map value
  length | the length of value to set

Returns
  U_OK on success

## ◆ u_map_get_length()

ssize_t u_map_get_length | ( | const struct _u_map * | u_map,
|  | const char * | key )

get the value length corresponding to the specified key in the u_map search is case sensitive

Parameters

  struct _u_map | the _u_map to analyze
  key | the key look for

Returns
  the value length if found, -1 if no match found

## ◆ u_map_get_case_length()

ssize_t u_map_get_case_length | ( | const struct _u_map * | u_map,
|  | const char * | key )

get the value length corresponding to the specified key in the u_map search is case insensitive

Parameters

  struct _u_map | the _u_map to analyze
  key | the key look for

Returns
  the value length if found, -1 if no match found

## ◆ u_map_get()

const char * u_map_get | ( | const struct _u_map * | u_map,
|  | const char * | key )

get the value corresponding to the specified key in the u_map search is case sensitive

Parameters

  struct _u_map | the _u_map to analyze
  key | the key to look for

Returns
  the value if key exists NULL if no match found

## ◆ u_map_get_case()

const char * u_map_get_case | ( | const struct _u_map * | u_map,
|  | const char * | key )

get the value corresponding to the specified key in the u_map search is case insensitive

Parameters

  struct _u_map | the _u_map to analyze
  key | the key to look for

Returns
  the value if key exists NULL if no match found

## ◆ u_map_remove_from_key()

int u_map_remove_from_key | ( | struct _u_map * | u_map,
|  | const char * | key )

remove an pair key/value that has the specified key search is case sensitive

Parameters

  struct _u_map | the _u_map to analyze
  key | the key to look for

Returns
  U_OK on success, U_NOT_FOUND if key was not found, error otherwise

## ◆ u_map_remove_from_key_case()

int u_map_remove_from_key_case | ( | struct _u_map * | u_map,
|  | const char * | key )

remove all pairs key/value that has the specified key (case insensitive search) search is case insensitive

Parameters

  struct _u_map | the _u_map to analyze
  key | the key to look for

Returns
  U_OK on success, U_NOT_FOUND if key was not found, error otherwise

## ◆ u_map_remove_from_value()

int u_map_remove_from_value | ( | struct _u_map * | u_map,
|  | const char * | value )

remove all pairs key/value that has the specified value search is case sensitive

Parameters

  struct _u_map | the _u_map to analyze
  value | the value to look for

Returns
  U_OK on success, U_NOT_FOUND if key was not found, error otherwise

## ◆ u_map_remove_from_value_case()

int u_map_remove_from_value_case | ( | struct _u_map * | u_map,
|  | const char * | value )

remove all pairs key/value that has the specified value search is case insensitive

Parameters

  struct _u_map | the _u_map to analyze
  value | the value to look for

Returns
  U_OK on success, U_NOT_FOUND if key was not found, error otherwise

## ◆ u_map_remove_from_value_binary()

int u_map_remove_from_value_binary | ( | struct _u_map * | u_map,
|  | const char * | key,
|  | size_t | length )

remove all pairs key/value that has the specified value up until the specified length

Parameters

  struct _u_map | the _u_map to analyze
  key | the key to look for
  length | the length of key

Returns
  U_OK on success, U_NOT_FOUND if key was not found, error otherwise

## ◆ u_map_remove_at()

int u_map_remove_at | ( | struct _u_map * | u_map,
|  | const int | index )

remove the pair key/value at the specified index

Parameters

  struct _u_map | the _u_map to analyze
  index | the position of the tuple to remove

Returns
  U_OK on success, U_NOT_FOUND if index is out of bound, error otherwise

## ◆ u_map_copy()

struct _u_map * u_map_copy | ( | const struct _u_map * | source | ) |

Create an exact copy of the specified struct _u_map

Parameters

  source | the _u_map to copy

Returns
  a reference to the copy, NULL otherwise returned value must be free'd after use

## ◆ u_map_copy_into()

int u_map_copy_into | ( | struct _u_map * | dest,
|  | const struct _u_map * | source )

Copy all key/values pairs of source into dest If a key is already present in dest, value is overwritten

Parameters

  dest | the _u_map to update
  source | the _u_map to copy

Returns
  U_OK on success, error otherwise

## ◆ u_map_count()

int u_map_count | ( | const struct _u_map * | source | ) |

Count the number of elements in the _u_map

Parameters

  source | the _u_map to analyze

Returns
  the number of key/values pair in the specified struct _u_map Return -1 on error

## ◆ u_map_empty()

int u_map_empty | ( | struct _u_map * | u_map | ) |

Empty a struct u_map of all its elements

Parameters

  struct _u_map | the _u_map to empty

Returns
  U_OK on success, error otherwise