… | |
… | |
8 | * Portions of this file were derived from sources bearing the following license: |
8 | * Portions of this file were derived from sources bearing the following license: |
9 | * Rights to this code are documented in doc/pod/license.pod. |
9 | * Rights to this code are documented in doc/pod/license.pod. |
10 | * Copyright © 2005-2007 Atheme Project (http://www.atheme.org) |
10 | * Copyright © 2005-2007 Atheme Project (http://www.atheme.org) |
11 | */ |
11 | */ |
12 | |
12 | |
13 | static char const rcsid[] = "$Id: servers.C,v 1.6 2007/09/16 18:54:45 pippijn Exp $"; |
13 | static char const rcsid[] = "$Id: servers.C,v 1.7 2007/09/22 14:27:30 pippijn Exp $"; |
|
|
14 | |
|
|
15 | #include <boost/foreach.hpp> |
14 | |
16 | |
15 | #include "atheme.h" |
17 | #include "atheme.h" |
|
|
18 | #include <libermyth.h> |
16 | #include "servers.h" |
19 | #include "servers.h" |
17 | #include <account/myuser.h> |
20 | #include <account/myuser.h> |
|
|
21 | #include <util/predicates.h> |
18 | |
22 | |
19 | typedef std::pair<char const * const, server_t *> server_pair; |
23 | typedef std::pair<char const * const, server_t *> server_pair; |
20 | typedef std::map<char const * const, server_t *, irccase_lt> server_map; |
24 | typedef std::map<char const * const, server_t *, irccase_lt> server_map; |
21 | server_map sidlist; |
25 | server_map sidlist; |
22 | server_map servlist; |
26 | server_map servlist; |
23 | list_t tldlist; |
27 | tld_t::list_type tld_t::list; |
24 | server_t::callbacks server_t::callback; |
28 | server_t::callbacks server_t::callback; |
25 | |
29 | |
26 | /* |
30 | /* |
27 | * init_servers() |
31 | * init_servers() |
28 | * |
32 | * |
… | |
… | |
271 | */ |
275 | */ |
272 | tld_t * |
276 | tld_t * |
273 | tld_add (char const * const name) |
277 | tld_add (char const * const name) |
274 | { |
278 | { |
275 | tld_t *tld; |
279 | tld_t *tld; |
276 | node_t *n = node_create (); |
|
|
277 | |
280 | |
278 | slog (LG_DEBUG, "tld_add(): %s", name); |
281 | slog (LG_DEBUG, "tld_add(): %s", name); |
279 | |
282 | |
280 | tld = new tld_t; |
283 | tld = new tld_t; |
281 | |
284 | |
282 | node_add (tld, n, &tldlist); |
285 | tld_t::list.insert (tld); |
283 | |
286 | |
284 | tld->name = sstrdup (name); |
287 | tld->name = sstrdup (name); |
285 | |
288 | |
286 | cnt.tld++; |
289 | cnt.tld++; |
287 | |
290 | |
… | |
… | |
301 | * |
304 | * |
302 | * Side Effects: |
305 | * Side Effects: |
303 | * - the TLD object is removed and deregistered from the TLD list. |
306 | * - the TLD object is removed and deregistered from the TLD list. |
304 | */ |
307 | */ |
305 | void |
308 | void |
306 | tld_delete (char const * const name) |
309 | tld_delete (tld_t *tld) |
307 | { |
310 | { |
308 | tld_t *tld = tld_find (name); |
|
|
309 | node_t *n; |
|
|
310 | |
|
|
311 | if (!tld) |
|
|
312 | { |
|
|
313 | slog (LG_DEBUG, "tld_delete(): called for nonexistant tld: %s", name); |
|
|
314 | |
|
|
315 | return; |
|
|
316 | } |
|
|
317 | |
|
|
318 | slog (LG_DEBUG, "tld_delete(): %s", tld->name); |
311 | slog (LG_DEBUG, "tld_delete(): %s", tld->name); |
319 | |
312 | |
320 | n = node_find (tld, &tldlist); |
313 | tld_t::list.erase (tld); |
321 | node_del (n, &tldlist); |
|
|
322 | node_free (n); |
|
|
323 | |
314 | |
324 | sfree (tld->name); |
315 | sfree (tld->name); |
325 | delete tld; |
316 | delete tld; |
326 | |
317 | |
327 | cnt.tld--; |
318 | cnt.tld--; |
328 | } |
319 | } |
329 | |
320 | |
|
|
321 | void |
|
|
322 | tld_delete (char const * const name) |
|
|
323 | { |
|
|
324 | tld_t *tld = tld_find (name); |
|
|
325 | |
|
|
326 | if (!tld) |
|
|
327 | { |
|
|
328 | slog (LG_DEBUG, "tld_delete(): called for nonexistant tld: %s", name); |
|
|
329 | |
|
|
330 | return; |
|
|
331 | } |
|
|
332 | |
|
|
333 | tld_delete (tld); |
|
|
334 | } |
|
|
335 | |
330 | /* |
336 | /* |
331 | * tld_find(char const * const name) |
337 | * tld_find(char const * const name) |
332 | * |
338 | * |
333 | * Looks up a TLD object. |
339 | * Looks up a TLD object. |
334 | * |
340 | * |
… | |
… | |
343 | * - none |
349 | * - none |
344 | */ |
350 | */ |
345 | tld_t * |
351 | tld_t * |
346 | tld_find (char const * const name) |
352 | tld_find (char const * const name) |
347 | { |
353 | { |
348 | tld_t *tld; |
|
|
349 | node_t *n; |
|
|
350 | |
|
|
351 | if (name == NULL) |
354 | if (name == NULL) |
352 | return NULL; |
355 | return NULL; |
353 | |
356 | |
354 | LIST_FOREACH (n, tldlist.head) |
357 | foreach (tld_t *tld, tld_t::list) |
355 | { |
|
|
356 | tld = (tld_t *) n->data; |
|
|
357 | |
|
|
358 | if (!strcasecmp (name, tld->name)) |
358 | if (!strcasecmp (name, tld->name)) |
359 | return tld; |
359 | return tld; |
360 | } |
|
|
361 | |
360 | |
362 | return NULL; |
361 | return NULL; |
363 | } |
362 | } |
364 | |
363 | |
365 | /* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs |
364 | void |
366 | * vim:ts=8 |
365 | tld_cleanup () |
367 | * vim:sw=8 |
366 | { |
368 | * vim:noexpandtab |
367 | tld_t *tld; |
369 | */ |
368 | |
|
|
369 | while (!tld_t::list.empty ()) |
|
|
370 | { |
|
|
371 | tld = tld_t::list.back (); |
|
|
372 | sfree (tld->name); |
|
|
373 | delete tld; |
|
|
374 | |
|
|
375 | tld_t::list.pop_back (); |
|
|
376 | } |
|
|
377 | } |