comparison libpurple/protocols/msn/contact.c @ 20538:90fd0826c6ce

finish converting the rest of stuff to the new soap api, signing on, getting address book seems to work, other blist management stuff not tested yet
author Ka-Hing Cheung <khc@hxbc.us>
date Wed, 24 Oct 2007 06:35:54 +0000
parents f6dff814d95f
children aa875e77e5ce d31843a6b3bb ca624eda4267 e64e6fbd1351 49b311889c10
comparison
equal deleted inserted replaced
20537:c49b886231d5 20538:90fd0826c6ce
26 26
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 32
32 const char *MsnSoapPartnerScenarioText[] = 33 const char *MsnSoapPartnerScenarioText[] =
33 { 34 {
34 "Initial", 35 "Initial",
35 "ContactSave", 36 "ContactSave",
45 "Block", 46 "Block",
46 "Reverse", 47 "Reverse",
47 "Pending" 48 "Pending"
48 }; 49 };
49 50
51 typedef struct {
52 MsnContact *contact;
53 MsnSoapPartnerScenario which;
54 } GetContactListCbData;
55
50 /* new a contact */ 56 /* new a contact */
51 MsnContact * 57 MsnContact *
52 msn_contact_new(MsnSession *session) 58 msn_contact_new(MsnSession *session)
53 { 59 {
54 MsnContact *contact; 60 MsnContact *contact;
55 61
56 contact = g_new0(MsnContact, 1); 62 contact = g_new0(MsnContact, 1);
57 contact->session = session; 63 contact->session = session;
58 contact->soapconn = msn_soap_new(session,contact,1);
59 64
60 return contact; 65 return contact;
61 } 66 }
62 67
63 /* destroy the contact */ 68 /* destroy the contact */
64 void 69 void
65 msn_contact_destroy(MsnContact *contact) 70 msn_contact_destroy(MsnContact *contact)
66 { 71 {
67 msn_soap_destroy(contact->soapconn);
68 g_free(contact); 72 g_free(contact);
69 } 73 }
70 74
71 MsnCallbackState * 75 MsnCallbackState *
72 msn_callback_state_new(void) 76 msn_callback_state_new(MsnSession *session)
73 { 77 {
74 return g_new0(MsnCallbackState, 1); 78 MsnCallbackState *state = g_new0(MsnCallbackState, 1);
79
80 state->session = session;
81
82 return state;
75 } 83 }
76 84
77 void 85 void
78 msn_callback_state_free(MsnCallbackState *state) 86 msn_callback_state_free(MsnCallbackState *state)
79 { 87 {
172 msn_callback_state_set_action(MsnCallbackState *state, MsnCallbackAction action) 180 msn_callback_state_set_action(MsnCallbackState *state, MsnCallbackAction action)
173 { 181 {
174 g_return_if_fail(state != NULL); 182 g_return_if_fail(state != NULL);
175 183
176 state->action |= action; 184 state->action |= action;
177 }
178
179 /*contact SOAP server login error*/
180 static void
181 msn_contact_login_error_cb(PurpleSslConnection *gsc, PurpleSslErrorType error, void *data)
182 {
183 MsnSoapConn *soapconn = data;
184 MsnSession *session;
185
186 session = soapconn->session;
187 g_return_if_fail(session != NULL);
188
189 msn_session_set_error(session, MSN_ERROR_SERV_DOWN, _("Unable to connect to contact server"));
190 }
191
192 /*msn contact SOAP server connect process*/
193 static void
194 msn_contact_login_connect_cb(gpointer data, PurpleSslConnection *gsc,
195 PurpleInputCondition cond)
196 {
197 MsnSoapConn *soapconn = data;
198 MsnSession * session;
199 MsnContact *contact;
200
201 contact = soapconn->parent;
202 g_return_if_fail(contact != NULL);
203
204 session = contact->session;
205 g_return_if_fail(session != NULL);
206
207 /*login ok!We can retrieve the contact list*/
208 // msn_get_contact_list(contact, MSN_PS_INITIAL, NULL);
209 } 185 }
210 186
211 /*get MSN member role utility*/ 187 /*get MSN member role utility*/
212 static MsnListId 188 static MsnListId
213 msn_get_memberrole(char * role) 189 msn_get_memberrole(char * role)
242 return MSN_USER_TYPE_UNKNOWN; 218 return MSN_USER_TYPE_UNKNOWN;
243 } 219 }
244 220
245 /* Create the AddressBook in the server, if we don't have one */ 221 /* Create the AddressBook in the server, if we don't have one */
246 static void 222 static void
247 msn_create_address_cb(gpointer data, gint source, PurpleInputCondition cond) 223 msn_create_address_cb(MsnSoapMessage *req, MsnSoapMessage *resp, gpointer data)
248 { 224 {
249 MsnSoapConn *soapconn = data; 225 if (resp && msn_soap_xml_get(resp->xml, "Body/Fault") == NULL) {
250 MsnContact *contact; 226 purple_debug_info("msnab", "Address Book successfully created!\n");
251 227 msn_get_address_book((MsnContact *)data, MSN_PS_INITIAL, NULL, NULL);
252 if (soapconn->body == NULL) 228 } else {
253 return; 229 purple_debug_info("msnab", "Address Book creation failed!\n");
254 230 }
255 contact = soapconn->parent;
256 g_return_if_fail(contact != NULL);
257
258 purple_debug_info("MSN AddressBook", "Address Book successfully created!\n");
259 msn_get_address_book(contact, MSN_PS_INITIAL, NULL, NULL);
260
261 // msn_soap_free_read_buf(soapconn);
262 return;
263 }
264
265 static void
266 msn_create_address_written_cb(gpointer data, gint source, PurpleInputCondition cond)
267 {
268 MsnSoapConn * soapconn = data;
269
270 purple_debug_info("MSN AddressBook","AddressBookAdd written\n");
271 soapconn->read_cb = msn_create_address_cb;
272
273 return;
274 } 231 }
275 232
276 static void 233 static void
277 msn_create_address_book(MsnContact * contact) 234 msn_create_address_book(MsnContact * contact)
278 { 235 {
279 MsnSoapReq *soap_request;
280 gchar *body; 236 gchar *body;
281 237
282 g_return_if_fail(contact != NULL); 238 g_return_if_fail(contact != NULL);
283 g_return_if_fail(contact->session != NULL); 239 g_return_if_fail(contact->session != NULL);
284 g_return_if_fail(contact->session->user != NULL); 240 g_return_if_fail(contact->session->user != NULL);
285 g_return_if_fail(contact->session->user->passport != NULL); 241 g_return_if_fail(contact->session->user->passport != NULL);
286 242
287 purple_debug_info("MSN AddressBook","Creating an Address Book.\n"); 243 purple_debug_info("msnab","Creating an Address Book.\n");
288 244
289 body = g_strdup_printf(MSN_ADD_ADDRESSBOOK_TEMPLATE, contact->session->user->passport); 245 body = g_strdup_printf(MSN_ADD_ADDRESSBOOK_TEMPLATE, contact->session->user->passport);
290 246
291 soap_request = msn_soap_request_new(MSN_CONTACT_SERVER, 247 msn_soap_message_send(contact->session,
292 MSN_ADDRESS_BOOK_POST_URL,MSN_ADD_ADDRESSBOOK_SOAP_ACTION, 248 msn_soap_message_new(MSN_ADD_ADDRESSBOOK_SOAP_ACTION,
293 body, 249 xmlnode_from_str(body, -1)),
294 NULL, 250 MSN_CONTACT_SERVER, MSN_ADDRESS_BOOK_POST_URL, msn_create_address_cb,
295 msn_create_address_cb, 251 contact);
296 msn_create_address_written_cb);
297 msn_soap_post(contact->soapconn, soap_request, msn_contact_connect_init);
298 252
299 g_free(body); 253 g_free(body);
300 254 }
301 return; 255
256 static void
257 msn_parse_each_member(MsnSession *session, xmlnode *member, const char *node,
258 MsnListId list)
259 {
260 char *passport = xmlnode_get_data(xmlnode_get_child(member, node));
261 char *type = xmlnode_get_data(xmlnode_get_child(member, "type"));
262 char *member_id = xmlnode_get_data(xmlnode_get_child(member, "MembershipId"));
263 MsnUser *user = msn_userlist_find_add_user(session->userlist, passport, NULL);
264
265 purple_debug_info("msncl","%s name: %s, Type: %s\n", node, passport, type);
266
267 if (member_id) {
268 user->membership_id[list] = atoi(member_id);
269 }
270
271 msn_got_lst_user(session, user, 1 << list, NULL);
272
273 g_free(passport);
274 g_free(type);
275 g_free(member_id);
276 }
277
278 static void
279 msn_parse_each_service(MsnSession *session, xmlnode *service)
280 {
281 xmlnode *type;
282
283 if ((type = msn_soap_xml_get(service, "Info/Handle/Type"))) {
284 char *type_str = xmlnode_get_data(type);
285
286 if (g_str_equal(type_str, "Profile")) {
287 /* Process Windows Live 'Messenger Roaming Identity' */
288 } else if (g_str_equal(type_str, "Messenger")) {
289 xmlnode *lastchange = xmlnode_get_child(service, "LastChange");
290 char *lastchange_str = xmlnode_get_data(lastchange);
291 xmlnode *membership;
292
293 purple_debug_info("msncl","last change: %s\n", lastchange_str);
294 purple_account_set_string(session->account, "CLLastChange",
295 lastchange_str);
296
297 for (membership = msn_soap_xml_get(service,
298 "Memberships/Membership");
299 membership; membership = xmlnode_get_next_twin(membership)) {
300
301 xmlnode *role = xmlnode_get_child(membership, "MemberRole");
302 char *role_str = xmlnode_get_data(role);
303 MsnListId list = msn_get_memberrole(role_str);
304 xmlnode *member;
305
306 purple_debug_info("msncl", "MemberRole role: %s, list: %d\n",
307 role, list);
308
309 for (member = msn_soap_xml_get(membership, "Members/Member");
310 member; member = xmlnode_get_next_twin(member)) {
311 const char *member_type = xmlnode_get_attrib(member, "type");
312 if (g_str_equal(member_type, "PassportMember")) {
313 msn_parse_each_member(session, member, "PassportName",
314 list);
315 } else if (g_str_equal(member_type, "PhoneMember")) {
316
317 } else if (g_str_equal(member_type, "EmailMember")) {
318 msn_parse_each_member(session, member, "Email", list);
319 }
320 }
321
322 g_free(role_str);
323 }
324
325 g_free(lastchange_str);
326 }
327
328 g_free(type_str);
329 }
302 } 330 }
303 331
304 /*parse contact list*/ 332 /*parse contact list*/
305 static void 333 static void
306 msn_parse_contact_list(MsnContact * contact) 334 msn_parse_contact_list(MsnContact *contact, xmlnode *node)
307 { 335 {
308 MsnSession * session; 336 xmlnode *fault, *faultnode;
309 MsnListOp list_op = 0; 337
310 MsnListId list; 338 /* we may get a response if our cache data is too old:
311 char * passport, *typedata; 339 *
312 xmlnode *fault, *faultstringnode, *faultdetail, *errorcode; 340 * <faultstring>Need to do full sync. Can't sync deltas Client
313 xmlnode *node, *body, *response, *result, *services; 341 * has too old a copy for us to do a delta sync</faultstring>
314 xmlnode *service, *memberships, *info, *handle, *handletype; 342 *
315 xmlnode *LastChangeNode; 343 * this is not handled yet
316 xmlnode *membershipnode, *members, *member, *passportNode; 344 */
317 char *LastChangeStr; 345 if ((fault = msn_soap_xml_get(node, "Body/Fault"))) {
318 346 if ((faultnode = xmlnode_get_child(fault, "faultstring"))) {
319 session = contact->session; 347 char *faultstring = xmlnode_get_data(faultnode);
320 node = xmlnode_from_str(contact->soapconn->body, contact->soapconn->body_len); 348 purple_debug_info("msncl", "Retrieving contact list failed: %s\n",
321 349 faultstring);
322 if (node == NULL) {
323 purple_debug_error("MSNCL","Unable to parse SOAP data!\n");
324 return;
325 }
326
327 purple_debug_misc("MSNCL","Parsing contact list with size %d\n", contact->soapconn->body_len);
328
329 purple_debug_misc("MSNCL","Root node @ %p: Name: '%s', child: '%s', lastchild: '%s'\n",node,node->name,node->child->name,node->lastchild->name);
330 body = xmlnode_get_child(node,"Body");
331
332 if (body == NULL) {
333 purple_debug_warning("MSNCL", "Failed to parse contact list Body node\n");
334 xmlnode_free(node);
335 return;
336 }
337 purple_debug_info("MSNCL","Body @ %p: Name: '%s'\n",body,body->name);
338
339 /* Did we receive a <Fault> ? */
340 if ( (fault = xmlnode_get_child(body, "Fault")) != NULL) {
341 purple_debug_info("MSNCL","Fault received from SOAP server!\n");
342
343 if ( (faultstringnode = xmlnode_get_child(fault, "faultstring")) != NULL ) {
344 gchar * faultstring = xmlnode_get_data(faultstringnode);
345 purple_debug_info("MSNCL","Faultstring: %s\n", faultstring);
346 g_free(faultstring); 350 g_free(faultstring);
347 } 351 }
348 if ( (faultdetail = xmlnode_get_child(fault, "detail")) != NULL ) { 352 if ((faultnode = msn_soap_xml_get(fault, "detail/errorcode"))) {
349 purple_debug_info("MSNCL","detail @ %p, name: %s\n",faultdetail, faultdetail->name); 353 char *errorcode = xmlnode_get_data(faultnode);
350 354
351 if ( (errorcode = xmlnode_get_child(faultdetail, "errorcode")) != NULL ) { 355 if (g_str_equal(errorcode, "ABDoesNotExist")) {
352 purple_debug_info("MSNCL","errorcode @ %p, name: %s\n",errorcode, errorcode->name); 356 msn_create_address_book(contact);
353 357 g_free(errorcode);
354 if (errorcode->child != NULL) {
355 gchar *errorcodestring = xmlnode_get_data(errorcode);
356 purple_debug_info("MSNCL", "Error Code: %s\n", errorcodestring);
357
358 if ( !strncmp(errorcodestring, "ABDoesNotExist", 14) ) {
359 xmlnode_free(node);
360 g_free(errorcodestring);
361 msn_create_address_book(contact);
362 return;
363 }
364 g_free(errorcodestring);
365 }
366 }
367 }
368 xmlnode_free(node);
369 msn_get_contact_list(contact, MSN_PS_INITIAL, NULL);
370 return;
371 }
372
373 response = xmlnode_get_child(body,"FindMembershipResponse");
374
375 if (response == NULL) {
376 /* we may get a response if our cache data is too old:
377 *
378 * <faultstring>Need to do full sync. Can't sync deltas Client
379 * has too old a copy for us to do a delta sync</faultstring>
380 */
381 xmlnode_free(node);
382 msn_get_contact_list(contact, MSN_PS_INITIAL, NULL);
383 return;
384 }
385 purple_debug_info("MSNCL","FindMembershipResponse @ %p: Name: '%s'\n",response,response->name);
386
387 result = xmlnode_get_child(response,"FindMembershipResult");
388 if (result == NULL) {
389 purple_debug_warning("MSNCL","Received No Update!\n");
390 xmlnode_free(node);
391 return;
392 }
393 purple_debug_info("MSNCL","Result @ %p: Name: '%s'\n", result, result->name);
394
395 if ( (services = xmlnode_get_child(result,"Services")) == NULL) {
396 purple_debug_misc("MSNCL","No <Services> received.\n");
397 xmlnode_free(node);
398 return;
399 }
400
401 purple_debug_info("MSNCL","Services @ %p\n",services);
402
403 for (service = xmlnode_get_child(services, "Service"); service;
404 service = xmlnode_get_next_twin(service)) {
405 purple_debug_info("MSNCL","Service @ %p\n",service);
406
407 if ( (info = xmlnode_get_child(service,"Info")) == NULL ) {
408 purple_debug_error("MSNCL","Error getting 'Info' child node\n");
409 continue;
410 }
411 if ( (handle = xmlnode_get_child(info,"Handle")) == NULL ) {
412 purple_debug_error("MSNCL","Error getting 'Handle' child node\n");
413 continue;
414 }
415 if ( (handletype = xmlnode_get_child(handle,"Type")) == NULL ) {
416 purple_debug_error("MSNCL","Error getting 'Type' child node\n");
417 continue;
418 }
419
420 if ( (typedata = xmlnode_get_data(handletype)) == NULL) {
421 purple_debug_error("MSNCL","Error retrieving data from 'Type' child node\n");
422 g_free(typedata);
423 continue;
424 }
425
426 purple_debug_info("MSNCL","processing '%s' Service\n", typedata);
427
428 if ( !g_strcasecmp(typedata, "Profile") ) {
429 /* Process Windows Live 'Messenger Roaming Identity' */
430 g_free(typedata);
431 continue;
432 }
433
434 if ( !g_strcasecmp(typedata, "Messenger") ) {
435
436 /*Last Change Node*/
437 LastChangeNode = xmlnode_get_child(service, "LastChange");
438 LastChangeStr = xmlnode_get_data(LastChangeNode);
439 purple_debug_info("MSNCL","LastChangeNode: '%s'\n",LastChangeStr);
440 purple_account_set_string(session->account, "CLLastChange", LastChangeStr);
441 g_free(LastChangeStr);
442
443 memberships = xmlnode_get_child(service,"Memberships");
444 if (memberships == NULL) {
445 purple_debug_warning("MSNCL","Memberships = NULL, cleaning up and returning.\n");
446 g_free(typedata);
447 xmlnode_free(node);
448 return; 358 return;
449 } 359 }
450 purple_debug_info("MSNCL","Memberships @ %p: Name: '%s'\n",memberships,memberships->name); 360
451 for (membershipnode = xmlnode_get_child(memberships, "Membership"); membershipnode; 361 g_free(errorcode);
452 membershipnode = xmlnode_get_next_twin(membershipnode)){ 362 }
453 xmlnode *roleNode; 363
454 char *role; 364 msn_get_contact_list(contact, MSN_PS_INITIAL, NULL);
455 365 } else {
456 roleNode = xmlnode_get_child(membershipnode,"MemberRole"); 366 xmlnode *service;
457 role = xmlnode_get_data(roleNode); 367
458 list = msn_get_memberrole(role); 368 for (service = msn_soap_xml_get(node, "Body/FindMembershipResponse/"
459 list_op = 1 << list; 369 "FindMembershipResult/Services/Service");
460 370 service; service = xmlnode_get_next_twin(service)) {
461 purple_debug_info("MSNCL","MemberRole role: %s, list_op: %d\n",role,list_op); 371 msn_parse_each_service(contact->session, service);
462 372 }
463 g_free(role); 373 }
464 374 }
465 members = xmlnode_get_child(membershipnode,"Members"); 375
466 for (member = xmlnode_get_child(members, "Member"); member; 376 static void
467 member = xmlnode_get_next_twin(member)){ 377 msn_get_contact_list_cb(MsnSoapMessage *req, MsnSoapMessage *resp,
468 MsnUser *user = NULL; 378 gpointer data)
469 xmlnode *typeNode, *membershipIdNode=NULL; 379 {
470 gchar *type, *membershipId = NULL; 380 GetContactListCbData *cb_data = data;
471 381 MsnContact *contact = cb_data->contact;
472 purple_debug_info("MSNCL","Member type: %s\n", xmlnode_get_attrib(member,"type")); 382 MsnSession *session = contact->session;
473 383
474 if( !g_strcasecmp(xmlnode_get_attrib(member,"type"), "PassportMember") ) {
475 passportNode = xmlnode_get_child(member,"PassportName");
476 passport = xmlnode_get_data(passportNode);
477 typeNode = xmlnode_get_child(member,"Type");
478 type = xmlnode_get_data(typeNode);
479 purple_debug_info("MSNCL","Passport name: '%s', Type: %s\n",passport,type);
480 g_free(type);
481
482 user = msn_userlist_find_add_user(session->userlist,passport,NULL);
483
484 membershipIdNode = xmlnode_get_child(member,"MembershipId");
485 if (membershipIdNode != NULL) {
486 membershipId = xmlnode_get_data(membershipIdNode);
487 if (membershipId != NULL) {
488 user->membership_id[list] = atoi(membershipId);
489 g_free(membershipId);
490 }
491 }
492
493 msn_got_lst_user(session, user, list_op, NULL);
494
495 g_free(passport);
496 }
497
498 if (!g_strcasecmp(xmlnode_get_attrib(member,"type"),"PhoneMember")) {
499 }
500
501 if (!g_strcasecmp(xmlnode_get_attrib(member,"type"),"EmailMember")) {
502 xmlnode *emailNode;
503
504 emailNode = xmlnode_get_child(member,"Email");
505 passport = xmlnode_get_data(emailNode);
506 purple_debug_info("MSNCL","Email Member: Name: '%s', list_op: %d\n", passport, list_op);
507 user = msn_userlist_find_add_user(session->userlist, passport, NULL);
508
509 membershipIdNode = xmlnode_get_child(member,"MembershipId");
510 if (membershipIdNode != NULL) {
511 membershipId = xmlnode_get_data(membershipIdNode);
512 if (membershipId != NULL) {
513 user->membership_id[list] = atoi(membershipId);
514 g_free(membershipId);
515 }
516 }
517
518 msn_got_lst_user(session, user, list_op, NULL);
519 g_free(passport);
520 }
521 }
522 }
523 g_free(typedata); /* Free 'Type' node data after processing 'Messenger' Service */
524 }
525 }
526
527 xmlnode_free(node); /* Free the whole XML tree */
528 }
529
530 static void
531 msn_get_contact_list_cb(gpointer data, gint source, PurpleInputCondition cond)
532 {
533 MsnSoapConn *soapconn = data;
534 MsnContact *contact;
535 MsnSession *session;
536 const char *abLastChange;
537 const char *dynamicItemLastChange;
538 gchar *partner_scenario;
539
540 if (soapconn->body == NULL)
541 return;
542
543 purple_debug_misc("MSNCL","Got the contact list!\n");
544
545 contact = soapconn->parent;
546 g_return_if_fail(contact != NULL);
547 session = soapconn->session;
548 g_return_if_fail(session != NULL); 384 g_return_if_fail(session != NULL);
549 g_return_if_fail(soapconn->data_cb != NULL); 385
550 386 if (resp != NULL) {
551 partner_scenario = soapconn->data_cb; 387 const char *abLastChange;
552 388 const char *dynamicItemLastChange;
553 msn_parse_contact_list(contact); 389
554 /*free the read buffer*/ 390 purple_debug_misc("msncl","Got the contact list!\n");
555 msn_soap_free_read_buf(soapconn); 391
556 392 msn_parse_contact_list(cb_data->contact, resp->xml);
557 abLastChange = purple_account_get_string(session->account, "ablastChange", NULL); 393 abLastChange = purple_account_get_string(session->account,
558 dynamicItemLastChange = purple_account_get_string(session->account, "dynamicItemLastChange", NULL); 394 "ablastChange", NULL);
559 395 dynamicItemLastChange = purple_account_get_string(session->account,
560 if (!strcmp(partner_scenario, MsnSoapPartnerScenarioText[MSN_PS_INITIAL])) { 396 "dynamicItemLastChange", NULL);
561 397
398 if (cb_data->which == MSN_PS_INITIAL) {
562 #ifdef MSN_PARTIAL_LISTS 399 #ifdef MSN_PARTIAL_LISTS
563 /* XXX: this should be enabled when we can correctly do partial 400 /* XXX: this should be enabled when we can correctly do partial
564 syncs with the server. Currently we need to retrieve the whole 401 syncs with the server. Currently we need to retrieve the whole
565 list to detect sync issues */ 402 list to detect sync issues */
566 msn_get_address_book(contact, MSN_PS_INITIAL, abLastChange, dynamicItemLastChange); 403 msn_get_address_book(contact, MSN_PS_INITIAL, abLastChange, dynamicItemLastChange);
567 #else 404 #else
568 msn_get_address_book(contact, MSN_PS_INITIAL, NULL, NULL); 405 msn_get_address_book(contact, MSN_PS_INITIAL, NULL, NULL);
569 #endif 406 #endif
570 } else { 407 }
571 msn_soap_free_read_buf(soapconn); 408 }
572 } 409
573 } 410 g_free(cb_data);
574
575 static void
576 msn_get_contact_written_cb(gpointer data, gint source, PurpleInputCondition cond)
577 {
578 MsnSoapConn * soapconn = data;
579
580 purple_debug_misc("MSNCL","Sent SOAP request for the contact list.\n");
581 soapconn->read_cb = msn_get_contact_list_cb;
582 // msn_soap_read_cb(data,source,cond);
583 } 411 }
584 412
585 /*SOAP get contact list*/ 413 /*SOAP get contact list*/
586 void 414 void
587 msn_get_contact_list(MsnContact * contact, const MsnSoapPartnerScenario partner_scenario, const char *update_time) 415 msn_get_contact_list(MsnContact * contact,
588 { 416 const MsnSoapPartnerScenario partner_scenario, const char *update_time)
589 MsnSoapReq *soap_request; 417 {
590 gchar *body = NULL; 418 gchar *body = NULL;
591 gchar * update_str; 419 gchar * update_str;
420 GetContactListCbData cb_data = { contact, partner_scenario };
592 const gchar *partner_scenario_str = MsnSoapPartnerScenarioText[partner_scenario]; 421 const gchar *partner_scenario_str = MsnSoapPartnerScenarioText[partner_scenario];
593 422
594 purple_debug_misc("MSNCL","Getting Contact List.\n"); 423 purple_debug_misc("MSNCL","Getting Contact List.\n");
595 424
596 if ( update_time != NULL ) { 425 if ( update_time != NULL ) {
598 update_str = g_strdup_printf(MSN_GET_CONTACT_UPDATE_XML,update_time); 427 update_str = g_strdup_printf(MSN_GET_CONTACT_UPDATE_XML,update_time);
599 } else { 428 } else {
600 update_str = g_strdup(""); 429 update_str = g_strdup("");
601 } 430 }
602 431
603 body = g_strdup_printf(MSN_GET_CONTACT_TEMPLATE, partner_scenario_str, update_str); 432 body = g_strdup_printf(MSN_GET_CONTACT_TEMPLATE, partner_scenario_str,
433 update_str);
434
435 msn_soap_message_send(contact->session,
436 msn_soap_message_new(MSN_GET_CONTACT_SOAP_ACTION,
437 xmlnode_from_str(body, -1)),
438 MSN_CONTACT_SERVER, MSN_GET_CONTACT_POST_URL,
439 msn_get_contact_list_cb, g_memdup(&cb_data, sizeof(cb_data)));
440
604 g_free(update_str); 441 g_free(update_str);
605
606 soap_request = msn_soap_request_new(MSN_CONTACT_SERVER,
607 MSN_GET_CONTACT_POST_URL,
608 MSN_GET_CONTACT_SOAP_ACTION,
609 body,
610 (gpointer) partner_scenario_str,
611 msn_get_contact_list_cb,
612 msn_get_contact_written_cb);
613 msn_soap_post(contact->soapconn,soap_request,msn_contact_connect_init);
614 g_free(body); 442 g_free(body);
615 } 443 }
616 444
617 static void 445 static void
618 msn_parse_addressbook_groups(MsnContact *contact, xmlnode *node) 446 msn_parse_addressbook_groups(MsnContact *contact, xmlnode *node)
619 { 447 {
620 MsnSession *session = contact->session; 448 MsnSession *session = contact->session;
621 xmlnode *group; 449 xmlnode *group;
622 450
623 purple_debug_info("MsnAb","msn_parse_addressbook_groups()\n"); 451 purple_debug_info("MSNAB","msn_parse_addressbook_groups()\n");
624 452
625 for(group = xmlnode_get_child(node, "Group"); group; 453 for(group = xmlnode_get_child(node, "Group"); group;
626 group = xmlnode_get_next_twin(group)){ 454 group = xmlnode_get_next_twin(group)){
627 xmlnode *groupId, *groupInfo, *groupname; 455 xmlnode *groupId, *groupInfo, *groupname;
628 char *group_id, *group_name; 456 char *group_id, *group_name;
773 msn_got_lst_user(session, user, MSN_LIST_FL_OP, NULL); 601 msn_got_lst_user(session, user, MSN_LIST_FL_OP, NULL);
774 } 602 }
775 } 603 }
776 604
777 static gboolean 605 static gboolean
778 msn_parse_addressbook(MsnContact * contact) 606 msn_parse_addressbook(MsnContact * contact, xmlnode *node)
779 { 607 {
780 MsnSession * session; 608 MsnSession * session;
781 xmlnode * node,*body,*response,*result; 609 xmlnode *result;
782 xmlnode *groups; 610 xmlnode *groups;
783 xmlnode *contacts; 611 xmlnode *contacts;
784 xmlnode *abNode; 612 xmlnode *abNode;
785 xmlnode *fault, *faultstringnode, *faultdetail, *errorcode; 613 xmlnode *fault;
786 614
787 session = contact->session; 615 session = contact->session;
788 616
789 617 if ((fault = msn_soap_xml_get(node, "Body/Fault"))) {
790 618 xmlnode *faultnode;
791 node = xmlnode_from_str(contact->soapconn->body, contact->soapconn->body_len); 619
792 if ( node == NULL ) { 620 if ((faultnode = xmlnode_get_child(fault, "faultstring"))) {
793 purple_debug_error("MSN AddressBook","Error parsing Address Book with size %d\n", contact->soapconn->body_len); 621 gchar *faultstring = xmlnode_get_data(faultnode);
622 purple_debug_info("MSNAB","Faultstring: %s\n", faultstring);
623 g_free(faultstring);
624 }
625
626 if ((faultnode = msn_soap_xml_get(fault, "detail/errorcode"))) {
627 gchar *errorcode = xmlnode_get_data(faultnode);
628
629 purple_debug_info("MSNAB", "Error Code: %s\n", errorcode);
630
631 if (g_str_equal(errorcode, "ABDoesNotExist")) {
632 g_free(errorcode);
633 return TRUE;
634 }
635 }
636
794 return FALSE; 637 return FALSE;
795 } 638 }
796 639
797 purple_debug_misc("MSN AddressBook", "Parsing Address Book with size %d\n", contact->soapconn->body_len); 640 result = msn_soap_xml_get(node, "Body/ABFindAllResponse/ABFindAllResult");
798
799 purple_debug_misc("MSN AddressBook","node{%p},name:%s,child:%s,last:%s\n",node,node->name,node->child->name,node->lastchild->name);
800
801 body = xmlnode_get_child(node,"Body");
802 purple_debug_misc("MSN AddressBook","body{%p},name:%s\n",body,body->name);
803
804 if ( (fault = xmlnode_get_child(body, "Fault")) != NULL) {
805 purple_debug_info("MSN AddressBook","Fault received from SOAP server!\n");
806
807 if ( (faultstringnode = xmlnode_get_child(fault, "faultstring")) != NULL ) {
808 gchar *faultstring = xmlnode_get_data(faultstringnode);
809 purple_debug_info("MSN AddressBook","Faultstring: %s\n", faultstring);
810 g_free(faultstring);
811 }
812 if ( (faultdetail = xmlnode_get_child(fault, "detail")) != NULL ) {
813 purple_debug_info("MSN AddressBook","detail @ %p, name: %s\n",faultdetail, faultdetail->name);
814
815 if ( (errorcode = xmlnode_get_child(faultdetail, "errorcode")) != NULL ) {
816 gchar *errorcodestring;
817 purple_debug_info("MSN AddressBook","errorcode @ %p, name: %s\n",errorcode, errorcode->name);
818
819 errorcodestring = xmlnode_get_data(errorcode);
820 purple_debug_info("MSN AddressBook", "Error Code: %s\n", errorcodestring);
821
822 if ( !strncmp(errorcodestring, "ABDoesNotExist", 14) ) {
823 g_free(errorcodestring);
824 xmlnode_free(node);
825 return TRUE;
826 }
827 g_free(errorcodestring);
828 }
829 }
830 xmlnode_free(node);
831 return FALSE;
832 }
833
834
835 response = xmlnode_get_child(body,"ABFindAllResponse");
836
837 if (response == NULL) {
838 xmlnode_free(node);
839 return FALSE;
840 }
841
842 purple_debug_misc("MSN SOAP","response{%p},name:%s\n",response,response->name);
843 result = xmlnode_get_child(response,"ABFindAllResult");
844 if(result == NULL){ 641 if(result == NULL){
845 purple_debug_misc("MSNAB","receive no address book update\n"); 642 purple_debug_misc("MSNAB","receive no address book update\n");
846 xmlnode_free(node);
847 return TRUE; 643 return TRUE;
848 } 644 }
849 purple_debug_info("MSN SOAP","result{%p},name:%s\n",result,result->name); 645
850 646 /* I don't see this "groups" tag documented on msnpiki, need to find out
647 if they are really there, and update msnpiki */
851 /*Process Group List*/ 648 /*Process Group List*/
852 groups = xmlnode_get_child(result,"groups"); 649 groups = xmlnode_get_child(result,"groups");
853 if (groups != NULL) { 650 if (groups != NULL) {
854 msn_parse_addressbook_groups(contact, groups); 651 msn_parse_addressbook_groups(contact, groups);
855 } 652 }
856 653
857 /*add a default No group to set up the no group Membership*/ 654 /*add a default No group to set up the no group Membership*/
858 msn_group_new(session->userlist, MSN_INDIVIDUALS_GROUP_ID, 655 msn_group_new(session->userlist, MSN_INDIVIDUALS_GROUP_ID,
859 MSN_INDIVIDUALS_GROUP_NAME); 656 MSN_INDIVIDUALS_GROUP_NAME);
860 purple_debug_misc("MsnAB","group_id:%s name:%s\n", 657 purple_debug_misc("MSNAB","group_id:%s name:%s\n",
861 MSN_INDIVIDUALS_GROUP_ID, MSN_INDIVIDUALS_GROUP_NAME); 658 MSN_INDIVIDUALS_GROUP_ID, MSN_INDIVIDUALS_GROUP_NAME);
862 if ((purple_find_group(MSN_INDIVIDUALS_GROUP_NAME)) == NULL){ 659 if ((purple_find_group(MSN_INDIVIDUALS_GROUP_NAME)) == NULL){
863 PurpleGroup *g = purple_group_new(MSN_INDIVIDUALS_GROUP_NAME); 660 PurpleGroup *g = purple_group_new(MSN_INDIVIDUALS_GROUP_NAME);
864 purple_blist_add_group(g, NULL); 661 purple_blist_add_group(g, NULL);
865 } 662 }
866 663
867 /*add a default No group to set up the no group Membership*/ 664 /*add a default No group to set up the no group Membership*/
868 msn_group_new(session->userlist, MSN_NON_IM_GROUP_ID, MSN_NON_IM_GROUP_NAME); 665 msn_group_new(session->userlist, MSN_NON_IM_GROUP_ID, MSN_NON_IM_GROUP_NAME);
869 purple_debug_misc("MsnAB","group_id:%s name:%s\n", MSN_NON_IM_GROUP_ID, MSN_NON_IM_GROUP_NAME); 666 purple_debug_misc("MSNAB","group_id:%s name:%s\n", MSN_NON_IM_GROUP_ID, MSN_NON_IM_GROUP_NAME);
870 if ((purple_find_group(MSN_NON_IM_GROUP_NAME)) == NULL){ 667 if ((purple_find_group(MSN_NON_IM_GROUP_NAME)) == NULL){
871 PurpleGroup *g = purple_group_new(MSN_NON_IM_GROUP_NAME); 668 PurpleGroup *g = purple_group_new(MSN_NON_IM_GROUP_NAME);
872 purple_blist_add_group(g, NULL); 669 purple_blist_add_group(g, NULL);
873 } 670 }
874 671
884 xmlnode *LastChangeNode, *DynamicItemLastChangedNode; 681 xmlnode *LastChangeNode, *DynamicItemLastChangedNode;
885 char *lastchange, *dynamicChange; 682 char *lastchange, *dynamicChange;
886 683
887 LastChangeNode = xmlnode_get_child(abNode,"lastChange"); 684 LastChangeNode = xmlnode_get_child(abNode,"lastChange");
888 lastchange = xmlnode_get_data(LastChangeNode); 685 lastchange = xmlnode_get_data(LastChangeNode);
889 purple_debug_info("MsnAB"," lastchanged Time:{%s}\n",lastchange); 686 purple_debug_info("MSNAB"," lastchanged Time:{%s}\n",lastchange);
890 purple_account_set_string(session->account, "ablastChange", lastchange); 687 purple_account_set_string(session->account, "ablastChange", lastchange);
891 688
892 DynamicItemLastChangedNode = xmlnode_get_child(abNode,"DynamicItemLastChanged"); 689 DynamicItemLastChangedNode = xmlnode_get_child(abNode,"DynamicItemLastChanged");
893 dynamicChange = xmlnode_get_data(DynamicItemLastChangedNode); 690 dynamicChange = xmlnode_get_data(DynamicItemLastChangedNode);
894 purple_debug_info("MsnAB"," DynamicItemLastChanged :{%s}\n",dynamicChange); 691 purple_debug_info("MSNAB"," DynamicItemLastChanged :{%s}\n",dynamicChange);
895 purple_account_set_string(session->account, "DynamicItemLastChanged", lastchange); 692 purple_account_set_string(session->account, "DynamicItemLastChanged", lastchange);
896 g_free(dynamicChange); 693 g_free(dynamicChange);
897 g_free(lastchange); 694 g_free(lastchange);
898 } 695 }
899 696
900 xmlnode_free(node);
901 msn_soap_free_read_buf(contact->soapconn);
902 return TRUE; 697 return TRUE;
903 } 698 }
904 699
905 static void 700 static void
906 msn_get_address_cb(gpointer data, gint source, PurpleInputCondition cond) 701 msn_get_address_cb(MsnSoapMessage *req, MsnSoapMessage *resp, gpointer data)
907 { 702 {
908 MsnSoapConn * soapconn = data; 703 MsnContact *contact = data;
909 MsnContact *contact;
910 MsnSession *session; 704 MsnSession *session;
911 705
912 if (soapconn->body == NULL) 706 if (resp == NULL)
913 return; 707 return;
914 708
915 contact = soapconn->parent;
916 g_return_if_fail(contact != NULL); 709 g_return_if_fail(contact != NULL);
917 session = soapconn->session; 710 session = contact->session;
918 g_return_if_fail(session != NULL); 711 g_return_if_fail(session != NULL);
919 712
920 purple_debug_misc("MSN AddressBook", "Got the Address Book!\n"); 713 purple_debug_misc("MSNAB", "Got the Address Book!\n");
921 714
922 if ( msn_parse_addressbook(contact) ) { 715 if (msn_parse_addressbook(contact, resp->xml)) {
923 //msn_soap_free_read_buf(soapconn);
924
925 if (!session->logged_in) { 716 if (!session->logged_in) {
926 msn_send_privacy(session->account->gc); 717 msn_send_privacy(session->account->gc);
927 msn_notification_dump_contact(session); 718 msn_notification_dump_contact(session);
928 } 719 }
929 } else { 720 } else {
930 /* This is making us loop infinitely when we fail to parse the address book, 721 /* This is making us loop infinitely when we fail to parse the
931 disable for now (we should re-enable when we send timestamps) 722 address book, disable for now (we should re-enable when we
723 send timestamps)
932 */ 724 */
933 /* 725 /*
934 msn_get_address_book(contact, NULL, NULL); 726 msn_get_address_book(contact, NULL, NULL);
935 */ 727 */
936 msn_session_disconnect(session); 728 msn_session_disconnect(session);
937 purple_connection_error(session->account->gc, _("Unable to retrieve MSN Address Book")); 729 purple_connection_error(session->account->gc, _("Unable to retrieve MSN Address Book"));
938 } 730 }
939
940 /*free the read buffer*/
941 msn_soap_free_read_buf(soapconn);
942 }
943
944 /**/
945 static void
946 msn_address_written_cb(gpointer data, gint source, PurpleInputCondition cond)
947 {
948 MsnSoapConn * soapconn = data;
949
950 purple_debug_misc("MSN AddressBook","Sent SOAP request for the Address Book.\n");
951 soapconn->read_cb = msn_get_address_cb;
952 } 731 }
953 732
954 /*get the address book*/ 733 /*get the address book*/
955 void 734 void
956 msn_get_address_book(MsnContact *contact, const MsnSoapPartnerScenario partner_scenario, const char *LastChanged, const char *dynamicItemLastChange) 735 msn_get_address_book(MsnContact *contact,
957 { 736 MsnSoapPartnerScenario partner_scenario, const char *LastChanged,
958 MsnSoapReq *soap_request; 737 const char *dynamicItemLastChange)
738 {
959 char *body = NULL; 739 char *body = NULL;
960 char *ab_update_str,*update_str; 740 char *ab_update_str,*update_str;
961 741
962 purple_debug_misc("MSN AddressBook","Getting Address Book\n"); 742 purple_debug_misc("MSNAB","Getting Address Book\n");
963 743
964 /*build SOAP and POST it*/ 744 /*build SOAP and POST it*/
965 if ( LastChanged != NULL ) { 745 if ( LastChanged != NULL ) {
966 ab_update_str = g_strdup_printf(MSN_GET_ADDRESS_UPDATE_XML,LastChanged); 746 ab_update_str = g_strdup_printf(MSN_GET_ADDRESS_UPDATE_XML,LastChanged);
967 } else { 747 } else {
971 update_str = g_strdup_printf(MSN_GET_ADDRESS_UPDATE_XML, 751 update_str = g_strdup_printf(MSN_GET_ADDRESS_UPDATE_XML,
972 dynamicItemLastChange); 752 dynamicItemLastChange);
973 } else { 753 } else {
974 update_str = g_strdup(ab_update_str); 754 update_str = g_strdup(ab_update_str);
975 } 755 }
976 g_free(ab_update_str); 756
977
978
979 body = g_strdup_printf(MSN_GET_ADDRESS_TEMPLATE, MsnSoapPartnerScenarioText[partner_scenario], update_str); 757 body = g_strdup_printf(MSN_GET_ADDRESS_TEMPLATE, MsnSoapPartnerScenarioText[partner_scenario], update_str);
980 g_free(update_str); 758 g_free(update_str);
981 759
982 soap_request = msn_soap_request_new(MSN_CONTACT_SERVER, 760 msn_soap_message_send(contact->session,
983 MSN_ADDRESS_BOOK_POST_URL,MSN_GET_ADDRESS_SOAP_ACTION, 761 msn_soap_message_new(MSN_GET_ADDRESS_SOAP_ACTION,
984 body, 762 xmlnode_from_str(body, -1)),
985 NULL, 763 MSN_CONTACT_SERVER, MSN_ADDRESS_BOOK_POST_URL, msn_get_address_cb,
986 msn_get_address_cb, 764 contact);
987 msn_address_written_cb); 765
988 msn_soap_post(contact->soapconn,soap_request,msn_contact_connect_init); 766 g_free(ab_update_str);
989 g_free(body); 767 g_free(body);
990 } 768 }
991 769
992 static void 770 static void
993 msn_add_contact_read_cb(gpointer data, gint source, PurpleInputCondition cond) 771 msn_add_contact_read_cb(MsnSoapMessage *req, MsnSoapMessage *resp,
994 { 772 gpointer data)
995 MsnSoapConn * soapconn = data; 773 {
996 MsnCallbackState *state = NULL; 774 MsnCallbackState *state = data;
997 MsnUserList *userlist; 775 MsnSession *session = state->session;
998 MsnUser *user; 776
999 777 g_return_if_fail(session != NULL);
1000 g_return_if_fail(soapconn->data_cb != NULL); 778
1001 g_return_if_fail(soapconn->session != NULL); 779 if (resp != NULL) {
1002 g_return_if_fail(soapconn->session->userlist != NULL); 780 MsnUserList *userlist = session->userlist;
1003 781 MsnUser *user;
1004 state = (MsnCallbackState *) soapconn->data_cb; 782
1005 783 purple_debug_info("MSNCL","Contact added successfully\n");
1006 if (soapconn->body == NULL) { 784
1007 msn_callback_state_free(state); 785 // the code this block is replacing didn't send ADL for yahoo contacts,
1008 return; 786 // but i haven't confirmed this is WLM's behaviour wrt yahoo contacts
1009 } 787
1010 788 if ( !msn_user_is_yahoo(session->account, state->who) ) {
1011 userlist = soapconn->session->userlist;
1012
1013 purple_debug_info("MSNCL","Contact added successfully\n");
1014
1015 // the code this block is replacing didn't send ADL for yahoo contacts,
1016 // but i haven't confirmed this is WLM's behaviour wrt yahoo contacts
1017
1018 if ( !msn_user_is_yahoo(soapconn->session->account, state->who) ) {
1019 789
1020 msn_userlist_add_buddy_to_list(userlist, state->who, MSN_LIST_AL); 790 msn_userlist_add_buddy_to_list(userlist, state->who, MSN_LIST_AL);
1021 msn_userlist_add_buddy_to_list(userlist, state->who, MSN_LIST_FL); 791 msn_userlist_add_buddy_to_list(userlist, state->who, MSN_LIST_FL);
1022 } 792 }
1023 msn_notification_send_fqy(soapconn->session, state->who); 793 msn_notification_send_fqy(session, state->who);
1024 794
1025 user = msn_userlist_find_add_user(userlist, state->who, state->who); 795 user = msn_userlist_find_add_user(userlist, state->who, state->who);
1026 msn_user_add_group_id(user, state->guid); 796 msn_user_add_group_id(user, state->guid);
1027 797
1028 if (msn_userlist_user_is_in_list(user, MSN_LIST_PL)) { 798 if (msn_userlist_user_is_in_list(user, MSN_LIST_PL)) {
1029 msn_del_contact_from_list(soapconn->session->contact, NULL, state->who, MSN_LIST_PL); 799 msn_del_contact_from_list(session->contact, NULL, state->who, MSN_LIST_PL);
1030 } else { 800 }
1031 msn_soap_free_read_buf(soapconn);
1032 } 801 }
1033 802
1034 msn_callback_state_free(state); 803 msn_callback_state_free(state);
1035 } 804 }
1036 805
1037 static void
1038 msn_add_contact_written_cb(gpointer data, gint source, PurpleInputCondition cond)
1039 {
1040 MsnSoapConn * soapconn = data;
1041
1042 purple_debug_info("MSNCL","Add contact request written\n");
1043 soapconn->read_cb = msn_add_contact_read_cb;
1044 }
1045
1046 /* add a Contact in MSN_INDIVIDUALS_GROUP */ 806 /* add a Contact in MSN_INDIVIDUALS_GROUP */
1047 void 807 void
1048 msn_add_contact(MsnContact *contact, MsnCallbackState *state, const char *passport) 808 msn_add_contact(MsnContact *contact, MsnCallbackState *state, const char *passport)
1049 { 809 {
1050 MsnSoapReq *soap_request;
1051 gchar *body = NULL; 810 gchar *body = NULL;
1052 gchar *contact_xml = NULL; 811 gchar *contact_xml = NULL;
1053 gchar *soap_action; 812
1054 /* gchar *escaped_displayname; 813 #if 0
814 gchar *escaped_displayname;
1055 815
1056 816
1057 if (displayname != NULL) { 817 if (displayname != NULL) {
1058 escaped_displayname = g_markup_decode_text(displayname, -1); 818 escaped_displayname = g_markup_decode_text(displayname, -1);
1059 } else { 819 } else {
1060 escaped_displayname = passport; 820 escaped_displayname = passport;
1061 } 821 }
1062 contact_xml = g_strdup_printf(MSN_XML_ADD_CONTACT, escaped_displayname, passport); 822 contact_xml = g_strdup_printf(MSN_XML_ADD_CONTACT, escaped_displayname, passport);
1063 */ 823 #endif
824
1064 purple_debug_info("MSNCL","Adding contact %s to contact list\n", passport); 825 purple_debug_info("MSNCL","Adding contact %s to contact list\n", passport);
1065 826
1066 // if ( !strcmp(state->guid, MSN_INDIVIDUALS_GROUP_ID) ) { 827 contact_xml = g_strdup_printf(MSN_CONTACT_XML, passport);
1067 contact_xml = g_strdup_printf(MSN_CONTACT_XML, passport);
1068 // }
1069 body = g_strdup_printf(MSN_ADD_CONTACT_TEMPLATE, contact_xml); 828 body = g_strdup_printf(MSN_ADD_CONTACT_TEMPLATE, contact_xml);
1070 829
830 msn_soap_message_send(contact->session,
831 msn_soap_message_new(MSN_CONTACT_ADD_SOAP_ACTION,
832 xmlnode_from_str(body, -1)),
833 MSN_CONTACT_SERVER, MSN_ADDRESS_BOOK_POST_URL,
834 msn_add_contact_read_cb, state);
835
1071 g_free(contact_xml); 836 g_free(contact_xml);
1072
1073 /*build SOAP and POST it*/
1074 soap_action = g_strdup(MSN_CONTACT_ADD_SOAP_ACTION);
1075
1076 soap_request = msn_soap_request_new(MSN_CONTACT_SERVER,
1077 MSN_ADDRESS_BOOK_POST_URL,
1078 soap_action,
1079 body,
1080 state,
1081 msn_add_contact_read_cb,
1082 msn_add_contact_written_cb);
1083 msn_soap_post(contact->soapconn,soap_request,msn_contact_connect_init);
1084
1085 g_free(soap_action);
1086 g_free(body); 837 g_free(body);
1087 } 838 }
1088 839
1089 static void 840 static void
1090 msn_add_contact_to_group_read_cb(gpointer data, gint source, PurpleInputCondition cond) 841 msn_add_contact_to_group_read_cb(MsnSoapMessage *req, MsnSoapMessage *resp,
1091 { 842 gpointer data)
1092 MsnSoapConn * soapconn = data; 843 {
1093 MsnCallbackState *state; 844 MsnCallbackState *state = data;
1094 MsnUserList *userlist; 845 MsnUserList *userlist;
1095 846
1096 g_return_if_fail(soapconn->data_cb != NULL); 847 g_return_if_fail(data != NULL);
1097 g_return_if_fail(soapconn->session != NULL); 848
1098 g_return_if_fail(soapconn->session->userlist != NULL); 849 userlist = state->session->userlist;
1099 850
1100 userlist = soapconn->session->userlist; 851 if (resp != NULL) {
1101 852 if (msn_userlist_add_buddy_to_group(userlist, state->who,
1102 state = (MsnCallbackState *) soapconn->data_cb; 853 state->new_group_name)) {
1103 854 purple_debug_info("MSNCL", "Contact %s added to group %s successfully!\n", state->who, state->new_group_name);
1104 if (soapconn->body == NULL) { 855 } else {
1105 msn_callback_state_free(state); 856 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);
1106 return; 857 }
1107 } 858
1108 859 if (state->action & MSN_ADD_BUDDY) {
1109 if (msn_userlist_add_buddy_to_group(userlist, state->who, state->new_group_name) == TRUE) { 860 MsnUser *user = msn_userlist_find_user(userlist, state->who);
1110 purple_debug_info("MSNCL", "Contact %s added to group %s successfully!\n", state->who, state->new_group_name); 861
1111 } else { 862 if ( !msn_user_is_yahoo(state->session->account, state->who) ) {
1112 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); 863
1113 } 864 msn_userlist_add_buddy_to_list(userlist, state->who, MSN_LIST_AL);
1114 865 msn_userlist_add_buddy_to_list(userlist, state->who, MSN_LIST_FL);
1115 if (state->action & MSN_ADD_BUDDY) {
1116 MsnUser *user = msn_userlist_find_user(userlist, state->who);
1117
1118 if ( !msn_user_is_yahoo(soapconn->session->account, state->who) ) {
1119
1120 msn_userlist_add_buddy_to_list(userlist, state->who, MSN_LIST_AL);
1121 msn_userlist_add_buddy_to_list(userlist, state->who, MSN_LIST_FL);
1122 } 866 }
1123 msn_notification_send_fqy(soapconn->session, state->who); 867 msn_notification_send_fqy(state->session, state->who);
1124 868
1125 if (msn_userlist_user_is_in_list(user, MSN_LIST_PL)) { 869 if (msn_userlist_user_is_in_list(user, MSN_LIST_PL)) {
1126 msn_del_contact_from_list(soapconn->session->contact, NULL, state->who, MSN_LIST_PL); 870 msn_del_contact_from_list(state->session->contact, NULL, state->who, MSN_LIST_PL);
1127 msn_callback_state_free(state); 871 msn_callback_state_free(state);
1128 return; 872 return;
1129 } 873 }
1130 } 874 }
1131 875
1132 if (state->action & MSN_MOVE_BUDDY) { 876 if (state->action & MSN_MOVE_BUDDY) {
1133 msn_del_contact_from_group(soapconn->session->contact, state->who, state->old_group_name); 877 msn_del_contact_from_group(state->session->contact, state->who, state->old_group_name);
1134 } else { 878 }
1135 msn_callback_state_free(state); 879 }
1136 msn_soap_free_read_buf(soapconn); 880
1137 } 881 msn_callback_state_free(state);
1138 }
1139
1140 static void
1141 msn_add_contact_to_group_written_cb(gpointer data, gint source, PurpleInputCondition cond)
1142 {
1143 MsnSoapConn * soapconn = data;
1144
1145 purple_debug_info("MSNCL","Add contact to group request sent!\n");
1146 soapconn->read_cb = msn_add_contact_to_group_read_cb;
1147 } 882 }
1148 883
1149 void 884 void
1150 msn_add_contact_to_group(MsnContact *contact, MsnCallbackState *state, 885 msn_add_contact_to_group(MsnContact *contact, MsnCallbackState *state,
1151 const char *passport, const char *groupId) 886 const char *passport, const char *groupId)
1152 { 887 {
1153 MsnSoapReq *soap_request;
1154 MsnUserList *userlist; 888 MsnUserList *userlist;
1155 MsnUser *user; 889 MsnUser *user;
1156 gchar *body = NULL, *soap_action, *contact_xml; 890 gchar *body = NULL, *contact_xml;
1157 891
1158 g_return_if_fail(passport != NULL); 892 g_return_if_fail(passport != NULL);
1159 g_return_if_fail(groupId != NULL); 893 g_return_if_fail(groupId != NULL);
1160 894
1161 g_return_if_fail(contact != NULL); 895 g_return_if_fail(contact != NULL);
1181 } 915 }
1182 916
1183 return; 917 return;
1184 } 918 }
1185 919
1186
1187 purple_debug_info("MSNCL", "Adding user %s to group %s\n", passport, 920 purple_debug_info("MSNCL", "Adding user %s to group %s\n", passport,
1188 msn_userlist_find_group_name(userlist, groupId)); 921 msn_userlist_find_group_name(userlist, groupId));
1189 922
1190 user = msn_userlist_find_user(userlist, passport); 923 user = msn_userlist_find_user(userlist, passport);
1191 if (user == NULL) { 924 if (user == NULL) {
1192 purple_debug_warning("MSN CL", "Unable to retrieve user %s from the userlist!\n", passport); 925 purple_debug_warning("MSNCL", "Unable to retrieve user %s from the userlist!\n", passport);
926 msn_callback_state_free(state);
927 return; /* guess this never happened! */
1193 } 928 }
1194 929
1195 if (user->uid != NULL) { 930 if (user->uid != NULL) {
1196 contact_xml = g_strdup_printf(MSN_CONTACT_ID_XML, user->uid); 931 contact_xml = g_strdup_printf(MSN_CONTACT_ID_XML, user->uid);
1197 } else { 932 } else {
1198 contact_xml = g_strdup_printf(MSN_CONTACT_XML, passport); 933 contact_xml = g_strdup_printf(MSN_CONTACT_XML, passport);
1199 } 934 }
1200 935
1201 body = g_strdup_printf(MSN_ADD_CONTACT_GROUP_TEMPLATE, groupId, contact_xml); 936 body = g_strdup_printf(MSN_ADD_CONTACT_GROUP_TEMPLATE, groupId, contact_xml);
937
938 msn_soap_message_send(state->session,
939 msn_soap_message_new(MSN_ADD_CONTACT_GROUP_SOAP_ACTION,
940 xmlnode_from_str(body, -1)),
941 MSN_CONTACT_SERVER, MSN_ADDRESS_BOOK_POST_URL,
942 msn_add_contact_to_group_read_cb, state);
943
1202 g_free(contact_xml); 944 g_free(contact_xml);
1203
1204 /*build SOAP and POST it*/
1205 soap_action = g_strdup(MSN_ADD_CONTACT_GROUP_SOAP_ACTION);
1206
1207 soap_request = msn_soap_request_new(MSN_CONTACT_SERVER,
1208 MSN_ADDRESS_BOOK_POST_URL,
1209 soap_action,
1210 body,
1211 state,
1212 msn_add_contact_to_group_read_cb,
1213 msn_add_contact_to_group_written_cb);
1214 msn_soap_post(contact->soapconn,soap_request,msn_contact_connect_init);
1215
1216 g_free(soap_action);
1217 g_free(body); 945 g_free(body);
1218 } 946 }
1219 947
1220 948 static void
1221 949 msn_delete_contact_read_cb(MsnSoapMessage *req, MsnSoapMessage *resp,
1222 static void 950 gpointer data)
1223 msn_delete_contact_read_cb(gpointer data, gint source, PurpleInputCondition cond) 951 {
1224 { 952 if (resp == NULL)
1225 MsnSoapConn * soapconn = data;
1226
1227 if (soapconn->body == NULL)
1228 return; 953 return;
1229 954
1230 // we should probably delete it from the userlist aswell 955 // we should probably delete it from the userlist aswell
1231 purple_debug_info("MSNCL","Delete contact successful\n"); 956 purple_debug_info("MSNCL","Delete contact successful\n");
1232 msn_soap_free_read_buf(soapconn);
1233 }
1234
1235 static void
1236 msn_delete_contact_written_cb(gpointer data, gint source, PurpleInputCondition cond)
1237 {
1238 MsnSoapConn * soapconn = data;
1239
1240 purple_debug_info("MSNCL","Delete contact request written\n");
1241 soapconn->read_cb = msn_delete_contact_read_cb;
1242 } 957 }
1243 958
1244 /*delete a Contact*/ 959 /*delete a Contact*/
1245 void 960 void
1246 msn_delete_contact(MsnContact *contact, const char *contactId) 961 msn_delete_contact(MsnContact *contact, const char *contactId)
1247 { 962 {
1248 gchar *body = NULL; 963 gchar *body = NULL;
1249 gchar *contact_id_xml = NULL ; 964 gchar *contact_id_xml = NULL ;
1250 MsnSoapReq *soap_request;
1251 965
1252 g_return_if_fail(contactId != NULL); 966 g_return_if_fail(contactId != NULL);
1253 contact_id_xml = g_strdup_printf(MSN_CONTACT_ID_XML, contactId); 967 contact_id_xml = g_strdup_printf(MSN_CONTACT_ID_XML, contactId);
1254 968
1255 /* build SOAP request */ 969 /* build SOAP request */
1256 purple_debug_info("MSNCL","Deleting contact with contactId: %s\n", contactId); 970 purple_debug_info("MSNCL","Deleting contact with contactId: %s\n", contactId);
1257 body = g_strdup_printf(MSN_DEL_CONTACT_TEMPLATE, contact_id_xml); 971 body = g_strdup_printf(MSN_DEL_CONTACT_TEMPLATE, contact_id_xml);
1258 soap_request = msn_soap_request_new(MSN_CONTACT_SERVER, 972 msn_soap_message_send(contact->session,
1259 MSN_ADDRESS_BOOK_POST_URL, 973 msn_soap_message_new(MSN_CONTACT_DEL_SOAP_ACTION,
1260 MSN_CONTACT_DEL_SOAP_ACTION, 974 xmlnode_from_str(body, -1)),
1261 body, 975 MSN_CONTACT_SERVER, MSN_ADDRESS_BOOK_POST_URL,
1262 NULL, 976 msn_delete_contact_read_cb, NULL);
1263 msn_delete_contact_read_cb,
1264 msn_delete_contact_written_cb);
1265 977
1266 g_free(contact_id_xml); 978 g_free(contact_id_xml);
1267
1268 /* POST the SOAP request */
1269 msn_soap_post(contact->soapconn, soap_request, msn_contact_connect_init);
1270
1271 g_free(body); 979 g_free(body);
1272 } 980 }
1273 981
1274 static void 982 static void
1275 msn_del_contact_from_group_read_cb(gpointer data, gint source, PurpleInputCondition cond) 983 msn_del_contact_from_group_read_cb(MsnSoapMessage *req, MsnSoapMessage *resp,
1276 { 984 gpointer data)
1277 MsnSoapConn * soapconn = data; 985 {
1278 MsnCallbackState *state = (MsnCallbackState *) soapconn->data_cb; 986 MsnCallbackState *state = data;
1279 987
1280 if (soapconn->body == NULL) { 988 if (resp != NULL) {
1281 msn_callback_state_free(state); 989 if (msn_userlist_rem_buddy_from_group(state->session->userlist,
1282 return; 990 state->who, state->old_group_name)) {
1283 } 991 purple_debug_info("MSNCL", "Contact %s deleted successfully from group %s\n", state->who, state->old_group_name);
1284 992 } else {
1285 if (msn_userlist_rem_buddy_from_group(soapconn->session->userlist, state->who, state->old_group_name)) { 993 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);
1286 purple_debug_info("MSN CL", "Contact %s deleted successfully from group %s\n", state->who, state->old_group_name); 994 }
1287 } else {
1288 purple_debug_info("MSN CL", "Contact %s deleted successfully from group %s in the server, but failed in the local list\n", state->who, state->old_group_name);
1289 } 995 }
1290 996
1291 msn_callback_state_free(state); 997 msn_callback_state_free(state);
1292 msn_soap_free_read_buf(soapconn);
1293 return;
1294 }
1295
1296 static void
1297 msn_del_contact_from_group_written_cb(gpointer data, gint source, PurpleInputCondition cond)
1298 {
1299 MsnSoapConn * soapconn = data;
1300
1301 purple_debug_info("MSN CL","Del contact from group request sent!\n");
1302 soapconn->read_cb = msn_del_contact_from_group_read_cb;
1303 } 998 }
1304 999
1305 void 1000 void
1306 msn_del_contact_from_group(MsnContact *contact, const char *passport, const char *group_name) 1001 msn_del_contact_from_group(MsnContact *contact, const char *passport, const char *group_name)
1307 { 1002 {
1308 MsnSoapReq *soap_request;
1309 MsnUserList * userlist; 1003 MsnUserList * userlist;
1310 MsnUser *user; 1004 MsnUser *user;
1311 MsnCallbackState *state; 1005 MsnCallbackState *state;
1312 gchar *body = NULL, *soap_action, *contact_id_xml; 1006 gchar *body, *contact_id_xml;
1313 const gchar *groupId; 1007 const gchar *groupId;
1314 1008
1315 g_return_if_fail(passport != NULL); 1009 g_return_if_fail(passport != NULL);
1316 g_return_if_fail(group_name != NULL); 1010 g_return_if_fail(group_name != NULL);
1317 g_return_if_fail(contact != NULL); 1011 g_return_if_fail(contact != NULL);
1320 1014
1321 userlist = contact->session->userlist; 1015 userlist = contact->session->userlist;
1322 1016
1323 groupId = msn_userlist_find_group_id(userlist, group_name); 1017 groupId = msn_userlist_find_group_id(userlist, group_name);
1324 if (groupId != NULL) { 1018 if (groupId != NULL) {
1325 purple_debug_info("MSN CL", "Deleting user %s from group %s\n", passport, group_name); 1019 purple_debug_info("MSNCL", "Deleting user %s from group %s\n", passport, group_name);
1326 } else { 1020 } else {
1327 purple_debug_warning("MSN CL", "Unable to retrieve group id from group %s !\n", group_name); 1021 purple_debug_warning("MSNCL", "Unable to retrieve group id from group %s !\n", group_name);
1328 return; 1022 return;
1329 } 1023 }
1330 1024
1331 user = msn_userlist_find_user(userlist, passport); 1025 user = msn_userlist_find_user(userlist, passport);
1332 1026
1333 if (user == NULL) { 1027 if (user == NULL) {
1334 purple_debug_warning("MSN CL", "Unable to retrieve user from passport %s!\n", passport); 1028 purple_debug_warning("MSNCL", "Unable to retrieve user from passport %s!\n", passport);
1335 return; 1029 return;
1336 } 1030 }
1337 1031
1338 if ( !strcmp(groupId, MSN_INDIVIDUALS_GROUP_ID) || !strcmp(groupId, MSN_NON_IM_GROUP_ID)) { 1032 if ( !strcmp(groupId, MSN_INDIVIDUALS_GROUP_ID) || !strcmp(groupId, MSN_NON_IM_GROUP_ID)) {
1339 msn_user_remove_group_id(user, groupId); 1033 msn_user_remove_group_id(user, groupId);
1340 return; 1034 return;
1341 } 1035 }
1342 1036
1343 state = msn_callback_state_new(); 1037 state = msn_callback_state_new(contact->session);
1344 msn_callback_state_set_who(state, passport); 1038 msn_callback_state_set_who(state, passport);
1345 msn_callback_state_set_guid(state, groupId); 1039 msn_callback_state_set_guid(state, groupId);
1346 msn_callback_state_set_old_group_name(state, group_name); 1040 msn_callback_state_set_old_group_name(state, group_name);
1347 1041
1348 contact_id_xml = g_strdup_printf(MSN_CONTACT_ID_XML, user->uid); 1042 contact_id_xml = g_strdup_printf(MSN_CONTACT_ID_XML, user->uid);
1349 body = g_strdup_printf(MSN_CONTACT_DEL_GROUP_TEMPLATE, contact_id_xml, groupId); 1043 body = g_strdup_printf(MSN_CONTACT_DEL_GROUP_TEMPLATE, contact_id_xml, groupId);
1044
1045 msn_soap_message_send(contact->session,
1046 msn_soap_message_new(MSN_CONTACT_DEL_GROUP_SOAP_ACTION,
1047 xmlnode_from_str(body, -1)),
1048 MSN_CONTACT_SERVER, MSN_ADDRESS_BOOK_POST_URL,
1049 msn_del_contact_from_group_read_cb, state);
1050
1350 g_free(contact_id_xml); 1051 g_free(contact_id_xml);
1351
1352 /*build SOAP and POST it*/
1353 soap_action = g_strdup(MSN_CONTACT_DEL_GROUP_SOAP_ACTION);
1354
1355 soap_request = msn_soap_request_new(MSN_CONTACT_SERVER,
1356 MSN_ADDRESS_BOOK_POST_URL,
1357 soap_action,
1358 body,
1359 state,
1360 msn_del_contact_from_group_read_cb,
1361 msn_del_contact_from_group_written_cb);
1362 msn_soap_post(contact->soapconn,soap_request,msn_contact_connect_init);
1363
1364 g_free(soap_action);
1365 g_free(body); 1052 g_free(body);
1366 } 1053 }
1367 1054
1368 1055
1369 static void 1056 static void
1370 msn_update_contact_read_cb(gpointer data, gint source, PurpleInputCondition cond) 1057 msn_update_contact_read_cb(MsnSoapMessage *req, MsnSoapMessage *resp,
1371 { 1058 gpointer data)
1372 MsnSoapConn *soapconn = data; 1059 {
1373 1060 if (resp)
1374 if (soapconn->body == NULL) 1061 purple_debug_info("MSN CL","Contact updated successfully\n");
1375 return; 1062 else
1376 1063 purple_debug_info("MSN CL","Contact updated successfully\n");
1377 purple_debug_info("MSN CL","Contact updated successfully\n");
1378 }
1379
1380 static void
1381 msn_update_contact_written_cb(gpointer data, gint source, PurpleInputCondition cond)
1382 {
1383 MsnSoapConn * soapconn = data;
1384
1385 purple_debug_info("MSN CL","Update contact information request sent\n");
1386 soapconn->read_cb = msn_update_contact_read_cb;
1387 } 1064 }
1388 1065
1389 /* Update a contact's nickname */ 1066 /* Update a contact's nickname */
1390
1391 void 1067 void
1392 msn_update_contact(MsnContact *contact, const char* nickname) 1068 msn_update_contact(MsnContact *contact, const char* nickname)
1393 { 1069 {
1394 MsnSoapReq *soap_request;
1395 gchar *body = NULL, *escaped_nickname; 1070 gchar *body = NULL, *escaped_nickname;
1396 1071
1397 purple_debug_info("MSN CL","Update contact information with new friendly name: %s\n", nickname); 1072 purple_debug_info("MSN CL","Update contact information with new friendly name: %s\n", nickname);
1398 1073
1399 escaped_nickname = g_markup_escape_text(nickname, -1); 1074 escaped_nickname = g_markup_escape_text(nickname, -1);
1400 1075
1401 body = g_strdup_printf(MSN_CONTACT_UPDATE_TEMPLATE, escaped_nickname); 1076 body = g_strdup_printf(MSN_CONTACT_UPDATE_TEMPLATE, escaped_nickname);
1402 1077
1078 msn_soap_message_send(contact->session,
1079 msn_soap_message_new(MSN_CONTACT_UPDATE_SOAP_ACTION,
1080 xmlnode_from_str(body, -1)),
1081 MSN_CONTACT_SERVER, MSN_ADDRESS_BOOK_POST_URL,
1082 msn_update_contact_read_cb, NULL);
1083
1403 g_free(escaped_nickname); 1084 g_free(escaped_nickname);
1404 /*build SOAP and POST it*/
1405 soap_request = msn_soap_request_new(MSN_CONTACT_SERVER,
1406 MSN_ADDRESS_BOOK_POST_URL,
1407 MSN_CONTACT_UPDATE_SOAP_ACTION,
1408 body,
1409 NULL,
1410 msn_update_contact_read_cb,
1411 msn_update_contact_written_cb);
1412 msn_soap_post(contact->soapconn, soap_request, msn_contact_connect_init);
1413
1414 g_free(body); 1085 g_free(body);
1415 } 1086 }
1416 1087
1417 1088 static void
1418 static void 1089 msn_del_contact_from_list_read_cb(MsnSoapMessage *req, MsnSoapMessage *resp,
1419 msn_del_contact_from_list_read_cb(gpointer data, gint source, PurpleInputCondition cond) 1090 gpointer data)
1420 { 1091 {
1421 MsnSoapConn * soapconn = data; 1092 MsnCallbackState *state = data;
1422 MsnCallbackState *state = NULL; 1093 MsnSession *session = state->session;
1423 1094
1424 g_return_if_fail(soapconn->data_cb != NULL); 1095 if (resp != NULL) {
1425 g_return_if_fail(soapconn->session != NULL); 1096 purple_debug_info("MSN CL", "Contact %s deleted successfully from %s list on server!\n", state->who, MsnMemberRole[state->list_id]);
1426 g_return_if_fail(soapconn->session->contact != NULL); 1097
1427 1098 if (state->list_id == MSN_LIST_PL) {
1428 state = (MsnCallbackState *) soapconn->data_cb; 1099 msn_add_contact_to_list(session->contact, state, state->who, MSN_LIST_RL);
1429 1100 } else if (state->list_id == MSN_LIST_AL) {
1430 if (soapconn->body == NULL) { 1101 purple_privacy_permit_remove(session->account, state->who, TRUE);
1431 msn_callback_state_free(state); 1102 msn_add_contact_to_list(session->contact, NULL, state->who, MSN_LIST_BL);
1432 return; 1103 } else if (state->list_id == MSN_LIST_BL) {
1433 } 1104 purple_privacy_deny_remove(session->account, state->who, TRUE);
1434 1105 msn_add_contact_to_list(session->contact, NULL, state->who, MSN_LIST_AL);
1435 purple_debug_info("MSN CL", "Contact %s deleted successfully from %s list on server!\n", state->who, MsnMemberRole[state->list_id]); 1106 }
1436
1437 if (state->list_id == MSN_LIST_PL) {
1438 msn_add_contact_to_list(soapconn->session->contact, state, state->who, MSN_LIST_RL);
1439 return;
1440 }
1441
1442 if (state->list_id == MSN_LIST_AL) {
1443 purple_privacy_permit_remove(soapconn->session->account, state->who, TRUE);
1444 msn_add_contact_to_list(soapconn->session->contact, NULL, state->who, MSN_LIST_BL);
1445 msn_callback_state_free(state);
1446 return;
1447 }
1448
1449 if (state->list_id == MSN_LIST_BL) {
1450 purple_privacy_deny_remove(soapconn->session->account, state->who, TRUE);
1451 msn_add_contact_to_list(soapconn->session->contact, NULL, state->who, MSN_LIST_AL);
1452 msn_callback_state_free(state);
1453 return;
1454 } 1107 }
1455 1108
1456 msn_callback_state_free(state); 1109 msn_callback_state_free(state);
1457 msn_soap_free_read_buf(soapconn);
1458 }
1459
1460 static void
1461 msn_del_contact_from_list_written_cb(gpointer data, gint source, PurpleInputCondition cond)
1462 {
1463 MsnSoapConn * soapconn = data;
1464
1465 purple_debug_info("MSN CL","Delete contact from list SOAP request sent!\n");
1466 soapconn->read_cb = msn_del_contact_from_list_read_cb;
1467 } 1110 }
1468 1111
1469 void 1112 void
1470 msn_del_contact_from_list(MsnContact *contact, MsnCallbackState *state, 1113 msn_del_contact_from_list(MsnContact *contact, MsnCallbackState *state,
1471 const gchar *passport, const MsnListId list) 1114 const gchar *passport, const MsnListId list)
1472 { 1115 {
1473 MsnSoapReq *soap_request;
1474 gchar *body = NULL, *member = NULL; 1116 gchar *body = NULL, *member = NULL;
1475 MsnSoapPartnerScenario partner_scenario; 1117 MsnSoapPartnerScenario partner_scenario;
1476 MsnUser *user; 1118 MsnUser *user;
1477 1119
1478 g_return_if_fail(contact != NULL); 1120 g_return_if_fail(contact != NULL);
1480 g_return_if_fail(list < 5); 1122 g_return_if_fail(list < 5);
1481 1123
1482 purple_debug_info("MSN CL", "Deleting contact %s from %s list\n", passport, MsnMemberRole[list]); 1124 purple_debug_info("MSN CL", "Deleting contact %s from %s list\n", passport, MsnMemberRole[list]);
1483 1125
1484 if (state == NULL) { 1126 if (state == NULL) {
1485 state = msn_callback_state_new(); 1127 state = msn_callback_state_new(contact->session);
1486 } 1128 }
1487 msn_callback_state_set_list_id(state, list); 1129 msn_callback_state_set_list_id(state, list);
1488 msn_callback_state_set_who(state, passport); 1130 msn_callback_state_set_who(state, passport);
1489 1131
1490 if (list == MSN_LIST_PL) { 1132 if (list == MSN_LIST_PL) {
1504 1146
1505 body = g_strdup_printf( MSN_CONTACT_DELECT_FROM_LIST_TEMPLATE, 1147 body = g_strdup_printf( MSN_CONTACT_DELECT_FROM_LIST_TEMPLATE,
1506 MsnSoapPartnerScenarioText[partner_scenario], 1148 MsnSoapPartnerScenarioText[partner_scenario],
1507 MsnMemberRole[list], 1149 MsnMemberRole[list],
1508 member); 1150 member);
1151
1152 msn_soap_message_send(contact->session,
1153 msn_soap_message_new(MSN_DELETE_MEMBER_FROM_LIST_SOAP_ACTION,
1154 xmlnode_from_str(body, -1)),
1155 MSN_CONTACT_SERVER, MSN_SHARE_POST_URL,
1156 msn_del_contact_from_list_read_cb, state);
1157
1509 g_free(member); 1158 g_free(member);
1510
1511 soap_request = msn_soap_request_new( MSN_CONTACT_SERVER,
1512 MSN_SHARE_POST_URL,
1513 MSN_DELETE_MEMBER_FROM_LIST_SOAP_ACTION,
1514 body,
1515 state,
1516 msn_del_contact_from_list_read_cb,
1517 msn_del_contact_from_list_written_cb);
1518
1519 msn_soap_post(contact->soapconn,soap_request,msn_contact_connect_init);
1520
1521 g_free(body); 1159 g_free(body);
1522 } 1160 }
1523 1161
1524 static void 1162 static void
1525 msn_add_contact_to_list_read_cb(gpointer data, gint source, PurpleInputCondition cond) 1163 msn_add_contact_to_list_read_cb(MsnSoapMessage *req, MsnSoapMessage *resp,
1526 { 1164 gpointer data)
1527 MsnSoapConn * soapconn = data; 1165 {
1528 MsnCallbackState *state = NULL; 1166 MsnCallbackState *state = data;
1529 1167
1530 g_return_if_fail(soapconn->data_cb != NULL); 1168 g_return_if_fail(state != NULL);
1531 1169 g_return_if_fail(state->session != NULL);
1532 state = (MsnCallbackState *) soapconn->data_cb; 1170 g_return_if_fail(state->session->contact != NULL);
1533 1171
1534 if (soapconn->body == NULL) { 1172 if (resp != NULL) {
1535 msn_callback_state_free(state); 1173 purple_debug_info("MSN CL", "Contact %s added successfully to %s list on server!\n", state->who, MsnMemberRole[state->list_id]);
1536 return; 1174
1537 } 1175 if (state->list_id == MSN_LIST_RL &&
1538 1176 (state->action & MSN_DENIED_BUDDY)) {
1539 purple_debug_info("MSN CL", "Contact %s added successfully to %s list on server!\n", state->who, MsnMemberRole[state->list_id]); 1177
1540 1178 msn_add_contact_to_list(state->session->contact, NULL, state->who, MSN_LIST_BL);
1541 if (state->list_id == MSN_LIST_RL && (state->action & MSN_DENIED_BUDDY) ) { 1179 } else if (state->list_id == MSN_LIST_AL) {
1542 g_return_if_fail(soapconn->session != NULL); 1180 purple_privacy_permit_add(state->session->account, state->who, TRUE);
1543 g_return_if_fail(soapconn->session->contact != NULL); 1181 } else if (state->list_id == MSN_LIST_BL) {
1544 1182 purple_privacy_deny_add(state->session->account, state->who, TRUE);
1545 msn_add_contact_to_list(soapconn->session->contact, NULL, state->who, MSN_LIST_BL); 1183 }
1546 return;
1547 }
1548
1549 if (state->list_id == MSN_LIST_AL) {
1550 purple_privacy_permit_add(soapconn->session->account, state->who, TRUE);
1551 } else if (state->list_id == MSN_LIST_BL) {
1552 purple_privacy_deny_add(soapconn->session->account, state->who, TRUE);
1553 } 1184 }
1554 1185
1555 msn_callback_state_free(state); 1186 msn_callback_state_free(state);
1556 msn_soap_free_read_buf(soapconn);
1557 }
1558
1559
1560 static void
1561 msn_add_contact_to_list_written_cb(gpointer data, gint source, PurpleInputCondition cond)
1562 {
1563 MsnSoapConn * soapconn = data;
1564
1565 purple_debug_info("MSN CL","Add contact to list SOAP request sent!\n");
1566 soapconn->read_cb = msn_add_contact_to_list_read_cb;
1567 } 1187 }
1568 1188
1569 void 1189 void
1570 msn_add_contact_to_list(MsnContact *contact, MsnCallbackState *state, 1190 msn_add_contact_to_list(MsnContact *contact, MsnCallbackState *state,
1571 const gchar *passport, const MsnListId list) 1191 const gchar *passport, const MsnListId list)
1572 { 1192 {
1573 MsnSoapReq *soap_request;
1574 gchar *body = NULL, *member = NULL; 1193 gchar *body = NULL, *member = NULL;
1575 MsnSoapPartnerScenario partner_scenario; 1194 MsnSoapPartnerScenario partner_scenario;
1576 1195
1577 g_return_if_fail(contact != NULL); 1196 g_return_if_fail(contact != NULL);
1578 g_return_if_fail(passport != NULL); 1197 g_return_if_fail(passport != NULL);
1579 g_return_if_fail(list < 5); 1198 g_return_if_fail(list < 5);
1580 1199
1581 purple_debug_info("MSN CL", "Adding contact %s to %s list\n", passport, MsnMemberRole[list]); 1200 purple_debug_info("MSN CL", "Adding contact %s to %s list\n", passport, MsnMemberRole[list]);
1582 1201
1583 if (state == NULL) { 1202 if (state == NULL) {
1584 state = msn_callback_state_new(); 1203 state = msn_callback_state_new(contact->session);
1585 } 1204 }
1586 msn_callback_state_set_list_id(state, list); 1205 msn_callback_state_set_list_id(state, list);
1587 msn_callback_state_set_who(state, passport); 1206 msn_callback_state_set_who(state, passport);
1588 1207
1589 partner_scenario = (list == MSN_LIST_RL) ? MSN_PS_CONTACT_API : MSN_PS_BLOCK_UNBLOCK; 1208 partner_scenario = (list == MSN_LIST_RL) ? MSN_PS_CONTACT_API : MSN_PS_BLOCK_UNBLOCK;
1593 body = g_strdup_printf(MSN_CONTACT_ADD_TO_LIST_TEMPLATE, 1212 body = g_strdup_printf(MSN_CONTACT_ADD_TO_LIST_TEMPLATE,
1594 MsnSoapPartnerScenarioText[partner_scenario], 1213 MsnSoapPartnerScenarioText[partner_scenario],
1595 MsnMemberRole[list], 1214 MsnMemberRole[list],
1596 member); 1215 member);
1597 1216
1217 msn_soap_message_send(contact->session,
1218 msn_soap_message_new(MSN_ADD_MEMBER_TO_LIST_SOAP_ACTION,
1219 xmlnode_from_str(body, -1)),
1220 MSN_CONTACT_SERVER, MSN_SHARE_POST_URL,
1221 msn_add_contact_to_list_read_cb, state);
1222
1598 g_free(member); 1223 g_free(member);
1599
1600 soap_request = msn_soap_request_new( MSN_CONTACT_SERVER,
1601 MSN_SHARE_POST_URL,
1602 MSN_ADD_MEMBER_TO_LIST_SOAP_ACTION,
1603 body,
1604 state,
1605 msn_add_contact_to_list_read_cb,
1606 msn_add_contact_to_list_written_cb);
1607
1608 msn_soap_post(contact->soapconn, soap_request, msn_contact_connect_init);
1609
1610 g_free(body); 1224 g_free(body);
1611 } 1225 }
1612 1226
1613
1614 #if 0 1227 #if 0
1615 static void 1228 static void
1616 msn_gleams_read_cb(gpointer data, gint source, PurpleInputCondition cond) 1229 msn_gleams_read_cb(MsnSoapMessage *req, MsnSoapMessage *resp, gpointer data)
1617 { 1230 {
1618 purple_debug_info("MSNP14","Gleams read done\n"); 1231 if (resp != NULL)
1619 } 1232 purple_debug_info("MSNP14","Gleams read done\n");
1620 1233 else
1621 static void 1234 purple_debug_info("MSNP14","Gleams read failed\n");
1622 msn_gleams_written_cb(gpointer data, gint source, PurpleInputCondition cond)
1623 {
1624 MsnSoapConn * soapconn = data;
1625
1626 purple_debug_info("MSNP14","finish Group written\n");
1627 soapconn->read_cb = msn_gleams_read_cb;
1628 // msn_soap_read_cb(data,source,cond);
1629 } 1235 }
1630 1236
1631 /*get the gleams info*/ 1237 /*get the gleams info*/
1632 void 1238 void
1633 msn_get_gleams(MsnContact *contact) 1239 msn_get_gleams(MsnContact *contact)
1634 { 1240 {
1635 MsnSoapReq *soap_request; 1241 MsnSoapReq *soap_request;
1636 1242
1637 purple_debug_info("MSNP14","msn get gleams info...\n"); 1243 purple_debug_info("MSNP14","msn get gleams info...\n");
1638 /*build SOAP and POST it*/ 1244 msn_soap_message_send(contact->session,
1639 soap_request = msn_soap_request_new(MSN_CONTACT_SERVER, 1245 msn_soap_message_new(MSN_GET_GLEAMS_SOAP_ACTION,
1640 MSN_ADDRESS_BOOK_POST_URL, 1246 xmlnode_from_str(MSN_GLEAMS_TEMPLATE, -1)),
1641 MSN_GET_GLEAMS_SOAP_ACTION, 1247 MSN_CONTACT_SERVER, MSN_ADDRESS_BOOK_POST_URL,
1642 MSN_GLEAMS_TEMPLATE, 1248 msn_gleams_read_cb, NULL);
1643 NULL,
1644 msn_gleams_read_cb,
1645 msn_gleams_written_cb);
1646 msn_soap_post(contact->soapconn,soap_request,msn_contact_connect_init);
1647 } 1249 }
1648 #endif 1250 #endif
1649 1251
1650 1252
1651 /*************************************************************** 1253 /***************************************************************
1652 * Group Operations 1254 * Group Operations
1653 ***************************************************************/ 1255 ***************************************************************/
1654 1256
1655 static void 1257 static void
1656 msn_group_read_cb(gpointer data, gint source, PurpleInputCondition cond) 1258 msn_group_read_cb(MsnSoapMessage *req, MsnSoapMessage *resp, gpointer data)
1657 { 1259 {
1658 MsnSoapConn * soapconn = data; 1260 MsnCallbackState *state = data;
1659 MsnUserList *userlist; 1261
1660 MsnCallbackState *state = NULL; 1262 purple_debug_info("MSNCL", "Group request successful.\n");
1661 1263
1662 purple_debug_info("MSN CL", "Group request successful.\n"); 1264 g_return_if_fail(state->session != NULL);
1663 1265 g_return_if_fail(state->session->userlist != NULL);
1664 g_return_if_fail(soapconn->session != NULL); 1266 g_return_if_fail(state->session->contact != NULL);
1665 g_return_if_fail(soapconn->session->userlist != NULL); 1267
1666 g_return_if_fail(soapconn->session->contact != NULL); 1268 if (resp == NULL) {
1667
1668 state = (MsnCallbackState *) soapconn->data_cb;
1669
1670 if (soapconn->body == NULL) {
1671 msn_callback_state_free(state); 1269 msn_callback_state_free(state);
1672 return; 1270 return;
1673 } 1271 }
1674 1272
1675 if (state) { 1273 if (state) {
1676 userlist = soapconn->session->userlist; 1274 MsnSession *session = state->session;
1275 MsnUserList *userlist = session->userlist;
1677 1276
1678 if (state->action & MSN_RENAME_GROUP) { 1277 if (state->action & MSN_RENAME_GROUP) {
1679 msn_userlist_rename_group_id(soapconn->session->userlist, 1278 msn_userlist_rename_group_id(session->userlist,
1680 state->guid, 1279 state->guid,
1681 state->new_group_name); 1280 state->new_group_name);
1682 } 1281 }
1683 1282
1684 if (state->action & MSN_ADD_GROUP) { 1283 if (state->action & MSN_ADD_GROUP) {
1685 gchar *guid, *endguid; 1284 /* the response is taken from
1686 1285 http://telepathy.freedesktop.org/wiki/Pymsn/MSNP/ContactListActions
1687 guid = g_strstr_len(soapconn->read_buf, soapconn->read_len, "<guid>"); 1286 should copy it to msnpiki some day */
1688 guid += 6; 1287 xmlnode *guid_node = msn_soap_xml_get(resp->xml,
1689 endguid = g_strstr_len(soapconn->read_buf, soapconn->read_len, "</guid>"); 1288 "Body/ABGroupAddResponse/ABGroupAddResult/guid");
1690 *endguid = '\0'; 1289
1691 /* create and add the new group to the userlist */ 1290 if (guid_node) {
1692 purple_debug_info("MSN CL", "Adding group %s with guid = %s to the userlist\n", state->new_group_name, guid); 1291 char *guid = xmlnode_get_data(guid_node);
1693 msn_group_new(soapconn->session->userlist, guid, state->new_group_name); 1292
1694 1293 /* create and add the new group to the userlist */
1695 if (state->action & MSN_ADD_BUDDY) { 1294 purple_debug_info("MSNCL", "Adding group %s with guid = %s to the userlist\n", state->new_group_name, guid);
1696 msn_userlist_add_buddy(soapconn->session->userlist, 1295 msn_group_new(session->userlist, guid, state->new_group_name);
1697 state->who, 1296
1698 state->new_group_name); 1297 if (state->action & MSN_ADD_BUDDY) {
1699 msn_callback_state_free(state); 1298 msn_userlist_add_buddy(session->userlist,
1700 return; 1299 state->who,
1701 } 1300 state->new_group_name);
1702 1301 msn_callback_state_free(state);
1703 if (state->action & MSN_MOVE_BUDDY) { 1302 } else if (state->action & MSN_MOVE_BUDDY) {
1704 msn_add_contact_to_group(soapconn->session->contact, state, state->who, guid); 1303 msn_add_contact_to_group(session->contact, state, state->who, guid);
1705 return; 1304 }
1305
1306 g_free(guid);
1307 } else {
1308 purple_debug_info("MSNCL", "Adding group %s failed\n",
1309 state->new_group_name);
1706 } 1310 }
1707 } 1311 }
1708 1312
1709 if (state->action & MSN_DEL_GROUP) { 1313 if (state->action & MSN_DEL_GROUP) {
1710 GList *l; 1314 GList *l;
1711 1315
1712 msn_userlist_remove_group_id(soapconn->session->userlist, state->guid); 1316 msn_userlist_remove_group_id(session->userlist, state->guid);
1713 for (l = userlist->users; l != NULL; l = l->next) { 1317 for (l = userlist->users; l != NULL; l = l->next) {
1714 msn_user_remove_group_id( (MsnUser *)l->data, state->guid); 1318 msn_user_remove_group_id( (MsnUser *)l->data, state->guid);
1715 } 1319 }
1716
1717 } 1320 }
1718 1321
1719 msn_callback_state_free(state); 1322 msn_callback_state_free(state);
1720 } 1323 }
1721
1722 msn_soap_free_read_buf(soapconn);
1723 }
1724
1725 static void
1726 msn_group_written_cb(gpointer data, gint source, PurpleInputCondition cond)
1727 {
1728 MsnSoapConn * soapconn = data;
1729
1730 purple_debug_info("MSN CL","Sent group request.\n");
1731 soapconn->read_cb = msn_group_read_cb;
1732 } 1324 }
1733 1325
1734 /* add group */ 1326 /* add group */
1735 void 1327 void
1736 msn_add_group(MsnSession *session, MsnCallbackState *state, const char* group_name) 1328 msn_add_group(MsnSession *session, MsnCallbackState *state, const char* group_name)
1737 { 1329 {
1738 MsnSoapReq *soap_request;
1739 MsnContact *contact;
1740 char *body = NULL; 1330 char *body = NULL;
1741 gchar *escaped_group_name;
1742 1331
1743 g_return_if_fail(session != NULL); 1332 g_return_if_fail(session != NULL);
1744 g_return_if_fail(group_name != NULL); 1333 g_return_if_fail(group_name != NULL);
1745 1334
1746 contact = session->contact; 1335 purple_debug_info("MSNCL","Adding group %s to contact list.\n", group_name);
1747 purple_debug_info("MSN CL","Adding group %s to contact list.\n", group_name);
1748 1336
1749 if (state == NULL) { 1337 if (state == NULL) {
1750 state = msn_callback_state_new(); 1338 state = msn_callback_state_new(session);
1751 } 1339 }
1752 1340
1753 msn_callback_state_set_action(state, MSN_ADD_GROUP); 1341 msn_callback_state_set_action(state, MSN_ADD_GROUP);
1754 msn_callback_state_set_new_group_name(state, group_name); 1342 msn_callback_state_set_new_group_name(state, group_name);
1755 1343
1756 /* escape group name's html special chars so it can safely be sent 1344 /* escape group name's html special chars so it can safely be sent
1757 * in a XML SOAP request 1345 * in a XML SOAP request
1758 */ 1346 */
1759 escaped_group_name = g_markup_escape_text(group_name, -1); 1347 body = g_markup_printf_escaped(MSN_GROUP_ADD_TEMPLATE, group_name);
1760 body = g_strdup_printf(MSN_GROUP_ADD_TEMPLATE, escaped_group_name); 1348
1761 g_free(escaped_group_name); 1349 msn_soap_message_send(session,
1762 1350 msn_soap_message_new(MSN_GROUP_ADD_SOAP_ACTION,
1763 /*build SOAP and POST it*/ 1351 xmlnode_from_str(body, -1)),
1764 soap_request = msn_soap_request_new(MSN_CONTACT_SERVER, 1352 MSN_CONTACT_SERVER, MSN_ADDRESS_BOOK_POST_URL,
1765 MSN_ADDRESS_BOOK_POST_URL, 1353 msn_group_read_cb, state);
1766 MSN_GROUP_ADD_SOAP_ACTION, 1354
1767 body,
1768 state,
1769 msn_group_read_cb,
1770 msn_group_written_cb);
1771 msn_soap_post(contact->soapconn,soap_request,msn_contact_connect_init);
1772
1773 g_free(body); 1355 g_free(body);
1774 } 1356 }
1775 1357
1776 /* delete group */ 1358 /* delete group */
1777 void 1359 void
1778 msn_del_group(MsnSession *session, const gchar *group_name) 1360 msn_del_group(MsnSession *session, const gchar *group_name)
1779 { 1361 {
1780 MsnSoapReq *soap_request;
1781 MsnContact *contact;
1782 MsnCallbackState *state; 1362 MsnCallbackState *state;
1783 char *body = NULL; 1363 char *body = NULL;
1784 const gchar *guid; 1364 const gchar *guid;
1785 1365
1786 g_return_if_fail(session != NULL); 1366 g_return_if_fail(session != NULL);
1787 1367
1788 g_return_if_fail(group_name != NULL); 1368 g_return_if_fail(group_name != NULL);
1789 contact = session->contact; 1369 purple_debug_info("MSNCL","Deleting group %s from contact list\n", group_name);
1790 purple_debug_info("MSN CL","Deleting group %s from contact list\n", group_name);
1791 1370
1792 guid = msn_userlist_find_group_id(session->userlist, group_name); 1371 guid = msn_userlist_find_group_id(session->userlist, group_name);
1793 1372
1794 /* if group uid we need to del is NULL, 1373 /* if group uid we need to del is NULL,
1795 * we need to delete nothing 1374 * we need to delete nothing
1796 */ 1375 */
1797 if (guid == NULL) { 1376 if (guid == NULL) {
1798 purple_debug_info("MSN CL", "Group %s guid not found, returning.\n", group_name); 1377 purple_debug_info("MSNCL", "Group %s guid not found, returning.\n", group_name);
1799 return; 1378 return;
1800 } 1379 }
1801 1380
1802 if ( !strcmp(guid, MSN_INDIVIDUALS_GROUP_ID) || !strcmp(guid, MSN_NON_IM_GROUP_ID) ) { 1381 if ( !strcmp(guid, MSN_INDIVIDUALS_GROUP_ID) || !strcmp(guid, MSN_NON_IM_GROUP_ID) ) {
1803 // XXX add back PurpleGroup since it isn't really removed in the server? 1382 // XXX add back PurpleGroup since it isn't really removed in the server?
1804 return; 1383 return;
1805 } 1384 }
1806 1385
1807 state = msn_callback_state_new(); 1386 state = msn_callback_state_new(session);
1808 msn_callback_state_set_action(state, MSN_DEL_GROUP); 1387 msn_callback_state_set_action(state, MSN_DEL_GROUP);
1809 msn_callback_state_set_guid(state, guid); 1388 msn_callback_state_set_guid(state, guid);
1810 1389
1811 body = g_strdup_printf(MSN_GROUP_DEL_TEMPLATE, guid); 1390 body = g_strdup_printf(MSN_GROUP_DEL_TEMPLATE, guid);
1812 /*build SOAP and POST it*/ 1391
1813 soap_request = msn_soap_request_new(MSN_CONTACT_SERVER, 1392 msn_soap_message_send(session,
1814 MSN_ADDRESS_BOOK_POST_URL, 1393 msn_soap_message_new(MSN_GROUP_DEL_SOAP_ACTION,
1815 MSN_GROUP_DEL_SOAP_ACTION, 1394 xmlnode_from_str(body, -1)),
1816 body, 1395 MSN_CONTACT_SERVER, MSN_ADDRESS_BOOK_POST_URL,
1817 state, 1396 msn_group_read_cb, state);
1818 msn_group_read_cb,
1819 msn_group_written_cb);
1820 msn_soap_post(contact->soapconn, soap_request, msn_contact_connect_init);
1821 1397
1822 g_free(body); 1398 g_free(body);
1823 } 1399 }
1824 1400
1825 /* rename group */ 1401 /* rename group */
1826 void 1402 void
1827 msn_contact_rename_group(MsnSession *session, const char *old_group_name, const char *new_group_name) 1403 msn_contact_rename_group(MsnSession *session, const char *old_group_name, const char *new_group_name)
1828 { 1404 {
1829 MsnSoapReq *soap_request; 1405 gchar *body = NULL;
1830 MsnContact *contact;
1831 gchar * escaped_group_name, *body = NULL;
1832 const gchar * guid; 1406 const gchar * guid;
1833 MsnCallbackState *state = msn_callback_state_new(); 1407 MsnCallbackState *state;
1834 1408
1835 g_return_if_fail(session != NULL); 1409 g_return_if_fail(session != NULL);
1836 g_return_if_fail(session->userlist != NULL); 1410 g_return_if_fail(session->userlist != NULL);
1837 g_return_if_fail(old_group_name != NULL); 1411 g_return_if_fail(old_group_name != NULL);
1838 g_return_if_fail(new_group_name != NULL); 1412 g_return_if_fail(new_group_name != NULL);
1839 1413
1840 contact = session->contact;
1841 purple_debug_info("MSN CL", "Renaming group %s to %s.\n", old_group_name, new_group_name); 1414 purple_debug_info("MSN CL", "Renaming group %s to %s.\n", old_group_name, new_group_name);
1842 1415
1843 guid = msn_userlist_find_group_id(session->userlist, old_group_name); 1416 guid = msn_userlist_find_group_id(session->userlist, old_group_name);
1844 if (guid == NULL) 1417 if (guid == NULL)
1845 return; 1418 return;
1846 1419
1420 state = msn_callback_state_new(session);
1847 msn_callback_state_set_guid(state, guid); 1421 msn_callback_state_set_guid(state, guid);
1848 msn_callback_state_set_new_group_name(state, new_group_name); 1422 msn_callback_state_set_new_group_name(state, new_group_name);
1849 1423
1850 if ( !strcmp(guid, MSN_INDIVIDUALS_GROUP_ID) || !strcmp(guid, MSN_NON_IM_GROUP_ID) ) { 1424 if ( !strcmp(guid, MSN_INDIVIDUALS_GROUP_ID) || !strcmp(guid, MSN_NON_IM_GROUP_ID) ) {
1851 msn_add_group(session, state, new_group_name); 1425 msn_add_group(session, state, new_group_name);
1852 // XXX move every buddy there (we probably need to fix concurrent SOAP reqs first) 1426 // XXX move every buddy there (we probably need to fix concurrent SOAP reqs first)
1853 } 1427 }
1854 1428
1855 msn_callback_state_set_action(state, MSN_RENAME_GROUP); 1429 msn_callback_state_set_action(state, MSN_RENAME_GROUP);
1856 1430
1857 /* escape group name's html special chars so it can safely be sent 1431 body = g_markup_printf_escaped(MSN_GROUP_RENAME_TEMPLATE,
1858 * in a XML SOAP request 1432 guid, new_group_name);
1859 */ 1433
1860 escaped_group_name = g_markup_escape_text(new_group_name, -1); 1434 msn_soap_message_send(session,
1861 1435 msn_soap_message_new(MSN_GROUP_RENAME_SOAP_ACTION,
1862 body = g_strdup_printf(MSN_GROUP_RENAME_TEMPLATE, guid, escaped_group_name); 1436 xmlnode_from_str(body, -1)),
1863 1437 MSN_CONTACT_SERVER, MSN_ADDRESS_BOOK_POST_URL,
1864 soap_request = msn_soap_request_new(MSN_CONTACT_SERVER, 1438 msn_group_read_cb, state);
1865 MSN_ADDRESS_BOOK_POST_URL, 1439
1866 MSN_GROUP_RENAME_SOAP_ACTION,
1867 body,
1868 state,
1869 msn_group_read_cb,
1870 msn_group_written_cb);
1871 msn_soap_post(contact->soapconn, soap_request, msn_contact_connect_init);
1872
1873 g_free(escaped_group_name);
1874 g_free(body); 1440 g_free(body);
1875 } 1441 }
1876
1877 void
1878 msn_contact_connect_init(MsnSoapConn *soapconn)
1879 {
1880 msn_soap_init(soapconn, MSN_CONTACT_SERVER, 1,
1881 msn_contact_login_connect_cb,
1882 msn_contact_login_error_cb);
1883 }