aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorToni <matzeton@googlemail.com>2021-06-29 15:32:48 +0200
committerGitHub <noreply@github.com>2021-06-29 15:32:48 +0200
commit8222ac5bdc5f9bb1ea1e2fcdd5733cd3241aa617 (patch)
tree2cb66704b65cbbe411f60ea219fb3d605d8f56df /src
parent1c2a0c36f130baa5eac1548d97da8553510849b3 (diff)
Removed ht_hash as it is not used anymore. (#1220)
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
Diffstat (limited to 'src')
-rw-r--r--src/lib/ndpi_main.c1
-rw-r--r--src/lib/ndpi_utils.c2
-rw-r--r--src/lib/third_party/include/ht_hash.h30
-rw-r--r--src/lib/third_party/src/ht_hash.c187
4 files changed, 0 insertions, 220 deletions
diff --git a/src/lib/ndpi_main.c b/src/lib/ndpi_main.c
index 26d54fb51..1ea517758 100644
--- a/src/lib/ndpi_main.c
+++ b/src/lib/ndpi_main.c
@@ -47,7 +47,6 @@
#include "ndpi_content_match.c.inc"
#include "third_party/include/ndpi_patricia.h"
-#include "third_party/include/ht_hash.h"
#include "third_party/include/ndpi_md5.h"
/* stun.c */
diff --git a/src/lib/ndpi_utils.c b/src/lib/ndpi_utils.c
index dddec3299..9814733f7 100644
--- a/src/lib/ndpi_utils.c
+++ b/src/lib/ndpi_utils.c
@@ -47,8 +47,6 @@
#endif
#include "third_party/include/ndpi_patricia.h"
-#include "third_party/include/ht_hash.h"
-
#include "third_party/include/libinjection.h"
#include "third_party/include/libinjection_sqli.h"
#include "third_party/include/libinjection_xss.h"
diff --git a/src/lib/third_party/include/ht_hash.h b/src/lib/third_party/include/ht_hash.h
deleted file mode 100644
index 2251706e4..000000000
--- a/src/lib/third_party/include/ht_hash.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/* Based on https://gist.github.com/tonious/1377667 */
-
-#ifndef _HASH_H_
-#define _HASH_H_
-
-#include "ndpi_api.h"
-
-struct entry_s {
- char *key;
- u_int16_t value;
- struct entry_s *next;
-};
-
-typedef struct entry_s entry_t;
-
-struct hashtable_s {
- int size;
- struct entry_s **table;
-};
-
-typedef struct hashtable_s hashtable_t;
-
-extern hashtable_t *ht_create( int size );
-extern int ht_hash( hashtable_t *hashtable, char *key );
-extern entry_t *ht_newpair( char *key, u_int16_t value );
-extern void ht_set( hashtable_t *hashtable, char *key, u_int16_t value );
-extern u_int16_t ht_get( hashtable_t *hashtable, char *key );
-extern void ht_free( hashtable_t *hashtable );
-
-#endif /* _HASH_H_ */
diff --git a/src/lib/third_party/src/ht_hash.c b/src/lib/third_party/src/ht_hash.c
deleted file mode 100644
index 9a3afabac..000000000
--- a/src/lib/third_party/src/ht_hash.c
+++ /dev/null
@@ -1,187 +0,0 @@
-/* Based on https://gist.github.com/tonious/1377667 */
-
-#include <stdint.h>
-#include <sys/types.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <limits.h>
-#include <string.h>
-
-#include "ht_hash.h"
-
-/* #define HASH_DEBUG 1 */
-
-/* Create a new hashtable. */
-hashtable_t *ht_create(int size) {
- hashtable_t *hashtable = NULL;
- int i;
-
- if(size < 1) return NULL;
-
- /* Allocate the table itself. */
- if((hashtable = ndpi_malloc(sizeof(hashtable_t))) == NULL)
- return NULL;
-
- /* Allocate pointers to the head nodes. */
- if((hashtable->table = ndpi_malloc(sizeof(entry_t *) * size)) == NULL) {
- free(hashtable);
- return NULL;
- } else {
- for(i = 0; i < size; i++)
- hashtable->table[i] = NULL;
- }
-
- hashtable->size = size;
-
- return hashtable;
-}
-
-/* **************************************************** */
-
-/* Hash a string for a particular hash table. */
-int ht_hash(hashtable_t *hashtable, char *key) {
- unsigned long int hashval = 0;
- int i = 0;
-
- /* Convert our string to an integer */
- while(hashval < ULONG_MAX && i < strlen(key)) {
- hashval = hashval << 8;
- hashval += key[ i ];
- i++;
- }
-
- return hashval % hashtable->size;
-}
-
-/* **************************************************** */
-
-/* Create a key-value pair. */
-entry_t *ht_newpair(char *key, u_int16_t value) {
- entry_t *newpair;
-
- if((newpair = ndpi_malloc(sizeof(entry_t))) == NULL)
- return NULL;
-
- if((newpair->key = ndpi_strdup(key)) == NULL) {
- free(newpair);
- return NULL;
- }
-
- newpair->value = value, newpair->next = NULL;
-
- return newpair;
-}
-
-/* **************************************************** */
-
-/* Insert a key-value pair into a hash table. */
-void ht_set(hashtable_t *hashtable, char *key, u_int16_t value) {
- int bin = 0;
- entry_t *newpair = NULL;
- entry_t *next = NULL;
- entry_t *last = NULL;
-
-#ifdef HASH_DEBUG
- printf("*** %s() %s = %u ***\n", __FUNCTION__, key, value);
-#endif
-
- bin = ht_hash(hashtable, key);
-
- next = hashtable->table[ bin ];
-
- while(next != NULL && next->key != NULL && strcmp(key, next->key) > 0) {
- last = next;
- next = next->next;
- }
-
- /* There's already a pair. Let's replace that string. */
- if(next != NULL && next->key != NULL && strcmp(key, next->key) == 0) {
- next->value = value;
-
- /* Nope, could't find it. Time to grow a pair. */
- } else {
- newpair = ht_newpair(key, value);
-
- /* We're at the start of the linked list in this bin. */
- if(next == hashtable->table[ bin ]) {
- newpair->next = next;
- hashtable->table[ bin ] = newpair;
-
- /* We're at the end of the linked list in this bin. */
- } else if (next == NULL) {
- last->next = newpair;
-
- /* We're in the middle of the list. */
- } else {
- newpair->next = next;
- last->next = newpair;
- }
- }
-}
-
-/* **************************************************** */
-
-/* Retrieve a key-value pair from a hash table. */
-u_int16_t ht_get(hashtable_t *hashtable, char *key) {
- int bin = 0;
- entry_t *pair;
-
- bin = ht_hash(hashtable, key);
-
- /* Step through the bin, looking for our value. */
- pair = hashtable->table[ bin ];
- while(pair != NULL && pair->key != NULL && strcmp(key, pair->key) > 0) {
- pair = pair->next;
- }
-
- /* Did we actually find anything? */
- if(pair == NULL || pair->key == NULL || strcmp(key, pair->key) != 0) {
- return 0;
- } else {
- return pair->value;
- }
-}
-
-/* **************************************************** */
-
-void ht_free(hashtable_t *hashtable) {
- int i;
-
- for(i=0; i<hashtable->size; i++) {
- struct entry_s *t = hashtable->table[i];
-
- while(t != NULL) {
- struct entry_s *next = t->next;
-
- ndpi_free(t->key);
- ndpi_free(t);
-
- t = next;
- }
- }
-
- ndpi_free(hashtable->table);
- ndpi_free(hashtable);
-}
-
-/* **************************************************** */
-
-#ifdef HASH_TEST
-
-int main(int argc, char **argv) {
- hashtable_t *hashtable = ht_create(65536);
-
- ht_set(hashtable, "key1", 32);
- ht_set(hashtable, "key2", 34);
- ht_set(hashtable, "key3", 124);
- ht_set(hashtable, "key4", 98);
-
- printf("%u\n", ht_get(hashtable, "key1"));
- printf("%u\n", ht_get(hashtable, "key2"));
- printf("%u\n", ht_get(hashtable, "key3"));
- printf("%u\n", ht_get(hashtable, "key4"));
-
- return 0;
-}
-
-#endif