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