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

# 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 "s_serv.h"
35     #include "send.h"
36     #include "parse.h"
37     #include "modules.h"
38 michael 1666 #include "memory.h"
39 adx 30
40    
41 michael 1007 /*! \brief Creates and sends a list of nick!user\@host masks a Client
42     * has on its acceptlist.
43 michael 887 *
44 michael 1007 * \param source_p The actual Client the list will be sent to.
45 adx 30 */
46     static void
47 michael 1007 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 michael 3109 sendto_one_numeric(source_p, &me, RPL_ACCEPTLIST, nicks);
67 michael 1007 t = nicks;
68     }
69    
70 michael 1793 t += sprintf(t, "%s!%s@%s ",
71     accept_p->nickptr,
72     accept_p->userptr, accept_p->hostptr);
73 michael 1007 }
74    
75     if (nicks[0] != '\0')
76     {
77     *(t - 1) = '\0';
78 michael 3109 sendto_one_numeric(source_p, &me, RPL_ACCEPTLIST, nicks);
79 michael 1007 }
80    
81 michael 3109 sendto_one_numeric(source_p, &me, RPL_ENDOFACCEPT);
82 michael 1007 }
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 michael 887 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 michael 1646 accept_p->nickptr = xstrdup(nuh->nickptr);
96     accept_p->userptr = xstrdup(nuh->userptr);
97     accept_p->hostptr = xstrdup(nuh->hostptr);
98 michael 887
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 michael 3096 * - parv[0] = command
115 michael 887 * - parv[1] = list of masks to be accepted or removed (optional)
116     */
117 michael 2820 static int
118 adx 30 m_accept(struct Client *client_p, struct Client *source_p,
119     int parc, char *parv[])
120     {
121 michael 887 char *mask = NULL;
122 adx 30 char *p = NULL;
123 michael 887 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 adx 30 {
131     list_accepts(source_p);
132 michael 2820 return 0;
133 adx 30 }
134    
135 michael 887 for (mask = strtoken(&p, parv[1], ","); mask != NULL;
136     mask = strtoken(&p, NULL, ","))
137 adx 30 {
138 michael 887 if (*mask == '-' && *++mask != '\0')
139 adx 30 {
140 michael 887 nuh.nuhmask = mask;
141     nuh.nickptr = nick;
142     nuh.userptr = user;
143     nuh.hostptr = host;
144 adx 30
145 michael 887 nuh.nicksize = sizeof(nick);
146     nuh.usersize = sizeof(user);
147     nuh.hostsize = sizeof(host);
148 adx 30
149 michael 887 split_nuh(&nuh);
150 adx 30
151 michael 2363 if ((accept_p = find_accept(nick, user, host, source_p, irccmp)) == NULL)
152 michael 887 {
153 michael 3109 sendto_one_numeric(source_p, &me, ERR_ACCEPTNOT, nick, user, host);
154 michael 887 continue;
155     }
156 adx 30
157 michael 887 del_accept(accept_p, source_p);
158 adx 30 }
159 michael 887 else if (*mask != '\0')
160 adx 30 {
161 michael 887 if (dlink_list_length(&source_p->localClient->acceptlist) >=
162     ConfigFileEntry.max_accept)
163     {
164 michael 3109 sendto_one_numeric(source_p, &me, ERR_ACCEPTFULL);
165 michael 2820 return 0;
166 michael 887 }
167 adx 30
168 michael 887 nuh.nuhmask = mask;
169     nuh.nickptr = nick;
170     nuh.userptr = user;
171     nuh.hostptr = host;
172 adx 30
173 michael 887 nuh.nicksize = sizeof(nick);
174     nuh.usersize = sizeof(user);
175     nuh.hostsize = sizeof(host);
176 adx 30
177 michael 887 split_nuh(&nuh);
178 adx 30
179 michael 2363 if ((accept_p = find_accept(nick, user, host, source_p, irccmp)) != NULL)
180 michael 887 {
181 michael 3109 sendto_one_numeric(source_p, &me, ERR_ACCEPTEXIST, nick, user, host);
182 michael 887 continue;
183     }
184    
185     add_accept(&nuh, source_p);
186 adx 30 }
187     }
188 michael 2820
189     return 0;
190 adx 30 }
191 michael 1230
192 michael 2820 static struct Message accept_msgtab =
193     {
194 michael 1230 "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 michael 2820 struct module module_entry =
211     {
212 michael 1230 .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