comparison libpurple/protocols/jabber/auth.c @ 28514:5328e205d3fb

jabber: Use purple_strequal to simplify some auth code
author Paul Aurich <paul@darkrain42.org>
date Fri, 06 Nov 2009 08:47:28 +0000
parents fa7f3426ed13
children 4fd0baa32a9e
comparison
equal deleted inserted replaced
28513:fa7f3426ed13 28514:5328e205d3fb
509 #ifdef HAVE_CYRUS_SASL 509 #ifdef HAVE_CYRUS_SASL
510 /* Don't include Google Talk's X-GOOGLE-TOKEN mechanism, as we will not 510 /* Don't include Google Talk's X-GOOGLE-TOKEN mechanism, as we will not
511 * support it and including it gives a false fall-back to other mechs offerred, 511 * support it and including it gives a false fall-back to other mechs offerred,
512 * leading to incorrect error handling. 512 * leading to incorrect error handling.
513 */ 513 */
514 if (mech_name && !strcmp(mech_name, "X-GOOGLE-TOKEN")) { 514 if (purple_strequal(mech_name, "X-GOOGLE-TOKEN")) {
515 g_free(mech_name); 515 g_free(mech_name);
516 continue; 516 continue;
517 } 517 }
518 518
519 g_string_append(js->sasl_mechs, mech_name); 519 g_string_append(js->sasl_mechs, mech_name);
520 g_string_append_c(js->sasl_mechs, ' '); 520 g_string_append_c(js->sasl_mechs, ' ');
521 #else 521 #else
522 if(mech_name && !strcmp(mech_name, "DIGEST-MD5")) 522 if (purple_strequal(mech_name, "DIGEST-MD5"))
523 digest_md5 = TRUE; 523 digest_md5 = TRUE;
524 else if(mech_name && !strcmp(mech_name, "PLAIN")) 524 else if (purple_strequal(mech_name, "PLAIN"))
525 plain = TRUE; 525 plain = TRUE;
526 #endif 526 #endif
527 g_free(mech_name); 527 g_free(mech_name);
528 } 528 }
529 529
584 const char *err_code; 584 const char *err_code;
585 585
586 /* FIXME: Why is this not in jabber_parse_error? */ 586 /* FIXME: Why is this not in jabber_parse_error? */
587 if((error = xmlnode_get_child(packet, "error")) && 587 if((error = xmlnode_get_child(packet, "error")) &&
588 (err_code = xmlnode_get_attrib(error, "code")) && 588 (err_code = xmlnode_get_attrib(error, "code")) &&
589 !strcmp(err_code, "401")) { 589 g_str_equal(err_code, "401")) {
590 reason = PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED; 590 reason = PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED;
591 /* Clear the pasword if it isn't being saved */ 591 /* Clear the pasword if it isn't being saved */
592 if (!purple_account_get_remember_password(js->gc->account)) 592 if (!purple_account_get_remember_password(js->gc->account))
593 purple_account_set_password(js->gc->account, NULL); 593 purple_account_set_password(js->gc->account, NULL);
594 } 594 }
885 885
886 if (g_hash_table_lookup(parts, "rspauth")) { 886 if (g_hash_table_lookup(parts, "rspauth")) {
887 char *rspauth = g_hash_table_lookup(parts, "rspauth"); 887 char *rspauth = g_hash_table_lookup(parts, "rspauth");
888 888
889 889
890 if(rspauth && js->expected_rspauth && 890 if (rspauth && purple_strequal(rspauth, js->expected_rspauth)) {
891 !strcmp(rspauth, js->expected_rspauth)) {
892 jabber_send_raw(js, 891 jabber_send_raw(js,
893 "<response xmlns='urn:ietf:params:xml:ns:xmpp-sasl' />", 892 "<response xmlns='urn:ietf:params:xml:ns:xmpp-sasl' />",
894 -1); 893 -1);
895 } else { 894 } else {
896 purple_connection_error_reason(js->gc, 895 purple_connection_error_reason(js->gc,
1012 * 1011 *
1013 * My reading of the digestmd5 plugin indicates the username and 1012 * My reading of the digestmd5 plugin indicates the username and
1014 * realm are always encoded in UTF-8 (they seem to be the values 1013 * realm are always encoded in UTF-8 (they seem to be the values
1015 * we pass in), so we need to ensure charset=utf-8 is set. 1014 * we pass in), so we need to ensure charset=utf-8 is set.
1016 */ 1015 */
1017 if (!js->current_mech || !g_str_equal(js->current_mech, "DIGEST-MD5") || 1016 if (!purple_strequal(js->current_mech, "DIGEST-MD5") ||
1018 strstr(c_out, ",charset=")) 1017 strstr(c_out, ",charset="))
1019 /* If we're not using DIGEST-MD5 or Cyrus SASL is fixed */ 1018 /* If we're not using DIGEST-MD5 or Cyrus SASL is fixed */
1020 enc_out = purple_base64_encode((unsigned char*)c_out, clen); 1019 enc_out = purple_base64_encode((unsigned char*)c_out, clen);
1021 else { 1020 else {
1022 char *tmp = g_strdup_printf("%s,charset=utf-8", c_out); 1021 char *tmp = g_strdup_printf("%s,charset=utf-8", c_out);
1039 const char *ns = xmlnode_get_namespace(packet); 1038 const char *ns = xmlnode_get_namespace(packet);
1040 #ifdef HAVE_CYRUS_SASL 1039 #ifdef HAVE_CYRUS_SASL
1041 const void *x; 1040 const void *x;
1042 #endif 1041 #endif
1043 1042
1044 if(!ns || strcmp(ns, "urn:ietf:params:xml:ns:xmpp-sasl")) { 1043 if (!purple_strequal(ns, "urn:ietf:params:xml:ns:xmpp-sasl")) {
1045 purple_connection_error_reason(js->gc, 1044 purple_connection_error_reason(js->gc,
1046 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, 1045 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
1047 _("Invalid response from server")); 1046 _("Invalid response from server"));
1048 return; 1047 return;
1049 } 1048 }