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