Mercurial > pidgin
annotate libgaim/protocols/msn/msn.c @ 14827:02b70dc43044
[gaim-migrate @ 17594]
Fix the bindings for scrolling through the histories in the entrybox.
committer: Tailor Script <tailor@pidgin.im>
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Sat, 28 Oct 2006 04:59:07 +0000 |
parents | ad44ab4442b1 |
children | acf1b5803346 |
rev | line source |
---|---|
14192 | 1 /** |
2 * @file msn.c The MSN protocol plugin | |
3 * | |
4 * gaim | |
5 * | |
6 * Gaim is the legal property of its developers, whose names are too numerous | |
7 * to list here. Please refer to the COPYRIGHT file distributed with this | |
8 * source distribution. | |
9 * | |
10 * This program is free software; you can redistribute it and/or modify | |
11 * it under the terms of the GNU General Public License as published by | |
12 * the Free Software Foundation; either version 2 of the License, or | |
13 * (at your option) any later version. | |
14 * | |
15 * This program is distributed in the hope that it will be useful, | |
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 * GNU General Public License for more details. | |
19 * | |
20 * You should have received a copy of the GNU General Public License | |
21 * along with this program; if not, write to the Free Software | |
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
23 */ | |
24 #define PHOTO_SUPPORT 1 | |
25 | |
26 #include <glib.h> | |
27 | |
28 #include "msn.h" | |
29 #include "accountopt.h" | |
30 #include "msg.h" | |
31 #include "page.h" | |
32 #include "pluginpref.h" | |
33 #include "prefs.h" | |
34 #include "session.h" | |
35 #include "state.h" | |
36 #include "util.h" | |
37 #include "cmds.h" | |
38 #include "prpl.h" | |
39 #include "msn-utils.h" | |
40 #include "version.h" | |
41 | |
42 #include "switchboard.h" | |
43 #include "notification.h" | |
44 #include "sync.h" | |
45 #include "slplink.h" | |
46 | |
47 #if PHOTO_SUPPORT | |
48 #include "imgstore.h" | |
49 #endif | |
50 | |
51 typedef struct | |
52 { | |
53 GaimConnection *gc; | |
54 const char *passport; | |
55 | |
56 } MsnMobileData; | |
57 | |
58 typedef struct | |
59 { | |
60 GaimConnection *gc; | |
61 char *name; | |
62 | |
63 } MsnGetInfoData; | |
64 | |
65 typedef struct | |
66 { | |
67 MsnGetInfoData *info_data; | |
68 char *stripped; | |
69 char *url_buffer; | |
70 GString *s; | |
71 char *photo_url_text; | |
72 char *tooltip_text; | |
73 const char *title; | |
74 | |
75 } MsnGetInfoStepTwoData; | |
76 | |
77 static const char * | |
78 msn_normalize(const GaimAccount *account, const char *str) | |
79 { | |
80 static char buf[BUF_LEN]; | |
81 char *tmp; | |
82 | |
83 g_return_val_if_fail(str != NULL, NULL); | |
84 | |
85 g_snprintf(buf, sizeof(buf), "%s%s", str, | |
86 (strchr(str, '@') ? "" : "@hotmail.com")); | |
87 | |
88 tmp = g_utf8_strdown(buf, -1); | |
89 strncpy(buf, tmp, sizeof(buf)); | |
90 g_free(tmp); | |
91 | |
92 return buf; | |
93 } | |
94 | |
95 static GaimCmdRet | |
96 msn_cmd_nudge(GaimConversation *conv, const gchar *cmd, gchar **args, gchar **error, void *data) | |
97 { | |
98 GaimAccount *account = gaim_conversation_get_account(conv); | |
99 GaimConnection *gc = gaim_account_get_connection(account); | |
100 MsnMessage *msg; | |
101 MsnSession *session; | |
102 MsnSwitchBoard *swboard; | |
103 | |
104 msg = msn_message_new_nudge(); | |
105 session = gc->proto_data; | |
106 swboard = msn_session_get_swboard(session, gaim_conversation_get_name(conv), MSN_SB_FLAG_IM); | |
107 | |
108 if (swboard == NULL) | |
109 return GAIM_CMD_RET_FAILED; | |
110 | |
111 msn_switchboard_send_msg(swboard, msg, TRUE); | |
112 | |
113 gaim_conversation_write(conv, NULL, _("You have just sent a Nudge!"), GAIM_MESSAGE_SYSTEM, time(NULL)); | |
114 | |
115 return GAIM_CMD_RET_OK; | |
116 } | |
117 | |
118 static void | |
119 msn_act_id(GaimConnection *gc, const char *entry) | |
120 { | |
121 MsnCmdProc *cmdproc; | |
122 MsnSession *session; | |
123 GaimAccount *account; | |
124 const char *alias; | |
125 | |
126 session = gc->proto_data; | |
127 cmdproc = session->notification->cmdproc; | |
128 account = gaim_connection_get_account(gc); | |
129 | |
130 if(entry && strlen(entry)) | |
131 alias = gaim_url_encode(entry); | |
132 else | |
133 alias = ""; | |
134 | |
135 if (strlen(alias) > BUDDY_ALIAS_MAXLEN) | |
136 { | |
137 gaim_notify_error(gc, NULL, | |
138 _("Your new MSN friendly name is too long."), NULL); | |
139 return; | |
140 } | |
141 | |
142 msn_cmdproc_send(cmdproc, "REA", "%s %s", | |
143 gaim_account_get_username(account), | |
144 alias); | |
145 } | |
146 | |
147 static void | |
148 msn_set_prp(GaimConnection *gc, const char *type, const char *entry) | |
149 { | |
150 MsnCmdProc *cmdproc; | |
151 MsnSession *session; | |
152 | |
153 session = gc->proto_data; | |
154 cmdproc = session->notification->cmdproc; | |
155 | |
156 if (entry == NULL || *entry == '\0') | |
157 { | |
158 msn_cmdproc_send(cmdproc, "PRP", "%s", type); | |
159 } | |
160 else | |
161 { | |
162 msn_cmdproc_send(cmdproc, "PRP", "%s %s", type, | |
163 gaim_url_encode(entry)); | |
164 } | |
165 } | |
166 | |
167 static void | |
168 msn_set_home_phone_cb(GaimConnection *gc, const char *entry) | |
169 { | |
170 msn_set_prp(gc, "PHH", entry); | |
171 } | |
172 | |
173 static void | |
174 msn_set_work_phone_cb(GaimConnection *gc, const char *entry) | |
175 { | |
176 msn_set_prp(gc, "PHW", entry); | |
177 } | |
178 | |
179 static void | |
180 msn_set_mobile_phone_cb(GaimConnection *gc, const char *entry) | |
181 { | |
182 msn_set_prp(gc, "PHM", entry); | |
183 } | |
184 | |
185 static void | |
186 enable_msn_pages_cb(GaimConnection *gc) | |
187 { | |
188 msn_set_prp(gc, "MOB", "Y"); | |
189 } | |
190 | |
191 static void | |
192 disable_msn_pages_cb(GaimConnection *gc) | |
193 { | |
194 msn_set_prp(gc, "MOB", "N"); | |
195 } | |
196 | |
197 static void | |
198 send_to_mobile(GaimConnection *gc, const char *who, const char *entry) | |
199 { | |
200 MsnTransaction *trans; | |
201 MsnSession *session; | |
202 MsnCmdProc *cmdproc; | |
203 MsnPage *page; | |
204 char *payload; | |
205 size_t payload_len; | |
206 | |
207 session = gc->proto_data; | |
208 cmdproc = session->notification->cmdproc; | |
209 | |
210 page = msn_page_new(); | |
211 msn_page_set_body(page, entry); | |
212 | |
213 payload = msn_page_gen_payload(page, &payload_len); | |
214 | |
215 trans = msn_transaction_new(cmdproc, "PGD", "%s 1 %d", who, payload_len); | |
216 | |
217 msn_transaction_set_payload(trans, payload, payload_len); | |
218 | |
219 msn_page_destroy(page); | |
220 | |
221 msn_cmdproc_send_trans(cmdproc, trans); | |
222 } | |
223 | |
224 static void | |
225 send_to_mobile_cb(MsnMobileData *data, const char *entry) | |
226 { | |
227 send_to_mobile(data->gc, data->passport, entry); | |
228 g_free(data); | |
229 } | |
230 | |
231 static void | |
232 close_mobile_page_cb(MsnMobileData *data, const char *entry) | |
233 { | |
234 g_free(data); | |
235 } | |
236 | |
237 /* -- */ | |
238 | |
239 static void | |
240 msn_show_set_friendly_name(GaimPluginAction *action) | |
241 { | |
242 GaimConnection *gc; | |
243 | |
244 gc = (GaimConnection *) action->context; | |
245 | |
246 gaim_request_input(gc, NULL, _("Set your friendly name."), | |
247 _("This is the name that other MSN buddies will " | |
248 "see you as."), | |
249 gaim_connection_get_display_name(gc), FALSE, FALSE, NULL, | |
250 _("OK"), G_CALLBACK(msn_act_id), | |
251 _("Cancel"), NULL, gc); | |
252 } | |
253 | |
254 static void | |
255 msn_show_set_home_phone(GaimPluginAction *action) | |
256 { | |
257 GaimConnection *gc; | |
258 MsnSession *session; | |
259 | |
260 gc = (GaimConnection *) action->context; | |
261 session = gc->proto_data; | |
262 | |
263 gaim_request_input(gc, NULL, _("Set your home phone number."), NULL, | |
264 msn_user_get_home_phone(session->user), FALSE, FALSE, NULL, | |
265 _("OK"), G_CALLBACK(msn_set_home_phone_cb), | |
266 _("Cancel"), NULL, gc); | |
267 } | |
268 | |
269 static void | |
270 msn_show_set_work_phone(GaimPluginAction *action) | |
271 { | |
272 GaimConnection *gc; | |
273 MsnSession *session; | |
274 | |
275 gc = (GaimConnection *) action->context; | |
276 session = gc->proto_data; | |
277 | |
278 gaim_request_input(gc, NULL, _("Set your work phone number."), NULL, | |
279 msn_user_get_work_phone(session->user), FALSE, FALSE, NULL, | |
280 _("OK"), G_CALLBACK(msn_set_work_phone_cb), | |
281 _("Cancel"), NULL, gc); | |
282 } | |
283 | |
284 static void | |
285 msn_show_set_mobile_phone(GaimPluginAction *action) | |
286 { | |
287 GaimConnection *gc; | |
288 MsnSession *session; | |
289 | |
290 gc = (GaimConnection *) action->context; | |
291 session = gc->proto_data; | |
292 | |
293 gaim_request_input(gc, NULL, _("Set your mobile phone number."), NULL, | |
294 msn_user_get_mobile_phone(session->user), FALSE, FALSE, NULL, | |
295 _("OK"), G_CALLBACK(msn_set_mobile_phone_cb), | |
296 _("Cancel"), NULL, gc); | |
297 } | |
298 | |
299 static void | |
300 msn_show_set_mobile_pages(GaimPluginAction *action) | |
301 { | |
302 GaimConnection *gc; | |
303 | |
304 gc = (GaimConnection *) action->context; | |
305 | |
306 gaim_request_action(gc, NULL, _("Allow MSN Mobile pages?"), | |
307 _("Do you want to allow or disallow people on " | |
308 "your buddy list to send you MSN Mobile pages " | |
309 "to your cell phone or other mobile device?"), | |
310 -1, gc, 3, | |
311 _("Allow"), G_CALLBACK(enable_msn_pages_cb), | |
312 _("Disallow"), G_CALLBACK(disable_msn_pages_cb), | |
313 _("Cancel"), NULL); | |
314 } | |
315 | |
316 static void | |
317 msn_show_hotmail_inbox(GaimPluginAction *action) | |
318 { | |
319 GaimConnection *gc; | |
320 MsnSession *session; | |
321 | |
322 gc = (GaimConnection *) action->context; | |
323 session = gc->proto_data; | |
324 | |
325 if (session->passport_info.file == NULL) | |
326 { | |
327 gaim_notify_error(gc, NULL, | |
328 _("This Hotmail account may not be active."), NULL); | |
329 return; | |
330 } | |
331 | |
332 gaim_notify_uri(gc, session->passport_info.file); | |
333 } | |
334 | |
335 static void | |
336 show_send_to_mobile_cb(GaimBlistNode *node, gpointer ignored) | |
337 { | |
338 GaimBuddy *buddy; | |
339 GaimConnection *gc; | |
340 MsnSession *session; | |
341 MsnMobileData *data; | |
342 | |
343 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node)); | |
344 | |
345 buddy = (GaimBuddy *) node; | |
346 gc = gaim_account_get_connection(buddy->account); | |
347 | |
348 session = gc->proto_data; | |
349 | |
350 data = g_new0(MsnMobileData, 1); | |
351 data->gc = gc; | |
352 data->passport = buddy->name; | |
353 | |
354 gaim_request_input(gc, NULL, _("Send a mobile message."), NULL, | |
355 NULL, TRUE, FALSE, NULL, | |
356 _("Page"), G_CALLBACK(send_to_mobile_cb), | |
357 _("Close"), G_CALLBACK(close_mobile_page_cb), | |
358 data); | |
359 } | |
360 | |
361 static void | |
362 initiate_chat_cb(GaimBlistNode *node, gpointer data) | |
363 { | |
364 GaimBuddy *buddy; | |
365 GaimConnection *gc; | |
366 | |
367 MsnSession *session; | |
368 MsnSwitchBoard *swboard; | |
369 | |
370 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node)); | |
371 | |
372 buddy = (GaimBuddy *) node; | |
373 gc = gaim_account_get_connection(buddy->account); | |
374 | |
375 session = gc->proto_data; | |
376 | |
377 swboard = msn_switchboard_new(session); | |
378 msn_switchboard_request(swboard); | |
379 msn_switchboard_request_add_user(swboard, buddy->name); | |
380 | |
381 /* TODO: This might move somewhere else, after USR might be */ | |
382 swboard->chat_id = session->conv_seq++; | |
383 swboard->conv = serv_got_joined_chat(gc, swboard->chat_id, "MSN Chat"); | |
384 swboard->flag = MSN_SB_FLAG_IM; | |
385 | |
386 gaim_conv_chat_add_user(GAIM_CONV_CHAT(swboard->conv), | |
387 gaim_account_get_username(buddy->account), NULL, GAIM_CBFLAGS_NONE, TRUE); | |
388 } | |
389 | |
390 static void | |
391 t_msn_xfer_init(GaimXfer *xfer) | |
392 { | |
393 MsnSlpLink *slplink; | |
394 const char *filename; | |
395 FILE *fp; | |
396 | |
397 filename = gaim_xfer_get_local_filename(xfer); | |
398 | |
399 slplink = xfer->data; | |
400 | |
401 if ((fp = g_fopen(filename, "rb")) == NULL) | |
402 { | |
403 GaimAccount *account; | |
404 const char *who; | |
405 char *msg; | |
406 | |
407 account = slplink->session->account; | |
408 who = slplink->remote_user; | |
409 | |
410 msg = g_strdup_printf(_("Error reading %s: \n%s.\n"), | |
411 filename, strerror(errno)); | |
412 gaim_xfer_error(gaim_xfer_get_type(xfer), account, xfer->who, msg); | |
413 gaim_xfer_cancel_local(xfer); | |
414 g_free(msg); | |
415 | |
416 return; | |
417 } | |
418 fclose(fp); | |
419 | |
420 msn_slplink_request_ft(slplink, xfer); | |
421 } | |
422 | |
423 static GaimXfer* | |
424 msn_new_xfer(GaimConnection *gc, const char *who) | |
425 { | |
426 MsnSession *session; | |
427 MsnSlpLink *slplink; | |
428 GaimXfer *xfer; | |
429 | |
430 session = gc->proto_data; | |
431 | |
432 xfer = gaim_xfer_new(gc->account, GAIM_XFER_SEND, who); | |
433 | |
434 slplink = msn_session_get_slplink(session, who); | |
435 | |
436 xfer->data = slplink; | |
437 | |
438 gaim_xfer_set_init_fnc(xfer, t_msn_xfer_init); | |
439 | |
440 return xfer; | |
441 } | |
442 | |
443 static void | |
444 msn_send_file(GaimConnection *gc, const char *who, const char *file) | |
445 { | |
446 GaimXfer *xfer = msn_new_xfer(gc, who); | |
447 | |
448 if (file) | |
449 gaim_xfer_request_accepted(xfer, file); | |
450 else | |
451 gaim_xfer_request(xfer); | |
452 } | |
453 | |
454 static gboolean | |
455 msn_can_receive_file(GaimConnection *gc, const char *who) | |
456 { | |
457 GaimAccount *account; | |
458 char *normal; | |
459 gboolean ret; | |
460 | |
461 account = gaim_connection_get_account(gc); | |
462 | |
463 normal = g_strdup(msn_normalize(account, gaim_account_get_username(account))); | |
464 | |
465 ret = strcmp(normal, msn_normalize(account, who)); | |
466 | |
467 g_free(normal); | |
468 | |
469 return ret; | |
470 } | |
471 | |
472 /************************************************************************** | |
473 * Protocol Plugin ops | |
474 **************************************************************************/ | |
475 | |
476 static const char * | |
477 msn_list_icon(GaimAccount *a, GaimBuddy *b) | |
478 { | |
479 return "msn"; | |
480 } | |
481 | |
482 static void | |
483 msn_list_emblems(GaimBuddy *b, const char **se, const char **sw, | |
484 const char **nw, const char **ne) | |
485 { | |
486 MsnUser *user; | |
487 GaimPresence *presence; | |
488 const char *emblems[4] = { NULL, NULL, NULL, NULL }; | |
489 int i = 0; | |
490 | |
491 user = b->proto_data; | |
492 presence = gaim_buddy_get_presence(b); | |
493 | |
494 if (!gaim_presence_is_online(presence)) | |
495 emblems[i++] = "offline"; | |
496 else if (gaim_presence_is_status_active(presence, "busy") || | |
497 gaim_presence_is_status_active(presence, "phone")) | |
498 emblems[i++] = "occupied"; | |
499 else if (!gaim_presence_is_available(presence)) | |
500 emblems[i++] = "away"; | |
501 | |
502 if (user == NULL) | |
503 { | |
504 emblems[0] = "offline"; | |
505 } | |
506 else | |
507 { | |
508 if (user->mobile) | |
509 emblems[i++] = "wireless"; | |
510 } | |
511 | |
512 *se = emblems[0]; | |
513 *sw = emblems[1]; | |
514 *nw = emblems[2]; | |
515 *ne = emblems[3]; | |
516 } | |
517 | |
518 static char * | |
519 msn_status_text(GaimBuddy *buddy) | |
520 { | |
521 GaimPresence *presence; | |
522 GaimStatus *status; | |
523 | |
524 presence = gaim_buddy_get_presence(buddy); | |
525 status = gaim_presence_get_active_status(presence); | |
526 | |
527 if (!gaim_presence_is_available(presence) && !gaim_presence_is_idle(presence)) | |
528 { | |
529 return g_strdup(gaim_status_get_name(status)); | |
530 } | |
531 | |
532 return NULL; | |
533 } | |
534 | |
535 static void | |
536 msn_tooltip_text(GaimBuddy *buddy, GString *str, gboolean full) | |
537 { | |
538 MsnUser *user; | |
539 GaimPresence *presence = gaim_buddy_get_presence(buddy); | |
540 GaimStatus *status = gaim_presence_get_active_status(presence); | |
541 | |
542 user = buddy->proto_data; | |
543 | |
544 if (gaim_presence_is_online(presence)) | |
545 { | |
546 g_string_append_printf(str, _("\n<b>%s:</b> %s"), _("Status"), | |
547 gaim_presence_is_idle(presence) ? | |
548 _("Idle") : gaim_status_get_name(status)); | |
549 } | |
550 | |
551 if (full && user) | |
552 { | |
553 g_string_append_printf(str, _("\n<b>%s:</b> %s"), _("Has you"), | |
554 (user->list_op & (1 << MSN_LIST_RL)) ? | |
555 _("Yes") : _("No")); | |
556 | |
557 /* XXX: This is being shown in non-full tooltips because the | |
558 * XXX: blocked icon overlay isn't always accurate for MSN. | |
559 * XXX: This can die as soon as gaim_privacy_check() knows that | |
560 * XXX: this prpl always honors both the allow and deny lists. */ | |
561 if (user) | |
562 g_string_append_printf(str, _("\n<b>%s:</b> %s"), _("Blocked"), | |
563 (user->list_op & (1 << MSN_LIST_BL)) ? | |
564 _("Yes") : _("No")); | |
565 } | |
566 } | |
567 | |
568 static GList * | |
569 msn_status_types(GaimAccount *account) | |
570 { | |
571 GaimStatusType *status; | |
572 GList *types = NULL; | |
573 | |
574 status = gaim_status_type_new_full(GAIM_STATUS_AVAILABLE, | |
575 NULL, NULL, FALSE, TRUE, FALSE); | |
576 types = g_list_append(types, status); | |
577 | |
578 status = gaim_status_type_new_full(GAIM_STATUS_AWAY, | |
579 NULL, NULL, FALSE, TRUE, FALSE); | |
580 types = g_list_append(types, status); | |
581 | |
582 status = gaim_status_type_new_full(GAIM_STATUS_AWAY, | |
583 "brb", _("Be Right Back"), FALSE, TRUE, FALSE); | |
584 types = g_list_append(types, status); | |
585 | |
586 status = gaim_status_type_new_full(GAIM_STATUS_UNAVAILABLE, | |
587 "busy", _("Busy"), FALSE, TRUE, FALSE); | |
588 types = g_list_append(types, status); | |
589 | |
590 status = gaim_status_type_new_full(GAIM_STATUS_UNAVAILABLE, | |
591 "phone", _("On the Phone"), FALSE, TRUE, FALSE); | |
592 types = g_list_append(types, status); | |
593 | |
594 status = gaim_status_type_new_full(GAIM_STATUS_AWAY, | |
595 "lunch", _("Out to Lunch"), FALSE, TRUE, FALSE); | |
596 types = g_list_append(types, status); | |
597 | |
598 status = gaim_status_type_new_full(GAIM_STATUS_INVISIBLE, | |
599 NULL, NULL, FALSE, TRUE, FALSE); | |
600 types = g_list_append(types, status); | |
601 | |
602 status = gaim_status_type_new_full(GAIM_STATUS_OFFLINE, | |
603 NULL, NULL, FALSE, TRUE, FALSE); | |
604 types = g_list_append(types, status); | |
605 | |
606 return types; | |
607 } | |
608 | |
609 static GList * | |
610 msn_actions(GaimPlugin *plugin, gpointer context) | |
611 { | |
612 GaimConnection *gc = (GaimConnection *)context; | |
613 GaimAccount *account; | |
614 const char *user; | |
615 | |
616 GList *m = NULL; | |
617 GaimPluginAction *act; | |
618 | |
619 act = gaim_plugin_action_new(_("Set Friendly Name..."), | |
620 msn_show_set_friendly_name); | |
621 m = g_list_append(m, act); | |
622 m = g_list_append(m, NULL); | |
623 | |
624 act = gaim_plugin_action_new(_("Set Home Phone Number..."), | |
625 msn_show_set_home_phone); | |
626 m = g_list_append(m, act); | |
627 | |
628 act = gaim_plugin_action_new(_("Set Work Phone Number..."), | |
629 msn_show_set_work_phone); | |
630 m = g_list_append(m, act); | |
631 | |
632 act = gaim_plugin_action_new(_("Set Mobile Phone Number..."), | |
633 msn_show_set_mobile_phone); | |
634 m = g_list_append(m, act); | |
635 m = g_list_append(m, NULL); | |
636 | |
637 #if 0 | |
638 act = gaim_plugin_action_new(_("Enable/Disable Mobile Devices..."), | |
639 msn_show_set_mobile_support); | |
640 m = g_list_append(m, act); | |
641 #endif | |
642 | |
643 act = gaim_plugin_action_new(_("Allow/Disallow Mobile Pages..."), | |
644 msn_show_set_mobile_pages); | |
645 m = g_list_append(m, act); | |
646 | |
647 account = gaim_connection_get_account(gc); | |
648 user = msn_normalize(account, gaim_account_get_username(account)); | |
649 | |
650 if (strstr(user, "@hotmail.com") != NULL) | |
651 { | |
652 m = g_list_append(m, NULL); | |
653 act = gaim_plugin_action_new(_("Open Hotmail Inbox"), | |
654 msn_show_hotmail_inbox); | |
655 m = g_list_append(m, act); | |
656 } | |
657 | |
658 return m; | |
659 } | |
660 | |
661 static GList * | |
662 msn_buddy_menu(GaimBuddy *buddy) | |
663 { | |
664 MsnUser *user; | |
665 | |
666 GList *m = NULL; | |
667 GaimMenuAction *act; | |
668 | |
669 g_return_val_if_fail(buddy != NULL, NULL); | |
670 | |
671 user = buddy->proto_data; | |
672 | |
673 if (user != NULL) | |
674 { | |
675 if (user->mobile) | |
676 { | |
677 act = gaim_menu_action_new(_("Send to Mobile"), | |
678 GAIM_CALLBACK(show_send_to_mobile_cb), | |
679 NULL, NULL); | |
680 m = g_list_append(m, act); | |
681 } | |
682 } | |
683 | |
684 if (g_ascii_strcasecmp(buddy->name, | |
685 gaim_account_get_username(buddy->account))) | |
686 { | |
687 act = gaim_menu_action_new(_("Initiate _Chat"), | |
688 GAIM_CALLBACK(initiate_chat_cb), | |
689 NULL, NULL); | |
690 m = g_list_append(m, act); | |
691 } | |
692 | |
693 return m; | |
694 } | |
695 | |
696 static GList * | |
697 msn_blist_node_menu(GaimBlistNode *node) | |
698 { | |
699 if(GAIM_BLIST_NODE_IS_BUDDY(node)) | |
700 { | |
701 return msn_buddy_menu((GaimBuddy *) node); | |
702 } | |
703 else | |
704 { | |
705 return NULL; | |
706 } | |
707 } | |
708 | |
709 static void | |
710 msn_login(GaimAccount *account) | |
711 { | |
712 GaimConnection *gc; | |
713 MsnSession *session; | |
714 const char *username; | |
715 const char *host; | |
716 gboolean http_method = FALSE; | |
717 int port; | |
718 | |
719 gc = gaim_account_get_connection(account); | |
720 | |
721 if (!gaim_ssl_is_supported()) | |
722 { | |
723 gc->wants_to_die = TRUE; | |
724 gaim_connection_error(gc, | |
725 _("SSL support is needed for MSN. Please install a supported " | |
726 "SSL library. See http://gaim.sf.net/faq-ssl.php for more " | |
727 "information.")); | |
728 | |
729 return; | |
730 } | |
731 | |
732 http_method = gaim_account_get_bool(account, "http_method", FALSE); | |
733 | |
734 host = gaim_account_get_string(account, "server", MSN_SERVER); | |
735 port = gaim_account_get_int(account, "port", MSN_PORT); | |
736 | |
737 session = msn_session_new(account); | |
738 | |
739 gc->proto_data = session; | |
740 gc->flags |= GAIM_CONNECTION_HTML | GAIM_CONNECTION_FORMATTING_WBFO | GAIM_CONNECTION_NO_BGCOLOR | GAIM_CONNECTION_NO_FONTSIZE | GAIM_CONNECTION_NO_URLDESC; | |
741 | |
742 msn_session_set_login_step(session, MSN_LOGIN_STEP_START); | |
743 | |
744 /* Hmm, I don't like this. */ | |
745 /* XXX shx: Me neither */ | |
746 username = msn_normalize(account, gaim_account_get_username(account)); | |
747 | |
748 if (strcmp(username, gaim_account_get_username(account))) | |
749 gaim_account_set_username(account, username); | |
750 | |
751 if (!msn_session_connect(session, host, port, http_method)) | |
752 gaim_connection_error(gc, _("Failed to connect to server.")); | |
753 } | |
754 | |
755 static void | |
756 msn_close(GaimConnection *gc) | |
757 { | |
758 MsnSession *session; | |
759 | |
760 session = gc->proto_data; | |
761 | |
762 g_return_if_fail(session != NULL); | |
763 | |
764 msn_session_destroy(session); | |
765 | |
766 gc->proto_data = NULL; | |
767 } | |
768 | |
769 static int | |
770 msn_send_im(GaimConnection *gc, const char *who, const char *message, | |
771 GaimMessageFlags flags) | |
772 { | |
773 GaimAccount *account; | |
774 MsnMessage *msg; | |
775 char *msgformat; | |
776 char *msgtext; | |
777 | |
778 account = gaim_connection_get_account(gc); | |
779 | |
780 msn_import_html(message, &msgformat, &msgtext); | |
781 | |
782 if (strlen(msgtext) + strlen(msgformat) + strlen(VERSION) > 1564) | |
783 { | |
784 g_free(msgformat); | |
785 g_free(msgtext); | |
786 | |
787 return -E2BIG; | |
788 } | |
789 | |
790 msg = msn_message_new_plain(msgtext); | |
791 msn_message_set_attr(msg, "X-MMS-IM-Format", msgformat); | |
792 | |
793 g_free(msgformat); | |
794 g_free(msgtext); | |
795 | |
796 if (g_ascii_strcasecmp(who, gaim_account_get_username(account))) | |
797 { | |
798 MsnSession *session; | |
799 MsnSwitchBoard *swboard; | |
800 | |
801 session = gc->proto_data; | |
802 swboard = msn_session_get_swboard(session, who, MSN_SB_FLAG_IM); | |
803 | |
804 msn_switchboard_send_msg(swboard, msg, TRUE); | |
805 } | |
806 else | |
807 { | |
808 char *body_str, *body_enc, *pre, *post; | |
809 const char *format; | |
810 /* | |
811 * In MSN, you can't send messages to yourself, so | |
812 * we'll fake like we received it ;) | |
813 */ | |
814 body_str = msn_message_to_string(msg); | |
815 body_enc = g_markup_escape_text(body_str, -1); | |
816 g_free(body_str); | |
817 | |
818 format = msn_message_get_attr(msg, "X-MMS-IM-Format"); | |
819 msn_parse_format(format, &pre, &post); | |
820 body_str = g_strdup_printf("%s%s%s", pre ? pre : "", | |
821 body_enc ? body_enc : "", post ? post : ""); | |
822 g_free(body_enc); | |
823 g_free(pre); | |
824 g_free(post); | |
825 | |
826 serv_got_typing_stopped(gc, who); | |
827 serv_got_im(gc, who, body_str, flags, time(NULL)); | |
828 g_free(body_str); | |
829 } | |
830 | |
831 msn_message_destroy(msg); | |
832 | |
833 return 1; | |
834 } | |
835 | |
836 static unsigned int | |
837 msn_send_typing(GaimConnection *gc, const char *who, GaimTypingState state) | |
838 { | |
839 GaimAccount *account; | |
840 MsnSession *session; | |
841 MsnSwitchBoard *swboard; | |
842 MsnMessage *msg; | |
843 | |
844 account = gaim_connection_get_account(gc); | |
845 session = gc->proto_data; | |
846 | |
847 /* | |
848 * TODO: I feel like this should be "if (state != GAIM_TYPING)" | |
849 * but this is how it was before, and I don't want to break | |
850 * anything. --KingAnt | |
851 */ | |
852 if (state == GAIM_NOT_TYPING) | |
853 return 0; | |
854 | |
855 if (!g_ascii_strcasecmp(who, gaim_account_get_username(account))) | |
856 { | |
857 /* We'll just fake it, since we're sending to ourself. */ | |
858 serv_got_typing(gc, who, MSN_TYPING_RECV_TIMEOUT, GAIM_TYPING); | |
859 | |
860 return MSN_TYPING_SEND_TIMEOUT; | |
861 } | |
862 | |
863 swboard = msn_session_find_swboard(session, who); | |
864 | |
865 if (swboard == NULL || !msn_switchboard_can_send(swboard)) | |
866 return 0; | |
867 | |
868 swboard->flag |= MSN_SB_FLAG_IM; | |
869 | |
870 msg = msn_message_new(MSN_MSG_TYPING); | |
871 msn_message_set_content_type(msg, "text/x-msmsgscontrol"); | |
872 msn_message_set_flag(msg, 'U'); | |
873 msn_message_set_attr(msg, "TypingUser", | |
874 gaim_account_get_username(account)); | |
875 msn_message_set_bin_data(msg, "\r\n", 2); | |
876 | |
877 msn_switchboard_send_msg(swboard, msg, FALSE); | |
878 | |
879 msn_message_destroy(msg); | |
880 | |
881 return MSN_TYPING_SEND_TIMEOUT; | |
882 } | |
883 | |
884 static void | |
885 msn_set_status(GaimAccount *account, GaimStatus *status) | |
886 { | |
887 GaimConnection *gc; | |
888 MsnSession *session; | |
889 | |
890 gc = gaim_account_get_connection(account); | |
891 | |
892 if (gc != NULL) | |
893 { | |
894 session = gc->proto_data; | |
895 msn_change_status(session); | |
896 } | |
897 } | |
898 | |
899 static void | |
900 msn_set_idle(GaimConnection *gc, int idle) | |
901 { | |
902 MsnSession *session; | |
903 | |
904 session = gc->proto_data; | |
905 | |
906 msn_change_status(session); | |
907 } | |
908 | |
909 #if 0 | |
910 static void | |
911 fake_userlist_add_buddy(MsnUserList *userlist, | |
912 const char *who, int list_id, | |
913 const char *group_name) | |
914 { | |
915 MsnUser *user; | |
916 static int group_id_c = 1; | |
917 int group_id; | |
918 | |
919 group_id = -1; | |
920 | |
921 if (group_name != NULL) | |
922 { | |
923 MsnGroup *group; | |
924 group = msn_group_new(userlist, group_id_c, group_name); | |
925 group_id = group_id_c++; | |
926 } | |
927 | |
928 user = msn_userlist_find_user(userlist, who); | |
929 | |
930 if (user == NULL) | |
931 { | |
932 user = msn_user_new(userlist, who, NULL); | |
933 msn_userlist_add_user(userlist, user); | |
934 } | |
935 else | |
936 if (user->list_op & (1 << list_id)) | |
937 { | |
938 if (list_id == MSN_LIST_FL) | |
939 { | |
940 if (group_id >= 0) | |
941 if (g_list_find(user->group_ids, | |
942 GINT_TO_POINTER(group_id))) | |
943 return; | |
944 } | |
945 else | |
946 return; | |
947 } | |
948 | |
949 if (group_id >= 0) | |
950 { | |
951 user->group_ids = g_list_append(user->group_ids, | |
952 GINT_TO_POINTER(group_id)); | |
953 } | |
954 | |
955 user->list_op |= (1 << list_id); | |
956 } | |
957 #endif | |
958 | |
959 static void | |
960 msn_add_buddy(GaimConnection *gc, GaimBuddy *buddy, GaimGroup *group) | |
961 { | |
962 MsnSession *session; | |
963 MsnUserList *userlist; | |
964 const char *who; | |
965 | |
966 session = gc->proto_data; | |
967 userlist = session->userlist; | |
968 who = msn_normalize(gc->account, buddy->name); | |
969 | |
970 if (!session->logged_in) | |
971 { | |
972 #if 0 | |
973 fake_userlist_add_buddy(session->sync_userlist, who, MSN_LIST_FL, | |
974 group ? group->name : NULL); | |
975 #else | |
976 gaim_debug_error("msn", "msn_add_buddy called before connected\n"); | |
977 #endif | |
978 | |
979 return; | |
980 } | |
981 | |
982 #if 0 | |
983 if (group != NULL && group->name != NULL) | |
984 gaim_debug_info("msn", "msn_add_buddy: %s, %s\n", who, group->name); | |
985 else | |
986 gaim_debug_info("msn", "msn_add_buddy: %s\n", who); | |
987 #endif | |
988 | |
989 #if 0 | |
990 /* Which is the max? */ | |
991 if (session->fl_users_count >= 150) | |
992 { | |
993 gaim_debug_info("msn", "Too many buddies\n"); | |
994 /* Buddy list full */ | |
995 /* TODO: gaim should be notified of this */ | |
996 return; | |
997 } | |
998 #endif | |
999 | |
1000 /* XXX - Would group ever be NULL here? I don't think so... | |
1001 * shx: Yes it should; MSN handles non-grouped buddies, and this is only | |
1002 * internal. */ | |
1003 msn_userlist_add_buddy(userlist, who, MSN_LIST_FL, | |
1004 group ? group->name : NULL); | |
1005 } | |
1006 | |
1007 static void | |
1008 msn_rem_buddy(GaimConnection *gc, GaimBuddy *buddy, GaimGroup *group) | |
1009 { | |
1010 MsnSession *session; | |
1011 MsnUserList *userlist; | |
1012 | |
1013 session = gc->proto_data; | |
1014 userlist = session->userlist; | |
1015 | |
1016 if (!session->logged_in) | |
1017 return; | |
1018 | |
1019 /* XXX - Does buddy->name need to be msn_normalize'd here? --KingAnt */ | |
1020 msn_userlist_rem_buddy(userlist, buddy->name, MSN_LIST_FL, group->name); | |
1021 } | |
1022 | |
1023 static void | |
1024 msn_add_permit(GaimConnection *gc, const char *who) | |
1025 { | |
1026 MsnSession *session; | |
1027 MsnUserList *userlist; | |
1028 MsnUser *user; | |
1029 | |
1030 session = gc->proto_data; | |
1031 userlist = session->userlist; | |
1032 user = msn_userlist_find_user(userlist, who); | |
1033 | |
1034 if (!session->logged_in) | |
1035 return; | |
1036 | |
1037 if (user != NULL && user->list_op & MSN_LIST_BL_OP) | |
1038 msn_userlist_rem_buddy(userlist, who, MSN_LIST_BL, NULL); | |
1039 | |
1040 msn_userlist_add_buddy(userlist, who, MSN_LIST_AL, NULL); | |
1041 } | |
1042 | |
1043 static void | |
1044 msn_add_deny(GaimConnection *gc, const char *who) | |
1045 { | |
1046 MsnSession *session; | |
1047 MsnUserList *userlist; | |
1048 MsnUser *user; | |
1049 | |
1050 session = gc->proto_data; | |
1051 userlist = session->userlist; | |
1052 user = msn_userlist_find_user(userlist, who); | |
1053 | |
1054 if (!session->logged_in) | |
1055 return; | |
1056 | |
1057 if (user != NULL && user->list_op & MSN_LIST_AL_OP) | |
1058 msn_userlist_rem_buddy(userlist, who, MSN_LIST_AL, NULL); | |
1059 | |
1060 msn_userlist_add_buddy(userlist, who, MSN_LIST_BL, NULL); | |
1061 } | |
1062 | |
1063 static void | |
1064 msn_rem_permit(GaimConnection *gc, const char *who) | |
1065 { | |
1066 MsnSession *session; | |
1067 MsnUserList *userlist; | |
1068 MsnUser *user; | |
1069 | |
1070 session = gc->proto_data; | |
1071 userlist = session->userlist; | |
1072 | |
1073 if (!session->logged_in) | |
1074 return; | |
1075 | |
1076 user = msn_userlist_find_user(userlist, who); | |
1077 | |
1078 msn_userlist_rem_buddy(userlist, who, MSN_LIST_AL, NULL); | |
1079 | |
1080 if (user != NULL && user->list_op & MSN_LIST_RL_OP) | |
1081 msn_userlist_add_buddy(userlist, who, MSN_LIST_BL, NULL); | |
1082 } | |
1083 | |
1084 static void | |
1085 msn_rem_deny(GaimConnection *gc, const char *who) | |
1086 { | |
1087 MsnSession *session; | |
1088 MsnUserList *userlist; | |
1089 MsnUser *user; | |
1090 | |
1091 session = gc->proto_data; | |
1092 userlist = session->userlist; | |
1093 | |
1094 if (!session->logged_in) | |
1095 return; | |
1096 | |
1097 user = msn_userlist_find_user(userlist, who); | |
1098 | |
1099 msn_userlist_rem_buddy(userlist, who, MSN_LIST_BL, NULL); | |
1100 | |
1101 if (user != NULL && user->list_op & MSN_LIST_RL_OP) | |
1102 msn_userlist_add_buddy(userlist, who, MSN_LIST_AL, NULL); | |
1103 } | |
1104 | |
1105 static void | |
1106 msn_set_permit_deny(GaimConnection *gc) | |
1107 { | |
1108 GaimAccount *account; | |
1109 MsnSession *session; | |
1110 MsnCmdProc *cmdproc; | |
1111 | |
1112 account = gaim_connection_get_account(gc); | |
1113 session = gc->proto_data; | |
1114 cmdproc = session->notification->cmdproc; | |
1115 | |
1116 if (account->perm_deny == GAIM_PRIVACY_ALLOW_ALL || | |
1117 account->perm_deny == GAIM_PRIVACY_DENY_USERS) | |
1118 { | |
1119 msn_cmdproc_send(cmdproc, "BLP", "%s", "AL"); | |
1120 } | |
1121 else | |
1122 { | |
1123 msn_cmdproc_send(cmdproc, "BLP", "%s", "BL"); | |
1124 } | |
1125 } | |
1126 | |
1127 static void | |
1128 msn_chat_invite(GaimConnection *gc, int id, const char *msg, | |
1129 const char *who) | |
1130 { | |
1131 MsnSession *session; | |
1132 MsnSwitchBoard *swboard; | |
1133 | |
1134 session = gc->proto_data; | |
1135 | |
1136 swboard = msn_session_find_swboard_with_id(session, id); | |
1137 | |
1138 if (swboard == NULL) | |
1139 { | |
1140 /* if we have no switchboard, everyone else left the chat already */ | |
1141 swboard = msn_switchboard_new(session); | |
1142 msn_switchboard_request(swboard); | |
1143 swboard->chat_id = id; | |
1144 swboard->conv = gaim_find_chat(gc, id); | |
1145 } | |
1146 | |
1147 swboard->flag |= MSN_SB_FLAG_IM; | |
1148 | |
1149 msn_switchboard_request_add_user(swboard, who); | |
1150 } | |
1151 | |
1152 static void | |
1153 msn_chat_leave(GaimConnection *gc, int id) | |
1154 { | |
1155 MsnSession *session; | |
1156 MsnSwitchBoard *swboard; | |
1157 GaimConversation *conv; | |
1158 | |
1159 session = gc->proto_data; | |
1160 | |
1161 swboard = msn_session_find_swboard_with_id(session, id); | |
1162 | |
1163 /* if swboard is NULL we were the only person left anyway */ | |
1164 if (swboard == NULL) | |
1165 return; | |
1166 | |
1167 conv = swboard->conv; | |
1168 | |
1169 msn_switchboard_release(swboard, MSN_SB_FLAG_IM); | |
1170 | |
1171 /* If other switchboards managed to associate themselves with this | |
1172 * conv, make sure they know it's gone! */ | |
1173 if (conv != NULL) | |
1174 { | |
1175 while ((swboard = msn_session_find_swboard_with_conv(session, conv)) != NULL) | |
1176 swboard->conv = NULL; | |
1177 } | |
1178 } | |
1179 | |
1180 static int | |
1181 msn_chat_send(GaimConnection *gc, int id, const char *message, GaimMessageFlags flags) | |
1182 { | |
1183 GaimAccount *account; | |
1184 MsnSession *session; | |
1185 MsnSwitchBoard *swboard; | |
1186 MsnMessage *msg; | |
1187 char *msgformat; | |
1188 char *msgtext; | |
1189 | |
1190 account = gaim_connection_get_account(gc); | |
1191 session = gc->proto_data; | |
1192 swboard = msn_session_find_swboard_with_id(session, id); | |
1193 | |
1194 if (swboard == NULL) | |
1195 return -EINVAL; | |
1196 | |
1197 if (!swboard->ready) | |
1198 return 0; | |
1199 | |
1200 swboard->flag |= MSN_SB_FLAG_IM; | |
1201 | |
1202 msn_import_html(message, &msgformat, &msgtext); | |
1203 | |
1204 if (strlen(msgtext) + strlen(msgformat) + strlen(VERSION) > 1564) | |
1205 { | |
1206 g_free(msgformat); | |
1207 g_free(msgtext); | |
1208 | |
1209 return -E2BIG; | |
1210 } | |
1211 | |
1212 msg = msn_message_new_plain(msgtext); | |
1213 msn_message_set_attr(msg, "X-MMS-IM-Format", msgformat); | |
1214 msn_switchboard_send_msg(swboard, msg, FALSE); | |
1215 msn_message_destroy(msg); | |
1216 | |
1217 g_free(msgformat); | |
1218 g_free(msgtext); | |
1219 | |
1220 serv_got_chat_in(gc, id, gaim_account_get_username(account), 0, | |
1221 message, time(NULL)); | |
1222 | |
1223 return 0; | |
1224 } | |
1225 | |
1226 static void | |
1227 msn_keepalive(GaimConnection *gc) | |
1228 { | |
1229 MsnSession *session; | |
1230 | |
1231 session = gc->proto_data; | |
1232 | |
1233 if (!session->http_method) | |
1234 { | |
1235 MsnCmdProc *cmdproc; | |
1236 | |
1237 cmdproc = session->notification->cmdproc; | |
1238 | |
1239 msn_cmdproc_send_quick(cmdproc, "PNG", NULL, NULL); | |
1240 } | |
1241 } | |
1242 | |
1243 static void | |
1244 msn_group_buddy(GaimConnection *gc, const char *who, | |
1245 const char *old_group_name, const char *new_group_name) | |
1246 { | |
1247 MsnSession *session; | |
1248 MsnUserList *userlist; | |
1249 | |
1250 session = gc->proto_data; | |
1251 userlist = session->userlist; | |
1252 | |
1253 msn_userlist_move_buddy(userlist, who, old_group_name, new_group_name); | |
1254 } | |
1255 | |
1256 static void | |
1257 msn_rename_group(GaimConnection *gc, const char *old_name, | |
1258 GaimGroup *group, GList *moved_buddies) | |
1259 { | |
1260 MsnSession *session; | |
1261 MsnCmdProc *cmdproc; | |
1262 int old_gid; | |
1263 const char *enc_new_group_name; | |
1264 | |
1265 session = gc->proto_data; | |
1266 cmdproc = session->notification->cmdproc; | |
1267 enc_new_group_name = gaim_url_encode(group->name); | |
1268 | |
1269 old_gid = msn_userlist_find_group_id(session->userlist, old_name); | |
1270 | |
1271 if (old_gid >= 0) | |
1272 { | |
1273 msn_cmdproc_send(cmdproc, "REG", "%d %s 0", old_gid, | |
1274 enc_new_group_name); | |
1275 } | |
1276 else | |
1277 { | |
1278 msn_cmdproc_send(cmdproc, "ADG", "%s 0", enc_new_group_name); | |
1279 } | |
1280 } | |
1281 | |
1282 static void | |
1283 msn_convo_closed(GaimConnection *gc, const char *who) | |
1284 { | |
1285 MsnSession *session; | |
1286 MsnSwitchBoard *swboard; | |
1287 GaimConversation *conv; | |
1288 | |
1289 session = gc->proto_data; | |
1290 | |
1291 swboard = msn_session_find_swboard(session, who); | |
1292 | |
1293 /* | |
1294 * Don't perform an assertion here. If swboard is NULL, then the | |
1295 * switchboard was either closed by the other party, or the person | |
1296 * is talking to himself. | |
1297 */ | |
1298 if (swboard == NULL) | |
1299 return; | |
1300 | |
1301 conv = swboard->conv; | |
1302 | |
1303 msn_switchboard_release(swboard, MSN_SB_FLAG_IM); | |
1304 | |
1305 /* If other switchboards managed to associate themselves with this | |
1306 * conv, make sure they know it's gone! */ | |
1307 if (conv != NULL) | |
1308 { | |
1309 while ((swboard = msn_session_find_swboard_with_conv(session, conv)) != NULL) | |
1310 swboard->conv = NULL; | |
1311 } | |
1312 } | |
1313 | |
1314 static void | |
1315 msn_set_buddy_icon(GaimConnection *gc, const char *filename) | |
1316 { | |
1317 MsnSession *session; | |
1318 MsnUser *user; | |
1319 | |
1320 session = gc->proto_data; | |
1321 user = session->user; | |
1322 | |
1323 msn_user_set_buddy_icon(user, filename); | |
1324 | |
1325 msn_change_status(session); | |
1326 } | |
1327 | |
1328 static void | |
1329 msn_remove_group(GaimConnection *gc, GaimGroup *group) | |
1330 { | |
1331 MsnSession *session; | |
1332 MsnCmdProc *cmdproc; | |
1333 int group_id; | |
1334 | |
1335 session = gc->proto_data; | |
1336 cmdproc = session->notification->cmdproc; | |
1337 | |
1338 if ((group_id = msn_userlist_find_group_id(session->userlist, group->name)) >= 0) | |
1339 { | |
1340 msn_cmdproc_send(cmdproc, "RMG", "%d", group_id); | |
1341 } | |
1342 } | |
1343 | |
1344 static char * | |
1345 msn_tooltip_info_text(MsnGetInfoData *info_data) | |
1346 { | |
1347 GString *s; | |
1348 GaimBuddy *b; | |
1349 | |
1350 s = g_string_sized_new(80); /* wild guess */ | |
1351 | |
1352 b = gaim_find_buddy(gaim_connection_get_account(info_data->gc), | |
1353 info_data->name); | |
1354 | |
1355 if (b) | |
1356 { | |
1357 GString *str = g_string_new(""); | |
1358 char *tmp; | |
1359 | |
1360 if (b->alias && b->alias[0]) | |
1361 { | |
1362 char *aliastext = g_markup_escape_text(b->alias, -1); | |
1363 g_string_append_printf(s, _("<b>Alias:</b> %s<br>"), aliastext); | |
1364 g_free(aliastext); | |
1365 } | |
1366 | |
1367 if (b->server_alias) | |
1368 { | |
1369 char *nicktext = g_markup_escape_text(b->server_alias, -1); | |
1370 g_string_append_printf(s, _("<b>%s:</b> "), _("Nickname")); | |
1371 g_string_append_printf(s, "<font sml=\"msn\">%s</font><br>", | |
1372 nicktext); | |
1373 g_free(nicktext); | |
1374 } | |
1375 | |
1376 msn_tooltip_text(b, str, TRUE); | |
1377 tmp = gaim_strreplace((*str->str == '\n' ? str->str + 1 : str->str), | |
1378 "\n", "<br>"); | |
1379 g_string_free(str, TRUE); | |
1380 g_string_append_printf(s, "%s<br>", tmp); | |
1381 g_free(tmp); | |
1382 } | |
1383 | |
1384 return g_string_free(s, FALSE); | |
1385 } | |
1386 | |
1387 #if PHOTO_SUPPORT | |
1388 | |
1389 static char * | |
1390 msn_get_photo_url(const char *url_text) | |
1391 { | |
1392 char *p, *q; | |
1393 | |
1394 if ((p = strstr(url_text, " contactparams:photopreauthurl=\"")) != NULL) | |
1395 { | |
1396 p += strlen(" contactparams:photopreauthurl=\""); | |
1397 } | |
1398 | |
1399 if (p && (strncmp(p, "http://", 8) == 0) && ((q = strchr(p, '"')) != NULL)) | |
1400 return g_strndup(p, q - p); | |
1401 | |
1402 return NULL; | |
1403 } | |
1404 | |
14354 | 1405 static void msn_got_photo(GaimUtilFetchUrlData *url_data, gpointer data, |
1406 const gchar *url_text, size_t len, const gchar *error_message); | |
14192 | 1407 |
1408 #endif | |
1409 | |
1410 #if 0 | |
1411 static char *msn_info_date_reformat(const char *field, size_t len) | |
1412 { | |
1413 char *tmp = g_strndup(field, len); | |
1414 time_t t = gaim_str_to_time(tmp, FALSE, NULL, NULL, NULL); | |
1415 | |
1416 g_free(tmp); | |
1417 return g_strdup(gaim_date_format_short(localtime(&t))); | |
1418 } | |
1419 #endif | |
1420 | |
1421 #define MSN_GOT_INFO_GET_FIELD(a, b) \ | |
1422 found = gaim_markup_extract_info_field(stripped, stripped_len, s, \ | |
14368
705c76724ce2
[gaim-migrate @ 17074]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14354
diff
changeset
|
1423 "\n" a ":", 0, "\n", 0, "Undisclosed", b, 0, NULL, NULL); \ |
14192 | 1424 if (found) \ |
1425 sect_info = TRUE; | |
1426 | |
1427 static void | |
14354 | 1428 msn_got_info(GaimUtilFetchUrlData *url_data, gpointer data, |
1429 const gchar *url_text, size_t len, const gchar *error_message) | |
14192 | 1430 { |
1431 MsnGetInfoData *info_data = (MsnGetInfoData *)data; | |
1432 char *stripped, *p, *q; | |
1433 char buf[1024]; | |
1434 char *tooltip_text; | |
1435 char *user_url = NULL; | |
1436 gboolean found; | |
1437 gboolean has_info = FALSE; | |
1438 gboolean sect_info = FALSE; | |
1439 const char* title = NULL; | |
1440 char *url_buffer; | |
1441 char *personal = NULL; | |
1442 char *business = NULL; | |
1443 GString *s, *s2; | |
1444 int stripped_len; | |
1445 #if PHOTO_SUPPORT | |
1446 char *photo_url_text = NULL; | |
1447 MsnGetInfoStepTwoData *info2_data = NULL; | |
1448 #endif | |
1449 | |
1450 gaim_debug_info("msn", "In msn_got_info\n"); | |
1451 | |
1452 /* Make sure the connection is still valid */ | |
1453 if (g_list_find(gaim_connections_get_all(), info_data->gc) == NULL) | |
1454 { | |
1455 gaim_debug_warning("msn", "invalid connection. ignoring buddy info.\n"); | |
1456 g_free(info_data->name); | |
1457 g_free(info_data); | |
1458 return; | |
1459 } | |
1460 | |
1461 tooltip_text = msn_tooltip_info_text(info_data); | |
1462 title = _("MSN Profile"); | |
1463 | |
14354 | 1464 if (error_message != NULL || url_text == NULL || strcmp(url_text, "") == 0) |
14192 | 1465 { |
1466 g_snprintf(buf, 1024, "<html><body>%s<b>%s</b></body></html>", | |
1467 tooltip_text, _("Error retrieving profile")); | |
1468 | |
1469 gaim_notify_userinfo(info_data->gc, info_data->name, buf, NULL, NULL); | |
1470 | |
1471 g_free(tooltip_text); | |
14368
705c76724ce2
[gaim-migrate @ 17074]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14354
diff
changeset
|
1472 g_free(info_data->name); |
705c76724ce2
[gaim-migrate @ 17074]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14354
diff
changeset
|
1473 g_free(info_data); |
14192 | 1474 return; |
1475 } | |
1476 | |
1477 url_buffer = g_strdup(url_text); | |
1478 | |
1479 /* If they have a homepage link, MSN masks it such that we need to | |
1480 * fetch the url out before gaim_markup_strip_html() nukes it */ | |
1481 /* I don't think this works with the new spaces profiles - Stu 3/2/06 */ | |
1482 if ((p = strstr(url_text, | |
1483 "Take a look at my </font><A class=viewDesc title=\"")) != NULL) | |
1484 { | |
1485 p += 50; | |
1486 | |
1487 if ((q = strchr(p, '"')) != NULL) | |
1488 user_url = g_strndup(p, q - p); | |
1489 } | |
1490 | |
1491 /* | |
1492 * gaim_markup_strip_html() doesn't strip out character entities like | |
1493 * and · | |
1494 */ | |
1495 while ((p = strstr(url_buffer, " ")) != NULL) | |
1496 { | |
1497 *p = ' '; /* Turn 's into ordinary blanks */ | |
1498 p += 1; | |
1499 memmove(p, p + 5, strlen(p + 5)); | |
1500 url_buffer[strlen(url_buffer) - 5] = '\0'; | |
1501 } | |
1502 | |
1503 while ((p = strstr(url_buffer, "·")) != NULL) | |
1504 { | |
1505 memmove(p, p + 6, strlen(p + 6)); | |
1506 url_buffer[strlen(url_buffer) - 6] = '\0'; | |
1507 } | |
1508 | |
1509 /* Nuke the nasty \r's that just get in the way */ | |
1510 gaim_str_strip_char(url_buffer, '\r'); | |
1511 | |
1512 /* MSN always puts in ' for apostrophes...replace them */ | |
1513 while ((p = strstr(url_buffer, "'")) != NULL) | |
1514 { | |
1515 *p = '\''; | |
1516 memmove(p + 1, p + 5, strlen(p + 5)); | |
1517 url_buffer[strlen(url_buffer) - 4] = '\0'; | |
1518 } | |
1519 | |
1520 /* Nuke the html, it's easier than trying to parse the horrid stuff */ | |
1521 stripped = gaim_markup_strip_html(url_buffer); | |
1522 stripped_len = strlen(stripped); | |
1523 | |
1524 gaim_debug_misc("msn", "stripped = %p\n", stripped); | |
1525 gaim_debug_misc("msn", "url_buffer = %p\n", url_buffer); | |
1526 | |
1527 /* Gonna re-use the memory we've already got for url_buffer */ | |
1528 /* No we're not. */ | |
1529 s = g_string_sized_new(strlen(url_buffer)); | |
1530 s2 = g_string_sized_new(strlen(url_buffer)); | |
1531 | |
1532 /* Extract their Name and put it in */ | |
1533 MSN_GOT_INFO_GET_FIELD("Name", _("Name")) | |
1534 | |
1535 /* General */ | |
1536 MSN_GOT_INFO_GET_FIELD("Nickname", _("Nickname")); | |
1537 MSN_GOT_INFO_GET_FIELD("Age", _("Age")); | |
1538 MSN_GOT_INFO_GET_FIELD("Gender", _("Gender")); | |
1539 MSN_GOT_INFO_GET_FIELD("Occupation", _("Occupation")); | |
1540 MSN_GOT_INFO_GET_FIELD("Location", _("Location")); | |
1541 | |
1542 /* Extract their Interests and put it in */ | |
1543 found = gaim_markup_extract_info_field(stripped, stripped_len, s, | |
1544 "\nInterests\t", 0, " (/default.aspx?page=searchresults", 0, | |
1545 "Undisclosed", _("Hobbies and Interests") /* _("Interests") */, | |
1546 0, NULL, NULL); | |
1547 | |
1548 if (found) | |
1549 sect_info = TRUE; | |
1550 | |
1551 MSN_GOT_INFO_GET_FIELD("More about me", _("A Little About Me")); | |
1552 | |
1553 if (sect_info) | |
1554 { | |
1555 /* trim off the trailing "<br>\n" */ | |
1556 g_string_truncate(s, strlen(s->str) - 5); | |
1557 g_string_append_printf(s2, _("%s<b>General</b><br>%s"), | |
1558 (*tooltip_text) ? "<hr>" : "", s->str); | |
1559 s = g_string_truncate(s, 0); | |
1560 has_info = TRUE; | |
1561 sect_info = FALSE; | |
1562 } | |
1563 | |
1564 | |
1565 /* Social */ | |
1566 MSN_GOT_INFO_GET_FIELD("Marital status", _("Marital Status")); | |
1567 MSN_GOT_INFO_GET_FIELD("Interested in", _("Interests")); | |
1568 MSN_GOT_INFO_GET_FIELD("Pets", _("Pets")); | |
1569 MSN_GOT_INFO_GET_FIELD("Hometown", _("Hometown")); | |
1570 MSN_GOT_INFO_GET_FIELD("Places lived", _("Places Lived")); | |
1571 MSN_GOT_INFO_GET_FIELD("Fashion", _("Fashion")); | |
1572 MSN_GOT_INFO_GET_FIELD("Humor", _("Humor")); | |
1573 MSN_GOT_INFO_GET_FIELD("Music", _("Music")); | |
1574 MSN_GOT_INFO_GET_FIELD("Favorite quote", _("Favorite Quote")); | |
1575 | |
1576 if (sect_info) | |
1577 { | |
1578 g_string_append_printf(s2, _("%s<b>Social</b><br>%s"), has_info ? "<br><hr>" : "", s->str); | |
1579 s = g_string_truncate(s, 0); | |
1580 has_info = TRUE; | |
1581 sect_info = FALSE; | |
1582 } | |
1583 | |
1584 /* Contact Info */ | |
1585 /* Personal */ | |
1586 MSN_GOT_INFO_GET_FIELD("Name", _("Name")); | |
1587 MSN_GOT_INFO_GET_FIELD("Significant other", _("Significant Other")); | |
1588 MSN_GOT_INFO_GET_FIELD("Home phone", _("Home Phone")); | |
1589 MSN_GOT_INFO_GET_FIELD("Home phone 2", _("Home Phone 2")); | |
1590 MSN_GOT_INFO_GET_FIELD("Home address", _("Home Address")); | |
1591 MSN_GOT_INFO_GET_FIELD("Personal Mobile", _("Personal Mobile")); | |
1592 MSN_GOT_INFO_GET_FIELD("Home fax", _("Home Fax")); | |
1593 MSN_GOT_INFO_GET_FIELD("Personal e-mail", _("Personal E-Mail")); | |
1594 MSN_GOT_INFO_GET_FIELD("Personal IM", _("Personal IM")); | |
1595 MSN_GOT_INFO_GET_FIELD("Birthday", _("Birthday")); | |
1596 MSN_GOT_INFO_GET_FIELD("Anniversary", _("Anniversary")); | |
1597 MSN_GOT_INFO_GET_FIELD("Notes", _("Notes")); | |
1598 | |
1599 if (sect_info) | |
1600 { | |
1601 personal = g_strdup_printf(_("<br><b>Personal</b><br>%s"), s->str); | |
1602 s = g_string_truncate(s, 0); | |
1603 sect_info = FALSE; | |
14368
705c76724ce2
[gaim-migrate @ 17074]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14354
diff
changeset
|
1604 has_info = TRUE; |
14192 | 1605 } |
1606 | |
1607 /* Business */ | |
1608 MSN_GOT_INFO_GET_FIELD("Name", _("Name")); | |
1609 MSN_GOT_INFO_GET_FIELD("Job title", _("Job Title")); | |
1610 MSN_GOT_INFO_GET_FIELD("Company", _("Company")); | |
1611 MSN_GOT_INFO_GET_FIELD("Department", _("Department")); | |
1612 MSN_GOT_INFO_GET_FIELD("Profession", _("Profession")); | |
1613 MSN_GOT_INFO_GET_FIELD("Work phone 1", _("Work Phone")); | |
1614 MSN_GOT_INFO_GET_FIELD("Work phone 2", _("Work Phone 2")); | |
1615 MSN_GOT_INFO_GET_FIELD("Work address", _("Work Address")); | |
1616 MSN_GOT_INFO_GET_FIELD("Work mobile", _("Work Mobile")); | |
1617 MSN_GOT_INFO_GET_FIELD("Work pager", _("Work Pager")); | |
1618 MSN_GOT_INFO_GET_FIELD("Work fax", _("Work Fax")); | |
1619 MSN_GOT_INFO_GET_FIELD("Work e-mail", _("Work E-Mail")); | |
1620 MSN_GOT_INFO_GET_FIELD("Work IM", _("Work IM")); | |
1621 MSN_GOT_INFO_GET_FIELD("Start date", _("Start Date")); | |
1622 MSN_GOT_INFO_GET_FIELD("Notes", _("Notes")); | |
1623 | |
1624 if (sect_info) | |
1625 { | |
1626 business = g_strdup_printf(_("<br><b>Business</b><br>%s"), s->str); | |
1627 s = g_string_truncate(s, 0); | |
1628 sect_info = FALSE; | |
1629 } | |
1630 | |
1631 if ((personal != NULL) || (business != NULL)) | |
1632 { | |
1633 /* trim off the trailing "<br>\n" */ | |
1634 g_string_truncate(s, strlen(s->str) - 5); | |
1635 | |
1636 has_info = TRUE; | |
1637 g_string_append_printf(s2, _("<hr><b>Contact Info</b>%s%s"), | |
1638 personal ? personal : "", | |
1639 business ? business : ""); | |
1640 } | |
1641 | |
1642 g_free(personal); | |
1643 g_free(business); | |
1644 g_string_free(s, TRUE); | |
1645 s = s2; | |
1646 | |
1647 #if 0 /* these probably don't show up any more */ | |
1648 /* | |
1649 * The fields, 'A Little About Me', 'Favorite Things', 'Hobbies | |
1650 * and Interests', 'Favorite Quote', and 'My Homepage' may or may | |
1651 * not appear, in any combination. However, they do appear in | |
1652 * certain order, so we can successively search to pin down the | |
1653 * distinct values. | |
1654 */ | |
1655 | |
1656 /* Check if they have A Little About Me */ | |
1657 found = gaim_markup_extract_info_field(stripped, stripped_len, s, | |
1658 " A Little About Me \n\n", 0, "Favorite Things", '\n', NULL, | |
1659 _("A Little About Me"), 0, NULL, NULL); | |
1660 | |
1661 if (!found) | |
1662 { | |
1663 found = gaim_markup_extract_info_field(stripped, stripped_len, s, | |
1664 " A Little About Me \n\n", 0, "Hobbies and Interests", '\n', | |
1665 NULL, _("A Little About Me"), 0, NULL, NULL); | |
1666 } | |
1667 | |
1668 if (!found) | |
1669 { | |
1670 found = gaim_markup_extract_info_field(stripped, stripped_len, s, | |
1671 " A Little About Me \n\n", 0, "Favorite Quote", '\n', NULL, | |
1672 _("A Little About Me"), 0, NULL, NULL); | |
1673 } | |
1674 | |
1675 if (!found) | |
1676 { | |
1677 found = gaim_markup_extract_info_field(stripped, stripped_len, s, | |
1678 " A Little About Me \n\n", 0, "My Homepage \n\nTake a look", | |
1679 '\n', | |
1680 NULL, _("A Little About Me"), 0, NULL, NULL); | |
1681 } | |
1682 | |
1683 if (!found) | |
1684 { | |
1685 gaim_markup_extract_info_field(stripped, stripped_len, s, | |
1686 " A Little About Me \n\n", 0, "last updated", '\n', NULL, | |
1687 _("A Little About Me"), 0, NULL, NULL); | |
1688 } | |
1689 | |
1690 if (found) | |
1691 has_info = TRUE; | |
1692 | |
1693 /* Check if they have Favorite Things */ | |
1694 found = gaim_markup_extract_info_field(stripped, stripped_len, s, | |
1695 " Favorite Things \n\n", 0, "Hobbies and Interests", '\n', NULL, | |
1696 _("Favorite Things"), 0, NULL, NULL); | |
1697 | |
1698 if (!found) | |
1699 { | |
1700 found = gaim_markup_extract_info_field(stripped, stripped_len, s, | |
1701 " Favorite Things \n\n", 0, "Favorite Quote", '\n', NULL, | |
1702 _("Favorite Things"), 0, NULL, NULL); | |
1703 } | |
1704 | |
1705 if (!found) | |
1706 { | |
1707 found = gaim_markup_extract_info_field(stripped, stripped_len, s, | |
1708 " Favorite Things \n\n", 0, "My Homepage \n\nTake a look", '\n', | |
1709 NULL, _("Favorite Things"), 0, NULL, NULL); | |
1710 } | |
1711 | |
1712 if (!found) | |
1713 { | |
1714 gaim_markup_extract_info_field(stripped, stripped_len, s, | |
1715 " Favorite Things \n\n", 0, "last updated", '\n', NULL, | |
1716 _("Favorite Things"), 0, NULL, NULL); | |
1717 } | |
1718 | |
1719 if (found) | |
1720 has_info = TRUE; | |
1721 | |
1722 /* Check if they have Hobbies and Interests */ | |
1723 found = gaim_markup_extract_info_field(stripped, stripped_len, s, | |
1724 " Hobbies and Interests \n\n", 0, "Favorite Quote", '\n', NULL, | |
1725 _("Hobbies and Interests"), 0, NULL, NULL); | |
1726 | |
1727 if (!found) | |
1728 { | |
1729 found = gaim_markup_extract_info_field(stripped, stripped_len, s, | |
1730 " Hobbies and Interests \n\n", 0, "My Homepage \n\nTake a look", | |
1731 '\n', NULL, _("Hobbies and Interests"), 0, NULL, NULL); | |
1732 } | |
1733 | |
1734 if (!found) | |
1735 { | |
1736 gaim_markup_extract_info_field(stripped, stripped_len, s, | |
1737 " Hobbies and Interests \n\n", 0, "last updated", '\n', NULL, | |
1738 _("Hobbies and Interests"), 0, NULL, NULL); | |
1739 } | |
1740 | |
1741 if (found) | |
1742 has_info = TRUE; | |
1743 | |
1744 /* Check if they have Favorite Quote */ | |
1745 found = gaim_markup_extract_info_field(stripped, stripped_len, s, | |
1746 "Favorite Quote \n\n", 0, "My Homepage \n\nTake a look", '\n', NULL, | |
1747 _("Favorite Quote"), 0, NULL, NULL); | |
1748 | |
1749 if (!found) | |
1750 { | |
1751 gaim_markup_extract_info_field(stripped, stripped_len, s, | |
1752 "Favorite Quote \n\n", 0, "last updated", '\n', NULL, | |
1753 _("Favorite Quote"), 0, NULL, NULL); | |
1754 } | |
1755 | |
1756 if (found) | |
1757 has_info = TRUE; | |
1758 | |
1759 /* Extract the last updated date and put it in */ | |
1760 found = gaim_markup_extract_info_field(stripped, stripped_len, s, | |
1761 " last updated:", 1, "\n", 0, NULL, _("Last Updated"), 0, | |
1762 NULL, msn_info_date_reformat); | |
1763 | |
1764 if (found) | |
1765 has_info = TRUE; | |
1766 #endif | |
1767 | |
1768 /* If we were able to fetch a homepage url earlier, stick it in there */ | |
1769 if (user_url != NULL) | |
1770 { | |
1771 g_snprintf(buf, sizeof(buf), | |
1772 "<b>%s:</b><br><a href=\"%s\">%s</a><br>\n", | |
1773 _("Homepage"), user_url, user_url); | |
1774 | |
1775 g_string_append(s, buf); | |
1776 | |
1777 g_free(user_url); | |
1778 | |
1779 has_info = TRUE; | |
1780 } | |
1781 | |
1782 if (!has_info) | |
1783 { | |
1784 /* MSN doesn't actually distinguish between "unknown member" and | |
1785 * a known member with an empty profile. Try to explain this fact. | |
1786 * Note that if we have a nonempty tooltip_text, we know the user | |
1787 * exists. | |
1788 */ | |
1789 /* This doesn't work with the new spaces profiles - Stu 3/2/06 | |
1790 char *p = strstr(url_buffer, "Unknown Member </TITLE>"); | |
1791 * This might not work for long either ... */ | |
1792 char *p = strstr(url_buffer, "form id=\"SpacesSearch\" name=\"SpacesSearch\""); | |
1793 GaimBuddy *b = gaim_find_buddy | |
1794 (gaim_connection_get_account(info_data->gc), info_data->name); | |
1795 g_string_append_printf(s, "<br><b>%s</b><br>%s<br><br>", | |
1796 _("Error retrieving profile"), | |
1797 ((p && b)? | |
1798 _("The user has not created a public profile."): | |
1799 p? _("MSN reported not being able to find the user's profile. " | |
1800 "This either means that the user does not exist, " | |
1801 "or that the user exists " | |
1802 "but has not created a public profile."): | |
1803 _("Gaim could not find " /* This should never happen */ | |
1804 "any information in the user's profile. " | |
1805 "The user most likely does not exist."))); | |
1806 } | |
1807 /* put a link to the actual profile URL */ | |
1808 g_string_append_printf(s, _("<hr><b>%s:</b> "), _("Profile URL")); | |
1809 g_string_append_printf(s, "<br><a href=\"%s%s\">%s%s</a><br>", | |
1810 PROFILE_URL, info_data->name, PROFILE_URL, info_data->name); | |
1811 | |
1812 /* Finish it off, and show it to them */ | |
1813 g_string_append(s, "</body></html>\n"); | |
1814 | |
1815 #if PHOTO_SUPPORT | |
1816 /* Find the URL to the photo; must be before the marshalling [Bug 994207] */ | |
1817 photo_url_text = msn_get_photo_url(url_text); | |
1818 | |
1819 /* Marshall the existing state */ | |
1820 info2_data = g_malloc0(sizeof(MsnGetInfoStepTwoData)); | |
1821 info2_data->info_data = info_data; | |
1822 info2_data->stripped = stripped; | |
1823 info2_data->url_buffer = url_buffer; | |
1824 info2_data->s = s; | |
1825 info2_data->photo_url_text = photo_url_text; | |
1826 info2_data->tooltip_text = tooltip_text; | |
1827 info2_data->title = title; | |
1828 | |
1829 /* Try to put the photo in there too, if there's one */ | |
1830 if (photo_url_text) | |
1831 { | |
14354 | 1832 gaim_util_fetch_url(photo_url_text, FALSE, NULL, FALSE, msn_got_photo, |
14192 | 1833 info2_data); |
1834 } | |
1835 else | |
1836 { | |
1837 /* Emulate a callback */ | |
14354 | 1838 /* TODO: Huh? */ |
1839 msn_got_photo(NULL, info2_data, NULL, 0, NULL); | |
14192 | 1840 } |
1841 } | |
1842 | |
1843 static void | |
14354 | 1844 msn_got_photo(GaimUtilFetchUrlData *url_data, gpointer user_data, |
1845 const gchar *url_text, size_t len, const gchar *error_message) | |
14192 | 1846 { |
14354 | 1847 MsnGetInfoStepTwoData *info2_data = (MsnGetInfoStepTwoData *)user_data; |
14192 | 1848 int id = -1; |
1849 | |
1850 /* Unmarshall the saved state */ | |
1851 MsnGetInfoData *info_data = info2_data->info_data; | |
1852 char *stripped = info2_data->stripped; | |
1853 char *url_buffer = info2_data->url_buffer; | |
1854 GString *s = info2_data->s; | |
1855 char *photo_url_text = info2_data->photo_url_text; | |
1856 char *tooltip_text = info2_data->tooltip_text; | |
1857 | |
1858 /* Make sure the connection is still valid if we got here by fetching a photo url */ | |
14508
8bc34ef93e55
[gaim-migrate @ 17228]
Evan Schoenberg <evan.s@dreskin.net>
parents:
14368
diff
changeset
|
1859 if (url_text && (error_message != NULL || |
8bc34ef93e55
[gaim-migrate @ 17228]
Evan Schoenberg <evan.s@dreskin.net>
parents:
14368
diff
changeset
|
1860 g_list_find(gaim_connections_get_all(), info_data->gc) == NULL)) |
14192 | 1861 { |
1862 gaim_debug_warning("msn", "invalid connection. ignoring buddy photo info.\n"); | |
1863 g_free(stripped); | |
1864 g_free(url_buffer); | |
1865 g_string_free(s, TRUE); | |
1866 g_free(tooltip_text); | |
1867 g_free(info_data->name); | |
1868 g_free(info_data); | |
1869 g_free(photo_url_text); | |
1870 g_free(info2_data); | |
1871 | |
1872 return; | |
1873 } | |
1874 | |
1875 /* Try to put the photo in there too, if there's one and is readable */ | |
14354 | 1876 if (user_data && url_text && len != 0) |
14192 | 1877 { |
1878 if (strstr(url_text, "400 Bad Request") | |
1879 || strstr(url_text, "403 Forbidden") | |
1880 || strstr(url_text, "404 Not Found")) | |
1881 { | |
1882 | |
1883 gaim_debug_info("msn", "Error getting %s: %s\n", | |
1884 photo_url_text, url_text); | |
1885 } | |
1886 else | |
1887 { | |
1888 char buf[1024]; | |
1889 gaim_debug_info("msn", "%s is %d bytes\n", photo_url_text, len); | |
1890 id = gaim_imgstore_add(url_text, len, NULL); | |
1891 g_snprintf(buf, sizeof(buf), "<img id=\"%d\"><br>", id); | |
1892 g_string_prepend(s, buf); | |
1893 } | |
1894 } | |
1895 | |
1896 /* We continue here from msn_got_info, as if nothing has happened */ | |
1897 #endif | |
1898 | |
1899 g_string_prepend(s, tooltip_text); | |
1900 gaim_notify_userinfo(info_data->gc, info_data->name, s->str, NULL, NULL); | |
1901 | |
1902 g_free(stripped); | |
1903 g_free(url_buffer); | |
1904 g_string_free(s, TRUE); | |
1905 g_free(tooltip_text); | |
1906 g_free(info_data->name); | |
1907 g_free(info_data); | |
1908 #if PHOTO_SUPPORT | |
1909 g_free(photo_url_text); | |
1910 g_free(info2_data); | |
1911 if (id != -1) | |
1912 gaim_imgstore_unref(id); | |
1913 #endif | |
1914 } | |
1915 | |
1916 static void | |
1917 msn_get_info(GaimConnection *gc, const char *name) | |
1918 { | |
1919 MsnGetInfoData *data; | |
1920 char *url; | |
1921 | |
1922 data = g_new0(MsnGetInfoData, 1); | |
1923 data->gc = gc; | |
1924 data->name = g_strdup(name); | |
1925 | |
1926 url = g_strdup_printf("%s%s", PROFILE_URL, name); | |
1927 | |
14354 | 1928 gaim_util_fetch_url(url, FALSE, |
14192 | 1929 "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)", |
1930 TRUE, msn_got_info, data); | |
1931 | |
1932 g_free(url); | |
1933 } | |
1934 | |
1935 static gboolean msn_load(GaimPlugin *plugin) | |
1936 { | |
1937 msn_notification_init(); | |
1938 msn_switchboard_init(); | |
1939 msn_sync_init(); | |
1940 | |
1941 return TRUE; | |
1942 } | |
1943 | |
1944 static gboolean msn_unload(GaimPlugin *plugin) | |
1945 { | |
1946 msn_notification_end(); | |
1947 msn_switchboard_end(); | |
1948 msn_sync_end(); | |
1949 | |
1950 return TRUE; | |
1951 } | |
1952 | |
1953 static GaimPluginProtocolInfo prpl_info = | |
1954 { | |
1955 OPT_PROTO_MAIL_CHECK, | |
1956 NULL, /* user_splits */ | |
1957 NULL, /* protocol_options */ | |
1958 {"png", 0, 0, 96, 96, GAIM_ICON_SCALE_SEND}, /* icon_spec */ | |
1959 msn_list_icon, /* list_icon */ | |
1960 msn_list_emblems, /* list_emblems */ | |
1961 msn_status_text, /* status_text */ | |
1962 msn_tooltip_text, /* tooltip_text */ | |
1963 msn_status_types, /* away_states */ | |
1964 msn_blist_node_menu, /* blist_node_menu */ | |
1965 NULL, /* chat_info */ | |
1966 NULL, /* chat_info_defaults */ | |
1967 msn_login, /* login */ | |
1968 msn_close, /* close */ | |
1969 msn_send_im, /* send_im */ | |
1970 NULL, /* set_info */ | |
1971 msn_send_typing, /* send_typing */ | |
1972 msn_get_info, /* get_info */ | |
1973 msn_set_status, /* set_away */ | |
1974 msn_set_idle, /* set_idle */ | |
1975 NULL, /* change_passwd */ | |
1976 msn_add_buddy, /* add_buddy */ | |
1977 NULL, /* add_buddies */ | |
1978 msn_rem_buddy, /* remove_buddy */ | |
1979 NULL, /* remove_buddies */ | |
1980 msn_add_permit, /* add_permit */ | |
1981 msn_add_deny, /* add_deny */ | |
1982 msn_rem_permit, /* rem_permit */ | |
1983 msn_rem_deny, /* rem_deny */ | |
1984 msn_set_permit_deny, /* set_permit_deny */ | |
1985 NULL, /* join_chat */ | |
1986 NULL, /* reject chat invite */ | |
1987 NULL, /* get_chat_name */ | |
1988 msn_chat_invite, /* chat_invite */ | |
1989 msn_chat_leave, /* chat_leave */ | |
1990 NULL, /* chat_whisper */ | |
1991 msn_chat_send, /* chat_send */ | |
1992 msn_keepalive, /* keepalive */ | |
1993 NULL, /* register_user */ | |
1994 NULL, /* get_cb_info */ | |
1995 NULL, /* get_cb_away */ | |
1996 NULL, /* alias_buddy */ | |
1997 msn_group_buddy, /* group_buddy */ | |
1998 msn_rename_group, /* rename_group */ | |
1999 NULL, /* buddy_free */ | |
2000 msn_convo_closed, /* convo_closed */ | |
2001 msn_normalize, /* normalize */ | |
2002 msn_set_buddy_icon, /* set_buddy_icon */ | |
2003 msn_remove_group, /* remove_group */ | |
2004 NULL, /* get_cb_real_name */ | |
2005 NULL, /* set_chat_topic */ | |
2006 NULL, /* find_blist_chat */ | |
2007 NULL, /* roomlist_get_list */ | |
2008 NULL, /* roomlist_cancel */ | |
2009 NULL, /* roomlist_expand_category */ | |
2010 msn_can_receive_file, /* can_receive_file */ | |
2011 msn_send_file, /* send_file */ | |
2012 msn_new_xfer, /* new_xfer */ | |
2013 NULL, /* offline_message */ | |
2014 NULL, /* whiteboard_prpl_ops */ | |
14543 | 2015 NULL, /* send_raw */ |
14192 | 2016 }; |
2017 | |
2018 static GaimPluginInfo info = | |
2019 { | |
2020 GAIM_PLUGIN_MAGIC, | |
2021 GAIM_MAJOR_VERSION, | |
2022 GAIM_MINOR_VERSION, | |
2023 GAIM_PLUGIN_PROTOCOL, /**< type */ | |
2024 NULL, /**< ui_requirement */ | |
2025 0, /**< flags */ | |
2026 NULL, /**< dependencies */ | |
2027 GAIM_PRIORITY_DEFAULT, /**< priority */ | |
2028 | |
2029 "prpl-msn", /**< id */ | |
2030 "MSN", /**< name */ | |
2031 VERSION, /**< version */ | |
2032 /** summary */ | |
2033 N_("MSN Protocol Plugin"), | |
2034 /** description */ | |
2035 N_("MSN Protocol Plugin"), | |
2036 "Christian Hammond <chipx86@gnupdate.org>", /**< author */ | |
2037 GAIM_WEBSITE, /**< homepage */ | |
2038 | |
2039 msn_load, /**< load */ | |
2040 msn_unload, /**< unload */ | |
2041 NULL, /**< destroy */ | |
2042 | |
2043 NULL, /**< ui_info */ | |
2044 &prpl_info, /**< extra_info */ | |
2045 NULL, /**< prefs_info */ | |
2046 msn_actions | |
2047 }; | |
2048 | |
2049 static void | |
2050 init_plugin(GaimPlugin *plugin) | |
2051 { | |
2052 GaimAccountOption *option; | |
2053 | |
2054 option = gaim_account_option_string_new(_("Server"), "server", | |
2055 MSN_SERVER); | |
2056 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, | |
2057 option); | |
2058 | |
2059 option = gaim_account_option_int_new(_("Port"), "port", 1863); | |
2060 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, | |
2061 option); | |
2062 | |
2063 option = gaim_account_option_bool_new(_("Use HTTP Method"), | |
2064 "http_method", FALSE); | |
2065 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, | |
2066 option); | |
2067 | |
2068 option = gaim_account_option_bool_new(_("Show custom smileys"), | |
2069 "custom_smileys", TRUE); | |
2070 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, | |
2071 option); | |
2072 | |
2073 gaim_cmd_register("nudge", "", GAIM_CMD_P_PRPL, | |
2074 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_PRPL_ONLY, | |
2075 "prpl-msn", msn_cmd_nudge, | |
2076 _("nudge: nudge a user to get their attention"), NULL); | |
2077 | |
2078 gaim_prefs_remove("/plugins/prpl/msn"); | |
2079 } | |
2080 | |
2081 GAIM_INIT_PLUGIN(msn, init_plugin, info); |