ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_accept.c
Revision: 2820
Committed: Wed Jan 15 23:10:26 2014 UTC (11 years, 7 months ago) by michael
Content type: text/x-csrc
File size: 6172 byte(s)
Log Message:
- Clean up all files in modules/ (fixed indentation, removed whitespaces/tabs)
- Fixed copyright years
- Made module handlers int type for later use

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

Properties

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