Sat, 14 Oct 2006 20:00:56 +0000
[gaim-migrate @ 17481]
gradually got SOAP contact list and address book from Server.
Cache the info in blist.xml
committer: Ethan Blanton <elb@pidgin.im>
| 13854 | 1 | /** |
| 2 | * @file contact.c | |
| 3 | * get MSN contacts via SOAP request | |
| 4 | * created by MaYuan<mayuan2006@gmail.com> | |
| 5 | * | |
| 6 | * gaim | |
| 7 | * | |
| 8 | * Gaim is the legal property of its developers, whose names are too numerous | |
| 9 | * to list here. Please refer to the COPYRIGHT file distributed with this | |
| 10 | * source distribution. | |
| 11 | * | |
| 12 | * This program is free software; you can redistribute it and/or modify | |
| 13 | * it under the terms of the GNU General Public License as published by | |
| 14 | * the Free Software Foundation; either version 2 of the License, or | |
| 15 | * (at your option) any later version. | |
| 16 | * | |
| 17 | * This program is distributed in the hope that it will be useful, | |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 20 | * GNU General Public License for more details. | |
| 21 | * | |
| 22 | * You should have received a copy of the GNU General Public License | |
| 23 | * along with this program; if not, write to the Free Software | |
| 24 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 25 | */ | |
| 26 | ||
| 27 | #include "msn.h" | |
| 28 | #include "soap.h" | |
| 29 | #include "contact.h" | |
| 30 | #include "xmlnode.h" | |
| 13857 | 31 | #include "group.h" |
| 13854 | 32 | |
| 13896 | 33 | /*define This to debug the Contact Server*/ |
| 34 | #undef MSN_CONTACT_SOAP_DEBUG | |
| 35 | ||
| 13876 | 36 | void msn_contact_connect_init(MsnSoapConn *soapconn); |
| 37 | ||
| 13854 | 38 | /*new a contact*/ |
| 39 | MsnContact * | |
| 40 | msn_contact_new(MsnSession *session) | |
| 41 | { | |
| 42 | MsnContact *contact; | |
| 43 | ||
| 44 | contact = g_new0(MsnContact, 1); | |
| 45 | contact->session = session; | |
| 13855 | 46 | contact->soapconn = msn_soap_new(session,contact,1); |
| 13854 | 47 | |
| 48 | return contact; | |
| 49 | } | |
| 50 | ||
| 51 | /*destroy the contact*/ | |
| 52 | void | |
| 53 | msn_contact_destroy(MsnContact *contact) | |
| 54 | { | |
| 55 | msn_soap_destroy(contact->soapconn); | |
| 56 | g_free(contact); | |
| 57 | } | |
| 58 | ||
| 59 | /*contact SOAP server login error*/ | |
| 60 | static void | |
| 61 | msn_contact_login_error_cb(GaimSslConnection *gsc, GaimSslErrorType error, void *data) | |
| 62 | { | |
| 63 | MsnSoapConn *soapconn = data; | |
| 64 | MsnSession *session; | |
| 65 | ||
| 66 | session = soapconn->session; | |
| 67 | g_return_if_fail(session != NULL); | |
| 68 | ||
| 69 | msn_session_set_error(session, MSN_ERROR_SERV_DOWN, _("Unable to connect to contact server")); | |
| 70 | } | |
| 71 | ||
| 72 | /*msn contact SOAP server connect process*/ | |
| 73 | static void | |
| 74 | msn_contact_login_connect_cb(gpointer data, GaimSslConnection *gsc, | |
| 75 | GaimInputCondition cond) | |
| 76 | { | |
| 77 | MsnSoapConn *soapconn = data; | |
| 78 | MsnSession * session; | |
| 79 | MsnContact *contact; | |
| 80 | ||
| 81 | contact = soapconn->parent; | |
| 82 | g_return_if_fail(contact != NULL); | |
| 83 | ||
| 84 | session = contact->session; | |
| 85 | g_return_if_fail(session != NULL); | |
| 86 | ||
| 87 | /*login ok!We can retrieve the contact list*/ | |
| 13910 | 88 | // msn_get_contact_list(contact,NULL); |
| 13854 | 89 | } |
| 90 | ||
| 13855 | 91 | /*get MSN member role utility*/ |
| 92 | static int | |
| 93 | msn_get_memberrole(char * role) | |
| 94 | { | |
| 95 | if(!strcmp(role,"Allow")){ | |
| 96 | return MSN_LIST_AL_OP; | |
| 97 | }else if(!strcmp(role,"Block")){ | |
| 98 | return MSN_LIST_BL_OP; | |
| 13869 | 99 | }else if(!strcmp(role,"Reverse")){ |
| 100 | return MSN_LIST_RL_OP; | |
| 13855 | 101 | } |
| 102 | return 0; | |
| 103 | } | |
| 104 | ||
| 105 | /*get User Type*/ | |
| 106 | static int | |
| 107 | msn_get_user_type(char * type) | |
| 108 | { | |
| 109 | if(!strcmp(type,"Regular")){ | |
| 110 | return 1; | |
| 111 | } | |
| 13895 | 112 | if(!strcmp(type,"Live")){ |
| 113 | return 1; | |
| 114 | } | |
| 115 | if(!strcmp(type,"LivePending")){ | |
| 116 | return 1; | |
| 117 | } | |
| 118 | ||
| 13855 | 119 | return 0; |
| 120 | } | |
| 121 | ||
| 122 | /*parse contact list*/ | |
| 13854 | 123 | static void |
| 124 | msn_parse_contact_list(MsnContact * contact) | |
| 125 | { | |
| 13855 | 126 | MsnSession * session; |
| 127 | int list_op =0; | |
| 128 | char * passport; | |
| 13910 | 129 | xmlnode * node,*body,*response,*result,*services; |
| 130 | xmlnode *service,*memberships; | |
| 13904 | 131 | xmlnode *LastChangeNode; |
| 13893 | 132 | xmlnode *membershipnode,*members,*member,*passportNode; |
| 13910 | 133 | char *LastChangeStr; |
| 13854 | 134 | |
| 13855 | 135 | session = contact->session; |
| 13910 | 136 | gaim_debug_misc("MSNCL","parse contact list:{%s}\nsize:%d\n",contact->soapconn->body,contact->soapconn->body_len); |
| 13854 | 137 | node = xmlnode_from_str(contact->soapconn->body, contact->soapconn->body_len); |
| 138 | ||
| 139 | if(node == NULL){ | |
| 13910 | 140 | gaim_debug_misc("MSNCL","parse contact from str err!\n"); |
| 13854 | 141 | return; |
| 142 | } | |
| 13910 | 143 | gaim_debug_misc("MSNCL","node{%p},name:%s,child:%s,last:%s\n",node,node->name,node->child->name,node->lastchild->name); |
| 13854 | 144 | body = xmlnode_get_child(node,"Body"); |
| 13910 | 145 | gaim_debug_misc("MSNCL","body{%p},name:%s\n",body,body->name); |
| 13854 | 146 | response = xmlnode_get_child(body,"FindMembershipResponse"); |
| 13910 | 147 | gaim_debug_misc("MSNCL","response{%p},name:%s\n",response,response->name); |
| 13854 | 148 | result =xmlnode_get_child(response,"FindMembershipResult"); |
| 13910 | 149 | if(result == NULL){ |
| 150 | gaim_debug_misc("MSNCL","receive No Update!\n"); | |
| 151 | return; | |
| 152 | } | |
| 153 | gaim_debug_misc("MSNCL","result{%p},name:%s\n",result,result->name); | |
| 13854 | 154 | services =xmlnode_get_child(result,"Services"); |
| 13910 | 155 | gaim_debug_misc("MSNCL","services{%p},name:%s\n",services,services->name); |
| 13854 | 156 | service =xmlnode_get_child(services,"Service"); |
| 13910 | 157 | gaim_debug_misc("MSNCL","service{%p},name:%s\n",service,service->name); |
| 13904 | 158 | |
| 159 | /*Last Change Node*/ | |
| 160 | LastChangeNode = xmlnode_get_child(service,"LastChange"); | |
| 13910 | 161 | LastChangeStr = xmlnode_get_data(LastChangeNode); |
| 162 | gaim_debug_misc("MSNCL","LastChangeNode0 %s\n",LastChangeStr); | |
| 163 | gaim_blist_node_set_string(msn_session_get_bnode(contact->session),"CLLastChange",LastChangeStr); | |
| 164 | gaim_debug_misc("MSNCL","LastChangeNode %s\n",LastChangeStr); | |
| 13904 | 165 | |
| 13854 | 166 | memberships =xmlnode_get_child(service,"Memberships"); |
| 13910 | 167 | gaim_debug_misc("MSNCL","memberships{%p},name:%s\n",memberships,memberships->name); |
| 13854 | 168 | for(membershipnode = xmlnode_get_child(memberships, "Membership"); membershipnode; |
| 169 | membershipnode = xmlnode_get_next_twin(membershipnode)){ | |
| 13893 | 170 | xmlnode *roleNode; |
| 171 | char *role; | |
| 172 | roleNode = xmlnode_get_child(membershipnode,"MemberRole"); | |
| 173 | role=xmlnode_get_data(roleNode); | |
| 174 | list_op = msn_get_memberrole(role); | |
| 13910 | 175 | gaim_debug_misc("MSNCL","MemberRole role:%s,list_op:%d\n",role,list_op); |
| 13893 | 176 | g_free(role); |
| 13854 | 177 | members = xmlnode_get_child(membershipnode,"Members"); |
| 13855 | 178 | for(member = xmlnode_get_child(members, "Member"); member; |
| 179 | member = xmlnode_get_next_twin(member)){ | |
| 13870 | 180 | MsnUser *user; |
| 13856 | 181 | xmlnode * typeNode; |
| 182 | char * type; | |
| 183 | ||
| 13910 | 184 | gaim_debug_misc("MSNCL","type:%s\n",xmlnode_get_attrib(member,"type")); |
| 13856 | 185 | if(!g_strcasecmp(xmlnode_get_attrib(member,"type"),"PassportMember")){ |
| 186 | passportNode = xmlnode_get_child(member,"PassportName"); | |
| 187 | passport = xmlnode_get_data(passportNode); | |
| 188 | typeNode = xmlnode_get_child(member,"Type"); | |
| 189 | type = xmlnode_get_data(typeNode); | |
| 13910 | 190 | gaim_debug_misc("MSNCL","Passport name:%s,type:%s\n",passport,type); |
| 13893 | 191 | g_free(type); |
| 13870 | 192 | |
| 193 | user = msn_userlist_find_add_user(session->userlist,passport,NULL); | |
| 13856 | 194 | msn_got_lst_user(session, user, list_op, NULL); |
| 13893 | 195 | g_free(passport); |
| 13854 | 196 | } |
| 13856 | 197 | if(!g_strcasecmp(xmlnode_get_attrib(member,"type"),"PhoneMember")){ |
| 198 | } | |
| 199 | if(!g_strcasecmp(xmlnode_get_attrib(member,"type"),"EmailMember")){ | |
| 13870 | 200 | xmlnode *emailNode; |
| 201 | ||
| 202 | emailNode = xmlnode_get_child(member,"Email"); | |
| 203 | passport = xmlnode_get_data(emailNode); | |
| 13910 | 204 | gaim_debug_info("MSNCL","Email Member :name:%s,list_op:%d\n",passport,list_op); |
| 13870 | 205 | user = msn_userlist_find_add_user(session->userlist,passport,NULL); |
| 206 | msn_got_lst_user(session,user,list_op,NULL); | |
| 13893 | 207 | g_free(passport); |
| 13856 | 208 | } |
| 13855 | 209 | } |
| 13854 | 210 | } |
| 211 | ||
| 212 | xmlnode_free(node); | |
| 213 | } | |
| 214 | ||
| 215 | static void | |
| 216 | msn_get_contact_list_cb(gpointer data, gint source, GaimInputCondition cond) | |
| 217 | { | |
| 218 | MsnSoapConn * soapconn = data; | |
| 219 | MsnContact *contact; | |
| 220 | MsnSession *session; | |
| 13910 | 221 | const char * abLastChange; |
| 222 | const char * dynamicItemLastChange; | |
| 13854 | 223 | |
| 224 | contact = soapconn->parent; | |
| 225 | g_return_if_fail(contact != NULL); | |
| 226 | session = soapconn->session; | |
| 227 | g_return_if_fail(session != NULL); | |
| 228 | ||
| 13896 | 229 | #ifdef MSN_CONTACT_SOAP_DEBUG |
| 230 | gaim_debug_misc("msn", "soap contact server Reply: {%s}\n", soapconn->read_buf); | |
| 231 | #endif | |
| 13854 | 232 | msn_parse_contact_list(contact); |
| 13886 | 233 | /*free the read buffer*/ |
| 234 | msn_soap_free_read_buf(soapconn); | |
| 235 | ||
| 13910 | 236 | abLastChange = gaim_blist_node_get_string(msn_session_get_bnode(contact->session),"ablastChange"); |
| 237 | dynamicItemLastChange = gaim_blist_node_get_string(msn_session_get_bnode(contact->session),"dynamicItemLastChange"); | |
| 238 | msn_get_address_book(contact,abLastChange,dynamicItemLastChange); | |
| 13854 | 239 | } |
| 240 | ||
| 241 | static void | |
| 13866 | 242 | msn_get_contact_written_cb(gpointer data, gint source, GaimInputCondition cond) |
| 13854 | 243 | { |
| 244 | MsnSoapConn * soapconn = data; | |
| 245 | ||
| 246 | gaim_debug_info("MaYuan","finish contact written\n"); | |
| 247 | soapconn->read_cb = msn_get_contact_list_cb; | |
| 13880 | 248 | // msn_soap_read_cb(data,source,cond); |
| 13854 | 249 | } |
| 250 | ||
| 13910 | 251 | /*SOAP get contact list*/ |
| 13854 | 252 | void |
| 13910 | 253 | msn_get_contact_list(MsnContact * contact,char * update_time) |
| 13854 | 254 | { |
| 13874 | 255 | MsnSoapReq *soap_request; |
| 13910 | 256 | char *body = NULL; |
| 257 | char * update_str; | |
| 258 | ||
| 13876 | 259 | gaim_debug_info("MaYuan","Getting Contact List...\n"); |
| 13910 | 260 | if(update_time != NULL){ |
| 261 | gaim_debug_info("MSNCL","last update time:{%s}\n",update_time); | |
| 262 | update_str = g_strdup_printf(MSN_GET_CONTACT_UPDATE_XML,update_time); | |
| 263 | }else{ | |
| 264 | update_str = g_strdup(""); | |
| 265 | } | |
| 266 | body = g_strdup_printf(MSN_GET_CONTACT_TEMPLATE,update_str); | |
| 13874 | 267 | soap_request = msn_soap_request_new(MSN_CONTACT_SERVER, |
| 268 | MSN_GET_CONTACT_POST_URL,MSN_GET_CONTACT_SOAP_ACTION, | |
| 13910 | 269 | body, |
| 13874 | 270 | msn_get_contact_list_cb, |
| 271 | msn_get_contact_written_cb); | |
| 13876 | 272 | msn_soap_post(contact->soapconn,soap_request,msn_contact_connect_init); |
| 13910 | 273 | g_free(update_str); |
| 274 | g_free(body); | |
| 13854 | 275 | } |
| 276 | ||
| 13855 | 277 | static void |
| 278 | msn_parse_addressbook(MsnContact * contact) | |
| 13854 | 279 | { |
| 13855 | 280 | MsnSession * session; |
| 281 | xmlnode * node,*body,*response,*result; | |
| 282 | xmlnode *groups,*group,*groupname,*groupId,*groupInfo; | |
| 283 | xmlnode *contacts,*contactNode,*contactId,*contactInfo,*contactType,*passportName,*displayName,*groupIds,*guid; | |
| 13910 | 284 | xmlnode *abNode; |
| 13857 | 285 | char *group_name,*group_id; |
| 13855 | 286 | |
| 287 | session = contact->session; | |
| 288 | gaim_debug_misc("xml","parse addressbook:{%s}\nsize:%d\n",contact->soapconn->body,contact->soapconn->body_len); | |
| 289 | node = xmlnode_from_str(contact->soapconn->body, contact->soapconn->body_len); | |
| 290 | ||
| 291 | if(node == NULL){ | |
| 292 | gaim_debug_misc("xml","parse from str err!\n"); | |
| 293 | return; | |
| 294 | } | |
| 295 | gaim_debug_misc("xml","node{%p},name:%s,child:%s,last:%s\n",node,node->name,node->child->name,node->lastchild->name); | |
| 296 | body = xmlnode_get_child(node,"Body"); | |
| 297 | gaim_debug_misc("xml","body{%p},name:%s\n",body,body->name); | |
| 298 | response = xmlnode_get_child(body,"ABFindAllResponse"); | |
| 299 | gaim_debug_misc("xml","response{%p},name:%s\n",response,response->name); | |
| 300 | result =xmlnode_get_child(response,"ABFindAllResult"); | |
| 13910 | 301 | if(result == NULL){ |
| 302 | gaim_debug_misc("MSNAB","receive no address book update\n"); | |
| 303 | return; | |
| 304 | } | |
| 13855 | 305 | gaim_debug_misc("xml","result{%p},name:%s\n",result,result->name); |
| 13857 | 306 | |
| 307 | /*Process Group List*/ | |
| 13855 | 308 | groups =xmlnode_get_child(result,"groups"); |
| 309 | for(group = xmlnode_get_child(groups, "Group"); group; | |
| 310 | group = xmlnode_get_next_twin(group)){ | |
| 13857 | 311 | groupId = xmlnode_get_child(group,"groupId"); |
| 312 | group_id = xmlnode_get_data(groupId); | |
| 313 | groupInfo = xmlnode_get_child(group,"groupInfo"); | |
| 314 | groupname = xmlnode_get_child(groupInfo,"name"); | |
| 315 | group_name = xmlnode_get_data(groupname); | |
| 13855 | 316 | |
| 13857 | 317 | msn_group_new(session->userlist, group_id, group_name); |
| 318 | ||
| 319 | if (group_id == NULL){ | |
| 320 | /* Group of ungroupped buddies */ | |
| 321 | continue; | |
| 322 | } | |
| 13855 | 323 | |
| 13893 | 324 | gaim_debug_misc("MsnAB","group_id:%s name:%s\n",group_id,group_name); |
| 13857 | 325 | if ((gaim_find_group(group_name)) == NULL){ |
| 326 | GaimGroup *g = gaim_group_new(group_name); | |
| 13910 | 327 | gaim_blist_node_set_string(&(g->node),"groupId",group_id); |
| 13857 | 328 | gaim_blist_add_group(g, NULL); |
| 329 | } | |
| 13893 | 330 | g_free(group_id); |
| 331 | g_free(group_name); | |
| 13857 | 332 | } |
| 333 | /*add a default No group to set up the no group Membership*/ | |
| 334 | group_id = g_strdup(MSN_INDIVIDUALS_GROUP_ID); | |
| 335 | group_name = g_strdup(MSN_INDIVIDUALS_GROUP_NAME); | |
| 336 | msn_group_new(session->userlist,group_id , group_name); | |
| 337 | if (group_id != NULL){ | |
| 13893 | 338 | gaim_debug_misc("MsnAB","group_id:%s name:%s,value:%d\n",group_id,group_name,*group_name=='\0'); |
| 13857 | 339 | if ((gaim_find_group(group_name)) == NULL){ |
| 340 | GaimGroup *g = gaim_group_new(group_name); | |
| 341 | gaim_blist_add_group(g, NULL); | |
| 342 | } | |
| 343 | } | |
| 344 | g_free(group_name); | |
| 345 | g_free(group_id); | |
| 13855 | 346 | |
| 13857 | 347 | /*add a default No group to set up the no group Membership*/ |
| 348 | group_id = g_strdup(MSN_NON_IM_GROUP_ID); | |
| 349 | group_name = g_strdup(MSN_NON_IM_GROUP_NAME); | |
| 350 | msn_group_new(session->userlist,group_id , group_name); | |
| 351 | if (group_id != NULL){ | |
| 13893 | 352 | gaim_debug_misc("MsnAB","group_id:%s name:%s,value:%d\n",group_id,group_name,*group_name=='\0'); |
| 13857 | 353 | if ((gaim_find_group(group_name)) == NULL){ |
| 354 | GaimGroup *g = gaim_group_new(group_name); | |
| 355 | gaim_blist_add_group(g, NULL); | |
| 356 | } | |
| 357 | } | |
| 358 | g_free(group_name); | |
| 359 | g_free(group_id); | |
| 13855 | 360 | |
| 13857 | 361 | /*Process contact List*/ |
| 13906 | 362 | gaim_debug_info("MSNAB","process contact list...\n"); |
| 13855 | 363 | contacts =xmlnode_get_child(result,"contacts"); |
| 364 | for(contactNode = xmlnode_get_child(contacts, "Contact"); contactNode; | |
| 365 | contactNode = xmlnode_get_next_twin(contactNode)){ | |
| 366 | MsnUser *user; | |
| 367 | char *passport,*Name,*uid,*type; | |
| 368 | ||
| 13897 | 369 | passport = NULL; |
| 370 | ||
| 13855 | 371 | contactId= xmlnode_get_child(contactNode,"contactId"); |
| 372 | uid = xmlnode_get_data(contactId); | |
| 373 | ||
| 374 | contactInfo = xmlnode_get_child(contactNode,"contactInfo"); | |
| 375 | contactType = xmlnode_get_child(contactInfo,"contactType"); | |
| 376 | type = xmlnode_get_data(contactType); | |
| 377 | ||
| 13895 | 378 | /*setup the Display Name*/ |
| 379 | if (!strcmp(type, "Me")){ | |
| 13897 | 380 | char *friendly; |
| 381 | friendly = xmlnode_get_data(xmlnode_get_child(contactInfo,"displayName")); | |
| 13895 | 382 | gaim_connection_set_display_name(session->account->gc, gaim_url_decode(friendly)); |
| 383 | g_free(friendly); | |
| 384 | } | |
| 385 | ||
| 13855 | 386 | passportName = xmlnode_get_child(contactInfo,"passportName"); |
| 13856 | 387 | if(passportName == NULL){ |
| 13870 | 388 | xmlnode *emailsNode, *contactEmailNode, *emailNode; |
| 389 | xmlnode *messengerEnabledNode; | |
| 390 | char *msnEnabled; | |
| 391 | ||
| 13856 | 392 | /*TODO: add it to the none-instant Messenger group and recognize as email Membership*/ |
| 13870 | 393 | /*Yahoo User?*/ |
| 394 | emailsNode = xmlnode_get_child(contactInfo,"emails"); | |
| 13906 | 395 | if(emailsNode == NULL){ |
| 396 | /*TODO: need to support the Mobile type*/ | |
| 397 | continue; | |
| 398 | } | |
| 13870 | 399 | for(contactEmailNode = xmlnode_get_child(emailsNode,"ContactEmail");contactEmailNode; |
| 400 | contactEmailNode = xmlnode_get_next_twin(contactEmailNode) ){ | |
| 401 | messengerEnabledNode = xmlnode_get_child(contactEmailNode,"isMessengerEnabled"); | |
| 13878 | 402 | if(messengerEnabledNode == NULL){ |
| 403 | break; | |
| 404 | } | |
| 13870 | 405 | msnEnabled = xmlnode_get_data(messengerEnabledNode); |
| 406 | if(!strcmp(msnEnabled,"true")){ | |
| 13897 | 407 | /*Messenger enabled, Get the Passport*/ |
| 13870 | 408 | emailNode = xmlnode_get_child(contactEmailNode,"email"); |
| 409 | passport = xmlnode_get_data(emailNode); | |
| 13893 | 410 | gaim_debug_info("MsnAB","Yahoo User %s\n",passport); |
| 13870 | 411 | break; |
| 13897 | 412 | }else{ |
| 413 | /*TODO maybe we can just ignore it in Gaim?*/ | |
| 414 | emailNode = xmlnode_get_child(contactEmailNode,"email"); | |
| 415 | passport = xmlnode_get_data(emailNode); | |
| 416 | gaim_debug_info("MSNAB","Other type user\n"); | |
| 13870 | 417 | } |
| 13893 | 418 | g_free(msnEnabled); |
| 13870 | 419 | } |
| 420 | }else{ | |
| 421 | passport = xmlnode_get_data(passportName); | |
| 13856 | 422 | } |
| 13855 | 423 | |
| 13897 | 424 | if(passport == NULL){ |
| 425 | continue; | |
| 426 | } | |
| 427 | ||
| 13855 | 428 | displayName = xmlnode_get_child(contactInfo,"displayName"); |
| 13893 | 429 | if(displayName == NULL){ |
| 430 | Name = g_strdup(passport); | |
| 431 | }else{ | |
| 13878 | 432 | Name =xmlnode_get_data(displayName); |
| 13893 | 433 | } |
| 13855 | 434 | |
| 13897 | 435 | gaim_debug_misc("MsnAB","passport:{%s} uid:{%s} display:{%s}\n", |
| 436 | passport,uid,Name); | |
| 13855 | 437 | |
| 13870 | 438 | user = msn_userlist_find_add_user(session->userlist, passport,Name); |
| 13855 | 439 | msn_user_set_uid(user,uid); |
| 440 | msn_user_set_type(user,msn_get_user_type(type)); | |
| 13869 | 441 | user->list_op |= MSN_LIST_FL_OP; |
| 13893 | 442 | g_free(Name); |
| 443 | g_free(passport); | |
| 444 | g_free(uid); | |
| 445 | g_free(type); | |
| 13855 | 446 | |
| 13906 | 447 | gaim_debug_misc("MsnAB","parse guid...\n"); |
| 13855 | 448 | groupIds = xmlnode_get_child(contactInfo,"groupIds"); |
| 449 | if(groupIds){ | |
| 450 | for(guid = xmlnode_get_child(groupIds, "guid");guid; | |
| 451 | guid = xmlnode_get_next_twin(guid)){ | |
| 452 | group_id = xmlnode_get_data(guid); | |
| 453 | msn_user_add_group_id(user,group_id); | |
| 13893 | 454 | gaim_debug_misc("MsnAB","guid:%s\n",group_id); |
| 455 | g_free(group_id); | |
| 13855 | 456 | } |
| 457 | }else{ | |
| 13894 | 458 | /*not in any group,Then set default group*/ |
| 13857 | 459 | group_id = g_strdup(MSN_INDIVIDUALS_GROUP_ID); |
| 460 | msn_user_add_group_id(user,group_id); | |
| 461 | g_free(group_id); | |
| 13855 | 462 | } |
| 463 | } | |
| 464 | ||
| 13904 | 465 | abNode =xmlnode_get_child(result,"ab"); |
| 466 | if(abNode != NULL){ | |
| 13910 | 467 | xmlnode *LastChangeNode, *DynamicItemLastChangedNode; |
| 468 | char *lastchange, *dynamicChange; | |
| 469 | ||
| 13904 | 470 | LastChangeNode = xmlnode_get_child(abNode,"lastChange"); |
| 471 | lastchange = xmlnode_get_data(LastChangeNode); | |
| 13906 | 472 | gaim_debug_info("MsnAB"," lastchanged Time:{%s}\n",lastchange); |
| 13910 | 473 | gaim_blist_node_set_string(msn_session_get_bnode(contact->session),"ablastChange",lastchange); |
| 474 | ||
| 475 | DynamicItemLastChangedNode = xmlnode_get_child(abNode,"DynamicItemLastChanged"); | |
| 476 | dynamicChange = xmlnode_get_data(DynamicItemLastChangedNode); | |
| 477 | gaim_debug_info("MsnAB"," DynamicItemLastChanged :{%s}\n",dynamicChange); | |
| 478 | gaim_blist_node_set_string(msn_session_get_bnode(contact->session),"DynamicItemLastChanged",lastchange); | |
| 13904 | 479 | } |
| 13855 | 480 | |
| 481 | xmlnode_free(node); | |
| 482 | msn_soap_free_read_buf(contact->soapconn); | |
| 13854 | 483 | } |
| 484 | ||
| 13855 | 485 | static void |
| 486 | msn_get_address_cb(gpointer data, gint source, GaimInputCondition cond) | |
| 13854 | 487 | { |
| 13855 | 488 | MsnSoapConn * soapconn = data; |
| 489 | MsnContact *contact; | |
| 490 | MsnSession *session; | |
| 491 | ||
| 492 | contact = soapconn->parent; | |
| 493 | g_return_if_fail(contact != NULL); | |
| 494 | session = soapconn->session; | |
| 495 | g_return_if_fail(session != NULL); | |
| 496 | ||
| 497 | // gaim_debug_misc("msn", "soap contact server Reply: {%s}\n", soapconn->read_buf); | |
| 498 | msn_parse_addressbook(contact); | |
| 13898 | 499 | |
| 500 | msn_notification_dump_contact(session); | |
| 501 | msn_set_psm(session); | |
| 502 | msn_session_finish_login(session); | |
| 503 | ||
| 13886 | 504 | /*free the read buffer*/ |
| 505 | msn_soap_free_read_buf(soapconn); | |
| 13855 | 506 | } |
| 507 | ||
| 508 | /**/ | |
| 509 | static void | |
| 510 | msn_address_written_cb(gpointer data, gint source, GaimInputCondition cond) | |
| 511 | { | |
| 512 | MsnSoapConn * soapconn = data; | |
| 513 | ||
| 514 | gaim_debug_info("MaYuan","finish contact written\n"); | |
| 515 | soapconn->read_cb = msn_get_address_cb; | |
| 13854 | 516 | } |
| 517 | ||
| 13855 | 518 | /*get the address book*/ |
| 519 | void | |
| 13910 | 520 | msn_get_address_book(MsnContact *contact,char * LastChanged, char * dynamicItemLastChange) |
| 13854 | 521 | { |
| 13874 | 522 | MsnSoapReq *soap_request; |
| 13910 | 523 | char *body = NULL; |
| 524 | char *ab_update_str,*update_str; | |
| 13874 | 525 | |
| 13855 | 526 | gaim_debug_info("MaYuan","msn_get_address_book()...\n"); |
| 527 | /*build SOAP and POST it*/ | |
| 13910 | 528 | if(LastChanged != NULL){ |
| 529 | ab_update_str = g_strdup_printf(MSN_GET_ADDRESS_UPDATE_XML,LastChanged); | |
| 530 | }else{ | |
| 531 | ab_update_str = g_strdup(""); | |
| 532 | } | |
| 533 | if(dynamicItemLastChange != NULL){ | |
| 534 | update_str = g_strdup_printf(MSN_GET_ADDRESS_UPDATE_XML, | |
| 535 | ab_update_str,dynamicItemLastChange); | |
| 536 | }else{ | |
| 537 | update_str = g_strdup(ab_update_str); | |
| 538 | } | |
| 539 | g_free(ab_update_str); | |
| 540 | ||
| 541 | body = g_strdup_printf(MSN_GET_ADDRESS_TEMPLATE,update_str); | |
| 13874 | 542 | soap_request = msn_soap_request_new(MSN_CONTACT_SERVER, |
| 543 | MSN_ADDRESS_BOOK_POST_URL,MSN_GET_ADDRESS_SOAP_ACTION, | |
| 13910 | 544 | body, |
| 13874 | 545 | msn_get_address_cb, |
| 546 | msn_address_written_cb); | |
| 13876 | 547 | msn_soap_post(contact->soapconn,soap_request,msn_contact_connect_init); |
| 13910 | 548 | g_free(update_str); |
| 549 | g_free(body); | |
| 13855 | 550 | } |
| 551 | ||
| 13866 | 552 | static void |
| 553 | msn_add_contact_read_cb(gpointer data, gint source, GaimInputCondition cond) | |
| 554 | { | |
| 13897 | 555 | gaim_debug_info("MaYuan","add contact read done\n"); |
| 13866 | 556 | } |
| 557 | ||
| 558 | static void | |
| 559 | msn_add_contact_written_cb(gpointer data, gint source, GaimInputCondition cond) | |
| 560 | { | |
| 561 | MsnSoapConn * soapconn = data; | |
| 562 | ||
| 13897 | 563 | gaim_debug_info("MaYuan","finish add contact written\n"); |
| 13866 | 564 | soapconn->read_cb = msn_add_contact_read_cb; |
| 13880 | 565 | // msn_soap_read_cb(data,source,cond); |
| 13866 | 566 | } |
| 567 | ||
| 13859 | 568 | /*add a Contact */ |
| 13855 | 569 | void |
| 13897 | 570 | msn_add_contact(MsnContact *contact,const char *passport,const char *groupId) |
| 13855 | 571 | { |
| 13874 | 572 | MsnSoapReq *soap_request; |
| 13864 | 573 | char *body = NULL; |
| 574 | char *contact_xml = NULL; | |
| 13874 | 575 | char *soap_action; |
| 13864 | 576 | |
| 13860 | 577 | gaim_debug_info("MaYuan","msn add a contact...\n"); |
| 13864 | 578 | contact_xml = g_strdup_printf(MSN_CONTACT_XML,passport); |
| 13866 | 579 | if(groupId == NULL){ |
| 580 | body = g_strdup_printf(MSN_ADD_CONTACT_TEMPLATE,contact_xml); | |
| 581 | g_free(contact_xml); | |
| 582 | /*build SOAP and POST it*/ | |
| 13874 | 583 | soap_action = g_strdup(MSN_CONTACT_ADD_SOAP_ACTION); |
| 13866 | 584 | }else{ |
| 585 | body = g_strdup_printf(MSN_ADD_CONTACT_GROUP_TEMPLATE,groupId,contact_xml); | |
| 586 | g_free(contact_xml); | |
| 587 | /*build SOAP and POST it*/ | |
| 13874 | 588 | soap_action = g_strdup(MSN_ADD_CONTACT_GROUP_SOAP_ACTION); |
| 13866 | 589 | } |
| 13874 | 590 | soap_request = msn_soap_request_new(MSN_CONTACT_SERVER, |
| 591 | MSN_ADDRESS_BOOK_POST_URL,soap_action, | |
| 592 | body, | |
| 593 | msn_add_contact_read_cb, | |
| 594 | msn_add_contact_written_cb); | |
| 13876 | 595 | msn_soap_post(contact->soapconn,soap_request,msn_contact_connect_init); |
| 13863 | 596 | |
| 13874 | 597 | g_free(soap_action); |
| 13864 | 598 | g_free(body); |
| 13854 | 599 | } |
| 600 | ||
| 13866 | 601 | static void |
| 602 | msn_delete_contact_read_cb(gpointer data, gint source, GaimInputCondition cond) | |
| 603 | { | |
| 604 | gaim_debug_info("MaYuan","delete contact read done\n"); | |
| 605 | } | |
| 606 | ||
| 607 | static void | |
| 608 | msn_delete_contact_written_cb(gpointer data, gint source, GaimInputCondition cond) | |
| 609 | { | |
| 610 | MsnSoapConn * soapconn = data; | |
| 611 | ||
| 612 | gaim_debug_info("MaYuan","delete contact written\n"); | |
| 613 | soapconn->read_cb = msn_delete_contact_read_cb; | |
| 13880 | 614 | // msn_soap_read_cb(data,source,cond); |
| 13866 | 615 | } |
| 616 | ||
| 13859 | 617 | /*delete a Contact*/ |
| 13855 | 618 | void |
| 13866 | 619 | msn_delete_contact(MsnContact *contact,const char *contactId) |
| 13855 | 620 | { |
| 13864 | 621 | char *body = NULL; |
| 622 | char *contact_xml = NULL ; | |
| 13874 | 623 | MsnSoapReq *soap_request; |
| 13864 | 624 | |
| 13901 | 625 | g_return_if_fail(contactId != NULL); |
| 13866 | 626 | gaim_debug_info("MaYuan","msn delete a contact,contactId:{%s}...\n",contactId); |
| 627 | contact_xml = g_strdup_printf(MSN_CONTACTS_DEL_XML,contactId); | |
| 13864 | 628 | body = g_strdup_printf(MSN_DEL_CONTACT_TEMPLATE,contact_xml); |
| 629 | g_free(contact_xml); | |
| 13863 | 630 | /*build SOAP and POST it*/ |
| 13874 | 631 | soap_request = msn_soap_request_new(MSN_CONTACT_SERVER, |
| 632 | MSN_ADDRESS_BOOK_POST_URL,MSN_CONTACT_DEL_SOAP_ACTION, | |
| 633 | body, | |
| 634 | msn_delete_contact_read_cb, | |
| 635 | msn_delete_contact_written_cb); | |
| 13876 | 636 | msn_soap_post(contact->soapconn,soap_request,msn_contact_connect_init); |
| 13874 | 637 | |
| 13864 | 638 | g_free(body); |
| 13855 | 639 | } |
| 640 | ||
| 13866 | 641 | static void |
| 13909 | 642 | msn_update_contact_read_cb(gpointer data, gint source, GaimInputCondition cond) |
| 643 | { | |
| 644 | gaim_debug_info("MaYuan","update contact read done\n"); | |
| 645 | } | |
| 646 | ||
| 647 | static void | |
| 648 | msn_update_contact_written_cb(gpointer data, gint source, GaimInputCondition cond) | |
| 649 | { | |
| 650 | MsnSoapConn * soapconn = data; | |
| 651 | ||
| 652 | gaim_debug_info("MaYuan","update contact written\n"); | |
| 653 | soapconn->read_cb = msn_update_contact_read_cb; | |
| 654 | // msn_soap_read_cb(data,source,cond); | |
| 655 | } | |
| 656 | ||
| 657 | /*update a contact's Nickname*/ | |
| 658 | void | |
| 659 | msn_update_contact(MsnContact *contact,const char* nickname) | |
| 660 | { | |
| 661 | MsnSoapReq *soap_request; | |
| 662 | char *body = NULL; | |
| 663 | ||
| 664 | gaim_debug_info("MaYuan","msn unblock a contact...\n"); | |
| 665 | ||
| 666 | body = g_strdup_printf(MSN_CONTACT_UPDATE_TEMPLATE,nickname); | |
| 667 | /*build SOAP and POST it*/ | |
| 668 | soap_request = msn_soap_request_new(MSN_CONTACT_SERVER, | |
| 669 | MSN_ADDRESS_BOOK_POST_URL,MSN_CONTACT_UPDATE_SOAP_ACTION, | |
| 670 | body, | |
| 671 | msn_update_contact_read_cb, | |
| 672 | msn_update_contact_written_cb); | |
| 673 | msn_soap_post(contact->soapconn,soap_request,msn_contact_connect_init); | |
| 674 | ||
| 675 | g_free(body); | |
| 676 | } | |
| 677 | ||
| 678 | static void | |
| 13866 | 679 | msn_block_read_cb(gpointer data, gint source, GaimInputCondition cond) |
| 680 | { | |
| 681 | gaim_debug_info("MaYuan","block read done\n"); | |
| 682 | } | |
| 683 | ||
| 684 | static void | |
| 685 | msn_block_written_cb(gpointer data, gint source, GaimInputCondition cond) | |
| 686 | { | |
| 687 | MsnSoapConn * soapconn = data; | |
| 688 | ||
| 689 | gaim_debug_info("MaYuan","finish unblock written\n"); | |
| 690 | soapconn->read_cb = msn_block_read_cb; | |
| 691 | } | |
| 692 | ||
| 13859 | 693 | /*block a Contact*/ |
| 13855 | 694 | void |
| 13864 | 695 | msn_block_contact(MsnContact *contact,const char* membership_id) |
| 696 | { | |
| 13874 | 697 | MsnSoapReq *soap_request; |
| 13864 | 698 | char *body = NULL; |
| 699 | ||
| 13860 | 700 | gaim_debug_info("MaYuan","msn block a contact...\n"); |
| 13864 | 701 | body = g_strdup_printf(MSN_CONTACT_DELECT_FROM_ALLOW_TEMPLATE,membership_id); |
| 13863 | 702 | /*build SOAP and POST it*/ |
| 13874 | 703 | soap_request = msn_soap_request_new(MSN_CONTACT_SERVER, |
| 704 | MSN_SHARE_POST_URL,MSN_CONTACT_BLOCK_SOAP_ACTION, | |
| 705 | body, | |
| 706 | msn_block_read_cb, | |
| 707 | msn_block_written_cb); | |
| 13876 | 708 | msn_soap_post(contact->soapconn,soap_request,msn_contact_connect_init); |
| 13874 | 709 | |
| 13864 | 710 | g_free(body); |
| 13855 | 711 | } |
| 712 | ||
| 13866 | 713 | static void |
| 714 | msn_unblock_read_cb(gpointer data, gint source, GaimInputCondition cond) | |
| 715 | { | |
| 716 | gaim_debug_info("MaYuan","unblock read done\n"); | |
| 717 | } | |
| 718 | ||
| 719 | static void | |
| 720 | msn_unblock_written_cb(gpointer data, gint source, GaimInputCondition cond) | |
| 721 | { | |
| 722 | MsnSoapConn * soapconn = data; | |
| 723 | ||
| 724 | gaim_debug_info("MaYuan","finish unblock written\n"); | |
| 725 | soapconn->read_cb = msn_unblock_read_cb; | |
| 726 | } | |
| 727 | ||
| 13859 | 728 | /*unblock a contact*/ |
| 13855 | 729 | void |
| 13864 | 730 | msn_unblock_contact(MsnContact *contact,const char* passport) |
| 731 | { | |
| 13874 | 732 | MsnSoapReq *soap_request; |
| 13864 | 733 | char *body = NULL; |
| 734 | ||
| 13860 | 735 | gaim_debug_info("MaYuan","msn unblock a contact...\n"); |
| 13864 | 736 | |
| 737 | body = g_strdup_printf(MSN_UNBLOCK_CONTACT_TEMPLATE,passport); | |
| 13863 | 738 | /*build SOAP and POST it*/ |
| 13874 | 739 | soap_request = msn_soap_request_new(MSN_CONTACT_SERVER, |
| 740 | MSN_SHARE_POST_URL,MSN_CONTACT_UNBLOCK_SOAP_ACTION, | |
| 741 | body, | |
| 742 | msn_unblock_read_cb, | |
| 743 | msn_unblock_written_cb); | |
| 13876 | 744 | msn_soap_post(contact->soapconn,soap_request,msn_contact_connect_init); |
| 13874 | 745 | |
| 13864 | 746 | g_free(body); |
| 13855 | 747 | } |
| 748 | ||
| 13866 | 749 | static void |
| 750 | msn_gleams_read_cb(gpointer data, gint source, GaimInputCondition cond) | |
| 751 | { | |
| 752 | gaim_debug_info("MaYuan","Gleams read done\n"); | |
| 753 | } | |
| 754 | ||
| 755 | static void | |
| 756 | msn_gleams_written_cb(gpointer data, gint source, GaimInputCondition cond) | |
| 757 | { | |
| 758 | MsnSoapConn * soapconn = data; | |
| 759 | ||
| 760 | gaim_debug_info("MaYuan","finish Group written\n"); | |
| 761 | soapconn->read_cb = msn_gleams_read_cb; | |
| 13880 | 762 | // msn_soap_read_cb(data,source,cond); |
| 13866 | 763 | } |
| 764 | ||
| 13859 | 765 | /*get the gleams info*/ |
| 13855 | 766 | void |
| 767 | msn_get_gleams(MsnContact *contact) | |
| 13854 | 768 | { |
| 13874 | 769 | MsnSoapReq *soap_request; |
| 770 | ||
| 13860 | 771 | gaim_debug_info("MaYuan","msn get gleams info...\n"); |
| 772 | /*build SOAP and POST it*/ | |
| 13874 | 773 | soap_request = msn_soap_request_new(MSN_CONTACT_SERVER, |
| 774 | MSN_ADDRESS_BOOK_POST_URL,MSN_GET_GLEAMS_SOAP_ACTION, | |
| 775 | MSN_GLEAMS_TEMPLATE, | |
| 776 | msn_gleams_read_cb, | |
| 777 | msn_gleams_written_cb); | |
| 13876 | 778 | msn_soap_post(contact->soapconn,soap_request,msn_contact_connect_init); |
| 13854 | 779 | } |
| 780 | ||
| 13865 | 781 | /*************************************************************** |
| 782 | * Group Operation | |
| 783 | ***************************************************************/ | |
| 784 | static void | |
| 785 | msn_group_read_cb(gpointer data, gint source, GaimInputCondition cond) | |
| 786 | { | |
| 787 | gaim_debug_info("MaYuan","Group read \n"); | |
| 788 | } | |
| 789 | ||
| 790 | static void | |
| 791 | msn_group_written_cb(gpointer data, gint source, GaimInputCondition cond) | |
| 792 | { | |
| 793 | MsnSoapConn * soapconn = data; | |
| 794 | ||
| 795 | gaim_debug_info("MaYuan","finish Group written\n"); | |
| 796 | soapconn->read_cb = msn_group_read_cb; | |
| 13880 | 797 | // msn_soap_read_cb(data,source,cond); |
| 13865 | 798 | } |
| 799 | ||
| 13864 | 800 | /*add group*/ |
| 13865 | 801 | void msn_add_group(MsnSession *session,const char* group_name) |
| 13863 | 802 | { |
| 13874 | 803 | MsnSoapReq *soap_request; |
| 804 | MsnContact *contact ; | |
| 13865 | 805 | char *body = NULL; |
| 806 | ||
| 807 | g_return_if_fail(session != NULL); | |
| 808 | contact = session->contact; | |
| 13863 | 809 | gaim_debug_info("MaYuan","msn add group...\n"); |
| 810 | ||
| 13865 | 811 | body = g_strdup_printf(MSN_GROUP_ADD_TEMPLATE,group_name); |
| 13863 | 812 | /*build SOAP and POST it*/ |
| 13874 | 813 | soap_request = msn_soap_request_new(MSN_CONTACT_SERVER, |
| 814 | MSN_ADDRESS_BOOK_POST_URL,MSN_GROUP_ADD_SOAP_ACTION, | |
| 815 | body, | |
| 816 | msn_group_read_cb, | |
| 817 | msn_group_written_cb); | |
| 13876 | 818 | msn_soap_post(contact->soapconn,soap_request,msn_contact_connect_init); |
| 13863 | 819 | } |
| 820 | ||
| 13864 | 821 | /*delete a group*/ |
| 13865 | 822 | void msn_del_group(MsnSession *session,const char *guid) |
| 13863 | 823 | { |
| 13874 | 824 | MsnSoapReq *soap_request; |
| 13865 | 825 | MsnContact *contact; |
| 826 | char *body = NULL; | |
| 827 | ||
| 828 | g_return_if_fail(session != NULL); | |
| 13897 | 829 | /*if group uid we need to del is NULL, |
| 830 | * we need to delete nothing | |
| 831 | */ | |
| 832 | g_return_if_fail(guid != NULL); | |
| 13865 | 833 | contact = session->contact; |
| 13863 | 834 | gaim_debug_info("MaYuan","msn del group...\n"); |
| 835 | ||
| 13865 | 836 | body = g_strdup_printf(MSN_GROUP_DEL_TEMPLATE,guid); |
| 13863 | 837 | /*build SOAP and POST it*/ |
| 13874 | 838 | soap_request = msn_soap_request_new(MSN_CONTACT_SERVER, |
| 839 | MSN_ADDRESS_BOOK_POST_URL,MSN_GROUP_DEL_SOAP_ACTION, | |
| 840 | body, | |
| 841 | msn_group_read_cb, | |
| 842 | msn_group_written_cb); | |
| 13876 | 843 | msn_soap_post(contact->soapconn,soap_request,msn_contact_connect_init); |
| 13874 | 844 | |
| 13865 | 845 | g_free(body); |
| 13863 | 846 | } |
| 847 | ||
| 13854 | 848 | void |
| 13876 | 849 | msn_contact_connect_init(MsnSoapConn *soapconn) |
| 13854 | 850 | { |
| 851 | /* Authenticate via Windows Live ID. */ | |
| 852 | gaim_debug_info("MaYuan","msn_contact_connect...\n"); | |
| 853 | ||
| 13876 | 854 | msn_soap_init(soapconn,MSN_CONTACT_SERVER,1, |
| 13854 | 855 | msn_contact_login_connect_cb, |
| 856 | msn_contact_login_error_cb); | |
| 857 | } | |
| 858 |