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