comparison libgaim/protocols/msn/nexus.c @ 20390:d634f88e25d8

msn.tgz from SF Patch #1621854 from Ka-Hing Cheung "This tarball brings soc-2006-msnp13 up to head. In addition to that it also fixes a crash with sending offline messages. I wasn't able to generate a diff against that branch, svn seems to insist on diff'ing against HEAD after I run the merge command. After running `svn merge -r 16309:HEAD https://gaim.svn.sourceforge.net/svnroot/gaim/trunk` on the soc-2006-msnp13 you can replace the msn directory with the attached tarball. The fix for offline messaging is on msn.c:901: if (!session->oim) session->oim = msn_oim_new(session)" committer: Richard Laager <rlaager@wiktel.com>
author Ka-Hing Cheung <khc@hxbc.us>
date Sun, 15 Apr 2007 02:18:17 +0000
parents e354528c4163
children
comparison
equal deleted inserted replaced
20389:e354528c4163 20390:d634f88e25d8
23 */ 23 */
24 #include "msn.h" 24 #include "msn.h"
25 #include "soap.h" 25 #include "soap.h"
26 #include "nexus.h" 26 #include "nexus.h"
27 #include "notification.h" 27 #include "notification.h"
28
28 #undef NEXUS_LOGIN_TWN 29 #undef NEXUS_LOGIN_TWN
29 30
30 /*Local Function Prototype*/ 31 /*Local Function Prototype*/
31 static void nexus_login_connect_cb(gpointer data, GaimSslConnection *gsc,GaimInputCondition cond); 32 static void nexus_login_connect_cb(gpointer data, GaimSslConnection *gsc,GaimInputCondition cond);
32 33
58 59
59 msn_soap_destroy(nexus->soapconn); 60 msn_soap_destroy(nexus->soapconn);
60 g_free(nexus); 61 g_free(nexus);
61 } 62 }
62 63
64 #if 0 /* khc */
65 /**************************************************************************
66 * Util
67 **************************************************************************/
68
69 static gssize
70 msn_ssl_read(MsnNexus *nexus)
71 {
72 gssize len;
73 char temp_buf[4096];
74
75 if ((len = gaim_ssl_read(nexus->gsc, temp_buf,
76 sizeof(temp_buf))) > 0)
77 {
78 nexus->read_buf = g_realloc(nexus->read_buf,
79 nexus->read_len + len + 1);
80 strncpy(nexus->read_buf + nexus->read_len, temp_buf, len);
81 nexus->read_len += len;
82 nexus->read_buf[nexus->read_len] = '\0';
83 }
84
85 return len;
86 }
87
88 static void
89 nexus_write_cb(gpointer data, gint source, GaimInputCondition cond)
90 {
91 MsnNexus *nexus = data;
92 int len, total_len;
93
94 total_len = strlen(nexus->write_buf);
95
96 len = gaim_ssl_write(nexus->gsc,
97 nexus->write_buf + nexus->written_len,
98 total_len - nexus->written_len);
99
100 if (len < 0 && errno == EAGAIN)
101 return;
102 else if (len <= 0) {
103 gaim_input_remove(nexus->input_handler);
104 nexus->input_handler = 0;
105 /* TODO: notify of the error */
106 return;
107 }
108 nexus->written_len += len;
109
110 if (nexus->written_len < total_len)
111 return;
112
113 gaim_input_remove(nexus->input_handler);
114 nexus->input_handler = 0;
115
116 g_free(nexus->write_buf);
117 nexus->write_buf = NULL;
118 nexus->written_len = 0;
119
120 nexus->written_cb(nexus, source, 0);
121 }
122
123 #endif
63 /************************************************************************** 124 /**************************************************************************
64 * Login 125 * Login
65 **************************************************************************/ 126 **************************************************************************/
66 static void 127 static void
67 nexus_login_error_cb(GaimSslConnection *gsc, GaimSslErrorType error, void *data) 128 nexus_login_error_cb(GaimSslConnection *gsc, GaimSslErrorType error, void *data)
69 MsnSoapConn * soapconn = data; 130 MsnSoapConn * soapconn = data;
70 MsnSession *session; 131 MsnSession *session;
71 132
72 session = soapconn->session; 133 session = soapconn->session;
73 g_return_if_fail(session != NULL); 134 g_return_if_fail(session != NULL);
135
136 soapconn->gsc = NULL;
74 137
75 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"));
76 /* 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
77 * to destroy it here, or we'd crash */ 140 * to destroy it here, or we'd crash */
78 } 141 }
91 char **elems, **cur, **tokens; 154 char **elems, **cur, **tokens;
92 char * cert_str; 155 char * cert_str;
93 156
94 nexus = soapconn->parent; 157 nexus = soapconn->parent;
95 g_return_if_fail(nexus != NULL); 158 g_return_if_fail(nexus != NULL);
96
97 session = nexus->session; 159 session = nexus->session;
98 g_return_if_fail(session != NULL); 160 g_return_if_fail(session != NULL);
99 161
100 gaim_debug_misc("msn", "TWN Server Reply: {%s}\n", soapconn->read_buf); 162 gaim_debug_misc("msn", "TWN Server Reply: {%s}\n", soapconn->read_buf);
101 163
274 soapconn->login_path,soapconn->login_host,(int)strlen(tail)); 336 soapconn->login_path,soapconn->login_host,(int)strlen(tail));
275 337
276 request_str = g_strdup_printf("%s%s", head,tail); 338 request_str = g_strdup_printf("%s%s", head,tail);
277 gaim_debug_misc("msn", "TWN Sending: {%s}\n", request_str); 339 gaim_debug_misc("msn", "TWN Sending: {%s}\n", request_str);
278 340
279 buffer = g_strdup_printf("%s,pwd=XXXXXXXX,%s\r\n", head, tail);
280 request_str = g_strdup_printf("%s,pwd=%s,%s\r\n", head, password, tail);
281
282 gaim_debug_misc("msn", "Sending: {%s}\n", buffer);
283
284 g_free(buffer);
285 g_free(head); 341 g_free(head);
286 g_free(tail); 342 g_free(tail);
287 g_free(username); 343 g_free(username);
288 g_free(password); 344 g_free(password);
289 345
290 /*prepare to send the SOAP request*/ 346 /*prepare to send the SOAP request*/
291 msn_soap_write(soapconn,request_str,nexus_login_written_cb); 347 msn_soap_write(soapconn,request_str,nexus_login_written_cb);
292 348
293 return; 349 return;
294 350 }
295 351
296 } 352 #if 0 /* khc */
297 353 static void
354 nexus_connect_written_cb(gpointer data, gint source, GaimInputCondition cond)
355 {
356 MsnNexus *nexus = data;
357 int len;
358 char *da_login;
359 char *base, *c;
360
361 if (nexus->input_handler == 0)
362 //TODO: Use gaim_ssl_input_add()?
363 nexus->input_handler = gaim_input_add(nexus->gsc->fd,
364 GAIM_INPUT_READ, nexus_connect_written_cb, nexus);
365
366 /* Get the PassportURLs line. */
367 len = msn_ssl_read(nexus);
368
369 if (len < 0 && errno == EAGAIN)
370 return;
371 else if (len < 0) {
372 gaim_input_remove(nexus->input_handler);
373 nexus->input_handler = 0;
374 g_free(nexus->read_buf);
375 nexus->read_buf = NULL;
376 nexus->read_len = 0;
377 /* TODO: error handling */
378 return;
379 }
380
381 if (g_strstr_len(nexus->read_buf, nexus->read_len,
382 "\r\n\r\n") == NULL)
383 return;
384
385 gaim_input_remove(nexus->input_handler);
386 nexus->input_handler = 0;
387
388 base = strstr(nexus->read_buf, "PassportURLs");
389
390 if (base == NULL)
391 {
392 g_free(nexus->read_buf);
393 nexus->read_buf = NULL;
394 nexus->read_len = 0;
395 return;
396 }
397
398 if ((da_login = strstr(base, "DALogin=")) != NULL)
399 {
400 /* skip over "DALogin=" */
401 da_login += 8;
402
403 if ((c = strchr(da_login, ',')) != NULL)
404 *c = '\0';
405
406 if ((c = strchr(da_login, '/')) != NULL)
407 {
408 nexus->login_path = g_strdup(c);
409 *c = '\0';
410 }
411
412 nexus->login_host = g_strdup(da_login);
413 }
414
415 g_free(nexus->read_buf);
416 nexus->read_buf = NULL;
417 nexus->read_len = 0;
418
419 gaim_ssl_close(nexus->gsc);
420
421 /* Now begin the connection to the login server. */
422 nexus->gsc = gaim_ssl_connect(nexus->session->account,
423 nexus->login_host, GAIM_SSL_DEFAULT_PORT,
424 login_connect_cb, login_error_cb, nexus);
425 }
426
427
428 #endif
298 429
299 /************************************************************************** 430 /**************************************************************************
300 * Connect 431 * Connect
301 **************************************************************************/ 432 **************************************************************************/
433
434 #if 0 /* khc */
435 static void
436 nexus_connect_cb(gpointer data, GaimSslConnection *gsc,
437 GaimInputCondition cond)
438 {
439 MsnNexus *nexus;
440 MsnSession *session;
441
442 nexus = data;
443 g_return_if_fail(nexus != NULL);
444
445 session = nexus->session;
446 g_return_if_fail(session != NULL);
447
448 msn_session_set_login_step(session, MSN_LOGIN_STEP_AUTH);
449
450 nexus->write_buf = g_strdup("GET /rdr/pprdr.asp\r\n\r\n");
451 nexus->written_len = 0;
452
453 nexus->read_len = 0;
454
455 nexus->written_cb = nexus_connect_written_cb;
456
457 nexus->input_handler = gaim_input_add(gsc->fd, GAIM_INPUT_WRITE,
458 nexus_write_cb, nexus);
459
460 nexus_write_cb(nexus, gsc->fd, GAIM_INPUT_WRITE);
461 }
462
463 #endif
302 464
303 void 465 void
304 msn_nexus_connect(MsnNexus *nexus) 466 msn_nexus_connect(MsnNexus *nexus)
305 { 467 {
306 /* Authenticate via Windows Live ID. */ 468 /* Authenticate via Windows Live ID. */
307 gaim_debug_info("MaYuan","msn_nexus_connect...\n"); 469 gaim_debug_info("MaYuan","msn_nexus_connect...\n");
308 msn_soap_init(nexus->soapconn,MSN_TWN_SERVER,1,nexus_login_connect_cb,nexus_login_error_cb); 470 msn_soap_init(nexus->soapconn,MSN_TWN_SERVER,1,nexus_login_connect_cb,nexus_login_error_cb);
309 msn_soap_connect(nexus->soapconn); 471 msn_soap_connect(nexus->soapconn);
310 } 472 }
473