]> jfr.im git - solanum.git/blobdiff - modules/m_testmask.c
Combine stats A output parameters (#35)
[solanum.git] / modules / m_testmask.c
index 2fa4eea8a741e4f04a995010edd8fcb87bfa77e2..46b431f87ce0e57165fc7883ddcb99ae1deddeff 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  m_testmask.c: Shows the number of matching local and global clients
- *                for a user@host mask, helpful when setting GLINE's
+ *                for a user@host mask
  *
  *  Copyright (C) 2003 by W. Campbell
  *  Coypright (C) 2004 ircd-ratbox development team
  *  met:
  *
  *  1.Redistributions of source code must retain the above copyright notice,
- *    this list of conditions and the following disclaimer. 
+ *    this list of conditions and the following disclaimer.
  *  2.Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution. 
+ *    documentation and/or other materials provided with the distribution.
  *  3.The name of the author may not be used to endorse or promote products
- *    derived from this software without specific prior written permission. 
+ *    derived from this software without specific prior written permission.
  *
  *  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  *  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  *  IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  *  POSSIBILITY OF SUCH DAMAGE.
  *
- *  $Id: m_testmask.c 2775 2006-11-27 11:45:31Z jilles $
- *
  */
 
 /* List of ircd includes from ../include/ */
 #include "stdinc.h"
 #include "client.h"
-#include "common.h"     /* FALSE bleah */
 #include "ircd.h"
-#include "irc_string.h"
+#include "match.h"
 #include "numeric.h"
 #include "s_conf.h"
-#include "s_log.h"
+#include "logger.h"
 #include "s_serv.h"
 #include "send.h"
 #include "msg.h"
 #include "parse.h"
 #include "modules.h"
 
-static int mo_testmask(struct Client *client_p, struct Client *source_p,
+static const char testmask_desc[] =
+       "Provides the TESTMASK command to show the number of clients matching a hostmask or GECOS";
+
+static void mo_testmask(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p,
                        int parc, const char *parv[]);
 
 struct Message testmask_msgtab = {
-       "TESTMASK", 0, 0, 0, MFLG_SLOW,
+       "TESTMASK", 0, 0, 0, 0,
        {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_testmask, 2}}
 };
 
 mapi_clist_av1 testmask_clist[] = { &testmask_msgtab, NULL };
-DECLARE_MODULE_AV1(testmask, NULL, NULL, testmask_clist, NULL, NULL, "$Revision: 2775 $");
+DECLARE_MODULE_AV2(testmask, NULL, NULL, testmask_clist, NULL, NULL, NULL, NULL, testmask_desc);
 
 static const char *empty_sockhost = "255.255.255.255";
 static const char *spoofed_sockhost = "0";
 
-static int
-mo_testmask(struct Client *client_p, struct Client *source_p,
+static void
+mo_testmask(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p,
                         int parc, const char *parv[])
 {
        struct Client *target_p;
@@ -71,8 +71,8 @@ mo_testmask(struct Client *client_p, struct Client *source_p,
        int gcount = 0;
        char *name, *username, *hostname;
        const char *sockhost;
-       char *gecos = NULL, *mangle_gecos = NULL;
-       dlink_node *ptr;
+       char *gecos = NULL;
+       rb_dlink_node *ptr;
 
        name = LOCAL_COPY(parv[1]);
        collapse(name);
@@ -80,9 +80,8 @@ mo_testmask(struct Client *client_p, struct Client *source_p,
        /* username is required */
        if((hostname = strchr(name, '@')) == NULL)
        {
-               sendto_one(source_p, ":%s NOTICE %s :Invalid parameters",
-                               me.name, source_p->name);
-               return 0;
+               sendto_one_notice(source_p, ":Invalid parameters");
+               return;
        }
 
        *hostname++ = '\0';
@@ -98,50 +97,17 @@ mo_testmask(struct Client *client_p, struct Client *source_p,
 
        if(EmptyString(username) || EmptyString(hostname))
        {
-               sendto_one(source_p, ":%s NOTICE %s :Invalid parameters",
-                               me.name, source_p->name);
-               return 0;
+               sendto_one_notice(source_p, ":Invalid parameters");
+               return;
        }
 
        if(parc > 2 && !EmptyString(parv[2]))
        {
                gecos = LOCAL_COPY(parv[2]);
                collapse_esc(gecos);
-               if(strstr(gecos, "\\s"))
-               {
-                       char *tmp = LOCAL_COPY(gecos);
-                       char *orig = tmp;
-                       char *new = tmp; 
-                       while(*orig)
-                       {
-                               if(*orig == '\\' && *(orig + 1) != '\0')
-                               {
-                                       if(*(orig + 1) == 's')
-                                       {
-                                               *new++ = ' ';
-                                               orig += 2;   
-                                       }
-                                       /* otherwise skip that and the escaped
-                                        * character after it, so we dont mistake
-                                        * \\s as \s --fl
-                                        */
-                                       else
-                                       {   
-                                               *new++ = *orig++;
-                                               *new++ = *orig++;
-                                       }
-                               }
-                               else
-                                       *new++ = *orig++;
-                       }
-
-                       *new = '\0';
-                       mangle_gecos = LOCAL_COPY(tmp);
-               } else
-                       mangle_gecos = gecos;
        }
 
-       DLINK_FOREACH(ptr, global_client_list.head)
+       RB_DLINK_FOREACH(ptr, global_client_list.head)
        {
                target_p = ptr->data;
 
@@ -163,7 +129,7 @@ mo_testmask(struct Client *client_p, struct Client *source_p,
                        if(name && !match(name, target_p->name))
                                continue;
 
-                       if(mangle_gecos && !match_esc(mangle_gecos, target_p->info))
+                       if(gecos && !match_esc(gecos, target_p->info))
                                continue;
 
                        if(MyClient(target_p))
@@ -177,5 +143,4 @@ mo_testmask(struct Client *client_p, struct Client *source_p,
                        me.name, source_p->name,
                        lcount, gcount, name ? name : "*",
                        username, hostname, gecos ? gecos : "*");
-       return 0;
 }