ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/ermyth/src/node.C
Revision: 1.4
Committed: Tue Aug 28 17:08:12 2007 UTC (19 years, 1 month ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.3: +34 -29 lines
Log Message:
- changed name
- updated the example config to the new system
- added more documentation
- enhanced documentation generators
- added a link to the pdf to the website
- added an RSS feed generator
- transitioned hooks to c++ callbacks
- did various merges with upstream along the way
- added const where appropriate
- removed the old block allocator
- fixed most memory leaks
- transitioned some dictionaries to std::map
- transitioned some lists to std::vector
- made some free functions members where appropriate
- renamed string to dynstr and added a static string ststr
- use NOW instead of time (NULL) if possible
- completely reworked database backends, crypto handlers and protocol handlers
  to use an object factory
- removed the old module system. ermyth does not do any dynamic loading anymore
- fixed most of the build system
- reworked how protocol commands work

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