comparison libpurple/protocols/msn/msn.c @ 15374:5fe8042783c1

Rename gtk/ and libgaim/ to pidgin/ and libpurple/
author Sean Egan <seanegan@gmail.com>
date Sat, 20 Jan 2007 02:32:10 +0000
parents
children 21bc8d84974f
comparison
equal deleted inserted replaced
15373:f79e0f4df793 15374:5fe8042783c1
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 GaimNotifyUserInfo *user_info;
71 char *photo_url_text;
72
73 } MsnGetInfoStepTwoData;
74
75 static const char *
76 msn_normalize(const GaimAccount *account, const char *str)
77 {
78 static char buf[BUF_LEN];
79 char *tmp;
80
81 g_return_val_if_fail(str != NULL, NULL);
82
83 g_snprintf(buf, sizeof(buf), "%s%s", str,
84 (strchr(str, '@') ? "" : "@hotmail.com"));
85
86 tmp = g_utf8_strdown(buf, -1);
87 strncpy(buf, tmp, sizeof(buf));
88 g_free(tmp);
89
90 return buf;
91 }
92
93 static GaimCmdRet
94 msn_cmd_nudge(GaimConversation *conv, const gchar *cmd, gchar **args, gchar **error, void *data)
95 {
96 GaimAccount *account = gaim_conversation_get_account(conv);
97 GaimConnection *gc = gaim_account_get_connection(account);
98 MsnMessage *msg;
99 MsnSession *session;
100 MsnSwitchBoard *swboard;
101
102 msg = msn_message_new_nudge();
103 session = gc->proto_data;
104 swboard = msn_session_get_swboard(session, gaim_conversation_get_name(conv), MSN_SB_FLAG_IM);
105
106 if (swboard == NULL)
107 return GAIM_CMD_RET_FAILED;
108
109 msn_switchboard_send_msg(swboard, msg, TRUE);
110
111 gaim_conversation_write(conv, NULL, _("You have just sent a Nudge!"), GAIM_MESSAGE_SYSTEM, time(NULL));
112
113 return GAIM_CMD_RET_OK;
114 }
115
116 static void
117 msn_act_id(GaimConnection *gc, const char *entry)
118 {
119 MsnCmdProc *cmdproc;
120 MsnSession *session;
121 GaimAccount *account;
122 const char *alias;
123
124 session = gc->proto_data;
125 cmdproc = session->notification->cmdproc;
126 account = gaim_connection_get_account(gc);
127
128 if(entry && strlen(entry))
129 alias = gaim_url_encode(entry);
130 else
131 alias = "";
132
133 if (strlen(alias) > BUDDY_ALIAS_MAXLEN)
134 {
135 gaim_notify_error(gc, NULL,
136 _("Your new MSN friendly name is too long."), NULL);
137 return;
138 }
139
140 msn_cmdproc_send(cmdproc, "REA", "%s %s",
141 gaim_account_get_username(account),
142 alias);
143 }
144
145 static void
146 msn_set_prp(GaimConnection *gc, const char *type, const char *entry)
147 {
148 MsnCmdProc *cmdproc;
149 MsnSession *session;
150
151 session = gc->proto_data;
152 cmdproc = session->notification->cmdproc;
153
154 if (entry == NULL || *entry == '\0')
155 {
156 msn_cmdproc_send(cmdproc, "PRP", "%s", type);
157 }
158 else
159 {
160 msn_cmdproc_send(cmdproc, "PRP", "%s %s", type,
161 gaim_url_encode(entry));
162 }
163 }
164
165 static void
166 msn_set_home_phone_cb(GaimConnection *gc, const char *entry)
167 {
168 msn_set_prp(gc, "PHH", entry);
169 }
170
171 static void
172 msn_set_work_phone_cb(GaimConnection *gc, const char *entry)
173 {
174 msn_set_prp(gc, "PHW", entry);
175 }
176
177 static void
178 msn_set_mobile_phone_cb(GaimConnection *gc, const char *entry)
179 {
180 msn_set_prp(gc, "PHM", entry);
181 }
182
183 static void
184 enable_msn_pages_cb(GaimConnection *gc)
185 {
186 msn_set_prp(gc, "MOB", "Y");
187 }
188
189 static void
190 disable_msn_pages_cb(GaimConnection *gc)
191 {
192 msn_set_prp(gc, "MOB", "N");
193 }
194
195 static void
196 send_to_mobile(GaimConnection *gc, const char *who, const char *entry)
197 {
198 MsnTransaction *trans;
199 MsnSession *session;
200 MsnCmdProc *cmdproc;
201 MsnPage *page;
202 char *payload;
203 size_t payload_len;
204
205 session = gc->proto_data;
206 cmdproc = session->notification->cmdproc;
207
208 page = msn_page_new();
209 msn_page_set_body(page, entry);
210
211 payload = msn_page_gen_payload(page, &payload_len);
212
213 trans = msn_transaction_new(cmdproc, "PGD", "%s 1 %d", who, payload_len);
214
215 msn_transaction_set_payload(trans, payload, payload_len);
216
217 msn_page_destroy(page);
218
219 msn_cmdproc_send_trans(cmdproc, trans);
220 }
221
222 static void
223 send_to_mobile_cb(MsnMobileData *data, const char *entry)
224 {
225 send_to_mobile(data->gc, data->passport, entry);
226 g_free(data);
227 }
228
229 static void
230 close_mobile_page_cb(MsnMobileData *data, const char *entry)
231 {
232 g_free(data);
233 }
234
235 /* -- */
236
237 static void
238 msn_show_set_friendly_name(GaimPluginAction *action)
239 {
240 GaimConnection *gc;
241
242 gc = (GaimConnection *) action->context;
243
244 gaim_request_input(gc, NULL, _("Set your friendly name."),
245 _("This is the name that other MSN buddies will "
246 "see you as."),
247 gaim_connection_get_display_name(gc), FALSE, FALSE, NULL,
248 _("OK"), G_CALLBACK(msn_act_id),
249 _("Cancel"), NULL, gc);
250 }
251
252 static void
253 msn_show_set_home_phone(GaimPluginAction *action)
254 {
255 GaimConnection *gc;
256 MsnSession *session;
257
258 gc = (GaimConnection *) action->context;
259 session = gc->proto_data;
260
261 gaim_request_input(gc, NULL, _("Set your home phone number."), NULL,
262 msn_user_get_home_phone(session->user), FALSE, FALSE, NULL,
263 _("OK"), G_CALLBACK(msn_set_home_phone_cb),
264 _("Cancel"), NULL, gc);
265 }
266
267 static void
268 msn_show_set_work_phone(GaimPluginAction *action)
269 {
270 GaimConnection *gc;
271 MsnSession *session;
272
273 gc = (GaimConnection *) action->context;
274 session = gc->proto_data;
275
276 gaim_request_input(gc, NULL, _("Set your work phone number."), NULL,
277 msn_user_get_work_phone(session->user), FALSE, FALSE, NULL,
278 _("OK"), G_CALLBACK(msn_set_work_phone_cb),
279 _("Cancel"), NULL, gc);
280 }
281
282 static void
283 msn_show_set_mobile_phone(GaimPluginAction *action)
284 {
285 GaimConnection *gc;
286 MsnSession *session;
287
288 gc = (GaimConnection *) action->context;
289 session = gc->proto_data;
290
291 gaim_request_input(gc, NULL, _("Set your mobile phone number."), NULL,
292 msn_user_get_mobile_phone(session->user), FALSE, FALSE, NULL,
293 _("OK"), G_CALLBACK(msn_set_mobile_phone_cb),
294 _("Cancel"), NULL, gc);
295 }
296
297 static void
298 msn_show_set_mobile_pages(GaimPluginAction *action)
299 {
300 GaimConnection *gc;
301
302 gc = (GaimConnection *) action->context;
303
304 gaim_request_action(gc, NULL, _("Allow MSN Mobile pages?"),
305 _("Do you want to allow or disallow people on "
306 "your buddy list to send you MSN Mobile pages "
307 "to your cell phone or other mobile device?"),
308 -1, gc, 3,
309 _("Allow"), G_CALLBACK(enable_msn_pages_cb),
310 _("Disallow"), G_CALLBACK(disable_msn_pages_cb),
311 _("Cancel"), NULL);
312 }
313
314 static void
315 msn_show_hotmail_inbox(GaimPluginAction *action)
316 {
317 GaimConnection *gc;
318 MsnSession *session;
319
320 gc = (GaimConnection *) action->context;
321 session = gc->proto_data;
322
323 if (session->passport_info.file == NULL)
324 {
325 gaim_notify_error(gc, NULL,
326 _("This Hotmail account may not be active."), NULL);
327 return;
328 }
329
330 gaim_notify_uri(gc, session->passport_info.file);
331 }
332
333 static void
334 show_send_to_mobile_cb(GaimBlistNode *node, gpointer ignored)
335 {
336 GaimBuddy *buddy;
337 GaimConnection *gc;
338 MsnSession *session;
339 MsnMobileData *data;
340
341 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node));
342
343 buddy = (GaimBuddy *) node;
344 gc = gaim_account_get_connection(buddy->account);
345
346 session = gc->proto_data;
347
348 data = g_new0(MsnMobileData, 1);
349 data->gc = gc;
350 data->passport = buddy->name;
351
352 gaim_request_input(gc, NULL, _("Send a mobile message."), NULL,
353 NULL, TRUE, FALSE, NULL,
354 _("Page"), G_CALLBACK(send_to_mobile_cb),
355 _("Close"), G_CALLBACK(close_mobile_page_cb),
356 data);
357 }
358
359 static void
360 initiate_chat_cb(GaimBlistNode *node, gpointer data)
361 {
362 GaimBuddy *buddy;
363 GaimConnection *gc;
364
365 MsnSession *session;
366 MsnSwitchBoard *swboard;
367
368 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node));
369
370 buddy = (GaimBuddy *) node;
371 gc = gaim_account_get_connection(buddy->account);
372
373 session = gc->proto_data;
374
375 swboard = msn_switchboard_new(session);
376 msn_switchboard_request(swboard);
377 msn_switchboard_request_add_user(swboard, buddy->name);
378
379 /* TODO: This might move somewhere else, after USR might be */
380 swboard->chat_id = session->conv_seq++;
381 swboard->conv = serv_got_joined_chat(gc, swboard->chat_id, "MSN Chat");
382 swboard->flag = MSN_SB_FLAG_IM;
383
384 gaim_conv_chat_add_user(GAIM_CONV_CHAT(swboard->conv),
385 gaim_account_get_username(buddy->account), NULL, GAIM_CBFLAGS_NONE, TRUE);
386 }
387
388 static void
389 t_msn_xfer_init(GaimXfer *xfer)
390 {
391 MsnSlpLink *slplink;
392 const char *filename;
393 FILE *fp;
394
395 filename = gaim_xfer_get_local_filename(xfer);
396
397 slplink = xfer->data;
398
399 if ((fp = g_fopen(filename, "rb")) == NULL)
400 {
401 GaimAccount *account;
402 const char *who;
403 char *msg;
404
405 account = slplink->session->account;
406 who = slplink->remote_user;
407
408 msg = g_strdup_printf(_("Error reading %s: \n%s.\n"),
409 filename, strerror(errno));
410 gaim_xfer_error(gaim_xfer_get_type(xfer), account, xfer->who, msg);
411 gaim_xfer_cancel_local(xfer);
412 g_free(msg);
413
414 return;
415 }
416 fclose(fp);
417
418 msn_slplink_request_ft(slplink, xfer);
419 }
420
421 static GaimXfer*
422 msn_new_xfer(GaimConnection *gc, const char *who)
423 {
424 MsnSession *session;
425 MsnSlpLink *slplink;
426 GaimXfer *xfer;
427
428 session = gc->proto_data;
429
430 xfer = gaim_xfer_new(gc->account, GAIM_XFER_SEND, who);
431 if (xfer)
432 {
433 slplink = msn_session_get_slplink(session, who);
434
435 xfer->data = slplink;
436
437 gaim_xfer_set_init_fnc(xfer, t_msn_xfer_init);
438 }
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, GaimNotifyUserInfo *user_info, 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
545 if (gaim_presence_is_online(presence))
546 {
547 gaim_notify_user_info_add_pair(user_info, _("Status"),
548 (gaim_presence_is_idle(presence) ? _("Idle") : gaim_status_get_name(status)));
549 }
550
551 if (full && user)
552 {
553 gaim_notify_user_info_add_pair(user_info, _("Has you"),
554 ((user->list_op & (1 << MSN_LIST_RL)) ? _("Yes") : _("No")));
555 }
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 {
563 gaim_notify_user_info_add_pair(user_info, _("Blocked"),
564 ((user->list_op & (1 << MSN_LIST_BL)) ? _("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 /**
1345 * Extract info text from info_data and add it to user_info
1346 */
1347 static gboolean
1348 msn_tooltip_extract_info_text(GaimNotifyUserInfo *user_info, MsnGetInfoData *info_data)
1349 {
1350 GaimBuddy *b;
1351
1352 b = gaim_find_buddy(gaim_connection_get_account(info_data->gc),
1353 info_data->name);
1354
1355 if (b)
1356 {
1357 char *tmp;
1358
1359 if (b->alias && b->alias[0])
1360 {
1361 char *aliastext = g_markup_escape_text(b->alias, -1);
1362 gaim_notify_user_info_add_pair(user_info, _("Alias"), aliastext);
1363 g_free(aliastext);
1364 }
1365
1366 if (b->server_alias)
1367 {
1368 char *nicktext = g_markup_escape_text(b->server_alias, -1);
1369 tmp = g_strdup_printf("<font sml=\"msn\">%s</font><br>", nicktext);
1370 gaim_notify_user_info_add_pair(user_info, _("Nickname"), tmp);
1371 g_free(tmp);
1372 g_free(nicktext);
1373 }
1374
1375 /* Add the tooltip information */
1376 msn_tooltip_text(b, user_info, TRUE);
1377
1378 return TRUE;
1379 }
1380
1381 return FALSE;
1382 }
1383
1384 #if PHOTO_SUPPORT
1385
1386 static char *
1387 msn_get_photo_url(const char *url_text)
1388 {
1389 char *p, *q;
1390
1391 if ((p = strstr(url_text, " contactparams:photopreauthurl=\"")) != NULL)
1392 {
1393 p += strlen(" contactparams:photopreauthurl=\"");
1394 }
1395
1396 if (p && (strncmp(p, "http://", 8) == 0) && ((q = strchr(p, '"')) != NULL))
1397 return g_strndup(p, q - p);
1398
1399 return NULL;
1400 }
1401
1402 static void msn_got_photo(GaimUtilFetchUrlData *url_data, gpointer data,
1403 const gchar *url_text, size_t len, const gchar *error_message);
1404
1405 #endif
1406
1407 #if 0
1408 static char *msn_info_date_reformat(const char *field, size_t len)
1409 {
1410 char *tmp = g_strndup(field, len);
1411 time_t t = gaim_str_to_time(tmp, FALSE, NULL, NULL, NULL);
1412
1413 g_free(tmp);
1414 return g_strdup(gaim_date_format_short(localtime(&t)));
1415 }
1416 #endif
1417
1418 #define MSN_GOT_INFO_GET_FIELD(a, b) \
1419 found = gaim_markup_extract_info_field(stripped, stripped_len, user_info, \
1420 "\n" a ":", 0, "\n", 0, "Undisclosed", b, 0, NULL, NULL); \
1421 if (found) \
1422 sect_info = TRUE;
1423
1424 static void
1425 msn_got_info(GaimUtilFetchUrlData *url_data, gpointer data,
1426 const gchar *url_text, size_t len, const gchar *error_message)
1427 {
1428 MsnGetInfoData *info_data = (MsnGetInfoData *)data;
1429 GaimNotifyUserInfo *user_info;
1430 char *stripped, *p, *q, *tmp;
1431 char *user_url = NULL;
1432 gboolean found;
1433 gboolean has_tooltip_text = FALSE;
1434 gboolean has_info = FALSE;
1435 gboolean sect_info = FALSE;
1436 gboolean has_contact_info = FALSE;
1437 char *url_buffer;
1438 GString *s, *s2;
1439 int stripped_len;
1440 #if PHOTO_SUPPORT
1441 char *photo_url_text = NULL;
1442 MsnGetInfoStepTwoData *info2_data = NULL;
1443 #endif
1444
1445 gaim_debug_info("msn", "In msn_got_info\n");
1446
1447 /* Make sure the connection is still valid */
1448 if (g_list_find(gaim_connections_get_all(), info_data->gc) == NULL)
1449 {
1450 gaim_debug_warning("msn", "invalid connection. ignoring buddy info.\n");
1451 g_free(info_data->name);
1452 g_free(info_data);
1453 return;
1454 }
1455
1456 user_info = gaim_notify_user_info_new();
1457 has_tooltip_text = msn_tooltip_extract_info_text(user_info, info_data);
1458
1459 if (error_message != NULL || url_text == NULL || strcmp(url_text, "") == 0)
1460 {
1461 tmp = g_strdup_printf("<b>%s</b>", _("Error retrieving profile"));
1462 gaim_notify_user_info_add_pair(user_info, NULL, tmp);
1463 g_free(tmp);
1464
1465 gaim_notify_userinfo(info_data->gc, info_data->name, user_info, NULL, NULL);
1466 gaim_notify_user_info_destroy(user_info);
1467
1468 g_free(info_data->name);
1469 g_free(info_data);
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 /* General section header */
1529 if (has_tooltip_text)
1530 gaim_notify_user_info_add_section_break(user_info);
1531
1532 gaim_notify_user_info_add_section_header(user_info, _("General"));
1533
1534 /* Extract their Name and put it in */
1535 MSN_GOT_INFO_GET_FIELD("Name", _("Name"));
1536
1537 /* General */
1538 MSN_GOT_INFO_GET_FIELD("Nickname", _("Nickname"));
1539 MSN_GOT_INFO_GET_FIELD("Age", _("Age"));
1540 MSN_GOT_INFO_GET_FIELD("Gender", _("Gender"));
1541 MSN_GOT_INFO_GET_FIELD("Occupation", _("Occupation"));
1542 MSN_GOT_INFO_GET_FIELD("Location", _("Location"));
1543
1544 /* Extract their Interests and put it in */
1545 found = gaim_markup_extract_info_field(stripped, stripped_len, user_info,
1546 "\nInterests\t", 0, " (/default.aspx?page=searchresults", 0,
1547 "Undisclosed", _("Hobbies and Interests") /* _("Interests") */,
1548 0, NULL, NULL);
1549
1550 if (found)
1551 sect_info = TRUE;
1552
1553 MSN_GOT_INFO_GET_FIELD("More about me", _("A Little About Me"));
1554
1555 if (sect_info)
1556 {
1557 has_info = TRUE;
1558 sect_info = FALSE;
1559 }
1560 else
1561 {
1562 /* Remove the section header */
1563 gaim_notify_user_info_remove_last_item(user_info);
1564 if (has_tooltip_text)
1565 gaim_notify_user_info_remove_last_item(user_info);
1566 }
1567
1568 /* Social */
1569 gaim_notify_user_info_add_section_break(user_info);
1570 gaim_notify_user_info_add_section_header(user_info, _("Social"));
1571
1572 MSN_GOT_INFO_GET_FIELD("Marital status", _("Marital Status"));
1573 MSN_GOT_INFO_GET_FIELD("Interested in", _("Interests"));
1574 MSN_GOT_INFO_GET_FIELD("Pets", _("Pets"));
1575 MSN_GOT_INFO_GET_FIELD("Hometown", _("Hometown"));
1576 MSN_GOT_INFO_GET_FIELD("Places lived", _("Places Lived"));
1577 MSN_GOT_INFO_GET_FIELD("Fashion", _("Fashion"));
1578 MSN_GOT_INFO_GET_FIELD("Humor", _("Humor"));
1579 MSN_GOT_INFO_GET_FIELD("Music", _("Music"));
1580 MSN_GOT_INFO_GET_FIELD("Favorite quote", _("Favorite Quote"));
1581
1582 if (sect_info)
1583 {
1584 has_info = TRUE;
1585 sect_info = FALSE;
1586 }
1587 else
1588 {
1589 /* Remove the section header */
1590 gaim_notify_user_info_remove_last_item(user_info);
1591 gaim_notify_user_info_remove_last_item(user_info);
1592 }
1593
1594 /* Contact Info */
1595 /* Personal */
1596 gaim_notify_user_info_add_section_break(user_info);
1597 gaim_notify_user_info_add_section_header(user_info, _("Contact Info"));
1598 gaim_notify_user_info_add_section_header(user_info, _("Personal"));
1599
1600 MSN_GOT_INFO_GET_FIELD("Name", _("Name"));
1601 MSN_GOT_INFO_GET_FIELD("Significant other", _("Significant Other"));
1602 MSN_GOT_INFO_GET_FIELD("Home phone", _("Home Phone"));
1603 MSN_GOT_INFO_GET_FIELD("Home phone 2", _("Home Phone 2"));
1604 MSN_GOT_INFO_GET_FIELD("Home address", _("Home Address"));
1605 MSN_GOT_INFO_GET_FIELD("Personal Mobile", _("Personal Mobile"));
1606 MSN_GOT_INFO_GET_FIELD("Home fax", _("Home Fax"));
1607 MSN_GOT_INFO_GET_FIELD("Personal e-mail", _("Personal E-Mail"));
1608 MSN_GOT_INFO_GET_FIELD("Personal IM", _("Personal IM"));
1609 MSN_GOT_INFO_GET_FIELD("Birthday", _("Birthday"));
1610 MSN_GOT_INFO_GET_FIELD("Anniversary", _("Anniversary"));
1611 MSN_GOT_INFO_GET_FIELD("Notes", _("Notes"));
1612
1613 if (sect_info)
1614 {
1615 has_info = TRUE;
1616 sect_info = FALSE;
1617 has_contact_info = TRUE;
1618 }
1619 else
1620 {
1621 /* Remove the section header */
1622 gaim_notify_user_info_remove_last_item(user_info);
1623 }
1624
1625 /* Business */
1626 gaim_notify_user_info_add_section_header(user_info, _("Work"));
1627 MSN_GOT_INFO_GET_FIELD("Name", _("Name"));
1628 MSN_GOT_INFO_GET_FIELD("Job title", _("Job Title"));
1629 MSN_GOT_INFO_GET_FIELD("Company", _("Company"));
1630 MSN_GOT_INFO_GET_FIELD("Department", _("Department"));
1631 MSN_GOT_INFO_GET_FIELD("Profession", _("Profession"));
1632 MSN_GOT_INFO_GET_FIELD("Work phone 1", _("Work Phone"));
1633 MSN_GOT_INFO_GET_FIELD("Work phone 2", _("Work Phone 2"));
1634 MSN_GOT_INFO_GET_FIELD("Work address", _("Work Address"));
1635 MSN_GOT_INFO_GET_FIELD("Work mobile", _("Work Mobile"));
1636 MSN_GOT_INFO_GET_FIELD("Work pager", _("Work Pager"));
1637 MSN_GOT_INFO_GET_FIELD("Work fax", _("Work Fax"));
1638 MSN_GOT_INFO_GET_FIELD("Work e-mail", _("Work E-Mail"));
1639 MSN_GOT_INFO_GET_FIELD("Work IM", _("Work IM"));
1640 MSN_GOT_INFO_GET_FIELD("Start date", _("Start Date"));
1641 MSN_GOT_INFO_GET_FIELD("Notes", _("Notes"));
1642
1643 if (sect_info)
1644 {
1645 has_info = TRUE;
1646 sect_info = FALSE;
1647 has_contact_info = TRUE;
1648 }
1649 else
1650 {
1651 /* Remove the section header */
1652 gaim_notify_user_info_remove_last_item(user_info);
1653 }
1654
1655 if (!has_contact_info)
1656 {
1657 /* Remove the Contact Info section header */
1658 gaim_notify_user_info_remove_last_item(user_info);
1659 }
1660
1661 #if 0 /* these probably don't show up any more */
1662 /*
1663 * The fields, 'A Little About Me', 'Favorite Things', 'Hobbies
1664 * and Interests', 'Favorite Quote', and 'My Homepage' may or may
1665 * not appear, in any combination. However, they do appear in
1666 * certain order, so we can successively search to pin down the
1667 * distinct values.
1668 */
1669
1670 /* Check if they have A Little About Me */
1671 found = gaim_markup_extract_info_field(stripped, stripped_len, s,
1672 " A Little About Me \n\n", 0, "Favorite Things", '\n', NULL,
1673 _("A Little About Me"), 0, NULL, NULL);
1674
1675 if (!found)
1676 {
1677 found = gaim_markup_extract_info_field(stripped, stripped_len, s,
1678 " A Little About Me \n\n", 0, "Hobbies and Interests", '\n',
1679 NULL, _("A Little About Me"), 0, NULL, NULL);
1680 }
1681
1682 if (!found)
1683 {
1684 found = gaim_markup_extract_info_field(stripped, stripped_len, s,
1685 " A Little About Me \n\n", 0, "Favorite Quote", '\n', NULL,
1686 _("A Little About Me"), 0, NULL, NULL);
1687 }
1688
1689 if (!found)
1690 {
1691 found = gaim_markup_extract_info_field(stripped, stripped_len, s,
1692 " A Little About Me \n\n", 0, "My Homepage \n\nTake a look",
1693 '\n',
1694 NULL, _("A Little About Me"), 0, NULL, NULL);
1695 }
1696
1697 if (!found)
1698 {
1699 gaim_markup_extract_info_field(stripped, stripped_len, s,
1700 " A Little About Me \n\n", 0, "last updated", '\n', NULL,
1701 _("A Little About Me"), 0, NULL, NULL);
1702 }
1703
1704 if (found)
1705 has_info = TRUE;
1706
1707 /* Check if they have Favorite Things */
1708 found = gaim_markup_extract_info_field(stripped, stripped_len, s,
1709 " Favorite Things \n\n", 0, "Hobbies and Interests", '\n', NULL,
1710 _("Favorite Things"), 0, NULL, NULL);
1711
1712 if (!found)
1713 {
1714 found = gaim_markup_extract_info_field(stripped, stripped_len, s,
1715 " Favorite Things \n\n", 0, "Favorite Quote", '\n', NULL,
1716 _("Favorite Things"), 0, NULL, NULL);
1717 }
1718
1719 if (!found)
1720 {
1721 found = gaim_markup_extract_info_field(stripped, stripped_len, s,
1722 " Favorite Things \n\n", 0, "My Homepage \n\nTake a look", '\n',
1723 NULL, _("Favorite Things"), 0, NULL, NULL);
1724 }
1725
1726 if (!found)
1727 {
1728 gaim_markup_extract_info_field(stripped, stripped_len, s,
1729 " Favorite Things \n\n", 0, "last updated", '\n', NULL,
1730 _("Favorite Things"), 0, NULL, NULL);
1731 }
1732
1733 if (found)
1734 has_info = TRUE;
1735
1736 /* Check if they have Hobbies and Interests */
1737 found = gaim_markup_extract_info_field(stripped, stripped_len, s,
1738 " Hobbies and Interests \n\n", 0, "Favorite Quote", '\n', NULL,
1739 _("Hobbies and Interests"), 0, NULL, NULL);
1740
1741 if (!found)
1742 {
1743 found = gaim_markup_extract_info_field(stripped, stripped_len, s,
1744 " Hobbies and Interests \n\n", 0, "My Homepage \n\nTake a look",
1745 '\n', NULL, _("Hobbies and Interests"), 0, NULL, NULL);
1746 }
1747
1748 if (!found)
1749 {
1750 gaim_markup_extract_info_field(stripped, stripped_len, s,
1751 " Hobbies and Interests \n\n", 0, "last updated", '\n', NULL,
1752 _("Hobbies and Interests"), 0, NULL, NULL);
1753 }
1754
1755 if (found)
1756 has_info = TRUE;
1757
1758 /* Check if they have Favorite Quote */
1759 found = gaim_markup_extract_info_field(stripped, stripped_len, s,
1760 "Favorite Quote \n\n", 0, "My Homepage \n\nTake a look", '\n', NULL,
1761 _("Favorite Quote"), 0, NULL, NULL);
1762
1763 if (!found)
1764 {
1765 gaim_markup_extract_info_field(stripped, stripped_len, s,
1766 "Favorite Quote \n\n", 0, "last updated", '\n', NULL,
1767 _("Favorite Quote"), 0, NULL, NULL);
1768 }
1769
1770 if (found)
1771 has_info = TRUE;
1772
1773 /* Extract the last updated date and put it in */
1774 found = gaim_markup_extract_info_field(stripped, stripped_len, s,
1775 " last updated:", 1, "\n", 0, NULL, _("Last Updated"), 0,
1776 NULL, msn_info_date_reformat);
1777
1778 if (found)
1779 has_info = TRUE;
1780 #endif
1781
1782 /* If we were able to fetch a homepage url earlier, stick it in there */
1783 if (user_url != NULL)
1784 {
1785 tmp = g_strdup_printf("<a href=\"%s\">%s</a>", user_url, user_url);
1786 gaim_notify_user_info_add_pair(user_info, _("Homepage"), tmp);
1787 g_free(tmp);
1788 g_free(user_url);
1789
1790 has_info = TRUE;
1791 }
1792
1793 if (!has_info)
1794 {
1795 /* MSN doesn't actually distinguish between "unknown member" and
1796 * a known member with an empty profile. Try to explain this fact.
1797 * Note that if we have a nonempty tooltip_text, we know the user
1798 * exists.
1799 */
1800 /* This doesn't work with the new spaces profiles - Stu 3/2/06
1801 char *p = strstr(url_buffer, "Unknown Member </TITLE>");
1802 * This might not work for long either ... */
1803 char *p = strstr(url_buffer, "form id=\"SpacesSearch\" name=\"SpacesSearch\"");
1804 GaimBuddy *b = gaim_find_buddy
1805 (gaim_connection_get_account(info_data->gc), info_data->name);
1806 gaim_notify_user_info_add_pair(user_info, _("Error retrieving profile"),
1807 ((p && b) ? _("The user has not created a public profile.") :
1808 (p ? _("MSN reported not being able to find the user's profile. "
1809 "This either means that the user does not exist, "
1810 "or that the user exists "
1811 "but has not created a public profile.") :
1812 _("Gaim could not find " /* This should never happen */
1813 "any information in the user's profile. "
1814 "The user most likely does not exist."))));
1815 }
1816
1817 /* put a link to the actual profile URL */
1818 tmp = g_strdup_printf("<a href=\"%s%s\">%s%s</a>",
1819 PROFILE_URL, info_data->name, PROFILE_URL, info_data->name);
1820 gaim_notify_user_info_add_pair(user_info, _("Profile URL"), tmp);
1821 g_free(tmp);
1822
1823 #if PHOTO_SUPPORT
1824 /* Find the URL to the photo; must be before the marshalling [Bug 994207] */
1825 photo_url_text = msn_get_photo_url(url_text);
1826
1827 /* Marshall the existing state */
1828 info2_data = g_malloc0(sizeof(MsnGetInfoStepTwoData));
1829 info2_data->info_data = info_data;
1830 info2_data->stripped = stripped;
1831 info2_data->url_buffer = url_buffer;
1832 info2_data->user_info = user_info;
1833 info2_data->photo_url_text = photo_url_text;
1834
1835 /* Try to put the photo in there too, if there's one */
1836 if (photo_url_text)
1837 {
1838 gaim_util_fetch_url(photo_url_text, FALSE, NULL, FALSE, msn_got_photo,
1839 info2_data);
1840 }
1841 else
1842 {
1843 /* Emulate a callback */
1844 /* TODO: Huh? */
1845 msn_got_photo(NULL, info2_data, NULL, 0, NULL);
1846 }
1847 }
1848
1849 static void
1850 msn_got_photo(GaimUtilFetchUrlData *url_data, gpointer user_data,
1851 const gchar *url_text, size_t len, const gchar *error_message)
1852 {
1853 MsnGetInfoStepTwoData *info2_data = (MsnGetInfoStepTwoData *)user_data;
1854 int id = -1;
1855
1856 /* Unmarshall the saved state */
1857 MsnGetInfoData *info_data = info2_data->info_data;
1858 char *stripped = info2_data->stripped;
1859 char *url_buffer = info2_data->url_buffer;
1860 GaimNotifyUserInfo *user_info = info2_data->user_info;
1861 char *photo_url_text = info2_data->photo_url_text;
1862
1863 /* Make sure the connection is still valid if we got here by fetching a photo url */
1864 if (url_text && (error_message != NULL ||
1865 g_list_find(gaim_connections_get_all(), info_data->gc) == NULL))
1866 {
1867 gaim_debug_warning("msn", "invalid connection. ignoring buddy photo info.\n");
1868 g_free(stripped);
1869 g_free(url_buffer);
1870 g_free(user_info);
1871 g_free(info_data->name);
1872 g_free(info_data);
1873 g_free(photo_url_text);
1874 g_free(info2_data);
1875
1876 return;
1877 }
1878
1879 /* Try to put the photo in there too, if there's one and is readable */
1880 if (user_data && url_text && len != 0)
1881 {
1882 if (strstr(url_text, "400 Bad Request")
1883 || strstr(url_text, "403 Forbidden")
1884 || strstr(url_text, "404 Not Found"))
1885 {
1886
1887 gaim_debug_info("msn", "Error getting %s: %s\n",
1888 photo_url_text, url_text);
1889 }
1890 else
1891 {
1892 char buf[1024];
1893 gaim_debug_info("msn", "%s is %d bytes\n", photo_url_text, len);
1894 id = gaim_imgstore_add(url_text, len, NULL);
1895 g_snprintf(buf, sizeof(buf), "<img id=\"%d\"><br>", id);
1896 gaim_notify_user_info_prepend_pair(user_info, NULL, buf);
1897 }
1898 }
1899
1900 /* We continue here from msn_got_info, as if nothing has happened */
1901 #endif
1902 gaim_notify_userinfo(info_data->gc, info_data->name, user_info, NULL, NULL);
1903
1904 g_free(stripped);
1905 g_free(url_buffer);
1906 gaim_notify_user_info_destroy(user_info);
1907 g_free(info_data->name);
1908 g_free(info_data);
1909 #if PHOTO_SUPPORT
1910 g_free(photo_url_text);
1911 g_free(info2_data);
1912 if (id != -1)
1913 gaim_imgstore_unref(id);
1914 #endif
1915 }
1916
1917 static void
1918 msn_get_info(GaimConnection *gc, const char *name)
1919 {
1920 MsnGetInfoData *data;
1921 char *url;
1922
1923 data = g_new0(MsnGetInfoData, 1);
1924 data->gc = gc;
1925 data->name = g_strdup(name);
1926
1927 url = g_strdup_printf("%s%s", PROFILE_URL, name);
1928
1929 gaim_util_fetch_url(url, FALSE,
1930 "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)",
1931 TRUE, msn_got_info, data);
1932
1933 g_free(url);
1934 }
1935
1936 static gboolean msn_load(GaimPlugin *plugin)
1937 {
1938 msn_notification_init();
1939 msn_switchboard_init();
1940 msn_sync_init();
1941
1942 return TRUE;
1943 }
1944
1945 static gboolean msn_unload(GaimPlugin *plugin)
1946 {
1947 msn_notification_end();
1948 msn_switchboard_end();
1949 msn_sync_end();
1950
1951 return TRUE;
1952 }
1953
1954 static GaimPluginProtocolInfo prpl_info =
1955 {
1956 OPT_PROTO_MAIL_CHECK,
1957 NULL, /* user_splits */
1958 NULL, /* protocol_options */
1959 {"png", 0, 0, 96, 96, 0, GAIM_ICON_SCALE_SEND}, /* icon_spec */
1960 msn_list_icon, /* list_icon */
1961 msn_list_emblems, /* list_emblems */
1962 msn_status_text, /* status_text */
1963 msn_tooltip_text, /* tooltip_text */
1964 msn_status_types, /* away_states */
1965 msn_blist_node_menu, /* blist_node_menu */
1966 NULL, /* chat_info */
1967 NULL, /* chat_info_defaults */
1968 msn_login, /* login */
1969 msn_close, /* close */
1970 msn_send_im, /* send_im */
1971 NULL, /* set_info */
1972 msn_send_typing, /* send_typing */
1973 msn_get_info, /* get_info */
1974 msn_set_status, /* set_away */
1975 msn_set_idle, /* set_idle */
1976 NULL, /* change_passwd */
1977 msn_add_buddy, /* add_buddy */
1978 NULL, /* add_buddies */
1979 msn_rem_buddy, /* remove_buddy */
1980 NULL, /* remove_buddies */
1981 msn_add_permit, /* add_permit */
1982 msn_add_deny, /* add_deny */
1983 msn_rem_permit, /* rem_permit */
1984 msn_rem_deny, /* rem_deny */
1985 msn_set_permit_deny, /* set_permit_deny */
1986 NULL, /* join_chat */
1987 NULL, /* reject chat invite */
1988 NULL, /* get_chat_name */
1989 msn_chat_invite, /* chat_invite */
1990 msn_chat_leave, /* chat_leave */
1991 NULL, /* chat_whisper */
1992 msn_chat_send, /* chat_send */
1993 msn_keepalive, /* keepalive */
1994 NULL, /* register_user */
1995 NULL, /* get_cb_info */
1996 NULL, /* get_cb_away */
1997 NULL, /* alias_buddy */
1998 msn_group_buddy, /* group_buddy */
1999 msn_rename_group, /* rename_group */
2000 NULL, /* buddy_free */
2001 msn_convo_closed, /* convo_closed */
2002 msn_normalize, /* normalize */
2003 msn_set_buddy_icon, /* set_buddy_icon */
2004 msn_remove_group, /* remove_group */
2005 NULL, /* get_cb_real_name */
2006 NULL, /* set_chat_topic */
2007 NULL, /* find_blist_chat */
2008 NULL, /* roomlist_get_list */
2009 NULL, /* roomlist_cancel */
2010 NULL, /* roomlist_expand_category */
2011 msn_can_receive_file, /* can_receive_file */
2012 msn_send_file, /* send_file */
2013 msn_new_xfer, /* new_xfer */
2014 NULL, /* offline_message */
2015 NULL, /* whiteboard_prpl_ops */
2016 NULL, /* send_raw */
2017 NULL, /* roomlist_room_serialize */
2018 };
2019
2020 static GaimPluginInfo info =
2021 {
2022 GAIM_PLUGIN_MAGIC,
2023 GAIM_MAJOR_VERSION,
2024 GAIM_MINOR_VERSION,
2025 GAIM_PLUGIN_PROTOCOL, /**< type */
2026 NULL, /**< ui_requirement */
2027 0, /**< flags */
2028 NULL, /**< dependencies */
2029 GAIM_PRIORITY_DEFAULT, /**< priority */
2030
2031 "prpl-msn", /**< id */
2032 "MSN", /**< name */
2033 VERSION, /**< version */
2034 /** summary */
2035 N_("MSN Protocol Plugin"),
2036 /** description */
2037 N_("MSN Protocol Plugin"),
2038 "Christian Hammond <chipx86@gnupdate.org>", /**< author */
2039 GAIM_WEBSITE, /**< homepage */
2040
2041 msn_load, /**< load */
2042 msn_unload, /**< unload */
2043 NULL, /**< destroy */
2044
2045 NULL, /**< ui_info */
2046 &prpl_info, /**< extra_info */
2047 NULL, /**< prefs_info */
2048 msn_actions
2049 };
2050
2051 static void
2052 init_plugin(GaimPlugin *plugin)
2053 {
2054 GaimAccountOption *option;
2055
2056 option = gaim_account_option_string_new(_("Server"), "server",
2057 MSN_SERVER);
2058 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options,
2059 option);
2060
2061 option = gaim_account_option_int_new(_("Port"), "port", 1863);
2062 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options,
2063 option);
2064
2065 option = gaim_account_option_bool_new(_("Use HTTP Method"),
2066 "http_method", FALSE);
2067 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options,
2068 option);
2069
2070 option = gaim_account_option_bool_new(_("Show custom smileys"),
2071 "custom_smileys", TRUE);
2072 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options,
2073 option);
2074
2075 gaim_cmd_register("nudge", "", GAIM_CMD_P_PRPL,
2076 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_PRPL_ONLY,
2077 "prpl-msn", msn_cmd_nudge,
2078 _("nudge: nudge a user to get their attention"), NULL);
2079
2080 gaim_prefs_remove("/plugins/prpl/msn");
2081 }
2082
2083 GAIM_INIT_PLUGIN(msn, init_plugin, info);