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