1 |
/* |
2 |
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
3 |
* m_list.c: List channel given or all channels. |
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 "tools.h" |
27 |
#include "handlers.h" |
28 |
#include "channel.h" |
29 |
#include "channel_mode.h" |
30 |
#include "client.h" |
31 |
#include "hash.h" |
32 |
#include "irc_string.h" |
33 |
#include "ircd.h" |
34 |
#include "numeric.h" |
35 |
#include "s_conf.h" |
36 |
#include "s_serv.h" |
37 |
#include "send.h" |
38 |
#include "list.h" |
39 |
#include "msg.h" |
40 |
#include "parse.h" |
41 |
#include "modules.h" |
42 |
#include "s_user.h" |
43 |
|
44 |
static void m_list(struct Client *, struct Client *, int, char **); |
45 |
static void ms_list(struct Client *, struct Client *, int, char **); |
46 |
static void mo_list(struct Client *, struct Client *, int, char **); |
47 |
|
48 |
struct Message list_msgtab = { |
49 |
"LIST", 0, 0, 0, 0, MFLG_SLOW, 0, |
50 |
{m_unregistered, m_list, ms_list, m_ignore, mo_list, m_ignore} |
51 |
}; |
52 |
|
53 |
#ifndef STATIC_MODULES |
54 |
void |
55 |
_modinit(void) |
56 |
{ |
57 |
mod_add_cmd(&list_msgtab); |
58 |
add_isupport("ELIST", "CMNTU", -1); |
59 |
add_isupport("SAFELIST", NULL, -1); |
60 |
} |
61 |
|
62 |
void |
63 |
_moddeinit(void) |
64 |
{ |
65 |
mod_del_cmd(&list_msgtab); |
66 |
delete_isupport("ELIST"); |
67 |
delete_isupport("SAFELIST"); |
68 |
} |
69 |
|
70 |
const char *_version = "$Revision$"; |
71 |
#endif |
72 |
|
73 |
static int |
74 |
has_wildcards(const char *s) |
75 |
{ |
76 |
char c; |
77 |
|
78 |
while ((c = *s++)) |
79 |
if (IsMWildChar(c)) |
80 |
return 1; |
81 |
|
82 |
return 0; |
83 |
} |
84 |
|
85 |
static void |
86 |
do_list(struct Client *source_p, int parc, char *parv[]) |
87 |
{ |
88 |
struct ListTask *lt; |
89 |
int no_masked_channels; |
90 |
|
91 |
if (MyConnect(source_p)) |
92 |
{ |
93 |
if (source_p->localClient->list_task != NULL) |
94 |
{ |
95 |
free_list_task(source_p->localClient->list_task, source_p); |
96 |
sendto_one(source_p, form_str(RPL_LISTEND), me.name, source_p->name); |
97 |
return; |
98 |
} |
99 |
} |
100 |
|
101 |
lt = (struct ListTask *) MyMalloc(sizeof(struct ListTask)); |
102 |
lt->users_max = UINT_MAX; |
103 |
lt->created_max = UINT_MAX; |
104 |
lt->topicts_max = UINT_MAX; |
105 |
if (MyConnect(source_p)) |
106 |
source_p->localClient->list_task = lt; |
107 |
no_masked_channels = 1; |
108 |
|
109 |
if (parc > 1) |
110 |
{ |
111 |
char *opt, *save; |
112 |
dlink_list *list; |
113 |
int i, errors = 0; |
114 |
|
115 |
for (opt = strtoken(&save, parv[1], ","); opt != NULL; |
116 |
opt = strtoken(&save, NULL, ",")) |
117 |
switch (*opt) |
118 |
{ |
119 |
case '<': if ((i = atoi(opt + 1)) > 0) |
120 |
lt->users_max = (unsigned int) i - 1; |
121 |
else |
122 |
errors = 1; |
123 |
break; |
124 |
case '>': if ((i = atoi(opt + 1)) >= 0) |
125 |
lt->users_min = (unsigned int) i + 1; |
126 |
else |
127 |
errors = 1; |
128 |
break; |
129 |
case '-': break; |
130 |
case 'C': |
131 |
case 'c': switch (*++opt) |
132 |
{ |
133 |
case '<': if ((i = atoi(opt + 1)) >= 0) |
134 |
lt->created_max = (unsigned int) (CurrentTime |
135 |
- 60 * i); |
136 |
else |
137 |
errors = 1; |
138 |
break; |
139 |
case '>': if ((i = atoi(opt + 1)) >= 0) |
140 |
lt->created_min = (unsigned int) (CurrentTime |
141 |
- 60 * i); |
142 |
else |
143 |
errors = 1; |
144 |
break; |
145 |
default: errors = 1; |
146 |
} |
147 |
break; |
148 |
case 'T': |
149 |
case 't': switch (*++opt) |
150 |
{ |
151 |
case '<': if ((i = atoi(opt + 1)) >= 0) |
152 |
lt->topicts_min = (unsigned int) (CurrentTime |
153 |
- 60 * i); |
154 |
else |
155 |
errors = 1; |
156 |
break; |
157 |
case '>': if ((i = atoi(opt + 1)) >= 0) |
158 |
lt->topicts_max = (unsigned int) (CurrentTime |
159 |
- 60 * i); |
160 |
else |
161 |
errors = 1; |
162 |
break; |
163 |
default: errors = 1; |
164 |
} |
165 |
break; |
166 |
default: if (*opt == '!') |
167 |
{ |
168 |
list = <->hide_mask; |
169 |
opt++; |
170 |
} |
171 |
else list = <->show_mask; |
172 |
|
173 |
if (has_wildcards(opt + !!IsChanPrefix(*opt))) |
174 |
{ |
175 |
if (list == <->show_mask) |
176 |
no_masked_channels = 0; |
177 |
} |
178 |
else if (!IsChanPrefix(*opt)) |
179 |
errors = 1; |
180 |
if (!errors) |
181 |
{ |
182 |
char *s; |
183 |
DupString(s, opt); |
184 |
dlinkAdd(s, make_dlink_node(), list); |
185 |
} |
186 |
} |
187 |
if (errors) |
188 |
{ |
189 |
free_list_task(lt, source_p); |
190 |
sendto_one(source_p, form_str(ERR_LISTSYNTAX), |
191 |
MyConnect(source_p) ? me.name : ID(&me), |
192 |
MyConnect(source_p) ? source_p->name : ID(source_p)); |
193 |
return; |
194 |
} |
195 |
} |
196 |
|
197 |
|
198 |
if (MyConnect(source_p)) |
199 |
dlinkAdd(source_p, make_dlink_node(), &listing_client_list); |
200 |
sendto_one(source_p, form_str(RPL_LISTSTART), |
201 |
MyConnect(source_p) ? me.name : ID(&me), |
202 |
MyConnect(source_p) ? source_p->name : ID(source_p)); |
203 |
safe_list_channels(source_p, lt, no_masked_channels && |
204 |
lt->show_mask.head != NULL, !MyConnect(source_p)); |
205 |
} |
206 |
|
207 |
/* |
208 |
** m_list |
209 |
** parv[0] = sender prefix |
210 |
** parv[1] = channel |
211 |
*/ |
212 |
static void |
213 |
m_list(struct Client *client_p, struct Client *source_p, |
214 |
int parc, char *parv[]) |
215 |
{ |
216 |
static time_t last_used = 0; |
217 |
|
218 |
/* If not a LazyLink connection, see if its still paced */ |
219 |
/* If we're forwarding this to uplinks.. it should be paced due to the |
220 |
* traffic involved in /list.. -- fl_ */ |
221 |
if (((last_used + ConfigFileEntry.pace_wait) > CurrentTime)) |
222 |
{ |
223 |
sendto_one(source_p,form_str(RPL_LOAD2HI),me.name,parv[0]); |
224 |
return; |
225 |
} |
226 |
else |
227 |
last_used = CurrentTime; |
228 |
|
229 |
/* If its a LazyLinks connection, let uplink handle the list */ |
230 |
if (uplink && IsCapable(uplink, CAP_LL)) |
231 |
{ |
232 |
if (parc < 2) |
233 |
sendto_one(uplink, ":%s LIST", source_p->name); |
234 |
else |
235 |
sendto_one(uplink, ":%s LIST %s", source_p->name, parv[1]); |
236 |
return; |
237 |
} |
238 |
|
239 |
do_list(source_p, parc, parv); |
240 |
} |
241 |
|
242 |
/* |
243 |
** mo_list |
244 |
** parv[0] = sender prefix |
245 |
** parv[1] = channel |
246 |
*/ |
247 |
static void |
248 |
mo_list(struct Client *client_p, struct Client *source_p, |
249 |
int parc, char *parv[]) |
250 |
{ |
251 |
/* If its a LazyLinks connection, let uplink handle the list |
252 |
* even for opers! |
253 |
*/ |
254 |
|
255 |
if (uplink && IsCapable(uplink, CAP_LL)) |
256 |
{ |
257 |
if (parc < 2) |
258 |
sendto_one(uplink, ":%s LIST", source_p->name); |
259 |
else |
260 |
sendto_one(uplink, ":%s LIST %s", source_p->name, parv[1]); |
261 |
return; |
262 |
} |
263 |
|
264 |
do_list(source_p, parc, parv); |
265 |
} |
266 |
|
267 |
/* |
268 |
** ms_list |
269 |
** parv[0] = sender prefix |
270 |
** parv[1] = channel |
271 |
*/ |
272 |
static void |
273 |
ms_list(struct Client *client_p, struct Client *source_p, |
274 |
int parc, char *parv[]) |
275 |
{ |
276 |
/* Only allow remote list if LazyLink request */ |
277 |
if (ServerInfo.hub) |
278 |
{ |
279 |
if (!IsCapable(client_p->from, CAP_LL) && !MyConnect(source_p)) |
280 |
return; |
281 |
|
282 |
do_list(source_p, parc, parv); |
283 |
} |
284 |
} |