ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/modules/m_stats.c
Revision: 68
Committed: Tue Oct 4 00:44:29 2005 UTC (20 years, 10 months ago) by adx
Content type: text/x-csrc
File size: 46507 byte(s)
Log Message:
- removed last references to the ircd core, libio is independent now
- to do: split headers

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

Properties

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