13592
|
1 /*
|
|
2 * Gaim'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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
19 */
|
|
20
|
|
21 #include "oscar.h"
|
|
22
|
|
23 typedef struct _SnacHandler SnacHandler;
|
|
24
|
|
25 struct _SnacHandler
|
|
26 {
|
|
27 guint16 family;
|
|
28 guint16 type;
|
|
29 aim_rxcallback_t handler;
|
|
30 guint16 flags;
|
|
31 };
|
|
32
|
|
33 static void
|
|
34 oscar_free_buddyinfo(void *data)
|
|
35 {
|
|
36 struct buddyinfo *bi = data;
|
|
37 g_free(bi);
|
|
38 }
|
|
39
|
|
40 /**
|
|
41 * Allocates a new OscarData and initializes it with default values.
|
|
42 */
|
|
43 OscarData *
|
|
44 oscar_data_new(void)
|
|
45 {
|
|
46 OscarData *od;
|
|
47
|
|
48 od = g_new0(OscarData, 1);
|
|
49
|
|
50 aim_initsnachash(od);
|
|
51 od->snacid_next = 0x00000001;
|
|
52 od->buddyinfo = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, oscar_free_buddyinfo);
|
|
53
|
|
54 /*
|
|
55 * Register all the modules for this session...
|
|
56 */
|
|
57 aim__registermodule(od, misc_modfirst); /* load the catch-all first */
|
|
58 aim__registermodule(od, service_modfirst);
|
|
59 aim__registermodule(od, locate_modfirst);
|
|
60 aim__registermodule(od, buddylist_modfirst);
|
|
61 aim__registermodule(od, msg_modfirst);
|
|
62 aim__registermodule(od, adverts_modfirst);
|
|
63 aim__registermodule(od, invite_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, translate_modfirst);
|
|
70 aim__registermodule(od, chatnav_modfirst);
|
|
71 aim__registermodule(od, chat_modfirst);
|
|
72 aim__registermodule(od, odir_modfirst);
|
|
73 aim__registermodule(od, bart_modfirst);
|
|
74 /* missing 0x11 - 0x12 */
|
|
75 aim__registermodule(od, ssi_modfirst);
|
|
76 /* missing 0x14 */
|
|
77 aim__registermodule(od, icq_modfirst);
|
|
78 /* missing 0x16 */
|
|
79 aim__registermodule(od, auth_modfirst);
|
|
80 aim__registermodule(od, email_modfirst);
|
|
81
|
|
82 return od;
|
|
83 }
|
|
84
|
|
85 /**
|
|
86 * Logoff and deallocate a session.
|
|
87 *
|
|
88 * @param od Session to kill
|
|
89 */
|
|
90 void
|
|
91 oscar_data_destroy(OscarData *od)
|
|
92 {
|
|
93 aim_cleansnacs(od, -1);
|
|
94
|
13597
|
95 while (od->requesticon)
|
|
96 {
|
|
97 gchar *sn = od->requesticon->data;
|
|
98 od->requesticon = g_slist_remove(od->requesticon, sn);
|
|
99 g_free(sn);
|
|
100 }
|
|
101 g_free(od->email);
|
|
102 g_free(od->newp);
|
|
103 g_free(od->oldp);
|
|
104 if (od->icontimer > 0)
|
|
105 gaim_timeout_remove(od->icontimer);
|
|
106 if (od->getblisttimer > 0)
|
|
107 gaim_timeout_remove(od->getblisttimer);
|
|
108 if (od->getinfotimer > 0)
|
|
109 gaim_timeout_remove(od->getinfotimer);
|
13592
|
110 while (od->oscar_connections != NULL)
|
|
111 flap_connection_destroy(od->oscar_connections->data);
|
|
112
|
|
113 while (od->peer_connections != NULL)
|
|
114 peer_connection_destroy(od->peer_connections->data,
|
|
115 PEER_DISCONNECT_LOCAL_CLOSED);
|
|
116
|
|
117 if (od->handlerlist != NULL)
|
|
118 aim_clearhandlers(od);
|
|
119
|
|
120 aim__shutdownmodules(od);
|
|
121
|
|
122 g_hash_table_destroy(od->buddyinfo);
|
|
123
|
|
124 g_free(od);
|
|
125 }
|
|
126
|
13597
|
127 int
|
|
128 oscar_data_addhandler(OscarData *od, guint16 family, guint16 type, aim_rxcallback_t newhandler, guint16 flags)
|
13592
|
129 {
|
|
130 SnacHandler *snac_handler;
|
|
131
|
|
132 gaim_debug_misc("oscar", "Adding handler for %04x/%04x\n", family, type);
|
|
133
|
|
134 snac_handler = g_new0(SnacHandler, 1);
|
|
135
|
|
136 snac_handler->family = family;
|
|
137 snac_handler->type = type;
|
|
138 snac_handler->flags = flags;
|
|
139 snac_handler->handler = newhandler;
|
|
140
|
|
141 od->handlerlist = g_list_prepend(od->handlerlist, snac_handler);
|
|
142
|
|
143 return 0;
|
|
144 }
|
|
145
|
|
146 void
|
|
147 aim_clearhandlers(OscarData *od)
|
|
148 {
|
|
149 SnacHandler *snac_handler;
|
|
150
|
|
151 while (od->handlerlist != NULL)
|
|
152 {
|
|
153 snac_handler = od->handlerlist->data;
|
|
154 od->handlerlist = g_list_remove(od->handlerlist, snac_handler);
|
|
155 g_free(snac_handler);
|
|
156 }
|
|
157 od->handlerlist = NULL;
|
|
158 }
|
|
159
|
|
160 aim_rxcallback_t
|
|
161 aim_callhandler(OscarData *od, guint16 family, guint16 type)
|
|
162 {
|
|
163 GList *cur;
|
|
164 SnacHandler *snac_handler;
|
|
165
|
|
166 for (cur = od->handlerlist; cur != NULL; cur = cur->next)
|
|
167 {
|
|
168 snac_handler = cur->data;
|
|
169 if ((snac_handler->family == family) && (snac_handler->type == type))
|
|
170 return snac_handler->handler;
|
|
171 }
|
|
172
|
|
173 return NULL;
|
|
174 }
|