aboutsummaryrefslogtreecommitdiff
path: root/src/lib/ndpi_main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/ndpi_main.c')
-rw-r--r--src/lib/ndpi_main.c47
1 files changed, 45 insertions, 2 deletions
diff --git a/src/lib/ndpi_main.c b/src/lib/ndpi_main.c
index 9e8c75c8f..dcc5d8705 100644
--- a/src/lib/ndpi_main.c
+++ b/src/lib/ndpi_main.c
@@ -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) { ; }
/* ****************************************************** */