ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/src/node.C
Revision: 1.7
Committed: Sat Sep 22 14:27:30 2007 UTC (16 years, 7 months ago) by pippijn
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.6: +33 -35 lines
Log Message:
split up ermyth into ermyth-modules, libermyth (currently just ermyth-util) and ermyth-core

File Contents

# Content
1 /*
2 * node.C: Data structure management.
3 *
4 * Copyright © 2007 Pippijn van Steenhoven / The Ermyth Team
5 * Rights to this code are as documented in COPYING.
6 *
7 *
8 * Portions of this file were derived from sources bearing the following license:
9 * Rights to this code are documented in doc/pod/license.pod.
10 * Copyright © 2005-2007 Atheme Project (http://www.atheme.org)
11 */
12
13 static char const rcsid[] = "$Id: node.C,v 1.6 2007-09-16 18:54:45 pippijn Exp $";
14
15 #include <boost/foreach.hpp>
16
17 #include "atheme.h"
18 #include <util/time.h>
19 #include <util/time.h>
20 #include <libermyth.h>
21 #include "servers.h"
22 #include <account/kline.h>
23 #include "uplink.h"
24 #include "privs.h"
25
26 kline_t::list_type kline_t::list;
27
28 /*************
29 * L I S T S *
30 *************/
31
32 void
33 init_nodes (void)
34 {
35 #if 0
36 kline_heap = BlockHeapCreate (sizeof (kline_t), 16);
37 #endif
38
39 init_uplinks ();
40 init_servers ();
41 init_accounts ();
42 init_users ();
43 init_channels ();
44 init_privs ();
45 }
46
47 /* Mark everything illegal, to be called before a rehash -- jilles */
48 void
49 mark_all_illegal ()
50 {
51 std::vector<soper_t *> soper_mortals;
52
53 foreach (uplink_t *u, uplinks)
54 u->flags |= UPF_ILLEGAL;
55
56 /* just delete these, we can survive without for a while */
57 foreach (soper_t *soper, soper_t::list)
58 if (soper->flags & SOPER_CONF)
59 soper_mortals.push_back (soper);
60
61 while (!soper_mortals.empty ())
62 {
63 soper_delete (soper_mortals.back ());
64 soper_mortals.pop_back ();
65 }
66
67 /* no sopers pointing to these anymore */
68 while (!operclass_t::list.empty ())
69 operclass_delete (operclass_t::list.back ());
70 }
71
72 /* Unmark everything illegal, to be called after a failed rehash -- jilles */
73 void
74 unmark_all_illegal ()
75 {
76 foreach (uplink_t *u, uplinks)
77 u->flags &= ~UPF_ILLEGAL;
78 }
79
80 /* Remove illegal stuff, to be called after a successful rehash -- jilles */
81 void
82 remove_illegals ()
83 {
84 std::vector<uplink_t *> mortals;
85
86 foreach (uplink_t *u, uplinks)
87 {
88 if (u->flags & UPF_ILLEGAL && u != curr_uplink)
89 mortals.push_back (u);
90 }
91
92 while (!mortals.empty ())
93 {
94 uplink_delete (mortals.back ());
95 mortals.pop_back ();
96 }
97 }
98
99 /*************
100 * K L I N E *
101 *************/
102
103 kline_t *
104 kline_t::create (char const * const user, char const * const host, char const * const reason, long duration)
105 {
106 kline_t *k;
107 static unsigned int kcnt = 0;
108
109 slog (LG_DEBUG, "kline_t::create(): %s@%s -> %s (%ld)", user, host, reason, duration);
110
111 k = new kline_t;
112
113 k->user = sstrdup (user);
114 k->host = sstrdup (host);
115 k->reason = sstrdup (reason);
116 k->duration = duration;
117 k->settime = NOW;
118 k->expires = NOW + duration;
119 k->number = ++kcnt;
120
121 list.push_back (k);
122
123 cnt.kline++;
124
125 phandler->kline_sts ("*", user, host, duration, reason);
126
127 return k;
128 }
129
130 void
131 kline_t::destroy (char const * const user, char const * const host)
132 {
133 kline_t *k = find (user, host);
134
135 if (!k)
136 {
137 slog (LG_DEBUG, "kline_t::destroy(): called for nonexistant kline: %s@%s", user, host);
138
139 return;
140 }
141
142 slog (LG_DEBUG, "kline_t::destroy(): %s@%s -> %s", k->user, k->host, k->reason);
143 /* only unkline if ircd has not already removed this -- jilles */
144 if (k->duration == 0 || k->expires > NOW)
145 phandler->unkline_sts ("*", k->user, k->host);
146
147 k->destroy ();
148 }
149
150 kline_t *
151 kline_t::find (char const * const user, char const * const host)
152 {
153 kline_t *k;
154 list_type::iterator klit = list.begin ();
155 list_type::iterator klet = list.end ();
156
157 while (klit != klet)
158 {
159 k = *klit;
160
161 if ((!match (k->user, user)) && (!match (k->host, host)))
162 return k;
163
164 ++klit;
165 }
166
167 return NULL;
168 }
169
170 kline_t *
171 kline_t::find (unsigned int number)
172 {
173 kline_t *k;
174 list_type::iterator klit = list.begin ();
175 list_type::iterator klet = list.end ();
176
177 while (klit != klet)
178 {
179 k = *klit;
180
181 if (k->number == number)
182 return k;
183
184 ++klit;
185 }
186
187 return NULL;
188 }
189
190 kline_t *
191 kline_t::find (user_t *u)
192 {
193 kline_t *k;
194 list_type::iterator klit = list.begin ();
195 list_type::iterator klet = list.end ();
196
197 while (klit != klet)
198 {
199 k = *klit;
200
201 if (k->duration != 0 && k->expires <= NOW)
202 continue;
203 if (!match (k->user, u->user) && (!match (k->host, u->host) || !match (k->host, u->ip) || !match_ips (k->host, u->ip)))
204 return k;
205 ++klit;
206 }
207
208 return NULL;
209 }
210
211 void
212 kline_t::expire (void *arg)
213 {
214 kline_t *k;
215 std::vector<kline_t *> mortals;
216 list_type::iterator klit = list.begin ();
217 list_type::iterator klet = list.end ();
218
219 while (klit != klet)
220 {
221 k = *klit;
222
223 if (k->duration == 0)
224 continue;
225
226 if (k->expires <= NOW)
227 {
228 snoop (_("KLINE:EXPIRE: \2%s@%s\2 set \2%s\2 ago by \2%s\2"), k->user, k->host, time_ago (k->settime), k->setby);
229
230 verbose_wallops (_("AKILL expired on \2%s@%s\2, set by \2%s\2"), k->user, k->host, k->setby);
231
232 mortals.push_back (k);
233 }
234
235 ++klit;
236 }
237
238 // We have to do this because we cannot destroy klines while iterating
239 while (!mortals.empty ())
240 {
241 mortals.back ()->destroy ();
242 mortals.pop_back ();
243 }
244 }