support sasl/temporary-auth-failure

Daniel Gultsch created

if the server is unable to query the database throwing a temporary-auth-failure
might be more appropriate

Change summary

src/main/java/eu/siacs/conversations/entities/Account.java    |  3 
src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java | 23 +++-
src/main/res/values/strings.xml                               |  1 
3 files changed, 19 insertions(+), 8 deletions(-)

Detailed changes

src/main/java/eu/siacs/conversations/entities/Account.java 🔗

@@ -627,6 +627,7 @@ public class Account extends AbstractEntity implements AvatarService.Avatarable
         ONLINE(false),
         NO_INTERNET(false),
         UNAUTHORIZED,
+        TEMPORARY_AUTH_FAILURE,
         SERVER_NOT_FOUND,
         REGISTRATION_SUCCESSFUL(false),
         REGISTRATION_FAILED(true, false),
@@ -732,6 +733,8 @@ public class Account extends AbstractEntity implements AvatarService.Avatarable
                     return R.string.payment_required;
                 case MISSING_INTERNET_PERMISSION:
                     return R.string.missing_internet_permission;
+                case TEMPORARY_AUTH_FAILURE:
+                    return R.string.account_status_temporary_auth_failure;
                 default:
                     return R.string.account_status_unknown;
             }

src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java 🔗

@@ -12,6 +12,8 @@ import android.util.SparseArray;
 
 import androidx.annotation.NonNull;
 
+import com.google.common.base.Strings;
+
 import org.xmlpull.v1.XmlPullParserException;
 
 import java.io.ByteArrayInputStream;
@@ -489,20 +491,25 @@ public class XmppConnection implements Runnable {
             } else if (nextTag.isStart("failure")) {
                 final Element failure = tagReader.readElement(nextTag);
                 if (Namespace.SASL.equals(failure.getNamespace())) {
-                    final String text = failure.findChildContent("text");
-                    if (failure.hasChild("account-disabled") && text != null) {
-                        Matcher matcher = Patterns.AUTOLINK_WEB_URL.matcher(text);
+                    if (failure.hasChild("temporary-auth-failure")) {
+                        throw new StateChangingException(Account.State.TEMPORARY_AUTH_FAILURE);
+                    } else if (failure.hasChild("account-disabled")) {
+                        final String text = failure.findChildContent("text");
+                        if ( Strings.isNullOrEmpty(text)) {
+                            throw new StateChangingException(Account.State.UNAUTHORIZED);
+                        }
+                        final Matcher matcher = Patterns.AUTOLINK_WEB_URL.matcher(text);
                         if (matcher.find()) {
                             final HttpUrl url;
                             try {
                                 url = HttpUrl.get(text.substring(matcher.start(), matcher.end()));
-                                if (url.isHttps()) {
-                                    this.redirectionUrl = url;
-                                    throw new StateChangingException(Account.State.PAYMENT_REQUIRED);
-                                }
-                            } catch (IllegalArgumentException e) {
+                            } catch (final IllegalArgumentException e) {
                                 throw new StateChangingException(Account.State.UNAUTHORIZED);
                             }
+                            if (url.isHttps()) {
+                                this.redirectionUrl = url;
+                                throw new StateChangingException(Account.State.PAYMENT_REQUIRED);
+                            }
                         }
                     }
                     throw new StateChangingException(Account.State.UNAUTHORIZED);

src/main/res/values/strings.xml 🔗

@@ -976,5 +976,6 @@
     <string name="plain_text_document">Plain text document</string>
     <string name="account_registrations_are_not_supported">Account registrations are not supported</string>
     <string name="no_xmpp_adddress_found">No XMPP address found</string>
+    <string name="account_status_temporary_auth_failure">Temporary authentication failure</string>
 
 </resources>