summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorluwenpeng <[email protected]>2022-08-16 10:37:00 +0800
committerluwenpeng <[email protected]>2022-08-16 11:07:29 +0800
commitb9d93e042b383f4ed683008662e99efa562ba017 (patch)
treeb5e1a2a7ebef6a1672cb54ad4529356192dd8cc0
parent4005e8d71655a5395a00c3be2b38dbc577f95847 (diff)
rename fn_session_event_callback to plugin_event_callback and update API parameters
* plugin_event_callback delete 'struct stellar_packet *p' * plugin_event_callback rename 'uint16_t len' to 'size_t len' * plugin_event_callback rename 'void **pme' to 'void **ctx'
-rw-r--r--readme.md2
-rw-r--r--sdk/example/custom_event_plugin.cpp60
-rw-r--r--sdk/example/http_event_plugin.cpp28
-rw-r--r--sdk/include/http.h2
-rw-r--r--sdk/include/plugin.h5
-rw-r--r--sdk/include/session.h2
-rw-r--r--src/plugin_manager/plugin_manager.cpp16
-rw-r--r--src/plugin_manager/plugin_manager.h5
-rw-r--r--src/plugin_manager/plugin_manager_module.cpp4
-rw-r--r--src/plugin_manager/test/gtest_plugin_manager.cpp100
-rw-r--r--src/plugin_manager/test/test_plugins/plugins_library/custom_event_plugin.cpp112
-rw-r--r--src/plugin_manager/test/test_plugins/plugins_library/http_event_plugin.cpp38
-rw-r--r--src/protocol_decoder/http/http.cpp4
13 files changed, 190 insertions, 188 deletions
diff --git a/readme.md b/readme.md
index db52db0..fa64dfc 100644
--- a/readme.md
+++ b/readme.md
@@ -77,7 +77,7 @@ session_unlock(session, plug_id);
```
Plugin Example
```
-plugin_entry(session, pme)
+plugin_entry(session, ctx)
{
session_get_metadata(session, "fw_action", value);
if(value==INTERCEPT)
diff --git a/sdk/example/custom_event_plugin.cpp b/sdk/example/custom_event_plugin.cpp
index 8034d99..00e0d43 100644
--- a/sdk/example/custom_event_plugin.cpp
+++ b/sdk/example/custom_event_plugin.cpp
@@ -9,72 +9,72 @@
static char *g_handler = NULL;
-static void *custom_decode(const char *payload, uint16_t len, void **pme)
+static void *custom_decode(const char *payload, size_t len, void **ctx)
{
return NULL;
}
-struct tcp_session_pme
+struct tcp_session_ctx
{
char data[16];
/* data */
};
-struct custom_session_pme
+struct custom_session_ctx
{
char data[16];
/* data */
};
-static struct tcp_session_pme *tcp_session_pme_create()
+static struct tcp_session_ctx *tcp_session_ctx_create()
{
- struct tcp_session_pme *pme = (struct tcp_session_pme *)calloc(1, sizeof(struct tcp_session_pme));
- return pme;
+ struct tcp_session_ctx *ctx = (struct tcp_session_ctx *)calloc(1, sizeof(struct tcp_session_ctx));
+ return ctx;
}
-static void tcp_session_pme_destory(struct tcp_session_pme *pme)
+static void tcp_session_ctx_destory(struct tcp_session_ctx *ctx)
{
- if (pme)
+ if (ctx)
{
- free(pme);
- pme = NULL;
+ free(ctx);
+ ctx = NULL;
}
}
-static struct custom_session_pme *custom_session_pme_create()
+static struct custom_session_ctx *custom_session_ctx_create()
{
- struct custom_session_pme *pme = (struct custom_session_pme *)calloc(1, sizeof(struct custom_session_pme));
- return pme;
+ struct custom_session_ctx *ctx = (struct custom_session_ctx *)calloc(1, sizeof(struct custom_session_ctx));
+ return ctx;
}
-static void custom_session_pme_destory(struct custom_session_pme *pme)
+static void custom_session_ctx_destory(struct custom_session_ctx *ctx)
{
- if (pme)
+ if (ctx)
{
- free(pme);
- pme = NULL;
+ free(ctx);
+ ctx = NULL;
}
}
-extern "C" void custom_event_plugin_tcp_entry(const struct stellar_session *session, enum session_event_type event, struct stellar_packet *p, const char *payload, uint16_t len, void **pme)
+extern "C" void custom_event_plugin_tcp_entry(const struct stellar_session *session, enum session_event_type event, const char *payload, size_t len, void **ctx)
{
- struct tcp_session_pme **per_tcp_session_pme = (struct tcp_session_pme **)pme;
+ struct tcp_session_ctx **per_tcp_session_ctx = (struct tcp_session_ctx **)ctx;
printf("RUN custom_event_plugin_tcp_entry, event: %d\n", event);
if (event & SESSION_EVENT_OPENING)
{
- if (*per_tcp_session_pme == NULL)
+ if (*per_tcp_session_ctx == NULL)
{
- struct tcp_session_pme *cur_ctx = tcp_session_pme_create();
+ struct tcp_session_ctx *cur_ctx = tcp_session_ctx_create();
memcpy(cur_ctx->data, "custom_event_plugin_tcp_entry", strlen("custom_event_plugin_tcp_entry"));
- *per_tcp_session_pme = *&cur_ctx;
+ *per_tcp_session_ctx = *&cur_ctx;
}
}
if (event & SESSION_EVENT_ORDPKT)
{
- struct stellar_session_event_extras *info = (struct stellar_session_event_extras *)custom_decode(payload, len, pme);
+ struct stellar_session_event_extras *info = (struct stellar_session_event_extras *)custom_decode(payload, len, ctx);
struct stellar_session *new_session = session_manager_session_derive(session, "CUSTOM");
session_manager_trigger_event(new_session, SESSION_EVENT_OPENING, info);
@@ -83,29 +83,29 @@ extern "C" void custom_event_plugin_tcp_entry(const struct stellar_session *sess
if (event & SESSION_EVENT_CLOSING)
{
- tcp_session_pme_destory(*per_tcp_session_pme);
+ tcp_session_ctx_destory(*per_tcp_session_ctx);
}
}
-extern "C" void custom_event_plugin_custom_entry(const struct stellar_session *session, enum session_event_type event, struct stellar_packet *p, const char *payload, uint16_t len, void **pme)
+extern "C" void custom_event_plugin_custom_entry(const struct stellar_session *session, enum session_event_type event, const char *payload, size_t len, void **ctx)
{
- struct custom_session_pme **per_custom_session_pme = (struct custom_session_pme **)pme;
+ struct custom_session_ctx **per_custom_session_ctx = (struct custom_session_ctx **)ctx;
printf("RUN custom_event_plugin_custom_entry, event: %d\n", event);
if (event & SESSION_EVENT_OPENING)
{
- if (*per_custom_session_pme == NULL)
+ if (*per_custom_session_ctx == NULL)
{
- struct custom_session_pme *cur_ctx = custom_session_pme_create();
+ struct custom_session_ctx *cur_ctx = custom_session_ctx_create();
memcpy(cur_ctx->data, "custom_event_plugin_custom_entry", strlen("custom_event_plugin_custom_entry"));
- *per_custom_session_pme = *&cur_ctx;
+ *per_custom_session_ctx = *&cur_ctx;
}
}
if (event & SESSION_EVENT_CLOSING)
{
- custom_session_pme_destory(*per_custom_session_pme);
+ custom_session_ctx_destory(*per_custom_session_ctx);
}
}
diff --git a/sdk/example/http_event_plugin.cpp b/sdk/example/http_event_plugin.cpp
index ef1e761..635dbbb 100644
--- a/sdk/example/http_event_plugin.cpp
+++ b/sdk/example/http_event_plugin.cpp
@@ -8,40 +8,40 @@
static char *g_handler = NULL;
-struct http_session_pme
+struct http_session_ctx
{
char data[16];
/* data */;
};
-static struct http_session_pme *http_session_pme_create()
+static struct http_session_ctx *http_session_ctx_create()
{
- struct http_session_pme *pme = (struct http_session_pme *)calloc(1, sizeof(struct http_session_pme));
- return pme;
+ struct http_session_ctx *ctx = (struct http_session_ctx *)calloc(1, sizeof(struct http_session_ctx));
+ return ctx;
}
-static void http_session_pme_destory(struct http_session_pme *pme)
+static void http_session_ctx_destory(struct http_session_ctx *ctx)
{
- if (pme)
+ if (ctx)
{
- free(pme);
- pme = NULL;
+ free(ctx);
+ ctx = NULL;
}
}
-extern "C" void http_event_plugin_entry(const struct stellar_session *session, enum session_event_type event, struct stellar_packet *p, const char *payload, uint16_t len, void **pme)
+extern "C" void http_event_plugin_entry(const struct stellar_session *session, enum session_event_type event, const char *payload, size_t len, void **ctx)
{
- struct http_session_pme **per_http_session_pme = (struct http_session_pme **)pme;
+ struct http_session_ctx **per_http_session_ctx = (struct http_session_ctx **)ctx;
printf("RUN http_event_plugin_entry, event: %d\n", event);
if (event & SESSION_EVENT_OPENING)
{
- if (*per_http_session_pme == NULL)
+ if (*per_http_session_ctx == NULL)
{
- struct http_session_pme *cur_ctx = http_session_pme_create();
+ struct http_session_ctx *cur_ctx = http_session_ctx_create();
memcpy(cur_ctx->data, "http_event_plugin_entry", strlen("http_event_plugin_entry"));
- *per_http_session_pme = *&cur_ctx;
+ *per_http_session_ctx = *&cur_ctx;
}
}
@@ -64,7 +64,7 @@ extern "C" void http_event_plugin_entry(const struct stellar_session *session, e
if (event & SESSION_EVENT_CLOSING)
{
- http_session_pme_destory(*per_http_session_pme);
+ http_session_ctx_destory(*per_http_session_ctx);
}
}
diff --git a/sdk/include/http.h b/sdk/include/http.h
index a88d072..e364ca0 100644
--- a/sdk/include/http.h
+++ b/sdk/include/http.h
@@ -7,7 +7,7 @@ extern "C"
#include "session.h"
-void http_decoder(const struct stellar_session *s, enum session_event_type event, struct stellar_packet *p, const char *payload, uint16_t len, void **pme);
+void http_decoder(const struct stellar_session *session, enum session_event_type event, const char *payload, size_t len, void **ctx);
#ifdef __cpluscplus
}
diff --git a/sdk/include/plugin.h b/sdk/include/plugin.h
index 7042bbe..33fe985 100644
--- a/sdk/include/plugin.h
+++ b/sdk/include/plugin.h
@@ -6,10 +6,13 @@ extern "C"
{
#endif
+#include <stddef.h>
+
#include "session.h"
typedef int plugin_init_callback(void);
typedef void plugin_exit_callback(void);
+typedef void plugin_event_callback(const struct stellar_session *session, enum session_event_type event, const char *payload, size_t len, void **ctx);
/******************************************************************************
* Public API For Plugin
@@ -31,7 +34,7 @@ void pm_session_dettach_me(const struct stellar_session *session);
* /|\
* |
* plugin cb2 run pm_session_take_over
- *
+ *
* A plugin(cb1/cb3/cb4) that is taken over, if the plugin was called before being taken over and has a registered SESSION_EVENT_CLOSING event,
* it will be called again when the SESSION_EVENT_CLOSING event comes. Otherwise, the plugin will not be called.
*/
diff --git a/sdk/include/session.h b/sdk/include/session.h
index 8ce3d26..c55d191 100644
--- a/sdk/include/session.h
+++ b/sdk/include/session.h
@@ -42,8 +42,6 @@ enum session_event_type
struct stellar_session_event_extras;
-typedef void(fn_session_event_callback)(const struct stellar_session *s, enum session_event_type event, struct stellar_packet *p, const char *payload, uint16_t len, void **pme);
-
void session_manager_trigger_event(struct stellar_session *s, enum session_event_type type, struct stellar_session_event_extras *info);
struct stellar_session *session_manager_session_derive(const struct stellar_session *this_session, const char *session_name);
diff --git a/src/plugin_manager/plugin_manager.cpp b/src/plugin_manager/plugin_manager.cpp
index 88aae1e..a35ee82 100644
--- a/src/plugin_manager/plugin_manager.cpp
+++ b/src/plugin_manager/plugin_manager.cpp
@@ -3,6 +3,7 @@
#include "uthash/uthash.h"
+#include "sdk/include/plugin.h"
#include "session_manager.h"
#include "plugin_manager_module.h"
@@ -20,7 +21,7 @@ enum plugin_status
struct callback_runtime
{
void *cb_args;
- fn_session_event_callback *event_cb;
+ plugin_event_callback *event_cb;
enum session_event_type event;
enum plugin_status status;
@@ -41,7 +42,7 @@ struct session_plugin_ctx
struct callback_static
{
enum session_event_type event;
- fn_session_event_callback *event_cb;
+ plugin_event_callback *event_cb;
};
struct plugin_manager_eventcb
@@ -342,7 +343,7 @@ void plugin_manager_destory(struct plugin_manager *plug_mgr)
}
}
-int plugin_manager_register(struct plugin_manager *plug_mgr, const char *session_name, enum session_event_type event, fn_session_event_callback *event_cb)
+int plugin_manager_register(struct plugin_manager *plug_mgr, const char *session_name, enum session_event_type event, plugin_event_callback *event_cb)
{
if (strlen(session_name) <= 0)
{
@@ -399,7 +400,6 @@ void plugin_manager_dispatch(struct plugin_manager *plug_mgr, struct stellar_eve
struct session_plugin_ctx *plug_ctx = stellar_event_get_plugin_ctx(event);
enum session_event_type event_type = stellar_event_get_type(event);
const char *session_name = stellar_event_get_session_name(event);
- struct stellar_packet *packet = stellar_event_get_packet(event);
uint16_t payload_len = stellar_event_get_payload_length(event);
const char *payload = stellar_event_get_payload(event);
@@ -441,7 +441,7 @@ void plugin_manager_dispatch(struct plugin_manager *plug_mgr, struct stellar_eve
{
plug_ctx->callback_index = i;
plugin_manager_log(DEBUG, "dispatch, run event_cb: %p, plugin status: 'taken over', session: %s, event: (%d, %s)", runtime->event_cb, session_name, event_type, event_str_buffer);
- runtime->event_cb(seesion, SESSION_EVENT_CLOSING, packet, payload, payload_len, &runtime->cb_args);
+ runtime->event_cb(seesion, SESSION_EVENT_CLOSING, payload, payload_len, &runtime->cb_args);
continue;
}
else
@@ -455,7 +455,7 @@ void plugin_manager_dispatch(struct plugin_manager *plug_mgr, struct stellar_eve
{
plug_ctx->callback_index = i;
plugin_manager_log(DEBUG, "dispatch, run event_cb: %p, plugin status: 'normal', session: %s, event: (%d, %s)", runtime->event_cb, session_name, event_type, event_str_buffer);
- runtime->event_cb(seesion, event_type, packet, payload, payload_len, &runtime->cb_args);
+ runtime->event_cb(seesion, event_type, payload, payload_len, &runtime->cb_args);
runtime->is_be_called = 1;
}
else
@@ -506,7 +506,7 @@ void pm_session_dettach_me(const struct stellar_session *session)
* /|\
* |
* plugin cb2 run pm_session_take_over
- *
+ *
* A plugin(cb1/cb3/cb4) that is taken over, if the plugin was called before being taken over and has a registered SESSION_EVENT_CLOSING event,
* it will be called again when the SESSION_EVENT_CLOSING event comes. Otherwise, the plugin will not be called.
*/
@@ -531,7 +531,7 @@ void pm_session_take_over(const struct stellar_session *session)
* Util For Gtest
******************************************************************************/
-void *pm_session_get_plugin_pme(const struct stellar_session *session)
+void *pm_session_get_plugin_ctx(const struct stellar_session *session)
{
struct session_plugin_ctx *plugin_ctx = stellar_session_get_plugin_ctx(session);
assert(plugin_ctx);
diff --git a/src/plugin_manager/plugin_manager.h b/src/plugin_manager/plugin_manager.h
index b23e874..a310d16 100644
--- a/src/plugin_manager/plugin_manager.h
+++ b/src/plugin_manager/plugin_manager.h
@@ -7,6 +7,7 @@ extern "C"
#endif
#include "sdk/include/session.h"
+#include "sdk/include/plugin.h"
struct plugin_manager;
@@ -16,11 +17,11 @@ void plugin_manager_destory(struct plugin_manager *plug_mgr);
int plugin_manager_load(struct plugin_manager *plug_mgr, const char *file);
void plugin_manager_unload(struct plugin_manager *plug_mgr);
-int plugin_manager_register(struct plugin_manager *plug_mgr, const char *session_name, enum session_event_type event, fn_session_event_callback *event_cb);
+int plugin_manager_register(struct plugin_manager *plug_mgr, const char *session_name, enum session_event_type event, plugin_event_callback *event_cb);
void plugin_manager_dispatch(struct plugin_manager *plug_mgr, struct stellar_event *event);
// only use for gtest
-void *pm_session_get_plugin_pme(const struct stellar_session *session);
+void *pm_session_get_plugin_ctx(const struct stellar_session *session);
#ifdef __cpluscplus
}
diff --git a/src/plugin_manager/plugin_manager_module.cpp b/src/plugin_manager/plugin_manager_module.cpp
index 7756da5..f8002cd 100644
--- a/src/plugin_manager/plugin_manager_module.cpp
+++ b/src/plugin_manager/plugin_manager_module.cpp
@@ -9,7 +9,7 @@
struct plugin_manager_module_evcb
{
char session_name[MAX_SESSION_NAME_LENGTH];
- fn_session_event_callback *event_cb_ptr;
+ plugin_event_callback *event_cb_ptr;
enum session_event_type event;
};
@@ -96,7 +96,7 @@ struct plugin_manager_module *plugin_manager_module_open(struct plugin_manager_c
strncpy(event_cb->session_name, session_config->session_name, strlen(session_config->session_name));
event_cb->event = session_config->event;
- event_cb->event_cb_ptr = (fn_session_event_callback *)(dlsym(module->dl_handle, session_config->cb_func_name));
+ event_cb->event_cb_ptr = (plugin_event_callback *)(dlsym(module->dl_handle, session_config->cb_func_name));
if (event_cb->event_cb_ptr == NULL)
{
plugin_manager_log(ERROR, "can't find symbol name of '%s' in dynamic library %s, %s",
diff --git a/src/plugin_manager/test/gtest_plugin_manager.cpp b/src/plugin_manager/test/gtest_plugin_manager.cpp
index 6afd126..22b746f 100644
--- a/src/plugin_manager/test/gtest_plugin_manager.cpp
+++ b/src/plugin_manager/test/gtest_plugin_manager.cpp
@@ -261,14 +261,14 @@ TEST(PLUGIN_MANAGER_TEST, plugin_manager_dispatch_CUSTOM)
* SESSION_EVENT_CALLBACK="custom_event_plugin_custom_entry"
*/
- struct custom_session_pme
+ struct custom_session_ctx
{
char data[64];
int flags;
/* data */
};
- struct custom_session_pme *pme;
+ struct custom_session_ctx *ctx;
char file_path[] = "./plugins_config/plugins.inf";
const char *session_name = "CUSTOM";
@@ -292,30 +292,30 @@ TEST(PLUGIN_MANAGER_TEST, plugin_manager_dispatch_CUSTOM)
// run evencb
event_data.type = SESSION_EVENT_OPENING;
plugin_manager_dispatch(plug_mgr, &event);
- pme = (struct custom_session_pme *)pm_session_get_plugin_pme(&session);
- EXPECT_TRUE(pme->flags == SESSION_EVENT_OPENING);
- EXPECT_STREQ(pme->data, "custom_event_plugin_custom_entry");
+ ctx = (struct custom_session_ctx *)pm_session_get_plugin_ctx(&session);
+ EXPECT_TRUE(ctx->flags == SESSION_EVENT_OPENING);
+ EXPECT_STREQ(ctx->data, "custom_event_plugin_custom_entry");
// unrun evencb
event_data.type = SESSION_EVENT_RAWPKT;
plugin_manager_dispatch(plug_mgr, &event);
- pme = (struct custom_session_pme *)pm_session_get_plugin_pme(&session);
- EXPECT_TRUE(pme->flags == SESSION_EVENT_OPENING);
- EXPECT_STREQ(pme->data, "custom_event_plugin_custom_entry");
+ ctx = (struct custom_session_ctx *)pm_session_get_plugin_ctx(&session);
+ EXPECT_TRUE(ctx->flags == SESSION_EVENT_OPENING);
+ EXPECT_STREQ(ctx->data, "custom_event_plugin_custom_entry");
// run evencb
event_data.type = SESSION_EVENT_ORDPKT;
plugin_manager_dispatch(plug_mgr, &event);
- pme = (struct custom_session_pme *)pm_session_get_plugin_pme(&session);
- EXPECT_TRUE(pme->flags == SESSION_EVENT_ORDPKT);
- EXPECT_STREQ(pme->data, "custom_event_plugin_custom_entry");
+ ctx = (struct custom_session_ctx *)pm_session_get_plugin_ctx(&session);
+ EXPECT_TRUE(ctx->flags == SESSION_EVENT_ORDPKT);
+ EXPECT_STREQ(ctx->data, "custom_event_plugin_custom_entry");
// unrun evencb
event_data.type = SESSION_EVENT_META;
plugin_manager_dispatch(plug_mgr, &event);
- pme = (struct custom_session_pme *)pm_session_get_plugin_pme(&session);
- EXPECT_TRUE(pme->flags == SESSION_EVENT_ORDPKT);
- EXPECT_STREQ(pme->data, "custom_event_plugin_custom_entry");
+ ctx = (struct custom_session_ctx *)pm_session_get_plugin_ctx(&session);
+ EXPECT_TRUE(ctx->flags == SESSION_EVENT_ORDPKT);
+ EXPECT_STREQ(ctx->data, "custom_event_plugin_custom_entry");
// run evencb
event_data.type = SESSION_EVENT_CLOSING;
@@ -342,13 +342,13 @@ TEST(PLUGIN_MANAGER_TEST, plugin_manager_dispatch_TCP)
* SESSION_EVENT_CALLBACK="custom_event_plugin_tcp_entry"
*/
- struct tcp_session_pme
+ struct tcp_session_ctx
{
char data[64];
int flags;
/* data */
};
- struct tcp_session_pme *pme;
+ struct tcp_session_ctx *ctx;
char file_path[] = "./plugins_config/plugins.inf";
@@ -373,30 +373,30 @@ TEST(PLUGIN_MANAGER_TEST, plugin_manager_dispatch_TCP)
// run evencb
event_data.type = SESSION_EVENT_OPENING;
plugin_manager_dispatch(plug_mgr, &event);
- pme = (struct tcp_session_pme *)pm_session_get_plugin_pme(&session);
- EXPECT_TRUE(pme->flags == SESSION_EVENT_OPENING);
- EXPECT_STREQ(pme->data, "custom_event_plugin_tcp_entry");
+ ctx = (struct tcp_session_ctx *)pm_session_get_plugin_ctx(&session);
+ EXPECT_TRUE(ctx->flags == SESSION_EVENT_OPENING);
+ EXPECT_STREQ(ctx->data, "custom_event_plugin_tcp_entry");
// run evencb
event_data.type = SESSION_EVENT_RAWPKT;
plugin_manager_dispatch(plug_mgr, &event);
- pme = (struct tcp_session_pme *)pm_session_get_plugin_pme(&session);
- EXPECT_TRUE(pme->flags == SESSION_EVENT_RAWPKT);
- EXPECT_STREQ(pme->data, "custom_event_plugin_tcp_entry");
+ ctx = (struct tcp_session_ctx *)pm_session_get_plugin_ctx(&session);
+ EXPECT_TRUE(ctx->flags == SESSION_EVENT_RAWPKT);
+ EXPECT_STREQ(ctx->data, "custom_event_plugin_tcp_entry");
// run evencb
event_data.type = SESSION_EVENT_ORDPKT;
plugin_manager_dispatch(plug_mgr, &event);
- pme = (struct tcp_session_pme *)pm_session_get_plugin_pme(&session);
- EXPECT_TRUE(pme->flags == SESSION_EVENT_ORDPKT);
- EXPECT_STREQ(pme->data, "custom_event_plugin_tcp_entry");
+ ctx = (struct tcp_session_ctx *)pm_session_get_plugin_ctx(&session);
+ EXPECT_TRUE(ctx->flags == SESSION_EVENT_ORDPKT);
+ EXPECT_STREQ(ctx->data, "custom_event_plugin_tcp_entry");
// run evencb
event_data.type = SESSION_EVENT_META;
plugin_manager_dispatch(plug_mgr, &event);
- pme = (struct tcp_session_pme *)pm_session_get_plugin_pme(&session);
- EXPECT_TRUE(pme->flags == SESSION_EVENT_META);
- EXPECT_STREQ(pme->data, "custom_event_plugin_tcp_entry");
+ ctx = (struct tcp_session_ctx *)pm_session_get_plugin_ctx(&session);
+ EXPECT_TRUE(ctx->flags == SESSION_EVENT_META);
+ EXPECT_STREQ(ctx->data, "custom_event_plugin_tcp_entry");
// run evencb
event_data.type = SESSION_EVENT_CLOSING;
@@ -427,14 +427,14 @@ TEST(PLUGIN_MANAGER_TEST, plugin_manager_dispatch_HTTP_dettach_me)
* SESSION_EVENT_CALLBACK="custom_event_plugin_http_entry"
*/
- struct http_session_pme
+ struct http_session_ctx
{
char data[64];
int flags;
/* data */;
};
- struct http_session_pme *pme = NULL;
+ struct http_session_ctx *ctx = NULL;
char file_path[] = "./plugins_config/plugins.inf";
const char *session_name = "HTTP";
@@ -458,23 +458,23 @@ TEST(PLUGIN_MANAGER_TEST, plugin_manager_dispatch_HTTP_dettach_me)
// run evencb
event_data.type = SESSION_EVENT_OPENING;
plugin_manager_dispatch(plug_mgr, &event);
- pme = (struct http_session_pme *)pm_session_get_plugin_pme(&session);
- EXPECT_TRUE(pme->flags == SESSION_EVENT_OPENING);
- EXPECT_STREQ(pme->data, "custom_event_plugin_http_entry");
+ ctx = (struct http_session_ctx *)pm_session_get_plugin_ctx(&session);
+ EXPECT_TRUE(ctx->flags == SESSION_EVENT_OPENING);
+ EXPECT_STREQ(ctx->data, "custom_event_plugin_http_entry");
// http_event_plugin_entry + SESSION_EVENT_RAWPKT ==> pm_session_dettach_me
event_data.type = SESSION_EVENT_RAWPKT;
plugin_manager_dispatch(plug_mgr, &event);
- pme = (struct http_session_pme *)pm_session_get_plugin_pme(&session);
- EXPECT_TRUE(pme->flags == SESSION_EVENT_RAWPKT);
- EXPECT_STREQ(pme->data, "custom_event_plugin_http_entry");
+ ctx = (struct http_session_ctx *)pm_session_get_plugin_ctx(&session);
+ EXPECT_TRUE(ctx->flags == SESSION_EVENT_RAWPKT);
+ EXPECT_STREQ(ctx->data, "custom_event_plugin_http_entry");
// run evencb
event_data.type = SESSION_EVENT_META;
plugin_manager_dispatch(plug_mgr, &event);
- pme = (struct http_session_pme *)pm_session_get_plugin_pme(&session);
- EXPECT_TRUE(pme->flags == SESSION_EVENT_META);
- EXPECT_STREQ(pme->data, "custom_event_plugin_http_entry");
+ ctx = (struct http_session_ctx *)pm_session_get_plugin_ctx(&session);
+ EXPECT_TRUE(ctx->flags == SESSION_EVENT_META);
+ EXPECT_STREQ(ctx->data, "custom_event_plugin_http_entry");
// run evencb
event_data.type = SESSION_EVENT_CLOSING;
@@ -505,14 +505,14 @@ TEST(PLUGIN_MANAGER_TEST, plugin_manager_dispatch_HTTP_take_over)
* SESSION_EVENT_CALLBACK="custom_event_plugin_http_entry"
*/
- struct http_session_pme
+ struct http_session_ctx
{
char data[64];
int flags;
/* data */;
};
- struct http_session_pme *pme = NULL;
+ struct http_session_ctx *ctx = NULL;
char file_path[] = "./plugins_config/plugins.inf";
const char *session_name = "HTTP";
@@ -536,23 +536,23 @@ TEST(PLUGIN_MANAGER_TEST, plugin_manager_dispatch_HTTP_take_over)
// run evencb
event_data.type = SESSION_EVENT_OPENING;
plugin_manager_dispatch(plug_mgr, &event);
- pme = (struct http_session_pme *)pm_session_get_plugin_pme(&session);
- EXPECT_TRUE(pme->flags == SESSION_EVENT_OPENING);
- EXPECT_STREQ(pme->data, "custom_event_plugin_http_entry");
+ ctx = (struct http_session_ctx *)pm_session_get_plugin_ctx(&session);
+ EXPECT_TRUE(ctx->flags == SESSION_EVENT_OPENING);
+ EXPECT_STREQ(ctx->data, "custom_event_plugin_http_entry");
// http_event_plugin_entry + SESSION_EVENT_ORDPKT ==> pm_session_take_over
event_data.type = SESSION_EVENT_ORDPKT;
plugin_manager_dispatch(plug_mgr, &event);
- pme = (struct http_session_pme *)pm_session_get_plugin_pme(&session);
- EXPECT_TRUE(pme->flags == SESSION_EVENT_ORDPKT);
- EXPECT_STREQ(pme->data, "http_event_plugin_entry");
+ ctx = (struct http_session_ctx *)pm_session_get_plugin_ctx(&session);
+ EXPECT_TRUE(ctx->flags == SESSION_EVENT_ORDPKT);
+ EXPECT_STREQ(ctx->data, "http_event_plugin_entry");
// run evencb
event_data.type = SESSION_EVENT_META;
plugin_manager_dispatch(plug_mgr, &event);
- pme = (struct http_session_pme *)pm_session_get_plugin_pme(&session);
- EXPECT_TRUE(pme->flags == SESSION_EVENT_META);
- EXPECT_STREQ(pme->data, "http_event_plugin_entry");
+ ctx = (struct http_session_ctx *)pm_session_get_plugin_ctx(&session);
+ EXPECT_TRUE(ctx->flags == SESSION_EVENT_META);
+ EXPECT_STREQ(ctx->data, "http_event_plugin_entry");
// run evencb
event_data.type = SESSION_EVENT_CLOSING;
diff --git a/src/plugin_manager/test/test_plugins/plugins_library/custom_event_plugin.cpp b/src/plugin_manager/test/test_plugins/plugins_library/custom_event_plugin.cpp
index 3757bbc..178ea05 100644
--- a/src/plugin_manager/test/test_plugins/plugins_library/custom_event_plugin.cpp
+++ b/src/plugin_manager/test/test_plugins/plugins_library/custom_event_plugin.cpp
@@ -8,102 +8,102 @@
static char *g_handler = NULL;
-static void *custom_decode(const char *payload, uint16_t len, void **pme)
+static void *custom_decode(const char *payload, size_t len, void **ctx)
{
return NULL;
}
-struct tcp_session_pme
+struct tcp_session_ctx
{
char data[64];
int flags;
/* data */
};
-struct custom_session_pme
+struct custom_session_ctx
{
char data[64];
int flags;
/* data */
};
-struct http_session_pme
+struct http_session_ctx
{
char data[64];
int flags;
/* data */;
};
-static struct tcp_session_pme *tcp_session_pme_create()
+static struct tcp_session_ctx *tcp_session_ctx_create()
{
- struct tcp_session_pme *pme = (struct tcp_session_pme *)calloc(1, sizeof(struct tcp_session_pme));
- return pme;
+ struct tcp_session_ctx *ctx = (struct tcp_session_ctx *)calloc(1, sizeof(struct tcp_session_ctx));
+ return ctx;
}
-static void tcp_session_pme_destory(struct tcp_session_pme *pme)
+static void tcp_session_ctx_destory(struct tcp_session_ctx *ctx)
{
- if (pme)
+ if (ctx)
{
- free(pme);
- pme = NULL;
+ free(ctx);
+ ctx = NULL;
}
}
-static struct custom_session_pme *custom_session_pme_create()
+static struct custom_session_ctx *custom_session_ctx_create()
{
- struct custom_session_pme *pme = (struct custom_session_pme *)calloc(1, sizeof(struct custom_session_pme));
- return pme;
+ struct custom_session_ctx *ctx = (struct custom_session_ctx *)calloc(1, sizeof(struct custom_session_ctx));
+ return ctx;
}
-static void custom_session_pme_destory(struct custom_session_pme *pme)
+static void custom_session_ctx_destory(struct custom_session_ctx *ctx)
{
- if (pme)
+ if (ctx)
{
- free(pme);
- pme = NULL;
+ free(ctx);
+ ctx = NULL;
}
}
-static struct http_session_pme *http_session_pme_create()
+static struct http_session_ctx *http_session_ctx_create()
{
- struct http_session_pme *pme = (struct http_session_pme *)calloc(1, sizeof(struct http_session_pme));
- return pme;
+ struct http_session_ctx *ctx = (struct http_session_ctx *)calloc(1, sizeof(struct http_session_ctx));
+ return ctx;
}
-static void http_session_pme_destory(struct http_session_pme *pme)
+static void http_session_ctx_destory(struct http_session_ctx *ctx)
{
- if (pme)
+ if (ctx)
{
- free(pme);
- pme = NULL;
+ free(ctx);
+ ctx = NULL;
}
}
-extern "C" void custom_event_plugin_tcp_entry(const struct stellar_session *session, enum session_event_type event, struct stellar_packet *p, const char *payload, uint16_t len, void **pme)
+extern "C" void custom_event_plugin_tcp_entry(const struct stellar_session *session, enum session_event_type event, const char *payload, size_t len, void **ctx)
{
- struct tcp_session_pme **per_tcp_session_pme = (struct tcp_session_pme **)pme;
+ struct tcp_session_ctx **per_tcp_session_ctx = (struct tcp_session_ctx **)ctx;
if (event & SESSION_EVENT_OPENING)
{
- if (*per_tcp_session_pme == NULL)
+ if (*per_tcp_session_ctx == NULL)
{
- struct tcp_session_pme *cur_ctx = tcp_session_pme_create();
+ struct tcp_session_ctx *cur_ctx = tcp_session_ctx_create();
memcpy(cur_ctx->data, "custom_event_plugin_tcp_entry", strlen("custom_event_plugin_tcp_entry"));
cur_ctx->flags = SESSION_EVENT_OPENING;
- *per_tcp_session_pme = *&cur_ctx;
+ *per_tcp_session_ctx = *&cur_ctx;
}
}
if (event & SESSION_EVENT_RAWPKT)
{
- (*per_tcp_session_pme)->flags = SESSION_EVENT_RAWPKT;
+ (*per_tcp_session_ctx)->flags = SESSION_EVENT_RAWPKT;
}
if (event & SESSION_EVENT_ORDPKT)
{
- (*per_tcp_session_pme)->flags = SESSION_EVENT_ORDPKT;
+ (*per_tcp_session_ctx)->flags = SESSION_EVENT_ORDPKT;
- struct stellar_session_event_extras *info = (struct stellar_session_event_extras *)custom_decode(payload, len, pme);
+ struct stellar_session_event_extras *info = (struct stellar_session_event_extras *)custom_decode(payload, len, ctx);
struct stellar_session *new_session = session_manager_session_derive(session, "CUSTOM");
session_manager_trigger_event(new_session, SESSION_EVENT_OPENING, info);
@@ -112,86 +112,86 @@ extern "C" void custom_event_plugin_tcp_entry(const struct stellar_session *sess
if (event & SESSION_EVENT_META)
{
- (*per_tcp_session_pme)->flags = SESSION_EVENT_META;
+ (*per_tcp_session_ctx)->flags = SESSION_EVENT_META;
}
if (event & SESSION_EVENT_CLOSING)
{
- tcp_session_pme_destory(*per_tcp_session_pme);
- *per_tcp_session_pme = NULL;
+ tcp_session_ctx_destory(*per_tcp_session_ctx);
+ *per_tcp_session_ctx = NULL;
}
}
-extern "C" void custom_event_plugin_custom_entry(const struct stellar_session *session, enum session_event_type event, struct stellar_packet *p, const char *payload, uint16_t len, void **pme)
+extern "C" void custom_event_plugin_custom_entry(const struct stellar_session *session, enum session_event_type event, const char *payload, size_t len, void **ctx)
{
- struct custom_session_pme **per_custom_session_pme = (struct custom_session_pme **)pme;
+ struct custom_session_ctx **per_custom_session_ctx = (struct custom_session_ctx **)ctx;
if (event & SESSION_EVENT_OPENING)
{
- if (*per_custom_session_pme == NULL)
+ if (*per_custom_session_ctx == NULL)
{
- struct custom_session_pme *cur_ctx = custom_session_pme_create();
+ struct custom_session_ctx *cur_ctx = custom_session_ctx_create();
memcpy(cur_ctx->data, "custom_event_plugin_custom_entry", strlen("custom_event_plugin_custom_entry"));
cur_ctx->flags = SESSION_EVENT_OPENING;
- *per_custom_session_pme = *&cur_ctx;
+ *per_custom_session_ctx = *&cur_ctx;
}
}
if (event & SESSION_EVENT_RAWPKT)
{
- (*per_custom_session_pme)->flags = SESSION_EVENT_RAWPKT;
+ (*per_custom_session_ctx)->flags = SESSION_EVENT_RAWPKT;
}
if (event & SESSION_EVENT_ORDPKT)
{
- (*per_custom_session_pme)->flags = SESSION_EVENT_ORDPKT;
+ (*per_custom_session_ctx)->flags = SESSION_EVENT_ORDPKT;
}
if (event & SESSION_EVENT_META)
{
- (*per_custom_session_pme)->flags = SESSION_EVENT_META;
+ (*per_custom_session_ctx)->flags = SESSION_EVENT_META;
}
if (event & SESSION_EVENT_CLOSING)
{
- custom_session_pme_destory(*per_custom_session_pme);
- *per_custom_session_pme = NULL;
+ custom_session_ctx_destory(*per_custom_session_ctx);
+ *per_custom_session_ctx = NULL;
}
}
-extern "C" void custom_event_plugin_http_entry(const struct stellar_session *session, enum session_event_type event, struct stellar_packet *p, const char *payload, uint16_t len, void **pme)
+extern "C" void custom_event_plugin_http_entry(const struct stellar_session *session, enum session_event_type event, const char *payload, size_t len, void **ctx)
{
- struct http_session_pme **per_http_session_pme = (struct http_session_pme **)pme;
+ struct http_session_ctx **per_http_session_ctx = (struct http_session_ctx **)ctx;
if (event & SESSION_EVENT_OPENING)
{
- if (*per_http_session_pme == NULL)
+ if (*per_http_session_ctx == NULL)
{
- struct http_session_pme *cur_ctx = http_session_pme_create();
+ struct http_session_ctx *cur_ctx = http_session_ctx_create();
memcpy(cur_ctx->data, "custom_event_plugin_http_entry", strlen("custom_event_plugin_http_entry"));
cur_ctx->flags = SESSION_EVENT_OPENING;
- *per_http_session_pme = *&cur_ctx;
+ *per_http_session_ctx = *&cur_ctx;
}
}
if (event & SESSION_EVENT_RAWPKT)
{
- (*per_http_session_pme)->flags = SESSION_EVENT_RAWPKT;
+ (*per_http_session_ctx)->flags = SESSION_EVENT_RAWPKT;
}
if (event & SESSION_EVENT_ORDPKT)
{
- (*per_http_session_pme)->flags = SESSION_EVENT_ORDPKT;
+ (*per_http_session_ctx)->flags = SESSION_EVENT_ORDPKT;
}
if (event & SESSION_EVENT_META)
{
- (*per_http_session_pme)->flags = SESSION_EVENT_META;
+ (*per_http_session_ctx)->flags = SESSION_EVENT_META;
}
if (event & SESSION_EVENT_CLOSING)
{
- http_session_pme_destory(*per_http_session_pme);
- *per_http_session_pme = NULL;
+ http_session_ctx_destory(*per_http_session_ctx);
+ *per_http_session_ctx = NULL;
}
}
diff --git a/src/plugin_manager/test/test_plugins/plugins_library/http_event_plugin.cpp b/src/plugin_manager/test/test_plugins/plugins_library/http_event_plugin.cpp
index 939ef34..65b1792 100644
--- a/src/plugin_manager/test/test_plugins/plugins_library/http_event_plugin.cpp
+++ b/src/plugin_manager/test/test_plugins/plugins_library/http_event_plugin.cpp
@@ -8,40 +8,40 @@
static char *g_handler = NULL;
-struct http_session_pme
+struct http_session_ctx
{
char data[64];
int flags;
/* data */;
};
-static struct http_session_pme *http_session_pme_create()
+static struct http_session_ctx *http_session_ctx_create()
{
- struct http_session_pme *pme = (struct http_session_pme *)calloc(1, sizeof(struct http_session_pme));
- return pme;
+ struct http_session_ctx *ctx = (struct http_session_ctx *)calloc(1, sizeof(struct http_session_ctx));
+ return ctx;
}
-static void http_session_pme_destory(struct http_session_pme *pme)
+static void http_session_ctx_destory(struct http_session_ctx *ctx)
{
- if (pme)
+ if (ctx)
{
- free(pme);
- pme = NULL;
+ free(ctx);
+ ctx = NULL;
}
}
-extern "C" void http_event_plugin_entry(const struct stellar_session *session, enum session_event_type event, struct stellar_packet *p, const char *payload, uint16_t len, void **pme)
+extern "C" void http_event_plugin_entry(const struct stellar_session *session, enum session_event_type event, const char *payload, size_t len, void **ctx)
{
- struct http_session_pme **per_http_session_pme = (struct http_session_pme **)pme;
+ struct http_session_ctx **per_http_session_ctx = (struct http_session_ctx **)ctx;
if (event & SESSION_EVENT_OPENING)
{
- if (*per_http_session_pme == NULL)
+ if (*per_http_session_ctx == NULL)
{
- struct http_session_pme *cur_ctx = http_session_pme_create();
+ struct http_session_ctx *cur_ctx = http_session_ctx_create();
memcpy(cur_ctx->data, "http_event_plugin_entry", strlen("http_event_plugin_entry"));
cur_ctx->flags = SESSION_EVENT_OPENING;
- *per_http_session_pme = *&cur_ctx;
+ *per_http_session_ctx = *&cur_ctx;
}
}
@@ -52,8 +52,8 @@ extern "C" void http_event_plugin_entry(const struct stellar_session *session, e
* The plugin manager just set the skip flag and don't call this event callback next.
* Before calling pm_session_dettach_me, the current plugin must release related resources for the current session.
*/
- http_session_pme_destory(*per_http_session_pme);
- *per_http_session_pme = NULL;
+ http_session_ctx_destory(*per_http_session_ctx);
+ *per_http_session_ctx = NULL;
pm_session_dettach_me(session);
return;
}
@@ -61,20 +61,20 @@ extern "C" void http_event_plugin_entry(const struct stellar_session *session, e
if (event & SESSION_EVENT_ORDPKT)
{
// TODO
- (*per_http_session_pme)->flags = SESSION_EVENT_ORDPKT;
+ (*per_http_session_ctx)->flags = SESSION_EVENT_ORDPKT;
pm_session_take_over(session);
}
if (event & SESSION_EVENT_META)
{
// TODO
- (*per_http_session_pme)->flags = SESSION_EVENT_META;
+ (*per_http_session_ctx)->flags = SESSION_EVENT_META;
}
if (event & SESSION_EVENT_CLOSING)
{
- http_session_pme_destory(*per_http_session_pme);
- *per_http_session_pme = NULL;
+ http_session_ctx_destory(*per_http_session_ctx);
+ *per_http_session_ctx = NULL;
}
}
diff --git a/src/protocol_decoder/http/http.cpp b/src/protocol_decoder/http/http.cpp
index cb8f0d9..14e431c 100644
--- a/src/protocol_decoder/http/http.cpp
+++ b/src/protocol_decoder/http/http.cpp
@@ -2,10 +2,10 @@
#include "sdk/include/session.h"
-void http_decoder(const struct stellar_session *s, enum session_event_type event, struct stellar_packet *p, const char *payload, uint16_t len, void **pme)
+void http_decoder(const struct stellar_session *session, enum session_event_type event, const char *payload, size_t len, void **ctx)
{
struct stellar_session_event_extras *info = NULL;
- struct stellar_session *new_session = session_manager_session_derive(s, "HTTP");
+ struct stellar_session *new_session = session_manager_session_derive(session, "HTTP");
session_manager_trigger_event(new_session, SESSION_EVENT_OPENING, info);
session_manager_trigger_event(new_session, SESSION_EVENT_META, info);