增加dup_func。

This commit is contained in:
zhengchao
2018-11-07 21:04:22 +08:00
parent 4097887e4c
commit cb26379ad4
3 changed files with 17 additions and 5 deletions

View File

@@ -243,13 +243,18 @@ void Maat_clean_status(scan_status_t* mid);
typedef void* MAAT_RULE_EX_DATA; typedef void* MAAT_RULE_EX_DATA;
// The idx parameter is the index: this will be the same value returned by Maat_rule_get_ex_new_index() when the functions were initially registered. // The idx parameter is the index: this will be the same value returned by Maat_rule_get_ex_new_index() when the functions were initially registered.
// Finally the argl and argp parameters are the values originally passed to the same corresponding parameters when Maat_rule_get_ex_new_index() was called. // Finally the argl and argp parameters are the values originally passed to the same corresponding parameters when Maat_rule_get_ex_new_index() was called.
typedef void Maat_rule_EX_new_func_t(int idx, const struct Maat_rule_t* rule, const char* srv_def_large, MAAT_RULE_EX_DATA* ad, long argl, void *argp); typedef void Maat_rule_EX_new_func_t(int idx, const struct Maat_rule_t* rule, const char* srv_def_large,
typedef void Maat_rule_EX_free_func_t(int idx, const struct Maat_rule_t* rule, const char* srv_def_large, MAAT_RULE_EX_DATA* ad, long argl, void *argp); MAAT_RULE_EX_DATA* ad, long argl, void *argp);
typedef void Maat_rule_EX_free_func_t(int idx, const struct Maat_rule_t* rule, const char* srv_def_large,
MAAT_RULE_EX_DATA* ad, long argl, void *argp);
typedef void Maat_rule_EX_dup_func_t(int idx, MAAT_RULE_EX_DATA *to, MAAT_RULE_EX_DATA *from, long argl, void *argp);
int Maat_rule_get_ex_new_index(Maat_feather_t feather, const char* compile_table_name, int Maat_rule_get_ex_new_index(Maat_feather_t feather, const char* compile_table_name,
Maat_rule_EX_new_func_t* new_func, Maat_rule_EX_new_func_t* new_func,
Maat_rule_EX_free_func_t* free_func, Maat_rule_EX_free_func_t* free_func,
Maat_rule_EX_dup_func_t* dup_func,
long argl, void *argp); long argl, void *argp);
//returned data is duplicated by dup_func of Maat_rule_get_ex_new_index, caller is responsible to free the data.
MAAT_RULE_EX_DATA Maat_rule_get_ex_data(Maat_feather_t feather, const struct Maat_rule_t* rule, int idx); MAAT_RULE_EX_DATA Maat_rule_get_ex_data(Maat_feather_t feather, const struct Maat_rule_t* rule, int idx);

View File

@@ -980,6 +980,7 @@ void rule_ex_data_new_cb(const uchar * key, uint size, void * data, void * user)
int Maat_rule_get_ex_new_index(Maat_feather_t feather, const char* compile_table_name, int Maat_rule_get_ex_new_index(Maat_feather_t feather, const char* compile_table_name,
Maat_rule_EX_new_func_t *new_func, Maat_rule_EX_new_func_t *new_func,
Maat_rule_EX_free_func_t* free_func, Maat_rule_EX_free_func_t* free_func,
Maat_rule_EX_dup_func_t* dup_func,
long argl, void *argp) long argl, void *argp)
{ {
struct _Maat_feather_t *_feather=(struct _Maat_feather_t *)feather; struct _Maat_feather_t *_feather=(struct _Maat_feather_t *)feather;
@@ -1008,6 +1009,8 @@ int Maat_rule_get_ex_new_index(Maat_feather_t feather, const char* compile_table
p_table->ex_desc[idx].argp=argp; p_table->ex_desc[idx].argp=argp;
p_table->ex_desc[idx].new_func=new_func; p_table->ex_desc[idx].new_func=new_func;
p_table->ex_desc[idx].free_func=free_func; p_table->ex_desc[idx].free_func=free_func;
p_table->ex_desc[idx].dup_func=dup_func;
p_table->ex_data_num++; p_table->ex_data_num++;
MESA_htable_iterate(_feather->scanner->compile_hash, rule_ex_data_new_cb, p_table->ex_desc+idx); MESA_htable_iterate(_feather->scanner->compile_hash, rule_ex_data_new_cb, p_table->ex_desc+idx);
failed: failed:
@@ -1019,7 +1022,9 @@ MAAT_RULE_EX_DATA Maat_rule_get_ex_data(Maat_feather_t feather, const struct Maa
{ {
struct _Maat_feather_t *_feather=(struct _Maat_feather_t *)feather; struct _Maat_feather_t *_feather=(struct _Maat_feather_t *)feather;
struct _Maat_compile_inner_t *compile_inner=NULL; struct _Maat_compile_inner_t *compile_inner=NULL;
const struct compile_ex_data_idx* ex_desc=NULL;
MAAT_RULE_EX_DATA ad=NULL; MAAT_RULE_EX_DATA ad=NULL;
compile_inner=(struct _Maat_compile_inner_t *)HASH_fetch_by_id(_feather->scanner->compile_hash, rule->config_id); compile_inner=(struct _Maat_compile_inner_t *)HASH_fetch_by_id(_feather->scanner->compile_hash, rule->config_id);
if(compile_inner==NULL) if(compile_inner==NULL)
{ {
@@ -1027,7 +1032,8 @@ MAAT_RULE_EX_DATA Maat_rule_get_ex_data(Maat_feather_t feather, const struct Maa
} }
pthread_rwlock_rdlock(&(compile_inner->rwlock)); pthread_rwlock_rdlock(&(compile_inner->rwlock));
assert(idx<compile_inner->ref_table->ex_data_num); assert(idx<compile_inner->ref_table->ex_data_num);
ad=compile_inner->ads[idx]; ex_desc=compile_inner->ref_table->ex_desc+idx;
ex_desc->dup_func(ex_desc->idx, &ad, compile_inner->ads+idx, ex_desc->argl,ex_desc->argp);
pthread_rwlock_unlock(&(compile_inner->rwlock)); pthread_rwlock_unlock(&(compile_inner->rwlock));
return ad; return ad;
} }

View File

@@ -94,6 +94,7 @@ struct compile_ex_data_idx
{ {
Maat_rule_EX_new_func_t *new_func; Maat_rule_EX_new_func_t *new_func;
Maat_rule_EX_free_func_t* free_func; Maat_rule_EX_free_func_t* free_func;
Maat_rule_EX_dup_func_t* dup_func;
long argl; long argl;
void *argp; void *argp;
int idx; int idx;