Get rid of ms_names(); clean up m_names() to be more uniform.
authorMichael Poole <mdpoole@troilus.org>
Tue, 14 Aug 2007 03:02:24 +0000 (03:02 +0000)
committerMichael Poole <mdpoole@troilus.org>
Tue, 14 Aug 2007 03:02:24 +0000 (03:02 +0000)
git-svn-id: file:///home/klmitch/undernet-ircu/undernet-ircu-svn/ircu2/branches/u2_10_12_branch@1827 c9e4aea6-c8fd-4c43-8297-357d70d61c8c

ChangeLog
ircd/m_names.c
ircd/parse.c

index bf5b31bc7d418b32399d52221a9ec9eb77459557..0decd5e41473b22db817a96e470d1dc88d2f750f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2007-08-13  Michael Poole <mdpoole@troilus.org>
+
+       * ircd/m_names.c (do_names): Add NAMES_DEL to comment.  Avoid use
+       of strcat().  Get rid of ms_names(), which was basically a copy of
+       m_names(), and merge the "showingdelayed" changes into m_names().
+       Replace the recursion with iteration.
+
+       * ircd/parse.c (msgtab): Use m_names(), not ms_names().
+
 2007-08-08  Michael Poole <mdpoole@troilus.org>
 
        * ircd/s_auth.c (report_iauth_conf): Remove end-of-stats message;
index 54a299d33c5142f5f4fa14421f3de55248bfca82..8b9509fbcc783ef875fd59966c51daff259fd180 100644 (file)
  *
  *  NAMES_ALL - Lists all users on channel.
  *  NAMES_VIS - Only list visible (-i) users. --Gte (04/06/2000).
+ *  NAMES_DEL - Show join-delayed names list.
  *  NAMES_EON - When OR'd with the other two, adds an 'End of Names' numeric
  *              used by m_join
  *
@@ -162,37 +163,26 @@ void do_names(struct Client* sptr, struct Channel* chptr, int filter)
     if ((!IsDelayedJoin(member) || (member->user == sptr)) && (filter & NAMES_DEL))
         continue;
 
-    if (needs_space) {
-       strcat(buf, " ");
-      idx++;
-    }
+    if (needs_space)
+      buf[idx++] = ' ';
     needs_space=1;
     if (IsZombie(member))
-    {
-      strcat(buf, "!");
-      idx++;
-    }
+      buf[idx++] = '!';
     else if (IsChanOp(member))
-    {
-      strcat(buf, "@");
-      idx++;
-    }
+      buf[idx++] = '@';
     else if (HasVoice(member))
-    {
-      strcat(buf, "+");
-      idx++;
-    }
-    strcat(buf, cli_name(c2ptr));
+      buf[idx++] = '+';
+    strcpy(buf + idx, cli_name(c2ptr));
     idx += strlen(cli_name(c2ptr));
     flag = 1;
     if (mlen + idx + NICKLEN + 5 > BUFSIZE)
       /* space, modifier, nick, \r \n \0 */
