#include "ChanNode.h"
#include "ChanUser.h"
#include "ClientSocket.h"
+#include "mysqlConn.h"
struct binding {
void *func;
#define BIND_TYPE_PRIVCTCP 12
#define BIND_TYPE_INVITE 13
#define BIND_TYPE_RAW 14
+#define BIND_TYPE_BOT_READY 15
-#define TOTAL_BIND_TYPES 15
+#define TOTAL_BIND_TYPES 16
void init_bind() {
binds = calloc(TOTAL_BIND_TYPES, sizeof(*binds));
}
+void free_bind() {
+ struct binding *cbind, *next;
+ int i;
+ for(i = 0; i < TOTAL_BIND_TYPES; i++) {
+ for(cbind = binds[i]; cbind; cbind = next) {
+ next = cbind->next;
+ free(cbind);
+ }
+ }
+ free(binds);
+}
+
static int is_bound(unsigned char type, void *func) {
struct binding *cbind;
for(cbind = binds[type]; cbind; cbind = cbind->next) {
#define FUNC_EVENT(NAME,FUNCTYPE,TYPE,PDECLARATION,PLIST) \
int event_##NAME PDECLARATION { \
struct binding *cbind; \
+ pre_event(TYPE); \
for(cbind = binds[TYPE]; cbind; cbind = cbind->next) { \
FUNCTYPE *func = cbind->func; \
func PLIST; \
} \
+ post_event(TYPE); \
return 1; \
}
+void pre_event(UNUSED_ARG(int type)) {
+
+}
+
+void post_event(UNUSED_ARG(int type)) {
+ mysql_free();
+}
+
//EVENTS
FUNC_BIND(join, join_func_t, BIND_TYPE_JOIN)
FUNC_BIND(invite, invite_func_t, BIND_TYPE_INVITE)
FUNC_UNBIND(invite, invite_func_t, BIND_TYPE_INVITE)
-FUNC_EVENT(invite, invite_func_t, BIND_TYPE_INVITE, (struct UserNode *user, char *channel), (user, channel))
+FUNC_EVENT(invite, invite_func_t, BIND_TYPE_INVITE, (struct ClientSocket *client, struct UserNode *user, char *channel), (client, user, channel))
FUNC_BIND(raw, raw_func_t, BIND_TYPE_RAW)
FUNC_UNBIND(raw, raw_func_t, BIND_TYPE_RAW)
FUNC_EVENT(raw, raw_func_t, BIND_TYPE_RAW, (struct ClientSocket *client, char *from, char *cmd, char **argv, int argc), (client, from, cmd, argv, argc))
+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))