From c8afc7b1d72e01e192a43901bfde2e76f6ffa81d Mon Sep 17 00:00:00 2001 From: zhengchao Date: Mon, 24 Dec 2018 19:00:16 +0600 Subject: [PATCH] =?UTF-8?q?#5=20=E5=A4=9A=E5=91=BD=E4=B8=AD=E6=83=85?= =?UTF-8?q?=E5=86=B5=E4=B8=8B=EF=BC=8C=E6=8C=89=E7=85=A7=E9=85=8D=E7=BD=AE?= =?UTF-8?q?ID=E7=94=B1=E5=A4=A7=E5=88=B0=E5=B0=8F=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E5=91=BD=E4=B8=AD=E7=BB=93=E6=9E=9C=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/entry/Maat_api.cpp | 9 +++++++++ test/test_maatframe.cpp | 41 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/src/entry/Maat_api.cpp b/src/entry/Maat_api.cpp index 43e217c..7927922 100644 --- a/src/entry/Maat_api.cpp +++ b/src/entry/Maat_api.cpp @@ -105,6 +105,13 @@ void fill_maat_rule(struct Maat_rule_t *rule, const struct _head_Maat_rule_t* ru memcpy(rule->service_defined, srv_def, MIN(srv_def_len,MAX_SERVICE_DEFINE_LEN)); return; } +static int compare_compile_id(const void *a, const void *b) +{ + struct Maat_rule_t *ra=(struct Maat_rule_t *)a; + struct Maat_rule_t *rb=(struct Maat_rule_t *)b; + + return (rb->config_id-ra->config_id); +} int region_compile(_Maat_feather_t*feather,struct _INNER_scan_status_t *_mid,int is_last_region,void* region_hit,int region_type_size,int group_offset,int region_hit_num,struct Maat_rule_t* result,_compile_result_t *rs_result, int size,int thread_num) { @@ -187,6 +194,8 @@ int region_compile(_Maat_feather_t*feather,struct _INNER_scan_status_t *_mid,int } if(result_cnt>0) { + qsort(result, result_cnt, sizeof(struct Maat_rule_t), + compare_compile_id); alignment_int64_array_add(feather->hit_cnt,thread_num,1); } return result_cnt; diff --git a/test/test_maatframe.cpp b/test/test_maatframe.cpp index 1dfe92d..6d516eb 100644 --- a/test/test_maatframe.cpp +++ b/test/test_maatframe.cpp @@ -1038,7 +1038,6 @@ int test_add_expr_command(Maat_feather_t feather,const char* region_table,int co int group_num=1,ret=0; memset(&rule,0,sizeof(rule)); rule.config_id=config_id; - strcpy(rule.service_defined,"maat_command"); //MUST acqire by function, because Maat_cmd_t has some hidden members. cmd=Maat_create_cmd(&rule, group_num); @@ -1301,6 +1300,46 @@ TEST_F(MaatCmdTest, RuleIDRecycle) EXPECT_EQ(result.config_id, rule_id); return; } +TEST_F(MaatCmdTest, ReturnRuleIDWithDescendingOrder) +{ + const char* table_name="HTTP_URL"; + const char* scan_data="This string will hit mulptiple rules."; + const char* keywords="string\\bwill\\bhit"; + Maat_feather_t feather=MaatCmdTest::_shared_feather; + + + int table_id=0; + table_id=Maat_table_register(feather,table_name); + ASSERT_GT(table_id, 0); + + int i=0, repeat_times=4; + struct Maat_rule_t result[8]; + int expect_ruleid[8]; + scan_status_t mid=NULL; + + int rule_id=(int)Maat_cmd_incrby(feather, "TEST_SEQ", repeat_times); + int label_id=5211, ret=0; + for(i=0; i=0); + usleep(WAIT_FOR_EFFECTIVE_US);//waiting for commands go into effect + ret=Maat_full_scan_string(feather, table_id,CHARSET_GBK, scan_data, strlen(scan_data), + result, NULL, 8, + &mid, 0); + Maat_clean_status(&mid); + EXPECT_EQ(ret, repeat_times); + for(i=0;i