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 34 by lusky, Sun Oct 2 21:05:51 2005 UTC vs.
ircd-hybrid/trunk/modules/m_stats.c (file contents), Revision 1628 by michael, Thu Nov 1 21:08:56 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"
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 – };
64 –
65 – #ifndef STATIC_MODULES
66 – const char *_version = "$Revision$";
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
94 –
95 – 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
133 – {
134 –  const unsigned char letter;
135 –  void (*handler)();
136 –  const unsigned int need_oper;
137 –  const unsigned int need_admin;
138 – } stats_cmd_table[] = {
139 –  /* letter     function            need_oper need_admin */
140 –  { 'a',        stats_dns_servers,      1,      1,      },
141 –  { 'A',        stats_dns_servers,      1,      1,      },
142 –  { 'c',        stats_connect,          1,      0,      },
143 –  { 'C',        stats_connect,          1,      0,      },
144 –  { 'd',        stats_tdeny,            1,      0,      },
145 –  { '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,      }
184 – };
52  
53   const char *from, *to;
54  
188 – static void
189 – do_stats(struct Client *source_p, int parc, char **parv)
190 – {
191 –  char statchar = *parv[1];
192 –  int i;
193 –
194 –  if (statchar == '\0')
195 –  {
196 –    sendto_one(source_p, form_str(RPL_ENDOFSTATS),
197 –               from, to, '*');
198 –    return;
199 –  }
200 –
201 –  for (i = 0; stats_cmd_table[i].handler; i++)
202 –  {
203 –    if (stats_cmd_table[i].letter == statchar)
204 –    {
205 –      /* 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 –      }
213 –
214 –      /* Blah, stats L needs the parameters, none of the others do.. */
215 –      if (statchar == 'L' || statchar == 'l')
216 –        stats_cmd_table[i].handler(source_p, parc, parv);
217 –      else
218 –        stats_cmd_table[i].handler(source_p);
219 –
220 –      break;
221 –    }
222 –  }
223 –
224 –  sendto_one(source_p, form_str(RPL_ENDOFSTATS),
225 –             from, to, statchar);
226 – }
227 –
228 – /*
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;
242 –
243 –  /* Is the stats meant for us? */
244 –  if (!ConfigFileEntry.disable_remote)
245 –    if (hunt_server(client_p,source_p,":%s STATS %s :%s",2,parc,parv) != HUNTED_ISME)
246 –      return;
247 –
248 –  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 –  }
258 –
259 –  /* Check the user is actually allowed to do /stats, and isnt flooding */
260 –  if ((last_used + ConfigFileEntry.pace_wait) > CurrentTime)
261 –  {
262 –    sendto_one(source_p,form_str(RPL_LOAD2HI),
263 –               from, to);
264 –    return;
265 –  }
266 –  else
267 –    last_used = CurrentTime;
268 –
269 – #ifdef STATIC_MODULES
270 –  do_stats(source_p, parc, parv);
271 – #else
272 –  execute_callback(stats_cb, source_p, parc, parv);
273 – #endif
274 – }
275 –
276 – /*
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
281 – *
282 – * This will search the tables for the appropriate stats letter,
283 – * if found execute it.  
284 – */
285 – static void
286 – mo_stats(struct Client *client_p, struct Client *source_p,
287 –         int parc, char *parv[])
288 – {
289 –  if (hunt_server(client_p, source_p, ":%s STATS %s :%s", 2,
290 –                  parc, parv) != HUNTED_ISME)
291 –     return;
292 –
293 –  if (!MyClient(source_p) && IsCapable(source_p->from, CAP_TS6) && HasID(source_p))
294 –  {
295 –    from = me.id;
296 –    to = source_p->id;
297 –  }
298 –  else
299 –  {
300 –    from = me.name;
301 –    to = source_p->name;
302 –  }
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
309 – }
310 –
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 316 | 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   {
321 – #ifndef _WIN32
65    struct rusage rus;
66    time_t secs;
67    time_t rup;
# Line 344 | 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 370 | 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);
373 – #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 users_invited_count = 0;  /* users invited */
136 <  int aways_counted = 0;
137 <  int number_ips_stored;        /* number of ip addresses hashed */
138 <
139 <  unsigned long channel_memory = 0;
140 <  size_t channel_ban_memory = 0;
141 <  size_t channel_except_memory = 0;
400 <  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 <  count_whowas_memory(&wwu, &wwm);
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 >
166  
167    DLINK_FOREACH(gptr, global_client_list.head)
168    {
# Line 433 | 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 +      watch_list_entries += dlink_list_length(&target_p->localClient->watches);
176      }
177      else
178        ++remote_client_count;
# Line 440 | Line 180 | count_memory(struct Client *source_p)
180      if (IsClient(target_p))
181      {
182        ++users_counted;
443 –      users_invited_count += dlink_list_length(&target_p->invited);
183  
184 <      if (target_p->away != NULL)
446 <      {
184 >      if (target_p->away[0])
185          ++aways_counted;
448 –        away_memory += strlen(target_p->away) + 1;
449 –      }
186      }
187    }
188  
# Line 455 | 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 <    {
469 <      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;
478 <      }
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 <    {
483 <      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;
492 <      }
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 <    {
497 <      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;
506 <      }
235 >      channel_invex_memory += actualBan->len + 1;
236 >      channel_invex_memory += strlen(actualBan->who) + 1;
237      }
238    }
239  
# Line 512 | 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 537 | Line 267 | count_memory(struct Client *source_p)
267    /* count up all classes */
268    class_count = dlink_list_length(&class_items);
269  
270 <  sendto_one(source_p, ":%s %d %s z :Clients %u(%lu) Invites %u(%lu)",
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(%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 <             (unsigned long)(users_counted * sizeof(struct Client)),
543 <             users_invited_count, (unsigned long)(users_invited_count * sizeof(dlink_node)));
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(%lu)",
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)));
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
289 >             (unsigned long long)(local_client_conf_count * sizeof(dlink_node)));
290  
291 <  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) invite %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 *
324 <             sizeof(dlink_node));
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) +
328 <                         channel_invites * sizeof(dlink_node);
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;
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();
343  
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 – ****/
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;
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);
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 666 | 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 678 | 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   {
683 –  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;
411  
412          /* dont report a tdline as a dline */
413 <        if (aconf->flags & CONF_FLAGS_TEMPORARY)
413 >        if (aconf->hold)
414            continue;
415  
416          conf = unmap_conf_item(aconf);
417  
418          sendto_one(source_p, form_str(RPL_STATSDLINE),
419 <                   from, to, 'D', aconf->host, aconf->reason,
704 <                   aconf->oper_reason);
419 >                   from, to, 'D', aconf->host, aconf->reason);
420        }
421      }
422    }
# Line 714 | Line 429 | stats_deny(struct Client *source_p)
429   * side effects - client is given dline list.
430   */
431   static void
432 < stats_tdeny(struct Client *source_p)
432 > stats_tdeny(struct Client *source_p, int parc, char *parv[])
433   {
719 –  struct AddressRec *arec;
434    struct ConfItem *conf;
435    struct AccessItem *aconf;
436 <  int i;
436 >  dlink_node *ptr = NULL;
437 >  unsigned int i = 0;
438  
439 <  for (i = 0; i < ATABLE_SIZE; i++)
439 >
440 >  for (i = 0; i < ATABLE_SIZE; ++i)
441    {
442 <    for (arec = atable[i]; arec; arec=arec->next)
442 >    DLINK_FOREACH(ptr, atable[i].head)
443      {
444 +      struct AddressRec *arec = ptr->data;
445 +
446        if (arec->type == CONF_DLINE)
447        {
448          aconf = arec->aconf;
449  
450          /* dont report a permanent dline as a tdline */
451 <        if (!(aconf->flags & CONF_FLAGS_TEMPORARY))
451 >        if (!aconf->hold)
452            continue;
453  
454          conf = unmap_conf_item(aconf);
455  
456          sendto_one(source_p, form_str(RPL_STATSDLINE),
457 <                   from, to, 'd', aconf->host, aconf->reason,
740 <                   aconf->oper_reason);
457 >                   from, to, 'd', aconf->host, aconf->reason);
458        }
459      }
460    }
# Line 750 | Line 467 | stats_tdeny(struct Client *source_p)
467   * side effects - client is given list of exempt blocks
468   */
469   static void
470 < stats_exempt(struct Client *source_p)
470 > stats_exempt(struct Client *source_p, int parc, char *parv[])
471   {
755 –  struct AddressRec *arec;
472    struct ConfItem *conf;
473    struct AccessItem *aconf;
474 <  int i;
474 >  dlink_node *ptr = NULL;
475 >  unsigned int i = 0;
476  
477 <  for (i = 0; i < ATABLE_SIZE; i++)
477 >  if (ConfigFileEntry.stats_e_disabled)
478    {
479 <    for (arec = atable[i]; arec; arec=arec->next)
479 >    sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
480 >               from, to);
481 >    return;
482 >  }
483 >
484 >
485 >  for (i = 0; i < ATABLE_SIZE; ++i)
486 >  {
487 >    DLINK_FOREACH(ptr, atable[i].head)
488      {
489 +      struct AddressRec *arec = ptr->data;
490 +
491        if (arec->type == CONF_EXEMPTDLINE)
492        {
493          aconf = arec->aconf;
# Line 769 | Line 496 | stats_exempt(struct Client *source_p)
496  
497          sendto_one(source_p, form_str(RPL_STATSDLINE),
498                     from, to, 'e', aconf->host,
499 <                   aconf->reason, aconf->oper_reason);
499 >                   aconf->reason);
500        }
501      }
502    }
503   }
504  
505   static void
506 < stats_events(struct Client *source_p)
506 > stats_events(struct Client *source_p, int parc, char *parv[])
507   {
508    show_events(source_p);
509   }
# Line 788 | Line 515 | stats_events(struct Client *source_p)
515   * side effects - client is shown list of pending glines
516   */
517   static void
518 < stats_pending_glines(struct Client *source_p)
518 > stats_pending_glines(struct Client *source_p, int parc, char *parv[])
519   {
520 < #ifdef GLINE_VOTING
521 <  dlink_node *pending_node;
522 <  struct gline_pending *glp_ptr;
523 <  char timebuffer[MAX_DATE_STRING];
797 <  struct tm *tmptr;
520 >  const dlink_node *dn_ptr = NULL;
521 >  const struct gline_pending *glp_ptr = NULL;
522 >  char timebuffer[MAX_DATE_STRING] = { '\0' };
523 >  struct tm *tmptr = NULL;
524  
525    if (!ConfigFileEntry.glines)
526    {
# Line 803 | Line 529 | stats_pending_glines(struct Client *sour
529      return;
530    }
531  
532 <  if (dlink_list_length(&pending_glines) > 0)
532 >  if (dlink_list_length(&pending_glines[GLINE_PENDING_ADD_TYPE]) > 0)
533      sendto_one(source_p, ":%s NOTICE %s :Pending G-lines",
534                 from, to);
535  
536 <  DLINK_FOREACH(pending_node, pending_glines.head)
536 >  DLINK_FOREACH(dn_ptr, pending_glines[GLINE_PENDING_ADD_TYPE].head)
537    {
538 <    glp_ptr = pending_node->data;
539 <    tmptr   = localtime(&glp_ptr->time_request1);
538 >    glp_ptr = dn_ptr->data;
539 >    tmptr   = localtime(&glp_ptr->vote_1.time_request);
540      strftime(timebuffer, MAX_DATE_STRING, "%Y/%m/%d %H:%M:%S", tmptr);
541  
542      sendto_one(source_p,
543                 ":%s NOTICE %s :1) %s!%s@%s on %s requested gline at %s for %s@%s [%s]",
544 <               from, to, glp_ptr->oper_nick1,
545 <               glp_ptr->oper_user1, glp_ptr->oper_host1,
546 <               glp_ptr->oper_server1, timebuffer,
547 <               glp_ptr->user, glp_ptr->host, glp_ptr->reason1);
544 >               from, to, glp_ptr->vote_1.oper_nick,
545 >               glp_ptr->vote_1.oper_user, glp_ptr->vote_1.oper_host,
546 >               glp_ptr->vote_1.oper_server, timebuffer,
547 >               glp_ptr->user, glp_ptr->host, glp_ptr->vote_1.reason);
548  
549 <    if (glp_ptr->oper_nick2[0] != '\0')
549 >    if (glp_ptr->vote_2.oper_nick[0] != '\0')
550      {
551 <      tmptr = localtime(&glp_ptr->time_request2);
551 >      tmptr = localtime(&glp_ptr->vote_2.time_request);
552        strftime(timebuffer, MAX_DATE_STRING, "%Y/%m/%d %H:%M:%S", tmptr);
553        sendto_one(source_p,
554        ":%s NOTICE %s :2) %s!%s@%s on %s requested gline at %s for %s@%s [%s]",
555 <                 from, to, glp_ptr->oper_nick2,
556 <                 glp_ptr->oper_user2, glp_ptr->oper_host2,
557 <                 glp_ptr->oper_server2, timebuffer,
558 <                 glp_ptr->user, glp_ptr->host, glp_ptr->reason2);
555 >               from, to, glp_ptr->vote_2.oper_nick,
556 >               glp_ptr->vote_2.oper_user, glp_ptr->vote_2.oper_host,
557 >               glp_ptr->vote_2.oper_server, timebuffer,
558 >               glp_ptr->user, glp_ptr->host, glp_ptr->vote_2.reason);
559      }
560    }
561  
562    sendto_one(source_p, ":%s NOTICE %s :End of Pending G-lines",
563               from, to);
564 < #else
565 <  sendto_one(source_p, ":%s NOTICE %s :This server does not support G-Line voting",
564 >
565 >  if (dlink_list_length(&pending_glines[GLINE_PENDING_DEL_TYPE]) > 0)
566 >    sendto_one(source_p, ":%s NOTICE %s :Pending UNG-lines",
567 >               from, to);
568 >
569 >  DLINK_FOREACH(dn_ptr, pending_glines[GLINE_PENDING_DEL_TYPE].head)
570 >  {
571 >    glp_ptr = dn_ptr->data;
572 >    tmptr   = localtime(&glp_ptr->vote_1.time_request);
573 >    strftime(timebuffer, MAX_DATE_STRING, "%Y/%m/%d %H:%M:%S", tmptr);
574 >
575 >    sendto_one(source_p,
576 >               ":%s NOTICE %s :1) %s!%s@%s on %s requested ungline at %s for %s@%s [%s]",
577 >               from, to, glp_ptr->vote_1.oper_nick,
578 >               glp_ptr->vote_1.oper_user, glp_ptr->vote_1.oper_host,
579 >               glp_ptr->vote_1.oper_server, timebuffer,
580 >               glp_ptr->user, glp_ptr->host, glp_ptr->vote_1.reason);
581 >
582 >    if (glp_ptr->vote_2.oper_nick[0] != '\0')
583 >    {
584 >      tmptr = localtime(&glp_ptr->vote_2.time_request);
585 >      strftime(timebuffer, MAX_DATE_STRING, "%Y/%m/%d %H:%M:%S", tmptr);
586 >      sendto_one(source_p,
587 >      ":%s NOTICE %s :2) %s!%s@%s on %s requested ungline at %s for %s@%s [%s]",
588 >               from, to, glp_ptr->vote_2.oper_nick,
589 >               glp_ptr->vote_2.oper_user, glp_ptr->vote_2.oper_host,
590 >               glp_ptr->vote_2.oper_server, timebuffer,
591 >               glp_ptr->user, glp_ptr->host, glp_ptr->vote_2.reason);
592 >
593 >    }
594 >  }
595 >
596 >  sendto_one(source_p, ":%s NOTICE %s :End of Pending UNG-lines",
597               from, to);
841 – #endif /* GLINE VOTING */
598   }
599  
600   /* stats_glines()
# Line 848 | Line 604 | stats_pending_glines(struct Client *sour
604   * side effects - client is shown list of glines
605   */
606   static void
607 < stats_glines(struct Client *source_p)
607 > stats_glines(struct Client *source_p, int parc, char *parv[])
608   {
609 <  struct AddressRec *arec = NULL;
610 <  int i = 0;
609 >  dlink_node *ptr = NULL;
610 >  unsigned int i = 0;
611  
612    if (!ConfigFileEntry.glines)
613    {
# Line 860 | Line 616 | stats_glines(struct Client *source_p)
616      return;
617    }
618  
619 <  for (; i < ATABLE_SIZE; ++i)
619 >  for (i = 0; i < ATABLE_SIZE; ++i)
620    {
621 <    for (arec = atable[i]; arec; arec=arec->next)
621 >    DLINK_FOREACH(ptr, atable[i].head)
622      {
623 +      const struct AddressRec *arec = ptr->data;
624 +
625        if (arec->type == CONF_GLINE)
626        {
627          const struct AccessItem *aconf = arec->aconf;
# Line 872 | Line 630 | stats_glines(struct Client *source_p)
630                     from, to, "G",
631                     aconf->host ? aconf->host : "*",
632                     aconf->user ? aconf->user : "*",
633 <                   aconf->reason ? aconf->reason : "No reason", "" );
633 >                   aconf->reason ? aconf->reason : "No reason");
634        }
635      }
636    }
637   }
638  
639 < /* stats_gdeny()
639 > static void
640 > stats_hubleaf(struct Client *source_p, int parc, char *parv[])
641 > {
642 >  report_confitem_types(source_p, HUB_TYPE);
643 >  report_confitem_types(source_p, LEAF_TYPE);
644 > }
645 >
646 > /*
647 > * show_iline_prefix()
648   *
649 < * input        - client pointer
650 < * outputs      - none
651 < * side effects - client is shown gline ACL
649 > * inputs       - pointer to struct Client requesting output
650 > *              - pointer to struct AccessItem
651 > *              - name to which iline prefix will be prefixed to
652 > * output       - pointer to static string with prefixes listed in ascii form
653 > * side effects - NONE
654   */
655 < static void
656 < stats_gdeny(struct Client *source_p)
655 > static const char *
656 > show_iline_prefix(struct Client *sptr, struct AccessItem *aconf, const char *name)
657   {
658 <  if (!ConfigFileEntry.glines)
659 <  {
892 <    sendto_one(source_p, ":%s NOTICE %s :This server does not support G-Lines",
893 <               from, to);
894 <    return;
895 <  }
658 >  static char prefix_of_host[USERLEN + 14];
659 >  char *prefix_ptr = prefix_of_host;
660  
661 <  report_confitem_types(source_p, GDENY_TYPE, 0);
661 >  if (IsNoTilde(aconf))
662 >    *prefix_ptr++ = '-';
663 >  if (IsLimitIp(aconf))
664 >    *prefix_ptr++ = '!';
665 >  if (IsNeedIdentd(aconf))
666 >    *prefix_ptr++ = '+';
667 >  if (!IsNeedPassword(aconf))
668 >    *prefix_ptr++ = '&';
669 >  if (IsConfExemptResv(aconf))
670 >    *prefix_ptr++ = '$';
671 >  if (IsNoMatchIp(aconf))
672 >    *prefix_ptr++ = '%';
673 >  if (IsConfDoSpoofIp(aconf))
674 >    *prefix_ptr++ = '=';
675 >  if (MyOper(sptr) && IsConfExemptKline(aconf))
676 >    *prefix_ptr++ = '^';
677 >  if (MyOper(sptr) && IsConfExemptGline(aconf))
678 >    *prefix_ptr++ = '_';
679 >  if (MyOper(sptr) && IsConfExemptLimits(aconf))
680 >    *prefix_ptr++ = '>';
681 >  if (IsConfCanFlood(aconf))
682 >    *prefix_ptr++ = '|';
683 >
684 >  strlcpy(prefix_ptr, name, USERLEN+1);
685 >
686 >  return prefix_of_host;
687   }
688  
689   static void
690 < stats_hubleaf(struct Client *source_p)
690 > report_auth(struct Client *client_p, int parc, char *parv[])
691   {
692 <  report_confitem_types(source_p, HUB_TYPE, 0);
693 <  report_confitem_types(source_p, LEAF_TYPE, 0);
692 >  struct ConfItem *conf;
693 >  struct AccessItem *aconf;
694 >  dlink_node *ptr = NULL;
695 >  unsigned int i;
696 >
697 >
698 >  for (i = 0; i < ATABLE_SIZE; ++i)
699 >  {
700 >    DLINK_FOREACH(ptr, atable[i].head)
701 >    {
702 >      struct AddressRec *arec = ptr->data;
703 >
704 >      if (arec->type == CONF_CLIENT)
705 >      {
706 >        aconf = arec->aconf;
707 >
708 >        if (!MyOper(client_p) && IsConfDoSpoofIp(aconf))
709 >          continue;
710 >
711 >        conf = unmap_conf_item(aconf);
712 >
713 >        /* We are doing a partial list, based on what matches the u@h of the
714 >         * sender, so prepare the strings for comparing --fl_
715 >         */
716 >        if (ConfigFileEntry.hide_spoof_ips)
717 >          sendto_one(client_p, form_str(RPL_STATSILINE), me.name,
718 >                     client_p->name, 'I',
719 >                     conf->name == NULL ? "*" : conf->name,
720 >                     show_iline_prefix(client_p, aconf, aconf->user),
721 >                     IsConfDoSpoofIp(aconf) ? "255.255.255.255" :
722 >                     aconf->host, aconf->port,
723 >                     aconf->class_ptr ? aconf->class_ptr->name : "<default>");
724 >
725 >        else
726 >          sendto_one(client_p, form_str(RPL_STATSILINE), me.name,
727 >                     client_p->name, 'I',
728 >                     conf->name == NULL ? "*" : conf->name,
729 >                     show_iline_prefix(client_p, aconf, aconf->user),
730 >                     aconf->host, aconf->port,
731 >                     aconf->class_ptr ? aconf->class_ptr->name : "<default>");
732 >      }
733 >    }
734 >  }
735   }
736  
737   static void
738 < stats_auth(struct Client *source_p)
738 > stats_auth(struct Client *source_p, int parc, char *parv[])
739   {
740    /* Oper only, if unopered, return ERR_NOPRIVILEGES */
741 <  if ((ConfigFileEntry.stats_i_oper_only == 2) && !IsOper(source_p))
741 >  if ((ConfigFileEntry.stats_i_oper_only == 2) && !HasUMode(source_p, UMODE_OPER))
742      sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
743                 from, to);
744  
745    /* If unopered, Only return matching auth blocks */
746 <  else if ((ConfigFileEntry.stats_i_oper_only == 1) && !IsOper(source_p))
746 >  else if ((ConfigFileEntry.stats_i_oper_only == 1) && !HasUMode(source_p, UMODE_OPER))
747    {
748      struct ConfItem *conf;
749      struct AccessItem *aconf;
# Line 924 | Line 754 | stats_auth(struct Client *source_p)
754                                     CONF_CLIENT,
755                                     source_p->localClient->aftype,
756                                     source_p->username,
757 <                                   source_p->localClient->passwd);
757 >                                   source_p->localClient->passwd, 1);
758      else
759        aconf = find_conf_by_address(source_p->host, NULL, CONF_CLIENT,
760 <                                   0, source_p->username, NULL);
760 >                                   0, source_p->username, NULL, 1);
761  
762      if (aconf == NULL)
763        return;
# Line 942 | Line 772 | stats_auth(struct Client *source_p)
772    }
773    /* They are opered, or allowed to see all auth blocks */
774    else
775 <    report_auth(source_p);
775 >    report_auth(source_p, 0, NULL);
776   }
777  
778 + /* report_Klines()
779 + * Inputs: Client to report to,
780 + *         type(==0 for perm, !=0 for temporary)
781 + *         mask
782 + * Output: None
783 + * Side effects: Reports configured K(or k)-lines to client_p.
784 + */
785   static void
786 < stats_tklines(struct Client *source_p)
786 > report_Klines(struct Client *client_p, int tkline)
787 > {
788 >  struct AccessItem *aconf = NULL;
789 >  unsigned int i = 0;
790 >  const char *p = NULL;
791 >  dlink_node *ptr = NULL;
792 >
793 >  if (tkline)
794 >    p = "k";
795 >  else
796 >    p = "K";
797 >
798 >  for (i = 0; i < ATABLE_SIZE; ++i)
799 >  {
800 >    DLINK_FOREACH(ptr, atable[i].head)
801 >    {
802 >      struct AddressRec *arec = ptr->data;
803 >
804 >      if (arec->type == CONF_KLINE)
805 >      {
806 >        aconf = arec->aconf;
807 >
808 >        if (!tkline && aconf->hold)
809 >          continue;
810 >
811 >        if (HasUMode(client_p, UMODE_OPER))
812 >          sendto_one(client_p, form_str(RPL_STATSKLINE), me.name,
813 >                     client_p->name, p, aconf->host, aconf->user,
814 >                     aconf->reason);
815 >        else
816 >          sendto_one(client_p, form_str(RPL_STATSKLINE), me.name,
817 >                     client_p->name, p, aconf->host, aconf->user,
818 >                     aconf->reason);
819 >      }
820 >    }
821 >  }
822 > }
823 >
824 > static void
825 > stats_tklines(struct Client *source_p, int parc, char *parv[])
826   {
951 –  struct ConfItem *conf;
827    /* Oper only, if unopered, return ERR_NOPRIVILEGES */
828 <  if ((ConfigFileEntry.stats_k_oper_only == 2) && !IsOper(source_p))
828 >  if ((ConfigFileEntry.stats_k_oper_only == 2) && !HasUMode(source_p, UMODE_OPER))
829      sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
830                 from, to);
831  
832    /* If unopered, Only return matching klines */
833 <  else if ((ConfigFileEntry.stats_k_oper_only == 1) && !IsOper(source_p))
833 >  else if ((ConfigFileEntry.stats_k_oper_only == 1) && !HasUMode(source_p, UMODE_OPER))
834    {
835 <    struct AccessItem *aconf;
835 >    struct AccessItem *aconf = NULL;
836  
837      if (MyConnect(source_p))
838        aconf = find_conf_by_address(source_p->host,
839                                     &source_p->localClient->ip,
840 <                                   CONF_KILL,
840 >                                   CONF_KLINE,
841                                     source_p->localClient->aftype,
842 <                                   source_p->username, NULL);
842 >                                   source_p->username, NULL, 1);
843      else
844 <      aconf = find_conf_by_address(source_p->host, NULL, CONF_KILL,
845 <                                   0, source_p->username, NULL);
844 >      aconf = find_conf_by_address(source_p->host, NULL, CONF_KLINE,
845 >                                   0, source_p->username, NULL, 1);
846  
847      if (aconf == NULL)
848        return;
849  
850      /* dont report a permanent kline as a tkline */
851 <    if (!(aconf->flags & CONF_FLAGS_TEMPORARY))
851 >    if (!aconf->hold)
852        return;
853  
979 –    conf = unmap_conf_item(aconf);
980 –
854      sendto_one(source_p, form_str(RPL_STATSKLINE), from,
855 <               to, "k", aconf->host, aconf->user, aconf->reason, "");
855 >               to, "k", aconf->host, aconf->user, aconf->reason);
856    }
857    /* Theyre opered, or allowed to see all klines */
858    else {
859      report_Klines(source_p, 1);
987 –    report_confitem_types(source_p, RKLINE_TYPE, 1);
860    }
861   }
862  
863   static void
864 < stats_klines(struct Client *source_p)
864 > stats_klines(struct Client *source_p, int parc, char *parv[])
865   {
866    /* Oper only, if unopered, return ERR_NOPRIVILEGES */
867 <  if ((ConfigFileEntry.stats_k_oper_only == 2) && !IsOper(source_p))
867 >  if ((ConfigFileEntry.stats_k_oper_only == 2) && !HasUMode(source_p, UMODE_OPER))
868      sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
869                 from, to);
870  
871    /* If unopered, Only return matching klines */
872 <  else if ((ConfigFileEntry.stats_k_oper_only == 1) && !IsOper(source_p))
872 >  else if ((ConfigFileEntry.stats_k_oper_only == 1) && !HasUMode(source_p, UMODE_OPER))
873    {
874 <    struct AccessItem *aconf;
874 >    struct AccessItem *aconf = NULL;
875  
876      /* search for a kline */
877 <    if(MyConnect(source_p))
877 >    if (MyConnect(source_p))
878        aconf = find_conf_by_address(source_p->host,
879                                     &source_p->localClient->ip,
880 <                                   CONF_KILL,
880 >                                   CONF_KLINE,
881                                     source_p->localClient->aftype,
882 <                                   source_p->username, NULL);
882 >                                   source_p->username, NULL, 0);
883      else
884 <      aconf = find_conf_by_address(source_p->host, NULL, CONF_KILL,
885 <                                   0, source_p->username, NULL);
884 >      aconf = find_conf_by_address(source_p->host, NULL, CONF_KLINE,
885 >                                   0, source_p->username, NULL, 0);
886  
887 <    if(aconf == NULL)
887 >    if (aconf == NULL)
888        return;
889  
890      /* dont report a tkline as a kline */
891 <    if(aconf->flags & CONF_FLAGS_TEMPORARY)
891 >    if (aconf->hold)
892        return;
893        
894      sendto_one(source_p, form_str(RPL_STATSKLINE), from,
895 <               to, "K", aconf->host, aconf->user, aconf->reason,
1024 <               aconf->oper_reason);
895 >               to, "K", aconf->host, aconf->user, aconf->reason);
896    }
897    /* Theyre opered, or allowed to see all klines */
898    else {
899      report_Klines(source_p, 0);
900 <    report_confitem_types(source_p, RKLINE_TYPE, 0);
900 >    report_confitem_types(source_p, RKLINE_TYPE);
901    }
902   }
903  
904   static void
905 < stats_messages(struct Client *source_p)
905 > stats_messages(struct Client *source_p, int parc, char *parv[])
906   {
907    report_messages(source_p);
908   }
909  
910   static void
911 < stats_oper(struct Client *source_p)
911 > stats_oper(struct Client *source_p, int parc, char *parv[])
912   {
913 <  if (!IsOper(source_p) && ConfigFileEntry.stats_o_oper_only)
913 >  if (!HasUMode(source_p, UMODE_OPER) && ConfigFileEntry.stats_o_oper_only)
914      sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
915                 from, to);
916    else
917 <    report_confitem_types(source_p, OPER_TYPE, 0);
917 >    report_confitem_types(source_p, OPER_TYPE);
918   }
919  
920   /* stats_operedup()
# Line 1053 | Line 924 | stats_oper(struct Client *source_p)
924   * side effects - client is shown a list of active opers
925   */
926   static void
927 < stats_operedup(struct Client *source_p)
927 > stats_operedup(struct Client *source_p, int parc, char *parv[])
928   {
929    dlink_node *ptr;
930  
# Line 1061 | Line 932 | stats_operedup(struct Client *source_p)
932    {
933      const struct Client *target_p = ptr->data;
934  
935 <    if (IsOperHidden(target_p) && !IsOper(source_p))
935 >    if (HasUMode(target_p, UMODE_HIDDEN) && !HasUMode(source_p, UMODE_OPER))
936        continue;
937  
938 <    if (MyClient(source_p) && IsOper(source_p))
938 >    if (MyClient(source_p) && HasUMode(source_p, UMODE_OPER))
939        sendto_one(source_p, ":%s %d %s p :[%c][%s] %s (%s@%s) Idle: %d",
940                   from, RPL_STATSDEBUG, to,
941 <                 IsAdmin(target_p) ?
1071 <                 (IsOperHiddenAdmin(target_p) ? 'O' : 'A') : 'O',
941 >                 HasUMode(target_p, UMODE_ADMIN) ? 'A' : 'O',
942                   oper_privs_as_string(target_p->localClient->operflags),
943                   target_p->name, target_p->username, target_p->host,
944 <                 (int)(CurrentTime - target_p->localClient->last));
944 >                 (int)(CurrentTime - target_p->localClient->last_privmsg));
945      else
946        sendto_one(source_p, ":%s %d %s p :[%c] %s (%s@%s) Idle: %d",
947                   from, RPL_STATSDEBUG, to,
948 <                 IsAdmin(target_p) ?
1079 <                 (IsOperHiddenAdmin(target_p) ? 'O' : 'A') : 'O',
948 >                 HasUMode(target_p, UMODE_ADMIN) ? 'A' : 'O',
949                   target_p->name, target_p->username, target_p->host,
950 <                 (int)(CurrentTime - target_p->localClient->last));
950 >                 (int)(CurrentTime - target_p->localClient->last_privmsg));
951    }
952  
953    sendto_one(source_p, ":%s %d %s p :%lu OPER(s)",
# Line 1086 | Line 955 | stats_operedup(struct Client *source_p)
955   }
956  
957   static void
958 < stats_ports(struct Client *source_p)
958 > stats_ports(struct Client *source_p, int parc, char *parv[])
959   {
960 <  if (!IsOper(source_p) && ConfigFileEntry.stats_P_oper_only)
960 >  if (!HasUMode(source_p, UMODE_OPER) && ConfigFileEntry.stats_P_oper_only)
961      sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
962                 from, to);
963    else
# Line 1096 | Line 965 | stats_ports(struct Client *source_p)
965   }
966  
967   static void
968 < stats_resv(struct Client *source_p)
968 > stats_resv(struct Client *source_p, int parc, char *parv[])
969   {
970    report_resv(source_p);
971   }
972  
973   static void
974 < stats_usage(struct Client *source_p)
974 > stats_service(struct Client *source_p, int parc, char *parv[])
975   {
976 <  send_usage(source_p);
976 >  report_confitem_types(source_p, SERVICE_TYPE);
977   }
978  
979   static void
980 < stats_tstats(struct Client *source_p)
980 > stats_tstats(struct Client *source_p, int parc, char *parv[])
981   {
982 <  tstats(source_p);
982 >  const struct Client *target_p = NULL;
983 >  const dlink_node *ptr = NULL;
984 >  struct ServerStatistics *sp;
985 >  struct ServerStatistics tmp;
986 >
987 >  sp = &tmp;
988 >  memcpy(sp, &ServerStats, sizeof(struct ServerStatistics));
989 >
990 >  /*
991 >   * must use the += operator. is_sv is not the number of currently
992 >   * active server connections. Note the incrementation in
993 >   * s_bsd.c:close_connection.
994 >   */
995 >  sp->is_sv += dlink_list_length(&serv_list);
996 >
997 >  DLINK_FOREACH(ptr, serv_list.head)
998 >  {
999 >    target_p = ptr->data;
1000 >
1001 >    sp->is_sbs += target_p->localClient->send.bytes;
1002 >    sp->is_sbr += target_p->localClient->recv.bytes;
1003 >    sp->is_sti += CurrentTime - target_p->localClient->firsttime;
1004 >  }
1005 >
1006 >  sp->is_cl += dlink_list_length(&local_client_list);
1007 >
1008 >  DLINK_FOREACH(ptr, local_client_list.head)
1009 >  {
1010 >    target_p = ptr->data;
1011 >
1012 >    sp->is_cbs += target_p->localClient->send.bytes;
1013 >    sp->is_cbr += target_p->localClient->recv.bytes;
1014 >    sp->is_cti += CurrentTime - target_p->localClient->firsttime;
1015 >  }
1016 >
1017 >  sp->is_ni += dlink_list_length(&unknown_list);
1018 >
1019 >  sendto_one(source_p, ":%s %d %s T :accepts %u refused %u",
1020 >             me.name, RPL_STATSDEBUG, source_p->name, sp->is_ac, sp->is_ref);
1021 >  sendto_one(source_p, ":%s %d %s T :unknown commands %u prefixes %u",
1022 >             me.name, RPL_STATSDEBUG, source_p->name, sp->is_unco, sp->is_unpf);
1023 >  sendto_one(source_p, ":%s %d %s T :nick collisions %u unknown closes %u",
1024 >             me.name, RPL_STATSDEBUG, source_p->name, sp->is_kill, sp->is_ni);
1025 >  sendto_one(source_p, ":%s %d %s T :wrong direction %u empty %u",
1026 >             me.name, RPL_STATSDEBUG, source_p->name, sp->is_wrdi, sp->is_empt);
1027 >  sendto_one(source_p, ":%s %d %s T :numerics seen %u",
1028 >             me.name, RPL_STATSDEBUG, source_p->name, sp->is_num);
1029 >  sendto_one(source_p, ":%s %d %s T :auth successes %u fails %u",
1030 >             me.name, RPL_STATSDEBUG, source_p->name, sp->is_asuc, sp->is_abad);
1031 >  sendto_one(source_p, ":%s %d %s T :Client Server",
1032 >             me.name, RPL_STATSDEBUG, source_p->name);
1033 >
1034 >  sendto_one(source_p, ":%s %d %s T :connected %u %u",
1035 >             me.name, RPL_STATSDEBUG, source_p->name,
1036 >             (unsigned int)sp->is_cl,
1037 >             (unsigned int)sp->is_sv);
1038 >  sendto_one(source_p, ":%s %d %s T :bytes sent %llu %llu",
1039 >             me.name, RPL_STATSDEBUG, source_p->name,
1040 >             sp->is_cbs, sp->is_sbs);
1041 >  sendto_one(source_p, ":%s %d %s T :bytes recv %llu %llu",
1042 >             me.name, RPL_STATSDEBUG, source_p->name,
1043 >             sp->is_cbr, sp->is_sbr);
1044 >  sendto_one(source_p, ":%s %d %s T :time connected %u %u",
1045 >             me.name, RPL_STATSDEBUG, source_p->name,
1046 >             (unsigned int)sp->is_cti,
1047 >             (unsigned int)sp->is_sti);
1048   }
1049  
1050   static void
1051 < stats_uptime(struct Client *source_p)
1051 > stats_uptime(struct Client *source_p, int parc, char *parv[])
1052   {
1053 <  time_t now = CurrentTime - me.since;
1053 >  time_t now = CurrentTime - me.localClient->since;
1054 >
1055    sendto_one(source_p, form_str(RPL_STATSUPTIME), from, to,
1056 <             now/86400, (now/3600)%24, (now/60)%60, now%60);
1057 <  if (!ConfigFileEntry.disable_remote || IsOper(source_p))
1056 >             now / 86400, (now / 3600) % 24, (now / 60) % 60, now % 60);
1057 >
1058 >  if (!ConfigFileEntry.disable_remote || HasUMode(source_p, UMODE_OPER))
1059       sendto_one(source_p, form_str(RPL_STATSCONN), from, to,
1060 <                MaxConnectionCount, MaxClientCount, Count.totalrestartcount);
1060 >                Count.max_loc_con, Count.max_loc_cli, Count.totalrestartcount);
1061   }
1062  
1063   static void
1064 < stats_shared(struct Client *source_p)
1064 > stats_shared(struct Client *source_p, int parc, char *parv[])
1065   {
1066 <  report_confitem_types(source_p, ULINE_TYPE, 0);
1066 >  report_confitem_types(source_p, ULINE_TYPE);
1067   }
1068  
1069   /* stats_servers()
# Line 1137 | Line 1073 | stats_shared(struct Client *source_p)
1073   * side effects - client is shown lists of who connected servers
1074   */
1075   static void
1076 < stats_servers(struct Client *source_p)
1076 > stats_servers(struct Client *source_p, int parc, char *parv[])
1077   {
1078 <  struct Client *target_p;
1143 <  dlink_node *ptr;
1144 <  int j = 0;
1078 >  dlink_node *ptr = NULL;
1079  
1080    DLINK_FOREACH(ptr, serv_list.head)
1081    {
1082 <    target_p = ptr->data;
1149 <
1150 <    j++;
1082 >    const struct Client *target_p = ptr->data;
1083  
1084      sendto_one(source_p, ":%s %d %s v :%s (%s!%s@%s) Idle: %d",
1085 <               from, RPL_STATSDEBUG, to,
1086 <               target_p->name,
1087 <               (target_p->serv->by[0] ? target_p->serv->by : "Remote."),
1156 <               "*", "*", (int)(CurrentTime - target_p->lasttime));
1085 >               from, RPL_STATSDEBUG, to, target_p->name,
1086 >               (target_p->serv->by[0] ? target_p->serv->by : "Remote."),
1087 >               "*", "*", (int)(CurrentTime - target_p->localClient->lasttime));
1088    }
1089  
1090 <  sendto_one(source_p, ":%s %d %s v :%d Server(s)",
1091 <             from, RPL_STATSDEBUG, to, j);
1161 < }
1162 <
1163 < static void
1164 < stats_gecos(struct Client *source_p)
1165 < {
1166 <  report_confitem_types(source_p, XLINE_TYPE, 0);
1167 <  report_confitem_types(source_p, RXLINE_TYPE, 0);
1090 >  sendto_one(source_p, ":%s %d %s v :%u Server(s)",
1091 >             from, RPL_STATSDEBUG, to, dlink_list_length(&serv_list));
1092   }
1093  
1094   static void
1095 < stats_class(struct Client *source_p)
1095 > stats_gecos(struct Client *source_p, int parc, char *parv[])
1096   {
1097 <  report_confitem_types(source_p, CLASS_TYPE, 0);
1097 >  report_confitem_types(source_p, XLINE_TYPE);
1098 >  report_confitem_types(source_p, RXLINE_TYPE);
1099   }
1100  
1101   static void
1102 < stats_memory(struct Client *source_p)
1102 > stats_class(struct Client *source_p, int parc, char *parv[])
1103   {
1104 <  count_memory(source_p);
1104 >  report_confitem_types(source_p, CLASS_TYPE);
1105   }
1106  
1107   static void
1108 < 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)
1190 <  {
1191 <    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));
1201 <
1202 <      sendto_one(source_p, ":%s %d %s Z :ZipLinks stats for %s send[%.2f%% "
1203 <                 "compression (%lu bytes data/%lu bytes wire)] recv[%.2f%% "
1204 <                 "compression (%lu bytes data/%lu bytes wire)]",
1205 <                 from, RPL_STATSDEBUG, to, target_p->name,
1206 <                 zipstats.out_ratio, zipstats.out, zipstats.out_wire,
1207 <                 zipstats.in_ratio,  zipstats.in,  zipstats.in_wire);
1208 <      ++sent_data;
1209 <    }
1210 <  }
1211 <
1212 <  sendto_one(source_p, ":%s %d %s Z :%u ziplink(s)",
1213 <             from, RPL_STATSDEBUG, to, sent_data);
1214 < }
1215 <
1216 < static void
1217 < stats_servlinks(struct Client *source_p)
1108 > stats_servlinks(struct Client *source_p, int parc, char *parv[])
1109   {
1110    uint64_t sendB = 0, recvB = 0;
1111    time_t uptime = 0;
1112 <  int j = 0;
1222 <  struct Client *target_p = NULL;
1223 <  dlink_node *ptr;
1112 >  dlink_node *ptr = NULL;
1113  
1114 <  if (ConfigServerHide.flatten_links && !IsOper(source_p))
1114 >  if (ConfigServerHide.flatten_links && !HasUMode(source_p, UMODE_OPER))
1115    {
1116      sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
1117                 from, to);
# Line 1231 | Line 1120 | stats_servlinks(struct Client *source_p)
1120  
1121    DLINK_FOREACH(ptr, serv_list.head)
1122    {
1123 <    target_p = ptr->data;
1123 >    struct Client *target_p = ptr->data;
1124  
1236 –    ++j;
1125      sendB += target_p->localClient->send.bytes;
1126      recvB += target_p->localClient->recv.bytes;
1127  
1128      /* ":%s 211 %s %s %u %u %llu %u %llu :%u %u %s" */
1129      sendto_one(source_p, form_str(RPL_STATSLINKINFO),
1130                 from, to,
1131 <               get_client_name(target_p, IsAdmin(source_p) ? SHOW_IP : MASK_IP),
1131 >               get_client_name(target_p, HasUMode(source_p, UMODE_ADMIN) ? SHOW_IP : MASK_IP),
1132                 dbuf_length(&target_p->localClient->buf_sendq),
1133                 target_p->localClient->send.messages,
1134                 target_p->localClient->send.bytes >> 10,
1135                 target_p->localClient->recv.messages,
1136                 target_p->localClient->recv.bytes >> 10,
1137 <               (unsigned)(CurrentTime - target_p->firsttime),
1138 <               (CurrentTime > target_p->since) ? (unsigned)(CurrentTime - target_p->since): 0,
1139 <               IsOper(source_p) ? show_capabilities(target_p) : "TS");
1137 >               (unsigned)(CurrentTime - target_p->localClient->firsttime),
1138 >               (CurrentTime > target_p->localClient->since) ? (unsigned)(CurrentTime - target_p->localClient->since): 0,
1139 >               HasUMode(source_p, UMODE_OPER) ? show_capabilities(target_p) : "TS");
1140    }
1141  
1142    sendB >>= 10;
1143    recvB >>= 10;
1144  
1145    sendto_one(source_p, ":%s %d %s ? :%u total server(s)",
1146 <             from, RPL_STATSDEBUG, to, j);
1146 >             from, RPL_STATSDEBUG, to, dlink_list_length(&serv_list));
1147    sendto_one(source_p, ":%s %d %s ? :Sent total : %7.2f %s",
1148               from, RPL_STATSDEBUG, to,
1149 <             _GMKv((signed)sendB), _GMKs((signed)sendB));
1149 >             _GMKv(sendB), _GMKs(sendB));
1150    sendto_one(source_p, ":%s %d %s ? :Recv total : %7.2f %s",
1151               from, RPL_STATSDEBUG, to,
1152 <             _GMKv((signed)recvB), _GMKs((signed)recvB));
1152 >             _GMKv(recvB), _GMKs(recvB));
1153  
1154 <  uptime = (CurrentTime - me.since);
1154 >  uptime = (CurrentTime - me.localClient->since);
1155  
1156    sendto_one(source_p, ":%s %d %s ? :Server send: %7.2f %s (%4.1f K/s)",
1157               from, RPL_STATSDEBUG, to,
1158 <             _GMKv((signed)(me.localClient->send.bytes>>10)),
1159 <             _GMKs((signed)(me.localClient->send.bytes>>10)),
1160 <             (float)((float)(((signed)me.localClient->send.bytes) >> 10) /
1161 <             (float)uptime));
1158 >             _GMKv((me.localClient->send.bytes>>10)),
1159 >             _GMKs((me.localClient->send.bytes>>10)),
1160 >             (float)((float)((me.localClient->send.bytes) >> 10) /
1161 >             (float)uptime));
1162    sendto_one(source_p, ":%s %d %s ? :Server recv: %7.2f %s (%4.1f K/s)",
1163               from, RPL_STATSDEBUG, to,
1164 <             _GMKv((signed)(me.localClient->recv.bytes>>10)),
1165 <             _GMKs((signed)(me.localClient->recv.bytes>>10)),
1166 <             (float)((float)(((signed)me.localClient->recv.bytes) >> 10) /
1167 <             (float)uptime));
1164 >             _GMKv((me.localClient->recv.bytes>>10)),
1165 >             _GMKs((me.localClient->recv.bytes>>10)),
1166 >             (float)((float)((me.localClient->recv.bytes) >> 10) /
1167 >             (float)uptime));
1168   }
1169  
1170 < static void
1171 < stats_ltrace(struct Client *source_p, int parc, char *parv[])
1170 > /* parse_stats_args()
1171 > *
1172 > * inputs       - arg count
1173 > *              - args
1174 > *              - doall flag
1175 > *              - wild card or not
1176 > * output       - pointer to name to use
1177 > * side effects -
1178 > * common parse routine for m_stats args
1179 > *
1180 > */
1181 > static char *
1182 > parse_stats_args(int parc, char *parv[], int *doall, int *wilds)
1183   {
1184 <  int doall = 0;
1286 <  int wilds = 0;
1287 <  char *name = NULL;
1288 <  char statchar;
1184 >  char *name;
1185  
1186 <  if ((name = parse_stats_args(parc, parv, &doall, &wilds)) != NULL)
1186 >  if (parc > 2)
1187    {
1188 <    statchar = parv[1][0];
1188 >    name = parv[2];
1189  
1190 <    stats_L(source_p, name, doall, wilds, statchar);
1191 <  }
1192 <  else
1193 <    sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
1298 <               from, to, "STATS");
1299 < }
1190 >    if (!irccmp(name, from))
1191 >      *doall = 2;
1192 >    else if (match(name, from))
1193 >      *doall = 1;
1194  
1195 < /*
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;
1195 >    *wilds = has_wildcards(name);
1196  
1197 <  if (IsClient(source_p))
1198 <    mo_stats(client_p, source_p, parc, parv);
1316 < }
1197 >    return name;
1198 >  }
1199  
1200 < /*
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);
1200 >  return NULL;
1201   }
1202  
1203   static void
# Line 1350 | Line 1217 | stats_L_list(struct Client *source_p,cha
1217    {
1218      target_p = ptr->data;
1219  
1220 <    if (IsInvisible(target_p) && (doall || wilds) &&
1221 <        !(MyConnect(source_p) && IsOper(source_p)) &&
1222 <        !IsOper(target_p) && (target_p != source_p))
1220 >    if (HasUMode(target_p, UMODE_INVISIBLE) && (doall || wilds) &&
1221 >        !(MyConnect(source_p) && HasUMode(source_p, UMODE_OPER)) &&
1222 >        !HasUMode(target_p, UMODE_OPER) && (target_p != source_p))
1223        continue;
1224      if (!doall && wilds && !match(name, target_p->name))
1225        continue;
# Line 1361 | Line 1228 | stats_L_list(struct Client *source_p,cha
1228  
1229      /* This basically shows ips for our opers if its not a server/admin, or
1230       * its one of our admins.  */
1231 <    if(MyClient(source_p) && IsOper(source_p) &&
1232 <       (IsAdmin(source_p) ||
1233 <       (!IsServer(target_p) && !IsAdmin(target_p) &&
1231 >    if(MyClient(source_p) && HasUMode(source_p, UMODE_OPER) &&
1232 >       (HasUMode(source_p, UMODE_ADMIN) ||
1233 >       (!IsServer(target_p) && !HasUMode(target_p, UMODE_ADMIN) &&
1234         !IsHandshake(target_p) && !IsConnecting(target_p))))
1235      {
1236        sendto_one(source_p, form_str(RPL_STATSLINKINFO),
1237 <                 from, to,
1237 >                 from, to,
1238                   (IsUpper(statchar)) ?
1239                   get_client_name(target_p, SHOW_IP) :
1240                   get_client_name(target_p, HIDE_IP),
# Line 1376 | Line 1243 | stats_L_list(struct Client *source_p,cha
1243                   target_p->localClient->send.bytes>>10,
1244                   target_p->localClient->recv.messages,
1245                   target_p->localClient->recv.bytes>>10,
1246 <                 (unsigned)(CurrentTime - target_p->firsttime),
1247 <                 (CurrentTime > target_p->since) ? (unsigned)(CurrentTime - target_p->since):0,
1246 >                 (unsigned)(CurrentTime - target_p->localClient->firsttime),
1247 >                 (CurrentTime > target_p->localClient->since) ? (unsigned)(CurrentTime - target_p->localClient->since):0,
1248                   IsServer(target_p) ? show_capabilities(target_p) : "-");
1249      }
1250      else
1251      {
1252        /* If its a hidden ip, an admin, or a server, mask the real IP */
1253 <      if(IsIPSpoof(target_p) || IsServer(target_p) || IsAdmin(target_p)
1253 >      if(IsIPSpoof(target_p) || IsServer(target_p) || HasUMode(target_p, UMODE_ADMIN)
1254           || IsHandshake(target_p) || IsConnecting(target_p))
1255          sendto_one(source_p, form_str(RPL_STATSLINKINFO),
1256                     from, to,
1257 <                   get_client_name(target_p, MASK_IP),
1258 <                   dbuf_length(&target_p->localClient->buf_sendq),
1259 <                   target_p->localClient->send.messages,
1260 <                   target_p->localClient->send.bytes>>10,
1261 <                   target_p->localClient->recv.messages,
1262 <                   target_p->localClient->recv.bytes>>10,
1263 <                   (unsigned)(CurrentTime - target_p->firsttime),
1264 <                   (CurrentTime > target_p->since) ? (unsigned)(CurrentTime - target_p->since):0,
1265 <                   IsServer(target_p) ? show_capabilities(target_p) : "-");
1257 >                   get_client_name(target_p, MASK_IP),
1258 >                   dbuf_length(&target_p->localClient->buf_sendq),
1259 >                   target_p->localClient->send.messages,
1260 >                   target_p->localClient->send.bytes>>10,
1261 >                   target_p->localClient->recv.messages,
1262 >                   target_p->localClient->recv.bytes>>10,
1263 >                   (unsigned)(CurrentTime - target_p->localClient->firsttime),
1264 >                   (CurrentTime > target_p->localClient->since) ? (unsigned)(CurrentTime - target_p->localClient->since):0,
1265 >                   IsServer(target_p) ? show_capabilities(target_p) : "-");
1266        else /* show the real IP */
1267          sendto_one(source_p, form_str(RPL_STATSLINKINFO),
1268                     from, to,
1269 <                   (IsUpper(statchar)) ?
1270 <                   get_client_name(target_p, SHOW_IP) :
1271 <                   get_client_name(target_p, HIDE_IP),
1272 <                   dbuf_length(&target_p->localClient->buf_sendq),
1273 <                   target_p->localClient->send.messages,
1274 <                   target_p->localClient->send.bytes>>10,
1275 <                   target_p->localClient->recv.messages,
1276 <                   target_p->localClient->recv.bytes>>10,
1277 <                   (unsigned)(CurrentTime - target_p->firsttime),
1278 <                   (CurrentTime > target_p->since) ? (unsigned)(CurrentTime - target_p->since):0,
1279 <                   IsServer(target_p) ? show_capabilities(target_p) : "-");
1269 >                   (IsUpper(statchar)) ?
1270 >                   get_client_name(target_p, SHOW_IP) :
1271 >                   get_client_name(target_p, HIDE_IP),
1272 >                   dbuf_length(&target_p->localClient->buf_sendq),
1273 >                   target_p->localClient->send.messages,
1274 >                   target_p->localClient->send.bytes>>10,
1275 >                   target_p->localClient->recv.messages,
1276 >                   target_p->localClient->recv.bytes>>10,
1277 >                   (unsigned)(CurrentTime - target_p->localClient->firsttime),
1278 >                   (CurrentTime > target_p->localClient->since) ? (unsigned)(CurrentTime - target_p->localClient->since):0,
1279 >                   IsServer(target_p) ? show_capabilities(target_p) : "-");
1280      }
1281    }
1282   }
1283  
1284 < /* parse_stats_args()
1284 > /*
1285 > * stats_L
1286   *
1287 < * inputs       - arg count
1288 < *              - args
1289 < *              - doall flag
1290 < *              - wild card or not
1291 < * output       - pointer to name to use
1292 < * side effects -
1293 < * common parse routine for m_stats args
1287 > * inputs       - pointer to client to report to
1288 > *              - doall flag
1289 > *              - wild card or not
1290 > * output       - NONE
1291 > * side effects -
1292 > */
1293 > static void
1294 > stats_L(struct Client *source_p,char *name,int doall,
1295 >        int wilds,char statchar)
1296 > {
1297 >  stats_L_list(source_p, name, doall, wilds, &unknown_list, statchar);
1298 >  stats_L_list(source_p, name, doall, wilds, &local_client_list, statchar);
1299 >  stats_L_list(source_p, name, doall, wilds, &serv_list, statchar);
1300 > }
1301 >
1302 > static void
1303 > stats_ltrace(struct Client *source_p, int parc, char *parv[])
1304 > {
1305 >  int doall = 0;
1306 >  int wilds = 0;
1307 >  char *name = NULL;
1308 >  char statchar;
1309 >
1310 >  if ((name = parse_stats_args(parc, parv, &doall, &wilds)) != NULL)
1311 >  {
1312 >    statchar = parv[1][0];
1313 >
1314 >    stats_L(source_p, name, doall, wilds, statchar);
1315 >  }
1316 >  else
1317 >    sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
1318 >               from, to, "STATS");
1319 > }
1320 >
1321 > static const struct StatsStruct
1322 > {
1323 >  const unsigned char letter;
1324 >  void (*handler)();
1325 >  const unsigned int need_oper;
1326 >  const unsigned int need_admin;
1327 > } stats_cmd_table[] = {
1328 >  /* letter     function            need_oper need_admin */
1329 >  { 'a',        stats_dns_servers,      1,      1       },
1330 >  { 'A',        stats_dns_servers,      1,      1       },
1331 >  { 'c',        stats_connect,          1,      0       },
1332 >  { 'C',        stats_connect,          1,      0       },
1333 >  { 'd',        stats_tdeny,            1,      0       },
1334 >  { 'D',        stats_deny,             1,      0       },
1335 >  { 'e',        stats_exempt,           1,      0       },
1336 >  { 'E',        stats_events,           1,      1       },
1337 >  { 'f',        fd_dump,                1,      1       },
1338 >  { 'F',        fd_dump,                1,      1       },
1339 >  { 'g',        stats_pending_glines,   1,      0       },
1340 >  { 'G',        stats_glines,           1,      0       },
1341 >  { 'h',        stats_hooks,            1,      1       },
1342 >  { 'H',        stats_hubleaf,          1,      0       },
1343 >  { 'i',        stats_auth,             0,      0       },
1344 >  { 'I',        stats_auth,             0,      0       },
1345 >  { 'k',        stats_tklines,          0,      0       },
1346 >  { 'K',        stats_klines,           0,      0       },
1347 >  { 'l',        stats_ltrace,           1,      0       },
1348 >  { 'L',        stats_ltrace,           1,      0       },
1349 >  { 'm',        stats_messages,         0,      0       },
1350 >  { 'M',        stats_messages,         0,      0       },
1351 >  { 'o',        stats_oper,             0,      0       },
1352 >  { 'O',        stats_oper,             0,      0       },
1353 >  { 'p',        stats_operedup,         0,      0       },
1354 >  { 'P',        stats_ports,            0,      0       },
1355 >  { 'q',        stats_resv,             1,      0       },
1356 >  { 'Q',        stats_resv,             1,      0       },
1357 >  { 'r',        stats_usage,            1,      0       },
1358 >  { 'R',        stats_usage,            1,      0       },
1359 >  { 'S',        stats_service,          1,      0       },
1360 >  { 't',        stats_tstats,           1,      0       },
1361 >  { 'T',        stats_tstats,           1,      0       },
1362 >  { 'u',        stats_uptime,           0,      0       },
1363 >  { 'U',        stats_shared,           1,      0       },
1364 >  { 'v',        stats_servers,          1,      0       },
1365 >  { 'x',        stats_gecos,            1,      0       },
1366 >  { 'X',        stats_gecos,            1,      0       },
1367 >  { 'y',        stats_class,            1,      0       },
1368 >  { 'Y',        stats_class,            1,      0       },
1369 >  { 'z',        stats_memory,           1,      0       },
1370 >  { '?',        stats_servlinks,        0,      0       },
1371 >  { '\0',       NULL,                   0,      0       }
1372 > };
1373 >
1374 > static void
1375 > do_stats(struct Client *source_p, int parc, char *parv[])
1376 > {
1377 >  const struct StatsStruct *tab = stats_cmd_table;
1378 >  const char statchar = *parv[1];
1379 >
1380 >  if (statchar == '\0')
1381 >  {
1382 >    sendto_one(source_p, form_str(RPL_ENDOFSTATS),
1383 >               from, to, '*');
1384 >    return;
1385 >  }
1386 >
1387 >  for (; tab->handler; ++tab)
1388 >  {
1389 >    if (tab->letter == statchar)
1390 >    {
1391 >      /* The stats table says what privs are needed, so check --fl_ */
1392 >      if ((tab->need_admin && !HasUMode(source_p, UMODE_ADMIN)) ||
1393 >          (tab->need_oper && !HasUMode(source_p, UMODE_OPER)))
1394 >      {
1395 >        sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
1396 >                   from, to);
1397 >        break;
1398 >      }
1399 >
1400 >      sendto_realops_flags(UMODE_SPY, L_ALL, SEND_NOTICE,
1401 >                           "STATS %c requested by %s (%s@%s) [%s]",
1402 >                           statchar, source_p->name, source_p->username,
1403 >                           source_p->host, source_p->servptr->name);
1404 >      tab->handler(source_p, parc, parv);
1405 >      break;
1406 >    }
1407 >  }
1408 >
1409 >  sendto_one(source_p, form_str(RPL_ENDOFSTATS),
1410 >             from, to, statchar);
1411 > }
1412 >
1413 > /*
1414 > * m_stats()
1415 > *      parv[0] = sender prefix
1416 > *      parv[1] = stat letter/command
1417 > *      parv[2] = (if present) server/mask in stats L
1418   *
1419 + * This will search the tables for the appropriate stats letter/command,
1420 + * if found execute it.  
1421   */
1422 < static char *
1423 < parse_stats_args(int parc, char *parv[], int *doall, int *wilds)
1422 > static void
1423 > m_stats(struct Client *client_p, struct Client *source_p,
1424 >        int parc, char *parv[])
1425   {
1426 <  char *name;
1426 >  static time_t last_used = 0;
1427  
1428 <  if (parc > 2)
1428 >  /* Is the stats meant for us? */
1429 >  if (!ConfigFileEntry.disable_remote)
1430 >    if (hunt_server(client_p, source_p, ":%s STATS %s :%s", 2,
1431 >                    parc, parv) != HUNTED_ISME)
1432 >      return;
1433 >
1434 >  if (!MyClient(source_p) && IsCapable(source_p->from, CAP_TS6) && HasID(source_p))
1435    {
1436 <    name = parv[2];
1436 >    from = me.id;
1437 >    to = source_p->id;
1438 >  }
1439 >  else
1440 >  {
1441 >    from = me.name;
1442 >    to = source_p->name;
1443 >  }
1444  
1445 <    if (!irccmp(name, from))
1446 <      *doall = 2;
1447 <    else if (match(name, from))
1448 <      *doall = 1;
1445 >  /* Check the user is actually allowed to do /stats, and isnt flooding */
1446 >  if ((last_used + ConfigFileEntry.pace_wait) > CurrentTime)
1447 >  {
1448 >    sendto_one(source_p,form_str(RPL_LOAD2HI),
1449 >               from, to);
1450 >    return;
1451 >  }
1452 >
1453 >  last_used = CurrentTime;
1454  
1455 <    if (strchr(name, '*') ||
1456 <        strchr(name, '?'))
1444 <      *wilds = 1;
1455 >  do_stats(source_p, parc, parv);
1456 > }
1457  
1458 <    return(name);
1458 > /*
1459 > * mo_stats()
1460 > *      parv[0] = sender prefix
1461 > *      parv[1] = stat letter/command
1462 > *      parv[2] = (if present) server/mask in stats L, or target
1463 > *
1464 > * This will search the tables for the appropriate stats letter,
1465 > * if found execute it.  
1466 > */
1467 > static void
1468 > mo_stats(struct Client *client_p, struct Client *source_p,
1469 >         int parc, char *parv[])
1470 > {
1471 >  if (hunt_server(client_p, source_p, ":%s STATS %s :%s", 2,
1472 >                  parc, parv) != HUNTED_ISME)
1473 >     return;
1474 >
1475 >  if (!MyClient(source_p) && IsCapable(source_p->from, CAP_TS6) && HasID(source_p))
1476 >  {
1477 >    from = me.id;
1478 >    to = source_p->id;
1479    }
1480    else
1481 <    return(NULL);
1481 >  {
1482 >    from = me.name;
1483 >    to = source_p->name;
1484 >  }
1485 >
1486 >  do_stats(source_p, parc, parv);
1487   }
1488 +
1489 + /*
1490 + * ms_stats - STATS message handler
1491 + *      parv[0] = sender prefix
1492 + *      parv[1] = statistics selector (defaults to Message frequency)
1493 + *      parv[2] = server name (current server defaulted, if omitted)
1494 + */
1495 + static void
1496 + ms_stats(struct Client *client_p, struct Client *source_p,
1497 +         int parc, char *parv[])
1498 + {
1499 +  if (hunt_server(client_p, source_p, ":%s STATS %s :%s", 2,
1500 +                  parc, parv) != HUNTED_ISME)
1501 +    return;
1502 +
1503 +  if (IsClient(source_p))
1504 +    mo_stats(client_p, source_p, parc, parv);
1505 + }
1506 +
1507 + static struct Message stats_msgtab = {
1508 +  "STATS", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
1509 +  { m_unregistered, m_stats, ms_stats, m_ignore, mo_stats, m_ignore }
1510 + };
1511 +
1512 + static void
1513 + module_init(void)
1514 + {
1515 +  mod_add_cmd(&stats_msgtab);
1516 + }
1517 +
1518 + static void
1519 + module_exit(void)
1520 + {
1521 +  mod_del_cmd(&stats_msgtab);
1522 + }
1523 +
1524 + struct module module_entry = {
1525 +  .node    = { NULL, NULL, NULL },
1526 +  .name    = NULL,
1527 +  .version = "$Revision$",
1528 +  .handle  = NULL,
1529 +  .modinit = module_init,
1530 +  .modexit = module_exit,
1531 +  .flags   = 0
1532 + };

Diff Legend

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