ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_accept.c
Revision: 3109
Committed: Thu Mar 6 19:25:12 2014 UTC (11 years, 5 months ago) by michael
Content type: text/x-csrc
File size: 5932 byte(s)
Log Message:
- Applied Adam's sendto_one_numeric() changes

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 *
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
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 /*! \file m_accept.c
23 * \brief Includes required functions for processing the ACCEPT command.
24 * \version $Id$
25 */
26
27 #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 #include "conf.h"
34 #include "s_serv.h"
35 #include "send.h"
36 #include "parse.h"
37 #include "modules.h"
38 #include "memory.h"
39
40
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 list_accepts(struct Client *source_p)
48 {
49 int len = 0;
50 char nicks[IRCD_BUFSIZE] = { '\0' };
51 char *t = nicks;
52 const dlink_node *ptr = NULL;
53
54 len = strlen(me.name) + strlen(source_p->name) + 12;
55
56 DLINK_FOREACH(ptr, source_p->localClient->acceptlist.head)
57 {
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 if ((t - nicks) + masklen + len > IRCD_BUFSIZE)
64 {
65 *(t - 1) = '\0';
66 sendto_one_numeric(source_p, &me, RPL_ACCEPTLIST, nicks);
67 t = nicks;
68 }
69
70 t += sprintf(t, "%s!%s@%s ",
71 accept_p->nickptr,
72 accept_p->userptr, accept_p->hostptr);
73 }
74
75 if (nicks[0] != '\0')
76 {
77 *(t - 1) = '\0';
78 sendto_one_numeric(source_p, &me, RPL_ACCEPTLIST, nicks);
79 }
80
81 sendto_one_numeric(source_p, &me, RPL_ENDOFACCEPT);
82 }
83
84 /*! \brief Allocates and adds a split_nuh_item holding a nick!user\@host
85 * mask to a Client's acceptlist.
86 *
87 * \param nuh A split_nuh_item already prepared with required masks.
88 * \param source_p The actual Client the new accept is added to.
89 */
90 static void
91 add_accept(const struct split_nuh_item *nuh, struct Client *source_p)
92 {
93 struct split_nuh_item *accept_p = MyMalloc(sizeof(*accept_p));
94
95 accept_p->nickptr = xstrdup(nuh->nickptr);
96 accept_p->userptr = xstrdup(nuh->userptr);
97 accept_p->hostptr = xstrdup(nuh->hostptr);
98
99 dlinkAdd(accept_p, &accept_p->node, &source_p->localClient->acceptlist);
100
101 list_accepts(source_p);
102 }
103
104 /*! \brief ACCEPT command handler
105 *
106 * \param client_p Pointer to allocated Client struct with physical connection
107 * to this server, i.e. with an open socket connected.
108 * \param source_p Pointer to allocated Client struct from which the message
109 * originally comes from. This can be a local or remote client.
110 * \param parc Integer holding the number of supplied arguments.
111 * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
112 * pointers.
113 * \note Valid arguments for this command are:
114 * - parv[0] = command
115 * - parv[1] = list of masks to be accepted or removed (optional)
116 */
117 static int
118 m_accept(struct Client *client_p, struct Client *source_p,
119 int parc, char *parv[])
120 {
121 char *mask = NULL;
122 char *p = NULL;
123 char nick[NICKLEN + 1];
124 char user[USERLEN + 1];
125 char host[HOSTLEN + 1];
126 struct split_nuh_item nuh;
127 struct split_nuh_item *accept_p = NULL;
128
129 if (EmptyString(parv[1]) || !irccmp(parv[1], "*"))
130 {
131 list_accepts(source_p);
132 return 0;
133 }
134
135 for (mask = strtoken(&p, parv[1], ","); mask != NULL;
136 mask = strtoken(&p, NULL, ","))
137 {
138 if (*mask == '-' && *++mask != '\0')
139 {
140 nuh.nuhmask = mask;
141 nuh.nickptr = nick;
142 nuh.userptr = user;
143 nuh.hostptr = host;
144
145 nuh.nicksize = sizeof(nick);
146 nuh.usersize = sizeof(user);
147 nuh.hostsize = sizeof(host);
148
149 split_nuh(&nuh);
150
151 if ((accept_p = find_accept(nick, user, host, source_p, irccmp)) == NULL)
152 {
153 sendto_one_numeric(source_p, &me, ERR_ACCEPTNOT, nick, user, host);
154 continue;
155 }
156
157 del_accept(accept_p, source_p);
158 }
159 else if (*mask != '\0')
160 {
161 if (dlink_list_length(&source_p->localClient->acceptlist) >=
162 ConfigFileEntry.max_accept)
163 {
164 sendto_one_numeric(source_p, &me, ERR_ACCEPTFULL);
165 return 0;
166 }
167
168 nuh.nuhmask = mask;
169 nuh.nickptr = nick;
170 nuh.userptr = user;
171 nuh.hostptr = host;
172
173 nuh.nicksize = sizeof(nick);
174 nuh.usersize = sizeof(user);
175 nuh.hostsize = sizeof(host);
176
177 split_nuh(&nuh);
178
179 if ((accept_p = find_accept(nick, user, host, source_p, irccmp)) != NULL)
180 {
181 sendto_one_numeric(source_p, &me, ERR_ACCEPTEXIST, nick, user, host);
182 continue;
183 }
184
185 add_accept(&nuh, source_p);
186 }
187 }
188
189 return 0;
190 }
191
192 static struct Message accept_msgtab =
193 {
194 "ACCEPT", 0, 0, 0, MAXPARA, MFLG_SLOW, 0,
195 { m_unregistered, m_accept, m_ignore, m_ignore, m_accept, m_ignore }
196 };
197
198 static void
199 module_init(void)
200 {
201 mod_add_cmd(&accept_msgtab);
202 }
203
204 static void
205 module_exit(void)
206 {
207 mod_del_cmd(&accept_msgtab);
208 }
209
210 struct module module_entry =
211 {
212 .node = { NULL, NULL, NULL },
213 .name = NULL,
214 .version = "$Revision$",
215 .handle = NULL,
216 .modinit = module_init,
217 .modexit = module_exit,
218 .flags = 0
219 };

Properties

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