ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-7.2/modules/m_stats.c
Revision: 560
Committed: Sun Apr 23 06:38:25 2006 UTC (17 years, 11 months ago) by michael
Content type: text/x-csrc
File size: 43476 byte(s)
Log Message:
- Fixed negative "STATS ?" output as reported by ThaPrince
- Updated RELNOTES

File Contents

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

Properties

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