1 |
/* |
2 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
* |
4 |
* Copyright (c) 1997-2015 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_list.c |
23 |
* \brief Includes required functions for processing the LIST command. |
24 |
* \version $Id$ |
25 |
*/ |
26 |
|
27 |
#include "stdinc.h" |
28 |
#include "list.h" |
29 |
#include "client.h" |
30 |
#include "hash.h" |
31 |
#include "irc_string.h" |
32 |
#include "ircd.h" |
33 |
#include "numeric.h" |
34 |
#include "send.h" |
35 |
#include "parse.h" |
36 |
#include "modules.h" |
37 |
#include "user.h" |
38 |
#include "memory.h" |
39 |
|
40 |
|
41 |
static void |
42 |
do_list(struct Client *source_p, char *arg) |
43 |
{ |
44 |
struct ListTask *lt = NULL; |
45 |
int no_masked_channels = 1; |
46 |
|
47 |
if (source_p->connection->list_task) |
48 |
{ |
49 |
free_list_task(source_p); |
50 |
sendto_one_numeric(source_p, &me, RPL_LISTEND); |
51 |
return; |
52 |
} |
53 |
|
54 |
lt = MyCalloc(sizeof(struct ListTask)); |
55 |
lt->users_max = UINT_MAX; |
56 |
lt->created_max = UINT_MAX; |
57 |
lt->topicts_max = UINT_MAX; |
58 |
source_p->connection->list_task = lt; |
59 |
|
60 |
if (!EmptyString(arg)) |
61 |
{ |
62 |
char *opt, *save = NULL; |
63 |
dlink_list *list = NULL; |
64 |
int i = 0, errors = 0; |
65 |
|
66 |
for (opt = strtoken(&save, arg, ","); opt; |
67 |
opt = strtoken(&save, NULL, ",")) |
68 |
{ |
69 |
switch (*opt) |
70 |
{ |
71 |
case '<': |
72 |
if ((i = atoi(opt + 1)) > 0) |
73 |
lt->users_max = (unsigned int)i - 1; |
74 |
else |
75 |
errors = 1; |
76 |
break; |
77 |
case '>': |
78 |
if ((i = atoi(opt + 1)) >= 0) |
79 |
lt->users_min = (unsigned int)i + 1; |
80 |
else |
81 |
errors = 1; |
82 |
break; |
83 |
case 'C': |
84 |
case 'c': |
85 |
switch (*++opt) |
86 |
{ |
87 |
case '<': |
88 |
if ((i = atoi(opt + 1)) >= 0) |
89 |
lt->created_max = (unsigned int)(CurrentTime - 60 * i); |
90 |
else |
91 |
errors = 1; |
92 |
break; |
93 |
case '>': |
94 |
if ((i = atoi(opt + 1)) >= 0) |
95 |
lt->created_min = (unsigned int)(CurrentTime - 60 * i); |
96 |
else |
97 |
errors = 1; |
98 |
break; |
99 |
default: |
100 |
errors = 1; |
101 |
} |
102 |
|
103 |
break; |
104 |
|
105 |
case 'T': |
106 |
case 't': |
107 |
switch (*++opt) |
108 |
{ |
109 |
case '<': |
110 |
if ((i = atoi(opt + 1)) >= 0) |
111 |
lt->topicts_min = (unsigned int)(CurrentTime - 60 * i); |
112 |
else |
113 |
errors = 1; |
114 |
break; |
115 |
case '>': |
116 |
if ((i = atoi(opt + 1)) >= 0) |
117 |
lt->topicts_max = (unsigned int)(CurrentTime - 60 * i); |
118 |
else |
119 |
errors = 1; |
120 |
break; |
121 |
case ':': |
122 |
if (strlcpy(lt->topic, opt + 1, sizeof(lt->topic)) == 0) |
123 |
errors = 1; |
124 |
break; |
125 |
default: |
126 |
errors = 1; |
127 |
} |
128 |
|
129 |
break; |
130 |
|
131 |
default: |
132 |
if (*opt == '!') |
133 |
{ |
134 |
list = <->hide_mask; |
135 |
opt++; |
136 |
} |
137 |
else |
138 |
list = <->show_mask; |
139 |
|
140 |
if (has_wildcards(opt + !!IsChanPrefix(*opt))) |
141 |
{ |
142 |
if (list == <->show_mask) |
143 |
no_masked_channels = 0; |
144 |
} |
145 |
else if (!IsChanPrefix(*opt)) |
146 |
errors = 1; |
147 |
|
148 |
if (!errors) |
149 |
dlinkAdd(xstrdup(opt), make_dlink_node(), list); |
150 |
} |
151 |
} |
152 |
|
153 |
if (errors) |
154 |
{ |
155 |
free_list_task(source_p); |
156 |
sendto_one_numeric(source_p, &me, ERR_LISTSYNTAX); |
157 |
return; |
158 |
} |
159 |
} |
160 |
|
161 |
dlinkAdd(source_p, make_dlink_node(), &listing_client_list); |
162 |
|
163 |
sendto_one_numeric(source_p, &me, RPL_LISTSTART); |
164 |
safe_list_channels(source_p, no_masked_channels && lt->show_mask.head != NULL); |
165 |
} |
166 |
|
167 |
/*! \brief LIST command handler |
168 |
* |
169 |
* \param source_p Pointer to allocated Client struct from which the message |
170 |
* originally comes from. This can be a local or remote client. |
171 |
* \param parc Integer holding the number of supplied arguments. |
172 |
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
173 |
* pointers. |
174 |
* \note Valid arguments for this command are: |
175 |
* - parv[0] = command |
176 |
* - parv[1] = channel name/list options |
177 |
*/ |
178 |
static int |
179 |
m_list(struct Client *source_p, int parc, char *parv[]) |
180 |
{ |
181 |
do_list(source_p, parv[1]); |
182 |
return 0; |
183 |
} |
184 |
|
185 |
static struct Message list_msgtab = |
186 |
{ |
187 |
.cmd = "LIST", |
188 |
.args_max = MAXPARA, |
189 |
.handlers[UNREGISTERED_HANDLER] = m_unregistered, |
190 |
.handlers[CLIENT_HANDLER] = m_list, |
191 |
.handlers[SERVER_HANDLER] = m_ignore, |
192 |
.handlers[ENCAP_HANDLER] = m_ignore, |
193 |
.handlers[OPER_HANDLER] = m_list |
194 |
}; |
195 |
|
196 |
static void |
197 |
module_init(void) |
198 |
{ |
199 |
mod_add_cmd(&list_msgtab); |
200 |
add_isupport("ELIST", "CMNTU", -1); |
201 |
add_isupport("SAFELIST", NULL, -1); |
202 |
} |
203 |
|
204 |
static void |
205 |
module_exit(void) |
206 |
{ |
207 |
mod_del_cmd(&list_msgtab); |
208 |
delete_isupport("ELIST"); |
209 |
delete_isupport("SAFELIST"); |
210 |
} |
211 |
|
212 |
struct module module_entry = |
213 |
{ |
214 |
.version = "$Revision$", |
215 |
.modinit = module_init, |
216 |
.modexit = module_exit, |
217 |
}; |