comparison libpurple/protocols/msn/contact.c @ 20394:4a099e4d0d09

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