1 |
/* |
2 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
* |
4 |
* Copyright (c) 1997-2019 ircd-hybrid development team |
5 |
* |
6 |
* This program is free software; you can redistribute it and/or modify |
7 |
* it under the terms of the GNU General Public License as published by |
8 |
* the Free Software Foundation; either version 2 of the License, or |
9 |
* (at your option) any later version. |
10 |
* |
11 |
* This program is distributed in the hope that it will be useful, |
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
* GNU General Public License for more details. |
15 |
* |
16 |
* You should have received a copy of the GNU General Public License |
17 |
* along with this program; if not, write to the Free Software |
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
19 |
* USA |
20 |
*/ |
21 |
|
22 |
/*! \file m_hash.c |
23 |
* \brief Includes required functions for processing the HASH command. |
24 |
* \version $Id$ |
25 |
*/ |
26 |
|
27 |
#include "stdinc.h" |
28 |
#include "list.h" |
29 |
#include "client.h" |
30 |
#include "hash.h" |
31 |
#include "ircd.h" |
32 |
#include "numeric.h" |
33 |
#include "send.h" |
34 |
#include "parse.h" |
35 |
#include "modules.h" |
36 |
|
37 |
|
38 |
/*! \brief HASH command handler |
39 |
* |
40 |
* \param source_p Pointer to allocated Client struct from which the message |
41 |
* originally comes from. This can be a local or remote client. |
42 |
* \param parc Integer holding the number of supplied arguments. |
43 |
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
44 |
* pointers. |
45 |
* \note Valid arguments for this command are: |
46 |
* - parv[0] = command |
47 |
*/ |
48 |
static int |
49 |
mo_hash(struct Client *source_p, int parc, char *parv[]) |
50 |
{ |
51 |
unsigned int i = 0; |
52 |
unsigned int max_chain = 0; |
53 |
unsigned int buckets = 0; |
54 |
unsigned int count = 0; |
55 |
const struct Client *cl = NULL; |
56 |
const struct Client *icl = NULL; |
57 |
const struct Channel *ch = NULL; |
58 |
|
59 |
for (i = 0; i < HASHSIZE; ++i) |
60 |
{ |
61 |
if ((cl = hash_get_bucket(HASH_TYPE_CLIENT, i))) |
62 |
{ |
63 |
unsigned int len = 0; |
64 |
|
65 |
++buckets; |
66 |
for (; cl; cl = cl->hnext) |
67 |
++len; |
68 |
if (len > max_chain) |
69 |
max_chain = len; |
70 |
count += len; |
71 |
} |
72 |
} |
73 |
|
74 |
sendto_one_notice(source_p, &me, ":Client: entries: %u buckets: %u " |
75 |
"max chain: %u", count, buckets, max_chain); |
76 |
|
77 |
count = 0; |
78 |
buckets = 0; |
79 |
max_chain = 0; |
80 |
|
81 |
for (i = 0; i < HASHSIZE; ++i) |
82 |
{ |
83 |
if ((ch = hash_get_bucket(HASH_TYPE_CHANNEL, i))) |
84 |
{ |
85 |
unsigned int len = 0; |
86 |
|
87 |
++buckets; |
88 |
for (; ch; ch = ch->hnextch) |
89 |
++len; |
90 |
if (len > max_chain) |
91 |
max_chain = len; |
92 |
count += len; |
93 |
} |
94 |
} |
95 |
|
96 |
sendto_one_notice(source_p, &me, ":Channel: entries: %u buckets: %u " |
97 |
"max chain: %u", count, buckets, max_chain); |
98 |
|
99 |
count = 0; |
100 |
buckets = 0; |
101 |
max_chain = 0; |
102 |
|
103 |
for (i = 0; i < HASHSIZE; ++i) |
104 |
{ |
105 |
if ((icl = hash_get_bucket(HASH_TYPE_ID, i))) |
106 |
{ |
107 |
unsigned int len = 0; |
108 |
|
109 |
++buckets; |
110 |
for (; icl; icl = icl->idhnext) |
111 |
++len; |
112 |
if (len > max_chain) |
113 |
max_chain = len; |
114 |
count += len; |
115 |
} |
116 |
} |
117 |
|
118 |
sendto_one_notice(source_p, &me, ":Id: entries: %u buckets: %u " |
119 |
"max chain: %u", count, buckets, max_chain); |
120 |
return 0; |
121 |
} |
122 |
|
123 |
static struct Message hash_msgtab = |
124 |
{ |
125 |
.cmd = "HASH", |
126 |
.args_max = MAXPARA, |
127 |
.handlers[UNREGISTERED_HANDLER] = m_unregistered, |
128 |
.handlers[CLIENT_HANDLER] = m_not_oper, |
129 |
.handlers[SERVER_HANDLER] = m_ignore, |
130 |
.handlers[ENCAP_HANDLER] = m_ignore, |
131 |
.handlers[OPER_HANDLER] = mo_hash |
132 |
}; |
133 |
|
134 |
static void |
135 |
module_init(void) |
136 |
{ |
137 |
mod_add_cmd(&hash_msgtab); |
138 |
} |
139 |
|
140 |
static void |
141 |
module_exit(void) |
142 |
{ |
143 |
mod_del_cmd(&hash_msgtab); |
144 |
} |
145 |
|
146 |
struct module module_entry = |
147 |
{ |
148 |
.version = "$Revision$", |
149 |
.modinit = module_init, |
150 |
.modexit = module_exit, |
151 |
}; |