ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_stats.c
(Generate patch)

Comparing:
ircd-hybrid/modules/m_stats.c (file contents), Revision 30 by adx, Sun Oct 2 20:03:27 2005 UTC vs.
ircd-hybrid/trunk/modules/m_stats.c (file contents), Revision 2116 by michael, Sun May 26 11:44:01 2013 UTC

# Line 19 | Line 19
19   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
20   *  USA
21   *
22 < *  $Id: m_stats.c,v 1.190 2005/09/27 12:43:33 adx Exp $
22 > *  $Id$
23   */
24  
25   #include "stdinc.h"
26 < #include "tools.h"       /* dlink_node/dlink_list */
27 < #include "handlers.h"    /* m_pass prototype */
26 > #include "list.h"        /* dlink_node/dlink_list */
27   #include "client.h"      /* Client */
29 – #include "common.h"      /* TRUE/FALSE */
28   #include "irc_string.h"  
29   #include "ircd.h"        /* me */
30   #include "listener.h"    /* show_ports */
31   #include "s_gline.h"
32 < #include "ircd_handler.h"
33 < #include "msg.h"         /* Message */
32 > #include "conf.h"
33 > #include "conf_class.h"
34   #include "hostmask.h"
35   #include "numeric.h"     /* ERR_xxx */
36   #include "send.h"        /* sendto_one */
37   #include "fdlist.h"      /* PF and friends */
38   #include "s_bsd.h"       /* highest_fd */
41 – #include "s_conf.h"      /* AccessItem, report_configured_links */
39   #include "s_misc.h"      /* serv_info */
40   #include "s_serv.h"      /* hunt_server */
44 – #include "s_stats.h"     /* tstats */
41   #include "s_user.h"      /* show_opers */
42   #include "event.h"       /* events */
43   #include "dbuf.h"
44 + #include "hook.h"
45   #include "parse.h"
46   #include "modules.h"
50 – #include "hook.h"
47   #include "resv.h"  /* report_resv */
48   #include "whowas.h"
49 < #include "list.h"
50 <
55 < static void do_stats(struct Client *, int, char **);
56 < static void m_stats(struct Client *, struct Client *, int, char *[]);
57 < static void mo_stats(struct Client *, struct Client *, int, char *[]);
58 < static void ms_stats(struct Client *, struct Client *, int, char *[]);
49 > #include "watch.h"
50 > #include "irc_res.h"
51  
60 – struct Message stats_msgtab = {
61 –  "STATS", 0, 0, 2, 0, MFLG_SLOW, 0,
62 –  { m_unregistered, m_stats, ms_stats, m_ignore, mo_stats, m_ignore }
63 – };
52  
53 < #ifndef STATIC_MODULES
66 < const char *_version = "$Revision: 1.190 $";
67 < static struct Callback *stats_cb;
68 <
69 < static void *
70 < va_stats(va_list args)
71 < {
72 <  struct Client *source_p = va_arg(args, struct Client *);
73 <  int parc = va_arg(args, int);
74 <  char **parv = va_arg(args, char **);
75 <
76 <  do_stats(source_p, parc, parv);
77 <  return NULL;
78 < }
79 <
80 < void
81 < _modinit(void)
82 < {
83 <  stats_cb = register_callback("doing_stats", va_stats);
84 <  mod_add_cmd(&stats_msgtab);
85 < }
86 <
87 < void
88 < _moddeinit(void)
89 < {
90 <  mod_del_cmd(&stats_msgtab);
91 <  uninstall_hook(stats_cb, va_stats);
92 < }
93 < #endif
53 > const char *from, *to;
54  
55 < static char *parse_stats_args(int, char **, int *, int *);
96 < static void stats_L(struct Client *, char *, int, int, char);
97 < static void stats_L_list(struct Client *s, char *, int, int, dlink_list *, char);
98 <
99 < static void stats_dns_servers(struct Client *);
100 < static void stats_connect(struct Client *);
101 < static void stats_deny(struct Client *);
102 < static void stats_tdeny(struct Client *);
103 < static void stats_exempt(struct Client *);
104 < static void stats_events(struct Client *);
105 < static void stats_pending_glines(struct Client *);
106 < static void stats_glines(struct Client *);
107 < static void stats_gdeny(struct Client *);
108 < static void stats_hubleaf(struct Client *);
109 < static void stats_auth(struct Client *);
110 < static void stats_tklines(struct Client *);
111 < static void stats_klines(struct Client *);
112 < static void stats_messages(struct Client *);
113 < static void stats_oper(struct Client *);
114 < static void stats_operedup(struct Client *);
115 < static void stats_ports(struct Client *);
116 < static void stats_resv(struct Client *);
117 < static void stats_usage(struct Client *);
118 < static void stats_tstats(struct Client *);
119 < static void stats_uptime(struct Client *);
120 < static void stats_shared(struct Client *);
121 < static void stats_servers(struct Client *);
122 < static void stats_gecos(struct Client *);
123 < static void stats_class(struct Client *);
124 < static void stats_memory(struct Client *);
125 < static void stats_servlinks(struct Client *);
126 < static void stats_ltrace(struct Client *, int, char **);
127 < static void stats_ziplinks(struct Client *);
128 <
129 < /* This table contains the possible stats items, in order:
130 < * /stats name,  function to call, operonly? adminonly? /stats letter
131 < * case only matters in the stats letter column.. -- fl_ */
132 < static const struct StatsStruct
55 > static const struct shared_flags
56   {
57 +  const unsigned int type;
58    const unsigned char letter;
59 <  void (*handler)();
60 <  const unsigned int need_oper;
61 <  const unsigned int need_admin;
62 < } stats_cmd_table[] = {
63 <  /* letter     function            need_oper need_admin */
64 <  { 'a',        stats_dns_servers,      1,      1,      },
65 <  { 'A',        stats_dns_servers,      1,      1,      },
66 <  { 'c',        stats_connect,          1,      0,      },
67 <  { 'C',        stats_connect,          1,      0,      },
68 <  { 'd',        stats_tdeny,            1,      0,      },
69 <  { 'D',        stats_deny,             1,      0,      },
146 <  { 'e',        stats_exempt,           1,      0,      },
147 <  { 'E',        stats_events,           1,      1,      },
148 <  { 'f',        fd_dump,                1,      1,      },
149 <  { 'F',        fd_dump,                1,      1,      },
150 <  { 'g',        stats_pending_glines,   1,      0,      },
151 <  { 'G',        stats_glines,           1,      0,      },
152 <  { 'h',        stats_hooks,            1,      1,      },
153 <  { 'H',        stats_hubleaf,          1,      0,      },
154 <  { 'i',        stats_auth,             0,      0,      },
155 <  { 'I',        stats_auth,             0,      0,      },
156 <  { 'k',        stats_tklines,          0,      0,      },
157 <  { 'K',        stats_klines,           0,      0,      },
158 <  { 'l',        stats_ltrace,           1,      0,      },
159 <  { 'L',        stats_ltrace,           1,      0,      },
160 <  { 'm',        stats_messages,         0,      0,      },
161 <  { 'M',        stats_messages,         0,      0,      },
162 <  { 'o',        stats_oper,             0,      0,      },
163 <  { 'O',        stats_oper,             0,      0,      },
164 <  { 'p',        stats_operedup,         0,      0,      },
165 <  { 'P',        stats_ports,            0,      0,      },
166 <  { 'q',        stats_resv,             1,      0,      },
167 <  { 'Q',        stats_resv,             1,      0,      },
168 <  { 'r',        stats_usage,            1,      0,      },
169 <  { 'R',        stats_usage,            1,      0,      },
170 <  { 't',        stats_tstats,           1,      0,      },
171 <  { 'T',        stats_tstats,           1,      0,      },
172 <  { 'u',        stats_uptime,           0,      0,      },
173 <  { 'U',        stats_shared,           1,      0,      },
174 <  { 'v',        stats_servers,          1,      0,      },
175 <  { 'V',        stats_gdeny,            1,      0,      },
176 <  { 'x',        stats_gecos,            1,      0,      },
177 <  { 'X',        stats_gecos,            1,      0,      },
178 <  { 'y',        stats_class,            1,      0,      },
179 <  { 'Y',        stats_class,            1,      0,      },
180 <  { 'z',        stats_memory,           1,      0,      },
181 <  { 'Z',        stats_ziplinks,         1,      0,      },
182 <  { '?',        stats_servlinks,        0,      0,      },
183 <  { '\0',       (void(*)())0,           0,      0,      }
59 > } flag_table[] = {
60 >  { SHARED_KLINE,   'K' },
61 >  { SHARED_UNKLINE, 'U' },
62 >  { SHARED_XLINE,   'X' },
63 >  { SHARED_UNXLINE, 'Y' },
64 >  { SHARED_RESV,    'Q' },
65 >  { SHARED_UNRESV,  'R' },
66 >  { SHARED_LOCOPS,  'L' },
67 >  { SHARED_DLINE,   'D' },
68 >  { SHARED_UNDLINE, 'E' },
69 >  { 0, '\0' }
70   };
71  
72 < const char *from, *to;
73 <
72 > /*
73 > * inputs       - pointer to client requesting confitem report
74 > *              - ConfType to report
75 > * output       - none
76 > * side effects -
77 > */
78   static void
79 < do_stats(struct Client *source_p, int parc, char **parv)
79 > report_confitem_types(struct Client *source_p, enum maskitem_type type)
80   {
81 <  char statchar = *parv[1];
82 <  int i;
81 >  dlink_node *ptr = NULL, *dptr = NULL;
82 >  struct MaskItem *conf = NULL;
83 >  const struct shared_flags *shared = NULL;
84 >  char buf[12];
85 >  char *p = NULL;
86  
87 <  if (statchar == '\0')
87 >  switch (type)
88    {
89 <    sendto_one(source_p, form_str(RPL_ENDOFSTATS),
90 <               from, to, '*');
91 <    return;
92 <  }
89 >  case CONF_XLINE:
90 >    DLINK_FOREACH(ptr, xconf_items.head)
91 >    {
92 >      conf = ptr->data;
93  
94 <  for (i = 0; stats_cmd_table[i].handler; i++)
95 <  {
96 <    if (stats_cmd_table[i].letter == statchar)
94 >      sendto_one(source_p, form_str(RPL_STATSXLINE),
95 >                 me.name, source_p->name,
96 >                 conf->until ? 'x': 'X', conf->count,
97 >                 conf->name, conf->reason);
98 >    }
99 >    break;
100 >
101 >  case CONF_ULINE:
102 >    shared = flag_table;
103 >    DLINK_FOREACH(ptr, uconf_items.head)
104      {
105 <      /* The stats table says what privs are needed, so check --fl_ */
206 <      if ((stats_cmd_table[i].need_admin && !IsAdmin(source_p)) ||
207 <          (stats_cmd_table[i].need_oper && !IsOper(source_p)))
208 <      {
209 <        sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
210 <                   from, to);
211 <        break;
212 <      }
105 >      conf = ptr->data;
106  
107 <      /* Blah, stats L needs the parameters, none of the others do.. */
108 <      if (statchar == 'L' || statchar == 'l')
109 <        stats_cmd_table[i].handler(source_p, parc, parv);
107 >      p = buf;
108 >
109 >      *p++ = 'c';
110 >      for (; shared->type; ++shared)
111 >        if (shared->type & conf->flags)
112 >          *p++ = shared->letter;
113 >        else
114 >          *p++ = ToLower(shared->letter);
115 >
116 >      sendto_one(source_p, form_str(RPL_STATSULINE),
117 >                 me.name, source_p->name, conf->name,
118 >                 conf->user?conf->user: "*",
119 >                 conf->host?conf->host: "*", buf);
120 >    }
121 >
122 >    shared = flag_table;
123 >    DLINK_FOREACH(ptr, cluster_items.head)
124 >    {
125 >      conf = ptr->data;
126 >
127 >      p = buf;
128 >
129 >      *p++ = 'C';
130 >      for (; shared->type; ++shared)
131 >        if (shared->type & conf->flags)
132 >          *p++ = shared->letter;
133 >        else
134 >          *p++ = ToLower(shared->letter);
135 >
136 >      sendto_one(source_p, form_str(RPL_STATSULINE),
137 >                 me.name, source_p->name, conf->name,
138 >                 "*", "*", buf);
139 >    }
140 >
141 >    break;
142 >
143 >  case CONF_OPER:
144 >    DLINK_FOREACH(ptr, oconf_items.head)
145 >    {
146 >      conf = ptr->data;
147 >
148 >      /* Don't allow non opers to see oper privs */
149 >      if (HasUMode(source_p, UMODE_OPER))
150 >        sendto_one(source_p, form_str(RPL_STATSOLINE),
151 >                   me.name, source_p->name, 'O', conf->count, conf->user, conf->host,
152 >                   conf->name, oper_privs_as_string(conf->port),
153 >                   conf->class ? conf->class->name : "<default>");
154        else
155 <        stats_cmd_table[i].handler(source_p);
155 >        sendto_one(source_p, form_str(RPL_STATSOLINE),
156 >                   me.name, source_p->name, 'O', conf->count, conf->user, conf->host,
157 >                   conf->name, "0",
158 >                   conf->class ? conf->class->name : "<default>");
159 >    }
160 >    break;
161  
162 <      break;
162 >  case CONF_SERVICE:
163 >    DLINK_FOREACH(ptr, service_items.head)
164 >    {
165 >      conf = ptr->data;
166 >      sendto_one(source_p, form_str(RPL_STATSSERVICE),
167 >                 me.name, source_p->name, 'S', "*", conf->name, 0, 0);
168      }
169 <  }
169 >    break;
170  
171 <  sendto_one(source_p, form_str(RPL_ENDOFSTATS),
172 <             from, to, statchar);
173 < }
171 >  case CONF_SERVER:
172 >    DLINK_FOREACH(ptr, server_items.head)
173 >    {
174 >      p = buf;
175 >      conf = ptr->data;
176  
177 < /*
229 < * m_stats()
230 < *      parv[0] = sender prefix
231 < *      parv[1] = stat letter/command
232 < *      parv[2] = (if present) server/mask in stats L
233 < *
234 < * This will search the tables for the appropriate stats letter/command,
235 < * if found execute it.  
236 < */
237 < static void
238 < m_stats(struct Client *client_p, struct Client *source_p,
239 <        int parc, char *parv[])
240 < {
241 <  static time_t last_used = 0;
177 >      buf[0] = '\0';
178  
179 <  /* Is the stats meant for us? */
180 <  if (!ConfigFileEntry.disable_remote)
181 <    if (hunt_server(client_p,source_p,":%s STATS %s :%s",2,parc,parv) != HUNTED_ISME)
182 <      return;
179 >      if (IsConfAllowAutoConn(conf))
180 >        *p++ = 'A';
181 >      if (IsConfSSL(conf))
182 >        *p++ = 'S';
183 >      if (buf[0] == '\0')
184 >        *p++ = '*';
185  
186 <  if (!MyClient(source_p) && IsCapable(source_p->from, CAP_TS6) && HasID(source_p))
249 <  {
250 <    from = me.id;
251 <    to = source_p->id;
252 <  }
253 <  else
254 <  {
255 <    from = me.name;
256 <    to = source_p->name;
257 <  }
186 >      *p = '\0';
187  
188 <  /* Check the user is actually allowed to do /stats, and isnt flooding */
189 <  if ((last_used + ConfigFileEntry.pace_wait) > CurrentTime)
190 <  {
191 <    sendto_one(source_p,form_str(RPL_LOAD2HI),
192 <               from, to);
193 <    return;
194 <  }
195 <  else
196 <    last_used = CurrentTime;
188 >      /*
189 >       * Allow admins to see actual ips unless hide_server_ips is enabled
190 >       */
191 >      if (!ConfigServerHide.hide_server_ips && HasUMode(source_p, UMODE_ADMIN))
192 >        sendto_one(source_p, form_str(RPL_STATSCLINE),
193 >                   me.name, source_p->name, 'C', conf->host,
194 >                   buf, conf->name, conf->port,
195 >                   conf->class ? conf->class->name : "<default>");
196 >        else
197 >          sendto_one(source_p, form_str(RPL_STATSCLINE),
198 >                     me.name, source_p->name, 'C',
199 >                     "*@127.0.0.1", buf, conf->name, conf->port,
200 >                     conf->class ? conf->class->name : "<default>");
201 >    }
202 >    break;
203  
204 < #ifdef STATIC_MODULES
205 <  do_stats(source_p, parc, parv);
206 < #else
207 <  execute_callback(stats_cb, source_p, parc, parv);
208 < #endif
204 >  case CONF_HUB:
205 >    DLINK_FOREACH(ptr, server_items.head)
206 >    {
207 >      conf = ptr->data;
208 >
209 >      DLINK_FOREACH(dptr, conf->hub_list.head)
210 >        sendto_one(source_p, form_str(RPL_STATSHLINE), me.name,
211 >                   source_p->name, 'H', dptr->data, conf->name, 0, "*");
212 >    }
213 >
214 >    DLINK_FOREACH(ptr, server_items.head)
215 >    {
216 >      conf = ptr->data;
217 >
218 >      DLINK_FOREACH(dptr, conf->leaf_list.head)
219 >        sendto_one(source_p, form_str(RPL_STATSLLINE), me.name,
220 >                   source_p->name, 'L', dptr->data, conf->name, 0, "*");
221 >    }
222 >
223 >    break;
224 >
225 >  default:
226 >    break;
227 >  }
228   }
229  
230 < /*
277 < * mo_stats()
278 < *      parv[0] = sender prefix
279 < *      parv[1] = stat letter/command
280 < *      parv[2] = (if present) server/mask in stats L, or target
230 > /* report_resv()
231   *
232 < * This will search the tables for the appropriate stats letter,
233 < * if found execute it.  
232 > * inputs       - pointer to client pointer to report to.
233 > * output       - NONE
234 > * side effects - report all resvs to client.
235   */
236   static void
237 < mo_stats(struct Client *client_p, struct Client *source_p,
287 <         int parc, char *parv[])
237 > report_resv(struct Client *source_p)
238   {
239 <  if (hunt_server(client_p, source_p, ":%s STATS %s :%s", 2,
240 <                  parc, parv) != HUNTED_ISME)
291 <     return;
239 >  dlink_node *ptr = NULL;
240 >  struct MaskItem *conf = NULL;
241  
242 <  if (!MyClient(source_p) && IsCapable(source_p->from, CAP_TS6) && HasID(source_p))
242 >  DLINK_FOREACH(ptr, resv_channel_list.head)
243    {
244 <    from = me.id;
245 <    to = source_p->id;
244 >    conf = ptr->data;
245 >    sendto_one(source_p, form_str(RPL_STATSQLINE),
246 >               me.name, source_p->name,
247 >               conf->until ? 'q' : 'Q', conf->count,
248 >               conf->name, conf->reason);
249    }
250 <  else
250 >
251 >  DLINK_FOREACH(ptr, nresv_items.head)
252    {
253 <    from = me.name;
254 <    to = source_p->name;
253 >    conf = ptr->data;
254 >    sendto_one(source_p, form_str(RPL_STATSQLINE),
255 >               me.name, source_p->name,
256 >               conf->until ? 'q' : 'Q', conf->count,
257 >               conf->name, conf->reason);
258    }
303 –
304 – #ifdef STATIC_MODULES
305 –  do_stats(source_p, parc, parv);
306 – #else
307 –  execute_callback(stats_cb, source_p, parc, parv);
308 – #endif
259   }
260  
261   /*
# Line 316 | Line 266 | mo_stats(struct Client *client_p, struct
266   * -avalon
267   */
268   static void
269 < send_usage(struct Client *source_p)
269 > stats_usage(struct Client *source_p, int parc, char *parv[])
270   {
321 – #ifndef _WIN32
271    struct rusage rus;
272    time_t secs;
273    time_t rup;
# Line 344 | Line 293 | send_usage(struct Client *source_p)
293    if (secs == 0)
294      secs = 1;
295  
296 <  rup = (CurrentTime - me.since) * hzz;
296 >  rup = (CurrentTime - me.localClient->since) * hzz;
297  
298    if (rup == 0)
299      rup = 1;
300  
301    sendto_one(source_p,
302 <             ":%s %d %s R :CPU Secs %d:%d User %d:%d System %d:%d",
302 >             ":%s %d %s R :CPU Secs %d:%02d User %d:%02d System %d:%02d",
303               me.name, RPL_STATSDEBUG, source_p->name, (int)(secs/60), (int)(secs%60),
304               (int)(rus.ru_utime.tv_sec/60), (int)(rus.ru_utime.tv_sec%60),
305               (int)(rus.ru_stime.tv_sec/60), (int)(rus.ru_stime.tv_sec%60));
# Line 370 | Line 319 | send_usage(struct Client *source_p)
319    sendto_one(source_p, ":%s %d %s R :Signals %d Context Vol. %d Invol %d",
320               me.name, RPL_STATSDEBUG, source_p->name, (int)rus.ru_nsignals,
321               (int)rus.ru_nvcsw, (int)rus.ru_nivcsw);
373 – #endif
322   }
323  
324   static void
325 < count_memory(struct Client *source_p)
325 > stats_memory(struct Client *source_p, int parc, char *parv[])
326   {
327    const dlink_node *gptr = NULL;
328    const dlink_node *dlink = NULL;
329  
330 <  int local_client_conf_count = 0;      /* local client conf links */
331 <  int users_counted = 0;                /* user structs */
330 >  unsigned int local_client_conf_count = 0;      /* local client conf links */
331 >  unsigned int users_counted = 0;                /* user structs */
332  
333 <  int channel_users = 0; /* XXX */
334 <  int channel_invites = 0;
335 <  int channel_bans = 0;
336 <  int channel_except = 0;
337 <  int channel_invex = 0;
338 <
339 <  int wwu = 0;                  /* whowas users */
340 <  int class_count = 0;          /* classes */
341 <  int users_invited_count = 0;  /* users invited */
342 <  int aways_counted = 0;
343 <  int number_ips_stored;        /* number of ip addresses hashed */
344 <
345 <  unsigned long channel_memory = 0;
346 <  size_t channel_ban_memory = 0;
347 <  size_t channel_except_memory = 0;
400 <  size_t channel_invex_memory = 0;
333 >  unsigned int channel_members = 0;
334 >  unsigned int channel_invites = 0;
335 >  unsigned int channel_bans = 0;
336 >  unsigned int channel_except = 0;
337 >  unsigned int channel_invex = 0;
338 >
339 >  unsigned int wwu = 0;                  /* whowas users */
340 >  unsigned int class_count = 0;          /* classes */
341 >  unsigned int aways_counted = 0;
342 >  unsigned int number_ips_stored;        /* number of ip addresses hashed */
343 >
344 >  uint64_t channel_memory = 0;
345 >  uint64_t channel_ban_memory = 0;
346 >  uint64_t channel_except_memory = 0;
347 >  uint64_t channel_invex_memory = 0;
348  
349    unsigned int safelist_count = 0;
350 <  size_t safelist_memory = 0;
350 >  uint64_t safelist_memory = 0;
351  
352 <  unsigned long away_memory = 0;       /* memory used by aways           */
353 <  unsigned long wwm = 0;               /* whowas array memory used       */
354 <  unsigned long conf_memory = 0;       /* memory used by conf lines      */
355 <  unsigned long mem_ips_stored;        /* memory used by ip address hash */
356 <
357 <  unsigned long client_hash_table_size = 0;
411 <  unsigned long channel_hash_table_size = 0;
412 <  unsigned long resv_hash_table_size = 0;
413 <  unsigned long id_hash_table_size = 0;
414 <  unsigned long total_channel_memory = 0;
415 <  unsigned long totww = 0;
352 >  uint64_t wwm = 0;               /* whowas array memory used       */
353 >  uint64_t conf_memory = 0;       /* memory used by conf lines      */
354 >  uint64_t mem_ips_stored;        /* memory used by ip address hash */
355 >
356 >  uint64_t total_channel_memory = 0;
357 >  uint64_t totww = 0;
358  
359    unsigned int local_client_count  = 0;
360    unsigned int remote_client_count = 0;
361  
362 <  unsigned int local_client_memory_used  = 0;
363 <  unsigned int remote_client_memory_used = 0;
362 >  uint64_t local_client_memory_used  = 0;
363 >  uint64_t remote_client_memory_used = 0;
364  
365 <  unsigned long total_memory = 0;
365 >  uint64_t total_memory = 0;
366    unsigned int topic_count = 0;
367  
368 <  count_whowas_memory(&wwu, &wwm);
368 >  unsigned int watch_list_headers = 0;   /* watchlist headers     */
369 >  unsigned int watch_list_entries = 0;   /* watchlist entries     */
370 >  uint64_t watch_list_memory = 0; /* watchlist memory used */
371 >
372  
373    DLINK_FOREACH(gptr, global_client_list.head)
374    {
# Line 433 | Line 378 | count_memory(struct Client *source_p)
378      {
379        ++local_client_count;
380        local_client_conf_count += dlink_list_length(&target_p->localClient->confs);
381 +      watch_list_entries += dlink_list_length(&target_p->localClient->watches);
382      }
383      else
384        ++remote_client_count;
# Line 440 | Line 386 | count_memory(struct Client *source_p)
386      if (IsClient(target_p))
387      {
388        ++users_counted;
443 –      users_invited_count += dlink_list_length(&target_p->invited);
389  
390 <      if (target_p->away != NULL)
446 <      {
390 >      if (target_p->away[0])
391          ++aways_counted;
448 –        away_memory += strlen(target_p->away) + 1;
449 –      }
392      }
393    }
394  
# Line 455 | Line 397 | count_memory(struct Client *source_p)
397                     sizeof(struct Channel);
398    DLINK_FOREACH(gptr, global_channel_list.head)
399    {
400 <    struct Ban *actualBan;
401 <    struct Channel *chptr = gptr->data;
400 >    const struct Ban *actualBan;
401 >    const struct Channel *chptr = gptr->data;
402  
403 <    channel_users   += dlink_list_length(&chptr->members);
403 >    channel_members += dlink_list_length(&chptr->members);
404      channel_invites += dlink_list_length(&chptr->invites);
405  
406 <    if (chptr->topic != NULL)
406 >    if (chptr->topic[0])
407        ++topic_count;
408  
409 <    if ((channel_bans = dlink_list_length(&chptr->banlist)))
410 <    {
469 <      channel_ban_memory = channel_bans * sizeof(struct Ban);
409 >    channel_bans += dlink_list_length(&chptr->banlist);
410 >    channel_ban_memory += dlink_list_length(&chptr->banlist) * sizeof(struct Ban);
411  
412 <      DLINK_FOREACH(dlink, chptr->banlist.head)
413 <      {
414 <        actualBan = dlink->data;
415 <        assert(actualBan->who);
412 >    DLINK_FOREACH(dlink, chptr->banlist.head)
413 >    {
414 >      actualBan = dlink->data;
415 >      assert(actualBan->who);
416  
417 <        channel_ban_memory += actualBan->len + 3;
418 <        channel_ban_memory += strlen(actualBan->who) + 1;
478 <      }
417 >      channel_ban_memory += actualBan->len + 1;
418 >      channel_ban_memory += strlen(actualBan->who) + 1;
419      }
420  
421 <    if ((channel_except = dlink_list_length(&chptr->exceptlist)))
422 <    {
483 <      channel_except_memory = channel_except * sizeof(struct Ban);
421 >    channel_except += dlink_list_length(&chptr->exceptlist);
422 >    channel_except_memory += dlink_list_length(&chptr->exceptlist) * sizeof(struct Ban);
423  
424 <      DLINK_FOREACH(dlink, chptr->exceptlist.head)
425 <      {
426 <        actualBan = dlink->data;
427 <        assert(actualBan->who);
424 >    DLINK_FOREACH(dlink, chptr->exceptlist.head)
425 >    {
426 >      actualBan = dlink->data;
427 >      assert(actualBan->who);
428  
429 <        channel_except_memory += actualBan->len + 3;
430 <        channel_except_memory += strlen(actualBan->who) + 1;
492 <      }
429 >      channel_except_memory += actualBan->len + 1;
430 >      channel_except_memory += strlen(actualBan->who) + 1;
431      }
432  
433 <    if ((channel_invex = dlink_list_length(&chptr->invexlist)))
434 <    {
497 <      channel_invex_memory = channel_invex * sizeof(struct Ban);
433 >    channel_invex += dlink_list_length(&chptr->invexlist);
434 >    channel_invex_memory += dlink_list_length(&chptr->invexlist) * sizeof(struct Ban);
435  
436 <      DLINK_FOREACH(dlink, chptr->invexlist.head)
437 <      {
438 <        actualBan = dlink->data;
439 <        assert(actualBan->who);
436 >    DLINK_FOREACH(dlink, chptr->invexlist.head)
437 >    {
438 >      actualBan = dlink->data;
439 >      assert(actualBan->who);
440  
441 <        channel_invex_memory += actualBan->len + 3;
442 <        channel_invex_memory += strlen(actualBan->who) + 1;
506 <      }
441 >      channel_invex_memory += actualBan->len + 1;
442 >      channel_invex_memory += strlen(actualBan->who) + 1;
443      }
444    }
445  
# Line 512 | Line 448 | count_memory(struct Client *source_p)
448      safelist_memory = safelist_count * sizeof(struct ListTask);
449      DLINK_FOREACH(gptr, listing_client_list.head)
450      {
451 <      struct Client *acptr = gptr->data;
451 >      const struct Client *acptr = gptr->data;
452  
453        DLINK_FOREACH(dlink, acptr->localClient->list_task->show_mask.head)
454          safelist_memory += strlen(dlink->data);
# Line 535 | Line 471 | count_memory(struct Client *source_p)
471    }
472   #endif
473    /* count up all classes */
474 <  class_count = dlink_list_length(&class_items);
474 >  class_count = dlink_list_length(class_get_list());
475 >
476 >  count_whowas_memory(&wwu, &wwm);
477 >  watch_count_memory(&watch_list_headers, &watch_list_memory);
478 >
479 >  sendto_one(source_p, ":%s %d %s z :WATCH headers %u(%llu) entries %d(%u)",
480 >             me.name, RPL_STATSDEBUG, source_p->name, watch_list_headers,
481 >             watch_list_memory, watch_list_entries,
482 >             watch_list_entries * sizeof(dlink_node) * 2);
483  
484 <  sendto_one(source_p, ":%s %d %s z :Clients %u(%lu) Invites %u(%lu)",
484 >  sendto_one(source_p, ":%s %d %s z :Clients %u(%u)",
485               me.name, RPL_STATSDEBUG, source_p->name, users_counted,
486 <             (unsigned long)(users_counted * sizeof(struct Client)),
543 <             users_invited_count, (unsigned long)(users_invited_count * sizeof(dlink_node)));
486 >             (users_counted * sizeof(struct Client)));
487  
488 <  sendto_one(source_p, ":%s %d %s z :User aways %u(%d)",
488 >  sendto_one(source_p, ":%s %d %s z :User aways %u",
489               me.name, RPL_STATSDEBUG, source_p->name,
490 <             aways_counted, (int)away_memory);
490 >             aways_counted);
491  
492 <  sendto_one(source_p, ":%s %d %s z :Attached confs %u(%lu)",
492 >  sendto_one(source_p, ":%s %d %s z :Attached confs %u(%llu)",
493               me.name, RPL_STATSDEBUG, source_p->name,
494               local_client_conf_count,
495 <             (unsigned long)(local_client_conf_count * sizeof(dlink_node)));
553 <
554 <  /* XXX  ConfigItemList fix */
555 < #if 0
556 <  sendto_one(source_p, ":%s %d %s z :Conflines %lu(%d)",
557 <             me.name, RPL_STATSDEBUG, source_p->name,
558 <             dlink_list_length(&ConfigItemList), (int) conf_memory);
559 < #endif
495 >             (unsigned long long)(local_client_conf_count * sizeof(dlink_node)));
496  
497 <  sendto_one(source_p, ":%s %d %s z :Resv channels %lu(%lu) nicks %lu(%lu)",
497 >  sendto_one(source_p, ":%s %d %s z :Resv channels %u(%lu) nicks %u(%lu)",
498               me.name, RPL_STATSDEBUG, source_p->name,
499               dlink_list_length(&resv_channel_list),
500 <             dlink_list_length(&resv_channel_list) * sizeof(struct ResvChannel),
500 >             dlink_list_length(&resv_channel_list) * sizeof(struct MaskItem),
501               dlink_list_length(&nresv_items),
502 <             dlink_list_length(&nresv_items) * sizeof(struct MatchItem));
502 >             dlink_list_length(&nresv_items) * sizeof(struct MaskItem));
503  
504 <  sendto_one(source_p, ":%s %d %s z :Classes %u(%lu)",
504 >  sendto_one(source_p, ":%s %d %s z :Classes %u(%llu)",
505               me.name, RPL_STATSDEBUG, source_p->name,
506 <             class_count, (unsigned long)(class_count * sizeof(struct ClassItem)));
506 >             class_count, (unsigned long long)(class_count * sizeof(struct ClassItem)));
507  
508 <  sendto_one(source_p, ":%s %d %s z :Channels %lu(%lu) Topics %u(%d)",
508 >  sendto_one(source_p, ":%s %d %s z :Channels %u(%llu) Topics %u(%u)",
509               me.name, RPL_STATSDEBUG, source_p->name,
510               dlink_list_length(&global_channel_list),
511               channel_memory, topic_count, topic_count *
512               (TOPICLEN + 1 + USERHOST_REPLYLEN));
513  
514 <  sendto_one(source_p, ":%s %d %s z :Bans %u(%u)",
514 >  sendto_one(source_p, ":%s %d %s z :Bans %u(%llu)",
515               me.name, RPL_STATSDEBUG, source_p->name,
516               channel_bans, channel_ban_memory);
517  
518 <  sendto_one(source_p, ":%s %d %s z :Exceptions %u(%u)",
518 >  sendto_one(source_p, ":%s %d %s z :Exceptions %u(%llu)",
519               me.name, RPL_STATSDEBUG, source_p->name,
520               channel_except, channel_except_memory);
521  
522 <  sendto_one(source_p, ":%s %d %s z :Invex %u(%u)",
522 >  sendto_one(source_p, ":%s %d %s z :Invex %u(%llu)",
523               me.name, RPL_STATSDEBUG, source_p->name,
524               channel_invex, channel_invex_memory);
525  
526 <  sendto_one(source_p, ":%s %d %s z :Channel members %u(%lu) invite %u(%lu)",
527 <             me.name, RPL_STATSDEBUG, source_p->name, channel_users,
528 <             (unsigned long)(channel_users * sizeof(struct Membership)),
529 <             channel_invites, (unsigned long)channel_invites *
530 <             sizeof(dlink_node));
526 >  sendto_one(source_p, ":%s %d %s z :Channel members %u(%llu) invites %u(%llu)",
527 >             me.name, RPL_STATSDEBUG, source_p->name, channel_members,
528 >             (unsigned long long)(channel_members * sizeof(struct Membership)),
529 >             channel_invites, (unsigned long long)channel_invites *
530 >             sizeof(dlink_node) * 2);
531  
532    total_channel_memory = channel_memory + channel_ban_memory +
533 <                         channel_users * sizeof(struct Membership) +
534 <                         channel_invites * sizeof(dlink_node);
533 >                         channel_members * sizeof(struct Membership) +
534 >                         (channel_invites * sizeof(dlink_node)*2);
535  
536 <  sendto_one(source_p, ":%s %d %s z :Safelist %u(%u)",
536 >  sendto_one(source_p, ":%s %d %s z :Safelist %u(%llu)",
537               me.name, RPL_STATSDEBUG, source_p->name,
538               safelist_count, safelist_memory);
539  
540 <  sendto_one(source_p, ":%s %d %s z :Whowas users %u(%lu)",
540 >  sendto_one(source_p, ":%s %d %s z :Whowas users %u(%llu)",
541               me.name, RPL_STATSDEBUG, source_p->name,
542 <             wwu, (unsigned long)(wwu * sizeof(struct Client)));
542 >             wwu, (unsigned long long)(wwu * sizeof(struct Client)));
543  
544 <  sendto_one(source_p, ":%s %d %s z :Whowas array %u(%d)",
544 >  sendto_one(source_p, ":%s %d %s z :Whowas array %u(%llu)",
545               me.name, RPL_STATSDEBUG, source_p->name,
546 <             NICKNAMEHISTORYLENGTH, (int)wwm);
546 >             NICKNAMEHISTORYLENGTH, wwm);
547  
548    totww = wwu * sizeof(struct Client) + wwm;
613 – /****
614 –  client_hash_table_size  = hash_get_client_table_size();
615 –  channel_hash_table_size = hash_get_channel_table_size();
616 –  resv_hash_table_size    = hash_get_resv_table_size();
617 –  id_hash_table_size      = hash_get_id_table_size();
549  
619 –  sendto_one(source_p, ":%s %d %s z :Hash: client %u(%lu) chan %u(%lu) resv "
620 –             "%u(%lu) id %u(%lu)",
621 –             me.name, RPL_STATSDEBUG, source_p->name,
622 –             U_MAX, client_hash_table_size,
623 –             CH_MAX, channel_hash_table_size , R_MAX,
624 –             resv_hash_table_size, U_MAX, id_hash_table_size);
625 – ****/
550    count_ip_hash(&number_ips_stored,&mem_ips_stored);
551 <  sendto_one(source_p, ":%s %d %s z :iphash %u(%d)",
551 >  sendto_one(source_p, ":%s %d %s z :iphash %u(%llu)",
552               me.name, RPL_STATSDEBUG, source_p->name,
553 <             number_ips_stored, (int)mem_ips_stored);
553 >             number_ips_stored, mem_ips_stored);
554  
555    total_memory = totww + total_channel_memory + conf_memory + class_count *
556                   sizeof(struct ClassItem);
557 <  total_memory += client_hash_table_size;
558 <  total_memory += channel_hash_table_size;
559 <  total_memory += resv_hash_table_size;
636 <  total_memory += id_hash_table_size;
637 <
638 <  sendto_one(source_p, ":%s %d %s z :Total: whowas %d channel %d conf %d",
639 <             me.name, RPL_STATSDEBUG, source_p->name, (int)totww,
640 <            (int)total_channel_memory, (int)conf_memory);
557 >  sendto_one(source_p, ":%s %d %s z :Total: whowas %llu channel %llu conf %llu",
558 >             me.name, RPL_STATSDEBUG, source_p->name, totww,
559 >             total_channel_memory, conf_memory);
560  
561    local_client_memory_used = local_client_count*(sizeof(struct Client) + sizeof(struct LocalUser));
562    total_memory += local_client_memory_used;
563 <  sendto_one(source_p, ":%s %d %s z :Local client Memory in use: %d(%d)",
563 >  sendto_one(source_p, ":%s %d %s z :Local client Memory in use: %u(%llu)",
564               me.name, RPL_STATSDEBUG, source_p->name, local_client_count,
565               local_client_memory_used);
566  
567    remote_client_memory_used = remote_client_count * sizeof(struct Client);
568    total_memory += remote_client_memory_used;
569 <  sendto_one(source_p, ":%s %d %s z :Remote client Memory in use: %d(%d)",
569 >  sendto_one(source_p, ":%s %d %s z :Remote client Memory in use: %u(%llu)",
570               me.name, RPL_STATSDEBUG, source_p->name, remote_client_count,
571               remote_client_memory_used);
572  
654 –  block_heap_report_stats(source_p);
655 –
573    sendto_one(source_p,
574 <             ":%s %d %s z :TOTAL: %d Available:  Current max RSS: %lu",
574 >             ":%s %d %s z :TOTAL: %llu",
575               me.name, RPL_STATSDEBUG, source_p->name,
576 <             (int)total_memory, get_maxrss());
576 >             total_memory);
577   }
578  
579   static void
# Line 666 | Line 583 | stats_dns_servers(struct Client *source_
583   }
584  
585   static void
586 < stats_connect(struct Client *source_p)
586 > stats_connect(struct Client *source_p, int parc, char *parv[])
587   {
588 <  report_confitem_types(source_p, SERVER_TYPE, 0);
588 >  report_confitem_types(source_p, CONF_SERVER);
589   }
590  
591   /* stats_deny()
# Line 678 | Line 595 | stats_connect(struct Client *source_p)
595   * side effects - client is given dline list.
596   */
597   static void
598 < stats_deny(struct Client *source_p)
598 > stats_deny(struct Client *source_p, int parc, char *parv[])
599   {
600 <  struct AddressRec *arec;
601 <  struct ConfItem *conf;
602 <  struct AccessItem *aconf;
686 <  int i;
600 >  struct MaskItem *conf;
601 >  dlink_node *ptr = NULL;
602 >  unsigned int i = 0;
603  
604 <  for (i = 0; i < ATABLE_SIZE; i++)
604 >
605 >  for (i = 0; i < ATABLE_SIZE; ++i)
606    {
607 <    for (arec = atable[i]; arec; arec=arec->next)
607 >    DLINK_FOREACH(ptr, atable[i].head)
608      {
609 <      if (arec->type == CONF_DLINE)
693 <      {
694 <        aconf = arec->aconf;
609 >      struct AddressRec *arec = ptr->data;
610  
611 <        /* dont report a tdline as a dline */
612 <        if (aconf->flags & CONF_FLAGS_TEMPORARY)
698 <          continue;
611 >      if (arec->type != CONF_DLINE)
612 >        continue;
613  
614 <        conf = unmap_conf_item(aconf);
614 >      conf = arec->conf;
615  
616 <        sendto_one(source_p, form_str(RPL_STATSDLINE),
617 <                   from, to, 'D', aconf->host, aconf->reason,
618 <                   aconf->oper_reason);
619 <      }
616 >      /* dont report a tdline as a dline */
617 >      if (conf->until)
618 >        continue;
619 >
620 >      sendto_one(source_p, form_str(RPL_STATSDLINE),
621 >                 from, to, 'D', conf->host, conf->reason);
622      }
623    }
624   }
# Line 714 | Line 630 | stats_deny(struct Client *source_p)
630   * side effects - client is given dline list.
631   */
632   static void
633 < stats_tdeny(struct Client *source_p)
633 > stats_tdeny(struct Client *source_p, int parc, char *parv[])
634   {
635 <  struct AddressRec *arec;
636 <  struct ConfItem *conf;
637 <  struct AccessItem *aconf;
638 <  int i;
635 >  struct MaskItem *conf = NULL;
636 >  dlink_node *ptr = NULL;
637 >  unsigned int i = 0;
638 >
639  
640 <  for (i = 0; i < ATABLE_SIZE; i++)
640 >  for (i = 0; i < ATABLE_SIZE; ++i)
641    {
642 <    for (arec = atable[i]; arec; arec=arec->next)
642 >    DLINK_FOREACH(ptr, atable[i].head)
643      {
644 <      if (arec->type == CONF_DLINE)
729 <      {
730 <        aconf = arec->aconf;
644 >      struct AddressRec *arec = ptr->data;
645  
646 <        /* dont report a permanent dline as a tdline */
647 <        if (!(aconf->flags & CONF_FLAGS_TEMPORARY))
734 <          continue;
646 >      if (arec->type != CONF_DLINE)
647 >        continue;
648  
649 <        conf = unmap_conf_item(aconf);
649 >      conf = arec->conf;
650  
651 <        sendto_one(source_p, form_str(RPL_STATSDLINE),
652 <                   from, to, 'd', aconf->host, aconf->reason,
653 <                   aconf->oper_reason);
654 <      }
651 >      /* dont report a permanent dline as a tdline */
652 >      if (!conf->until)
653 >        continue;
654 >
655 >      sendto_one(source_p, form_str(RPL_STATSDLINE),
656 >                 from, to, 'd', conf->host, conf->reason);
657      }
658    }
659   }
# Line 750 | Line 665 | stats_tdeny(struct Client *source_p)
665   * side effects - client is given list of exempt blocks
666   */
667   static void
668 < stats_exempt(struct Client *source_p)
668 > stats_exempt(struct Client *source_p, int parc, char *parv[])
669   {
670 <  struct AddressRec *arec;
671 <  struct ConfItem *conf;
672 <  struct AccessItem *aconf;
758 <  int i;
670 >  struct MaskItem *conf;
671 >  dlink_node *ptr = NULL;
672 >  unsigned int i = 0;
673  
674 <  for (i = 0; i < ATABLE_SIZE; i++)
674 >  if (ConfigFileEntry.stats_e_disabled)
675    {
676 <    for (arec = atable[i]; arec; arec=arec->next)
676 >    sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
677 >               from, to);
678 >    return;
679 >  }
680 >
681 >
682 >  for (i = 0; i < ATABLE_SIZE; ++i)
683 >  {
684 >    DLINK_FOREACH(ptr, atable[i].head)
685      {
686 <      if (arec->type == CONF_EXEMPTDLINE)
765 <      {
766 <        aconf = arec->aconf;
686 >      struct AddressRec *arec = ptr->data;
687  
688 <        conf = unmap_conf_item(aconf);
688 >      if (arec->type != CONF_EXEMPT)
689 >        continue;
690  
691 <        sendto_one(source_p, form_str(RPL_STATSDLINE),
692 <                   from, to, 'e', aconf->host,
693 <                   aconf->reason, aconf->oper_reason);
694 <      }
691 >      conf = arec->conf;
692 >
693 >      sendto_one(source_p, form_str(RPL_STATSDLINE), from, to, 'e',
694 >                 conf->host, "");
695      }
696    }
697   }
698  
699   static void
700 < stats_events(struct Client *source_p)
700 > stats_events(struct Client *source_p, int parc, char *parv[])
701   {
702    show_events(source_p);
703   }
# Line 788 | Line 709 | stats_events(struct Client *source_p)
709   * side effects - client is shown list of pending glines
710   */
711   static void
712 < stats_pending_glines(struct Client *source_p)
712 > stats_pending_glines(struct Client *source_p, int parc, char *parv[])
713   {
714 < #ifdef GLINE_VOTING
715 <  dlink_node *pending_node;
716 <  struct gline_pending *glp_ptr;
717 <  char timebuffer[MAX_DATE_STRING];
797 <  struct tm *tmptr;
714 >  const dlink_node *dn_ptr = NULL;
715 >  const struct gline_pending *glp_ptr = NULL;
716 >  char timebuffer[MAX_DATE_STRING] = { '\0' };
717 >  struct tm *tmptr = NULL;
718  
719    if (!ConfigFileEntry.glines)
720    {
# Line 803 | Line 723 | stats_pending_glines(struct Client *sour
723      return;
724    }
725  
726 <  if (dlink_list_length(&pending_glines) > 0)
726 >  if (dlink_list_length(&pending_glines[GLINE_PENDING_ADD_TYPE]) > 0)
727      sendto_one(source_p, ":%s NOTICE %s :Pending G-lines",
728                 from, to);
729  
730 <  DLINK_FOREACH(pending_node, pending_glines.head)
730 >  DLINK_FOREACH(dn_ptr, pending_glines[GLINE_PENDING_ADD_TYPE].head)
731    {
732 <    glp_ptr = pending_node->data;
733 <    tmptr   = localtime(&glp_ptr->time_request1);
732 >    glp_ptr = dn_ptr->data;
733 >    tmptr   = localtime(&glp_ptr->vote_1.time_request);
734      strftime(timebuffer, MAX_DATE_STRING, "%Y/%m/%d %H:%M:%S", tmptr);
735  
736      sendto_one(source_p,
737                 ":%s NOTICE %s :1) %s!%s@%s on %s requested gline at %s for %s@%s [%s]",
738 <               from, to, glp_ptr->oper_nick1,
739 <               glp_ptr->oper_user1, glp_ptr->oper_host1,
740 <               glp_ptr->oper_server1, timebuffer,
741 <               glp_ptr->user, glp_ptr->host, glp_ptr->reason1);
738 >               from, to, glp_ptr->vote_1.oper_nick,
739 >               glp_ptr->vote_1.oper_user, glp_ptr->vote_1.oper_host,
740 >               glp_ptr->vote_1.oper_server, timebuffer,
741 >               glp_ptr->user, glp_ptr->host, glp_ptr->vote_1.reason);
742  
743 <    if (glp_ptr->oper_nick2[0] != '\0')
743 >    if (glp_ptr->vote_2.oper_nick[0] != '\0')
744      {
745 <      tmptr = localtime(&glp_ptr->time_request2);
745 >      tmptr = localtime(&glp_ptr->vote_2.time_request);
746        strftime(timebuffer, MAX_DATE_STRING, "%Y/%m/%d %H:%M:%S", tmptr);
747        sendto_one(source_p,
748        ":%s NOTICE %s :2) %s!%s@%s on %s requested gline at %s for %s@%s [%s]",
749 <                 from, to, glp_ptr->oper_nick2,
750 <                 glp_ptr->oper_user2, glp_ptr->oper_host2,
751 <                 glp_ptr->oper_server2, timebuffer,
752 <                 glp_ptr->user, glp_ptr->host, glp_ptr->reason2);
749 >               from, to, glp_ptr->vote_2.oper_nick,
750 >               glp_ptr->vote_2.oper_user, glp_ptr->vote_2.oper_host,
751 >               glp_ptr->vote_2.oper_server, timebuffer,
752 >               glp_ptr->user, glp_ptr->host, glp_ptr->vote_2.reason);
753      }
754    }
755  
756    sendto_one(source_p, ":%s NOTICE %s :End of Pending G-lines",
757               from, to);
758 < #else
759 <  sendto_one(source_p, ":%s NOTICE %s :This server does not support G-Line voting",
758 >
759 >  if (dlink_list_length(&pending_glines[GLINE_PENDING_DEL_TYPE]) > 0)
760 >    sendto_one(source_p, ":%s NOTICE %s :Pending UNG-lines",
761 >               from, to);
762 >
763 >  DLINK_FOREACH(dn_ptr, pending_glines[GLINE_PENDING_DEL_TYPE].head)
764 >  {
765 >    glp_ptr = dn_ptr->data;
766 >    tmptr   = localtime(&glp_ptr->vote_1.time_request);
767 >    strftime(timebuffer, MAX_DATE_STRING, "%Y/%m/%d %H:%M:%S", tmptr);
768 >
769 >    sendto_one(source_p,
770 >               ":%s NOTICE %s :1) %s!%s@%s on %s requested ungline at %s for %s@%s [%s]",
771 >               from, to, glp_ptr->vote_1.oper_nick,
772 >               glp_ptr->vote_1.oper_user, glp_ptr->vote_1.oper_host,
773 >               glp_ptr->vote_1.oper_server, timebuffer,
774 >               glp_ptr->user, glp_ptr->host, glp_ptr->vote_1.reason);
775 >
776 >    if (glp_ptr->vote_2.oper_nick[0] != '\0')
777 >    {
778 >      tmptr = localtime(&glp_ptr->vote_2.time_request);
779 >      strftime(timebuffer, MAX_DATE_STRING, "%Y/%m/%d %H:%M:%S", tmptr);
780 >      sendto_one(source_p,
781 >      ":%s NOTICE %s :2) %s!%s@%s on %s requested ungline at %s for %s@%s [%s]",
782 >               from, to, glp_ptr->vote_2.oper_nick,
783 >               glp_ptr->vote_2.oper_user, glp_ptr->vote_2.oper_host,
784 >               glp_ptr->vote_2.oper_server, timebuffer,
785 >               glp_ptr->user, glp_ptr->host, glp_ptr->vote_2.reason);
786 >
787 >    }
788 >  }
789 >
790 >  sendto_one(source_p, ":%s NOTICE %s :End of Pending UNG-lines",
791               from, to);
841 – #endif /* GLINE VOTING */
792   }
793  
794   /* stats_glines()
# Line 848 | Line 798 | stats_pending_glines(struct Client *sour
798   * side effects - client is shown list of glines
799   */
800   static void
801 < stats_glines(struct Client *source_p)
801 > stats_glines(struct Client *source_p, int parc, char *parv[])
802   {
803 <  struct AddressRec *arec = NULL;
804 <  int i = 0;
803 >  dlink_node *ptr = NULL;
804 >  unsigned int i = 0;
805  
806    if (!ConfigFileEntry.glines)
807    {
# Line 860 | Line 810 | stats_glines(struct Client *source_p)
810      return;
811    }
812  
813 <  for (; i < ATABLE_SIZE; ++i)
813 >  for (i = 0; i < ATABLE_SIZE; ++i)
814    {
815 <    for (arec = atable[i]; arec; arec=arec->next)
815 >    DLINK_FOREACH(ptr, atable[i].head)
816      {
817 +      const struct AddressRec *arec = ptr->data;
818 +
819        if (arec->type == CONF_GLINE)
820        {
821 <        const struct AccessItem *aconf = arec->aconf;
821 >        const struct MaskItem *conf = arec->conf;
822  
823          sendto_one(source_p, form_str(RPL_STATSKLINE),
824 <                   from, to, "G",
825 <                   aconf->host ? aconf->host : "*",
826 <                   aconf->user ? aconf->user : "*",
827 <                   aconf->reason ? aconf->reason : "No reason", "" );
824 >                   from, to, 'G',
825 >                   conf->host ? conf->host : "*",
826 >                   conf->user ? conf->user : "*",
827 >                   conf->reason ? conf->reason : CONF_NOREASON);
828        }
829      }
830    }
831   }
832  
833 < /* stats_gdeny()
833 > static void
834 > stats_hubleaf(struct Client *source_p, int parc, char *parv[])
835 > {
836 >  report_confitem_types(source_p, CONF_HUB);
837 > }
838 >
839 > /*
840 > * show_iline_prefix()
841   *
842 < * input        - client pointer
843 < * outputs      - none
844 < * side effects - client is shown gline ACL
842 > * inputs       - pointer to struct Client requesting output
843 > *              - pointer to struct MaskItem
844 > *              - name to which iline prefix will be prefixed to
845 > * output       - pointer to static string with prefixes listed in ascii form
846 > * side effects - NONE
847   */
848 < static void
849 < stats_gdeny(struct Client *source_p)
848 > static const char *
849 > show_iline_prefix(const struct Client *sptr, const struct MaskItem *conf)
850   {
851 <  if (!ConfigFileEntry.glines)
852 <  {
892 <    sendto_one(source_p, ":%s NOTICE %s :This server does not support G-Lines",
893 <               from, to);
894 <    return;
895 <  }
851 >  static char prefix_of_host[USERLEN + 15];
852 >  char *prefix_ptr = prefix_of_host;
853  
854 <  report_confitem_types(source_p, GDENY_TYPE, 0);
854 >  if (IsConfWebIRC(conf))
855 >    *prefix_ptr++ = '<';
856 >  if (IsNoTilde(conf))
857 >    *prefix_ptr++ = '-';
858 >  if (IsLimitIp(conf))
859 >    *prefix_ptr++ = '!';
860 >  if (IsNeedIdentd(conf))
861 >    *prefix_ptr++ = '+';
862 >  if (!IsNeedPassword(conf))
863 >    *prefix_ptr++ = '&';
864 >  if (IsConfExemptResv(conf))
865 >    *prefix_ptr++ = '$';
866 >  if (IsNoMatchIp(conf))
867 >    *prefix_ptr++ = '%';
868 >  if (IsConfDoSpoofIp(conf))
869 >    *prefix_ptr++ = '=';
870 >  if (MyOper(sptr) && IsConfExemptKline(conf))
871 >    *prefix_ptr++ = '^';
872 >  if (MyOper(sptr) && IsConfExemptGline(conf))
873 >    *prefix_ptr++ = '_';
874 >  if (MyOper(sptr) && IsConfExemptLimits(conf))
875 >    *prefix_ptr++ = '>';
876 >  if (IsConfCanFlood(conf))
877 >    *prefix_ptr++ = '|';
878 >
879 >  strlcpy(prefix_ptr, conf->user, USERLEN+1);
880 >
881 >  return prefix_of_host;
882   }
883  
884   static void
885 < stats_hubleaf(struct Client *source_p)
886 < {
887 <  report_confitem_types(source_p, HUB_TYPE, 0);
888 <  report_confitem_types(source_p, LEAF_TYPE, 0);
885 > report_auth(struct Client *client_p, int parc, char *parv[])
886 > {
887 >  struct MaskItem *conf = NULL;
888 >  dlink_node *ptr = NULL;
889 >  unsigned int i;
890 >
891 >
892 >  for (i = 0; i < ATABLE_SIZE; ++i)
893 >  {
894 >    DLINK_FOREACH(ptr, atable[i].head)
895 >    {
896 >      struct AddressRec *arec = ptr->data;
897 >
898 >      if (arec->type != CONF_CLIENT)
899 >        continue;
900 >
901 >      conf = arec->conf;
902 >
903 >      if (!MyOper(client_p) && IsConfDoSpoofIp(conf))
904 >        continue;
905 >
906 >      /* We are doing a partial list, based on what matches the u@h of the
907 >       * sender, so prepare the strings for comparing --fl_
908 >       */
909 >      if (ConfigFileEntry.hide_spoof_ips)
910 >        sendto_one(client_p, form_str(RPL_STATSILINE), me.name,
911 >                   client_p->name, 'I',
912 >                   conf->name == NULL ? "*" : conf->name,
913 >                   show_iline_prefix(client_p, conf),
914 >                   IsConfDoSpoofIp(conf) ? "255.255.255.255" :
915 >                   conf->host, conf->port,
916 >                   conf->class ? conf->class->name : "<default>");
917 >
918 >      else
919 >        sendto_one(client_p, form_str(RPL_STATSILINE), me.name,
920 >                   client_p->name, 'I',
921 >                   conf->name == NULL ? "*" : conf->name,
922 >                   show_iline_prefix(client_p, conf),
923 >                   conf->host, conf->port,
924 >                   conf->class ? conf->class->name : "<default>");
925 >    }
926 >  }
927   }
928  
929   static void
930 < stats_auth(struct Client *source_p)
930 > stats_auth(struct Client *source_p, int parc, char *parv[])
931   {
932    /* Oper only, if unopered, return ERR_NOPRIVILEGES */
933 <  if ((ConfigFileEntry.stats_i_oper_only == 2) && !IsOper(source_p))
933 >  if ((ConfigFileEntry.stats_i_oper_only == 2) && !HasUMode(source_p, UMODE_OPER))
934      sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
935                 from, to);
936  
937    /* If unopered, Only return matching auth blocks */
938 <  else if ((ConfigFileEntry.stats_i_oper_only == 1) && !IsOper(source_p))
938 >  else if ((ConfigFileEntry.stats_i_oper_only == 1) && !HasUMode(source_p, UMODE_OPER))
939    {
940 <    struct ConfItem *conf;
919 <    struct AccessItem *aconf;
940 >    struct MaskItem *conf;
941  
942      if (MyConnect(source_p))
943 <      aconf = find_conf_by_address(source_p->host,
943 >      conf = find_conf_by_address(source_p->host,
944                                     &source_p->localClient->ip,
945                                     CONF_CLIENT,
946                                     source_p->localClient->aftype,
947                                     source_p->username,
948 <                                   source_p->localClient->passwd);
948 >                                   source_p->localClient->passwd, 1);
949      else
950 <      aconf = find_conf_by_address(source_p->host, NULL, CONF_CLIENT,
951 <                                   0, source_p->username, NULL);
950 >      conf = find_conf_by_address(source_p->host, NULL, CONF_CLIENT,
951 >                                   0, source_p->username, NULL, 1);
952  
953 <    if (aconf == NULL)
953 >    if (conf == NULL)
954        return;
955  
935 –    conf = unmap_conf_item(aconf);
936 –
956      sendto_one(source_p, form_str(RPL_STATSILINE), from,
957                 to, 'I',
958 <               "*", show_iline_prefix(source_p, aconf, aconf->user),
959 <               aconf->host, aconf->port,
960 <               aconf->class_ptr ? aconf->class_ptr->name : "<default>");
958 >               "*", show_iline_prefix(source_p, conf),
959 >               conf->host, conf->port,
960 >               conf->class ? conf->class->name : "<default>");
961    }
962    /* They are opered, or allowed to see all auth blocks */
963    else
964 <    report_auth(source_p);
964 >    report_auth(source_p, 0, NULL);
965   }
966  
967 + /* report_Klines()
968 + * Inputs: Client to report to,
969 + *         type(==0 for perm, !=0 for temporary)
970 + *         mask
971 + * Output: None
972 + * Side effects: Reports configured K(or k)-lines to client_p.
973 + */
974   static void
975 < stats_tklines(struct Client *source_p)
975 > report_Klines(struct Client *client_p, int tkline)
976 > {
977 >  struct MaskItem *conf = NULL;
978 >  unsigned int i = 0;
979 >  char c = '\0';
980 >  dlink_node *ptr = NULL;
981 >
982 >  if (tkline)
983 >    c = 'k';
984 >  else
985 >    c = 'K';
986 >
987 >  for (i = 0; i < ATABLE_SIZE; ++i)
988 >  {
989 >    DLINK_FOREACH(ptr, atable[i].head)
990 >    {
991 >      struct AddressRec *arec = ptr->data;
992 >
993 >      if (arec->type != CONF_KLINE)
994 >        continue;
995 >
996 >      conf = arec->conf;
997 >
998 >      if ((!tkline && conf->until) ||
999 >          (tkline && !conf->until))
1000 >        continue;
1001 >
1002 >      if (HasUMode(client_p, UMODE_OPER))
1003 >        sendto_one(client_p, form_str(RPL_STATSKLINE), me.name,
1004 >                   client_p->name, c, conf->host, conf->user,
1005 >                   conf->reason);
1006 >      else
1007 >        sendto_one(client_p, form_str(RPL_STATSKLINE), me.name,
1008 >                   client_p->name, c, conf->host, conf->user,
1009 >                   conf->reason);
1010 >    }
1011 >  }
1012 > }
1013 >
1014 > static void
1015 > stats_tklines(struct Client *source_p, int parc, char *parv[])
1016   {
951 –  struct ConfItem *conf;
1017    /* Oper only, if unopered, return ERR_NOPRIVILEGES */
1018 <  if ((ConfigFileEntry.stats_k_oper_only == 2) && !IsOper(source_p))
1018 >  if ((ConfigFileEntry.stats_k_oper_only == 2) && !HasUMode(source_p, UMODE_OPER))
1019      sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
1020                 from, to);
1021  
1022    /* If unopered, Only return matching klines */
1023 <  else if ((ConfigFileEntry.stats_k_oper_only == 1) && !IsOper(source_p))
1023 >  else if ((ConfigFileEntry.stats_k_oper_only == 1) && !HasUMode(source_p, UMODE_OPER))
1024    {
1025 <    struct AccessItem *aconf;
1025 >    struct MaskItem *conf = NULL;
1026  
1027      if (MyConnect(source_p))
1028 <      aconf = find_conf_by_address(source_p->host,
1029 <                                   &source_p->localClient->ip,
1030 <                                   CONF_KILL,
1028 >      conf = find_conf_by_address(source_p->host,
1029 >                                  &source_p->localClient->ip,
1030 >                                   CONF_KLINE,
1031                                     source_p->localClient->aftype,
1032 <                                   source_p->username, NULL);
1032 >                                   source_p->username, NULL, 1);
1033      else
1034 <      aconf = find_conf_by_address(source_p->host, NULL, CONF_KILL,
1035 <                                   0, source_p->username, NULL);
1034 >      conf = find_conf_by_address(source_p->host, NULL, CONF_KLINE,
1035 >                                   0, source_p->username, NULL, 1);
1036  
1037 <    if (aconf == NULL)
1037 >    if (!conf)
1038        return;
1039  
1040      /* dont report a permanent kline as a tkline */
1041 <    if (!(aconf->flags & CONF_FLAGS_TEMPORARY))
1041 >    if (!conf->until)
1042        return;
1043  
979 –    conf = unmap_conf_item(aconf);
980 –
1044      sendto_one(source_p, form_str(RPL_STATSKLINE), from,
1045 <               to, "k", aconf->host, aconf->user, aconf->reason, "");
1045 >               to, 'k', conf->host, conf->user, conf->reason);
1046    }
1047    /* Theyre opered, or allowed to see all klines */
1048    else {
1049      report_Klines(source_p, 1);
987 –    report_confitem_types(source_p, RKLINE_TYPE, 1);
1050    }
1051   }
1052  
1053   static void
1054 < stats_klines(struct Client *source_p)
1054 > stats_klines(struct Client *source_p, int parc, char *parv[])
1055   {
1056    /* Oper only, if unopered, return ERR_NOPRIVILEGES */
1057 <  if ((ConfigFileEntry.stats_k_oper_only == 2) && !IsOper(source_p))
1057 >  if ((ConfigFileEntry.stats_k_oper_only == 2) && !HasUMode(source_p, UMODE_OPER))
1058      sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
1059                 from, to);
1060  
1061    /* If unopered, Only return matching klines */
1062 <  else if ((ConfigFileEntry.stats_k_oper_only == 1) && !IsOper(source_p))
1062 >  else if ((ConfigFileEntry.stats_k_oper_only == 1) && !HasUMode(source_p, UMODE_OPER))
1063    {
1064 <    struct AccessItem *aconf;
1064 >    struct MaskItem *conf = NULL;
1065  
1066      /* search for a kline */
1067 <    if(MyConnect(source_p))
1068 <      aconf = find_conf_by_address(source_p->host,
1067 >    if (MyConnect(source_p))
1068 >      conf = find_conf_by_address(source_p->host,
1069                                     &source_p->localClient->ip,
1070 <                                   CONF_KILL,
1070 >                                   CONF_KLINE,
1071                                     source_p->localClient->aftype,
1072 <                                   source_p->username, NULL);
1072 >                                   source_p->username, NULL, 0);
1073      else
1074 <      aconf = find_conf_by_address(source_p->host, NULL, CONF_KILL,
1075 <                                   0, source_p->username, NULL);
1074 >      conf = find_conf_by_address(source_p->host, NULL, CONF_KLINE,
1075 >                                   0, source_p->username, NULL, 0);
1076  
1077 <    if(aconf == NULL)
1077 >    if (!conf)
1078        return;
1079  
1080      /* dont report a tkline as a kline */
1081 <    if(aconf->flags & CONF_FLAGS_TEMPORARY)
1081 >    if (conf->until)
1082        return;
1083        
1084      sendto_one(source_p, form_str(RPL_STATSKLINE), from,
1085 <               to, "K", aconf->host, aconf->user, aconf->reason,
1024 <               aconf->oper_reason);
1085 >               to, 'K', conf->host, conf->user, conf->reason);
1086    }
1087    /* Theyre opered, or allowed to see all klines */
1088 <  else {
1088 >  else
1089      report_Klines(source_p, 0);
1029 –    report_confitem_types(source_p, RKLINE_TYPE, 0);
1030 –  }
1090   }
1091  
1092   static void
1093 < stats_messages(struct Client *source_p)
1093 > stats_messages(struct Client *source_p, int parc, char *parv[])
1094   {
1095    report_messages(source_p);
1096   }
1097  
1098   static void
1099 < stats_oper(struct Client *source_p)
1099 > stats_oper(struct Client *source_p, int parc, char *parv[])
1100   {
1101 <  if (!IsOper(source_p) && ConfigFileEntry.stats_o_oper_only)
1101 >  if (!HasUMode(source_p, UMODE_OPER) && ConfigFileEntry.stats_o_oper_only)
1102      sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
1103                 from, to);
1104    else
1105 <    report_confitem_types(source_p, OPER_TYPE, 0);
1105 >    report_confitem_types(source_p, CONF_OPER);
1106   }
1107  
1108   /* stats_operedup()
# Line 1053 | Line 1112 | stats_oper(struct Client *source_p)
1112   * side effects - client is shown a list of active opers
1113   */
1114   static void
1115 < stats_operedup(struct Client *source_p)
1115 > stats_operedup(struct Client *source_p, int parc, char *parv[])
1116   {
1117    dlink_node *ptr;
1118  
# Line 1061 | Line 1120 | stats_operedup(struct Client *source_p)
1120    {
1121      const struct Client *target_p = ptr->data;
1122  
1123 <    if (IsOperHidden(target_p) && !IsOper(source_p))
1123 >    if (HasUMode(target_p, UMODE_HIDDEN) && !HasUMode(source_p, UMODE_OPER))
1124        continue;
1125  
1126 <    if (MyClient(source_p) && IsOper(source_p))
1127 <      sendto_one(source_p, ":%s %d %s p :[%c][%s] %s (%s@%s) Idle: %d",
1126 >    if (MyClient(source_p) && HasUMode(source_p, UMODE_OPER))
1127 >      sendto_one(source_p, ":%s %d %s p :[%c][%s] %s (%s@%s) Idle: %u",
1128                   from, RPL_STATSDEBUG, to,
1129 <                 IsAdmin(target_p) ?
1071 <                 (IsOperHiddenAdmin(target_p) ? 'O' : 'A') : 'O',
1129 >                 HasUMode(target_p, UMODE_ADMIN) ? 'A' : 'O',
1130                   oper_privs_as_string(target_p->localClient->operflags),
1131                   target_p->name, target_p->username, target_p->host,
1132 <                 (int)(CurrentTime - target_p->localClient->last));
1132 >                 idle_time_get(source_p, target_p));
1133      else
1134 <      sendto_one(source_p, ":%s %d %s p :[%c] %s (%s@%s) Idle: %d",
1134 >      sendto_one(source_p, ":%s %d %s p :[%c] %s (%s@%s) Idle: %u",
1135                   from, RPL_STATSDEBUG, to,
1136 <                 IsAdmin(target_p) ?
1079 <                 (IsOperHiddenAdmin(target_p) ? 'O' : 'A') : 'O',
1136 >                 HasUMode(target_p, UMODE_ADMIN) ? 'A' : 'O',
1137                   target_p->name, target_p->username, target_p->host,
1138 <                 (int)(CurrentTime - target_p->localClient->last));
1138 >                 idle_time_get(source_p, target_p));
1139    }
1140  
1141 <  sendto_one(source_p, ":%s %d %s p :%lu OPER(s)",
1141 >  sendto_one(source_p, ":%s %d %s p :%u OPER(s)",
1142               from, RPL_STATSDEBUG, to, dlink_list_length(&oper_list));
1143   }
1144  
1145   static void
1146 < stats_ports(struct Client *source_p)
1146 > stats_ports(struct Client *source_p, int parc, char *parv[])
1147   {
1148 <  if (!IsOper(source_p) && ConfigFileEntry.stats_P_oper_only)
1148 >  if (!HasUMode(source_p, UMODE_OPER) && ConfigFileEntry.stats_P_oper_only)
1149      sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
1150                 from, to);
1151    else
# Line 1096 | Line 1153 | stats_ports(struct Client *source_p)
1153   }
1154  
1155   static void
1156 < stats_resv(struct Client *source_p)
1156 > stats_resv(struct Client *source_p, int parc, char *parv[])
1157   {
1158    report_resv(source_p);
1159   }
1160  
1161   static void
1162 < stats_usage(struct Client *source_p)
1162 > stats_service(struct Client *source_p, int parc, char *parv[])
1163   {
1164 <  send_usage(source_p);
1164 >  report_confitem_types(source_p, CONF_SERVICE);
1165   }
1166  
1167   static void
1168 < stats_tstats(struct Client *source_p)
1168 > stats_tstats(struct Client *source_p, int parc, char *parv[])
1169   {
1170 <  tstats(source_p);
1170 >  const struct Client *target_p = NULL;
1171 >  const dlink_node *ptr = NULL;
1172 >  struct ServerStatistics tmp;
1173 >  struct ServerStatistics *sp = &tmp;
1174 >
1175 >  memcpy(sp, &ServerStats, sizeof(struct ServerStatistics));
1176 >
1177 >  /*
1178 >   * must use the += operator. is_sv is not the number of currently
1179 >   * active server connections. Note the incrementation in
1180 >   * s_bsd.c:close_connection.
1181 >   */
1182 >  sp->is_sv += dlink_list_length(&serv_list);
1183 >
1184 >  DLINK_FOREACH(ptr, serv_list.head)
1185 >  {
1186 >    target_p = ptr->data;
1187 >
1188 >    sp->is_sbs += target_p->localClient->send.bytes;
1189 >    sp->is_sbr += target_p->localClient->recv.bytes;
1190 >    sp->is_sti += CurrentTime - target_p->localClient->firsttime;
1191 >  }
1192 >
1193 >  sp->is_cl += dlink_list_length(&local_client_list);
1194 >
1195 >  DLINK_FOREACH(ptr, local_client_list.head)
1196 >  {
1197 >    target_p = ptr->data;
1198 >
1199 >    sp->is_cbs += target_p->localClient->send.bytes;
1200 >    sp->is_cbr += target_p->localClient->recv.bytes;
1201 >    sp->is_cti += CurrentTime - target_p->localClient->firsttime;
1202 >  }
1203 >
1204 >  sp->is_ni += dlink_list_length(&unknown_list);
1205 >
1206 >  sendto_one(source_p, ":%s %d %s T :accepts %u refused %u",
1207 >             me.name, RPL_STATSDEBUG, source_p->name, sp->is_ac, sp->is_ref);
1208 >  sendto_one(source_p, ":%s %d %s T :unknown commands %u prefixes %u",
1209 >             me.name, RPL_STATSDEBUG, source_p->name, sp->is_unco, sp->is_unpf);
1210 >  sendto_one(source_p, ":%s %d %s T :nick collisions %u unknown closes %u",
1211 >             me.name, RPL_STATSDEBUG, source_p->name, sp->is_kill, sp->is_ni);
1212 >  sendto_one(source_p, ":%s %d %s T :wrong direction %u empty %u",
1213 >             me.name, RPL_STATSDEBUG, source_p->name, sp->is_wrdi, sp->is_empt);
1214 >  sendto_one(source_p, ":%s %d %s T :numerics seen %u",
1215 >             me.name, RPL_STATSDEBUG, source_p->name, sp->is_num);
1216 >  sendto_one(source_p, ":%s %d %s T :auth successes %u fails %u",
1217 >             me.name, RPL_STATSDEBUG, source_p->name, sp->is_asuc, sp->is_abad);
1218 >  sendto_one(source_p, ":%s %d %s T :Client Server",
1219 >             me.name, RPL_STATSDEBUG, source_p->name);
1220 >
1221 >  sendto_one(source_p, ":%s %d %s T :connected %u %u",
1222 >             me.name, RPL_STATSDEBUG, source_p->name,
1223 >             (unsigned int)sp->is_cl,
1224 >             (unsigned int)sp->is_sv);
1225 >  sendto_one(source_p, ":%s %d %s T :bytes sent %llu %llu",
1226 >             me.name, RPL_STATSDEBUG, source_p->name,
1227 >             sp->is_cbs, sp->is_sbs);
1228 >  sendto_one(source_p, ":%s %d %s T :bytes recv %llu %llu",
1229 >             me.name, RPL_STATSDEBUG, source_p->name,
1230 >             sp->is_cbr, sp->is_sbr);
1231 >  sendto_one(source_p, ":%s %d %s T :time connected %u %u",
1232 >             me.name, RPL_STATSDEBUG, source_p->name,
1233 >             (unsigned int)sp->is_cti,
1234 >             (unsigned int)sp->is_sti);
1235   }
1236  
1237   static void
1238 < stats_uptime(struct Client *source_p)
1238 > stats_uptime(struct Client *source_p, int parc, char *parv[])
1239   {
1240 <  time_t now = CurrentTime - me.since;
1240 >  time_t now = CurrentTime - me.localClient->since;
1241 >
1242    sendto_one(source_p, form_str(RPL_STATSUPTIME), from, to,
1243 <             now/86400, (now/3600)%24, (now/60)%60, now%60);
1244 <  if (!ConfigFileEntry.disable_remote || IsOper(source_p))
1243 >             now / 86400, (now / 3600) % 24, (now / 60) % 60, now % 60);
1244 >
1245 >  if (!ConfigFileEntry.disable_remote || HasUMode(source_p, UMODE_OPER))
1246       sendto_one(source_p, form_str(RPL_STATSCONN), from, to,
1247 <                MaxConnectionCount, MaxClientCount, Count.totalrestartcount);
1247 >                Count.max_loc_con, Count.max_loc_cli, Count.totalrestartcount);
1248   }
1249  
1250   static void
1251 < stats_shared(struct Client *source_p)
1251 > stats_shared(struct Client *source_p, int parc, char *parv[])
1252   {
1253 <  report_confitem_types(source_p, ULINE_TYPE, 0);
1253 >  report_confitem_types(source_p, CONF_ULINE);
1254   }
1255  
1256   /* stats_servers()
# Line 1137 | Line 1260 | stats_shared(struct Client *source_p)
1260   * side effects - client is shown lists of who connected servers
1261   */
1262   static void
1263 < stats_servers(struct Client *source_p)
1263 > stats_servers(struct Client *source_p, int parc, char *parv[])
1264   {
1265 <  struct Client *target_p;
1143 <  dlink_node *ptr;
1144 <  int j = 0;
1265 >  dlink_node *ptr = NULL;
1266  
1267    DLINK_FOREACH(ptr, serv_list.head)
1268    {
1269 <    target_p = ptr->data;
1149 <
1150 <    j++;
1269 >    const struct Client *target_p = ptr->data;
1270  
1271      sendto_one(source_p, ":%s %d %s v :%s (%s!%s@%s) Idle: %d",
1272 <               from, RPL_STATSDEBUG, to,
1273 <               target_p->name,
1274 <               (target_p->serv->by[0] ? target_p->serv->by : "Remote."),
1156 <               "*", "*", (int)(CurrentTime - target_p->lasttime));
1272 >               from, RPL_STATSDEBUG, to, target_p->name,
1273 >               (target_p->serv->by[0] ? target_p->serv->by : "Remote."),
1274 >               "*", "*", (int)(CurrentTime - target_p->localClient->lasttime));
1275    }
1276  
1277 <  sendto_one(source_p, ":%s %d %s v :%d Server(s)",
1278 <             from, RPL_STATSDEBUG, to, j);
1277 >  sendto_one(source_p, ":%s %d %s v :%u Server(s)",
1278 >             from, RPL_STATSDEBUG, to, dlink_list_length(&serv_list));
1279   }
1280  
1281   static void
1282 < stats_gecos(struct Client *source_p)
1282 > stats_gecos(struct Client *source_p, int parc, char *parv[])
1283   {
1284 <  report_confitem_types(source_p, XLINE_TYPE, 0);
1167 <  report_confitem_types(source_p, RXLINE_TYPE, 0);
1284 >  report_confitem_types(source_p, CONF_XLINE);
1285   }
1286  
1287   static void
1288 < stats_class(struct Client *source_p)
1288 > stats_class(struct Client *source_p, int parc, char *parv[])
1289   {
1290 <  report_confitem_types(source_p, CLASS_TYPE, 0);
1174 < }
1290 >  const dlink_node *ptr = NULL;
1291  
1292 < static void
1177 < stats_memory(struct Client *source_p)
1178 < {
1179 <  count_memory(source_p);
1180 < }
1181 <
1182 < static void
1183 < stats_ziplinks(struct Client *source_p)
1184 < {
1185 <  dlink_node *ptr;
1186 <  struct Client *target_p;
1187 <  unsigned int sent_data = 0;
1188 <
1189 <  DLINK_FOREACH(ptr, serv_list.head)
1292 >  DLINK_FOREACH(ptr, class_get_list()->head)
1293    {
1294 <    target_p = ptr->data;
1192 <
1193 <    if (IsCapable(target_p, CAP_ZIP))
1194 <    {
1195 <      /* we use memcpy(3) and a local copy of the structure to
1196 <       * work around a register use bug on GCC on the SPARC.
1197 <       * -jmallett, 04/27/2002
1198 <       */
1199 <      struct ZipStats zipstats;
1200 <      memcpy(&zipstats, &target_p->localClient->zipstats, sizeof (struct ZipStats));
1294 >    const struct ClassItem *class = ptr->data;
1295  
1296 <      sendto_one(source_p, ":%s %d %s Z :ZipLinks stats for %s send[%.2f%% "
1297 <                 "compression (%lu bytes data/%lu bytes wire)] recv[%.2f%% "
1298 <                 "compression (%lu bytes data/%lu bytes wire)]",
1299 <                 from, RPL_STATSDEBUG, to, target_p->name,
1300 <                 zipstats.out_ratio, zipstats.out, zipstats.out_wire,
1301 <                 zipstats.in_ratio,  zipstats.in,  zipstats.in_wire);
1302 <      ++sent_data;
1303 <    }
1296 >    sendto_one(source_p, form_str(RPL_STATSYLINE),
1297 >               me.name, source_p->name, 'Y',
1298 >               class->name, class->ping_freq,
1299 >               class->con_freq,
1300 >               class->max_total, class->max_sendq,
1301 >               class->max_recvq,
1302 >               class->ref_count,
1303 >               class->number_per_cidr, class->cidr_bitlen_ipv4,
1304 >               class->number_per_cidr, class->cidr_bitlen_ipv6,
1305 >               class->active ? "active" : "disabled");
1306    }
1211 –
1212 –  sendto_one(source_p, ":%s %d %s Z :%u ziplink(s)",
1213 –             from, RPL_STATSDEBUG, to, sent_data);
1307   }
1308  
1309   static void
1310 < stats_servlinks(struct Client *source_p)
1310 > stats_servlinks(struct Client *source_p, int parc, char *parv[])
1311   {
1312    uint64_t sendB = 0, recvB = 0;
1313    time_t uptime = 0;
1314 <  int j = 0;
1222 <  struct Client *target_p = NULL;
1223 <  dlink_node *ptr;
1314 >  dlink_node *ptr = NULL;
1315  
1316 <  if (ConfigServerHide.flatten_links && !IsOper(source_p))
1316 >  if (ConfigServerHide.flatten_links && !HasUMode(source_p, UMODE_OPER))
1317    {
1318      sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
1319                 from, to);
# Line 1231 | Line 1322 | stats_servlinks(struct Client *source_p)
1322  
1323    DLINK_FOREACH(ptr, serv_list.head)
1324    {
1325 <    target_p = ptr->data;
1325 >    struct Client *target_p = ptr->data;
1326 >
1327 >    if (HasFlag(target_p, FLAGS_SERVICE) && ConfigServerHide.hide_services)
1328 >      if (!HasUMode(source_p, UMODE_OPER))
1329 >        continue;
1330  
1236 –    ++j;
1331      sendB += target_p->localClient->send.bytes;
1332      recvB += target_p->localClient->recv.bytes;
1333  
1334      /* ":%s 211 %s %s %u %u %llu %u %llu :%u %u %s" */
1335      sendto_one(source_p, form_str(RPL_STATSLINKINFO),
1336                 from, to,
1337 <               get_client_name(target_p, IsAdmin(source_p) ? SHOW_IP : MASK_IP),
1337 >               get_client_name(target_p, HasUMode(source_p, UMODE_ADMIN) ? SHOW_IP : MASK_IP),
1338                 dbuf_length(&target_p->localClient->buf_sendq),
1339                 target_p->localClient->send.messages,
1340                 target_p->localClient->send.bytes >> 10,
1341                 target_p->localClient->recv.messages,
1342                 target_p->localClient->recv.bytes >> 10,
1343 <               (unsigned)(CurrentTime - target_p->firsttime),
1344 <               (CurrentTime > target_p->since) ? (unsigned)(CurrentTime - target_p->since): 0,
1345 <               IsOper(source_p) ? show_capabilities(target_p) : "TS");
1343 >               (unsigned)(CurrentTime - target_p->localClient->firsttime),
1344 >               (CurrentTime > target_p->localClient->since) ? (unsigned)(CurrentTime - target_p->localClient->since): 0,
1345 >               HasUMode(source_p, UMODE_OPER) ? show_capabilities(target_p) : "TS");
1346    }
1347  
1348    sendB >>= 10;
1349    recvB >>= 10;
1350  
1351    sendto_one(source_p, ":%s %d %s ? :%u total server(s)",
1352 <             from, RPL_STATSDEBUG, to, j);
1352 >             from, RPL_STATSDEBUG, to, dlink_list_length(&serv_list));
1353    sendto_one(source_p, ":%s %d %s ? :Sent total : %7.2f %s",
1354               from, RPL_STATSDEBUG, to,
1355 <             _GMKv((signed)sendB), _GMKs((signed)sendB));
1355 >             _GMKv(sendB), _GMKs(sendB));
1356    sendto_one(source_p, ":%s %d %s ? :Recv total : %7.2f %s",
1357               from, RPL_STATSDEBUG, to,
1358 <             _GMKv((signed)recvB), _GMKs((signed)recvB));
1358 >             _GMKv(recvB), _GMKs(recvB));
1359  
1360 <  uptime = (CurrentTime - me.since);
1360 >  uptime = (CurrentTime - me.localClient->since);
1361  
1362    sendto_one(source_p, ":%s %d %s ? :Server send: %7.2f %s (%4.1f K/s)",
1363               from, RPL_STATSDEBUG, to,
1364 <             _GMKv((signed)(me.localClient->send.bytes>>10)),
1365 <             _GMKs((signed)(me.localClient->send.bytes>>10)),
1366 <             (float)((float)(((signed)me.localClient->send.bytes) >> 10) /
1367 <             (float)uptime));
1364 >             _GMKv((me.localClient->send.bytes>>10)),
1365 >             _GMKs((me.localClient->send.bytes>>10)),
1366 >             (float)((float)((me.localClient->send.bytes) >> 10) /
1367 >             (float)uptime));
1368    sendto_one(source_p, ":%s %d %s ? :Server recv: %7.2f %s (%4.1f K/s)",
1369               from, RPL_STATSDEBUG, to,
1370 <             _GMKv((signed)(me.localClient->recv.bytes>>10)),
1371 <             _GMKs((signed)(me.localClient->recv.bytes>>10)),
1372 <             (float)((float)(((signed)me.localClient->recv.bytes) >> 10) /
1373 <             (float)uptime));
1370 >             _GMKv((me.localClient->recv.bytes>>10)),
1371 >             _GMKs((me.localClient->recv.bytes>>10)),
1372 >             (float)((float)((me.localClient->recv.bytes) >> 10) /
1373 >             (float)uptime));
1374   }
1375  
1376 < static void
1377 < stats_ltrace(struct Client *source_p, int parc, char *parv[])
1376 > /* parse_stats_args()
1377 > *
1378 > * inputs       - arg count
1379 > *              - args
1380 > *              - doall flag
1381 > *              - wild card or not
1382 > * output       - pointer to name to use
1383 > * side effects -
1384 > * common parse routine for m_stats args
1385 > *
1386 > */
1387 > static char *
1388 > parse_stats_args(int parc, char *parv[], int *doall, int *wilds)
1389   {
1390 <  int doall = 0;
1286 <  int wilds = 0;
1287 <  char *name = NULL;
1288 <  char statchar;
1390 >  char *name;
1391  
1392 <  if ((name = parse_stats_args(parc, parv, &doall, &wilds)) != NULL)
1392 >  if (parc > 2)
1393    {
1394 <    statchar = parv[1][0];
1394 >    name = parv[2];
1395  
1396 <    stats_L(source_p, name, doall, wilds, statchar);
1397 <  }
1398 <  else
1399 <    sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
1298 <               from, to, "STATS");
1299 < }
1396 >    if (!irccmp(name, from))
1397 >      *doall = 2;
1398 >    else if (!match(name, from))
1399 >      *doall = 1;
1400  
1401 < /*
1302 < * ms_stats - STATS message handler
1303 < *      parv[0] = sender prefix
1304 < *      parv[1] = statistics selector (defaults to Message frequency)
1305 < *      parv[2] = server name (current server defaulted, if omitted)
1306 < */
1307 < static void
1308 < ms_stats(struct Client *client_p, struct Client *source_p,
1309 <         int parc, char *parv[])
1310 < {
1311 <  if (hunt_server(client_p,source_p,":%s STATS %s :%s",2,parc,parv)!=HUNTED_ISME)
1312 <    return;
1401 >    *wilds = has_wildcards(name);
1402  
1403 <  if (IsClient(source_p))
1404 <    mo_stats(client_p, source_p, parc, parv);
1316 < }
1403 >    return name;
1404 >  }
1405  
1406 < /*
1319 < * stats_L
1320 < *
1321 < * inputs       - pointer to client to report to
1322 < *              - doall flag
1323 < *              - wild card or not
1324 < * output       - NONE
1325 < * side effects -
1326 < */
1327 < static void
1328 < stats_L(struct Client *source_p,char *name,int doall,
1329 <        int wilds,char statchar)
1330 < {
1331 <  stats_L_list(source_p, name, doall, wilds, &unknown_list, statchar);
1332 <  stats_L_list(source_p, name, doall, wilds, &local_client_list, statchar);
1333 <  stats_L_list(source_p, name, doall, wilds, &serv_list, statchar);
1406 >  return NULL;
1407   }
1408  
1409   static void
# Line 1350 | Line 1423 | stats_L_list(struct Client *source_p,cha
1423    {
1424      target_p = ptr->data;
1425  
1426 <    if (IsInvisible(target_p) && (doall || wilds) &&
1427 <        !(MyConnect(source_p) && IsOper(source_p)) &&
1428 <        !IsOper(target_p) && (target_p != source_p))
1426 >    if (HasUMode(target_p, UMODE_INVISIBLE) && (doall || wilds) &&
1427 >        !(MyConnect(source_p) && HasUMode(source_p, UMODE_OPER)) &&
1428 >        !HasUMode(target_p, UMODE_OPER) && (target_p != source_p))
1429        continue;
1430 <    if (!doall && wilds && !match(name, target_p->name))
1430 >    if (!doall && wilds && match(name, target_p->name))
1431        continue;
1432      if (!(doall || wilds) && irccmp(name, target_p->name))
1433        continue;
1434  
1435      /* This basically shows ips for our opers if its not a server/admin, or
1436       * its one of our admins.  */
1437 <    if(MyClient(source_p) && IsOper(source_p) &&
1438 <       (IsAdmin(source_p) ||
1439 <       (!IsServer(target_p) && !IsAdmin(target_p) &&
1437 >    if(MyClient(source_p) && HasUMode(source_p, UMODE_OPER) &&
1438 >       (HasUMode(source_p, UMODE_ADMIN) ||
1439 >       (!IsServer(target_p) && !HasUMode(target_p, UMODE_ADMIN) &&
1440         !IsHandshake(target_p) && !IsConnecting(target_p))))
1441      {
1442        sendto_one(source_p, form_str(RPL_STATSLINKINFO),
1443 <                 from, to,
1443 >                 from, to,
1444                   (IsUpper(statchar)) ?
1445                   get_client_name(target_p, SHOW_IP) :
1446                   get_client_name(target_p, HIDE_IP),
# Line 1376 | Line 1449 | stats_L_list(struct Client *source_p,cha
1449                   target_p->localClient->send.bytes>>10,
1450                   target_p->localClient->recv.messages,
1451                   target_p->localClient->recv.bytes>>10,
1452 <                 (unsigned)(CurrentTime - target_p->firsttime),
1453 <                 (CurrentTime > target_p->since) ? (unsigned)(CurrentTime - target_p->since):0,
1452 >                 (unsigned)(CurrentTime - target_p->localClient->firsttime),
1453 >                 (CurrentTime > target_p->localClient->since) ? (unsigned)(CurrentTime - target_p->localClient->since):0,
1454                   IsServer(target_p) ? show_capabilities(target_p) : "-");
1455      }
1456      else
1457      {
1458        /* If its a hidden ip, an admin, or a server, mask the real IP */
1459 <      if(IsIPSpoof(target_p) || IsServer(target_p) || IsAdmin(target_p)
1459 >      if(IsIPSpoof(target_p) || IsServer(target_p) || HasUMode(target_p, UMODE_ADMIN)
1460           || IsHandshake(target_p) || IsConnecting(target_p))
1461          sendto_one(source_p, form_str(RPL_STATSLINKINFO),
1462                     from, to,
1463 <                   get_client_name(target_p, MASK_IP),
1464 <                   dbuf_length(&target_p->localClient->buf_sendq),
1465 <                   target_p->localClient->send.messages,
1466 <                   target_p->localClient->send.bytes>>10,
1467 <                   target_p->localClient->recv.messages,
1468 <                   target_p->localClient->recv.bytes>>10,
1469 <                   (unsigned)(CurrentTime - target_p->firsttime),
1470 <                   (CurrentTime > target_p->since) ? (unsigned)(CurrentTime - target_p->since):0,
1471 <                   IsServer(target_p) ? show_capabilities(target_p) : "-");
1463 >                   get_client_name(target_p, MASK_IP),
1464 >                   dbuf_length(&target_p->localClient->buf_sendq),
1465 >                   target_p->localClient->send.messages,
1466 >                   target_p->localClient->send.bytes>>10,
1467 >                   target_p->localClient->recv.messages,
1468 >                   target_p->localClient->recv.bytes>>10,
1469 >                   (unsigned)(CurrentTime - target_p->localClient->firsttime),
1470 >                   (CurrentTime > target_p->localClient->since) ? (unsigned)(CurrentTime - target_p->localClient->since):0,
1471 >                   IsServer(target_p) ? show_capabilities(target_p) : "-");
1472        else /* show the real IP */
1473          sendto_one(source_p, form_str(RPL_STATSLINKINFO),
1474                     from, to,
1475 <                   (IsUpper(statchar)) ?
1476 <                   get_client_name(target_p, SHOW_IP) :
1477 <                   get_client_name(target_p, HIDE_IP),
1478 <                   dbuf_length(&target_p->localClient->buf_sendq),
1479 <                   target_p->localClient->send.messages,
1480 <                   target_p->localClient->send.bytes>>10,
1481 <                   target_p->localClient->recv.messages,
1482 <                   target_p->localClient->recv.bytes>>10,
1483 <                   (unsigned)(CurrentTime - target_p->firsttime),
1484 <                   (CurrentTime > target_p->since) ? (unsigned)(CurrentTime - target_p->since):0,
1485 <                   IsServer(target_p) ? show_capabilities(target_p) : "-");
1475 >                   (IsUpper(statchar)) ?
1476 >                   get_client_name(target_p, SHOW_IP) :
1477 >                   get_client_name(target_p, HIDE_IP),
1478 >                   dbuf_length(&target_p->localClient->buf_sendq),
1479 >                   target_p->localClient->send.messages,
1480 >                   target_p->localClient->send.bytes>>10,
1481 >                   target_p->localClient->recv.messages,
1482 >                   target_p->localClient->recv.bytes>>10,
1483 >                   (unsigned)(CurrentTime - target_p->localClient->firsttime),
1484 >                   (CurrentTime > target_p->localClient->since) ? (unsigned)(CurrentTime - target_p->localClient->since):0,
1485 >                   IsServer(target_p) ? show_capabilities(target_p) : "-");
1486      }
1487    }
1488   }
1489  
1490 < /* parse_stats_args()
1490 > /*
1491 > * stats_L
1492   *
1493 < * inputs       - arg count
1494 < *              - args
1495 < *              - doall flag
1496 < *              - wild card or not
1497 < * output       - pointer to name to use
1498 < * side effects -
1499 < * common parse routine for m_stats args
1493 > * inputs       - pointer to client to report to
1494 > *              - doall flag
1495 > *              - wild card or not
1496 > * output       - NONE
1497 > * side effects -
1498 > */
1499 > static void
1500 > stats_L(struct Client *source_p,char *name,int doall,
1501 >        int wilds,char statchar)
1502 > {
1503 >  stats_L_list(source_p, name, doall, wilds, &unknown_list, statchar);
1504 >  stats_L_list(source_p, name, doall, wilds, &local_client_list, statchar);
1505 >  stats_L_list(source_p, name, doall, wilds, &serv_list, statchar);
1506 > }
1507 >
1508 > static void
1509 > stats_ltrace(struct Client *source_p, int parc, char *parv[])
1510 > {
1511 >  int doall = 0;
1512 >  int wilds = 0;
1513 >  char *name = NULL;
1514 >  char statchar;
1515 >
1516 >  if ((name = parse_stats_args(parc, parv, &doall, &wilds)) != NULL)
1517 >  {
1518 >    statchar = parv[1][0];
1519 >
1520 >    stats_L(source_p, name, doall, wilds, statchar);
1521 >  }
1522 >  else
1523 >    sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
1524 >               from, to, "STATS");
1525 > }
1526 >
1527 > static const struct StatsStruct
1528 > {
1529 >  const unsigned char letter;
1530 >  void (*handler)();
1531 >  const unsigned int need_oper;
1532 >  const unsigned int need_admin;
1533 > } stats_cmd_table[] = {
1534 >  /* letter     function            need_oper need_admin */
1535 >  { 'a',        stats_dns_servers,      1,      1       },
1536 >  { 'A',        stats_dns_servers,      1,      1       },
1537 >  { 'c',        stats_connect,          1,      0       },
1538 >  { 'C',        stats_connect,          1,      0       },
1539 >  { 'd',        stats_tdeny,            1,      0       },
1540 >  { 'D',        stats_deny,             1,      0       },
1541 >  { 'e',        stats_exempt,           1,      0       },
1542 >  { 'E',        stats_events,           1,      1       },
1543 >  { 'f',        fd_dump,                1,      1       },
1544 >  { 'F',        fd_dump,                1,      1       },
1545 >  { 'g',        stats_pending_glines,   1,      0       },
1546 >  { 'G',        stats_glines,           1,      0       },
1547 >  { 'h',        stats_hooks,            1,      1       },
1548 >  { 'H',        stats_hubleaf,          1,      0       },
1549 >  { 'i',        stats_auth,             0,      0       },
1550 >  { 'I',        stats_auth,             0,      0       },
1551 >  { 'k',        stats_tklines,          0,      0       },
1552 >  { 'K',        stats_klines,           0,      0       },
1553 >  { 'l',        stats_ltrace,           1,      0       },
1554 >  { 'L',        stats_ltrace,           1,      0       },
1555 >  { 'm',        stats_messages,         0,      0       },
1556 >  { 'M',        stats_messages,         0,      0       },
1557 >  { 'o',        stats_oper,             0,      0       },
1558 >  { 'O',        stats_oper,             0,      0       },
1559 >  { 'p',        stats_operedup,         0,      0       },
1560 >  { 'P',        stats_ports,            0,      0       },
1561 >  { 'q',        stats_resv,             1,      0       },
1562 >  { 'Q',        stats_resv,             1,      0       },
1563 >  { 'r',        stats_usage,            1,      0       },
1564 >  { 'R',        stats_usage,            1,      0       },
1565 >  { 's',        stats_service,          1,      0       },
1566 >  { 'S',        stats_service,          1,      0       },
1567 >  { 't',        stats_tstats,           1,      0       },
1568 >  { 'T',        stats_tstats,           1,      0       },
1569 >  { 'u',        stats_uptime,           0,      0       },
1570 >  { 'U',        stats_shared,           1,      0       },
1571 >  { 'v',        stats_servers,          1,      0       },
1572 >  { 'x',        stats_gecos,            1,      0       },
1573 >  { 'X',        stats_gecos,            1,      0       },
1574 >  { 'y',        stats_class,            1,      0       },
1575 >  { 'Y',        stats_class,            1,      0       },
1576 >  { 'z',        stats_memory,           1,      0       },
1577 >  { '?',        stats_servlinks,        0,      0       },
1578 >  { '\0',       NULL,                   0,      0       }
1579 > };
1580 >
1581 > static void
1582 > do_stats(struct Client *source_p, int parc, char *parv[])
1583 > {
1584 >  const struct StatsStruct *tab = stats_cmd_table;
1585 >  const char statchar = *parv[1];
1586 >
1587 >  if (statchar == '\0')
1588 >  {
1589 >    sendto_one(source_p, form_str(RPL_ENDOFSTATS),
1590 >               from, to, '*');
1591 >    return;
1592 >  }
1593 >
1594 >  for (; tab->handler; ++tab)
1595 >  {
1596 >    if (tab->letter == statchar)
1597 >    {
1598 >      /* The stats table says what privs are needed, so check --fl_ */
1599 >      if ((tab->need_admin && !HasUMode(source_p, UMODE_ADMIN)) ||
1600 >          (tab->need_oper && !HasUMode(source_p, UMODE_OPER)))
1601 >      {
1602 >        sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
1603 >                   from, to);
1604 >        break;
1605 >      }
1606 >
1607 >      sendto_realops_flags(UMODE_SPY, L_ALL, SEND_NOTICE,
1608 >                           "STATS %c requested by %s (%s@%s) [%s]",
1609 >                           statchar, source_p->name, source_p->username,
1610 >                           source_p->host, source_p->servptr->name);
1611 >      tab->handler(source_p, parc, parv);
1612 >      break;
1613 >    }
1614 >  }
1615 >
1616 >  sendto_one(source_p, form_str(RPL_ENDOFSTATS),
1617 >             from, to, statchar);
1618 > }
1619 >
1620 > /*
1621 > * m_stats()
1622 > *      parv[0] = sender prefix
1623 > *      parv[1] = stat letter/command
1624 > *      parv[2] = (if present) server/mask in stats L
1625   *
1626 + * This will search the tables for the appropriate stats letter/command,
1627 + * if found execute it.  
1628   */
1629 < static char *
1630 < parse_stats_args(int parc, char *parv[], int *doall, int *wilds)
1629 > static void
1630 > m_stats(struct Client *client_p, struct Client *source_p,
1631 >        int parc, char *parv[])
1632   {
1633 <  char *name;
1633 >  static time_t last_used = 0;
1634  
1635 <  if (parc > 2)
1635 >  /* Is the stats meant for us? */
1636 >  if (!ConfigFileEntry.disable_remote)
1637 >    if (hunt_server(client_p, source_p, ":%s STATS %s :%s", 2,
1638 >                    parc, parv) != HUNTED_ISME)
1639 >      return;
1640 >
1641 >  if (!MyClient(source_p) && IsCapable(source_p->from, CAP_TS6) && HasID(source_p))
1642    {
1643 <    name = parv[2];
1643 >    from = me.id;
1644 >    to = source_p->id;
1645 >  }
1646 >  else
1647 >  {
1648 >    from = me.name;
1649 >    to = source_p->name;
1650 >  }
1651  
1652 <    if (!irccmp(name, from))
1653 <      *doall = 2;
1654 <    else if (match(name, from))
1655 <      *doall = 1;
1652 >  /* Check the user is actually allowed to do /stats, and isnt flooding */
1653 >  if ((last_used + ConfigFileEntry.pace_wait) > CurrentTime)
1654 >  {
1655 >    sendto_one(source_p,form_str(RPL_LOAD2HI),
1656 >               from, to);
1657 >    return;
1658 >  }
1659 >
1660 >  last_used = CurrentTime;
1661  
1662 <    if (strchr(name, '*') ||
1663 <        strchr(name, '?'))
1444 <      *wilds = 1;
1662 >  do_stats(source_p, parc, parv);
1663 > }
1664  
1665 <    return(name);
1665 > /*
1666 > * mo_stats()
1667 > *      parv[0] = sender prefix
1668 > *      parv[1] = stat letter/command
1669 > *      parv[2] = (if present) server/mask in stats L, or target
1670 > *
1671 > * This will search the tables for the appropriate stats letter,
1672 > * if found execute it.  
1673 > */
1674 > static void
1675 > mo_stats(struct Client *client_p, struct Client *source_p,
1676 >         int parc, char *parv[])
1677 > {
1678 >  if (hunt_server(client_p, source_p, ":%s STATS %s :%s", 2,
1679 >                  parc, parv) != HUNTED_ISME)
1680 >     return;
1681 >
1682 >  if (!MyClient(source_p) && IsCapable(source_p->from, CAP_TS6) && HasID(source_p))
1683 >  {
1684 >    from = me.id;
1685 >    to = source_p->id;
1686    }
1687    else
1688 <    return(NULL);
1688 >  {
1689 >    from = me.name;
1690 >    to = source_p->name;
1691 >  }
1692 >
1693 >  do_stats(source_p, parc, parv);
1694   }
1695 +
1696 + /*
1697 + * ms_stats - STATS message handler
1698 + *      parv[0] = sender prefix
1699 + *      parv[1] = statistics selector (defaults to Message frequency)
1700 + *      parv[2] = server name (current server defaulted, if omitted)
1701 + */
1702 + static void
1703 + ms_stats(struct Client *client_p, struct Client *source_p,
1704 +         int parc, char *parv[])
1705 + {
1706 +  if (hunt_server(client_p, source_p, ":%s STATS %s :%s", 2,
1707 +                  parc, parv) != HUNTED_ISME)
1708 +    return;
1709 +
1710 +  if (IsClient(source_p))
1711 +    mo_stats(client_p, source_p, parc, parv);
1712 + }
1713 +
1714 + static struct Message stats_msgtab = {
1715 +  "STATS", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
1716 +  { m_unregistered, m_stats, ms_stats, m_ignore, mo_stats, m_ignore }
1717 + };
1718 +
1719 + static void
1720 + module_init(void)
1721 + {
1722 +  mod_add_cmd(&stats_msgtab);
1723 + }
1724 +
1725 + static void
1726 + module_exit(void)
1727 + {
1728 +  mod_del_cmd(&stats_msgtab);
1729 + }
1730 +
1731 + struct module module_entry = {
1732 +  .node    = { NULL, NULL, NULL },
1733 +  .name    = NULL,
1734 +  .version = "$Revision$",
1735 +  .handle  = NULL,
1736 +  .modinit = module_init,
1737 +  .modexit = module_exit,
1738 +  .flags   = 0
1739 + };

Comparing:
ircd-hybrid/modules/m_stats.c (property svn:keywords), Revision 30 by adx, Sun Oct 2 20:03:27 2005 UTC vs.
ircd-hybrid/trunk/modules/m_stats.c (property svn:keywords), Revision 2116 by michael, Sun May 26 11:44:01 2013 UTC

# Line 1 | Line 1
1 < "Id Revision"
1 > Id Revision

Diff Legend

– Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)