Generic protocol cleanup (work in progress)
This commit is contained in:
+7
-7
@@ -42,9 +42,9 @@ typedef char AC_ALPHABET_t;
|
||||
* automata for further reference. we provisioned two possible types as a
|
||||
* union for this purpose. you can add your desired type in it.
|
||||
**/
|
||||
typedef union {
|
||||
char * stringy; /* null-terminated string */
|
||||
unsigned long number;
|
||||
typedef struct {
|
||||
int number;
|
||||
u_int16_t category, breed;
|
||||
} AC_REP_t;
|
||||
|
||||
/* AC_PATTERN_t:
|
||||
@@ -112,20 +112,20 @@ typedef enum
|
||||
ac_automata_finalize() you can not add new patterns to the automata. */
|
||||
} AC_ERROR_t;
|
||||
|
||||
/* MATCH_CALBACK_t:
|
||||
/* MATCH_CALLBACK_t:
|
||||
* This is the call-back function type that must be given to automata at
|
||||
* initialization to report match occurrence to the caller.
|
||||
* at a match event, the automata will reach you using this function and sends
|
||||
* you a pointer to AC_MATCH_t. using that pointer you can handle
|
||||
* matches. you can send parameters to the call-back function when you call
|
||||
* ac_automata_search(). at call-back, the automata will sent you those
|
||||
* parameters as the second parameter (void *) of MATCH_CALBACK_t. inside
|
||||
* parameters as the second parameter (void *) of MATCH_CALLBACK_t. inside
|
||||
* the call-back function you can cast it to whatever you want.
|
||||
* If you return 0 from MATCH_CALBACK_t function to the automata, it will
|
||||
* If you return 0 from MATCH_CALLBACK_t function to the automata, it will
|
||||
* continue searching, otherwise it will return from ac_automata_search()
|
||||
* to your calling function.
|
||||
**/
|
||||
typedef int (*MATCH_CALBACK_f)(AC_MATCH_t *, AC_TEXT_t *, void *);
|
||||
typedef int (*MATCH_CALLBACK_f)(AC_MATCH_t *, AC_TEXT_t *, AC_REP_t *);
|
||||
|
||||
/* AC_PATTRN_MAX_LENGTH:
|
||||
* Maximum acceptable pattern length in AC_PATTERN_t.length
|
||||
|
||||
+3
-3
@@ -36,7 +36,7 @@ typedef struct
|
||||
unsigned int all_nodes_max; /* Current max allocated memory for *all_nodes */
|
||||
|
||||
AC_MATCH_t match; /* Any match is reported with this */
|
||||
MATCH_CALBACK_f match_callback; /* Match call-back function */
|
||||
MATCH_CALLBACK_f match_callback; /* Match call-back function */
|
||||
|
||||
/* this flag indicates that if automata is finalized by
|
||||
* ac_automata_finalize() or not. 1 means finalized and 0
|
||||
@@ -58,10 +58,10 @@ typedef struct
|
||||
} AC_AUTOMATA_t;
|
||||
|
||||
|
||||
AC_AUTOMATA_t * ac_automata_init (MATCH_CALBACK_f mc);
|
||||
AC_AUTOMATA_t * ac_automata_init (MATCH_CALLBACK_f mc);
|
||||
AC_ERROR_t ac_automata_add (AC_AUTOMATA_t * thiz, AC_PATTERN_t * str);
|
||||
void ac_automata_finalize (AC_AUTOMATA_t * thiz);
|
||||
int ac_automata_search (AC_AUTOMATA_t * thiz, AC_TEXT_t * str, void * param);
|
||||
int ac_automata_search (AC_AUTOMATA_t * thiz, AC_TEXT_t * str, AC_REP_t * param);
|
||||
void ac_automata_reset (AC_AUTOMATA_t * thiz);
|
||||
void ac_automata_release (AC_AUTOMATA_t * thiz);
|
||||
void ac_automata_display (AC_AUTOMATA_t * thiz, char repcast);
|
||||
|
||||
+8
-8
@@ -44,10 +44,10 @@ static void ac_automata_traverse_setfailure
|
||||
* FUNCTION: ac_automata_init
|
||||
* Initialize automata; allocate memories and set initial values
|
||||
* PARAMS:
|
||||
* MATCH_CALBACK mc: call-back function
|
||||
* MATCH_CALLBACK mc: call-back function
|
||||
* the call-back function will be used to reach the caller on match occurrence
|
||||
******************************************************************************/
|
||||
AC_AUTOMATA_t * ac_automata_init (MATCH_CALBACK_f mc)
|
||||
AC_AUTOMATA_t * ac_automata_init (MATCH_CALLBACK_f mc)
|
||||
{
|
||||
AC_AUTOMATA_t * thiz = (AC_AUTOMATA_t *)ndpi_malloc(sizeof(AC_AUTOMATA_t));
|
||||
memset (thiz, 0, sizeof(AC_AUTOMATA_t));
|
||||
@@ -159,7 +159,7 @@ void ac_automata_finalize (AC_AUTOMATA_t * thiz)
|
||||
* 0: success; continue searching; call-back sent me a 0 value
|
||||
* 1: success; stop searching; call-back sent me a non-0 value
|
||||
******************************************************************************/
|
||||
int ac_automata_search (AC_AUTOMATA_t * thiz, AC_TEXT_t * txt, void * param)
|
||||
int ac_automata_search (AC_AUTOMATA_t * thiz, AC_TEXT_t * txt, AC_REP_t * param)
|
||||
{
|
||||
unsigned long position;
|
||||
AC_NODE_t *curr;
|
||||
@@ -283,10 +283,10 @@ void ac_automata_display (AC_AUTOMATA_t * thiz, char repcast)
|
||||
switch (repcast)
|
||||
{
|
||||
case 'n':
|
||||
printf("%ld", sid.rep.number);
|
||||
break;
|
||||
case 's':
|
||||
printf("%s", sid.rep.stringy);
|
||||
printf("%u/%u/%u",
|
||||
sid.rep.number,
|
||||
sid.rep.category,
|
||||
sid.rep.breed);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -304,7 +304,7 @@ static void ac_automata_register_nodeptr (AC_AUTOMATA_t * thiz, AC_NODE_t * node
|
||||
{
|
||||
if(thiz->all_nodes_num >= thiz->all_nodes_max)
|
||||
{
|
||||
thiz->all_nodes = ndpi_realloc(thiz->all_nodes,
|
||||
thiz->all_nodes = ndpi_realloc(thiz->all_nodes,
|
||||
thiz->all_nodes_max*sizeof(AC_NODE_t *),
|
||||
(REALLOC_CHUNK_ALLNODES+thiz->all_nodes_max)*sizeof(AC_NODE_t *)
|
||||
);
|
||||
|
||||
Vendored
+1
-1
@@ -192,7 +192,7 @@ void node_register_matchstr (AC_NODE_t * thiz, AC_PATTERN_t * str)
|
||||
|
||||
thiz->matched_patterns[thiz->matched_patterns_num].astring = str->astring;
|
||||
thiz->matched_patterns[thiz->matched_patterns_num].length = str->length;
|
||||
thiz->matched_patterns[thiz->matched_patterns_num].rep = str->rep;
|
||||
memcpy(&thiz->matched_patterns[thiz->matched_patterns_num].rep, &str->rep, sizeof(AC_REP_t));
|
||||
thiz->matched_patterns_num++;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user