Loading src/com/owncloud/android/lib/common/network/WebdavEntry.java +20 −0 Original line number Diff line number Diff line Loading @@ -42,10 +42,12 @@ public class WebdavEntry { private static final String TAG = WebdavEntry.class.getSimpleName(); public static final String NAMESPACE_OC = "http://owncloud.org/ns"; public static final String NAMESPACE_NC = "http://nextcloud.org/ns"; public static final String EXTENDED_PROPERTY_NAME_PERMISSIONS = "permissions"; public static final String EXTENDED_PROPERTY_NAME_REMOTE_ID = "id"; public static final String EXTENDED_PROPERTY_NAME_SIZE = "size"; public static final String EXTENDED_PROPERTY_FAVORITE = "favorite"; public static final String EXTENDED_PROPERTY_IS_ENCRYPTED = "is-encrypted"; public static final String PROPERTY_QUOTA_USED_BYTES = "quota-used-bytes"; public static final String PROPERTY_QUOTA_AVAILABLE_BYTES = "quota-available-bytes"; Loading @@ -60,6 +62,7 @@ public class WebdavEntry { private String mPermissions; private String mRemoteId; private boolean mIsFavorite; private boolean mIsEncrypted; private long mContentLength, mCreateTimestamp, mModifiedTimestamp, mSize; private BigDecimal mQuotaUsedBytes, mQuotaAvailableBytes; Loading Loading @@ -210,6 +213,19 @@ public class WebdavEntry { mIsFavorite = false; } // NC encrypted property <nc:is-encrypted> prop = propSet.get(EXTENDED_PROPERTY_IS_ENCRYPTED, Namespace.getNamespace(NAMESPACE_NC)); if (prop != null) { String encryptedValue = (String) prop.getValue(); if ("1".equals(encryptedValue)) { mIsEncrypted = true; } else { mIsEncrypted = false; } } else { mIsEncrypted = false; } } else { Log_OC.e("WebdavEntry", "General fuckup, no status for webdav response"); } Loading @@ -223,6 +239,10 @@ public class WebdavEntry { this.mIsFavorite = mIsFavorite; } public boolean isEncrypted() { return mIsEncrypted; } public String path() { return mPath; } Loading src/com/owncloud/android/lib/common/network/WebdavUtils.java +5 −8 Original line number Diff line number Diff line Loading @@ -101,14 +101,11 @@ public class WebdavUtils { propSet.add(DavPropertyName.GETETAG); propSet.add(DavPropertyName.create(WebdavEntry.PROPERTY_QUOTA_USED_BYTES)); propSet.add(DavPropertyName.create(WebdavEntry.PROPERTY_QUOTA_AVAILABLE_BYTES)); propSet.add(WebdavEntry.EXTENDED_PROPERTY_NAME_PERMISSIONS, Namespace.getNamespace(WebdavEntry.NAMESPACE_OC)); propSet.add(WebdavEntry.EXTENDED_PROPERTY_NAME_REMOTE_ID, Namespace.getNamespace(WebdavEntry.NAMESPACE_OC)); propSet.add(WebdavEntry.EXTENDED_PROPERTY_NAME_SIZE, Namespace.getNamespace(WebdavEntry.NAMESPACE_OC)); propSet.add(WebdavEntry.EXTENDED_PROPERTY_FAVORITE, Namespace.getNamespace(WebdavEntry.NAMESPACE_OC)); propSet.add(WebdavEntry.EXTENDED_PROPERTY_NAME_PERMISSIONS, Namespace.getNamespace(WebdavEntry.NAMESPACE_OC)); propSet.add(WebdavEntry.EXTENDED_PROPERTY_NAME_REMOTE_ID, Namespace.getNamespace(WebdavEntry.NAMESPACE_OC)); propSet.add(WebdavEntry.EXTENDED_PROPERTY_NAME_SIZE, Namespace.getNamespace(WebdavEntry.NAMESPACE_OC)); propSet.add(WebdavEntry.EXTENDED_PROPERTY_FAVORITE, Namespace.getNamespace(WebdavEntry.NAMESPACE_OC)); propSet.add(WebdavEntry.EXTENDED_PROPERTY_IS_ENCRYPTED, Namespace.getNamespace(WebdavEntry.NAMESPACE_NC)); return propSet; } Loading src/com/owncloud/android/lib/common/operations/RemoteOperationResult.java +3 −1 Original line number Diff line number Diff line Loading @@ -123,7 +123,9 @@ public class RemoteOperationResult implements Serializable { MAINTENANCE_MODE, LOCK_FAILED, DELAYED_IN_POWER_SAVE_MODE, ACCOUNT_USES_STANDARD_PASSWORD ACCOUNT_USES_STANDARD_PASSWORD, METADATA_NOT_FOUND, OLD_ANDROID_API } private boolean mSuccess = false; Loading src/com/owncloud/android/lib/resources/files/GetMetadataOperation.java 0 → 100644 +105 −0 Original line number Diff line number Diff line /* * Nextcloud Android client application * * @author Tobias Kaminsky * Copyright (C) 2017 Tobias Kaminsky * Copyright (C) 2017 Nextcloud GmbH. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * at your option) any later version. * * 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package com.owncloud.android.lib.resources.files; import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.utils.Log_OC; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.methods.GetMethod; import org.json.JSONObject; import java.util.ArrayList; /** * Remote operation performing the fetch of metadata for a folder */ public class GetMetadataOperation extends RemoteOperation { private static final String TAG = GetMetadataOperation.class.getSimpleName(); private static final int SYNC_READ_TIMEOUT = 40000; private static final int SYNC_CONNECTION_TIMEOUT = 5000; private static final String METADATA_URL = "/ocs/v2.php/apps/end_to_end_encryption/api/v1/meta-data/"; // JSON node names private static final String NODE_OCS = "ocs"; private static final String NODE_DATA = "data"; private static final String NODE_META_DATA = "meta-data"; private static final String JSON_FORMAT = "?format=json"; private String fileId; /** * Constructor */ public GetMetadataOperation(String fileId) { this.fileId = fileId; } /** * @param client Client object */ @Override protected RemoteOperationResult run(OwnCloudClient client) { GetMethod getMethod = null; RemoteOperationResult result; try { // remote request getMethod = new GetMethod(client.getBaseUri() + METADATA_URL + fileId + JSON_FORMAT); getMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); int status = client.executeMethod(getMethod, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT); if (status == HttpStatus.SC_OK) { String response = getMethod.getResponseBodyAsString(); // Parse the response JSONObject respJSON = new JSONObject(response); String metadata = (String) respJSON.getJSONObject(NODE_OCS).getJSONObject(NODE_DATA) .get(NODE_META_DATA); result = new RemoteOperationResult(true, getMethod); ArrayList<Object> metadataArray = new ArrayList<>(); metadataArray.add(metadata); result.setData(metadataArray); } else { result = new RemoteOperationResult(false, getMethod); client.exhaustResponse(getMethod.getResponseBodyAsStream()); } } catch (Exception e) { result = new RemoteOperationResult(e); e.printStackTrace(); Log_OC.e(TAG, "Fetching of metadata for folder " + fileId + " failed: " + result.getLogMessage(), result.getException()); } finally { if (getMethod != null) getMethod.releaseConnection(); } return result; } } src/com/owncloud/android/lib/resources/files/LockFileOperation.java 0 → 100644 +117 −0 Original line number Diff line number Diff line /* * Nextcloud Android client application * * @author Tobias Kaminsky * Copyright (C) 2017 Tobias Kaminsky * Copyright (C) 2017 Nextcloud GmbH. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * at your option) any later version. * * 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package com.owncloud.android.lib.resources.files; import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.utils.Log_OC; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.methods.PostMethod; import org.json.JSONObject; import java.util.ArrayList; /** * Lock a file */ public class LockFileOperation extends RemoteOperation { private static final String TAG = LockFileOperation.class.getSimpleName(); private static final int SYNC_READ_TIMEOUT = 40000; private static final int SYNC_CONNECTION_TIMEOUT = 5000; private static final String LOCK_FILE_URL = "/ocs/v2.php/apps/end_to_end_encryption/api/v1/lock/"; private String localId; private String token; // JSON node names private static final String NODE_OCS = "ocs"; private static final String NODE_DATA = "data"; private static final String NODE_TOKEN = "token"; private static final String JSON_FORMAT = "?format=json"; /** * Constructor */ public LockFileOperation(String localId, String token) { this.localId = localId; this.token = token; } public LockFileOperation(String localId) { this.localId = localId; this.token = ""; } /** * @param client Client object */ @Override protected RemoteOperationResult run(OwnCloudClient client) { RemoteOperationResult result; PostMethod postMethod = null; try { postMethod = new PostMethod(client.getBaseUri() + LOCK_FILE_URL + localId + JSON_FORMAT); if (!token.isEmpty()) { postMethod.setParameter("token", token); } // remote request postMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); postMethod.addRequestHeader("Content-Type", "application/x-www-form-urlencoded"); int status = client.executeMethod(postMethod, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT); if (status == HttpStatus.SC_OK) { String response = postMethod.getResponseBodyAsString(); // Parse the response JSONObject respJSON = new JSONObject(response); String token = (String) respJSON.getJSONObject(NODE_OCS).getJSONObject(NODE_DATA) .get(NODE_TOKEN); result = new RemoteOperationResult(true, postMethod); ArrayList<Object> tokenArray = new ArrayList<>(); tokenArray.add(token); result.setData(tokenArray); } else { result = new RemoteOperationResult(false, postMethod); client.exhaustResponse(postMethod.getResponseBodyAsStream()); } } catch (Exception e) { result = new RemoteOperationResult(e); e.printStackTrace(); Log_OC.e(TAG, "Lock file with id " + localId + " failed: " + result.getLogMessage(), result.getException()); } finally { if (postMethod != null) postMethod.releaseConnection(); } return result; } } Loading
src/com/owncloud/android/lib/common/network/WebdavEntry.java +20 −0 Original line number Diff line number Diff line Loading @@ -42,10 +42,12 @@ public class WebdavEntry { private static final String TAG = WebdavEntry.class.getSimpleName(); public static final String NAMESPACE_OC = "http://owncloud.org/ns"; public static final String NAMESPACE_NC = "http://nextcloud.org/ns"; public static final String EXTENDED_PROPERTY_NAME_PERMISSIONS = "permissions"; public static final String EXTENDED_PROPERTY_NAME_REMOTE_ID = "id"; public static final String EXTENDED_PROPERTY_NAME_SIZE = "size"; public static final String EXTENDED_PROPERTY_FAVORITE = "favorite"; public static final String EXTENDED_PROPERTY_IS_ENCRYPTED = "is-encrypted"; public static final String PROPERTY_QUOTA_USED_BYTES = "quota-used-bytes"; public static final String PROPERTY_QUOTA_AVAILABLE_BYTES = "quota-available-bytes"; Loading @@ -60,6 +62,7 @@ public class WebdavEntry { private String mPermissions; private String mRemoteId; private boolean mIsFavorite; private boolean mIsEncrypted; private long mContentLength, mCreateTimestamp, mModifiedTimestamp, mSize; private BigDecimal mQuotaUsedBytes, mQuotaAvailableBytes; Loading Loading @@ -210,6 +213,19 @@ public class WebdavEntry { mIsFavorite = false; } // NC encrypted property <nc:is-encrypted> prop = propSet.get(EXTENDED_PROPERTY_IS_ENCRYPTED, Namespace.getNamespace(NAMESPACE_NC)); if (prop != null) { String encryptedValue = (String) prop.getValue(); if ("1".equals(encryptedValue)) { mIsEncrypted = true; } else { mIsEncrypted = false; } } else { mIsEncrypted = false; } } else { Log_OC.e("WebdavEntry", "General fuckup, no status for webdav response"); } Loading @@ -223,6 +239,10 @@ public class WebdavEntry { this.mIsFavorite = mIsFavorite; } public boolean isEncrypted() { return mIsEncrypted; } public String path() { return mPath; } Loading
src/com/owncloud/android/lib/common/network/WebdavUtils.java +5 −8 Original line number Diff line number Diff line Loading @@ -101,14 +101,11 @@ public class WebdavUtils { propSet.add(DavPropertyName.GETETAG); propSet.add(DavPropertyName.create(WebdavEntry.PROPERTY_QUOTA_USED_BYTES)); propSet.add(DavPropertyName.create(WebdavEntry.PROPERTY_QUOTA_AVAILABLE_BYTES)); propSet.add(WebdavEntry.EXTENDED_PROPERTY_NAME_PERMISSIONS, Namespace.getNamespace(WebdavEntry.NAMESPACE_OC)); propSet.add(WebdavEntry.EXTENDED_PROPERTY_NAME_REMOTE_ID, Namespace.getNamespace(WebdavEntry.NAMESPACE_OC)); propSet.add(WebdavEntry.EXTENDED_PROPERTY_NAME_SIZE, Namespace.getNamespace(WebdavEntry.NAMESPACE_OC)); propSet.add(WebdavEntry.EXTENDED_PROPERTY_FAVORITE, Namespace.getNamespace(WebdavEntry.NAMESPACE_OC)); propSet.add(WebdavEntry.EXTENDED_PROPERTY_NAME_PERMISSIONS, Namespace.getNamespace(WebdavEntry.NAMESPACE_OC)); propSet.add(WebdavEntry.EXTENDED_PROPERTY_NAME_REMOTE_ID, Namespace.getNamespace(WebdavEntry.NAMESPACE_OC)); propSet.add(WebdavEntry.EXTENDED_PROPERTY_NAME_SIZE, Namespace.getNamespace(WebdavEntry.NAMESPACE_OC)); propSet.add(WebdavEntry.EXTENDED_PROPERTY_FAVORITE, Namespace.getNamespace(WebdavEntry.NAMESPACE_OC)); propSet.add(WebdavEntry.EXTENDED_PROPERTY_IS_ENCRYPTED, Namespace.getNamespace(WebdavEntry.NAMESPACE_NC)); return propSet; } Loading
src/com/owncloud/android/lib/common/operations/RemoteOperationResult.java +3 −1 Original line number Diff line number Diff line Loading @@ -123,7 +123,9 @@ public class RemoteOperationResult implements Serializable { MAINTENANCE_MODE, LOCK_FAILED, DELAYED_IN_POWER_SAVE_MODE, ACCOUNT_USES_STANDARD_PASSWORD ACCOUNT_USES_STANDARD_PASSWORD, METADATA_NOT_FOUND, OLD_ANDROID_API } private boolean mSuccess = false; Loading
src/com/owncloud/android/lib/resources/files/GetMetadataOperation.java 0 → 100644 +105 −0 Original line number Diff line number Diff line /* * Nextcloud Android client application * * @author Tobias Kaminsky * Copyright (C) 2017 Tobias Kaminsky * Copyright (C) 2017 Nextcloud GmbH. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * at your option) any later version. * * 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package com.owncloud.android.lib.resources.files; import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.utils.Log_OC; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.methods.GetMethod; import org.json.JSONObject; import java.util.ArrayList; /** * Remote operation performing the fetch of metadata for a folder */ public class GetMetadataOperation extends RemoteOperation { private static final String TAG = GetMetadataOperation.class.getSimpleName(); private static final int SYNC_READ_TIMEOUT = 40000; private static final int SYNC_CONNECTION_TIMEOUT = 5000; private static final String METADATA_URL = "/ocs/v2.php/apps/end_to_end_encryption/api/v1/meta-data/"; // JSON node names private static final String NODE_OCS = "ocs"; private static final String NODE_DATA = "data"; private static final String NODE_META_DATA = "meta-data"; private static final String JSON_FORMAT = "?format=json"; private String fileId; /** * Constructor */ public GetMetadataOperation(String fileId) { this.fileId = fileId; } /** * @param client Client object */ @Override protected RemoteOperationResult run(OwnCloudClient client) { GetMethod getMethod = null; RemoteOperationResult result; try { // remote request getMethod = new GetMethod(client.getBaseUri() + METADATA_URL + fileId + JSON_FORMAT); getMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); int status = client.executeMethod(getMethod, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT); if (status == HttpStatus.SC_OK) { String response = getMethod.getResponseBodyAsString(); // Parse the response JSONObject respJSON = new JSONObject(response); String metadata = (String) respJSON.getJSONObject(NODE_OCS).getJSONObject(NODE_DATA) .get(NODE_META_DATA); result = new RemoteOperationResult(true, getMethod); ArrayList<Object> metadataArray = new ArrayList<>(); metadataArray.add(metadata); result.setData(metadataArray); } else { result = new RemoteOperationResult(false, getMethod); client.exhaustResponse(getMethod.getResponseBodyAsStream()); } } catch (Exception e) { result = new RemoteOperationResult(e); e.printStackTrace(); Log_OC.e(TAG, "Fetching of metadata for folder " + fileId + " failed: " + result.getLogMessage(), result.getException()); } finally { if (getMethod != null) getMethod.releaseConnection(); } return result; } }
src/com/owncloud/android/lib/resources/files/LockFileOperation.java 0 → 100644 +117 −0 Original line number Diff line number Diff line /* * Nextcloud Android client application * * @author Tobias Kaminsky * Copyright (C) 2017 Tobias Kaminsky * Copyright (C) 2017 Nextcloud GmbH. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * at your option) any later version. * * 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package com.owncloud.android.lib.resources.files; import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.utils.Log_OC; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.methods.PostMethod; import org.json.JSONObject; import java.util.ArrayList; /** * Lock a file */ public class LockFileOperation extends RemoteOperation { private static final String TAG = LockFileOperation.class.getSimpleName(); private static final int SYNC_READ_TIMEOUT = 40000; private static final int SYNC_CONNECTION_TIMEOUT = 5000; private static final String LOCK_FILE_URL = "/ocs/v2.php/apps/end_to_end_encryption/api/v1/lock/"; private String localId; private String token; // JSON node names private static final String NODE_OCS = "ocs"; private static final String NODE_DATA = "data"; private static final String NODE_TOKEN = "token"; private static final String JSON_FORMAT = "?format=json"; /** * Constructor */ public LockFileOperation(String localId, String token) { this.localId = localId; this.token = token; } public LockFileOperation(String localId) { this.localId = localId; this.token = ""; } /** * @param client Client object */ @Override protected RemoteOperationResult run(OwnCloudClient client) { RemoteOperationResult result; PostMethod postMethod = null; try { postMethod = new PostMethod(client.getBaseUri() + LOCK_FILE_URL + localId + JSON_FORMAT); if (!token.isEmpty()) { postMethod.setParameter("token", token); } // remote request postMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); postMethod.addRequestHeader("Content-Type", "application/x-www-form-urlencoded"); int status = client.executeMethod(postMethod, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT); if (status == HttpStatus.SC_OK) { String response = postMethod.getResponseBodyAsString(); // Parse the response JSONObject respJSON = new JSONObject(response); String token = (String) respJSON.getJSONObject(NODE_OCS).getJSONObject(NODE_DATA) .get(NODE_TOKEN); result = new RemoteOperationResult(true, postMethod); ArrayList<Object> tokenArray = new ArrayList<>(); tokenArray.add(token); result.setData(tokenArray); } else { result = new RemoteOperationResult(false, postMethod); client.exhaustResponse(postMethod.getResponseBodyAsStream()); } } catch (Exception e) { result = new RemoteOperationResult(e); e.printStackTrace(); Log_OC.e(TAG, "Lock file with id " + localId + " failed: " + result.getLogMessage(), result.getException()); } finally { if (postMethod != null) postMethod.releaseConnection(); } return result; } }