migrate redirection urls to HttpUrl
This commit is contained in:
parent
739d20428a
commit
1cd95aefa6
|
@ -38,7 +38,6 @@ import com.google.common.base.CharMatcher;
|
||||||
|
|
||||||
import org.openintents.openpgp.util.OpenPgpUtils;
|
import org.openintents.openpgp.util.OpenPgpUtils;
|
||||||
|
|
||||||
import java.net.URL;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -78,6 +77,7 @@ import eu.siacs.conversations.xmpp.XmppConnection;
|
||||||
import eu.siacs.conversations.xmpp.XmppConnection.Features;
|
import eu.siacs.conversations.xmpp.XmppConnection.Features;
|
||||||
import eu.siacs.conversations.xmpp.forms.Data;
|
import eu.siacs.conversations.xmpp.forms.Data;
|
||||||
import eu.siacs.conversations.xmpp.pep.Avatar;
|
import eu.siacs.conversations.xmpp.pep.Avatar;
|
||||||
|
import okhttp3.HttpUrl;
|
||||||
|
|
||||||
public class EditAccountActivity extends OmemoActivity implements OnAccountUpdate, OnUpdateBlocklist,
|
public class EditAccountActivity extends OmemoActivity implements OnAccountUpdate, OnUpdateBlocklist,
|
||||||
OnKeyStatusUpdated, OnCaptchaRequested, KeyChainAliasCallback, XmppConnectionService.OnShowErrorToast, XmppConnectionService.OnMamPreferencesFetched {
|
OnKeyStatusUpdated, OnCaptchaRequested, KeyChainAliasCallback, XmppConnectionService.OnShowErrorToast, XmppConnectionService.OnMamPreferencesFetched {
|
||||||
|
@ -188,7 +188,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
|
||||||
final boolean openRegistrationUrl = registerNewAccount && !accountInfoEdited && mAccount != null && mAccount.getStatus() == Account.State.REGISTRATION_WEB;
|
final boolean openRegistrationUrl = registerNewAccount && !accountInfoEdited && mAccount != null && mAccount.getStatus() == Account.State.REGISTRATION_WEB;
|
||||||
final boolean openPaymentUrl = mAccount != null && mAccount.getStatus() == Account.State.PAYMENT_REQUIRED;
|
final boolean openPaymentUrl = mAccount != null && mAccount.getStatus() == Account.State.PAYMENT_REQUIRED;
|
||||||
final boolean redirectionWorthyStatus = openPaymentUrl || openRegistrationUrl;
|
final boolean redirectionWorthyStatus = openPaymentUrl || openRegistrationUrl;
|
||||||
URL url = connection != null && redirectionWorthyStatus ? connection.getRedirectionUrl() : null;
|
final HttpUrl url = connection != null && redirectionWorthyStatus ? connection.getRedirectionUrl() : null;
|
||||||
if (url != null && !wasDisabled) {
|
if (url != null && !wasDisabled) {
|
||||||
try {
|
try {
|
||||||
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url.toString())));
|
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url.toString())));
|
||||||
|
@ -531,7 +531,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
XmppConnection connection = mAccount == null ? null : mAccount.getXmppConnection();
|
XmppConnection connection = mAccount == null ? null : mAccount.getXmppConnection();
|
||||||
URL url = connection != null && mAccount.getStatus() == Account.State.PAYMENT_REQUIRED ? connection.getRedirectionUrl() : null;
|
HttpUrl url = connection != null && mAccount.getStatus() == Account.State.PAYMENT_REQUIRED ? connection.getRedirectionUrl() : null;
|
||||||
if (url != null) {
|
if (url != null) {
|
||||||
this.binding.saveButton.setText(R.string.open_website);
|
this.binding.saveButton.setText(R.string.open_website);
|
||||||
} else if (inNeedOfSaslAccept()) {
|
} else if (inNeedOfSaslAccept()) {
|
||||||
|
@ -542,7 +542,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
XmppConnection connection = mAccount == null ? null : mAccount.getXmppConnection();
|
XmppConnection connection = mAccount == null ? null : mAccount.getXmppConnection();
|
||||||
URL url = connection != null && mAccount.getStatus() == Account.State.REGISTRATION_WEB ? connection.getRedirectionUrl() : null;
|
HttpUrl url = connection != null && mAccount.getStatus() == Account.State.REGISTRATION_WEB ? connection.getRedirectionUrl() : null;
|
||||||
if (url != null && this.binding.accountRegisterNew.isChecked() && !accountInfoEdited) {
|
if (url != null && this.binding.accountRegisterNew.isChecked() && !accountInfoEdited) {
|
||||||
this.binding.saveButton.setText(R.string.open_website);
|
this.binding.saveButton.setText(R.string.open_website);
|
||||||
} else {
|
} else {
|
||||||
|
@ -736,7 +736,8 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onNewIntent(Intent intent) {
|
public void onNewIntent(final Intent intent) {
|
||||||
|
super.onNewIntent(intent);
|
||||||
if (intent != null && intent.getData() != null) {
|
if (intent != null && intent.getData() != null) {
|
||||||
final XmppUri uri = new XmppUri(intent.getData());
|
final XmppUri uri = new XmppUri(intent.getData());
|
||||||
if (xmppConnectionServiceBound) {
|
if (xmppConnectionServiceBound) {
|
||||||
|
|
|
@ -32,7 +32,7 @@ public class XmppUri {
|
||||||
private Map<String, String> parameters = Collections.emptyMap();
|
private Map<String, String> parameters = Collections.emptyMap();
|
||||||
private boolean safeSource = true;
|
private boolean safeSource = true;
|
||||||
|
|
||||||
public XmppUri(String uri) {
|
public XmppUri(final String uri) {
|
||||||
try {
|
try {
|
||||||
parse(Uri.parse(uri));
|
parse(Uri.parse(uri));
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
|
|
|
@ -21,7 +21,6 @@ import java.net.ConnectException;
|
||||||
import java.net.IDN;
|
import java.net.IDN;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
|
@ -102,6 +101,7 @@ import eu.siacs.conversations.xmpp.stanzas.streammgmt.AckPacket;
|
||||||
import eu.siacs.conversations.xmpp.stanzas.streammgmt.EnablePacket;
|
import eu.siacs.conversations.xmpp.stanzas.streammgmt.EnablePacket;
|
||||||
import eu.siacs.conversations.xmpp.stanzas.streammgmt.RequestPacket;
|
import eu.siacs.conversations.xmpp.stanzas.streammgmt.RequestPacket;
|
||||||
import eu.siacs.conversations.xmpp.stanzas.streammgmt.ResumePacket;
|
import eu.siacs.conversations.xmpp.stanzas.streammgmt.ResumePacket;
|
||||||
|
import okhttp3.HttpUrl;
|
||||||
|
|
||||||
public class XmppConnection implements Runnable {
|
public class XmppConnection implements Runnable {
|
||||||
|
|
||||||
|
@ -172,7 +172,7 @@ public class XmppConnection implements Runnable {
|
||||||
private OnBindListener bindListener = null;
|
private OnBindListener bindListener = null;
|
||||||
private OnMessageAcknowledged acknowledgedListener = null;
|
private OnMessageAcknowledged acknowledgedListener = null;
|
||||||
private SaslMechanism saslMechanism;
|
private SaslMechanism saslMechanism;
|
||||||
private URL redirectionUrl = null;
|
private HttpUrl redirectionUrl = null;
|
||||||
private String verifiedHostname = null;
|
private String verifiedHostname = null;
|
||||||
private volatile Thread mThread;
|
private volatile Thread mThread;
|
||||||
private CountDownLatch mStreamCountDownLatch;
|
private CountDownLatch mStreamCountDownLatch;
|
||||||
|
@ -383,9 +383,7 @@ public class XmppConnection implements Runnable {
|
||||||
this.changeStatus(Account.State.MISSING_INTERNET_PERMISSION);
|
this.changeStatus(Account.State.MISSING_INTERNET_PERMISSION);
|
||||||
} catch (final StateChangingException e) {
|
} catch (final StateChangingException e) {
|
||||||
this.changeStatus(e.state);
|
this.changeStatus(e.state);
|
||||||
} catch (final UnknownHostException | ConnectException e) {
|
} catch (final UnknownHostException | ConnectException | SocksSocketFactory.HostNotFoundException e) {
|
||||||
this.changeStatus(Account.State.SERVER_NOT_FOUND);
|
|
||||||
} catch (final SocksSocketFactory.HostNotFoundException e) {
|
|
||||||
this.changeStatus(Account.State.SERVER_NOT_FOUND);
|
this.changeStatus(Account.State.SERVER_NOT_FOUND);
|
||||||
} catch (final SocksSocketFactory.SocksProxyNotFoundException e) {
|
} catch (final SocksSocketFactory.SocksProxyNotFoundException e) {
|
||||||
this.changeStatus(Account.State.TOR_NOT_AVAILABLE);
|
this.changeStatus(Account.State.TOR_NOT_AVAILABLE);
|
||||||
|
@ -498,13 +496,14 @@ public class XmppConnection implements Runnable {
|
||||||
if (failure.hasChild("account-disabled") && text != null) {
|
if (failure.hasChild("account-disabled") && text != null) {
|
||||||
Matcher matcher = Patterns.AUTOLINK_WEB_URL.matcher(text);
|
Matcher matcher = Patterns.AUTOLINK_WEB_URL.matcher(text);
|
||||||
if (matcher.find()) {
|
if (matcher.find()) {
|
||||||
|
final HttpUrl url;
|
||||||
try {
|
try {
|
||||||
URL url = new URL(text.substring(matcher.start(), matcher.end()));
|
url = HttpUrl.get(text.substring(matcher.start(), matcher.end()));
|
||||||
if (url.getProtocol().equals("https")) {
|
if (url.isHttps()) {
|
||||||
this.redirectionUrl = url;
|
this.redirectionUrl = url;
|
||||||
throw new StateChangingException(Account.State.PAYMENT_REQUIRED);
|
throw new StateChangingException(Account.State.PAYMENT_REQUIRED);
|
||||||
}
|
}
|
||||||
} catch (MalformedURLException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
throw new StateChangingException(Account.State.UNAUTHORIZED);
|
throw new StateChangingException(Account.State.UNAUTHORIZED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -975,8 +974,8 @@ public class XmppConnection implements Runnable {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
Field field = data.getFieldByName("url");
|
final Field field = data.getFieldByName("url");
|
||||||
URL url = field != null && field.getValue() != null ? new URL(field.getValue()) : null;
|
final URL url = field != null && field.getValue() != null ? new URL(field.getValue()) : null;
|
||||||
is = url != null ? url.openStream() : null;
|
is = url != null ? url.openStream() : null;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
is = null;
|
is = null;
|
||||||
|
@ -1001,7 +1000,7 @@ public class XmppConnection implements Runnable {
|
||||||
if (url != null) {
|
if (url != null) {
|
||||||
setAccountCreationFailed(url);
|
setAccountCreationFailed(url);
|
||||||
} else if (instructions != null) {
|
} else if (instructions != null) {
|
||||||
Matcher matcher = Patterns.AUTOLINK_WEB_URL.matcher(instructions);
|
final Matcher matcher = Patterns.AUTOLINK_WEB_URL.matcher(instructions);
|
||||||
if (matcher.find()) {
|
if (matcher.find()) {
|
||||||
setAccountCreationFailed(instructions.substring(matcher.start(), matcher.end()));
|
setAccountCreationFailed(instructions.substring(matcher.start(), matcher.end()));
|
||||||
}
|
}
|
||||||
|
@ -1011,21 +1010,16 @@ public class XmppConnection implements Runnable {
|
||||||
}, true);
|
}, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setAccountCreationFailed(String url) {
|
private void setAccountCreationFailed(final String url) {
|
||||||
if (url != null) {
|
final HttpUrl httpUrl = url == null ? null : HttpUrl.parse(url);
|
||||||
try {
|
if (httpUrl != null && httpUrl.isHttps()) {
|
||||||
this.redirectionUrl = new URL(url);
|
this.redirectionUrl = httpUrl;
|
||||||
if (this.redirectionUrl.getProtocol().equals("https")) {
|
throw new StateChangingError(Account.State.REGISTRATION_WEB);
|
||||||
throw new StateChangingError(Account.State.REGISTRATION_WEB);
|
|
||||||
}
|
|
||||||
} catch (MalformedURLException e) {
|
|
||||||
//fall through
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
throw new StateChangingError(Account.State.REGISTRATION_FAILED);
|
throw new StateChangingError(Account.State.REGISTRATION_FAILED);
|
||||||
}
|
}
|
||||||
|
|
||||||
public URL getRedirectionUrl() {
|
public HttpUrl getRedirectionUrl() {
|
||||||
return this.redirectionUrl;
|
return this.redirectionUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue