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