]> jfr.im git - solanum.git/blobdiff - modules/m_stats.c
Replace RPL_WHOISTEXT(337) with RPL_WHOISSPECIAL(320) (#419)
[solanum.git] / modules / m_stats.c
index 5063fc6135d06283d8e559b48a19f7f19710f6ba..751c9446be2693e3c0afcbb721a2771e80e8b678 100644 (file)
@@ -60,11 +60,13 @@ struct Message stats_msgtab = {
 
 int doing_stats_hook;
 int doing_stats_p_hook;
+int doing_stats_show_idle_hook;
 
 mapi_clist_av1 stats_clist[] = { &stats_msgtab, NULL };
 mapi_hlist_av1 stats_hlist[] = {
        { "doing_stats",        &doing_stats_hook },
        { "doing_stats_p",      &doing_stats_p_hook },
+       { "doing_stats_show_idle", &doing_stats_show_idle_hook },
        { NULL, NULL }
 };
 
@@ -104,7 +106,6 @@ static void stats_deny(struct Client *);
 static void stats_exempt(struct Client *);
 static void stats_events(struct Client *);
 static void stats_prop_klines(struct Client *);
-static void stats_hubleaf(struct Client *);
 static void stats_auth(struct Client *);
 static void stats_tklines(struct Client *);
 static void stats_klines(struct Client *);
@@ -128,7 +129,6 @@ static void stats_class(struct Client *);
 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 *);
 static void stats_capability(struct Client *);
 
@@ -159,8 +159,6 @@ static struct stats_cmd stats_cmd_table[256] = {
        ['f'] = HANDLER_NORM(stats_comm,        true,   NULL),
        ['F'] = HANDLER_NORM(stats_comm,        true,   NULL),
        ['g'] = HANDLER_NORM(stats_prop_klines, false,  "oper:general"),
-       ['h'] = HANDLER_NORM(stats_hubleaf,     false,  NULL),
-       ['H'] = HANDLER_NORM(stats_hubleaf,     false,  NULL),
        ['i'] = HANDLER_NORM(stats_auth,        false,  NULL),
        ['I'] = HANDLER_NORM(stats_auth,        false,  NULL),
        ['k'] = HANDLER_NORM(stats_tklines,     false,  NULL),
@@ -190,7 +188,6 @@ static struct stats_cmd stats_cmd_table[256] = {
        ['y'] = HANDLER_NORM(stats_class,       false,  NULL),
        ['Y'] = HANDLER_NORM(stats_class,       false,  NULL),
        ['z'] = HANDLER_NORM(stats_memory,      false,  "oper:general"),
-       ['Z'] = HANDLER_NORM(stats_ziplinks,    false,  "oper:general"),
        ['?'] = HANDLER_NORM(stats_servlinks,   false,  NULL),
 };
 
@@ -356,8 +353,6 @@ stats_connect(struct Client *source_p)
                                *s++ = 'S';
                        if(ServerConfTb(server_p))
                                *s++ = 'T';
-                       if(ServerConfCompressed(server_p))
-                               *s++ = 'Z';
                }
 
                if(s == buf)
@@ -458,7 +453,7 @@ stats_deny (struct Client *source_p)
 static void
 stats_exempt(struct Client *source_p)
 {
-       char *name, *host, *user, *classname;
+       char *name, *host, *user, *classname, *desc;
        const char *pass;
        struct AddressRec *arec;
        struct ConfItem *aconf;
@@ -479,7 +474,7 @@ stats_exempt(struct Client *source_p)
                        {
                                aconf = arec->aconf;
                                get_printable_conf (aconf, &name, &host, &pass,
-                                                   &user, &port, &classname);
+                                                   &user, &port, &classname, &desc);
 
                                sendto_one_numeric(source_p, RPL_STATSDLINE,
                                                   form_str(RPL_STATSDLINE),
@@ -506,15 +501,13 @@ static void
 stats_prop_klines(struct Client *source_p)
 {
        struct ConfItem *aconf;
-       rb_dlink_node *ptr;
        char *user, *host, *pass, *oper_reason;
+       rb_dictionary_iter state;
 
-       RB_DLINK_FOREACH(ptr, prop_bans.head)
+       RB_DICTIONARY_FOREACH(aconf, &state, prop_bans_dict)
        {
-               aconf = ptr->data;
-
                /* Skip non-klines and deactivated klines. */
-               if(aconf->status != CONF_KILL)
+               if (aconf->status != CONF_KILL)
                        continue;
 
                get_printable_kline(source_p, aconf, &host, &pass,
@@ -528,37 +521,6 @@ stats_prop_klines(struct Client *source_p)
        }
 }
 
-static void
-stats_hubleaf(struct Client *source_p)
-{
-       struct remote_conf *hub_p;
-       rb_dlink_node *ptr;
-
-       if((ConfigFileEntry.stats_h_oper_only ||
-           (ConfigServerHide.flatten_links && !IsExemptShide(source_p))) &&
-           !IsOperGeneral(source_p))
-       {
-               sendto_one_numeric(source_p, ERR_NOPRIVILEGES,
-                                  form_str (ERR_NOPRIVILEGES));
-               return;
-       }
-
-       RB_DLINK_FOREACH(ptr, hubleaf_conf_list.head)
-       {
-               hub_p = ptr->data;
-
-               if(hub_p->flags & CONF_HUB)
-                       sendto_one_numeric(source_p, RPL_STATSHLINE,
-                                       form_str(RPL_STATSHLINE),
-                                       hub_p->host, hub_p->server);
-               else
-                       sendto_one_numeric(source_p, RPL_STATSLLINE,
-                                       form_str(RPL_STATSLLINE),
-                                       hub_p->host, hub_p->server);
-       }
-}
-
-
 static void
 stats_auth (struct Client *source_p)
 {
@@ -571,7 +533,7 @@ stats_auth (struct Client *source_p)
        else if((ConfigFileEntry.stats_i_oper_only == 1) && !IsOperGeneral (source_p))
        {
                struct ConfItem *aconf;
-               char *name, *host, *user, *classname;
+               char *name, *host, *user, *classname, *desc;
                const char *pass = "*";
                int port;
 
@@ -588,13 +550,13 @@ stats_auth (struct Client *source_p)
                if(aconf == NULL)
                        return;
 
-               get_printable_conf (aconf, &name, &host, &pass, &user, &port, &classname);
+               get_printable_conf (aconf, &name, &host, &pass, &user, &port, &classname, &desc);
                if(!EmptyString(aconf->spasswd))
                        pass = aconf->spasswd;
 
                sendto_one_numeric(source_p, RPL_STATSILINE, form_str(RPL_STATSILINE),
                                   name, pass, show_iline_prefix(source_p, aconf, user),
-                                  host, port, classname);
+                                  host, port, classname, desc);
        }
 
        /* Theyre opered, or allowed to see all auth blocks */
@@ -765,16 +727,16 @@ static void
 stats_dnsbl(struct Client *source_p)
 {
        rb_dictionary_iter iter;
-       struct DNSBLEntryStats *stats;
+       struct DNSBLEntry *entry;
 
        if(dnsbl_stats == NULL)
                return;
 
-       RB_DICTIONARY_FOREACH(stats, &iter, dnsbl_stats)
+       RB_DICTIONARY_FOREACH(entry, &iter, dnsbl_stats)
        {
                /* use RPL_STATSDEBUG for now -- jilles */
                sendto_one_numeric(source_p, RPL_STATSDEBUG, "n :%d %s",
-                               stats->hits, (const char *)iter.cur->key);
+                               entry->hits, entry->host);
        }
 }
 
@@ -946,8 +908,8 @@ 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 :%s",
-                       pid,
+                       "S :%ld %c %u :%s",
+                       (long)pid,
                        status == SSLD_DEAD ? 'D' : (status == SSLD_SHUTDOWN ? 'S' : 'A'),
                        cli_count,
                        version);
@@ -962,7 +924,6 @@ stats_ssld(struct Client *source_p)
 static void
 stats_usage (struct Client *source_p)
 {
-#ifndef _WIN32
        struct rusage rus;
        time_t secs;
        time_t rup;
@@ -999,8 +960,8 @@ stats_usage (struct Client *source_p)
                           (int) (rus.ru_stime.tv_sec % 60));
        sendto_one_numeric(source_p, RPL_STATSDEBUG,
                           "R :RSS %ld ShMem %ld Data %ld Stack %ld",
-                          rus.ru_maxrss, (rus.ru_ixrss / rup),
-                          (rus.ru_idrss / rup), (rus.ru_isrss / rup));
+                          rus.ru_maxrss, (long)(rus.ru_ixrss / rup),
+                          (long)(rus.ru_idrss / rup), (long)(rus.ru_isrss / rup));
        sendto_one_numeric(source_p, RPL_STATSDEBUG,
                           "R :Swaps %d Reclaims %d Faults %d",
                           (int) rus.ru_nswap, (int) rus.ru_minflt, (int) rus.ru_majflt);
@@ -1014,7 +975,6 @@ stats_usage (struct Client *source_p)
                           "R :Signals %d Context Vol. %d Invol %d",
                           (int) rus.ru_nsignals, (int) rus.ru_nvcsw,
                           (int) rus.ru_nivcsw);
