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

# 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.6 static char const rcsid[] = "$Id: node.C,v 1.5 2007-09-09 20:05:52 pippijn Exp $";
14 pippijn 1.1
15     #include "atheme.h"
16 pippijn 1.5 #include "servers.h"
17 pippijn 1.1 #include <account/kline.h>
18     #include "uplink.h"
19     #include "privs.h"
20    
21 pippijn 1.5 kline_t::list_type kline_t::list;
22 pippijn 1.1
23     /*************
24     * L I S T S *
25     *************/
26    
27     void
28     init_nodes (void)
29     {
30 pippijn 1.4 #if 0
31 pippijn 1.1 kline_heap = BlockHeapCreate (sizeof (kline_t), 16);
32 pippijn 1.4 #endif
33 pippijn 1.1
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 pippijn 1.5 kline_t::create (char const * const user, char const * const host, char const * const reason, long duration)
107 pippijn 1.1 {
108     kline_t *k;
109     static unsigned int kcnt = 0;
110    
111 pippijn 1.5 slog (LG_DEBUG, "kline_t::create(): %s@%s -> %s (%ld)", user, host, reason, duration);
112 pippijn 1.1
113 pippijn 1.4 k = new kline_t;
114 pippijn 1.1
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 pippijn 1.5 list.push_back (k);
124 pippijn 1.1
125     cnt.kline++;
126    
127 pippijn 1.4 phandler->kline_sts ("*", user, host, duration, reason);
128 pippijn 1.1
129     return k;
130     }
131    
132     void
133 pippijn 1.5 kline_t::destroy (char const * const user, char const * const host)
134 pippijn 1.1 {
135 pippijn 1.5 kline_t *k = find (user, host);
136 pippijn 1.1
137     if (!k)
138     {
139 pippijn 1.5 slog (LG_DEBUG, "kline_t::destroy(): called for nonexistant kline: %s@%s", user, host);
140 pippijn 1.1
141     return;
142     }
143    
144 pippijn 1.5 slog (LG_DEBUG, "kline_t::destroy(): %s@%s -> %s", k->user, k->host, k->reason);
145 pippijn 1.1 /* only unkline if ircd has not already removed this -- jilles */
146     if (k->duration == 0 || k->expires > NOW)
147 pippijn 1.4 phandler->unkline_sts ("*", k->user, k->host);
148 pippijn 1.1
149 pippijn 1.5 k->destroy ();
150 pippijn 1.1 }
151    
152     kline_t *
153 pippijn 1.5 kline_t::find (char const * const user, char const * const host)
154 pippijn 1.1 {
155     kline_t *k;
156 pippijn 1.5 list_type::iterator klit = list.begin ();
157     list_type::iterator klet = list.end ();
158 pippijn 1.1
159 pippijn 1.4 while (klit != klet)
160 pippijn 1.1 {
161     k = *klit;
162    
163     if ((!match (k->user, user)) && (!match (k->host, host)))
164     return k;
165 pippijn 1.4
166     ++klit;
167 pippijn 1.1 }
168    
169     return NULL;
170     }
171    
172     kline_t *
173 pippijn 1.5 kline_t::find (unsigned int number)
174 pippijn 1.1 {
175     kline_t *k;
176 pippijn 1.5 list_type::iterator klit = list.begin ();
177     list_type::iterator klet = list.end ();
178 pippijn 1.1
179 pippijn 1.4 while (klit != klet)
180 pippijn 1.1 {
181     k = *klit;
182    
183     if (k->number == number)
184     return k;
185 pippijn 1.4
186     ++klit;
187 pippijn 1.1 }
188    
189     return NULL;
190     }
191    
192     kline_t *
193 pippijn 1.5 kline_t::find (user_t *u)
194 pippijn 1.1 {
195     kline_t *k;
196 pippijn 1.5 list_type::iterator klit = list.begin ();
197     list_type::iterator klet = list.end ();
198 pippijn 1.1
199 pippijn 1.4 while (klit != klet)
200 pippijn 1.1 {
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 pippijn 1.4 ++klit;
208 pippijn 1.1 }
209    
210     return NULL;
211     }
212    
213     void
214 pippijn 1.5 kline_t::expire (void *arg)
215 pippijn 1.1 {
216     kline_t *k;
217     std::vector<kline_t *> mortals;
218 pippijn 1.5 list_type::iterator klit = list.begin ();
219     list_type::iterator klet = list.end ();
220 pippijn 1.1
221 pippijn 1.4 while (klit != klet)
222 pippijn 1.1 {
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 pippijn 1.4
237     ++klit;
238 pippijn 1.1 }
239    
240     // We have to do this because we cannot destroy klines while iterating
241     while (!mortals.empty ())
242     {
243 pippijn 1.5 mortals.back ()->destroy ();
244 pippijn 1.1 mortals.pop_back ();
245     }
246     }