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 (18 years, 5 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

# Content
1 /*
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 * $Id$
23 */
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 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 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 const char *_version = "$Revision$";
66 #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 char *mask, *nick, *user, *host;
78 char *p = NULL;
79 char addbuf[IRCD_BUFSIZE] = { '\0' };
80 char delbuf[IRCD_BUFSIZE] = { '\0' };
81 int accept_num=0;
82
83 if (parc < 2)
84 {
85 list_accepts(source_p);
86 return;
87 }
88
89 build_nuh_list(source_p, addbuf, delbuf, parv[1]);
90
91 /* parse the delete list */
92 for (mask = strtoken(&p, delbuf, ","); mask != NULL;
93 mask = strtoken(&p, NULL, ","))
94 {
95 /* 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 {
100 sendto_one(source_p, form_str(ERR_ACCEPTNOT),
101 me.name, source_p->name, nick, user, host);
102 continue;
103 }
104
105 del_accept(nick, user, host, source_p);
106 }
107
108 /* get the number of accepts they have */
109 accept_num = dlink_list_length(&source_p->localClient->acceptlist);
110
111 /* parse the add list */
112 for (mask = strtoken(&p, addbuf, ","); mask;
113 mask = strtoken(&p, NULL, ","), accept_num++)
114 {
115 /* user is already on clients accept list */
116 split_nuh(mask, &nick, &user, &host);
117
118 if (accept_message(nick, user, host, NULL, source_p))
119 {
120 sendto_one(source_p, form_str(ERR_ACCEPTEXIST),
121 me.name, source_p->name, nick, user, host);
122 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
132 add_accept(nick, user, host, source_p);
133 }
134 }
135
136 /* build_nuh_list()
137 *
138 * input - pointer to client
139 * - pointer to addbuffer
140 * - pointer to remove buffer
141 * - pointer to list of nicks
142 * - pointer to list of nicks!user@host
143 * output -
144 * side effects - addbuf/delbuf are modified to give valid masks
145 */
146 static void
147 build_nuh_list(struct Client *source_p, char *addbuf,
148 char *delbuf, char *masks)
149 {
150 char *mask = NULL;
151 char *p = NULL;
152 int lenadd;
153 int lendel;
154
155 *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 {
162 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 else
175 {
176 if (*addbuf)
177 strcat(addbuf, ",");
178
179 strncat(addbuf, mask, IRCD_BUFSIZE - lenadd - 1);
180 lenadd += strlen(mask) + 1;
181 }
182 }
183 }
184
185 /* add_accept()
186 *
187 * input - nick
188 * - username
189 * - host
190 * - pointer to client to add to acceptlist
191 * output - none
192 * side effects - target is added to clients list
193 */
194 static void
195 add_accept(const char *name, const char *username, const char *host,
196 struct Client *source_p)
197 {
198 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 list_accepts(source_p);
207 }
208
209 /* 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 /* 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 struct Accept *accept;
254 int len = 0;
255 char nuh_list[IRCD_BUFSIZE] = { '\0' };
256 char *t = nuh_list;
257 const dlink_node *ptr = NULL;
258
259 len = strlen(me.name) + strlen(source_p->name) + 12;
260
261 DLINK_FOREACH(ptr, source_p->localClient->acceptlist.head)
262 {
263 accept = ptr->data;
264
265 if ((t - nuh_list) + strlen(source_p->name) + len > IRCD_BUFSIZE)
266 {
267 *(t - 1) = '\0';
268 sendto_one(source_p, form_str(RPL_ACCEPTLIST),
269 me.name, source_p->name, nuh_list);
270 t = nuh_list;
271 }
272
273 t += ircsprintf(t, "%s!%s@%s ",
274 accept->name, accept->username, accept->host);
275 }
276
277 if (nuh_list[0] != '\0')
278 {
279 *(t - 1) = '\0';
280 sendto_one(source_p, form_str(RPL_ACCEPTLIST),
281 me.name, source_p->name, nuh_list);
282 }
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