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