--- a/libpurple/protocols/jabber/auth_cyrus.c Wed Feb 27 12:00:44 2013 +0100 +++ b/libpurple/protocols/jabber/auth_cyrus.c Sat Mar 02 10:55:03 2013 -0500 @@ -167,7 +167,6 @@ auth_no_pass_cb(PurpleConnection *gc, PurpleRequestFields *fields) { PurpleAccount *account; - JabberStream *js; /* The password prompt dialog doesn't get disposed if the account disconnects */ if (!PURPLE_CONNECTION_IS_VALID(gc)) @@ -179,6 +178,25 @@ purple_account_set_enabled(account, purple_core_get_ui(), FALSE); } +static gboolean remove_current_mech(JabberStream *js) { + char *pos; + if ((pos = strstr(js->sasl_mechs->str, js->current_mech))) { + int len = strlen(js->current_mech); + /* Clean up space that separated this Mech from the one before or after it */ + if (pos > js->sasl_mechs->str && *(pos - 1) == ' ') { + /* Handle removing space before when current_mech isn't the first mech in the list */ + pos--; + len++; + } else if (strlen(pos) > len && *(pos + len) == ' ') { + /* Handle removing space after */ + len++; + } + g_string_erase(js->sasl_mechs, pos - js->sasl_mechs->str, len); + return TRUE; + } + return FALSE; +} + static JabberSaslState jabber_auth_start_cyrus(JabberStream *js, xmlnode **reply, char **error) { @@ -300,14 +318,8 @@ * supported mechanisms. This code handles that case */ if (js->current_mech && *js->current_mech) { - char *pos; - if ((pos = strstr(js->sasl_mechs->str, js->current_mech))) { - g_string_erase(js->sasl_mechs, pos-js->sasl_mechs->str, strlen(js->current_mech)); - } - /* Remove space which separated this mech from the next */ - if ((js->sasl_mechs->str)[0] == ' ') { - g_string_erase(js->sasl_mechs, 0, 1); - } + remove_current_mech(js); + /* Should we only try again if we've removed the mech? */ again = TRUE; } @@ -546,15 +558,10 @@ { if (js->auth_fail_count++ < 5) { if (js->current_mech && *js->current_mech) { - char *pos; - if ((pos = strstr(js->sasl_mechs->str, js->current_mech))) { - g_string_erase(js->sasl_mechs, pos-js->sasl_mechs->str, strlen(js->current_mech)); - } - /* Remove space which separated this mech from the next */ - if ((js->sasl_mechs->str)[0] == ' ') { - g_string_erase(js->sasl_mechs, 0, 1); - } + remove_current_mech(js); } + + /* Should we only try again if we've actually removed a mech? */ if (*js->sasl_mechs->str) { /* If we have remaining mechs to try, do so */ sasl_dispose(&js->sasl);