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