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