libpurple/protocols/oscar/oscar_data.c

changeset 40072
67e558b6711b
parent 40065
3b61e89f42bd
parent 40071
148d89dee247
child 40076
432bd1f3748f
equal deleted inserted replaced
40065:3b61e89f42bd 40072:67e558b6711b
1 /*
2 * Purple's oscar protocol plugin
3 * This file is the legal property of its developers.
4 * Please see the AUTHORS file distributed alongside this file.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
19 */
20
21 #include "oscar.h"
22
23 typedef struct _SnacHandler SnacHandler;
24
25 struct _SnacHandler
26 {
27 guint16 family;
28 guint16 subtype;
29 aim_rxcallback_t handler;
30 guint16 flags;
31 };
32
33 /**
34 * Allocates a new OscarData and initializes it with default values.
35 */
36 OscarData *
37 oscar_data_new(void)
38 {
39 OscarData *od;
40 aim_module_t *cur;
41 GString *msg;
42
43 od = g_new0(OscarData, 1);
44
45 aim_initsnachash(od);
46 od->snacid_next = 0x00000001;
47 od->buddyinfo = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
48 od->handlerlist = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, g_free);
49
50 od->ssi.local.idx_gid_bid = g_hash_table_new(g_direct_hash, g_direct_equal);
51 od->ssi.local.idx_all_named_items = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
52
53 od->ssi.official.idx_gid_bid = g_hash_table_new(g_direct_hash, g_direct_equal);
54 od->ssi.official.idx_all_named_items = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
55
56 /*
57 * Register all the modules for this session...
58 */
59 aim__registermodule(od, misc_modfirst); /* load the catch-all first */
60 aim__registermodule(od, service_modfirst);
61 aim__registermodule(od, locate_modfirst);
62 aim__registermodule(od, buddylist_modfirst);
63 aim__registermodule(od, msg_modfirst);
64 aim__registermodule(od, admin_modfirst);
65 aim__registermodule(od, popups_modfirst);
66 aim__registermodule(od, bos_modfirst);
67 aim__registermodule(od, search_modfirst);
68 aim__registermodule(od, stats_modfirst);
69 aim__registermodule(od, chatnav_modfirst);
70 aim__registermodule(od, chat_modfirst);
71 aim__registermodule(od, bart_modfirst);
72 /* missing 0x11 - 0x12 */
73 aim__registermodule(od, ssi_modfirst);
74 /* missing 0x14 */
75 aim__registermodule(od, icq_modfirst);
76 /* missing 0x16 */
77 /* auth_modfirst is only needed if we're connecting with the old-style BUCP login */
78 aim__registermodule(od, auth_modfirst);
79 aim__registermodule(od, email_modfirst);
80
81 msg = g_string_new("Registered modules: ");
82 for (cur = od->modlistv; cur; cur = cur->next) {
83 g_string_append_printf(
84 msg,
85 "%s (family=0x%04x, version=0x%04x, toolid=0x%04x, toolversion=0x%04x), ",
86 cur->name,
87 cur->family,
88 cur->version,
89 cur->toolid,
90 cur->toolversion);
91 }
92 purple_debug_misc("oscar", "%s\n", msg->str);
93 g_string_free(msg, TRUE);
94
95 return od;
96 }
97
98 /**
99 * Logoff and deallocate a session.
100 *
101 * @param od Session to kill
102 */
103 void
104 oscar_data_destroy(OscarData *od)
105 {
106 aim_cleansnacs(od, -1);
107
108 /* Only used when connecting with clientLogin or Kerberos. */
109 if (od->http_conns) {
110 soup_session_abort(od->http_conns);
111 g_object_unref(od->http_conns);
112 }
113
114 g_slist_free_full(od->requesticon, g_free);
115 g_free(od->email);
116 g_free(od->newp);
117 g_free(od->oldp);
118 if (od->getblisttimer > 0)
119 g_source_remove(od->getblisttimer);
120 while (od->oscar_connections != NULL)
121 flap_connection_destroy(od->oscar_connections->data,
122 OSCAR_DISCONNECT_DONE, NULL);
123
124 while (od->peer_connections != NULL)
125 peer_connection_destroy(od->peer_connections->data,
126 OSCAR_DISCONNECT_LOCAL_CLOSED, NULL);
127
128 aim__shutdownmodules(od);
129
130 g_hash_table_destroy(od->buddyinfo);
131 g_hash_table_destroy(od->handlerlist);
132
133 g_hash_table_destroy(od->ssi.local.idx_gid_bid);
134 g_hash_table_destroy(od->ssi.local.idx_all_named_items);
135
136 g_hash_table_destroy(od->ssi.official.idx_gid_bid);
137 g_hash_table_destroy(od->ssi.official.idx_all_named_items);
138
139 g_free(od);
140 }
141
142 void
143 oscar_data_addhandler(OscarData *od, guint16 family, guint16 subtype, aim_rxcallback_t newhandler, guint16 flags)
144 {
145 SnacHandler *snac_handler;
146
147 snac_handler = g_new0(SnacHandler, 1);
148
149 snac_handler->family = family;
150 snac_handler->subtype = subtype;
151 snac_handler->flags = flags;
152 snac_handler->handler = newhandler;
153
154 g_hash_table_insert(od->handlerlist,
155 GUINT_TO_POINTER((family << 16) + subtype),
156 snac_handler);
157 }
158
159 aim_rxcallback_t
160 aim_callhandler(OscarData *od, guint16 family, guint16 subtype)
161 {
162 SnacHandler *snac_handler;
163
164 snac_handler = g_hash_table_lookup(od->handlerlist, GUINT_TO_POINTER((family << 16) + subtype));
165
166 return snac_handler ? snac_handler->handler : NULL;
167 }

mercurial