libonion
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Typedefs | Enumerations | Functions
Dict.

Data Structures

struct  onion_dict_node_t
 Node for the tree. More...
struct  onion_dict_t
 A 'char *' to 'char *' dictionary. More...

Typedefs

typedef struct onion_dict_node_t onion_dict_node
 Node for the tree.

Enumerations

enum  onion_dict_flags_e {
  OD_FREE_KEY = 2, OD_FREE_VALUE = 4, OD_FREE_ALL = 6, OD_DUP_KEY = 0x12,
  OD_DUP_VALUE = 0x24, OD_DUP_ALL = 0x36, OD_REPLACE = 0x040, OD_STRING = 0,
  OD_DICT = 0x0100, OD_TYPE_MASK = 0x0FF00, OD_ICASE = 0x01
}
 Flags to change some parameters of each key. More...

Functions

void onion_dict_merge (onion_dict *me, const onion_dict *other)
 memberof onion_dict_tMeres the contents of other dictionary intro me.
onion_dictonion_dict_from_json (const char *data)
 Creates a dict from a jsonOnion dicts do not support full json semantics, soit will do the translations as possible; sometimes information may be lost.
onion_dictonion_dict_t::onion_dict_new ()
void onion_dict_t::onion_dict_set_flags (onion_dict *dict, int flags)
onion_dictonion_dict_t::onion_dict_dup (onion_dict *dict)
 Creates a duplicate of the dict.
onion_dictonion_dict_t::onion_dict_hard_dup (onion_dict *dict)
 Creates a full duplicate of the dict.
void onion_dict_t::onion_dict_free (onion_dict *dict)
 Removes the full dict struct from mem.
static const onion_dict_nodeonion_dict_t::onion_dict_find_node (const onion_dict *d, const onion_dict_node *current, const char *key, const onion_dict_node **parent)
 Searchs for a given key, and returns that node and its parent (if parent!=NULL)
void onion_dict_t::onion_dict_add (onion_dict *dict, const char *key, const void *value, int flags)
 Adds a value in the tree.Flags are or from onion_dict_flags_e, for example OD_DUP_ALL.
int onion_dict_t::onion_dict_remove (onion_dict *dict, const char *key)
onion_dictonion_dict_t::onion_dict_get_dict (const onion_dict *dict, const char *key)
 Gets a value, only if its a dict.
void onion_dict_t::onion_dict_print_dot (const onion_dict *dict)
void onion_dict_t::onion_dict_preorder (const onion_dict *dict, void *func, void *data)
 Executes a function on each element, in preorder by key.
int onion_dict_t::onion_dict_count (const onion_dict *dict)
 Counts elements.
void onion_dict_t::onion_dict_lock_read (const onion_dict *dict)
void onion_dict_t::onion_dict_lock_write (onion_dict *dict)
 Do a read lock. Several can lock for reading, but only can be writing.
void onion_dict_t::onion_dict_unlock (onion_dict *dict)
 Free latest lock be it read or write.
onion_blockonion_dict_t::onion_dict_to_json (onion_dict *dict)
 Converts a dict to a json string.
const char * onion_dict_t::onion_dict_rget (const onion_dict *dict, const char *key,...)
 Gets a dictionary string value, recursively.
onion_dictonion_dict_t::onion_dict_rget_dict (const onion_dict *dict, const char *key,...)
 Gets a dictionary dict value, recursively.

Detailed Description

Typedef Documentation

Node for the tree.

