summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorliuwentan <[email protected]>2023-06-28 11:12:25 +0800
committerliuwentan <[email protected]>2023-06-28 11:12:25 +0800
commite5c020453e64bd6c212519a888b9fe936eadfb99 (patch)
tree791a63dd4b08e901aba4c96840ba370a7296c29c
parentfc0b810211db9257e43d87e122707f2ab82f1cb9 (diff)
[FEATURE]ADD maat_state_get_scan_count APIv4.0.29
-rw-r--r--include/maat.h2
-rw-r--r--src/maat_api.c9
-rw-r--r--test/maat_framework_gtest.cpp13
3 files changed, 23 insertions, 1 deletions
diff --git a/include/maat.h b/include/maat.h
index 3533ff5..e149d8a 100644
--- a/include/maat.h
+++ b/include/maat.h
@@ -268,6 +268,8 @@ int maat_state_set_scan_compile_table(struct maat_state *state, int compile_tabl
int maat_state_get_hit_paths(struct maat_state *state, struct maat_hit_path *paths,
size_t n_path);
+
+size_t maat_state_get_scan_count(struct maat_state *state);
int maat_state_get_hit_groups(struct maat_state *state, struct maat_hit_group *groups,
size_t n_group);
diff --git a/src/maat_api.c b/src/maat_api.c
index 748b8fc..302e3f4 100644
--- a/src/maat_api.c
+++ b/src/maat_api.c
@@ -1926,6 +1926,15 @@ int maat_state_get_hit_paths(struct maat_state *state, struct maat_hit_path *pat
state->compile_state, paths, n_path, internal_hit_path_cnt);
}
+size_t maat_state_get_scan_count(struct maat_state *state)
+{
+ if (NULL == state) {
+ return 0;
+ }
+
+ return state->scan_cnt;
+}
+
int maat_state_get_hit_groups(struct maat_state *state, struct maat_hit_group *groups,
size_t n_group)
{
diff --git a/test/maat_framework_gtest.cpp b/test/maat_framework_gtest.cpp
index 45097a6..c00cab0 100644
--- a/test/maat_framework_gtest.cpp
+++ b/test/maat_framework_gtest.cpp
@@ -596,7 +596,7 @@ TEST_F(MaatFlagScan, basic) {
EXPECT_EQ(n_hit_result, 2);
EXPECT_EQ(results[0], 207);
EXPECT_EQ(results[1], 192);
-
+
struct maat_hit_path hit_path[HIT_PATH_SIZE] = {0};
int n_read = 0;
n_read = maat_state_get_hit_paths(state, hit_path, HIT_PATH_SIZE);
@@ -5498,6 +5498,9 @@ TEST_F(MaatCmdTest, HitPath) {
results, ARRAY_SIZE, &n_hit_result, state);
EXPECT_EQ(ret, MAAT_SCAN_HALF_HIT);
+ size_t scan_count = maat_state_get_scan_count(state);
+ EXPECT_EQ(scan_count, 1);
+
struct maat_hit_group hit_groups[128];
memset(hit_groups, 0, sizeof(hit_groups));
int n_hit_group = maat_state_get_hit_groups(state, hit_groups, sizeof(hit_groups));
@@ -5540,6 +5543,8 @@ TEST_F(MaatCmdTest, HitPath) {
EXPECT_EQ(ret, MAAT_SCAN_HIT);
EXPECT_EQ(n_hit_result, 1);
EXPECT_EQ(results[0], compile1_id);
+ scan_count = maat_state_get_scan_count(state);
+ EXPECT_EQ(scan_count, 2);
n_hit_group = maat_state_get_hit_groups(state, hit_groups, sizeof(hit_groups));
EXPECT_EQ(n_hit_group, 4);
@@ -5602,6 +5607,8 @@ that the edges be all directed in the same direction.";
ret = maat_stream_scan(stream, keywords1, strlen(keywords1), results, ARRAY_SIZE,
&n_hit_result, state);
EXPECT_EQ(ret, MAAT_SCAN_HALF_HIT);
+ scan_count = maat_state_get_scan_count(state);
+ EXPECT_EQ(scan_count, 3);
n_hit_group = maat_state_get_hit_groups(state, hit_groups, sizeof(hit_groups));
EXPECT_EQ(n_hit_group, 5);
@@ -5638,6 +5645,8 @@ that the edges be all directed in the same direction.";
ret = maat_scan_ipv4(maat_inst, ip_table_id, ip_addr, port, 6, results, ARRAY_SIZE,
&n_hit_result, state);
EXPECT_EQ(ret, MAAT_SCAN_HALF_HIT);
+ scan_count = maat_state_get_scan_count(state);
+ EXPECT_EQ(scan_count, 4);
n_hit_group = maat_state_get_hit_groups(state, hit_groups, sizeof(hit_groups));
EXPECT_EQ(n_hit_group, 6);
@@ -5670,6 +5679,8 @@ that the edges be all directed in the same direction.";
ret = maat_stream_scan(stream, keywords2, strlen(keywords2), results, ARRAY_SIZE,
&n_hit_result, state);
EXPECT_EQ(ret, MAAT_SCAN_HALF_HIT);
+ scan_count = maat_state_get_scan_count(state);
+ EXPECT_EQ(scan_count, 5);
n_read = maat_state_get_hit_paths(state, hit_path, sizeof(hit_path));
EXPECT_EQ(n_read, 7);