ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_list.c
Revision: 4545
Committed: Fri Aug 22 08:46:13 2014 UTC (11 years ago) by michael
Content type: text/x-csrc
File size: 5677 byte(s)
Log Message:
- Implemented pseudo {} blocks (service aliases)
- Fixed compile warnings with -Wmissing-field-initializers

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 'C':
88 case 'c':
89 switch (*++opt)
90 {
91 case '<':
92 if ((i = atoi(opt + 1)) >= 0)
93 lt->created_max = (unsigned int)(CurrentTime - 60 * i);
94 else
95 errors = 1;
96 break;
97 case '>':
98 if ((i = atoi(opt + 1)) >= 0)
99 lt->created_min = (unsigned int)(CurrentTime - 60 * i);
100 else
101 errors = 1;
102 break;
103 default:
104 errors = 1;
105 }
106
107 break;
108
109 case 'T':
110 case 't':
111 switch (*++opt)
112 {
113 case '<':
114 if ((i = atoi(opt + 1)) >= 0)
115 lt->topicts_min = (unsigned int)(CurrentTime - 60 * i);
116 else
117 errors = 1;
118 break;
119 case '>':
120 if ((i = atoi(opt + 1)) >= 0)
121 lt->topicts_max = (unsigned int)(CurrentTime - 60 * i);
122 else
123 errors = 1;
124 break;
125 case ':':
126 if (strlcpy(lt->topic, opt + 1, sizeof(lt->topic)) == 0)
127 errors = 1;
128 break;
129 default:
130 errors = 1;
131 }
132
133 break;
134
135 default:
136 if (*opt == '!')
137 {
138 list = &lt->hide_mask;
139 opt++;
140 }
141 else
142 list = &lt->show_mask;
143
144 if (has_wildcards(opt + !!IsChanPrefix(*opt)))
145 {
146 if (list == &lt->show_mask)
147 no_masked_channels = 0;
148 }
149 else if (!IsChanPrefix(*opt))
150 errors = 1;
151
152 if (!errors)
153 dlinkAdd(xstrdup(opt), make_dlink_node(), list);
154 }
155 }
156
157 if (errors)
158 {
159 free_list_task(source_p);
160 sendto_one_numeric(source_p, &me, ERR_LISTSYNTAX);
161 return;
162 }
163 }
164
165 dlinkAdd(source_p, make_dlink_node(), &listing_client_list);
166
167 sendto_one_numeric(source_p, &me, RPL_LISTSTART);
168 safe_list_channels(source_p, no_masked_channels && lt->show_mask.head != NULL);
169 }
170
171 /*! \brief LIST command handler
172 *
173 * \param source_p Pointer to allocated Client struct from which the message
174 * originally comes from. This can be a local or remote client.
175 * \param parc Integer holding the number of supplied arguments.
176 * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
177 * pointers.
178 * \note Valid arguments for this command are:
179 * - parv[0] = command
180 * - parv[1] = channel name/list options
181 */
182 static int
183 m_list(struct Client *source_p, int parc, char *parv[])
184 {
185 do_list(source_p, parc, parv);
186 return 0;
187 }
188
189 static struct Message list_msgtab =
190 {
191 "LIST", NULL, 0, 0, 0, MAXPARA, MFLG_SLOW, 0,
192 { m_unregistered, m_list, m_ignore, m_ignore, m_list, m_ignore }
193 };
194
195 static void
196 module_init(void)
197 {
198 mod_add_cmd(&list_msgtab);
199 add_isupport("ELIST", "CMNTU", -1);
200 add_isupport("SAFELIST", NULL, -1);
201 }
202
203 static void
204 module_exit(void)
205 {
206 mod_del_cmd(&list_msgtab);
207 delete_isupport("ELIST");
208 delete_isupport("SAFELIST");
209 }
210
211 struct module module_entry =
212 {
213 .node = { NULL, NULL, NULL },
214 .name = NULL,
215 .version = "$Revision$",
216 .handle = NULL,
217 .modinit = module_init,
218 .modexit = module_exit,
219 .flags = 0
220 };

Properties

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