comparison libgaim/protocols/msn/msn.c @ 14192:60b1bc8dbf37

[gaim-migrate @ 16863] Renamed 'core' to 'libgaim' committer: Tailor Script <tailor@pidgin.im>
author Evan Schoenberg <evan.s@dreskin.net>
date Sat, 19 Aug 2006 01:50:10 +0000
parents
children 01daacf7b771
comparison
equal deleted inserted replaced
14191:009db0b357b5 14192:60b1bc8dbf37
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
1405 static void msn_got_photo(void *data, const char *url_text, size_t len);
1406
1407 #endif
1408
1409 #if 0
1410 static char *msn_info_date_reformat(const char *field, size_t len)
1411 {
1412 char *tmp = g_strndup(field, len);
1413 time_t t = gaim_str_to_time(tmp, FALSE, NULL, NULL, NULL);
1414
1415 g_free(tmp);
1416 return g_strdup(gaim_date_format_short(localtime(&t)));
1417 }
1418 #endif
1419
1420 #define MSN_GOT_INFO_GET_FIELD(a, b) \
1421 found = gaim_markup_extract_info_field(stripped, stripped_len, s, \
1422 "\n" a "\t", 0, "\n", 0, "Undisclosed", b, 0, NULL, NULL); \
1423 if (found) \
1424 sect_info = TRUE;
1425
1426 static void
1427 msn_got_info(void *data, const char *url_text, size_t len)
1428 {
1429 MsnGetInfoData *info_data = (MsnGetInfoData *)data;
1430 char *stripped, *p, *q;
1431 char buf[1024];
1432 char *tooltip_text;
1433 char *user_url = NULL;
1434 gboolean found;
1435 gboolean has_info = FALSE;
1436 gboolean sect_info = FALSE;
1437 const char* title = NULL;
1438 char *url_buffer;
1439 char *personal = NULL;
1440 char *business = NULL;
1441 GString *s, *s2;
1442 int stripped_len;
1443 #if PHOTO_SUPPORT
1444 char *photo_url_text = NULL;
1445 MsnGetInfoStepTwoData *info2_data = NULL;
1446 #endif
1447
1448 gaim_debug_info("msn", "In msn_got_info\n");
1449
1450 /* Make sure the connection is still valid */
1451 if (g_list_find(gaim_connections_get_all(), info_data->gc) == NULL)
1452 {
1453 gaim_debug_warning("msn", "invalid connection. ignoring buddy info.\n");
1454 g_free(info_data->name);
1455 g_free(info_data);
1456 return;
1457 }
1458
1459 tooltip_text = msn_tooltip_info_text(info_data);
1460 title = _("MSN Profile");
1461
1462 if (url_text == NULL || strcmp(url_text, "") == 0)
1463 {
1464 g_snprintf(buf, 1024, "<html><body>%s<b>%s</b></body></html>",
1465 tooltip_text, _("Error retrieving profile"));
1466
1467 gaim_notify_userinfo(info_data->gc, info_data->name, buf, NULL, NULL);
1468
1469 g_free(tooltip_text);
1470 return;
1471 }
1472
1473 url_buffer = g_strdup(url_text);
1474
1475 /* If they have a homepage link, MSN masks it such that we need to
1476 * fetch the url out before gaim_markup_strip_html() nukes it */
1477 /* I don't think this works with the new spaces profiles - Stu 3/2/06 */
1478 if ((p = strstr(url_text,
1479 "Take a look at my </font><A class=viewDesc title=\"")) != NULL)
1480 {
1481 p += 50;
1482
1483 if ((q = strchr(p, '"')) != NULL)
1484 user_url = g_strndup(p, q - p);
1485 }
1486
1487 /*
1488 * gaim_markup_strip_html() doesn't strip out character entities like &nbsp;
1489 * and &#183;
1490 */
1491 while ((p = strstr(url_buffer, "&nbsp;")) != NULL)
1492 {
1493 *p = ' '; /* Turn &nbsp;'s into ordinary blanks */
1494 p += 1;
1495 memmove(p, p + 5, strlen(p + 5));
1496 url_buffer[strlen(url_buffer) - 5] = '\0';
1497 }
1498
1499 while ((p = strstr(url_buffer, "&#183;")) != NULL)
1500 {
1501 memmove(p, p + 6, strlen(p + 6));
1502 url_buffer[strlen(url_buffer) - 6] = '\0';
1503 }
1504
1505 /* Nuke the nasty \r's that just get in the way */
1506 gaim_str_strip_char(url_buffer, '\r');
1507
1508 /* MSN always puts in &#39; for apostrophes...replace them */
1509 while ((p = strstr(url_buffer, "&#39;")) != NULL)
1510 {
1511 *p = '\'';
1512 memmove(p + 1, p + 5, strlen(p + 5));
1513 url_buffer[strlen(url_buffer) - 4] = '\0';
1514 }
1515
1516 /* Nuke the html, it's easier than trying to parse the horrid stuff */
1517 stripped = gaim_markup_strip_html(url_buffer);
1518 stripped_len = strlen(stripped);
1519
1520 gaim_debug_misc("msn", "stripped = %p\n", stripped);
1521 gaim_debug_misc("msn", "url_buffer = %p\n", url_buffer);
1522
1523 /* Gonna re-use the memory we've already got for url_buffer */
1524 /* No we're not. */
1525 s = g_string_sized_new(strlen(url_buffer));
1526 s2 = g_string_sized_new(strlen(url_buffer));
1527
1528 /* Extract their Name and put it in */
1529 MSN_GOT_INFO_GET_FIELD("Name", _("Name"))
1530
1531 /* General */
1532 MSN_GOT_INFO_GET_FIELD("Nickname", _("Nickname"));
1533 MSN_GOT_INFO_GET_FIELD("Age", _("Age"));
1534 MSN_GOT_INFO_GET_FIELD("Gender", _("Gender"));
1535 MSN_GOT_INFO_GET_FIELD("Occupation", _("Occupation"));
1536 MSN_GOT_INFO_GET_FIELD("Location", _("Location"));
1537
1538 /* Extract their Interests and put it in */
1539 found = gaim_markup_extract_info_field(stripped, stripped_len, s,
1540 "\nInterests\t", 0, " (/default.aspx?page=searchresults", 0,
1541 "Undisclosed", _("Hobbies and Interests") /* _("Interests") */,
1542 0, NULL, NULL);
1543
1544 if (found)
1545 sect_info = TRUE;
1546
1547 MSN_GOT_INFO_GET_FIELD("More about me", _("A Little About Me"));
1548
1549 if (sect_info)
1550 {
1551 /* trim off the trailing "<br>\n" */
1552 g_string_truncate(s, strlen(s->str) - 5);
1553 g_string_append_printf(s2, _("%s<b>General</b><br>%s"),
1554 (*tooltip_text) ? "<hr>" : "", s->str);
1555 s = g_string_truncate(s, 0);
1556 has_info = TRUE;
1557 sect_info = FALSE;
1558 }
1559
1560
1561 /* Social */
1562 MSN_GOT_INFO_GET_FIELD("Marital status", _("Marital Status"));
1563 MSN_GOT_INFO_GET_FIELD("Interested in", _("Interests"));
1564 MSN_GOT_INFO_GET_FIELD("Pets", _("Pets"));
1565 MSN_GOT_INFO_GET_FIELD("Hometown", _("Hometown"));
1566 MSN_GOT_INFO_GET_FIELD("Places lived", _("Places Lived"));
1567 MSN_GOT_INFO_GET_FIELD("Fashion", _("Fashion"));
1568 MSN_GOT_INFO_GET_FIELD("Humor", _("Humor"));
1569 MSN_GOT_INFO_GET_FIELD("Music", _("Music"));
1570 MSN_GOT_INFO_GET_FIELD("Favorite quote", _("Favorite Quote"));
1571
1572 if (sect_info)
1573 {
1574 g_string_append_printf(s2, _("%s<b>Social</b><br>%s"), has_info ? "<br><hr>" : "", s->str);
1575 s = g_string_truncate(s, 0);
1576 has_info = TRUE;
1577 sect_info = FALSE;
1578 }
1579
1580 /* Contact Info */
1581 /* Personal */
1582 MSN_GOT_INFO_GET_FIELD("Name", _("Name"));
1583 MSN_GOT_INFO_GET_FIELD("Significant other", _("Significant Other"));
1584 MSN_GOT_INFO_GET_FIELD("Home phone", _("Home Phone"));
1585 MSN_GOT_INFO_GET_FIELD("Home phone 2", _("Home Phone 2"));
1586 MSN_GOT_INFO_GET_FIELD("Home address", _("Home Address"));
1587 MSN_GOT_INFO_GET_FIELD("Personal Mobile", _("Personal Mobile"));
1588 MSN_GOT_INFO_GET_FIELD("Home fax", _("Home Fax"));
1589 MSN_GOT_INFO_GET_FIELD("Personal e-mail", _("Personal E-Mail"));
1590 MSN_GOT_INFO_GET_FIELD("Personal IM", _("Personal IM"));
1591 MSN_GOT_INFO_GET_FIELD("Birthday", _("Birthday"));
1592 MSN_GOT_INFO_GET_FIELD("Anniversary", _("Anniversary"));
1593 MSN_GOT_INFO_GET_FIELD("Notes", _("Notes"));
1594
1595 if (sect_info)
1596 {
1597 personal = g_strdup_printf(_("<br><b>Personal</b><br>%s"), s->str);
1598 s = g_string_truncate(s, 0);
1599 sect_info = FALSE;
1600 }
1601
1602 /* Business */
1603 MSN_GOT_INFO_GET_FIELD("Name", _("Name"));
1604 MSN_GOT_INFO_GET_FIELD("Job title", _("Job Title"));
1605 MSN_GOT_INFO_GET_FIELD("Company", _("Company"));
1606 MSN_GOT_INFO_GET_FIELD("Department", _("Department"));
1607 MSN_GOT_INFO_GET_FIELD("Profession", _("Profession"));
1608 MSN_GOT_INFO_GET_FIELD("Work phone 1", _("Work Phone"));
1609 MSN_GOT_INFO_GET_FIELD("Work phone 2", _("Work Phone 2"));
1610 MSN_GOT_INFO_GET_FIELD("Work address", _("Work Address"));
1611 MSN_GOT_INFO_GET_FIELD("Work mobile", _("Work Mobile"));
1612 MSN_GOT_INFO_GET_FIELD("Work pager", _("Work Pager"));
1613 MSN_GOT_INFO_GET_FIELD("Work fax", _("Work Fax"));
1614 MSN_GOT_INFO_GET_FIELD("Work e-mail", _("Work E-Mail"));
1615 MSN_GOT_INFO_GET_FIELD("Work IM", _("Work IM"));
1616 MSN_GOT_INFO_GET_FIELD("Start date", _("Start Date"));
1617 MSN_GOT_INFO_GET_FIELD("Notes", _("Notes"));
1618
1619 if (sect_info)
1620 {
1621 business = g_strdup_printf(_("<br><b>Business</b><br>%s"), s->str);
1622 s = g_string_truncate(s, 0);
1623 sect_info = FALSE;
1624 }
1625
1626 if ((personal != NULL) || (business != NULL))
1627 {
1628 /* trim off the trailing "<br>\n" */
1629 g_string_truncate(s, strlen(s->str) - 5);
1630
1631 has_info = TRUE;
1632 g_string_append_printf(s2, _("<hr><b>Contact Info</b>%s%s"),
1633 personal ? personal : "",
1634 business ? business : "");
1635 }
1636
1637 g_free(personal);
1638 g_free(business);
1639 g_string_free(s, TRUE);
1640 s = s2;
1641
1642 #if 0 /* these probably don't show up any more */
1643 /*
1644 * The fields, 'A Little About Me', 'Favorite Things', 'Hobbies
1645 * and Interests', 'Favorite Quote', and 'My Homepage' may or may
1646 * not appear, in any combination. However, they do appear in
1647 * certain order, so we can successively search to pin down the
1648 * distinct values.
1649 */
1650
1651 /* Check if they have A Little About Me */
1652 found = gaim_markup_extract_info_field(stripped, stripped_len, s,
1653 " A Little About Me \n\n", 0, "Favorite Things", '\n', NULL,
1654 _("A Little About Me"), 0, NULL, NULL);
1655
1656 if (!found)
1657 {
1658 found = gaim_markup_extract_info_field(stripped, stripped_len, s,
1659 " A Little About Me \n\n", 0, "Hobbies and Interests", '\n',
1660 NULL, _("A Little About Me"), 0, NULL, NULL);
1661 }
1662
1663 if (!found)
1664 {
1665 found = gaim_markup_extract_info_field(stripped, stripped_len, s,
1666 " A Little About Me \n\n", 0, "Favorite Quote", '\n', NULL,
1667 _("A Little About Me"), 0, NULL, NULL);
1668 }
1669
1670 if (!found)
1671 {
1672 found = gaim_markup_extract_info_field(stripped, stripped_len, s,
1673 " A Little About Me \n\n", 0, "My Homepage \n\nTake a look",
1674 '\n',
1675 NULL, _("A Little About Me"), 0, NULL, NULL);
1676 }
1677
1678 if (!found)
1679 {
1680 gaim_markup_extract_info_field(stripped, stripped_len, s,
1681 " A Little About Me \n\n", 0, "last updated", '\n', NULL,
1682 _("A Little About Me"), 0, NULL, NULL);
1683 }
1684
1685 if (found)
1686 has_info = TRUE;
1687
1688 /* Check if they have Favorite Things */
1689 found = gaim_markup_extract_info_field(stripped, stripped_len, s,
1690 " Favorite Things \n\n", 0, "Hobbies and Interests", '\n', NULL,
1691 _("Favorite Things"), 0, NULL, NULL);
1692
1693 if (!found)
1694 {
1695 found = gaim_markup_extract_info_field(stripped, stripped_len, s,
1696 " Favorite Things \n\n", 0, "Favorite Quote", '\n', NULL,
1697 _("Favorite Things"), 0, NULL, NULL);
1698 }
1699
1700 if (!found)
1701 {
1702 found = gaim_markup_extract_info_field(stripped, stripped_len, s,
1703 " Favorite Things \n\n", 0, "My Homepage \n\nTake a look", '\n',
1704 NULL, _("Favorite Things"), 0, NULL, NULL);
1705 }
1706
1707 if (!found)
1708 {
1709 gaim_markup_extract_info_field(stripped, stripped_len, s,
1710 " Favorite Things \n\n", 0, "last updated", '\n', NULL,
1711 _("Favorite Things"), 0, NULL, NULL);
1712 }
1713
1714 if (found)
1715 has_info = TRUE;
1716
1717 /* Check if they have Hobbies and Interests */
1718 found = gaim_markup_extract_info_field(stripped, stripped_len, s,
1719 " Hobbies and Interests \n\n", 0, "Favorite Quote", '\n', NULL,
1720 _("Hobbies and Interests"), 0, NULL, NULL);
1721
1722 if (!found)
1723 {
1724 found = gaim_markup_extract_info_field(stripped, stripped_len, s,
1725 " Hobbies and Interests \n\n", 0, "My Homepage \n\nTake a look",
1726 '\n', NULL, _("Hobbies and Interests"), 0, NULL, NULL);
1727 }
1728
1729 if (!found)
1730 {
1731 gaim_markup_extract_info_field(stripped, stripped_len, s,
1732 " Hobbies and Interests \n\n", 0, "last updated", '\n', NULL,
1733 _("Hobbies and Interests"), 0, NULL, NULL);
1734 }
1735
1736 if (found)
1737 has_info = TRUE;
1738
1739 /* Check if they have Favorite Quote */
1740 found = gaim_markup_extract_info_field(stripped, stripped_len, s,
1741 "Favorite Quote \n\n", 0, "My Homepage \n\nTake a look", '\n', NULL,
1742 _("Favorite Quote"), 0, NULL, NULL);
1743
1744 if (!found)
1745 {
1746 gaim_markup_extract_info_field(stripped, stripped_len, s,
1747 "Favorite Quote \n\n", 0, "last updated", '\n', NULL,
1748 _("Favorite Quote"), 0, NULL, NULL);
1749 }
1750
1751 if (found)
1752 has_info = TRUE;
1753
1754 /* Extract the last updated date and put it in */
1755 found = gaim_markup_extract_info_field(stripped, stripped_len, s,
1756 " last updated:", 1, "\n", 0, NULL, _("Last Updated"), 0,
1757 NULL, msn_info_date_reformat);
1758
1759 if (found)
1760 has_info = TRUE;
1761 #endif
1762
1763 /* If we were able to fetch a homepage url earlier, stick it in there */
1764 if (user_url != NULL)
1765 {
1766 g_snprintf(buf, sizeof(buf),
1767 "<b>%s:</b><br><a href=\"%s\">%s</a><br>\n",
1768 _("Homepage"), user_url, user_url);
1769
1770 g_string_append(s, buf);
1771
1772 g_free(user_url);
1773
1774 has_info = TRUE;
1775 }
1776
1777 if (!has_info)
1778 {
1779 /* MSN doesn't actually distinguish between "unknown member" and
1780 * a known member with an empty profile. Try to explain this fact.
1781 * Note that if we have a nonempty tooltip_text, we know the user
1782 * exists.
1783 */
1784 /* This doesn't work with the new spaces profiles - Stu 3/2/06
1785 char *p = strstr(url_buffer, "Unknown Member </TITLE>");
1786 * This might not work for long either ... */
1787 char *p = strstr(url_buffer, "form id=\"SpacesSearch\" name=\"SpacesSearch\"");
1788 GaimBuddy *b = gaim_find_buddy
1789 (gaim_connection_get_account(info_data->gc), info_data->name);
1790 g_string_append_printf(s, "<br><b>%s</b><br>%s<br><br>",
1791 _("Error retrieving profile"),
1792 ((p && b)?
1793 _("The user has not created a public profile."):
1794 p? _("MSN reported not being able to find the user's profile. "
1795 "This either means that the user does not exist, "
1796 "or that the user exists "
1797 "but has not created a public profile."):
1798 _("Gaim could not find " /* This should never happen */
1799 "any information in the user's profile. "
1800 "The user most likely does not exist.")));
1801 }
1802 /* put a link to the actual profile URL */
1803 g_string_append_printf(s, _("<hr><b>%s:</b> "), _("Profile URL"));
1804 g_string_append_printf(s, "<br><a href=\"%s%s\">%s%s</a><br>",
1805 PROFILE_URL, info_data->name, PROFILE_URL, info_data->name);
1806
1807 /* Finish it off, and show it to them */
1808 g_string_append(s, "</body></html>\n");
1809
1810 #if PHOTO_SUPPORT
1811 /* Find the URL to the photo; must be before the marshalling [Bug 994207] */
1812 photo_url_text = msn_get_photo_url(url_text);
1813
1814 /* Marshall the existing state */
1815 info2_data = g_malloc0(sizeof(MsnGetInfoStepTwoData));
1816 info2_data->info_data = info_data;
1817 info2_data->stripped = stripped;
1818 info2_data->url_buffer = url_buffer;
1819 info2_data->s = s;
1820 info2_data->photo_url_text = photo_url_text;
1821 info2_data->tooltip_text = tooltip_text;
1822 info2_data->title = title;
1823
1824 /* Try to put the photo in there too, if there's one */
1825 if (photo_url_text)
1826 {
1827 gaim_url_fetch(photo_url_text, FALSE, NULL, FALSE, msn_got_photo,
1828 info2_data);
1829 }
1830 else
1831 {
1832 /* Emulate a callback */
1833 msn_got_photo(info2_data, NULL, 0);
1834 }
1835 }
1836
1837 static void
1838 msn_got_photo(void *data, const char *url_text, size_t len)
1839 {
1840 MsnGetInfoStepTwoData *info2_data = (MsnGetInfoStepTwoData *)data;
1841 int id = -1;
1842
1843 /* Unmarshall the saved state */
1844 MsnGetInfoData *info_data = info2_data->info_data;
1845 char *stripped = info2_data->stripped;
1846 char *url_buffer = info2_data->url_buffer;
1847 GString *s = info2_data->s;
1848 char *photo_url_text = info2_data->photo_url_text;
1849 char *tooltip_text = info2_data->tooltip_text;
1850
1851 /* Make sure the connection is still valid if we got here by fetching a photo url */
1852 if (url_text &&
1853 g_list_find(gaim_connections_get_all(), info_data->gc) == NULL)
1854 {
1855 gaim_debug_warning("msn", "invalid connection. ignoring buddy photo info.\n");
1856 g_free(stripped);
1857 g_free(url_buffer);
1858 g_string_free(s, TRUE);
1859 g_free(tooltip_text);
1860 g_free(info_data->name);
1861 g_free(info_data);
1862 g_free(photo_url_text);
1863 g_free(info2_data);
1864
1865 return;
1866 }
1867
1868 /* Try to put the photo in there too, if there's one and is readable */
1869 if (data && url_text && len != 0)
1870 {
1871 if (strstr(url_text, "400 Bad Request")
1872 || strstr(url_text, "403 Forbidden")
1873 || strstr(url_text, "404 Not Found"))
1874 {
1875
1876 gaim_debug_info("msn", "Error getting %s: %s\n",
1877 photo_url_text, url_text);
1878 }
1879 else
1880 {
1881 char buf[1024];
1882 gaim_debug_info("msn", "%s is %d bytes\n", photo_url_text, len);
1883 id = gaim_imgstore_add(url_text, len, NULL);
1884 g_snprintf(buf, sizeof(buf), "<img id=\"%d\"><br>", id);
1885 g_string_prepend(s, buf);
1886 }
1887 }
1888
1889 /* We continue here from msn_got_info, as if nothing has happened */
1890 #endif
1891
1892 g_string_prepend(s, tooltip_text);
1893 gaim_notify_userinfo(info_data->gc, info_data->name, s->str, NULL, NULL);
1894
1895 g_free(stripped);
1896 g_free(url_buffer);
1897 g_string_free(s, TRUE);
1898 g_free(tooltip_text);
1899 g_free(info_data->name);
1900 g_free(info_data);
1901 #if PHOTO_SUPPORT
1902 g_free(photo_url_text);
1903 g_free(info2_data);
1904 if (id != -1)
1905 gaim_imgstore_unref(id);
1906 #endif
1907 }
1908
1909 static void
1910 msn_get_info(GaimConnection *gc, const char *name)
1911 {
1912 MsnGetInfoData *data;
1913 char *url;
1914
1915 data = g_new0(MsnGetInfoData, 1);
1916 data->gc = gc;
1917 data->name = g_strdup(name);
1918
1919 url = g_strdup_printf("%s%s", PROFILE_URL, name);
1920
1921 gaim_url_fetch(url, FALSE,
1922 "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)",
1923 TRUE, msn_got_info, data);
1924
1925 g_free(url);
1926 }
1927
1928 static gboolean msn_load(GaimPlugin *plugin)
1929 {
1930 msn_notification_init();
1931 msn_switchboard_init();
1932 msn_sync_init();
1933
1934 return TRUE;
1935 }
1936
1937 static gboolean msn_unload(GaimPlugin *plugin)
1938 {
1939 msn_notification_end();
1940 msn_switchboard_end();
1941 msn_sync_end();
1942
1943 return TRUE;
1944 }
1945
1946 static GaimPluginProtocolInfo prpl_info =
1947 {
1948 OPT_PROTO_MAIL_CHECK,
1949 NULL, /* user_splits */
1950 NULL, /* protocol_options */
1951 {"png", 0, 0, 96, 96, GAIM_ICON_SCALE_SEND}, /* icon_spec */
1952 msn_list_icon, /* list_icon */
1953 msn_list_emblems, /* list_emblems */
1954 msn_status_text, /* status_text */
1955 msn_tooltip_text, /* tooltip_text */
1956 msn_status_types, /* away_states */
1957 msn_blist_node_menu, /* blist_node_menu */
1958 NULL, /* chat_info */
1959 NULL, /* chat_info_defaults */
1960 msn_login, /* login */
1961 msn_close, /* close */
1962 msn_send_im, /* send_im */
1963 NULL, /* set_info */
1964 msn_send_typing, /* send_typing */
1965 msn_get_info, /* get_info */
1966 msn_set_status, /* set_away */
1967 msn_set_idle, /* set_idle */
1968 NULL, /* change_passwd */
1969 msn_add_buddy, /* add_buddy */
1970 NULL, /* add_buddies */
1971 msn_rem_buddy, /* remove_buddy */
1972 NULL, /* remove_buddies */
1973 msn_add_permit, /* add_permit */
1974 msn_add_deny, /* add_deny */
1975 msn_rem_permit, /* rem_permit */
1976 msn_rem_deny, /* rem_deny */
1977 msn_set_permit_deny, /* set_permit_deny */
1978 NULL, /* join_chat */
1979 NULL, /* reject chat invite */
1980 NULL, /* get_chat_name */
1981 msn_chat_invite, /* chat_invite */
1982 msn_chat_leave, /* chat_leave */
1983 NULL, /* chat_whisper */
1984 msn_chat_send, /* chat_send */
1985 msn_keepalive, /* keepalive */
1986 NULL, /* register_user */
1987 NULL, /* get_cb_info */
1988 NULL, /* get_cb_away */
1989 NULL, /* alias_buddy */
1990 msn_group_buddy, /* group_buddy */
1991 msn_rename_group, /* rename_group */
1992 NULL, /* buddy_free */
1993 msn_convo_closed, /* convo_closed */
1994 msn_normalize, /* normalize */
1995 msn_set_buddy_icon, /* set_buddy_icon */
1996 msn_remove_group, /* remove_group */
1997 NULL, /* get_cb_real_name */
1998 NULL, /* set_chat_topic */
1999 NULL, /* find_blist_chat */
2000 NULL, /* roomlist_get_list */
2001 NULL, /* roomlist_cancel */
2002 NULL, /* roomlist_expand_category */
2003 msn_can_receive_file, /* can_receive_file */
2004 msn_send_file, /* send_file */
2005 msn_new_xfer, /* new_xfer */
2006 NULL, /* offline_message */
2007 NULL, /* whiteboard_prpl_ops */
2008 };
2009
2010 static GaimPluginInfo info =
2011 {
2012 GAIM_PLUGIN_MAGIC,
2013 GAIM_MAJOR_VERSION,
2014 GAIM_MINOR_VERSION,
2015 GAIM_PLUGIN_PROTOCOL, /**< type */
2016 NULL, /**< ui_requirement */
2017 0, /**< flags */
2018 NULL, /**< dependencies */
2019 GAIM_PRIORITY_DEFAULT, /**< priority */
2020
2021 "prpl-msn", /**< id */
2022 "MSN", /**< name */
2023 VERSION, /**< version */
2024 /** summary */
2025 N_("MSN Protocol Plugin"),
2026 /** description */
2027 N_("MSN Protocol Plugin"),
2028 "Christian Hammond <chipx86@gnupdate.org>", /**< author */
2029 GAIM_WEBSITE, /**< homepage */
2030
2031 msn_load, /**< load */
2032 msn_unload, /**< unload */
2033 NULL, /**< destroy */
2034
2035 NULL, /**< ui_info */
2036 &prpl_info, /**< extra_info */
2037 NULL, /**< prefs_info */
2038 msn_actions
2039 };
2040
2041 static void
2042 init_plugin(GaimPlugin *plugin)
2043 {
2044 GaimAccountOption *option;
2045
2046 option = gaim_account_option_string_new(_("Server"), "server",
2047 MSN_SERVER);
2048 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options,
2049 option);
2050
2051 option = gaim_account_option_int_new(_("Port"), "port", 1863);
2052 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options,
2053 option);
2054
2055 option = gaim_account_option_bool_new(_("Use HTTP Method"),
2056 "http_method", FALSE);
2057 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options,
2058 option);
2059
2060 option = gaim_account_option_bool_new(_("Show custom smileys"),
2061 "custom_smileys", TRUE);
2062 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options,
2063 option);
2064
2065 gaim_cmd_register("nudge", "", GAIM_CMD_P_PRPL,
2066 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_PRPL_ONLY,
2067 "prpl-msn", msn_cmd_nudge,
2068 _("nudge: nudge a user to get their attention"), NULL);
2069
2070 gaim_prefs_remove("/plugins/prpl/msn");
2071 }
2072
2073 GAIM_INIT_PLUGIN(msn, init_plugin, info);