]> jfr.im git - solanum.git/blobdiff - modules/m_stats.c
modules: chase MsgBuf API change
[solanum.git] / modules / m_stats.c
index f61e48858d096124245ebe69ce0bac6e5d7aa79e..63f9dc1f290a9d7e92b8e0f8c922a6c2c2a4383d 100644 (file)
 #include "hash.h"
 #include "reject.h"
 #include "whowas.h"
+#include "irc_radixtree.h"
+#include "sslproc.h"
 
-static int m_stats (struct Client *, struct Client *, int, const char **);
+static int m_stats (struct MsgBuf *, struct Client *, struct Client *, int, const char **);
 
 struct Message stats_msgtab = {
        "STATS", 0, 0, 0, MFLG_SLOW,
@@ -75,7 +77,7 @@ static void stats_l_list(struct Client *s, const char *, int, int, rb_dlink_list
 static void stats_l_client(struct Client *source_p, struct Client *target_p,
                                char statchar);
 
-static void stats_spy(struct Client *, char, const char *);
+static int stats_spy(struct Client *, char, const char *);
 static void stats_p_spy(struct Client *);
 
 /* Heres our struct for the stats table */
@@ -108,6 +110,7 @@ static void stats_operedup(struct Client *);
 static void stats_ports(struct Client *);
 static void stats_tresv(struct Client *);
 static void stats_resv(struct Client *);
+static void stats_ssld(struct Client *);
 static void stats_usage(struct Client *);
 static void stats_tstats(struct Client *);
 static void stats_uptime(struct Client *);
@@ -161,6 +164,8 @@ static struct StatsStruct stats_cmd_table[] = {
        {'Q', stats_resv,               1, 0, },
        {'r', stats_usage,              1, 0, },
        {'R', stats_usage,              1, 0, },
+       {'s', stats_ssld,               1, 1, },
+       {'S', stats_ssld,               1, 1, },
        {'t', stats_tstats,             1, 0, },
        {'T', stats_tstats,             1, 0, },
        {'u', stats_uptime,             0, 0, },
@@ -186,11 +191,12 @@ static struct StatsStruct stats_cmd_table[] = {
  * if found execute it.
  */
 static int
-m_stats(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
+m_stats(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
 {
        static time_t last_used = 0;
        int i;
        char statchar;
+       int did_stats = 0;
 
        statchar = parv[1][0];
 
@@ -214,7 +220,11 @@ m_stats(struct Client *client_p, struct Client *source_p, int parc, const char *
                return 0;
 
        if((statchar != 'L') && (statchar != 'l'))
-               stats_spy(source_p, statchar, NULL);
+               did_stats = stats_spy(source_p, statchar, NULL);
+
+       /* if did_stats is true, a module grabbed this STATS request */
+       if (did_stats)
+               goto stats_out;
 
        for (i = 0; stats_cmd_table[i].letter; i++)
        {
@@ -245,6 +255,7 @@ m_stats(struct Client *client_p, struct Client *source_p, int parc, const char *
                }
        }
 
+stats_out:
        /* Send the end of stats notice, and the stats_spy */
        sendto_one_numeric(source_p, RPL_ENDOFSTATS,
                           form_str(RPL_ENDOFSTATS), statchar);
@@ -271,10 +282,20 @@ stats_delay(struct Client *source_p)
        }
 }
 
+static void
+stats_hash_cb(const char *buf, void *client_p)
+{
+       sendto_one_numeric(client_p, RPL_STATSDEBUG, "B :%s", buf);
+}
+
 static void
 stats_hash(struct Client *source_p)
 {
-       hash_stats(source_p);
+       sendto_one_numeric(source_p, RPL_STATSDEBUG, "B :%-30s %-15s %-10s %-10s %-10s %-10s",
+               "NAME", "TYPE", "OBJECTS", "DEPTH SUM", "AVG DEPTH", "MAX DEPTH");
+
+       irc_dictionary_stats_walk(stats_hash_cb, source_p);
+       irc_radixtree_stats_walk(stats_hash_cb, source_p);
 }
 
 static void
@@ -412,7 +433,8 @@ stats_deny (struct Client *source_p)
 static void
 stats_exempt(struct Client *source_p)
 {
-       char *name, *host, *pass, *user, *classname;
+       char *name, *host, *user, *classname;
+       const char *pass;
        struct AddressRec *arec;
        struct ConfItem *aconf;
        int i, port;
@@ -523,7 +545,8 @@ stats_auth (struct Client *source_p)
        else if((ConfigFileEntry.stats_i_oper_only == 1) && !IsOper (source_p))
        {
                struct ConfItem *aconf;
-               char *name, *host, *pass = "*", *user, *classname;
+               char *name, *host, *user, *classname;
+               const char *pass = "*";
                int port;
 
                if(MyConnect (source_p))
@@ -619,6 +642,43 @@ stats_tklines(struct Client *source_p)
        }
 }
 
+/* report_Klines()
+ *
+ * inputs       - Client to report to, mask
+ * outputs      -
+ * side effects - Reports configured K-lines to client_p.
+ */
+static void
+report_Klines(struct Client *source_p)
+{
+       char *host, *pass, *user, *oper_reason;
+       struct AddressRec *arec;
+       struct ConfItem *aconf = NULL;
+       int i;
+
+       for (i = 0; i < ATABLE_SIZE; i++)
+       {
+               for (arec = atable[i]; arec; arec = arec->next)
+               {
+                       if(arec->type == CONF_KILL)
+                       {
+                               aconf = arec->aconf;
+
+                               /* its a tempkline, theyre reported elsewhere */
+                               if(aconf->flags & CONF_FLAGS_TEMPORARY)
+                                       continue;
+
+                               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 ? "|" : "",
+                                                  oper_reason ? oper_reason : "");
+                       }
+               }
+       }
+}
+
 static void
 stats_klines(struct Client *source_p)
 {
@@ -779,6 +839,7 @@ static void
 stats_tresv(struct Client *source_p)
 {
        struct ConfItem *aconf;
+       struct irc_radixtree_iteration_state state;
        rb_dlink_node *ptr;
        int i;
 
@@ -791,15 +852,13 @@ stats_tresv(struct Client *source_p)
                                        'q', aconf->port, aconf->host, aconf->passwd);
        }
 
-       HASH_WALK(i, R_MAX, ptr, resvTable)
+       IRC_RADIXTREE_FOREACH(aconf, &state, resv_tree)
        {
-               aconf = ptr->data;
                if(aconf->hold)
                        sendto_one_numeric(source_p, RPL_STATSQLINE,
                                        form_str(RPL_STATSQLINE),
                                        'q', aconf->port, aconf->host, aconf->passwd);
        }
-       HASH_WALK_END
 }
 
 
@@ -807,6 +866,7 @@ static void
 stats_resv(struct Client *source_p)
 {
        struct ConfItem *aconf;
+       struct irc_radixtree_iteration_state state;
        rb_dlink_node *ptr;
        int i;
 
@@ -819,15 +879,33 @@ stats_resv(struct Client *source_p)
                                        'Q', aconf->port, aconf->host, aconf->passwd);
        }
 
-       HASH_WALK(i, R_MAX, ptr, resvTable)
+       IRC_RADIXTREE_FOREACH(aconf, &state, resv_tree)
        {
-               aconf = ptr->data;
                if(!aconf->hold)
                        sendto_one_numeric(source_p, RPL_STATSQLINE,
                                        form_str(RPL_STATSQLINE),
                                        'Q', aconf->port, aconf->host, aconf->passwd);
        }
-       HASH_WALK_END
+}
+
+static void
+stats_ssld_foreach(void *data, pid_t pid, int cli_count, enum ssld_status status)
+{
+       struct Client *source_p = data;
+
+       sendto_one_numeric(source_p, RPL_STATSDEBUG,
+                       "S :%u %c %u",
+                       pid,
+                       status == SSLD_DEAD ? 'D' : (status == SSLD_SHUTDOWN ? 'S' : 'A'),
+                       cli_count);
+}
+
+static void
+stats_ssld(struct Client *source_p)
+{
+#if 0
+       ssld_foreach_info(stats_ssld_foreach, source_p);
+#endif
 }
 
 static void
@@ -1005,6 +1083,8 @@ static struct shared_flags shared_flagtable[] =
        { SHARED_TDLINE,        'd' },
        { SHARED_PDLINE,        'D' },
        { SHARED_UNDLINE,       'E' },
+       { SHARED_GRANT,         'G' },
+       { SHARED_DIE,           'I' },
        { 0,                    '\0'}
 };
 
@@ -1211,7 +1291,7 @@ stats_memory (struct Client *source_p)
 
        size_t total_memory = 0;
 
-       count_whowas_memory(&ww, &wwm);
+       whowas_memory_usage(&ww, &wwm);
 
        RB_DLINK_FOREACH(ptr, global_client_list.head)
        {
@@ -1661,7 +1741,7 @@ stats_comm(struct Client *source_p)
  * any damage with stats requests now anyway. So, why show them?
  * -Dianora
  */
-static void
+static int
 stats_spy(struct Client *source_p, char statchar, const char *name)
 {
        hook_data_int data;
@@ -1669,8 +1749,11 @@ stats_spy(struct Client *source_p, char statchar, const char *name)
        data.client = source_p;
        data.arg1 = name;
        data.arg2 = (int) statchar;
+       data.result = 0;
 
        call_hook(doing_stats_hook, &data);
+
+       return data.result;
 }
 
 /* stats_p_spy()