ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/modules/m_stats.c
Revision: 69
Committed: Tue Oct 4 16:09:51 2005 UTC (20 years, 10 months ago) by adx
Content type: text/x-csrc
File size: 46168 byte(s)
Log Message:
- splitted ircd/libio, all headers connected with libio sources have been
  moved for internal use only. To use libio interface, include "libio.h"
  (which is already done in "stdinc.h")


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

Properties

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