summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorroot <[email protected]>2024-08-22 10:26:59 +0000
committerroot <[email protected]>2024-08-22 10:26:59 +0000
commit54a70f19d9f5aa50142aed1779132639c34cc5dd (patch)
treecf5fd594f5822c0f49195fbfa97c65f0b1df9839 /src
parent72cf89723d7d751470204c95e633f7b518e5952c (diff)
rename terminology "group" to "object"
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/inc_internal/maat_core.h6
-rw-r--r--src/inc_internal/maat_expr.h4
-rw-r--r--src/inc_internal/maat_flag.h4
-rw-r--r--src/inc_internal/maat_group.h58
-rw-r--r--src/inc_internal/maat_interval.h4
-rw-r--r--src/inc_internal/maat_limits.h4
-rw-r--r--src/inc_internal/maat_object.h58
-rw-r--r--src/inc_internal/maat_rule.h46
-rw-r--r--src/inc_internal/maat_table.h6
-rw-r--r--src/inc_internal/maat_utils.h2
-rw-r--r--src/json2iris.c466
-rw-r--r--src/maat_api.c224
-rw-r--r--src/maat_command.c2
-rw-r--r--src/maat_expr.c30
-rw-r--r--src/maat_flag.c22
-rw-r--r--src/maat_group.c1252
-rw-r--r--src/maat_interval.c22
-rw-r--r--src/maat_ip.c22
-rw-r--r--src/maat_object.c1252
-rw-r--r--src/maat_rule.c570
-rw-r--r--src/maat_stat.c16
-rw-r--r--src/maat_table.c56
-rw-r--r--src/maat_utils.c4
24 files changed, 2066 insertions, 2066 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index c76bda8..7bed0f4 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -13,7 +13,7 @@ add_definitions(-D_GNU_SOURCE)
add_definitions(-fPIC)
set(MAAT_SRC alignment.c json2iris.c maat_api.c rcu_hash.c maat_garbage_collection.c maat_config_monitor.c
maat_core.c maat_kv.c maat_ex_data.c maat_utils.c maat_command.c maat_redis_monitor.c maat_table.c
- maat_rule.c maat_group.c maat_ip.c maat_flag.c maat_interval.c maat_expr.c maat_plugin.c
+ maat_rule.c maat_object.c maat_ip.c maat_flag.c maat_interval.c maat_expr.c maat_plugin.c
maat_ip_plugin.c maat_ipport_plugin.c maat_bool_plugin.c maat_fqdn_plugin.c maat_attribute.c maat_stat.c)
set(LIB_SOURCE_FILES
diff --git a/src/inc_internal/maat_core.h b/src/inc_internal/maat_core.h
index e4d42ff..c50834c 100644
--- a/src/inc_internal/maat_core.h
+++ b/src/inc_internal/maat_core.h
@@ -44,7 +44,7 @@ extern "C"
#define INVALID_VERSION -1
#define mr_region_id_var "SEQUENCE_REGION"
-#define mr_group_id_var "SEQUENCE_GROUP"
+#define mr_object_id_var "SEQUENCE_OBJECT"
enum tag_match {
TAG_MATCH_ERR = -1,
@@ -54,7 +54,7 @@ enum tag_match {
struct maat_item {
long long item_id;
- long long group_id;
+ long long object_id;
};
struct maat_runtime {
@@ -121,7 +121,7 @@ struct maat_options {
int stat_on;
int perf_on;
int hit_path_on;
- int hit_group_on;
+ int hit_object_on;
int deferred_load_on;
int maat_json_is_gzipped;
diff --git a/src/inc_internal/maat_expr.h b/src/inc_internal/maat_expr.h
index 2e7693a..bdd3512 100644
--- a/src/inc_internal/maat_expr.h
+++ b/src/inc_internal/maat_expr.h
@@ -45,9 +45,9 @@ long long expr_runtime_get_version(void *expr_runtime);
/* expr runtime scan API */
/**
- * @brief scan string to get hit group_ids
+ * @brief scan string to get hit object_ids
*
- * @retval the num of hit group_id
+ * @retval the num of hit object_id
*/
int expr_runtime_scan(struct expr_runtime *expr_rt, int thread_id, const char *data,
size_t data_len, int attribute_id, struct maat_state *state);
diff --git a/src/inc_internal/maat_flag.h b/src/inc_internal/maat_flag.h
index c65cbae..63e5d56 100644
--- a/src/inc_internal/maat_flag.h
+++ b/src/inc_internal/maat_flag.h
@@ -43,9 +43,9 @@ long long flag_runtime_rule_count(void *flag_runtime);
/* flag runtime scan API */
/**
- * @brief scan flag to get hit group_ids
+ * @brief scan flag to get hit object_ids
*
- * @retval the num of hit group_id
+ * @retval the num of hit object_id
*/
int flag_runtime_scan(struct flag_runtime *flag_rt, int thread_id, long long flag,
int attribute_id, struct maat_state *state);
diff --git a/src/inc_internal/maat_group.h b/src/inc_internal/maat_group.h
deleted file mode 100644
index f03a23e..0000000
--- a/src/inc_internal/maat_group.h
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
-**********************************************************************************************
-* File: maat_group.h
-* Description:
-* Authors: Liu wentan <[email protected]>
-* Date: 2022-10-31
-* Copyright: (c) Since 2022 Geedge Networks, Ltd. All rights reserved.
-***********************************************************************************************
-*/
-
-#ifndef _MAAT_GROUP_H_
-#define _MAAT_GROUP_H_
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-#include <stdint.h>
-
-#include "cJSON/cJSON.h"
-#include "maat_kv.h"
-#include "maat_table.h"
-
-struct maat_group;
-struct group2group_runtime;
-
-/* group2group schema API */
-void *group2group_schema_new(cJSON *json, struct table_manager *tbl_mgr,
- const char *table_name, struct log_handle *logger);
-void group2group_schema_free(void *g2g_schema);
-
-/* group2group runtime API */
-void *group2group_runtime_new(void *g2g_schema, size_t max_thread_num,
- struct maat_garbage_bin *garbage_bin,
- struct log_handle *logger);
-void group2group_runtime_free(void *g2g_runtime);
-
-int group2group_runtime_update(void *g2g_runtime, void *g2g_schema, const char *table_name,
- const char *line, int valid_column);
-
-int group2group_runtime_commit(void *g2g_runtime, const char *table_name, long long maat_rt_version);
-
-size_t group2group_runtime_get_super_groups(void *g2g_runtime, long long *group_ids,
- size_t n_group_ids, long long *super_group_ids,
- size_t super_group_ids_size);
-
-long long group2group_runtime_rule_count(void *g2g_runtime);
-
-long long group2group_runtime_exclude_rule_count(void *g2g_runtime);
-
-long long group2group_runtime_update_err_count(void *g2g_runtime);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/src/inc_internal/maat_interval.h b/src/inc_internal/maat_interval.h
index 0c82442..86382c3 100644
--- a/src/inc_internal/maat_interval.h
+++ b/src/inc_internal/maat_interval.h
@@ -44,9 +44,9 @@ long long interval_runtime_rule_count(void *interval_runtime);
/* interval runtime scan API */
/**
- * @brief scan interval to get hit group_ids
+ * @brief scan interval to get hit object_ids
*
- * @retval the num of hit group_id
+ * @retval the num of hit object_id
*/
int interval_runtime_scan(struct interval_runtime *interval_rt, int thread_id,
long long integer, int attribute_id, struct maat_state *state);
diff --git a/src/inc_internal/maat_limits.h b/src/inc_internal/maat_limits.h
index 45b9f1a..58542b3 100644
--- a/src/inc_internal/maat_limits.h
+++ b/src/inc_internal/maat_limits.h
@@ -22,8 +22,8 @@ extern "C"
#define MAX_NAME_STR_LEN 128
#define MAX_IP_STR_LEN 64
#define MAX_INSTANCE_NAME_LEN 15
-#define MAX_GROUP_IDS_STR_LEN 256
-#define MAX_GROUP_CNT 128
+#define MAX_OBJECT_IDS_STR_LEN 256
+#define MAX_OBJECT_CNT 128
#define MAX_CONJ_PARENTS_NUM 16
#ifdef __cplusplus
diff --git a/src/inc_internal/maat_object.h b/src/inc_internal/maat_object.h
new file mode 100644
index 0000000..ffc9d19
--- /dev/null
+++ b/src/inc_internal/maat_object.h
@@ -0,0 +1,58 @@
+/*
+**********************************************************************************************
+* File: maat_object.h
+* Description:
+* Authors: Liu wentan <[email protected]>
+* Date: 2022-10-31
+* Copyright: (c) Since 2022 Geedge Networks, Ltd. All rights reserved.
+***********************************************************************************************
+*/
+
+#ifndef _MAAT_OBJECT_H_
+#define _MAAT_OBJECT_H_
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <stdint.h>
+
+#include "cJSON/cJSON.h"
+#include "maat_kv.h"
+#include "maat_table.h"
+
+struct maat_object;
+struct object2object_runtime;
+
+/* object2object schema API */
+void *object2object_schema_new(cJSON *json, struct table_manager *tbl_mgr,
+ const char *table_name, struct log_handle *logger);
+void object2object_schema_free(void *g2g_schema);
+
+/* object2object runtime API */
+void *object2object_runtime_new(void *g2g_schema, size_t max_thread_num,
+ struct maat_garbage_bin *garbage_bin,
+ struct log_handle *logger);
+void object2object_runtime_free(void *g2g_runtime);
+
+int object2object_runtime_update(void *g2g_runtime, void *g2g_schema, const char *table_name,
+ const char *line, int valid_column);
+
+int object2object_runtime_commit(void *g2g_runtime, const char *table_name, long long maat_rt_version);
+
+size_t object2object_runtime_get_super_objects(void *g2g_runtime, long long *object_ids,
+ size_t n_object_ids, long long *super_object_ids,
+ size_t super_object_ids_size);
+
+long long object2object_runtime_rule_count(void *g2g_runtime);
+
+long long object2object_runtime_exclude_rule_count(void *g2g_runtime);
+
+long long object2object_runtime_update_err_count(void *g2g_runtime);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/src/inc_internal/maat_rule.h b/src/inc_internal/maat_rule.h
index da1bb45..6a3dda3 100644
--- a/src/inc_internal/maat_rule.h
+++ b/src/inc_internal/maat_rule.h
@@ -25,17 +25,17 @@ extern "C"
struct rule_schema;
struct rule_runtime;
struct rule_state;
-struct group2group_runtime;
+struct object2object_runtime;
/* rule schema API */
void *rule_schema_new(cJSON *json, struct table_manager *tbl_mgr,
const char *table_name, struct log_handle *logger);
void rule_schema_free(void *rule_schema);
-void *group2rule_schema_new(cJSON *json, struct table_manager *tbl_mgr,
+void *object2rule_schema_new(cJSON *json, struct table_manager *tbl_mgr,
const char *table_name, struct log_handle *logger);
-void group2rule_schema_free(void *g2c_schema);
-int group2rule_associated_rule_table_id(void *g2c_schema);
+void object2rule_schema_free(void *g2c_schema);
+int object2rule_associated_rule_table_id(void *g2c_schema);
/* rule runtime API */
void *rule_runtime_new(void *rule_schema, size_t max_thread_num,
@@ -64,24 +64,24 @@ size_t rule_runtime_get_hit_paths(struct rule_runtime *rule_rt, int thread_id,
struct maat_hit_path *hit_path_array,
size_t array_size, size_t n_hit_path);
-/* group2rule runtime API */
-void *group2rule_runtime_new(void *g2c_schema, size_t max_thread_num,
+/* object2rule runtime API */
+void *object2rule_runtime_new(void *g2c_schema, size_t max_thread_num,
struct maat_garbage_bin *garbage_bin,
struct log_handle *logger);
-void group2rule_runtime_init(void *g2c_runtime, void *rule_runtime);
+void object2rule_runtime_init(void *g2c_runtime, void *rule_runtime);
-void group2rule_runtime_free(void *g2c_runtime);
+void object2rule_runtime_free(void *g2c_runtime);
-int group2rule_runtime_update(void *g2c_runtime, void *g2c_schema,
+int object2rule_runtime_update(void *g2c_runtime, void *g2c_schema,
const char *table_name, const char *line,
int valid_column);
-long long group2rule_runtime_not_condition_count(void *g2c_runtime);
+long long object2rule_runtime_not_condition_count(void *g2c_runtime);
-long long group2rule_runtime_rule_count(void *g2c_runtime);
+long long object2rule_runtime_rule_count(void *g2c_runtime);
-long long group2rule_runtime_update_err_count(void *g2c_runtime);
+long long object2rule_runtime_update_err_count(void *g2c_runtime);
/* maat rule state API */
struct rule_state;
@@ -96,7 +96,7 @@ int rule_state_update(struct rule_state *rule_state, struct maat *maat_inst,
int attribute_id, int custom_rule_tbl_id, int Nth_scan,
struct maat_item *hit_items, size_t n_hit_item);
-void rule_state_clear_last_hit_group(struct rule_state *rule_state);
+void rule_state_clear_last_hit_object(struct rule_state *rule_state);
void rule_state_not_logic_update(struct rule_state *rule_state,
struct rule_runtime *rule_rt,
@@ -105,27 +105,27 @@ void rule_state_not_logic_update(struct rule_state *rule_state,
size_t rule_state_get_internal_hit_paths(struct rule_state *rule_state,
struct rule_runtime *rule_rt,
- struct group2group_runtime *g2g_rt,
+ struct object2object_runtime *g2g_rt,
struct maat_hit_path *hit_path_array,
size_t array_size);
-size_t rule_state_get_direct_hit_groups(struct rule_state *rule_state,
- struct maat_hit_group *group_array,
+size_t rule_state_get_direct_hit_objects(struct rule_state *rule_state,
+ struct maat_hit_object *object_array,
size_t array_size);
-size_t rule_state_get_direct_hit_group_cnt(struct rule_state *rule_state);
+size_t rule_state_get_direct_hit_object_cnt(struct rule_state *rule_state);
-size_t rule_state_get_indirect_hit_groups(struct rule_state *rule_state,
- struct maat_hit_group *group_array,
+size_t rule_state_get_indirect_hit_objects(struct rule_state *rule_state,
+ struct maat_hit_object *object_array,
size_t array_size);
-size_t rule_state_get_indirect_hit_group_cnt(struct rule_state *rule_state);
+size_t rule_state_get_indirect_hit_object_cnt(struct rule_state *rule_state);
-size_t rule_state_get_last_hit_groups(struct rule_state *rule_state,
- struct maat_hit_group *group_arary,
+size_t rule_state_get_last_hit_objects(struct rule_state *rule_state,
+ struct maat_hit_object *object_arary,
size_t array_size);
-size_t rule_state_get_last_hit_group_cnt(struct rule_state *rule_state);
+size_t rule_state_get_last_hit_object_cnt(struct rule_state *rule_state);
int rule_state_get_rule_table_id(struct rule_state *rule_state,
long long rule_id);
diff --git a/src/inc_internal/maat_table.h b/src/inc_internal/maat_table.h
index d1890c8..5cead74 100644
--- a/src/inc_internal/maat_table.h
+++ b/src/inc_internal/maat_table.h
@@ -40,8 +40,8 @@ enum table_type {
//above are physical table
TABLE_TYPE_ATTRIBUTE,
TABLE_TYPE_RULE,
- TABLE_TYPE_GROUP2GROUP,
- TABLE_TYPE_GROUP2RULE,
+ TABLE_TYPE_OBJECT2OBJECT,
+ TABLE_TYPE_OBJECT2RULE,
TABLE_TYPE_MAX
};
@@ -85,7 +85,7 @@ const char *table_manager_get_table_schema_tag(struct table_manager *tbl_mgr, in
enum table_type table_manager_get_table_type(struct table_manager *tbl_mgr, int table_id);
int table_manager_get_default_rule_table_id(struct table_manager *tbl_mgr);
-int table_manager_get_group2group_table_id(struct table_manager *tbl_mgr);
+int table_manager_get_object2object_table_id(struct table_manager *tbl_mgr);
int table_manager_get_valid_column(struct table_manager *tbl_mgr, int table_id);
diff --git a/src/inc_internal/maat_utils.h b/src/inc_internal/maat_utils.h
index 915861f..fca7ef6 100644
--- a/src/inc_internal/maat_utils.h
+++ b/src/inc_internal/maat_utils.h
@@ -56,7 +56,7 @@ extern "C"
#define MAX_HIT_PATH_NUM 4096
#define MAX_HIT_RULE_NUM 4096
-#define MAX_HIT_GROUP_NUM 4096
+#define MAX_HIT_OBJECT_NUM 4096
#define MAX_HIT_ITEM_NUM 4096
#define IPV4 4
diff --git a/src/json2iris.c b/src/json2iris.c
index a0ccded..f9863ad 100644
--- a/src/json2iris.c
+++ b/src/json2iris.c
@@ -28,22 +28,22 @@
#define MAX_COLUMN_NUM 32
#define MAX_PATH_LINE 512
#define MAX_BUFF_LEN 4096
-#define MAX_GROUP_ID_STR 128
+#define MAX_OBJECT_ID_STR 128
const int json_version = 1;
-const char *untitled_group_name = "Untitled";
-long long untitled_group_id = 123456789;
+const char *untitled_object_name = "Untitled";
+long long untitled_object_id = 123456789;
-enum maat_group_relation {
+enum maat_object_relation {
PARENT_TYPE_RULE = 0,
- PARENT_TYPE_GROUP
+ PARENT_TYPE_OBJECT
};
-struct group_info {
- int group_id;
- char group_name[NAME_MAX];
- UT_array *incl_sub_group_ids;
- UT_array *excl_sub_group_ids;
+struct object_info {
+ int object_id;
+ char object_name[NAME_MAX];
+ UT_array *incl_sub_object_ids;
+ UT_array *excl_sub_object_ids;
UT_hash_handle hh;
};
@@ -59,19 +59,19 @@ struct iris_table {
};
struct iris_description {
- int group_cnt;
+ int object_cnt;
int region_cnt;
char tmp_iris_dir[MAX_PATH_LINE];
char tmp_iris_index_dir[MAX_PATH_LINE];
char index_path[PATH_MAX];
- struct iris_table *group_table;
- struct iris_table *group2group_table;
- struct iris_table *group2rule_table;
+ struct iris_table *object_table;
+ struct iris_table *object2object_table;
+ struct iris_table *object2rule_table;
struct iris_table *rule_table;
- struct group_info *group_name_map;
+ struct object_info *object_name_map;
struct iris_table *iris_table_map;
struct maat_kv_store *str2int_map;
@@ -130,8 +130,8 @@ static void free_iris_table_info(void *p)
static int
set_iris_descriptor(const char *json_file, cJSON *json,
const char *encrypt_key, const char *encrypt_algo,
- const char *rule_tn, const char *group2rule_tn,
- const char* group2group_tn, redisContext *redis_write_ctx,
+ const char *rule_tn, const char *object2rule_tn,
+ const char* object2object_tn, redisContext *redis_write_ctx,
struct iris_description *iris_cfg)
{
memset(iris_cfg, 0, sizeof(struct iris_description));
@@ -183,10 +183,10 @@ set_iris_descriptor(const char *json_file, cJSON *json,
iris_cfg->rule_table = query_table_info(iris_cfg, rule_tn,
TABLE_TYPE_RULE);
- iris_cfg->group2rule_table = query_table_info(iris_cfg, group2rule_tn,
- TABLE_TYPE_GROUP2RULE);
- iris_cfg->group2group_table = query_table_info(iris_cfg, group2group_tn,
- TABLE_TYPE_GROUP2GROUP);
+ iris_cfg->object2rule_table = query_table_info(iris_cfg, object2rule_tn,
+ TABLE_TYPE_OBJECT2RULE);
+ iris_cfg->object2object_table = query_table_info(iris_cfg, object2object_tn,
+ TABLE_TYPE_OBJECT2OBJECT);
if (encrypt_key && encrypt_algo) {
iris_cfg->encrypt_key = maat_strdup(encrypt_key);
@@ -198,21 +198,21 @@ set_iris_descriptor(const char *json_file, cJSON *json,
static void clear_iris_descriptor(struct iris_description *iris_cfg)
{
- if (iris_cfg->group_name_map != NULL) {
- struct group_info *node = NULL;
- struct group_info *tmp = NULL;
- HASH_ITER(hh, iris_cfg->group_name_map, node, tmp) {
- if (node->incl_sub_group_ids != NULL) {
- utarray_free(node->incl_sub_group_ids);
- node->incl_sub_group_ids = NULL;
+ if (iris_cfg->object_name_map != NULL) {
+ struct object_info *node = NULL;
+ struct object_info *tmp = NULL;
+ HASH_ITER(hh, iris_cfg->object_name_map, node, tmp) {
+ if (node->incl_sub_object_ids != NULL) {
+ utarray_free(node->incl_sub_object_ids);
+ node->incl_sub_object_ids = NULL;
}
- if (node->excl_sub_group_ids != NULL) {
- utarray_free(node->excl_sub_group_ids);
- node->excl_sub_group_ids = NULL;
+ if (node->excl_sub_object_ids != NULL) {
+ utarray_free(node->excl_sub_object_ids);
+ node->excl_sub_object_ids = NULL;
}
- HASH_DELETE(hh, iris_cfg->group_name_map, node);
+ HASH_DELETE(hh, iris_cfg->object_name_map, node);
FREE(node);
}
}
@@ -301,31 +301,31 @@ write_plugin_line(cJSON *plug_table_json, int sequence,
return 0;
}
-static struct group_info *group_info_read(struct group_info *group_name_map,
- const char *group_name)
+static struct object_info *object_info_read(struct object_info *object_name_map,
+ const char *object_name)
{
- struct group_info *node = NULL;
- HASH_FIND(hh, group_name_map, group_name, strlen(group_name), node);
+ struct object_info *node = NULL;
+ HASH_FIND(hh, object_name_map, object_name, strlen(object_name), node);
return node;
}
-UT_icd ut_json2iris_group_id_icd = {sizeof(int), NULL, NULL, NULL};
-static struct group_info *
-group_info_add_unsafe(struct iris_description *p_iris, const char *group_name,
- long long group_id)
+UT_icd ut_json2iris_object_id_icd = {sizeof(int), NULL, NULL, NULL};
+static struct object_info *
+object_info_add_unsafe(struct iris_description *p_iris, const char *object_name,
+ long long object_id)
{
- struct group_info *group_info = ALLOC(struct group_info, 1);
- utarray_new(group_info->incl_sub_group_ids, &ut_json2iris_group_id_icd);
- utarray_new(group_info->excl_sub_group_ids, &ut_json2iris_group_id_icd);
+ struct object_info *object_info = ALLOC(struct object_info, 1);
+ utarray_new(object_info->incl_sub_object_ids, &ut_json2iris_object_id_icd);
+ utarray_new(object_info->excl_sub_object_ids, &ut_json2iris_object_id_icd);
- group_info->group_id = group_id;
- strncpy(group_info->group_name, group_name, sizeof(group_info->group_name));
+ object_info->object_id = object_id;
+ strncpy(object_info->object_name, object_name, sizeof(object_info->object_name));
- HASH_ADD_KEYPTR(hh, p_iris->group_name_map, group_info->group_name,
- strlen(group_name), group_info);
+ HASH_ADD_KEYPTR(hh, p_iris->object_name_map, object_info->object_name,
+ strlen(object_name), object_info);
- return group_info;
+ return object_info;
}
static int get_region_seq(struct iris_description *iris_cfg)
@@ -435,7 +435,7 @@ write_flag_line(cJSON *region_json, struct iris_description *p_iris,
json_cmd[cmd_cnt].json_type=cJSON_Number;
cmd_cnt++;
- json_cmd[cmd_cnt].json_string = "group_id";
+ json_cmd[cmd_cnt].json_string = "object_id";
json_cmd[cmd_cnt].json_type = cJSON_Number;
cmd_cnt++;
@@ -473,7 +473,7 @@ write_expr_line(cJSON *region_json, struct iris_description *p_iris,
json_cmd[cmd_cnt].json_type = cJSON_Number;
cmd_cnt++;
- json_cmd[cmd_cnt].json_string = "group_id";
+ json_cmd[cmd_cnt].json_string = "object_id";
json_cmd[cmd_cnt].json_type = cJSON_Number;
cmd_cnt++;
@@ -512,7 +512,7 @@ write_ip_line(cJSON *region_json, struct iris_description *p_iris,
json_cmd[cmd_cnt].json_type = cJSON_Number;
cmd_cnt++;
- json_cmd[cmd_cnt].json_string = "group_id";
+ json_cmd[cmd_cnt].json_string = "object_id";
json_cmd[cmd_cnt].json_type = cJSON_Number;
cmd_cnt++;
@@ -548,7 +548,7 @@ write_interval_line(cJSON *region_json, struct iris_description *p_iris,
json_cmd[cmd_cnt].json_type = cJSON_Number;
cmd_cnt++;
- json_cmd[cmd_cnt].json_string = "group_id";
+ json_cmd[cmd_cnt].json_string = "object_id";
json_cmd[cmd_cnt].json_type = cJSON_Number;
cmd_cnt++;
@@ -571,7 +571,7 @@ write_interval_line(cJSON *region_json, struct iris_description *p_iris,
}
static int
-write_region_rule(cJSON *region_json, int rule_id, int group_id,
+write_region_rule(cJSON *region_json, int rule_id, int object_id,
struct iris_description *p_iris, struct log_handle *logger)
{
cJSON *item = cJSON_GetObjectItem(region_json, "table_name");
@@ -613,7 +613,7 @@ write_region_rule(cJSON *region_json, int rule_id, int group_id,
int region_id = get_region_seq(p_iris);
cJSON_AddNumberToObject(table_content, "region_id", region_id);
- cJSON_AddNumberToObject(table_content, "group_id", group_id);
+ cJSON_AddNumberToObject(table_content, "object_id", object_id);
cJSON_AddNumberToObject(table_content, "is_valid", 1);
struct iris_table *table_info = query_table_info(p_iris, table_name,
@@ -642,8 +642,8 @@ write_region_rule(cJSON *region_json, int rule_id, int group_id,
}
static int
-write_group2rule_line(int *group_ids, size_t n_group_id,
- int rule_id, int group_negate_option,
+write_object2rule_line(int *object_ids, size_t n_object_id,
+ int rule_id, int object_negate_option,
int condition_index, const char *attribute,
struct iris_description *p_iris,
struct iris_table *g2c_table)
@@ -654,26 +654,26 @@ write_group2rule_line(int *group_ids, size_t n_group_id,
if (g2c_table != NULL) {
table = g2c_table;
} else {
- if (NULL == p_iris->group2rule_table) {
+ if (NULL == p_iris->object2rule_table) {
return -1;
}
- table = p_iris->group2rule_table;
+ table = p_iris->object2rule_table;
}
- if (n_group_id > 1) {
+ if (n_object_id > 1) {
char tmp_str[64] = {0};
- char group_id_str[2048] = {0};
+ char object_id_str[2048] = {0};
- for (size_t i = 0; i < n_group_id; i++) {
- snprintf(tmp_str, sizeof(tmp_str), "%d,", group_ids[i]);
- strcat(group_id_str, tmp_str);
+ for (size_t i = 0; i < n_object_id; i++) {
+ snprintf(tmp_str, sizeof(tmp_str), "%d,", object_ids[i]);
+ strcat(object_id_str, tmp_str);
}
- group_id_str[strlen(group_id_str) - 1] = '\0';
- snprintf(buff, sizeof(buff), "%s\t%d\t%d\t%s\t%d\t1\n", group_id_str,
- rule_id, group_negate_option, attribute, condition_index);
+ object_id_str[strlen(object_id_str) - 1] = '\0';
+ snprintf(buff, sizeof(buff), "%s\t%d\t%d\t%s\t%d\t1\n", object_id_str,
+ rule_id, object_negate_option, attribute, condition_index);
} else {
- snprintf(buff, sizeof(buff), "%d\t%d\t%d\t%s\t%d\t1\n", group_ids[0],
- rule_id, group_negate_option, attribute, condition_index);
+ snprintf(buff, sizeof(buff), "%d\t%d\t%d\t%s\t%d\t1\n", object_ids[0],
+ rule_id, object_negate_option, attribute, condition_index);
}
table->write_pos += memcat(&(table->buff), table->write_pos,
@@ -684,60 +684,60 @@ write_group2rule_line(int *group_ids, size_t n_group_id,
}
static int
-write_group2group_line(int group_id, UT_array *incl_sub_group_ids,
- UT_array *excl_sub_group_ids,
+write_object2object_line(int object_id, UT_array *incl_sub_object_ids,
+ UT_array *excl_sub_object_ids,
struct iris_description *p_iris)
{
char buff[MAX_BUFF_LEN*4] = {0};
- struct iris_table *table = p_iris->group2group_table;
+ struct iris_table *table = p_iris->object2object_table;
if (NULL == table) {
return -1;
}
size_t i = 0, pos = 0;
- char incl_sub_group_id_str[MAX_BUFF_LEN] = {0};
- char excl_sub_group_id_str[MAX_BUFF_LEN] = {0};
+ char incl_sub_object_id_str[MAX_BUFF_LEN] = {0};
+ char excl_sub_object_id_str[MAX_BUFF_LEN] = {0};
- if (0 == utarray_len(incl_sub_group_ids) &&
- 0 == utarray_len(excl_sub_group_ids)) {
+ if (0 == utarray_len(incl_sub_object_ids) &&
+ 0 == utarray_len(excl_sub_object_ids)) {
return 0;
}
int *tmp_id = NULL;
- char tmp_str[MAX_GROUP_ID_STR] = {0};
- for (i = 0; i < utarray_len(incl_sub_group_ids); i++) {
- tmp_id = (int *)utarray_eltptr(incl_sub_group_ids, i);
+ char tmp_str[MAX_OBJECT_ID_STR] = {0};
+ for (i = 0; i < utarray_len(incl_sub_object_ids); i++) {
+ tmp_id = (int *)utarray_eltptr(incl_sub_object_ids, i);
sprintf(tmp_str, "%d,", *tmp_id);
- sprintf(incl_sub_group_id_str + pos, "%s", tmp_str);
+ sprintf(incl_sub_object_id_str + pos, "%s", tmp_str);
pos += strlen(tmp_str);
}
const char *null_str = "null";
- size_t str_len = strlen(incl_sub_group_id_str);
+ size_t str_len = strlen(incl_sub_object_id_str);
if (str_len > 0) {
- incl_sub_group_id_str[str_len - 1] = '\0';
+ incl_sub_object_id_str[str_len - 1] = '\0';
} else {
- memcpy(incl_sub_group_id_str, null_str, strlen(null_str));
+ memcpy(incl_sub_object_id_str, null_str, strlen(null_str));
}
pos = 0;
memset(tmp_str, 0, sizeof(tmp_str));
- for (i = 0; i < utarray_len(excl_sub_group_ids); i++) {
- tmp_id = (int *)utarray_eltptr(excl_sub_group_ids, i);
+ for (i = 0; i < utarray_len(excl_sub_object_ids); i++) {
+ tmp_id = (int *)utarray_eltptr(excl_sub_object_ids, i);
sprintf(tmp_str, "%d,", *tmp_id);
- sprintf(excl_sub_group_id_str + pos, "%s", tmp_str);
+ sprintf(excl_sub_object_id_str + pos, "%s", tmp_str);
pos += strlen(tmp_str);
}
- str_len = strlen(excl_sub_group_id_str);
+ str_len = strlen(excl_sub_object_id_str);
if (str_len > 0) {
- excl_sub_group_id_str[str_len - 1] = '\0';
+ excl_sub_object_id_str[str_len - 1] = '\0';
} else {
- memcpy(excl_sub_group_id_str, null_str, strlen(null_str));
+ memcpy(excl_sub_object_id_str, null_str, strlen(null_str));
}
- snprintf(buff, sizeof(buff), "%d\t%s\t%s\t1\n", group_id,
- incl_sub_group_id_str, excl_sub_group_id_str);
+ snprintf(buff, sizeof(buff), "%d\t%s\t%s\t1\n", object_id,
+ incl_sub_object_id_str, excl_sub_object_id_str);
table->write_pos += memcat(&(table->buff), table->write_pos,
&(table->buff_sz), buff, strlen(buff));
@@ -747,119 +747,119 @@ write_group2group_line(int group_id, UT_array *incl_sub_group_ids,
}
static int
-write_group_rule(cJSON *group_json, int parent_id,
+write_object_rule(cJSON *object_json, int parent_id,
int parent_type, int tracking_rule_id,
- int Nth_group, struct iris_description *p_iris,
+ int Nth_object, struct iris_description *p_iris,
struct log_handle *logger)
{
int ret = 0;
- int group_negate_option = 0;
+ int object_negate_option = 0;
int condition_index = 0;
- const char *group_name = NULL;
- char group_name_array[32][MAX_NAME_STR_LEN];
- size_t group_name_cnt = 0;
- long long group_id = -1;
+ const char *object_name = NULL;
+ char object_name_array[32][MAX_NAME_STR_LEN];
+ size_t object_name_cnt = 0;
+ long long object_id = -1;
const char *attribute = NULL;
struct iris_table *g2c_table = NULL;
- cJSON *item = cJSON_GetObjectItem(group_json, "group_name");
+ cJSON *item = cJSON_GetObjectItem(object_json, "object_name");
if (NULL == item) {
- group_name = untitled_group_name;
+ object_name = untitled_object_name;
} else if (item->type == cJSON_String) {
- group_name = item->valuestring;
+ object_name = item->valuestring;
} else if (item->type == cJSON_Array) {
- group_name_cnt = cJSON_GetArraySize(item);
- assert(group_name_cnt <= 32);
- for (size_t i = 0; i < group_name_cnt; i++) {
+ object_name_cnt = cJSON_GetArraySize(item);
+ assert(object_name_cnt <= 32);
+ for (size_t i = 0; i < object_name_cnt; i++) {
cJSON *tmp_json = cJSON_GetArrayItem(item, i);
if (NULL == tmp_json || tmp_json->type != cJSON_String) {
log_fatal(logger, MODULE_JSON2IRIS,
- "[%s:%d] group_name of rule:%d format error",
+ "[%s:%d] object_name of rule:%d format error",
__FUNCTION__, __LINE__, parent_id);
return -1;
}
- memset(group_name_array[i], 0, sizeof(group_name_array[i]));
- memcpy(group_name_array[i], tmp_json->valuestring,
+ memset(object_name_array[i], 0, sizeof(object_name_array[i]));
+ memcpy(object_name_array[i], tmp_json->valuestring,
strlen(tmp_json->valuestring));
}
}
- item = cJSON_GetObjectItem(group_json, "group_id");
+ item = cJSON_GetObjectItem(object_json, "object_id");
if (item != NULL && item->type == cJSON_Number) {
- group_id = item->valueint;
+ object_id = item->valueint;
}
if (parent_type == PARENT_TYPE_RULE) {
- item = cJSON_GetObjectItem(group_json, "attribute");
+ item = cJSON_GetObjectItem(object_json, "attribute");
if (NULL == item || item->type != cJSON_String) {
attribute = "null";
} else {
attribute = item->valuestring;
}
- item = cJSON_GetObjectItem(group_json, "negate_option");
+ item = cJSON_GetObjectItem(object_json, "negate_option");
if (NULL == item || item->type != cJSON_Number) {
- group_negate_option = 0;
+ object_negate_option = 0;
} else {
- group_negate_option = item->valueint;
+ object_negate_option = item->valueint;
}
- item = cJSON_GetObjectItem(group_json, "condition_index");
+ item = cJSON_GetObjectItem(object_json, "condition_index");
if (NULL == item || item->type != cJSON_Number) {
- condition_index = Nth_group;
+ condition_index = Nth_object;
} else {
condition_index = item->valueint;
}
- item = cJSON_GetObjectItem(group_json, "g2c_table_name");
+ item = cJSON_GetObjectItem(object_json, "g2c_table_name");
if (item != NULL && item->type == cJSON_String) {
g2c_table = query_table_info(p_iris, item->valuestring,
- TABLE_TYPE_GROUP2RULE);
+ TABLE_TYPE_OBJECT2RULE);
}
}
- if (group_name_cnt > 0) {
- int group_ids[group_name_cnt];
- for (size_t i = 0; i < group_name_cnt; i++) {
- struct group_info *group_info =
- group_info_read(p_iris->group_name_map, group_name_array[i]);
- if (NULL == group_info) {
- log_fatal(logger, MODULE_JSON2IRIS, "[%s:%d] group_name:%s"
- " has no group_id", __FUNCTION__, __LINE__,
- group_name_array[i]);
+ if (object_name_cnt > 0) {
+ int object_ids[object_name_cnt];
+ for (size_t i = 0; i < object_name_cnt; i++) {
+ struct object_info *object_info =
+ object_info_read(p_iris->object_name_map, object_name_array[i]);
+ if (NULL == object_info) {
+ log_fatal(logger, MODULE_JSON2IRIS, "[%s:%d] object_name:%s"
+ " has no object_id", __FUNCTION__, __LINE__,
+ object_name_array[i]);
return -1;
}
- group_ids[i] = group_info->group_id;
+ object_ids[i] = object_info->object_id;
}
assert(parent_type == PARENT_TYPE_RULE);
- ret = write_group2rule_line(group_ids, group_name_cnt, parent_id,
- group_negate_option, condition_index,
+ ret = write_object2rule_line(object_ids, object_name_cnt, parent_id,
+ object_negate_option, condition_index,
attribute, p_iris, g2c_table);
} else {
- struct group_info *group_info =
- group_info_read(p_iris->group_name_map, group_name);
- // exist group name, regions and sub groups will be ommit.
- if (NULL == group_info) {
- if (0 == strncasecmp(group_name, untitled_group_name,
- strlen(untitled_group_name))) {
- group_id = untitled_group_id;
+ struct object_info *object_info =
+ object_info_read(p_iris->object_name_map, object_name);
+ // exist object name, regions and sub objects will be ommit.
+ if (NULL == object_info) {
+ if (0 == strncasecmp(object_name, untitled_object_name,
+ strlen(untitled_object_name))) {
+ object_id = untitled_object_id;
}
- if (-1 == group_id) {
+ if (-1 == object_id) {
log_fatal(logger, MODULE_JSON2IRIS,
- "[%s:%d] group_name:<%s> has no group_id",
- __FUNCTION__, __LINE__, group_name);
+ "[%s:%d] object_name:<%s> has no object_id",
+ __FUNCTION__, __LINE__, object_name);
return -1;
}
- group_info = group_info_add_unsafe(p_iris, group_name, group_id);
- cJSON *region_json = cJSON_GetObjectItem(group_json, "regions");
+ object_info = object_info_add_unsafe(p_iris, object_name, object_id);
+ cJSON *region_json = cJSON_GetObjectItem(object_json, "regions");
if (region_json != NULL) {
cJSON *region_rule = NULL;
cJSON_ArrayForEach(region_rule, region_json) {
ret = write_region_rule(region_rule, tracking_rule_id,
- group_info->group_id, p_iris, logger);
+ object_info->object_id, p_iris, logger);
if (ret < 0) {
log_fatal(logger, MODULE_JSON2IRIS,
"[%s:%d] rule rule %d write region error",
@@ -869,14 +869,14 @@ write_group_rule(cJSON *group_json, int parent_id,
}
}
- cJSON *sub_groups = cJSON_GetObjectItem(group_json, "sub_groups");
- if (sub_groups != NULL) {
+ cJSON *sub_objects = cJSON_GetObjectItem(object_json, "sub_objects");
+ if (sub_objects != NULL) {
// recursively
int i = 0;
- cJSON_ArrayForEach(item, sub_groups) {
+ cJSON_ArrayForEach(item, sub_objects) {
i++;
- ret = write_group_rule(item, group_info->group_id,
- PARENT_TYPE_GROUP, tracking_rule_id,
+ ret = write_object_rule(item, object_info->object_id,
+ PARENT_TYPE_OBJECT, tracking_rule_id,
i, p_iris, logger);
if (ret < 0) {
return -1;
@@ -884,21 +884,21 @@ write_group_rule(cJSON *group_json, int parent_id,
}
}
- if (NULL == region_json && NULL == sub_groups) {
+ if (NULL == region_json && NULL == sub_objects) {
log_info(logger, MODULE_JSON2IRIS,
- "[%s:%d] A group of rule rule %d has neither regions, "
- "sub groups, nor refered another existed group",
+ "[%s:%d] A object of rule rule %d has neither regions, "
+ "sub objects, nor refered another existed object",
__FUNCTION__, __LINE__, tracking_rule_id);
}
}
if (parent_type == PARENT_TYPE_RULE) {
- ret = write_group2rule_line(&(group_info->group_id), 1, parent_id,
- group_negate_option, condition_index,
+ ret = write_object2rule_line(&(object_info->object_id), 1, parent_id,
+ object_negate_option, condition_index,
attribute, p_iris, g2c_table);
if (ret < 0) {
log_fatal(logger, MODULE_JSON2IRIS,
- "[%s:%d] rule:%d write group error",
+ "[%s:%d] rule:%d write object error",
__FUNCTION__, __LINE__, parent_id);
return -1;
}
@@ -921,14 +921,14 @@ write_rule_line(cJSON *rule, struct iris_description *p_iris,
}
int rule_id = item->valueint;
- cJSON *group_array = cJSON_GetObjectItem(rule, "groups");
- int group_num = cJSON_GetArraySize(group_array);
- int *condition_ids = ALLOC(int, group_num);
+ cJSON *object_array = cJSON_GetObjectItem(rule, "objects");
+ int object_num = cJSON_GetArraySize(object_array);
+ int *condition_ids = ALLOC(int, object_num);
int condition_num = 0;
- cJSON *group_obj = NULL;
+ cJSON *object_obj = NULL;
- cJSON_ArrayForEach(group_obj, group_array) {
- item = cJSON_GetObjectItem(group_obj, "condition_index");
+ cJSON_ArrayForEach(object_obj, object_array) {
+ item = cJSON_GetObjectItem(object_obj, "condition_index");
if (item) {
int i = 0;
int condition_index = item->valueint;
@@ -947,7 +947,7 @@ write_rule_line(cJSON *rule, struct iris_description *p_iris,
FREE(condition_ids);
if (condition_num == 0) {
- condition_num = group_num;
+ condition_num = object_num;
}
cJSON_AddNumberToObject(rule, "condition_num", condition_num);
@@ -1086,67 +1086,67 @@ static int write_index_file(struct iris_description *p_iris,
return 0;
}
-int recursive_traverse_sub_groups(cJSON *group_obj, struct iris_description *p_iris,
+int recursive_traverse_sub_objects(cJSON *object_obj, struct iris_description *p_iris,
struct log_handle *logger)
{
- cJSON *sub_group_array = cJSON_GetObjectItem(group_obj, "sub_groups");
- if (NULL == sub_group_array) {
+ cJSON *sub_object_array = cJSON_GetObjectItem(object_obj, "sub_objects");
+ if (NULL == sub_object_array) {
return 0;
}
- cJSON *item = cJSON_GetObjectItem(group_obj, "group_name");
+ cJSON *item = cJSON_GetObjectItem(object_obj, "object_name");
if (NULL == item || item->type != cJSON_String) {
log_fatal(logger, MODULE_JSON2IRIS,
- "[%s:%d] has no group_name before sub_groups.");
+ "[%s:%d] has no object_name before sub_objects.");
return -1;
}
- const char *parent_group_name = item->valuestring;
- struct group_info *parent_group = group_info_read(p_iris->group_name_map,
+ const char *parent_object_name = item->valuestring;
+ struct object_info *parent_object = object_info_read(p_iris->object_name_map,
item->valuestring);
- if (NULL == parent_group) {
- item = cJSON_GetObjectItem(group_obj, "group_id");
+ if (NULL == parent_object) {
+ item = cJSON_GetObjectItem(object_obj, "object_id");
if (NULL == item || item->type != cJSON_Number) {
log_fatal(logger, MODULE_JSON2IRIS,
- "[%s:%d] group_name:%s has no group_id.", parent_group_name);
+ "[%s:%d] object_name:%s has no object_id.", parent_object_name);
return -1;
}
- parent_group = group_info_add_unsafe(p_iris, parent_group_name, item->valueint);
+ parent_object = object_info_add_unsafe(p_iris, parent_object_name, item->valueint);
}
- cJSON *sub_group_obj = NULL;
- cJSON_ArrayForEach(sub_group_obj, sub_group_array) {
- cJSON *tmp_item1 = cJSON_GetObjectItem(sub_group_obj, "group_name");
+ cJSON *sub_object_obj = NULL;
+ cJSON_ArrayForEach(sub_object_obj, sub_object_array) {
+ cJSON *tmp_item1 = cJSON_GetObjectItem(sub_object_obj, "object_name");
if (NULL == tmp_item1 || tmp_item1->type != cJSON_String) {
log_fatal(logger, MODULE_JSON2IRIS,
- "[%s:%d]group:%s's sub_groups has no group_name",
- __FUNCTION__, __LINE__, parent_group_name);
+ "[%s:%d]object:%s's sub_objects has no object_name",
+ __FUNCTION__, __LINE__, parent_object_name);
return -1;
}
- int group_id = -1;
+ int object_id = -1;
int is_exclude = 0;
- cJSON *tmp_item2 = cJSON_GetObjectItem(sub_group_obj, "group_id");
+ cJSON *tmp_item2 = cJSON_GetObjectItem(sub_object_obj, "object_id");
if (NULL == tmp_item2) {
- struct group_info *group = group_info_read(p_iris->group_name_map,
+ struct object_info *object = object_info_read(p_iris->object_name_map,
tmp_item1->valuestring);
- assert(group != NULL);
- group_id = group->group_id;
+ assert(object != NULL);
+ object_id = object->object_id;
} else {
- group_id = tmp_item2->valueint;
+ object_id = tmp_item2->valueint;
}
- cJSON *tmp_item3 = cJSON_GetObjectItem(sub_group_obj, "is_exclude");
+ cJSON *tmp_item3 = cJSON_GetObjectItem(sub_object_obj, "is_exclude");
if (tmp_item3 != NULL && tmp_item3->type == cJSON_Number) {
is_exclude = tmp_item3->valueint;
}
if (0 == is_exclude) {
- utarray_push_back(parent_group->incl_sub_group_ids, &group_id);
+ utarray_push_back(parent_object->incl_sub_object_ids, &object_id);
} else {
- utarray_push_back(parent_group->excl_sub_group_ids, &group_id);
+ utarray_push_back(parent_object->excl_sub_object_ids, &object_id);
}
- int ret = recursive_traverse_sub_groups(sub_group_obj, p_iris, logger);
+ int ret = recursive_traverse_sub_objects(sub_object_obj, p_iris, logger);
if (ret < 0) {
return -1;
}
@@ -1155,21 +1155,21 @@ int recursive_traverse_sub_groups(cJSON *group_obj, struct iris_description *p_i
return 0;
}
-static int write_group2group_rule(struct iris_description *p_iris,
+static int write_object2object_rule(struct iris_description *p_iris,
struct log_handle *logger)
{
int ret = 0;
- struct group_info *group_info = NULL, *tmp_group_info = NULL;
+ struct object_info *object_info = NULL, *tmp_object_info = NULL;
- HASH_ITER(hh, p_iris->group_name_map, group_info, tmp_group_info) {
- ret = write_group2group_line(group_info->group_id,
- group_info->incl_sub_group_ids,
- group_info->excl_sub_group_ids,
+ HASH_ITER(hh, p_iris->object_name_map, object_info, tmp_object_info) {
+ ret = write_object2object_line(object_info->object_id,
+ object_info->incl_sub_object_ids,
+ object_info->excl_sub_object_ids,
p_iris);
if (ret < 0) {
log_fatal(logger, MODULE_JSON2IRIS,
- "[%s:%d] write group2group line failed for super_group:%d",
- __FUNCTION__, __LINE__, group_info->group_id);
+ "[%s:%d] write object2object line failed for super_object:%d",
+ __FUNCTION__, __LINE__, object_info->object_id);
return -1;
}
}
@@ -1182,7 +1182,7 @@ static int write_iris(cJSON *json, struct iris_description *p_iris,
{
int i = 0;
int ret = 0;
- static struct group_info *parent_group = NULL; // TODO
+ static struct object_info *parent_object = NULL; // TODO
cJSON *plug_tables = cJSON_GetObjectItem(json, "plugin_table");
if (plug_tables != NULL) {
@@ -1193,35 +1193,35 @@ static int write_iris(cJSON *json, struct iris_description *p_iris,
}
}
- cJSON *group_array = cJSON_GetObjectItem(json, "groups"); // sub-group to group
- if (group_array != NULL) {
- cJSON *group_obj = NULL;
- cJSON_ArrayForEach(group_obj, group_array) {
- const char *parent_group_name = NULL;
- cJSON *item = cJSON_GetObjectItem(group_obj, "parent_group");
+ cJSON *object_array = cJSON_GetObjectItem(json, "objects"); // sub-object to object
+ if (object_array != NULL) {
+ cJSON *object_obj = NULL;
+ cJSON_ArrayForEach(object_obj, object_array) {
+ const char *parent_object_name = NULL;
+ cJSON *item = cJSON_GetObjectItem(object_obj, "parent_object");
if (NULL == item || item->type != cJSON_String) {
- parent_group_name = untitled_group_name;
+ parent_object_name = untitled_object_name;
} else {
- parent_group_name = item->string;
+ parent_object_name = item->string;
}
- parent_group = group_info_read(p_iris->group_name_map, parent_group_name);
- if (NULL == parent_group) {
- parent_group = group_info_add_unsafe(p_iris, parent_group_name,
- untitled_group_id);
+ parent_object = object_info_read(p_iris->object_name_map, parent_object_name);
+ if (NULL == parent_object) {
+ parent_object = object_info_add_unsafe(p_iris, parent_object_name,
+ untitled_object_id);
}
- item = cJSON_GetObjectItem(group_obj, "group_id");
+ item = cJSON_GetObjectItem(object_obj, "object_id");
if (NULL == item || item->type != cJSON_Number) {
log_fatal(logger, MODULE_JSON2IRIS,
- "[%s:%d]Global groups has group with no group_id.",
+ "[%s:%d]Global objects has object with no object_id.",
__FUNCTION__, __LINE__);
return -1;
}
- utarray_push_back(parent_group->incl_sub_group_ids, &item->valueint);
- ret = write_group_rule(group_obj, parent_group->group_id,
- PARENT_TYPE_GROUP, 0, 0, p_iris, logger);
+ utarray_push_back(parent_object->incl_sub_object_ids, &item->valueint);
+ ret = write_object_rule(object_obj, parent_object->object_id,
+ PARENT_TYPE_OBJECT, 0, 0, p_iris, logger);
if (ret < 0) {
return -1;
}
@@ -1245,26 +1245,26 @@ static int write_iris(cJSON *json, struct iris_description *p_iris,
return -1;
}
- group_array = cJSON_GetObjectItem(rule_obj, "groups");
- if (NULL == group_array) {
+ object_array = cJSON_GetObjectItem(rule_obj, "objects");
+ if (NULL == object_array) {
log_fatal(logger, MODULE_JSON2IRIS,
- "[%s:%d] rule rule %d have no group",
+ "[%s:%d] rule rule %d have no object",
__FUNCTION__, __LINE__, rule_id);
return -1;
}
- int group_cnt = cJSON_GetArraySize(group_array);
- if (group_cnt <= 0) {
+ int object_cnt = cJSON_GetArraySize(object_array);
+ if (object_cnt <= 0) {
log_fatal(logger, MODULE_JSON2IRIS,
- "[%s:%d] rule rule %d have no groups",
+ "[%s:%d] rule rule %d have no objects",
__FUNCTION__, __LINE__, rule_id);
return -1;
}
i = 0;
- cJSON *group_obj = NULL;
- cJSON_ArrayForEach(group_obj, group_array) {
- ret = write_group_rule(group_obj, rule_id, PARENT_TYPE_RULE,
+ cJSON *object_obj = NULL;
+ cJSON_ArrayForEach(object_obj, object_array) {
+ ret = write_object_rule(object_obj, rule_id, PARENT_TYPE_RULE,
rule_id, i, p_iris, logger);
if (ret < 0) {
return -1;
@@ -1274,11 +1274,11 @@ static int write_iris(cJSON *json, struct iris_description *p_iris,
}
cJSON_ArrayForEach(rule_obj, rule_array) {
- cJSON *group_array = cJSON_GetObjectItem(rule_obj, "groups");
+ cJSON *object_array = cJSON_GetObjectItem(rule_obj, "objects");
- cJSON *group_obj = NULL;
- cJSON_ArrayForEach(group_obj, group_array) {
- ret = recursive_traverse_sub_groups(group_obj, p_iris, logger);
+ cJSON *object_obj = NULL;
+ cJSON_ArrayForEach(object_obj, object_array) {
+ ret = recursive_traverse_sub_objects(object_obj, p_iris, logger);
if (ret < 0) {
return -1;
}
@@ -1286,7 +1286,7 @@ static int write_iris(cJSON *json, struct iris_description *p_iris,
}
}
- ret = write_group2group_rule(p_iris, logger);
+ ret = write_object2object_rule(p_iris, logger);
if (ret < 0) {
return -1;
}
@@ -1307,8 +1307,8 @@ int json2iris(const char *json_buff, const char *json_filename,
int ret = -1;
cJSON *tmp_obj = NULL;
const char *rule_tbl_name = NULL;
- const char *group2rule_tbl_name = NULL;
- const char *group2group_tbl_name = NULL;
+ const char *object2rule_tbl_name = NULL;
+ const char *object2object_tbl_name = NULL;
struct iris_description iris_cfg;
memset(&iris_cfg, 0, sizeof(iris_cfg));
@@ -1326,19 +1326,19 @@ int json2iris(const char *json_buff, const char *json_filename,
rule_tbl_name = tmp_obj->valuestring;
}
- tmp_obj = cJSON_GetObjectItem(json, "group2rule_table");
+ tmp_obj = cJSON_GetObjectItem(json, "object2rule_table");
if (tmp_obj) {
- group2rule_tbl_name = tmp_obj->valuestring;
+ object2rule_tbl_name = tmp_obj->valuestring;
}
- tmp_obj = cJSON_GetObjectItem(json, "group2group_table");
+ tmp_obj = cJSON_GetObjectItem(json, "object2object_table");
if (tmp_obj) {
- group2group_tbl_name = tmp_obj->valuestring;
+ object2object_tbl_name = tmp_obj->valuestring;
}
ret = set_iris_descriptor(json_filename, json, encrypt_key, encrypt_algo,
- rule_tbl_name, group2rule_tbl_name,
- group2group_tbl_name, redis_write_ctx, &iris_cfg);
+ rule_tbl_name, object2rule_tbl_name,
+ object2object_tbl_name, redis_write_ctx, &iris_cfg);
if (ret < 0) {
goto error_out;
}
diff --git a/src/maat_api.c b/src/maat_api.c
index 0cf4ffa..660d094 100644
--- a/src/maat_api.c
+++ b/src/maat_api.c
@@ -29,7 +29,7 @@
#include "ip_matcher.h"
#include "adapter_hs.h"
#include "maat_garbage_collection.h"
-#include "maat_group.h"
+#include "maat_object.h"
#include "maat_expr.h"
#include "maat_flag.h"
#include "maat_interval.h"
@@ -288,13 +288,13 @@ int maat_options_set_hit_path_enabled(struct maat_options *opts)
return 0;
}
-int maat_options_set_hit_group_enabled(struct maat_options *opts)
+int maat_options_set_hit_object_enabled(struct maat_options *opts)
{
if (NULL == opts) {
return -1;
}
- opts->hit_group_on = 1;
+ opts->hit_object_on = 1;
return 0;
}
@@ -1081,22 +1081,22 @@ flag_scan(struct table_manager *tbl_mgr, int thread_id, long long flag,
}
}
- int group_hit_cnt = flag_runtime_scan((struct flag_runtime *)flag_rt,
+ int object_hit_cnt = flag_runtime_scan((struct flag_runtime *)flag_rt,
thread_id, flag, attribute_id, state);
- if (group_hit_cnt <= 0) {
- return group_hit_cnt;
+ if (object_hit_cnt <= 0) {
+ return object_hit_cnt;
}
if (virt_rt != NULL) {
- //Note: group_hit_cnt is equivalent to item_hit_cnt
+ //Note: object_hit_cnt is equivalent to item_hit_cnt
attribute_runtime_hit_item_num_add((struct attribute_runtime *)virt_rt,
- thread_id, group_hit_cnt);
+ thread_id, object_hit_cnt);
attribute_runtime_hit_times_inc((struct attribute_runtime *)virt_rt, thread_id);
}
flag_runtime_hit_times_inc((struct flag_runtime *)flag_rt, thread_id);
- return group_hit_cnt;
+ return object_hit_cnt;
}
static int
@@ -1133,22 +1133,22 @@ interval_scan(struct table_manager *tbl_mgr, int thread_id, long long integer,
}
}
- int group_hit_cnt = interval_runtime_scan((struct interval_runtime *)interval_rt,
+ int object_hit_cnt = interval_runtime_scan((struct interval_runtime *)interval_rt,
thread_id, integer, attribute_id, state);
- if (group_hit_cnt <= 0) {
- return group_hit_cnt;
+ if (object_hit_cnt <= 0) {
+ return object_hit_cnt;
}
if (virt_rt != NULL) {
- //Note: group_hit_cnt is equivalent to item_hit_cnt
+ //Note: object_hit_cnt is equivalent to item_hit_cnt
attribute_runtime_hit_item_num_add((struct attribute_runtime *)virt_rt,
- thread_id, group_hit_cnt);
+ thread_id, object_hit_cnt);
attribute_runtime_hit_times_inc((struct attribute_runtime *)virt_rt, thread_id);
}
interval_runtime_hit_times_inc((struct interval_runtime *)interval_rt, thread_id);
- return group_hit_cnt;
+ return object_hit_cnt;
}
static int
@@ -1179,22 +1179,22 @@ ipv4_scan(struct table_manager *tbl_mgr, int thread_id, uint32_t ip_addr,
}
}
- int group_hit_cnt = ip_runtime_scan((struct ip_runtime *)ip_rt, thread_id, IPv4,
+ int object_hit_cnt = ip_runtime_scan((struct ip_runtime *)ip_rt, thread_id, IPv4,
(uint8_t *)&ip_addr, port, attribute_id, state);
- if (group_hit_cnt <= 0) {
- return group_hit_cnt;
+ if (object_hit_cnt <= 0) {
+ return object_hit_cnt;
}
if (virt_rt != NULL) {
- //Note: group_hit_cnt is equivalent to item_hit_cnt
+ //Note: object_hit_cnt is equivalent to item_hit_cnt
attribute_runtime_hit_item_num_add((struct attribute_runtime *)virt_rt,
- thread_id, group_hit_cnt);
+ thread_id, object_hit_cnt);
attribute_runtime_hit_times_inc((struct attribute_runtime *)virt_rt, thread_id);
}
ip_runtime_hit_times_inc((struct ip_runtime *)ip_rt, thread_id);
- return group_hit_cnt;
+ return object_hit_cnt;
}
static int
@@ -1225,22 +1225,22 @@ ipv6_scan(struct table_manager *tbl_mgr, int thread_id, uint8_t *ip_addr,
}
}
- int group_hit_cnt = ip_runtime_scan((struct ip_runtime *)ip_rt, thread_id, IPv6,
+ int object_hit_cnt = ip_runtime_scan((struct ip_runtime *)ip_rt, thread_id, IPv6,
ip_addr, port, attribute_id, state);
- if (group_hit_cnt <= 0) {
- return group_hit_cnt;
+ if (object_hit_cnt <= 0) {
+ return object_hit_cnt;
}
if (virt_rt != NULL) {
- //Note: group_hit_cnt is equivalent to item_hit_cnt
+ //Note: object_hit_cnt is equivalent to item_hit_cnt
attribute_runtime_hit_item_num_add((struct attribute_runtime *)virt_rt,
- thread_id, group_hit_cnt);
+ thread_id, object_hit_cnt);
attribute_runtime_hit_times_inc((struct attribute_runtime *)virt_rt, thread_id);
}
ip_runtime_hit_times_inc((struct ip_runtime *)ip_rt, thread_id);
- return group_hit_cnt;
+ return object_hit_cnt;
}
static int
@@ -1280,27 +1280,27 @@ string_scan(struct table_manager *tbl_mgr, int thread_id,
}
}
- int group_hit_cnt = expr_runtime_scan((struct expr_runtime *)expr_rt,
+ int object_hit_cnt = expr_runtime_scan((struct expr_runtime *)expr_rt,
thread_id, data, data_len,
attribute_id, state);
- if (group_hit_cnt <= 0) {
- return group_hit_cnt;
+ if (object_hit_cnt <= 0) {
+ return object_hit_cnt;
}
if (virt_rt != NULL) {
- //Note: group_hit_cnt is equivalent to item_hit_cnt
+ //Note: object_hit_cnt is equivalent to item_hit_cnt
attribute_runtime_hit_item_num_add((struct attribute_runtime *)virt_rt,
- thread_id, group_hit_cnt);
+ thread_id, object_hit_cnt);
attribute_runtime_hit_times_inc((struct attribute_runtime *)virt_rt, thread_id);
}
expr_runtime_hit_times_inc((struct expr_runtime *)expr_rt, thread_id);
- return group_hit_cnt;
+ return object_hit_cnt;
}
static size_t
-group_to_rule(struct maat *maat_inst, long long *results, size_t n_result,
+object_to_rule(struct maat *maat_inst, long long *results, size_t n_result,
struct maat_state *state)
{
int rule_table_id =
@@ -1363,9 +1363,9 @@ int maat_scan_flag(struct maat *maat_inst, int table_id,
}
alignment_int64_array_add(maat_inst->stat->thread_call_cnt, state->thread_id, 1);
- int hit_group_cnt = flag_scan(maat_inst->tbl_mgr, state->thread_id, flag,
+ int hit_object_cnt = flag_scan(maat_inst->tbl_mgr, state->thread_id, flag,
phy_table_id, attribute_id, state);
- if (hit_group_cnt < 0) {
+ if (hit_object_cnt < 0) {
maat_inst->stat->scan_err_cnt++;
return MAAT_SCAN_ERR;
}
@@ -1373,8 +1373,8 @@ int maat_scan_flag(struct maat *maat_inst, int table_id,
maat_runtime_ref_inc(maat_rt, state->thread_id);
size_t sum_hit_rule_cnt = 0;
- if (hit_group_cnt > 0) {
- sum_hit_rule_cnt = group_to_rule(maat_inst, results, n_result, state);
+ if (hit_object_cnt > 0) {
+ sum_hit_rule_cnt = object_to_rule(maat_inst, results, n_result, state);
*n_hit_result = sum_hit_rule_cnt;
}
@@ -1397,7 +1397,7 @@ int maat_scan_flag(struct maat *maat_inst, int table_id,
if (sum_hit_rule_cnt > 0) {
return MAAT_SCAN_HIT;
- } else if (hit_group_cnt > 0) {
+ } else if (hit_object_cnt > 0) {
return MAAT_SCAN_HALF_HIT;
} else {
return MAAT_SCAN_OK;
@@ -1448,9 +1448,9 @@ int maat_scan_integer(struct maat *maat_inst, int table_id,
}
alignment_int64_array_add(maat_inst->stat->thread_call_cnt, state->thread_id, 1);
- int hit_group_cnt = interval_scan(maat_inst->tbl_mgr, state->thread_id, integer,
+ int hit_object_cnt = interval_scan(maat_inst->tbl_mgr, state->thread_id, integer,
phy_table_id, attribute_id, state);
- if (hit_group_cnt < 0) {
+ if (hit_object_cnt < 0) {
maat_inst->stat->scan_err_cnt++;
return MAAT_SCAN_ERR;
}
@@ -1458,8 +1458,8 @@ int maat_scan_integer(struct maat *maat_inst, int table_id,
maat_runtime_ref_inc(maat_rt, state->thread_id);
size_t sum_hit_rule_cnt = 0;
- if (hit_group_cnt > 0) {
- sum_hit_rule_cnt = group_to_rule(maat_inst, results, n_result, state);
+ if (hit_object_cnt > 0) {
+ sum_hit_rule_cnt = object_to_rule(maat_inst, results, n_result, state);
*n_hit_result = sum_hit_rule_cnt;
}
@@ -1482,7 +1482,7 @@ int maat_scan_integer(struct maat *maat_inst, int table_id,
if (sum_hit_rule_cnt > 0) {
return MAAT_SCAN_HIT;
- } else if (hit_group_cnt > 0) {
+ } else if (hit_object_cnt > 0) {
return MAAT_SCAN_HALF_HIT;
} else {
return MAAT_SCAN_OK;
@@ -1532,9 +1532,9 @@ int maat_scan_ipv4_port(struct maat *maat_inst, int table_id, uint32_t ip_addr,
}
alignment_int64_array_add(maat_inst->stat->thread_call_cnt, state->thread_id, 1);
- int hit_group_cnt = ipv4_scan(maat_inst->tbl_mgr, state->thread_id, ip_addr, port,
+ int hit_object_cnt = ipv4_scan(maat_inst->tbl_mgr, state->thread_id, ip_addr, port,
phy_table_id, attribute_id, state);
- if (hit_group_cnt < 0) {
+ if (hit_object_cnt < 0) {
maat_inst->stat->scan_err_cnt++;
return MAAT_SCAN_ERR;
}
@@ -1542,8 +1542,8 @@ int maat_scan_ipv4_port(struct maat *maat_inst, int table_id, uint32_t ip_addr,
maat_runtime_ref_inc(maat_rt, state->thread_id);
size_t sum_hit_rule_cnt = 0;
- if (hit_group_cnt > 0) {
- sum_hit_rule_cnt = group_to_rule(maat_inst, results, n_result, state);
+ if (hit_object_cnt > 0) {
+ sum_hit_rule_cnt = object_to_rule(maat_inst, results, n_result, state);
*n_hit_result = sum_hit_rule_cnt;
}
@@ -1566,7 +1566,7 @@ int maat_scan_ipv4_port(struct maat *maat_inst, int table_id, uint32_t ip_addr,
if (sum_hit_rule_cnt > 0) {
return MAAT_SCAN_HIT;
- } else if (hit_group_cnt > 0) {
+ } else if (hit_object_cnt > 0) {
return MAAT_SCAN_HALF_HIT;
} else {
return MAAT_SCAN_OK;
@@ -1616,9 +1616,9 @@ int maat_scan_ipv6_port(struct maat *maat_inst, int table_id, uint8_t *ip_addr,
}
alignment_int64_array_add(maat_inst->stat->thread_call_cnt, state->thread_id, 1);
- int hit_group_cnt = ipv6_scan(maat_inst->tbl_mgr, state->thread_id, ip_addr, port,
+ int hit_object_cnt = ipv6_scan(maat_inst->tbl_mgr, state->thread_id, ip_addr, port,
phy_table_id, attribute_id, state);
- if (hit_group_cnt < 0) {
+ if (hit_object_cnt < 0) {
maat_inst->stat->scan_err_cnt++;
return MAAT_SCAN_ERR;
}
@@ -1626,8 +1626,8 @@ int maat_scan_ipv6_port(struct maat *maat_inst, int table_id, uint8_t *ip_addr,
maat_runtime_ref_inc(maat_rt, state->thread_id);
size_t sum_hit_rule_cnt = 0;
- if (hit_group_cnt > 0) {
- sum_hit_rule_cnt = group_to_rule(maat_inst, results, n_result, state);
+ if (hit_object_cnt > 0) {
+ sum_hit_rule_cnt = object_to_rule(maat_inst, results, n_result, state);
*n_hit_result = sum_hit_rule_cnt;
}
@@ -1650,7 +1650,7 @@ int maat_scan_ipv6_port(struct maat *maat_inst, int table_id, uint8_t *ip_addr,
if (sum_hit_rule_cnt > 0) {
return MAAT_SCAN_HIT;
- } else if (hit_group_cnt > 0) {
+ } else if (hit_object_cnt > 0) {
return MAAT_SCAN_HALF_HIT;
} else {
return MAAT_SCAN_OK;
@@ -1719,9 +1719,9 @@ int maat_scan_string(struct maat *maat_inst, int table_id,
}
alignment_int64_array_add(maat_inst->stat->thread_call_cnt, state->thread_id, 1);
- int hit_group_cnt = string_scan(maat_inst->tbl_mgr, state->thread_id, data,
+ int hit_object_cnt = string_scan(maat_inst->tbl_mgr, state->thread_id, data,
data_len, phy_table_id, attribute_id, state);
- if (hit_group_cnt < 0) {
+ if (hit_object_cnt < 0) {
maat_inst->stat->scan_err_cnt++;
return MAAT_SCAN_ERR;
}
@@ -1729,8 +1729,8 @@ int maat_scan_string(struct maat *maat_inst, int table_id,
maat_runtime_ref_inc(maat_rt, state->thread_id);
size_t sum_hit_rule_cnt = 0;
- if (hit_group_cnt > 0) {
- sum_hit_rule_cnt = group_to_rule(maat_inst, results, n_result, state);
+ if (hit_object_cnt > 0) {
+ sum_hit_rule_cnt = object_to_rule(maat_inst, results, n_result, state);
*n_hit_result = sum_hit_rule_cnt;
}
@@ -1753,21 +1753,21 @@ int maat_scan_string(struct maat *maat_inst, int table_id,
if (sum_hit_rule_cnt > 0) {
return MAAT_SCAN_HIT;
- } else if (hit_group_cnt > 0) {
+ } else if (hit_object_cnt > 0) {
return MAAT_SCAN_HALF_HIT;
} else {
return MAAT_SCAN_OK;
}
}
-static void maat_state_add_hit_group(struct maat_state *state, int table_id,
- struct maat_hit_group *groups, size_t n_group)
+static void maat_state_add_hit_object(struct maat_state *state, int table_id,
+ struct maat_hit_object *objects, size_t n_object)
{
struct maat *maat_inst = state->maat_inst;
- //clear rule_state->last_hit_group
+ //clear rule_state->last_hit_object
if (state != NULL && state->rule_state != NULL) {
- rule_state_clear_last_hit_group(state->rule_state);
+ rule_state_clear_last_hit_object(state->rule_state);
}
if (NULL == state->rule_state) {
@@ -1776,15 +1776,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;
- if (n_group >= MAX_HIT_GROUP_NUM) {
- n_hit_item = MAX_HIT_GROUP_NUM;
+ size_t n_hit_item = n_object;
+ if (n_object >= MAX_HIT_OBJECT_NUM) {
+ n_hit_item = MAX_HIT_OBJECT_NUM;
}
struct maat_item hit_items[n_hit_item];
for (size_t i = 0; i < n_hit_item; i++) {
- hit_items[i].item_id = groups[i].item_id;
- hit_items[i].group_id = groups[i].group_id;
+ hit_items[i].item_id = objects[i].item_id;
+ hit_items[i].object_id = objects[i].object_id;
}
rule_state_update(state->rule_state, maat_inst, table_id,
@@ -1793,7 +1793,7 @@ static void maat_state_add_hit_group(struct maat_state *state, int table_id,
}
static void
-maat_state_activate_hit_not_group(struct maat_state *state, int table_id)
+maat_state_activate_hit_not_object(struct maat_state *state, int table_id)
{
if (NULL == state) {
return;
@@ -1812,22 +1812,22 @@ maat_state_activate_hit_not_group(struct maat_state *state, int table_id)
return;
}
- //clear rule_state->last_hit_group
+ //clear rule_state->last_hit_object
if (state != NULL && state->rule_state != NULL) {
- rule_state_clear_last_hit_group(state->rule_state);
+ rule_state_clear_last_hit_object(state->rule_state);
}
rule_state_not_logic_update(state->rule_state, rule_rt, maat_inst,
table_id, state->Nth_scan);
}
-int maat_scan_group(struct maat *maat_inst, int table_id,
- struct maat_hit_group *groups, size_t n_group,
+int maat_scan_object(struct maat *maat_inst, int table_id,
+ struct maat_hit_object *objects, size_t n_object,
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 == groups) || (0 == n_group) || (NULL == results) ||
+ (NULL == objects) || (0 == n_object) || (NULL == results) ||
(0 == n_result) || (NULL == n_hit_result) || (NULL == state) ||
(state->thread_id < 0)) {
return -1;
@@ -1852,15 +1852,15 @@ int maat_scan_group(struct maat *maat_inst, int table_id,
attribute_runtime_hit_times_inc((struct attribute_runtime *)virt_rt,
state->thread_id);
attribute_runtime_hit_item_num_add((struct attribute_runtime *)virt_rt,
- state->thread_id, n_group);
+ state->thread_id, n_object);
}
}
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, groups, n_group);
- size_t hit_rule_cnt = group_to_rule(maat_inst, results, n_result, state);
+ maat_state_add_hit_object(state, table_id, objects, n_object);
+ size_t hit_rule_cnt = object_to_rule(maat_inst, results, n_result, state);
*n_hit_result = hit_rule_cnt;
maat_runtime_ref_dec(maat_rt, state->thread_id);
@@ -1895,8 +1895,8 @@ int maat_scan_not_logic(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_activate_hit_not_group(state, table_id);
- size_t hit_rule_cnt = group_to_rule(maat_inst, results, n_result, state);
+ maat_state_activate_hit_not_object(state, table_id);
+ size_t hit_rule_cnt = object_to_rule(maat_inst, results, n_result, state);
*n_hit_result = hit_rule_cnt;
maat_runtime_ref_dec(maat_rt, state->thread_id);
@@ -2004,22 +2004,22 @@ static int expr_stream_scan(struct maat_stream *stream, const char *data,
}
}
- int group_hit_cnt = expr_runtime_stream_scan(stream->expr_rt_stream, data,
+ int object_hit_cnt = expr_runtime_stream_scan(stream->expr_rt_stream, data,
data_len, stream->attribute_id, state);
- if (group_hit_cnt <= 0) {
- return group_hit_cnt;
+ if (object_hit_cnt <= 0) {
+ return object_hit_cnt;
}
if (virt_rt != NULL) {
- //Note: group_hit_cnt is equivalent to item_hit_cnt
+ //Note: object_hit_cnt is equivalent to item_hit_cnt
attribute_runtime_hit_item_num_add((struct attribute_runtime *)virt_rt,
- stream->thread_id, group_hit_cnt);
+ stream->thread_id, object_hit_cnt);
attribute_runtime_hit_times_inc((struct attribute_runtime *)virt_rt, stream->thread_id);
}
expr_runtime_stream_hit_times_inc(stream->expr_rt_stream, stream->thread_id);
- return group_hit_cnt;
+ return object_hit_cnt;
}
int maat_stream_scan(struct maat_stream *maat_stream, const char *data, int data_len,
@@ -2055,15 +2055,15 @@ int maat_stream_scan(struct maat_stream *maat_stream, const char *data, int data
alignment_int64_array_add(maat_inst->stat->thread_call_cnt,
maat_stream->thread_id, 1);
- int hit_group_cnt = expr_stream_scan(maat_stream, data, data_len, state);
- if (hit_group_cnt < 0) {
+ int hit_object_cnt = expr_stream_scan(maat_stream, data, data_len, state);
+ if (hit_object_cnt < 0) {
maat_inst->stat->scan_err_cnt++;
return MAAT_SCAN_ERR;
}
size_t sum_hit_rule_cnt = 0;
- if (hit_group_cnt > 0) {
- sum_hit_rule_cnt = group_to_rule(maat_inst, results, n_result, state);
+ if (hit_object_cnt > 0) {
+ sum_hit_rule_cnt = object_to_rule(maat_inst, results, n_result, state);
*n_hit_result = sum_hit_rule_cnt;
}
@@ -2081,7 +2081,7 @@ int maat_stream_scan(struct maat_stream *maat_stream, const char *data, int data
if (sum_hit_rule_cnt > 0) {
return MAAT_SCAN_HIT;
- } else if (hit_group_cnt > 0) {
+ } else if (hit_object_cnt > 0) {
return MAAT_SCAN_HALF_HIT;
} else {
return MAAT_SCAN_OK;
@@ -2309,13 +2309,13 @@ int maat_state_get_hit_paths(struct maat_state *state, struct maat_hit_path *pat
return -1;
}
- int g2g_table_id = table_manager_get_group2group_table_id(maat_inst->tbl_mgr);
+ int g2g_table_id = table_manager_get_object2object_table_id(maat_inst->tbl_mgr);
void *g2g_runtime = table_manager_get_runtime(maat_inst->tbl_mgr, g2g_table_id);
size_t hit_path_cnt =
rule_state_get_internal_hit_paths(state->rule_state,
(struct rule_runtime *)rule_rt,
- (struct group2group_runtime *)g2g_runtime,
+ (struct object2object_runtime *)g2g_runtime,
path_array, array_size);
return rule_runtime_get_hit_paths((struct rule_runtime *)rule_rt,
@@ -2332,11 +2332,11 @@ size_t maat_state_get_scan_count(struct maat_state *state)
return state->Nth_scan;
}
-int maat_state_get_direct_hit_groups(struct maat_state *state,
- struct maat_hit_group *group_array,
+int maat_state_get_direct_hit_objects(struct maat_state *state,
+ struct maat_hit_object *object_array,
size_t array_size)
{
- if (NULL == state || NULL == group_array || 0 == array_size) {
+ if (NULL == state || NULL == object_array || 0 == array_size) {
return -1;
}
@@ -2344,24 +2344,24 @@ int maat_state_get_direct_hit_groups(struct maat_state *state,
return 0;
}
- return rule_state_get_direct_hit_groups(state->rule_state,
- group_array, array_size);
+ return rule_state_get_direct_hit_objects(state->rule_state,
+ object_array, array_size);
}
-size_t maat_state_get_direct_hit_group_cnt(struct maat_state *state)
+size_t maat_state_get_direct_hit_object_cnt(struct maat_state *state)
{
if (NULL == state || NULL == state->rule_state) {
return 0;
}
- return rule_state_get_direct_hit_group_cnt(state->rule_state);
+ return rule_state_get_direct_hit_object_cnt(state->rule_state);
}
-int maat_state_get_indirect_hit_groups(struct maat_state *state,
- struct maat_hit_group *group_array,
+int maat_state_get_indirect_hit_objects(struct maat_state *state,
+ struct maat_hit_object *object_array,
size_t array_size)
{
- if (NULL == state || NULL == group_array || 0 == array_size) {
+ if (NULL == state || NULL == object_array || 0 == array_size) {
return -1;
}
@@ -2369,36 +2369,36 @@ int maat_state_get_indirect_hit_groups(struct maat_state *state,
return 0;
}
- return rule_state_get_indirect_hit_groups(state->rule_state,
- group_array, array_size);
+ return rule_state_get_indirect_hit_objects(state->rule_state,
+ object_array, array_size);
}
-size_t maat_state_get_indirect_hit_group_cnt(struct maat_state *state)
+size_t maat_state_get_indirect_hit_object_cnt(struct maat_state *state)
{
if (NULL == state || NULL == state->rule_state) {
return 0;
}
- return rule_state_get_indirect_hit_group_cnt(state->rule_state);
+ return rule_state_get_indirect_hit_object_cnt(state->rule_state);
}
-int maat_state_get_last_hit_groups(struct maat_state *state,
- struct maat_hit_group *group_array,
+int maat_state_get_last_hit_objects(struct maat_state *state,
+ struct maat_hit_object *object_array,
size_t array_size)
{
if (NULL == state || NULL == state->rule_state) {
return 0;
}
- return rule_state_get_last_hit_groups(state->rule_state,
- group_array, array_size);
+ return rule_state_get_last_hit_objects(state->rule_state,
+ object_array, array_size);
}
-size_t maat_state_get_last_hit_group_cnt(struct maat_state *state)
+size_t maat_state_get_last_hit_object_cnt(struct maat_state *state)
{
if (NULL == state || NULL == state->rule_state) {
return 0;
}
- return rule_state_get_last_hit_group_cnt(state->rule_state);
+ return rule_state_get_last_hit_object_cnt(state->rule_state);
} \ No newline at end of file
diff --git a/src/maat_command.c b/src/maat_command.c
index ec6a588..8a76b49 100644
--- a/src/maat_command.c
+++ b/src/maat_command.c
@@ -158,7 +158,7 @@ redis_flushDB(redisContext *ctx, int db_index, struct log_handle *logger)
append_cmd_cnt++;
redisAppendCommand(ctx, "SET %s 1", mr_region_id_var);
append_cmd_cnt++;
- redisAppendCommand(ctx, "SET %s 1", mr_group_id_var);
+ redisAppendCommand(ctx, "SET %s 1", mr_object_id_var);
append_cmd_cnt++;
redisAppendCommand(ctx, "EXEC");
append_cmd_cnt++;
diff --git a/src/maat_expr.c b/src/maat_expr.c
index 0ad3a2c..a4d9076 100644
--- a/src/maat_expr.c
+++ b/src/maat_expr.c
@@ -21,7 +21,7 @@
#include "maat.h"
#include "maat_core.h"
#include "maat_rule.h"
-#include "maat_group.h"
+#include "maat_object.h"
#include "alignment.h"
#include "maat_garbage_collection.h"
@@ -35,7 +35,7 @@
struct expr_schema {
int item_id_column;
- int group_id_column;
+ int object_id_column;
int district_column;
int keywords_column;
int expr_type_column;
@@ -63,7 +63,7 @@ enum match_method {
struct expr_item {
long long item_id;
- long long group_id;
+ long long object_id;
char keywords[MAX_KEYWORDS_STR_LEN + 1];
enum expr_type expr_type;
void *user_data;
@@ -175,15 +175,15 @@ expr_item_new(struct expr_schema *expr_schema, const char *table_name,
}
expr_item->item_id = atoll(line + column_offset);
- ret = get_column_pos(line, expr_schema->group_id_column, &column_offset,
+ ret = get_column_pos(line, expr_schema->object_id_column, &column_offset,
&column_len);
if (ret < 0) {
log_fatal(expr_rt->logger, MODULE_EXPR,
- "[%s:%d] expr table:<%s> has no group_id in line:%s",
+ "[%s:%d] expr table:<%s> has no object_id in line:%s",
__FUNCTION__, __LINE__, table_name, line);
goto error;
}
- expr_item->group_id = atoll(line + column_offset);
+ expr_item->object_id = atoll(line + column_offset);
ret = get_column_pos(line, expr_schema->keywords_column, &column_offset, &column_len);
if (ret < 0) {
@@ -311,12 +311,12 @@ void *expr_schema_new(cJSON *json, struct table_manager *tbl_mgr,
goto error;
}
- custom_item = cJSON_GetObjectItem(item, "group_id");
+ custom_item = cJSON_GetObjectItem(item, "object_id");
if (custom_item != NULL && custom_item->type == cJSON_Number) {
- expr_schema->group_id_column = custom_item->valueint;
+ expr_schema->object_id_column = custom_item->valueint;
} else {
log_fatal(logger, MODULE_EXPR,
- "[%s:%d] expr table:<%s> schema has no group_id column",
+ "[%s:%d] expr table:<%s> schema has no object_id column",
__FUNCTION__, __LINE__, table_name);
goto error;
}
@@ -953,9 +953,9 @@ int expr_runtime_scan(struct expr_runtime *expr_rt, int thread_id,
const char *data, size_t data_len,
int attribute_id, struct maat_state *state)
{
- //clear rule_state->last_hit_group
+ //clear rule_state->last_hit_object
if (state != NULL && state->rule_state != NULL) {
- rule_state_clear_last_hit_group(state->rule_state);
+ rule_state_clear_last_hit_object(state->rule_state);
}
if (0 == expr_rt->rule_num) {
@@ -1002,7 +1002,7 @@ int expr_runtime_scan(struct expr_runtime *expr_rt, int thread_id,
}
hit_maat_items[real_hit_item_num].item_id = item_id;
- hit_maat_items[real_hit_item_num].group_id = expr_item->group_id;
+ hit_maat_items[real_hit_item_num].object_id = expr_item->object_id;
real_hit_item_num++;
}
}
@@ -1049,9 +1049,9 @@ int expr_runtime_stream_scan(struct expr_runtime_stream *expr_rt_stream,
{
struct expr_runtime *expr_rt = expr_rt_stream->ref_expr_rt;
- //clear rule_state->last_hit_group
+ //clear rule_state->last_hit_object
if (state != NULL && state->rule_state != NULL) {
- rule_state_clear_last_hit_group(state->rule_state);
+ rule_state_clear_last_hit_object(state->rule_state);
}
if (0 == expr_rt->rule_num) {
@@ -1097,7 +1097,7 @@ int expr_runtime_stream_scan(struct expr_runtime_stream *expr_rt_stream,
}
hit_maat_items[real_hit_item_cnt].item_id = item_id;
- hit_maat_items[real_hit_item_cnt].group_id = expr_item->group_id;
+ hit_maat_items[real_hit_item_cnt].object_id = expr_item->object_id;
real_hit_item_cnt++;
}
diff --git a/src/maat_flag.c b/src/maat_flag.c
index 75ef69d..ed73dab 100644
--- a/src/maat_flag.c
+++ b/src/maat_flag.c
@@ -26,7 +26,7 @@
struct flag_schema {
int item_id_column;
- int group_id_column;
+ int object_id_column;
int district_column;
int flag_column;
int flag_mask_column;
@@ -36,7 +36,7 @@ struct flag_schema {
struct flag_item {
long long item_id;
- long long group_id;
+ long long object_id;
long long flag;
long long flag_mask;
void *user_data;
@@ -104,12 +104,12 @@ void *flag_schema_new(cJSON *json, struct table_manager *tbl_mgr,
goto error;
}
- custom_item = cJSON_GetObjectItem(item, "group_id");
+ custom_item = cJSON_GetObjectItem(item, "object_id");
if (custom_item != NULL && custom_item->type == cJSON_Number) {
- schema->group_id_column = custom_item->valueint;
+ schema->object_id_column = custom_item->valueint;
} else {
log_fatal(logger, MODULE_FLAG,
- "[%s:%d] flag table:<%s> schema has no group_id column",
+ "[%s:%d] flag table:<%s> schema has no object_id column",
__FUNCTION__, __LINE__, table_name);
goto error;
}
@@ -326,15 +326,15 @@ flag_item_new(struct flag_schema *schema, const char *table_name,
}
item->item_id = atoll(line + column_offset);
- ret = get_column_pos(line, schema->group_id_column, &column_offset,
+ ret = get_column_pos(line, schema->object_id_column, &column_offset,
&column_len);
if (ret < 0) {
log_fatal(flag_rt->logger, MODULE_FLAG,
- "[%s:%d] flag table:<%s> has no group_id in line:%s",
+ "[%s:%d] flag table:<%s> has no object_id in line:%s",
__FUNCTION__, __LINE__, table_name, line);
goto error;
}
- item->group_id = atoll(line + column_offset);
+ item->object_id = atoll(line + column_offset);
table_type = table_manager_get_table_type(schema->ref_tbl_mgr, schema->table_id);
if (table_type == TABLE_TYPE_INTERVAL_PLUS) {
@@ -555,9 +555,9 @@ long long flag_runtime_rule_count(void *flag_runtime)
int flag_runtime_scan(struct flag_runtime *flag_rt, int thread_id,
long long flag, int attribute_id, struct maat_state *state)
{
- //clear rule_state->last_hit_group
+ //clear rule_state->last_hit_object
if (state != NULL && state->rule_state != NULL) {
- rule_state_clear_last_hit_group(state->rule_state);
+ rule_state_clear_last_hit_object(state->rule_state);
}
if (0 == flag_rt->rule_num) {
@@ -598,7 +598,7 @@ int flag_runtime_scan(struct flag_runtime *flag_rt, int thread_id,
}
hit_maat_items[real_hit_item_cnt].item_id = item_id;
- hit_maat_items[real_hit_item_cnt].group_id = flag_item->group_id;
+ hit_maat_items[real_hit_item_cnt].object_id = flag_item->object_id;
real_hit_item_cnt++;
}
}
diff --git a/src/maat_group.c b/src/maat_group.c
deleted file mode 100644
index 10b02c8..0000000
--- a/src/maat_group.c
+++ /dev/null
@@ -1,1252 +0,0 @@
-/*
-**********************************************************************************************
-* File: maat_group.c
-* Description:
-* Authors: Liu wentan <[email protected]>
-* Date: 2022-10-31
-* Copyright: (c) Since 2022 Geedge Networks, Ltd. All rights reserved.
-***********************************************************************************************
-*/
-
-#include <assert.h>
-#include <pthread.h>
-
-#include "log/log.h"
-#include "maat_group.h"
-#include "maat_utils.h"
-#include "maat_limits.h"
-#include "uthash/uthash.h"
-#include "uthash/utarray.h"
-#include "igraph/igraph.h"
-#include "maat_kv.h"
-
-#define MODULE_GROUP module_name_str("maat.group")
-
-struct group2group_item {
- long long group_id;
- UT_array *incl_sub_group_ids;
- UT_array *excl_sub_group_ids;
-};
-
-struct group2group_schema {
- int group_id_column;
- int incl_sub_group_ids_column;
- int excl_sub_group_ids_column;
- int table_id;
- struct table_manager *ref_tbl_mgr;
-};
-
-struct maat_group {
- igraph_integer_t vertex_id;
- long long group_id;
-
- int ref_by_super_group_cnt;
- int ref_by_sub_group_cnt;
-
- UT_array *incl_super_group_ids;
- UT_array *excl_super_group_ids;
- UT_array *incl_sub_group_ids;
- UT_array *excl_sub_group_ids;
-
- UT_hash_handle hh_group_id;
- UT_hash_handle hh_vertex_id;
-};
-
-struct maat_group_topology {
- struct maat_group *hash_by_group_id; //key: group_id, value: struct maat_group *.
- struct maat_group *hash_by_vertex_id; //key: vetex_id, value: struct maat_group *.
- igraph_t group_graph;
- igraph_integer_t grp_vertex_id_generator;
- struct log_handle *logger;
-};
-
-struct group2group_runtime {
- struct maat_group_topology *group_topo;
- struct maat_group_topology *updating_group_topo;
- long long rule_num;
- long long excl_rule_num; //exclude g2g rule num
- long long update_err_cnt;
- int updating_flag;
-
- struct maat_garbage_bin *ref_garbage_bin;
- struct log_handle *logger;
-};
-
-UT_icd ut_group_id_icd = {sizeof(long long), NULL, NULL, NULL};
-
-static inline int compare_group_id(const void *a, const void *b)
-{
- long long ret = *(const long long *)a - *(const long long *)b;
-
- if (0 == ret) {
- return 0;
- } else if(ret < 0) {
- return -1;
- } else {
- return 1;
- }
-}
-
-void *group2group_schema_new(cJSON *json, struct table_manager *tbl_mgr,
- const char *table_name, struct log_handle *logger)
-{
- struct group2group_schema *g2g_schema = ALLOC(struct group2group_schema, 1);
-
- cJSON *custom_item = NULL;
- cJSON *item = cJSON_GetObjectItem(json, "table_id");
- if (item != NULL && item->type == cJSON_Number) {
- g2g_schema->table_id = item->valueint;
- } else {
- log_fatal(logger, MODULE_GROUP,
- "[%s:%d] g2g table:<%s> schema has no table_id column",
- __FUNCTION__, __LINE__, table_name);
- goto error;
- }
-
- item = cJSON_GetObjectItem(json, "custom");
- if (item == NULL || item->type != cJSON_Object) {
- log_fatal(logger, MODULE_GROUP,
- "[%s:%d] g2g table:<%s> schema has no custom column",
- __FUNCTION__, __LINE__, table_name);
- goto error;
- }
-
- custom_item = cJSON_GetObjectItem(item, "group_id");
- if (custom_item != NULL && custom_item->type == cJSON_Number) {
- g2g_schema->group_id_column = custom_item->valueint;
- } else {
- log_fatal(logger, MODULE_GROUP,
- "[%s:%d] g2g table:<%s> schema has no group_id column",
- __FUNCTION__, __LINE__, table_name);
- goto error;
- }
-
- custom_item = cJSON_GetObjectItem(item, "included_sub_group_ids");
- if (custom_item != NULL && custom_item->type == cJSON_Number) {
- g2g_schema->incl_sub_group_ids_column = custom_item->valueint;
- } else {
- log_fatal(logger, MODULE_GROUP,
- "[%s:%d] g2g table:<%s> schema has no included_sub_group_ids column",
- __FUNCTION__, __LINE__, table_name);
- goto error;
- }
-
- custom_item = cJSON_GetObjectItem(item, "excluded_sub_group_ids");
- if (custom_item != NULL && custom_item->type == cJSON_Number) {
- g2g_schema->excl_sub_group_ids_column = custom_item->valueint;
- } else {
- log_fatal(logger, MODULE_GROUP,
- "[%s:%d] g2g table:<%s> schema has no excluded_sub_group_ids column",
- __FUNCTION__, __LINE__, table_name);
- goto error;
- }
-
- g2g_schema->ref_tbl_mgr = tbl_mgr;
- return g2g_schema;
-error:
- FREE(g2g_schema);
- return NULL;
-}
-
-void group2group_schema_free(void *g2g_schema)
-{
- FREE(g2g_schema);
-}
-
-static void group_vertex_free(struct maat_group *group)
-{
- if (NULL == group) {
- return;
- }
-
- if (group->incl_super_group_ids != NULL) {
- utarray_free(group->incl_super_group_ids);
- group->incl_super_group_ids = NULL;
- }
-
- if (group->excl_super_group_ids != NULL) {
- utarray_free(group->excl_super_group_ids);
- group->excl_super_group_ids = NULL;
- }
-
- if (group->incl_sub_group_ids != NULL) {
- utarray_free(group->incl_sub_group_ids);
- group->incl_sub_group_ids = NULL;
- }
-
- if (group->excl_sub_group_ids != NULL) {
- utarray_free(group->excl_sub_group_ids);
- group->excl_sub_group_ids = NULL;
- }
-
- FREE(group);
-}
-
-static struct maat_group_topology *
-maat_group_topology_new(struct log_handle *logger)
-{
- struct maat_group_topology *group_topo = ALLOC(struct maat_group_topology, 1);
- UNUSED int ret = 0;
-
- group_topo->hash_by_group_id = NULL;
- group_topo->hash_by_vertex_id = NULL;
-
- ret = igraph_empty(&(group_topo->group_graph), 0, IGRAPH_DIRECTED);
- assert(ret == IGRAPH_SUCCESS);
-
- group_topo->logger = logger;
-
- return group_topo;
-}
-
-static void maat_group_topology_free(struct maat_group_topology *group_topo)
-{
- if (NULL == group_topo) {
- return;
- }
-
- struct maat_group *group = NULL, *tmp_group = NULL;
-
- HASH_CLEAR(hh_vertex_id, group_topo->hash_by_vertex_id);//No need group memory clean up.
- HASH_ITER(hh_group_id, group_topo->hash_by_group_id, group, tmp_group) {
- HASH_DELETE(hh_group_id, group_topo->hash_by_group_id, group);
- group_vertex_free(group);
- }
- assert(group_topo->hash_by_group_id == NULL);
-
- igraph_destroy(&group_topo->group_graph);
- FREE(group_topo);
-}
-
-static struct maat_group *maat_group_clone(struct maat_group *group)
-{
- struct maat_group *group_copy = ALLOC(struct maat_group, 1);
-
- group_copy->group_id = group->group_id;
- group_copy->vertex_id = group->vertex_id;
- group_copy->ref_by_sub_group_cnt = group->ref_by_sub_group_cnt;
- group_copy->ref_by_super_group_cnt = group->ref_by_super_group_cnt;
- utarray_new(group_copy->incl_super_group_ids, &ut_group_id_icd);
- utarray_new(group_copy->excl_super_group_ids, &ut_group_id_icd);
- utarray_new(group_copy->incl_sub_group_ids, &ut_group_id_icd);
- utarray_new(group_copy->excl_sub_group_ids, &ut_group_id_icd);
-
- long long *p = NULL;
- for (p = (long long *)utarray_front(group->incl_super_group_ids); p != NULL;
- p = (long long *)utarray_next(group->incl_super_group_ids, p)) {
- utarray_push_back(group_copy->incl_super_group_ids, p);
- }
-
- for (p = (long long *)utarray_front(group->excl_super_group_ids); p != NULL;
- p = (long long *)utarray_next(group->excl_super_group_ids, p)) {
- utarray_push_back(group_copy->excl_super_group_ids, p);
- }
-
- for (p = (long long *)utarray_front(group->incl_sub_group_ids); p != NULL;
- p = (long long *)utarray_next(group->incl_sub_group_ids, p)) {
- utarray_push_back(group_copy->incl_sub_group_ids, p);
- }
-
- for (p = (long long *)utarray_front(group->excl_sub_group_ids); p != NULL;
- p = (long long *)utarray_next(group->excl_sub_group_ids, p)) {
- utarray_push_back(group_copy->excl_sub_group_ids, p);
- }
-
- return group_copy;
-}
-
-static struct maat_group_topology *
-maat_group_topology_clone(struct maat_group_topology *group_topo)
-{
- if (NULL == group_topo) {
- return NULL;
- }
-
- struct maat_group_topology *group_topo_copy = ALLOC(struct maat_group_topology, 1);
-
- struct maat_group *group = NULL, *tmp_group = NULL;
- HASH_ITER(hh_group_id, group_topo->hash_by_group_id, group, tmp_group) {
- struct maat_group *group_copy = maat_group_clone(group);
-
- HASH_ADD(hh_group_id, group_topo_copy->hash_by_group_id, group_id,
- sizeof(group_copy->group_id), group_copy);
- HASH_ADD(hh_vertex_id, group_topo_copy->hash_by_vertex_id, vertex_id,
- sizeof(group_copy->vertex_id), group_copy);
- }
-
- igraph_copy(&(group_topo_copy->group_graph), &(group_topo->group_graph));
- group_topo_copy->grp_vertex_id_generator = group_topo->grp_vertex_id_generator;
- group_topo_copy->logger = group_topo->logger;
-
- return group_topo_copy;
-}
-
-void *group2group_runtime_new(void *g2g_schema, size_t max_thread_num,
- struct maat_garbage_bin *garbage_bin,
- struct log_handle *logger)
-{
- if (NULL == g2g_schema) {
- return NULL;
- }
-
- struct group2group_runtime *g2g_rt = ALLOC(struct group2group_runtime, 1);
-
- g2g_rt->group_topo = maat_group_topology_new(logger);
- g2g_rt->ref_garbage_bin = garbage_bin;
- g2g_rt->logger = logger;
-
- return g2g_rt;
-}
-
-void group2group_runtime_free(void *g2g_runtime)
-{
- if (NULL == g2g_runtime) {
- return;
- }
-
- struct group2group_runtime *g2g_rt = (struct group2group_runtime *)g2g_runtime;
-
- if (g2g_rt->group_topo != NULL) {
- maat_group_topology_free(g2g_rt->group_topo);
- g2g_rt->group_topo = NULL;
- }
-
- if (g2g_rt->updating_group_topo != NULL) {
- maat_group_topology_free(g2g_rt->updating_group_topo);
- g2g_rt->updating_group_topo = NULL;
- }
-
- FREE(g2g_rt);
-}
-
-static struct group2group_item *
-group2group_item_new(const char *line, struct group2group_schema *g2g_schema,
- const char *table_name, struct log_handle *logger)
-{
- size_t column_offset = 0;
- size_t column_len = 0;
- struct group2group_item *g2g_item = ALLOC(struct group2group_item, 1);
- utarray_new(g2g_item->incl_sub_group_ids, &ut_group_id_icd);
- utarray_new(g2g_item->excl_sub_group_ids, &ut_group_id_icd);
-
- int ret = get_column_pos(line, g2g_schema->group_id_column,
- &column_offset, &column_len);
- if (ret < 0) {
- log_fatal(logger, MODULE_GROUP,
- "[%s:%d] g2 table:<%s> has no group_id in line:%s",
- __FUNCTION__, __LINE__, table_name, line);
- goto error;
- }
- g2g_item->group_id = atoll(line + column_offset);
-
- ret = get_column_pos(line, g2g_schema->incl_sub_group_ids_column,
- &column_offset, &column_len);
- if (ret < 0) {
- log_fatal(logger, MODULE_GROUP,
- "[%s:%d] g2g table:<%s> has no included_sub_group_ids in line:%s",
- __FUNCTION__, __LINE__, table_name, line);
- goto error;
- }
-
- char group_ids_str[MAX_GROUP_IDS_STR_LEN] = {0};
- memcpy(group_ids_str, line + column_offset, MIN(MAX_GROUP_IDS_STR_LEN, column_len));
-
- ret = ids_str2longlong_array(group_ids_str, g2g_item->incl_sub_group_ids);
- if (ret < 0) {
- log_fatal(logger, MODULE_GROUP,
- "[%s:%d] g2c table:<%s> included_sub_group_ids str2longlong failed in line:%s",
- __FUNCTION__, __LINE__, table_name, line);
- goto error;
- }
-
- if (utarray_len(g2g_item->incl_sub_group_ids) > MAX_GROUP_CNT) {
- log_fatal(logger, MODULE_GROUP,
- "[%s:%d] g2c table:<%s> included_sub_group_ids exceed maximum:%d in line:%s",
- __FUNCTION__, __LINE__, table_name, MAX_GROUP_CNT, line);
- goto error;
- }
-
- ret = get_column_pos(line, g2g_schema->excl_sub_group_ids_column,
- &column_offset, &column_len);
- if (ret < 0) {
- log_fatal(logger, MODULE_GROUP,
- "[%s:%d] g2g table:<%s> has no excluded_sub_group_ids in line:%s",
- __FUNCTION__, __LINE__, table_name, line);
- goto error;
- }
-
- memset(group_ids_str, 0, sizeof(group_ids_str));
- memcpy(group_ids_str, line + column_offset, MIN(MAX_GROUP_IDS_STR_LEN, column_len));
-
- ret = ids_str2longlong_array(group_ids_str, g2g_item->excl_sub_group_ids);
- if (ret < 0) {
- log_fatal(logger, MODULE_GROUP,
- "[%s:%d] g2c table:<%s> excluded_sub_group_ids str2longlong failed in line:%s",
- __FUNCTION__, __LINE__, table_name, line);
- goto error;
- }
-
- if (utarray_len(g2g_item->excl_sub_group_ids) > MAX_GROUP_CNT) {
- log_fatal(logger, MODULE_GROUP,
- "[%s:%d] g2c table:<%s> excluded_sub_group_ids exceed maximum:%d in line:%s",
- __FUNCTION__, __LINE__, table_name, MAX_GROUP_CNT, line);
- goto error;
- }
-
- return g2g_item;
-error:
- FREE(g2g_item);
- return NULL;
-}
-
-static void group2group_item_free(struct group2group_item *g2g_item)
-{
- if (NULL == g2g_item) {
- return;
- }
-
- if (g2g_item->incl_sub_group_ids != NULL) {
- utarray_free(g2g_item->incl_sub_group_ids);
- g2g_item->incl_sub_group_ids = NULL;
- }
-
- if (g2g_item->excl_sub_group_ids != NULL) {
- utarray_free(g2g_item->excl_sub_group_ids);
- g2g_item->excl_sub_group_ids = NULL;
- }
-
- FREE(g2g_item);
-}
-
-static size_t print_igraph_vector(igraph_vector_t *v, char *buff, size_t sz) {
- long int i;
- int printed = 0;
-
- for (i = 0; i < igraph_vector_size(v); i++) {
- printed += snprintf(buff + printed, sz - printed, " %li",
- (long int) VECTOR(*v)[i]);
- }
-
- return printed;
-}
-
-static struct maat_group *
-group_topology_add_group(struct maat_group_topology *group_topo, long long group_id)
-{
- assert(group_topo != NULL);
-
- struct maat_group *group = ALLOC(struct maat_group, 1);
- group->group_id = group_id;
- group->vertex_id = group_topo->grp_vertex_id_generator++;
- utarray_new(group->incl_super_group_ids, &ut_group_id_icd);
- utarray_new(group->excl_super_group_ids, &ut_group_id_icd);
- utarray_new(group->incl_sub_group_ids, &ut_group_id_icd);
- utarray_new(group->excl_sub_group_ids, &ut_group_id_icd);
-
- assert(igraph_vcount(&group_topo->group_graph)==group->vertex_id);
- igraph_add_vertices(&group_topo->group_graph, 1, NULL); //Add 1 vertice.
-
- HASH_ADD(hh_group_id, group_topo->hash_by_group_id, group_id,
- sizeof(group->group_id), group);
- HASH_ADD(hh_vertex_id, group_topo->hash_by_vertex_id, vertex_id,
- sizeof(group->vertex_id), group);
-
- return group;
-}
-
-static void group_topology_del_group(struct maat_group_topology *group_topo,
- struct maat_group *group)
-{
- if (NULL == group_topo || NULL == group) {
- return;
- }
-
- igraph_vector_t v;
- char buff[4096] = {0};
-
- assert(group->ref_by_super_group_cnt == 0);
-
- igraph_vector_init(&v, 8);
- igraph_neighbors(&group_topo->group_graph, &v, group->vertex_id, IGRAPH_ALL);
- if (igraph_vector_size(&v) > 0) {
- print_igraph_vector(&v, buff, sizeof(buff));
- log_fatal(group_topo->logger, MODULE_GROUP,
- "[%s:%d] Del group %d exception, still reached by %s.",
- __FUNCTION__, __LINE__, group->vertex_id, buff);
- assert(0);
- }
- igraph_vector_destroy(&v);
-
- //We should not call igraph_delete_vertices, because this is function changes the ids of the vertices.
-
- HASH_DELETE(hh_group_id, group_topo->hash_by_group_id, group);
- HASH_DELETE(hh_vertex_id, group_topo->hash_by_vertex_id, group);
- group_vertex_free(group);
-}
-
-static struct maat_group *
-group_topology_find_group(struct maat_group_topology *group_topo, long long group_id)
-{
- if (NULL == group_topo || group_id < 0) {
- return NULL;
- }
-
- struct maat_group *group = NULL;
- HASH_FIND(hh_group_id, group_topo->hash_by_group_id, &group_id, sizeof(group_id), group);
-
- return group;
-}
-
-static void maat_group_reference_super_group(struct maat_group *group,
- long long super_group_id,
- int is_exclude)
-{
- if (NULL == group || super_group_id < 0) {
- return;
- }
-
- if (0 == is_exclude) {
- //include superior group
- if (!utarray_find(group->incl_super_group_ids, &super_group_id,
- compare_group_id)) {
- utarray_push_back(group->incl_super_group_ids, &super_group_id);
- utarray_sort(group->incl_super_group_ids, compare_group_id);
- }
- } else {
- //exclude superior group
- if (!utarray_find(group->excl_super_group_ids, &super_group_id,
- compare_group_id)) {
- utarray_push_back(group->excl_super_group_ids, &super_group_id);
- utarray_sort(group->excl_super_group_ids, compare_group_id);
- }
- }
-}
-
-static void maat_group_reference_sub_group(struct maat_group *group,
- long long sub_group_id,
- int is_exclude)
-{
- if (NULL == group || sub_group_id < 0) {
- return;
- }
-
- if (0 == is_exclude) {
- //include sub group
- if (!utarray_find(group->incl_sub_group_ids, &sub_group_id,
- compare_group_id)) {
- utarray_push_back(group->incl_sub_group_ids, &sub_group_id);
- utarray_sort(group->incl_sub_group_ids, compare_group_id);
- }
- } else {
- //exclude sub group
- if (!utarray_find(group->excl_sub_group_ids, &sub_group_id,
- compare_group_id)) {
- utarray_push_back(group->excl_sub_group_ids, &sub_group_id);
- utarray_sort(group->excl_sub_group_ids, compare_group_id);
- }
- }
-}
-
-static void maat_group_dereference_super_group(struct maat_group *group,
- long long super_group_id,
- int is_exclude)
-{
- if (NULL == group || super_group_id < 0) {
- return;
- }
-
- size_t remove_idx = 0;
- long long *tmp_id = NULL;
- if (0 == is_exclude) {
- //include superior group
- tmp_id = utarray_find(group->incl_super_group_ids, &super_group_id,
- compare_group_id);
- if (tmp_id != NULL) {
- remove_idx = utarray_eltidx(group->incl_super_group_ids, tmp_id);
- utarray_erase(group->incl_super_group_ids, remove_idx, 1);
- }
- } else {
- //exclude superior group
- tmp_id = utarray_find(group->excl_super_group_ids, &super_group_id,
- compare_group_id);
- if (tmp_id != NULL) {
- remove_idx = utarray_eltidx(group->excl_super_group_ids, tmp_id);
- utarray_erase(group->excl_super_group_ids, remove_idx, 1);
- }
- }
-}
-
-static void maat_group_dereference_sub_group(struct maat_group *group,
- long long sub_group_id,
- int is_exclude)
-{
- if (NULL == group || sub_group_id < 0) {
- return;
- }
-
- size_t remove_idx = 0;
- long long *tmp_id = NULL;
- if (0 == is_exclude) {
- //include superior group
- tmp_id = utarray_find(group->incl_sub_group_ids, &sub_group_id,
- compare_group_id);
- if (tmp_id != NULL) {
- remove_idx = utarray_eltidx(group->incl_sub_group_ids, tmp_id);
- utarray_erase(group->incl_sub_group_ids, remove_idx, 1);
- }
- } else {
- //exclude superior group
- tmp_id = utarray_find(group->excl_sub_group_ids, &sub_group_id,
- compare_group_id);
- if (tmp_id != NULL) {
- remove_idx = utarray_eltidx(group->excl_sub_group_ids, tmp_id);
- utarray_erase(group->excl_sub_group_ids, remove_idx, 1);
- }
- }
-}
-
-static int group_topology_add_group_to_group(struct maat_group_topology *group_topo,
- long long group_id, long long sub_group_id,
- int is_exclude)
-{
- if (NULL == group_topo) {
- return -1;
- }
-
- struct maat_group *sub_group = group_topology_find_group(group_topo, sub_group_id);
- if (NULL == sub_group) {
- sub_group = group_topology_add_group(group_topo, sub_group_id);
- }
-
- struct maat_group *group = group_topology_find_group(group_topo, group_id);
- if (NULL == group) {
- group = group_topology_add_group(group_topo, group_id);
- }
-
- maat_group_reference_super_group(sub_group, group_id, is_exclude);
- maat_group_reference_sub_group(group, sub_group_id, is_exclude);
-
- igraph_integer_t edge_id;
- int ret = igraph_get_eid(&group_topo->group_graph, &edge_id, sub_group->vertex_id,
- group->vertex_id, IGRAPH_DIRECTED, /*error*/ 0);
-
- //No duplicated edges between two groups.
- if (edge_id > 0) {
- log_fatal(group_topo->logger, MODULE_GROUP,
- "[%s:%d] Add group %d to group %d failed, relation already existed.",
- __FUNCTION__, __LINE__, sub_group->group_id, group->group_id);
- ret = -1;
- } else {
- igraph_add_edge(&group_topo->group_graph, sub_group->vertex_id,
- group->vertex_id);
- sub_group->ref_by_super_group_cnt++;
- group->ref_by_sub_group_cnt++;
- ret = 0;
- }
-
- igraph_bool_t is_dag;
- igraph_is_dag(&(group_topo->group_graph), &is_dag);
- if (!is_dag) {
- log_fatal(group_topo->logger, MODULE_GROUP,
- "[%s:%d] Sub group cycle detected, sub_group_id:%lld, group_id:%lld!",
- __FUNCTION__, __LINE__, sub_group_id, group_id);
- return -1;
- }
-
- return ret;
-}
-
-static int group_topology_del_group_from_group(struct maat_group_topology *group_topo,
- long long group_id, long long sub_group_id,
- int is_exclude)
-{
- if (NULL == group_topo) {
- return -1;
- }
-
- //No hash write operation, LOCK protection is unnecessary.
- struct maat_group *sub_group = group_topology_find_group(group_topo, sub_group_id);
- if (NULL == sub_group) {
- log_fatal(group_topo->logger, MODULE_GROUP,
- "[%s:%d] Del group %d from group %d failed, group %d not existed.",
- __FUNCTION__, __LINE__, sub_group_id, group_id, sub_group_id);
- return -1;
- }
-
- struct maat_group *group = group_topology_find_group(group_topo, group_id);
- if (NULL == group) {
- log_fatal(group_topo->logger, MODULE_GROUP,
- "[%s:%d] Del group %d from group %d failed, group %d not existed.",
- __FUNCTION__, __LINE__, sub_group_id, group_id, group_id);
- return -1;
- }
-
- maat_group_dereference_super_group(sub_group, group_id, is_exclude);
- maat_group_dereference_sub_group(group, sub_group_id, is_exclude);
-
- igraph_es_t es;
- igraph_integer_t edge_num_before = 0, edge_num_after = 0;
-
- edge_num_before = igraph_ecount(&group_topo->group_graph);
- // The edges between the given pairs of vertices will be included in the edge selection.
- //The vertex pairs must be given as the arguments of the function call, the third argument
- //is the first vertex of the first edge, the fourth argument is the second vertex of the
- //first edge, the fifth is the first vertex of the second edge and so on. The last element
- //of the argument list must be -1 to denote the end of the argument list.
- //https://igraph.org/c/doc/igraph-Iterators.html#igraph_es_pairs_small
- int ret = igraph_es_pairs_small(&es, IGRAPH_DIRECTED, sub_group->vertex_id,
- group->vertex_id, -1);
- assert(ret==IGRAPH_SUCCESS);
- // ignore no such edge to abort().
- igraph_set_error_handler(igraph_error_handler_ignore);
- ret = igraph_delete_edges(&group_topo->group_graph, es);
- edge_num_after = igraph_ecount(&group_topo->group_graph);
- igraph_es_destroy(&es);
-
- if (ret != IGRAPH_SUCCESS || edge_num_before - edge_num_after != 1) {
- assert(0);
- return -1;
- }
-
- sub_group->ref_by_super_group_cnt--;
- group->ref_by_sub_group_cnt--;
-
- return 0;
-}
-
-static int group_topology_build_super_groups(struct maat_group_topology *group_topo)
-{
- if (NULL == group_topo) {
- return -1;
- }
-
- igraph_bool_t is_dag;
- igraph_is_dag(&(group_topo->group_graph), &is_dag);
- if (!is_dag) {
- log_fatal(group_topo->logger, MODULE_GROUP,
- "[%s:%d] Sub group cycle detected!", __FUNCTION__, __LINE__);
- return -1;
- }
-
- struct maat_group *group = NULL, *tmp_group = NULL;
- HASH_ITER (hh_group_id, group_topo->hash_by_group_id, group, tmp_group) {
- //Orphan, Not reference by any one, free it.
- if (0 == group->ref_by_super_group_cnt
- && 0 == group->ref_by_sub_group_cnt) {
- group_topology_del_group(group_topo, group);
- continue;
- }
- }
-
- return 0;
-}
-
-int group2group_runtime_update(void *g2g_runtime, void *g2g_schema,
- const char *table_name, const char *line,
- int valid_column)
-{
- if (NULL == g2g_runtime || NULL == g2g_schema ||
- NULL == line) {
- return -1;
- }
-
- struct group2group_schema *schema = (struct group2group_schema *)g2g_schema;
- struct group2group_runtime *g2g_rt = (struct group2group_runtime *)g2g_runtime;
- int is_valid = get_column_value(line, valid_column);
- if (is_valid < 0) {
- log_fatal(g2g_rt->logger, MODULE_GROUP,
- "[%s:%d] g2g table:<%s> has no is_valid(column seq:%d)"
- " in table_line:%s", __FUNCTION__, __LINE__, table_name,
- valid_column, line);
- g2g_rt->update_err_cnt++;
- return -1;
- }
-
- struct group2group_item *g2g_item = group2group_item_new(line, schema, table_name,
- g2g_rt->logger);
- if (NULL == g2g_item) {
- g2g_rt->update_err_cnt++;
- return -1;
- }
-
- if (0 == g2g_rt->updating_flag) {
- assert(g2g_rt->updating_group_topo == NULL);
- g2g_rt->updating_group_topo = maat_group_topology_clone(g2g_rt->group_topo);
- g2g_rt->updating_flag = 1;
- }
-
- int ret = 0;
- size_t i = 0;
- int err_flag = 0;
- long long *sub_group_id = NULL;
- if (0 == is_valid) {
- //delete
- for (i = 0; i < utarray_len(g2g_item->incl_sub_group_ids); i++) {
- sub_group_id = (long long *)utarray_eltptr(g2g_item->incl_sub_group_ids, i);
- ret = group_topology_del_group_from_group(g2g_rt->updating_group_topo,
- g2g_item->group_id, *sub_group_id, 0);
- if (ret != 0) {
- err_flag = 1;
- }
- }
-
- for (i = 0; i < utarray_len(g2g_item->excl_sub_group_ids); i++) {
- sub_group_id = (long long *)utarray_eltptr(g2g_item->excl_sub_group_ids, i);
- ret = group_topology_del_group_from_group(g2g_rt->updating_group_topo,
- g2g_item->group_id, *sub_group_id, 1);
- if (ret != 0) {
- err_flag = 1;
- }
- }
-
- if (1 == err_flag) {
- g2g_rt->update_err_cnt++;
- } else {
- if (utarray_len(g2g_item->excl_sub_group_ids) > 0) {
- g2g_rt->excl_rule_num--;
- }
- g2g_rt->rule_num--;
- }
- } else {
- //add
- for (i = 0; i < utarray_len(g2g_item->incl_sub_group_ids); i++) {
- sub_group_id = (long long *)utarray_eltptr(g2g_item->incl_sub_group_ids, i);
- ret = group_topology_add_group_to_group(g2g_rt->updating_group_topo,
- g2g_item->group_id, *sub_group_id, 0);
- if (ret != 0) {
- err_flag = 1;
- }
- }
-
- for (i = 0; i < utarray_len(g2g_item->excl_sub_group_ids); i++) {
- sub_group_id = (long long *)utarray_eltptr(g2g_item->excl_sub_group_ids, i);
- ret = group_topology_add_group_to_group(g2g_rt->updating_group_topo,
- g2g_item->group_id, *sub_group_id, 1);
- if (ret != 0) {
- err_flag = 1;
- }
- }
-
- if (1 == err_flag) {
- g2g_rt->update_err_cnt++;
- } else {
- if (utarray_len(g2g_item->excl_sub_group_ids) > 0) {
- g2g_rt->excl_rule_num++;
- }
- g2g_rt->rule_num++;
- }
- }
- group2group_item_free(g2g_item);
-
- return ret;
-}
-
-static void garbage_maat_group_topology_free(void *data, void *arg)
-{
- struct maat_group_topology *group_topo = (struct maat_group_topology *)data;
- maat_group_topology_free(group_topo);
-}
-
-int group2group_runtime_commit(void *g2g_runtime, const char *table_name,
- long long maat_rt_version)
-{
- if (NULL == g2g_runtime) {
- return -1;
- }
-
- struct group2group_runtime *g2g_rt = (struct group2group_runtime *)g2g_runtime;
- if (0 == g2g_rt->updating_flag) {
- return 0;
- }
-
- struct timespec start, end;
- clock_gettime(CLOCK_MONOTONIC, &start);
- int ret = group_topology_build_super_groups(g2g_rt->updating_group_topo);
- clock_gettime(CLOCK_MONOTONIC, &end);
- long long time_elapse_ms = (end.tv_sec - start.tv_sec) * 1000 +
- (end.tv_nsec - start.tv_nsec) / 1000000;
-
- if (ret < 0) {
- log_fatal(g2g_rt->logger, MODULE_GROUP,
- "[%s:%d] table[%s] group2group runtime commit failed",
- __FUNCTION__, __LINE__, table_name);
- return -1;
- }
-
- struct maat_group_topology *old_group_topo = g2g_rt->group_topo;
- g2g_rt->group_topo = g2g_rt->updating_group_topo;
- g2g_rt->updating_group_topo = NULL;
- g2g_rt->updating_flag = 0;
-
- maat_garbage_bagging(g2g_rt->ref_garbage_bin, old_group_topo, NULL,
- garbage_maat_group_topology_free);
-
- log_info(g2g_rt->logger, MODULE_GROUP,
- "table[%s] commit %zu g2g rules and rebuild super_groups completed,"
- " version:%lld, consume:%lldms", table_name, g2g_rt->rule_num,
- maat_rt_version, time_elapse_ms);
-
- return 0;
-}
-
-#define MAX_RECURSION_DEPTH 5
-static void get_candidate_super_group_ids(struct maat_group_topology *group_topo,
- UT_array *hit_group_ids,
- UT_array *super_group_ids)
-{
- long long *p = NULL;
-
- //Find super candidates
- for (p = (long long *)utarray_front(hit_group_ids); p != NULL;
- p = (long long *)utarray_next(hit_group_ids, p)) {
- struct maat_group *group = group_topology_find_group(group_topo, *p);
- if (NULL == group) {
- //group_id not in group2group table
- continue;
- }
-
- for (int i = 0; i < utarray_len(group->incl_super_group_ids); i++) {
- long long *tmp = (long long *)utarray_eltptr(group->incl_super_group_ids, i);
- utarray_push_back(super_group_ids, tmp);
- }
- }
-}
-
-static void verify_group_by_sub_include_groups(struct maat_group *group,
- UT_array *candidate_group_ids,
- UT_array *kept_super_group_ids,
- UT_array *all_hit_group_ids)
-{
- size_t remove_idx = 0;
- long long *tmp_id = NULL;
-
- // delete groups whose all incl sub not in all_hit_group_ids
- if (utarray_len(group->incl_sub_group_ids) != 0) {
- int sub_incl_flag = 0;
-
- for (tmp_id = (long long *)utarray_front(group->incl_sub_group_ids); tmp_id != NULL;
- tmp_id = (long long *)utarray_next(group->incl_sub_group_ids, tmp_id)) {
- if (utarray_find(candidate_group_ids, tmp_id, compare_group_id)) {
- sub_incl_flag = 1;
- break;
- }
- }
-
- if (0 == sub_incl_flag) {
- tmp_id = utarray_find(all_hit_group_ids, &(group->group_id), compare_group_id);
- if (tmp_id != NULL) {
- remove_idx = utarray_eltidx(all_hit_group_ids, tmp_id);
- utarray_erase(all_hit_group_ids, remove_idx, 1);
- }
-
- tmp_id = utarray_find(kept_super_group_ids, &(group->group_id), compare_group_id);
- if (tmp_id != NULL) {
- remove_idx = utarray_eltidx(kept_super_group_ids, tmp_id);
- utarray_erase(kept_super_group_ids, remove_idx, 1);
- }
- }
- }
-}
-
-static void verify_group_by_sub_exclude_groups(struct maat_group *group,
- UT_array *candidate_group_ids,
- UT_array *kept_super_group_ids,
- UT_array *all_hit_group_ids)
-{
- if (0 == utarray_len(group->excl_sub_group_ids)) {
- return;
- }
-
- // delete groups whose excl sub in all_hit_group_ids
- int sub_excl_flag = 0;
- long long *tmp_id = NULL;
- for (tmp_id = (long long *)utarray_front(group->excl_sub_group_ids); tmp_id != NULL;
- tmp_id = (long long *)utarray_next(group->excl_sub_group_ids, tmp_id)) {
- if (utarray_find(candidate_group_ids, tmp_id, compare_group_id)) {
- sub_excl_flag = 1;
- break;
- }
- }
-
- if (1 == sub_excl_flag) {
- size_t remove_idx = 0;
- tmp_id = utarray_find(all_hit_group_ids, &(group->group_id), compare_group_id);
- if (tmp_id != NULL) {
- remove_idx = utarray_eltidx(all_hit_group_ids, tmp_id);
- utarray_erase(all_hit_group_ids, remove_idx, 1);
- }
-
- tmp_id = utarray_find(kept_super_group_ids, &(group->group_id), compare_group_id);
- if (tmp_id != NULL) {
- remove_idx = utarray_eltidx(kept_super_group_ids, tmp_id);
- utarray_erase(kept_super_group_ids, remove_idx, 1);
- }
- }
-}
-
-static void verify_candidate_super_group_ids(struct maat_group_topology *group_topo,
- UT_array *candidate_super_group_ids,
- UT_array *all_hit_group_ids,
- UT_array *kept_super_group_ids)
-{
- long long *p = NULL;
- UT_array *candidate_group_ids;
-
- utarray_new(candidate_group_ids, &ut_group_id_icd);
-
- /* merge this round of candidate super groups with hit groups from the previous round */
- for (p = (long long *)utarray_front(candidate_super_group_ids); p != NULL;
- p = (long long *)utarray_next(candidate_super_group_ids, p)) {
- utarray_push_back(candidate_group_ids, p);
- }
-
- for (p = (long long *)utarray_front(all_hit_group_ids); p != NULL;
- p = (long long *)utarray_next(all_hit_group_ids, p)) {
- utarray_push_back(candidate_group_ids, p);
- }
-
- utarray_sort(candidate_group_ids, compare_group_id);
-
- /**
- * verify sub exclude for candidate_super_group_ids
- */
- long long prev_group_id = -1;
- for (p = (long long *)utarray_front(candidate_super_group_ids); p != NULL;
- p = (long long *)utarray_next(candidate_super_group_ids, p)) {
- //filter duplicated group id
- if (*p == prev_group_id) {
- continue;
- }
- prev_group_id = *p;
-
- struct maat_group *group = group_topology_find_group(group_topo, *p);
- if (NULL == group) {
- continue;
- }
-
- //if group's sub excl in candidate_group_ids
- int sub_excl_flag = 0;
- long long *tmp_id = NULL;
- for (tmp_id = (long long *)utarray_front(group->excl_sub_group_ids); tmp_id != NULL;
- tmp_id = (long long *)utarray_next(group->excl_sub_group_ids, tmp_id)) {
- if (utarray_find(candidate_group_ids, tmp_id, compare_group_id)) {
- sub_excl_flag = 1;
- break;
- }
- }
-
- //kept super groups should not store this group
- if (1 == sub_excl_flag) {
- continue;
- }
-
- utarray_push_back(kept_super_group_ids, p);
- utarray_push_back(all_hit_group_ids, p);
- }
-
- utarray_sort(all_hit_group_ids, compare_group_id);
- utarray_sort(kept_super_group_ids, compare_group_id);
-
- /**
- * candidate_group_ids clone all_hit_group_ids
- */
- utarray_clear(candidate_group_ids);
- for (p = (long long *)utarray_front(all_hit_group_ids); p != NULL;
- p = (long long *)utarray_next(all_hit_group_ids, p)) {
- utarray_push_back(candidate_group_ids, p);
- }
-
- /**
- * 1. delete groups whose excl sub in all_hit_group_ids
- * 2. delete groups whose all incl sub is non-exist in all_hit_group_ids
- */
- for (p = (long long *)utarray_front(candidate_group_ids); p != NULL;
- p = (long long *)utarray_next(candidate_group_ids, p)) {
- struct maat_group *group = group_topology_find_group(group_topo, *p);
- if (NULL == group) {
- continue;
- }
-
- verify_group_by_sub_exclude_groups(group, candidate_group_ids,
- kept_super_group_ids, all_hit_group_ids);
- verify_group_by_sub_include_groups(group, candidate_group_ids,
- kept_super_group_ids, all_hit_group_ids);
- }
-
- utarray_free(candidate_group_ids);
-}
-
-static void get_super_group_ids(struct maat_group_topology *group_topo,
- UT_array *hit_group_ids, UT_array *all_hit_group_ids,
- size_t depth)
-{
- UT_array *candidate_super_group_ids;
- UT_array *kept_super_group_ids;
-
- if (depth >= MAX_RECURSION_DEPTH) {
- log_error(group_topo->logger, MODULE_GROUP,
- "[%s:%d]exceed max recursion depth(5)",
- __FUNCTION__, __LINE__);
- for (int i = 0; i < utarray_len(hit_group_ids); i++) {
- long long *p = (long long *)utarray_eltptr(hit_group_ids, i);
- log_error(group_topo->logger, MODULE_GROUP,
- "[%s:%d]group_id:%lld can't recursively get super group_id",
- __FUNCTION__, __LINE__, *p);
- }
- return;
- }
-
- utarray_new(kept_super_group_ids, &ut_group_id_icd);
- utarray_new(candidate_super_group_ids, &ut_group_id_icd);
-
- /**
- candidate super groups means all hit groups' super include group,
- don't consider super exclude groups
- for example:
- hit_groups = {g4, g11}
- g4's super include groups = {g7, g8}
- g11's super include groups = {g12}
-
- candidate super groups = {g7, g8, g12}
- */
- get_candidate_super_group_ids(group_topo, hit_group_ids, candidate_super_group_ids);
-
- if (0 == utarray_len(candidate_super_group_ids)) {
- goto next;
- }
-
- /**
- verify if candidates should be kept for hit super groups, must consider exclude groups
- for example:
- hit_groups = {g4, g11}
- \:include x:exclude
- g12
- x \
- x \
- x \
- x \
- g7 g8 \
- x \ /\ \
- x \ / \ \
- x \ / \ \
- x \/ \ \
- g3 g4 g5 g11
- candidate super groups = {g7, g8, g12}
- verify logic:
- 1. g12's sub_exclude g8 in candidates, so g12 should be dropped
- 2. g7 & g8, their sub_include in hit groups, so kept them
- if their all sub_include not exist in hit groups, they should be dropped
- after verify candidates, kept super groups = {g7, g8},
- all hit groups = {g4, g11, g7, g8}
- */
- verify_candidate_super_group_ids(group_topo, candidate_super_group_ids, all_hit_group_ids,
- kept_super_group_ids);
-
- depth++;
- get_super_group_ids(group_topo, kept_super_group_ids, all_hit_group_ids, depth);
-next:
- utarray_free(candidate_super_group_ids);
- utarray_free(kept_super_group_ids);
-}
-
-static size_t group_topology_get_super_groups(struct maat_group_topology *group_topo,
- long long *group_ids, size_t n_group_ids,
- long long *super_group_ids,
- size_t super_group_ids_size)
-{
- size_t i = 0, idx = 0;
- UT_array *all_hit_group_ids;
- UT_array *candidate_group_ids;
-
- utarray_new(all_hit_group_ids, &ut_group_id_icd);
- utarray_new(candidate_group_ids, &ut_group_id_icd);
-
- for (i = 0; i < n_group_ids; i++) {
- utarray_push_back(all_hit_group_ids, &(group_ids[i]));
- utarray_push_back(candidate_group_ids, &(group_ids[i]));
- }
-
- get_super_group_ids(group_topo, candidate_group_ids, all_hit_group_ids, 0);
-
- for (i = 0; i < n_group_ids; i++) {
- long long *tmp_id = utarray_find(all_hit_group_ids, &(group_ids[i]),
- compare_group_id);
- if (tmp_id != NULL) {
- size_t remove_idx = utarray_eltidx(all_hit_group_ids, tmp_id);
- utarray_erase(all_hit_group_ids, remove_idx, 1);
- }
- }
-
- long long *p = NULL;
- for (p = (long long *)utarray_front(all_hit_group_ids); p != NULL;
- p = (long long *)utarray_next(all_hit_group_ids, p)) {
- if (idx >= super_group_ids_size) {
- break;
- }
- super_group_ids[idx++] = *p;
- }
-
- utarray_free(all_hit_group_ids);
- utarray_free(candidate_group_ids);
-
- return idx;
-}
-
-size_t group2group_runtime_get_super_groups(void *g2g_runtime, long long *group_ids,
- size_t n_group_ids, long long *super_group_ids,
- size_t super_group_ids_size)
-{
- if (NULL == g2g_runtime || NULL == group_ids || 0 == n_group_ids) {
- return 0;
- }
-
- struct group2group_runtime *g2g_rt = (struct group2group_runtime *)g2g_runtime;
- long long g2g_group_ids[n_group_ids];
- size_t g2g_group_ids_cnt = 0;
-
- for (size_t i = 0; i < n_group_ids; i++) {
- struct maat_group *group = group_topology_find_group(g2g_rt->group_topo, group_ids[i]);
- if (NULL == group) {
- continue;
- }
-
- g2g_group_ids[g2g_group_ids_cnt++] = group_ids[i];
- }
-
- if (0 == g2g_group_ids_cnt) {
- return 0;
- }
-
- return group_topology_get_super_groups(g2g_rt->group_topo, g2g_group_ids, g2g_group_ids_cnt,
- super_group_ids, super_group_ids_size);
-}
-
-long long group2group_runtime_rule_count(void *g2g_runtime)
-{
- if (NULL == g2g_runtime) {
- return 0;
- }
-
- struct group2group_runtime *g2g_rt = (struct group2group_runtime *)g2g_runtime;
- return g2g_rt->rule_num;
-}
-
-long long group2group_runtime_exclude_rule_count(void *g2g_runtime)
-{
- if (NULL == g2g_runtime) {
- return 0;
- }
-
- struct group2group_runtime *g2g_rt = (struct group2group_runtime *)g2g_runtime;
- return g2g_rt->excl_rule_num;
-}
-
-long long group2group_runtime_update_err_count(void *g2g_runtime)
-{
- if (NULL == g2g_runtime) {
- return 0;
- }
-
- struct group2group_runtime *g2g_rt = (struct group2group_runtime *)g2g_runtime;
- return g2g_rt->update_err_cnt;
-} \ No newline at end of file
diff --git a/src/maat_interval.c b/src/maat_interval.c
index 828271c..81a8b05 100644
--- a/src/maat_interval.c
+++ b/src/maat_interval.c
@@ -23,7 +23,7 @@
struct interval_schema {
int item_id_column;
- int group_id_column;
+ int object_id_column;
int district_column;
int interval_column;
int table_id;
@@ -32,7 +32,7 @@ struct interval_schema {
struct interval_item {
long long item_id;
- long long group_id;
+ long long object_id;
int low_boundary;
int up_boundary;
void *user_data;
@@ -100,12 +100,12 @@ void *interval_schema_new(cJSON *json, struct table_manager *tbl_mgr,
goto error;
}
- custom_item = cJSON_GetObjectItem(item, "group_id");
+ custom_item = cJSON_GetObjectItem(item, "object_id");
if (custom_item != NULL && custom_item->type == cJSON_Number) {
- schema->group_id_column = custom_item->valueint;
+ schema->object_id_column = custom_item->valueint;
} else {
log_fatal(logger, MODULE_INTERVAL,
- "[%s:%d] interval table:<%s> schema has no group_id column",
+ "[%s:%d] interval table:<%s> schema has no object_id column",
__FUNCTION__, __LINE__, table_name);
goto error;
}
@@ -289,15 +289,15 @@ interval_item_new(struct interval_schema *schema, const char *table_name,
}
item->item_id = atoll(line + column_offset);
- ret = get_column_pos(line, schema->group_id_column, &column_offset,
+ ret = get_column_pos(line, schema->object_id_column, &column_offset,
&column_len);
if (ret < 0) {
log_fatal(interval_rt->logger, MODULE_INTERVAL,
- "[%s:%d] interval table:<%s> has no group_id in line:%s",
+ "[%s:%d] interval table:<%s> has no object_id in line:%s",
__FUNCTION__, __LINE__, table_name, line);
goto error;
}
- item->group_id = atoll(line + column_offset);
+ item->object_id = atoll(line + column_offset);
table_type = table_manager_get_table_type(schema->ref_tbl_mgr, schema->table_id);
if (table_type == TABLE_TYPE_INTERVAL_PLUS) {
@@ -544,9 +544,9 @@ long long interval_runtime_rule_count(void *interval_runtime)
int interval_runtime_scan(struct interval_runtime *interval_rt, int thread_id,
long long integer, int attribute_id, struct maat_state *state)
{
- //clear rule_state->last_hit_group
+ //clear rule_state->last_hit_object
if (state != NULL && state->rule_state != NULL) {
- rule_state_clear_last_hit_group(state->rule_state);
+ rule_state_clear_last_hit_object(state->rule_state);
}
if (0 == interval_rt->rule_num) {
@@ -587,7 +587,7 @@ int interval_runtime_scan(struct interval_runtime *interval_rt, int thread_id,
}
hit_maat_items[real_hit_item_cnt].item_id = item_id;
- hit_maat_items[real_hit_item_cnt].group_id = int_item->group_id;
+ hit_maat_items[real_hit_item_cnt].object_id = int_item->object_id;
real_hit_item_cnt++;
}
}
diff --git a/src/maat_ip.c b/src/maat_ip.c
index 21cfdc3..86c3d78 100644
--- a/src/maat_ip.c
+++ b/src/maat_ip.c
@@ -25,7 +25,7 @@
struct ip_schema {
int item_id_column;
- int group_id_column;
+ int object_id_column;
int ip_column;
int table_id;
int port_column;
@@ -44,7 +44,7 @@ struct ipv6_item_rule {
struct ip_item {
long long item_id;
- long long group_id;
+ long long object_id;
int addr_type;
union {
struct ipv4_item_rule ipv4;
@@ -107,12 +107,12 @@ void *ip_schema_new(cJSON *json, struct table_manager *tbl_mgr,
goto error;
}
- custom_item = cJSON_GetObjectItem(item, "group_id");
+ custom_item = cJSON_GetObjectItem(item, "object_id");
if (custom_item != NULL && custom_item->type == cJSON_Number) {
- ip_schema->group_id_column = custom_item->valueint;
+ ip_schema->object_id_column = custom_item->valueint;
} else {
log_fatal(logger, MODULE_IP,
- "[%s:%d] ip table:<%s> schema has no group_id column",
+ "[%s:%d] ip table:<%s> schema has no object_id column",
__FUNCTION__, __LINE__, table_name);
goto error;
}
@@ -164,15 +164,15 @@ ip_item_new(struct ip_schema *ip_schema, const char *table_name,
}
ip_item->item_id = atoll(line + column_offset);
- ret = get_column_pos(line, ip_schema->group_id_column, &column_offset,
+ ret = get_column_pos(line, ip_schema->object_id_column, &column_offset,
&column_len);
if (ret < 0) {
log_fatal(logger, MODULE_IP,
- "[%s:%d] ip table:<%s> has no group_id in line:%s",
+ "[%s:%d] ip table:<%s> has no object_id in line:%s",
__FUNCTION__, __LINE__, table_name, line);
goto error;
}
- ip_item->group_id = atoll(line + column_offset);
+ ip_item->object_id = atoll(line + column_offset);
ret = get_column_pos(line, ip_schema->ip_column, &column_offset,
&column_len);
@@ -522,9 +522,9 @@ long long ip_runtime_ipv6_rule_count(void *ip_runtime)
int ip_runtime_scan(struct ip_runtime *ip_rt, int thread_id, int ip_type,
uint8_t *ip_addr, int port, int attribute_id, struct maat_state *state)
{
- //clear rule_state->last_hit_group
+ //clear rule_state->last_hit_object
if (state != NULL && state->rule_state != NULL) {
- rule_state_clear_last_hit_group(state->rule_state);
+ rule_state_clear_last_hit_object(state->rule_state);
}
if (0 == ip_rt->rule_num) {
@@ -584,7 +584,7 @@ int ip_runtime_scan(struct ip_runtime *ip_rt, int thread_id, int ip_type,
}
hit_maat_items[real_hit_item_cnt].item_id = ip_results[i].rule_id;
- hit_maat_items[real_hit_item_cnt].group_id = ip_item->group_id;
+ hit_maat_items[real_hit_item_cnt].object_id = ip_item->object_id;
real_hit_item_cnt++;
}
diff --git a/src/maat_object.c b/src/maat_object.c
new file mode 100644
index 0000000..c0e9eee
--- /dev/null
+++ b/src/maat_object.c
@@ -0,0 +1,1252 @@
+/*
+**********************************************************************************************
+* File: maat_object.c
+* Description:
+* Authors: Liu wentan <[email protected]>
+* Date: 2022-10-31
+* Copyright: (c) Since 2022 Geedge Networks, Ltd. All rights reserved.
+***********************************************************************************************
+*/
+
+#include <assert.h>
+#include <pthread.h>
+
+#include "log/log.h"
+#include "maat_object.h"
+#include "maat_utils.h"
+#include "maat_limits.h"
+#include "uthash/uthash.h"
+#include "uthash/utarray.h"
+#include "igraph/igraph.h"
+#include "maat_kv.h"
+
+#define MODULE_OBJECT module_name_str("maat.object")
+
+struct object2object_item {
+ long long object_id;
+ UT_array *incl_sub_object_ids;
+ UT_array *excl_sub_object_ids;
+};
+
+struct object2object_schema {
+ int object_id_column;
+ int incl_sub_object_ids_column;
+ int excl_sub_object_ids_column;
+ int table_id;
+ struct table_manager *ref_tbl_mgr;
+};
+
+struct maat_object {
+ igraph_integer_t vertex_id;
+ long long object_id;
+
+ int ref_by_super_object_cnt;
+ int ref_by_sub_object_cnt;
+
+ UT_array *incl_super_object_ids;
+ UT_array *excl_super_object_ids;
+ UT_array *incl_sub_object_ids;
+ UT_array *excl_sub_object_ids;
+
+ UT_hash_handle hh_object_id;
+ UT_hash_handle hh_vertex_id;
+};
+
+struct maat_object_topology {
+ struct maat_object *hash_by_object_id; //key: object_id, value: struct maat_object *.
+ struct maat_object *hash_by_vertex_id; //key: vetex_id, value: struct maat_object *.
+ igraph_t object_graph;
+ igraph_integer_t grp_vertex_id_generator;
+ struct log_handle *logger;
+};
+
+struct object2object_runtime {
+ struct maat_object_topology *object_topo;
+ struct maat_object_topology *updating_object_topo;
+ long long rule_num;
+ long long excl_rule_num; //exclude g2g rule num
+ long long update_err_cnt;
+ int updating_flag;
+
+ struct maat_garbage_bin *ref_garbage_bin;
+ struct log_handle *logger;
+};
+
+UT_icd ut_object_id_icd = {sizeof(long long), NULL, NULL, NULL};
+
+static inline int compare_object_id(const void *a, const void *b)
+{
+ long long ret = *(const long long *)a - *(const long long *)b;
+
+ if (0 == ret) {
+ return 0;
+ } else if(ret < 0) {
+ return -1;
+ } else {
+ return 1;
+ }
+}
+
+void *object2object_schema_new(cJSON *json, struct table_manager *tbl_mgr,
+ const char *table_name, struct log_handle *logger)
+{
+ struct object2object_schema *g2g_schema = ALLOC(struct object2object_schema, 1);
+
+ cJSON *custom_item = NULL;
+ cJSON *item = cJSON_GetObjectItem(json, "table_id");
+ if (item != NULL && item->type == cJSON_Number) {
+ g2g_schema->table_id = item->valueint;
+ } else {
+ log_fatal(logger, MODULE_OBJECT,
+ "[%s:%d] g2g table:<%s> schema has no table_id column",
+ __FUNCTION__, __LINE__, table_name);
+ goto error;
+ }
+
+ item = cJSON_GetObjectItem(json, "custom");
+ if (item == NULL || item->type != cJSON_Object) {
+ log_fatal(logger, MODULE_OBJECT,
+ "[%s:%d] g2g table:<%s> schema has no custom column",
+ __FUNCTION__, __LINE__, table_name);
+ goto error;
+ }
+
+ custom_item = cJSON_GetObjectItem(item, "object_id");
+ if (custom_item != NULL && custom_item->type == cJSON_Number) {
+ g2g_schema->object_id_column = custom_item->valueint;
+ } else {
+ log_fatal(logger, MODULE_OBJECT,
+ "[%s:%d] g2g table:<%s> schema has no object_id column",
+ __FUNCTION__, __LINE__, table_name);
+ goto error;
+ }
+
+ custom_item = cJSON_GetObjectItem(item, "included_sub_object_ids");
+ if (custom_item != NULL && custom_item->type == cJSON_Number) {
+ g2g_schema->incl_sub_object_ids_column = custom_item->valueint;
+ } else {
+ log_fatal(logger, MODULE_OBJECT,
+ "[%s:%d] g2g table:<%s> schema has no included_sub_object_ids column",
+ __FUNCTION__, __LINE__, table_name);
+ goto error;
+ }
+
+ custom_item = cJSON_GetObjectItem(item, "excluded_sub_object_ids");
+ if (custom_item != NULL && custom_item->type == cJSON_Number) {
+ g2g_schema->excl_sub_object_ids_column = custom_item->valueint;
+ } else {
+ log_fatal(logger, MODULE_OBJECT,
+ "[%s:%d] g2g table:<%s> schema has no excluded_sub_object_ids column",
+ __FUNCTION__, __LINE__, table_name);
+ goto error;
+ }
+
+ g2g_schema->ref_tbl_mgr = tbl_mgr;
+ return g2g_schema;
+error:
+ FREE(g2g_schema);
+ return NULL;
+}
+
+void object2object_schema_free(void *g2g_schema)
+{
+ FREE(g2g_schema);
+}
+
+static void object_vertex_free(struct maat_object *object)
+{
+ if (NULL == object) {
+ return;
+ }
+
+ if (object->incl_super_object_ids != NULL) {
+ utarray_free(object->incl_super_object_ids);
+ object->incl_super_object_ids = NULL;
+ }
+
+ if (object->excl_super_object_ids != NULL) {
+ utarray_free(object->excl_super_object_ids);
+ object->excl_super_object_ids = NULL;
+ }
+
+ if (object->incl_sub_object_ids != NULL) {
+ utarray_free(object->incl_sub_object_ids);
+ object->incl_sub_object_ids = NULL;
+ }
+
+ if (object->excl_sub_object_ids != NULL) {
+ utarray_free(object->excl_sub_object_ids);
+ object->excl_sub_object_ids = NULL;
+ }
+
+ FREE(object);
+}
+
+static struct maat_object_topology *
+maat_object_topology_new(struct log_handle *logger)
+{
+ struct maat_object_topology *object_topo = ALLOC(struct maat_object_topology, 1);
+ UNUSED int ret = 0;
+
+ object_topo->hash_by_object_id = NULL;
+ object_topo->hash_by_vertex_id = NULL;
+
+ ret = igraph_empty(&(object_topo->object_graph), 0, IGRAPH_DIRECTED);
+ assert(ret == IGRAPH_SUCCESS);
+
+ object_topo->logger = logger;
+
+ return object_topo;
+}
+
+static void maat_object_topology_free(struct maat_object_topology *object_topo)
+{
+ if (NULL == object_topo) {
+ return;
+ }
+
+ struct maat_object *object = NULL, *tmp_object = NULL;
+
+ HASH_CLEAR(hh_vertex_id, object_topo->hash_by_vertex_id);//No need object memory clean up.
+ HASH_ITER(hh_object_id, object_topo->hash_by_object_id, object, tmp_object) {
+ HASH_DELETE(hh_object_id, object_topo->hash_by_object_id, object);
+ object_vertex_free(object);
+ }
+ assert(object_topo->hash_by_object_id == NULL);
+
+ igraph_destroy(&object_topo->object_graph);
+ FREE(object_topo);
+}
+
+static struct maat_object *maat_object_clone(struct maat_object *object)
+{
+ struct maat_object *object_copy = ALLOC(struct maat_object, 1);
+
+ object_copy->object_id = object->object_id;
+ object_copy->vertex_id = object->vertex_id;
+ object_copy->ref_by_sub_object_cnt = object->ref_by_sub_object_cnt;
+ object_copy->ref_by_super_object_cnt = object->ref_by_super_object_cnt;
+ utarray_new(object_copy->incl_super_object_ids, &ut_object_id_icd);
+ utarray_new(object_copy->excl_super_object_ids, &ut_object_id_icd);
+ utarray_new(object_copy->incl_sub_object_ids, &ut_object_id_icd);
+ utarray_new(object_copy->excl_sub_object_ids, &ut_object_id_icd);
+
+ long long *p = NULL;
+ for (p = (long long *)utarray_front(object->incl_super_object_ids); p != NULL;
+ p = (long long *)utarray_next(object->incl_super_object_ids, p)) {
+ utarray_push_back(object_copy->incl_super_object_ids, p);
+ }
+
+ for (p = (long long *)utarray_front(object->excl_super_object_ids); p != NULL;
+ p = (long long *)utarray_next(object->excl_super_object_ids, p)) {
+ utarray_push_back(object_copy->excl_super_object_ids, p);
+ }
+
+ for (p = (long long *)utarray_front(object->incl_sub_object_ids); p != NULL;
+ p = (long long *)utarray_next(object->incl_sub_object_ids, p)) {
+ utarray_push_back(object_copy->incl_sub_object_ids, p);
+ }
+
+ for (p = (long long *)utarray_front(object->excl_sub_object_ids); p != NULL;
+ p = (long long *)utarray_next(object->excl_sub_object_ids, p)) {
+ utarray_push_back(object_copy->excl_sub_object_ids, p);
+ }
+
+ return object_copy;
+}
+
+static struct maat_object_topology *
+maat_object_topology_clone(struct maat_object_topology *object_topo)
+{
+ if (NULL == object_topo) {
+ return NULL;
+ }
+
+ struct maat_object_topology *object_topo_copy = ALLOC(struct maat_object_topology, 1);
+
+ struct maat_object *object = NULL, *tmp_object = NULL;
+ HASH_ITER(hh_object_id, object_topo->hash_by_object_id, object, tmp_object) {
+ struct maat_object *object_copy = maat_object_clone(object);
+
+ HASH_ADD(hh_object_id, object_topo_copy->hash_by_object_id, object_id,
+ sizeof(object_copy->object_id), object_copy);
+ HASH_ADD(hh_vertex_id, object_topo_copy->hash_by_vertex_id, vertex_id,
+ sizeof(object_copy->vertex_id), object_copy);
+ }
+
+ igraph_copy(&(object_topo_copy->object_graph), &(object_topo->object_graph));
+ object_topo_copy->grp_vertex_id_generator = object_topo->grp_vertex_id_generator;
+ object_topo_copy->logger = object_topo->logger;
+
+ return object_topo_copy;
+}
+
+void *object2object_runtime_new(void *g2g_schema, size_t max_thread_num,
+ struct maat_garbage_bin *garbage_bin,
+ struct log_handle *logger)
+{
+ if (NULL == g2g_schema) {
+ return NULL;
+ }
+
+ struct object2object_runtime *g2g_rt = ALLOC(struct object2object_runtime, 1);
+
+ g2g_rt->object_topo = maat_object_topology_new(logger);
+ g2g_rt->ref_garbage_bin = garbage_bin;
+ g2g_rt->logger = logger;
+
+ return g2g_rt;
+}
+
+void object2object_runtime_free(void *g2g_runtime)
+{
+ if (NULL == g2g_runtime) {
+ return;
+ }
+
+ struct object2object_runtime *g2g_rt = (struct object2object_runtime *)g2g_runtime;
+
+ if (g2g_rt->object_topo != NULL) {
+ maat_object_topology_free(g2g_rt->object_topo);
+ g2g_rt->object_topo = NULL;
+ }
+
+ if (g2g_rt->updating_object_topo != NULL) {
+ maat_object_topology_free(g2g_rt->updating_object_topo);
+ g2g_rt->updating_object_topo = NULL;
+ }
+
+ FREE(g2g_rt);
+}
+
+static struct object2object_item *
+object2object_item_new(const char *line, struct object2object_schema *g2g_schema,
+ const char *table_name, struct log_handle *logger)
+{
+ size_t column_offset = 0;
+ size_t column_len = 0;
+ struct object2object_item *g2g_item = ALLOC(struct object2object_item, 1);
+ utarray_new(g2g_item->incl_sub_object_ids, &ut_object_id_icd);
+ utarray_new(g2g_item->excl_sub_object_ids, &ut_object_id_icd);
+
+ int ret = get_column_pos(line, g2g_schema->object_id_column,
+ &column_offset, &column_len);
+ if (ret < 0) {
+ log_fatal(logger, MODULE_OBJECT,
+ "[%s:%d] g2 table:<%s> has no object_id in line:%s",
+ __FUNCTION__, __LINE__, table_name, line);
+ goto error;
+ }
+ g2g_item->object_id = atoll(line + column_offset);
+
+ ret = get_column_pos(line, g2g_schema->incl_sub_object_ids_column,
+ &column_offset, &column_len);
+ if (ret < 0) {
+ log_fatal(logger, MODULE_OBJECT,
+ "[%s:%d] g2g table:<%s> has no included_sub_object_ids in line:%s",
+ __FUNCTION__, __LINE__, table_name, line);
+ goto error;
+ }
+
+ char object_ids_str[MAX_OBJECT_IDS_STR_LEN] = {0};
+ memcpy(object_ids_str, line + column_offset, MIN(MAX_OBJECT_IDS_STR_LEN, column_len));
+
+ ret = ids_str2longlong_array(object_ids_str, g2g_item->incl_sub_object_ids);
+ if (ret < 0) {
+ log_fatal(logger, MODULE_OBJECT,
+ "[%s:%d] g2c table:<%s> included_sub_object_ids str2longlong failed in line:%s",
+ __FUNCTION__, __LINE__, table_name, line);
+ goto error;
+ }
+
+ if (utarray_len(g2g_item->incl_sub_object_ids) > MAX_OBJECT_CNT) {
+ log_fatal(logger, MODULE_OBJECT,
+ "[%s:%d] g2c table:<%s> included_sub_object_ids exceed maximum:%d in line:%s",
+ __FUNCTION__, __LINE__, table_name, MAX_OBJECT_CNT, line);
+ goto error;
+ }
+
+ ret = get_column_pos(line, g2g_schema->excl_sub_object_ids_column,
+ &column_offset, &column_len);
+ if (ret < 0) {
+ log_fatal(logger, MODULE_OBJECT,
+ "[%s:%d] g2g table:<%s> has no excluded_sub_object_ids in line:%s",
+ __FUNCTION__, __LINE__, table_name, line);
+ goto error;
+ }
+
+ memset(object_ids_str, 0, sizeof(object_ids_str));
+ memcpy(object_ids_str, line + column_offset, MIN(MAX_OBJECT_IDS_STR_LEN, column_len));
+
+ ret = ids_str2longlong_array(object_ids_str, g2g_item->excl_sub_object_ids);
+ if (ret < 0) {
+ log_fatal(logger, MODULE_OBJECT,
+ "[%s:%d] g2c table:<%s> excluded_sub_object_ids str2longlong failed in line:%s",
+ __FUNCTION__, __LINE__, table_name, line);
+ goto error;
+ }
+
+ if (utarray_len(g2g_item->excl_sub_object_ids) > MAX_OBJECT_CNT) {
+ log_fatal(logger, MODULE_OBJECT,
+ "[%s:%d] g2c table:<%s> excluded_sub_object_ids exceed maximum:%d in line:%s",
+ __FUNCTION__, __LINE__, table_name, MAX_OBJECT_CNT, line);
+ goto error;
+ }
+
+ return g2g_item;
+error:
+ FREE(g2g_item);
+ return NULL;
+}
+
+static void object2object_item_free(struct object2object_item *g2g_item)
+{
+ if (NULL == g2g_item) {
+ return;
+ }
+
+ if (g2g_item->incl_sub_object_ids != NULL) {
+ utarray_free(g2g_item->incl_sub_object_ids);
+ g2g_item->incl_sub_object_ids = NULL;
+ }
+
+ if (g2g_item->excl_sub_object_ids != NULL) {
+ utarray_free(g2g_item->excl_sub_object_ids);
+ g2g_item->excl_sub_object_ids = NULL;
+ }
+
+ FREE(g2g_item);
+}
+
+static size_t print_igraph_vector(igraph_vector_t *v, char *buff, size_t sz) {
+ long int i;
+ int printed = 0;
+
+ for (i = 0; i < igraph_vector_size(v); i++) {
+ printed += snprintf(buff + printed, sz - printed, " %li",
+ (long int) VECTOR(*v)[i]);
+ }
+
+ return printed;
+}
+
+static struct maat_object *
+object_topology_add_object(struct maat_object_topology *object_topo, long long object_id)
+{
+ assert(object_topo != NULL);
+
+ struct maat_object *object = ALLOC(struct maat_object, 1);
+ object->object_id = object_id;
+ object->vertex_id = object_topo->grp_vertex_id_generator++;
+ utarray_new(object->incl_super_object_ids, &ut_object_id_icd);
+ utarray_new(object->excl_super_object_ids, &ut_object_id_icd);
+ utarray_new(object->incl_sub_object_ids, &ut_object_id_icd);
+ utarray_new(object->excl_sub_object_ids, &ut_object_id_icd);
+
+ assert(igraph_vcount(&object_topo->object_graph)==object->vertex_id);
+ igraph_add_vertices(&object_topo->object_graph, 1, NULL); //Add 1 vertice.
+
+ HASH_ADD(hh_object_id, object_topo->hash_by_object_id, object_id,
+ sizeof(object->object_id), object);
+ HASH_ADD(hh_vertex_id, object_topo->hash_by_vertex_id, vertex_id,
+ sizeof(object->vertex_id), object);
+
+ return object;
+}
+
+static void object_topology_del_object(struct maat_object_topology *object_topo,
+ struct maat_object *object)
+{
+ if (NULL == object_topo || NULL == object) {
+ return;
+ }
+
+ igraph_vector_t v;
+ char buff[4096] = {0};
+
+ assert(object->ref_by_super_object_cnt == 0);
+
+ igraph_vector_init(&v, 8);
+ igraph_neighbors(&object_topo->object_graph, &v, object->vertex_id, IGRAPH_ALL);
+ if (igraph_vector_size(&v) > 0) {
+ print_igraph_vector(&v, buff, sizeof(buff));
+ log_fatal(object_topo->logger, MODULE_OBJECT,
+ "[%s:%d] Del object %d exception, still reached by %s.",
+ __FUNCTION__, __LINE__, object->vertex_id, buff);
+ assert(0);
+ }
+ igraph_vector_destroy(&v);
+
+ //We should not call igraph_delete_vertices, because this is function changes the ids of the vertices.
+
+ HASH_DELETE(hh_object_id, object_topo->hash_by_object_id, object);
+ HASH_DELETE(hh_vertex_id, object_topo->hash_by_vertex_id, object);
+ object_vertex_free(object);
+}
+
+static struct maat_object *
+object_topology_find_object(struct maat_object_topology *object_topo, long long object_id)
+{
+ if (NULL == object_topo || object_id < 0) {
+ return NULL;
+ }
+
+ struct maat_object *object = NULL;
+ HASH_FIND(hh_object_id, object_topo->hash_by_object_id, &object_id, sizeof(object_id), object);
+
+ return object;
+}
+
+static void maat_object_reference_super_object(struct maat_object *object,
+ long long super_object_id,
+ int is_exclude)
+{
+ if (NULL == object || super_object_id < 0) {
+ return;
+ }
+
+ if (0 == is_exclude) {
+ //include superior object
+ if (!utarray_find(object->incl_super_object_ids, &super_object_id,
+ compare_object_id)) {
+ utarray_push_back(object->incl_super_object_ids, &super_object_id);
+ utarray_sort(object->incl_super_object_ids, compare_object_id);
+ }
+ } else {
+ //exclude superior object
+ if (!utarray_find(object->excl_super_object_ids, &super_object_id,
+ compare_object_id)) {
+ utarray_push_back(object->excl_super_object_ids, &super_object_id);
+ utarray_sort(object->excl_super_object_ids, compare_object_id);
+ }
+ }
+}
+
+static void maat_object_reference_sub_object(struct maat_object *object,
+ long long sub_object_id,
+ int is_exclude)
+{
+ if (NULL == object || sub_object_id < 0) {
+ return;
+ }
+
+ if (0 == is_exclude) {
+ //include sub object
+ if (!utarray_find(object->incl_sub_object_ids, &sub_object_id,
+ compare_object_id)) {
+ utarray_push_back(object->incl_sub_object_ids, &sub_object_id);
+ utarray_sort(object->incl_sub_object_ids, compare_object_id);
+ }
+ } else {
+ //exclude sub object
+ if (!utarray_find(object->excl_sub_object_ids, &sub_object_id,
+ compare_object_id)) {
+ utarray_push_back(object->excl_sub_object_ids, &sub_object_id);
+ utarray_sort(object->excl_sub_object_ids, compare_object_id);
+ }
+ }
+}
+
+static void maat_object_dereference_super_object(struct maat_object *object,
+ long long super_object_id,
+ int is_exclude)
+{
+ if (NULL == object || super_object_id < 0) {
+ return;
+ }
+
+ size_t remove_idx = 0;
+ long long *tmp_id = NULL;
+ if (0 == is_exclude) {
+ //include superior object
+ tmp_id = utarray_find(object->incl_super_object_ids, &super_object_id,
+ compare_object_id);
+ if (tmp_id != NULL) {
+ remove_idx = utarray_eltidx(object->incl_super_object_ids, tmp_id);
+ utarray_erase(object->incl_super_object_ids, remove_idx, 1);
+ }
+ } else {
+ //exclude superior object
+ tmp_id = utarray_find(object->excl_super_object_ids, &super_object_id,
+ compare_object_id);
+ if (tmp_id != NULL) {
+ remove_idx = utarray_eltidx(object->excl_super_object_ids, tmp_id);
+ utarray_erase(object->excl_super_object_ids, remove_idx, 1);
+ }
+ }
+}
+
+static void maat_object_dereference_sub_object(struct maat_object *object,
+ long long sub_object_id,
+ int is_exclude)
+{
+ if (NULL == object || sub_object_id < 0) {
+ return;
+ }
+
+ size_t remove_idx = 0;
+ long long *tmp_id = NULL;
+ if (0 == is_exclude) {
+ //include superior object
+ tmp_id = utarray_find(object->incl_sub_object_ids, &sub_object_id,
+ compare_object_id);
+ if (tmp_id != NULL) {
+ remove_idx = utarray_eltidx(object->incl_sub_object_ids, tmp_id);
+ utarray_erase(object->incl_sub_object_ids, remove_idx, 1);
+ }
+ } else {
+ //exclude superior object
+ tmp_id = utarray_find(object->excl_sub_object_ids, &sub_object_id,
+ compare_object_id);
+ if (tmp_id != NULL) {
+ remove_idx = utarray_eltidx(object->excl_sub_object_ids, tmp_id);
+ utarray_erase(object->excl_sub_object_ids, remove_idx, 1);
+ }
+ }
+}
+
+static int object_topology_add_object_to_object(struct maat_object_topology *object_topo,
+ long long object_id, long long sub_object_id,
+ int is_exclude)
+{
+ if (NULL == object_topo) {
+ return -1;
+ }
+
+ struct maat_object *sub_object = object_topology_find_object(object_topo, sub_object_id);
+ if (NULL == sub_object) {
+ sub_object = object_topology_add_object(object_topo, sub_object_id);
+ }
+
+ struct maat_object *object = object_topology_find_object(object_topo, object_id);
+ if (NULL == object) {
+ object = object_topology_add_object(object_topo, object_id);
+ }
+
+ maat_object_reference_super_object(sub_object, object_id, is_exclude);
+ maat_object_reference_sub_object(object, sub_object_id, is_exclude);
+
+ igraph_integer_t edge_id;
+ int ret = igraph_get_eid(&object_topo->object_graph, &edge_id, sub_object->vertex_id,
+ object->vertex_id, IGRAPH_DIRECTED, /*error*/ 0);
+
+ //No duplicated edges between two objects.
+ if (edge_id > 0) {
+ log_fatal(object_topo->logger, MODULE_OBJECT,
+ "[%s:%d] Add object %d to object %d failed, relation already existed.",
+ __FUNCTION__, __LINE__, sub_object->object_id, object->object_id);
+ ret = -1;
+ } else {
+ igraph_add_edge(&object_topo->object_graph, sub_object->vertex_id,
+ object->vertex_id);
+ sub_object->ref_by_super_object_cnt++;
+ object->ref_by_sub_object_cnt++;
+ ret = 0;
+ }
+
+ igraph_bool_t is_dag;
+ igraph_is_dag(&(object_topo->object_graph), &is_dag);
+ if (!is_dag) {
+ log_fatal(object_topo->logger, MODULE_OBJECT,
+ "[%s:%d] Sub object cycle detected, sub_object_id:%lld, object_id:%lld!",
+ __FUNCTION__, __LINE__, sub_object_id, object_id);
+ return -1;
+ }
+
+ return ret;
+}
+
+static int object_topology_del_object_from_object(struct maat_object_topology *object_topo,
+ long long object_id, long long sub_object_id,
+ int is_exclude)
+{
+ if (NULL == object_topo) {
+ return -1;
+ }
+
+ //No hash write operation, LOCK protection is unnecessary.
+ struct maat_object *sub_object = object_topology_find_object(object_topo, sub_object_id);
+ if (NULL == sub_object) {
+ log_fatal(object_topo->logger, MODULE_OBJECT,
+ "[%s:%d] Del object %d from object %d failed, object %d not existed.",
+ __FUNCTION__, __LINE__, sub_object_id, object_id, sub_object_id);
+ return -1;
+ }
+
+ struct maat_object *object = object_topology_find_object(object_topo, object_id);
+ if (NULL == object) {
+ log_fatal(object_topo->logger, MODULE_OBJECT,
+ "[%s:%d] Del object %d from object %d failed, object %d not existed.",
+ __FUNCTION__, __LINE__, sub_object_id, object_id, object_id);
+ return -1;
+ }
+
+ maat_object_dereference_super_object(sub_object, object_id, is_exclude);
+ maat_object_dereference_sub_object(object, sub_object_id, is_exclude);
+
+ igraph_es_t es;
+ igraph_integer_t edge_num_before = 0, edge_num_after = 0;
+
+ edge_num_before = igraph_ecount(&object_topo->object_graph);
+ // The edges between the given pairs of vertices will be included in the edge selection.
+ //The vertex pairs must be given as the arguments of the function call, the third argument
+ //is the first vertex of the first edge, the fourth argument is the second vertex of the
+ //first edge, the fifth is the first vertex of the second edge and so on. The last element
+ //of the argument list must be -1 to denote the end of the argument list.
+ //https://igraph.org/c/doc/igraph-Iterators.html#igraph_es_pairs_small
+ int ret = igraph_es_pairs_small(&es, IGRAPH_DIRECTED, sub_object->vertex_id,
+ object->vertex_id, -1);
+ assert(ret==IGRAPH_SUCCESS);
+ // ignore no such edge to abort().
+ igraph_set_error_handler(igraph_error_handler_ignore);
+ ret = igraph_delete_edges(&object_topo->object_graph, es);
+ edge_num_after = igraph_ecount(&object_topo->object_graph);
+ igraph_es_destroy(&es);
+
+ if (ret != IGRAPH_SUCCESS || edge_num_before - edge_num_after != 1) {
+ assert(0);
+ return -1;
+ }
+
+ sub_object->ref_by_super_object_cnt--;
+ object->ref_by_sub_object_cnt--;
+
+ return 0;
+}
+
+static int object_topology_build_super_objects(struct maat_object_topology *object_topo)
+{
+ if (NULL == object_topo) {
+ return -1;
+ }
+
+ igraph_bool_t is_dag;
+ igraph_is_dag(&(object_topo->object_graph), &is_dag);
+ if (!is_dag) {
+ log_fatal(object_topo->logger, MODULE_OBJECT,
+ "[%s:%d] Sub object cycle detected!", __FUNCTION__, __LINE__);
+ return -1;
+ }
+
+ struct maat_object *object = NULL, *tmp_object = NULL;
+ HASH_ITER (hh_object_id, object_topo->hash_by_object_id, object, tmp_object) {
+ //Orphan, Not reference by any one, free it.
+ if (0 == object->ref_by_super_object_cnt
+ && 0 == object->ref_by_sub_object_cnt) {
+ object_topology_del_object(object_topo, object);
+ continue;
+ }
+ }
+
+ return 0;
+}
+
+int object2object_runtime_update(void *g2g_runtime, void *g2g_schema,
+ const char *table_name, const char *line,
+ int valid_column)
+{
+ if (NULL == g2g_runtime || NULL == g2g_schema ||
+ NULL == line) {
+ return -1;
+ }
+
+ struct object2object_schema *schema = (struct object2object_schema *)g2g_schema;
+ struct object2object_runtime *g2g_rt = (struct object2object_runtime *)g2g_runtime;
+ int is_valid = get_column_value(line, valid_column);
+ if (is_valid < 0) {
+ log_fatal(g2g_rt->logger, MODULE_OBJECT,
+ "[%s:%d] g2g table:<%s> has no is_valid(column seq:%d)"
+ " in table_line:%s", __FUNCTION__, __LINE__, table_name,
+ valid_column, line);
+ g2g_rt->update_err_cnt++;
+ return -1;
+ }
+
+ struct object2object_item *g2g_item = object2object_item_new(line, schema, table_name,
+ g2g_rt->logger);
+ if (NULL == g2g_item) {
+ g2g_rt->update_err_cnt++;
+ return -1;
+ }
+
+ if (0 == g2g_rt->updating_flag) {
+ assert(g2g_rt->updating_object_topo == NULL);
+ g2g_rt->updating_object_topo = maat_object_topology_clone(g2g_rt->object_topo);
+ g2g_rt->updating_flag = 1;
+ }
+
+ int ret = 0;
+ size_t i = 0;
+ int err_flag = 0;
+ long long *sub_object_id = NULL;
+ if (0 == is_valid) {
+ //delete
+ for (i = 0; i < utarray_len(g2g_item->incl_sub_object_ids); i++) {
+ sub_object_id = (long long *)utarray_eltptr(g2g_item->incl_sub_object_ids, i);
+ ret = object_topology_del_object_from_object(g2g_rt->updating_object_topo,
+ g2g_item->object_id, *sub_object_id, 0);
+ if (ret != 0) {
+ err_flag = 1;
+ }
+ }
+
+ for (i = 0; i < utarray_len(g2g_item->excl_sub_object_ids); i++) {
+ sub_object_id = (long long *)utarray_eltptr(g2g_item->excl_sub_object_ids, i);
+ ret = object_topology_del_object_from_object(g2g_rt->updating_object_topo,
+ g2g_item->object_id, *sub_object_id, 1);
+ if (ret != 0) {
+ err_flag = 1;
+ }
+ }
+
+ if (1 == err_flag) {
+ g2g_rt->update_err_cnt++;
+ } else {
+ if (utarray_len(g2g_item->excl_sub_object_ids) > 0) {
+ g2g_rt->excl_rule_num--;
+ }
+ g2g_rt->rule_num--;
+ }
+ } else {
+ //add
+ for (i = 0; i < utarray_len(g2g_item->incl_sub_object_ids); i++) {
+ sub_object_id = (long long *)utarray_eltptr(g2g_item->incl_sub_object_ids, i);
+ ret = object_topology_add_object_to_object(g2g_rt->updating_object_topo,
+ g2g_item->object_id, *sub_object_id, 0);
+ if (ret != 0) {
+ err_flag = 1;
+ }
+ }
+
+ for (i = 0; i < utarray_len(g2g_item->excl_sub_object_ids); i++) {
+ sub_object_id = (long long *)utarray_eltptr(g2g_item->excl_sub_object_ids, i);
+ ret = object_topology_add_object_to_object(g2g_rt->updating_object_topo,
+ g2g_item->object_id, *sub_object_id, 1);
+ if (ret != 0) {
+ err_flag = 1;
+ }
+ }
+
+ if (1 == err_flag) {
+ g2g_rt->update_err_cnt++;
+ } else {
+ if (utarray_len(g2g_item->excl_sub_object_ids) > 0) {
+ g2g_rt->excl_rule_num++;
+ }
+ g2g_rt->rule_num++;
+ }
+ }
+ object2object_item_free(g2g_item);
+
+ return ret;
+}
+
+static void garbage_maat_object_topology_free(void *data, void *arg)
+{
+ struct maat_object_topology *object_topo = (struct maat_object_topology *)data;
+ maat_object_topology_free(object_topo);
+}
+
+int object2object_runtime_commit(void *g2g_runtime, const char *table_name,
+ long long maat_rt_version)
+{
+ if (NULL == g2g_runtime) {
+ return -1;
+ }
+
+ struct object2object_runtime *g2g_rt = (struct object2object_runtime *)g2g_runtime;
+ if (0 == g2g_rt->updating_flag) {
+ return 0;
+ }
+
+ struct timespec start, end;
+ clock_gettime(CLOCK_MONOTONIC, &start);
+ int ret = object_topology_build_super_objects(g2g_rt->updating_object_topo);
+ clock_gettime(CLOCK_MONOTONIC, &end);
+ long long time_elapse_ms = (end.tv_sec - start.tv_sec) * 1000 +
+ (end.tv_nsec - start.tv_nsec) / 1000000;
+
+ if (ret < 0) {
+ log_fatal(g2g_rt->logger, MODULE_OBJECT,
+ "[%s:%d] table[%s] object2object runtime commit failed",
+ __FUNCTION__, __LINE__, table_name);
+ return -1;
+ }
+
+ struct maat_object_topology *old_object_topo = g2g_rt->object_topo;
+ g2g_rt->object_topo = g2g_rt->updating_object_topo;
+ g2g_rt->updating_object_topo = NULL;
+ g2g_rt->updating_flag = 0;
+
+ maat_garbage_bagging(g2g_rt->ref_garbage_bin, old_object_topo, NULL,
+ garbage_maat_object_topology_free);
+
+ log_info(g2g_rt->logger, MODULE_OBJECT,
+ "table[%s] commit %zu g2g rules and rebuild super_objects completed,"
+ " version:%lld, consume:%lldms", table_name, g2g_rt->rule_num,
+ maat_rt_version, time_elapse_ms);
+
+ return 0;
+}
+
+#define MAX_RECURSION_DEPTH 5
+static void get_candidate_super_object_ids(struct maat_object_topology *object_topo,
+ UT_array *hit_object_ids,
+ UT_array *super_object_ids)
+{
+ long long *p = NULL;
+
+ //Find super candidates
+ for (p = (long long *)utarray_front(hit_object_ids); p != NULL;
+ p = (long long *)utarray_next(hit_object_ids, p)) {
+ struct maat_object *object = object_topology_find_object(object_topo, *p);
+ if (NULL == object) {
+ //object_id not in object2object table
+ continue;
+ }
+
+ for (int i = 0; i < utarray_len(object->incl_super_object_ids); i++) {
+ long long *tmp = (long long *)utarray_eltptr(object->incl_super_object_ids, i);
+ utarray_push_back(super_object_ids, tmp);
+ }
+ }
+}
+
+static void verify_object_by_sub_include_objects(struct maat_object *object,
+ UT_array *candidate_object_ids,
+ UT_array *kept_super_object_ids,
+ UT_array *all_hit_object_ids)
+{
+ size_t remove_idx = 0;
+ long long *tmp_id = NULL;
+
+ // delete objects whose all incl sub not in all_hit_object_ids
+ if (utarray_len(object->incl_sub_object_ids) != 0) {
+ int sub_incl_flag = 0;
+
+ for (tmp_id = (long long *)utarray_front(object->incl_sub_object_ids); tmp_id != NULL;
+ tmp_id = (long long *)utarray_next(object->incl_sub_object_ids, tmp_id)) {
+ if (utarray_find(candidate_object_ids, tmp_id, compare_object_id)) {
+ sub_incl_flag = 1;
+ break;
+ }
+ }
+
+ if (0 == sub_incl_flag) {
+ tmp_id = utarray_find(all_hit_object_ids, &(object->object_id), compare_object_id);
+ if (tmp_id != NULL) {
+ remove_idx = utarray_eltidx(all_hit_object_ids, tmp_id);
+ utarray_erase(all_hit_object_ids, remove_idx, 1);
+ }
+
+ tmp_id = utarray_find(kept_super_object_ids, &(object->object_id), compare_object_id);
+ if (tmp_id != NULL) {
+ remove_idx = utarray_eltidx(kept_super_object_ids, tmp_id);
+ utarray_erase(kept_super_object_ids, remove_idx, 1);
+ }
+ }
+ }
+}
+
+static void verify_object_by_sub_exclude_objects(struct maat_object *object,
+ UT_array *candidate_object_ids,
+ UT_array *kept_super_object_ids,
+ UT_array *all_hit_object_ids)
+{
+ if (0 == utarray_len(object->excl_sub_object_ids)) {
+ return;
+ }
+
+ // delete objects whose excl sub in all_hit_object_ids
+ int sub_excl_flag = 0;
+ long long *tmp_id = NULL;
+ for (tmp_id = (long long *)utarray_front(object->excl_sub_object_ids); tmp_id != NULL;
+ tmp_id = (long long *)utarray_next(object->excl_sub_object_ids, tmp_id)) {
+ if (utarray_find(candidate_object_ids, tmp_id, compare_object_id)) {
+ sub_excl_flag = 1;
+ break;
+ }
+ }
+
+ if (1 == sub_excl_flag) {
+ size_t remove_idx = 0;
+ tmp_id = utarray_find(all_hit_object_ids, &(object->object_id), compare_object_id);
+ if (tmp_id != NULL) {
+ remove_idx = utarray_eltidx(all_hit_object_ids, tmp_id);
+ utarray_erase(all_hit_object_ids, remove_idx, 1);
+ }
+
+ tmp_id = utarray_find(kept_super_object_ids, &(object->object_id), compare_object_id);
+ if (tmp_id != NULL) {
+ remove_idx = utarray_eltidx(kept_super_object_ids, tmp_id);
+ utarray_erase(kept_super_object_ids, remove_idx, 1);
+ }
+ }
+}
+
+static void verify_candidate_super_object_ids(struct maat_object_topology *object_topo,
+ UT_array *candidate_super_object_ids,
+ UT_array *all_hit_object_ids,
+ UT_array *kept_super_object_ids)
+{
+ long long *p = NULL;
+ UT_array *candidate_object_ids;
+
+ utarray_new(candidate_object_ids, &ut_object_id_icd);
+
+ /* merge this round of candidate super objects with hit objects from the previous round */
+ for (p = (long long *)utarray_front(candidate_super_object_ids); p != NULL;
+ p = (long long *)utarray_next(candidate_super_object_ids, p)) {
+ utarray_push_back(candidate_object_ids, p);
+ }
+
+ for (p = (long long *)utarray_front(all_hit_object_ids); p != NULL;
+ p = (long long *)utarray_next(all_hit_object_ids, p)) {
+ utarray_push_back(candidate_object_ids, p);
+ }
+
+ utarray_sort(candidate_object_ids, compare_object_id);
+
+ /**
+ * verify sub exclude for candidate_super_object_ids
+ */
+ long long prev_object_id = -1;
+ for (p = (long long *)utarray_front(candidate_super_object_ids); p != NULL;
+ p = (long long *)utarray_next(candidate_super_object_ids, p)) {
+ //filter duplicated object id
+ if (*p == prev_object_id) {
+ continue;
+ }
+ prev_object_id = *p;
+
+ struct maat_object *object = object_topology_find_object(object_topo, *p);
+ if (NULL == object) {
+ continue;
+ }
+
+ //if object's sub excl in candidate_object_ids
+ int sub_excl_flag = 0;
+ long long *tmp_id = NULL;
+ for (tmp_id = (long long *)utarray_front(object->excl_sub_object_ids); tmp_id != NULL;
+ tmp_id = (long long *)utarray_next(object->excl_sub_object_ids, tmp_id)) {
+ if (utarray_find(candidate_object_ids, tmp_id, compare_object_id)) {
+ sub_excl_flag = 1;
+ break;
+ }
+ }
+
+ //kept super objects should not store this object
+ if (1 == sub_excl_flag) {
+ continue;
+ }
+
+ utarray_push_back(kept_super_object_ids, p);
+ utarray_push_back(all_hit_object_ids, p);
+ }
+
+ utarray_sort(all_hit_object_ids, compare_object_id);
+ utarray_sort(kept_super_object_ids, compare_object_id);
+
+ /**
+ * candidate_object_ids clone all_hit_object_ids
+ */
+ utarray_clear(candidate_object_ids);
+ for (p = (long long *)utarray_front(all_hit_object_ids); p != NULL;
+ p = (long long *)utarray_next(all_hit_object_ids, p)) {
+ utarray_push_back(candidate_object_ids, p);
+ }
+
+ /**
+ * 1. delete objects whose excl sub in all_hit_object_ids
+ * 2. delete objects whose all incl sub is non-exist in all_hit_object_ids
+ */
+ for (p = (long long *)utarray_front(candidate_object_ids); p != NULL;
+ p = (long long *)utarray_next(candidate_object_ids, p)) {
+ struct maat_object *object = object_topology_find_object(object_topo, *p);
+ if (NULL == object) {
+ continue;
+ }
+
+ verify_object_by_sub_exclude_objects(object, candidate_object_ids,
+ kept_super_object_ids, all_hit_object_ids);
+ verify_object_by_sub_include_objects(object, candidate_object_ids,
+ kept_super_object_ids, all_hit_object_ids);
+ }
+
+ utarray_free(candidate_object_ids);
+}
+
+static void get_super_object_ids(struct maat_object_topology *object_topo,
+ UT_array *hit_object_ids, UT_array *all_hit_object_ids,
+ size_t depth)
+{
+ UT_array *candidate_super_object_ids;
+ UT_array *kept_super_object_ids;
+
+ if (depth >= MAX_RECURSION_DEPTH) {
+ log_error(object_topo->logger, MODULE_OBJECT,
+ "[%s:%d]exceed max recursion depth(5)",
+ __FUNCTION__, __LINE__);
+ for (int i = 0; i < utarray_len(hit_object_ids); i++) {
+ long long *p = (long long *)utarray_eltptr(hit_object_ids, i);
+ log_error(object_topo->logger, MODULE_OBJECT,
+ "[%s:%d]object_id:%lld can't recursively get super object_id",
+ __FUNCTION__, __LINE__, *p);
+ }
+ return;
+ }
+
+ utarray_new(kept_super_object_ids, &ut_object_id_icd);
+ utarray_new(candidate_super_object_ids, &ut_object_id_icd);
+
+ /**
+ candidate super objects means all hit objects' super include object,
+ don't consider super exclude objects
+ for example:
+ hit_objects = {g4, g11}
+ g4's super include objects = {g7, g8}
+ g11's super include objects = {g12}
+
+ candidate super objects = {g7, g8, g12}
+ */
+ get_candidate_super_object_ids(object_topo, hit_object_ids, candidate_super_object_ids);
+
+ if (0 == utarray_len(candidate_super_object_ids)) {
+ goto next;
+ }
+
+ /**
+ verify if candidates should be kept for hit super objects, must consider exclude objects
+ for example:
+ hit_objects = {g4, g11}
+ \:include x:exclude
+ g12
+ x \
+ x \
+ x \
+ x \
+ g7 g8 \
+ x \ /\ \
+ x \ / \ \
+ x \ / \ \
+ x \/ \ \
+ g3 g4 g5 g11
+ candidate super objects = {g7, g8, g12}
+ verify logic:
+ 1. g12's sub_exclude g8 in candidates, so g12 should be dropped
+ 2. g7 & g8, their sub_include in hit objects, so kept them
+ if their all sub_include not exist in hit objects, they should be dropped
+ after verify candidates, kept super objects = {g7, g8},
+ all hit objects = {g4, g11, g7, g8}
+ */
+ verify_candidate_super_object_ids(object_topo, candidate_super_object_ids, all_hit_object_ids,
+ kept_super_object_ids);
+
+ depth++;
+ get_super_object_ids(object_topo, kept_super_object_ids, all_hit_object_ids, depth);
+next:
+ utarray_free(candidate_super_object_ids);
+ utarray_free(kept_super_object_ids);
+}
+
+static size_t object_topology_get_super_objects(struct maat_object_topology *object_topo,
+ long long *object_ids, size_t n_object_ids,
+ long long *super_object_ids,
+ size_t super_object_ids_size)
+{
+ size_t i = 0, idx = 0;
+ UT_array *all_hit_object_ids;
+ UT_array *candidate_object_ids;
+
+ utarray_new(all_hit_object_ids, &ut_object_id_icd);
+ utarray_new(candidate_object_ids, &ut_object_id_icd);
+
+ for (i = 0; i < n_object_ids; i++) {
+ utarray_push_back(all_hit_object_ids, &(object_ids[i]));
+ utarray_push_back(candidate_object_ids, &(object_ids[i]));
+ }
+
+ get_super_object_ids(object_topo, candidate_object_ids, all_hit_object_ids, 0);
+
+ for (i = 0; i < n_object_ids; i++) {
+ long long *tmp_id = utarray_find(all_hit_object_ids, &(object_ids[i]),
+ compare_object_id);
+ if (tmp_id != NULL) {
+ size_t remove_idx = utarray_eltidx(all_hit_object_ids, tmp_id);
+ utarray_erase(all_hit_object_ids, remove_idx, 1);
+ }
+ }
+
+ long long *p = NULL;
+ for (p = (long long *)utarray_front(all_hit_object_ids); p != NULL;
+ p = (long long *)utarray_next(all_hit_object_ids, p)) {
+ if (idx >= super_object_ids_size) {
+ break;
+ }
+ super_object_ids[idx++] = *p;
+ }
+
+ utarray_free(all_hit_object_ids);
+ utarray_free(candidate_object_ids);
+
+ return idx;
+}
+
+size_t object2object_runtime_get_super_objects(void *g2g_runtime, long long *object_ids,
+ size_t n_object_ids, long long *super_object_ids,
+ size_t super_object_ids_size)
+{
+ if (NULL == g2g_runtime || NULL == object_ids || 0 == n_object_ids) {
+ return 0;
+ }
+
+ struct object2object_runtime *g2g_rt = (struct object2object_runtime *)g2g_runtime;
+ long long g2g_object_ids[n_object_ids];
+ size_t g2g_object_ids_cnt = 0;
+
+ for (size_t i = 0; i < n_object_ids; i++) {
+ struct maat_object *object = object_topology_find_object(g2g_rt->object_topo, object_ids[i]);
+ if (NULL == object) {
+ continue;
+ }
+
+ g2g_object_ids[g2g_object_ids_cnt++] = object_ids[i];
+ }
+
+ if (0 == g2g_object_ids_cnt) {
+ return 0;
+ }
+
+ return object_topology_get_super_objects(g2g_rt->object_topo, g2g_object_ids, g2g_object_ids_cnt,
+ super_object_ids, super_object_ids_size);
+}
+
+long long object2object_runtime_rule_count(void *g2g_runtime)
+{
+ if (NULL == g2g_runtime) {
+ return 0;
+ }
+
+ struct object2object_runtime *g2g_rt = (struct object2object_runtime *)g2g_runtime;
+ return g2g_rt->rule_num;
+}
+
+long long object2object_runtime_exclude_rule_count(void *g2g_runtime)
+{
+ if (NULL == g2g_runtime) {
+ return 0;
+ }
+
+ struct object2object_runtime *g2g_rt = (struct object2object_runtime *)g2g_runtime;
+ return g2g_rt->excl_rule_num;
+}
+
+long long object2object_runtime_update_err_count(void *g2g_runtime)
+{
+ if (NULL == g2g_runtime) {
+ return 0;
+ }
+
+ struct object2object_runtime *g2g_rt = (struct object2object_runtime *)g2g_runtime;
+ return g2g_rt->update_err_cnt;
+} \ No newline at end of file
diff --git a/src/maat_rule.c b/src/maat_rule.c
index eb30f17..9fec6cc 100644
--- a/src/maat_rule.c
+++ b/src/maat_rule.c
@@ -21,7 +21,7 @@
#include "igraph/igraph.h"
#include "maat_rule.h"
#include "maat_garbage_collection.h"
-#include "maat_group.h"
+#include "maat_object.h"
#include "maat_ex_data.h"
#include "maat_table.h"
#include "alignment.h"
@@ -44,8 +44,8 @@ struct rule_schema {
struct log_handle *logger;
};
-struct group2rule_schema {
- int group_id_column;
+struct object2rule_schema {
+ int object_id_column;
int rule_id_column;
int negate_option_column;
int attribute_name_column;
@@ -62,8 +62,8 @@ struct rule_item {
size_t table_line_len;
};
-struct group2rule_item {
- UT_array *group_ids;
+struct object2rule_item {
+ UT_array *object_ids;
long long rule_id;
int negate_option;
int attribute_id;
@@ -71,7 +71,7 @@ struct group2rule_item {
};
struct condition_query_key {
- long long group_id;
+ long long object_id;
int attribute_id;
int negate_option;
};
@@ -86,17 +86,17 @@ struct table_condition {
int attribute_id;
int actual_condition_num;
UT_array *condition_ids;
- UT_array *group_ids;
+ UT_array *object_ids;
UT_hash_handle hh;
};
-struct table_group {
+struct table_object {
int attribute_id;
- UT_array *group_ids;
+ UT_array *object_ids;
UT_hash_handle hh;
};
-/* rule_runtime and group2rule_runtime share rule_hash_map */
+/* rule_runtime and object2rule_runtime share rule_hash_map */
struct rule_runtime {
struct bool_matcher *bm;
struct rcu_hash_table *cfg_hash; // <rule_id, struct maat_rule>
@@ -112,7 +112,7 @@ struct rule_runtime {
long long update_err_cnt;
};
-struct group2rule_runtime {
+struct object2rule_runtime {
long long not_condition_cnt;
long long rule_num;
long long update_err_cnt;
@@ -121,8 +121,8 @@ struct group2rule_runtime {
};
struct condition_literal {
- long long group_ids[MAX_GROUP_CNT];
- int group_cnt;
+ long long object_ids[MAX_OBJECT_CNT];
+ int object_cnt;
int attribute_id;
};
@@ -152,7 +152,7 @@ struct maat_rule {
struct internal_hit_path {
long long item_id;
- long long group_id;
+ long long object_id;
int Nth_scan;
int attribute_id;
int negate_option; // 1 means negate condition
@@ -173,17 +173,17 @@ struct rule_state {
UT_array *this_scan_hit_conditions;
UT_array *this_scan_hit_not_conditions;
UT_array *exclude_not_conditions;
- UT_array *direct_hit_groups;
- UT_array *indirect_hit_groups;
- UT_array *last_hit_groups;
+ UT_array *direct_hit_objects;
+ UT_array *indirect_hit_objects;
+ UT_array *last_hit_objects;
UT_array *hit_rule_table_ids;
- struct table_group *hit_not_tbl_groups;
+ struct table_object *hit_not_tbl_objects;
};
UT_icd ut_condition_id_icd = {sizeof(long long), NULL, NULL, NULL};
UT_icd ut_condition_literal_icd = {sizeof(struct condition_literal), NULL, NULL, NULL};
-UT_icd ut_rule_group_id_icd = {sizeof(long long), NULL, NULL, NULL};
-UT_icd ut_maat_hit_group_icd = {sizeof(struct maat_hit_group), NULL, NULL, NULL};
+UT_icd ut_rule_object_id_icd = {sizeof(long long), NULL, NULL, NULL};
+UT_icd ut_maat_hit_object_icd = {sizeof(struct maat_hit_object), NULL, NULL, NULL};
UT_icd ut_hit_path_icd = {sizeof(struct internal_hit_path), NULL, NULL, NULL};
UT_icd ut_hit_rule_table_id_icd = {sizeof(struct rule2table_id), NULL, NULL, NULL};
@@ -415,10 +415,10 @@ void rule_schema_free(void *rule_schema)
FREE(rule_schema);
}
-void *group2rule_schema_new(cJSON *json, struct table_manager *tbl_mgr,
+void *object2rule_schema_new(cJSON *json, struct table_manager *tbl_mgr,
const char *table_name, struct log_handle *logger)
{
- struct group2rule_schema *g2c_schema = ALLOC(struct group2rule_schema, 1);
+ struct object2rule_schema *g2c_schema = ALLOC(struct object2rule_schema, 1);
cJSON *custom_item = NULL;
cJSON *item = cJSON_GetObjectItem(json, "table_id");
@@ -449,12 +449,12 @@ void *group2rule_schema_new(cJSON *json, struct table_manager *tbl_mgr,
goto error;
}
- custom_item = cJSON_GetObjectItem(item, "group_id");
+ custom_item = cJSON_GetObjectItem(item, "object_id");
if (custom_item != NULL && custom_item->type == cJSON_Number) {
- g2c_schema->group_id_column = custom_item->valueint;
+ g2c_schema->object_id_column = custom_item->valueint;
} else {
log_fatal(logger, MODULE_RULE,
- "[%s:%d] table: <%s> schema has no group_id column",
+ "[%s:%d] table: <%s> schema has no object_id column",
__FUNCTION__, __LINE__, table_name);
goto error;
}
@@ -506,14 +506,14 @@ error:
return NULL;
}
-void group2rule_schema_free(void *g2c_schema)
+void object2rule_schema_free(void *g2c_schema)
{
FREE(g2c_schema);
}
-int group2rule_associated_rule_table_id(void *g2c_schema)
+int object2rule_associated_rule_table_id(void *g2c_schema)
{
- struct group2rule_schema *schema = (struct group2rule_schema *)g2c_schema;
+ struct object2rule_schema *schema = (struct object2rule_schema *)g2c_schema;
return schema->asso_rule_table_id;
}
@@ -609,7 +609,7 @@ void rule_runtime_init(void *rule_runtime, struct maat_runtime *maat_rt)
rule_rt->ref_maat_rt = maat_rt;
}
-void *group2rule_runtime_new(void *g2c_schema, size_t max_thread_num,
+void *object2rule_runtime_new(void *g2c_schema, size_t max_thread_num,
struct maat_garbage_bin *garbage_bin,
struct log_handle *logger)
{
@@ -617,30 +617,30 @@ void *group2rule_runtime_new(void *g2c_schema, size_t max_thread_num,
return NULL;
}
- struct group2rule_runtime *g2c_rt =
- ALLOC(struct group2rule_runtime, 1);
+ struct object2rule_runtime *g2c_rt =
+ ALLOC(struct object2rule_runtime, 1);
g2c_rt->tbl_not_condition_hash = NULL;
return g2c_rt;
}
-void group2rule_runtime_init(void *g2c_runtime, void *rule_runtime)
+void object2rule_runtime_init(void *g2c_runtime, void *rule_runtime)
{
- struct group2rule_runtime *g2c_rt =
- (struct group2rule_runtime *)g2c_runtime;
+ struct object2rule_runtime *g2c_rt =
+ (struct object2rule_runtime *)g2c_runtime;
g2c_rt->ref_rule_rt = (struct rule_runtime *)rule_runtime;
}
-void group2rule_runtime_free(void *g2c_runtime)
+void object2rule_runtime_free(void *g2c_runtime)
{
if (NULL == g2c_runtime) {
return;
}
- struct group2rule_runtime *g2c_rt =
- (struct group2rule_runtime *)g2c_runtime;
+ struct object2rule_runtime *g2c_rt =
+ (struct object2rule_runtime *)g2c_runtime;
if (g2c_rt->tbl_not_condition_hash != NULL) {
struct table_condition *not_condition = NULL, *tmp_not_condition = NULL;
@@ -671,54 +671,54 @@ static int is_valid_table_name(const char *str)
return 1;
}
-static void group2rule_item_free(struct group2rule_item *g2c_item)
+static void object2rule_item_free(struct object2rule_item *g2c_item)
{
if (NULL == g2c_item) {
return;
}
- if (g2c_item->group_ids != NULL) {
- utarray_free(g2c_item->group_ids);
- g2c_item->group_ids = NULL;
+ if (g2c_item->object_ids != NULL) {
+ utarray_free(g2c_item->object_ids);
+ g2c_item->object_ids = NULL;
}
FREE(g2c_item);
}
-static struct group2rule_item *
-group2rule_item_new(const char *line, struct group2rule_schema *g2c_schema,
+static struct object2rule_item *
+object2rule_item_new(const char *line, struct object2rule_schema *g2c_schema,
const char *table_name, struct log_handle *logger)
{
size_t column_offset = 0;
size_t column_len = 0;
char attribute_name[MAX_NAME_STR_LEN + 1] = {0};
- struct group2rule_item *g2c_item = ALLOC(struct group2rule_item, 1);
- utarray_new(g2c_item->group_ids, &ut_rule_group_id_icd);
+ struct object2rule_item *g2c_item = ALLOC(struct object2rule_item, 1);
+ utarray_new(g2c_item->object_ids, &ut_rule_object_id_icd);
- int ret = get_column_pos(line, g2c_schema->group_id_column, &column_offset,
+ int ret = get_column_pos(line, g2c_schema->object_id_column, &column_offset,
&column_len);
if (ret < 0) {
log_fatal(logger, MODULE_RULE,
- "[%s:%d] g2c table:<%s> has no group_id in line:%s",
+ "[%s:%d] g2c table:<%s> has no object_id in line:%s",
__FUNCTION__, __LINE__, table_name, line);
goto error;
}
- char group_ids_str[MAX_GROUP_IDS_STR_LEN] = {0};
- memcpy(group_ids_str, line + column_offset, MIN(MAX_GROUP_IDS_STR_LEN, column_len));
+ char object_ids_str[MAX_OBJECT_IDS_STR_LEN] = {0};
+ memcpy(object_ids_str, line + column_offset, MIN(MAX_OBJECT_IDS_STR_LEN, column_len));
- ret = ids_str2longlong_array(group_ids_str, g2c_item->group_ids);
+ ret = ids_str2longlong_array(object_ids_str, g2c_item->object_ids);
if (ret < 0) {
log_fatal(logger, MODULE_RULE,
- "[%s:%d] g2c table:<%s> group_ids str2longlong failed in line:%s",
+ "[%s:%d] g2c table:<%s> object_ids str2longlong failed in line:%s",
__FUNCTION__, __LINE__, table_name, line);
goto error;
}
- if (utarray_len(g2c_item->group_ids) > MAX_GROUP_CNT) {
+ if (utarray_len(g2c_item->object_ids) > MAX_OBJECT_CNT) {
log_fatal(logger, MODULE_RULE,
- "[%s:%d] g2c table:<%s> group_ids exceed maximum:%d in line:%s",
- __FUNCTION__, __LINE__, table_name, MAX_GROUP_CNT, line);
+ "[%s:%d] g2c table:<%s> object_ids exceed maximum:%d in line:%s",
+ __FUNCTION__, __LINE__, table_name, MAX_OBJECT_CNT, line);
goto error;
}
@@ -802,11 +802,11 @@ group2rule_item_new(const char *line, struct group2rule_schema *g2c_schema,
return g2c_item;
error:
- group2rule_item_free(g2c_item);
+ object2rule_item_free(g2c_item);
return NULL;
}
-static inline int compare_group_id(const void *a, const void *b)
+static inline int compare_object_id(const void *a, const void *b)
{
long long ret = *(const long long *)a - *(const long long *)b;
@@ -820,21 +820,21 @@ static inline int compare_group_id(const void *a, const void *b)
}
static void rule_condition_add_literal(struct rule_condition *condition,
- struct group2rule_item *g2c_item)
+ struct object2rule_item *g2c_item)
{
struct condition_literal tmp_literal;
tmp_literal.attribute_id = g2c_item->attribute_id;
- tmp_literal.group_cnt = utarray_len(g2c_item->group_ids);
- utarray_sort(g2c_item->group_ids, compare_group_id);
+ tmp_literal.object_cnt = utarray_len(g2c_item->object_ids);
+ utarray_sort(g2c_item->object_ids, compare_object_id);
- for (size_t i = 0; i < utarray_len(g2c_item->group_ids); i++) {
- tmp_literal.group_ids[i] = *(long long *)utarray_eltptr(g2c_item->group_ids, i);
+ for (size_t i = 0; i < utarray_len(g2c_item->object_ids); i++) {
+ tmp_literal.object_ids[i] = *(long long *)utarray_eltptr(g2c_item->object_ids, i);
}
utarray_push_back(condition->literals, &tmp_literal);
}
void rule_condition_remove_literal(struct rule_condition *condition,
- struct group2rule_item *g2c_item)
+ struct object2rule_item *g2c_item)
{
struct condition_literal *tmp_literal = NULL;
@@ -849,7 +849,7 @@ void rule_condition_remove_literal(struct rule_condition *condition,
}
static int maat_rule_condition_find_literal(struct maat_rule *rule,
- struct group2rule_item *g2c_item)
+ struct object2rule_item *g2c_item)
{
struct rule_condition *condition = rule->conditions + g2c_item->condition_index;
struct condition_literal *tmp_literal = NULL;
@@ -866,7 +866,7 @@ static int maat_rule_condition_find_literal(struct maat_rule *rule,
}
static void maat_rule_condition_add_literal(struct maat_rule *rule,
- struct group2rule_item *g2c_item)
+ struct object2rule_item *g2c_item)
{
struct rule_condition *condition = rule->conditions + g2c_item->condition_index;
@@ -881,7 +881,7 @@ static void maat_rule_condition_add_literal(struct maat_rule *rule,
}
static void maat_rule_condition_remove_literal(struct maat_rule *rule,
- struct group2rule_item *g2c_item)
+ struct object2rule_item *g2c_item)
{
struct rule_condition *condition = rule->conditions + g2c_item->condition_index;
@@ -941,9 +941,9 @@ maat_rule_bool_matcher_new(struct rule_runtime *rule_rt,
struct condition_literal *tmp_cl = NULL;
for(tmp_cl = (struct condition_literal *)utarray_front(iter_rule->conditions[i].literals); tmp_cl !=NULL;
tmp_cl = (struct condition_literal *)utarray_next(iter_rule->conditions[i].literals, tmp_cl)) {
- for (size_t it = 0; it < tmp_cl->group_cnt; it++) {
+ for (size_t it = 0; it < tmp_cl->object_cnt; it++) {
printf("<before bool_matcher_new> rule_rt:%p rule_id:%lld, condition_id:%llu, condition_query_key{%lld: %d, %d}\n",
- rule_rt, iter_rule->rule_id, iter_rule->conditions[i].condition_id, tmp_cl->group_ids[it],
+ rule_rt, iter_rule->rule_id, iter_rule->conditions[i].condition_id, tmp_cl->object_ids[it],
tmp_cl->attribute_id, iter_rule->conditions[i].negate_option);
}
}
@@ -954,7 +954,7 @@ maat_rule_bool_matcher_new(struct rule_runtime *rule_rt,
}
}
- // some rule may have zero groups, e.g. default policy.
+ // some rule may have zero objects, e.g. default policy.
if (j == (size_t)iter_rule->declared_condition_num && j > 0) {
bool_expr_array[expr_cnt].expr_id = iter_rule->rule_id;
bool_expr_array[expr_cnt].user_tag = iter_rule;
@@ -1002,14 +1002,14 @@ static inline int compare_condition_id(const void *a, const void *b)
}
}
-static inline int compare_hit_group(const void *pa, const void *pb)
+static inline int compare_hit_object(const void *pa, const void *pb)
{
- struct maat_hit_group *la=(struct maat_hit_group *)pa;
- struct maat_hit_group *lb=(struct maat_hit_group *)pb;
+ struct maat_hit_object *la=(struct maat_hit_object *)pa;
+ struct maat_hit_object *lb=(struct maat_hit_object *)pb;
long long ret = la->item_id - lb->item_id;
if (0 == ret) {
- ret = la->group_id - lb->group_id;
+ ret = la->object_id - lb->object_id;
if (0 == ret) {
ret = la->attribute_id - lb->attribute_id;
}
@@ -1074,9 +1074,9 @@ build_condition_id_kv_hash(struct rule_runtime *rule_rt, int negate_option)
for (size_t j = 0; j < utarray_len(condition->literals); j++) {
tmp_cl = (struct condition_literal *)utarray_eltptr(condition->literals, j);
- for (size_t k = 0; k < tmp_cl->group_cnt; k++) {
+ for (size_t k = 0; k < tmp_cl->object_cnt; k++) {
struct condition_query_key key =
- {tmp_cl->group_ids[k], tmp_cl->attribute_id, condition->negate_option};
+ {tmp_cl->object_ids[k], tmp_cl->attribute_id, condition->negate_option};
struct condition_id_kv *condition_id_kv = NULL;
HASH_FIND(hh, condition_id_kv_hash, &key, sizeof(struct condition_query_key),
@@ -1268,8 +1268,8 @@ maat_rule_clone(struct maat_rule *rule, int deep_copy)
return new_rule;
}
-static int maat_add_group_to_rule(struct rcu_hash_table *hash_tbl,
- struct group2rule_item *g2c_item,
+static int maat_add_object_to_rule(struct rcu_hash_table *hash_tbl,
+ struct object2rule_item *g2c_item,
struct log_handle *logger)
{
int ret = 0;
@@ -1340,8 +1340,8 @@ static int maat_add_group_to_rule(struct rcu_hash_table *hash_tbl,
return 0;
}
-static int maat_remove_group_from_rule(struct rcu_hash_table *hash_tbl,
- struct group2rule_item *g2c_item,
+static int maat_remove_object_from_rule(struct rcu_hash_table *hash_tbl,
+ struct object2rule_item *g2c_item,
struct log_handle *logger)
{
int ret = 0;
@@ -1429,33 +1429,33 @@ struct rule_state *rule_state_new(void)
utarray_new(rule_state->this_scan_hit_conditions, &ut_condition_id_icd);
utarray_new(rule_state->this_scan_hit_not_conditions, &ut_condition_id_icd);
utarray_new(rule_state->exclude_not_conditions, &ut_condition_id_icd);
- utarray_new(rule_state->direct_hit_groups, &ut_maat_hit_group_icd);
- utarray_new(rule_state->indirect_hit_groups, &ut_maat_hit_group_icd);
- utarray_new(rule_state->last_hit_groups, &ut_maat_hit_group_icd);
+ utarray_new(rule_state->direct_hit_objects, &ut_maat_hit_object_icd);
+ utarray_new(rule_state->indirect_hit_objects, &ut_maat_hit_object_icd);
+ utarray_new(rule_state->last_hit_objects, &ut_maat_hit_object_icd);
utarray_new(rule_state->hit_rule_table_ids, &ut_hit_rule_table_id_icd);
- rule_state->hit_not_tbl_groups = NULL;
+ rule_state->hit_not_tbl_objects = NULL;
return rule_state;
}
static long long
-rule_state_hit_not_tbl_groups_free(struct rule_state *rule_state)
+rule_state_hit_not_tbl_objects_free(struct rule_state *rule_state)
{
if (NULL == rule_state) {
return 0;
}
long long free_bytes = 0;
- struct table_group *tbl_group = NULL, *tmp_tbl_group = NULL;
- HASH_ITER(hh, rule_state->hit_not_tbl_groups, tbl_group, tmp_tbl_group) {
+ struct table_object *tbl_object = NULL, *tmp_tbl_object = NULL;
+ HASH_ITER(hh, rule_state->hit_not_tbl_objects, tbl_object, tmp_tbl_object) {
free_bytes +=
- (sizeof(tbl_group) + utarray_len(tbl_group->group_ids) * sizeof(long long));
- HASH_DEL(rule_state->hit_not_tbl_groups, tbl_group);
- if (tbl_group->group_ids != NULL) {
- utarray_free(tbl_group->group_ids);
- tbl_group->group_ids = NULL;
+ (sizeof(tbl_object) + utarray_len(tbl_object->object_ids) * sizeof(long long));
+ HASH_DEL(rule_state->hit_not_tbl_objects, tbl_object);
+ if (tbl_object->object_ids != NULL) {
+ utarray_free(tbl_object->object_ids);
+ tbl_object->object_ids = NULL;
}
- FREE(tbl_group);
+ FREE(tbl_object);
}
return free_bytes;
@@ -1476,14 +1476,14 @@ void rule_state_reset(struct rule_state *rule_state)
utarray_clear(rule_state->this_scan_hit_conditions);
utarray_clear(rule_state->this_scan_hit_not_conditions);
utarray_clear(rule_state->exclude_not_conditions);
- utarray_clear(rule_state->direct_hit_groups);
- utarray_clear(rule_state->indirect_hit_groups);
- utarray_clear(rule_state->last_hit_groups);
+ utarray_clear(rule_state->direct_hit_objects);
+ utarray_clear(rule_state->indirect_hit_objects);
+ utarray_clear(rule_state->last_hit_objects);
utarray_clear(rule_state->hit_rule_table_ids);
- struct table_group *tbl_group = NULL, *tmp_tbl_group = NULL;
- HASH_ITER(hh, rule_state->hit_not_tbl_groups, tbl_group, tmp_tbl_group) {
- utarray_clear(tbl_group->group_ids);
+ struct table_object *tbl_object = NULL, *tmp_tbl_object = NULL;
+ HASH_ITER(hh, rule_state->hit_not_tbl_objects, tbl_object, tmp_tbl_object) {
+ utarray_clear(tbl_object->object_ids);
}
}
@@ -1530,25 +1530,25 @@ void rule_state_free(struct rule_state *rule_state,
rule_state->exclude_not_conditions = NULL;
}
- if (rule_state->direct_hit_groups != NULL) {
- free_bytes += utarray_size(rule_state->direct_hit_groups) *
- sizeof(struct maat_hit_group);
- utarray_free(rule_state->direct_hit_groups);
- rule_state->direct_hit_groups = NULL;
+ if (rule_state->direct_hit_objects != NULL) {
+ free_bytes += utarray_size(rule_state->direct_hit_objects) *
+ sizeof(struct maat_hit_object);
+ utarray_free(rule_state->direct_hit_objects);
+ rule_state->direct_hit_objects = NULL;
}
- if (rule_state->indirect_hit_groups != NULL) {
- free_bytes += utarray_size(rule_state->indirect_hit_groups) *
- sizeof(struct maat_hit_group);
- utarray_free(rule_state->indirect_hit_groups);
- rule_state->indirect_hit_groups = NULL;
+ if (rule_state->indirect_hit_objects != NULL) {
+ free_bytes += utarray_size(rule_state->indirect_hit_objects) *
+ sizeof(struct maat_hit_object);
+ utarray_free(rule_state->indirect_hit_objects);
+ rule_state->indirect_hit_objects = NULL;
}
- if (rule_state->last_hit_groups != NULL) {
- free_bytes += utarray_size(rule_state->last_hit_groups) *
- sizeof(struct maat_hit_group);
- utarray_free(rule_state->last_hit_groups);
- rule_state->last_hit_groups = NULL;
+ if (rule_state->last_hit_objects != NULL) {
+ free_bytes += utarray_size(rule_state->last_hit_objects) *
+ sizeof(struct maat_hit_object);
+ utarray_free(rule_state->last_hit_objects);
+ rule_state->last_hit_objects = NULL;
}
if (rule_state->hit_rule_table_ids != NULL) {
@@ -1558,7 +1558,7 @@ void rule_state_free(struct rule_state *rule_state,
rule_state->hit_rule_table_ids = NULL;
}
- free_bytes += rule_state_hit_not_tbl_groups_free(rule_state);
+ free_bytes += rule_state_hit_not_tbl_objects_free(rule_state);
FREE(rule_state);
@@ -1569,7 +1569,7 @@ void rule_state_free(struct rule_state *rule_state,
static void
rule_state_add_internal_hit_path(struct rule_state *rule_state,
- long long item_id, long long group_id,
+ long long item_id, long long object_id,
int attribute_id, int negate_option, int Nth_scan)
{
if (NULL == rule_state) {
@@ -1579,7 +1579,7 @@ rule_state_add_internal_hit_path(struct rule_state *rule_state,
struct internal_hit_path new_path;
new_path.item_id = item_id;
new_path.Nth_scan = Nth_scan;
- new_path.group_id = group_id;
+ new_path.object_id = object_id;
new_path.attribute_id = attribute_id;
new_path.negate_option = negate_option;
@@ -1606,10 +1606,10 @@ static int maat_rule_has_condition_query_key(struct maat_rule *rule,
continue;
}
- long long *tmp_group_id = bsearch(&(key->group_id), tmp_cl->group_ids,
- tmp_cl->group_cnt, sizeof(long long),
- compare_group_id);
- if (tmp_group_id != NULL) {
+ long long *tmp_object_id = bsearch(&(key->object_id), tmp_cl->object_ids,
+ tmp_cl->object_cnt, sizeof(long long),
+ compare_object_id);
+ if (tmp_object_id != NULL) {
return 1;
}
}
@@ -1620,7 +1620,7 @@ static int maat_rule_has_condition_query_key(struct maat_rule *rule,
static size_t
maat_rule_get_hit_condition_index(struct maat_rule *rule,
- int attribute_id, long long hit_group_id,
+ int attribute_id, long long hit_object_id,
int *condition_idx_array, size_t array_size)
{
size_t hit_condition_cnt = 0;
@@ -1639,10 +1639,10 @@ maat_rule_get_hit_condition_index(struct maat_rule *rule,
continue;
}
- long long *tmp_group_id = bsearch(&hit_group_id, tmp_cl->group_ids,
- tmp_cl->group_cnt, sizeof(long long),
- compare_group_id);
- if (tmp_group_id != NULL) {
+ long long *tmp_object_id = bsearch(&hit_object_id, tmp_cl->object_ids,
+ tmp_cl->object_cnt, sizeof(long long),
+ compare_object_id);
+ if (tmp_object_id != NULL) {
condition_idx_array[hit_condition_cnt++] = i;
break;
}
@@ -1676,8 +1676,8 @@ void populate_hit_path_with_rule(struct maat_hit_path *hit_path_array,
size_t new_hit_path_cnt = *n_new_hit_path;
int condition_index_array[MAX_ITEMS_PER_BOOL_EXPR] = {0};
- if (hit_path_array[idx].top_group_id < 0) {
- hit_path_array[idx].top_group_id = hit_path_array[idx].sub_group_id;
+ if (hit_path_array[idx].top_object_id < 0) {
+ hit_path_array[idx].top_object_id = hit_path_array[idx].sub_object_id;
}
struct maat_hit_path tmp_path;
@@ -1686,7 +1686,7 @@ void populate_hit_path_with_rule(struct maat_hit_path *hit_path_array,
// find out which condition in rule hit
n_condition_index =
maat_rule_get_hit_condition_index(rule, hit_path_array[idx].attribute_id,
- hit_path_array[idx].top_group_id,
+ hit_path_array[idx].top_object_id,
condition_index_array,
MAX_ITEMS_PER_BOOL_EXPR);
hit_path_array[idx].condition_index = condition_index_array[0];
@@ -1706,7 +1706,7 @@ void populate_hit_path_with_rule(struct maat_hit_path *hit_path_array,
hit_path_array[n_hit_path + new_hit_path_cnt] = tmp_path;
new_hit_path_cnt++;
n_condition_index =
- maat_rule_get_hit_condition_index(rule, tmp_path.attribute_id, tmp_path.top_group_id,
+ maat_rule_get_hit_condition_index(rule, tmp_path.attribute_id, tmp_path.top_object_id,
condition_index_array, MAX_ITEMS_PER_BOOL_EXPR);
hit_path_array[n_hit_path + new_hit_path_cnt - 1].condition_index = condition_index_array[0];
if (n_condition_index > 1) {
@@ -1754,10 +1754,10 @@ size_t rule_runtime_get_hit_paths(struct rule_runtime *rule_rt, int thread_id,
}
for (size_t j = 0; j < n_hit_path && (n_hit_path + n_new_hit_path) < array_size; j++) {
- if (hit_path_array[j].top_group_id < 0) {
- key.group_id = hit_path_array[j].sub_group_id;
+ if (hit_path_array[j].top_object_id < 0) {
+ key.object_id = hit_path_array[j].sub_object_id;
} else {
- key.group_id = hit_path_array[j].top_group_id;
+ key.object_id = hit_path_array[j].top_object_id;
}
key.attribute_id = hit_path_array[j].attribute_id;
@@ -1773,7 +1773,7 @@ size_t rule_runtime_get_hit_paths(struct rule_runtime *rule_rt, int thread_id,
}
static void
-rule_state_add_direct_hit_groups(struct rule_state *rule_state,
+rule_state_add_direct_hit_objects(struct rule_state *rule_state,
struct maat_item *hit_items,
size_t n_hit_items, int attribute_id)
{
@@ -1781,30 +1781,30 @@ rule_state_add_direct_hit_groups(struct rule_state *rule_state,
return;
}
- struct maat_hit_group hit_group;
+ struct maat_hit_object hit_object;
for (size_t i = 0; i < n_hit_items; i++) {
- hit_group.item_id = hit_items[i].item_id;
- hit_group.group_id = hit_items[i].group_id;
- hit_group.attribute_id = attribute_id;
- utarray_push_back(rule_state->direct_hit_groups, &hit_group);
+ hit_object.item_id = hit_items[i].item_id;
+ hit_object.object_id = hit_items[i].object_id;
+ hit_object.attribute_id = attribute_id;
+ utarray_push_back(rule_state->direct_hit_objects, &hit_object);
}
}
static void
-rule_state_add_indirect_hit_groups(struct rule_state *rule_state,
- long long *group_ids,
- size_t n_group_ids, int attribute_id)
+rule_state_add_indirect_hit_objects(struct rule_state *rule_state,
+ long long *object_ids,
+ size_t n_object_ids, int attribute_id)
{
- if (NULL == rule_state || NULL == group_ids) {
+ if (NULL == rule_state || NULL == object_ids) {
return;
}
- struct maat_hit_group hit_group;
- for (size_t i = 0; i < n_group_ids; i++) {
- hit_group.item_id = 0;
- hit_group.group_id = group_ids[i];
- hit_group.attribute_id = attribute_id;
- utarray_push_back(rule_state->indirect_hit_groups, &hit_group);
+ struct maat_hit_object hit_object;
+ for (size_t i = 0; i < n_object_ids; i++) {
+ hit_object.item_id = 0;
+ hit_object.object_id = object_ids[i];
+ hit_object.attribute_id = attribute_id;
+ utarray_push_back(rule_state->indirect_hit_objects, &hit_object);
}
}
@@ -1887,13 +1887,13 @@ rule_state_add_hit_not_conditions(struct rule_state *rule_state,
static void
rule_state_update_hit_conditions(struct rule_state *rule_state,
struct rule_runtime *rule_rt,
- long long group_id, int attribute_id)
+ long long object_id, int attribute_id)
{
if (NULL == rule_state || NULL == rule_rt) {
return;
}
- struct condition_query_key key = {group_id, attribute_id, 0};
+ struct condition_query_key key = {object_id, attribute_id, 0};
struct condition_id_kv *condition_id_kv = NULL;
HASH_FIND(hh, rule_rt->condition_id_kv_hash, &key, sizeof(key), condition_id_kv);
@@ -1909,31 +1909,31 @@ rule_state_update_hit_conditions(struct rule_state *rule_state,
}
static void
-rule_state_cache_hit_not_groups(struct rule_state *rule_state,
+rule_state_cache_hit_not_objects(struct rule_state *rule_state,
struct rule_runtime *rule_rt,
- long long *hit_group_ids,
- size_t n_hit_group_id, int attribute_id)
+ long long *hit_object_ids,
+ size_t n_hit_object_id, int attribute_id)
{
if (NULL == rule_state || NULL == rule_rt) {
return;
}
- if (n_hit_group_id != 0) {
- qsort(hit_group_ids, n_hit_group_id, sizeof(long long), compare_group_id);
+ if (n_hit_object_id != 0) {
+ qsort(hit_object_ids, n_hit_object_id, sizeof(long long), compare_object_id);
}
- struct table_group *tbl_group = NULL;
- HASH_FIND(hh, rule_state->hit_not_tbl_groups, &attribute_id, sizeof(int), tbl_group);
- if (tbl_group != NULL) {
- for (size_t i = 0; i < n_hit_group_id; i++) {
- long long *group_id = (long long *)utarray_find(tbl_group->group_ids,
- &hit_group_ids[i],
- compare_group_id);
- if (NULL == group_id) {
+ struct table_object *tbl_object = NULL;
+ HASH_FIND(hh, rule_state->hit_not_tbl_objects, &attribute_id, sizeof(int), tbl_object);
+ if (tbl_object != NULL) {
+ for (size_t i = 0; i < n_hit_object_id; i++) {
+ long long *object_id = (long long *)utarray_find(tbl_object->object_ids,
+ &hit_object_ids[i],
+ compare_object_id);
+ if (NULL == object_id) {
continue;
}
- size_t remove_idx = utarray_eltidx(tbl_group->group_ids, group_id);
- utarray_erase(tbl_group->group_ids, remove_idx, 1);
+ size_t remove_idx = utarray_eltidx(tbl_object->object_ids, object_id);
+ utarray_erase(tbl_object->object_ids, remove_idx, 1);
}
}
@@ -1943,28 +1943,28 @@ rule_state_cache_hit_not_groups(struct rule_state *rule_state,
continue;
}
- long long *tmp_group_id =
- bsearch(&(condition_id_kv->key.group_id), hit_group_ids,
- n_hit_group_id, sizeof(long long), compare_group_id);
- if (tmp_group_id != NULL) {
+ long long *tmp_object_id =
+ bsearch(&(condition_id_kv->key.object_id), hit_object_ids,
+ n_hit_object_id, sizeof(long long), compare_object_id);
+ if (tmp_object_id != NULL) {
continue;
}
- if (NULL == tbl_group) {
- tbl_group = ALLOC(struct table_group, 1);
- tbl_group->attribute_id = attribute_id;
- utarray_new(tbl_group->group_ids, &ut_rule_group_id_icd);
- HASH_ADD_INT(rule_state->hit_not_tbl_groups, attribute_id, tbl_group);
+ if (NULL == tbl_object) {
+ tbl_object = ALLOC(struct table_object, 1);
+ tbl_object->attribute_id = attribute_id;
+ utarray_new(tbl_object->object_ids, &ut_rule_object_id_icd);
+ HASH_ADD_INT(rule_state->hit_not_tbl_objects, attribute_id, tbl_object);
}
- if (!utarray_find(tbl_group->group_ids, &(condition_id_kv->key.group_id),
- compare_group_id)) {
- utarray_push_back(tbl_group->group_ids, &(condition_id_kv->key.group_id));
+ if (!utarray_find(tbl_object->object_ids, &(condition_id_kv->key.object_id),
+ compare_object_id)) {
+ utarray_push_back(tbl_object->object_ids, &(condition_id_kv->key.object_id));
}
}
- if (tbl_group != NULL) {
- utarray_sort(tbl_group->group_ids, compare_group_id);
+ if (tbl_object != NULL) {
+ utarray_sort(tbl_object->object_ids, compare_object_id);
}
}
@@ -2009,14 +2009,14 @@ rule_runtime_add_rule(struct rule_runtime *rule_rt,
sizeof(long long));
if (rule != NULL) {
/****************************************************************
- rule found in updating hash(added by group2rule runtime), which means
+ rule found in updating hash(added by object2rule runtime), which means
1. rcu_hash_add(htable, rule) ==> finished
2. rcu_hash_commit(htable) ==> undo
because it's in updating hash, we can modify it directly
******************************************************************/
- /* rule has group2rule_table info, so set rule_table info */
+ /* rule has object2rule_table info, so set rule_table info */
maat_rule_set(rule, table_id, rule_item->declared_condition_num, rule_item);
} else {
// rule neither in effective hash nor in updating hash
@@ -2029,7 +2029,7 @@ rule_runtime_add_rule(struct rule_runtime *rule_rt,
rule = rcu_hash_find(rule_rt->cfg_hash, (char *)&rule_id, sizeof(long long));
if (rule != NULL) {
/********************************************************************************
- rule found in effective hash(added by group2rule runtime), which means
+ rule found in effective hash(added by object2rule runtime), which means
1. rcu_hash_add(htable, rule) ==> finished
2. rcu_hash_commit(htable) ==> finished
@@ -2043,7 +2043,7 @@ rule_runtime_add_rule(struct rule_runtime *rule_rt,
/* delete rule from rcu hash */
rcu_hash_del(rule_rt->cfg_hash, (char *)&rule_id, sizeof(long long));
- /* copy_rule has group2rule_table info, so set rule_table info */
+ /* copy_rule has object2rule_table info, so set rule_table info */
maat_rule_set(copy_rule, table_id, rule_item->declared_condition_num, rule_item);
/* add copy_rule to rcu hash */
rcu_hash_add(rule_rt->cfg_hash, (char *)&rule_id, sizeof(long long), copy_rule);
@@ -2171,7 +2171,7 @@ int rule_runtime_update(void *rule_runtime, void *rule_schema,
return 0;
}
-static int validate_table_not_condition(struct group2rule_runtime *g2c_rt,
+static int validate_table_not_condition(struct object2rule_runtime *g2c_rt,
struct table_manager *tbl_mgr, int table_id,
int is_valid, struct log_handle *logger)
{
@@ -2207,7 +2207,7 @@ static int validate_table_not_condition(struct group2rule_runtime *g2c_rt,
return 0;
}
-int group2rule_runtime_update(void *g2c_runtime, void *g2c_schema,
+int object2rule_runtime_update(void *g2c_runtime, void *g2c_schema,
const char *table_name, const char *line,
int valid_column)
{
@@ -2215,8 +2215,8 @@ int group2rule_runtime_update(void *g2c_runtime, void *g2c_schema,
return -1;
}
- struct group2rule_schema *schema = (struct group2rule_schema *)g2c_schema;
- struct group2rule_runtime *g2c_rt = (struct group2rule_runtime *)g2c_runtime;
+ struct object2rule_schema *schema = (struct object2rule_schema *)g2c_schema;
+ struct object2rule_runtime *g2c_rt = (struct object2rule_runtime *)g2c_runtime;
struct rule_runtime *rule_rt = g2c_rt->ref_rule_rt;
int is_valid = get_column_value(line, valid_column);
@@ -2230,8 +2230,8 @@ int group2rule_runtime_update(void *g2c_runtime, void *g2c_schema,
}
int ret = -1;
- struct group2rule_item *g2c_item =
- group2rule_item_new(line, schema, table_name, rule_rt->logger);
+ struct object2rule_item *g2c_item =
+ object2rule_item_new(line, schema, table_name, rule_rt->logger);
if (NULL == g2c_item) {
g2c_rt->update_err_cnt++;
return -1;
@@ -2251,7 +2251,7 @@ int group2rule_runtime_update(void *g2c_runtime, void *g2c_schema,
if (0 == is_valid) {
//delete
- ret = maat_remove_group_from_rule(rule_rt->cfg_hash, g2c_item,
+ ret = maat_remove_object_from_rule(rule_rt->cfg_hash, g2c_item,
rule_rt->logger);
if (0 == ret) {
if (g2c_item->negate_option) {
@@ -2263,7 +2263,7 @@ int group2rule_runtime_update(void *g2c_runtime, void *g2c_schema,
}
} else {
//add
- ret = maat_add_group_to_rule(rule_rt->cfg_hash, g2c_item,
+ ret = maat_add_object_to_rule(rule_rt->cfg_hash, g2c_item,
rule_rt->logger);
if (0 == ret) {
if (g2c_item->negate_option) {
@@ -2276,42 +2276,42 @@ int group2rule_runtime_update(void *g2c_runtime, void *g2c_schema,
}
next:
- group2rule_item_free(g2c_item);
+ object2rule_item_free(g2c_item);
return ret;
}
-long long group2rule_runtime_not_condition_count(void *g2c_runtime)
+long long object2rule_runtime_not_condition_count(void *g2c_runtime)
{
if (NULL == g2c_runtime) {
return 0;
}
- struct group2rule_runtime *g2c_rt =
- (struct group2rule_runtime *)g2c_runtime;
+ struct object2rule_runtime *g2c_rt =
+ (struct object2rule_runtime *)g2c_runtime;
return g2c_rt->not_condition_cnt;
}
-long long group2rule_runtime_rule_count(void *g2c_runtime)
+long long object2rule_runtime_rule_count(void *g2c_runtime)
{
if (NULL == g2c_runtime) {
return 0;
}
- struct group2rule_runtime *g2c_rt =
- (struct group2rule_runtime *)g2c_runtime;
+ struct object2rule_runtime *g2c_rt =
+ (struct object2rule_runtime *)g2c_runtime;
return g2c_rt->rule_num;
}
-long long group2rule_runtime_update_err_count(void *g2c_runtime)
+long long object2rule_runtime_update_err_count(void *g2c_runtime)
{
if (NULL == g2c_runtime) {
return 0;
}
- struct group2rule_runtime *g2c_rt =
- (struct group2rule_runtime *)g2c_runtime;
+ struct object2rule_runtime *g2c_rt =
+ (struct object2rule_runtime *)g2c_runtime;
return g2c_rt->update_err_cnt;
}
@@ -2483,47 +2483,47 @@ int rule_state_update(struct rule_state *rule_state, struct maat *maat_inst,
{
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;
+ long long hit_object_ids[MAX_HIT_OBJECT_NUM];
+ struct maat_hit_object hit_object;
utarray_clear(rule_state->this_scan_hit_conditions);
rule_state->this_scan_not_logic = 0;
rule_state->Nth_scan = Nth_scan;
for (i = 0; i < hit_cnt; i++) {
- hit_group_ids[i] = hit_items[i].group_id;
+ hit_object_ids[i] = hit_items[i].object_id;
- hit_group.item_id = hit_items[i].item_id;
- hit_group.group_id = hit_items[i].group_id;
- hit_group.attribute_id = attribute_id;
- utarray_push_back(rule_state->last_hit_groups, &hit_group);
+ hit_object.item_id = hit_items[i].item_id;
+ hit_object.object_id = hit_items[i].object_id;
+ hit_object.attribute_id = attribute_id;
+ utarray_push_back(rule_state->last_hit_objects, &hit_object);
}
- int g2g_table_id = table_manager_get_group2group_table_id(maat_inst->tbl_mgr);
+ int g2g_table_id = table_manager_get_object2object_table_id(maat_inst->tbl_mgr);
void *g2g_rt = table_manager_get_runtime(maat_inst->tbl_mgr, g2g_table_id);
- long long super_group_ids[MAX_HIT_GROUP_NUM];
- size_t super_group_cnt = group2group_runtime_get_super_groups(g2g_rt, hit_group_ids,
- hit_cnt, super_group_ids,
- MAX_HIT_GROUP_NUM);
- for (i = 0; i < super_group_cnt; i++) {
- hit_group.item_id = 0;
- hit_group.group_id = super_group_ids[i];
- hit_group.attribute_id = attribute_id;
- utarray_push_back(rule_state->last_hit_groups, &hit_group);
+ long long super_object_ids[MAX_HIT_OBJECT_NUM];
+ size_t super_object_cnt = object2object_runtime_get_super_objects(g2g_rt, hit_object_ids,
+ hit_cnt, super_object_ids,
+ MAX_HIT_OBJECT_NUM);
+ for (i = 0; i < super_object_cnt; i++) {
+ hit_object.item_id = 0;
+ hit_object.object_id = super_object_ids[i];
+ hit_object.attribute_id = attribute_id;
+ utarray_push_back(rule_state->last_hit_objects, &hit_object);
}
if (1 == maat_inst->opts.hit_path_on && hit_cnt > 0) {
for (i = 0; i < hit_cnt; i++) {
rule_state_add_internal_hit_path(rule_state, hit_items[i].item_id,
- hit_items[i].group_id, attribute_id, 0, Nth_scan);
+ hit_items[i].object_id, attribute_id, 0, Nth_scan);
}
}
- if (1 == maat_inst->opts.hit_group_on) {
- rule_state_add_direct_hit_groups(rule_state, hit_items, hit_cnt, attribute_id);
- rule_state_add_indirect_hit_groups(rule_state, super_group_ids,
- super_group_cnt, attribute_id);
+ if (1 == maat_inst->opts.hit_object_on) {
+ rule_state_add_direct_hit_objects(rule_state, hit_items, hit_cnt, attribute_id);
+ rule_state_add_indirect_hit_objects(rule_state, super_object_ids,
+ super_object_cnt, attribute_id);
}
/* update hit condition */
@@ -2538,27 +2538,27 @@ int rule_state_update(struct rule_state *rule_state, struct maat *maat_inst,
return 0;
}
- for (j = 0; j < super_group_cnt && hit_cnt < MAX_HIT_GROUP_NUM; j++) {
- hit_group_ids[hit_cnt++] = super_group_ids[j];
+ for (j = 0; j < super_object_cnt && hit_cnt < MAX_HIT_OBJECT_NUM; j++) {
+ hit_object_ids[hit_cnt++] = super_object_ids[j];
}
for (i = 0; i < hit_cnt; i++) {
rule_state_update_hit_conditions(rule_state, rule_rt,
- hit_group_ids[i], attribute_id);
+ hit_object_ids[i], attribute_id);
}
- rule_state_cache_hit_not_groups(rule_state, rule_rt, hit_group_ids,
+ rule_state_cache_hit_not_objects(rule_state, rule_rt, hit_object_ids,
hit_cnt, attribute_id);
return hit_cnt;
}
-void rule_state_clear_last_hit_group(struct rule_state *rule_state)
+void rule_state_clear_last_hit_object(struct rule_state *rule_state)
{
if (NULL == rule_state) {
return;
}
- utarray_clear(rule_state->last_hit_groups);
+ utarray_clear(rule_state->last_hit_objects);
}
void rule_state_not_logic_update(struct rule_state *rule_state,
@@ -2574,16 +2574,16 @@ void rule_state_not_logic_update(struct rule_state *rule_state,
rule_state->Nth_scan = Nth_scan;
utarray_clear(rule_state->this_scan_hit_not_conditions);
- struct table_group *tbl_group = NULL;
- HASH_FIND(hh, rule_state->hit_not_tbl_groups, &attribute_id, sizeof(int), tbl_group);
- if (NULL == tbl_group) {
+ struct table_object *tbl_object = NULL;
+ HASH_FIND(hh, rule_state->hit_not_tbl_objects, &attribute_id, sizeof(int), tbl_object);
+ if (NULL == tbl_object) {
return;
}
struct condition_id_kv *condition_id_kv = NULL;
- for (size_t i = 0; i < utarray_len(tbl_group->group_ids); i++) {
- long long *group_id = utarray_eltptr(tbl_group->group_ids, i);
- struct condition_query_key key = {*group_id, attribute_id, 1};
+ for (size_t i = 0; i < utarray_len(tbl_object->object_ids); i++) {
+ long long *object_id = utarray_eltptr(tbl_object->object_ids, i);
+ struct condition_query_key key = {*object_id, attribute_id, 1};
HASH_FIND(hh, rule_rt->not_condition_id_kv_hash, &key, sizeof(key), condition_id_kv);
if (NULL == condition_id_kv) {
@@ -2592,83 +2592,83 @@ void rule_state_not_logic_update(struct rule_state *rule_state,
rule_state_add_hit_not_conditions(rule_state, condition_id_kv->condition_ids);
if (1 == maat_inst->opts.hit_path_on) {
- rule_state_add_internal_hit_path(rule_state, -1, *group_id,
+ rule_state_add_internal_hit_path(rule_state, -1, *object_id,
attribute_id, 1, Nth_scan);
}
}
}
-size_t rule_state_get_indirect_hit_groups(struct rule_state *rule_state,
- struct maat_hit_group *group_array,
+size_t rule_state_get_indirect_hit_objects(struct rule_state *rule_state,
+ struct maat_hit_object *object_array,
size_t array_size)
{
size_t i = 0;
- struct maat_hit_group *hit_group = NULL;
- for (i = 0; i < utarray_len(rule_state->indirect_hit_groups) && i < array_size; i++) {
- hit_group =
- (struct maat_hit_group *)utarray_eltptr(rule_state->indirect_hit_groups, i);
- group_array[i].item_id = hit_group->item_id;
- group_array[i].group_id = hit_group->group_id;
- group_array[i].attribute_id = hit_group->attribute_id;
+ struct maat_hit_object *hit_object = NULL;
+ for (i = 0; i < utarray_len(rule_state->indirect_hit_objects) && i < array_size; i++) {
+ hit_object =
+ (struct maat_hit_object *)utarray_eltptr(rule_state->indirect_hit_objects, i);
+ object_array[i].item_id = hit_object->item_id;
+ object_array[i].object_id = hit_object->object_id;
+ object_array[i].attribute_id = hit_object->attribute_id;
}
- utarray_clear(rule_state->indirect_hit_groups);
+ utarray_clear(rule_state->indirect_hit_objects);
return i;
}
-size_t rule_state_get_indirect_hit_group_cnt(struct rule_state *rule_state)
+size_t rule_state_get_indirect_hit_object_cnt(struct rule_state *rule_state)
{
- return utarray_len(rule_state->indirect_hit_groups);
+ return utarray_len(rule_state->indirect_hit_objects);
}
-size_t rule_state_get_last_hit_groups(struct rule_state *rule_state,
- struct maat_hit_group *group_array,
+size_t rule_state_get_last_hit_objects(struct rule_state *rule_state,
+ struct maat_hit_object *object_array,
size_t array_size)
{
size_t i = 0;
- for (i = 0; i < utarray_len(rule_state->last_hit_groups) && i < array_size; i++) {
- group_array[i] =
- *(struct maat_hit_group *)utarray_eltptr(rule_state->last_hit_groups, i);
+ for (i = 0; i < utarray_len(rule_state->last_hit_objects) && i < array_size; i++) {
+ object_array[i] =
+ *(struct maat_hit_object *)utarray_eltptr(rule_state->last_hit_objects, i);
}
return i;
}
-size_t rule_state_get_last_hit_group_cnt(struct rule_state *rule_state)
+size_t rule_state_get_last_hit_object_cnt(struct rule_state *rule_state)
{
- return utarray_len(rule_state->last_hit_groups);
+ return utarray_len(rule_state->last_hit_objects);
}
-size_t rule_state_get_direct_hit_groups(struct rule_state *rule_state,
- struct maat_hit_group *group_array,
+size_t rule_state_get_direct_hit_objects(struct rule_state *rule_state,
+ struct maat_hit_object *object_array,
size_t array_size)
{
- UT_array *direct_hit_group = rule_state->direct_hit_groups;
+ UT_array *direct_hit_object = rule_state->direct_hit_objects;
size_t i = 0;
- struct maat_hit_group *group = NULL;
- for (i = 0; i < utarray_len(direct_hit_group) && i < array_size; i++) {
- group = (struct maat_hit_group *)utarray_eltptr(direct_hit_group, i);
- group_array[i].item_id = group->item_id;
- group_array[i].group_id = group->group_id;
- group_array[i].attribute_id = group->attribute_id;
+ struct maat_hit_object *object = NULL;
+ for (i = 0; i < utarray_len(direct_hit_object) && i < array_size; i++) {
+ object = (struct maat_hit_object *)utarray_eltptr(direct_hit_object, i);
+ object_array[i].item_id = object->item_id;
+ object_array[i].object_id = object->object_id;
+ object_array[i].attribute_id = object->attribute_id;
}
- utarray_clear(rule_state->direct_hit_groups);
+ utarray_clear(rule_state->direct_hit_objects);
return i;
}
-size_t rule_state_get_direct_hit_group_cnt(struct rule_state *rule_state)
+size_t rule_state_get_direct_hit_object_cnt(struct rule_state *rule_state)
{
- return utarray_len(rule_state->direct_hit_groups);
+ return utarray_len(rule_state->direct_hit_objects);
}
size_t rule_state_get_internal_hit_paths(struct rule_state *rule_state,
struct rule_runtime *rule_rt,
- struct group2group_runtime *g2g_rt,
+ struct object2object_runtime *g2g_rt,
struct maat_hit_path *hit_path_array,
size_t array_size)
{
@@ -2681,37 +2681,37 @@ size_t rule_state_get_internal_hit_paths(struct rule_state *rule_state,
/*
NOTE: maybe one item has been deleted, but it's item_id still exist in internal_hit_paths
*/
- long long super_group_ids[MAX_HIT_GROUP_NUM];
- UT_array *valid_super_group_ids;
- utarray_new(valid_super_group_ids, &ut_rule_group_id_icd);
-
- size_t super_group_cnt =
- group2group_runtime_get_super_groups(g2g_rt, &(internal_path->group_id), 1,
- super_group_ids, MAX_HIT_GROUP_NUM);
- for (size_t idx = 0; idx < super_group_cnt; idx++) {
- utarray_push_back(valid_super_group_ids, &super_group_ids[idx]);
+ long long super_object_ids[MAX_HIT_OBJECT_NUM];
+ UT_array *valid_super_object_ids;
+ utarray_new(valid_super_object_ids, &ut_rule_object_id_icd);
+
+ size_t super_object_cnt =
+ object2object_runtime_get_super_objects(g2g_rt, &(internal_path->object_id), 1,
+ super_object_ids, MAX_HIT_OBJECT_NUM);
+ for (size_t idx = 0; idx < super_object_cnt; idx++) {
+ utarray_push_back(valid_super_object_ids, &super_object_ids[idx]);
}
/*
- internal_path->group_id can be referenced directly by rule,
- so add it to hit_path which super_group_ids is -1
+ internal_path->object_id can be referenced directly by rule,
+ so add it to hit_path which super_object_ids is -1
------------------------------------------------------------------------------
NOTE: Add the hit path as long as the item is hit
*/
- long long super_group_id = -1;
- utarray_push_back(valid_super_group_ids, &super_group_id);
+ long long super_object_id = -1;
+ utarray_push_back(valid_super_object_ids, &super_object_id);
long long *p = NULL;
struct maat_hit_path tmp_path;
- for (p = utarray_front(valid_super_group_ids);
+ for (p = utarray_front(valid_super_object_ids);
p != NULL && hit_path_cnt < array_size;
- p = utarray_next(valid_super_group_ids, p)) {
+ p = utarray_next(valid_super_object_ids, p)) {
memset(&tmp_path, 0, sizeof(tmp_path));
tmp_path.Nth_scan = internal_path->Nth_scan;
tmp_path.item_id = internal_path->item_id;
- tmp_path.sub_group_id = internal_path->group_id;
- tmp_path.top_group_id = *p;
+ tmp_path.sub_object_id = internal_path->object_id;
+ tmp_path.top_object_id = *p;
tmp_path.attribute_id = internal_path->attribute_id;
tmp_path.negate_option = internal_path->negate_option;
tmp_path.condition_index = -1;
@@ -2729,7 +2729,7 @@ size_t rule_state_get_internal_hit_paths(struct rule_state *rule_state,
hit_path_array[hit_path_cnt] = tmp_path;
hit_path_cnt++;
}
- utarray_free(valid_super_group_ids);
+ utarray_free(valid_super_object_ids);
}
return hit_path_cnt;
diff --git a/src/maat_stat.c b/src/maat_stat.c
index 7a30c44..13db5d9 100644
--- a/src/maat_stat.c
+++ b/src/maat_stat.c
@@ -17,7 +17,7 @@
#include "alignment.h"
#include "maat_ip.h"
#include "maat_rule.h"
-#include "maat_group.h"
+#include "maat_object.h"
#include "maat_plugin.h"
#include "maat_expr.h"
@@ -30,7 +30,7 @@ enum MAAT_FS_STATUS {
STATUS_PLUGIN_CACHE_NUM,
STATUS_PLUGIN_ACC_NUM,
STATUS_CONDITION_REF_NOT_NUM,
- STATUS_GROUP_REF_EXCL_NUM, //group reference exclude group num
+ STATUS_OBJECT_REF_EXCL_NUM, //object reference exclude object num
STATUS_HIT_RULE_NUM,
STATUS_MAAT_STATE_NUM,
STATUS_MAAT_PER_STATE_MEM,
@@ -78,7 +78,7 @@ static void fs_global_metric_register(struct maat_stat *stat)
stat->g_metric_id[STATUS_CONDITION_REF_NOT_NUM] =
fieldstat_easy_register_counter(stat->fs_handle, "NOT_condition_num");
- stat->g_metric_id[STATUS_GROUP_REF_EXCL_NUM] =
+ stat->g_metric_id[STATUS_OBJECT_REF_EXCL_NUM] =
fieldstat_easy_register_counter(stat->fs_handle, "excl_grp");
stat->g_metric_id[STATUS_GARBAGE_QUEUE_LEN] =
@@ -272,11 +272,11 @@ static void fs_table_row_refresh(struct maat_stat *stat, int perf_on)
plugin_cache_num += plugin_runtime_cached_row_count(runtime);
plugin_rule_num += plugin_runtime_rule_count(runtime);
break;
- case TABLE_TYPE_GROUP2RULE:
- g2c_not_condition_num += group2rule_runtime_not_condition_count(runtime);
+ case TABLE_TYPE_OBJECT2RULE:
+ g2c_not_condition_num += object2rule_runtime_not_condition_count(runtime);
break;
- case TABLE_TYPE_GROUP2GROUP:
- g2g_excl_rule_num += group2group_runtime_exclude_rule_count(runtime);
+ case TABLE_TYPE_OBJECT2OBJECT:
+ g2g_excl_rule_num += object2object_runtime_exclude_rule_count(runtime);
break;
case TABLE_TYPE_EXPR:
case TABLE_TYPE_EXPR_PLUS:
@@ -419,7 +419,7 @@ static void fs_table_row_refresh(struct maat_stat *stat, int perf_on)
NULL, 0, g2c_not_condition_num);
fieldstat_easy_counter_set(stat->fs_handle, 0,
- stat->g_metric_id[STATUS_GROUP_REF_EXCL_NUM],
+ stat->g_metric_id[STATUS_OBJECT_REF_EXCL_NUM],
NULL, 0, g2g_excl_rule_num);
}
diff --git a/src/maat_table.c b/src/maat_table.c
index 52b5686..7de74b0 100644
--- a/src/maat_table.c
+++ b/src/maat_table.c
@@ -19,7 +19,7 @@
#include "maat_expr.h"
#include "maat_ip.h"
#include "maat_rule.h"
-#include "maat_group.h"
+#include "maat_object.h"
#include "maat_flag.h"
#include "maat_plugin.h"
#include "maat_ip_plugin.h"
@@ -289,26 +289,26 @@ struct table_operations table_ops[TABLE_TYPE_MAX] = {
.update_err_count = rule_runtime_update_err_count
},
{
- .type = TABLE_TYPE_GROUP2GROUP,
- .new_schema = group2group_schema_new,
- .free_schema = group2group_schema_free,
- .new_runtime = group2group_runtime_new,
- .free_runtime = group2group_runtime_free,
- .update_runtime = group2group_runtime_update,
- .commit_runtime = group2group_runtime_commit,
- .rule_count = group2group_runtime_rule_count,
- .update_err_count = group2group_runtime_update_err_count
+ .type = TABLE_TYPE_OBJECT2OBJECT,
+ .new_schema = object2object_schema_new,
+ .free_schema = object2object_schema_free,
+ .new_runtime = object2object_runtime_new,
+ .free_runtime = object2object_runtime_free,
+ .update_runtime = object2object_runtime_update,
+ .commit_runtime = object2object_runtime_commit,
+ .rule_count = object2object_runtime_rule_count,
+ .update_err_count = object2object_runtime_update_err_count
},
{
- .type = TABLE_TYPE_GROUP2RULE,
- .new_schema = group2rule_schema_new,
- .free_schema = group2rule_schema_free,
- .new_runtime = group2rule_runtime_new,
- .free_runtime = group2rule_runtime_free,
- .update_runtime = group2rule_runtime_update,
+ .type = TABLE_TYPE_OBJECT2RULE,
+ .new_schema = object2rule_schema_new,
+ .free_schema = object2rule_schema_free,
+ .new_runtime = object2rule_runtime_new,
+ .free_runtime = object2rule_runtime_free,
+ .update_runtime = object2rule_runtime_update,
.commit_runtime = NULL,
- .rule_count = group2rule_runtime_rule_count,
- .update_err_count = group2rule_runtime_update_err_count
+ .rule_count = object2rule_runtime_rule_count,
+ .update_err_count = object2rule_runtime_update_err_count
}
};
@@ -500,8 +500,8 @@ static void maat_table_schema_free(void *schema, enum table_type table_type)
static void register_reserved_word(struct maat_kv_store *reserved_word_map)
{
maat_kv_register(reserved_word_map, "rule", TABLE_TYPE_RULE);
- maat_kv_register(reserved_word_map, "group2rule", TABLE_TYPE_GROUP2RULE);
- maat_kv_register(reserved_word_map, "group2group", TABLE_TYPE_GROUP2GROUP);
+ maat_kv_register(reserved_word_map, "object2rule", TABLE_TYPE_OBJECT2RULE);
+ maat_kv_register(reserved_word_map, "object2object", TABLE_TYPE_OBJECT2OBJECT);
maat_kv_register(reserved_word_map, "flag", TABLE_TYPE_FLAG);
maat_kv_register(reserved_word_map, "flag_plus", TABLE_TYPE_FLAG_PLUS);
maat_kv_register(reserved_word_map, "expr", TABLE_TYPE_EXPR);
@@ -905,7 +905,7 @@ table_manager_create(const char *table_info_path, const char *accept_tags,
}
}
- if (maat_tbl->table_type == TABLE_TYPE_GROUP2GROUP) {
+ if (maat_tbl->table_type == TABLE_TYPE_OBJECT2OBJECT) {
g2g_table_id = maat_tbl->table_id;
}
@@ -930,7 +930,7 @@ table_manager_create(const char *table_info_path, const char *accept_tags,
tbl_mgr->g2g_table_id = g2g_table_id;
log_info(logger, MODULE_TABLE, "default rule table id: %d", default_rule_table_id);
- log_info(logger, MODULE_TABLE, "group2group table id: %d", g2g_table_id);
+ log_info(logger, MODULE_TABLE, "object2object table id: %d", g2g_table_id);
next:
FREE(json_buff);
maat_kv_store_free(reserved_word_map);
@@ -990,18 +990,18 @@ int table_manager_runtime_create(struct table_manager *tbl_mgr, size_t max_threa
garbage_bin, tbl_mgr->logger);
}
- /* group2rule runtime depends on associated rule runtime,
+ /* object2rule runtime depends on associated rule runtime,
must make sure associated rule runtime already exist */
for (i = 0; i < MAX_TABLE_NUM; i++) {
table_type = table_manager_get_table_type(tbl_mgr, i);
- if (table_type != TABLE_TYPE_GROUP2RULE) {
+ if (table_type != TABLE_TYPE_OBJECT2RULE) {
continue;
}
void *schema = table_manager_get_schema(tbl_mgr, i);
if (NULL == schema) {
log_fatal(tbl_mgr->logger, MODULE_TABLE,
- "[%s:%d] group2rule table(table_id:%d) schema is null",
+ "[%s:%d] object2rule table(table_id:%d) schema is null",
__FUNCTION__, __LINE__, i);
continue;
}
@@ -1011,9 +1011,9 @@ int table_manager_runtime_create(struct table_manager *tbl_mgr, size_t max_threa
continue;
}
- int asso_rule_table_id = group2rule_associated_rule_table_id(schema);
+ int asso_rule_table_id = object2rule_associated_rule_table_id(schema);
void *rule_updating_rt = table_manager_get_updating_runtime(tbl_mgr, asso_rule_table_id);
- group2rule_runtime_init(g2c_updating_rt, rule_updating_rt);
+ object2rule_runtime_init(g2c_updating_rt, rule_updating_rt);
}
return 0;
@@ -1163,7 +1163,7 @@ int table_manager_get_default_rule_table_id(struct table_manager *tbl_mgr)
return tbl_mgr->default_rule_table_id;
}
-int table_manager_get_group2group_table_id(struct table_manager *tbl_mgr)
+int table_manager_get_object2object_table_id(struct table_manager *tbl_mgr)
{
if (NULL == tbl_mgr) {
return -1;
diff --git a/src/maat_utils.c b/src/maat_utils.c
index e3aca86..feaa351 100644
--- a/src/maat_utils.c
+++ b/src/maat_utils.c
@@ -603,8 +603,8 @@ int ids_str2longlong_array(const char *ids_str, UT_array *ids_array)
subtoken = strtok_r(str, seps, &saveptr);
if (subtoken == NULL)
break;
- long long group_id = atoll(subtoken);
- utarray_push_back(ids_array, &group_id);
+ long long object_id = atoll(subtoken);
+ utarray_push_back(ids_array, &object_id);
counter++;
}