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