12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364 |
- //
- // OCWebDAVClient.m
- // OCWebDAVClient
- //
- // This class is based in https://github.com/zwaldowski/DZWebDAVClient. Copyright (c) 2012 Zachary Waldowski, Troy Brant, Marcus Rohrmoser, and Sam Soffes.
- //
- // Copyright (C) 2016, ownCloud GmbH. ( http://www.owncloud.org/ )
- //
- // Permission is hereby granted, free of charge, to any person obtaining a copy
- // of this software and associated documentation files (the "Software"), to deal
- // in the Software without restriction, including without limitation the rights
- // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- // copies of the Software, and to permit persons to whom the Software is
- // furnished to do so, subject to the following conditions:
- // The above copyright notice and this permission notice shall be included in
- // all copies or substantial portions of the Software.
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- // THE SOFTWARE.
- //
- //
- // Add : getNotificationServer & setNotificationServer
- // Add : getUserProfileServer
- // Add : Support for Favorite
- // Add : getActivityServer
- //
- // Author Marino Faggiana <marino.faggiana@nextcloud.com>
- // Copyright (c) 2017 Marino Faggiana. All rights reserved.
- //
- #import "OCWebDAVClient.h"
- #import "OCFrameworkConstants.h"
- #import "OCCommunication.h"
- #import "UtilsFramework.h"
- #import "AFURLSessionManager.h"
- #import "NSString+Encode.h"
- #import "OCConstants.h"
- #define k_api_user_url_xml @"index.php/ocs/cloud/user"
- #define k_api_user_url_json @"index.php/ocs/cloud/user?format=json"
- #define k_server_information_json @"status.php"
- #define k_api_header_request @"OCS-APIREQUEST"
- #define k_group_sharee_type 1
- NSString const *OCWebDAVContentTypeKey = @"getcontenttype";
- NSString const *OCWebDAVETagKey = @"getetag";
- NSString const *OCWebDAVCTagKey = @"getctag";
- NSString const *OCWebDAVCreationDateKey = @"creationdate";
- NSString const *OCWebDAVModificationDateKey = @"modificationdate";
- @interface OCWebDAVClient()
- - (void)mr_listPath:(NSString *)path depth:(NSString *)depth onCommunication:
- (OCCommunication *)sharedOCCommunication
- success:(void(^)(NSHTTPURLResponse *, id))success
- failure:(void(^)(NSHTTPURLResponse *, id _Nullable responseObject, NSError *))failure;
- @end
- @implementation OCWebDAVClient
- - (id) init {
-
- self = [super init];
-
- if (self != nil) {
- self.defaultHeaders = [NSMutableDictionary new];
- }
-
- return self;
- }
- - (void)setAuthorizationHeaderWithUsername:(NSString *)username password:(NSString *)password {
- NSString *basicAuthCredentials = [NSString stringWithFormat:@"%@:%@", username, password];
- [self.defaultHeaders setObject:[NSString stringWithFormat:@"Basic %@", [UtilsFramework AFBase64EncodedStringFromString: basicAuthCredentials]] forKey:@"Authorization"];
- }
- - (void)setAuthorizationHeaderWithCookie:(NSString *) cookieString {
- [self.defaultHeaders setObject:cookieString forKey:@"Cookie"];
- }
- - (void)setAuthorizationHeaderWithToken:(NSString *)token {
- [self.defaultHeaders setObject:token forKey:@"Authorization"];
- }
- - (void)setDefaultHeader:(NSString *)header value:(NSString *)value {
- [self.defaultHeaders setObject:value forKey:header];
- }
- - (void)setUserAgent:(NSString *)userAgent{
- [self.defaultHeaders setObject:userAgent forKey:@"User-Agent"];
- }
- - (OCHTTPRequestOperation *)mr_operationWithRequest:(NSMutableURLRequest *)request onCommunication:(OCCommunication *)sharedOCCommunication withUserSessionToken:(NSString*)token success:(void(^)(NSHTTPURLResponse *operation, id response, NSString *token))success failure:(void(^)(NSHTTPURLResponse *operation, id _Nullable responseObject, NSError *error, NSString *token))failure {
-
- //If is not nil is a redirection so we keep the original url server
- if (!self.originalUrlServer) {
- self.originalUrlServer = [request.URL absoluteString];
- }
-
- if (sharedOCCommunication.isCookiesAvailable) {
- //We add the cookies of that URL
- request = [UtilsFramework getRequestWithCookiesByRequest:request andOriginalUrlServer:self.originalUrlServer];
- } else {
- [UtilsFramework deleteAllCookies];
- }
-
- OCHTTPRequestOperation *operation = (OCHTTPRequestOperation*) [sharedOCCommunication.networkSessionManager dataTaskWithRequest:request completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) {
- if (!error) {
- success((NSHTTPURLResponse*)response,responseObject, token);
- } else {
- failure((NSHTTPURLResponse*)response, responseObject, error, token);
- }
- }];
-
- return operation;
- }
- - (OCHTTPRequestOperation *)mr_operationWithRequest:(NSMutableURLRequest *)request onCommunication:(OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *, id))success failure:(void(^)(NSHTTPURLResponse *, id _Nullable responseObject, NSError *))failure {
-
- //If is not nil is a redirection so we keep the original url server
- if (!self.originalUrlServer) {
- self.originalUrlServer = [request.URL absoluteString];
- }
-
- if (sharedOCCommunication.isCookiesAvailable) {
- //We add the cookies of that URL
- request = [UtilsFramework getRequestWithCookiesByRequest:request andOriginalUrlServer:self.originalUrlServer];
- } else {
- [UtilsFramework deleteAllCookies];
- }
-
- OCHTTPRequestOperation *operation = (OCHTTPRequestOperation*) [sharedOCCommunication.networkSessionManager dataTaskWithRequest:request completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) {
- if (!error) {
- success((NSHTTPURLResponse*)response,responseObject);
- } else {
- failure((NSHTTPURLResponse*)response, responseObject, error);
- }
- }];
-
- return operation;
-
- }
- - (NSMutableURLRequest *)requestWithMethod:(NSString *)method path:(NSString *)path parameters:(NSDictionary *)parameters timeout:(NSTimeInterval)timeout {
-
- NSMutableURLRequest *request = [[AFHTTPRequestSerializer new] requestWithMethod:method URLString:path parameters:nil error:nil];
- [request setAllHTTPHeaderFields:self.defaultHeaders];
-
- [request setCachePolicy: NSURLRequestReloadIgnoringLocalCacheData];
- [request setTimeoutInterval: timeout];
-
- return request;
- }
- - (NSMutableURLRequest *)sharedRequestWithMethod:(NSString *)method path:(NSString *)path parameters:(NSDictionary *)parameters timeout:(NSTimeInterval)timeout {
-
- NSMutableURLRequest *request = [[AFHTTPRequestSerializer new] requestWithMethod:method URLString:path parameters:nil error:nil];
-
- [request setAllHTTPHeaderFields:self.defaultHeaders];
-
- //NSMutableURLRequest *request = [super requestWithMethod:method path:path parameters:parameters];
- [request setCachePolicy: NSURLRequestReloadIgnoringLocalCacheData];
- [request setTimeoutInterval: k_timeout_webdav];
- //Header for use the OC API CALL
- NSString *ocs_apiquests = @"true";
- [request setValue:ocs_apiquests forHTTPHeaderField:k_api_header_request];
- [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
- [request addValue:@"gzip, deflate" forHTTPHeaderField:@"Accept-Encoding"];
-
- return request;
- }
- - (void)movePath:(NSString *)source toPath:(NSString *)destination
- onCommunication:(OCCommunication *)sharedOCCommunication
- success:(void(^)(NSHTTPURLResponse *, id))success
- failure:(void(^)(NSHTTPURLResponse *, id _Nullable responseObject, NSError *))failure {
- _requestMethod = @"MOVE";
- NSMutableURLRequest *request = [self requestWithMethod:_requestMethod path:source parameters:nil timeout:k_timeout_webdav];
- [request setValue:destination forHTTPHeaderField:@"Destination"];
- [request setValue:@"T" forHTTPHeaderField:@"Overwrite"];
- OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure];
- [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager];
- [operation resume];
- }
- - (void)deletePath:(NSString *)path
- onCommunication:(OCCommunication *)sharedOCCommunication
- success:(void(^)(NSHTTPURLResponse *, id))success
- failure:(void(^)(NSHTTPURLResponse *, id _Nullable responseObject, NSError *))failure {
-
- _requestMethod = @"DELETE";
- NSMutableURLRequest *request = [self requestWithMethod:_requestMethod path:path parameters:nil timeout:k_timeout_webdav];
- OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure];
- [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager];
- [operation resume];
- }
- - (void)mr_listPath:(NSString *)path depth:(NSString *)depth onCommunication:
- (OCCommunication *)sharedOCCommunication
- success:(void(^)(NSHTTPURLResponse *, id))success
- failure:(void(^)(NSHTTPURLResponse *, id _Nullable responseObject, NSError *))failure {
- NSParameterAssert(success);
-
- _requestMethod = @"PROPFIND";
- NSMutableURLRequest *request = [self requestWithMethod:_requestMethod path:path parameters:nil timeout:k_timeout_webdav];
-
- [request setValue: depth forHTTPHeaderField: @"Depth"];
- [request setHTTPBody:[@"<?xml version=\"1.0\" encoding=\"UTF-8\"?><D:propfind xmlns:D=\"DAV:\" xmlns:oc=\"http://owncloud.org/ns\" xmlns:nc=\"http://nextcloud.org/ns\"><D:prop><D:resourcetype/><D:getlastmodified/><size xmlns=\"http://owncloud.org/ns\"/><favorite xmlns=\"http://owncloud.org/ns\"/><id xmlns=\"http://owncloud.org/ns\"/><D:getcontentlength/><D:getetag/><permissions xmlns=\"http://owncloud.org/ns\"/><D:getcontenttype/><nc:is-encrypted/><nc:has-preview/></D:prop></D:propfind>" dataUsingEncoding:NSUTF8StringEncoding]];
- [request setValue:@"application/xml" forHTTPHeaderField:@"Content-Type"];
-
-
- OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure];
- [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager];
- [operation resume];
- }
- - (void)mr_listPath:(NSString *)path depth:(NSString *)depth withUserSessionToken:(NSString*)token onCommunication:
- (OCCommunication *)sharedOCCommunication
- success:(void(^)(NSHTTPURLResponse *operation, id response, NSString *token))success
- failure:(void(^)(NSHTTPURLResponse *response, id _Nullable responseObject, NSError *, NSString *token))failure {
- NSParameterAssert(success);
-
- _requestMethod = @"PROPFIND";
- NSMutableURLRequest *request = [self requestWithMethod:_requestMethod path:path parameters:nil timeout:k_timeout_webdav];
-
- [request setValue: depth forHTTPHeaderField: @"Depth"];
- [request setHTTPBody:[@"<?xml version=\"1.0\" encoding=\"UTF-8\"?><D:propfind xmlns:D=\"DAV:\" xmlns:oc=\"http://owncloud.org/ns\" xmlns:nc=\"http://nextcloud.org/ns\"><D:prop><D:resourcetype/><D:getlastmodified/><size xmlns=\"http://owncloud.org/ns\"/><favorite xmlns=\"http://owncloud.org/ns\"/><id xmlns=\"http://owncloud.org/ns\"/><D:getcontentlength/><D:getetag/><permissions xmlns=\"http://owncloud.org/ns\"/><D:getcontenttype/><nc:is-encrypted/><nc:has-preview/></D:prop></D:propfind>" dataUsingEncoding:NSUTF8StringEncoding]];
- [request setValue:@"application/xml" forHTTPHeaderField:@"Content-Type"];
-
-
- OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication withUserSessionToken:token success:success failure:failure];
- [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager];
- [operation resume];
- }
- - (void)propertiesOfPath:(NSString *)path
- onCommunication: (OCCommunication *)sharedOCCommunication
- success:(void(^)(NSHTTPURLResponse *, id ))success
- failure:(void(^)(NSHTTPURLResponse *, id _Nullable responseObject, NSError *))failure {
- [self mr_listPath:path depth:@"0" onCommunication:sharedOCCommunication success:success failure:failure];
- }
- - (void)listPath:(NSString *)path depth:(NSString *)depth
- onCommunication:(OCCommunication *)sharedOCCommunication
- success:(void(^)(NSHTTPURLResponse *, id))success
- failure:(void(^)(NSHTTPURLResponse *, id _Nullable responseObject, NSError *))failure {
- [self mr_listPath:path depth:depth onCommunication:sharedOCCommunication success:success failure:failure];
- }
- - (void)listPath:(NSString *)path depth:(NSString *)depth
- onCommunication:(OCCommunication *)sharedOCCommunication withUserSessionToken:(NSString *)token
- success:(void(^)(NSHTTPURLResponse *, id, NSString *token))success
- failure:(void(^)(NSHTTPURLResponse *, id _Nullable responseObject, NSError *, NSString *token))failure {
- [self mr_listPath:path depth:depth withUserSessionToken:token onCommunication:sharedOCCommunication success:success failure:failure];
- }
- - (void)search:(NSString *)path folder:(NSString *)folder fileName:(NSString *)fileName depth:(NSString *)depth dateLastModified:(NSString *)dateLastModified contentType:(NSArray *)contentType user:(NSString *)user userID:(NSString *)userID onCommunication:(OCCommunication *)sharedOCCommunication withUserSessionToken:(NSString *)token success:(void(^)(NSHTTPURLResponse *, id, NSString *token))success failure:(void(^)(NSHTTPURLResponse *, id _Nullable responseObject, NSError *, NSString *token))failure {
-
- NSString *body = @"";
- NSString *whereType = @"";
-
- NSParameterAssert(success);
-
- _requestMethod = @"SEARCH";
-
- NSMutableURLRequest *request = [self requestWithMethod:_requestMethod path:path parameters:nil timeout:k_timeout_search];
-
- if (contentType && dateLastModified) {
-
- body = [NSString stringWithFormat: @""
- "<?xml version=\"1.0\"?>"
- "<d:searchrequest xmlns:d=\"DAV:\" xmlns:oc=\"http://owncloud.org/ns\" xmlns:nc=\"http://nextcloud.org/ns\">"
- "<d:basicsearch>"
- "<d:select>"
- "<d:prop>"
- "<d:getlastmodified />"
- "<d:getetag />"
- "<d:getcontenttype />"
- "<d:resourcetype/>"
- "<d:getcontentlength />"
- "<oc:fileid/>"
- "<oc:id/>"
- "<oc:permissions />"
- "<oc:size />"
- "<oc:favorite/>"
- "<nc:is-encrypted/>"
- "<nc:has-preview/>"
- "</d:prop>"
- "</d:select>"
- "<d:from>"
- "<d:scope>"
- "<d:href>/files/%@%@</d:href>"
- "<d:depth>infinity</d:depth>"
- "</d:scope>"
- "</d:from>"
- "<d:where><d:and><d:or>", userID, folder];
-
- for (NSString *type in contentType) {
- whereType = [NSString stringWithFormat: @"%@<d:like><d:prop><d:getcontenttype/></d:prop><d:literal>%@</d:literal></d:like>", whereType, type];
- }
-
- body = [NSString stringWithFormat: @"%@%@</d:or><d:gte><d:prop><d:getlastmodified/></d:prop><d:literal>%@</d:literal></d:gte></d:and></d:where></d:basicsearch></d:searchrequest>", body, whereType, dateLastModified];
-
- } else {
-
- body = [NSString stringWithFormat: @""
- "<?xml version=\"1.0\"?>"
- "<d:searchrequest xmlns:d=\"DAV:\" xmlns:oc=\"http://owncloud.org/ns\" xmlns:nc=\"http://nextcloud.org/ns\">"
- "<d:basicsearch>"
- "<d:select>"
- "<d:prop>"
- "<d:getlastmodified />"
- "<d:getetag />"
- "<d:getcontenttype />"
- "<d:resourcetype/>"
- "<d:getcontentlength />"
- "<oc:fileid/>"
- "<oc:id/>"
- "<oc:permissions />"
- "<oc:size />"
- "<oc:favorite/>"
- "<nc:is-encrypted/>"
- "<nc:has-preview/>"
- "</d:prop>"
- "</d:select>"
- "<d:from>"
- "<d:scope>"
- "<d:href>/files/%@%@</d:href>"
- "<d:depth>infinity</d:depth>"
- "</d:scope>"
- "</d:from>"
- "<d:where>"
- "<d:like>"
- "<d:prop><d:displayname/></d:prop>"
- "<d:literal>%@</d:literal>"
- "</d:like>"
- "</d:where>"
- "</d:basicsearch>"
- "</d:searchrequest>", userID, folder, fileName];
- }
-
- [request setHTTPBody:[body dataUsingEncoding:NSUTF8StringEncoding]];
- [request setValue:@"text/xml" forHTTPHeaderField:@"Content-Type"];
-
- OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication withUserSessionToken:token success:success failure:failure];
- [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager];
- [operation resume];
- }
- - (void)settingFavorite:(NSString * _Nonnull)path favorite:(BOOL)favorite onCommunication:(OCCommunication *)sharedOCCommunication withUserSessionToken:(NSString *)token success:(void(^)(NSHTTPURLResponse *, id, NSString *token))success failure:(void(^)(NSHTTPURLResponse *, id _Nullable responseObject, NSError *, NSString *token))failure {
-
- NSParameterAssert(success);
-
- _requestMethod = @"PROPPATCH";
-
- NSMutableURLRequest *request = [self requestWithMethod:_requestMethod path:path parameters:nil timeout:k_timeout_webdav];
-
- NSString *body;
- body = [NSString stringWithFormat: @""
- "<?xml version=\"1.0\"?>"
- "<d:propertyupdate xmlns:d=\"DAV:\" xmlns:oc=\"http://owncloud.org/ns\" xmlns:nc=\"http://nextcloud.org/ns\">"
- "<d:set>"
- "<d:prop>"
- "<oc:favorite>%i</oc:favorite>"
- "</d:prop>"
- "</d:set>"
- "</d:propertyupdate>", (favorite ? 1 : 0)];
-
- [request setHTTPBody:[body dataUsingEncoding:NSUTF8StringEncoding]];
-
- [request setValue:@"application/xml" forHTTPHeaderField:@"Content-Type"];
-
- OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication withUserSessionToken:token success:success failure:failure];
- [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager];
- [operation resume];
- }
- - (void)listingFavorites:(NSString *)path folder:(NSString *)folder user:(NSString *)user userID:(NSString *)userID onCommunication:(OCCommunication *)sharedOCCommunication withUserSessionToken:(NSString *)token success:(void(^)(NSHTTPURLResponse *, id, NSString *token))success failure:(void(^)(NSHTTPURLResponse *, id _Nullable responseObject, NSError *, NSString *token))failure {
-
- NSString *body;
-
- NSParameterAssert(success);
-
- _requestMethod = @"REPORT";
-
- userID = [userID stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLFragmentAllowedCharacterSet]];
- NSMutableURLRequest *request = [self requestWithMethod:_requestMethod path:[NSString stringWithFormat:@"%@/files/%@%@", path, userID, folder] parameters:nil timeout:k_timeout_webdav];
-
- body = [NSString stringWithFormat: @""
- "<?xml version=\"1.0\"?>"
- "<oc:filter-files xmlns:d=\"DAV:\" xmlns:oc=\"http://owncloud.org/ns\" xmlns:nc=\"http://nextcloud.org/ns\">"
- "<d:prop>"
- "<d:resourcetype/>"
- "<oc:fileid/>"
- "<d:getetag/>"
- "<d:getcontentlength/>"
- "<oc:size/>"
- "<d:getlastmodified/>"
- "<oc:id/>"
- "<oc:permissions/>"
- "<oc:favorite/>"
- "<nc:is-encrypted/>"
- "<nc:has-preview/>"
- "</d:prop>"
- "<oc:filter-rules>"
- "<oc:favorite>1</oc:favorite>"
- "</oc:filter-rules>"
- "</oc:filter-files>"];
-
- [request setHTTPBody:[body dataUsingEncoding:NSUTF8StringEncoding]];
- [request setValue:@"text/xml" forHTTPHeaderField:@"Content-Type"];
-
- OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication withUserSessionToken:token success:success failure:failure];
- [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager];
- [operation resume];
- }
- - (NSURLSessionDownloadTask *)downloadWithSessionPath:(NSString *)remoteSource toPath:(NSString *)localDestination defaultPriority:(BOOL)defaultPriority onCommunication:(OCCommunication *)sharedOCCommunication progress:(void(^)(NSProgress *progress))downloadProgress success:(void(^)(NSURLResponse *response, NSURL *filePath))success failure:(void(^)(NSURLResponse *response, NSError *error))failure{
-
- NSMutableURLRequest *request = [self requestWithMethod:@"GET" path:remoteSource parameters:nil timeout:k_timeout_webdav];
-
- //If is not nil is a redirection so we keep the original url server
- if (!self.originalUrlServer) {
- self.originalUrlServer = [request.URL absoluteString];
- }
-
- //We add the cookies of that URL
- request = [UtilsFramework getRequestWithCookiesByRequest:request andOriginalUrlServer:self.originalUrlServer];
-
- NSURL *localDestinationUrl = [NSURL fileURLWithPath:localDestination];
-
- NSURLSessionDownloadTask *downloadTask = [sharedOCCommunication.downloadSessionManager downloadTaskWithRequest:request progress:^(NSProgress * _Nonnull progress) {
- downloadProgress(progress);
- } destination:^NSURL * _Nonnull(NSURL * _Nonnull targetPath, NSURLResponse * _Nonnull response) {
- return localDestinationUrl;
- } completionHandler:^(NSURLResponse * _Nonnull response, NSURL * _Nullable filePath, NSError * _Nullable error) {
- if (error) {
- failure(response, error);
- } else {
- success(response,filePath);
- }
- }];
-
- [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.downloadSessionManager];
-
-
- if (defaultPriority) {
- [downloadTask resume];
- }
-
- return downloadTask;
- }
- - (void)checkServer:(NSString *)path onCommunication:
- (OCCommunication *)sharedOCCommunication
- success:(void(^)(NSHTTPURLResponse *, id))success
- failure:(void(^)(NSHTTPURLResponse *, id _Nullable responseObject, NSError *))failure {
- _requestMethod = @"HEAD";
- NSMutableURLRequest *request = [self requestWithMethod:_requestMethod path:path parameters:nil timeout:k_timeout_webdav];
- request.HTTPShouldHandleCookies = false;
- OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure];
- [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager];
- [operation resume];
- }
- - (void)makeCollection:(NSString *)path onCommunication:
- (OCCommunication *)sharedOCCommunication
- success:(void(^)(NSHTTPURLResponse *, id))success
- failure:(void(^)(NSHTTPURLResponse *, id _Nullable responseObject, NSError *))failure {
- _requestMethod = @"MKCOL";
- NSMutableURLRequest *request = [self requestWithMethod:_requestMethod path:path parameters:nil timeout:k_timeout_webdav];
- OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure];
- [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager];
- [operation resume];
- }
- - (NSURLSessionUploadTask *)putWithSessionLocalPath:(NSString *)localSource atRemotePath:(NSString *)remoteDestination onCommunication:(OCCommunication *)sharedOCCommunication progress:(void(^)(NSProgress *progress))uploadProgress success:(void(^)(NSURLResponse *, NSString *))success failure:(void(^)(NSURLResponse *, id, NSError *))failure failureBeforeRequest:(void(^)(NSError *)) failureBeforeRequest {
-
- NSFileManager *fileManager = [NSFileManager defaultManager];
-
- if (localSource == nil || ![fileManager fileExistsAtPath:localSource]) {
- NSMutableDictionary* details = [NSMutableDictionary dictionary];
- [details setValue:@"You are trying upload a file that does not exist" forKey:NSLocalizedDescriptionKey];
-
- NSError *error = [NSError errorWithDomain:k_domain_error_code code:OCErrorFileToUploadDoesNotExist userInfo:details];
-
- failureBeforeRequest(error);
-
- return nil;
- } else {
-
- NSMutableURLRequest *request = [self requestWithMethod:@"PUT" path:remoteDestination parameters:nil timeout:k_timeout_webdav];
- [request setTimeoutInterval:k_timeout_upload];
- [request setValue:[NSString stringWithFormat:@"%lld", [UtilsFramework getSizeInBytesByPath:localSource]] forHTTPHeaderField:@"Content-Length"];
- [request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData];
-
- //If is not nil is a redirection so we keep the original url server
- if (!self.originalUrlServer) {
- self.originalUrlServer = [request.URL absoluteString];
- }
-
- if (sharedOCCommunication.isCookiesAvailable) {
- //We add the cookies of that URL
- request = [UtilsFramework getRequestWithCookiesByRequest:request andOriginalUrlServer:self.originalUrlServer];
- } else {
- [UtilsFramework deleteAllCookies];
- }
-
- NSURL *file = [NSURL fileURLWithPath:localSource];
-
- sharedOCCommunication.uploadSessionManager.responseSerializer = [AFHTTPResponseSerializer serializer];
-
- NSURLSessionUploadTask *uploadTask = [sharedOCCommunication.uploadSessionManager uploadTaskWithRequest:request fromFile:file progress:^(NSProgress * _Nonnull progress) {
- uploadProgress(progress);
- } completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) {
- if (error) {
- failure(response, responseObject, error);
- } else {
- success(response,responseObject);
- }
- }];
-
- [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.uploadSessionManager];
- [uploadTask resume];
- return uploadTask;
- }
- }
- - (void) requestUserNameOfServer:(NSString * _Nonnull) path byCookie:(NSString * _Nonnull) cookieString onCommunication:
- (OCCommunication * _Nonnull)sharedOCCommunication success:(void(^ _Nonnull)(NSHTTPURLResponse * _Nonnull, id _Nonnull))success
- failure:(void(^ _Nonnull)(NSHTTPURLResponse * _Nonnull, id _Nullable responseObject, NSError * _Nonnull))failure {
-
- NSString *apiUserUrl = nil;
- apiUserUrl = [NSString stringWithFormat:@"%@%@", path, k_api_user_url_json];
-
- NSLog(@"api user name call: %@", apiUserUrl);
-
- _requestMethod = @"GET";
-
- NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path: apiUserUrl parameters: nil timeout:k_timeout_webdav];
- [request setValue:@"application/xml" forHTTPHeaderField:@"Content-Type"];
-
- OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure];
- [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager];
- [operation resume];
- }
- - (void) getStatusOfTheServer:(NSString *)serverPath onCommunication:
- (OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *operation, id responseObject))success
- failure:(void(^)(NSHTTPURLResponse *operation, id _Nullable responseObject, NSError *error))failure {
-
- NSString *urlString = [NSString stringWithFormat:@"%@%@", serverPath, k_server_information_json];
-
- _requestMethod = @"GET";
-
- NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path: urlString parameters: nil timeout:k_timeout_webdav];
-
- request.HTTPShouldHandleCookies = false;
-
- OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure];
- [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager];
- [operation resume];
- }
- - (void)listSharedByServer:(NSString *)serverPath
- onCommunication:(OCCommunication *)sharedOCCommunication
- success:(void(^)(NSHTTPURLResponse *, id))success
- failure:(void(^)(NSHTTPURLResponse *, id _Nullable responseObject, NSError *))failure {
-
- NSParameterAssert(success);
-
- _requestMethod = @"GET";
-
- NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path:serverPath parameters:nil timeout:k_timeout_webdav];
-
- OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure];
- [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager];
- [operation resume];
- }
- - (void)listSharedByServer:(NSString *)serverPath andPath:(NSString *) path
- onCommunication:(OCCommunication *)sharedOCCommunication
- success:(void(^)(NSHTTPURLResponse *, id))success
- failure:(void(^)(NSHTTPURLResponse *, id _Nullable responseObject, NSError *))failure {
-
- NSParameterAssert(success);
-
- NSString *postString = [NSString stringWithFormat: @"?path=%@&subfiles=true",path];
- serverPath = [serverPath stringByAppendingString:postString];
- _requestMethod = @"GET";
-
- NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path:serverPath parameters:nil timeout:k_timeout_webdav];
-
- OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure];
- [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager];
- [operation resume];
- }
- - (void)shareByLinkFileOrFolderByServer:(NSString *)serverPath andPath:(NSString *) filePath andPassword:(NSString *)password andPermission:(NSInteger)permission andHideDownload:(BOOL)hideDownload
- onCommunication:(OCCommunication *)sharedOCCommunication
- success:(void(^)(NSHTTPURLResponse *, id))success
- failure:(void(^)(NSHTTPURLResponse *, id _Nullable responseObject, NSError *))failure {
- NSParameterAssert(success);
-
- _requestMethod = @"POST";
-
- NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path:serverPath parameters:nil timeout:k_timeout_webdav];
- _postStringForShare = [NSString stringWithFormat: @"path=%@&shareType=3&permissions=%ld&password=%@&hidedownload=%i", filePath, (long)permission, password, hideDownload];
- [request setHTTPBody:[_postStringForShare dataUsingEncoding:NSUTF8StringEncoding]];
-
- OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure];
- [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager];
- [operation resume];
- }
- - (void)shareByLinkFileOrFolderByServer:(NSString *)serverPath andPath:(NSString *) filePath
- onCommunication:(OCCommunication *)sharedOCCommunication
- success:(void(^)(NSHTTPURLResponse *, id))success
- failure:(void(^)(NSHTTPURLResponse *, id _Nullable responseObject, NSError *))failure {
- NSParameterAssert(success);
-
- _requestMethod = @"POST";
-
- NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path:serverPath parameters:nil timeout:k_timeout_webdav];
- _postStringForShare = [NSString stringWithFormat: @"path=%@&shareType=3",filePath];
- [request setHTTPBody:[_postStringForShare dataUsingEncoding:NSUTF8StringEncoding]];
-
- OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure];
- [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager];
- [operation resume];
- }
- - (void)shareWith:(NSString *)userOrGroup shareeType:(NSInteger)shareeType inServer:(NSString *) serverPath andPath:(NSString *) filePath andPermissions:(NSInteger) permissions onCommunication:(OCCommunication *)sharedOCCommunication
- success:(void(^)(NSHTTPURLResponse *, id))success
- failure:(void(^)(NSHTTPURLResponse *, id _Nullable responseObject, NSError *))failure {
- NSParameterAssert(success);
-
- _requestMethod = @"POST";
-
- NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path:serverPath parameters:nil timeout:k_timeout_webdav];
-
- self.postStringForShare = [NSString stringWithFormat: @"path=%@&shareType=%ld&shareWith=%@&permissions=%ld",filePath, (long)shareeType, userOrGroup, (long)permissions];
- [request setHTTPBody:[_postStringForShare dataUsingEncoding:NSUTF8StringEncoding]];
-
- OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure];
- [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager];
- [operation resume];
- }
- - (void)unShareFileOrFolderByServer:(NSString *)serverPath
- onCommunication:(OCCommunication *)sharedOCCommunication
- success:(void(^)(NSHTTPURLResponse *, id))success
- failure:(void(^)(NSHTTPURLResponse *, id _Nullable responseObject, NSError *))failure {
- NSParameterAssert(success);
-
- _requestMethod = @"DELETE";
-
- NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path:serverPath parameters:nil timeout:k_timeout_webdav];
-
- OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure];
- [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager];
- [operation resume];
- }
- - (void)isShareFileOrFolderByServer:(NSString *)serverPath
- onCommunication:(OCCommunication *)sharedOCCommunication
- success:(void(^)(NSHTTPURLResponse *, id))success
- failure:(void(^)(NSHTTPURLResponse *, id _Nullable responseObject, NSError *))failure {
- NSParameterAssert(success);
-
- _requestMethod = @"GET";
-
- NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path:serverPath parameters:nil timeout:k_timeout_webdav];
-
- OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure];
- [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager];
- [operation resume];
- }
- - (void) updateShareItem:(NSInteger)shareId ofServerPath:(NSString*)serverPath withPasswordProtect:(NSString*)password andExpirationTime:(NSString*)expirationTime andPermissions:(NSInteger)permissions andHideDownload:(BOOL)hideDownload
- onCommunication:(OCCommunication *)sharedOCCommunication
- success:(void(^)(NSHTTPURLResponse *, id response))success
- failure:(void(^)(NSHTTPURLResponse *, id _Nullable responseObject, NSError *error))failure{
-
- NSParameterAssert(success);
-
- _requestMethod = @"PUT";
-
- NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path:serverPath parameters:nil timeout:k_timeout_webdav];
-
- if (password) {
- self.postStringForShare = [NSString stringWithFormat:@"password=%@&",password];
- } else if (expirationTime) {
- self.postStringForShare = [NSString stringWithFormat:@"expireDate=%@",expirationTime];
- } else if (permissions > 0) {
- self.postStringForShare = [NSString stringWithFormat:@"permissions=%ld",(long)permissions];
- } else {
- if (hideDownload) self.postStringForShare = [NSString stringWithFormat:@"hideDownload=true"];
- else self.postStringForShare = [NSString stringWithFormat:@"hideDownload=false"];
- }
-
- [request setHTTPBody:[_postStringForShare dataUsingEncoding:NSUTF8StringEncoding]];
-
- OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure];
- [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager];
- [operation resume];
- }
- - (void) searchUsersAndGroupsWith:(NSString *)searchString forPage:(NSInteger)page with:(NSInteger)resultsPerPage ofServer:(NSString*)serverPath onCommunication:(OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *operation, id response))success
- failure:(void(^)(NSHTTPURLResponse *operation, id _Nullable responseObject, NSError *error))failure {
-
- NSParameterAssert(success);
-
- _requestMethod = @"GET";
-
- NSString *searchQuery = [NSString stringWithFormat: @"&search=%@",searchString];
- NSString *jsonQuery = [NSString stringWithFormat:@"?format=json"];
- NSString *queryType = [NSString stringWithFormat:@"&itemType=file"];
- NSString *pagination = [NSString stringWithFormat:@"&page=%ld&perPage=%ld", (long)page, (long)resultsPerPage];
- serverPath = [serverPath stringByAppendingString:jsonQuery];
- serverPath = [serverPath stringByAppendingString:queryType];
- serverPath = [serverPath stringByAppendingString:searchQuery];
- serverPath = [serverPath stringByAppendingString:pagination];
- NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path:serverPath parameters:nil timeout:k_timeout_webdav];
-
- OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure];
- [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager];
- [operation resume];
- }
- - (void)getSharePermissionsFile:(NSString*)fileName onCommunication:(OCCommunication *)sharedOCCommunication
- success:(void(^)(NSHTTPURLResponse *, id))success
- failure:(void(^)(NSHTTPURLResponse *, id _Nullable responseObject, NSError *))failure {
-
- NSParameterAssert(success);
-
- _requestMethod = @"PROPFIND";
- NSMutableURLRequest *request = [self requestWithMethod:_requestMethod path:fileName parameters:nil timeout:k_timeout_webdav];
-
- [request setHTTPBody:[@"<?xml version=\"1.0\" encoding=\"UTF-8\"?><a:propfind xmlns:a=\"DAV:\" xmlns:b=\"http://open-collaboration-services.org/ns\"><a:prop><b:share-permissions/></a:prop></a:propfind>" dataUsingEncoding:NSUTF8StringEncoding]];
-
- [request setValue:@"application/xml" forHTTPHeaderField:@"Content-Type"];
-
- OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure];
- [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager];
-
- [operation resume];
- }
- - (void) getCapabilitiesOfServer:(NSString*)serverPath onCommunication:(OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *operation, id response))success failure:(void(^)(NSHTTPURLResponse *operation, id _Nullable responseObject, NSError *error))failure{
- _requestMethod = @"GET";
-
- serverPath = [serverPath stringByAppendingString:[NSString stringWithFormat:@"?format=json"]];
-
- NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path:serverPath parameters:nil timeout:k_timeout_webdav];
-
- OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure];
- [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager];
- [operation resume];
- }
- #pragma mark - Remote thumbnails
- - (OCHTTPRequestOperation *) getRemoteThumbnailByServer:(NSString*)serverPath ofFilePath:(NSString*)filePath withWidth:(NSInteger)fileWidth andHeight:(NSInteger)fileHeight onCommunication:(OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *operation, id response))success failure:(void(^)(NSHTTPURLResponse *operation, id _Nullable responseObject, NSError *error))failure{
- _requestMethod = @"GET";
-
- NSString *query = [NSString stringWithFormat:@"/index.php/apps/files/api/v1/thumbnail/%i/%i/%@", (int)fileWidth, (int)fileHeight, filePath];
- serverPath = [serverPath stringByAppendingString:query];
-
- NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path:serverPath parameters:nil timeout:k_timeout_webdav];
-
- OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure];
- [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager];
-
- return operation;
- }
- - (OCHTTPRequestOperation *) getRemotePreviewByServer:(NSString *)serverPath ofFilePath:(NSString *)filePath withWidth:(NSInteger)fileWidth andHeight:(NSInteger)fileHeight andA:(NSInteger)a andMode:(NSString *)mode path:(NSString *)path onCommunication:(OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *operation, id response))success failure:(void(^)(NSHTTPURLResponse *operation, id _Nullable responseObject, NSError *error))failure {
-
- _requestMethod = @"GET";
-
- if (path.length > 0) {
- serverPath = path;
- } else {
- NSString *query = [NSString stringWithFormat:@"/index.php/core/preview.png?file=%@&x=%d&y=%d&a=%d&mode=%@", filePath, (int)fileWidth, (int)fileHeight, (int)a, mode];
- serverPath = [serverPath stringByAppendingString:query];
- }
-
- NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path:serverPath parameters:nil timeout:k_timeout_webdav];
-
- OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure];
- [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager];
-
- return operation;
- }
- - (OCHTTPRequestOperation *) getRemotePreviewTrashByServer:(NSString *)serverPath ofFileID:(NSString*)fileID onCommunication:(OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *operation, id response))success failure:(void(^)(NSHTTPURLResponse *operation, id _Nullable responseObject, NSError *error))failure {
-
- _requestMethod = @"GET";
-
- NSString *query = [NSString stringWithFormat:@"/index.php/apps/files_trashbin/preview?fileId=%@&x=128&y=128", fileID];
- serverPath = [serverPath stringByAppendingString:query];
-
- NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path:serverPath parameters:nil timeout:k_timeout_webdav];
-
- OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure];
- [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager];
-
- return operation;
- }
- #pragma mark - Get Notification
- - (void)getNotificationServer:(NSString*)serverPath onCommunication:(OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *operation, id response))success failure:(void(^)(NSHTTPURLResponse *operation, id _Nullable responseObject, NSError *error))failure{
-
- _requestMethod = @"GET";
- serverPath = [serverPath stringByAppendingString:[NSString stringWithFormat:@"?format=json"]];
-
- NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path:serverPath parameters:nil timeout:k_timeout_webdav];
-
- OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure];
- [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager];
- [operation resume];
- }
- - (void)setNotificationServer:(NSString *)serverPath type:(NSString *)type onCommunication:(OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *, id))success failure:(void(^)(NSHTTPURLResponse *, id _Nullable responseObject, NSError *))failure {
-
- NSParameterAssert(success);
-
- _requestMethod = type;
-
- NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path:serverPath parameters:nil timeout:k_timeout_webdav];
-
- OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure];
- [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager];
- [operation resume];
- }
- - (void)subscribingNextcloudServerPush:(NSString *)serverPath pushTokenHash:(NSString *)pushTokenHash devicePublicKey:(NSString *)devicePublicKey proxyServerPath:(NSString *)proxyServerPath onCommunication:(OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *, id))success failure:(void(^)(NSHTTPURLResponse *, id _Nullable responseObject, NSError *))failure {
-
- NSParameterAssert(success);
-
- _requestMethod = @"POST";
-
- serverPath = [serverPath stringByAppendingString:[NSString stringWithFormat:@"?format=json"]];
- serverPath = [serverPath stringByAppendingString:[NSString stringWithFormat:@"&pushTokenHash=%@",pushTokenHash]];
- serverPath = [serverPath stringByAppendingString:[NSString stringWithFormat:@"&devicePublicKey=%@",devicePublicKey]];
- serverPath = [serverPath stringByAppendingString:[NSString stringWithFormat:@"&proxyServer=%@",proxyServerPath]];
- NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path:serverPath parameters:nil timeout:k_timeout_webdav];
- OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure];
- [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager];
- [operation resume];
- }
- - (void)unsubscribingNextcloudServerPush:(NSString *)serverPath onCommunication:(OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *, id))success failure:(void(^)(NSHTTPURLResponse *, id _Nullable responseObject, NSError *))failure {
-
- NSParameterAssert(success);
-
- _requestMethod = @"DELETE";
-
- serverPath = [serverPath stringByAppendingString:[NSString stringWithFormat:@"?format=json"]];
-
- NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path:serverPath parameters:nil timeout:k_timeout_webdav];
-
- OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure];
- [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager];
- [operation resume];
- }
- - (void)subscribingPushProxy:(NSString *)serverPath pushToken:(NSString *)pushToken deviceIdentifier:(NSString *)deviceIdentifier deviceIdentifierSignature:(NSString *)deviceIdentifierSignature publicKey:(NSString *)publicKey onCommunication:(OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *, id))success failure:(void(^)(NSHTTPURLResponse *, id _Nullable responseObject, NSError *))failure {
-
- NSParameterAssert(success);
-
- _requestMethod = @"POST";
-
- serverPath = [serverPath stringByAppendingString:[NSString stringWithFormat:@"?format=json"]];
- serverPath = [serverPath stringByAppendingString:[NSString stringWithFormat:@"&pushToken=%@",pushToken]];
- serverPath = [serverPath stringByAppendingString:[NSString stringWithFormat:@"&deviceIdentifier=%@",deviceIdentifier]];
- serverPath = [serverPath stringByAppendingString:[NSString stringWithFormat:@"&deviceIdentifierSignature=%@",deviceIdentifierSignature]];
- serverPath = [serverPath stringByAppendingString:[NSString stringWithFormat:@"&userPublicKey=%@",publicKey]];
-
- NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path:serverPath parameters:nil timeout:k_timeout_webdav];
-
- [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
-
- OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure];
- [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager];
- [operation resume];
- }
- - (void)unsubscribingPushProxy:(NSString *)serverPath deviceIdentifier:(NSString *)deviceIdentifier deviceIdentifierSignature:(NSString *)deviceIdentifierSignature publicKey:(NSString *)publicKey onCommunication:(OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *, id))success failure:(void(^)(NSHTTPURLResponse *, id _Nullable responseObject, NSError *))failure {
-
- NSParameterAssert(success);
-
- _requestMethod = @"DELETE";
-
- serverPath = [serverPath stringByAppendingString:[NSString stringWithFormat:@"?format=json"]];
- serverPath = [serverPath stringByAppendingString:[NSString stringWithFormat:@"&deviceIdentifier=%@",deviceIdentifier]];
- serverPath = [serverPath stringByAppendingString:[NSString stringWithFormat:@"&deviceIdentifierSignature=%@",deviceIdentifierSignature]];
- serverPath = [serverPath stringByAppendingString:[NSString stringWithFormat:@"&userPublicKey=%@",publicKey]];
-
- NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path:serverPath parameters:nil timeout:k_timeout_webdav];
-
- [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
-
- OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure];
- [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager];
- [operation resume];
- }
- #pragma mark - Get Activity
- - (void) getActivityServer:(NSString*)serverPath since:(NSInteger)since onCommunication:(OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *operation, id response))success failure:(void(^)(NSHTTPURLResponse *operation, id _Nullable responseObject, NSError *error))failure{
-
- _requestMethod = @"GET";
-
- since = 0;
- //serverPath = [serverPath stringByAppendingString:[NSString stringWithFormat:@"?format=json&since=%ld", (long)since]];
- serverPath = [serverPath stringByAppendingString:[NSString stringWithFormat:@"?format=json&limit=100"]];
- serverPath = [serverPath stringByAppendingString:[NSString stringWithFormat:@"&previews=true"]];
-
- NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path:serverPath parameters:nil timeout:k_timeout_webdav];
-
- OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure];
- [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager];
- [operation resume];
- }
- #pragma mark - Get External sites
- - (void) getExternalSitesServer:(NSString*)serverPath onCommunication:(OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *operation, id response))success failure:(void(^)(NSHTTPURLResponse *operation, id _Nullable responseObject, NSError *error))failure{
-
- _requestMethod = @"GET";
-
- serverPath = [serverPath stringByAppendingString:[NSString stringWithFormat:@"?format=json"]];
-
- NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path:serverPath parameters:nil timeout:k_timeout_webdav];
-
- OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure];
- [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager];
- [operation resume];
- }
- #pragma mark - Get User Profile
- - (void) getUserProfileServer:(NSString*)serverPath onCommunication:(OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *operation, id response))success failure:(void(^)(NSHTTPURLResponse *operation, id _Nullable responseObject, NSError *error))failure{
-
- _requestMethod = @"GET";
-
- serverPath = [serverPath stringByAppendingString:[NSString stringWithFormat:@"?format=json"]];
-
- NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path:serverPath parameters:nil timeout:k_timeout_webdav];
- OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure];
- [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager];
- [operation resume];
- }
- #pragma mark - End-to-End Encryption
- - (void)getEndToEndPublicKeys:(NSString*)serverPath onCommunication:(OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *operation, id response))success failure:(void(^)(NSHTTPURLResponse *operation, id _Nullable responseObject, NSError *error))failure{
-
- _requestMethod = @"GET";
-
- NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path:serverPath parameters:nil timeout:k_timeout_webdav];
- [request setValue:@"true" forHTTPHeaderField:@"OCS-APIRequest"];
- OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure];
- [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager];
- [operation resume];
- }
- - (void)getEndToEndPrivateKeyCipher:(NSString*)serverPath onCommunication:(OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *operation, id response))success failure:(void(^)(NSHTTPURLResponse *operation, id _Nullable responseObject, NSError *error))failure{
-
- _requestMethod = @"GET";
-
- NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path:serverPath parameters:nil timeout:k_timeout_webdav];
- [request setValue:@"true" forHTTPHeaderField:@"OCS-APIRequest"];
- OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure];
- [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager];
- [operation resume];
- }
- - (void)getEndToEndServerPublicKey:(NSString*)serverPath onCommunication:(OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *operation, id response))success failure:(void(^)(NSHTTPURLResponse *operation, id _Nullable responseObject, NSError *error))failure{
-
- _requestMethod = @"GET";
-
- NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path:serverPath parameters:nil timeout:k_timeout_webdav];
- [request setValue:@"true" forHTTPHeaderField:@"OCS-APIRequest"];
- OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure];
- [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager];
- [operation resume];
- }
- - (void)signEndToEndPublicKey:(NSString*)serverPath key:(NSString *)key onCommunication:(OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *operation, id response))success failure:(void(^)(NSHTTPURLResponse *operation, id _Nullable responseObject, NSError *error))failure{
-
- NSParameterAssert(success);
-
- _requestMethod = @"POST";
-
- NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path:serverPath parameters:nil timeout:k_timeout_webdav];
- [request setValue:@"true" forHTTPHeaderField:@"OCS-APIRequest"];
- _postStringKey = [NSString stringWithFormat: @"csr=%@",key];
- [request setHTTPBody:[_postStringKey dataUsingEncoding:NSUTF8StringEncoding]];
-
- OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure];
- [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager];
-
- [operation resume];
- }
- - (void)storeEndToEndPrivateKeyCipher:(NSString*)serverPath key:(NSString *)key onCommunication:(OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *operation, id response))success failure:(void(^)(NSHTTPURLResponse *operation, id _Nullable responseObject, NSError *error))failure{
-
- NSParameterAssert(success);
-
- _requestMethod = @"POST";
-
- NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path:serverPath parameters:nil timeout:k_timeout_webdav];
- [request setValue:@"true" forHTTPHeaderField:@"OCS-APIRequest"];
- _postStringKey = [NSString stringWithFormat: @"privateKey=%@",key];
- [request setHTTPBody:[_postStringKey dataUsingEncoding:NSUTF8StringEncoding]];
-
- OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure];
- [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager];
-
- [operation resume];
- }
- - (void)deleteEndToEndPublicKey:(NSString*)serverPath onCommunication:(OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *operation, id response))success failure:(void(^)(NSHTTPURLResponse *operation, id _Nullable responseObject, NSError *error))failure{
-
- _requestMethod = @"DELETE";
-
- NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path:serverPath parameters:nil timeout:k_timeout_webdav];
- [request setValue:@"true" forHTTPHeaderField:@"OCS-APIRequest"];
- OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure];
- [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager];
- [operation resume];
- }
- - (void)deleteEndToEndPrivateKey:(NSString*)serverPath onCommunication:(OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *operation, id response))success failure:(void(^)(NSHTTPURLResponse *operation, id _Nullable responseObject, NSError *error))failure{
-
- _requestMethod = @"DELETE";
-
- NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path:serverPath parameters:nil timeout:k_timeout_webdav];
- [request setValue:@"true" forHTTPHeaderField:@"OCS-APIRequest"];
- OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure];
- [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager];
- [operation resume];
- }
- - (void)markEndToEndFolderEncrypted:(NSString*)serverPath onCommunication:(OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *operation, id response))success failure:(void(^)(NSHTTPURLResponse *operation, id _Nullable responseObject, NSError *error))failure{
-
- _requestMethod = @"PUT";
-
- NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path:serverPath parameters:nil timeout:k_timeout_webdav];
- [request setValue:@"true" forHTTPHeaderField:@"OCS-APIRequest"];
- OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure];
- [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager];
- [operation resume];
- }
- - (void)deletemarkEndToEndFolderEncrypted:(NSString*)serverPath onCommunication:(OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *operation, id response))success failure:(void(^)(NSHTTPURLResponse *operation, id _Nullable responseObject, NSError *error))failure{
-
- _requestMethod = @"DELETE";
-
- NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path:serverPath parameters:nil timeout:k_timeout_webdav];
- [request setValue:@"true" forHTTPHeaderField:@"OCS-APIRequest"];
- OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure];
- [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager];
- [operation resume];
- }
- - (void)lockEndToEndFolderEncrypted:(NSString*)serverPath onCommunication:(OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *operation, id response))success failure:(void(^)(NSHTTPURLResponse *operation, id _Nullable responseObject, NSError *error))failure{
-
- _requestMethod = @"POST";
-
- NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path:serverPath parameters:nil timeout:k_timeout_webdav];
- [request setValue:@"true" forHTTPHeaderField:@"OCS-APIRequest"];
- OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure];
- [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager];
- [operation resume];
- }
- - (void)unlockEndToEndFolderEncrypted:(NSString*)serverPath token:(NSString *)token onCommunication:(OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *operation, id response))success failure:(void(^)(NSHTTPURLResponse *operation, id _Nullable responseObject, NSError *error))failure{
-
- _requestMethod = @"DELETE";
-
- NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path:serverPath parameters:nil timeout:k_timeout_webdav];
- [request setValue:@"true" forHTTPHeaderField:@"OCS-APIRequest"];
-
- // Add token
- [request setValue:token forHTTPHeaderField:@"token"];
- OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure];
- [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager];
- [operation resume];
- }
- - (void)getEndToEndMetadata:(NSString*)serverPath onCommunication:(OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *operation, id response))success failure:(void(^)(NSHTTPURLResponse *operation, id _Nullable responseObject, NSError *error))failure{
-
- NSParameterAssert(success);
-
- _requestMethod = @"GET";
-
- NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path:serverPath parameters:nil timeout:k_timeout_webdav];
- [request setValue:@"true" forHTTPHeaderField:@"OCS-APIRequest"];
-
- OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure];
- [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager];
-
- [operation resume];
- }
- - (void)storeEndToEndMetadata:(NSString*)serverPath metadata:(NSString *)metadata onCommunication:(OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *operation, id response))success failure:(void(^)(NSHTTPURLResponse *operation, id _Nullable responseObject, NSError *error))failure{
-
- NSParameterAssert(success);
-
- _requestMethod = @"POST";
-
- NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path:serverPath parameters:nil timeout:k_timeout_webdav];
- [request setValue:@"true" forHTTPHeaderField:@"OCS-APIRequest"];
-
- _postStringMetadata = [NSString stringWithFormat: @"metaData=%@",metadata];
- [request setHTTPBody:[_postStringMetadata dataUsingEncoding:NSUTF8StringEncoding]];
- OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure];
- [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager];
-
- [operation resume];
- }
- - (void)updateEndToEndMetadata:(NSString*)serverPath metadata:(NSString *)metadata onCommunication:(OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *operation, id response))success failure:(void(^)(NSHTTPURLResponse *operation, id _Nullable responseObject, NSError *error))failure{
-
- NSParameterAssert(success);
-
- _requestMethod = @"PUT";
-
- NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path:serverPath parameters:nil timeout:k_timeout_webdav];
- [request setValue:@"true" forHTTPHeaderField:@"OCS-APIRequest"];
- _postStringMetadata = [NSString stringWithFormat: @"metaData=%@",metadata];
- [request setHTTPBody:[_postStringMetadata dataUsingEncoding:NSUTF8StringEncoding]];
- OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure];
- [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager];
-
- [operation resume];
- }
- - (void)deleteEndToEndMetadata:(NSString*)serverPath onCommunication:(OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *operation, id response))success failure:(void(^)(NSHTTPURLResponse *operation, id _Nullable responseObject, NSError *error))failure {
-
- NSParameterAssert(success);
-
- _requestMethod = @"DELETE";
-
- NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path:serverPath parameters:nil timeout:k_timeout_webdav];
- [request setValue:@"true" forHTTPHeaderField:@"OCS-APIRequest"];
- OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure];
- [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager];
-
- [operation resume];
- }
- #pragma mark - Manage Mobile Editor OCS API
- - (void)createLinkRichdocuments:(NSString *)serverPath fileID:(NSString *)fileID onCommunication:(OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *operation, id response))success failure:(void(^)(NSHTTPURLResponse *operation, id _Nullable responseObject, NSError *error))failure {
-
- NSParameterAssert(success);
-
- _requestMethod = @"POST";
-
- NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path:serverPath parameters:nil timeout:k_timeout_webdav];
- [request setValue:@"true" forHTTPHeaderField:@"OCS-APIRequest"];
- [request setHTTPBody:[[NSString stringWithFormat: @"fileId=%@",fileID] dataUsingEncoding:NSUTF8StringEncoding]];
-
- OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure];
- [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager];
-
- [operation resume];
- }
- - (void)geTemplatesRichdocuments:(NSString *)serverPath onCommunication:(OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *operation, id response))success failure:(void(^)(NSHTTPURLResponse *operation, id _Nullable responseObject, NSError *error))failure {
-
- NSParameterAssert(success);
-
- _requestMethod = @"GET";
-
- NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path:serverPath parameters:nil timeout:k_timeout_webdav];
- [request setValue:@"true" forHTTPHeaderField:@"OCS-APIRequest"];
-
- OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure];
- [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager];
-
- [operation resume];
- }
- - (void)createNewRichdocuments:(NSString *)serverPath path:(NSString *)path templateID:(NSString *)templateID onCommunication:(OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *operation, id response))success failure:(void(^)(NSHTTPURLResponse *operation, id _Nullable responseObject, NSError *error))failure {
-
- NSParameterAssert(success);
-
- _requestMethod = @"POST";
-
- NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path:serverPath parameters:nil timeout:k_timeout_webdav];
- [request setValue:@"true" forHTTPHeaderField:@"OCS-APIRequest"];
- [request setHTTPBody:[[NSString stringWithFormat: @"path=%@&template=%@", path, templateID] dataUsingEncoding:NSUTF8StringEncoding]];
-
- OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure];
- [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager];
-
- [operation resume];
- }
- - (void)createAssetRichdocuments:(NSString *)serverPath path:(NSString *)path onCommunication:(OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *operation, id response))success failure:(void(^)(NSHTTPURLResponse *operation, id _Nullable responseObject, NSError *error))failure {
- NSParameterAssert(success);
-
- _requestMethod = @"POST";
-
- NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path:serverPath parameters:nil timeout:k_timeout_webdav];
- [request setValue:@"true" forHTTPHeaderField:@"OCS-APIRequest"];
- [request setHTTPBody:[[NSString stringWithFormat: @"path=%@",path] dataUsingEncoding:NSUTF8StringEncoding]];
-
- OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure];
- [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager];
-
- [operation resume];
- }
- #pragma mark - Trash
- - (void)listTrash:(NSString *)path onCommunication:(OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *operation, id response))success failure:(void(^)(NSHTTPURLResponse *response, id _Nullable responseObject, NSError *error))failure
- {
- NSParameterAssert(success);
-
- _requestMethod = @"PROPFIND";
-
- NSMutableURLRequest *request = [self requestWithMethod:_requestMethod path:path parameters:nil timeout:k_timeout_webdav];
-
- NSString *body = [NSString stringWithFormat: @""
- "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
- "<D:propfind xmlns:D=\"DAV:\" xmlns:oc=\"http://owncloud.org/ns\" xmlns:nc=\"http://nextcloud.org/ns\">"
- "<D:prop>"
- "<D:resourcetype/>"
- "<D:getlastmodified/>"
- "<id xmlns=\"http://owncloud.org/ns\"/>"
- "<D:getcontentlength/>"
- "<nc:trashbin-filename/>"
- "<nc:trashbin-original-location/>"
- "<nc:trashbin-deletion-time/>"
- "<nc:has-preview/>"
- "</D:prop>"
- "</D:propfind>"];
- [request setHTTPBody:[body dataUsingEncoding:NSUTF8StringEncoding]];
- [request setValue:@"application/xml" forHTTPHeaderField:@"Content-Type"];
-
- OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure];
- [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager];
- [operation resume];
- }
- - (void)emptyTrash:(NSString*)path onCommunication:(OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *operation, id response))success failure:(void(^)(NSHTTPURLResponse *operation, id _Nullable responseObject, NSError *error))failure {
-
- NSParameterAssert(success);
-
- _requestMethod = @"DELETE";
-
- NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path:path parameters:nil timeout:k_timeout_webdav];
- [request setValue:@"true" forHTTPHeaderField:@"OCS-APIRequest"];
-
- OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure];
- [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager];
-
- [operation resume];
- }
- #pragma mark - Manage Redirections
- - (void)setRedirectionBlockOnDatataskWithOCCommunication: (OCCommunication *) sharedOCCommunication andSessionManager:(AFURLSessionManager *) sessionManager{
-
- [sessionManager setTaskWillPerformHTTPRedirectionBlock:^NSURLRequest * _Nonnull(NSURLSession * _Nonnull session, NSURLSessionTask * _Nonnull task, NSURLResponse * _Nonnull response, NSURLRequest * _Nonnull request) {
-
- if (response == nil) {
- // needed to handle fake redirects to canonical addresses, as explained in https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/URLLoadingSystem/Articles/RequestChanges.html
- return request;
- }
-
- NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
- NSDictionary *dict = [httpResponse allHeaderFields];
- //Server path of redirected server
- NSString *responseURLString = [dict objectForKey:@"Location"];
-
- if (responseURLString) {
-
- if ([UtilsFramework isURLWithSamlFragment:responseURLString] || httpResponse.statusCode == k_redirected_code_1) {
- //We set the redirectedServer in case SAML or is a permanent redirection
- self.redirectedServer = responseURLString;
-
- if ([UtilsFramework isURLWithSamlFragment:responseURLString]) {
- // if SAML request, we don't want to follow it; WebView takes care, not here -> nil to NO FOLLOW
- return nil;
- }
- }
-
- NSMutableURLRequest *requestRedirect = [request mutableCopy];
- [requestRedirect setURL: [NSURL URLWithString:responseURLString]];
-
- requestRedirect = [sharedOCCommunication getRequestWithCredentials:requestRedirect];
- requestRedirect.HTTPMethod = _requestMethod;
-
- if (_postStringForShare) {
- //It is a request to share a file by link
- requestRedirect = [self sharedRequestWithMethod:_requestMethod path:responseURLString parameters:nil timeout:k_timeout_webdav];
- [requestRedirect setHTTPBody:[_postStringForShare dataUsingEncoding:NSUTF8StringEncoding]];
- }
-
- return requestRedirect;
-
- } else {
- // no location to redirect -> nil to NO FOLLOW
- return nil;
- }
- }];
- }
- @end
|