diff --git a/src/entry/Maat_rule.cpp b/src/entry/Maat_rule.cpp index 3124cce..efadc00 100644 --- a/src/entry/Maat_rule.cpp +++ b/src/entry/Maat_rule.cpp @@ -523,26 +523,6 @@ error_out: return ret; } -void * HASH_fetch_by_id(MESA_htable_handle hash,int id) -{ - return MESA_htable_search(hash,(unsigned char*)&(id),sizeof(id)); -} -int HASH_add_by_id(MESA_htable_handle hash,int id,void*data) -{ - int ret=0; - ret=MESA_htable_add(hash - ,(unsigned char*)&(id) - ,sizeof(id) - ,data); - return ret; -} -int HASH_delete_by_id(MESA_htable_handle hash,int id) -{ - //destroy function had been initialized when hash create. - int ret=-1; - ret=MESA_htable_del(hash,(unsigned char*)&id, sizeof(id), NULL); - return ret; -} MAAT_RULE_EX_DATA rule_ex_data_new(const struct Maat_rule_head * rule_head, const char* srv_def, const struct compile_ex_data_idx* ex_desc) { MAAT_RULE_EX_DATA ad=NULL; diff --git a/src/entry/hyperscan_adapter.cpp b/src/entry/hyperscan_adapter.cpp index 007b7f3..8fc03fc 100644 --- a/src/entry/hyperscan_adapter.cpp +++ b/src/entry/hyperscan_adapter.cpp @@ -1,5 +1,6 @@ #include #include +#include struct hs_adapter { hs_database_t *hs_pure_literal_db; @@ -7,11 +8,51 @@ struct hs_adapter struct bool_matcher *logical_matcher; int mode; int n_thread; + size_t regex_cnt; + size_t regex_sub_pattern_cnt; + size_t pure_lit_cnt; + size_t pure_lit_sub_pattern_cnt; + void **user_tag_array; hs_scratch_t *scratchs[]; }; - struct hs_adapter *hs_adapter_new(struct hs_expression ** exprs, size_t n_expr, int scan_mode, int n_thread) { + struct hs_adapter *hsa=ALLOC(struct hs_adapter, 1); + size_t i=0, j=0; + unsigned int *hs_ids=NULL; + for(i=0; iregex_cnt++; + hsa->regex_sub_pattern_cnt=exprs[i].n_sub_pattern; + } + else + { + hsa->pure_lit_cnt++; + hsa->pure_lit_sub_pattern_cnt++; + } + } + const char **regex_exprs=NULL, **pure_lit_exprs=NULL; + if(hsa->regex_sub_pattern_cnt>0) + { + regex_exprs=ALLOC(char *, hsa->regex_sub_pattern_cnt); + } + if(hsa->pure_lit_sub_pattern_cnt>0) + { + pure_lit_exprs=ALLOC(char *, hsa->pure_lit_sub_pattern_cnt) + } + size_t sub_pure_lit_idx=0, sub_regex_idx=0; + for(i=0; in_sub_pattern; j++) + { + regex_exprs[j]=exprs[i]. + } + sub_pure_lit_idx + + } + struct bool_expr *bool_exprs=ALLOC(struct bool_expr, 1); } void hs_adpter_free(struct hs_adapter *adapter) { @@ -20,3 +61,7 @@ void hs_adpter_free(struct hs_adapter *adapter) int hs_adapter_scan(struct hs_adapter *adapter, int thread_id, const char* data, unsigned int length, void **matched_tags, size_t n_tag) { } +int hs_adapter_open_stream(struct hs_adapter *adapter, int thread_id) +{ + +} \ No newline at end of file diff --git a/src/inc_internal/hyperscan_adapter.h b/src/inc_internal/hyperscan_adapter.h index 9aadd53..c2fef40 100644 --- a/src/inc_internal/hyperscan_adapter.h +++ b/src/inc_internal/hyperscan_adapter.h @@ -16,14 +16,23 @@ struct hs_pattern struct hs_expression { - void *user_tag; - enum MAAT_EXPR_TYPE type; - size_t n_sub_pattern; + void * user_tag; + int is_regex; //if is_regex==1, then n_sub_pattern must be 1 + size_t n_sub_pattern; //must not exceed HSA_MAX_SUB_STRING_NUM struct hs_pattern sub_patterns[]; }; + struct hs_adapter; +#define HSA_SCAN_MODE_BLOCK 0 +#define HSA_SCAN_MODE_STREAM 1 +/** + * @param scan_mode + * HSA_SCAN_MODE_BLOCK or HSA_SCAN_MODE_STREAM + * @param exprs + * Expressions to match, it's life time must be longger than the hs_adapter. +*/ struct hs_adapter *hs_adapter_new(const struct hs_expression ** exprs, size_t n_expr, int scan_mode, int n_thread); -void hs_adpter_free(struct hs_adapter *adapter); +void hs_adapter_free(struct hs_adapter *adapter); int hs_adapter_scan(struct hs_adapter *adapter, int thread_id, const char* data, unsigned int length, void **matched_tags, size_t n_tag);