X-Git-Url: https://jfr.im/git/irc/evilnet/x3.git/blobdiff_plain/30874d6682a37bc1d8f3d76fd90afde6a0f3fce7..HEAD:/src/hash.c diff --git a/src/hash.c b/src/hash.c index 80ac002..8f6a3df 100644 --- a/src/hash.c +++ b/src/hash.c @@ -38,6 +38,7 @@ dict_t servers; unsigned int max_clients, invis_clients; time_t max_clients_time; struct userList curr_opers; +unsigned int count_opers; static void hash_cleanup(void *extra); @@ -47,6 +48,7 @@ void init_structs(void) clients = dict_new(); servers = dict_new(); userList_init(&curr_opers); + count_opers = 0; reg_exit_func(hash_cleanup, NULL); } @@ -101,37 +103,96 @@ GetServerH(const char *name) return dict_find(servers, name, NULL); } -new_user_func_t *nuf_list; -void **nuf_list_extra; -unsigned int nuf_size = 0, nuf_used = 0; +sasl_input_func_t *sif_list; +void **sif_list_extra; +unsigned int sif_size = 0, sif_used = 0; void -reg_new_user_func(new_user_func_t handler, void *extra) +reg_sasl_input_func(sasl_input_func_t handler, void *extra) { - if (nuf_used == nuf_size) { - if (nuf_size) { - nuf_size <<= 1; - nuf_list = realloc(nuf_list, nuf_size*sizeof(new_user_func_t)); - nuf_list_extra = realloc(nuf_list_extra, nuf_size*sizeof(void*)); + if (sif_used == sif_size) { + if (sif_size) { + sif_size <<= 1; + sif_list = realloc(sif_list, sif_size*sizeof(new_user_func_t)); + sif_list_extra = realloc(sif_list_extra, sif_size*sizeof(void*)); } else { - nuf_size = 8; - nuf_list = malloc(nuf_size*sizeof(new_user_func_t)); - nuf_list_extra = malloc(nuf_size*sizeof(void*)); + sif_size = 8; + sif_list = malloc(sif_size*sizeof(new_user_func_t)); + sif_list_extra = malloc(sif_size*sizeof(void*)); } } - nuf_list[nuf_used] = handler; - nuf_list_extra[nuf_used++] = extra; + sif_list[sif_used] = handler; + sif_list_extra[sif_used++] = extra; } void -call_new_user_funcs(struct userNode* user) +call_sasl_input_func(struct server* source ,const char *identifier, const char *subcmd, const char *data, const char *ext) { unsigned int i; - for (i = 0; i < nuf_used && !(user->dead); ++i) + for (i = 0; i < sif_used; ++i) { - nuf_list[i](user, nuf_list_extra[i]); + sif_list[i](source, identifier, subcmd, data, ext, sif_list_extra[i]); + } +} + +void +unreg_sasl_input_func(sasl_input_func_t handler, void *extra) +{ + unsigned int i; + for (i=0; iextra != NULL) + free(ehf->extra); +} + +DEFINE_EH_FUNC_LIST(nuf_list, EH_ADD_TAIL, nuf_free_ehf); + +int +nuf_wrapper(void *extra, void *callextra) +{ + struct funcargs *fa = (struct funcargs *)extra; + struct userNode *user = (struct userNode *)callextra; + + ((new_user_func_t)fa->func)(user, fa->extra); + + if (user->dead) + return EH_STOP; + + return EH_CONT; +} + +void +reg_new_user_func_pos(new_user_func_t handler, void *extra, int pos) +{ + struct funcargs *fa = malloc(sizeof(struct funcargs)); + + fa->func = (void *)handler; + fa->extra = extra; + + reg_hook_func_pos(&nuf_list, nuf_wrapper, (void *)fa, pos); +} + +void +reg_new_user_func(new_user_func_t handler, void *extra) +{ + reg_new_user_func_pos(handler, extra, EH_ADD_DEFAULT); +} + +void +call_new_user_funcs(struct userNode* user) +{ + call_hook_func_args(&nuf_list, (void *)user); } static nick_change_func_t *ncf2_list; @@ -424,26 +485,51 @@ reg_new_channel_func(new_channel_func_t handler, void *extra) ncf_list_extra[ncf_used++] = extra; } -static join_func_t *jf_list; -static void **jf_list_extra; -static unsigned int jf_size = 0, jf_used = 0; +void +jf_free_ehf(struct eh_func *ehf) +{ + if (ehf->extra != NULL) + free(ehf->extra); +} + +DEFINE_EH_FUNC_LIST(jf_list, EH_ADD_TAIL, jf_free_ehf); + +int +jf_wrapper(void *extra, void *callextra) +{ + struct funcargs *fa = (struct funcargs *)extra; + struct modeNode *mNode = (struct modeNode *)callextra; + struct userNode *user = mNode->user; + + ((join_func_t)fa->func)(mNode, fa->extra); + + if (user->dead) + return EH_STOP; + + return EH_CONT; +} + +void +reg_join_func_pos(join_func_t handler, void *extra, int pos) +{ + struct funcargs *fa = malloc(sizeof(struct funcargs)); + + fa->func = (void *)handler; + fa->extra = extra; + + reg_hook_func_pos(&jf_list, jf_wrapper, (void *)fa, pos); +} void reg_join_func(join_func_t handler, void *extra) { - if (jf_used == jf_size) { - if (jf_size) { - jf_size <<= 1; - jf_list = realloc(jf_list, jf_size*sizeof(join_func_t)); - jf_list_extra = realloc(jf_list_extra, jf_size*sizeof(void*)); - } else { - jf_size = 8; - jf_list = malloc(jf_size*sizeof(join_func_t)); - jf_list_extra = malloc(jf_size*sizeof(void*)); - } - } - jf_list[jf_used] = handler; - jf_list_extra[jf_used++] = extra; + reg_join_func_pos(handler, extra, EH_ADD_DEFAULT); +} + +void +call_join_funcs(struct modeNode *mNode) +{ + call_hook_func_args(&jf_list, (void *)mNode); } int rel_age; @@ -657,7 +743,6 @@ struct modeNode * AddChannelUser(struct userNode *user, struct chanNode* channel) { struct modeNode *mNode; - unsigned int n; mNode = GetUserMode(channel, user); if (mNode) @@ -683,19 +768,13 @@ AddChannelUser(struct userNode *user, struct chanNode* channel) && !(channel->modes & MODE_REGISTERED) && !(channel->modes & MODE_APASS)) { mNode->modes |= MODE_CHANOP; - log_module(MAIN_LOG, LOG_DEBUG, "setting op"); } if (IsLocal(user)) { irc_join(user, channel); } - for (n=0; (ndead; n++) { - /* Callbacks return true if they kick or kill the user, - * and we can continue without removing mNode. */ - if (jf_list[n](mNode, jf_list_extra[n])) - return NULL; - } + call_join_funcs(mNode); return mNode; } @@ -1010,19 +1089,18 @@ hash_cleanup(UNUSED_ARG(void *extra)) dict_delete(clients); dict_delete(servers); userList_clean(&curr_opers); + count_opers = 0; free(slf_list); free(slf_list_extra); - free(nuf_list); - free(nuf_list_extra); + free_hook_func_list(&nuf_list); free(ncf2_list); free(ncf2_list_extra); free(duf_list); free(duf_list_extra); free(ncf_list); free(ncf_list_extra); - free(jf_list); - free(jf_list_extra); + free_hook_func_list(&jf_list); free(dcf_list); free(dcf_list_extra); free(pf_list);