comparison libpurple/protocols/msn/contact.c @ 23461:d756a0477c06

propagate from branch 'im.pidgin.pidgin' (head e1c49c9ec5c6869ed9813feccd8ee41d2ca40f35) to branch 'im.pidgin.pidgin.khc.msnp15' (head cee4156a103d7f7b90a8d4e3a3ebf10950baf0aa)
author Ka-Hing Cheung <khc@hxbc.us>
date Wed, 14 May 2008 04:38:26 +0000
parents 69af5301e1a7 f62a4a7fe365
children 1ac5faa72c8d
comparison
equal deleted inserted replaced
23460:a1652ea8f252 23461:d756a0477c06
80 } 80 }
81 81
82 void 82 void
83 msn_callback_state_set_who(MsnCallbackState *state, const gchar *who) 83 msn_callback_state_set_who(MsnCallbackState *state, const gchar *who)
84 { 84 {
85 gchar *nval;
86 g_return_if_fail(state != NULL); 85 g_return_if_fail(state != NULL);
87 86
88 nval = g_strdup(who);
89 g_free(state->who); 87 g_free(state->who);
90 state->who = nval; 88 state->who = g_strdup(who);
91 } 89 }
92 90
93 void 91 void
94 msn_callback_state_set_uid(MsnCallbackState *state, const gchar *uid) 92 msn_callback_state_set_uid(MsnCallbackState *state, const gchar *uid)
95 { 93 {
96 gchar *nval;
97 g_return_if_fail(state != NULL); 94 g_return_if_fail(state != NULL);
98 95
99 nval = g_strdup(uid);
100 g_free(state->uid); 96 g_free(state->uid);
101 state->uid = nval; 97 state->uid = g_strdup(uid);
102 } 98 }
103 99
104 void 100 void
105 msn_callback_state_set_old_group_name(MsnCallbackState *state, const gchar *old_group_name) 101 msn_callback_state_set_old_group_name(MsnCallbackState *state, const gchar *old_group_name)
106 { 102 {
107 gchar *nval;
108 g_return_if_fail(state != NULL); 103 g_return_if_fail(state != NULL);
109 104
110 nval = g_strdup(old_group_name);
111 g_free(state->old_group_name); 105 g_free(state->old_group_name);
112 state->old_group_name = nval; 106 state->old_group_name = g_strdup(old_group_name);
113 } 107 }
114 108
115 void 109 void
116 msn_callback_state_set_new_group_name(MsnCallbackState *state, const gchar *new_group_name) 110 msn_callback_state_set_new_group_name(MsnCallbackState *state, const gchar *new_group_name)
117 { 111 {
118 gchar *nval;
119 g_return_if_fail(state != NULL); 112 g_return_if_fail(state != NULL);
120 113
121 nval = g_strdup(new_group_name);
122 g_free(state->new_group_name); 114 g_free(state->new_group_name);
123 state->new_group_name = nval; 115 state->new_group_name = g_strdup(new_group_name);
124 } 116 }
125 117
126 void 118 void
127 msn_callback_state_set_guid(MsnCallbackState *state, const gchar *guid) 119 msn_callback_state_set_guid(MsnCallbackState *state, const gchar *guid)
128 { 120 {
129 gchar *nval;
130 g_return_if_fail(state != NULL); 121 g_return_if_fail(state != NULL);
131 122
132 nval = g_strdup(guid);
133 g_free(state->guid); 123 g_free(state->guid);
134 state->guid = nval; 124 state->guid = g_strdup(guid);
135 } 125 }
136 126
137 127
138 void 128 void
139 msn_callback_state_set_list_id(MsnCallbackState *state, MsnListId list_id) 129 msn_callback_state_set_list_id(MsnCallbackState *state, MsnListId list_id)
445 g_free(group_id); 435 g_free(group_id);
446 g_free(group_name); 436 g_free(group_name);
447 } 437 }
448 } 438 }
449 439
440 static gboolean
441 msn_parse_addressbook_mobile(xmlnode *contactInfo, char **inout_mobile_number)
442 {
443 xmlnode *phones;
444 char *mobile_number = NULL;
445 gboolean mobile = FALSE;
446
447 *inout_mobile_number = NULL;
448
449 if ((phones = xmlnode_get_child(contactInfo, "phones"))) {
450 xmlnode *contact_phone;
451 char *phone_type = NULL;
452
453 for (contact_phone = xmlnode_get_child(phones, "ContactPhone");
454 contact_phone;
455 contact_phone = xmlnode_get_next_twin(contact_phone)) {
456 xmlnode *contact_phone_type;
457
458 if (!(contact_phone_type =
459 xmlnode_get_child(contact_phone, "contactPhoneType")))
460 continue;
461
462 phone_type = xmlnode_get_data(contact_phone_type);
463
464 if (phone_type && !strcmp(phone_type, "ContactPhoneMobile")) {
465 xmlnode *number;
466
467 if ((number = xmlnode_get_child(contact_phone, "number"))) {
468 xmlnode *messenger_enabled;
469 char *is_messenger_enabled = NULL;
470
471 g_free(mobile_number);
472 mobile_number = xmlnode_get_data(number);
473
474 if (mobile_number &&
475 (messenger_enabled = xmlnode_get_child(contact_phone, "isMessengerEnabled"))
476 && (is_messenger_enabled = xmlnode_get_data(messenger_enabled))
477 && !strcmp(is_messenger_enabled, "true"))
478 mobile = TRUE;
479
480 g_free(is_messenger_enabled);
481 }
482 }
483
484 g_free(phone_type);
485 }
486 }
487
488 *inout_mobile_number = mobile_number;
489 return mobile;
490 }
491
450 static void 492 static void
451 msn_parse_addressbook_contacts(MsnSession *session, xmlnode *node) 493 msn_parse_addressbook_contacts(MsnSession *session, xmlnode *node)
452 { 494 {
453 xmlnode *contactNode; 495 xmlnode *contactNode;
454 char *passport = NULL, *Name = NULL, *uid = NULL, *type = NULL; 496 char *passport = NULL, *Name = NULL, *uid = NULL, *type = NULL, *mobile_number = NULL;
497 gboolean mobile = FALSE;
455 498
456 for(contactNode = xmlnode_get_child(node, "Contact"); contactNode; 499 for(contactNode = xmlnode_get_child(node, "Contact"); contactNode;
457 contactNode = xmlnode_get_next_twin(contactNode)) { 500 contactNode = xmlnode_get_next_twin(contactNode)) {
458 xmlnode *contactId, *contactInfo, *contactType, *passportName, *displayName, *guid, *groupIds; 501 xmlnode *contactId, *contactInfo, *contactType, *passportName, *displayName, *guid, *groupIds, *messenger_user;
459 MsnUser *user; 502 MsnUser *user;
460 MsnUserType usertype; 503 MsnUserType usertype;
461 504
462 if (!(contactId = xmlnode_get_child(contactNode,"contactId")) 505 if (!(contactId = xmlnode_get_child(contactNode,"contactId"))
463 || !(contactInfo = xmlnode_get_child(contactNode, "contactInfo")) 506 || !(contactInfo = xmlnode_get_child(contactNode, "contactInfo"))
466 509
467 g_free(passport); 510 g_free(passport);
468 g_free(Name); 511 g_free(Name);
469 g_free(uid); 512 g_free(uid);
470 g_free(type); 513 g_free(type);
471 passport = Name = uid = type = NULL; 514 g_free(mobile_number);
515 passport = Name = uid = type = mobile_number = NULL;
516 mobile = FALSE;
472 517
473 uid = xmlnode_get_data(contactId); 518 uid = xmlnode_get_data(contactId);
474 type = xmlnode_get_data(contactType); 519 type = xmlnode_get_data(contactType);
475 520
476 /*setup the Display Name*/ 521 /*setup the Display Name*/
479 if ((displayName = xmlnode_get_child(contactInfo, "displayName"))) 524 if ((displayName = xmlnode_get_child(contactInfo, "displayName")))
480 friendly = xmlnode_get_data(displayName); 525 friendly = xmlnode_get_data(displayName);
481 purple_connection_set_display_name(session->account->gc, friendly ? purple_url_decode(friendly) : NULL); 526 purple_connection_set_display_name(session->account->gc, friendly ? purple_url_decode(friendly) : NULL);
482 g_free(friendly); 527 g_free(friendly);
483 continue; /* Not adding own account as buddy to buddylist */ 528 continue; /* Not adding own account as buddy to buddylist */
529 }
530
531 /* ignore non-messenger contacts */
532 if((messenger_user = xmlnode_get_child(contactInfo, "isMessengerUser"))) {
533 char *is_messenger_user = xmlnode_get_data(messenger_user);
534
535 if(is_messenger_user && !strcmp(is_messenger_user, "false")) {
536 g_free(is_messenger_user);
537 continue;
538 }
539
540 g_free(is_messenger_user);
484 } 541 }
485 542
486 usertype = msn_get_user_type(type); 543 usertype = msn_get_user_type(type);
487 passportName = xmlnode_get_child(contactInfo, "passportName"); 544 passportName = xmlnode_get_child(contactInfo, "passportName");
488 if (passportName == NULL) { 545 if (passportName == NULL) {
534 if ((displayName = xmlnode_get_child(contactInfo, "displayName"))) 591 if ((displayName = xmlnode_get_child(contactInfo, "displayName")))
535 Name = xmlnode_get_data(displayName); 592 Name = xmlnode_get_data(displayName);
536 else 593 else
537 Name = g_strdup(passport); 594 Name = g_strdup(passport);
538 595
539 purple_debug_misc("MsnAB","passport:{%s} uid:{%s} display:{%s}\n", 596 mobile = msn_parse_addressbook_mobile(contactInfo, &mobile_number);
540 passport, uid ? uid : "(null)", Name ? Name : "(null)"); 597
598 purple_debug_misc("MsnAB","passport:{%s} uid:{%s} display:{%s} mobile:{%s} mobile number:{%s}\n",
599 passport, uid ? uid : "(null)", Name ? Name : "(null)",
600 mobile ? "true" : "false", mobile_number ? mobile_number : "(null)");
541 601
542 user = msn_userlist_find_add_user(session->userlist, passport, Name); 602 user = msn_userlist_find_add_user(session->userlist, passport, Name);
543 msn_user_set_uid(user, uid); 603 msn_user_set_uid(user, uid);
544 msn_user_set_type(user, usertype); 604 msn_user_set_type(user, usertype);
605 msn_user_set_mobile_phone(user, mobile_number);
545 606
546 groupIds = xmlnode_get_child(contactInfo, "groupIds"); 607 groupIds = xmlnode_get_child(contactInfo, "groupIds");
547 if (groupIds) { 608 if (groupIds) {
548 for (guid = xmlnode_get_child(groupIds, "guid"); guid; 609 for (guid = xmlnode_get_child(groupIds, "guid"); guid;
549 guid = xmlnode_get_next_twin(guid)){ 610 guid = xmlnode_get_next_twin(guid)){
557 /*not in any group,Then set default group*/ 618 /*not in any group,Then set default group*/
558 msn_user_add_group_id(user, MSN_INDIVIDUALS_GROUP_ID); 619 msn_user_add_group_id(user, MSN_INDIVIDUALS_GROUP_ID);
559 } 620 }
560 621
561 msn_got_lst_user(session, user, MSN_LIST_FL_OP, NULL); 622 msn_got_lst_user(session, user, MSN_LIST_FL_OP, NULL);
623
624 if(mobile && user)
625 {
626 user->mobile = TRUE;
627 purple_prpl_got_user_status(session->account, user->passport, "mobile", NULL);
628 purple_prpl_got_user_status(session->account, user->passport, "available", NULL);
629 }
562 } 630 }
563 631
564 g_free(passport); 632 g_free(passport);
565 g_free(Name); 633 g_free(Name);
566 g_free(uid); 634 g_free(uid);
567 g_free(type); 635 g_free(type);
636 g_free(mobile_number);
568 } 637 }
569 638
570 static gboolean 639 static gboolean
571 msn_parse_addressbook(MsnSession *session, xmlnode *node) 640 msn_parse_addressbook(MsnSession *session, xmlnode *node)
572 { 641 {
592 661
593 if (g_str_equal(errorcode, "ABDoesNotExist")) { 662 if (g_str_equal(errorcode, "ABDoesNotExist")) {
594 g_free(errorcode); 663 g_free(errorcode);
595 return TRUE; 664 return TRUE;
596 } 665 }
666 g_free(errorcode);
597 } 667 }
598 668
599 return FALSE; 669 return FALSE;
600 } 670 }
601 671