comparison libpurple/protocols/jabber/auth.c @ 29136:b94fd073187c

jabber: Fix that leak I mentioned (and fix a mistake where error/response weren't NULL-initialized)
author Paul Aurich <paul@darkrain42.org>
date Fri, 04 Dec 2009 06:18:05 +0000
parents 4f45aae3ace1
children c64b22932ffa
comparison
equal deleted inserted replaced
29135:8a5252630857 29136:b94fd073187c
163 GSList *mechanisms = NULL; 163 GSList *mechanisms = NULL;
164 GSList *l; 164 GSList *l;
165 xmlnode *response = NULL; 165 xmlnode *response = NULL;
166 xmlnode *mechs, *mechnode; 166 xmlnode *mechs, *mechnode;
167 JabberSaslState state; 167 JabberSaslState state;
168 const char *msg = NULL; 168 char *msg = NULL;
169 169
170 if(js->registration) { 170 if(js->registration) {
171 jabber_register_start(js); 171 jabber_register_start(js);
172 return; 172 return;
173 } 173 }
223 msg ? msg : _("Unknown Error")); 223 msg ? msg : _("Unknown Error"));
224 } else if (response) { 224 } else if (response) {
225 jabber_send(js, response); 225 jabber_send(js, response);
226 xmlnode_free(response); 226 xmlnode_free(response);
227 } 227 }
228
229 g_free(msg);
228 } 230 }
229 231
230 static void auth_old_result_cb(JabberStream *js, const char *from, 232 static void auth_old_result_cb(JabberStream *js, const char *from,
231 JabberIqType type, const char *id, 233 JabberIqType type, const char *id,
232 xmlnode *packet, gpointer data) 234 xmlnode *packet, gpointer data)
418 return; 420 return;
419 } 421 }
420 422
421 if (js->auth_mech && js->auth_mech->handle_challenge) { 423 if (js->auth_mech && js->auth_mech->handle_challenge) {
422 xmlnode *response = NULL; 424 xmlnode *response = NULL;
423 const char *msg = NULL; 425 char *msg = NULL;
424 JabberSaslState state = js->auth_mech->handle_challenge(js, packet, &response, &msg); 426 JabberSaslState state = js->auth_mech->handle_challenge(js, packet, &response, &msg);
425 if (state == JABBER_SASL_STATE_FAIL) { 427 if (state == JABBER_SASL_STATE_FAIL) {
426 purple_connection_error_reason(js->gc, 428 purple_connection_error_reason(js->gc,
427 PURPLE_CONNECTION_ERROR_AUTHENTICATION_IMPOSSIBLE, 429 PURPLE_CONNECTION_ERROR_AUTHENTICATION_IMPOSSIBLE,
428 msg ? msg : _("Invalid challenge from server")); 430 msg ? msg : _("Invalid challenge from server"));
429 } else if (response) { 431 } else if (response) {
430 jabber_send(js, response); 432 jabber_send(js, response);
431 xmlnode_free(response); 433 xmlnode_free(response);
432 } 434 }
435
436 g_free(msg);
433 } else 437 } else
434 purple_debug_warning("jabber", "Received unexpected (and unhandled) <challenge/>\n"); 438 purple_debug_warning("jabber", "Received unexpected (and unhandled) <challenge/>\n");
435 } 439 }
436 440
437 void jabber_auth_handle_success(JabberStream *js, xmlnode *packet) 441 void jabber_auth_handle_success(JabberStream *js, xmlnode *packet)
444 _("Invalid response from server")); 448 _("Invalid response from server"));
445 return; 449 return;
446 } 450 }
447 451
448 if (js->auth_mech && js->auth_mech->handle_success) { 452 if (js->auth_mech && js->auth_mech->handle_success) {
449 const char *msg = NULL; 453 char *msg = NULL;
450 JabberSaslState state = js->auth_mech->handle_success(js, packet, &msg); 454 JabberSaslState state = js->auth_mech->handle_success(js, packet, &msg);
451 455
452 if (state == JABBER_SASL_STATE_FAIL) { 456 if (state == JABBER_SASL_STATE_FAIL) {
453 purple_connection_error_reason(js->gc, 457 purple_connection_error_reason(js->gc,
454 PURPLE_CONNECTION_ERROR_AUTHENTICATION_IMPOSSIBLE, 458 PURPLE_CONNECTION_ERROR_AUTHENTICATION_IMPOSSIBLE,
458 purple_connection_error_reason(js->gc, 462 purple_connection_error_reason(js->gc,
459 PURPLE_CONNECTION_ERROR_AUTHENTICATION_IMPOSSIBLE, 463 PURPLE_CONNECTION_ERROR_AUTHENTICATION_IMPOSSIBLE,
460 msg ? msg : _("Server thinks authentication is complete, but client does not")); 464 msg ? msg : _("Server thinks authentication is complete, but client does not"));
461 return; 465 return;
462 } 466 }
467
468 g_free(msg);
463 } 469 }
464 470
465 /* 471 /*
466 * The stream will be reinitialized later in jabber_recv_cb_ssl() or 472 * The stream will be reinitialized later in jabber_recv_cb_ssl() or
467 * jabber_bosh_connection_send. 473 * jabber_bosh_connection_send.
471 } 477 }
472 478
473 void jabber_auth_handle_failure(JabberStream *js, xmlnode *packet) 479 void jabber_auth_handle_failure(JabberStream *js, xmlnode *packet)
474 { 480 {
475 PurpleConnectionError reason = PURPLE_CONNECTION_ERROR_NETWORK_ERROR; 481 PurpleConnectionError reason = PURPLE_CONNECTION_ERROR_NETWORK_ERROR;
476 char *msg; 482 char *msg = NULL;
477 483
478 if (js->auth_mech && js->auth_mech->handle_failure) { 484 if (js->auth_mech && js->auth_mech->handle_failure) {
479 xmlnode *stanza = NULL; 485 xmlnode *stanza = NULL;
480 const char *msg = NULL;
481 JabberSaslState state = js->auth_mech->handle_failure(js, packet, &stanza, &msg); 486 JabberSaslState state = js->auth_mech->handle_failure(js, packet, &stanza, &msg);
482 487
483 if (state != JABBER_SASL_STATE_FAIL && stanza) { 488 if (state != JABBER_SASL_STATE_FAIL && stanza) {
484 jabber_send(js, stanza); 489 jabber_send(js, stanza);
485 xmlnode_free(stanza); 490 xmlnode_free(stanza);
486 return; 491 return;
487 } 492 }
488 } 493 }
489 494
490 msg = jabber_parse_error(js, packet, &reason); 495 if (!msg)
491 if(!msg) { 496 msg = jabber_parse_error(js, packet, &reason);
497
498 if (!msg) {
492 purple_connection_error_reason(js->gc, 499 purple_connection_error_reason(js->gc,
493 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, 500 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
494 _("Invalid response from server")); 501 _("Invalid response from server"));
495 } else { 502 } else {
496 purple_connection_error_reason(js->gc, reason, msg); 503 purple_connection_error_reason(js->gc, reason, msg);