diff --git a/src/entry/json2iris.cpp b/src/entry/json2iris.cpp index 29a538a..4c1d954 100644 --- a/src/entry/json2iris.cpp +++ b/src/entry/json2iris.cpp @@ -695,8 +695,12 @@ int write_compile_rule(cJSON *compile,struct iris_description_t *p_iris,void * l { int compile_id=-1,cmd_cnt=0,ret=-1; cJSON* item=NULL; + struct iris_table_t* table_info=NULL; + struct traslate_command_t compile_cmd[MAX_COLUMN_NUM]; memset(compile_cmd,0,sizeof(compile_cmd)); + + compile_cmd[cmd_cnt].json_string="compile_id"; compile_cmd[cmd_cnt].json_type=cJSON_Number; cmd_cnt++; @@ -733,16 +737,25 @@ int write_compile_rule(cJSON *compile,struct iris_description_t *p_iris,void * l compile_cmd[cmd_cnt].str2int_flag=1; cmd_cnt++; - - if(p_iris->compile_table.line_count==0) + item=cJSON_GetObjectItem(compile,"table_name"); + if(item==NULL||item->type!=cJSON_String) { - ret=set_file_rulenum(p_iris->compile_table.table_path, 0,logger); + table_info=&(p_iris->compile_table); + } + else + { + table_info=query_table_info(p_iris,item->valuestring); + } + + if(table_info->line_count==0) + { + ret=set_file_rulenum(table_info->table_path, 0,logger); if(ret<0) { return -1; } } - ret=direct_write_rule(compile, p_iris->str2int_map,compile_cmd,cmd_cnt, p_iris->compile_table.table_path,logger); + ret=direct_write_rule(compile, p_iris->str2int_map,compile_cmd,cmd_cnt, table_info->table_path,logger); if(ret<0) { return -1; @@ -755,8 +768,8 @@ int write_compile_rule(cJSON *compile,struct iris_description_t *p_iris,void * l return -1; } compile_id=item->valueint; - p_iris->compile_table.line_count++; - set_file_rulenum(p_iris->compile_table.table_path,p_iris->compile_table.line_count,logger); + table_info->line_count++; + set_file_rulenum(table_info->table_path,table_info->line_count,logger); return compile_id; } int write_group_rule(int compile_id ,int group_id,struct iris_description_t *p_iris,void * logger) @@ -1000,14 +1013,15 @@ int json2iris(const char* json_file,const char*compile_tn,const char* group_tn,r MESA_handle_runtime_log(logger,RLOG_LV_FATAL,maat_json,"Error before: %-200.200s",cJSON_GetErrorPtr()); goto error_out; } - if(compile_tn==NULL) + tmp_obj=cJSON_GetObjectItem(json,"compile_table"); + if(tmp_obj) { - tmp_obj=cJSON_GetObjectItem(json,"compile_table"); compile_tn=tmp_obj->valuestring; } - if(group_tn==NULL) + + tmp_obj=cJSON_GetObjectItem(json,"group_table"); + if(tmp_obj) { - tmp_obj=cJSON_GetObjectItem(json,"group_table"); group_tn=tmp_obj->valuestring; } ret=set_iris_descriptor(json_file,json,compile_tn,group_tn,redis_write_ctx,&iris_cfg,logger); diff --git a/test/maat_json.json b/test/maat_json.json index 64d80e6..9819f97 100644 --- a/test/maat_json.json +++ b/test/maat_json.json @@ -4,6 +4,7 @@ "rules": [ { "compile_id": 123, + "table_name": "COMPILE_ALIAS", "service": 1, "action": 1, "do_blacklist": 1, diff --git a/test/right_result.txt b/test/right_result.txt deleted file mode 100644 index d42d57d..0000000 --- a/test/right_result.txt +++ /dev/null @@ -1,35 +0,0 @@ -Load entry id 101 SUCCESS. -hit 1 rules -ipv4 scan hit compile rule id 123. -hit current region,but not hit compile rule. -ipv6 scan hit region. -digest scan hit 127. -digest scan hit 127. -digest scan hit 127. -digest scan hit 127. -digest scan hit 127. -digest scan hit 127. -Hit expr_plus rule 128. -URL encode scan utf8 url hit 1 rules, hit ruleid=129 -URL encode scan gb2312 url hit 1 rules, hit ruleid=129 -test_unicode_esc processing ./testdata_uni2ascii/original_Uygur_webpage.html -UNI2ASCII file ./testdata_uni2ascii/original_Uygur_webpage.html,hit 2 rules, hit ruleid=130 131 -UNI2ASCII file ./testdata_uni2ascii/original_Uygur_webpage.html,hit 1 rules, hit ruleid=131 -UNI2ASCII file ./testdata_uni2ascii/original_Uygur_webpage.html,hit 1 rules, hit ruleid=131 -UNI2ASCII file ./testdata_uni2ascii/original_Uygur_webpage.html,hit 1 rules, hit ruleid=131 -UNI2ASCII file ./testdata_uni2ascii/original_Uygur_webpage.html,hit 1 rules, hit ruleid=131 -UNI2ASCII file ./testdata_uni2ascii/original_Uygur_webpage.html,hit 1 rules, hit ruleid=131 -UNI2ASCII file ./testdata_uni2ascii/original_Uygur_webpage.html,hit 1 rules, hit ruleid=131 -UNI2ASCII file ./testdata_uni2ascii/original_Uygur_webpage.html,hit 1 rules, hit ruleid=131 -UNI2ASCII file ./testdata_uni2ascii/original_Uygur_webpage.html,hit 1 rules, hit ruleid=131 -UNI2ASCII file ./testdata_uni2ascii/original_Uygur_webpage.html,hit 1 rules, hit ruleid=131 -test_unicode_esc processing ./testdata_uni2ascii/original_uy.txt -UNI2ASCII file ./testdata_uni2ascii/original_uy.txt,hit 2 rules, hit ruleid=130 131 -test_unicode_esc processing ./testdata_uni2ascii/qq_mail_https.txt -UNI2ASCII file ./testdata_uni2ascii/qq_mail_https.txt,hit 2 rules, hit ruleid=130 131 -UNI2ASCII file ./testdata_uni2ascii/qq_mail_https.txt,hit 1 rules, hit ruleid=130 -test_unicode_esc processing ./testdata_uni2ascii/sina_read_mail.txt -UNI2ASCII file ./testdata_uni2ascii/sina_read_mail.txt,hit 2 rules, hit ruleid=130 131 -test_unicode_esc processing ./testdata_uni2ascii/sohu_mail_unicode.txt -UNI2ASCII file ./testdata_uni2ascii/sohu_mail_unicode.txt,hit 2 rules, hit ruleid=130 131 -UNI2ASCII file ./testdata_uni2ascii/sohu_mail_unicode.txt,hit 2 rules, hit ruleid=130 131 diff --git a/test/table_info.conf b/test/table_info.conf index e467830..a920f3c 100644 --- a/test/table_info.conf +++ b/test/table_info.conf @@ -28,4 +28,5 @@ 9 SIM_URL similar -- 10 IMAGE_FP expr UTF8 UTF8 yes 128 quickoff 11 TEST_EFFECTIVE_RANGE_TABLE plugin {"valid":4,"tag":5} -- -12 TEST_FOREIGN_KEY plugin {"valid":4,"foreign":"6,8","tag":3} -- \ No newline at end of file +12 TEST_FOREIGN_KEY plugin {"valid":4,"foreign":"6,8","tag":3} -- +13 COMPILE_ALIAS compile escape --