Mercurial > pidgin.yaz
comparison libpurple/protocols/msn/msn.c @ 20516:5bc492d82ff4
explicit merge of '46d8a45835e685c9dd812f5c6c0df074388bec8a'
and 'fa439470adac87fe2027a307e96c857766b06d12'
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Sun, 16 Sep 2007 18:05:55 +0000 |
parents | e5b827037534 7aaebdb013c9 |
children | 8a4748cbf844 |
comparison
equal
deleted
inserted
replaced
19719:bfa1557a7773 | 20516:5bc492d82ff4 |
---|---|
35 #include "state.h" | 35 #include "state.h" |
36 #include "util.h" | 36 #include "util.h" |
37 #include "cmds.h" | 37 #include "cmds.h" |
38 #include "core.h" | 38 #include "core.h" |
39 #include "prpl.h" | 39 #include "prpl.h" |
40 #include "msn-utils.h" | 40 #include "msnutils.h" |
41 #include "version.h" | 41 #include "version.h" |
42 | 42 |
43 #include "switchboard.h" | 43 #include "switchboard.h" |
44 #include "notification.h" | 44 #include "notification.h" |
45 #include "sync.h" | 45 #include "sync.h" |
149 serv_send_attention(gc, username, MSN_NUDGE); | 149 serv_send_attention(gc, username, MSN_NUDGE); |
150 | 150 |
151 return PURPLE_CMD_RET_OK; | 151 return PURPLE_CMD_RET_OK; |
152 } | 152 } |
153 | 153 |
154 static void | 154 void |
155 msn_act_id(PurpleConnection *gc, const char *entry) | 155 msn_act_id(PurpleConnection *gc, const char *entry) |
156 { | 156 { |
157 MsnCmdProc *cmdproc; | 157 MsnCmdProc *cmdproc; |
158 MsnSession *session; | 158 MsnSession *session; |
159 PurpleAccount *account; | 159 PurpleAccount *account; |
173 purple_notify_error(gc, NULL, | 173 purple_notify_error(gc, NULL, |
174 _("Your new MSN friendly name is too long."), NULL); | 174 _("Your new MSN friendly name is too long."), NULL); |
175 return; | 175 return; |
176 } | 176 } |
177 | 177 |
178 msn_cmdproc_send(cmdproc, "REA", "%s %s", | 178 if (*alias == '\0') { |
179 purple_account_get_username(account), | 179 alias = purple_url_encode(purple_account_get_username(account)); |
180 alias); | 180 } |
181 | |
182 msn_cmdproc_send(cmdproc, "PRP", "MFN %s", alias); | |
183 | |
181 } | 184 } |
182 | 185 |
183 static void | 186 static void |
184 msn_set_prp(PurpleConnection *gc, const char *type, const char *entry) | 187 msn_set_prp(PurpleConnection *gc, const char *type, const char *entry) |
185 { | 188 { |
412 return FALSE; | 415 return FALSE; |
413 user = buddy->proto_data; | 416 user = buddy->proto_data; |
414 return user && user->mobile; | 417 return user && user->mobile; |
415 } | 418 } |
416 | 419 |
420 void | |
421 msn_send_privacy(PurpleConnection *gc) | |
422 { | |
423 PurpleAccount *account; | |
424 MsnSession *session; | |
425 MsnCmdProc *cmdproc; | |
426 | |
427 account = purple_connection_get_account(gc); | |
428 session = gc->proto_data; | |
429 cmdproc = session->notification->cmdproc; | |
430 | |
431 if (account->perm_deny == PURPLE_PRIVACY_ALLOW_ALL || | |
432 account->perm_deny == PURPLE_PRIVACY_DENY_USERS) | |
433 { | |
434 msn_cmdproc_send(cmdproc, "BLP", "%s", "AL"); | |
435 } | |
436 else | |
437 { | |
438 msn_cmdproc_send(cmdproc, "BLP", "%s", "BL"); | |
439 } | |
440 } | |
441 | |
417 static void | 442 static void |
418 initiate_chat_cb(PurpleBlistNode *node, gpointer data) | 443 initiate_chat_cb(PurpleBlistNode *node, gpointer data) |
419 { | 444 { |
420 PurpleBuddy *buddy; | 445 PurpleBuddy *buddy; |
421 PurpleConnection *gc; | 446 PurpleConnection *gc; |
458 PurpleXfer *xfer; | 483 PurpleXfer *xfer; |
459 | 484 |
460 session = gc->proto_data; | 485 session = gc->proto_data; |
461 | 486 |
462 xfer = purple_xfer_new(gc->account, PURPLE_XFER_SEND, who); | 487 xfer = purple_xfer_new(gc->account, PURPLE_XFER_SEND, who); |
488 | |
463 if (xfer) | 489 if (xfer) |
464 { | 490 { |
465 slplink = msn_session_get_slplink(session, who); | 491 slplink = msn_session_get_slplink(session, who); |
466 | 492 |
467 xfer->data = slplink; | 493 xfer->data = slplink; |
509 msn_list_icon(PurpleAccount *a, PurpleBuddy *b) | 535 msn_list_icon(PurpleAccount *a, PurpleBuddy *b) |
510 { | 536 { |
511 return "msn"; | 537 return "msn"; |
512 } | 538 } |
513 | 539 |
540 /* | |
541 * Set the User status text | |
542 * Add the PSM String Using "Name - PSM String" format | |
543 */ | |
514 static char * | 544 static char * |
515 msn_status_text(PurpleBuddy *buddy) | 545 msn_status_text(PurpleBuddy *buddy) |
516 { | 546 { |
517 PurplePresence *presence; | 547 PurplePresence *presence; |
518 PurpleStatus *status; | 548 PurpleStatus *status; |
549 const char *msg, *cmedia; | |
519 | 550 |
520 presence = purple_buddy_get_presence(buddy); | 551 presence = purple_buddy_get_presence(buddy); |
521 status = purple_presence_get_active_status(presence); | 552 status = purple_presence_get_active_status(presence); |
522 | 553 |
523 if (!purple_presence_is_available(presence) && !purple_presence_is_idle(presence)) | 554 msg = purple_status_get_attr_string(status, "message"); |
524 { | 555 cmedia = purple_status_get_attr_string(status, "currentmedia"); |
525 return g_strdup(purple_status_get_name(status)); | 556 |
526 } | 557 if (cmedia) |
527 | 558 return g_markup_escape_text(cmedia, -1); |
559 else if (msg) | |
560 return g_markup_escape_text(msg, -1); | |
528 return NULL; | 561 return NULL; |
529 } | 562 } |
530 | 563 |
531 static void | 564 static void |
532 msn_tooltip_text(PurpleBuddy *buddy, PurpleNotifyUserInfo *user_info, gboolean full) | 565 msn_tooltip_text(PurpleBuddy *buddy, PurpleNotifyUserInfo *user_info, gboolean full) |
538 user = buddy->proto_data; | 571 user = buddy->proto_data; |
539 | 572 |
540 | 573 |
541 if (purple_presence_is_online(presence)) | 574 if (purple_presence_is_online(presence)) |
542 { | 575 { |
543 purple_notify_user_info_add_pair(user_info, _("Status"), | 576 const char *psm, *currentmedia, *name; |
544 (purple_presence_is_idle(presence) ? _("Idle") : purple_status_get_name(status))); | 577 char *tmp; |
578 | |
579 psm = purple_status_get_attr_string(status, "message"); | |
580 currentmedia = purple_status_get_attr_string(status, "currentmedia"); | |
581 | |
582 if (!purple_presence_is_available(presence)) { | |
583 name = purple_status_get_name(status); | |
584 } else { | |
585 name = NULL; | |
586 } | |
587 | |
588 if (name != NULL && *name) { | |
589 char *tmp2 = g_markup_escape_text(name, -1); | |
590 | |
591 if (psm != NULL && *psm) { | |
592 tmp = g_markup_escape_text(psm, -1); | |
593 purple_notify_user_info_add_pair(user_info, tmp2, tmp); | |
594 g_free(tmp); | |
595 } else { | |
596 purple_notify_user_info_add_pair(user_info, _("Status"), tmp2); | |
597 } | |
598 | |
599 g_free(tmp2); | |
600 } else { | |
601 tmp = g_markup_escape_text(psm, -1); | |
602 purple_notify_user_info_add_pair(user_info, _("Status"), tmp); | |
603 g_free(tmp); | |
604 } | |
605 | |
606 if (currentmedia) { | |
607 tmp = g_markup_escape_text(currentmedia, -1); | |
608 purple_notify_user_info_add_pair(user_info, _("Current media"), tmp); | |
609 g_free(tmp); | |
610 } | |
545 } | 611 } |
546 | 612 |
547 if (full && user) | 613 if (full && user) |
548 { | 614 { |
549 purple_notify_user_info_add_pair(user_info, _("Has you"), | 615 purple_notify_user_info_add_pair(user_info, _("Has you"), |
564 static GList * | 630 static GList * |
565 msn_status_types(PurpleAccount *account) | 631 msn_status_types(PurpleAccount *account) |
566 { | 632 { |
567 PurpleStatusType *status; | 633 PurpleStatusType *status; |
568 GList *types = NULL; | 634 GList *types = NULL; |
569 | 635 #if 0 |
570 status = purple_status_type_new_full(PURPLE_STATUS_AVAILABLE, | 636 status = purple_status_type_new_full(PURPLE_STATUS_AVAILABLE, |
571 NULL, NULL, FALSE, TRUE, FALSE); | 637 NULL, NULL, FALSE, TRUE, FALSE); |
638 #endif | |
639 status = purple_status_type_new_with_attrs( | |
640 PURPLE_STATUS_AVAILABLE, NULL, NULL, TRUE, TRUE, FALSE, | |
641 "message", _("Message"), purple_value_new(PURPLE_TYPE_STRING), | |
642 "currentmedia", _("Current media"), purple_value_new(PURPLE_TYPE_STRING), | |
643 NULL); | |
572 types = g_list_append(types, status); | 644 types = g_list_append(types, status); |
573 | 645 |
574 status = purple_status_type_new_full(PURPLE_STATUS_AWAY, | 646 status = purple_status_type_new_with_attrs( |
575 NULL, NULL, FALSE, TRUE, FALSE); | 647 PURPLE_STATUS_AWAY, NULL, NULL, TRUE, TRUE, FALSE, |
648 "message", _("Message"), purple_value_new(PURPLE_TYPE_STRING), | |
649 "currentmedia", _("Current media"), purple_value_new(PURPLE_TYPE_STRING), | |
650 NULL); | |
576 types = g_list_append(types, status); | 651 types = g_list_append(types, status); |
577 | 652 |
578 status = purple_status_type_new_full(PURPLE_STATUS_AWAY, | 653 status = purple_status_type_new_with_attrs( |
579 "brb", _("Be Right Back"), FALSE, TRUE, FALSE); | 654 PURPLE_STATUS_AWAY, "brb", _("Be Right Back"), TRUE, TRUE, FALSE, |
655 "message", _("Message"), purple_value_new(PURPLE_TYPE_STRING), | |
656 "currentmedia", _("Current media"), purple_value_new(PURPLE_TYPE_STRING), | |
657 NULL); | |
580 types = g_list_append(types, status); | 658 types = g_list_append(types, status); |
581 | 659 |
582 status = purple_status_type_new_full(PURPLE_STATUS_UNAVAILABLE, | 660 status = purple_status_type_new_with_attrs( |
583 "busy", _("Busy"), FALSE, TRUE, FALSE); | 661 PURPLE_STATUS_UNAVAILABLE, "busy", _("Busy"), TRUE, TRUE, FALSE, |
662 "message", _("Message"), purple_value_new(PURPLE_TYPE_STRING), | |
663 "currentmedia", _("Current media"), purple_value_new(PURPLE_TYPE_STRING), | |
664 NULL); | |
584 types = g_list_append(types, status); | 665 types = g_list_append(types, status); |
585 | 666 status = purple_status_type_new_with_attrs( |
586 status = purple_status_type_new_full(PURPLE_STATUS_UNAVAILABLE, | 667 PURPLE_STATUS_UNAVAILABLE, "phone", _("On the Phone"), TRUE, TRUE, FALSE, |
587 "phone", _("On the Phone"), FALSE, TRUE, FALSE); | 668 "message", _("Message"), purple_value_new(PURPLE_TYPE_STRING), |
669 "currentmedia", _("Current media"), purple_value_new(PURPLE_TYPE_STRING), | |
670 NULL); | |
588 types = g_list_append(types, status); | 671 types = g_list_append(types, status); |
589 | 672 status = purple_status_type_new_with_attrs( |
590 status = purple_status_type_new_full(PURPLE_STATUS_AWAY, | 673 PURPLE_STATUS_AWAY, "lunch", _("Out to Lunch"), TRUE, TRUE, FALSE, |
591 "lunch", _("Out to Lunch"), FALSE, TRUE, FALSE); | 674 "message", _("Message"), purple_value_new(PURPLE_TYPE_STRING), |
675 "currentmedia", _("Current media"), purple_value_new(PURPLE_TYPE_STRING), | |
676 NULL); | |
592 types = g_list_append(types, status); | 677 types = g_list_append(types, status); |
593 | 678 |
594 status = purple_status_type_new_full(PURPLE_STATUS_INVISIBLE, | 679 status = purple_status_type_new_full(PURPLE_STATUS_INVISIBLE, |
595 NULL, NULL, FALSE, TRUE, FALSE); | 680 NULL, NULL, FALSE, TRUE, FALSE); |
596 types = g_list_append(types, status); | 681 types = g_list_append(types, status); |
597 | 682 |
598 status = purple_status_type_new_full(PURPLE_STATUS_OFFLINE, | 683 status = purple_status_type_new_full(PURPLE_STATUS_OFFLINE, |
599 NULL, NULL, FALSE, TRUE, FALSE); | 684 NULL, NULL, FALSE, TRUE, FALSE); |
600 types = g_list_append(types, status); | 685 types = g_list_append(types, status); |
601 | 686 |
602 status = purple_status_type_new_full(PURPLE_STATUS_MOBILE, | 687 status = purple_status_type_new_full(PURPLE_STATUS_MOBILE, |
603 "mobile", NULL, FALSE, FALSE, TRUE); | 688 "mobile", NULL, FALSE, FALSE, TRUE); |
604 types = g_list_append(types, status); | 689 types = g_list_append(types, status); |
605 | 690 |
606 return types; | 691 return types; |
607 } | 692 } |
608 | 693 |
609 static GList * | 694 static GList * |
610 msn_actions(PurplePlugin *plugin, gpointer context) | 695 msn_actions(PurplePlugin *plugin, gpointer context) |
783 PurpleBuddy *buddy = purple_find_buddy(gc->account, who); | 868 PurpleBuddy *buddy = purple_find_buddy(gc->account, who); |
784 MsnMessage *msg; | 869 MsnMessage *msg; |
785 char *msgformat; | 870 char *msgformat; |
786 char *msgtext; | 871 char *msgtext; |
787 | 872 |
873 purple_debug_info("MSNP14","send IM {%s} to %s\n",message,who); | |
788 account = purple_connection_get_account(gc); | 874 account = purple_connection_get_account(gc); |
789 | 875 |
790 if (buddy) { | 876 if (buddy) { |
791 PurplePresence *p = purple_buddy_get_presence(buddy); | 877 PurplePresence *p = purple_buddy_get_presence(buddy); |
792 if (purple_presence_is_status_primitive_active(p, PURPLE_STATUS_MOBILE)) { | 878 if (purple_presence_is_status_primitive_active(p, PURPLE_STATUS_MOBILE)) { |
796 return 1; | 882 return 1; |
797 } | 883 } |
798 } | 884 } |
799 | 885 |
800 msn_import_html(message, &msgformat, &msgtext); | 886 msn_import_html(message, &msgformat, &msgtext); |
801 | 887 if(msn_user_is_online(account, who)|| |
802 if (strlen(msgtext) + strlen(msgformat) + strlen(VERSION) > 1564) | 888 msn_user_is_yahoo(account, who)){ |
803 { | 889 /*User online,then send Online Instant Message*/ |
890 | |
891 if (strlen(msgtext) + strlen(msgformat) + strlen(VERSION) > 1564) | |
892 { | |
893 g_free(msgformat); | |
894 g_free(msgtext); | |
895 | |
896 return -E2BIG; | |
897 } | |
898 | |
899 msg = msn_message_new_plain(msgtext); | |
900 msg->remote_user = g_strdup(who); | |
901 msn_message_set_attr(msg, "X-MMS-IM-Format", msgformat); | |
902 | |
804 g_free(msgformat); | 903 g_free(msgformat); |
805 g_free(msgtext); | 904 g_free(msgtext); |
806 | 905 |
807 return -E2BIG; | 906 purple_debug_info("MSNP14","prepare to send online Message\n"); |
808 } | 907 if (g_ascii_strcasecmp(who, purple_account_get_username(account))) |
809 | 908 { |
810 msg = msn_message_new_plain(msgtext); | 909 MsnSession *session; |
811 msn_message_set_attr(msg, "X-MMS-IM-Format", msgformat); | 910 MsnSwitchBoard *swboard; |
812 | 911 |
813 g_free(msgformat); | 912 session = gc->proto_data; |
814 g_free(msgtext); | 913 if(msn_user_is_yahoo(account,who)){ |
815 | 914 /*we send the online and offline Message to Yahoo User via UBM*/ |
816 if (g_ascii_strcasecmp(who, purple_account_get_username(account))) | 915 purple_debug_info("MSNP14","send to Yahoo User\n"); |
817 { | 916 uum_send_msg(session,msg); |
917 }else{ | |
918 purple_debug_info("MSNP14","send via switchboard\n"); | |
919 swboard = msn_session_get_swboard(session, who, MSN_SB_FLAG_IM); | |
920 msn_switchboard_send_msg(swboard, msg, TRUE); | |
921 } | |
922 } | |
923 else | |
924 { | |
925 char *body_str, *body_enc, *pre, *post; | |
926 const char *format; | |
927 MsnIMData *imdata = g_new0(MsnIMData, 1); | |
928 /* | |
929 * In MSN, you can't send messages to yourself, so | |
930 * we'll fake like we received it ;) | |
931 */ | |
932 body_str = msn_message_to_string(msg); | |
933 body_enc = g_markup_escape_text(body_str, -1); | |
934 g_free(body_str); | |
935 | |
936 format = msn_message_get_attr(msg, "X-MMS-IM-Format"); | |
937 msn_parse_format(format, &pre, &post); | |
938 body_str = g_strdup_printf("%s%s%s", pre ? pre : "", | |
939 body_enc ? body_enc : "", post ? post : ""); | |
940 g_free(body_enc); | |
941 g_free(pre); | |
942 g_free(post); | |
943 | |
944 serv_got_typing_stopped(gc, who); | |
945 imdata->gc = gc; | |
946 imdata->who = who; | |
947 imdata->msg = body_str; | |
948 imdata->flags = flags; | |
949 imdata->when = time(NULL); | |
950 g_idle_add(msn_send_me_im, imdata); | |
951 } | |
952 | |
953 msn_message_destroy(msg); | |
954 }else { | |
955 /*send Offline Instant Message,only to MSN Passport User*/ | |
818 MsnSession *session; | 956 MsnSession *session; |
819 MsnSwitchBoard *swboard; | 957 MsnOim *oim; |
820 | 958 char *friendname; |
959 | |
960 purple_debug_info("MSNP14","prepare to send offline Message\n"); | |
821 session = gc->proto_data; | 961 session = gc->proto_data; |
822 swboard = msn_session_get_swboard(session, who, MSN_SB_FLAG_IM); | 962 /* XXX/khc: hack */ |
823 | 963 if (!session->oim) |
824 msn_switchboard_send_msg(swboard, msg, TRUE); | 964 session->oim = msn_oim_new(session); |
825 } | 965 |
826 else | 966 oim = session->oim; |
827 { | 967 friendname = msn_encode_mime(account->username); |
828 char *body_str, *body_enc, *pre, *post; | 968 msn_oim_prep_send_msg_info(oim, purple_account_get_username(account), |
829 const char *format; | 969 friendname, who, message); |
830 MsnIMData *imdata = g_new0(MsnIMData, 1); | 970 msn_oim_send_msg(oim); |
831 /* | 971 } |
832 * In MSN, you can't send messages to yourself, so | |
833 * we'll fake like we received it ;) | |
834 */ | |
835 body_str = msn_message_to_string(msg); | |
836 body_enc = g_markup_escape_text(body_str, -1); | |
837 g_free(body_str); | |
838 | |
839 format = msn_message_get_attr(msg, "X-MMS-IM-Format"); | |
840 msn_parse_format(format, &pre, &post); | |
841 body_str = g_strdup_printf("%s%s%s", pre ? pre : "", | |
842 body_enc ? body_enc : "", post ? post : ""); | |
843 g_free(body_enc); | |
844 g_free(pre); | |
845 g_free(post); | |
846 | |
847 serv_got_typing_stopped(gc, who); | |
848 imdata->gc = gc; | |
849 imdata->who = who; | |
850 imdata->msg = body_str; | |
851 imdata->flags = flags; | |
852 imdata->when = time(NULL); | |
853 g_idle_add(msn_send_me_im, imdata); | |
854 } | |
855 | |
856 msn_message_destroy(msg); | |
857 | 972 |
858 return 1; | 973 return 1; |
859 } | 974 } |
860 | 975 |
861 static unsigned int | 976 static unsigned int |
990 | 1105 |
991 session = gc->proto_data; | 1106 session = gc->proto_data; |
992 userlist = session->userlist; | 1107 userlist = session->userlist; |
993 who = msn_normalize(gc->account, buddy->name); | 1108 who = msn_normalize(gc->account, buddy->name); |
994 | 1109 |
1110 purple_debug_info("MSN","Add user:%s to group:%s\n", who, group->name); | |
995 if (!session->logged_in) | 1111 if (!session->logged_in) |
996 { | 1112 { |
997 #if 0 | 1113 #if 0 |
998 fake_userlist_add_buddy(session->sync_userlist, who, MSN_LIST_FL, | 1114 fake_userlist_add_buddy(session->sync_userlist, who, MSN_LIST_FL, |
999 group ? group->name : NULL); | 1115 group ? group->name : NULL); |
1023 #endif | 1139 #endif |
1024 | 1140 |
1025 /* XXX - Would group ever be NULL here? I don't think so... | 1141 /* XXX - Would group ever be NULL here? I don't think so... |
1026 * shx: Yes it should; MSN handles non-grouped buddies, and this is only | 1142 * shx: Yes it should; MSN handles non-grouped buddies, and this is only |
1027 * internal. */ | 1143 * internal. */ |
1028 msn_userlist_add_buddy(userlist, who, MSN_LIST_FL, | 1144 msn_userlist_add_buddy(userlist, who, group ? group->name : NULL); |
1029 group ? group->name : NULL); | |
1030 } | 1145 } |
1031 | 1146 |
1032 static void | 1147 static void |
1033 msn_rem_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group) | 1148 msn_rem_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group) |
1034 { | 1149 { |
1040 | 1155 |
1041 if (!session->logged_in) | 1156 if (!session->logged_in) |
1042 return; | 1157 return; |
1043 | 1158 |
1044 /* XXX - Does buddy->name need to be msn_normalize'd here? --KingAnt */ | 1159 /* XXX - Does buddy->name need to be msn_normalize'd here? --KingAnt */ |
1045 msn_userlist_rem_buddy(userlist, buddy->name, MSN_LIST_FL, group->name); | 1160 msn_userlist_rem_buddy(userlist, buddy->name); |
1046 } | 1161 } |
1047 | 1162 |
1048 static void | 1163 static void |
1049 msn_add_permit(PurpleConnection *gc, const char *who) | 1164 msn_add_permit(PurpleConnection *gc, const char *who) |
1050 { | 1165 { |
1057 user = msn_userlist_find_user(userlist, who); | 1172 user = msn_userlist_find_user(userlist, who); |
1058 | 1173 |
1059 if (!session->logged_in) | 1174 if (!session->logged_in) |
1060 return; | 1175 return; |
1061 | 1176 |
1062 if (user != NULL && user->list_op & MSN_LIST_BL_OP) | 1177 if (user != NULL && user->list_op & MSN_LIST_BL_OP) { |
1063 msn_userlist_rem_buddy(userlist, who, MSN_LIST_BL, NULL); | 1178 msn_userlist_rem_buddy_from_list(userlist, who, MSN_LIST_BL); |
1064 | 1179 |
1065 msn_userlist_add_buddy(userlist, who, MSN_LIST_AL, NULL); | 1180 /* delete contact from Block list and add it to Allow in the callback */ |
1181 msn_del_contact_from_list(session->contact, NULL, who, MSN_LIST_BL); | |
1182 } else { | |
1183 /* just add the contact to Allow list */ | |
1184 msn_add_contact_to_list(session->contact, NULL, who, MSN_LIST_AL); | |
1185 } | |
1186 | |
1187 | |
1188 msn_userlist_add_buddy_to_list(userlist, who, MSN_LIST_AL); | |
1066 } | 1189 } |
1067 | 1190 |
1068 static void | 1191 static void |
1069 msn_add_deny(PurpleConnection *gc, const char *who) | 1192 msn_add_deny(PurpleConnection *gc, const char *who) |
1070 { | 1193 { |
1077 user = msn_userlist_find_user(userlist, who); | 1200 user = msn_userlist_find_user(userlist, who); |
1078 | 1201 |
1079 if (!session->logged_in) | 1202 if (!session->logged_in) |
1080 return; | 1203 return; |
1081 | 1204 |
1082 if (user != NULL && user->list_op & MSN_LIST_AL_OP) | 1205 if (user != NULL && user->list_op & MSN_LIST_AL_OP) { |
1083 msn_userlist_rem_buddy(userlist, who, MSN_LIST_AL, NULL); | 1206 msn_userlist_rem_buddy_from_list(userlist, who, MSN_LIST_AL); |
1084 | 1207 |
1085 msn_userlist_add_buddy(userlist, who, MSN_LIST_BL, NULL); | 1208 /* delete contact from Allow list and add it to Block in the callback */ |
1209 msn_del_contact_from_list(session->contact, NULL, who, MSN_LIST_AL); | |
1210 } else { | |
1211 /* just add the contact to Block list */ | |
1212 msn_add_contact_to_list(session->contact, NULL, who, MSN_LIST_BL); | |
1213 } | |
1214 | |
1215 msn_userlist_add_buddy_to_list(userlist, who, MSN_LIST_BL); | |
1086 } | 1216 } |
1087 | 1217 |
1088 static void | 1218 static void |
1089 msn_rem_permit(PurpleConnection *gc, const char *who) | 1219 msn_rem_permit(PurpleConnection *gc, const char *who) |
1090 { | 1220 { |
1098 if (!session->logged_in) | 1228 if (!session->logged_in) |
1099 return; | 1229 return; |
1100 | 1230 |
1101 user = msn_userlist_find_user(userlist, who); | 1231 user = msn_userlist_find_user(userlist, who); |
1102 | 1232 |
1103 msn_userlist_rem_buddy(userlist, who, MSN_LIST_AL, NULL); | 1233 msn_userlist_rem_buddy_from_list(userlist, who, MSN_LIST_AL); |
1234 | |
1235 msn_del_contact_from_list(session->contact, NULL, who, MSN_LIST_AL); | |
1104 | 1236 |
1105 if (user != NULL && user->list_op & MSN_LIST_RL_OP) | 1237 if (user != NULL && user->list_op & MSN_LIST_RL_OP) |
1106 msn_userlist_add_buddy(userlist, who, MSN_LIST_BL, NULL); | 1238 msn_userlist_add_buddy_to_list(userlist, who, MSN_LIST_BL); |
1107 } | 1239 } |
1108 | 1240 |
1109 static void | 1241 static void |
1110 msn_rem_deny(PurpleConnection *gc, const char *who) | 1242 msn_rem_deny(PurpleConnection *gc, const char *who) |
1111 { | 1243 { |
1119 if (!session->logged_in) | 1251 if (!session->logged_in) |
1120 return; | 1252 return; |
1121 | 1253 |
1122 user = msn_userlist_find_user(userlist, who); | 1254 user = msn_userlist_find_user(userlist, who); |
1123 | 1255 |
1124 msn_userlist_rem_buddy(userlist, who, MSN_LIST_BL, NULL); | 1256 msn_userlist_rem_buddy_from_list(userlist, who, MSN_LIST_BL); |
1257 | |
1258 msn_del_contact_from_list(session->contact, NULL, who, MSN_LIST_BL); | |
1125 | 1259 |
1126 if (user != NULL && user->list_op & MSN_LIST_RL_OP) | 1260 if (user != NULL && user->list_op & MSN_LIST_RL_OP) |
1127 msn_userlist_add_buddy(userlist, who, MSN_LIST_AL, NULL); | 1261 msn_userlist_add_buddy_to_list(userlist, who, MSN_LIST_AL); |
1128 } | 1262 } |
1129 | 1263 |
1130 static void | 1264 static void |
1131 msn_set_permit_deny(PurpleConnection *gc) | 1265 msn_set_permit_deny(PurpleConnection *gc) |
1132 { | 1266 { |
1133 PurpleAccount *account; | 1267 msn_send_privacy(gc); |
1134 MsnSession *session; | |
1135 MsnCmdProc *cmdproc; | |
1136 | |
1137 account = purple_connection_get_account(gc); | |
1138 session = gc->proto_data; | |
1139 cmdproc = session->notification->cmdproc; | |
1140 | |
1141 if (account->perm_deny == PURPLE_PRIVACY_ALLOW_ALL || | |
1142 account->perm_deny == PURPLE_PRIVACY_DENY_USERS) | |
1143 { | |
1144 msn_cmdproc_send(cmdproc, "BLP", "%s", "AL"); | |
1145 } | |
1146 else | |
1147 { | |
1148 msn_cmdproc_send(cmdproc, "BLP", "%s", "BL"); | |
1149 } | |
1150 } | 1268 } |
1151 | 1269 |
1152 static void | 1270 static void |
1153 msn_chat_invite(PurpleConnection *gc, int id, const char *msg, | 1271 msn_chat_invite(PurpleConnection *gc, int id, const char *msg, |
1154 const char *who) | 1272 const char *who) |
1281 static void | 1399 static void |
1282 msn_rename_group(PurpleConnection *gc, const char *old_name, | 1400 msn_rename_group(PurpleConnection *gc, const char *old_name, |
1283 PurpleGroup *group, GList *moved_buddies) | 1401 PurpleGroup *group, GList *moved_buddies) |
1284 { | 1402 { |
1285 MsnSession *session; | 1403 MsnSession *session; |
1286 MsnCmdProc *cmdproc; | 1404 |
1287 int old_gid; | 1405 session = gc->proto_data; |
1288 const char *enc_new_group_name; | 1406 |
1289 | 1407 g_return_if_fail(session != NULL); |
1290 session = gc->proto_data; | 1408 g_return_if_fail(session->userlist != NULL); |
1291 cmdproc = session->notification->cmdproc; | 1409 |
1292 enc_new_group_name = purple_url_encode(group->name); | 1410 if (msn_userlist_find_group_with_name(session->userlist, old_name) != NULL) |
1293 | 1411 { |
1294 old_gid = msn_userlist_find_group_id(session->userlist, old_name); | 1412 msn_contact_rename_group(session, old_name, group->name); |
1295 | |
1296 if (old_gid >= 0) | |
1297 { | |
1298 msn_cmdproc_send(cmdproc, "REG", "%d %s 0", old_gid, | |
1299 enc_new_group_name); | |
1300 } | 1413 } |
1301 else | 1414 else |
1302 { | 1415 { |
1303 msn_cmdproc_send(cmdproc, "ADG", "%s 0", enc_new_group_name); | 1416 /* not found */ |
1417 msn_add_group(session, NULL, group->name); | |
1304 } | 1418 } |
1305 } | 1419 } |
1306 | 1420 |
1307 static void | 1421 static void |
1308 msn_convo_closed(PurpleConnection *gc, const char *who) | 1422 msn_convo_closed(PurpleConnection *gc, const char *who) |
1358 static void | 1472 static void |
1359 msn_remove_group(PurpleConnection *gc, PurpleGroup *group) | 1473 msn_remove_group(PurpleConnection *gc, PurpleGroup *group) |
1360 { | 1474 { |
1361 MsnSession *session; | 1475 MsnSession *session; |
1362 MsnCmdProc *cmdproc; | 1476 MsnCmdProc *cmdproc; |
1363 int group_id; | |
1364 | 1477 |
1365 session = gc->proto_data; | 1478 session = gc->proto_data; |
1366 cmdproc = session->notification->cmdproc; | 1479 cmdproc = session->notification->cmdproc; |
1367 | 1480 |
1368 if ((group_id = msn_userlist_find_group_id(session->userlist, group->name)) >= 0) | 1481 purple_debug_info("MSN", "Remove group %s\n", group->name); |
1369 { | 1482 /*we can't delete the default group*/ |
1370 msn_cmdproc_send(cmdproc, "RMG", "%d", group_id); | 1483 if(!strcmp(group->name, MSN_INDIVIDUALS_GROUP_NAME)|| |
1371 } | 1484 !strcmp(group->name, MSN_NON_IM_GROUP_NAME)) |
1485 { | |
1486 purple_debug_info("MSN", "This group can't be removed, returning.\n"); | |
1487 return ; | |
1488 } | |
1489 | |
1490 msn_del_group(session, group->name); | |
1372 } | 1491 } |
1373 | 1492 |
1374 /** | 1493 /** |
1375 * Extract info text from info_data and add it to user_info | 1494 * Extract info text from info_data and add it to user_info |
1376 */ | 1495 */ |
1416 static char * | 1535 static char * |
1417 msn_get_photo_url(const char *url_text) | 1536 msn_get_photo_url(const char *url_text) |
1418 { | 1537 { |
1419 char *p, *q; | 1538 char *p, *q; |
1420 | 1539 |
1421 if ((p = strstr(url_text, " contactparams:photopreauthurl=\"")) != NULL) | 1540 if ((p = strstr(url_text, PHOTO_URL)) != NULL) |
1422 { | 1541 { |
1423 p += strlen(" contactparams:photopreauthurl=\""); | 1542 p += strlen(PHOTO_URL); |
1424 } | 1543 } |
1425 | 1544 if (p && (strncmp(p, "http://",strlen("http://")) == 0) && ((q = strchr(p, '"')) != NULL)) |
1426 if (p && (strncmp(p, "http://", 8) == 0) && ((q = strchr(p, '"')) != NULL)) | |
1427 return g_strndup(p, q - p); | 1545 return g_strndup(p, q - p); |
1428 | 1546 |
1429 return NULL; | 1547 return NULL; |
1430 } | 1548 } |
1431 | 1549 |
1486 #if PHOTO_SUPPORT | 1604 #if PHOTO_SUPPORT |
1487 char *photo_url_text = NULL; | 1605 char *photo_url_text = NULL; |
1488 MsnGetInfoStepTwoData *info2_data = NULL; | 1606 MsnGetInfoStepTwoData *info2_data = NULL; |
1489 #endif | 1607 #endif |
1490 | 1608 |
1491 purple_debug_info("msn", "In msn_got_info\n"); | 1609 purple_debug_info("msn", "In msn_got_info,url_text:{%s}\n",url_text); |
1492 | 1610 |
1493 /* Make sure the connection is still valid */ | 1611 /* Make sure the connection is still valid */ |
1494 if (g_list_find(purple_connections_get_all(), info_data->gc) == NULL) | 1612 if (g_list_find(purple_connections_get_all(), info_data->gc) == NULL) |
1495 { | 1613 { |
1496 purple_debug_warning("msn", "invalid connection. ignoring buddy info.\n"); | 1614 purple_debug_warning("msn", "invalid connection. ignoring buddy info.\n"); |
1870 g_free(tmp); | 1988 g_free(tmp); |
1871 | 1989 |
1872 #if PHOTO_SUPPORT | 1990 #if PHOTO_SUPPORT |
1873 /* Find the URL to the photo; must be before the marshalling [Bug 994207] */ | 1991 /* Find the URL to the photo; must be before the marshalling [Bug 994207] */ |
1874 photo_url_text = msn_get_photo_url(url_text); | 1992 photo_url_text = msn_get_photo_url(url_text); |
1993 purple_debug_info("MSNP14","photo url:{%s}\n",photo_url_text); | |
1875 | 1994 |
1876 /* Marshall the existing state */ | 1995 /* Marshall the existing state */ |
1877 info2_data = g_malloc0(sizeof(MsnGetInfoStepTwoData)); | 1996 info2_data = g_malloc0(sizeof(MsnGetInfoStepTwoData)); |
1878 info2_data->info_data = info_data; | 1997 info2_data->info_data = info_data; |
1879 info2_data->stripped = stripped; | 1998 info2_data->stripped = stripped; |
2094 NULL, /* remove_buddies */ | 2213 NULL, /* remove_buddies */ |
2095 msn_add_permit, /* add_permit */ | 2214 msn_add_permit, /* add_permit */ |
2096 msn_add_deny, /* add_deny */ | 2215 msn_add_deny, /* add_deny */ |
2097 msn_rem_permit, /* rem_permit */ | 2216 msn_rem_permit, /* rem_permit */ |
2098 msn_rem_deny, /* rem_deny */ | 2217 msn_rem_deny, /* rem_deny */ |
2099 msn_set_permit_deny, /* set_permit_deny */ | 2218 msn_set_permit_deny, /* set_permit_deny */ |
2100 NULL, /* join_chat */ | 2219 NULL, /* join_chat */ |
2101 NULL, /* reject chat invite */ | 2220 NULL, /* reject chat invite */ |
2102 NULL, /* get_chat_name */ | 2221 NULL, /* get_chat_name */ |
2103 msn_chat_invite, /* chat_invite */ | 2222 msn_chat_invite, /* chat_invite */ |
2104 msn_chat_leave, /* chat_leave */ | 2223 msn_chat_leave, /* chat_leave */ |
2150 | 2269 |
2151 "prpl-msn", /**< id */ | 2270 "prpl-msn", /**< id */ |
2152 "MSN", /**< name */ | 2271 "MSN", /**< name */ |
2153 VERSION, /**< version */ | 2272 VERSION, /**< version */ |
2154 /** summary */ | 2273 /** summary */ |
2155 N_("MSN Protocol Plugin"), | 2274 N_("Windows Live Messenger Protocol Plugin"), |
2156 /** description */ | 2275 /** description */ |
2157 N_("MSN Protocol Plugin"), | 2276 N_("Windows Live Messenger Protocol Plugin"), |
2158 "Christian Hammond <chipx86@gnupdate.org>", /**< author */ | 2277 "Christian Hammond <chipx86@gnupdate.org>, " |
2278 "MaYuan <mayuan2006@gmail.com>", /**< author */ | |
2159 PURPLE_WEBSITE, /**< homepage */ | 2279 PURPLE_WEBSITE, /**< homepage */ |
2160 | 2280 |
2161 msn_load, /**< load */ | 2281 msn_load, /**< load */ |
2162 msn_unload, /**< unload */ | 2282 msn_unload, /**< unload */ |
2163 NULL, /**< destroy */ | 2283 NULL, /**< destroy */ |
2178 init_plugin(PurplePlugin *plugin) | 2298 init_plugin(PurplePlugin *plugin) |
2179 { | 2299 { |
2180 PurpleAccountOption *option; | 2300 PurpleAccountOption *option; |
2181 | 2301 |
2182 option = purple_account_option_string_new(_("Server"), "server", | 2302 option = purple_account_option_string_new(_("Server"), "server", |
2183 MSN_SERVER); | 2303 WLM_SERVER); |
2184 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, | 2304 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, |
2185 option); | 2305 option); |
2186 | 2306 |
2187 option = purple_account_option_int_new(_("Port"), "port", 1863); | 2307 option = purple_account_option_int_new(_("Port"), "port", WLM_PORT); |
2188 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, | 2308 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, |
2189 option); | 2309 option); |
2190 | 2310 |
2191 option = purple_account_option_bool_new(_("Use HTTP Method"), | 2311 option = purple_account_option_bool_new(_("Use HTTP Method"), |
2192 "http_method", FALSE); | 2312 "http_method", FALSE); |