1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565 |
- //
- // 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 <marino.faggiana@nextcloud.com>
- // Copyright (c) 2017 Marino Faggiana. All rights reserved.
- //
- #import "OCCommunication.h"
- #import "OCHTTPRequestOperation.h"
- #import "UtilsFramework.h"
- #import "OCXMLSharedParser.h"
- #import "OCXMLServerErrorsParser.h"
- #import "NSString+Encode.h"
- #import "OCFrameworkConstants.h"
- #import "OCWebDAVClient.h"
- #import "OCXMLShareByLinkParser.h"
- #import "OCErrorMsg.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"
- #import "HCFeatures.h"
- #import "NCXMLCommentsParser.h"
- #import "NCXMLListParser.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;
- }
- - (void) setupNextcloudVersion:(NSInteger) version
- {
- self.nextcloudVersion = version;
- }
- ///-----------------------------------
- /// @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) {
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- NSData *responseData = (NSData*) responseObject;
-
- // NSString* newStr = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
- // NSLog(@"newStrReadFolder: %@", newStr);
-
- NCXMLListParser *parser = [NCXMLListParser new];
- [parser initParserWithData:responseData controlFirstFileOfList:true];
- NSMutableArray *list = [parser.list mutableCopy];
- dispatch_async(dispatch_get_main_queue(), ^{
- successRequest(response, list, request.redirectedServer, token);
- });
- });
- }
- } failure:^(NSHTTPURLResponse *response, id responseData, NSError *error, NSString *token) {
- NSLog(@"Failure");
- failureRequest(response, error, token, request.redirectedServer);
- }];
- }
- ///-----------------------------------
- /// @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) {
- if (successRequest) {
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- NSData *responseData = (NSData*) responseObject;
-
- // NSString* newStr = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
- // NSLog(@"newStrReadFolder: %@", newStr);
-
- NCXMLListParser *parser = [NCXMLListParser new];
- [parser initParserWithData:responseData controlFirstFileOfList:true];
- NSMutableArray *list = [parser.list mutableCopy];
-
- dispatch_async(dispatch_get_main_queue(), ^{
- successRequest(response, list, 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 lteDateLastModified:(NSString *)lteDateLastModified gteDateLastModified:(NSString *)gteDateLastModified 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 lteDateLastModified:lteDateLastModified gteDateLastModified:gteDateLastModified 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;
-
- NCXMLListParser *parser = [NCXMLListParser new];
- [parser initParserWithData:responseData controlFirstFileOfList:false];
- NSMutableArray *list = [parser.list mutableCopy];
-
- dispatch_async(dispatch_get_main_queue(), ^{
- successRequest(response, list, request.redirectedServer, token);
- });
- });
- }
- } failure:^(NSHTTPURLResponse *response, id responseData, NSError *error, NSString *token) {
-
- failureRequest(response, error, token, request.redirectedServer);
- }];
- }
- - (void)search:(NSString *)path folder:(NSString *)folder fileName:(NSString *)fileName dateLastModified:(NSString *)dateLastModified numberOfItem:(NSInteger)numberOfItem 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 dateLastModified:dateLastModified numberOfItem:numberOfItem 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;
-
- NCXMLListParser *parser = [NCXMLListParser new];
- [parser initParserWithData:responseData controlFirstFileOfList:false];
- NSMutableArray *list = [parser.list mutableCopy];
-
- dispatch_async(dispatch_get_main_queue(), ^{
- successRequest(response, list, 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) {
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
- NSData *responseData = (NSData*) responseObject;
-
- NCXMLListParser *parser = [NCXMLListParser new];
- [parser initParserWithData:responseData controlFirstFileOfList:false];
- NSMutableArray *list = [parser.list mutableCopy];
-
- dispatch_async(dispatch_get_main_queue(), ^{
- successRequest(response, list, request.redirectedServer, token);
- });
- });
- }
- } failure:^(NSHTTPURLResponse *response, id responseData, NSError *error, NSString *token) {
- failureRequest(response, error, token, request.redirectedServer);
- }];
- }
- ///-----------------------------------
- /// @name Download File Session
- ///-----------------------------------
- - (NSURLSessionDownloadTask *) downloadFileSession:(NSString *)remotePath toDestiny:(NSString *)localPath defaultPriority:(BOOL)defaultPriority encode:(BOOL)encode 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];
- if (encode) 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 encode:(BOOL)encode 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];
- if (encode) 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);
- }];
- }
- #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 andHideDownload:(BOOL)hideDownload
- 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 andHideDownload:hideDownload 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];
-
- if (parser.statusCode == kOCSharedAPISuccessful || parser.statusCode == kOCShareeAPISuccessful) {
-
- 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);
- }
-
- } else {
-
- 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];
-
- if (parser.statusCode == kOCSharedAPISuccessful || parser.statusCode == kOCShareeAPISuccessful) {
-
- 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);
- }
- } else {
-
- 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];
-
- if (parser.statusCode == kOCSharedAPISuccessful || parser.statusCode == kOCShareeAPISuccessful) {
- successRequest(response, request.redirectedServer);
- } else {
- 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 andNote:(NSString *)note andExpirationTime:(NSString*)expirationTime andPermissions:(NSInteger)permissions andHideDownload:(BOOL)hideDownload
- 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 andNote:note andExpirationTime:expirationTime andPermissions:permissions andHideDownload:hideDownload 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];
-
- if (parser.statusCode == kOCSharedAPISuccessful || parser.statusCode == kOCShareeAPISuccessful) {
- successRequest(response, request.redirectedServer);
- } else {
- 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);
- }];
- }
- #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"];
-
- //CORE
-
- NSDictionary *core = [capabilitiesDict valueForKey:@"core"];
-
- NSNumber *corePollIntervalNumber = (NSNumber*)[core valueForKey:@"pollinterval"];
- capabilities.corePollInterval = corePollIntervalNumber.integerValue;
- capabilities.coreWebDavRoot = [core valueForKey:@"webdav-root"];
-
- //FILE SHARING
-
- NSDictionary *fileSharing = [capabilitiesDict valueForKey:@"files_sharing"];
-
- NSNumber *fileSharingAPIEnabled = (NSNumber*)[fileSharing valueForKey:@"api_enabled"];
- NSNumber *filesSharingDefaultPermissions = (NSNumber*)[fileSharing valueForKey:@"default_permissions"];
- NSNumber *fileSharingGroupSharing = (NSNumber*)[fileSharing valueForKey:@"group_sharing"];
- NSNumber *filesSharingReSharing = (NSNumber*)[fileSharing valueForKey:@"resharing"];
-
- capabilities.isFilesSharingAPIEnabled = fileSharingAPIEnabled.boolValue;
- capabilities.filesSharingDefaulPermissions = filesSharingDefaultPermissions.integerValue;
- capabilities.isFilesSharingGroupSharing = fileSharingGroupSharing.boolValue;
- capabilities.isFilesSharingReSharing = filesSharingReSharing.boolValue;
- //FILE SHARING - PUBLIC
-
- NSDictionary *fileSharingPublic = [fileSharing valueForKey:@"public"];
-
- NSNumber *filesSharingPublicShareLinkEnabledNumber = (NSNumber*)[fileSharingPublic valueForKey:@"enabled"];
- NSNumber *filesSharingAllowPublicUploadsEnabledNumber = (NSNumber*)[fileSharingPublic valueForKey:@"upload"];
- NSNumber *isFilesSharingAllowPublicUserSendMailNumber = (NSNumber*)[fileSharingPublic valueForKey:@"send_mail"];
- NSNumber *filesSharingAllowPublicUploadFilesDrop = (NSNumber*)[fileSharingPublic valueForKey:@"upload_files_drop"];
- NSNumber *filesSharingAllowPublicMultipleLinks = (NSNumber*)[fileSharingPublic valueForKey:@"multiple_links"];
-
- capabilities.isFilesSharingPublicShareLinkEnabled = filesSharingPublicShareLinkEnabledNumber.boolValue;
- capabilities.isFilesSharingAllowPublicUploadsEnabled = filesSharingAllowPublicUploadsEnabledNumber.boolValue;
- capabilities.isFilesSharingAllowPublicUserSendMail = isFilesSharingAllowPublicUserSendMailNumber.boolValue;
- capabilities.isFilesSharingAllowPublicUploadFilesDrop = filesSharingAllowPublicUploadFilesDrop.boolValue;
- capabilities.isFilesSharingAllowPublicMultipleLinks = filesSharingAllowPublicMultipleLinks.boolValue;
-
- NSDictionary *fileSharingPublicExpireDate = [fileSharingPublic valueForKey:@"expire_date"];
-
- NSNumber *filesSharingPublicExpireDateByDefaultEnabledNumber = (NSNumber*)[fileSharingPublicExpireDate valueForKey:@"enabled"];
- NSNumber *filesSharingPublicExpireDateEnforceEnabledNumber = (NSNumber*)[fileSharingPublicExpireDate valueForKey:@"enforced"];
- NSNumber *filesSharingPublicExpireDateDaysNumber = (NSNumber*)[fileSharingPublicExpireDate valueForKey:@"days"];
-
- capabilities.isFilesSharingPublicExpireDateByDefaultEnabled = filesSharingPublicExpireDateByDefaultEnabledNumber.boolValue;
- capabilities.isFilesSharingPublicExpireDateEnforceEnabled = filesSharingPublicExpireDateEnforceEnabledNumber.boolValue;
- capabilities.filesSharingPublicExpireDateDays = filesSharingPublicExpireDateDaysNumber.integerValue;
-
- NSDictionary *fileSharingPublicPassword = [fileSharingPublic valueForKey:@"password"];
-
- NSNumber *fileSharingPublicPasswordEnforcedEnabled = (NSNumber*)[fileSharingPublicPassword valueForKey:@"enforced"];
-
- capabilities.isFilesSharingPublicPasswordEnforced = fileSharingPublicPasswordEnforcedEnabled.boolValue;
-
- //FILE SHARING - USER
- NSDictionary *fileSharingUser = [fileSharing valueForKey:@"user"];
-
- NSNumber *isFilesSharingAllowUserSendMailNumber = (NSNumber*)[fileSharingUser valueForKey:@"send_mail"];
-
- capabilities.isFilesSharingAllowUserSendMail = isFilesSharingAllowUserSendMailNumber.boolValue;
-
- NSDictionary *fileSharingUserExpireDate = [fileSharingUser valueForKey:@"expire_date"];
- NSNumber *filesSharingUserExpireDateNumber = (NSNumber*)[fileSharingUserExpireDate valueForKey:@"enabled"];
- capabilities.isFilesSharingUserExpireDate = filesSharingUserExpireDateNumber.boolValue;
-
- //FILE SHARING - GROUP
-
- NSDictionary *fileSharingGroup = [fileSharing valueForKey:@"group"];
-
- NSNumber *filesSharingGroupEnabled = (NSNumber*)[fileSharingGroup valueForKey:@"enabled"];
-
- capabilities.isFilesSharingGroupEnabled = filesSharingGroupEnabled.boolValue;
-
- NSDictionary *fileSharingGroupExpireDate = [fileSharingGroup valueForKey:@"expire_date"];
- NSNumber *filesSharingGroupExpireDateNumber = (NSNumber*)[fileSharingGroupExpireDate valueForKey:@"enabled"];
-
- capabilities.isFilesSharingGroupExpireDate = filesSharingGroupExpireDateNumber.boolValue;
-
- //FILE SHARING - FEDERATION
-
- NSDictionary *fileSharingFederation = [fileSharing valueForKey:@"federation"];
- NSDictionary *fileSharingFederationExpireDate = [fileSharingFederation valueForKey:@"expire_date"];
- NSNumber *filesSharingFederationAllowUserSendSharesNumber = (NSNumber*)[fileSharingFederation valueForKey:@"outgoing"];
- NSNumber *filesSharingFederationAllowUserReceiveSharesNumber = (NSNumber*)[fileSharingFederation valueForKey:@"incoming"];
- NSNumber *filesSharingFederationExpireDateNumber = (NSNumber*)[fileSharingFederationExpireDate valueForKey:@"enabled"];
- capabilities.isFilesSharingFederationAllowUserSendShares = filesSharingFederationAllowUserSendSharesNumber.boolValue;
- capabilities.isFilesSharingFederationAllowUserReceiveShares = filesSharingFederationAllowUserReceiveSharesNumber.boolValue;
- capabilities.isFilesSharingFederationExpireDate = filesSharingFederationExpireDateNumber.boolValue;
-
- //FILE SHARING - SHAREBYMAIL
-
- NSDictionary *fileSharingShareByMail = [fileSharing valueForKey:@"sharebymail"];
- NSNumber *fileSharingShareByMailEnabled = (NSNumber*)[fileSharingShareByMail valueForKey:@"enabled"];
-
- capabilities.isFileSharingShareByMailEnabled = fileSharingShareByMailEnabled.boolValue;
-
- NSDictionary *fileSharingShareByMailExpireDate = [fileSharingShareByMail valueForKey:@"expire_date"];
- NSNumber *fileSharingShareByMailExpireDateNumber = (NSNumber*)[fileSharingShareByMailExpireDate valueForKey:@"enabled"];
- capabilities.isFileSharingShareByMailExpireDate = fileSharingShareByMailExpireDateNumber.boolValue;
-
- NSDictionary *fileSharingShareByMailPassword = [fileSharingShareByMail valueForKey:@"password"];
-
- NSNumber *fileSharingShareByMailPasswordNumber = (NSNumber*)[fileSharingShareByMailPassword valueForKey:@"enabled"];
- capabilities.isFileSharingShareByMailPassword = fileSharingShareByMailPasswordNumber.boolValue;
- NSDictionary *fileSharingShareByMailUploadFilesDrop = [fileSharingShareByMail valueForKey:@"upload_files_drop"];
- NSNumber *fileSharingShareByMailUploadFilesDropNumber = (NSNumber*)[fileSharingShareByMailUploadFilesDrop valueForKey:@"enabled"];
- capabilities.isFileSharingShareByMailUploadFilesDrop = fileSharingShareByMailUploadFilesDropNumber.boolValue;
- // EXTERNAL SITES
-
- NSDictionary *externalSitesDic = [capabilitiesDict valueForKey:@"external"];
- if (externalSitesDic) {
- capabilities.isExternalSitesServerEnabled = YES;
- NSArray *externalSitesArray = [externalSitesDic valueForKey:@"v1"];
- capabilities.externalSiteV1 = [externalSitesArray componentsJoinedByString:@","];
- }
-
- // ACTIVITY
-
- NSDictionary *activityDic = [capabilitiesDict valueForKey:@"activity"];
- if (activityDic) {
- NSArray *activityArray = [activityDic valueForKey:@"apiv2"];
- if (activityArray) {
- capabilities.isActivityV2Enabled = YES;
- capabilities.activityV2 = [activityArray 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;
-
- NSDictionary *pagination = [files valueForKey:@"pagination"];
- if (pagination) {
- capabilities.isPaginationEnabled = true;
- capabilities.paginationEndponit = [pagination valueForKey:@"endpoint"];
- }
-
- //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.richdocumentsDirectEditing = [[richdocuments valueForKey:@"direct_editing"] boolValue];
- capabilities.richdocumentsMimetypes = [richdocuments valueForKey:@"mimetypes"];
- }
-
- //Handwerkcloud
-
- NSDictionary *handwerkcloudDic = [capabilitiesDict valueForKey:@"handwerkcloud"];
- if (handwerkcloudDic) {
- NSNumber *isHandwerkcloudEnabledNumber = (NSNumber*)[handwerkcloudDic valueForKey:@"enabled"];
- capabilities.isHandwerkcloudEnabled = isHandwerkcloudEnabledNumber.boolValue;
-
- if ([handwerkcloudDic valueForKey:@"shop_url"] && ![[handwerkcloudDic valueForKey:@"shop_url"] isEqual:[NSNull null]])
- capabilities.HCShopUrl = [handwerkcloudDic valueForKey:@"shop_url"];
- }
-
- //Imagemeter
-
- NSDictionary *imagemeterDic = [capabilitiesDict valueForKey:@"imagemeter"];
- if (imagemeterDic) {
- NSNumber *isImagemeterEnabledNumber = (NSNumber*)[imagemeterDic valueForKey:@"enabled"];
- capabilities.isImagemeterEnabled = isImagemeterEnabledNumber.boolValue;
- }
-
- //Fulltextsearch
- NSDictionary *fulltextsearchDic = [capabilitiesDict valueForKey:@"fulltextsearch"];
- if (fulltextsearchDic) {
- NSNumber *isFulltextsearchEnabledNumber = (NSNumber*)[fulltextsearchDic valueForKey:@"remote"];
- capabilities.isFulltextsearchEnabled = isFulltextsearchEnabledNumber.boolValue;
- }
-
- //extendedSupport
- NSDictionary *extendedSupportDic = [capabilitiesDict valueForKey:@"extendedSupport"];
- if (extendedSupportDic) {
- NSNumber *isExtendedSupportEnabled = (NSNumber*)[extendedSupportDic valueForKey:@"enabled"];
- capabilities.isExtendedSupportEnabled = isExtendedSupportEnabled.boolValue;
- }
- }
-
- 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 path:(NSString * _Nonnull)path 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 path:path 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 size:(NSString *)size 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 size:size 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) {
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- 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]] && [[data valueForKey:@"subjectRichParameters"] count] > 0)
- 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]] && [[data valueForKey:@"messageRichParameters"] count] > 0)
- 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];
- }
- dispatch_async(dispatch_get_main_queue(), ^{
- successRequest(response, listOfNotifications, request.redirectedServer);
- });
- } else {
-
- NSString *message = (NSString *)[meta objectForKey:@"message"];
- if ([message isKindOfClass:[NSNull class]]) {
- message = NSLocalizedString(@"_server_response_error_", nil);
- }
- dispatch_async(dispatch_get_main_queue(), ^{
- failureRequest(response, [UtilsFramework getErrorWithCode:statusCode andCustomMessageFromTheServer:message], request.redirectedServer);
- });
- }
- } else {
- dispatch_async(dispatch_get_main_queue(), ^{
- 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.defaultHeaders setObject:self.userAgent forKey:@"User-Agent"];
-
- [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.defaultHeaders setObject:self.userAgent forKey:@"User-Agent"];
-
- [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 since:(NSInteger)since limit:(NSInteger)limit objectId:(NSString *)objectId objectType:(NSString *)objectType previews:(BOOL)previews link:(NSString *)link 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 since:since limit:limit objectId:objectId objectType:objectType previews:previews link:link 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:@"activity_id"] && ![[data valueForKey:@"activity_id"] isEqual:[NSNull null]])
- activity.idActivity = [[data valueForKey:@"activity_id"] integerValue];
-
- 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"];
-
- activity.date = [dateFormatter dateFromString:dateString];
- }
-
- if ([data valueForKey:@"app"] && ![[data valueForKey:@"app"] isEqual:[NSNull null]])
- activity.app = [data valueForKey:@"app"];
-
- if ([data valueForKey:@"type"] && ![[data valueForKey:@"type"] isEqual:[NSNull null]])
- activity.type = [data valueForKey:@"type"];
-
- if ([data valueForKey:@"user"] && ![[data valueForKey:@"user"] isEqual:[NSNull null]])
- activity.user = [data valueForKey:@"user"];
-
- if ([data valueForKey:@"subject"] && ![[data valueForKey:@"subject"] isEqual:[NSNull null]])
- activity.subject = [data valueForKey:@"subject"];
-
- if ([data valueForKey:@"subject_rich"] && ![[data valueForKey:@"subject_rich"] isEqual:[NSNull null]])
- activity.subject_rich = [data valueForKey:@"subject_rich"];
-
- if ([data valueForKey:@"message"] && ![[data valueForKey:@"message"] isEqual:[NSNull null]])
- activity.message = [data valueForKey:@"message"];
-
- if ([data valueForKey:@"message_rich"] && ![[data valueForKey:@"message_rich"] isEqual:[NSNull null]])
- activity.message_rich = [data valueForKey:@"message_rich"];
-
- if ([data valueForKey:@"icon"] && ![[data valueForKey:@"icon"] isEqual:[NSNull null]])
- activity.icon = [data valueForKey:@"icon"];
-
- if ([data valueForKey:@"link"] && ![[data valueForKey:@"link"] isEqual:[NSNull null]])
- activity.link = [data valueForKey:@"link"];
-
- if ([data valueForKey:@"object_type"] && ![[data valueForKey:@"object_type"] isEqual:[NSNull null]])
- activity.object_type = [data valueForKey:@"object_type"];
-
- if ([data valueForKey:@"object_id"] && ![[data valueForKey:@"object_id"] isEqual:[NSNull null]])
- activity.object_id = [[data valueForKey:@"object_id"] integerValue];
-
- if ([data valueForKey:@"object_name"] && ![[data valueForKey:@"object_name"] isEqual:[NSNull null]])
- activity.object_name = [data valueForKey:@"object_name"];
-
- if ([data valueForKey:@"previews"] && ![[data valueForKey:@"previews"] isEqual:[NSNull null]])
- activity.previews = [data valueForKey:@"previews"];
-
- [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 e2eToken:(NSString *)e2eToken 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 e2eToken:e2eToken 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 e2eToken:(NSString *)e2eToken onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *e2eToken, 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 (e2eToken) {
- serverPath = [NSString stringWithFormat:@"%@?e2e-token=%@", serverPath, e2eToken];
- serverPath = [serverPath stringByAppendingString:@"&format=json"];
- } else {
- serverPath = [serverPath stringByAppendingString:@"?format=json"];
- }
- OCWebDAVClient *request = [OCWebDAVClient new];
- request = [self getRequestWithCredentials:request];
-
- [request lockEndToEndFolderEncrypted:serverPath e2eToken:e2eToken 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:@"e2e-token"] && ![[data valueForKey:@"e2e-token"] isKindOfClass:[NSNull class]]) {
-
- token = [data valueForKey:@"e2e-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 e2eToken:(NSString *)e2eToken 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 e2eToken:e2eToken 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 e2eToken:(NSString *)e2eToken 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 e2eToken:e2eToken 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 e2eToken:(NSString *)e2eToken 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:@"%@?e2e-token=%@", serverPath, e2eToken];
- serverPath = [serverPath stringByAppendingString:@"&format=json"];
-
- OCWebDAVClient *request = [[OCWebDAVClient alloc] init];
- request = [self getRequestWithCredentials:request];
-
- [request updateEndToEndMetadata:serverPath metadata:encryptedMetadata e2eToken:e2eToken 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 e2eToken:(NSString *)e2eToken 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 e2eToken:e2eToken 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_richdocuments];
- 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)getTemplatesRichdocuments:(NSString *)serverPath typeTemplate:(NSString *)typeTemplate 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_get_template_mobile_richdocuments];
- serverPath = [serverPath stringByAppendingString:typeTemplate];
- serverPath = [serverPath stringByAppendingString:@"?format=json"];
-
- OCWebDAVClient *request = [[OCWebDAVClient alloc] init];
- request = [self getRequestWithCredentials:request];
-
- [request getTemplatesRichdocuments: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.templateID = [[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)createNewRichdocuments:(NSString *)serverPath path:(NSString *)path templateID:(NSString *)templateID 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_create_new_mobile_richdocuments];
- serverPath = [serverPath stringByAppendingString:@"?format=json"];
-
- OCWebDAVClient *request = [[OCWebDAVClient alloc] init];
- request = [self getRequestWithCredentials:request];
-
- [request createNewRichdocuments:serverPath path:path templateID:templateID 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);
-
- 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]])
- successRequest(response, [data valueForKey:@"url"], request.redirectedServer);
- else
- successRequest(response, 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);
- }];
- }
- - (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_richdocuments];
- 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 depth:(NSString *)depth 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];
-
- path = [path encodeString:NSUTF8StringEncoding];
- [request listTrash:path depth:depth onCommunication:sharedOCCommunication success:^(NSHTTPURLResponse *response, id responseObject) {
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
- NCXMLListParser *parser = [NCXMLListParser new];
- [parser initParserWithData:responseObject controlFirstFileOfList:true];
- NSMutableArray *list = [parser.list mutableCopy];
-
- dispatch_async(dispatch_get_main_queue(), ^{
- successRequest(response, list, request.redirectedServer);
- });
- });
- } failure:^(NSHTTPURLResponse *response, id responseData, NSError *error) {
- failureRequest(response, error, request.redirectedServer);
- }];
- }
- - (void)emptyTrash:(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];
-
- [request emptyTrash:path onCommunication:sharedOCCommunication success:^(NSHTTPURLResponse *response, id responseObject) {
-
- successRequest(response, request.redirectedServer);
-
- } failure:^(NSHTTPURLResponse *response, id responseData, NSError *error) {
-
- failureRequest(response, error, request.redirectedServer);
- }];
- }
- #pragma mark - Fulltextsearch
- - (void)fullTextSearch:(NSString *)serverPath data:(NSString *)data onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSArray *items, NSString *redirectedServer))successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
-
- serverPath = [serverPath stringByAppendingString:k_url_fulltextsearch];
-
- OCWebDAVClient *request = [[OCWebDAVClient alloc] init];
- request = [self getRequestWithCredentials:request];
-
- [request fullTextSearch:serverPath data:data onCommunication:sharedOCComunication success:^(NSHTTPURLResponse * _Nonnull operation, id _Nonnull 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) {
-
- successRequest(response, 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 - Remore wipe
- - (void)getRemoteWipeStatus:(NSString *)serverPath token:(NSString *)token onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, BOOL wipe, NSString *redirectedServer))successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
-
- serverPath = [NSString stringWithFormat:@"%@/%@/check", serverPath, k_url_get_wipe];
-
- OCWebDAVClient *request = [[OCWebDAVClient alloc] init];
- request = [self getRequestWithCredentials:request];
-
- [request getSetRemoteWipe:serverPath token:token onCommunication:sharedOCComunication success:^(NSHTTPURLResponse * _Nonnull operation, id _Nonnull response) {
-
- NSData *responseData = (NSData*) response;
-
- //Parse
- NSError *error;
- NSDictionary *jsongParsed = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
-
- if (jsongParsed && jsongParsed.allKeys > 0) {
-
- BOOL wipe = (BOOL)[jsongParsed valueForKey:@"wipe"];
- successRequest(response, wipe, 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)setRemoteWipeCompletition:(NSString *)serverPath token:(NSString *)token onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer))successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
-
- serverPath = [NSString stringWithFormat:@"%@/%@/success", serverPath, k_url_get_wipe];
-
- OCWebDAVClient *request = [[OCWebDAVClient alloc] init];
- request = [self getRequestWithCredentials:request];
-
- [request getSetRemoteWipe:serverPath token:token onCommunication:sharedOCComunication success:^(NSHTTPURLResponse * _Nonnull operation, id _Nonnull response) {
-
- successRequest(response, request.redirectedServer);
-
- } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
-
- failureRequest(response, error, request.redirectedServer);
- }];
- }
- #pragma mark - Comments
- - (void)getComments:(NSString *)serverPath fileId:(NSString *)fileId onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSArray *list, NSString *redirectedServer))successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
-
- serverPath = [NSString stringWithFormat:@"%@/comments/files/%@", serverPath, fileId];
- serverPath = [serverPath encodeString:NSUTF8StringEncoding];
- OCWebDAVClient *request = [OCWebDAVClient new];
- request = [self getRequestWithCredentials:request];
-
- [request getComments:serverPath onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
-
- NSData *responseData = (NSData *)responseObject;
-
- NCXMLCommentsParser *parser = [NCXMLCommentsParser new];
- [parser initParserWithData:responseData];
- NSMutableArray *list = [parser.list mutableCopy];
-
- successRequest(response, list, request.redirectedServer);
-
- } failure:^(NSHTTPURLResponse *response, id responseData, NSError *error) {
-
- failureRequest(response, error, request.redirectedServer);
- }];
- }
- - (void)putComments:(NSString*)serverPath fileId:(NSString *)fileId message:(NSString *)message onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer))successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
-
- serverPath = [NSString stringWithFormat:@"%@/comments/files/%@", serverPath, fileId];
- serverPath = [serverPath encodeString:NSUTF8StringEncoding];
-
- OCWebDAVClient *request = [[OCWebDAVClient alloc] init];
- request = [self getRequestWithCredentials:request];
-
- [request putComments:serverPath message:message onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *operation, id response) {
-
- successRequest(response, request.redirectedServer);
- } failure:^(NSHTTPURLResponse *response, id responseObject, NSError *error) {
-
- failureRequest(response, error, request.redirectedServer);
- }];
- }
- - (void)updateComments:(NSString*)serverPath fileId:(NSString *)fileId messageID:(NSString *)messageID message:(NSString *)message onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer))successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
-
- serverPath = [NSString stringWithFormat:@"%@/comments/files/%@/%@", serverPath, fileId, messageID];
- serverPath = [serverPath encodeString:NSUTF8StringEncoding];
-
- OCWebDAVClient *request = [[OCWebDAVClient alloc] init];
- request = [self getRequestWithCredentials:request];
-
- [request updateComments:serverPath message:message onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *operation, id response) {
-
- successRequest(response, request.redirectedServer);
-
- } failure:^(NSHTTPURLResponse *response, id responseObject, NSError *error) {
-
- failureRequest(response, error, request.redirectedServer);
- }];
- }
- - (void)readMarkComments:(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 = [NSString stringWithFormat:@"%@/comments/files/%@", serverPath, fileId];
- serverPath = [serverPath encodeString:NSUTF8StringEncoding];
-
- OCWebDAVClient *request = [[OCWebDAVClient alloc] init];
- request = [self getRequestWithCredentials:request];
-
- [request readMarkComments:serverPath onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *operation, id response) {
-
- successRequest(response, request.redirectedServer);
-
- } failure:^(NSHTTPURLResponse *response, id responseObject, NSError *error) {
-
- failureRequest(response, error, request.redirectedServer);
- }];
- }
- - (void)deleteComments:(NSString*)serverPath fileId:(NSString *)fileId messageID:(NSString *)messageID onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer))successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
-
- serverPath = [NSString stringWithFormat:@"%@/comments/files/%@/%@", serverPath, fileId, messageID];
- serverPath = [serverPath encodeString:NSUTF8StringEncoding];
-
- OCWebDAVClient *request = [[OCWebDAVClient alloc] init];
- request = [self getRequestWithCredentials:request];
-
- [request deleteComments:serverPath onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *operation, id response) {
-
- successRequest(response, request.redirectedServer);
-
- } failure:^(NSHTTPURLResponse *response, id responseObject, NSError *error) {
-
- failureRequest(response, error, request.redirectedServer);
- }];
- }
- #pragma mark - Third Parts
- - (void)getHCUserProfile:(NSString *)serverPath onCommunication:(OCCommunication *)sharedOCCommunication successRequest:(void(^)(NSHTTPURLResponse *response, OCUserProfile *userProfile, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest
- {
- serverPath = [serverPath encodeString:NSUTF8StringEncoding];
-
- OCWebDAVClient *request = [OCWebDAVClient new];
- request = [self getRequestWithCredentials:request];
-
- [request getHCUserProfile:serverPath onCommunication:sharedOCCommunication success:^(NSHTTPURLResponse * _Nonnull operation, id _Nonnull response) {
-
- NSData *responseData = (NSData*) response;
- 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];
-
- data = [data valueForKey:@"data"];
- if (statusCode == kOCUserProfileAPISuccessful) {
-
- if ([data valueForKey:@"address"] && ![[data valueForKey:@"address"] isKindOfClass:[NSNull class]])
- userProfile.address = [data valueForKey:@"address"];
-
- if ([data valueForKey:@"displayname"] && ![[data valueForKey:@"displayname"] isKindOfClass:[NSNull class]])
- userProfile.displayName = [data valueForKey:@"displayname"];
-
- if ([data valueForKey:@"businesssize"] && ![[data valueForKey:@"businesssize"] isKindOfClass:[NSNull class]]) {
- switch ([[data valueForKey:@"businesssize"] integerValue]) {
- case 1:
- userProfile.businessSize = @"1-4";
- break;
- case 5:
- userProfile.businessSize = @"5-9";
- break;
- case 10:
- userProfile.businessSize = @"10-19";
- break;
- case 20:
- userProfile.businessSize = @"20-49";
- break;
- case 50:
- userProfile.businessSize = @"50-99";
- break;
- case 100:
- userProfile.businessSize = @"100-249";
- break;
- case 250:
- userProfile.businessSize = @"250-499";
- break;
- case 500:
- userProfile.businessSize = @"500-999";
- break;
- case 1000:
- userProfile.businessSize = @"1000+";
- break;
- default:
- break;
- }
- }
-
- if ([data valueForKey:@"businesstype"] && ![[data valueForKey:@"businesstype"] isKindOfClass:[NSNull class]])
- userProfile.businessType = [data valueForKey:@"businesstype"];
-
- if ([data valueForKey:@"city"] && ![[data valueForKey:@"city"] isKindOfClass:[NSNull class]])
- userProfile.city = [data valueForKey:@"city"];
-
- if ([data valueForKey:@"company"] && ![[data valueForKey:@"company"] isKindOfClass:[NSNull class]])
- userProfile.company = [data valueForKey:@"company"];
-
- if ([data valueForKey:@"country"] && ![[data valueForKey:@"country"] isKindOfClass:[NSNull class]])
- userProfile.country = [data valueForKey:@"country"];
-
- if ([data valueForKey:@"email"] && ![[data valueForKey:@"email"] isKindOfClass:[NSNull class]])
- userProfile.email = [data valueForKey:@"email"];
-
- if ([data valueForKey:@"phone"] && ![[data valueForKey:@"phone"] isKindOfClass:[NSNull class]])
- userProfile.phone = [data valueForKey:@"phone"];
-
- if ([data valueForKey:@"role"] && ![[data valueForKey:@"role"] isKindOfClass:[NSNull class]])
- userProfile.role = [data valueForKey:@"role"];
-
- if ([data valueForKey:@"twitter"] && ![[data valueForKey:@"twitter"] isKindOfClass:[NSNull class]])
- userProfile.twitter = [data valueForKey:@"twitter"];
-
- if ([data valueForKey:@"website"] && ![[data valueForKey:@"website"] isKindOfClass:[NSNull class]])
- userProfile.webpage = [data valueForKey:@"website"];
-
- if ([data valueForKey:@"zip"] && ![[data valueForKey:@"zip"] isKindOfClass:[NSNull class]])
- userProfile.zip = [data valueForKey:@"zip"];
-
- 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);
- }];
-
- }
- - (void)putHCUserProfile:(NSString*)serverPath data:(NSString *)data onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer))successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
-
- serverPath = [serverPath encodeString:NSUTF8StringEncoding];
- OCWebDAVClient *request = [[OCWebDAVClient alloc] init];
- request = [self getRequestWithCredentials:request];
-
- [request putHCUserProfile:serverPath data:data onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *operation, id response) {
-
- successRequest(response, request.redirectedServer);
-
- } failure:^(NSHTTPURLResponse *response, id responseObject, NSError *error) {
-
- failureRequest(response, error, request.redirectedServer);
- }];
- }
- - (void)getHCFeatures:(NSString *)serverPath onCommunication:(OCCommunication *)sharedOCCommunication successRequest:(void(^)(NSHTTPURLResponse *response, HCFeatures *features, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest
- {
- serverPath = [serverPath encodeString:NSUTF8StringEncoding];
-
- OCWebDAVClient *request = [OCWebDAVClient new];
- request = [self getRequestWithCredentials:request];
-
- [request getHCUserProfile:serverPath onCommunication:sharedOCCommunication success:^(NSHTTPURLResponse * _Nonnull operation, id _Nonnull response) {
-
- NSData *responseData = (NSData*) response;
- HCFeatures *features = [HCFeatures new];
-
- //Parse
- NSError *error;
- NSDictionary *jsongParsed = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
- NSLog(@"[LOG] User Profile Features : %@",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];
-
- data = [data valueForKey:@"data"];
-
- if (statusCode == kOCUserProfileAPISuccessful) {
-
- if ([data valueForKey:@"is_trial"] && ![[data valueForKey:@"is_trial"] isKindOfClass:[NSNull class]])
- features.isTrial = [[data valueForKey:@"is_trial"] boolValue];
-
- if ([data valueForKey:@"trial_expired"] && ![[data valueForKey:@"trial_expired"] isKindOfClass:[NSNull class]])
- features.trialExpired = [[data valueForKey:@"trial_expired"] boolValue];
-
- if ([data valueForKey:@"trial_remaining_sec"] && ![[data valueForKey:@"trial_remaining_sec"] isKindOfClass:[NSNull class]])
- features.trialRemainingSec = [[data valueForKey:@"trial_remaining_sec"] integerValue];
-
- if ([data valueForKey:@"trial_end_time"] && ![[data valueForKey:@"trial_end_time"] isKindOfClass:[NSNull class]])
- features.trialEndTime = [[data valueForKey:@"trial_end_time"] integerValue];
-
- if ([data valueForKey:@"trial_end"] && ![[data valueForKey:@"trial_end"] isKindOfClass:[NSNull class]])
- features.trialEnd = [data valueForKey:@"trial_end"];
-
- if ([data valueForKey:@"account_remove_expired"] && ![[data valueForKey:@"account_remove_expired"] isKindOfClass:[NSNull class]])
- features.accountRemoveExpired = [[data valueForKey:@"account_remove_expired"] boolValue];
-
- if ([data valueForKey:@"account_remove_remaining_sec"] && ![[data valueForKey:@"account_remove_remaining_sec"] isKindOfClass:[NSNull class]])
- features.accountRemoveRemainingSec = [[data valueForKey:@"account_remove_remaining_sec"] integerValue];
-
- if ([data valueForKey:@"account_remove_time"] && ![[data valueForKey:@"account_remove_time"] isKindOfClass:[NSNull class]])
- features.accountRemoveTime = [[data valueForKey:@"account_remove_time"] integerValue];
-
- if ([data valueForKey:@"account_remove"] && ![[data valueForKey:@"account_remove"] isKindOfClass:[NSNull class]])
- features.accountRemove = [data valueForKey:@"account_remove"];
-
- NSDictionary *nextGroupExpirationDic = [data valueForKey:@"next_group_expiration"];
- if (nextGroupExpirationDic) {
- if ([nextGroupExpirationDic valueForKey:@"group"] && ![[nextGroupExpirationDic valueForKey:@"group"] isKindOfClass:[NSNull class]])
- features.nextGroupExpirationGroup = [nextGroupExpirationDic valueForKey:@"group"];
-
- if ([nextGroupExpirationDic valueForKey:@"group_expired"] && ![[nextGroupExpirationDic valueForKey:@"group_expired"] isKindOfClass:[NSNull class]])
- features.nextGroupExpirationGroupExpired = [[nextGroupExpirationDic valueForKey:@"group_expired"] boolValue];
-
- if ([nextGroupExpirationDic valueForKey:@"expires_time"] && ![[nextGroupExpirationDic valueForKey:@"expires_time"] isKindOfClass:[NSNull class]])
- features.nextGroupExpirationExpiresTime = [[nextGroupExpirationDic valueForKey:@"expires_time"] integerValue];
-
- if ([nextGroupExpirationDic valueForKey:@"expires"] && ![[nextGroupExpirationDic valueForKey:@"expires"] isKindOfClass:[NSNull class]])
- features.nextGroupExpirationExpires = [nextGroupExpirationDic valueForKey:@"expires"];
- }
-
- successRequest(response, features, 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 - 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
|