ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/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

# User Rev Content
1 pippijn 1.1 /*
2     * node.C: Data structure management.
3 pippijn 1.2 * Rights to this code are documented in doc/pod/license.pod.
4 pippijn 1.1 *
5 pippijn 1.4 * Copyright © 2005-2007 Atheme Project (http://www.atheme.org)
6 pippijn 1.1 */
7    
8 pippijn 1.5 static char const rcsid[] = "$Id: node.C,v 1.4 2007-08-28 17:08:12 pippijn Exp $";
9 pippijn 1.1
10     #include "atheme.h"
11 pippijn 1.5 #include "servers.h"
12 pippijn 1.1 #include <account/kline.h>
13     #include "uplink.h"
14     #include "privs.h"
15    
16 pippijn 1.5 kline_t::list_type kline_t::list;
17 pippijn 1.1
18     /*************
19     * L I S T S *
20     *************/
21    
22     void
23     init_nodes (void)
24     {
25 pippijn 1.4 #if 0
26 pippijn 1.1 kline_heap = BlockHeapCreate (sizeof (kline_t), 16);
27 pippijn 1.4 #endif
28 pippijn 1.1
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 pippijn 1.5 kline_t::create (char const * const user, char const * const host, char const * const reason, long duration)
102 pippijn 1.1 {
103     kline_t *k;
104     static unsigned int kcnt = 0;
105    
106 pippijn 1.5 slog (LG_DEBUG, "kline_t::create(): %s@%s -> %s (%ld)", user, host, reason, duration);
107 pippijn 1.1
108 pippijn 1.4 k = new kline_t;
109 pippijn 1.1
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 pippijn 1.5 list.push_back (k);
119 pippijn 1.1
120     cnt.kline++;
121    
122 pippijn 1.4 phandler->kline_sts ("*", user, host, duration, reason);
123 pippijn 1.1
124     return k;
125     }
126    
127     void
128 pippijn 1.5 kline_t::destroy (char const * const user, char const * const host)
129 pippijn 1.1 {
130 pippijn 1.5 kline_t *k = find (user, host);
131 pippijn 1.1
132     if (!k)
133     {
134 pippijn 1.5 slog (LG_DEBUG, "kline_t::destroy(): called for nonexistant kline: %s@%s", user, host);
135 pippijn 1.1
136     return;
137     }
138    
139 pippijn 1.5 slog (LG_DEBUG, "kline_t::destroy(): %s@%s -> %s", k->user, k->host, k->reason);
140 pippijn 1.1 /* only unkline if ircd has not already removed this -- jilles */
141     if (k->duration == 0 || k->expires > NOW)
142 pippijn 1.4 phandler->unkline_sts ("*", k->user, k->host);
143 pippijn 1.1
144 pippijn 1.5 k->destroy ();
145 pippijn 1.1 }
146    
147     kline_t *
148 pippijn 1.5 kline_t::find (char const * const user, char const * const host)
149 pippijn 1.1 {
150     kline_t *k;
151 pippijn 1.5 list_type::iterator klit = list.begin ();
152     list_type::iterator klet = list.end ();
153 pippijn 1.1
154 pippijn 1.4 while (klit != klet)
155 pippijn 1.1 {
156     k = *klit;
157    
158     if ((!match (k->user, user)) && (!match (k->host, host)))
159     return k;
160 pippijn 1.4
161     ++klit;
162 pippijn 1.1 }
163    
164     return NULL;
165     }
166    
167     kline_t *
168 pippijn 1.5 kline_t::find (unsigned int number)
169 pippijn 1.1 {
170     kline_t *k;
171 pippijn 1.5 list_type::iterator klit = list.begin ();
172     list_type::iterator klet = list.end ();
173 pippijn 1.1
174 pippijn 1.4 while (klit != klet)
175 pippijn 1.1 {
176     k = *klit;
177    
178     if (k->number == number)
179     return k;
180 pippijn 1.4
181     ++klit;
182 pippijn 1.1 }
183    
184     return NULL;
185     }
186    
187     kline_t *
188 pippijn 1.5 kline_t::find (user_t *u)
189 pippijn 1.1 {
190     kline_t *k;
191 pippijn 1.5 list_type::iterator klit = list.begin ();
192     list_type::iterator klet = list.end ();
193 pippijn 1.1
194 pippijn 1.4 while (klit != klet)
195 pippijn 1.1 {
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 pippijn 1.4 ++klit;
203 pippijn 1.1 }
204    
205     return NULL;
206     }
207    
208     void
209 pippijn 1.5 kline_t::expire (void *arg)
210 pippijn 1.1 {
211     kline_t *k;
212     std::vector<kline_t *> mortals;
213 pippijn 1.5 list_type::iterator klit = list.begin ();
214     list_type::iterator klet = list.end ();
215 pippijn 1.1
216 pippijn 1.4 while (klit != klet)
217 pippijn 1.1 {
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 pippijn 1.4
232     ++klit;
233 pippijn 1.1 }
234    
235     // We have to do this because we cannot destroy klines while iterating
236     while (!mortals.empty ())
237     {
238 pippijn 1.5 mortals.back ()->destroy ();
239 pippijn 1.1 mortals.pop_back ();
240     }
241     }