[PATCH]maat_state_get_hit_groups API obtain inc hit groups from multiple scans
This commit is contained in:
@@ -140,6 +140,7 @@ struct maat_internal_hit_path {
|
||||
struct maat_compile_state {
|
||||
uint8_t this_scan_hit_item_flag;
|
||||
uint8_t not_clause_hit_flag;
|
||||
uint8_t inc_hit_path_flag;
|
||||
int Nth_scan;
|
||||
time_t compile_rt_version;
|
||||
|
||||
@@ -1379,6 +1380,7 @@ void maat_compile_state_reset(struct maat_compile_state *compile_state)
|
||||
compile_state->compile_rt_version = 0;
|
||||
compile_state->this_scan_hit_item_flag = 0;
|
||||
compile_state->not_clause_hit_flag = 0;
|
||||
compile_state->inc_hit_path_flag = 0;
|
||||
|
||||
utarray_clear(compile_state->internal_hit_paths);
|
||||
utarray_clear(compile_state->internal_inc_hit_paths);
|
||||
@@ -1544,10 +1546,14 @@ static void maat_compile_state_update_hit_path(struct maat_compile_state *compil
|
||||
if (compile_state->Nth_scan != Nth_scan) {
|
||||
assert(compile_state->this_scan_hit_item_flag == 0);
|
||||
compile_state->Nth_scan = Nth_scan;
|
||||
utarray_clear(compile_state->internal_inc_hit_paths);
|
||||
utarray_clear(compile_state->this_scan_hit_clauses);
|
||||
}
|
||||
|
||||
if (1 == compile_state->inc_hit_path_flag) {
|
||||
compile_state->inc_hit_path_flag = 0;
|
||||
utarray_clear(compile_state->internal_inc_hit_paths);
|
||||
}
|
||||
|
||||
maat_compile_hit_path_add(compile_state->internal_inc_hit_paths, item_id, group_id,
|
||||
vtable_id, Nth_scan, Nth_item_result);
|
||||
|
||||
@@ -2128,6 +2134,7 @@ size_t maat_compile_state_get_hit_groups(struct maat_compile_state *compile_stat
|
||||
tmp_hit_path = compile_state->internal_hit_paths;
|
||||
} else if (type == MAAT_LIST_TYPE_INC) {
|
||||
tmp_hit_path = compile_state->internal_inc_hit_paths;
|
||||
compile_state->inc_hit_path_flag = 1;
|
||||
}
|
||||
|
||||
for (i = 0; i < utarray_len(tmp_hit_path); i++) {
|
||||
|
||||
@@ -6506,6 +6506,7 @@ TEST_F(MaatCmdTest, HitGroup) {
|
||||
EXPECT_EQ(hit_groups[1].group_id, group2_id);
|
||||
EXPECT_EQ(hit_groups[1].vtable_id, http_res_table_id);
|
||||
|
||||
|
||||
const char* keywords1="In graph theory, hit group item forth";
|
||||
const char *keywords2="To test one group hit group item fifth";
|
||||
|
||||
@@ -6541,13 +6542,6 @@ TEST_F(MaatCmdTest, HitGroup) {
|
||||
EXPECT_EQ(hit_groups[4].group_id, group4_id);
|
||||
EXPECT_EQ(hit_groups[4].vtable_id, 0); //physical table(keywords_table) vtable_id is 0
|
||||
|
||||
memset(hit_groups, 0, sizeof(hit_groups));
|
||||
n_hit_group = maat_state_get_hit_groups(state, MAAT_LIST_TYPE_INC, hit_groups, 128);
|
||||
EXPECT_EQ(n_hit_group, 1);
|
||||
EXPECT_EQ(hit_groups[0].item_id, item4_id);
|
||||
EXPECT_EQ(hit_groups[0].group_id, group4_id);
|
||||
EXPECT_EQ(hit_groups[0].vtable_id, 0); //physical table(keywords_table) vtable_id is 0
|
||||
|
||||
int ip_table_id = maat_get_table_id(maat_inst, ip_table_name);
|
||||
ASSERT_GT(ip_table_id, 0);
|
||||
|
||||
@@ -6588,11 +6582,15 @@ TEST_F(MaatCmdTest, HitGroup) {
|
||||
|
||||
memset(hit_groups, 0, sizeof(hit_groups));
|
||||
n_hit_group = maat_state_get_hit_groups(state, MAAT_LIST_TYPE_INC, hit_groups, 128);
|
||||
EXPECT_EQ(n_hit_group, 1);
|
||||
EXPECT_EQ(n_hit_group, 2);
|
||||
EXPECT_EQ(hit_groups[0].item_id, item3_id);
|
||||
EXPECT_EQ(hit_groups[0].group_id, group3_id);
|
||||
EXPECT_EQ(hit_groups[0].vtable_id, 0); //physical table(keywords_table) vtable_id is 0
|
||||
|
||||
EXPECT_EQ(hit_groups[1].item_id, item4_id);
|
||||
EXPECT_EQ(hit_groups[1].group_id, group4_id);
|
||||
EXPECT_EQ(hit_groups[1].vtable_id, 0);
|
||||
|
||||
ret = maat_stream_scan(stream, keywords2, strlen(keywords2), results, ARRAY_SIZE,
|
||||
&n_hit_result, state);
|
||||
EXPECT_EQ(ret, MAAT_SCAN_HALF_HIT);
|
||||
|
||||
Reference in New Issue
Block a user