Mercurial > pidgin
comparison libpurple/protocols/msn/contact.c @ 23472:70de4e2246ec
Add real server-side aliasing to MSN.
author | Elliott Sales de Andrade <qulogic@pidgin.im> |
---|---|
date | Sat, 07 Jun 2008 08:01:41 +0000 |
parents | eb8bd060b987 |
children | 31b5a1334e7e |
comparison
equal
deleted
inserted
replaced
23471:5a6cf27ead31 | 23472:70de4e2246ec |
---|---|
508 | 508 |
509 static void | 509 static void |
510 msn_parse_addressbook_contacts(MsnSession *session, xmlnode *node) | 510 msn_parse_addressbook_contacts(MsnSession *session, xmlnode *node) |
511 { | 511 { |
512 xmlnode *contactNode; | 512 xmlnode *contactNode; |
513 char *passport = NULL, *Name = NULL, *uid = NULL, *type = NULL, *mobile_number = NULL; | 513 char *passport = NULL, *Name = NULL, *uid = NULL, *type = NULL, *mobile_number = NULL, *alias = NULL; |
514 gboolean mobile = FALSE; | 514 gboolean mobile = FALSE; |
515 PurpleConnection *pc = purple_account_get_connection(session->account); | |
515 | 516 |
516 for(contactNode = xmlnode_get_child(node, "Contact"); contactNode; | 517 for(contactNode = xmlnode_get_child(node, "Contact"); contactNode; |
517 contactNode = xmlnode_get_next_twin(contactNode)) { | 518 contactNode = xmlnode_get_next_twin(contactNode)) { |
518 xmlnode *contactId, *contactInfo, *contactType, *passportName, *displayName, *guid, *groupIds, *messenger_user; | 519 xmlnode *contactId, *contactInfo, *contactType, *passportName, *displayName, *guid, *groupIds, *messenger_user; |
520 xmlnode *annotation; | |
519 MsnUser *user; | 521 MsnUser *user; |
520 MsnUserType usertype; | 522 MsnUserType usertype; |
521 | 523 |
522 if (!(contactId = xmlnode_get_child(contactNode,"contactId")) | 524 if (!(contactId = xmlnode_get_child(contactNode,"contactId")) |
523 || !(contactInfo = xmlnode_get_child(contactNode, "contactInfo")) | 525 || !(contactInfo = xmlnode_get_child(contactNode, "contactInfo")) |
524 || !(contactType = xmlnode_get_child(contactInfo, "contactType"))) | 526 || !(contactType = xmlnode_get_child(contactInfo, "contactType"))) |
525 continue; | 527 continue; |
526 | 528 |
527 g_free(passport); | 529 g_free(passport); |
528 g_free(Name); | 530 g_free(Name); |
531 g_free(alias); | |
529 g_free(uid); | 532 g_free(uid); |
530 g_free(type); | 533 g_free(type); |
531 g_free(mobile_number); | 534 g_free(mobile_number); |
532 passport = Name = uid = type = mobile_number = NULL; | 535 passport = Name = uid = type = mobile_number = alias = NULL; |
533 mobile = FALSE; | 536 mobile = FALSE; |
534 | 537 |
535 uid = xmlnode_get_data(contactId); | 538 uid = xmlnode_get_data(contactId); |
536 type = xmlnode_get_data(contactType); | 539 type = xmlnode_get_data(contactType); |
537 | 540 |
608 if ((displayName = xmlnode_get_child(contactInfo, "displayName"))) | 611 if ((displayName = xmlnode_get_child(contactInfo, "displayName"))) |
609 Name = xmlnode_get_data(displayName); | 612 Name = xmlnode_get_data(displayName); |
610 else | 613 else |
611 Name = g_strdup(passport); | 614 Name = g_strdup(passport); |
612 | 615 |
616 for (annotation = xmlnode_get_child(contactInfo, "annotations/Annotation"); | |
617 annotation; annotation = xmlnode_get_next_twin(annotation)) { | |
618 char *name; | |
619 name = xmlnode_get_data(xmlnode_get_child(annotation, "Name")); | |
620 if (!strcmp(name, "AB.NickName")) | |
621 alias = xmlnode_get_data(xmlnode_get_child(annotation, "Value")); | |
622 g_free(name); | |
623 } | |
624 | |
613 mobile = msn_parse_addressbook_mobile(contactInfo, &mobile_number); | 625 mobile = msn_parse_addressbook_mobile(contactInfo, &mobile_number); |
614 | 626 |
615 purple_debug_misc("MsnAB","passport:{%s} uid:{%s} display:{%s} mobile:{%s} mobile number:{%s}\n", | 627 purple_debug_misc("MsnAB","passport:{%s} uid:{%s} display:{%s} alias: {%s} mobile:{%s} mobile number:{%s}\n", |
616 passport, uid ? uid : "(null)", Name ? Name : "(null)", | 628 passport, uid ? uid : "(null)", Name ? Name : "(null)", alias ? alias : "(null)", |
617 mobile ? "true" : "false", mobile_number ? mobile_number : "(null)"); | 629 mobile ? "true" : "false", mobile_number ? mobile_number : "(null)"); |
618 | 630 |
619 user = msn_userlist_find_add_user(session->userlist, passport, Name); | 631 user = msn_userlist_find_add_user(session->userlist, passport, Name); |
620 msn_user_set_uid(user, uid); | 632 msn_user_set_uid(user, uid); |
621 msn_user_set_type(user, usertype); | 633 msn_user_set_type(user, usertype); |
642 { | 654 { |
643 user->mobile = TRUE; | 655 user->mobile = TRUE; |
644 purple_prpl_got_user_status(session->account, user->passport, "mobile", NULL); | 656 purple_prpl_got_user_status(session->account, user->passport, "mobile", NULL); |
645 purple_prpl_got_user_status(session->account, user->passport, "available", NULL); | 657 purple_prpl_got_user_status(session->account, user->passport, "available", NULL); |
646 } | 658 } |
659 if (alias) | |
660 purple_serv_got_private_alias(pc, passport, alias); | |
647 } | 661 } |
648 | 662 |
649 g_free(passport); | 663 g_free(passport); |
650 g_free(Name); | 664 g_free(Name); |
651 g_free(uid); | 665 g_free(uid); |
1183 gpointer data) | 1197 gpointer data) |
1184 { | 1198 { |
1185 purple_debug_info("MSN CL","Contact updated successfully\n"); | 1199 purple_debug_info("MSN CL","Contact updated successfully\n"); |
1186 } | 1200 } |
1187 | 1201 |
1188 /* Update a contact's nickname */ | 1202 /* Update a contact's info */ |
1189 void | 1203 void |
1190 msn_update_contact(MsnSession *session, const char* nickname) | 1204 msn_update_contact(MsnSession *session, const char *passport, MsnContactUpdateType type, const char* value) |
1191 { | 1205 { |
1192 MsnCallbackState *state; | 1206 MsnCallbackState *state; |
1193 gchar *body = NULL, *escaped_nickname; | 1207 xmlnode *contact; |
1194 | 1208 xmlnode *contact_info; |
1195 purple_debug_info("MSN CL","Update contact information with new friendly name: %s\n", nickname); | 1209 xmlnode *changes; |
1196 | 1210 |
1197 escaped_nickname = g_markup_escape_text(nickname, -1); | 1211 purple_debug_info("MSN CL","Update contact information with new %s: %s\n", |
1198 | 1212 type==MSN_UPDATE_DISPLAY ? "display name" : "alias", value); |
1199 body = g_strdup_printf(MSN_CONTACT_UPDATE_TEMPLATE, escaped_nickname); | 1213 purple_debug_info("msncl", "passport=%s\n", passport); |
1214 g_return_if_fail(passport != NULL); | |
1215 contact_info = xmlnode_new("contactInfo"); | |
1216 changes = xmlnode_new("propertiesChanged"); | |
1217 | |
1218 switch (type) { | |
1219 xmlnode *annotations; | |
1220 xmlnode *display; | |
1221 xmlnode *a, *n, *v; | |
1222 case MSN_UPDATE_DISPLAY: | |
1223 display = xmlnode_new_child(contact_info, "displayName"); | |
1224 xmlnode_insert_data(display, value, -1); | |
1225 xmlnode_insert_data(changes, "DisplayName", -1); | |
1226 break; | |
1227 | |
1228 case MSN_UPDATE_ALIAS: | |
1229 annotations = xmlnode_new_child(contact_info, "annotations"); | |
1230 xmlnode_insert_data(changes, "Annotation ", -1); | |
1231 | |
1232 a = xmlnode_new_child(annotations, "Annotation"); | |
1233 n = xmlnode_new_child(a, "Name"); | |
1234 xmlnode_insert_data(n, "AB.NickName", -1); | |
1235 v = xmlnode_new_child(a, "Value"); | |
1236 xmlnode_insert_data(v, value, -1); | |
1237 break; | |
1238 | |
1239 default: | |
1240 g_return_if_reached(); | |
1241 } | |
1242 | |
1243 | |
1200 | 1244 |
1201 state = msn_callback_state_new(session); | 1245 state = msn_callback_state_new(session); |
1202 state->body = xmlnode_from_str(body, -1); | 1246 |
1247 state->body = xmlnode_from_str(MSN_CONTACT_UPDATE_TEMPLATE, -1); | |
1203 state->action = MSN_UPDATE_INFO; | 1248 state->action = MSN_UPDATE_INFO; |
1204 state->post_action = MSN_CONTACT_UPDATE_SOAP_ACTION; | 1249 state->post_action = MSN_CONTACT_UPDATE_SOAP_ACTION; |
1205 state->post_url = MSN_ADDRESS_BOOK_POST_URL; | 1250 state->post_url = MSN_ADDRESS_BOOK_POST_URL; |
1206 state->cb = msn_update_contact_read_cb; | 1251 state->cb = msn_update_contact_read_cb; |
1207 | 1252 |
1208 g_free(escaped_nickname); | 1253 contact = xmlnode_get_child(state->body, "Body/ABContactUpdate/contacts/Contact"); |
1209 g_free(body); | 1254 xmlnode_insert_child(contact, contact_info); |
1255 xmlnode_insert_child(contact, changes); | |
1256 | |
1257 if (!strcmp(passport, "Me")) { | |
1258 xmlnode *contactType = xmlnode_new_child(contact_info, "contactType"); | |
1259 xmlnode_insert_data(contactType, "Me", -1); | |
1260 } else { | |
1261 MsnUser *user = msn_userlist_find_user(session->userlist, passport); | |
1262 xmlnode *contactId = xmlnode_new_child(contact, "contactId"); | |
1263 msn_callback_state_set_uid(state, user->uid); | |
1264 xmlnode_insert_data(contactId, state->uid, -1); | |
1265 } | |
1266 | |
1267 msn_contact_request(state); | |
1210 } | 1268 } |
1211 | 1269 |
1212 static void | 1270 static void |
1213 msn_del_contact_from_list_read_cb(MsnSoapMessage *req, MsnSoapMessage *resp, | 1271 msn_del_contact_from_list_read_cb(MsnSoapMessage *req, MsnSoapMessage *resp, |
1214 gpointer data) | 1272 gpointer data) |