summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryangwei <[email protected]>2024-07-24 11:46:32 +0800
committeryangwei <[email protected]>2024-07-24 11:58:24 +0800
commit55d4639c91c6f2b1b3f89353099a7cb6f47ee46f (patch)
treead901840587dfae42b01d25db545ea220647ac25
parent9c07f0d619ebe4d6f436e2b6af6238742d96f69a (diff)
🦄 refactor(stellar exdata header): integration stellar_exdata.h
-rw-r--r--examples/stellar_plugin/simple_stellar_plugin.c8
-rw-r--r--include/stellar/stellar_exdata.h7
-rw-r--r--src/plugin_manager/plugin_manager.c86
-rw-r--r--src/plugin_manager/plugin_manager_interna.h10
-rw-r--r--test/plugin_manager/plugin_manager_gtest_main.cpp94
5 files changed, 98 insertions, 107 deletions
diff --git a/examples/stellar_plugin/simple_stellar_plugin.c b/examples/stellar_plugin/simple_stellar_plugin.c
index 6de75df..a9cc0ee 100644
--- a/examples/stellar_plugin/simple_stellar_plugin.c
+++ b/examples/stellar_plugin/simple_stellar_plugin.c
@@ -173,7 +173,7 @@ int simple_plugin_on_polling(void *plugin_env)
return 0;
}
-static void simple_plugin_packet_exdata_free(struct packet *pkt, int idx, void *ex_ptr, void *arg)
+static void simple_plugin_packet_exdata_free(int idx, void *ex_ptr, void *arg)
{
struct simple_stellar_plugin_env *env = (struct simple_stellar_plugin_env *)arg;
assert(env);
@@ -201,7 +201,7 @@ void *simple_session_packet_plugin_init(struct stellar *st)
{
struct simple_stellar_plugin_env *env = CALLOC(struct simple_stellar_plugin_env, 1);
env->st = st;
- env->session_exdata_idx = stellar_session_exdata_new_index(st, "EXDATA_SESSION_STAT", NULL, NULL);
+ env->session_exdata_idx = stellar_exdata_new_index(st, "EXDATA_SESSION_STAT", NULL, NULL);
env->session_plugin_id = stellar_session_plugin_register(st,
simple_plugin_session_ctx_new,
simple_plugin_session_ctx_free,
@@ -239,7 +239,7 @@ void *simple_session_packet_plugin_init(struct stellar *st)
stellar_packet_mq_subscribe(st, env->packet_topic_id, simple_plugin_on_packet_msg_cb, icmp_plugin_id);
stellar_packet_mq_subscribe(st, env->packet_topic_id, simple_plugin_on_packet_msg_cb, icmp6_plugin_id);
- env->packet_exdata_idx=stellar_packet_exdata_new_index(st, "EXDATA_PACKET_ENV", simple_plugin_packet_exdata_free, env);
+ env->packet_exdata_idx=stellar_exdata_new_index(st, "EXDATA_PACKET_ENV", simple_plugin_packet_exdata_free, env);
int polling_plugin_id=stellar_polling_plugin_register(st, simple_plugin_on_polling, env);
if(polling_plugin_id < 0)
@@ -312,7 +312,7 @@ void *simple_plugin_sub_session_stat_init(struct stellar *st)
{
struct simple_stellar_plugin_env *env = CALLOC(struct simple_stellar_plugin_env, 1);
env->st = st;
- env->session_exdata_idx = stellar_session_exdata_new_index(st, "EXDATA_SESSION_STAT", NULL, NULL);
+ env->session_exdata_idx = stellar_exdata_new_index(st, "EXDATA_SESSION_STAT", NULL, NULL);
int topic_id=stellar_mq_get_topic_id(st, "TOPIC_SESSION_STAT");
if(topic_id < 0)
{
diff --git a/include/stellar/stellar_exdata.h b/include/stellar/stellar_exdata.h
index c8baa06..ffb0e8c 100644
--- a/include/stellar/stellar_exdata.h
+++ b/include/stellar/stellar_exdata.h
@@ -2,14 +2,13 @@
#include "stellar.h"
+typedef void stellar_exdata_free(int idx, void *ex_ptr, void *arg);
+int stellar_exdata_new_index(struct stellar *st, const char *name, stellar_exdata_free *free_func,void *arg);
+
//packet exdata api
-typedef void packet_exdata_free(struct packet *pkt, int idx, void *ex_ptr, void *arg);
-int stellar_packet_exdata_new_index(struct stellar *st, const char *name, packet_exdata_free *free_func,void *arg);
int packet_exdata_set(struct packet *pkt, int idx, void *ex_ptr);
void *packet_exdata_get(struct packet *pkt, int idx);
//session exdata api
-typedef void session_exdata_free(struct session *sess, int idx, void *ex_ptr, void *arg);
-int stellar_session_exdata_new_index(struct stellar *st, const char *name, session_exdata_free *free_func,void *arg);
int session_exdata_set(struct session *sess, int idx, void *ex_ptr);
void *session_exdata_get(struct session *sess, int idx); \ No newline at end of file
diff --git a/src/plugin_manager/plugin_manager.c b/src/plugin_manager/plugin_manager.c
index 640f817..239b13a 100644
--- a/src/plugin_manager/plugin_manager.c
+++ b/src/plugin_manager/plugin_manager.c
@@ -147,8 +147,7 @@ void plugin_manager_exit(struct plugin_manager_schema *plug_mgr)
}
utarray_free(plug_mgr->stellar_mq_schema_array);
}
- if(plug_mgr->packet_exdata_schema_array)utarray_free(plug_mgr->packet_exdata_schema_array);
- if(plug_mgr->session_exdata_schema_array)utarray_free(plug_mgr->session_exdata_schema_array);
+ if(plug_mgr->stellar_exdata_schema_array)utarray_free(plug_mgr->stellar_exdata_schema_array);
if(plug_mgr->registered_polling_plugin_array)utarray_free(plug_mgr->registered_polling_plugin_array);
if(plug_mgr->registered_packet_plugin_array)
{
@@ -180,7 +179,7 @@ void plugin_manager_exit(struct plugin_manager_schema *plug_mgr)
static void stellar_exdata_met_copy(void *_dst, const void *_src)
{
struct stellar_exdata_schema *dst = (struct stellar_exdata_schema *)_dst, *src = (struct stellar_exdata_schema *)_src;
- dst->sess_free_func = src->sess_free_func;
+ dst->free_func = src->free_func;
dst->free_arg = src->free_arg;
dst->idx = src->idx;
dst->name = src->name ? strdup(src->name) : NULL;
@@ -195,19 +194,20 @@ static void stellar_exdata_met_dtor(void *_elt)
UT_icd stellar_exdata_meta_icd = {sizeof(struct stellar_exdata_schema), NULL, stellar_exdata_met_copy, stellar_exdata_met_dtor};
-int stellar_exdata_new_index(struct stellar *st, const char *name, UT_array **exdata_schema, void *free_func,void *free_arg)
+int stellar_exdata_new_index(struct stellar *st, const char *name, stellar_exdata_free *free_func,void *free_arg)
{
- if(st==NULL || name==NULL || exdata_schema==NULL)return -1;
- if(*exdata_schema == NULL)
+ if(st==NULL || name==NULL)return -1;
+ struct plugin_manager_schema *plug_mgr = stellar_plugin_manager_schema_get(st);
+ if(plug_mgr->stellar_exdata_schema_array == NULL)
{
- utarray_new(*exdata_schema, &stellar_exdata_meta_icd);
+ utarray_new(plug_mgr->stellar_exdata_schema_array, &stellar_exdata_meta_icd);
}
- if(*exdata_schema == NULL)return -1;
- unsigned int len = utarray_len(*exdata_schema);
+ if(plug_mgr->stellar_exdata_schema_array == NULL)return -1;
+ unsigned int len = utarray_len(plug_mgr->stellar_exdata_schema_array);
struct stellar_exdata_schema *t_schema;
for(unsigned int i = 0; i < len; i++)
{
- t_schema = (struct stellar_exdata_schema *)utarray_eltptr(*exdata_schema, i);
+ t_schema = (struct stellar_exdata_schema *)utarray_eltptr(plug_mgr->stellar_exdata_schema_array, i);
if(strcmp(t_schema->name, name) == 0)
{
t_schema->free_func=free_func;
@@ -221,7 +221,7 @@ int stellar_exdata_new_index(struct stellar *st, const char *name, UT_array **ex
new_schema.name=(char *)name;
new_schema.idx=len;
new_schema.free_arg=free_arg;
- utarray_push_back(*exdata_schema, &new_schema);
+ utarray_push_back(plug_mgr->stellar_exdata_schema_array, &new_schema);
return new_schema.idx;
}
@@ -249,11 +249,11 @@ void *stellar_exdata_get(UT_array *exdata_schema, struct stellar_exdata *exdata_
*******************************/
static struct stellar_exdata *per_thread_packet_exdata_arrary_get(struct plugin_manager_schema *plug_mgr)
{
- if(plug_mgr==NULL || plug_mgr->packet_exdata_schema_array == NULL)return NULL;
+ if(plug_mgr==NULL || plug_mgr->stellar_exdata_schema_array == NULL)return NULL;
int tid=stellar_get_current_thread_id(plug_mgr->st);
if(plug_mgr->per_thread_data[tid].per_thread_pkt_exdata_array.exdata_array == NULL)
{
- unsigned int len = utarray_len(plug_mgr->packet_exdata_schema_array);
+ unsigned int len = utarray_len(plug_mgr->stellar_exdata_schema_array);
plug_mgr->per_thread_data[tid].per_thread_pkt_exdata_array.exdata_array = CALLOC(struct stellar_exdata, len);
}
return plug_mgr->per_thread_data[tid].per_thread_pkt_exdata_array.exdata_array;
@@ -261,20 +261,20 @@ static struct stellar_exdata *per_thread_packet_exdata_arrary_get(struct plugin_
static void per_thread_packet_exdata_arrary_clean(struct plugin_manager_schema *plug_mgr, struct packet *pkt)
{
- if(plug_mgr==NULL || plug_mgr->packet_exdata_schema_array == NULL)return;
- unsigned int len=utarray_len(plug_mgr->packet_exdata_schema_array);
+ if(plug_mgr==NULL || plug_mgr->stellar_exdata_schema_array == NULL)return;
+ unsigned int len=utarray_len(plug_mgr->stellar_exdata_schema_array);
struct stellar_exdata *per_thread_pkt_exdata_arrary = per_thread_packet_exdata_arrary_get(plug_mgr);
if(per_thread_pkt_exdata_arrary == NULL)return;
for (unsigned int i = 0; i < len; i++)
{
void *exdata = (per_thread_pkt_exdata_arrary + i)->exdata;
(per_thread_pkt_exdata_arrary + i)->state=EXIT;
- struct stellar_exdata_schema *schema = (struct stellar_exdata_schema *)utarray_eltptr(plug_mgr->packet_exdata_schema_array, i);
+ struct stellar_exdata_schema *schema = (struct stellar_exdata_schema *)utarray_eltptr(plug_mgr->stellar_exdata_schema_array, i);
if (exdata)
{
- if (schema->pkt_free_func)
+ if (schema->free_func)
{
- schema->pkt_free_func(pkt, i, exdata, schema->free_arg);
+ schema->free_func(i, exdata, schema->free_arg);
}
(per_thread_pkt_exdata_arrary + i)->exdata=NULL;
}
@@ -282,51 +282,38 @@ static void per_thread_packet_exdata_arrary_clean(struct plugin_manager_schema *
}
}
-int stellar_packet_exdata_new_index(struct stellar *st, const char *name, packet_exdata_free *free_func,void *free_arg)
-{
- struct plugin_manager_schema *plug_mgr = stellar_plugin_manager_schema_get(st);
- assert(plug_mgr);
- return stellar_exdata_new_index(st, name, &plug_mgr->packet_exdata_schema_array, (void*)free_func, free_arg);
-}
-
int packet_exdata_set(struct packet *pkt, int idx, void *ex_ptr)
{
if(pkt == NULL)return -1;
struct plugin_manager_schema *plug_mgr = stellar_plugin_manager_schema_get(packet_stellar_get(pkt));
- return stellar_exdata_set(plug_mgr->packet_exdata_schema_array, per_thread_packet_exdata_arrary_get(plug_mgr), idx, ex_ptr);
+ return stellar_exdata_set(plug_mgr->stellar_exdata_schema_array, per_thread_packet_exdata_arrary_get(plug_mgr), idx, ex_ptr);
}
void *packet_exdata_get(struct packet *pkt, int idx)
{
if(pkt == NULL)return NULL;
struct plugin_manager_schema *plug_mgr = stellar_plugin_manager_schema_get(packet_stellar_get(pkt));
- return stellar_exdata_get( plug_mgr->packet_exdata_schema_array, per_thread_packet_exdata_arrary_get(plug_mgr), idx);
+ return stellar_exdata_get( plug_mgr->stellar_exdata_schema_array, per_thread_packet_exdata_arrary_get(plug_mgr), idx);
}
/*******************************
* SESSION EXDATA *
*******************************/
-int stellar_session_exdata_new_index(struct stellar *st, const char *name, session_exdata_free *free_func,void *free_arg)
-{
- struct plugin_manager_schema *plug_mgr = stellar_plugin_manager_schema_get(st);
- assert(plug_mgr);
- return stellar_exdata_new_index(st, name, &plug_mgr->session_exdata_schema_array, (void*)free_func, free_arg);
-}
int session_exdata_set(struct session *sess, int idx, void *ex_ptr)
{
struct plugin_manager_runtime *plug_mgr_rt = session_plugin_manager_runtime_get(sess);
if(plug_mgr_rt == NULL)return -1;
- if(plug_mgr_rt->plug_mgr->session_exdata_schema_array == NULL)return -1;
- return stellar_exdata_set(plug_mgr_rt->plug_mgr->session_exdata_schema_array, plug_mgr_rt->sess_exdata_array, idx, ex_ptr);
+ if(plug_mgr_rt->plug_mgr->stellar_exdata_schema_array == NULL)return -1;
+ return stellar_exdata_set(plug_mgr_rt->plug_mgr->stellar_exdata_schema_array, plug_mgr_rt->sess_exdata_array, idx, ex_ptr);
}
void *session_exdata_get(struct session *sess, int idx)
{
struct plugin_manager_runtime *plug_mgr_rt = session_plugin_manager_runtime_get(sess);
if(plug_mgr_rt == NULL)return NULL;
- if(plug_mgr_rt->plug_mgr->session_exdata_schema_array==NULL)return NULL;
- return stellar_exdata_get(plug_mgr_rt->plug_mgr->session_exdata_schema_array, plug_mgr_rt->sess_exdata_array, idx);
+ if(plug_mgr_rt->plug_mgr->stellar_exdata_schema_array==NULL)return NULL;
+ return stellar_exdata_get(plug_mgr_rt->plug_mgr->stellar_exdata_schema_array, plug_mgr_rt->sess_exdata_array, idx);
}
/*******************************
@@ -647,19 +634,24 @@ int stellar_packet_mq_subscribe(struct stellar *st, int topic_id, on_packet_msg_
return stellar_mq_subscribe(plug_mgr,topic_id, (void *)plugin_on_msg_cb, plugin_idx, packet_plugin_schema->registed_packet_mq_subscriber_info);
}
-int packet_mq_publish_message(struct packet *pkt, int topic_id, void *data)
+int packet_mq_publish_message_with_priority(struct packet *pkt, int topic_id, void *data, enum stellar_mq_priority priority)
{
struct stellar *st = packet_stellar_get(pkt);
struct plugin_manager_schema *plug_mgr = stellar_plugin_manager_schema_get(st);
int tid = stellar_get_current_thread_id(plug_mgr->st);
if(plug_mgr->per_thread_data[tid].pub_packet_msg_cnt == -1)return -1;
if(plug_mgr->per_thread_data[tid].pub_packet_msg_cnt >= plug_mgr->max_message_dispatch)return -1;
- if(stellar_mq_publish_message(ON_PACKET_TOPIC ,topic_id, data, plug_mgr->stellar_mq_schema_array, plug_mgr->per_thread_data[tid].priority_mq,STELLAR_MQ_PRIORITY_HIGH)==0)
+ if(stellar_mq_publish_message(ON_PACKET_TOPIC ,topic_id, data, plug_mgr->stellar_mq_schema_array, plug_mgr->per_thread_data[tid].priority_mq,priority)==0)
{
plug_mgr->per_thread_data[tid].pub_packet_msg_cnt+=1;
return 0;
}
- return -1;
+ return -1;
+}
+
+int packet_mq_publish_message(struct packet *pkt, int topic_id, void *data)
+{
+ return packet_mq_publish_message_with_priority(pkt, topic_id, data, STELLAR_MQ_PRIORITY_NORMAL);
}
/*******************************
@@ -779,8 +771,8 @@ int session_mq_topic_is_active(struct session *sess, int topic_id)
static struct stellar_exdata *session_exdata_runtime_new(struct plugin_manager_schema *plug_mgr)
{
struct stellar_exdata *exdata_rt = NULL;
- if(plug_mgr->session_exdata_schema_array==NULL)return NULL;
- unsigned int len = utarray_len(plug_mgr->session_exdata_schema_array);
+ if(plug_mgr->stellar_exdata_schema_array==NULL)return NULL;
+ unsigned int len = utarray_len(plug_mgr->stellar_exdata_schema_array);
if(len > 0)
{
exdata_rt=CALLOC(struct stellar_exdata, len);
@@ -791,18 +783,18 @@ static struct stellar_exdata *session_exdata_runtime_new(struct plugin_manager_s
static void session_exdata_runtime_free(struct plugin_manager_schema *plug_mgr, struct session *sess, struct stellar_exdata *exdata_rt)
{
if(exdata_rt==NULL)return;
- if(plug_mgr->session_exdata_schema_array==NULL)return;
- unsigned int len=utarray_len(plug_mgr->session_exdata_schema_array);
+ if(plug_mgr->stellar_exdata_schema_array==NULL)return;
+ unsigned int len=utarray_len(plug_mgr->stellar_exdata_schema_array);
for (unsigned int i = 0; i < len; i++)
{
void *exdata = (exdata_rt + i)->exdata;
(exdata_rt + i)->state=EXIT;
- struct stellar_exdata_schema *schema = (struct stellar_exdata_schema *)utarray_eltptr(plug_mgr->session_exdata_schema_array, i);
+ struct stellar_exdata_schema *schema = (struct stellar_exdata_schema *)utarray_eltptr(plug_mgr->stellar_exdata_schema_array, i);
if (exdata)
{
- if (schema->sess_free_func)
+ if (schema->free_func)
{
- schema->sess_free_func(sess, i, exdata, schema->free_arg);
+ schema->free_func(i, exdata, schema->free_arg);
}
}
}
diff --git a/src/plugin_manager/plugin_manager_interna.h b/src/plugin_manager/plugin_manager_interna.h
index 7792cf7..5889ddf 100644
--- a/src/plugin_manager/plugin_manager_interna.h
+++ b/src/plugin_manager/plugin_manager_interna.h
@@ -28,8 +28,7 @@ struct plugin_manager_schema
{
struct stellar *st;
UT_array *plugin_load_specs_array;
- UT_array *packet_exdata_schema_array;
- UT_array *session_exdata_schema_array;
+ UT_array *stellar_exdata_schema_array;
UT_array *stellar_mq_schema_array;
UT_array *registered_session_plugin_array;
UT_array *registered_packet_plugin_array;
@@ -60,12 +59,7 @@ struct stellar_exdata
struct stellar_exdata_schema
{
char *name;
- union
- {
- void *free_func;
- session_exdata_free *sess_free_func;
- packet_exdata_free *pkt_free_func;
- };
+ stellar_exdata_free *free_func;
void *free_arg;
int idx;
diff --git a/test/plugin_manager/plugin_manager_gtest_main.cpp b/test/plugin_manager/plugin_manager_gtest_main.cpp
index ac134d4..df0b080 100644
--- a/test/plugin_manager/plugin_manager_gtest_main.cpp
+++ b/test/plugin_manager/plugin_manager_gtest_main.cpp
@@ -17,11 +17,8 @@ void whitebox_test_plugin_manager_intrisic_metadata(struct stellar *st, struct p
//load spec null
EXPECT_TRUE(plug_mgr->plugin_load_specs_array==NULL);
- //packet exdata & mq schema null
- EXPECT_TRUE(plug_mgr->packet_exdata_schema_array==NULL);
-
//session exdata schema null
- EXPECT_TRUE(plug_mgr->session_exdata_schema_array==NULL);
+ EXPECT_TRUE(plug_mgr->stellar_exdata_schema_array==NULL);
//session mq schema not null
EXPECT_TRUE(plug_mgr->stellar_mq_schema_array!=NULL);
@@ -85,9 +82,9 @@ TEST(plugin_manager_init, init_with_null_toml) {
* TEST PLUGIN MANAGER PACKET PLUGIN INIT *
******************************************/
-static void test_mock_packet_exdata_free(struct packet *pkt, int idx, void *ex_ptr, void *arg){}
+static void test_mock_packet_exdata_free(int idx, void *ex_ptr, void *arg){}
-static void test_mock_overwrite_packet_exdata_free(struct packet *pkt, int idx, void *ex_ptr, void *arg){}
+static void test_mock_overwrite_packet_exdata_free(int idx, void *ex_ptr, void *arg){}
TEST(plugin_manager_init, packet_exdata_new_index_overwrite) {
struct stellar st={0};
@@ -95,22 +92,22 @@ TEST(plugin_manager_init, packet_exdata_new_index_overwrite) {
whitebox_test_plugin_manager_intrisic_metadata(&st, plug_mgr);
const char *exdata_name="PACKET_EXDATA";
- int exdata_idx=stellar_packet_exdata_new_index(&st,exdata_name, test_mock_packet_exdata_free, &st);
+ int exdata_idx=stellar_exdata_new_index(&st,exdata_name, test_mock_packet_exdata_free, &st);
EXPECT_GE(exdata_idx, 0);
- int overwrite_idx=stellar_packet_exdata_new_index(&st,exdata_name, test_mock_overwrite_packet_exdata_free, plug_mgr);
+ int overwrite_idx=stellar_exdata_new_index(&st,exdata_name, test_mock_overwrite_packet_exdata_free, plug_mgr);
EXPECT_GE(overwrite_idx, 0);
EXPECT_EQ(overwrite_idx, exdata_idx);
{
SCOPED_TRACE("White-box test, check stellar internal schema");
struct stellar_exdata_schema *exdata_schema = (struct stellar_exdata_schema *)utarray_eltptr(
- plug_mgr->packet_exdata_schema_array, (unsigned int)exdata_idx);
+ plug_mgr->stellar_exdata_schema_array, (unsigned int)exdata_idx);
EXPECT_EQ(exdata_schema->free_func, (void *)test_mock_overwrite_packet_exdata_free);
EXPECT_EQ(exdata_schema->free_arg, plug_mgr);
EXPECT_EQ(exdata_schema->idx, exdata_idx);
EXPECT_STREQ(exdata_schema->name, exdata_name);
- int exdata_num = utarray_len(plug_mgr->packet_exdata_schema_array);
+ int exdata_num = utarray_len(plug_mgr->stellar_exdata_schema_array);
EXPECT_EQ(exdata_num, 1);
}
@@ -342,6 +339,14 @@ TEST(plugin_manager, packet_plugins_with_proto_filter) {
}
}
+
+struct test_exdata
+{
+ struct packet *pkt;
+ struct session *sess;
+ long long value;
+};
+
static void test_exdata_set_on_packet(struct packet *pkt, unsigned char ip_protocol, void *plugin_env)
{
struct packet_plugin_env *env = (struct packet_plugin_env *)plugin_env;
@@ -354,8 +359,9 @@ static void test_exdata_set_on_packet(struct packet *pkt, unsigned char ip_proto
for(int i=0; i<exdata_idx_len; i++)
{
- long long *exdata_val=CALLOC(long long , 1);
- *exdata_val=i;
+ struct test_exdata *exdata_val=CALLOC(struct test_exdata , 1);
+ exdata_val->value=i;
+ exdata_val->pkt=pkt;
EXPECT_EQ(packet_exdata_set(pkt, env->packet_exdata_idx[i], exdata_val), 0);
}
return;
@@ -372,23 +378,26 @@ static void test_exdata_get_on_packet(struct packet *pkt, unsigned char ip_proto
for(int i=0; i<exdata_idx_len; i++)
{
- long long *exdata_val=(long long *)packet_exdata_get(pkt, env->packet_exdata_idx[i]);
- EXPECT_EQ(*exdata_val, i);
+ struct test_exdata *exdata_val=(struct test_exdata *)packet_exdata_get(pkt, env->packet_exdata_idx[i]);
+ EXPECT_EQ(exdata_val->value, i);
}
env->exdata_get_on_packet_called+=1;
return;
}
-static void test_packet_exdata_free(struct packet *pkt, int idx, void *ex_ptr, void *arg)
+static void test_packet_exdata_free(int idx, void *ex_ptr, void *arg)
{
struct packet_plugin_env *env = (struct packet_plugin_env *)arg;
+ struct test_exdata *exdata_val=(struct test_exdata *)ex_ptr;
EXPECT_EQ(env->packet_exdata_idx[idx], idx);
- EXPECT_EQ(*(long long *)ex_ptr, idx);
+ EXPECT_EQ(exdata_val->value, idx);
+
+ EXPECT_EQ(packet_exdata_get(exdata_val->pkt, idx), nullptr);// illegal get in exdata_free callback
+ EXPECT_EQ(packet_exdata_set(exdata_val->pkt, idx, exdata_val->pkt), -1);// illegal set in exdata_free callback
+
FREE(ex_ptr);
env->exdata_free_called[idx]+=1;
- EXPECT_EQ((long)packet_exdata_get(pkt, idx), NULL);// illegal get in exdata_free callback
- EXPECT_EQ(packet_exdata_set(pkt, idx, pkt), -1);// illegal set in exdata_free callback
return;
}
@@ -409,11 +418,11 @@ TEST(plugin_manager, packet_plugins_share_exdata) {
for(int i=0; i<exdata_idx_len; i++)
{
sprintf(exdata_name[i], "PACKET_EXDATA_%d", i);
- env.packet_exdata_idx[i]=stellar_packet_exdata_new_index(&st, exdata_name[i], test_packet_exdata_free, &env);
+ env.packet_exdata_idx[i]=stellar_exdata_new_index(&st, exdata_name[i], test_packet_exdata_free, &env);
{
SCOPED_TRACE("White-box test, check stellar internal schema");
struct stellar_exdata_schema *exdata_schema = (struct stellar_exdata_schema *)utarray_eltptr(
- plug_mgr->packet_exdata_schema_array, env.packet_exdata_idx[i]);
+ plug_mgr->stellar_exdata_schema_array, env.packet_exdata_idx[i]);
EXPECT_EQ(exdata_schema->free_func, (void *)test_packet_exdata_free);
EXPECT_EQ(exdata_schema->free_arg, &env);
@@ -424,7 +433,7 @@ TEST(plugin_manager, packet_plugins_share_exdata) {
{
SCOPED_TRACE("White-box test, check stellar internal schema");
- EXPECT_EQ(utarray_len(plug_mgr->packet_exdata_schema_array), exdata_idx_len);
+ EXPECT_EQ(utarray_len(plug_mgr->stellar_exdata_schema_array), exdata_idx_len);
}
int exdata_set_plugin_id=stellar_packet_plugin_register(&st, ip_proto, test_exdata_set_on_packet, &env);
@@ -680,13 +689,12 @@ TEST(plugin_manager, packet_plugins_pub_overlimit) {
-static void test_exdata_free_pub_msg_exdata_free(struct packet *pkt, int idx, void *ex_ptr, void *arg)
+static void test_exdata_free_pub_msg_exdata_free(int idx, void *ex_ptr, void *arg)
{
struct packet_plugin_env *env = (struct packet_plugin_env *)arg;
EXPECT_EQ(env->packet_exdata_idx[idx], idx);
- EXPECT_EQ(ex_ptr, pkt);
env->exdata_free_called[idx]+=1;
- EXPECT_EQ(packet_mq_publish_message(pkt, env->packet_topic_id[0], pkt), -1);// publish message in packet exdata_free is illegal
+ EXPECT_EQ(packet_mq_publish_message((struct packet *)ex_ptr, env->packet_topic_id[0], (struct packet *)ex_ptr), -1);// publish message in packet exdata_free is illegal
env->msg_pub_cnt+=1;
return;
}
@@ -730,7 +738,7 @@ TEST(plugin_manager, packet_plugin_exdata_free_pub_msg) {
int plugin_id=stellar_packet_plugin_register(&st, ip_proto, test_exdata_free_pub_msg_on_packet, &env);
EXPECT_GE(plugin_id, PACKET_PULGIN_ID_BASE);
- env.packet_exdata_idx[0]=stellar_packet_exdata_new_index(&st, "PACKET_EXDATA", test_exdata_free_pub_msg_exdata_free, &env);
+ env.packet_exdata_idx[0]=stellar_exdata_new_index(&st, "PACKET_EXDATA", test_exdata_free_pub_msg_exdata_free, &env);
env.packet_topic_id[0]=stellar_mq_create_topic(&st, "PACKET_TOPIC", test_exdata_free_pub_msg_free, &env);
EXPECT_EQ(stellar_packet_mq_subscribe(&st, env.packet_topic_id[0], test_exdata_free_pub_msg_on_packet_msg, plugin_id),0);
@@ -753,8 +761,8 @@ TEST(plugin_manager, packet_plugin_exdata_free_pub_msg) {
* TEST PLUGIN MANAGER ON SESSION PLUGIN INIT *
**********************************************/
-static void test_mock_session_exdata_free(struct session *sess, int idx, void *ex_ptr, void *arg){}
-static void test_mock_overwrite_session_exdata_free(struct session *sess, int idx, void *ex_ptr, void *arg){}
+static void test_mock_session_exdata_free(int idx, void *ex_ptr, void *arg){}
+static void test_mock_overwrite_session_exdata_free(int idx, void *ex_ptr, void *arg){}
TEST(plugin_manager_init, session_exdata_new_index_overwrite) {
struct stellar st={0};
@@ -762,22 +770,22 @@ TEST(plugin_manager_init, session_exdata_new_index_overwrite) {
whitebox_test_plugin_manager_intrisic_metadata(&st, plug_mgr);
const char *exdata_name="SESSION_EXDATA";
- int exdata_idx=stellar_session_exdata_new_index(&st,exdata_name, test_mock_session_exdata_free, &st);
+ int exdata_idx=stellar_exdata_new_index(&st,exdata_name, test_mock_session_exdata_free, &st);
EXPECT_GE(exdata_idx, 0);
- int overwrite_idx=stellar_session_exdata_new_index(&st,exdata_name, test_mock_overwrite_session_exdata_free, plug_mgr);
+ int overwrite_idx=stellar_exdata_new_index(&st,exdata_name, test_mock_overwrite_session_exdata_free, plug_mgr);
EXPECT_GE(overwrite_idx, 0);
EXPECT_EQ(overwrite_idx, exdata_idx);
{
SCOPED_TRACE("White-box test, check stellar internal schema");
struct stellar_exdata_schema *exdata_schema = (struct stellar_exdata_schema *)utarray_eltptr(
- plug_mgr->session_exdata_schema_array, (unsigned int)exdata_idx);
+ plug_mgr->stellar_exdata_schema_array, (unsigned int)exdata_idx);
EXPECT_EQ(exdata_schema->free_func, (void *)test_mock_overwrite_session_exdata_free);
EXPECT_EQ(exdata_schema->free_arg, plug_mgr);
EXPECT_EQ(exdata_schema->idx, exdata_idx);
EXPECT_STREQ(exdata_schema->name, exdata_name);
- int exdata_num = utarray_len(plug_mgr->session_exdata_schema_array);
+ int exdata_num = utarray_len(plug_mgr->stellar_exdata_schema_array);
EXPECT_EQ(exdata_num, 1);
}
plugin_manager_exit(plug_mgr);
@@ -1002,7 +1010,7 @@ static void test_basic_on_session_ingress(struct session *sess, int topic_id, co
EXPECT_EQ(sess->plug_mgr_rt->plug_mgr, env->plug_mgr);
EXPECT_EQ(session_exdata_set(sess, 2, sess), -1);// illegal set
EXPECT_EQ(session_exdata_get(sess, 2), nullptr);// illegal get
- EXPECT_EQ(session_exdata_set(sess, env->basic_exdata_idx, env), 0);
+ EXPECT_EQ(session_exdata_set(sess, env->basic_exdata_idx, sess), 0);
if(msg)
{
env->basic_on_session_ingress_called+=1;
@@ -1021,19 +1029,18 @@ static void test_basic_on_session_egress(struct session *sess, int topic_id, con
EXPECT_EQ(session_exdata_set(sess, 2, sess), -1);// illegal set
EXPECT_EQ(session_exdata_get(sess, 2), nullptr);// illegal get
EXPECT_TRUE(msg!=NULL);
- EXPECT_EQ(session_exdata_get(sess, env->basic_exdata_idx), env);
+ EXPECT_EQ(session_exdata_get(sess, env->basic_exdata_idx), sess);
env->basic_on_session_egress_called+=1;
ctx->called+=1;
return;
}
-static void test_basic_session_exdata_free(struct session *sess, int idx, void *ex_ptr, void *arg)
+static void test_basic_session_exdata_free(int idx, void *ex_ptr, void *arg)
{
struct session_plugin_env *env = (struct session_plugin_env *)arg;
EXPECT_EQ(env->basic_exdata_idx, idx);
- EXPECT_EQ(ex_ptr, env);
- EXPECT_EQ((long)session_exdata_get(sess, idx), NULL);// illegal get in exdata_free callback
- EXPECT_EQ(session_exdata_set(sess, idx, arg), -1);// illegal set in exdata_free callback
+ EXPECT_EQ(session_exdata_get((struct session *)ex_ptr, idx), nullptr);// illegal get in exdata_free callback
+ EXPECT_EQ(session_exdata_set((struct session *)ex_ptr, idx, arg), -1);// illegal set in exdata_free callback
env->basic_exdata_free_called+=1;
}
@@ -1062,7 +1069,7 @@ TEST(plugin_manager, session_plugin_on_intrinsic_ingress_egress) {
EXPECT_EQ(stellar_session_mq_subscribe(&st, env.intrinsc_egress_topic_id, test_basic_on_session_ingress, plugin_id), 0);// Intentional error
EXPECT_EQ(stellar_session_mq_subscribe(&st, env.intrinsc_egress_topic_id, test_basic_on_session_egress, plugin_id), 0);
- env.basic_exdata_idx=stellar_session_exdata_new_index(&st, "SESSION_EXDATA", test_basic_session_exdata_free,&env);
+ env.basic_exdata_idx=stellar_exdata_new_index(&st, "SESSION_EXDATA", test_basic_session_exdata_free,&env);
EXPECT_GE(env.basic_exdata_idx, 0);
struct packet pkt={&st, TCP, ip_proto};
@@ -2083,18 +2090,17 @@ TEST(plugin_manager, test_session_mq_priority) {
}
-void test_session_exdata_free_pub_msg_exdata_free(struct session *sess, int idx, void *ex_ptr, void *arg)
+void test_session_exdata_free_pub_msg_exdata_free(int idx, void *ex_ptr, void *arg)
{
- EXPECT_EQ(ex_ptr, arg);
- struct session_plugin_env *env = (struct session_plugin_env *)ex_ptr;
- EXPECT_EQ(session_mq_publish_message(sess, env->intrinsc_tcp_topic_id, env), -1);
+ struct session_plugin_env *env = (struct session_plugin_env *)arg;
+ EXPECT_EQ(session_mq_publish_message((struct session *)ex_ptr, env->intrinsc_tcp_topic_id, arg), -1);
env->basic_exdata_free_called+=1;
}
static void test_session_exdata_free_pub_msg_on_session(struct session *sess, int topic_id, const void *msg, void *per_session_ctx, void *plugin_env)
{
struct session_plugin_env *env = (struct session_plugin_env *)plugin_env;
- EXPECT_EQ(session_exdata_set(sess, env->basic_exdata_idx, (void *)plugin_env), 0);
+ EXPECT_EQ(session_exdata_set(sess, env->basic_exdata_idx, sess), 0);
if(msg)env->plugin_id_1_called+=1;
}
@@ -2116,7 +2122,7 @@ TEST(plugin_manager, session_exdata_free_pub_msg) {
EXPECT_GE(env.intrinsc_tcp_topic_id, 0);
EXPECT_EQ(stellar_session_mq_subscribe(&st, env.intrinsc_tcp_topic_id, test_session_exdata_free_pub_msg_on_session, env.plugin_id_1), 0);
- env.basic_exdata_idx=stellar_session_exdata_new_index(&st, "BASIC_EXDATA", test_session_exdata_free_pub_msg_exdata_free, &env) ;
+ env.basic_exdata_idx=stellar_exdata_new_index(&st, "BASIC_EXDATA", test_session_exdata_free_pub_msg_exdata_free, &env) ;
EXPECT_GE(env.basic_exdata_idx, 0);
// pesudo packet and session