]>
jfr.im git - irc/quakenet/snircd.git/blob - ircd/m_list.c
2 * IRC - Internet Relay Chat, ircd/m_list.c
3 * Copyright (C) 1990 Jarkko Oikarinen and
4 * University of Oulu, Computing Center
6 * See file AUTHORS in IRC package for additional names of
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 1, or (at your option)
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 * $Id: m_list.c,v 1.16 2005/06/20 13:22:45 a1kmm Exp $
27 * m_functions execute protocol messages on this server:
29 * cptr is always NON-NULL, pointing to a *LOCAL* client
30 * structure (with an open socket connected!). This
31 * identifies the physical socket where the message
32 * originated (or which caused the m_function to be
33 * executed--some m_functions may call others...).
35 * sptr is the source of the message, defined by the
36 * prefix part of the message if present. If not
37 * or prefix not found, then sptr==cptr.
39 * (!IsServer(cptr)) => (cptr == sptr), because
40 * prefixes are taken *only* from servers...
43 * (sptr == cptr) => the message didn't
46 * (sptr != cptr && IsServer(sptr) means
47 * the prefix specified servername. (?)
49 * (sptr != cptr && !IsServer(sptr) means
50 * that message originated from a remote
55 * (!IsServer(sptr)) means that, sptr can safely
56 * taken as defining the target structure of the
57 * message in this server.
59 * *Always* true (if 'parse' and others are working correct):
61 * 1) sptr->from == cptr (note: cptr->from == cptr)
63 * 2) MyConnect(sptr) <=> sptr == cptr (e.g. sptr
64 * *cannot* be a local connection, unless it's
65 * actually cptr!). [MyConnect(x) should probably
66 * be defined as (x == x->from) --msa ]
68 * parc number of variable parameter strings (if zero,
69 * parv is allowed to be NULL)
71 * parv a NULL terminated list of parameter pointers,
73 * parv[0], sender (prefix string), if not present
74 * this points to an empty string.
75 * parv[1]...parv[parc-1]
76 * pointers to additional parameters
77 * parv[parc] == NULL, *always*
79 * note: it is guaranteed that parv[0]..parv[parc-1] are all
88 #include "ircd_alloc.h"
89 #include "ircd_chattr.h"
90 #include "ircd_features.h"
92 #include "ircd_reply.h"
93 #include "ircd_string.h"
100 /* #include <assert.h> -- Now using assert in ircd_log.h */
104 #define LPARAM_ERROR -1
105 #define LPARAM_SUCCESS 0
106 #define LPARAM_CHANNEL 1
108 static struct ListingArgs la_init
= {
109 2147483647, /* max_time */
111 4294967295U, /* max_users */
114 2147483647, /* max_topic_time */
115 0, /* min_topic_time */
120 static struct ListingArgs la_default
= {
121 2147483647, /* max_time */
123 4294967295U, /* max_users */
126 2147483647, /* max_topic_time */
127 0, /* min_topic_time */
133 show_usage(struct Client
*sptr
)
135 if (!sptr
) { /* configuration file error... */
136 log_write(LS_CONFIG
, L_ERROR
, 0, "Invalid default list parameter");
140 send_reply(sptr
, RPL_LISTUSAGE
,
141 "Usage: \002/QUOTE LIST\002 \037parameters\037");
142 send_reply(sptr
, RPL_LISTUSAGE
,
143 "Where \037parameters\037 is a space or comma separated "
144 "list of one or more of:");
145 send_reply(sptr
, RPL_LISTUSAGE
,
146 " \002<\002\037max_users\037 ; Show all channels with less "
147 "than \037max_users\037.");
148 send_reply(sptr
, RPL_LISTUSAGE
,
149 " \002>\002\037min_users\037 ; Show all channels with more "
150 "than \037min_users\037.");
151 send_reply(sptr
, RPL_LISTUSAGE
,
152 " \002C<\002\037max_minutes\037 ; Channels that exist less "
153 "than \037max_minutes\037.");
154 send_reply(sptr
, RPL_LISTUSAGE
,
155 " \002C>\002\037min_minutes\037 ; Channels that exist more "
156 "than \037min_minutes\037.");
157 send_reply(sptr
, RPL_LISTUSAGE
,
158 " \002T<\002\037max_minutes\037 ; Channels with a topic last "
159 "set less than \037max_minutes\037 ago.");
160 send_reply(sptr
, RPL_LISTUSAGE
,
161 " \002T>\002\037min_minutes\037 ; Channels with a topic last "
162 "set more than \037min_minutes\037 ago.");
163 send_reply(sptr
, RPL_LISTUSAGE
,
164 " \037pattern\037 ; Channels with names matching "
165 "\037pattern\037. ");
166 send_reply(sptr
, RPL_LISTUSAGE
,
167 " !\037pattern\037 ; Channels with names not "
168 "matching \037pattern\037. ");
169 send_reply(sptr
, RPL_LISTUSAGE
, "Note: Patterns may contain * and ?. "
170 "You may only give one pattern match constraint.");
172 send_reply(sptr
, RPL_LISTUSAGE
,
173 " \002S\002 ; Show secret channels.");
174 send_reply(sptr
, RPL_LISTUSAGE
,
175 "Example: LIST <3,>1,C<10,T>0,#a* ; 2 users, younger than 10 "
176 "min., topic set., starts with #a");
178 return LPARAM_ERROR
; /* return error condition */
182 param_parse(struct Client
*sptr
, const char *param
, struct ListingArgs
*args
,
192 if (!param
) /* NULL param == default--no list param */
193 return LPARAM_SUCCESS
;
200 args
->flags
|= LISTARG_TOPICLIMITS
;
207 if (*param
!= '<' && *param
!= '>')
208 return show_usage(sptr
);
215 if (!IsDigit(*param
)) /* must start with a digit */
216 return show_usage(sptr
);
218 val
= strtol(param
, (char **)¶m
, 10); /* convert it... */
220 if (*param
!= ',' && *param
!= ' ' && *param
!= '\0') /* check syntax */
221 return show_usage(sptr
);
223 if (is_time
&& val
< 80000000) /* Toggle UTC/offset */
224 val
= TStime() - val
* 60;
227 case 0: /* number of users on channel */
229 args
->max_users
= val
;
231 args
->min_users
= val
;
234 case 1: /* channel topic */
236 args
->min_topic_time
= val
;
238 args
->max_topic_time
= val
;
241 case 2: /* channel creation time */
243 args
->min_time
= val
;
245 args
->max_time
= val
;
252 if (!IsAnOper(sptr
) || !HasPriv(sptr
, PRIV_LIST_CHAN
))
253 return show_usage(sptr
);
255 args
->flags
|= LISTARG_SHOWSECRET
;
258 if (*param
!= ',' && *param
!= ' ' && *param
!= '\0') /* check syntax */
259 return show_usage(sptr
);
263 /* It might be a wildcard... */
264 if (strchr(param
, '*') ||
270 args
->flags
|= LISTARG_NEGATEWILDCARD
;
273 /* Only one wildcard allowed... */
274 if (args
->wildcard
[0] != 0)
275 return show_usage(sptr
);
277 /* If its not going to match anything, don't bother. */
278 if (param
[0] != '*' &&
282 return show_usage(sptr
);
284 tmp1
= strchr(param
, ',');
285 tmp2
= strchr(param
, ' ');
286 if (tmp2
&& (!tmp1
|| (tmp2
< tmp1
)))
292 ircd_strncpy(args
->wildcard
, param
, CHANNELLEN
-1);
293 args
->wildcard
[CHANNELLEN
-1] = 0;
296 return LPARAM_SUCCESS
;
303 if (!permit_chan
|| !IsChannelName(param
))
304 return show_usage(sptr
);
306 return LPARAM_CHANNEL
;
310 if (!*param
) /* hit end of string? */
316 return LPARAM_SUCCESS
;
320 list_set_default(void)
322 la_default
= la_init
; /* start off with a clean slate... */
324 if (param_parse(0, feature_str(FEAT_DEFAULT_LIST_PARAM
), &la_default
, 0) !=
326 la_default
= la_init
; /* recover from error by switching to default */
330 * m_list - generic message handler
332 * parv[0] = sender prefix
333 * parv[1] = channel list or user/time limit
334 * parv[2...] = more user/time limits
336 int m_list(struct Client
* cptr
, struct Client
* sptr
, int parc
, char* parv
[])
338 struct Channel
*chptr
;
340 int show_channels
= 0, param
;
341 struct ListingArgs args
;
343 if (cli_listing(sptr
)) /* Already listing ? */
345 if (cli_listing(sptr
))
346 MyFree(cli_listing(sptr
));
347 cli_listing(sptr
) = 0;
348 send_reply(sptr
, RPL_LISTEND
);
350 if (parc
< 2 || 0 == ircd_strcmp("STOP", parv
[1]))
351 return 0; /* Let LIST or LIST STOP abort a listing. */
354 if (parc
< 2) /* No arguments given to /LIST ? */
357 args
= la_init
; /* initialize argument to blank slate */
359 for (param
= 1; parv
[param
]; param
++) { /* process each parameter */
360 switch (param_parse(sptr
, parv
[param
], &args
, parc
== 2)) {
361 case LPARAM_ERROR
: /* error encountered, usage already sent, return */
365 case LPARAM_CHANNEL
: /* show channel instead */
369 case LPARAM_SUCCESS
: /* parse succeeded */
375 send_reply(sptr
, RPL_LISTSTART
);
379 if (args
.max_users
> args
.min_users
+ 1 && args
.max_time
> args
.min_time
&&
380 args
.max_topic_time
> args
.min_topic_time
) /* Sanity check */
382 cli_listing(sptr
) = (struct ListingArgs
*) MyMalloc(sizeof(struct ListingArgs
));
383 assert(0 != cli_listing(sptr
));
384 memcpy(cli_listing(sptr
), &args
, sizeof(struct ListingArgs
));
385 list_next_channels(sptr
);
388 send_reply(sptr
, RPL_LISTEND
);
392 for (; (name
= ircd_strtok(&p
, parv
[1], ",")); parv
[1] = 0)
394 chptr
= FindChannel(name
);
397 if (ShowChannel(sptr
, chptr
)
398 || (IsAnOper(sptr
) && HasPriv(sptr
, PRIV_LIST_CHAN
)))
399 send_reply(sptr
, RPL_LIST
, chptr
->chname
,
400 chptr
->users
- number_of_zombies(chptr
), chptr
->topic
);
403 send_reply(sptr
, RPL_LISTEND
);