Mercurial > pidgin.yaz
comparison src/protocols/msn/contact.c @ 19738:bc30c6270d9f
[gaim-migrate @ 16473]
add the Framework of SOAP request
Now can retrieve the Contact via SOAP Request.
so many bug still exist!
commited by MaYuan<mayuan2006@gmail.com>
committer: Ethan Blanton <elb@pidgin.im>
author | Ma Yuan <mayuan2006@gmail.com> |
---|---|
date | Sun, 09 Jul 2006 16:48:25 +0000 |
parents | |
children | 852b32710df0 |
comparison
equal
deleted
inserted
replaced
19737:995aea35b05c | 19738:bc30c6270d9f |
---|---|
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 | |
32 /*new a contact*/ | |
33 MsnContact * | |
34 msn_contact_new(MsnSession *session) | |
35 { | |
36 MsnContact *contact; | |
37 | |
38 contact = g_new0(MsnContact, 1); | |
39 contact->session = session; | |
40 contact->soapconn = msn_soap_new(session); | |
41 contact->soapconn->parent = contact; | |
42 contact->soapconn->ssl_conn = 1; | |
43 | |
44 return contact; | |
45 } | |
46 | |
47 /*destroy the contact*/ | |
48 void | |
49 msn_contact_destroy(MsnContact *contact) | |
50 { | |
51 msn_soap_destroy(contact->soapconn); | |
52 g_free(contact); | |
53 } | |
54 | |
55 /*contact SOAP server login error*/ | |
56 static void | |
57 msn_contact_login_error_cb(GaimSslConnection *gsc, GaimSslErrorType error, void *data) | |
58 { | |
59 MsnSoapConn *soapconn = data; | |
60 MsnSession *session; | |
61 | |
62 session = soapconn->session; | |
63 g_return_if_fail(session != NULL); | |
64 | |
65 msn_session_set_error(session, MSN_ERROR_SERV_DOWN, _("Unable to connect to contact server")); | |
66 } | |
67 | |
68 /*msn contact SOAP server connect process*/ | |
69 static void | |
70 msn_contact_login_connect_cb(gpointer data, GaimSslConnection *gsc, | |
71 GaimInputCondition cond) | |
72 { | |
73 MsnSoapConn *soapconn = data; | |
74 MsnSession * session; | |
75 MsnContact *contact; | |
76 | |
77 contact = soapconn->parent; | |
78 g_return_if_fail(contact != NULL); | |
79 | |
80 session = contact->session; | |
81 g_return_if_fail(session != NULL); | |
82 | |
83 /*login ok!We can retrieve the contact list*/ | |
84 msn_get_contact_list(contact); | |
85 } | |
86 | |
87 static void | |
88 msn_parse_contact_list(MsnContact * contact) | |
89 { | |
90 xmlnode * node,*envelop,*body,*response,*result,*services,*service,*memberships; | |
91 xmlnode *membershipnode,*members,*member,*passport,*role; | |
92 int len; | |
93 | |
94 gaim_debug_misc("xml","parse contact list:{%s}\nsize:%d\n",contact->soapconn->body,contact->soapconn->body_len); | |
95 node = xmlnode_from_str(contact->soapconn->body, contact->soapconn->body_len); | |
96 // node = xmlnode_from_str(contact->soapconn->body, -1); | |
97 | |
98 if(node == NULL){ | |
99 gaim_debug_misc("xml","parse from str err!\n"); | |
100 return; | |
101 } | |
102 gaim_debug_misc("xml","node{%p},name:%s,child:%s,last:%s\n",node,node->name,node->child->name,node->lastchild->name); | |
103 body = xmlnode_get_child(node,"Body"); | |
104 gaim_debug_misc("xml","body{%p},name:%s\n",body,body->name); | |
105 response = xmlnode_get_child(body,"FindMembershipResponse"); | |
106 gaim_debug_misc("xml","response{%p},name:%s\n",response,response->name); | |
107 result =xmlnode_get_child(response,"FindMembershipResult"); | |
108 gaim_debug_misc("xml","result{%p},name:%s\n",result,result->name); | |
109 services =xmlnode_get_child(result,"Services"); | |
110 gaim_debug_misc("xml","services{%p},name:%s\n",services,services->name); | |
111 service =xmlnode_get_child(services,"Service"); | |
112 gaim_debug_misc("xml","service{%p},name:%s\n",service,service->name); | |
113 memberships =xmlnode_get_child(service,"Memberships"); | |
114 gaim_debug_misc("xml","memberships{%p},name:%s\n",memberships,memberships->name); | |
115 for(membershipnode = xmlnode_get_child(memberships, "Membership"); membershipnode; | |
116 membershipnode = xmlnode_get_next_twin(membershipnode)){ | |
117 role = xmlnode_get_child(membershipnode,"MemberRole"); | |
118 gaim_debug_misc("memberrole","role:%s\n",xmlnode_get_data(role)); | |
119 members = xmlnode_get_child(membershipnode,"Members"); | |
120 for(member = xmlnode_get_child(members, "Member"); member; | |
121 member = xmlnode_get_next_twin(member)){ | |
122 passport = xmlnode_get_child(member,"PassportName"); | |
123 gaim_debug_misc("Passport","name:%s\n",xmlnode_get_data(passport)); | |
124 } | |
125 } | |
126 | |
127 xmlnode_free(node); | |
128 } | |
129 | |
130 static void | |
131 msn_get_contact_list_cb(gpointer data, gint source, GaimInputCondition cond) | |
132 { | |
133 MsnSoapConn * soapconn = data; | |
134 MsnContact *contact; | |
135 MsnSession *session; | |
136 | |
137 contact = soapconn->parent; | |
138 g_return_if_fail(contact != NULL); | |
139 session = soapconn->session; | |
140 g_return_if_fail(session != NULL); | |
141 | |
142 // gaim_debug_misc("msn", "soap contact server Reply: {%s}\n", soapconn->read_buf); | |
143 msn_parse_contact_list(contact); | |
144 } | |
145 | |
146 static void | |
147 msn_contact_written_cb(gpointer data, gint source, GaimInputCondition cond) | |
148 { | |
149 MsnSoapConn * soapconn = data; | |
150 | |
151 gaim_debug_info("MaYuan","finish contact written\n"); | |
152 soapconn->read_cb = msn_get_contact_list_cb; | |
153 msn_soap_read_cb(data,source,cond); | |
154 } | |
155 | |
156 void | |
157 msn_get_contact_list(MsnContact * contact) | |
158 { | |
159 char * soap_head = NULL; | |
160 char * soap_body = NULL; | |
161 char * request_str = NULL; | |
162 | |
163 gaim_debug_info("MaYuan","msn_get_contact_list()...\n"); | |
164 contact->soapconn->login_path = g_strdup(MSN_GET_CONTACT_POST_URL); | |
165 soap_body = g_strdup_printf(MSN_GET_CONTACT_TEMPLATE); | |
166 soap_head = g_strdup_printf( | |
167 "POST %s HTTP/1.1\r\n" | |
168 "SOAPAction: http://www.msn.com/webservices/AddressBook/FindMembership\r\n" | |
169 "Content-Type:text/xml; charset=utf-8\r\n" | |
170 "Cookie: MSPAuth=%s\r\n" | |
171 "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)\r\n" | |
172 "Accept: text/*\r\n" | |
173 "Host: %s\r\n" | |
174 "Content-Length: %d\r\n" | |
175 "Connection: Keep-Alive\r\n" | |
176 "Cache-Control: no-cache\r\n\r\n", | |
177 contact->soapconn->login_path, | |
178 contact->session->passport_info.mspauth, | |
179 contact->soapconn->login_host, | |
180 strlen(soap_body) | |
181 ); | |
182 request_str = g_strdup_printf("%s%s", soap_head,soap_body); | |
183 g_free(soap_head); | |
184 g_free(soap_body); | |
185 | |
186 // gaim_debug_info("MaYuan","send to contact server{%s}\n",request_str); | |
187 msn_soap_write(contact->soapconn,request_str,msn_contact_written_cb); | |
188 } | |
189 | |
190 msn_add_contact() | |
191 { | |
192 } | |
193 | |
194 msn_delete_contact() | |
195 { | |
196 } | |
197 | |
198 msn_block_contact() | |
199 { | |
200 } | |
201 | |
202 msn_unblock_contact() | |
203 { | |
204 } | |
205 | |
206 msn_get_gleams() | |
207 { | |
208 } | |
209 | |
210 void | |
211 msn_contact_connect(MsnContact *contact) | |
212 { | |
213 /* Authenticate via Windows Live ID. */ | |
214 gaim_debug_info("MaYuan","msn_contact_connect...\n"); | |
215 | |
216 msn_soap_init(contact->soapconn,MSN_CONTACT_SERVER,1, | |
217 msn_contact_login_connect_cb, | |
218 msn_contact_login_error_cb); | |
219 } | |
220 |