* note: it is guaranteed that parv[0]..parv[parc-1] are all
* non-NULL pointers.
*/
-#if 0
-/*
- * No need to include handlers.h here the signatures must match
- * and we don't need to force a rebuild of all the handlers everytime
- * we add a new one to the list. --Bleep
- */
-#include "handlers.h"
-#endif /* 0 */
+#include "config.h"
+
#include "channel.h"
#include "client.h"
#include "hash.h"
#include "ircd.h"
#include "ircd_alloc.h"
#include "ircd_chattr.h"
+#include "ircd_features.h"
+#include "ircd_log.h"
#include "ircd_reply.h"
#include "ircd_string.h"
#include "msg.h"
#include "numeric.h"
#include "numnicks.h"
+#include "s_bsd.h"
#include "send.h"
-#include <assert.h>
+/* #include <assert.h> -- Now using assert in ircd_log.h */
#include <stdlib.h>
#include <string.h>
-/*
- * m_list - generic message handler
- *
- * parv[0] = sender prefix
- * parv[1] = channel list or user/time limit
- * parv[2...] = more user/time limits
- */
-int m_list(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
+#define LPARAM_ERROR -1
+#define LPARAM_SUCCESS 0
+#define LPARAM_CHANNEL 1
+
+static struct ListingArgs la_init = {
+ 2147483647, /* max_time */
+ 0, /* min_time */
+ 4294967295U, /* max_users */
+ 0, /* min_users */
+ 0, /* flags */
+ 2147483647, /* max_topic_time */
+ 0, /* min_topic_time */
+ 0, /* bucket */
+ {0} /* wildcard */
+};
+
+static struct ListingArgs la_default = {
+ 2147483647, /* max_time */
+ 0, /* min_time */
+ 4294967295U, /* max_users */
+ 0, /* min_users */
+ 0, /* flags */
+ 2147483647, /* max_topic_time */
+ 0, /* min_topic_time */
+ 0, /* bucket */
+ {0} /* wildcard */
+};
+
+static int
+show_usage(struct Client *sptr)
{
- struct Channel *chptr;
- char *name, *p = 0;
- int show_usage = 0, show_channels = 0, param;
- struct ListingArgs args = {
- 2147483647, /* max_time */
- 0, /* min_time */
- 4294967295U, /* max_users */
- 0, /* min_users */
- 0, /* topic_limits */
- 2147483647, /* max_topic_time */
- 0, /* min_topic_time */
- 0 /* chptr */
- };
-
- if (sptr->listing) /* Already listing ? */
- {
- sptr->listing->chptr->mode.mode &= ~MODE_LISTED;
- MyFree(sptr->listing);
- sptr->listing = 0;
- sendto_one(sptr, rpl_str(RPL_LISTEND), me.name, sptr->name);
- if (parc < 2)
- return 0; /* Let LIST abort a listing. */
+ if (!sptr) { /* configuration file error... */
+ log_write(LS_CONFIG, L_ERROR, 0, "Invalid default list parameter");
+ return LPARAM_ERROR;
}
- if (parc < 2) /* No arguments given to /LIST ? */
- {
-#ifdef DEFAULT_LIST_PARAM
- static char *defparv[MAXPARA + 1];
- static int defparc = 0;
- static char lp[] = DEFAULT_LIST_PARAM;
- int i;
-
- /*
- * XXX - strtok used
- */
- if (!defparc)
- {
- char *s = lp, *t;
+ send_reply(sptr, RPL_LISTUSAGE,
+ "Usage: \002/QUOTE LIST\002 \037parameters\037");
+ send_reply(sptr, RPL_LISTUSAGE,
+ "Where \037parameters\037 is a space or comma separated "
+ "list of one or more of:");
+ send_reply(sptr, RPL_LISTUSAGE,
+ " \002<\002\037max_users\037 ; Show all channels with less "
+ "than \037max_users\037.");
+ send_reply(sptr, RPL_LISTUSAGE,
+ " \002>\002\037min_users\037 ; Show all channels with more "
+ "than \037min_users\037.");
+ send_reply(sptr, RPL_LISTUSAGE,
+ " \002C<\002\037max_minutes\037 ; Channels that exist less "
+ "than \037max_minutes\037.");
+ send_reply(sptr, RPL_LISTUSAGE,
+ " \002C>\002\037min_minutes\037 ; Channels that exist more "
+ "than \037min_minutes\037.");
+ send_reply(sptr, RPL_LISTUSAGE,
+ " \002T<\002\037max_minutes\037 ; Channels with a topic last "
+ "set less than \037max_minutes\037 ago.");
+ send_reply(sptr, RPL_LISTUSAGE,
+ " \002T>\002\037min_minutes\037 ; Channels with a topic last "
+ "set more than \037min_minutes\037 ago.");
+ send_reply(sptr, RPL_LISTUSAGE,
+ " \037pattern\037 ; Channels with names matching "
+ "\037pattern\037. ");
+ send_reply(sptr, RPL_LISTUSAGE,
+ " !\037pattern\037 ; Channels with names not "
+ "matching \037pattern\037. ");
+ send_reply(sptr, RPL_LISTUSAGE, "Note: Patterns may contain * and ?. "
+ "You may only give one pattern match constraint.");
+ if (IsAnOper(sptr)) {
+ send_reply(sptr, RPL_LISTUSAGE,
+ " \002S\002 ; Show secret channels.");
+ send_reply(sptr, RPL_LISTUSAGE,
+ " \002M\002 ; Show channel modes.");
+ }
+ send_reply(sptr, RPL_LISTUSAGE,
+ "Example: LIST <3,>1,C<10,T>0,#a* ; 2 users, younger than 10 "
+ "min., topic set., starts with #a");
- defparc = 1;
- defparv[defparc++] = t = strtok(s, " ");
- while (t && defparc < MAXPARA)
- {
- if ((t = strtok(0, " ")))
- defparv[defparc++] = t;
+ return LPARAM_ERROR; /* return error condition */
+}
+
+static int
+param_parse(struct Client *sptr, const char *param, struct ListingArgs *args,
+ int permit_chan)
+{
+ int is_time = 0;
+ char dir;
+ unsigned int val;
+ char *tmp1, *tmp2;
+
+ assert(0 != args);
+
+ if (!param) /* NULL param == default--no list param */
+ return LPARAM_SUCCESS;
+
+ while (1) {
+ switch (*param) {
+ case 'T':
+ case 't':
+ is_time++;
+ args->flags |= LISTARG_TOPICLIMITS;
+ /*FALLTHROUGH*/
+
+ case 'C':
+ case 'c':
+ is_time++;
+ param++;
+ if (*param != '<' && *param != '>')
+ return show_usage(sptr);
+ /*FALLTHROUGH*/
+
+ case '<':
+ case '>':
+ dir = *(param++);
+
+ if (!IsDigit(*param)) /* must start with a digit */
+ return show_usage(sptr);
+
+ val = strtol(param, (char **)¶m, 10); /* convert it... */
+
+ if (*param != ',' && *param != ' ' && *param != '\0') /* check syntax */
+ return show_usage(sptr);
+
+ if (is_time && val < 80000000) {
+ /* Convert age to timestamp and reverse direction */
+ val = TStime() - val * 60;
+ dir = (dir == '>') ? '<' : '>';
}
- }
- for (i = 1; i < defparc; i++)
- parv[i] = defparv[i];
- parv[i] = 0;
- parc = defparc;
-#endif /* DEFAULT_LIST_PARAM */
- }
+
+ switch (is_time) {
+ case 0: /* number of users on channel */
+ if (dir == '<')
+ args->max_users = val;
+ else
+ args->min_users = val;
+ break;
- /* Decode command */
- for (param = 1; !show_usage && parv[param]; param++)
- {
- char *p = parv[param];
- do
- {
- int is_time = 0;
- switch (*p)
+ case 1: /* channel creation time */
+ if (dir == '<')
+ args->max_time = val;
+ else
+ args->min_time = val;
+ break;
+
+ case 2: /* channel topic */
+ if (dir == '<')
+ args->max_topic_time = val;
+ else
+ args->min_topic_time = val;
+ break;
+ }
+ break;
+
+ case 'S':
+ case 's':
+ if (!IsAnOper(sptr) || !HasPriv(sptr, PRIV_LIST_CHAN))
+ return show_usage(sptr);
+
+ args->flags |= LISTARG_SHOWSECRET;
+ param++;
+
+ if (*param != ',' && *param != ' ' && *param != '\0') /* check syntax */
+ return show_usage(sptr);
+ break;
+
+ case 'M':
+ case 'm':
+ if (!IsAnOper(sptr) || !HasPriv(sptr, PRIV_LIST_CHAN))
+ return show_usage(sptr);
+
+ args->flags |= LISTARG_SHOWMODES;
+ param++;
+
+ if (*param != ',' && *param != ' ' && *param != '\0') /* check syntax */
+ return show_usage(sptr);
+ break;
+
+ default:
+ /* It might be a wildcard... */
+ if (strchr(param, '*') ||
+ strchr(param, '?'))
{
- case 'T':
- case 't':
- is_time++;
- args.topic_limits = 1;
- /* Fall through */
- case 'C':
- case 'c':
- is_time++;
- p++;
- if (*p != '<' && *p != '>')
- {
- show_usage = 1;
- break;
- }
- /* Fall through */
- case '<':
- case '>':
+ if (param[0] == '!')
{
- p++;
- if (!IsDigit(*p))
- show_usage = 1;
- else
- {
- if (is_time)
- {
- time_t val = atoi(p);
- if (p[-1] == '<')
- {
- if (val < 80000000) /* Toggle UTC/offset */
- {
- /*
- * Demands that
- * 'TStime() - chptr->creationtime < val * 60'
- * Which equals
- * 'chptr->creationtime > TStime() - val * 60'
- */
- if (is_time == 1)
- args.min_time = TStime() - val * 60;
- else
- args.min_topic_time = TStime() - val * 60;
- }
- else if (is_time == 1) /* Creation time in UTC was entered */
- args.max_time = val;
- else /* Topic time in UTC was entered */
- args.max_topic_time = val;
- }
- else if (val < 80000000)
- {
- if (is_time == 1)
- args.max_time = TStime() - val * 60;
- else
- args.max_topic_time = TStime() - val * 60;
- }
- else if (is_time == 1)
- args.min_time = val;
- else
- args.min_topic_time = val;
- }
- else if (p[-1] == '<')
- args.max_users = atoi(p);
- else
- args.min_users = atoi(p);
- if ((p = strchr(p, ',')))
- p++;
- }
- break;
+ param++;
+ args->flags |= LISTARG_NEGATEWILDCARD;
}
- default:
- if (!IsChannelName(p))
- {
- show_usage = 1;
- break;
- }
- if (parc != 2) /* Don't allow a mixture of channels with <,> */
- show_usage = 1;
- show_channels = 1;
- p = 0;
- break;
- }
- }
- while (!show_usage && p); /* p points after comma, or is NULL */
- }
- if (show_usage)
- {
- sendto_one(sptr, rpl_str(RPL_LISTUSAGE), me.name, parv[0],
- "Usage: \002/QUOTE LIST\002 \037parameters\037");
- sendto_one(sptr, rpl_str(RPL_LISTUSAGE), me.name, parv[0],
- "Where \037parameters\037 is a space or comma seperated "
- "list of one or more of:");
- sendto_one(sptr, rpl_str(RPL_LISTUSAGE), me.name, parv[0],
- " \002<\002\037max_users\037 ; Show all channels with less "
- "than \037max_users\037.");
- sendto_one(sptr, rpl_str(RPL_LISTUSAGE), me.name, parv[0],
- " \002>\002\037min_users\037 ; Show all channels with more "
- "than \037min_users\037.");
- sendto_one(sptr, rpl_str(RPL_LISTUSAGE), me.name, parv[0],
- " \002C<\002\037max_minutes\037 ; Channels that exist less "
- "than \037max_minutes\037.");
- sendto_one(sptr, rpl_str(RPL_LISTUSAGE), me.name, parv[0],
- " \002C>\002\037min_minutes\037 ; Channels that exist more "
- "than \037min_minutes\037.");
- sendto_one(sptr, rpl_str(RPL_LISTUSAGE), me.name, parv[0],
- " \002T<\002\037max_minutes\037 ; Channels with a topic last "
- "set less than \037max_minutes\037 ago.");
- sendto_one(sptr, rpl_str(RPL_LISTUSAGE), me.name, parv[0],
- " \002T>\002\037min_minutes\037 ; Channels with a topic last "
- "set more than \037min_minutes\037 ago.");
- sendto_one(sptr, rpl_str(RPL_LISTUSAGE), me.name, parv[0],
- "Example: LIST <3,>1,C<10,T>0 ; 2 users, younger than 10 min., "
- "topic set.");
- return 0;
- }
+ /* Only one wildcard allowed... */
+ if (args->wildcard[0] != 0)
+ return show_usage(sptr);
- sendto_one(sptr, rpl_str(RPL_LISTSTART), me.name, parv[0]);
+ /* If its not going to match anything, don't bother. */
+ if (param[0] != '*' &&
+ param[0] != '?' &&
+ param[0] != '#' &&
+ param[0] != '&')
+ return show_usage(sptr);
- if (!show_channels)
- {
- if (args.max_users > args.min_users + 1 && args.max_time > args.min_time &&
- args.max_topic_time > args.min_topic_time) /* Sanity check */
- {
- sptr->listing = (struct ListingArgs*) MyMalloc(sizeof(struct ListingArgs));
- assert(0 != sptr->listing);
- memcpy(sptr->listing, &args, sizeof(struct ListingArgs));
- if ((sptr->listing->chptr = GlobalChannelList)) {
- int m = GlobalChannelList->mode.mode & MODE_LISTED;
- list_next_channels(sptr, 64);
- GlobalChannelList->mode.mode |= m;
- return 0;
+ tmp1 = strchr(param, ',');
+ tmp2 = strchr(param, ' ');
+ if (tmp2 && (!tmp1 || (tmp2 < tmp1)))
+ tmp1 = tmp2;
+
+ if (tmp1)
+ *tmp1++ = 0;
+
+ ircd_strncpy(args->wildcard, param, CHANNELLEN-1);
+ args->wildcard[CHANNELLEN-1] = 0;
+
+ if (tmp1 == NULL)
+ return LPARAM_SUCCESS;
+
+ param = tmp1;
+ continue;
}
- MyFree(sptr->listing);
- sptr->listing = 0;
+
+ /* channel name? */
+ if (!permit_chan || !IsChannelName(param))
+ return show_usage(sptr);
+
+ return LPARAM_CHANNEL;
}
- sendto_one(sptr, rpl_str(RPL_LISTEND), me.name, parv[0]);
- return 0;
- }
- for (; (name = ircd_strtok(&p, parv[1], ",")); parv[1] = 0)
- {
- chptr = FindChannel(name);
- if (chptr && ShowChannel(sptr, chptr) && sptr->user)
- sendto_one(sptr, rpl_str(RPL_LIST), me.name, parv[0],
- chptr->chname,
- chptr->users - number_of_zombies(chptr), chptr->topic);
+ if (!*param) /* hit end of string? */
+ break;
+
+ param++;
}
- sendto_one(sptr, rpl_str(RPL_LISTEND), me.name, parv[0]);
- return 0;
+ return LPARAM_SUCCESS;
}
+void
+list_set_default(void)
+{
+ la_default = la_init; /* start off with a clean slate... */
+
+ if (param_parse(0, feature_str(FEAT_DEFAULT_LIST_PARAM), &la_default, 0) !=
+ LPARAM_SUCCESS)
+ la_default = la_init; /* recover from error by switching to default */
+}
-#if 0
/*
- * m_list
+ * m_list - generic message handler
*
* parv[0] = sender prefix
* parv[1] = channel list or user/time limit
* parv[2...] = more user/time limits
*/
-int m_list(struct Client* cptr, struct Client *sptr, int parc, char *parv[])
+int m_list(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
{
struct Channel *chptr;
char *name, *p = 0;
- int show_usage = 0, show_channels = 0, param;
- struct ListingArgs args = {
- 2147483647, /* max_time */
- 0, /* min_time */
- 4294967295U, /* max_users */
- 0, /* min_users */
- 0, /* topic_limits */
- 2147483647, /* max_topic_time */
- 0, /* min_topic_time */
- 0 /* chptr */
- };
-
- if (sptr->listing) /* Already listing ? */
+ int show_channels = 0, param;
+ struct ListingArgs args;
+
+ if (cli_listing(sptr)) /* Already listing ? */
{
- sptr->listing->chptr->mode.mode &= ~MODE_LISTED;
- MyFree(sptr->listing);
- sptr->listing = 0;
- sendto_one(sptr, rpl_str(RPL_LISTEND), me.name, sptr->name);
- if (parc < 2)
- return 0; /* Let LIST abort a listing. */
+ if (cli_listing(sptr))
+ MyFree(cli_listing(sptr));
+ cli_listing(sptr) = 0;
+ send_reply(sptr, RPL_LISTEND);
+ update_write(sptr);
+ if (parc < 2 || 0 == ircd_strcmp("STOP", parv[1]))
+ return 0; /* Let LIST or LIST STOP abort a listing. */
}
if (parc < 2) /* No arguments given to /LIST ? */
- {
-#ifdef DEFAULT_LIST_PARAM
- static char *defparv[MAXPARA + 1];
- static int defparc = 0;
- static char lp[] = DEFAULT_LIST_PARAM;
- int i;
+ args = la_default;
+ else {
+ args = la_init; /* initialize argument to blank slate */
- if (!defparc)
- {
- char *s = lp, *t;
+ for (param = 1; parv[param]; param++) { /* process each parameter */
+ switch (param_parse(sptr, parv[param], &args, parc == 2)) {
+ case LPARAM_ERROR: /* error encountered, usage already sent, return */
+ return 0;
- defparc = 1;
- defparv[defparc++] = t = strtok(s, " ");
- while (t && defparc < MAXPARA)
- {
- if ((t = strtok(0, " ")))
- defparv[defparc++] = t;
- }
- }
- for (i = 1; i < defparc; i++)
- parv[i] = defparv[i];
- parv[i] = 0;
- parc = defparc;
-#endif /* DEFAULT_LIST_PARAM */
- }
+ case LPARAM_CHANNEL: /* show channel instead */
+ show_channels++;
+ break;
- /* Decode command */
- for (param = 1; !show_usage && parv[param]; param++)
- {
- char *p = parv[param];
- do
- {
- int is_time = 0;
- switch (*p)
- {
- case 'T':
- case 't':
- is_time++;
- args.topic_limits = 1;
- /* Fall through */
- case 'C':
- case 'c':
- is_time++;
- p++;
- if (*p != '<' && *p != '>')
- {
- show_usage = 1;
- break;
- }
- /* Fall through */
- case '<':
- case '>':
- {
- p++;
- if (!IsDigit(*p))
- show_usage = 1;
- else
- {
- if (is_time)
- {
- time_t val = atoi(p);
- if (p[-1] == '<')
- {
- if (val < 80000000) /* Toggle UTC/offset */
- {
- /*
- * Demands that
- * 'TStime() - chptr->creationtime < val * 60'
- * Which equals
- * 'chptr->creationtime > TStime() - val * 60'
- */
- if (is_time == 1)
- args.min_time = TStime() - val * 60;
- else
- args.min_topic_time = TStime() - val * 60;
- }
- else if (is_time == 1) /* Creation time in UTC was entered */
- args.max_time = val;
- else /* Topic time in UTC was entered */
- args.max_topic_time = val;
- }
- else if (val < 80000000)
- {
- if (is_time == 1)
- args.max_time = TStime() - val * 60;
- else
- args.max_topic_time = TStime() - val * 60;
- }
- else if (is_time == 1)
- args.min_time = val;
- else
- args.min_topic_time = val;
- }
- else if (p[-1] == '<')
- args.max_users = atoi(p);
- else
- args.min_users = atoi(p);
- if ((p = strchr(p, ',')))
- p++;
- }
- break;
- }
- default:
- if (!IsChannelName(p))
- {
- show_usage = 1;
- break;
- }
- if (parc != 2) /* Don't allow a mixture of channels with <,> */
- show_usage = 1;
- show_channels = 1;
- p = 0;
- break;
+ case LPARAM_SUCCESS: /* parse succeeded */
+ break;
}
}
- while (!show_usage && p); /* p points after comma, or is NULL */
}
- if (show_usage)
- {
- sendto_one(sptr, rpl_str(RPL_LISTUSAGE), me.name, parv[0],
- "Usage: \002/QUOTE LIST\002 \037parameters\037");
- sendto_one(sptr, rpl_str(RPL_LISTUSAGE), me.name, parv[0],
- "Where \037parameters\037 is a space or comma seperated "
- "list of one or more of:");
- sendto_one(sptr, rpl_str(RPL_LISTUSAGE), me.name, parv[0],
- " \002<\002\037max_users\037 ; Show all channels with less "
- "than \037max_users\037.");
- sendto_one(sptr, rpl_str(RPL_LISTUSAGE), me.name, parv[0],
- " \002>\002\037min_users\037 ; Show all channels with more "
- "than \037min_users\037.");
- sendto_one(sptr, rpl_str(RPL_LISTUSAGE), me.name, parv[0],
- " \002C<\002\037max_minutes\037 ; Channels that exist less "
- "than \037max_minutes\037.");
- sendto_one(sptr, rpl_str(RPL_LISTUSAGE), me.name, parv[0],
- " \002C>\002\037min_minutes\037 ; Channels that exist more "
- "than \037min_minutes\037.");
- sendto_one(sptr, rpl_str(RPL_LISTUSAGE), me.name, parv[0],
- " \002T<\002\037max_minutes\037 ; Channels with a topic last "
- "set less than \037max_minutes\037 ago.");
- sendto_one(sptr, rpl_str(RPL_LISTUSAGE), me.name, parv[0],
- " \002T>\002\037min_minutes\037 ; Channels with a topic last "
- "set more than \037min_minutes\037 ago.");
- sendto_one(sptr, rpl_str(RPL_LISTUSAGE), me.name, parv[0],
- "Example: LIST <3,>1,C<10,T>0 ; 2 users, younger than 10 min., "
- "topic set.");
- return 0;
- }
-
- sendto_one(sptr, rpl_str(RPL_LISTSTART), me.name, parv[0]);
+ send_reply(sptr, RPL_LISTSTART);
if (!show_channels)
{
if (args.max_users > args.min_users + 1 && args.max_time > args.min_time &&
args.max_topic_time > args.min_topic_time) /* Sanity check */
{
- sptr->listing = (struct ListingArgs*) MyMalloc(sizeof(struct ListingArgs));
- assert(0 != sptr->listing);
- memcpy(sptr->listing, &args, sizeof(struct ListingArgs));
- if ((sptr->listing->chptr = GlobalChannelList)) {
- int m = GlobalChannelList->mode.mode & MODE_LISTED;
- list_next_channels(sptr, 64);
- GlobalChannelList->mode.mode |= m;
- return 0;
- }
- MyFree(sptr->listing);
- sptr->listing = 0;
+ cli_listing(sptr) = (struct ListingArgs*) MyMalloc(sizeof(struct ListingArgs));
+ assert(0 != cli_listing(sptr));
+ memcpy(cli_listing(sptr), &args, sizeof(struct ListingArgs));
+ list_next_channels(sptr);
+ return 0;
}
- sendto_one(sptr, rpl_str(RPL_LISTEND), me.name, parv[0]);
+ send_reply(sptr, RPL_LISTEND);
return 0;
}
for (; (name = ircd_strtok(&p, parv[1], ",")); parv[1] = 0)
{
chptr = FindChannel(name);
- if (chptr && ShowChannel(sptr, chptr) && sptr->user)
- sendto_one(sptr, rpl_str(RPL_LIST), me.name, parv[0],
- ShowChannel(sptr, chptr) ? chptr->chname : "*",
- chptr->users - number_of_zombies(chptr), chptr->topic);
+ if (!chptr)
+ continue;
+ if (ShowChannel(sptr, chptr)
+ || (IsAnOper(sptr) && HasPriv(sptr, PRIV_LIST_CHAN)))
+ send_reply(sptr, RPL_LIST, chptr->chname,
+ chptr->users - number_of_zombies(chptr), chptr->topic);
}
- sendto_one(sptr, rpl_str(RPL_LISTEND), me.name, parv[0]);
+ send_reply(sptr, RPL_LISTEND);
return 0;
}
-#endif /* 0 */
-