1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618 |
- //
- // 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 "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";
- NSString *const NCResource = @"<d:displayname/>"
- "<d:getcontenttype/>"
- "<d:resourcetype/>"
- "<d:getcontentlength/>"
- "<d:getlastmodified/>"
- "<d:creationdate/>"
- "<d:getetag/>"
- "<d:quota-used-bytes/>"
- "<d:quota-available-bytes/>"
- "<permissions xmlns=\"http://owncloud.org/ns\"/>"
- "<id xmlns=\"http://owncloud.org/ns\"/>"
- "<fileid xmlns=\"http://owncloud.org/ns\"/>"
- "<size xmlns=\"http://owncloud.org/ns\"/>"
- "<favorite xmlns=\"http://owncloud.org/ns\"/>"
- "<is-encrypted xmlns=\"http://nextcloud.org/ns\"/>"
- "<mount-type xmlns=\"http://nextcloud.org/ns\"/>"
- "<owner-id xmlns=\"http://owncloud.org/ns\"/>"
- "<owner-display-name xmlns=\"http://owncloud.org/ns\"/>"
- "<comments-unread xmlns=\"http://owncloud.org/ns\"/>"
- "<has-preview xmlns=\"http://nextcloud.org/ns\"/>"
- "<trashbin-filename xmlns=\"http://nextcloud.org/ns\"/>"
- "<trashbin-original-location xmlns=\"http://nextcloud.org/ns\"/>"
- "<trashbin-deletion-time xmlns=\"http://nextcloud.org/ns\"/>";
- @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"];
- NSString *body = @"<?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>";
- body = [body stringByAppendingString:NCResource];
- body = [body stringByAppendingString:@"</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)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"];
- NSString *body = @"<?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>";
- body = [body stringByAppendingString:NCResource];
- body = [body stringByAppendingString:@"</d:prop></d:propfind>"];
- [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)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 lteDateLastModified:(NSString *)lteDateLastModified gteDateLastModified:(NSString *)gteDateLastModified 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 = @"";
- NSString *whereDate = @"";
-
- NSParameterAssert(success);
-
- _requestMethod = @"SEARCH";
-
- NSMutableURLRequest *request = [self requestWithMethod:_requestMethod path:path parameters:nil timeout:k_timeout_search];
-
- if (contentType && lteDateLastModified && gteDateLastModified) {
-
- 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:prop>"
- "</d:select>"
- "<d:from>"
- "<d:scope>"
- "<d:href>/files/%@%@</d:href>"
- "<d:depth>infinity</d:depth>"
- "</d:scope>"
- "</d:from>"
- "<d:orderby>"
- "<d:order>"
- "<d:prop><d:getlastmodified/></d:prop>"
- "<d:descending/>"
- "</d:order>"
- "<d:order>"
- "<d:prop><d:displayname/></d:prop>"
- "<d:descending/>"
- "</d:order>"
- "</d:orderby>"
- "<d:where><d:and><d:or>", NCResource, 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:or>", body, whereType];
-
- whereDate = [NSString stringWithFormat: @"%@<d:and><d:lte><d:prop><d:getlastmodified/></d:prop><d:literal>%@</d:literal></d:lte><d:gte><d:prop><d:getlastmodified/></d:prop><d:literal>%@</d:literal></d:gte></d:and>", whereDate, lteDateLastModified, gteDateLastModified];
-
- /*
- if (gteDateLastModified != nil && lteDateLastModified == nil) {
- whereDate = [NSString stringWithFormat: @"%@<d:gte><d:prop><d:getlastmodified/></d:prop><d:literal>%@</d:literal></d:gte>", whereDate, gteDateLastModified];
- } else if (gteDateLastModified != nil && lteDateLastModified != nil) {
- whereDate = [NSString stringWithFormat: @"%@<d:and><d:lte><d:prop><d:getlastmodified/></d:prop><d:literal>%@</d:literal></d:lte><d:gte><d:prop><d:getlastmodified/></d:prop><d:literal>%@</d:literal></d:gte></d:and>", whereDate, lteDateLastModified, gteDateLastModified];
- }
- */
-
- body = [NSString stringWithFormat: @"%@%@</d:or></d:and></d:where></d:basicsearch></d:searchrequest>", body, whereDate];
-
- } 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: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>", NCResource, 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)search:(NSString *)path folder:(NSString *)folder fileName:(NSString *)fileName dateLastModified:(NSString *)dateLastModified numberOfItem:(NSInteger)numberOfItem 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 = @"SEARCH";
-
- NSMutableURLRequest *request = [self requestWithMethod:_requestMethod path:path parameters:nil timeout:k_timeout_search];
-
- 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:prop>"
- "</d:select>"
-
- "<d:from>"
- "<d:scope>"
- "<d:href>/files/%@%@</d:href>"
- "<d:depth>1</d:depth>"
- "</d:scope>"
- "</d:from>"
-
- /*
- "<d:orderby>"
- "<d:order>"
- "<d:prop><d:displayname/></d:prop>"
- "<d:descending/>"
- "</d:order>"
- "<d:order>"
- "<d:prop><d:getlastmodified/></d:prop>"
- "<d:descending/>"
- "</d:order>"
- "</d:orderby>"
- */
-
- "<d:where>"
- "<d:like>"
- "<d:prop><d:displayname/></d:prop>"
- "<d:literal>%@</d:literal>"
- "</d:like>"
- "</d:where>"
- /*
- "<d:where><d:and><d:or>"
- "<d:gte>"
- "<d:prop><d:getlastmodified/></d:prop>"
- "<d:literal>%@</d:literal>"
- "</d:gte>"
- "</d:or></d:and></d:where>"
-
- "<d:limit>"
- "<d:nresults>%@</d:nresults>"
- "</d:limit>"
- */
- "</d:basicsearch>"
- "</d:searchrequest>", NCResource, userID, folder, fileName]; //, [@(numberOfItem) stringValue]];
-
- [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 {
- 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];
-
- NSString *body = @"<?xml version=\"1.0\"?><oc:filter-files xmlns:d=\"DAV:\" xmlns:oc=\"http://owncloud.org/ns\" xmlns:nc=\"http://nextcloud.org/ns\"><d:prop>";
- body = [body stringByAppendingString:NCResource];
- body = [body stringByAppendingString:@"</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];
-
- NSURLSessionDownloadTask *downloadTask = [sharedOCCommunication.downloadSessionManager downloadTaskWithRequest:request progress:^(NSProgress * _Nonnull progress) {
- downloadProgress(progress);
- } destination:^NSURL * _Nonnull(NSURL * _Nonnull targetPath, NSURLResponse * _Nonnull response) {
- [[NSFileManager defaultManager] removeItemAtURL:[NSURL fileURLWithPath:localDestination] error:nil];
- return [NSURL fileURLWithPath:localDestination];
- } 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=%@&reshares=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 andNote:(NSString *)note 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 (note) {
- self.postStringForShare = [NSString stringWithFormat:@"note=%@",note];
- } 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) 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 size:(NSString *)size 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=%@&y=%@", fileId, size, size];
- 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"];
- NSString *userAgent = [request valueForHTTPHeaderField:@"User-Agent"];
- //[request setValue:[userAgent stringByAppendingString:@" (SilentPush)"] forHTTPHeaderField:@"User-Agent"];
- [request setValue:[userAgent stringByAppendingString:@" (Strict VoIP)"] forHTTPHeaderField:@"User-Agent"];
- 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 limit:(NSInteger)limit objectId:(NSString *)objectId objectType:(NSString *)objectType previews:(BOOL)previews link:(NSString *)link onCommunication:(OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *operation, id response))success failure:(void(^)(NSHTTPURLResponse *operation, id _Nullable responseObject, NSError *error))failure{
-
- _requestMethod = @"GET";
-
- if (objectId.length == 0) {
- serverPath = [serverPath stringByAppendingString:[NSString stringWithFormat:@"/all?format=json&since=%ld&limit=%ld", (long)since, (long)limit]];
- } else {
- serverPath = [serverPath stringByAppendingString:[NSString stringWithFormat:@"/filter?format=json&since=%ld&limit=%ld&object_id=%@&object_type=%@",(long)since, (long)limit, objectId, objectType]];
- }
- if (previews) {
- 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)getTemplatesRichdocuments:(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 - Fulltextsearch
- - (void)fullTextSearch:(NSString *)serverPath data:(NSString *)data 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"];
- //[request setHTTPBody:[data dataUsingEncoding:NSUTF8StringEncoding]];
- [request setHTTPBody:[[NSString stringWithFormat:@"request=%@",data] dataUsingEncoding:NSUTF8StringEncoding]];
- OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure];
- [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager];
-
- [operation resume];
- }
- #pragma mark - Remore wipe
- - (void)getSetRemoteWipe:(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 {
-
- 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:@"token=%@",token] 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 depth:(NSString *)depth 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];
-
- [request setValue: depth forHTTPHeaderField: @"Depth"];
-
- NSString *body = @"<?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>";
- body = [body stringByAppendingString:NCResource];
- body = [body stringByAppendingString:@"</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 - Messages
- - (void)getComments:(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 = @"PROPFIND";
- NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path:serverPath parameters:nil timeout:k_timeout_webdav];
-
- [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>"
- "<oc:id/>"
- "<oc:verb/>"
- "<oc:actorType/>"
- "<oc:actorId/>"
- "<oc:creationDateTime/>"
- "<oc:objectType/>"
- "<oc:objectId/>"
- "<oc:isUnread/>"
- "<oc:message/>"
- "<oc:actorDisplayName/>"
- "</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)putComments:(NSString*)serverPath message:(NSString *)message onCommunication:(OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *operation, id response))success failure:(void(^)(NSHTTPURLResponse *operation, id responseObject, NSError *error))failure {
-
- NSParameterAssert(success);
-
- _requestMethod = @"POST";
-
- NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path:serverPath parameters:nil timeout:k_timeout_webdav];
- [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
- [request setHTTPBody:[[NSString stringWithFormat: @"{\"actorType\":\"users\",\"verb\":\"comment\",\"message\":\"%@\"}",message] dataUsingEncoding:NSUTF8StringEncoding]];
-
- OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure];
- [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager];
-
- [operation resume];
- }
- - (void)updateComments:(NSString*)serverPath message:(NSString *)message onCommunication:(OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *operation, id response))success failure:(void(^)(NSHTTPURLResponse *operation, id responseObject, NSError *error))failure {
-
- NSParameterAssert(success);
-
- _requestMethod = @"PROPPATCH";
-
- NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path:serverPath 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:message>%@</oc:message>"
- "</d:prop>"
- "</d:set>"
- "</d:propertyupdate>", message];
-
- [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)readMarkComments:(NSString*)serverPath onCommunication:(OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *operation, id response))success failure:(void(^)(NSHTTPURLResponse *operation, id responseObject, NSError *error))failure {
-
- NSParameterAssert(success);
-
- _requestMethod = @"PROPPATCH";
-
- NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path:serverPath 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>"
- "<readMarker xmlns=\"http://owncloud.org/ns\"/>"
- "</d:prop>"
- "</d:set>"
- "</d:propertyupdate>"];
-
- [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)deleteComments:(NSString*)serverPath onCommunication:(OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *operation, id response))success failure:(void(^)(NSHTTPURLResponse *operation, id responseObject, NSError *error))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];
- }
- #pragma mark - Third Parts
- - (void)getHCUserProfile:(NSString *)serverPath onCommunication:(OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *operation, id response))success failure:(void(^)(NSHTTPURLResponse *operation, id 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)putHCUserProfile:(NSString*)serverPath data:(NSString *)data onCommunication:(OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *operation, id response))success failure:(void(^)(NSHTTPURLResponse *operation, id 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: @"data=%@",data] dataUsingEncoding:NSUTF8StringEncoding]];
-
- OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure];
- [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager];
-
- [operation resume];
- }
- - (void)getHCFeatures:(NSString *)serverPath onCommunication:(OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *operation, id response))success failure:(void(^)(NSHTTPURLResponse *operation, id 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 - 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
|