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

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-7.3/modules/m_accept.c (property svn:keywords), Revision 1121 by michael, Sun Jan 9 11:03:03 2011 UTC

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

Diff Legend

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