改进conjunction功能的错误日志,增加测试用例,自测通过。

This commit is contained in:
zhengchao
2016-08-30 11:08:32 +08:00
parent 86832693d6
commit 5e2a23568b
5 changed files with 89 additions and 6 deletions

View File

@@ -426,7 +426,7 @@ Maat_feather_t Maat_feather(int max_thread_num,const char* table_info_path,void*
{ {
feather->GROUP_MODE_ON=1; feather->GROUP_MODE_ON=1;
} }
for(j=0;j<feather->p_table_info[i].conj_cnt;j++) for(j=0;j<feather->p_table_info[i]->conj_cnt;j++)
{ {
ret=map_register(feather->map_tablename2id,feather->p_table_info[i]->table_name[j],feather->p_table_info[i]->table_id); ret=map_register(feather->map_tablename2id,feather->p_table_info[i]->table_name[j],feather->p_table_info[i]->table_id);
if(ret<0) if(ret<0)

View File

@@ -552,7 +552,7 @@ int read_table_info(struct _Maat_table_info_t** p_table_info,int num,const char*
} }
if(p->table_id>=num) if(p->table_id>=num)
{ {
fprintf(stderr,"Maat read table info %s line %d error: table id %uh > %d.\n",table_info_path,i,p->table_id,num); fprintf(stderr,"Maat read table info %s:%d error: table id %uh > %d.\n",table_info_path,i,p->table_id,num);
MESA_handle_runtime_log(logger, RLOG_LV_FATAL,maat_module, MESA_handle_runtime_log(logger, RLOG_LV_FATAL,maat_module,
"Maat read table info %s line %d error: table id %uh > %d.\n",table_info_path,i,p->table_id,num); "Maat read table info %s line %d error: table id %uh > %d.\n",table_info_path,i,p->table_id,num);
@@ -571,7 +571,7 @@ int read_table_info(struct _Maat_table_info_t** p_table_info,int num,const char*
memcpy(conj_table->table_name[conj_table->conj_cnt],p->table_name[0],MAX_TABLE_NAME_LEN); memcpy(conj_table->table_name[conj_table->conj_cnt],p->table_name[0],MAX_TABLE_NAME_LEN);
conj_table->conj_cnt++; conj_table->conj_cnt++;
MESA_handle_runtime_log(logger, RLOG_LV_INFO,maat_module, MESA_handle_runtime_log(logger, RLOG_LV_INFO,maat_module,
"Maat read table info %s line %d error:conjunction %s with %s (id=%d,total=%d).\n" "Maat read table info %s:%d:conjunction %s with %s (id=%d,total=%d).\n"
,table_info_path,i,p->table_name[0] ,table_info_path,i,p->table_name[0]
,conj_table->table_name[0],conj_table->table_id,conj_table->conj_cnt); ,conj_table->table_name[0],conj_table->table_id,conj_table->conj_cnt);
//use goto to free the conjunctioned table_info //use goto to free the conjunctioned table_info
@@ -2687,12 +2687,12 @@ void maat_update_cb(const char* table_name,const char* line,void *u_para)
p_table=feather->p_table_info[table_id]; p_table=feather->p_table_info[table_id];
for(i=0;i<p_table->conj_cnt;i++) for(i=0;i<p_table->conj_cnt;i++)
{ {
if(0==memcmp(p_table->table_name[i],table_name,strlen(table_name)) if(0==memcmp(p_table->table_name[i],table_name,strlen(table_name)))
{ {
p_table->updating_name=i; p_table->updating_name=i;
} }
} }
assert(i<p_table->conj_cnt); assert(i<=p_table->conj_cnt);
switch(feather->p_table_info[table_id]->table_type) switch(feather->p_table_info[table_id]->table_type)
{ {

View File

@@ -28,7 +28,7 @@ void maat_stat_init(struct _Maat_feather_t* feather)
int value=0; int value=0;
int i=0,j=0,offset=0; int i=0,j=0,offset=0;
struct _Maat_table_info_t* p_table=NULL; struct _Maat_table_info_t* p_table=NULL;
char conj_table_name[(MAX_TABLE_NAME_LEN+1)*MAX_CONJUNCTION_TABLE_NUM]={0} char conj_table_name[(MAX_TABLE_NAME_LEN+1)*MAX_CONJUNCTION_TABLE_NUM]={0};
feather->stat_handle=FS_create_handle(); feather->stat_handle=FS_create_handle();
FS_set_para(feather->stat_handle, OUTPUT_DEVICE, feather->stat_file, strlen(feather->stat_file)+1); FS_set_para(feather->stat_handle, OUTPUT_DEVICE, feather->stat_file, strlen(feather->stat_file)+1);

View File

@@ -324,6 +324,61 @@
] ]
} }
] ]
},
{
"compile_id": 133,
"service": 1,
"action": 1,
"do_blacklist": 1,
"do_log": 1,
"effective_rage": 0,
"user_region": "table_conjunction_test_part1",
"is_valid": "yes",
"groups": [
{
"group_name": "group_13",
"regions": [
{
"table_name": "HTTP_HOST",
"table_type": "string",
"table_content": {
"keywords": "www.3300av.com",
"expr_type": "none",
"match_method": "sub",
"format": "uncase plain"
}
}
]
}
]
}
,
{
"compile_id": 134,
"service": 1,
"action": 1,
"do_blacklist": 1,
"do_log": 1,
"effective_rage": 0,
"user_region": "table_conjunction_test_part2",
"is_valid": "yes",
"groups": [
{
"group_name": "group_14",
"regions": [
{
"table_name": "HTTP_URL",
"table_type": "string",
"table_content": {
"keywords": "novel&27122.txt",
"expr_type": "and",
"match_method": "sub",
"format": "uncase plain"
}
}
]
}
]
} }
], ],
"plugin_table": [ "plugin_table": [

View File

@@ -431,6 +431,31 @@ int test_expr_plus(Maat_feather_t feather,const char* table_name,scan_status_t*
return ret; return ret;
} }
int test_table_conjunction(Maat_feather_t feather,const char* table_name,const char* conj_table_name,scan_status_t* mid)
{
int ret=0;
int table_id=0,conj_table_id=0;
struct Maat_rule_t result[4];
int found_pos[4];
const char* scan_data="soq is using table conjunction function.http://www.3300av.com/novel/27122.txt";
table_id=Maat_table_register(feather,table_name);
if(table_id==-1)
{
printf("Database table %s register failed.\n",table_name);
return -1;
}
conj_table_id=Maat_table_register(feather,conj_table_name);
assert(conj_table_id==table_id);
ret=Maat_full_scan_string(feather, conj_table_id,CHARSET_GBK, scan_data, strlen(scan_data),
result,found_pos, 4,
mid, 0);
if(ret>=2)
{
printf("Table conjunction success %s\n",print_maat_result(result,ret));
}
return 0;
}
int main(int argc,char* argv[]) int main(int argc,char* argv[])
{ {
Maat_feather_t feather=NULL; Maat_feather_t feather=NULL;
@@ -488,6 +513,9 @@ int main(int argc,char* argv[])
test_unescape_string_scan(feather,"KEYWORDS_TABLE",&mid); test_unescape_string_scan(feather,"KEYWORDS_TABLE",&mid);
Maat_clean_status(&mid); Maat_clean_status(&mid);
test_table_conjunction(feather, "HTTP_URL", "HTTP_HOST", &mid);
Maat_clean_status(&mid);
sleep(4); sleep(4);
Maat_burn_feather(feather); Maat_burn_feather(feather);