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 "list.h" |
27 |
#include "channel.h" |
28 |
#include "channel_mode.h" |
29 |
#include "client.h" |
30 |
#include "hash.h" |
31 |
#include "irc_string.h" |
32 |
#include "ircd.h" |
33 |
#include "numeric.h" |
34 |
#include "conf.h" |
35 |
#include "s_serv.h" |
36 |
#include "send.h" |
37 |
#include "parse.h" |
38 |
#include "modules.h" |
39 |
#include "s_user.h" |
40 |
#include "memory.h" |
41 |
|
42 |
|
43 |
static void |
44 |
do_list(struct Client *source_p, int parc, char *parv[]) |
45 |
{ |
46 |
struct ListTask *lt = NULL; |
47 |
int no_masked_channels = 1; |
48 |
|
49 |
if (source_p->localClient->list_task != NULL) |
50 |
{ |
51 |
free_list_task(source_p->localClient->list_task, source_p); |
52 |
sendto_one(source_p, form_str(RPL_LISTEND), me.name, source_p->name); |
53 |
return; |
54 |
} |
55 |
|
56 |
lt = MyMalloc(sizeof(struct ListTask)); |
57 |
lt->users_max = UINT_MAX; |
58 |
lt->created_max = UINT_MAX; |
59 |
lt->topicts_max = UINT_MAX; |
60 |
source_p->localClient->list_task = lt; |
61 |
|
62 |
if (parc > 1 && !EmptyString(parv[1])) |
63 |
{ |
64 |
char *opt, *save = NULL; |
65 |
dlink_list *list = NULL; |
66 |
int i = 0, errors = 0; |
67 |
|
68 |
for (opt = strtoken(&save, parv[1], ","); opt != NULL; |
69 |
opt = strtoken(&save, NULL, ",")) |
70 |
switch (*opt) |
71 |
{ |
72 |
case '<': if ((i = atoi(opt + 1)) > 0) |
73 |
lt->users_max = (unsigned int) i - 1; |
74 |
else |
75 |
errors = 1; |
76 |
break; |
77 |
case '>': if ((i = atoi(opt + 1)) >= 0) |
78 |
lt->users_min = (unsigned int) i + 1; |
79 |
else |
80 |
errors = 1; |
81 |
break; |
82 |
case '-': break; |
83 |
case 'C': |
84 |
case 'c': switch (*++opt) |
85 |
{ |
86 |
case '<': if ((i = atoi(opt + 1)) >= 0) |
87 |
lt->created_max = (unsigned int) (CurrentTime |
88 |
- 60 * i); |
89 |
else |
90 |
errors = 1; |
91 |
break; |
92 |
case '>': if ((i = atoi(opt + 1)) >= 0) |
93 |
lt->created_min = (unsigned int) (CurrentTime |
94 |
- 60 * i); |
95 |
else |
96 |
errors = 1; |
97 |
break; |
98 |
default: errors = 1; |
99 |
} |
100 |
break; |
101 |
case 'T': |
102 |
case 't': switch (*++opt) |
103 |
{ |
104 |
case '<': if ((i = atoi(opt + 1)) >= 0) |
105 |
lt->topicts_min = (unsigned int) (CurrentTime |
106 |
- 60 * i); |
107 |
else |
108 |
errors = 1; |
109 |
break; |
110 |
case '>': if ((i = atoi(opt + 1)) >= 0) |
111 |
lt->topicts_max = (unsigned int) (CurrentTime |
112 |
- 60 * i); |
113 |
else |
114 |
errors = 1; |
115 |
break; |
116 |
default: errors = 1; |
117 |
} |
118 |
break; |
119 |
default: if (*opt == '!') |
120 |
{ |
121 |
list = <->hide_mask; |
122 |
opt++; |
123 |
} |
124 |
else list = <->show_mask; |
125 |
|
126 |
if (has_wildcards(opt + !!IsChanPrefix(*opt))) |
127 |
{ |
128 |
if (list == <->show_mask) |
129 |
no_masked_channels = 0; |
130 |
} |
131 |
else if (!IsChanPrefix(*opt)) |
132 |
errors = 1; |
133 |
if (!errors) |
134 |
{ |
135 |
char *s = xstrdup(opt); |
136 |
dlinkAdd(s, make_dlink_node(), list); |
137 |
} |
138 |
} |
139 |
if (errors) |
140 |
{ |
141 |
free_list_task(lt, source_p); |
142 |
sendto_one(source_p, form_str(ERR_LISTSYNTAX), |
143 |
me.name, source_p->name); |
144 |
return; |
145 |
} |
146 |
} |
147 |
|
148 |
|
149 |
dlinkAdd(source_p, make_dlink_node(), &listing_client_list); |
150 |
|
151 |
sendto_one(source_p, form_str(RPL_LISTSTART), |
152 |
me.name, source_p->name); |
153 |
safe_list_channels(source_p, lt, no_masked_channels && |
154 |
lt->show_mask.head != NULL); |
155 |
} |
156 |
|
157 |
/* |
158 |
** mo_list |
159 |
** parv[0] = sender prefix |
160 |
** parv[1] = channel |
161 |
*/ |
162 |
static void |
163 |
m_list(struct Client *client_p, struct Client *source_p, |
164 |
int parc, char *parv[]) |
165 |
{ |
166 |
do_list(source_p, parc, parv); |
167 |
} |
168 |
|
169 |
static struct Message list_msgtab = { |
170 |
"LIST", 0, 0, 0, MAXPARA, MFLG_SLOW, 0, |
171 |
{ m_unregistered, m_list, m_ignore, m_ignore, m_list, m_ignore } |
172 |
}; |
173 |
|
174 |
static void |
175 |
module_init(void) |
176 |
{ |
177 |
mod_add_cmd(&list_msgtab); |
178 |
add_isupport("ELIST", "CMNTU", -1); |
179 |
add_isupport("SAFELIST", NULL, -1); |
180 |
} |
181 |
|
182 |
static void |
183 |
module_exit(void) |
184 |
{ |
185 |
mod_del_cmd(&list_msgtab); |
186 |
delete_isupport("ELIST"); |
187 |
delete_isupport("SAFELIST"); |
188 |
} |
189 |
|
190 |
struct module module_entry = { |
191 |
.node = { NULL, NULL, NULL }, |
192 |
.name = NULL, |
193 |
.version = "$Revision$", |
194 |
.handle = NULL, |
195 |
.modinit = module_init, |
196 |
.modexit = module_exit, |
197 |
.flags = 0 |
198 |
}; |