Its implemented as a AA Tree (http://en.wikipedia.org/wiki/AA_tree)

Enumeration Type Documentation

Flags to change some parameters of each key.

Enumerator:
OD_FREE_KEY 

Whether the key has to be removed at free time.

OD_FREE_VALUE 

Whether the value has to be removed at free time.

OD_FREE_ALL 

Whether both, the key and value have to be removed at free time. In any case its also marked for freeing later.

OD_DUP_KEY 

Whether the key has to be dupped.

OD_DUP_VALUE 

Whether the value has to be dupped.

OD_DUP_ALL 

Whether both, the key and value have to be dupped. In any case its also marked for freeing later.

OD_REPLACE 

If already exists, replaces content.

OD_STRING 

Stored data is a string, this is the most normal situation.

OD_DICT 

Stored data is another dictionary.

OD_TYPE_MASK 

Mask for the types.

OD_ICASE 

Do case insensitive cmps.

Function Documentation

void onion_dict_add ( onion_dict dict,
const char *  key,
const void *  value,
int  flags 
)
int onion_dict_count ( const onion_dict dict)
onion_dict * onion_dict_dup ( onion_dict dict)

Creates a duplicate of the dict.

Its actually the same, but with refcount increased, so future frees will free the dict only on latest one.

Any change on one dict s made also on the other one, as well as rwlock... This is usefull on a multhreaded environment so that multiple threads cna have the same dict and free it when not in use anymore.

References ONION_DEBUG0, pthread_mutex_lock, pthread_mutex_unlock, and onion_dict_t::refcount.

static const onion_dict_node * onion_dict_find_node ( const onion_dict d,
const onion_dict_node current,
const char *  key,
const onion_dict_node **  parent 
)

Searchs for a given key, and returns that node and its parent (if parent!=NULL)

If not found, returns the parent where it should be. Nice for adding too.

References onion_dict_t::cmp, onion_dict_node_t::data, onion_dict_node_t::left, and onion_dict_node_t::right.

Referenced by onion_dict_t::onion_dict_get(), and onion_dict_t::onion_dict_get_dict().

void onion_dict_free ( onion_dict dict)
onion_dict* onion_dict_from_json ( const char *  data)

Creates a dict from a jsonOnion dicts do not support full json semantics, soit will do the translations as possible; sometimes information may be lost.

Converts a C string into a dictionary.

Anyway dicts created by onion are ensured to be readable by onion.

If the data is invalid NULL is returned.

References ONION_DEBUG, and onion_dict_t::onion_dict_free().

onion_dict * onion_dict_get_dict ( const onion_dict dict,
const char *  key 
)
onion_dict * onion_dict_hard_dup ( onion_dict dict)

Creates a full duplicate of the dict.

Its actually the same, but with refcount increased, so future frees will free the dict only on latest one.

Any change on one dict is made also on the other one, as well as rwlock... This is usefull on a multhreaded environment so that multiple threads cna have the same dict and free it when not in use anymore.

References onion_dict_hard_dup_helper(), onion_dict_t::onion_dict_new(), and onion_dict_t::onion_dict_preorder().

void onion_dict_lock_read ( const onion_dict dict)

Do a read lock. Several can lock for reading, but only can be writing.

void onion_dict_lock_write ( onion_dict dict)

Do a read lock. Several can lock for reading, but only can be writing.

Referenced by onion_handler_auth_pam_handler().

void onion_dict_merge ( onion_dict me,
const onion_dict other 
)

memberof onion_dict_tMeres the contents of other dictionary intro me.

Merges argument dictionary into current.

Parameters
meThe current dictionary where keys: vlaues will be added
otherDictionary with keys to add to me

References onion_dict_t::onion_dict_preorder().

onion_dict * onion_dict_new ( )
void onion_dict_preorder ( const onion_dict dict,
void *  func,
void *  data 
)

Executes a function on each element, in preorder by key.

The function is of prototype void func(void *data, const char *key, const void *value, int flags);

References onion_dict_t::root.

Referenced by onion_dict_t::onion_dict_hard_dup(), onion_dict_merge(), onion_request_t::onion_request_clean(), onion_request_t::onion_request_free(), and onion_response_t::onion_response_write_headers().

void onion_dict_print_dot ( const onion_dict dict)

Prints a graph on the form:

key1 -> key0; key1 -> key2; ...

User of this function has to write the 'digraph G{' and '}'

References onion_dict_t::root.

int onion_dict_remove ( onion_dict dict,
const char *  key 
)

Removes the given key.

Returns if it removed any node.

References onion_dict_t::root.

Referenced by onion_mime_update().

const char * onion_dict_rget ( const onion_dict dict,
const char *  key,
  ... 
)

Gets a dictionary string value, recursively.

Loops inside given dictionaries to get the given value

Parameters
dictThe dictionary
keyThe key list, one per arg, end with NULL
Returns
The const string if valid, or NULL

References onion_dict_t::onion_dict_get(), and onion_dict_t::onion_dict_get_dict().

onion_dict * onion_dict_rget_dict ( const onion_dict dict,
const char *  key,
  ... 
)

Gets a dictionary dict value, recursively.

Loops inside given dictionaries to get the given value

Parameters
dictThe dictionary
keyThe key list, one per arg, end with NULL
Returns
The const string if valid, or NULL

References onion_dict_t::onion_dict_get_dict().

void onion_dict_set_flags ( onion_dict dict,
int  flags 
)
onion_block * onion_dict_to_json ( onion_dict dict)

Converts a dict to a json string.

Given a dictionary and a buffer (with size), it writes a json dictionary to it.

Returns
an onion_block with the json data, or NULL on error

References onion_block_t::onion_block_add_char(), onion_block_t::onion_block_free(), onion_block_t::onion_block_new(), onion_block_t::onion_block_rewind(), onion_block_t::onion_block_size(), and onion_dict_t::root.

Referenced by onion_sessions_redis_save(), onion_sessions_sqlite3_save(), and onion_shortcut_response_json().

void onion_dict_unlock ( onion_dict dict)

Free latest lock be it read or write.

Referenced by onion_handler_auth_pam_handler().