<string name="auth_testing_connection">Testing connection…</string>
<string name="auth_not_configured_title">Malformed ownCloud configuration</string>
<string name="auth_not_configured_message">It seems that your ownCloud instance is not correctly configured. Contact your administrator for more details.</string>
- <string name="auth_unknown_error_title">Unknown error occurred</string>
+ <string name="auth_unknown_error_title">Unknown error occurred!</string>
<string name="auth_unknown_error_message">Unknown error occurred. Please contact authors and include logs from your device.</string>
- <string name="auth_unknow_host_title">Can\'t establish connection</string>
- <string name="auth_unknow_host_message">Couldn\'t establish connection to host. Please check hostname and server availability and try again.</string>
+ <string name="auth_unknown_host_title">Couldn\'t find host</string>
+ <string name="auth_unknown_host_message">Couldn\'t find the entered host. Please check hostname and server availability and try again.</string>
<string name="auth_incorrect_path_title">ownCloud instance not found</string>
<string name="auth_incorrect_path_message">Application couldn\'t find ownClound instance at given path. Please check your path and try again.</string>
- <string name="auth_secure_connection">Secure connection established</string>
- <string name="auth_unknow_error">Unknown error occurred!</string>
+ <string name="auth_timeout_title">The server took too long to respond</string>
+ <string name="auth_incorrect_address_title">Malformed URL</string>
+ <string name="auth_ssl_general_error_title">SSL initialization failed</string>
+ <string name="auth_ssl_unverified_server_title">Unverified SSL server\'s identity</string>
+ <string name="auth_bad_oc_version_title">Unrecognized ownCloud server version</string>
+ <string name="auth_wrong_connection_title">Couldn\'t establish connection</string>
+ <string name="auth_secure_connection">Secure connection established</string>
<string name="auth_login_details">Login details</string>
<string name="crashlog_message">Application terminated unexpectedly. Would you like to submit crash report?</string>
package com.owncloud.android.authenticator;
+import java.io.IOException;
import java.net.ConnectException;
+import java.net.MalformedURLException;
+import java.net.SocketException;
import java.net.SocketTimeoutException;
+import java.net.URI;
+import java.net.URL;
import java.net.UnknownHostException;
+import javax.net.ssl.SSLException;
import javax.net.ssl.SSLHandshakeException;
+import javax.net.ssl.SSLPeerUnverifiedException;
+import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.GetMethod;
import org.json.JSONException;
}
if (mUrl.startsWith("http://") || mUrl.startsWith("https://")) {
mLatestResult = (mUrl.startsWith("https://"))? ResultType.OK_SSL : ResultType.OK_NO_SSL;
- tryConnection(Uri.parse(mUrl + AccountUtils.STATUS_PATH));
+ tryConnection(mUrl + AccountUtils.STATUS_PATH);
postResult(mLatestResult);
} else {
- Uri uri = Uri.parse("https://" + mUrl + AccountUtils.STATUS_PATH);
- if (tryConnection(uri)) {
+ if (tryConnection("https://" + mUrl + AccountUtils.STATUS_PATH)) {
postResult(ResultType.OK_SSL);
return;
}
Log.d(TAG,
"establishing secure connection failed, trying non secure connection");
- uri = Uri.parse("http://" + mUrl + AccountUtils.STATUS_PATH);
- if (tryConnection(uri)) {
+ if (tryConnection("http://" + mUrl + AccountUtils.STATUS_PATH)) {
postResult(ResultType.OK_NO_SSL);
return;
}
return mOCVersion;
}
- private boolean tryConnection(Uri uri) {
- WebdavClient wc = new WebdavClient();
- wc.allowSelfsignedCertificates();
- GetMethod get = new GetMethod(uri.toString());
+ private boolean tryConnection(String urlSt) {
boolean retval = false;
try {
+ WebdavClient wc = new WebdavClient();
+ wc.allowSelfsignedCertificates();
+ URL url = new URL(urlSt); // better than android.net.Uri in this case; provides URL validation
+ GetMethod get = new GetMethod(url.toString());
int status = wc.executeMethod(get, TRY_CONNECTION_TIMEOUT);
switch (status) {
case HttpStatus.SC_OK: {
break;
}
mOCVersion = new OwnCloudVersion(json.getString("version"));
- if (!mOCVersion.isVersionValid())
+ if (!mOCVersion.isVersionValid()) {
+ mLatestResult = ResultType.BAD_OC_VERSION;
break;
+ }
retval = true;
break;
}
Log.e(TAG, "Not handled status received from server: " + status);
}
+ } catch (JSONException e) {
+ mLatestResult = ResultType.INSTANCE_NOT_CONFIGURED;
+ Log.e(TAG, "JSON exception while trying connection (instance not configured) ", e);
+
+ } catch (SocketException e) {
+ mLatestResult = ResultType.WRONG_CONNECTION;
+ Log.e(TAG, "Socket exception while trying connection", e);
+
+ } catch (SocketTimeoutException e) {
+ mLatestResult = ResultType.TIMEOUT;
+ Log.e(TAG, "Socket timeout exception while trying connection", e);
+
+ } catch (MalformedURLException e) {
+ mLatestResult = ResultType.INCORRECT_ADDRESS;
+ Log.e(TAG, "Connect exception while trying connection", e);
+
+ } catch (UnknownHostException e) {
+ mLatestResult = ResultType.HOST_NOT_AVAILABLE;
+ Log.e(TAG, "Unknown host exception while trying connection", e);
+
+ } catch (SSLPeerUnverifiedException e) { // specially meaningful SSLException
+ mLatestResult = ResultType.SSL_UNVERIFIED_SERVER;
+ Log.e(TAG, "SSL Peer Unverified exception while trying connection", e);
+
+ } catch (SSLException e) {
+ mLatestResult = ResultType.SSL_INIT_ERROR;
+ Log.e(TAG, "SSL exception while trying connection", e);
+
+ } catch (HttpException e) { // specific exceptions from org.apache.commons.httpclient
+ mLatestResult = ResultType.UNKNOWN_ERROR;
+ Log.e(TAG, "HTTP exception while trying connection", e);
+
+ } catch (IOException e) { // UnkownsServiceException, and any other weird I/O Exception that could occur
+ mLatestResult = ResultType.UNKNOWN_ERROR;
+ Log.e(TAG, "I/O exception while trying connection", e);
+
} catch (Exception e) {
- if (e instanceof UnknownHostException
- || e instanceof ConnectException
- || e instanceof SocketTimeoutException) {
- mLatestResult = ResultType.HOST_NOT_AVAILABLE;
- } else if (e instanceof JSONException) {
- mLatestResult = ResultType.INSTANCE_NOT_CONFIGURED;
- } else if (e instanceof SSLHandshakeException) {
- mLatestResult = ResultType.SSL_INIT_ERROR;
- } else {
- mLatestResult = ResultType.UNKNOWN_ERROR;
- }
- e.printStackTrace();
+ mLatestResult = ResultType.UNKNOWN_ERROR;
+ Log.e(TAG, "Unexpected exception while trying connection", e);
}
return retval;
\r
private void continueConnection(String prefix) {\r
String url = ((TextView) findViewById(R.id.host_URL)).getText()\r
- .toString();\r
+ .toString().trim();\r
String username = ((TextView) findViewById(R.id.account_username))\r
.getText().toString();\r
String password = ((TextView) findViewById(R.id.account_password))\r
mStatusIcon = android.R.drawable.ic_partial_secure;\r
}\r
break;\r
+ case BAD_OC_VERSION:\r
+ mStatusIcon = R.drawable.common_error;\r
+ mStatusText = R.string.auth_bad_oc_version_title;\r
+ break;\r
+ case WRONG_CONNECTION:\r
+ mStatusIcon = R.drawable.common_error;\r
+ mStatusText = R.string.auth_wrong_connection_title;\r
+ break;\r
case TIMEOUT:\r
- case INORRECT_ADDRESS:\r
+ mStatusIcon = R.drawable.common_error;\r
+ mStatusText = R.string.auth_timeout_title;\r
+ break;\r
+ case INCORRECT_ADDRESS:\r
+ mStatusIcon = R.drawable.common_error;\r
+ mStatusText = R.string.auth_incorrect_address_title;\r
+ break;\r
+ case SSL_UNVERIFIED_SERVER:\r
+ mStatusIcon = R.drawable.common_error;\r
+ mStatusText = R.string.auth_ssl_unverified_server_title;\r
+ break;\r
case SSL_INIT_ERROR:\r
+ mStatusIcon = R.drawable.common_error;\r
+ mStatusText = R.string.auth_ssl_general_error_title;\r
+ break;\r
case HOST_NOT_AVAILABLE:\r
mStatusIcon = R.drawable.common_error;\r
- mStatusText = R.string.auth_unknow_host_title;\r
+ mStatusText = R.string.auth_unknown_host_title;\r
break;\r
case NO_NETWORK_CONNECTION:\r
mStatusIcon = R.drawable.no_network;\r
break;\r
case UNKNOWN_ERROR:\r
mStatusIcon = R.drawable.common_error;\r
- mStatusText = R.string.auth_unknow_error;\r
+ mStatusText = R.string.auth_unknown_error_title;\r
break;\r
case FILE_NOT_FOUND:\r
mStatusIcon = R.drawable.common_error;\r
if (view.getId() == R.id.host_URL) {\r
if (!hasFocus) {\r
TextView tv = ((TextView) findViewById(R.id.host_URL));\r
- String uri = tv.getText().toString();\r
+ String uri = tv.getText().toString().trim();\r
if (uri.length() != 0) {\r
setResultIconAndText(R.drawable.progress_small,\r
R.string.auth_testing_connection);\r