ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_list.c
Revision: 1230
Committed: Thu Sep 22 19:41:19 2011 UTC (13 years, 11 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-8/modules/m_list.c
File size: 5698 byte(s)
Log Message:
- cleanup module loader. Make module api more flexible

File Contents

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

Properties

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