-#endif
 }
 
 static void
@@ -1341,10 +1301,10 @@ stats_memory (struct Client *source_p)
                           (unsigned long) users_invited_count * sizeof(rb_dlink_node));
 
        sendto_one_numeric(source_p, RPL_STATSDEBUG,
-                          "z :User channels %u(%lu) Aways %u(%d)",
+                          "z :User channels %u(%lu) Aways %u(%zu)",
                           user_channels,
                           (unsigned long) user_channels * sizeof(rb_dlink_node),
-                          aways_counted, (int) away_memory);
+                          aways_counted, away_memory);
 
        sendto_one_numeric(source_p, RPL_STATSDEBUG,
                           "z :Attached confs %u(%lu)",
@@ -1352,7 +1312,7 @@ stats_memory (struct Client *source_p)
                           (unsigned long) local_client_conf_count * sizeof(rb_dlink_node));
 
        sendto_one_numeric(source_p, RPL_STATSDEBUG,
-                          "z :Conflines %u(%d)", conf_count, (int) conf_memory);
+                          "z :Conflines %u(%zu)", conf_count, conf_memory);
 
        sendto_one_numeric(source_p, RPL_STATSDEBUG,
                           "z :Classes %u(%lu)",
@@ -1360,15 +1320,15 @@ stats_memory (struct Client *source_p)
                           (unsigned long) class_count * sizeof(struct Class));
 
        sendto_one_numeric(source_p, RPL_STATSDEBUG,
-                          "z :Channels %u(%d)",
-                          channel_count, (int) channel_memory);
+                          "z :Channels %u(%zu)",
+                          channel_count, channel_memory);
 
        sendto_one_numeric(source_p, RPL_STATSDEBUG,
-                          "z :Bans %u(%d) Exceptions %u(%d) Invex %u(%d) Quiets %u(%d)",
-                          channel_bans, (int) channel_ban_memory,
-                          channel_except, (int) channel_except_memory,
-                          channel_invex, (int) channel_invex_memory,
-                          channel_quiets, (int) channel_quiet_memory);
+                          "z :Bans %u(%zu) Exceptions %u(%zu) Invex %u(%zu) Quiets %u(%zu)",
+                          channel_bans, channel_ban_memory,
+                          channel_except, channel_except_memory,
+                          channel_invex, channel_invex_memory,
+                          channel_quiets, channel_quiet_memory);
 
        sendto_one_numeric(source_p, RPL_STATSDEBUG,
                           "z :Channel members %u(%lu) invite %u(%lu)",
@@ -1382,86 +1342,58 @@ stats_memory (struct Client *source_p)
                channel_users * sizeof(rb_dlink_node) + channel_invites * sizeof(rb_dlink_node);
 
        sendto_one_numeric(source_p, RPL_STATSDEBUG,
-                          "z :Whowas array %ld(%ld)",
-                          (long)ww, (long)wwm);
+                          "z :Whowas array %zu(%zu)",
+                          ww, wwm);
 
        totww = wwm;
 
        sendto_one_numeric(source_p, RPL_STATSDEBUG,
-                          "z :Hash: client %u(%ld) chan %u(%ld)",
-                          U_MAX, (long)(U_MAX * sizeof(rb_dlink_list)),
-                          CH_MAX, (long)(CH_MAX * sizeof(rb_dlink_list)));
+                          "z :Hash: client %u(%lu) chan %u(%lu)",
+                          U_MAX, (unsigned long)(U_MAX * sizeof(rb_dlink_list)),
+                          CH_MAX, (unsigned long)(CH_MAX * sizeof(rb_dlink_list)));
 
        sendto_one_numeric(source_p, RPL_STATSDEBUG,
-                          "z :linebuf %ld(%ld)",
-                          (long)linebuf_count, (long)linebuf_memory_used);
+                          "z :linebuf %zu(%zu)",
+                          linebuf_count, linebuf_memory_used);
 
        count_scache(&number_servers_cached, &mem_servers_cached);
 
        sendto_one_numeric(source_p, RPL_STATSDEBUG,
-                          "z :scache %ld(%ld)",
-                          (long)number_servers_cached, (long)mem_servers_cached);
+                          "z :scache %zu(%zu)",
+                          number_servers_cached, mem_servers_cached);
 
        sendto_one_numeric(source_p, RPL_STATSDEBUG,
-                          "z :hostname hash %d(%ld)",
-                          HOST_MAX, (long)HOST_MAX * sizeof(rb_dlink_list));
+                          "z :hostname hash %d(%lu)",
+                          HOST_MAX, (unsigned long)HOST_MAX * sizeof(rb_dlink_list));
 
        total_memory = totww + total_channel_memory + conf_memory +
                class_count * sizeof(struct Class);
 
        total_memory += mem_servers_cached;
        sendto_one_numeric(source_p, RPL_STATSDEBUG,
-                          "z :Total: whowas %d channel %d conf %d",
-                          (int) totww, (int) total_channel_memory,
-                          (int) conf_memory);
+                          "z :Total: whowas %zu channel %zu conf %zu",
+                          totww, total_channel_memory,
+                          conf_memory);
 
        count_local_client_memory(&local_client_count, &local_client_memory_used);
        total_memory += local_client_memory_used;
 
        sendto_one_numeric(source_p, RPL_STATSDEBUG,
-                          "z :Local client Memory in use: %ld(%ld)",
-                          (long)local_client_count, (long)local_client_memory_used);
+                          "z :Local client Memory in use: %zu(%zu)",
+                          local_client_count, local_client_memory_used);
 
 
        count_remote_client_memory(&remote_client_count, &remote_client_memory_used);
        total_memory += remote_client_memory_used;
 
        sendto_one_numeric(source_p, RPL_STATSDEBUG,
-                          "z :Remote client Memory in use: %ld(%ld)",
-                          (long)remote_client_count,
-                          (long)remote_client_memory_used);
-}
-
-static void
-stats_ziplinks (struct Client *source_p)
-{
-       rb_dlink_node *ptr;
-       struct Client *target_p;
-       struct ZipStats *zipstats;
-       int sent_data = 0;
-       char buf[128], buf1[128];
-       RB_DLINK_FOREACH (ptr, serv_list.head)
-       {
-               target_p = ptr->data;
-               if(IsCapable (target_p, CAP_ZIP))
-               {
-                       zipstats = target_p->localClient->zipstats;
-                       sprintf(buf, "%.2f%%", zipstats->out_ratio);
-                       sprintf(buf1, "%.2f%%", zipstats->in_ratio);
-                       sendto_one_numeric(source_p, RPL_STATSDEBUG,
-                                           "Z :ZipLinks stats for %s send[%s compression "
-                                           "(%llu kB data/%llu kB wire)] recv[%s compression "
-                                           "(%llu kB data/%llu kB wire)]",
-                                           target_p->name,
-                                           buf, zipstats->out >> 10,
-                                           zipstats->out_wire >> 10, buf1,
-                                           zipstats->in >> 10, zipstats->in_wire >> 10);
-                       sent_data++;
-               }
-       }
+                          "z :Remote client Memory in use: %zu(%zu)",
+                          remote_client_count,
+                          remote_client_memory_used);
 
        sendto_one_numeric(source_p, RPL_STATSDEBUG,
-                          "Z :%u ziplink(s)", sent_data);
+                          "z :TOTAL: %zu",
+                          total_memory);
 }
 
 static void
