ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/src/node.C
Revision: 1.6
Committed: Sun Sep 16 18:54:45 2007 UTC (16 years, 8 months ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.5: +7 -2 lines
Log Message:
#defines to enum

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