mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-07 07:56:19 +00:00
Merge pull request #286 from owncloud/remove_older_10_support
End of support for <10 servers
This commit is contained in:
commit
6df51cc323
@ -1,62 +0,0 @@
|
|||||||
package com.owncloud.android.lib.common;
|
|
||||||
|
|
||||||
import android.accounts.AuthenticatorException;
|
|
||||||
import android.accounts.OperationCanceledException;
|
|
||||||
import android.content.Context;
|
|
||||||
|
|
||||||
import com.owncloud.android.lib.common.accounts.AccountUtils;
|
|
||||||
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Dynamic implementation of {@link OwnCloudClientManager}.
|
|
||||||
*
|
|
||||||
* Wraps instances of {@link SingleSessionManager} and {@link SimpleFactoryManager} and delegates on one
|
|
||||||
* or the other depending on the known version of the server corresponding to the {@link OwnCloudAccount}
|
|
||||||
*
|
|
||||||
* @author David A. Velasco
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class DynamicSessionManager implements OwnCloudClientManager {
|
|
||||||
|
|
||||||
private SimpleFactoryManager mSimpleFactoryManager = new SimpleFactoryManager();
|
|
||||||
|
|
||||||
private SingleSessionManager mSingleSessionManager = new SingleSessionManager();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public OwnCloudClient getClientFor(OwnCloudAccount account, Context context)
|
|
||||||
throws OperationCanceledException, AuthenticatorException, IOException {
|
|
||||||
|
|
||||||
OwnCloudVersion ownCloudVersion = null;
|
|
||||||
if (account.getSavedAccount() != null) {
|
|
||||||
ownCloudVersion = AccountUtils.getServerVersionForAccount(
|
|
||||||
account.getSavedAccount(), context
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ownCloudVersion != null && ownCloudVersion.isSessionMonitoringSupported()) {
|
|
||||||
return mSingleSessionManager.getClientFor(account, context);
|
|
||||||
} else {
|
|
||||||
return mSimpleFactoryManager.getClientFor(account, context);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public OwnCloudClient removeClientFor(OwnCloudAccount account) {
|
|
||||||
OwnCloudClient clientRemovedFromFactoryManager = mSimpleFactoryManager.removeClientFor(account);
|
|
||||||
OwnCloudClient clientRemovedFromSingleSessionManager = mSingleSessionManager.removeClientFor(account);
|
|
||||||
if (clientRemovedFromSingleSessionManager != null) {
|
|
||||||
return clientRemovedFromSingleSessionManager;
|
|
||||||
} else {
|
|
||||||
return clientRemovedFromFactoryManager;
|
|
||||||
}
|
|
||||||
// clientRemoved and clientRemoved2 should not be != null at the same time
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void saveAllClients(Context context, String accountType) {
|
|
||||||
mSimpleFactoryManager.saveAllClients(context, accountType);
|
|
||||||
mSingleSessionManager.saveAllClients(context, accountType);
|
|
||||||
}
|
|
||||||
}
|
|
@ -381,16 +381,16 @@ public class OwnCloudClient extends HttpClient {
|
|||||||
* cannot be invalidated with the given arguments.
|
* cannot be invalidated with the given arguments.
|
||||||
*/
|
*/
|
||||||
private boolean shouldInvalidateAccountCredentials(int httpStatusCode) {
|
private boolean shouldInvalidateAccountCredentials(int httpStatusCode) {
|
||||||
|
boolean shouldInvalidateAccountCredentials =
|
||||||
|
(httpStatusCode == HttpConstants.HTTP_UNAUTHORIZED);
|
||||||
|
|
||||||
boolean should = (httpStatusCode == HttpConstants.HTTP_UNAUTHORIZED); // invalid credentials
|
shouldInvalidateAccountCredentials &= (mCredentials != null && // real credentials
|
||||||
|
|
||||||
should &= (mCredentials != null && // real credentials
|
|
||||||
!(mCredentials instanceof OwnCloudCredentialsFactory.OwnCloudAnonymousCredentials));
|
!(mCredentials instanceof OwnCloudCredentialsFactory.OwnCloudAnonymousCredentials));
|
||||||
|
|
||||||
// test if have all the needed to effectively invalidate ...
|
// test if have all the needed to effectively invalidate ...
|
||||||
should &= (mAccount != null && mAccount.getSavedAccount() != null && getContext() != null);
|
shouldInvalidateAccountCredentials &= (mAccount != null && mAccount.getSavedAccount() != null && getContext() != null);
|
||||||
|
|
||||||
return should;
|
return shouldInvalidateAccountCredentials;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -29,17 +29,17 @@ public class OwnCloudClientManagerFactory {
|
|||||||
private static OwnCloudClientManager sDefaultSingleton;
|
private static OwnCloudClientManager sDefaultSingleton;
|
||||||
private static String sUserAgent;
|
private static String sUserAgent;
|
||||||
|
|
||||||
public static OwnCloudClientManager newDefaultOwnCloudClientManager() {
|
private static OwnCloudClientManager newDefaultOwnCloudClientManager() {
|
||||||
return newOwnCloudClientManager(sDefaultPolicy);
|
return newOwnCloudClientManager(sDefaultPolicy);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static OwnCloudClientManager newOwnCloudClientManager(Policy policy) {
|
private static OwnCloudClientManager newOwnCloudClientManager(Policy policy) {
|
||||||
switch (policy) {
|
switch (policy) {
|
||||||
case ALWAYS_NEW_CLIENT:
|
case ALWAYS_NEW_CLIENT:
|
||||||
return new SimpleFactoryManager();
|
return new SimpleFactoryManager();
|
||||||
|
|
||||||
case SINGLE_SESSION_PER_ACCOUNT_IF_SERVER_SUPPORTS_SERVER_MONITORING:
|
case SINGLE_SESSION_PER_ACCOUNT:
|
||||||
return new DynamicSessionManager();
|
return new SingleSessionManager();
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new IllegalArgumentException("Unknown policy");
|
throw new IllegalArgumentException("Unknown policy");
|
||||||
@ -53,10 +53,6 @@ public class OwnCloudClientManagerFactory {
|
|||||||
return sDefaultSingleton;
|
return sDefaultSingleton;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Policy getDefaultPolicy() {
|
|
||||||
return sDefaultPolicy;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setDefaultPolicy(Policy policy) {
|
public static void setDefaultPolicy(Policy policy) {
|
||||||
if (policy == null) {
|
if (policy == null) {
|
||||||
throw new IllegalArgumentException("Default policy cannot be NULL");
|
throw new IllegalArgumentException("Default policy cannot be NULL");
|
||||||
@ -84,6 +80,6 @@ public class OwnCloudClientManagerFactory {
|
|||||||
|
|
||||||
public enum Policy {
|
public enum Policy {
|
||||||
ALWAYS_NEW_CLIENT,
|
ALWAYS_NEW_CLIENT,
|
||||||
SINGLE_SESSION_PER_ACCOUNT_IF_SERVER_SUPPORTS_SERVER_MONITORING
|
SINGLE_SESSION_PER_ACCOUNT
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -143,7 +143,6 @@ public class AccountUtils {
|
|||||||
boolean isOauth2 = supportsOAuth2 != null && supportsOAuth2.equals("TRUE");
|
boolean isOauth2 = supportsOAuth2 != null && supportsOAuth2.equals("TRUE");
|
||||||
|
|
||||||
String username = AccountUtils.getUsernameForAccount(account);
|
String username = AccountUtils.getUsernameForAccount(account);
|
||||||
OwnCloudVersion version = new OwnCloudVersion(am.getUserData(account, Constants.KEY_OC_VERSION));
|
|
||||||
|
|
||||||
if (isOauth2) {
|
if (isOauth2) {
|
||||||
String accessToken = am.blockingGetAuthToken(
|
String accessToken = am.blockingGetAuthToken(
|
||||||
@ -152,7 +151,6 @@ public class AccountUtils {
|
|||||||
false);
|
false);
|
||||||
|
|
||||||
credentials = OwnCloudCredentialsFactory.newBearerCredentials(username, accessToken);
|
credentials = OwnCloudCredentialsFactory.newBearerCredentials(username, accessToken);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
String password = am.blockingGetAuthToken(
|
String password = am.blockingGetAuthToken(
|
||||||
account,
|
account,
|
||||||
@ -161,8 +159,7 @@ public class AccountUtils {
|
|||||||
|
|
||||||
credentials = OwnCloudCredentialsFactory.newBasicCredentials(
|
credentials = OwnCloudCredentialsFactory.newBasicCredentials(
|
||||||
username,
|
username,
|
||||||
password,
|
password
|
||||||
version.isPreemptiveAuthenticationPreferred()
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -201,9 +198,8 @@ public class AccountUtils {
|
|||||||
if (url.contains("://")) {
|
if (url.contains("://")) {
|
||||||
url = url.substring(serverBaseUrl.toString().indexOf("://") + 3);
|
url = url.substring(serverBaseUrl.toString().indexOf("://") + 3);
|
||||||
}
|
}
|
||||||
String accountName = username + "@" + url;
|
|
||||||
|
|
||||||
return accountName;
|
return username + "@" + url;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void saveClient(OwnCloudClient client, Account savedAccount, Context context) {
|
public static void saveClient(OwnCloudClient client, Account savedAccount, Context context) {
|
||||||
|
@ -38,12 +38,6 @@ public class OwnCloudCredentialsFactory {
|
|||||||
return new OwnCloudBasicCredentials(username, password);
|
return new OwnCloudBasicCredentials(username, password);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static OwnCloudCredentials newBasicCredentials(
|
|
||||||
String username, String password, boolean preemptiveMode
|
|
||||||
) {
|
|
||||||
return new OwnCloudBasicCredentials(username, password, preemptiveMode);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static OwnCloudCredentials newBearerCredentials(String username, String authToken) {
|
public static OwnCloudCredentials newBearerCredentials(String username, String authToken) {
|
||||||
return new OwnCloudBearerCredentials(username, authToken);
|
return new OwnCloudBearerCredentials(username, authToken);
|
||||||
}
|
}
|
||||||
|
@ -188,8 +188,12 @@ public class RemoteOperationResult<T>
|
|||||||
try {
|
try {
|
||||||
if (xmlParser.parseXMLResponse(is)) {
|
if (xmlParser.parseXMLResponse(is)) {
|
||||||
mCode = ResultCode.INVALID_CHARACTER_DETECT_IN_SERVER;
|
mCode = ResultCode.INVALID_CHARACTER_DETECT_IN_SERVER;
|
||||||
|
} else {
|
||||||
|
parseErrorMessageAndSetCode(
|
||||||
|
httpMethod.getResponseBodyAsString(),
|
||||||
|
ResultCode.SPECIFIC_BAD_REQUEST
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Timber.w("Error reading exception from server: %s", e.getMessage());
|
Timber.w("Error reading exception from server: %s", e.getMessage());
|
||||||
// mCode stays as set in this(success, httpCode, headers)
|
// mCode stays as set in this(success, httpCode, headers)
|
||||||
@ -305,13 +309,12 @@ public class RemoteOperationResult<T>
|
|||||||
* @param resultCode our own custom result code
|
* @param resultCode our own custom result code
|
||||||
*/
|
*/
|
||||||
private void parseErrorMessageAndSetCode(String bodyResponse, ResultCode resultCode) {
|
private void parseErrorMessageAndSetCode(String bodyResponse, ResultCode resultCode) {
|
||||||
|
|
||||||
if (bodyResponse != null && bodyResponse.length() > 0) {
|
if (bodyResponse != null && bodyResponse.length() > 0) {
|
||||||
InputStream is = new ByteArrayInputStream(bodyResponse.getBytes());
|
InputStream is = new ByteArrayInputStream(bodyResponse.getBytes());
|
||||||
ErrorMessageParser xmlParser = new ErrorMessageParser();
|
ErrorMessageParser xmlParser = new ErrorMessageParser();
|
||||||
try {
|
try {
|
||||||
String errorMessage = xmlParser.parseXMLResponse(is);
|
String errorMessage = xmlParser.parseXMLResponse(is);
|
||||||
if (errorMessage != null && !errorMessage.equals("")) {
|
if (!errorMessage.equals("")) {
|
||||||
mCode = resultCode;
|
mCode = resultCode;
|
||||||
mHttpPhrase = errorMessage;
|
mHttpPhrase = errorMessage;
|
||||||
}
|
}
|
||||||
@ -566,6 +569,7 @@ public class RemoteOperationResult<T>
|
|||||||
SERVICE_UNAVAILABLE,
|
SERVICE_UNAVAILABLE,
|
||||||
SPECIFIC_SERVICE_UNAVAILABLE,
|
SPECIFIC_SERVICE_UNAVAILABLE,
|
||||||
SPECIFIC_UNSUPPORTED_MEDIA_TYPE,
|
SPECIFIC_UNSUPPORTED_MEDIA_TYPE,
|
||||||
SPECIFIC_METHOD_NOT_ALLOWED
|
SPECIFIC_METHOD_NOT_ALLOWED,
|
||||||
|
SPECIFIC_BAD_REQUEST
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,6 @@ import com.owncloud.android.lib.common.network.WebdavUtils;
|
|||||||
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
|
||||||
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
|
|
||||||
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
@ -41,11 +40,12 @@ import java.util.concurrent.TimeUnit;
|
|||||||
/**
|
/**
|
||||||
* Remote operation moving a remote file or folder in the ownCloud server to a different folder
|
* Remote operation moving a remote file or folder in the ownCloud server to a different folder
|
||||||
* in the same account.
|
* in the same account.
|
||||||
* <p>
|
*
|
||||||
* Allows renaming the moving file/folder at the same time.
|
* Allows renaming the moving file/folder at the same time.
|
||||||
*
|
*
|
||||||
* @author David A. Velasco
|
* @author David A. Velasco
|
||||||
* @author Christian Schabesberger
|
* @author Christian Schabesberger
|
||||||
|
* @author David González V.
|
||||||
*/
|
*/
|
||||||
public class CopyRemoteFileOperation extends RemoteOperation<String> {
|
public class CopyRemoteFileOperation extends RemoteOperation<String> {
|
||||||
|
|
||||||
@ -81,14 +81,6 @@ public class CopyRemoteFileOperation extends RemoteOperation<String> {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected RemoteOperationResult<String> run(OwnCloudClient client) {
|
protected RemoteOperationResult<String> run(OwnCloudClient client) {
|
||||||
OwnCloudVersion version = client.getOwnCloudVersion();
|
|
||||||
boolean versionWithForbiddenChars =
|
|
||||||
(version != null && version.isVersionWithForbiddenCharacters());
|
|
||||||
|
|
||||||
/// check parameters
|
|
||||||
if (!FileUtils.isValidPath(mTargetRemotePath, versionWithForbiddenChars)) {
|
|
||||||
return new RemoteOperationResult<>(ResultCode.INVALID_CHARACTER_IN_NAME);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mTargetRemotePath.equals(mSrcRemotePath)) {
|
if (mTargetRemotePath.equals(mSrcRemotePath)) {
|
||||||
// nothing to do!
|
// nothing to do!
|
||||||
@ -100,7 +92,7 @@ public class CopyRemoteFileOperation extends RemoteOperation<String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// perform remote operation
|
/// perform remote operation
|
||||||
RemoteOperationResult<String> result;
|
RemoteOperationResult result;
|
||||||
try {
|
try {
|
||||||
CopyMethod copyMethod =
|
CopyMethod copyMethod =
|
||||||
new CopyMethod(new URL(client.getUserFilesWebDavUri() + WebdavUtils.encodePath(mSrcRemotePath)),
|
new CopyMethod(new URL(client.getUserFilesWebDavUri() + WebdavUtils.encodePath(mSrcRemotePath)),
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* ownCloud Android Library is available under MIT license
|
/* ownCloud Android Library is available under MIT license
|
||||||
* Copyright (C) 2016 ownCloud GmbH.
|
* Copyright (C) 2019 ownCloud GmbH.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -33,7 +33,6 @@ import com.owncloud.android.lib.common.network.WebdavUtils;
|
|||||||
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
|
||||||
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
|
|
||||||
import timber.log.Timber;
|
import timber.log.Timber;
|
||||||
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
@ -73,13 +72,7 @@ public class CreateRemoteFolderOperation extends RemoteOperation {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected RemoteOperationResult run(OwnCloudClient client) {
|
protected RemoteOperationResult run(OwnCloudClient client) {
|
||||||
RemoteOperationResult result;
|
RemoteOperationResult result = createFolder(client);
|
||||||
OwnCloudVersion version = client.getOwnCloudVersion();
|
|
||||||
boolean versionWithForbiddenChars =
|
|
||||||
(version != null && version.isVersionWithForbiddenCharacters());
|
|
||||||
boolean noInvalidChars = FileUtils.isValidPath(mRemotePath, versionWithForbiddenChars);
|
|
||||||
if (noInvalidChars) {
|
|
||||||
result = createFolder(client);
|
|
||||||
if (!result.isSuccess() && mCreateFullPath &&
|
if (!result.isSuccess() && mCreateFullPath &&
|
||||||
RemoteOperationResult.ResultCode.CONFLICT == result.getCode()) {
|
RemoteOperationResult.ResultCode.CONFLICT == result.getCode()) {
|
||||||
result = createParentFolder(FileUtils.getParentPath(mRemotePath), client);
|
result = createParentFolder(FileUtils.getParentPath(mRemotePath), client);
|
||||||
@ -87,10 +80,6 @@ public class CreateRemoteFolderOperation extends RemoteOperation {
|
|||||||
result = createFolder(client); // second (and last) try
|
result = createFolder(client); // second (and last) try
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
result = new RemoteOperationResult<>(ResultCode.INVALID_CHARACTER_IN_NAME);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,11 +29,10 @@ import timber.log.Timber;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
public class FileUtils {
|
public class FileUtils {
|
||||||
|
|
||||||
public static final String PATH_SEPARATOR = "/";
|
public static final String PATH_SEPARATOR = "/";
|
||||||
public static final String FINAL_CHUNKS_FILE = ".file";
|
public static final String FINAL_CHUNKS_FILE = ".file";
|
||||||
|
|
||||||
public static String getParentPath(String remotePath) {
|
static String getParentPath(String remotePath) {
|
||||||
String parentPath = new File(remotePath).getParent();
|
String parentPath = new File(remotePath).getParent();
|
||||||
parentPath = parentPath.endsWith(PATH_SEPARATOR) ? parentPath : parentPath + PATH_SEPARATOR;
|
parentPath = parentPath.endsWith(PATH_SEPARATOR) ? parentPath : parentPath + PATH_SEPARATOR;
|
||||||
return parentPath;
|
return parentPath;
|
||||||
@ -42,35 +41,15 @@ public class FileUtils {
|
|||||||
/**
|
/**
|
||||||
* Validate the fileName to detect if contains any forbidden character: / , \ , < , > ,
|
* Validate the fileName to detect if contains any forbidden character: / , \ , < , > ,
|
||||||
* : , " , | , ? , *
|
* : , " , | , ? , *
|
||||||
|
*
|
||||||
|
* @param fileName
|
||||||
|
* @return
|
||||||
*/
|
*/
|
||||||
public static boolean isValidName(String fileName, boolean versionSupportsForbiddenChars) {
|
public static boolean isValidName(String fileName) {
|
||||||
boolean result = true;
|
boolean result = true;
|
||||||
|
|
||||||
Timber.d("fileName =======%s", fileName);
|
Timber.d("fileName =======%s", fileName);
|
||||||
if ((versionSupportsForbiddenChars && fileName.contains(PATH_SEPARATOR)) ||
|
if (fileName.contains(PATH_SEPARATOR)) {
|
||||||
(!versionSupportsForbiddenChars && (fileName.contains(PATH_SEPARATOR) ||
|
|
||||||
fileName.contains("\\") || fileName.contains("<") || fileName.contains(">") ||
|
|
||||||
fileName.contains(":") || fileName.contains("\"") || fileName.contains("|") ||
|
|
||||||
fileName.contains("?") || fileName.contains("*")))) {
|
|
||||||
|
|
||||||
result = false;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Validate the path to detect if contains any forbidden character: \ , < , > , : , " , | ,
|
|
||||||
* ? , *
|
|
||||||
*/
|
|
||||||
public static boolean isValidPath(String path, boolean versionSupportsForbidenChars) {
|
|
||||||
boolean result = true;
|
|
||||||
|
|
||||||
Timber.d("path ....... %s", path);
|
|
||||||
if (!versionSupportsForbidenChars &&
|
|
||||||
(path.contains("\\") || path.contains("<") || path.contains(">") ||
|
|
||||||
path.contains(":") || path.contains("\"") || path.contains("|") ||
|
|
||||||
path.contains("?") || path.contains("*"))) {
|
|
||||||
|
|
||||||
result = false;
|
result = false;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -34,7 +34,6 @@ import com.owncloud.android.lib.common.network.WebdavUtils;
|
|||||||
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
|
||||||
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
|
|
||||||
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
@ -87,16 +86,6 @@ public class MoveRemoteFileOperation extends RemoteOperation {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected RemoteOperationResult run(OwnCloudClient client) {
|
protected RemoteOperationResult run(OwnCloudClient client) {
|
||||||
|
|
||||||
OwnCloudVersion version = client.getOwnCloudVersion();
|
|
||||||
boolean versionWithForbiddenChars =
|
|
||||||
(version != null && version.isVersionWithForbiddenCharacters());
|
|
||||||
|
|
||||||
/// check parameters
|
|
||||||
if (!FileUtils.isValidPath(mTargetRemotePath, versionWithForbiddenChars)) {
|
|
||||||
return new RemoteOperationResult<>(ResultCode.INVALID_CHARACTER_IN_NAME);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mTargetRemotePath.equals(mSrcRemotePath)) {
|
if (mTargetRemotePath.equals(mSrcRemotePath)) {
|
||||||
// nothing to do!
|
// nothing to do!
|
||||||
return new RemoteOperationResult<>(ResultCode.OK);
|
return new RemoteOperationResult<>(ResultCode.OK);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* ownCloud Android Library is available under MIT license
|
/* ownCloud Android Library is available under MIT license
|
||||||
* Copyright (C) 2016 ownCloud GmbH.
|
* Copyright (C) 2019 ownCloud GmbH.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -31,7 +31,6 @@ import com.owncloud.android.lib.common.network.WebdavUtils;
|
|||||||
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
|
||||||
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
|
|
||||||
import timber.log.Timber;
|
import timber.log.Timber;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -84,15 +83,6 @@ public class RenameRemoteFileOperation extends RemoteOperation {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected RemoteOperationResult run(OwnCloudClient client) {
|
protected RemoteOperationResult run(OwnCloudClient client) {
|
||||||
|
|
||||||
final OwnCloudVersion version = client.getOwnCloudVersion();
|
|
||||||
final boolean versionWithForbiddenChars =
|
|
||||||
(version != null && version.isVersionWithForbiddenCharacters());
|
|
||||||
|
|
||||||
if (!FileUtils.isValidPath(mNewRemotePath, versionWithForbiddenChars)) {
|
|
||||||
return new RemoteOperationResult<>(ResultCode.INVALID_CHARACTER_IN_NAME);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (mNewName.equals(mOldName)) {
|
if (mNewName.equals(mOldName)) {
|
||||||
return new RemoteOperationResult<>(ResultCode.OK);
|
return new RemoteOperationResult<>(ResultCode.OK);
|
||||||
|
@ -66,16 +66,14 @@ data class RemoteShare(
|
|||||||
const val MAXIMUM_PERMISSIONS_FOR_FOLDER = MAXIMUM_PERMISSIONS_FOR_FILE +
|
const val MAXIMUM_PERMISSIONS_FOR_FOLDER = MAXIMUM_PERMISSIONS_FOR_FILE +
|
||||||
CREATE_PERMISSION_FLAG +
|
CREATE_PERMISSION_FLAG +
|
||||||
DELETE_PERMISSION_FLAG
|
DELETE_PERMISSION_FLAG
|
||||||
const val FEDERATED_PERMISSIONS_FOR_FILE_UP_TO_OC9 = READ_PERMISSION_FLAG + UPDATE_PERMISSION_FLAG
|
const val FEDERATED_PERMISSIONS_FOR_FILE = READ_PERMISSION_FLAG +
|
||||||
const val FEDERATED_PERMISSIONS_FOR_FILE_AFTER_OC9 = READ_PERMISSION_FLAG +
|
|
||||||
UPDATE_PERMISSION_FLAG +
|
UPDATE_PERMISSION_FLAG +
|
||||||
SHARE_PERMISSION_FLAG
|
SHARE_PERMISSION_FLAG
|
||||||
const val FEDERATED_PERMISSIONS_FOR_FOLDER_UP_TO_OC9 = READ_PERMISSION_FLAG +
|
const val FEDERATED_PERMISSIONS_FOR_FOLDER = READ_PERMISSION_FLAG +
|
||||||
UPDATE_PERMISSION_FLAG +
|
UPDATE_PERMISSION_FLAG +
|
||||||
CREATE_PERMISSION_FLAG +
|
CREATE_PERMISSION_FLAG +
|
||||||
DELETE_PERMISSION_FLAG
|
DELETE_PERMISSION_FLAG +
|
||||||
const val FEDERATED_PERMISSIONS_FOR_FOLDER_AFTER_OC9 =
|
SHARE_PERMISSION_FLAG
|
||||||
FEDERATED_PERMISSIONS_FOR_FOLDER_UP_TO_OC9 + SHARE_PERMISSION_FLAG
|
|
||||||
|
|
||||||
const val INIT_EXPIRATION_DATE_IN_MILLIS: Long = 0
|
const val INIT_EXPIRATION_DATE_IN_MILLIS: Long = 0
|
||||||
const val INIT_SHARED_DATE: Long = 0
|
const val INIT_SHARED_DATE: Long = 0
|
||||||
|
@ -72,7 +72,7 @@ class ShareToRemoteOperationResultParser(private var shareXmlParser: ShareXMLPar
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (serverBaseUri != null) {
|
if (serverBaseUri != null) {
|
||||||
val sharingLinkPath = ShareUtils.getSharingLinkPath(ownCloudVersion)
|
val sharingLinkPath = ShareUtils.SHARING_LINK_PATH
|
||||||
share.shareLink = serverBaseUri.toString() + sharingLinkPath + share.token
|
share.shareLink = serverBaseUri.toString() + sharingLinkPath + share.token
|
||||||
} else {
|
} else {
|
||||||
Timber.e("Couldn't build link for public share :(")
|
Timber.e("Couldn't build link for public share :(")
|
||||||
|
@ -39,14 +39,5 @@ public class ShareUtils {
|
|||||||
public static final String SHARING_API_PATH = "ocs/v2.php/apps/files_sharing/api/v1/shares";
|
public static final String SHARING_API_PATH = "ocs/v2.php/apps/files_sharing/api/v1/shares";
|
||||||
|
|
||||||
// String to build the link with the token of a share:
|
// String to build the link with the token of a share:
|
||||||
public static final String SHARING_LINK_PATH_BEFORE_VERSION_8 = "/public.php?service=files&t=";
|
public static final String SHARING_LINK_PATH = "/index.php/s/";
|
||||||
public static final String SHARING_LINK_PATH_AFTER_VERSION_8 = "/index.php/s/";
|
|
||||||
|
|
||||||
public static String getSharingLinkPath(OwnCloudVersion version) {
|
|
||||||
if (version != null && version.isAfter8Version()) {
|
|
||||||
return SHARING_LINK_PATH_AFTER_VERSION_8;
|
|
||||||
} else {
|
|
||||||
return SHARING_LINK_PATH_BEFORE_VERSION_8;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -45,66 +45,24 @@ class OwnCloudVersion(version: String) : Comparable<OwnCloudVersion>, Parcelable
|
|||||||
INVALID_ZERO_VERSION
|
INVALID_ZERO_VERSION
|
||||||
}
|
}
|
||||||
|
|
||||||
val isChunkedUploadSupported: Boolean
|
val isServerVersionSupported: Boolean
|
||||||
get() = mVersion >= MINIMUN_VERSION_FOR_CHUNKED_UPLOADS
|
get() = mVersion >= MINIMUN_VERSION_SUPPORTED
|
||||||
|
|
||||||
val isSharedSupported: Boolean
|
|
||||||
get() = mVersion >= MINIMUM_VERSION_FOR_SHARING_API
|
|
||||||
|
|
||||||
val isVersionWithForbiddenCharacters: Boolean
|
|
||||||
get() = mVersion >= MINIMUM_VERSION_WITH_FORBIDDEN_CHARS
|
|
||||||
|
|
||||||
val isAfter8Version: Boolean
|
|
||||||
get() = mVersion >= VERSION_8
|
|
||||||
|
|
||||||
val isSearchUsersSupported: Boolean
|
|
||||||
get() = mVersion >= MINIMUM_VERSION_FOR_SEARCHING_USERS
|
|
||||||
|
|
||||||
val isVersionWithCapabilitiesAPI: Boolean
|
|
||||||
get() = mVersion >= MINIMUM_VERSION_CAPABILITIES_API
|
|
||||||
|
|
||||||
val isNotReshareableFederatedSupported: Boolean
|
|
||||||
get() = mVersion >= MINIMUM_VERSION_WITH_NOT_RESHAREABLE_FEDERATED
|
|
||||||
|
|
||||||
val isSessionMonitoringSupported: Boolean
|
|
||||||
get() = mVersion >= MINIMUM_VERSION_WITH_SESSION_MONITORING
|
|
||||||
|
|
||||||
/**
|
|
||||||
* From OC 9.1 session tracking is a feature, but to get it working in the OC app we need the preemptive
|
|
||||||
* mode of basic authentication is disabled. This changes in OC 9.1.3, where preemptive mode is compatible
|
|
||||||
* with session tracking again.
|
|
||||||
*
|
|
||||||
* @return True for every version before 9.1 and from 9.1.3, false otherwise
|
|
||||||
*/
|
|
||||||
val isPreemptiveAuthenticationPreferred: Boolean
|
|
||||||
get() = mVersion < MINIMUM_VERSION_WITH_SESSION_MONITORING || mVersion >= MINIMUM_VERSION_WITH_SESSION_MONITORING_WORKING_IN_PREEMPTIVE_MODE
|
|
||||||
|
|
||||||
val isVersionLowerThan10: Boolean
|
|
||||||
get() = mVersion < VERSION_10
|
|
||||||
|
|
||||||
val isMultiplePublicSharingSupported: Boolean
|
|
||||||
get() = mVersion >= MINIMUM_VERSION_WITH_MULTIPLE_PUBLIC_SHARING
|
|
||||||
|
|
||||||
val isPublicSharingWriteOnlySupported: Boolean
|
val isPublicSharingWriteOnlySupported: Boolean
|
||||||
get() = mVersion >= MINIMUM_VERSION_WITH_WRITE_ONLY_PUBLIC_SHARING
|
get() = mVersion >= MINIMUM_VERSION_WITH_WRITE_ONLY_PUBLIC_SHARING
|
||||||
|
|
||||||
val isPublicUploadPermissionNeeded: Boolean
|
|
||||||
get() = mVersion >= MINIMUN_MAJOR_VERSION_WITHOUT_PUBLIC_UPLOAD_PERMISSION &&
|
|
||||||
(mVersion > MINIMUN_MINOR_VERSION_WITHOUT_PUBLIC_UPLOAD_PERMISSION ||
|
|
||||||
mVersion > MINIMUN_MICRO_VERSION_WITHOUT_PUBLIC_UPLOAD_PERMISSION)
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
var version = version
|
var versionToParse = version
|
||||||
mVersion = 0
|
mVersion = 0
|
||||||
isVersionValid = false
|
isVersionValid = false
|
||||||
val countDots = version.length - version.replace(".", "").length
|
val countDots = versionToParse.length - versionToParse.replace(".", "").length
|
||||||
|
|
||||||
// Complete the version. Version must have 3 dots
|
// Complete the version. Version must have 3 dots
|
||||||
for (i in countDots until MAX_DOTS) {
|
for (i in countDots until MAX_DOTS) {
|
||||||
version = "$version.0"
|
versionToParse = "$versionToParse.0"
|
||||||
}
|
}
|
||||||
|
|
||||||
parseVersion(version)
|
parseVersion(versionToParse)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,10 +80,10 @@ class OwnCloudVersion(version: String) : Comparable<OwnCloudVersion>, Parcelable
|
|||||||
return versionToString
|
return versionToString
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun compareTo(another: OwnCloudVersion): Int {
|
override fun compareTo(other: OwnCloudVersion): Int {
|
||||||
return if (another.mVersion == mVersion)
|
return if (other.mVersion == mVersion)
|
||||||
0
|
0
|
||||||
else if (another.mVersion < mVersion) 1 else -1
|
else if (other.mVersion < mVersion) 1 else -1
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun parseVersion(version: String) {
|
private fun parseVersion(version: String) {
|
||||||
@ -137,20 +95,18 @@ class OwnCloudVersion(version: String) : Comparable<OwnCloudVersion>, Parcelable
|
|||||||
isVersionValid = false
|
isVersionValid = false
|
||||||
// if invalid, the instance will respond as if server is 8.1, minimum with capabilities API,
|
// if invalid, the instance will respond as if server is 8.1, minimum with capabilities API,
|
||||||
// and "dead" : https://github.com/owncloud/core/wiki/Maintenance-and-Release-Schedule
|
// and "dead" : https://github.com/owncloud/core/wiki/Maintenance-and-Release-Schedule
|
||||||
mVersion = MINIMUM_VERSION_CAPABILITIES_API
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Throws(NumberFormatException::class)
|
@Throws(NumberFormatException::class)
|
||||||
private fun getParsedVersion(version: String): Int {
|
private fun getParsedVersion(version: String): Int {
|
||||||
var version = version
|
var versionToParse = version
|
||||||
var versionValue = 0
|
var versionValue = 0
|
||||||
|
|
||||||
// get only numeric part
|
// get only numeric part
|
||||||
version = version.replace("[^\\d.]".toRegex(), "")
|
versionToParse = versionToParse.replace("[^\\d.]".toRegex(), "")
|
||||||
|
|
||||||
val nums = version.split("\\.".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
|
val nums = versionToParse.split("\\.".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
|
||||||
var i = 0
|
var i = 0
|
||||||
while (i < nums.size && i <= MAX_DOTS) {
|
while (i < nums.size && i <= MAX_DOTS) {
|
||||||
versionValue += Integer.parseInt(nums[i])
|
versionValue += Integer.parseInt(nums[i])
|
||||||
@ -163,10 +119,6 @@ class OwnCloudVersion(version: String) : Comparable<OwnCloudVersion>, Parcelable
|
|||||||
return versionValue
|
return versionValue
|
||||||
}
|
}
|
||||||
|
|
||||||
fun supportsRemoteThumbnails(): Boolean {
|
|
||||||
return mVersion >= MINIMUM_SERVER_VERSION_FOR_REMOTE_THUMBNAILS
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun describeContents(): Int {
|
override fun describeContents(): Int {
|
||||||
return super.hashCode()
|
return super.hashCode()
|
||||||
}
|
}
|
||||||
@ -177,36 +129,7 @@ class OwnCloudVersion(version: String) : Comparable<OwnCloudVersion>, Parcelable
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val MINIMUN_MINOR_VERSION_WITHOUT_PUBLIC_UPLOAD_PERMISSION = 0x01000000 // 1.0.0
|
private const val MINIMUN_VERSION_SUPPORTED = 0xA000000 // 10.0.0
|
||||||
|
|
||||||
private const val MINIMUN_MICRO_VERSION_WITHOUT_PUBLIC_UPLOAD_PERMISSION = 0x03000000 // 3.0.0
|
|
||||||
|
|
||||||
const val MINIMUN_VERSION_FOR_CHUNKED_UPLOADS = 0x04050000 // 4.5
|
|
||||||
|
|
||||||
const val MINIMUM_VERSION_FOR_SHARING_API = 0x05001B00 // 5.0.27
|
|
||||||
|
|
||||||
const val MINIMUM_VERSION_WITH_FORBIDDEN_CHARS = 0x08010000 // 8.1
|
|
||||||
|
|
||||||
const val MINIMUM_SERVER_VERSION_FOR_REMOTE_THUMBNAILS = 0x07080000 // 7.8.0
|
|
||||||
|
|
||||||
const val MINIMUM_VERSION_FOR_SEARCHING_USERS = 0x08020000 //8.2
|
|
||||||
|
|
||||||
const val VERSION_8 = 0x08000000 // 8.0
|
|
||||||
|
|
||||||
const val MINIMUM_VERSION_CAPABILITIES_API = 0x08010000 // 8.1
|
|
||||||
|
|
||||||
private const val MINIMUM_VERSION_WITH_NOT_RESHAREABLE_FEDERATED = 0x09010000 // 9.1
|
|
||||||
|
|
||||||
private const val MINIMUM_VERSION_WITH_SESSION_MONITORING = 0x09010000 // 9.1
|
|
||||||
|
|
||||||
private const val MINIMUM_VERSION_WITH_SESSION_MONITORING_WORKING_IN_PREEMPTIVE_MODE = 0x09010301
|
|
||||||
// 9.1.3.1, final 9.1.3: https://github.com/owncloud/core/commit/f9a867b70c217463289a741d4d26079eb2a80dfd
|
|
||||||
|
|
||||||
private const val VERSION_10 = 0xA000000 // 10.0.0
|
|
||||||
|
|
||||||
private const val MINIMUM_VERSION_WITH_MULTIPLE_PUBLIC_SHARING = 0xA000000 // 10.0.0
|
|
||||||
|
|
||||||
private const val MINIMUN_MAJOR_VERSION_WITHOUT_PUBLIC_UPLOAD_PERMISSION = 0xA000000 // 10.0.0
|
|
||||||
|
|
||||||
private const val MINIMUM_VERSION_WITH_WRITE_ONLY_PUBLIC_SHARING = 0xA000100 // 10.0.1
|
private const val MINIMUM_VERSION_WITH_WRITE_ONLY_PUBLIC_SHARING = 0xA000100 // 10.0.1
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user