diff --git a/src/main/java/eu/siacs/conversations/entities/Account.java b/src/main/java/eu/siacs/conversations/entities/Account.java
index 88e218d10..8feffae2a 100644
--- a/src/main/java/eu/siacs/conversations/entities/Account.java
+++ b/src/main/java/eu/siacs/conversations/entities/Account.java
@@ -115,6 +115,7 @@ public class Account extends AbstractEntity {
UNAUTHORIZED(true),
SERVER_NOT_FOUND(true),
REGISTRATION_FAILED(true),
+ REGISTRATION_WEB(true),
REGISTRATION_CONFLICT(true),
REGISTRATION_SUCCESSFUL,
REGISTRATION_NOT_SUPPORTED(true),
@@ -164,6 +165,8 @@ public class Account extends AbstractEntity {
return R.string.account_status_no_internet;
case REGISTRATION_FAILED:
return R.string.account_status_regis_fail;
+ case REGISTRATION_WEB:
+ return R.string.account_status_regis_web;
case REGISTRATION_CONFLICT:
return R.string.account_status_regis_conflict;
case REGISTRATION_SUCCESSFUL:
diff --git a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java
index aa9584f10..f17337e86 100644
--- a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java
@@ -129,6 +129,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
public void onClick(final View v) {
final String password = mPassword.getText().toString();
final String passwordConfirm = mPasswordConfirm.getText().toString();
+ final boolean wasDisabled = mAccount != null && mAccount.getStatus() == Account.State.DISABLED;
if (!mInitMode && passwordChangedInMagicCreateMode()) {
gotoChangePassword(password);
@@ -150,6 +151,19 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
mAccountJid.requestFocus();
return;
}
+
+ XmppConnection connection = mAccount == null ? null : mAccount.getXmppConnection();
+ String url = connection != null && mAccount.getStatus() == Account.State.REGISTRATION_WEB ? connection.getWebRegistrationUrl() : null;
+ if (url != null && registerNewAccount && !wasDisabled) {
+ try {
+ startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
+ return;
+ } catch (ActivityNotFoundException e) {
+ Toast.makeText(EditAccountActivity.this,R.string.application_found_to_open_website,Toast.LENGTH_SHORT);
+ return;
+ }
+ }
+
final Jid jid;
try {
if (mUsernameMode) {
@@ -437,7 +451,13 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
this.mSaveButton.setText(R.string.connect);
}
} else {
- this.mSaveButton.setText(R.string.next);
+ XmppConnection connection = mAccount == null ? null : mAccount.getXmppConnection();
+ String url = connection != null && mAccount.getStatus() == Account.State.REGISTRATION_WEB ? connection.getWebRegistrationUrl() : null;
+ if (url != null && mRegisterNew.isChecked()) {
+ this.mSaveButton.setText(R.string.open_website);
+ } else {
+ this.mSaveButton.setText(R.string.next);
+ }
}
}
}
diff --git a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java
index 57fb158e1..309e3dbfe 100644
--- a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java
+++ b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java
@@ -40,6 +40,7 @@ import java.util.List;
import java.util.Map.Entry;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
+import java.util.regex.Matcher;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.KeyManager;
@@ -67,6 +68,7 @@ import eu.siacs.conversations.generator.IqGenerator;
import eu.siacs.conversations.services.NotificationService;
import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.utils.DNSHelper;
+import eu.siacs.conversations.utils.Patterns;
import eu.siacs.conversations.utils.SSLSocketHelper;
import eu.siacs.conversations.utils.SocksSocketFactory;
import eu.siacs.conversations.xml.Element;
@@ -137,6 +139,7 @@ public class XmppConnection implements Runnable {
private final XmppConnectionService mXmppConnectionService;
private SaslMechanism saslMechanism;
+ private String webRegistrationUrl = null;
private class MyKeyManager implements X509KeyManager {
@Override
@@ -438,7 +441,7 @@ public class XmppConnection implements Runnable {
}
}
} else {
- Log.d(Config.LOGTAG,account.getJid().toBareJid()+": not force closing socket and releasing wake lock because thread was interrupted");
+ Log.d(Config.LOGTAG,account.getJid().toBareJid()+": not force closing socket and releasing wake lock (is held="+wakeLock.isHeld()+") because thread was interrupted");
}
}
}
@@ -976,19 +979,38 @@ public class XmppConnection implements Runnable {
}
if (failed) {
- final Element instructions = packet.query().findChild("instructions");
- setAccountCreationFailed((instructions != null) ? instructions.getContent() : "");
+ final Element query = packet.query();
+ final String instructions = query.findChildContent("instructions");
+ final Element oob = query.findChild("x",Namespace.OOB);
+ final String url = oob == null ? null : oob.findChildContent("url");
+ if (url == null && instructions != null) {
+ Matcher matcher = Patterns.AUTOLINK_WEB_URL.matcher(instructions);
+ if (matcher.find()) {
+ setAccountCreationFailed(instructions.substring(matcher.start(),matcher.end()));
+ } else {
+ setAccountCreationFailed(null);
+ }
+ } else {
+ setAccountCreationFailed(url);
+ }
}
}
});
}
- private void setAccountCreationFailed(String instructions) {
- changeStatus(Account.State.REGISTRATION_FAILED);
+ private void setAccountCreationFailed(String url) {
+ if (url != null && (url.toLowerCase().startsWith("http://") || url.toLowerCase().startsWith("https://"))) {
+ changeStatus(Account.State.REGISTRATION_WEB);
+ this.webRegistrationUrl = url;
+ } else {
+ changeStatus(Account.State.REGISTRATION_FAILED);
+ }
disconnect(true);
- Log.d(Config.LOGTAG, account.getJid().toBareJid()
- + ": could not register. instructions are"
- + instructions);
+ Log.d(Config.LOGTAG, account.getJid().toBareJid()+": could not register. url="+url);
+ }
+
+ public String getWebRegistrationUrl() {
+ return this.webRegistrationUrl;
}
public void resetEverything() {
@@ -996,6 +1018,7 @@ public class XmppConnection implements Runnable {
resetStreamId();
clearIqCallbacks();
mStanzaQueue.clear();
+ this.webRegistrationUrl = null;
synchronized (this.disco) {
disco.clear();
}
diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml
index 7319f5c89..ccd556b2c 100644
--- a/src/main/res/values/strings.xml
+++ b/src/main/res/values/strings.xml
@@ -749,4 +749,7 @@
Retry decryption
Session failure
Downgraded SASL mechanism
+ Server requires registration on website
+ Open website
+ No application found to open website