refactor ex_data_runtime & fix all leak memory

This commit is contained in:
liuwentan
2023-04-05 21:09:19 +08:00
parent 5d545d6dbf
commit fb3896c078
26 changed files with 438 additions and 693 deletions

View File

@@ -18,6 +18,7 @@ extern "C"
#include "maat.h"
#include "maat_table.h"
#include "maat_ex_data.h"
#include "cJSON/cJSON.h"
struct bool_plugin_runtime;
@@ -27,15 +28,13 @@ void *bool_plugin_schema_new(cJSON *json, struct table_manager *tbl_mgr,
const char *table_name, struct log_handle *logger);
void bool_plugin_schema_free(void *bool_plugin_schema);
/* ip plugin table ex data API */
struct ex_data_schema *bool_plugin_table_get_ex_data_schema(void *bool_plugin_schema);
int bool_plugin_table_set_ex_data_schema(void *bool_plugin_schema,
maat_ex_new_func_t *new_func,
maat_ex_free_func_t *free_func,
maat_ex_dup_func_t *dup_func,
long argl, void *argp,
struct log_handle *logger);
int bool_plugin_table_set_ex_container_schema(void *bool_plugin_schema, int table_id,
maat_ex_new_func_t *new_func,
maat_ex_free_func_t *free_func,
maat_ex_dup_func_t *dup_func,
void (*custom_data_free)(void *),
long argl, void *argp);
struct ex_container_schema *bool_plugin_table_get_ex_container_schema(void *bool_plugin_schema);
/* ip plugin runtime API */
void *bool_plugin_runtime_new(void *bool_plugin_schema, int max_thread_num,
@@ -49,9 +48,8 @@ int bool_plugin_runtime_commit(void *bool_plugin_runtime, const char *table_name
struct ex_data_runtime *bool_plugin_runtime_get_ex_data_rt(void *bool_plugin_runtime);
int bool_plugin_runtime_get_ex_data(void *bool_plugin_runtime, void *bool_plugin_schema,
unsigned long long *item_ids, size_t n_item,
void **ex_data_array, size_t n_ex_data);
int bool_plugin_runtime_get_ex_data(void *bool_plugin_runtime, unsigned long long *item_ids,
size_t n_item, void **ex_data_array, size_t n_ex_data);
#ifdef __cplusplus
}

View File

@@ -41,8 +41,7 @@ int compile_table_set_ex_data_schema(struct compile_schema *compile_schema, int
maat_ex_new_func_t *new_func,
maat_ex_free_func_t *free_func,
maat_ex_dup_func_t *dup_func,
long argl, void *argp,
struct log_handle *logger);
long argl, void *argp);
/* compile runtime API */
void *compile_runtime_new(void *compile_schema, int max_thread_num,

View File

@@ -20,11 +20,6 @@ extern "C"
#include "rcu_hash.h"
#include "maat_garbage_collection.h"
struct ex_container {
void *ex_data;
void *custom_data;
};
struct ex_data_schema {
maat_ex_new_func_t *new_func;
maat_ex_free_func_t *free_func;
@@ -33,18 +28,22 @@ struct ex_data_schema {
void *argp;
};
struct ex_container {
void *ex_data;
void *custom_data;
};
struct ex_container_schema {
int table_id;
struct ex_data_schema *ex_schema;
void (*user_data_free)(void *);
int set_flag;
struct ex_data_schema ex_schema;
void (*custom_data_free)(void *);
};
struct ex_data_runtime;
/* ex_data_runtime API */
struct ex_data_runtime *
ex_data_runtime_new(int table_id, rcu_hash_data_free_fn *data_free_fn,
struct log_handle *logger);
struct ex_data_runtime *ex_data_runtime_new(int table_id, struct log_handle *logger);
void ex_data_runtime_free(struct ex_data_runtime *ex_data_rt);
void ex_data_runtime_commit(struct ex_data_runtime *ex_data_rt);
@@ -57,26 +56,14 @@ size_t ex_data_runtime_cached_row_count(struct ex_data_runtime *ex_data_rt);
void ex_data_runtime_clear_row_cache(struct ex_data_runtime *ex_data_rt);
/* set schema API */
struct ex_data_schema *ex_data_schema_new(maat_ex_new_func_t *new_func,
maat_ex_free_func_t *free_func,
maat_ex_dup_func_t *dup_func,
long argl, void *argp);
void ex_data_schema_free(struct ex_data_schema *ex_schema);
/* set user_ctx API */
void ex_data_runtime_set_ex_container_schema(struct ex_data_runtime *ex_data_rt,
struct ex_container_schema *container_schema);
struct ex_container_schema *
ex_data_runtime_get_ex_container_schema(struct ex_data_runtime *ex_data_rt);
struct ex_container_schema *container_schema);
struct ex_container *ex_container_new(void *ex_data, void *custom_data);
void ex_container_free(void *ctx, void *data);
/* ex_data_runtime ex data API */
void *ex_data_runtime_row2ex_data(struct ex_data_runtime *ex_data_rt,
struct ex_data_schema *ex_schema,
const char *table_name, const char *row,
const char *key, size_t key_len);
@@ -95,11 +82,9 @@ size_t ex_data_runtime_ex_container_count(struct ex_data_runtime *ex_data_rt);
int ex_data_runtime_is_updating(struct ex_data_runtime *ex_data_rt);
void *ex_data_runtime_get_ex_data_by_key(struct ex_data_runtime *ex_data_rt,
struct ex_data_schema *ex_schema,
const char *key, size_t key_len);
void *ex_data_runtime_get_ex_data_by_container(struct ex_data_runtime *ex_data_rt,
struct ex_data_schema *ex_schema,
struct ex_container *ex_container);
void *ex_data_runtime_get_custom_data(struct ex_data_runtime *ex_data_rt,

View File

@@ -18,7 +18,9 @@ extern "C"
#include "maat.h"
#include "maat_table.h"
#include "maat_ex_data.h"
#include "cJSON/cJSON.h"
#include "fqdn_engine.h"
struct fqdn_plugin_runtime;
@@ -28,14 +30,13 @@ void *fqdn_plugin_schema_new(cJSON *json, struct table_manager *tbl_mgr,
void fqdn_plugin_schema_free(void *fqdn_plugin_schema);
/* fqdn plugin table ex data API */
struct ex_data_schema *fqdn_plugin_table_get_ex_data_schema(void *fqdn_plugin_schema);
int fqdn_plugin_table_set_ex_data_schema(void *fqdn_plugin_schema,
maat_ex_new_func_t *new_func,
maat_ex_free_func_t *free_func,
maat_ex_dup_func_t *dup_func,
long argl, void *argp,
struct log_handle *logger);
int fqdn_plugin_table_set_ex_container_schema(void *fqdn_plugin_schema, int table_id,
maat_ex_new_func_t *new_func,
maat_ex_free_func_t *free_func,
maat_ex_dup_func_t *dup_func,
void (*custom_data_free)(void *),
long argl, void *argp);
struct ex_container_schema *fqdn_plugin_table_get_ex_container_schema(void *fqdn_plugin_schema);
/* fqdn plugin runtime API */
void *fqdn_plugin_runtime_new(void *fqdn_plugin_schema, int max_thread_num,
@@ -49,8 +50,11 @@ int fqdn_plugin_runtime_commit(void *fqdn_plugin_runtime, const char *table_name
struct ex_data_runtime *fqdn_plugin_runtime_get_ex_data_rt(void *fqdn_plugin_runtime);
int fqdn_plugin_runtime_get_ex_data(void *fqdn_plugin_runtime, void *fqdn_plugin_schema,
const char *fqdn, void **ex_data_array, size_t n_ex_data);
int fqdn_plugin_runtime_get_ex_data(void *fqdn_plugin_runtime, const char *fqdn,
void **ex_data_array, size_t n_ex_data);
void fqdn_rule_free(struct FQDN_rule *fqdn_rule);
#ifdef __cplusplus
}
#endif

View File

@@ -19,6 +19,7 @@ extern "C"
#include "maat.h"
#include "cJSON/cJSON.h"
#include "maat_table.h"
#include "maat_ex_data.h"
struct ip_plugin_runtime;
@@ -28,14 +29,13 @@ void *ip_plugin_schema_new(cJSON *json, struct table_manager *tbl_mgr,
void ip_plugin_schema_free(void *ip_plugin_schema);
/* ip plugin table ex data API */
struct ex_data_schema *ip_plugin_table_get_ex_data_schema(void *ip_plugin_schema);
void ip_plugin_table_set_ex_data_schema(void *ip_plugin_schema,
maat_ex_new_func_t *new_func,
maat_ex_free_func_t *free_func,
maat_ex_dup_func_t *dup_func,
long argl, void *argp,
struct log_handle *logger);
int ip_plugin_table_set_ex_container_schema(void *ip_plugin_schema, int table_id,
maat_ex_new_func_t *new_func,
maat_ex_free_func_t *free_func,
maat_ex_dup_func_t *dup_func,
void (*custom_data_free)(void *),
long argl, void *argp);
struct ex_container_schema *ip_plugin_table_get_ex_container_schema(void *ip_plugin_schema);
/* ip plugin runtime API */
void *ip_plugin_runtime_new(void *ip_plugin_schema, int max_thread_num,
@@ -49,9 +49,8 @@ int ip_plugin_runtime_commit(void *ip_plugin_runtime, const char *table_name);
struct ex_data_runtime *ip_plugin_runtime_get_ex_data_rt(void *ip_plugin_runtime);
int ip_plugin_runtime_get_ex_data(void *ip_plugin_runtime, void *ip_plugin_schema,
const struct ip_addr *ip_addr, void **ex_data_array,
size_t n_ex_data_array);
int ip_plugin_runtime_get_ex_data(void *ip_plugin_runtime, const struct ip_addr *ip_addr,
void **ex_data_array, size_t n_ex_data_array);
#ifdef __cplusplus
}

View File

@@ -18,6 +18,7 @@ extern "C"
#include "cJSON/cJSON.h"
#include "maat.h"
#include "maat_ex_data.h"
#define MAX_FOREIGN_CLMN_NUM 8
@@ -40,13 +41,13 @@ void plugin_table_all_callback_finish(struct plugin_schema *plugin_schema);
int plugin_table_get_foreign_column(struct plugin_schema *plugin_schema, int *foreign_columns);
/* plugin table ex data API */
void plugin_table_set_ex_data_schema(void *plugin_schema,
maat_ex_new_func_t *new_func,
maat_ex_free_func_t *free_func,
maat_ex_dup_func_t *dup_func,
long argl, void *argp,
struct log_handle *logger);
struct ex_data_schema *plugin_table_get_ex_data_schema(void *custom_schema);
int plugin_table_set_ex_container_schema(void *plugin_schema, int table_id,
maat_ex_new_func_t *new_func,
maat_ex_free_func_t *free_func,
maat_ex_dup_func_t *dup_func,
void (*custom_data_free)(void *),
long argl, void *argp);
struct ex_container_schema *plugin_table_get_ex_container_schema(void *plugin_schema);
/* plugin runtime API */
void *plugin_runtime_new(void *plugin_schema, int max_thread_num,

View File

@@ -18,19 +18,15 @@ extern "C"
#include "uthash/uthash.h"
typedef void rcu_hash_data_free_fn(void *user_ctx, void *data);
typedef void data_free_fn(void *user_ctx, void *data);
/* rcu hash table */
struct rcu_hash_table;
struct rcu_hash_table *rcu_hash_new(rcu_hash_data_free_fn *free_fn);
struct rcu_hash_table *rcu_hash_new(data_free_fn *free_fn, void *arg);
void rcu_hash_free(struct rcu_hash_table *htable);
void rcu_hash_set_user_ctx(struct rcu_hash_table *htable, void *user_ctx);
void *rcu_hash_get_user_ctx(struct rcu_hash_table *htable);
/**
* @brief Adding the updating nodes which will become effective nodes after call rcu_hash_commit
*