Send RPL_TRACEEND at end of trace output.
authorMichael Poole <mdpoole@troilus.org>
Sun, 12 Sep 2004 01:42:17 +0000 (01:42 +0000)
committerMichael Poole <mdpoole@troilus.org>
Sun, 12 Sep 2004 01:42:17 +0000 (01:42 +0000)
git-svn-id: file:///home/klmitch/undernet-ircu/undernet-ircu-svn/ircu2/trunk@1134 c9e4aea6-c8fd-4c43-8297-357d70d61c8c

ChangeLog
include/numeric.h
ircd/m_trace.c
ircd/s_err.c

index a50aa94ba8047ae3a9938ca42f73bd7f3520f842..4320de59ec5eb2e9fb3a7c7b4783aca16a945e2a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2004-09-11  Michael Poole <mdpoole@troilus.org>
+
+       * include/numeric.h, ircd/s_err.c: Remove RPL_TRACEPING, and
+       replace with RPL_TRACEEND.
+
+       * ircd/s_trace.c: Move all the duplicated code in m*_trace() to
+       do_trace().  Implement RPL_TRACEEND, per RFE#830291.
+
 2003-06-20  Alexander Maassen <outsider@key2peace.org>
 
        * ircd/m_topic.c : Don't allow banned users to set a topic in a
index 0dfb1a2fec48ef4473fe66474b55b8d31441996d..ed631d2e7d1d06b18d45795998c99f6db330749d 100644 (file)
@@ -156,8 +156,7 @@ extern const struct Numeric* get_error_numeric(int err);
 #define RPL_ADMINEMAIL       259
 
 #define RPL_TRACELOG         261       /* unused */
-#define RPL_TRACEPING        262        /* Extension to RFC1459, unused */
-/*     RPL_TRACEEND         262           efnet(?) Numerics List: IRCnet */
+#define RPL_TRACEEND        262        /* efnet/IRCnet */
 /*      RPL_LOAD_THROTTLED   263           efnet/hybrid */
 /*     RPL_TRYAGAIN         263           Numerics List: IRCnet */
 /*     RPL_LOAD2HI          263           Dalnet */
index 34547ee5dceb33eee25202ce5da1fa2fe1eed4c6..e311682a443778f8557571e1c1126603e2aef21d 100644 (file)
 #include <assert.h>
 #include <string.h>
 
