HTP  0.5
Functions
htp_table.c File Reference
#include "htp_config_auto.h"
#include "htp_private.h"

Functions

htp_status_t htp_table_add (htp_table_t *table, const bstr *key, const void *element)
 
htp_status_t htp_table_addn (htp_table_t *table, const bstr *key, const void *element)
 
htp_status_t htp_table_addk (htp_table_t *table, const bstr *key, const void *element)
 
void htp_table_clear (htp_table_t *table)
 
void htp_table_clear_ex (htp_table_t *table)
 
htp_table_thtp_table_create (size_t size)
 
void htp_table_destroy (htp_table_t *table)
 
void htp_table_destroy_ex (htp_table_t *table)
 
void * htp_table_get (const htp_table_t *table, const bstr *key)
 
void * htp_table_get_c (const htp_table_t *table, const char *ckey)
 
void * htp_table_get_index (const htp_table_t *table, size_t idx, bstr **key)
 
void * htp_table_get_mem (const htp_table_t *table, const void *key, size_t key_len)
 
size_t htp_table_size (const htp_table_t *table)
 

Detailed Description

Author
Ivan Ristic ivanr.nosp@m.@web.nosp@m.kreat.nosp@m.or.c.nosp@m.om

Function Documentation

htp_status_t htp_table_add ( htp_table_t table,
const bstr key,
const void *  element 
)

Add a new element to the table. The key will be copied, and the copy managed by the table. The table keeps a pointer to the element. It is the callers responsibility to ensure the pointer remains valid.

Parameters
[in]table
[in]key
[in]element
Returns
HTP_OK on success, HTP_ERROR on failure.
htp_status_t htp_table_addk ( htp_table_t table,
const bstr key,
const void *  element 
)

Add a new element to the table. The key provided will be only referenced and the caller remains responsible to keep it alive until after the table is destroyed. The table keeps a pointer to the element. It is the callers responsibility to ensure the pointer remains valid.

Parameters
[in]table
[in]key
[in]element
Returns
HTP_OK on success, HTP_ERROR on failure.
htp_status_t htp_table_addn ( htp_table_t table,
const bstr key,
const void *  element 
)

Add a new element to the table. The key provided will be adopted and managed by the table. You should not keep a copy of the pointer to the key unless you're certain that the table will live longer that the copy. The table keeps a pointer to the element. It is the callers responsibility to ensure the pointer remains valid.

Parameters
[in]table
[in]key
[in]element
Returns
HTP_OK on success, HTP_ERROR on failure.
void htp_table_clear ( htp_table_t table)

Remove all elements from the table. This function handles keys according to the active allocation strategy. If the elements need freeing, you need to free them before invoking this function.

Parameters
[in]table
void htp_table_clear_ex ( htp_table_t table)

Remove all elements from the table without freeing any of the keys, even if the table is using an allocation strategy where keys belong to it. This function is useful if all the keys have been adopted by some other structure.

Parameters
[in]table
htp_table_t* htp_table_create ( size_t  size)

Create a new table structure. The table will grow automatically as needed, but you are required to provide a starting size.

Parameters
[in]sizeThe starting size.
Returns
Newly created table instance, or NULL on failure.
void htp_table_destroy ( htp_table_t table)

Destroy a table. This function handles the keys according to the active allocation strategy. If the elements need freeing, you need to free them before invoking this function. After the table has been destroyed, the pointer is set to NULL.

Parameters
[in]table
void htp_table_destroy_ex ( htp_table_t table)

Destroy the given table, but don't free the keys. even if they are managed by the table. Use this method when the responsibility for the keys has been transferred elsewhere. After the table has been destroyed, the pointer is set to NULL.

Parameters
[in]table
void* htp_table_get ( const htp_table_t table,
const bstr key 
)

Retrieve the first element that matches the given bstr key.

Parameters
[in]table
[in]key
Returns
Matched element, or NULL if no elements match the key.
void* htp_table_get_c ( const htp_table_t table,
const char *  ckey 
)

Retrieve the first element that matches the given NUL-terminated key.

Parameters
[in]table
[in]ckey
Returns
Matched element, or NULL if no elements match the key.
void* htp_table_get_index ( const htp_table_t table,
size_t  idx,
bstr **  key 
)

Retrieve key and element at the given index.

Parameters
[in]table
[in]idx
[in,out]keyPointer in which the key will be returned. Can be NULL.
Returns
HTP_OK on success, HTP_ERROR on failure.
void* htp_table_get_mem ( const htp_table_t table,
const void *  key,
size_t  key_len 
)

Retrieve table key defined by the provided pointer and length.

Parameters
[in]table
[in]key
[in]key_len
Returns
Matched element, or NULL if no elements match the key.
size_t htp_table_size ( const htp_table_t table)

Return the size of the table.

Parameters
[in]table
Returns
table size