ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/modules/m_accept.c
Revision: 470
Committed: Fri Feb 17 05:07:43 2006 UTC (20 years, 5 months ago) by db
Content type: text/x-csrc
File size: 5985 byte(s)
Log Message:
- fix compile errors with moved modules.h
- fix a few missing includes, msg.h and parse.h


File Contents

# User Rev Content
1 adx 30 /*
2     * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3     * m_accept.c: Allows a user to talk to a +g user.
4     *
5     * Copyright (C) 2002 by the past and present ircd coders, and others.
6     *
7     * This program is free software; you can redistribute it and/or modify
8     * it under the terms of the GNU General Public License as published by
9     * the Free Software Foundation; either version 2 of the License, or
10     * (at your option) any later version.
11     *
12     * This program is distributed in the hope that it will be useful,
13     * but WITHOUT ANY WARRANTY; without even the implied warranty of
14     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15     * GNU General Public License for more details.
16     *
17     * You should have received a copy of the GNU General Public License
18     * along with this program; if not, write to the Free Software
19     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20     * USA
21     *
22 knight 31 * $Id$
23 adx 30 */
24    
25     #include "stdinc.h"
26     #include "handlers.h"
27     #include "client.h"
28     #include "ircd.h"
29     #include "numeric.h"
30     #include "s_conf.h"
31     #include "s_serv.h"
32     #include "send.h"
33     #include "msg.h"
34     #include "parse.h"
35     #include "s_user.h"
36 db 470 #include "conf/modules.h"
37 adx 30
38     static void m_accept(struct Client *, struct Client *, int, char *[]);
39 michael 357 static void add_accept(const struct split_nuh_item *, struct Client *);
40 adx 30 static void list_accepts(struct Client *);
41    
42     struct Message accept_msgtab = {
43 michael 235 "ACCEPT", 0, 0, 0, 0, MFLG_SLOW, 0,
44     { m_unregistered, m_accept, m_ignore, m_ignore, m_accept, m_ignore }
45 adx 30 };
46    
47 adx 442 INIT_MODULE(m_accept, "$Revision$")
48 adx 30 {
49     mod_add_cmd(&accept_msgtab);
50     }
51    
52 adx 442 CLEANUP_MODULE
53 adx 30 {
54     mod_del_cmd(&accept_msgtab);
55     }
56    
57 michael 345 /*! \brief ACCEPT command handler
58     *
59     * \param client_p Pointer to allocated Client struct with physical connection
60     * to this server, i.e. with an open socket connected.
61     * \param source_p Pointer to allocated Client struct from which the message
62     * originally comes from. This can be a local or remote client.
63     * \param parc Integer holding the number of supplied arguments.
64     * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
65     * pointers.
66     * \note Valid arguments for this command are:
67     * - parv[0] = sender prefix
68     * - parv[1] = list of masks to be accepted or removed (optional)
69 adx 30 */
70     static void
71     m_accept(struct Client *client_p, struct Client *source_p,
72     int parc, char *parv[])
73     {
74 metalrock 362 struct Accept *acceptvar = NULL;
75 michael 357 char *mask = NULL;
76     char nick[NICKLEN + 1];
77     char user[USERLEN + 1];
78     char host[HOSTLEN + 1];
79 adx 271 char first, *p = NULL;
80 michael 357 struct split_nuh_item nuh;
81 michael 240
82 adx 271 if (EmptyString(parv[1]) || !irccmp(parv[1], "*"))
83 adx 30 {
84     list_accepts(source_p);
85     return;
86     }
87    
88 adx 271 for (mask = strtoken(&p, parv[1], ","), first = YES; mask != NULL;
89     mask = strtoken(&p, NULL, ","), first = NO)
90 adx 30 {
91 michael 239 if (*mask == '-' && *++mask != '\0')
92 adx 30 {
93 michael 357 nuh.nuhmask = mask;
94     nuh.nickptr = nick;
95     nuh.userptr = user;
96     nuh.hostptr = host;
97 adx 30
98 michael 357 nuh.nicksize = sizeof(nick);
99     nuh.usersize = sizeof(user);
100     nuh.hostsize = sizeof(host);
101    
102     split_nuh(&nuh);
103    
104 metalrock 362 if ((acceptvar = find_accept(nick, user, host, source_p, 0)) == NULL)
105 michael 239 {
106 adx 271 if (first)
107     sendto_one(source_p, form_str(ERR_ACCEPTNOT),
108     me.name, source_p->name, nick, user, host);
109 michael 239 continue;
110     }
111 michael 235
112 metalrock 362 del_accept(acceptvar, source_p);
113 adx 30 }
114 michael 239 else if (*mask != '\0')
115     {
116 db 241 if (dlink_list_length(&source_p->localClient->acceptlist) >=
117     ConfigFileEntry.max_accept)
118     {
119     sendto_one(source_p, form_str(ERR_ACCEPTFULL),
120     me.name, source_p->name);
121 adx 271 return;
122 db 241 }
123    
124 michael 357 nuh.nuhmask = mask;
125     nuh.nickptr = nick;
126     nuh.userptr = user;
127     nuh.hostptr = host;
128 adx 30
129 michael 357 nuh.nicksize = sizeof(nick);
130     nuh.usersize = sizeof(user);
131     nuh.hostsize = sizeof(host);
132    
133     split_nuh(&nuh);
134    
135 metalrock 362 if ((acceptvar = find_accept(nick, user, host, source_p, 0)) != NULL)
136 michael 239 {
137 adx 271 if (first)
138     sendto_one(source_p, form_str(ERR_ACCEPTEXIST),
139     me.name, source_p->name, nick, user, host);
140 michael 239 continue;
141     }
142 michael 357
143     add_accept(&nuh, source_p);
144 adx 30 }
145     }
146     }
147    
148     /* add_accept()
149     *
150 db 241 * input - pointer to preallocated nick
151     * - pointer to preallocated username
152     * - pointer to preallocated host
153 db 232 * - pointer to client to add to acceptlist
154 adx 30 * output - none
155     * side effects - target is added to clients list
156     */
157     static void
158 michael 357 add_accept(const struct split_nuh_item *nuh, struct Client *source_p)
159 adx 30 {
160 metalrock 362 struct Accept *acceptvar = MyMalloc(sizeof(*acceptvar));
161 michael 235
162 metalrock 362 DupString(acceptvar->nick, nuh->nickptr);
163     DupString(acceptvar->user, nuh->userptr);
164     DupString(acceptvar->host, nuh->hostptr);
165 michael 235
166 metalrock 362 dlinkAdd(acceptvar, &acceptvar->node, &source_p->localClient->acceptlist);
167 db 232
168 adx 30 list_accepts(source_p);
169     }
170    
171     /* list_accepts()
172     *
173     * input - pointer to client
174     * output - none
175     * side effects - print accept list to client
176     */
177     static void
178     list_accepts(struct Client *source_p)
179     {
180 metalrock 362 struct Accept *acceptvar = NULL;
181 adx 30 int len = 0;
182 db 232 char nuh_list[IRCD_BUFSIZE] = { '\0' };
183 michael 357 char *t = NULL;
184 adx 30 const dlink_node *ptr = NULL;
185    
186 michael 357 len = ircsprintf(nuh_list, form_str(RPL_ACCEPTLIST),
187     me.name, source_p->name);
188 adx 271 t = nuh_list + len;
189 adx 30
190 db 232 DLINK_FOREACH(ptr, source_p->localClient->acceptlist.head)
191 adx 30 {
192 metalrock 362 acceptvar = ptr->data;
193 adx 30
194 metalrock 362 if ((t - nuh_list) + (strlen(acceptvar->nick) + 1 + strlen(acceptvar->user) + 1 +
195     strlen(acceptvar->host)) > IRCD_BUFSIZE)
196 adx 30 {
197     *(t - 1) = '\0';
198 adx 271 sendto_one(source_p, "%s", nuh_list);
199     t = nuh_list + len;
200 adx 30 }
201    
202 db 232 t += ircsprintf(t, "%s!%s@%s ",
203 metalrock 362 acceptvar->nick, acceptvar->user, acceptvar->host);
204 adx 30 }
205    
206 adx 271 if (t - nuh_list > len)
207 adx 30 {
208     *(t - 1) = '\0';
209     sendto_one(source_p, form_str(RPL_ACCEPTLIST),
210 db 232 me.name, source_p->name, nuh_list);
211 adx 30 }
212    
213     sendto_one(source_p, form_str(RPL_ENDOFACCEPT),
214     me.name, source_p->name);
215     }

Properties

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