Merge remote-tracking branch 'origin/master'
[pub/Android/ownCloud.git] / src / com / owncloud / android / authentication / AuthenticatorActivity.java
index b4b1c6b..6eae48f 100644 (file)
@@ -18,7 +18,6 @@
 \r
 package com.owncloud.android.authentication;\r
 \r
-import com.owncloud.android.AccountUtils;\r
 import com.owncloud.android.Log_OC;\r
 import com.owncloud.android.ui.dialog.SslValidatorDialog;\r
 import com.owncloud.android.ui.dialog.SslValidatorDialog.OnSslValidatorListener;\r
@@ -110,8 +109,7 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
 \r
     public static final byte ACTION_CREATE = 0;\r
     public static final byte ACTION_UPDATE_TOKEN = 1;\r
-\r
-\r
+    \r
     private String mHostBaseUrl;\r
     private OwnCloudVersion mDiscoveredVersion;\r
 \r
@@ -451,7 +449,7 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
 \r
 \r
     private void checkOcServer() {\r
-        String uri = mHostUrlInput.getText().toString().trim();\r
+        String uri = trimUrlWebdav(mHostUrlInput.getText().toString().trim());\r
         mServerIsValid = false;\r
         mServerIsChecked = false;\r
         mOkButton.setEnabled(false);\r
@@ -693,15 +691,33 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
                 } else {\r
                     url = "http://" + url;\r
                 }\r
-\r
             }\r
+\r
+            // OC-208: Add suffix remote.php/webdav to normalize (OC-34)            \r
+            url = trimUrlWebdav(url);\r
+\r
             if (url.endsWith("/")) {\r
                 url = url.substring(0, url.length() - 1);\r
             }\r
+\r
         }\r
+        Log_OC.d(TAG, "URL Normalize " + url);\r
         return (url != null ? url : "");\r
     }\r
 \r
+\r
+    private String trimUrlWebdav(String url){       \r
+        if(url.toLowerCase().endsWith(AccountUtils.WEBDAV_PATH_4_0)){\r
+            url = url.substring(0, url.length() - AccountUtils.WEBDAV_PATH_4_0.length());             \r
+        } else if(url.toLowerCase().endsWith(AccountUtils.WEBDAV_PATH_2_0)){\r
+            url = url.substring(0, url.length() - AccountUtils.WEBDAV_PATH_2_0.length());             \r
+        } else if (url.toLowerCase().endsWith(AccountUtils.WEBDAV_PATH_1_2)){\r
+            url = url.substring(0, url.length() - AccountUtils.WEBDAV_PATH_1_2.length());             \r
+        } \r
+        return (url != null ? url : "");\r
+    }\r
+    \r
+    \r
     /**\r
      * Chooses the right icon and text to show to the user for the received operation result.\r
      * \r
@@ -918,7 +934,33 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
 \r
             finish();\r
 \r
-        } else {\r
+        } else if (result.isServerFail() || result.isException()) {\r
+            /// if server fail or exception in authorization, the UI is updated as when a server check failed\r
+            mServerIsChecked = true;\r
+            mServerIsValid = false;\r
+            mIsSslConn = false;\r
+            mOcServerChkOperation = null;\r
+            mDiscoveredVersion = null;\r
+            mHostBaseUrl = normalizeUrl(mHostUrlInput.getText().toString());\r
+\r
+            // update status icon and text\r
+            updateServerStatusIconAndText(result);\r
+            showServerStatus();\r
+            mAuthStatusIcon = 0;\r
+            mAuthStatusText = 0;\r
+            showAuthStatus();\r
+            \r
+            // update input controls state\r
+            showRefreshButton();\r
+            mOkButton.setEnabled(false);\r
+\r
+            // very special case (TODO: move to a common place for all the remote operations) (dangerous here?)\r
+            if (result.getCode() == ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED) {\r
+                mLastSslUntrustedServerResult = result;\r
+                showDialog(DIALOG_SSL_VALIDATOR); \r
+            }\r
+\r
+        } else {    // authorization fail due to client side - probably wrong credentials\r
             updateAuthStatusIconAndText(result);\r
             showAuthStatus();\r
             Log_OC.d(TAG, "Access failed: " + result.getLogMessage());\r
@@ -1228,7 +1270,7 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
      * Called from SslValidatorDialog when a new server certificate was correctly saved.\r
      */\r
     public void onSavedCertificate() {\r
-        mOperationThread = mOcServerChkOperation.retry(this, mHandler);                \r
+        checkOcServer();\r
     }\r
 \r
     /**\r