ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/modules/m_accept.c
Revision: 345
Committed: Sat Dec 31 11:50:01 2005 UTC (20 years, 7 months ago) by michael
Content type: text/x-csrc
File size: 5618 byte(s)
Log Message:
- Continue doxyfying modules

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     #include "modules.h"
37    
38     static void m_accept(struct Client *, struct Client *, int, char *[]);
39 db 241 static void add_accept(char *, char *, char *, 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     #ifndef STATIC_MODULES
48     void
49     _modinit(void)
50     {
51     mod_add_cmd(&accept_msgtab);
52     }
53    
54     void
55     _moddeinit(void)
56     {
57     mod_del_cmd(&accept_msgtab);
58     }
59    
60 knight 31 const char *_version = "$Revision$";
61 adx 30 #endif
62    
63 michael 345
64     /*! \brief ACCEPT command handler
65     *
66     * \param client_p Pointer to allocated Client struct with physical connection
67     * to this server, i.e. with an open socket connected.
68     * \param source_p Pointer to allocated Client struct from which the message
69     * originally comes from. This can be a local or remote client.
70     * \param parc Integer holding the number of supplied arguments.
71     * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
72     * pointers.
73     * \note Valid arguments for this command are:
74     * - parv[0] = sender prefix
75     * - parv[1] = list of masks to be accepted or removed (optional)
76 adx 30 */
77     static void
78     m_accept(struct Client *client_p, struct Client *source_p,
79     int parc, char *parv[])
80     {
81 michael 235 struct Accept *accept = NULL;
82 db 232 char *mask, *nick, *user, *host;
83 adx 271 char first, *p = NULL;
84 michael 240
85 adx 271 if (EmptyString(parv[1]) || !irccmp(parv[1], "*"))
86 adx 30 {
87     list_accepts(source_p);
88     return;
89     }
90    
91 adx 271 for (mask = strtoken(&p, parv[1], ","), first = YES; mask != NULL;
92     mask = strtoken(&p, NULL, ","), first = NO)
93 adx 30 {
94 michael 239 if (*mask == '-' && *++mask != '\0')
95 adx 30 {
96 michael 239 split_nuh(mask, &nick, &user, &host);
97 adx 30
98 michael 239 if ((accept = find_accept(nick, user, host, source_p, 0)) == NULL)
99     {
100 adx 271 if (first)
101     sendto_one(source_p, form_str(ERR_ACCEPTNOT),
102     me.name, source_p->name, nick, user, host);
103 michael 239 MyFree(nick);
104     MyFree(user);
105     MyFree(host);
106     continue;
107     }
108 michael 235
109 michael 239 del_accept(accept, source_p);
110 adx 30
111 michael 235 MyFree(nick);
112     MyFree(user);
113     MyFree(host);
114 adx 30 }
115 michael 239 else if (*mask != '\0')
116     {
117 db 241 if (dlink_list_length(&source_p->localClient->acceptlist) >=
118     ConfigFileEntry.max_accept)
119     {
120     sendto_one(source_p, form_str(ERR_ACCEPTFULL),
121     me.name, source_p->name);
122 adx 271 return;
123 db 241 }
124    
125 michael 239 split_nuh(mask, &nick, &user, &host);
126 adx 30
127 michael 239 if ((accept = find_accept(nick, user, host, source_p, 0)) != NULL)
128     {
129 adx 271 if (first)
130     sendto_one(source_p, form_str(ERR_ACCEPTEXIST),
131     me.name, source_p->name, nick, user, host);
132 michael 239 MyFree(nick);
133     MyFree(user);
134     MyFree(host);
135     continue;
136     }
137     add_accept(nick, user, host, source_p);
138 adx 30 }
139     }
140     }
141    
142     /* add_accept()
143     *
144 db 241 * input - pointer to preallocated nick
145     * - pointer to preallocated username
146     * - pointer to preallocated host
147 db 232 * - pointer to client to add to acceptlist
148 adx 30 * output - none
149     * side effects - target is added to clients list
150     */
151     static void
152 db 241 add_accept(char *nick, char *user, char *host, struct Client *source_p)
153 adx 30 {
154 michael 235 struct Accept *accept = MyMalloc(sizeof(*accept));
155    
156 db 241 accept->nick = nick;
157     accept->user = user;
158     accept->host = host;
159 michael 235
160 db 232 dlinkAdd(accept, &accept->node, &source_p->localClient->acceptlist);
161    
162 adx 30 list_accepts(source_p);
163     }
164    
165     /* list_accepts()
166     *
167     * input - pointer to client
168     * output - none
169     * side effects - print accept list to client
170     */
171     static void
172     list_accepts(struct Client *source_p)
173     {
174 db 232 struct Accept *accept;
175 adx 30 int len = 0;
176 db 232 char nuh_list[IRCD_BUFSIZE] = { '\0' };
177 adx 271 char *t;
178 adx 30 const dlink_node *ptr = NULL;
179    
180 adx 271 len = ircsprintf(nuh_list, form_str(RPL_ACCEPTLIST), me.name,
181     source_p->name);
182     t = nuh_list + len;
183 adx 30
184 db 232 DLINK_FOREACH(ptr, source_p->localClient->acceptlist.head)
185 adx 30 {
186 db 232 accept = ptr->data;
187 adx 30
188 adx 271 if ((t - nuh_list) + (strlen(accept->nick) + 1 + strlen(accept->user) + 1 +
189     strlen(accept->host)) > IRCD_BUFSIZE)
190 adx 30 {
191     *(t - 1) = '\0';
192 adx 271 sendto_one(source_p, "%s", nuh_list);
193     t = nuh_list + len;
194 adx 30 }
195    
196 db 232 t += ircsprintf(t, "%s!%s@%s ",
197 michael 235 accept->nick, accept->user, accept->host);
198 adx 30 }
199    
200 adx 271 if (t - nuh_list > len)
201 adx 30 {
202     *(t - 1) = '\0';
203     sendto_one(source_p, form_str(RPL_ACCEPTLIST),
204 db 232 me.name, source_p->name, nuh_list);
205 adx 30 }
206    
207     sendto_one(source_p, form_str(RPL_ENDOFACCEPT),
208     me.name, source_p->name);
209     }

Properties

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