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