Sun, 27 Aug 2006 11:45:02 +0000
[gaim-migrate @ 17057]
fix contact delete bug:
when Send ADL,NS disconnect.<fix the add/delte XML format>
committed by MaYuan<mayuan2006@gmail.com>
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*/ | |
| 13876 | 88 | // msn_get_contact_list(contact); |
| 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; | |
| 129 | xmlnode * node,*body,*response,*result,*services,*service,*memberships; | |
| 13893 | 130 | xmlnode *membershipnode,*members,*member,*passportNode; |
| 13854 | 131 | |
| 13855 | 132 | session = contact->session; |
| 13870 | 133 | gaim_debug_misc("xml","parse contact list:{%s}\nsize:%d\n",contact->soapconn->body,contact->soapconn->body_len); |
| 13854 | 134 | node = xmlnode_from_str(contact->soapconn->body, contact->soapconn->body_len); |
| 135 | // node = xmlnode_from_str(contact->soapconn->body, -1); | |
| 136 | ||
| 137 | if(node == NULL){ | |
| 138 | gaim_debug_misc("xml","parse from str err!\n"); | |
| 139 | return; | |
| 140 | } | |
| 141 | gaim_debug_misc("xml","node{%p},name:%s,child:%s,last:%s\n",node,node->name,node->child->name,node->lastchild->name); | |
| 142 | body = xmlnode_get_child(node,"Body"); | |
| 143 | gaim_debug_misc("xml","body{%p},name:%s\n",body,body->name); | |
| 144 | response = xmlnode_get_child(body,"FindMembershipResponse"); | |
| 145 | gaim_debug_misc("xml","response{%p},name:%s\n",response,response->name); | |
| 146 | result =xmlnode_get_child(response,"FindMembershipResult"); | |
| 147 | gaim_debug_misc("xml","result{%p},name:%s\n",result,result->name); | |
| 148 | services =xmlnode_get_child(result,"Services"); | |
| 149 | gaim_debug_misc("xml","services{%p},name:%s\n",services,services->name); | |
| 150 | service =xmlnode_get_child(services,"Service"); | |
| 151 | gaim_debug_misc("xml","service{%p},name:%s\n",service,service->name); | |
| 152 | memberships =xmlnode_get_child(service,"Memberships"); | |
| 153 | gaim_debug_misc("xml","memberships{%p},name:%s\n",memberships,memberships->name); | |
| 154 | for(membershipnode = xmlnode_get_child(memberships, "Membership"); membershipnode; | |
| 155 | membershipnode = xmlnode_get_next_twin(membershipnode)){ | |
| 13893 | 156 | xmlnode *roleNode; |
| 157 | char *role; | |
| 158 | roleNode = xmlnode_get_child(membershipnode,"MemberRole"); | |
| 159 | role=xmlnode_get_data(roleNode); | |
| 160 | list_op = msn_get_memberrole(role); | |
| 161 | gaim_debug_misc("memberrole","role:%s,list_op:%d\n",role,list_op); | |
| 162 | g_free(role); | |
| 13854 | 163 | members = xmlnode_get_child(membershipnode,"Members"); |
| 13855 | 164 | for(member = xmlnode_get_child(members, "Member"); member; |
| 165 | member = xmlnode_get_next_twin(member)){ | |
| 13870 | 166 | MsnUser *user; |
| 13856 | 167 | xmlnode * typeNode; |
| 168 | char * type; | |
| 169 | ||
| 170 | gaim_debug_misc("MaYuan","type:%s\n",xmlnode_get_attrib(member,"type")); | |
| 171 | if(!g_strcasecmp(xmlnode_get_attrib(member,"type"),"PassportMember")){ | |
| 172 | passportNode = xmlnode_get_child(member,"PassportName"); | |
| 173 | passport = xmlnode_get_data(passportNode); | |
| 174 | typeNode = xmlnode_get_child(member,"Type"); | |
| 175 | type = xmlnode_get_data(typeNode); | |
| 176 | gaim_debug_misc("Passport","name:%s,type:%s\n",passport,type); | |
| 13893 | 177 | g_free(type); |
| 13870 | 178 | |
| 179 | user = msn_userlist_find_add_user(session->userlist,passport,NULL); | |
| 13856 | 180 | msn_got_lst_user(session, user, list_op, NULL); |
| 13893 | 181 | g_free(passport); |
| 13854 | 182 | } |
| 13856 | 183 | if(!g_strcasecmp(xmlnode_get_attrib(member,"type"),"PhoneMember")){ |
| 184 | } | |
| 185 | if(!g_strcasecmp(xmlnode_get_attrib(member,"type"),"EmailMember")){ | |
| 13870 | 186 | xmlnode *emailNode; |
| 187 | ||
| 188 | emailNode = xmlnode_get_child(member,"Email"); | |
| 189 | passport = xmlnode_get_data(emailNode); | |
| 190 | gaim_debug_info("Email","name:%s,list_op:%d\n",passport,list_op); | |
| 191 | user = msn_userlist_find_add_user(session->userlist,passport,NULL); | |
| 192 | msn_got_lst_user(session,user,list_op,NULL); | |
| 13893 | 193 | g_free(passport); |
| 13856 | 194 | } |
| 13855 | 195 | } |
| 13854 | 196 | } |
| 197 | ||
| 198 | xmlnode_free(node); | |
| 199 | } | |
| 200 | ||
| 201 | static void | |
| 202 | msn_get_contact_list_cb(gpointer data, gint source, GaimInputCondition cond) | |
| 203 | { | |
| 204 | MsnSoapConn * soapconn = data; | |
| 205 | MsnContact *contact; | |
| 206 | MsnSession *session; | |
| 207 | ||
| 208 | contact = soapconn->parent; | |
| 209 | g_return_if_fail(contact != NULL); | |
| 210 | session = soapconn->session; | |
| 211 | g_return_if_fail(session != NULL); | |
| 212 | ||
| 13896 | 213 | #ifdef MSN_CONTACT_SOAP_DEBUG |
| 214 | gaim_debug_misc("msn", "soap contact server Reply: {%s}\n", soapconn->read_buf); | |
| 215 | #endif | |
| 13854 | 216 | msn_parse_contact_list(contact); |
| 13886 | 217 | /*free the read buffer*/ |
| 218 | msn_soap_free_read_buf(soapconn); | |
| 219 | ||
| 220 | msn_get_address_book(contact); | |
| 13854 | 221 | } |
| 222 | ||
| 223 | static void | |
| 13866 | 224 | msn_get_contact_written_cb(gpointer data, gint source, GaimInputCondition cond) |
| 13854 | 225 | { |
| 226 | MsnSoapConn * soapconn = data; | |
| 227 | ||
| 228 | gaim_debug_info("MaYuan","finish contact written\n"); | |
| 229 | soapconn->read_cb = msn_get_contact_list_cb; | |
| 13880 | 230 | // msn_soap_read_cb(data,source,cond); |
| 13854 | 231 | } |
| 232 | ||
| 233 | void | |
| 234 | msn_get_contact_list(MsnContact * contact) | |
| 235 | { | |
| 13874 | 236 | MsnSoapReq *soap_request; |
| 237 | ||
| 13876 | 238 | gaim_debug_info("MaYuan","Getting Contact List...\n"); |
| 13874 | 239 | soap_request = msn_soap_request_new(MSN_CONTACT_SERVER, |
| 240 | MSN_GET_CONTACT_POST_URL,MSN_GET_CONTACT_SOAP_ACTION, | |
| 241 | MSN_GET_CONTACT_TEMPLATE, | |
| 242 | msn_get_contact_list_cb, | |
| 243 | msn_get_contact_written_cb); | |
| 13876 | 244 | msn_soap_post(contact->soapconn,soap_request,msn_contact_connect_init); |
| 13854 | 245 | } |
| 246 | ||
| 13855 | 247 | static void |
| 248 | msn_parse_addressbook(MsnContact * contact) | |
| 13854 | 249 | { |
| 13855 | 250 | MsnSession * session; |
| 251 | xmlnode * node,*body,*response,*result; | |
| 252 | xmlnode *groups,*group,*groupname,*groupId,*groupInfo; | |
| 253 | xmlnode *contacts,*contactNode,*contactId,*contactInfo,*contactType,*passportName,*displayName,*groupIds,*guid; | |
| 254 | xmlnode *ab; | |
| 13857 | 255 | char *group_name,*group_id; |
| 13855 | 256 | |
| 257 | session = contact->session; | |
| 258 | gaim_debug_misc("xml","parse addressbook:{%s}\nsize:%d\n",contact->soapconn->body,contact->soapconn->body_len); | |
| 259 | node = xmlnode_from_str(contact->soapconn->body, contact->soapconn->body_len); | |
| 260 | ||
| 261 | if(node == NULL){ | |
| 262 | gaim_debug_misc("xml","parse from str err!\n"); | |
| 263 | return; | |
| 264 | } | |
| 265 | gaim_debug_misc("xml","node{%p},name:%s,child:%s,last:%s\n",node,node->name,node->child->name,node->lastchild->name); | |
| 266 | body = xmlnode_get_child(node,"Body"); | |
| 267 | gaim_debug_misc("xml","body{%p},name:%s\n",body,body->name); | |
| 268 | response = xmlnode_get_child(body,"ABFindAllResponse"); | |
| 269 | gaim_debug_misc("xml","response{%p},name:%s\n",response,response->name); | |
| 270 | result =xmlnode_get_child(response,"ABFindAllResult"); | |
| 271 | gaim_debug_misc("xml","result{%p},name:%s\n",result,result->name); | |
| 13857 | 272 | |
| 273 | /*Process Group List*/ | |
| 13855 | 274 | groups =xmlnode_get_child(result,"groups"); |
| 275 | for(group = xmlnode_get_child(groups, "Group"); group; | |
| 276 | group = xmlnode_get_next_twin(group)){ | |
| 13857 | 277 | groupId = xmlnode_get_child(group,"groupId"); |
| 278 | group_id = xmlnode_get_data(groupId); | |
| 279 | groupInfo = xmlnode_get_child(group,"groupInfo"); | |
| 280 | groupname = xmlnode_get_child(groupInfo,"name"); | |
| 281 | group_name = xmlnode_get_data(groupname); | |
| 13855 | 282 | |
| 13857 | 283 | msn_group_new(session->userlist, group_id, group_name); |
| 284 | ||
| 285 | if (group_id == NULL){ | |
| 286 | /* Group of ungroupped buddies */ | |
| 287 | continue; | |
| 288 | } | |
| 13855 | 289 | |
| 13893 | 290 | gaim_debug_misc("MsnAB","group_id:%s name:%s\n",group_id,group_name); |
| 13857 | 291 | if ((gaim_find_group(group_name)) == NULL){ |
| 292 | GaimGroup *g = gaim_group_new(group_name); | |
| 293 | gaim_blist_add_group(g, NULL); | |
| 294 | } | |
| 13893 | 295 | g_free(group_id); |
| 296 | g_free(group_name); | |
| 13857 | 297 | } |
| 298 | /*add a default No group to set up the no group Membership*/ | |
| 299 | group_id = g_strdup(MSN_INDIVIDUALS_GROUP_ID); | |
| 300 | group_name = g_strdup(MSN_INDIVIDUALS_GROUP_NAME); | |
| 301 | msn_group_new(session->userlist,group_id , group_name); | |
| 302 | if (group_id != NULL){ | |
| 13893 | 303 | gaim_debug_misc("MsnAB","group_id:%s name:%s,value:%d\n",group_id,group_name,*group_name=='\0'); |
| 13857 | 304 | if ((gaim_find_group(group_name)) == NULL){ |
| 305 | GaimGroup *g = gaim_group_new(group_name); | |
| 306 | gaim_blist_add_group(g, NULL); | |
| 307 | } | |
| 308 | } | |
| 309 | g_free(group_name); | |
| 310 | g_free(group_id); | |
| 13855 | 311 | |
| 13857 | 312 | /*add a default No group to set up the no group Membership*/ |
| 313 | group_id = g_strdup(MSN_NON_IM_GROUP_ID); | |
| 314 | group_name = g_strdup(MSN_NON_IM_GROUP_NAME); | |
| 315 | msn_group_new(session->userlist,group_id , group_name); | |
| 316 | if (group_id != NULL){ | |
| 13893 | 317 | gaim_debug_misc("MsnAB","group_id:%s name:%s,value:%d\n",group_id,group_name,*group_name=='\0'); |
| 13857 | 318 | if ((gaim_find_group(group_name)) == NULL){ |
| 319 | GaimGroup *g = gaim_group_new(group_name); | |
| 320 | gaim_blist_add_group(g, NULL); | |
| 321 | } | |
| 322 | } | |
| 323 | g_free(group_name); | |
| 324 | g_free(group_id); | |
| 13855 | 325 | |
| 13857 | 326 | /*Process contact List*/ |
| 13855 | 327 | contacts =xmlnode_get_child(result,"contacts"); |
| 328 | for(contactNode = xmlnode_get_child(contacts, "Contact"); contactNode; | |
| 329 | contactNode = xmlnode_get_next_twin(contactNode)){ | |
| 330 | MsnUser *user; | |
| 331 | char *passport,*Name,*uid,*type; | |
| 332 | ||
| 13897 | 333 | passport = NULL; |
| 334 | ||
| 13855 | 335 | contactId= xmlnode_get_child(contactNode,"contactId"); |
| 336 | uid = xmlnode_get_data(contactId); | |
| 337 | ||
| 338 | contactInfo = xmlnode_get_child(contactNode,"contactInfo"); | |
| 339 | contactType = xmlnode_get_child(contactInfo,"contactType"); | |
| 340 | type = xmlnode_get_data(contactType); | |
| 341 | ||
| 13895 | 342 | /*setup the Display Name*/ |
| 343 | if (!strcmp(type, "Me")){ | |
| 13897 | 344 | char *friendly; |
| 345 | friendly = xmlnode_get_data(xmlnode_get_child(contactInfo,"displayName")); | |
| 13895 | 346 | gaim_connection_set_display_name(session->account->gc, gaim_url_decode(friendly)); |
| 347 | g_free(friendly); | |
| 348 | } | |
| 349 | ||
| 13855 | 350 | passportName = xmlnode_get_child(contactInfo,"passportName"); |
| 13856 | 351 | if(passportName == NULL){ |
| 13870 | 352 | xmlnode *emailsNode, *contactEmailNode, *emailNode; |
| 353 | xmlnode *messengerEnabledNode; | |
| 354 | char *msnEnabled; | |
| 355 | ||
| 13856 | 356 | /*TODO: add it to the none-instant Messenger group and recognize as email Membership*/ |
| 13870 | 357 | /*Yahoo User?*/ |
| 358 | emailsNode = xmlnode_get_child(contactInfo,"emails"); | |
| 359 | for(contactEmailNode = xmlnode_get_child(emailsNode,"ContactEmail");contactEmailNode; | |
| 360 | contactEmailNode = xmlnode_get_next_twin(contactEmailNode) ){ | |
| 361 | messengerEnabledNode = xmlnode_get_child(contactEmailNode,"isMessengerEnabled"); | |
| 13878 | 362 | if(messengerEnabledNode == NULL){ |
| 363 | break; | |
| 364 | } | |
| 13870 | 365 | msnEnabled = xmlnode_get_data(messengerEnabledNode); |
| 366 | if(!strcmp(msnEnabled,"true")){ | |
| 13897 | 367 | /*Messenger enabled, Get the Passport*/ |
| 13870 | 368 | emailNode = xmlnode_get_child(contactEmailNode,"email"); |
| 369 | passport = xmlnode_get_data(emailNode); | |
| 13893 | 370 | gaim_debug_info("MsnAB","Yahoo User %s\n",passport); |
| 13870 | 371 | break; |
| 13897 | 372 | }else{ |
| 373 | /*TODO maybe we can just ignore it in Gaim?*/ | |
| 374 | emailNode = xmlnode_get_child(contactEmailNode,"email"); | |
| 375 | passport = xmlnode_get_data(emailNode); | |
| 376 | gaim_debug_info("MSNAB","Other type user\n"); | |
| 13870 | 377 | } |
| 13893 | 378 | g_free(msnEnabled); |
| 13870 | 379 | } |
| 380 | }else{ | |
| 381 | passport = xmlnode_get_data(passportName); | |
| 13856 | 382 | } |
| 13855 | 383 | |
| 13897 | 384 | if(passport == NULL){ |
| 385 | continue; | |
| 386 | } | |
| 387 | ||
| 13855 | 388 | displayName = xmlnode_get_child(contactInfo,"displayName"); |
| 13893 | 389 | if(displayName == NULL){ |
| 390 | Name = g_strdup(passport); | |
| 391 | }else{ | |
| 13878 | 392 | Name =xmlnode_get_data(displayName); |
| 13893 | 393 | } |
| 13855 | 394 | |
| 13897 | 395 | gaim_debug_misc("MsnAB","passport:{%s} uid:{%s} display:{%s}\n", |
| 396 | passport,uid,Name); | |
| 13855 | 397 | |
| 13870 | 398 | user = msn_userlist_find_add_user(session->userlist, passport,Name); |
| 13855 | 399 | msn_user_set_uid(user,uid); |
| 400 | msn_user_set_type(user,msn_get_user_type(type)); | |
| 13869 | 401 | user->list_op |= MSN_LIST_FL_OP; |
| 13897 | 402 | gaim_debug_info("MsnAB","prepare to free Name...\n"); |
| 13893 | 403 | g_free(Name); |
| 13897 | 404 | gaim_debug_info("MsnAB","prepare to free passport...\n"); |
| 13893 | 405 | g_free(passport); |
| 13897 | 406 | gaim_debug_info("MsnAB","prepare to free uid...\n"); |
| 13893 | 407 | g_free(uid); |
| 13897 | 408 | gaim_debug_info("MsnAB","prepare to free type...\n"); |
| 13893 | 409 | g_free(type); |
| 13855 | 410 | |
| 13897 | 411 | gaim_debug_misc("MsnAB","prepare for guid parse...\n"); |
| 13855 | 412 | groupIds = xmlnode_get_child(contactInfo,"groupIds"); |
| 413 | if(groupIds){ | |
| 414 | for(guid = xmlnode_get_child(groupIds, "guid");guid; | |
| 415 | guid = xmlnode_get_next_twin(guid)){ | |
| 416 | group_id = xmlnode_get_data(guid); | |
| 417 | msn_user_add_group_id(user,group_id); | |
| 13893 | 418 | gaim_debug_misc("MsnAB","guid:%s\n",group_id); |
| 419 | g_free(group_id); | |
| 13855 | 420 | } |
| 421 | }else{ | |
| 13894 | 422 | /*not in any group,Then set default group*/ |
| 13857 | 423 | group_id = g_strdup(MSN_INDIVIDUALS_GROUP_ID); |
| 424 | msn_user_add_group_id(user,group_id); | |
| 425 | g_free(group_id); | |
| 13855 | 426 | } |
| 427 | } | |
| 428 | ||
| 429 | ab =xmlnode_get_child(result,"ab"); | |
| 430 | ||
| 431 | xmlnode_free(node); | |
| 432 | msn_soap_free_read_buf(contact->soapconn); | |
| 13854 | 433 | } |
| 434 | ||
| 13855 | 435 | static void |
| 436 | msn_get_address_cb(gpointer data, gint source, GaimInputCondition cond) | |
| 13854 | 437 | { |
| 13855 | 438 | MsnSoapConn * soapconn = data; |
| 439 | MsnContact *contact; | |
| 440 | MsnSession *session; | |
| 441 | ||
| 442 | contact = soapconn->parent; | |
| 443 | g_return_if_fail(contact != NULL); | |
| 444 | session = soapconn->session; | |
| 445 | g_return_if_fail(session != NULL); | |
| 446 | ||
| 447 | // gaim_debug_misc("msn", "soap contact server Reply: {%s}\n", soapconn->read_buf); | |
| 448 | msn_parse_addressbook(contact); | |
| 13898 | 449 | |
| 450 | msn_notification_dump_contact(session); | |
| 451 | msn_set_psm(session); | |
| 452 | msn_session_finish_login(session); | |
| 453 | ||
| 13886 | 454 | /*free the read buffer*/ |
| 455 | msn_soap_free_read_buf(soapconn); | |
| 13855 | 456 | } |
| 457 | ||
| 458 | /**/ | |
| 459 | static void | |
| 460 | msn_address_written_cb(gpointer data, gint source, GaimInputCondition cond) | |
| 461 | { | |
| 462 | MsnSoapConn * soapconn = data; | |
| 463 | ||
| 464 | gaim_debug_info("MaYuan","finish contact written\n"); | |
| 465 | soapconn->read_cb = msn_get_address_cb; | |
| 13854 | 466 | } |
| 467 | ||
| 13855 | 468 | /*get the address book*/ |
| 469 | void | |
| 470 | msn_get_address_book(MsnContact *contact) | |
| 13854 | 471 | { |
| 13874 | 472 | MsnSoapReq *soap_request; |
| 473 | ||
| 13855 | 474 | gaim_debug_info("MaYuan","msn_get_address_book()...\n"); |
| 475 | /*build SOAP and POST it*/ | |
| 13874 | 476 | soap_request = msn_soap_request_new(MSN_CONTACT_SERVER, |
| 477 | MSN_ADDRESS_BOOK_POST_URL,MSN_GET_ADDRESS_SOAP_ACTION, | |
| 478 | MSN_GET_ADDRESS_TEMPLATE, | |
| 479 | msn_get_address_cb, | |
| 480 | msn_address_written_cb); | |
| 13876 | 481 | msn_soap_post(contact->soapconn,soap_request,msn_contact_connect_init); |
| 13855 | 482 | } |
| 483 | ||
| 13866 | 484 | static void |
| 485 | msn_add_contact_read_cb(gpointer data, gint source, GaimInputCondition cond) | |
| 486 | { | |
| 13897 | 487 | gaim_debug_info("MaYuan","add contact read done\n"); |
| 13866 | 488 | } |
| 489 | ||
| 490 | static void | |
| 491 | msn_add_contact_written_cb(gpointer data, gint source, GaimInputCondition cond) | |
| 492 | { | |
| 493 | MsnSoapConn * soapconn = data; | |
| 494 | ||
| 13897 | 495 | gaim_debug_info("MaYuan","finish add contact written\n"); |
| 13866 | 496 | soapconn->read_cb = msn_add_contact_read_cb; |
| 13880 | 497 | // msn_soap_read_cb(data,source,cond); |
| 13866 | 498 | } |
| 499 | ||
| 13859 | 500 | /*add a Contact */ |
| 13855 | 501 | void |
| 13897 | 502 | msn_add_contact(MsnContact *contact,const char *passport,const char *groupId) |
| 13855 | 503 | { |
| 13874 | 504 | MsnSoapReq *soap_request; |
| 13864 | 505 | char *body = NULL; |
| 506 | char *contact_xml = NULL; | |
| 13874 | 507 | char *soap_action; |
| 13864 | 508 | |
| 13860 | 509 | gaim_debug_info("MaYuan","msn add a contact...\n"); |
| 13864 | 510 | contact_xml = g_strdup_printf(MSN_CONTACT_XML,passport); |
| 13866 | 511 | if(groupId == NULL){ |
| 512 | body = g_strdup_printf(MSN_ADD_CONTACT_TEMPLATE,contact_xml); | |
| 513 | g_free(contact_xml); | |
| 514 | /*build SOAP and POST it*/ | |
| 13874 | 515 | soap_action = g_strdup(MSN_CONTACT_ADD_SOAP_ACTION); |
| 13866 | 516 | }else{ |
| 517 | body = g_strdup_printf(MSN_ADD_CONTACT_GROUP_TEMPLATE,groupId,contact_xml); | |
| 518 | g_free(contact_xml); | |
| 519 | /*build SOAP and POST it*/ | |
| 13874 | 520 | soap_action = g_strdup(MSN_ADD_CONTACT_GROUP_SOAP_ACTION); |
| 13866 | 521 | } |
| 13874 | 522 | soap_request = msn_soap_request_new(MSN_CONTACT_SERVER, |
| 523 | MSN_ADDRESS_BOOK_POST_URL,soap_action, | |
| 524 | body, | |
| 525 | msn_add_contact_read_cb, | |
| 526 | msn_add_contact_written_cb); | |
| 13876 | 527 | msn_soap_post(contact->soapconn,soap_request,msn_contact_connect_init); |
| 13863 | 528 | |
| 13874 | 529 | g_free(soap_action); |
| 13864 | 530 | g_free(body); |
| 13854 | 531 | } |
| 532 | ||
| 13866 | 533 | static void |
| 534 | msn_delete_contact_read_cb(gpointer data, gint source, GaimInputCondition cond) | |
| 535 | { | |
| 536 | gaim_debug_info("MaYuan","delete contact read done\n"); | |
| 537 | } | |
| 538 | ||
| 539 | static void | |
| 540 | msn_delete_contact_written_cb(gpointer data, gint source, GaimInputCondition cond) | |
| 541 | { | |
| 542 | MsnSoapConn * soapconn = data; | |
| 543 | ||
| 544 | gaim_debug_info("MaYuan","delete contact written\n"); | |
| 545 | soapconn->read_cb = msn_delete_contact_read_cb; | |
| 13880 | 546 | // msn_soap_read_cb(data,source,cond); |
| 13866 | 547 | } |
| 548 | ||
| 13859 | 549 | /*delete a Contact*/ |
| 13855 | 550 | void |
| 13866 | 551 | msn_delete_contact(MsnContact *contact,const char *contactId) |
| 13855 | 552 | { |
| 13864 | 553 | char *body = NULL; |
| 554 | char *contact_xml = NULL ; | |
| 13874 | 555 | MsnSoapReq *soap_request; |
| 13864 | 556 | |
| 13901 | 557 | g_return_if_fail(contactId != NULL); |
| 13866 | 558 | gaim_debug_info("MaYuan","msn delete a contact,contactId:{%s}...\n",contactId); |
| 559 | contact_xml = g_strdup_printf(MSN_CONTACTS_DEL_XML,contactId); | |
| 13864 | 560 | body = g_strdup_printf(MSN_DEL_CONTACT_TEMPLATE,contact_xml); |
| 561 | g_free(contact_xml); | |
| 13863 | 562 | /*build SOAP and POST it*/ |
| 13874 | 563 | soap_request = msn_soap_request_new(MSN_CONTACT_SERVER, |
| 564 | MSN_ADDRESS_BOOK_POST_URL,MSN_CONTACT_DEL_SOAP_ACTION, | |
| 565 | body, | |
| 566 | msn_delete_contact_read_cb, | |
| 567 | msn_delete_contact_written_cb); | |
| 13876 | 568 | msn_soap_post(contact->soapconn,soap_request,msn_contact_connect_init); |
| 13874 | 569 | |
| 13864 | 570 | g_free(body); |
| 13855 | 571 | } |
| 572 | ||
| 13866 | 573 | static void |
| 574 | msn_block_read_cb(gpointer data, gint source, GaimInputCondition cond) | |
| 575 | { | |
| 576 | gaim_debug_info("MaYuan","block read done\n"); | |
| 577 | } | |
| 578 | ||
| 579 | static void | |
| 580 | msn_block_written_cb(gpointer data, gint source, GaimInputCondition cond) | |
| 581 | { | |
| 582 | MsnSoapConn * soapconn = data; | |
| 583 | ||
| 584 | gaim_debug_info("MaYuan","finish unblock written\n"); | |
| 585 | soapconn->read_cb = msn_block_read_cb; | |
| 586 | } | |
| 587 | ||
| 13859 | 588 | /*block a Contact*/ |
| 13855 | 589 | void |
| 13864 | 590 | msn_block_contact(MsnContact *contact,const char* membership_id) |
| 591 | { | |
| 13874 | 592 | MsnSoapReq *soap_request; |
| 13864 | 593 | char *body = NULL; |
| 594 | ||
| 13860 | 595 | gaim_debug_info("MaYuan","msn block a contact...\n"); |
| 13864 | 596 | body = g_strdup_printf(MSN_CONTACT_DELECT_FROM_ALLOW_TEMPLATE,membership_id); |
| 13863 | 597 | /*build SOAP and POST it*/ |
| 13874 | 598 | soap_request = msn_soap_request_new(MSN_CONTACT_SERVER, |
| 599 | MSN_SHARE_POST_URL,MSN_CONTACT_BLOCK_SOAP_ACTION, | |
| 600 | body, | |
| 601 | msn_block_read_cb, | |
| 602 | msn_block_written_cb); | |
| 13876 | 603 | msn_soap_post(contact->soapconn,soap_request,msn_contact_connect_init); |
| 13874 | 604 | |
| 13864 | 605 | g_free(body); |
| 13855 | 606 | } |
| 607 | ||
| 13866 | 608 | static void |
| 609 | msn_unblock_read_cb(gpointer data, gint source, GaimInputCondition cond) | |
| 610 | { | |
| 611 | gaim_debug_info("MaYuan","unblock read done\n"); | |
| 612 | } | |
| 613 | ||
| 614 | static void | |
| 615 | msn_unblock_written_cb(gpointer data, gint source, GaimInputCondition cond) | |
| 616 | { | |
| 617 | MsnSoapConn * soapconn = data; | |
| 618 | ||
| 619 | gaim_debug_info("MaYuan","finish unblock written\n"); | |
| 620 | soapconn->read_cb = msn_unblock_read_cb; | |
| 621 | } | |
| 622 | ||
| 13859 | 623 | /*unblock a contact*/ |
| 13855 | 624 | void |
| 13864 | 625 | msn_unblock_contact(MsnContact *contact,const char* passport) |
| 626 | { | |
| 13874 | 627 | MsnSoapReq *soap_request; |
| 13864 | 628 | char *body = NULL; |
| 629 | ||
| 13860 | 630 | gaim_debug_info("MaYuan","msn unblock a contact...\n"); |
| 13864 | 631 | |
| 632 | body = g_strdup_printf(MSN_UNBLOCK_CONTACT_TEMPLATE,passport); | |
| 13863 | 633 | /*build SOAP and POST it*/ |
| 13874 | 634 | soap_request = msn_soap_request_new(MSN_CONTACT_SERVER, |
| 635 | MSN_SHARE_POST_URL,MSN_CONTACT_UNBLOCK_SOAP_ACTION, | |
| 636 | body, | |
| 637 | msn_unblock_read_cb, | |
| 638 | msn_unblock_written_cb); | |
| 13876 | 639 | msn_soap_post(contact->soapconn,soap_request,msn_contact_connect_init); |
| 13874 | 640 | |
| 13864 | 641 | g_free(body); |
| 13855 | 642 | } |
| 643 | ||
| 13866 | 644 | static void |
| 645 | msn_gleams_read_cb(gpointer data, gint source, GaimInputCondition cond) | |
| 646 | { | |
| 647 | gaim_debug_info("MaYuan","Gleams read done\n"); | |
| 648 | } | |
| 649 | ||
| 650 | static void | |
| 651 | msn_gleams_written_cb(gpointer data, gint source, GaimInputCondition cond) | |
| 652 | { | |
| 653 | MsnSoapConn * soapconn = data; | |
| 654 | ||
| 655 | gaim_debug_info("MaYuan","finish Group written\n"); | |
| 656 | soapconn->read_cb = msn_gleams_read_cb; | |
| 13880 | 657 | // msn_soap_read_cb(data,source,cond); |
| 13866 | 658 | } |
| 659 | ||
| 13859 | 660 | /*get the gleams info*/ |
| 13855 | 661 | void |
| 662 | msn_get_gleams(MsnContact *contact) | |
| 13854 | 663 | { |
| 13874 | 664 | MsnSoapReq *soap_request; |
| 665 | ||
| 13860 | 666 | gaim_debug_info("MaYuan","msn get gleams info...\n"); |
| 667 | /*build SOAP and POST it*/ | |
| 13874 | 668 | soap_request = msn_soap_request_new(MSN_CONTACT_SERVER, |
| 669 | MSN_ADDRESS_BOOK_POST_URL,MSN_GET_GLEAMS_SOAP_ACTION, | |
| 670 | MSN_GLEAMS_TEMPLATE, | |
| 671 | msn_gleams_read_cb, | |
| 672 | msn_gleams_written_cb); | |
| 13876 | 673 | msn_soap_post(contact->soapconn,soap_request,msn_contact_connect_init); |
| 13854 | 674 | } |
| 675 | ||
| 13865 | 676 | /*************************************************************** |
| 677 | * Group Operation | |
| 678 | ***************************************************************/ | |
| 679 | static void | |
| 680 | msn_group_read_cb(gpointer data, gint source, GaimInputCondition cond) | |
| 681 | { | |
| 682 | gaim_debug_info("MaYuan","Group read \n"); | |
| 683 | } | |
| 684 | ||
| 685 | static void | |
| 686 | msn_group_written_cb(gpointer data, gint source, GaimInputCondition cond) | |
| 687 | { | |
| 688 | MsnSoapConn * soapconn = data; | |
| 689 | ||
| 690 | gaim_debug_info("MaYuan","finish Group written\n"); | |
| 691 | soapconn->read_cb = msn_group_read_cb; | |
| 13880 | 692 | // msn_soap_read_cb(data,source,cond); |
| 13865 | 693 | } |
| 694 | ||
| 13864 | 695 | /*add group*/ |
| 13865 | 696 | void msn_add_group(MsnSession *session,const char* group_name) |
| 13863 | 697 | { |
| 13874 | 698 | MsnSoapReq *soap_request; |
| 699 | MsnContact *contact ; | |
| 13865 | 700 | char *body = NULL; |
| 701 | ||
| 702 | g_return_if_fail(session != NULL); | |
| 703 | contact = session->contact; | |
| 13863 | 704 | gaim_debug_info("MaYuan","msn add group...\n"); |
| 705 | ||
| 13865 | 706 | body = g_strdup_printf(MSN_GROUP_ADD_TEMPLATE,group_name); |
| 13863 | 707 | /*build SOAP and POST it*/ |
| 13874 | 708 | soap_request = msn_soap_request_new(MSN_CONTACT_SERVER, |
| 709 | MSN_ADDRESS_BOOK_POST_URL,MSN_GROUP_ADD_SOAP_ACTION, | |
| 710 | body, | |
| 711 | msn_group_read_cb, | |
| 712 | msn_group_written_cb); | |
| 13876 | 713 | msn_soap_post(contact->soapconn,soap_request,msn_contact_connect_init); |
| 13863 | 714 | } |
| 715 | ||
| 13864 | 716 | /*delete a group*/ |
| 13865 | 717 | void msn_del_group(MsnSession *session,const char *guid) |
| 13863 | 718 | { |
| 13874 | 719 | MsnSoapReq *soap_request; |
| 13865 | 720 | MsnContact *contact; |
| 721 | char *body = NULL; | |
| 722 | ||
| 723 | g_return_if_fail(session != NULL); | |
| 13897 | 724 | /*if group uid we need to del is NULL, |
| 725 | * we need to delete nothing | |
| 726 | */ | |
| 727 | g_return_if_fail(guid != NULL); | |
| 13865 | 728 | contact = session->contact; |
| 13863 | 729 | gaim_debug_info("MaYuan","msn del group...\n"); |
| 730 | ||
| 13865 | 731 | body = g_strdup_printf(MSN_GROUP_DEL_TEMPLATE,guid); |
| 13863 | 732 | /*build SOAP and POST it*/ |
| 13874 | 733 | soap_request = msn_soap_request_new(MSN_CONTACT_SERVER, |
| 734 | MSN_ADDRESS_BOOK_POST_URL,MSN_GROUP_DEL_SOAP_ACTION, | |
| 735 | body, | |
| 736 | msn_group_read_cb, | |
| 737 | msn_group_written_cb); | |
| 13876 | 738 | msn_soap_post(contact->soapconn,soap_request,msn_contact_connect_init); |
| 13874 | 739 | |
| 13865 | 740 | g_free(body); |
| 13863 | 741 | } |
| 742 | ||
| 13854 | 743 | void |
| 13876 | 744 | msn_contact_connect_init(MsnSoapConn *soapconn) |
| 13854 | 745 | { |
| 746 | /* Authenticate via Windows Live ID. */ | |
| 747 | gaim_debug_info("MaYuan","msn_contact_connect...\n"); | |
| 748 | ||
| 13876 | 749 | msn_soap_init(soapconn,MSN_CONTACT_SERVER,1, |
| 13854 | 750 | msn_contact_login_connect_cb, |
| 751 | msn_contact_login_error_cb); | |
| 752 | } | |
| 753 |