OCCommunication.m 140 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767
  1. //
  2. // OCCommunication.m
  3. // Owncloud iOs Client
  4. //
  5. // Copyright (C) 2016, ownCloud GmbH. ( http://www.owncloud.org/ )
  6. //
  7. // Permission is hereby granted, free of charge, to any person obtaining a copy
  8. // of this software and associated documentation files (the "Software"), to deal
  9. // in the Software without restriction, including without limitation the rights
  10. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. // copies of the Software, and to permit persons to whom the Software is
  12. // furnished to do so, subject to the following conditions:
  13. // The above copyright notice and this permission notice shall be included in
  14. // all copies or substantial portions of the Software.
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. // THE SOFTWARE.
  22. //
  23. //
  24. // Add : getNotificationServer & setNotificationServer
  25. // Add : getUserProfileServer
  26. // Add : Support for Favorite
  27. // Add : getActivityServer
  28. //
  29. // Author Marino Faggiana <m.faggiana@twsweb.it>
  30. // Copyright (c) 2017 TWS. All rights reserved.
  31. //
  32. #import "OCCommunication.h"
  33. #import "OCHTTPRequestOperation.h"
  34. #import "UtilsFramework.h"
  35. #import "OCXMLParser.h"
  36. #import "OCXMLSharedParser.h"
  37. #import "OCXMLServerErrorsParser.h"
  38. #import "OCXMLListParser.h"
  39. #import "NSString+Encode.h"
  40. #import "OCFrameworkConstants.h"
  41. #import "OCWebDAVClient.h"
  42. #import "OCXMLShareByLinkParser.h"
  43. #import "OCErrorMsg.h"
  44. #import "AFURLSessionManager.h"
  45. #import "OCShareUser.h"
  46. #import "OCActivity.h"
  47. #import "OCExternalSites.h"
  48. #import "OCCapabilities.h"
  49. #import "OCNotifications.h"
  50. #import "OCNotificationsAction.h"
  51. #import "OCRichObjectStrings.h"
  52. #import "OCUserProfile.h"
  53. @interface OCCommunication ()
  54. @property (nonatomic, strong) NSString *currentServerVersion;
  55. @end
  56. @implementation OCCommunication
  57. -(id) init {
  58. self = [super init];
  59. if (self) {
  60. //Init the Donwload queue array
  61. self.downloadTaskNetworkQueueArray = [NSMutableArray new];
  62. //Credentials not set yet
  63. self.kindOfCredential = credentialNotSet;
  64. [self setSecurityPolicyManagers:[self createSecurityPolicy]];
  65. self.isCookiesAvailable = YES;
  66. self.isForbiddenCharactersAvailable = NO;
  67. #ifdef UNIT_TEST
  68. self.uploadSessionManager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
  69. self.downloadSessionManager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
  70. self.networkSessionManager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
  71. self.networkSessionManager.responseSerializer = [AFHTTPResponseSerializer serializer];
  72. #else
  73. //Network Upload queue for NSURLSession (iOS 7)
  74. NSURLSessionConfiguration *uploadConfiguration = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:k_session_name];
  75. uploadConfiguration.HTTPShouldUsePipelining = YES;
  76. uploadConfiguration.HTTPMaximumConnectionsPerHost = 1;
  77. uploadConfiguration.requestCachePolicy = NSURLRequestReloadIgnoringLocalCacheData;
  78. self.uploadSessionManager = [[AFURLSessionManager alloc] initWithSessionConfiguration:uploadConfiguration];
  79. [self.uploadSessionManager.operationQueue setMaxConcurrentOperationCount:1];
  80. //Network Download queue for NSURLSession (iOS 7)
  81. NSURLSessionConfiguration *downConfiguration = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:k_download_session_name];
  82. downConfiguration.HTTPShouldUsePipelining = YES;
  83. downConfiguration.HTTPMaximumConnectionsPerHost = 1;
  84. downConfiguration.requestCachePolicy = NSURLRequestReloadIgnoringLocalCacheData;
  85. self.downloadSessionManager = [[AFURLSessionManager alloc] initWithSessionConfiguration:downConfiguration];
  86. [self.downloadSessionManager.operationQueue setMaxConcurrentOperationCount:1];
  87. //Network Download queue for NSURLSession (iOS 7)
  88. NSURLSessionConfiguration *networkConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration];
  89. networkConfiguration.HTTPShouldUsePipelining = YES;
  90. networkConfiguration.HTTPMaximumConnectionsPerHost = 1;
  91. networkConfiguration.requestCachePolicy = NSURLRequestReloadIgnoringLocalCacheData;
  92. self.networkSessionManager = [[AFURLSessionManager alloc] initWithSessionConfiguration:networkConfiguration];
  93. [self.networkSessionManager.operationQueue setMaxConcurrentOperationCount:1];
  94. self.networkSessionManager.responseSerializer = [AFHTTPResponseSerializer serializer];
  95. #endif
  96. }
  97. return self;
  98. }
  99. -(id) initWithUploadSessionManager:(AFURLSessionManager *) uploadSessionManager {
  100. self = [super init];
  101. if (self) {
  102. //Init the Donwload queue array
  103. self.downloadTaskNetworkQueueArray = [NSMutableArray new];
  104. self.isCookiesAvailable = YES;
  105. self.isForbiddenCharactersAvailable = NO;
  106. //Credentials not set yet
  107. self.kindOfCredential = credentialNotSet;
  108. [self setSecurityPolicyManagers:[self createSecurityPolicy]];
  109. self.uploadSessionManager = uploadSessionManager;
  110. }
  111. return self;
  112. }
  113. -(id) initWithUploadSessionManager:(AFURLSessionManager *) uploadSessionManager andDownloadSessionManager:(AFURLSessionManager *) downloadSessionManager andNetworkSessionManager:(AFURLSessionManager *) networkSessionManager {
  114. self = [super init];
  115. if (self) {
  116. //Init the Donwload queue array
  117. self.downloadTaskNetworkQueueArray = [NSMutableArray new];
  118. //Credentials not set yet
  119. self.kindOfCredential = credentialNotSet;
  120. [self setSecurityPolicyManagers:[self createSecurityPolicy]];
  121. self.uploadSessionManager = uploadSessionManager;
  122. self.downloadSessionManager = downloadSessionManager;
  123. self.networkSessionManager = networkSessionManager;
  124. }
  125. return self;
  126. }
  127. - (AFSecurityPolicy *) createSecurityPolicy {
  128. return [AFSecurityPolicy defaultPolicy];
  129. }
  130. - (void)setSecurityPolicyManagers:(AFSecurityPolicy *)securityPolicy {
  131. self.securityPolicy = securityPolicy;
  132. self.uploadSessionManager.securityPolicy = securityPolicy;
  133. self.downloadSessionManager.securityPolicy = securityPolicy;
  134. }
  135. #pragma mark - Setting Credentials
  136. - (void) setCredentialsWithUser:(NSString*) user andUserID:(NSString *) userID andPassword:(NSString*) password {
  137. self.kindOfCredential = credentialNormal;
  138. self.user = user;
  139. self.userID = userID;
  140. self.password = password;
  141. }
  142. - (void) setCredentialsWithCookie:(NSString*) cookie {
  143. self.kindOfCredential = credentialCookie;
  144. self.password = cookie;
  145. }
  146. - (void) setCredentialsOauthWithToken:(NSString*) token {
  147. self.kindOfCredential = credentialOauth;
  148. self.password = token;
  149. }
  150. ///-----------------------------------
  151. /// @name getRequestWithCredentials
  152. ///-----------------------------------
  153. /**
  154. * Method to return the request with the right credential
  155. *
  156. * @param OCWebDAVClient like a dinamic typed
  157. *
  158. * @return OCWebDAVClient like a dinamic typed
  159. *
  160. */
  161. - (id) getRequestWithCredentials:(id) request {
  162. if ([request isKindOfClass:[NSMutableURLRequest class]]) {
  163. NSMutableURLRequest *myRequest = (NSMutableURLRequest *)request;
  164. switch (self.kindOfCredential) {
  165. case credentialNotSet:
  166. //Without credentials
  167. break;
  168. case credentialNormal:
  169. {
  170. NSString *basicAuthCredentials = [NSString stringWithFormat:@"%@:%@", self.user, self.password];
  171. [myRequest addValue:[NSString stringWithFormat:@"Basic %@", [UtilsFramework AFBase64EncodedStringFromString:basicAuthCredentials]] forHTTPHeaderField:@"Authorization"];
  172. break;
  173. }
  174. case credentialCookie:
  175. NSLog(@"Cookie: %@", self.password);
  176. [myRequest addValue:self.password forHTTPHeaderField:@"Cookie"];
  177. break;
  178. case credentialOauth:
  179. [myRequest addValue:[NSString stringWithFormat:@"Bearer %@", self.password] forHTTPHeaderField:@"Authorization"];
  180. break;
  181. default:
  182. break;
  183. }
  184. if (self.userAgent) {
  185. [myRequest addValue:self.userAgent forHTTPHeaderField:@"User-Agent"];
  186. }
  187. return myRequest;
  188. } else if([request isKindOfClass:[OCWebDAVClient class]]) {
  189. OCWebDAVClient *myRequest = (OCWebDAVClient *)request;
  190. switch (self.kindOfCredential) {
  191. case credentialNotSet:
  192. //Without credentials
  193. break;
  194. case credentialNormal:
  195. [myRequest setAuthorizationHeaderWithUsername:self.user password:self.password];
  196. break;
  197. case credentialCookie:
  198. [myRequest setAuthorizationHeaderWithCookie:self.password];
  199. break;
  200. case credentialOauth:
  201. [myRequest setAuthorizationHeaderWithToken:[NSString stringWithFormat:@"Bearer %@", self.password]];
  202. break;
  203. default:
  204. break;
  205. }
  206. if (self.userAgent) {
  207. [myRequest setUserAgent:self.userAgent];
  208. }
  209. return request;
  210. } else {
  211. NSLog(@"We do not know witch kind of object is");
  212. return request;
  213. }
  214. }
  215. #pragma mark - WebDav network Operations
  216. ///-----------------------------------
  217. /// @name Check Server
  218. ///-----------------------------------
  219. - (void) checkServer: (NSString *) path
  220. onCommunication:(OCCommunication *)sharedOCCommunication
  221. successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer)) successRequest
  222. failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
  223. OCWebDAVClient *request = [OCWebDAVClient new];
  224. request = [self getRequestWithCredentials:request];
  225. if (self.userAgent) {
  226. [request setUserAgent:self.userAgent];
  227. }
  228. path = [path encodeString:NSUTF8StringEncoding];
  229. [request checkServer:path onCommunication:sharedOCCommunication
  230. success:^(NSHTTPURLResponse *response, id responseObject) {
  231. if (successRequest) {
  232. successRequest(response, request.redirectedServer);
  233. }
  234. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  235. failureRequest(response, error, request.redirectedServer);
  236. }];
  237. }
  238. ///-----------------------------------
  239. /// @name Create a folder
  240. ///-----------------------------------
  241. - (void) createFolder: (NSString *) path
  242. onCommunication:(OCCommunication *)sharedOCCommunication withForbiddenCharactersSupported:(BOOL)isFCSupported
  243. successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer)) successRequest
  244. failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest
  245. errorBeforeRequest:(void(^)(NSError *error)) errorBeforeRequest {
  246. if ([UtilsFramework isForbiddenCharactersInFileName:[UtilsFramework getFileNameOrFolderByPath:path] withForbiddenCharactersSupported:isFCSupported]) {
  247. NSError *error = [UtilsFramework getErrorByCodeId:OCErrorForbidenCharacters];
  248. errorBeforeRequest(error);
  249. } else {
  250. OCWebDAVClient *request = [OCWebDAVClient new];
  251. request = [self getRequestWithCredentials:request];
  252. path = [path encodeString:NSUTF8StringEncoding];
  253. [request makeCollection:path onCommunication:sharedOCCommunication
  254. success:^(NSHTTPURLResponse *response, id responseObject) {
  255. if (successRequest) {
  256. successRequest(response, request.redirectedServer);
  257. }
  258. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  259. OCXMLServerErrorsParser *serverErrorParser = [OCXMLServerErrorsParser new];
  260. [serverErrorParser startToParseWithData:responseData withCompleteBlock:^(NSError *err) {
  261. if (err) {
  262. failureRequest(response, err, request.redirectedServer);
  263. }else{
  264. failureRequest(response, error, request.redirectedServer);
  265. }
  266. }];
  267. }];
  268. }
  269. }
  270. ///-----------------------------------
  271. /// @name Move a file or a folder
  272. ///-----------------------------------
  273. - (void) moveFileOrFolder:(NSString *)sourcePath
  274. toDestiny:(NSString *)destinyPath
  275. onCommunication:(OCCommunication *)sharedOCCommunication withForbiddenCharactersSupported:(BOOL)isFCSupported
  276. successRequest:(void (^)(NSHTTPURLResponse *response, NSString *redirectServer))successRequest
  277. failureRequest:(void (^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer))failureRequest
  278. errorBeforeRequest:(void (^)(NSError *error))errorBeforeRequest {
  279. if ([UtilsFramework isTheSameFileOrFolderByNewURLString:destinyPath andOriginURLString:sourcePath]) {
  280. //We check that we are not trying to move the file to the same place
  281. NSError *error = [UtilsFramework getErrorByCodeId:OCErrorMovingTheDestinyAndOriginAreTheSame];
  282. errorBeforeRequest(error);
  283. } else if ([UtilsFramework isAFolderUnderItByNewURLString:destinyPath andOriginURLString:sourcePath]) {
  284. //We check we are not trying to move a folder inside himself
  285. NSError *error = [UtilsFramework getErrorByCodeId:OCErrorMovingFolderInsideHimself];
  286. errorBeforeRequest(error);
  287. } else if ([UtilsFramework isForbiddenCharactersInFileName:[UtilsFramework getFileNameOrFolderByPath:destinyPath] withForbiddenCharactersSupported:isFCSupported]) {
  288. //We check that we are making a move not a rename to prevent special characters problems
  289. NSError *error = [UtilsFramework getErrorByCodeId:OCErrorMovingDestinyNameHaveForbiddenCharacters];
  290. errorBeforeRequest(error);
  291. } else {
  292. sourcePath = [sourcePath encodeString:NSUTF8StringEncoding];
  293. destinyPath = [destinyPath encodeString:NSUTF8StringEncoding];
  294. OCWebDAVClient *request = [OCWebDAVClient new];
  295. request = [self getRequestWithCredentials:request];
  296. [request movePath:sourcePath toPath:destinyPath onCommunication:sharedOCCommunication success:^(NSHTTPURLResponse *response, id responseObject) {
  297. if (successRequest) {
  298. successRequest(response, request.redirectedServer);
  299. }
  300. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  301. OCXMLServerErrorsParser *serverErrorParser = [OCXMLServerErrorsParser new];
  302. [serverErrorParser startToParseWithData:responseData withCompleteBlock:^(NSError *err) {
  303. if (err) {
  304. failureRequest(response, err, request.redirectedServer);
  305. }else{
  306. failureRequest(response, error, request.redirectedServer);
  307. }
  308. }];
  309. }];
  310. }
  311. }
  312. ///-----------------------------------
  313. /// @name Delete a file or a folder
  314. ///-----------------------------------
  315. - (void) deleteFileOrFolder:(NSString *)path
  316. onCommunication:(OCCommunication *)sharedOCCommunication
  317. successRequest:(void (^)(NSHTTPURLResponse *response, NSString *redirectedServer))successRequest
  318. failureRquest:(void (^)(NSHTTPURLResponse *resposne, NSError *error, NSString *redirectedServer))failureRequest {
  319. path = [path encodeString:NSUTF8StringEncoding];
  320. OCWebDAVClient *request = [OCWebDAVClient new];
  321. request = [self getRequestWithCredentials:request];
  322. [request deletePath:path onCommunication:sharedOCCommunication success:^(NSHTTPURLResponse *response, id responseObject) {
  323. if (successRequest) {
  324. successRequest(response, request.redirectedServer);
  325. }
  326. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  327. failureRequest(response, error, request.redirectedServer);
  328. }];
  329. }
  330. ///-----------------------------------
  331. /// @name Read folder
  332. ///-----------------------------------
  333. - (void) readFolder: (NSString *) path depth:(NSString *)depth withUserSessionToken:(NSString *)token
  334. onCommunication:(OCCommunication *)sharedOCCommunication
  335. successRequest:(void(^)(NSHTTPURLResponse *response, NSArray *items, NSString *redirectedServer, NSString *token)) successRequest
  336. failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *token, NSString *redirectedServer)) failureRequest{
  337. if (!token){
  338. token = @"no token";
  339. }
  340. path = [path encodeString:NSUTF8StringEncoding];
  341. OCWebDAVClient *request = [OCWebDAVClient new];
  342. request = [self getRequestWithCredentials:request];
  343. [request listPath:path depth:depth onCommunication:sharedOCCommunication withUserSessionToken:token success:^(NSHTTPURLResponse *response, id responseObject, NSString *token) {
  344. if (successRequest) {
  345. NSData *responseData = (NSData*) responseObject;
  346. // NSString* newStr = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
  347. // NSLog(@"newStrReadFolder: %@", newStr);
  348. OCXMLParser *parser = [[OCXMLParser alloc]init];
  349. [parser initParserWithData:responseData];
  350. NSMutableArray *directoryList = [parser.directoryList mutableCopy];
  351. //Return success
  352. successRequest(response, directoryList, request.redirectedServer, token);
  353. }
  354. } failure:^(NSHTTPURLResponse *response, id responseData, NSError *error, NSString *token) {
  355. NSLog(@"Failure");
  356. failureRequest(response, error, token, request.redirectedServer);
  357. }];
  358. }
  359. ///-----------------------------------
  360. /// @name Download File Session
  361. ///-----------------------------------
  362. - (NSURLSessionDownloadTask *) downloadFileSession:(NSString *)remotePath toDestiny:(NSString *)localPath defaultPriority:(BOOL)defaultPriority onCommunication:(OCCommunication *)sharedOCCommunication progress:(void(^)(NSProgress *progress))downloadProgress successRequest:(void(^)(NSURLResponse *response, NSURL *filePath)) successRequest failureRequest:(void(^)(NSURLResponse *response, NSError *error)) failureRequest {
  363. OCWebDAVClient *request = [OCWebDAVClient new];
  364. request = [self getRequestWithCredentials:request];
  365. remotePath = [remotePath encodeString:NSUTF8StringEncoding];
  366. NSURLSessionDownloadTask *downloadTask = [request downloadWithSessionPath:remotePath toPath:localPath defaultPriority:defaultPriority onCommunication:sharedOCCommunication progress:^(NSProgress *progress) {
  367. downloadProgress(progress);
  368. } success:^(NSURLResponse *response, NSURL *filePath) {
  369. [UtilsFramework addCookiesToStorageFromResponse:(NSURLResponse *) response andPath:[NSURL URLWithString:remotePath]];
  370. successRequest(response,filePath);
  371. } failure:^(NSURLResponse *response, NSError *error) {
  372. [UtilsFramework addCookiesToStorageFromResponse:(NSURLResponse *) response andPath:[NSURL URLWithString:remotePath]];
  373. failureRequest(response,error);
  374. }];
  375. return downloadTask;
  376. }
  377. ///-----------------------------------
  378. /// @name Set Download Task Complete Block
  379. ///-----------------------------------
  380. - (void)setDownloadTaskComleteBlock: (NSURL * (^)(NSURLSession *session, NSURLSessionDownloadTask *downloadTask, NSURL *location))block{
  381. [self.downloadSessionManager setDownloadTaskDidFinishDownloadingBlock:block];
  382. }
  383. ///-----------------------------------
  384. /// @name Set Download Task Did Get Body Data Block
  385. ///-----------------------------------
  386. - (void) setDownloadTaskDidGetBodyDataBlock: (void(^)(NSURLSession *session, NSURLSessionDownloadTask *downloadTask, int64_t bytesWritten, int64_t totalBytesWritten, int64_t totalBytesExpectedToWrite)) block{
  387. [self.downloadSessionManager setDownloadTaskDidWriteDataBlock:^(NSURLSession *session, NSURLSessionDownloadTask *downloadTask, int64_t bytesWritten, int64_t totalBytesWritten, int64_t totalBytesExpectedToWrite) {
  388. block(session,downloadTask,bytesWritten,totalBytesWritten,totalBytesExpectedToWrite);
  389. }];
  390. }
  391. ///-----------------------------------
  392. /// @name Upload File Session
  393. ///-----------------------------------
  394. - (NSURLSessionUploadTask *) uploadFileSession:(NSString *) localPath toDestiny:(NSString *) remotePath onCommunication:(OCCommunication *)sharedOCCommunication progress:(void(^)(NSProgress *progress))uploadProgress successRequest:(void(^)(NSURLResponse *response, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSURLResponse *response, NSString *redirectedServer, NSError *error)) failureRequest failureBeforeRequest:(void(^)(NSError *error)) failureBeforeRequest {
  395. OCWebDAVClient *request = [OCWebDAVClient new];
  396. request = [self getRequestWithCredentials:request];
  397. remotePath = [remotePath encodeString:NSUTF8StringEncoding];
  398. NSURLSessionUploadTask *uploadTask = [request putWithSessionLocalPath:localPath atRemotePath:remotePath onCommunication:sharedOCCommunication progress:^(NSProgress *progress) {
  399. uploadProgress(progress);
  400. } success:^(NSURLResponse *response, id responseObjec){
  401. [UtilsFramework addCookiesToStorageFromResponse:(NSURLResponse *) response andPath:[NSURL URLWithString:remotePath]];
  402. //TODO: The second parameter is the redirected server
  403. successRequest(response, @"");
  404. } failure:^(NSURLResponse *response, id responseObject, NSError *error) {
  405. [UtilsFramework addCookiesToStorageFromResponse:(NSURLResponse *) response andPath:[NSURL URLWithString:remotePath]];
  406. //TODO: The second parameter is the redirected server
  407. NSData *responseData = (NSData*) responseObject;
  408. OCXMLServerErrorsParser *serverErrorParser = [OCXMLServerErrorsParser new];
  409. [serverErrorParser startToParseWithData:responseData withCompleteBlock:^(NSError *err) {
  410. if (err) {
  411. failureRequest(response, @"", err);
  412. }else{
  413. failureRequest(response, @"", error);
  414. }
  415. }];
  416. } failureBeforeRequest:^(NSError *error) {
  417. failureBeforeRequest(error);
  418. }];
  419. return uploadTask;
  420. }
  421. ///-----------------------------------
  422. /// @name Set Task Did Complete Block
  423. ///-----------------------------------
  424. - (void) setTaskDidCompleteBlock: (void(^)(NSURLSession *session, NSURLSessionTask *task, NSError *error)) block{
  425. [self.uploadSessionManager setTaskDidCompleteBlock:^(NSURLSession *session, NSURLSessionTask *task, NSError *error) {
  426. block(session, task, error);
  427. }];
  428. }
  429. ///-----------------------------------
  430. /// @name Set Task Did Send Body Data Block
  431. ///-----------------------------------
  432. - (void) setTaskDidSendBodyDataBlock: (void(^)(NSURLSession *session, NSURLSessionTask *task, int64_t bytesSent, int64_t totalBytesSent, int64_t totalBytesExpectedToSend)) block{
  433. [self.uploadSessionManager setTaskDidSendBodyDataBlock:^(NSURLSession *session, NSURLSessionTask *task, int64_t bytesSent, int64_t totalBytesSent, int64_t totalBytesExpectedToSend) {
  434. block(session, task, bytesSent, totalBytesSent, totalBytesExpectedToSend);
  435. }];
  436. }
  437. ///-----------------------------------
  438. /// @name Read File
  439. ///-----------------------------------
  440. - (void) readFile: (NSString *) path
  441. onCommunication:(OCCommunication *)sharedOCCommunication
  442. successRequest:(void(^)(NSHTTPURLResponse *response, NSArray *items, NSString *redirectedServer)) successRequest
  443. failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
  444. path = [path encodeString:NSUTF8StringEncoding];
  445. OCWebDAVClient *request = [OCWebDAVClient new];
  446. request = [self getRequestWithCredentials:request];
  447. [request propertiesOfPath:path onCommunication:sharedOCCommunication success:^(NSHTTPURLResponse *response, id responseObject) {
  448. if (successRequest) {
  449. NSData *responseData = (NSData*) responseObject;
  450. // NSString* newStr = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
  451. // NSLog(@"newStrReadFile: %@", newStr);
  452. OCXMLParser *parser = [[OCXMLParser alloc]init];
  453. [parser initParserWithData:responseData];
  454. NSMutableArray *directoryList = [parser.directoryList mutableCopy];
  455. //Return success
  456. successRequest(response, directoryList, request.redirectedServer);
  457. }
  458. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  459. failureRequest(response, error, request.redirectedServer);
  460. }];
  461. }
  462. ///-----------------------------------
  463. /// @name search
  464. ///-----------------------------------
  465. - (void)search:(NSString *)path folder:(NSString *)folder fileName:(NSString *)fileName depth:(NSString *)depth dateLastModified:(NSString *)dateLastModified contentType:(NSArray *)contentType withUserSessionToken:(NSString *)token onCommunication:(OCCommunication *)sharedOCCommunication successRequest:(void(^)(NSHTTPURLResponse *response, NSArray *items, NSString *redirectedServer, NSString *token)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *token, NSString *redirectedServer)) failureRequest{
  466. if (!token){
  467. token = @"no token";
  468. }
  469. path = [path encodeString:NSUTF8StringEncoding];
  470. OCWebDAVClient *request = [OCWebDAVClient new];
  471. request = [self getRequestWithCredentials:request];
  472. [request search:path folder:folder fileName:fileName depth:depth dateLastModified:dateLastModified contentType:contentType user:_user userID:_userID onCommunication:sharedOCCommunication withUserSessionToken:token success:^(NSHTTPURLResponse *response, id responseObject, NSString *token) {
  473. if (successRequest) {
  474. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
  475. NSData *responseData = (NSData*) responseObject;
  476. OCXMLListParser *parser = [OCXMLListParser new];
  477. [parser initParserWithData:responseData];
  478. NSMutableArray *searchList = [parser.searchList mutableCopy];
  479. //Return success
  480. dispatch_async(dispatch_get_main_queue(), ^{
  481. successRequest(response, searchList, request.redirectedServer, token);
  482. });
  483. });
  484. }
  485. } failure:^(NSHTTPURLResponse *response, id responseData, NSError *error, NSString *token) {
  486. failureRequest(response, error, token, request.redirectedServer);
  487. }];
  488. }
  489. ///-----------------------------------
  490. /// @name Setting favorite
  491. ///-----------------------------------
  492. - (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 {
  493. if (!token){
  494. token = @"no token";
  495. }
  496. path = [NSString stringWithFormat:@"%@/files/%@/%@", path, _userID, filePath];
  497. path = [path encodeString:NSUTF8StringEncoding];
  498. OCWebDAVClient *request = [OCWebDAVClient new];
  499. request = [self getRequestWithCredentials:request];
  500. [request settingFavorite:path favorite:favorite onCommunication:sharedOCCommunication withUserSessionToken:token success:^(NSHTTPURLResponse *response, id responseObject, NSString *token) {
  501. if (successRequest) {
  502. //Return success
  503. successRequest(response, request.redirectedServer, token);
  504. }
  505. } failure:^(NSHTTPURLResponse *response, id responseData, NSError *error, NSString *token) {
  506. NSLog(@"Failure");
  507. failureRequest(response, error, token, request.redirectedServer);
  508. }];
  509. }
  510. ///-----------------------------------
  511. /// @name Listing favorites
  512. ///-----------------------------------
  513. - (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{
  514. if (!token){
  515. token = @"no token";
  516. }
  517. path = [path encodeString:NSUTF8StringEncoding];
  518. OCWebDAVClient *request = [OCWebDAVClient new];
  519. request = [self getRequestWithCredentials:request];
  520. [request listingFavorites:path folder:folder user:_user userID:_userID onCommunication:sharedOCCommunication withUserSessionToken:token success:^(NSHTTPURLResponse *response, id responseObject, NSString *token) {
  521. if (successRequest) {
  522. NSData *responseData = (NSData*) responseObject;
  523. OCXMLListParser *parser = [OCXMLListParser new];
  524. [parser initParserWithData:responseData];
  525. NSMutableArray *searchList = [parser.searchList mutableCopy];
  526. //Return success
  527. successRequest(response, searchList, request.redirectedServer, token);
  528. }
  529. } failure:^(NSHTTPURLResponse *response, id responseData, NSError *error, NSString *token) {
  530. failureRequest(response, error, token, request.redirectedServer);
  531. }];
  532. }
  533. #pragma mark - OC/NC API Calls
  534. - (NSString *) getCurrentServerVersion {
  535. return self.currentServerVersion;
  536. }
  537. - (void) getServerVersionWithPath:(NSString*) path onCommunication:(OCCommunication *)sharedOCCommunication
  538. successRequest:(void(^)(NSHTTPURLResponse *response, NSString *serverVersion, NSString *redirectedServer)) success
  539. failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failure{
  540. OCWebDAVClient *request = [OCWebDAVClient new];
  541. if (self.userAgent) {
  542. [request setUserAgent:self.userAgent];
  543. }
  544. [request getStatusOfTheServer:path onCommunication:sharedOCCommunication success:^(NSHTTPURLResponse *response, id responseObject) {
  545. NSData *data = (NSData*) responseObject;
  546. NSString *versionString = [NSString new];
  547. NSError* error=nil;
  548. if (data) {
  549. NSMutableDictionary *jsonArray = [NSJSONSerialization JSONObjectWithData: data options: NSJSONReadingMutableContainers error: &error];
  550. if(error) {
  551. NSLog(@"Error parsing JSON: %@", error);
  552. } else {
  553. //Obtain the server version from the version field
  554. versionString = [jsonArray valueForKey:@"version"];
  555. self.currentServerVersion = versionString;
  556. }
  557. } else {
  558. NSLog(@"Error parsing JSON: data is null");
  559. }
  560. success(response, versionString, request.redirectedServer);
  561. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  562. failure(response, error, request.redirectedServer);
  563. }];
  564. }
  565. ///-----------------------------------
  566. /// @name Get UserName by cookie
  567. ///-----------------------------------
  568. - (void) getUserNameByCookie:(NSString *) cookieString ofServerPath:(NSString *)path onCommunication:
  569. (OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *response, NSData *responseData, NSString *redirectedServer))success
  570. failure:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer))failure{
  571. OCWebDAVClient *request = [OCWebDAVClient new];
  572. request = [self getRequestWithCredentials:request];
  573. [request requestUserNameOfServer: path byCookie:cookieString onCommunication:sharedOCCommunication success:^(NSHTTPURLResponse *response, id responseObject) {
  574. success(response, responseObject, request.redirectedServer);
  575. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  576. failure(response, error, request.redirectedServer);
  577. }];
  578. }
  579. - (void) getFeaturesSupportedByServer:(NSString*) path onCommunication:(OCCommunication *)sharedOCCommunication
  580. successRequest:(void(^)(NSHTTPURLResponse *response, BOOL hasShareSupport, BOOL hasShareeSupport, BOOL hasCookiesSupport, BOOL hasForbiddenCharactersSupport, BOOL hasCapabilitiesSupport, BOOL hasFedSharesOptionShareSupport, NSString *redirectedServer)) success
  581. failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failure{
  582. OCWebDAVClient *request = [OCWebDAVClient new];
  583. if (self.userAgent) {
  584. [request setUserAgent:self.userAgent];
  585. }
  586. [request getStatusOfTheServer:path onCommunication:sharedOCCommunication success:^(NSHTTPURLResponse *response, id responseObject) {
  587. if (responseObject) {
  588. NSError* error = nil;
  589. NSMutableDictionary *jsonArray = [NSJSONSerialization JSONObjectWithData: (NSData*) responseObject options: NSJSONReadingMutableContainers error: &error];
  590. if(error) {
  591. // NSLog(@"Error parsing JSON: %@", error);
  592. failure(response, error, request.redirectedServer);
  593. }else{
  594. self.currentServerVersion = [jsonArray valueForKey:@"version"];
  595. BOOL hasShareSupport = [UtilsFramework isServerVersion:self.currentServerVersion higherThanLimitVersion:k_version_support_shared];
  596. BOOL hasShareeSupport = [UtilsFramework isServerVersion:self.currentServerVersion higherThanLimitVersion:k_version_support_sharee_api];
  597. BOOL hasCookiesSupport = [UtilsFramework isServerVersion:self.currentServerVersion higherThanLimitVersion:k_version_support_cookies];
  598. BOOL hasForbiddenCharactersSupport = [UtilsFramework isServerVersion:self.currentServerVersion higherThanLimitVersion:k_version_support_forbidden_characters];
  599. BOOL hasCapabilitiesSupport = [UtilsFramework isServerVersion:self.currentServerVersion higherThanLimitVersion:k_version_support_capabilities];
  600. BOOL hasFedSharesOptionShareSupport = [UtilsFramework isServerVersion:self.currentServerVersion higherThanLimitVersion:k_version_support_share_option_fed_share];
  601. success(response, hasShareSupport, hasShareeSupport, hasCookiesSupport, hasForbiddenCharactersSupport, hasCapabilitiesSupport, hasFedSharesOptionShareSupport, request.redirectedServer);
  602. }
  603. } else {
  604. // NSLog(@"Error parsing JSON: data is null");
  605. failure(response, nil, request.redirectedServer);
  606. }
  607. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  608. failure(response, error, request.redirectedServer);
  609. }];
  610. }
  611. #pragma mark - Share
  612. - (void) readSharedByServer: (NSString *) path
  613. onCommunication:(OCCommunication *)sharedOCCommunication
  614. successRequest:(void(^)(NSHTTPURLResponse *response, NSArray *listOfShared, NSString *redirectedServer)) successRequest
  615. failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
  616. path = [path encodeString:NSUTF8StringEncoding];
  617. path = [path stringByAppendingString:k_url_acces_shared_api];
  618. OCWebDAVClient *request = [OCWebDAVClient new];
  619. request = [self getRequestWithCredentials:request];
  620. [request listSharedByServer:path onCommunication:sharedOCCommunication success:^(NSHTTPURLResponse *response, id responseObject) {
  621. if (successRequest) {
  622. NSData *responseData = (NSData*) responseObject;
  623. OCXMLSharedParser *parser = [[OCXMLSharedParser alloc]init];
  624. //NSLog(@"response: %@", [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]);
  625. [parser initParserWithData:responseData];
  626. NSMutableArray *sharedList = [parser.shareList mutableCopy];
  627. //Return success
  628. successRequest(response, sharedList, request.redirectedServer);
  629. }
  630. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  631. failureRequest(response, error, request.redirectedServer);
  632. }];
  633. }
  634. - (void) readSharedByServer: (NSString *) serverPath andPath: (NSString *) path
  635. onCommunication:(OCCommunication *)sharedOCCommunication
  636. successRequest:(void(^)(NSHTTPURLResponse *response, NSArray *listOfShared, NSString *redirectedServer)) successRequest
  637. failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
  638. serverPath = [serverPath encodeString:NSUTF8StringEncoding];
  639. serverPath = [serverPath stringByAppendingString:k_url_acces_shared_api];
  640. path = [path encodeString:NSUTF8StringEncoding];
  641. OCWebDAVClient *request = [OCWebDAVClient new];
  642. request = [self getRequestWithCredentials:request];
  643. [request listSharedByServer:serverPath andPath:path onCommunication:sharedOCCommunication success:^(NSHTTPURLResponse *response, id responseObject) {
  644. if (successRequest) {
  645. NSData *responseData = (NSData*) responseObject;
  646. OCXMLSharedParser *parser = [[OCXMLSharedParser alloc]init];
  647. // NSString *str = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
  648. // NSLog(@"responseDataReadSharedByServer:andPath: %@", str);
  649. // NSLog(@"pathFolders: %@", path);
  650. // NSLog(@"serverPath: %@", serverPath);
  651. [parser initParserWithData:responseData];
  652. NSMutableArray *sharedList = [parser.shareList mutableCopy];
  653. //Return success
  654. successRequest(response, sharedList, request.redirectedServer);
  655. }
  656. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  657. failureRequest(response, error, request.redirectedServer);
  658. }];
  659. }
  660. - (void) shareFileOrFolderByServer: (NSString *) serverPath andFileOrFolderPath: (NSString *) filePath andPassword:(NSString *)password
  661. onCommunication:(OCCommunication *)sharedOCCommunication
  662. successRequest:(void(^)(NSHTTPURLResponse *response, NSString *token, NSString *redirectedServer)) successRequest
  663. failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
  664. serverPath = [serverPath encodeString:NSUTF8StringEncoding];
  665. serverPath = [serverPath stringByAppendingString:k_url_acces_shared_api];
  666. OCWebDAVClient *request = [OCWebDAVClient new];
  667. request = [self getRequestWithCredentials:request];
  668. [request shareByLinkFileOrFolderByServer:serverPath andPath:filePath andPassword:password onCommunication:sharedOCCommunication success:^(NSHTTPURLResponse *response, id responseObject) {
  669. NSData *responseData = (NSData*) responseObject;
  670. OCXMLShareByLinkParser *parser = [[OCXMLShareByLinkParser alloc]init];
  671. // NSLog(@"response: %@", [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding]);
  672. [parser initParserWithData:responseData];
  673. switch (parser.statusCode) {
  674. case kOCSharedAPISuccessful:
  675. {
  676. NSString *url = parser.url;
  677. NSString *token = parser.token;
  678. if (url != nil) {
  679. successRequest(response, url, request.redirectedServer);
  680. }else if (token != nil){
  681. //We remove the \n and the empty spaces " "
  682. token = [token stringByReplacingOccurrencesOfString:@"\n" withString:@""];
  683. token = [token stringByReplacingOccurrencesOfString:@" " withString:@""];
  684. successRequest(response, token, request.redirectedServer);
  685. }else{
  686. NSError *error = [UtilsFramework getErrorWithCode:parser.statusCode andCustomMessageFromTheServer:parser.message];
  687. failureRequest(response, error, request.redirectedServer);
  688. }
  689. break;
  690. }
  691. default:
  692. {
  693. NSError *error = [UtilsFramework getErrorWithCode:parser.statusCode andCustomMessageFromTheServer:parser.message];
  694. failureRequest(response, error, request.redirectedServer);
  695. }
  696. }
  697. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  698. failureRequest(response, error, request.redirectedServer);
  699. }];
  700. }
  701. - (void) shareFileOrFolderByServer: (NSString *) serverPath andFileOrFolderPath: (NSString *) filePath
  702. onCommunication:(OCCommunication *)sharedOCCommunication
  703. successRequest:(void(^)(NSHTTPURLResponse *response, NSString *shareLink, NSString *redirectedServer)) successRequest
  704. failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
  705. serverPath = [serverPath encodeString:NSUTF8StringEncoding];
  706. serverPath = [serverPath stringByAppendingString:k_url_acces_shared_api];
  707. OCWebDAVClient *request = [OCWebDAVClient new];
  708. request = [self getRequestWithCredentials:request];
  709. [request shareByLinkFileOrFolderByServer:serverPath andPath:filePath onCommunication:sharedOCCommunication success:^(NSHTTPURLResponse *response, id responseObject) {
  710. NSData *responseData = (NSData*) responseObject;
  711. OCXMLShareByLinkParser *parser = [[OCXMLShareByLinkParser alloc]init];
  712. // NSLog(@"response: %@", [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding]);
  713. [parser initParserWithData:responseData];
  714. switch (parser.statusCode) {
  715. case kOCSharedAPISuccessful:
  716. {
  717. NSString *url = parser.url;
  718. NSString *token = parser.token;
  719. if (url != nil) {
  720. successRequest(response, url, request.redirectedServer);
  721. }else if (token != nil){
  722. //We remove the \n and the empty spaces " "
  723. token = [token stringByReplacingOccurrencesOfString:@"\n" withString:@""];
  724. token = [token stringByReplacingOccurrencesOfString:@" " withString:@""];
  725. successRequest(response, token, request.redirectedServer);
  726. }else{
  727. NSError *error = [UtilsFramework getErrorWithCode:parser.statusCode andCustomMessageFromTheServer:parser.message];
  728. failureRequest(response, error, request.redirectedServer);
  729. }
  730. break;
  731. }
  732. default:
  733. {
  734. NSError *error = [UtilsFramework getErrorWithCode:parser.statusCode andCustomMessageFromTheServer:parser.message];
  735. failureRequest(response, error, request.redirectedServer);
  736. }
  737. }
  738. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  739. failureRequest(response, error, request.redirectedServer);
  740. }];
  741. }
  742. - (void)shareWith:(NSString *)userOrGroup shareeType:(NSInteger)shareeType inServer:(NSString *) serverPath andFileOrFolderPath:(NSString *) filePath andPermissions:(NSInteger) permissions onCommunication:(OCCommunication *)sharedOCCommunication
  743. successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer))successRequest
  744. failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer))failureRequest{
  745. serverPath = [serverPath encodeString:NSUTF8StringEncoding];
  746. serverPath = [serverPath stringByAppendingString:k_url_acces_shared_api];
  747. userOrGroup = [userOrGroup encodeString:NSUTF8StringEncoding];
  748. OCWebDAVClient *request = [OCWebDAVClient new];
  749. request = [self getRequestWithCredentials:request];
  750. [request shareWith:userOrGroup shareeType:shareeType inServer:serverPath andPath:filePath andPermissions:permissions onCommunication:sharedOCCommunication success:^(NSHTTPURLResponse *response, id responseObject) {
  751. NSData *responseData = (NSData*) responseObject;
  752. OCXMLShareByLinkParser *parser = [[OCXMLShareByLinkParser alloc]init];
  753. // NSLog(@"response: %@", [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding]);
  754. [parser initParserWithData:responseData];
  755. switch (parser.statusCode) {
  756. case kOCSharedAPISuccessful:
  757. {
  758. successRequest(response, request.redirectedServer);
  759. break;
  760. }
  761. default:
  762. {
  763. NSError *error = [UtilsFramework getErrorWithCode:parser.statusCode andCustomMessageFromTheServer:parser.message];
  764. failureRequest(response, error, request.redirectedServer);
  765. }
  766. }
  767. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  768. failureRequest(response, error, request.redirectedServer);
  769. }];
  770. }
  771. - (void) unShareFileOrFolderByServer: (NSString *) path andIdRemoteShared: (NSInteger) idRemoteShared
  772. onCommunication:(OCCommunication *)sharedOCCommunication
  773. successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer)) successRequest
  774. failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest{
  775. path = [path encodeString:NSUTF8StringEncoding];
  776. path = [path stringByAppendingString:k_url_acces_shared_api];
  777. path = [path stringByAppendingString:[NSString stringWithFormat:@"/%ld",(long)idRemoteShared]];
  778. OCWebDAVClient *request = [OCWebDAVClient new];
  779. request = [self getRequestWithCredentials:request];
  780. [request unShareFileOrFolderByServer:path onCommunication:sharedOCCommunication success:^(NSHTTPURLResponse *response, id responseObject) {
  781. if (successRequest) {
  782. //Return success
  783. successRequest(response, request.redirectedServer);
  784. }
  785. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  786. failureRequest(response, error, request.redirectedServer);
  787. }];
  788. }
  789. - (void) isShareFileOrFolderByServer: (NSString *) path andIdRemoteShared: (NSInteger) idRemoteShared
  790. onCommunication:(OCCommunication *)sharedOCCommunication
  791. successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer, BOOL isShared, id shareDto)) successRequest
  792. failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
  793. path = [path encodeString:NSUTF8StringEncoding];
  794. path = [path stringByAppendingString:k_url_acces_shared_api];
  795. path = [path stringByAppendingString:[NSString stringWithFormat:@"/%ld",(long)idRemoteShared]];
  796. OCWebDAVClient *request = [OCWebDAVClient new];
  797. request = [self getRequestWithCredentials:request];
  798. [request isShareFileOrFolderByServer:path onCommunication:sharedOCCommunication success:^(NSHTTPURLResponse *response, id responseObject) {
  799. if (successRequest) {
  800. NSData *responseData = (NSData*) responseObject;
  801. OCXMLSharedParser *parser = [[OCXMLSharedParser alloc]init];
  802. // NSLog(@"response: %@", [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding]);
  803. [parser initParserWithData:responseData];
  804. BOOL isShared = NO;
  805. OCSharedDto *shareDto = nil;
  806. if (parser.shareList) {
  807. NSMutableArray *sharedList = [parser.shareList mutableCopy];
  808. if ([sharedList count] > 0) {
  809. isShared = YES;
  810. shareDto = [sharedList objectAtIndex:0];
  811. }
  812. }
  813. //Return success
  814. successRequest(response, request.redirectedServer, isShared, shareDto);
  815. }
  816. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  817. failureRequest(response, error, request.redirectedServer);
  818. }];
  819. }
  820. - (void) updateShare:(NSInteger)shareId ofServerPath:(NSString *)serverPath withPasswordProtect:(NSString*)password andExpirationTime:(NSString*)expirationTime andPermissions:(NSInteger)permissions
  821. onCommunication:(OCCommunication *)sharedOCCommunication
  822. successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer)) successRequest
  823. failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest{
  824. serverPath = [serverPath encodeString:NSUTF8StringEncoding];
  825. serverPath = [serverPath stringByAppendingString:k_url_acces_shared_api];
  826. serverPath = [serverPath stringByAppendingString:[NSString stringWithFormat:@"/%ld",(long)shareId]];
  827. OCWebDAVClient *request = [OCWebDAVClient new];
  828. request = [self getRequestWithCredentials:request];
  829. [request updateShareItem:shareId ofServerPath:serverPath withPasswordProtect:password andExpirationTime:expirationTime andPermissions:permissions onCommunication:sharedOCCommunication success:^(NSHTTPURLResponse *response, id responseObject) {
  830. NSData *responseData = (NSData*) responseObject;
  831. OCXMLShareByLinkParser *parser = [[OCXMLShareByLinkParser alloc]init];
  832. // NSLog(@"response: %@", [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding]);
  833. [parser initParserWithData:responseData];
  834. switch (parser.statusCode) {
  835. case kOCSharedAPISuccessful:
  836. {
  837. successRequest(response, request.redirectedServer);
  838. break;
  839. }
  840. default:
  841. {
  842. NSError *error = [UtilsFramework getErrorWithCode:parser.statusCode andCustomMessageFromTheServer:parser.message];
  843. failureRequest(response, error, request.redirectedServer);
  844. }
  845. }
  846. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  847. failureRequest(response, error, request.redirectedServer);
  848. }];
  849. }
  850. - (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{
  851. serverPath = [serverPath encodeString:NSUTF8StringEncoding];
  852. serverPath = [serverPath stringByAppendingString:k_url_access_sharee_api];
  853. searchString = [searchString encodeString:NSUTF8StringEncoding];
  854. OCWebDAVClient *request = [OCWebDAVClient new];
  855. request = [self getRequestWithCredentials:request];
  856. [request searchUsersAndGroupsWith:searchString forPage:page with:resultsPerPage ofServer:serverPath onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
  857. NSData *responseData = (NSData*) responseObject;
  858. NSMutableArray *itemList = [NSMutableArray new];
  859. //Parse
  860. NSError *error;
  861. NSDictionary *jsongParsed = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
  862. if (error == nil) {
  863. NSDictionary *ocsDict = [jsongParsed valueForKey:@"ocs"];
  864. NSDictionary *metaDict = [ocsDict valueForKey:@"meta"];
  865. NSInteger statusCode = [[metaDict valueForKey:@"statuscode"] integerValue];
  866. if (statusCode == kOCShareeAPISuccessful || statusCode == kOCSharedAPISuccessful) {
  867. NSDictionary *dataDict = [ocsDict valueForKey:@"data"];
  868. NSArray *exactDict = [dataDict valueForKey:@"exact"];
  869. NSArray *usersFounded = [dataDict valueForKey:@"users"];
  870. NSArray *groupsFounded = [dataDict valueForKey:@"groups"];
  871. NSArray *usersRemote = [dataDict valueForKey:@"remotes"];
  872. NSArray *usersExact = [exactDict valueForKey:@"users"];
  873. NSArray *groupsExact = [exactDict valueForKey:@"groups"];
  874. NSArray *remotesExact = [exactDict valueForKey:@"remotes"];
  875. [self addUserItemOfType:shareTypeUser fromArray:usersFounded ToList:itemList];
  876. [self addUserItemOfType:shareTypeUser fromArray:usersExact ToList:itemList];
  877. [self addUserItemOfType:shareTypeRemote fromArray:usersRemote ToList:itemList];
  878. [self addUserItemOfType:shareTypeRemote fromArray:remotesExact ToList:itemList];
  879. [self addGroupItemFromArray:groupsFounded ToList:itemList];
  880. [self addGroupItemFromArray:groupsExact ToList:itemList];
  881. }else{
  882. NSString *message = (NSString*)[metaDict objectForKey:@"message"];
  883. if ([message isKindOfClass:[NSNull class]]) {
  884. message = @"";
  885. }
  886. NSError *error = [UtilsFramework getErrorWithCode:statusCode andCustomMessageFromTheServer:message];
  887. failureRequest(response, error, request.redirectedServer);
  888. }
  889. //Return success
  890. successRequest(response, itemList, request.redirectedServer);
  891. }
  892. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  893. failureRequest(response, error, request.redirectedServer);
  894. }];
  895. }
  896. - (void)getSharePermissionsFile:(NSString *)fileName onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *permissions, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest{
  897. fileName = [fileName encodeString:NSUTF8StringEncoding];
  898. OCWebDAVClient *request = [OCWebDAVClient new];
  899. request = [self getRequestWithCredentials:request];
  900. [request getSharePermissionsFile:fileName onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
  901. if (successRequest) {
  902. NSString *permissions;
  903. NSData *responseData = (NSData *)responseObject;
  904. NSString *newStr = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
  905. NSLog(@"newStrReadFolder: %@", newStr);
  906. OCXMLParser *parser = [[OCXMLParser alloc]init];
  907. [parser initParserWithData:responseData];
  908. NSMutableArray *directoryList = [parser.directoryList mutableCopy];
  909. if ([directoryList count] == 1) {
  910. OCFileDto *file = [directoryList objectAtIndex:0];
  911. permissions = file.permissions;
  912. }
  913. //Return success
  914. successRequest(response, permissions, request.redirectedServer);
  915. }
  916. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  917. failureRequest(response, error, request.redirectedServer);
  918. }];
  919. }
  920. #pragma mark - Capabilities
  921. - (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{
  922. serverPath = [serverPath encodeString:NSUTF8StringEncoding];
  923. serverPath = [serverPath stringByAppendingString:k_url_capabilities];
  924. OCWebDAVClient *request = [OCWebDAVClient new];
  925. request = [self getRequestWithCredentials:request];
  926. [request getCapabilitiesOfServer:serverPath onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
  927. NSData *responseData = (NSData*) responseObject;
  928. OCCapabilities *capabilities = [OCCapabilities new];
  929. //Parse
  930. NSError *error;
  931. NSDictionary *jsongParsed = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
  932. NSLog(@"dic: %@",jsongParsed);
  933. if (jsongParsed && jsongParsed.allKeys > 0) {
  934. NSDictionary *ocs = [jsongParsed valueForKey:@"ocs"];
  935. NSDictionary *data = [ocs valueForKey:@"data"];
  936. NSDictionary *version = [data valueForKey:@"version"];
  937. if (ocs.count > 0 && data.count > 0 && version.count > 0) {
  938. //VERSION
  939. NSNumber *versionMajorNumber = (NSNumber*) [version valueForKey:@"major"];
  940. NSNumber *versionMinorNumber = (NSNumber*) [version valueForKey:@"minor"];
  941. NSNumber *versionMicroNumber = (NSNumber*) [version valueForKey:@"micro"];
  942. capabilities.versionMajor = versionMajorNumber.integerValue;
  943. capabilities.versionMinor = versionMinorNumber.integerValue;
  944. capabilities.versionMicro = versionMicroNumber.integerValue;
  945. capabilities.versionString = (NSString*)[version valueForKey:@"string"];
  946. capabilities.versionEdition = (NSString*)[version valueForKey:@"edition"];
  947. NSDictionary *capabilitiesDict = [data valueForKey:@"capabilities"];
  948. NSDictionary *core = [capabilitiesDict valueForKey:@"core"];
  949. //CORE
  950. NSNumber *corePollIntervalNumber = (NSNumber*)[core valueForKey:@"pollinterval"];
  951. capabilities.corePollInterval = corePollIntervalNumber.integerValue;
  952. NSDictionary *fileSharing = [capabilitiesDict valueForKey:@"files_sharing"];
  953. //FILE SHARING
  954. NSNumber *fileSharingAPIEnabledNumber = (NSNumber*)[fileSharing valueForKey:@"api_enabled"];
  955. NSNumber *filesSharingReSharingEnabledNumber = (NSNumber*)[fileSharing valueForKey:@"resharing"];
  956. capabilities.isFilesSharingAPIEnabled = fileSharingAPIEnabledNumber.boolValue;
  957. capabilities.isFilesSharingReSharingEnabled = filesSharingReSharingEnabledNumber.boolValue;
  958. NSDictionary *fileSharingPublic = [fileSharing valueForKey:@"public"];
  959. NSNumber *filesSharingShareLinkEnabledNumber = (NSNumber*)[fileSharingPublic valueForKey:@"enabled"];
  960. NSNumber *filesSharingAllowPublicUploadsEnabledNumber = (NSNumber*)[fileSharingPublic valueForKey:@"upload"];
  961. NSNumber *filesSharingAllowUserSendMailNotificationAboutShareLinkEnabledNumber = (NSNumber*)[fileSharingPublic valueForKey:@"send_mail"];
  962. capabilities.isFilesSharingShareLinkEnabled = filesSharingShareLinkEnabledNumber.boolValue;
  963. capabilities.isFilesSharingAllowPublicUploadsEnabled = filesSharingAllowPublicUploadsEnabledNumber.boolValue;
  964. capabilities.isFilesSharingAllowUserSendMailNotificationAboutShareLinkEnabled = filesSharingAllowUserSendMailNotificationAboutShareLinkEnabledNumber.boolValue;
  965. NSDictionary *fileSharingPublicExpireDate = [fileSharingPublic valueForKey:@"expire_date"];
  966. NSNumber *filesSharingExpireDateByDefaultEnabledNumber = (NSNumber*)[fileSharingPublicExpireDate valueForKey:@"enabled"];
  967. NSNumber *filesSharingExpireDateEnforceEnabledNumber = (NSNumber*)[fileSharingPublicExpireDate valueForKey:@"enforced"];
  968. NSNumber *filesSharingExpireDateDaysNumber = (NSNumber*)[fileSharingPublicExpireDate valueForKey:@"days"];
  969. capabilities.isFilesSharingExpireDateByDefaultEnabled = filesSharingExpireDateByDefaultEnabledNumber.boolValue;
  970. capabilities.isFilesSharingExpireDateEnforceEnabled = filesSharingExpireDateEnforceEnabledNumber.boolValue;
  971. capabilities.filesSharingExpireDateDaysNumber = filesSharingExpireDateDaysNumber.integerValue;
  972. NSDictionary *fileSharingPublicPassword = [fileSharingPublic valueForKey:@"password"];
  973. NSNumber *filesSharingPasswordEnforcedEnabledNumber = (NSNumber*)[fileSharingPublicPassword valueForKey:@"enforced"];
  974. capabilities.isFilesSharingPasswordEnforcedEnabled = filesSharingPasswordEnforcedEnabledNumber.boolValue;;
  975. NSDictionary *fileSharingUser = [fileSharing valueForKey:@"user"];
  976. NSNumber *filesSharingAllowUserSendMailNotificationAboutOtherUsersEnabledNumber = (NSNumber*)[fileSharingUser valueForKey:@"send_mail"];
  977. capabilities.isFilesSharingAllowUserSendMailNotificationAboutOtherUsersEnabled = filesSharingAllowUserSendMailNotificationAboutOtherUsersEnabledNumber.boolValue;
  978. //FEDERATION
  979. NSDictionary *fileSharingFederation = [fileSharing valueForKey:@"federation"];
  980. NSNumber *filesSharingAllowUserSendSharesToOtherServersEnabledNumber = (NSNumber*)[fileSharingFederation valueForKey:@"outgoing"];
  981. NSNumber *filesSharingAllowUserReceiveSharesToOtherServersEnabledNumber = (NSNumber*)[fileSharingFederation valueForKey:@"incoming"];
  982. capabilities.isFilesSharingAllowUserSendSharesToOtherServersEnabled = filesSharingAllowUserSendSharesToOtherServersEnabledNumber.boolValue;
  983. capabilities.isFilesSharingAllowUserReceiveSharesToOtherServersEnabled = filesSharingAllowUserReceiveSharesToOtherServersEnabledNumber.boolValue;
  984. // EXTERNAL SITES
  985. NSDictionary *externalSitesDic = [capabilitiesDict valueForKey:@"external"];
  986. if (externalSitesDic) {
  987. capabilities.isExternalSitesServerEnabled = YES;
  988. NSArray *externalSitesArray = [externalSitesDic valueForKey:@"v1"];
  989. capabilities.externalSiteV1 = [externalSitesArray componentsJoinedByString:@","];
  990. }
  991. // NOTIFICATION
  992. NSDictionary *notificationDic = [capabilitiesDict valueForKey:@"notifications"];
  993. if (notificationDic) {
  994. capabilities.isNotificationServerEnabled = YES;
  995. NSArray *ocsendpointsArray = [notificationDic valueForKey:@"ocs-endpoints"];
  996. capabilities.notificationOcsEndpoints = [ocsendpointsArray componentsJoinedByString:@","];
  997. NSArray *pushArray = [notificationDic valueForKey:@"push"];
  998. capabilities.notificationPush = [pushArray componentsJoinedByString:@","];
  999. }
  1000. // SPREED
  1001. NSDictionary *spreedDic = [capabilitiesDict valueForKey:@"spreed"];
  1002. if (spreedDic) {
  1003. capabilities.isSpreedServerEnabled = YES;
  1004. NSArray *featuresArray = [capabilitiesDict valueForKey:@"features"];
  1005. capabilities.spreedFeatures = [featuresArray componentsJoinedByString:@","];
  1006. }
  1007. //FILES
  1008. NSDictionary *files = [capabilitiesDict valueForKey:@"files"];
  1009. NSNumber *fileBigFileChunkingEnabledNumber = (NSNumber*)[files valueForKey:@"bigfilechunking"];
  1010. NSNumber *fileUndeleteEnabledNumber = (NSNumber*)[files valueForKey:@"undelete"];
  1011. NSNumber *fileVersioningEnabledNumber = (NSNumber*)[files valueForKey:@"versioning"];
  1012. capabilities.isFileBigFileChunkingEnabled = fileBigFileChunkingEnabledNumber.boolValue;
  1013. capabilities.isFileUndeleteEnabled = fileUndeleteEnabledNumber.boolValue;
  1014. capabilities.isFileVersioningEnabled = fileVersioningEnabledNumber.boolValue;
  1015. //THEMING
  1016. NSDictionary *theming = [capabilitiesDict valueForKey:@"theming"];
  1017. if ([theming count] > 0) {
  1018. if ([theming valueForKey:@"background"] && ![[theming valueForKey:@"background"] isEqual:[NSNull null]])
  1019. capabilities.themingBackground = [theming valueForKey:@"background"];
  1020. if ([theming valueForKey:@"background-default"] && ![[theming valueForKey:@"background-default"] isEqual:[NSNull null]]) {
  1021. NSNumber *result = (NSNumber*)[theming valueForKey:@"background-default"];
  1022. capabilities.themingBackgroundDefault = result.boolValue;
  1023. }
  1024. if ([theming valueForKey:@"background-plain"] && ![[theming valueForKey:@"background-plain"] isEqual:[NSNull null]]) {
  1025. NSNumber *result = (NSNumber*)[theming valueForKey:@"background-plain"];
  1026. capabilities.themingBackgroundPlain = result.boolValue;
  1027. }
  1028. if ([theming valueForKey:@"color"] && ![[theming valueForKey:@"color"] isEqual:[NSNull null]])
  1029. capabilities.themingColor = [theming valueForKey:@"color"];
  1030. if ([theming valueForKey:@"color-element"] && ![[theming valueForKey:@"color-element"] isEqual:[NSNull null]])
  1031. capabilities.themingColorElement = [theming valueForKey:@"color-element"];
  1032. if ([theming valueForKey:@"color-text"] && ![[theming valueForKey:@"color-text"] isEqual:[NSNull null]])
  1033. capabilities.themingColorText = [theming valueForKey:@"color-text"];
  1034. if ([theming valueForKey:@"logo"] && ![[theming valueForKey:@"logo"] isEqual:[NSNull null]])
  1035. capabilities.themingLogo = [theming valueForKey:@"logo"];
  1036. if ([theming valueForKey:@"name"] && ![[theming valueForKey:@"name"] isEqual:[NSNull null]])
  1037. capabilities.themingName = [theming valueForKey:@"name"];
  1038. if ([theming valueForKey:@"slogan"] && ![[theming valueForKey:@"slogan"] isEqual:[NSNull null]])
  1039. capabilities.themingSlogan = [theming valueForKey:@"slogan"];
  1040. if ([theming valueForKey:@"url"] && ![[theming valueForKey:@"url"] isEqual:[NSNull null]])
  1041. capabilities.themingUrl = [theming valueForKey:@"url"];
  1042. }
  1043. //END TO END Encryption
  1044. NSDictionary *endToEndEncryption = [capabilitiesDict valueForKey:@"end-to-end-encryption"];
  1045. if ([endToEndEncryption count] > 0) {
  1046. NSNumber *endToEndEncryptionEnabled = (NSNumber*)[endToEndEncryption valueForKey:@"enabled"];
  1047. capabilities.isEndToEndEncryptionEnabled = endToEndEncryptionEnabled.boolValue;
  1048. if ([endToEndEncryption valueForKey:@"api-version"] && ![[endToEndEncryption valueForKey:@"api-version"] isEqual:[NSNull null]])
  1049. capabilities.endToEndEncryptionVersion = [endToEndEncryption valueForKey:@"api-version"];
  1050. }
  1051. }
  1052. successRequest(response, capabilities, request.redirectedServer);
  1053. } else {
  1054. failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedStringFromTable(@"_server_response_error_", @"Error", nil)], request.redirectedServer);
  1055. }
  1056. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  1057. failureRequest(response, error, request.redirectedServer);
  1058. }];
  1059. }
  1060. #pragma mark - Thumbnail
  1061. - (NSURLSessionTask *) getRemoteThumbnailByServer:(NSString*)serverPath ofFilePath:(NSString *)filePath withWidth:(NSInteger)fileWidth andHeight:(NSInteger)fileHeight onCommunication:(OCCommunication *)sharedOCComunication
  1062. successRequest:(void(^)(NSHTTPURLResponse *response, NSData *thumbnail, NSString *redirectedServer)) successRequest
  1063. failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
  1064. serverPath = [serverPath encodeString:NSUTF8StringEncoding];
  1065. serverPath = [serverPath stringByAppendingString:k_url_thumbnails];
  1066. filePath = [filePath encodeString:NSUTF8StringEncoding];
  1067. OCWebDAVClient *request = [OCWebDAVClient new];
  1068. request = [self getRequestWithCredentials:request];
  1069. OCHTTPRequestOperation *operation = [request getRemoteThumbnailByServer:serverPath ofFilePath:filePath withWidth:fileWidth andHeight:fileHeight onCommunication:sharedOCComunication
  1070. success:^(NSHTTPURLResponse *response, id responseObject) {
  1071. NSData *responseData = (NSData*) responseObject;
  1072. successRequest(response, responseData, request.redirectedServer);
  1073. } failure:^(NSHTTPURLResponse *response, id _Nullable responseObject, NSError * _Nonnull error) {
  1074. failureRequest(response, error, request.redirectedServer);
  1075. }];
  1076. [operation resume];
  1077. return operation;
  1078. }
  1079. - (NSURLSessionTask *) getRemotePreviewByServer:(NSString*)serverPath ofFilePath:(NSString *)filePath withWidth:(NSInteger)fileWidth andHeight:(NSInteger)fileHeight andA:(NSInteger)a andMode:(NSString * _Nonnull)mode onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSData *preview, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
  1080. serverPath = [serverPath encodeString:NSUTF8StringEncoding];
  1081. filePath = [filePath encodeString:NSUTF8StringEncoding];
  1082. OCWebDAVClient *request = [OCWebDAVClient new];
  1083. request = [self getRequestWithCredentials:request];
  1084. OCHTTPRequestOperation *operation = [request getRemotePreviewByServer:serverPath ofFilePath:filePath withWidth:fileWidth andHeight:fileHeight andA:a andMode:mode onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
  1085. NSData *responseData = (NSData*) responseObject;
  1086. successRequest(response, responseData, request.redirectedServer);
  1087. } failure:^(NSHTTPURLResponse *response, id _Nullable responseObject, NSError * _Nonnull error) {
  1088. failureRequest(response, error, request.redirectedServer);
  1089. }];
  1090. [operation resume];
  1091. return operation;
  1092. }
  1093. #pragma mark - Notification
  1094. - (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 {
  1095. serverPath = [serverPath encodeString:NSUTF8StringEncoding];
  1096. serverPath = [serverPath stringByAppendingString:k_url_acces_remote_notification_api];
  1097. OCWebDAVClient *request = [OCWebDAVClient new];
  1098. request = [self getRequestWithCredentials:request];
  1099. [request getNotificationServer:serverPath onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
  1100. NSData *responseData = (NSData*) responseObject;
  1101. NSMutableArray *listOfNotifications = [NSMutableArray new];
  1102. //Parse
  1103. NSError *error;
  1104. NSDictionary *jsongParsed = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
  1105. NSLog(@"[LOG] Notifications : %@",jsongParsed);
  1106. if (jsongParsed && jsongParsed.allKeys > 0) {
  1107. NSDictionary *ocs = [jsongParsed valueForKey:@"ocs"];
  1108. NSDictionary *meta = [ocs valueForKey:@"meta"];
  1109. NSDictionary *datas = [ocs valueForKey:@"data"];
  1110. NSInteger statusCode = [[meta valueForKey:@"statuscode"] integerValue];
  1111. if (statusCode == kOCNotificationAPINoContent || statusCode == kOCNotificationAPISuccessful) {
  1112. for (NSDictionary *data in datas) {
  1113. OCNotifications *notification = [OCNotifications new];
  1114. if ([data valueForKey:@"notification_id"] && ![[data valueForKey:@"notification_id"] isEqual:[NSNull null]])
  1115. notification.idNotification = [[data valueForKey:@"notification_id"] integerValue];
  1116. if ([data valueForKey:@"app"] && ![[data valueForKey:@"app"] isEqual:[NSNull null]])
  1117. notification.application = [data valueForKey:@"app"];
  1118. if ([data valueForKey:@"user"] && ![[data valueForKey:@"user"] isEqual:[NSNull null]])
  1119. notification.user = [data valueForKey:@"user"];
  1120. if ([data valueForKey:@"datetime"] && ![[data valueForKey:@"datetime"] isEqual:[NSNull null]]) {
  1121. NSString *dateString = [data valueForKey:@"datetime"];
  1122. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  1123. NSLocale *enUSPOSIXLocale = [NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"];
  1124. [dateFormatter setLocale:enUSPOSIXLocale];
  1125. [dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZZZZZ"];
  1126. notification.date = [dateFormatter dateFromString:dateString];
  1127. }
  1128. if ([data valueForKey:@"object_type"] && ![[data valueForKey:@"object_type"] isEqual:[NSNull null]])
  1129. notification.typeObject = [data valueForKey:@"object_type"];
  1130. if ([data valueForKey:@"object_id"] && ![[data valueForKey:@"object_id"] isEqual:[NSNull null]])
  1131. notification.idObject = [data valueForKey:@"object_id"];
  1132. if ([data valueForKey:@"subject"] && ![[data valueForKey:@"subject"] isEqual:[NSNull null]])
  1133. notification.subject = [data valueForKey:@"subject"];
  1134. if ([data valueForKey:@"subjectRich"] && ![[data valueForKey:@"subjectRich"] isEqual:[NSNull null]])
  1135. notification.subjectRich = [data valueForKey:@"subjectRich"];
  1136. if ([data valueForKey:@"subjectRichParameters"] && ![[data valueForKey:@"subjectRichParameters"] isEqual:[NSNull null]])
  1137. notification.subjectRichParameters = [data valueForKey:@"subjectRichParameters"];
  1138. if ([data valueForKey:@"message"] && ![[data valueForKey:@"message"] isEqual:[NSNull null]])
  1139. notification.message = [data valueForKey:@"message"];
  1140. if ([data valueForKey:@"messageRich"] && ![[data valueForKey:@"messageRich"] isEqual:[NSNull null]])
  1141. notification.messageRich = [data valueForKey:@"messageRich"];
  1142. if ([data valueForKey:@"messageRichParameters"] && ![[data valueForKey:@"messageRichParameters"] isEqual:[NSNull null]])
  1143. notification.messageRichParameters = [data valueForKey:@"messageRichParameters"];
  1144. if ([data valueForKey:@"link"] && ![[data valueForKey:@"link"] isEqual:[NSNull null]])
  1145. notification.link = [data valueForKey:@"link"];
  1146. if ([data valueForKey:@"icon"] && ![[data valueForKey:@"icon"] isEqual:[NSNull null]])
  1147. notification.icon = [data valueForKey:@"icon"];
  1148. /* ACTION */
  1149. NSMutableArray *actionsArr = [NSMutableArray new];
  1150. NSDictionary *actions = [data valueForKey:@"actions"];
  1151. for (NSDictionary *action in actions) {
  1152. OCNotificationsAction *notificationAction = [OCNotificationsAction new];
  1153. if ([action valueForKey:@"label"] && ![[action valueForKey:@"label"] isEqual:[NSNull null]])
  1154. notificationAction.label = [action valueForKey:@"label"];
  1155. if ([action valueForKey:@"link"] && ![[action valueForKey:@"link"] isEqual:[NSNull null]])
  1156. notificationAction.link = [action valueForKey:@"link"];
  1157. if ([action valueForKey:@"primary"] && ![[action valueForKey:@"primary"] isEqual:[NSNull null]])
  1158. notificationAction.primary = [[action valueForKey:@"primary"] boolValue];
  1159. if ([action valueForKey:@"type"] && ![[action valueForKey:@"type"] isEqual:[NSNull null]])
  1160. notificationAction.type = [action valueForKey:@"type"];
  1161. [actionsArr addObject:notificationAction];
  1162. }
  1163. notification.actions = [[NSArray alloc] initWithArray:actionsArr];
  1164. [listOfNotifications addObject:notification];
  1165. }
  1166. successRequest(response, listOfNotifications, request.redirectedServer);
  1167. } else {
  1168. NSString *message = (NSString *)[meta objectForKey:@"message"];
  1169. if ([message isKindOfClass:[NSNull class]]) {
  1170. message = NSLocalizedStringFromTable(@"_server_response_error_", @"Error", nil);
  1171. }
  1172. failureRequest(response, [UtilsFramework getErrorWithCode:statusCode andCustomMessageFromTheServer:message], request.redirectedServer);
  1173. }
  1174. } else {
  1175. failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedStringFromTable(@"_server_response_error_", @"Error", nil)], request.redirectedServer);
  1176. }
  1177. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  1178. failureRequest(response, error, request.redirectedServer);
  1179. }];
  1180. }
  1181. - (void)setNotificationServer:(NSString*)serverPath type:(NSString *)type onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void (^)(NSHTTPURLResponse *, NSString *))successRequest failureRequest:(void (^)(NSHTTPURLResponse *, NSError *, NSString *))failureRequest {
  1182. serverPath = [serverPath encodeString:NSUTF8StringEncoding];
  1183. OCWebDAVClient *request = [OCWebDAVClient new];
  1184. request = [self getRequestWithCredentials:request];
  1185. __weak OCWebDAVClient *wrequest = request;
  1186. [request setNotificationServer:serverPath type:type onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
  1187. successRequest(response, wrequest.redirectedServer);
  1188. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  1189. failureRequest(response, error, wrequest.redirectedServer);
  1190. }];
  1191. }
  1192. #pragma mark - Push Notification
  1193. - (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 {
  1194. serverPath = [serverPath encodeString:NSUTF8StringEncoding];
  1195. serverPath = [serverPath stringByAppendingString:k_url_acces_remote_subscribing_nextcloud_server_api];
  1196. OCWebDAVClient *request = [OCWebDAVClient new];
  1197. request = [self getRequestWithCredentials:request];
  1198. [request subscribingNextcloudServerPush:serverPath pushTokenHash:pushTokenHash devicePublicKey:devicePublicKey proxyServerPath:proxyServerPath onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
  1199. NSData *responseData = (NSData*)responseObject;
  1200. NSError *error;
  1201. NSDictionary *jsongParsed = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
  1202. if (jsongParsed && jsongParsed.allKeys > 0) {
  1203. NSDictionary *ocs = [jsongParsed valueForKey:@"ocs"];
  1204. NSDictionary *meta = [ocs valueForKey:@"meta"];
  1205. NSDictionary *datas = [ocs valueForKey:@"data"];
  1206. NSInteger statusCode = [[meta valueForKey:@"statuscode"] integerValue];
  1207. if (statusCode == kOCPushNotificationAPISuccessful || statusCode == kOCPushNotificationAPINeedSendProxy) {
  1208. NSString *publicKey = [datas objectForKey:@"publicKey"];
  1209. NSString *deviceIdentifier = [datas objectForKey:@"deviceIdentifier"];
  1210. NSString *signature = [datas objectForKey:@"signature"];
  1211. successRequest(response, publicKey, deviceIdentifier, signature, request.redirectedServer);
  1212. } else {
  1213. NSString *message = (NSString *)[meta objectForKey:@"message"];
  1214. if ([message isKindOfClass:[NSNull class]]) {
  1215. message = NSLocalizedStringFromTable(@"_server_response_error_", @"Error", nil);
  1216. }
  1217. failureRequest(response, [UtilsFramework getErrorWithCode:statusCode andCustomMessageFromTheServer:message], request.redirectedServer);
  1218. }
  1219. } else {
  1220. failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedStringFromTable(@"_server_response_error_", @"Error", nil)], request.redirectedServer);
  1221. }
  1222. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  1223. failureRequest(response, error, request.redirectedServer);
  1224. }];
  1225. }
  1226. - (void)unsubscribingNextcloudServerPush:(NSString *)serverPath onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer)) successRequest failureRequest:(void (^)(NSHTTPURLResponse *, NSError *, NSString *))failureRequest {
  1227. serverPath = [serverPath encodeString:NSUTF8StringEncoding];
  1228. serverPath = [serverPath stringByAppendingString:k_url_acces_remote_subscribing_nextcloud_server_api];
  1229. OCWebDAVClient *request = [OCWebDAVClient new];
  1230. request = [self getRequestWithCredentials:request];
  1231. [request unsubscribingNextcloudServerPush:serverPath onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
  1232. successRequest(response, request.redirectedServer);
  1233. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  1234. failureRequest(response, error, request.redirectedServer);
  1235. }];
  1236. }
  1237. - (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 {
  1238. serverPath = [serverPath encodeString:NSUTF8StringEncoding];
  1239. serverPath = [serverPath stringByAppendingString:@"/devices"];
  1240. OCWebDAVClient *request = [OCWebDAVClient new];
  1241. request = [self getRequestWithCredentials:request];
  1242. [request subscribingPushProxy:serverPath pushToken:pushToken deviceIdentifier:deviceIdentifier deviceIdentifierSignature:deviceIdentifierSignature publicKey:publicKey onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
  1243. if (successRequest) {
  1244. //Return success
  1245. successRequest(response, request.redirectedServer);
  1246. }
  1247. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  1248. failureRequest(response, error, request.redirectedServer);
  1249. }];
  1250. }
  1251. - (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 {
  1252. serverPath = [serverPath encodeString:NSUTF8StringEncoding];
  1253. serverPath = [serverPath stringByAppendingString:@"/devices"];
  1254. OCWebDAVClient *request = [OCWebDAVClient new];
  1255. request = [self getRequestWithCredentials:request];
  1256. [request unsubscribingPushProxy:serverPath deviceIdentifier:deviceIdentifier deviceIdentifierSignature:deviceIdentifierSignature publicKey:publicKey onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
  1257. if (successRequest) {
  1258. //Return success
  1259. successRequest(response, request.redirectedServer);
  1260. }
  1261. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  1262. failureRequest(response, error, request.redirectedServer);
  1263. }];
  1264. }
  1265. #pragma mark - Activity
  1266. - (void) getActivityServer:(NSString*)serverPath onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSArray *listOfActivity, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
  1267. serverPath = [serverPath encodeString:NSUTF8StringEncoding];
  1268. serverPath = [serverPath stringByAppendingString:k_url_acces_remote_activity_api];
  1269. OCWebDAVClient *request = [OCWebDAVClient new];
  1270. request = [self getRequestWithCredentials:request];
  1271. [request getActivityServer:serverPath onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
  1272. NSData *responseData = (NSData*) responseObject;
  1273. NSMutableArray *listOfActivity = [NSMutableArray new];
  1274. //Parse
  1275. NSError *error;
  1276. NSDictionary *jsongParsed = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
  1277. NSLog(@"[LOG] Activity : %@",jsongParsed);
  1278. if (jsongParsed && [jsongParsed isKindOfClass:[NSDictionary class]] && jsongParsed.allKeys > 0) {
  1279. NSDictionary *ocs = [jsongParsed valueForKey:@"ocs"];
  1280. NSDictionary *meta = [ocs valueForKey:@"meta"];
  1281. NSDictionary *datas = [ocs valueForKey:@"data"];
  1282. NSInteger statusCode = [[meta valueForKey:@"statuscode"] integerValue];
  1283. if (statusCode == kOCNotificationAPINoContent || statusCode == kOCNotificationAPISuccessful) {
  1284. for (NSDictionary *data in datas) {
  1285. OCActivity *activity = [OCActivity new];
  1286. if ([data valueForKey:@"id"] && ![[data valueForKey:@"id"] isEqual:[NSNull null]])
  1287. activity.idActivity = [[data valueForKey:@"id"] integerValue];
  1288. if ([data valueForKey:@"date"] && ![[data valueForKey:@"date"] isEqual:[NSNull null]]) {
  1289. NSString *dateString = [data valueForKey:@"date"];
  1290. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  1291. NSLocale *enUSPOSIXLocale = [NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"];
  1292. [dateFormatter setLocale:enUSPOSIXLocale];
  1293. [dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZZZZZ"];
  1294. activity.date = [dateFormatter dateFromString:dateString];
  1295. }
  1296. if ([data valueForKey:@"file"] && ![[data valueForKey:@"file"] isEqual:[NSNull null]])
  1297. activity.file = [data valueForKey:@"file"];
  1298. if ([data valueForKey:@"link"] && ![[data valueForKey:@"link"] isEqual:[NSNull null]])
  1299. activity.link = [data valueForKey:@"link"];
  1300. if ([data valueForKey:@"message"] && ![[data valueForKey:@"message"] isEqual:[NSNull null]])
  1301. activity.message = [data valueForKey:@"message"];
  1302. if ([data valueForKey:@"subject"] && ![[data valueForKey:@"subject"] isEqual:[NSNull null]])
  1303. activity.subject = [data valueForKey:@"subject"];
  1304. [listOfActivity addObject:activity];
  1305. }
  1306. successRequest(response, listOfActivity, request.redirectedServer);
  1307. } else {
  1308. NSString *message = (NSString *)[meta objectForKey:@"message"];
  1309. if ([message isKindOfClass:[NSNull class]]) {
  1310. message = NSLocalizedStringFromTable(@"_server_response_error_", @"Error", nil);
  1311. }
  1312. failureRequest(response, [UtilsFramework getErrorWithCode:statusCode andCustomMessageFromTheServer:message], request.redirectedServer);
  1313. }
  1314. } else {
  1315. failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedStringFromTable(@"_server_response_error_", @"Error", nil)], request.redirectedServer);
  1316. }
  1317. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  1318. failureRequest(response, error, request.redirectedServer);
  1319. }];
  1320. }
  1321. #pragma mark - External Sites
  1322. - (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 {
  1323. serverPath = [serverPath encodeString:NSUTF8StringEncoding];
  1324. serverPath = [serverPath stringByAppendingString:k_url_acces_external_sites_api];
  1325. OCWebDAVClient *request = [OCWebDAVClient new];
  1326. request = [self getRequestWithCredentials:request];
  1327. [request getExternalSitesServer:serverPath onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
  1328. NSData *responseData = (NSData*) responseObject;
  1329. NSMutableArray *listOfExternalSites = [NSMutableArray new];
  1330. //Parse
  1331. NSError *error;
  1332. NSDictionary *jsongParsed = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
  1333. NSLog(@"[LOG] External Sites : %@",jsongParsed);
  1334. if (jsongParsed && jsongParsed.allKeys > 0) {
  1335. NSDictionary *ocs = [jsongParsed valueForKey:@"ocs"];
  1336. NSDictionary *meta = [ocs valueForKey:@"meta"];
  1337. NSDictionary *datas = [ocs valueForKey:@"data"];
  1338. NSInteger statusCode = [[meta valueForKey:@"statuscode"] integerValue];
  1339. if (statusCode == kOCNotificationAPINoContent || statusCode == kOCNotificationAPISuccessful) {
  1340. for (NSDictionary *data in datas) {
  1341. OCExternalSites *externalSites = [OCExternalSites new];
  1342. externalSites.idExternalSite = [[data valueForKey:@"id"] integerValue];
  1343. if ([data valueForKey:@"icon"] && ![[data valueForKey:@"icon"] isEqual:[NSNull null]])
  1344. externalSites.icon = [data valueForKey:@"icon"];
  1345. if ([data valueForKey:@"lang"] && ![[data valueForKey:@"lang"] isEqual:[NSNull null]])
  1346. externalSites.lang = [data valueForKey:@"lang"];
  1347. if ([data valueForKey:@"name"] && ![[data valueForKey:@"name"] isEqual:[NSNull null]])
  1348. externalSites.name = [data valueForKey:@"name"];
  1349. if ([data valueForKey:@"url"] && ![[data valueForKey:@"url"] isEqual:[NSNull null]])
  1350. externalSites.url = [data valueForKey:@"url"];
  1351. if ([data valueForKey:@"type"] && ![[data valueForKey:@"type"] isEqual:[NSNull null]])
  1352. externalSites.type = [data valueForKey:@"type"];
  1353. [listOfExternalSites addObject:externalSites];
  1354. }
  1355. successRequest(response, listOfExternalSites, request.redirectedServer);
  1356. } else {
  1357. NSString *message = (NSString *)[meta objectForKey:@"message"];
  1358. if ([message isKindOfClass:[NSNull class]]) {
  1359. message = NSLocalizedStringFromTable(@"_server_response_error_", @"Error", nil);
  1360. }
  1361. failureRequest(response, [UtilsFramework getErrorWithCode:statusCode andCustomMessageFromTheServer:message], request.redirectedServer);
  1362. }
  1363. } else {
  1364. failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedStringFromTable(@"_server_response_error_", @"Error", nil)], request.redirectedServer);
  1365. }
  1366. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  1367. failureRequest(response, error, request.redirectedServer);
  1368. }];
  1369. }
  1370. #pragma mark - User Profile
  1371. - (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 {
  1372. serverPath = [serverPath stringByAppendingString:k_url_acces_remote_userprofile_api];
  1373. serverPath = [serverPath encodeString:NSUTF8StringEncoding];
  1374. OCWebDAVClient *request = [OCWebDAVClient new];
  1375. request = [self getRequestWithCredentials:request];
  1376. [request getUserProfileServer:serverPath onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
  1377. NSData *responseData = (NSData*) responseObject;
  1378. OCUserProfile *userProfile = [OCUserProfile new];
  1379. //Parse
  1380. NSError *error;
  1381. NSDictionary *jsongParsed = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
  1382. NSLog(@"[LOG] User Profile : %@",jsongParsed);
  1383. if (jsongParsed && jsongParsed.allKeys > 0) {
  1384. NSDictionary *ocs = [jsongParsed valueForKey:@"ocs"];
  1385. NSDictionary *meta = [ocs valueForKey:@"meta"];
  1386. NSDictionary *data = [ocs valueForKey:@"data"];
  1387. NSInteger statusCode = [[meta valueForKey:@"statuscode"] integerValue];
  1388. if (statusCode == kOCUserProfileAPISuccessful) {
  1389. if ([data valueForKey:@"address"] && ![[data valueForKey:@"address"] isKindOfClass:[NSNull class]])
  1390. userProfile.address = [data valueForKey:@"address"];
  1391. if ([data valueForKey:@"display-name"] && ![[data valueForKey:@"display-name"] isKindOfClass:[NSNull class]])
  1392. userProfile.displayName = [data valueForKey:@"display-name"];
  1393. if ([data valueForKey:@"email"] && ![[data valueForKey:@"email"] isKindOfClass:[NSNull class]])
  1394. userProfile.email = [data valueForKey:@"email"];
  1395. if ([data valueForKey:@"enabled"] && ![[data valueForKey:@"enabled"] isKindOfClass:[NSNull class]])
  1396. userProfile.enabled = [[data valueForKey:@"enabled"] boolValue];
  1397. if ([data valueForKey:@"id"] && ![[data valueForKey:@"id"] isKindOfClass:[NSNull class]])
  1398. userProfile.id = [data valueForKey:@"id"];
  1399. if ([data valueForKey:@"phone"] && ![[data valueForKey:@"phone"] isKindOfClass:[NSNull class]])
  1400. userProfile.phone = [data valueForKey:@"phone"];
  1401. if ([data valueForKey:@"twitter"] && ![[data valueForKey:@"twitter"] isKindOfClass:[NSNull class]])
  1402. userProfile.twitter = [data valueForKey:@"twitter"];
  1403. if ([data valueForKey:@"webpage"] && ![[data valueForKey:@"webpage"] isKindOfClass:[NSNull class]])
  1404. userProfile.webpage = [data valueForKey:@"webpage"];
  1405. /* QUOTA */
  1406. NSDictionary *quota = [data valueForKey:@"quota"];
  1407. if ([quota count] > 0) {
  1408. if ([quota valueForKey:@"free"] && ![[quota valueForKey:@"free"] isKindOfClass:[NSNull class]])
  1409. userProfile.quotaFree = [[quota valueForKey:@"free"] doubleValue];
  1410. if ([quota valueForKey:@"quota"] && ![[quota valueForKey:@"quota"] isKindOfClass:[NSNull class]])
  1411. userProfile.quota = [[quota valueForKey:@"quota"] doubleValue];
  1412. if ([quota valueForKey:@"relative"] && ![[quota valueForKey:@"relative"] isKindOfClass:[NSNull class]])
  1413. userProfile.quotaRelative = [[quota valueForKey:@"relative"] doubleValue];
  1414. if ([quota valueForKey:@"total"] && ![[quota valueForKey:@"total"] isKindOfClass:[NSNull class]])
  1415. userProfile.quotaTotal = [[quota valueForKey:@"total"] doubleValue];
  1416. if ([quota valueForKey:@"used"] && ![[quota valueForKey:@"used"] isKindOfClass:[NSNull class]])
  1417. userProfile.quotaUsed = [[quota valueForKey:@"used"] doubleValue];
  1418. }
  1419. successRequest(response, userProfile, request.redirectedServer);
  1420. } else {
  1421. NSString *message = (NSString *)[meta objectForKey:@"message"];
  1422. if ([message isKindOfClass:[NSNull class]]) {
  1423. message = NSLocalizedStringFromTable(@"_server_response_error_", @"Error", nil);
  1424. }
  1425. failureRequest(response, [UtilsFramework getErrorWithCode:statusCode andCustomMessageFromTheServer:message], request.redirectedServer);
  1426. }
  1427. } else {
  1428. failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedStringFromTable(@"_server_response_error_", @"Error", nil)], request.redirectedServer);
  1429. }
  1430. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  1431. failureRequest(response, error, request.redirectedServer);
  1432. }];
  1433. }
  1434. #pragma mark - End-to-End Encryption
  1435. - (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 {
  1436. serverPath = [serverPath stringByAppendingString:k_url_client_side_encryption];
  1437. serverPath = [serverPath stringByAppendingString:@"/public-key"];
  1438. serverPath = [serverPath stringByAppendingString:@"?format=json"];
  1439. OCWebDAVClient *request = [OCWebDAVClient new];
  1440. request = [self getRequestWithCredentials:request];
  1441. [request getEndToEndPublicKeys:serverPath onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
  1442. NSData *responseData = (NSData*) responseObject;
  1443. NSString *publicKey = @"";
  1444. //Parse
  1445. NSError *error;
  1446. NSDictionary *jsongParsed = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
  1447. NSLog(@"[LOG] E2E Get PublicKey : %@",jsongParsed);
  1448. if (jsongParsed && jsongParsed.allKeys > 0) {
  1449. NSDictionary *ocs = [jsongParsed valueForKey:@"ocs"];
  1450. NSDictionary *meta = [ocs valueForKey:@"meta"];
  1451. NSDictionary *data = [ocs valueForKey:@"data"];
  1452. NSInteger statusCode = [[meta valueForKey:@"statuscode"] integerValue];
  1453. if (statusCode == kOCUserProfileAPISuccessful) {
  1454. if ([data valueForKey:@"public-keys"] && ![[data valueForKey:@"public-keys"] isKindOfClass:[NSNull class]]) {
  1455. NSDictionary *publickeys = [data valueForKey:@"public-keys"];
  1456. publicKey = [publickeys valueForKey:self.userID];
  1457. successRequest(response, publicKey, request.redirectedServer);
  1458. } else {
  1459. failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedStringFromTable(@"_server_response_error_", @"Error", nil)], request.redirectedServer);
  1460. }
  1461. } else {
  1462. NSString *message = (NSString *)[meta objectForKey:@"message"];
  1463. if ([message isKindOfClass:[NSNull class]]) {
  1464. message = NSLocalizedStringFromTable(@"_server_response_error_", @"Error", nil);
  1465. }
  1466. failureRequest(response, [UtilsFramework getErrorWithCode:statusCode andCustomMessageFromTheServer:message], request.redirectedServer);
  1467. }
  1468. } else {
  1469. failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedStringFromTable(@"_server_response_error_", @"Error", nil)], request.redirectedServer);
  1470. }
  1471. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  1472. //Return error
  1473. failureRequest(response, error, request.redirectedServer);
  1474. }];
  1475. }
  1476. - (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 {
  1477. serverPath = [serverPath stringByAppendingString:k_url_client_side_encryption];
  1478. serverPath = [serverPath stringByAppendingString:@"/private-key"];
  1479. serverPath = [serverPath stringByAppendingString:@"?format=json"];
  1480. OCWebDAVClient *request = [OCWebDAVClient new];
  1481. request = [self getRequestWithCredentials:request];
  1482. [request getEndToEndPrivateKeyCipher:serverPath onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
  1483. NSData *responseData = (NSData*) responseObject;
  1484. NSString *privateKeyChiper = @"";
  1485. //Parse
  1486. NSError *error;
  1487. NSDictionary *jsongParsed = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
  1488. NSLog(@"[LOG] E2E Get PrivateKey : %@",jsongParsed);
  1489. if (jsongParsed && jsongParsed.allKeys > 0) {
  1490. NSDictionary *ocs = [jsongParsed valueForKey:@"ocs"];
  1491. NSDictionary *meta = [ocs valueForKey:@"meta"];
  1492. NSDictionary *data = [ocs valueForKey:@"data"];
  1493. NSInteger statusCode = [[meta valueForKey:@"statuscode"] integerValue];
  1494. if (statusCode == kOCUserProfileAPISuccessful) {
  1495. if ([data valueForKey:@"private-key"] && ![[data valueForKey:@"private-key"] isKindOfClass:[NSNull class]]) {
  1496. privateKeyChiper = [data valueForKey:@"private-key"];
  1497. successRequest(response, privateKeyChiper, request.redirectedServer);
  1498. } else {
  1499. failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedStringFromTable(@"_server_response_error_", @"Error", nil)], request.redirectedServer);
  1500. }
  1501. } else {
  1502. NSString *message = (NSString *)[meta objectForKey:@"message"];
  1503. if ([message isKindOfClass:[NSNull class]]) {
  1504. message = NSLocalizedStringFromTable(@"_server_response_error_", @"Error", nil);
  1505. }
  1506. failureRequest(response, [UtilsFramework getErrorWithCode:statusCode andCustomMessageFromTheServer:message], request.redirectedServer);
  1507. }
  1508. } else {
  1509. failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedStringFromTable(@"_server_response_error_", @"Error", nil)], request.redirectedServer);
  1510. }
  1511. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  1512. //Return error
  1513. failureRequest(response, error, request.redirectedServer);
  1514. }];
  1515. }
  1516. - (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 {
  1517. serverPath = [serverPath stringByAppendingString:k_url_client_side_encryption];
  1518. serverPath = [serverPath stringByAppendingString:@"/server-key"];
  1519. serverPath = [serverPath stringByAppendingString:@"?format=json"];
  1520. OCWebDAVClient *request = [OCWebDAVClient new];
  1521. request = [self getRequestWithCredentials:request];
  1522. [request getEndToEndServerPublicKey:serverPath onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
  1523. NSData *responseData = (NSData*) responseObject;
  1524. NSString *publicKey = @"";
  1525. //Parse
  1526. NSError *error;
  1527. NSDictionary *jsongParsed = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
  1528. NSLog(@"[LOG] E2E Get Server PublicKey : %@",jsongParsed);
  1529. if (jsongParsed && jsongParsed.allKeys > 0) {
  1530. NSDictionary *ocs = [jsongParsed valueForKey:@"ocs"];
  1531. NSDictionary *meta = [ocs valueForKey:@"meta"];
  1532. NSDictionary *data = [ocs valueForKey:@"data"];
  1533. NSInteger statusCode = [[meta valueForKey:@"statuscode"] integerValue];
  1534. if (statusCode == kOCUserProfileAPISuccessful) {
  1535. if ([data valueForKey:@"public-key"] && ![[data valueForKey:@"public-key"] isKindOfClass:[NSNull class]]) {
  1536. publicKey = [data valueForKey:@"public-key"];
  1537. successRequest(response, publicKey, request.redirectedServer);
  1538. } else {
  1539. failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedStringFromTable(@"_server_response_error_", @"Error", nil)], request.redirectedServer);
  1540. }
  1541. } else {
  1542. NSString *message = (NSString *)[meta objectForKey:@"message"];
  1543. if ([message isKindOfClass:[NSNull class]]) {
  1544. message = NSLocalizedStringFromTable(@"_server_response_error_", @"Error", nil);
  1545. }
  1546. failureRequest(response, [UtilsFramework getErrorWithCode:statusCode andCustomMessageFromTheServer:message], request.redirectedServer);
  1547. }
  1548. } else {
  1549. failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedStringFromTable(@"_server_response_error_", @"Error", nil)], request.redirectedServer);
  1550. }
  1551. //Return success
  1552. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  1553. //Return error
  1554. failureRequest(response, error, request.redirectedServer);
  1555. }];
  1556. }
  1557. - (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 {
  1558. serverPath = [serverPath stringByAppendingString:k_url_client_side_encryption];
  1559. serverPath = [serverPath stringByAppendingString:@"/public-key"];
  1560. serverPath = [serverPath stringByAppendingString:@"?format=json"];
  1561. OCWebDAVClient *request = [[OCWebDAVClient alloc] init];
  1562. request = [self getRequestWithCredentials:request];
  1563. [request signEndToEndPublicKey:serverPath key:publicKey onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
  1564. NSData *responseData = (NSData*) responseObject;
  1565. NSString *publicKey = @"";
  1566. //Parse
  1567. NSError *error;
  1568. NSDictionary *jsongParsed = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
  1569. NSLog(@"[LOG] E2E Sign PublicKey : %@",jsongParsed);
  1570. if (jsongParsed && jsongParsed.allKeys > 0) {
  1571. NSDictionary *ocs = [jsongParsed valueForKey:@"ocs"];
  1572. NSDictionary *meta = [ocs valueForKey:@"meta"];
  1573. NSDictionary *data = [ocs valueForKey:@"data"];
  1574. NSInteger statusCode = [[meta valueForKey:@"statuscode"] integerValue];
  1575. if (statusCode == kOCUserProfileAPISuccessful) {
  1576. if ([data valueForKey:@"public-key"] && ![[data valueForKey:@"public-key"] isKindOfClass:[NSNull class]]) {
  1577. publicKey = [data valueForKey:@"public-key"];
  1578. successRequest(response, publicKey, request.redirectedServer);
  1579. } else {
  1580. failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedStringFromTable(@"_server_response_error_", @"Error", nil)], request.redirectedServer);
  1581. }
  1582. } else {
  1583. NSString *message = (NSString *)[meta objectForKey:@"message"];
  1584. if ([message isKindOfClass:[NSNull class]]) {
  1585. message = NSLocalizedStringFromTable(@"_server_response_error_", @"Error", nil);
  1586. }
  1587. failureRequest(response, [UtilsFramework getErrorWithCode:statusCode andCustomMessageFromTheServer:message], request.redirectedServer);
  1588. }
  1589. } else {
  1590. failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedStringFromTable(@"_server_response_error_", @"Error", nil)], request.redirectedServer);
  1591. }
  1592. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  1593. //Return error
  1594. failureRequest(response, error, request.redirectedServer);
  1595. }];
  1596. }
  1597. - (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 {
  1598. serverPath = [serverPath stringByAppendingString:k_url_client_side_encryption];
  1599. serverPath = [serverPath stringByAppendingString:@"/private-key"];
  1600. serverPath = [serverPath stringByAppendingString:@"?format=json"];
  1601. OCWebDAVClient *request = [[OCWebDAVClient alloc] init];
  1602. request = [self getRequestWithCredentials:request];
  1603. [request storeEndToEndPrivateKeyCipher:serverPath key:privateKeyChiper onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
  1604. NSData *responseData = (NSData*) responseObject;
  1605. NSString *privateKey = @"";
  1606. //Parse
  1607. NSError *error;
  1608. NSDictionary *jsongParsed = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
  1609. NSLog(@"[LOG] E2E Store PrivateKey : %@",jsongParsed);
  1610. if (jsongParsed && jsongParsed.allKeys > 0) {
  1611. NSDictionary *ocs = [jsongParsed valueForKey:@"ocs"];
  1612. NSDictionary *meta = [ocs valueForKey:@"meta"];
  1613. NSDictionary *data = [ocs valueForKey:@"data"];
  1614. NSInteger statusCode = [[meta valueForKey:@"statuscode"] integerValue];
  1615. if (statusCode == kOCUserProfileAPISuccessful) {
  1616. if ([data valueForKey:@"private-key"] && ![[data valueForKey:@"private-key"] isKindOfClass:[NSNull class]]) {
  1617. privateKey = [data valueForKey:@"private-key"];
  1618. successRequest(response, privateKey, request.redirectedServer);
  1619. } else {
  1620. failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedStringFromTable(@"_server_response_error_", @"Error", nil)], request.redirectedServer);
  1621. }
  1622. } else {
  1623. NSString *message = (NSString *)[meta objectForKey:@"message"];
  1624. if ([message isKindOfClass:[NSNull class]]) {
  1625. message = NSLocalizedStringFromTable(@"_server_response_error_", @"Error", nil);
  1626. }
  1627. failureRequest(response, [UtilsFramework getErrorWithCode:statusCode andCustomMessageFromTheServer:message], request.redirectedServer);
  1628. }
  1629. } else {
  1630. failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedStringFromTable(@"_server_response_error_", @"Error", nil)], request.redirectedServer);
  1631. }
  1632. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  1633. //Return error
  1634. failureRequest(response, error, request.redirectedServer);
  1635. }];
  1636. }
  1637. - (void)deleteEndToEndPublicKey:(NSString*)serverPath onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
  1638. serverPath = [serverPath stringByAppendingString:k_url_client_side_encryption];
  1639. serverPath = [serverPath stringByAppendingString:@"/public-key"];
  1640. serverPath = [serverPath stringByAppendingString:@"?format=json"];
  1641. OCWebDAVClient *request = [OCWebDAVClient new];
  1642. request = [self getRequestWithCredentials:request];
  1643. [request deleteEndToEndPublicKey:serverPath onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
  1644. //Return success
  1645. successRequest(response, request.redirectedServer);
  1646. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  1647. //Return error
  1648. failureRequest(response, error, request.redirectedServer);
  1649. }];
  1650. }
  1651. - (void)deleteEndToEndPrivateKey:(NSString*)serverPath onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
  1652. serverPath = [serverPath stringByAppendingString:k_url_client_side_encryption];
  1653. serverPath = [serverPath stringByAppendingString:@"/private-key"];
  1654. serverPath = [serverPath stringByAppendingString:@"?format=json"];
  1655. OCWebDAVClient *request = [OCWebDAVClient new];
  1656. request = [self getRequestWithCredentials:request];
  1657. [request deleteEndToEndPrivateKey:serverPath onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
  1658. //Return success
  1659. successRequest(response, request.redirectedServer);
  1660. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  1661. //Return error
  1662. failureRequest(response, error, request.redirectedServer);
  1663. }];
  1664. }
  1665. - (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 {
  1666. serverPath = [serverPath stringByAppendingString:k_url_client_side_encryption];
  1667. serverPath = [NSString stringWithFormat:@"%@/encrypted/%@", serverPath, fileID];
  1668. serverPath = [serverPath stringByAppendingString:@"?format=json"];
  1669. OCWebDAVClient *request = [OCWebDAVClient new];
  1670. request = [self getRequestWithCredentials:request];
  1671. [request markEndToEndFolderEncrypted:serverPath onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
  1672. //Return success
  1673. successRequest(response, request.redirectedServer);
  1674. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  1675. //Return error
  1676. failureRequest(response, error, request.redirectedServer);
  1677. }];
  1678. }
  1679. - (void)deletemarkEndToEndFolderEncrypted:(NSString*)serverPath fileID:(NSString *)fileID onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
  1680. serverPath = [serverPath stringByAppendingString:k_url_client_side_encryption];
  1681. serverPath = [NSString stringWithFormat:@"%@/encrypted/%@", serverPath, fileID];
  1682. serverPath = [serverPath stringByAppendingString:@"?format=json"];
  1683. OCWebDAVClient *request = [OCWebDAVClient new];
  1684. request = [self getRequestWithCredentials:request];
  1685. [request deletemarkEndToEndFolderEncrypted:serverPath onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
  1686. //Return success
  1687. successRequest(response, request.redirectedServer);
  1688. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  1689. //Return error
  1690. failureRequest(response, error, request.redirectedServer);
  1691. }];
  1692. }
  1693. - (void)lockEndToEndFolderEncrypted:(NSString*)serverPath fileID:(NSString *)fileID token:(NSString *)token onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *token, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
  1694. serverPath = [serverPath stringByAppendingString:k_url_client_side_encryption];
  1695. serverPath = [NSString stringWithFormat:@"%@/lock/%@", serverPath, fileID];
  1696. if (token) {
  1697. serverPath = [NSString stringWithFormat:@"%@?token=%@", serverPath, token];
  1698. serverPath = [serverPath stringByAppendingString:@"&format=json"];
  1699. } else {
  1700. serverPath = [serverPath stringByAppendingString:@"?format=json"];
  1701. }
  1702. OCWebDAVClient *request = [OCWebDAVClient new];
  1703. request = [self getRequestWithCredentials:request];
  1704. [request lockEndToEndFolderEncrypted:serverPath onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
  1705. NSData *responseData = (NSData*) responseObject;
  1706. NSString *token = @"";
  1707. //Parse
  1708. NSError *error;
  1709. NSDictionary *jsongParsed = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
  1710. NSLog(@"[LOG] E2E Lock File : %@",jsongParsed);
  1711. if (jsongParsed && jsongParsed.allKeys > 0) {
  1712. NSDictionary *ocs = [jsongParsed valueForKey:@"ocs"];
  1713. NSDictionary *meta = [ocs valueForKey:@"meta"];
  1714. NSDictionary *data = [ocs valueForKey:@"data"];
  1715. NSInteger statusCode = [[meta valueForKey:@"statuscode"] integerValue];
  1716. if (statusCode == kOCUserProfileAPISuccessful) {
  1717. if ([data valueForKey:@"token"] && ![[data valueForKey:@"token"] isKindOfClass:[NSNull class]]) {
  1718. token = [data valueForKey:@"token"];
  1719. successRequest(response, token, request.redirectedServer);
  1720. } else {
  1721. failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedStringFromTable(@"_server_response_error_", @"Error", nil)], request.redirectedServer);
  1722. }
  1723. } else {
  1724. NSString *message = (NSString *)[meta objectForKey:@"message"];
  1725. if ([message isKindOfClass:[NSNull class]]) {
  1726. message = NSLocalizedStringFromTable(@"_server_response_error_", @"Error", nil);
  1727. }
  1728. failureRequest(response, [UtilsFramework getErrorWithCode:statusCode andCustomMessageFromTheServer:message], request.redirectedServer);
  1729. }
  1730. } else {
  1731. failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedStringFromTable(@"_server_response_error_", @"Error", nil)], request.redirectedServer);
  1732. }
  1733. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  1734. //Return error
  1735. failureRequest(response, error, request.redirectedServer);
  1736. }];
  1737. }
  1738. - (void)unlockEndToEndFolderEncrypted:(NSString*)serverPath fileID:(NSString *)fileID token:(NSString *)token onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
  1739. serverPath = [serverPath stringByAppendingString:k_url_client_side_encryption];
  1740. serverPath = [NSString stringWithFormat:@"%@/lock/%@", serverPath, fileID];
  1741. serverPath = [serverPath stringByAppendingString:@"&format=json"];
  1742. OCWebDAVClient *request = [OCWebDAVClient new];
  1743. request = [self getRequestWithCredentials:request];
  1744. [request unlockEndToEndFolderEncrypted:serverPath token:token onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
  1745. //Return success
  1746. successRequest(response, request.redirectedServer);
  1747. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  1748. //Return error
  1749. failureRequest(response, error, request.redirectedServer);
  1750. }];
  1751. }
  1752. - (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 {
  1753. serverPath = [serverPath stringByAppendingString:k_url_client_side_encryption];
  1754. serverPath = [NSString stringWithFormat:@"%@/meta-data/%@", serverPath, fileID];
  1755. serverPath = [serverPath stringByAppendingString:@"?format=json"];
  1756. OCWebDAVClient *request = [[OCWebDAVClient alloc] init];
  1757. request = [self getRequestWithCredentials:request];
  1758. [request getEndToEndMetadata:serverPath onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
  1759. NSData *responseData = (NSData*) responseObject;
  1760. NSString *encryptedMetadata = @"";
  1761. //Parse
  1762. NSError *error;
  1763. NSDictionary *jsongParsed = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
  1764. NSLog(@"[LOG] E2E Get Metadata : %@",jsongParsed);
  1765. if (jsongParsed && jsongParsed.allKeys > 0) {
  1766. NSDictionary *ocs = [jsongParsed valueForKey:@"ocs"];
  1767. NSDictionary *meta = [ocs valueForKey:@"meta"];
  1768. NSDictionary *data = [ocs valueForKey:@"data"];
  1769. NSInteger statusCode = [[meta valueForKey:@"statuscode"] integerValue];
  1770. if (statusCode == kOCUserProfileAPISuccessful) {
  1771. if ([data valueForKey:@"meta-data"] && ![[data valueForKey:@"meta-data"] isKindOfClass:[NSNull class]]) {
  1772. encryptedMetadata = [data valueForKey:@"meta-data"];
  1773. successRequest(response, encryptedMetadata, request.redirectedServer);
  1774. } else {
  1775. failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedStringFromTable(@"_server_response_error_", @"Error", nil)], request.redirectedServer);
  1776. }
  1777. } else {
  1778. NSString *message = (NSString *)[meta objectForKey:@"message"];
  1779. if ([message isKindOfClass:[NSNull class]]) {
  1780. message = NSLocalizedStringFromTable(@"_server_response_error_", @"Error", nil);
  1781. }
  1782. failureRequest(response, [UtilsFramework getErrorWithCode:statusCode andCustomMessageFromTheServer:message], request.redirectedServer);
  1783. }
  1784. } else {
  1785. failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedStringFromTable(@"_server_response_error_", @"Error", nil)], request.redirectedServer);
  1786. }
  1787. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  1788. //Return error
  1789. failureRequest(response, error, request.redirectedServer);
  1790. }];
  1791. }
  1792. - (void)storeEndToEndMetadata:(NSString*)serverPath fileID:(NSString *)fileID encryptedMetadata:(NSString *)encryptedMetadata onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *encryptedMetadata, NSString *redirectedServer))successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
  1793. encryptedMetadata = [encryptedMetadata encodeString:NSUTF8StringEncoding];
  1794. serverPath = [serverPath stringByAppendingString:k_url_client_side_encryption];
  1795. serverPath = [NSString stringWithFormat:@"%@/meta-data/%@", serverPath, fileID];
  1796. serverPath = [serverPath stringByAppendingString:@"?format=json"];
  1797. OCWebDAVClient *request = [[OCWebDAVClient alloc] init];
  1798. request = [self getRequestWithCredentials:request];
  1799. [request storeEndToEndMetadata:serverPath metadata:encryptedMetadata onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
  1800. NSData *responseData = (NSData*) responseObject;
  1801. NSString *encryptedMetadata = @"";
  1802. //Parse
  1803. NSError *error;
  1804. NSDictionary *jsongParsed = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
  1805. NSLog(@"[LOG] E2E Store Metadata : %@",jsongParsed);
  1806. if (jsongParsed && jsongParsed.allKeys > 0) {
  1807. NSDictionary *ocs = [jsongParsed valueForKey:@"ocs"];
  1808. NSDictionary *meta = [ocs valueForKey:@"meta"];
  1809. NSDictionary *data = [ocs valueForKey:@"data"];
  1810. NSInteger statusCode = [[meta valueForKey:@"statuscode"] integerValue];
  1811. if (statusCode == kOCUserProfileAPISuccessful) {
  1812. if ([data valueForKey:@"meta-data"] && ![[data valueForKey:@"meta-data"] isKindOfClass:[NSNull class]]) {
  1813. encryptedMetadata = [data valueForKey:@"meta-data"];
  1814. successRequest(response, encryptedMetadata, request.redirectedServer);
  1815. } else {
  1816. failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedStringFromTable(@"_server_response_error_", @"Error", nil)], request.redirectedServer);
  1817. }
  1818. } else {
  1819. NSString *message = (NSString *)[meta objectForKey:@"message"];
  1820. if ([message isKindOfClass:[NSNull class]]) {
  1821. message = NSLocalizedStringFromTable(@"_server_response_error_", @"Error", nil);
  1822. }
  1823. failureRequest(response, [UtilsFramework getErrorWithCode:statusCode andCustomMessageFromTheServer:message], request.redirectedServer);
  1824. }
  1825. } else {
  1826. failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedStringFromTable(@"_server_response_error_", @"Error", nil)], request.redirectedServer);
  1827. }
  1828. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  1829. //Return error
  1830. failureRequest(response, error, request.redirectedServer);
  1831. }];
  1832. }
  1833. - (void)updateEndToEndMetadata:(NSString*)serverPath fileID:(NSString *)fileID encryptedMetadata:(NSString *)encryptedMetadata token:(NSString *)token onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *encryptedMetadata, NSString *redirectedServer))successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
  1834. encryptedMetadata = [encryptedMetadata encodeString:NSUTF8StringEncoding];
  1835. serverPath = [serverPath stringByAppendingString:k_url_client_side_encryption];
  1836. serverPath = [NSString stringWithFormat:@"%@/meta-data/%@", serverPath, fileID];
  1837. serverPath = [NSString stringWithFormat:@"%@?token=%@", serverPath, token];
  1838. serverPath = [serverPath stringByAppendingString:@"&format=json"];
  1839. OCWebDAVClient *request = [[OCWebDAVClient alloc] init];
  1840. request = [self getRequestWithCredentials:request];
  1841. [request updateEndToEndMetadata:serverPath metadata:encryptedMetadata onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
  1842. NSData *responseData = (NSData*) responseObject;
  1843. NSString *encryptedMetadata = @"";
  1844. //Parse
  1845. NSError *error;
  1846. NSDictionary *jsongParsed = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
  1847. NSLog(@"[LOG] E2E Update Metadata : %@",jsongParsed);
  1848. if (jsongParsed && jsongParsed.allKeys > 0) {
  1849. NSDictionary *ocs = [jsongParsed valueForKey:@"ocs"];
  1850. NSDictionary *meta = [ocs valueForKey:@"meta"];
  1851. NSDictionary *data = [ocs valueForKey:@"data"];
  1852. NSInteger statusCode = [[meta valueForKey:@"statuscode"] integerValue];
  1853. if (statusCode == kOCUserProfileAPISuccessful) {
  1854. if ([data valueForKey:@"meta-data"] && ![[data valueForKey:@"meta-data"] isKindOfClass:[NSNull class]]) {
  1855. encryptedMetadata = [data valueForKey:@"meta-data"];
  1856. successRequest(response, encryptedMetadata, request.redirectedServer);
  1857. } else {
  1858. failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedStringFromTable(@"_server_response_error_", @"Error", nil)], request.redirectedServer);
  1859. }
  1860. } else {
  1861. NSString *message = (NSString *)[meta objectForKey:@"message"];
  1862. if ([message isKindOfClass:[NSNull class]]) {
  1863. message = NSLocalizedStringFromTable(@"_server_response_error_", @"Error", nil);
  1864. }
  1865. failureRequest(response, [UtilsFramework getErrorWithCode:statusCode andCustomMessageFromTheServer:message], request.redirectedServer);
  1866. }
  1867. } else {
  1868. failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedStringFromTable(@"_server_response_error_", @"Error", nil)], request.redirectedServer);
  1869. }
  1870. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  1871. //Return error
  1872. failureRequest(response, error, request.redirectedServer);
  1873. }];
  1874. }
  1875. - (void)deleteEndToEndMetadata:(NSString*)serverPath fileID:(NSString *)fileID onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer))successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
  1876. serverPath = [serverPath stringByAppendingString:k_url_client_side_encryption];
  1877. serverPath = [NSString stringWithFormat:@"%@/meta-data/%@", serverPath, fileID];
  1878. serverPath = [serverPath stringByAppendingString:@"?format=json"];
  1879. OCWebDAVClient *request = [[OCWebDAVClient alloc] init];
  1880. request = [self getRequestWithCredentials:request];
  1881. [request deleteEndToEndMetadata:serverPath onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
  1882. //Return success
  1883. successRequest(response, request.redirectedServer);
  1884. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  1885. //Return error
  1886. failureRequest(response, error, request.redirectedServer);
  1887. }];
  1888. }
  1889. #pragma mark - Clear Cache
  1890. - (void)eraseURLCache
  1891. {
  1892. [[NSURLCache sharedURLCache] setMemoryCapacity:0];
  1893. [[NSURLCache sharedURLCache] setDiskCapacity:0];
  1894. }
  1895. #pragma mark - Utils
  1896. - (void) addUserItemOfType:(NSInteger) shareeType fromArray:(NSArray*) usersArray ToList: (NSMutableArray *) itemList
  1897. {
  1898. for (NSDictionary *userFound in usersArray) {
  1899. OCShareUser *user = [OCShareUser new];
  1900. if ([[userFound valueForKey:@"label"] isKindOfClass:[NSNumber class]]) {
  1901. NSNumber *number = [userFound valueForKey:@"label"];
  1902. user.displayName = [NSString stringWithFormat:@"%ld", number.longValue];
  1903. }else{
  1904. user.displayName = [userFound valueForKey:@"label"];
  1905. }
  1906. NSDictionary *userValues = [userFound valueForKey:@"value"];
  1907. if ([[userValues valueForKey:@"shareWith"] isKindOfClass:[NSNumber class]]) {
  1908. NSNumber *number = [userValues valueForKey:@"shareWith"];
  1909. user.name = [NSString stringWithFormat:@"%ld", number.longValue];
  1910. }else{
  1911. user.name = [userValues valueForKey:@"shareWith"];
  1912. }
  1913. user.shareeType = shareeType;
  1914. user.server = [userValues valueForKey:@"server"];
  1915. [itemList addObject:user];
  1916. }
  1917. }
  1918. - (void) addGroupItemFromArray:(NSArray*) groupsArray ToList: (NSMutableArray *) itemList
  1919. {
  1920. for (NSDictionary *groupFound in groupsArray) {
  1921. OCShareUser *group = [OCShareUser new];
  1922. NSDictionary *groupValues = [groupFound valueForKey:@"value"];
  1923. if ([[groupValues valueForKey:@"shareWith"] isKindOfClass:[NSNumber class]]) {
  1924. NSNumber *number = [groupValues valueForKey:@"shareWith"];
  1925. group.name = [NSString stringWithFormat:@"%ld", number.longValue];
  1926. }else{
  1927. group.name = [groupValues valueForKey:@"shareWith"];
  1928. }
  1929. group.shareeType = shareTypeGroup;
  1930. [itemList addObject:group];
  1931. }
  1932. }
  1933. @end