diff --git a/include/maat.h b/include/maat.h index 07ae691..2e63251 100644 --- a/include/maat.h +++ b/include/maat.h @@ -283,7 +283,7 @@ int maat_scan_string(struct maat *instance, int table_id, size_t *n_hit_result, struct maat_state *state); int maat_scan_group(struct maat *instance, int table_id, - long long *group_ids, size_t n_group_id, + struct maat_hit_group *groups, size_t n_group, long long *results, size_t n_result, size_t *n_hit_result, struct maat_state *state); @@ -346,13 +346,13 @@ int maat_state_get_indirect_hit_groups(struct maat_state *state, size_t maat_state_get_indirect_hit_group_cnt(struct maat_state *state); /** - * @brief get last scan hit group id(including direct/indirect) + * @brief get last scan hit groups(including direct/indirect) */ -int maat_state_get_last_hit_group_ids(struct maat_state *state, - long long *group_id_array, - size_t array_size); +int maat_state_get_last_hit_groups(struct maat_state *state, + struct maat_hit_group *group_array, + size_t array_size); -size_t maat_state_get_last_hit_group_id_cnt(struct maat_state *state); +size_t maat_state_get_last_hit_group_cnt(struct maat_state *state); #ifdef __cplusplus } diff --git a/src/inc_internal/maat_compile.h b/src/inc_internal/maat_compile.h index aeec840..76b9a1a 100644 --- a/src/inc_internal/maat_compile.h +++ b/src/inc_internal/maat_compile.h @@ -119,11 +119,11 @@ size_t compile_state_get_indirect_hit_groups(struct compile_state *compile_state size_t compile_state_get_indirect_hit_group_cnt(struct compile_state *compile_state); -size_t compile_state_get_last_hit_group_id(struct compile_state *compile_state, - long long *group_id_arary, - size_t array_size); +size_t compile_state_get_last_hit_groups(struct compile_state *compile_state, + struct maat_hit_group *group_arary, + size_t array_size); -size_t compile_state_get_last_hit_group_id_cnt(struct compile_state *compile_state); +size_t compile_state_get_last_hit_group_cnt(struct compile_state *compile_state); int compile_state_get_compile_table_id(struct compile_state *compile_state, long long compile_id); diff --git a/src/inc_internal/maat_limits.h b/src/inc_internal/maat_limits.h index 2a6086e..628a46e 100644 --- a/src/inc_internal/maat_limits.h +++ b/src/inc_internal/maat_limits.h @@ -24,6 +24,7 @@ extern "C" #define MAX_INSTANCE_NAME_LEN 15 #define MAX_GROUP_IDS_STR_LEN 256 #define MAX_GROUP_CNT 128 +#define MAX_CONJ_PARENTS_NUM 16 #ifdef __cplusplus } diff --git a/src/maat_api.c b/src/maat_api.c index b322a38..313ac1a 100644 --- a/src/maat_api.c +++ b/src/maat_api.c @@ -1601,7 +1601,7 @@ int maat_scan_string(struct maat *maat_inst, int table_id, } static void maat_state_add_hit_group(struct maat_state *state, int table_id, - long long *group_ids, size_t n_group_id) + struct maat_hit_group *groups, size_t n_group) { struct maat *maat_inst = state->maat_inst; @@ -1611,15 +1611,15 @@ static void maat_state_add_hit_group(struct maat_state *state, int table_id, state->thread_id, 1); } - size_t n_hit_item = n_group_id; - if (n_group_id >= MAX_HIT_GROUP_NUM) { + size_t n_hit_item = n_group; + if (n_group >= MAX_HIT_GROUP_NUM) { n_hit_item = MAX_HIT_GROUP_NUM; } struct maat_item hit_items[n_hit_item]; for (size_t i = 0; i < n_hit_item; i++) { - hit_items[i].item_id = 0; - hit_items[i].group_id = group_ids[i]; + hit_items[i].item_id = groups[i].item_id; + hit_items[i].group_id = groups[i].group_id; } compile_state_update(state->compile_state, maat_inst, table_id, @@ -1650,12 +1650,12 @@ static void maat_state_activate_hit_not_group(struct maat_state *state, int tabl } int maat_scan_group(struct maat *maat_inst, int table_id, - long long *group_ids, size_t n_group_id, + struct maat_hit_group *groups, size_t n_group, long long *results, size_t n_result, size_t *n_hit_result, struct maat_state *state) { if ((NULL == maat_inst) || table_id < 0 || table_id >= MAX_TABLE_NUM || - (NULL == group_ids) || (0 == n_group_id) || (NULL == results) || + (NULL == groups) || (0 == n_group) || (NULL == results) || (0 == n_result) || (NULL == n_hit_result) || (NULL == state) || (state->thread_id < 0)) { return -1; @@ -1671,7 +1671,7 @@ int maat_scan_group(struct maat *maat_inst, int table_id, maat_runtime_ref_inc(maat_rt, state->thread_id); alignment_int64_array_add(maat_inst->stat->thread_call_cnt, state->thread_id, 1); - maat_state_add_hit_group(state, table_id, group_ids, n_group_id); + maat_state_add_hit_group(state, table_id, groups, n_group); size_t hit_compile_cnt = group_to_compile(maat_inst, results, n_result, state); *n_hit_result = hit_compile_cnt; @@ -2161,23 +2161,23 @@ size_t maat_state_get_indirect_hit_group_cnt(struct maat_state *state) return compile_state_get_indirect_hit_group_cnt(state->compile_state); } -int maat_state_get_last_hit_group_ids(struct maat_state *state, - long long *group_id_array, - size_t array_size) +int maat_state_get_last_hit_groups(struct maat_state *state, + struct maat_hit_group *group_array, + size_t array_size) { if (NULL == state || NULL == state->compile_state) { return 0; } - return compile_state_get_last_hit_group_id(state->compile_state, - group_id_array, array_size); + return compile_state_get_last_hit_groups(state->compile_state, + group_array, array_size); } -size_t maat_state_get_last_hit_group_id_cnt(struct maat_state *state) +size_t maat_state_get_last_hit_group_cnt(struct maat_state *state) { if (NULL == state || NULL == state->compile_state) { return 0; } - return compile_state_get_last_hit_group_id_cnt(state->compile_state); + return compile_state_get_last_hit_group_cnt(state->compile_state); } \ No newline at end of file diff --git a/src/maat_compile.c b/src/maat_compile.c index 03bde13..b88238b 100644 --- a/src/maat_compile.c +++ b/src/maat_compile.c @@ -175,7 +175,7 @@ struct compile_state { UT_array *exclude_not_clauses; UT_array *direct_hit_groups; UT_array *indirect_hit_groups; - UT_array *last_hit_group_ids; + UT_array *last_hit_groups; UT_array *hit_compile_table_ids; struct table_group *hit_not_tbl_groups; }; @@ -1404,7 +1404,7 @@ struct compile_state *compile_state_new(void) utarray_new(compile_state->exclude_not_clauses, &ut_clause_id_icd); utarray_new(compile_state->direct_hit_groups, &ut_maat_hit_group_icd); utarray_new(compile_state->indirect_hit_groups, &ut_maat_hit_group_icd); - utarray_new(compile_state->last_hit_group_ids, &ut_compile_group_id_icd); + utarray_new(compile_state->last_hit_groups, &ut_maat_hit_group_icd); utarray_new(compile_state->hit_compile_table_ids, &ut_hit_compile_table_id_icd); compile_state->hit_not_tbl_groups = NULL; @@ -1449,7 +1449,7 @@ void compile_state_reset(struct compile_state *compile_state) utarray_clear(compile_state->exclude_not_clauses); utarray_clear(compile_state->direct_hit_groups); utarray_clear(compile_state->indirect_hit_groups); - utarray_clear(compile_state->last_hit_group_ids); + utarray_clear(compile_state->last_hit_groups); utarray_clear(compile_state->hit_compile_table_ids); struct table_group *tbl_group = NULL, *tmp_tbl_group = NULL; @@ -1509,10 +1509,10 @@ void compile_state_free(struct compile_state *compile_state, compile_state->indirect_hit_groups = NULL; } - if (compile_state->last_hit_group_ids != NULL) { - free_bytes += utarray_size(compile_state->last_hit_group_ids) * sizeof(long long); - utarray_free(compile_state->last_hit_group_ids); - compile_state->last_hit_group_ids = NULL; + if (compile_state->last_hit_groups != NULL) { + free_bytes += utarray_size(compile_state->last_hit_groups) * sizeof(struct maat_hit_group); + utarray_free(compile_state->last_hit_groups); + compile_state->last_hit_groups = NULL; } if (compile_state->hit_compile_table_ids != NULL) { @@ -2415,15 +2415,20 @@ int compile_state_update(struct compile_state *compile_state, struct maat *maat_ size_t i = 0, j = 0; size_t hit_cnt = n_hit_item; long long hit_group_ids[MAX_HIT_GROUP_NUM]; + struct maat_hit_group hit_group; utarray_clear(compile_state->this_scan_hit_clauses); - utarray_clear(compile_state->last_hit_group_ids); + utarray_clear(compile_state->last_hit_groups); compile_state->this_scan_not_logic = 0; compile_state->Nth_scan = Nth_scan; for (i = 0; i < hit_cnt; i++) { hit_group_ids[i] = hit_items[i].group_id; - utarray_push_back(compile_state->last_hit_group_ids, &hit_items[i].group_id); + + hit_group.item_id = hit_items[i].item_id; + hit_group.group_id = hit_items[i].group_id; + hit_group.vtable_id = vtable_id; + utarray_push_back(compile_state->last_hit_groups, &hit_group); } int g2g_table_id = table_manager_get_group2group_table_id(maat_inst->tbl_mgr); @@ -2434,7 +2439,10 @@ int compile_state_update(struct compile_state *compile_state, struct maat *maat_ hit_cnt, super_group_ids, MAX_HIT_GROUP_NUM); for (i = 0; i < super_group_cnt; i++) { - utarray_push_back(compile_state->last_hit_group_ids, &super_group_ids[i]); + hit_group.item_id = 0; + hit_group.group_id = super_group_ids[i]; + hit_group.vtable_id = vtable_id; + utarray_push_back(compile_state->last_hit_groups, &hit_group); } if (1 == maat_inst->opts.hit_path_on && hit_cnt > 0) { @@ -2536,22 +2544,22 @@ size_t compile_state_get_indirect_hit_group_cnt(struct compile_state *compile_st return utarray_len(compile_state->indirect_hit_groups); } -size_t compile_state_get_last_hit_group_id(struct compile_state *compile_state, - long long *group_id_array, - size_t array_size) +size_t compile_state_get_last_hit_groups(struct compile_state *compile_state, + struct maat_hit_group *group_array, + size_t array_size) { size_t i = 0; - for (i = 0; i < utarray_len(compile_state->last_hit_group_ids) && i < array_size; i++) { - group_id_array[i] = *(long long *)utarray_eltptr(compile_state->last_hit_group_ids, i); + for (i = 0; i < utarray_len(compile_state->last_hit_groups) && i < array_size; i++) { + group_array[i] = *(struct maat_hit_group *)utarray_eltptr(compile_state->last_hit_groups, i); } return i; } -size_t compile_state_get_last_hit_group_id_cnt(struct compile_state *compile_state) +size_t compile_state_get_last_hit_group_cnt(struct compile_state *compile_state) { - return utarray_len(compile_state->last_hit_group_ids); + return utarray_len(compile_state->last_hit_groups); } size_t compile_state_get_direct_hit_groups(struct compile_state *compile_state, diff --git a/src/maat_rule.c b/src/maat_rule.c index e513bea..ed0a951 100644 --- a/src/maat_rule.c +++ b/src/maat_rule.c @@ -143,9 +143,9 @@ static int maat_update_cb(const char *table_name, const char *line, void *u_para } // find conjunction id for table_id - long long conj_parent_table_ids[4]; + long long conj_parent_table_ids[MAX_CONJ_PARENTS_NUM]; int conj_parent_table_cnt = table_manager_get_conj_parent_table_ids(maat_inst->tbl_mgr, table_name, - conj_parent_table_ids, 4); + conj_parent_table_ids, MAX_CONJ_PARENTS_NUM); if (conj_parent_table_cnt > 0) { for (int i = 0; i < conj_parent_table_cnt; i++) { int ret = table_manager_update_runtime(maat_inst->tbl_mgr, table_name, diff --git a/src/maat_table.c b/src/maat_table.c index 5e7cc5f..9c9fcd8 100644 --- a/src/maat_table.c +++ b/src/maat_table.c @@ -873,9 +873,9 @@ table_manager_create(const char *table_info_path, const char *accept_tags, goto next; } - long long parent_table_ids[4]; + long long parent_table_ids[MAX_CONJ_PARENTS_NUM]; int parent_table_cnt = table_manager_get_conj_parent_table_ids(tbl_mgr, maat_tbl->table_name, - parent_table_ids, 4); + parent_table_ids, MAX_CONJ_PARENTS_NUM); if (parent_table_cnt <= 0) { // if table has conjuncion parent, which can share schema and // runtime with parent. diff --git a/test/maat_framework_gtest.cpp b/test/maat_framework_gtest.cpp index 76a8631..a26f249 100644 --- a/test/maat_framework_gtest.cpp +++ b/test/maat_framework_gtest.cpp @@ -3402,8 +3402,10 @@ TEST_F(MaatGroupScan, basic) { int table_id = maat_get_table_id(maat_inst, table_name); ASSERT_GE(table_id, 0); - long long group_id = 247; - int ret = maat_scan_group(maat_inst, table_id, &group_id, 1, results, + struct maat_hit_group hit_group; + hit_group.group_id = 247; + hit_group.vtable_id = table_id; + int ret = maat_scan_group(maat_inst, table_id, &hit_group, 1, results, ARRAY_SIZE, &n_hit_result, state); EXPECT_EQ(ret, MAAT_SCAN_HIT); EXPECT_EQ(n_hit_result, 1); @@ -3430,8 +3432,10 @@ TEST_F(MaatGroupScan, SetScanCompileTable) { int ret = maat_state_set_scan_compile_table(state, compile_table_id); EXPECT_EQ(ret, 0); - long long group_id = 248; - ret = maat_scan_group(maat_inst, table_id, &group_id, 1, results, + struct maat_hit_group hit_group; + hit_group.group_id = 248; + hit_group.vtable_id = table_id; + ret = maat_scan_group(maat_inst, table_id, &hit_group, 1, results, ARRAY_SIZE, &n_hit_result, state); EXPECT_EQ(ret, MAAT_SCAN_HIT); EXPECT_EQ(n_hit_result, 1); @@ -7531,7 +7535,10 @@ TEST_F(MaatCmdTest, MaatGroupScan) { sleep(WAIT_FOR_EFFECTIVE_S); - ret = maat_scan_group(maat_inst, table_id, &group_id, 1, results, ARRAY_SIZE, + struct maat_hit_group hit_group; + hit_group.group_id = group_id; + hit_group.vtable_id = table_id; + ret = maat_scan_group(maat_inst, table_id, &hit_group, 1, results, ARRAY_SIZE, &n_hit_result, state); EXPECT_EQ(ret, MAAT_SCAN_HIT); EXPECT_EQ(n_hit_result, 1); @@ -9026,12 +9033,18 @@ TEST_F(MaatCmdTest, HitGroup) { EXPECT_EQ(hit_groups[0].group_id, group11_id); EXPECT_EQ(hit_groups[0].vtable_id, http_req_table_id); - size_t n_last_hit_group = maat_state_get_last_hit_group_id_cnt(state); - long long last_hit_group_ids[128] = {0}; - maat_state_get_last_hit_group_ids(state, last_hit_group_ids, 128); + size_t n_last_hit_group = maat_state_get_last_hit_group_cnt(state); + struct maat_hit_group last_hit_groups[128] = {0}; + maat_state_get_last_hit_groups(state, last_hit_groups, 128); EXPECT_EQ(n_last_hit_group, 2); - EXPECT_EQ(last_hit_group_ids[0], group1_id); - EXPECT_EQ(last_hit_group_ids[1], group11_id); + + EXPECT_EQ(last_hit_groups[0].item_id, item1_id); + EXPECT_EQ(last_hit_groups[0].group_id, group1_id); + EXPECT_EQ(last_hit_groups[0].vtable_id, http_req_table_id); + + EXPECT_EQ(last_hit_groups[1].item_id, 0); + EXPECT_EQ(last_hit_groups[1].group_id, group11_id); + EXPECT_EQ(last_hit_groups[1].vtable_id, http_req_table_id); int http_res_table_id = maat_get_table_id(maat_inst, "HTTP_RESPONSE_HEADER"); ASSERT_GT(http_res_table_id, 0); @@ -9072,11 +9085,17 @@ TEST_F(MaatCmdTest, HitGroup) { EXPECT_EQ(hit_groups[0].group_id, group21_id); EXPECT_EQ(hit_groups[0].vtable_id, http_res_table_id); - n_last_hit_group = maat_state_get_last_hit_group_id_cnt(state); - maat_state_get_last_hit_group_ids(state, last_hit_group_ids, 128); + n_last_hit_group = maat_state_get_last_hit_group_cnt(state); + maat_state_get_last_hit_groups(state, last_hit_groups, 128); EXPECT_EQ(n_last_hit_group, 2); - EXPECT_EQ(last_hit_group_ids[0], group2_id); - EXPECT_EQ(last_hit_group_ids[1], group21_id); + + EXPECT_EQ(last_hit_groups[0].item_id, item2_id); + EXPECT_EQ(last_hit_groups[0].group_id, group2_id); + EXPECT_EQ(last_hit_groups[0].vtable_id, http_res_table_id); + + EXPECT_EQ(last_hit_groups[1].item_id, 0); + EXPECT_EQ(last_hit_groups[1].group_id, group21_id); + EXPECT_EQ(last_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"; @@ -9141,12 +9160,21 @@ TEST_F(MaatCmdTest, HitGroup) { EXPECT_EQ(hit_groups[1].group_id, group4_id); EXPECT_EQ(hit_groups[1].vtable_id, keywords_table_id); //physical table(keywords_table) vtable_id is 0 - n_last_hit_group = maat_state_get_last_hit_group_id_cnt(state); - maat_state_get_last_hit_group_ids(state, last_hit_group_ids, 128); + n_last_hit_group = maat_state_get_last_hit_group_cnt(state); + maat_state_get_last_hit_groups(state, last_hit_groups, 128); EXPECT_EQ(n_last_hit_group, 3); - EXPECT_EQ(last_hit_group_ids[0], group1_id); - EXPECT_EQ(last_hit_group_ids[1], group4_id); - EXPECT_EQ(last_hit_group_ids[2], group11_id); + + EXPECT_EQ(last_hit_groups[0].item_id, item5_id); + EXPECT_EQ(last_hit_groups[0].group_id, group1_id); + EXPECT_EQ(last_hit_groups[0].vtable_id, keywords_table_id); + + EXPECT_EQ(last_hit_groups[1].item_id, item4_id); + EXPECT_EQ(last_hit_groups[1].group_id, group4_id); + EXPECT_EQ(last_hit_groups[1].vtable_id, keywords_table_id); + + EXPECT_EQ(last_hit_groups[2].item_id, 0); + EXPECT_EQ(last_hit_groups[2].group_id, group11_id); + EXPECT_EQ(last_hit_groups[2].vtable_id, keywords_table_id); maat_stream_free(stream); maat_state_free(state);