Mercurial > pidgin.yaz
annotate src/protocols/sametime/sametime.c @ 12105:d4cd7d443795
[gaim-migrate @ 14402]
trying not to fall behind on sametime fixes
committer: Tailor Script <tailor@pidgin.im>
author | Christopher O'Brien <siege@pidgin.im> |
---|---|
date | Tue, 15 Nov 2005 06:06:47 +0000 |
parents | 980c877bd238 |
children | 40724851e95e |
rev | line source |
---|---|
10977 | 1 |
2 /* | |
3 Meanwhile Protocol Plugin for Gaim | |
4 Adds Lotus Sametime support to Gaim using the Meanwhile library | |
5 | |
6 Copyright (C) 2004 Christopher (siege) O'Brien <siege@preoccupied.net> | |
7 | |
8 This program is free software; you can redistribute it and/or modify | |
9 it under the terms of the GNU General Public License as published by | |
10 the Free Software Foundation; either version 2 of the License, or (at | |
11 your option) any later version. | |
12 | |
13 This program is distributed in the hope that it will be useful, but | |
14 WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 General Public License for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
19 along with this program; if not, write to the Free Software | |
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
21 USA. | |
22 */ | |
23 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
24 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
25 /* system includes */ |
10977 | 26 #include <stdlib.h> |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
27 #include <time.h> |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
28 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
29 /* glib includes */ |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
30 #include <glib.h> |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
31 #include <glib/ghash.h> |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
32 #include <glib/glist.h> |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
33 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
34 /* gaim includes */ |
10977 | 35 #include <internal.h> |
36 #include <gaim.h> | |
37 #include <config.h> | |
38 | |
39 #include <account.h> | |
40 #include <accountopt.h> | |
41 #include <conversation.h> | |
42 #include <debug.h> | |
43 #include <ft.h> | |
44 #include <imgstore.h> | |
45 #include <mime.h> | |
46 #include <notify.h> | |
47 #include <plugin.h> | |
48 #include <privacy.h> | |
49 #include <prpl.h> | |
50 #include <request.h> | |
51 #include <util.h> | |
52 #include <version.h> | |
53 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
54 /* meanwhile includes */ |
10977 | 55 #include <mw_cipher.h> |
56 #include <mw_common.h> | |
57 #include <mw_error.h> | |
58 #include <mw_service.h> | |
59 #include <mw_session.h> | |
60 #include <mw_srvc_aware.h> | |
61 #include <mw_srvc_conf.h> | |
62 #include <mw_srvc_ft.h> | |
63 #include <mw_srvc_im.h> | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
64 #include <mw_srvc_place.h> |
10977 | 65 #include <mw_srvc_resolve.h> |
66 #include <mw_srvc_store.h> | |
67 #include <mw_st_list.h> | |
68 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
69 /* project includes */ |
10977 | 70 #include "sametime.h" |
71 | |
72 | |
73 /* considering that there's no display of this information for prpls, | |
74 I don't know why I even bother providing these. Oh valiant reader, | |
75 I do it all for you. */ | |
76 /* scratch that, I just added it to the prpl options panel */ | |
77 #define PLUGIN_ID "prpl-meanwhile" | |
78 #define PLUGIN_NAME "Sametime" | |
79 #define PLUGIN_SUMMARY "Sametime Protocol Plugin" | |
80 #define PLUGIN_DESC "Open implementation of a Lotus Sametime client" | |
81 #define PLUGIN_AUTHOR "Christopher (siege) O'Brien <siege@preoccupied.net>" | |
82 #define PLUGIN_HOMEPAGE "http://meanwhile.sourceforge.net/" | |
83 | |
84 | |
85 /* plugin preference names */ | |
86 #define MW_PRPL_OPT_BASE "/plugins/prpl/meanwhile" | |
87 #define MW_PRPL_OPT_BLIST_ACTION MW_PRPL_OPT_BASE "/blist_action" | |
88 #define MW_PRPL_OPT_PSYCHIC MW_PRPL_OPT_BASE "/psychic" | |
89 #define MW_PRPL_OPT_FORCE_LOGIN MW_PRPL_OPT_BASE "/force_login" | |
90 #define MW_PRPL_OPT_SAVE_DYNAMIC MW_PRPL_OPT_BASE "/save_dynamic" | |
91 | |
92 | |
93 /* stages of connecting-ness */ | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
94 #define MW_CONNECT_STEPS 9 |
10977 | 95 |
96 | |
97 /* stages of conciousness */ | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
98 #define MW_STATE_OFFLINE "offline" |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
99 #define MW_STATE_ACTIVE "active" |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
100 #define MW_STATE_AWAY "away" |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
101 #define MW_STATE_BUSY "dnd" |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
102 #define MW_STATE_MESSAGE "message" |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
103 #define MW_STATE_ENLIGHTENED "buddha" |
10977 | 104 |
105 | |
106 /* keys to get/set chat information */ | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
107 #define CHAT_KEY_CREATOR "chat.creator" |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
108 #define CHAT_KEY_NAME "chat.name" |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
109 #define CHAT_KEY_TOPIC "chat.topic" |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
110 #define CHAT_KEY_INVITE "chat.invite" |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
111 #define CHAT_KEY_IS_PLACE "chat.is_place" |
10977 | 112 |
113 | |
114 /* key for associating a mwLoginType with a buddy */ | |
115 #define BUDDY_KEY_CLIENT "meanwhile.client" | |
116 | |
117 /* store the remote alias so that we can re-create it easily */ | |
118 #define BUDDY_KEY_NAME "meanwhile.shortname" | |
119 | |
120 /* enum mwSametimeUserType */ | |
121 #define BUDDY_KEY_TYPE "meanwhile.type" | |
122 | |
123 | |
124 /* key for the real group name for a meanwhile group */ | |
125 #define GROUP_KEY_NAME "meanwhile.group" | |
126 | |
127 /* enum mwSametimeGroupType */ | |
128 #define GROUP_KEY_TYPE "meanwhile.type" | |
129 | |
130 /* NAB group owning account */ | |
131 #define GROUP_KEY_OWNER "meanwhile.account" | |
132 | |
133 /* key gtk blist uses to indicate a collapsed group */ | |
134 #define GROUP_KEY_COLLAPSED "collapsed" | |
135 | |
136 | |
11133
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
137 /* verification replacement */ |
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
138 #define mwSession_NO_SECRET "meanwhile.no_secret" |
10977 | 139 |
140 | |
141 /* keys to get/set gaim plugin information */ | |
142 #define MW_KEY_HOST "server" | |
143 #define MW_KEY_PORT "port" | |
144 #define MW_KEY_ACTIVE_MSG "active_msg" | |
145 #define MW_KEY_AWAY_MSG "away_msg" | |
146 #define MW_KEY_BUSY_MSG "busy_msg" | |
147 #define MW_KEY_MSG_PROMPT "msg_prompt" | |
148 #define MW_KEY_INVITE "conf_invite" | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
149 #define MW_KEY_ENCODING "encoding" |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
150 #define MW_KEY_FORCE "force_login" |
10977 | 151 |
152 | |
153 /** number of seconds from the first blist change before a save to the | |
154 storage service occurs. */ | |
155 #define BLIST_SAVE_SECONDS 15 | |
156 | |
157 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
158 /** the possible buddy list storage settings */ |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
159 enum blist_choice { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
160 blist_choice_LOCAL = 1, /**< local only */ |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
161 blist_choice_MERGE = 2, /**< merge from server */ |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
162 blist_choice_STORE = 3, /**< merge from and save to server */ |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
163 blist_choice_SYNCH = 4, /**< sync with server */ |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
164 }; |
10977 | 165 |
166 | |
167 /** the default blist storage option */ | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
168 #define BLIST_CHOICE_DEFAULT blist_choice_SYNCH |
10977 | 169 |
170 | |
171 /* testing for the above */ | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
172 #define BLIST_PREF_IS(n) (gaim_prefs_get_int(MW_PRPL_OPT_BLIST_ACTION)==(n)) |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
173 #define BLIST_PREF_IS_LOCAL() BLIST_PREF_IS(blist_choice_LOCAL) |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
174 #define BLIST_PREF_IS_MERGE() BLIST_PREF_IS(blist_choice_MERGE) |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
175 #define BLIST_PREF_IS_STORE() BLIST_PREF_IS(blist_choice_STORE) |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
176 #define BLIST_PREF_IS_SYNCH() BLIST_PREF_IS(blist_choice_SYNCH) |
10977 | 177 |
178 | |
179 /* debugging output */ | |
180 #define DEBUG_ERROR(a...) gaim_debug_error(G_LOG_DOMAIN, a) | |
181 #define DEBUG_INFO(a...) gaim_debug_info(G_LOG_DOMAIN, a) | |
182 #define DEBUG_MISC(a...) gaim_debug_misc(G_LOG_DOMAIN, a) | |
183 #define DEBUG_WARN(a...) gaim_debug_warning(G_LOG_DOMAIN, a) | |
184 | |
185 | |
186 /** ensure non-null strings */ | |
187 #ifndef NSTR | |
188 # define NSTR(str) ((str)? (str): "(null)") | |
189 #endif | |
190 | |
191 | |
192 /** calibrates distinct secure channel nomenclature */ | |
193 static const unsigned char no_secret[] = { | |
194 0x2d, 0x2d, 0x20, 0x73, 0x69, 0x65, 0x67, 0x65, | |
195 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x73, 0x20, 0x6a, | |
196 0x65, 0x6e, 0x6e, 0x69, 0x20, 0x61, 0x6e, 0x64, | |
197 0x20, 0x7a, 0x6f, 0x65, 0x20, 0x2d, 0x2d, 0x00, | |
198 }; | |
199 | |
200 | |
201 /** handler IDs from g_log_set_handler in mw_plugin_init */ | |
202 static guint log_handler[2] = { 0, 0 }; | |
203 | |
204 | |
205 /** the gaim plugin data. | |
206 available as gc->proto_data and mwSession_getClientData */ | |
207 struct mwGaimPluginData { | |
208 struct mwSession *session; | |
209 | |
210 struct mwServiceAware *srvc_aware; | |
211 struct mwServiceConference *srvc_conf; | |
212 struct mwServiceFileTransfer *srvc_ft; | |
213 struct mwServiceIm *srvc_im; | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
214 struct mwServicePlace *srvc_place; |
10977 | 215 struct mwServiceResolve *srvc_resolve; |
216 struct mwServiceStorage *srvc_store; | |
217 | |
218 /** map of GaimGroup:mwAwareList and mwAwareList:GaimGroup */ | |
219 GHashTable *group_list_map; | |
220 | |
221 /** event id for the buddy list save callback */ | |
222 guint save_event; | |
223 | |
224 /** socket fd */ | |
225 int socket; | |
226 | |
227 GaimConnection *gc; | |
228 }; | |
229 | |
230 | |
231 /* blist and aware functions */ | |
232 | |
233 static void blist_export(GaimConnection *gc, struct mwSametimeList *stlist); | |
234 | |
235 static void blist_store(struct mwGaimPluginData *pd); | |
236 | |
237 static void blist_schedule(struct mwGaimPluginData *pd); | |
238 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
239 static void blist_merge(GaimConnection *gc, struct mwSametimeList *stlist); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
240 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
241 static void blist_sync(GaimConnection *gc, struct mwSametimeList *stlist); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
242 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
243 static gboolean buddy_is_external(GaimBuddy *b); |
10977 | 244 |
245 static void buddy_add(struct mwGaimPluginData *pd, GaimBuddy *buddy); | |
246 | |
247 static GaimBuddy * | |
248 buddy_ensure(GaimConnection *gc, GaimGroup *group, | |
249 struct mwSametimeUser *stuser); | |
250 | |
251 static void group_add(struct mwGaimPluginData *pd, GaimGroup *group); | |
252 | |
253 static GaimGroup * | |
254 group_ensure(GaimConnection *gc, struct mwSametimeGroup *stgroup); | |
255 | |
256 static struct mwAwareList * | |
257 list_ensure(struct mwGaimPluginData *pd, GaimGroup *group); | |
258 | |
259 | |
260 /* session functions */ | |
261 | |
262 static struct mwSession * | |
263 gc_to_session(GaimConnection *gc); | |
264 | |
265 static GaimConnection *session_to_gc(struct mwSession *session); | |
266 | |
267 | |
268 /* conference functions */ | |
269 | |
270 static struct mwConference * | |
271 conf_find_by_id(struct mwGaimPluginData *pd, int id); | |
272 | |
273 | |
274 /* conversation functions */ | |
275 | |
276 struct convo_msg { | |
277 enum mwImSendType type; | |
278 gpointer data; | |
279 GDestroyNotify clear; | |
280 }; | |
281 | |
282 | |
283 struct convo_data { | |
284 struct mwConversation *conv; | |
285 GList *queue; /**< outgoing message queue, list of convo_msg */ | |
286 }; | |
287 | |
288 static void convo_data_new(struct mwConversation *conv); | |
289 | |
290 static void convo_data_free(struct convo_data *conv); | |
291 | |
292 static void convo_features(struct mwConversation *conv); | |
293 | |
294 static GaimConversation *convo_get_gconv(struct mwConversation *conv); | |
295 | |
296 | |
297 /* resolved id */ | |
298 | |
299 struct resolved_id { | |
300 char *id; | |
301 char *name; | |
302 }; | |
303 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
304 static struct resolved_id *resolved_id_new(const char *id, const char *name); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
305 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
306 static void resolved_id_free(struct resolved_id *rid); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
307 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
308 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
309 /* connection functions */ |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
310 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
311 static void connect_cb(gpointer data, gint source, GaimInputCondition cond); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
312 |
10977 | 313 |
314 /* ----- session ------ */ | |
315 | |
316 | |
317 /** resolves a mwSession from a GaimConnection */ | |
318 static struct mwSession *gc_to_session(GaimConnection *gc) { | |
319 struct mwGaimPluginData *pd; | |
320 | |
321 g_return_val_if_fail(gc != NULL, NULL); | |
322 | |
323 pd = gc->proto_data; | |
324 g_return_val_if_fail(pd != NULL, NULL); | |
325 | |
326 return pd->session; | |
327 } | |
328 | |
329 | |
330 /** resolves a GaimConnection from a mwSession */ | |
331 static GaimConnection *session_to_gc(struct mwSession *session) { | |
332 struct mwGaimPluginData *pd; | |
333 | |
334 g_return_val_if_fail(session != NULL, NULL); | |
335 | |
336 pd = mwSession_getClientData(session); | |
337 g_return_val_if_fail(pd != NULL, NULL); | |
338 | |
339 return pd->gc; | |
340 } | |
341 | |
342 | |
343 static int mw_session_io_write(struct mwSession *session, | |
344 const char *buf, gsize len) { | |
345 struct mwGaimPluginData *pd; | |
346 int ret = 0; | |
347 | |
348 pd = mwSession_getClientData(session); | |
349 | |
350 /* socket was already closed. */ | |
351 if(pd->socket == 0) | |
352 return 1; | |
353 | |
354 while(len) { | |
355 ret = write(pd->socket, buf, len); | |
356 if(ret <= 0) break; | |
357 len -= ret; | |
358 } | |
359 | |
360 if(len > 0) { | |
361 DEBUG_ERROR("write returned %i, %i bytes left unwritten\n", ret, len); | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
362 gaim_connection_error(pd->gc, _("Connection closed (writing)")); |
11133
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
363 |
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
364 #if 0 |
10977 | 365 close(pd->socket); |
366 pd->socket = 0; | |
11133
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
367 #endif |
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
368 |
10977 | 369 return -1; |
370 } | |
371 | |
372 return 0; | |
373 } | |
374 | |
375 | |
376 static void mw_session_io_close(struct mwSession *session) { | |
377 struct mwGaimPluginData *pd; | |
11133
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
378 GaimConnection *gc; |
10977 | 379 |
380 pd = mwSession_getClientData(session); | |
11133
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
381 g_return_if_fail(pd != NULL); |
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
382 |
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
383 gc = pd->gc; |
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
384 |
10977 | 385 if(pd->socket) { |
386 close(pd->socket); | |
387 pd->socket = 0; | |
388 } | |
11133
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
389 |
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
390 if(gc->inpa) { |
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
391 gaim_input_remove(gc->inpa); |
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
392 gc->inpa = 0; |
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
393 } |
10977 | 394 } |
395 | |
396 | |
397 static void mw_session_clear(struct mwSession *session) { | |
398 ; /* nothing for now */ | |
399 } | |
400 | |
401 | |
402 /* ----- aware list ----- */ | |
403 | |
404 | |
405 static void blist_resolve_alias_cb(struct mwServiceResolve *srvc, | |
406 guint32 id, guint32 code, GList *results, | |
407 gpointer data) { | |
408 struct mwResolveResult *result; | |
409 struct mwResolveMatch *match; | |
410 | |
411 g_return_if_fail(results != NULL); | |
412 | |
413 result = results->data; | |
414 g_return_if_fail(result != NULL); | |
415 g_return_if_fail(result->matches != NULL); | |
416 | |
417 match = result->matches->data; | |
418 g_return_if_fail(match != NULL); | |
419 | |
420 gaim_blist_server_alias_buddy(data, match->name); | |
421 gaim_blist_node_set_string(data, BUDDY_KEY_NAME, match->name); | |
422 } | |
423 | |
424 | |
425 static void mw_aware_list_on_aware(struct mwAwareList *list, | |
426 struct mwAwareSnapshot *aware) { | |
427 | |
428 GaimConnection *gc; | |
11638 | 429 GaimAccount *acct; |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
430 |
10977 | 431 struct mwGaimPluginData *pd; |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
432 time_t idle; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
433 guint stat; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
434 const char *id; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
435 const char *status = MW_STATE_ACTIVE; |
10977 | 436 |
437 gc = mwAwareList_getClientData(list); | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
438 acct = gaim_connection_get_account(gc); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
439 |
10977 | 440 pd = gc->proto_data; |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
441 idle = aware->status.time; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
442 stat = aware->status.status; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
443 id = aware->id.user; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
444 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
445 /* not sure which client sends this yet */ |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
446 if(idle == 0xdeadbeef) { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
447 /* knock knock! |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
448 who's there? |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
449 rude interrupting cow. |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
450 rude interr... |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
451 MOO! */ |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
452 idle = -1; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
453 } |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
454 |
10977 | 455 switch(stat) { |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
456 case mwStatus_ACTIVE: |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
457 status = MW_STATE_ACTIVE; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
458 idle = 0; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
459 break; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
460 |
10977 | 461 case mwStatus_IDLE: |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
462 if(! idle) idle = -1; |
10977 | 463 break; |
464 | |
465 case mwStatus_AWAY: | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
466 status = MW_STATE_AWAY; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
467 break; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
468 |
10977 | 469 case mwStatus_BUSY: |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
470 status = MW_STATE_BUSY; |
10977 | 471 break; |
472 } | |
473 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
474 /* NAB group members */ |
10977 | 475 if(aware->group) { |
476 GaimGroup *group; | |
477 GaimBuddy *buddy; | |
478 GaimBlistNode *bnode; | |
479 | |
480 group = g_hash_table_lookup(pd->group_list_map, list); | |
481 buddy = gaim_find_buddy_in_group(acct, id, group); | |
482 bnode = (GaimBlistNode *) buddy; | |
483 | |
484 if(! buddy) { | |
485 struct mwServiceResolve *srvc; | |
486 GList *query; | |
487 | |
488 buddy = gaim_buddy_new(acct, id, NULL); | |
489 gaim_blist_add_buddy(buddy, NULL, group, NULL); | |
490 | |
491 bnode = (GaimBlistNode *) buddy; | |
492 | |
493 srvc = pd->srvc_resolve; | |
494 query = g_list_append(NULL, (char *) id); | |
495 | |
496 mwServiceResolve_resolve(srvc, query, mwResolveFlag_USERS, | |
497 blist_resolve_alias_cb, buddy, NULL); | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
498 g_list_free(query); |
10977 | 499 } |
500 | |
501 gaim_blist_node_set_int(bnode, BUDDY_KEY_TYPE, mwSametimeUser_NORMAL); | |
502 } | |
503 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
504 gaim_prpl_got_user_status(acct, id, status, NULL); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
505 gaim_prpl_got_user_idle(acct, id, !!idle, idle); |
10977 | 506 } |
507 | |
508 | |
509 static void mw_aware_list_on_attrib(struct mwAwareList *list, | |
510 struct mwAwareIdBlock *id, | |
511 struct mwAwareAttribute *attrib) { | |
512 | |
513 ; /* nothing. We'll get attribute data as we need it */ | |
514 } | |
515 | |
516 | |
517 static void mw_aware_list_clear(struct mwAwareList *list) { | |
518 ; /* nothing for now */ | |
519 } | |
520 | |
521 | |
522 static struct mwAwareListHandler mw_aware_list_handler = { | |
523 .on_aware = mw_aware_list_on_aware, | |
524 .on_attrib = mw_aware_list_on_attrib, | |
525 .clear = mw_aware_list_clear, | |
526 }; | |
527 | |
528 | |
529 /** Ensures that an Aware List is associated with the given group, and | |
530 returns that list. */ | |
531 static struct mwAwareList * | |
532 list_ensure(struct mwGaimPluginData *pd, GaimGroup *group) { | |
533 | |
534 struct mwAwareList *list; | |
535 | |
536 g_return_val_if_fail(pd != NULL, NULL); | |
537 g_return_val_if_fail(group != NULL, NULL); | |
538 | |
539 list = g_hash_table_lookup(pd->group_list_map, group); | |
540 if(! list) { | |
541 list = mwAwareList_new(pd->srvc_aware, &mw_aware_list_handler); | |
542 mwAwareList_setClientData(list, pd->gc, NULL); | |
543 | |
544 mwAwareList_watchAttributes(list, | |
545 mwAttribute_AV_PREFS_SET, | |
546 mwAttribute_MICROPHONE, | |
547 mwAttribute_SPEAKERS, | |
548 mwAttribute_VIDEO_CAMERA, | |
549 mwAttribute_FILE_TRANSFER, | |
550 NULL); | |
551 | |
552 g_hash_table_replace(pd->group_list_map, group, list); | |
553 g_hash_table_insert(pd->group_list_map, list, group); | |
554 } | |
555 | |
556 return list; | |
557 } | |
558 | |
559 | |
560 static void blist_export(GaimConnection *gc, struct mwSametimeList *stlist) { | |
561 /* - find the account for this connection | |
562 - iterate through the buddy list | |
563 - add each buddy matching this account to the stlist | |
564 */ | |
565 | |
566 GaimAccount *acct; | |
567 GaimBuddyList *blist; | |
568 GaimBlistNode *gn, *cn, *bn; | |
569 GaimGroup *grp; | |
570 GaimBuddy *bdy; | |
571 | |
572 struct mwSametimeGroup *stg = NULL; | |
573 struct mwIdBlock idb = { NULL, NULL }; | |
574 | |
575 acct = gaim_connection_get_account(gc); | |
576 g_return_if_fail(acct != NULL); | |
577 | |
578 blist = gaim_get_blist(); | |
579 g_return_if_fail(blist != NULL); | |
580 | |
581 for(gn = blist->root; gn; gn = gn->next) { | |
582 const char *owner; | |
583 const char *gname; | |
584 enum mwSametimeGroupType gtype; | |
585 gboolean gopen; | |
586 | |
587 if(! GAIM_BLIST_NODE_IS_GROUP(gn)) continue; | |
588 grp = (GaimGroup *) gn; | |
589 | |
590 /* the group's type (normal or dynamic) */ | |
591 gtype = gaim_blist_node_get_int(gn, GROUP_KEY_TYPE); | |
592 if(! gtype) gtype = mwSametimeGroup_NORMAL; | |
593 | |
594 /* if it's a normal group with none of our people in it, skip it */ | |
595 if(gtype == mwSametimeGroup_NORMAL && !gaim_group_on_account(grp, acct)) | |
596 continue; | |
597 | |
598 /* if the group has an owner and we're not it, skip it */ | |
599 owner = gaim_blist_node_get_string(gn, GROUP_KEY_OWNER); | |
600 if(owner && strcmp(owner, gaim_account_get_username(acct))) | |
601 continue; | |
602 | |
603 /* the group's actual name may be different from the gaim group's | |
604 name. Find whichever is there */ | |
605 gname = gaim_blist_node_get_string(gn, GROUP_KEY_NAME); | |
606 if(! gname) gname = grp->name; | |
607 | |
608 /* we save this, but never actually honor it */ | |
609 gopen = ! gaim_blist_node_get_bool(gn, GROUP_KEY_COLLAPSED); | |
610 | |
611 stg = mwSametimeGroup_new(stlist, gtype, gname); | |
612 mwSametimeGroup_setAlias(stg, grp->name); | |
613 mwSametimeGroup_setOpen(stg, gopen); | |
614 | |
11133
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
615 /* don't attempt to put buddies in a dynamic group, it breaks |
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
616 other clients */ |
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
617 if(gtype == mwSametimeGroup_DYNAMIC) |
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
618 continue; |
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
619 |
10977 | 620 for(cn = gn->child; cn; cn = cn->next) { |
621 if(! GAIM_BLIST_NODE_IS_CONTACT(cn)) continue; | |
622 | |
623 for(bn = cn->child; bn; bn = bn->next) { | |
624 if(! GAIM_BLIST_NODE_IS_BUDDY(bn)) continue; | |
625 if(! GAIM_BLIST_NODE_SHOULD_SAVE(bn)) continue; | |
626 | |
627 bdy = (GaimBuddy *) bn; | |
628 | |
629 if(bdy->account == acct) { | |
630 struct mwSametimeUser *stu; | |
631 enum mwSametimeUserType utype; | |
632 | |
633 idb.user = bdy->name; | |
634 | |
635 utype = gaim_blist_node_get_int(bn, BUDDY_KEY_TYPE); | |
636 if(! utype) utype = mwSametimeUser_NORMAL; | |
637 | |
638 stu = mwSametimeUser_new(stg, utype, &idb); | |
639 mwSametimeUser_setShortName(stu, bdy->server_alias); | |
640 mwSametimeUser_setAlias(stu, bdy->alias); | |
641 } | |
642 } | |
643 } | |
644 } | |
645 } | |
646 | |
647 | |
648 static void blist_store(struct mwGaimPluginData *pd) { | |
649 | |
650 struct mwSametimeList *stlist; | |
651 struct mwServiceStorage *srvc; | |
652 struct mwStorageUnit *unit; | |
653 | |
654 GaimConnection *gc; | |
655 | |
656 struct mwPutBuffer *b; | |
657 struct mwOpaque *o; | |
658 | |
659 g_return_if_fail(pd != NULL); | |
660 | |
661 srvc = pd->srvc_store; | |
662 g_return_if_fail(srvc != NULL); | |
663 | |
664 gc = pd->gc; | |
665 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
666 if(BLIST_PREF_IS_LOCAL() || BLIST_PREF_IS_MERGE()) { |
10977 | 667 DEBUG_INFO("preferences indicate not to save remote blist\n"); |
668 return; | |
669 | |
670 } else if(MW_SERVICE_IS_DEAD(srvc)) { | |
671 DEBUG_INFO("aborting save of blist: storage service is not alive\n"); | |
672 return; | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
673 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
674 } else if(BLIST_PREF_IS_STORE() || BLIST_PREF_IS_SYNCH()) { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
675 DEBUG_INFO("saving remote blist\n"); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
676 |
10977 | 677 } else { |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
678 g_return_if_reached(); |
10977 | 679 } |
680 | |
681 /* create and export to a list object */ | |
682 stlist = mwSametimeList_new(); | |
683 blist_export(gc, stlist); | |
684 | |
685 /* write it to a buffer */ | |
686 b = mwPutBuffer_new(); | |
687 mwSametimeList_put(b, stlist); | |
688 mwSametimeList_free(stlist); | |
689 | |
690 /* put the buffer contents into a storage unit */ | |
691 unit = mwStorageUnit_new(mwStore_AWARE_LIST); | |
692 o = mwStorageUnit_asOpaque(unit); | |
693 mwPutBuffer_finalize(o, b); | |
694 | |
695 /* save the storage unit to the service */ | |
696 mwServiceStorage_save(srvc, unit, NULL, NULL, NULL); | |
697 } | |
698 | |
699 | |
700 static gboolean blist_save_cb(gpointer data) { | |
701 struct mwGaimPluginData *pd = data; | |
702 | |
703 blist_store(pd); | |
704 pd->save_event = 0; | |
705 return FALSE; | |
706 } | |
707 | |
708 | |
709 /** schedules the buddy list to be saved to the server */ | |
710 static void blist_schedule(struct mwGaimPluginData *pd) { | |
711 if(pd->save_event) return; | |
712 | |
713 pd->save_event = gaim_timeout_add(BLIST_SAVE_SECONDS * 1000, | |
714 blist_save_cb, pd); | |
715 } | |
716 | |
717 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
718 static gboolean buddy_is_external(GaimBuddy *b) { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
719 g_return_val_if_fail(b != NULL, FALSE); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
720 return g_str_has_prefix(b->name, "@E "); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
721 } |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
722 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
723 |
10977 | 724 /** Actually add a buddy to the aware service, and schedule the buddy |
725 list to be saved to the server */ | |
726 static void buddy_add(struct mwGaimPluginData *pd, | |
727 GaimBuddy *buddy) { | |
728 | |
729 struct mwAwareIdBlock idb = { mwAware_USER, (char *) buddy->name, NULL }; | |
730 struct mwAwareList *list; | |
731 | |
732 GaimGroup *group; | |
733 GList *add; | |
734 | |
735 add = g_list_prepend(NULL, &idb); | |
736 | |
12088 | 737 group = gaim_buddy_get_group(buddy); |
10977 | 738 list = list_ensure(pd, group); |
739 | |
740 if(mwAwareList_addAware(list, add)) { | |
741 gaim_blist_remove_buddy(buddy); | |
742 } | |
743 | |
744 blist_schedule(pd); | |
745 | |
746 g_list_free(add); | |
747 } | |
748 | |
749 | |
750 /** ensure that a GaimBuddy exists in the group with data | |
751 appropriately matching the st user entry from the st list */ | |
752 static GaimBuddy *buddy_ensure(GaimConnection *gc, GaimGroup *group, | |
753 struct mwSametimeUser *stuser) { | |
754 | |
755 struct mwGaimPluginData *pd = gc->proto_data; | |
756 GaimBuddy *buddy; | |
757 GaimAccount *acct = gaim_connection_get_account(gc); | |
758 | |
759 const char *id = mwSametimeUser_getUser(stuser); | |
760 const char *name = mwSametimeUser_getShortName(stuser); | |
761 const char *alias = mwSametimeUser_getAlias(stuser); | |
762 enum mwSametimeUserType type = mwSametimeUser_getType(stuser); | |
763 | |
764 g_return_val_if_fail(id != NULL, NULL); | |
765 g_return_val_if_fail(strlen(id) > 0, NULL); | |
766 | |
767 buddy = gaim_find_buddy_in_group(acct, id, group); | |
768 if(! buddy) { | |
769 buddy = gaim_buddy_new(acct, id, alias); | |
770 | |
771 gaim_blist_add_buddy(buddy, NULL, group, NULL); | |
772 buddy_add(pd, buddy); | |
773 } | |
774 | |
775 gaim_blist_alias_buddy(buddy, alias); | |
776 gaim_blist_server_alias_buddy(buddy, name); | |
777 gaim_blist_node_set_string((GaimBlistNode *) buddy, BUDDY_KEY_NAME, name); | |
778 gaim_blist_node_set_int((GaimBlistNode *) buddy, BUDDY_KEY_TYPE, type); | |
779 | |
780 return buddy; | |
781 } | |
782 | |
783 | |
11133
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
784 /** add aware watch for a dynamic group */ |
10977 | 785 static void group_add(struct mwGaimPluginData *pd, |
786 GaimGroup *group) { | |
787 | |
788 struct mwAwareIdBlock idb = { mwAware_GROUP, NULL, NULL }; | |
789 struct mwAwareList *list; | |
790 const char *n; | |
791 GList *add; | |
792 | |
793 n = gaim_blist_node_get_string((GaimBlistNode *) group, GROUP_KEY_NAME); | |
794 if(! n) n = group->name; | |
795 | |
796 idb.user = (char *) n; | |
797 add = g_list_prepend(NULL, &idb); | |
798 | |
799 list = list_ensure(pd, group); | |
800 mwAwareList_addAware(list, add); | |
801 g_list_free(add); | |
802 } | |
803 | |
804 | |
805 /** ensure that a GaimGroup exists in the blist with data | |
806 appropriately matching the st group entry from the st list */ | |
807 static GaimGroup *group_ensure(GaimConnection *gc, | |
808 struct mwSametimeGroup *stgroup) { | |
809 GaimAccount *acct; | |
12006
de25a063aebe
[gaim-migrate @ 14299]
Christopher O'Brien <siege@pidgin.im>
parents:
12005
diff
changeset
|
810 GaimGroup *group = NULL; |
12005
5b3368008513
[gaim-migrate @ 14298]
Christopher O'Brien <siege@pidgin.im>
parents:
11953
diff
changeset
|
811 GaimBuddyList *blist; |
10977 | 812 GaimBlistNode *gn; |
11133
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
813 const char *name, *alias, *owner; |
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
814 enum mwSametimeGroupType type; |
10977 | 815 |
816 acct = gaim_connection_get_account(gc); | |
817 owner = gaim_account_get_username(acct); | |
818 | |
12005
5b3368008513
[gaim-migrate @ 14298]
Christopher O'Brien <siege@pidgin.im>
parents:
11953
diff
changeset
|
819 blist = gaim_get_blist(); |
5b3368008513
[gaim-migrate @ 14298]
Christopher O'Brien <siege@pidgin.im>
parents:
11953
diff
changeset
|
820 g_return_val_if_fail(blist != NULL, NULL); |
5b3368008513
[gaim-migrate @ 14298]
Christopher O'Brien <siege@pidgin.im>
parents:
11953
diff
changeset
|
821 |
11133
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
822 name = mwSametimeGroup_getName(stgroup); |
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
823 alias = mwSametimeGroup_getAlias(stgroup); |
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
824 type = mwSametimeGroup_getType(stgroup); |
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
825 |
12005
5b3368008513
[gaim-migrate @ 14298]
Christopher O'Brien <siege@pidgin.im>
parents:
11953
diff
changeset
|
826 /* first attempt at finding the group, by the name key */ |
5b3368008513
[gaim-migrate @ 14298]
Christopher O'Brien <siege@pidgin.im>
parents:
11953
diff
changeset
|
827 for(gn = blist->root; gn; gn = gn->next) { |
5b3368008513
[gaim-migrate @ 14298]
Christopher O'Brien <siege@pidgin.im>
parents:
11953
diff
changeset
|
828 const char *n; |
5b3368008513
[gaim-migrate @ 14298]
Christopher O'Brien <siege@pidgin.im>
parents:
11953
diff
changeset
|
829 if(! GAIM_BLIST_NODE_IS_GROUP(gn)) continue; |
5b3368008513
[gaim-migrate @ 14298]
Christopher O'Brien <siege@pidgin.im>
parents:
11953
diff
changeset
|
830 n = gaim_blist_node_get_string(gn, GROUP_KEY_NAME); |
5b3368008513
[gaim-migrate @ 14298]
Christopher O'Brien <siege@pidgin.im>
parents:
11953
diff
changeset
|
831 |
5b3368008513
[gaim-migrate @ 14298]
Christopher O'Brien <siege@pidgin.im>
parents:
11953
diff
changeset
|
832 if(n && !strcmp(n, name)) { |
5b3368008513
[gaim-migrate @ 14298]
Christopher O'Brien <siege@pidgin.im>
parents:
11953
diff
changeset
|
833 group = (GaimGroup *) gn; |
5b3368008513
[gaim-migrate @ 14298]
Christopher O'Brien <siege@pidgin.im>
parents:
11953
diff
changeset
|
834 break; |
5b3368008513
[gaim-migrate @ 14298]
Christopher O'Brien <siege@pidgin.im>
parents:
11953
diff
changeset
|
835 } |
5b3368008513
[gaim-migrate @ 14298]
Christopher O'Brien <siege@pidgin.im>
parents:
11953
diff
changeset
|
836 } |
5b3368008513
[gaim-migrate @ 14298]
Christopher O'Brien <siege@pidgin.im>
parents:
11953
diff
changeset
|
837 |
5b3368008513
[gaim-migrate @ 14298]
Christopher O'Brien <siege@pidgin.im>
parents:
11953
diff
changeset
|
838 /* try again, by alias */ |
12006
de25a063aebe
[gaim-migrate @ 14299]
Christopher O'Brien <siege@pidgin.im>
parents:
12005
diff
changeset
|
839 if(! group) group = gaim_find_group(alias); |
12005
5b3368008513
[gaim-migrate @ 14298]
Christopher O'Brien <siege@pidgin.im>
parents:
11953
diff
changeset
|
840 |
5b3368008513
[gaim-migrate @ 14298]
Christopher O'Brien <siege@pidgin.im>
parents:
11953
diff
changeset
|
841 /* oh well, no such group. Let's create it! */ |
10977 | 842 if(! group) { |
843 group = gaim_group_new(alias); | |
844 gaim_blist_add_group(group, NULL); | |
845 } | |
846 | |
847 gn = (GaimBlistNode *) group; | |
848 gaim_blist_node_set_string(gn, GROUP_KEY_NAME, name); | |
849 gaim_blist_node_set_int(gn, GROUP_KEY_TYPE, type); | |
850 | |
851 if(type == mwSametimeGroup_DYNAMIC) { | |
852 gaim_blist_node_set_string(gn, GROUP_KEY_OWNER, owner); | |
853 group_add(gc->proto_data, group); | |
854 } | |
855 | |
856 return group; | |
857 } | |
858 | |
859 | |
860 /** merge the entries from a st list into the gaim blist */ | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
861 static void blist_merge(GaimConnection *gc, struct mwSametimeList *stlist) { |
10977 | 862 struct mwSametimeGroup *stgroup; |
863 struct mwSametimeUser *stuser; | |
864 | |
865 GaimGroup *group; | |
866 GaimBuddy *buddy; | |
867 | |
868 GList *gl, *gtl, *ul, *utl; | |
869 | |
870 gl = gtl = mwSametimeList_getGroups(stlist); | |
871 for(; gl; gl = gl->next) { | |
872 | |
873 stgroup = (struct mwSametimeGroup *) gl->data; | |
874 group = group_ensure(gc, stgroup); | |
875 | |
876 ul = utl = mwSametimeGroup_getUsers(stgroup); | |
877 for(; ul; ul = ul->next) { | |
878 | |
879 stuser = (struct mwSametimeUser *) ul->data; | |
880 buddy = buddy_ensure(gc, group, stuser); | |
881 } | |
882 g_list_free(utl); | |
883 } | |
884 g_list_free(gtl); | |
885 } | |
886 | |
887 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
888 /** remove all buddies on account from group. If del is TRUE and group |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
889 is left empty, remove group as well */ |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
890 static void group_clear(GaimGroup *group, GaimAccount *acct, gboolean del) { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
891 GaimConnection *gc; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
892 GList *prune = NULL; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
893 GaimBlistNode *gn, *cn, *bn; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
894 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
895 g_return_if_fail(group != NULL); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
896 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
897 DEBUG_INFO("clearing members from pruned group %s\n", NSTR(group->name)); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
898 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
899 gc = gaim_account_get_connection(acct); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
900 g_return_if_fail(gc != NULL); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
901 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
902 gn = (GaimBlistNode *) group; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
903 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
904 for(cn = gn->child; cn; cn = cn->next) { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
905 if(! GAIM_BLIST_NODE_IS_CONTACT(cn)) continue; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
906 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
907 for(bn = cn->child; bn; bn = bn->next) { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
908 GaimBuddy *gb = (GaimBuddy *) bn; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
909 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
910 if(! GAIM_BLIST_NODE_IS_BUDDY(bn)) continue; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
911 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
912 if(gb->account == acct) { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
913 DEBUG_INFO("clearing %s from group\n", NSTR(gb->name)); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
914 prune = g_list_prepend(prune, gb); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
915 } |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
916 } |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
917 } |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
918 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
919 /* quickly unsubscribe from presence for the entire group */ |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
920 gaim_account_remove_group(acct, group); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
921 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
922 /* remove blist entries that need to go */ |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
923 while(prune) { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
924 gaim_blist_remove_buddy(prune->data); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
925 prune = g_list_delete_link(prune, prune); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
926 } |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
927 DEBUG_INFO("cleared buddies\n"); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
928 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
929 /* optionally remove group from blist */ |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
930 if(del && !gaim_blist_get_group_size(group, TRUE)) { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
931 DEBUG_INFO("removing empty group\n"); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
932 gaim_blist_remove_group(group); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
933 } |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
934 } |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
935 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
936 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
937 /** prune out group members that shouldn't be there */ |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
938 static void group_prune(GaimConnection *gc, GaimGroup *group, |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
939 struct mwSametimeGroup *stgroup) { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
940 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
941 GaimAccount *acct; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
942 GaimBlistNode *gn, *cn, *bn; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
943 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
944 GHashTable *stusers; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
945 GList *prune = NULL; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
946 GList *ul, *utl; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
947 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
948 g_return_if_fail(group != NULL); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
949 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
950 DEBUG_INFO("pruning membership of group %s\n", NSTR(group->name)); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
951 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
952 acct = gaim_connection_get_account(gc); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
953 g_return_if_fail(acct != NULL); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
954 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
955 stusers = g_hash_table_new(g_str_hash, g_str_equal); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
956 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
957 /* build a hash table for quick lookup while pruning the group |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
958 contents */ |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
959 utl = mwSametimeGroup_getUsers(stgroup); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
960 for(ul = utl; ul; ul = ul->next) { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
961 const char *id = mwSametimeUser_getUser(ul->data); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
962 g_hash_table_insert(stusers, (char *) id, ul->data); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
963 DEBUG_INFO("server copy has %s\n", NSTR(id)); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
964 } |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
965 g_list_free(utl); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
966 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
967 gn = (GaimBlistNode *) group; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
968 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
969 for(cn = gn->child; cn; cn = cn->next) { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
970 if(! GAIM_BLIST_NODE_IS_CONTACT(cn)) continue; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
971 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
972 for(bn = cn->child; bn; bn = bn->next) { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
973 GaimBuddy *gb = (GaimBuddy *) bn; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
974 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
975 if(! GAIM_BLIST_NODE_IS_BUDDY(bn)) continue; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
976 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
977 /* if the account is correct and they're not in our table, mark |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
978 them for pruning */ |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
979 if(gb->account == acct && !g_hash_table_lookup(stusers, gb->name)) { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
980 DEBUG_INFO("marking %s for pruning\n", NSTR(gb->name)); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
981 prune = g_list_prepend(prune, gb); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
982 } |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
983 } |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
984 } |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
985 DEBUG_INFO("done marking\n"); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
986 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
987 g_hash_table_destroy(stusers); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
988 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
989 if(prune) { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
990 gaim_account_remove_buddies(acct, prune, NULL); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
991 while(prune) { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
992 gaim_blist_remove_buddy(prune->data); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
993 prune = g_list_delete_link(prune, prune); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
994 } |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
995 } |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
996 } |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
997 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
998 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
999 /** synch the entries from a st list into the gaim blist, removing any |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1000 existing buddies that aren't in the st list */ |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1001 static void blist_sync(GaimConnection *gc, struct mwSametimeList *stlist) { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1002 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1003 GaimAccount *acct; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1004 GaimBuddyList *blist; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1005 GaimBlistNode *gn; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1006 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1007 GHashTable *stgroups; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1008 GList *g_prune = NULL; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1009 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1010 GList *gl, *gtl; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1011 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1012 const char *acct_n; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1013 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1014 DEBUG_INFO("synchronizing local buddy list from server list\n"); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1015 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1016 acct = gaim_connection_get_account(gc); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1017 g_return_if_fail(acct != NULL); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1018 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1019 acct_n = gaim_account_get_username(acct); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1020 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1021 blist = gaim_get_blist(); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1022 g_return_if_fail(blist != NULL); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1023 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1024 /* build a hash table for quick lookup while pruning the local |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1025 list, mapping group name to group structure */ |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1026 stgroups = g_hash_table_new(g_str_hash, g_str_equal); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1027 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1028 gtl = mwSametimeList_getGroups(stlist); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1029 for(gl = gtl; gl; gl = gl->next) { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1030 const char *name = mwSametimeGroup_getName(gl->data); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1031 g_hash_table_insert(stgroups, (char *) name, gl->data); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1032 } |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1033 g_list_free(gtl); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1034 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1035 /* find all groups which should be pruned from the local list */ |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1036 for(gn = blist->root; gn; gn = gn->next) { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1037 GaimGroup *grp = (GaimGroup *) gn; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1038 const char *gname, *owner; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1039 struct mwSametimeGroup *stgrp; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1040 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1041 if(! GAIM_BLIST_NODE_IS_GROUP(gn)) continue; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1042 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1043 /* group not belonging to this account */ |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1044 if(! gaim_group_on_account(grp, acct)) |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1045 continue; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1046 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1047 /* dynamic group belonging to this account. don't prune contents */ |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1048 owner = gaim_blist_node_get_string(gn, GROUP_KEY_OWNER); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1049 if(owner && !strcmp(owner, acct_n)) |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1050 continue; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1051 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1052 /* we actually are synching by this key as opposed to the group |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1053 title, which can be different things in the st list */ |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1054 gname = gaim_blist_node_get_string(gn, GROUP_KEY_NAME); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1055 if(! gname) gname = grp->name; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1056 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1057 stgrp = g_hash_table_lookup(stgroups, gname); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1058 if(! stgrp) { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1059 /* remove the whole group */ |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1060 DEBUG_INFO("marking group %s for pruning\n", grp->name); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1061 g_prune = g_list_prepend(g_prune, grp); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1062 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1063 } else { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1064 /* synch the group contents */ |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1065 group_prune(gc, grp, stgrp); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1066 } |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1067 } |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1068 DEBUG_INFO("done marking groups\n"); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1069 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1070 /* don't need this anymore */ |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1071 g_hash_table_destroy(stgroups); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1072 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1073 /* prune all marked groups */ |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1074 while(g_prune) { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1075 GaimGroup *grp = g_prune->data; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1076 GaimBlistNode *gn = (GaimBlistNode *) grp; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1077 const char *owner; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1078 gboolean del = TRUE; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1079 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1080 owner = gaim_blist_node_get_string(gn, GROUP_KEY_OWNER); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1081 if(owner && strcmp(owner, acct_n)) { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1082 /* it's a specialty group belonging to another account with some |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1083 of our members in it, so don't fully delete it */ |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1084 del = FALSE; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1085 } |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1086 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1087 group_clear(g_prune->data, acct, del); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1088 g_prune = g_list_delete_link(g_prune, g_prune); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1089 } |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1090 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1091 /* done with the pruning, let's merge in the additions */ |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1092 blist_merge(gc, stlist); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1093 } |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1094 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1095 |
10977 | 1096 /** callback passed to the storage service when it's told to load the |
1097 st list */ | |
1098 static void fetch_blist_cb(struct mwServiceStorage *srvc, | |
1099 guint32 result, struct mwStorageUnit *item, | |
1100 gpointer data) { | |
1101 | |
1102 struct mwGaimPluginData *pd = data; | |
1103 struct mwSametimeList *stlist; | |
1104 struct mwSession *s; | |
1105 | |
1106 struct mwGetBuffer *b; | |
1107 | |
1108 g_return_if_fail(result == ERR_SUCCESS); | |
1109 | |
1110 /* check our preferences for loading */ | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1111 if(BLIST_PREF_IS_LOCAL()) { |
10977 | 1112 DEBUG_INFO("preferences indicate not to load remote buddy list\n"); |
1113 return; | |
1114 } | |
1115 | |
1116 b = mwGetBuffer_wrap(mwStorageUnit_asOpaque(item)); | |
1117 | |
1118 stlist = mwSametimeList_new(); | |
1119 mwSametimeList_get(b, stlist); | |
1120 | |
1121 s = mwService_getSession(MW_SERVICE(srvc)); | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1122 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1123 /* merge or synch depending on preferences */ |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1124 if(BLIST_PREF_IS_MERGE() || BLIST_PREF_IS_STORE()) { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1125 blist_merge(pd->gc, stlist); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1126 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1127 } else if(BLIST_PREF_IS_SYNCH()) { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1128 blist_sync(pd->gc, stlist); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1129 } |
10977 | 1130 |
1131 mwSametimeList_free(stlist); | |
1132 } | |
1133 | |
1134 | |
1135 /** callback passed to the storage service when it's told to load one | |
1136 of the default status messages */ | |
1137 static void fetch_msg_cb(struct mwServiceStorage *srvc, | |
1138 guint32 result, struct mwStorageUnit *item, | |
1139 gpointer data) { | |
1140 | |
1141 struct mwGaimPluginData *pd = data; | |
1142 GaimConnection *gc; | |
1143 GaimAccount *acct; | |
1144 struct mwSession *session; | |
1145 char *msg, *m; | |
1146 | |
11133
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
1147 /* it's no big deal if these entries don't exist on the server */ |
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
1148 if(result != ERR_SUCCESS) return; |
10977 | 1149 |
1150 g_return_if_fail(pd != NULL); | |
1151 | |
1152 gc = pd->gc; | |
1153 g_return_if_fail(gc != NULL); | |
1154 | |
1155 acct = gaim_connection_get_account(gc); | |
1156 g_return_if_fail(acct != NULL); | |
1157 | |
1158 session = pd->session; | |
1159 g_return_if_fail(session != NULL); | |
1160 | |
1161 m = msg = mwStorageUnit_asString(item); | |
1162 | |
1163 /* only load the first (non-empty) line of the collection of | |
1164 status messages */ | |
1165 if(m && *m) { | |
1166 while(*m && isspace(*m)) m++; | |
1167 if(*m) { | |
1168 char *tail; | |
1169 | |
1170 tail = strchr(m, '\r'); | |
1171 if(tail) *tail = '\0'; | |
1172 tail = strchr(m, '\n'); | |
1173 if(tail) *tail = '\0'; | |
1174 } | |
1175 } | |
1176 | |
1177 switch(mwStorageUnit_getKey(item)) { | |
1178 case mwStore_AWAY_MESSAGES: | |
1179 DEBUG_INFO("setting away message to \"%s\"\n", NSTR(m)); | |
1180 gaim_account_set_string(acct, MW_KEY_AWAY_MSG, m); | |
1181 break; | |
1182 | |
1183 case mwStore_BUSY_MESSAGES: | |
1184 DEBUG_INFO("setting busy message to \"%s\"\n", NSTR(m)); | |
1185 gaim_account_set_string(acct, MW_KEY_BUSY_MSG, m); | |
1186 break; | |
1187 | |
1188 case mwStore_ACTIVE_MESSAGES: | |
1189 DEBUG_INFO("setting active message to \"%s\"\n", NSTR(m)); | |
1190 gaim_account_set_string(acct, MW_KEY_ACTIVE_MSG, m); | |
1191 break; | |
1192 | |
1193 default: | |
1194 g_free(msg); | |
1195 g_return_if_reached(); | |
1196 } | |
1197 | |
1198 g_free(msg); | |
1199 msg = NULL; | |
1200 | |
1201 #if 0 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1202 /* XXX resets the status, thus updating the message */ |
10977 | 1203 if(!gc->away_state || !strcmp(gc->away_state, MW_STATE_ACTIVE)) { |
1204 msg = MW_STATE_ACTIVE; | |
1205 } else if(gc->away_state && !strcmp(gc->away_state, MW_STATE_AWAY)) { | |
1206 msg = MW_STATE_AWAY; | |
1207 } else if(gc->away_state && !strcmp(gc->away_state, MW_STATE_BUSY)) { | |
1208 msg = MW_STATE_BUSY; | |
1209 } | |
1210 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1211 if(msg) serv_set_away(gc, msg, NULL); |
10977 | 1212 #endif |
1213 } | |
1214 | |
1215 | |
1216 /** signal triggered when a conversation is opened in Gaim */ | |
1217 static void conversation_created_cb(GaimConversation *g_conv, | |
1218 struct mwGaimPluginData *pd) { | |
1219 | |
1220 /* we need to tell the IM service to negotiate features for the | |
1221 conversation right away, otherwise it'll wait until the first | |
1222 message is sent before offering NotesBuddy features. Therefore | |
1223 whenever Gaim creates a conversation, we'll immediately open the | |
1224 channel to the other side and figure out what the target can | |
1225 handle. Unfortunately, this makes us vulnerable to Psychic Mode, | |
1226 whereas a more lazy negotiation based on the first message | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1227 would not */ |
10977 | 1228 |
1229 GaimConnection *gc; | |
1230 struct mwIdBlock who = { 0, 0 }; | |
1231 struct mwConversation *conv; | |
1232 | |
1233 gc = gaim_conversation_get_gc(g_conv); | |
1234 if(pd->gc != gc) | |
1235 return; /* not ours */ | |
1236 | |
11338 | 1237 if(gaim_conversation_get_type(g_conv) != GAIM_CONV_TYPE_IM) |
10977 | 1238 return; /* wrong type */ |
1239 | |
1240 who.user = (char *) gaim_conversation_get_name(g_conv); | |
1241 conv = mwServiceIm_getConversation(pd->srvc_im, &who); | |
1242 | |
1243 convo_features(conv); | |
1244 | |
1245 if(mwConversation_isClosed(conv)) | |
1246 mwConversation_open(conv); | |
1247 } | |
1248 | |
1249 | |
1250 static void blist_menu_nab(GaimBlistNode *node, gpointer data) { | |
1251 struct mwGaimPluginData *pd = data; | |
1252 GaimConnection *gc; | |
1253 | |
1254 GaimGroup *group = (GaimGroup *) node; | |
1255 | |
1256 GString *str; | |
1257 char *tmp; | |
1258 | |
1259 g_return_if_fail(pd != NULL); | |
1260 | |
1261 gc = pd->gc; | |
1262 g_return_if_fail(gc != NULL); | |
1263 | |
1264 g_return_if_fail(GAIM_BLIST_NODE_IS_GROUP(node)); | |
1265 | |
1266 str = g_string_new(NULL); | |
1267 | |
1268 tmp = (char *) gaim_blist_node_get_string(node, GROUP_KEY_NAME); | |
1269 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1270 g_string_append_printf(str, _("<b>Group Title:</b> %s<br>"), group->name); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1271 g_string_append_printf(str, _("<b>Notes Group ID:</b> %s<br>"), tmp); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1272 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1273 tmp = g_strdup_printf(_("Info for Group %s"), group->name); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1274 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1275 gaim_notify_formatted(gc, tmp, _("Notes Address Book Information"), |
10977 | 1276 NULL, str->str, NULL, NULL); |
1277 | |
1278 g_free(tmp); | |
1279 g_string_free(str, TRUE); | |
1280 } | |
1281 | |
1282 | |
1283 /** The normal blist menu prpl function doesn't get called for groups, | |
1284 so we use the blist-node-extended-menu signal to trigger this | |
1285 handler */ | |
1286 static void blist_node_menu_cb(GaimBlistNode *node, | |
1287 GList **menu, struct mwGaimPluginData *pd) { | |
1288 GaimBlistNodeAction *act; | |
1289 | |
1290 if(GAIM_BLIST_NODE_IS_GROUP(node)) { | |
1291 const char *owner; | |
1292 GaimAccount *acct; | |
1293 | |
1294 owner = gaim_blist_node_get_string(node, GROUP_KEY_OWNER); | |
1295 if(! owner) return; | |
1296 | |
1297 acct = gaim_accounts_find(owner, PLUGIN_ID); | |
1298 if(! acct) return; | |
1299 if(! gaim_account_is_connected(acct)) return; | |
1300 if(acct != gaim_connection_get_account(pd->gc)) return; | |
1301 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1302 act = gaim_blist_node_action_new(_("Get Notes Address Book Info"), |
10977 | 1303 blist_menu_nab, pd, NULL); |
1304 | |
1305 *menu = g_list_append(*menu, NULL); | |
1306 *menu = g_list_append(*menu, act); | |
1307 } | |
1308 } | |
1309 | |
1310 | |
1311 /** Last thing to happen from a started session */ | |
1312 static void services_starting(struct mwGaimPluginData *pd) { | |
1313 | |
1314 GaimConnection *gc; | |
1315 GaimAccount *acct; | |
1316 struct mwStorageUnit *unit; | |
1317 GaimBuddyList *blist; | |
1318 GaimBlistNode *l; | |
1319 | |
1320 gc = pd->gc; | |
1321 acct = gaim_connection_get_account(gc); | |
1322 | |
1323 /* grab the buddy list from the server */ | |
1324 unit = mwStorageUnit_new(mwStore_AWARE_LIST); | |
1325 mwServiceStorage_load(pd->srvc_store, unit, fetch_blist_cb, pd, NULL); | |
1326 | |
1327 /* fetch the away/busy/active messages from the server */ | |
1328 unit = mwStorageUnit_new(mwStore_AWAY_MESSAGES); | |
1329 mwServiceStorage_load(pd->srvc_store, unit, fetch_msg_cb, pd, NULL); | |
1330 | |
1331 unit = mwStorageUnit_new(mwStore_BUSY_MESSAGES); | |
1332 mwServiceStorage_load(pd->srvc_store, unit, fetch_msg_cb, pd, NULL); | |
1333 | |
1334 unit = mwStorageUnit_new(mwStore_ACTIVE_MESSAGES); | |
1335 mwServiceStorage_load(pd->srvc_store, unit, fetch_msg_cb, pd, NULL); | |
1336 | |
1337 /* start watching for new conversations */ | |
1338 gaim_signal_connect(gaim_conversations_get_handle(), | |
1339 "conversation-created", gc, | |
1340 GAIM_CALLBACK(conversation_created_cb), pd); | |
1341 | |
1342 /* watch for group extended menu items */ | |
1343 gaim_signal_connect(gaim_blist_get_handle(), | |
1344 "blist-node-extended-menu", gc, | |
1345 GAIM_CALLBACK(blist_node_menu_cb), pd); | |
1346 | |
1347 /* find all the NAB groups and subscribe to them */ | |
1348 blist = gaim_get_blist(); | |
1349 for(l = blist->root; l; l = l->next) { | |
1350 GaimGroup *group = (GaimGroup *) l; | |
1351 enum mwSametimeGroupType gt; | |
1352 const char *owner; | |
1353 | |
1354 if(! GAIM_BLIST_NODE_IS_GROUP(l)) continue; | |
1355 | |
1356 /* if the group is ownerless, or has an owner and we're not it, | |
1357 skip it */ | |
1358 owner = gaim_blist_node_get_string(l, GROUP_KEY_OWNER); | |
1359 if(!owner || strcmp(owner, gaim_account_get_username(acct))) | |
1360 continue; | |
1361 | |
1362 gt = gaim_blist_node_get_int(l, GROUP_KEY_TYPE); | |
1363 if(gt == mwSametimeGroup_DYNAMIC) | |
1364 group_add(pd, group); | |
1365 } | |
1366 | |
1367 /* set the aware attributes */ | |
1368 /* indicate we understand what AV prefs are, but don't support any */ | |
1369 mwServiceAware_setAttributeBoolean(pd->srvc_aware, | |
1370 mwAttribute_AV_PREFS_SET, TRUE); | |
1371 mwServiceAware_unsetAttribute(pd->srvc_aware, mwAttribute_MICROPHONE); | |
1372 mwServiceAware_unsetAttribute(pd->srvc_aware, mwAttribute_SPEAKERS); | |
1373 mwServiceAware_unsetAttribute(pd->srvc_aware, mwAttribute_VIDEO_CAMERA); | |
1374 | |
1375 /* ... but we can do file transfers! */ | |
1376 mwServiceAware_setAttributeBoolean(pd->srvc_aware, | |
1377 mwAttribute_FILE_TRANSFER, TRUE); | |
1378 } | |
1379 | |
1380 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1381 static void session_loginRedirect(struct mwSession *session, |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1382 const char *host) { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1383 struct mwGaimPluginData *pd; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1384 GaimConnection *gc; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1385 GaimAccount *account; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1386 guint port; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1387 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1388 pd = mwSession_getClientData(session); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1389 gc = pd->gc; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1390 account = gaim_connection_get_account(gc); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1391 port = gaim_account_get_int(account, MW_KEY_PORT, MW_PLUGIN_DEFAULT_PORT); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1392 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1393 if(gaim_account_get_bool(account, MW_KEY_FORCE, FALSE) || |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1394 gaim_proxy_connect(account, host, port, connect_cb, pd)) { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1395 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1396 mwSession_forceLogin(session); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1397 } |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1398 } |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1399 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1400 |
10977 | 1401 /** called from mw_session_stateChange when the session's state is |
1402 mwSession_STARTED. Any finalizing of start-up stuff should go | |
1403 here */ | |
1404 static void session_started(struct mwGaimPluginData *pd) { | |
1405 | |
1406 /* XXX setup status */ | |
1407 | |
1408 /* use our services to do neat things */ | |
1409 services_starting(pd); | |
1410 } | |
1411 | |
1412 | |
1413 static void mw_session_stateChange(struct mwSession *session, | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1414 enum mwSessionState state, |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1415 gpointer info) { |
10977 | 1416 struct mwGaimPluginData *pd; |
1417 GaimConnection *gc; | |
1418 char *msg = NULL; | |
1419 | |
1420 pd = mwSession_getClientData(session); | |
1421 gc = pd->gc; | |
1422 | |
1423 switch(state) { | |
1424 case mwSession_STARTING: | |
1425 msg = _("Sending Handshake"); | |
1426 gaim_connection_update_progress(gc, msg, 2, MW_CONNECT_STEPS); | |
1427 break; | |
1428 | |
1429 case mwSession_HANDSHAKE: | |
1430 msg = _("Waiting for Handshake Acknowledgement"); | |
1431 gaim_connection_update_progress(gc, msg, 3, MW_CONNECT_STEPS); | |
1432 break; | |
1433 | |
1434 case mwSession_HANDSHAKE_ACK: | |
1435 msg = _("Handshake Acknowledged, Sending Login"); | |
1436 gaim_connection_update_progress(gc, msg, 4, MW_CONNECT_STEPS); | |
1437 break; | |
1438 | |
1439 case mwSession_LOGIN: | |
1440 msg = _("Waiting for Login Acknowledgement"); | |
1441 gaim_connection_update_progress(gc, msg, 5, MW_CONNECT_STEPS); | |
1442 break; | |
1443 | |
1444 case mwSession_LOGIN_REDIR: | |
1445 msg = _("Login Redirected"); | |
1446 gaim_connection_update_progress(gc, msg, 6, MW_CONNECT_STEPS); | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1447 session_loginRedirect(session, info); |
10977 | 1448 break; |
1449 | |
11133
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
1450 case mwSession_LOGIN_CONT: |
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
1451 msg = _("Forcing Login"); |
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
1452 gaim_connection_update_progress(gc, msg, 7, MW_CONNECT_STEPS); |
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
1453 |
10977 | 1454 case mwSession_LOGIN_ACK: |
1455 msg = _("Login Acknowledged"); | |
11133
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
1456 gaim_connection_update_progress(gc, msg, 8, MW_CONNECT_STEPS); |
10977 | 1457 break; |
1458 | |
1459 case mwSession_STARTED: | |
1460 msg = _("Connected to Sametime Community Server"); | |
11133
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
1461 gaim_connection_update_progress(gc, msg, 9, MW_CONNECT_STEPS); |
10977 | 1462 gaim_connection_set_state(gc, GAIM_CONNECTED); |
1463 | |
1464 session_started(pd); | |
1465 break; | |
1466 | |
1467 case mwSession_STOPPING: | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1468 if(GPOINTER_TO_UINT(info) & ERR_FAILURE) { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1469 msg = mwError(GPOINTER_TO_UINT(info)); |
10977 | 1470 gaim_connection_error(gc, msg); |
1471 g_free(msg); | |
1472 } | |
1473 break; | |
1474 | |
1475 case mwSession_STOPPED: | |
1476 break; | |
1477 | |
1478 case mwSession_UNKNOWN: | |
1479 default: | |
1480 DEBUG_WARN("session in unknown state\n"); | |
1481 } | |
1482 } | |
1483 | |
1484 | |
1485 static void mw_session_setPrivacyInfo(struct mwSession *session) { | |
1486 struct mwGaimPluginData *pd; | |
1487 GaimConnection *gc; | |
1488 GaimAccount *acct; | |
1489 struct mwPrivacyInfo *privacy; | |
1490 GSList *l, **ll; | |
1491 guint count; | |
1492 | |
1493 DEBUG_INFO("privacy information set from server\n"); | |
1494 | |
1495 g_return_if_fail(session != NULL); | |
1496 | |
1497 pd = mwSession_getClientData(session); | |
1498 g_return_if_fail(pd != NULL); | |
1499 | |
1500 gc = pd->gc; | |
1501 g_return_if_fail(gc != NULL); | |
1502 | |
1503 acct = gaim_connection_get_account(gc); | |
1504 g_return_if_fail(acct != NULL); | |
1505 | |
1506 privacy = mwSession_getPrivacyInfo(session); | |
1507 count = privacy->count; | |
1508 | |
1509 ll = (privacy->deny)? &acct->deny: &acct->permit; | |
1510 for(l = *ll; l; l = l->next) g_free(l->data); | |
1511 g_slist_free(*ll); | |
1512 l = *ll = NULL; | |
1513 | |
1514 while(count--) { | |
1515 struct mwUserItem *u = privacy->users + count; | |
1516 l = g_slist_prepend(l, g_strdup(u->id)); | |
1517 } | |
1518 *ll = l; | |
1519 } | |
1520 | |
1521 | |
1522 static void mw_session_setUserStatus(struct mwSession *session) { | |
1523 struct mwGaimPluginData *pd; | |
1524 GaimConnection *gc; | |
1525 struct mwAwareIdBlock idb = { mwAware_USER, NULL, NULL }; | |
1526 struct mwUserStatus *stat; | |
1527 | |
1528 g_return_if_fail(session != NULL); | |
1529 | |
1530 pd = mwSession_getClientData(session); | |
1531 g_return_if_fail(pd != NULL); | |
1532 | |
1533 gc = pd->gc; | |
1534 g_return_if_fail(gc != NULL); | |
1535 | |
1536 idb.user = mwSession_getProperty(session, mwSession_AUTH_USER_ID); | |
1537 stat = mwSession_getUserStatus(session); | |
1538 | |
1539 /* trigger an update of our own status if we're in the buddy list */ | |
1540 mwServiceAware_setStatus(pd->srvc_aware, &idb, stat); | |
1541 } | |
1542 | |
1543 | |
1544 static void mw_session_admin(struct mwSession *session, | |
1545 const char *text) { | |
1546 | |
1547 GaimConnection *gc = session_to_gc(session); | |
1548 g_return_if_fail(gc != NULL); | |
1549 | |
1550 /** @todo Admin alerts should probably be in a conversation window | |
1551 rather than a gaim_notify_message. Or in some sort of updating | |
1552 dialog, or something. */ | |
1553 | |
1554 gaim_notify_message(gc, GAIM_NOTIFY_MSG_INFO, _("Admin Alert"), | |
1555 text, NULL, NULL, NULL); | |
1556 } | |
1557 | |
1558 | |
1559 /** called from read_cb, attempts to read available data from sock and | |
1560 pass it to the session, passing back the return code from the read | |
1561 call for handling in read_cb */ | |
1562 static int read_recv(struct mwSession *session, int sock) { | |
1563 char buf[BUF_LEN]; | |
1564 int len; | |
1565 | |
1566 len = read(sock, buf, BUF_LEN); | |
1567 if(len > 0) mwSession_recv(session, buf, len); | |
1568 | |
1569 return len; | |
1570 } | |
1571 | |
1572 | |
1573 /** callback triggered from gaim_input_add, watches the socked for | |
1574 available data to be processed by the session */ | |
1575 static void read_cb(gpointer data, gint source, | |
1576 GaimInputCondition cond) { | |
1577 | |
1578 struct mwGaimPluginData *pd = data; | |
1579 int ret = 0, err = 0; | |
1580 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1581 /* How the heck can this happen? Fix submitted to Gaim so that it |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1582 won't happen anymore. */ |
11133
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
1583 if(! cond) return; |
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
1584 |
10977 | 1585 g_return_if_fail(pd != NULL); |
11133
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
1586 g_return_if_fail(cond & GAIM_INPUT_READ); |
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
1587 |
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
1588 ret = read_recv(pd->session, pd->socket); |
10977 | 1589 |
1590 /* normal operation ends here */ | |
1591 if(ret > 0) return; | |
1592 | |
11133
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
1593 /* fetch the global error value */ |
10977 | 1594 err = errno; |
1595 | |
1596 /* read problem occured if we're here, so we'll need to take care of | |
1597 it and clean up internal state */ | |
1598 | |
1599 if(pd->socket) { | |
1600 close(pd->socket); | |
1601 pd->socket = 0; | |
1602 } | |
1603 | |
1604 if(pd->gc->inpa) { | |
1605 gaim_input_remove(pd->gc->inpa); | |
1606 pd->gc->inpa = 0; | |
1607 } | |
1608 | |
1609 if(! ret) { | |
1610 DEBUG_INFO("connection reset\n"); | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1611 gaim_connection_error(pd->gc, _("Connection reset")); |
10977 | 1612 |
1613 } else if(ret < 0) { | |
1614 char *msg = strerror(err); | |
11133
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
1615 |
10977 | 1616 DEBUG_INFO("error in read callback: %s\n", msg); |
1617 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1618 msg = g_strdup_printf(_("Error reading from socket: %s"), msg); |
10977 | 1619 gaim_connection_error(pd->gc, msg); |
1620 g_free(msg); | |
1621 } | |
1622 } | |
1623 | |
1624 | |
1625 /** Callback passed to gaim_proxy_connect when an account is logged | |
1626 in, and if the session logging in receives a redirect message */ | |
1627 static void connect_cb(gpointer data, gint source, | |
1628 GaimInputCondition cond) { | |
1629 | |
1630 struct mwGaimPluginData *pd = data; | |
1631 GaimConnection *gc = pd->gc; | |
1632 | |
1633 if(! g_list_find(gaim_connections_get_all(), pd->gc)) { | |
1634 close(source); | |
1635 g_return_if_reached(); | |
1636 } | |
1637 | |
1638 if(source < 0) { | |
1639 /* connection failed */ | |
1640 | |
1641 if(pd->socket) { | |
1642 /* this is a redirect connect, force login on existing socket */ | |
1643 mwSession_forceLogin(pd->session); | |
1644 | |
1645 } else { | |
1646 /* this is a regular connect, error out */ | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1647 gaim_connection_error(pd->gc, _("Unable to connect to host")); |
10977 | 1648 } |
1649 | |
1650 return; | |
1651 } | |
1652 | |
1653 if(pd->socket) { | |
1654 /* stop any existing login attempt */ | |
1655 mwSession_stop(pd->session, ERR_SUCCESS); | |
1656 } | |
1657 | |
1658 pd->socket = source; | |
1659 gc->inpa = gaim_input_add(source, GAIM_INPUT_READ, read_cb, pd); | |
1660 | |
1661 mwSession_start(pd->session); | |
1662 } | |
1663 | |
1664 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1665 static void mw_session_announce(struct mwSession *s, |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1666 struct mwLoginInfo *from, |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1667 gboolean may_reply, |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1668 const char *text) { |
10977 | 1669 struct mwGaimPluginData *pd; |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1670 GaimAccount *acct; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1671 GaimConversation *conv; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1672 GSList *buddies; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1673 char *who = from->user_id; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1674 char *msg; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1675 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1676 pd = mwSession_getClientData(s); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1677 acct = gaim_connection_get_account(pd->gc); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1678 conv = gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM, who, acct); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1679 if(! conv) conv = gaim_conversation_new(GAIM_CONV_TYPE_IM, acct, who); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1680 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1681 buddies = gaim_find_buddies(acct, who); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1682 if(buddies) { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1683 who = (char *) gaim_buddy_get_contact_alias(buddies->data); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1684 g_slist_free(buddies); |
10977 | 1685 } |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1686 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1687 who = g_strdup_printf(_("Announcement from %s"), who); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1688 msg = gaim_markup_linkify(text); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1689 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1690 gaim_conversation_write(conv, who, msg, GAIM_MESSAGE_RECV, time(NULL)); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1691 g_free(who); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1692 g_free(msg); |
10977 | 1693 } |
1694 | |
1695 | |
1696 static struct mwSessionHandler mw_session_handler = { | |
1697 .io_write = mw_session_io_write, | |
1698 .io_close = mw_session_io_close, | |
1699 .clear = mw_session_clear, | |
1700 .on_stateChange = mw_session_stateChange, | |
1701 .on_setPrivacyInfo = mw_session_setPrivacyInfo, | |
1702 .on_setUserStatus = mw_session_setUserStatus, | |
1703 .on_admin = mw_session_admin, | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1704 .on_announce = mw_session_announce, |
10977 | 1705 }; |
1706 | |
1707 | |
1708 static void mw_aware_on_attrib(struct mwServiceAware *srvc, | |
1709 struct mwAwareAttribute *attrib) { | |
1710 | |
1711 ; /** @todo handle server attributes. There may be some stuff we | |
1712 actually want to look for, but I'm not aware of anything right | |
1713 now.*/ | |
1714 } | |
1715 | |
1716 | |
1717 static void mw_aware_clear(struct mwServiceAware *srvc) { | |
1718 ; /* nothing for now */ | |
1719 } | |
1720 | |
1721 | |
1722 static struct mwAwareHandler mw_aware_handler = { | |
1723 .on_attrib = mw_aware_on_attrib, | |
1724 .clear = mw_aware_clear, | |
1725 }; | |
1726 | |
1727 | |
1728 static struct mwServiceAware *mw_srvc_aware_new(struct mwSession *s) { | |
1729 struct mwServiceAware *srvc; | |
1730 srvc = mwServiceAware_new(s, &mw_aware_handler); | |
1731 return srvc; | |
1732 }; | |
1733 | |
1734 | |
1735 static void mw_conf_invited(struct mwConference *conf, | |
1736 struct mwLoginInfo *inviter, | |
1737 const char *invitation) { | |
1738 | |
1739 struct mwServiceConference *srvc; | |
1740 struct mwSession *session; | |
1741 struct mwGaimPluginData *pd; | |
1742 GaimConnection *gc; | |
1743 | |
1744 char *c_inviter, *c_name, *c_topic, *c_invitation; | |
1745 GHashTable *ht; | |
1746 | |
1747 srvc = mwConference_getService(conf); | |
1748 session = mwService_getSession(MW_SERVICE(srvc)); | |
1749 pd = mwSession_getClientData(session); | |
1750 gc = pd->gc; | |
1751 | |
1752 ht = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free); | |
1753 | |
1754 c_inviter = g_strdup(inviter->user_id); | |
1755 g_hash_table_insert(ht, CHAT_KEY_CREATOR, c_inviter); | |
1756 | |
1757 c_name = g_strdup(mwConference_getName(conf)); | |
1758 g_hash_table_insert(ht, CHAT_KEY_NAME, c_name); | |
1759 | |
1760 c_topic = g_strdup(mwConference_getTitle(conf)); | |
1761 g_hash_table_insert(ht, CHAT_KEY_TOPIC, c_topic); | |
1762 | |
1763 c_invitation = g_strdup(invitation); | |
1764 g_hash_table_insert(ht, CHAT_KEY_INVITE, c_invitation); | |
1765 | |
1766 DEBUG_INFO("received invitation from '%s' to join ('%s','%s'): '%s'\n", | |
1767 NSTR(c_inviter), NSTR(c_name), | |
1768 NSTR(c_topic), NSTR(c_invitation)); | |
1769 | |
1770 serv_got_chat_invite(gc, c_topic, c_inviter, c_invitation, ht); | |
1771 } | |
1772 | |
1773 | |
1774 /* The following mess helps us relate a mwConference to a GaimConvChat | |
1775 in the various forms by which either may be indicated */ | |
1776 | |
1777 #define CONF_TO_ID(conf) (GPOINTER_TO_INT(conf)) | |
1778 #define ID_TO_CONF(pd, id) (conf_find_by_id((pd), (id))) | |
1779 | |
1780 #define CHAT_TO_ID(chat) (gaim_conv_chat_get_id(chat)) | |
1781 #define ID_TO_CHAT(id) (gaim_find_chat(id)) | |
1782 | |
11133
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
1783 #define CHAT_TO_CONF(pd, chat) (ID_TO_CONF((pd), CHAT_TO_ID(chat))) |
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
1784 #define CONF_TO_CHAT(conf) (ID_TO_CHAT(CONF_TO_ID(conf))) |
10977 | 1785 |
1786 | |
1787 static struct mwConference * | |
1788 conf_find_by_id(struct mwGaimPluginData *pd, int id) { | |
1789 | |
1790 struct mwServiceConference *srvc = pd->srvc_conf; | |
1791 struct mwConference *conf = NULL; | |
1792 GList *l, *ll; | |
1793 | |
1794 ll = mwServiceConference_getConferences(srvc); | |
1795 for(l = ll; l; l = l->next) { | |
1796 struct mwConference *c = l->data; | |
1797 GaimConvChat *h = mwConference_getClientData(c); | |
1798 | |
1799 if(CHAT_TO_ID(h) == id) { | |
1800 conf = c; | |
1801 break; | |
1802 } | |
1803 } | |
1804 g_list_free(ll); | |
1805 | |
1806 return conf; | |
1807 } | |
1808 | |
1809 | |
1810 static void mw_conf_opened(struct mwConference *conf, GList *members) { | |
1811 struct mwServiceConference *srvc; | |
1812 struct mwSession *session; | |
1813 struct mwGaimPluginData *pd; | |
1814 GaimConnection *gc; | |
1815 GaimConversation *g_conf; | |
1816 | |
1817 const char *n = mwConference_getName(conf); | |
1818 | |
1819 DEBUG_INFO("conf %s opened, %u initial members\n", | |
1820 NSTR(n), g_list_length(members)); | |
1821 | |
1822 srvc = mwConference_getService(conf); | |
1823 session = mwService_getSession(MW_SERVICE(srvc)); | |
1824 pd = mwSession_getClientData(session); | |
1825 gc = pd->gc; | |
1826 | |
1827 g_conf = serv_got_joined_chat(gc, CONF_TO_ID(conf), | |
1828 mwConference_getTitle(conf)); | |
1829 | |
1830 mwConference_setClientData(conf, GAIM_CONV_CHAT(g_conf), NULL); | |
1831 | |
1832 for(; members; members = members->next) { | |
1833 struct mwLoginInfo *peer = members->data; | |
1834 gaim_conv_chat_add_user(GAIM_CONV_CHAT(g_conf), peer->user_id, | |
1835 NULL, GAIM_CBFLAGS_NONE, FALSE); | |
1836 } | |
1837 } | |
1838 | |
1839 | |
1840 static void mw_conf_closed(struct mwConference *conf, guint32 reason) { | |
1841 struct mwServiceConference *srvc; | |
1842 struct mwSession *session; | |
1843 struct mwGaimPluginData *pd; | |
1844 GaimConnection *gc; | |
1845 | |
1846 const char *n = mwConference_getName(conf); | |
1847 char *msg = mwError(reason); | |
1848 | |
1849 DEBUG_INFO("conf %s closed, 0x%08x\n", NSTR(n), reason); | |
1850 | |
1851 srvc = mwConference_getService(conf); | |
1852 session = mwService_getSession(MW_SERVICE(srvc)); | |
1853 pd = mwSession_getClientData(session); | |
1854 gc = pd->gc; | |
1855 | |
1856 serv_got_chat_left(gc, CONF_TO_ID(conf)); | |
1857 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
1858 gaim_notify_error(gc, _("Conference Closed"), NULL, msg); |
10977 | 1859 g_free(msg); |
1860 } | |
1861 | |
1862 | |
1863 static void mw_conf_peer_joined(struct mwConference *conf, | |
1864 struct mwLoginInfo *peer) { | |
1865 | |
1866 struct mwServiceConference *srvc; | |
1867 struct mwSession *session; | |
1868 struct mwGaimPluginData *pd; | |
1869 GaimConnection *gc; | |
1870 GaimConvChat *g_conf; | |
1871 | |
1872 const char *n = mwConference_getName(conf); | |
1873 | |
1874 DEBUG_INFO("%s joined conf %s\n", NSTR(peer->user_id), NSTR(n)); | |
1875 | |
1876 srvc = mwConference_getService(conf); | |
1877 session = mwService_getSession(MW_SERVICE(srvc)); | |
1878 pd = mwSession_getClientData(session); | |
1879 gc = pd->gc; | |
1880 | |
1881 g_conf = mwConference_getClientData(conf); | |
1882 g_return_if_fail(g_conf != NULL); | |
1883 | |
1884 gaim_conv_chat_add_user(g_conf, peer->user_id, | |
1885 NULL, GAIM_CBFLAGS_NONE, TRUE); | |
1886 } | |
1887 | |
1888 | |
1889 static void mw_conf_peer_parted(struct mwConference *conf, | |
1890 struct mwLoginInfo *peer) { | |
1891 | |
1892 struct mwServiceConference *srvc; | |
1893 struct mwSession *session; | |
1894 struct mwGaimPluginData *pd; | |
1895 GaimConnection *gc; | |
1896 GaimConvChat *g_conf; | |
1897 | |
1898 const char *n = mwConference_getName(conf); | |
1899 | |
1900 DEBUG_INFO("%s left conf %s\n", NSTR(peer->user_id), NSTR(n)); | |
1901 | |
1902 srvc = mwConference_getService(conf); | |
1903 session = mwService_getSession(MW_SERVICE(srvc)); | |
1904 pd = mwSession_getClientData(session); | |
1905 gc = pd->gc; | |
1906 | |
1907 g_conf = mwConference_getClientData(conf); | |
1908 g_return_if_fail(g_conf != NULL); | |
1909 | |
1910 gaim_conv_chat_remove_user(g_conf, peer->user_id, NULL); | |
1911 } | |
1912 | |
1913 | |
1914 static void mw_conf_text(struct mwConference *conf, | |
1915 struct mwLoginInfo *who, const char *text) { | |
1916 | |
1917 struct mwServiceConference *srvc; | |
1918 struct mwSession *session; | |
1919 struct mwGaimPluginData *pd; | |
1920 GaimConnection *gc; | |
1921 char *esc; | |
1922 | |
1923 srvc = mwConference_getService(conf); | |
1924 session = mwService_getSession(MW_SERVICE(srvc)); | |
1925 pd = mwSession_getClientData(session); | |
1926 gc = pd->gc; | |
1927 | |
1928 esc = g_markup_escape_text(text, -1); | |
1929 serv_got_chat_in(gc, CONF_TO_ID(conf), who->user_id, 0, esc, time(NULL)); | |
1930 g_free(esc); | |
1931 } | |
1932 | |
1933 | |
1934 static void mw_conf_typing(struct mwConference *conf, | |
1935 struct mwLoginInfo *who, gboolean typing) { | |
1936 | |
1937 /* gaim really has no good way to expose this to the user. */ | |
1938 | |
1939 const char *n = mwConference_getName(conf); | |
1940 const char *w = who->user_id; | |
1941 | |
1942 if(typing) { | |
1943 DEBUG_INFO("%s in conf %s: <typing>\n", NSTR(w), NSTR(n)); | |
1944 | |
1945 } else { | |
1946 DEBUG_INFO("%s in conf %s: <stopped typing>\n", NSTR(w), NSTR(n)); | |
1947 } | |
1948 } | |
1949 | |
1950 | |
1951 static void mw_conf_clear(struct mwServiceConference *srvc) { | |
1952 ; | |
1953 } | |
1954 | |
1955 | |
1956 static struct mwConferenceHandler mw_conference_handler = { | |
1957 .on_invited = mw_conf_invited, | |
1958 .conf_opened = mw_conf_opened, | |
1959 .conf_closed = mw_conf_closed, | |
1960 .on_peer_joined = mw_conf_peer_joined, | |
1961 .on_peer_parted = mw_conf_peer_parted, | |
1962 .on_text = mw_conf_text, | |
1963 .on_typing = mw_conf_typing, | |
1964 .clear = mw_conf_clear, | |
1965 }; | |
1966 | |
1967 | |
1968 static struct mwServiceConference *mw_srvc_conf_new(struct mwSession *s) { | |
1969 struct mwServiceConference *srvc; | |
1970 srvc = mwServiceConference_new(s, &mw_conference_handler); | |
1971 return srvc; | |
1972 } | |
1973 | |
1974 | |
1975 static void ft_incoming_cancel(GaimXfer *xfer) { | |
1976 /* incoming transfer rejected or canceled in-progress */ | |
1977 struct mwFileTransfer *ft = xfer->data; | |
1978 if(ft) mwFileTransfer_reject(ft); | |
1979 } | |
1980 | |
1981 | |
1982 static void ft_incoming_init(GaimXfer *xfer) { | |
1983 /* incoming transfer accepted */ | |
1984 | |
1985 /* - accept the mwFileTransfer | |
1986 - open/create the local FILE "wb" | |
1987 - stick the FILE's fp in xfer->dest_fp | |
1988 */ | |
1989 | |
1990 struct mwFileTransfer *ft; | |
1991 FILE *fp; | |
1992 | |
1993 ft = xfer->data; | |
1994 | |
1995 fp = g_fopen(xfer->local_filename, "wb"); | |
1996 if(! fp) { | |
1997 mwFileTransfer_cancel(ft); | |
1998 return; | |
1999 } | |
2000 | |
2001 xfer->dest_fp = fp; | |
2002 mwFileTransfer_accept(ft); | |
2003 } | |
2004 | |
2005 | |
2006 static void mw_ft_offered(struct mwFileTransfer *ft) { | |
2007 /* | |
2008 - create a gaim ft object | |
2009 - offer it | |
2010 */ | |
2011 | |
2012 struct mwServiceFileTransfer *srvc; | |
2013 struct mwSession *session; | |
2014 struct mwGaimPluginData *pd; | |
2015 GaimConnection *gc; | |
2016 GaimAccount *acct; | |
2017 const char *who; | |
2018 GaimXfer *xfer; | |
2019 | |
2020 /* @todo add some safety checks */ | |
2021 srvc = mwFileTransfer_getService(ft); | |
2022 session = mwService_getSession(MW_SERVICE(srvc)); | |
2023 pd = mwSession_getClientData(session); | |
2024 gc = pd->gc; | |
2025 acct = gaim_connection_get_account(gc); | |
2026 | |
2027 who = mwFileTransfer_getUser(ft)->user; | |
2028 | |
2029 DEBUG_INFO("file transfer %p offered\n", ft); | |
2030 DEBUG_INFO(" from: %s\n", NSTR(who)); | |
2031 DEBUG_INFO(" file: %s\n", NSTR(mwFileTransfer_getFileName(ft))); | |
2032 DEBUG_INFO(" size: %u\n", mwFileTransfer_getFileSize(ft)); | |
2033 DEBUG_INFO(" text: %s\n", NSTR(mwFileTransfer_getMessage(ft))); | |
2034 | |
2035 xfer = gaim_xfer_new(acct, GAIM_XFER_RECEIVE, who); | |
2036 | |
2037 gaim_xfer_ref(xfer); | |
2038 mwFileTransfer_setClientData(ft, xfer, (GDestroyNotify) gaim_xfer_unref); | |
2039 xfer->data = ft; | |
2040 | |
2041 gaim_xfer_set_init_fnc(xfer, ft_incoming_init); | |
2042 gaim_xfer_set_cancel_recv_fnc(xfer, ft_incoming_cancel); | |
2043 gaim_xfer_set_request_denied_fnc(xfer, ft_incoming_cancel); | |
2044 | |
2045 gaim_xfer_set_filename(xfer, mwFileTransfer_getFileName(ft)); | |
2046 gaim_xfer_set_size(xfer, mwFileTransfer_getFileSize(ft)); | |
2047 gaim_xfer_set_message(xfer, mwFileTransfer_getMessage(ft)); | |
2048 | |
2049 gaim_xfer_request(xfer); | |
2050 } | |
2051 | |
2052 | |
2053 static void ft_send(struct mwFileTransfer *ft, FILE *fp) { | |
2054 char buf[BUF_LONG]; | |
2055 struct mwOpaque o = { .data = buf, .len = BUF_LONG }; | |
2056 guint32 rem; | |
2057 GaimXfer *xfer; | |
2058 | |
2059 xfer = mwFileTransfer_getClientData(ft); | |
2060 | |
2061 rem = mwFileTransfer_getRemaining(ft); | |
2062 if(rem < BUF_LONG) o.len = rem; | |
2063 | |
2064 if(fread(buf, (size_t) o.len, 1, fp)) { | |
2065 | |
2066 /* calculate progress first. update is displayed upon ack */ | |
2067 xfer->bytes_sent += o.len; | |
2068 xfer->bytes_remaining -= o.len; | |
2069 | |
2070 /* ... send data second */ | |
2071 mwFileTransfer_send(ft, &o); | |
2072 | |
2073 } else { | |
2074 int err = errno; | |
2075 DEBUG_WARN("problem reading from file %s: %s", | |
2076 NSTR(mwFileTransfer_getFileName(ft)), strerror(err)); | |
2077 | |
2078 mwFileTransfer_cancel(ft); | |
2079 } | |
2080 } | |
2081 | |
2082 | |
2083 static gboolean ft_idle_cb(struct mwFileTransfer *ft) { | |
2084 GaimXfer *xfer = mwFileTransfer_getClientData(ft); | |
2085 g_return_val_if_fail(xfer != NULL, FALSE); | |
2086 | |
2087 xfer->watcher = 0; | |
2088 ft_send(ft, xfer->dest_fp); | |
2089 | |
2090 return FALSE; | |
2091 } | |
2092 | |
2093 | |
2094 static void mw_ft_opened(struct mwFileTransfer *ft) { | |
2095 /* | |
2096 - get gaim ft from client data in ft | |
2097 - set the state to active | |
2098 */ | |
2099 | |
2100 GaimXfer *xfer; | |
2101 | |
2102 xfer = mwFileTransfer_getClientData(ft); | |
2103 | |
2104 if(! xfer) { | |
2105 mwFileTransfer_cancel(ft); | |
2106 mwFileTransfer_free(ft); | |
2107 g_return_if_reached(); | |
2108 } | |
2109 | |
2110 gaim_xfer_update_progress(xfer); | |
2111 | |
2112 if(gaim_xfer_get_type(xfer) == GAIM_XFER_SEND) { | |
2113 xfer->watcher = g_idle_add((GSourceFunc)ft_idle_cb, ft); | |
2114 xfer->dest_fp = g_fopen(xfer->local_filename, "rb"); | |
2115 } | |
2116 } | |
2117 | |
2118 | |
2119 static void mw_ft_closed(struct mwFileTransfer *ft, guint32 code) { | |
2120 /* | |
2121 - get gaim ft from client data in ft | |
2122 - indicate rejection/cancelation/completion | |
2123 - free the file transfer itself | |
2124 */ | |
2125 | |
2126 GaimXfer *xfer; | |
2127 | |
2128 xfer = mwFileTransfer_getClientData(ft); | |
2129 if(xfer) { | |
2130 xfer->data = NULL; | |
2131 | |
2132 if(mwFileTransfer_isDone(ft)) { | |
2133 gaim_xfer_set_completed(xfer, TRUE); | |
2134 gaim_xfer_end(xfer); | |
2135 | |
2136 } else if(mwFileTransfer_isCancelLocal(ft)) { | |
2137 /* calling gaim_xfer_cancel_local is redundant, since that's | |
2138 probably what triggered this function to be called */ | |
2139 ; | |
2140 | |
2141 } else if(mwFileTransfer_isCancelRemote(ft)) { | |
2142 /* steal the reference for the xfer */ | |
2143 mwFileTransfer_setClientData(ft, NULL, NULL); | |
2144 gaim_xfer_cancel_remote(xfer); | |
2145 | |
2146 /* drop the stolen reference */ | |
2147 gaim_xfer_unref(xfer); | |
2148 return; | |
2149 } | |
2150 } | |
2151 | |
2152 mwFileTransfer_free(ft); | |
2153 } | |
2154 | |
2155 | |
2156 static void mw_ft_recv(struct mwFileTransfer *ft, | |
2157 struct mwOpaque *data) { | |
2158 /* | |
2159 - get gaim ft from client data in ft | |
2160 - update transfered percentage | |
2161 - if done, destroy the ft, disassociate from gaim ft | |
2162 */ | |
2163 | |
2164 GaimXfer *xfer; | |
2165 FILE *fp; | |
2166 | |
2167 xfer = mwFileTransfer_getClientData(ft); | |
2168 g_return_if_fail(xfer != NULL); | |
2169 | |
2170 fp = xfer->dest_fp; | |
2171 g_return_if_fail(fp != NULL); | |
2172 | |
2173 /* we must collect and save our precious data */ | |
2174 fwrite(data->data, 1, data->len, fp); | |
2175 | |
2176 /* update the progress */ | |
2177 xfer->bytes_sent += data->len; | |
2178 xfer->bytes_remaining -= data->len; | |
2179 gaim_xfer_update_progress(xfer); | |
2180 | |
2181 /* let the other side know we got it, and to send some more */ | |
2182 mwFileTransfer_ack(ft); | |
2183 } | |
2184 | |
2185 | |
2186 static void mw_ft_ack(struct mwFileTransfer *ft) { | |
2187 GaimXfer *xfer; | |
2188 | |
2189 xfer = mwFileTransfer_getClientData(ft); | |
2190 g_return_if_fail(xfer != NULL); | |
2191 g_return_if_fail(xfer->watcher == 0); | |
2192 | |
2193 gaim_xfer_update_progress(xfer); | |
2194 | |
2195 if(mwFileTransfer_isOpen(ft)) | |
2196 xfer->watcher = g_idle_add((GSourceFunc)ft_idle_cb, ft); | |
2197 } | |
2198 | |
2199 | |
2200 static void mw_ft_clear(struct mwServiceFileTransfer *srvc) { | |
2201 ; | |
2202 } | |
2203 | |
2204 | |
2205 static struct mwFileTransferHandler mw_ft_handler = { | |
2206 .ft_offered = mw_ft_offered, | |
2207 .ft_opened = mw_ft_opened, | |
2208 .ft_closed = mw_ft_closed, | |
2209 .ft_recv = mw_ft_recv, | |
2210 .ft_ack = mw_ft_ack, | |
2211 .clear = mw_ft_clear, | |
2212 }; | |
2213 | |
2214 | |
2215 static struct mwServiceFileTransfer *mw_srvc_ft_new(struct mwSession *s) { | |
2216 struct mwServiceFileTransfer *srvc; | |
2217 GHashTable *ft_map; | |
2218 | |
2219 ft_map = g_hash_table_new(g_direct_hash, g_direct_equal); | |
2220 | |
2221 srvc = mwServiceFileTransfer_new(s, &mw_ft_handler); | |
2222 mwService_setClientData(MW_SERVICE(srvc), ft_map, | |
2223 (GDestroyNotify) g_hash_table_destroy); | |
2224 | |
2225 return srvc; | |
2226 } | |
2227 | |
2228 | |
2229 static void convo_data_free(struct convo_data *cd) { | |
2230 GList *l; | |
2231 | |
2232 /* clean the queue */ | |
2233 for(l = cd->queue; l; l = g_list_delete_link(l, l)) { | |
2234 struct convo_msg *m = l->data; | |
2235 if(m->clear) m->clear(m->data); | |
2236 g_free(m); | |
2237 } | |
2238 | |
2239 g_free(cd); | |
2240 } | |
2241 | |
2242 | |
2243 /** allocates a convo_data structure and associates it with the | |
2244 conversation in the client data slot */ | |
2245 static void convo_data_new(struct mwConversation *conv) { | |
2246 struct convo_data *cd; | |
2247 | |
2248 g_return_if_fail(conv != NULL); | |
2249 | |
2250 if(mwConversation_getClientData(conv)) | |
2251 return; | |
2252 | |
2253 cd = g_new0(struct convo_data, 1); | |
2254 cd->conv = conv; | |
2255 | |
2256 mwConversation_setClientData(conv, cd, (GDestroyNotify) convo_data_free); | |
2257 } | |
2258 | |
2259 | |
2260 static GaimConversation *convo_get_gconv(struct mwConversation *conv) { | |
2261 struct mwServiceIm *srvc; | |
2262 struct mwSession *session; | |
2263 struct mwGaimPluginData *pd; | |
2264 GaimConnection *gc; | |
2265 GaimAccount *acct; | |
2266 | |
2267 struct mwIdBlock *idb; | |
2268 | |
2269 srvc = mwConversation_getService(conv); | |
2270 session = mwService_getSession(MW_SERVICE(srvc)); | |
2271 pd = mwSession_getClientData(session); | |
2272 gc = pd->gc; | |
2273 acct = gaim_connection_get_account(gc); | |
2274 | |
2275 idb = mwConversation_getTarget(conv); | |
2276 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2277 return gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM, |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2278 idb->user, acct); |
10977 | 2279 } |
2280 | |
2281 | |
2282 static void convo_queue(struct mwConversation *conv, | |
2283 enum mwImSendType type, gconstpointer data) { | |
2284 | |
2285 struct convo_data *cd; | |
2286 struct convo_msg *m; | |
2287 | |
2288 convo_data_new(conv); | |
2289 cd = mwConversation_getClientData(conv); | |
2290 | |
2291 m = g_new0(struct convo_msg, 1); | |
2292 m->type = type; | |
2293 | |
2294 switch(type) { | |
2295 case mwImSend_PLAIN: | |
2296 m->data = g_strdup(data); | |
2297 m->clear = g_free; | |
2298 break; | |
2299 | |
2300 case mwImSend_TYPING: | |
2301 default: | |
2302 m->data = (gpointer) data; | |
2303 m->clear = NULL; | |
2304 } | |
2305 | |
2306 cd->queue = g_list_append(cd->queue, m); | |
2307 } | |
2308 | |
2309 | |
2310 /* Does what it takes to get an error displayed for a conversation */ | |
2311 static void convo_error(struct mwConversation *conv, guint32 err) { | |
2312 GaimConversation *gconv; | |
2313 char *tmp, *text; | |
2314 struct mwIdBlock *idb; | |
2315 | |
2316 idb = mwConversation_getTarget(conv); | |
2317 | |
2318 tmp = mwError(err); | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2319 text = g_strconcat(_("Unable to send message: "), tmp, NULL); |
10977 | 2320 |
2321 gconv = convo_get_gconv(conv); | |
2322 if(gconv && !gaim_conv_present_error(idb->user, gconv->account, text)) { | |
2323 | |
2324 g_free(text); | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2325 text = g_strdup_printf(_("Unable to send message to %s:"), |
10977 | 2326 (idb->user)? idb->user: "(unknown)"); |
2327 gaim_notify_error(gaim_account_get_connection(gconv->account), | |
2328 NULL, text, tmp); | |
2329 } | |
2330 | |
2331 g_free(tmp); | |
2332 g_free(text); | |
2333 } | |
2334 | |
2335 | |
2336 static void convo_queue_send(struct mwConversation *conv) { | |
2337 struct convo_data *cd; | |
2338 GList *l; | |
2339 | |
2340 cd = mwConversation_getClientData(conv); | |
2341 | |
2342 for(l = cd->queue; l; l = g_list_delete_link(l, l)) { | |
2343 struct convo_msg *m = l->data; | |
2344 | |
2345 mwConversation_send(conv, m->type, m->data); | |
2346 | |
2347 if(m->clear) m->clear(m->data); | |
2348 g_free(m); | |
2349 } | |
2350 | |
2351 cd->queue = NULL; | |
2352 } | |
2353 | |
2354 | |
2355 /** called when a mw conversation leaves a gaim conversation to | |
2356 inform the gaim conversation that it's unsafe to offer any *cool* | |
2357 features. */ | |
2358 static void convo_nofeatures(struct mwConversation *conv) { | |
2359 GaimConversation *gconv; | |
2360 GaimConnection *gc; | |
2361 | |
2362 gconv = convo_get_gconv(conv); | |
2363 if(! gconv) return; | |
2364 | |
2365 gc = gaim_conversation_get_gc(gconv); | |
11133
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
2366 if(! gc) return; |
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
2367 |
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
2368 gaim_conversation_set_features(gconv, gc->flags); |
10977 | 2369 } |
2370 | |
2371 | |
2372 /** called when a mw conversation and gaim conversation come together, | |
2373 to inform the gaim conversation of what features to offer the | |
2374 user */ | |
2375 static void convo_features(struct mwConversation *conv) { | |
2376 GaimConversation *gconv; | |
2377 GaimConnectionFlags feat; | |
2378 | |
2379 gconv = convo_get_gconv(conv); | |
2380 if(! gconv) return; | |
2381 | |
2382 feat = gaim_conversation_get_features(gconv); | |
2383 | |
2384 if(mwConversation_isOpen(conv)) { | |
2385 if(mwConversation_supports(conv, mwImSend_HTML)) { | |
2386 feat |= GAIM_CONNECTION_HTML; | |
2387 } else { | |
2388 feat &= ~GAIM_CONNECTION_HTML; | |
2389 } | |
2390 | |
2391 if(mwConversation_supports(conv, mwImSend_MIME)) { | |
2392 feat &= ~GAIM_CONNECTION_NO_IMAGES; | |
2393 } else { | |
2394 feat |= GAIM_CONNECTION_NO_IMAGES; | |
2395 } | |
2396 | |
2397 DEBUG_INFO("conversation features set to 0x%04x\n", feat); | |
2398 gaim_conversation_set_features(gconv, feat); | |
2399 | |
2400 } else { | |
2401 convo_nofeatures(conv); | |
2402 } | |
2403 } | |
2404 | |
2405 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2406 #if 0 |
10977 | 2407 /** triggered from mw_conversation_opened if the appropriate plugin |
2408 preference is set. This will open a window for the conversation | |
2409 before the first message is sent. */ | |
2410 static void convo_do_psychic(struct mwConversation *conv) { | |
2411 struct mwServiceIm *srvc; | |
2412 struct mwSession *session; | |
2413 struct mwGaimPluginData *pd; | |
2414 GaimConnection *gc; | |
2415 GaimAccount *acct; | |
2416 | |
2417 struct mwIdBlock *idb; | |
2418 | |
2419 GaimConversation *gconv; | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2420 GaimConvWindow *win; |
10977 | 2421 |
2422 srvc = mwConversation_getService(conv); | |
2423 session = mwService_getSession(MW_SERVICE(srvc)); | |
2424 pd = mwSession_getClientData(session); | |
2425 gc = pd->gc; | |
2426 acct = gaim_connection_get_account(gc); | |
2427 | |
2428 idb = mwConversation_getTarget(conv); | |
2429 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2430 gconv = gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM, |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2431 idb->user, acct); |
10977 | 2432 if(! gconv) { |
11338 | 2433 gconv = gaim_conversation_new(GAIM_CONV_TYPE_IM, acct, idb->user); |
10977 | 2434 } |
2435 | |
2436 g_return_if_fail(gconv != NULL); | |
2437 | |
2438 win = gaim_conversation_get_window(gconv); | |
2439 g_return_if_fail(win != NULL); | |
2440 | |
2441 gaim_conv_window_show(win); | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2442 } |
11547 | 2443 #endif |
10977 | 2444 |
2445 | |
2446 static void mw_conversation_opened(struct mwConversation *conv) { | |
2447 struct mwServiceIm *srvc; | |
2448 struct mwSession *session; | |
2449 struct mwGaimPluginData *pd; | |
2450 GaimConnection *gc; | |
2451 GaimAccount *acct; | |
2452 | |
2453 struct convo_dat *cd; | |
2454 | |
2455 srvc = mwConversation_getService(conv); | |
2456 session = mwService_getSession(MW_SERVICE(srvc)); | |
2457 pd = mwSession_getClientData(session); | |
2458 gc = pd->gc; | |
2459 acct = gaim_connection_get_account(gc); | |
2460 | |
2461 /* set up the queue */ | |
2462 cd = mwConversation_getClientData(conv); | |
2463 if(cd) { | |
2464 convo_queue_send(conv); | |
2465 | |
2466 if(! convo_get_gconv(conv)) { | |
2467 mwConversation_free(conv); | |
2468 return; | |
2469 } | |
2470 | |
2471 } else { | |
2472 convo_data_new(conv); | |
2473 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2474 #if 0 |
10977 | 2475 if(gaim_prefs_get_bool(MW_PRPL_OPT_PSYCHIC)) { |
2476 convo_do_psychic(conv); | |
2477 } | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2478 #endif |
10977 | 2479 } |
2480 | |
2481 { /* record the client key for the buddy */ | |
2482 GaimBuddy *buddy; | |
2483 struct mwLoginInfo *info; | |
2484 info = mwConversation_getTargetInfo(conv); | |
2485 | |
2486 buddy = gaim_find_buddy(acct, info->user_id); | |
2487 if(buddy) { | |
2488 gaim_blist_node_set_int((GaimBlistNode *) buddy, | |
2489 BUDDY_KEY_CLIENT, info->type); | |
2490 } | |
2491 } | |
2492 | |
2493 convo_features(conv); | |
2494 } | |
2495 | |
2496 | |
2497 static void mw_conversation_closed(struct mwConversation *conv, | |
2498 guint32 reason) { | |
2499 | |
2500 struct convo_data *cd; | |
2501 | |
2502 g_return_if_fail(conv != NULL); | |
2503 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2504 /* if there's an error code and a non-typing message in the queue, |
11133
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
2505 print an error message to the conversation */ |
10977 | 2506 cd = mwConversation_getClientData(conv); |
2507 if(reason && cd && cd->queue) { | |
11133
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
2508 GList *l; |
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
2509 for(l = cd->queue; l; l = l->next) { |
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
2510 struct convo_msg *m = l->data; |
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
2511 if(m->type != mwImSend_TYPING) { |
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
2512 convo_error(conv, reason); |
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
2513 break; |
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
2514 } |
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
2515 } |
10977 | 2516 } |
2517 | |
2518 #if 0 | |
2519 /* don't do this, to prevent the occasional weird sending of | |
2520 formatted messages as plaintext when the other end closes the | |
2521 conversation after we've begun composing the message */ | |
2522 convo_nofeatures(conv); | |
2523 #endif | |
2524 | |
2525 mwConversation_removeClientData(conv); | |
2526 } | |
2527 | |
2528 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2529 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2530 static char *im_decode(GaimConnection *gc, const char *msg) { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2531 return gaim_utf8_try_convert(msg); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2532 } |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2533 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2534 |
10977 | 2535 static void im_recv_text(struct mwConversation *conv, |
2536 struct mwGaimPluginData *pd, | |
2537 const char *msg) { | |
2538 | |
2539 struct mwIdBlock *idb; | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2540 char *txt, *esc, *t; |
10977 | 2541 |
2542 idb = mwConversation_getTarget(conv); | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2543 txt = im_decode(pd->gc, msg); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2544 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2545 t = txt? txt: (char *) msg; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2546 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2547 esc = g_markup_escape_text(t, -1); |
10977 | 2548 serv_got_im(pd->gc, idb->user, esc, 0, time(NULL)); |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2549 g_free(esc); |
10977 | 2550 |
2551 g_free(txt); | |
2552 } | |
2553 | |
2554 | |
2555 static void im_recv_typing(struct mwConversation *conv, | |
2556 struct mwGaimPluginData *pd, | |
2557 gboolean typing) { | |
2558 | |
2559 struct mwIdBlock *idb; | |
2560 idb = mwConversation_getTarget(conv); | |
2561 | |
2562 serv_got_typing(pd->gc, idb->user, 0, | |
2563 typing? GAIM_TYPING: GAIM_NOT_TYPING); | |
2564 } | |
2565 | |
2566 | |
2567 static void im_recv_html(struct mwConversation *conv, | |
2568 struct mwGaimPluginData *pd, | |
2569 const char *msg) { | |
2570 | |
2571 struct mwIdBlock *idb; | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2572 char *txt, *t; |
10977 | 2573 |
2574 idb = mwConversation_getTarget(conv); | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2575 txt = im_decode(pd->gc, msg); |
10977 | 2576 |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2577 t = txt? txt: (char *) msg; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2578 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2579 serv_got_im(pd->gc, idb->user, t, 0, time(NULL)); |
10977 | 2580 |
2581 g_free(txt); | |
2582 } | |
2583 | |
2584 | |
2585 static void im_recv_subj(struct mwConversation *conv, | |
2586 struct mwGaimPluginData *pd, | |
2587 const char *subj) { | |
2588 | |
2589 /** @todo somehow indicate receipt of a conversation subject. It | |
2590 would also be nice if we added a /topic command for the | |
2591 protocol */ | |
2592 ; | |
2593 } | |
2594 | |
2595 | |
2596 /** generate "cid:908@20582notesbuddy" from "<908@20582notesbuddy>" */ | |
2597 static char *make_cid(const char *cid) { | |
2598 gsize n; | |
2599 char *c, *d; | |
2600 | |
2601 g_return_val_if_fail(cid != NULL, NULL); | |
2602 | |
2603 n = strlen(cid); | |
2604 g_return_val_if_fail(n > 2, NULL); | |
2605 | |
2606 c = g_strndup(cid+1, n-2); | |
2607 d = g_strdup_printf("cid:%s", c); | |
2608 | |
2609 g_free(c); | |
2610 return d; | |
2611 } | |
2612 | |
2613 | |
2614 static void im_recv_mime(struct mwConversation *conv, | |
2615 struct mwGaimPluginData *pd, | |
2616 const char *data) { | |
2617 | |
2618 struct mwIdBlock *idb; | |
2619 | |
2620 GHashTable *img_by_cid; | |
2621 GList *images; | |
2622 | |
2623 GString *str; | |
2624 | |
2625 GaimMimeDocument *doc; | |
2626 const GList *parts; | |
2627 | |
2628 idb = mwConversation_getTarget(conv); | |
2629 | |
2630 img_by_cid = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); | |
2631 images = NULL; | |
2632 | |
2633 /* don't want the contained string to ever be NULL */ | |
2634 str = g_string_new(""); | |
2635 | |
2636 doc = gaim_mime_document_parse(data); | |
2637 | |
2638 /* handle all the MIME parts */ | |
2639 parts = gaim_mime_document_get_parts(doc); | |
2640 for(; parts; parts = parts->next) { | |
2641 GaimMimePart *part = parts->data; | |
2642 const char *type; | |
2643 | |
2644 type = gaim_mime_part_get_field(part, "content-type"); | |
2645 DEBUG_INFO("MIME part Content-Type: %s\n", NSTR(type)); | |
2646 | |
2647 if(! type) { | |
2648 ; /* feh */ | |
2649 | |
2650 } else if(g_str_has_prefix(type, "image")) { | |
2651 /* put images into the image store */ | |
2652 | |
11183 | 2653 guchar *d_dat; |
10977 | 2654 gsize d_len; |
2655 char *cid; | |
2656 int img; | |
2657 | |
2658 /* obtain and unencode the data */ | |
2659 gaim_mime_part_get_data_decoded(part, &d_dat, &d_len); | |
2660 | |
2661 /* look up the content id */ | |
2662 cid = (char *) gaim_mime_part_get_field(part, "Content-ID"); | |
2663 cid = make_cid(cid); | |
2664 | |
2665 /* add image to the gaim image store */ | |
2666 img = gaim_imgstore_add(d_dat, d_len, cid); | |
11133
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
2667 g_free(d_dat); |
10977 | 2668 |
2669 /* map the cid to the image store identifier */ | |
2670 g_hash_table_insert(img_by_cid, cid, GINT_TO_POINTER(img)); | |
2671 | |
2672 /* recall the image for dereferencing later */ | |
2673 images = g_list_append(images, GINT_TO_POINTER(img)); | |
2674 | |
2675 } else if(g_str_has_prefix(type, "text")) { | |
2676 | |
2677 /* concatenate all the text parts together */ | |
11183 | 2678 guchar *data; |
11132 | 2679 char *txt; |
10977 | 2680 gsize len; |
2681 | |
2682 gaim_mime_part_get_data_decoded(part, &data, &len); | |
11133
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
2683 |
11953 | 2684 txt = im_decode(pd->gc, (const char *)data); |
2685 g_string_append(str, txt?txt:(const char *)data); | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2686 |
11133
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
2687 g_free(data); |
10977 | 2688 g_free(txt); |
2689 } | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2690 } |
10977 | 2691 |
2692 gaim_mime_document_free(doc); | |
2693 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2694 /* @todo should put this in its own function */ |
10977 | 2695 { /* replace each IMG tag's SRC attribute with an ID attribute. This |
2696 actually modifies the contents of str */ | |
2697 GData *attribs; | |
2698 char *start, *end; | |
2699 char *tmp = str->str; | |
2700 | |
2701 while(*tmp && gaim_markup_find_tag("img", tmp, (const char **) &start, | |
2702 (const char **) &end, &attribs)) { | |
2703 | |
2704 char *alt, *align, *border, *src; | |
2705 int img; | |
2706 | |
2707 alt = g_datalist_get_data(&attribs, "alt"); | |
2708 align = g_datalist_get_data(&attribs, "align"); | |
2709 border = g_datalist_get_data(&attribs, "border"); | |
2710 src = g_datalist_get_data(&attribs, "src"); | |
2711 | |
2712 img = GPOINTER_TO_INT(g_hash_table_lookup(img_by_cid, src)); | |
2713 if(img) { | |
2714 GString *atstr; | |
2715 gsize len = (end - start); | |
2716 gsize mov; | |
2717 | |
2718 atstr = g_string_new(""); | |
2719 if(alt) g_string_append_printf(atstr, " alt=\"%s\"", alt); | |
2720 if(align) g_string_append_printf(atstr, " align=\"%s\"", align); | |
2721 if(border) g_string_append_printf(atstr, " border=\"%s\"", border); | |
2722 | |
2723 mov = g_snprintf(start, len, "<img%s id=\"%i\"", atstr->str, img); | |
2724 while(mov < len) start[mov++] = ' '; | |
2725 | |
2726 g_string_free(atstr, TRUE); | |
2727 } | |
2728 | |
2729 g_datalist_clear(&attribs); | |
2730 tmp = end + 1; | |
2731 } | |
2732 } | |
2733 | |
2734 /* actually display the message */ | |
2735 serv_got_im(pd->gc, idb->user, str->str, 0, time(NULL)); | |
2736 | |
2737 g_string_free(str, TRUE); | |
2738 | |
2739 /* clean up the cid table */ | |
2740 g_hash_table_destroy(img_by_cid); | |
2741 | |
2742 /* dereference all the imgages */ | |
2743 while(images) { | |
2744 gaim_imgstore_unref(GPOINTER_TO_INT(images->data)); | |
2745 images = g_list_delete_link(images, images); | |
2746 } | |
2747 } | |
2748 | |
2749 | |
2750 static void mw_conversation_recv(struct mwConversation *conv, | |
2751 enum mwImSendType type, | |
2752 gconstpointer msg) { | |
2753 struct mwServiceIm *srvc; | |
2754 struct mwSession *session; | |
2755 struct mwGaimPluginData *pd; | |
2756 | |
2757 srvc = mwConversation_getService(conv); | |
2758 session = mwService_getSession(MW_SERVICE(srvc)); | |
2759 pd = mwSession_getClientData(session); | |
2760 | |
2761 switch(type) { | |
2762 case mwImSend_PLAIN: | |
2763 im_recv_text(conv, pd, msg); | |
2764 break; | |
2765 | |
2766 case mwImSend_TYPING: | |
2767 im_recv_typing(conv, pd, !! msg); | |
2768 break; | |
2769 | |
2770 case mwImSend_HTML: | |
2771 im_recv_html(conv, pd, msg); | |
2772 break; | |
2773 | |
2774 case mwImSend_SUBJECT: | |
2775 im_recv_subj(conv, pd, msg); | |
2776 break; | |
2777 | |
2778 case mwImSend_MIME: | |
2779 im_recv_mime(conv, pd, msg); | |
2780 break; | |
2781 | |
2782 default: | |
2783 DEBUG_INFO("conversation received strange type, 0x%04x\n", type); | |
2784 ; /* erm... */ | |
2785 } | |
2786 } | |
2787 | |
2788 | |
2789 static void mw_place_invite(struct mwConversation *conv, | |
2790 const char *message, | |
2791 const char *title, const char *name) { | |
2792 struct mwServiceIm *srvc; | |
2793 struct mwSession *session; | |
2794 struct mwGaimPluginData *pd; | |
2795 | |
2796 struct mwIdBlock *idb; | |
2797 GHashTable *ht; | |
2798 | |
2799 srvc = mwConversation_getService(conv); | |
2800 session = mwService_getSession(MW_SERVICE(srvc)); | |
2801 pd = mwSession_getClientData(session); | |
2802 | |
2803 idb = mwConversation_getTarget(conv); | |
2804 | |
2805 ht = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free); | |
2806 g_hash_table_insert(ht, CHAT_KEY_CREATOR, g_strdup(idb->user)); | |
2807 g_hash_table_insert(ht, CHAT_KEY_NAME, g_strdup(name)); | |
2808 g_hash_table_insert(ht, CHAT_KEY_TOPIC, g_strdup(title)); | |
2809 g_hash_table_insert(ht, CHAT_KEY_INVITE, g_strdup(message)); | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2810 g_hash_table_insert(ht, CHAT_KEY_IS_PLACE, g_strdup("")); /* ugh */ |
10977 | 2811 |
2812 serv_got_chat_invite(pd->gc, title, idb->user, message, ht); | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2813 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2814 mwConversation_close(conv, ERR_SUCCESS); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2815 mwConversation_free(conv); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2816 } |
10977 | 2817 |
2818 | |
2819 static void mw_im_clear(struct mwServiceIm *srvc) { | |
2820 ; | |
2821 } | |
2822 | |
2823 | |
2824 static struct mwImHandler mw_im_handler = { | |
2825 .conversation_opened = mw_conversation_opened, | |
2826 .conversation_closed = mw_conversation_closed, | |
2827 .conversation_recv = mw_conversation_recv, | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2828 .place_invite = mw_place_invite, |
10977 | 2829 .clear = mw_im_clear, |
2830 }; | |
2831 | |
2832 | |
2833 static struct mwServiceIm *mw_srvc_im_new(struct mwSession *s) { | |
2834 struct mwServiceIm *srvc; | |
2835 srvc = mwServiceIm_new(s, &mw_im_handler); | |
2836 mwServiceIm_setClientType(srvc, mwImClient_NOTESBUDDY); | |
2837 return srvc; | |
2838 } | |
2839 | |
2840 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2841 /* The following helps us relate a mwPlace to a GaimConvChat in the |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2842 various forms by which either may be indicated. Uses some of |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2843 the similar macros from the conference service above */ |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2844 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2845 #define PLACE_TO_ID(place) (GPOINTER_TO_INT(place)) |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2846 #define ID_TO_PLACE(pd, id) (place_find_by_id((pd), (id))) |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2847 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2848 #define CHAT_TO_PLACE(pd, chat) (ID_TO_PLACE((pd), CHAT_TO_ID(chat))) |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2849 #define PLACE_TO_CHAT(place) (ID_TO_CHAT(PLACE_TO_ID(place))) |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2850 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2851 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2852 static struct mwPlace * |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2853 place_find_by_id(struct mwGaimPluginData *pd, int id) { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2854 struct mwServicePlace *srvc = pd->srvc_place; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2855 struct mwPlace *place = NULL; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2856 GList *l; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2857 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2858 l = (GList *) mwServicePlace_getPlaces(srvc); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2859 for(; l; l = l->next) { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2860 struct mwPlace *p = l->data; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2861 GaimConvChat *h = GAIM_CONV_CHAT(mwPlace_getClientData(p)); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2862 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2863 if(CHAT_TO_ID(h) == id) { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2864 place = p; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2865 break; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2866 } |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2867 } |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2868 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2869 return place; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2870 } |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2871 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2872 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2873 static void mw_place_opened(struct mwPlace *place) { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2874 struct mwServicePlace *srvc; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2875 struct mwSession *session; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2876 struct mwGaimPluginData *pd; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2877 GaimConnection *gc; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2878 GaimConversation *gconf; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2879 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2880 GList *members, *l; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2881 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2882 const char *n = mwPlace_getName(place); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2883 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2884 srvc = mwPlace_getService(place); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2885 session = mwService_getSession(MW_SERVICE(srvc)); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2886 pd = mwSession_getClientData(session); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2887 gc = pd->gc; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2888 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2889 members = mwPlace_getMembers(place); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2890 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2891 DEBUG_INFO("place %s opened, %u initial members\n", |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2892 NSTR(n), g_list_length(members)); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2893 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2894 gconf = serv_got_joined_chat(gc, PLACE_TO_ID(place), |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2895 mwPlace_getTitle(place)); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2896 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2897 mwPlace_setClientData(place, gconf, NULL); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2898 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2899 for(l = members; l; l = l->next) { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2900 struct mwIdBlock *idb = l->data; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2901 gaim_conv_chat_add_user(GAIM_CONV_CHAT(gconf), idb->user, |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2902 NULL, GAIM_CBFLAGS_NONE, FALSE); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2903 } |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2904 g_list_free(members); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2905 } |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2906 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2907 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2908 static void mw_place_closed(struct mwPlace *place, guint32 code) { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2909 struct mwServicePlace *srvc; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2910 struct mwSession *session; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2911 struct mwGaimPluginData *pd; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2912 GaimConnection *gc; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2913 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2914 const char *n = mwPlace_getName(place); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2915 char *msg = mwError(code); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2916 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2917 DEBUG_INFO("place %s closed, 0x%08x\n", NSTR(n), code); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2918 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2919 srvc = mwPlace_getService(place); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2920 session = mwService_getSession(MW_SERVICE(srvc)); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2921 pd = mwSession_getClientData(session); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2922 gc = pd->gc; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2923 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2924 serv_got_chat_left(gc, PLACE_TO_ID(place)); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2925 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2926 gaim_notify_error(gc, _("Place Closed"), NULL, msg); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2927 g_free(msg); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2928 } |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2929 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2930 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2931 static void mw_place_peerJoined(struct mwPlace *place, |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2932 const struct mwIdBlock *peer) { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2933 struct mwServicePlace *srvc; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2934 struct mwSession *session; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2935 struct mwGaimPluginData *pd; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2936 GaimConnection *gc; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2937 GaimConversation *gconf; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2938 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2939 const char *n = mwPlace_getName(place); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2940 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2941 DEBUG_INFO("%s joined place %s\n", NSTR(peer->user), NSTR(n)); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2942 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2943 srvc = mwPlace_getService(place); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2944 session = mwService_getSession(MW_SERVICE(srvc)); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2945 pd = mwSession_getClientData(session); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2946 gc = pd->gc; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2947 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2948 gconf = mwPlace_getClientData(place); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2949 g_return_if_fail(gconf != NULL); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2950 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2951 gaim_conv_chat_add_user(GAIM_CONV_CHAT(gconf), peer->user, |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2952 NULL, GAIM_CBFLAGS_NONE, TRUE); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2953 } |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2954 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2955 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2956 static void mw_place_peerParted(struct mwPlace *place, |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2957 const struct mwIdBlock *peer) { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2958 struct mwServicePlace *srvc; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2959 struct mwSession *session; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2960 struct mwGaimPluginData *pd; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2961 GaimConnection *gc; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2962 GaimConversation *gconf; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2963 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2964 const char *n = mwPlace_getName(place); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2965 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2966 DEBUG_INFO("%s left place %s\n", NSTR(peer->user), NSTR(n)); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2967 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2968 srvc = mwPlace_getService(place); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2969 session = mwService_getSession(MW_SERVICE(srvc)); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2970 pd = mwSession_getClientData(session); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2971 gc = pd->gc; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2972 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2973 gconf = mwPlace_getClientData(place); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2974 g_return_if_fail(gconf != NULL); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2975 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2976 gaim_conv_chat_remove_user(GAIM_CONV_CHAT(gconf), peer->user, NULL); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2977 } |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2978 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2979 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2980 static void mw_place_peerSetAttribute(struct mwPlace *place, |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2981 const struct mwIdBlock *peer, |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2982 guint32 attr, struct mwOpaque *o) { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2983 ; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2984 } |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2985 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2986 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2987 static void mw_place_peerUnsetAttribute(struct mwPlace *place, |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2988 const struct mwIdBlock *peer, |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2989 guint32 attr) { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2990 ; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2991 } |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2992 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2993 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2994 static void mw_place_message(struct mwPlace *place, |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2995 const struct mwIdBlock *who, |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2996 const char *msg) { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2997 struct mwServicePlace *srvc; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2998 struct mwSession *session; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
2999 struct mwGaimPluginData *pd; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3000 GaimConnection *gc; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3001 char *esc; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3002 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3003 srvc = mwPlace_getService(place); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3004 session = mwService_getSession(MW_SERVICE(srvc)); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3005 pd = mwSession_getClientData(session); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3006 gc = pd->gc; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3007 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3008 esc = g_markup_escape_text(msg, -1); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3009 serv_got_chat_in(gc, PLACE_TO_ID(place), who->user, 0, esc, time(NULL)); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3010 g_free(esc); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3011 } |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3012 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3013 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3014 static void mw_place_clear(struct mwServicePlace *srvc) { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3015 ; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3016 } |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3017 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3018 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3019 static struct mwPlaceHandler mw_place_handler = { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3020 .opened = mw_place_opened, |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3021 .closed = mw_place_closed, |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3022 .peerJoined = mw_place_peerJoined, |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3023 .peerParted = mw_place_peerParted, |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3024 .peerSetAttribute = mw_place_peerSetAttribute, |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3025 .peerUnsetAttribute = mw_place_peerUnsetAttribute, |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3026 .message = mw_place_message, |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3027 .clear = mw_place_clear, |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3028 }; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3029 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3030 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3031 static struct mwServicePlace *mw_srvc_place_new(struct mwSession *s) { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3032 struct mwServicePlace *srvc; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3033 srvc = mwServicePlace_new(s, &mw_place_handler); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3034 return srvc; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3035 } |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3036 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3037 |
10977 | 3038 static struct mwServiceResolve *mw_srvc_resolve_new(struct mwSession *s) { |
3039 struct mwServiceResolve *srvc; | |
3040 srvc = mwServiceResolve_new(s); | |
3041 return srvc; | |
3042 } | |
3043 | |
3044 | |
3045 static struct mwServiceStorage *mw_srvc_store_new(struct mwSession *s) { | |
3046 struct mwServiceStorage *srvc; | |
3047 srvc = mwServiceStorage_new(s); | |
3048 return srvc; | |
3049 } | |
3050 | |
3051 | |
3052 /** allocate and associate a mwGaimPluginData with a GaimConnection */ | |
3053 static struct mwGaimPluginData *mwGaimPluginData_new(GaimConnection *gc) { | |
3054 struct mwGaimPluginData *pd; | |
3055 | |
3056 g_return_val_if_fail(gc != NULL, NULL); | |
3057 | |
3058 pd = g_new0(struct mwGaimPluginData, 1); | |
3059 pd->gc = gc; | |
3060 pd->session = mwSession_new(&mw_session_handler); | |
3061 pd->srvc_aware = mw_srvc_aware_new(pd->session); | |
3062 pd->srvc_conf = mw_srvc_conf_new(pd->session); | |
3063 pd->srvc_ft = mw_srvc_ft_new(pd->session); | |
3064 pd->srvc_im = mw_srvc_im_new(pd->session); | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3065 pd->srvc_place = mw_srvc_place_new(pd->session); |
10977 | 3066 pd->srvc_resolve = mw_srvc_resolve_new(pd->session); |
3067 pd->srvc_store = mw_srvc_store_new(pd->session); | |
3068 pd->group_list_map = g_hash_table_new(g_direct_hash, g_direct_equal); | |
3069 | |
3070 mwSession_addService(pd->session, MW_SERVICE(pd->srvc_aware)); | |
3071 mwSession_addService(pd->session, MW_SERVICE(pd->srvc_conf)); | |
3072 mwSession_addService(pd->session, MW_SERVICE(pd->srvc_ft)); | |
3073 mwSession_addService(pd->session, MW_SERVICE(pd->srvc_im)); | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3074 mwSession_addService(pd->session, MW_SERVICE(pd->srvc_place)); |
10977 | 3075 mwSession_addService(pd->session, MW_SERVICE(pd->srvc_resolve)); |
3076 mwSession_addService(pd->session, MW_SERVICE(pd->srvc_store)); | |
3077 | |
3078 mwSession_addCipher(pd->session, mwCipher_new_RC2_40(pd->session)); | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3079 mwSession_addCipher(pd->session, mwCipher_new_RC2_128(pd->session)); |
10977 | 3080 |
3081 mwSession_setClientData(pd->session, pd, NULL); | |
3082 gc->proto_data = pd; | |
3083 | |
3084 return pd; | |
3085 } | |
3086 | |
3087 | |
3088 static void mwGaimPluginData_free(struct mwGaimPluginData *pd) { | |
3089 g_return_if_fail(pd != NULL); | |
3090 | |
3091 pd->gc->proto_data = NULL; | |
3092 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3093 mwSession_removeService(pd->session, mwService_AWARE); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3094 mwSession_removeService(pd->session, mwService_CONFERENCE); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3095 mwSession_removeService(pd->session, mwService_FILE_TRANSFER); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3096 mwSession_removeService(pd->session, mwService_IM); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3097 mwSession_removeService(pd->session, mwService_PLACE); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3098 mwSession_removeService(pd->session, mwService_RESOLVE); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3099 mwSession_removeService(pd->session, mwService_STORAGE); |
10977 | 3100 |
3101 mwService_free(MW_SERVICE(pd->srvc_aware)); | |
3102 mwService_free(MW_SERVICE(pd->srvc_conf)); | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3103 mwService_free(MW_SERVICE(pd->srvc_ft)); |
10977 | 3104 mwService_free(MW_SERVICE(pd->srvc_im)); |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3105 mwService_free(MW_SERVICE(pd->srvc_place)); |
10977 | 3106 mwService_free(MW_SERVICE(pd->srvc_resolve)); |
3107 mwService_free(MW_SERVICE(pd->srvc_store)); | |
3108 | |
3109 mwCipher_free(mwSession_getCipher(pd->session, mwCipher_RC2_40)); | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3110 mwCipher_free(mwSession_getCipher(pd->session, mwCipher_RC2_128)); |
10977 | 3111 |
3112 mwSession_free(pd->session); | |
3113 | |
3114 g_hash_table_destroy(pd->group_list_map); | |
3115 | |
3116 g_free(pd); | |
3117 } | |
3118 | |
3119 | |
3120 static const char *mw_prpl_list_icon(GaimAccount *a, GaimBuddy *b) { | |
3121 /* my little green dude is a chopped up version of the aim running | |
3122 guy. First, cut off the head and store someplace safe. Then, | |
3123 take the left-half side of the body and throw it away. Make a | |
3124 copy of the remaining body, and flip it horizontally. Now attach | |
3125 the two pieces into an X shape, and drop the head back on the | |
3126 top, being careful to center it. Then, just change the color | |
3127 saturation to bring the red down a bit, and voila! */ | |
3128 | |
3129 /* then, throw all of that away and use sodipodi to make a new | |
3130 icon. You know, LIKE A REAL MAN. */ | |
3131 | |
3132 return "meanwhile"; | |
3133 } | |
3134 | |
3135 | |
3136 static void mw_prpl_list_emblems(GaimBuddy *b, | |
3137 const char **se, const char **sw, | |
3138 const char **nw, const char **ne) { | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3139 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3140 /* speaking of custom icons, the external icon here is an ugly |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3141 little example of what happens when I use Gimp */ |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3142 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3143 GaimPresence *presence; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3144 GaimStatus *status; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3145 const char *status_id; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3146 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3147 presence = gaim_buddy_get_presence(b); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3148 status = gaim_presence_get_active_status(presence); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3149 status_id = gaim_status_get_id(status); |
10977 | 3150 |
3151 if(! GAIM_BUDDY_IS_ONLINE(b)) { | |
3152 *se = "offline"; | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3153 } else if(!strcmp(status_id, MW_STATE_AWAY)) { |
10977 | 3154 *se = "away"; |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3155 } else if(!strcmp(status_id, MW_STATE_BUSY)) { |
10977 | 3156 *se = "dnd"; |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3157 } |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3158 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3159 if(buddy_is_external(b)) { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3160 /* best assignment ever */ |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3161 *(*se?sw:se) = "external"; |
10977 | 3162 } |
3163 } | |
3164 | |
3165 | |
3166 static char *mw_prpl_status_text(GaimBuddy *b) { | |
3167 GaimConnection *gc; | |
3168 struct mwGaimPluginData *pd; | |
3169 struct mwAwareIdBlock t = { mwAware_USER, b->name, NULL }; | |
3170 const char *ret; | |
3171 | |
3172 gc = b->account->gc; | |
3173 pd = gc->proto_data; | |
3174 | |
3175 ret = mwServiceAware_getText(pd->srvc_aware, &t); | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3176 return g_strdup(ret); |
10977 | 3177 } |
3178 | |
3179 | |
3180 static const char *status_text(GaimBuddy *b) { | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3181 GaimPresence *presence; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3182 GaimStatus *status; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3183 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3184 presence = gaim_buddy_get_presence(b); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3185 status = gaim_presence_get_active_status(presence); |
11536 | 3186 |
3187 return gaim_status_get_name(status); | |
10977 | 3188 } |
3189 | |
3190 | |
3191 static gboolean user_supports(struct mwServiceAware *srvc, | |
3192 const char *who, guint32 feature) { | |
3193 | |
3194 const struct mwAwareAttribute *attr; | |
3195 struct mwAwareIdBlock idb = { mwAware_USER, (char *) who, NULL }; | |
3196 | |
3197 attr = mwServiceAware_getAttribute(srvc, &idb, feature); | |
3198 return (attr != NULL) && mwAwareAttribute_asBoolean(attr); | |
3199 } | |
3200 | |
3201 | |
3202 char *user_supports_text(struct mwServiceAware *srvc, const char *who) { | |
3203 char *feat[] = {NULL, NULL, NULL, NULL, NULL}; | |
3204 char **f = feat; | |
3205 | |
3206 if(user_supports(srvc, who, mwAttribute_AV_PREFS_SET)) { | |
3207 gboolean mic, speak, video; | |
3208 | |
3209 mic = user_supports(srvc, who, mwAttribute_MICROPHONE); | |
3210 speak = user_supports(srvc, who, mwAttribute_SPEAKERS); | |
3211 video = user_supports(srvc, who, mwAttribute_VIDEO_CAMERA); | |
3212 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3213 if(mic) *f++ = _("Microphone"); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3214 if(speak) *f++ = _("Speakers"); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3215 if(video) *f++ = _("Video Camera"); |
10977 | 3216 } |
3217 | |
3218 if(user_supports(srvc, who, mwAttribute_FILE_TRANSFER)) | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3219 *f++ = _("File Transfer"); |
10977 | 3220 |
3221 return (*feat)? g_strjoinv(", ", feat): NULL; | |
3222 /* jenni loves siege */ | |
3223 } | |
3224 | |
3225 | |
3226 static char *mw_prpl_tooltip_text(GaimBuddy *b) { | |
3227 GaimConnection *gc; | |
3228 struct mwGaimPluginData *pd; | |
3229 struct mwAwareIdBlock idb = { mwAware_USER, b->name, NULL }; | |
3230 | |
3231 GString *str; | |
3232 const char *tmp; | |
3233 | |
3234 gc = b->account->gc; | |
3235 pd = gc->proto_data; | |
3236 | |
3237 str = g_string_new(NULL); | |
3238 | |
3239 tmp = status_text(b); | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3240 g_string_append_printf(str, _("\n<b>Status</b>: %s"), tmp); |
10977 | 3241 |
3242 tmp = mwServiceAware_getText(pd->srvc_aware, &idb); | |
11133
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
3243 if(tmp) { |
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
3244 tmp = g_markup_escape_text(tmp, -1); |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3245 g_string_append_printf(str, _("\n<b>Message</b>: %s"), tmp); |
11133
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
3246 g_free((char *) tmp); |
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
3247 } |
10977 | 3248 |
3249 tmp = user_supports_text(pd->srvc_aware, b->name); | |
3250 if(tmp) { | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3251 g_string_append_printf(str, _("\n<b>Supports</b>: %s"), tmp); |
10977 | 3252 g_free((char *) tmp); |
3253 } | |
3254 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3255 if(buddy_is_external(b)) { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3256 g_string_append(str, _("\n<b>External User</b>")); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3257 } |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3258 |
10977 | 3259 tmp = str->str; |
3260 g_string_free(str, FALSE); | |
3261 return (char *) tmp; | |
3262 } | |
3263 | |
3264 | |
3265 static GList *mw_prpl_status_types(GaimAccount *acct) { | |
3266 GList *types = NULL; | |
3267 GaimStatusType *type; | |
3268 | |
3269 type = gaim_status_type_new(GAIM_STATUS_OFFLINE, MW_STATE_OFFLINE, | |
3270 _("Offline"), TRUE); | |
3271 types = g_list_append(types, type); | |
3272 | |
3273 type = gaim_status_type_new(GAIM_STATUS_AVAILABLE, MW_STATE_ACTIVE, | |
3274 _("Active"), TRUE); | |
3275 gaim_status_type_add_attr(type, MW_STATE_MESSAGE, _("Message"), | |
3276 gaim_value_new(GAIM_TYPE_STRING)); | |
3277 types = g_list_append(types, type); | |
3278 | |
3279 type = gaim_status_type_new(GAIM_STATUS_AWAY, MW_STATE_AWAY, | |
3280 _("Away"), TRUE); | |
3281 gaim_status_type_add_attr(type, MW_STATE_MESSAGE, _("Message"), | |
3282 gaim_value_new(GAIM_TYPE_STRING)); | |
3283 types = g_list_append(types, type); | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3284 |
10977 | 3285 type = gaim_status_type_new(GAIM_STATUS_UNAVAILABLE, MW_STATE_BUSY, |
3286 _("Do Not Disturb"), TRUE); | |
3287 gaim_status_type_add_attr(type, MW_STATE_MESSAGE, _("Message"), | |
3288 gaim_value_new(GAIM_TYPE_STRING)); | |
3289 types = g_list_append(types, type); | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3290 |
10977 | 3291 return types; |
3292 } | |
3293 | |
3294 | |
3295 static void conf_create_prompt_cancel(GaimBuddy *buddy, | |
3296 GaimRequestFields *fields) { | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3297 ; /* nothing to do */ |
10977 | 3298 } |
3299 | |
3300 | |
3301 static void conf_create_prompt_join(GaimBuddy *buddy, | |
3302 GaimRequestFields *fields) { | |
3303 GaimAccount *acct; | |
3304 GaimConnection *gc; | |
3305 struct mwGaimPluginData *pd; | |
3306 struct mwServiceConference *srvc; | |
3307 | |
3308 GaimRequestField *f; | |
3309 | |
3310 const char *topic, *invite; | |
3311 struct mwConference *conf; | |
3312 struct mwIdBlock idb = { NULL, NULL }; | |
3313 | |
3314 acct = buddy->account; | |
3315 gc = gaim_account_get_connection(acct); | |
3316 pd = gc->proto_data; | |
3317 srvc = pd->srvc_conf; | |
3318 | |
3319 f = gaim_request_fields_get_field(fields, CHAT_KEY_TOPIC); | |
3320 topic = gaim_request_field_string_get_value(f); | |
3321 | |
3322 f = gaim_request_fields_get_field(fields, CHAT_KEY_INVITE); | |
3323 invite = gaim_request_field_string_get_value(f); | |
3324 | |
3325 conf = mwConference_new(srvc, topic); | |
3326 mwConference_open(conf); | |
3327 | |
3328 idb.user = buddy->name; | |
3329 mwConference_invite(conf, &idb, invite); | |
3330 } | |
3331 | |
3332 | |
3333 static void blist_menu_conf_create(GaimBuddy *buddy, const char *msg) { | |
3334 | |
3335 GaimRequestFields *fields; | |
3336 GaimRequestFieldGroup *g; | |
3337 GaimRequestField *f; | |
3338 | |
3339 GaimAccount *acct; | |
3340 GaimConnection *gc; | |
3341 | |
3342 char *msgA, *msgB; | |
3343 | |
3344 g_return_if_fail(buddy != NULL); | |
3345 | |
3346 acct = buddy->account; | |
3347 g_return_if_fail(acct != NULL); | |
3348 | |
3349 gc = gaim_account_get_connection(acct); | |
3350 g_return_if_fail(gc != NULL); | |
3351 | |
3352 fields = gaim_request_fields_new(); | |
3353 | |
3354 g = gaim_request_field_group_new(NULL); | |
3355 gaim_request_fields_add_group(fields, g); | |
3356 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3357 f = gaim_request_field_string_new(CHAT_KEY_TOPIC, _("Topic"), NULL, FALSE); |
10977 | 3358 gaim_request_field_group_add_field(g, f); |
3359 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3360 f = gaim_request_field_string_new(CHAT_KEY_INVITE, _("Message"), msg, FALSE); |
10977 | 3361 gaim_request_field_group_add_field(g, f); |
3362 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3363 msgA = _("Create conference with user"); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3364 msgB = _("Please enter a topic for the new conference, and an invitation" |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3365 " message to be sent to %s"); |
10977 | 3366 msgB = g_strdup_printf(msgB, buddy->name); |
3367 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3368 gaim_request_fields(gc, _("New Conference"), |
10977 | 3369 msgA, msgB, fields, |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3370 _("Create"), G_CALLBACK(conf_create_prompt_join), |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3371 _("Cancel"), G_CALLBACK(conf_create_prompt_cancel), |
10977 | 3372 buddy); |
3373 g_free(msgB); | |
3374 } | |
3375 | |
3376 | |
3377 static void conf_select_prompt_cancel(GaimBuddy *buddy, | |
3378 GaimRequestFields *fields) { | |
3379 ; | |
3380 } | |
3381 | |
3382 | |
3383 static void conf_select_prompt_invite(GaimBuddy *buddy, | |
3384 GaimRequestFields *fields) { | |
3385 GaimRequestField *f; | |
3386 const GList *l; | |
3387 const char *msg; | |
3388 | |
3389 f = gaim_request_fields_get_field(fields, CHAT_KEY_INVITE); | |
3390 msg = gaim_request_field_string_get_value(f); | |
3391 | |
3392 f = gaim_request_fields_get_field(fields, "conf"); | |
3393 l = gaim_request_field_list_get_selected(f); | |
3394 | |
3395 if(l) { | |
3396 gpointer d = gaim_request_field_list_get_data(f, l->data); | |
3397 | |
3398 if(GPOINTER_TO_INT(d) == 0x01) { | |
3399 blist_menu_conf_create(buddy, msg); | |
3400 | |
3401 } else { | |
3402 struct mwIdBlock idb = { buddy->name, NULL }; | |
3403 mwConference_invite(d, &idb, msg); | |
3404 } | |
3405 } | |
3406 } | |
3407 | |
3408 | |
3409 static void blist_menu_conf_list(GaimBuddy *buddy, | |
3410 GList *confs) { | |
3411 | |
3412 GaimRequestFields *fields; | |
3413 GaimRequestFieldGroup *g; | |
3414 GaimRequestField *f; | |
3415 | |
3416 GaimAccount *acct; | |
3417 GaimConnection *gc; | |
3418 | |
3419 char *msgA, *msgB; | |
3420 | |
3421 acct = buddy->account; | |
3422 g_return_if_fail(acct != NULL); | |
3423 | |
3424 gc = gaim_account_get_connection(acct); | |
3425 g_return_if_fail(gc != NULL); | |
3426 | |
3427 fields = gaim_request_fields_new(); | |
3428 | |
3429 g = gaim_request_field_group_new(NULL); | |
3430 gaim_request_fields_add_group(fields, g); | |
3431 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3432 f = gaim_request_field_list_new("conf", _("Available Conferences")); |
10977 | 3433 gaim_request_field_list_set_multi_select(f, FALSE); |
3434 for(; confs; confs = confs->next) { | |
3435 struct mwConference *c = confs->data; | |
3436 gaim_request_field_list_add(f, mwConference_getTitle(c), c); | |
3437 } | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3438 gaim_request_field_list_add(f, _("Create New Conference..."), |
10977 | 3439 GINT_TO_POINTER(0x01)); |
3440 gaim_request_field_group_add_field(g, f); | |
3441 | |
3442 f = gaim_request_field_string_new(CHAT_KEY_INVITE, "Message", NULL, FALSE); | |
3443 gaim_request_field_group_add_field(g, f); | |
3444 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3445 msgA = _("Invite user to a conference"); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3446 msgB = _("Select a conference from the list below to send an invite to" |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3447 " user %s. Select \"Create New Conference\" if you'd like to" |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3448 " create a new conference to invite this user to."); |
10977 | 3449 msgB = g_strdup_printf(msgB, buddy->name); |
3450 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3451 gaim_request_fields(gc, _("Invite to Conference"), |
10977 | 3452 msgA, msgB, fields, |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3453 _("Invite"), G_CALLBACK(conf_select_prompt_invite), |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3454 _("Cancel"), G_CALLBACK(conf_select_prompt_cancel), |
10977 | 3455 buddy); |
3456 g_free(msgB); | |
3457 } | |
3458 | |
3459 | |
3460 static void blist_menu_conf(GaimBlistNode *node, gpointer data) { | |
3461 GaimBuddy *buddy = (GaimBuddy *) node; | |
3462 GaimAccount *acct; | |
3463 GaimConnection *gc; | |
3464 struct mwGaimPluginData *pd; | |
3465 GList *l; | |
3466 | |
3467 g_return_if_fail(node != NULL); | |
3468 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node)); | |
3469 | |
3470 acct = buddy->account; | |
3471 g_return_if_fail(acct != NULL); | |
3472 | |
3473 gc = gaim_account_get_connection(acct); | |
3474 g_return_if_fail(gc != NULL); | |
3475 | |
3476 pd = gc->proto_data; | |
3477 g_return_if_fail(pd != NULL); | |
3478 | |
11133
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
3479 /* |
10977 | 3480 - get a list of all conferences on this session |
3481 - if none, prompt to create one, and invite buddy to it | |
3482 - else, prompt to select a conference or create one | |
3483 */ | |
3484 | |
3485 l = mwServiceConference_getConferences(pd->srvc_conf); | |
3486 if(l) { | |
3487 blist_menu_conf_list(buddy, l); | |
3488 g_list_free(l); | |
3489 | |
3490 } else { | |
3491 blist_menu_conf_create(buddy, NULL); | |
3492 } | |
3493 } | |
3494 | |
3495 | |
3496 static GList *mw_prpl_blist_node_menu(GaimBlistNode *node) { | |
3497 GList *l = NULL; | |
3498 GaimBlistNodeAction *act; | |
3499 | |
3500 if(! GAIM_BLIST_NODE_IS_BUDDY(node)) | |
3501 return l; | |
3502 | |
3503 l = g_list_append(l, NULL); | |
3504 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3505 act = gaim_blist_node_action_new(_("Invite to Conference..."), |
10977 | 3506 blist_menu_conf, NULL, NULL); |
3507 l = g_list_append(l, act); | |
3508 | |
3509 /** note: this never gets called for a GaimGroup, have to use the | |
3510 blist-node-extended-menu signal for that. The function | |
3511 blist_node_menu_cb is assigned to this signal in the function | |
3512 services_starting */ | |
3513 | |
3514 return l; | |
3515 } | |
3516 | |
3517 | |
3518 static GList *mw_prpl_chat_info(GaimConnection *gc) { | |
3519 GList *l = NULL; | |
3520 struct proto_chat_entry *pce; | |
3521 | |
3522 pce = g_new0(struct proto_chat_entry, 1); | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3523 pce->label = _("Topic:"); |
10977 | 3524 pce->identifier = CHAT_KEY_TOPIC; |
3525 l = g_list_append(l, pce); | |
3526 | |
3527 return l; | |
3528 } | |
3529 | |
3530 | |
3531 static GHashTable *mw_prpl_chat_info_defaults(GaimConnection *gc, | |
3532 const char *name) { | |
3533 GHashTable *table; | |
3534 | |
3535 g_return_val_if_fail(gc != NULL, NULL); | |
3536 | |
3537 table = g_hash_table_new_full(g_str_hash, g_str_equal, | |
3538 NULL, g_free); | |
3539 | |
3540 g_hash_table_insert(table, CHAT_KEY_NAME, g_strdup(name)); | |
3541 g_hash_table_insert(table, CHAT_KEY_INVITE, NULL); | |
3542 | |
3543 return table; | |
3544 } | |
3545 | |
3546 | |
11837 | 3547 static void mw_prpl_login(GaimAccount *acct); |
10977 | 3548 |
3549 | |
3550 static void prompt_host_cancel_cb(GaimConnection *gc) { | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3551 gaim_connection_error(gc, _("No Sametime Community Server specified")); |
10977 | 3552 } |
3553 | |
3554 | |
3555 static void prompt_host_ok_cb(GaimConnection *gc, const char *host) { | |
3556 if(host && *host) { | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3557 GaimAccount *acct = gaim_connection_get_account(gc); |
10977 | 3558 gaim_account_set_string(acct, MW_KEY_HOST, host); |
11837 | 3559 mw_prpl_login(acct); |
10977 | 3560 |
3561 } else { | |
3562 prompt_host_cancel_cb(gc); | |
3563 } | |
3564 } | |
3565 | |
3566 | |
3567 static void prompt_host(GaimConnection *gc) { | |
3568 GaimAccount *acct; | |
3569 char *msg; | |
3570 | |
3571 acct = gaim_connection_get_account(gc); | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3572 msg = _("No host or IP address has been configured for the" |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3573 " Meanwhile account %s. Please enter one below to" |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3574 " continue logging in."); |
10977 | 3575 msg = g_strdup_printf(msg, NSTR(gaim_account_get_username(acct))); |
3576 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3577 gaim_request_input(gc, _("Meanwhile Connection Setup"), |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3578 _("No Sametime Community Server Specified"), msg, |
10977 | 3579 MW_PLUGIN_DEFAULT_HOST, FALSE, FALSE, NULL, |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3580 _("Connect"), G_CALLBACK(prompt_host_ok_cb), |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3581 _("Cancel"), G_CALLBACK(prompt_host_cancel_cb), |
10977 | 3582 gc); |
3583 | |
3584 g_free(msg); | |
3585 } | |
3586 | |
3587 | |
11837 | 3588 static void mw_prpl_login(GaimAccount *account) { |
10977 | 3589 GaimConnection *gc; |
3590 struct mwGaimPluginData *pd; | |
3591 | |
3592 char *user, *pass, *host; | |
3593 guint port; | |
3594 | |
3595 gc = gaim_account_get_connection(account); | |
3596 pd = mwGaimPluginData_new(gc); | |
3597 | |
3598 /* while we do support images, the default is to not offer it */ | |
3599 gc->flags |= GAIM_CONNECTION_NO_IMAGES; | |
3600 | |
3601 user = g_strdup(gaim_account_get_username(account)); | |
3602 pass = (char *) gaim_account_get_password(account); | |
3603 | |
3604 host = strrchr(user, ':'); | |
3605 if(host) { | |
3606 /* annoying user split from 1.2.0, need to undo it */ | |
3607 *host++ = '\0'; | |
3608 gaim_account_set_string(account, MW_KEY_HOST, host); | |
3609 gaim_account_set_username(account, user); | |
3610 | |
3611 } else { | |
3612 host = (char *) gaim_account_get_string(account, MW_KEY_HOST, | |
3613 MW_PLUGIN_DEFAULT_HOST); | |
3614 } | |
3615 | |
3616 if(! host || ! *host) { | |
3617 /* somehow, we don't have a host to connect to. Well, we need one | |
3618 to actually continue, so let's ask the user directly. */ | |
3619 prompt_host(gc); | |
3620 return; | |
3621 } | |
3622 | |
3623 port = gaim_account_get_int(account, MW_KEY_PORT, MW_PLUGIN_DEFAULT_PORT); | |
3624 | |
3625 DEBUG_INFO("user: '%s'\n", user); | |
3626 DEBUG_INFO("host: '%s'\n", host); | |
3627 DEBUG_INFO("port: %u\n", port); | |
3628 | |
11133
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
3629 mwSession_setProperty(pd->session, mwSession_NO_SECRET, |
10977 | 3630 (char *) no_secret, NULL); |
3631 mwSession_setProperty(pd->session, mwSession_AUTH_USER_ID, user, g_free); | |
3632 mwSession_setProperty(pd->session, mwSession_AUTH_PASSWORD, pass, NULL); | |
3633 mwSession_setProperty(pd->session, mwSession_CLIENT_TYPE_ID, | |
3634 GUINT_TO_POINTER(MW_CLIENT_TYPE_ID), NULL); | |
3635 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3636 gaim_connection_update_progress(gc, _("Connecting"), 1, MW_CONNECT_STEPS); |
10977 | 3637 |
3638 if(gaim_proxy_connect(account, host, port, connect_cb, pd)) { | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3639 gaim_connection_error(gc, _("Unable to connect to host")); |
10977 | 3640 } |
3641 } | |
3642 | |
3643 | |
3644 static void mw_prpl_close(GaimConnection *gc) { | |
3645 struct mwGaimPluginData *pd; | |
3646 | |
3647 g_return_if_fail(gc != NULL); | |
3648 | |
3649 pd = gc->proto_data; | |
3650 g_return_if_fail(pd != NULL); | |
3651 | |
3652 /* get rid of the blist save timeout */ | |
3653 if(pd->save_event) { | |
3654 gaim_timeout_remove(pd->save_event); | |
3655 pd->save_event = 0; | |
3656 blist_store(pd); | |
3657 } | |
3658 | |
3659 /* stop the session */ | |
3660 mwSession_stop(pd->session, 0x00); | |
3661 | |
3662 /* no longer necessary */ | |
3663 gc->proto_data = NULL; | |
3664 | |
3665 /* stop watching the socket */ | |
3666 if(gc->inpa) { | |
3667 gaim_input_remove(gc->inpa); | |
3668 gc->inpa = 0; | |
3669 } | |
3670 | |
3671 /* clean up the rest */ | |
3672 mwGaimPluginData_free(pd); | |
3673 } | |
3674 | |
3675 | |
11133
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
3676 /** generates a random-ish content id string */ |
10977 | 3677 static char *im_mime_content_id() { |
3678 const char *c = "%03x@%05xmeanwhile"; | |
3679 srand(time(0) ^ rand()); | |
3680 return g_strdup_printf(c, rand() & 0xfff, rand() & 0xfffff); | |
3681 } | |
3682 | |
3683 | |
11133
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
3684 /** generates a multipart/related content type with a random-ish |
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
3685 boundary value */ |
10977 | 3686 static char *im_mime_content_type() { |
3687 const char *c = "multipart/related; boundary=related_MW%03x_%04x"; | |
3688 srand(time(0) ^ rand()); | |
3689 return g_strdup_printf(c, rand() & 0xfff, rand() & 0xffff); | |
3690 } | |
3691 | |
3692 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3693 /** determine content type from extension. Not so happy about this, |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3694 but I don't want to actually write image type detection */ |
12105
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3695 static char *im_mime_img_content_type(GaimStoredImage *img) { |
10977 | 3696 const char *fn = gaim_imgstore_get_filename(img); |
12105
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3697 const char *ct = NULL; |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3698 |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3699 ct = strrchr(fn, '.'); |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3700 if(! ct) { |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3701 ct = "image"; |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3702 |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3703 } else if(! strcmp(".png", ct)) { |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3704 ct = "image/png"; |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3705 |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3706 } else if(! strcmp(".jpg", ct)) { |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3707 ct = "image/jpeg"; |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3708 |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3709 } else if(! strcmp(".jpeg", ct)) { |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3710 ct = "image/jpeg"; |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3711 |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3712 } else if(! strcmp(".gif", ct)) { |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3713 ct = "image/gif"; |
10977 | 3714 |
3715 } else { | |
12105
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3716 ct = "image"; |
10977 | 3717 } |
12105
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3718 |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3719 return g_strdup_printf("%s; name=\"%s\"", ct, fn); |
10977 | 3720 } |
3721 | |
3722 | |
3723 static char *im_mime_img_content_disp(GaimStoredImage *img) { | |
3724 const char *fn = gaim_imgstore_get_filename(img); | |
3725 return g_strdup_printf("attachment; filename=\"%s\"", fn); | |
3726 } | |
3727 | |
3728 | |
12105
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3729 static char *nb_im_encode(GaimConnection *gc, const char *message) { |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3730 GaimAccount *acct; |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3731 const char *enc; |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3732 char *ret; |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3733 GError *error = NULL; |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3734 |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3735 acct = gaim_connection_get_account(gc); |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3736 g_return_val_if_fail(acct != NULL, NULL); |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3737 |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3738 enc = gaim_account_get_string(acct, MW_KEY_ENCODING, |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3739 MW_PLUGIN_DEFAULT_ENCODING); |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3740 g_return_val_if_fail(enc != NULL, NULL); |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3741 |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3742 ret = g_convert_with_fallback(message, strlen(message), |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3743 enc, "UTF-8", "?", |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3744 NULL, NULL, &error); |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3745 |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3746 if(error) { |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3747 DEBUG_INFO("problem converting to %s: %s\n", |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3748 enc, NSTR(error->message)); |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3749 g_error_free(error); |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3750 } |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3751 |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3752 /* something went so wrong that not even the fallback worked */ |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3753 if(! ret) ret = g_strdup(message); |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3754 |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3755 return ret; |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3756 } |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3757 |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3758 |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3759 static gboolean is_nb(struct mwConversation *conv) { |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3760 struct mwLoginInfo *info; |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3761 |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3762 info = mwConversation_getTargetInfo(conv); |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3763 if(! info) return FALSE; |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3764 |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3765 /* NotesBuddy can be at least three different type IDs (all in the |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3766 0x1400 range), or it can show up as 0x1002. However, if we're |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3767 calling this check, then we're already in HTML or MIME mode, so |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3768 we can discount the real 0x1002 */ |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3769 /* I tried to avoid having any client-type-dependant code in here, I |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3770 really did. Oh well. CURSE YOU NOTESBUDDY */ |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3771 return ((info->type == 0x1002) || ((info->type & 0xff00) == 0x1400)); |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3772 } |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3773 |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3774 |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3775 /** turn an IM with embedded images into a multi-part mime document */ |
12105
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3776 static char *im_mime_convert(GaimConnection *gc, |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3777 struct mwConversation *conv, |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3778 const char *message) { |
10977 | 3779 GString *str; |
3780 GaimMimeDocument *doc; | |
3781 GaimMimePart *part; | |
3782 | |
3783 GData *attr; | |
3784 char *tmp, *start, *end; | |
3785 | |
3786 str = g_string_new(NULL); | |
3787 | |
3788 doc = gaim_mime_document_new(); | |
3789 | |
3790 gaim_mime_document_set_field(doc, "Mime-Version", "1.0"); | |
3791 gaim_mime_document_set_field(doc, "Content-Disposition", "inline"); | |
3792 | |
3793 tmp = im_mime_content_type(); | |
3794 gaim_mime_document_set_field(doc, "Content-Type", tmp); | |
3795 g_free(tmp); | |
3796 | |
3797 tmp = (char *) message; | |
3798 while(*tmp && gaim_markup_find_tag("img", tmp, (const char **) &start, | |
3799 (const char **) &end, &attr)) { | |
3800 char *id; | |
3801 GaimStoredImage *img = NULL; | |
3802 | |
3803 gsize len = (start - tmp); | |
3804 | |
3805 /* append the in-between-tags text */ | |
3806 if(len) g_string_append_len(str, tmp, len); | |
3807 | |
3808 /* find the imgstore data by the id tag */ | |
3809 id = g_datalist_get_data(&attr, "id"); | |
3810 if(id && *id) | |
3811 img = gaim_imgstore_get(atoi(id)); | |
3812 | |
3813 if(img) { | |
3814 char *cid; | |
3815 gpointer data; | |
3816 size_t size; | |
3817 | |
3818 part = gaim_mime_part_new(doc); | |
3819 | |
3820 data = im_mime_img_content_disp(img); | |
3821 gaim_mime_part_set_field(part, "Content-Disposition", data); | |
3822 g_free(data); | |
3823 | |
12105
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3824 data = im_mime_img_content_type(img); |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3825 gaim_mime_part_set_field(part, "Content-Type", data); |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3826 g_free(data); |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3827 |
10977 | 3828 cid = im_mime_content_id(); |
3829 data = g_strdup_printf("<%s>", cid); | |
3830 gaim_mime_part_set_field(part, "Content-ID", data); | |
3831 g_free(data); | |
3832 | |
3833 gaim_mime_part_set_field(part, "Content-transfer-encoding", "base64"); | |
3834 | |
3835 /* obtain and base64 encode the image data, and put it in the | |
3836 mime part */ | |
3837 data = gaim_imgstore_get_data(img); | |
3838 size = gaim_imgstore_get_size(img); | |
3839 data = gaim_base64_encode(data, (gsize) size); | |
3840 gaim_mime_part_set_data(part, data); | |
3841 g_free(data); | |
3842 | |
3843 /* append the modified tag */ | |
3844 g_string_append_printf(str, "<img src=\"cid:%s\">", cid); | |
3845 g_free(cid); | |
3846 | |
3847 } else { | |
3848 /* append the literal image tag, since we couldn't find a | |
3849 relative imgstore object */ | |
3850 gsize len = (end - start) + 1; | |
3851 g_string_append_len(str, start, len); | |
3852 } | |
3853 | |
3854 g_datalist_clear(&attr); | |
3855 tmp = end + 1; | |
3856 } | |
3857 | |
3858 /* append left-overs */ | |
3859 g_string_append(str, tmp); | |
3860 | |
12105
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3861 /* add the text/html part */ |
10977 | 3862 part = gaim_mime_part_new(doc); |
3863 gaim_mime_part_set_field(part, "Content-Disposition", "inline"); | |
12105
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3864 |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3865 if(is_nb(conv)) { |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3866 GaimAccount *acct = gaim_connection_get_account(gc); |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3867 |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3868 tmp = (char *) gaim_account_get_string(acct, MW_KEY_ENCODING, |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3869 MW_PLUGIN_DEFAULT_ENCODING); |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3870 tmp = g_strdup_printf("text/html; charset=\"%s\"", tmp); |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3871 gaim_mime_part_set_field(part, "Content-Type", tmp); |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3872 g_free(tmp); |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3873 |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3874 gaim_mime_part_set_field(part, "Content-Transfer-Encoding", "7bit"); |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3875 |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3876 tmp = nb_im_encode(gc, str->str); |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3877 gaim_mime_part_set_data(part, tmp); |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3878 g_free(tmp); |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3879 |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3880 } else { |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3881 gaim_mime_part_set_field(part, "Content-Type", "text/html"); |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3882 gaim_mime_part_set_field(part, "Content-Transfer-Encoding", "8bit"); |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3883 gaim_mime_part_set_data(part, str->str); |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3884 } |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3885 |
10977 | 3886 g_string_free(str, TRUE); |
3887 | |
3888 str = g_string_new(NULL); | |
3889 gaim_mime_document_write(doc, str); | |
3890 tmp = str->str; | |
3891 g_string_free(str, FALSE); | |
3892 | |
3893 return tmp; | |
3894 } | |
3895 | |
3896 | |
3897 static int mw_prpl_send_im(GaimConnection *gc, | |
3898 const char *name, | |
3899 const char *message, | |
3900 GaimConvImFlags flags) { | |
3901 | |
3902 struct mwGaimPluginData *pd; | |
3903 struct mwIdBlock who = { (char *) name, NULL }; | |
3904 struct mwConversation *conv; | |
3905 | |
3906 g_return_val_if_fail(gc != NULL, 0); | |
3907 pd = gc->proto_data; | |
3908 | |
3909 g_return_val_if_fail(pd != NULL, 0); | |
3910 | |
3911 conv = mwServiceIm_getConversation(pd->srvc_im, &who); | |
3912 | |
3913 /* this detection of features to determine how to send the message | |
3914 (plain, html, or mime) is flawed because the other end of the | |
3915 conversation could close their channel at any time, rendering any | |
3916 existing formatting in an outgoing message innapropriate. The end | |
3917 result is that it may be possible that the other side of the | |
3918 conversation will receive a plaintext message with html contents, | |
3919 which is bad. I'm not sure how to fix this correctly. */ | |
3920 | |
12105
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3921 if(strstr(message, "<img ") || strstr(message, "<IMG ")) |
10977 | 3922 flags |= GAIM_CONV_IM_IMAGES; |
3923 | |
3924 if(mwConversation_isOpen(conv)) { | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3925 char *tmp; |
10977 | 3926 int ret; |
3927 | |
3928 if((flags & GAIM_CONV_IM_IMAGES) && | |
3929 mwConversation_supports(conv, mwImSend_MIME)) { | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3930 /* send a MIME message */ |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3931 |
12105
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3932 tmp = im_mime_convert(gc, conv, message); |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3933 ret = mwConversation_send(conv, mwImSend_MIME, tmp); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3934 g_free(tmp); |
10977 | 3935 |
3936 } else if(mwConversation_supports(conv, mwImSend_HTML)) { | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3937 /* send an HTML message */ |
10977 | 3938 |
12105
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3939 /* need to do this to get the \n to <br> conversion */ |
12005
5b3368008513
[gaim-migrate @ 14298]
Christopher O'Brien <siege@pidgin.im>
parents:
11953
diff
changeset
|
3940 if(is_nb(conv)) { |
12105
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3941 |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3942 /* html messages need the notesbuddy hack */ |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3943 char *msg = nb_im_encode(gc, message); |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3944 tmp = gaim_strdup_withhtml(msg); |
12005
5b3368008513
[gaim-migrate @ 14298]
Christopher O'Brien <siege@pidgin.im>
parents:
11953
diff
changeset
|
3945 g_free(msg); |
12105
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3946 |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3947 } else { |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3948 tmp = gaim_strdup_withhtml(message); |
12005
5b3368008513
[gaim-migrate @ 14298]
Christopher O'Brien <siege@pidgin.im>
parents:
11953
diff
changeset
|
3949 } |
5b3368008513
[gaim-migrate @ 14298]
Christopher O'Brien <siege@pidgin.im>
parents:
11953
diff
changeset
|
3950 |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3951 ret = mwConversation_send(conv, mwImSend_HTML, tmp); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3952 g_free(tmp); |
10977 | 3953 |
3954 } else { | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3955 /* default to text */ |
12105
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3956 ret = mwConversation_send(conv, mwImSend_PLAIN, message); |
10977 | 3957 } |
3958 | |
3959 return !ret; | |
11133
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
3960 |
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
3961 } else { |
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
3962 |
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
3963 /* queue up the message safely as plain text */ |
12105
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
3964 char *tmp = gaim_markup_strip_html(message); |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3965 convo_queue(conv, mwImSend_PLAIN, tmp); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3966 g_free(tmp); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
3967 |
11133
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
3968 if(! mwConversation_isPending(conv)) |
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
3969 mwConversation_open(conv); |
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
3970 |
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
3971 return 1; |
10977 | 3972 } |
3973 } | |
3974 | |
3975 | |
3976 static int mw_prpl_send_typing(GaimConnection *gc, const char *name, | |
3977 int typing) { | |
3978 | |
3979 struct mwGaimPluginData *pd; | |
3980 struct mwIdBlock who = { (char *) name, NULL }; | |
3981 struct mwConversation *conv; | |
3982 | |
3983 gpointer t = GINT_TO_POINTER(!! typing); | |
3984 | |
3985 g_return_val_if_fail(gc != NULL, 0); | |
3986 pd = gc->proto_data; | |
3987 | |
3988 g_return_val_if_fail(pd != NULL, 0); | |
3989 | |
3990 conv = mwServiceIm_getConversation(pd->srvc_im, &who); | |
3991 | |
3992 if(mwConversation_isOpen(conv)) | |
3993 return ! mwConversation_send(conv, mwImSend_TYPING, t); | |
3994 | |
3995 if(typing) { | |
3996 /* let's only open a channel for typing, not for not-typing. | |
3997 Otherwise two users in psychic mode will continually open | |
3998 conversations to each other, never able to get rid of them, as | |
3999 when the other person closes, it psychicaly opens again */ | |
4000 | |
4001 convo_queue(conv, mwImSend_TYPING, t); | |
4002 | |
4003 if(! mwConversation_isPending(conv)) | |
4004 mwConversation_open(conv); | |
4005 } | |
4006 | |
4007 return 1; | |
4008 } | |
4009 | |
4010 | |
4011 static void mw_prpl_get_info(GaimConnection *gc, const char *who) { | |
4012 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4013 struct mwAwareIdBlock idb = { mwAware_USER, (char *) who, NULL }; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4014 |
10977 | 4015 struct mwGaimPluginData *pd; |
4016 GaimAccount *acct; | |
4017 GaimBuddy *b; | |
4018 | |
4019 GString *str; | |
4020 const char *tmp; | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4021 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4022 g_return_if_fail(who != NULL); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4023 g_return_if_fail(*who != '\0'); |
10977 | 4024 |
4025 pd = gc->proto_data; | |
4026 | |
4027 acct = gaim_connection_get_account(gc); | |
4028 b = gaim_find_buddy(acct, who); | |
4029 | |
4030 str = g_string_new(NULL); | |
4031 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4032 if(g_str_has_prefix(who, "@E ")) { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4033 g_string_append(str, _("<b>External User</b><br>")); |
10977 | 4034 } |
4035 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4036 g_string_append_printf(str, _("<b>User ID:</b> %s<br>"), who); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4037 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4038 if(b) { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4039 guint32 type; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4040 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4041 if(b->server_alias) { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4042 g_string_append_printf(str, _("<b>Full Name:</b> %s<br>"), |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4043 b->server_alias); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4044 } |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4045 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4046 type = gaim_blist_node_get_int((GaimBlistNode *) b, BUDDY_KEY_CLIENT); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4047 if(type) { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4048 g_string_append(str, _("<b>Last Known Client:</b> ")); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4049 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4050 tmp = mwLoginType_getName(type); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4051 if(tmp) { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4052 g_string_append(str, tmp); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4053 g_string_append(str, "<br>"); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4054 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4055 } else { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4056 g_string_append_printf(str, _("Unknown (0x%04x)<br>"), type); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4057 } |
10977 | 4058 } |
4059 } | |
4060 | |
4061 tmp = user_supports_text(pd->srvc_aware, who); | |
4062 if(tmp) { | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4063 g_string_append_printf(str, _("<b>Supports:</b> %s<br>"), tmp); |
10977 | 4064 g_free((char *) tmp); |
4065 } | |
4066 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4067 if(b) { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4068 tmp = status_text(b); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4069 g_string_append_printf(str, _("<b>Status:</b> %s"), tmp); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4070 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4071 g_string_append(str, "<hr>"); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4072 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4073 tmp = mwServiceAware_getText(pd->srvc_aware, &idb); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4074 if(tmp) g_string_append(str, tmp); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4075 } |
10977 | 4076 |
4077 /* @todo emit a signal to allow a plugin to override the display of | |
4078 this notification, so that it can create its own */ | |
4079 | |
11533
c9b815aeddc1
[gaim-migrate @ 13782]
Richard Laager <rlaager@wiktel.com>
parents:
11531
diff
changeset
|
4080 gaim_notify_userinfo(gc, who, str->str, NULL, NULL); |
10977 | 4081 |
4082 g_string_free(str, TRUE); | |
4083 } | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4084 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4085 |
11638 | 4086 static void mw_prpl_set_status(GaimAccount *acct, GaimStatus *status) { |
4087 GaimConnection *gc; | |
4088 const char *state; | |
11641
925c1960af34
[gaim-migrate @ 13918]
Richard Laager <rlaager@wiktel.com>
parents:
11638
diff
changeset
|
4089 char *message = NULL; |
10977 | 4090 struct mwSession *session; |
4091 struct mwUserStatus stat; | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4092 |
10977 | 4093 g_return_if_fail(acct != NULL); |
11638 | 4094 gc = gaim_account_get_connection(acct); |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4095 |
11638 | 4096 state = gaim_status_get_id(status); |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4097 |
12105
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
4098 DEBUG_INFO("Set status to %s\n", gaim_status_get_name(status)); |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4099 |
11638 | 4100 g_return_if_fail(gc != NULL); |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4101 |
10977 | 4102 session = gc_to_session(gc); |
4103 g_return_if_fail(session != NULL); | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4104 |
10977 | 4105 /* get a working copy of the current status */ |
4106 mwUserStatus_clone(&stat, mwSession_getUserStatus(session)); | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4107 |
10977 | 4108 /* determine the state */ |
11638 | 4109 if(! strcmp(state, MW_STATE_ACTIVE)) { |
10977 | 4110 stat.status = mwStatus_ACTIVE; |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4111 |
11638 | 4112 } else if(! strcmp(state, MW_STATE_AWAY)) { |
4113 stat.status = mwStatus_AWAY; | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4114 |
11638 | 4115 } else if(! strcmp(state, MW_STATE_BUSY)) { |
4116 stat.status = mwStatus_BUSY; | |
10977 | 4117 } |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4118 |
10977 | 4119 /* determine the message */ |
12105
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
4120 message = (char *) gaim_status_get_attr_string(status, MW_STATE_MESSAGE); |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4121 |
10977 | 4122 if(message) { |
4123 /* all the possible non-NULL values of message up to this point | |
4124 are const, so we don't need to free them */ | |
4125 message = gaim_markup_strip_html(message); | |
4126 } | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4127 |
10977 | 4128 /* out with the old */ |
4129 g_free(stat.desc); | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4130 |
10977 | 4131 /* in with the new */ |
4132 stat.desc = (char *) message; | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4133 |
10977 | 4134 mwSession_setUserStatus(session, &stat); |
11638 | 4135 mwUserStatus_clear(&stat); |
10977 | 4136 } |
4137 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4138 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4139 static void mw_prpl_set_idle(GaimConnection *gc, int t) { |
10977 | 4140 struct mwSession *session; |
4141 struct mwUserStatus stat; | |
12105
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
4142 |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
4143 |
10977 | 4144 session = gc_to_session(gc); |
4145 g_return_if_fail(session != NULL); | |
12105
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
4146 |
10977 | 4147 mwUserStatus_clone(&stat, mwSession_getUserStatus(session)); |
4148 | |
12105
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
4149 if(t) { |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
4150 time_t now = time(NULL); |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
4151 stat.time = now - t; |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
4152 |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
4153 } else { |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
4154 stat.time = 0; |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
4155 } |
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
4156 |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4157 if(t > 0 && stat.status == mwStatus_ACTIVE) { |
12105
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
4158 /* we were active and went idle, so change the status to IDLE. */ |
10977 | 4159 stat.status = mwStatus_IDLE; |
12105
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
4160 |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4161 } else if(t == 0 && stat.status == mwStatus_IDLE) { |
12105
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
4162 /* we only become idle automatically, so change back to ACTIVE */ |
10977 | 4163 stat.status = mwStatus_ACTIVE; |
4164 } | |
12105
d4cd7d443795
[gaim-migrate @ 14402]
Christopher O'Brien <siege@pidgin.im>
parents:
12088
diff
changeset
|
4165 |
10977 | 4166 mwSession_setUserStatus(session, &stat); |
4167 mwUserStatus_clear(&stat); | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4168 } |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4169 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4170 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4171 static struct resolved_id *resolved_id_new(const char *id, |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4172 const char *name) { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4173 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4174 struct resolved_id *rid = g_new0(struct resolved_id, 1); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4175 rid->id = g_strdup(id); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4176 rid->name = g_strdup(name); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4177 return rid; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4178 } |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4179 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4180 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4181 static void resolved_id_free(struct resolved_id *rid) { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4182 if(rid) { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4183 g_free(rid->id); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4184 g_free(rid->name); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4185 g_free(rid); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4186 } |
10977 | 4187 } |
4188 | |
4189 | |
4190 static void add_resolved_done(const char *id, const char *name, | |
4191 GaimBuddy *buddy) { | |
4192 GaimAccount *acct; | |
4193 GaimConnection *gc; | |
4194 struct mwGaimPluginData *pd; | |
4195 | |
4196 g_return_if_fail(id != NULL); | |
4197 | |
4198 g_return_if_fail(buddy != NULL); | |
4199 acct = buddy->account; | |
4200 | |
4201 g_return_if_fail(acct != NULL); | |
4202 gc = gaim_account_get_connection(acct); | |
4203 | |
4204 g_return_if_fail(gc != NULL); | |
4205 pd = gc->proto_data; | |
4206 | |
4207 gaim_blist_rename_buddy(buddy, id); | |
4208 | |
4209 gaim_blist_server_alias_buddy(buddy, name); | |
4210 gaim_blist_node_set_string((GaimBlistNode *) buddy, BUDDY_KEY_NAME, name); | |
4211 | |
4212 buddy_add(pd, buddy); | |
4213 } | |
4214 | |
4215 | |
4216 static void multi_resolved_cleanup(GaimRequestFields *fields) { | |
4217 GaimRequestField *f; | |
4218 const GList *l; | |
4219 | |
4220 f = gaim_request_fields_get_field(fields, "user"); | |
4221 l = gaim_request_field_list_get_items(f); | |
4222 | |
4223 for(; l; l = l->next) { | |
4224 const char *i = l->data; | |
4225 struct resolved_id *res; | |
4226 | |
4227 res = gaim_request_field_list_get_data(f, i); | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4228 resolved_id_free(res); |
10977 | 4229 } |
4230 } | |
4231 | |
4232 | |
4233 static void multi_resolved_cancel(GaimBuddy *buddy, | |
4234 GaimRequestFields *fields) { | |
4235 GaimConnection *gc; | |
4236 struct mwGaimPluginData *pd; | |
4237 | |
4238 gc = gaim_account_get_connection(buddy->account); | |
4239 pd = gc->proto_data; | |
4240 | |
4241 gaim_blist_remove_buddy(buddy); | |
4242 multi_resolved_cleanup(fields); | |
4243 | |
4244 blist_schedule(pd); | |
4245 } | |
4246 | |
4247 | |
4248 static void multi_resolved_cb(GaimBuddy *buddy, | |
4249 GaimRequestFields *fields) { | |
4250 GaimRequestField *f; | |
4251 const GList *l; | |
4252 | |
4253 f = gaim_request_fields_get_field(fields, "user"); | |
4254 l = gaim_request_field_list_get_selected(f); | |
4255 | |
4256 if(l) { | |
4257 const char *i = l->data; | |
4258 struct resolved_id *res; | |
4259 | |
4260 res = gaim_request_field_list_get_data(f, i); | |
4261 | |
4262 add_resolved_done(res->id, res->name, buddy); | |
4263 multi_resolved_cleanup(fields); | |
4264 | |
4265 } else { | |
4266 multi_resolved_cancel(buddy, fields); | |
4267 } | |
4268 } | |
4269 | |
4270 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4271 static void foreach_resolved_id(char *key, char *val, GList **l) { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4272 struct resolved_id *res = resolved_id_new(key, val); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4273 *l = g_list_prepend(*l, res); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4274 } |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4275 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4276 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4277 static gint resolved_id_comp(struct resolved_id *a, struct resolved_id *b) { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4278 return g_ascii_strcasecmp(a->name, b->name); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4279 } |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4280 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4281 |
10977 | 4282 static void multi_resolved_query(struct mwResolveResult *result, |
4283 GaimBuddy *buddy) { | |
4284 GaimRequestFields *fields; | |
4285 GaimRequestFieldGroup *g; | |
4286 GaimRequestField *f; | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4287 GHashTable *hash; |
10977 | 4288 GList *l; |
4289 char *msgA, *msgB; | |
4290 | |
4291 GaimAccount *acct; | |
4292 GaimConnection *gc; | |
4293 | |
4294 g_return_if_fail(buddy != NULL); | |
4295 | |
4296 acct = buddy->account; | |
4297 g_return_if_fail(acct != NULL); | |
4298 | |
4299 gc = gaim_account_get_connection(acct); | |
4300 g_return_if_fail(gc != NULL); | |
4301 | |
4302 fields = gaim_request_fields_new(); | |
4303 | |
4304 g = gaim_request_field_group_new(NULL); | |
4305 | |
4306 /* note that Gaim segfaults if you don't add the group to the fields | |
4307 before you add a required field to the group. Feh. */ | |
4308 gaim_request_fields_add_group(fields, g); | |
4309 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4310 f = gaim_request_field_list_new("user", _("Possible Matches")); |
10977 | 4311 gaim_request_field_list_set_multi_select(f, FALSE); |
4312 gaim_request_field_set_required(f, TRUE); | |
4313 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4314 /* collect results into a set of identities */ |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4315 hash = g_hash_table_new(g_str_hash, g_str_equal); |
10977 | 4316 for(l = result->matches; l; l = l->next) { |
4317 struct mwResolveMatch *match = l->data; | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4318 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4319 if(!match->id || !match->name) |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4320 continue; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4321 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4322 g_hash_table_insert(hash, match->id, match->name); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4323 } |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4324 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4325 /* collect set into a list of structures */ |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4326 l = NULL; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4327 g_hash_table_foreach(hash, (GHFunc) foreach_resolved_id, &l); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4328 g_list_sort(l, (GCompareFunc) resolved_id_comp); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4329 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4330 /* populate choices in request field */ |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4331 for(; l; l = l->next) { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4332 struct resolved_id *res = l->data; |
10977 | 4333 char *label; |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4334 |
10977 | 4335 /* fixes bug 1178603 by making the selection label a combination |
4336 of the full name and the user id. Problems arrise when multiple | |
4337 entries have identical labels */ | |
4338 label = g_strdup_printf("%s (%s)", NSTR(res->name), NSTR(res->id)); | |
4339 gaim_request_field_list_add(f, label, res); | |
4340 g_free(label); | |
4341 } | |
4342 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4343 g_list_free(l); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4344 |
10977 | 4345 gaim_request_field_group_add_field(g, f); |
4346 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4347 msgA = _("An ambiguous user ID was entered"); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4348 msgB = _("The identifier '%s' may possibly refer to any of the following" |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4349 " users. Please select the correct user from the list below to" |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4350 " add them to your buddy list."); |
10977 | 4351 msgB = g_strdup_printf(msgB, result->name); |
4352 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4353 gaim_request_fields(gc, _("Select User to Add"), |
10977 | 4354 msgA, msgB, fields, |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4355 _("Add User"), G_CALLBACK(multi_resolved_cb), |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4356 _("Cancel"), G_CALLBACK(multi_resolved_cancel), |
10977 | 4357 buddy); |
4358 g_free(msgB); | |
4359 } | |
4360 | |
4361 | |
4362 static void add_buddy_resolved(struct mwServiceResolve *srvc, | |
4363 guint32 id, guint32 code, GList *results, | |
4364 gpointer b) { | |
4365 | |
4366 struct mwResolveResult *res = NULL; | |
4367 GaimBuddy *buddy = b; | |
4368 GaimConnection *gc; | |
4369 struct mwGaimPluginData *pd; | |
4370 | |
4371 gc = gaim_account_get_connection(buddy->account); | |
4372 pd = gc->proto_data; | |
4373 | |
4374 if(results) | |
4375 res = results->data; | |
4376 | |
4377 if(!code && res && res->matches) { | |
4378 if(g_list_length(res->matches) == 1) { | |
4379 struct mwResolveMatch *match = res->matches->data; | |
4380 | |
4381 DEBUG_INFO("searched for %s, got only %s\n", | |
4382 NSTR(res->name), NSTR(match->id)); | |
4383 | |
4384 /* only one? that might be the right one! */ | |
4385 if(strcmp(res->name, match->id)) { | |
4386 /* uh oh, the single result isn't identical to the search | |
4387 term, better safe then sorry, so let's make sure it's who | |
4388 the user meant to add */ | |
4389 multi_resolved_query(res, buddy); | |
4390 | |
4391 } else { | |
4392 /* same person, add 'em */ | |
4393 add_resolved_done(match->id, match->name, buddy); | |
4394 } | |
4395 | |
4396 } else { | |
4397 /* prompt user if more than one match was returned */ | |
4398 multi_resolved_query(res, buddy); | |
4399 } | |
4400 | |
4401 return; | |
4402 } | |
4403 | |
4404 /* fall-through indicates that we couldn't find a matching user in | |
4405 the resolve service (ether error or zero results), so we remove | |
4406 this buddy */ | |
4407 | |
4408 DEBUG_INFO("no such buddy in community\n"); | |
4409 gaim_blist_remove_buddy(buddy); | |
4410 blist_schedule(pd); | |
4411 | |
4412 if(res && res->name) { | |
4413 /* compose and display an error message */ | |
4414 char *msgA, *msgB; | |
4415 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4416 msgA = _("Unable to add user: user not found"); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4417 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4418 msgB = _("The identifier '%s' did not match any users in your" |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4419 " Sametime community. This entry has been removed from" |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4420 " your buddy list."); |
10977 | 4421 msgB = g_strdup_printf(msgB, NSTR(res->name)); |
4422 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4423 gaim_notify_error(gc, _("Unable to add user"), msgA, msgB); |
10977 | 4424 |
4425 g_free(msgB); | |
4426 } | |
4427 } | |
4428 | |
4429 | |
4430 static void mw_prpl_add_buddy(GaimConnection *gc, | |
4431 GaimBuddy *buddy, | |
4432 GaimGroup *group) { | |
4433 | |
4434 struct mwGaimPluginData *pd; | |
4435 struct mwServiceResolve *srvc; | |
4436 GList *query; | |
4437 enum mwResolveFlag flags; | |
4438 guint32 req; | |
4439 | |
4440 pd = gc->proto_data; | |
4441 srvc = pd->srvc_resolve; | |
4442 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4443 /* catch external buddies. They won't be in the resolve service */ |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4444 if(g_str_has_prefix(buddy->name, "@E ")) { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4445 buddy_add(pd, buddy); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4446 return; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4447 } |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4448 |
10977 | 4449 query = g_list_prepend(NULL, buddy->name); |
4450 flags = mwResolveFlag_FIRST | mwResolveFlag_USERS; | |
4451 | |
4452 req = mwServiceResolve_resolve(srvc, query, flags, add_buddy_resolved, | |
4453 buddy, NULL); | |
4454 g_list_free(query); | |
4455 | |
4456 if(req == SEARCH_ERROR) { | |
4457 gaim_blist_remove_buddy(buddy); | |
4458 blist_schedule(pd); | |
4459 } | |
4460 } | |
4461 | |
4462 | |
4463 static void foreach_add_buddies(GaimGroup *group, GList *buddies, | |
4464 struct mwGaimPluginData *pd) { | |
4465 struct mwAwareList *list; | |
4466 | |
4467 list = list_ensure(pd, group); | |
4468 mwAwareList_addAware(list, buddies); | |
4469 g_list_free(buddies); | |
4470 } | |
4471 | |
4472 | |
4473 static void mw_prpl_add_buddies(GaimConnection *gc, | |
4474 GList *buddies, | |
4475 GList *groups) { | |
4476 | |
4477 struct mwGaimPluginData *pd; | |
4478 GHashTable *group_sets; | |
4479 struct mwAwareIdBlock *idbs, *idb; | |
4480 | |
4481 pd = gc->proto_data; | |
4482 | |
4483 /* map GaimGroup:GList of mwAwareIdBlock */ | |
4484 group_sets = g_hash_table_new(g_direct_hash, g_direct_equal); | |
4485 | |
4486 /* bunch of mwAwareIdBlock allocated at once, free'd at once */ | |
4487 idb = idbs = g_new(struct mwAwareIdBlock, g_list_length(buddies)); | |
4488 | |
4489 /* first pass collects mwAwareIdBlock lists for each group */ | |
4490 for(; buddies; buddies = buddies->next) { | |
4491 GaimBuddy *b = buddies->data; | |
4492 GaimGroup *g; | |
4493 const char *fn; | |
4494 GList *l; | |
4495 | |
4496 /* nab the saved server alias and stick it on the buddy */ | |
4497 fn = gaim_blist_node_get_string((GaimBlistNode *) b, BUDDY_KEY_NAME); | |
4498 gaim_blist_server_alias_buddy(b, fn); | |
4499 | |
4500 /* convert GaimBuddy into a mwAwareIdBlock */ | |
4501 idb->type = mwAware_USER; | |
4502 idb->user = (char *) b->name; | |
4503 idb->community = NULL; | |
4504 | |
4505 /* put idb into the list associated with the buddy's group */ | |
12088 | 4506 g = gaim_buddy_get_group(b); |
10977 | 4507 l = g_hash_table_lookup(group_sets, g); |
4508 l = g_list_prepend(l, idb++); | |
4509 g_hash_table_insert(group_sets, g, l); | |
4510 } | |
4511 | |
4512 /* each group's buddies get added in one shot, and schedule the blist | |
4513 for saving */ | |
4514 g_hash_table_foreach(group_sets, (GHFunc) foreach_add_buddies, pd); | |
4515 blist_schedule(pd); | |
4516 | |
4517 /* cleanup */ | |
4518 g_hash_table_destroy(group_sets); | |
4519 g_free(idbs); | |
4520 } | |
4521 | |
4522 | |
4523 static void mw_prpl_remove_buddy(GaimConnection *gc, | |
4524 GaimBuddy *buddy, GaimGroup *group) { | |
4525 | |
4526 struct mwGaimPluginData *pd; | |
4527 struct mwAwareIdBlock idb = { mwAware_USER, buddy->name, NULL }; | |
4528 struct mwAwareList *list; | |
4529 | |
4530 GList *rem = g_list_prepend(NULL, &idb); | |
4531 | |
4532 pd = gc->proto_data; | |
12088 | 4533 group = gaim_buddy_get_group(buddy); |
10977 | 4534 list = list_ensure(pd, group); |
4535 | |
4536 mwAwareList_removeAware(list, rem); | |
4537 blist_schedule(pd); | |
4538 | |
4539 g_list_free(rem); | |
4540 } | |
4541 | |
4542 | |
4543 static void privacy_fill(struct mwPrivacyInfo *priv, | |
4544 GSList *members) { | |
4545 | |
4546 struct mwUserItem *u; | |
4547 guint count; | |
4548 | |
4549 count = g_slist_length(members); | |
11133
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
4550 DEBUG_INFO("privacy_fill: %u members\n", count); |
10977 | 4551 |
4552 priv->count = count; | |
4553 priv->users = g_new0(struct mwUserItem, count); | |
4554 | |
4555 while(count--) { | |
4556 u = priv->users + count; | |
4557 u->id = members->data; | |
4558 members = members->next; | |
4559 } | |
4560 } | |
4561 | |
4562 | |
4563 static void mw_prpl_set_permit_deny(GaimConnection *gc) { | |
4564 GaimAccount *acct; | |
4565 struct mwGaimPluginData *pd; | |
4566 struct mwSession *session; | |
4567 | |
4568 struct mwPrivacyInfo privacy = { | |
4569 .deny = FALSE, | |
4570 .count = 0, | |
4571 .users = NULL, | |
4572 }; | |
4573 | |
4574 g_return_if_fail(gc != NULL); | |
4575 | |
4576 acct = gaim_connection_get_account(gc); | |
4577 g_return_if_fail(acct != NULL); | |
4578 | |
4579 pd = gc->proto_data; | |
4580 g_return_if_fail(pd != NULL); | |
4581 | |
4582 session = pd->session; | |
4583 g_return_if_fail(session != NULL); | |
4584 | |
4585 switch(acct->perm_deny) { | |
4586 case GAIM_PRIVACY_DENY_USERS: | |
4587 DEBUG_INFO("GAIM_PRIVACY_DENY_USERS\n"); | |
4588 privacy_fill(&privacy, acct->deny); | |
11133
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
4589 privacy.deny = TRUE; |
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
4590 break; |
10977 | 4591 |
4592 case GAIM_PRIVACY_ALLOW_ALL: | |
4593 DEBUG_INFO("GAIM_PRIVACY_ALLOW_ALL\n"); | |
4594 privacy.deny = TRUE; | |
4595 break; | |
4596 | |
4597 case GAIM_PRIVACY_ALLOW_USERS: | |
4598 DEBUG_INFO("GAIM_PRIVACY_ALLOW_USERS\n"); | |
4599 privacy_fill(&privacy, acct->permit); | |
11133
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
4600 privacy.deny = FALSE; |
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
4601 break; |
10977 | 4602 |
4603 case GAIM_PRIVACY_DENY_ALL: | |
4604 DEBUG_INFO("GAIM_PRIVACY_DENY_ALL\n"); | |
4605 privacy.deny = FALSE; | |
4606 break; | |
4607 | |
4608 default: | |
4609 DEBUG_INFO("acct->perm_deny is 0x%x\n", acct->perm_deny); | |
11133
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
4610 return; |
10977 | 4611 } |
4612 | |
4613 mwSession_setPrivacyInfo(session, &privacy); | |
4614 g_free(privacy.users); | |
4615 } | |
4616 | |
4617 | |
4618 static void mw_prpl_add_permit(GaimConnection *gc, const char *name) { | |
4619 mw_prpl_set_permit_deny(gc); | |
4620 } | |
4621 | |
4622 | |
4623 static void mw_prpl_add_deny(GaimConnection *gc, const char *name) { | |
4624 mw_prpl_set_permit_deny(gc); | |
4625 } | |
4626 | |
4627 | |
4628 static void mw_prpl_rem_permit(GaimConnection *gc, const char *name) { | |
4629 mw_prpl_set_permit_deny(gc); | |
4630 } | |
4631 | |
4632 | |
4633 static void mw_prpl_rem_deny(GaimConnection *gc, const char *name) { | |
4634 mw_prpl_set_permit_deny(gc); | |
4635 } | |
4636 | |
4637 | |
4638 static struct mwConference *conf_find(struct mwServiceConference *srvc, | |
4639 const char *name) { | |
4640 GList *l, *ll; | |
4641 struct mwConference *conf = NULL; | |
4642 | |
4643 ll = mwServiceConference_getConferences(srvc); | |
4644 for(l = ll; l; l = l->next) { | |
4645 struct mwConference *c = l->data; | |
4646 if(! strcmp(name, mwConference_getName(c))) { | |
4647 conf = c; | |
4648 break; | |
4649 } | |
4650 } | |
4651 g_list_free(ll); | |
4652 | |
4653 return conf; | |
4654 } | |
4655 | |
4656 | |
4657 static void mw_prpl_join_chat(GaimConnection *gc, | |
4658 GHashTable *components) { | |
4659 | |
4660 struct mwGaimPluginData *pd; | |
4661 char *c, *t; | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4662 |
10977 | 4663 pd = gc->proto_data; |
4664 | |
4665 c = g_hash_table_lookup(components, CHAT_KEY_NAME); | |
4666 t = g_hash_table_lookup(components, CHAT_KEY_TOPIC); | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4667 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4668 if(g_hash_table_lookup(components, CHAT_KEY_IS_PLACE)) { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4669 /* use place service */ |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4670 struct mwServicePlace *srvc; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4671 struct mwPlace *place = NULL; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4672 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4673 srvc = pd->srvc_place; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4674 place = mwPlace_new(srvc, c, t); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4675 mwPlace_open(place); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4676 |
10977 | 4677 } else { |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4678 /* use conference service */ |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4679 struct mwServiceConference *srvc; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4680 struct mwConference *conf = NULL; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4681 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4682 srvc = pd->srvc_conf; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4683 if(c) conf = conf_find(srvc, c); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4684 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4685 if(conf) { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4686 DEBUG_INFO("accepting conference invitation\n"); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4687 mwConference_accept(conf); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4688 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4689 } else { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4690 DEBUG_INFO("creating new conference\n"); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4691 conf = mwConference_new(srvc, t); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4692 mwConference_open(conf); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4693 } |
10977 | 4694 } |
4695 } | |
4696 | |
4697 | |
4698 static void mw_prpl_reject_chat(GaimConnection *gc, | |
4699 GHashTable *components) { | |
4700 | |
4701 struct mwGaimPluginData *pd; | |
4702 struct mwServiceConference *srvc; | |
4703 char *c; | |
4704 | |
4705 pd = gc->proto_data; | |
4706 srvc = pd->srvc_conf; | |
4707 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4708 if(g_hash_table_lookup(components, CHAT_KEY_IS_PLACE)) { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4709 ; /* nothing needs doing */ |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4710 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4711 } else { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4712 /* reject conference */ |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4713 c = g_hash_table_lookup(components, CHAT_KEY_NAME); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4714 if(c) { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4715 struct mwConference *conf = conf_find(srvc, c); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4716 if(conf) mwConference_reject(conf, ERR_SUCCESS, "Declined"); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4717 } |
10977 | 4718 } |
4719 } | |
4720 | |
4721 | |
4722 static char *mw_prpl_get_chat_name(GHashTable *components) { | |
4723 return g_hash_table_lookup(components, CHAT_KEY_NAME); | |
4724 } | |
4725 | |
4726 | |
4727 static void mw_prpl_chat_invite(GaimConnection *gc, | |
4728 int id, | |
4729 const char *invitation, | |
4730 const char *who) { | |
4731 | |
4732 struct mwGaimPluginData *pd; | |
4733 struct mwConference *conf; | |
4734 struct mwIdBlock idb = { (char *) who, NULL }; | |
4735 | |
4736 pd = gc->proto_data; | |
4737 | |
4738 g_return_if_fail(pd != NULL); | |
4739 conf = ID_TO_CONF(pd, id); | |
4740 | |
4741 g_return_if_fail(conf != NULL); | |
4742 | |
4743 mwConference_invite(conf, &idb, invitation); | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4744 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4745 /* @todo: use Place by default instead */ |
10977 | 4746 } |
4747 | |
4748 | |
4749 static void mw_prpl_chat_leave(GaimConnection *gc, | |
4750 int id) { | |
4751 | |
4752 struct mwGaimPluginData *pd; | |
4753 struct mwConference *conf; | |
4754 | |
4755 pd = gc->proto_data; | |
4756 | |
4757 g_return_if_fail(pd != NULL); | |
4758 conf = ID_TO_CONF(pd, id); | |
4759 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4760 if(conf) { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4761 mwConference_destroy(conf, ERR_SUCCESS, "Leaving"); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4762 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4763 } else { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4764 struct mwPlace *place = ID_TO_PLACE(pd, id); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4765 g_return_if_fail(place != NULL); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4766 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4767 mwPlace_destroy(place, ERR_SUCCESS); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4768 } |
10977 | 4769 } |
4770 | |
4771 | |
4772 static void mw_prpl_chat_whisper(GaimConnection *gc, | |
4773 int id, | |
4774 const char *who, | |
4775 const char *message) { | |
4776 | |
4777 mw_prpl_send_im(gc, who, message, 0); | |
4778 } | |
4779 | |
4780 | |
4781 static int mw_prpl_chat_send(GaimConnection *gc, | |
4782 int id, | |
4783 const char *message) { | |
4784 | |
4785 struct mwGaimPluginData *pd; | |
4786 struct mwConference *conf; | |
4787 | |
4788 pd = gc->proto_data; | |
4789 | |
4790 g_return_val_if_fail(pd != NULL, 0); | |
4791 conf = ID_TO_CONF(pd, id); | |
4792 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4793 if(conf) { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4794 return ! mwConference_sendText(conf, message); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4795 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4796 } else { |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4797 struct mwPlace *place = ID_TO_PLACE(pd, id); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4798 g_return_val_if_fail(place != NULL, 0); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4799 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4800 return ! mwPlace_sendText(place, message); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4801 } |
10977 | 4802 } |
4803 | |
4804 | |
4805 static void mw_prpl_keepalive(GaimConnection *gc) { | |
4806 struct mwSession *session; | |
4807 | |
4808 g_return_if_fail(gc != NULL); | |
4809 | |
4810 session = gc_to_session(gc); | |
4811 g_return_if_fail(session != NULL); | |
4812 | |
4813 mwSession_sendKeepalive(session); | |
4814 } | |
4815 | |
4816 | |
4817 static void mw_prpl_alias_buddy(GaimConnection *gc, | |
4818 const char *who, | |
4819 const char *alias) { | |
4820 | |
4821 struct mwGaimPluginData *pd = gc->proto_data; | |
4822 g_return_if_fail(pd != NULL); | |
4823 | |
4824 /* it's a change to the buddy list, so we've gotta reflect that in | |
4825 the server copy */ | |
4826 | |
4827 blist_schedule(pd); | |
4828 } | |
4829 | |
4830 | |
4831 static void mw_prpl_group_buddy(GaimConnection *gc, | |
4832 const char *who, | |
4833 const char *old_group, | |
4834 const char *new_group) { | |
4835 | |
4836 struct mwAwareIdBlock idb = { mwAware_USER, (char *) who, NULL }; | |
4837 GList *gl = g_list_prepend(NULL, &idb); | |
4838 | |
4839 struct mwGaimPluginData *pd = gc->proto_data; | |
4840 GaimGroup *group; | |
4841 struct mwAwareList *list; | |
4842 | |
4843 /* add who to new_group's aware list */ | |
4844 group = gaim_find_group(new_group); | |
4845 list = list_ensure(pd, group); | |
4846 mwAwareList_addAware(list, gl); | |
4847 | |
4848 /* remove who from old_group's aware list */ | |
4849 group = gaim_find_group(old_group); | |
4850 list = list_ensure(pd, group); | |
4851 mwAwareList_removeAware(list, gl); | |
4852 | |
4853 g_list_free(gl); | |
4854 | |
4855 /* schedule the changes to be saved */ | |
4856 blist_schedule(pd); | |
4857 } | |
4858 | |
4859 | |
4860 static void mw_prpl_rename_group(GaimConnection *gc, | |
4861 const char *old, | |
4862 GaimGroup *group, | |
4863 GList *buddies) { | |
4864 | |
4865 struct mwGaimPluginData *pd = gc->proto_data; | |
4866 g_return_if_fail(pd != NULL); | |
4867 | |
4868 /* it's a change in the buddy list, so we've gotta reflect that in | |
4869 the server copy. Also, having this function should prevent all | |
4870 those buddies from being removed and re-added. We don't really | |
4871 give a crap what the group is named in Gaim other than to record | |
4872 that as the group name/alias */ | |
4873 | |
4874 blist_schedule(pd); | |
4875 } | |
4876 | |
4877 | |
4878 static void mw_prpl_buddy_free(GaimBuddy *buddy) { | |
4879 /* I don't think we have any cleanup for buddies yet */ | |
4880 ; | |
4881 } | |
4882 | |
4883 | |
4884 static void mw_prpl_convo_closed(GaimConnection *gc, const char *who) { | |
4885 struct mwGaimPluginData *pd = gc->proto_data; | |
4886 struct mwServiceIm *srvc; | |
4887 struct mwConversation *conv; | |
4888 struct mwIdBlock idb = { (char *) who, NULL }; | |
4889 | |
4890 g_return_if_fail(pd != NULL); | |
4891 | |
4892 srvc = pd->srvc_im; | |
4893 g_return_if_fail(srvc != NULL); | |
4894 | |
4895 conv = mwServiceIm_findConversation(srvc, &idb); | |
4896 if(! conv) return; | |
4897 | |
4898 if(mwConversation_isOpen(conv)) | |
4899 mwConversation_free(conv); | |
4900 } | |
4901 | |
4902 | |
4903 static const char *mw_prpl_normalize(const GaimAccount *account, | |
4904 const char *id) { | |
4905 | |
4906 /* code elsewhere assumes that the return value points to different | |
4907 memory than the passed value, but it won't free the normalized | |
4908 data. wtf? */ | |
4909 | |
4910 static char buf[BUF_LEN]; | |
4911 strncpy(buf, id, sizeof(buf)); | |
4912 return buf; | |
4913 } | |
4914 | |
4915 | |
4916 static void mw_prpl_remove_group(GaimConnection *gc, GaimGroup *group) { | |
4917 struct mwGaimPluginData *pd; | |
4918 struct mwAwareList *list; | |
4919 | |
4920 pd = gc->proto_data; | |
4921 g_return_if_fail(pd != NULL); | |
4922 g_return_if_fail(pd->group_list_map != NULL); | |
4923 | |
4924 list = g_hash_table_lookup(pd->group_list_map, group); | |
4925 | |
4926 if(list) { | |
4927 g_hash_table_remove(pd->group_list_map, list); | |
4928 g_hash_table_remove(pd->group_list_map, group); | |
4929 mwAwareList_free(list); | |
4930 | |
4931 blist_schedule(pd); | |
4932 } | |
4933 } | |
4934 | |
4935 | |
4936 static gboolean mw_prpl_can_receive_file(GaimConnection *gc, | |
4937 const char *who) { | |
4938 struct mwGaimPluginData *pd; | |
4939 struct mwServiceAware *srvc; | |
4940 GaimAccount *acct; | |
4941 | |
4942 g_return_val_if_fail(gc != NULL, FALSE); | |
4943 | |
4944 pd = gc->proto_data; | |
4945 g_return_val_if_fail(pd != NULL, FALSE); | |
4946 | |
4947 srvc = pd->srvc_aware; | |
4948 g_return_val_if_fail(srvc != NULL, FALSE); | |
4949 | |
4950 acct = gaim_connection_get_account(gc); | |
4951 g_return_val_if_fail(acct != NULL, FALSE); | |
4952 | |
4953 return gaim_find_buddy(acct, who) && | |
4954 user_supports(srvc, who, mwAttribute_FILE_TRANSFER); | |
4955 } | |
4956 | |
4957 | |
4958 static void ft_outgoing_init(GaimXfer *xfer) { | |
4959 GaimAccount *acct; | |
4960 GaimConnection *gc; | |
4961 | |
4962 struct mwGaimPluginData *pd; | |
4963 struct mwServiceFileTransfer *srvc; | |
4964 struct mwFileTransfer *ft; | |
4965 | |
4966 const char *filename; | |
4967 gsize filesize; | |
4968 FILE *fp; | |
4969 | |
4970 struct mwIdBlock idb = { NULL, NULL }; | |
4971 | |
4972 DEBUG_INFO("ft_outgoing_init\n"); | |
4973 | |
4974 acct = gaim_xfer_get_account(xfer); | |
4975 gc = gaim_account_get_connection(acct); | |
4976 pd = gc->proto_data; | |
4977 srvc = pd->srvc_ft; | |
4978 | |
4979 filename = gaim_xfer_get_local_filename(xfer); | |
4980 filesize = gaim_xfer_get_size(xfer); | |
4981 idb.user = xfer->who; | |
4982 | |
4983 /* test that we can actually send the file */ | |
4984 fp = g_fopen(filename, "rb"); | |
4985 if(! fp) { | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
4986 char *msg = g_strdup_printf(_("Error reading file %s: \n%s\n"), |
10977 | 4987 filename, strerror(errno)); |
4988 gaim_xfer_error(gaim_xfer_get_type(xfer), acct, xfer->who, msg); | |
4989 g_free(msg); | |
4990 return; | |
4991 } | |
4992 fclose(fp); | |
4993 | |
4994 { | |
4995 char *tmp = strrchr(filename, G_DIR_SEPARATOR); | |
4996 if(tmp++) filename = tmp; | |
4997 } | |
4998 | |
4999 ft = mwFileTransfer_new(srvc, &idb, NULL, filename, filesize); | |
5000 | |
5001 gaim_xfer_ref(xfer); | |
5002 mwFileTransfer_setClientData(ft, xfer, (GDestroyNotify) gaim_xfer_unref); | |
5003 xfer->data = ft; | |
5004 | |
5005 mwFileTransfer_offer(ft); | |
5006 } | |
5007 | |
5008 | |
5009 static void ft_outgoing_cancel(GaimXfer *xfer) { | |
5010 struct mwFileTransfer *ft = xfer->data; | |
5011 if(ft) mwFileTransfer_cancel(ft); | |
5012 } | |
5013 | |
5014 | |
5015 static void mw_prpl_send_file(GaimConnection *gc, | |
5016 const char *who, const char *file) { | |
5017 | |
5018 GaimAccount *acct; | |
5019 GaimXfer *xfer; | |
5020 | |
5021 acct = gaim_connection_get_account(gc); | |
5022 | |
5023 xfer = gaim_xfer_new(acct, GAIM_XFER_SEND, who); | |
5024 gaim_xfer_set_init_fnc(xfer, ft_outgoing_init); | |
5025 gaim_xfer_set_cancel_send_fnc(xfer, ft_outgoing_cancel); | |
5026 | |
5027 if(file) { | |
5028 DEBUG_INFO("file != NULL\n"); | |
5029 gaim_xfer_request_accepted(xfer, file); | |
5030 | |
5031 } else { | |
5032 DEBUG_INFO("file == NULL\n"); | |
5033 gaim_xfer_request(xfer); | |
5034 } | |
5035 } | |
5036 | |
5037 | |
5038 static GaimPluginProtocolInfo mw_prpl_info = { | |
5039 .options = OPT_PROTO_IM_IMAGE, | |
5040 .user_splits = NULL, /*< set in mw_plugin_init */ | |
5041 .protocol_options = NULL, /*< set in mw_plugin_init */ | |
5042 .icon_spec = NO_BUDDY_ICONS, | |
5043 .list_icon = mw_prpl_list_icon, | |
5044 .list_emblems = mw_prpl_list_emblems, | |
5045 .status_text = mw_prpl_status_text, | |
5046 .tooltip_text = mw_prpl_tooltip_text, | |
5047 .status_types = mw_prpl_status_types, | |
5048 .blist_node_menu = mw_prpl_blist_node_menu, | |
5049 .chat_info = mw_prpl_chat_info, | |
5050 .chat_info_defaults = mw_prpl_chat_info_defaults, | |
5051 .login = mw_prpl_login, | |
5052 .close = mw_prpl_close, | |
5053 .send_im = mw_prpl_send_im, | |
5054 .set_info = NULL, | |
5055 .send_typing = mw_prpl_send_typing, | |
5056 .get_info = mw_prpl_get_info, | |
11638 | 5057 .set_status = mw_prpl_set_status, |
10977 | 5058 .set_idle = mw_prpl_set_idle, |
5059 .change_passwd = NULL, | |
5060 .add_buddy = mw_prpl_add_buddy, | |
5061 .add_buddies = mw_prpl_add_buddies, | |
5062 .remove_buddy = mw_prpl_remove_buddy, | |
5063 .remove_buddies = NULL, | |
5064 .add_permit = mw_prpl_add_permit, | |
5065 .add_deny = mw_prpl_add_deny, | |
5066 .rem_permit = mw_prpl_rem_permit, | |
5067 .rem_deny = mw_prpl_rem_deny, | |
5068 .set_permit_deny = mw_prpl_set_permit_deny, | |
5069 .join_chat = mw_prpl_join_chat, | |
5070 .reject_chat = mw_prpl_reject_chat, | |
5071 .get_chat_name = mw_prpl_get_chat_name, | |
5072 .chat_invite = mw_prpl_chat_invite, | |
5073 .chat_leave = mw_prpl_chat_leave, | |
5074 .chat_whisper = mw_prpl_chat_whisper, | |
5075 .chat_send = mw_prpl_chat_send, | |
5076 .keepalive = mw_prpl_keepalive, | |
5077 .register_user = NULL, | |
5078 .get_cb_info = NULL, | |
5079 .get_cb_away = NULL, | |
5080 .alias_buddy = mw_prpl_alias_buddy, | |
5081 .group_buddy = mw_prpl_group_buddy, | |
5082 .rename_group = mw_prpl_rename_group, | |
5083 .buddy_free = mw_prpl_buddy_free, | |
5084 .convo_closed = mw_prpl_convo_closed, | |
5085 .normalize = mw_prpl_normalize, | |
5086 .set_buddy_icon = NULL, | |
5087 .remove_group = mw_prpl_remove_group, | |
5088 .get_cb_real_name = NULL, | |
5089 .set_chat_topic = NULL, | |
5090 .find_blist_chat = NULL, | |
5091 .roomlist_get_list = NULL, | |
5092 .roomlist_expand_category = NULL, | |
5093 .can_receive_file = mw_prpl_can_receive_file, | |
5094 .send_file = mw_prpl_send_file, | |
5095 }; | |
5096 | |
5097 | |
5098 static GaimPluginPrefFrame * | |
5099 mw_plugin_get_plugin_pref_frame(GaimPlugin *plugin) { | |
5100 GaimPluginPrefFrame *frame; | |
5101 GaimPluginPref *pref; | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5102 |
10977 | 5103 frame = gaim_plugin_pref_frame_new(); |
5104 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5105 pref = gaim_plugin_pref_new_with_label(_("Remotely Stored Buddy List")); |
10977 | 5106 gaim_plugin_pref_frame_add(frame, pref); |
5107 | |
5108 | |
5109 pref = gaim_plugin_pref_new_with_name(MW_PRPL_OPT_BLIST_ACTION); | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5110 gaim_plugin_pref_set_label(pref, _("Buddy List Storage Mode")); |
10977 | 5111 |
5112 gaim_plugin_pref_set_type(pref, GAIM_PLUGIN_PREF_CHOICE); | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5113 gaim_plugin_pref_add_choice(pref, _("Local Buddy List Only"), |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5114 GINT_TO_POINTER(blist_choice_LOCAL)); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5115 gaim_plugin_pref_add_choice(pref, _("Merge List from Server"), |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5116 GINT_TO_POINTER(blist_choice_MERGE)); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5117 gaim_plugin_pref_add_choice(pref, _("Merge and Save List to Server"), |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5118 GINT_TO_POINTER(blist_choice_STORE)); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5119 gaim_plugin_pref_add_choice(pref, _("Synchronize List with Server"), |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5120 GINT_TO_POINTER(blist_choice_SYNCH)); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5121 |
10977 | 5122 gaim_plugin_pref_frame_add(frame, pref); |
5123 | |
5124 return frame; | |
5125 } | |
5126 | |
5127 | |
5128 static GaimPluginUiInfo mw_plugin_ui_info = { | |
5129 .get_plugin_pref_frame = mw_plugin_get_plugin_pref_frame, | |
5130 }; | |
5131 | |
5132 | |
5133 static void status_msg_action_cb(GaimConnection *gc, | |
5134 GaimRequestFields *fields) { | |
5135 GaimAccount *acct; | |
5136 GaimRequestField *f; | |
5137 const char *msg; | |
5138 | |
5139 struct mwGaimPluginData *pd; | |
5140 struct mwServiceStorage *srvc; | |
5141 struct mwStorageUnit *unit; | |
5142 | |
5143 pd = gc->proto_data; | |
5144 srvc = pd->srvc_store; | |
5145 | |
5146 acct = gaim_connection_get_account(gc); | |
5147 | |
5148 f = gaim_request_fields_get_field(fields, "active"); | |
5149 msg = gaim_request_field_string_get_value(f); | |
5150 gaim_account_set_string(acct, MW_KEY_ACTIVE_MSG, msg); | |
5151 unit = mwStorageUnit_newString(mwStore_ACTIVE_MESSAGES, msg); | |
5152 mwServiceStorage_save(srvc, unit, NULL, NULL, NULL); | |
5153 | |
5154 f = gaim_request_fields_get_field(fields, "away"); | |
5155 msg = gaim_request_field_string_get_value(f); | |
5156 gaim_account_set_string(acct, MW_KEY_AWAY_MSG, msg); | |
5157 unit = mwStorageUnit_newString(mwStore_AWAY_MESSAGES, msg); | |
5158 mwServiceStorage_save(srvc, unit, NULL, NULL, NULL); | |
5159 | |
5160 f = gaim_request_fields_get_field(fields, "busy"); | |
5161 msg = gaim_request_field_string_get_value(f); | |
5162 gaim_account_set_string(acct, MW_KEY_BUSY_MSG, msg); | |
5163 unit = mwStorageUnit_newString(mwStore_BUSY_MESSAGES, msg); | |
5164 mwServiceStorage_save(srvc, unit, NULL, NULL, NULL); | |
5165 | |
5166 #if 0 | |
5167 /* XXX */ | |
5168 /* need to propagate the message change if we're in any of those | |
5169 default states */ | |
5170 msg = NULL; | |
5171 if(!gc->away_state || !strcmp(gc->away_state, MW_STATE_ACTIVE)) { | |
5172 msg = MW_STATE_ACTIVE; | |
5173 } else if(gc->away_state && !strcmp(gc->away_state, MW_STATE_AWAY)) { | |
5174 msg = MW_STATE_AWAY; | |
5175 } else if(gc->away_state && !strcmp(gc->away_state, MW_STATE_BUSY)) { | |
5176 msg = MW_STATE_BUSY; | |
5177 } | |
5178 if(msg) | |
5179 serv_set_away(gc, msg, NULL); | |
5180 #endif | |
5181 } | |
5182 | |
5183 | |
5184 /** Prompt for messages for the three default status types. These | |
5185 values should be mirrored as strings in the storage service */ | |
5186 static void status_msg_action(GaimPluginAction *act) { | |
5187 GaimConnection *gc; | |
5188 GaimAccount *acct; | |
5189 | |
5190 GaimRequestFields *fields; | |
5191 GaimRequestFieldGroup *g; | |
5192 GaimRequestField *f; | |
5193 | |
5194 char *msgA, *msgB; | |
5195 const char *val; | |
5196 | |
5197 gc = act->context; | |
5198 acct = gaim_connection_get_account(gc); | |
5199 | |
5200 fields = gaim_request_fields_new(); | |
5201 | |
5202 g = gaim_request_field_group_new(NULL); | |
5203 gaim_request_fields_add_group(fields, g); | |
5204 | |
5205 val = gaim_account_get_string(acct, MW_KEY_ACTIVE_MSG, | |
5206 MW_PLUGIN_DEFAULT_ACTIVE_MSG); | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5207 f = gaim_request_field_string_new("active", _("Active Message"), val, FALSE); |
10977 | 5208 gaim_request_field_set_required(f, FALSE); |
5209 gaim_request_field_group_add_field(g, f); | |
5210 | |
5211 val = gaim_account_get_string(acct, MW_KEY_AWAY_MSG, | |
5212 MW_PLUGIN_DEFAULT_AWAY_MSG); | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5213 f = gaim_request_field_string_new("away", _("Away Message"), val, FALSE); |
10977 | 5214 gaim_request_field_set_required(f, FALSE); |
5215 gaim_request_field_group_add_field(g, f); | |
5216 | |
5217 val = gaim_account_get_string(acct, MW_KEY_BUSY_MSG, | |
5218 MW_PLUGIN_DEFAULT_BUSY_MSG); | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5219 f = gaim_request_field_string_new("busy", _("Busy Message"), val, FALSE); |
10977 | 5220 gaim_request_field_set_required(f, FALSE); |
5221 gaim_request_field_group_add_field(g, f); | |
5222 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5223 msgA = _("Default status messages"); |
10977 | 5224 msgB = (""); |
5225 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5226 gaim_request_fields(gc, _("Edit Status Messages"), |
10977 | 5227 msgA, msgB, fields, |
5228 _("OK"), G_CALLBACK(status_msg_action_cb), | |
5229 _("Cancel"), NULL, | |
5230 gc); | |
5231 } | |
5232 | |
5233 | |
5234 static void st_import_action_cb(GaimConnection *gc, char *filename) { | |
5235 struct mwSametimeList *l; | |
5236 | |
5237 FILE *file; | |
5238 char buf[BUF_LEN]; | |
5239 size_t len; | |
5240 | |
5241 GString *str; | |
5242 | |
5243 file = fopen(filename, "r"); | |
5244 g_return_if_fail(file != NULL); | |
5245 | |
5246 str = g_string_new(NULL); | |
5247 while( (len = fread(buf, 1, BUF_LEN, file)) ) { | |
5248 g_string_append_len(str, buf, len); | |
5249 } | |
5250 | |
5251 fclose(file); | |
5252 | |
5253 l = mwSametimeList_load(str->str); | |
5254 g_string_free(str, TRUE); | |
5255 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5256 blist_merge(gc, l); |
10977 | 5257 mwSametimeList_free(l); |
5258 } | |
5259 | |
5260 | |
5261 /** prompts for a file to import blist from */ | |
5262 static void st_import_action(GaimPluginAction *act) { | |
5263 GaimConnection *gc; | |
5264 GaimAccount *account; | |
5265 char *title; | |
5266 | |
5267 gc = act->context; | |
5268 account = gaim_connection_get_account(gc); | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5269 title = g_strdup_printf(_("Import Sametime List for Account %s"), |
10977 | 5270 gaim_account_get_username(account)); |
5271 | |
5272 gaim_request_file(gc, title, NULL, FALSE, | |
5273 G_CALLBACK(st_import_action_cb), NULL, | |
5274 gc); | |
5275 | |
5276 g_free(title); | |
5277 } | |
5278 | |
5279 | |
5280 static void st_export_action_cb(GaimConnection *gc, char *filename) { | |
5281 struct mwSametimeList *l; | |
5282 char *str; | |
5283 FILE *file; | |
5284 | |
5285 file = fopen(filename, "w"); | |
5286 g_return_if_fail(file != NULL); | |
5287 | |
5288 l = mwSametimeList_new(); | |
5289 blist_export(gc, l); | |
5290 str = mwSametimeList_store(l); | |
5291 mwSametimeList_free(l); | |
5292 | |
5293 fprintf(file, "%s", str); | |
5294 fclose(file); | |
5295 | |
5296 g_free(str); | |
5297 } | |
5298 | |
5299 | |
5300 /** prompts for a file to export blist to */ | |
5301 static void st_export_action(GaimPluginAction *act) { | |
5302 GaimConnection *gc; | |
5303 GaimAccount *account; | |
5304 char *title; | |
5305 | |
5306 gc = act->context; | |
5307 account = gaim_connection_get_account(gc); | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5308 title = g_strdup_printf(_("Export Sametime List for Account %s"), |
10977 | 5309 gaim_account_get_username(account)); |
5310 | |
5311 gaim_request_file(gc, title, NULL, TRUE, | |
5312 G_CALLBACK(st_export_action_cb), NULL, | |
5313 gc); | |
5314 | |
5315 g_free(title); | |
5316 } | |
5317 | |
5318 | |
5319 static void remote_group_multi_cleanup(gpointer ignore, | |
5320 GaimRequestFields *fields) { | |
5321 | |
5322 GaimRequestField *f; | |
5323 const GList *l; | |
5324 | |
5325 f = gaim_request_fields_get_field(fields, "group"); | |
5326 l = gaim_request_field_list_get_items(f); | |
5327 | |
5328 for(; l; l = l->next) { | |
5329 const char *i = l->data; | |
5330 struct resolved_id *res; | |
5331 | |
5332 res = gaim_request_field_list_get_data(f, i); | |
5333 | |
5334 g_free(res->id); | |
5335 g_free(res->name); | |
5336 g_free(res); | |
5337 } | |
5338 } | |
5339 | |
5340 | |
5341 static void remote_group_done(struct mwGaimPluginData *pd, | |
5342 const char *id, const char *name) { | |
5343 GaimConnection *gc; | |
5344 GaimAccount *acct; | |
5345 GaimGroup *group; | |
5346 GaimBlistNode *gn; | |
5347 const char *owner; | |
5348 | |
5349 g_return_if_fail(pd != NULL); | |
5350 | |
5351 gc = pd->gc; | |
5352 acct = gaim_connection_get_account(gc); | |
5353 | |
5354 /* collision checking */ | |
5355 group = gaim_find_group(name); | |
5356 if(group) { | |
5357 char *msgA, *msgB; | |
5358 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5359 msgA = _("Unable to add group: group exists"); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5360 msgB = _("A group named '%s' already exists in your buddy list."); |
10977 | 5361 msgB = g_strdup_printf(msgB, name); |
5362 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5363 gaim_notify_error(gc, _("Unable to add group"), msgA, msgB); |
10977 | 5364 |
5365 g_free(msgB); | |
5366 return; | |
5367 } | |
5368 | |
5369 group = gaim_group_new(name); | |
5370 gn = (GaimBlistNode *) group; | |
5371 | |
5372 owner = gaim_account_get_username(acct); | |
5373 | |
5374 gaim_blist_node_set_string(gn, GROUP_KEY_NAME, id); | |
5375 gaim_blist_node_set_int(gn, GROUP_KEY_TYPE, mwSametimeGroup_DYNAMIC); | |
5376 gaim_blist_node_set_string(gn, GROUP_KEY_OWNER, owner); | |
5377 gaim_blist_add_group(group, NULL); | |
5378 | |
5379 group_add(pd, group); | |
5380 blist_schedule(pd); | |
5381 } | |
5382 | |
5383 | |
5384 static void remote_group_multi_cb(struct mwGaimPluginData *pd, | |
5385 GaimRequestFields *fields) { | |
5386 GaimRequestField *f; | |
5387 const GList *l; | |
5388 | |
5389 f = gaim_request_fields_get_field(fields, "group"); | |
5390 l = gaim_request_field_list_get_selected(f); | |
5391 | |
5392 if(l) { | |
5393 const char *i = l->data; | |
5394 struct resolved_id *res; | |
5395 | |
5396 res = gaim_request_field_list_get_data(f, i); | |
5397 remote_group_done(pd, res->id, res->name); | |
5398 } | |
5399 | |
5400 remote_group_multi_cleanup(NULL, fields); | |
5401 } | |
5402 | |
5403 | |
5404 static void remote_group_multi(struct mwResolveResult *result, | |
5405 struct mwGaimPluginData *pd) { | |
5406 | |
5407 GaimRequestFields *fields; | |
5408 GaimRequestFieldGroup *g; | |
5409 GaimRequestField *f; | |
5410 GList *l; | |
5411 char *msgA, *msgB; | |
5412 | |
5413 GaimConnection *gc = pd->gc; | |
5414 | |
5415 fields = gaim_request_fields_new(); | |
5416 | |
5417 g = gaim_request_field_group_new(NULL); | |
5418 gaim_request_fields_add_group(fields, g); | |
5419 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5420 f = gaim_request_field_list_new("group", _("Possible Matches")); |
10977 | 5421 gaim_request_field_list_set_multi_select(f, FALSE); |
5422 gaim_request_field_set_required(f, TRUE); | |
5423 | |
5424 for(l = result->matches; l; l = l->next) { | |
5425 struct mwResolveMatch *match = l->data; | |
5426 struct resolved_id *res = g_new0(struct resolved_id, 1); | |
5427 | |
5428 res->id = g_strdup(match->id); | |
5429 res->name = g_strdup(match->name); | |
5430 | |
5431 gaim_request_field_list_add(f, res->name, res); | |
5432 } | |
5433 | |
5434 gaim_request_field_group_add_field(g, f); | |
5435 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5436 msgA = _("Notes Address Book group results"); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5437 msgB = _("The identifier '%s' may possibly refer to any of the following" |
10977 | 5438 " Notes Address Book groups. Please select the correct group from" |
5439 " the list below to add it to your buddy list."); | |
5440 msgB = g_strdup_printf(msgB, result->name); | |
5441 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5442 gaim_request_fields(gc, _("Select Notes Address Book"), |
10977 | 5443 msgA, msgB, fields, |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5444 _("Add Group"), G_CALLBACK(remote_group_multi_cb), |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5445 _("Cancel"), G_CALLBACK(remote_group_multi_cleanup), |
10977 | 5446 pd); |
5447 | |
5448 g_free(msgB); | |
5449 } | |
5450 | |
5451 | |
5452 static void remote_group_resolved(struct mwServiceResolve *srvc, | |
5453 guint32 id, guint32 code, GList *results, | |
5454 gpointer b) { | |
11133
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
5455 |
1081735edc10
[gaim-migrate @ 13192]
Christopher O'Brien <siege@pidgin.im>
parents:
11132
diff
changeset
|
5456 struct mwResolveResult *res = NULL; |
10977 | 5457 struct mwSession *session; |
5458 struct mwGaimPluginData *pd; | |
5459 GaimConnection *gc; | |
5460 | |
5461 session = mwService_getSession(MW_SERVICE(srvc)); | |
5462 g_return_if_fail(session != NULL); | |
5463 | |
5464 pd = mwSession_getClientData(session); | |
5465 g_return_if_fail(pd != NULL); | |
5466 | |
5467 gc = pd->gc; | |
5468 g_return_if_fail(gc != NULL); | |
5469 | |
5470 if(!code && results) { | |
5471 res = results->data; | |
5472 | |
5473 if(res->matches) { | |
5474 remote_group_multi(res, pd); | |
5475 return; | |
5476 } | |
5477 } | |
5478 | |
5479 if(res && res->name) { | |
5480 char *msgA, *msgB; | |
5481 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5482 msgA = _("Unable to add group: group not found"); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5483 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5484 msgB = _("The identifier '%s' did not match any Notes Address Book" |
10977 | 5485 " groups in your Sametime community."); |
5486 msgB = g_strdup_printf(msgB, res->name); | |
5487 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5488 gaim_notify_error(gc, _("Unable to add group"), msgA, msgB); |
10977 | 5489 |
5490 g_free(msgB); | |
5491 } | |
5492 } | |
5493 | |
5494 | |
5495 static void remote_group_action_cb(GaimConnection *gc, const char *name) { | |
5496 struct mwGaimPluginData *pd; | |
5497 struct mwServiceResolve *srvc; | |
5498 GList *query; | |
5499 enum mwResolveFlag flags; | |
5500 guint32 req; | |
5501 | |
5502 pd = gc->proto_data; | |
5503 srvc = pd->srvc_resolve; | |
5504 | |
5505 query = g_list_prepend(NULL, (char *) name); | |
5506 flags = mwResolveFlag_FIRST | mwResolveFlag_GROUPS; | |
5507 | |
5508 req = mwServiceResolve_resolve(srvc, query, flags, remote_group_resolved, | |
5509 NULL, NULL); | |
5510 g_list_free(query); | |
5511 | |
5512 if(req == SEARCH_ERROR) { | |
5513 /** @todo display error */ | |
5514 } | |
5515 } | |
5516 | |
5517 | |
5518 static void remote_group_action(GaimPluginAction *act) { | |
5519 GaimConnection *gc; | |
5520 const char *msgA, *msgB; | |
5521 | |
5522 gc = act->context; | |
5523 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5524 msgA = _("Notes Address Book Group"); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5525 msgB = _("Enter the name of a Notes Address Book group in the field below" |
10977 | 5526 " to add the group and its members to your buddy list."); |
5527 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5528 gaim_request_input(gc, _("Add Group"), msgA, msgB, NULL, |
10977 | 5529 FALSE, FALSE, NULL, |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5530 _("Add"), G_CALLBACK(remote_group_action_cb), |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5531 _("Cancel"), NULL, |
10977 | 5532 gc); |
5533 } | |
5534 | |
5535 | |
5536 static GList *mw_plugin_actions(GaimPlugin *plugin, gpointer context) { | |
5537 GaimPluginAction *act; | |
5538 GList *l = NULL; | |
5539 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5540 act = gaim_plugin_action_new(_("Set Status Messages..."), |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5541 status_msg_action); |
10977 | 5542 l = g_list_append(l, act); |
5543 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5544 act = gaim_plugin_action_new(_("Import Sametime List..."), |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5545 st_import_action); |
10977 | 5546 l = g_list_append(l, act); |
5547 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5548 act = gaim_plugin_action_new(_("Export Sametime List..."), |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5549 st_export_action); |
10977 | 5550 l = g_list_append(l, act); |
5551 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5552 act = gaim_plugin_action_new(_("Add Notes Address Book Group..."), |
10977 | 5553 remote_group_action); |
5554 l = g_list_append(l, act); | |
5555 | |
5556 return l; | |
5557 } | |
5558 | |
5559 | |
5560 static gboolean mw_plugin_load(GaimPlugin *plugin) { | |
5561 return TRUE; | |
5562 } | |
5563 | |
5564 | |
5565 static gboolean mw_plugin_unload(GaimPlugin *plugin) { | |
5566 return TRUE; | |
5567 } | |
5568 | |
5569 | |
5570 static void mw_plugin_destroy(GaimPlugin *plugin) { | |
5571 g_log_remove_handler(G_LOG_DOMAIN, log_handler[0]); | |
5572 g_log_remove_handler("meanwhile", log_handler[1]); | |
5573 } | |
5574 | |
5575 | |
5576 static GaimPluginInfo mw_plugin_info = { | |
5577 .magic = GAIM_PLUGIN_MAGIC, | |
5578 .major_version = GAIM_MAJOR_VERSION, | |
5579 .minor_version = GAIM_MINOR_VERSION, | |
5580 .type = GAIM_PLUGIN_PROTOCOL, | |
5581 .ui_requirement = NULL, | |
5582 .flags = 0, | |
5583 .dependencies = NULL, | |
5584 .priority = GAIM_PRIORITY_DEFAULT, | |
5585 .id = PLUGIN_ID, | |
5586 .name = PLUGIN_NAME, | |
5587 .version = VERSION, | |
5588 .summary = PLUGIN_SUMMARY, | |
5589 .description = PLUGIN_DESC, | |
5590 .author = PLUGIN_AUTHOR, | |
5591 .homepage = PLUGIN_HOMEPAGE, | |
5592 .load = mw_plugin_load, | |
5593 .unload = mw_plugin_unload, | |
5594 .destroy = mw_plugin_destroy, | |
5595 .ui_info = NULL, | |
5596 .extra_info = &mw_prpl_info, | |
5597 .prefs_info = &mw_plugin_ui_info, | |
5598 .actions = mw_plugin_actions, | |
5599 }; | |
5600 | |
5601 | |
5602 static void mw_log_handler(const gchar *domain, GLogLevelFlags flags, | |
5603 const gchar *msg, gpointer data) { | |
12005
5b3368008513
[gaim-migrate @ 14298]
Christopher O'Brien <siege@pidgin.im>
parents:
11953
diff
changeset
|
5604 |
5b3368008513
[gaim-migrate @ 14298]
Christopher O'Brien <siege@pidgin.im>
parents:
11953
diff
changeset
|
5605 if(! (msg && *msg)) return; |
10977 | 5606 |
5607 /* handle g_log requests via gaim's built-in debug logging */ | |
5608 if(flags & G_LOG_LEVEL_ERROR) { | |
12005
5b3368008513
[gaim-migrate @ 14298]
Christopher O'Brien <siege@pidgin.im>
parents:
11953
diff
changeset
|
5609 gaim_debug_error(domain, "%s\n", msg); |
10977 | 5610 |
5611 } else if(flags & G_LOG_LEVEL_WARNING) { | |
12005
5b3368008513
[gaim-migrate @ 14298]
Christopher O'Brien <siege@pidgin.im>
parents:
11953
diff
changeset
|
5612 gaim_debug_warning(domain, "%s\n", msg); |
10977 | 5613 |
5614 } else { | |
12005
5b3368008513
[gaim-migrate @ 14298]
Christopher O'Brien <siege@pidgin.im>
parents:
11953
diff
changeset
|
5615 gaim_debug_info(domain, "%s\n", msg); |
10977 | 5616 } |
5617 } | |
5618 | |
5619 | |
5620 static void mw_plugin_init(GaimPlugin *plugin) { | |
5621 GaimAccountOption *opt; | |
5622 GList *l = NULL; | |
5623 | |
5624 GLogLevelFlags logflags = | |
5625 G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION; | |
5626 | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5627 /* set up the preferences */ |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5628 gaim_prefs_add_none(MW_PRPL_OPT_BASE); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5629 gaim_prefs_add_int(MW_PRPL_OPT_BLIST_ACTION, BLIST_CHOICE_DEFAULT); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5630 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5631 /* remove dead preferences */ |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5632 gaim_prefs_remove(MW_PRPL_OPT_PSYCHIC); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5633 gaim_prefs_remove(MW_PRPL_OPT_SAVE_DYNAMIC); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5634 |
10977 | 5635 /* host to connect to */ |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5636 opt = gaim_account_option_string_new(_("Server"), MW_KEY_HOST, |
10977 | 5637 MW_PLUGIN_DEFAULT_HOST); |
5638 l = g_list_append(l, opt); | |
5639 | |
5640 /* port to connect to */ | |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5641 opt = gaim_account_option_int_new(_("Port"), MW_KEY_PORT, |
10977 | 5642 MW_PLUGIN_DEFAULT_PORT); |
5643 l = g_list_append(l, opt); | |
5644 | |
12005
5b3368008513
[gaim-migrate @ 14298]
Christopher O'Brien <siege@pidgin.im>
parents:
11953
diff
changeset
|
5645 /* notesbuddy hack encoding */ |
5b3368008513
[gaim-migrate @ 14298]
Christopher O'Brien <siege@pidgin.im>
parents:
11953
diff
changeset
|
5646 opt = gaim_account_option_string_new(_("NotesBuddy Encoding"), |
5b3368008513
[gaim-migrate @ 14298]
Christopher O'Brien <siege@pidgin.im>
parents:
11953
diff
changeset
|
5647 MW_KEY_ENCODING, |
11943
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5648 MW_PLUGIN_DEFAULT_ENCODING); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5649 l = g_list_append(l, opt); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5650 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5651 { /* copy the old force login setting from prefs if it's |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5652 there. Don't delete the preference, since there may be more |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5653 than one account that wants to check for it. */ |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5654 gboolean b = FALSE; |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5655 const char *label = _("Force Login (Ignore Server Redirects)"); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5656 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5657 if(gaim_prefs_exists(MW_PRPL_OPT_FORCE_LOGIN)) |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5658 b = gaim_prefs_get_bool(MW_PRPL_OPT_FORCE_LOGIN); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5659 |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5660 opt = gaim_account_option_bool_new(label, MW_KEY_FORCE, b); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5661 l = g_list_append(l, opt); |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5662 } |
0110fc7c6a8a
[gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents:
11837
diff
changeset
|
5663 |
10977 | 5664 mw_prpl_info.protocol_options = l; |
5665 l = NULL; | |
5666 | |
5667 /* forward all our g_log messages to gaim. Generally all the logging | |
5668 calls are using gaim_log directly, but the g_return macros will | |
5669 get caught here */ | |
5670 log_handler[0] = g_log_set_handler(G_LOG_DOMAIN, logflags, | |
5671 mw_log_handler, NULL); | |
5672 | |
5673 /* redirect meanwhile's logging to gaim's */ | |
5674 log_handler[1] = g_log_set_handler("meanwhile", logflags, | |
5675 mw_log_handler, NULL); | |
5676 } | |
5677 | |
5678 | |
11949
47e1723a89d7
[gaim-migrate @ 14240]
Christopher O'Brien <siege@pidgin.im>
parents:
11943
diff
changeset
|
5679 GAIM_INIT_PLUGIN(sametime, mw_plugin_init, mw_plugin_info); |
10977 | 5680 /* The End. */ |
5681 |