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.2/modules/m_accept.c (file contents), Revision 887 by michael, Thu Nov 1 11:54:48 2007 UTC vs.
ircd-hybrid/branches/8.2.x/modules/m_accept.c (file contents), Revision 3377 by michael, Thu Apr 24 16:15:51 2014 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.
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 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"
35 < #include "s_serv.h"
33 > #include "conf.h"
34   #include "send.h"
37 #include "msg.h"
35   #include "parse.h"
39 #include "s_user.h"
36   #include "modules.h"
37 + #include "memory.h"
38  
42 static void m_accept(struct Client *, struct Client *, int, char *[]);
43 static void list_accepts(struct Client *);
44
45 struct Message accept_msgtab = {
46  "ACCEPT", 0, 0, 0, 0, MFLG_SLOW, 0,
47  { m_unregistered, m_accept, m_ignore, m_ignore, m_accept, m_ignore }
48 };
39  
40 < #ifndef STATIC_MODULES
41 < void
42 < _modinit(void)
40 > /*! \brief Creates and sends a list of nick!user\@host masks a Client
41 > *         has on its acceptlist.
42 > *
43 > * \param source_p The actual Client the list will be sent to.
44 > */
45 > static void
46 > list_accepts(struct Client *source_p)
47   {
48 <  mod_add_cmd(&accept_msgtab);
49 < }
48 >  int len = 0;
49 >  char nicks[IRCD_BUFSIZE] = "";
50 >  char *t = nicks;
51 >  const dlink_node *ptr = NULL;
52  
53 < void
54 < _moddeinit(void)
55 < {
56 <  mod_del_cmd(&accept_msgtab);
57 < }
53 >  len = strlen(me.name) + strlen(source_p->name) + 12;
54 >
55 >  DLINK_FOREACH(ptr, source_p->localClient->acceptlist.head)
56 >  {
57 >    const struct split_nuh_item *accept_p = ptr->data;
58 >    size_t masklen = strlen(accept_p->nickptr) +
59 >                     strlen(accept_p->userptr) +
60 >                     strlen(accept_p->hostptr) + 2 /* !@ */ ;
61 >
62 >    if ((t - nicks) + masklen + len  > IRCD_BUFSIZE)
63 >    {
64 >      *(t - 1) = '\0';
65 >      sendto_one_numeric(source_p, &me, RPL_ACCEPTLIST, nicks);
66 >      t = nicks;
67 >    }
68  
69 < const char *_version = "$Revision$";
70 < #endif
69 >    t += sprintf(t, "%s!%s@%s ",
70 >                 accept_p->nickptr,
71 >                 accept_p->userptr, accept_p->hostptr);
72 >  }
73 >
74 >  if (nicks[0])
75 >  {
76 >    *(t - 1) = '\0';
77 >    sendto_one_numeric(source_p, &me, RPL_ACCEPTLIST, nicks);
78 >  }
79  
80 +  sendto_one_numeric(source_p, &me, RPL_ENDOFACCEPT);
81 + }
82  
83 < /* add_accept()
83 > /*! \brief Allocates and adds a split_nuh_item holding a nick!user\@host
84 > *         mask to a Client's acceptlist.
85   *
86 < * input        - pointer to preallocated nick
87 < *              - pointer to preallocated username
71 < *              - pointer to preallocated host
72 < *              - pointer to client to add to acceptlist
73 < * output       - none
74 < * side effects - target is added to clients list
86 > * \param nuh      A split_nuh_item already prepared with required masks.
87 > * \param source_p The actual Client the new accept is added to.
88   */
89   static void
90   add_accept(const struct split_nuh_item *nuh, struct Client *source_p)
91   {
92    struct split_nuh_item *accept_p = MyMalloc(sizeof(*accept_p));
93  
94 <  DupString(accept_p->nickptr, nuh->nickptr);
95 <  DupString(accept_p->userptr, nuh->userptr);
96 <  DupString(accept_p->hostptr, nuh->hostptr);
94 >  accept_p->nickptr = xstrdup(nuh->nickptr);
95 >  accept_p->userptr = xstrdup(nuh->userptr);
96 >  accept_p->hostptr = xstrdup(nuh->hostptr);
97  
98    dlinkAdd(accept_p, &accept_p->node, &source_p->localClient->acceptlist);
99  
# Line 89 | Line 102 | add_accept(const struct split_nuh_item *
102  
103   /*! \brief ACCEPT command handler
104   *
92 * \param client_p Pointer to allocated Client struct with physical connection
93 *                 to this server, i.e. with an open socket connected.
105   * \param source_p Pointer to allocated Client struct from which the message
106   *                 originally comes from.  This can be a local or remote client.
107   * \param parc     Integer holding the number of supplied arguments.
108   * \param parv     Argument vector where parv[0] .. parv[parc-1] are non-NULL
109   *                 pointers.
110   * \note Valid arguments for this command are:
111 < *      - parv[0] = sender prefix
112 < *      - parv[1] = list of masks to be accepted or removed (optional)
111 > *      - parv[0] = command
112 > *      - parv[1] = comma-separated list of masks to be accepted or removed
113   */
114 < static void
115 < m_accept(struct Client *client_p, struct Client *source_p,
105 <         int parc, char *parv[])
114 > static int
115 > m_accept(struct Client *source_p, int parc, char *parv[])
116   {
117    char *mask = NULL;
118    char *p = NULL;
119 <  char nick[NICKLEN + 1];
120 <  char user[USERLEN + 1];
121 <  char host[HOSTLEN + 1];
119 >  char nick[NICKLEN + 1] = "";
120 >  char user[USERLEN + 1] = "";
121 >  char host[HOSTLEN + 1] = "";
122    struct split_nuh_item nuh;
123    struct split_nuh_item *accept_p = NULL;
124  
125 <  if (EmptyString(parv[1]) || !irccmp(parv[1], "*"))
125 >  if (EmptyString(parv[1]) || !strcmp(parv[1], "*"))
126    {
127      list_accepts(source_p);
128 <    return;
128 >    return 0;
129    }
130  
131 <  for (mask = strtoken(&p, parv[1], ","); mask != NULL;
131 >  for (mask = strtoken(&p, parv[1], ","); mask;
132         mask = strtoken(&p,    NULL, ","))
133    {
134      if (*mask == '-' && *++mask != '\0')
# Line 134 | Line 144 | m_accept(struct Client *client_p, struct
144  
145        split_nuh(&nuh);
146  
147 <      if ((accept_p = find_accept(nick, user, host, source_p, 0)) == NULL)
147 >      if ((accept_p = find_accept(nick, user, host, source_p, irccmp)) == NULL)
148        {
149 <        sendto_one(source_p, form_str(ERR_ACCEPTNOT),
140 <                   me.name, source_p->name, nick, user, host);
149 >        sendto_one_numeric(source_p, &me, ERR_ACCEPTNOT, nick, user, host);
150          continue;
151        }
152  
# Line 148 | Line 157 | m_accept(struct Client *client_p, struct
157        if (dlink_list_length(&source_p->localClient->acceptlist) >=
158            ConfigFileEntry.max_accept)
159        {
160 <        sendto_one(source_p, form_str(ERR_ACCEPTFULL),
161 <                   me.name, source_p->name);
153 <        return;
160 >        sendto_one_numeric(source_p, &me, ERR_ACCEPTFULL);
161 >        return 0;
162        }
163  
164        nuh.nuhmask  = mask;
# Line 164 | Line 172 | m_accept(struct Client *client_p, struct
172  
173        split_nuh(&nuh);
174  
175 <      if ((accept_p = find_accept(nick, user, host, source_p, 0)) != NULL)
175 >      if ((accept_p = find_accept(nick, user, host, source_p, irccmp)))
176        {
177 <        sendto_one(source_p, form_str(ERR_ACCEPTEXIST),
170 <                   me.name, source_p->name, nick, user, host);
177 >        sendto_one_numeric(source_p, &me, ERR_ACCEPTEXIST, nick, user, host);
178          continue;
179        }
180  
181        add_accept(&nuh, source_p);
182      }
183    }
184 +
185 +  return 0;
186   }
187  
188 < /* list_accepts()
180 < *
181 < * input        - pointer to client
182 < * output       - none
183 < * side effects - print accept list to client
184 < */
185 < static void
186 < list_accepts(struct Client *source_p)
188 > static struct Message accept_msgtab =
189   {
190 <  int len = 0;
191 <  char nicks[IRCD_BUFSIZE] = { '\0' };
192 <  char *t = nicks;
191 <  const dlink_node *ptr = NULL;
192 <
193 <  len = strlen(me.name) + strlen(source_p->name) + 12;
194 <
195 <  DLINK_FOREACH(ptr, source_p->localClient->acceptlist.head)
196 <  {
197 <    const struct split_nuh_item *accept_p = ptr->data;
198 <    size_t masklen = strlen(accept_p->nickptr) +
199 <                     strlen(accept_p->userptr) +
200 <                     strlen(accept_p->hostptr) + 2 /* !@ */ ;
201 <
202 <    if ((t - nicks) + masklen + len  > IRCD_BUFSIZE)
203 <    {
204 <      *(t - 1) = '\0';
205 <      sendto_one(source_p, form_str(RPL_ACCEPTLIST),
206 <                 me.name, source_p->name, nicks);
207 <      t = nicks;
208 <    }
209 <
210 <    t += ircsprintf(t, "%s!%s@%s ",
211 <                    accept_p->nickptr,
212 <                    accept_p->userptr, accept_p->hostptr);
213 <  }
190 >  "ACCEPT", 0, 0, 0, MAXPARA, MFLG_SLOW, 0,
191 >  { m_unregistered, m_accept, m_ignore, m_ignore, m_accept, m_ignore }
192 > };
193  
194 <  if (nicks[0] != '\0')
195 <  {
196 <    *(t - 1) = '\0';
197 <    sendto_one(source_p, form_str(RPL_ACCEPTLIST),
198 <               me.name, source_p->name, nicks);
220 <  }
194 > static void
195 > module_init(void)
196 > {
197 >  mod_add_cmd(&accept_msgtab);
198 > }
199  
200 <  sendto_one(source_p, form_str(RPL_ENDOFACCEPT),
201 <             me.name, source_p->name);
200 > static void
201 > module_exit(void)
202 > {
203 >  mod_del_cmd(&accept_msgtab);
204   }
205 +
206 + struct module module_entry =
207 + {
208 +  .node    = { NULL, NULL, NULL },
209 +  .name    = NULL,
210 +  .version = "$Revision$",
211 +  .handle  = NULL,
212 +  .modinit = module_init,
213 +  .modexit = module_exit,
214 +  .flags   = 0
215 + };

Diff Legend

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