支持128字节以上的用户自定义域,单个编译配置总长度不超过16kb,通过Maat_read_rule获取。

This commit is contained in:
zhengchao
2018-07-05 18:39:15 +08:00
parent 6fdeebb2da
commit f07c810d2c
6 changed files with 58 additions and 8 deletions

View File

@@ -56,7 +56,7 @@ struct Maat_rule_t
char do_log;
char do_blacklist;
char action;
char resevered;
char reserved;
int serv_def_len;
char service_defined[MAX_SERVICE_DEFINE_LEN];
};
@@ -234,6 +234,10 @@ int Maat_similar_scan_string(Maat_feather_t feather,int table_id
,scan_status_t* mid,int thread_num);
void Maat_clean_status(scan_status_t* mid);
enum MAAT_RULE_OPT
{
MAAT_RULE_SERV_DEFINE
};
int Maat_read_rule(Maat_feather_t feather, const struct Maat_rule_t* rule, enum MAAT_RULE_OPT type, void* value, int size);
#endif // H_MAAT_RULE_H_INCLUDE

View File

@@ -169,7 +169,8 @@ int region_compile(_Maat_feather_t*feather,struct _INNER_scan_status_t *_mid,int
memcpy(&(result[result_cnt]),&(_mi_rule->db_c_rule->m_rule_head),sizeof(struct _head_Maat_rule_t));
memcpy(result[result_cnt].service_defined
,_mi_rule->db_c_rule->service_defined
,_mi_rule->db_c_rule->m_rule_head.serv_def_len);
,MIN(_mi_rule->db_c_rule->m_rule_head.serv_def_len,MAX_SERVICE_DEFINE_LEN));
rs_result[result_cnt].compile_id=_mi_rule->compile_id;
result_cnt++;
}
@@ -1749,6 +1750,32 @@ void Maat_stream_scan_digest_end(stream_para_t* stream_para)
return;
}
int Maat_read_rule(Maat_feather_t feather, const struct Maat_rule_t* rule, enum MAAT_RULE_OPT type, void* value, int size)
{
int ret=0;
struct _Maat_feather_t *_feather=(struct _Maat_feather_t *)feather;
struct _Maat_compile_inner_t *compile_inner=NULL;
switch(type)
{
case MAAT_RULE_SERV_DEFINE:
compile_inner=(struct _Maat_compile_inner_t *)HASH_fetch_by_id(_feather->scanner->compile_hash, rule->config_id);
pthread_rwlock_rdlock(&(compile_inner->rwlock));
if(compile_inner==NULL)
{
ret=0;
}
else
{
ret=MIN(size,compile_inner->db_c_rule->m_rule_head.serv_def_len);
memcpy(value,compile_inner->db_c_rule->service_defined,ret);
}
pthread_rwlock_unlock(&(compile_inner->rwlock));
break;
default:
ret=-1;
}
return ret;
}
int Maat_set_scan_status(Maat_feather_t feather,scan_status_t* mid,enum MAAT_SCAN_OPT type,const void* value,int size)
{
struct _Maat_feather_t* _feather=(_Maat_feather_t*)feather;

View File

@@ -783,6 +783,8 @@ int reconstruct_cmd(struct _Maat_feather_t *feather, struct _Maat_cmd_inner_t* _
return -1;
}
compile_inner=(struct _Maat_compile_inner_t *)HASH_fetch_by_id(feather->scanner->compile_hash, config_id);
//Operation on compile_inner is thread safe, no immediate memory free when delete a compile rule or a scanner.
//In another words, if the compile_inner is accessable from compile means, its was valid in at least 10 seconds (garbage bury).
if(compile_inner==NULL)
{
MESA_handle_runtime_log(logger,RLOG_LV_INFO,maat_command
@@ -790,6 +792,7 @@ int reconstruct_cmd(struct _Maat_feather_t *feather, struct _Maat_cmd_inner_t* _
,config_id);
return -1;
}
pthread_rwlock_rdlock(&(compile_inner->rwlock));
cmd->group_num=compile_inner->group_cnt;
assert(cmd->groups==NULL);
cmd->groups=(struct Maat_group_t*)calloc(sizeof(struct Maat_group_t),cmd->group_num);
@@ -824,6 +827,7 @@ int reconstruct_cmd(struct _Maat_feather_t *feather, struct _Maat_cmd_inner_t* _
}
grp_idx++;
}
pthread_rwlock_unlock(&(compile_inner->rwlock));
return 0;
}

View File

@@ -30,7 +30,7 @@
#include "stream_fuzzy_hash.h"
#include "gram_index_engine.h"
int MAAT_FRAME_VERSION_2_2_20180617=1;
int MAAT_FRAME_VERSION_2_2_20180705=1;
const char* CHARSET_STRING[]={"NONE","gbk","big5","unicode","utf8","bin",
"unicode_ascii_esc","unicode_ascii_aligned","unicode_ncr_dec","unicode_ncr_hex","url_encode_gb2312","url_encode_utf8",""};
@@ -2654,7 +2654,7 @@ void update_compile_rule(struct _Maat_table_info_t* table,const char* table_line
,user_region
,&(p_compile->is_valid)
,&(p_compile->declare_grp_num));
if((ret!=8&&ret!=9)||strlen(user_region)>MAX_SERVICE_DEFINE_LEN||p_compile->declare_grp_num>MAAT_MAX_EXPR_ITEM_NUM)
if((ret!=8&&ret!=9)||p_compile->declare_grp_num>MAAT_MAX_EXPR_ITEM_NUM)
{
MESA_handle_runtime_log(logger,RLOG_LV_FATAL,maat_module ,
"update error,invalid format of compile table %s:%s"
@@ -2664,7 +2664,6 @@ void update_compile_rule(struct _Maat_table_info_t* table,const char* table_line
table->udpate_err_cnt++;
return;
}
p_m_rule->serv_def_len=strlen(user_region)+1;
p_compile->service_defined=(char*)malloc(p_m_rule->serv_def_len*sizeof(char));
memcpy(p_compile->service_defined,user_region,p_m_rule->serv_def_len);

File diff suppressed because one or more lines are too long

View File

@@ -543,7 +543,22 @@ void test_offset_str_scan(Maat_feather_t feather,const char* table_name)
test_offset_str_scan_with_chunk(feather,table_name,1460);
return;
}
void test_longer_service_define(Maat_feather_t feather, struct Maat_rule_t* rule)
{
int ret=0;
char* buff=(char*)malloc(sizeof(char)*rule->serv_def_len);
ret=Maat_read_rule(feather, rule,MAAT_RULE_SERV_DEFINE, buff, rule->serv_def_len);
if(ret==rule->serv_def_len)
{
printf("Test read longer service define Success.\n");
}
else
{
printf("Test read longer service define Failed.\n");
}
assert(ret==rule->serv_def_len);
free(buff);
}
int test_table_conjunction(Maat_feather_t feather,const char* table_name,const char* conj_table_name,scan_status_t* mid)
{
int ret=0;
@@ -566,6 +581,7 @@ int test_table_conjunction(Maat_feather_t feather,const char* table_name,const c
if(ret>=2)
{
printf("Table conjunction success %s\n",print_maat_result(result,ret));
test_longer_service_define(feather, result);
}
return 0;
}