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