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