Mercurial > pidgin.yaz
comparison libgaim/protocols/msn/nexus.c @ 14249:9c371189d7d6
[gaim-migrate @ 16931]
I was wrong when I said PRPLs wouldn't need to be changed to
handle cancelable ssl connections.
This makes MSN not crash when canceling half-way through sign
on. Try it, I dare you.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Mon, 21 Aug 2006 02:21:51 +0000 |
parents | 60b1bc8dbf37 |
children | e354528c4163 |
comparison
equal
deleted
inserted
replaced
14248:4975f529d909 | 14249:9c371189d7d6 |
---|---|
43 } | 43 } |
44 | 44 |
45 void | 45 void |
46 msn_nexus_destroy(MsnNexus *nexus) | 46 msn_nexus_destroy(MsnNexus *nexus) |
47 { | 47 { |
48 if (nexus->gsc) | |
49 gaim_ssl_close(nexus->gsc); | |
50 | |
48 g_free(nexus->login_host); | 51 g_free(nexus->login_host); |
49 | 52 |
50 g_free(nexus->login_path); | 53 g_free(nexus->login_path); |
51 | 54 |
52 if (nexus->challenge_data != NULL) | 55 if (nexus->challenge_data != NULL) |
97 | 100 |
98 if (len < 0 && errno == EAGAIN) | 101 if (len < 0 && errno == EAGAIN) |
99 return; | 102 return; |
100 else if (len <= 0) { | 103 else if (len <= 0) { |
101 gaim_input_remove(nexus->input_handler); | 104 gaim_input_remove(nexus->input_handler); |
102 nexus->input_handler = -1; | 105 nexus->input_handler = 0; |
103 /* TODO: notify of the error */ | 106 /* TODO: notify of the error */ |
104 return; | 107 return; |
105 } | 108 } |
106 nexus->written_len += len; | 109 nexus->written_len += len; |
107 | 110 |
108 if (nexus->written_len < total_len) | 111 if (nexus->written_len < total_len) |
109 return; | 112 return; |
110 | 113 |
111 gaim_input_remove(nexus->input_handler); | 114 gaim_input_remove(nexus->input_handler); |
112 nexus->input_handler = -1; | 115 nexus->input_handler = 0; |
113 | 116 |
114 g_free(nexus->write_buf); | 117 g_free(nexus->write_buf); |
115 nexus->write_buf = NULL; | 118 nexus->write_buf = NULL; |
116 nexus->written_len = 0; | 119 nexus->written_len = 0; |
117 | 120 |
133 MsnSession *session; | 136 MsnSession *session; |
134 | 137 |
135 nexus = data; | 138 nexus = data; |
136 g_return_if_fail(nexus != NULL); | 139 g_return_if_fail(nexus != NULL); |
137 | 140 |
141 nexus->gsc = NULL; | |
142 | |
138 session = nexus->session; | 143 session = nexus->session; |
139 g_return_if_fail(session != NULL); | 144 g_return_if_fail(session != NULL); |
140 | 145 |
141 msn_session_set_error(session, MSN_ERROR_AUTH, _("Unable to connect")); | 146 msn_session_set_error(session, MSN_ERROR_AUTH, _("Unable to connect")); |
142 /* the above line will result in nexus being destroyed, so we don't want | 147 /* the above line will result in nexus being destroyed, so we don't want |
151 int len; | 156 int len; |
152 | 157 |
153 session = nexus->session; | 158 session = nexus->session; |
154 g_return_if_fail(session != NULL); | 159 g_return_if_fail(session != NULL); |
155 | 160 |
156 if (nexus->input_handler == -1) | 161 if (nexus->input_handler == 0) |
162 //TODO: Use gaim_ssl_input_add()? | |
157 nexus->input_handler = gaim_input_add(nexus->gsc->fd, | 163 nexus->input_handler = gaim_input_add(nexus->gsc->fd, |
158 GAIM_INPUT_READ, nexus_login_written_cb, nexus); | 164 GAIM_INPUT_READ, nexus_login_written_cb, nexus); |
159 | 165 |
160 | 166 |
161 len = msn_ssl_read(nexus); | 167 len = msn_ssl_read(nexus); |
162 | 168 |
163 if (len < 0 && errno == EAGAIN) | 169 if (len < 0 && errno == EAGAIN) |
164 return; | 170 return; |
165 else if (len < 0) { | 171 else if (len < 0) { |
166 gaim_input_remove(nexus->input_handler); | 172 gaim_input_remove(nexus->input_handler); |
167 nexus->input_handler = -1; | 173 nexus->input_handler = 0; |
168 g_free(nexus->read_buf); | 174 g_free(nexus->read_buf); |
169 nexus->read_buf = NULL; | 175 nexus->read_buf = NULL; |
170 nexus->read_len = 0; | 176 nexus->read_len = 0; |
171 /* TODO: error handling */ | 177 /* TODO: error handling */ |
172 return; | 178 return; |
175 if (g_strstr_len(nexus->read_buf, nexus->read_len, | 181 if (g_strstr_len(nexus->read_buf, nexus->read_len, |
176 "\r\n\r\n") == NULL) | 182 "\r\n\r\n") == NULL) |
177 return; | 183 return; |
178 | 184 |
179 gaim_input_remove(nexus->input_handler); | 185 gaim_input_remove(nexus->input_handler); |
180 nexus->input_handler = -1; | 186 nexus->input_handler = 0; |
181 | 187 |
182 gaim_ssl_close(nexus->gsc); | 188 gaim_ssl_close(nexus->gsc); |
183 nexus->gsc = NULL; | 189 nexus->gsc = NULL; |
184 | 190 |
185 gaim_debug_misc("msn", "ssl buffer: {%s}", nexus->read_buf); | 191 gaim_debug_misc("msn", "ssl buffer: {%s}", nexus->read_buf); |
216 } | 222 } |
217 | 223 |
218 g_free(nexus->login_host); | 224 g_free(nexus->login_host); |
219 nexus->login_host = g_strdup(location); | 225 nexus->login_host = g_strdup(location); |
220 | 226 |
221 gaim_ssl_connect(session->account, nexus->login_host, | 227 nexus->gsc = gaim_ssl_connect(session->account, |
222 GAIM_SSL_DEFAULT_PORT, login_connect_cb, | 228 nexus->login_host, GAIM_SSL_DEFAULT_PORT, |
223 login_error_cb, nexus); | 229 login_connect_cb, login_error_cb, nexus); |
224 } | 230 } |
225 else if (strstr(nexus->read_buf, "HTTP/1.1 401 Unauthorized") != NULL) | 231 else if (strstr(nexus->read_buf, "HTTP/1.1 401 Unauthorized") != NULL) |
226 { | 232 { |
227 const char *error; | 233 const char *error; |
228 | 234 |
317 nexus = data; | 323 nexus = data; |
318 g_return_if_fail(nexus != NULL); | 324 g_return_if_fail(nexus != NULL); |
319 | 325 |
320 session = nexus->session; | 326 session = nexus->session; |
321 g_return_if_fail(session != NULL); | 327 g_return_if_fail(session != NULL); |
322 | |
323 nexus->gsc = gsc; | |
324 | 328 |
325 msn_session_set_login_step(session, MSN_LOGIN_STEP_GET_COOKIE); | 329 msn_session_set_login_step(session, MSN_LOGIN_STEP_GET_COOKIE); |
326 | 330 |
327 username = | 331 username = |
328 g_strdup(gaim_url_encode(gaim_account_get_username(session->account))); | 332 g_strdup(gaim_url_encode(gaim_account_get_username(session->account))); |
391 MsnNexus *nexus = data; | 395 MsnNexus *nexus = data; |
392 int len; | 396 int len; |
393 char *da_login; | 397 char *da_login; |
394 char *base, *c; | 398 char *base, *c; |
395 | 399 |
396 if (nexus->input_handler == -1) | 400 if (nexus->input_handler == 0) |
401 //TODO: Use gaim_ssl_input_add()? | |
397 nexus->input_handler = gaim_input_add(nexus->gsc->fd, | 402 nexus->input_handler = gaim_input_add(nexus->gsc->fd, |
398 GAIM_INPUT_READ, nexus_connect_written_cb, nexus); | 403 GAIM_INPUT_READ, nexus_connect_written_cb, nexus); |
399 | 404 |
400 /* Get the PassportURLs line. */ | 405 /* Get the PassportURLs line. */ |
401 len = msn_ssl_read(nexus); | 406 len = msn_ssl_read(nexus); |
402 | 407 |
403 if (len < 0 && errno == EAGAIN) | 408 if (len < 0 && errno == EAGAIN) |
404 return; | 409 return; |
405 else if (len < 0) { | 410 else if (len < 0) { |
406 gaim_input_remove(nexus->input_handler); | 411 gaim_input_remove(nexus->input_handler); |
407 nexus->input_handler = -1; | 412 nexus->input_handler = 0; |
408 g_free(nexus->read_buf); | 413 g_free(nexus->read_buf); |
409 nexus->read_buf = NULL; | 414 nexus->read_buf = NULL; |
410 nexus->read_len = 0; | 415 nexus->read_len = 0; |
411 /* TODO: error handling */ | 416 /* TODO: error handling */ |
412 return; | 417 return; |
415 if (g_strstr_len(nexus->read_buf, nexus->read_len, | 420 if (g_strstr_len(nexus->read_buf, nexus->read_len, |
416 "\r\n\r\n") == NULL) | 421 "\r\n\r\n") == NULL) |
417 return; | 422 return; |
418 | 423 |
419 gaim_input_remove(nexus->input_handler); | 424 gaim_input_remove(nexus->input_handler); |
420 nexus->input_handler = -1; | 425 nexus->input_handler = 0; |
421 | 426 |
422 base = strstr(nexus->read_buf, "PassportURLs"); | 427 base = strstr(nexus->read_buf, "PassportURLs"); |
423 | 428 |
424 if (base == NULL) | 429 if (base == NULL) |
425 { | 430 { |
449 g_free(nexus->read_buf); | 454 g_free(nexus->read_buf); |
450 nexus->read_buf = NULL; | 455 nexus->read_buf = NULL; |
451 nexus->read_len = 0; | 456 nexus->read_len = 0; |
452 | 457 |
453 gaim_ssl_close(nexus->gsc); | 458 gaim_ssl_close(nexus->gsc); |
454 nexus->gsc = NULL; | |
455 | 459 |
456 /* Now begin the connection to the login server. */ | 460 /* Now begin the connection to the login server. */ |
457 gaim_ssl_connect(nexus->session->account, nexus->login_host, | 461 nexus->gsc = gaim_ssl_connect(nexus->session->account, |
458 GAIM_SSL_DEFAULT_PORT, login_connect_cb, login_error_cb, | 462 nexus->login_host, GAIM_SSL_DEFAULT_PORT, |
459 nexus); | 463 login_connect_cb, login_error_cb, nexus); |
460 } | 464 } |
461 | 465 |
462 | 466 |
463 /************************************************************************** | 467 /************************************************************************** |
464 * Connect | 468 * Connect |
475 g_return_if_fail(nexus != NULL); | 479 g_return_if_fail(nexus != NULL); |
476 | 480 |
477 session = nexus->session; | 481 session = nexus->session; |
478 g_return_if_fail(session != NULL); | 482 g_return_if_fail(session != NULL); |
479 | 483 |
480 nexus->gsc = gsc; | |
481 | |
482 msn_session_set_login_step(session, MSN_LOGIN_STEP_AUTH); | 484 msn_session_set_login_step(session, MSN_LOGIN_STEP_AUTH); |
483 | 485 |
484 nexus->write_buf = g_strdup("GET /rdr/pprdr.asp\r\n\r\n"); | 486 nexus->write_buf = g_strdup("GET /rdr/pprdr.asp\r\n\r\n"); |
485 nexus->written_len = 0; | 487 nexus->written_len = 0; |
486 | 488 |
495 } | 497 } |
496 | 498 |
497 void | 499 void |
498 msn_nexus_connect(MsnNexus *nexus) | 500 msn_nexus_connect(MsnNexus *nexus) |
499 { | 501 { |
500 gaim_ssl_connect(nexus->session->account, "nexus.passport.com", | 502 nexus->gsc = gaim_ssl_connect(nexus->session->account, |
501 GAIM_SSL_DEFAULT_PORT, nexus_connect_cb, | 503 "nexus.passport.com", GAIM_SSL_DEFAULT_PORT, |
502 login_error_cb, nexus); | 504 nexus_connect_cb, login_error_cb, nexus); |
503 } | 505 } |