ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_accept.c
Revision: 1230
Committed: Thu Sep 22 19:41:19 2011 UTC (13 years, 11 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-8/modules/m_accept.c
File size: 6206 byte(s)
Log Message:
- cleanup module loader. Make module api more flexible

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

Properties

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