summaryrefslogtreecommitdiff
path: root/src/common/HPM.c
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2015-06-15 20:52:44 +0200
committerHaru <haru@dotalux.com>2015-08-15 00:51:42 +0200
commit51b7adcf4e5b2a347081ec9a6903102c4909a404 (patch)
tree39a080440b4bd78b786c8f9372f7883b55fd3ba9 /src/common/HPM.c
parentf8edb93a6a26cd81eeaad0eac23e33da7740c8b4 (diff)
downloadhercules-51b7adcf4e5b2a347081ec9a6903102c4909a404.tar.gz
hercules-51b7adcf4e5b2a347081ec9a6903102c4909a404.tar.bz2
hercules-51b7adcf4e5b2a347081ec9a6903102c4909a404.tar.xz
hercules-51b7adcf4e5b2a347081ec9a6903102c4909a404.zip
HPM compatibility improvements
Improved compatibility, portability and standards conformance. - Since it is not possible to portably and reliably re-use the core's symbols in plugins, symbols are no longer exported unless explicitly required, in the UNIX builds. This mimics the Windows behavior and adds HPM compatibility to OSes such as FreeBSD. Credits to Andrei Karas for making this possible. - For convenience, it is no longer necessary to call GET_SYMBOL, since the plugin will automatically import all the available symbols when it's loaded, depending on the included headers. - Plugins are now supposed to include the "common/hercules.h" header before including anything else. Incluing common/HPMi.h, common/cbasetypes.h or conf/core.h is no longer necessary, as those are guaranteed to be automatically included by hercules.h. - HPM API version bumped to 1.1. Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src/common/HPM.c')
-rw-r--r--src/common/HPM.c38
1 files changed, 13 insertions, 25 deletions
diff --git a/src/common/HPM.c b/src/common/HPM.c
index d82faee1f..85f3d9e95 100644
--- a/src/common/HPM.c
+++ b/src/common/HPM.c
@@ -34,6 +34,7 @@
struct malloc_interface iMalloc_HPM;
struct malloc_interface *HPMiMalloc;
struct HPM_interface HPM_s;
+struct HPM_interface *HPM;
/**
* (char*) data name -> (unsigned int) HPMDataCheck[] index
@@ -95,28 +96,6 @@ struct hplugin *hplugin_create(void) {
HPM->plugins[HPM->plugin_count - 1]->filename = NULL;
return HPM->plugins[HPM->plugin_count - 1];
}
-#define HPM_POP(x) { #x , x }
-bool hplugin_populate(struct hplugin *plugin, const char *filename) {
- struct {
- const char* name;
- void *Ref;
- } ToLink[] = {
- HPM_POP(showmsg),
- };
- int i, length = ARRAYLENGTH(ToLink);
-
- for(i = 0; i < length; i++) {
- void **Link;
- if (!( Link = plugin_import(plugin->dll, ToLink[i].name,void **))) {
- ShowFatalError("HPM:plugin_load: failed to retrieve '%s' for '"CL_WHITE"%s"CL_RESET"'!\n", ToLink[i].name, filename);
- exit(EXIT_FAILURE);
- }
- *Link = ToLink[i].Ref;
- }
-
- return true;
-}
-#undef HPM_POP
struct hplugin *hplugin_load(const char* filename) {
struct hplugin *plugin;
struct hplugin_info *info;
@@ -127,6 +106,7 @@ struct hplugin *hplugin_load(const char* filename) {
int *HPMDataCheckVer;
unsigned int *HPMDataCheckLen;
struct s_HPMDataCheck *HPMDataCheck;
+ const char *(*HPMLoadEvent)(int server_type);
if( HPM->exists(filename) ) {
ShowWarning("HPM:plugin_load: attempting to load duplicate '"CL_WHITE"%s"CL_RESET"', skipping...\n", filename);
@@ -204,8 +184,17 @@ struct hplugin *hplugin_load(const char* filename) {
exit(EXIT_FAILURE);
}
- if( !HPM->populate(plugin,filename) )
- return NULL;
+ if (!(HPMLoadEvent = plugin_import(plugin->dll, "HPM_shared_symbols", const char *(*)(int)))) {
+ ShowFatalError("HPM:plugin_load: failed to retrieve 'HPM_shared_symbols' for '"CL_WHITE"%s"CL_RESET"', most likely not including HPMDataCheck.h!\n", filename);
+ exit(EXIT_FAILURE);
+ }
+ {
+ const char *failure = HPMLoadEvent(SERVER_TYPE);
+ if (failure) {
+ ShowFatalError("HPM:plugin_load: failed to import symbol '%s' into '"CL_WHITE"%s"CL_RESET"'.\n", failure, filename);
+ exit(EXIT_FAILURE);
+ }
+ }
if( !( HPMDataCheckLen = plugin_import(plugin->dll, "HPMDataCheckLen", unsigned int *) ) ) {
ShowFatalError("HPM:plugin_load: failed to retrieve 'HPMDataCheckLen' for '"CL_WHITE"%s"CL_RESET"', most likely not including HPMDataCheck.h!\n", filename);
@@ -925,7 +914,6 @@ void hpm_defaults(void) {
HPM->share = hplugin_export_symbol;
HPM->symbol_defaults = hplugins_share_defaults;
HPM->config_read = hplugins_config_read;
- HPM->populate = hplugin_populate;
HPM->symbol_defaults_sub = NULL;
HPM->pid2name = hplugins_id2name;
HPM->parse_packets = hplugins_parse_packets;