summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2015-09-15 12:52:08 +0200
committerHaru <haru@dotalux.com>2015-10-11 00:24:20 +0200
commitf17add758aa067f3b643e008dc42ec918b358528 (patch)
tree84d5640f652f2e4c6c546be5f95d8c1233ae0617 /src/common
parent5a9d6c05dba6aa00590b475f848964cd888c0a93 (diff)
downloadhercules-f17add758aa067f3b643e008dc42ec918b358528.tar.gz
hercules-f17add758aa067f3b643e008dc42ec918b358528.tar.bz2
hercules-f17add758aa067f3b643e008dc42ec918b358528.tar.xz
hercules-f17add758aa067f3b643e008dc42ec918b358528.zip
Changed HPM->symbols to a VECTOR
Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src/common')
-rw-r--r--src/common/HPM.c52
-rw-r--r--src/common/HPM.h12
2 files changed, 40 insertions, 24 deletions
diff --git a/src/common/HPM.c b/src/common/HPM.c
index 645784b01..12b879357 100644
--- a/src/common/HPM.c
+++ b/src/common/HPM.c
@@ -58,20 +58,37 @@ void hplugin_trigger_event(enum hp_event_types type)
}
}
-void hplugin_export_symbol(void *var, char *name) {
- RECREATE(HPM->symbols, struct hpm_symbol *, ++HPM->symbol_count);
- CREATE(HPM->symbols[HPM->symbol_count - 1] ,struct hpm_symbol, 1);
- HPM->symbols[HPM->symbol_count - 1]->name = name;
- HPM->symbols[HPM->symbol_count - 1]->ptr = var;
+/**
+ * Exports a symbol to the shared symbols list.
+ *
+ * @param value The symbol value.
+ * @param name The symbol name.
+ */
+void hplugin_export_symbol(void *value, const char *name)
+{
+ struct hpm_symbol *symbol = NULL;
+ CREATE(symbol ,struct hpm_symbol, 1);
+ symbol->name = name;
+ symbol->ptr = value;
+ VECTOR_ENSURE(HPM->symbols, 1, 1);
+ VECTOR_PUSH(HPM->symbols, symbol);
}
-void *hplugin_import_symbol(char *name, unsigned int pID) {
- unsigned int i;
+/**
+ * Imports a shared symbol.
+ *
+ * @param name The symbol name.
+ * @param pID The requesting plugin ID.
+ * @return The symbol value.
+ * @retval NULL if the symbol wasn't found.
+ */
+void *hplugin_import_symbol(char *name, unsigned int pID)
+{
+ int i;
+ ARR_FIND(0, VECTOR_LENGTH(HPM->symbols), i, strcmp(VECTOR_INDEX(HPM->symbols, i)->name, name) == 0);
- for( i = 0; i < HPM->symbol_count; i++ ) {
- if( strcmp(HPM->symbols[i]->name,name) == 0 )
- return HPM->symbols[i]->ptr;
- }
+ if (i != VECTOR_LENGTH(HPM->symbols))
+ return VECTOR_INDEX(HPM->symbols, i)->ptr;
ShowError("HPM:get_symbol:%s: '"CL_WHITE"%s"CL_RESET"' not found!\n",HPM->pid2name(pID),name);
return NULL;
@@ -790,9 +807,9 @@ void hpm_init(void) {
datacheck_data = NULL;
datacheck_version = 0;
- HPM->symbols = NULL;
VECTOR_INIT(HPM->plugins);
- HPM->symbol_count = 0;
+ VECTOR_INIT(HPM->symbols);
+
HPM->off = false;
memcpy(&iMalloc_HPM, iMalloc, sizeof(struct malloc_interface));
@@ -843,13 +860,10 @@ void hpm_final(void)
}
VECTOR_CLEAR(HPM->plugins);
- if( HPM->symbols )
- {
- for( i = 0; i < HPM->symbol_count; i++ ) {
- aFree(HPM->symbols[i]);
- }
- aFree(HPM->symbols);
+ while (VECTOR_LENGTH(HPM->symbols)) {
+ aFree(VECTOR_POP(HPM->symbols));
}
+ VECTOR_CLEAR(HPM->symbols);
for( i = 0; i < hpPHP_MAX; i++ ) {
if( HPM->packets[i] )
diff --git a/src/common/HPM.h b/src/common/HPM.h
index 5579dc2b1..6d44cd474 100644
--- a/src/common/HPM.h
+++ b/src/common/HPM.h
@@ -57,9 +57,12 @@ struct hplugin {
struct HPMi_interface *hpi;
};
+/**
+ * Symbols shared between core and plugins.
+ */
struct hpm_symbol {
- char *name;
- void *ptr;
+ const char *name; ///< The symbol name
+ void *ptr; ///< The symbol value
};
struct HPluginData {
@@ -104,8 +107,7 @@ struct HPM_interface {
bool force_return;
/* data */
VECTOR_DECL(struct hplugin *) plugins;
- struct hpm_symbol **symbols;
- unsigned int symbol_count;
+ VECTOR_DECL(struct hpm_symbol *) symbols;
/* packet hooking points */
struct HPluginPacket *packets[hpPHP_MAX];
unsigned int packetsc[hpPHP_MAX];
@@ -128,7 +130,7 @@ struct HPM_interface {
bool (*iscompatible) (char* version);
void (*event) (enum hp_event_types type);
void *(*import_symbol) (char *name, unsigned int pID);
- void (*share) (void *, char *);
+ void (*share) (void *value, const char *name);
void (*config_read) (void);
char *(*pid2name) (unsigned int pid);
unsigned char (*parse_packets) (int fd, enum HPluginPacketHookingPoints point);