summaryrefslogtreecommitdiff
path: root/src/plugin_manager/plugin_manager_config.cpp
diff options
context:
space:
mode:
authorluwenpeng <[email protected]>2022-08-03 19:46:43 +0800
committerluwenpeng <[email protected]>2022-08-04 17:30:03 +0800
commit5c790085ebbf5812a34f6fcbc9c2e4398a723667 (patch)
treee3c9f40624e136dc292d7cae7d893c89fd28f2f5 /src/plugin_manager/plugin_manager_config.cpp
parent50111e7cd09ff83ecbd53017d0edf6d33b84a801 (diff)
Plugin management support pm_session_dettach_me and pm_session_dettach_others
Add test cases for pm_session_dettach_me and pm_session_dettach_others
Diffstat (limited to 'src/plugin_manager/plugin_manager_config.cpp')
-rw-r--r--src/plugin_manager/plugin_manager_config.cpp115
1 files changed, 21 insertions, 94 deletions
diff --git a/src/plugin_manager/plugin_manager_config.cpp b/src/plugin_manager/plugin_manager_config.cpp
index f36512c..89dd39b 100644
--- a/src/plugin_manager/plugin_manager_config.cpp
+++ b/src/plugin_manager/plugin_manager_config.cpp
@@ -1,64 +1,9 @@
#include <errno.h>
-#include <stdlib.h>
#include <string.h>
#include "toml/toml.h"
-#include "sdk/include/session.h"
-#include "plugin_manager_util.h"
-#include "plugin_manager_config.h"
-
-struct event_type_map
-{
- const char *type_str;
- enum session_event_type type_int;
-};
-
-static struct event_type_map evtype_map[] =
- {
- {"SESSION_EVENT_OPENING", SESSION_EVENT_OPENING},
- {"SESSION_EVENT_RAWPKT", SESSION_EVENT_RAWPKT},
- {"SESSION_EVENT_ORDPKT", SESSION_EVENT_ORDPKT},
- {"SESSION_EVENT_META", SESSION_EVENT_META},
- {"SESSION_EVENT_CLOSING", SESSION_EVENT_CLOSING},
- {"SESSION_EVENT_ALL", SESSION_EVENT_ALL},
-};
-
-/******************************************************************************
- * Private API (For Event Type)
- ******************************************************************************/
-
-static enum session_event_type event_type_str2int(const char *evtype_str)
-{
- int num = sizeof(evtype_map) / sizeof(evtype_map[0]);
-
- for (int i = 0; i < num; i++)
- {
- if (strcmp(evtype_str, evtype_map[i].type_str) == 0)
- {
- return evtype_map[i].type_int;
- }
- }
-
- return SESSION_EVENT_UNKNOWN;
-}
-static void event_type_int2str(enum session_event_type evtype_int, char *buffer, int size)
-{
- int used = 0;
- int num = sizeof(evtype_map) / sizeof(evtype_map[0]);
-
- for (int i = 0; i < num; i++)
- {
- if (evtype_map[i].type_int & evtype_int)
- {
- if (evtype_map[i].type_int == SESSION_EVENT_ALL && evtype_int != SESSION_EVENT_ALL)
- {
- continue;
- }
- used += snprintf(buffer + used, size - used, "%s ", evtype_map[i].type_str);
- }
- }
-}
+#include "plugin_manager_config.h"
/******************************************************************************
* Private API (For Parse)
@@ -117,6 +62,11 @@ 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;
@@ -193,7 +143,7 @@ static int toml_parse_session_section(toml_table_t *root, struct plugin_manager_
return -1;
}
- type_int = event_type_str2int(type_str.u.s);
+ type_int = session_event_type_str2int(type_str.u.s);
if (type_int == SESSION_EVENT_UNKNOWN)
{
plugin_manager_log(ERROR, "invalid value '%s' for 'SESSION_EVENT_TYPE' configuration item in '[SESSION_NAME.%s]' section of %s", type_str.u.s, session_name, file);
@@ -219,12 +169,12 @@ struct plugin_manager_config *plugin_mangager_config_create()
{
struct plugin_manager_config *config = safe_alloc(struct plugin_manager_config, 1);
- config->prefix_path = NULL;
config->file_path = NULL;
config->session_section_num = 0;
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;
@@ -234,11 +184,11 @@ void plugin_mangager_config_destory(struct plugin_manager_config *config)
{
if (config)
{
- safe_free(config->prefix_path);
safe_free(config->file_path);
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)
@@ -260,10 +210,10 @@ void plugin_mangager_config_dump(struct plugin_manager_config *config)
{
if (config)
{
- plugin_manager_log(DEBUG, "[CONFIG_PREFIX] : %s", config->prefix_path);
- 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, "[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)
@@ -272,29 +222,26 @@ void plugin_mangager_config_dump(struct plugin_manager_config *config)
{
char tmp_buffer[1024] = {0};
struct session_section_config *temp = &config->session_section[i];
- event_type_int2str(temp->event, tmp_buffer, 1024);
- plugin_manager_log(DEBUG, "[SESSION_NAME.%s]->SESSION_EVENT_TYPE : %d, %s", temp->session_name, temp->event, tmp_buffer);
+ session_event_type_int2str(temp->event, tmp_buffer, 1024);
+ plugin_manager_log(DEBUG, "[SESSION_NAME.%s]->SESSION_EVENT_TYPE : %d, %s", temp->session_name, temp->event, tmp_buffer);
plugin_manager_log(DEBUG, "[SESSION_NAME.%s]->SESSION_EVENT_CALLBACK : %s", temp->session_name, temp->cb_func_name);
}
}
}
}
-int plugin_mangager_config_parse(struct plugin_manager_config *config, const char *prefix, const char *file)
+int plugin_mangager_config_parse(struct plugin_manager_config *config, const char *file)
{
FILE *fp = NULL;
toml_table_t *root = NULL;
char errbuf[200] = {0};
- char tmp_buffer[4096] = {0};
- config->prefix_path = safe_dup(prefix);
config->file_path = safe_dup(file);
- strcat_prefix_and_file(prefix, file, tmp_buffer, sizeof(tmp_buffer));
- fp = fopen(tmp_buffer, "r");
+ fp = fopen(config->file_path, "r");
if (fp == NULL)
{
- plugin_manager_log(ERROR, "can't open %s, %s", tmp_buffer, strerror(errno));
+ plugin_manager_log(ERROR, "can't open %s, %s", config->file_path, strerror(errno));
return -1;
}
@@ -318,6 +265,8 @@ int plugin_mangager_config_parse(struct plugin_manager_config *config, const cha
toml_free(root);
fclose(fp);
+ plugin_manager_log(INFO, "plugin config file '%s' parse success", config->file_path);
+
return 0;
err:
@@ -333,26 +282,4 @@ err:
}
return -1;
-}
-
-/******************************************************************************
- * Test
- ******************************************************************************/
-
-#ifdef PLUGIN_MANAGER_TEST
-int main(int argc, char *argv[])
-{
- struct plugin_manager_config *config = plugin_mangager_config_create();
-
- if (plugin_mangager_config_parse(config, argv[1], argv[2]) == -1)
- {
- plugin_manager_log(ERROR, "can't parser %s %s", argv[1], argv[2]);
- }
-
- plugin_mangager_config_dump(config);
-
- plugin_mangager_config_destory(config);
-
- return 0;
-}
-#endif \ No newline at end of file
+} \ No newline at end of file