12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993 |
- //
- // OCCommunication.m
- // Owncloud iOs Client
- //
- // Copyright (C) 2016, ownCloud GmbH. ( http://www.owncloud.org/ )
- //
- // Permission is hereby granted, free of charge, to any person obtaining a copy
- // of this software and associated documentation files (the "Software"), to deal
- // in the Software without restriction, including without limitation the rights
- // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- // copies of the Software, and to permit persons to whom the Software is
- // furnished to do so, subject to the following conditions:
- // The above copyright notice and this permission notice shall be included in
- // all copies or substantial portions of the Software.
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- // THE SOFTWARE.
- //
- //
- // Add : getNotificationServer & setNotificationServer
- // Add : getUserProfileServer
- // Add : Support for Favorite
- // Add : getActivityServer
- //
- // Author Marino Faggiana <m.faggiana@twsweb.it>
- // Copyright (c) 2017 Marino Faggiana. All rights reserved.
- //
- #import "OCCommunication.h"
- #import "OCHTTPRequestOperation.h"
- #import "UtilsFramework.h"
- #import "OCXMLParser.h"
- #import "OCXMLSharedParser.h"
- #import "OCXMLServerErrorsParser.h"
- #import "OCXMLListParser.h"
- #import "NSString+Encode.h"
- #import "OCFrameworkConstants.h"
- #import "OCWebDAVClient.h"
- #import "OCXMLShareByLinkParser.h"
- #import "OCErrorMsg.h"
- #import "AFURLSessionManager.h"
- #import "OCShareUser.h"
- #import "OCActivity.h"
- #import "OCExternalSites.h"
- #import "OCCapabilities.h"
- #import "OCNotifications.h"
- #import "OCNotificationsAction.h"
- #import "OCRichObjectStrings.h"
- #import "OCUserProfile.h"
- #import "NCRichDocumentTemplate.h"
- @interface OCCommunication ()
- @property (nonatomic, strong) NSString *currentServerVersion;
- @end
- @implementation OCCommunication
- -(id) init {
-
- self = [super init];
-
- if (self) {
-
- //Init the Donwload queue array
- self.downloadTaskNetworkQueueArray = [NSMutableArray new];
-
- //Credentials not set yet
- self.kindOfCredential = credentialNotSet;
-
- [self setSecurityPolicyManagers:[self createSecurityPolicy]];
-
- self.isCookiesAvailable = YES;
- self.isForbiddenCharactersAvailable = NO;
-
- #ifdef UNIT_TEST
-
- self.uploadSessionManager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
- self.downloadSessionManager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
- self.networkSessionManager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
- self.networkSessionManager.responseSerializer = [AFHTTPResponseSerializer serializer];
- #else
- //Network Upload queue for NSURLSession (iOS 7)
- NSURLSessionConfiguration *uploadConfiguration = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:k_session_name];
- uploadConfiguration.HTTPShouldUsePipelining = YES;
- uploadConfiguration.HTTPMaximumConnectionsPerHost = 1;
- uploadConfiguration.requestCachePolicy = NSURLRequestReloadIgnoringLocalCacheData;
- self.uploadSessionManager = [[AFURLSessionManager alloc] initWithSessionConfiguration:uploadConfiguration];
- [self.uploadSessionManager.operationQueue setMaxConcurrentOperationCount:1];
-
- //Network Download queue for NSURLSession (iOS 7)
- NSURLSessionConfiguration *downConfiguration = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:k_download_session_name];
- downConfiguration.HTTPShouldUsePipelining = YES;
- downConfiguration.HTTPMaximumConnectionsPerHost = 1;
- downConfiguration.requestCachePolicy = NSURLRequestReloadIgnoringLocalCacheData;
- self.downloadSessionManager = [[AFURLSessionManager alloc] initWithSessionConfiguration:downConfiguration];
- [self.downloadSessionManager.operationQueue setMaxConcurrentOperationCount:1];
-
- //Network Download queue for NSURLSession (iOS 7)
- NSURLSessionConfiguration *networkConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration];
- networkConfiguration.HTTPShouldUsePipelining = YES;
- networkConfiguration.HTTPMaximumConnectionsPerHost = 1;
- networkConfiguration.requestCachePolicy = NSURLRequestReloadIgnoringLocalCacheData;
- self.networkSessionManager = [[AFURLSessionManager alloc] initWithSessionConfiguration:networkConfiguration];
- [self.networkSessionManager.operationQueue setMaxConcurrentOperationCount:1];
- self.networkSessionManager.responseSerializer = [AFHTTPResponseSerializer serializer];
- #endif
-
- }
-
- return self;
- }
- -(id) initWithUploadSessionManager:(AFURLSessionManager *) uploadSessionManager {
-
- self = [super init];
-
- if (self) {
-
- //Init the Donwload queue array
- self.downloadTaskNetworkQueueArray = [NSMutableArray new];
-
- self.isCookiesAvailable = YES;
- self.isForbiddenCharactersAvailable = NO;
-
- //Credentials not set yet
- self.kindOfCredential = credentialNotSet;
-
- [self setSecurityPolicyManagers:[self createSecurityPolicy]];
-
- self.uploadSessionManager = uploadSessionManager;
- }
-
- return self;
- }
- -(id) initWithUploadSessionManager:(AFURLSessionManager *) uploadSessionManager andDownloadSessionManager:(AFURLSessionManager *) downloadSessionManager andNetworkSessionManager:(AFURLSessionManager *) networkSessionManager {
-
- self = [super init];
-
- if (self) {
-
- //Init the Donwload queue array
- self.downloadTaskNetworkQueueArray = [NSMutableArray new];
-
- //Credentials not set yet
- self.kindOfCredential = credentialNotSet;
-
- [self setSecurityPolicyManagers:[self createSecurityPolicy]];
-
- self.uploadSessionManager = uploadSessionManager;
- self.downloadSessionManager = downloadSessionManager;
- self.networkSessionManager = networkSessionManager;
- }
-
- return self;
- }
- - (AFSecurityPolicy *) createSecurityPolicy {
- return [AFSecurityPolicy defaultPolicy];
- }
- - (void)setSecurityPolicyManagers:(AFSecurityPolicy *)securityPolicy {
- self.securityPolicy = securityPolicy;
- self.uploadSessionManager.securityPolicy = securityPolicy;
- self.downloadSessionManager.securityPolicy = securityPolicy;
- }
- #pragma mark - Setting Credentials
- - (void) setCredentialsWithUser:(NSString*) user andUserID:(NSString *) userID andPassword:(NSString*) password {
- self.kindOfCredential = credentialNormal;
- self.user = user;
- self.userID = userID;
- self.password = password;
- }
- - (void) setCredentialsWithCookie:(NSString*) cookie {
- self.kindOfCredential = credentialCookie;
- self.password = cookie;
- }
- - (void) setCredentialsOauthWithToken:(NSString*) token {
- self.kindOfCredential = credentialOauth;
- self.password = token;
- }
- ///-----------------------------------
- /// @name getRequestWithCredentials
- ///-----------------------------------
- /**
- * Method to return the request with the right credential
- *
- * @param OCWebDAVClient like a dinamic typed
- *
- * @return OCWebDAVClient like a dinamic typed
- *
- */
- - (id) getRequestWithCredentials:(id) request {
-
- if ([request isKindOfClass:[NSMutableURLRequest class]]) {
- NSMutableURLRequest *myRequest = (NSMutableURLRequest *)request;
-
- switch (self.kindOfCredential) {
- case credentialNotSet:
- //Without credentials
- break;
- case credentialNormal:
- {
- NSString *basicAuthCredentials = [NSString stringWithFormat:@"%@:%@", self.user, self.password];
- [myRequest addValue:[NSString stringWithFormat:@"Basic %@", [UtilsFramework AFBase64EncodedStringFromString:basicAuthCredentials]] forHTTPHeaderField:@"Authorization"];
- break;
- }
- case credentialCookie:
- NSLog(@"Cookie: %@", self.password);
- [myRequest addValue:self.password forHTTPHeaderField:@"Cookie"];
- break;
- case credentialOauth:
- [myRequest addValue:[NSString stringWithFormat:@"Bearer %@", self.password] forHTTPHeaderField:@"Authorization"];
- break;
- default:
- break;
- }
-
- if (self.userAgent) {
- [myRequest addValue:self.userAgent forHTTPHeaderField:@"User-Agent"];
- }
-
- return myRequest;
-
- } else if([request isKindOfClass:[OCWebDAVClient class]]) {
- OCWebDAVClient *myRequest = (OCWebDAVClient *)request;
-
- switch (self.kindOfCredential) {
- case credentialNotSet:
- //Without credentials
- break;
- case credentialNormal:
- [myRequest setAuthorizationHeaderWithUsername:self.user password:self.password];
- break;
- case credentialCookie:
- [myRequest setAuthorizationHeaderWithCookie:self.password];
- break;
- case credentialOauth:
- [myRequest setAuthorizationHeaderWithToken:[NSString stringWithFormat:@"Bearer %@", self.password]];
- break;
- default:
- break;
- }
-
- if (self.userAgent) {
- [myRequest setUserAgent:self.userAgent];
- }
-
- return request;
-
- } else {
- NSLog(@"We do not know witch kind of object is");
- return request;
- }
- }
- #pragma mark - WebDav network Operations
- ///-----------------------------------
- /// @name Check Server
- ///-----------------------------------
- - (void) checkServer: (NSString *) path
- onCommunication:(OCCommunication *)sharedOCCommunication
- successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer)) successRequest
- failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
-
- OCWebDAVClient *request = [OCWebDAVClient new];
- request = [self getRequestWithCredentials:request];
-
- if (self.userAgent) {
- [request setUserAgent:self.userAgent];
- }
-
- path = [path encodeString:NSUTF8StringEncoding];
-
- [request checkServer:path onCommunication:sharedOCCommunication
- success:^(NSHTTPURLResponse *response, id responseObject) {
- if (successRequest) {
- successRequest(response, request.redirectedServer);
- }
- } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
- failureRequest(response, error, request.redirectedServer);
- }];
- }
- ///-----------------------------------
- /// @name Create a folder
- ///-----------------------------------
- - (void) createFolder: (NSString *) path
- onCommunication:(OCCommunication *)sharedOCCommunication withForbiddenCharactersSupported:(BOOL)isFCSupported
- successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer)) successRequest
- failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest
- errorBeforeRequest:(void(^)(NSError *error)) errorBeforeRequest {
-
-
- if ([UtilsFramework isForbiddenCharactersInFileName:[UtilsFramework getFileNameOrFolderByPath:path] withForbiddenCharactersSupported:isFCSupported]) {
- NSError *error = [UtilsFramework getErrorByCodeId:OCErrorForbidenCharacters];
- errorBeforeRequest(error);
- } else {
- OCWebDAVClient *request = [OCWebDAVClient new];
- request = [self getRequestWithCredentials:request];
-
-
- path = [path encodeString:NSUTF8StringEncoding];
-
- [request makeCollection:path onCommunication:sharedOCCommunication
- success:^(NSHTTPURLResponse *response, id responseObject) {
- if (successRequest) {
- successRequest(response, request.redirectedServer);
- }
- } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
-
- OCXMLServerErrorsParser *serverErrorParser = [OCXMLServerErrorsParser new];
-
- [serverErrorParser startToParseWithData:responseData withCompleteBlock:^(NSError *err) {
-
- if (err) {
- failureRequest(response, err, request.redirectedServer);
- }else{
- failureRequest(response, error, request.redirectedServer);
- }
-
-
- }];
-
- }];
- }
- }
- ///-----------------------------------
- /// @name Move a file or a folder
- ///-----------------------------------
- - (void) moveFileOrFolder:(NSString *)sourcePath
- toDestiny:(NSString *)destinyPath
- onCommunication:(OCCommunication *)sharedOCCommunication withForbiddenCharactersSupported:(BOOL)isFCSupported
- successRequest:(void (^)(NSHTTPURLResponse *response, NSString *redirectServer))successRequest
- failureRequest:(void (^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer))failureRequest
- errorBeforeRequest:(void (^)(NSError *error))errorBeforeRequest {
-
- if ([UtilsFramework isTheSameFileOrFolderByNewURLString:destinyPath andOriginURLString:sourcePath]) {
- //We check that we are not trying to move the file to the same place
- NSError *error = [UtilsFramework getErrorByCodeId:OCErrorMovingTheDestinyAndOriginAreTheSame];
- errorBeforeRequest(error);
- } else if ([UtilsFramework isAFolderUnderItByNewURLString:destinyPath andOriginURLString:sourcePath]) {
- //We check we are not trying to move a folder inside himself
- NSError *error = [UtilsFramework getErrorByCodeId:OCErrorMovingFolderInsideHimself];
- errorBeforeRequest(error);
- } else if ([UtilsFramework isForbiddenCharactersInFileName:[UtilsFramework getFileNameOrFolderByPath:destinyPath] withForbiddenCharactersSupported:isFCSupported]) {
- //We check that we are making a move not a rename to prevent special characters problems
- NSError *error = [UtilsFramework getErrorByCodeId:OCErrorMovingDestinyNameHaveForbiddenCharacters];
- errorBeforeRequest(error);
- } else {
-
- sourcePath = [sourcePath encodeString:NSUTF8StringEncoding];
- destinyPath = [destinyPath encodeString:NSUTF8StringEncoding];
-
- OCWebDAVClient *request = [OCWebDAVClient new];
- request = [self getRequestWithCredentials:request];
-
-
- [request movePath:sourcePath toPath:destinyPath onCommunication:sharedOCCommunication success:^(NSHTTPURLResponse *response, id responseObject) {
- if (successRequest) {
- successRequest(response, request.redirectedServer);
- }
- } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
-
- OCXMLServerErrorsParser *serverErrorParser = [OCXMLServerErrorsParser new];
-
- [serverErrorParser startToParseWithData:responseData withCompleteBlock:^(NSError *err) {
-
- if (err) {
- failureRequest(response, err, request.redirectedServer);
- }else{
- failureRequest(response, error, request.redirectedServer);
- }
-
- }];
-
- }];
- }
- }
- ///-----------------------------------
- /// @name Delete a file or a folder
- ///-----------------------------------
- - (void) deleteFileOrFolder:(NSString *)path
- onCommunication:(OCCommunication *)sharedOCCommunication
- successRequest:(void (^)(NSHTTPURLResponse *response, NSString *redirectedServer))successRequest
- failureRquest:(void (^)(NSHTTPURLResponse *resposne, NSError *error, NSString *redirectedServer))failureRequest {
-
- path = [path encodeString:NSUTF8StringEncoding];
-
- OCWebDAVClient *request = [OCWebDAVClient new];
- request = [self getRequestWithCredentials:request];
-
-
- [request deletePath:path onCommunication:sharedOCCommunication success:^(NSHTTPURLResponse *response, id responseObject) {
- if (successRequest) {
- successRequest(response, request.redirectedServer);
- }
- } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
- failureRequest(response, error, request.redirectedServer);
- }];
- }
- ///-----------------------------------
- /// @name Read folder
- ///-----------------------------------
- - (void) readFolder: (NSString *) path depth:(NSString *)depth withUserSessionToken:(NSString *)token
- onCommunication:(OCCommunication *)sharedOCCommunication
- successRequest:(void(^)(NSHTTPURLResponse *response, NSArray *items, NSString *redirectedServer, NSString *token)) successRequest
- failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *token, NSString *redirectedServer)) failureRequest{
-
- if (!token){
- token = @"no token";
- }
-
- path = [path encodeString:NSUTF8StringEncoding];
-
- OCWebDAVClient *request = [OCWebDAVClient new];
- request = [self getRequestWithCredentials:request];
-
-
- [request listPath:path depth:depth onCommunication:sharedOCCommunication withUserSessionToken:token success:^(NSHTTPURLResponse *response, id responseObject, NSString *token) {
- if (successRequest) {
- NSData *responseData = (NSData*) responseObject;
-
- // NSString* newStr = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
- // NSLog(@"newStrReadFolder: %@", newStr);
-
- OCXMLParser *parser = [[OCXMLParser alloc]init];
- [parser initParserWithData:responseData];
- NSMutableArray *directoryList = [parser.directoryList mutableCopy];
-
- //Return success
- successRequest(response, directoryList, request.redirectedServer, token);
- }
-
- } failure:^(NSHTTPURLResponse *response, id responseData, NSError *error, NSString *token) {
- NSLog(@"Failure");
- failureRequest(response, error, token, request.redirectedServer);
- }];
- }
- ///-----------------------------------
- /// @name Download File Session
- ///-----------------------------------
- - (NSURLSessionDownloadTask *) downloadFileSession:(NSString *)remotePath toDestiny:(NSString *)localPath defaultPriority:(BOOL)defaultPriority onCommunication:(OCCommunication *)sharedOCCommunication progress:(void(^)(NSProgress *progress))downloadProgress successRequest:(void(^)(NSURLResponse *response, NSURL *filePath)) successRequest failureRequest:(void(^)(NSURLResponse *response, NSError *error)) failureRequest {
-
- OCWebDAVClient *request = [OCWebDAVClient new];
- request = [self getRequestWithCredentials:request];
- remotePath = [remotePath encodeString:NSUTF8StringEncoding];
-
- NSURLSessionDownloadTask *downloadTask = [request downloadWithSessionPath:remotePath toPath:localPath defaultPriority:defaultPriority onCommunication:sharedOCCommunication progress:^(NSProgress *progress) {
- downloadProgress(progress);
- } success:^(NSURLResponse *response, NSURL *filePath) {
-
- [UtilsFramework addCookiesToStorageFromResponse:(NSURLResponse *) response andPath:[NSURL URLWithString:remotePath]];
- successRequest(response,filePath);
-
- } failure:^(NSURLResponse *response, NSError *error) {
- [UtilsFramework addCookiesToStorageFromResponse:(NSURLResponse *) response andPath:[NSURL URLWithString:remotePath]];
- failureRequest(response,error);
- }];
-
- return downloadTask;
- }
- ///-----------------------------------
- /// @name Set Download Task Complete Block
- ///-----------------------------------
- - (void)setDownloadTaskComleteBlock: (NSURL * (^)(NSURLSession *session, NSURLSessionDownloadTask *downloadTask, NSURL *location))block{
-
- [self.downloadSessionManager setDownloadTaskDidFinishDownloadingBlock:block];
-
- }
- ///-----------------------------------
- /// @name Set Download Task Did Get Body Data Block
- ///-----------------------------------
- - (void) setDownloadTaskDidGetBodyDataBlock: (void(^)(NSURLSession *session, NSURLSessionDownloadTask *downloadTask, int64_t bytesWritten, int64_t totalBytesWritten, int64_t totalBytesExpectedToWrite)) block{
-
- [self.downloadSessionManager setDownloadTaskDidWriteDataBlock:^(NSURLSession *session, NSURLSessionDownloadTask *downloadTask, int64_t bytesWritten, int64_t totalBytesWritten, int64_t totalBytesExpectedToWrite) {
- block(session,downloadTask,bytesWritten,totalBytesWritten,totalBytesExpectedToWrite);
- }];
-
- }
- ///-----------------------------------
- /// @name Upload File Session
- ///-----------------------------------
- - (NSURLSessionUploadTask *) uploadFileSession:(NSString *) localPath toDestiny:(NSString *) remotePath onCommunication:(OCCommunication *)sharedOCCommunication progress:(void(^)(NSProgress *progress))uploadProgress successRequest:(void(^)(NSURLResponse *response, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSURLResponse *response, NSString *redirectedServer, NSError *error)) failureRequest failureBeforeRequest:(void(^)(NSError *error)) failureBeforeRequest {
-
- OCWebDAVClient *request = [OCWebDAVClient new];
- request = [self getRequestWithCredentials:request];
-
-
- remotePath = [remotePath encodeString:NSUTF8StringEncoding];
-
- NSURLSessionUploadTask *uploadTask = [request putWithSessionLocalPath:localPath atRemotePath:remotePath onCommunication:sharedOCCommunication progress:^(NSProgress *progress) {
- uploadProgress(progress);
- } success:^(NSURLResponse *response, id responseObjec){
- [UtilsFramework addCookiesToStorageFromResponse:(NSURLResponse *) response andPath:[NSURL URLWithString:remotePath]];
- //TODO: The second parameter is the redirected server
- successRequest(response, @"");
- } failure:^(NSURLResponse *response, id responseObject, NSError *error) {
- [UtilsFramework addCookiesToStorageFromResponse:(NSURLResponse *) response andPath:[NSURL URLWithString:remotePath]];
- //TODO: The second parameter is the redirected server
- NSData *responseData = (NSData*) responseObject;
-
- OCXMLServerErrorsParser *serverErrorParser = [OCXMLServerErrorsParser new];
-
- [serverErrorParser startToParseWithData:responseData withCompleteBlock:^(NSError *err) {
-
- if (err) {
- failureRequest(response, @"", err);
- }else{
- failureRequest(response, @"", error);
- }
-
- }];
-
- } failureBeforeRequest:^(NSError *error) {
- failureBeforeRequest(error);
- }];
-
- return uploadTask;
- }
- ///-----------------------------------
- /// @name Set Task Did Complete Block
- ///-----------------------------------
- - (void) setTaskDidCompleteBlock: (void(^)(NSURLSession *session, NSURLSessionTask *task, NSError *error)) block{
-
- [self.uploadSessionManager setTaskDidCompleteBlock:^(NSURLSession *session, NSURLSessionTask *task, NSError *error) {
- block(session, task, error);
- }];
-
- }
- ///-----------------------------------
- /// @name Set Task Did Send Body Data Block
- ///-----------------------------------
- - (void) setTaskDidSendBodyDataBlock: (void(^)(NSURLSession *session, NSURLSessionTask *task, int64_t bytesSent, int64_t totalBytesSent, int64_t totalBytesExpectedToSend)) block{
-
- [self.uploadSessionManager setTaskDidSendBodyDataBlock:^(NSURLSession *session, NSURLSessionTask *task, int64_t bytesSent, int64_t totalBytesSent, int64_t totalBytesExpectedToSend) {
- block(session, task, bytesSent, totalBytesSent, totalBytesExpectedToSend);
- }];
- }
- ///-----------------------------------
- /// @name Read File
- ///-----------------------------------
- - (void) readFile: (NSString *) path
- onCommunication:(OCCommunication *)sharedOCCommunication
- successRequest:(void(^)(NSHTTPURLResponse *response, NSArray *items, NSString *redirectedServer)) successRequest
- failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
-
- path = [path encodeString:NSUTF8StringEncoding];
-
- OCWebDAVClient *request = [OCWebDAVClient new];
- request = [self getRequestWithCredentials:request];
-
-
- [request propertiesOfPath:path onCommunication:sharedOCCommunication success:^(NSHTTPURLResponse *response, id responseObject) {
-
- if (successRequest) {
- NSData *responseData = (NSData*) responseObject;
-
- // NSString* newStr = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
- // NSLog(@"newStrReadFile: %@", newStr);
- OCXMLParser *parser = [[OCXMLParser alloc]init];
- [parser initParserWithData:responseData];
- NSMutableArray *directoryList = [parser.directoryList mutableCopy];
-
- //Return success
- successRequest(response, directoryList, request.redirectedServer);
- }
-
- } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
- failureRequest(response, error, request.redirectedServer);
-
- }];
-
- }
- ///-----------------------------------
- /// @name search
- ///-----------------------------------
- - (void)search:(NSString *)path folder:(NSString *)folder fileName:(NSString *)fileName depth:(NSString *)depth dateLastModified:(NSString *)dateLastModified contentType:(NSArray *)contentType withUserSessionToken:(NSString *)token onCommunication:(OCCommunication *)sharedOCCommunication successRequest:(void(^)(NSHTTPURLResponse *response, NSArray *items, NSString *redirectedServer, NSString *token)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *token, NSString *redirectedServer)) failureRequest{
-
- if (!token){
- token = @"no token";
- }
-
- path = [path encodeString:NSUTF8StringEncoding];
-
- OCWebDAVClient *request = [OCWebDAVClient new];
- request = [self getRequestWithCredentials:request];
-
- [request search:path folder:folder fileName:fileName depth:depth dateLastModified:dateLastModified contentType:contentType user:_user userID:_userID onCommunication:sharedOCCommunication withUserSessionToken:token success:^(NSHTTPURLResponse *response, id responseObject, NSString *token) {
-
- if (successRequest) {
-
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
- NSData *responseData = (NSData*) responseObject;
-
- OCXMLListParser *parser = [OCXMLListParser new];
- [parser initParserWithData:responseData];
- NSMutableArray *searchList = [parser.searchList mutableCopy];
-
- //Return success
- dispatch_async(dispatch_get_main_queue(), ^{
- successRequest(response, searchList, request.redirectedServer, token);
- });
- });
- }
-
- } failure:^(NSHTTPURLResponse *response, id responseData, NSError *error, NSString *token) {
-
- failureRequest(response, error, token, request.redirectedServer);
- }];
- }
- ///-----------------------------------
- /// @name Setting favorite
- ///-----------------------------------
- - (void)settingFavoriteServer:(NSString *)path andFileOrFolderPath:(NSString *)filePath favorite:(BOOL)favorite withUserSessionToken:(NSString *)token onCommunication:(OCCommunication *)sharedOCCommunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer, NSString *token)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *token, NSString *redirectedServer)) failureRequest {
-
- if (!token){
- token = @"no token";
- }
-
- path = [NSString stringWithFormat:@"%@/files/%@/%@", path, _userID, filePath];
- path = [path encodeString:NSUTF8StringEncoding];
-
- OCWebDAVClient *request = [OCWebDAVClient new];
- request = [self getRequestWithCredentials:request];
-
- [request settingFavorite:path favorite:favorite onCommunication:sharedOCCommunication withUserSessionToken:token success:^(NSHTTPURLResponse *response, id responseObject, NSString *token) {
-
- if (successRequest) {
- //Return success
- successRequest(response, request.redirectedServer, token);
- }
-
- } failure:^(NSHTTPURLResponse *response, id responseData, NSError *error, NSString *token) {
-
- NSLog(@"Failure");
- failureRequest(response, error, token, request.redirectedServer);
- }];
- }
- ///-----------------------------------
- /// @name Listing favorites
- ///-----------------------------------
- - (void)listingFavorites:(NSString *)path folder:(NSString *)folder withUserSessionToken:(NSString *)token onCommunication:(OCCommunication *)sharedOCCommunication successRequest:(void(^)(NSHTTPURLResponse *response, NSArray *items, NSString *redirectedServer, NSString *token)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *token, NSString *redirectedServer)) failureRequest{
-
- if (!token){
- token = @"no token";
- }
-
- path = [path encodeString:NSUTF8StringEncoding];
-
- OCWebDAVClient *request = [OCWebDAVClient new];
- request = [self getRequestWithCredentials:request];
-
- [request listingFavorites:path folder:folder user:_user userID:_userID onCommunication:sharedOCCommunication withUserSessionToken:token success:^(NSHTTPURLResponse *response, id responseObject, NSString *token) {
-
- if (successRequest) {
-
- NSData *responseData = (NSData*) responseObject;
-
- OCXMLListParser *parser = [OCXMLListParser new];
- [parser initParserWithData:responseData];
- NSMutableArray *searchList = [parser.searchList mutableCopy];
-
- //Return success
- successRequest(response, searchList, request.redirectedServer, token);
- }
-
- } failure:^(NSHTTPURLResponse *response, id responseData, NSError *error, NSString *token) {
-
- failureRequest(response, error, token, request.redirectedServer);
- }];
- }
- #pragma mark - OC/NC API Calls
- - (NSString *) getCurrentServerVersion {
- return self.currentServerVersion;
- }
- - (void) getServerVersionWithPath:(NSString*) path onCommunication:(OCCommunication *)sharedOCCommunication
- successRequest:(void(^)(NSHTTPURLResponse *response, NSString *serverVersion, NSString *redirectedServer)) success
- failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failure{
-
- OCWebDAVClient *request = [OCWebDAVClient new];
-
- if (self.userAgent) {
- [request setUserAgent:self.userAgent];
- }
-
- [request getStatusOfTheServer:path onCommunication:sharedOCCommunication success:^(NSHTTPURLResponse *response, id responseObject) {
-
- NSData *data = (NSData*) responseObject;
- NSString *versionString = [NSString new];
- NSError* error=nil;
-
- if (data) {
- NSMutableDictionary *jsonArray = [NSJSONSerialization JSONObjectWithData: data options: NSJSONReadingMutableContainers error: &error];
- if(error) {
- NSLog(@"Error parsing JSON: %@", error);
- } else {
- //Obtain the server version from the version field
- versionString = [jsonArray valueForKey:@"version"];
- self.currentServerVersion = versionString;
- }
- } else {
- NSLog(@"Error parsing JSON: data is null");
- }
- success(response, versionString, request.redirectedServer);
-
- } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
- failure(response, error, request.redirectedServer);
- }];
-
- }
- ///-----------------------------------
- /// @name Get UserName by cookie
- ///-----------------------------------
- - (void) getUserNameByCookie:(NSString *) cookieString ofServerPath:(NSString *)path onCommunication:
- (OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *response, NSData *responseData, NSString *redirectedServer))success
- failure:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer))failure{
-
- OCWebDAVClient *request = [OCWebDAVClient new];
- request = [self getRequestWithCredentials:request];
-
-
- [request requestUserNameOfServer: path byCookie:cookieString onCommunication:sharedOCCommunication success:^(NSHTTPURLResponse *response, id responseObject) {
- success(response, responseObject, request.redirectedServer);
- } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
- failure(response, error, request.redirectedServer);
- }];
- }
- - (void) getFeaturesSupportedByServer:(NSString*) path onCommunication:(OCCommunication *)sharedOCCommunication
- successRequest:(void(^)(NSHTTPURLResponse *response, BOOL hasShareSupport, BOOL hasShareeSupport, BOOL hasCookiesSupport, BOOL hasForbiddenCharactersSupport, BOOL hasCapabilitiesSupport, BOOL hasFedSharesOptionShareSupport, NSString *redirectedServer)) success
- failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failure{
-
- OCWebDAVClient *request = [OCWebDAVClient new];
-
- if (self.userAgent) {
- [request setUserAgent:self.userAgent];
- }
-
- [request getStatusOfTheServer:path onCommunication:sharedOCCommunication success:^(NSHTTPURLResponse *response, id responseObject) {
-
- if (responseObject) {
-
- NSError* error = nil;
- NSMutableDictionary *jsonArray = [NSJSONSerialization JSONObjectWithData: (NSData*) responseObject options: NSJSONReadingMutableContainers error: &error];
-
- if(error) {
- // NSLog(@"Error parsing JSON: %@", error);
- failure(response, error, request.redirectedServer);
- }else{
-
- self.currentServerVersion = [jsonArray valueForKey:@"version"];
-
- BOOL hasShareSupport = [UtilsFramework isServerVersion:self.currentServerVersion higherThanLimitVersion:k_version_support_shared];
- BOOL hasShareeSupport = [UtilsFramework isServerVersion:self.currentServerVersion higherThanLimitVersion:k_version_support_sharee_api];
- BOOL hasCookiesSupport = [UtilsFramework isServerVersion:self.currentServerVersion higherThanLimitVersion:k_version_support_cookies];
- BOOL hasForbiddenCharactersSupport = [UtilsFramework isServerVersion:self.currentServerVersion higherThanLimitVersion:k_version_support_forbidden_characters];
- BOOL hasCapabilitiesSupport = [UtilsFramework isServerVersion:self.currentServerVersion higherThanLimitVersion:k_version_support_capabilities];
- BOOL hasFedSharesOptionShareSupport = [UtilsFramework isServerVersion:self.currentServerVersion higherThanLimitVersion:k_version_support_share_option_fed_share];
- success(response, hasShareSupport, hasShareeSupport, hasCookiesSupport, hasForbiddenCharactersSupport, hasCapabilitiesSupport, hasFedSharesOptionShareSupport, request.redirectedServer);
- }
-
- } else {
- // NSLog(@"Error parsing JSON: data is null");
- failure(response, nil, request.redirectedServer);
- }
-
- } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
- failure(response, error, request.redirectedServer);
- }];
- }
- #pragma mark - Share
- - (void) readSharedByServer: (NSString *) path
- onCommunication:(OCCommunication *)sharedOCCommunication
- successRequest:(void(^)(NSHTTPURLResponse *response, NSArray *listOfShared, NSString *redirectedServer)) successRequest
- failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
-
- path = [path encodeString:NSUTF8StringEncoding];
- path = [path stringByAppendingString:k_url_acces_shared_api];
-
- OCWebDAVClient *request = [OCWebDAVClient new];
- request = [self getRequestWithCredentials:request];
-
-
- [request listSharedByServer:path onCommunication:sharedOCCommunication success:^(NSHTTPURLResponse *response, id responseObject) {
- if (successRequest) {
- NSData *responseData = (NSData*) responseObject;
- OCXMLSharedParser *parser = [[OCXMLSharedParser alloc]init];
-
- //NSLog(@"response: %@", [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]);
-
- [parser initParserWithData:responseData];
- NSMutableArray *sharedList = [parser.shareList mutableCopy];
-
- //Return success
- successRequest(response, sharedList, request.redirectedServer);
- }
-
- } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
- failureRequest(response, error, request.redirectedServer);
- }];
- }
- - (void) readSharedByServer: (NSString *) serverPath andPath: (NSString *) path
- onCommunication:(OCCommunication *)sharedOCCommunication
- successRequest:(void(^)(NSHTTPURLResponse *response, NSArray *listOfShared, NSString *redirectedServer)) successRequest
- failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
-
- serverPath = [serverPath encodeString:NSUTF8StringEncoding];
- serverPath = [serverPath stringByAppendingString:k_url_acces_shared_api];
-
- path = [path encodeString:NSUTF8StringEncoding];
-
- OCWebDAVClient *request = [OCWebDAVClient new];
- request = [self getRequestWithCredentials:request];
-
-
- [request listSharedByServer:serverPath andPath:path onCommunication:sharedOCCommunication success:^(NSHTTPURLResponse *response, id responseObject) {
- if (successRequest) {
- NSData *responseData = (NSData*) responseObject;
- OCXMLSharedParser *parser = [[OCXMLSharedParser alloc]init];
-
- // NSString *str = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
- // NSLog(@"responseDataReadSharedByServer:andPath: %@", str);
- // NSLog(@"pathFolders: %@", path);
- // NSLog(@"serverPath: %@", serverPath);
-
- [parser initParserWithData:responseData];
- NSMutableArray *sharedList = [parser.shareList mutableCopy];
-
- //Return success
- successRequest(response, sharedList, request.redirectedServer);
- }
- } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
- failureRequest(response, error, request.redirectedServer);
- }];
- }
- - (void) shareFileOrFolderByServer: (NSString *) serverPath andFileOrFolderPath: (NSString *) filePath andPassword:(NSString *)password andPermission:(NSInteger)permission
- onCommunication:(OCCommunication *)sharedOCCommunication
- successRequest:(void(^)(NSHTTPURLResponse *response, NSString *token, NSString *redirectedServer)) successRequest
- failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
-
- serverPath = [serverPath encodeString:NSUTF8StringEncoding];
- serverPath = [serverPath stringByAppendingString:k_url_acces_shared_api];
-
- OCWebDAVClient *request = [OCWebDAVClient new];
- request = [self getRequestWithCredentials:request];
-
-
- [request shareByLinkFileOrFolderByServer:serverPath andPath:filePath andPassword:password andPermission:permission onCommunication:sharedOCCommunication success:^(NSHTTPURLResponse *response, id responseObject) {
-
- NSData *responseData = (NSData*) responseObject;
-
- OCXMLShareByLinkParser *parser = [[OCXMLShareByLinkParser alloc]init];
-
- // NSLog(@"response: %@", [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding]);
-
- [parser initParserWithData:responseData];
-
- switch (parser.statusCode) {
- case kOCSharedAPISuccessful:
- {
- NSString *url = parser.url;
- NSString *token = parser.token;
-
- if (url != nil) {
-
- successRequest(response, url, request.redirectedServer);
-
- }else if (token != nil){
- //We remove the \n and the empty spaces " "
- token = [token stringByReplacingOccurrencesOfString:@"\n" withString:@""];
- token = [token stringByReplacingOccurrencesOfString:@" " withString:@""];
-
- successRequest(response, token, request.redirectedServer);
-
- }else{
-
- NSError *error = [UtilsFramework getErrorWithCode:parser.statusCode andCustomMessageFromTheServer:parser.message];
- failureRequest(response, error, request.redirectedServer);
- }
-
- break;
- }
-
- default:
- {
- NSError *error = [UtilsFramework getErrorWithCode:parser.statusCode andCustomMessageFromTheServer:parser.message];
- failureRequest(response, error, request.redirectedServer);
- }
- }
-
- } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
- failureRequest(response, error, request.redirectedServer);
- }];
- }
- - (void) shareFileOrFolderByServer: (NSString *) serverPath andFileOrFolderPath: (NSString *) filePath
- onCommunication:(OCCommunication *)sharedOCCommunication
- successRequest:(void(^)(NSHTTPURLResponse *response, NSString *shareLink, NSString *redirectedServer)) successRequest
- failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
-
- serverPath = [serverPath encodeString:NSUTF8StringEncoding];
- serverPath = [serverPath stringByAppendingString:k_url_acces_shared_api];
-
- OCWebDAVClient *request = [OCWebDAVClient new];
- request = [self getRequestWithCredentials:request];
-
-
- [request shareByLinkFileOrFolderByServer:serverPath andPath:filePath onCommunication:sharedOCCommunication success:^(NSHTTPURLResponse *response, id responseObject) {
-
- NSData *responseData = (NSData*) responseObject;
-
- OCXMLShareByLinkParser *parser = [[OCXMLShareByLinkParser alloc]init];
-
- // NSLog(@"response: %@", [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding]);
-
- [parser initParserWithData:responseData];
-
- switch (parser.statusCode) {
- case kOCSharedAPISuccessful:
- {
- NSString *url = parser.url;
- NSString *token = parser.token;
-
- if (url != nil) {
-
- successRequest(response, url, request.redirectedServer);
-
- }else if (token != nil){
- //We remove the \n and the empty spaces " "
- token = [token stringByReplacingOccurrencesOfString:@"\n" withString:@""];
- token = [token stringByReplacingOccurrencesOfString:@" " withString:@""];
-
- successRequest(response, token, request.redirectedServer);
-
- }else{
-
- NSError *error = [UtilsFramework getErrorWithCode:parser.statusCode andCustomMessageFromTheServer:parser.message];
- failureRequest(response, error, request.redirectedServer);
- }
- break;
- }
-
- default:
- {
- NSError *error = [UtilsFramework getErrorWithCode:parser.statusCode andCustomMessageFromTheServer:parser.message];
- failureRequest(response, error, request.redirectedServer);
- }
- }
- } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
- failureRequest(response, error, request.redirectedServer);
- }];
- }
- - (void)shareWith:(NSString *)userOrGroup shareeType:(NSInteger)shareeType inServer:(NSString *) serverPath andFileOrFolderPath:(NSString *) filePath andPermissions:(NSInteger) permissions onCommunication:(OCCommunication *)sharedOCCommunication
- successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer))successRequest
- failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer))failureRequest{
-
- serverPath = [serverPath encodeString:NSUTF8StringEncoding];
- serverPath = [serverPath stringByAppendingString:k_url_acces_shared_api];
- userOrGroup = [userOrGroup encodeString:NSUTF8StringEncoding];
-
- OCWebDAVClient *request = [OCWebDAVClient new];
- request = [self getRequestWithCredentials:request];
-
-
- [request shareWith:userOrGroup shareeType:shareeType inServer:serverPath andPath:filePath andPermissions:permissions onCommunication:sharedOCCommunication success:^(NSHTTPURLResponse *response, id responseObject) {
- NSData *responseData = (NSData*) responseObject;
-
- OCXMLShareByLinkParser *parser = [[OCXMLShareByLinkParser alloc]init];
-
- // NSLog(@"response: %@", [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding]);
-
- [parser initParserWithData:responseData];
-
- switch (parser.statusCode) {
- case kOCSharedAPISuccessful:
- {
- successRequest(response, request.redirectedServer);
- break;
- }
-
- default:
- {
- NSError *error = [UtilsFramework getErrorWithCode:parser.statusCode andCustomMessageFromTheServer:parser.message];
- failureRequest(response, error, request.redirectedServer);
- }
- }
-
-
- } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
- failureRequest(response, error, request.redirectedServer);
- }];
-
- }
- - (void) unShareFileOrFolderByServer: (NSString *) path andIdRemoteShared: (NSInteger) idRemoteShared
- onCommunication:(OCCommunication *)sharedOCCommunication
- successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer)) successRequest
- failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest{
-
- path = [path encodeString:NSUTF8StringEncoding];
- path = [path stringByAppendingString:k_url_acces_shared_api];
- path = [path stringByAppendingString:[NSString stringWithFormat:@"/%ld",(long)idRemoteShared]];
-
- OCWebDAVClient *request = [OCWebDAVClient new];
- request = [self getRequestWithCredentials:request];
-
-
- [request unShareFileOrFolderByServer:path onCommunication:sharedOCCommunication success:^(NSHTTPURLResponse *response, id responseObject) {
- if (successRequest) {
- //Return success
- successRequest(response, request.redirectedServer);
- }
-
- } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
- failureRequest(response, error, request.redirectedServer);
- }];
- }
- - (void) isShareFileOrFolderByServer: (NSString *) path andIdRemoteShared: (NSInteger) idRemoteShared
- onCommunication:(OCCommunication *)sharedOCCommunication
- successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer, BOOL isShared, id shareDto)) successRequest
- failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
-
- path = [path encodeString:NSUTF8StringEncoding];
- path = [path stringByAppendingString:k_url_acces_shared_api];
- path = [path stringByAppendingString:[NSString stringWithFormat:@"/%ld",(long)idRemoteShared]];
-
- OCWebDAVClient *request = [OCWebDAVClient new];
- request = [self getRequestWithCredentials:request];
-
-
- [request isShareFileOrFolderByServer:path onCommunication:sharedOCCommunication success:^(NSHTTPURLResponse *response, id responseObject) {
- if (successRequest) {
-
- NSData *responseData = (NSData*) responseObject;
- OCXMLSharedParser *parser = [[OCXMLSharedParser alloc]init];
-
- // NSLog(@"response: %@", [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding]);
-
- [parser initParserWithData:responseData];
-
- BOOL isShared = NO;
-
- OCSharedDto *shareDto = nil;
-
- if (parser.shareList) {
-
- NSMutableArray *sharedList = [parser.shareList mutableCopy];
-
- if ([sharedList count] > 0) {
- isShared = YES;
- shareDto = [sharedList objectAtIndex:0];
- }
-
- }
-
- //Return success
- successRequest(response, request.redirectedServer, isShared, shareDto);
- }
-
- } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
- failureRequest(response, error, request.redirectedServer);
- }];
- }
- - (void) updateShare:(NSInteger)shareId ofServerPath:(NSString *)serverPath withPasswordProtect:(NSString*)password andExpirationTime:(NSString*)expirationTime andPermissions:(NSInteger)permissions
- onCommunication:(OCCommunication *)sharedOCCommunication
- successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer)) successRequest
- failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest{
-
-
- serverPath = [serverPath encodeString:NSUTF8StringEncoding];
- serverPath = [serverPath stringByAppendingString:k_url_acces_shared_api];
- serverPath = [serverPath stringByAppendingString:[NSString stringWithFormat:@"/%ld",(long)shareId]];
-
- OCWebDAVClient *request = [OCWebDAVClient new];
- request = [self getRequestWithCredentials:request];
-
-
- [request updateShareItem:shareId ofServerPath:serverPath withPasswordProtect:password andExpirationTime:expirationTime andPermissions:permissions onCommunication:sharedOCCommunication success:^(NSHTTPURLResponse *response, id responseObject) {
-
- NSData *responseData = (NSData*) responseObject;
-
- OCXMLShareByLinkParser *parser = [[OCXMLShareByLinkParser alloc]init];
-
- // NSLog(@"response: %@", [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding]);
-
- [parser initParserWithData:responseData];
-
-
- switch (parser.statusCode) {
- case kOCSharedAPISuccessful:
- {
- successRequest(response, request.redirectedServer);
- break;
- }
-
- default:
- {
- NSError *error = [UtilsFramework getErrorWithCode:parser.statusCode andCustomMessageFromTheServer:parser.message];
- failureRequest(response, error, request.redirectedServer);
- }
- }
- } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
- failureRequest(response, error, request.redirectedServer);
- }];
-
- }
- - (void) searchUsersAndGroupsWith:(NSString *)searchString forPage:(NSInteger)page with:(NSInteger)resultsPerPage ofServer:(NSString*)serverPath onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSArray *itemList, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest{
-
- serverPath = [serverPath encodeString:NSUTF8StringEncoding];
- serverPath = [serverPath stringByAppendingString:k_url_access_sharee_api];
-
- searchString = [searchString encodeString:NSUTF8StringEncoding];
-
- OCWebDAVClient *request = [OCWebDAVClient new];
- request = [self getRequestWithCredentials:request];
-
-
-
- [request searchUsersAndGroupsWith:searchString forPage:page with:resultsPerPage ofServer:serverPath onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
-
- NSData *responseData = (NSData*) responseObject;
-
- NSMutableArray *itemList = [NSMutableArray new];
-
- //Parse
- NSError *error;
- NSDictionary *jsongParsed = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
-
- if (error == nil) {
-
- NSDictionary *ocsDict = [jsongParsed valueForKey:@"ocs"];
-
- NSDictionary *metaDict = [ocsDict valueForKey:@"meta"];
- NSInteger statusCode = [[metaDict valueForKey:@"statuscode"] integerValue];
-
- if (statusCode == kOCShareeAPISuccessful || statusCode == kOCSharedAPISuccessful) {
-
- NSDictionary *dataDict = [ocsDict valueForKey:@"data"];
- NSArray *exactDict = [dataDict valueForKey:@"exact"];
- NSArray *usersFounded = [dataDict valueForKey:@"users"];
- NSArray *groupsFounded = [dataDict valueForKey:@"groups"];
- NSArray *usersRemote = [dataDict valueForKey:@"remotes"];
- NSArray *usersExact = [exactDict valueForKey:@"users"];
- NSArray *groupsExact = [exactDict valueForKey:@"groups"];
- NSArray *remotesExact = [exactDict valueForKey:@"remotes"];
-
- [self addUserItemOfType:shareTypeUser fromArray:usersFounded ToList:itemList];
- [self addUserItemOfType:shareTypeUser fromArray:usersExact ToList:itemList];
- [self addUserItemOfType:shareTypeRemote fromArray:usersRemote ToList:itemList];
- [self addUserItemOfType:shareTypeRemote fromArray:remotesExact ToList:itemList];
- [self addGroupItemFromArray:groupsFounded ToList:itemList];
- [self addGroupItemFromArray:groupsExact ToList:itemList];
-
- }else{
-
- NSString *message = (NSString*)[metaDict objectForKey:@"message"];
-
- if ([message isKindOfClass:[NSNull class]]) {
- message = @"";
- }
-
- NSError *error = [UtilsFramework getErrorWithCode:statusCode andCustomMessageFromTheServer:message];
- failureRequest(response, error, request.redirectedServer);
-
- }
-
- //Return success
- successRequest(response, itemList, request.redirectedServer);
-
- }
-
-
- } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
- failureRequest(response, error, request.redirectedServer);
- }];
- }
- - (void)getSharePermissionsFile:(NSString *)fileName onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *permissions, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest{
-
- fileName = [fileName encodeString:NSUTF8StringEncoding];
-
- OCWebDAVClient *request = [OCWebDAVClient new];
- request = [self getRequestWithCredentials:request];
-
- [request getSharePermissionsFile:fileName onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
-
- if (successRequest) {
-
- NSString *permissions;
- NSData *responseData = (NSData *)responseObject;
-
- NSString *newStr = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
- NSLog(@"newStrReadFolder: %@", newStr);
-
- OCXMLParser *parser = [[OCXMLParser alloc]init];
- [parser initParserWithData:responseData];
- NSMutableArray *directoryList = [parser.directoryList mutableCopy];
-
- if ([directoryList count] == 1) {
- OCFileDto *file = [directoryList objectAtIndex:0];
- permissions = file.permissions;
- }
-
- //Return success
- successRequest(response, permissions, request.redirectedServer);
- }
-
- } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
-
- failureRequest(response, error, request.redirectedServer);
- }];
- }
- #pragma mark - Capabilities
- - (void) getCapabilitiesOfServer:(NSString*)serverPath onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, OCCapabilities *capabilities, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest{
-
- serverPath = [serverPath encodeString:NSUTF8StringEncoding];
- serverPath = [serverPath stringByAppendingString:k_url_capabilities];
-
- OCWebDAVClient *request = [OCWebDAVClient new];
- request = [self getRequestWithCredentials:request];
-
- [request getCapabilitiesOfServer:serverPath onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
-
- NSData *responseData = (NSData*) responseObject;
- OCCapabilities *capabilities = [OCCapabilities new];
-
- //Parse
- NSError *error;
- NSDictionary *jsongParsed = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
- NSLog(@"dic: %@",jsongParsed);
-
- if (jsongParsed && jsongParsed.allKeys > 0) {
-
- NSDictionary *ocs = [jsongParsed valueForKey:@"ocs"];
- NSDictionary *data = [ocs valueForKey:@"data"];
- NSDictionary *version = [data valueForKey:@"version"];
-
- if (ocs.count > 0 && data.count > 0 && version.count > 0) {
-
- //VERSION
-
- NSNumber *versionMajorNumber = (NSNumber*) [version valueForKey:@"major"];
- NSNumber *versionMinorNumber = (NSNumber*) [version valueForKey:@"minor"];
- NSNumber *versionMicroNumber = (NSNumber*) [version valueForKey:@"micro"];
-
- capabilities.versionMajor = versionMajorNumber.integerValue;
- capabilities.versionMinor = versionMinorNumber.integerValue;
- capabilities.versionMicro = versionMicroNumber.integerValue;
-
- capabilities.versionString = (NSString*)[version valueForKey:@"string"];
- capabilities.versionEdition = (NSString*)[version valueForKey:@"edition"];
-
- NSDictionary *capabilitiesDict = [data valueForKey:@"capabilities"];
- NSDictionary *core = [capabilitiesDict valueForKey:@"core"];
-
- //CORE
-
- NSNumber *corePollIntervalNumber = (NSNumber*)[core valueForKey:@"pollinterval"];
- capabilities.corePollInterval = corePollIntervalNumber.integerValue;
-
- NSDictionary *fileSharing = [capabilitiesDict valueForKey:@"files_sharing"];
-
- //FILE SHARING
-
- NSNumber *fileSharingAPIEnabledNumber = (NSNumber*)[fileSharing valueForKey:@"api_enabled"];
- NSNumber *filesSharingReSharingEnabledNumber = (NSNumber*)[fileSharing valueForKey:@"resharing"];
-
- capabilities.isFilesSharingAPIEnabled = fileSharingAPIEnabledNumber.boolValue;
- capabilities.isFilesSharingReSharingEnabled = filesSharingReSharingEnabledNumber.boolValue;
-
- NSDictionary *fileSharingPublic = [fileSharing valueForKey:@"public"];
-
- NSNumber *filesSharingShareLinkEnabledNumber = (NSNumber*)[fileSharingPublic valueForKey:@"enabled"];
- NSNumber *filesSharingAllowPublicUploadsEnabledNumber = (NSNumber*)[fileSharingPublic valueForKey:@"upload"];
- NSNumber *filesSharingAllowUserSendMailNotificationAboutShareLinkEnabledNumber = (NSNumber*)[fileSharingPublic valueForKey:@"send_mail"];
-
- capabilities.isFilesSharingShareLinkEnabled = filesSharingShareLinkEnabledNumber.boolValue;
- capabilities.isFilesSharingAllowPublicUploadsEnabled = filesSharingAllowPublicUploadsEnabledNumber.boolValue;
- capabilities.isFilesSharingAllowUserSendMailNotificationAboutShareLinkEnabled = filesSharingAllowUserSendMailNotificationAboutShareLinkEnabledNumber.boolValue;
-
- NSDictionary *fileSharingPublicExpireDate = [fileSharingPublic valueForKey:@"expire_date"];
-
- NSNumber *filesSharingExpireDateByDefaultEnabledNumber = (NSNumber*)[fileSharingPublicExpireDate valueForKey:@"enabled"];
- NSNumber *filesSharingExpireDateEnforceEnabledNumber = (NSNumber*)[fileSharingPublicExpireDate valueForKey:@"enforced"];
- NSNumber *filesSharingExpireDateDaysNumber = (NSNumber*)[fileSharingPublicExpireDate valueForKey:@"days"];
-
-
- capabilities.isFilesSharingExpireDateByDefaultEnabled = filesSharingExpireDateByDefaultEnabledNumber.boolValue;
- capabilities.isFilesSharingExpireDateEnforceEnabled = filesSharingExpireDateEnforceEnabledNumber.boolValue;
- capabilities.filesSharingExpireDateDaysNumber = filesSharingExpireDateDaysNumber.integerValue;
-
- NSDictionary *fileSharingPublicPassword = [fileSharingPublic valueForKey:@"password"];
-
- NSNumber *filesSharingPasswordEnforcedEnabledNumber = (NSNumber*)[fileSharingPublicPassword valueForKey:@"enforced"];
-
- capabilities.isFilesSharingPasswordEnforcedEnabled = filesSharingPasswordEnforcedEnabledNumber.boolValue;;
-
- NSDictionary *fileSharingUser = [fileSharing valueForKey:@"user"];
-
- NSNumber *filesSharingAllowUserSendMailNotificationAboutOtherUsersEnabledNumber = (NSNumber*)[fileSharingUser valueForKey:@"send_mail"];
-
- capabilities.isFilesSharingAllowUserSendMailNotificationAboutOtherUsersEnabled = filesSharingAllowUserSendMailNotificationAboutOtherUsersEnabledNumber.boolValue;
-
- //FEDERATION
-
- NSDictionary *fileSharingFederation = [fileSharing valueForKey:@"federation"];
-
- NSNumber *filesSharingAllowUserSendSharesToOtherServersEnabledNumber = (NSNumber*)[fileSharingFederation valueForKey:@"outgoing"];
- NSNumber *filesSharingAllowUserReceiveSharesToOtherServersEnabledNumber = (NSNumber*)[fileSharingFederation valueForKey:@"incoming"];
-
- capabilities.isFilesSharingAllowUserSendSharesToOtherServersEnabled = filesSharingAllowUserSendSharesToOtherServersEnabledNumber.boolValue;
- capabilities.isFilesSharingAllowUserReceiveSharesToOtherServersEnabled = filesSharingAllowUserReceiveSharesToOtherServersEnabledNumber.boolValue;
-
- // EXTERNAL SITES
-
- NSDictionary *externalSitesDic = [capabilitiesDict valueForKey:@"external"];
- if (externalSitesDic) {
- capabilities.isExternalSitesServerEnabled = YES;
- NSArray *externalSitesArray = [externalSitesDic valueForKey:@"v1"];
- capabilities.externalSiteV1 = [externalSitesArray componentsJoinedByString:@","];
- }
-
- // NOTIFICATION
-
- NSDictionary *notificationDic = [capabilitiesDict valueForKey:@"notifications"];
- if (notificationDic) {
- capabilities.isNotificationServerEnabled = YES;
- NSArray *ocsendpointsArray = [notificationDic valueForKey:@"ocs-endpoints"];
- capabilities.notificationOcsEndpoints = [ocsendpointsArray componentsJoinedByString:@","];
- NSArray *pushArray = [notificationDic valueForKey:@"push"];
- capabilities.notificationPush = [pushArray componentsJoinedByString:@","];
- }
-
- // SPREED
-
- NSDictionary *spreedDic = [capabilitiesDict valueForKey:@"spreed"];
- if (spreedDic) {
- capabilities.isSpreedServerEnabled = YES;
- NSArray *featuresArray = [capabilitiesDict valueForKey:@"features"];
- capabilities.spreedFeatures = [featuresArray componentsJoinedByString:@","];
- }
-
- //FILES
-
- NSDictionary *files = [capabilitiesDict valueForKey:@"files"];
-
- NSNumber *fileBigFileChunkingEnabledNumber = (NSNumber*)[files valueForKey:@"bigfilechunking"];
- NSNumber *fileUndeleteEnabledNumber = (NSNumber*)[files valueForKey:@"undelete"];
- NSNumber *fileVersioningEnabledNumber = (NSNumber*)[files valueForKey:@"versioning"];
-
- capabilities.isFileBigFileChunkingEnabled = fileBigFileChunkingEnabledNumber.boolValue;
- capabilities.isFileUndeleteEnabled = fileUndeleteEnabledNumber.boolValue;
- capabilities.isFileVersioningEnabled = fileVersioningEnabledNumber.boolValue;
-
- //THEMING
-
- NSDictionary *theming = [capabilitiesDict valueForKey:@"theming"];
-
- if ([theming count] > 0) {
-
- if ([theming valueForKey:@"background"] && ![[theming valueForKey:@"background"] isEqual:[NSNull null]])
- capabilities.themingBackground = [theming valueForKey:@"background"];
-
- if ([theming valueForKey:@"background-default"] && ![[theming valueForKey:@"background-default"] isEqual:[NSNull null]]) {
- NSNumber *result = (NSNumber*)[theming valueForKey:@"background-default"];
- capabilities.themingBackgroundDefault = result.boolValue;
- }
-
- if ([theming valueForKey:@"background-plain"] && ![[theming valueForKey:@"background-plain"] isEqual:[NSNull null]]) {
- NSNumber *result = (NSNumber*)[theming valueForKey:@"background-plain"];
- capabilities.themingBackgroundPlain = result.boolValue;
- }
-
- if ([theming valueForKey:@"color"] && ![[theming valueForKey:@"color"] isEqual:[NSNull null]])
- capabilities.themingColor = [theming valueForKey:@"color"];
-
- if ([theming valueForKey:@"color-element"] && ![[theming valueForKey:@"color-element"] isEqual:[NSNull null]])
- capabilities.themingColorElement = [theming valueForKey:@"color-element"];
-
- if ([theming valueForKey:@"color-text"] && ![[theming valueForKey:@"color-text"] isEqual:[NSNull null]])
- capabilities.themingColorText = [theming valueForKey:@"color-text"];
-
- if ([theming valueForKey:@"logo"] && ![[theming valueForKey:@"logo"] isEqual:[NSNull null]])
- capabilities.themingLogo = [theming valueForKey:@"logo"];
-
- if ([theming valueForKey:@"name"] && ![[theming valueForKey:@"name"] isEqual:[NSNull null]])
- capabilities.themingName = [theming valueForKey:@"name"];
-
- if ([theming valueForKey:@"slogan"] && ![[theming valueForKey:@"slogan"] isEqual:[NSNull null]])
- capabilities.themingSlogan = [theming valueForKey:@"slogan"];
-
- if ([theming valueForKey:@"url"] && ![[theming valueForKey:@"url"] isEqual:[NSNull null]])
- capabilities.themingUrl = [theming valueForKey:@"url"];
- }
-
- //END TO END Encryption
-
- NSDictionary *endToEndEncryption = [capabilitiesDict valueForKey:@"end-to-end-encryption"];
-
- if ([endToEndEncryption count] > 0) {
-
- NSNumber *endToEndEncryptionEnabled = (NSNumber*)[endToEndEncryption valueForKey:@"enabled"];
- capabilities.isEndToEndEncryptionEnabled = endToEndEncryptionEnabled.boolValue;
-
- if ([endToEndEncryption valueForKey:@"api-version"] && ![[endToEndEncryption valueForKey:@"api-version"] isEqual:[NSNull null]])
- capabilities.endToEndEncryptionVersion = [endToEndEncryption valueForKey:@"api-version"];
- }
-
- //Richdocuments
-
- NSDictionary *richdocuments = [capabilitiesDict valueForKey:@"richdocuments"];
-
- if (richdocuments!= nil && [richdocuments count] > 0) {
- capabilities.RichdocumentsMimetypes = [richdocuments valueForKey:@"mimetypes"];
- }
- }
-
- successRequest(response, capabilities, request.redirectedServer);
-
- } else {
- failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedString(@"_server_response_error_", nil)], request.redirectedServer);
- }
-
- } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
- failureRequest(response, error, request.redirectedServer);
- }];
- }
- #pragma mark - Thumbnail
- - (NSURLSessionTask *) getRemoteThumbnailByServer:(NSString*)serverPath ofFilePath:(NSString *)filePath withWidth:(NSInteger)fileWidth andHeight:(NSInteger)fileHeight onCommunication:(OCCommunication *)sharedOCComunication
- successRequest:(void(^)(NSHTTPURLResponse *response, NSData *thumbnail, NSString *redirectedServer)) successRequest
- failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
-
- serverPath = [serverPath encodeString:NSUTF8StringEncoding];
- filePath = [filePath encodeString:NSUTF8StringEncoding];
-
- OCWebDAVClient *request = [OCWebDAVClient new];
- request = [self getRequestWithCredentials:request];
-
-
- OCHTTPRequestOperation *operation = [request getRemoteThumbnailByServer:serverPath ofFilePath:filePath withWidth:fileWidth andHeight:fileHeight onCommunication:sharedOCComunication
- success:^(NSHTTPURLResponse *response, id responseObject) {
- NSData *responseData = (NSData*) responseObject;
-
- successRequest(response, responseData, request.redirectedServer);
-
- } failure:^(NSHTTPURLResponse *response, id _Nullable responseObject, NSError * _Nonnull error) {
- failureRequest(response, error, request.redirectedServer);
- }];
-
- [operation resume];
- return operation;
- }
- - (NSURLSessionTask *) getRemotePreviewByServer:(NSString*)serverPath ofFilePath:(NSString *)filePath withWidth:(NSInteger)fileWidth andHeight:(NSInteger)fileHeight andA:(NSInteger)a andMode:(NSString * _Nonnull)mode onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSData *preview, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
-
- serverPath = [serverPath encodeString:NSUTF8StringEncoding];
- filePath = [filePath encodeString:NSUTF8StringEncoding];
-
- OCWebDAVClient *request = [OCWebDAVClient new];
- request = [self getRequestWithCredentials:request];
-
- OCHTTPRequestOperation *operation = [request getRemotePreviewByServer:serverPath ofFilePath:filePath withWidth:fileWidth andHeight:fileHeight andA:a andMode:mode onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
-
- NSData *responseData = (NSData*) responseObject;
-
- successRequest(response, responseData, request.redirectedServer);
-
- } failure:^(NSHTTPURLResponse *response, id _Nullable responseObject, NSError * _Nonnull error) {
-
- failureRequest(response, error, request.redirectedServer);
- }];
-
- [operation resume];
-
- return operation;
- }
- - (NSURLSessionTask *) getRemotePreviewTrashByServer:(NSString*)serverPath ofFileID:(NSString *)fileID onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSData *preview, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
-
- serverPath = [serverPath encodeString:NSUTF8StringEncoding];
-
- OCWebDAVClient *request = [OCWebDAVClient new];
- request = [self getRequestWithCredentials:request];
-
- OCHTTPRequestOperation *operation = [request getRemotePreviewTrashByServer:serverPath ofFileID:fileID onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
-
- NSData *responseData = (NSData*) responseObject;
-
- successRequest(response, responseData, request.redirectedServer);
-
- } failure:^(NSHTTPURLResponse *response, id _Nullable responseObject, NSError * _Nonnull error) {
-
- failureRequest(response, error, request.redirectedServer);
- }];
-
- [operation resume];
-
- return operation;
- }
- #pragma mark - Notification
- - (void)getNotificationServer:(NSString*)serverPath onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSArray *listOfNotifications, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
-
- serverPath = [serverPath encodeString:NSUTF8StringEncoding];
- serverPath = [serverPath stringByAppendingString:k_url_acces_remote_notification_api];
-
- OCWebDAVClient *request = [OCWebDAVClient new];
- request = [self getRequestWithCredentials:request];
-
- [request getNotificationServer:serverPath onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
-
- NSData *responseData = (NSData*) responseObject;
- NSMutableArray *listOfNotifications = [NSMutableArray new];
- //Parse
- NSError *error;
- NSDictionary *jsongParsed = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
- NSLog(@"[LOG] Notifications : %@",jsongParsed);
-
- if (jsongParsed && jsongParsed.allKeys > 0) {
-
- NSDictionary *ocs = [jsongParsed valueForKey:@"ocs"];
- NSDictionary *meta = [ocs valueForKey:@"meta"];
- NSDictionary *datas = [ocs valueForKey:@"data"];
-
- NSInteger statusCode = [[meta valueForKey:@"statuscode"] integerValue];
-
- if (statusCode == kOCNotificationAPINoContent || statusCode == kOCNotificationAPISuccessful) {
-
- for (NSDictionary *data in datas) {
-
- OCNotifications *notification = [OCNotifications new];
-
- if ([data valueForKey:@"notification_id"] && ![[data valueForKey:@"notification_id"] isEqual:[NSNull null]])
- notification.idNotification = [[data valueForKey:@"notification_id"] integerValue];
-
- if ([data valueForKey:@"app"] && ![[data valueForKey:@"app"] isEqual:[NSNull null]])
- notification.application = [data valueForKey:@"app"];
-
- if ([data valueForKey:@"user"] && ![[data valueForKey:@"user"] isEqual:[NSNull null]])
- notification.user = [data valueForKey:@"user"];
-
- if ([data valueForKey:@"datetime"] && ![[data valueForKey:@"datetime"] isEqual:[NSNull null]]) {
-
- NSString *dateString = [data valueForKey:@"datetime"];
-
- NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
- NSLocale *enUSPOSIXLocale = [NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"];
- [dateFormatter setLocale:enUSPOSIXLocale];
- [dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZZZZZ"];
-
- notification.date = [dateFormatter dateFromString:dateString];
- }
-
- if ([data valueForKey:@"object_type"] && ![[data valueForKey:@"object_type"] isEqual:[NSNull null]])
- notification.typeObject = [data valueForKey:@"object_type"];
-
- if ([data valueForKey:@"object_id"] && ![[data valueForKey:@"object_id"] isEqual:[NSNull null]])
- notification.idObject = [data valueForKey:@"object_id"];
-
- if ([data valueForKey:@"subject"] && ![[data valueForKey:@"subject"] isEqual:[NSNull null]])
- notification.subject = [data valueForKey:@"subject"];
-
- if ([data valueForKey:@"subjectRich"] && ![[data valueForKey:@"subjectRich"] isEqual:[NSNull null]])
- notification.subjectRich = [data valueForKey:@"subjectRich"];
-
- if ([data valueForKey:@"subjectRichParameters"] && ![[data valueForKey:@"subjectRichParameters"] isEqual:[NSNull null]])
- notification.subjectRichParameters = [data valueForKey:@"subjectRichParameters"];
-
- if ([data valueForKey:@"message"] && ![[data valueForKey:@"message"] isEqual:[NSNull null]])
- notification.message = [data valueForKey:@"message"];
-
- if ([data valueForKey:@"messageRich"] && ![[data valueForKey:@"messageRich"] isEqual:[NSNull null]])
- notification.messageRich = [data valueForKey:@"messageRich"];
-
- if ([data valueForKey:@"messageRichParameters"] && ![[data valueForKey:@"messageRichParameters"] isEqual:[NSNull null]])
- notification.messageRichParameters = [data valueForKey:@"messageRichParameters"];
-
- if ([data valueForKey:@"link"] && ![[data valueForKey:@"link"] isEqual:[NSNull null]])
- notification.link = [data valueForKey:@"link"];
-
- if ([data valueForKey:@"icon"] && ![[data valueForKey:@"icon"] isEqual:[NSNull null]])
- notification.icon = [data valueForKey:@"icon"];
-
- /* ACTION */
-
- NSMutableArray *actionsArr = [NSMutableArray new];
- NSDictionary *actions = [data valueForKey:@"actions"];
-
- for (NSDictionary *action in actions) {
-
- OCNotificationsAction *notificationAction = [OCNotificationsAction new];
-
- if ([action valueForKey:@"label"] && ![[action valueForKey:@"label"] isEqual:[NSNull null]])
- notificationAction.label = [action valueForKey:@"label"];
-
- if ([action valueForKey:@"link"] && ![[action valueForKey:@"link"] isEqual:[NSNull null]])
- notificationAction.link = [action valueForKey:@"link"];
-
- if ([action valueForKey:@"primary"] && ![[action valueForKey:@"primary"] isEqual:[NSNull null]])
- notificationAction.primary = [[action valueForKey:@"primary"] boolValue];
-
- if ([action valueForKey:@"type"] && ![[action valueForKey:@"type"] isEqual:[NSNull null]])
- notificationAction.type = [action valueForKey:@"type"];
- [actionsArr addObject:notificationAction];
- }
-
- notification.actions = [[NSArray alloc] initWithArray:actionsArr];
- [listOfNotifications addObject:notification];
- }
-
- successRequest(response, listOfNotifications, request.redirectedServer);
-
- } else {
-
- NSString *message = (NSString *)[meta objectForKey:@"message"];
- if ([message isKindOfClass:[NSNull class]]) {
- message = NSLocalizedString(@"_server_response_error_", nil);
- }
- failureRequest(response, [UtilsFramework getErrorWithCode:statusCode andCustomMessageFromTheServer:message], request.redirectedServer);
- }
- } else {
- failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedString(@"_server_response_error_", nil)], request.redirectedServer);
- }
-
- } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
- failureRequest(response, error, request.redirectedServer);
- }];
- }
- - (void)setNotificationServer:(NSString*)serverPath type:(NSString *)type onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void (^)(NSHTTPURLResponse *, NSString *))successRequest failureRequest:(void (^)(NSHTTPURLResponse *, NSError *, NSString *))failureRequest {
-
- serverPath = [serverPath encodeString:NSUTF8StringEncoding];
-
- OCWebDAVClient *request = [OCWebDAVClient new];
- request = [self getRequestWithCredentials:request];
-
- __weak OCWebDAVClient *wrequest = request;
-
- [request setNotificationServer:serverPath type:type onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
-
- successRequest(response, wrequest.redirectedServer);
-
- } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
-
- failureRequest(response, error, wrequest.redirectedServer);
- }];
- }
- #pragma mark - Push Notification
- - (void)subscribingNextcloudServerPush:(NSString *)serverPath pushTokenHash:(NSString *)pushTokenHash devicePublicKey:(NSString *)devicePublicKey proxyServerPath:(NSString *)proxyServerPath onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *publicKey, NSString *deviceIdentifier, NSString *signature, NSString *redirectedServer)) successRequest failureRequest:(void (^)(NSHTTPURLResponse *, NSError *, NSString *))failureRequest {
-
- serverPath = [serverPath encodeString:NSUTF8StringEncoding];
- serverPath = [serverPath stringByAppendingString:k_url_acces_remote_subscribing_nextcloud_server_api];
- OCWebDAVClient *request = [OCWebDAVClient new];
- request = [self getRequestWithCredentials:request];
-
- [request subscribingNextcloudServerPush:serverPath pushTokenHash:pushTokenHash devicePublicKey:devicePublicKey proxyServerPath:proxyServerPath onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
-
- NSData *responseData = (NSData*)responseObject;
-
- NSError *error;
- NSDictionary *jsongParsed = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
-
- if (jsongParsed && jsongParsed.allKeys > 0) {
-
- NSDictionary *ocs = [jsongParsed valueForKey:@"ocs"];
- NSDictionary *meta = [ocs valueForKey:@"meta"];
- NSDictionary *datas = [ocs valueForKey:@"data"];
-
- NSInteger statusCode = [[meta valueForKey:@"statuscode"] integerValue];
-
- if (statusCode == kOCPushNotificationAPISuccessful || statusCode == kOCPushNotificationAPINeedSendProxy) {
-
- NSString *publicKey = [datas objectForKey:@"publicKey"];
- NSString *deviceIdentifier = [datas objectForKey:@"deviceIdentifier"];
- NSString *signature = [datas objectForKey:@"signature"];
-
- successRequest(response, publicKey, deviceIdentifier, signature, request.redirectedServer);
-
- } else {
-
- NSString *message = (NSString *)[meta objectForKey:@"message"];
- if ([message isKindOfClass:[NSNull class]]) {
- message = NSLocalizedString(@"_server_response_error_", nil);
- }
- failureRequest(response, [UtilsFramework getErrorWithCode:statusCode andCustomMessageFromTheServer:message], request.redirectedServer);
- }
- } else {
- failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedString(@"_server_response_error_", nil)], request.redirectedServer);
- }
- } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
-
- failureRequest(response, error, request.redirectedServer);
- }];
- }
- - (void)unsubscribingNextcloudServerPush:(NSString *)serverPath onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer)) successRequest failureRequest:(void (^)(NSHTTPURLResponse *, NSError *, NSString *))failureRequest {
-
- serverPath = [serverPath encodeString:NSUTF8StringEncoding];
- serverPath = [serverPath stringByAppendingString:k_url_acces_remote_subscribing_nextcloud_server_api];
-
- OCWebDAVClient *request = [OCWebDAVClient new];
- request = [self getRequestWithCredentials:request];
-
- [request unsubscribingNextcloudServerPush:serverPath onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
- successRequest(response, request.redirectedServer);
- } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
- failureRequest(response, error, request.redirectedServer);
- }];
- }
- - (void)subscribingPushProxy:(NSString *)serverPath pushToken:(NSString *)pushToken deviceIdentifier:(NSString *)deviceIdentifier deviceIdentifierSignature:(NSString *)deviceIdentifierSignature publicKey:(NSString *)publicKey onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void (^)(NSHTTPURLResponse *, NSString *redirectedServer))successRequest failureRequest:(void (^)(NSHTTPURLResponse *, NSError *, NSString *))failureRequest {
-
- serverPath = [serverPath encodeString:NSUTF8StringEncoding];
- serverPath = [serverPath stringByAppendingString:@"/devices"];
-
- OCWebDAVClient *request = [OCWebDAVClient new];
- request = [self getRequestWithCredentials:request];
-
- [request subscribingPushProxy:serverPath pushToken:pushToken deviceIdentifier:deviceIdentifier deviceIdentifierSignature:deviceIdentifierSignature publicKey:publicKey onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
-
- if (successRequest) {
- //Return success
- successRequest(response, request.redirectedServer);
- }
-
- } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
-
- failureRequest(response, error, request.redirectedServer);
- }];
- }
- - (void)unsubscribingPushProxy:(NSString *)serverPath deviceIdentifier:(NSString *)deviceIdentifier deviceIdentifierSignature:(NSString *)deviceIdentifierSignature publicKey:(NSString *)publicKey onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void (^)(NSHTTPURLResponse *, NSString *redirectedServer))successRequest failureRequest:(void (^)(NSHTTPURLResponse *, NSError *, NSString *))failureRequest {
-
- serverPath = [serverPath encodeString:NSUTF8StringEncoding];
- serverPath = [serverPath stringByAppendingString:@"/devices"];
-
- OCWebDAVClient *request = [OCWebDAVClient new];
- request = [self getRequestWithCredentials:request];
-
- [request unsubscribingPushProxy:serverPath deviceIdentifier:deviceIdentifier deviceIdentifierSignature:deviceIdentifierSignature publicKey:publicKey onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
-
- if (successRequest) {
- //Return success
- successRequest(response, request.redirectedServer);
- }
-
- } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
-
- failureRequest(response, error, request.redirectedServer);
- }];
- }
- #pragma mark - Activity
- - (void) getActivityServer:(NSString*)serverPath onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSArray *listOfActivity, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
- serverPath = [serverPath encodeString:NSUTF8StringEncoding];
- serverPath = [serverPath stringByAppendingString:k_url_acces_remote_activity_api];
-
- OCWebDAVClient *request = [OCWebDAVClient new];
- request = [self getRequestWithCredentials:request];
-
- [request getActivityServer:serverPath onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
-
- NSData *responseData = (NSData*) responseObject;
- NSMutableArray *listOfActivity = [NSMutableArray new];
- //Parse
- NSError *error;
- NSDictionary *jsongParsed = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
- NSLog(@"[LOG] Activity : %@",jsongParsed);
-
- if (jsongParsed && [jsongParsed isKindOfClass:[NSDictionary class]] && jsongParsed.allKeys > 0) {
-
- NSDictionary *ocs = [jsongParsed valueForKey:@"ocs"];
- NSDictionary *meta = [ocs valueForKey:@"meta"];
- NSDictionary *datas = [ocs valueForKey:@"data"];
-
- NSInteger statusCode = [[meta valueForKey:@"statuscode"] integerValue];
- if (statusCode == kOCNotificationAPINoContent || statusCode == kOCNotificationAPISuccessful) {
-
- for (NSDictionary *data in datas) {
-
- OCActivity *activity = [OCActivity new];
-
- if ([data valueForKey:@"id"] && ![[data valueForKey:@"id"] isEqual:[NSNull null]])
- activity.idActivity = [[data valueForKey:@"id"] integerValue];
-
- if ([data valueForKey:@"date"] && ![[data valueForKey:@"date"] isEqual:[NSNull null]]) {
-
- NSString *dateString = [data valueForKey:@"date"];
-
- NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
- NSLocale *enUSPOSIXLocale = [NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"];
- [dateFormatter setLocale:enUSPOSIXLocale];
- [dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZZZZZ"];
-
- activity.date = [dateFormatter dateFromString:dateString];
- }
-
- if ([data valueForKey:@"file"] && ![[data valueForKey:@"file"] isEqual:[NSNull null]])
- activity.file = [data valueForKey:@"file"];
-
- if ([data valueForKey:@"link"] && ![[data valueForKey:@"link"] isEqual:[NSNull null]])
- activity.link = [data valueForKey:@"link"];
-
- if ([data valueForKey:@"message"] && ![[data valueForKey:@"message"] isEqual:[NSNull null]])
- activity.message = [data valueForKey:@"message"];
-
- if ([data valueForKey:@"subject"] && ![[data valueForKey:@"subject"] isEqual:[NSNull null]])
- activity.subject = [data valueForKey:@"subject"];
-
- [listOfActivity addObject:activity];
- }
-
- successRequest(response, listOfActivity, request.redirectedServer);
- } else {
-
- NSString *message = (NSString *)[meta objectForKey:@"message"];
- if ([message isKindOfClass:[NSNull class]]) {
- message = NSLocalizedString(@"_server_response_error_", nil);
- }
- failureRequest(response, [UtilsFramework getErrorWithCode:statusCode andCustomMessageFromTheServer:message], request.redirectedServer);
- }
-
- } else {
- failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedString(@"_server_response_error_", nil)], request.redirectedServer);
- }
- } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
- failureRequest(response, error, request.redirectedServer);
- }];
- }
- #pragma mark - External Sites
- - (void) getExternalSitesServer:(NSString*)serverPath onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSArray *listOfExternalSites, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
- serverPath = [serverPath encodeString:NSUTF8StringEncoding];
- serverPath = [serverPath stringByAppendingString:k_url_acces_external_sites_api];
-
- OCWebDAVClient *request = [OCWebDAVClient new];
- request = [self getRequestWithCredentials:request];
-
- [request getExternalSitesServer:serverPath onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
-
- NSData *responseData = (NSData*) responseObject;
- NSMutableArray *listOfExternalSites = [NSMutableArray new];
- //Parse
- NSError *error;
- NSDictionary *jsongParsed = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
- NSLog(@"[LOG] External Sites : %@",jsongParsed);
-
- if (jsongParsed && jsongParsed.allKeys > 0) {
-
- NSDictionary *ocs = [jsongParsed valueForKey:@"ocs"];
- NSDictionary *meta = [ocs valueForKey:@"meta"];
- NSDictionary *datas = [ocs valueForKey:@"data"];
-
- NSInteger statusCode = [[meta valueForKey:@"statuscode"] integerValue];
-
- if (statusCode == kOCNotificationAPINoContent || statusCode == kOCNotificationAPISuccessful) {
-
- for (NSDictionary *data in datas) {
-
- OCExternalSites *externalSites = [OCExternalSites new];
-
- externalSites.idExternalSite = [[data valueForKey:@"id"] integerValue];
-
- if ([data valueForKey:@"icon"] && ![[data valueForKey:@"icon"] isEqual:[NSNull null]])
- externalSites.icon = [data valueForKey:@"icon"];
-
- if ([data valueForKey:@"lang"] && ![[data valueForKey:@"lang"] isEqual:[NSNull null]])
- externalSites.lang = [data valueForKey:@"lang"];
-
- if ([data valueForKey:@"name"] && ![[data valueForKey:@"name"] isEqual:[NSNull null]])
- externalSites.name = [data valueForKey:@"name"];
-
- if ([data valueForKey:@"url"] && ![[data valueForKey:@"url"] isEqual:[NSNull null]])
- externalSites.url = [data valueForKey:@"url"];
-
- if ([data valueForKey:@"type"] && ![[data valueForKey:@"type"] isEqual:[NSNull null]])
- externalSites.type = [data valueForKey:@"type"];
-
- [listOfExternalSites addObject:externalSites];
- }
-
- successRequest(response, listOfExternalSites, request.redirectedServer);
- } else {
-
- NSString *message = (NSString *)[meta objectForKey:@"message"];
- if ([message isKindOfClass:[NSNull class]]) {
- message = NSLocalizedString(@"_server_response_error_", nil);
- }
- failureRequest(response, [UtilsFramework getErrorWithCode:statusCode andCustomMessageFromTheServer:message], request.redirectedServer);
- }
-
- } else {
- failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedString(@"_server_response_error_", nil)], request.redirectedServer);
- }
-
- } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
- failureRequest(response, error, request.redirectedServer);
- }];
- }
- #pragma mark - User Profile
- - (void) getUserProfileServer:(NSString*)serverPath onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, OCUserProfile *userProfile, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
-
- serverPath = [serverPath stringByAppendingString:k_url_acces_remote_userprofile_api];
- serverPath = [serverPath encodeString:NSUTF8StringEncoding];
- OCWebDAVClient *request = [OCWebDAVClient new];
- request = [self getRequestWithCredentials:request];
-
- [request getUserProfileServer:serverPath onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
-
- NSData *responseData = (NSData*) responseObject;
- OCUserProfile *userProfile = [OCUserProfile new];
- //Parse
- NSError *error;
- NSDictionary *jsongParsed = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
- NSLog(@"[LOG] User Profile : %@",jsongParsed);
-
- if (jsongParsed && jsongParsed.allKeys > 0) {
- NSDictionary *ocs = [jsongParsed valueForKey:@"ocs"];
- NSDictionary *meta = [ocs valueForKey:@"meta"];
- NSDictionary *data = [ocs valueForKey:@"data"];
-
- NSInteger statusCode = [[meta valueForKey:@"statuscode"] integerValue];
-
- if (statusCode == kOCUserProfileAPISuccessful) {
-
- if ([data valueForKey:@"address"] && ![[data valueForKey:@"address"] isKindOfClass:[NSNull class]])
- userProfile.address = [data valueForKey:@"address"];
-
- if ([data valueForKey:@"display-name"] && ![[data valueForKey:@"display-name"] isKindOfClass:[NSNull class]])
- userProfile.displayName = [data valueForKey:@"display-name"];
-
- if ([data valueForKey:@"email"] && ![[data valueForKey:@"email"] isKindOfClass:[NSNull class]])
- userProfile.email = [data valueForKey:@"email"];
-
- if ([data valueForKey:@"enabled"] && ![[data valueForKey:@"enabled"] isKindOfClass:[NSNull class]])
- userProfile.enabled = [[data valueForKey:@"enabled"] boolValue];
-
- if ([data valueForKey:@"id"] && ![[data valueForKey:@"id"] isKindOfClass:[NSNull class]])
- userProfile.id = [data valueForKey:@"id"];
-
- if ([data valueForKey:@"phone"] && ![[data valueForKey:@"phone"] isKindOfClass:[NSNull class]])
- userProfile.phone = [data valueForKey:@"phone"];
-
- if ([data valueForKey:@"twitter"] && ![[data valueForKey:@"twitter"] isKindOfClass:[NSNull class]])
- userProfile.twitter = [data valueForKey:@"twitter"];
-
- if ([data valueForKey:@"webpage"] && ![[data valueForKey:@"webpage"] isKindOfClass:[NSNull class]])
- userProfile.webpage = [data valueForKey:@"webpage"];
- /* QUOTA */
-
- NSDictionary *quota = [data valueForKey:@"quota"];
-
- if ([quota count] > 0) {
-
- if ([quota valueForKey:@"free"] && ![[quota valueForKey:@"free"] isKindOfClass:[NSNull class]])
- userProfile.quotaFree = [[quota valueForKey:@"free"] doubleValue];
-
- if ([quota valueForKey:@"quota"] && ![[quota valueForKey:@"quota"] isKindOfClass:[NSNull class]])
- userProfile.quota = [[quota valueForKey:@"quota"] doubleValue];
-
- if ([quota valueForKey:@"relative"] && ![[quota valueForKey:@"relative"] isKindOfClass:[NSNull class]])
- userProfile.quotaRelative = [[quota valueForKey:@"relative"] doubleValue];
-
- if ([quota valueForKey:@"total"] && ![[quota valueForKey:@"total"] isKindOfClass:[NSNull class]])
- userProfile.quotaTotal = [[quota valueForKey:@"total"] doubleValue];
-
- if ([quota valueForKey:@"used"] && ![[quota valueForKey:@"used"] isKindOfClass:[NSNull class]])
- userProfile.quotaUsed = [[quota valueForKey:@"used"] doubleValue];
- }
-
- successRequest(response, userProfile, request.redirectedServer);
- } else {
-
- NSString *message = (NSString *)[meta objectForKey:@"message"];
- if ([message isKindOfClass:[NSNull class]]) {
- message = NSLocalizedString(@"_server_response_error_", nil);
- }
- failureRequest(response, [UtilsFramework getErrorWithCode:statusCode andCustomMessageFromTheServer:message], request.redirectedServer);
- }
-
- } else {
- failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedString(@"_server_response_error_", nil)], request.redirectedServer);
- }
-
- } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
-
- failureRequest(response, error, request.redirectedServer);
- }];
- }
- #pragma mark - End-to-End Encryption
- - (void)getEndToEndPublicKeys:(NSString*)serverPath onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *publicKey, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
-
- serverPath = [serverPath stringByAppendingString:k_url_client_side_encryption];
- serverPath = [serverPath stringByAppendingString:@"/public-key"];
- serverPath = [serverPath stringByAppendingString:@"?format=json"];
-
- OCWebDAVClient *request = [OCWebDAVClient new];
- request = [self getRequestWithCredentials:request];
-
- [request getEndToEndPublicKeys:serverPath onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
-
- NSData *responseData = (NSData*) responseObject;
- NSString *publicKey = @"";
-
- //Parse
- NSError *error;
- NSDictionary *jsongParsed = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
- NSLog(@"[LOG] E2E Get PublicKey : %@",jsongParsed);
-
- if (jsongParsed && jsongParsed.allKeys > 0) {
-
- NSDictionary *ocs = [jsongParsed valueForKey:@"ocs"];
- NSDictionary *meta = [ocs valueForKey:@"meta"];
- NSDictionary *data = [ocs valueForKey:@"data"];
-
- NSInteger statusCode = [[meta valueForKey:@"statuscode"] integerValue];
-
- if (statusCode == kOCUserProfileAPISuccessful) {
-
- if ([data valueForKey:@"public-keys"] && ![[data valueForKey:@"public-keys"] isKindOfClass:[NSNull class]]) {
-
- NSDictionary *publickeys = [data valueForKey:@"public-keys"];
- publicKey = [publickeys valueForKey:self.userID];
-
- successRequest(response, publicKey, request.redirectedServer);
-
- } else {
- failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedString(@"_server_response_error_", nil)], request.redirectedServer);
- }
-
- } else {
-
- NSString *message = (NSString *)[meta objectForKey:@"message"];
- if ([message isKindOfClass:[NSNull class]]) {
- message = NSLocalizedString(@"_server_response_error_", nil);
- }
- failureRequest(response, [UtilsFramework getErrorWithCode:statusCode andCustomMessageFromTheServer:message], request.redirectedServer);
- }
-
- } else {
- failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedString(@"_server_response_error_", nil)], request.redirectedServer);
- }
-
- } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
-
- //Return error
- failureRequest(response, error, request.redirectedServer);
- }];
- }
- - (void)getEndToEndPrivateKeyCipher:(NSString*)serverPath onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *privateKeyChiper, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
-
- serverPath = [serverPath stringByAppendingString:k_url_client_side_encryption];
- serverPath = [serverPath stringByAppendingString:@"/private-key"];
- serverPath = [serverPath stringByAppendingString:@"?format=json"];
- OCWebDAVClient *request = [OCWebDAVClient new];
- request = [self getRequestWithCredentials:request];
-
- [request getEndToEndPrivateKeyCipher:serverPath onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
-
- NSData *responseData = (NSData*) responseObject;
- NSString *privateKeyChiper = @"";
-
- //Parse
- NSError *error;
- NSDictionary *jsongParsed = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
- NSLog(@"[LOG] E2E Get PrivateKey : %@",jsongParsed);
-
- if (jsongParsed && jsongParsed.allKeys > 0) {
-
- NSDictionary *ocs = [jsongParsed valueForKey:@"ocs"];
- NSDictionary *meta = [ocs valueForKey:@"meta"];
- NSDictionary *data = [ocs valueForKey:@"data"];
-
- NSInteger statusCode = [[meta valueForKey:@"statuscode"] integerValue];
-
- if (statusCode == kOCUserProfileAPISuccessful) {
-
- if ([data valueForKey:@"private-key"] && ![[data valueForKey:@"private-key"] isKindOfClass:[NSNull class]]) {
-
- privateKeyChiper = [data valueForKey:@"private-key"];
- successRequest(response, privateKeyChiper, request.redirectedServer);
-
- } else {
- failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedString(@"_server_response_error_", nil)], request.redirectedServer);
- }
- } else {
-
- NSString *message = (NSString *)[meta objectForKey:@"message"];
- if ([message isKindOfClass:[NSNull class]]) {
- message = NSLocalizedString(@"_server_response_error_", nil);
- }
- failureRequest(response, [UtilsFramework getErrorWithCode:statusCode andCustomMessageFromTheServer:message], request.redirectedServer);
- }
- } else {
- failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedString(@"_server_response_error_", nil)], request.redirectedServer);
- }
-
- } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
-
- //Return error
- failureRequest(response, error, request.redirectedServer);
- }];
- }
- - (void)getEndToEndServerPublicKey:(NSString*)serverPath onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *publicKey, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
-
- serverPath = [serverPath stringByAppendingString:k_url_client_side_encryption];
- serverPath = [serverPath stringByAppendingString:@"/server-key"];
- serverPath = [serverPath stringByAppendingString:@"?format=json"];
- OCWebDAVClient *request = [OCWebDAVClient new];
- request = [self getRequestWithCredentials:request];
-
- [request getEndToEndServerPublicKey:serverPath onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
-
- NSData *responseData = (NSData*) responseObject;
- NSString *publicKey = @"";
-
- //Parse
- NSError *error;
- NSDictionary *jsongParsed = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
- NSLog(@"[LOG] E2E Get Server PublicKey : %@",jsongParsed);
-
- if (jsongParsed && jsongParsed.allKeys > 0) {
-
- NSDictionary *ocs = [jsongParsed valueForKey:@"ocs"];
- NSDictionary *meta = [ocs valueForKey:@"meta"];
- NSDictionary *data = [ocs valueForKey:@"data"];
-
- NSInteger statusCode = [[meta valueForKey:@"statuscode"] integerValue];
-
- if (statusCode == kOCUserProfileAPISuccessful) {
-
- if ([data valueForKey:@"public-key"] && ![[data valueForKey:@"public-key"] isKindOfClass:[NSNull class]]) {
-
- publicKey = [data valueForKey:@"public-key"];
- successRequest(response, publicKey, request.redirectedServer);
-
- } else {
- failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedString(@"_server_response_error_", nil)], request.redirectedServer);
- }
- } else {
-
- NSString *message = (NSString *)[meta objectForKey:@"message"];
- if ([message isKindOfClass:[NSNull class]]) {
- message = NSLocalizedString(@"_server_response_error_", nil);
- }
- failureRequest(response, [UtilsFramework getErrorWithCode:statusCode andCustomMessageFromTheServer:message], request.redirectedServer);
- }
- } else {
- failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedString(@"_server_response_error_", nil)], request.redirectedServer);
- }
-
- //Return success
-
- } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
-
- //Return error
- failureRequest(response, error, request.redirectedServer);
- }];
- }
- - (void)signEndToEndPublicKey:(NSString*)serverPath publicKey:(NSString *)publicKey onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *publicKey,NSString *redirectedServer))successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
-
- serverPath = [serverPath stringByAppendingString:k_url_client_side_encryption];
- serverPath = [serverPath stringByAppendingString:@"/public-key"];
- serverPath = [serverPath stringByAppendingString:@"?format=json"];
-
- OCWebDAVClient *request = [[OCWebDAVClient alloc] init];
- request = [self getRequestWithCredentials:request];
-
- [request signEndToEndPublicKey:serverPath key:publicKey onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
-
- NSData *responseData = (NSData*) responseObject;
- NSString *publicKey = @"";
-
- //Parse
- NSError *error;
- NSDictionary *jsongParsed = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
- NSLog(@"[LOG] E2E Sign PublicKey : %@",jsongParsed);
-
- if (jsongParsed && jsongParsed.allKeys > 0) {
-
- NSDictionary *ocs = [jsongParsed valueForKey:@"ocs"];
- NSDictionary *meta = [ocs valueForKey:@"meta"];
- NSDictionary *data = [ocs valueForKey:@"data"];
-
- NSInteger statusCode = [[meta valueForKey:@"statuscode"] integerValue];
-
- if (statusCode == kOCUserProfileAPISuccessful) {
-
- if ([data valueForKey:@"public-key"] && ![[data valueForKey:@"public-key"] isKindOfClass:[NSNull class]]) {
-
- publicKey = [data valueForKey:@"public-key"];
- successRequest(response, publicKey, request.redirectedServer);
-
- } else {
- failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedString(@"_server_response_error_", nil)], request.redirectedServer);
- }
- } else {
-
- NSString *message = (NSString *)[meta objectForKey:@"message"];
- if ([message isKindOfClass:[NSNull class]]) {
- message = NSLocalizedString(@"_server_response_error_", nil);
- }
- failureRequest(response, [UtilsFramework getErrorWithCode:statusCode andCustomMessageFromTheServer:message], request.redirectedServer);
- }
- } else {
- failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedString(@"_server_response_error_", nil)], request.redirectedServer);
- }
-
- } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
-
- //Return error
- failureRequest(response, error, request.redirectedServer);
- }];
- }
- - (void)storeEndToEndPrivateKeyCipher:(NSString*)serverPath privateKeyChiper:(NSString *)privateKeyChiper onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *privateKey, NSString *redirectedServer))successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
-
- serverPath = [serverPath stringByAppendingString:k_url_client_side_encryption];
- serverPath = [serverPath stringByAppendingString:@"/private-key"];
- serverPath = [serverPath stringByAppendingString:@"?format=json"];
-
- OCWebDAVClient *request = [[OCWebDAVClient alloc] init];
- request = [self getRequestWithCredentials:request];
-
- [request storeEndToEndPrivateKeyCipher:serverPath key:privateKeyChiper onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
-
- NSData *responseData = (NSData*) responseObject;
- NSString *privateKey = @"";
-
- //Parse
- NSError *error;
- NSDictionary *jsongParsed = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
- NSLog(@"[LOG] E2E Store PrivateKey : %@",jsongParsed);
-
- if (jsongParsed && jsongParsed.allKeys > 0) {
-
- NSDictionary *ocs = [jsongParsed valueForKey:@"ocs"];
- NSDictionary *meta = [ocs valueForKey:@"meta"];
- NSDictionary *data = [ocs valueForKey:@"data"];
-
- NSInteger statusCode = [[meta valueForKey:@"statuscode"] integerValue];
-
- if (statusCode == kOCUserProfileAPISuccessful) {
-
- if ([data valueForKey:@"private-key"] && ![[data valueForKey:@"private-key"] isKindOfClass:[NSNull class]]) {
-
- privateKey = [data valueForKey:@"private-key"];
- successRequest(response, privateKey, request.redirectedServer);
-
- } else {
- failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedString(@"_server_response_error_", nil)], request.redirectedServer);
- }
-
- } else {
-
- NSString *message = (NSString *)[meta objectForKey:@"message"];
- if ([message isKindOfClass:[NSNull class]]) {
- message = NSLocalizedString(@"_server_response_error_", nil);
- }
- failureRequest(response, [UtilsFramework getErrorWithCode:statusCode andCustomMessageFromTheServer:message], request.redirectedServer);
- }
- } else {
- failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedString(@"_server_response_error_", nil)], request.redirectedServer);
- }
-
- } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
-
- //Return error
- failureRequest(response, error, request.redirectedServer);
- }];
- }
- - (void)deleteEndToEndPublicKey:(NSString*)serverPath onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
-
- serverPath = [serverPath stringByAppendingString:k_url_client_side_encryption];
- serverPath = [serverPath stringByAppendingString:@"/public-key"];
- serverPath = [serverPath stringByAppendingString:@"?format=json"];
-
- OCWebDAVClient *request = [OCWebDAVClient new];
- request = [self getRequestWithCredentials:request];
-
- [request deleteEndToEndPublicKey:serverPath onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
-
- //Return success
- successRequest(response, request.redirectedServer);
-
- } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
-
- //Return error
- failureRequest(response, error, request.redirectedServer);
- }];
- }
- - (void)deleteEndToEndPrivateKey:(NSString*)serverPath onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
-
- serverPath = [serverPath stringByAppendingString:k_url_client_side_encryption];
- serverPath = [serverPath stringByAppendingString:@"/private-key"];
- serverPath = [serverPath stringByAppendingString:@"?format=json"];
- OCWebDAVClient *request = [OCWebDAVClient new];
- request = [self getRequestWithCredentials:request];
-
- [request deleteEndToEndPrivateKey:serverPath onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
-
- //Return success
- successRequest(response, request.redirectedServer);
-
- } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
-
- //Return error
- failureRequest(response, error, request.redirectedServer);
- }];
- }
- - (void)markEndToEndFolderEncrypted:(NSString*)serverPath fileID:(NSString *)fileID onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
-
- serverPath = [serverPath stringByAppendingString:k_url_client_side_encryption];
- serverPath = [NSString stringWithFormat:@"%@/encrypted/%@", serverPath, fileID];
- serverPath = [serverPath stringByAppendingString:@"?format=json"];
- OCWebDAVClient *request = [OCWebDAVClient new];
- request = [self getRequestWithCredentials:request];
-
- [request markEndToEndFolderEncrypted:serverPath onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
-
- //Return success
- successRequest(response, request.redirectedServer);
-
- } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
-
- //Return error
- failureRequest(response, error, request.redirectedServer);
- }];
- }
- - (void)deletemarkEndToEndFolderEncrypted:(NSString*)serverPath fileID:(NSString *)fileID onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
-
- serverPath = [serverPath stringByAppendingString:k_url_client_side_encryption];
- serverPath = [NSString stringWithFormat:@"%@/encrypted/%@", serverPath, fileID];
- serverPath = [serverPath stringByAppendingString:@"?format=json"];
- OCWebDAVClient *request = [OCWebDAVClient new];
- request = [self getRequestWithCredentials:request];
-
- [request deletemarkEndToEndFolderEncrypted:serverPath onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
-
- //Return success
- successRequest(response, request.redirectedServer);
-
- } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
-
- //Return error
- failureRequest(response, error, request.redirectedServer);
- }];
- }
- - (void)lockEndToEndFolderEncrypted:(NSString*)serverPath fileID:(NSString *)fileID token:(NSString *)token onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *token, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
-
- serverPath = [serverPath stringByAppendingString:k_url_client_side_encryption];
- serverPath = [NSString stringWithFormat:@"%@/lock/%@", serverPath, fileID];
- if (token) {
- serverPath = [NSString stringWithFormat:@"%@?token=%@", serverPath, token];
- serverPath = [serverPath stringByAppendingString:@"&format=json"];
- } else {
- serverPath = [serverPath stringByAppendingString:@"?format=json"];
- }
- OCWebDAVClient *request = [OCWebDAVClient new];
- request = [self getRequestWithCredentials:request];
-
- [request lockEndToEndFolderEncrypted:serverPath onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
-
- NSData *responseData = (NSData*) responseObject;
- NSString *token = @"";
-
- //Parse
- NSError *error;
- NSDictionary *jsongParsed = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
- NSLog(@"[LOG] E2E Lock File : %@",jsongParsed);
-
- if (jsongParsed && jsongParsed.allKeys > 0) {
-
- NSDictionary *ocs = [jsongParsed valueForKey:@"ocs"];
- NSDictionary *meta = [ocs valueForKey:@"meta"];
- NSDictionary *data = [ocs valueForKey:@"data"];
-
- NSInteger statusCode = [[meta valueForKey:@"statuscode"] integerValue];
-
- if (statusCode == kOCUserProfileAPISuccessful) {
-
- if ([data valueForKey:@"token"] && ![[data valueForKey:@"token"] isKindOfClass:[NSNull class]]) {
-
- token = [data valueForKey:@"token"];
- successRequest(response, token, request.redirectedServer);
-
- } else {
- failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedString(@"_server_response_error_", nil)], request.redirectedServer);
- }
- } else {
-
- NSString *message = (NSString *)[meta objectForKey:@"message"];
- if ([message isKindOfClass:[NSNull class]]) {
- message = NSLocalizedString(@"_server_response_error_", nil);
- }
- failureRequest(response, [UtilsFramework getErrorWithCode:statusCode andCustomMessageFromTheServer:message], request.redirectedServer);
- }
- } else {
- failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedString(@"_server_response_error_", nil)], request.redirectedServer);
- }
-
- } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
-
- //Return error
- failureRequest(response, error, request.redirectedServer);
- }];
- }
- - (void)unlockEndToEndFolderEncrypted:(NSString*)serverPath fileID:(NSString *)fileID token:(NSString *)token onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
-
- serverPath = [serverPath stringByAppendingString:k_url_client_side_encryption];
- serverPath = [NSString stringWithFormat:@"%@/lock/%@", serverPath, fileID];
- serverPath = [serverPath stringByAppendingString:@"&format=json"];
- OCWebDAVClient *request = [OCWebDAVClient new];
- request = [self getRequestWithCredentials:request];
-
- [request unlockEndToEndFolderEncrypted:serverPath token:token onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
-
- //Return success
- successRequest(response, request.redirectedServer);
-
- } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
-
- //Return error
- failureRequest(response, error, request.redirectedServer);
- }];
- }
- - (void)getEndToEndMetadata:(NSString*)serverPath fileID:(NSString *)fileID onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *encryptedMetadata, NSString *redirectedServer))successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
-
- serverPath = [serverPath stringByAppendingString:k_url_client_side_encryption];
- serverPath = [NSString stringWithFormat:@"%@/meta-data/%@", serverPath, fileID];
- serverPath = [serverPath stringByAppendingString:@"?format=json"];
- OCWebDAVClient *request = [[OCWebDAVClient alloc] init];
- request = [self getRequestWithCredentials:request];
-
- [request getEndToEndMetadata:serverPath onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
-
- NSData *responseData = (NSData*) responseObject;
- NSString *encryptedMetadata = @"";
-
- //Parse
- NSError *error;
- NSDictionary *jsongParsed = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
- NSLog(@"[LOG] E2E Get Metadata : %@",jsongParsed);
-
- if (jsongParsed && jsongParsed.allKeys > 0) {
-
- NSDictionary *ocs = [jsongParsed valueForKey:@"ocs"];
- NSDictionary *meta = [ocs valueForKey:@"meta"];
- NSDictionary *data = [ocs valueForKey:@"data"];
-
- NSInteger statusCode = [[meta valueForKey:@"statuscode"] integerValue];
-
- if (statusCode == kOCUserProfileAPISuccessful) {
-
- if ([data valueForKey:@"meta-data"] && ![[data valueForKey:@"meta-data"] isKindOfClass:[NSNull class]]) {
-
- encryptedMetadata = [data valueForKey:@"meta-data"];
- successRequest(response, encryptedMetadata, request.redirectedServer);
-
- } else {
- failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedString(@"_server_response_error_", nil)], request.redirectedServer);
- }
- } else {
- NSString *message = (NSString *)[meta objectForKey:@"message"];
- if ([message isKindOfClass:[NSNull class]]) {
- message = NSLocalizedString(@"_server_response_error_", nil);
- }
- failureRequest(response, [UtilsFramework getErrorWithCode:statusCode andCustomMessageFromTheServer:message], request.redirectedServer);
- }
- } else {
- failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedString(@"_server_response_error_", nil)], request.redirectedServer);
- }
-
- } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
-
- //Return error
- failureRequest(response, error, request.redirectedServer);
- }];
- }
- - (void)storeEndToEndMetadata:(NSString*)serverPath fileID:(NSString *)fileID encryptedMetadata:(NSString *)encryptedMetadata onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *encryptedMetadata, NSString *redirectedServer))successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
-
- encryptedMetadata = [encryptedMetadata encodeString:NSUTF8StringEncoding];
-
- serverPath = [serverPath stringByAppendingString:k_url_client_side_encryption];
- serverPath = [NSString stringWithFormat:@"%@/meta-data/%@", serverPath, fileID];
- serverPath = [serverPath stringByAppendingString:@"?format=json"];
-
- OCWebDAVClient *request = [[OCWebDAVClient alloc] init];
- request = [self getRequestWithCredentials:request];
-
- [request storeEndToEndMetadata:serverPath metadata:encryptedMetadata onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
-
- NSData *responseData = (NSData*) responseObject;
- NSString *encryptedMetadata = @"";
-
- //Parse
- NSError *error;
- NSDictionary *jsongParsed = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
- NSLog(@"[LOG] E2E Store Metadata : %@",jsongParsed);
-
- if (jsongParsed && jsongParsed.allKeys > 0) {
-
- NSDictionary *ocs = [jsongParsed valueForKey:@"ocs"];
- NSDictionary *meta = [ocs valueForKey:@"meta"];
- NSDictionary *data = [ocs valueForKey:@"data"];
-
- NSInteger statusCode = [[meta valueForKey:@"statuscode"] integerValue];
-
- if (statusCode == kOCUserProfileAPISuccessful) {
-
- if ([data valueForKey:@"meta-data"] && ![[data valueForKey:@"meta-data"] isKindOfClass:[NSNull class]]) {
-
- encryptedMetadata = [data valueForKey:@"meta-data"];
- successRequest(response, encryptedMetadata, request.redirectedServer);
-
- } else {
- failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedString(@"_server_response_error_", nil)], request.redirectedServer);
- }
- } else {
-
- NSString *message = (NSString *)[meta objectForKey:@"message"];
- if ([message isKindOfClass:[NSNull class]]) {
- message = NSLocalizedString(@"_server_response_error_", nil);
- }
- failureRequest(response, [UtilsFramework getErrorWithCode:statusCode andCustomMessageFromTheServer:message], request.redirectedServer);
- }
- } else {
- failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedString(@"_server_response_error_", nil)], request.redirectedServer);
- }
-
- } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
-
- //Return error
- failureRequest(response, error, request.redirectedServer);
- }];
- }
- - (void)updateEndToEndMetadata:(NSString*)serverPath fileID:(NSString *)fileID encryptedMetadata:(NSString *)encryptedMetadata token:(NSString *)token onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *encryptedMetadata, NSString *redirectedServer))successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
-
- encryptedMetadata = [encryptedMetadata encodeString:NSUTF8StringEncoding];
- serverPath = [serverPath stringByAppendingString:k_url_client_side_encryption];
- serverPath = [NSString stringWithFormat:@"%@/meta-data/%@", serverPath, fileID];
- serverPath = [NSString stringWithFormat:@"%@?token=%@", serverPath, token];
- serverPath = [serverPath stringByAppendingString:@"&format=json"];
-
- OCWebDAVClient *request = [[OCWebDAVClient alloc] init];
- request = [self getRequestWithCredentials:request];
-
- [request updateEndToEndMetadata:serverPath metadata:encryptedMetadata onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
-
- NSData *responseData = (NSData*) responseObject;
- NSString *encryptedMetadata = @"";
-
- //Parse
- NSError *error;
- NSDictionary *jsongParsed = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
- NSLog(@"[LOG] E2E Update Metadata : %@",jsongParsed);
-
- if (jsongParsed && jsongParsed.allKeys > 0) {
-
- NSDictionary *ocs = [jsongParsed valueForKey:@"ocs"];
- NSDictionary *meta = [ocs valueForKey:@"meta"];
- NSDictionary *data = [ocs valueForKey:@"data"];
-
- NSInteger statusCode = [[meta valueForKey:@"statuscode"] integerValue];
-
- if (statusCode == kOCUserProfileAPISuccessful) {
-
- if ([data valueForKey:@"meta-data"] && ![[data valueForKey:@"meta-data"] isKindOfClass:[NSNull class]]) {
-
- encryptedMetadata = [data valueForKey:@"meta-data"];
- successRequest(response, encryptedMetadata, request.redirectedServer);
-
- } else {
- failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedString(@"_server_response_error_", nil)], request.redirectedServer);
- }
- } else {
-
- NSString *message = (NSString *)[meta objectForKey:@"message"];
- if ([message isKindOfClass:[NSNull class]]) {
- message = NSLocalizedString(@"_server_response_error_", nil);
- }
- failureRequest(response, [UtilsFramework getErrorWithCode:statusCode andCustomMessageFromTheServer:message], request.redirectedServer);
- }
- } else {
- failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedString(@"_server_response_error_", nil)], request.redirectedServer);
- }
-
- } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
-
- //Return error
- failureRequest(response, error, request.redirectedServer);
- }];
- }
- - (void)deleteEndToEndMetadata:(NSString*)serverPath fileID:(NSString *)fileID onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer))successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
-
- serverPath = [serverPath stringByAppendingString:k_url_client_side_encryption];
- serverPath = [NSString stringWithFormat:@"%@/meta-data/%@", serverPath, fileID];
- serverPath = [serverPath stringByAppendingString:@"?format=json"];
- OCWebDAVClient *request = [[OCWebDAVClient alloc] init];
- request = [self getRequestWithCredentials:request];
-
- [request deleteEndToEndMetadata:serverPath onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
-
- //Return success
- successRequest(response, request.redirectedServer);
-
- } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
-
- //Return error
- failureRequest(response, error, request.redirectedServer);
- }];
- }
- #pragma mark - Manage Mobile Editor OCS API
- - (void)createLinkRichdocuments:(NSString *)serverPath fileID:(NSString *)fileID onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *link, NSString *redirectedServer))successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
-
- serverPath = [serverPath stringByAppendingString:k_url_create_link_mobile_editor];
- serverPath = [serverPath stringByAppendingString:@"?format=json"];
-
- OCWebDAVClient *request = [[OCWebDAVClient alloc] init];
- request = [self getRequestWithCredentials:request];
-
- [request createLinkRichdocuments:serverPath fileID:fileID onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *operation, id response) {
-
- NSData *responseData = (NSData*) response;
-
- //Parse
- NSError *error;
- NSDictionary *jsongParsed = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
- NSLog(@"[LOG] Link richdocuments : %@",jsongParsed);
-
- if (jsongParsed && jsongParsed.allKeys > 0) {
-
- NSDictionary *ocs = [jsongParsed valueForKey:@"ocs"];
- NSDictionary *meta = [ocs valueForKey:@"meta"];
- NSDictionary *data = [ocs valueForKey:@"data"];
-
- NSInteger statusCode = [[meta valueForKey:@"statuscode"] integerValue];
-
- if (statusCode == kOCUserProfileAPISuccessful) {
-
- if ([data valueForKey:@"url"] && ![[data valueForKey:@"url"] isKindOfClass:[NSNull class]]) {
-
- NSString *link = [data valueForKey:@"url"];
- successRequest(response, link, request.redirectedServer);
-
- } else {
- failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedString(@"_server_response_error_", nil)], request.redirectedServer);
- }
-
- } else {
-
- NSString *message = (NSString *)[meta objectForKey:@"message"];
- if ([message isKindOfClass:[NSNull class]]) {
- message = NSLocalizedString(@"_server_response_error_", nil);
- }
- failureRequest(response, [UtilsFramework getErrorWithCode:statusCode andCustomMessageFromTheServer:message], request.redirectedServer);
- }
-
- } else {
- failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedString(@"_server_response_error_", nil)], request.redirectedServer);
- }
-
- } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
-
- //Return error
- failureRequest(response, error, request.redirectedServer);
- }];
- }
- - (void)createTemplateRichdocuments:(NSString *)serverPath template:(NSString *)template onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSArray *listOfTemplate, NSString *redirectedServer))successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
-
- serverPath = [serverPath stringByAppendingString:k_url_create_template_mobile_editor];
- serverPath = [serverPath stringByAppendingString:template];
- serverPath = [serverPath stringByAppendingString:@"?format=json"];
-
- OCWebDAVClient *request = [[OCWebDAVClient alloc] init];
- request = [self getRequestWithCredentials:request];
-
- [request createTemplateRichdocuments:serverPath onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *operation, id response) {
-
- NSData *responseData = (NSData*) response;
-
- //Parse
- NSError *error;
- NSDictionary *jsongParsed = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
- NSLog(@"[LOG] Link richdocuments : %@",jsongParsed);
-
- if (jsongParsed && jsongParsed.allKeys > 0) {
-
- NSMutableArray *list = [NSMutableArray new];
-
- NSDictionary *ocs = [jsongParsed valueForKey:@"ocs"];
- NSDictionary *meta = [ocs valueForKey:@"meta"];
- NSDictionary *data = [ocs valueForKey:@"data"];
-
- NSInteger statusCode = [[meta valueForKey:@"statuscode"] integerValue];
-
- if (statusCode == kOCUserProfileAPISuccessful) {
-
- for (NSDictionary *dicDatas in data) {
-
- NCRichDocumentTemplate *template = [NCRichDocumentTemplate new];
-
- if ([dicDatas valueForKey:@"id"] && ![[dicDatas valueForKey:@"id"] isEqual:[NSNull null]])
- template.idTemplate = [[dicDatas valueForKey:@"id"] integerValue];
-
- if ([dicDatas valueForKey:@"delete"] && ![[dicDatas valueForKey:@"delete"] isKindOfClass:[NSNull class]])
- template.delete = [dicDatas valueForKey:@"delete"];
-
- if ([dicDatas valueForKey:@"extension"] && ![[dicDatas valueForKey:@"extension"] isKindOfClass:[NSNull class]])
- template.extension = [dicDatas valueForKey:@"extension"];
-
- if ([dicDatas valueForKey:@"name"] && ![[dicDatas valueForKey:@"name"] isKindOfClass:[NSNull class]])
- template.name = [dicDatas valueForKey:@"name"];
-
- if ([dicDatas valueForKey:@"preview"] && ![[dicDatas valueForKey:@"preview"] isKindOfClass:[NSNull class]])
- template.preview = [dicDatas valueForKey:@"preview"];
-
- if ([dicDatas valueForKey:@"type"] && ![[dicDatas valueForKey:@"type"] isKindOfClass:[NSNull class]])
- template.type = [dicDatas valueForKey:@"type"];
-
- [list addObject:template];
- }
-
- successRequest(response, list, request.redirectedServer);
- } else {
-
- NSString *message = (NSString *)[meta objectForKey:@"message"];
- if ([message isKindOfClass:[NSNull class]]) {
- message = NSLocalizedString(@"_server_response_error_", nil);
- }
- failureRequest(response, [UtilsFramework getErrorWithCode:statusCode andCustomMessageFromTheServer:message], request.redirectedServer);
- }
-
- } else {
- failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedString(@"_server_response_error_", nil)], request.redirectedServer);
- }
-
- } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
-
- //Return error
- failureRequest(response, error, request.redirectedServer);
- }];
- }
- - (void)createAssetRichdocuments:(NSString *)serverPath path:(NSString *)path onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *url, NSString *redirectedServer))successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
-
- serverPath = [serverPath stringByAppendingString:k_url_insert_assets_to_collabora];
- serverPath = [serverPath stringByAppendingString:@"?format=json"];
-
- OCWebDAVClient *request = [[OCWebDAVClient alloc] init];
- request = [self getRequestWithCredentials:request];
-
- [request createAssetRichdocuments:serverPath path:path onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *operation, id response) {
-
- NSData *responseData = (NSData*) response;
-
- //Parse
- NSError *error;
- NSDictionary *jsongParsed = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
- NSLog(@"[LOG] URL Asset : %@",jsongParsed);
-
- if (jsongParsed && jsongParsed.allKeys > 0) {
-
- if ([jsongParsed valueForKey:@"url"] && ![[jsongParsed valueForKey:@"url"] isKindOfClass:[NSNull class]]) {
-
- NSString *url = [jsongParsed valueForKey:@"url"];
- successRequest(response, url, request.redirectedServer);
-
- } else {
- failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedString(@"_server_response_error_", nil)], request.redirectedServer);
- }
-
- } else {
- failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedString(@"_server_response_error_", nil)], request.redirectedServer);
- }
-
- } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
-
- //Return error
- failureRequest(response, error, request.redirectedServer);
- }];
- }
- #pragma mark - Trash
- - (void)listingTrash:(NSString *)path onCommunication:(OCCommunication *)sharedOCCommunication successRequest:(void(^)(NSHTTPURLResponse *response, NSArray *items, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest
- {
- OCWebDAVClient *request = [OCWebDAVClient new];
- request = [self getRequestWithCredentials:request];
-
- [request listTrash:path onCommunication:sharedOCCommunication success:^(NSHTTPURLResponse *response, id responseObject) {
-
- OCXMLParser *parser = [OCXMLParser new];
- [parser initParserWithData:responseObject];
- NSMutableArray *list = [parser.directoryList mutableCopy];
-
- successRequest(response, list, request.redirectedServer);
-
- } failure:^(NSHTTPURLResponse *response, id responseData, NSError *error) {
-
- failureRequest(response, error, request.redirectedServer);
- }];
- }
- #pragma mark - Manage Mobile Editor OCS API
- - (void)eraseURLCache
- {
- [[NSURLCache sharedURLCache] setMemoryCapacity:0];
- [[NSURLCache sharedURLCache] setDiskCapacity:0];
- }
- #pragma mark - Utils
- - (void) addUserItemOfType:(NSInteger) shareeType fromArray:(NSArray*) usersArray ToList: (NSMutableArray *) itemList
- {
- for (NSDictionary *userFound in usersArray) {
- OCShareUser *user = [OCShareUser new];
-
- if ([[userFound valueForKey:@"label"] isKindOfClass:[NSNumber class]]) {
- NSNumber *number = [userFound valueForKey:@"label"];
- user.displayName = [NSString stringWithFormat:@"%ld", number.longValue];
- }else{
- user.displayName = [userFound valueForKey:@"label"];
- }
-
- NSDictionary *userValues = [userFound valueForKey:@"value"];
-
- if ([[userValues valueForKey:@"shareWith"] isKindOfClass:[NSNumber class]]) {
- NSNumber *number = [userValues valueForKey:@"shareWith"];
- user.name = [NSString stringWithFormat:@"%ld", number.longValue];
- }else{
- user.name = [userValues valueForKey:@"shareWith"];
- }
- user.shareeType = shareeType;
- user.server = [userValues valueForKey:@"server"];
-
- [itemList addObject:user];
- }
- }
- - (void) addGroupItemFromArray:(NSArray*) groupsArray ToList: (NSMutableArray *) itemList
- {
- for (NSDictionary *groupFound in groupsArray) {
-
- OCShareUser *group = [OCShareUser new];
-
- NSDictionary *groupValues = [groupFound valueForKey:@"value"];
- if ([[groupValues valueForKey:@"shareWith"] isKindOfClass:[NSNumber class]]) {
- NSNumber *number = [groupValues valueForKey:@"shareWith"];
- group.name = [NSString stringWithFormat:@"%ld", number.longValue];
- }else{
- group.name = [groupValues valueForKey:@"shareWith"];
- }
- group.shareeType = shareTypeGroup;
-
- [itemList addObject:group];
-
- }
- }
- @end
|