--- /dev/null
+/* ModuleFunctions.c - NeonServ v5.4
+ * Copyright (C) 2011-2012 Philipp Kreil (pk910)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#include "ModuleFunctions.h"
+#include "modules.h"
+#include "ChanNode.h"
+#ifndef WIN32
+#include <dlfcn.h>
+#endif
+
+#define FUNCTION_GLOBAL_CMD_REGISTER_NEONBACKUP 0
+#define FUNCTION_GLOBAL_CMD_UNREGISTER_NEONBACKUP 1
+#define FUNCTION_NEONBACKUP_RECOVER_CHAN 2
+
+#define TOTAL_FUNCTIONS 3
+
+struct module_function {
+ struct ModuleInfo *module;
+ void *function;
+};
+
+static struct module_function module_functions[TOTAL_FUNCTIONS];
+
+void init_modulefunctions() {
+ int i;
+ for(i = 0; i < TOTAL_FUNCTIONS; i++) {
+ module_functions[i].function = NULL;
+ }
+}
+
+void scan_module(struct ModuleInfo *module) {
+ char *function_names[] = {
+ "global_cmd_register_neonbackup", /* FUNCTION_GLOBAL_CMD_REGISTER_NEONBACKUP */
+ "global_cmd_unregister_neonbackup", /* FUNCTION_GLOBAL_CMD_UNREGISTER_NEONBACKUP */
+ "neonbackup_recover_chan" /* FUNCTION_NEONBACKUP_RECOVER_CHAN */
+ };
+ int i;
+ for(i = 0; i < TOTAL_FUNCTIONS; i++) {
+ #ifndef WIN32
+ void* func = dlsym(module->module, function_names[i]);
+ #else
+ FARPROC func = GetProcAddress(module->module, function_names[i]);
+ #endif
+ if(func) {
+ module_functions[i].module = module;
+ module_functions[i].function = func;
+ }
+ }
+}
+
+void free_module_functions(struct ModuleInfo *module) {
+ int i;
+ for(i = 0; i < TOTAL_FUNCTIONS; i++) {
+ if(module_functions[i].module == module) {
+ module_functions[i].function = NULL;
+ }
+ }
+}
+
+/* function handlers */
+void module_global_cmd_register_neonbackup(char *chan) {
+ if(!module_functions[FUNCTION_GLOBAL_CMD_REGISTER_NEONBACKUP].function)
+ return;
+ ((void (*)(char *)) module_functions[FUNCTION_GLOBAL_CMD_REGISTER_NEONBACKUP].function)(chan);
+}
+
+void module_global_cmd_unregister_neonbackup(char *chan) {
+ if(!module_functions[FUNCTION_GLOBAL_CMD_UNREGISTER_NEONBACKUP].function)
+ return;
+ ((void (*)(char *)) module_functions[FUNCTION_GLOBAL_CMD_UNREGISTER_NEONBACKUP].function)(chan);
+}
+
+void module_neonbackup_recover_chan(struct ChanNode *chan) {
+ if(!module_functions[FUNCTION_NEONBACKUP_RECOVER_CHAN].function)
+ return;
+ ((void (*)(struct ChanNode *)) module_functions[FUNCTION_NEONBACKUP_RECOVER_CHAN].function)(chan);
+}