Mercurial > pidgin
comparison src/protocols/msn/contact.c @ 19840:5568b3ac6fce
[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>
author | Ma Yuan <mayuan2006@gmail.com> |
---|---|
date | Sat, 14 Oct 2006 20:00:56 +0000 |
parents | 2b36697b05ea |
children |
comparison
equal
deleted
inserted
replaced
19839:2b36697b05ea | 19840:5568b3ac6fce |
---|---|
83 | 83 |
84 session = contact->session; | 84 session = contact->session; |
85 g_return_if_fail(session != NULL); | 85 g_return_if_fail(session != NULL); |
86 | 86 |
87 /*login ok!We can retrieve the contact list*/ | 87 /*login ok!We can retrieve the contact list*/ |
88 // msn_get_contact_list(contact); | 88 // msn_get_contact_list(contact,NULL); |
89 } | 89 } |
90 | 90 |
91 /*get MSN member role utility*/ | 91 /*get MSN member role utility*/ |
92 static int | 92 static int |
93 msn_get_memberrole(char * role) | 93 msn_get_memberrole(char * role) |
124 msn_parse_contact_list(MsnContact * contact) | 124 msn_parse_contact_list(MsnContact * contact) |
125 { | 125 { |
126 MsnSession * session; | 126 MsnSession * session; |
127 int list_op =0; | 127 int list_op =0; |
128 char * passport; | 128 char * passport; |
129 xmlnode * node,*body,*response,*result,*services,*service,*memberships; | 129 xmlnode * node,*body,*response,*result,*services; |
130 xmlnode *service,*memberships; | |
130 xmlnode *LastChangeNode; | 131 xmlnode *LastChangeNode; |
131 xmlnode *membershipnode,*members,*member,*passportNode; | 132 xmlnode *membershipnode,*members,*member,*passportNode; |
132 char *lastchange; | 133 char *LastChangeStr; |
133 | 134 |
134 session = contact->session; | 135 session = contact->session; |
135 gaim_debug_misc("xml","parse contact list:{%s}\nsize:%d\n",contact->soapconn->body,contact->soapconn->body_len); | 136 gaim_debug_misc("MSNCL","parse contact list:{%s}\nsize:%d\n",contact->soapconn->body,contact->soapconn->body_len); |
136 node = xmlnode_from_str(contact->soapconn->body, contact->soapconn->body_len); | 137 node = xmlnode_from_str(contact->soapconn->body, contact->soapconn->body_len); |
137 | 138 |
138 if(node == NULL){ | 139 if(node == NULL){ |
139 gaim_debug_misc("xml","parse contact from str err!\n"); | 140 gaim_debug_misc("MSNCL","parse contact from str err!\n"); |
140 return; | 141 return; |
141 } | 142 } |
142 gaim_debug_misc("xml","node{%p},name:%s,child:%s,last:%s\n",node,node->name,node->child->name,node->lastchild->name); | 143 gaim_debug_misc("MSNCL","node{%p},name:%s,child:%s,last:%s\n",node,node->name,node->child->name,node->lastchild->name); |
143 body = xmlnode_get_child(node,"Body"); | 144 body = xmlnode_get_child(node,"Body"); |
144 gaim_debug_misc("xml","body{%p},name:%s\n",body,body->name); | 145 gaim_debug_misc("MSNCL","body{%p},name:%s\n",body,body->name); |
145 response = xmlnode_get_child(body,"FindMembershipResponse"); | 146 response = xmlnode_get_child(body,"FindMembershipResponse"); |
146 gaim_debug_misc("xml","response{%p},name:%s\n",response,response->name); | 147 gaim_debug_misc("MSNCL","response{%p},name:%s\n",response,response->name); |
147 result =xmlnode_get_child(response,"FindMembershipResult"); | 148 result =xmlnode_get_child(response,"FindMembershipResult"); |
148 gaim_debug_misc("xml","result{%p},name:%s\n",result,result->name); | 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); | |
149 services =xmlnode_get_child(result,"Services"); | 154 services =xmlnode_get_child(result,"Services"); |
150 gaim_debug_misc("xml","services{%p},name:%s\n",services,services->name); | 155 gaim_debug_misc("MSNCL","services{%p},name:%s\n",services,services->name); |
151 service =xmlnode_get_child(services,"Service"); | 156 service =xmlnode_get_child(services,"Service"); |
152 gaim_debug_misc("xml","service{%p},name:%s\n",service,service->name); | 157 gaim_debug_misc("MSNCL","service{%p},name:%s\n",service,service->name); |
153 | 158 |
154 /*Last Change Node*/ | 159 /*Last Change Node*/ |
155 LastChangeNode = xmlnode_get_child(service,"LastChange"); | 160 LastChangeNode = xmlnode_get_child(service,"LastChange"); |
156 lastchange = xmlnode_get_data(LastChangeNode); | 161 LastChangeStr = xmlnode_get_data(LastChangeNode); |
157 gaim_debug_misc("MSNContact","LastChangeNode %s\n",lastchange); | 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); | |
158 | 165 |
159 memberships =xmlnode_get_child(service,"Memberships"); | 166 memberships =xmlnode_get_child(service,"Memberships"); |
160 gaim_debug_misc("xml","memberships{%p},name:%s\n",memberships,memberships->name); | 167 gaim_debug_misc("MSNCL","memberships{%p},name:%s\n",memberships,memberships->name); |
161 for(membershipnode = xmlnode_get_child(memberships, "Membership"); membershipnode; | 168 for(membershipnode = xmlnode_get_child(memberships, "Membership"); membershipnode; |
162 membershipnode = xmlnode_get_next_twin(membershipnode)){ | 169 membershipnode = xmlnode_get_next_twin(membershipnode)){ |
163 xmlnode *roleNode; | 170 xmlnode *roleNode; |
164 char *role; | 171 char *role; |
165 roleNode = xmlnode_get_child(membershipnode,"MemberRole"); | 172 roleNode = xmlnode_get_child(membershipnode,"MemberRole"); |
166 role=xmlnode_get_data(roleNode); | 173 role=xmlnode_get_data(roleNode); |
167 list_op = msn_get_memberrole(role); | 174 list_op = msn_get_memberrole(role); |
168 gaim_debug_misc("memberrole","role:%s,list_op:%d\n",role,list_op); | 175 gaim_debug_misc("MSNCL","MemberRole role:%s,list_op:%d\n",role,list_op); |
169 g_free(role); | 176 g_free(role); |
170 members = xmlnode_get_child(membershipnode,"Members"); | 177 members = xmlnode_get_child(membershipnode,"Members"); |
171 for(member = xmlnode_get_child(members, "Member"); member; | 178 for(member = xmlnode_get_child(members, "Member"); member; |
172 member = xmlnode_get_next_twin(member)){ | 179 member = xmlnode_get_next_twin(member)){ |
173 MsnUser *user; | 180 MsnUser *user; |
174 xmlnode * typeNode; | 181 xmlnode * typeNode; |
175 char * type; | 182 char * type; |
176 | 183 |
177 gaim_debug_misc("MaYuan","type:%s\n",xmlnode_get_attrib(member,"type")); | 184 gaim_debug_misc("MSNCL","type:%s\n",xmlnode_get_attrib(member,"type")); |
178 if(!g_strcasecmp(xmlnode_get_attrib(member,"type"),"PassportMember")){ | 185 if(!g_strcasecmp(xmlnode_get_attrib(member,"type"),"PassportMember")){ |
179 passportNode = xmlnode_get_child(member,"PassportName"); | 186 passportNode = xmlnode_get_child(member,"PassportName"); |
180 passport = xmlnode_get_data(passportNode); | 187 passport = xmlnode_get_data(passportNode); |
181 typeNode = xmlnode_get_child(member,"Type"); | 188 typeNode = xmlnode_get_child(member,"Type"); |
182 type = xmlnode_get_data(typeNode); | 189 type = xmlnode_get_data(typeNode); |
183 gaim_debug_misc("Passport","name:%s,type:%s\n",passport,type); | 190 gaim_debug_misc("MSNCL","Passport name:%s,type:%s\n",passport,type); |
184 g_free(type); | 191 g_free(type); |
185 | 192 |
186 user = msn_userlist_find_add_user(session->userlist,passport,NULL); | 193 user = msn_userlist_find_add_user(session->userlist,passport,NULL); |
187 msn_got_lst_user(session, user, list_op, NULL); | 194 msn_got_lst_user(session, user, list_op, NULL); |
188 g_free(passport); | 195 g_free(passport); |
192 if(!g_strcasecmp(xmlnode_get_attrib(member,"type"),"EmailMember")){ | 199 if(!g_strcasecmp(xmlnode_get_attrib(member,"type"),"EmailMember")){ |
193 xmlnode *emailNode; | 200 xmlnode *emailNode; |
194 | 201 |
195 emailNode = xmlnode_get_child(member,"Email"); | 202 emailNode = xmlnode_get_child(member,"Email"); |
196 passport = xmlnode_get_data(emailNode); | 203 passport = xmlnode_get_data(emailNode); |
197 gaim_debug_info("Email","name:%s,list_op:%d\n",passport,list_op); | 204 gaim_debug_info("MSNCL","Email Member :name:%s,list_op:%d\n",passport,list_op); |
198 user = msn_userlist_find_add_user(session->userlist,passport,NULL); | 205 user = msn_userlist_find_add_user(session->userlist,passport,NULL); |
199 msn_got_lst_user(session,user,list_op,NULL); | 206 msn_got_lst_user(session,user,list_op,NULL); |
200 g_free(passport); | 207 g_free(passport); |
201 } | 208 } |
202 } | 209 } |
209 msn_get_contact_list_cb(gpointer data, gint source, GaimInputCondition cond) | 216 msn_get_contact_list_cb(gpointer data, gint source, GaimInputCondition cond) |
210 { | 217 { |
211 MsnSoapConn * soapconn = data; | 218 MsnSoapConn * soapconn = data; |
212 MsnContact *contact; | 219 MsnContact *contact; |
213 MsnSession *session; | 220 MsnSession *session; |
221 const char * abLastChange; | |
222 const char * dynamicItemLastChange; | |
214 | 223 |
215 contact = soapconn->parent; | 224 contact = soapconn->parent; |
216 g_return_if_fail(contact != NULL); | 225 g_return_if_fail(contact != NULL); |
217 session = soapconn->session; | 226 session = soapconn->session; |
218 g_return_if_fail(session != NULL); | 227 g_return_if_fail(session != NULL); |
222 #endif | 231 #endif |
223 msn_parse_contact_list(contact); | 232 msn_parse_contact_list(contact); |
224 /*free the read buffer*/ | 233 /*free the read buffer*/ |
225 msn_soap_free_read_buf(soapconn); | 234 msn_soap_free_read_buf(soapconn); |
226 | 235 |
227 msn_get_address_book(contact); | 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); | |
228 } | 239 } |
229 | 240 |
230 static void | 241 static void |
231 msn_get_contact_written_cb(gpointer data, gint source, GaimInputCondition cond) | 242 msn_get_contact_written_cb(gpointer data, gint source, GaimInputCondition cond) |
232 { | 243 { |
235 gaim_debug_info("MaYuan","finish contact written\n"); | 246 gaim_debug_info("MaYuan","finish contact written\n"); |
236 soapconn->read_cb = msn_get_contact_list_cb; | 247 soapconn->read_cb = msn_get_contact_list_cb; |
237 // msn_soap_read_cb(data,source,cond); | 248 // msn_soap_read_cb(data,source,cond); |
238 } | 249 } |
239 | 250 |
240 void | 251 /*SOAP get contact list*/ |
241 msn_get_contact_list(MsnContact * contact) | 252 void |
242 { | 253 msn_get_contact_list(MsnContact * contact,char * update_time) |
243 MsnSoapReq *soap_request; | 254 { |
244 | 255 MsnSoapReq *soap_request; |
256 char *body = NULL; | |
257 char * update_str; | |
258 | |
245 gaim_debug_info("MaYuan","Getting Contact List...\n"); | 259 gaim_debug_info("MaYuan","Getting Contact List...\n"); |
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); | |
246 soap_request = msn_soap_request_new(MSN_CONTACT_SERVER, | 267 soap_request = msn_soap_request_new(MSN_CONTACT_SERVER, |
247 MSN_GET_CONTACT_POST_URL,MSN_GET_CONTACT_SOAP_ACTION, | 268 MSN_GET_CONTACT_POST_URL,MSN_GET_CONTACT_SOAP_ACTION, |
248 MSN_GET_CONTACT_TEMPLATE, | 269 body, |
249 msn_get_contact_list_cb, | 270 msn_get_contact_list_cb, |
250 msn_get_contact_written_cb); | 271 msn_get_contact_written_cb); |
251 msn_soap_post(contact->soapconn,soap_request,msn_contact_connect_init); | 272 msn_soap_post(contact->soapconn,soap_request,msn_contact_connect_init); |
273 g_free(update_str); | |
274 g_free(body); | |
252 } | 275 } |
253 | 276 |
254 static void | 277 static void |
255 msn_parse_addressbook(MsnContact * contact) | 278 msn_parse_addressbook(MsnContact * contact) |
256 { | 279 { |
257 MsnSession * session; | 280 MsnSession * session; |
258 xmlnode * node,*body,*response,*result; | 281 xmlnode * node,*body,*response,*result; |
259 xmlnode *groups,*group,*groupname,*groupId,*groupInfo; | 282 xmlnode *groups,*group,*groupname,*groupId,*groupInfo; |
260 xmlnode *contacts,*contactNode,*contactId,*contactInfo,*contactType,*passportName,*displayName,*groupIds,*guid; | 283 xmlnode *contacts,*contactNode,*contactId,*contactInfo,*contactType,*passportName,*displayName,*groupIds,*guid; |
261 xmlnode *abNode,*LastChangeNode; | 284 xmlnode *abNode; |
262 char *lastchange; | |
263 char *group_name,*group_id; | 285 char *group_name,*group_id; |
264 | 286 |
265 session = contact->session; | 287 session = contact->session; |
266 gaim_debug_misc("xml","parse addressbook:{%s}\nsize:%d\n",contact->soapconn->body,contact->soapconn->body_len); | 288 gaim_debug_misc("xml","parse addressbook:{%s}\nsize:%d\n",contact->soapconn->body,contact->soapconn->body_len); |
267 node = xmlnode_from_str(contact->soapconn->body, contact->soapconn->body_len); | 289 node = xmlnode_from_str(contact->soapconn->body, contact->soapconn->body_len); |
274 body = xmlnode_get_child(node,"Body"); | 296 body = xmlnode_get_child(node,"Body"); |
275 gaim_debug_misc("xml","body{%p},name:%s\n",body,body->name); | 297 gaim_debug_misc("xml","body{%p},name:%s\n",body,body->name); |
276 response = xmlnode_get_child(body,"ABFindAllResponse"); | 298 response = xmlnode_get_child(body,"ABFindAllResponse"); |
277 gaim_debug_misc("xml","response{%p},name:%s\n",response,response->name); | 299 gaim_debug_misc("xml","response{%p},name:%s\n",response,response->name); |
278 result =xmlnode_get_child(response,"ABFindAllResult"); | 300 result =xmlnode_get_child(response,"ABFindAllResult"); |
301 if(result == NULL){ | |
302 gaim_debug_misc("MSNAB","receive no address book update\n"); | |
303 return; | |
304 } | |
279 gaim_debug_misc("xml","result{%p},name:%s\n",result,result->name); | 305 gaim_debug_misc("xml","result{%p},name:%s\n",result,result->name); |
280 | 306 |
281 /*Process Group List*/ | 307 /*Process Group List*/ |
282 groups =xmlnode_get_child(result,"groups"); | 308 groups =xmlnode_get_child(result,"groups"); |
283 for(group = xmlnode_get_child(groups, "Group"); group; | 309 for(group = xmlnode_get_child(groups, "Group"); group; |
296 } | 322 } |
297 | 323 |
298 gaim_debug_misc("MsnAB","group_id:%s name:%s\n",group_id,group_name); | 324 gaim_debug_misc("MsnAB","group_id:%s name:%s\n",group_id,group_name); |
299 if ((gaim_find_group(group_name)) == NULL){ | 325 if ((gaim_find_group(group_name)) == NULL){ |
300 GaimGroup *g = gaim_group_new(group_name); | 326 GaimGroup *g = gaim_group_new(group_name); |
327 gaim_blist_node_set_string(&(g->node),"groupId",group_id); | |
301 gaim_blist_add_group(g, NULL); | 328 gaim_blist_add_group(g, NULL); |
302 } | 329 } |
303 g_free(group_id); | 330 g_free(group_id); |
304 g_free(group_name); | 331 g_free(group_name); |
305 } | 332 } |
435 } | 462 } |
436 } | 463 } |
437 | 464 |
438 abNode =xmlnode_get_child(result,"ab"); | 465 abNode =xmlnode_get_child(result,"ab"); |
439 if(abNode != NULL){ | 466 if(abNode != NULL){ |
467 xmlnode *LastChangeNode, *DynamicItemLastChangedNode; | |
468 char *lastchange, *dynamicChange; | |
469 | |
440 LastChangeNode = xmlnode_get_child(abNode,"lastChange"); | 470 LastChangeNode = xmlnode_get_child(abNode,"lastChange"); |
441 lastchange = xmlnode_get_data(LastChangeNode); | 471 lastchange = xmlnode_get_data(LastChangeNode); |
442 gaim_debug_info("MsnAB"," lastchanged Time:{%s}\n",lastchange); | 472 gaim_debug_info("MsnAB"," lastchanged Time:{%s}\n",lastchange); |
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); | |
443 } | 479 } |
444 | 480 |
445 xmlnode_free(node); | 481 xmlnode_free(node); |
446 msn_soap_free_read_buf(contact->soapconn); | 482 msn_soap_free_read_buf(contact->soapconn); |
447 } | 483 } |
479 soapconn->read_cb = msn_get_address_cb; | 515 soapconn->read_cb = msn_get_address_cb; |
480 } | 516 } |
481 | 517 |
482 /*get the address book*/ | 518 /*get the address book*/ |
483 void | 519 void |
484 msn_get_address_book(MsnContact *contact) | 520 msn_get_address_book(MsnContact *contact,char * LastChanged, char * dynamicItemLastChange) |
485 { | 521 { |
486 MsnSoapReq *soap_request; | 522 MsnSoapReq *soap_request; |
523 char *body = NULL; | |
524 char *ab_update_str,*update_str; | |
487 | 525 |
488 gaim_debug_info("MaYuan","msn_get_address_book()...\n"); | 526 gaim_debug_info("MaYuan","msn_get_address_book()...\n"); |
489 /*build SOAP and POST it*/ | 527 /*build SOAP and POST it*/ |
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); | |
490 soap_request = msn_soap_request_new(MSN_CONTACT_SERVER, | 542 soap_request = msn_soap_request_new(MSN_CONTACT_SERVER, |
491 MSN_ADDRESS_BOOK_POST_URL,MSN_GET_ADDRESS_SOAP_ACTION, | 543 MSN_ADDRESS_BOOK_POST_URL,MSN_GET_ADDRESS_SOAP_ACTION, |
492 MSN_GET_ADDRESS_TEMPLATE, | 544 body, |
493 msn_get_address_cb, | 545 msn_get_address_cb, |
494 msn_address_written_cb); | 546 msn_address_written_cb); |
495 msn_soap_post(contact->soapconn,soap_request,msn_contact_connect_init); | 547 msn_soap_post(contact->soapconn,soap_request,msn_contact_connect_init); |
548 g_free(update_str); | |
549 g_free(body); | |
496 } | 550 } |
497 | 551 |
498 static void | 552 static void |
499 msn_add_contact_read_cb(gpointer data, gint source, GaimInputCondition cond) | 553 msn_add_contact_read_cb(gpointer data, gint source, GaimInputCondition cond) |
500 { | 554 { |