libonion
|
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_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. | |
onion_dict * | onion_dict_t::onion_dict_new () |
void | onion_dict_t::onion_dict_set_flags (onion_dict *dict, int flags) |
onion_dict * | onion_dict_t::onion_dict_dup (onion_dict *dict) |
Creates a duplicate of the dict. | |
onion_dict * | onion_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_node * | onion_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_dict * | onion_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_block * | onion_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_dict * | onion_dict_t::onion_dict_rget_dict (const onion_dict *dict, const char *key,...) |
Gets a dictionary dict value, recursively. |
typedef struct onion_dict_node_t onion_dict_node |
Node for the tree.
Its implemented as a AA Tree (http://en.wikipedia.org/wiki/AA_tree)
enum onion_dict_flags_e |
Flags to change some parameters of each key.
void 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.
References ONION_ERROR, and onion_dict_t::root.
Referenced by onion_dict_hard_dup_helper(), onion_handler_auth_pam_handler(), onion_mime_update(), onion_request_t::onion_request_get_cookies_dict(), onion_response_t::onion_response_new(), onion_response_t::onion_response_set_header(), and onion_url_handler().
int onion_dict_count | ( | const onion_dict * | dict | ) |
Counts elements.
References onion_dict_t::root.
Referenced by onion_request_t::onion_request_clean(), onion_request_t::onion_request_free(), and onion_response_t::onion_response_write_headers().
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 | ) |
Removes the full dict struct from mem.
References ONION_DEBUG0, onion_low_free(), pthread_mutex_lock, pthread_mutex_unlock, onion_dict_t::refcount, and onion_dict_t::root.
Referenced by onion_dict_from_json(), onion_mime_set(), onion_request_t::onion_request_clean(), onion_request_t::onion_request_free(), onion_request_t::onion_request_session_free(), onion_response_t::onion_response_free(), onion_sessions_t::onion_sessions_create(), and onion_shortcut_response_json().
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 | ||
) |
Gets a value, only if its a dict.
References onion_dict_node_t::data, OD_DICT, onion_dict_t::onion_dict_find_node(), and onion_dict_t::root.
Referenced by onion_dict_t::onion_dict_rget(), and onion_dict_t::onion_dict_rget_dict().
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.
me | The current dictionary where keys: vlaues will be added |
other | Dictionary with keys to add to me |
References onion_dict_t::onion_dict_preorder().
onion_dict * onion_dict_new | ( | ) |
Initializes the basic tree with all the structure in place, but empty.
References onion_dict_t::cmp, ONION_DEBUG0, onion_low_calloc(), pthread_mutex_init, and onion_dict_t::refcount.
Referenced by onion_dict_t::onion_dict_hard_dup(), onion_request_t::onion_request_clean(), onion_request_t::onion_request_get_cookies_dict(), onion_request_t::onion_request_new(), onion_response_t::onion_response_new(), onion_sessions_t::onion_sessions_create(), and onion_sessions_mem_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
dict | The dictionary |
key | The key list, one per arg, end with 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
dict | The dictionary |
key | The key list, one per arg, end with NULL |
References onion_dict_t::onion_dict_get_dict().
void onion_dict_set_flags | ( | onion_dict * | dict, |
int | flags | ||
) |
Sets the dict flags.
References onion_dict_t::cmp, and OD_ICASE.
Referenced by onion_request_t::onion_request_clean(), and onion_request_t::onion_request_new().
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.
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().