ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_accept.c
Revision: 3300
Committed: Sat Apr 12 18:26:22 2014 UTC (11 years, 4 months ago) by michael
Content type: text/x-csrc
File size: 5718 byte(s)
Log Message:
- doxygen

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 "send.h"
35 #include "parse.h"
36 #include "modules.h"
37 #include "memory.h"
38
39
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 int len = 0;
49 char nicks[IRCD_BUFSIZE] = "";
50 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 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 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 /*! \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 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 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
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 * - parv[0] = command
112 * - parv[1] = comma-separated list of masks to be accepted or removed
113 */
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] = "";
122 struct split_nuh_item nuh;
123 struct split_nuh_item *accept_p = NULL;
124
125 if (EmptyString(parv[1]) || !irccmp(parv[1], "*"))
126 {
127 list_accepts(source_p);
128 return 0;
129 }
130
131 for (mask = strtoken(&p, parv[1], ","); mask;
132 mask = strtoken(&p, NULL, ","))
133 {
134 if (*mask == '-' && *++mask != '\0')
135 {
136 nuh.nuhmask = mask;
137 nuh.nickptr = nick;
138 nuh.userptr = user;
139 nuh.hostptr = host;
140
141 nuh.nicksize = sizeof(nick);
142 nuh.usersize = sizeof(user);
143 nuh.hostsize = sizeof(host);
144
145 split_nuh(&nuh);
146
147 if ((accept_p = find_accept(nick, user, host, source_p, irccmp)) == NULL)
148 {
149 sendto_one_numeric(source_p, &me, ERR_ACCEPTNOT, nick, user, host);
150 continue;
151 }
152
153 del_accept(accept_p, source_p);
154 }
155 else if (*mask != '\0')
156 {
157 if (dlink_list_length(&source_p->localClient->acceptlist) >=
158 ConfigFileEntry.max_accept)
159 {
160 sendto_one_numeric(source_p, &me, ERR_ACCEPTFULL);
161 return 0;
162 }
163
164 nuh.nuhmask = mask;
165 nuh.nickptr = nick;
166 nuh.userptr = user;
167 nuh.hostptr = host;
168
169 nuh.nicksize = sizeof(nick);
170 nuh.usersize = sizeof(user);
171 nuh.hostsize = sizeof(host);
172
173 split_nuh(&nuh);
174
175 if ((accept_p = find_accept(nick, user, host, source_p, irccmp)))
176 {
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 static struct Message accept_msgtab =
189 {
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 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 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 };

Properties

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