From 0f7468b9946e29e19cd8a6f8c63e6949e29b9b02 Mon Sep 17 00:00:00 2001 From: luwenpeng Date: Mon, 8 Aug 2022 14:19:32 +0800 Subject: [PATCH] Refactored pm_session_dettach_others to pm_session_take_over --- readme.md | 15 ++-- sdk/example/custom_event_plugin.cpp | 17 ---- sdk/example/http_event_plugin.cpp | 12 +-- .../custom_event_plugin.inf | 1 - .../http_event_plugin/http_event_plugin.inf | 1 - sdk/include/http.h | 3 +- sdk/include/plugin.h | 15 +++- sdk/include/session.h | 6 -- src/main.cpp | 2 +- src/plugin_manager/plugin_manager.cpp | 89 ++++++++++++------- src/plugin_manager/plugin_manager.h | 2 +- src/plugin_manager/plugin_manager_config.cpp | 8 -- src/plugin_manager/plugin_manager_config.h | 1 - src/plugin_manager/plugin_manager_module.cpp | 12 +-- .../test/gtest_plugin_manager.cpp | 8 +- .../custom_event_plugin.inf | 1 - .../http_event_plugin/http_event_plugin.inf | 1 - .../plugins_library/custom_event_plugin.cpp | 24 ----- .../plugins_library/http_event_plugin.cpp | 12 +-- src/protocol_decoder/http/http.cpp | 4 - 20 files changed, 91 insertions(+), 143 deletions(-) diff --git a/readme.md b/readme.md index 5b375b8..b6d1023 100644 --- a/readme.md +++ b/readme.md @@ -42,17 +42,20 @@ Plugin Management APIs ``` /* - * The plugin manager just set the skip flag and don't call this event callback next. + * The pm_session_dettach_me just sets the flag to disable this plugin and no longer call this event callback. * Before calling pm_session_dettach_me, the current plugin must release related resources for the current session. */ pm_session_dettach_me(session); /* - * The plugin manager uses ERROR_EVENT_DETTACH to call other plugin error callbacks, - * and when the plugin error callback handler is called, - * the error callback handler must release the relevant resources for the current session. + * The current plugin takes over the current session, the pm_session_take_over setting flag disables other plugins, + * and the current session does not call other plugins except for the SESSION_EVENT_CLOSING event. + * + * The current plugin may be taken over while the session is open (SESSION_EVENT_OPENING), + * other plugins event_cb is not called, the session pme on other plugins is NULL, + * When the session is closed (SESSION_EVENT_CLOSING), call other plugin even_cb to destroy pme must check if pme is NULL. */ -pm_session_dettach_others(session); +pm_session_take_over(session); ``` ## Session Manager @@ -82,7 +85,7 @@ plugin_entry(session, pme) ret=check_security_policy(session); if(ret==INTERCEPT) { - pm_session_dettach_others(session); + pm_session_take_over(session); } else if(ret==RATE_LIMIT) { diff --git a/sdk/example/custom_event_plugin.cpp b/sdk/example/custom_event_plugin.cpp index dc56c0d..8034d99 100644 --- a/sdk/example/custom_event_plugin.cpp +++ b/sdk/example/custom_event_plugin.cpp @@ -56,23 +56,6 @@ static void custom_session_pme_destory(struct custom_session_pme *pme) } } -extern "C" void custom_event_plugin_error(const struct stellar_session *session, enum error_event_type event, void **pme) -{ - if (strcmp(stellar_session_get_name(session), "TCP") == 0) - { - struct tcp_session_pme **per_tcp_session_pme = (struct tcp_session_pme **)pme; - printf("RUN custom_event_plugin_error, session_name: 'TCP', error_event_type: %d, pme->data: %s\n", event, (*per_tcp_session_pme) == NULL ? "NULL" : (*per_tcp_session_pme)->data); - tcp_session_pme_destory(*per_tcp_session_pme); - } - - if (strcmp(stellar_session_get_name(session), "CUSTOM") == 0) - { - struct custom_session_pme **per_custom_session_pme = (struct custom_session_pme **)pme; - printf("RUN custom_event_plugin_error, session_name: 'CUSTOM', error_event_type: %d, pme->data: %s\n", event, (*per_custom_session_pme) == NULL ? "NULL" : (*per_custom_session_pme)->data); - custom_session_pme_destory(*per_custom_session_pme); - } -} - 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) { struct tcp_session_pme **per_tcp_session_pme = (struct tcp_session_pme **)pme; diff --git a/sdk/example/http_event_plugin.cpp b/sdk/example/http_event_plugin.cpp index 4f795d3..ef1e761 100644 --- a/sdk/example/http_event_plugin.cpp +++ b/sdk/example/http_event_plugin.cpp @@ -29,16 +29,6 @@ static void http_session_pme_destory(struct http_session_pme *pme) } } -extern "C" void http_event_plugin_error(const struct stellar_session *session, enum error_event_type event, void **pme) -{ - if (strcmp(stellar_session_get_name(session), "HTTP") == 0) - { - struct http_session_pme **per_http_session_pme = (struct http_session_pme **)pme; - printf("RUN http_event_plugin_error, session_name: 'HTTP', error_event_type: %d, pme->data: %s\n", event, (*per_http_session_pme) == NULL ? "NULL" : (*per_http_session_pme)->data); - http_session_pme_destory(*per_http_session_pme); - } -} - 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) { struct http_session_pme **per_http_session_pme = (struct http_session_pme **)pme; @@ -64,7 +54,7 @@ extern "C" void http_event_plugin_entry(const struct stellar_session *session, e if (event & SESSION_EVENT_ORDPKT) { // TODO - pm_session_dettach_others(session); + pm_session_take_over(session); } if (event & SESSION_EVENT_META) diff --git a/sdk/example/plugins/custom_event_plugin/custom_event_plugin.inf b/sdk/example/plugins/custom_event_plugin/custom_event_plugin.inf index 3718be0..08c84a3 100644 --- a/sdk/example/plugins/custom_event_plugin/custom_event_plugin.inf +++ b/sdk/example/plugins/custom_event_plugin/custom_event_plugin.inf @@ -1,7 +1,6 @@ [PLUGINFO] INIT_FUNC="custom_event_plugin_init" EXIT_FUNC="custom_event_plugin_exit" -ERROR_FUNC="custom_event_plugin_error" LIBRARY_PATH="./plugins/custom_event_plugin/custom_event_plugin.so" # Support SESSION_EVENT_TYPE: "SESSION_EVENT_OPENING", "SESSION_EVENT_RAWPKT", "SESSION_EVENT_ORDPKT", "SESSION_EVENT_META", "SESSION_EVENT_CLOSING", "SESSION_EVENT_ALL" diff --git a/sdk/example/plugins/http_event_plugin/http_event_plugin.inf b/sdk/example/plugins/http_event_plugin/http_event_plugin.inf index e0f2704..a58a405 100644 --- a/sdk/example/plugins/http_event_plugin/http_event_plugin.inf +++ b/sdk/example/plugins/http_event_plugin/http_event_plugin.inf @@ -1,7 +1,6 @@ [PLUGINFO] INIT_FUNC="http_event_plugin_init" EXIT_FUNC="http_event_plugin_exit" -ERROR_FUNC="http_event_plugin_error" LIBRARY_PATH="./plugins/http_event_plugin/http_event_plugin.so" # Support SESSION_EVENT_TYPE: "SESSION_EVENT_OPENING", "SESSION_EVENT_RAWPKT", "SESSION_EVENT_ORDPKT", "SESSION_EVENT_META", "SESSION_EVENT_CLOSING", "SESSION_EVENT_ALL" diff --git a/sdk/include/http.h b/sdk/include/http.h index 4db1126..6250055 100644 --- a/sdk/include/http.h +++ b/sdk/include/http.h @@ -2,5 +2,4 @@ #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_error_cb(const struct stellar_session *s, enum error_event_type event, void **pme); \ No newline at end of file +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); \ No newline at end of file diff --git a/sdk/include/plugin.h b/sdk/include/plugin.h index 0d6c346..301363a 100644 --- a/sdk/include/plugin.h +++ b/sdk/include/plugin.h @@ -15,8 +15,21 @@ typedef void plugin_exit_callback(void); * Public API For Plugin ******************************************************************************/ +/* + * The pm_session_dettach_me just sets the flag to disable this plugin and no longer call this event callback. + * Before calling pm_session_dettach_me, the current plugin must release related resources for the current session. + */ void pm_session_dettach_me(const struct stellar_session *session); -void pm_session_dettach_others(const struct stellar_session *session); + +/* + * The current plugin takes over the current session, the pm_session_take_over setting flag disables other plugins, + * and the current session does not call other plugins except for the SESSION_EVENT_CLOSING event. + * + * The current plugin may be taken over while the session is open (SESSION_EVENT_OPENING), + * other plugins event_cb is not called, the session pme on other plugins is NULL, + * When the session is closed (SESSION_EVENT_CLOSING), call other plugin even_cb to destroy pme must check if pme is NULL. + */ +void pm_session_take_over(const struct stellar_session *session); #ifdef __cpluscplus } diff --git a/sdk/include/session.h b/sdk/include/session.h index 8c4b25f..8ce3d26 100644 --- a/sdk/include/session.h +++ b/sdk/include/session.h @@ -40,14 +40,8 @@ enum session_event_type SESSION_EVENT_ALL = (0x01 << 1 | 0x01 << 2 | 0x01 << 3 | 0x01 << 4 | 0x01 << 5), }; -enum error_event_type -{ - ERROR_EVENT_DETTACH = (0x1 << 10), -}; - struct stellar_session_event_extras; -typedef void(fn_session_error_callback)(const struct stellar_session *s, enum error_event_type event, void **pme); 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); diff --git a/src/main.cpp b/src/main.cpp index 2b1d541..75f803c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -59,7 +59,7 @@ int main(int argc, char ** argv) struct plugin_manager *plug_mgr = plugin_manager_create(); // register build-in plugin - plugin_manager_register(plug_mgr, "HTTP", SESSION_EVENT_ALL, http_decoder, http_error_cb); + plugin_manager_register(plug_mgr, "HTTP", SESSION_EVENT_ALL, http_decoder); // load external plugins char file_path[] = "./plugs/plugins.inf"; diff --git a/src/plugin_manager/plugin_manager.cpp b/src/plugin_manager/plugin_manager.cpp index 95f63b4..d90122c 100644 --- a/src/plugin_manager/plugin_manager.cpp +++ b/src/plugin_manager/plugin_manager.cpp @@ -10,14 +10,20 @@ * CallBack Runtime (For Per Session) ******************************************************************************/ +enum plugin_status +{ + PLUGIN_STATUS_NORMAL = 0x00, + PLUGIN_STATUS_DETTACH_ME = 0x01, + PLUGIN_STATUS_TAKEN_OVER = 0x02, // Noitce: this is taken over not take over +}; + struct callback_runtime { - int skip; + enum plugin_status status; void *cb_args; enum session_event_type event; fn_session_event_callback *event_cb; - fn_session_error_callback *error_cb; }; struct session_plugin_ctx @@ -35,7 +41,6 @@ struct callback_static { enum session_event_type event; fn_session_event_callback *event_cb; - fn_session_error_callback *error_cb; }; struct plugin_manager_eventcb @@ -90,10 +95,9 @@ static struct session_plugin_ctx *plugin_manager_create_plugin_ctx(struct plugin for (int i = 0; i < plug_ctx->callback_num; i++) { - plug_ctx->callbacks[i].skip = 0; + plug_ctx->callbacks[i].status = PLUGIN_STATUS_NORMAL; plug_ctx->callbacks[i].event = elem->callbacks[i].event; plug_ctx->callbacks[i].event_cb = elem->callbacks[i].event_cb; - plug_ctx->callbacks[i].error_cb = elem->callbacks[i].error_cb; plug_ctx->callbacks[i].cb_args = NULL; } @@ -336,7 +340,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, fn_session_error_callback *error_cb) +int plugin_manager_register(struct plugin_manager *plug_mgr, const char *session_name, enum session_event_type event, fn_session_event_callback *event_cb) { if (strlen(session_name) <= 0) { @@ -356,12 +360,6 @@ int plugin_manager_register(struct plugin_manager *plug_mgr, const char *session return -1; } - if (error_cb == NULL) - { - plugin_manager_log(ERROR, "invalid parameter, the error callback corresponding to the session name '%s' is null", session_name); - return -1; - } - struct plugin_manager_eventcb *elem; HASH_FIND_STR(plug_mgr->evcb_htable, session_name, elem); // session_name exists, add a new cb to the end of the callbacks dynamic array @@ -371,7 +369,6 @@ int plugin_manager_register(struct plugin_manager *plug_mgr, const char *session elem->callbacks[elem->callback_num].event = event; elem->callbacks[elem->callback_num].event_cb = event_cb; - elem->callbacks[elem->callback_num].error_cb = error_cb; elem->callback_num++; } @@ -385,7 +382,6 @@ int plugin_manager_register(struct plugin_manager *plug_mgr, const char *session elem->callbacks[elem->callback_num].event = event; elem->callbacks[elem->callback_num].event_cb = event_cb; - elem->callbacks[elem->callback_num].error_cb = error_cb; elem->callback_num++; @@ -431,17 +427,43 @@ void plugin_manager_dispatch(struct plugin_manager *plug_mgr, struct stellar_eve for (int i = 0; i < plug_ctx->callback_num; i++) { struct callback_runtime *runtime = &plug_ctx->callbacks[i]; - if (runtime->skip == 1) + + if (runtime->status == PLUGIN_STATUS_DETTACH_ME) { - plugin_manager_log(DEBUG, "dispatch, skip event_cb: %p, session: %s, event: (%d, %s)", runtime->event_cb, session_name, event_type, event_str_buffer); + plugin_manager_log(DEBUG, "dispatch, skip event_cb: %p, plugin status: 'dettach me', session: %s, event: (%d, %s)", runtime->event_cb, session_name, event_type, event_str_buffer); continue; } - - if (runtime->event & event_type) + else if (runtime->status == PLUGIN_STATUS_TAKEN_OVER) { - plug_ctx->callback_index = i; - plugin_manager_log(DEBUG, "dispatch, run event_cb: %p, 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); + /* + * This plugin may be taken over when the session is open (SESSION_EVENT_OPENING), + * and the pme may be NULL when event_cb() is run to free memory with the session is closed (SESSION_EVENT_CLOSING). + * So, The plugin must check whether the pme is NULL before freeing memory. + */ + if (event_type & SESSION_EVENT_CLOSING) + { + 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); + continue; + } + else + { + plugin_manager_log(DEBUG, "dispatch, skip event_cb: %p, plugin status: 'taken over', session: %s, event: (%d, %s)", runtime->event_cb, session_name, event_type, event_str_buffer); + } + } + else if (runtime->status == PLUGIN_STATUS_NORMAL) + { + if (runtime->event & event_type) + { + 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); + } + else + { + plugin_manager_log(DEBUG, "dispatch, skip event_cb: %p, plugin status: 'normal', session: %s, event: (%d, %s)", runtime->event_cb, session_name, event_type, event_str_buffer); + } } } } @@ -462,21 +484,29 @@ void plugin_manager_dispatch(struct plugin_manager *plug_mgr, struct stellar_eve * Public API For Plugin ******************************************************************************/ +/* + * pm_session_dettach_me just sets the flag to disable this plugin and no longer call this event callback. + * Before calling pm_session_dettach_me, the current plugin must release related resources for the current session. + */ void pm_session_dettach_me(const struct stellar_session *session) { struct session_plugin_ctx *plugin_ctx = stellar_session_get_plugin_ctx(session); assert(plugin_ctx); struct callback_runtime *runtime_me = &plugin_ctx->callbacks[plugin_ctx->callback_index]; - /* - * Just set the skip flag and don't call this event callback next. - * The plugin is closed before calling pm_session_dettach_me. - */ - runtime_me->skip = 1; + runtime_me->status = PLUGIN_STATUS_DETTACH_ME; plugin_manager_log(DEBUG, "%p dettach me, disable event_cb: %p, session: %s", runtime_me->event_cb, runtime_me->event_cb, stellar_session_get_name(session)); } -void pm_session_dettach_others(const struct stellar_session *session) +/* + * The current plugin takes over the current session, the pm_session_take_over setting flag disables other plugins, + * and the current session does not call other plugins except for the SESSION_EVENT_CLOSING event. + * + * The current plugin may be taken over while the session is open (SESSION_EVENT_OPENING), + * other plugins event_cb is not called, the session pme on other plugins is NULL, + * When the session is closed (SESSION_EVENT_CLOSING), call other plugin even_cb to destroy pme must check if pme is NULL + */ +void pm_session_take_over(const struct stellar_session *session) { struct session_plugin_ctx *plugin_ctx = stellar_session_get_plugin_ctx(session); assert(plugin_ctx); @@ -487,9 +517,8 @@ void pm_session_dettach_others(const struct stellar_session *session) if (i != plugin_ctx->callback_index) { struct callback_runtime *runtime_other = &plugin_ctx->callbacks[i]; - runtime_other->skip = 1; - plugin_manager_log(DEBUG, "%p dettach others, run error_cb: %p, session: %s", runtime_me->event_cb, runtime_other->error_cb, stellar_session_get_name(session)); - runtime_other->error_cb(session, ERROR_EVENT_DETTACH, &runtime_other->cb_args); + runtime_other->status = PLUGIN_STATUS_TAKEN_OVER; + plugin_manager_log(DEBUG, "%p take over, disable event_cb: %p, session: %s", runtime_me->event_cb, runtime_other->event_cb, stellar_session_get_name(session)); } } } diff --git a/src/plugin_manager/plugin_manager.h b/src/plugin_manager/plugin_manager.h index 2827483..b23e874 100644 --- a/src/plugin_manager/plugin_manager.h +++ b/src/plugin_manager/plugin_manager.h @@ -16,7 +16,7 @@ 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, fn_session_error_callback *error_cb); +int plugin_manager_register(struct plugin_manager *plug_mgr, const char *session_name, enum session_event_type event, fn_session_event_callback *event_cb); void plugin_manager_dispatch(struct plugin_manager *plug_mgr, struct stellar_event *event); // only use for gtest diff --git a/src/plugin_manager/plugin_manager_config.cpp b/src/plugin_manager/plugin_manager_config.cpp index 89dd39b..1772900 100644 --- a/src/plugin_manager/plugin_manager_config.cpp +++ b/src/plugin_manager/plugin_manager_config.cpp @@ -62,11 +62,6 @@ static int toml_parse_plugin_section(toml_table_t *root, struct plugin_manager_c return -1; } - if (toml_parse_string(plugin_section, "ERROR_FUNC", file, &config->plugin_section.error_func_name) == -1) - { - return -1; - } - if (toml_parse_string(plugin_section, "LIBRARY_PATH", file, &config->plugin_section.lib_path) == -1) { return -1; @@ -174,7 +169,6 @@ struct plugin_manager_config *plugin_mangager_config_create() config->session_section = NULL; config->plugin_section.init_func_name = NULL; config->plugin_section.exit_func_name = NULL; - config->plugin_section.error_func_name = NULL; config->plugin_section.lib_path = NULL; return config; @@ -188,7 +182,6 @@ void plugin_mangager_config_destory(struct plugin_manager_config *config) safe_free(config->plugin_section.init_func_name); safe_free(config->plugin_section.exit_func_name); - safe_free(config->plugin_section.error_func_name); safe_free(config->plugin_section.lib_path); if (config->session_section) @@ -213,7 +206,6 @@ void plugin_mangager_config_dump(struct plugin_manager_config *config) plugin_manager_log(DEBUG, "[CONFIG_FILE] : %s", config->file_path); plugin_manager_log(DEBUG, "[PLUGINFO]->INIT_FUNC : %s", config->plugin_section.init_func_name); plugin_manager_log(DEBUG, "[PLUGINFO]->EXIT_FUNC : %s", config->plugin_section.exit_func_name); - plugin_manager_log(DEBUG, "[PLUGINFO]->ERROR_FUNC : %s", config->plugin_section.error_func_name); plugin_manager_log(DEBUG, "[PLUGINFO]->LIBRARY_PATH : %s", config->plugin_section.lib_path); if (config->session_section) diff --git a/src/plugin_manager/plugin_manager_config.h b/src/plugin_manager/plugin_manager_config.h index 16a62ba..e028a15 100644 --- a/src/plugin_manager/plugin_manager_config.h +++ b/src/plugin_manager/plugin_manager_config.h @@ -20,7 +20,6 @@ struct plugin_section_config { char *init_func_name; char *exit_func_name; - char *error_func_name; char *lib_path; }; diff --git a/src/plugin_manager/plugin_manager_module.cpp b/src/plugin_manager/plugin_manager_module.cpp index 2ff7179..7756da5 100644 --- a/src/plugin_manager/plugin_manager_module.cpp +++ b/src/plugin_manager/plugin_manager_module.cpp @@ -20,7 +20,6 @@ struct plugin_manager_module plugin_init_callback *init_cb_ptr; plugin_exit_callback *exit_cb_ptr; - fn_session_error_callback *error_cb_ptr; struct plugin_manager_module_evcb *evcbs; int evcbs_num; @@ -85,14 +84,6 @@ struct plugin_manager_module *plugin_manager_module_open(struct plugin_manager_c goto err; } - module->error_cb_ptr = (fn_session_error_callback *)(dlsym(module->dl_handle, config->plugin_section.error_func_name)); - if (module->error_cb_ptr == NULL) - { - plugin_manager_log(ERROR, "can't find symbol name of '%s' in dynamic library %s, %s", - config->plugin_section.error_func_name, module->lib_path, dlerror()); - goto err; - } - if (config->session_section) { module->evcbs = safe_alloc(struct plugin_manager_module_evcb, config->session_section_num); @@ -170,7 +161,7 @@ int plugin_manager_module_register(struct plugin_manager *plug_mgr, struct plugi { struct plugin_manager_module_evcb *event_cb = &module->evcbs[i]; - if (plugin_manager_register(plug_mgr, event_cb->session_name, event_cb->event, event_cb->event_cb_ptr, module->error_cb_ptr) == -1) + if (plugin_manager_register(plug_mgr, event_cb->session_name, event_cb->event, event_cb->event_cb_ptr) == -1) { plugin_manager_log(ERROR, "dynamic library '%s' failed to register the event callback function of session '%s'", module->lib_path, event_cb->session_name); return -1; @@ -188,7 +179,6 @@ void plugin_manager_module_dump(struct plugin_manager_module *module, struct plu plugin_manager_log(DEBUG, "[LIBRARY] : %s, %p", config->plugin_section.lib_path, module->dl_handle); plugin_manager_log(DEBUG, "[INIT_FUNC] : %s, %p", config->plugin_section.init_func_name, module->init_cb_ptr); plugin_manager_log(DEBUG, "[EXIT_FUNC] : %s, %p", config->plugin_section.exit_func_name, module->exit_cb_ptr); - plugin_manager_log(DEBUG, "[ERROR_FUNC] : %s, %p", config->plugin_section.error_func_name, module->error_cb_ptr); for (int i = 0; i < module->evcbs_num; i++) { diff --git a/src/plugin_manager/test/gtest_plugin_manager.cpp b/src/plugin_manager/test/gtest_plugin_manager.cpp index dbe267f..6afd126 100644 --- a/src/plugin_manager/test/gtest_plugin_manager.cpp +++ b/src/plugin_manager/test/gtest_plugin_manager.cpp @@ -144,7 +144,6 @@ TEST(PLUGIN_MANAGER_TEST, plugin_mangager_config_HTTP) EXPECT_STREQ(config->file_path, "./plugins_config/http_event_plugin/http_event_plugin.inf"); EXPECT_STREQ(config->plugin_section.init_func_name, "http_event_plugin_init"); EXPECT_STREQ(config->plugin_section.exit_func_name, "http_event_plugin_exit"); - EXPECT_STREQ(config->plugin_section.error_func_name, "http_event_plugin_error"); EXPECT_STREQ(config->plugin_section.lib_path, "./test_plugins/plugins_library/http_event_plugin_test.so"); EXPECT_TRUE(config->session_section_num == 1); @@ -170,7 +169,6 @@ TEST(PLUGIN_MANAGER_TEST, plugin_mangager_config_CUSTOM) EXPECT_STREQ(config->file_path, "./plugins_config/custom_event_plugin/custom_event_plugin.inf"); EXPECT_STREQ(config->plugin_section.init_func_name, "custom_event_plugin_init"); EXPECT_STREQ(config->plugin_section.exit_func_name, "custom_event_plugin_exit"); - EXPECT_STREQ(config->plugin_section.error_func_name, "custom_event_plugin_error"); EXPECT_STREQ(config->plugin_section.lib_path, "./test_plugins/plugins_library/custom_event_plugin_test.so"); EXPECT_TRUE(config->session_section_num == 3); @@ -494,8 +492,8 @@ TEST(PLUGIN_MANAGER_TEST, plugin_manager_dispatch_HTTP_dettach_me) #endif #if 1 -// http_event_plugin_entry + SESSION_EVENT_ORDPKT ==> pm_session_dettach_others -TEST(PLUGIN_MANAGER_TEST, plugin_manager_dispatch_HTTP_dettach_other) +// http_event_plugin_entry + SESSION_EVENT_ORDPKT ==> pm_session_take_over +TEST(PLUGIN_MANAGER_TEST, plugin_manager_dispatch_HTTP_take_over) { /* * [SESSION_NAME.HTTP] @@ -542,7 +540,7 @@ TEST(PLUGIN_MANAGER_TEST, plugin_manager_dispatch_HTTP_dettach_other) EXPECT_TRUE(pme->flags == SESSION_EVENT_OPENING); EXPECT_STREQ(pme->data, "custom_event_plugin_http_entry"); - // http_event_plugin_entry + SESSION_EVENT_ORDPKT ==> pm_session_dettach_others + // 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); diff --git a/src/plugin_manager/test/test_plugins/plugins_config/custom_event_plugin/custom_event_plugin.inf b/src/plugin_manager/test/test_plugins/plugins_config/custom_event_plugin/custom_event_plugin.inf index 5df88aa..d3ff370 100644 --- a/src/plugin_manager/test/test_plugins/plugins_config/custom_event_plugin/custom_event_plugin.inf +++ b/src/plugin_manager/test/test_plugins/plugins_config/custom_event_plugin/custom_event_plugin.inf @@ -1,7 +1,6 @@ [PLUGINFO] INIT_FUNC="custom_event_plugin_init" EXIT_FUNC="custom_event_plugin_exit" -ERROR_FUNC="custom_event_plugin_error" LIBRARY_PATH="./test_plugins/plugins_library/custom_event_plugin_test.so" # Support SESSION_EVENT_TYPE: "SESSION_EVENT_OPENING", "SESSION_EVENT_RAWPKT", "SESSION_EVENT_ORDPKT", "SESSION_EVENT_META", "SESSION_EVENT_CLOSING", "SESSION_EVENT_ALL" diff --git a/src/plugin_manager/test/test_plugins/plugins_config/http_event_plugin/http_event_plugin.inf b/src/plugin_manager/test/test_plugins/plugins_config/http_event_plugin/http_event_plugin.inf index cf0d16b..1dd124b 100644 --- a/src/plugin_manager/test/test_plugins/plugins_config/http_event_plugin/http_event_plugin.inf +++ b/src/plugin_manager/test/test_plugins/plugins_config/http_event_plugin/http_event_plugin.inf @@ -1,7 +1,6 @@ [PLUGINFO] INIT_FUNC="http_event_plugin_init" EXIT_FUNC="http_event_plugin_exit" -ERROR_FUNC="http_event_plugin_error" LIBRARY_PATH="./test_plugins/plugins_library/http_event_plugin_test.so" # Support SESSION_EVENT_TYPE: "SESSION_EVENT_OPENING", "SESSION_EVENT_RAWPKT", "SESSION_EVENT_ORDPKT", "SESSION_EVENT_META", "SESSION_EVENT_CLOSING", "SESSION_EVENT_ALL" 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 dc34f1e..3757bbc 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 @@ -79,30 +79,6 @@ static void http_session_pme_destory(struct http_session_pme *pme) } } -extern "C" void custom_event_plugin_error(const struct stellar_session *session, enum error_event_type event, void **pme) -{ - if (strcmp(stellar_session_get_name(session), "TCP") == 0) - { - struct tcp_session_pme **per_tcp_session_pme = (struct tcp_session_pme **)pme; - printf("RUN custom_event_plugin_error, session_name: 'TCP', error_event_type: %d, pme->data: %s\n", event, (*per_tcp_session_pme) == NULL ? "NULL" : (*per_tcp_session_pme)->data); - tcp_session_pme_destory(*per_tcp_session_pme); - } - - if (strcmp(stellar_session_get_name(session), "CUSTOM") == 0) - { - struct custom_session_pme **per_custom_session_pme = (struct custom_session_pme **)pme; - printf("RUN custom_event_plugin_error, session_name: 'CUSTOM', error_event_type: %d, pme->data: %s\n", event, (*per_custom_session_pme) == NULL ? "NULL" : (*per_custom_session_pme)->data); - custom_session_pme_destory(*per_custom_session_pme); - } - - if (strcmp(stellar_session_get_name(session), "HTTP") == 0) - { - struct http_session_pme **per_http_session_pme = (struct http_session_pme **)pme; - printf("RUN custom_event_plugin_error, session_name: 'HTTP', error_event_type: %d, pme->data: %s\n", event, (*per_http_session_pme) == NULL ? "NULL" : (*per_http_session_pme)->data); - http_session_pme_destory(*per_http_session_pme); - } -} - 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) { struct tcp_session_pme **per_tcp_session_pme = (struct tcp_session_pme **)pme; 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 487d6bf..939ef34 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 @@ -30,16 +30,6 @@ static void http_session_pme_destory(struct http_session_pme *pme) } } -extern "C" void http_event_plugin_error(const struct stellar_session *session, enum error_event_type event, void **pme) -{ - if (strcmp(stellar_session_get_name(session), "HTTP") == 0) - { - struct http_session_pme **per_http_session_pme = (struct http_session_pme **)pme; - printf("RUN http_event_plugin_error, session_name: 'HTTP', error_event_type: %d, pme->data: %s\n", event, (*per_http_session_pme) == NULL ? "NULL" : (*per_http_session_pme)->data); - http_session_pme_destory(*per_http_session_pme); - } -} - 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) { struct http_session_pme **per_http_session_pme = (struct http_session_pme **)pme; @@ -72,7 +62,7 @@ extern "C" void http_event_plugin_entry(const struct stellar_session *session, e { // TODO (*per_http_session_pme)->flags = SESSION_EVENT_ORDPKT; - pm_session_dettach_others(session); + pm_session_take_over(session); } if (event & SESSION_EVENT_META) diff --git a/src/protocol_decoder/http/http.cpp b/src/protocol_decoder/http/http.cpp index c7e3e79..cb8f0d9 100644 --- a/src/protocol_decoder/http/http.cpp +++ b/src/protocol_decoder/http/http.cpp @@ -9,8 +9,4 @@ void http_decoder(const struct stellar_session *s, enum session_event_type event session_manager_trigger_event(new_session, SESSION_EVENT_OPENING, info); session_manager_trigger_event(new_session, SESSION_EVENT_META, info); -} - -void http_error_cb(const struct stellar_session *s, enum error_event_type event, void **pme) -{ } \ No newline at end of file