ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-8/modules/m_stats.c
Revision: 948
Committed: Tue Jul 21 17:34:06 2009 UTC (14 years, 8 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-7.2/modules/m_stats.c
File size: 46456 byte(s)
Log Message:
- lp64\llp64\ilp32 portability fixes

File Contents

# User Rev Content
1 adx 30 /*
2     * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3     * m_stats.c: Sends the user statistics or config information.
4     *
5     * Copyright (C) 2002 by the past and present ircd coders, and others.
6     *
7     * This program is free software; you can redistribute it and/or modify
8     * it under the terms of the GNU General Public License as published by
9     * the Free Software Foundation; either version 2 of the License, or
10     * (at your option) any later version.
11     *
12     * This program is distributed in the hope that it will be useful,
13     * but WITHOUT ANY WARRANTY; without even the implied warranty of
14     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15     * GNU General Public License for more details.
16     *
17     * You should have received a copy of the GNU General Public License
18     * along with this program; if not, write to the Free Software
19     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20     * USA
21     *
22 knight 31 * $Id$
23 adx 30 */
24    
25     #include "stdinc.h"
26     #include "tools.h" /* dlink_node/dlink_list */
27     #include "handlers.h" /* m_pass prototype */
28     #include "client.h" /* Client */
29     #include "common.h" /* TRUE/FALSE */
30     #include "irc_string.h"
31     #include "ircd.h" /* me */
32     #include "listener.h" /* show_ports */
33     #include "s_gline.h"
34     #include "ircd_handler.h"
35     #include "msg.h" /* Message */
36     #include "hostmask.h"
37     #include "numeric.h" /* ERR_xxx */
38     #include "send.h" /* sendto_one */
39     #include "fdlist.h" /* PF and friends */
40     #include "s_bsd.h" /* highest_fd */
41     #include "s_conf.h" /* AccessItem, report_configured_links */
42     #include "s_misc.h" /* serv_info */
43     #include "s_serv.h" /* hunt_server */
44     #include "s_user.h" /* show_opers */
45     #include "event.h" /* events */
46     #include "dbuf.h"
47     #include "parse.h"
48     #include "modules.h"
49     #include "hook.h"
50     #include "resv.h" /* report_resv */
51     #include "whowas.h"
52     #include "list.h"
53 michael 884 #include "watch.h"
54 adx 30
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 *[]);
59    
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 knight 31 const char *_version = "$Revision$";
67 adx 30 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 michael 948 { '\0', NULL, 0, 0, }
184 adx 30 };
185    
186     const char *from, *to;
187    
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    
311     /*
312     * This is part of the STATS replies. There is no offical numeric for this
313     * since this isnt an official command, in much the same way as HASH isnt.
314     * It is also possible that some systems wont support this call or have
315     * different field names for "struct rusage".
316     * -avalon
317     */
318     static void
319     send_usage(struct Client *source_p)
320     {
321     #ifndef _WIN32
322     struct rusage rus;
323     time_t secs;
324     time_t rup;
325     #ifdef hz
326     # define hzz hz
327     #else
328     # ifdef HZ
329     # define hzz HZ
330     # else
331     int hzz = 1;
332     # endif
333     #endif
334    
335     if (getrusage(RUSAGE_SELF, &rus) == -1)
336     {
337     sendto_one(source_p, ":%s NOTICE %s :Getruseage error: %s",
338     me.name, source_p->name, strerror(errno));
339     return;
340     }
341    
342     secs = rus.ru_utime.tv_sec + rus.ru_stime.tv_sec;
343    
344     if (secs == 0)
345     secs = 1;
346    
347     rup = (CurrentTime - me.since) * hzz;
348    
349     if (rup == 0)
350     rup = 1;
351    
352     sendto_one(source_p,
353     ":%s %d %s R :CPU Secs %d:%d User %d:%d System %d:%d",
354     me.name, RPL_STATSDEBUG, source_p->name, (int)(secs/60), (int)(secs%60),
355     (int)(rus.ru_utime.tv_sec/60), (int)(rus.ru_utime.tv_sec%60),
356     (int)(rus.ru_stime.tv_sec/60), (int)(rus.ru_stime.tv_sec%60));
357     sendto_one(source_p, ":%s %d %s R :RSS %ld ShMem %ld Data %ld Stack %ld",
358     me.name, RPL_STATSDEBUG, source_p->name, rus.ru_maxrss,
359     (rus.ru_ixrss / rup), (rus.ru_idrss / rup),
360     (rus.ru_isrss / rup));
361     sendto_one(source_p, ":%s %d %s R :Swaps %d Reclaims %d Faults %d",
362     me.name, RPL_STATSDEBUG, source_p->name, (int)rus.ru_nswap,
363     (int)rus.ru_minflt, (int)rus.ru_majflt);
364     sendto_one(source_p, ":%s %d %s R :Block in %d out %d",
365     me.name, RPL_STATSDEBUG, source_p->name, (int)rus.ru_inblock,
366     (int)rus.ru_oublock);
367     sendto_one(source_p, ":%s %d %s R :Msg Rcv %d Send %d",
368     me.name, RPL_STATSDEBUG, source_p->name, (int)rus.ru_msgrcv,
369     (int)rus.ru_msgsnd);
370     sendto_one(source_p, ":%s %d %s R :Signals %d Context Vol. %d Invol %d",
371     me.name, RPL_STATSDEBUG, source_p->name, (int)rus.ru_nsignals,
372     (int)rus.ru_nvcsw, (int)rus.ru_nivcsw);
373     #endif
374     }
375    
376     static void
377     count_memory(struct Client *source_p)
378     {
379     const dlink_node *gptr = NULL;
380     const dlink_node *dlink = NULL;
381    
382 michael 948 unsigned int local_client_conf_count = 0; /* local client conf links */
383     unsigned int users_counted = 0; /* user structs */
384 adx 30
385 michael 948 unsigned int channel_users = 0; /* XXX */
386     unsigned int channel_invites = 0;
387     unsigned int channel_bans = 0;
388     unsigned int channel_except = 0;
389     unsigned int channel_invex = 0;
390 adx 30
391 michael 948 unsigned int wwu = 0; /* whowas users */
392     unsigned int class_count = 0; /* classes */
393     unsigned int aways_counted = 0;
394     unsigned int number_ips_stored; /* number of ip addresses hashed */
395 adx 30
396 michael 948 uint64_t channel_memory = 0;
397     uint64_t channel_ban_memory = 0;
398     uint64_t channel_except_memory = 0;
399     uint64_t channel_invex_memory = 0;
400 adx 30
401     unsigned int safelist_count = 0;
402 michael 948 uint64_t safelist_memory = 0;
403 adx 30
404 michael 948 uint64_t away_memory = 0; /* memory used by aways */
405     uint64_t wwm = 0; /* whowas array memory used */
406     uint64_t conf_memory = 0; /* memory used by conf lines */
407     uint64_t mem_ips_stored; /* memory used by ip address hash */
408 adx 30
409 michael 948 uint64_t client_hash_table_size = 0;
410     uint64_t channel_hash_table_size = 0;
411     uint64_t resv_hash_table_size = 0;
412     uint64_t id_hash_table_size = 0;
413     uint64_t total_channel_memory = 0;
414     uint64_t totww = 0;
415 adx 30
416     unsigned int local_client_count = 0;
417     unsigned int remote_client_count = 0;
418    
419 michael 948 uint64_t local_client_memory_used = 0;
420     uint64_t remote_client_memory_used = 0;
421 adx 30
422 michael 948 uint64_t total_memory = 0;
423 adx 30 unsigned int topic_count = 0;
424    
425 michael 884 unsigned int wlh = 0; /* watchlist headers */
426     unsigned int wle = 0; /* watchlist entries */
427 michael 948 uint64_t wlhm = 0; /* watchlist memory used */
428 michael 884
429 adx 30 count_whowas_memory(&wwu, &wwm);
430    
431     DLINK_FOREACH(gptr, global_client_list.head)
432     {
433     struct Client *target_p = gptr->data;
434    
435     if (MyConnect(target_p))
436     {
437     ++local_client_count;
438     local_client_conf_count += dlink_list_length(&target_p->localClient->confs);
439 michael 884 wle += dlink_list_length(&target_p->localClient->watches);
440 adx 30 }
441     else
442     ++remote_client_count;
443    
444     if (IsClient(target_p))
445     {
446     ++users_counted;
447    
448     if (target_p->away != NULL)
449     {
450     ++aways_counted;
451     away_memory += strlen(target_p->away) + 1;
452     }
453     }
454     }
455    
456     /* Count up all channels, ban lists, except lists, Invex lists */
457     channel_memory = dlink_list_length(&global_channel_list) *
458     sizeof(struct Channel);
459     DLINK_FOREACH(gptr, global_channel_list.head)
460     {
461 michael 948 const struct Ban *actualBan;
462     const struct Channel *chptr = gptr->data;
463 adx 30
464     channel_users += dlink_list_length(&chptr->members);
465     channel_invites += dlink_list_length(&chptr->invites);
466    
467     if (chptr->topic != NULL)
468     ++topic_count;
469    
470     if ((channel_bans = dlink_list_length(&chptr->banlist)))
471     {
472     channel_ban_memory = channel_bans * sizeof(struct Ban);
473    
474     DLINK_FOREACH(dlink, chptr->banlist.head)
475     {
476     actualBan = dlink->data;
477     assert(actualBan->who);
478    
479     channel_ban_memory += actualBan->len + 3;
480     channel_ban_memory += strlen(actualBan->who) + 1;
481     }
482     }
483    
484     if ((channel_except = dlink_list_length(&chptr->exceptlist)))
485     {
486     channel_except_memory = channel_except * sizeof(struct Ban);
487    
488     DLINK_FOREACH(dlink, chptr->exceptlist.head)
489     {
490     actualBan = dlink->data;
491     assert(actualBan->who);
492    
493     channel_except_memory += actualBan->len + 3;
494     channel_except_memory += strlen(actualBan->who) + 1;
495     }
496     }
497    
498     if ((channel_invex = dlink_list_length(&chptr->invexlist)))
499     {
500     channel_invex_memory = channel_invex * sizeof(struct Ban);
501    
502     DLINK_FOREACH(dlink, chptr->invexlist.head)
503     {
504     actualBan = dlink->data;
505     assert(actualBan->who);
506    
507     channel_invex_memory += actualBan->len + 3;
508     channel_invex_memory += strlen(actualBan->who) + 1;
509     }
510     }
511     }
512    
513     if ((safelist_count = dlink_list_length(&listing_client_list)))
514     {
515     safelist_memory = safelist_count * sizeof(struct ListTask);
516     DLINK_FOREACH(gptr, listing_client_list.head)
517     {
518 michael 948 const struct Client *acptr = gptr->data;
519 adx 30
520     DLINK_FOREACH(dlink, acptr->localClient->list_task->show_mask.head)
521     safelist_memory += strlen(dlink->data);
522    
523     DLINK_FOREACH(dlink, acptr->localClient->list_task->hide_mask.head)
524     safelist_memory += strlen(dlink->data);
525     }
526     }
527    
528     #if 0
529     /* XXX THIS has to be fixed !!!! -db */
530     /* count up all config items */
531     DLINK_FOREACH(dlink, ConfigItemList.head)
532     {
533     aconf = dlink->data;
534     conf_memory += aconf->host ? strlen(aconf->host)+1 : 0;
535     conf_memory += aconf->passwd ? strlen(aconf->passwd)+1 : 0;
536     conf_memory += aconf->name ? strlen(aconf->name)+1 : 0;
537     conf_memory += sizeof(struct AccessItem);
538     }
539     #endif
540     /* count up all classes */
541     class_count = dlink_list_length(&class_items);
542    
543 michael 884 watch_count_memory(&wlh, &wlhm);
544    
545     sendto_one(source_p, ":%s %d %s z :WATCH headers %u(%u) entries %d(%d)",
546     me.name, RPL_STATSDEBUG, source_p->name, wlh, wlhm, wle,
547     wle * sizeof(dlink_node));
548    
549     sendto_one(source_p, ":%s %d %s z :Clients %u(%u)",
550 adx 30 me.name, RPL_STATSDEBUG, source_p->name, users_counted,
551 michael 884 (users_counted * sizeof(struct Client)));
552 adx 30
553 michael 948 sendto_one(source_p, ":%s %d %s z :User aways %u(%llu)",
554 adx 30 me.name, RPL_STATSDEBUG, source_p->name,
555 michael 948 aways_counted, away_memory);
556 adx 30
557 michael 948 sendto_one(source_p, ":%s %d %s z :Attached confs %u(%llu)",
558 adx 30 me.name, RPL_STATSDEBUG, source_p->name,
559     local_client_conf_count,
560 michael 948 (unsigned long long)(local_client_conf_count * sizeof(dlink_node)));
561 adx 30
562     /* XXX ConfigItemList fix */
563     #if 0
564     sendto_one(source_p, ":%s %d %s z :Conflines %lu(%d)",
565     me.name, RPL_STATSDEBUG, source_p->name,
566     dlink_list_length(&ConfigItemList), (int) conf_memory);
567     #endif
568    
569     sendto_one(source_p, ":%s %d %s z :Resv channels %lu(%lu) nicks %lu(%lu)",
570     me.name, RPL_STATSDEBUG, source_p->name,
571     dlink_list_length(&resv_channel_list),
572     dlink_list_length(&resv_channel_list) * sizeof(struct ResvChannel),
573     dlink_list_length(&nresv_items),
574     dlink_list_length(&nresv_items) * sizeof(struct MatchItem));
575    
576 michael 948 sendto_one(source_p, ":%s %d %s z :Classes %u(%llu)",
577 adx 30 me.name, RPL_STATSDEBUG, source_p->name,
578 michael 948 class_count, (unsigned long long)(class_count * sizeof(struct ClassItem)));
579 adx 30
580 michael 948 sendto_one(source_p, ":%s %d %s z :Channels %lu(%llu) Topics %u(%d)",
581 adx 30 me.name, RPL_STATSDEBUG, source_p->name,
582     dlink_list_length(&global_channel_list),
583     channel_memory, topic_count, topic_count *
584     (TOPICLEN + 1 + USERHOST_REPLYLEN));
585    
586 michael 948 sendto_one(source_p, ":%s %d %s z :Bans %u(%llu)",
587 adx 30 me.name, RPL_STATSDEBUG, source_p->name,
588     channel_bans, channel_ban_memory);
589    
590 michael 948 sendto_one(source_p, ":%s %d %s z :Exceptions %u(%llu)",
591 adx 30 me.name, RPL_STATSDEBUG, source_p->name,
592     channel_except, channel_except_memory);
593    
594 michael 948 sendto_one(source_p, ":%s %d %s z :Invex %u(%llu)",
595 adx 30 me.name, RPL_STATSDEBUG, source_p->name,
596     channel_invex, channel_invex_memory);
597    
598 michael 948 sendto_one(source_p, ":%s %d %s z :Channel members %u(%llu) invites %u(%llu)",
599 adx 30 me.name, RPL_STATSDEBUG, source_p->name, channel_users,
600 michael 948 (unsigned long long)(channel_users * sizeof(struct Membership)),
601     channel_invites, (unsigned long long)channel_invites *
602 michael 884 sizeof(dlink_node) * 2);
603 adx 30
604     total_channel_memory = channel_memory + channel_ban_memory +
605     channel_users * sizeof(struct Membership) +
606 michael 884 (channel_invites * sizeof(dlink_node)*2);
607 adx 30
608 michael 948 sendto_one(source_p, ":%s %d %s z :Safelist %u(%llu)",
609 adx 30 me.name, RPL_STATSDEBUG, source_p->name,
610     safelist_count, safelist_memory);
611    
612 michael 948 sendto_one(source_p, ":%s %d %s z :Whowas users %u(%llu)",
613 adx 30 me.name, RPL_STATSDEBUG, source_p->name,
614 michael 948 wwu, (unsigned long long)(wwu * sizeof(struct Client)));
615 adx 30
616 michael 948 sendto_one(source_p, ":%s %d %s z :Whowas array %u(%llu)",
617 adx 30 me.name, RPL_STATSDEBUG, source_p->name,
618 michael 948 NICKNAMEHISTORYLENGTH, wwm);
619 adx 30
620     totww = wwu * sizeof(struct Client) + wwm;
621     /****
622     client_hash_table_size = hash_get_client_table_size();
623     channel_hash_table_size = hash_get_channel_table_size();
624     resv_hash_table_size = hash_get_resv_table_size();
625     id_hash_table_size = hash_get_id_table_size();
626    
627     sendto_one(source_p, ":%s %d %s z :Hash: client %u(%lu) chan %u(%lu) resv "
628     "%u(%lu) id %u(%lu)",
629     me.name, RPL_STATSDEBUG, source_p->name,
630     U_MAX, client_hash_table_size,
631     CH_MAX, channel_hash_table_size , R_MAX,
632     resv_hash_table_size, U_MAX, id_hash_table_size);
633     ****/
634     count_ip_hash(&number_ips_stored,&mem_ips_stored);
635 michael 948 sendto_one(source_p, ":%s %d %s z :iphash %u(%llu)",
636 adx 30 me.name, RPL_STATSDEBUG, source_p->name,
637 michael 948 number_ips_stored, mem_ips_stored);
638 adx 30
639     total_memory = totww + total_channel_memory + conf_memory + class_count *
640     sizeof(struct ClassItem);
641     total_memory += client_hash_table_size;
642     total_memory += channel_hash_table_size;
643     total_memory += resv_hash_table_size;
644     total_memory += id_hash_table_size;
645    
646 michael 948 sendto_one(source_p, ":%s %d %s z :Total: whowas %llu channel %llu conf %llu",
647     me.name, RPL_STATSDEBUG, source_p->name, totww,
648     total_channel_memory, conf_memory);
649 adx 30
650     local_client_memory_used = local_client_count*(sizeof(struct Client) + sizeof(struct LocalUser));
651     total_memory += local_client_memory_used;
652 michael 948 sendto_one(source_p, ":%s %d %s z :Local client Memory in use: %d(%llu)",
653 adx 30 me.name, RPL_STATSDEBUG, source_p->name, local_client_count,
654     local_client_memory_used);
655    
656     remote_client_memory_used = remote_client_count * sizeof(struct Client);
657     total_memory += remote_client_memory_used;
658 michael 948 sendto_one(source_p, ":%s %d %s z :Remote client Memory in use: %d(%llu)",
659 adx 30 me.name, RPL_STATSDEBUG, source_p->name, remote_client_count,
660     remote_client_memory_used);
661    
662     block_heap_report_stats(source_p);
663    
664     sendto_one(source_p,
665 michael 948 ":%s %d %s z :TOTAL: %llu",
666 adx 30 me.name, RPL_STATSDEBUG, source_p->name,
667 michael 948 total_memory);
668 adx 30 }
669    
670     static void
671     stats_dns_servers(struct Client *source_p)
672     {
673     report_dns_servers(source_p);
674     }
675    
676     static void
677     stats_connect(struct Client *source_p)
678     {
679     report_confitem_types(source_p, SERVER_TYPE, 0);
680     }
681    
682     /* stats_deny()
683     *
684     * input - client to report to
685     * output - none
686     * side effects - client is given dline list.
687     */
688     static void
689     stats_deny(struct Client *source_p)
690     {
691     struct AddressRec *arec;
692     struct ConfItem *conf;
693     struct AccessItem *aconf;
694     int i;
695    
696     for (i = 0; i < ATABLE_SIZE; i++)
697     {
698     for (arec = atable[i]; arec; arec=arec->next)
699     {
700     if (arec->type == CONF_DLINE)
701     {
702     aconf = arec->aconf;
703    
704     /* dont report a tdline as a dline */
705     if (aconf->flags & CONF_FLAGS_TEMPORARY)
706     continue;
707    
708     conf = unmap_conf_item(aconf);
709    
710     sendto_one(source_p, form_str(RPL_STATSDLINE),
711     from, to, 'D', aconf->host, aconf->reason,
712     aconf->oper_reason);
713     }
714     }
715     }
716     }
717    
718     /* stats_tdeny()
719     *
720     * input - client to report to
721     * output - none
722     * side effects - client is given dline list.
723     */
724     static void
725     stats_tdeny(struct Client *source_p)
726     {
727     struct AddressRec *arec;
728     struct ConfItem *conf;
729     struct AccessItem *aconf;
730     int i;
731    
732     for (i = 0; i < ATABLE_SIZE; i++)
733     {
734     for (arec = atable[i]; arec; arec=arec->next)
735     {
736     if (arec->type == CONF_DLINE)
737     {
738     aconf = arec->aconf;
739    
740     /* dont report a permanent dline as a tdline */
741     if (!(aconf->flags & CONF_FLAGS_TEMPORARY))
742     continue;
743    
744     conf = unmap_conf_item(aconf);
745    
746     sendto_one(source_p, form_str(RPL_STATSDLINE),
747     from, to, 'd', aconf->host, aconf->reason,
748     aconf->oper_reason);
749     }
750     }
751     }
752     }
753    
754     /* stats_exempt()
755     *
756     * input - client to report to
757     * output - none
758     * side effects - client is given list of exempt blocks
759     */
760     static void
761     stats_exempt(struct Client *source_p)
762     {
763     struct AddressRec *arec;
764     struct ConfItem *conf;
765     struct AccessItem *aconf;
766     int i;
767    
768 michael 584 if (ConfigFileEntry.stats_e_disabled)
769     {
770     sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
771     from, to);
772     return;
773     }
774    
775 adx 30 for (i = 0; i < ATABLE_SIZE; i++)
776     {
777     for (arec = atable[i]; arec; arec=arec->next)
778     {
779     if (arec->type == CONF_EXEMPTDLINE)
780     {
781     aconf = arec->aconf;
782    
783     conf = unmap_conf_item(aconf);
784    
785     sendto_one(source_p, form_str(RPL_STATSDLINE),
786     from, to, 'e', aconf->host,
787     aconf->reason, aconf->oper_reason);
788     }
789     }
790     }
791     }
792    
793     static void
794     stats_events(struct Client *source_p)
795     {
796     show_events(source_p);
797     }
798    
799     /* stats_pending_glines()
800     *
801     * input - client pointer
802     * output - none
803     * side effects - client is shown list of pending glines
804     */
805     static void
806     stats_pending_glines(struct Client *source_p)
807     {
808     #ifdef GLINE_VOTING
809     dlink_node *pending_node;
810     struct gline_pending *glp_ptr;
811     char timebuffer[MAX_DATE_STRING];
812     struct tm *tmptr;
813    
814     if (!ConfigFileEntry.glines)
815     {
816     sendto_one(source_p, ":%s NOTICE %s :This server does not support G-Lines",
817     from, to);
818     return;
819     }
820    
821     if (dlink_list_length(&pending_glines) > 0)
822     sendto_one(source_p, ":%s NOTICE %s :Pending G-lines",
823     from, to);
824    
825     DLINK_FOREACH(pending_node, pending_glines.head)
826     {
827     glp_ptr = pending_node->data;
828     tmptr = localtime(&glp_ptr->time_request1);
829     strftime(timebuffer, MAX_DATE_STRING, "%Y/%m/%d %H:%M:%S", tmptr);
830    
831     sendto_one(source_p,
832     ":%s NOTICE %s :1) %s!%s@%s on %s requested gline at %s for %s@%s [%s]",
833     from, to, glp_ptr->oper_nick1,
834     glp_ptr->oper_user1, glp_ptr->oper_host1,
835     glp_ptr->oper_server1, timebuffer,
836     glp_ptr->user, glp_ptr->host, glp_ptr->reason1);
837    
838     if (glp_ptr->oper_nick2[0] != '\0')
839     {
840     tmptr = localtime(&glp_ptr->time_request2);
841     strftime(timebuffer, MAX_DATE_STRING, "%Y/%m/%d %H:%M:%S", tmptr);
842     sendto_one(source_p,
843     ":%s NOTICE %s :2) %s!%s@%s on %s requested gline at %s for %s@%s [%s]",
844     from, to, glp_ptr->oper_nick2,
845     glp_ptr->oper_user2, glp_ptr->oper_host2,
846     glp_ptr->oper_server2, timebuffer,
847     glp_ptr->user, glp_ptr->host, glp_ptr->reason2);
848     }
849     }
850    
851     sendto_one(source_p, ":%s NOTICE %s :End of Pending G-lines",
852     from, to);
853     #else
854     sendto_one(source_p, ":%s NOTICE %s :This server does not support G-Line voting",
855     from, to);
856     #endif /* GLINE VOTING */
857     }
858    
859     /* stats_glines()
860     *
861     * input - client pointer
862     * output - none
863     * side effects - client is shown list of glines
864     */
865     static void
866     stats_glines(struct Client *source_p)
867     {
868     struct AddressRec *arec = NULL;
869     int i = 0;
870    
871     if (!ConfigFileEntry.glines)
872     {
873     sendto_one(source_p, ":%s NOTICE %s :This server does not support G-Lines",
874     from, to);
875     return;
876     }
877    
878     for (; i < ATABLE_SIZE; ++i)
879     {
880 michael 884 for (arec = atable[i]; arec; arec = arec->next)
881 adx 30 {
882     if (arec->type == CONF_GLINE)
883     {
884     const struct AccessItem *aconf = arec->aconf;
885    
886     sendto_one(source_p, form_str(RPL_STATSKLINE),
887     from, to, "G",
888     aconf->host ? aconf->host : "*",
889     aconf->user ? aconf->user : "*",
890     aconf->reason ? aconf->reason : "No reason", "" );
891     }
892     }
893     }
894     }
895    
896     /* stats_gdeny()
897     *
898     * input - client pointer
899     * outputs - none
900     * side effects - client is shown gline ACL
901     */
902     static void
903     stats_gdeny(struct Client *source_p)
904     {
905     if (!ConfigFileEntry.glines)
906     {
907     sendto_one(source_p, ":%s NOTICE %s :This server does not support G-Lines",
908     from, to);
909     return;
910     }
911    
912     report_confitem_types(source_p, GDENY_TYPE, 0);
913     }
914    
915     static void
916     stats_hubleaf(struct Client *source_p)
917     {
918     report_confitem_types(source_p, HUB_TYPE, 0);
919     report_confitem_types(source_p, LEAF_TYPE, 0);
920     }
921    
922     static void
923     stats_auth(struct Client *source_p)
924     {
925     /* Oper only, if unopered, return ERR_NOPRIVILEGES */
926     if ((ConfigFileEntry.stats_i_oper_only == 2) && !IsOper(source_p))
927     sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
928     from, to);
929    
930     /* If unopered, Only return matching auth blocks */
931     else if ((ConfigFileEntry.stats_i_oper_only == 1) && !IsOper(source_p))
932     {
933     struct ConfItem *conf;
934     struct AccessItem *aconf;
935    
936     if (MyConnect(source_p))
937     aconf = find_conf_by_address(source_p->host,
938     &source_p->localClient->ip,
939     CONF_CLIENT,
940     source_p->localClient->aftype,
941     source_p->username,
942     source_p->localClient->passwd);
943     else
944     aconf = find_conf_by_address(source_p->host, NULL, CONF_CLIENT,
945     0, source_p->username, NULL);
946    
947     if (aconf == NULL)
948     return;
949    
950     conf = unmap_conf_item(aconf);
951    
952     sendto_one(source_p, form_str(RPL_STATSILINE), from,
953     to, 'I',
954     "*", show_iline_prefix(source_p, aconf, aconf->user),
955     aconf->host, aconf->port,
956     aconf->class_ptr ? aconf->class_ptr->name : "<default>");
957     }
958     /* They are opered, or allowed to see all auth blocks */
959     else
960     report_auth(source_p);
961     }
962    
963     static void
964     stats_tklines(struct Client *source_p)
965     {
966     struct ConfItem *conf;
967     /* Oper only, if unopered, return ERR_NOPRIVILEGES */
968     if ((ConfigFileEntry.stats_k_oper_only == 2) && !IsOper(source_p))
969     sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
970     from, to);
971    
972     /* If unopered, Only return matching klines */
973     else if ((ConfigFileEntry.stats_k_oper_only == 1) && !IsOper(source_p))
974     {
975     struct AccessItem *aconf;
976    
977     if (MyConnect(source_p))
978     aconf = find_conf_by_address(source_p->host,
979     &source_p->localClient->ip,
980     CONF_KILL,
981     source_p->localClient->aftype,
982     source_p->username, NULL);
983     else
984     aconf = find_conf_by_address(source_p->host, NULL, CONF_KILL,
985     0, source_p->username, NULL);
986    
987     if (aconf == NULL)
988     return;
989    
990     /* dont report a permanent kline as a tkline */
991     if (!(aconf->flags & CONF_FLAGS_TEMPORARY))
992     return;
993    
994     conf = unmap_conf_item(aconf);
995    
996     sendto_one(source_p, form_str(RPL_STATSKLINE), from,
997     to, "k", aconf->host, aconf->user, aconf->reason, "");
998     }
999     /* Theyre opered, or allowed to see all klines */
1000     else {
1001     report_Klines(source_p, 1);
1002     report_confitem_types(source_p, RKLINE_TYPE, 1);
1003     }
1004     }
1005    
1006     static void
1007     stats_klines(struct Client *source_p)
1008     {
1009     /* Oper only, if unopered, return ERR_NOPRIVILEGES */
1010     if ((ConfigFileEntry.stats_k_oper_only == 2) && !IsOper(source_p))
1011     sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
1012     from, to);
1013    
1014     /* If unopered, Only return matching klines */
1015     else if ((ConfigFileEntry.stats_k_oper_only == 1) && !IsOper(source_p))
1016     {
1017     struct AccessItem *aconf;
1018    
1019     /* search for a kline */
1020 michael 560 if (MyConnect(source_p))
1021 adx 30 aconf = find_conf_by_address(source_p->host,
1022     &source_p->localClient->ip,
1023     CONF_KILL,
1024     source_p->localClient->aftype,
1025     source_p->username, NULL);
1026     else
1027     aconf = find_conf_by_address(source_p->host, NULL, CONF_KILL,
1028     0, source_p->username, NULL);
1029    
1030 michael 560 if (aconf == NULL)
1031 adx 30 return;
1032    
1033     /* dont report a tkline as a kline */
1034 michael 560 if (aconf->flags & CONF_FLAGS_TEMPORARY)
1035 adx 30 return;
1036    
1037     sendto_one(source_p, form_str(RPL_STATSKLINE), from,
1038     to, "K", aconf->host, aconf->user, aconf->reason,
1039     aconf->oper_reason);
1040     }
1041     /* Theyre opered, or allowed to see all klines */
1042     else {
1043     report_Klines(source_p, 0);
1044     report_confitem_types(source_p, RKLINE_TYPE, 0);
1045     }
1046     }
1047    
1048     static void
1049     stats_messages(struct Client *source_p)
1050     {
1051     report_messages(source_p);
1052     }
1053    
1054     static void
1055     stats_oper(struct Client *source_p)
1056     {
1057     if (!IsOper(source_p) && ConfigFileEntry.stats_o_oper_only)
1058     sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
1059     from, to);
1060     else
1061     report_confitem_types(source_p, OPER_TYPE, 0);
1062     }
1063    
1064     /* stats_operedup()
1065     *
1066     * input - client pointer
1067     * output - none
1068     * side effects - client is shown a list of active opers
1069     */
1070     static void
1071     stats_operedup(struct Client *source_p)
1072     {
1073     dlink_node *ptr;
1074    
1075     DLINK_FOREACH(ptr, oper_list.head)
1076     {
1077     const struct Client *target_p = ptr->data;
1078    
1079     if (IsOperHidden(target_p) && !IsOper(source_p))
1080     continue;
1081    
1082     if (MyClient(source_p) && IsOper(source_p))
1083     sendto_one(source_p, ":%s %d %s p :[%c][%s] %s (%s@%s) Idle: %d",
1084     from, RPL_STATSDEBUG, to,
1085     IsAdmin(target_p) ?
1086     (IsOperHiddenAdmin(target_p) ? 'O' : 'A') : 'O',
1087     oper_privs_as_string(target_p->localClient->operflags),
1088     target_p->name, target_p->username, target_p->host,
1089     (int)(CurrentTime - target_p->localClient->last));
1090     else
1091     sendto_one(source_p, ":%s %d %s p :[%c] %s (%s@%s) Idle: %d",
1092     from, RPL_STATSDEBUG, to,
1093     IsAdmin(target_p) ?
1094     (IsOperHiddenAdmin(target_p) ? 'O' : 'A') : 'O',
1095     target_p->name, target_p->username, target_p->host,
1096     (int)(CurrentTime - target_p->localClient->last));
1097     }
1098    
1099     sendto_one(source_p, ":%s %d %s p :%lu OPER(s)",
1100     from, RPL_STATSDEBUG, to, dlink_list_length(&oper_list));
1101     }
1102    
1103     static void
1104     stats_ports(struct Client *source_p)
1105     {
1106     if (!IsOper(source_p) && ConfigFileEntry.stats_P_oper_only)
1107     sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
1108     from, to);
1109     else
1110     show_ports(source_p);
1111     }
1112    
1113     static void
1114     stats_resv(struct Client *source_p)
1115     {
1116     report_resv(source_p);
1117     }
1118    
1119     static void
1120     stats_usage(struct Client *source_p)
1121     {
1122     send_usage(source_p);
1123     }
1124    
1125     static void
1126     stats_tstats(struct Client *source_p)
1127     {
1128 michael 896 const struct Client *target_p = NULL;
1129     const dlink_node *ptr = NULL;
1130     struct ServerStatistics *sp;
1131     struct ServerStatistics tmp;
1132    
1133     sp = &tmp;
1134     memcpy(sp, &ServerStats, sizeof(struct ServerStatistics));
1135    
1136     /*
1137     * must use the += operator. is_sv is not the number of currently
1138     * active server connections. Note the incrementation in
1139     * s_bsd.c:close_connection.
1140     */
1141     sp->is_sv += dlink_list_length(&serv_list);
1142    
1143     DLINK_FOREACH(ptr, serv_list.head)
1144     {
1145     target_p = ptr->data;
1146    
1147     sp->is_sbs += target_p->localClient->send.bytes;
1148     sp->is_sbr += target_p->localClient->recv.bytes;
1149     sp->is_sti += CurrentTime - target_p->firsttime;
1150     }
1151    
1152     sp->is_cl += dlink_list_length(&local_client_list);
1153    
1154     DLINK_FOREACH(ptr, local_client_list.head)
1155     {
1156     target_p = ptr->data;
1157    
1158     sp->is_cbs += target_p->localClient->send.bytes;
1159     sp->is_cbr += target_p->localClient->recv.bytes;
1160     sp->is_cti += CurrentTime - target_p->firsttime;
1161     }
1162    
1163     sp->is_ni += dlink_list_length(&unknown_list);
1164    
1165     sendto_one(source_p, ":%s %d %s T :accepts %u refused %u",
1166     me.name, RPL_STATSDEBUG, source_p->name, sp->is_ac, sp->is_ref);
1167     sendto_one(source_p, ":%s %d %s T :unknown commands %u prefixes %u",
1168     me.name, RPL_STATSDEBUG, source_p->name, sp->is_unco, sp->is_unpf);
1169     sendto_one(source_p, ":%s %d %s T :nick collisions %u unknown closes %u",
1170     me.name, RPL_STATSDEBUG, source_p->name, sp->is_kill, sp->is_ni);
1171     sendto_one(source_p, ":%s %d %s T :wrong direction %u empty %u",
1172     me.name, RPL_STATSDEBUG, source_p->name, sp->is_wrdi, sp->is_empt);
1173     sendto_one(source_p, ":%s %d %s T :numerics seen %u",
1174     me.name, RPL_STATSDEBUG, source_p->name, sp->is_num);
1175     sendto_one(source_p, ":%s %d %s T :auth successes %u fails %u",
1176     me.name, RPL_STATSDEBUG, source_p->name, sp->is_asuc, sp->is_abad);
1177     sendto_one(source_p, ":%s %d %s T :Client Server",
1178     me.name, RPL_STATSDEBUG, source_p->name);
1179    
1180     sendto_one(source_p, ":%s %d %s T :connected %u %u",
1181     me.name, RPL_STATSDEBUG, source_p->name,
1182     (unsigned int)sp->is_cl,
1183     (unsigned int)sp->is_sv);
1184     sendto_one(source_p, ":%s %d %s T :bytes sent %llu %llu",
1185     me.name, RPL_STATSDEBUG, source_p->name,
1186     sp->is_cbs, sp->is_sbs);
1187     sendto_one(source_p, ":%s %d %s T :bytes recv %llu %llu",
1188     me.name, RPL_STATSDEBUG, source_p->name,
1189     sp->is_cbr, sp->is_sbr);
1190     sendto_one(source_p, ":%s %d %s T :time connected %u %u",
1191     me.name, RPL_STATSDEBUG, source_p->name,
1192     (unsigned int)sp->is_cti,
1193     (unsigned int)sp->is_sti);
1194 adx 30 }
1195    
1196     static void
1197     stats_uptime(struct Client *source_p)
1198     {
1199     time_t now = CurrentTime - me.since;
1200     sendto_one(source_p, form_str(RPL_STATSUPTIME), from, to,
1201     now/86400, (now/3600)%24, (now/60)%60, now%60);
1202     if (!ConfigFileEntry.disable_remote || IsOper(source_p))
1203     sendto_one(source_p, form_str(RPL_STATSCONN), from, to,
1204     MaxConnectionCount, MaxClientCount, Count.totalrestartcount);
1205     }
1206    
1207     static void
1208     stats_shared(struct Client *source_p)
1209     {
1210     report_confitem_types(source_p, ULINE_TYPE, 0);
1211     }
1212    
1213     /* stats_servers()
1214     *
1215     * input - client pointer
1216     * output - none
1217     * side effects - client is shown lists of who connected servers
1218     */
1219     static void
1220     stats_servers(struct Client *source_p)
1221     {
1222     struct Client *target_p;
1223     dlink_node *ptr;
1224     int j = 0;
1225    
1226     DLINK_FOREACH(ptr, serv_list.head)
1227     {
1228     target_p = ptr->data;
1229    
1230     j++;
1231    
1232     sendto_one(source_p, ":%s %d %s v :%s (%s!%s@%s) Idle: %d",
1233     from, RPL_STATSDEBUG, to,
1234     target_p->name,
1235     (target_p->serv->by[0] ? target_p->serv->by : "Remote."),
1236     "*", "*", (int)(CurrentTime - target_p->lasttime));
1237     }
1238    
1239     sendto_one(source_p, ":%s %d %s v :%d Server(s)",
1240     from, RPL_STATSDEBUG, to, j);
1241     }
1242    
1243     static void
1244     stats_gecos(struct Client *source_p)
1245     {
1246     report_confitem_types(source_p, XLINE_TYPE, 0);
1247     report_confitem_types(source_p, RXLINE_TYPE, 0);
1248     }
1249    
1250     static void
1251     stats_class(struct Client *source_p)
1252     {
1253     report_confitem_types(source_p, CLASS_TYPE, 0);
1254     }
1255    
1256     static void
1257     stats_memory(struct Client *source_p)
1258     {
1259     count_memory(source_p);
1260     }
1261    
1262     static void
1263     stats_ziplinks(struct Client *source_p)
1264     {
1265 michael 948 dlink_node *ptr = NULL;
1266 adx 30 unsigned int sent_data = 0;
1267    
1268     DLINK_FOREACH(ptr, serv_list.head)
1269     {
1270 michael 948 const struct Client *target_p = ptr->data;
1271 adx 30
1272     if (IsCapable(target_p, CAP_ZIP))
1273     {
1274     /* we use memcpy(3) and a local copy of the structure to
1275     * work around a register use bug on GCC on the SPARC.
1276     * -jmallett, 04/27/2002
1277     */
1278     struct ZipStats zipstats;
1279    
1280 michael 948 memcpy(&zipstats, &target_p->localClient->zipstats, sizeof(zipstats));
1281    
1282 adx 30 sendto_one(source_p, ":%s %d %s Z :ZipLinks stats for %s send[%.2f%% "
1283 michael 948 "compression (%llu bytes data/%llu bytes wire)] recv[%.2f%% "
1284     "compression (%llu bytes data/%llu bytes wire)]",
1285 adx 30 from, RPL_STATSDEBUG, to, target_p->name,
1286 michael 560 zipstats.out_ratio, zipstats.out, zipstats.out_wire,
1287     zipstats.in_ratio, zipstats.in, zipstats.in_wire);
1288 adx 30 ++sent_data;
1289     }
1290     }
1291    
1292     sendto_one(source_p, ":%s %d %s Z :%u ziplink(s)",
1293     from, RPL_STATSDEBUG, to, sent_data);
1294     }
1295    
1296     static void
1297     stats_servlinks(struct Client *source_p)
1298     {
1299     uint64_t sendB = 0, recvB = 0;
1300     time_t uptime = 0;
1301 michael 560 dlink_node *ptr = NULL;
1302 adx 30
1303     if (ConfigServerHide.flatten_links && !IsOper(source_p))
1304     {
1305     sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
1306     from, to);
1307     return;
1308     }
1309    
1310     DLINK_FOREACH(ptr, serv_list.head)
1311     {
1312 michael 560 struct Client *target_p = ptr->data;
1313 adx 30
1314     sendB += target_p->localClient->send.bytes;
1315     recvB += target_p->localClient->recv.bytes;
1316    
1317     /* ":%s 211 %s %s %u %u %llu %u %llu :%u %u %s" */
1318     sendto_one(source_p, form_str(RPL_STATSLINKINFO),
1319     from, to,
1320     get_client_name(target_p, IsAdmin(source_p) ? SHOW_IP : MASK_IP),
1321     dbuf_length(&target_p->localClient->buf_sendq),
1322     target_p->localClient->send.messages,
1323     target_p->localClient->send.bytes >> 10,
1324     target_p->localClient->recv.messages,
1325     target_p->localClient->recv.bytes >> 10,
1326     (unsigned)(CurrentTime - target_p->firsttime),
1327     (CurrentTime > target_p->since) ? (unsigned)(CurrentTime - target_p->since): 0,
1328     IsOper(source_p) ? show_capabilities(target_p) : "TS");
1329     }
1330    
1331     sendB >>= 10;
1332     recvB >>= 10;
1333    
1334     sendto_one(source_p, ":%s %d %s ? :%u total server(s)",
1335 michael 560 from, RPL_STATSDEBUG, to, dlink_list_length(&serv_list));
1336 adx 30 sendto_one(source_p, ":%s %d %s ? :Sent total : %7.2f %s",
1337     from, RPL_STATSDEBUG, to,
1338 michael 560 _GMKv(sendB), _GMKs(sendB));
1339 adx 30 sendto_one(source_p, ":%s %d %s ? :Recv total : %7.2f %s",
1340     from, RPL_STATSDEBUG, to,
1341 michael 560 _GMKv(recvB), _GMKs(recvB));
1342 adx 30
1343     uptime = (CurrentTime - me.since);
1344    
1345     sendto_one(source_p, ":%s %d %s ? :Server send: %7.2f %s (%4.1f K/s)",
1346     from, RPL_STATSDEBUG, to,
1347 michael 560 _GMKv((me.localClient->send.bytes>>10)),
1348     _GMKs((me.localClient->send.bytes>>10)),
1349     (float)((float)((me.localClient->send.bytes) >> 10) /
1350     (float)uptime));
1351 adx 30 sendto_one(source_p, ":%s %d %s ? :Server recv: %7.2f %s (%4.1f K/s)",
1352     from, RPL_STATSDEBUG, to,
1353 michael 560 _GMKv((me.localClient->recv.bytes>>10)),
1354     _GMKs((me.localClient->recv.bytes>>10)),
1355     (float)((float)((me.localClient->recv.bytes) >> 10) /
1356     (float)uptime));
1357 adx 30 }
1358    
1359     static void
1360     stats_ltrace(struct Client *source_p, int parc, char *parv[])
1361     {
1362     int doall = 0;
1363     int wilds = 0;
1364     char *name = NULL;
1365     char statchar;
1366    
1367     if ((name = parse_stats_args(parc, parv, &doall, &wilds)) != NULL)
1368     {
1369     statchar = parv[1][0];
1370    
1371     stats_L(source_p, name, doall, wilds, statchar);
1372     }
1373     else
1374     sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
1375     from, to, "STATS");
1376     }
1377    
1378     /*
1379     * ms_stats - STATS message handler
1380     * parv[0] = sender prefix
1381     * parv[1] = statistics selector (defaults to Message frequency)
1382     * parv[2] = server name (current server defaulted, if omitted)
1383     */
1384     static void
1385     ms_stats(struct Client *client_p, struct Client *source_p,
1386     int parc, char *parv[])
1387     {
1388     if (hunt_server(client_p,source_p,":%s STATS %s :%s",2,parc,parv)!=HUNTED_ISME)
1389     return;
1390    
1391     if (IsClient(source_p))
1392     mo_stats(client_p, source_p, parc, parv);
1393     }
1394    
1395     /*
1396     * stats_L
1397     *
1398     * inputs - pointer to client to report to
1399     * - doall flag
1400     * - wild card or not
1401     * output - NONE
1402     * side effects -
1403     */
1404     static void
1405     stats_L(struct Client *source_p,char *name,int doall,
1406     int wilds,char statchar)
1407     {
1408     stats_L_list(source_p, name, doall, wilds, &unknown_list, statchar);
1409     stats_L_list(source_p, name, doall, wilds, &local_client_list, statchar);
1410     stats_L_list(source_p, name, doall, wilds, &serv_list, statchar);
1411     }
1412    
1413     static void
1414     stats_L_list(struct Client *source_p,char *name, int doall, int wilds,
1415     dlink_list *list,char statchar)
1416     {
1417     dlink_node *ptr;
1418     struct Client *target_p;
1419    
1420     /*
1421     * send info about connections which match, or all if the
1422     * mask matches from. Only restrictions are on those who
1423     * are invisible not being visible to 'foreigners' who use
1424     * a wild card based search to list it.
1425     */
1426     DLINK_FOREACH(ptr, list->head)
1427     {
1428     target_p = ptr->data;
1429    
1430     if (IsInvisible(target_p) && (doall || wilds) &&
1431     !(MyConnect(source_p) && IsOper(source_p)) &&
1432     !IsOper(target_p) && (target_p != source_p))
1433     continue;
1434     if (!doall && wilds && !match(name, target_p->name))
1435     continue;
1436     if (!(doall || wilds) && irccmp(name, target_p->name))
1437     continue;
1438    
1439     /* This basically shows ips for our opers if its not a server/admin, or
1440     * its one of our admins. */
1441     if(MyClient(source_p) && IsOper(source_p) &&
1442     (IsAdmin(source_p) ||
1443     (!IsServer(target_p) && !IsAdmin(target_p) &&
1444     !IsHandshake(target_p) && !IsConnecting(target_p))))
1445     {
1446     sendto_one(source_p, form_str(RPL_STATSLINKINFO),
1447     from, to,
1448     (IsUpper(statchar)) ?
1449     get_client_name(target_p, SHOW_IP) :
1450     get_client_name(target_p, HIDE_IP),
1451     dbuf_length(&target_p->localClient->buf_sendq),
1452     target_p->localClient->send.messages,
1453     target_p->localClient->send.bytes>>10,
1454     target_p->localClient->recv.messages,
1455     target_p->localClient->recv.bytes>>10,
1456     (unsigned)(CurrentTime - target_p->firsttime),
1457     (CurrentTime > target_p->since) ? (unsigned)(CurrentTime - target_p->since):0,
1458     IsServer(target_p) ? show_capabilities(target_p) : "-");
1459     }
1460     else
1461     {
1462     /* If its a hidden ip, an admin, or a server, mask the real IP */
1463     if(IsIPSpoof(target_p) || IsServer(target_p) || IsAdmin(target_p)
1464     || IsHandshake(target_p) || IsConnecting(target_p))
1465     sendto_one(source_p, form_str(RPL_STATSLINKINFO),
1466     from, to,
1467     get_client_name(target_p, MASK_IP),
1468     dbuf_length(&target_p->localClient->buf_sendq),
1469     target_p->localClient->send.messages,
1470     target_p->localClient->send.bytes>>10,
1471     target_p->localClient->recv.messages,
1472     target_p->localClient->recv.bytes>>10,
1473     (unsigned)(CurrentTime - target_p->firsttime),
1474     (CurrentTime > target_p->since) ? (unsigned)(CurrentTime - target_p->since):0,
1475     IsServer(target_p) ? show_capabilities(target_p) : "-");
1476     else /* show the real IP */
1477     sendto_one(source_p, form_str(RPL_STATSLINKINFO),
1478     from, to,
1479     (IsUpper(statchar)) ?
1480     get_client_name(target_p, SHOW_IP) :
1481     get_client_name(target_p, HIDE_IP),
1482     dbuf_length(&target_p->localClient->buf_sendq),
1483     target_p->localClient->send.messages,
1484     target_p->localClient->send.bytes>>10,
1485     target_p->localClient->recv.messages,
1486     target_p->localClient->recv.bytes>>10,
1487     (unsigned)(CurrentTime - target_p->firsttime),
1488     (CurrentTime > target_p->since) ? (unsigned)(CurrentTime - target_p->since):0,
1489     IsServer(target_p) ? show_capabilities(target_p) : "-");
1490     }
1491     }
1492     }
1493    
1494     /* parse_stats_args()
1495     *
1496     * inputs - arg count
1497     * - args
1498     * - doall flag
1499     * - wild card or not
1500     * output - pointer to name to use
1501     * side effects -
1502     * common parse routine for m_stats args
1503     *
1504     */
1505     static char *
1506     parse_stats_args(int parc, char *parv[], int *doall, int *wilds)
1507     {
1508     char *name;
1509    
1510     if (parc > 2)
1511     {
1512     name = parv[2];
1513    
1514     if (!irccmp(name, from))
1515     *doall = 2;
1516     else if (match(name, from))
1517     *doall = 1;
1518    
1519     if (strchr(name, '*') ||
1520     strchr(name, '?'))
1521     *wilds = 1;
1522    
1523     return(name);
1524     }
1525     else
1526     return(NULL);
1527     }

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision