diff options
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/ndpi_api.h.in | 50 | ||||
-rw-r--r-- | src/include/ndpi_typedefs.h | 15 |
2 files changed, 50 insertions, 15 deletions
diff --git a/src/include/ndpi_api.h.in b/src/include/ndpi_api.h.in index 36d592b8d..ed1016aea 100644 --- a/src/include/ndpi_api.h.in +++ b/src/include/ndpi_api.h.in @@ -1693,10 +1693,52 @@ extern "C" { /* ******************************* */ - ndpi_str_hash* ndpi_hash_alloc(u_int32_t max_num_entries); - void ndpi_hash_free(ndpi_str_hash *h); - int ndpi_hash_find_entry(ndpi_str_hash *h, char *key, u_int key_len, u_int8_t *value); - int ndpi_hash_add_entry(ndpi_str_hash *h, char *key, u_int8_t key_len, u_int8_t value); + /** + * Initialize the hashmap. + * + * @par h = pointer to the hash map [in, out] + * + * @return 0 on success, 1 otherwise + * + */ + int ndpi_hash_init(ndpi_str_hash **h); + + /** + * Free the hashmap. + * + * @par h = pointer to the hash map [in, out] + * @par cleanup_func = pointer to a optional callback function + * called for each element in the hashmap [in] + * + */ + void ndpi_hash_free(ndpi_str_hash **h, void (*cleanup_func)(ndpi_str_hash *h)); + + /** + * Search for an entry in the hashmap. + * + * @par h = pointer to the hash map [in] + * @par key = character string (no '\0' required) [in] + * @par key_len = length of the character string @key [in] + * @par value = pointer to a pointer to the value, which contains a + * previously added hash entry [in, out] + * + * @return 0 if an entry with that key was found, 1 otherwise + * + */ + int ndpi_hash_find_entry(ndpi_str_hash *h, char *key, u_int key_len, void **value); + + /** + * Add an entry to the hashmap. + * + * @par h = pointer to the hash map [in, out] + * @par key = character string (no '\0' required) [in] + * @par key_len = length of the character string @key [in] + * @par value = pointer to the value to add [in] + * + * @return 0 if the entry was added, 1 otherwise + * + */ + int ndpi_hash_add_entry(ndpi_str_hash **h, char *key, u_int8_t key_len, void *value); /* ******************************* */ diff --git a/src/include/ndpi_typedefs.h b/src/include/ndpi_typedefs.h index 2f47a28b5..309351abf 100644 --- a/src/include/ndpi_typedefs.h +++ b/src/include/ndpi_typedefs.h @@ -1608,19 +1608,12 @@ struct ndpi_bin { /* **************************************** */ -struct ndpi_str_hash_info { - char *key; /* Key */ - u_int8_t key_len; - u_int8_t value; /* Value */ - struct ndpi_str_hash_info *next; -}; - -typedef struct { - u_int32_t num_buckets, max_num_entries; - struct ndpi_str_hash_info **buckets; +typedef struct ndpi_str_hash { + unsigned int hash; + void *value; + u_int8_t private_data[0]; } ndpi_str_hash; - /* **************************************** */ #define HW_HISTORY_LEN 4 |