ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/modules/m_accept.c
Revision: 232
Committed: Sat Nov 5 06:05:06 2005 UTC (20 years, 9 months ago) by db
Content type: text/x-csrc
File size: 7296 byte(s)
Log Message:
- This commits the n!u@h accept code
  I'll tidy it up more later.


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 "hash.h" /* for find_client() */
29     #include "ircd.h"
30     #include "numeric.h"
31     #include "s_conf.h"
32     #include "s_serv.h"
33     #include "send.h"
34     #include "msg.h"
35     #include "parse.h"
36     #include "s_user.h"
37     #include "modules.h"
38    
39     static void m_accept(struct Client *, struct Client *, int, char *[]);
40 db 232 static void build_nuh_list(struct Client *, char *, char *, char *);
41     static void add_accept(const char *name, const char *username,
42     const char *host, struct Client *source_p);
43     static int del_accept(const char *name, const char *username,
44     const char *host, struct Client *source_p);
45 adx 30 static void list_accepts(struct Client *);
46    
47     struct Message accept_msgtab = {
48     "ACCEPT", 0, 0, 0, 0, MFLG_SLOW, 0,
49     {m_unregistered, m_accept, m_ignore, m_ignore, m_accept, m_ignore}
50     };
51    
52     #ifndef STATIC_MODULES
53     void
54     _modinit(void)
55     {
56     mod_add_cmd(&accept_msgtab);
57     }
58    
59     void
60     _moddeinit(void)
61     {
62     mod_del_cmd(&accept_msgtab);
63     }
64    
65 knight 31 const char *_version = "$Revision$";
66 adx 30 #endif
67    
68     /*
69     * m_accept - ACCEPT command handler
70     * parv[0] = sender prefix
71     * parv[1] = servername
72     */
73     static void
74     m_accept(struct Client *client_p, struct Client *source_p,
75     int parc, char *parv[])
76     {
77 db 232 char *mask, *nick, *user, *host;
78 adx 30 char *p = NULL;
79     char addbuf[IRCD_BUFSIZE] = { '\0' };
80     char delbuf[IRCD_BUFSIZE] = { '\0' };
81 db 232 int accept_num=0;
82 adx 30
83 db 232 if (parc < 2)
84 adx 30 {
85     list_accepts(source_p);
86     return;
87     }
88    
89 db 232 build_nuh_list(source_p, addbuf, delbuf, parv[1]);
90 adx 30
91     /* parse the delete list */
92 db 232 for (mask = strtoken(&p, delbuf, ","); mask != NULL;
93     mask = strtoken(&p, NULL, ","))
94 adx 30 {
95 db 232 /* user isn't on clients accept list */
96     split_nuh(mask, &nick, &user, &host);
97     if (!accept_message((const char *)nick, (const char *)user,
98     (const char *)host, NULL, source_p))
99 adx 30 {
100     sendto_one(source_p, form_str(ERR_ACCEPTNOT),
101 db 232 me.name, source_p->name, nick, user, host);
102 adx 30 continue;
103     }
104    
105 db 232 del_accept(nick, user, host, source_p);
106 adx 30 }
107    
108     /* get the number of accepts they have */
109 db 232 accept_num = dlink_list_length(&source_p->localClient->acceptlist);
110 adx 30
111     /* parse the add list */
112 db 232 for (mask = strtoken(&p, addbuf, ","); mask;
113     mask = strtoken(&p, NULL, ","), accept_num++)
114 adx 30 {
115 db 232 /* user is already on clients accept list */
116     split_nuh(mask, &nick, &user, &host);
117 adx 30
118 db 232 if (accept_message(nick, user, host, NULL, source_p))
119 adx 30 {
120     sendto_one(source_p, form_str(ERR_ACCEPTEXIST),
121 db 232 me.name, source_p->name, nick, user, host);
122 adx 30 continue;
123     }
124    
125     if (accept_num >= ConfigFileEntry.max_accept)
126     {
127     sendto_one(source_p, form_str(ERR_ACCEPTFULL),
128     me.name, source_p->name);
129     return;
130     }
131 db 232
132     add_accept(nick, user, host, source_p);
133 adx 30 }
134     }
135    
136 db 232 /* build_nuh_list()
137 adx 30 *
138     * input - pointer to client
139     * - pointer to addbuffer
140     * - pointer to remove buffer
141     * - pointer to list of nicks
142 db 232 * - pointer to list of nicks!user@host
143 adx 30 * output -
144 db 232 * side effects - addbuf/delbuf are modified to give valid masks
145 adx 30 */
146     static void
147 db 232 build_nuh_list(struct Client *source_p, char *addbuf,
148     char *delbuf, char *masks)
149 adx 30 {
150 db 232 char *mask = NULL;
151 adx 30 char *p = NULL;
152 db 232 int lenadd;
153     int lendel;
154 adx 30
155 db 232 *addbuf = *delbuf = '\0';
156     lenadd = lendel = 0;
157    
158     /* build list of nuh to add into addbuf, nuh to remove in delbuf */
159     for (mask = strtoken(&p, masks, ","); mask;
160     mask = strtoken(&p, NULL, ","))
161 adx 30 {
162 db 232 if (*mask == '-')
163     {
164     mask++;
165    
166     /* deleting a client */
167     if (*delbuf)
168     strcat(delbuf, ",");
169    
170     strncat(delbuf, mask, IRCD_BUFSIZE - lendel - 1);
171     lendel += strlen(mask) + 1;
172     }
173     /* adding a client */
174 adx 30 else
175     {
176 db 232 if (*addbuf)
177     strcat(addbuf, ",");
178    
179     strncat(addbuf, mask, IRCD_BUFSIZE - lenadd - 1);
180     lenadd += strlen(mask) + 1;
181 adx 30 }
182     }
183     }
184    
185     /* add_accept()
186     *
187 db 232 * input - nick
188     * - username
189     * - host
190     * - pointer to client to add to acceptlist
191 adx 30 * output - none
192     * side effects - target is added to clients list
193     */
194     static void
195 db 232 add_accept(const char *name, const char *username, const char *host,
196     struct Client *source_p)
197 adx 30 {
198 db 232 struct Accept *accept;
199    
200     accept = MyMalloc(sizeof(struct Accept));
201     DupString(accept->name, name);
202     DupString(accept->username, username);
203     DupString(accept->host, host);
204     dlinkAdd(accept, &accept->node, &source_p->localClient->acceptlist);
205    
206 adx 30 list_accepts(source_p);
207     }
208    
209 db 232 /* del_accept()
210     *
211     * input - nick
212     * - username
213     * - host
214     * - pointer to client to add to acceptlist
215     * output - 1 if found and removed 0 if not found and nothing removed
216     * side effects - mask is removed from acceptlist of given client if found
217     */
218     static int
219     del_accept(const char *name, const char *username, const char *host,
220     struct Client *client_p)
221     {
222     struct Accept *accept;
223     dlink_node *ptr, *next_ptr;
224     int found=0;
225    
226     DLINK_FOREACH_SAFE(ptr, next_ptr, client_p->localClient->acceptlist.head)
227     {
228     accept = ptr->data;
229     if (match(accept->name, name) &&
230     match(accept->username, username) &&
231     match(accept->host, host))
232     {
233     MyFree(accept->name);
234     MyFree(accept->username);
235     MyFree(accept->host);
236     dlinkDelete(ptr, &client_p->localClient->acceptlist);
237     MyFree(accept);
238     found = 1; /* On the off chance, they have more than one */
239     }
240     }
241     return(found);
242     }
243    
244 adx 30 /* list_accepts()
245     *
246     * input - pointer to client
247     * output - none
248     * side effects - print accept list to client
249     */
250     static void
251     list_accepts(struct Client *source_p)
252     {
253 db 232 struct Accept *accept;
254 adx 30 int len = 0;
255 db 232 char nuh_list[IRCD_BUFSIZE] = { '\0' };
256     char *t = nuh_list;
257 adx 30 const dlink_node *ptr = NULL;
258    
259     len = strlen(me.name) + strlen(source_p->name) + 12;
260    
261 db 232 DLINK_FOREACH(ptr, source_p->localClient->acceptlist.head)
262 adx 30 {
263 db 232 accept = ptr->data;
264 adx 30
265 db 232 if ((t - nuh_list) + strlen(source_p->name) + len > IRCD_BUFSIZE)
266 adx 30 {
267     *(t - 1) = '\0';
268     sendto_one(source_p, form_str(RPL_ACCEPTLIST),
269 db 232 me.name, source_p->name, nuh_list);
270     t = nuh_list;
271 adx 30 }
272    
273 db 232 t += ircsprintf(t, "%s!%s@%s ",
274     accept->name, accept->username, accept->host);
275 adx 30 }
276    
277 db 232 if (nuh_list[0] != '\0')
278 adx 30 {
279     *(t - 1) = '\0';
280     sendto_one(source_p, form_str(RPL_ACCEPTLIST),
281 db 232 me.name, source_p->name, nuh_list);
282 adx 30 }
283    
284     sendto_one(source_p, form_str(RPL_ENDOFACCEPT),
285     me.name, source_p->name);
286     }

Properties

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