Added wrappers for substring-search
ndpi_init_automa() ndpi_free_automa() ndpi_add_string_to_automa() ndpi_finalize_automa() ndpi_match_string() set_ndpi_malloc() set_ndpi_free()
This commit is contained in:
@@ -544,6 +544,62 @@ extern "C" {
|
||||
struct ndpi_flow_struct *flow, char *certificate);
|
||||
#endif
|
||||
|
||||
/* Wrappers functions */
|
||||
/**
|
||||
* Init Aho-Corasick automata
|
||||
*
|
||||
* @return The requested automata, or NULL if an error occurred
|
||||
*
|
||||
*/
|
||||
void* ndpi_init_automa();
|
||||
|
||||
|
||||
/**
|
||||
* Free Aho-Corasick automata allocated with ndpi_init_automa();
|
||||
*
|
||||
* @par The automata initialized with ndpi_init_automa();
|
||||
* @return The requested automata, or NULL if an error occurred
|
||||
*
|
||||
*/
|
||||
void ndpi_free_automa(void *_automa);
|
||||
|
||||
|
||||
/**
|
||||
* Add a string to match to an automata
|
||||
*
|
||||
* @par The automata initialized with ndpi_init_automa();
|
||||
* @par The (sub)string to search
|
||||
* @return 0 in case of no error, or -1 if an error occurred.
|
||||
*
|
||||
*/
|
||||
int ndpi_add_string_to_automa(void *_automa, char *str);
|
||||
|
||||
|
||||
/**
|
||||
* Finalize the automa (necessary before start searching)
|
||||
*
|
||||
* @par The automata initialized with ndpi_init_automa();
|
||||
*
|
||||
*/
|
||||
void ndpi_finalize_automa(void *_automa);
|
||||
|
||||
|
||||
/**
|
||||
* Add a string to match to an automata
|
||||
*
|
||||
* @par The automata initialized with ndpi_init_automa();
|
||||
* @par The (sub)string to search
|
||||
* @return 0 in case of match, or -1 if no match, or -2 if an error occurred.
|
||||
*
|
||||
*/
|
||||
int ndpi_match_string(void *_automa, char *string_to_match);
|
||||
|
||||
|
||||
|
||||
/* Utility functions to set ndpi malloc/free wrappers */
|
||||
void set_ndpi_malloc(void* (*__ndpi_malloc)(size_t size));
|
||||
void set_ndpi_free(void (*__ndpi_free)(void *ptr));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -7533,3 +7533,4 @@ static const char *ndpi_en_impossible_bigrams[] = {
|
||||
"yj", "yq", "yv", "yz", "yw", "zb", "zc", "zg", "zh", "zj", "zn", "zq", "zr", "zs", "zx", "wh", "wk",
|
||||
"wb", "zk", "kp", "zk", "xy",
|
||||
NULL };
|
||||
|
||||
|
||||
+45
-2
@@ -1681,6 +1681,9 @@ static int ndpi_add_host_ip_subprotocol(struct ndpi_detection_module_struct *ndp
|
||||
|
||||
#endif
|
||||
|
||||
void set_ndpi_malloc(void* (*__ndpi_malloc)(size_t size)) { _ndpi_malloc = __ndpi_malloc; }
|
||||
void set_ndpi_free(void (*__ndpi_free)(void *ptr)) { _ndpi_free = __ndpi_free; }
|
||||
|
||||
/* ******************************************************************** */
|
||||
|
||||
struct ndpi_detection_module_struct *ndpi_init_detection_module(u_int32_t ticks_per_second,
|
||||
@@ -1691,8 +1694,7 @@ struct ndpi_detection_module_struct *ndpi_init_detection_module(u_int32_t ticks_
|
||||
struct ndpi_detection_module_struct *ndpi_str;
|
||||
|
||||
/* TODO global malloc wrappers should not be set here: ndpi_init_detection_module can be called many times */
|
||||
_ndpi_malloc = __ndpi_malloc;
|
||||
_ndpi_free = __ndpi_free;
|
||||
set_ndpi_malloc(__ndpi_malloc), set_ndpi_free(__ndpi_free);
|
||||
|
||||
ndpi_str = ndpi_malloc(sizeof(struct ndpi_detection_module_struct));
|
||||
|
||||
@@ -1746,6 +1748,47 @@ struct ndpi_detection_module_struct *ndpi_init_detection_module(u_int32_t ticks_
|
||||
|
||||
/* *********************************************** */
|
||||
|
||||
/* Wrappers */
|
||||
void* ndpi_init_automa() {
|
||||
return(ac_automata_init(ac_match_handler));
|
||||
}
|
||||
|
||||
int ndpi_add_string_to_automa(void *_automa, char *str) {
|
||||
AC_PATTERN_t ac_pattern;
|
||||
AC_AUTOMATA_t *automa = (AC_AUTOMATA_t*)_automa;
|
||||
|
||||
if(automa == NULL) return(-1);
|
||||
|
||||
ac_pattern.astring = str;
|
||||
ac_pattern.rep.number = 1; /* Dummy */
|
||||
ac_pattern.length = strlen(ac_pattern.astring);
|
||||
return(ac_automata_add(automa, &ac_pattern) == ACERR_SUCCESS ? 0 : -1);
|
||||
}
|
||||
|
||||
void ndpi_free_automa(void *_automa) { ac_automata_release((AC_AUTOMATA_t*)_automa); }
|
||||
void ndpi_finalize_automa(void *_automa) { ac_automata_finalize((AC_AUTOMATA_t*)_automa); }
|
||||
|
||||
/* ****************************************************** */
|
||||
|
||||
int ndpi_match_string(void *_automa, char *string_to_match) {
|
||||
int matching_protocol_id = NDPI_PROTOCOL_UNKNOWN;
|
||||
AC_TEXT_t ac_input_text;
|
||||
AC_AUTOMATA_t *automa = (AC_AUTOMATA_t*)_automa;
|
||||
|
||||
if((automa == NULL)
|
||||
|| (string_to_match == NULL)
|
||||
|| (string_to_match[0] == '\0'))
|
||||
return(-2);
|
||||
|
||||
ac_input_text.astring = string_to_match, ac_input_text.length = strlen(string_to_match);
|
||||
ac_automata_search(automa, &ac_input_text, (void*)&matching_protocol_id);
|
||||
ac_automata_reset(automa);
|
||||
|
||||
return(matching_protocol_id > 0 ? 0 : -1);
|
||||
}
|
||||
|
||||
/* *********************************************** */
|
||||
|
||||
static void free_ptree_data(void *data) { ; }
|
||||
|
||||
/* ****************************************************** */
|
||||
|
||||
@@ -117,8 +117,7 @@ void ndpi_search_dns(struct ndpi_detection_module_struct *ndpi_struct, struct nd
|
||||
if(off < flow->packet.payload_packet_len)
|
||||
{
|
||||
flow->host_server_name[j] = flow->packet.payload[off];
|
||||
if(j < strlen(flow->host_server_name))
|
||||
{
|
||||
if(j < strlen((char*)flow->host_server_name)) {
|
||||
if(flow->host_server_name[j] < ' ')
|
||||
flow->host_server_name[j] = '.';
|
||||
j++;
|
||||
|
||||
Reference in New Issue
Block a user