libpurple/protocols/jabber/auth_cyrus.c

branch
soc.2008.masterpassword
changeset 34111
85b5efb9a873
parent 34091
9a23c6eaec25
parent 33811
5ab172aeeff2
child 34440
83610e0823fb
child 34935
686fa55b0deb
--- a/libpurple/protocols/jabber/auth_cyrus.c	Mon Mar 18 11:53:11 2013 +0100
+++ b/libpurple/protocols/jabber/auth_cyrus.c	Mon Mar 18 12:50:51 2013 +0100
@@ -176,6 +176,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)
 {
@@ -297,14 +316,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;
 				}
 
@@ -541,15 +554,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);

mercurial