summaryrefslogtreecommitdiff
path: root/modules/m_testmask.c
blob: 78d02d592e4da7f9450a58c9275b488407f0eb50 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
 *  ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
 *  m_testmask.c: Counts the birdies err local and remote clients.
 *
 *  Copyright (C) 2005 by Diane Bruce
 *  Coypright (C) 2005 ircd-hybrid team
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are
 *  met:
 *
 *  1.Redistributions of source code must retain the above copyright notice,
 *    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. 
 *  3.The name of the author may not be used to endorse or promote products
 *    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
 *  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 *  DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
 *  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 *  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 *  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 *  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 *  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
 *  IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 *  POSSIBILITY OF SUCH DAMAGE.
 *
 *  $Id$
 */

#include "stdinc.h"
#include "client.h"
#include "irc_string.h"
#include "ircd_defs.h"
#include "ircd.h"
#include "restart.h"
#include "conf.h"
#include "send.h"
#include "hostmask.h"
#include "numeric.h"
#include "parse.h"
#include "modules.h"


/* mo_testmask()
 *
 * inputs       - pointer to physical connection request is coming from
 *              - pointer to source connection request is coming from
 *              - parc arg count
 *              - parv actual arguments   
 * output       - NONE
 * side effects - count up clients matching mask
 * i.e. /quote testmask user@host
 */
static void
mo_testmask(struct Client *client_p, struct Client *source_p,
            int parc, char *parv[])
{
  struct split_nuh_item nuh;
  char given_nick[IRCD_BUFSIZE];
  char given_user[IRCD_BUFSIZE];
  char given_host[IRCD_BUFSIZE];
  unsigned int count[2] = { 0, 0 };
  const dlink_node *ptr = NULL;

  if (EmptyString(parv[1]))
  {
    sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
               me.name, source_p->name, "TESTMASK");
    return;
  }

  nuh.nuhmask  = parv[1];
  nuh.nickptr  = given_nick;
  nuh.userptr  = given_user;
  nuh.hostptr  = given_host;

  nuh.nicksize = sizeof(given_nick);
  nuh.usersize = sizeof(given_user);
  nuh.hostsize = sizeof(given_host);

  split_nuh(&nuh);

  DLINK_FOREACH(ptr, global_client_list.head)
  {
    const struct Client *target_p = ptr->data;

    if (!IsClient(target_p) || match(given_nick, target_p->name))
      continue;

    if (!match(given_user, target_p->username))
      if (!match(given_host, target_p->host) || !match(given_host, target_p->sockhost))
        ++count[!MyConnect(target_p)];
  }

  sendto_one(source_p, form_str(RPL_TESTMASK), me.name,
             source_p->name,
             given_nick, given_user,
             given_host, count[0], count[1]);
}

static struct Message testmask_msgtab = {
  "TESTMASK", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
  {m_unregistered, m_not_oper, m_ignore, m_ignore, mo_testmask, m_ignore}
};

static void
module_init(void)
{
  mod_add_cmd(&testmask_msgtab);
}

static void
module_exit(void)
{
  mod_del_cmd(&testmask_msgtab);
}

struct module module_entry = {
  .node    = { NULL, NULL, NULL },
  .name    = NULL,
  .version = "$Revision$",
  .handle  = NULL,
  .modinit = module_init,
  .modexit = module_exit,
  .flags   = 0
};