/[svn]/ircd-hybrid-7.2/modules/m_accept.c
ViewVC logotype

Contents of /ircd-hybrid-7.2/modules/m_accept.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1007 - (show annotations)
Tue Sep 1 15:25:26 2009 UTC (10 years, 4 months ago) by michael
File MIME type: text/x-chdr
File size: 6114 byte(s)
- continue doxyfying sources

1 /*
2 * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 *
4 * Copyright (C) 2002 by the past and present ircd coders, and others.
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 "handlers.h"
29 #include "client.h"
30 #include "irc_string.h"
31 #include "sprintf_irc.h"
32 #include "ircd.h"
33 #include "list.h"
34 #include "numeric.h"
35 #include "s_conf.h"
36 #include "s_serv.h"
37 #include "send.h"
38 #include "msg.h"
39 #include "parse.h"
40 #include "modules.h"
41
42 static void m_accept(struct Client *, struct Client *, int, char *[]);
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 }
47 };
48
49 #ifndef STATIC_MODULES
50 void
51 _modinit(void)
52 {
53 mod_add_cmd(&accept_msgtab);
54 }
55
56 void
57 _moddeinit(void)
58 {
59 mod_del_cmd(&accept_msgtab);
60 }
61
62 const char *_version = "$Revision$";
63 #endif
64
65
66 /*! \brief Creates and sends a list of nick!user\@host masks a Client
67 * has on its acceptlist.
68 *
69 * \param source_p The actual Client the list will be sent to.
70 */
71 static void
72 list_accepts(struct Client *source_p)
73 {
74 int len = 0;
75 char nicks[IRCD_BUFSIZE] = { '\0' };
76 char *t = nicks;
77 const dlink_node *ptr = NULL;
78
79 len = strlen(me.name) + strlen(source_p->name) + 12;
80
81 DLINK_FOREACH(ptr, source_p->localClient->acceptlist.head)
82 {
83 const struct split_nuh_item *accept_p = ptr->data;
84 size_t masklen = strlen(accept_p->nickptr) +
85 strlen(accept_p->userptr) +
86 strlen(accept_p->hostptr) + 2 /* !@ */ ;
87
88 if ((t - nicks) + masklen + len > IRCD_BUFSIZE)
89 {
90 *(t - 1) = '\0';
91 sendto_one(source_p, form_str(RPL_ACCEPTLIST),
92 me.name, source_p->name, nicks);
93 t = nicks;
94 }
95
96 t += ircsprintf(t, "%s!%s@%s ",
97 accept_p->nickptr,
98 accept_p->userptr, accept_p->hostptr);
99 }
100
101 if (nicks[0] != '\0')
102 {
103 *(t - 1) = '\0';
104 sendto_one(source_p, form_str(RPL_ACCEPTLIST),
105 me.name, source_p->name, nicks);
106 }
107
108 sendto_one(source_p, form_str(RPL_ENDOFACCEPT),
109 me.name, source_p->name);
110 }
111
112 /*! \brief Allocates and adds a split_nuh_item holding a nick!user\@host
113 * mask to a Client's acceptlist.
114 *
115 * \param nuh A split_nuh_item already prepared with required masks.
116 * \param source_p The actual Client the new accept is added to.
117 */
118 static void
119 add_accept(const struct split_nuh_item *nuh, struct Client *source_p)
120 {
121 struct split_nuh_item *accept_p = MyMalloc(sizeof(*accept_p));
122
123 DupString(accept_p->nickptr, nuh->nickptr);
124 DupString(accept_p->userptr, nuh->userptr);
125 DupString(accept_p->hostptr, nuh->hostptr);
126
127 dlinkAdd(accept_p, &accept_p->node, &source_p->localClient->acceptlist);
128
129 list_accepts(source_p);
130 }
131
132 /*! \brief ACCEPT command handler
133 *
134 * \param client_p Pointer to allocated Client struct with physical connection
135 * to this server, i.e. with an open socket connected.
136 * \param source_p Pointer to allocated Client struct from which the message
137 * originally comes from. This can be a local or remote client.
138 * \param parc Integer holding the number of supplied arguments.
139 * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
140 * pointers.
141 * \note Valid arguments for this command are:
142 * - parv[0] = sender prefix
143 * - parv[1] = list of masks to be accepted or removed (optional)
144 */
145 static void
146 m_accept(struct Client *client_p, struct Client *source_p,
147 int parc, char *parv[])
148 {
149 char *mask = NULL;
150 char *p = NULL;
151 char nick[NICKLEN + 1];
152 char user[USERLEN + 1];
153 char host[HOSTLEN + 1];
154 struct split_nuh_item nuh;
155 struct split_nuh_item *accept_p = NULL;
156
157 if (EmptyString(parv[1]) || !irccmp(parv[1], "*"))
158 {
159 list_accepts(source_p);
160 return;
161 }
162
163 for (mask = strtoken(&p, parv[1], ","); mask != NULL;
164 mask = strtoken(&p, NULL, ","))
165 {
166 if (*mask == '-' && *++mask != '\0')
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, 0)) == NULL)
180 {
181 sendto_one(source_p, form_str(ERR_ACCEPTNOT),
182 me.name, source_p->name, nick, user, host);
183 continue;
184 }
185
186 del_accept(accept_p, source_p);
187 }
188 else if (*mask != '\0')
189 {
190 if (dlink_list_length(&source_p->localClient->acceptlist) >=
191 ConfigFileEntry.max_accept)
192 {
193 sendto_one(source_p, form_str(ERR_ACCEPTFULL),
194 me.name, source_p->name);
195 return;
196 }
197
198 nuh.nuhmask = mask;
199 nuh.nickptr = nick;
200 nuh.userptr = user;
201 nuh.hostptr = host;
202
203 nuh.nicksize = sizeof(nick);
204 nuh.usersize = sizeof(user);
205 nuh.hostsize = sizeof(host);
206
207 split_nuh(&nuh);
208
209 if ((accept_p = find_accept(nick, user, host, source_p, 0)) != NULL)
210 {
211 sendto_one(source_p, form_str(ERR_ACCEPTEXIST),
212 me.name, source_p->name, nick, user, host);
213 continue;
214 }
215
216 add_accept(&nuh, source_p);
217 }
218 }
219 }

Properties

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

svnadmin@ircd-hybrid.org
ViewVC Help
Powered by ViewVC 1.1.26