]> jfr.im git - solanum.git/blobdiff - modules/m_stats.c
Get rid of ^M.
[solanum.git] / modules / m_stats.c
index 14c3bf7e4be90228335838a7f365468cfccd240c..7d9abc9fe276ec76ec866ae7c2bbabad492c446d 100644 (file)
@@ -25,7 +25,6 @@
  */
 
 #include "stdinc.h"
-#include "tools.h"             /* dlink_node/dlink_list */
 #include "class.h"             /* report_classes */
 #include "client.h"            /* Client */
 #include "common.h"            /* TRUE/FALSE */
 #include "numeric.h"           /* ERR_xxx */
 #include "scache.h"            /* list_scache */
 #include "send.h"              /* sendto_one */
-#include "commio.h"            /* highest_fd */
 #include "s_conf.h"            /* ConfItem */
 #include "s_serv.h"            /* hunt_server */
 #include "s_stats.h"           /* tstats */
 #include "s_user.h"            /* show_opers */
-#include "event.h"             /* events */
 #include "blacklist.h"         /* dnsbl stuff */
-#include "linebuf.h"
 #include "parse.h"
 #include "modules.h"
 #include "hook.h"
@@ -73,7 +69,7 @@ DECLARE_MODULE_AV1(stats, NULL, NULL, stats_clist, stats_hlist, NULL, "$Revision
 
 const char *Lformat = "%s %u %u %u %u %u :%u %u %s";
 
-static void stats_l_list(struct Client *s, const char *, int, int, dlink_list *, char);
+static void stats_l_list(struct Client *s, const char *, int, int, rb_dlink_list *, char);
 static void stats_l_client(struct Client *source_p, struct Client *target_p,
                                char statchar);
 
@@ -122,7 +118,7 @@ static void stats_memory(struct Client *);
 static void stats_servlinks(struct Client *);
 static void stats_ltrace(struct Client *, int, const char **);
 static void stats_ziplinks(struct Client *);
-
+static void stats_comm(struct Client *);
 /* This table contains the possible stats items, in order:
  * stats letter,  function to call, operonly? adminonly?
  * case only matters in the stats letter column.. -- fl_
@@ -139,8 +135,8 @@ static struct StatsStruct stats_cmd_table[] = {
        {'D', stats_deny,               1, 0, },
        {'e', stats_exempt,             1, 0, },
        {'E', stats_events,             1, 1, },
-       {'f', comm_dump,                1, 1, },
-       {'F', comm_dump,                1, 1, },
+       {'f', stats_comm,               1, 1, },
+       {'F', stats_comm,               1, 1, },
        {'g', stats_pending_glines,     1, 0, },
        {'G', stats_glines,             1, 0, },
        {'h', stats_hubleaf,            0, 0, },
@@ -199,7 +195,7 @@ m_stats(struct Client *client_p, struct Client *source_p, int parc, const char *
        if(MyClient(source_p) && !IsOper(source_p))
        {
                /* Check the user is actually allowed to do /stats, and isnt flooding */
-               if((last_used + ConfigFileEntry.pace_wait) > CurrentTime)
+               if((last_used + ConfigFileEntry.pace_wait) > rb_current_time())
                {
                        /* safe enough to give this on a local connect only */
                        sendto_one(source_p, form_str(RPL_LOAD2HI),
@@ -209,7 +205,7 @@ m_stats(struct Client *client_p, struct Client *source_p, int parc, const char *
                        return 0;
                }
                else
-                       last_used = CurrentTime;
+                       last_used = rb_current_time();
        }
 
        if(hunt_server (client_p, source_p, ":%s STATS %s :%s", 2, parc, parv) != HUNTED_ISME)
@@ -226,13 +222,18 @@ m_stats(struct Client *client_p, struct Client *source_p, int parc, const char *
                        /* Called for remote clients and for local opers, so check need_admin
                         * and need_oper
                         */
-                       if((stats_cmd_table[i].need_admin && !IsOperAdmin (source_p)) ||
-                          (stats_cmd_table[i].need_oper && !IsOper (source_p)))
+                       if(stats_cmd_table[i].need_oper && !IsOper(source_p))
                        {
                                sendto_one_numeric(source_p, ERR_NOPRIVILEGES,
                                                   form_str (ERR_NOPRIVILEGES));
                                break;
                        }
+                       if(stats_cmd_table[i].need_admin && !IsOperAdmin(source_p))
+                       {
+                               sendto_one(source_p, form_str(ERR_NOPRIVS),
+                                          me.name, source_p->name, "admin");
+                               break;
+                       }
 
                        /* Blah, stats L needs the parameters, none of the others do.. */
                        if(statchar == 'L' || statchar == 'l')
@@ -259,16 +260,13 @@ static void
 stats_delay(struct Client *source_p)
 {
        struct nd_entry *nd;
-       dlink_node *ptr;
-       int i;
+       struct DictionaryIter iter;
 
-       HASH_WALK(i, U_MAX, ptr, ndTable)
+       DICTIONARY_FOREACH(nd, &iter, nd_dict)
        {
-               nd = ptr->data;
-               sendto_one_notice(source_p, "Delaying: %s for %ld",
+               sendto_one_notice(source_p, ":Delaying: %s for %ld",
                                nd->name, (long) nd->expire);
        }
-       HASH_WALK_END
 }
 
 static void
@@ -283,7 +281,7 @@ stats_connect(struct Client *source_p)
        static char buf[5];
        struct server_conf *server_p;
        char *s;
-       dlink_node *ptr;
+       rb_dlink_node *ptr;
 
        if((ConfigFileEntry.stats_c_oper_only || 
            (ConfigServerHide.flatten_links && !IsExemptShide(source_p))) &&
@@ -294,7 +292,7 @@ stats_connect(struct Client *source_p)
                return;
        }
 
-       DLINK_FOREACH(ptr, server_conf_list.head)
+       RB_DLINK_FOREACH(ptr, server_conf_list.head)
        {
                server_p = ptr->data;
 
@@ -422,8 +420,8 @@ stats_exempt(struct Client *source_p)
 
        if(ConfigFileEntry.stats_e_disabled)
        {
-               sendto_one_numeric(source_p, ERR_NOPRIVILEGES,
-                                  form_str (ERR_NOPRIVILEGES));
+               sendto_one_numeric(source_p, ERR_DISABLED,
+                                  form_str(ERR_DISABLED), "STATS e");
                return;
        }
 
@@ -445,10 +443,17 @@ stats_exempt(struct Client *source_p)
        }}
 
 
+static void
+stats_events_cb(char *str, void *ptr)
+{
+       sendto_one_numeric(ptr, RPL_STATSDEBUG, "E :%s", str);
+}
+
 static void
 stats_events (struct Client *source_p)
 {
-       show_events (source_p);
+       rb_dump_events(stats_events_cb, source_p);
+       send_pop_queue(source_p);
 }
 
 /* stats_pending_glines()
@@ -462,12 +467,12 @@ stats_pending_glines (struct Client *source_p)
 {
        if(ConfigFileEntry.glines)
        {
-               dlink_node *pending_node;
+               rb_dlink_node *pending_node;
                struct gline_pending *glp_ptr;
                char timebuffer[MAX_DATE_STRING];
                struct tm *tmptr;
 
-               DLINK_FOREACH (pending_node, pending_glines.head)
+               RB_DLINK_FOREACH (pending_node, pending_glines.head)
                {
                        glp_ptr = pending_node->data;
 
@@ -494,7 +499,7 @@ stats_pending_glines (struct Client *source_p)
                        }
                }
 
-               if(dlink_list_length (&pending_glines) > 0)
+               if(rb_dlink_list_length (&pending_glines) > 0)
                        sendto_one_notice(source_p, ":End of Pending G-lines");
        }
        else
@@ -513,10 +518,10 @@ stats_glines (struct Client *source_p)
 {
        if(ConfigFileEntry.glines)
        {
-               dlink_node *gline_node;
+               rb_dlink_node *gline_node;
                struct ConfItem *kill_ptr;
 
-               DLINK_FOREACH_PREV (gline_node, glines.tail)
+               RB_DLINK_FOREACH_PREV (gline_node, glines.tail)
                {
                        kill_ptr = gline_node->data;
 
@@ -538,7 +543,7 @@ static void
 stats_hubleaf(struct Client *source_p)
 {
        struct remote_conf *hub_p;
-       dlink_node *ptr;
+       rb_dlink_node *ptr;
 
        if((ConfigFileEntry.stats_h_oper_only || 
            (ConfigServerHide.flatten_links && !IsExemptShide(source_p))) &&
@@ -549,7 +554,7 @@ stats_hubleaf(struct Client *source_p)
                return;
        }
 
-       DLINK_FOREACH(ptr, hubleaf_conf_list.head)
+       RB_DLINK_FOREACH(ptr, hubleaf_conf_list.head)
        {
                hub_p = ptr->data;
 
@@ -640,21 +645,21 @@ stats_tklines(struct Client *source_p)
                get_printable_kline(source_p, aconf, &host, &pass, &user, &oper_reason);
 
                sendto_one_numeric(source_p, RPL_STATSKLINE, 
-                                  form_str(RPL_STATSKLINE), 'k',
-                                  user, pass, oper_reason ? "|" : "",
+                                  form_str(RPL_STATSKLINE), aconf->flags & CONF_FLAGS_TEMPORARY ? 'k' : 'K',
+                                  host, user, pass, oper_reason ? "|" : "",
                                   oper_reason ? oper_reason : "");
        }
        /* Theyre opered, or allowed to see all klines */
        else
        {
                struct ConfItem *aconf;
-               dlink_node *ptr;
+               rb_dlink_node *ptr;
                int i;
                char *user, *host, *pass, *oper_reason;
 
                for(i = 0; i < LAST_TEMP_TYPE; i++)
                {
-                       DLINK_FOREACH(ptr, temp_klines[i].head)
+                       RB_DLINK_FOREACH(ptr, temp_klines[i].head)
                        {
                                aconf = ptr->data;
 
@@ -699,14 +704,11 @@ stats_klines(struct Client *source_p)
                if(aconf == NULL)
                        return;
 
-               /* dont report a tkline as a kline */
-               if(aconf->flags & CONF_FLAGS_TEMPORARY)
-                       return;
-
                get_printable_kline(source_p, aconf, &host, &pass, &user, &oper_reason);
 
                sendto_one_numeric(source_p, RPL_STATSKLINE, form_str(RPL_STATSKLINE),
-                                  'K', host, user, pass, oper_reason ? "|" : "",
+                                  aconf->flags & CONF_FLAGS_TEMPORARY ? 'k' : 'K',
+                                  host, user, pass, oper_reason ? "|" : "",
                                   oper_reason ? oper_reason : "");
        }
        /* Theyre opered, or allowed to see all klines */
@@ -723,10 +725,10 @@ stats_messages(struct Client *source_p)
 static void
 stats_dnsbl(struct Client *source_p)
 {
-       dlink_node *ptr;
+       rb_dlink_node *ptr;
        struct Blacklist *blptr;
 
-       DLINK_FOREACH(ptr, blacklist_list.head)
+       RB_DLINK_FOREACH(ptr, blacklist_list.head)
        {
                blptr = ptr->data;
 
@@ -743,7 +745,7 @@ static void
 stats_oper(struct Client *source_p)
 {
        struct oper_conf *oper_p;
-       dlink_node *ptr;
+       rb_dlink_node *ptr;
 
        if(!IsOper(source_p) && ConfigFileEntry.stats_o_oper_only)
        {
@@ -752,7 +754,7 @@ stats_oper(struct Client *source_p)
                return;
        }
 
-       DLINK_FOREACH(ptr, oper_conf_list.head)
+       RB_DLINK_FOREACH(ptr, oper_conf_list.head)
        {
                oper_p = ptr->data;
                
@@ -774,10 +776,10 @@ static void
 stats_operedup (struct Client *source_p)
 {
        struct Client *target_p;
-       dlink_node *oper_ptr;
+       rb_dlink_node *oper_ptr;
        unsigned int count = 0;
 
-       DLINK_FOREACH (oper_ptr, oper_list.head)
+       RB_DLINK_FOREACH (oper_ptr, oper_list.head)
        {
                target_p = oper_ptr->data;
 
@@ -815,10 +817,10 @@ static void
 stats_tresv(struct Client *source_p)
 {
        struct ConfItem *aconf;
-       dlink_node *ptr;
+       rb_dlink_node *ptr;
        int i;
 
-       DLINK_FOREACH(ptr, resv_conf_list.head)
+       RB_DLINK_FOREACH(ptr, resv_conf_list.head)
        {
                aconf = ptr->data;
                if(aconf->hold)
@@ -843,10 +845,10 @@ static void
 stats_resv(struct Client *source_p)
 {
        struct ConfItem *aconf;
-       dlink_node *ptr;
+       rb_dlink_node *ptr;
        int i;
 
-       DLINK_FOREACH(ptr, resv_conf_list.head)
+       RB_DLINK_FOREACH(ptr, resv_conf_list.head)
        {
                aconf = ptr->data;
                if(!aconf->hold)
@@ -892,7 +894,7 @@ stats_usage (struct Client *source_p)
        if(0 == secs)
                secs = 1;
 
-       rup = (CurrentTime - startup_time) * hzz;
+       rup = (rb_current_time() - startup_time) * hzz;
        if(0 == rup)
                rup = 1;
   
@@ -933,7 +935,7 @@ stats_uptime (struct Client *source_p)
 {
        time_t now;
 
-       now = CurrentTime - startup_time;
+       now = rb_current_time() - startup_time;
        sendto_one_numeric(source_p, RPL_STATSUPTIME, 
                           form_str (RPL_STATSUPTIME),
                           now / 86400, (now / 3600) % 24, 
@@ -970,12 +972,12 @@ static void
 stats_shared (struct Client *source_p)
 {
        struct remote_conf *shared_p;
-       dlink_node *ptr;
+       rb_dlink_node *ptr;
        char buf[15];
        char *p;
        int i;
 
-       DLINK_FOREACH(ptr, shared_conf_list.head)
+       RB_DLINK_FOREACH(ptr, shared_conf_list.head)
        {
                shared_p = ptr->data;
 
@@ -997,7 +999,7 @@ stats_shared (struct Client *source_p)
                                        shared_p->host, buf);
        }
 
-       DLINK_FOREACH(ptr, cluster_conf_list.head)
+       RB_DLINK_FOREACH(ptr, cluster_conf_list.head)
        {
                shared_p = ptr->data;
 
@@ -1029,7 +1031,7 @@ static void
 stats_servers (struct Client *source_p)
 {
        struct Client *target_p;
-       dlink_node *ptr;
+       rb_dlink_node *ptr;
        time_t seconds;
        int days, hours, minutes;
        int j = 0;
@@ -1042,12 +1044,12 @@ stats_servers (struct Client *source_p)
                return;
        }
 
-       DLINK_FOREACH (ptr, serv_list.head)
+       RB_DLINK_FOREACH (ptr, serv_list.head)
        {
                target_p = ptr->data;
 
                j++;
-               seconds = CurrentTime - target_p->localClient->firsttime;
+               seconds = rb_current_time() - target_p->localClient->firsttime;
 
                days = (int) (seconds / 86400);
                seconds %= 86400;
@@ -1061,8 +1063,8 @@ stats_servers (struct Client *source_p)
                                   "Connected: %d day%s, %d:%02d:%02d",
                                   target_p->name,
                                   (target_p->serv->by[0] ? target_p->serv->by : "Remote."),
-                                  (int) (CurrentTime - target_p->localClient->lasttime),
-                                  (int) linebuf_len (&target_p->localClient->buf_sendq),
+                                  (int) (rb_current_time() - target_p->localClient->lasttime),
+                                  (int) rb_linebuf_len (&target_p->localClient->buf_sendq),
                                   days, (days == 1) ? "" : "s", hours, minutes, 
                                   (int) seconds);
        }
@@ -1075,9 +1077,9 @@ static void
 stats_tgecos(struct Client *source_p)
 {
        struct ConfItem *aconf;
-       dlink_node *ptr;
+       rb_dlink_node *ptr;
 
-       DLINK_FOREACH(ptr, xline_conf_list.head)
+       RB_DLINK_FOREACH(ptr, xline_conf_list.head)
        {
                aconf = ptr->data;
 
@@ -1093,9 +1095,9 @@ static void
 stats_gecos(struct Client *source_p)
 {
        struct ConfItem *aconf;
-       dlink_node *ptr;
+       rb_dlink_node *ptr;
 
-       DLINK_FOREACH(ptr, xline_conf_list.head)
+       RB_DLINK_FOREACH(ptr, xline_conf_list.head)
        {
                aconf = ptr->data;
 
@@ -1126,11 +1128,11 @@ stats_memory (struct Client *source_p)
 static void
 stats_ziplinks (struct Client *source_p)
 {
-       dlink_node *ptr;
+       rb_dlink_node *ptr;
        struct Client *target_p;
        int sent_data = 0;
 
-       DLINK_FOREACH (ptr, serv_list.head)
+       RB_DLINK_FOREACH (ptr, serv_list.head)
        {
                target_p = ptr->data;
                if(IsCapable (target_p, CAP_ZIP))
@@ -1163,7 +1165,7 @@ stats_servlinks (struct Client *source_p)
        static char Sformat[] = ":%s %d %s %s %u %u %u %u %u :%u %u %s";
        long uptime, sendK, receiveK;
        struct Client *target_p;
-       dlink_node *ptr;
+       rb_dlink_node *ptr;
        int j = 0;
 
        if(ConfigServerHide.flatten_links && !IsOper (source_p) &&
@@ -1176,7 +1178,7 @@ stats_servlinks (struct Client *source_p)
 
        sendK = receiveK = 0;
 
-       DLINK_FOREACH (ptr, serv_list.head)
+       RB_DLINK_FOREACH (ptr, serv_list.head)
        {
                target_p = ptr->data;
 
@@ -1187,14 +1189,14 @@ stats_servlinks (struct Client *source_p)
                sendto_one(source_p, Sformat,
                        get_id(&me, source_p), RPL_STATSLINKINFO, get_id(source_p, source_p),
                        get_server_name(target_p, SHOW_IP),
-                       (int) linebuf_len (&target_p->localClient->buf_sendq),
+                       (int) rb_linebuf_len (&target_p->localClient->buf_sendq),
                        (int) target_p->localClient->sendM,
                        (int) target_p->localClient->sendK,
                        (int) target_p->localClient->receiveM,
                        (int) target_p->localClient->receiveK,
-                       CurrentTime - target_p->localClient->firsttime,
-                       (CurrentTime > target_p->localClient->lasttime) ? 
-                        (CurrentTime - target_p->localClient->lasttime) : 0,
+                       rb_current_time() - target_p->localClient->firsttime,
+                       (rb_current_time() > target_p->localClient->lasttime) ? 
+                        (rb_current_time() - target_p->localClient->lasttime) : 0,
                        IsOper (source_p) ? show_capabilities (target_p) : "TS");
        }
 
@@ -1208,7 +1210,7 @@ stats_servlinks (struct Client *source_p)
                           "? :Recv total : %7.2f %s",
                           _GMKv (receiveK), _GMKs (receiveK));
 
-       uptime = (CurrentTime - startup_time);
+       uptime = (rb_current_time() - startup_time);
 
        sendto_one_numeric(source_p, RPL_STATSDEBUG,
                           "? :Server send: %7.2f %s (%4.1f K/s)",
@@ -1312,16 +1314,16 @@ stats_ltrace(struct Client *source_p, int parc, const char *parv[])
 
 static void
 stats_l_list(struct Client *source_p, const char *name, int doall, int wilds,
-            dlink_list * list, char statchar)
+            rb_dlink_list * list, char statchar)
 {
-       dlink_node *ptr;
+       rb_dlink_node *ptr;
        struct Client *target_p;
 
        /* send information about connections which match.  note, we
         * dont need tests for IsInvisible(), because non-opers will
         * never get here for normal clients --fl
         */
-       DLINK_FOREACH(ptr, list->head)
+       RB_DLINK_FOREACH(ptr, list->head)
        {
                target_p = ptr->data;
 
@@ -1340,14 +1342,14 @@ stats_l_client(struct Client *source_p, struct Client *target_p,
        {
                sendto_one_numeric(source_p, RPL_STATSLINKINFO, Lformat,
                                get_server_name(target_p, SHOW_IP),
-                               (int) linebuf_len(&target_p->localClient->buf_sendq),
+                               (int) rb_linebuf_len(&target_p->localClient->buf_sendq),
                                (int) target_p->localClient->sendM,
                                (int) target_p->localClient->sendK,
                                (int) target_p->localClient->receiveM,
                                (int) target_p->localClient->receiveK,
-                               CurrentTime - target_p->localClient->firsttime,
-                               (CurrentTime > target_p->localClient->lasttime) ? 
-                                (CurrentTime - target_p->localClient->lasttime) : 0,
+                               rb_current_time() - target_p->localClient->firsttime,
+                               (rb_current_time() > target_p->localClient->lasttime) ? 
+                                (rb_current_time() - target_p->localClient->lasttime) : 0,
                                IsOper(source_p) ? show_capabilities(target_p) : "-");
        }
 
@@ -1359,18 +1361,32 @@ stats_l_client(struct Client *source_p, struct Client *target_p,
                                     get_client_name(target_p, SHOW_IP) :
                                     get_client_name(target_p, HIDE_IP)) :
                                    get_client_name(target_p, MASK_IP),
-                                   (int) linebuf_len(&target_p->localClient->buf_sendq),
+                                   (int) rb_linebuf_len(&target_p->localClient->buf_sendq),
                                    (int) target_p->localClient->sendM,
                                    (int) target_p->localClient->sendK,
                                    (int) target_p->localClient->receiveM,
                                    (int) target_p->localClient->receiveK,
-                                   CurrentTime - target_p->localClient->firsttime,
-                                   (CurrentTime > target_p->localClient->lasttime) ? 
-                                    (CurrentTime - target_p->localClient->lasttime) : 0,
+                                   rb_current_time() - target_p->localClient->firsttime,
+                                   (rb_current_time() > target_p->localClient->lasttime) ? 
+                                    (rb_current_time() - target_p->localClient->lasttime) : 0,
                                    "-");
        }
 }
 
+static void
+rb_dump_fd_callback(int fd, const char *desc, void *data)
+{
+       struct Client *source_p = data;
+       sendto_one_numeric(source_p, RPL_STATSDEBUG, "F :fd %-3d desc '%s'", fd, desc);
+}
+
+static void
+stats_comm(struct Client *source_p)
+{
+       rb_dump_fd(rb_dump_fd_callback, source_p);
+       send_pop_queue(source_p);
+}
+
 /*
  * stats_spy
  *