Skip to content
This repository was archived by the owner on Mar 19, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -381,16 +381,16 @@ private boolean checkUnauthorizedAccess(int status, int repeatCounter) {
* cannot be invalidated with the given arguments.
*/
private boolean shouldInvalidateAccountCredentials(int httpStatusCode) {
boolean shouldInvalidateAccountCredentials =
(httpStatusCode == HttpConstants.HTTP_UNAUTHORIZED);

boolean should = (httpStatusCode == HttpConstants.HTTP_UNAUTHORIZED); // invalid credentials

should &= (mCredentials != null && // real credentials
shouldInvalidateAccountCredentials &= (mCredentials != null && // real credentials
!(mCredentials instanceof OwnCloudCredentialsFactory.OwnCloudAnonymousCredentials));

// 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;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ public class OwnCloudClientManagerFactory {
private static OwnCloudClientManager sDefaultSingleton;
private static String sUserAgent;

public static OwnCloudClientManager newDefaultOwnCloudClientManager() {
private static OwnCloudClientManager newDefaultOwnCloudClientManager() {
return newOwnCloudClientManager(sDefaultPolicy);
}

public static OwnCloudClientManager newOwnCloudClientManager(Policy policy) {
private static OwnCloudClientManager newOwnCloudClientManager(Policy policy) {
switch (policy) {
case ALWAYS_NEW_CLIENT:
return new SimpleFactoryManager();

case SINGLE_SESSION_PER_ACCOUNT_IF_SERVER_SUPPORTS_SERVER_MONITORING:
return new DynamicSessionManager();
case SINGLE_SESSION_PER_ACCOUNT:
return new SingleSessionManager();

default:
throw new IllegalArgumentException("Unknown policy");
Expand All @@ -53,10 +53,6 @@ public static OwnCloudClientManager getDefaultSingleton() {
return sDefaultSingleton;
}

public static Policy getDefaultPolicy() {
return sDefaultPolicy;
}

public static void setDefaultPolicy(Policy policy) {
if (policy == null) {
throw new IllegalArgumentException("Default policy cannot be NULL");
Expand Down Expand Up @@ -84,6 +80,6 @@ private static boolean defaultSingletonMustBeUpdated(Policy policy) {

public enum Policy {
ALWAYS_NEW_CLIENT,
SINGLE_SESSION_PER_ACCOUNT_IF_SERVER_SUPPORTS_SERVER_MONITORING
SINGLE_SESSION_PER_ACCOUNT
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ public static OwnCloudCredentials getCredentialsForAccount(Context context, Acco
boolean isOauth2 = supportsOAuth2 != null && supportsOAuth2.equals("TRUE");

String username = AccountUtils.getUsernameForAccount(account);
OwnCloudVersion version = new OwnCloudVersion(am.getUserData(account, Constants.KEY_OC_VERSION));

if (isOauth2) {
String accessToken = am.blockingGetAuthToken(
Expand All @@ -152,7 +151,6 @@ public static OwnCloudCredentials getCredentialsForAccount(Context context, Acco
false);

credentials = OwnCloudCredentialsFactory.newBearerCredentials(username, accessToken);

} else {
String password = am.blockingGetAuthToken(
account,
Expand All @@ -161,8 +159,7 @@ public static OwnCloudCredentials getCredentialsForAccount(Context context, Acco

credentials = OwnCloudCredentialsFactory.newBasicCredentials(
username,
password,
version.isPreemptiveAuthenticationPreferred()
password
);
}

Expand Down Expand Up @@ -201,9 +198,8 @@ public static String buildAccountName(Uri serverBaseUrl, String username) {
if (url.contains("://")) {
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@ public static OwnCloudCredentials newBasicCredentials(String username, String pa
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) {
return new OwnCloudBearerCredentials(username, authToken);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,12 @@ public RemoteOperationResult(HttpBaseMethod httpMethod) throws IOException {
try {
if (xmlParser.parseXMLResponse(is)) {
mCode = ResultCode.INVALID_CHARACTER_DETECT_IN_SERVER;
} else {
parseErrorMessageAndSetCode(
httpMethod.getResponseBodyAsString(),
ResultCode.SPECIFIC_BAD_REQUEST
);
}

} catch (Exception e) {
Timber.w("Error reading exception from server: %s", e.getMessage());
// mCode stays as set in this(success, httpCode, headers)
Expand Down Expand Up @@ -305,13 +309,12 @@ private RemoteOperationResult(int httpCode, String httpPhrase) {
* @param resultCode our own custom result code
*/
private void parseErrorMessageAndSetCode(String bodyResponse, ResultCode resultCode) {

if (bodyResponse != null && bodyResponse.length() > 0) {
InputStream is = new ByteArrayInputStream(bodyResponse.getBytes());
ErrorMessageParser xmlParser = new ErrorMessageParser();
try {
String errorMessage = xmlParser.parseXMLResponse(is);
if (errorMessage != null && !errorMessage.equals("")) {
if (!errorMessage.equals("")) {
mCode = resultCode;
mHttpPhrase = errorMessage;
}
Expand Down Expand Up @@ -566,6 +569,7 @@ public enum ResultCode {
SERVICE_UNAVAILABLE,
SPECIFIC_SERVICE_UNAVAILABLE,
SPECIFIC_UNSUPPORTED_MEDIA_TYPE,
SPECIFIC_METHOD_NOT_ALLOWED
SPECIFIC_METHOD_NOT_ALLOWED,
SPECIFIC_BAD_REQUEST
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,19 @@
import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
import com.owncloud.android.lib.resources.status.OwnCloudVersion;

import java.net.URL;
import java.util.concurrent.TimeUnit;

/**
* Remote operation moving a remote file or folder in the ownCloud server to a different folder
* in the same account.
* <p>
*
* Allows renaming the moving file/folder at the same time.
*
* @author David A. Velasco
* @author Christian Schabesberger
* @author David González V.
*/
public class CopyRemoteFileOperation extends RemoteOperation<String> {

Expand Down Expand Up @@ -81,14 +81,6 @@ public CopyRemoteFileOperation(String srcRemotePath, String targetRemotePath, bo
*/
@Override
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)) {
// nothing to do!
Expand All @@ -100,7 +92,7 @@ protected RemoteOperationResult<String> run(OwnCloudClient client) {
}

/// perform remote operation
RemoteOperationResult<String> result;
RemoteOperationResult result;
try {
CopyMethod copyMethod =
new CopyMethod(new URL(client.getUserFilesWebDavUri() + WebdavUtils.encodePath(mSrcRemotePath)),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* 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
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -33,7 +33,6 @@
import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
import timber.log.Timber;

import java.net.URL;
Expand Down Expand Up @@ -73,24 +72,14 @@ public CreateRemoteFolderOperation(String remotePath, boolean createFullPath) {
*/
@Override
protected RemoteOperationResult run(OwnCloudClient client) {
RemoteOperationResult result;
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 &&
RemoteOperationResult.ResultCode.CONFLICT == result.getCode()) {
result = createParentFolder(FileUtils.getParentPath(mRemotePath), client);
if (result.isSuccess()) {
result = createFolder(client); // second (and last) try
}
RemoteOperationResult result = createFolder(client);
if (!result.isSuccess() && mCreateFullPath &&
RemoteOperationResult.ResultCode.CONFLICT == result.getCode()) {
result = createParentFolder(FileUtils.getParentPath(mRemotePath), client);
if (result.isSuccess()) {
result = createFolder(client); // second (and last) try
}
} else {
result = new RemoteOperationResult<>(ResultCode.INVALID_CHARACTER_IN_NAME);
}

return result;
}

Expand Down Expand Up @@ -121,4 +110,4 @@ private RemoteOperationResult createParentFolder(String parentPath, OwnCloudClie
RemoteOperation operation = new CreateRemoteFolderOperation(parentPath, mCreateFullPath);
return operation.execute(client);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,10 @@
import java.io.File;

public class FileUtils {

public static final String PATH_SEPARATOR = "/";
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();
parentPath = parentPath.endsWith(PATH_SEPARATOR) ? parentPath : parentPath + PATH_SEPARATOR;
return parentPath;
Expand All @@ -42,35 +41,15 @@ public static String getParentPath(String remotePath) {
/**
* 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;

Timber.d("fileName =======%s", fileName);
if ((versionSupportsForbiddenChars && 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("*"))) {

if (fileName.contains(PATH_SEPARATOR)) {
result = false;
}
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
import com.owncloud.android.lib.resources.status.OwnCloudVersion;

import java.net.URL;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -87,16 +86,6 @@ public MoveRemoteFileOperation(String srcRemotePath,
*/
@Override
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)) {
// nothing to do!
return new RemoteOperationResult<>(ResultCode.OK);
Expand Down
Loading