X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/261aaf50019732a4e766d6b3e9e07576a64f5504..b3267c409b1e5ad5037d919f3248464534a92cea:/src/com/owncloud/android/operations/RemoteOperationResult.java
diff --git a/src/com/owncloud/android/operations/RemoteOperationResult.java b/src/com/owncloud/android/operations/RemoteOperationResult.java
index 03afda55..4e137c42 100644
--- a/src/com/owncloud/android/operations/RemoteOperationResult.java
+++ b/src/com/owncloud/android/operations/RemoteOperationResult.java
@@ -1,5 +1,25 @@
+/* ownCloud Android client application
+ *   Copyright (C) 2012 Bartek Przybylski
+ *   Copyright (C) 2012-2013 ownCloud Inc.
+ *
+ *   This program is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License version 2,
+ *   as published by the Free Software Foundation.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program.  If not, see .
+ *
+ */
+
 package com.owncloud.android.operations;
 
+import java.io.IOException;
+import java.io.Serializable;
 import java.net.MalformedURLException;
 import java.net.SocketException;
 import java.net.SocketTimeoutException;
@@ -8,20 +28,41 @@ import java.net.UnknownHostException;
 import javax.net.ssl.SSLException;
 
 import org.apache.commons.httpclient.ConnectTimeoutException;
+import org.apache.commons.httpclient.Header;
+import org.apache.commons.httpclient.HttpException;
 import org.apache.commons.httpclient.HttpStatus;
+import org.apache.jackrabbit.webdav.DavException;
 
-import android.util.Log;
+import android.accounts.Account;
+import android.accounts.AccountsException;
 
+import com.owncloud.android.Log_OC;
+import com.owncloud.android.authentication.AccountUtils.AccountNotFoundException;
 import com.owncloud.android.network.CertificateCombinedException;
 
+/**
+ * The result of a remote operation required to an ownCloud server.
+ * 
+ * Provides a common classification of remote operation results for all the
+ * application.
+ * 
+ * @author David A. Velasco
+ */
+public class RemoteOperationResult implements Serializable {
+
+    /** Generated - should be refreshed every time the class changes!! */
+    private static final long serialVersionUID = -4415103901492836870L;
+    
 
-public class RemoteOperationResult {
     
-    public enum ResultCode {    // TODO leave alone our own errors
+    private static final String TAG = "RemoteOperationResult";
+    
+    public enum ResultCode { 
         OK,
         OK_SSL,
         OK_NO_SSL,
         UNHANDLED_HTTP_CODE,
+        UNAUTHORIZED,        
         FILE_NOT_FOUND, 
         INSTANCE_NOT_CONFIGURED, 
         UNKNOWN_ERROR, 
@@ -31,122 +72,266 @@ public class RemoteOperationResult {
         HOST_NOT_AVAILABLE, 
         NO_NETWORK_CONNECTION, 
         SSL_ERROR,
-        BAD_OC_VERSION, 
+        SSL_RECOVERABLE_PEER_UNVERIFIED,
+        BAD_OC_VERSION,
+        CANCELLED, 
+        INVALID_LOCAL_FILE_NAME, 
+        INVALID_OVERWRITE,
+        CONFLICT, 
+        OAUTH2_ERROR,
+        SYNC_CONFLICT,
+        LOCAL_STORAGE_FULL, 
+        LOCAL_STORAGE_NOT_MOVED, 
+        LOCAL_STORAGE_NOT_COPIED, 
+        OAUTH2_ERROR_ACCESS_DENIED,
+        QUOTA_EXCEEDED, 
+        ACCOUNT_NOT_FOUND, 
+        ACCOUNT_EXCEPTION, 
+        ACCOUNT_NOT_NEW, 
+        ACCOUNT_NOT_THE_SAME
     }
 
-    private static final String TAG = null;
-    
     private boolean mSuccess = false;
     private int mHttpCode = -1;
     private Exception mException = null;
     private ResultCode mCode = ResultCode.UNKNOWN_ERROR;
-    
+    private String mRedirectedLocation;
+
     public RemoteOperationResult(ResultCode code) {
         mCode = code;
         mSuccess = (code == ResultCode.OK || code == ResultCode.OK_SSL || code == ResultCode.OK_NO_SSL);
     }
-    
-    public RemoteOperationResult(boolean success, int httpCode) {
-        mSuccess = success; 
+
+    private RemoteOperationResult(boolean success, int httpCode) {
+        mSuccess = success;
         mHttpCode = httpCode;
 
         if (success) {
             mCode = ResultCode.OK;
-            
+
         } else if (httpCode > 0) {
             switch (httpCode) {
-                case HttpStatus.SC_NOT_FOUND:
-                    mCode = ResultCode.FILE_NOT_FOUND;
-                    break;
-                case HttpStatus.SC_INTERNAL_SERVER_ERROR:
-                    mCode = ResultCode.INSTANCE_NOT_CONFIGURED;
-                    break;
-                default:
-                    mCode = ResultCode.UNHANDLED_HTTP_CODE;
+            case HttpStatus.SC_UNAUTHORIZED:
+                mCode = ResultCode.UNAUTHORIZED;
+                break;
+            case HttpStatus.SC_NOT_FOUND:
+                mCode = ResultCode.FILE_NOT_FOUND;
+                break;
+            case HttpStatus.SC_INTERNAL_SERVER_ERROR:
+                mCode = ResultCode.INSTANCE_NOT_CONFIGURED;
+                break;
+            case HttpStatus.SC_CONFLICT:
+                mCode = ResultCode.CONFLICT;
+                break;
+            case HttpStatus.SC_INSUFFICIENT_STORAGE:
+                mCode = ResultCode.QUOTA_EXCEEDED;
+                break;
+            default:
+                mCode = ResultCode.UNHANDLED_HTTP_CODE;
+                Log_OC.d(TAG, "RemoteOperationResult has processed UNHANDLED_HTTP_CODE: " + httpCode);
             }
         }
     }
     
+    public RemoteOperationResult(boolean success, int httpCode, Header[] headers) {
+        this(success, httpCode);
+        if (headers != null) {
+            Header current;
+            for (int i=0; i= HttpStatus.SC_INTERNAL_SERVER_ERROR);
+    }
+
+    public boolean isException() {
+        return (mException != null);
+    }
+
+    public boolean isTemporalRedirection() {
+        return (mHttpCode == 302 || mHttpCode == 307);
+    }
+
+    public String getRedirectedLocation() {
+        return mRedirectedLocation;
+    }
+    
+    public boolean isIdPRedirection() {
+        return (mRedirectedLocation != null &&
+                (mRedirectedLocation.toUpperCase().contains("SAML") || 
+                mRedirectedLocation.toLowerCase().contains("wayf")));
     }
 
 }