]> jfr.im git - irc/freenode/solanum.git/commitdiff
Use linear channel list comparisons
authorEd Kellett <redacted>
Tue, 26 May 2020 23:16:22 +0000 (00:16 +0100)
committerEd Kellett <redacted>
Mon, 19 Oct 2020 19:15:26 +0000 (20:15 +0100)
extensions/hide_uncommon_channels.c
include/hook.h
ircd/tgchange.c
modules/m_whois.c

index ff1d0cb6b3fa4da0632ea353f56cf5a7b63584bc..586dc36023b297557965428c0fe1947ef65b8f16 100644 (file)
@@ -14,7 +14,7 @@
 
 static const char hide_desc[] = "Hides channel memberships not shared";
 
-static void h_huc_doing_whois_channel_visibility(hook_data_client *);
+static void h_huc_doing_whois_channel_visibility(void *);
 
 mapi_hfn_list_av1 huc_hfnlist[] = {
        { "doing_whois_channel_visibility", (hookfn) h_huc_doing_whois_channel_visibility },
@@ -24,7 +24,8 @@ mapi_hfn_list_av1 huc_hfnlist[] = {
 DECLARE_MODULE_AV2(hide_uncommon_channels, NULL, NULL, NULL, NULL, huc_hfnlist, NULL, NULL, hide_desc);
 
 static void
-h_huc_doing_whois_channel_visibility(hook_data_client *hdata)
+h_huc_doing_whois_channel_visibility(void *data_)
 {
-       hdata->approved = ((PubChannel(hdata->chptr) && !IsInvisible(hdata->target)) || IsMember((hdata->client), (hdata->chptr)));
+       hook_data_channel_visibility *data = data_;
+       data->approved = data->approved && (!IsInvisible(data->targms->client_p) || data->clientms != NULL);
 }
index ddcf6b6cb5a4c08ccfa3f52d0daac5d5cefd5394..f3a2b88f7e1eafab7a03e326098c978f86444088 100644 (file)
@@ -79,8 +79,6 @@ typedef struct
 {
        struct Client *client;
        struct Client *target;
-       struct Channel *chptr;
-       int approved;
 } hook_data_client;
 
 typedef struct
@@ -109,6 +107,15 @@ typedef struct
        const char *error;
 } hook_data_channel_approval;
 
+typedef struct
+{
+       struct Client *client;
+       struct Channel *chptr;
+       struct membership *clientms;
+       struct membership *targms;
+       int approved;
+} hook_data_channel_visibility;
+
 typedef struct
 {
        struct Client *client;
index b9f427bd5d65cdb8c645a0ba80a2f6cea007131b..c8e595aab8f0548b60ae9597f932dd647ca41eed 100644 (file)
@@ -38,14 +38,29 @@ static int add_hashed_target(struct Client *source_p, uint32_t hashv);
 struct Channel *
 find_allowing_channel(struct Client *source_p, struct Client *target_p)
 {
-       rb_dlink_node *ptr;
-       struct membership *msptr;
+       rb_dlink_node *ps = source_p->user->channel.head;
+       rb_dlink_node *pt = target_p->user->channel.head;
 
-       RB_DLINK_FOREACH(ptr, source_p->user->channel.head)
+       while (ps && pt)
        {
-               msptr = ptr->data;
-               if (is_chanop_voiced(msptr) && IsMember(target_p, msptr->chptr))
-                       return msptr->chptr;
+               struct membership *ms = ps->data;
+               struct membership *mt = pt->data;
+               int d;
+               if (ms->chptr == mt->chptr)
+               {
+                       if (is_chanop_voiced(ms))
+                               return ms->chptr;
+                       ps = ps->next;
+                       pt = pt->next;
+                       continue;
+               }
+               d = irccmp(ms->chptr->chname, mt->chptr->chname);
+               if (d < 0)
+                       ps = ps->next;
+               else if (d > 0)
+                       pt = pt->next;
+               else
+                       assert("different channels can't have equal names" && false);
        }
        return NULL;
 }
index 6fd1bcfc5657fa63fb9bcc199a36352a58c8aaca..d07f0fc6d09d9f6bb53094a42ef45e815b0bf7c9 100644 (file)
@@ -225,8 +225,6 @@ single_whois(struct Client *source_p, struct Client *target_p, int operspy)
 {
        char buf[BUFSIZE];
        rb_dlink_node *ptr;
-       struct membership *msptr;
-       struct Channel *chptr;
        int cur_len = 0;
        int mlen;
        char *t;
@@ -269,19 +267,57 @@ single_whois(struct Client *source_p, struct Client *target_p, int operspy)
 
        if (!IsService(target_p))
        {
-               RB_DLINK_FOREACH(ptr, target_p->user->channel.head)
-               {
-                       msptr = ptr->data;
-                       chptr = msptr->chptr;
+               hook_data_channel_visibility hdata_vis;
+               rb_dlink_node *ps = source_p->user->channel.head;
+               rb_dlink_node *pt = target_p->user->channel.head;
+
+               hdata_vis.client = source_p;
 
-                       hdata.chptr = chptr;
+               while (pt)
+               {
+                       struct membership *mt = pt->data;
+                       int dir = 0;
+                       if (ps != NULL)
+                       {
+                               struct membership *ms = ps->data;
+                               if (ms->chptr == mt->chptr)
+                               {
+                                       ps = ps->next;
+                                       pt = pt->next;
+                                       hdata_vis.chptr = mt->chptr;
+                                       hdata_vis.clientms = ms;
+                                       hdata_vis.targms = mt;
+                                       hdata_vis.approved = 1;
+                                       dir = 0;
+                               }
+                               else
+                               {
+                                       dir = irccmp(ms->chptr->chname, mt->chptr->chname);
+                               }
+                       }
+                       else
+                       {
+                               dir = 1;
+                       }
+                       if (dir < 0)
+                       {
+                               ps = ps->next;
+                               continue;
+                       }
+                       else if (dir > 0)
+                       {
+                               pt = pt->next;
+                               hdata_vis.chptr = mt->chptr;
+                               hdata_vis.clientms = NULL;
+                               hdata_vis.targms = mt;
+                               hdata_vis.approved = PubChannel(mt->chptr);
+                       }
 
-                       hdata.approved = ShowChannel(source_p, chptr);
-                       call_hook(doing_whois_channel_visibility_hook, &hdata);
+                       call_hook(doing_whois_channel_visibility_hook, &hdata_vis);
 
-                       if(hdata.approved || operspy)
+                       if(hdata_vis.approved || operspy)
                        {
-                               if((cur_len + strlen(chptr->chname) + 3) > (BUFSIZE - 5))
+                               if((cur_len + strlen(mt->chptr->chname) + 3) > (BUFSIZE - 5))
                                {
                                        sendto_one(source_p, "%s", buf);
                                        cur_len = mlen + extra_space;
@@ -289,9 +325,9 @@ single_whois(struct Client *source_p, struct Client *target_p, int operspy)
                                }
 
                                tlen = sprintf(t, "%s%s%s ",
-                                               hdata.approved ? "" : "!",
-                                               find_channel_status(msptr, 1),
-                                               chptr->chname);
+                                               hdata_vis.approved ? "" : "!",
+                                               find_channel_status(mt, 1),
+                                               mt->chptr->chname);
                                t += tlen;
                                cur_len += tlen;
                        }