ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/src/node.C
Revision: 1.2
Committed: Sat Jul 21 01:29:12 2007 UTC (16 years, 10 months ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.1: +1 -1 lines
Log Message:
- moved to new documentation system
- fixed small build error

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     * Copyright © 2005-2007 Atheme Project (http://www.atheme.org)
6     */
7    
8     static char const rcsid[] = "$Id";
9    
10     #include "atheme.h"
11     #include <account/kline.h>
12     #include "uplink.h"
13     #include "privs.h"
14    
15     kline_vector klnlist;
16    
17     static BlockHeap *kline_heap; /* 16 */
18    
19     /*************
20     * L I S T S *
21     *************/
22    
23     void
24     init_nodes (void)
25     {
26     kline_heap = BlockHeapCreate (sizeof (kline_t), 16);
27    
28     if (kline_heap == NULL)
29     {
30     slog (LG_INFO, "init_nodes(): block allocator failed.");
31     exit (EXIT_FAILURE);
32     }
33    
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     kline_add (char *user, char *host, char *reason, long duration)
107     {
108     kline_t *k;
109     static unsigned int kcnt = 0;
110    
111     slog (LG_DEBUG, "kline_add(): %s@%s -> %s (%ld)", user, host, reason, duration);
112    
113     k = static_cast<kline_t *> (BlockHeapAlloc (kline_heap));
114    
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     klnlist.push_back (k);
124    
125     cnt.kline++;
126    
127     kline_sts ("*", user, host, duration, reason);
128    
129     return k;
130     }
131    
132     void
133     kline_delete (kline_t *k)
134     {
135     klnlist.erase (k);
136    
137     free (k->user);
138     free (k->host);
139     free (k->reason);
140     free (k->setby);
141    
142     BlockHeapFree (kline_heap, k);
143    
144     cnt.kline--;
145     }
146    
147     void
148     kline_delete (const char *user, const char *host)
149     {
150     kline_t *k = kline_find (user, host);
151    
152     if (!k)
153     {
154     slog (LG_DEBUG, "kline_delete(): called for nonexistant kline: %s@%s", user, host);
155    
156     return;
157     }
158    
159     slog (LG_DEBUG, "kline_delete(): %s@%s -> %s", k->user, k->host, k->reason);
160     /* only unkline if ircd has not already removed this -- jilles */
161     if (k->duration == 0 || k->expires > NOW)
162     unkline_sts ("*", k->user, k->host);
163    
164     kline_delete (k);
165     }
166    
167     kline_t *
168     kline_find (const char *user, const char *host)
169     {
170     kline_t *k;
171     kline_vector::iterator klit, klit_end;
172    
173     for (klit = klnlist.begin (), klit_end = klnlist.end (); klit != klit_end; ++klit)
174     {
175     k = *klit;
176    
177     if ((!match (k->user, user)) && (!match (k->host, host)))
178     return k;
179     }
180    
181     return NULL;
182     }
183    
184     kline_t *
185     kline_find_num (unsigned int number)
186     {
187     kline_t *k;
188     kline_vector::iterator klit, klit_end;
189    
190     for (klit = klnlist.begin (), klit_end = klnlist.end (); klit != klit_end; ++klit)
191     {
192     k = *klit;
193    
194     if (k->number == number)
195     return k;
196     }
197    
198     return NULL;
199     }
200    
201     kline_t *
202     kline_find_user (user_t *u)
203     {
204     kline_t *k;
205     kline_vector::iterator klit, klit_end;
206    
207     for (klit = klnlist.begin (), klit_end = klnlist.end (); klit != klit_end; ++klit)
208     {
209     k = *klit;
210    
211     if (k->duration != 0 && k->expires <= NOW)
212     continue;
213     if (!match (k->user, u->user) && (!match (k->host, u->host) || !match (k->host, u->ip) || !match_ips (k->host, u->ip)))
214     return k;
215     }
216    
217     return NULL;
218     }
219    
220     void
221     kline_expire (void *arg)
222     {
223     kline_t *k;
224     std::vector<kline_t *> mortals;
225     kline_vector::iterator klit, klit_end;
226    
227     for (klit = klnlist.begin (), klit_end = klnlist.end (); klit != klit_end; ++klit)
228     {
229     k = *klit;
230    
231     if (k->duration == 0)
232     continue;
233    
234     if (k->expires <= NOW)
235     {
236     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);
237    
238     verbose_wallops (_("AKILL expired on \2%s@%s\2, set by \2%s\2"), k->user, k->host, k->setby);
239    
240     mortals.push_back (k);
241     }
242     }
243    
244     // We have to do this because we cannot destroy klines while iterating
245     while (!mortals.empty ())
246     {
247     k = mortals.back ();
248     kline_delete (k);
249     mortals.pop_back ();
250     }
251     }