123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323 |
- //
- // 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 <m.faggiana@twsweb.it>
- // 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
- 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=%@", filePath, (long)permission, password];
- [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
- 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];
- }
-
- [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 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/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 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 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)createTemplateRichdocuments:(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 = @"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)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];
- }
- #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
|