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-7.2/modules/m_stats.c (file contents), Revision 884 by michael, Sun Oct 28 18:22:55 2007 UTC vs.
ircd-hybrid-8/modules/m_stats.c (file contents), Revision 1483 by michael, Wed Jul 25 19:15:48 2012 UTC

# Line 23 | Line 23
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 "balloc.h"
28   #include "client.h"      /* Client */
29 #include "common.h"      /* TRUE/FALSE */
29   #include "irc_string.h"  
30   #include "ircd.h"        /* me */
31   #include "listener.h"    /* show_ports */
32   #include "s_gline.h"
34 #include "ircd_handler.h"
35 #include "msg.h"         /* Message */
33   #include "hostmask.h"
34   #include "numeric.h"     /* ERR_xxx */
35   #include "send.h"        /* sendto_one */
36   #include "fdlist.h"      /* PF and friends */
37   #include "s_bsd.h"       /* highest_fd */
38 < #include "s_conf.h"      /* AccessItem, report_configured_links */
38 > #include "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"
53 #include "list.h"
49   #include "watch.h"
50 + #include "irc_res.h"
51  
56 static void do_stats(struct Client *, int, char **);
57 static void m_stats(struct Client *, struct Client *, int, char *[]);
58 static void mo_stats(struct Client *, struct Client *, int, char *[]);
59 static void ms_stats(struct Client *, struct Client *, int, char *[]);
60
61 struct Message stats_msgtab = {
62  "STATS", 0, 0, 2, 0, MFLG_SLOW, 0,
63  { m_unregistered, m_stats, ms_stats, m_ignore, mo_stats, m_ignore }
64 };
65
66 #ifndef STATIC_MODULES
67 const char *_version = "$Revision$";
68 static struct Callback *stats_cb;
69
70 static void *
71 va_stats(va_list args)
72 {
73  struct Client *source_p = va_arg(args, struct Client *);
74  int parc = va_arg(args, int);
75  char **parv = va_arg(args, char **);
76
77  do_stats(source_p, parc, parv);
78  return NULL;
79 }
80
81 void
82 _modinit(void)
83 {
84  stats_cb = register_callback("doing_stats", va_stats);
85  mod_add_cmd(&stats_msgtab);
86 }
87
88 void
89 _moddeinit(void)
90 {
91  mod_del_cmd(&stats_msgtab);
92  uninstall_hook(stats_cb, va_stats);
93 }
94 #endif
95
96 static char *parse_stats_args(int, char **, int *, int *);
97 static void stats_L(struct Client *, char *, int, int, char);
98 static void stats_L_list(struct Client *s, char *, int, int, dlink_list *, char);
99
100 static void stats_dns_servers(struct Client *);
101 static void stats_connect(struct Client *);
102 static void stats_deny(struct Client *);
103 static void stats_tdeny(struct Client *);
104 static void stats_exempt(struct Client *);
105 static void stats_events(struct Client *);
106 static void stats_pending_glines(struct Client *);
107 static void stats_glines(struct Client *);
108 static void stats_gdeny(struct Client *);
109 static void stats_hubleaf(struct Client *);
110 static void stats_auth(struct Client *);
111 static void stats_tklines(struct Client *);
112 static void stats_klines(struct Client *);
113 static void stats_messages(struct Client *);
114 static void stats_oper(struct Client *);
115 static void stats_operedup(struct Client *);
116 static void stats_ports(struct Client *);
117 static void stats_resv(struct Client *);
118 static void stats_usage(struct Client *);
119 static void stats_tstats(struct Client *);
120 static void stats_uptime(struct Client *);
121 static void stats_shared(struct Client *);
122 static void stats_servers(struct Client *);
123 static void stats_gecos(struct Client *);
124 static void stats_class(struct Client *);
125 static void stats_memory(struct Client *);
126 static void stats_servlinks(struct Client *);
127 static void stats_ltrace(struct Client *, int, char **);
128 static void stats_ziplinks(struct Client *);
129
130 /* This table contains the possible stats items, in order:
131 * /stats name,  function to call, operonly? adminonly? /stats letter
132 * case only matters in the stats letter column.. -- fl_ */
133 static const struct StatsStruct
134 {
135  const unsigned char letter;
136  void (*handler)();
137  const unsigned int need_oper;
138  const unsigned int need_admin;
139 } stats_cmd_table[] = {
140  /* letter     function            need_oper need_admin */
141  { 'a',        stats_dns_servers,      1,      1,      },
142  { 'A',        stats_dns_servers,      1,      1,      },
143  { 'c',        stats_connect,          1,      0,      },
144  { 'C',        stats_connect,          1,      0,      },
145  { 'd',        stats_tdeny,            1,      0,      },
146  { 'D',        stats_deny,             1,      0,      },
147  { 'e',        stats_exempt,           1,      0,      },
148  { 'E',        stats_events,           1,      1,      },
149  { 'f',        fd_dump,                1,      1,      },
150  { 'F',        fd_dump,                1,      1,      },
151  { 'g',        stats_pending_glines,   1,      0,      },
152  { 'G',        stats_glines,           1,      0,      },
153  { 'h',        stats_hooks,            1,      1,      },
154  { 'H',        stats_hubleaf,          1,      0,      },
155  { 'i',        stats_auth,             0,      0,      },
156  { 'I',        stats_auth,             0,      0,      },
157  { 'k',        stats_tklines,          0,      0,      },
158  { 'K',        stats_klines,           0,      0,      },
159  { 'l',        stats_ltrace,           1,      0,      },
160  { 'L',        stats_ltrace,           1,      0,      },
161  { 'm',        stats_messages,         0,      0,      },
162  { 'M',        stats_messages,         0,      0,      },
163  { 'o',        stats_oper,             0,      0,      },
164  { 'O',        stats_oper,             0,      0,      },
165  { 'p',        stats_operedup,         0,      0,      },
166  { 'P',        stats_ports,            0,      0,      },
167  { 'q',        stats_resv,             1,      0,      },
168  { 'Q',        stats_resv,             1,      0,      },
169  { 'r',        stats_usage,            1,      0,      },
170  { 'R',        stats_usage,            1,      0,      },
171  { 't',        stats_tstats,           1,      0,      },
172  { 'T',        stats_tstats,           1,      0,      },
173  { 'u',        stats_uptime,           0,      0,      },
174  { 'U',        stats_shared,           1,      0,      },
175  { 'v',        stats_servers,          1,      0,      },
176  { 'V',        stats_gdeny,            1,      0,      },
177  { 'x',        stats_gecos,            1,      0,      },
178  { 'X',        stats_gecos,            1,      0,      },
179  { 'y',        stats_class,            1,      0,      },
180  { 'Y',        stats_class,            1,      0,      },
181  { 'z',        stats_memory,           1,      0,      },
182  { 'Z',        stats_ziplinks,         1,      0,      },
183  { '?',        stats_servlinks,        0,      0,      },
184  { '\0',       (void(*)())0,           0,      0,      }
185 };
52  
53   const char *from, *to;
54  
189 static void
190 do_stats(struct Client *source_p, int parc, char **parv)
191 {
192  char statchar = *parv[1];
193  int i;
194
195  if (statchar == '\0')
196  {
197    sendto_one(source_p, form_str(RPL_ENDOFSTATS),
198               from, to, '*');
199    return;
200  }
201
202  for (i = 0; stats_cmd_table[i].handler; i++)
203  {
204    if (stats_cmd_table[i].letter == statchar)
205    {
206      /* The stats table says what privs are needed, so check --fl_ */
207      if ((stats_cmd_table[i].need_admin && !IsAdmin(source_p)) ||
208          (stats_cmd_table[i].need_oper && !IsOper(source_p)))
209      {
210        sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
211                   from, to);
212        break;
213      }
214
215      /* Blah, stats L needs the parameters, none of the others do.. */
216      if (statchar == 'L' || statchar == 'l')
217        stats_cmd_table[i].handler(source_p, parc, parv);
218      else
219        stats_cmd_table[i].handler(source_p);
220
221      break;
222    }
223  }
224
225  sendto_one(source_p, form_str(RPL_ENDOFSTATS),
226             from, to, statchar);
227 }
228
229 /*
230 * m_stats()
231 *      parv[0] = sender prefix
232 *      parv[1] = stat letter/command
233 *      parv[2] = (if present) server/mask in stats L
234 *
235 * This will search the tables for the appropriate stats letter/command,
236 * if found execute it.  
237 */
238 static void
239 m_stats(struct Client *client_p, struct Client *source_p,
240        int parc, char *parv[])
241 {
242  static time_t last_used = 0;
243
244  /* Is the stats meant for us? */
245  if (!ConfigFileEntry.disable_remote)
246    if (hunt_server(client_p,source_p,":%s STATS %s :%s",2,parc,parv) != HUNTED_ISME)
247      return;
248
249  if (!MyClient(source_p) && IsCapable(source_p->from, CAP_TS6) && HasID(source_p))
250  {
251    from = me.id;
252    to = source_p->id;
253  }
254  else
255  {
256    from = me.name;
257    to = source_p->name;
258  }
259
260  /* Check the user is actually allowed to do /stats, and isnt flooding */
261  if ((last_used + ConfigFileEntry.pace_wait) > CurrentTime)
262  {
263    sendto_one(source_p,form_str(RPL_LOAD2HI),
264               from, to);
265    return;
266  }
267  else
268    last_used = CurrentTime;
269
270 #ifdef STATIC_MODULES
271  do_stats(source_p, parc, parv);
272 #else
273  execute_callback(stats_cb, source_p, parc, parv);
274 #endif
275 }
276
277 /*
278 * mo_stats()
279 *      parv[0] = sender prefix
280 *      parv[1] = stat letter/command
281 *      parv[2] = (if present) server/mask in stats L, or target
282 *
283 * This will search the tables for the appropriate stats letter,
284 * if found execute it.  
285 */
286 static void
287 mo_stats(struct Client *client_p, struct Client *source_p,
288         int parc, char *parv[])
289 {
290  if (hunt_server(client_p, source_p, ":%s STATS %s :%s", 2,
291                  parc, parv) != HUNTED_ISME)
292     return;
293
294  if (!MyClient(source_p) && IsCapable(source_p->from, CAP_TS6) && HasID(source_p))
295  {
296    from = me.id;
297    to = source_p->id;
298  }
299  else
300  {
301    from = me.name;
302    to = source_p->name;
303  }
304
305 #ifdef STATIC_MODULES
306  do_stats(source_p, parc, parv);
307 #else
308  execute_callback(stats_cb, source_p, parc, parv);
309 #endif
310 }
311
55   /*
56   * This is part of the STATS replies. There is no offical numeric for this
57   * since this isnt an official command, in much the same way as HASH isnt.
# Line 317 | Line 60 | mo_stats(struct Client *client_p, struct
60   * -avalon
61   */
62   static void
63 < send_usage(struct Client *source_p)
63 > stats_usage(struct Client *source_p, int parc, char *parv[])
64   {
322 #ifndef _WIN32
65    struct rusage rus;
66    time_t secs;
67    time_t rup;
# Line 345 | Line 87 | send_usage(struct Client *source_p)
87    if (secs == 0)
88      secs = 1;
89  
90 <  rup = (CurrentTime - me.since) * hzz;
90 >  rup = (CurrentTime - me.localClient->since) * hzz;
91  
92    if (rup == 0)
93      rup = 1;
# Line 371 | Line 113 | send_usage(struct Client *source_p)
113    sendto_one(source_p, ":%s %d %s R :Signals %d Context Vol. %d Invol %d",
114               me.name, RPL_STATSDEBUG, source_p->name, (int)rus.ru_nsignals,
115               (int)rus.ru_nvcsw, (int)rus.ru_nivcsw);
374 #endif
116   }
117  
118   static void
119 < count_memory(struct Client *source_p)
119 > stats_memory(struct Client *source_p, int parc, char *parv[])
120   {
121    const dlink_node *gptr = NULL;
122    const dlink_node *dlink = NULL;
123  
124 <  int local_client_conf_count = 0;      /* local client conf links */
125 <  int users_counted = 0;                /* user structs */
124 >  unsigned int local_client_conf_count = 0;      /* local client conf links */
125 >  unsigned int users_counted = 0;                /* user structs */
126  
127 <  int channel_users = 0; /* XXX */
128 <  int channel_invites = 0;
129 <  int channel_bans = 0;
130 <  int channel_except = 0;
131 <  int channel_invex = 0;
132 <
133 <  int wwu = 0;                  /* whowas users */
134 <  int class_count = 0;          /* classes */
135 <  int aways_counted = 0;
136 <  int number_ips_stored;        /* number of ip addresses hashed */
137 <
138 <  unsigned long channel_memory = 0;
139 <  size_t channel_ban_memory = 0;
140 <  size_t channel_except_memory = 0;
141 <  size_t channel_invex_memory = 0;
127 >  unsigned int channel_members = 0;
128 >  unsigned int channel_invites = 0;
129 >  unsigned int channel_bans = 0;
130 >  unsigned int channel_except = 0;
131 >  unsigned int channel_invex = 0;
132 >
133 >  unsigned int wwu = 0;                  /* whowas users */
134 >  unsigned int class_count = 0;          /* classes */
135 >  unsigned int aways_counted = 0;
136 >  unsigned int number_ips_stored;        /* number of ip addresses hashed */
137 >
138 >  uint64_t channel_memory = 0;
139 >  uint64_t channel_ban_memory = 0;
140 >  uint64_t channel_except_memory = 0;
141 >  uint64_t channel_invex_memory = 0;
142  
143    unsigned int safelist_count = 0;
144 <  size_t safelist_memory = 0;
144 >  uint64_t safelist_memory = 0;
145 >
146 >  uint64_t wwm = 0;               /* whowas array memory used       */
147 >  uint64_t conf_memory = 0;       /* memory used by conf lines      */
148 >  uint64_t mem_ips_stored;        /* memory used by ip address hash */
149  
150 <  unsigned long away_memory = 0;       /* memory used by aways           */
151 <  unsigned long wwm = 0;               /* whowas array memory used       */
407 <  unsigned long conf_memory = 0;       /* memory used by conf lines      */
408 <  unsigned long mem_ips_stored;        /* memory used by ip address hash */
409 <
410 <  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;
150 >  uint64_t total_channel_memory = 0;
151 >  uint64_t totww = 0;
152  
153    unsigned int local_client_count  = 0;
154    unsigned int remote_client_count = 0;
155  
156 <  unsigned int local_client_memory_used  = 0;
157 <  unsigned int remote_client_memory_used = 0;
156 >  uint64_t local_client_memory_used  = 0;
157 >  uint64_t remote_client_memory_used = 0;
158  
159 <  unsigned long total_memory = 0;
159 >  uint64_t total_memory = 0;
160    unsigned int topic_count = 0;
161  
162 <  unsigned int wlh = 0;   /* watchlist headers     */
163 <  unsigned int wle = 0;   /* watchlist entries     */
164 <  size_t wlhm = 0; /* watchlist memory used */
162 >  unsigned int watch_list_headers = 0;   /* watchlist headers     */
163 >  unsigned int watch_list_entries = 0;   /* watchlist entries     */
164 >  uint64_t watch_list_memory = 0; /* watchlist memory used */
165  
430  count_whowas_memory(&wwu, &wwm);
166  
167    DLINK_FOREACH(gptr, global_client_list.head)
168    {
# Line 437 | Line 172 | count_memory(struct Client *source_p)
172      {
173        ++local_client_count;
174        local_client_conf_count += dlink_list_length(&target_p->localClient->confs);
175 <      wle += dlink_list_length(&target_p->localClient->watches);
175 >      watch_list_entries += dlink_list_length(&target_p->localClient->watches);
176      }
177      else
178        ++remote_client_count;
# Line 446 | Line 181 | count_memory(struct Client *source_p)
181      {
182        ++users_counted;
183  
184 <      if (target_p->away != NULL)
450 <      {
184 >      if (target_p->away[0])
185          ++aways_counted;
452        away_memory += strlen(target_p->away) + 1;
453      }
186      }
187    }
188  
# Line 459 | Line 191 | count_memory(struct Client *source_p)
191                     sizeof(struct Channel);
192    DLINK_FOREACH(gptr, global_channel_list.head)
193    {
194 <    struct Ban *actualBan;
195 <    struct Channel *chptr = gptr->data;
194 >    const struct Ban *actualBan;
195 >    const struct Channel *chptr = gptr->data;
196  
197 <    channel_users   += dlink_list_length(&chptr->members);
197 >    channel_members += dlink_list_length(&chptr->members);
198      channel_invites += dlink_list_length(&chptr->invites);
199  
200 <    if (chptr->topic != NULL)
200 >    if (chptr->topic[0])
201        ++topic_count;
202  
203 <    if ((channel_bans = dlink_list_length(&chptr->banlist)))
204 <    {
473 <      channel_ban_memory = channel_bans * sizeof(struct Ban);
203 >    channel_bans += dlink_list_length(&chptr->banlist);
204 >    channel_ban_memory += dlink_list_length(&chptr->banlist) * sizeof(struct Ban);
205  
206 <      DLINK_FOREACH(dlink, chptr->banlist.head)
207 <      {
208 <        actualBan = dlink->data;
209 <        assert(actualBan->who);
206 >    DLINK_FOREACH(dlink, chptr->banlist.head)
207 >    {
208 >      actualBan = dlink->data;
209 >      assert(actualBan->who);
210  
211 <        channel_ban_memory += actualBan->len + 3;
212 <        channel_ban_memory += strlen(actualBan->who) + 1;
482 <      }
211 >      channel_ban_memory += actualBan->len + 1;
212 >      channel_ban_memory += strlen(actualBan->who) + 1;
213      }
214  
215 <    if ((channel_except = dlink_list_length(&chptr->exceptlist)))
216 <    {
487 <      channel_except_memory = channel_except * sizeof(struct Ban);
215 >    channel_except += dlink_list_length(&chptr->exceptlist);
216 >    channel_except_memory += dlink_list_length(&chptr->exceptlist) * sizeof(struct Ban);
217  
218 <      DLINK_FOREACH(dlink, chptr->exceptlist.head)
219 <      {
220 <        actualBan = dlink->data;
221 <        assert(actualBan->who);
218 >    DLINK_FOREACH(dlink, chptr->exceptlist.head)
219 >    {
220 >      actualBan = dlink->data;
221 >      assert(actualBan->who);
222  
223 <        channel_except_memory += actualBan->len + 3;
224 <        channel_except_memory += strlen(actualBan->who) + 1;
496 <      }
223 >      channel_except_memory += actualBan->len + 1;
224 >      channel_except_memory += strlen(actualBan->who) + 1;
225      }
226  
227 <    if ((channel_invex = dlink_list_length(&chptr->invexlist)))
228 <    {
501 <      channel_invex_memory = channel_invex * sizeof(struct Ban);
227 >    channel_invex += dlink_list_length(&chptr->invexlist);
228 >    channel_invex_memory += dlink_list_length(&chptr->invexlist) * sizeof(struct Ban);
229  
230 <      DLINK_FOREACH(dlink, chptr->invexlist.head)
231 <      {
232 <        actualBan = dlink->data;
233 <        assert(actualBan->who);
230 >    DLINK_FOREACH(dlink, chptr->invexlist.head)
231 >    {
232 >      actualBan = dlink->data;
233 >      assert(actualBan->who);
234  
235 <        channel_invex_memory += actualBan->len + 3;
236 <        channel_invex_memory += strlen(actualBan->who) + 1;
510 <      }
235 >      channel_invex_memory += actualBan->len + 1;
236 >      channel_invex_memory += strlen(actualBan->who) + 1;
237      }
238    }
239  
# Line 516 | Line 242 | count_memory(struct Client *source_p)
242      safelist_memory = safelist_count * sizeof(struct ListTask);
243      DLINK_FOREACH(gptr, listing_client_list.head)
244      {
245 <      struct Client *acptr = gptr->data;
245 >      const struct Client *acptr = gptr->data;
246  
247        DLINK_FOREACH(dlink, acptr->localClient->list_task->show_mask.head)
248          safelist_memory += strlen(dlink->data);
# Line 541 | Line 267 | count_memory(struct Client *source_p)
267    /* count up all classes */
268    class_count = dlink_list_length(&class_items);
269  
270 <  watch_count_memory(&wlh, &wlhm);
270 >  count_whowas_memory(&wwu, &wwm);
271 >  watch_count_memory(&watch_list_headers, &watch_list_memory);
272  
273 <  sendto_one(source_p, ":%s %d %s z :WATCH headers %u(%u) entries %d(%d)",
274 <             me.name, RPL_STATSDEBUG, source_p->name, wlh, wlhm, wle,
275 <             wle * sizeof(dlink_node));
273 >  sendto_one(source_p, ":%s %d %s z :WATCH headers %u(%u) entries %d(%u)",
274 >             me.name, RPL_STATSDEBUG, source_p->name, watch_list_headers,
275 >             watch_list_memory, watch_list_entries,
276 >             watch_list_entries * sizeof(dlink_node) * 2);
277  
278    sendto_one(source_p, ":%s %d %s z :Clients %u(%u)",
279               me.name, RPL_STATSDEBUG, source_p->name, users_counted,
280               (users_counted * sizeof(struct Client)));
281  
282 <  sendto_one(source_p, ":%s %d %s z :User aways %u(%d)",
282 >  sendto_one(source_p, ":%s %d %s z :User aways %u",
283               me.name, RPL_STATSDEBUG, source_p->name,
284 <             aways_counted, (int)away_memory);
284 >             aways_counted);
285  
286 <  sendto_one(source_p, ":%s %d %s z :Attached confs %u(%u)",
286 >  sendto_one(source_p, ":%s %d %s z :Attached confs %u(%llu)",
287               me.name, RPL_STATSDEBUG, source_p->name,
288               local_client_conf_count,
289 <             (unsigned long)(local_client_conf_count * sizeof(dlink_node)));
289 >             (unsigned long long)(local_client_conf_count * sizeof(dlink_node)));
290  
291 <  /* XXX  ConfigItemList fix */
564 < #if 0
565 <  sendto_one(source_p, ":%s %d %s z :Conflines %lu(%d)",
566 <             me.name, RPL_STATSDEBUG, source_p->name,
567 <             dlink_list_length(&ConfigItemList), (int) conf_memory);
568 < #endif
569 <
570 <  sendto_one(source_p, ":%s %d %s z :Resv channels %lu(%lu) nicks %lu(%lu)",
291 >  sendto_one(source_p, ":%s %d %s z :Resv channels %u(%lu) nicks %u(%lu)",
292               me.name, RPL_STATSDEBUG, source_p->name,
293               dlink_list_length(&resv_channel_list),
294               dlink_list_length(&resv_channel_list) * sizeof(struct ResvChannel),
295               dlink_list_length(&nresv_items),
296               dlink_list_length(&nresv_items) * sizeof(struct MatchItem));
297  
298 <  sendto_one(source_p, ":%s %d %s z :Classes %u(%lu)",
298 >  sendto_one(source_p, ":%s %d %s z :Classes %u(%llu)",
299               me.name, RPL_STATSDEBUG, source_p->name,
300 <             class_count, (unsigned long)(class_count * sizeof(struct ClassItem)));
300 >             class_count, (unsigned long long)(class_count * sizeof(struct ClassItem)));
301  
302 <  sendto_one(source_p, ":%s %d %s z :Channels %lu(%lu) Topics %u(%d)",
302 >  sendto_one(source_p, ":%s %d %s z :Channels %uu(%llu) Topics %u(%u)",
303               me.name, RPL_STATSDEBUG, source_p->name,
304               dlink_list_length(&global_channel_list),
305               channel_memory, topic_count, topic_count *
306               (TOPICLEN + 1 + USERHOST_REPLYLEN));
307  
308 <  sendto_one(source_p, ":%s %d %s z :Bans %u(%u)",
308 >  sendto_one(source_p, ":%s %d %s z :Bans %u(%llu)",
309               me.name, RPL_STATSDEBUG, source_p->name,
310               channel_bans, channel_ban_memory);
311  
312 <  sendto_one(source_p, ":%s %d %s z :Exceptions %u(%u)",
312 >  sendto_one(source_p, ":%s %d %s z :Exceptions %u(%llu)",
313               me.name, RPL_STATSDEBUG, source_p->name,
314               channel_except, channel_except_memory);
315  
316 <  sendto_one(source_p, ":%s %d %s z :Invex %u(%u)",
316 >  sendto_one(source_p, ":%s %d %s z :Invex %u(%llu)",
317               me.name, RPL_STATSDEBUG, source_p->name,
318               channel_invex, channel_invex_memory);
319  
320 <  sendto_one(source_p, ":%s %d %s z :Channel members %u(%lu) invites %u(%lu)",
321 <             me.name, RPL_STATSDEBUG, source_p->name, channel_users,
322 <             (unsigned long)(channel_users * sizeof(struct Membership)),
323 <             channel_invites, (unsigned long)channel_invites *
320 >  sendto_one(source_p, ":%s %d %s z :Channel members %u(%llu) invites %u(%llu)",
321 >             me.name, RPL_STATSDEBUG, source_p->name, channel_members,
322 >             (unsigned long long)(channel_members * sizeof(struct Membership)),
323 >             channel_invites, (unsigned long long)channel_invites *
324               sizeof(dlink_node) * 2);
325  
326    total_channel_memory = channel_memory + channel_ban_memory +
327 <                         channel_users * sizeof(struct Membership) +
327 >                         channel_members * sizeof(struct Membership) +
328                           (channel_invites * sizeof(dlink_node)*2);
329  
330 <  sendto_one(source_p, ":%s %d %s z :Safelist %u(%u)",
330 >  sendto_one(source_p, ":%s %d %s z :Safelist %u(%llu)",
331               me.name, RPL_STATSDEBUG, source_p->name,
332               safelist_count, safelist_memory);
333  
334 <  sendto_one(source_p, ":%s %d %s z :Whowas users %u(%lu)",
334 >  sendto_one(source_p, ":%s %d %s z :Whowas users %u(%llu)",
335               me.name, RPL_STATSDEBUG, source_p->name,
336 <             wwu, (unsigned long)(wwu * sizeof(struct Client)));
336 >             wwu, (unsigned long long)(wwu * sizeof(struct Client)));
337  
338 <  sendto_one(source_p, ":%s %d %s z :Whowas array %u(%d)",
338 >  sendto_one(source_p, ":%s %d %s z :Whowas array %u(%llu)",
339               me.name, RPL_STATSDEBUG, source_p->name,
340 <             NICKNAMEHISTORYLENGTH, (int)wwm);
340 >             NICKNAMEHISTORYLENGTH, wwm);
341  
342    totww = wwu * sizeof(struct Client) + wwm;
622 /****
623  client_hash_table_size  = hash_get_client_table_size();
624  channel_hash_table_size = hash_get_channel_table_size();
625  resv_hash_table_size    = hash_get_resv_table_size();
626  id_hash_table_size      = hash_get_id_table_size();
343  
628  sendto_one(source_p, ":%s %d %s z :Hash: client %u(%lu) chan %u(%lu) resv "
629             "%u(%lu) id %u(%lu)",
630             me.name, RPL_STATSDEBUG, source_p->name,
631             U_MAX, client_hash_table_size,
632             CH_MAX, channel_hash_table_size , R_MAX,
633             resv_hash_table_size, U_MAX, id_hash_table_size);
634 ****/
344    count_ip_hash(&number_ips_stored,&mem_ips_stored);
345 <  sendto_one(source_p, ":%s %d %s z :iphash %u(%d)",
345 >  sendto_one(source_p, ":%s %d %s z :iphash %u(%llu)",
346               me.name, RPL_STATSDEBUG, source_p->name,
347 <             number_ips_stored, (int)mem_ips_stored);
347 >             number_ips_stored, mem_ips_stored);
348  
349    total_memory = totww + total_channel_memory + conf_memory + class_count *
350                   sizeof(struct ClassItem);
351 <  total_memory += client_hash_table_size;
352 <  total_memory += channel_hash_table_size;
353 <  total_memory += resv_hash_table_size;
645 <  total_memory += id_hash_table_size;
646 <
647 <  sendto_one(source_p, ":%s %d %s z :Total: whowas %d channel %d conf %d",
648 <             me.name, RPL_STATSDEBUG, source_p->name, (int)totww,
649 <            (int)total_channel_memory, (int)conf_memory);
351 >  sendto_one(source_p, ":%s %d %s z :Total: whowas %llu channel %llu conf %llu",
352 >             me.name, RPL_STATSDEBUG, source_p->name, totww,
353 >             total_channel_memory, conf_memory);
354  
355    local_client_memory_used = local_client_count*(sizeof(struct Client) + sizeof(struct LocalUser));
356    total_memory += local_client_memory_used;
357 <  sendto_one(source_p, ":%s %d %s z :Local client Memory in use: %d(%d)",
357 >  sendto_one(source_p, ":%s %d %s z :Local client Memory in use: %u(%llu)",
358               me.name, RPL_STATSDEBUG, source_p->name, local_client_count,
359               local_client_memory_used);
360  
361    remote_client_memory_used = remote_client_count * sizeof(struct Client);
362    total_memory += remote_client_memory_used;
363 <  sendto_one(source_p, ":%s %d %s z :Remote client Memory in use: %d(%d)",
363 >  sendto_one(source_p, ":%s %d %s z :Remote client Memory in use: %u(%llu)",
364               me.name, RPL_STATSDEBUG, source_p->name, remote_client_count,
365               remote_client_memory_used);
366  
367    block_heap_report_stats(source_p);
368  
369    sendto_one(source_p,
370 <             ":%s %d %s z :TOTAL: %d Available:  Current max RSS: %lu",
370 >             ":%s %d %s z :TOTAL: %llu",
371               me.name, RPL_STATSDEBUG, source_p->name,
372 <             (int)total_memory, get_maxrss());
372 >             total_memory);
373   }
374  
375   static void
# Line 675 | Line 379 | stats_dns_servers(struct Client *source_
379   }
380  
381   static void
382 < stats_connect(struct Client *source_p)
382 > stats_connect(struct Client *source_p, int parc, char *parv[])
383   {
384 <  report_confitem_types(source_p, SERVER_TYPE, 0);
384 >  report_confitem_types(source_p, SERVER_TYPE);
385   }
386  
387   /* stats_deny()
# Line 687 | Line 391 | stats_connect(struct Client *source_p)
391   * side effects - client is given dline list.
392   */
393   static void
394 < stats_deny(struct Client *source_p)
394 > stats_deny(struct Client *source_p, int parc, char *parv[])
395   {
692  struct AddressRec *arec;
396    struct ConfItem *conf;
397    struct AccessItem *aconf;
398 <  int i;
398 >  dlink_node *ptr = NULL;
399 >  unsigned int i = 0;
400  
401 <  for (i = 0; i < ATABLE_SIZE; i++)
401 >
402 >  for (i = 0; i < ATABLE_SIZE; ++i)
403    {
404 <    for (arec = atable[i]; arec; arec=arec->next)
404 >    DLINK_FOREACH(ptr, atable[i].head)
405      {
406 +      struct AddressRec *arec = ptr->data;
407 +
408        if (arec->type == CONF_DLINE)
409        {
410          aconf = arec->aconf;
# Line 723 | Line 430 | stats_deny(struct Client *source_p)
430   * side effects - client is given dline list.
431   */
432   static void
433 < stats_tdeny(struct Client *source_p)
433 > stats_tdeny(struct Client *source_p, int parc, char *parv[])
434   {
728  struct AddressRec *arec;
435    struct ConfItem *conf;
436    struct AccessItem *aconf;
437 <  int i;
437 >  dlink_node *ptr = NULL;
438 >  unsigned int i = 0;
439 >
440  
441 <  for (i = 0; i < ATABLE_SIZE; i++)
441 >  for (i = 0; i < ATABLE_SIZE; ++i)
442    {
443 <    for (arec = atable[i]; arec; arec=arec->next)
443 >    DLINK_FOREACH(ptr, atable[i].head)
444      {
445 +      struct AddressRec *arec = ptr->data;
446 +
447        if (arec->type == CONF_DLINE)
448        {
449          aconf = arec->aconf;
# Line 759 | Line 469 | stats_tdeny(struct Client *source_p)
469   * side effects - client is given list of exempt blocks
470   */
471   static void
472 < stats_exempt(struct Client *source_p)
472 > stats_exempt(struct Client *source_p, int parc, char *parv[])
473   {
764  struct AddressRec *arec;
474    struct ConfItem *conf;
475    struct AccessItem *aconf;
476 <  int i;
476 >  dlink_node *ptr = NULL;
477 >  unsigned int i = 0;
478  
479    if (ConfigFileEntry.stats_e_disabled)
480    {
# Line 773 | Line 483 | stats_exempt(struct Client *source_p)
483      return;
484    }
485  
486 <  for (i = 0; i < ATABLE_SIZE; i++)
486 >
487 >  for (i = 0; i < ATABLE_SIZE; ++i)
488    {
489 <    for (arec = atable[i]; arec; arec=arec->next)
489 >    DLINK_FOREACH(ptr, atable[i].head)
490      {
491 +      struct AddressRec *arec = ptr->data;
492 +
493        if (arec->type == CONF_EXEMPTDLINE)
494        {
495          aconf = arec->aconf;
# Line 792 | Line 505 | stats_exempt(struct Client *source_p)
505   }
506  
507   static void
508 < stats_events(struct Client *source_p)
508 > stats_events(struct Client *source_p, int parc, char *parv[])
509   {
510    show_events(source_p);
511   }
# Line 804 | Line 517 | stats_events(struct Client *source_p)
517   * side effects - client is shown list of pending glines
518   */
519   static void
520 < stats_pending_glines(struct Client *source_p)
520 > stats_pending_glines(struct Client *source_p, int parc, char *parv[])
521   {
522 < #ifdef GLINE_VOTING
523 <  dlink_node *pending_node;
524 <  struct gline_pending *glp_ptr;
525 <  char timebuffer[MAX_DATE_STRING];
813 <  struct tm *tmptr;
522 >  const dlink_node *dn_ptr = NULL;
523 >  const struct gline_pending *glp_ptr = NULL;
524 >  char timebuffer[MAX_DATE_STRING] = { '\0' };
525 >  struct tm *tmptr = NULL;
526  
527    if (!ConfigFileEntry.glines)
528    {
# Line 819 | Line 531 | stats_pending_glines(struct Client *sour
531      return;
532    }
533  
534 <  if (dlink_list_length(&pending_glines) > 0)
534 >  if (dlink_list_length(&pending_glines[GLINE_PENDING_ADD_TYPE]) > 0)
535      sendto_one(source_p, ":%s NOTICE %s :Pending G-lines",
536                 from, to);
537  
538 <  DLINK_FOREACH(pending_node, pending_glines.head)
538 >  DLINK_FOREACH(dn_ptr, pending_glines[GLINE_PENDING_ADD_TYPE].head)
539    {
540 <    glp_ptr = pending_node->data;
541 <    tmptr   = localtime(&glp_ptr->time_request1);
540 >    glp_ptr = dn_ptr->data;
541 >    tmptr   = localtime(&glp_ptr->vote_1.time_request);
542      strftime(timebuffer, MAX_DATE_STRING, "%Y/%m/%d %H:%M:%S", tmptr);
543  
544      sendto_one(source_p,
545                 ":%s NOTICE %s :1) %s!%s@%s on %s requested gline at %s for %s@%s [%s]",
546 <               from, to, glp_ptr->oper_nick1,
547 <               glp_ptr->oper_user1, glp_ptr->oper_host1,
548 <               glp_ptr->oper_server1, timebuffer,
549 <               glp_ptr->user, glp_ptr->host, glp_ptr->reason1);
546 >               from, to, glp_ptr->vote_1.oper_nick,
547 >               glp_ptr->vote_1.oper_user, glp_ptr->vote_1.oper_host,
548 >               glp_ptr->vote_1.oper_server, timebuffer,
549 >               glp_ptr->user, glp_ptr->host, glp_ptr->vote_1.reason);
550  
551 <    if (glp_ptr->oper_nick2[0] != '\0')
551 >    if (glp_ptr->vote_2.oper_nick[0] != '\0')
552      {
553 <      tmptr = localtime(&glp_ptr->time_request2);
553 >      tmptr = localtime(&glp_ptr->vote_2.time_request);
554        strftime(timebuffer, MAX_DATE_STRING, "%Y/%m/%d %H:%M:%S", tmptr);
555        sendto_one(source_p,
556        ":%s NOTICE %s :2) %s!%s@%s on %s requested gline at %s for %s@%s [%s]",
557 <                 from, to, glp_ptr->oper_nick2,
558 <                 glp_ptr->oper_user2, glp_ptr->oper_host2,
559 <                 glp_ptr->oper_server2, timebuffer,
560 <                 glp_ptr->user, glp_ptr->host, glp_ptr->reason2);
557 >               from, to, glp_ptr->vote_2.oper_nick,
558 >               glp_ptr->vote_2.oper_user, glp_ptr->vote_2.oper_host,
559 >               glp_ptr->vote_2.oper_server, timebuffer,
560 >               glp_ptr->user, glp_ptr->host, glp_ptr->vote_2.reason);
561      }
562    }
563  
564    sendto_one(source_p, ":%s NOTICE %s :End of Pending G-lines",
565               from, to);
566 < #else
567 <  sendto_one(source_p, ":%s NOTICE %s :This server does not support G-Line voting",
566 >
567 >  if (dlink_list_length(&pending_glines[GLINE_PENDING_DEL_TYPE]) > 0)
568 >    sendto_one(source_p, ":%s NOTICE %s :Pending UNG-lines",
569 >               from, to);
570 >
571 >  DLINK_FOREACH(dn_ptr, pending_glines[GLINE_PENDING_DEL_TYPE].head)
572 >  {
573 >    glp_ptr = dn_ptr->data;
574 >    tmptr   = localtime(&glp_ptr->vote_1.time_request);
575 >    strftime(timebuffer, MAX_DATE_STRING, "%Y/%m/%d %H:%M:%S", tmptr);
576 >
577 >    sendto_one(source_p,
578 >               ":%s NOTICE %s :1) %s!%s@%s on %s requested ungline at %s for %s@%s [%s]",
579 >               from, to, glp_ptr->vote_1.oper_nick,
580 >               glp_ptr->vote_1.oper_user, glp_ptr->vote_1.oper_host,
581 >               glp_ptr->vote_1.oper_server, timebuffer,
582 >               glp_ptr->user, glp_ptr->host, glp_ptr->vote_1.reason);
583 >
584 >    if (glp_ptr->vote_2.oper_nick[0] != '\0')
585 >    {
586 >      tmptr = localtime(&glp_ptr->vote_2.time_request);
587 >      strftime(timebuffer, MAX_DATE_STRING, "%Y/%m/%d %H:%M:%S", tmptr);
588 >      sendto_one(source_p,
589 >      ":%s NOTICE %s :2) %s!%s@%s on %s requested ungline at %s for %s@%s [%s]",
590 >               from, to, glp_ptr->vote_2.oper_nick,
591 >               glp_ptr->vote_2.oper_user, glp_ptr->vote_2.oper_host,
592 >               glp_ptr->vote_2.oper_server, timebuffer,
593 >               glp_ptr->user, glp_ptr->host, glp_ptr->vote_2.reason);
594 >
595 >    }
596 >  }
597 >
598 >  sendto_one(source_p, ":%s NOTICE %s :End of Pending UNG-lines",
599               from, to);
857 #endif /* GLINE VOTING */
600   }
601  
602   /* stats_glines()
# Line 864 | Line 606 | stats_pending_glines(struct Client *sour
606   * side effects - client is shown list of glines
607   */
608   static void
609 < stats_glines(struct Client *source_p)
609 > stats_glines(struct Client *source_p, int parc, char *parv[])
610   {
611 <  struct AddressRec *arec = NULL;
612 <  int i = 0;
611 >  dlink_node *ptr = NULL;
612 >  unsigned int i = 0;
613  
614    if (!ConfigFileEntry.glines)
615    {
# Line 876 | Line 618 | stats_glines(struct Client *source_p)
618      return;
619    }
620  
621 <  for (; i < ATABLE_SIZE; ++i)
621 >  for (i = 0; i < ATABLE_SIZE; ++i)
622    {
623 <    for (arec = atable[i]; arec; arec = arec->next)
623 >    DLINK_FOREACH(ptr, atable[i].head)
624      {
625 +      const struct AddressRec *arec = ptr->data;
626 +
627        if (arec->type == CONF_GLINE)
628        {
629          const struct AccessItem *aconf = arec->aconf;
# Line 894 | Line 638 | stats_glines(struct Client *source_p)
638    }
639   }
640  
641 < /* stats_gdeny()
641 > static void
642 > stats_hubleaf(struct Client *source_p, int parc, char *parv[])
643 > {
644 >  report_confitem_types(source_p, HUB_TYPE);
645 >  report_confitem_types(source_p, LEAF_TYPE);
646 > }
647 >
648 > /*
649 > * show_iline_prefix()
650   *
651 < * input        - client pointer
652 < * outputs      - none
653 < * side effects - client is shown gline ACL
651 > * inputs       - pointer to struct Client requesting output
652 > *              - pointer to struct AccessItem
653 > *              - name to which iline prefix will be prefixed to
654 > * output       - pointer to static string with prefixes listed in ascii form
655 > * side effects - NONE
656   */
657 < static void
658 < stats_gdeny(struct Client *source_p)
657 > static const char *
658 > show_iline_prefix(struct Client *sptr, struct AccessItem *aconf, const char *name)
659   {
660 <  if (!ConfigFileEntry.glines)
661 <  {
662 <    sendto_one(source_p, ":%s NOTICE %s :This server does not support G-Lines",
663 <               from, to);
664 <    return;
665 <  }
660 >  static char prefix_of_host[USERLEN + 14];
661 >  char *prefix_ptr = prefix_of_host;
662 >
663 >  if (IsNoTilde(aconf))
664 >    *prefix_ptr++ = '-';
665 >  if (IsLimitIp(aconf))
666 >    *prefix_ptr++ = '!';
667 >  if (IsNeedIdentd(aconf))
668 >    *prefix_ptr++ = '+';
669 >  if (!IsNeedPassword(aconf))
670 >    *prefix_ptr++ = '&';
671 >  if (IsConfExemptResv(aconf))
672 >    *prefix_ptr++ = '$';
673 >  if (IsNoMatchIp(aconf))
674 >    *prefix_ptr++ = '%';
675 >  if (IsConfDoSpoofIp(aconf))
676 >    *prefix_ptr++ = '=';
677 >  if (MyOper(sptr) && IsConfExemptKline(aconf))
678 >    *prefix_ptr++ = '^';
679 >  if (MyOper(sptr) && IsConfExemptGline(aconf))
680 >    *prefix_ptr++ = '_';
681 >  if (MyOper(sptr) && IsConfExemptLimits(aconf))
682 >    *prefix_ptr++ = '>';
683 >  if (IsConfCanFlood(aconf))
684 >    *prefix_ptr++ = '|';
685  
686 <  report_confitem_types(source_p, GDENY_TYPE, 0);
686 >  strlcpy(prefix_ptr, name, USERLEN+1);
687 >
688 >  return prefix_of_host;
689   }
690  
691   static void
692 < stats_hubleaf(struct Client *source_p)
692 > report_auth(struct Client *client_p, int parc, char *parv[])
693   {
694 <  report_confitem_types(source_p, HUB_TYPE, 0);
695 <  report_confitem_types(source_p, LEAF_TYPE, 0);
694 >  struct ConfItem *conf;
695 >  struct AccessItem *aconf;
696 >  dlink_node *ptr = NULL;
697 >  unsigned int i;
698 >
699 >
700 >  for (i = 0; i < ATABLE_SIZE; ++i)
701 >  {
702 >    DLINK_FOREACH(ptr, atable[i].head)
703 >    {
704 >      struct AddressRec *arec = ptr->data;
705 >
706 >      if (arec->type == CONF_CLIENT)
707 >      {
708 >        aconf = arec->aconf;
709 >
710 >        if (!MyOper(client_p) && IsConfDoSpoofIp(aconf))
711 >          continue;
712 >
713 >        conf = unmap_conf_item(aconf);
714 >
715 >        /* We are doing a partial list, based on what matches the u@h of the
716 >         * sender, so prepare the strings for comparing --fl_
717 >         */
718 >        if (ConfigFileEntry.hide_spoof_ips)
719 >          sendto_one(client_p, form_str(RPL_STATSILINE), me.name,
720 >                     client_p->name, 'I',
721 >                     conf->name == NULL ? "*" : conf->name,
722 >                     show_iline_prefix(client_p, aconf, aconf->user),
723 >                     IsConfDoSpoofIp(aconf) ? "255.255.255.255" :
724 >                     aconf->host, aconf->port,
725 >                     aconf->class_ptr ? aconf->class_ptr->name : "<default>");
726 >
727 >        else
728 >          sendto_one(client_p, form_str(RPL_STATSILINE), me.name,
729 >                     client_p->name, 'I',
730 >                     conf->name == NULL ? "*" : conf->name,
731 >                     show_iline_prefix(client_p, aconf, aconf->user),
732 >                     aconf->host, aconf->port,
733 >                     aconf->class_ptr ? aconf->class_ptr->name : "<default>");
734 >      }
735 >    }
736 >  }
737   }
738  
739   static void
740 < stats_auth(struct Client *source_p)
740 > stats_auth(struct Client *source_p, int parc, char *parv[])
741   {
742    /* Oper only, if unopered, return ERR_NOPRIVILEGES */
743 <  if ((ConfigFileEntry.stats_i_oper_only == 2) && !IsOper(source_p))
743 >  if ((ConfigFileEntry.stats_i_oper_only == 2) && !HasUMode(source_p, UMODE_OPER))
744      sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
745                 from, to);
746  
747    /* If unopered, Only return matching auth blocks */
748 <  else if ((ConfigFileEntry.stats_i_oper_only == 1) && !IsOper(source_p))
748 >  else if ((ConfigFileEntry.stats_i_oper_only == 1) && !HasUMode(source_p, UMODE_OPER))
749    {
750      struct ConfItem *conf;
751      struct AccessItem *aconf;
# Line 940 | Line 756 | stats_auth(struct Client *source_p)
756                                     CONF_CLIENT,
757                                     source_p->localClient->aftype,
758                                     source_p->username,
759 <                                   source_p->localClient->passwd);
759 >                                   source_p->localClient->passwd, 1);
760      else
761        aconf = find_conf_by_address(source_p->host, NULL, CONF_CLIENT,
762 <                                   0, source_p->username, NULL);
762 >                                   0, source_p->username, NULL, 1);
763  
764      if (aconf == NULL)
765        return;
# Line 958 | Line 774 | stats_auth(struct Client *source_p)
774    }
775    /* They are opered, or allowed to see all auth blocks */
776    else
777 <    report_auth(source_p);
777 >    report_auth(source_p, 0, NULL);
778 > }
779 >
780 > /* report_Klines()
781 > * Inputs: Client to report to,
782 > *         type(==0 for perm, !=0 for temporary)
783 > *         mask
784 > * Output: None
785 > * Side effects: Reports configured K(or k)-lines to client_p.
786 > */
787 > static void
788 > report_Klines(struct Client *client_p, int tkline)
789 > {
790 >  struct AccessItem *aconf = NULL;
791 >  unsigned int i = 0;
792 >  const char *p = NULL;
793 >  dlink_node *ptr = NULL;
794 >
795 >  if (tkline)
796 >    p = "k";
797 >  else
798 >    p = "K";
799 >
800 >  for (i = 0; i < ATABLE_SIZE; ++i)
801 >  {
802 >    DLINK_FOREACH(ptr, atable[i].head)
803 >    {
804 >      struct AddressRec *arec = ptr->data;
805 >
806 >      if (arec->type == CONF_KLINE)
807 >      {
808 >        if ((tkline && !((aconf = arec->aconf)->flags & CONF_FLAGS_TEMPORARY)) ||
809 >            (!tkline && ((aconf = arec->aconf)->flags & CONF_FLAGS_TEMPORARY)))
810 >          continue;
811 >
812 >        if (HasUMode(client_p, UMODE_OPER))
813 >          sendto_one(client_p, form_str(RPL_STATSKLINE), me.name,
814 >                     client_p->name, p, aconf->host, aconf->user,
815 >                     aconf->reason, aconf->oper_reason ? aconf->oper_reason : "");
816 >        else
817 >          sendto_one(client_p, form_str(RPL_STATSKLINE), me.name,
818 >                     client_p->name, p, aconf->host, aconf->user,
819 >                     aconf->reason, "");
820 >      }
821 >    }
822 >  }
823   }
824  
825   static void
826 < stats_tklines(struct Client *source_p)
826 > stats_tklines(struct Client *source_p, int parc, char *parv[])
827   {
828    struct ConfItem *conf;
829    /* Oper only, if unopered, return ERR_NOPRIVILEGES */
830 <  if ((ConfigFileEntry.stats_k_oper_only == 2) && !IsOper(source_p))
830 >  if ((ConfigFileEntry.stats_k_oper_only == 2) && !HasUMode(source_p, UMODE_OPER))
831      sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
832                 from, to);
833  
834    /* If unopered, Only return matching klines */
835 <  else if ((ConfigFileEntry.stats_k_oper_only == 1) && !IsOper(source_p))
835 >  else if ((ConfigFileEntry.stats_k_oper_only == 1) && !HasUMode(source_p, UMODE_OPER))
836    {
837      struct AccessItem *aconf;
838  
839      if (MyConnect(source_p))
840        aconf = find_conf_by_address(source_p->host,
841                                     &source_p->localClient->ip,
842 <                                   CONF_KILL,
842 >                                   CONF_KLINE,
843                                     source_p->localClient->aftype,
844 <                                   source_p->username, NULL);
844 >                                   source_p->username, NULL, 1);
845      else
846 <      aconf = find_conf_by_address(source_p->host, NULL, CONF_KILL,
847 <                                   0, source_p->username, NULL);
846 >      aconf = find_conf_by_address(source_p->host, NULL, CONF_KLINE,
847 >                                   0, source_p->username, NULL, 1);
848  
849      if (aconf == NULL)
850        return;
# Line 1000 | Line 861 | stats_tklines(struct Client *source_p)
861    /* Theyre opered, or allowed to see all klines */
862    else {
863      report_Klines(source_p, 1);
1003    report_confitem_types(source_p, RKLINE_TYPE, 1);
864    }
865   }
866  
867   static void
868 < stats_klines(struct Client *source_p)
868 > stats_klines(struct Client *source_p, int parc, char *parv[])
869   {
870    /* Oper only, if unopered, return ERR_NOPRIVILEGES */
871 <  if ((ConfigFileEntry.stats_k_oper_only == 2) && !IsOper(source_p))
871 >  if ((ConfigFileEntry.stats_k_oper_only == 2) && !HasUMode(source_p, UMODE_OPER))
872      sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
873                 from, to);
874  
875    /* If unopered, Only return matching klines */
876 <  else if ((ConfigFileEntry.stats_k_oper_only == 1) && !IsOper(source_p))
876 >  else if ((ConfigFileEntry.stats_k_oper_only == 1) && !HasUMode(source_p, UMODE_OPER))
877    {
878      struct AccessItem *aconf;
879  
# Line 1021 | Line 881 | stats_klines(struct Client *source_p)
881      if (MyConnect(source_p))
882        aconf = find_conf_by_address(source_p->host,
883                                     &source_p->localClient->ip,
884 <                                   CONF_KILL,
884 >                                   CONF_KLINE,
885                                     source_p->localClient->aftype,
886 <                                   source_p->username, NULL);
886 >                                   source_p->username, NULL, 0);
887      else
888 <      aconf = find_conf_by_address(source_p->host, NULL, CONF_KILL,
889 <                                   0, source_p->username, NULL);
888 >      aconf = find_conf_by_address(source_p->host, NULL, CONF_KLINE,
889 >                                   0, source_p->username, NULL, 0);
890  
891      if (aconf == NULL)
892        return;
# Line 1042 | Line 902 | stats_klines(struct Client *source_p)
902    /* Theyre opered, or allowed to see all klines */
903    else {
904      report_Klines(source_p, 0);
905 <    report_confitem_types(source_p, RKLINE_TYPE, 0);
905 >    report_confitem_types(source_p, RKLINE_TYPE);
906    }
907   }
908  
909   static void
910 < stats_messages(struct Client *source_p)
910 > stats_messages(struct Client *source_p, int parc, char *parv[])
911   {
912    report_messages(source_p);
913   }
914  
915   static void
916 < stats_oper(struct Client *source_p)
916 > stats_oper(struct Client *source_p, int parc, char *parv[])
917   {
918 <  if (!IsOper(source_p) && ConfigFileEntry.stats_o_oper_only)
918 >  if (!HasUMode(source_p, UMODE_OPER) && ConfigFileEntry.stats_o_oper_only)
919      sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
920                 from, to);
921    else
922 <    report_confitem_types(source_p, OPER_TYPE, 0);
922 >    report_confitem_types(source_p, OPER_TYPE);
923   }
924  
925   /* stats_operedup()
# Line 1069 | Line 929 | stats_oper(struct Client *source_p)
929   * side effects - client is shown a list of active opers
930   */
931   static void
932 < stats_operedup(struct Client *source_p)
932 > stats_operedup(struct Client *source_p, int parc, char *parv[])
933   {
934    dlink_node *ptr;
935  
# Line 1077 | Line 937 | stats_operedup(struct Client *source_p)
937    {
938      const struct Client *target_p = ptr->data;
939  
940 <    if (IsOperHidden(target_p) && !IsOper(source_p))
940 >    if (HasUMode(target_p, UMODE_HIDDEN) && !HasUMode(source_p, UMODE_OPER))
941        continue;
942  
943 <    if (MyClient(source_p) && IsOper(source_p))
943 >    if (MyClient(source_p) && HasUMode(source_p, UMODE_OPER))
944        sendto_one(source_p, ":%s %d %s p :[%c][%s] %s (%s@%s) Idle: %d",
945                   from, RPL_STATSDEBUG, to,
946 <                 IsAdmin(target_p) ?
1087 <                 (IsOperHiddenAdmin(target_p) ? 'O' : 'A') : 'O',
946 >                 HasUMode(target_p, UMODE_ADMIN) ? 'A' : 'O',
947                   oper_privs_as_string(target_p->localClient->operflags),
948                   target_p->name, target_p->username, target_p->host,
949 <                 (int)(CurrentTime - target_p->localClient->last));
949 >                 (int)(CurrentTime - target_p->localClient->last_privmsg));
950      else
951        sendto_one(source_p, ":%s %d %s p :[%c] %s (%s@%s) Idle: %d",
952                   from, RPL_STATSDEBUG, to,
953 <                 IsAdmin(target_p) ?
1095 <                 (IsOperHiddenAdmin(target_p) ? 'O' : 'A') : 'O',
953 >                 HasUMode(target_p, UMODE_ADMIN) ? 'A' : 'O',
954                   target_p->name, target_p->username, target_p->host,
955 <                 (int)(CurrentTime - target_p->localClient->last));
955 >                 (int)(CurrentTime - target_p->localClient->last_privmsg));
956    }
957  
958    sendto_one(source_p, ":%s %d %s p :%lu OPER(s)",
# Line 1102 | Line 960 | stats_operedup(struct Client *source_p)
960   }
961  
962   static void
963 < stats_ports(struct Client *source_p)
963 > stats_ports(struct Client *source_p, int parc, char *parv[])
964   {
965 <  if (!IsOper(source_p) && ConfigFileEntry.stats_P_oper_only)
965 >  if (!HasUMode(source_p, UMODE_OPER) && ConfigFileEntry.stats_P_oper_only)
966      sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
967                 from, to);
968    else
# Line 1112 | Line 970 | stats_ports(struct Client *source_p)
970   }
971  
972   static void
973 < stats_resv(struct Client *source_p)
973 > stats_resv(struct Client *source_p, int parc, char *parv[])
974   {
975    report_resv(source_p);
976   }
977  
978   static void
979 < stats_usage(struct Client *source_p)
979 > stats_service(struct Client *source_p, int parc, char *parv[])
980   {
981 <  send_usage(source_p);
981 >  report_confitem_types(source_p, SERVICE_TYPE);
982   }
983  
984   static void
985 < stats_tstats(struct Client *source_p)
985 > stats_tstats(struct Client *source_p, int parc, char *parv[])
986   {
987 <  tstats(source_p);
987 >  const struct Client *target_p = NULL;
988 >  const dlink_node *ptr = NULL;
989 >  struct ServerStatistics *sp;
990 >  struct ServerStatistics tmp;
991 >
992 >  sp = &tmp;
993 >  memcpy(sp, &ServerStats, sizeof(struct ServerStatistics));
994 >
995 >  /*
996 >   * must use the += operator. is_sv is not the number of currently
997 >   * active server connections. Note the incrementation in
998 >   * s_bsd.c:close_connection.
999 >   */
1000 >  sp->is_sv += dlink_list_length(&serv_list);
1001 >
1002 >  DLINK_FOREACH(ptr, serv_list.head)
1003 >  {
1004 >    target_p = ptr->data;
1005 >
1006 >    sp->is_sbs += target_p->localClient->send.bytes;
1007 >    sp->is_sbr += target_p->localClient->recv.bytes;
1008 >    sp->is_sti += CurrentTime - target_p->localClient->firsttime;
1009 >  }
1010 >
1011 >  sp->is_cl += dlink_list_length(&local_client_list);
1012 >
1013 >  DLINK_FOREACH(ptr, local_client_list.head)
1014 >  {
1015 >    target_p = ptr->data;
1016 >
1017 >    sp->is_cbs += target_p->localClient->send.bytes;
1018 >    sp->is_cbr += target_p->localClient->recv.bytes;
1019 >    sp->is_cti += CurrentTime - target_p->localClient->firsttime;
1020 >  }
1021 >
1022 >  sp->is_ni += dlink_list_length(&unknown_list);
1023 >
1024 >  sendto_one(source_p, ":%s %d %s T :accepts %u refused %u",
1025 >             me.name, RPL_STATSDEBUG, source_p->name, sp->is_ac, sp->is_ref);
1026 >  sendto_one(source_p, ":%s %d %s T :unknown commands %u prefixes %u",
1027 >             me.name, RPL_STATSDEBUG, source_p->name, sp->is_unco, sp->is_unpf);
1028 >  sendto_one(source_p, ":%s %d %s T :nick collisions %u unknown closes %u",
1029 >             me.name, RPL_STATSDEBUG, source_p->name, sp->is_kill, sp->is_ni);
1030 >  sendto_one(source_p, ":%s %d %s T :wrong direction %u empty %u",
1031 >             me.name, RPL_STATSDEBUG, source_p->name, sp->is_wrdi, sp->is_empt);
1032 >  sendto_one(source_p, ":%s %d %s T :numerics seen %u",
1033 >             me.name, RPL_STATSDEBUG, source_p->name, sp->is_num);
1034 >  sendto_one(source_p, ":%s %d %s T :auth successes %u fails %u",
1035 >             me.name, RPL_STATSDEBUG, source_p->name, sp->is_asuc, sp->is_abad);
1036 >  sendto_one(source_p, ":%s %d %s T :Client Server",
1037 >             me.name, RPL_STATSDEBUG, source_p->name);
1038 >
1039 >  sendto_one(source_p, ":%s %d %s T :connected %u %u",
1040 >             me.name, RPL_STATSDEBUG, source_p->name,
1041 >             (unsigned int)sp->is_cl,
1042 >             (unsigned int)sp->is_sv);
1043 >  sendto_one(source_p, ":%s %d %s T :bytes sent %llu %llu",
1044 >             me.name, RPL_STATSDEBUG, source_p->name,
1045 >             sp->is_cbs, sp->is_sbs);
1046 >  sendto_one(source_p, ":%s %d %s T :bytes recv %llu %llu",
1047 >             me.name, RPL_STATSDEBUG, source_p->name,
1048 >             sp->is_cbr, sp->is_sbr);
1049 >  sendto_one(source_p, ":%s %d %s T :time connected %u %u",
1050 >             me.name, RPL_STATSDEBUG, source_p->name,
1051 >             (unsigned int)sp->is_cti,
1052 >             (unsigned int)sp->is_sti);
1053   }
1054  
1055   static void
1056 < stats_uptime(struct Client *source_p)
1056 > stats_uptime(struct Client *source_p, int parc, char *parv[])
1057   {
1058 <  time_t now = CurrentTime - me.since;
1058 >  time_t now = CurrentTime - me.localClient->since;
1059 >
1060    sendto_one(source_p, form_str(RPL_STATSUPTIME), from, to,
1061 <             now/86400, (now/3600)%24, (now/60)%60, now%60);
1062 <  if (!ConfigFileEntry.disable_remote || IsOper(source_p))
1061 >             now / 86400, (now / 3600) % 24, (now / 60) % 60, now % 60);
1062 >
1063 >  if (!ConfigFileEntry.disable_remote || HasUMode(source_p, UMODE_OPER))
1064       sendto_one(source_p, form_str(RPL_STATSCONN), from, to,
1065 <                MaxConnectionCount, MaxClientCount, Count.totalrestartcount);
1065 >                Count.max_loc_con, Count.max_loc_cli, Count.totalrestartcount);
1066   }
1067  
1068   static void
1069 < stats_shared(struct Client *source_p)
1069 > stats_shared(struct Client *source_p, int parc, char *parv[])
1070   {
1071 <  report_confitem_types(source_p, ULINE_TYPE, 0);
1071 >  report_confitem_types(source_p, ULINE_TYPE);
1072   }
1073  
1074   /* stats_servers()
# Line 1153 | Line 1078 | stats_shared(struct Client *source_p)
1078   * side effects - client is shown lists of who connected servers
1079   */
1080   static void
1081 < stats_servers(struct Client *source_p)
1081 > stats_servers(struct Client *source_p, int parc, char *parv[])
1082   {
1083 <  struct Client *target_p;
1159 <  dlink_node *ptr;
1160 <  int j = 0;
1083 >  dlink_node *ptr = NULL;
1084  
1085    DLINK_FOREACH(ptr, serv_list.head)
1086    {
1087 <    target_p = ptr->data;
1165 <
1166 <    j++;
1087 >    const struct Client *target_p = ptr->data;
1088  
1089      sendto_one(source_p, ":%s %d %s v :%s (%s!%s@%s) Idle: %d",
1090 <               from, RPL_STATSDEBUG, to,
1091 <               target_p->name,
1092 <               (target_p->serv->by[0] ? target_p->serv->by : "Remote."),
1172 <               "*", "*", (int)(CurrentTime - target_p->lasttime));
1090 >               from, RPL_STATSDEBUG, to, target_p->name,
1091 >               (target_p->serv->by[0] ? target_p->serv->by : "Remote."),
1092 >               "*", "*", (int)(CurrentTime - target_p->localClient->lasttime));
1093    }
1094  
1095 <  sendto_one(source_p, ":%s %d %s v :%d Server(s)",
1096 <             from, RPL_STATSDEBUG, to, j);
1177 < }
1178 <
1179 < static void
1180 < stats_gecos(struct Client *source_p)
1181 < {
1182 <  report_confitem_types(source_p, XLINE_TYPE, 0);
1183 <  report_confitem_types(source_p, RXLINE_TYPE, 0);
1184 < }
1185 <
1186 < static void
1187 < stats_class(struct Client *source_p)
1188 < {
1189 <  report_confitem_types(source_p, CLASS_TYPE, 0);
1095 >  sendto_one(source_p, ":%s %d %s v :%u Server(s)",
1096 >             from, RPL_STATSDEBUG, to, dlink_list_length(&serv_list));
1097   }
1098  
1099   static void
1100 < stats_memory(struct Client *source_p)
1100 > stats_gecos(struct Client *source_p, int parc, char *parv[])
1101   {
1102 <  count_memory(source_p);
1102 >  report_confitem_types(source_p, XLINE_TYPE);
1103 >  report_confitem_types(source_p, RXLINE_TYPE);
1104   }
1105  
1106   static void
1107 < stats_ziplinks(struct Client *source_p)
1107 > stats_class(struct Client *source_p, int parc, char *parv[])
1108   {
1109 <  dlink_node *ptr;
1202 <  struct Client *target_p;
1203 <  unsigned int sent_data = 0;
1204 <
1205 <  DLINK_FOREACH(ptr, serv_list.head)
1206 <  {
1207 <    target_p = ptr->data;
1208 <
1209 <    if (IsCapable(target_p, CAP_ZIP))
1210 <    {
1211 <      /* we use memcpy(3) and a local copy of the structure to
1212 <       * work around a register use bug on GCC on the SPARC.
1213 <       * -jmallett, 04/27/2002
1214 <       */
1215 <      struct ZipStats zipstats;
1216 <      memcpy(&zipstats, &target_p->localClient->zipstats, sizeof (struct ZipStats));
1217 <
1218 <      sendto_one(source_p, ":%s %d %s Z :ZipLinks stats for %s send[%.2f%% "
1219 <                 "compression (%lu bytes data/%lu bytes wire)] recv[%.2f%% "
1220 <                 "compression (%lu bytes data/%lu bytes wire)]",
1221 <                 from, RPL_STATSDEBUG, to, target_p->name,
1222 <                 zipstats.out_ratio, zipstats.out, zipstats.out_wire,
1223 <                 zipstats.in_ratio,  zipstats.in,  zipstats.in_wire);
1224 <      ++sent_data;
1225 <    }
1226 <  }
1227 <
1228 <  sendto_one(source_p, ":%s %d %s Z :%u ziplink(s)",
1229 <             from, RPL_STATSDEBUG, to, sent_data);
1109 >  report_confitem_types(source_p, CLASS_TYPE);
1110   }
1111  
1112   static void
1113 < stats_servlinks(struct Client *source_p)
1113 > stats_servlinks(struct Client *source_p, int parc, char *parv[])
1114   {
1115    uint64_t sendB = 0, recvB = 0;
1116    time_t uptime = 0;
1117    dlink_node *ptr = NULL;
1118  
1119 <  if (ConfigServerHide.flatten_links && !IsOper(source_p))
1119 >  if (ConfigServerHide.flatten_links && !HasUMode(source_p, UMODE_OPER))
1120    {
1121      sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
1122                 from, to);
# Line 1253 | Line 1133 | stats_servlinks(struct Client *source_p)
1133      /* ":%s 211 %s %s %u %u %llu %u %llu :%u %u %s" */
1134      sendto_one(source_p, form_str(RPL_STATSLINKINFO),
1135                 from, to,
1136 <               get_client_name(target_p, IsAdmin(source_p) ? SHOW_IP : MASK_IP),
1136 >               get_client_name(target_p, HasUMode(source_p, UMODE_ADMIN) ? SHOW_IP : MASK_IP),
1137                 dbuf_length(&target_p->localClient->buf_sendq),
1138                 target_p->localClient->send.messages,
1139                 target_p->localClient->send.bytes >> 10,
1140                 target_p->localClient->recv.messages,
1141                 target_p->localClient->recv.bytes >> 10,
1142 <               (unsigned)(CurrentTime - target_p->firsttime),
1143 <               (CurrentTime > target_p->since) ? (unsigned)(CurrentTime - target_p->since): 0,
1144 <               IsOper(source_p) ? show_capabilities(target_p) : "TS");
1142 >               (unsigned)(CurrentTime - target_p->localClient->firsttime),
1143 >               (CurrentTime > target_p->localClient->since) ? (unsigned)(CurrentTime - target_p->localClient->since): 0,
1144 >               HasUMode(source_p, UMODE_OPER) ? show_capabilities(target_p) : "TS");
1145    }
1146  
1147    sendB >>= 10;
# Line 1276 | Line 1156 | stats_servlinks(struct Client *source_p)
1156               from, RPL_STATSDEBUG, to,
1157               _GMKv(recvB), _GMKs(recvB));
1158  
1159 <  uptime = (CurrentTime - me.since);
1159 >  uptime = (CurrentTime - me.localClient->since);
1160  
1161    sendto_one(source_p, ":%s %d %s ? :Server send: %7.2f %s (%4.1f K/s)",
1162               from, RPL_STATSDEBUG, to,
# Line 1292 | Line 1172 | stats_servlinks(struct Client *source_p)
1172               (float)uptime));
1173   }
1174  
1175 < static void
1176 < stats_ltrace(struct Client *source_p, int parc, char *parv[])
1175 > /* parse_stats_args()
1176 > *
1177 > * inputs       - arg count
1178 > *              - args
1179 > *              - doall flag
1180 > *              - wild card or not
1181 > * output       - pointer to name to use
1182 > * side effects -
1183 > * common parse routine for m_stats args
1184 > *
1185 > */
1186 > static char *
1187 > parse_stats_args(int parc, char *parv[], int *doall, int *wilds)
1188   {
1189 <  int doall = 0;
1299 <  int wilds = 0;
1300 <  char *name = NULL;
1301 <  char statchar;
1189 >  char *name;
1190  
1191 <  if ((name = parse_stats_args(parc, parv, &doall, &wilds)) != NULL)
1191 >  if (parc > 2)
1192    {
1193 <    statchar = parv[1][0];
1193 >    name = parv[2];
1194  
1195 <    stats_L(source_p, name, doall, wilds, statchar);
1196 <  }
1197 <  else
1198 <    sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
1311 <               from, to, "STATS");
1312 < }
1195 >    if (!irccmp(name, from))
1196 >      *doall = 2;
1197 >    else if (match(name, from))
1198 >      *doall = 1;
1199  
1200 < /*
1315 < * ms_stats - STATS message handler
1316 < *      parv[0] = sender prefix
1317 < *      parv[1] = statistics selector (defaults to Message frequency)
1318 < *      parv[2] = server name (current server defaulted, if omitted)
1319 < */
1320 < static void
1321 < ms_stats(struct Client *client_p, struct Client *source_p,
1322 <         int parc, char *parv[])
1323 < {
1324 <  if (hunt_server(client_p,source_p,":%s STATS %s :%s",2,parc,parv)!=HUNTED_ISME)
1325 <    return;
1200 >    *wilds = has_wildcards(name);
1201  
1202 <  if (IsClient(source_p))
1203 <    mo_stats(client_p, source_p, parc, parv);
1329 < }
1202 >    return name;
1203 >  }
1204  
1205 < /*
1332 < * stats_L
1333 < *
1334 < * inputs       - pointer to client to report to
1335 < *              - doall flag
1336 < *              - wild card or not
1337 < * output       - NONE
1338 < * side effects -
1339 < */
1340 < static void
1341 < stats_L(struct Client *source_p,char *name,int doall,
1342 <        int wilds,char statchar)
1343 < {
1344 <  stats_L_list(source_p, name, doall, wilds, &unknown_list, statchar);
1345 <  stats_L_list(source_p, name, doall, wilds, &local_client_list, statchar);
1346 <  stats_L_list(source_p, name, doall, wilds, &serv_list, statchar);
1205 >  return NULL;
1206   }
1207  
1208   static void
# Line 1363 | Line 1222 | stats_L_list(struct Client *source_p,cha
1222    {
1223      target_p = ptr->data;
1224  
1225 <    if (IsInvisible(target_p) && (doall || wilds) &&
1226 <        !(MyConnect(source_p) && IsOper(source_p)) &&
1227 <        !IsOper(target_p) && (target_p != source_p))
1225 >    if (HasUMode(target_p, UMODE_INVISIBLE) && (doall || wilds) &&
1226 >        !(MyConnect(source_p) && HasUMode(source_p, UMODE_OPER)) &&
1227 >        !HasUMode(target_p, UMODE_OPER) && (target_p != source_p))
1228        continue;
1229      if (!doall && wilds && !match(name, target_p->name))
1230        continue;
# Line 1374 | Line 1233 | stats_L_list(struct Client *source_p,cha
1233  
1234      /* This basically shows ips for our opers if its not a server/admin, or
1235       * its one of our admins.  */
1236 <    if(MyClient(source_p) && IsOper(source_p) &&
1237 <       (IsAdmin(source_p) ||
1238 <       (!IsServer(target_p) && !IsAdmin(target_p) &&
1236 >    if(MyClient(source_p) && HasUMode(source_p, UMODE_OPER) &&
1237 >       (HasUMode(source_p, UMODE_ADMIN) ||
1238 >       (!IsServer(target_p) && !HasUMode(target_p, UMODE_ADMIN) &&
1239         !IsHandshake(target_p) && !IsConnecting(target_p))))
1240      {
1241        sendto_one(source_p, form_str(RPL_STATSLINKINFO),
1242 <                 from, to,
1242 >                 from, to,
1243                   (IsUpper(statchar)) ?
1244                   get_client_name(target_p, SHOW_IP) :
1245                   get_client_name(target_p, HIDE_IP),
# Line 1389 | Line 1248 | stats_L_list(struct Client *source_p,cha
1248                   target_p->localClient->send.bytes>>10,
1249                   target_p->localClient->recv.messages,
1250                   target_p->localClient->recv.bytes>>10,
1251 <                 (unsigned)(CurrentTime - target_p->firsttime),
1252 <                 (CurrentTime > target_p->since) ? (unsigned)(CurrentTime - target_p->since):0,
1251 >                 (unsigned)(CurrentTime - target_p->localClient->firsttime),
1252 >                 (CurrentTime > target_p->localClient->since) ? (unsigned)(CurrentTime - target_p->localClient->since):0,
1253                   IsServer(target_p) ? show_capabilities(target_p) : "-");
1254      }
1255      else
1256      {
1257        /* If its a hidden ip, an admin, or a server, mask the real IP */
1258 <      if(IsIPSpoof(target_p) || IsServer(target_p) || IsAdmin(target_p)
1258 >      if(IsIPSpoof(target_p) || IsServer(target_p) || HasUMode(target_p, UMODE_ADMIN)
1259           || IsHandshake(target_p) || IsConnecting(target_p))
1260          sendto_one(source_p, form_str(RPL_STATSLINKINFO),
1261                     from, to,
1262 <                   get_client_name(target_p, MASK_IP),
1263 <                   dbuf_length(&target_p->localClient->buf_sendq),
1264 <                   target_p->localClient->send.messages,
1265 <                   target_p->localClient->send.bytes>>10,
1266 <                   target_p->localClient->recv.messages,
1267 <                   target_p->localClient->recv.bytes>>10,
1268 <                   (unsigned)(CurrentTime - target_p->firsttime),
1269 <                   (CurrentTime > target_p->since) ? (unsigned)(CurrentTime - target_p->since):0,
1270 <                   IsServer(target_p) ? show_capabilities(target_p) : "-");
1262 >                   get_client_name(target_p, MASK_IP),
1263 >                   dbuf_length(&target_p->localClient->buf_sendq),
1264 >                   target_p->localClient->send.messages,
1265 >                   target_p->localClient->send.bytes>>10,
1266 >                   target_p->localClient->recv.messages,
1267 >                   target_p->localClient->recv.bytes>>10,
1268 >                   (unsigned)(CurrentTime - target_p->localClient->firsttime),
1269 >                   (CurrentTime > target_p->localClient->since) ? (unsigned)(CurrentTime - target_p->localClient->since):0,
1270 >                   IsServer(target_p) ? show_capabilities(target_p) : "-");
1271        else /* show the real IP */
1272          sendto_one(source_p, form_str(RPL_STATSLINKINFO),
1273                     from, to,
1274 <                   (IsUpper(statchar)) ?
1275 <                   get_client_name(target_p, SHOW_IP) :
1276 <                   get_client_name(target_p, HIDE_IP),
1277 <                   dbuf_length(&target_p->localClient->buf_sendq),
1278 <                   target_p->localClient->send.messages,
1279 <                   target_p->localClient->send.bytes>>10,
1280 <                   target_p->localClient->recv.messages,
1281 <                   target_p->localClient->recv.bytes>>10,
1282 <                   (unsigned)(CurrentTime - target_p->firsttime),
1283 <                   (CurrentTime > target_p->since) ? (unsigned)(CurrentTime - target_p->since):0,
1284 <                   IsServer(target_p) ? show_capabilities(target_p) : "-");
1274 >                   (IsUpper(statchar)) ?
1275 >                   get_client_name(target_p, SHOW_IP) :
1276 >                   get_client_name(target_p, HIDE_IP),
1277 >                   dbuf_length(&target_p->localClient->buf_sendq),
1278 >                   target_p->localClient->send.messages,
1279 >                   target_p->localClient->send.bytes>>10,
1280 >                   target_p->localClient->recv.messages,
1281 >                   target_p->localClient->recv.bytes>>10,
1282 >                   (unsigned)(CurrentTime - target_p->localClient->firsttime),
1283 >                   (CurrentTime > target_p->localClient->since) ? (unsigned)(CurrentTime - target_p->localClient->since):0,
1284 >                   IsServer(target_p) ? show_capabilities(target_p) : "-");
1285      }
1286    }
1287   }
1288  
1289 < /* parse_stats_args()
1289 > /*
1290 > * stats_L
1291   *
1292 < * inputs       - arg count
1293 < *              - args
1294 < *              - doall flag
1295 < *              - wild card or not
1296 < * output       - pointer to name to use
1297 < * side effects -
1298 < * common parse routine for m_stats args
1292 > * inputs       - pointer to client to report to
1293 > *              - doall flag
1294 > *              - wild card or not
1295 > * output       - NONE
1296 > * side effects -
1297 > */
1298 > static void
1299 > stats_L(struct Client *source_p,char *name,int doall,
1300 >        int wilds,char statchar)
1301 > {
1302 >  stats_L_list(source_p, name, doall, wilds, &unknown_list, statchar);
1303 >  stats_L_list(source_p, name, doall, wilds, &local_client_list, statchar);
1304 >  stats_L_list(source_p, name, doall, wilds, &serv_list, statchar);
1305 > }
1306 >
1307 > static void
1308 > stats_ltrace(struct Client *source_p, int parc, char *parv[])
1309 > {
1310 >  int doall = 0;
1311 >  int wilds = 0;
1312 >  char *name = NULL;
1313 >  char statchar;
1314 >
1315 >  if ((name = parse_stats_args(parc, parv, &doall, &wilds)) != NULL)
1316 >  {
1317 >    statchar = parv[1][0];
1318 >
1319 >    stats_L(source_p, name, doall, wilds, statchar);
1320 >  }
1321 >  else
1322 >    sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
1323 >               from, to, "STATS");
1324 > }
1325 >
1326 > static const struct StatsStruct
1327 > {
1328 >  const unsigned char letter;
1329 >  void (*handler)();
1330 >  const unsigned int need_oper;
1331 >  const unsigned int need_admin;
1332 > } stats_cmd_table[] = {
1333 >  /* letter     function            need_oper need_admin */
1334 >  { 'a',        stats_dns_servers,      1,      1       },
1335 >  { 'A',        stats_dns_servers,      1,      1       },
1336 >  { 'c',        stats_connect,          1,      0       },
1337 >  { 'C',        stats_connect,          1,      0       },
1338 >  { 'd',        stats_tdeny,            1,      0       },
1339 >  { 'D',        stats_deny,             1,      0       },
1340 >  { 'e',        stats_exempt,           1,      0       },
1341 >  { 'E',        stats_events,           1,      1       },
1342 >  { 'f',        fd_dump,                1,      1       },
1343 >  { 'F',        fd_dump,                1,      1       },
1344 >  { 'g',        stats_pending_glines,   1,      0       },
1345 >  { 'G',        stats_glines,           1,      0       },
1346 >  { 'h',        stats_hooks,            1,      1       },
1347 >  { 'H',        stats_hubleaf,          1,      0       },
1348 >  { 'i',        stats_auth,             0,      0       },
1349 >  { 'I',        stats_auth,             0,      0       },
1350 >  { 'k',        stats_tklines,          0,      0       },
1351 >  { 'K',        stats_klines,           0,      0       },
1352 >  { 'l',        stats_ltrace,           1,      0       },
1353 >  { 'L',        stats_ltrace,           1,      0       },
1354 >  { 'm',        stats_messages,         0,      0       },
1355 >  { 'M',        stats_messages,         0,      0       },
1356 >  { 'o',        stats_oper,             0,      0       },
1357 >  { 'O',        stats_oper,             0,      0       },
1358 >  { 'p',        stats_operedup,         0,      0       },
1359 >  { 'P',        stats_ports,            0,      0       },
1360 >  { 'q',        stats_resv,             1,      0       },
1361 >  { 'Q',        stats_resv,             1,      0       },
1362 >  { 'r',        stats_usage,            1,      0       },
1363 >  { 'R',        stats_usage,            1,      0       },
1364 >  { 'S',        stats_service,          1,      0       },
1365 >  { 't',        stats_tstats,           1,      0       },
1366 >  { 'T',        stats_tstats,           1,      0       },
1367 >  { 'u',        stats_uptime,           0,      0       },
1368 >  { 'U',        stats_shared,           1,      0       },
1369 >  { 'v',        stats_servers,          1,      0       },
1370 >  { 'x',        stats_gecos,            1,      0       },
1371 >  { 'X',        stats_gecos,            1,      0       },
1372 >  { 'y',        stats_class,            1,      0       },
1373 >  { 'Y',        stats_class,            1,      0       },
1374 >  { 'z',        stats_memory,           1,      0       },
1375 >  { '?',        stats_servlinks,        0,      0       },
1376 >  { '\0',       NULL,                   0,      0       }
1377 > };
1378 >
1379 > static void
1380 > do_stats(struct Client *source_p, int parc, char *parv[])
1381 > {
1382 >  const struct StatsStruct *tab = stats_cmd_table;
1383 >  const char statchar = *parv[1];
1384 >
1385 >  if (statchar == '\0')
1386 >  {
1387 >    sendto_one(source_p, form_str(RPL_ENDOFSTATS),
1388 >               from, to, '*');
1389 >    return;
1390 >  }
1391 >
1392 >  for (; tab->handler; ++tab)
1393 >  {
1394 >    if (tab->letter == statchar)
1395 >    {
1396 >      /* The stats table says what privs are needed, so check --fl_ */
1397 >      if ((tab->need_admin && !HasUMode(source_p, UMODE_ADMIN)) ||
1398 >          (tab->need_oper && !HasUMode(source_p, UMODE_OPER)))
1399 >      {
1400 >        sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
1401 >                   from, to);
1402 >        break;
1403 >      }
1404 >
1405 >      sendto_realops_flags(UMODE_SPY, L_ALL,
1406 >                           "STATS %c requested by %s (%s@%s) [%s] on %s",
1407 >                           statchar, source_p->name, source_p->username,
1408 >                           source_p->host, source_p->servptr->name);
1409 >      tab->handler(source_p, parc, parv);
1410 >      break;
1411 >    }
1412 >  }
1413 >
1414 >  sendto_one(source_p, form_str(RPL_ENDOFSTATS),
1415 >             from, to, statchar);
1416 > }
1417 >
1418 > /*
1419 > * m_stats()
1420 > *      parv[0] = sender prefix
1421 > *      parv[1] = stat letter/command
1422 > *      parv[2] = (if present) server/mask in stats L
1423   *
1424 + * This will search the tables for the appropriate stats letter/command,
1425 + * if found execute it.  
1426   */
1427 < static char *
1428 < parse_stats_args(int parc, char *parv[], int *doall, int *wilds)
1427 > static void
1428 > m_stats(struct Client *client_p, struct Client *source_p,
1429 >        int parc, char *parv[])
1430   {
1431 <  char *name;
1431 >  static time_t last_used = 0;
1432  
1433 <  if (parc > 2)
1433 >  /* Is the stats meant for us? */
1434 >  if (!ConfigFileEntry.disable_remote)
1435 >    if (hunt_server(client_p, source_p, ":%s STATS %s :%s", 2,
1436 >                    parc, parv) != HUNTED_ISME)
1437 >      return;
1438 >
1439 >  if (!MyClient(source_p) && IsCapable(source_p->from, CAP_TS6) && HasID(source_p))
1440    {
1441 <    name = parv[2];
1441 >    from = me.id;
1442 >    to = source_p->id;
1443 >  }
1444 >  else
1445 >  {
1446 >    from = me.name;
1447 >    to = source_p->name;
1448 >  }
1449  
1450 <    if (!irccmp(name, from))
1451 <      *doall = 2;
1452 <    else if (match(name, from))
1453 <      *doall = 1;
1450 >  /* Check the user is actually allowed to do /stats, and isnt flooding */
1451 >  if ((last_used + ConfigFileEntry.pace_wait) > CurrentTime)
1452 >  {
1453 >    sendto_one(source_p,form_str(RPL_LOAD2HI),
1454 >               from, to);
1455 >    return;
1456 >  }
1457  
1458 <    if (strchr(name, '*') ||
1456 <        strchr(name, '?'))
1457 <      *wilds = 1;
1458 >  last_used = CurrentTime;
1459  
1460 <    return(name);
1460 >  do_stats(source_p, parc, parv);
1461 > }
1462 >
1463 > /*
1464 > * mo_stats()
1465 > *      parv[0] = sender prefix
1466 > *      parv[1] = stat letter/command
1467 > *      parv[2] = (if present) server/mask in stats L, or target
1468 > *
1469 > * This will search the tables for the appropriate stats letter,
1470 > * if found execute it.  
1471 > */
1472 > static void
1473 > mo_stats(struct Client *client_p, struct Client *source_p,
1474 >         int parc, char *parv[])
1475 > {
1476 >  if (hunt_server(client_p, source_p, ":%s STATS %s :%s", 2,
1477 >                  parc, parv) != HUNTED_ISME)
1478 >     return;
1479 >
1480 >  if (!MyClient(source_p) && IsCapable(source_p->from, CAP_TS6) && HasID(source_p))
1481 >  {
1482 >    from = me.id;
1483 >    to = source_p->id;
1484    }
1485    else
1486 <    return(NULL);
1486 >  {
1487 >    from = me.name;
1488 >    to = source_p->name;
1489 >  }
1490 >
1491 >  do_stats(source_p, parc, parv);
1492   }
1493 +
1494 + /*
1495 + * ms_stats - STATS message handler
1496 + *      parv[0] = sender prefix
1497 + *      parv[1] = statistics selector (defaults to Message frequency)
1498 + *      parv[2] = server name (current server defaulted, if omitted)
1499 + */
1500 + static void
1501 + ms_stats(struct Client *client_p, struct Client *source_p,
1502 +         int parc, char *parv[])
1503 + {
1504 +  if (hunt_server(client_p, source_p, ":%s STATS %s :%s", 2,
1505 +                  parc, parv) != HUNTED_ISME)
1506 +    return;
1507 +
1508 +  if (IsClient(source_p))
1509 +    mo_stats(client_p, source_p, parc, parv);
1510 + }
1511 +
1512 + static struct Message stats_msgtab = {
1513 +  "STATS", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
1514 +  { m_unregistered, m_stats, ms_stats, m_ignore, mo_stats, m_ignore }
1515 + };
1516 +
1517 + static void
1518 + module_init(void)
1519 + {
1520 +  mod_add_cmd(&stats_msgtab);
1521 + }
1522 +
1523 + static void
1524 + module_exit(void)
1525 + {
1526 +  mod_del_cmd(&stats_msgtab);
1527 + }
1528 +
1529 + struct module module_entry = {
1530 +  .node    = { NULL, NULL, NULL },
1531 +  .name    = NULL,
1532 +  .version = "$Revision$",
1533 +  .handle  = NULL,
1534 +  .modinit = module_init,
1535 +  .modexit = module_exit,
1536 +  .flags   = 0
1537 + };

Diff Legend

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