1 | /* |
1 | /* |
2 | * uplink.C: Uplink management. |
2 | * uplink.C: Uplink management. |
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 | |
8 | static char const rcsid[] = "$Id: uplink.C,v 1.3 2007/07/21 13:23:22 pippijn Exp $"; |
8 | static char const rcsid[] = "$Id: uplink.C,v 1.4 2007/08/28 17:08:12 pippijn Exp $"; |
9 | |
9 | |
10 | #include "atheme.h" |
10 | #include "atheme.h" |
11 | #include "datastream.h" |
11 | #include "datastream.h" |
12 | #include "uplink.h" |
12 | #include "uplink.h" |
13 | |
13 | |
14 | list_t uplinks; |
14 | list_t uplinks; |
15 | uplink_t *curr_uplink; |
15 | uplink_t *curr_uplink; |
16 | |
16 | |
17 | static BlockHeap *uplink_heap; |
|
|
18 | |
|
|
19 | static void uplink_close (connection_t *cptr); |
17 | static void uplink_close (connection_t *cptr); |
20 | |
18 | |
21 | void |
19 | void |
22 | init_uplinks (void) |
20 | init_uplinks (void) |
23 | { |
21 | { |
|
|
22 | #if 0 |
24 | uplink_heap = BlockHeapCreate (sizeof (uplink_t), 4); |
23 | uplink_heap = BlockHeapCreate (sizeof (uplink_t), 4); |
25 | if (!uplink_heap) |
24 | #endif |
26 | { |
|
|
27 | slog (LG_INFO, "init_uplinks(): block allocator failed."); |
|
|
28 | exit (EXIT_FAILURE); |
|
|
29 | } |
|
|
30 | } |
25 | } |
31 | |
26 | |
32 | uplink_t * |
27 | uplink_t * |
33 | uplink_add (char *name, char *host, char *password, char *vhost, int port) |
28 | uplink_add (char *name, char *host, char *password, char *vhost, int port) |
34 | { |
29 | { |
… | |
… | |
40 | if ((u = uplink_find (name))) |
35 | if ((u = uplink_find (name))) |
41 | { |
36 | { |
42 | if (u->flags & UPF_ILLEGAL) |
37 | if (u->flags & UPF_ILLEGAL) |
43 | { |
38 | { |
44 | u->flags &= ~UPF_ILLEGAL; |
39 | u->flags &= ~UPF_ILLEGAL; |
45 | free (u->name); |
40 | sfree (u->name); |
46 | free (u->host); |
41 | sfree (u->host); |
47 | free (u->pass); |
42 | sfree (u->pass); |
48 | free (u->vhost); |
43 | sfree (u->vhost); |
49 | } |
44 | } |
50 | else |
45 | else |
51 | { |
46 | { |
52 | slog (LG_INFO, "Duplicate uplink %s.", name); |
47 | slog (LG_INFO, "Duplicate uplink %s.", name); |
53 | return NULL; |
48 | return NULL; |
54 | } |
49 | } |
55 | } |
50 | } |
56 | else |
51 | else |
57 | { |
52 | { |
58 | u = static_cast<uplink_t *> (BlockHeapAlloc (uplink_heap)); |
53 | u = new uplink_t; |
59 | n = node_create (); |
54 | n = node_create (); |
60 | u->node = n; |
55 | u->node = n; |
61 | node_add (u, n, &uplinks); |
56 | node_add (u, n, &uplinks); |
62 | cnt.uplink++; |
57 | cnt.uplink++; |
63 | } |
58 | } |
… | |
… | |
77 | void |
72 | void |
78 | uplink_delete (uplink_t *u) |
73 | uplink_delete (uplink_t *u) |
79 | { |
74 | { |
80 | node_t *n = node_find (u, &uplinks); |
75 | node_t *n = node_find (u, &uplinks); |
81 | |
76 | |
82 | free (u->name); |
77 | sfree (u->name); |
83 | free (u->host); |
78 | sfree (u->host); |
84 | free (u->pass); |
79 | sfree (u->pass); |
85 | free (u->vhost); |
80 | sfree (u->vhost); |
86 | |
81 | |
87 | node_del (n, &uplinks); |
82 | node_del (n, &uplinks); |
88 | node_free (n); |
83 | node_free (n); |
89 | |
84 | |
90 | BlockHeapFree (uplink_heap, u); |
85 | delete u; |
91 | cnt.uplink--; |
86 | cnt.uplink--; |
92 | } |
87 | } |
93 | |
88 | |
94 | uplink_t * |
89 | uplink_t * |
95 | uplink_find (char *name) |
90 | uplink_find (char *name) |