From 7c52605cabb4f5447055344733d69555c1948956 Mon Sep 17 00:00:00 2001 From: Haru Date: Tue, 11 Aug 2015 01:57:27 +0200 Subject: Moved sql_handle into the HPMi interface Signed-off-by: Haru --- src/map/HPMmap.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/map/HPMmap.c') diff --git a/src/map/HPMmap.c b/src/map/HPMmap.c index 7600d3d0c..9029a6a78 100644 --- a/src/map/HPMmap.c +++ b/src/map/HPMmap.c @@ -135,6 +135,7 @@ bool HPM_map_grabHPData(struct HPDataOperationStorage *ret, enum HPluginDataType } void HPM_map_plugin_load_sub(struct hplugin *plugin) { + plugin->hpi->sql_handle = map->mysql_handle; plugin->hpi->addCommand = HPM->import_symbol("addCommand",plugin->idx); plugin->hpi->addScript = HPM->import_symbol("addScript",plugin->idx); plugin->hpi->addPCGPermission = HPM->import_symbol("addGroupPermission",plugin->idx); -- cgit v1.2.3-70-g09d2 From 5efc9f173f6905da39f3037c278e0e880e82ca35 Mon Sep 17 00:00:00 2001 From: Haru Date: Tue, 11 Aug 2015 02:16:59 +0200 Subject: Removed some unnecessary shared symbols, already present in interfaces Signed-off-by: Haru --- src/common/HPM.c | 506 +++++++++++++++++++++++++++--------------------------- src/common/HPMi.h | 34 ++-- src/map/HPMmap.c | 6 +- src/map/map.c | 4 - 4 files changed, 278 insertions(+), 272 deletions(-) (limited to 'src/map/HPMmap.c') diff --git a/src/common/HPM.c b/src/common/HPM.c index 8963630b1..dcca6ae4c 100644 --- a/src/common/HPM.c +++ b/src/common/HPM.c @@ -96,6 +96,250 @@ struct hplugin *hplugin_create(void) { HPM->plugins[HPM->plugin_count - 1]->filename = NULL; return HPM->plugins[HPM->plugin_count - 1]; } + +bool hplugins_addpacket(unsigned short cmd, unsigned short length, void (*receive) (int fd), unsigned int point,unsigned int pluginID) { + struct HPluginPacket *packet; + unsigned int i; + + if( point >= hpPHP_MAX ) { + ShowError("HPM->addPacket:%s: unknown point '%u' specified for packet 0x%04x (len %d)\n",HPM->pid2name(pluginID),point,cmd,length); + return false; + } + + for(i = 0; i < HPM->packetsc[point]; i++) { + if( HPM->packets[point][i].cmd == cmd ) { + ShowError("HPM->addPacket:%s: can't add packet 0x%04x, already in use by '%s'!",HPM->pid2name(pluginID),cmd,HPM->pid2name(HPM->packets[point][i].pluginID)); + return false; + } + } + + RECREATE(HPM->packets[point], struct HPluginPacket, ++HPM->packetsc[point]); + packet = &HPM->packets[point][HPM->packetsc[point] - 1]; + + packet->pluginID = pluginID; + packet->cmd = cmd; + packet->len = length; + packet->receive = receive; + + return true; +} + +void hplugins_grabHPData(struct HPDataOperationStorage *ret, enum HPluginDataTypes type, void *ptr) +{ + /* record address */ + switch (type) { + /* core-handled */ + case HPDT_SESSION: + ret->HPDataSRCPtr = (void**)(&((struct socket_data *)ptr)->hdata); + ret->hdatac = &((struct socket_data *)ptr)->hdatac; + break; + /* goes to sub */ + default: + if (HPM->grabHPDataSub) { + if (HPM->grabHPDataSub(ret,type,ptr)) + return; + ShowError("HPM:HPM:grabHPData failed, unknown type %d!\n",type); + } else { + ShowError("HPM:grabHPData failed, type %d needs sub-handler!\n",type); + } + ret->HPDataSRCPtr = NULL; + ret->hdatac = NULL; + return; + } +} + +void hplugins_addToHPData(enum HPluginDataTypes type, unsigned int pluginID, void *ptr, void *data, unsigned int index, bool autofree) +{ + struct HPluginData *HPData, **HPDataSRC; + struct HPDataOperationStorage action; + unsigned int i, max; + + HPM->grabHPData(&action,type,ptr); + + if (action.hdatac == NULL) { /* woo it failed! */ + ShowError("HPM:addToHPData:%s: failed, type %d (%u|%u)\n",HPM->pid2name(pluginID),type,pluginID,index); + return; + } + + /* flag */ + HPDataSRC = *(action.HPDataSRCPtr); + max = *(action.hdatac); + + /* duplicate check */ + for (i = 0; i < max; i++) { + if (HPDataSRC[i]->pluginID == pluginID && HPDataSRC[i]->type == index) { + ShowError("HPM:addToHPData:%s: error! attempting to insert duplicate struct of id %u and index %u\n",HPM->pid2name(pluginID),pluginID,index); + return; + } + } + + /* HPluginData is always same size, probably better to use the ERS (with reasonable chunk size e.g. 10/25/50) */ + CREATE(HPData, struct HPluginData, 1); + + /* input */ + HPData->pluginID = pluginID; + HPData->type = index; + HPData->flag.free = autofree ? 1 : 0; + HPData->data = data; + + /* resize */ + *(action.hdatac) += 1; + RECREATE(*(action.HPDataSRCPtr),struct HPluginData *,*(action.hdatac)); + + /* RECREATE modified the address */ + HPDataSRC = *(action.HPDataSRCPtr); + HPDataSRC[*(action.hdatac) - 1] = HPData; +} + +void *hplugins_getFromHPData(enum HPluginDataTypes type, unsigned int pluginID, void *ptr, unsigned int index) +{ + struct HPDataOperationStorage action; + struct HPluginData **HPDataSRC; + unsigned int i, max; + + HPM->grabHPData(&action,type,ptr); + + if (action.hdatac == NULL) { /* woo it failed! */ + ShowError("HPM:getFromHPData:%s: failed, type %d (%u|%u)\n",HPM->pid2name(pluginID),type,pluginID,index); + return NULL; + } + + /* flag */ + HPDataSRC = *(action.HPDataSRCPtr); + max = *(action.hdatac); + + for (i = 0; i < max; i++) { + if (HPDataSRC[i]->pluginID == pluginID && HPDataSRC[i]->type == index) + return HPDataSRC[i]->data; + } + + return NULL; +} + +void hplugins_removeFromHPData(enum HPluginDataTypes type, unsigned int pluginID, void *ptr, unsigned int index) +{ + struct HPDataOperationStorage action; + struct HPluginData **HPDataSRC; + unsigned int i, max; + + HPM->grabHPData(&action,type,ptr); + + if (action.hdatac == NULL) { /* woo it failed! */ + ShowError("HPM:removeFromHPData:%s: failed, type %d (%u|%u)\n",HPM->pid2name(pluginID),type,pluginID,index); + return; + } + + /* flag */ + HPDataSRC = *(action.HPDataSRCPtr); + max = *(action.hdatac); + + for (i = 0; i < max; i++) { + if (HPDataSRC[i]->pluginID == pluginID && HPDataSRC[i]->type == index) + break; + } + + if (i != max) { + unsigned int cursor; + + aFree(HPDataSRC[i]->data);/* when its removed we delete it regardless of autofree */ + aFree(HPDataSRC[i]); + HPDataSRC[i] = NULL; + + for (i = 0, cursor = 0; i < max; i++) { + if (HPDataSRC[i] == NULL) + continue; + if (i != cursor) + HPDataSRC[cursor] = HPDataSRC[i]; + cursor++; + } + *(action.hdatac) = cursor; + } +} + +/* TODO: add ability for tracking using pID for the upcoming runtime load/unload support. */ +bool HPM_AddHook(enum HPluginHookType type, const char *target, void *hook, unsigned int pID) +{ + if (!HPM->hooking) { + ShowError("HPM:AddHook Fail! '%s' tried to hook to '%s' but HPMHooking is disabled!\n",HPM->pid2name(pID),target); + return false; + } + /* search if target is a known hook point within 'common' */ + /* if not check if a sub-hooking list is available (from the server) and run it by */ + if (HPM->addhook_sub && HPM->addhook_sub(type,target,hook,pID)) + return true; + + ShowError("HPM:AddHook: unknown Hooking Point '%s'!\n",target); + + return false; +} + +void HPM_HookStop(const char *func, unsigned int pID) +{ + /* track? */ + HPM->force_return = true; +} + +bool HPM_HookStopped (void) +{ + return HPM->force_return; +} + +/** + * Adds a plugin-defined command-line argument. + * + * @param pluginID the current plugin's ID. + * @param name the command line argument's name, including the leading '--'. + * @param has_param whether the command line argument expects to be followed by a value. + * @param func the triggered function. + * @param help the help string to be displayed by '--help', if any. + * @return the success status. + */ +bool hpm_add_arg(unsigned int pluginID, char *name, bool has_param, CmdlineExecFunc func, const char *help) +{ + int i; + + if (!name || strlen(name) < 3 || name[0] != '-' || name[1] != '-') { + ShowError("HPM:add_arg:%s invalid argument name: arguments must begin with '--' (from %s)\n", name, HPM->pid2name(pluginID)); + return false; + } + + ARR_FIND(0, cmdline->args_data_count, i, strcmp(cmdline->args_data[i].name, name) == 0); + + if (i < cmdline->args_data_count) { + ShowError("HPM:add_arg:%s duplicate! (from %s)\n",name,HPM->pid2name(pluginID)); + return false; + } + + return cmdline->arg_add(pluginID, name, '\0', func, help, has_param ? CMDLINE_OPT_PARAM : CMDLINE_OPT_NORMAL); +} + +bool hplugins_addconf(unsigned int pluginID, enum HPluginConfType type, char *name, void (*func) (const char *val)) +{ + struct HPConfListenStorage *conf; + unsigned int i; + + if (type >= HPCT_MAX) { + ShowError("HPM->addConf:%s: unknown point '%u' specified for config '%s'\n",HPM->pid2name(pluginID),type,name); + return false; + } + + for (i = 0; i < HPM->confsc[type]; i++) { + if (!strcmpi(name,HPM->confs[type][i].key)) { + ShowError("HPM->addConf:%s: duplicate '%s', already in use by '%s'!",HPM->pid2name(pluginID),name,HPM->pid2name(HPM->confs[type][i].pluginID)); + return false; + } + } + + RECREATE(HPM->confs[type], struct HPConfListenStorage, ++HPM->confsc[type]); + conf = &HPM->confs[type][HPM->confsc[type] - 1]; + + conf->pluginID = pluginID; + safestrncpy(conf->key, name, HPM_ADDCONF_LENGTH); + conf->func = func; + + return true; +} + struct hplugin *hplugin_load(const char* filename) { struct hplugin *plugin; struct hplugin_info *info; @@ -212,16 +456,18 @@ struct hplugin *hplugin_load(const char* filename) { /* id */ plugin->hpi->pid = plugin->idx; /* core */ - plugin->hpi->addCPCommand = HPM->import_symbol("addCPCommand",plugin->idx); - plugin->hpi->addPacket = HPM->import_symbol("addPacket",plugin->idx); - plugin->hpi->addToHPData = HPM->import_symbol("addToHPData",plugin->idx); - plugin->hpi->getFromHPData = HPM->import_symbol("getFromHPData",plugin->idx); - plugin->hpi->removeFromHPData = HPM->import_symbol("removeFromHPData",plugin->idx); - plugin->hpi->AddHook = HPM->import_symbol("AddHook",plugin->idx); - plugin->hpi->HookStop = HPM->import_symbol("HookStop",plugin->idx); - plugin->hpi->HookStopped = HPM->import_symbol("HookStopped",plugin->idx); - plugin->hpi->addArg = HPM->import_symbol("addArg",plugin->idx); - plugin->hpi->addConf = HPM->import_symbol("addConf",plugin->idx); +#ifdef CONSOLE_INPUT + plugin->hpi->addCPCommand = console->input->addCommand; +#endif // CONSOLE_INPUT + plugin->hpi->addPacket = hplugins_addpacket; + plugin->hpi->addToHPData = hplugins_addToHPData; + plugin->hpi->getFromHPData = hplugins_getFromHPData; + plugin->hpi->removeFromHPData = hplugins_removeFromHPData; + plugin->hpi->AddHook = HPM_AddHook; + plugin->hpi->HookStop = HPM_HookStop; + plugin->hpi->HookStopped = HPM_HookStopped; + plugin->hpi->addArg = hpm_add_arg; + plugin->hpi->addConf = hplugins_addconf; /* server specific */ if( HPM->load_sub ) HPM->load_sub(plugin); @@ -356,160 +602,7 @@ CPCMD(plugins) { } } } -void hplugins_grabHPData(struct HPDataOperationStorage *ret, enum HPluginDataTypes type, void *ptr) { - /* record address */ - switch( type ) { - /* core-handled */ - case HPDT_SESSION: - ret->HPDataSRCPtr = (void**)(&((struct socket_data *)ptr)->hdata); - ret->hdatac = &((struct socket_data *)ptr)->hdatac; - break; - /* goes to sub */ - default: - if( HPM->grabHPDataSub ) { - if( HPM->grabHPDataSub(ret,type,ptr) ) - return; - else { - ShowError("HPM:HPM:grabHPData failed, unknown type %d!\n",type); - } - } else - ShowError("HPM:grabHPData failed, type %d needs sub-handler!\n",type); - ret->HPDataSRCPtr = NULL; - ret->hdatac = NULL; - return; - } -} -void hplugins_addToHPData(enum HPluginDataTypes type, unsigned int pluginID, void *ptr, void *data, unsigned int index, bool autofree) { - struct HPluginData *HPData, **HPDataSRC; - struct HPDataOperationStorage action; - unsigned int i, max; - - HPM->grabHPData(&action,type,ptr); - - if( action.hdatac == NULL ) { /* woo it failed! */ - ShowError("HPM:addToHPData:%s: failed, type %d (%u|%u)\n",HPM->pid2name(pluginID),type,pluginID,index); - return; - } - - /* flag */ - HPDataSRC = *(action.HPDataSRCPtr); - max = *(action.hdatac); - - /* duplicate check */ - for(i = 0; i < max; i++) { - if( HPDataSRC[i]->pluginID == pluginID && HPDataSRC[i]->type == index ) { - ShowError("HPM:addToHPData:%s: error! attempting to insert duplicate struct of id %u and index %u\n",HPM->pid2name(pluginID),pluginID,index); - return; - } - } - - /* HPluginData is always same size, probably better to use the ERS (with reasonable chunk size e.g. 10/25/50) */ - CREATE(HPData, struct HPluginData, 1); - - /* input */ - HPData->pluginID = pluginID; - HPData->type = index; - HPData->flag.free = autofree ? 1 : 0; - HPData->data = data; - - /* resize */ - *(action.hdatac) += 1; - RECREATE(*(action.HPDataSRCPtr),struct HPluginData *,*(action.hdatac)); - - /* RECREATE modified the address */ - HPDataSRC = *(action.HPDataSRCPtr); - HPDataSRC[*(action.hdatac) - 1] = HPData; -} - -void *hplugins_getFromHPData(enum HPluginDataTypes type, unsigned int pluginID, void *ptr, unsigned int index) { - struct HPDataOperationStorage action; - struct HPluginData **HPDataSRC; - unsigned int i, max; - - HPM->grabHPData(&action,type,ptr); - - if( action.hdatac == NULL ) { /* woo it failed! */ - ShowError("HPM:getFromHPData:%s: failed, type %d (%u|%u)\n",HPM->pid2name(pluginID),type,pluginID,index); - return NULL; - } - - /* flag */ - HPDataSRC = *(action.HPDataSRCPtr); - max = *(action.hdatac); - - for(i = 0; i < max; i++) { - if( HPDataSRC[i]->pluginID == pluginID && HPDataSRC[i]->type == index ) - return HPDataSRC[i]->data; - } - - return NULL; -} -void hplugins_removeFromHPData(enum HPluginDataTypes type, unsigned int pluginID, void *ptr, unsigned int index) { - struct HPDataOperationStorage action; - struct HPluginData **HPDataSRC; - unsigned int i, max; - - HPM->grabHPData(&action,type,ptr); - - if( action.hdatac == NULL ) { /* woo it failed! */ - ShowError("HPM:removeFromHPData:%s: failed, type %d (%u|%u)\n",HPM->pid2name(pluginID),type,pluginID,index); - return; - } - - /* flag */ - HPDataSRC = *(action.HPDataSRCPtr); - max = *(action.hdatac); - - for(i = 0; i < max; i++) { - if( HPDataSRC[i]->pluginID == pluginID && HPDataSRC[i]->type == index ) - break; - } - - if( i != max ) { - unsigned int cursor; - - aFree(HPDataSRC[i]->data);/* when its removed we delete it regardless of autofree */ - aFree(HPDataSRC[i]); - HPDataSRC[i] = NULL; - - for(i = 0, cursor = 0; i < max; i++) { - if( HPDataSRC[i] == NULL ) - continue; - if( i != cursor ) - HPDataSRC[cursor] = HPDataSRC[i]; - cursor++; - } - *(action.hdatac) = cursor; - } -} - -bool hplugins_addpacket(unsigned short cmd, short length,void (*receive) (int fd),unsigned int point,unsigned int pluginID) { - struct HPluginPacket *packet; - unsigned int i; - - if( point >= hpPHP_MAX ) { - ShowError("HPM->addPacket:%s: unknown point '%u' specified for packet 0x%04x (len %d)\n",HPM->pid2name(pluginID),point,cmd,length); - return false; - } - - for(i = 0; i < HPM->packetsc[point]; i++) { - if( HPM->packets[point][i].cmd == cmd ) { - ShowError("HPM->addPacket:%s: can't add packet 0x%04x, already in use by '%s'!",HPM->pid2name(pluginID),cmd,HPM->pid2name(HPM->packets[point][i].pluginID)); - return false; - } - } - - RECREATE(HPM->packets[point], struct HPluginPacket, ++HPM->packetsc[point]); - packet = &HPM->packets[point][HPM->packetsc[point] - 1]; - - packet->pluginID = pluginID; - packet->cmd = cmd; - packet->len = length; - packet->receive = receive; - - return true; -} /* 0 = unknown 1 = OK @@ -586,80 +679,7 @@ void* HPM_reallocz(void *p, size_t size, const char *file, int line, const char char* HPM_astrdup(const char *p, const char *file, int line, const char *func) { return iMalloc->astrdup(p,HPM_file2ptr(file),line,func); } -/* TODO: add ability for tracking using pID for the upcoming runtime load/unload support. */ -bool HPM_AddHook(enum HPluginHookType type, const char *target, void *hook, unsigned int pID) { - if( !HPM->hooking ) { - ShowError("HPM:AddHook Fail! '%s' tried to hook to '%s' but HPMHooking is disabled!\n",HPM->pid2name(pID),target); - return false; - } - /* search if target is a known hook point within 'common' */ - /* if not check if a sub-hooking list is available (from the server) and run it by */ - if( HPM->addhook_sub && HPM->addhook_sub(type,target,hook,pID) ) - return true; - ShowError("HPM:AddHook: unknown Hooking Point '%s'!\n",target); - - return false; -} -void HPM_HookStop (const char *func, unsigned int pID) { - /* track? */ - HPM->force_return = true; -} -bool HPM_HookStopped (void) { - return HPM->force_return; -} -/** - * Adds a plugin-defined command-line argument. - * - * @param pluginID the current plugin's ID. - * @param name the command line argument's name, including the leading '--'. - * @param has_param whether the command line argument expects to be followed by a value. - * @param func the triggered function. - * @param help the help string to be displayed by '--help', if any. - * @return the success status. - */ -bool hpm_add_arg(unsigned int pluginID, char *name, bool has_param, CmdlineExecFunc func, const char *help) { - int i; - - if (!name || strlen(name) < 3 || name[0] != '-' || name[1] != '-') { - ShowError("HPM:add_arg:%s invalid argument name: arguments must begin with '--' (from %s)\n", name, HPM->pid2name(pluginID)); - return false; - } - - ARR_FIND(0, cmdline->args_data_count, i, strcmp(cmdline->args_data[i].name, name) == 0); - - if (i < cmdline->args_data_count) { - ShowError("HPM:add_arg:%s duplicate! (from %s)\n",name,HPM->pid2name(pluginID)); - return false; - } - - return cmdline->arg_add(pluginID, name, '\0', func, help, has_param ? CMDLINE_OPT_PARAM : CMDLINE_OPT_NORMAL); -} -bool hplugins_addconf(unsigned int pluginID, enum HPluginConfType type, char *name, void (*func) (const char *val)) { - struct HPConfListenStorage *conf; - unsigned int i; - - if( type >= HPCT_MAX ) { - ShowError("HPM->addConf:%s: unknown point '%u' specified for config '%s'\n",HPM->pid2name(pluginID),type,name); - return false; - } - - for(i = 0; i < HPM->confsc[type]; i++) { - if( !strcmpi(name,HPM->confs[type][i].key) ) { - ShowError("HPM->addConf:%s: duplicate '%s', already in use by '%s'!",HPM->pid2name(pluginID),name,HPM->pid2name(HPM->confs[type][i].pluginID)); - return false; - } - } - - RECREATE(HPM->confs[type], struct HPConfListenStorage, ++HPM->confsc[type]); - conf = &HPM->confs[type][HPM->confsc[type] - 1]; - - conf->pluginID = pluginID; - safestrncpy(conf->key, name, HPM_ADDCONF_LENGTH); - conf->func = func; - - return true; -} bool hplugins_parse_conf(const char *w1, const char *w2, enum HPluginConfType point) { unsigned int i; @@ -729,20 +749,6 @@ void HPM_datacheck_final(void) { } void hplugins_share_defaults(void) { - /* console */ -#ifdef CONSOLE_INPUT - HPM->share(console->input->addCommand,"addCPCommand"); -#endif - /* our own */ - HPM->share(hplugins_addpacket,"addPacket"); - HPM->share(hplugins_addToHPData,"addToHPData"); - HPM->share(hplugins_getFromHPData,"getFromHPData"); - HPM->share(hplugins_removeFromHPData,"removeFromHPData"); - HPM->share(HPM_AddHook,"AddHook"); - HPM->share(HPM_HookStop,"HookStop"); - HPM->share(HPM_HookStopped,"HookStopped"); - HPM->share(hpm_add_arg,"addArg"); - HPM->share(hplugins_addconf,"addConf"); /* core */ HPM->share(core,"core"); HPM->share(HPMiMalloc, "iMalloc"); diff --git a/src/common/HPMi.h b/src/common/HPMi.h index 5f677cce3..6f97659f9 100644 --- a/src/common/HPMi.h +++ b/src/common/HPMi.h @@ -139,33 +139,37 @@ enum HPluginConfType { #define getFromBGDATA(ptr,index) (HPMi->getFromHPData(HPDT_BGDATA,HPMi->pid,(ptr),(index))) #define removeFromBGDATA(ptr,index) (HPMi->removeFromHPData(HPDT_BGDATA,HPMi->pid,(ptr),(index))) -/* HPMi->addCommand */ -#define addAtcommand(cname,funcname) \ - if ( HPMi->addCommand != NULL ) { \ +/// HPMi->addCommand +#define addAtcommand(cname,funcname) do { \ + if (HPMi->addCommand != NULL) { \ HPMi->addCommand(cname,atcommand_ ## funcname); \ } else { \ ShowWarning("HPM (%s):addAtcommand(\"%s\",%s) failed, addCommand sub is NULL!\n",pinfo.name,cname,# funcname);\ - } -/* HPMi->addScript */ -#define addScriptCommand(cname,scinfo,funcname) \ - if ( HPMi->addScript != NULL ) { \ + } \ +} while(0) +/// HPMi->addScript +#define addScriptCommand(cname,scinfo,funcname) do { \ + if (HPMi->addScript != NULL) { \ HPMi->addScript(cname,scinfo,buildin_ ## funcname, false); \ } else { \ ShowWarning("HPM (%s):addScriptCommand(\"%s\",\"%s\",%s) failed, addScript sub is NULL!\n",pinfo.name,cname,scinfo,# funcname);\ - } -#define addScriptCommandDeprecated(cname,scinfo,funcname) \ - if ( HPMi->addScript != NULL ) { \ + } \ +} while(0) +#define addScriptCommandDeprecated(cname,scinfo,funcname) do { \ + if (HPMi->addScript != NULL) { \ HPMi->addScript(cname,scinfo,buildin_ ## funcname, true); \ } else { \ ShowWarning("HPM (%s):addScriptCommandDeprecated(\"%s\",\"%s\",%s) failed, addScript sub is NULL!\n",pinfo.name,cname,scinfo,# funcname);\ - } -/* HPMi->addCPCommand */ -#define addCPCommand(cname,funcname) \ - if ( HPMi->addCPCommand != NULL ) { \ + } \ +} while(0) +/// HPMi->addCPCommand +#define addCPCommand(cname,funcname) do { \ + if (HPMi->addCPCommand != NULL) { \ HPMi->addCPCommand(cname,console_parse_ ## funcname); \ } else { \ ShowWarning("HPM (%s):addCPCommand(\"%s\",%s) failed, addCPCommand sub is NULL!\n",pinfo.name,cname,# funcname);\ - } + } \ +} while(0) /* HPMi->addPacket */ #define addPacket(cmd,len,receive,point) HPMi->addPacket(cmd,len,receive,point,HPMi->pid) /* HPMi->addBattleConf */ diff --git a/src/map/HPMmap.c b/src/map/HPMmap.c index 9029a6a78..a974f60ce 100644 --- a/src/map/HPMmap.c +++ b/src/map/HPMmap.c @@ -136,9 +136,9 @@ bool HPM_map_grabHPData(struct HPDataOperationStorage *ret, enum HPluginDataType void HPM_map_plugin_load_sub(struct hplugin *plugin) { plugin->hpi->sql_handle = map->mysql_handle; - plugin->hpi->addCommand = HPM->import_symbol("addCommand",plugin->idx); - plugin->hpi->addScript = HPM->import_symbol("addScript",plugin->idx); - plugin->hpi->addPCGPermission = HPM->import_symbol("addGroupPermission",plugin->idx); + plugin->hpi->addCommand = atcommand->create; + plugin->hpi->addScript = script->addScript; + plugin->hpi->addPCGPermission = HPM_map_add_group_permission; } bool HPM_map_add_atcommand(char *name, AtCommandFunc func) { diff --git a/src/map/map.c b/src/map/map.c index 9a6c8b70b..e05e77f46 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -5662,10 +5662,6 @@ void map_hp_symbols(void) { #endif HPM->share(mapit,"mapit"); HPM->share(mapindex,"mapindex"); - /* specific */ - HPM->share(atcommand->create,"addCommand"); - HPM->share(script->addScript,"addScript"); - HPM->share(HPM_map_add_group_permission,"addGroupPermission"); } void map_load_defaults(void) { -- cgit v1.2.3-70-g09d2 From e7c2f7d827ad286dc826e483391e64b8ffe2720b Mon Sep 17 00:00:00 2001 From: Haru Date: Tue, 11 Aug 2015 02:17:37 +0200 Subject: Automatic HPM symbol sharing Signed-off-by: Haru --- src/char/HPMchar.c | 1 + src/char/char.c | 21 ---------------- src/common/HPM.c | 38 ---------------------------- src/common/HPM.h | 2 -- src/common/HPMi.h | 4 ++- src/login/HPMlogin.c | 1 + src/login/login.c | 6 ----- src/map/HPMmap.c | 1 + src/map/map.c | 49 ------------------------------------- tools/HPMHookGen/HPMDataCheckGen.pl | 7 ++++-- 10 files changed, 11 insertions(+), 119 deletions(-) (limited to 'src/map/HPMmap.c') diff --git a/src/char/HPMchar.c b/src/char/HPMchar.c index 3e8470e9b..a67f017c1 100644 --- a/src/char/HPMchar.c +++ b/src/char/HPMchar.c @@ -62,6 +62,7 @@ void HPM_char_plugin_load_sub(struct hplugin *plugin) { void HPM_char_do_init(void) { HPM->datacheck_init(HPMDataCheck, HPMDataCheckLen, HPMDataCheckVer); + HPM_shared_symbols(SERVER_TYPE_CHAR); } void HPM_char_do_final(void) { diff --git a/src/char/char.c b/src/char/char.c index 625103b71..576eb9630 100644 --- a/src/char/char.c +++ b/src/char/char.c @@ -5806,26 +5806,6 @@ void do_shutdown(void) } } -void char_hp_symbols(void) { - HPM->share(mapindex,"mapindex"); - HPM->share(chr, "chr"); - HPM->share(geoip, "geoip"); - HPM->share(inter_auction, "inter_auction"); - HPM->share(inter_elemental, "inter_elemental"); - HPM->share(inter_guild, "inter_guild"); - HPM->share(inter_homunculus, "inter_homunculus"); - HPM->share(inter_mail, "inter_mail"); - HPM->share(inter_mercenary, "inter_mercenary"); - HPM->share(inter_party, "inter_party"); - HPM->share(inter_pet, "inter_pet"); - HPM->share(inter_quest, "inter_quest"); - HPM->share(inter_storage, "inter_storage"); - HPM->share(inter, "inter"); - HPM->share(loginif, "loginif"); - HPM->share(mapif, "mapif"); - HPM->share(pincode, "pincode"); -} - /** * --char-config handler * @@ -5887,7 +5867,6 @@ int do_init(int argc, char **argv) { chr->server[i].map = NULL; HPM_char_do_init(); - HPM->symbol_defaults_sub = char_hp_symbols; cmdline->exec(argc, argv, CMDLINE_OPT_PREINIT); HPM->config_read(); HPM->event(HPET_PRE_INIT); diff --git a/src/common/HPM.c b/src/common/HPM.c index dcca6ae4c..a78f03daa 100644 --- a/src/common/HPM.c +++ b/src/common/HPM.c @@ -533,9 +533,6 @@ void hplugins_config_read(void) { if (libconfig->read_file(&plugins_conf, config_filename)) return; - if( HPM->symbol_defaults_sub ) - HPM->symbol_defaults_sub(); - plist = libconfig->lookup(&plugins_conf, "plugins_list"); for (i = 0; i < HPM->cmdline_plugins_count; i++) { config_setting_t *entry = libconfig->setting_add(plist, NULL, CONFIG_TYPE_STRING); @@ -748,37 +745,6 @@ void HPM_datacheck_final(void) { db_destroy(datacheck_db); } -void hplugins_share_defaults(void) { - /* core */ - HPM->share(core,"core"); - HPM->share(HPMiMalloc, "iMalloc"); - HPM->share(cmdline,"cmdline"); - /* console */ - HPM->share(console,"console"); - /* db */ - HPM->share(DB, "DB"); - /* nullpo */ - HPM->share(nullpo,"nullpo"); - /* showmsg */ - HPM->share(showmsg,"showmsg"); - /* socket */ - HPM->share(sockt,"sockt"); - /* strlib */ - HPM->share(strlib,"strlib"); - HPM->share(sv,"sv"); - HPM->share(StrBuf,"StrBuf"); - /* sql */ - HPM->share(SQL,"SQL"); - /* timer */ - HPM->share(timer,"timer"); - /* libconfig */ - HPM->share(libconfig,"libconfig"); - /* sysinfo */ - HPM->share(sysinfo,"sysinfo"); - /* utils */ - HPM->share(HCache,"HCache"); -} - void hpm_init(void) { unsigned int i; datacheck_db = NULL; @@ -810,8 +776,6 @@ void hpm_init(void) { HPM->packetsc[i] = 0; } - HPM->symbol_defaults(); - #ifdef CONSOLE_INPUT console->input->addCommand("plugins",CPCMD_A(plugins)); #endif @@ -906,9 +870,7 @@ void hpm_defaults(void) { HPM->iscompatible = hplugin_iscompatible; HPM->import_symbol = hplugin_import_symbol; HPM->share = hplugin_export_symbol; - HPM->symbol_defaults = hplugins_share_defaults; HPM->config_read = hplugins_config_read; - HPM->symbol_defaults_sub = NULL; HPM->pid2name = hplugins_id2name; HPM->parse_packets = hplugins_parse_packets; HPM->load_sub = NULL; diff --git a/src/common/HPM.h b/src/common/HPM.h index 2d38a2bfa..c13132cfc 100644 --- a/src/common/HPM.h +++ b/src/common/HPM.h @@ -129,9 +129,7 @@ struct HPM_interface { void (*event) (enum hp_event_types type); void *(*import_symbol) (char *name, unsigned int pID); void (*share) (void *, char *); - void (*symbol_defaults) (void); void (*config_read) (void); - void (*symbol_defaults_sub) (void);//TODO drop char *(*pid2name) (unsigned int pid); unsigned char (*parse_packets) (int fd, enum HPluginPacketHookingPoints point); void (*load_sub) (struct hplugin *plugin); diff --git a/src/common/HPMi.h b/src/common/HPMi.h index 6f97659f9..bd8d8fe64 100644 --- a/src/common/HPMi.h +++ b/src/common/HPMi.h @@ -218,7 +218,9 @@ struct HPMi_interface { Sql *sql_handle; }; -#ifndef HERCULES_CORE +#ifdef HERCULES_CORE +#define HPM_SYMBOL(n, s) (HPM->share((s), (n)), true) +#else // ! HERCULES_CORE HPExport struct HPMi_interface HPMi_s; HPExport struct HPMi_interface *HPMi; HPExport void *(*import_symbol) (char *name, unsigned int pID); diff --git a/src/login/HPMlogin.c b/src/login/HPMlogin.c index b1c097a52..895cbad16 100644 --- a/src/login/HPMlogin.c +++ b/src/login/HPMlogin.c @@ -47,6 +47,7 @@ void HPM_login_plugin_load_sub(struct hplugin *plugin) { void HPM_login_do_init(void) { HPM->datacheck_init(HPMDataCheck, HPMDataCheckLen, HPMDataCheckVer); + HPM_shared_symbols(SERVER_TYPE_LOGIN); } void HPM_login_do_final(void) { diff --git a/src/login/login.c b/src/login/login.c index cf27fe71a..572bd594f 100644 --- a/src/login/login.c +++ b/src/login/login.c @@ -1918,11 +1918,6 @@ void do_shutdown_login(void) } } -void login_hp_symbols(void) { - HPM->share(account_db_sql_up(accounts),"sql_handle"); - HPM->share(login,"login"); -} - /** * --login-config handler * @@ -1980,7 +1975,6 @@ int do_init(int argc, char** argv) login->NET_CONF_NAME = aStrdup("conf/network.conf"); HPM_login_do_init(); - HPM->symbol_defaults_sub = login_hp_symbols; cmdline->exec(argc, argv, CMDLINE_OPT_PREINIT); HPM->config_read(); HPM->event(HPET_PRE_INIT); diff --git a/src/map/HPMmap.c b/src/map/HPMmap.c index a974f60ce..a59fbb6ef 100644 --- a/src/map/HPMmap.c +++ b/src/map/HPMmap.c @@ -186,6 +186,7 @@ void HPM_map_do_init(void) { HPM->load_sub = HPM_map_plugin_load_sub; HPM->grabHPDataSub = HPM_map_grabHPData; HPM->datacheck_init(HPMDataCheck, HPMDataCheckLen, HPMDataCheckVer); + HPM_shared_symbols(SERVER_TYPE_MAP); } void HPM_map_do_final(void) { diff --git a/src/map/map.c b/src/map/map.c index e05e77f46..a7b171ddf 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -5615,54 +5615,6 @@ void map_cp_defaults(void) { console->input->addCommand("gm:use",CPCMD_A(gm_use)); #endif } -/* Hercules Plugin Mananger */ -void map_hp_symbols(void) { - /* full interfaces */ - HPM->share(atcommand,"atcommand"); - HPM->share(battle,"battle"); - HPM->share(bg,"battlegrounds"); - HPM->share(buyingstore,"buyingstore"); - HPM->share(channel,"channel"); - HPM->share(clif,"clif"); - HPM->share(chrif,"chrif"); - HPM->share(guild,"guild"); - HPM->share(gstorage,"gstorage"); - HPM->share(homun,"homun"); - HPM->share(map,"map"); - HPM->share(ircbot,"ircbot"); - HPM->share(itemdb,"itemdb"); - HPM->share(logs,"logs"); - HPM->share(mail,"mail"); - HPM->share(instance,"instance"); - HPM->share(script,"script"); - HPM->share(searchstore,"searchstore"); - HPM->share(skill,"skill"); - HPM->share(vending,"vending"); - HPM->share(pc,"pc"); - HPM->share(pcg,"pc_groups"); - HPM->share(party,"party"); - HPM->share(storage,"storage"); - HPM->share(trade,"trade"); - HPM->share(status,"status"); - HPM->share(chat, "chat"); - HPM->share(duel,"duel"); - HPM->share(elemental,"elemental"); - HPM->share(intif,"intif"); - HPM->share(mercenary,"mercenary"); - HPM->share(mob,"mob"); - HPM->share(unit,"unit"); - HPM->share(npc,"npc"); - HPM->share(mapreg,"mapreg"); - HPM->share(pet,"pet"); - HPM->share(path,"path"); - HPM->share(quest,"quest"); -#ifdef PCRE_SUPPORT - HPM->share(npc_chat,"npc_chat"); - HPM->share(libpcre,"libpcre"); -#endif - HPM->share(mapit,"mapit"); - HPM->share(mapindex,"mapindex"); -} void map_load_defaults(void) { mapindex_defaults(); @@ -5899,7 +5851,6 @@ int do_init(int argc, char *argv[]) map->GRF_PATH_FILENAME = aStrdup("conf/grf-files.txt"); HPM_map_do_init(); - HPM->symbol_defaults_sub = map_hp_symbols; cmdline->exec(argc, argv, CMDLINE_OPT_PREINIT); HPM->config_read(); diff --git a/tools/HPMHookGen/HPMDataCheckGen.pl b/tools/HPMHookGen/HPMDataCheckGen.pl index 2f4b02d26..e658f8be8 100644 --- a/tools/HPMHookGen/HPMDataCheckGen.pl +++ b/tools/HPMHookGen/HPMDataCheckGen.pl @@ -58,9 +58,12 @@ print FH <<"EOF"; #ifndef HPM_DATA_CHECK_H #define HPM_DATA_CHECK_H -#if !defined(HERCULES_CORE) && !defined(HPMHOOKGEN) +#if !defined(HPMHOOKGEN) #include "common/HPMSymbols.inc.h" -#endif // ! HERCULES_CORE && ! HPMHOOKGEN +#endif // ! HPMHOOKGEN +#ifdef HPM_SYMBOL +#undef HPM_SYMBOL +#endif // HPM_SYMBOL HPExport const struct s_HPMDataCheck HPMDataCheck[] = { EOF -- cgit v1.2.3-70-g09d2