Generic protocol cleanup (work in progress)

This commit is contained in:
Luca Deri
2018-08-16 12:03:09 +02:00
parent 70eb619b86
commit 9847c2ccbb
7 changed files with 115 additions and 71 deletions
+7 -7
View File
@@ -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
View File
@@ -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);