ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-8/modules/m_list.c
Revision: 1156
Committed: Tue Aug 9 20:29:20 2011 UTC (12 years, 7 months ago) by michael
Content type: text/x-csrc
File size: 5620 byte(s)
Log Message:
- create ircd-hybrid-8 "branch"

File Contents

# Content
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 "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 "msg.h"
39 #include "parse.h"
40 #include "modules.h"
41 #include "s_user.h"
42
43 static void m_list(struct Client *, struct Client *, int, char *[]);
44 static void mo_list(struct Client *, struct Client *, int, char *[]);
45
46 struct Message list_msgtab = {
47 "LIST", 0, 0, 0, 0, MFLG_SLOW, 0,
48 {m_unregistered, m_list, m_ignore, m_ignore, mo_list, m_ignore}
49 };
50
51 void
52 _modinit(void)
53 {
54 mod_add_cmd(&list_msgtab);
55 add_isupport("ELIST", "CMNTU", -1);
56 add_isupport("SAFELIST", NULL, -1);
57 }
58
59 void
60 _moddeinit(void)
61 {
62 mod_del_cmd(&list_msgtab);
63 delete_isupport("ELIST");
64 delete_isupport("SAFELIST");
65 }
66
67 const char *_version = "$Revision$";
68
69 static int
70 has_wildcards(const char *s)
71 {
72 char c;
73
74 while ((c = *s++))
75 if (IsMWildChar(c))
76 return 1;
77
78 return 0;
79 }
80
81 static void
82 do_list(struct Client *source_p, int parc, char *parv[])
83 {
84 struct ListTask *lt;
85 int no_masked_channels;
86
87 if (source_p->localClient->list_task != NULL)
88 {
89 free_list_task(source_p->localClient->list_task, source_p);
90 sendto_one(source_p, form_str(RPL_LISTEND), me.name, source_p->name);
91 return;
92 }
93
94 lt = MyMalloc(sizeof(struct ListTask));
95 lt->users_max = UINT_MAX;
96 lt->created_max = UINT_MAX;
97 lt->topicts_max = UINT_MAX;
98 source_p->localClient->list_task = lt;
99
100 no_masked_channels = 1;
101
102 if (parc > 1)
103 {
104 char *opt, *save = NULL;
105 dlink_list *list;
106 int i, errors = 0;
107
108 for (opt = strtoken(&save, parv[1], ","); opt != NULL;
109 opt = strtoken(&save, NULL, ","))
110 switch (*opt)
111 {
112 case '<': if ((i = atoi(opt + 1)) > 0)
113 lt->users_max = (unsigned int) i - 1;
114 else
115 errors = 1;
116 break;
117 case '>': if ((i = atoi(opt + 1)) >= 0)
118 lt->users_min = (unsigned int) i + 1;
119 else
120 errors = 1;
121 break;
122 case '-': break;
123 case 'C':
124 case 'c': switch (*++opt)
125 {
126 case '<': if ((i = atoi(opt + 1)) >= 0)
127 lt->created_max = (unsigned int) (CurrentTime
128 - 60 * i);
129 else
130 errors = 1;
131 break;
132 case '>': if ((i = atoi(opt + 1)) >= 0)
133 lt->created_min = (unsigned int) (CurrentTime
134 - 60 * i);
135 else
136 errors = 1;
137 break;
138 default: errors = 1;
139 }
140 break;
141 case 'T':
142 case 't': switch (*++opt)
143 {
144 case '<': if ((i = atoi(opt + 1)) >= 0)
145 lt->topicts_min = (unsigned int) (CurrentTime
146 - 60 * i);
147 else
148 errors = 1;
149 break;
150 case '>': if ((i = atoi(opt + 1)) >= 0)
151 lt->topicts_max = (unsigned int) (CurrentTime
152 - 60 * i);
153 else
154 errors = 1;
155 break;
156 default: errors = 1;
157 }
158 break;
159 default: if (*opt == '!')
160 {
161 list = &lt->hide_mask;
162 opt++;
163 }
164 else list = &lt->show_mask;
165
166 if (has_wildcards(opt + !!IsChanPrefix(*opt)))
167 {
168 if (list == &lt->show_mask)
169 no_masked_channels = 0;
170 }
171 else if (!IsChanPrefix(*opt))
172 errors = 1;
173 if (!errors)
174 {
175 char *s;
176 DupString(s, opt);
177 dlinkAdd(s, make_dlink_node(), list);
178 }
179 }
180 if (errors)
181 {
182 free_list_task(lt, source_p);
183 sendto_one(source_p, form_str(ERR_LISTSYNTAX),
184 me.name, source_p->name);
185 return;
186 }
187 }
188
189
190 dlinkAdd(source_p, make_dlink_node(), &listing_client_list);
191
192 sendto_one(source_p, form_str(RPL_LISTSTART),
193 me.name, source_p->name);
194 safe_list_channels(source_p, lt, no_masked_channels &&
195 lt->show_mask.head != NULL);
196 }
197
198 /*
199 ** m_list
200 ** parv[0] = sender prefix
201 ** parv[1] = channel
202 */
203 static void
204 m_list(struct Client *client_p, struct Client *source_p,
205 int parc, char *parv[])
206 {
207 static time_t last_used = 0;
208
209 if (((last_used + ConfigFileEntry.pace_wait) > CurrentTime))
210 {
211 sendto_one(source_p, form_str(RPL_LOAD2HI), me.name, parv[0]);
212 return;
213 }
214
215 last_used = CurrentTime;
216
217 do_list(source_p, parc, parv);
218 }
219
220 /*
221 ** mo_list
222 ** parv[0] = sender prefix
223 ** parv[1] = channel
224 */
225 static void
226 mo_list(struct Client *client_p, struct Client *source_p,
227 int parc, char *parv[])
228 {
229 do_list(source_p, parc, parv);
230 }

Properties

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