-    { 
+    {
       send_reply(sptr, (filter & NAMES_DEL) ? RPL_DELNAMREPLY : RPL_NAMREPLY, buf);
       strcpy(buf, "* ");
       ircd_strncpy(buf + 2, chptr->chname, len + 1);
-      buf[len + 2] = 0;
-      strcat(buf, " :");
+      buf[len + 2] = ':';
+      buf[len + 3] = '\0';
       if (PubChannel(chptr))
         *buf = '=';
       else if (SecretChannel(chptr))
@@ -227,7 +217,7 @@ int m_names(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
 
   if (parc > 1 && !ircd_strcmp(parv[1], "-D")) {
     para = (parc > 2) ? parv[2] : 0;
-    showingdelayed = 1;
+    showingdelayed = NAMES_DEL;
     if (parc > 3 && hunt_server_cmd(sptr, CMD_NAMES, cptr, 1, "%s %s %C", 3, parc, parv))
       return 0;
   } else if (parc > 2 && hunt_server_cmd(sptr, CMD_NAMES, cptr, 1, "%s %C", 2, parc, parv))
@@ -237,268 +227,105 @@ int m_names(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
     send_reply(sptr, RPL_ENDOFNAMES, "*");
     return 0;
   }
-  else if (*para == '0')
-    *para = '\0';
-  
-  s = strchr(para, ','); /* Recursively call m_names for each comma-separated channel. Eww. */
-  if (s) {
-    *s++ = '\0';
-    parv[1+showingdelayed] = s;
-    m_names(cptr, sptr, parc, parv);
-  }
-  /*
-   * Special Case 1: "/names 0". 
-   * Full list as per RFC. 
-   */
-
-  if (!*para) { 
-    int idx; 
-    int mlen;
-    int flag;
-    struct Channel *ch3ptr;
-    char buf[BUFSIZE]; 
 
-    mlen = strlen(cli_name(&me)) + 10 + strlen(cli_name(sptr));
-
-    /* List all visible channels/visible members */ 
-
-    for (ch2ptr = GlobalChannelList; ch2ptr; ch2ptr = ch2ptr->next)
-    { 
-      if (!ShowChannel(sptr, ch2ptr))
-        continue;                 /* Don't show secret chans. */ 
-
-      if (find_channel_member(sptr, ch2ptr))
-      {
-        do_names(sptr, ch2ptr, (showingdelayed?NAMES_DEL:0)|NAMES_ALL); /* Full list if we're in this chan. */
-      } else { 
-        do_names(sptr, ch2ptr, (showingdelayed?NAMES_DEL:0)|NAMES_VIS);
-      }
-    } 
-
-    /* List all remaining users on channel '*' */
-
-    strcpy(buf, "* * :");
-    idx = 5;
-    flag = 0;
-
-    for (c2ptr = GlobalClientList; c2ptr; c2ptr = cli_next(c2ptr))
+  do {
+    s = strchr(para, ',');
+    if (s)
+      *s++ = '\0';
+    /*
+     * Special Case 1: "/names 0". 
+     * Full list as per RFC. 
+     */
+    if ((*para == '0') || (*para == '\0'))
     {
-      int showflag = 0;
-
-      if (!IsUser(c2ptr) || (sptr != c2ptr && IsInvisible(c2ptr)))
-        continue;
-
-      member = cli_user(c2ptr)->channel;
-
-      while (member)
-      {
-        ch3ptr = member->channel;
-  
-        if (PubChannel(ch3ptr) || find_channel_member(sptr, ch3ptr))
-          showflag = 1;
-        member = member->next_channel;
-      }
-
-      if (showflag)               /* Have we already shown them? */
-        continue;
-      strcat(buf, cli_name(c2ptr));
-      strcat(buf, " ");
-      idx += strlen(cli_name(c2ptr)) + 1;
-      flag = 1;
+      int idx; 
+      int mlen;
+      int flag;
+      struct Channel *ch3ptr;
+      char buf[BUFSIZE]; 
+
+      mlen = strlen(cli_name(&me)) + 10 + strlen(cli_name(sptr));
+
+      /* List all visible channels/visible members */ 
+
+      for (ch2ptr = GlobalChannelList; ch2ptr; ch2ptr = ch2ptr->next)
+      { 
+        if (!ShowChannel(sptr, ch2ptr))
+          continue;                 /* Don't show secret chans. */ 
+        else if (find_channel_member(sptr, ch2ptr))
+          do_names(sptr, ch2ptr, showingdelayed|NAMES_ALL); /* Full list if we're in this chan. */
+        else
+          do_names(sptr, ch2ptr, showingdelayed|NAMES_VIS);
+      } 
+
+      /* List all remaining users on channel '*' */
+
+      strcpy(buf, "* * :");
+      idx = 5;
+      flag = 0;
 
-      if (mlen + idx + NICKLEN + 3 > BUFSIZE)     /* space, \r\n\0 */
-      {
-        send_reply(sptr, RPL_NAMREPLY, buf);
-        strcpy(buf, "* * :");
-        idx = 5;
-        flag = 0;
-      }
-    }
-    if (flag)
-      send_reply(sptr, RPL_NAMREPLY, buf);
-    send_reply(sptr, RPL_ENDOFNAMES, "*");
-    return 1; 
-  } 
-
-  /*
-   *  Special Case 2: User is on this channel, requesting full names list.
-   *  (As performed with each /join) - ** High frequency usage **
-   */
-
-  chptr = FindChannel(para); 
-
-  if (chptr) {
-    member = find_member_link(chptr, sptr);
-    if (member)
-    { 
-      do_names(sptr, chptr, (showingdelayed?NAMES_DEL:0)|NAMES_ALL);
-      if (!EmptyString(para))
+      for (c2ptr = GlobalClientList; c2ptr; c2ptr = cli_next(c2ptr))
       {
-        send_reply(sptr, RPL_ENDOFNAMES, chptr ? chptr->chname : para);
-        return 1;
-      }
-    }
-      else 
-    {
-      /*
-       *  Special Case 3: User isn't on this channel, show all visible users, in 
-       *  non secret channels.
-       */ 
-      do_names(sptr, chptr, (showingdelayed?NAMES_DEL:0)|NAMES_VIS);
-      send_reply(sptr, RPL_ENDOFNAMES, para);
-    } 
-  } else { /* Channel doesn't exist. */ 
-      send_reply(sptr, RPL_ENDOFNAMES, para); 
-  }
-  return 1;
-}
+        int showflag = 0;
 
-/*
- * ms_names - server message handler
- *
- * parv[0] = sender prefix
- * parv[1] = channel
- */
-int ms_names(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
-{
-  struct Channel *chptr; 
-  struct Channel *ch2ptr; 
-  struct Client *c2ptr;
-  struct Membership* member; 
-  char* s;
-  char* para = parc > 1 ? parv[1] : 0; 
-  int showingdelayed = 0;
+        if (!IsUser(c2ptr) || (sptr != c2ptr && IsInvisible(c2ptr)))
+          continue;
 
-  if (parc > 1 && !ircd_strcmp(parv[1], "-D")) {
-    para = (parc > 2) ? parv[2] : 0;
-    showingdelayed = NAMES_DEL;
-    if (parc > 3 && hunt_server_cmd(sptr, CMD_NAMES, cptr, 1, "%s %s %C", 3, parc, parv))
-      return 0;
-  } else if (parc > 2 && hunt_server_cmd(sptr, CMD_NAMES, cptr, 1, "%s %C", 2, parc, parv))
-    return 0;
+        member = cli_user(c2ptr)->channel;
 
-  if (EmptyString(para)) {
-    send_reply(sptr, RPL_ENDOFNAMES, "*");
-    return 0;
-  }
-  else if (*para == '0')
-    *para = '\0';
+        while (member)
+        {
+          ch3ptr = member->channel;
   
-  s = strchr(para, ','); /* Recursively call m_names for each comma-separated channel. */
-  if (s) {
-    *s++ = '\0';
-    parv[1+!!showingdelayed] = s;
-    m_names(cptr, sptr, parc, parv);
-  }
+          if (PubChannel(ch3ptr) || find_channel_member(sptr, ch3ptr))
+            showflag = 1;
  
-  /*
-   * Special Case 1: "/names 0".
-   * Full list as per RFC. 
-   */
-
-  if (!*para) { 
-    int idx; 
-    int mlen;
-    int flag;
-    struct Channel *ch3ptr;
-    char buf[BUFSIZE]; 
-
-    mlen = strlen(cli_name(&me)) + 10 + strlen(cli_name(sptr));
-
-    /* List all visible channels/visible members */ 
-
-    for (ch2ptr = GlobalChannelList; ch2ptr; ch2ptr = ch2ptr->next)
-    { 
-      if (!ShowChannel(sptr, ch2ptr))
-        continue;                 /* Don't show secret chans. */ 
+          member = member->next_channel;
+        }
 
-      if (find_channel_member(sptr, ch2ptr))
-      {
-        do_names(sptr, ch2ptr, showingdelayed|NAMES_ALL); /* Full list if we're in this chan. */
-      } else { 
-        do_names(sptr, ch2ptr, showingdelayed|NAMES_VIS);
-      }
-    } 
-    /* List all remaining users on channel '*' */
-
-    strcpy(buf, "* * :");
-    idx = 5;
-    flag = 0;
-
-    for (c2ptr = GlobalClientList; c2ptr; c2ptr = cli_next(c2ptr))
-    {
-      int showflag = 0;
-
-      if (!IsUser(c2ptr) || (sptr != c2ptr && IsInvisible(c2ptr)))
-        continue;
-
-      member = cli_user(c2ptr)->channel; 
-
-      while (member)
-      {
-        ch3ptr = member->channel;
-  
-        if (PubChannel(ch3ptr) || find_channel_member(sptr, ch3ptr))
-          showflag = 1;
+        if (showflag)               /* Have we already shown them? */
+          continue;
  
-        member = member->next_channel;
+        strcpy(buf + idx, cli_name(c2ptr));
+        idx += strlen(cli_name(c2ptr));
+        buf[idx++] = ' ';
+        flag = 1;
+
+        if (mlen + idx + NICKLEN + 3 > BUFSIZE)     /* space, \r\n\0 */
+        {
+          send_reply(sptr, RPL_NAMREPLY, buf);
+          strcpy(buf, "* * :");
+          idx = 5;
+          flag = 0;
+        }
       }
-
-      if (showflag)               /* Have we already shown them? */
-        continue;
-      strcat(buf, cli_name(c2ptr));
-      strcat(buf, " ");
-      idx += strlen(cli_name(c2ptr)) + 1;
-      flag = 1;
-
-      if (mlen + idx + NICKLEN + 3 > BUFSIZE)     /* space, \r\n\0 */
-      {
+      if (flag)
         send_reply(sptr, RPL_NAMREPLY, buf);
-        strcpy(buf, "* * :");
-        idx = 5;
-        flag = 0;
-      }
+      send_reply(sptr, RPL_ENDOFNAMES, "*");
     }
-    if (flag)
-      send_reply(sptr, RPL_NAMREPLY, buf);
-    send_reply(sptr, RPL_ENDOFNAMES, "*");
-    return 1; 
-  } 
-
-  /*
-   *  Special Case 2: User is on this channel, requesting full names list.
-   *  (As performed with each /join) - ** High frequency usage **
-   */
-
-  chptr = FindChannel(para); 
-
-  if (chptr) {
-    member = find_member_link(chptr, sptr);
-    if (member)
-    { 
-      do_names(sptr, chptr, showingdelayed|NAMES_ALL);
-      if (!EmptyString(para))
+    else if ((chptr = FindChannel(para)) != NULL)
+    {
+      member = find_member_link(chptr, sptr);
+      if (member)
       {
-        send_reply(sptr, RPL_ENDOFNAMES, chptr ? chptr->chname : para);
-        return 1;
+        /*
+         *  Special Case 2: User is on this channel, requesting full names list.
+         *  (As performed with each /join) - ** High frequency usage **
+         */
+        do_names(sptr, chptr, showingdelayed|NAMES_ALL|NAMES_EON);
       }
+      else
+      {
+        /*
+         *  Special Case 3: User isn't on this channel, show all visible users, in 
+         *  non secret channels.
+         */ 
+        do_names(sptr, chptr, showingdelayed|NAMES_VIS|NAMES_EON);
+      } 
     }
-      else 
-    {
-      /*
-       *  Special Case 3: User isn't on this channel, show all visible users, in 
-       *  non secret channels.
-       */ 
-      do_names(sptr, chptr, showingdelayed|NAMES_VIS);
-    } 
-  } else { /* Channel doesn't exist. */ 
-      send_reply(sptr, RPL_ENDOFNAMES, para); 
-  }
+    else
+        send_reply(sptr, RPL_ENDOFNAMES, para);
+  } while ((para = s) != NULL);
+
   return 1;
 }
index d90c5192c0b66494827bf6788325404d037ba67a..9b6b5b3d4cece3f8f0268f68d2cea40f5369191f 100644 (file)
@@ -342,7 +342,7 @@ struct Message msgtab[] = {
     TOK_NAMES,
     0, MAXPARA, MFLG_SLOW, 0, NULL,
     /* UNREG, CLIENT, SERVER, OPER, SERVICE */
-    { m_unregistered, m_names, ms_names, m_names, m_ignore }
+    { m_unregistered, m_names, m_names, m_names, m_ignore }
   },
   {
     MSG_USERHOST,