Added new API calls
- ndpi_add_string_value_to_automa - ndpi_match_string_id
This commit is contained in:
@@ -41,9 +41,11 @@ ndpi_set_detected_protocol
|
|||||||
ndpi_match_string_subprotocol
|
ndpi_match_string_subprotocol
|
||||||
ndpi_init_automa
|
ndpi_init_automa
|
||||||
ndpi_free_automa
|
ndpi_free_automa
|
||||||
|
ndpi_add_string_value_to_automa
|
||||||
ndpi_add_string_to_automa
|
ndpi_add_string_to_automa
|
||||||
ndpi_finalize_automa
|
ndpi_finalize_automa
|
||||||
ndpi_match_string
|
ndpi_match_string
|
||||||
|
ndpi_match_string_id
|
||||||
set_ndpi_malloc
|
set_ndpi_malloc
|
||||||
set_ndpi_free
|
set_ndpi_free
|
||||||
set_ndpi_debug_function
|
set_ndpi_debug_function
|
||||||
|
|||||||
@@ -566,6 +566,18 @@ extern "C" {
|
|||||||
*
|
*
|
||||||
* @par The automata initialized with ndpi_init_automa();
|
* @par The automata initialized with ndpi_init_automa();
|
||||||
* @par The (sub)string to search
|
* @par The (sub)string to search
|
||||||
|
* @par The number associated with this string
|
||||||
|
* @return 0 in case of no error, or -1 if an error occurred.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
int ndpi_add_string_value_to_automa(void *_automa, char *str, unsigned long num);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a string to match to an automata. Same as ndpi_add_string_value_to_automa() with num set to 1
|
||||||
|
*
|
||||||
|
* @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.
|
* @return 0 in case of no error, or -1 if an error occurred.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@@ -592,6 +604,18 @@ extern "C" {
|
|||||||
int ndpi_match_string(void *_automa, char *string_to_match);
|
int ndpi_match_string(void *_automa, char *string_to_match);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a string to match to an automata
|
||||||
|
*
|
||||||
|
* @par The automata initialized with ndpi_init_automa();
|
||||||
|
* @par The (sub)string to search
|
||||||
|
* @par The id associated with the matched string or 0 id not found.
|
||||||
|
* @return 0 in case of match, or -1 if no match, or -2 if an error occurred.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
int ndpi_match_string_id(void *_automa, char *string_to_match, unsigned long *id);
|
||||||
|
|
||||||
|
|
||||||
/* Utility functions to set ndpi malloc/free/print wrappers */
|
/* Utility functions to set ndpi malloc/free/print wrappers */
|
||||||
void set_ndpi_malloc(void* (*__ndpi_malloc)(size_t size));
|
void set_ndpi_malloc(void* (*__ndpi_malloc)(size_t size));
|
||||||
void set_ndpi_free(void (*__ndpi_free)(void *ptr));
|
void set_ndpi_free(void (*__ndpi_free)(void *ptr));
|
||||||
|
|||||||
+25
-2
@@ -1858,18 +1858,22 @@ void* ndpi_init_automa(void) {
|
|||||||
return(ac_automata_init(ac_match_handler));
|
return(ac_automata_init(ac_match_handler));
|
||||||
}
|
}
|
||||||
|
|
||||||
int ndpi_add_string_to_automa(void *_automa, char *str) {
|
int ndpi_add_string_value_to_automa(void *_automa, char *str, unsigned long num) {
|
||||||
AC_PATTERN_t ac_pattern;
|
AC_PATTERN_t ac_pattern;
|
||||||
AC_AUTOMATA_t *automa = (AC_AUTOMATA_t*)_automa;
|
AC_AUTOMATA_t *automa = (AC_AUTOMATA_t*)_automa;
|
||||||
|
|
||||||
if(automa == NULL) return(-1);
|
if(automa == NULL) return(-1);
|
||||||
|
|
||||||
ac_pattern.astring = str;
|
ac_pattern.astring = str;
|
||||||
ac_pattern.rep.number = 1; /* Dummy */
|
ac_pattern.rep.number = num;
|
||||||
ac_pattern.length = strlen(ac_pattern.astring);
|
ac_pattern.length = strlen(ac_pattern.astring);
|
||||||
return(ac_automata_add(automa, &ac_pattern) == ACERR_SUCCESS ? 0 : -1);
|
return(ac_automata_add(automa, &ac_pattern) == ACERR_SUCCESS ? 0 : -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ndpi_add_string_to_automa(void *_automa, char *str) {
|
||||||
|
return(ndpi_add_string_value_to_automa(_automa, str, 1));
|
||||||
|
}
|
||||||
|
|
||||||
void ndpi_free_automa(void *_automa) { ac_automata_release((AC_AUTOMATA_t*)_automa); }
|
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); }
|
void ndpi_finalize_automa(void *_automa) { ac_automata_finalize((AC_AUTOMATA_t*)_automa); }
|
||||||
|
|
||||||
@@ -1892,6 +1896,25 @@ int ndpi_match_string(void *_automa, char *string_to_match) {
|
|||||||
return(matching_protocol_id > 0 ? 0 : -1);
|
return(matching_protocol_id > 0 ? 0 : -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ****************************************************** */
|
||||||
|
|
||||||
|
int ndpi_match_string_id(void *_automa, char *string_to_match, unsigned long *id) {
|
||||||
|
AC_TEXT_t ac_input_text;
|
||||||
|
AC_AUTOMATA_t *automa = (AC_AUTOMATA_t*)_automa;
|
||||||
|
|
||||||
|
*id = 0;
|
||||||
|
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*)&id);
|
||||||
|
ac_automata_reset(automa);
|
||||||
|
|
||||||
|
return(*id > 0 ? *id : -1);
|
||||||
|
}
|
||||||
|
|
||||||
/* *********************************************** */
|
/* *********************************************** */
|
||||||
|
|
||||||
static void free_ptree_data(void *data) { ; }
|
static void free_ptree_data(void *data) { ; }
|
||||||
|
|||||||
Reference in New Issue
Block a user