ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/ermyth/src/node.C
Revision: 1.5
Committed: Sun Sep 9 20:05:52 2007 UTC (19 years ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.4: +24 -39 lines
Log Message:
- changed configurations to the c++ stdlib
- more #defines to enum
- removed getopt.h and link.h from the system as they were unused
- reworked logstreams
- added an itoa with old syntax
- made klines objects
- moved some global variables into appropriate classes
- fixed boost.foreach's compiler workaround #if's
- allow other files to add exceptions with ADD_EXCEPTION
- changed mynick_t to c++ object
- moved servers.h out of atheme.h
- corrected PING from inspircd 1.2

File Contents

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