offer to open website if ibb offers oob redirect. fixes #2503

This commit is contained in:
Daniel Gultsch 2017-06-19 20:02:41 +02:00
parent 95405fde5f
commit 5d9d725446
4 changed files with 58 additions and 9 deletions

View file

@ -115,6 +115,7 @@ public class Account extends AbstractEntity {
UNAUTHORIZED(true), UNAUTHORIZED(true),
SERVER_NOT_FOUND(true), SERVER_NOT_FOUND(true),
REGISTRATION_FAILED(true), REGISTRATION_FAILED(true),
REGISTRATION_WEB(true),
REGISTRATION_CONFLICT(true), REGISTRATION_CONFLICT(true),
REGISTRATION_SUCCESSFUL, REGISTRATION_SUCCESSFUL,
REGISTRATION_NOT_SUPPORTED(true), REGISTRATION_NOT_SUPPORTED(true),
@ -164,6 +165,8 @@ public class Account extends AbstractEntity {
return R.string.account_status_no_internet; return R.string.account_status_no_internet;
case REGISTRATION_FAILED: case REGISTRATION_FAILED:
return R.string.account_status_regis_fail; return R.string.account_status_regis_fail;
case REGISTRATION_WEB:
return R.string.account_status_regis_web;
case REGISTRATION_CONFLICT: case REGISTRATION_CONFLICT:
return R.string.account_status_regis_conflict; return R.string.account_status_regis_conflict;
case REGISTRATION_SUCCESSFUL: case REGISTRATION_SUCCESSFUL:

View file

@ -129,6 +129,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
public void onClick(final View v) { public void onClick(final View v) {
final String password = mPassword.getText().toString(); final String password = mPassword.getText().toString();
final String passwordConfirm = mPasswordConfirm.getText().toString(); final String passwordConfirm = mPasswordConfirm.getText().toString();
final boolean wasDisabled = mAccount != null && mAccount.getStatus() == Account.State.DISABLED;
if (!mInitMode && passwordChangedInMagicCreateMode()) { if (!mInitMode && passwordChangedInMagicCreateMode()) {
gotoChangePassword(password); gotoChangePassword(password);
@ -150,6 +151,19 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
mAccountJid.requestFocus(); mAccountJid.requestFocus();
return; 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; final Jid jid;
try { try {
if (mUsernameMode) { if (mUsernameMode) {
@ -437,7 +451,13 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
this.mSaveButton.setText(R.string.connect); this.mSaveButton.setText(R.string.connect);
} }
} else { } 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);
}
} }
} }
} }

View file

@ -40,6 +40,7 @@ import java.util.List;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Matcher;
import javax.net.ssl.HostnameVerifier; import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.KeyManager; 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.NotificationService;
import eu.siacs.conversations.services.XmppConnectionService; import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.utils.DNSHelper; import eu.siacs.conversations.utils.DNSHelper;
import eu.siacs.conversations.utils.Patterns;
import eu.siacs.conversations.utils.SSLSocketHelper; import eu.siacs.conversations.utils.SSLSocketHelper;
import eu.siacs.conversations.utils.SocksSocketFactory; import eu.siacs.conversations.utils.SocksSocketFactory;
import eu.siacs.conversations.xml.Element; import eu.siacs.conversations.xml.Element;
@ -137,6 +139,7 @@ public class XmppConnection implements Runnable {
private final XmppConnectionService mXmppConnectionService; private final XmppConnectionService mXmppConnectionService;
private SaslMechanism saslMechanism; private SaslMechanism saslMechanism;
private String webRegistrationUrl = null;
private class MyKeyManager implements X509KeyManager { private class MyKeyManager implements X509KeyManager {
@Override @Override
@ -438,7 +441,7 @@ public class XmppConnection implements Runnable {
} }
} }
} else { } 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) { if (failed) {
final Element instructions = packet.query().findChild("instructions"); final Element query = packet.query();
setAccountCreationFailed((instructions != null) ? instructions.getContent() : ""); 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) { private void setAccountCreationFailed(String url) {
changeStatus(Account.State.REGISTRATION_FAILED); 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); disconnect(true);
Log.d(Config.LOGTAG, account.getJid().toBareJid() Log.d(Config.LOGTAG, account.getJid().toBareJid()+": could not register. url="+url);
+ ": could not register. instructions are" }
+ instructions);
public String getWebRegistrationUrl() {
return this.webRegistrationUrl;
} }
public void resetEverything() { public void resetEverything() {
@ -996,6 +1018,7 @@ public class XmppConnection implements Runnable {
resetStreamId(); resetStreamId();
clearIqCallbacks(); clearIqCallbacks();
mStanzaQueue.clear(); mStanzaQueue.clear();
this.webRegistrationUrl = null;
synchronized (this.disco) { synchronized (this.disco) {
disco.clear(); disco.clear();
} }

View file

@ -749,4 +749,7 @@
<string name="retry_decryption">Retry decryption</string> <string name="retry_decryption">Retry decryption</string>
<string name="session_failure">Session failure</string> <string name="session_failure">Session failure</string>
<string name="sasl_downgrade">Downgraded SASL mechanism</string> <string name="sasl_downgrade">Downgraded SASL mechanism</string>
<string name="account_status_regis_web">Server requires registration on website</string>
<string name="open_website">Open website</string>
<string name="application_found_to_open_website">No application found to open website</string>
</resources> </resources>