multiple fixes
[NeonServV5.git] / src / IRCEvents.c
index 6d813fe9831e548bdbe2a8f5da92dc8a844c9282..b0cbd02a722f955a7276f3687f0f8629d7b2d58d 100644 (file)
@@ -1,5 +1,5 @@
-/* IRCEvents.c - NeonServ v5.2
- * Copyright (C) 2011  Philipp Kreil (pk910)
+/* IRCEvents.c - NeonServ v5.3
+ * 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
@@ -24,6 +24,7 @@
 
 struct binding {
     void *func;
+    int module_id;
     struct binding *next;
 };
 
@@ -66,6 +67,25 @@ void free_bind() {
     free(binds);
 }
 
+void unregister_module_events(int module_id) {
+    struct binding *cbind, *next, *prev;
+    int i;
+    for(i = 0; i < TOTAL_BIND_TYPES; i++) {
+        prev = NULL;
+        for(cbind = binds[i]; cbind; cbind = next) {
+            next = cbind->next;
+            if(cbind->module_id == module_id) {
+                if(prev)
+                    prev->next = next;
+                else
+                    binds[i] = next;
+                free(cbind);
+            } else
+                prev = cbind;
+        }
+    }
+}
+
 static int is_bound(unsigned char type, void *func) {
     struct binding *cbind;
     for(cbind = binds[type]; cbind; cbind = cbind->next) {
@@ -76,7 +96,7 @@ static int is_bound(unsigned char type, void *func) {
 }
 
 #define FUNC_BIND(NAME,FUNCTYPE,TYPE) \
-int bind_##NAME(FUNCTYPE *func) { \
+int bind_##NAME(FUNCTYPE *func, int module_id) { \
     if(!is_bound(TYPE, func)) { \
         struct binding *cbind = malloc(sizeof(*cbind)); \
         if (!cbind) { \
@@ -84,6 +104,7 @@ int bind_##NAME(FUNCTYPE *func) { \
             return 0; \
         } \
         cbind->func = func; \
+        cbind->module_id = module_id; \
         cbind->next = binds[TYPE]; \
         binds[TYPE] = cbind; \
         return 1; \
@@ -124,7 +145,7 @@ void pre_event(UNUSED_ARG(int type)) {
 }
 
 void post_event(UNUSED_ARG(int type)) {
-    mysql_free();
+
 }
 
 //EVENTS