@@ -1689,19 +1621,27 @@ stats_l_client(struct Client *source_p, struct Client *target_p,
 
        else
        {
+               /* fire the doing_stats_show_idle hook to allow modules to tell us whether to show the idle time */
+               hook_data_client_approval hdata_showidle;
+
+               hdata_showidle.client = source_p;
+               hdata_showidle.target = target_p;
+               hdata_showidle.approved = WHOIS_IDLE_SHOW;
+
+               call_hook(doing_stats_show_idle_hook, &hdata_showidle);
                sendto_one_numeric(source_p, RPL_STATSLINKINFO, Lformat,
                                   show_ip(source_p, target_p) ?
                                    (IsUpper(statchar) ?
                                     get_client_name(target_p, SHOW_IP) :
                                     get_client_name(target_p, HIDE_IP)) :
                                    get_client_name(target_p, MASK_IP),
-                                   (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,
+                                   hdata_showidle.approved ? (int) rb_linebuf_len(&target_p->localClient->buf_sendq) : 0,
+                                   hdata_showidle.approved ? (int) target_p->localClient->sendM : 0,
+                                   hdata_showidle.approved ? (int) target_p->localClient->sendK : 0,
+                                   hdata_showidle.approved ? (int) target_p->localClient->receiveM : 0,
+                                   hdata_showidle.approved ? (int) target_p->localClient->receiveK : 0,
                                    rb_current_time() - target_p->localClient->firsttime,
-                                   (rb_current_time() > target_p->localClient->lasttime) ?
+                                   (rb_current_time() > target_p->localClient->lasttime) && hdata_showidle.approved ?
                                     (rb_current_time() - target_p->localClient->lasttime) : 0,
                                    "-");
        }