]> jfr.im git - solanum.git/blobdiff - modules/m_list.c
Rerun autoconf.
[solanum.git] / modules / m_list.c
index e6aaff4ebbd31c167206cfaf153eaf076e45df38..d8f70607d298504516b25c2a2fd16fef59a48212 100644 (file)
 #include "channel.h"
 #include "client.h"
 #include "hash.h"
-#include "irc_string.h"
+#include "match.h"
 #include "ircd.h"
 #include "numeric.h"
 #include "s_conf.h"
+#include "s_newconf.h"
 #include "s_serv.h"
+#include "supported.h"
 #include "send.h"
 #include "msg.h"
 #include "parse.h"
@@ -61,7 +63,7 @@ static void safelist_client_release(struct Client *);
 static void safelist_one_channel(struct Client *source_p, struct Channel *chptr);
 static void safelist_iterate_client(struct Client *source_p);
 static void safelist_iterate_clients(void *unused);
-static void safelist_channel_named(struct Client *source_p, const char *name);
+static void safelist_channel_named(struct Client *source_p, const char *name, int operspy);
 
 struct Message list_msgtab = {
        "LIST", 0, 0, 0, MFLG_SLOW,
@@ -83,12 +85,26 @@ static int _modinit(void)
 {
        iterate_clients_ev = rb_event_add("safelist_iterate_clients", safelist_iterate_clients, NULL, 3);
 
+       /* ELIST=[tokens]:
+        *
+        * M = mask search
+        * N = !mask search
+        * U = user count search (< >)
+        * C = creation time search (C> C<)
+        * T = topic search (T> T<)
+        */
+       add_isupport("SAFELIST", isupport_string, "");
+       add_isupport("ELIST", isupport_string, "CTU");
+
        return 0;
 }
 
 static void _moddeinit(void)
 {
        rb_event_delete(iterate_clients_ev);
+
+       delete_isupport("SAFELIST");
+       delete_isupport("ELIST");
 }
 
 static void safelist_check_cliexit(hook_data_client_exit * hdata)
@@ -103,7 +119,6 @@ static void safelist_check_cliexit(hook_data_client_exit * hdata)
 }
 
 /* m_list()
- *      parv[0] = sender prefix
  *      parv[1] = channel
  *
  * XXX - With SAFELIST, do we really need to continue pacing?
@@ -116,7 +131,6 @@ static int m_list(struct Client *client_p, struct Client *source_p, int parc, co
        if (source_p->localClient->safelist_data != NULL)
        {
                sendto_one_notice(source_p, ":/LIST aborted");
-               sendto_one(source_p, form_str(RPL_LISTEND), me.name, source_p->name);
                safelist_client_release(source_p);
                return 0;
        }
@@ -138,35 +152,58 @@ static int m_list(struct Client *client_p, struct Client *source_p, int parc, co
 }
 
 /* mo_list()
- *      parv[0] = sender prefix
  *      parv[1] = channel
  */
 static int mo_list(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
 {
-       struct ListClient params;
-       char *p, *args;
+       struct ListClient *params;
+       char *p;
+       char *args = NULL;
        int i;
+       int operspy = 0;
 
        if (source_p->localClient->safelist_data != NULL)
        {
                sendto_one_notice(source_p, ":/LIST aborted");
-               sendto_one(source_p, form_str(RPL_LISTEND), me.name, source_p->name);
                safelist_client_release(source_p);
                return 0;
        }
 
+       if (parc > 1)
+       {
+               args = LOCAL_COPY(parv[1]);
+       }
+
+       if (args && *args == '!' && IsOperSpy(source_p))
+       {
+               args++;
+               report_operspy(source_p, "LIST", args);
+               operspy = 1;
+       }
+
+       /* Single channel. */
+       if (args && IsChannelName(args))
+       {
+               safelist_channel_named(source_p, args, operspy);
+               return 0;
+       }
+
+       /* Multiple channels, possibly with parameters. */
+       params = rb_malloc(sizeof(struct ListClient));
+
        /* XXX rather arbitrary -- jilles */
-       params.users_min = 3;
-       params.users_max = INT_MAX;
+       params->users_min = 3;
+       params->users_max = INT_MAX;
+       params->operspy = operspy;
+       params->created_min = params->topic_min = 
+               params->created_max = params->topic_max = 0;
 
-       if (parc > 1 && parv[1] != NULL && !IsChannelName(parv[1]))
+       if (args && !EmptyString(args))
        {
-               args = LOCAL_COPY(parv[1]);
-               /* Make any specification cancel out defaults */
-               if (*args == '<')
-                       params.users_min = 0;
+               /* Cancel out default minimum. */
+               params->users_min = 0;
 
-               for (i = 0; i < 2; i++)
+               for (i = 0; i < 7; i++)
                {
                        if ((p = strchr(args, ',')) != NULL)
                                *p++ = '\0';
@@ -176,22 +213,64 @@ static int mo_list(struct Client *client_p, struct Client *source_p, int parc, c
                                args++;
                                if (IsDigit(*args))
                                {
-                                       params.users_max = atoi(args);
-                                       if (params.users_max == 0)
-                                               params.users_max = INT_MAX;
+                                       params->users_max = atoi(args);
+                                       if (params->users_max == 0)
+                                               params->users_max = INT_MAX;
                                        else
-                                               params.users_max--;
+                                               params->users_max--;
                                }
-                               else
-                                       params.users_max = INT_MAX;
                        }
                        else if (*args == '>')
                        {
                                args++;
                                if (IsDigit(*args))
-                                       params.users_min = atoi(args) + 1;
+                                       params->users_min = atoi(args) + 1;
                                else
-                                       params.users_min = 0;
+                                       params->users_min = 0;
+                       }
+                       else if (*args == 'C' || *args == 'c')
+                       {
+                               args++;
+                               if (*args == '>')
+                               {
+                                       /* Creation time earlier than last x minutes. */
+                                       args++;
+                                       if (IsDigit(*args))
+                                       {
+                                               params->created_max = rb_current_time() - (60 * atoi(args));
+                                       }
+                               }
+                               else if (*args == '<')
+                               {
+                                       /* Creation time within last x minutes. */
+                                       args++;
+                                       if (IsDigit(*args))
+                                       {
+                                               params->created_min = rb_current_time() - (60 * atoi(args));
+                                       }
+                               }
+                       }
+                       else if (*args == 'T' || *args == 't')
+                       {
+                               args++;
+                               if (*args == '>')
+                               {
+                                       /* Topic change time earlier than last x minutes. */
+                                       args++;
+                                       if (IsDigit(*args))
+                                       {
+                                               params->topic_max = rb_current_time() - (60 * atoi(args));
+                                       }
+                               }
+                               else if (*args == '<')
+                               {
+                                       /* Topic change time within last x minutes. */
+                                       args++;
+                                       if (IsDigit(*args))
+                                       {
+                                               params->topic_min = rb_current_time() - (60 * atoi(args));
+                                       }
+                               }
                        }
 
                        if (EmptyString(p))
@@ -200,13 +279,8 @@ static int mo_list(struct Client *client_p, struct Client *source_p, int parc, c
                                args = p;
                }
        }
-       else if (parc > 1 && IsChannelName(parv[1]))
-       {
-               safelist_channel_named(source_p, parv[1]);
-               return 0;
-       }
 
-       safelist_client_instantiate(source_p, &params);
+       safelist_client_instantiate(source_p, params);
 
        return 0;
 }
@@ -234,7 +308,7 @@ static int safelist_sendq_exceeded(struct Client *client_p)
  * safelist_client_instantiate()
  *
  * inputs       - pointer to Client to be listed,
- *                struct ListClient to copy for params
+ *                pointer to ListClient for params
  * outputs      - none
  * side effects - the safelist process begins for a
  *                client.
@@ -244,18 +318,10 @@ static int safelist_sendq_exceeded(struct Client *client_p)
  */
 static void safelist_client_instantiate(struct Client *client_p, struct ListClient *params)
 {
-       struct ListClient *self;
-
        s_assert(MyClient(client_p));
        s_assert(params != NULL);
 
-       self = rb_malloc(sizeof(struct ListClient));
-
-       self->hash_indice = 0;
-       self->users_min = params->users_min;
-       self->users_max = params->users_max;
-
-       client_p->localClient->safelist_data = self;
+       client_p->localClient->safelist_data = params;
 
        sendto_one(client_p, form_str(RPL_LISTSTART), me.name, client_p->name);
 
@@ -293,40 +359,42 @@ static void safelist_client_release(struct Client *client_p)
 /*
  * safelist_channel_named()
  *
- * inputs       - client pointer, channel name
+ * inputs       - client pointer, channel name, operspy
  * outputs      - none
  * side effects - a named channel is listed
  */
-static void safelist_channel_named(struct Client *source_p, const char *name)
+static void safelist_channel_named(struct Client *source_p, const char *name, int operspy)
 {
        struct Channel *chptr;
        char *p;
-       char *n = LOCAL_COPY(name);
+       int visible;
 
        sendto_one(source_p, form_str(RPL_LISTSTART), me.name, source_p->name);
 
-       if ((p = strchr(n, ',')))
+       if ((p = strchr(name, ',')))
                *p = '\0';
 
-       if (*n == '\0')
+       if (*name == '\0')
        {
                sendto_one_numeric(source_p, ERR_NOSUCHNICK, form_str(ERR_NOSUCHNICK), name);
                sendto_one(source_p, form_str(RPL_LISTEND), me.name, source_p->name);
                return;
        }
 
-       chptr = find_channel(n);
+       chptr = find_channel(name);
 
        if (chptr == NULL)
        {
-               sendto_one_numeric(source_p, ERR_NOSUCHNICK, form_str(ERR_NOSUCHNICK), n);
+               sendto_one_numeric(source_p, ERR_NOSUCHNICK, form_str(ERR_NOSUCHNICK), name);
                sendto_one(source_p, form_str(RPL_LISTEND), me.name, source_p->name);
                return;
        }
 
-       if (ShowChannel(source_p, chptr))
-               sendto_one(source_p, form_str(RPL_LIST), me.name, source_p->name, chptr->chname,
-                          rb_dlink_list_length(&chptr->members),
+       visible = !SecretChannel(chptr) || IsMember(source_p, chptr);
+       if (visible || operspy)
+               sendto_one(source_p, form_str(RPL_LIST), me.name, source_p->name,
+                          visible ? "" : "!",
+                          chptr->chname, rb_dlink_list_length(&chptr->members),
                           chptr->topic == NULL ? "" : chptr->topic);
 
        sendto_one(source_p, form_str(RPL_LISTEND), me.name, source_p->name);
@@ -344,16 +412,34 @@ static void safelist_channel_named(struct Client *source_p, const char *name)
 static void safelist_one_channel(struct Client *source_p, struct Channel *chptr)
 {
        struct ListClient *safelist_data = source_p->localClient->safelist_data;
+       int visible;
 
-       if (SecretChannel(chptr) && !IsMember(source_p, chptr))
+       visible = !SecretChannel(chptr) || IsMember(source_p, chptr);
+       if (!visible && !safelist_data->operspy)
                return;
 
        if ((unsigned int)chptr->members.length < safelist_data->users_min
            || (unsigned int)chptr->members.length > safelist_data->users_max)
                return;
 
-       sendto_one(source_p, form_str(RPL_LIST), me.name, source_p->name, chptr->chname,
-                  chptr->members.length, chptr->topic == NULL ? "" : chptr->topic);
+       if (safelist_data->topic_min && chptr->topic_time < safelist_data->topic_min)
+               return;
+
+       /* If a topic TS is provided, don't show channels without a topic set. */
+       if (safelist_data->topic_max && (chptr->topic_time > safelist_data->topic_max
+               || chptr->topic_time == 0))
+               return;
+
+       if (safelist_data->created_min && chptr->channelts < safelist_data->created_min)
+               return;
+
+       if (safelist_data->created_max && chptr->channelts > safelist_data->created_max)
+               return;
+
+       sendto_one(source_p, form_str(RPL_LIST), me.name, source_p->name,
+                  visible ? "" : "!",
+                  chptr->chname, rb_dlink_list_length(&chptr->members),
+                  chptr->topic == NULL ? "" : chptr->topic);
 }
 
 /*