ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/branches/8.2.x/modules/m_accept.c
(Generate patch)

Comparing:
ircd-hybrid-7.3/modules/m_accept.c (file contents), Revision 1029 by michael, Sun Nov 8 13:10:50 2009 UTC vs.
ircd-hybrid/branches/8.2.x/modules/m_accept.c (file contents), Revision 4341 by michael, Sat Aug 2 16:53:48 2014 UTC

# Line 1 | Line 1
1   /*
2 < *  ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
2 > *  ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3   *
4 < *  Copyright (C) 2002 by the past and present ircd coders, and others.
4 > *  Copyright (c) 2000-2014 ircd-hybrid development team
5   *
6   *  This program is free software; you can redistribute it and/or modify
7   *  it under the terms of the GNU General Public License as published by
# Line 25 | Line 25
25   */
26  
27   #include "stdinc.h"
28 #include "handlers.h"
28   #include "client.h"
29   #include "irc_string.h"
31 #include "sprintf_irc.h"
30   #include "ircd.h"
31   #include "list.h"
32   #include "numeric.h"
33 < #include "s_conf.h"
36 < #include "s_serv.h"
33 > #include "conf.h"
34   #include "send.h"
38 #include "msg.h"
35   #include "parse.h"
36   #include "modules.h"
37 <
42 < static void m_accept(struct Client *, struct Client *, int, char *[]);
43 <
44 < struct Message accept_msgtab = {
45 <  "ACCEPT", 0, 0, 0, 0, MFLG_SLOW, 0,
46 <  { m_unregistered, m_accept, m_ignore, m_ignore, m_accept, m_ignore }
47 < };
48 <
49 < #ifndef STATIC_MODULES
50 < void
51 < _modinit(void)
52 < {
53 <  mod_add_cmd(&accept_msgtab);
54 < }
55 <
56 < void
57 < _moddeinit(void)
58 < {
59 <  mod_del_cmd(&accept_msgtab);
60 < }
61 <
62 < const char *_version = "$Revision$";
63 < #endif
37 > #include "memory.h"
38  
39  
40   /*! \brief Creates and sends a list of nick!user\@host masks a Client
# Line 72 | Line 46 | static void
46   list_accepts(struct Client *source_p)
47   {
48    int len = 0;
49 <  char nicks[IRCD_BUFSIZE] = { '\0' };
49 >  char nicks[IRCD_BUFSIZE] = "";
50    char *t = nicks;
51    const dlink_node *ptr = NULL;
52  
53 <  len = strlen(me.name) + strlen(source_p->name) + 12;
53 >  /* :me.name 281 source_p->name :n1!u1@h1 n2!u2@h2 ...\r\n */
54 >  /* 1       23456              78                     9 10 */
55 >  len = strlen(me.name) + strlen(source_p->name) + 10;
56  
57    DLINK_FOREACH(ptr, source_p->localClient->acceptlist.head)
58    {
59      const struct split_nuh_item *accept_p = ptr->data;
60      size_t masklen = strlen(accept_p->nickptr) +
61                       strlen(accept_p->userptr) +
62 <                     strlen(accept_p->hostptr) + 2 /* !@ */ ;
62 >                     strlen(accept_p->hostptr) + 3;  /* +3 for ! + @ + space */
63  
64 <    if ((t - nicks) + masklen + len  > IRCD_BUFSIZE)
64 >    if ((t - nicks) + masklen + len > IRCD_BUFSIZE)
65      {
66        *(t - 1) = '\0';
67 <      sendto_one(source_p, form_str(RPL_ACCEPTLIST),
92 <                 me.name, source_p->name, nicks);
67 >      sendto_one_numeric(source_p, &me, RPL_ACCEPTLIST, nicks);
68        t = nicks;
69      }
70  
71 <    t += ircsprintf(t, "%s!%s@%s ",
72 <                    accept_p->nickptr,
73 <                    accept_p->userptr, accept_p->hostptr);
71 >    t += sprintf(t, "%s!%s@%s ",
72 >                 accept_p->nickptr,
73 >                 accept_p->userptr, accept_p->hostptr);
74    }
75  
76 <  if (nicks[0] != '\0')
76 >  if (nicks[0])
77    {
78      *(t - 1) = '\0';
79 <    sendto_one(source_p, form_str(RPL_ACCEPTLIST),
105 <               me.name, source_p->name, nicks);
79 >    sendto_one_numeric(source_p, &me, RPL_ACCEPTLIST, nicks);
80    }
81  
82 <  sendto_one(source_p, form_str(RPL_ENDOFACCEPT),
109 <             me.name, source_p->name);
82 >  sendto_one_numeric(source_p, &me, RPL_ENDOFACCEPT);
83   }
84  
85   /*! \brief Allocates and adds a split_nuh_item holding a nick!user\@host
# Line 118 | Line 91 | list_accepts(struct Client *source_p)
91   static void
92   add_accept(const struct split_nuh_item *nuh, struct Client *source_p)
93   {
94 <  struct split_nuh_item *accept_p = MyMalloc(sizeof(*accept_p));
94 >  struct split_nuh_item *accept_p = MyCalloc(sizeof(*accept_p));
95  
96 <  DupString(accept_p->nickptr, nuh->nickptr);
97 <  DupString(accept_p->userptr, nuh->userptr);
98 <  DupString(accept_p->hostptr, nuh->hostptr);
96 >  accept_p->nickptr = xstrdup(nuh->nickptr);
97 >  accept_p->userptr = xstrdup(nuh->userptr);
98 >  accept_p->hostptr = xstrdup(nuh->hostptr);
99  
100    dlinkAdd(accept_p, &accept_p->node, &source_p->localClient->acceptlist);
101  
# Line 131 | Line 104 | add_accept(const struct split_nuh_item *
104  
105   /*! \brief ACCEPT command handler
106   *
134 * \param client_p Pointer to allocated Client struct with physical connection
135 *                 to this server, i.e. with an open socket connected.
107   * \param source_p Pointer to allocated Client struct from which the message
108   *                 originally comes from.  This can be a local or remote client.
109   * \param parc     Integer holding the number of supplied arguments.
110   * \param parv     Argument vector where parv[0] .. parv[parc-1] are non-NULL
111   *                 pointers.
112   * \note Valid arguments for this command are:
113 < *      - parv[0] = sender prefix
114 < *      - parv[1] = list of masks to be accepted or removed (optional)
113 > *      - parv[0] = command
114 > *      - parv[1] = comma-separated list of masks to be accepted or removed
115   */
116 < static void
117 < m_accept(struct Client *client_p, struct Client *source_p,
147 <         int parc, char *parv[])
116 > static int
117 > m_accept(struct Client *source_p, int parc, char *parv[])
118   {
119    char *mask = NULL;
120    char *p = NULL;
121 <  char nick[NICKLEN + 1];
122 <  char user[USERLEN + 1];
123 <  char host[HOSTLEN + 1];
121 >  char nick[NICKLEN + 1] = "";
122 >  char user[USERLEN + 1] = "";
123 >  char host[HOSTLEN + 1] = "";
124    struct split_nuh_item nuh;
125    struct split_nuh_item *accept_p = NULL;
126  
127 <  if (EmptyString(parv[1]) || !irccmp(parv[1], "*"))
127 >  if (EmptyString(parv[1]) || !strcmp(parv[1], "*"))
128    {
129      list_accepts(source_p);
130 <    return;
130 >    return 0;
131    }
132  
133 <  for (mask = strtoken(&p, parv[1], ","); mask != NULL;
133 >  for (mask = strtoken(&p, parv[1], ","); mask;
134         mask = strtoken(&p,    NULL, ","))
135    {
136 <    if (*mask == '-' && *++mask != '\0')
136 >    if (*mask == '-' && *++mask)
137      {
138        nuh.nuhmask  = mask;
139        nuh.nickptr  = nick;
# Line 176 | Line 146 | m_accept(struct Client *client_p, struct
146  
147        split_nuh(&nuh);
148  
149 <      if ((accept_p = find_accept(nick, user, host, source_p, 0)) == NULL)
149 >      if ((accept_p = find_accept(nick, user, host, source_p, irccmp)) == NULL)
150        {
151 <        sendto_one(source_p, form_str(ERR_ACCEPTNOT),
182 <                   me.name, source_p->name, nick, user, host);
151 >        sendto_one_numeric(source_p, &me, ERR_ACCEPTNOT, nick, user, host);
152          continue;
153        }
154  
155        del_accept(accept_p, source_p);
156      }
157 <    else if (*mask != '\0')
157 >    else if (*mask)
158      {
159        if (dlink_list_length(&source_p->localClient->acceptlist) >=
160 <          ConfigFileEntry.max_accept)
160 >          ConfigGeneral.max_accept)
161        {
162 <        sendto_one(source_p, form_str(ERR_ACCEPTFULL),
163 <                   me.name, source_p->name);
195 <        return;
162 >        sendto_one_numeric(source_p, &me, ERR_ACCEPTFULL);
163 >        return 0;
164        }
165  
166        nuh.nuhmask  = mask;
# Line 206 | Line 174 | m_accept(struct Client *client_p, struct
174  
175        split_nuh(&nuh);
176  
177 <      if ((accept_p = find_accept(nick, user, host, source_p, 0)) != NULL)
177 >      if ((accept_p = find_accept(nick, user, host, source_p, irccmp)))
178        {
179 <        sendto_one(source_p, form_str(ERR_ACCEPTEXIST),
212 <                   me.name, source_p->name, nick, user, host);
179 >        sendto_one_numeric(source_p, &me, ERR_ACCEPTEXIST, nick, user, host);
180          continue;
181        }
182  
183        add_accept(&nuh, source_p);
184      }
185    }
186 +
187 +  return 0;
188 + }
189 +
190 + static struct Message accept_msgtab =
191 + {
192 +  "ACCEPT", 0, 0, 0, MAXPARA, MFLG_SLOW, 0,
193 +  { m_unregistered, m_accept, m_ignore, m_ignore, m_accept, m_ignore }
194 + };
195 +
196 + static void
197 + module_init(void)
198 + {
199 +  mod_add_cmd(&accept_msgtab);
200   }
201 +
202 + static void
203 + module_exit(void)
204 + {
205 +  mod_del_cmd(&accept_msgtab);
206 + }
207 +
208 + struct module module_entry =
209 + {
210 +  .node    = { NULL, NULL, NULL },
211 +  .name    = NULL,
212 +  .version = "$Revision$",
213 +  .handle  = NULL,
214 +  .modinit = module_init,
215 +  .modexit = module_exit,
216 +  .flags   = 0
217 + };

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)