ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/ermyth/src/node.C
Revision: 1.7
Committed: Sat Sep 22 14:27:30 2007 UTC (16 years, 9 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

# User Rev Content
1 pippijn 1.1 /*
2     * node.C: Data structure management.
3 pippijn 1.6 *
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 pippijn 1.2 * Rights to this code are documented in doc/pod/license.pod.
10 pippijn 1.4 * Copyright © 2005-2007 Atheme Project (http://www.atheme.org)
11 pippijn 1.1 */
12    
13 pippijn 1.7 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 pippijn 1.1
17     #include "atheme.h"
18 pippijn 1.7 #include <util/time.h>
19     #include <util/time.h>
20     #include <libermyth.h>
21 pippijn 1.5 #include "servers.h"
22 pippijn 1.1 #include <account/kline.h>
23     #include "uplink.h"
24     #include "privs.h"
25    
26 pippijn 1.5 kline_t::list_type kline_t::list;
27 pippijn 1.1
28     /*************
29     * L I S T S *
30     *************/
31    
32     void
33     init_nodes (void)
34     {
35 pippijn 1.4 #if 0
36 pippijn 1.1 kline_heap = BlockHeapCreate (sizeof (kline_t), 16);
37 pippijn 1.4 #endif
38 pippijn 1.1
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 pippijn 1.7 std::vector<soper_t *> soper_mortals;
52    
53     foreach (uplink_t *u, uplinks)
54 pippijn 1.1 u->flags |= UPF_ILLEGAL;
55    
56     /* just delete these, we can survive without for a while */
57 pippijn 1.7 foreach (soper_t *soper, soper_t::list)
58 pippijn 1.1 if (soper->flags & SOPER_CONF)
59 pippijn 1.7 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 pippijn 1.1 /* no sopers pointing to these anymore */
68 pippijn 1.7 while (!operclass_t::list.empty ())
69     operclass_delete (operclass_t::list.back ());
70 pippijn 1.1 }
71    
72     /* Unmark everything illegal, to be called after a failed rehash -- jilles */
73     void
74     unmark_all_illegal ()
75     {
76 pippijn 1.7 foreach (uplink_t *u, uplinks)
77 pippijn 1.1 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 pippijn 1.7 std::vector<uplink_t *> mortals;
85 pippijn 1.1
86 pippijn 1.7 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 pippijn 1.1 }
98    
99     /*************
100     * K L I N E *
101     *************/
102    
103     kline_t *
104 pippijn 1.5 kline_t::create (char const * const user, char const * const host, char const * const reason, long duration)
105 pippijn 1.1 {
106     kline_t *k;
107     static unsigned int kcnt = 0;
108    
109 pippijn 1.5 slog (LG_DEBUG, "kline_t::create(): %s@%s -> %s (%ld)", user, host, reason, duration);
110 pippijn 1.1
111 pippijn 1.4 k = new kline_t;
112 pippijn 1.1
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 pippijn 1.5 list.push_back (k);
122 pippijn 1.1
123     cnt.kline++;
124    
125 pippijn 1.4 phandler->kline_sts ("*", user, host, duration, reason);
126 pippijn 1.1
127     return k;
128     }
129    
130     void
131 pippijn 1.5 kline_t::destroy (char const * const user, char const * const host)
132 pippijn 1.1 {
133 pippijn 1.5 kline_t *k = find (user, host);
134 pippijn 1.1
135     if (!k)
136     {
137 pippijn 1.5 slog (LG_DEBUG, "kline_t::destroy(): called for nonexistant kline: %s@%s", user, host);
138 pippijn 1.1
139     return;
140     }
141    
142 pippijn 1.5 slog (LG_DEBUG, "kline_t::destroy(): %s@%s -> %s", k->user, k->host, k->reason);
143 pippijn 1.1 /* only unkline if ircd has not already removed this -- jilles */
144     if (k->duration == 0 || k->expires > NOW)
145 pippijn 1.4 phandler->unkline_sts ("*", k->user, k->host);
146 pippijn 1.1
147 pippijn 1.5 k->destroy ();
148 pippijn 1.1 }
149    
150     kline_t *
151 pippijn 1.5 kline_t::find (char const * const user, char const * const host)
152 pippijn 1.1 {
153     kline_t *k;
154 pippijn 1.5 list_type::iterator klit = list.begin ();
155     list_type::iterator klet = list.end ();
156 pippijn 1.1
157 pippijn 1.4 while (klit != klet)
158 pippijn 1.1 {
159     k = *klit;
160    
161     if ((!match (k->user, user)) && (!match (k->host, host)))
162     return k;
163 pippijn 1.4
164     ++klit;
165 pippijn 1.1 }
166    
167     return NULL;
168     }
169    
170     kline_t *
171 pippijn 1.5 kline_t::find (unsigned int number)
172 pippijn 1.1 {
173     kline_t *k;
174 pippijn 1.5 list_type::iterator klit = list.begin ();
175     list_type::iterator klet = list.end ();
176 pippijn 1.1
177 pippijn 1.4 while (klit != klet)
178 pippijn 1.1 {
179     k = *klit;
180    
181     if (k->number == number)
182     return k;
183 pippijn 1.4
184     ++klit;
185 pippijn 1.1 }
186    
187     return NULL;
188     }
189    
190     kline_t *
191 pippijn 1.5 kline_t::find (user_t *u)
192 pippijn 1.1 {
193     kline_t *k;
194 pippijn 1.5 list_type::iterator klit = list.begin ();
195     list_type::iterator klet = list.end ();
196 pippijn 1.1
197 pippijn 1.4 while (klit != klet)
198 pippijn 1.1 {
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 pippijn 1.4 ++klit;
206 pippijn 1.1 }
207    
208     return NULL;
209     }
210    
211     void
212 pippijn 1.5 kline_t::expire (void *arg)
213 pippijn 1.1 {
214     kline_t *k;
215     std::vector<kline_t *> mortals;
216 pippijn 1.5 list_type::iterator klit = list.begin ();
217     list_type::iterator klet = list.end ();
218 pippijn 1.1
219 pippijn 1.4 while (klit != klet)
220 pippijn 1.1 {
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 pippijn 1.4
235     ++klit;
236 pippijn 1.1 }
237    
238     // We have to do this because we cannot destroy klines while iterating
239     while (!mortals.empty ())
240     {
241 pippijn 1.5 mortals.back ()->destroy ();
242 pippijn 1.1 mortals.pop_back ();
243     }
244     }