ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/branches/8.2.x/modules/m_accept.c
Revision: 3874
Committed: Fri Jun 6 14:42:13 2014 UTC (12 years, 2 months ago) by michael
Content type: text/x-csrc
File size: 5709 byte(s)
Log Message:
- Style corrections; fixed comments

File Contents

# User Rev Content
1 adx 30 /*
2 michael 2820 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 adx 30 *
4 michael 2820 * Copyright (c) 2000-2014 ircd-hybrid development team
5 adx 30 *
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
8     * the Free Software Foundation; either version 2 of the License, or
9     * (at your option) any later version.
10     *
11     * This program is distributed in the hope that it will be useful,
12     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU General Public License for more details.
15     *
16     * You should have received a copy of the GNU General Public License
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    
22 michael 1007 /*! \file m_accept.c
23     * \brief Includes required functions for processing the ACCEPT command.
24     * \version $Id$
25     */
26    
27 adx 30 #include "stdinc.h"
28     #include "client.h"
29     #include "irc_string.h"
30     #include "ircd.h"
31     #include "list.h"
32     #include "numeric.h"
33 michael 1309 #include "conf.h"
34 adx 30 #include "send.h"
35     #include "parse.h"
36     #include "modules.h"
37 michael 1666 #include "memory.h"
38 adx 30
39    
40 michael 1007 /*! \brief Creates and sends a list of nick!user\@host masks a Client
41     * has on its acceptlist.
42 michael 887 *
43 michael 1007 * \param source_p The actual Client the list will be sent to.
44 adx 30 */
45     static void
46 michael 1007 list_accepts(struct Client *source_p)
47     {
48     int len = 0;
49 michael 3246 char nicks[IRCD_BUFSIZE] = "";
50 michael 1007 char *t = nicks;
51     const dlink_node *ptr = NULL;
52    
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 michael 3874 strlen(accept_p->hostptr) + 2; /* +2 for !@ */
61 michael 1007
62     if ((t - nicks) + masklen + len > IRCD_BUFSIZE)
63     {
64     *(t - 1) = '\0';
65 michael 3109 sendto_one_numeric(source_p, &me, RPL_ACCEPTLIST, nicks);
66 michael 1007 t = nicks;
67     }
68    
69 michael 1793 t += sprintf(t, "%s!%s@%s ",
70     accept_p->nickptr,
71     accept_p->userptr, accept_p->hostptr);
72 michael 1007 }
73    
74 michael 3246 if (nicks[0])
75 michael 1007 {
76     *(t - 1) = '\0';
77 michael 3109 sendto_one_numeric(source_p, &me, RPL_ACCEPTLIST, nicks);
78 michael 1007 }
79    
80 michael 3109 sendto_one_numeric(source_p, &me, RPL_ENDOFACCEPT);
81 michael 1007 }
82    
83     /*! \brief Allocates and adds a split_nuh_item holding a nick!user\@host
84     * mask to a Client's acceptlist.
85     *
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 michael 887 add_accept(const struct split_nuh_item *nuh, struct Client *source_p)
91     {
92 michael 3505 struct split_nuh_item *accept_p = MyCalloc(sizeof(*accept_p));
93 michael 887
94 michael 1646 accept_p->nickptr = xstrdup(nuh->nickptr);
95     accept_p->userptr = xstrdup(nuh->userptr);
96     accept_p->hostptr = xstrdup(nuh->hostptr);
97 michael 887
98     dlinkAdd(accept_p, &accept_p->node, &source_p->localClient->acceptlist);
99    
100     list_accepts(source_p);
101     }
102    
103     /*! \brief ACCEPT command handler
104     *
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 michael 3096 * - parv[0] = command
112 michael 3300 * - parv[1] = comma-separated list of masks to be accepted or removed
113 michael 887 */
114 michael 2820 static int
115 michael 3156 m_accept(struct Client *source_p, int parc, char *parv[])
116 adx 30 {
117 michael 887 char *mask = NULL;
118 adx 30 char *p = NULL;
119 michael 3246 char nick[NICKLEN + 1] = "";
120     char user[USERLEN + 1] = "";
121     char host[HOSTLEN + 1] = "";
122 michael 887 struct split_nuh_item nuh;
123     struct split_nuh_item *accept_p = NULL;
124    
125 michael 3370 if (EmptyString(parv[1]) || !strcmp(parv[1], "*"))
126 adx 30 {
127     list_accepts(source_p);
128 michael 2820 return 0;
129 adx 30 }
130    
131 michael 3246 for (mask = strtoken(&p, parv[1], ","); mask;
132 michael 887 mask = strtoken(&p, NULL, ","))
133 adx 30 {
134 michael 3604 if (*mask == '-' && *++mask)
135 adx 30 {
136 michael 887 nuh.nuhmask = mask;
137     nuh.nickptr = nick;
138     nuh.userptr = user;
139     nuh.hostptr = host;
140 adx 30
141 michael 887 nuh.nicksize = sizeof(nick);
142     nuh.usersize = sizeof(user);
143     nuh.hostsize = sizeof(host);
144 adx 30
145 michael 887 split_nuh(&nuh);
146 adx 30
147 michael 2363 if ((accept_p = find_accept(nick, user, host, source_p, irccmp)) == NULL)
148 michael 887 {
149 michael 3109 sendto_one_numeric(source_p, &me, ERR_ACCEPTNOT, nick, user, host);
150 michael 887 continue;
151     }
152 adx 30
153 michael 887 del_accept(accept_p, source_p);
154 adx 30 }
155 michael 3604 else if (*mask)
156 adx 30 {
157 michael 887 if (dlink_list_length(&source_p->localClient->acceptlist) >=
158     ConfigFileEntry.max_accept)
159     {
160 michael 3109 sendto_one_numeric(source_p, &me, ERR_ACCEPTFULL);
161 michael 2820 return 0;
162 michael 887 }
163 adx 30
164 michael 887 nuh.nuhmask = mask;
165     nuh.nickptr = nick;
166     nuh.userptr = user;
167     nuh.hostptr = host;
168 adx 30
169 michael 887 nuh.nicksize = sizeof(nick);
170     nuh.usersize = sizeof(user);
171     nuh.hostsize = sizeof(host);
172 adx 30
173 michael 887 split_nuh(&nuh);
174 adx 30
175 michael 3246 if ((accept_p = find_accept(nick, user, host, source_p, irccmp)))
176 michael 887 {
177 michael 3109 sendto_one_numeric(source_p, &me, ERR_ACCEPTEXIST, nick, user, host);
178 michael 887 continue;
179     }
180    
181     add_accept(&nuh, source_p);
182 adx 30 }
183     }
184 michael 2820
185     return 0;
186 adx 30 }
187 michael 1230
188 michael 2820 static struct Message accept_msgtab =
189     {
190 michael 1230 "ACCEPT", 0, 0, 0, MAXPARA, MFLG_SLOW, 0,
191     { m_unregistered, m_accept, m_ignore, m_ignore, m_accept, m_ignore }
192     };
193    
194     static void
195     module_init(void)
196     {
197     mod_add_cmd(&accept_msgtab);
198     }
199    
200     static void
201     module_exit(void)
202     {
203     mod_del_cmd(&accept_msgtab);
204     }
205    
206 michael 2820 struct module module_entry =
207     {
208 michael 1230 .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     };

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision