+/** Display objects allocated (and total memory used by them) for
+ * several types of structures.
+ * @param[in] to Client requesting statistics.
+ * @param[in] sd Stats descriptor for request (ignored).
+ * @param[in] param Extra parameter from user (ignored).
+ */
+static void
+stats_meminfo(struct Client* to, const struct StatDesc* sd, char* param)
+{
+ extern void bans_send_meminfo(struct Client *cptr);
+
+ class_send_meminfo(to);
+ bans_send_meminfo(to);
+ send_listinfo(to, 0);
+}
+
+/** Send a list of available statistics.
+ * @param[in] to Client requesting statistics.
+ * @param[in] sd Stats descriptor for request.
+ * @param[in] param Extra parameter from user (ignored).
+ */
+static void
+stats_help(struct Client* to, const struct StatDesc* sd, char* param)
+{
+ struct StatDesc *asd;
+
+ /* only if it's my user */
+ if (MyUser(to))
+ for (asd = statsinfo; asd->sd_name; asd++)
+ if (asd != sd) /* don't send the help for us */
+ sendcmdto_one(&me, CMD_NOTICE, to, "%C :%c (%s) - %s", to, asd->sd_c,
+ asd->sd_name, asd->sd_desc);
+}
+
+/** Contains information about all statistics. */
+struct StatDesc statsinfo[] = {
+ { 'a', "nameservers", STAT_FLAG_OPERFEAT|STAT_FLAG_LOCONLY, FEAT_HIS_STATS_a,
+ report_dns_servers, 0,
+ "DNS servers." },
+ { 'c', "connect", STAT_FLAG_OPERFEAT, FEAT_HIS_STATS_c,
+ stats_configured_links, CONF_SERVER,
+ "Remote server connection lines." },
+ { 'd', "maskrules", (STAT_FLAG_OPERFEAT | STAT_FLAG_CASESENS), FEAT_HIS_STATS_d,
+ stats_crule_list, CRULE_MASK,
+ "Dynamic routing configuration." },
+ { 'D', "crules", (STAT_FLAG_OPERFEAT | STAT_FLAG_CASESENS), FEAT_HIS_STATS_d,
+ stats_crule_list, CRULE_ALL,
+ "Dynamic routing configuration." },
+ { 'e', "engine", STAT_FLAG_OPERFEAT, FEAT_HIS_STATS_e,
+ stats_engine, 0,
+ "Report server event loop engine." },
+ { 'f', "features", (STAT_FLAG_OPERFEAT | STAT_FLAG_CASESENS), FEAT_HIS_STATS_f,
+ feature_report, 0,
+ "Feature settings." },
+ { 'F', "featuresall", (STAT_FLAG_OPERFEAT | STAT_FLAG_CASESENS), FEAT_HIS_STATS_f,
+ feature_report, 1,
+ "All feature settings, including defaulted values." },
+ { 'g', "glines", STAT_FLAG_OPERFEAT, FEAT_HIS_STATS_g,
+ gline_stats, 0,
+ "Global bans (G-lines)." },
+ { 'i', "access", (STAT_FLAG_OPERFEAT | STAT_FLAG_VARPARAM), FEAT_HIS_STATS_i,
+ stats_access, CONF_CLIENT,
+ "Connection authorization lines." },
+ { 'j', "histogram", (STAT_FLAG_OPERFEAT | STAT_FLAG_CASESENS), FEAT_HIS_STATS_j,
+ msgq_histogram, 0,
+ "Message length histogram." },
+ { 'J', "jupes", (STAT_FLAG_OPERFEAT | STAT_FLAG_CASESENS), FEAT_HIS_STATS_J,
+ stats_nickjupes, 0,
+ "Nickname jupes." },
+ { 'k', "klines", (STAT_FLAG_OPERFEAT | STAT_FLAG_VARPARAM), FEAT_HIS_STATS_k,
+ stats_klines, 0,
+ "Local bans (K-Lines)." },
+ { 'l', "links", (STAT_FLAG_OPERFEAT | STAT_FLAG_VARPARAM | STAT_FLAG_CASESENS),
+ FEAT_HIS_STATS_l,
+ stats_links, 0,
+ "Current connections information." },
+ { 'L', "modules", (STAT_FLAG_OPERFEAT | STAT_FLAG_CASESENS),
+ FEAT_HIS_STATS_L,
+ stats_modules, 0,
+ "Dynamically loaded modules." },
+ { 'm', "commands", (STAT_FLAG_OPERFEAT | STAT_FLAG_CASESENS), FEAT_HIS_STATS_m,
+ stats_commands, 0,
+ "Message usage information." },
+ { 'o', "operators", STAT_FLAG_OPERFEAT, FEAT_HIS_STATS_o,
+ stats_configured_links, CONF_OPERATOR,
+ "Operator information." },
+ { 'p', "ports", (STAT_FLAG_OPERFEAT | STAT_FLAG_VARPARAM), FEAT_HIS_STATS_p,
+ show_ports, 0,
+ "Listening ports." },
+ { 'q', "quarantines", (STAT_FLAG_OPERONLY | STAT_FLAG_VARPARAM), FEAT_HIS_STATS_q,
+ stats_quarantine, 0,
+ "Quarantined channels list." },
+ { 'R', "mappings", (STAT_FLAG_OPERFEAT | STAT_FLAG_CASESENS), FEAT_HIS_STATS_R,
+ stats_mapping, 0,
+ "Service mappings." },
+#ifdef DEBUGMODE
+ { 'r', "usage", (STAT_FLAG_OPERFEAT | STAT_FLAG_CASESENS), FEAT_HIS_STATS_r,
+ send_usage, 0,
+ "System resource usage (Debug only)." },
+#endif
+ { 'T', "motds", (STAT_FLAG_OPERFEAT | STAT_FLAG_CASESENS), FEAT_HIS_STATS_T,
+ motd_report, 0,
+ "Configured Message Of The Day files." },
+ { 't', "locals", (STAT_FLAG_OPERFEAT | STAT_FLAG_CASESENS), FEAT_HIS_STATS_t,
+ tstats, 0,
+ "Local connection statistics (Total SND/RCV, etc)." },
+ { 'U', "uworld", (STAT_FLAG_OPERFEAT | STAT_FLAG_CASESENS), FEAT_HIS_STATS_U,
+ stats_configured_links, CONF_UWORLD,
+ "Service server information." },
+ { 'u', "uptime", (STAT_FLAG_OPERFEAT | STAT_FLAG_CASESENS), FEAT_HIS_STATS_u,
+ stats_uptime, 0,
+ "Current uptime & highest connection count." },
+ { 'v', "vservers", (STAT_FLAG_OPERFEAT | STAT_FLAG_VARPARAM | STAT_FLAG_CASESENS), FEAT_HIS_STATS_v,
+ stats_servers_verbose, 1,
+ "Verbose server information." },
+ { 'V', "vserversmach", (STAT_FLAG_OPERFEAT | STAT_FLAG_VARPARAM | STAT_FLAG_CASESENS), FEAT_HIS_STATS_v,
+ stats_servers_verbose, 0,
+ "Verbose server information." },
+ { 'w', "userload", STAT_FLAG_OPERFEAT, FEAT_HIS_STATS_w,
+ calc_load, 0,
+ "Userload statistics." },
+ { 'x', "memusage", STAT_FLAG_OPERFEAT, FEAT_HIS_STATS_x,
+ stats_meminfo, 0,
+ "List usage information." },
+ { 'y', "classes", STAT_FLAG_OPERFEAT, FEAT_HIS_STATS_y,
+ report_classes, 0,
+ "Connection classes." },
+ { 'z', "memory", STAT_FLAG_OPERFEAT, FEAT_HIS_STATS_z,
+ count_memory, 0,
+ "Memory/Structure allocation information." },
+ { ' ', "iauth", STAT_FLAG_OPERFEAT, FEAT_HIS_STATS_IAUTH,
+ report_iauth_stats, 0,
+ "IAuth statistics." },
+ { ' ', "iauthconf", STAT_FLAG_OPERFEAT, FEAT_HIS_STATS_IAUTH,
+ report_iauth_conf, 0,
+ "IAuth configuration." },
+ { '*', "help", STAT_FLAG_CASESENS, FEAT_LAST_F,
+ stats_help, 0,
+ "Send help for stats." },
+ { '\0', 0, FEAT_LAST_F, 0, 0, 0 }
+};
+
+/** Maps from characters to statistics descriptors.
+ * Statistics descriptors with no single-character alias are not included.
+ */
+static struct StatDesc *statsmap[256];
+/** Number of statistics descriptors. */
+static int statscount;
+
+/** Compare two StatDesc structures by long name (StatDesc::sd_name).
+ * @param[in] a_ Pointer to a StatDesc.
+ * @param[in] b_ Pointer to a StatDesc.
+ * @return Less than, equal to, or greater than zero if \a a_ is
+ * lexicographically less than, equal to, or greater than \a b_.
+ */
+static int
+stats_cmp(const void *a_, const void *b_)
+{
+ const struct StatDesc *a = a_;
+ const struct StatDesc *b = b_;
+ return ircd_strcmp(a->sd_name, b->sd_name);
+}
+
+/** Compare a StatDesc's name against a string.
+ * @param[in] key Pointer to a null-terminated string.
+ * @param[in] sd_ Pointer to a StatDesc.
+ * @return Less than, equal to, or greater than zero if \a key is
+ * lexicographically less than, equal to, or greater than \a
+ * sd_->sd_name.
+ */
+static int
+stats_search(const void *key, const void *sd_)
+{
+ const struct StatDesc *sd = sd_;
+ return ircd_strcmp(key, sd->sd_name);
+}
+
+/** Look up a stats handler. If name_or_char is just one character
+ * long, use that as a character index; otherwise, look it up by name
+ * in #statsinfo.
+ * @param[in] name_or_char Null-terminated string to look up.
+ * @return The statistics descriptor for \a name_or_char (NULL if none).
+ */
+const struct StatDesc *
+stats_find(const char *name_or_char)
+{
+ if (!name_or_char[1])
+ return statsmap[name_or_char[0] - CHAR_MIN];
+ else
+ return bsearch(name_or_char, statsinfo, statscount, sizeof(statsinfo[0]), stats_search);
+}
+
+/** Build statsmap from the statsinfo array. */
+void
+stats_init(void)
+{
+ struct StatDesc *sd;
+
+ /* Count number of stats entries and sort them. */
+ for (statscount = 0, sd = statsinfo; sd->sd_name; sd++, statscount++) {}
+ qsort(statsinfo, statscount, sizeof(statsinfo[0]), stats_cmp);
+
+ /* Build the mapping */
+ for (sd = statsinfo; sd->sd_name; sd++)
+ {
+ if (!sd->sd_c)
+ continue;
+ else if (sd->sd_flags & STAT_FLAG_CASESENS)
+ /* case sensitive character... */
+ statsmap[sd->sd_c - CHAR_MIN] = sd;
+ else
+ {
+ /* case insensitive--make sure to put in two entries */
+ statsmap[ToLower(sd->sd_c) - CHAR_MIN] = sd;
+ statsmap[ToUpper(sd->sd_c) - CHAR_MIN] = sd;
+ }
+ }
+}