ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/modules/m_stats.c
Revision: 526
Committed: Sat Mar 18 11:04:52 2006 UTC (20 years, 4 months ago) by michael
Content type: text/x-csrc
File size: 44301 byte(s)
Log Message:
- misc cleanups for better readability to m_stats.c

File Contents

# Content
1 /*
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 * $Id$
23 */
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 #include "conf/modules.h"
42 #include "resv.h" /* report_resv */
43 #include "whowas.h"
44 #include "watch.h"
45
46 static void *do_stats(va_list args);
47 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 { m_unregistered, m_stats, mo_stats, m_ignore, mo_stats, m_ignore }
53 };
54
55 static struct Callback *stats_cb;
56
57 INIT_MODULE(m_stats, "$Revision$")
58 {
59 stats_cb = register_callback("doing_stats", do_stats);
60 mod_add_cmd(&stats_msgtab);
61 }
62
63 CLEANUP_MODULE
64 {
65 mod_del_cmd(&stats_msgtab);
66 uninstall_hook(stats_cb, do_stats);
67 }
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 static void stats_hooks(struct Client *);
103 static void fd_dump(struct Client *);
104
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 static void *
165 do_stats(va_list args)
166 {
167 struct Client *source_p = va_arg(args, struct Client *);
168 int parc = va_arg(args, int);
169 char **parv = va_arg(args, char **);
170 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 return NULL;
178 }
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 return NULL;
206 }
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 if (hunt_server(client_p, source_p, ":%s STATS %s :%s", 2,
226 parc, parv) != HUNTED_ISME)
227 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 last_used = CurrentTime;
249
250 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 if (!IsClient(source_p))
267 return;
268
269 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 #ifdef hz
302 # 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 BlockHeap *bh;
356 const dlink_node *gptr = NULL;
357 const dlink_node *dlink = NULL;
358
359 int users_counted = 0; /* real Clients counted, i.e. not a server */
360
361 int channel_users = 0; /* XXX */
362 unsigned int channel_invites = 0;
363 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 unsigned int wlh = 0; /* watchlist headers */
399 unsigned int wle = 0; /* watchlist entries */
400 unsigned int wlhm = 0; /* watchlist memory used */
401
402 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 wle += dlink_list_length(&target_p->localClient->watches);
410 }
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 count_watch_memory(&wlh, &wlhm);
499
500 sendto_one(source_p, ":%s %d %s z :WATCH headers %u(%u) entries %d(%d)",
501 me.name, RPL_STATSDEBUG, source_p->name, wlh, wlhm, wle,
502 wle * sizeof(dlink_node));
503
504 /* count up all classes */
505 class_count = dlink_list_length(&class_items);
506
507 sendto_one(source_p, ":%s %d %s z :Clients %u(%lu)",
508 me.name, RPL_STATSDEBUG, source_p->name, users_counted,
509 (unsigned long)(users_counted * sizeof(struct Client)));
510
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 sendto_one(source_p, ":%s %d %s z :Channel members %u(%lu) invites %u(%u)",
545 me.name, RPL_STATSDEBUG, source_p->name, channel_users,
546 (unsigned long)(channel_users * sizeof(struct Membership)),
547 channel_invites, channel_invites * sizeof(dlink_node) * 2);
548
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
557 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 total_memory = total_channel_memory + conf_memory + class_count *
563 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 sendto_one(source_p, ":%s %d %s z :Total: channel %d conf %d",
570 me.name, RPL_STATSDEBUG, source_p->name,
571 (int)total_channel_memory, (int)conf_memory);
572
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 for (bh = heap_list; bh != NULL; bh = bh->next)
586 sendto_one(source_p,
587 ":%s %d %s z :%s mempool: used %u/%u free %u/%u (size %u/%u)",
588 me.name, RPL_STATSDEBUG, source_p->name, bh->name,
589 block_heap_get_used_elm(bh),
590 block_heap_get_used_mem(bh),
591 block_heap_get_free_elm(bh),
592 block_heap_get_free_mem(bh),
593 block_heap_get_size_elm(bh),
594 block_heap_get_size_mem(bh));
595
596 sendto_one(source_p,
597 ":%s %d %s z :TOTAL: %d Available: Current max RSS: %lu",
598 me.name, RPL_STATSDEBUG, source_p->name,
599 (int)total_memory, get_maxrss());
600 }
601
602 static void
603 stats_connect(struct Client *source_p)
604 {
605 report_confitem_types(source_p, SERVER_TYPE, 0);
606 }
607
608 /* stats_deny()
609 *
610 * input - client to report to
611 * output - none
612 * side effects - client is given dline list.
613 */
614 static void
615 stats_deny(struct Client *source_p)
616 {
617 struct AddressRec *arec;
618 struct ConfItem *conf;
619 struct AccessItem *aconf;
620 int i;
621
622 for (i = 0; i < ATABLE_SIZE; ++i)
623 {
624 for (arec = atable[i]; arec; arec=arec->next)
625 {
626 if (arec->type == CONF_DLINE)
627 {
628 aconf = arec->aconf;
629
630 /* dont report a tdline as a dline */
631 if (aconf->flags & CONF_FLAGS_TEMPORARY)
632 continue;
633
634 conf = aconf->conf_ptr;
635
636 sendto_one(source_p, form_str(RPL_STATSDLINE),
637 from, to, 'D', aconf->host, aconf->reason,
638 aconf->oper_reason);
639 }
640 }
641 }
642 }
643
644 /* stats_tdeny()
645 *
646 * input - client to report to
647 * output - none
648 * side effects - client is given dline list.
649 */
650 static void
651 stats_tdeny(struct Client *source_p)
652 {
653 struct AddressRec *arec;
654 struct ConfItem *conf;
655 struct AccessItem *aconf;
656 int i;
657
658 for (i = 0; i < ATABLE_SIZE; ++i)
659 {
660 for (arec = atable[i]; arec; arec=arec->next)
661 {
662 if (arec->type == CONF_DLINE)
663 {
664 aconf = arec->aconf;
665
666 /* dont report a permanent dline as a tdline */
667 if (!(aconf->flags & CONF_FLAGS_TEMPORARY))
668 continue;
669
670 conf = aconf->conf_ptr;
671
672 sendto_one(source_p, form_str(RPL_STATSDLINE),
673 from, to, 'd', aconf->host, aconf->reason,
674 aconf->oper_reason);
675 }
676 }
677 }
678 }
679
680 /* stats_exempt()
681 *
682 * input - client to report to
683 * output - none
684 * side effects - client is given list of exempt blocks
685 */
686 static void
687 stats_exempt(struct Client *source_p)
688 {
689 struct AddressRec *arec;
690 struct ConfItem *conf;
691 struct AccessItem *aconf;
692 int i;
693
694 for (i = 0; i < ATABLE_SIZE; ++i)
695 {
696 for (arec = atable[i]; arec; arec=arec->next)
697 {
698 if (arec->type == CONF_EXEMPTDLINE)
699 {
700 aconf = arec->aconf;
701
702 conf = aconf->conf_ptr;
703
704 sendto_one(source_p, form_str(RPL_STATSDLINE),
705 from, to, 'e', aconf->host,
706 aconf->reason, aconf->oper_reason);
707 }
708 }
709 }
710 }
711
712 /* stats_pending_glines()
713 *
714 * input - client pointer
715 * output - none
716 * side effects - client is shown list of pending glines
717 */
718 static void
719 stats_pending_glines(struct Client *source_p)
720 {
721 #ifdef GLINE_VOTING
722 dlink_node *pending_node;
723 struct gline_pending *glp_ptr;
724 char timebuffer[MAX_DATE_STRING];
725 struct tm *tmptr;
726
727 if (!ConfigFileEntry.glines)
728 {
729 sendto_one(source_p, ":%s NOTICE %s :This server does not support G-Lines",
730 from, to);
731 return;
732 }
733
734 if (dlink_list_length(&pending_glines) > 0)
735 sendto_one(source_p, ":%s NOTICE %s :Pending G-lines",
736 from, to);
737
738 DLINK_FOREACH(pending_node, pending_glines.head)
739 {
740 glp_ptr = pending_node->data;
741 tmptr = localtime(&glp_ptr->time_request1);
742 strftime(timebuffer, MAX_DATE_STRING, "%Y/%m/%d %H:%M:%S", tmptr);
743
744 sendto_one(source_p,
745 ":%s NOTICE %s :1) %s!%s@%s on %s requested gline at %s for %s@%s [%s]",
746 from, to, glp_ptr->oper_nick1,
747 glp_ptr->oper_user1, glp_ptr->oper_host1,
748 glp_ptr->oper_server1, timebuffer,
749 glp_ptr->user, glp_ptr->host, glp_ptr->reason1);
750
751 if (glp_ptr->oper_nick2[0] != '\0')
752 {
753 tmptr = localtime(&glp_ptr->time_request2);
754 strftime(timebuffer, MAX_DATE_STRING, "%Y/%m/%d %H:%M:%S", tmptr);
755 sendto_one(source_p,
756 ":%s NOTICE %s :2) %s!%s@%s on %s requested gline at %s for %s@%s [%s]",
757 from, to, glp_ptr->oper_nick2,
758 glp_ptr->oper_user2, glp_ptr->oper_host2,
759 glp_ptr->oper_server2, timebuffer,
760 glp_ptr->user, glp_ptr->host, glp_ptr->reason2);
761 }
762 }
763
764 sendto_one(source_p, ":%s NOTICE %s :End of Pending G-lines",
765 from, to);
766 #else
767 sendto_one(source_p, ":%s NOTICE %s :This server does not support G-Line voting",
768 from, to);
769 #endif /* GLINE VOTING */
770 }
771
772 /* stats_glines()
773 *
774 * input - client pointer
775 * output - none
776 * side effects - client is shown list of glines
777 */
778 static void
779 stats_glines(struct Client *source_p)
780 {
781 struct AddressRec *arec = NULL;
782 int i = 0;
783
784 if (!ConfigFileEntry.glines)
785 {
786 sendto_one(source_p, ":%s NOTICE %s :This server does not support G-Lines",
787 from, to);
788 return;
789 }
790
791 for (; i < ATABLE_SIZE; ++i)
792 {
793 for (arec = atable[i]; arec; arec=arec->next)
794 {
795 if (arec->type == CONF_GLINE)
796 {
797 const struct AccessItem *aconf = arec->aconf;
798
799 sendto_one(source_p, form_str(RPL_STATSKLINE),
800 from, to, "G",
801 aconf->host ? aconf->host : "*",
802 aconf->user ? aconf->user : "*",
803 aconf->reason ? aconf->reason : "No reason", "" );
804 }
805 }
806 }
807 }
808
809 /* stats_gdeny()
810 *
811 * input - client pointer
812 * outputs - none
813 * side effects - client is shown gline ACL
814 */
815 static void
816 stats_gdeny(struct Client *source_p)
817 {
818 if (!ConfigFileEntry.glines)
819 {
820 sendto_one(source_p, ":%s NOTICE %s :This server does not support G-Lines",
821 from, to);
822 return;
823 }
824
825 report_confitem_types(source_p, GDENY_TYPE, 0);
826 }
827
828 static void
829 stats_hubleaf(struct Client *source_p)
830 {
831 report_confitem_types(source_p, HUB_TYPE, 0);
832 report_confitem_types(source_p, LEAF_TYPE, 0);
833 }
834
835 static void
836 stats_auth(struct Client *source_p)
837 {
838 /* Oper only, if unopered, return ERR_NOPRIVILEGES */
839 if ((ConfigFileEntry.stats_i_oper_only == 2) && !IsOper(source_p))
840 sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
841 from, to);
842
843 /* If unopered, Only return matching auth blocks */
844 else if ((ConfigFileEntry.stats_i_oper_only == 1) && !IsOper(source_p))
845 {
846 struct ConfItem *conf;
847 struct AccessItem *aconf;
848
849 if (MyConnect(source_p))
850 aconf = find_conf_by_address(source_p->host,
851 &source_p->localClient->ip,
852 CONF_CLIENT,
853 source_p->localClient->aftype,
854 source_p->username,
855 source_p->localClient->passwd);
856 else
857 aconf = find_conf_by_address(source_p->host, NULL, CONF_CLIENT,
858 0, source_p->username, NULL);
859
860 if (aconf == NULL)
861 return;
862
863 conf = aconf->conf_ptr;
864
865 sendto_one(source_p, form_str(RPL_STATSILINE), from,
866 to, 'I', "*",
867 make_iline_prefix(source_p, aconf), aconf->user,
868 aconf->host, aconf->port,
869 aconf->class_ptr ? aconf->class_ptr->name : "<default>");
870 }
871 /* They are opered, or allowed to see all auth blocks */
872 else
873 report_auth(source_p);
874 }
875
876 static void
877 stats_tklines(struct Client *source_p)
878 {
879 struct ConfItem *conf;
880 /* Oper only, if unopered, return ERR_NOPRIVILEGES */
881 if ((ConfigFileEntry.stats_k_oper_only == 2) && !IsOper(source_p))
882 sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
883 from, to);
884
885 /* If unopered, Only return matching klines */
886 else if ((ConfigFileEntry.stats_k_oper_only == 1) && !IsOper(source_p))
887 {
888 struct AccessItem *aconf;
889
890 if (MyConnect(source_p))
891 aconf = find_conf_by_address(source_p->host,
892 &source_p->localClient->ip,
893 CONF_KILL,
894 source_p->localClient->aftype,
895 source_p->username, NULL);
896 else
897 aconf = find_conf_by_address(source_p->host, NULL, CONF_KILL,
898 0, source_p->username, NULL);
899
900 if (aconf == NULL)
901 return;
902
903 /* dont report a permanent kline as a tkline */
904 if (!(aconf->flags & CONF_FLAGS_TEMPORARY))
905 return;
906
907 conf = aconf->conf_ptr;
908
909 sendto_one(source_p, form_str(RPL_STATSKLINE), from,
910 to, "k", aconf->host, aconf->user, aconf->reason, "");
911 }
912 /* Theyre opered, or allowed to see all klines */
913 else
914 {
915 report_Klines(source_p, 1);
916 report_confitem_types(source_p, RKLINE_TYPE, 1);
917 }
918 }
919
920 static void
921 stats_klines(struct Client *source_p)
922 {
923 /* Oper only, if unopered, return ERR_NOPRIVILEGES */
924 if ((ConfigFileEntry.stats_k_oper_only == 2) && !IsOper(source_p))
925 sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
926 from, to);
927
928 /* If unopered, Only return matching klines */
929 else if ((ConfigFileEntry.stats_k_oper_only == 1) && !IsOper(source_p))
930 {
931 struct AccessItem *aconf;
932
933 /* search for a kline */
934 if (MyConnect(source_p))
935 aconf = find_conf_by_address(source_p->host,
936 &source_p->localClient->ip,
937 CONF_KILL,
938 source_p->localClient->aftype,
939 source_p->username, NULL);
940 else
941 aconf = find_conf_by_address(source_p->host, NULL, CONF_KILL,
942 0, source_p->username, NULL);
943
944 if (aconf == NULL)
945 return;
946
947 /* dont report a tkline as a kline */
948 if (aconf->flags & CONF_FLAGS_TEMPORARY)
949 return;
950
951 sendto_one(source_p, form_str(RPL_STATSKLINE), from,
952 to, "K", aconf->host, aconf->user, aconf->reason,
953 aconf->oper_reason);
954 }
955 /* Theyre opered, or allowed to see all klines */
956 else
957 {
958 report_Klines(source_p, 0);
959 report_confitem_types(source_p, RKLINE_TYPE, 0);
960 }
961 }
962
963 static void
964 stats_messages(struct Client *source_p)
965 {
966 report_messages(source_p);
967 }
968
969 static void
970 stats_oper(struct Client *source_p)
971 {
972 if (!IsOper(source_p) && ConfigFileEntry.stats_o_oper_only)
973 sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
974 from, to);
975 else
976 report_confitem_types(source_p, OPER_TYPE, 0);
977 }
978
979 /* stats_operedup()
980 *
981 * input - client pointer
982 * output - none
983 * side effects - client is shown a list of active opers
984 */
985 static void
986 stats_operedup(struct Client *source_p)
987 {
988 dlink_node *ptr;
989
990 DLINK_FOREACH(ptr, oper_list.head)
991 {
992 const struct Client *target_p = ptr->data;
993
994 if (IsOperHidden(target_p) && !IsOper(source_p))
995 continue;
996
997 if (MyClient(source_p) && IsOper(source_p))
998 sendto_one(source_p, ":%s %d %s p :[%c][%s] %s (%s@%s) Idle: %d",
999 from, RPL_STATSDEBUG, to,
1000 IsAdmin(target_p) ?
1001 (IsOperHiddenAdmin(target_p) ? 'O' : 'A') : 'O',
1002 oper_privs_as_string(target_p->localClient->operflags),
1003 target_p->name, target_p->username, target_p->host,
1004 (int)(CurrentTime - target_p->localClient->last));
1005 else
1006 sendto_one(source_p, ":%s %d %s p :[%c] %s (%s@%s) Idle: %d",
1007 from, RPL_STATSDEBUG, to,
1008 IsAdmin(target_p) ?
1009 (IsOperHiddenAdmin(target_p) ? 'O' : 'A') : 'O',
1010 target_p->name, target_p->username, target_p->host,
1011 (int)(CurrentTime - target_p->localClient->last));
1012 }
1013
1014 sendto_one(source_p, ":%s %d %s p :%lu OPER(s)",
1015 from, RPL_STATSDEBUG, to, dlink_list_length(&oper_list));
1016 }
1017
1018 static void
1019 stats_ports(struct Client *source_p)
1020 {
1021 if (!IsOper(source_p) && ConfigFileEntry.stats_P_oper_only)
1022 sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
1023 from, to);
1024 else
1025 show_ports(source_p);
1026 }
1027
1028 static void
1029 stats_resv(struct Client *source_p)
1030 {
1031 report_resv(source_p);
1032 }
1033
1034 static void
1035 stats_usage(struct Client *source_p)
1036 {
1037 send_usage(source_p);
1038 }
1039
1040 static void
1041 stats_tstats(struct Client *source_p)
1042 {
1043 const struct Client *target_p = NULL;
1044 struct ServerStatistics sp;
1045 dlink_node *ptr = NULL;
1046
1047 memcpy(&sp, &ServerStats, sizeof(sp));
1048
1049 /*
1050 * must use the += operator. is_sv is not the number of currently
1051 * active server connections. Note the incrementation in
1052 * s_bsd.c:close_connection.
1053 */
1054 sp.is_sv += dlink_list_length(&serv_list);
1055
1056 DLINK_FOREACH(ptr, serv_list.head)
1057 {
1058 target_p = ptr->data;
1059
1060 sp.is_sbs += target_p->localClient->send.bytes;
1061 sp.is_sbr += target_p->localClient->recv.bytes;
1062 sp.is_sti += CurrentTime - target_p->firsttime;
1063 }
1064
1065 sp.is_cl += dlink_list_length(&local_client_list);
1066
1067 DLINK_FOREACH(ptr, local_client_list.head)
1068 {
1069 target_p = ptr->data;
1070
1071 sp.is_cbs += target_p->localClient->send.bytes;
1072 sp.is_cbr += target_p->localClient->recv.bytes;
1073 sp.is_cti += CurrentTime - target_p->firsttime;
1074 }
1075
1076 sp.is_ni += dlink_list_length(&unknown_list);
1077
1078 sendto_one(source_p, ":%s %d %s T :accepts %u refused %u",
1079 me.name, RPL_STATSDEBUG, source_p->name, sp.is_ac, sp.is_ref);
1080 sendto_one(source_p, ":%s %d %s T :unknown commands %u prefixes %u",
1081 me.name, RPL_STATSDEBUG, source_p->name, sp.is_unco, sp.is_unpf);
1082 sendto_one(source_p, ":%s %d %s T :nick collisions %u unknown closes %u",
1083 me.name, RPL_STATSDEBUG, source_p->name, sp.is_kill, sp.is_ni);
1084 sendto_one(source_p, ":%s %d %s T :wrong direction %u empty %u",
1085 me.name, RPL_STATSDEBUG, source_p->name, sp.is_wrdi, sp.is_empt);
1086 sendto_one(source_p, ":%s %d %s T :numerics seen %u",
1087 me.name, RPL_STATSDEBUG, source_p->name, sp.is_num);
1088 sendto_one(source_p, ":%s %d %s T :auth successes %u fails %u",
1089 me.name, RPL_STATSDEBUG, source_p->name, sp.is_asuc, sp.is_abad);
1090 sendto_one(source_p, ":%s %d %s T :Client Server",
1091 me.name, RPL_STATSDEBUG, source_p->name);
1092
1093 sendto_one(source_p, ":%s %d %s T :connected %u %u",
1094 me.name, RPL_STATSDEBUG, source_p->name,
1095 (unsigned int)sp.is_cl,
1096 (unsigned int)sp.is_sv);
1097 sendto_one(source_p, ":%s %d %s T :bytes sent %llu %llu",
1098 me.name, RPL_STATSDEBUG, source_p->name,
1099 sp.is_cbs, sp.is_sbs);
1100 sendto_one(source_p, ":%s %d %s T :bytes recv %llu %llu",
1101 me.name, RPL_STATSDEBUG, source_p->name,
1102 sp.is_cbr, sp.is_sbr);
1103 sendto_one(source_p, ":%s %d %s T :time connected %u %u",
1104 me.name, RPL_STATSDEBUG, source_p->name,
1105 (unsigned int)sp.is_cti,
1106 (unsigned int)sp.is_sti);
1107 }
1108
1109 static void
1110 stats_uptime(struct Client *source_p)
1111 {
1112 time_t now = CurrentTime - me.since;
1113 sendto_one(source_p, form_str(RPL_STATSUPTIME), from, to,
1114 now/86400, (now/3600)%24, (now/60)%60, now%60);
1115 if (!ConfigFileEntry.disable_remote || IsOper(source_p))
1116 sendto_one(source_p, form_str(RPL_STATSCONN), from, to,
1117 MaxConnectionCount, MaxClientCount, Count.totalrestartcount);
1118 }
1119
1120 static void
1121 stats_shared(struct Client *source_p)
1122 {
1123 report_confitem_types(source_p, ULINE_TYPE, 0);
1124 }
1125
1126 /* stats_servers()
1127 *
1128 * input - client pointer
1129 * output - none
1130 * side effects - client is shown lists of who connected servers
1131 */
1132 static void
1133 stats_servers(struct Client *source_p)
1134 {
1135 dlink_node *ptr = NULL;
1136
1137 DLINK_FOREACH(ptr, serv_list.head)
1138 {
1139 const struct Client *target_p = ptr->data;
1140
1141 sendto_one(source_p, ":%s %d %s v :%s (%s!%s@%s) Idle: %d",
1142 from, RPL_STATSDEBUG, to,
1143 target_p->name,
1144 (target_p->serv->by[0] ? target_p->serv->by : "Remote."),
1145 "*", "*", (int)(CurrentTime - target_p->lasttime));
1146 }
1147
1148 sendto_one(source_p, ":%s %d %s v :%lu Server(s)",
1149 from, RPL_STATSDEBUG, to,
1150 dlink_list_length(&serv_list));
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 dlink_node *ptr = NULL;
1212
1213 if (ConfigServerHide.flatten_links && !IsOper(source_p))
1214 {
1215 sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
1216 from, to);
1217 return;
1218 }
1219
1220 DLINK_FOREACH(ptr, serv_list.head)
1221 {
1222 struct Client *target_p = ptr->data;
1223
1224 sendB += target_p->localClient->send.bytes;
1225 recvB += target_p->localClient->recv.bytes;
1226
1227 /* ":%s 211 %s %s %u %u %llu %u %llu :%u %u %s" */
1228 sendto_one(source_p, form_str(RPL_STATSLINKINFO),
1229 from, to,
1230 get_client_name(target_p, IsAdmin(source_p) ? SHOW_IP : MASK_IP),
1231 dbuf_length(&target_p->localClient->buf_sendq),
1232 target_p->localClient->send.messages,
1233 target_p->localClient->send.bytes >> 10,
1234 target_p->localClient->recv.messages,
1235 target_p->localClient->recv.bytes >> 10,
1236 (unsigned)(CurrentTime - target_p->firsttime),
1237 (CurrentTime > target_p->since) ? (unsigned)(CurrentTime - target_p->since): 0,
1238 IsOper(source_p) ? show_capabilities(target_p) : "TS");
1239 }
1240
1241 sendB >>= 10;
1242 recvB >>= 10;
1243
1244 sendto_one(source_p, ":%s %d %s ? :%u total server(s)",
1245 from, RPL_STATSDEBUG, to, dlink_list_length(&serv_list));
1246 sendto_one(source_p, ":%s %d %s ? :Sent total : %7.2f %s",
1247 from, RPL_STATSDEBUG, to,
1248 _GMKv((signed)sendB), _GMKs((signed)sendB));
1249 sendto_one(source_p, ":%s %d %s ? :Recv total : %7.2f %s",
1250 from, RPL_STATSDEBUG, to,
1251 _GMKv((signed)recvB), _GMKs((signed)recvB));
1252
1253 uptime = (CurrentTime - me.since);
1254
1255 sendto_one(source_p, ":%s %d %s ? :Server send: %7.2f %s (%4.1f K/s)",
1256 from, RPL_STATSDEBUG, to,
1257 _GMKv((signed)(me.localClient->send.bytes>>10)),
1258 _GMKs((signed)(me.localClient->send.bytes>>10)),
1259 (float)((float)(((signed)me.localClient->send.bytes) >> 10) /
1260 (float)uptime));
1261 sendto_one(source_p, ":%s %d %s ? :Server recv: %7.2f %s (%4.1f K/s)",
1262 from, RPL_STATSDEBUG, to,
1263 _GMKv((signed)(me.localClient->recv.bytes>>10)),
1264 _GMKs((signed)(me.localClient->recv.bytes>>10)),
1265 (float)((float)(((signed)me.localClient->recv.bytes) >> 10) /
1266 (float)uptime));
1267 }
1268
1269 static void
1270 stats_ltrace(struct Client *source_p, int parc, char *parv[])
1271 {
1272 int doall = 0;
1273 int wilds = 0;
1274 char *name = NULL;
1275 char statchar;
1276
1277 if ((name = parse_stats_args(parc, parv, &doall, &wilds)) != NULL)
1278 {
1279 statchar = *parv[1];
1280
1281 stats_L(source_p, name, doall, wilds, statchar);
1282 }
1283 else
1284 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
1285 from, to, "STATS");
1286 }
1287
1288 static void
1289 stats_hooks(struct Client *source_p)
1290 {
1291 dlink_node *ptr;
1292 struct Callback *cb;
1293 char lastused[32];
1294
1295 sendto_one(source_p, ":%s %d %s : %-20s %-20s Used Hooks", me.name,
1296 RPL_STATSDEBUG, source_p->name, "Callback", "Last Execution");
1297 sendto_one(source_p, ":%s %d %s : ------------------------------------"
1298 "--------------------", me.name, RPL_STATSDEBUG, source_p->name);
1299
1300 DLINK_FOREACH(ptr, callback_list.head)
1301 {
1302 cb = ptr->data;
1303
1304 if (cb->last != 0)
1305 snprintf(lastused, sizeof(lastused), "%d seconds ago",
1306 (int) (CurrentTime - cb->last));
1307 else
1308 strcpy(lastused, "NEVER");
1309
1310 sendto_one(source_p, ":%s %d %s : %-20s %-20s %-8u %d", me.name,
1311 RPL_STATSDEBUG, source_p->name, cb->name, lastused, cb->called,
1312 dlink_list_length(&cb->chain));
1313 }
1314
1315 sendto_one(source_p, ":%s %d %s : ", me.name, RPL_STATSDEBUG,
1316 source_p->name);
1317 }
1318
1319 static void
1320 stats_events(struct Client *source_p)
1321 {
1322 int i;
1323
1324 if (last_event_ran)
1325 {
1326 sendto_one(source_p, ":%s %d %s :Last event to run: %s",
1327 me.name, RPL_STATSDEBUG, source_p->name, last_event_ran);
1328 sendto_one(source_p, ":%s %d %s : ",
1329 me.name, RPL_STATSDEBUG, source_p->name);
1330 }
1331
1332 sendto_one(source_p,
1333 ":%s %d %s : Operation Next Execution",
1334 me.name, RPL_STATSDEBUG, source_p->name);
1335 sendto_one(source_p,
1336 ":%s %d %s : -------------------------------------------",
1337 me.name, RPL_STATSDEBUG, source_p->name);
1338
1339 for (i = 0; i < MAX_EVENTS; i++)
1340 if (event_table[i].active)
1341 {
1342 sendto_one(source_p, ":%s %d %s : %-28s %-4d seconds",
1343 me.name, RPL_STATSDEBUG, source_p->name,
1344 event_table[i].name,
1345 (int)(event_table[i].when - CurrentTime));
1346 }
1347
1348 sendto_one(source_p, ":%s %d %s : ",
1349 me.name, RPL_STATSDEBUG, source_p->name);
1350 }
1351
1352 static void
1353 stats_dns_servers(struct Client *source_p)
1354 {
1355 int i;
1356 char ipaddr[HOSTIPLEN];
1357
1358 for (i = 0; i < irc_nscount; ++i)
1359 {
1360 irc_getnameinfo((struct sockaddr *)&(irc_nsaddr_list[i]),
1361 irc_nsaddr_list[i].ss_len, ipaddr, sizeof(ipaddr), NULL, 0,
1362 NI_NUMERICHOST);
1363 sendto_one(source_p, form_str(RPL_STATSALINE),
1364 me.name, source_p->name, ipaddr);
1365 }
1366 }
1367
1368 static void
1369 fd_dump(struct Client *source_p)
1370 {
1371 int i;
1372 fde_t *F;
1373
1374 for (i = 0; i < FD_HASH_SIZE; i++)
1375 for (F = fd_hash[i]; F != NULL; F = F->hnext)
1376 sendto_one(source_p, ":%s %d %s :fd %-5d desc '%s'",
1377 me.name, RPL_STATSDEBUG, source_p->name,
1378 F->fd, F->desc);
1379 }
1380
1381 /*
1382 * stats_L
1383 *
1384 * inputs - pointer to client to report to
1385 * - doall flag
1386 * - wild card or not
1387 * output - NONE
1388 * side effects -
1389 */
1390 static void
1391 stats_L(struct Client *source_p,char *name,int doall,
1392 int wilds,char statchar)
1393 {
1394 stats_L_list(source_p, name, doall, wilds, &unknown_list, statchar);
1395 stats_L_list(source_p, name, doall, wilds, &local_client_list, statchar);
1396 stats_L_list(source_p, name, doall, wilds, &serv_list, statchar);
1397 }
1398
1399 static void
1400 stats_L_list(struct Client *source_p, char *name, int doall, int wilds,
1401 dlink_list *list, char statchar)
1402 {
1403 dlink_node *ptr = NULL;
1404
1405 /*
1406 * send info about connections which match, or all if the
1407 * mask matches from. Only restrictions are on those who
1408 * are invisible not being visible to 'foreigners' who use
1409 * a wild card based search to list it.
1410 */
1411 DLINK_FOREACH(ptr, list->head)
1412 {
1413 int ip_action = 0;
1414 const struct Client *target_p = ptr->data;
1415
1416 if (IsInvisible(target_p) && (doall || wilds) &&
1417 !(MyConnect(source_p) && IsOper(source_p)) &&
1418 !IsOper(target_p) && (target_p != source_p))
1419 continue;
1420 if (!doall && wilds && !match(name, target_p->name))
1421 continue;
1422 if (!(doall || wilds) && irccmp(name, target_p->name))
1423 continue;
1424
1425 if (IsIPSpoof(target_p) || IsServer(target_p) || IsAdmin(target_p) ||
1426 IsHandshake(target_p) || IsConnecting(target_p))
1427 ip_action = MASK_IP;
1428 else if (IsUpper(statchar))
1429 ip_action = SHOW_IP;
1430 else
1431 ip_action = HIDE_IP;
1432
1433 sendto_one(source_p, form_str(RPL_STATSLINKINFO),
1434 from, to, get_client_name(target_p, ip_action),
1435 dbuf_length(&target_p->localClient->buf_sendq),
1436 target_p->localClient->send.messages,
1437 target_p->localClient->send.bytes>>10,
1438 target_p->localClient->recv.messages,
1439 target_p->localClient->recv.bytes>>10,
1440 (unsigned)(CurrentTime - target_p->firsttime),
1441 (CurrentTime > target_p->since) ? (unsigned)(CurrentTime - target_p->since):0,
1442 IsServer(target_p) ? show_capabilities(target_p) : "-");
1443 }
1444 }
1445
1446 /* parse_stats_args()
1447 *
1448 * inputs - arg count
1449 * - args
1450 * - doall flag
1451 * - wild card or not
1452 * output - pointer to name to use
1453 * side effects -
1454 * common parse routine for m_stats args
1455 *
1456 */
1457 static char *
1458 parse_stats_args(int parc, char *parv[], int *doall, int *wilds)
1459 {
1460 char *name;
1461
1462 if (parc > 2)
1463 {
1464 name = parv[2];
1465
1466 if (!irccmp(name, from))
1467 *doall = 2;
1468 else if (match(name, from))
1469 *doall = 1;
1470
1471 if (has_wildcards(name))
1472 *wilds = 1;
1473
1474 return name;
1475 }
1476
1477 return NULL;
1478 }

Properties

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