ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/src/servers.C
(Generate patch)

Comparing ermyth/src/servers.C (file contents):
Revision 1.3 by pippijn, Sat Jul 21 13:23:22 2007 UTC vs.
Revision 1.4 by pippijn, Tue Aug 28 17:08:12 2007 UTC

1/* 1/*
2 * servers.C: Server and network state tracking. 2 * servers.C: Server and network state tracking.
3 * Rights to this code are documented in doc/pod/license.pod. 3 * Rights to this code are documented in doc/pod/license.pod.
4 * 4 *
5 * Copyright © 2005-2007 Atheme Project (http://www.atheme.org) 5 * Copyright © 2005-2007 Atheme Project (http://www.atheme.org)
6 */ 6 */
7 7
8static char const rcsid[] = "$Id: servers.C,v 1.3 2007/07/21 13:23:22 pippijn Exp $"; 8static char const rcsid[] = "$Id: servers.C,v 1.4 2007/08/28 17:08:12 pippijn Exp $";
9 9
10#include "atheme.h" 10#include "atheme.h"
11#include <account/myuser.h> 11#include <account/myuser.h>
12 12
13dictionary_tree_t *sidlist; 13typedef std::pair<char const * const, server_t *> server_pair;
14dictionary_tree_t *servlist; 14typedef std::map<char const * const, server_t *, irccase_lt> server_map;
15server_map sidlist;
16server_map servlist;
15list_t tldlist; 17list_t tldlist;
16 18server_t::callbacks server_t::callback;
17static BlockHeap *serv_heap;
18static BlockHeap *tld_heap;
19 19
20/* 20/*
21 * init_servers() 21 * init_servers()
22 * 22 *
23 * Initializes the server heap and server/sid DTree structures. 23 * Initializes the server heap and server/sid DTree structures.
33 * will abort. 33 * will abort.
34 */ 34 */
35void 35void
36init_servers (void) 36init_servers (void)
37{ 37{
38#if 0
38 serv_heap = BlockHeapCreate (sizeof (server_t), HEAP_SERVER); 39 serv_heap = BlockHeapCreate (sizeof (server_t), HEAP_SERVER);
39 tld_heap = BlockHeapCreate (sizeof (tld_t), 4); 40 tld_heap = BlockHeapCreate (sizeof (tld_t), 4);
40 41#endif
41 if (serv_heap == NULL || tld_heap == NULL)
42 {
43 slog (LG_INFO, "init_servers(): block allocator failure.");
44 exit (EXIT_FAILURE);
45 }
46
47 servlist = dictionary_create ("server", HASH_SERVER, irccasecmp);
48 sidlist = dictionary_create ("sid", HASH_SERVER, strcmp);
49} 42}
50 43
51/* 44/*
52 * server_add(const char *name, unsigned int hops, const char *uplink, 45 * server_add(char const * const name, unsigned int hops, char const * const uplink,
53 * const char *id, const char *desc) 46 * char const * const id, char const * const desc)
54 * 47 *
55 * Server object factory. 48 * Server object factory.
56 * 49 *
57 * Inputs: 50 * Inputs:
58 * - name of server object to create 51 * - name of server object to create
66 * 59 *
67 * Side Effects: 60 * Side Effects:
68 * - the new server object is added to the server and sid DTree. 61 * - the new server object is added to the server and sid DTree.
69 */ 62 */
70server_t * 63server_t *
71server_add (const char *name, unsigned int hops, const char *uplink, const char *id, const char *desc) 64server_add (char const * const name, unsigned int hops, char const * const uplink, char const * const id, char const * const description)
72{ 65{
73 server_t *s, *u = NULL; 66 server_t *s, *u = NULL;
74 const char *tld; 67 char const *tld;
68 char const *desc = description;
75 69
76 if (uplink) 70 if (uplink)
77 { 71 {
78 if (id != NULL) 72 if (id != NULL)
79 slog (LG_NETWORK, "server_add(): %s (%s), uplink %s", name, id, uplink); 73 slog (LG_NETWORK, "server_add(): %s (%s), uplink %s", name, id, uplink);
82 u = server_find (uplink); 76 u = server_find (uplink);
83 } 77 }
84 else 78 else
85 slog (LG_DEBUG, "server_add(): %s, root", name); 79 slog (LG_DEBUG, "server_add(): %s, root", name);
86 80
87 s = static_cast<server_t *> (BlockHeapAlloc (serv_heap)); 81 s = new server_t;
88 82
89 if (id != NULL) 83 if (id != NULL)
90 { 84 {
91 s->sid = sstrdup (id); 85 s->sid = sstrdup (id);
92 dictionary_add (sidlist, s->sid, s); 86 sidlist[s->sid] = s;
93 } 87 }
94 88
95 /* check to see if it's hidden */ 89 /* check to see if it's hidden */
96 if (!strncmp (desc, "(H)", 3)) 90 if (!strncmp (desc, "(H)", 3))
97 { 91 {
104 s->name = sstrdup (name); 98 s->name = sstrdup (name);
105 s->desc = sstrdup (desc); 99 s->desc = sstrdup (desc);
106 s->hops = hops; 100 s->hops = hops;
107 s->connected_since = NOW; 101 s->connected_since = NOW;
108 102
109 dictionary_add (servlist, s->name, s); 103 servlist[s->name] = s;
110 104
111 if (u) 105 if (u)
112 { 106 {
113 s->uplink = u; 107 s->uplink = u;
114 node_add (s, node_create (), &u->children); 108 node_add (s, node_create (), &u->children);
127 121
128 return s; 122 return s;
129} 123}
130 124
131/* 125/*
132 * server_delete(const char *name) 126 * server_delete(char const * const name)
133 * 127 *
134 * Finds and recursively destroys a server object. 128 * Finds and recursively destroys a server object.
135 * 129 *
136 * Inputs: 130 * Inputs:
137 * - name of server to find and destroy 131 * - name of server to find and destroy
141 * 135 *
142 * Side Effects: 136 * Side Effects:
143 * - all users and servers attached to the target are recursively deleted 137 * - all users and servers attached to the target are recursively deleted
144 */ 138 */
145void 139void
146server_delete (const char *name) 140server_delete (char const * const name)
147{ 141{
148 server_t *s = server_find (name); 142 server_t *s = server_find (name);
149 server_t *child; 143 server_t *child;
150 user_t *u; 144 user_t *u;
151 node_t *n, *tn; 145 node_t *n, *tn;
185 child = static_cast<server_t *> (n->data); 179 child = static_cast<server_t *> (n->data);
186 server_delete (child->name); 180 server_delete (child->name);
187 } 181 }
188 182
189 /* now remove the server */ 183 /* now remove the server */
190 dictionary_delete (servlist, s->name); 184 servlist.erase (s->name);
191 185
192 if (s->sid) 186 if (s->sid)
193 dictionary_delete (sidlist, s->sid); 187 sidlist.erase (s->sid);
194 188
195 if (s->uplink) 189 if (s->uplink)
196 { 190 {
197 n = node_find (s, &s->uplink->children); 191 n = node_find (s, &s->uplink->children);
198 node_del (n, &s->uplink->children); 192 node_del (n, &s->uplink->children);
201 195
202 /* If unconnect semantics SQUIT was confirmed, introduce the jupe 196 /* If unconnect semantics SQUIT was confirmed, introduce the jupe
203 * now. This must be after removing the server from the dtrees. 197 * now. This must be after removing the server from the dtrees.
204 * -- jilles */ 198 * -- jilles */
205 if (s->flags & SF_JUPE_PENDING) 199 if (s->flags & SF_JUPE_PENDING)
206 jupe (s->name, "Juped"); 200 phandler->jupe (s->name, "Juped");
207 201
208 free (s->name); 202 sfree (s->name);
209 free (s->desc); 203 sfree (s->desc);
210 if (s->sid) 204 if (s->sid)
211 free (s->sid); 205 sfree (s->sid);
212 206
213 BlockHeapFree (serv_heap, s); 207 delete s;
214 208
215 cnt.server--; 209 cnt.server--;
216} 210}
217 211
218/* 212/*
219 * server_find(const char *name) 213 * server_find(char const * const name)
220 * 214 *
221 * Finds a server object. 215 * Finds a server object.
222 * 216 *
223 * Inputs: 217 * Inputs:
224 * - name of server to find 218 * - name of server to find
229 * 223 *
230 * Side Effects: 224 * Side Effects:
231 * - none 225 * - none
232 */ 226 */
233server_t * 227server_t *
234server_find (const char *name) 228server_find (char const * const name)
235{ 229{
236 server_t *s; 230 server_map::iterator it;
237 231
238 if (ircd->uses_uid) 232 if (ircd->uses_uid)
239 { 233 {
240 s = static_cast<server_t *> (dictionary_retrieve (sidlist, name)); 234 it = sidlist.find (name);
241 if (s != NULL) 235 if (it != sidlist.end ())
242 return s; 236 return it->second;
243 } 237 }
244 238
245 return static_cast<server_t *> (dictionary_retrieve (servlist, name)); 239 return ((it = servlist.find (name)) == servlist.end ()
240 ? NULL
241 : it->second);
246} 242}
247 243
248/* 244/*
249 * tld_add(const char *name) 245 * tld_add(char const * const name)
250 * 246 *
251 * TLD object factory. 247 * TLD object factory.
252 * 248 *
253 * Inputs: 249 * Inputs:
254 * - name of TLD to cache as an object 250 * - name of TLD to cache as an object
259 * 255 *
260 * Side Effects: 256 * Side Effects:
261 * - the TLD object is registered with the TLD list. 257 * - the TLD object is registered with the TLD list.
262 */ 258 */
263tld_t * 259tld_t *
264tld_add (const char *name) 260tld_add (char const * const name)
265{ 261{
266 tld_t *tld; 262 tld_t *tld;
267 node_t *n = node_create (); 263 node_t *n = node_create ();
268 264
269 slog (LG_DEBUG, "tld_add(): %s", name); 265 slog (LG_DEBUG, "tld_add(): %s", name);
270 266
271 tld = static_cast<tld_t *> (BlockHeapAlloc (tld_heap)); 267 tld = new tld_t;
272 268
273 node_add (tld, n, &tldlist); 269 node_add (tld, n, &tldlist);
274 270
275 tld->name = sstrdup (name); 271 tld->name = sstrdup (name);
276 272
278 274
279 return tld; 275 return tld;
280} 276}
281 277
282/* 278/*
283 * tld_delete(const char *name) 279 * tld_delete(char const * const name)
284 * 280 *
285 * Destroys a TLD object. 281 * Destroys a TLD object.
286 * 282 *
287 * Inputs: 283 * Inputs:
288 * - name of TLD object to destroy 284 * - name of TLD object to destroy
292 * 288 *
293 * Side Effects: 289 * Side Effects:
294 * - the TLD object is removed and deregistered from the TLD list. 290 * - the TLD object is removed and deregistered from the TLD list.
295 */ 291 */
296void 292void
297tld_delete (const char *name) 293tld_delete (char const * const name)
298{ 294{
299 tld_t *tld = tld_find (name); 295 tld_t *tld = tld_find (name);
300 node_t *n; 296 node_t *n;
301 297
302 if (!tld) 298 if (!tld)
310 306
311 n = node_find (tld, &tldlist); 307 n = node_find (tld, &tldlist);
312 node_del (n, &tldlist); 308 node_del (n, &tldlist);
313 node_free (n); 309 node_free (n);
314 310
315 free (tld->name); 311 sfree (tld->name);
316 BlockHeapFree (tld_heap, tld); 312 delete tld;
317 313
318 cnt.tld--; 314 cnt.tld--;
319} 315}
320 316
321/* 317/*
322 * tld_find(const char *name) 318 * tld_find(char const * const name)
323 * 319 *
324 * Looks up a TLD object. 320 * Looks up a TLD object.
325 * 321 *
326 * Inputs: 322 * Inputs:
327 * - name of TLD object to look up 323 * - name of TLD object to look up
332 * 328 *
333 * Side Effects: 329 * Side Effects:
334 * - none 330 * - none
335 */ 331 */
336tld_t * 332tld_t *
337tld_find (const char *name) 333tld_find (char const * const name)
338{ 334{
339 tld_t *tld; 335 tld_t *tld;
340 node_t *n; 336 node_t *n;
341 337
342 if (name == NULL) 338 if (name == NULL)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines