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: 1666
Committed: Sun Nov 18 17:03:18 2012 UTC (13 years, 8 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid/trunk/modules/m_accept.c
File size: 6182 byte(s)
Log Message:
- Cleanup unused header file includes
- Fixed minor compile warning in conf.c

File Contents

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

Properties

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