-/*
- * m_trace - generic message handler
- *
- * parv[0] = sender prefix
- * parv[1] = nick or servername
- * parv[2] = 'target' servername
- */
-int m_trace(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
+void do_trace(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
 {
   int i;
   struct Client *acptr;
@@ -121,9 +114,6 @@ int m_trace(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
   int wilds;
   int dow;
 
-  if (feature_bool(FEAT_HIS_TRACE))
-    return send_reply(cptr, ERR_NOPRIVILEGES);
-
   if (parc < 2 || BadPtr(parv[1]))
   {
     /* just "TRACE" without parameters. Must be from local client */
@@ -148,7 +138,7 @@ int m_trace(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
       parv[3] = 0;
       if ((i = hunt_server_cmd(sptr, CMD_TRACE, cptr, IsServer(acptr),
                               "%s :%C", 2, parc, parv)) == HUNTED_NOSUCH)
-        return 0;
+        return;
     }
     else
       i = HUNTED_ISME;
@@ -161,7 +151,7 @@ int m_trace(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
       acptr = FindNServer(parv[2]);
     if ((i = hunt_server_cmd(sptr, CMD_TRACE, cptr, 0, "%s :%C", 2, parc,
                             parv)) == HUNTED_NOSUCH)
-      return 0;
+      return;
     tname = parv[1];
   }
 
@@ -173,7 +163,7 @@ int m_trace(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
     send_reply(sptr, RPL_TRACELINK,
               version, debugmode, tname,
               acptr ? cli_name(cli_from(acptr)) : "<No_match>");
-    return 0;
+    return;
   }
 
   doall = (parv[1] && (parc > 1)) ? !match(tname, cli_name(&me)) : 1;
@@ -181,8 +171,10 @@ int m_trace(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
   dow = wilds || doall;
 
   /* Don't give (long) remote listings to lusers */
-  if (dow && !MyConnect(sptr) && !IsAnOper(sptr))
-    return 0;
+  if (dow && !MyConnect(sptr) && !IsAnOper(sptr)) {
+    send_reply(sptr, RPL_TRACEEND);
+    return;
+  }
 
   for (i = 0; i < MAXCONNECTIONS; i++)
     link_s[i] = 0, link_u[i] = 0;
@@ -292,20 +284,27 @@ int m_trace(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
    * Add these lines to summarize the above which can get rather long
    * and messy when done remotely - Avalon
    */
-  if (!IsAnOper(sptr) || !cnt) {
-    if (!cnt)
-      /* let the user have some idea that its at the end of the trace */
-      send_reply(sptr, RPL_TRACESERVER, 0, link_s[cli_fd(&me)],
-                 link_u[cli_fd(&me)], "<No_match>", *(cli_serv(&me)->by) ?
-                 cli_serv(&me)->by : "*", "*", cli_name(&me), 0, 0);
-    return 0;
-  }
-  if (doall) {
+  if (IsAnOper(sptr) && doall) {
     for (cl = get_class_list(); cl; cl = cl->next) {
       if (Links(cl) > 0)
        send_reply(sptr, RPL_TRACECLASS, ConClass(cl), Links(cl));
     }
   }
+  send_reply(sptr, RPL_TRACEEND);
+}
+
+/*
+ * m_trace - generic message handler
+ *
+ * parv[0] = sender prefix
+ * parv[1] = nick or servername
+ * parv[2] = 'target' servername
+ */
+int m_trace(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
+{
+  if (feature_bool(FEAT_HIS_TRACE))
+    return send_reply(cptr, ERR_NOPRIVILEGES);
+  do_trace(cptr, sptr, parc, parv);
   return 0;
 }
 
@@ -318,194 +317,7 @@ int m_trace(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
  */
 int ms_trace(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
 {
-  int i;
-  struct Client *acptr;
-  const struct ConnectionClass* cl;
-  char *tname;
-  int doall;
-  int link_s[MAXCONNECTIONS];
-  int link_u[MAXCONNECTIONS];
-  int cnt = 0;
-  int wilds;
-  int dow;
-
-  if (parc < 2 || BadPtr(parv[1])) {
-    /* just "TRACE" without parameters. Must be from local client */
-    parc = 1;
-    acptr = &me;
-    tname = cli_name(&me);
-    i = HUNTED_ISME;
-  } else if (parc < 3 || BadPtr(parv[2])) {
-    /* No target specified. Make one before propagating. */
-    parc = 2;
-    tname = parv[1];
-    if ((acptr = find_match_server(parv[1])) ||
-        ((acptr = FindClient(parv[1])) && !MyUser(acptr))) {
-      if (IsUser(acptr))
-        parv[2] = cli_name(cli_user(acptr)->server);
-      else
-        parv[2] = cli_name(acptr);
-      parc = 3;
-      parv[3] = 0;
-
-      if ((i = hunt_server_cmd(sptr, CMD_TRACE, cptr, IsServer(acptr),
-                              "%s :%C", 2, parc, parv)) == HUNTED_NOSUCH)
-        return 0;
-    } else
-      i = HUNTED_ISME;
-  } else {
-    /* Got "TRACE <tname> :<target>" */
-    parc = 3;
-    if (MyUser(sptr) || Protocol(cptr) < 10)
-      acptr = find_match_server(parv[2]);
-    else
-      acptr = FindNServer(parv[2]);
-    if ((i = hunt_server_cmd(sptr, CMD_TRACE, cptr, 0, "%s :%C", 2, parc,
-                            parv)) == HUNTED_NOSUCH)
-      return 0;
-    tname = parv[1];
-  }
-
-  if (i == HUNTED_PASS) {
-    if (!acptr)
-      acptr = next_client(GlobalClientList, tname);
-    else
-      acptr = cli_from(acptr);
-    send_reply(sptr, RPL_TRACELINK,
-              version, debugmode, tname,
-              acptr ? cli_name(cli_from(acptr)) : "<No_match>");
-    return 0;
-  }
-
-  doall = (parv[1] && (parc > 1)) ? !match(tname, cli_name(&me)) : 1;
-  wilds = !parv[1] || strchr(tname, '*') || strchr(tname, '?');
-  dow = wilds || doall;
-
-  /* Don't give (long) remote listings to lusers */
-  if (dow && !MyConnect(sptr) && !IsAnOper(sptr))
-    return 0;
-
-  for (i = 0; i < MAXCONNECTIONS; i++)
-    link_s[i] = 0, link_u[i] = 0;
-
-  if (doall) {
-    for (acptr = GlobalClientList; acptr; acptr = cli_next(acptr)) {
-      if (IsUser(acptr))
-        link_u[cli_fd(cli_from(acptr))]++;
-      else if (IsServer(acptr))
-        link_s[cli_fd(cli_from(acptr))]++;
-    }
-  }
-
-  /* report all direct connections */
-
-  for (i = 0; i <= HighestFd; i++) {
-    const char *conClass;
-
-    if (!(acptr = LocalClientArray[i])) /* Local Connection? */
-      continue;
-    if (IsInvisible(acptr) && dow && !(MyConnect(sptr) && IsOper(sptr)) &&
-        !IsAnOper(acptr) && (acptr != sptr))
-      continue;
-    if (!doall && wilds && match(tname, cli_name(acptr)))
-      continue;
-    if (!dow && 0 != ircd_strcmp(tname, cli_name(acptr)))
-      continue;
-    conClass = get_client_class(acptr);
-
-    switch (cli_status(acptr)) {
-      case STAT_CONNECTING:
-       send_reply(sptr, RPL_TRACECONNECTING, conClass, cli_name(acptr));
-        cnt++;
-        break;
-      case STAT_HANDSHAKE:
-       send_reply(sptr, RPL_TRACEHANDSHAKE, conClass, cli_name(acptr));
-        cnt++;
-        break;
-      case STAT_ME:
-        break;
-      case STAT_UNKNOWN:
-      case STAT_UNKNOWN_USER:
-       send_reply(sptr, RPL_TRACEUNKNOWN, conClass,
-                  get_client_name(acptr, HIDE_IP));
-        cnt++;
-        break;
-      case STAT_UNKNOWN_SERVER:
-       send_reply(sptr, RPL_TRACEUNKNOWN, conClass, "Unknown Server");
-        cnt++;
-        break;
-      case STAT_USER:
-        /* Only opers see users if there is a wildcard
-           but anyone can see all the opers. */
-        if ((IsAnOper(sptr) && (MyUser(sptr) ||
-            !(dow && IsInvisible(acptr)))) || !dow || IsAnOper(acptr)) {
-          if (IsAnOper(acptr))
-           send_reply(sptr, RPL_TRACEOPERATOR, conClass,
-                      get_client_name(acptr, SHOW_IP),
-                      CurrentTime - cli_lasttime(acptr));
-          else
-           send_reply(sptr, RPL_TRACEUSER, conClass,
-                      get_client_name(acptr, SHOW_IP),
-                      CurrentTime - cli_lasttime(acptr));
-          cnt++;
-        }
-        break;
-        /*
-         * Connection is a server
-         *
-         * Serv <class> <nS> <nC> <name> <ConnBy> <last> <age>
-         *
-         * class        Class the server is in
-         * nS           Number of servers reached via this link
-         * nC           Number of clients reached via this link
-         * name         Name of the server linked
-         * ConnBy       Who established this link
-         * last         Seconds since we got something from this link
-         * age          Seconds this link has been alive
-         *
-         * Additional comments etc......        -Cym-<cym@acrux.net>
-         */
-
-      case STAT_SERVER:
-        if (cli_serv(acptr)->user)
-         send_reply(sptr, RPL_TRACESERVER, conClass, link_s[i],
-                     link_u[i], cli_name(acptr),
-                     (*(cli_serv(acptr))->by) ? cli_serv(acptr)->by : "*",
-                     cli_serv(acptr)->user->username, cli_serv(acptr)->user->host,
-                     CurrentTime - cli_lasttime(acptr),
-                     CurrentTime - cli_serv(acptr)->timestamp);
-        else
-         send_reply(sptr, RPL_TRACESERVER, conClass, link_s[i],
-                     link_u[i], cli_name(acptr),
-                     (*(cli_serv(acptr))->by) ? cli_serv(acptr)->by : "*", "*",
-                     cli_name(&me), CurrentTime - cli_lasttime(acptr),
-                     CurrentTime - cli_serv(acptr)->timestamp);
-        cnt++;
-        break;
-      default:                  /* We actually shouldn't come here, -msa */
-       send_reply(sptr, RPL_TRACENEWTYPE, get_client_name(acptr, HIDE_IP));
-        cnt++;
-        break;
-    }
-  }
-  /*
-   * Add these lines to summarize the above which can get rather long
-   * and messy when done remotely - Avalon
-   */
-  if (!IsAnOper(sptr) || !cnt) {
-    if (!cnt)
-      /* let the user have some idea that its at the end of the trace */
-      send_reply(sptr, RPL_TRACESERVER, 0, link_s[cli_fd(&me)],
-          link_u[cli_fd(&me)], "<No_match>", *(cli_serv(&me)->by) ?
-          cli_serv(&me)->by : "*", "*", cli_name(&me), 0, 0);
-    return 0;
-  }
-  if (doall) {
-    for (cl = get_class_list(); cl; cl = cl->next) {
-      if (Links(cl) > 0)
-        send_reply(sptr, RPL_TRACECLASS, ConClass(cl), Links(cl));
-    }
-  }
+  do_trace(cptr, sptr, parc, parv);
   return 0;
 }
 
@@ -518,194 +330,8 @@ int ms_trace(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
  */
 int mo_trace(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
 {
-  int               i;
-  struct Client*    acptr;
-  const struct ConnectionClass* cl;
-  char*             tname;
-  int doall;
-  int link_s[MAXCONNECTIONS];
-  int link_u[MAXCONNECTIONS];
-  int cnt = 0;
-  int wilds;
-  int dow;
-
-  if (parc < 2 || BadPtr(parv[1])) {
-    /* just "TRACE" without parameters. Must be from local client */
-    parc = 1;
-    acptr = &me;
-    tname = cli_name(&me);
-    i = HUNTED_ISME;
-  } else if (parc < 3 || BadPtr(parv[2])) {
-    /* No target specified. Make one before propagating. */
-    parc = 2;
-    tname = parv[1];
-    if ((acptr = find_match_server(parv[1])) ||
-        ((acptr = FindClient(parv[1])) && !MyUser(acptr))) {
-      if (IsUser(acptr))
-        parv[2] = cli_name(cli_user(acptr)->server);
-      else
-        parv[2] = cli_name(acptr);
-      parc = 3;
-      parv[3] = 0;
-      if ((i = hunt_server_cmd(sptr, CMD_TRACE, cptr, IsServer(acptr),
-                              "%s :%C", 2, parc, parv)) == HUNTED_NOSUCH)
-        return 0;
-    } else
-      i = HUNTED_ISME;
-  } else {
-    /* Got "TRACE <tname> :<target>" */
-    parc = 3;
-    if (MyUser(sptr) || Protocol(cptr) < 10)
-      acptr = find_match_server(parv[2]);
-    else
-      acptr = FindNServer(parv[2]);
-    if ((i = hunt_server_cmd(sptr, CMD_TRACE, cptr, 0, "%s :%C", 2, parc,
-                            parv)) == HUNTED_NOSUCH)
-      return 0;
-    tname = parv[1];
-  }
-
-  if (i == HUNTED_PASS) {
-    if (!acptr)
-      acptr = next_client(GlobalClientList, tname);
-    else
-      acptr = cli_from(acptr);
-    send_reply(sptr, RPL_TRACELINK,
-              version, debugmode, tname,
-              acptr ? cli_name(cli_from(acptr)) : "<No_match>");
-    return 0;
-  }
-
-  doall = (parv[1] && (parc > 1)) ? !match(tname, cli_name(&me)) : 1;
-  wilds = !parv[1] || strchr(tname, '*') || strchr(tname, '?');
-  dow = wilds || doall;
-
-  /* Don't give (long) remote listings to lusers */
-  if (dow && !MyConnect(sptr) && !IsAnOper(sptr))
-    return 0;
-
-  for (i = 0; i < MAXCONNECTIONS; i++)
-    link_s[i] = 0, link_u[i] = 0;
-
-  if (doall) {
-    for (acptr = GlobalClientList; acptr; acptr = cli_next(acptr)) {
-      if (IsUser(acptr))
-        link_u[cli_fd(cli_from(acptr))]++;
-      else if (IsServer(acptr))
-        link_s[cli_fd(cli_from(acptr))]++;
-    }
-  }
-
-  /* report all direct connections */
-
-  for (i = 0; i <= HighestFd; i++) {
-    const char *conClass;
-
-    if (!(acptr = LocalClientArray[i])) /* Local Connection? */
-      continue;
-    if (IsInvisible(acptr) && dow && !(MyConnect(sptr) && IsOper(sptr)) &&
-        !IsAnOper(acptr) && (acptr != sptr))
-      continue;
-    if (!doall && wilds && match(tname, cli_name(acptr)))
-      continue;
-    if (!dow && 0 != ircd_strcmp(tname, cli_name(acptr)))
-      continue;
-    conClass = get_client_class(acptr);
-
-    switch (cli_status(acptr)) {
-      case STAT_CONNECTING:
-       send_reply(sptr, RPL_TRACECONNECTING, conClass, cli_name(acptr));
-        cnt++;
-        break;
-      case STAT_HANDSHAKE:
-       send_reply(sptr, RPL_TRACEHANDSHAKE, conClass, cli_name(acptr));
-        cnt++;
-        break;
-      case STAT_ME:
-        break;
-      case STAT_UNKNOWN:
-      case STAT_UNKNOWN_USER:
-       send_reply(sptr, RPL_TRACEUNKNOWN, conClass,
-                  get_client_name(acptr, HIDE_IP));
-        cnt++;
-        break;
-      case STAT_UNKNOWN_SERVER:
-       send_reply(sptr, RPL_TRACEUNKNOWN, conClass, "Unknown Server");
-        cnt++;
-        break;
-      case STAT_USER:
-        /* Only opers see users if there is a wildcard
-           but anyone can see all the opers. */
-        if ((IsAnOper(sptr) && (MyUser(sptr) ||
-            !(dow && IsInvisible(acptr)))) || !dow || IsAnOper(acptr)) {
-          if (IsAnOper(acptr))
-           send_reply(sptr, RPL_TRACEOPERATOR, conClass,
-                      get_client_name(acptr, SHOW_IP),
-                       CurrentTime - cli_lasttime(acptr));
-          else
-           send_reply(sptr, RPL_TRACEUSER, conClass,
-                      get_client_name(acptr, SHOW_IP),
-                       CurrentTime - cli_lasttime(acptr));
-          cnt++;
-        }
-        break;
-        /*
-         * Connection is a server
-         *
-         * Serv <class> <nS> <nC> <name> <ConnBy> <last> <age>
-         *
-         * class        Class the server is in
-         * nS           Number of servers reached via this link
-         * nC           Number of clients reached via this link
-         * name         Name of the server linked
-         * ConnBy       Who established this link
-         * last         Seconds since we got something from this link
-         * age          Seconds this link has been alive
-         *
-         * Additional comments etc......        -Cym-<cym@acrux.net>
-         */
-
-      case STAT_SERVER:
-        if (cli_serv(acptr)->user)
-         send_reply(sptr, RPL_TRACESERVER, conClass, link_s[i],
-                     link_u[i], cli_name(acptr),
-                     (*(cli_serv(acptr))->by) ? cli_serv(acptr)->by : "*",
-                     cli_serv(acptr)->user->username, cli_serv(acptr)->user->host,
-                     CurrentTime - cli_lasttime(acptr),
-                     CurrentTime - cli_serv(acptr)->timestamp);
-        else
-         send_reply(sptr, RPL_TRACESERVER, conClass, link_s[i],
-                     link_u[i], cli_name(acptr),
-                     (*(cli_serv(acptr))->by) ? cli_serv(acptr)->by : "*", "*",
-                     cli_name(&me), CurrentTime - cli_lasttime(acptr),
-                     CurrentTime - cli_serv(acptr)->timestamp);
-        cnt++;
-        break;
-      default:                  /* We actually shouldn't come here, -msa */
-       send_reply(sptr, RPL_TRACENEWTYPE, get_client_name(acptr, HIDE_IP));
-        cnt++;
-        break;
-    }
-  }
-  /*
-   * Add these lines to summarize the above which can get rather long
-   * and messy when done remotely - Avalon
-   */
-  if (!IsAnOper(sptr) || !cnt) {
-    if (!cnt)
-      /* let the user have some idea that its at the end of the trace */
-      send_reply(sptr, RPL_TRACESERVER, 0, link_s[cli_fd(&me)],
-                 link_u[cli_fd(&me)], "<No_match>", *(cli_serv(&me)->by) ?
-                 cli_serv(&me)->by : "*", "*", cli_name(&me), 0, 0);
-    return 0;
-  }
-  if (doall) {
-    for (cl = get_class_list(); cl; cl = cl->next) {
-      if (Links(cl) > 0)
-        send_reply(sptr, RPL_TRACECLASS, ConClass(cl), Links(cl));
-    }
-  }
+  if (feature_bool(FEAT_HIS_TRACE) && !IsAnOper(sptr))
+    return send_reply(cptr, ERR_NOPRIVILEGES);
+  do_trace(cptr, sptr, parc, parv);
   return 0;
 }
-
-
index 79da7b9bb09160206e577eb6b1207395fa362388..46feebfb3c150f0aa54c1c06a55c709413ea0fb4 100644 (file)
@@ -556,7 +556,7 @@ static Numeric replyTable[] = {
 /* 261 */
   { RPL_TRACELOG, "File %s %d", "261" },
 /* 262 */
-  { RPL_TRACEPING, "Ping %s %s", "262" },
+  { RPL_TRACEEND, ":End of TRACE", "262" },
 /* 263 */
   { 0 },
 /* 264 */