X-Git-Url: http://git.pk910.de/?p=NeonServV5.git;a=blobdiff_plain;f=src%2FIRCEvents.c;h=2eea34d8ecc1067bddf693e2a721b6a748abeee7;hp=eb29a094ff23f8c3ea238b1c3ea81c488afb1d5f;hb=HEAD;hpb=9ec0d46248903ba3f53de3d9ef3dceb2d2f1970f diff --git a/src/IRCEvents.c b/src/IRCEvents.c index eb29a09..2eea34d 100644 --- a/src/IRCEvents.c +++ b/src/IRCEvents.c @@ -1,4 +1,4 @@ -/* IRCEvents.c - NeonServ v5.3 +/* IRCEvents.c - NeonServ v5.6 * Copyright (C) 2011-2012 Philipp Kreil (pk910) * * This program is free software: you can redistribute it and/or modify @@ -21,13 +21,15 @@ #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 @@ -47,10 +49,14 @@ static void **binds; #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 19 +#define TOTAL_BIND_TYPES 21 void init_bind() { + if(binds) + return; binds = calloc(TOTAL_BIND_TYPES, sizeof(*binds)); } @@ -64,6 +70,26 @@ void free_bind() { } } 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) { @@ -76,14 +102,15 @@ 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; \ @@ -139,11 +166,7 @@ FUNC_EVENT(nick, nick_func_t, BIND_TYPE_NICK, (struct UserNode *user, char *new_ 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) @@ -195,17 +218,7 @@ FUNC_EVENT(bot_ready, bot_ready_func_t, BIND_TYPE_BOT_READY, (struct ClientSocke FUNC_BIND(registered, registered_func_t, BIND_TYPE_REGISTERED) FUNC_UNBIND(registered, registered_func_t, BIND_TYPE_REGISTERED) -int event_registered(struct UserNode *old_user, struct UserNode *new_user) { - struct binding *cbind; - int ret = 0; - pre_event(BIND_TYPE_REGISTERED); - for(cbind = binds[BIND_TYPE_REGISTERED]; cbind; cbind = cbind->next) { - registered_func_t *func = cbind->func; - ret |= func(old_user, new_user); - } - post_event(BIND_TYPE_REGISTERED); - return ret; -} +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) @@ -214,3 +227,11 @@ FUNC_EVENT(freeuser, freeuser_func_t, BIND_TYPE_FREEUSER, (struct UserNode *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))