comparison libpurple/protocols/msn/contact.c @ 23509:1ac5faa72c8d

explicit merge of '9d90ebdb7e38fdd77bb504bc3302a083616360d9' and '547cd65fb6e1faeb37d88730f0dbf45075a08426' to branch 'im.pidgin.cpw.qulogic.msn'
author Elliott Sales de Andrade <qulogic@pidgin.im>
date Sat, 07 Jun 2008 03:10:15 +0000
parents 5cdd93dac7a2 d756a0477c06
children eb8bd060b987
comparison
equal deleted inserted replaced
23309:99b4470a763e 23509:1ac5faa72c8d
1 /** 1 /**
2 * @file contact.c 2 * @file contact.c
3 * get MSN contacts via SOAP request 3 * get MSN contacts via SOAP request
4 * created by MaYuan<mayuan2006@gmail.com> 4 * created by MaYuan<mayuan2006@gmail.com>
5 * 5 *
6 * purple 6 * purple
7 * 7 *
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",
47 "Reverse", 48 "Reverse",
48 "Pending" 49 "Pending"
49 }; 50 };
50 51
51 typedef struct { 52 typedef struct {
52 MsnContact *contact; 53 MsnSession *session;
53 MsnSoapPartnerScenario which; 54 MsnSoapPartnerScenario which;
54 } GetContactListCbData; 55 } GetContactListCbData;
55
56 /* new a contact */
57 MsnContact *
58 msn_contact_new(MsnSession *session)
59 {
60 MsnContact *contact;
61
62 contact = g_new0(MsnContact, 1);
63 contact->session = session;
64
65 return contact;
66 }
67
68 /* destroy the contact */
69 void
70 msn_contact_destroy(MsnContact *contact)
71 {
72 g_free(contact);
73 }
74 56
75 MsnCallbackState * 57 MsnCallbackState *
76 msn_callback_state_new(MsnSession *session) 58 msn_callback_state_new(MsnSession *session)
77 { 59 {
78 MsnCallbackState *state = g_new0(MsnCallbackState, 1); 60 MsnCallbackState *state = g_new0(MsnCallbackState, 1);
198 180
199 /* Create the AddressBook in the server, if we don't have one */ 181 /* Create the AddressBook in the server, if we don't have one */
200 static void 182 static void
201 msn_create_address_cb(MsnSoapMessage *req, MsnSoapMessage *resp, gpointer data) 183 msn_create_address_cb(MsnSoapMessage *req, MsnSoapMessage *resp, gpointer data)
202 { 184 {
203 if (resp && msn_soap_xml_get(resp->xml, "Body/Fault") == NULL) { 185 if (resp && xmlnode_get_child(resp->xml, "Body/Fault") == NULL) {
204 purple_debug_info("msnab", "Address Book successfully created!\n"); 186 purple_debug_info("msnab", "Address Book successfully created!\n");
205 msn_get_address_book((MsnContact *)data, MSN_PS_INITIAL, NULL, NULL); 187 msn_get_address_book((MsnSession *)data, MSN_PS_INITIAL, NULL, NULL);
206 } else { 188 } else {
207 purple_debug_info("msnab", "Address Book creation failed!\n"); 189 purple_debug_info("msnab", "Address Book creation failed!\n");
208 } 190 }
209 } 191 }
210 192
211 static void 193 static void
212 msn_create_address_book(MsnContact * contact) 194 msn_create_address_book(MsnSession *session)
213 { 195 {
214 gchar *body; 196 gchar *body;
215 197
216 g_return_if_fail(contact != NULL); 198 g_return_if_fail(session != NULL);
217 g_return_if_fail(contact->session != NULL); 199 g_return_if_fail(session->user != NULL);
218 g_return_if_fail(contact->session->user != NULL); 200 g_return_if_fail(session->user->passport != NULL);
219 g_return_if_fail(contact->session->user->passport != NULL); 201
220
221 purple_debug_info("msnab","Creating an Address Book.\n"); 202 purple_debug_info("msnab","Creating an Address Book.\n");
222 203
223 body = g_strdup_printf(MSN_ADD_ADDRESSBOOK_TEMPLATE, contact->session->user->passport); 204 body = g_strdup_printf(MSN_ADD_ADDRESSBOOK_TEMPLATE,
224 205 msn_nexus_get_token_str(session->nexus, MSN_AUTH_CONTACTS),
225 msn_soap_message_send(contact->session, 206 session->user->passport);
207
208 msn_soap_message_send(session,
226 msn_soap_message_new(MSN_ADD_ADDRESSBOOK_SOAP_ACTION, 209 msn_soap_message_new(MSN_ADD_ADDRESSBOOK_SOAP_ACTION,
227 xmlnode_from_str(body, -1)), 210 xmlnode_from_str(body, -1)),
228 MSN_CONTACT_SERVER, MSN_ADDRESS_BOOK_POST_URL, msn_create_address_cb, 211 MSN_CONTACT_SERVER, MSN_ADDRESS_BOOK_POST_URL, msn_create_address_cb,
229 contact); 212 session);
230 213
231 g_free(body); 214 g_free(body);
232 } 215 }
233 216
234 static void 217 static void
257 static void 240 static void
258 msn_parse_each_service(MsnSession *session, xmlnode *service) 241 msn_parse_each_service(MsnSession *session, xmlnode *service)
259 { 242 {
260 xmlnode *type; 243 xmlnode *type;
261 244
262 if ((type = msn_soap_xml_get(service, "Info/Handle/Type"))) { 245 if ((type = xmlnode_get_child(service, "Info/Handle/Type"))) {
263 char *type_str = xmlnode_get_data(type); 246 char *type_str = xmlnode_get_data(type);
264 247
265 if (g_str_equal(type_str, "Profile")) { 248 if (g_str_equal(type_str, "Profile")) {
266 /* Process Windows Live 'Messenger Roaming Identity' */ 249 /* Process Windows Live 'Messenger Roaming Identity' */
267 } else if (g_str_equal(type_str, "Messenger")) { 250 } else if (g_str_equal(type_str, "Messenger")) {
271 254
272 purple_debug_info("msncl","last change: %s\n", lastchange_str); 255 purple_debug_info("msncl","last change: %s\n", lastchange_str);
273 purple_account_set_string(session->account, "CLLastChange", 256 purple_account_set_string(session->account, "CLLastChange",
274 lastchange_str); 257 lastchange_str);
275 258
276 for (membership = msn_soap_xml_get(service, 259 for (membership = xmlnode_get_child(service,
277 "Memberships/Membership"); 260 "Memberships/Membership");
278 membership; membership = xmlnode_get_next_twin(membership)) { 261 membership; membership = xmlnode_get_next_twin(membership)) {
279 262
280 xmlnode *role = xmlnode_get_child(membership, "MemberRole"); 263 xmlnode *role = xmlnode_get_child(membership, "MemberRole");
281 char *role_str = xmlnode_get_data(role); 264 char *role_str = xmlnode_get_data(role);
283 xmlnode *member; 266 xmlnode *member;
284 267
285 purple_debug_info("msncl", "MemberRole role: %s, list: %d\n", 268 purple_debug_info("msncl", "MemberRole role: %s, list: %d\n",
286 role_str, list); 269 role_str, list);
287 270
288 for (member = msn_soap_xml_get(membership, "Members/Member"); 271 for (member = xmlnode_get_child(membership, "Members/Member");
289 member; member = xmlnode_get_next_twin(member)) { 272 member; member = xmlnode_get_next_twin(member)) {
290 const char *member_type = xmlnode_get_attrib(member, "type"); 273 const char *member_type = xmlnode_get_attrib(member, "type");
291 if (g_str_equal(member_type, "PassportMember")) { 274 if (g_str_equal(member_type, "PassportMember")) {
292 msn_parse_each_member(session, member, "PassportName", 275 msn_parse_each_member(session, member, "PassportName",
293 list); 276 list);
308 } 291 }
309 } 292 }
310 293
311 /*parse contact list*/ 294 /*parse contact list*/
312 static void 295 static void
313 msn_parse_contact_list(MsnContact *contact, xmlnode *node) 296 msn_parse_contact_list(MsnSession *session, xmlnode *node)
314 { 297 {
315 xmlnode *fault, *faultnode; 298 xmlnode *fault, *faultnode;
316 299
317 /* we may get a response if our cache data is too old: 300 /* we may get a response if our cache data is too old:
318 * 301 *
319 * <faultstring>Need to do full sync. Can't sync deltas Client 302 * <faultstring>Need to do full sync. Can't sync deltas Client
320 * has too old a copy for us to do a delta sync</faultstring> 303 * has too old a copy for us to do a delta sync</faultstring>
321 * 304 *
322 * this is not handled yet 305 * this is not handled yet
323 */ 306 */
324 if ((fault = msn_soap_xml_get(node, "Body/Fault"))) { 307 if ((fault = xmlnode_get_child(node, "Body/Fault"))) {
325 if ((faultnode = xmlnode_get_child(fault, "faultstring"))) { 308 if ((faultnode = xmlnode_get_child(fault, "faultstring"))) {
326 char *faultstring = xmlnode_get_data(faultnode); 309 char *faultstring = xmlnode_get_data(faultnode);
327 purple_debug_info("msncl", "Retrieving contact list failed: %s\n", 310 purple_debug_info("msncl", "Retrieving contact list failed: %s\n",
328 faultstring); 311 faultstring);
329 g_free(faultstring); 312 g_free(faultstring);
330 } 313 }
331 if ((faultnode = msn_soap_xml_get(fault, "detail/errorcode"))) { 314 if ((faultnode = xmlnode_get_child(fault, "detail/errorcode"))) {
332 char *errorcode = xmlnode_get_data(faultnode); 315 char *errorcode = xmlnode_get_data(faultnode);
333 316
334 if (g_str_equal(errorcode, "ABDoesNotExist")) { 317 if (g_str_equal(errorcode, "ABDoesNotExist")) {
335 msn_create_address_book(contact); 318 msn_create_address_book(session);
336 g_free(errorcode); 319 g_free(errorcode);
337 return; 320 return;
338 } 321 }
339 322
340 g_free(errorcode); 323 g_free(errorcode);
341 } 324 }
342 325
343 msn_get_contact_list(contact, MSN_PS_INITIAL, NULL); 326 msn_get_contact_list(session, MSN_PS_INITIAL, NULL);
344 } else { 327 } else {
345 xmlnode *service; 328 xmlnode *service;
346 329
347 for (service = msn_soap_xml_get(node, "Body/FindMembershipResponse/" 330 for (service = xmlnode_get_child(node, "Body/FindMembershipResponse/"
348 "FindMembershipResult/Services/Service"); 331 "FindMembershipResult/Services/Service");
349 service; service = xmlnode_get_next_twin(service)) { 332 service; service = xmlnode_get_next_twin(service)) {
350 msn_parse_each_service(contact->session, service); 333 msn_parse_each_service(session, service);
351 } 334 }
352 } 335 }
353 } 336 }
354 337
355 static void 338 static void
356 msn_get_contact_list_cb(MsnSoapMessage *req, MsnSoapMessage *resp, 339 msn_get_contact_list_cb(MsnSoapMessage *req, MsnSoapMessage *resp,
357 gpointer data) 340 gpointer data)
358 { 341 {
359 GetContactListCbData *cb_data = data; 342 GetContactListCbData *cb_data = data;
360 MsnContact *contact = cb_data->contact; 343 MsnSession *session = cb_data->session;
361 MsnSession *session = contact->session;
362 344
363 g_return_if_fail(session != NULL); 345 g_return_if_fail(session != NULL);
364 346
365 if (resp != NULL) { 347 if (resp != NULL) {
366 const char *abLastChange; 348 const char *abLastChange;
367 const char *dynamicItemLastChange; 349 const char *dynamicItemLastChange;
368 350
369 purple_debug_misc("msncl","Got the contact list!\n"); 351 purple_debug_misc("msncl","Got the contact list!\n");
370 352
371 msn_parse_contact_list(cb_data->contact, resp->xml); 353 msn_parse_contact_list(session, resp->xml);
372 abLastChange = purple_account_get_string(session->account, 354 abLastChange = purple_account_get_string(session->account,
373 "ablastChange", NULL); 355 "ablastChange", NULL);
374 dynamicItemLastChange = purple_account_get_string(session->account, 356 dynamicItemLastChange = purple_account_get_string(session->account,
375 "dynamicItemLastChange", NULL); 357 "dynamicItemLastChange", NULL);
376 358
377 if (cb_data->which == MSN_PS_INITIAL) { 359 if (cb_data->which == MSN_PS_INITIAL) {
378 #ifdef MSN_PARTIAL_LISTS 360 #ifdef MSN_PARTIAL_LISTS
379 /* XXX: this should be enabled when we can correctly do partial 361 /* XXX: this should be enabled when we can correctly do partial
380 syncs with the server. Currently we need to retrieve the whole 362 syncs with the server. Currently we need to retrieve the whole
381 list to detect sync issues */ 363 list to detect sync issues */
382 msn_get_address_book(contact, MSN_PS_INITIAL, abLastChange, dynamicItemLastChange); 364 msn_get_address_book(session, MSN_PS_INITIAL, abLastChange, dynamicItemLastChange);
383 #else 365 #else
384 msn_get_address_book(contact, MSN_PS_INITIAL, NULL, NULL); 366 msn_get_address_book(session, MSN_PS_INITIAL, NULL, NULL);
385 #endif 367 #endif
386 } 368 }
387 } 369 }
388 370
389 g_free(cb_data); 371 g_free(cb_data);
390 } 372 }
391 373
392 /*SOAP get contact list*/ 374 /*SOAP get contact list*/
393 void 375 void
394 msn_get_contact_list(MsnContact * contact, 376 msn_get_contact_list(MsnSession *session,
395 const MsnSoapPartnerScenario partner_scenario, const char *update_time) 377 const MsnSoapPartnerScenario partner_scenario, const char *update_time)
396 { 378 {
397 gchar *body = NULL; 379 gchar *body = NULL;
398 gchar *update_str = NULL; 380 gchar *update_str = NULL;
399 GetContactListCbData cb_data = { contact, partner_scenario }; 381 GetContactListCbData cb_data = { session, partner_scenario };
400 const gchar *partner_scenario_str = MsnSoapPartnerScenarioText[partner_scenario]; 382 const gchar *partner_scenario_str = MsnSoapPartnerScenarioText[partner_scenario];
401 383
402 purple_debug_misc("MSNCL","Getting Contact List.\n"); 384 purple_debug_misc("MSNCL","Getting Contact List.\n");
403 385
404 if ( update_time != NULL ) { 386 if ( update_time != NULL ) {
405 purple_debug_info("MSNCL","Last update time: %s\n",update_time); 387 purple_debug_info("MSNCL","Last update time: %s\n",update_time);
406 update_str = g_strdup_printf(MSN_GET_CONTACT_UPDATE_XML,update_time); 388 update_str = g_strdup_printf(MSN_GET_CONTACT_UPDATE_XML,update_time);
407 } 389 }
408 390
409 body = g_strdup_printf(MSN_GET_CONTACT_TEMPLATE, partner_scenario_str, update_str ? update_str : ""); 391 body = g_strdup_printf(MSN_GET_CONTACT_TEMPLATE, partner_scenario_str,
410 392 msn_nexus_get_token_str(session->nexus, MSN_AUTH_CONTACTS),
411 msn_soap_message_send(contact->session, 393 update_str ? update_str : "");
394
395 msn_soap_message_send(session,
412 msn_soap_message_new(MSN_GET_CONTACT_SOAP_ACTION, 396 msn_soap_message_new(MSN_GET_CONTACT_SOAP_ACTION,
413 xmlnode_from_str(body, -1)), 397 xmlnode_from_str(body, -1)),
414 MSN_CONTACT_SERVER, MSN_GET_CONTACT_POST_URL, 398 MSN_CONTACT_SERVER, MSN_GET_CONTACT_POST_URL,
415 msn_get_contact_list_cb, g_memdup(&cb_data, sizeof(cb_data))); 399 msn_get_contact_list_cb, g_memdup(&cb_data, sizeof(cb_data)));
416 400
417 g_free(update_str); 401 g_free(update_str);
418 g_free(body); 402 g_free(body);
419 } 403 }
420 404
421 static void 405 static void
422 msn_parse_addressbook_groups(MsnContact *contact, xmlnode *node) 406 msn_parse_addressbook_groups(MsnSession *session, xmlnode *node)
423 { 407 {
424 MsnSession *session = contact->session;
425 xmlnode *group; 408 xmlnode *group;
426 409
427 purple_debug_info("MSNAB","msn_parse_addressbook_groups()\n"); 410 purple_debug_info("MSNAB","msn_parse_addressbook_groups()\n");
428 411
429 for(group = xmlnode_get_child(node, "Group"); group; 412 for(group = xmlnode_get_child(node, "Group"); group;
505 *inout_mobile_number = mobile_number; 488 *inout_mobile_number = mobile_number;
506 return mobile; 489 return mobile;
507 } 490 }
508 491
509 static void 492 static void
510 msn_parse_addressbook_contacts(MsnContact *contact, xmlnode *node) 493 msn_parse_addressbook_contacts(MsnSession *session, xmlnode *node)
511 { 494 {
512 MsnSession *session = contact->session;
513 xmlnode *contactNode; 495 xmlnode *contactNode;
514 char *passport = NULL, *Name = NULL, *uid = NULL, *type = NULL, *mobile_number = NULL; 496 char *passport = NULL, *Name = NULL, *uid = NULL, *type = NULL, *mobile_number = NULL;
515 gboolean mobile = FALSE; 497 gboolean mobile = FALSE;
516 498
517 for(contactNode = xmlnode_get_child(node, "Contact"); contactNode; 499 for(contactNode = xmlnode_get_child(node, "Contact"); contactNode;
653 g_free(type); 635 g_free(type);
654 g_free(mobile_number); 636 g_free(mobile_number);
655 } 637 }
656 638
657 static gboolean 639 static gboolean
658 msn_parse_addressbook(MsnContact * contact, xmlnode *node) 640 msn_parse_addressbook(MsnSession *session, xmlnode *node)
659 { 641 {
660 MsnSession * session;
661 xmlnode *result; 642 xmlnode *result;
662 xmlnode *groups; 643 xmlnode *groups;
663 xmlnode *contacts; 644 xmlnode *contacts;
664 xmlnode *abNode; 645 xmlnode *abNode;
665 xmlnode *fault; 646 xmlnode *fault;
666 647
667 session = contact->session; 648 if ((fault = xmlnode_get_child(node, "Body/Fault"))) {
668
669 if ((fault = msn_soap_xml_get(node, "Body/Fault"))) {
670 xmlnode *faultnode; 649 xmlnode *faultnode;
671 650
672 if ((faultnode = xmlnode_get_child(fault, "faultstring"))) { 651 if ((faultnode = xmlnode_get_child(fault, "faultstring"))) {
673 gchar *faultstring = xmlnode_get_data(faultnode); 652 gchar *faultstring = xmlnode_get_data(faultnode);
674 purple_debug_info("MSNAB","Faultstring: %s\n", faultstring); 653 purple_debug_info("MSNAB","Faultstring: %s\n", faultstring);
675 g_free(faultstring); 654 g_free(faultstring);
676 } 655 }
677 656
678 if ((faultnode = msn_soap_xml_get(fault, "detail/errorcode"))) { 657 if ((faultnode = xmlnode_get_child(fault, "detail/errorcode"))) {
679 gchar *errorcode = xmlnode_get_data(faultnode); 658 gchar *errorcode = xmlnode_get_data(faultnode);
680 659
681 purple_debug_info("MSNAB", "Error Code: %s\n", errorcode); 660 purple_debug_info("MSNAB", "Error Code: %s\n", errorcode);
682 661
683 if (g_str_equal(errorcode, "ABDoesNotExist")) { 662 if (g_str_equal(errorcode, "ABDoesNotExist")) {
688 } 667 }
689 668
690 return FALSE; 669 return FALSE;
691 } 670 }
692 671
693 result = msn_soap_xml_get(node, "Body/ABFindAllResponse/ABFindAllResult"); 672 result = xmlnode_get_child(node, "Body/ABFindAllResponse/ABFindAllResult");
694 if(result == NULL){ 673 if(result == NULL){
695 purple_debug_misc("MSNAB","receive no address book update\n"); 674 purple_debug_misc("MSNAB","receive no address book update\n");
696 return TRUE; 675 return TRUE;
697 } 676 }
698 677
699 /* I don't see this "groups" tag documented on msnpiki, need to find out 678 /* I don't see this "groups" tag documented on msnpiki, need to find out
700 if they are really there, and update msnpiki */ 679 if they are really there, and update msnpiki */
701 /*Process Group List*/ 680 /*Process Group List*/
702 groups = xmlnode_get_child(result,"groups"); 681 groups = xmlnode_get_child(result,"groups");
703 if (groups != NULL) { 682 if (groups != NULL) {
704 msn_parse_addressbook_groups(contact, groups); 683 msn_parse_addressbook_groups(session, groups);
705 } 684 }
706 685
707 /*add a default No group to set up the no group Membership*/ 686 /*add a default No group to set up the no group Membership*/
708 msn_group_new(session->userlist, MSN_INDIVIDUALS_GROUP_ID, 687 msn_group_new(session->userlist, MSN_INDIVIDUALS_GROUP_ID,
709 MSN_INDIVIDUALS_GROUP_NAME); 688 MSN_INDIVIDUALS_GROUP_NAME);
724 703
725 /*Process contact List*/ 704 /*Process contact List*/
726 purple_debug_info("MSNAB","process contact list...\n"); 705 purple_debug_info("MSNAB","process contact list...\n");
727 contacts =xmlnode_get_child(result,"contacts"); 706 contacts =xmlnode_get_child(result,"contacts");
728 if (contacts != NULL) { 707 if (contacts != NULL) {
729 msn_parse_addressbook_contacts(contact, contacts); 708 msn_parse_addressbook_contacts(session, contacts);
730 } 709 }
731 710
732 abNode =xmlnode_get_child(result,"ab"); 711 abNode =xmlnode_get_child(result,"ab");
733 if(abNode != NULL){ 712 if(abNode != NULL){
734 xmlnode *node2; 713 xmlnode *node2;
751 } 730 }
752 731
753 static void 732 static void
754 msn_get_address_cb(MsnSoapMessage *req, MsnSoapMessage *resp, gpointer data) 733 msn_get_address_cb(MsnSoapMessage *req, MsnSoapMessage *resp, gpointer data)
755 { 734 {
756 MsnContact *contact = data; 735 MsnSession *session = data;
757 MsnSession *session;
758 736
759 if (resp == NULL) 737 if (resp == NULL)
760 return; 738 return;
761 739
762 g_return_if_fail(contact != NULL);
763 session = contact->session;
764 g_return_if_fail(session != NULL); 740 g_return_if_fail(session != NULL);
765 741
766 purple_debug_misc("MSNAB", "Got the Address Book!\n"); 742 purple_debug_misc("MSNAB", "Got the Address Book!\n");
767 743
768 if (msn_parse_addressbook(contact, resp->xml)) { 744 if (msn_parse_addressbook(session, resp->xml)) {
769 if (!session->logged_in) { 745 if (!session->logged_in) {
770 msn_send_privacy(session->account->gc); 746 msn_send_privacy(session->account->gc);
771 msn_notification_dump_contact(session); 747 msn_notification_dump_contact(session);
772 } 748 }
773 } else { 749 } else {
774 /* This is making us loop infinitely when we fail to parse the 750 /* This is making us loop infinitely when we fail to parse the
775 address book, disable for now (we should re-enable when we 751 address book, disable for now (we should re-enable when we
776 send timestamps) 752 send timestamps)
777 */ 753 */
778 /* 754 /*
779 msn_get_address_book(contact, NULL, NULL); 755 msn_get_address_book(session, NULL, NULL);
780 */ 756 */
781 msn_session_disconnect(session); 757 msn_session_disconnect(session);
782 purple_connection_error_reason(session->account->gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, _("Unable to retrieve MSN Address Book")); 758 purple_connection_error_reason(session->account->gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, _("Unable to retrieve MSN Address Book"));
783 } 759 }
784 } 760 }
785 761
786 /*get the address book*/ 762 /*get the address book*/
787 void 763 void
788 msn_get_address_book(MsnContact *contact, 764 msn_get_address_book(MsnSession *session,
789 MsnSoapPartnerScenario partner_scenario, const char *LastChanged, 765 MsnSoapPartnerScenario partner_scenario, const char *LastChanged,
790 const char *dynamicItemLastChange) 766 const char *dynamicItemLastChange)
791 { 767 {
792 char *body, *update_str = NULL; 768 char *body, *update_str = NULL;
793 769
797 if (dynamicItemLastChange != NULL) 773 if (dynamicItemLastChange != NULL)
798 update_str = g_strdup_printf(MSN_GET_ADDRESS_UPDATE_XML, dynamicItemLastChange); 774 update_str = g_strdup_printf(MSN_GET_ADDRESS_UPDATE_XML, dynamicItemLastChange);
799 else if (LastChanged != NULL) 775 else if (LastChanged != NULL)
800 update_str = g_strdup_printf(MSN_GET_ADDRESS_UPDATE_XML, LastChanged); 776 update_str = g_strdup_printf(MSN_GET_ADDRESS_UPDATE_XML, LastChanged);
801 777
802 body = g_strdup_printf(MSN_GET_ADDRESS_TEMPLATE, MsnSoapPartnerScenarioText[partner_scenario], update_str ? update_str : ""); 778 body = g_strdup_printf(MSN_GET_ADDRESS_TEMPLATE,
803 779 MsnSoapPartnerScenarioText[partner_scenario],
804 msn_soap_message_send(contact->session, 780 msn_nexus_get_token_str(session->nexus, MSN_AUTH_CONTACTS),
781 update_str ? update_str : "");
782
783 msn_soap_message_send(session,
805 msn_soap_message_new(MSN_GET_ADDRESS_SOAP_ACTION, 784 msn_soap_message_new(MSN_GET_ADDRESS_SOAP_ACTION,
806 xmlnode_from_str(body, -1)), 785 xmlnode_from_str(body, -1)),
807 MSN_CONTACT_SERVER, MSN_ADDRESS_BOOK_POST_URL, msn_get_address_cb, 786 MSN_CONTACT_SERVER, MSN_ADDRESS_BOOK_POST_URL, msn_get_address_cb,
808 contact); 787 session);
809 788
810 g_free(update_str); 789 g_free(update_str);
811 g_free(body); 790 g_free(body);
812 } 791 }
813 792
842 msn_callback_state_free(state); 821 msn_callback_state_free(state);
843 } 822 }
844 823
845 /* add a Contact in MSN_INDIVIDUALS_GROUP */ 824 /* add a Contact in MSN_INDIVIDUALS_GROUP */
846 void 825 void
847 msn_add_contact(MsnContact *contact, MsnCallbackState *state, const char *passport) 826 msn_add_contact(MsnSession *session, MsnCallbackState *state, const char *passport)
848 { 827 {
849 gchar *body = NULL; 828 gchar *body = NULL;
850 gchar *contact_xml = NULL; 829 gchar *contact_xml = NULL;
851 830
852 #if 0 831 #if 0
862 #endif 841 #endif
863 842
864 purple_debug_info("MSNCL","Adding contact %s to contact list\n", passport); 843 purple_debug_info("MSNCL","Adding contact %s to contact list\n", passport);
865 844
866 contact_xml = g_strdup_printf(MSN_CONTACT_XML, passport); 845 contact_xml = g_strdup_printf(MSN_CONTACT_XML, passport);
867 body = g_strdup_printf(MSN_ADD_CONTACT_TEMPLATE, contact_xml); 846 body = g_strdup_printf(MSN_ADD_CONTACT_TEMPLATE,
868 847 msn_nexus_get_token_str(session->nexus, MSN_AUTH_CONTACTS),
869 msn_soap_message_send(contact->session, 848 contact_xml);
849
850 msn_soap_message_send(session,
870 msn_soap_message_new(MSN_CONTACT_ADD_SOAP_ACTION, 851 msn_soap_message_new(MSN_CONTACT_ADD_SOAP_ACTION,
871 xmlnode_from_str(body, -1)), 852 xmlnode_from_str(body, -1)),
872 MSN_CONTACT_SERVER, MSN_ADDRESS_BOOK_POST_URL, 853 MSN_CONTACT_SERVER, MSN_ADDRESS_BOOK_POST_URL,
873 msn_add_contact_read_cb, state); 854 msn_add_contact_read_cb, state);
874 855
904 msn_userlist_add_buddy_to_list(userlist, state->who, MSN_LIST_FL); 885 msn_userlist_add_buddy_to_list(userlist, state->who, MSN_LIST_FL);
905 } 886 }
906 msn_notification_send_fqy(state->session, state->who); 887 msn_notification_send_fqy(state->session, state->who);
907 888
908 if (msn_userlist_user_is_in_list(user, MSN_LIST_PL)) { 889 if (msn_userlist_user_is_in_list(user, MSN_LIST_PL)) {
909 msn_del_contact_from_list(state->session->contact, NULL, state->who, MSN_LIST_PL); 890 msn_del_contact_from_list(state->session, NULL, state->who, MSN_LIST_PL);
910 msn_callback_state_free(state); 891 msn_callback_state_free(state);
911 return; 892 return;
912 } 893 }
913 } 894 }
914 895
915 if (state->action & MSN_MOVE_BUDDY) { 896 if (state->action & MSN_MOVE_BUDDY) {
916 msn_del_contact_from_group(state->session->contact, state->who, state->old_group_name); 897 msn_del_contact_from_group(state->session, state->who, state->old_group_name);
917 } 898 }
918 } 899 }
919 900
920 msn_callback_state_free(state); 901 msn_callback_state_free(state);
921 } 902 }
922 903
923 void 904 void
924 msn_add_contact_to_group(MsnContact *contact, MsnCallbackState *state, 905 msn_add_contact_to_group(MsnSession *session, MsnCallbackState *state,
925 const char *passport, const char *groupId) 906 const char *passport, const char *groupId)
926 { 907 {
927 MsnUserList *userlist; 908 MsnUserList *userlist;
928 MsnUser *user; 909 MsnUser *user;
929 gchar *body = NULL, *contact_xml; 910 gchar *body = NULL, *contact_xml;
930 911
931 g_return_if_fail(passport != NULL); 912 g_return_if_fail(passport != NULL);
932 g_return_if_fail(groupId != NULL); 913 g_return_if_fail(groupId != NULL);
933 914
934 g_return_if_fail(contact != NULL); 915 g_return_if_fail(session != NULL);
935 g_return_if_fail(contact->session != NULL); 916
936 g_return_if_fail(contact->session->userlist != NULL); 917 userlist = session->userlist;
937
938 userlist = contact->session->userlist;
939 918
940 if (!strcmp(groupId, MSN_INDIVIDUALS_GROUP_ID) || !strcmp(groupId, MSN_NON_IM_GROUP_ID)) { 919 if (!strcmp(groupId, MSN_INDIVIDUALS_GROUP_ID) || !strcmp(groupId, MSN_NON_IM_GROUP_ID)) {
941 920
942 user = msn_userlist_find_add_user(userlist, passport, passport); 921 user = msn_userlist_find_add_user(userlist, passport, passport);
943 922
944 if (state->action & MSN_ADD_BUDDY) { 923 if (state->action & MSN_ADD_BUDDY) {
945 msn_add_contact(contact, state, passport); 924 msn_add_contact(session, state, passport);
946 return; 925 return;
947 } 926 }
948 927
949 if (state->action & MSN_MOVE_BUDDY) { 928 if (state->action & MSN_MOVE_BUDDY) {
950 msn_user_add_group_id(user, groupId); 929 msn_user_add_group_id(user, groupId);
951 msn_del_contact_from_group(contact, passport, state->old_group_name); 930 msn_del_contact_from_group(session, passport, state->old_group_name);
952 } else { 931 } else {
953 msn_callback_state_free(state); 932 msn_callback_state_free(state);
954 } 933 }
955 934
956 return; 935 return;
970 contact_xml = g_strdup_printf(MSN_CONTACT_ID_XML, user->uid); 949 contact_xml = g_strdup_printf(MSN_CONTACT_ID_XML, user->uid);
971 } else { 950 } else {
972 contact_xml = g_strdup_printf(MSN_CONTACT_XML, passport); 951 contact_xml = g_strdup_printf(MSN_CONTACT_XML, passport);
973 } 952 }
974 953
975 body = g_strdup_printf(MSN_ADD_CONTACT_GROUP_TEMPLATE, groupId, contact_xml); 954 body = g_strdup_printf(MSN_ADD_CONTACT_GROUP_TEMPLATE,
955 msn_nexus_get_token_str(session->nexus, MSN_AUTH_CONTACTS),
956 groupId, contact_xml);
976 957
977 msn_soap_message_send(state->session, 958 msn_soap_message_send(state->session,
978 msn_soap_message_new(MSN_ADD_CONTACT_GROUP_SOAP_ACTION, 959 msn_soap_message_new(MSN_ADD_CONTACT_GROUP_SOAP_ACTION,
979 xmlnode_from_str(body, -1)), 960 xmlnode_from_str(body, -1)),
980 MSN_CONTACT_SERVER, MSN_ADDRESS_BOOK_POST_URL, 961 MSN_CONTACT_SERVER, MSN_ADDRESS_BOOK_POST_URL,
1004 msn_callback_state_free(state); 985 msn_callback_state_free(state);
1005 } 986 }
1006 987
1007 /*delete a Contact*/ 988 /*delete a Contact*/
1008 void 989 void
1009 msn_delete_contact(MsnContact *contact, const char *contactId) 990 msn_delete_contact(MsnSession *session, const char *contactId)
1010 { 991 {
1011 gchar *body = NULL; 992 gchar *body = NULL;
1012 gchar *contact_id_xml = NULL ; 993 gchar *contact_id_xml = NULL ;
1013 MsnCallbackState *state; 994 MsnCallbackState *state;
1014 995
1015 g_return_if_fail(contactId != NULL); 996 g_return_if_fail(contactId != NULL);
1016 contact_id_xml = g_strdup_printf(MSN_CONTACT_ID_XML, contactId); 997 contact_id_xml = g_strdup_printf(MSN_CONTACT_ID_XML, contactId);
1017 998
1018 state = msn_callback_state_new(contact->session); 999 state = msn_callback_state_new(session);
1019 msn_callback_state_set_uid(state, contactId); 1000 msn_callback_state_set_uid(state, contactId);
1020 1001
1021 /* build SOAP request */ 1002 /* build SOAP request */
1022 purple_debug_info("MSNCL","Deleting contact with contactId: %s\n", contactId); 1003 purple_debug_info("MSNCL","Deleting contact with contactId: %s\n", contactId);
1023 body = g_strdup_printf(MSN_DEL_CONTACT_TEMPLATE, contact_id_xml); 1004 body = g_strdup_printf(MSN_DEL_CONTACT_TEMPLATE,
1024 msn_soap_message_send(contact->session, 1005 msn_nexus_get_token_str(session->nexus, MSN_AUTH_CONTACTS),
1006 contact_id_xml);
1007
1008 msn_soap_message_send(session,
1025 msn_soap_message_new(MSN_CONTACT_DEL_SOAP_ACTION, 1009 msn_soap_message_new(MSN_CONTACT_DEL_SOAP_ACTION,
1026 xmlnode_from_str(body, -1)), 1010 xmlnode_from_str(body, -1)),
1027 MSN_CONTACT_SERVER, MSN_ADDRESS_BOOK_POST_URL, 1011 MSN_CONTACT_SERVER, MSN_ADDRESS_BOOK_POST_URL,
1028 msn_delete_contact_read_cb, state); 1012 msn_delete_contact_read_cb, state);
1029 1013
1048 1032
1049 msn_callback_state_free(state); 1033 msn_callback_state_free(state);
1050 } 1034 }
1051 1035
1052 void 1036 void
1053 msn_del_contact_from_group(MsnContact *contact, const char *passport, const char *group_name) 1037 msn_del_contact_from_group(MsnSession *session, const char *passport, const char *group_name)
1054 { 1038 {
1055 MsnUserList * userlist; 1039 MsnUserList * userlist;
1056 MsnUser *user; 1040 MsnUser *user;
1057 MsnCallbackState *state; 1041 MsnCallbackState *state;
1058 gchar *body, *contact_id_xml; 1042 gchar *body, *contact_id_xml;
1059 const gchar *groupId; 1043 const gchar *groupId;
1060 1044
1061 g_return_if_fail(passport != NULL); 1045 g_return_if_fail(passport != NULL);
1062 g_return_if_fail(group_name != NULL); 1046 g_return_if_fail(group_name != NULL);
1063 g_return_if_fail(contact != NULL); 1047 g_return_if_fail(session != NULL);
1064 g_return_if_fail(contact->session != NULL); 1048
1065 g_return_if_fail(contact->session->userlist != NULL); 1049 userlist = session->userlist;
1066
1067 userlist = contact->session->userlist;
1068 1050
1069 groupId = msn_userlist_find_group_id(userlist, group_name); 1051 groupId = msn_userlist_find_group_id(userlist, group_name);
1070 if (groupId != NULL) { 1052 if (groupId != NULL) {
1071 purple_debug_info("MSNCL", "Deleting user %s from group %s\n", passport, group_name); 1053 purple_debug_info("MSNCL", "Deleting user %s from group %s\n", passport, group_name);
1072 } else { 1054 } else {
1084 if ( !strcmp(groupId, MSN_INDIVIDUALS_GROUP_ID) || !strcmp(groupId, MSN_NON_IM_GROUP_ID)) { 1066 if ( !strcmp(groupId, MSN_INDIVIDUALS_GROUP_ID) || !strcmp(groupId, MSN_NON_IM_GROUP_ID)) {
1085 msn_user_remove_group_id(user, groupId); 1067 msn_user_remove_group_id(user, groupId);
1086 return; 1068 return;
1087 } 1069 }
1088 1070
1089 state = msn_callback_state_new(contact->session); 1071 state = msn_callback_state_new(session);
1090 msn_callback_state_set_who(state, passport); 1072 msn_callback_state_set_who(state, passport);
1091 msn_callback_state_set_guid(state, groupId); 1073 msn_callback_state_set_guid(state, groupId);
1092 msn_callback_state_set_old_group_name(state, group_name); 1074 msn_callback_state_set_old_group_name(state, group_name);
1093 1075
1094 contact_id_xml = g_strdup_printf(MSN_CONTACT_ID_XML, user->uid); 1076 contact_id_xml = g_strdup_printf(MSN_CONTACT_ID_XML, user->uid);
1095 body = g_strdup_printf(MSN_CONTACT_DEL_GROUP_TEMPLATE, contact_id_xml, groupId); 1077 body = g_strdup_printf(MSN_CONTACT_DEL_GROUP_TEMPLATE,
1096 1078 msn_nexus_get_token_str(session->nexus, MSN_AUTH_CONTACTS),
1097 msn_soap_message_send(contact->session, 1079 contact_id_xml, groupId);
1080
1081 msn_soap_message_send(session,
1098 msn_soap_message_new(MSN_CONTACT_DEL_GROUP_SOAP_ACTION, 1082 msn_soap_message_new(MSN_CONTACT_DEL_GROUP_SOAP_ACTION,
1099 xmlnode_from_str(body, -1)), 1083 xmlnode_from_str(body, -1)),
1100 MSN_CONTACT_SERVER, MSN_ADDRESS_BOOK_POST_URL, 1084 MSN_CONTACT_SERVER, MSN_ADDRESS_BOOK_POST_URL,
1101 msn_del_contact_from_group_read_cb, state); 1085 msn_del_contact_from_group_read_cb, state);
1102 1086
1115 purple_debug_info("MSN CL","Contact updated successfully\n"); 1099 purple_debug_info("MSN CL","Contact updated successfully\n");
1116 } 1100 }
1117 1101
1118 /* Update a contact's nickname */ 1102 /* Update a contact's nickname */
1119 void 1103 void
1120 msn_update_contact(MsnContact *contact, const char* nickname) 1104 msn_update_contact(MsnSession *session, const char* nickname)
1121 { 1105 {
1122 gchar *body = NULL, *escaped_nickname; 1106 gchar *body = NULL, *escaped_nickname;
1123 1107
1124 purple_debug_info("MSN CL","Update contact information with new friendly name: %s\n", nickname); 1108 purple_debug_info("MSN CL","Update contact information with new friendly name: %s\n", nickname);
1125 1109
1126 escaped_nickname = g_markup_escape_text(nickname, -1); 1110 escaped_nickname = g_markup_escape_text(nickname, -1);
1127 1111
1128 body = g_strdup_printf(MSN_CONTACT_UPDATE_TEMPLATE, escaped_nickname); 1112 body = g_strdup_printf(MSN_CONTACT_UPDATE_TEMPLATE,
1129 1113 msn_nexus_get_token_str(session->nexus, MSN_AUTH_CONTACTS),
1130 msn_soap_message_send(contact->session, 1114 escaped_nickname);
1115
1116 msn_soap_message_send(session,
1131 msn_soap_message_new(MSN_CONTACT_UPDATE_SOAP_ACTION, 1117 msn_soap_message_new(MSN_CONTACT_UPDATE_SOAP_ACTION,
1132 xmlnode_from_str(body, -1)), 1118 xmlnode_from_str(body, -1)),
1133 MSN_CONTACT_SERVER, MSN_ADDRESS_BOOK_POST_URL, 1119 MSN_CONTACT_SERVER, MSN_ADDRESS_BOOK_POST_URL,
1134 msn_update_contact_read_cb, NULL); 1120 msn_update_contact_read_cb, NULL);
1135 1121
1151 MsnUser *user = msn_userlist_find_user(session->userlist, state->who); 1137 MsnUser *user = msn_userlist_find_user(session->userlist, state->who);
1152 1138
1153 if (user != NULL) 1139 if (user != NULL)
1154 msn_user_unset_op(user, MSN_LIST_PL_OP); 1140 msn_user_unset_op(user, MSN_LIST_PL_OP);
1155 1141
1156 msn_add_contact_to_list(session->contact, state, state->who, MSN_LIST_RL); 1142 msn_add_contact_to_list(session, state, state->who, MSN_LIST_RL);
1157 return; 1143 return;
1158 } else if (state->list_id == MSN_LIST_AL) { 1144 } else if (state->list_id == MSN_LIST_AL) {
1159 purple_privacy_permit_remove(session->account, state->who, TRUE); 1145 purple_privacy_permit_remove(session->account, state->who, TRUE);
1160 msn_add_contact_to_list(session->contact, NULL, state->who, MSN_LIST_BL); 1146 msn_add_contact_to_list(session, NULL, state->who, MSN_LIST_BL);
1161 } else if (state->list_id == MSN_LIST_BL) { 1147 } else if (state->list_id == MSN_LIST_BL) {
1162 purple_privacy_deny_remove(session->account, state->who, TRUE); 1148 purple_privacy_deny_remove(session->account, state->who, TRUE);
1163 msn_add_contact_to_list(session->contact, NULL, state->who, MSN_LIST_AL); 1149 msn_add_contact_to_list(session, NULL, state->who, MSN_LIST_AL);
1164 } 1150 }
1165 } 1151 }
1166 1152
1167 msn_callback_state_free(state); 1153 msn_callback_state_free(state);
1168 } 1154 }
1169 1155
1170 void 1156 void
1171 msn_del_contact_from_list(MsnContact *contact, MsnCallbackState *state, 1157 msn_del_contact_from_list(MsnSession *session, MsnCallbackState *state,
1172 const gchar *passport, const MsnListId list) 1158 const gchar *passport, const MsnListId list)
1173 { 1159 {
1174 gchar *body = NULL, *member = NULL; 1160 gchar *body = NULL, *member = NULL;
1175 MsnSoapPartnerScenario partner_scenario; 1161 MsnSoapPartnerScenario partner_scenario;
1176 MsnUser *user; 1162 MsnUser *user;
1177 1163
1178 g_return_if_fail(contact != NULL); 1164 g_return_if_fail(session != NULL);
1179 g_return_if_fail(passport != NULL); 1165 g_return_if_fail(passport != NULL);
1180 g_return_if_fail(list < 5); 1166 g_return_if_fail(list < 5);
1181 1167
1182 purple_debug_info("MSN CL", "Deleting contact %s from %s list\n", passport, MsnMemberRole[list]); 1168 purple_debug_info("MSN CL", "Deleting contact %s from %s list\n", passport, MsnMemberRole[list]);
1183 1169
1184 if (state == NULL) { 1170 if (state == NULL) {
1185 state = msn_callback_state_new(contact->session); 1171 state = msn_callback_state_new(session);
1186 } 1172 }
1187 msn_callback_state_set_list_id(state, list); 1173 msn_callback_state_set_list_id(state, list);
1188 msn_callback_state_set_who(state, passport); 1174 msn_callback_state_set_who(state, passport);
1189 1175
1190 if (list == MSN_LIST_PL) { 1176 if (list == MSN_LIST_PL) {
1191 g_return_if_fail(contact->session != NULL); 1177 g_return_if_fail(session->userlist != NULL);
1192 g_return_if_fail(contact->session->userlist != NULL); 1178
1193 1179 user = msn_userlist_find_user(session->userlist, passport);
1194 user = msn_userlist_find_user(contact->session->userlist, passport);
1195 1180
1196 partner_scenario = MSN_PS_CONTACT_API; 1181 partner_scenario = MSN_PS_CONTACT_API;
1197 member = g_strdup_printf(MSN_MEMBER_MEMBERSHIPID_XML, user->membership_id[MSN_LIST_PL]); 1182 member = g_strdup_printf(MSN_MEMBER_MEMBERSHIPID_XML, user->membership_id[MSN_LIST_PL]);
1198 } else { 1183 } else {
1199 /* list == MSN_LIST_AL || list == MSN_LIST_BL */ 1184 /* list == MSN_LIST_AL || list == MSN_LIST_BL */
1200 partner_scenario = MSN_PS_BLOCK_UNBLOCK; 1185 partner_scenario = MSN_PS_BLOCK_UNBLOCK;
1201 1186
1202 member = g_strdup_printf(MSN_MEMBER_PASSPORT_XML, passport); 1187 member = g_strdup_printf(MSN_MEMBER_PASSPORT_XML, passport);
1203 } 1188 }
1204 1189
1205 body = g_strdup_printf( MSN_CONTACT_DELECT_FROM_LIST_TEMPLATE, 1190 body = g_strdup_printf( MSN_CONTACT_DELECT_FROM_LIST_TEMPLATE,
1206 MsnSoapPartnerScenarioText[partner_scenario], 1191 MsnSoapPartnerScenarioText[partner_scenario],
1207 MsnMemberRole[list], 1192 msn_nexus_get_token_str(session->nexus, MSN_AUTH_CONTACTS),
1208 member); 1193 MsnMemberRole[list], member);
1209 1194
1210 msn_soap_message_send(contact->session, 1195 msn_soap_message_send(session,
1211 msn_soap_message_new(MSN_DELETE_MEMBER_FROM_LIST_SOAP_ACTION, 1196 msn_soap_message_new(MSN_DELETE_MEMBER_FROM_LIST_SOAP_ACTION,
1212 xmlnode_from_str(body, -1)), 1197 xmlnode_from_str(body, -1)),
1213 MSN_CONTACT_SERVER, MSN_SHARE_POST_URL, 1198 MSN_CONTACT_SERVER, MSN_SHARE_POST_URL,
1214 msn_del_contact_from_list_read_cb, state); 1199 msn_del_contact_from_list_read_cb, state);
1215 1200
1223 { 1208 {
1224 MsnCallbackState *state = data; 1209 MsnCallbackState *state = data;
1225 1210
1226 g_return_if_fail(state != NULL); 1211 g_return_if_fail(state != NULL);
1227 g_return_if_fail(state->session != NULL); 1212 g_return_if_fail(state->session != NULL);
1228 g_return_if_fail(state->session->contact != NULL);
1229 1213
1230 if (resp != NULL) { 1214 if (resp != NULL) {
1231 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]);
1232 1216
1233 if (state->list_id == MSN_LIST_RL) { 1217 if (state->list_id == MSN_LIST_RL) {
1237 msn_user_set_op(user, MSN_LIST_RL_OP); 1221 msn_user_set_op(user, MSN_LIST_RL_OP);
1238 } 1222 }
1239 1223
1240 if (state->action & MSN_DENIED_BUDDY) { 1224 if (state->action & MSN_DENIED_BUDDY) {
1241 1225
1242 msn_add_contact_to_list(state->session->contact, NULL, state->who, MSN_LIST_BL); 1226 msn_add_contact_to_list(state->session, NULL, state->who, MSN_LIST_BL);
1243 } else if (state->list_id == MSN_LIST_AL) { 1227 } else if (state->list_id == MSN_LIST_AL) {
1244 purple_privacy_permit_add(state->session->account, state->who, TRUE); 1228 purple_privacy_permit_add(state->session->account, state->who, TRUE);
1245 } else if (state->list_id == MSN_LIST_BL) { 1229 } else if (state->list_id == MSN_LIST_BL) {
1246 purple_privacy_deny_add(state->session->account, state->who, TRUE); 1230 purple_privacy_deny_add(state->session->account, state->who, TRUE);
1247 } 1231 }
1250 1234
1251 msn_callback_state_free(state); 1235 msn_callback_state_free(state);
1252 } 1236 }
1253 1237
1254 void 1238 void
1255 msn_add_contact_to_list(MsnContact *contact, MsnCallbackState *state, 1239 msn_add_contact_to_list(MsnSession *session, MsnCallbackState *state,
1256 const gchar *passport, const MsnListId list) 1240 const gchar *passport, const MsnListId list)
1257 { 1241 {
1258 gchar *body = NULL, *member = NULL; 1242 gchar *body = NULL, *member = NULL;
1259 MsnSoapPartnerScenario partner_scenario; 1243 MsnSoapPartnerScenario partner_scenario;
1260 1244
1261 g_return_if_fail(contact != NULL); 1245 g_return_if_fail(session != NULL);
1262 g_return_if_fail(passport != NULL); 1246 g_return_if_fail(passport != NULL);
1263 g_return_if_fail(list < 5); 1247 g_return_if_fail(list < 5);
1264 1248
1265 purple_debug_info("MSN CL", "Adding contact %s to %s list\n", passport, MsnMemberRole[list]); 1249 purple_debug_info("MSN CL", "Adding contact %s to %s list\n", passport, MsnMemberRole[list]);
1266 1250
1267 if (state == NULL) { 1251 if (state == NULL) {
1268 state = msn_callback_state_new(contact->session); 1252 state = msn_callback_state_new(session);
1269 } 1253 }
1270 msn_callback_state_set_list_id(state, list); 1254 msn_callback_state_set_list_id(state, list);
1271 msn_callback_state_set_who(state, passport); 1255 msn_callback_state_set_who(state, passport);
1272 1256
1273 partner_scenario = (list == MSN_LIST_RL) ? MSN_PS_CONTACT_API : MSN_PS_BLOCK_UNBLOCK; 1257 partner_scenario = (list == MSN_LIST_RL) ? MSN_PS_CONTACT_API : MSN_PS_BLOCK_UNBLOCK;
1274 1258
1275 member = g_strdup_printf(MSN_MEMBER_PASSPORT_XML, state->who); 1259 member = g_strdup_printf(MSN_MEMBER_PASSPORT_XML, state->who);
1276 1260
1277 body = g_strdup_printf(MSN_CONTACT_ADD_TO_LIST_TEMPLATE, 1261 body = g_strdup_printf(MSN_CONTACT_ADD_TO_LIST_TEMPLATE,
1278 MsnSoapPartnerScenarioText[partner_scenario], 1262 MsnSoapPartnerScenarioText[partner_scenario],
1279 MsnMemberRole[list], 1263 msn_nexus_get_token_str(session->nexus, MSN_AUTH_CONTACTS),
1280 member); 1264 MsnMemberRole[list], member);
1281 1265
1282 msn_soap_message_send(contact->session, 1266 msn_soap_message_send(session,
1283 msn_soap_message_new(MSN_ADD_MEMBER_TO_LIST_SOAP_ACTION, 1267 msn_soap_message_new(MSN_ADD_MEMBER_TO_LIST_SOAP_ACTION,
1284 xmlnode_from_str(body, -1)), 1268 xmlnode_from_str(body, -1)),
1285 MSN_CONTACT_SERVER, MSN_SHARE_POST_URL, 1269 MSN_CONTACT_SERVER, MSN_SHARE_POST_URL,
1286 msn_add_contact_to_list_read_cb, state); 1270 msn_add_contact_to_list_read_cb, state);
1287 1271
1299 purple_debug_info("MSNP14","Gleams read failed\n"); 1283 purple_debug_info("MSNP14","Gleams read failed\n");
1300 } 1284 }
1301 1285
1302 /*get the gleams info*/ 1286 /*get the gleams info*/
1303 void 1287 void
1304 msn_get_gleams(MsnContact *contact) 1288 msn_get_gleams(MsnSession *session)
1305 { 1289 {
1306 MsnSoapReq *soap_request; 1290 MsnSoapReq *soap_request;
1291 gchar *body = NULL;
1307 1292
1308 purple_debug_info("MSNP14","msn get gleams info...\n"); 1293 purple_debug_info("MSNP14","msn get gleams info...\n");
1309 msn_soap_message_send(contact->session, 1294
1295 body = g_strdup_printf(MSN_GLEAMS_TEMPLATE,
1296 msn_nexus_get_token_str(session->nexus, MSN_AUTH_CONTACTS));
1297
1298 msn_soap_message_send(session,
1310 msn_soap_message_new(MSN_GET_GLEAMS_SOAP_ACTION, 1299 msn_soap_message_new(MSN_GET_GLEAMS_SOAP_ACTION,
1311 xmlnode_from_str(MSN_GLEAMS_TEMPLATE, -1)), 1300 xmlnode_from_str(body, -1)),
1312 MSN_CONTACT_SERVER, MSN_ADDRESS_BOOK_POST_URL, 1301 MSN_CONTACT_SERVER, MSN_ADDRESS_BOOK_POST_URL,
1313 msn_gleams_read_cb, NULL); 1302 msn_gleams_read_cb, NULL);
1303 g_free(body);
1314 } 1304 }
1315 #endif 1305 #endif
1316 1306
1317 1307
1318 /*************************************************************** 1308 /***************************************************************
1326 1316
1327 purple_debug_info("MSNCL", "Group request successful.\n"); 1317 purple_debug_info("MSNCL", "Group request successful.\n");
1328 1318
1329 g_return_if_fail(state->session != NULL); 1319 g_return_if_fail(state->session != NULL);
1330 g_return_if_fail(state->session->userlist != NULL); 1320 g_return_if_fail(state->session->userlist != NULL);
1331 g_return_if_fail(state->session->contact != NULL);
1332 1321
1333 if (resp == NULL) { 1322 if (resp == NULL) {
1334 msn_callback_state_free(state); 1323 msn_callback_state_free(state);
1335 return; 1324 return;
1336 } 1325 }
1347 1336
1348 if (state->action & MSN_ADD_GROUP) { 1337 if (state->action & MSN_ADD_GROUP) {
1349 /* the response is taken from 1338 /* the response is taken from
1350 http://telepathy.freedesktop.org/wiki/Pymsn/MSNP/ContactListActions 1339 http://telepathy.freedesktop.org/wiki/Pymsn/MSNP/ContactListActions
1351 should copy it to msnpiki some day */ 1340 should copy it to msnpiki some day */
1352 xmlnode *guid_node = msn_soap_xml_get(resp->xml, 1341 xmlnode *guid_node = xmlnode_get_child(resp->xml,
1353 "Body/ABGroupAddResponse/ABGroupAddResult/guid"); 1342 "Body/ABGroupAddResponse/ABGroupAddResult/guid");
1354 1343
1355 if (guid_node) { 1344 if (guid_node) {
1356 char *guid = xmlnode_get_data(guid_node); 1345 char *guid = xmlnode_get_data(guid_node);
1357 1346
1362 if (state->action & MSN_ADD_BUDDY) { 1351 if (state->action & MSN_ADD_BUDDY) {
1363 msn_userlist_add_buddy(session->userlist, 1352 msn_userlist_add_buddy(session->userlist,
1364 state->who, 1353 state->who,
1365 state->new_group_name); 1354 state->new_group_name);
1366 } else if (state->action & MSN_MOVE_BUDDY) { 1355 } else if (state->action & MSN_MOVE_BUDDY) {
1367 msn_add_contact_to_group(session->contact, state, state->who, guid); 1356 msn_add_contact_to_group(session, state, state->who, guid);
1368 g_free(guid); 1357 g_free(guid);
1369 return; 1358 return;
1370 } 1359 }
1371 g_free(guid); 1360 g_free(guid);
1372 } else { 1361 } else {
1391 /* add group */ 1380 /* add group */
1392 void 1381 void
1393 msn_add_group(MsnSession *session, MsnCallbackState *state, const char* group_name) 1382 msn_add_group(MsnSession *session, MsnCallbackState *state, const char* group_name)
1394 { 1383 {
1395 char *body = NULL; 1384 char *body = NULL;
1385 char *escaped_group_name = NULL;
1396 1386
1397 g_return_if_fail(session != NULL); 1387 g_return_if_fail(session != NULL);
1398 g_return_if_fail(group_name != NULL); 1388 g_return_if_fail(group_name != NULL);
1399 1389
1400 purple_debug_info("MSNCL","Adding group %s to contact list.\n", group_name); 1390 purple_debug_info("MSNCL","Adding group %s to contact list.\n", group_name);
1407 msn_callback_state_set_new_group_name(state, group_name); 1397 msn_callback_state_set_new_group_name(state, group_name);
1408 1398
1409 /* escape group name's html special chars so it can safely be sent 1399 /* escape group name's html special chars so it can safely be sent
1410 * in a XML SOAP request 1400 * in a XML SOAP request
1411 */ 1401 */
1412 body = g_markup_printf_escaped(MSN_GROUP_ADD_TEMPLATE, group_name); 1402 escaped_group_name = g_markup_escape_text(group_name, -1);
1403 body = g_strdup_printf(MSN_GROUP_ADD_TEMPLATE,
1404 msn_nexus_get_token_str(session->nexus, MSN_AUTH_CONTACTS),
1405 escaped_group_name);
1413 1406
1414 msn_soap_message_send(session, 1407 msn_soap_message_send(session,
1415 msn_soap_message_new(MSN_GROUP_ADD_SOAP_ACTION, 1408 msn_soap_message_new(MSN_GROUP_ADD_SOAP_ACTION,
1416 xmlnode_from_str(body, -1)), 1409 xmlnode_from_str(body, -1)),
1417 MSN_CONTACT_SERVER, MSN_ADDRESS_BOOK_POST_URL, 1410 MSN_CONTACT_SERVER, MSN_ADDRESS_BOOK_POST_URL,
1418 msn_group_read_cb, state); 1411 msn_group_read_cb, state);
1419 1412
1413 g_free(escaped_group_name);
1420 g_free(body); 1414 g_free(body);
1421 } 1415 }
1422 1416
1423 /* delete group */ 1417 /* delete group */
1424 void 1418 void
1450 1444
1451 state = msn_callback_state_new(session); 1445 state = msn_callback_state_new(session);
1452 msn_callback_state_set_action(state, MSN_DEL_GROUP); 1446 msn_callback_state_set_action(state, MSN_DEL_GROUP);
1453 msn_callback_state_set_guid(state, guid); 1447 msn_callback_state_set_guid(state, guid);
1454 1448
1455 body = g_strdup_printf(MSN_GROUP_DEL_TEMPLATE, guid); 1449 body = g_strdup_printf(MSN_GROUP_DEL_TEMPLATE,
1450 msn_nexus_get_token_str(session->nexus, MSN_AUTH_CONTACTS),
1451 guid);
1456 1452
1457 msn_soap_message_send(session, 1453 msn_soap_message_send(session,
1458 msn_soap_message_new(MSN_GROUP_DEL_SOAP_ACTION, 1454 msn_soap_message_new(MSN_GROUP_DEL_SOAP_ACTION,
1459 xmlnode_from_str(body, -1)), 1455 xmlnode_from_str(body, -1)),
1460 MSN_CONTACT_SERVER, MSN_ADDRESS_BOOK_POST_URL, 1456 MSN_CONTACT_SERVER, MSN_ADDRESS_BOOK_POST_URL,
1468 msn_contact_rename_group(MsnSession *session, const char *old_group_name, const char *new_group_name) 1464 msn_contact_rename_group(MsnSession *session, const char *old_group_name, const char *new_group_name)
1469 { 1465 {
1470 gchar *body = NULL; 1466 gchar *body = NULL;
1471 const gchar * guid; 1467 const gchar * guid;
1472 MsnCallbackState *state; 1468 MsnCallbackState *state;
1469 char *escaped_group_name;
1473 1470
1474 g_return_if_fail(session != NULL); 1471 g_return_if_fail(session != NULL);
1475 g_return_if_fail(session->userlist != NULL); 1472 g_return_if_fail(session->userlist != NULL);
1476 g_return_if_fail(old_group_name != NULL); 1473 g_return_if_fail(old_group_name != NULL);
1477 g_return_if_fail(new_group_name != NULL); 1474 g_return_if_fail(new_group_name != NULL);
1491 // XXX move every buddy there (we probably need to fix concurrent SOAP reqs first) 1488 // XXX move every buddy there (we probably need to fix concurrent SOAP reqs first)
1492 } 1489 }
1493 1490
1494 msn_callback_state_set_action(state, MSN_RENAME_GROUP); 1491 msn_callback_state_set_action(state, MSN_RENAME_GROUP);
1495 1492
1496 body = g_markup_printf_escaped(MSN_GROUP_RENAME_TEMPLATE, 1493 escaped_group_name = g_markup_escape_text(new_group_name, -1);
1497 guid, new_group_name); 1494 body = g_strdup_printf(MSN_GROUP_RENAME_TEMPLATE,
1495 msn_nexus_get_token_str(session->nexus, MSN_AUTH_CONTACTS),
1496 guid, escaped_group_name);
1498 1497
1499 msn_soap_message_send(session, 1498 msn_soap_message_send(session,
1500 msn_soap_message_new(MSN_GROUP_RENAME_SOAP_ACTION, 1499 msn_soap_message_new(MSN_GROUP_RENAME_SOAP_ACTION,
1501 xmlnode_from_str(body, -1)), 1500 xmlnode_from_str(body, -1)),
1502 MSN_CONTACT_SERVER, MSN_ADDRESS_BOOK_POST_URL, 1501 MSN_CONTACT_SERVER, MSN_ADDRESS_BOOK_POST_URL,
1503 msn_group_read_cb, state); 1502 msn_group_read_cb, state);
1504 1503
1504 g_free(escaped_group_name);
1505 g_free(body); 1505 g_free(body);
1506 } 1506 }