ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/modules/m_accept.c
Revision: 241
Committed: Sat Nov 5 19:39:35 2005 UTC (20 years, 9 months ago) by db
Content type: text/x-csrc
File size: 4937 byte(s)
Log Message:
- Don't allocate memory until it is known it will be allowed
- No need to allocate memory twice.


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     /*
64     * m_accept - ACCEPT command handler
65     * parv[0] = sender prefix
66 michael 239 * parv[1] = list of masks to be accepted or removed
67 adx 30 */
68     static void
69     m_accept(struct Client *client_p, struct Client *source_p,
70     int parc, char *parv[])
71     {
72 michael 235 struct Accept *accept = NULL;
73 db 232 char *mask, *nick, *user, *host;
74 adx 30 char *p = NULL;
75 michael 240
76 michael 239 if (parc < 2 || !irccmp(parv[1], "*"))
77 adx 30 {
78     list_accepts(source_p);
79     return;
80     }
81    
82 michael 239 for (mask = strtoken(&p, parv[1], ","); mask != NULL;
83     mask = strtoken(&p, NULL, ","))
84 adx 30 {
85 michael 239 if (*mask == '-' && *++mask != '\0')
86 adx 30 {
87 michael 239 split_nuh(mask, &nick, &user, &host);
88 adx 30
89 michael 239 if ((accept = find_accept(nick, user, host, source_p, 0)) == NULL)
90     {
91     sendto_one(source_p, form_str(ERR_ACCEPTNOT),
92     me.name, source_p->name, nick, user, host);
93     MyFree(nick);
94     MyFree(user);
95     MyFree(host);
96     continue;
97     }
98 michael 235
99 michael 239 del_accept(accept, source_p);
100 adx 30
101 michael 235 MyFree(nick);
102     MyFree(user);
103     MyFree(host);
104 adx 30 }
105 michael 239 else if (*mask != '\0')
106     {
107 db 241 if (dlink_list_length(&source_p->localClient->acceptlist) >=
108     ConfigFileEntry.max_accept)
109     {
110     sendto_one(source_p, form_str(ERR_ACCEPTFULL),
111     me.name, source_p->name);
112     return;
113     }
114    
115 michael 239 split_nuh(mask, &nick, &user, &host);
116 adx 30
117 michael 239 if ((accept = find_accept(nick, user, host, source_p, 0)) != NULL)
118     {
119     sendto_one(source_p, form_str(ERR_ACCEPTEXIST),
120     me.name, source_p->name, nick, user, host);
121     MyFree(nick);
122     MyFree(user);
123     MyFree(host);
124     continue;
125     }
126     add_accept(nick, user, host, source_p);
127 adx 30 }
128     }
129     }
130    
131     /* add_accept()
132     *
133 db 241 * input - pointer to preallocated nick
134     * - pointer to preallocated username
135     * - pointer to preallocated host
136 db 232 * - pointer to client to add to acceptlist
137 adx 30 * output - none
138     * side effects - target is added to clients list
139     */
140     static void
141 db 241 add_accept(char *nick, char *user, char *host, struct Client *source_p)
142 adx 30 {
143 michael 235 struct Accept *accept = MyMalloc(sizeof(*accept));
144    
145 db 241 accept->nick = nick;
146     accept->user = user;
147     accept->host = host;
148 michael 235
149 db 232 dlinkAdd(accept, &accept->node, &source_p->localClient->acceptlist);
150    
151 adx 30 list_accepts(source_p);
152     }
153    
154     /* list_accepts()
155     *
156     * input - pointer to client
157     * output - none
158     * side effects - print accept list to client
159     */
160     static void
161     list_accepts(struct Client *source_p)
162     {
163 db 232 struct Accept *accept;
164 adx 30 int len = 0;
165 db 232 char nuh_list[IRCD_BUFSIZE] = { '\0' };
166     char *t = nuh_list;
167 adx 30 const dlink_node *ptr = NULL;
168    
169     len = strlen(me.name) + strlen(source_p->name) + 12;
170    
171 db 232 DLINK_FOREACH(ptr, source_p->localClient->acceptlist.head)
172 adx 30 {
173 db 232 accept = ptr->data;
174 adx 30
175 db 232 if ((t - nuh_list) + strlen(source_p->name) + len > IRCD_BUFSIZE)
176 adx 30 {
177     *(t - 1) = '\0';
178     sendto_one(source_p, form_str(RPL_ACCEPTLIST),
179 db 232 me.name, source_p->name, nuh_list);
180     t = nuh_list;
181 adx 30 }
182    
183 db 232 t += ircsprintf(t, "%s!%s@%s ",
184 michael 235 accept->nick, accept->user, accept->host);
185 adx 30 }
186    
187 db 232 if (nuh_list[0] != '\0')
188 adx 30 {
189     *(t - 1) = '\0';
190     sendto_one(source_p, form_str(RPL_ACCEPTLIST),
191 db 232 me.name, source_p->name, nuh_list);
192 adx 30 }
193    
194     sendto_one(source_p, form_str(RPL_ENDOFACCEPT),
195     me.name, source_p->name);
196     }

Properties

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