Mercurial > pidgin.yaz
comparison libpurple/protocols/msn/nexus.c @ 20530:719ce4acfcb9
the new soap code finally doesn't crash on startup, still can't
authenticate though
author | Ka-Hing Cheung <khc@hxbc.us> |
---|---|
date | Fri, 28 Sep 2007 05:51:49 +0000 |
parents | 723b5a2f91ce |
children | a96b5015395a |
comparison
equal
deleted
inserted
replaced
20529:1180920ffcec | 20530:719ce4acfcb9 |
---|---|
20 * You should have received a copy of the GNU General Public License | 20 * You should have received a copy of the GNU General Public License |
21 * along with this program; if not, write to the Free Software | 21 * along with this program; if not, write to the Free Software |
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA | 22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
23 */ | 23 */ |
24 #include "msn.h" | 24 #include "msn.h" |
25 #include "soap.h" | 25 #include "soap2.h" |
26 #include "nexus.h" | 26 #include "nexus.h" |
27 #include "notification.h" | 27 #include "notification.h" |
28 | 28 |
29 #undef NEXUS_LOGIN_TWN | 29 #undef NEXUS_LOGIN_TWN |
30 | 30 |
41 MsnNexus *nexus; | 41 MsnNexus *nexus; |
42 | 42 |
43 nexus = g_new0(MsnNexus, 1); | 43 nexus = g_new0(MsnNexus, 1); |
44 nexus->session = session; | 44 nexus->session = session; |
45 /*we must use SSL connection to do Windows Live ID authentication*/ | 45 /*we must use SSL connection to do Windows Live ID authentication*/ |
46 nexus->soapconn = msn_soap_new(session,nexus,1); | 46 //nexus->soapconn = msn_soap_new(session,nexus,1); |
47 | 47 |
48 nexus->challenge_data = g_hash_table_new_full(g_str_hash, | 48 nexus->challenge_data = g_hash_table_new_full(g_str_hash, |
49 g_str_equal, g_free, g_free); | 49 g_str_equal, g_free, g_free); |
50 | 50 |
51 return nexus; | 51 return nexus; |
55 msn_nexus_destroy(MsnNexus *nexus) | 55 msn_nexus_destroy(MsnNexus *nexus) |
56 { | 56 { |
57 if (nexus->challenge_data != NULL) | 57 if (nexus->challenge_data != NULL) |
58 g_hash_table_destroy(nexus->challenge_data); | 58 g_hash_table_destroy(nexus->challenge_data); |
59 | 59 |
60 msn_soap_destroy(nexus->soapconn); | 60 //msn_soap_destroy(nexus->soapconn); |
61 g_free(nexus); | 61 g_free(nexus); |
62 } | 62 } |
63 | 63 |
64 #if 0 /* khc */ | 64 #if 0 /* khc */ |
65 /************************************************************************** | 65 /************************************************************************** |
138 msn_session_set_error(session, MSN_ERROR_AUTH, _("Windows Live ID authentication:Unable to connect")); | 138 msn_session_set_error(session, MSN_ERROR_AUTH, _("Windows Live ID authentication:Unable to connect")); |
139 /* the above line will result in nexus being destroyed, so we don't want | 139 /* the above line will result in nexus being destroyed, so we don't want |
140 * to destroy it here, or we'd crash */ | 140 * to destroy it here, or we'd crash */ |
141 } | 141 } |
142 | 142 |
143 static void | |
144 nexus_got_response_cb(MsnSoapMessage *req, MsnSoapMessage *resp, gpointer data) | |
145 { | |
146 MsnNexus *nexus = data; | |
147 MsnSession *session = nexus->session; | |
148 xmlnode *node; | |
149 | |
150 if (resp == NULL) { | |
151 msn_session_set_error(session, MSN_ERROR_AUTH, _("Windows Live ID authentication:Unable to connect")); | |
152 return; | |
153 } | |
154 | |
155 node = msn_soap_xml_get(resp->xml, "Body/" | |
156 "RequestSecurityTokenResponseCollection/RequestSecurityTokenResponse"); | |
157 | |
158 for (; node; node = node->next) { | |
159 xmlnode *token = msn_soap_xml_get(node, | |
160 "RequestedSecurityToken/BinarySecurityToken"); | |
161 | |
162 if (token) { | |
163 char **elems, **cur, **tokens; | |
164 char *msn_twn_t, *msn_twn_p, *cert_str; | |
165 | |
166 elems = g_strsplit(token->data, "&", 0); | |
167 | |
168 for (cur = elems; *cur != NULL; cur++){ | |
169 tokens = g_strsplit(*cur, "=", 2); | |
170 g_hash_table_insert(nexus->challenge_data, tokens[0], tokens[1]); | |
171 /* Don't free each of the tokens, only the array. */ | |
172 g_free(tokens); | |
173 } | |
174 | |
175 g_strfreev(elems); | |
176 | |
177 msn_twn_t = g_hash_table_lookup(nexus->challenge_data, "t"); | |
178 msn_twn_p = g_hash_table_lookup(nexus->challenge_data, "p"); | |
179 | |
180 /*setup the t and p parameter for session*/ | |
181 if (session->passport_info.t != NULL){ | |
182 g_free(session->passport_info.t); | |
183 } | |
184 session->passport_info.t = g_strdup(msn_twn_t); | |
185 | |
186 if (session->passport_info.p != NULL) | |
187 g_free(session->passport_info.p); | |
188 session->passport_info.p = g_strdup(msn_twn_p); | |
189 | |
190 cert_str = g_strdup_printf("t=%s&p=%s",msn_twn_t,msn_twn_p); | |
191 msn_got_login_params(session, cert_str); | |
192 | |
193 purple_debug_info("MSN Nexus","Close nexus connection!\n"); | |
194 g_free(cert_str); | |
195 msn_nexus_destroy(nexus); | |
196 session->nexus = NULL; | |
197 | |
198 return; | |
199 } | |
200 } | |
201 } | |
202 #if 0 | |
143 /*process the SOAP reply, get the Authentication Info*/ | 203 /*process the SOAP reply, get the Authentication Info*/ |
144 static void | 204 static void |
145 nexus_login_read_cb(gpointer data, gint source, PurpleInputCondition cond) | 205 nexus_login_read_cb(gpointer data, gint source, PurpleInputCondition cond) |
146 { | 206 { |
147 MsnSoapConn * soapconn = data; | 207 MsnSoapConn * soapconn = data; |
219 MsnSoapConn * soapconn = data; | 279 MsnSoapConn * soapconn = data; |
220 | 280 |
221 soapconn->read_cb = nexus_login_read_cb; | 281 soapconn->read_cb = nexus_login_read_cb; |
222 // msn_soap_read_cb(data,source,cond); | 282 // msn_soap_read_cb(data,source,cond); |
223 } | 283 } |
224 | 284 #endif |
225 | 285 |
226 /*when connect, do the SOAP Style windows Live ID authentication */ | 286 /*when connect, do the SOAP Style windows Live ID authentication */ |
227 void | 287 void |
228 nexus_login_connect_cb(gpointer data, PurpleSslConnection *gsc, | 288 nexus_login_connect_cb(gpointer data, PurpleSslConnection *gsc, |
229 PurpleInputCondition cond) | 289 PurpleInputCondition cond) |
230 { | 290 { |
231 MsnSoapConn *soapconn; | 291 //MsnSoapConn *soapconn; |
232 MsnNexus * nexus; | 292 MsnNexus *nexus = data; |
233 MsnSession *session; | 293 MsnSession *session = nexus->session; |
234 char *ru,*lc,*id,*tw,*ct,*kpp,*kv,*ver,*rn,*tpf; | 294 char *ru,*lc,*id,*tw,*ct,*kpp,*kv,*ver,*rn,*tpf; |
235 char *fs0,*fs; | 295 char *fs0,*fs; |
236 char *username, *password; | 296 char *username, *password; |
237 char *request_str, *head, *tail; | 297 char *request_str, *head, *tail; |
238 #ifdef NEXUS_LOGIN_TWN | 298 #ifdef NEXUS_LOGIN_TWN |
239 char *challenge_str; | 299 char *challenge_str; |
240 #else | 300 #else |
241 char *rst1_str,*rst2_str,*rst3_str; | 301 char *rst1_str,*rst2_str,*rst3_str; |
242 #endif | 302 #endif |
243 | 303 |
304 MsnSoapMessage *soap; | |
305 | |
244 purple_debug_info("MSN Nexus","Starting Windows Live ID authentication\n"); | 306 purple_debug_info("MSN Nexus","Starting Windows Live ID authentication\n"); |
245 | 307 /* |
246 soapconn = data; | 308 soapconn = data; |
247 g_return_if_fail(soapconn != NULL); | 309 g_return_if_fail(soapconn != NULL); |
248 | 310 |
249 nexus = soapconn->parent; | 311 nexus = soapconn->parent; |
250 g_return_if_fail(nexus != NULL); | 312 g_return_if_fail(nexus != NULL); |
251 | 313 |
252 session = soapconn->session; | 314 session = soapconn->session; |
253 g_return_if_fail(session != NULL); | 315 g_return_if_fail(session != NULL); |
316 */ | |
254 | 317 |
255 msn_session_set_login_step(session, MSN_LOGIN_STEP_GET_COOKIE); | 318 msn_session_set_login_step(session, MSN_LOGIN_STEP_GET_COOKIE); |
256 | 319 |
257 /*prepare the Windows Live ID authentication token*/ | 320 /*prepare the Windows Live ID authentication token*/ |
258 username = g_strdup(purple_account_get_username(session->account)); | 321 username = g_strdup(purple_account_get_username(session->account)); |
320 g_free(rst2_str); | 383 g_free(rst2_str); |
321 g_free(rst3_str); | 384 g_free(rst3_str); |
322 #endif | 385 #endif |
323 g_free(fs); | 386 g_free(fs); |
324 | 387 |
388 soap = msn_soap_message_new(NULL, xmlnode_from_str(tail, -1)); | |
389 msn_soap_message_send(nexus->session, soap, MSN_TWN_SERVER, TWN_POST_URL, | |
390 nexus_got_response_cb, nexus); | |
391 | |
392 #if 0 | |
325 soapconn->login_path = g_strdup(TWN_POST_URL); | 393 soapconn->login_path = g_strdup(TWN_POST_URL); |
326 head = g_strdup_printf( | 394 head = g_strdup_printf( |
327 "POST %s HTTP/1.1\r\n" | 395 "POST %s HTTP/1.1\r\n" |
328 "Accept: text/*\r\n" | 396 "Accept: text/*\r\n" |
329 "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)\r\n" | 397 "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)\r\n" |
343 g_free(username); | 411 g_free(username); |
344 g_free(password); | 412 g_free(password); |
345 | 413 |
346 /*prepare to send the SOAP request*/ | 414 /*prepare to send the SOAP request*/ |
347 msn_soap_write(soapconn,request_str,nexus_login_written_cb); | 415 msn_soap_write(soapconn,request_str,nexus_login_written_cb); |
348 | 416 #endif |
349 return; | 417 return; |
350 } | 418 } |
351 | 419 |
352 #if 0 /* khc */ | 420 #if 0 /* khc */ |
353 static void | 421 static void |
465 #endif | 533 #endif |
466 | 534 |
467 void | 535 void |
468 msn_nexus_connect(MsnNexus *nexus) | 536 msn_nexus_connect(MsnNexus *nexus) |
469 { | 537 { |
538 #if 0 | |
470 /* Authenticate via Windows Live ID. */ | 539 /* Authenticate via Windows Live ID. */ |
471 purple_debug_info("MSN Nexus","msn_nexus_connect()\n"); | 540 purple_debug_info("MSN Nexus","msn_nexus_connect()\n"); |
472 msn_soap_init(nexus->soapconn,MSN_TWN_SERVER,1,nexus_login_connect_cb,nexus_login_error_cb); | 541 msn_soap_init(nexus->soapconn,MSN_TWN_SERVER,1,nexus_login_connect_cb,nexus_login_error_cb); |
473 msn_soap_connect(nexus->soapconn); | 542 msn_soap_connect(nexus->soapconn); |
474 } | 543 #endif |
544 nexus_login_connect_cb(nexus, NULL, 0); | |
545 } |