-/* IRCEvents.c - NeonServ v5.2
- * Copyright (C) 2011 Philipp Kreil (pk910)
+/* IRCEvents.c - NeonServ v5.6
+ * 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
#include "ChanUser.h"
#include "ClientSocket.h"
#include "mysqlConn.h"
+#include "log.h"
struct binding {
void *func;
+ int module_id;
struct binding *next;
};
-static void **binds;
+static void **binds = NULL;
#define BIND_TYPE_JOIN 0
#define BIND_TYPE_NICK 1
#define BIND_TYPE_PART 2
#define BIND_TYPE_INVITE 13
#define BIND_TYPE_RAW 14
#define BIND_TYPE_BOT_READY 15
+#define BIND_TYPE_REGISTERED 16
+#define BIND_TYPE_FREEUSER 17
+#define BIND_TYPE_FREECHAN 18
+#define BIND_TYPE_RELOAD 19
+#define BIND_TYPE_FREECLIENT 20
-#define TOTAL_BIND_TYPES 16
+#define TOTAL_BIND_TYPES 21
void init_bind() {
+ if(binds)
+ return;
binds = calloc(TOTAL_BIND_TYPES, sizeof(*binds));
}
}
}
free(binds);
+ binds = NULL;
+}
+
+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) {
}
#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) { \
- perror("malloc() failed"); \
+ printf_log("main", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__); \
return 0; \
} \
cbind->func = func; \
+ cbind->module_id = module_id; \
cbind->next = binds[TYPE]; \
binds[TYPE] = cbind; \
return 1; \
}
void post_event(UNUSED_ARG(int type)) {
- mysql_free();
+
}
//EVENTS
FUNC_BIND(part, part_func_t, BIND_TYPE_PART)
FUNC_UNBIND(part, part_func_t, BIND_TYPE_PART)
-FUNC_EVENT(part, part_func_t, BIND_TYPE_PART, (struct ChanUser *chanuser, char *reason), (chanuser, reason))
-
-FUNC_BIND(quit, quit_func_t, BIND_TYPE_QUIT)
-FUNC_UNBIND(quit, quit_func_t, BIND_TYPE_QUIT)
-FUNC_EVENT(quit, quit_func_t, BIND_TYPE_QUIT, (struct UserNode *user, char *reason), (user, reason))
+FUNC_EVENT(part, part_func_t, BIND_TYPE_PART, (struct ChanUser *chanuser, int quit, char *reason), (chanuser, quit, reason))
FUNC_BIND(kick, kick_func_t, BIND_TYPE_KICK)
FUNC_UNBIND(kick, kick_func_t, BIND_TYPE_KICK)
FUNC_BIND(bot_ready, bot_ready_func_t, BIND_TYPE_BOT_READY)
FUNC_UNBIND(bot_ready, bot_ready_func_t, BIND_TYPE_BOT_READY)
FUNC_EVENT(bot_ready, bot_ready_func_t, BIND_TYPE_BOT_READY, (struct ClientSocket *client), (client))
+
+FUNC_BIND(registered, registered_func_t, BIND_TYPE_REGISTERED)
+FUNC_UNBIND(registered, registered_func_t, BIND_TYPE_REGISTERED)
+FUNC_EVENT(registered, registered_func_t, BIND_TYPE_REGISTERED, (struct UserNode *user, char *new_mask), (user, new_mask))
+
+FUNC_BIND(freeuser, freeuser_func_t, BIND_TYPE_FREEUSER)
+FUNC_UNBIND(freeuser, freeuser_func_t, BIND_TYPE_FREEUSER)
+FUNC_EVENT(freeuser, freeuser_func_t, BIND_TYPE_FREEUSER, (struct UserNode *user), (user))
+
+FUNC_BIND(freechan, freechan_func_t, BIND_TYPE_FREECHAN)
+FUNC_UNBIND(freechan, freechan_func_t, BIND_TYPE_FREECHAN)
+FUNC_EVENT(freechan, freechan_func_t, BIND_TYPE_FREECHAN, (struct ChanNode *chan), (chan))
+
+FUNC_BIND(reload, reload_func_t, BIND_TYPE_RELOAD)
+FUNC_UNBIND(reload, reload_func_t, BIND_TYPE_RELOAD)
+FUNC_EVENT(reload, reload_func_t, BIND_TYPE_RELOAD, (int initialization), (initialization))
+
+FUNC_BIND(freeclient, freeclient_func_t, BIND_TYPE_FREECLIENT)
+FUNC_UNBIND(freeclient, freeclient_func_t, BIND_TYPE_FREECLIENT)
+FUNC_EVENT(freeclient, freeclient_func_t, BIND_TYPE_FREECLIENT, (struct ClientSocket *client), (client))