Mercurial > pidgin
diff 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 |
line wrap: on
line diff
--- a/libpurple/protocols/msn/contact.c Tue Mar 18 05:36:30 2008 +0000 +++ b/libpurple/protocols/msn/contact.c Wed May 14 04:38:26 2008 +0000 @@ -82,56 +82,46 @@ void msn_callback_state_set_who(MsnCallbackState *state, const gchar *who) { - gchar *nval; g_return_if_fail(state != NULL); - nval = g_strdup(who); g_free(state->who); - state->who = nval; + state->who = g_strdup(who); } void msn_callback_state_set_uid(MsnCallbackState *state, const gchar *uid) { - gchar *nval; g_return_if_fail(state != NULL); - nval = g_strdup(uid); g_free(state->uid); - state->uid = nval; + state->uid = g_strdup(uid); } void msn_callback_state_set_old_group_name(MsnCallbackState *state, const gchar *old_group_name) { - gchar *nval; g_return_if_fail(state != NULL); - nval = g_strdup(old_group_name); g_free(state->old_group_name); - state->old_group_name = nval; + state->old_group_name = g_strdup(old_group_name); } void msn_callback_state_set_new_group_name(MsnCallbackState *state, const gchar *new_group_name) { - gchar *nval; g_return_if_fail(state != NULL); - nval = g_strdup(new_group_name); g_free(state->new_group_name); - state->new_group_name = nval; + state->new_group_name = g_strdup(new_group_name); } void msn_callback_state_set_guid(MsnCallbackState *state, const gchar *guid) { - gchar *nval; g_return_if_fail(state != NULL); - nval = g_strdup(guid); g_free(state->guid); - state->guid = nval; + state->guid = g_strdup(guid); } @@ -447,15 +437,68 @@ } } +static gboolean +msn_parse_addressbook_mobile(xmlnode *contactInfo, char **inout_mobile_number) +{ + xmlnode *phones; + char *mobile_number = NULL; + gboolean mobile = FALSE; + + *inout_mobile_number = NULL; + + if ((phones = xmlnode_get_child(contactInfo, "phones"))) { + xmlnode *contact_phone; + char *phone_type = NULL; + + for (contact_phone = xmlnode_get_child(phones, "ContactPhone"); + contact_phone; + contact_phone = xmlnode_get_next_twin(contact_phone)) { + xmlnode *contact_phone_type; + + if (!(contact_phone_type = + xmlnode_get_child(contact_phone, "contactPhoneType"))) + continue; + + phone_type = xmlnode_get_data(contact_phone_type); + + if (phone_type && !strcmp(phone_type, "ContactPhoneMobile")) { + xmlnode *number; + + if ((number = xmlnode_get_child(contact_phone, "number"))) { + xmlnode *messenger_enabled; + char *is_messenger_enabled = NULL; + + g_free(mobile_number); + mobile_number = xmlnode_get_data(number); + + if (mobile_number && + (messenger_enabled = xmlnode_get_child(contact_phone, "isMessengerEnabled")) + && (is_messenger_enabled = xmlnode_get_data(messenger_enabled)) + && !strcmp(is_messenger_enabled, "true")) + mobile = TRUE; + + g_free(is_messenger_enabled); + } + } + + g_free(phone_type); + } + } + + *inout_mobile_number = mobile_number; + return mobile; +} + static void msn_parse_addressbook_contacts(MsnSession *session, xmlnode *node) { xmlnode *contactNode; - char *passport = NULL, *Name = NULL, *uid = NULL, *type = NULL; + char *passport = NULL, *Name = NULL, *uid = NULL, *type = NULL, *mobile_number = NULL; + gboolean mobile = FALSE; for(contactNode = xmlnode_get_child(node, "Contact"); contactNode; contactNode = xmlnode_get_next_twin(contactNode)) { - xmlnode *contactId, *contactInfo, *contactType, *passportName, *displayName, *guid, *groupIds; + xmlnode *contactId, *contactInfo, *contactType, *passportName, *displayName, *guid, *groupIds, *messenger_user; MsnUser *user; MsnUserType usertype; @@ -468,7 +511,9 @@ g_free(Name); g_free(uid); g_free(type); - passport = Name = uid = type = NULL; + g_free(mobile_number); + passport = Name = uid = type = mobile_number = NULL; + mobile = FALSE; uid = xmlnode_get_data(contactId); type = xmlnode_get_data(contactType); @@ -483,6 +528,18 @@ continue; /* Not adding own account as buddy to buddylist */ } + /* ignore non-messenger contacts */ + if((messenger_user = xmlnode_get_child(contactInfo, "isMessengerUser"))) { + char *is_messenger_user = xmlnode_get_data(messenger_user); + + if(is_messenger_user && !strcmp(is_messenger_user, "false")) { + g_free(is_messenger_user); + continue; + } + + g_free(is_messenger_user); + } + usertype = msn_get_user_type(type); passportName = xmlnode_get_child(contactInfo, "passportName"); if (passportName == NULL) { @@ -536,12 +593,16 @@ else Name = g_strdup(passport); - purple_debug_misc("MsnAB","passport:{%s} uid:{%s} display:{%s}\n", - passport, uid ? uid : "(null)", Name ? Name : "(null)"); + mobile = msn_parse_addressbook_mobile(contactInfo, &mobile_number); + + purple_debug_misc("MsnAB","passport:{%s} uid:{%s} display:{%s} mobile:{%s} mobile number:{%s}\n", + passport, uid ? uid : "(null)", Name ? Name : "(null)", + mobile ? "true" : "false", mobile_number ? mobile_number : "(null)"); user = msn_userlist_find_add_user(session->userlist, passport, Name); msn_user_set_uid(user, uid); msn_user_set_type(user, usertype); + msn_user_set_mobile_phone(user, mobile_number); groupIds = xmlnode_get_child(contactInfo, "groupIds"); if (groupIds) { @@ -559,12 +620,20 @@ } msn_got_lst_user(session, user, MSN_LIST_FL_OP, NULL); + + if(mobile && user) + { + user->mobile = TRUE; + purple_prpl_got_user_status(session->account, user->passport, "mobile", NULL); + purple_prpl_got_user_status(session->account, user->passport, "available", NULL); + } } g_free(passport); g_free(Name); g_free(uid); g_free(type); + g_free(mobile_number); } static gboolean @@ -594,6 +663,7 @@ g_free(errorcode); return TRUE; } + g_free(errorcode); } return FALSE;