Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New release 2.2.0 #168

Merged
merged 7 commits into from
Dec 26, 2017
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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: objective-c
osx_image: xcode8.2
osx_image: xcode8.3
#xcode_project: OCCommunicationLib/ownCloud iOS library.xcodeproj
#xcode_scheme: ownCloud iOS library
#xcode_sdk: iphonesimulator
Expand Down
12 changes: 11 additions & 1 deletion Doc_Changelog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
## What's new in 2.1.0 version
## What's new in 2.2.0 version
- Added OAuth2 support with automatic refresh of new tokens
- Added support to new public share link option that allows you to share a folder with only the option of uploading files to it
- Added methods to get user data and features supported by server
- Fix updating share link permissions
- Improved cookies handling
- Improved OCErrors
- Updated travis file


## 2.1.0 version
- Added support multiple share links
- Added new method to get supported server features by version
- Improve error handling
Expand Down
4 changes: 2 additions & 2 deletions OCCommunicationLib/OCCommunicationLib/OCCommunication.h
Original file line number Diff line number Diff line change
Expand Up @@ -511,8 +511,8 @@ typedef enum {
* @param sharedOCCommunication -> OCCommunication Singleton of communication to add the operation on the queue.
*/
- (void) getUserDisplayNameOfServer:(NSString *)path onCommunication:(OCCommunication *)sharedOCCommunication
success:(void(^)(NSHTTPURLResponse *response, NSString *displayName, NSString *redirectedServer))success
failure:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer))failureRequest;
success:(void(^)(NSHTTPURLResponse *response, NSString *serverUserId, NSString *displayName, NSString *redirectedServer))success
failure:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer))failureRequest ;


///-----------------------------------
Expand Down
7 changes: 5 additions & 2 deletions OCCommunicationLib/OCCommunicationLib/OCCommunication.m
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ - (void) getUserDataOfServer:(NSString *)path onCommunication:(OCCommunication *
///-----------------------------------

- (void) getUserDisplayNameOfServer:(NSString *)path onCommunication:(OCCommunication *)sharedOCCommunication
success:(void(^)(NSHTTPURLResponse *response, NSString *displayName, NSString *redirectedServer))success
success:(void(^)(NSHTTPURLResponse *response, NSString *serverUserId, NSString *displayName, NSString *redirectedServer))success
failure:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer))failureRequest {

OCWebDAVClient *request = [OCWebDAVClient new];
Expand All @@ -664,6 +664,7 @@ - (void) getUserDisplayNameOfServer:(NSString *)path onCommunication:(OCCommunic

NSError *jsonError = nil;
NSString *displayName = @"";
NSString *serverUserId = @"";

NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:responseObject options:kNilOptions error:&jsonError];

Expand All @@ -677,13 +678,15 @@ - (void) getUserDisplayNameOfServer:(NSString *)path onCommunication:(OCCommunic
NSDictionary *userDataDict = [ocsDict objectForKey:k_json_ocs_data];

displayName = [userDataDict objectForKey:k_json_ocs_data_display_name];

serverUserId = [userDataDict objectForKey:k_json_ocs_data_user_id];
}

for(NSString *key in [jsonDict allKeys]) {
NSLog(@"%@",[jsonDict objectForKey:key]);
}

success(response, displayName, request.redirectedServer);
success(response, serverUserId, displayName, request.redirectedServer);

} failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
failureRequest(response,error, request.redirectedServer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#define k_json_ocs @"ocs"
#define k_json_ocs_data @"data"
#define k_json_ocs_data_display_name @"display-name"
#define k_json_ocs_data_user_id @"id"

//Url to access to Shared API to create
#define k_url_acces_shared_api @"ocs/v1.php/apps/files_sharing/api/v1/shares"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,21 +101,27 @@ - (NSURLSessionDataTask *)mr_operationWithRequest:(NSMutableURLRequest *)request
self.originalUrlServer = [request.URL absoluteString];
}

NSLog(@"Before adding cookies, Main Request with token");
// NSLog(@"Before adding cookies, Main Request with token for userId:%@ username:%@ url:%@ headers-> %@ ",sharedOCCommunication.credDto.userId, sharedOCCommunication.credDto.userName,request.URL, request.allHTTPHeaderFields);

