Mercurial > pidgin.yaz
comparison libpurple/protocols/msn/contact.c @ 23490:b70f30dd4753
Patch 3 from Qulogic, this one updates contact list actions to use ticket
tokens
committer: Ka-Hing Cheung <khc@hxbc.us>
author | Elliott Sales de Andrade <qulogic@pidgin.im> |
---|---|
date | Wed, 26 Dec 2007 00:34:50 +0000 |
parents | 068b412ba385 |
children | f1f5efd679a4 |
comparison
equal
deleted
inserted
replaced
23489:25899ec348a4 | 23490:b70f30dd4753 |
---|---|
27 #include "msn.h" | 27 #include "msn.h" |
28 #include "contact.h" | 28 #include "contact.h" |
29 #include "xmlnode.h" | 29 #include "xmlnode.h" |
30 #include "group.h" | 30 #include "group.h" |
31 #include "soap2.h" | 31 #include "soap2.h" |
32 #include "nexus.h" | |
32 | 33 |
33 const char *MsnSoapPartnerScenarioText[] = | 34 const char *MsnSoapPartnerScenarioText[] = |
34 { | 35 { |
35 "Initial", | 36 "Initial", |
36 "ContactSave", | 37 "ContactSave", |
204 } | 205 } |
205 | 206 |
206 return MSN_USER_TYPE_UNKNOWN; | 207 return MSN_USER_TYPE_UNKNOWN; |
207 } | 208 } |
208 | 209 |
210 /* Get a ticket token that's correctly formatted */ | |
211 static const char * | |
212 msn_contact_get_token(MsnContact *contact) | |
213 { | |
214 GHashTable *token; | |
215 char *msn_t; | |
216 char *msn_p; | |
217 static char token_str[BUF_LEN]; | |
218 | |
219 token = msn_nexus_get_token(contact->session->nexus, MSN_AUTH_CONTACTS); | |
220 msn_t = g_hash_table_lookup(token, "t"); | |
221 msn_p = g_hash_table_lookup(token, "p"); | |
222 | |
223 g_sprintf(token_str, "t=%s&p=%s", msn_t, msn_p); | |
224 | |
225 g_hash_table_unref(token); | |
226 | |
227 return token_str; | |
228 } | |
229 | |
209 /* Create the AddressBook in the server, if we don't have one */ | 230 /* Create the AddressBook in the server, if we don't have one */ |
210 static void | 231 static void |
211 msn_create_address_cb(MsnSoapMessage *req, MsnSoapMessage *resp, gpointer data) | 232 msn_create_address_cb(MsnSoapMessage *req, MsnSoapMessage *resp, gpointer data) |
212 { | 233 { |
213 if (resp && msn_soap_xml_get(resp->xml, "Body/Fault") == NULL) { | 234 if (resp && msn_soap_xml_get(resp->xml, "Body/Fault") == NULL) { |
228 g_return_if_fail(contact->session->user != NULL); | 249 g_return_if_fail(contact->session->user != NULL); |
229 g_return_if_fail(contact->session->user->passport != NULL); | 250 g_return_if_fail(contact->session->user->passport != NULL); |
230 | 251 |
231 purple_debug_info("msnab","Creating an Address Book.\n"); | 252 purple_debug_info("msnab","Creating an Address Book.\n"); |
232 | 253 |
233 body = g_strdup_printf(MSN_ADD_ADDRESSBOOK_TEMPLATE, contact->session->user->passport); | 254 body = g_strdup_printf(MSN_ADD_ADDRESSBOOK_TEMPLATE, |
255 msn_contact_get_token(contact), | |
256 contact->session->user->passport); | |
234 | 257 |
235 msn_soap_message_send(contact->session, | 258 msn_soap_message_send(contact->session, |
236 msn_soap_message_new(MSN_ADD_ADDRESSBOOK_SOAP_ACTION, | 259 msn_soap_message_new(MSN_ADD_ADDRESSBOOK_SOAP_ACTION, |
237 xmlnode_from_str(body, -1)), | 260 xmlnode_from_str(body, -1)), |
238 MSN_CONTACT_SERVER, MSN_ADDRESS_BOOK_POST_URL, msn_create_address_cb, | 261 MSN_CONTACT_SERVER, MSN_ADDRESS_BOOK_POST_URL, msn_create_address_cb, |
414 if ( update_time != NULL ) { | 437 if ( update_time != NULL ) { |
415 purple_debug_info("MSNCL","Last update time: %s\n",update_time); | 438 purple_debug_info("MSNCL","Last update time: %s\n",update_time); |
416 update_str = g_strdup_printf(MSN_GET_CONTACT_UPDATE_XML,update_time); | 439 update_str = g_strdup_printf(MSN_GET_CONTACT_UPDATE_XML,update_time); |
417 } | 440 } |
418 | 441 |
419 body = g_strdup_printf(MSN_GET_CONTACT_TEMPLATE, partner_scenario_str, update_str ? update_str : ""); | 442 body = g_strdup_printf(MSN_GET_CONTACT_TEMPLATE, partner_scenario_str, |
443 msn_contact_get_token(contact), | |
444 update_str ? update_str : ""); | |
420 | 445 |
421 msn_soap_message_send(contact->session, | 446 msn_soap_message_send(contact->session, |
422 msn_soap_message_new(MSN_GET_CONTACT_SOAP_ACTION, | 447 msn_soap_message_new(MSN_GET_CONTACT_SOAP_ACTION, |
423 xmlnode_from_str(body, -1)), | 448 xmlnode_from_str(body, -1)), |
424 MSN_CONTACT_SERVER, MSN_GET_CONTACT_POST_URL, | 449 MSN_CONTACT_SERVER, MSN_GET_CONTACT_POST_URL, |
727 if (dynamicItemLastChange != NULL) | 752 if (dynamicItemLastChange != NULL) |
728 update_str = g_strdup_printf(MSN_GET_ADDRESS_UPDATE_XML, dynamicItemLastChange); | 753 update_str = g_strdup_printf(MSN_GET_ADDRESS_UPDATE_XML, dynamicItemLastChange); |
729 else if (LastChanged != NULL) | 754 else if (LastChanged != NULL) |
730 update_str = g_strdup_printf(MSN_GET_ADDRESS_UPDATE_XML, LastChanged); | 755 update_str = g_strdup_printf(MSN_GET_ADDRESS_UPDATE_XML, LastChanged); |
731 | 756 |
732 body = g_strdup_printf(MSN_GET_ADDRESS_TEMPLATE, MsnSoapPartnerScenarioText[partner_scenario], update_str ? update_str : ""); | 757 body = g_strdup_printf(MSN_GET_ADDRESS_TEMPLATE, |
758 MsnSoapPartnerScenarioText[partner_scenario], | |
759 msn_contact_get_token(contact), | |
760 update_str ? update_str : ""); | |
733 | 761 |
734 msn_soap_message_send(contact->session, | 762 msn_soap_message_send(contact->session, |
735 msn_soap_message_new(MSN_GET_ADDRESS_SOAP_ACTION, | 763 msn_soap_message_new(MSN_GET_ADDRESS_SOAP_ACTION, |
736 xmlnode_from_str(body, -1)), | 764 xmlnode_from_str(body, -1)), |
737 MSN_CONTACT_SERVER, MSN_ADDRESS_BOOK_POST_URL, msn_get_address_cb, | 765 MSN_CONTACT_SERVER, MSN_ADDRESS_BOOK_POST_URL, msn_get_address_cb, |
792 #endif | 820 #endif |
793 | 821 |
794 purple_debug_info("MSNCL","Adding contact %s to contact list\n", passport); | 822 purple_debug_info("MSNCL","Adding contact %s to contact list\n", passport); |
795 | 823 |
796 contact_xml = g_strdup_printf(MSN_CONTACT_XML, passport); | 824 contact_xml = g_strdup_printf(MSN_CONTACT_XML, passport); |
797 body = g_strdup_printf(MSN_ADD_CONTACT_TEMPLATE, contact_xml); | 825 body = g_strdup_printf(MSN_ADD_CONTACT_TEMPLATE, |
826 msn_contact_get_token(contact), | |
827 contact_xml); | |
798 | 828 |
799 msn_soap_message_send(contact->session, | 829 msn_soap_message_send(contact->session, |
800 msn_soap_message_new(MSN_CONTACT_ADD_SOAP_ACTION, | 830 msn_soap_message_new(MSN_CONTACT_ADD_SOAP_ACTION, |
801 xmlnode_from_str(body, -1)), | 831 xmlnode_from_str(body, -1)), |
802 MSN_CONTACT_SERVER, MSN_ADDRESS_BOOK_POST_URL, | 832 MSN_CONTACT_SERVER, MSN_ADDRESS_BOOK_POST_URL, |
900 contact_xml = g_strdup_printf(MSN_CONTACT_ID_XML, user->uid); | 930 contact_xml = g_strdup_printf(MSN_CONTACT_ID_XML, user->uid); |
901 } else { | 931 } else { |
902 contact_xml = g_strdup_printf(MSN_CONTACT_XML, passport); | 932 contact_xml = g_strdup_printf(MSN_CONTACT_XML, passport); |
903 } | 933 } |
904 | 934 |
905 body = g_strdup_printf(MSN_ADD_CONTACT_GROUP_TEMPLATE, groupId, contact_xml); | 935 body = g_strdup_printf(MSN_ADD_CONTACT_GROUP_TEMPLATE, |
936 msn_contact_get_token(contact), | |
937 groupId, | |
938 contact_xml); | |
906 | 939 |
907 msn_soap_message_send(state->session, | 940 msn_soap_message_send(state->session, |
908 msn_soap_message_new(MSN_ADD_CONTACT_GROUP_SOAP_ACTION, | 941 msn_soap_message_new(MSN_ADD_CONTACT_GROUP_SOAP_ACTION, |
909 xmlnode_from_str(body, -1)), | 942 xmlnode_from_str(body, -1)), |
910 MSN_CONTACT_SERVER, MSN_ADDRESS_BOOK_POST_URL, | 943 MSN_CONTACT_SERVER, MSN_ADDRESS_BOOK_POST_URL, |
948 state = msn_callback_state_new(contact->session); | 981 state = msn_callback_state_new(contact->session); |
949 msn_callback_state_set_uid(state, contactId); | 982 msn_callback_state_set_uid(state, contactId); |
950 | 983 |
951 /* build SOAP request */ | 984 /* build SOAP request */ |
952 purple_debug_info("MSNCL","Deleting contact with contactId: %s\n", contactId); | 985 purple_debug_info("MSNCL","Deleting contact with contactId: %s\n", contactId); |
953 body = g_strdup_printf(MSN_DEL_CONTACT_TEMPLATE, contact_id_xml); | 986 body = g_strdup_printf(MSN_DEL_CONTACT_TEMPLATE, |
987 msn_contact_get_token(contact), | |
988 contact_id_xml); | |
954 msn_soap_message_send(contact->session, | 989 msn_soap_message_send(contact->session, |
955 msn_soap_message_new(MSN_CONTACT_DEL_SOAP_ACTION, | 990 msn_soap_message_new(MSN_CONTACT_DEL_SOAP_ACTION, |
956 xmlnode_from_str(body, -1)), | 991 xmlnode_from_str(body, -1)), |
957 MSN_CONTACT_SERVER, MSN_ADDRESS_BOOK_POST_URL, | 992 MSN_CONTACT_SERVER, MSN_ADDRESS_BOOK_POST_URL, |
958 msn_delete_contact_read_cb, state); | 993 msn_delete_contact_read_cb, state); |
1020 msn_callback_state_set_who(state, passport); | 1055 msn_callback_state_set_who(state, passport); |
1021 msn_callback_state_set_guid(state, groupId); | 1056 msn_callback_state_set_guid(state, groupId); |
1022 msn_callback_state_set_old_group_name(state, group_name); | 1057 msn_callback_state_set_old_group_name(state, group_name); |
1023 | 1058 |
1024 contact_id_xml = g_strdup_printf(MSN_CONTACT_ID_XML, user->uid); | 1059 contact_id_xml = g_strdup_printf(MSN_CONTACT_ID_XML, user->uid); |
1025 body = g_strdup_printf(MSN_CONTACT_DEL_GROUP_TEMPLATE, contact_id_xml, groupId); | 1060 body = g_strdup_printf(MSN_CONTACT_DEL_GROUP_TEMPLATE, |
1061 msn_contact_get_token(contact), | |
1062 contact_id_xml, | |
1063 groupId); | |
1026 | 1064 |
1027 msn_soap_message_send(contact->session, | 1065 msn_soap_message_send(contact->session, |
1028 msn_soap_message_new(MSN_CONTACT_DEL_GROUP_SOAP_ACTION, | 1066 msn_soap_message_new(MSN_CONTACT_DEL_GROUP_SOAP_ACTION, |
1029 xmlnode_from_str(body, -1)), | 1067 xmlnode_from_str(body, -1)), |
1030 MSN_CONTACT_SERVER, MSN_ADDRESS_BOOK_POST_URL, | 1068 MSN_CONTACT_SERVER, MSN_ADDRESS_BOOK_POST_URL, |
1053 | 1091 |
1054 purple_debug_info("MSN CL","Update contact information with new friendly name: %s\n", nickname); | 1092 purple_debug_info("MSN CL","Update contact information with new friendly name: %s\n", nickname); |
1055 | 1093 |
1056 escaped_nickname = g_markup_escape_text(nickname, -1); | 1094 escaped_nickname = g_markup_escape_text(nickname, -1); |
1057 | 1095 |
1058 body = g_strdup_printf(MSN_CONTACT_UPDATE_TEMPLATE, escaped_nickname); | 1096 body = g_strdup_printf(MSN_CONTACT_UPDATE_TEMPLATE, |
1097 msn_contact_get_token(contact), | |
1098 escaped_nickname); | |
1059 | 1099 |
1060 msn_soap_message_send(contact->session, | 1100 msn_soap_message_send(contact->session, |
1061 msn_soap_message_new(MSN_CONTACT_UPDATE_SOAP_ACTION, | 1101 msn_soap_message_new(MSN_CONTACT_UPDATE_SOAP_ACTION, |
1062 xmlnode_from_str(body, -1)), | 1102 xmlnode_from_str(body, -1)), |
1063 MSN_CONTACT_SERVER, MSN_ADDRESS_BOOK_POST_URL, | 1103 MSN_CONTACT_SERVER, MSN_ADDRESS_BOOK_POST_URL, |
1132 member = g_strdup_printf(MSN_MEMBER_PASSPORT_XML, passport); | 1172 member = g_strdup_printf(MSN_MEMBER_PASSPORT_XML, passport); |
1133 } | 1173 } |
1134 | 1174 |
1135 body = g_strdup_printf( MSN_CONTACT_DELECT_FROM_LIST_TEMPLATE, | 1175 body = g_strdup_printf( MSN_CONTACT_DELECT_FROM_LIST_TEMPLATE, |
1136 MsnSoapPartnerScenarioText[partner_scenario], | 1176 MsnSoapPartnerScenarioText[partner_scenario], |
1177 msn_contact_get_token(contact), | |
1137 MsnMemberRole[list], | 1178 MsnMemberRole[list], |
1138 member); | 1179 member); |
1139 | 1180 |
1140 msn_soap_message_send(contact->session, | 1181 msn_soap_message_send(contact->session, |
1141 msn_soap_message_new(MSN_DELETE_MEMBER_FROM_LIST_SOAP_ACTION, | 1182 msn_soap_message_new(MSN_DELETE_MEMBER_FROM_LIST_SOAP_ACTION, |
1204 | 1245 |
1205 member = g_strdup_printf(MSN_MEMBER_PASSPORT_XML, state->who); | 1246 member = g_strdup_printf(MSN_MEMBER_PASSPORT_XML, state->who); |
1206 | 1247 |
1207 body = g_strdup_printf(MSN_CONTACT_ADD_TO_LIST_TEMPLATE, | 1248 body = g_strdup_printf(MSN_CONTACT_ADD_TO_LIST_TEMPLATE, |
1208 MsnSoapPartnerScenarioText[partner_scenario], | 1249 MsnSoapPartnerScenarioText[partner_scenario], |
1250 msn_contact_get_token(contact), | |
1209 MsnMemberRole[list], | 1251 MsnMemberRole[list], |
1210 member); | 1252 member); |
1211 | 1253 |
1212 msn_soap_message_send(contact->session, | 1254 msn_soap_message_send(contact->session, |
1213 msn_soap_message_new(MSN_ADD_MEMBER_TO_LIST_SOAP_ACTION, | 1255 msn_soap_message_new(MSN_ADD_MEMBER_TO_LIST_SOAP_ACTION, |
1232 /*get the gleams info*/ | 1274 /*get the gleams info*/ |
1233 void | 1275 void |
1234 msn_get_gleams(MsnContact *contact) | 1276 msn_get_gleams(MsnContact *contact) |
1235 { | 1277 { |
1236 MsnSoapReq *soap_request; | 1278 MsnSoapReq *soap_request; |
1279 gchar *body = NULL; | |
1237 | 1280 |
1238 purple_debug_info("MSNP14","msn get gleams info...\n"); | 1281 purple_debug_info("MSNP14","msn get gleams info...\n"); |
1282 | |
1283 body = g_strdup_printf(MSN_GLEAMS_TEMPLATE, | |
1284 msn_contact_get_token(contact)) | |
1239 msn_soap_message_send(contact->session, | 1285 msn_soap_message_send(contact->session, |
1240 msn_soap_message_new(MSN_GET_GLEAMS_SOAP_ACTION, | 1286 msn_soap_message_new(MSN_GET_GLEAMS_SOAP_ACTION, |
1241 xmlnode_from_str(MSN_GLEAMS_TEMPLATE, -1)), | 1287 xmlnode_from_str(body, -1)), |
1242 MSN_CONTACT_SERVER, MSN_ADDRESS_BOOK_POST_URL, | 1288 MSN_CONTACT_SERVER, MSN_ADDRESS_BOOK_POST_URL, |
1243 msn_gleams_read_cb, NULL); | 1289 msn_gleams_read_cb, NULL); |
1290 g_free(body); | |
1244 } | 1291 } |
1245 #endif | 1292 #endif |
1246 | 1293 |
1247 | 1294 |
1248 /*************************************************************** | 1295 /*************************************************************** |
1337 msn_callback_state_set_new_group_name(state, group_name); | 1384 msn_callback_state_set_new_group_name(state, group_name); |
1338 | 1385 |
1339 /* escape group name's html special chars so it can safely be sent | 1386 /* escape group name's html special chars so it can safely be sent |
1340 * in a XML SOAP request | 1387 * in a XML SOAP request |
1341 */ | 1388 */ |
1342 body = g_markup_printf_escaped(MSN_GROUP_ADD_TEMPLATE, group_name); | 1389 body = g_markup_printf_escaped(MSN_GROUP_ADD_TEMPLATE, |
1390 msn_contact_get_token(session->contact), | |
1391 group_name); | |
1343 | 1392 |
1344 msn_soap_message_send(session, | 1393 msn_soap_message_send(session, |
1345 msn_soap_message_new(MSN_GROUP_ADD_SOAP_ACTION, | 1394 msn_soap_message_new(MSN_GROUP_ADD_SOAP_ACTION, |
1346 xmlnode_from_str(body, -1)), | 1395 xmlnode_from_str(body, -1)), |
1347 MSN_CONTACT_SERVER, MSN_ADDRESS_BOOK_POST_URL, | 1396 MSN_CONTACT_SERVER, MSN_ADDRESS_BOOK_POST_URL, |
1380 | 1429 |
1381 state = msn_callback_state_new(session); | 1430 state = msn_callback_state_new(session); |
1382 msn_callback_state_set_action(state, MSN_DEL_GROUP); | 1431 msn_callback_state_set_action(state, MSN_DEL_GROUP); |
1383 msn_callback_state_set_guid(state, guid); | 1432 msn_callback_state_set_guid(state, guid); |
1384 | 1433 |
1385 body = g_strdup_printf(MSN_GROUP_DEL_TEMPLATE, guid); | 1434 body = g_strdup_printf(MSN_GROUP_DEL_TEMPLATE, |
1435 msn_contact_get_token(session->contact), | |
1436 guid); | |
1386 | 1437 |
1387 msn_soap_message_send(session, | 1438 msn_soap_message_send(session, |
1388 msn_soap_message_new(MSN_GROUP_DEL_SOAP_ACTION, | 1439 msn_soap_message_new(MSN_GROUP_DEL_SOAP_ACTION, |
1389 xmlnode_from_str(body, -1)), | 1440 xmlnode_from_str(body, -1)), |
1390 MSN_CONTACT_SERVER, MSN_ADDRESS_BOOK_POST_URL, | 1441 MSN_CONTACT_SERVER, MSN_ADDRESS_BOOK_POST_URL, |
1422 } | 1473 } |
1423 | 1474 |
1424 msn_callback_state_set_action(state, MSN_RENAME_GROUP); | 1475 msn_callback_state_set_action(state, MSN_RENAME_GROUP); |
1425 | 1476 |
1426 body = g_markup_printf_escaped(MSN_GROUP_RENAME_TEMPLATE, | 1477 body = g_markup_printf_escaped(MSN_GROUP_RENAME_TEMPLATE, |
1427 guid, new_group_name); | 1478 msn_contact_get_token(session->contact), |
1479 guid, new_group_name); | |
1428 | 1480 |
1429 msn_soap_message_send(session, | 1481 msn_soap_message_send(session, |
1430 msn_soap_message_new(MSN_GROUP_RENAME_SOAP_ACTION, | 1482 msn_soap_message_new(MSN_GROUP_RENAME_SOAP_ACTION, |
1431 xmlnode_from_str(body, -1)), | 1483 xmlnode_from_str(body, -1)), |
1432 MSN_CONTACT_SERVER, MSN_ADDRESS_BOOK_POST_URL, | 1484 MSN_CONTACT_SERVER, MSN_ADDRESS_BOOK_POST_URL, |