Mercurial > pidgin
comparison libpurple/protocols/msn/contact.c @ 23470:eb8bd060b987
Update MSN Contact tokens when an invalid token error is returned.
author | Elliott Sales de Andrade <qulogic@pidgin.im> |
---|---|
date | Sat, 07 Jun 2008 06:21:09 +0000 |
parents | 1ac5faa72c8d |
children | 70de4e2246ec |
comparison
equal
deleted
inserted
replaced
23469:5f9e6f8b2aea | 23470:eb8bd060b987 |
---|---|
62 state->session = session; | 62 state->session = session; |
63 | 63 |
64 return state; | 64 return state; |
65 } | 65 } |
66 | 66 |
67 MsnCallbackState * | |
68 msn_callback_state_dup(MsnCallbackState *state) | |
69 { | |
70 MsnCallbackState *new_state = g_new0(MsnCallbackState, 1); | |
71 | |
72 new_state->session = state->session; | |
73 new_state->who = g_strdup(state->who); | |
74 new_state->uid = g_strdup(state->uid); | |
75 new_state->old_group_name = g_strdup(state->old_group_name); | |
76 new_state->new_group_name = g_strdup(state->new_group_name); | |
77 new_state->guid = g_strdup(state->guid); | |
78 /* The rest should be made new */ | |
79 | |
80 return new_state; | |
81 } | |
82 | |
67 void | 83 void |
68 msn_callback_state_free(MsnCallbackState *state) | 84 msn_callback_state_free(MsnCallbackState *state) |
69 { | 85 { |
70 if (state == NULL) | 86 if (state == NULL) |
71 return; | 87 return; |
73 g_free(state->who); | 89 g_free(state->who); |
74 g_free(state->uid); | 90 g_free(state->uid); |
75 g_free(state->old_group_name); | 91 g_free(state->old_group_name); |
76 g_free(state->new_group_name); | 92 g_free(state->new_group_name); |
77 g_free(state->guid); | 93 g_free(state->guid); |
94 xmlnode_free(state->body); | |
78 | 95 |
79 g_free(state); | 96 g_free(state); |
80 } | 97 } |
81 | 98 |
82 void | 99 void |
199 g_return_if_fail(session->user != NULL); | 216 g_return_if_fail(session->user != NULL); |
200 g_return_if_fail(session->user->passport != NULL); | 217 g_return_if_fail(session->user->passport != NULL); |
201 | 218 |
202 purple_debug_info("msnab","Creating an Address Book.\n"); | 219 purple_debug_info("msnab","Creating an Address Book.\n"); |
203 | 220 |
204 body = g_strdup_printf(MSN_ADD_ADDRESSBOOK_TEMPLATE, | 221 body = g_markup_printf_escaped(MSN_ADD_ADDRESSBOOK_TEMPLATE, |
205 msn_nexus_get_token_str(session->nexus, MSN_AUTH_CONTACTS), | 222 msn_nexus_get_token_str(session->nexus, MSN_AUTH_CONTACTS), |
206 session->user->passport); | 223 session->user->passport); |
207 | 224 |
208 msn_soap_message_send(session, | 225 msn_soap_message_send(session, |
209 msn_soap_message_new(MSN_ADD_ADDRESSBOOK_SOAP_ACTION, | 226 msn_soap_message_new(MSN_ADD_ADDRESSBOOK_SOAP_ACTION, |
386 if ( update_time != NULL ) { | 403 if ( update_time != NULL ) { |
387 purple_debug_info("MSNCL","Last update time: %s\n",update_time); | 404 purple_debug_info("MSNCL","Last update time: %s\n",update_time); |
388 update_str = g_strdup_printf(MSN_GET_CONTACT_UPDATE_XML,update_time); | 405 update_str = g_strdup_printf(MSN_GET_CONTACT_UPDATE_XML,update_time); |
389 } | 406 } |
390 | 407 |
391 body = g_strdup_printf(MSN_GET_CONTACT_TEMPLATE, partner_scenario_str, | 408 body = g_markup_printf_escaped(MSN_GET_CONTACT_TEMPLATE, partner_scenario_str, |
392 msn_nexus_get_token_str(session->nexus, MSN_AUTH_CONTACTS), | 409 msn_nexus_get_token_str(session->nexus, MSN_AUTH_CONTACTS), |
393 update_str ? update_str : ""); | 410 update_str ? update_str : ""); |
394 | 411 |
395 msn_soap_message_send(session, | 412 msn_soap_message_send(session, |
396 msn_soap_message_new(MSN_GET_CONTACT_SOAP_ACTION, | 413 msn_soap_message_new(MSN_GET_CONTACT_SOAP_ACTION, |
773 if (dynamicItemLastChange != NULL) | 790 if (dynamicItemLastChange != NULL) |
774 update_str = g_strdup_printf(MSN_GET_ADDRESS_UPDATE_XML, dynamicItemLastChange); | 791 update_str = g_strdup_printf(MSN_GET_ADDRESS_UPDATE_XML, dynamicItemLastChange); |
775 else if (LastChanged != NULL) | 792 else if (LastChanged != NULL) |
776 update_str = g_strdup_printf(MSN_GET_ADDRESS_UPDATE_XML, LastChanged); | 793 update_str = g_strdup_printf(MSN_GET_ADDRESS_UPDATE_XML, LastChanged); |
777 | 794 |
778 body = g_strdup_printf(MSN_GET_ADDRESS_TEMPLATE, | 795 body = g_markup_printf_escaped(MSN_GET_ADDRESS_TEMPLATE, |
779 MsnSoapPartnerScenarioText[partner_scenario], | 796 MsnSoapPartnerScenarioText[partner_scenario], |
780 msn_nexus_get_token_str(session->nexus, MSN_AUTH_CONTACTS), | 797 msn_nexus_get_token_str(session->nexus, MSN_AUTH_CONTACTS), |
781 update_str ? update_str : ""); | 798 update_str ? update_str : ""); |
782 | 799 |
783 msn_soap_message_send(session, | 800 msn_soap_message_send(session, |
788 | 805 |
789 g_free(update_str); | 806 g_free(update_str); |
790 g_free(body); | 807 g_free(body); |
791 } | 808 } |
792 | 809 |
810 /*************************************************************** | |
811 * Contact Operations | |
812 ***************************************************************/ | |
813 | |
814 static const char * | |
815 msn_contact_operation_str(MsnCallbackAction action) | |
816 { | |
817 /* Make sure this is large enough when adding more */ | |
818 static char buf[BUF_LEN]; | |
819 buf[0] = '\0'; | |
820 | |
821 if (action & MSN_ADD_BUDDY) | |
822 strcat(buf, "Adding Buddy,"); | |
823 if (action & MSN_MOVE_BUDDY) | |
824 strcat(buf, "Moving Buddy,"); | |
825 if (action & MSN_ACCEPTED_BUDDY) | |
826 strcat(buf, "Accepted Buddy,"); | |
827 if (action & MSN_DENIED_BUDDY) | |
828 strcat(buf, "Denied Buddy,"); | |
829 if (action & MSN_ADD_GROUP) | |
830 strcat(buf, "Adding Group,"); | |
831 if (action & MSN_DEL_GROUP) | |
832 strcat(buf, "Deleting Group,"); | |
833 if (action & MSN_RENAME_GROUP) | |
834 strcat(buf, "Renaming Group,"); | |
835 if (action & MSN_UPDATE_INFO) | |
836 strcat(buf, "Updating Contact Info,"); | |
837 | |
838 return buf; | |
839 } | |
840 | |
841 static gboolean msn_contact_request(MsnCallbackState *state); | |
842 | |
843 static void | |
844 msn_contact_request_cb(MsnSoapMessage *req, MsnSoapMessage *resp, | |
845 gpointer data) | |
846 { | |
847 MsnCallbackState *state = data; | |
848 xmlnode *faultcode; | |
849 char *faultcode_str; | |
850 | |
851 if (resp == NULL) { | |
852 purple_debug_error("MSNCL", | |
853 "Operation {%s} failed. No response received from server.\n", | |
854 msn_contact_operation_str(state->action)); | |
855 return; | |
856 } | |
857 | |
858 faultcode = xmlnode_get_child(resp->xml, "Body/Fault/faultcode"); | |
859 | |
860 if (faultcode == NULL) { | |
861 /* No errors */ | |
862 if (state->cb) | |
863 ((MsnSoapCallback)state->cb)(req, resp, data); | |
864 msn_callback_state_free(state); | |
865 return; | |
866 } | |
867 | |
868 faultcode_str = xmlnode_get_data(faultcode); | |
869 | |
870 if (faultcode_str && g_str_equal(faultcode_str, "q0:BadContextToken")) { | |
871 purple_debug_info("MSNCL", | |
872 "Contact Operation {%s} failed because of bad token." | |
873 " Updating token now and retrying operation.\n", | |
874 msn_contact_operation_str(state->action)); | |
875 /* Token has expired, so renew it, and try again later */ | |
876 msn_nexus_update_token(state->session->nexus, MSN_AUTH_CONTACTS, | |
877 (GSourceFunc)msn_contact_request, data); | |
878 } | |
879 else | |
880 { | |
881 /* We don't know how to respond to this faultcode, so just log it */ | |
882 /* XXX: Probably should notify the user or undo the change or something? */ | |
883 char *str = xmlnode_to_str(xmlnode_get_child(resp->xml, "Body/Fault"), NULL); | |
884 purple_debug_error("MSNCL", "Operation {%s} Failed, SOAP Fault was: %s\n", | |
885 msn_contact_operation_str(state->action), str); | |
886 g_free(str); | |
887 msn_callback_state_free(state); | |
888 } | |
889 | |
890 g_free(faultcode_str); | |
891 } | |
892 | |
893 static gboolean | |
894 msn_contact_request(MsnCallbackState *state) | |
895 { | |
896 if (state->token == NULL) | |
897 state->token = xmlnode_get_child(state->body, | |
898 "Header/ABAuthHeader/TicketToken"); | |
899 /* delete old & replace with new token */ | |
900 xmlnode_free(state->token->child); | |
901 xmlnode_insert_data(state->token, | |
902 msn_nexus_get_token_str(state->session->nexus, MSN_AUTH_CONTACTS), -1); | |
903 msn_soap_message_send(state->session, | |
904 msn_soap_message_new(state->post_action, xmlnode_copy(state->body)), | |
905 MSN_CONTACT_SERVER, state->post_url, msn_contact_request_cb, state); | |
906 return FALSE; | |
907 } | |
908 | |
793 static void | 909 static void |
794 msn_add_contact_read_cb(MsnSoapMessage *req, MsnSoapMessage *resp, | 910 msn_add_contact_read_cb(MsnSoapMessage *req, MsnSoapMessage *resp, |
795 gpointer data) | 911 gpointer data) |
796 { | 912 { |
797 MsnCallbackState *state = data; | 913 MsnCallbackState *state = data; |
798 MsnSession *session = state->session; | 914 MsnSession *session = state->session; |
799 | 915 |
916 MsnUserList *userlist; | |
917 MsnUser *user; | |
918 | |
800 g_return_if_fail(session != NULL); | 919 g_return_if_fail(session != NULL); |
801 | 920 |
802 if (resp != NULL) { | 921 userlist = session->userlist; |
803 MsnUserList *userlist = session->userlist; | 922 |
804 MsnUser *user; | 923 purple_debug_info("MSNCL","Contact added successfully\n"); |
805 | 924 |
806 purple_debug_info("MSNCL","Contact added successfully\n"); | 925 // the code this block is replacing didn't send ADL for yahoo contacts, |
807 | 926 // but i haven't confirmed this is WLM's behaviour wrt yahoo contacts |
808 // the code this block is replacing didn't send ADL for yahoo contacts, | 927 if ( !msn_user_is_yahoo(session->account, state->who) ) { |
809 // but i haven't confirmed this is WLM's behaviour wrt yahoo contacts | 928 msn_userlist_add_buddy_to_list(userlist, state->who, MSN_LIST_AL); |
810 if ( !msn_user_is_yahoo(session->account, state->who) ) { | 929 msn_userlist_add_buddy_to_list(userlist, state->who, MSN_LIST_FL); |
811 msn_userlist_add_buddy_to_list(userlist, state->who, MSN_LIST_AL); | 930 } |
812 msn_userlist_add_buddy_to_list(userlist, state->who, MSN_LIST_FL); | 931 |
813 } | 932 msn_notification_send_fqy(session, state->who); |
814 | 933 |
815 msn_notification_send_fqy(session, state->who); | 934 user = msn_userlist_find_add_user(userlist, state->who, state->who); |
816 | 935 msn_user_add_group_id(user, state->guid); |
817 user = msn_userlist_find_add_user(userlist, state->who, state->who); | |
818 msn_user_add_group_id(user, state->guid); | |
819 } | |
820 | |
821 msn_callback_state_free(state); | |
822 } | 936 } |
823 | 937 |
824 /* add a Contact in MSN_INDIVIDUALS_GROUP */ | 938 /* add a Contact in MSN_INDIVIDUALS_GROUP */ |
825 void | 939 void |
826 msn_add_contact(MsnSession *session, MsnCallbackState *state, const char *passport) | 940 msn_add_contact(MsnSession *session, MsnCallbackState *state, const char *passport) |
841 #endif | 955 #endif |
842 | 956 |
843 purple_debug_info("MSNCL","Adding contact %s to contact list\n", passport); | 957 purple_debug_info("MSNCL","Adding contact %s to contact list\n", passport); |
844 | 958 |
845 contact_xml = g_strdup_printf(MSN_CONTACT_XML, passport); | 959 contact_xml = g_strdup_printf(MSN_CONTACT_XML, passport); |
846 body = g_strdup_printf(MSN_ADD_CONTACT_TEMPLATE, | 960 body = g_strdup_printf(MSN_ADD_CONTACT_TEMPLATE, contact_xml); |
847 msn_nexus_get_token_str(session->nexus, MSN_AUTH_CONTACTS), | 961 |
848 contact_xml); | 962 state->body = xmlnode_from_str(body, -1); |
849 | 963 state->post_action = MSN_CONTACT_ADD_SOAP_ACTION; |
850 msn_soap_message_send(session, | 964 state->post_url = MSN_ADDRESS_BOOK_POST_URL; |
851 msn_soap_message_new(MSN_CONTACT_ADD_SOAP_ACTION, | 965 state->cb = msn_add_contact_read_cb; |
852 xmlnode_from_str(body, -1)), | 966 msn_contact_request(state); |
853 MSN_CONTACT_SERVER, MSN_ADDRESS_BOOK_POST_URL, | |
854 msn_add_contact_read_cb, state); | |
855 | 967 |
856 g_free(contact_xml); | 968 g_free(contact_xml); |
857 g_free(body); | 969 g_free(body); |
858 } | 970 } |
859 | 971 |
866 | 978 |
867 g_return_if_fail(data != NULL); | 979 g_return_if_fail(data != NULL); |
868 | 980 |
869 userlist = state->session->userlist; | 981 userlist = state->session->userlist; |
870 | 982 |
871 if (resp != NULL) { | 983 if (msn_userlist_add_buddy_to_group(userlist, state->who, |
872 if (msn_userlist_add_buddy_to_group(userlist, state->who, | 984 state->new_group_name)) { |
873 state->new_group_name)) { | 985 purple_debug_info("MSNCL", "Contact %s added to group %s successfully!\n", state->who, state->new_group_name); |
874 purple_debug_info("MSNCL", "Contact %s added to group %s successfully!\n", state->who, state->new_group_name); | 986 } else { |
875 } else { | 987 purple_debug_info("MSNCL","Contact %s added to group %s successfully on server, but failed in the local list\n", state->who, state->new_group_name); |
876 purple_debug_info("MSNCL","Contact %s added to group %s successfully on server, but failed in the local list\n", state->who, state->new_group_name); | 988 } |
877 } | 989 |
878 | 990 if (state->action & MSN_ADD_BUDDY) { |
879 if (state->action & MSN_ADD_BUDDY) { | 991 MsnUser *user = msn_userlist_find_user(userlist, state->who); |
880 MsnUser *user = msn_userlist_find_user(userlist, state->who); | 992 |
881 | 993 if ( !msn_user_is_yahoo(state->session->account, state->who) ) { |
882 if ( !msn_user_is_yahoo(state->session->account, state->who) ) { | 994 msn_userlist_add_buddy_to_list(userlist, state->who, MSN_LIST_AL); |
883 | 995 msn_userlist_add_buddy_to_list(userlist, state->who, MSN_LIST_FL); |
884 msn_userlist_add_buddy_to_list(userlist, state->who, MSN_LIST_AL); | 996 } |
885 msn_userlist_add_buddy_to_list(userlist, state->who, MSN_LIST_FL); | 997 msn_notification_send_fqy(state->session, state->who); |
886 } | 998 |
887 msn_notification_send_fqy(state->session, state->who); | 999 if (msn_userlist_user_is_in_list(user, MSN_LIST_PL)) { |
888 | 1000 msn_del_contact_from_list(state->session, NULL, state->who, MSN_LIST_PL); |
889 if (msn_userlist_user_is_in_list(user, MSN_LIST_PL)) { | 1001 return; |
890 msn_del_contact_from_list(state->session, NULL, state->who, MSN_LIST_PL); | 1002 } |
891 msn_callback_state_free(state); | 1003 } |
892 return; | 1004 |
893 } | 1005 if (state->action & MSN_MOVE_BUDDY) { |
894 } | 1006 msn_del_contact_from_group(state->session, state->who, state->old_group_name); |
895 | 1007 } |
896 if (state->action & MSN_MOVE_BUDDY) { | |
897 msn_del_contact_from_group(state->session, state->who, state->old_group_name); | |
898 } | |
899 } | |
900 | |
901 msn_callback_state_free(state); | |
902 } | 1008 } |
903 | 1009 |
904 void | 1010 void |
905 msn_add_contact_to_group(MsnSession *session, MsnCallbackState *state, | 1011 msn_add_contact_to_group(MsnSession *session, MsnCallbackState *state, |
906 const char *passport, const char *groupId) | 1012 const char *passport, const char *groupId) |
926 } | 1032 } |
927 | 1033 |
928 if (state->action & MSN_MOVE_BUDDY) { | 1034 if (state->action & MSN_MOVE_BUDDY) { |
929 msn_user_add_group_id(user, groupId); | 1035 msn_user_add_group_id(user, groupId); |
930 msn_del_contact_from_group(session, passport, state->old_group_name); | 1036 msn_del_contact_from_group(session, passport, state->old_group_name); |
931 } else { | |
932 msn_callback_state_free(state); | |
933 } | 1037 } |
934 | 1038 |
935 return; | 1039 return; |
936 } | 1040 } |
937 | 1041 |
949 contact_xml = g_strdup_printf(MSN_CONTACT_ID_XML, user->uid); | 1053 contact_xml = g_strdup_printf(MSN_CONTACT_ID_XML, user->uid); |
950 } else { | 1054 } else { |
951 contact_xml = g_strdup_printf(MSN_CONTACT_XML, passport); | 1055 contact_xml = g_strdup_printf(MSN_CONTACT_XML, passport); |
952 } | 1056 } |
953 | 1057 |
954 body = g_strdup_printf(MSN_ADD_CONTACT_GROUP_TEMPLATE, | 1058 body = g_strdup_printf(MSN_ADD_CONTACT_GROUP_TEMPLATE, groupId, contact_xml); |
955 msn_nexus_get_token_str(session->nexus, MSN_AUTH_CONTACTS), | 1059 |
956 groupId, contact_xml); | 1060 state->body = xmlnode_from_str(body, -1); |
957 | 1061 state->post_action = MSN_ADD_CONTACT_GROUP_SOAP_ACTION; |
958 msn_soap_message_send(state->session, | 1062 state->post_url = MSN_ADDRESS_BOOK_POST_URL; |
959 msn_soap_message_new(MSN_ADD_CONTACT_GROUP_SOAP_ACTION, | 1063 state->cb = msn_add_contact_to_group_read_cb; |
960 xmlnode_from_str(body, -1)), | 1064 msn_contact_request(state); |
961 MSN_CONTACT_SERVER, MSN_ADDRESS_BOOK_POST_URL, | |
962 msn_add_contact_to_group_read_cb, state); | |
963 | 1065 |
964 g_free(contact_xml); | 1066 g_free(contact_xml); |
965 g_free(body); | 1067 g_free(body); |
966 } | 1068 } |
967 | 1069 |
968 static void | 1070 static void |
969 msn_delete_contact_read_cb(MsnSoapMessage *req, MsnSoapMessage *resp, | 1071 msn_delete_contact_read_cb(MsnSoapMessage *req, MsnSoapMessage *resp, |
970 gpointer data) | 1072 gpointer data) |
971 { | 1073 { |
972 MsnCallbackState *state = data; | 1074 MsnCallbackState *state = data; |
973 | 1075 MsnUserList *userlist = state->session->userlist; |
974 if (resp != NULL) { | 1076 MsnUser *user = msn_userlist_find_user_with_id(userlist, state->uid); |
975 MsnUserList *userlist = state->session->userlist; | 1077 |
976 MsnUser *user = msn_userlist_find_user_with_id(userlist, state->uid); | 1078 purple_debug_info("MSNCL","Delete contact successful\n"); |
977 | 1079 |
978 purple_debug_info("MSNCL","Delete contact successful\n"); | 1080 if (user != NULL) { |
979 | 1081 msn_userlist_remove_user(userlist, user); |
980 if (user != NULL) { | 1082 } |
981 msn_userlist_remove_user(userlist, user); | |
982 } | |
983 } | |
984 | |
985 msn_callback_state_free(state); | |
986 } | 1083 } |
987 | 1084 |
988 /*delete a Contact*/ | 1085 /*delete a Contact*/ |
989 void | 1086 void |
990 msn_delete_contact(MsnSession *session, const char *contactId) | 1087 msn_delete_contact(MsnSession *session, const char *contactId) |
999 state = msn_callback_state_new(session); | 1096 state = msn_callback_state_new(session); |
1000 msn_callback_state_set_uid(state, contactId); | 1097 msn_callback_state_set_uid(state, contactId); |
1001 | 1098 |
1002 /* build SOAP request */ | 1099 /* build SOAP request */ |
1003 purple_debug_info("MSNCL","Deleting contact with contactId: %s\n", contactId); | 1100 purple_debug_info("MSNCL","Deleting contact with contactId: %s\n", contactId); |
1004 body = g_strdup_printf(MSN_DEL_CONTACT_TEMPLATE, | 1101 body = g_strdup_printf(MSN_DEL_CONTACT_TEMPLATE, contact_id_xml); |
1005 msn_nexus_get_token_str(session->nexus, MSN_AUTH_CONTACTS), | 1102 |
1006 contact_id_xml); | 1103 state->body = xmlnode_from_str(body, -1); |
1007 | 1104 state->post_action = MSN_CONTACT_DEL_SOAP_ACTION; |
1008 msn_soap_message_send(session, | 1105 state->post_url = MSN_ADDRESS_BOOK_POST_URL; |
1009 msn_soap_message_new(MSN_CONTACT_DEL_SOAP_ACTION, | 1106 state->cb = msn_delete_contact_read_cb; |
1010 xmlnode_from_str(body, -1)), | 1107 msn_contact_request(state); |
1011 MSN_CONTACT_SERVER, MSN_ADDRESS_BOOK_POST_URL, | |
1012 msn_delete_contact_read_cb, state); | |
1013 | 1108 |
1014 g_free(contact_id_xml); | 1109 g_free(contact_id_xml); |
1015 g_free(body); | 1110 g_free(body); |
1016 } | 1111 } |
1017 | 1112 |
1019 msn_del_contact_from_group_read_cb(MsnSoapMessage *req, MsnSoapMessage *resp, | 1114 msn_del_contact_from_group_read_cb(MsnSoapMessage *req, MsnSoapMessage *resp, |
1020 gpointer data) | 1115 gpointer data) |
1021 { | 1116 { |
1022 MsnCallbackState *state = data; | 1117 MsnCallbackState *state = data; |
1023 | 1118 |
1024 if (resp != NULL) { | 1119 if (msn_userlist_rem_buddy_from_group(state->session->userlist, |
1025 if (msn_userlist_rem_buddy_from_group(state->session->userlist, | 1120 state->who, state->old_group_name)) { |
1026 state->who, state->old_group_name)) { | 1121 purple_debug_info("MSNCL", "Contact %s deleted successfully from group %s\n", state->who, state->old_group_name); |
1027 purple_debug_info("MSNCL", "Contact %s deleted successfully from group %s\n", state->who, state->old_group_name); | 1122 } else { |
1028 } else { | 1123 purple_debug_info("MSNCL", "Contact %s deleted successfully from group %s in the server, but failed in the local list\n", state->who, state->old_group_name); |
1029 purple_debug_info("MSNCL", "Contact %s deleted successfully from group %s in the server, but failed in the local list\n", state->who, state->old_group_name); | 1124 } |
1030 } | |
1031 } | |
1032 | |
1033 msn_callback_state_free(state); | |
1034 } | 1125 } |
1035 | 1126 |
1036 void | 1127 void |
1037 msn_del_contact_from_group(MsnSession *session, const char *passport, const char *group_name) | 1128 msn_del_contact_from_group(MsnSession *session, const char *passport, const char *group_name) |
1038 { | 1129 { |
1072 msn_callback_state_set_who(state, passport); | 1163 msn_callback_state_set_who(state, passport); |
1073 msn_callback_state_set_guid(state, groupId); | 1164 msn_callback_state_set_guid(state, groupId); |
1074 msn_callback_state_set_old_group_name(state, group_name); | 1165 msn_callback_state_set_old_group_name(state, group_name); |
1075 | 1166 |
1076 contact_id_xml = g_strdup_printf(MSN_CONTACT_ID_XML, user->uid); | 1167 contact_id_xml = g_strdup_printf(MSN_CONTACT_ID_XML, user->uid); |
1077 body = g_strdup_printf(MSN_CONTACT_DEL_GROUP_TEMPLATE, | 1168 body = g_strdup_printf(MSN_CONTACT_DEL_GROUP_TEMPLATE, contact_id_xml, groupId); |
1078 msn_nexus_get_token_str(session->nexus, MSN_AUTH_CONTACTS), | 1169 |
1079 contact_id_xml, groupId); | 1170 state->body = xmlnode_from_str(body, -1); |
1080 | 1171 state->post_action = MSN_CONTACT_DEL_GROUP_SOAP_ACTION; |
1081 msn_soap_message_send(session, | 1172 state->post_url = MSN_ADDRESS_BOOK_POST_URL; |
1082 msn_soap_message_new(MSN_CONTACT_DEL_GROUP_SOAP_ACTION, | 1173 state->cb = msn_del_contact_from_group_read_cb; |
1083 xmlnode_from_str(body, -1)), | 1174 msn_contact_request(state); |
1084 MSN_CONTACT_SERVER, MSN_ADDRESS_BOOK_POST_URL, | |
1085 msn_del_contact_from_group_read_cb, state); | |
1086 | 1175 |
1087 g_free(contact_id_xml); | 1176 g_free(contact_id_xml); |
1088 g_free(body); | 1177 g_free(body); |
1089 } | 1178 } |
1090 | 1179 |
1091 | 1180 |
1092 static void | 1181 static void |
1093 msn_update_contact_read_cb(MsnSoapMessage *req, MsnSoapMessage *resp, | 1182 msn_update_contact_read_cb(MsnSoapMessage *req, MsnSoapMessage *resp, |
1094 gpointer data) | 1183 gpointer data) |
1095 { | 1184 { |
1096 if (resp) | 1185 purple_debug_info("MSN CL","Contact updated successfully\n"); |
1097 purple_debug_info("MSN CL","Contact updated successfully\n"); | |
1098 else | |
1099 purple_debug_info("MSN CL","Contact updated successfully\n"); | |
1100 } | 1186 } |
1101 | 1187 |
1102 /* Update a contact's nickname */ | 1188 /* Update a contact's nickname */ |
1103 void | 1189 void |
1104 msn_update_contact(MsnSession *session, const char* nickname) | 1190 msn_update_contact(MsnSession *session, const char* nickname) |
1105 { | 1191 { |
1192 MsnCallbackState *state; | |
1106 gchar *body = NULL, *escaped_nickname; | 1193 gchar *body = NULL, *escaped_nickname; |
1107 | 1194 |
1108 purple_debug_info("MSN CL","Update contact information with new friendly name: %s\n", nickname); | 1195 purple_debug_info("MSN CL","Update contact information with new friendly name: %s\n", nickname); |
1109 | 1196 |
1110 escaped_nickname = g_markup_escape_text(nickname, -1); | 1197 escaped_nickname = g_markup_escape_text(nickname, -1); |
1111 | 1198 |
1112 body = g_strdup_printf(MSN_CONTACT_UPDATE_TEMPLATE, | 1199 body = g_strdup_printf(MSN_CONTACT_UPDATE_TEMPLATE, escaped_nickname); |
1113 msn_nexus_get_token_str(session->nexus, MSN_AUTH_CONTACTS), | 1200 |
1114 escaped_nickname); | 1201 state = msn_callback_state_new(session); |
1115 | 1202 state->body = xmlnode_from_str(body, -1); |
1116 msn_soap_message_send(session, | 1203 state->action = MSN_UPDATE_INFO; |
1117 msn_soap_message_new(MSN_CONTACT_UPDATE_SOAP_ACTION, | 1204 state->post_action = MSN_CONTACT_UPDATE_SOAP_ACTION; |
1118 xmlnode_from_str(body, -1)), | 1205 state->post_url = MSN_ADDRESS_BOOK_POST_URL; |
1119 MSN_CONTACT_SERVER, MSN_ADDRESS_BOOK_POST_URL, | 1206 state->cb = msn_update_contact_read_cb; |
1120 msn_update_contact_read_cb, NULL); | |
1121 | 1207 |
1122 g_free(escaped_nickname); | 1208 g_free(escaped_nickname); |
1123 g_free(body); | 1209 g_free(body); |
1124 } | 1210 } |
1125 | 1211 |
1128 gpointer data) | 1214 gpointer data) |
1129 { | 1215 { |
1130 MsnCallbackState *state = data; | 1216 MsnCallbackState *state = data; |
1131 MsnSession *session = state->session; | 1217 MsnSession *session = state->session; |
1132 | 1218 |
1133 if (resp != NULL) { | 1219 purple_debug_info("MSN CL", "Contact %s deleted successfully from %s list on server!\n", state->who, MsnMemberRole[state->list_id]); |
1134 purple_debug_info("MSN CL", "Contact %s deleted successfully from %s list on server!\n", state->who, MsnMemberRole[state->list_id]); | 1220 |
1135 | 1221 if (state->list_id == MSN_LIST_PL) { |
1136 if (state->list_id == MSN_LIST_PL) { | 1222 MsnUser *user = msn_userlist_find_user(session->userlist, state->who); |
1137 MsnUser *user = msn_userlist_find_user(session->userlist, state->who); | 1223 MsnCallbackState *new_state = msn_callback_state_dup(state); |
1138 | 1224 |
1139 if (user != NULL) | 1225 if (user != NULL) |
1140 msn_user_unset_op(user, MSN_LIST_PL_OP); | 1226 msn_user_unset_op(user, MSN_LIST_PL_OP); |
1141 | 1227 |
1142 msn_add_contact_to_list(session, state, state->who, MSN_LIST_RL); | 1228 msn_add_contact_to_list(session, new_state, state->who, MSN_LIST_RL); |
1143 return; | 1229 return; |
1144 } else if (state->list_id == MSN_LIST_AL) { | 1230 } else if (state->list_id == MSN_LIST_AL) { |
1145 purple_privacy_permit_remove(session->account, state->who, TRUE); | 1231 purple_privacy_permit_remove(session->account, state->who, TRUE); |
1146 msn_add_contact_to_list(session, NULL, state->who, MSN_LIST_BL); | 1232 msn_add_contact_to_list(session, NULL, state->who, MSN_LIST_BL); |
1147 } else if (state->list_id == MSN_LIST_BL) { | 1233 } else if (state->list_id == MSN_LIST_BL) { |
1148 purple_privacy_deny_remove(session->account, state->who, TRUE); | 1234 purple_privacy_deny_remove(session->account, state->who, TRUE); |
1149 msn_add_contact_to_list(session, NULL, state->who, MSN_LIST_AL); | 1235 msn_add_contact_to_list(session, NULL, state->who, MSN_LIST_AL); |
1150 } | 1236 } |
1151 } | 1237 |
1152 | |
1153 msn_callback_state_free(state); | |
1154 } | 1238 } |
1155 | 1239 |
1156 void | 1240 void |
1157 msn_del_contact_from_list(MsnSession *session, MsnCallbackState *state, | 1241 msn_del_contact_from_list(MsnSession *session, MsnCallbackState *state, |
1158 const gchar *passport, const MsnListId list) | 1242 const gchar *passport, const MsnListId list) |
1185 partner_scenario = MSN_PS_BLOCK_UNBLOCK; | 1269 partner_scenario = MSN_PS_BLOCK_UNBLOCK; |
1186 | 1270 |
1187 member = g_strdup_printf(MSN_MEMBER_PASSPORT_XML, passport); | 1271 member = g_strdup_printf(MSN_MEMBER_PASSPORT_XML, passport); |
1188 } | 1272 } |
1189 | 1273 |
1190 body = g_strdup_printf( MSN_CONTACT_DELECT_FROM_LIST_TEMPLATE, | 1274 body = g_strdup_printf(MSN_CONTACT_DELECT_FROM_LIST_TEMPLATE, |
1191 MsnSoapPartnerScenarioText[partner_scenario], | 1275 MsnSoapPartnerScenarioText[partner_scenario], |
1192 msn_nexus_get_token_str(session->nexus, MSN_AUTH_CONTACTS), | |
1193 MsnMemberRole[list], member); | 1276 MsnMemberRole[list], member); |
1194 | 1277 |
1195 msn_soap_message_send(session, | 1278 state->body = xmlnode_from_str(body, -1); |
1196 msn_soap_message_new(MSN_DELETE_MEMBER_FROM_LIST_SOAP_ACTION, | 1279 state->post_action = MSN_DELETE_MEMBER_FROM_LIST_SOAP_ACTION; |
1197 xmlnode_from_str(body, -1)), | 1280 state->post_url = MSN_SHARE_POST_URL; |
1198 MSN_CONTACT_SERVER, MSN_SHARE_POST_URL, | 1281 state->cb = msn_del_contact_from_list_read_cb; |
1199 msn_del_contact_from_list_read_cb, state); | 1282 msn_contact_request(state); |
1200 | 1283 |
1201 g_free(member); | 1284 g_free(member); |
1202 g_free(body); | 1285 g_free(body); |
1203 } | 1286 } |
1204 | 1287 |
1209 MsnCallbackState *state = data; | 1292 MsnCallbackState *state = data; |
1210 | 1293 |
1211 g_return_if_fail(state != NULL); | 1294 g_return_if_fail(state != NULL); |
1212 g_return_if_fail(state->session != NULL); | 1295 g_return_if_fail(state->session != NULL); |
1213 | 1296 |
1214 if (resp != NULL) { | 1297 purple_debug_info("MSN CL", "Contact %s added successfully to %s list on server!\n", state->who, MsnMemberRole[state->list_id]); |
1215 purple_debug_info("MSN CL", "Contact %s added successfully to %s list on server!\n", state->who, MsnMemberRole[state->list_id]); | 1298 |
1216 | 1299 if (state->list_id == MSN_LIST_RL) { |
1217 if (state->list_id == MSN_LIST_RL) { | 1300 MsnUser *user = msn_userlist_find_user(state->session->userlist, state->who); |
1218 MsnUser *user = msn_userlist_find_user(state->session->userlist, state->who); | 1301 |
1219 | 1302 if (user != NULL) { |
1220 if (user != NULL) { | 1303 msn_user_set_op(user, MSN_LIST_RL_OP); |
1221 msn_user_set_op(user, MSN_LIST_RL_OP); | 1304 } |
1222 } | 1305 |
1223 | 1306 if (state->action & MSN_DENIED_BUDDY) { |
1224 if (state->action & MSN_DENIED_BUDDY) { | 1307 msn_add_contact_to_list(state->session, NULL, state->who, MSN_LIST_BL); |
1225 | 1308 } else if (state->list_id == MSN_LIST_AL) { |
1226 msn_add_contact_to_list(state->session, NULL, state->who, MSN_LIST_BL); | 1309 purple_privacy_permit_add(state->session->account, state->who, TRUE); |
1227 } else if (state->list_id == MSN_LIST_AL) { | 1310 } else if (state->list_id == MSN_LIST_BL) { |
1228 purple_privacy_permit_add(state->session->account, state->who, TRUE); | 1311 purple_privacy_deny_add(state->session->account, state->who, TRUE); |
1229 } else if (state->list_id == MSN_LIST_BL) { | 1312 } |
1230 purple_privacy_deny_add(state->session->account, state->who, TRUE); | 1313 } |
1231 } | |
1232 } | |
1233 } | |
1234 | |
1235 msn_callback_state_free(state); | |
1236 } | 1314 } |
1237 | 1315 |
1238 void | 1316 void |
1239 msn_add_contact_to_list(MsnSession *session, MsnCallbackState *state, | 1317 msn_add_contact_to_list(MsnSession *session, MsnCallbackState *state, |
1240 const gchar *passport, const MsnListId list) | 1318 const gchar *passport, const MsnListId list) |
1258 | 1336 |
1259 member = g_strdup_printf(MSN_MEMBER_PASSPORT_XML, state->who); | 1337 member = g_strdup_printf(MSN_MEMBER_PASSPORT_XML, state->who); |
1260 | 1338 |
1261 body = g_strdup_printf(MSN_CONTACT_ADD_TO_LIST_TEMPLATE, | 1339 body = g_strdup_printf(MSN_CONTACT_ADD_TO_LIST_TEMPLATE, |
1262 MsnSoapPartnerScenarioText[partner_scenario], | 1340 MsnSoapPartnerScenarioText[partner_scenario], |
1263 msn_nexus_get_token_str(session->nexus, MSN_AUTH_CONTACTS), | |
1264 MsnMemberRole[list], member); | 1341 MsnMemberRole[list], member); |
1265 | 1342 |
1266 msn_soap_message_send(session, | 1343 state->body = xmlnode_from_str(body, -1); |
1267 msn_soap_message_new(MSN_ADD_MEMBER_TO_LIST_SOAP_ACTION, | 1344 state->post_action = MSN_ADD_MEMBER_TO_LIST_SOAP_ACTION; |
1268 xmlnode_from_str(body, -1)), | 1345 state->post_url = MSN_SHARE_POST_URL; |
1269 MSN_CONTACT_SERVER, MSN_SHARE_POST_URL, | 1346 state->cb = msn_add_contact_to_list_read_cb; |
1270 msn_add_contact_to_list_read_cb, state); | 1347 msn_contact_request(state); |
1271 | 1348 |
1272 g_free(member); | 1349 g_free(member); |
1273 g_free(body); | 1350 g_free(body); |
1274 } | 1351 } |
1275 | 1352 |
1276 #if 0 | 1353 #if 0 |
1277 static void | 1354 static void |
1278 msn_gleams_read_cb(MsnSoapMessage *req, MsnSoapMessage *resp, gpointer data) | 1355 msn_gleams_read_cb(MsnSoapMessage *req, MsnSoapMessage *resp, gpointer data) |
1279 { | 1356 { |
1280 if (resp != NULL) | 1357 purple_debug_info("MSNP14","Gleams read done\n"); |
1281 purple_debug_info("MSNP14","Gleams read done\n"); | |
1282 else | |
1283 purple_debug_info("MSNP14","Gleams read failed\n"); | |
1284 } | 1358 } |
1285 | 1359 |
1286 /*get the gleams info*/ | 1360 /*get the gleams info*/ |
1287 void | 1361 void |
1288 msn_get_gleams(MsnSession *session) | 1362 msn_get_gleams(MsnSession *session) |
1289 { | 1363 { |
1290 MsnSoapReq *soap_request; | 1364 MsnSoapReq *soap_request; |
1291 gchar *body = NULL; | |
1292 | 1365 |
1293 purple_debug_info("MSNP14","msn get gleams info...\n"); | 1366 purple_debug_info("MSNP14","msn get gleams info...\n"); |
1294 | 1367 |
1295 body = g_strdup_printf(MSN_GLEAMS_TEMPLATE, | 1368 state = msn_callback_state_new(session); |
1296 msn_nexus_get_token_str(session->nexus, MSN_AUTH_CONTACTS)); | 1369 state->body = xmlnode_from_str(MSN_GLEAMS_TEMPLATE, -1); |
1297 | 1370 state->post_action = MSN_GET_GLEAMS_SOAP_ACTION; |
1298 msn_soap_message_send(session, | 1371 state->post_url = MSN_ADDRESS_BOOK_POST_URL; |
1299 msn_soap_message_new(MSN_GET_GLEAMS_SOAP_ACTION, | 1372 state->cb = msn_gleams_read_cb; |
1300 xmlnode_from_str(body, -1)), | 1373 msn_contact_request(state); |
1301 MSN_CONTACT_SERVER, MSN_ADDRESS_BOOK_POST_URL, | |
1302 msn_gleams_read_cb, NULL); | |
1303 g_free(body); | |
1304 } | 1374 } |
1305 #endif | 1375 #endif |
1306 | 1376 |
1307 | 1377 |
1308 /*************************************************************** | 1378 /*************************************************************** |
1311 | 1381 |
1312 static void | 1382 static void |
1313 msn_group_read_cb(MsnSoapMessage *req, MsnSoapMessage *resp, gpointer data) | 1383 msn_group_read_cb(MsnSoapMessage *req, MsnSoapMessage *resp, gpointer data) |
1314 { | 1384 { |
1315 MsnCallbackState *state = data; | 1385 MsnCallbackState *state = data; |
1386 MsnSession *session; | |
1387 MsnUserList *userlist; | |
1316 | 1388 |
1317 purple_debug_info("MSNCL", "Group request successful.\n"); | 1389 purple_debug_info("MSNCL", "Group request successful.\n"); |
1318 | 1390 |
1319 g_return_if_fail(state->session != NULL); | 1391 g_return_if_fail(state->session != NULL); |
1320 g_return_if_fail(state->session->userlist != NULL); | 1392 g_return_if_fail(state->session->userlist != NULL); |
1321 | 1393 |
1322 if (resp == NULL) { | 1394 session = state->session; |
1323 msn_callback_state_free(state); | 1395 userlist = session->userlist; |
1324 return; | 1396 |
1325 } | 1397 if (state->action & MSN_RENAME_GROUP) { |
1326 | 1398 msn_userlist_rename_group_id(session->userlist, |
1327 if (state) { | 1399 state->guid, |
1328 MsnSession *session = state->session; | 1400 state->new_group_name); |
1329 MsnUserList *userlist = session->userlist; | 1401 } |
1330 | 1402 |
1331 if (state->action & MSN_RENAME_GROUP) { | 1403 if (state->action & MSN_ADD_GROUP) { |
1332 msn_userlist_rename_group_id(session->userlist, | 1404 /* the response is taken from |
1333 state->guid, | 1405 http://telepathy.freedesktop.org/wiki/Pymsn/MSNP/ContactListActions |
1334 state->new_group_name); | 1406 should copy it to msnpiki some day */ |
1335 } | 1407 xmlnode *guid_node = xmlnode_get_child(resp->xml, |
1336 | 1408 "Body/ABGroupAddResponse/ABGroupAddResult/guid"); |
1337 if (state->action & MSN_ADD_GROUP) { | 1409 |
1338 /* the response is taken from | 1410 if (guid_node) { |
1339 http://telepathy.freedesktop.org/wiki/Pymsn/MSNP/ContactListActions | 1411 char *guid = xmlnode_get_data(guid_node); |
1340 should copy it to msnpiki some day */ | 1412 |
1341 xmlnode *guid_node = xmlnode_get_child(resp->xml, | 1413 /* create and add the new group to the userlist */ |
1342 "Body/ABGroupAddResponse/ABGroupAddResult/guid"); | 1414 purple_debug_info("MSNCL", "Adding group %s with guid = %s to the userlist\n", state->new_group_name, guid); |
1343 | 1415 msn_group_new(session->userlist, guid, state->new_group_name); |
1344 if (guid_node) { | 1416 |
1345 char *guid = xmlnode_get_data(guid_node); | 1417 if (state->action & MSN_ADD_BUDDY) { |
1346 | 1418 msn_userlist_add_buddy(session->userlist, |
1347 /* create and add the new group to the userlist */ | 1419 state->who, |
1348 purple_debug_info("MSNCL", "Adding group %s with guid = %s to the userlist\n", state->new_group_name, guid); | 1420 state->new_group_name); |
1349 msn_group_new(session->userlist, guid, state->new_group_name); | 1421 } else if (state->action & MSN_MOVE_BUDDY) { |
1350 | 1422 /* This will be freed when the add contact callback fires */ |
1351 if (state->action & MSN_ADD_BUDDY) { | 1423 MsnCallbackState *new_state = msn_callback_state_dup(state); |
1352 msn_userlist_add_buddy(session->userlist, | 1424 msn_add_contact_to_group(session, new_state, state->who, guid); |
1353 state->who, | |
1354 state->new_group_name); | |
1355 } else if (state->action & MSN_MOVE_BUDDY) { | |
1356 msn_add_contact_to_group(session, state, state->who, guid); | |
1357 g_free(guid); | |
1358 return; | |
1359 } | |
1360 g_free(guid); | 1425 g_free(guid); |
1361 } else { | 1426 return; |
1362 purple_debug_info("MSNCL", "Adding group %s failed\n", | |
1363 state->new_group_name); | |
1364 } | 1427 } |
1365 } | 1428 g_free(guid); |
1366 | 1429 } else { |
1367 if (state->action & MSN_DEL_GROUP) { | 1430 purple_debug_info("MSNCL", "Adding group %s failed\n", |
1368 GList *l; | 1431 state->new_group_name); |
1369 | 1432 } |
1370 msn_userlist_remove_group_id(session->userlist, state->guid); | 1433 } |
1371 for (l = userlist->users; l != NULL; l = l->next) { | 1434 |
1372 msn_user_remove_group_id( (MsnUser *)l->data, state->guid); | 1435 if (state->action & MSN_DEL_GROUP) { |
1373 } | 1436 GList *l; |
1374 } | 1437 |
1375 | 1438 msn_userlist_remove_group_id(session->userlist, state->guid); |
1376 msn_callback_state_free(state); | 1439 for (l = userlist->users; l != NULL; l = l->next) { |
1440 msn_user_remove_group_id( (MsnUser *)l->data, state->guid); | |
1441 } | |
1377 } | 1442 } |
1378 } | 1443 } |
1379 | 1444 |
1380 /* add group */ | 1445 /* add group */ |
1381 void | 1446 void |
1398 | 1463 |
1399 /* escape group name's html special chars so it can safely be sent | 1464 /* escape group name's html special chars so it can safely be sent |
1400 * in a XML SOAP request | 1465 * in a XML SOAP request |
1401 */ | 1466 */ |
1402 escaped_group_name = g_markup_escape_text(group_name, -1); | 1467 escaped_group_name = g_markup_escape_text(group_name, -1); |
1403 body = g_strdup_printf(MSN_GROUP_ADD_TEMPLATE, | 1468 body = g_strdup_printf(MSN_GROUP_ADD_TEMPLATE, escaped_group_name); |
1404 msn_nexus_get_token_str(session->nexus, MSN_AUTH_CONTACTS), | 1469 |
1405 escaped_group_name); | 1470 state->body = xmlnode_from_str(body, -1); |
1406 | 1471 state->post_action = MSN_GROUP_ADD_SOAP_ACTION; |
1407 msn_soap_message_send(session, | 1472 state->post_url = MSN_ADDRESS_BOOK_POST_URL; |
1408 msn_soap_message_new(MSN_GROUP_ADD_SOAP_ACTION, | 1473 state->cb = msn_group_read_cb; |
1409 xmlnode_from_str(body, -1)), | 1474 msn_contact_request(state); |
1410 MSN_CONTACT_SERVER, MSN_ADDRESS_BOOK_POST_URL, | |
1411 msn_group_read_cb, state); | |
1412 | 1475 |
1413 g_free(escaped_group_name); | 1476 g_free(escaped_group_name); |
1414 g_free(body); | 1477 g_free(body); |
1415 } | 1478 } |
1416 | 1479 |
1444 | 1507 |
1445 state = msn_callback_state_new(session); | 1508 state = msn_callback_state_new(session); |
1446 msn_callback_state_set_action(state, MSN_DEL_GROUP); | 1509 msn_callback_state_set_action(state, MSN_DEL_GROUP); |
1447 msn_callback_state_set_guid(state, guid); | 1510 msn_callback_state_set_guid(state, guid); |
1448 | 1511 |
1449 body = g_strdup_printf(MSN_GROUP_DEL_TEMPLATE, | 1512 body = g_strdup_printf(MSN_GROUP_DEL_TEMPLATE, guid); |
1450 msn_nexus_get_token_str(session->nexus, MSN_AUTH_CONTACTS), | 1513 |
1451 guid); | 1514 state->body = xmlnode_from_str(body, -1); |
1452 | 1515 state->post_action = MSN_GROUP_DEL_SOAP_ACTION; |
1453 msn_soap_message_send(session, | 1516 state->post_url = MSN_ADDRESS_BOOK_POST_URL; |
1454 msn_soap_message_new(MSN_GROUP_DEL_SOAP_ACTION, | 1517 state->cb = msn_group_read_cb; |
1455 xmlnode_from_str(body, -1)), | 1518 msn_contact_request(state); |
1456 MSN_CONTACT_SERVER, MSN_ADDRESS_BOOK_POST_URL, | |
1457 msn_group_read_cb, state); | |
1458 | 1519 |
1459 g_free(body); | 1520 g_free(body); |
1460 } | 1521 } |
1461 | 1522 |
1462 /* rename group */ | 1523 /* rename group */ |
1482 state = msn_callback_state_new(session); | 1543 state = msn_callback_state_new(session); |
1483 msn_callback_state_set_guid(state, guid); | 1544 msn_callback_state_set_guid(state, guid); |
1484 msn_callback_state_set_new_group_name(state, new_group_name); | 1545 msn_callback_state_set_new_group_name(state, new_group_name); |
1485 | 1546 |
1486 if ( !strcmp(guid, MSN_INDIVIDUALS_GROUP_ID) || !strcmp(guid, MSN_NON_IM_GROUP_ID) ) { | 1547 if ( !strcmp(guid, MSN_INDIVIDUALS_GROUP_ID) || !strcmp(guid, MSN_NON_IM_GROUP_ID) ) { |
1487 msn_add_group(session, state, new_group_name); | 1548 MsnCallbackState *new_state = msn_callback_state_dup(state); |
1549 msn_add_group(session, new_state, new_group_name); | |
1488 // XXX move every buddy there (we probably need to fix concurrent SOAP reqs first) | 1550 // XXX move every buddy there (we probably need to fix concurrent SOAP reqs first) |
1489 } | 1551 } |
1490 | 1552 |
1491 msn_callback_state_set_action(state, MSN_RENAME_GROUP); | 1553 msn_callback_state_set_action(state, MSN_RENAME_GROUP); |
1492 | 1554 |
1493 escaped_group_name = g_markup_escape_text(new_group_name, -1); | 1555 escaped_group_name = g_markup_escape_text(new_group_name, -1); |
1494 body = g_strdup_printf(MSN_GROUP_RENAME_TEMPLATE, | 1556 body = g_strdup_printf(MSN_GROUP_RENAME_TEMPLATE, guid, escaped_group_name); |
1495 msn_nexus_get_token_str(session->nexus, MSN_AUTH_CONTACTS), | 1557 |
1496 guid, escaped_group_name); | 1558 state->body = xmlnode_from_str(body, -1); |
1497 | 1559 state->post_action = MSN_GROUP_RENAME_SOAP_ACTION; |
1498 msn_soap_message_send(session, | 1560 state->post_url = MSN_ADDRESS_BOOK_POST_URL; |
1499 msn_soap_message_new(MSN_GROUP_RENAME_SOAP_ACTION, | 1561 state->cb = msn_group_read_cb; |
1500 xmlnode_from_str(body, -1)), | 1562 msn_contact_request(state); |
1501 MSN_CONTACT_SERVER, MSN_ADDRESS_BOOK_POST_URL, | |
1502 msn_group_read_cb, state); | |
1503 | 1563 |
1504 g_free(escaped_group_name); | 1564 g_free(escaped_group_name); |
1505 g_free(body); | 1565 g_free(body); |
1506 } | 1566 } |