if (sharedOCCommunication.isCookiesAvailable) {
//We add the cookies of that URL
request = [UtilsFramework getRequestWithCookiesByRequest:request andOriginalUrlServer:self.originalUrlServer];
} else {
[UtilsFramework deleteAllCookies];
}

//NSLog(@"Main Request with token for userId:%@ username:%@ url:%@ headers-> %@ ",sharedOCCommunication.credDto.userId, sharedOCCommunication.credDto.userName,request.URL, request.allHTTPHeaderFields);

__block NSURLSessionDataTask *sessionDataTask;

sessionDataTask = [sharedOCCommunication.networkSessionManager dataTaskWithRequest:request completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) {
if (!error) {
success((NSHTTPURLResponse*)response,responseObject, token);
} else {
if (((NSHTTPURLResponse*)response).statusCode == 401 &&
sharedOCCommunication.credDto.authenticationMethod == AuthenticationMethodBEARER_TOKEN) {
if (((NSHTTPURLResponse*)response).statusCode == 401
&& sharedOCCommunication.credDto.authenticationMethod == AuthenticationMethodBEARER_TOKEN
&& sharedOCCommunication.credDto.userId != nil) {
if (ntimes <= 0) {
if (failure) {
failure((NSHTTPURLResponse*)response, responseObject, error, token);
Expand Down Expand Up @@ -176,21 +182,28 @@ - (NSURLSessionDataTask *)mr_operationWithRequest:(NSMutableURLRequest *)request
self.originalUrlServer = [request.URL absoluteString];
}

NSLog(@"Before adding cookies");
//NSLog(@"Before adding cookies, Request for userId:%@ username:%@ url:%@ headers-> %@ ",sharedOCCommunication.credDto.userId, sharedOCCommunication.credDto.userName,request.URL, request.allHTTPHeaderFields);

if (sharedOCCommunication.isCookiesAvailable) {
//We add the cookies of that URL
request = [UtilsFramework getRequestWithCookiesByRequest:request andOriginalUrlServer:self.originalUrlServer];
} else {
[UtilsFramework deleteAllCookies];
}

// NSLog(@"Request for userId:%@ username:%@ url:%@ headers-> %@ ",sharedOCCommunication.credDto.userId, sharedOCCommunication.credDto.userName,request.URL, request.allHTTPHeaderFields);

__block NSURLSessionDataTask *sessionDataTask;

sessionDataTask = [sharedOCCommunication.networkSessionManager dataTaskWithRequest:request completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) {
if (!error) {
success((NSHTTPURLResponse*)response,responseObject);
} else {

if (((NSHTTPURLResponse*)response).statusCode == 401 && sharedOCCommunication.credDto.authenticationMethod == AuthenticationMethodBEARER_TOKEN) {
if (((NSHTTPURLResponse*)response).statusCode == 401
&& sharedOCCommunication.credDto.authenticationMethod == AuthenticationMethodBEARER_TOKEN
&& sharedOCCommunication.credDto.userId != nil) {
if (ntimes <= 0) {
if (failure) {
failure((NSHTTPURLResponse*)response, responseObject, error);
Expand Down Expand Up @@ -316,7 +329,6 @@ - (void)mr_listPath:(NSString *)path depth:(NSUInteger)depth onCommunication:
[request setHTTPBody:[@"<?xml version=\"1.0\" encoding=\"UTF-8\"?><D:propfind xmlns:D=\"DAV:\"><D:prop><D:resourcetype/><D:getlastmodified/><size xmlns=\"http://owncloud.org/ns\"/><D:creationdate/><id xmlns=\"http://owncloud.org/ns\"/><D:getcontentlength/><D:displayname/><D:quota-available-bytes/><D:getetag/><permissions xmlns=\"http://owncloud.org/ns\"/><D:quota-used-bytes/><D:getcontenttype/></D:prop></D:propfind>" dataUsingEncoding:NSUTF8StringEncoding]];
[request setValue:@"application/xml" forHTTPHeaderField:@"Content-Type"];


NSURLSessionDataTask *sessionDataTask = [self mr_operationWithRequest:request retryingNumberOfTimes:k_retry_ntimes onCommunication:sharedOCCommunication success:success failure:failure];
[self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager];
[sessionDataTask resume];
Expand All @@ -342,7 +354,6 @@ - (void)mr_listPath:(NSString *)path depth:(NSUInteger)depth withUserSessionToke
[request setHTTPBody:[@"<?xml version=\"1.0\" encoding=\"UTF-8\"?><D:propfind xmlns:D=\"DAV:\"><D:prop><D:resourcetype/><D:getlastmodified/><size xmlns=\"http://owncloud.org/ns\"/><D:creationdate/><id xmlns=\"http://owncloud.org/ns\"/><D:getcontentlength/><D:displayname/><D:quota-available-bytes/><D:getetag/><permissions xmlns=\"http://owncloud.org/ns\"/><D:quota-used-bytes/><D:getcontenttype/></D:prop></D:propfind>" dataUsingEncoding:NSUTF8StringEncoding]];
[request setValue:@"application/xml" forHTTPHeaderField:@"Content-Type"];


NSURLSessionDataTask *sessionDataTask = [self mr_operationWithRequest:request retryingNumberOfTimes:k_retry_ntimes onCommunication:sharedOCCommunication withUserSessionToken:token success:success failure:failure];
[self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager];
[sessionDataTask resume];
Expand Down Expand Up @@ -396,7 +407,9 @@ - (NSURLSessionDownloadTask *)downloadTaskWithRequest:(NSMutableURLRequest *)req
if (!error) {
success(response,filePath);
} else {
if (((NSHTTPURLResponse*)response).statusCode == 401 && sharedOCCommunication.credDto.authenticationMethod == AuthenticationMethodBEARER_TOKEN) {
if (((NSHTTPURLResponse*)response).statusCode == 401
&& sharedOCCommunication.credDto.authenticationMethod == AuthenticationMethodBEARER_TOKEN
&& sharedOCCommunication.credDto.userId != nil) {
if (ntimes <= 0) {
if (failure) {
failure(response, error);
Expand Down Expand Up @@ -516,8 +529,9 @@ - (NSURLSessionUploadTask *)uploadTaskWithRequest:(NSMutableURLRequest *)request
if (!error) {
success(response,responseObject);
} else {
if ( ((NSHTTPURLResponse*)response).statusCode == 401 &&
sharedOCCommunication.credDto.authenticationMethod == AuthenticationMethodBEARER_TOKEN ){
if ( ((NSHTTPURLResponse*)response).statusCode == 401
&& sharedOCCommunication.credDto.authenticationMethod == AuthenticationMethodBEARER_TOKEN
&& sharedOCCommunication.credDto.userId != nil){
if (ntimes <= 0) {
if (failure) {
failure(response, responseObject, error);
Expand Down Expand Up @@ -599,13 +613,18 @@ - (NSURLSessionUploadTask *)putWithSessionLocalPath:(NSString *)localSource
self.originalUrlServer = [request.URL absoluteString];
}

NSLog(@"Before adding cookies, Request put");
// NSLog(@"Before adding cookies, Request put for userId:%@ username:%@ url:%@ headers-> %@ ",sharedOCCommunication.credDto.userId, sharedOCCommunication.credDto.userName,request.URL, request.allHTTPHeaderFields);

if (sharedOCCommunication.isCookiesAvailable) {
//We add the cookies of that URL
request = [UtilsFramework getRequestWithCookiesByRequest:request andOriginalUrlServer:self.originalUrlServer];
} else {
[UtilsFramework deleteAllCookies];
}

// NSLog(@"Request put for userId:%@ username:%@ url:%@ headers-> %@ ",sharedOCCommunication.credDto.userId, sharedOCCommunication.credDto.userName,request.URL, request.allHTTPHeaderFields);

NSURL *file = [NSURL fileURLWithPath:localSource];

sharedOCCommunication.uploadSessionManager.responseSerializer = [AFHTTPResponseSerializer serializer];
Expand Down Expand Up @@ -673,8 +692,6 @@ - (void) getStatusOfTheServer:(NSString *)serverPath onCommunication:
_requestMethod = @"GET";

NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path: urlString parameters: nil];

request.HTTPShouldHandleCookies = false;

NSURLSessionDataTask *sessionDataTask = [self mr_operationWithRequest:request retryingNumberOfTimes:k_retry_ntimes onCommunication:sharedOCCommunication success:success failure:failure];
[self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager];
Expand Down Expand Up @@ -743,19 +760,14 @@ - (void)shareByLinkFileOrFolderByServer:(NSString * _Nonnull)serverPath
if (linkName) {
self.postStringForShare = [NSString stringWithFormat:@"%@&name=%@",self.postStringForShare,linkName];
}
if ([publicUpload isEqualToString:@"true"]) {

if (permissions != 0) {
self.postStringForShare = [NSString stringWithFormat:@"%@&permissions=%d",self.postStringForShare,(int)permissions];
} else {
self.postStringForShare = [NSString stringWithFormat:@"%@&publicUpload=%@",self.postStringForShare,@"true"];
}


if (permissions != 0) {
self.postStringForShare = [NSString stringWithFormat:@"%@&permissions=%d",self.postStringForShare,(int)permissions];
} else if ([publicUpload isEqualToString:@"true"]) {
self.postStringForShare = [NSString stringWithFormat:@"%@&publicUpload=%@",self.postStringForShare,@"true"];
} else if ([publicUpload isEqualToString:@"false"]) {

self.postStringForShare = [NSString stringWithFormat:@"%@&publicUpload=%@",self.postStringForShare,@"false"];
}


[request setHTTPBody:[self.postStringForShare dataUsingEncoding:NSUTF8StringEncoding]];

Expand Down Expand Up @@ -860,7 +872,7 @@ - (void) updateShareItem:(NSInteger)shareId

NSParameterAssert(success);

_requestMethod = @"PUT";
_requestMethod = @"PUT";

NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path:serverPath parameters:nil];

Expand All @@ -872,12 +884,10 @@ - (void) updateShareItem:(NSInteger)shareId
self.postStringForShare = [NSString stringWithFormat:@"expireDate=%@",expirationTime];
}else if (linkName) {
self.postStringForShare = [NSString stringWithFormat:@"name=%@",linkName];
} if ([publicUpload isEqualToString:@"true"]) {
if (permissions != 0) {
self.postStringForShare = [NSString stringWithFormat:@"permissions=%d",(int)permissions];
} else {
self.postStringForShare = [NSString stringWithFormat:@"publicUpload=%@",@"true"];
}
} if (permissions != 0) {
self.postStringForShare = [NSString stringWithFormat:@"permissions=%d",(int)permissions];
} else if ([publicUpload isEqualToString:@"true"]) {
self.postStringForShare = [NSString stringWithFormat:@"publicUpload=%@",@"true"];
} else if ([publicUpload isEqualToString:@"false"]) {
self.postStringForShare = [NSString stringWithFormat:@"publicUpload=%@",@"false"];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@ + (NSMutableURLRequest *) getRequestWithCookiesByRequest: (NSMutableURLRequest *
NSArray *cookieStorage = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:[NSURL URLWithString:originalUrlServer]];
NSDictionary *cookieHeaders = [NSHTTPCookie requestHeaderFieldsWithCookies:cookieStorage];

[request setValue:@"" forHTTPHeaderField:@"Cookie"];
for (NSString *key in cookieHeaders) {
[request addValue:cookieHeaders[key] forHTTPHeaderField:key];
}
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# ownCloud iOS Library v 2.1.0
# ownCloud iOS Library v 2.2.0

### Introduction
Using ownCloud iOS library it will be the easiest way to communicate with ownCloud servers.
Expand Down Expand Up @@ -116,6 +116,6 @@ ownCloud iOS library uses some classes based in https://github.com/zwaldowski/D

### Compatibility

ownCloud iOS library supports iOS 8, iOS 9 and iOS10 and works in Xcode 8.
ownCloud iOS library supports iOS 9 and iOS10 and works in Xcode 8.

ownCloud iOS library supports ownCloud server from version 4.5.