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

Properties

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