ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/modules/m_stats.c
Revision: 65
Committed: Mon Oct 3 23:33:16 2005 UTC (20 years, 10 months ago) by adx
Content type: text/x-csrc
File size: 45808 byte(s)
Log Message:
- removed external references from libio/misc
- imported s_misc.c to libio, moved CurrentTime there

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

Properties

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