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

Comparing:
ircd-hybrid/modules/m_accept.c (property svn:keywords), Revision 30 by adx, Sun Oct 2 20:03:27 2005 UTC vs.
ircd-hybrid-8/modules/m_accept.c (property svn:keywords), Revision 1230 by michael, Thu Sep 22 19:41:19 2011 UTC

# Line 1 | Line 1
1 < "Id Revision"
1 > Id Revision

Diff Legend

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