ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_accept.c
Revision: 1155
Committed: Tue Aug 9 20:27:45 2011 UTC (14 years ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid/modules/m_accept.c
File size: 6084 byte(s)
Log Message:
- recreate "trunk"

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

Properties

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