aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLuca Deri <deri@ntop.org>2017-05-01 21:20:43 +0200
committerLuca Deri <deri@ntop.org>2017-05-01 21:20:43 +0200
commit205b82f6ba0018f2b7620a0558bfd78723fc2a2d (patch)
tree0447dc8f5a8353ce075ef136362290db8ec923eb /src
parent806fae659617765de84a96161465342c06aad002 (diff)
Added new API calls
- ndpi_add_string_value_to_automa - ndpi_match_string_id
Diffstat (limited to 'src')
-rw-r--r--src/include/ndpi_api.h24
-rw-r--r--src/lib/ndpi_main.c27
2 files changed, 49 insertions, 2 deletions
diff --git a/src/include/ndpi_api.h b/src/include/ndpi_api.h
index bcc5fe51f..b2c6b6952 100644
--- a/src/include/ndpi_api.h
+++ b/src/include/ndpi_api.h
@@ -566,6 +566,18 @@ extern "C" {
*
* @par The automata initialized with ndpi_init_automa();
* @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.
*
*/
@@ -592,6 +604,18 @@ extern "C" {
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 */
void set_ndpi_malloc(void* (*__ndpi_malloc)(size_t size));
void set_ndpi_free(void (*__ndpi_free)(void *ptr));
diff --git a/src/lib/ndpi_main.c b/src/lib/ndpi_main.c
index 0c5c0f0ff..8783ef6cd 100644
--- a/src/lib/ndpi_main.c
+++ b/src/lib/ndpi_main.c
@@ -1858,18 +1858,22 @@ void* ndpi_init_automa(void) {
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_AUTOMATA_t *automa = (AC_AUTOMATA_t*)_automa;
if(automa == NULL) return(-1);
ac_pattern.astring = str;
- ac_pattern.rep.number = 1; /* Dummy */
+ ac_pattern.rep.number = num;
ac_pattern.length = strlen(ac_pattern.astring);
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_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);
}
+/* ****************************************************** */
+
+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) { ; }