19784
|
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"
|
19787
|
31 #include "group.h"
|
19784
|
32
|
19826
|
33 /*define This to debug the Contact Server*/
|
|
34 #undef MSN_CONTACT_SOAP_DEBUG
|
|
35
|
19806
|
36 void msn_contact_connect_init(MsnSoapConn *soapconn);
|
|
37
|
19784
|
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;
|
19785
|
46 contact->soapconn = msn_soap_new(session,contact,1);
|
19784
|
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*/
|
19840
|
88 // msn_get_contact_list(contact,NULL);
|
19784
|
89 }
|
|
90
|
19785
|
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;
|
19799
|
99 }else if(!strcmp(role,"Reverse")){
|
|
100 return MSN_LIST_RL_OP;
|
19785
|
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 }
|
19825
|
112 if(!strcmp(type,"Live")){
|
|
113 return 1;
|
|
114 }
|
|
115 if(!strcmp(type,"LivePending")){
|
|
116 return 1;
|
|
117 }
|
|
118
|
19785
|
119 return 0;
|
|
120 }
|
|
121
|
|
122 /*parse contact list*/
|
19784
|
123 static void
|
|
124 msn_parse_contact_list(MsnContact * contact)
|
|
125 {
|
19785
|
126 MsnSession * session;
|
|
127 int list_op =0;
|
|
128 char * passport;
|
19840
|
129 xmlnode * node,*body,*response,*result,*services;
|
|
130 xmlnode *service,*memberships;
|
19834
|
131 xmlnode *LastChangeNode;
|
19823
|
132 xmlnode *membershipnode,*members,*member,*passportNode;
|
19840
|
133 char *LastChangeStr;
|
19784
|
134
|
19785
|
135 session = contact->session;
|
19840
|
136 gaim_debug_misc("MSNCL","parse contact list:{%s}\nsize:%d\n",contact->soapconn->body,contact->soapconn->body_len);
|
19784
|
137 node = xmlnode_from_str(contact->soapconn->body, contact->soapconn->body_len);
|
|
138
|
|
139 if(node == NULL){
|
19840
|
140 gaim_debug_misc("MSNCL","parse contact from str err!\n");
|
19784
|
141 return;
|
|
142 }
|
19840
|
143 gaim_debug_misc("MSNCL","node{%p},name:%s,child:%s,last:%s\n",node,node->name,node->child->name,node->lastchild->name);
|
19784
|
144 body = xmlnode_get_child(node,"Body");
|
19840
|
145 gaim_debug_misc("MSNCL","body{%p},name:%s\n",body,body->name);
|
19784
|
146 response = xmlnode_get_child(body,"FindMembershipResponse");
|
19840
|
147 gaim_debug_misc("MSNCL","response{%p},name:%s\n",response,response->name);
|
19784
|
148 result =xmlnode_get_child(response,"FindMembershipResult");
|
19840
|
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);
|
19784
|
154 services =xmlnode_get_child(result,"Services");
|
19840
|
155 gaim_debug_misc("MSNCL","services{%p},name:%s\n",services,services->name);
|
19784
|
156 service =xmlnode_get_child(services,"Service");
|
19840
|
157 gaim_debug_misc("MSNCL","service{%p},name:%s\n",service,service->name);
|
19834
|
158
|
|
159 /*Last Change Node*/
|
|
160 LastChangeNode = xmlnode_get_child(service,"LastChange");
|
19840
|
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);
|
19834
|
165
|
19784
|
166 memberships =xmlnode_get_child(service,"Memberships");
|
19840
|
167 gaim_debug_misc("MSNCL","memberships{%p},name:%s\n",memberships,memberships->name);
|
19784
|
168 for(membershipnode = xmlnode_get_child(memberships, "Membership"); membershipnode;
|
|
169 membershipnode = xmlnode_get_next_twin(membershipnode)){
|
19823
|
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);
|
19840
|
175 gaim_debug_misc("MSNCL","MemberRole role:%s,list_op:%d\n",role,list_op);
|
19823
|
176 g_free(role);
|
19784
|
177 members = xmlnode_get_child(membershipnode,"Members");
|
19785
|
178 for(member = xmlnode_get_child(members, "Member"); member;
|
|
179 member = xmlnode_get_next_twin(member)){
|
19800
|
180 MsnUser *user;
|
19786
|
181 xmlnode * typeNode;
|
|
182 char * type;
|
|
183
|
19840
|
184 gaim_debug_misc("MSNCL","type:%s\n",xmlnode_get_attrib(member,"type"));
|
19786
|
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);
|
19840
|
190 gaim_debug_misc("MSNCL","Passport name:%s,type:%s\n",passport,type);
|
19823
|
191 g_free(type);
|
19800
|
192
|
|
193 user = msn_userlist_find_add_user(session->userlist,passport,NULL);
|
19786
|
194 msn_got_lst_user(session, user, list_op, NULL);
|
19823
|
195 g_free(passport);
|
19784
|
196 }
|
19786
|
197 if(!g_strcasecmp(xmlnode_get_attrib(member,"type"),"PhoneMember")){
|
|
198 }
|
|
199 if(!g_strcasecmp(xmlnode_get_attrib(member,"type"),"EmailMember")){
|
19800
|
200 xmlnode *emailNode;
|
|
201
|
|
202 emailNode = xmlnode_get_child(member,"Email");
|
|
203 passport = xmlnode_get_data(emailNode);
|
19840
|
204 gaim_debug_info("MSNCL","Email Member :name:%s,list_op:%d\n",passport,list_op);
|
19800
|
205 user = msn_userlist_find_add_user(session->userlist,passport,NULL);
|
|
206 msn_got_lst_user(session,user,list_op,NULL);
|
19823
|
207 g_free(passport);
|
19786
|
208 }
|
19785
|
209 }
|
19784
|
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;
|
19840
|
221 const char * abLastChange;
|
|
222 const char * dynamicItemLastChange;
|
19784
|
223
|
|
224 contact = soapconn->parent;
|
|
225 g_return_if_fail(contact != NULL);
|
|
226 session = soapconn->session;
|
|
227 g_return_if_fail(session != NULL);
|
|
228
|
19826
|
229 #ifdef MSN_CONTACT_SOAP_DEBUG
|
|
230 gaim_debug_misc("msn", "soap contact server Reply: {%s}\n", soapconn->read_buf);
|
|
231 #endif
|
19784
|
232 msn_parse_contact_list(contact);
|
19816
|
233 /*free the read buffer*/
|
|
234 msn_soap_free_read_buf(soapconn);
|
|
235
|
19840
|
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);
|
19784
|
239 }
|
|
240
|
|
241 static void
|
19796
|
242 msn_get_contact_written_cb(gpointer data, gint source, GaimInputCondition cond)
|
19784
|
243 {
|
|
244 MsnSoapConn * soapconn = data;
|
|
245
|
|
246 gaim_debug_info("MaYuan","finish contact written\n");
|
|
247 soapconn->read_cb = msn_get_contact_list_cb;
|
19810
|
248 // msn_soap_read_cb(data,source,cond);
|
19784
|
249 }
|
|
250
|
19840
|
251 /*SOAP get contact list*/
|
19784
|
252 void
|
19840
|
253 msn_get_contact_list(MsnContact * contact,char * update_time)
|
19784
|
254 {
|
19804
|
255 MsnSoapReq *soap_request;
|
19840
|
256 char *body = NULL;
|
|
257 char * update_str;
|
|
258
|
19806
|
259 gaim_debug_info("MaYuan","Getting Contact List...\n");
|
19840
|
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);
|
19804
|
267 soap_request = msn_soap_request_new(MSN_CONTACT_SERVER,
|
|
268 MSN_GET_CONTACT_POST_URL,MSN_GET_CONTACT_SOAP_ACTION,
|
19840
|
269 body,
|
19804
|
270 msn_get_contact_list_cb,
|
|
271 msn_get_contact_written_cb);
|
19806
|
272 msn_soap_post(contact->soapconn,soap_request,msn_contact_connect_init);
|
19840
|
273 g_free(update_str);
|
|
274 g_free(body);
|
19784
|
275 }
|
|
276
|
19785
|
277 static void
|
|
278 msn_parse_addressbook(MsnContact * contact)
|
19784
|
279 {
|
19785
|
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;
|
19840
|
284 xmlnode *abNode;
|
19787
|
285 char *group_name,*group_id;
|
19785
|
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");
|
19840
|
301 if(result == NULL){
|
|
302 gaim_debug_misc("MSNAB","receive no address book update\n");
|
|
303 return;
|
|
304 }
|
19785
|
305 gaim_debug_misc("xml","result{%p},name:%s\n",result,result->name);
|
19787
|
306
|
|
307 /*Process Group List*/
|
19785
|
308 groups =xmlnode_get_child(result,"groups");
|
|
309 for(group = xmlnode_get_child(groups, "Group"); group;
|
|
310 group = xmlnode_get_next_twin(group)){
|
19787
|
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);
|
19785
|
316
|
19787
|
317 msn_group_new(session->userlist, group_id, group_name);
|
|
318
|
|
319 if (group_id == NULL){
|
|
320 /* Group of ungroupped buddies */
|
|
321 continue;
|
|
322 }
|
19785
|
323
|
19823
|
324 gaim_debug_misc("MsnAB","group_id:%s name:%s\n",group_id,group_name);
|
19787
|
325 if ((gaim_find_group(group_name)) == NULL){
|
|
326 GaimGroup *g = gaim_group_new(group_name);
|
19840
|
327 gaim_blist_node_set_string(&(g->node),"groupId",group_id);
|
19787
|
328 gaim_blist_add_group(g, NULL);
|
|
329 }
|
19823
|
330 g_free(group_id);
|
|
331 g_free(group_name);
|
19787
|
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){
|
19823
|
338 gaim_debug_misc("MsnAB","group_id:%s name:%s,value:%d\n",group_id,group_name,*group_name=='\0');
|
19787
|
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);
|
19785
|
346
|
19787
|
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){
|
19823
|
352 gaim_debug_misc("MsnAB","group_id:%s name:%s,value:%d\n",group_id,group_name,*group_name=='\0');
|
19787
|
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);
|
19785
|
360
|
19787
|
361 /*Process contact List*/
|
19836
|
362 gaim_debug_info("MSNAB","process contact list...\n");
|
19785
|
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
|
19827
|
369 passport = NULL;
|
|
370
|
19785
|
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
|
19825
|
378 /*setup the Display Name*/
|
|
379 if (!strcmp(type, "Me")){
|
19827
|
380 char *friendly;
|
|
381 friendly = xmlnode_get_data(xmlnode_get_child(contactInfo,"displayName"));
|
19825
|
382 gaim_connection_set_display_name(session->account->gc, gaim_url_decode(friendly));
|
|
383 g_free(friendly);
|
|
384 }
|
|
385
|
19785
|
386 passportName = xmlnode_get_child(contactInfo,"passportName");
|
19786
|
387 if(passportName == NULL){
|
19800
|
388 xmlnode *emailsNode, *contactEmailNode, *emailNode;
|
|
389 xmlnode *messengerEnabledNode;
|
|
390 char *msnEnabled;
|
|
391
|
19786
|
392 /*TODO: add it to the none-instant Messenger group and recognize as email Membership*/
|
19800
|
393 /*Yahoo User?*/
|
|
394 emailsNode = xmlnode_get_child(contactInfo,"emails");
|
19836
|
395 if(emailsNode == NULL){
|
|
396 /*TODO: need to support the Mobile type*/
|
|
397 continue;
|
|
398 }
|
19800
|
399 for(contactEmailNode = xmlnode_get_child(emailsNode,"ContactEmail");contactEmailNode;
|
|
400 contactEmailNode = xmlnode_get_next_twin(contactEmailNode) ){
|
|
401 messengerEnabledNode = xmlnode_get_child(contactEmailNode,"isMessengerEnabled");
|
19808
|
402 if(messengerEnabledNode == NULL){
|
|
403 break;
|
|
404 }
|
19800
|
405 msnEnabled = xmlnode_get_data(messengerEnabledNode);
|
|
406 if(!strcmp(msnEnabled,"true")){
|
19827
|
407 /*Messenger enabled, Get the Passport*/
|
19800
|
408 emailNode = xmlnode_get_child(contactEmailNode,"email");
|
|
409 passport = xmlnode_get_data(emailNode);
|
19823
|
410 gaim_debug_info("MsnAB","Yahoo User %s\n",passport);
|
19800
|
411 break;
|
19827
|
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");
|
19800
|
417 }
|
19823
|
418 g_free(msnEnabled);
|
19800
|
419 }
|
|
420 }else{
|
|
421 passport = xmlnode_get_data(passportName);
|
19786
|
422 }
|
19785
|
423
|
19827
|
424 if(passport == NULL){
|
|
425 continue;
|
|
426 }
|
|
427
|
19785
|
428 displayName = xmlnode_get_child(contactInfo,"displayName");
|
19823
|
429 if(displayName == NULL){
|
|
430 Name = g_strdup(passport);
|
|
431 }else{
|
19808
|
432 Name =xmlnode_get_data(displayName);
|
19823
|
433 }
|
19785
|
434
|
19827
|
435 gaim_debug_misc("MsnAB","passport:{%s} uid:{%s} display:{%s}\n",
|
|
436 passport,uid,Name);
|
19785
|
437
|
19800
|
438 user = msn_userlist_find_add_user(session->userlist, passport,Name);
|
19785
|
439 msn_user_set_uid(user,uid);
|
|
440 msn_user_set_type(user,msn_get_user_type(type));
|
19799
|
441 user->list_op |= MSN_LIST_FL_OP;
|
19823
|
442 g_free(Name);
|
|
443 g_free(passport);
|
|
444 g_free(uid);
|
|
445 g_free(type);
|
19785
|
446
|
19836
|
447 gaim_debug_misc("MsnAB","parse guid...\n");
|
19785
|
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);
|
19823
|
454 gaim_debug_misc("MsnAB","guid:%s\n",group_id);
|
|
455 g_free(group_id);
|
19785
|
456 }
|
|
457 }else{
|
19824
|
458 /*not in any group,Then set default group*/
|
19787
|
459 group_id = g_strdup(MSN_INDIVIDUALS_GROUP_ID);
|
|
460 msn_user_add_group_id(user,group_id);
|
|
461 g_free(group_id);
|
19785
|
462 }
|
|
463 }
|
|
464
|
19834
|
465 abNode =xmlnode_get_child(result,"ab");
|
|
466 if(abNode != NULL){
|
19840
|
467 xmlnode *LastChangeNode, *DynamicItemLastChangedNode;
|
|
468 char *lastchange, *dynamicChange;
|
|
469
|
19834
|
470 LastChangeNode = xmlnode_get_child(abNode,"lastChange");
|
|
471 lastchange = xmlnode_get_data(LastChangeNode);
|
19836
|
472 gaim_debug_info("MsnAB"," lastchanged Time:{%s}\n",lastchange);
|
19840
|
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);
|
19834
|
479 }
|
19785
|
480
|
|
481 xmlnode_free(node);
|
|
482 msn_soap_free_read_buf(contact->soapconn);
|
19784
|
483 }
|
|
484
|
19785
|
485 static void
|
|
486 msn_get_address_cb(gpointer data, gint source, GaimInputCondition cond)
|
19784
|
487 {
|
19785
|
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);
|
19828
|
499
|
|
500 msn_notification_dump_contact(session);
|
|
501 msn_set_psm(session);
|
|
502 msn_session_finish_login(session);
|
|
503
|
19816
|
504 /*free the read buffer*/
|
|
505 msn_soap_free_read_buf(soapconn);
|
19785
|
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;
|
19784
|
516 }
|
|
517
|
19785
|
518 /*get the address book*/
|
|
519 void
|
19840
|
520 msn_get_address_book(MsnContact *contact,char * LastChanged, char * dynamicItemLastChange)
|
19784
|
521 {
|
19804
|
522 MsnSoapReq *soap_request;
|
19840
|
523 char *body = NULL;
|
|
524 char *ab_update_str,*update_str;
|
19804
|
525
|
19785
|
526 gaim_debug_info("MaYuan","msn_get_address_book()...\n");
|
|
527 /*build SOAP and POST it*/
|
19840
|
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);
|
19804
|
542 soap_request = msn_soap_request_new(MSN_CONTACT_SERVER,
|
|
543 MSN_ADDRESS_BOOK_POST_URL,MSN_GET_ADDRESS_SOAP_ACTION,
|
19840
|
544 body,
|
19804
|
545 msn_get_address_cb,
|
|
546 msn_address_written_cb);
|
19806
|
547 msn_soap_post(contact->soapconn,soap_request,msn_contact_connect_init);
|
19840
|
548 g_free(update_str);
|
|
549 g_free(body);
|
19785
|
550 }
|
|
551
|
19796
|
552 static void
|
|
553 msn_add_contact_read_cb(gpointer data, gint source, GaimInputCondition cond)
|
|
554 {
|
19827
|
555 gaim_debug_info("MaYuan","add contact read done\n");
|
19796
|
556 }
|
|
557
|
|
558 static void
|
|
559 msn_add_contact_written_cb(gpointer data, gint source, GaimInputCondition cond)
|
|
560 {
|
|
561 MsnSoapConn * soapconn = data;
|
|
562
|
19827
|
563 gaim_debug_info("MaYuan","finish add contact written\n");
|
19796
|
564 soapconn->read_cb = msn_add_contact_read_cb;
|
19810
|
565 // msn_soap_read_cb(data,source,cond);
|
19796
|
566 }
|
|
567
|
19789
|
568 /*add a Contact */
|
19785
|
569 void
|
19827
|
570 msn_add_contact(MsnContact *contact,const char *passport,const char *groupId)
|
19785
|
571 {
|
19804
|
572 MsnSoapReq *soap_request;
|
19794
|
573 char *body = NULL;
|
|
574 char *contact_xml = NULL;
|
19804
|
575 char *soap_action;
|
19794
|
576
|
19790
|
577 gaim_debug_info("MaYuan","msn add a contact...\n");
|
19794
|
578 contact_xml = g_strdup_printf(MSN_CONTACT_XML,passport);
|
19796
|
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*/
|
19804
|
583 soap_action = g_strdup(MSN_CONTACT_ADD_SOAP_ACTION);
|
19796
|
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*/
|
19804
|
588 soap_action = g_strdup(MSN_ADD_CONTACT_GROUP_SOAP_ACTION);
|
19796
|
589 }
|
19804
|
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);
|
19806
|
595 msn_soap_post(contact->soapconn,soap_request,msn_contact_connect_init);
|
19793
|
596
|
19804
|
597 g_free(soap_action);
|
19794
|
598 g_free(body);
|
19784
|
599 }
|
|
600
|
19796
|
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;
|
19810
|
614 // msn_soap_read_cb(data,source,cond);
|
19796
|
615 }
|
|
616
|
19789
|
617 /*delete a Contact*/
|
19785
|
618 void
|
19796
|
619 msn_delete_contact(MsnContact *contact,const char *contactId)
|
19785
|
620 {
|
19794
|
621 char *body = NULL;
|
|
622 char *contact_xml = NULL ;
|
19804
|
623 MsnSoapReq *soap_request;
|
19794
|
624
|
19831
|
625 g_return_if_fail(contactId != NULL);
|
19796
|
626 gaim_debug_info("MaYuan","msn delete a contact,contactId:{%s}...\n",contactId);
|
|
627 contact_xml = g_strdup_printf(MSN_CONTACTS_DEL_XML,contactId);
|
19794
|
628 body = g_strdup_printf(MSN_DEL_CONTACT_TEMPLATE,contact_xml);
|
|
629 g_free(contact_xml);
|
19793
|
630 /*build SOAP and POST it*/
|
19804
|
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);
|
19806
|
636 msn_soap_post(contact->soapconn,soap_request,msn_contact_connect_init);
|
19804
|
637
|
19794
|
638 g_free(body);
|
19785
|
639 }
|
|
640
|
19796
|
641 static void
|
19839
|
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
|
19796
|
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
|
19789
|
693 /*block a Contact*/
|
19785
|
694 void
|
19794
|
695 msn_block_contact(MsnContact *contact,const char* membership_id)
|
|
696 {
|
19804
|
697 MsnSoapReq *soap_request;
|
19794
|
698 char *body = NULL;
|
|
699
|
19790
|
700 gaim_debug_info("MaYuan","msn block a contact...\n");
|
19794
|
701 body = g_strdup_printf(MSN_CONTACT_DELECT_FROM_ALLOW_TEMPLATE,membership_id);
|
19793
|
702 /*build SOAP and POST it*/
|
19804
|
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);
|
19806
|
708 msn_soap_post(contact->soapconn,soap_request,msn_contact_connect_init);
|
19804
|
709
|
19794
|
710 g_free(body);
|
19785
|
711 }
|
|
712
|
19796
|
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
|
19789
|
728 /*unblock a contact*/
|
19785
|
729 void
|
19794
|
730 msn_unblock_contact(MsnContact *contact,const char* passport)
|
|
731 {
|
19804
|
732 MsnSoapReq *soap_request;
|
19794
|
733 char *body = NULL;
|
|
734
|
19790
|
735 gaim_debug_info("MaYuan","msn unblock a contact...\n");
|
19794
|
736
|
|
737 body = g_strdup_printf(MSN_UNBLOCK_CONTACT_TEMPLATE,passport);
|
19793
|
738 /*build SOAP and POST it*/
|
19804
|
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);
|
19806
|
744 msn_soap_post(contact->soapconn,soap_request,msn_contact_connect_init);
|
19804
|
745
|
19794
|
746 g_free(body);
|
19785
|
747 }
|
|
748
|
19796
|
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;
|
19810
|
762 // msn_soap_read_cb(data,source,cond);
|
19796
|
763 }
|
|
764
|
19789
|
765 /*get the gleams info*/
|
19785
|
766 void
|
|
767 msn_get_gleams(MsnContact *contact)
|
19784
|
768 {
|
19804
|
769 MsnSoapReq *soap_request;
|
|
770
|
19790
|
771 gaim_debug_info("MaYuan","msn get gleams info...\n");
|
|
772 /*build SOAP and POST it*/
|
19804
|
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);
|
19806
|
778 msn_soap_post(contact->soapconn,soap_request,msn_contact_connect_init);
|
19784
|
779 }
|
|
780
|
19795
|
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;
|
19810
|
797 // msn_soap_read_cb(data,source,cond);
|
19795
|
798 }
|
|
799
|
19794
|
800 /*add group*/
|
19795
|
801 void msn_add_group(MsnSession *session,const char* group_name)
|
19793
|
802 {
|
19804
|
803 MsnSoapReq *soap_request;
|
|
804 MsnContact *contact ;
|
19795
|
805 char *body = NULL;
|
|
806
|
|
807 g_return_if_fail(session != NULL);
|
|
808 contact = session->contact;
|
19793
|
809 gaim_debug_info("MaYuan","msn add group...\n");
|
|
810
|
19795
|
811 body = g_strdup_printf(MSN_GROUP_ADD_TEMPLATE,group_name);
|
19793
|
812 /*build SOAP and POST it*/
|
19804
|
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);
|
19806
|
818 msn_soap_post(contact->soapconn,soap_request,msn_contact_connect_init);
|
19793
|
819 }
|
|
820
|
19794
|
821 /*delete a group*/
|
19795
|
822 void msn_del_group(MsnSession *session,const char *guid)
|
19793
|
823 {
|
19804
|
824 MsnSoapReq *soap_request;
|
19795
|
825 MsnContact *contact;
|
|
826 char *body = NULL;
|
|
827
|
|
828 g_return_if_fail(session != NULL);
|
19827
|
829 /*if group uid we need to del is NULL,
|
|
830 * we need to delete nothing
|
|
831 */
|
|
832 g_return_if_fail(guid != NULL);
|
19795
|
833 contact = session->contact;
|
19793
|
834 gaim_debug_info("MaYuan","msn del group...\n");
|
|
835
|
19795
|
836 body = g_strdup_printf(MSN_GROUP_DEL_TEMPLATE,guid);
|
19793
|
837 /*build SOAP and POST it*/
|
19804
|
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);
|
19806
|
843 msn_soap_post(contact->soapconn,soap_request,msn_contact_connect_init);
|
19804
|
844
|
19795
|
845 g_free(body);
|
19793
|
846 }
|
|
847
|
19784
|
848 void
|
19806
|
849 msn_contact_connect_init(MsnSoapConn *soapconn)
|
19784
|
850 {
|
|
851 /* Authenticate via Windows Live ID. */
|
|
852 gaim_debug_info("MaYuan","msn_contact_connect...\n");
|
|
853
|
19806
|
854 msn_soap_init(soapconn,MSN_CONTACT_SERVER,1,
|
19784
|
855 msn_contact_login_connect_cb,
|
|
856 msn_contact_login_error_cb);
|
|
857 }
|
|
858
|