]> jfr.im git - irc/evilnet/x3.git/blobdiff - src/hash.c
Couple of srvx updates.
[irc/evilnet/x3.git] / src / hash.c
index 44b56d82b311df4d7b08f3baab93359927c070f8..80ac00223cb2c1e491b96778370796f121df844a 100644 (file)
@@ -39,7 +39,7 @@ unsigned int max_clients, invis_clients;
 time_t max_clients_time;
 struct userList curr_opers;
 
-static void hash_cleanup(void);
+static void hash_cleanup(void *extra);
 
 void init_structs(void)
 {
@@ -47,7 +47,7 @@ void init_structs(void)
     clients = dict_new();
     servers = dict_new();
     userList_init(&curr_opers);
-    reg_exit_func(hash_cleanup);
+    reg_exit_func(hash_cleanup, NULL);
 }
 
 int userList_contains(struct userList *list, struct userNode *user)
@@ -701,33 +701,38 @@ AddChannelUser(struct userNode *user, struct chanNode* channel)
 }
 
 static part_func_t *pf_list;
+static void **pf_list_extra;
 static unsigned int pf_size = 0, pf_used = 0;
 
 void
-reg_part_func(part_func_t handler)
+reg_part_func(part_func_t handler, void *extra)
 {
     if (pf_used == pf_size) {
        if (pf_size) {
            pf_size <<= 1;
            pf_list = realloc(pf_list, pf_size*sizeof(part_func_t));
+        pf_list_extra = realloc(pf_list_extra, pf_size*sizeof(void*));
        } else {
            pf_size = 8;
            pf_list = malloc(pf_size*sizeof(part_func_t));
+        pf_list_extra = malloc(pf_size*sizeof(void*));
        }
     }
-    pf_list[pf_used++] = handler;
+    pf_list[pf_used] = handler;
+    pf_list_extra[pf_used++] = extra;
 }
 
 void
-unreg_part_func(part_func_t handler)
+unreg_part_func(part_func_t handler, void *extra)
 {
     unsigned int i;
     for (i=0; i<pf_used; i++)
-        if (pf_list[i] == handler)
+        if (pf_list[i] == handler && pf_list_extra[i] == extra)
             break;
     if (i == pf_used)
         return;
     memmove(pf_list+i, pf_list+i+1, (pf_used-i-1)*sizeof(pf_list[0]));
+    memmove(pf_list_extra+i, pf_list_extra+i+1, (pf_used-i-1)*sizeof(pf_list_extra[0]));
     pf_used--;
 }
 
@@ -768,7 +773,7 @@ DelChannelUser(struct userNode* user, struct chanNode* channel, const char *reas
 
     /* make callbacks */
     for (n=0; n<pf_used; n++)
-       pf_list[n](mNode, reason);
+       pf_list[n](mNode, reason, pf_list_extra[n]);
 
     /* free memory */
     free(mNode);
@@ -780,6 +785,7 @@ DelChannelUser(struct userNode* user, struct chanNode* channel, const char *reas
 }
 
 static kick_func_t *kf_list;
+static void **kf_list_extra;
 static unsigned int kf_size = 0, kf_used = 0;
 
 void
@@ -792,7 +798,7 @@ KickChannelUser(struct userNode* target, struct chanNode* channel, struct userNo
 
     /* This may break things, but lets see.. -Rubin */
     for (n=0; n<kf_used; n++)
-        kf_list[n](kicker, target, channel);
+        kf_list[n](kicker, target, channel, kf_list_extra[n]);
 
     /* don't remove them from the channel, since the server will send a PART */
     irc_kick(kicker, target, channel, why);
@@ -806,18 +812,21 @@ KickChannelUser(struct userNode* target, struct chanNode* channel, struct userNo
 }
 
 void
-reg_kick_func(kick_func_t handler)
+reg_kick_func(kick_func_t handler, void *extra)
 {
     if (kf_used == kf_size) {
        if (kf_size) {
            kf_size <<= 1;
            kf_list = realloc(kf_list, kf_size*sizeof(kick_func_t));
+        kf_list_extra = realloc(kf_list_extra, kf_size*sizeof(void*));
        } else {
            kf_size = 8;
            kf_list = malloc(kf_size*sizeof(kick_func_t));
+        kf_list_extra = malloc(kf_size*sizeof(void*));
        }
     }
-    kf_list[kf_used++] = handler;
+    kf_list[kf_used] = handler;
+    kf_list_extra[kf_used++] = extra;
 }
 
 void
@@ -834,7 +843,7 @@ ChannelUserKicked(struct userNode* kicker, struct userNode* victim, struct chanN
         mn->idle_since = now;
 
     for (n=0; n<kf_used; n++)
-       kf_list[n](kicker, victim, channel);
+       kf_list[n](kicker, victim, channel, kf_list_extra[n]);
 
     DelChannelUser(victim, channel, 0, 0);
 
@@ -988,7 +997,7 @@ DEFINE_LIST(channelList, struct chanNode*)
 DEFINE_LIST(serverList, struct server*)
 
 static void
-hash_cleanup(void)
+hash_cleanup(UNUSED_ARG(void *extra))
 {
     dict_iterator_t it, next;
 
@@ -1017,7 +1026,9 @@ hash_cleanup(void)
     free(dcf_list);
     free(dcf_list_extra);
     free(pf_list);
+    free(pf_list_extra);
     free(kf_list);
+    free(kf_list_extra);
     free(tf_list);
     free(tf_list_extra);
 }