ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/modules/m_stats.c
Revision: 62
Committed: Mon Oct 3 22:23:39 2005 UTC (20 years, 10 months ago) by adx
Content type: text/x-csrc
File size: 43924 byte(s)
Log Message:
- reorganisation goes on, removed external references from libio/mem

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

Properties

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