comparison libpurple/protocols/msn/msn.c @ 20394:4a099e4d0d09

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