ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_list.c
Revision: 3504
Committed: Sat May 10 19:51:29 2014 UTC (11 years, 3 months ago) by michael
Content type: text/x-csrc
File size: 5554 byte(s)
Log Message:
- Renamed MyMalloc() to MyCalloc()

File Contents

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

Properties

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