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

Comparing:
ircd-hybrid/modules/m_accept.c (file contents), Revision 33 by knight, Sun Oct 2 20:50:00 2005 UTC vs.
ircd-hybrid/trunk/modules/m_accept.c (file contents), Revision 2363 by michael, Thu Jul 4 21:29:23 2013 UTC

# Line 1 | Line 1
1   /*
2   *  ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 *  m_accept.c: Allows a user to talk to a +g user.
3   *
4   *  Copyright (C) 2002 by the past and present ircd coders, and others.
5   *
# Line 18 | Line 17
17   *  along with this program; if not, write to the Free Software
18   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
19   *  USA
20 < *
21 < *  $Id$
20 > */
21 >
22 > /*! \file m_accept.c
23 > * \brief Includes required functions for processing the ACCEPT command.
24 > * \version $Id$
25   */
26  
27   #include "stdinc.h"
26 #include "handlers.h"
28   #include "client.h"
29   #include "irc_string.h"
29 #include "sprintf_irc.h"
30 #include "hash.h"       /* for find_client() */
30   #include "ircd.h"
31   #include "list.h"
32   #include "numeric.h"
33 < #include "s_conf.h"
33 > #include "conf.h"
34   #include "s_serv.h"
35   #include "send.h"
37 #include "msg.h"
36   #include "parse.h"
39 #include "s_user.h"
37   #include "modules.h"
38 + #include "memory.h"
39  
42 static void m_accept(struct Client *, struct Client *, int, char *[]);
43 static void build_nicklist(struct Client *, char *, char *, char *);
44 static void add_accept(struct Client *, struct Client *);
45 static void list_accepts(struct Client *);
46
47 struct Message accept_msgtab = {
48  "ACCEPT", 0, 0, 0, 0, MFLG_SLOW, 0,
49  {m_unregistered, m_accept, m_ignore, m_ignore, m_accept, m_ignore}
50 };
51
52 #ifndef STATIC_MODULES
53 void
54 _modinit(void)
55 {
56  mod_add_cmd(&accept_msgtab);
57 }
58
59 void
60 _moddeinit(void)
61 {
62  mod_del_cmd(&accept_msgtab);
63 }
64
65 const char *_version = "$Revision$";
66 #endif
40  
41 < /*
42 < * m_accept - ACCEPT command handler
43 < *      parv[0] = sender prefix
44 < *      parv[1] = servername
41 > /*! \brief Creates and sends a list of nick!user\@host masks a Client
42 > *         has on its acceptlist.
43 > *
44 > * \param source_p The actual Client the list will be sent to.
45   */
46   static void
47 < m_accept(struct Client *client_p, struct Client *source_p,
75 <         int parc, char *parv[])
47 > list_accepts(struct Client *source_p)
48   {
49 <  char *nick;
50 <  char *p = NULL;
51 <  char addbuf[IRCD_BUFSIZE] = { '\0' };
52 <  char delbuf[IRCD_BUFSIZE] = { '\0' };
81 <  struct Client *target_p = NULL;
82 <  int accept_num;
83 <  
84 <  if ((parc < 2) || (*parv[1] == '*'))
85 <  {
86 <    list_accepts(source_p);
87 <    return;
88 <  }
49 >  int len = 0;
50 >  char nicks[IRCD_BUFSIZE] = { '\0' };
51 >  char *t = nicks;
52 >  const dlink_node *ptr = NULL;
53  
54 <  build_nicklist(source_p, addbuf, delbuf, parv[1]);
54 >  len = strlen(me.name) + strlen(source_p->name) + 12;
55  
56 <  /* parse the delete list */
93 <  for (nick = strtoken(&p, delbuf, ","); nick != NULL;
94 <       nick = strtoken(&p, NULL, ","))
56 >  DLINK_FOREACH(ptr, source_p->localClient->acceptlist.head)
57    {
58 <    /* shouldnt happen, but lets be paranoid */
59 <    if (((target_p = find_client(nick)) == NULL) || !IsClient(target_p))
60 <    {
61 <      sendto_one(source_p, form_str(ERR_NOSUCHNICK),
100 <                 me.name, source_p->name, nick);
101 <      continue;
102 <    }
58 >    const struct split_nuh_item *accept_p = ptr->data;
59 >    size_t masklen = strlen(accept_p->nickptr) +
60 >                     strlen(accept_p->userptr) +
61 >                     strlen(accept_p->hostptr) + 2 /* !@ */ ;
62  
63 <    /* user isnt on clients accept list */
105 <    if (!accept_message(target_p, source_p))
63 >    if ((t - nicks) + masklen + len  > IRCD_BUFSIZE)
64      {
65 <      sendto_one(source_p, form_str(ERR_ACCEPTNOT),
66 <                 me.name, source_p->name, target_p->name);
67 <      continue;
65 >      *(t - 1) = '\0';
66 >      sendto_one(source_p, form_str(RPL_ACCEPTLIST),
67 >                 me.name, source_p->name, nicks);
68 >      t = nicks;
69      }
70  
71 <    del_from_accept(target_p, source_p);
71 >    t += sprintf(t, "%s!%s@%s ",
72 >                 accept_p->nickptr,
73 >                 accept_p->userptr, accept_p->hostptr);
74    }
75  
76 <  /* get the number of accepts they have */
116 <  accept_num = dlink_list_length(&source_p->allow_list);
117 <
118 <  /* parse the add list */
119 <  for (nick = strtoken(&p, addbuf, ","); nick;
120 <       nick = strtoken(&p, NULL, ","), accept_num++)
76 >  if (nicks[0] != '\0')
77    {
78 <    /* shouldnt happen, but lets be paranoid */
79 <    if (((target_p = find_client(nick)) == NULL) || !IsClient(target_p))
80 <    {
125 <      sendto_one(source_p, form_str(ERR_NOSUCHNICK),
126 <                 me.name, source_p->name, nick);
127 <      continue;
128 <    }
129 <
130 <    /* user is already on clients accept list */
131 <    if (accept_message(target_p, source_p))
132 <    {
133 <      sendto_one(source_p, form_str(ERR_ACCEPTEXIST),
134 <                 me.name, source_p->name, target_p->name);
135 <      continue;
136 <    }
137 <
138 <    if (accept_num >= ConfigFileEntry.max_accept)
139 <    {
140 <      sendto_one(source_p, form_str(ERR_ACCEPTFULL),
141 <                 me.name, source_p->name);
142 <      return;
143 <    }
144 <      
145 <    /* why is this here? */
146 <    /* del_from accept(target_p, source_p); */
147 <    add_accept(source_p, target_p);
78 >    *(t - 1) = '\0';
79 >    sendto_one(source_p, form_str(RPL_ACCEPTLIST),
80 >               me.name, source_p->name, nicks);
81    }
82 +
83 +  sendto_one(source_p, form_str(RPL_ENDOFACCEPT),
84 +             me.name, source_p->name);
85   }
86  
87 < /* build_nicklist()
87 > /*! \brief Allocates and adds a split_nuh_item holding a nick!user\@host
88 > *         mask to a Client's acceptlist.
89   *
90 < * input        - pointer to client
91 < *              - pointer to addbuffer
155 < *              - pointer to remove buffer
156 < *              - pointer to list of nicks
157 < * output       -
158 < * side effects - addbuf/delbuf are modified to give valid nicks
90 > * \param nuh      A split_nuh_item already prepared with required masks.
91 > * \param source_p The actual Client the new accept is added to.
92   */
93   static void
94 < build_nicklist(struct Client *source_p, char *addbuf,
162 <               char *delbuf, char *nicks)
94 > add_accept(const struct split_nuh_item *nuh, struct Client *source_p)
95   {
96 <  char *name = NULL;
165 <  char *p = NULL;
166 <  char *buf_p = NULL;
167 <  struct Client *target_p = NULL;
96 >  struct split_nuh_item *accept_p = MyMalloc(sizeof(*accept_p));
97  
98 <  /* build list of clients to add into addbuf, clients to remove in delbuf */
99 <  for (name = strtoken(&p, nicks, ","); name;
100 <       name = strtoken(&p, NULL, ","))
172 <  {
173 <    if (*name == '-')
174 <      buf_p = delbuf, ++name;
175 <    else
176 <      buf_p = addbuf;
98 >  accept_p->nickptr = xstrdup(nuh->nickptr);
99 >  accept_p->userptr = xstrdup(nuh->userptr);
100 >  accept_p->hostptr = xstrdup(nuh->hostptr);
101  
102 <    if (((target_p = find_client(name)) == NULL) || !IsClient(target_p))
179 <    {
180 <      sendto_one(source_p, form_str(ERR_NOSUCHNICK),
181 <                 me.name, source_p->name, name);
182 <      continue;
183 <    }
102 >  dlinkAdd(accept_p, &accept_p->node, &source_p->localClient->acceptlist);
103  
185    if (*buf_p)
186      strlcat(buf_p, ",", IRCD_BUFSIZE);
187    strlcat(buf_p, name, IRCD_BUFSIZE);
188  }
189 }
190
191 /* add_accept()
192 *
193 * input        - pointer to clients accept list to add to
194 *              - pointer to client to add
195 * output       - none
196 * side effects - target is added to clients list
197 */
198 static void
199 add_accept(struct Client *source_p, struct Client *target_p)
200 {
201  dlinkAdd(target_p, make_dlink_node(), &source_p->allow_list);
202  dlinkAdd(source_p, make_dlink_node(), &target_p->on_allow_list);
104    list_accepts(source_p);
105   }
106  
107 < /* list_accepts()
107 > /*! \brief ACCEPT command handler
108   *
109 < * input        - pointer to client
110 < * output       - none
111 < * side effects - print accept list to client
109 > * \param client_p Pointer to allocated Client struct with physical connection
110 > *                 to this server, i.e. with an open socket connected.
111 > * \param source_p Pointer to allocated Client struct from which the message
112 > *                 originally comes from.  This can be a local or remote client.
113 > * \param parc     Integer holding the number of supplied arguments.
114 > * \param parv     Argument vector where parv[0] .. parv[parc-1] are non-NULL
115 > *                 pointers.
116 > * \note Valid arguments for this command are:
117 > *      - parv[0] = sender prefix
118 > *      - parv[1] = list of masks to be accepted or removed (optional)
119   */
120   static void
121 < list_accepts(struct Client *source_p)
121 > m_accept(struct Client *client_p, struct Client *source_p,
122 >         int parc, char *parv[])
123   {
124 <  int len = 0;
125 <  char nicks[IRCD_BUFSIZE] = { '\0' };
126 <  char *t = nicks;
127 <  const dlink_node *ptr = NULL;
128 <
129 <  len = strlen(me.name) + strlen(source_p->name) + 12;
124 >  char *mask = NULL;
125 >  char *p = NULL;
126 >  char nick[NICKLEN + 1];
127 >  char user[USERLEN + 1];
128 >  char host[HOSTLEN + 1];
129 >  struct split_nuh_item nuh;
130 >  struct split_nuh_item *accept_p = NULL;
131  
132 <  DLINK_FOREACH(ptr, source_p->allow_list.head)
132 >  if (EmptyString(parv[1]) || !irccmp(parv[1], "*"))
133    {
134 <    const struct Client *target_p = ptr->data;
134 >    list_accepts(source_p);
135 >    return;
136 >  }
137  
138 <    if ((t - nicks) + strlen(target_p->name) + len > IRCD_BUFSIZE)
138 >  for (mask = strtoken(&p, parv[1], ","); mask != NULL;
139 >       mask = strtoken(&p,    NULL, ","))
140 >  {
141 >    if (*mask == '-' && *++mask != '\0')
142      {
143 <      *(t - 1) = '\0';
144 <      sendto_one(source_p, form_str(RPL_ACCEPTLIST),
145 <                 me.name, source_p->name, nicks);
146 <      t = nicks;
143 >      nuh.nuhmask  = mask;
144 >      nuh.nickptr  = nick;
145 >      nuh.userptr  = user;
146 >      nuh.hostptr  = host;
147 >
148 >      nuh.nicksize = sizeof(nick);
149 >      nuh.usersize = sizeof(user);
150 >      nuh.hostsize = sizeof(host);
151 >
152 >      split_nuh(&nuh);
153 >
154 >      if ((accept_p = find_accept(nick, user, host, source_p, irccmp)) == NULL)
155 >      {
156 >        sendto_one(source_p, form_str(ERR_ACCEPTNOT),
157 >                   me.name, source_p->name, nick, user, host);
158 >        continue;
159 >      }
160 >
161 >      del_accept(accept_p, source_p);
162      }
163 +    else if (*mask != '\0')
164 +    {
165 +      if (dlink_list_length(&source_p->localClient->acceptlist) >=
166 +          ConfigFileEntry.max_accept)
167 +      {
168 +        sendto_one(source_p, form_str(ERR_ACCEPTFULL),
169 +                   me.name, source_p->name);
170 +        return;
171 +      }
172  
173 <    t += ircsprintf(t, "%s ", target_p->name);
174 <  }
173 >      nuh.nuhmask  = mask;
174 >      nuh.nickptr  = nick;
175 >      nuh.userptr  = user;
176 >      nuh.hostptr  = host;
177  
178 <  if (nicks[0] != '\0')
179 <  {
180 <    *(t - 1) = '\0';
181 <    sendto_one(source_p, form_str(RPL_ACCEPTLIST),
182 <               me.name, source_p->name, nicks);
178 >      nuh.nicksize = sizeof(nick);
179 >      nuh.usersize = sizeof(user);
180 >      nuh.hostsize = sizeof(host);
181 >
182 >      split_nuh(&nuh);
183 >
184 >      if ((accept_p = find_accept(nick, user, host, source_p, irccmp)) != NULL)
185 >      {
186 >        sendto_one(source_p, form_str(ERR_ACCEPTEXIST),
187 >                   me.name, source_p->name, nick, user, host);
188 >        continue;
189 >      }
190 >
191 >      add_accept(&nuh, source_p);
192 >    }
193    }
194 + }
195  
196 <  sendto_one(source_p, form_str(RPL_ENDOFACCEPT),
197 <             me.name, source_p->name);
196 > static struct Message accept_msgtab = {
197 >  "ACCEPT", 0, 0, 0, MAXPARA, MFLG_SLOW, 0,
198 >  { m_unregistered, m_accept, m_ignore, m_ignore, m_accept, m_ignore }
199 > };
200 >
201 > static void
202 > module_init(void)
203 > {
204 >  mod_add_cmd(&accept_msgtab);
205   }
206 +
207 + static void
208 + module_exit(void)
209 + {
210 +  mod_del_cmd(&accept_msgtab);
211 + }
212 +
213 + struct module module_entry = {
214 +  .node    = { NULL, NULL, NULL },
215 +  .name    = NULL,
216 +  .version = "$Revision$",
217 +  .handle  = NULL,
218 +  .modinit = module_init,
219 +  .modexit = module_exit,
220 +  .flags   = 0
221 + };

Diff Legend

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