Classification fixes
This commit is contained in:
@@ -1181,7 +1181,7 @@ typedef void ndpi_bitmap_iterator;
|
|||||||
typedef void ndpi_filter;
|
typedef void ndpi_filter;
|
||||||
|
|
||||||
/* Save memory limiting the key to 56 bit */
|
/* Save memory limiting the key to 56 bit */
|
||||||
#define SAVE_BINARY_BITMAP_MEMORY
|
//#define SAVE_BINARY_BITMAP_MEMORY
|
||||||
|
|
||||||
PACK_ON
|
PACK_ON
|
||||||
struct ndpi_binary_bitmap_entry {
|
struct ndpi_binary_bitmap_entry {
|
||||||
|
|||||||
@@ -83,7 +83,11 @@ static int ndpi_binary_bitmap_entry_compare(const void *_a, const void *_b) {
|
|||||||
struct ndpi_binary_bitmap_entry *a = (struct ndpi_binary_bitmap_entry*)_a;
|
struct ndpi_binary_bitmap_entry *a = (struct ndpi_binary_bitmap_entry*)_a;
|
||||||
struct ndpi_binary_bitmap_entry *b = (struct ndpi_binary_bitmap_entry*)_b;
|
struct ndpi_binary_bitmap_entry *b = (struct ndpi_binary_bitmap_entry*)_b;
|
||||||
|
|
||||||
return(a->value > b->value) - (a->value < b->value);
|
// return(a->value > b->value) - (a->value < b->value);
|
||||||
|
|
||||||
|
if (a->value < b->value) return -1;
|
||||||
|
else if (a->value > b->value) return 1;
|
||||||
|
else return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ********************************************************** */
|
/* ********************************************************** */
|
||||||
@@ -139,14 +143,13 @@ bool ndpi_binary_bitmap_isset(ndpi_binary_bitmap *b, u_int64_t value, u_int8_t *
|
|||||||
struct ndpi_binary_bitmap_entry *rc;
|
struct ndpi_binary_bitmap_entry *rc;
|
||||||
struct ndpi_binary_bitmap_entry tofind;
|
struct ndpi_binary_bitmap_entry tofind;
|
||||||
|
|
||||||
tofind.value = value;
|
tofind.value = value; rc = (struct ndpi_binary_bitmap_entry*)bsearch(&tofind, b->entries,
|
||||||
rc = (struct ndpi_binary_bitmap_entry*)bsearch(&tofind, b->entries,
|
|
||||||
b->num_used_entries,
|
b->num_used_entries,
|
||||||
sizeof(struct ndpi_binary_bitmap_entry),
|
sizeof(struct ndpi_binary_bitmap_entry),
|
||||||
ndpi_binary_bitmap_entry_compare);
|
ndpi_binary_bitmap_entry_compare);
|
||||||
|
if(rc != NULL)
|
||||||
if(rc != NULL) *out_category = rc->category;
|
*out_category = rc->category;
|
||||||
|
|
||||||
return(rc == NULL ? false : true);
|
return(rc == NULL ? false : true);
|
||||||
} else
|
} else
|
||||||
return(false);
|
return(false);
|
||||||
|
|||||||
@@ -155,8 +155,9 @@ bool ndpi_domain_classify_contains(ndpi_domain_classify *c,
|
|||||||
u_int8_t *class_id /* out */,
|
u_int8_t *class_id /* out */,
|
||||||
char *domain) {
|
char *domain) {
|
||||||
u_int32_t len;
|
u_int32_t len;
|
||||||
char *dot, *elem;
|
char *dot;
|
||||||
|
u_int64_t hash;
|
||||||
|
|
||||||
if(!domain) return(false);
|
if(!domain) return(false);
|
||||||
if((len = strlen(domain)) == 0) return(false);
|
if((len = strlen(domain)) == 0) return(false);
|
||||||
if((dot = strrchr(domain, '.')) == NULL) return(false);
|
if((dot = strrchr(domain, '.')) == NULL) return(false);
|
||||||
@@ -179,28 +180,17 @@ bool ndpi_domain_classify_contains(ndpi_domain_classify *c,
|
|||||||
return(false);
|
return(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
elem = domain;
|
hash = ndpi_quick_hash64(domain, strlen(domain));
|
||||||
|
|
||||||
while(true) {
|
|
||||||
u_int64_t hash;
|
|
||||||
|
|
||||||
hash = ndpi_quick_hash64(elem, strlen(elem));
|
|
||||||
|
|
||||||
#ifdef DEBUG_CONTAINS
|
#ifdef DEBUG_CONTAINS
|
||||||
printf("[contains] Searching %s [hash: %llu]\n", elem, hash);
|
printf("[contains] Searching %s [hash: %llu]\n", domain, hash);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(ndpi_binary_bitmap_isset(c->bitmap, hash, class_id)) {
|
if(ndpi_binary_bitmap_isset(c->bitmap, hash, class_id)) {
|
||||||
#ifdef DEBUG_CONTAINS
|
#ifdef DEBUG_CONTAINS
|
||||||
printf("[contains] %s = %d\n", domain, *class_id);
|
printf("[contains] %s = %d\n", domain, *class_id);
|
||||||
#endif
|
#endif
|
||||||
return(true);
|
return(true);
|
||||||
}
|
|
||||||
|
|
||||||
if((elem = strchr(elem, '.')) == NULL)
|
|
||||||
break;
|
|
||||||
else
|
|
||||||
elem = &elem[1];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG_CONTAINS
|
#ifdef DEBUG_CONTAINS
|
||||||
|
|||||||
Reference in New Issue
Block a user