OCCommunication.m 188 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565
  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 <marino.faggiana@nextcloud.com>
  30. // Copyright (c) 2017 Marino Faggiana. All rights reserved.
  31. //
  32. #import "OCCommunication.h"
  33. #import "OCHTTPRequestOperation.h"
  34. #import "UtilsFramework.h"
  35. #import "OCXMLSharedParser.h"
  36. #import "OCXMLServerErrorsParser.h"
  37. #import "NSString+Encode.h"
  38. #import "OCFrameworkConstants.h"
  39. #import "OCWebDAVClient.h"
  40. #import "OCXMLShareByLinkParser.h"
  41. #import "OCErrorMsg.h"
  42. #import "OCShareUser.h"
  43. #import "OCActivity.h"
  44. #import "OCExternalSites.h"
  45. #import "OCCapabilities.h"
  46. #import "OCNotifications.h"
  47. #import "OCNotificationsAction.h"
  48. #import "OCRichObjectStrings.h"
  49. #import "OCUserProfile.h"
  50. #import "NCRichDocumentTemplate.h"
  51. #import "HCFeatures.h"
  52. #import "NCXMLCommentsParser.h"
  53. #import "NCXMLListParser.h"
  54. @interface OCCommunication ()
  55. @property (nonatomic, strong) NSString *currentServerVersion;
  56. @end
  57. @implementation OCCommunication
  58. -(id) init {
  59. self = [super init];
  60. if (self) {
  61. //Init the Donwload queue array
  62. self.downloadTaskNetworkQueueArray = [NSMutableArray new];
  63. //Credentials not set yet
  64. self.kindOfCredential = credentialNotSet;
  65. [self setSecurityPolicyManagers:[self createSecurityPolicy]];
  66. self.isCookiesAvailable = YES;
  67. self.isForbiddenCharactersAvailable = NO;
  68. #ifdef UNIT_TEST
  69. self.uploadSessionManager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
  70. self.downloadSessionManager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
  71. self.networkSessionManager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
  72. self.networkSessionManager.responseSerializer = [AFHTTPResponseSerializer serializer];
  73. #else
  74. //Network Upload queue for NSURLSession (iOS 7)
  75. NSURLSessionConfiguration *uploadConfiguration = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:k_session_name];
  76. uploadConfiguration.HTTPShouldUsePipelining = YES;
  77. uploadConfiguration.HTTPMaximumConnectionsPerHost = 1;
  78. uploadConfiguration.requestCachePolicy = NSURLRequestReloadIgnoringLocalCacheData;
  79. self.uploadSessionManager = [[AFURLSessionManager alloc] initWithSessionConfiguration:uploadConfiguration];
  80. [self.uploadSessionManager.operationQueue setMaxConcurrentOperationCount:1];
  81. //Network Download queue for NSURLSession (iOS 7)
  82. NSURLSessionConfiguration *downConfiguration = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:k_download_session_name];
  83. downConfiguration.HTTPShouldUsePipelining = YES;
  84. downConfiguration.HTTPMaximumConnectionsPerHost = 1;
  85. downConfiguration.requestCachePolicy = NSURLRequestReloadIgnoringLocalCacheData;
  86. self.downloadSessionManager = [[AFURLSessionManager alloc] initWithSessionConfiguration:downConfiguration];
  87. [self.downloadSessionManager.operationQueue setMaxConcurrentOperationCount:1];
  88. //Network Download queue for NSURLSession (iOS 7)
  89. NSURLSessionConfiguration *networkConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration];
  90. networkConfiguration.HTTPShouldUsePipelining = YES;
  91. networkConfiguration.HTTPMaximumConnectionsPerHost = 1;
  92. networkConfiguration.requestCachePolicy = NSURLRequestReloadIgnoringLocalCacheData;
  93. self.networkSessionManager = [[AFURLSessionManager alloc] initWithSessionConfiguration:networkConfiguration];
  94. [self.networkSessionManager.operationQueue setMaxConcurrentOperationCount:1];
  95. self.networkSessionManager.responseSerializer = [AFHTTPResponseSerializer serializer];
  96. #endif
  97. }
  98. return self;
  99. }
  100. -(id) initWithUploadSessionManager:(AFURLSessionManager *) uploadSessionManager {
  101. self = [super init];
  102. if (self) {
  103. //Init the Donwload queue array
  104. self.downloadTaskNetworkQueueArray = [NSMutableArray new];
  105. self.isCookiesAvailable = YES;
  106. self.isForbiddenCharactersAvailable = NO;
  107. //Credentials not set yet
  108. self.kindOfCredential = credentialNotSet;
  109. [self setSecurityPolicyManagers:[self createSecurityPolicy]];
  110. self.uploadSessionManager = uploadSessionManager;
  111. }
  112. return self;
  113. }
  114. -(id) initWithUploadSessionManager:(AFURLSessionManager *) uploadSessionManager andDownloadSessionManager:(AFURLSessionManager *) downloadSessionManager andNetworkSessionManager:(AFURLSessionManager *) networkSessionManager {
  115. self = [super init];
  116. if (self) {
  117. //Init the Donwload queue array
  118. self.downloadTaskNetworkQueueArray = [NSMutableArray new];
  119. //Credentials not set yet
  120. self.kindOfCredential = credentialNotSet;
  121. [self setSecurityPolicyManagers:[self createSecurityPolicy]];
  122. self.uploadSessionManager = uploadSessionManager;
  123. self.downloadSessionManager = downloadSessionManager;
  124. self.networkSessionManager = networkSessionManager;
  125. }
  126. return self;
  127. }
  128. - (AFSecurityPolicy *) createSecurityPolicy {
  129. return [AFSecurityPolicy defaultPolicy];
  130. }
  131. - (void)setSecurityPolicyManagers:(AFSecurityPolicy *)securityPolicy {
  132. self.securityPolicy = securityPolicy;
  133. self.uploadSessionManager.securityPolicy = securityPolicy;
  134. self.downloadSessionManager.securityPolicy = securityPolicy;
  135. }
  136. #pragma mark - Setting Credentials
  137. - (void) setCredentialsWithUser:(NSString*) user andUserID:(NSString *) userID andPassword:(NSString*) password {
  138. self.kindOfCredential = credentialNormal;
  139. self.user = user;
  140. self.userID = userID;
  141. self.password = password;
  142. }
  143. - (void) setCredentialsWithCookie:(NSString*) cookie {
  144. self.kindOfCredential = credentialCookie;
  145. self.password = cookie;
  146. }
  147. - (void) setCredentialsOauthWithToken:(NSString*) token {
  148. self.kindOfCredential = credentialOauth;
  149. self.password = token;
  150. }
  151. - (void) setupNextcloudVersion:(NSInteger) version
  152. {
  153. self.nextcloudVersion = version;
  154. }
  155. ///-----------------------------------
  156. /// @name getRequestWithCredentials
  157. ///-----------------------------------
  158. /**
  159. * Method to return the request with the right credential
  160. *
  161. * @param OCWebDAVClient like a dinamic typed
  162. *
  163. * @return OCWebDAVClient like a dinamic typed
  164. *
  165. */
  166. - (id) getRequestWithCredentials:(id) request {
  167. if ([request isKindOfClass:[NSMutableURLRequest class]]) {
  168. NSMutableURLRequest *myRequest = (NSMutableURLRequest *)request;
  169. switch (self.kindOfCredential) {
  170. case credentialNotSet:
  171. //Without credentials
  172. break;
  173. case credentialNormal:
  174. {
  175. NSString *basicAuthCredentials = [NSString stringWithFormat:@"%@:%@", self.user, self.password];
  176. [myRequest addValue:[NSString stringWithFormat:@"Basic %@", [UtilsFramework AFBase64EncodedStringFromString:basicAuthCredentials]] forHTTPHeaderField:@"Authorization"];
  177. break;
  178. }
  179. case credentialCookie:
  180. NSLog(@"Cookie: %@", self.password);
  181. [myRequest addValue:self.password forHTTPHeaderField:@"Cookie"];
  182. break;
  183. case credentialOauth:
  184. [myRequest addValue:[NSString stringWithFormat:@"Bearer %@", self.password] forHTTPHeaderField:@"Authorization"];
  185. break;
  186. default:
  187. break;
  188. }
  189. if (self.userAgent) {
  190. [myRequest addValue:self.userAgent forHTTPHeaderField:@"User-Agent"];
  191. }
  192. return myRequest;
  193. } else if([request isKindOfClass:[OCWebDAVClient class]]) {
  194. OCWebDAVClient *myRequest = (OCWebDAVClient *)request;
  195. switch (self.kindOfCredential) {
  196. case credentialNotSet:
  197. //Without credentials
  198. break;
  199. case credentialNormal:
  200. [myRequest setAuthorizationHeaderWithUsername:self.user password:self.password];
  201. break;
  202. case credentialCookie:
  203. [myRequest setAuthorizationHeaderWithCookie:self.password];
  204. break;
  205. case credentialOauth:
  206. [myRequest setAuthorizationHeaderWithToken:[NSString stringWithFormat:@"Bearer %@", self.password]];
  207. break;
  208. default:
  209. break;
  210. }
  211. if (self.userAgent) {
  212. [myRequest setUserAgent:self.userAgent];
  213. }
  214. return request;
  215. } else {
  216. NSLog(@"We do not know witch kind of object is");
  217. return request;
  218. }
  219. }
  220. #pragma mark - WebDav network Operations
  221. ///-----------------------------------
  222. /// @name Check Server
  223. ///-----------------------------------
  224. - (void) checkServer: (NSString *) path
  225. onCommunication:(OCCommunication *)sharedOCCommunication
  226. successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer)) successRequest
  227. failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
  228. OCWebDAVClient *request = [OCWebDAVClient new];
  229. request = [self getRequestWithCredentials:request];
  230. if (self.userAgent) {
  231. [request setUserAgent:self.userAgent];
  232. }
  233. path = [path encodeString:NSUTF8StringEncoding];
  234. [request checkServer:path onCommunication:sharedOCCommunication
  235. success:^(NSHTTPURLResponse *response, id responseObject) {
  236. if (successRequest) {
  237. successRequest(response, request.redirectedServer);
  238. }
  239. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  240. failureRequest(response, error, request.redirectedServer);
  241. }];
  242. }
  243. ///-----------------------------------
  244. /// @name Create a folder
  245. ///-----------------------------------
  246. - (void) createFolder: (NSString *) path
  247. onCommunication:(OCCommunication *)sharedOCCommunication withForbiddenCharactersSupported:(BOOL)isFCSupported
  248. successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer)) successRequest
  249. failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest
  250. errorBeforeRequest:(void(^)(NSError *error)) errorBeforeRequest {
  251. if ([UtilsFramework isForbiddenCharactersInFileName:[UtilsFramework getFileNameOrFolderByPath:path] withForbiddenCharactersSupported:isFCSupported]) {
  252. NSError *error = [UtilsFramework getErrorByCodeId:OCErrorForbidenCharacters];
  253. errorBeforeRequest(error);
  254. } else {
  255. OCWebDAVClient *request = [OCWebDAVClient new];
  256. request = [self getRequestWithCredentials:request];
  257. path = [path encodeString:NSUTF8StringEncoding];
  258. [request makeCollection:path onCommunication:sharedOCCommunication
  259. success:^(NSHTTPURLResponse *response, id responseObject) {
  260. if (successRequest) {
  261. successRequest(response, request.redirectedServer);
  262. }
  263. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  264. OCXMLServerErrorsParser *serverErrorParser = [OCXMLServerErrorsParser new];
  265. [serverErrorParser startToParseWithData:responseData withCompleteBlock:^(NSError *err) {
  266. if (err) {
  267. failureRequest(response, err, request.redirectedServer);
  268. }else{
  269. failureRequest(response, error, request.redirectedServer);
  270. }
  271. }];
  272. }];
  273. }
  274. }
  275. ///-----------------------------------
  276. /// @name Move a file or a folder
  277. ///-----------------------------------
  278. - (void) moveFileOrFolder:(NSString *)sourcePath
  279. toDestiny:(NSString *)destinyPath
  280. onCommunication:(OCCommunication *)sharedOCCommunication withForbiddenCharactersSupported:(BOOL)isFCSupported
  281. successRequest:(void (^)(NSHTTPURLResponse *response, NSString *redirectServer))successRequest
  282. failureRequest:(void (^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer))failureRequest
  283. errorBeforeRequest:(void (^)(NSError *error))errorBeforeRequest {
  284. if ([UtilsFramework isTheSameFileOrFolderByNewURLString:destinyPath andOriginURLString:sourcePath]) {
  285. //We check that we are not trying to move the file to the same place
  286. NSError *error = [UtilsFramework getErrorByCodeId:OCErrorMovingTheDestinyAndOriginAreTheSame];
  287. errorBeforeRequest(error);
  288. } else if ([UtilsFramework isAFolderUnderItByNewURLString:destinyPath andOriginURLString:sourcePath]) {
  289. //We check we are not trying to move a folder inside himself
  290. NSError *error = [UtilsFramework getErrorByCodeId:OCErrorMovingFolderInsideHimself];
  291. errorBeforeRequest(error);
  292. } else if ([UtilsFramework isForbiddenCharactersInFileName:[UtilsFramework getFileNameOrFolderByPath:destinyPath] withForbiddenCharactersSupported:isFCSupported]) {
  293. //We check that we are making a move not a rename to prevent special characters problems
  294. NSError *error = [UtilsFramework getErrorByCodeId:OCErrorMovingDestinyNameHaveForbiddenCharacters];
  295. errorBeforeRequest(error);
  296. } else {
  297. sourcePath = [sourcePath encodeString:NSUTF8StringEncoding];
  298. destinyPath = [destinyPath encodeString:NSUTF8StringEncoding];
  299. OCWebDAVClient *request = [OCWebDAVClient new];
  300. request = [self getRequestWithCredentials:request];
  301. [request movePath:sourcePath toPath:destinyPath onCommunication:sharedOCCommunication success:^(NSHTTPURLResponse *response, id responseObject) {
  302. if (successRequest) {
  303. successRequest(response, request.redirectedServer);
  304. }
  305. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  306. OCXMLServerErrorsParser *serverErrorParser = [OCXMLServerErrorsParser new];
  307. [serverErrorParser startToParseWithData:responseData withCompleteBlock:^(NSError *err) {
  308. if (err) {
  309. failureRequest(response, err, request.redirectedServer);
  310. }else{
  311. failureRequest(response, error, request.redirectedServer);
  312. }
  313. }];
  314. }];
  315. }
  316. }
  317. ///-----------------------------------
  318. /// @name Delete a file or a folder
  319. ///-----------------------------------
  320. - (void) deleteFileOrFolder:(NSString *)path
  321. onCommunication:(OCCommunication *)sharedOCCommunication
  322. successRequest:(void (^)(NSHTTPURLResponse *response, NSString *redirectedServer))successRequest
  323. failureRquest:(void (^)(NSHTTPURLResponse *resposne, NSError *error, NSString *redirectedServer))failureRequest {
  324. path = [path encodeString:NSUTF8StringEncoding];
  325. OCWebDAVClient *request = [OCWebDAVClient new];
  326. request = [self getRequestWithCredentials:request];
  327. [request deletePath:path onCommunication:sharedOCCommunication success:^(NSHTTPURLResponse *response, id responseObject) {
  328. if (successRequest) {
  329. successRequest(response, request.redirectedServer);
  330. }
  331. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  332. failureRequest(response, error, request.redirectedServer);
  333. }];
  334. }
  335. ///-----------------------------------
  336. /// @name Read folder
  337. ///-----------------------------------
  338. - (void) readFolder: (NSString *) path depth:(NSString *)depth withUserSessionToken:(NSString *)token
  339. onCommunication:(OCCommunication *)sharedOCCommunication
  340. successRequest:(void(^)(NSHTTPURLResponse *response, NSArray *items, NSString *redirectedServer, NSString *token)) successRequest
  341. failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *token, NSString *redirectedServer)) failureRequest{
  342. if (!token){
  343. token = @"no token";
  344. }
  345. path = [path encodeString:NSUTF8StringEncoding];
  346. OCWebDAVClient *request = [OCWebDAVClient new];
  347. request = [self getRequestWithCredentials:request];
  348. [request listPath:path depth:depth onCommunication:sharedOCCommunication withUserSessionToken:token success:^(NSHTTPURLResponse *response, id responseObject, NSString *token) {
  349. if (successRequest) {
  350. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  351. NSData *responseData = (NSData*) responseObject;
  352. // NSString* newStr = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
  353. // NSLog(@"newStrReadFolder: %@", newStr);
  354. NCXMLListParser *parser = [NCXMLListParser new];
  355. [parser initParserWithData:responseData controlFirstFileOfList:true];
  356. NSMutableArray *list = [parser.list mutableCopy];
  357. dispatch_async(dispatch_get_main_queue(), ^{
  358. successRequest(response, list, request.redirectedServer, token);
  359. });
  360. });
  361. }
  362. } failure:^(NSHTTPURLResponse *response, id responseData, NSError *error, NSString *token) {
  363. NSLog(@"Failure");
  364. failureRequest(response, error, token, request.redirectedServer);
  365. }];
  366. }
  367. ///-----------------------------------
  368. /// @name Read File
  369. ///-----------------------------------
  370. - (void) readFile: (NSString *) path
  371. onCommunication:(OCCommunication *)sharedOCCommunication
  372. successRequest:(void(^)(NSHTTPURLResponse *response, NSArray *items, NSString *redirectedServer)) successRequest
  373. failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
  374. path = [path encodeString:NSUTF8StringEncoding];
  375. OCWebDAVClient *request = [OCWebDAVClient new];
  376. request = [self getRequestWithCredentials:request];
  377. [request propertiesOfPath:path onCommunication:sharedOCCommunication success:^(NSHTTPURLResponse *response, id responseObject) {
  378. if (successRequest) {
  379. if (successRequest) {
  380. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  381. NSData *responseData = (NSData*) responseObject;
  382. // NSString* newStr = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
  383. // NSLog(@"newStrReadFolder: %@", newStr);
  384. NCXMLListParser *parser = [NCXMLListParser new];
  385. [parser initParserWithData:responseData controlFirstFileOfList:true];
  386. NSMutableArray *list = [parser.list mutableCopy];
  387. dispatch_async(dispatch_get_main_queue(), ^{
  388. successRequest(response, list, request.redirectedServer);
  389. });
  390. });
  391. }
  392. }
  393. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  394. failureRequest(response, error, request.redirectedServer);
  395. }];
  396. }
  397. ///-----------------------------------
  398. /// @name search
  399. ///-----------------------------------
  400. - (void)search:(NSString *)path folder:(NSString *)folder fileName:(NSString *)fileName depth:(NSString *)depth lteDateLastModified:(NSString *)lteDateLastModified gteDateLastModified:(NSString *)gteDateLastModified contentType:(NSArray *)contentType withUserSessionToken:(NSString *)token onCommunication:(OCCommunication *)sharedOCCommunication successRequest:(void(^)(NSHTTPURLResponse *response, NSArray *items, NSString *redirectedServer, NSString *token)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *token, NSString *redirectedServer)) failureRequest{
  401. if (!token){
  402. token = @"no token";
  403. }
  404. path = [path encodeString:NSUTF8StringEncoding];
  405. OCWebDAVClient *request = [OCWebDAVClient new];
  406. request = [self getRequestWithCredentials:request];
  407. [request search:path folder:folder fileName:fileName depth:depth lteDateLastModified:lteDateLastModified gteDateLastModified:gteDateLastModified contentType:contentType user:_user userID:_userID onCommunication:sharedOCCommunication withUserSessionToken:token success:^(NSHTTPURLResponse *response, id responseObject, NSString *token) {
  408. if (successRequest) {
  409. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
  410. NSData *responseData = (NSData*) responseObject;
  411. NCXMLListParser *parser = [NCXMLListParser new];
  412. [parser initParserWithData:responseData controlFirstFileOfList:false];
  413. NSMutableArray *list = [parser.list mutableCopy];
  414. dispatch_async(dispatch_get_main_queue(), ^{
  415. successRequest(response, list, request.redirectedServer, token);
  416. });
  417. });
  418. }
  419. } failure:^(NSHTTPURLResponse *response, id responseData, NSError *error, NSString *token) {
  420. failureRequest(response, error, token, request.redirectedServer);
  421. }];
  422. }
  423. - (void)search:(NSString *)path folder:(NSString *)folder fileName:(NSString *)fileName dateLastModified:(NSString *)dateLastModified numberOfItem:(NSInteger)numberOfItem withUserSessionToken:(NSString *)token onCommunication:(OCCommunication *)sharedOCCommunication successRequest:(void(^)(NSHTTPURLResponse *response, NSArray *items, NSString *redirectedServer, NSString *token)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *token, NSString *redirectedServer)) failureRequest {
  424. if (!token){
  425. token = @"no token";
  426. }
  427. path = [path encodeString:NSUTF8StringEncoding];
  428. OCWebDAVClient *request = [OCWebDAVClient new];
  429. request = [self getRequestWithCredentials:request];
  430. [request search:path folder:folder fileName:fileName dateLastModified:dateLastModified numberOfItem:numberOfItem userID:_userID onCommunication:sharedOCCommunication withUserSessionToken:token success:^(NSHTTPURLResponse *response, id responseObject, NSString *token) {
  431. if (successRequest) {
  432. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
  433. NSData *responseData = (NSData*) responseObject;
  434. NCXMLListParser *parser = [NCXMLListParser new];
  435. [parser initParserWithData:responseData controlFirstFileOfList:false];
  436. NSMutableArray *list = [parser.list mutableCopy];
  437. dispatch_async(dispatch_get_main_queue(), ^{
  438. successRequest(response, list, request.redirectedServer, token);
  439. });
  440. });
  441. }
  442. } failure:^(NSHTTPURLResponse *response, id responseData, NSError *error, NSString *token) {
  443. failureRequest(response, error, token, request.redirectedServer);
  444. }];
  445. }
  446. ///-----------------------------------
  447. /// @name Setting favorite
  448. ///-----------------------------------
  449. - (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 {
  450. if (!token){
  451. token = @"no token";
  452. }
  453. path = [NSString stringWithFormat:@"%@/files/%@/%@", path, _userID, filePath];
  454. path = [path encodeString:NSUTF8StringEncoding];
  455. OCWebDAVClient *request = [OCWebDAVClient new];
  456. request = [self getRequestWithCredentials:request];
  457. [request settingFavorite:path favorite:favorite onCommunication:sharedOCCommunication withUserSessionToken:token success:^(NSHTTPURLResponse *response, id responseObject, NSString *token) {
  458. if (successRequest) {
  459. //Return success
  460. successRequest(response, request.redirectedServer, token);
  461. }
  462. } failure:^(NSHTTPURLResponse *response, id responseData, NSError *error, NSString *token) {
  463. NSLog(@"Failure");
  464. failureRequest(response, error, token, request.redirectedServer);
  465. }];
  466. }
  467. ///-----------------------------------
  468. /// @name Listing favorites
  469. ///-----------------------------------
  470. - (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{
  471. if (!token){
  472. token = @"no token";
  473. }
  474. path = [path encodeString:NSUTF8StringEncoding];
  475. OCWebDAVClient *request = [OCWebDAVClient new];
  476. request = [self getRequestWithCredentials:request];
  477. [request listingFavorites:path folder:folder user:_user userID:_userID onCommunication:sharedOCCommunication withUserSessionToken:token success:^(NSHTTPURLResponse *response, id responseObject, NSString *token) {
  478. if (successRequest) {
  479. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
  480. NSData *responseData = (NSData*) responseObject;
  481. NCXMLListParser *parser = [NCXMLListParser new];
  482. [parser initParserWithData:responseData controlFirstFileOfList:false];
  483. NSMutableArray *list = [parser.list mutableCopy];
  484. dispatch_async(dispatch_get_main_queue(), ^{
  485. successRequest(response, list, request.redirectedServer, token);
  486. });
  487. });
  488. }
  489. } failure:^(NSHTTPURLResponse *response, id responseData, NSError *error, NSString *token) {
  490. failureRequest(response, error, token, request.redirectedServer);
  491. }];
  492. }
  493. ///-----------------------------------
  494. /// @name Download File Session
  495. ///-----------------------------------
  496. - (NSURLSessionDownloadTask *) downloadFileSession:(NSString *)remotePath toDestiny:(NSString *)localPath defaultPriority:(BOOL)defaultPriority encode:(BOOL)encode onCommunication:(OCCommunication *)sharedOCCommunication progress:(void(^)(NSProgress *progress))downloadProgress successRequest:(void(^)(NSURLResponse *response, NSURL *filePath)) successRequest failureRequest:(void(^)(NSURLResponse *response, NSError *error)) failureRequest {
  497. OCWebDAVClient *request = [OCWebDAVClient new];
  498. request = [self getRequestWithCredentials:request];
  499. if (encode) remotePath = [remotePath encodeString:NSUTF8StringEncoding];
  500. NSURLSessionDownloadTask *downloadTask = [request downloadWithSessionPath:remotePath toPath:localPath defaultPriority:defaultPriority onCommunication:sharedOCCommunication progress:^(NSProgress *progress) {
  501. downloadProgress(progress);
  502. } success:^(NSURLResponse *response, NSURL *filePath) {
  503. [UtilsFramework addCookiesToStorageFromResponse:(NSURLResponse *) response andPath:[NSURL URLWithString:remotePath]];
  504. successRequest(response,filePath);
  505. } failure:^(NSURLResponse *response, NSError *error) {
  506. [UtilsFramework addCookiesToStorageFromResponse:(NSURLResponse *) response andPath:[NSURL URLWithString:remotePath]];
  507. failureRequest(response,error);
  508. }];
  509. return downloadTask;
  510. }
  511. ///-----------------------------------
  512. /// @name Set Download Task Complete Block
  513. ///-----------------------------------
  514. - (void)setDownloadTaskComleteBlock: (NSURL * (^)(NSURLSession *session, NSURLSessionDownloadTask *downloadTask, NSURL *location))block{
  515. [self.downloadSessionManager setDownloadTaskDidFinishDownloadingBlock:block];
  516. }
  517. ///-----------------------------------
  518. /// @name Set Download Task Did Get Body Data Block
  519. ///-----------------------------------
  520. - (void) setDownloadTaskDidGetBodyDataBlock: (void(^)(NSURLSession *session, NSURLSessionDownloadTask *downloadTask, int64_t bytesWritten, int64_t totalBytesWritten, int64_t totalBytesExpectedToWrite)) block{
  521. [self.downloadSessionManager setDownloadTaskDidWriteDataBlock:^(NSURLSession *session, NSURLSessionDownloadTask *downloadTask, int64_t bytesWritten, int64_t totalBytesWritten, int64_t totalBytesExpectedToWrite) {
  522. block(session,downloadTask,bytesWritten,totalBytesWritten,totalBytesExpectedToWrite);
  523. }];
  524. }
  525. ///-----------------------------------
  526. /// @name Upload File Session
  527. ///-----------------------------------
  528. - (NSURLSessionUploadTask *) uploadFileSession:(NSString *) localPath toDestiny:(NSString *) remotePath encode:(BOOL)encode onCommunication:(OCCommunication *)sharedOCCommunication progress:(void(^)(NSProgress *progress))uploadProgress successRequest:(void(^)(NSURLResponse *response, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSURLResponse *response, NSString *redirectedServer, NSError *error)) failureRequest failureBeforeRequest:(void(^)(NSError *error)) failureBeforeRequest {
  529. OCWebDAVClient *request = [OCWebDAVClient new];
  530. request = [self getRequestWithCredentials:request];
  531. if (encode) remotePath = [remotePath encodeString:NSUTF8StringEncoding];
  532. NSURLSessionUploadTask *uploadTask = [request putWithSessionLocalPath:localPath atRemotePath:remotePath onCommunication:sharedOCCommunication progress:^(NSProgress *progress) {
  533. uploadProgress(progress);
  534. } success:^(NSURLResponse *response, id responseObjec){
  535. [UtilsFramework addCookiesToStorageFromResponse:(NSURLResponse *) response andPath:[NSURL URLWithString:remotePath]];
  536. //TODO: The second parameter is the redirected server
  537. successRequest(response, @"");
  538. } failure:^(NSURLResponse *response, id responseObject, NSError *error) {
  539. [UtilsFramework addCookiesToStorageFromResponse:(NSURLResponse *) response andPath:[NSURL URLWithString:remotePath]];
  540. //TODO: The second parameter is the redirected server
  541. NSData *responseData = (NSData*) responseObject;
  542. OCXMLServerErrorsParser *serverErrorParser = [OCXMLServerErrorsParser new];
  543. [serverErrorParser startToParseWithData:responseData withCompleteBlock:^(NSError *err) {
  544. if (err) {
  545. failureRequest(response, @"", err);
  546. }else{
  547. failureRequest(response, @"", error);
  548. }
  549. }];
  550. } failureBeforeRequest:^(NSError *error) {
  551. failureBeforeRequest(error);
  552. }];
  553. return uploadTask;
  554. }
  555. ///-----------------------------------
  556. /// @name Set Task Did Complete Block
  557. ///-----------------------------------
  558. - (void) setTaskDidCompleteBlock: (void(^)(NSURLSession *session, NSURLSessionTask *task, NSError *error)) block{
  559. [self.uploadSessionManager setTaskDidCompleteBlock:^(NSURLSession *session, NSURLSessionTask *task, NSError *error) {
  560. block(session, task, error);
  561. }];
  562. }
  563. ///-----------------------------------
  564. /// @name Set Task Did Send Body Data Block
  565. ///-----------------------------------
  566. - (void) setTaskDidSendBodyDataBlock: (void(^)(NSURLSession *session, NSURLSessionTask *task, int64_t bytesSent, int64_t totalBytesSent, int64_t totalBytesExpectedToSend)) block{
  567. [self.uploadSessionManager setTaskDidSendBodyDataBlock:^(NSURLSession *session, NSURLSessionTask *task, int64_t bytesSent, int64_t totalBytesSent, int64_t totalBytesExpectedToSend) {
  568. block(session, task, bytesSent, totalBytesSent, totalBytesExpectedToSend);
  569. }];
  570. }
  571. #pragma mark - OC/NC API Calls
  572. - (NSString *) getCurrentServerVersion {
  573. return self.currentServerVersion;
  574. }
  575. - (void) getServerVersionWithPath:(NSString*) path onCommunication:(OCCommunication *)sharedOCCommunication
  576. successRequest:(void(^)(NSHTTPURLResponse *response, NSString *serverVersion, NSString *redirectedServer)) success
  577. failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failure{
  578. OCWebDAVClient *request = [OCWebDAVClient new];
  579. if (self.userAgent) {
  580. [request setUserAgent:self.userAgent];
  581. }
  582. [request getStatusOfTheServer:path onCommunication:sharedOCCommunication success:^(NSHTTPURLResponse *response, id responseObject) {
  583. NSData *data = (NSData*) responseObject;
  584. NSString *versionString = [NSString new];
  585. NSError* error=nil;
  586. if (data) {
  587. NSMutableDictionary *jsonArray = [NSJSONSerialization JSONObjectWithData: data options: NSJSONReadingMutableContainers error: &error];
  588. if(error) {
  589. NSLog(@"Error parsing JSON: %@", error);
  590. } else {
  591. //Obtain the server version from the version field
  592. versionString = [jsonArray valueForKey:@"version"];
  593. self.currentServerVersion = versionString;
  594. }
  595. } else {
  596. NSLog(@"Error parsing JSON: data is null");
  597. }
  598. success(response, versionString, request.redirectedServer);
  599. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  600. failure(response, error, request.redirectedServer);
  601. }];
  602. }
  603. ///-----------------------------------
  604. /// @name Get UserName by cookie
  605. ///-----------------------------------
  606. - (void) getUserNameByCookie:(NSString *) cookieString ofServerPath:(NSString *)path onCommunication:
  607. (OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *response, NSData *responseData, NSString *redirectedServer))success
  608. failure:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer))failure{
  609. OCWebDAVClient *request = [OCWebDAVClient new];
  610. request = [self getRequestWithCredentials:request];
  611. [request requestUserNameOfServer: path byCookie:cookieString onCommunication:sharedOCCommunication success:^(NSHTTPURLResponse *response, id responseObject) {
  612. success(response, responseObject, request.redirectedServer);
  613. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  614. failure(response, error, request.redirectedServer);
  615. }];
  616. }
  617. - (void) getFeaturesSupportedByServer:(NSString*) path onCommunication:(OCCommunication *)sharedOCCommunication
  618. successRequest:(void(^)(NSHTTPURLResponse *response, BOOL hasShareSupport, BOOL hasShareeSupport, BOOL hasCookiesSupport, BOOL hasForbiddenCharactersSupport, BOOL hasCapabilitiesSupport, BOOL hasFedSharesOptionShareSupport, NSString *redirectedServer)) success
  619. failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failure{
  620. OCWebDAVClient *request = [OCWebDAVClient new];
  621. if (self.userAgent) {
  622. [request setUserAgent:self.userAgent];
  623. }
  624. [request getStatusOfTheServer:path onCommunication:sharedOCCommunication success:^(NSHTTPURLResponse *response, id responseObject) {
  625. if (responseObject) {
  626. NSError* error = nil;
  627. NSMutableDictionary *jsonArray = [NSJSONSerialization JSONObjectWithData: (NSData*) responseObject options: NSJSONReadingMutableContainers error: &error];
  628. if(error) {
  629. // NSLog(@"Error parsing JSON: %@", error);
  630. failure(response, error, request.redirectedServer);
  631. }else{
  632. self.currentServerVersion = [jsonArray valueForKey:@"version"];
  633. BOOL hasShareSupport = [UtilsFramework isServerVersion:self.currentServerVersion higherThanLimitVersion:k_version_support_shared];
  634. BOOL hasShareeSupport = [UtilsFramework isServerVersion:self.currentServerVersion higherThanLimitVersion:k_version_support_sharee_api];
  635. BOOL hasCookiesSupport = [UtilsFramework isServerVersion:self.currentServerVersion higherThanLimitVersion:k_version_support_cookies];
  636. BOOL hasForbiddenCharactersSupport = [UtilsFramework isServerVersion:self.currentServerVersion higherThanLimitVersion:k_version_support_forbidden_characters];
  637. BOOL hasCapabilitiesSupport = [UtilsFramework isServerVersion:self.currentServerVersion higherThanLimitVersion:k_version_support_capabilities];
  638. BOOL hasFedSharesOptionShareSupport = [UtilsFramework isServerVersion:self.currentServerVersion higherThanLimitVersion:k_version_support_share_option_fed_share];
  639. success(response, hasShareSupport, hasShareeSupport, hasCookiesSupport, hasForbiddenCharactersSupport, hasCapabilitiesSupport, hasFedSharesOptionShareSupport, request.redirectedServer);
  640. }
  641. } else {
  642. // NSLog(@"Error parsing JSON: data is null");
  643. failure(response, nil, request.redirectedServer);
  644. }
  645. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  646. failure(response, error, request.redirectedServer);
  647. }];
  648. }
  649. #pragma mark - Share
  650. - (void) readSharedByServer: (NSString *) path
  651. onCommunication:(OCCommunication *)sharedOCCommunication
  652. successRequest:(void(^)(NSHTTPURLResponse *response, NSArray *listOfShared, NSString *redirectedServer)) successRequest
  653. failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
  654. path = [path encodeString:NSUTF8StringEncoding];
  655. path = [path stringByAppendingString:k_url_acces_shared_api];
  656. OCWebDAVClient *request = [OCWebDAVClient new];
  657. request = [self getRequestWithCredentials:request];
  658. [request listSharedByServer:path onCommunication:sharedOCCommunication success:^(NSHTTPURLResponse *response, id responseObject) {
  659. if (successRequest) {
  660. NSData *responseData = (NSData*) responseObject;
  661. OCXMLSharedParser *parser = [[OCXMLSharedParser alloc]init];
  662. //NSLog(@"response: %@", [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]);
  663. [parser initParserWithData:responseData];
  664. NSMutableArray *sharedList = [parser.shareList mutableCopy];
  665. //Return success
  666. successRequest(response, sharedList, request.redirectedServer);
  667. }
  668. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  669. failureRequest(response, error, request.redirectedServer);
  670. }];
  671. }
  672. - (void) readSharedByServer: (NSString *) serverPath andPath: (NSString *) path
  673. onCommunication:(OCCommunication *)sharedOCCommunication
  674. successRequest:(void(^)(NSHTTPURLResponse *response, NSArray *listOfShared, NSString *redirectedServer)) successRequest
  675. failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
  676. serverPath = [serverPath encodeString:NSUTF8StringEncoding];
  677. serverPath = [serverPath stringByAppendingString:k_url_acces_shared_api];
  678. path = [path encodeString:NSUTF8StringEncoding];
  679. OCWebDAVClient *request = [OCWebDAVClient new];
  680. request = [self getRequestWithCredentials:request];
  681. [request listSharedByServer:serverPath andPath:path onCommunication:sharedOCCommunication success:^(NSHTTPURLResponse *response, id responseObject) {
  682. if (successRequest) {
  683. NSData *responseData = (NSData*) responseObject;
  684. OCXMLSharedParser *parser = [[OCXMLSharedParser alloc]init];
  685. // NSString *str = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
  686. // NSLog(@"responseDataReadSharedByServer:andPath: %@", str);
  687. // NSLog(@"pathFolders: %@", path);
  688. // NSLog(@"serverPath: %@", serverPath);
  689. [parser initParserWithData:responseData];
  690. NSMutableArray *sharedList = [parser.shareList mutableCopy];
  691. //Return success
  692. successRequest(response, sharedList, request.redirectedServer);
  693. }
  694. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  695. failureRequest(response, error, request.redirectedServer);
  696. }];
  697. }
  698. - (void) shareFileOrFolderByServer: (NSString *) serverPath andFileOrFolderPath: (NSString *) filePath andPassword:(NSString *)password andPermission:(NSInteger)permission andHideDownload:(BOOL)hideDownload
  699. onCommunication:(OCCommunication *)sharedOCCommunication
  700. successRequest:(void(^)(NSHTTPURLResponse *response, NSString *token, NSString *redirectedServer)) successRequest
  701. failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
  702. serverPath = [serverPath encodeString:NSUTF8StringEncoding];
  703. serverPath = [serverPath stringByAppendingString:k_url_acces_shared_api];
  704. OCWebDAVClient *request = [OCWebDAVClient new];
  705. request = [self getRequestWithCredentials:request];
  706. [request shareByLinkFileOrFolderByServer:serverPath andPath:filePath andPassword:password andPermission:permission andHideDownload:hideDownload onCommunication:sharedOCCommunication success:^(NSHTTPURLResponse *response, id responseObject) {
  707. NSData *responseData = (NSData*) responseObject;
  708. OCXMLShareByLinkParser *parser = [[OCXMLShareByLinkParser alloc]init];
  709. // NSLog(@"response: %@", [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding]);
  710. [parser initParserWithData:responseData];
  711. if (parser.statusCode == kOCSharedAPISuccessful || parser.statusCode == kOCShareeAPISuccessful) {
  712. NSString *url = parser.url;
  713. NSString *token = parser.token;
  714. if (url != nil) {
  715. successRequest(response, url, request.redirectedServer);
  716. } else if (token != nil) {
  717. //We remove the \n and the empty spaces " "
  718. token = [token stringByReplacingOccurrencesOfString:@"\n" withString:@""];
  719. token = [token stringByReplacingOccurrencesOfString:@" " withString:@""];
  720. successRequest(response, token, request.redirectedServer);
  721. } else {
  722. NSError *error = [UtilsFramework getErrorWithCode:parser.statusCode andCustomMessageFromTheServer:parser.message];
  723. failureRequest(response, error, request.redirectedServer);
  724. }
  725. } else {
  726. NSError *error = [UtilsFramework getErrorWithCode:parser.statusCode andCustomMessageFromTheServer:parser.message];
  727. failureRequest(response, error, request.redirectedServer);
  728. }
  729. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  730. failureRequest(response, error, request.redirectedServer);
  731. }];
  732. }
  733. - (void) shareFileOrFolderByServer: (NSString *) serverPath andFileOrFolderPath: (NSString *) filePath
  734. onCommunication:(OCCommunication *)sharedOCCommunication
  735. successRequest:(void(^)(NSHTTPURLResponse *response, NSString *shareLink, NSString *redirectedServer)) successRequest
  736. failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
  737. serverPath = [serverPath encodeString:NSUTF8StringEncoding];
  738. serverPath = [serverPath stringByAppendingString:k_url_acces_shared_api];
  739. OCWebDAVClient *request = [OCWebDAVClient new];
  740. request = [self getRequestWithCredentials:request];
  741. [request shareByLinkFileOrFolderByServer:serverPath andPath:filePath onCommunication:sharedOCCommunication success:^(NSHTTPURLResponse *response, id responseObject) {
  742. NSData *responseData = (NSData*) responseObject;
  743. OCXMLShareByLinkParser *parser = [[OCXMLShareByLinkParser alloc]init];
  744. // NSLog(@"response: %@", [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding]);
  745. [parser initParserWithData:responseData];
  746. if (parser.statusCode == kOCSharedAPISuccessful || parser.statusCode == kOCShareeAPISuccessful) {
  747. NSString *url = parser.url;
  748. NSString *token = parser.token;
  749. if (url != nil) {
  750. successRequest(response, url, request.redirectedServer);
  751. } else if (token != nil) {
  752. //We remove the \n and the empty spaces " "
  753. token = [token stringByReplacingOccurrencesOfString:@"\n" withString:@""];
  754. token = [token stringByReplacingOccurrencesOfString:@" " withString:@""];
  755. successRequest(response, token, request.redirectedServer);
  756. } else {
  757. NSError *error = [UtilsFramework getErrorWithCode:parser.statusCode andCustomMessageFromTheServer:parser.message];
  758. failureRequest(response, error, request.redirectedServer);
  759. }
  760. } else {
  761. NSError *error = [UtilsFramework getErrorWithCode:parser.statusCode andCustomMessageFromTheServer:parser.message];
  762. failureRequest(response, error, request.redirectedServer);
  763. }
  764. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  765. failureRequest(response, error, request.redirectedServer);
  766. }];
  767. }
  768. - (void)shareWith:(NSString *)userOrGroup shareeType:(NSInteger)shareeType inServer:(NSString *) serverPath andFileOrFolderPath:(NSString *) filePath andPermissions:(NSInteger) permissions onCommunication:(OCCommunication *)sharedOCCommunication
  769. successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer))successRequest
  770. failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer))failureRequest{
  771. serverPath = [serverPath encodeString:NSUTF8StringEncoding];
  772. serverPath = [serverPath stringByAppendingString:k_url_acces_shared_api];
  773. userOrGroup = [userOrGroup encodeString:NSUTF8StringEncoding];
  774. OCWebDAVClient *request = [OCWebDAVClient new];
  775. request = [self getRequestWithCredentials:request];
  776. [request shareWith:userOrGroup shareeType:shareeType inServer:serverPath andPath:filePath andPermissions:permissions onCommunication:sharedOCCommunication success:^(NSHTTPURLResponse *response, id responseObject) {
  777. NSData *responseData = (NSData*) responseObject;
  778. OCXMLShareByLinkParser *parser = [[OCXMLShareByLinkParser alloc]init];
  779. // NSLog(@"response: %@", [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding]);
  780. [parser initParserWithData:responseData];
  781. if (parser.statusCode == kOCSharedAPISuccessful || parser.statusCode == kOCShareeAPISuccessful) {
  782. successRequest(response, request.redirectedServer);
  783. } else {
  784. NSError *error = [UtilsFramework getErrorWithCode:parser.statusCode andCustomMessageFromTheServer:parser.message];
  785. failureRequest(response, error, request.redirectedServer);
  786. }
  787. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  788. failureRequest(response, error, request.redirectedServer);
  789. }];
  790. }
  791. - (void) unShareFileOrFolderByServer: (NSString *) path andIdRemoteShared: (NSInteger) idRemoteShared
  792. onCommunication:(OCCommunication *)sharedOCCommunication
  793. successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer)) successRequest
  794. failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest{
  795. path = [path encodeString:NSUTF8StringEncoding];
  796. path = [path stringByAppendingString:k_url_acces_shared_api];
  797. path = [path stringByAppendingString:[NSString stringWithFormat:@"/%ld",(long)idRemoteShared]];
  798. OCWebDAVClient *request = [OCWebDAVClient new];
  799. request = [self getRequestWithCredentials:request];
  800. [request unShareFileOrFolderByServer:path onCommunication:sharedOCCommunication success:^(NSHTTPURLResponse *response, id responseObject) {
  801. if (successRequest) {
  802. //Return success
  803. successRequest(response, request.redirectedServer);
  804. }
  805. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  806. failureRequest(response, error, request.redirectedServer);
  807. }];
  808. }
  809. - (void) isShareFileOrFolderByServer: (NSString *) path andIdRemoteShared: (NSInteger) idRemoteShared
  810. onCommunication:(OCCommunication *)sharedOCCommunication
  811. successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer, BOOL isShared, id shareDto)) successRequest
  812. failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
  813. path = [path encodeString:NSUTF8StringEncoding];
  814. path = [path stringByAppendingString:k_url_acces_shared_api];
  815. path = [path stringByAppendingString:[NSString stringWithFormat:@"/%ld",(long)idRemoteShared]];
  816. OCWebDAVClient *request = [OCWebDAVClient new];
  817. request = [self getRequestWithCredentials:request];
  818. [request isShareFileOrFolderByServer:path onCommunication:sharedOCCommunication success:^(NSHTTPURLResponse *response, id responseObject) {
  819. if (successRequest) {
  820. NSData *responseData = (NSData*) responseObject;
  821. OCXMLSharedParser *parser = [[OCXMLSharedParser alloc]init];
  822. // NSLog(@"response: %@", [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding]);
  823. [parser initParserWithData:responseData];
  824. BOOL isShared = NO;
  825. OCSharedDto *shareDto = nil;
  826. if (parser.shareList) {
  827. NSMutableArray *sharedList = [parser.shareList mutableCopy];
  828. if ([sharedList count] > 0) {
  829. isShared = YES;
  830. shareDto = [sharedList objectAtIndex:0];
  831. }
  832. }
  833. //Return success
  834. successRequest(response, request.redirectedServer, isShared, shareDto);
  835. }
  836. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  837. failureRequest(response, error, request.redirectedServer);
  838. }];
  839. }
  840. - (void) updateShare:(NSInteger)shareId ofServerPath:(NSString *)serverPath withPasswordProtect:(NSString*)password andNote:(NSString *)note andExpirationTime:(NSString*)expirationTime andPermissions:(NSInteger)permissions andHideDownload:(BOOL)hideDownload
  841. onCommunication:(OCCommunication *)sharedOCCommunication
  842. successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer)) successRequest
  843. failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest{
  844. serverPath = [serverPath encodeString:NSUTF8StringEncoding];
  845. serverPath = [serverPath stringByAppendingString:k_url_acces_shared_api];
  846. serverPath = [serverPath stringByAppendingString:[NSString stringWithFormat:@"/%ld",(long)shareId]];
  847. OCWebDAVClient *request = [OCWebDAVClient new];
  848. request = [self getRequestWithCredentials:request];
  849. [request updateShareItem:shareId ofServerPath:serverPath withPasswordProtect:password andNote:note andExpirationTime:expirationTime andPermissions:permissions andHideDownload:hideDownload onCommunication:sharedOCCommunication success:^(NSHTTPURLResponse *response, id responseObject) {
  850. NSData *responseData = (NSData*) responseObject;
  851. OCXMLShareByLinkParser *parser = [[OCXMLShareByLinkParser alloc]init];
  852. // NSLog(@"response: %@", [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding]);
  853. [parser initParserWithData:responseData];
  854. if (parser.statusCode == kOCSharedAPISuccessful || parser.statusCode == kOCShareeAPISuccessful) {
  855. successRequest(response, request.redirectedServer);
  856. } else {
  857. NSError *error = [UtilsFramework getErrorWithCode:parser.statusCode andCustomMessageFromTheServer:parser.message];
  858. failureRequest(response, error, request.redirectedServer);
  859. }
  860. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  861. failureRequest(response, error, request.redirectedServer);
  862. }];
  863. }
  864. - (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{
  865. serverPath = [serverPath encodeString:NSUTF8StringEncoding];
  866. serverPath = [serverPath stringByAppendingString:k_url_access_sharee_api];
  867. searchString = [searchString encodeString:NSUTF8StringEncoding];
  868. OCWebDAVClient *request = [OCWebDAVClient new];
  869. request = [self getRequestWithCredentials:request];
  870. [request searchUsersAndGroupsWith:searchString forPage:page with:resultsPerPage ofServer:serverPath onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
  871. NSData *responseData = (NSData*) responseObject;
  872. NSMutableArray *itemList = [NSMutableArray new];
  873. //Parse
  874. NSError *error;
  875. NSDictionary *jsongParsed = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
  876. if (error == nil) {
  877. NSDictionary *ocsDict = [jsongParsed valueForKey:@"ocs"];
  878. NSDictionary *metaDict = [ocsDict valueForKey:@"meta"];
  879. NSInteger statusCode = [[metaDict valueForKey:@"statuscode"] integerValue];
  880. if (statusCode == kOCShareeAPISuccessful || statusCode == kOCSharedAPISuccessful) {
  881. NSDictionary *dataDict = [ocsDict valueForKey:@"data"];
  882. NSArray *exactDict = [dataDict valueForKey:@"exact"];
  883. NSArray *usersFounded = [dataDict valueForKey:@"users"];
  884. NSArray *groupsFounded = [dataDict valueForKey:@"groups"];
  885. NSArray *usersRemote = [dataDict valueForKey:@"remotes"];
  886. NSArray *usersExact = [exactDict valueForKey:@"users"];
  887. NSArray *groupsExact = [exactDict valueForKey:@"groups"];
  888. NSArray *remotesExact = [exactDict valueForKey:@"remotes"];
  889. [self addUserItemOfType:shareTypeUser fromArray:usersFounded ToList:itemList];
  890. [self addUserItemOfType:shareTypeUser fromArray:usersExact ToList:itemList];
  891. [self addUserItemOfType:shareTypeRemote fromArray:usersRemote ToList:itemList];
  892. [self addUserItemOfType:shareTypeRemote fromArray:remotesExact ToList:itemList];
  893. [self addGroupItemFromArray:groupsFounded ToList:itemList];
  894. [self addGroupItemFromArray:groupsExact ToList:itemList];
  895. }else{
  896. NSString *message = (NSString*)[metaDict objectForKey:@"message"];
  897. if ([message isKindOfClass:[NSNull class]]) {
  898. message = @"";
  899. }
  900. NSError *error = [UtilsFramework getErrorWithCode:statusCode andCustomMessageFromTheServer:message];
  901. failureRequest(response, error, request.redirectedServer);
  902. }
  903. //Return success
  904. successRequest(response, itemList, request.redirectedServer);
  905. }
  906. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  907. failureRequest(response, error, request.redirectedServer);
  908. }];
  909. }
  910. #pragma mark - Capabilities
  911. - (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{
  912. serverPath = [serverPath encodeString:NSUTF8StringEncoding];
  913. serverPath = [serverPath stringByAppendingString:k_url_capabilities];
  914. OCWebDAVClient *request = [OCWebDAVClient new];
  915. request = [self getRequestWithCredentials:request];
  916. [request getCapabilitiesOfServer:serverPath onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
  917. NSData *responseData = (NSData*) responseObject;
  918. OCCapabilities *capabilities = [OCCapabilities new];
  919. //Parse
  920. NSError *error;
  921. NSDictionary *jsongParsed = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
  922. NSLog(@"dic: %@",jsongParsed);
  923. if (jsongParsed && jsongParsed.allKeys > 0) {
  924. NSDictionary *ocs = [jsongParsed valueForKey:@"ocs"];
  925. NSDictionary *data = [ocs valueForKey:@"data"];
  926. NSDictionary *version = [data valueForKey:@"version"];
  927. if (ocs.count > 0 && data.count > 0 && version.count > 0) {
  928. //VERSION
  929. NSNumber *versionMajorNumber = (NSNumber*) [version valueForKey:@"major"];
  930. NSNumber *versionMinorNumber = (NSNumber*) [version valueForKey:@"minor"];
  931. NSNumber *versionMicroNumber = (NSNumber*) [version valueForKey:@"micro"];
  932. capabilities.versionMajor = versionMajorNumber.integerValue;
  933. capabilities.versionMinor = versionMinorNumber.integerValue;
  934. capabilities.versionMicro = versionMicroNumber.integerValue;
  935. capabilities.versionString = (NSString*)[version valueForKey:@"string"];
  936. capabilities.versionEdition = (NSString*)[version valueForKey:@"edition"];
  937. NSDictionary *capabilitiesDict = [data valueForKey:@"capabilities"];
  938. //CORE
  939. NSDictionary *core = [capabilitiesDict valueForKey:@"core"];
  940. NSNumber *corePollIntervalNumber = (NSNumber*)[core valueForKey:@"pollinterval"];
  941. capabilities.corePollInterval = corePollIntervalNumber.integerValue;
  942. capabilities.coreWebDavRoot = [core valueForKey:@"webdav-root"];
  943. //FILE SHARING
  944. NSDictionary *fileSharing = [capabilitiesDict valueForKey:@"files_sharing"];
  945. NSNumber *fileSharingAPIEnabled = (NSNumber*)[fileSharing valueForKey:@"api_enabled"];
  946. NSNumber *filesSharingDefaultPermissions = (NSNumber*)[fileSharing valueForKey:@"default_permissions"];
  947. NSNumber *fileSharingGroupSharing = (NSNumber*)[fileSharing valueForKey:@"group_sharing"];
  948. NSNumber *filesSharingReSharing = (NSNumber*)[fileSharing valueForKey:@"resharing"];
  949. capabilities.isFilesSharingAPIEnabled = fileSharingAPIEnabled.boolValue;
  950. capabilities.filesSharingDefaulPermissions = filesSharingDefaultPermissions.integerValue;
  951. capabilities.isFilesSharingGroupSharing = fileSharingGroupSharing.boolValue;
  952. capabilities.isFilesSharingReSharing = filesSharingReSharing.boolValue;
  953. //FILE SHARING - PUBLIC
  954. NSDictionary *fileSharingPublic = [fileSharing valueForKey:@"public"];
  955. NSNumber *filesSharingPublicShareLinkEnabledNumber = (NSNumber*)[fileSharingPublic valueForKey:@"enabled"];
  956. NSNumber *filesSharingAllowPublicUploadsEnabledNumber = (NSNumber*)[fileSharingPublic valueForKey:@"upload"];
  957. NSNumber *isFilesSharingAllowPublicUserSendMailNumber = (NSNumber*)[fileSharingPublic valueForKey:@"send_mail"];
  958. NSNumber *filesSharingAllowPublicUploadFilesDrop = (NSNumber*)[fileSharingPublic valueForKey:@"upload_files_drop"];
  959. NSNumber *filesSharingAllowPublicMultipleLinks = (NSNumber*)[fileSharingPublic valueForKey:@"multiple_links"];
  960. capabilities.isFilesSharingPublicShareLinkEnabled = filesSharingPublicShareLinkEnabledNumber.boolValue;
  961. capabilities.isFilesSharingAllowPublicUploadsEnabled = filesSharingAllowPublicUploadsEnabledNumber.boolValue;
  962. capabilities.isFilesSharingAllowPublicUserSendMail = isFilesSharingAllowPublicUserSendMailNumber.boolValue;
  963. capabilities.isFilesSharingAllowPublicUploadFilesDrop = filesSharingAllowPublicUploadFilesDrop.boolValue;
  964. capabilities.isFilesSharingAllowPublicMultipleLinks = filesSharingAllowPublicMultipleLinks.boolValue;
  965. NSDictionary *fileSharingPublicExpireDate = [fileSharingPublic valueForKey:@"expire_date"];
  966. NSNumber *filesSharingPublicExpireDateByDefaultEnabledNumber = (NSNumber*)[fileSharingPublicExpireDate valueForKey:@"enabled"];
  967. NSNumber *filesSharingPublicExpireDateEnforceEnabledNumber = (NSNumber*)[fileSharingPublicExpireDate valueForKey:@"enforced"];
  968. NSNumber *filesSharingPublicExpireDateDaysNumber = (NSNumber*)[fileSharingPublicExpireDate valueForKey:@"days"];
  969. capabilities.isFilesSharingPublicExpireDateByDefaultEnabled = filesSharingPublicExpireDateByDefaultEnabledNumber.boolValue;
  970. capabilities.isFilesSharingPublicExpireDateEnforceEnabled = filesSharingPublicExpireDateEnforceEnabledNumber.boolValue;
  971. capabilities.filesSharingPublicExpireDateDays = filesSharingPublicExpireDateDaysNumber.integerValue;
  972. NSDictionary *fileSharingPublicPassword = [fileSharingPublic valueForKey:@"password"];
  973. NSNumber *fileSharingPublicPasswordEnforcedEnabled = (NSNumber*)[fileSharingPublicPassword valueForKey:@"enforced"];
  974. capabilities.isFilesSharingPublicPasswordEnforced = fileSharingPublicPasswordEnforcedEnabled.boolValue;
  975. //FILE SHARING - USER
  976. NSDictionary *fileSharingUser = [fileSharing valueForKey:@"user"];
  977. NSNumber *isFilesSharingAllowUserSendMailNumber = (NSNumber*)[fileSharingUser valueForKey:@"send_mail"];
  978. capabilities.isFilesSharingAllowUserSendMail = isFilesSharingAllowUserSendMailNumber.boolValue;
  979. NSDictionary *fileSharingUserExpireDate = [fileSharingUser valueForKey:@"expire_date"];
  980. NSNumber *filesSharingUserExpireDateNumber = (NSNumber*)[fileSharingUserExpireDate valueForKey:@"enabled"];
  981. capabilities.isFilesSharingUserExpireDate = filesSharingUserExpireDateNumber.boolValue;
  982. //FILE SHARING - GROUP
  983. NSDictionary *fileSharingGroup = [fileSharing valueForKey:@"group"];
  984. NSNumber *filesSharingGroupEnabled = (NSNumber*)[fileSharingGroup valueForKey:@"enabled"];
  985. capabilities.isFilesSharingGroupEnabled = filesSharingGroupEnabled.boolValue;
  986. NSDictionary *fileSharingGroupExpireDate = [fileSharingGroup valueForKey:@"expire_date"];
  987. NSNumber *filesSharingGroupExpireDateNumber = (NSNumber*)[fileSharingGroupExpireDate valueForKey:@"enabled"];
  988. capabilities.isFilesSharingGroupExpireDate = filesSharingGroupExpireDateNumber.boolValue;
  989. //FILE SHARING - FEDERATION
  990. NSDictionary *fileSharingFederation = [fileSharing valueForKey:@"federation"];
  991. NSDictionary *fileSharingFederationExpireDate = [fileSharingFederation valueForKey:@"expire_date"];
  992. NSNumber *filesSharingFederationAllowUserSendSharesNumber = (NSNumber*)[fileSharingFederation valueForKey:@"outgoing"];
  993. NSNumber *filesSharingFederationAllowUserReceiveSharesNumber = (NSNumber*)[fileSharingFederation valueForKey:@"incoming"];
  994. NSNumber *filesSharingFederationExpireDateNumber = (NSNumber*)[fileSharingFederationExpireDate valueForKey:@"enabled"];
  995. capabilities.isFilesSharingFederationAllowUserSendShares = filesSharingFederationAllowUserSendSharesNumber.boolValue;
  996. capabilities.isFilesSharingFederationAllowUserReceiveShares = filesSharingFederationAllowUserReceiveSharesNumber.boolValue;
  997. capabilities.isFilesSharingFederationExpireDate = filesSharingFederationExpireDateNumber.boolValue;
  998. //FILE SHARING - SHAREBYMAIL
  999. NSDictionary *fileSharingShareByMail = [fileSharing valueForKey:@"sharebymail"];
  1000. NSNumber *fileSharingShareByMailEnabled = (NSNumber*)[fileSharingShareByMail valueForKey:@"enabled"];
  1001. capabilities.isFileSharingShareByMailEnabled = fileSharingShareByMailEnabled.boolValue;
  1002. NSDictionary *fileSharingShareByMailExpireDate = [fileSharingShareByMail valueForKey:@"expire_date"];
  1003. NSNumber *fileSharingShareByMailExpireDateNumber = (NSNumber*)[fileSharingShareByMailExpireDate valueForKey:@"enabled"];
  1004. capabilities.isFileSharingShareByMailExpireDate = fileSharingShareByMailExpireDateNumber.boolValue;
  1005. NSDictionary *fileSharingShareByMailPassword = [fileSharingShareByMail valueForKey:@"password"];
  1006. NSNumber *fileSharingShareByMailPasswordNumber = (NSNumber*)[fileSharingShareByMailPassword valueForKey:@"enabled"];
  1007. capabilities.isFileSharingShareByMailPassword = fileSharingShareByMailPasswordNumber.boolValue;
  1008. NSDictionary *fileSharingShareByMailUploadFilesDrop = [fileSharingShareByMail valueForKey:@"upload_files_drop"];
  1009. NSNumber *fileSharingShareByMailUploadFilesDropNumber = (NSNumber*)[fileSharingShareByMailUploadFilesDrop valueForKey:@"enabled"];
  1010. capabilities.isFileSharingShareByMailUploadFilesDrop = fileSharingShareByMailUploadFilesDropNumber.boolValue;
  1011. // EXTERNAL SITES
  1012. NSDictionary *externalSitesDic = [capabilitiesDict valueForKey:@"external"];
  1013. if (externalSitesDic) {
  1014. capabilities.isExternalSitesServerEnabled = YES;
  1015. NSArray *externalSitesArray = [externalSitesDic valueForKey:@"v1"];
  1016. capabilities.externalSiteV1 = [externalSitesArray componentsJoinedByString:@","];
  1017. }
  1018. // ACTIVITY
  1019. NSDictionary *activityDic = [capabilitiesDict valueForKey:@"activity"];
  1020. if (activityDic) {
  1021. NSArray *activityArray = [activityDic valueForKey:@"apiv2"];
  1022. if (activityArray) {
  1023. capabilities.isActivityV2Enabled = YES;
  1024. capabilities.activityV2 = [activityArray componentsJoinedByString:@","];
  1025. }
  1026. }
  1027. // NOTIFICATION
  1028. NSDictionary *notificationDic = [capabilitiesDict valueForKey:@"notifications"];
  1029. if (notificationDic) {
  1030. capabilities.isNotificationServerEnabled = YES;
  1031. NSArray *ocsendpointsArray = [notificationDic valueForKey:@"ocs-endpoints"];
  1032. capabilities.notificationOcsEndpoints = [ocsendpointsArray componentsJoinedByString:@","];
  1033. NSArray *pushArray = [notificationDic valueForKey:@"push"];
  1034. capabilities.notificationPush = [pushArray componentsJoinedByString:@","];
  1035. }
  1036. // SPREED
  1037. NSDictionary *spreedDic = [capabilitiesDict valueForKey:@"spreed"];
  1038. if (spreedDic) {
  1039. capabilities.isSpreedServerEnabled = YES;
  1040. NSArray *featuresArray = [capabilitiesDict valueForKey:@"features"];
  1041. capabilities.spreedFeatures = [featuresArray componentsJoinedByString:@","];
  1042. }
  1043. //FILES
  1044. NSDictionary *files = [capabilitiesDict valueForKey:@"files"];
  1045. NSNumber *fileBigFileChunkingEnabledNumber = (NSNumber*)[files valueForKey:@"bigfilechunking"];
  1046. NSNumber *fileUndeleteEnabledNumber = (NSNumber*)[files valueForKey:@"undelete"];
  1047. NSNumber *fileVersioningEnabledNumber = (NSNumber*)[files valueForKey:@"versioning"];
  1048. capabilities.isFileBigFileChunkingEnabled = fileBigFileChunkingEnabledNumber.boolValue;
  1049. capabilities.isFileUndeleteEnabled = fileUndeleteEnabledNumber.boolValue;
  1050. capabilities.isFileVersioningEnabled = fileVersioningEnabledNumber.boolValue;
  1051. NSDictionary *pagination = [files valueForKey:@"pagination"];
  1052. if (pagination) {
  1053. capabilities.isPaginationEnabled = true;
  1054. capabilities.paginationEndponit = [pagination valueForKey:@"endpoint"];
  1055. }
  1056. //THEMING
  1057. NSDictionary *theming = [capabilitiesDict valueForKey:@"theming"];
  1058. if ([theming count] > 0) {
  1059. if ([theming valueForKey:@"background"] && ![[theming valueForKey:@"background"] isEqual:[NSNull null]])
  1060. capabilities.themingBackground = [theming valueForKey:@"background"];
  1061. if ([theming valueForKey:@"background-default"] && ![[theming valueForKey:@"background-default"] isEqual:[NSNull null]]) {
  1062. NSNumber *result = (NSNumber*)[theming valueForKey:@"background-default"];
  1063. capabilities.themingBackgroundDefault = result.boolValue;
  1064. }
  1065. if ([theming valueForKey:@"background-plain"] && ![[theming valueForKey:@"background-plain"] isEqual:[NSNull null]]) {
  1066. NSNumber *result = (NSNumber*)[theming valueForKey:@"background-plain"];
  1067. capabilities.themingBackgroundPlain = result.boolValue;
  1068. }
  1069. if ([theming valueForKey:@"color"] && ![[theming valueForKey:@"color"] isEqual:[NSNull null]])
  1070. capabilities.themingColor = [theming valueForKey:@"color"];
  1071. if ([theming valueForKey:@"color-element"] && ![[theming valueForKey:@"color-element"] isEqual:[NSNull null]])
  1072. capabilities.themingColorElement = [theming valueForKey:@"color-element"];
  1073. if ([theming valueForKey:@"color-text"] && ![[theming valueForKey:@"color-text"] isEqual:[NSNull null]])
  1074. capabilities.themingColorText = [theming valueForKey:@"color-text"];
  1075. if ([theming valueForKey:@"logo"] && ![[theming valueForKey:@"logo"] isEqual:[NSNull null]])
  1076. capabilities.themingLogo = [theming valueForKey:@"logo"];
  1077. if ([theming valueForKey:@"name"] && ![[theming valueForKey:@"name"] isEqual:[NSNull null]])
  1078. capabilities.themingName = [theming valueForKey:@"name"];
  1079. if ([theming valueForKey:@"slogan"] && ![[theming valueForKey:@"slogan"] isEqual:[NSNull null]])
  1080. capabilities.themingSlogan = [theming valueForKey:@"slogan"];
  1081. if ([theming valueForKey:@"url"] && ![[theming valueForKey:@"url"] isEqual:[NSNull null]])
  1082. capabilities.themingUrl = [theming valueForKey:@"url"];
  1083. }
  1084. //END TO END Encryption
  1085. NSDictionary *endToEndEncryption = [capabilitiesDict valueForKey:@"end-to-end-encryption"];
  1086. if ([endToEndEncryption count] > 0) {
  1087. NSNumber *endToEndEncryptionEnabled = (NSNumber*)[endToEndEncryption valueForKey:@"enabled"];
  1088. capabilities.isEndToEndEncryptionEnabled = endToEndEncryptionEnabled.boolValue;
  1089. if ([endToEndEncryption valueForKey:@"api-version"] && ![[endToEndEncryption valueForKey:@"api-version"] isEqual:[NSNull null]])
  1090. capabilities.endToEndEncryptionVersion = [endToEndEncryption valueForKey:@"api-version"];
  1091. }
  1092. //Richdocuments
  1093. NSDictionary *richdocuments = [capabilitiesDict valueForKey:@"richdocuments"];
  1094. if (richdocuments!= nil && [richdocuments count] > 0) {
  1095. capabilities.richdocumentsDirectEditing = [[richdocuments valueForKey:@"direct_editing"] boolValue];
  1096. capabilities.richdocumentsMimetypes = [richdocuments valueForKey:@"mimetypes"];
  1097. }
  1098. //Handwerkcloud
  1099. NSDictionary *handwerkcloudDic = [capabilitiesDict valueForKey:@"handwerkcloud"];
  1100. if (handwerkcloudDic) {
  1101. NSNumber *isHandwerkcloudEnabledNumber = (NSNumber*)[handwerkcloudDic valueForKey:@"enabled"];
  1102. capabilities.isHandwerkcloudEnabled = isHandwerkcloudEnabledNumber.boolValue;
  1103. if ([handwerkcloudDic valueForKey:@"shop_url"] && ![[handwerkcloudDic valueForKey:@"shop_url"] isEqual:[NSNull null]])
  1104. capabilities.HCShopUrl = [handwerkcloudDic valueForKey:@"shop_url"];
  1105. }
  1106. //Imagemeter
  1107. NSDictionary *imagemeterDic = [capabilitiesDict valueForKey:@"imagemeter"];
  1108. if (imagemeterDic) {
  1109. NSNumber *isImagemeterEnabledNumber = (NSNumber*)[imagemeterDic valueForKey:@"enabled"];
  1110. capabilities.isImagemeterEnabled = isImagemeterEnabledNumber.boolValue;
  1111. }
  1112. //Fulltextsearch
  1113. NSDictionary *fulltextsearchDic = [capabilitiesDict valueForKey:@"fulltextsearch"];
  1114. if (fulltextsearchDic) {
  1115. NSNumber *isFulltextsearchEnabledNumber = (NSNumber*)[fulltextsearchDic valueForKey:@"remote"];
  1116. capabilities.isFulltextsearchEnabled = isFulltextsearchEnabledNumber.boolValue;
  1117. }
  1118. //extendedSupport
  1119. NSDictionary *extendedSupportDic = [capabilitiesDict valueForKey:@"extendedSupport"];
  1120. if (extendedSupportDic) {
  1121. NSNumber *isExtendedSupportEnabled = (NSNumber*)[extendedSupportDic valueForKey:@"enabled"];
  1122. capabilities.isExtendedSupportEnabled = isExtendedSupportEnabled.boolValue;
  1123. }
  1124. }
  1125. successRequest(response, capabilities, request.redirectedServer);
  1126. } else {
  1127. failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedString(@"_server_response_error_", nil)], request.redirectedServer);
  1128. }
  1129. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  1130. failureRequest(response, error, request.redirectedServer);
  1131. }];
  1132. }
  1133. #pragma mark - Thumbnail
  1134. - (NSURLSessionTask *) getRemoteThumbnailByServer:(NSString*)serverPath ofFilePath:(NSString *)filePath withWidth:(NSInteger)fileWidth andHeight:(NSInteger)fileHeight onCommunication:(OCCommunication *)sharedOCComunication
  1135. successRequest:(void(^)(NSHTTPURLResponse *response, NSData *thumbnail, NSString *redirectedServer)) successRequest
  1136. failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
  1137. serverPath = [serverPath encodeString:NSUTF8StringEncoding];
  1138. filePath = [filePath encodeString:NSUTF8StringEncoding];
  1139. OCWebDAVClient *request = [OCWebDAVClient new];
  1140. request = [self getRequestWithCredentials:request];
  1141. OCHTTPRequestOperation *operation = [request getRemoteThumbnailByServer:serverPath ofFilePath:filePath withWidth:fileWidth andHeight:fileHeight onCommunication:sharedOCComunication
  1142. success:^(NSHTTPURLResponse *response, id responseObject) {
  1143. NSData *responseData = (NSData*) responseObject;
  1144. successRequest(response, responseData, request.redirectedServer);
  1145. } failure:^(NSHTTPURLResponse *response, id _Nullable responseObject, NSError * _Nonnull error) {
  1146. failureRequest(response, error, request.redirectedServer);
  1147. }];
  1148. [operation resume];
  1149. return operation;
  1150. }
  1151. - (NSURLSessionTask *) getRemotePreviewByServer:(NSString*)serverPath ofFilePath:(NSString *)filePath withWidth:(NSInteger)fileWidth andHeight:(NSInteger)fileHeight andA:(NSInteger)a andMode:(NSString * _Nonnull)mode path:(NSString * _Nonnull)path onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSData *preview, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
  1152. serverPath = [serverPath encodeString:NSUTF8StringEncoding];
  1153. filePath = [filePath encodeString:NSUTF8StringEncoding];
  1154. OCWebDAVClient *request = [OCWebDAVClient new];
  1155. request = [self getRequestWithCredentials:request];
  1156. OCHTTPRequestOperation *operation = [request getRemotePreviewByServer:serverPath ofFilePath:filePath withWidth:fileWidth andHeight:fileHeight andA:a andMode:mode path:path onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
  1157. NSData *responseData = (NSData*) responseObject;
  1158. successRequest(response, responseData, request.redirectedServer);
  1159. } failure:^(NSHTTPURLResponse *response, id _Nullable responseObject, NSError * _Nonnull error) {
  1160. failureRequest(response, error, request.redirectedServer);
  1161. }];
  1162. [operation resume];
  1163. return operation;
  1164. }
  1165. - (NSURLSessionTask *) getRemotePreviewTrashByServer:(NSString*)serverPath ofFileId:(NSString *)fileId size:(NSString *)size onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSData *preview, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
  1166. serverPath = [serverPath encodeString:NSUTF8StringEncoding];
  1167. OCWebDAVClient *request = [OCWebDAVClient new];
  1168. request = [self getRequestWithCredentials:request];
  1169. OCHTTPRequestOperation *operation = [request getRemotePreviewTrashByServer:serverPath ofFileId:fileId size:size onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
  1170. NSData *responseData = (NSData*) responseObject;
  1171. successRequest(response, responseData, request.redirectedServer);
  1172. } failure:^(NSHTTPURLResponse *response, id _Nullable responseObject, NSError * _Nonnull error) {
  1173. failureRequest(response, error, request.redirectedServer);
  1174. }];
  1175. [operation resume];
  1176. return operation;
  1177. }
  1178. #pragma mark - Notification
  1179. - (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 {
  1180. serverPath = [serverPath encodeString:NSUTF8StringEncoding];
  1181. serverPath = [serverPath stringByAppendingString:k_url_acces_remote_notification_api];
  1182. OCWebDAVClient *request = [OCWebDAVClient new];
  1183. request = [self getRequestWithCredentials:request];
  1184. [request getNotificationServer:serverPath onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
  1185. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1186. NSData *responseData = (NSData*) responseObject;
  1187. NSMutableArray *listOfNotifications = [NSMutableArray new];
  1188. //Parse
  1189. NSError *error;
  1190. NSDictionary *jsongParsed = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
  1191. NSLog(@"[LOG] Notifications : %@",jsongParsed);
  1192. if (jsongParsed && jsongParsed.allKeys > 0) {
  1193. NSDictionary *ocs = [jsongParsed valueForKey:@"ocs"];
  1194. NSDictionary *meta = [ocs valueForKey:@"meta"];
  1195. NSDictionary *datas = [ocs valueForKey:@"data"];
  1196. NSInteger statusCode = [[meta valueForKey:@"statuscode"] integerValue];
  1197. if (statusCode == kOCNotificationAPINoContent || statusCode == kOCNotificationAPISuccessful) {
  1198. for (NSDictionary *data in datas) {
  1199. OCNotifications *notification = [OCNotifications new];
  1200. if ([data valueForKey:@"notification_id"] && ![[data valueForKey:@"notification_id"] isEqual:[NSNull null]])
  1201. notification.idNotification = [[data valueForKey:@"notification_id"] integerValue];
  1202. if ([data valueForKey:@"app"] && ![[data valueForKey:@"app"] isEqual:[NSNull null]])
  1203. notification.application = [data valueForKey:@"app"];
  1204. if ([data valueForKey:@"user"] && ![[data valueForKey:@"user"] isEqual:[NSNull null]])
  1205. notification.user = [data valueForKey:@"user"];
  1206. if ([data valueForKey:@"datetime"] && ![[data valueForKey:@"datetime"] isEqual:[NSNull null]]) {
  1207. NSString *dateString = [data valueForKey:@"datetime"];
  1208. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  1209. NSLocale *enUSPOSIXLocale = [NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"];
  1210. [dateFormatter setLocale:enUSPOSIXLocale];
  1211. [dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZZZZZ"];
  1212. notification.date = [dateFormatter dateFromString:dateString];
  1213. }
  1214. if ([data valueForKey:@"object_type"] && ![[data valueForKey:@"object_type"] isEqual:[NSNull null]])
  1215. notification.typeObject = [data valueForKey:@"object_type"];
  1216. if ([data valueForKey:@"object_id"] && ![[data valueForKey:@"object_id"] isEqual:[NSNull null]])
  1217. notification.idObject = [data valueForKey:@"object_id"];
  1218. if ([data valueForKey:@"subject"] && ![[data valueForKey:@"subject"] isEqual:[NSNull null]])
  1219. notification.subject = [data valueForKey:@"subject"];
  1220. if ([data valueForKey:@"subjectRich"] && ![[data valueForKey:@"subjectRich"] isEqual:[NSNull null]])
  1221. notification.subjectRich = [data valueForKey:@"subjectRich"];
  1222. if ([data valueForKey:@"subjectRichParameters"] && ![[data valueForKey:@"subjectRichParameters"] isEqual:[NSNull null]] && [[data valueForKey:@"subjectRichParameters"] count] > 0)
  1223. notification.subjectRichParameters = [data valueForKey:@"subjectRichParameters"];
  1224. if ([data valueForKey:@"message"] && ![[data valueForKey:@"message"] isEqual:[NSNull null]])
  1225. notification.message = [data valueForKey:@"message"];
  1226. if ([data valueForKey:@"messageRich"] && ![[data valueForKey:@"messageRich"] isEqual:[NSNull null]])
  1227. notification.messageRich = [data valueForKey:@"messageRich"];
  1228. if ([data valueForKey:@"messageRichParameters"] && ![[data valueForKey:@"messageRichParameters"] isEqual:[NSNull null]] && [[data valueForKey:@"messageRichParameters"] count] > 0)
  1229. notification.messageRichParameters = [data valueForKey:@"messageRichParameters"];
  1230. if ([data valueForKey:@"link"] && ![[data valueForKey:@"link"] isEqual:[NSNull null]])
  1231. notification.link = [data valueForKey:@"link"];
  1232. if ([data valueForKey:@"icon"] && ![[data valueForKey:@"icon"] isEqual:[NSNull null]])
  1233. notification.icon = [data valueForKey:@"icon"];
  1234. /* ACTION */
  1235. NSMutableArray *actionsArr = [NSMutableArray new];
  1236. NSDictionary *actions = [data valueForKey:@"actions"];
  1237. for (NSDictionary *action in actions) {
  1238. OCNotificationsAction *notificationAction = [OCNotificationsAction new];
  1239. if ([action valueForKey:@"label"] && ![[action valueForKey:@"label"] isEqual:[NSNull null]])
  1240. notificationAction.label = [action valueForKey:@"label"];
  1241. if ([action valueForKey:@"link"] && ![[action valueForKey:@"link"] isEqual:[NSNull null]])
  1242. notificationAction.link = [action valueForKey:@"link"];
  1243. if ([action valueForKey:@"primary"] && ![[action valueForKey:@"primary"] isEqual:[NSNull null]])
  1244. notificationAction.primary = [[action valueForKey:@"primary"] boolValue];
  1245. if ([action valueForKey:@"type"] && ![[action valueForKey:@"type"] isEqual:[NSNull null]])
  1246. notificationAction.type = [action valueForKey:@"type"];
  1247. [actionsArr addObject:notificationAction];
  1248. }
  1249. notification.actions = [[NSArray alloc] initWithArray:actionsArr];
  1250. [listOfNotifications addObject:notification];
  1251. }
  1252. dispatch_async(dispatch_get_main_queue(), ^{
  1253. successRequest(response, listOfNotifications, request.redirectedServer);
  1254. });
  1255. } else {
  1256. NSString *message = (NSString *)[meta objectForKey:@"message"];
  1257. if ([message isKindOfClass:[NSNull class]]) {
  1258. message = NSLocalizedString(@"_server_response_error_", nil);
  1259. }
  1260. dispatch_async(dispatch_get_main_queue(), ^{
  1261. failureRequest(response, [UtilsFramework getErrorWithCode:statusCode andCustomMessageFromTheServer:message], request.redirectedServer);
  1262. });
  1263. }
  1264. } else {
  1265. dispatch_async(dispatch_get_main_queue(), ^{
  1266. failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedString(@"_server_response_error_", nil)], request.redirectedServer);
  1267. });
  1268. }
  1269. });
  1270. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  1271. failureRequest(response, error, request.redirectedServer);
  1272. }];
  1273. }
  1274. - (void)setNotificationServer:(NSString*)serverPath type:(NSString *)type onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void (^)(NSHTTPURLResponse *, NSString *))successRequest failureRequest:(void (^)(NSHTTPURLResponse *, NSError *, NSString *))failureRequest {
  1275. serverPath = [serverPath encodeString:NSUTF8StringEncoding];
  1276. OCWebDAVClient *request = [OCWebDAVClient new];
  1277. request = [self getRequestWithCredentials:request];
  1278. __weak OCWebDAVClient *wrequest = request;
  1279. [request setNotificationServer:serverPath type:type onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
  1280. successRequest(response, wrequest.redirectedServer);
  1281. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  1282. failureRequest(response, error, wrequest.redirectedServer);
  1283. }];
  1284. }
  1285. #pragma mark - Push Notification
  1286. - (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 {
  1287. serverPath = [serverPath encodeString:NSUTF8StringEncoding];
  1288. serverPath = [serverPath stringByAppendingString:k_url_acces_remote_subscribing_nextcloud_server_api];
  1289. OCWebDAVClient *request = [OCWebDAVClient new];
  1290. request = [self getRequestWithCredentials:request];
  1291. [request subscribingNextcloudServerPush:serverPath pushTokenHash:pushTokenHash devicePublicKey:devicePublicKey proxyServerPath:proxyServerPath onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
  1292. NSData *responseData = (NSData*)responseObject;
  1293. NSError *error;
  1294. NSDictionary *jsongParsed = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
  1295. if (jsongParsed && jsongParsed.allKeys > 0) {
  1296. NSDictionary *ocs = [jsongParsed valueForKey:@"ocs"];
  1297. NSDictionary *meta = [ocs valueForKey:@"meta"];
  1298. NSDictionary *datas = [ocs valueForKey:@"data"];
  1299. NSInteger statusCode = [[meta valueForKey:@"statuscode"] integerValue];
  1300. if (statusCode == kOCPushNotificationAPISuccessful || statusCode == kOCPushNotificationAPINeedSendProxy) {
  1301. NSString *publicKey = [datas objectForKey:@"publicKey"];
  1302. NSString *deviceIdentifier = [datas objectForKey:@"deviceIdentifier"];
  1303. NSString *signature = [datas objectForKey:@"signature"];
  1304. successRequest(response, publicKey, deviceIdentifier, signature, request.redirectedServer);
  1305. } else {
  1306. NSString *message = (NSString *)[meta objectForKey:@"message"];
  1307. if ([message isKindOfClass:[NSNull class]]) {
  1308. message = NSLocalizedString(@"_server_response_error_", nil);
  1309. }
  1310. failureRequest(response, [UtilsFramework getErrorWithCode:statusCode andCustomMessageFromTheServer:message], request.redirectedServer);
  1311. }
  1312. } else {
  1313. failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedString(@"_server_response_error_", nil)], request.redirectedServer);
  1314. }
  1315. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  1316. failureRequest(response, error, request.redirectedServer);
  1317. }];
  1318. }
  1319. - (void)unsubscribingNextcloudServerPush:(NSString *)serverPath onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer)) successRequest failureRequest:(void (^)(NSHTTPURLResponse *, NSError *, NSString *))failureRequest {
  1320. serverPath = [serverPath encodeString:NSUTF8StringEncoding];
  1321. serverPath = [serverPath stringByAppendingString:k_url_acces_remote_subscribing_nextcloud_server_api];
  1322. OCWebDAVClient *request = [OCWebDAVClient new];
  1323. request = [self getRequestWithCredentials:request];
  1324. [request unsubscribingNextcloudServerPush:serverPath onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
  1325. successRequest(response, request.redirectedServer);
  1326. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  1327. failureRequest(response, error, request.redirectedServer);
  1328. }];
  1329. }
  1330. - (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 {
  1331. serverPath = [serverPath encodeString:NSUTF8StringEncoding];
  1332. serverPath = [serverPath stringByAppendingString:@"/devices"];
  1333. OCWebDAVClient *request = [OCWebDAVClient new];
  1334. [request.defaultHeaders setObject:self.userAgent forKey:@"User-Agent"];
  1335. [request subscribingPushProxy:serverPath pushToken:pushToken deviceIdentifier:deviceIdentifier deviceIdentifierSignature:deviceIdentifierSignature publicKey:publicKey onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
  1336. if (successRequest) {
  1337. //Return success
  1338. successRequest(response, request.redirectedServer);
  1339. }
  1340. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  1341. failureRequest(response, error, request.redirectedServer);
  1342. }];
  1343. }
  1344. - (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 {
  1345. serverPath = [serverPath encodeString:NSUTF8StringEncoding];
  1346. serverPath = [serverPath stringByAppendingString:@"/devices"];
  1347. OCWebDAVClient *request = [OCWebDAVClient new];
  1348. [request.defaultHeaders setObject:self.userAgent forKey:@"User-Agent"];
  1349. [request unsubscribingPushProxy:serverPath deviceIdentifier:deviceIdentifier deviceIdentifierSignature:deviceIdentifierSignature publicKey:publicKey onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
  1350. if (successRequest) {
  1351. //Return success
  1352. successRequest(response, request.redirectedServer);
  1353. }
  1354. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  1355. failureRequest(response, error, request.redirectedServer);
  1356. }];
  1357. }
  1358. #pragma mark - Activity
  1359. - (void) getActivityServer:(NSString*)serverPath since:(NSInteger)since limit:(NSInteger)limit objectId:(NSString *)objectId objectType:(NSString *)objectType previews:(BOOL)previews link:(NSString *)link onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSArray *listOfActivity, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
  1360. serverPath = [serverPath encodeString:NSUTF8StringEncoding];
  1361. serverPath = [serverPath stringByAppendingString:k_url_acces_remote_activity_api];
  1362. OCWebDAVClient *request = [OCWebDAVClient new];
  1363. request = [self getRequestWithCredentials:request];
  1364. [request getActivityServer:serverPath since:since limit:limit objectId:objectId objectType:objectType previews:previews link:link onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
  1365. NSData *responseData = (NSData*) responseObject;
  1366. NSMutableArray *listOfActivity = [NSMutableArray new];
  1367. //Parse
  1368. NSError *error;
  1369. NSDictionary *jsongParsed = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
  1370. NSLog(@"[LOG] Activity : %@",jsongParsed);
  1371. if (jsongParsed && [jsongParsed isKindOfClass:[NSDictionary class]] && jsongParsed.allKeys > 0) {
  1372. NSDictionary *ocs = [jsongParsed valueForKey:@"ocs"];
  1373. NSDictionary *meta = [ocs valueForKey:@"meta"];
  1374. NSDictionary *datas = [ocs valueForKey:@"data"];
  1375. NSInteger statusCode = [[meta valueForKey:@"statuscode"] integerValue];
  1376. if (statusCode == kOCNotificationAPINoContent || statusCode == kOCNotificationAPISuccessful) {
  1377. for (NSDictionary *data in datas) {
  1378. OCActivity *activity = [OCActivity new];
  1379. if ([data valueForKey:@"activity_id"] && ![[data valueForKey:@"activity_id"] isEqual:[NSNull null]])
  1380. activity.idActivity = [[data valueForKey:@"activity_id"] integerValue];
  1381. if ([data valueForKey:@"datetime"] && ![[data valueForKey:@"datetime"] isEqual:[NSNull null]]) {
  1382. NSString *dateString = [data valueForKey:@"datetime"];
  1383. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  1384. NSLocale *enUSPOSIXLocale = [NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"];
  1385. [dateFormatter setLocale:enUSPOSIXLocale];
  1386. [dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZZZZZ"];
  1387. activity.date = [dateFormatter dateFromString:dateString];
  1388. }
  1389. if ([data valueForKey:@"app"] && ![[data valueForKey:@"app"] isEqual:[NSNull null]])
  1390. activity.app = [data valueForKey:@"app"];
  1391. if ([data valueForKey:@"type"] && ![[data valueForKey:@"type"] isEqual:[NSNull null]])
  1392. activity.type = [data valueForKey:@"type"];
  1393. if ([data valueForKey:@"user"] && ![[data valueForKey:@"user"] isEqual:[NSNull null]])
  1394. activity.user = [data valueForKey:@"user"];
  1395. if ([data valueForKey:@"subject"] && ![[data valueForKey:@"subject"] isEqual:[NSNull null]])
  1396. activity.subject = [data valueForKey:@"subject"];
  1397. if ([data valueForKey:@"subject_rich"] && ![[data valueForKey:@"subject_rich"] isEqual:[NSNull null]])
  1398. activity.subject_rich = [data valueForKey:@"subject_rich"];
  1399. if ([data valueForKey:@"message"] && ![[data valueForKey:@"message"] isEqual:[NSNull null]])
  1400. activity.message = [data valueForKey:@"message"];
  1401. if ([data valueForKey:@"message_rich"] && ![[data valueForKey:@"message_rich"] isEqual:[NSNull null]])
  1402. activity.message_rich = [data valueForKey:@"message_rich"];
  1403. if ([data valueForKey:@"icon"] && ![[data valueForKey:@"icon"] isEqual:[NSNull null]])
  1404. activity.icon = [data valueForKey:@"icon"];
  1405. if ([data valueForKey:@"link"] && ![[data valueForKey:@"link"] isEqual:[NSNull null]])
  1406. activity.link = [data valueForKey:@"link"];
  1407. if ([data valueForKey:@"object_type"] && ![[data valueForKey:@"object_type"] isEqual:[NSNull null]])
  1408. activity.object_type = [data valueForKey:@"object_type"];
  1409. if ([data valueForKey:@"object_id"] && ![[data valueForKey:@"object_id"] isEqual:[NSNull null]])
  1410. activity.object_id = [[data valueForKey:@"object_id"] integerValue];
  1411. if ([data valueForKey:@"object_name"] && ![[data valueForKey:@"object_name"] isEqual:[NSNull null]])
  1412. activity.object_name = [data valueForKey:@"object_name"];
  1413. if ([data valueForKey:@"previews"] && ![[data valueForKey:@"previews"] isEqual:[NSNull null]])
  1414. activity.previews = [data valueForKey:@"previews"];
  1415. [listOfActivity addObject:activity];
  1416. }
  1417. successRequest(response, listOfActivity, request.redirectedServer);
  1418. } else {
  1419. NSString *message = (NSString *)[meta objectForKey:@"message"];
  1420. if ([message isKindOfClass:[NSNull class]]) {
  1421. message = NSLocalizedString(@"_server_response_error_", nil);
  1422. }
  1423. failureRequest(response, [UtilsFramework getErrorWithCode:statusCode andCustomMessageFromTheServer:message], request.redirectedServer);
  1424. }
  1425. } else {
  1426. failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedString(@"_server_response_error_", nil)], request.redirectedServer);
  1427. }
  1428. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  1429. failureRequest(response, error, request.redirectedServer);
  1430. }];
  1431. }
  1432. #pragma mark - External Sites
  1433. - (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 {
  1434. serverPath = [serverPath encodeString:NSUTF8StringEncoding];
  1435. serverPath = [serverPath stringByAppendingString:k_url_acces_external_sites_api];
  1436. OCWebDAVClient *request = [OCWebDAVClient new];
  1437. request = [self getRequestWithCredentials:request];
  1438. [request getExternalSitesServer:serverPath onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
  1439. NSData *responseData = (NSData*) responseObject;
  1440. NSMutableArray *listOfExternalSites = [NSMutableArray new];
  1441. //Parse
  1442. NSError *error;
  1443. NSDictionary *jsongParsed = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
  1444. NSLog(@"[LOG] External Sites : %@",jsongParsed);
  1445. if (jsongParsed && jsongParsed.allKeys > 0) {
  1446. NSDictionary *ocs = [jsongParsed valueForKey:@"ocs"];
  1447. NSDictionary *meta = [ocs valueForKey:@"meta"];
  1448. NSDictionary *datas = [ocs valueForKey:@"data"];
  1449. NSInteger statusCode = [[meta valueForKey:@"statuscode"] integerValue];
  1450. if (statusCode == kOCNotificationAPINoContent || statusCode == kOCNotificationAPISuccessful) {
  1451. for (NSDictionary *data in datas) {
  1452. OCExternalSites *externalSites = [OCExternalSites new];
  1453. externalSites.idExternalSite = [[data valueForKey:@"id"] integerValue];
  1454. if ([data valueForKey:@"icon"] && ![[data valueForKey:@"icon"] isEqual:[NSNull null]])
  1455. externalSites.icon = [data valueForKey:@"icon"];
  1456. if ([data valueForKey:@"lang"] && ![[data valueForKey:@"lang"] isEqual:[NSNull null]])
  1457. externalSites.lang = [data valueForKey:@"lang"];
  1458. if ([data valueForKey:@"name"] && ![[data valueForKey:@"name"] isEqual:[NSNull null]])
  1459. externalSites.name = [data valueForKey:@"name"];
  1460. if ([data valueForKey:@"url"] && ![[data valueForKey:@"url"] isEqual:[NSNull null]])
  1461. externalSites.url = [data valueForKey:@"url"];
  1462. if ([data valueForKey:@"type"] && ![[data valueForKey:@"type"] isEqual:[NSNull null]])
  1463. externalSites.type = [data valueForKey:@"type"];
  1464. [listOfExternalSites addObject:externalSites];
  1465. }
  1466. successRequest(response, listOfExternalSites, request.redirectedServer);
  1467. } else {
  1468. NSString *message = (NSString *)[meta objectForKey:@"message"];
  1469. if ([message isKindOfClass:[NSNull class]]) {
  1470. message = NSLocalizedString(@"_server_response_error_", nil);
  1471. }
  1472. failureRequest(response, [UtilsFramework getErrorWithCode:statusCode andCustomMessageFromTheServer:message], request.redirectedServer);
  1473. }
  1474. } else {
  1475. failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedString(@"_server_response_error_", nil)], request.redirectedServer);
  1476. }
  1477. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  1478. failureRequest(response, error, request.redirectedServer);
  1479. }];
  1480. }
  1481. #pragma mark - User Profile
  1482. - (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 {
  1483. serverPath = [serverPath stringByAppendingString:k_url_acces_remote_userprofile_api];
  1484. serverPath = [serverPath encodeString:NSUTF8StringEncoding];
  1485. OCWebDAVClient *request = [OCWebDAVClient new];
  1486. request = [self getRequestWithCredentials:request];
  1487. [request getUserProfileServer:serverPath onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
  1488. NSData *responseData = (NSData*) responseObject;
  1489. OCUserProfile *userProfile = [OCUserProfile new];
  1490. //Parse
  1491. NSError *error;
  1492. NSDictionary *jsongParsed = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
  1493. NSLog(@"[LOG] User Profile : %@",jsongParsed);
  1494. if (jsongParsed && jsongParsed.allKeys > 0) {
  1495. NSDictionary *ocs = [jsongParsed valueForKey:@"ocs"];
  1496. NSDictionary *meta = [ocs valueForKey:@"meta"];
  1497. NSDictionary *data = [ocs valueForKey:@"data"];
  1498. NSInteger statusCode = [[meta valueForKey:@"statuscode"] integerValue];
  1499. if (statusCode == kOCUserProfileAPISuccessful) {
  1500. if ([data valueForKey:@"address"] && ![[data valueForKey:@"address"] isKindOfClass:[NSNull class]])
  1501. userProfile.address = [data valueForKey:@"address"];
  1502. if ([data valueForKey:@"display-name"] && ![[data valueForKey:@"display-name"] isKindOfClass:[NSNull class]])
  1503. userProfile.displayName = [data valueForKey:@"display-name"];
  1504. if ([data valueForKey:@"email"] && ![[data valueForKey:@"email"] isKindOfClass:[NSNull class]])
  1505. userProfile.email = [data valueForKey:@"email"];
  1506. if ([data valueForKey:@"enabled"] && ![[data valueForKey:@"enabled"] isKindOfClass:[NSNull class]])
  1507. userProfile.enabled = [[data valueForKey:@"enabled"] boolValue];
  1508. if ([data valueForKey:@"id"] && ![[data valueForKey:@"id"] isKindOfClass:[NSNull class]])
  1509. userProfile.id = [data valueForKey:@"id"];
  1510. if ([data valueForKey:@"phone"] && ![[data valueForKey:@"phone"] isKindOfClass:[NSNull class]])
  1511. userProfile.phone = [data valueForKey:@"phone"];
  1512. if ([data valueForKey:@"twitter"] && ![[data valueForKey:@"twitter"] isKindOfClass:[NSNull class]])
  1513. userProfile.twitter = [data valueForKey:@"twitter"];
  1514. if ([data valueForKey:@"webpage"] && ![[data valueForKey:@"webpage"] isKindOfClass:[NSNull class]])
  1515. userProfile.webpage = [data valueForKey:@"webpage"];
  1516. /* QUOTA */
  1517. NSDictionary *quota = [data valueForKey:@"quota"];
  1518. if ([quota count] > 0) {
  1519. if ([quota valueForKey:@"free"] && ![[quota valueForKey:@"free"] isKindOfClass:[NSNull class]])
  1520. userProfile.quotaFree = [[quota valueForKey:@"free"] doubleValue];
  1521. if ([quota valueForKey:@"quota"] && ![[quota valueForKey:@"quota"] isKindOfClass:[NSNull class]])
  1522. userProfile.quota = [[quota valueForKey:@"quota"] doubleValue];
  1523. if ([quota valueForKey:@"relative"] && ![[quota valueForKey:@"relative"] isKindOfClass:[NSNull class]])
  1524. userProfile.quotaRelative = [[quota valueForKey:@"relative"] doubleValue];
  1525. if ([quota valueForKey:@"total"] && ![[quota valueForKey:@"total"] isKindOfClass:[NSNull class]])
  1526. userProfile.quotaTotal = [[quota valueForKey:@"total"] doubleValue];
  1527. if ([quota valueForKey:@"used"] && ![[quota valueForKey:@"used"] isKindOfClass:[NSNull class]])
  1528. userProfile.quotaUsed = [[quota valueForKey:@"used"] doubleValue];
  1529. }
  1530. successRequest(response, userProfile, request.redirectedServer);
  1531. } else {
  1532. NSString *message = (NSString *)[meta objectForKey:@"message"];
  1533. if ([message isKindOfClass:[NSNull class]]) {
  1534. message = NSLocalizedString(@"_server_response_error_", nil);
  1535. }
  1536. failureRequest(response, [UtilsFramework getErrorWithCode:statusCode andCustomMessageFromTheServer:message], request.redirectedServer);
  1537. }
  1538. } else {
  1539. failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedString(@"_server_response_error_", nil)], request.redirectedServer);
  1540. }
  1541. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  1542. failureRequest(response, error, request.redirectedServer);
  1543. }];
  1544. }
  1545. #pragma mark - End-to-End Encryption
  1546. - (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 {
  1547. serverPath = [serverPath stringByAppendingString:k_url_client_side_encryption];
  1548. serverPath = [serverPath stringByAppendingString:@"/public-key"];
  1549. serverPath = [serverPath stringByAppendingString:@"?format=json"];
  1550. OCWebDAVClient *request = [OCWebDAVClient new];
  1551. request = [self getRequestWithCredentials:request];
  1552. [request getEndToEndPublicKeys:serverPath onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
  1553. NSData *responseData = (NSData*) responseObject;
  1554. NSString *publicKey = @"";
  1555. //Parse
  1556. NSError *error;
  1557. NSDictionary *jsongParsed = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
  1558. NSLog(@"[LOG] E2E Get PublicKey : %@",jsongParsed);
  1559. if (jsongParsed && jsongParsed.allKeys > 0) {
  1560. NSDictionary *ocs = [jsongParsed valueForKey:@"ocs"];
  1561. NSDictionary *meta = [ocs valueForKey:@"meta"];
  1562. NSDictionary *data = [ocs valueForKey:@"data"];
  1563. NSInteger statusCode = [[meta valueForKey:@"statuscode"] integerValue];
  1564. if (statusCode == kOCUserProfileAPISuccessful) {
  1565. if ([data valueForKey:@"public-keys"] && ![[data valueForKey:@"public-keys"] isKindOfClass:[NSNull class]]) {
  1566. NSDictionary *publickeys = [data valueForKey:@"public-keys"];
  1567. publicKey = [publickeys valueForKey:self.userID];
  1568. successRequest(response, publicKey, request.redirectedServer);
  1569. } else {
  1570. failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedString(@"_server_response_error_", nil)], request.redirectedServer);
  1571. }
  1572. } else {
  1573. NSString *message = (NSString *)[meta objectForKey:@"message"];
  1574. if ([message isKindOfClass:[NSNull class]]) {
  1575. message = NSLocalizedString(@"_server_response_error_", nil);
  1576. }
  1577. failureRequest(response, [UtilsFramework getErrorWithCode:statusCode andCustomMessageFromTheServer:message], request.redirectedServer);
  1578. }
  1579. } else {
  1580. failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedString(@"_server_response_error_", nil)], request.redirectedServer);
  1581. }
  1582. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  1583. //Return error
  1584. failureRequest(response, error, request.redirectedServer);
  1585. }];
  1586. }
  1587. - (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 {
  1588. serverPath = [serverPath stringByAppendingString:k_url_client_side_encryption];
  1589. serverPath = [serverPath stringByAppendingString:@"/private-key"];
  1590. serverPath = [serverPath stringByAppendingString:@"?format=json"];
  1591. OCWebDAVClient *request = [OCWebDAVClient new];
  1592. request = [self getRequestWithCredentials:request];
  1593. [request getEndToEndPrivateKeyCipher:serverPath onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
  1594. NSData *responseData = (NSData*) responseObject;
  1595. NSString *privateKeyChiper = @"";
  1596. //Parse
  1597. NSError *error;
  1598. NSDictionary *jsongParsed = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
  1599. NSLog(@"[LOG] E2E Get PrivateKey : %@",jsongParsed);
  1600. if (jsongParsed && jsongParsed.allKeys > 0) {
  1601. NSDictionary *ocs = [jsongParsed valueForKey:@"ocs"];
  1602. NSDictionary *meta = [ocs valueForKey:@"meta"];
  1603. NSDictionary *data = [ocs valueForKey:@"data"];
  1604. NSInteger statusCode = [[meta valueForKey:@"statuscode"] integerValue];
  1605. if (statusCode == kOCUserProfileAPISuccessful) {
  1606. if ([data valueForKey:@"private-key"] && ![[data valueForKey:@"private-key"] isKindOfClass:[NSNull class]]) {
  1607. privateKeyChiper = [data valueForKey:@"private-key"];
  1608. successRequest(response, privateKeyChiper, request.redirectedServer);
  1609. } else {
  1610. failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedString(@"_server_response_error_", nil)], request.redirectedServer);
  1611. }
  1612. } else {
  1613. NSString *message = (NSString *)[meta objectForKey:@"message"];
  1614. if ([message isKindOfClass:[NSNull class]]) {
  1615. message = NSLocalizedString(@"_server_response_error_", nil);
  1616. }
  1617. failureRequest(response, [UtilsFramework getErrorWithCode:statusCode andCustomMessageFromTheServer:message], request.redirectedServer);
  1618. }
  1619. } else {
  1620. failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedString(@"_server_response_error_", nil)], request.redirectedServer);
  1621. }
  1622. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  1623. //Return error
  1624. failureRequest(response, error, request.redirectedServer);
  1625. }];
  1626. }
  1627. - (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 {
  1628. serverPath = [serverPath stringByAppendingString:k_url_client_side_encryption];
  1629. serverPath = [serverPath stringByAppendingString:@"/server-key"];
  1630. serverPath = [serverPath stringByAppendingString:@"?format=json"];
  1631. OCWebDAVClient *request = [OCWebDAVClient new];
  1632. request = [self getRequestWithCredentials:request];
  1633. [request getEndToEndServerPublicKey:serverPath onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
  1634. NSData *responseData = (NSData*) responseObject;
  1635. NSString *publicKey = @"";
  1636. //Parse
  1637. NSError *error;
  1638. NSDictionary *jsongParsed = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
  1639. NSLog(@"[LOG] E2E Get Server PublicKey : %@",jsongParsed);
  1640. if (jsongParsed && jsongParsed.allKeys > 0) {
  1641. NSDictionary *ocs = [jsongParsed valueForKey:@"ocs"];
  1642. NSDictionary *meta = [ocs valueForKey:@"meta"];
  1643. NSDictionary *data = [ocs valueForKey:@"data"];
  1644. NSInteger statusCode = [[meta valueForKey:@"statuscode"] integerValue];
  1645. if (statusCode == kOCUserProfileAPISuccessful) {
  1646. if ([data valueForKey:@"public-key"] && ![[data valueForKey:@"public-key"] isKindOfClass:[NSNull class]]) {
  1647. publicKey = [data valueForKey:@"public-key"];
  1648. successRequest(response, publicKey, request.redirectedServer);
  1649. } else {
  1650. failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedString(@"_server_response_error_", nil)], request.redirectedServer);
  1651. }
  1652. } else {
  1653. NSString *message = (NSString *)[meta objectForKey:@"message"];
  1654. if ([message isKindOfClass:[NSNull class]]) {
  1655. message = NSLocalizedString(@"_server_response_error_", nil);
  1656. }
  1657. failureRequest(response, [UtilsFramework getErrorWithCode:statusCode andCustomMessageFromTheServer:message], request.redirectedServer);
  1658. }
  1659. } else {
  1660. failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedString(@"_server_response_error_", nil)], request.redirectedServer);
  1661. }
  1662. //Return success
  1663. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  1664. //Return error
  1665. failureRequest(response, error, request.redirectedServer);
  1666. }];
  1667. }
  1668. - (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 {
  1669. serverPath = [serverPath stringByAppendingString:k_url_client_side_encryption];
  1670. serverPath = [serverPath stringByAppendingString:@"/public-key"];
  1671. serverPath = [serverPath stringByAppendingString:@"?format=json"];
  1672. OCWebDAVClient *request = [[OCWebDAVClient alloc] init];
  1673. request = [self getRequestWithCredentials:request];
  1674. [request signEndToEndPublicKey:serverPath key:publicKey onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
  1675. NSData *responseData = (NSData*) responseObject;
  1676. NSString *publicKey = @"";
  1677. //Parse
  1678. NSError *error;
  1679. NSDictionary *jsongParsed = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
  1680. NSLog(@"[LOG] E2E Sign PublicKey : %@",jsongParsed);
  1681. if (jsongParsed && jsongParsed.allKeys > 0) {
  1682. NSDictionary *ocs = [jsongParsed valueForKey:@"ocs"];
  1683. NSDictionary *meta = [ocs valueForKey:@"meta"];
  1684. NSDictionary *data = [ocs valueForKey:@"data"];
  1685. NSInteger statusCode = [[meta valueForKey:@"statuscode"] integerValue];
  1686. if (statusCode == kOCUserProfileAPISuccessful) {
  1687. if ([data valueForKey:@"public-key"] && ![[data valueForKey:@"public-key"] isKindOfClass:[NSNull class]]) {
  1688. publicKey = [data valueForKey:@"public-key"];
  1689. successRequest(response, publicKey, request.redirectedServer);
  1690. } else {
  1691. failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedString(@"_server_response_error_", nil)], request.redirectedServer);
  1692. }
  1693. } else {
  1694. NSString *message = (NSString *)[meta objectForKey:@"message"];
  1695. if ([message isKindOfClass:[NSNull class]]) {
  1696. message = NSLocalizedString(@"_server_response_error_", nil);
  1697. }
  1698. failureRequest(response, [UtilsFramework getErrorWithCode:statusCode andCustomMessageFromTheServer:message], request.redirectedServer);
  1699. }
  1700. } else {
  1701. failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedString(@"_server_response_error_", nil)], request.redirectedServer);
  1702. }
  1703. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  1704. //Return error
  1705. failureRequest(response, error, request.redirectedServer);
  1706. }];
  1707. }
  1708. - (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 {
  1709. serverPath = [serverPath stringByAppendingString:k_url_client_side_encryption];
  1710. serverPath = [serverPath stringByAppendingString:@"/private-key"];
  1711. serverPath = [serverPath stringByAppendingString:@"?format=json"];
  1712. OCWebDAVClient *request = [[OCWebDAVClient alloc] init];
  1713. request = [self getRequestWithCredentials:request];
  1714. [request storeEndToEndPrivateKeyCipher:serverPath key:privateKeyChiper onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
  1715. NSData *responseData = (NSData*) responseObject;
  1716. NSString *privateKey = @"";
  1717. //Parse
  1718. NSError *error;
  1719. NSDictionary *jsongParsed = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
  1720. NSLog(@"[LOG] E2E Store PrivateKey : %@",jsongParsed);
  1721. if (jsongParsed && jsongParsed.allKeys > 0) {
  1722. NSDictionary *ocs = [jsongParsed valueForKey:@"ocs"];
  1723. NSDictionary *meta = [ocs valueForKey:@"meta"];
  1724. NSDictionary *data = [ocs valueForKey:@"data"];
  1725. NSInteger statusCode = [[meta valueForKey:@"statuscode"] integerValue];
  1726. if (statusCode == kOCUserProfileAPISuccessful) {
  1727. if ([data valueForKey:@"private-key"] && ![[data valueForKey:@"private-key"] isKindOfClass:[NSNull class]]) {
  1728. privateKey = [data valueForKey:@"private-key"];
  1729. successRequest(response, privateKey, request.redirectedServer);
  1730. } else {
  1731. failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedString(@"_server_response_error_", nil)], request.redirectedServer);
  1732. }
  1733. } else {
  1734. NSString *message = (NSString *)[meta objectForKey:@"message"];
  1735. if ([message isKindOfClass:[NSNull class]]) {
  1736. message = NSLocalizedString(@"_server_response_error_", nil);
  1737. }
  1738. failureRequest(response, [UtilsFramework getErrorWithCode:statusCode andCustomMessageFromTheServer:message], request.redirectedServer);
  1739. }
  1740. } else {
  1741. failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedString(@"_server_response_error_", nil)], request.redirectedServer);
  1742. }
  1743. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  1744. //Return error
  1745. failureRequest(response, error, request.redirectedServer);
  1746. }];
  1747. }
  1748. - (void)deleteEndToEndPublicKey:(NSString*)serverPath onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
  1749. serverPath = [serverPath stringByAppendingString:k_url_client_side_encryption];
  1750. serverPath = [serverPath stringByAppendingString:@"/public-key"];
  1751. serverPath = [serverPath stringByAppendingString:@"?format=json"];
  1752. OCWebDAVClient *request = [OCWebDAVClient new];
  1753. request = [self getRequestWithCredentials:request];
  1754. [request deleteEndToEndPublicKey:serverPath onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
  1755. //Return success
  1756. successRequest(response, request.redirectedServer);
  1757. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  1758. //Return error
  1759. failureRequest(response, error, request.redirectedServer);
  1760. }];
  1761. }
  1762. - (void)deleteEndToEndPrivateKey:(NSString*)serverPath onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
  1763. serverPath = [serverPath stringByAppendingString:k_url_client_side_encryption];
  1764. serverPath = [serverPath stringByAppendingString:@"/private-key"];
  1765. serverPath = [serverPath stringByAppendingString:@"?format=json"];
  1766. OCWebDAVClient *request = [OCWebDAVClient new];
  1767. request = [self getRequestWithCredentials:request];
  1768. [request deleteEndToEndPrivateKey:serverPath onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
  1769. //Return success
  1770. successRequest(response, request.redirectedServer);
  1771. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  1772. //Return error
  1773. failureRequest(response, error, request.redirectedServer);
  1774. }];
  1775. }
  1776. - (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 {
  1777. serverPath = [serverPath stringByAppendingString:k_url_client_side_encryption];
  1778. serverPath = [NSString stringWithFormat:@"%@/encrypted/%@", serverPath, fileId];
  1779. serverPath = [serverPath stringByAppendingString:@"?format=json"];
  1780. OCWebDAVClient *request = [OCWebDAVClient new];
  1781. request = [self getRequestWithCredentials:request];
  1782. [request markEndToEndFolderEncrypted:serverPath onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
  1783. //Return success
  1784. successRequest(response, request.redirectedServer);
  1785. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  1786. //Return error
  1787. failureRequest(response, error, request.redirectedServer);
  1788. }];
  1789. }
  1790. - (void)deletemarkEndToEndFolderEncrypted:(NSString*)serverPath fileId:(NSString *)fileId e2eToken:(NSString *)e2eToken onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
  1791. serverPath = [serverPath stringByAppendingString:k_url_client_side_encryption];
  1792. serverPath = [NSString stringWithFormat:@"%@/encrypted/%@", serverPath, fileId];
  1793. serverPath = [serverPath stringByAppendingString:@"?format=json"];
  1794. OCWebDAVClient *request = [OCWebDAVClient new];
  1795. request = [self getRequestWithCredentials:request];
  1796. [request deletemarkEndToEndFolderEncrypted:serverPath e2eToken:e2eToken onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
  1797. //Return success
  1798. successRequest(response, request.redirectedServer);
  1799. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  1800. //Return error
  1801. failureRequest(response, error, request.redirectedServer);
  1802. }];
  1803. }
  1804. - (void)lockEndToEndFolderEncrypted:(NSString*)serverPath fileId:(NSString *)fileId e2eToken:(NSString *)e2eToken onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *e2eToken, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
  1805. serverPath = [serverPath stringByAppendingString:k_url_client_side_encryption];
  1806. serverPath = [NSString stringWithFormat:@"%@/lock/%@", serverPath, fileId];
  1807. if (e2eToken) {
  1808. serverPath = [NSString stringWithFormat:@"%@?e2e-token=%@", serverPath, e2eToken];
  1809. serverPath = [serverPath stringByAppendingString:@"&format=json"];
  1810. } else {
  1811. serverPath = [serverPath stringByAppendingString:@"?format=json"];
  1812. }
  1813. OCWebDAVClient *request = [OCWebDAVClient new];
  1814. request = [self getRequestWithCredentials:request];
  1815. [request lockEndToEndFolderEncrypted:serverPath e2eToken:e2eToken onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
  1816. NSData *responseData = (NSData*) responseObject;
  1817. NSString *token = @"";
  1818. //Parse
  1819. NSError *error;
  1820. NSDictionary *jsongParsed = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
  1821. NSLog(@"[LOG] E2E Lock File : %@",jsongParsed);
  1822. if (jsongParsed && jsongParsed.allKeys > 0) {
  1823. NSDictionary *ocs = [jsongParsed valueForKey:@"ocs"];
  1824. NSDictionary *meta = [ocs valueForKey:@"meta"];
  1825. NSDictionary *data = [ocs valueForKey:@"data"];
  1826. NSInteger statusCode = [[meta valueForKey:@"statuscode"] integerValue];
  1827. if (statusCode == kOCUserProfileAPISuccessful) {
  1828. if ([data valueForKey:@"e2e-token"] && ![[data valueForKey:@"e2e-token"] isKindOfClass:[NSNull class]]) {
  1829. token = [data valueForKey:@"e2e-token"];
  1830. successRequest(response, token, request.redirectedServer);
  1831. } else {
  1832. failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedString(@"_server_response_error_", nil)], request.redirectedServer);
  1833. }
  1834. } else {
  1835. NSString *message = (NSString *)[meta objectForKey:@"message"];
  1836. if ([message isKindOfClass:[NSNull class]]) {
  1837. message = NSLocalizedString(@"_server_response_error_", nil);
  1838. }
  1839. failureRequest(response, [UtilsFramework getErrorWithCode:statusCode andCustomMessageFromTheServer:message], request.redirectedServer);
  1840. }
  1841. } else {
  1842. failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedString(@"_server_response_error_", nil)], request.redirectedServer);
  1843. }
  1844. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  1845. //Return error
  1846. failureRequest(response, error, request.redirectedServer);
  1847. }];
  1848. }
  1849. - (void)unlockEndToEndFolderEncrypted:(NSString*)serverPath fileId:(NSString *)fileId e2eToken:(NSString *)e2eToken onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
  1850. serverPath = [serverPath stringByAppendingString:k_url_client_side_encryption];
  1851. serverPath = [NSString stringWithFormat:@"%@/lock/%@", serverPath, fileId];
  1852. serverPath = [serverPath stringByAppendingString:@"&format=json"];
  1853. OCWebDAVClient *request = [OCWebDAVClient new];
  1854. request = [self getRequestWithCredentials:request];
  1855. [request unlockEndToEndFolderEncrypted:serverPath e2eToken:e2eToken onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
  1856. //Return success
  1857. successRequest(response, request.redirectedServer);
  1858. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  1859. //Return error
  1860. failureRequest(response, error, request.redirectedServer);
  1861. }];
  1862. }
  1863. - (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 {
  1864. serverPath = [serverPath stringByAppendingString:k_url_client_side_encryption];
  1865. serverPath = [NSString stringWithFormat:@"%@/meta-data/%@", serverPath, fileId];
  1866. serverPath = [serverPath stringByAppendingString:@"?format=json"];
  1867. OCWebDAVClient *request = [[OCWebDAVClient alloc] init];
  1868. request = [self getRequestWithCredentials:request];
  1869. [request getEndToEndMetadata:serverPath onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
  1870. NSData *responseData = (NSData*) responseObject;
  1871. NSString *encryptedMetadata = @"";
  1872. //Parse
  1873. NSError *error;
  1874. NSDictionary *jsongParsed = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
  1875. NSLog(@"[LOG] E2E Get Metadata : %@",jsongParsed);
  1876. if (jsongParsed && jsongParsed.allKeys > 0) {
  1877. NSDictionary *ocs = [jsongParsed valueForKey:@"ocs"];
  1878. NSDictionary *meta = [ocs valueForKey:@"meta"];
  1879. NSDictionary *data = [ocs valueForKey:@"data"];
  1880. NSInteger statusCode = [[meta valueForKey:@"statuscode"] integerValue];
  1881. if (statusCode == kOCUserProfileAPISuccessful) {
  1882. if ([data valueForKey:@"meta-data"] && ![[data valueForKey:@"meta-data"] isKindOfClass:[NSNull class]]) {
  1883. encryptedMetadata = [data valueForKey:@"meta-data"];
  1884. successRequest(response, encryptedMetadata, request.redirectedServer);
  1885. } else {
  1886. failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedString(@"_server_response_error_", nil)], request.redirectedServer);
  1887. }
  1888. } else {
  1889. NSString *message = (NSString *)[meta objectForKey:@"message"];
  1890. if ([message isKindOfClass:[NSNull class]]) {
  1891. message = NSLocalizedString(@"_server_response_error_", nil);
  1892. }
  1893. failureRequest(response, [UtilsFramework getErrorWithCode:statusCode andCustomMessageFromTheServer:message], request.redirectedServer);
  1894. }
  1895. } else {
  1896. failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedString(@"_server_response_error_", nil)], request.redirectedServer);
  1897. }
  1898. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  1899. //Return error
  1900. failureRequest(response, error, request.redirectedServer);
  1901. }];
  1902. }
  1903. - (void)storeEndToEndMetadata:(NSString*)serverPath fileId:(NSString *)fileId e2eToken:(NSString *)e2eToken encryptedMetadata:(NSString *)encryptedMetadata onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *encryptedMetadata, NSString *redirectedServer))successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
  1904. encryptedMetadata = [encryptedMetadata encodeString:NSUTF8StringEncoding];
  1905. serverPath = [serverPath stringByAppendingString:k_url_client_side_encryption];
  1906. serverPath = [NSString stringWithFormat:@"%@/meta-data/%@", serverPath, fileId];
  1907. serverPath = [serverPath stringByAppendingString:@"?format=json"];
  1908. OCWebDAVClient *request = [[OCWebDAVClient alloc] init];
  1909. request = [self getRequestWithCredentials:request];
  1910. [request storeEndToEndMetadata:serverPath metadata:encryptedMetadata e2eToken:e2eToken onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
  1911. NSData *responseData = (NSData*) responseObject;
  1912. NSString *encryptedMetadata = @"";
  1913. //Parse
  1914. NSError *error;
  1915. NSDictionary *jsongParsed = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
  1916. NSLog(@"[LOG] E2E Store Metadata : %@",jsongParsed);
  1917. if (jsongParsed && jsongParsed.allKeys > 0) {
  1918. NSDictionary *ocs = [jsongParsed valueForKey:@"ocs"];
  1919. NSDictionary *meta = [ocs valueForKey:@"meta"];
  1920. NSDictionary *data = [ocs valueForKey:@"data"];
  1921. NSInteger statusCode = [[meta valueForKey:@"statuscode"] integerValue];
  1922. if (statusCode == kOCUserProfileAPISuccessful) {
  1923. if ([data valueForKey:@"meta-data"] && ![[data valueForKey:@"meta-data"] isKindOfClass:[NSNull class]]) {
  1924. encryptedMetadata = [data valueForKey:@"meta-data"];
  1925. successRequest(response, encryptedMetadata, request.redirectedServer);
  1926. } else {
  1927. failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedString(@"_server_response_error_", nil)], request.redirectedServer);
  1928. }
  1929. } else {
  1930. NSString *message = (NSString *)[meta objectForKey:@"message"];
  1931. if ([message isKindOfClass:[NSNull class]]) {
  1932. message = NSLocalizedString(@"_server_response_error_", nil);
  1933. }
  1934. failureRequest(response, [UtilsFramework getErrorWithCode:statusCode andCustomMessageFromTheServer:message], request.redirectedServer);
  1935. }
  1936. } else {
  1937. failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedString(@"_server_response_error_", nil)], request.redirectedServer);
  1938. }
  1939. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  1940. //Return error
  1941. failureRequest(response, error, request.redirectedServer);
  1942. }];
  1943. }
  1944. - (void)updateEndToEndMetadata:(NSString*)serverPath fileId:(NSString *)fileId encryptedMetadata:(NSString *)encryptedMetadata e2eToken:(NSString *)e2eToken onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *encryptedMetadata, NSString *redirectedServer))successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
  1945. encryptedMetadata = [encryptedMetadata encodeString:NSUTF8StringEncoding];
  1946. serverPath = [serverPath stringByAppendingString:k_url_client_side_encryption];
  1947. serverPath = [NSString stringWithFormat:@"%@/meta-data/%@", serverPath, fileId];
  1948. serverPath = [NSString stringWithFormat:@"%@?e2e-token=%@", serverPath, e2eToken];
  1949. serverPath = [serverPath stringByAppendingString:@"&format=json"];
  1950. OCWebDAVClient *request = [[OCWebDAVClient alloc] init];
  1951. request = [self getRequestWithCredentials:request];
  1952. [request updateEndToEndMetadata:serverPath metadata:encryptedMetadata e2eToken:e2eToken onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
  1953. NSData *responseData = (NSData*) responseObject;
  1954. NSString *encryptedMetadata = @"";
  1955. //Parse
  1956. NSError *error;
  1957. NSDictionary *jsongParsed = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
  1958. NSLog(@"[LOG] E2E Update Metadata : %@",jsongParsed);
  1959. if (jsongParsed && jsongParsed.allKeys > 0) {
  1960. NSDictionary *ocs = [jsongParsed valueForKey:@"ocs"];
  1961. NSDictionary *meta = [ocs valueForKey:@"meta"];
  1962. NSDictionary *data = [ocs valueForKey:@"data"];
  1963. NSInteger statusCode = [[meta valueForKey:@"statuscode"] integerValue];
  1964. if (statusCode == kOCUserProfileAPISuccessful) {
  1965. if ([data valueForKey:@"meta-data"] && ![[data valueForKey:@"meta-data"] isKindOfClass:[NSNull class]]) {
  1966. encryptedMetadata = [data valueForKey:@"meta-data"];
  1967. successRequest(response, encryptedMetadata, request.redirectedServer);
  1968. } else {
  1969. failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedString(@"_server_response_error_", nil)], request.redirectedServer);
  1970. }
  1971. } else {
  1972. NSString *message = (NSString *)[meta objectForKey:@"message"];
  1973. if ([message isKindOfClass:[NSNull class]]) {
  1974. message = NSLocalizedString(@"_server_response_error_", nil);
  1975. }
  1976. failureRequest(response, [UtilsFramework getErrorWithCode:statusCode andCustomMessageFromTheServer:message], request.redirectedServer);
  1977. }
  1978. } else {
  1979. failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedString(@"_server_response_error_", nil)], request.redirectedServer);
  1980. }
  1981. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  1982. //Return error
  1983. failureRequest(response, error, request.redirectedServer);
  1984. }];
  1985. }
  1986. - (void)deleteEndToEndMetadata:(NSString*)serverPath fileId:(NSString *)fileId e2eToken:(NSString *)e2eToken onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer))successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
  1987. serverPath = [serverPath stringByAppendingString:k_url_client_side_encryption];
  1988. serverPath = [NSString stringWithFormat:@"%@/meta-data/%@", serverPath, fileId];
  1989. serverPath = [serverPath stringByAppendingString:@"?format=json"];
  1990. OCWebDAVClient *request = [[OCWebDAVClient alloc] init];
  1991. request = [self getRequestWithCredentials:request];
  1992. [request deleteEndToEndMetadata:serverPath e2eToken:e2eToken onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
  1993. //Return success
  1994. successRequest(response, request.redirectedServer);
  1995. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  1996. //Return error
  1997. failureRequest(response, error, request.redirectedServer);
  1998. }];
  1999. }
  2000. #pragma mark - Manage Mobile Editor OCS API
  2001. - (void)createLinkRichdocuments:(NSString *)serverPath fileId:(NSString *)fileId onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *link, NSString *redirectedServer))successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
  2002. serverPath = [serverPath stringByAppendingString:k_url_create_link_mobile_richdocuments];
  2003. serverPath = [serverPath stringByAppendingString:@"?format=json"];
  2004. OCWebDAVClient *request = [[OCWebDAVClient alloc] init];
  2005. request = [self getRequestWithCredentials:request];
  2006. [request createLinkRichdocuments:serverPath fileId:fileId onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *operation, id response) {
  2007. NSData *responseData = (NSData*) response;
  2008. //Parse
  2009. NSError *error;
  2010. NSDictionary *jsongParsed = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
  2011. NSLog(@"[LOG] Link richdocuments : %@",jsongParsed);
  2012. if (jsongParsed && jsongParsed.allKeys > 0) {
  2013. NSDictionary *ocs = [jsongParsed valueForKey:@"ocs"];
  2014. NSDictionary *meta = [ocs valueForKey:@"meta"];
  2015. NSDictionary *data = [ocs valueForKey:@"data"];
  2016. NSInteger statusCode = [[meta valueForKey:@"statuscode"] integerValue];
  2017. if (statusCode == kOCUserProfileAPISuccessful) {
  2018. if ([data valueForKey:@"url"] && ![[data valueForKey:@"url"] isKindOfClass:[NSNull class]]) {
  2019. NSString *link = [data valueForKey:@"url"];
  2020. successRequest(response, link, request.redirectedServer);
  2021. } else {
  2022. failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedString(@"_server_response_error_", nil)], request.redirectedServer);
  2023. }
  2024. } else {
  2025. NSString *message = (NSString *)[meta objectForKey:@"message"];
  2026. if ([message isKindOfClass:[NSNull class]]) {
  2027. message = NSLocalizedString(@"_server_response_error_", nil);
  2028. }
  2029. failureRequest(response, [UtilsFramework getErrorWithCode:statusCode andCustomMessageFromTheServer:message], request.redirectedServer);
  2030. }
  2031. } else {
  2032. failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedString(@"_server_response_error_", nil)], request.redirectedServer);
  2033. }
  2034. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  2035. //Return error
  2036. failureRequest(response, error, request.redirectedServer);
  2037. }];
  2038. }
  2039. - (void)getTemplatesRichdocuments:(NSString *)serverPath typeTemplate:(NSString *)typeTemplate onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSArray *listOfTemplate, NSString *redirectedServer))successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
  2040. serverPath = [serverPath stringByAppendingString:k_url_get_template_mobile_richdocuments];
  2041. serverPath = [serverPath stringByAppendingString:typeTemplate];
  2042. serverPath = [serverPath stringByAppendingString:@"?format=json"];
  2043. OCWebDAVClient *request = [[OCWebDAVClient alloc] init];
  2044. request = [self getRequestWithCredentials:request];
  2045. [request getTemplatesRichdocuments:serverPath onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *operation, id response) {
  2046. NSData *responseData = (NSData*) response;
  2047. //Parse
  2048. NSError *error;
  2049. NSDictionary *jsongParsed = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
  2050. NSLog(@"[LOG] Link richdocuments : %@",jsongParsed);
  2051. if (jsongParsed && jsongParsed.allKeys > 0) {
  2052. NSMutableArray *list = [NSMutableArray new];
  2053. NSDictionary *ocs = [jsongParsed valueForKey:@"ocs"];
  2054. NSDictionary *meta = [ocs valueForKey:@"meta"];
  2055. NSDictionary *data = [ocs valueForKey:@"data"];
  2056. NSInteger statusCode = [[meta valueForKey:@"statuscode"] integerValue];
  2057. if (statusCode == kOCUserProfileAPISuccessful) {
  2058. for (NSDictionary *dicDatas in data) {
  2059. NCRichDocumentTemplate *template = [NCRichDocumentTemplate new];
  2060. if ([dicDatas valueForKey:@"id"] && ![[dicDatas valueForKey:@"id"] isEqual:[NSNull null]])
  2061. template.templateID = [[dicDatas valueForKey:@"id"] integerValue];
  2062. if ([dicDatas valueForKey:@"delete"] && ![[dicDatas valueForKey:@"delete"] isKindOfClass:[NSNull class]])
  2063. template.delete = [dicDatas valueForKey:@"delete"];
  2064. if ([dicDatas valueForKey:@"extension"] && ![[dicDatas valueForKey:@"extension"] isKindOfClass:[NSNull class]])
  2065. template.extension = [dicDatas valueForKey:@"extension"];
  2066. if ([dicDatas valueForKey:@"name"] && ![[dicDatas valueForKey:@"name"] isKindOfClass:[NSNull class]])
  2067. template.name = [dicDatas valueForKey:@"name"];
  2068. if ([dicDatas valueForKey:@"preview"] && ![[dicDatas valueForKey:@"preview"] isKindOfClass:[NSNull class]])
  2069. template.preview = [dicDatas valueForKey:@"preview"];
  2070. if ([dicDatas valueForKey:@"type"] && ![[dicDatas valueForKey:@"type"] isKindOfClass:[NSNull class]])
  2071. template.type = [dicDatas valueForKey:@"type"];
  2072. [list addObject:template];
  2073. }
  2074. successRequest(response, list, request.redirectedServer);
  2075. } else {
  2076. NSString *message = (NSString *)[meta objectForKey:@"message"];
  2077. if ([message isKindOfClass:[NSNull class]]) {
  2078. message = NSLocalizedString(@"_server_response_error_", nil);
  2079. }
  2080. failureRequest(response, [UtilsFramework getErrorWithCode:statusCode andCustomMessageFromTheServer:message], request.redirectedServer);
  2081. }
  2082. } else {
  2083. failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedString(@"_server_response_error_", nil)], request.redirectedServer);
  2084. }
  2085. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  2086. //Return error
  2087. failureRequest(response, error, request.redirectedServer);
  2088. }];
  2089. }
  2090. - (void)createNewRichdocuments:(NSString *)serverPath path:(NSString *)path templateID:(NSString *)templateID onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *url, NSString *redirectedServer))successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
  2091. serverPath = [serverPath stringByAppendingString:k_url_create_new_mobile_richdocuments];
  2092. serverPath = [serverPath stringByAppendingString:@"?format=json"];
  2093. OCWebDAVClient *request = [[OCWebDAVClient alloc] init];
  2094. request = [self getRequestWithCredentials:request];
  2095. [request createNewRichdocuments:serverPath path:path templateID:templateID onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *operation, id response) {
  2096. NSData *responseData = (NSData*) response;
  2097. //Parse
  2098. NSError *error;
  2099. NSDictionary *jsongParsed = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
  2100. NSLog(@"[LOG] URL Asset : %@",jsongParsed);
  2101. NSDictionary *ocs = [jsongParsed valueForKey:@"ocs"];
  2102. NSDictionary *meta = [ocs valueForKey:@"meta"];
  2103. NSDictionary *data = [ocs valueForKey:@"data"];
  2104. NSInteger statusCode = [[meta valueForKey:@"statuscode"] integerValue];
  2105. if (statusCode == kOCUserProfileAPISuccessful) {
  2106. if ([data valueForKey:@"url"] && ![[data valueForKey:@"url"] isKindOfClass:[NSNull class]])
  2107. successRequest(response, [data valueForKey:@"url"], request.redirectedServer);
  2108. else
  2109. successRequest(response, nil, request.redirectedServer);
  2110. } else {
  2111. failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedString(@"_server_response_error_", nil)], request.redirectedServer);
  2112. }
  2113. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  2114. //Return error
  2115. failureRequest(response, error, request.redirectedServer);
  2116. }];
  2117. }
  2118. - (void)createAssetRichdocuments:(NSString *)serverPath path:(NSString *)path onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *url, NSString *redirectedServer))successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
  2119. serverPath = [serverPath stringByAppendingString:k_url_insert_assets_to_richdocuments];
  2120. serverPath = [serverPath stringByAppendingString:@"?format=json"];
  2121. OCWebDAVClient *request = [[OCWebDAVClient alloc] init];
  2122. request = [self getRequestWithCredentials:request];
  2123. [request createAssetRichdocuments:serverPath path:path onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *operation, id response) {
  2124. NSData *responseData = (NSData*) response;
  2125. //Parse
  2126. NSError *error;
  2127. NSDictionary *jsongParsed = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
  2128. NSLog(@"[LOG] URL Asset : %@",jsongParsed);
  2129. if (jsongParsed && jsongParsed.allKeys > 0) {
  2130. if ([jsongParsed valueForKey:@"url"] && ![[jsongParsed valueForKey:@"url"] isKindOfClass:[NSNull class]]) {
  2131. NSString *url = [jsongParsed valueForKey:@"url"];
  2132. successRequest(response, url, request.redirectedServer);
  2133. } else {
  2134. failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedString(@"_server_response_error_", nil)], request.redirectedServer);
  2135. }
  2136. } else {
  2137. failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedString(@"_server_response_error_", nil)], request.redirectedServer);
  2138. }
  2139. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  2140. //Return error
  2141. failureRequest(response, error, request.redirectedServer);
  2142. }];
  2143. }
  2144. #pragma mark - Trash
  2145. - (void)listingTrash:(NSString *)path depth:(NSString *)depth onCommunication:(OCCommunication *)sharedOCCommunication successRequest:(void(^)(NSHTTPURLResponse *response, NSArray *items, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest
  2146. {
  2147. OCWebDAVClient *request = [OCWebDAVClient new];
  2148. request = [self getRequestWithCredentials:request];
  2149. path = [path encodeString:NSUTF8StringEncoding];
  2150. [request listTrash:path depth:depth onCommunication:sharedOCCommunication success:^(NSHTTPURLResponse *response, id responseObject) {
  2151. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
  2152. NCXMLListParser *parser = [NCXMLListParser new];
  2153. [parser initParserWithData:responseObject controlFirstFileOfList:true];
  2154. NSMutableArray *list = [parser.list mutableCopy];
  2155. dispatch_async(dispatch_get_main_queue(), ^{
  2156. successRequest(response, list, request.redirectedServer);
  2157. });
  2158. });
  2159. } failure:^(NSHTTPURLResponse *response, id responseData, NSError *error) {
  2160. failureRequest(response, error, request.redirectedServer);
  2161. }];
  2162. }
  2163. - (void)emptyTrash:(NSString *)path onCommunication:(OCCommunication *)sharedOCCommunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest
  2164. {
  2165. OCWebDAVClient *request = [OCWebDAVClient new];
  2166. request = [self getRequestWithCredentials:request];
  2167. [request emptyTrash:path onCommunication:sharedOCCommunication success:^(NSHTTPURLResponse *response, id responseObject) {
  2168. successRequest(response, request.redirectedServer);
  2169. } failure:^(NSHTTPURLResponse *response, id responseData, NSError *error) {
  2170. failureRequest(response, error, request.redirectedServer);
  2171. }];
  2172. }
  2173. #pragma mark - Fulltextsearch
  2174. - (void)fullTextSearch:(NSString *)serverPath data:(NSString *)data onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSArray *items, NSString *redirectedServer))successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
  2175. serverPath = [serverPath stringByAppendingString:k_url_fulltextsearch];
  2176. OCWebDAVClient *request = [[OCWebDAVClient alloc] init];
  2177. request = [self getRequestWithCredentials:request];
  2178. [request fullTextSearch:serverPath data:data onCommunication:sharedOCComunication success:^(NSHTTPURLResponse * _Nonnull operation, id _Nonnull response) {
  2179. NSData *responseData = (NSData*) response;
  2180. //Parse
  2181. NSError *error;
  2182. NSDictionary *jsongParsed = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
  2183. NSLog(@"[LOG] Link richdocuments : %@",jsongParsed);
  2184. if (jsongParsed && jsongParsed.allKeys > 0) {
  2185. successRequest(response, nil, request.redirectedServer);
  2186. } else {
  2187. failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedString(@"_server_response_error_", nil)], request.redirectedServer);
  2188. }
  2189. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  2190. //Return error
  2191. failureRequest(response, error, request.redirectedServer);
  2192. }];
  2193. }
  2194. #pragma mark - Remore wipe
  2195. - (void)getRemoteWipeStatus:(NSString *)serverPath token:(NSString *)token onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, BOOL wipe, NSString *redirectedServer))successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
  2196. serverPath = [NSString stringWithFormat:@"%@/%@/check", serverPath, k_url_get_wipe];
  2197. OCWebDAVClient *request = [[OCWebDAVClient alloc] init];
  2198. request = [self getRequestWithCredentials:request];
  2199. [request getSetRemoteWipe:serverPath token:token onCommunication:sharedOCComunication success:^(NSHTTPURLResponse * _Nonnull operation, id _Nonnull response) {
  2200. NSData *responseData = (NSData*) response;
  2201. //Parse
  2202. NSError *error;
  2203. NSDictionary *jsongParsed = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
  2204. if (jsongParsed && jsongParsed.allKeys > 0) {
  2205. BOOL wipe = (BOOL)[jsongParsed valueForKey:@"wipe"];
  2206. successRequest(response, wipe, request.redirectedServer);
  2207. } else {
  2208. failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedString(@"_server_response_error_", nil)], request.redirectedServer);
  2209. }
  2210. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  2211. //Return error
  2212. failureRequest(response, error, request.redirectedServer);
  2213. }];
  2214. }
  2215. - (void)setRemoteWipeCompletition:(NSString *)serverPath token:(NSString *)token onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer))successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
  2216. serverPath = [NSString stringWithFormat:@"%@/%@/success", serverPath, k_url_get_wipe];
  2217. OCWebDAVClient *request = [[OCWebDAVClient alloc] init];
  2218. request = [self getRequestWithCredentials:request];
  2219. [request getSetRemoteWipe:serverPath token:token onCommunication:sharedOCComunication success:^(NSHTTPURLResponse * _Nonnull operation, id _Nonnull response) {
  2220. successRequest(response, request.redirectedServer);
  2221. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  2222. failureRequest(response, error, request.redirectedServer);
  2223. }];
  2224. }
  2225. #pragma mark - Comments
  2226. - (void)getComments:(NSString *)serverPath fileId:(NSString *)fileId onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSArray *list, NSString *redirectedServer))successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
  2227. serverPath = [NSString stringWithFormat:@"%@/comments/files/%@", serverPath, fileId];
  2228. serverPath = [serverPath encodeString:NSUTF8StringEncoding];
  2229. OCWebDAVClient *request = [OCWebDAVClient new];
  2230. request = [self getRequestWithCredentials:request];
  2231. [request getComments:serverPath onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
  2232. NSData *responseData = (NSData *)responseObject;
  2233. NCXMLCommentsParser *parser = [NCXMLCommentsParser new];
  2234. [parser initParserWithData:responseData];
  2235. NSMutableArray *list = [parser.list mutableCopy];
  2236. successRequest(response, list, request.redirectedServer);
  2237. } failure:^(NSHTTPURLResponse *response, id responseData, NSError *error) {
  2238. failureRequest(response, error, request.redirectedServer);
  2239. }];
  2240. }
  2241. - (void)putComments:(NSString*)serverPath fileId:(NSString *)fileId message:(NSString *)message onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer))successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
  2242. serverPath = [NSString stringWithFormat:@"%@/comments/files/%@", serverPath, fileId];
  2243. serverPath = [serverPath encodeString:NSUTF8StringEncoding];
  2244. OCWebDAVClient *request = [[OCWebDAVClient alloc] init];
  2245. request = [self getRequestWithCredentials:request];
  2246. [request putComments:serverPath message:message onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *operation, id response) {
  2247. successRequest(response, request.redirectedServer);
  2248. } failure:^(NSHTTPURLResponse *response, id responseObject, NSError *error) {
  2249. failureRequest(response, error, request.redirectedServer);
  2250. }];
  2251. }
  2252. - (void)updateComments:(NSString*)serverPath fileId:(NSString *)fileId messageID:(NSString *)messageID message:(NSString *)message onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer))successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
  2253. serverPath = [NSString stringWithFormat:@"%@/comments/files/%@/%@", serverPath, fileId, messageID];
  2254. serverPath = [serverPath encodeString:NSUTF8StringEncoding];
  2255. OCWebDAVClient *request = [[OCWebDAVClient alloc] init];
  2256. request = [self getRequestWithCredentials:request];
  2257. [request updateComments:serverPath message:message onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *operation, id response) {
  2258. successRequest(response, request.redirectedServer);
  2259. } failure:^(NSHTTPURLResponse *response, id responseObject, NSError *error) {
  2260. failureRequest(response, error, request.redirectedServer);
  2261. }];
  2262. }
  2263. - (void)readMarkComments:(NSString*)serverPath fileId:(NSString *)fileId onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer))successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
  2264. serverPath = [NSString stringWithFormat:@"%@/comments/files/%@", serverPath, fileId];
  2265. serverPath = [serverPath encodeString:NSUTF8StringEncoding];
  2266. OCWebDAVClient *request = [[OCWebDAVClient alloc] init];
  2267. request = [self getRequestWithCredentials:request];
  2268. [request readMarkComments:serverPath onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *operation, id response) {
  2269. successRequest(response, request.redirectedServer);
  2270. } failure:^(NSHTTPURLResponse *response, id responseObject, NSError *error) {
  2271. failureRequest(response, error, request.redirectedServer);
  2272. }];
  2273. }
  2274. - (void)deleteComments:(NSString*)serverPath fileId:(NSString *)fileId messageID:(NSString *)messageID onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer))successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
  2275. serverPath = [NSString stringWithFormat:@"%@/comments/files/%@/%@", serverPath, fileId, messageID];
  2276. serverPath = [serverPath encodeString:NSUTF8StringEncoding];
  2277. OCWebDAVClient *request = [[OCWebDAVClient alloc] init];
  2278. request = [self getRequestWithCredentials:request];
  2279. [request deleteComments:serverPath onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *operation, id response) {
  2280. successRequest(response, request.redirectedServer);
  2281. } failure:^(NSHTTPURLResponse *response, id responseObject, NSError *error) {
  2282. failureRequest(response, error, request.redirectedServer);
  2283. }];
  2284. }
  2285. #pragma mark - Third Parts
  2286. - (void)getHCUserProfile:(NSString *)serverPath onCommunication:(OCCommunication *)sharedOCCommunication successRequest:(void(^)(NSHTTPURLResponse *response, OCUserProfile *userProfile, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest
  2287. {
  2288. serverPath = [serverPath encodeString:NSUTF8StringEncoding];
  2289. OCWebDAVClient *request = [OCWebDAVClient new];
  2290. request = [self getRequestWithCredentials:request];
  2291. [request getHCUserProfile:serverPath onCommunication:sharedOCCommunication success:^(NSHTTPURLResponse * _Nonnull operation, id _Nonnull response) {
  2292. NSData *responseData = (NSData*) response;
  2293. OCUserProfile *userProfile = [OCUserProfile new];
  2294. //Parse
  2295. NSError *error;
  2296. NSDictionary *jsongParsed = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
  2297. NSLog(@"[LOG] User Profile : %@",jsongParsed);
  2298. if (jsongParsed && jsongParsed.allKeys > 0) {
  2299. NSDictionary *ocs = [jsongParsed valueForKey:@"ocs"];
  2300. NSDictionary *meta = [ocs valueForKey:@"meta"];
  2301. NSDictionary *data = [ocs valueForKey:@"data"];
  2302. NSInteger statusCode = [[meta valueForKey:@"statuscode"] integerValue];
  2303. data = [data valueForKey:@"data"];
  2304. if (statusCode == kOCUserProfileAPISuccessful) {
  2305. if ([data valueForKey:@"address"] && ![[data valueForKey:@"address"] isKindOfClass:[NSNull class]])
  2306. userProfile.address = [data valueForKey:@"address"];
  2307. if ([data valueForKey:@"displayname"] && ![[data valueForKey:@"displayname"] isKindOfClass:[NSNull class]])
  2308. userProfile.displayName = [data valueForKey:@"displayname"];
  2309. if ([data valueForKey:@"businesssize"] && ![[data valueForKey:@"businesssize"] isKindOfClass:[NSNull class]]) {
  2310. switch ([[data valueForKey:@"businesssize"] integerValue]) {
  2311. case 1:
  2312. userProfile.businessSize = @"1-4";
  2313. break;
  2314. case 5:
  2315. userProfile.businessSize = @"5-9";
  2316. break;
  2317. case 10:
  2318. userProfile.businessSize = @"10-19";
  2319. break;
  2320. case 20:
  2321. userProfile.businessSize = @"20-49";
  2322. break;
  2323. case 50:
  2324. userProfile.businessSize = @"50-99";
  2325. break;
  2326. case 100:
  2327. userProfile.businessSize = @"100-249";
  2328. break;
  2329. case 250:
  2330. userProfile.businessSize = @"250-499";
  2331. break;
  2332. case 500:
  2333. userProfile.businessSize = @"500-999";
  2334. break;
  2335. case 1000:
  2336. userProfile.businessSize = @"1000+";
  2337. break;
  2338. default:
  2339. break;
  2340. }
  2341. }
  2342. if ([data valueForKey:@"businesstype"] && ![[data valueForKey:@"businesstype"] isKindOfClass:[NSNull class]])
  2343. userProfile.businessType = [data valueForKey:@"businesstype"];
  2344. if ([data valueForKey:@"city"] && ![[data valueForKey:@"city"] isKindOfClass:[NSNull class]])
  2345. userProfile.city = [data valueForKey:@"city"];
  2346. if ([data valueForKey:@"company"] && ![[data valueForKey:@"company"] isKindOfClass:[NSNull class]])
  2347. userProfile.company = [data valueForKey:@"company"];
  2348. if ([data valueForKey:@"country"] && ![[data valueForKey:@"country"] isKindOfClass:[NSNull class]])
  2349. userProfile.country = [data valueForKey:@"country"];
  2350. if ([data valueForKey:@"email"] && ![[data valueForKey:@"email"] isKindOfClass:[NSNull class]])
  2351. userProfile.email = [data valueForKey:@"email"];
  2352. if ([data valueForKey:@"phone"] && ![[data valueForKey:@"phone"] isKindOfClass:[NSNull class]])
  2353. userProfile.phone = [data valueForKey:@"phone"];
  2354. if ([data valueForKey:@"role"] && ![[data valueForKey:@"role"] isKindOfClass:[NSNull class]])
  2355. userProfile.role = [data valueForKey:@"role"];
  2356. if ([data valueForKey:@"twitter"] && ![[data valueForKey:@"twitter"] isKindOfClass:[NSNull class]])
  2357. userProfile.twitter = [data valueForKey:@"twitter"];
  2358. if ([data valueForKey:@"website"] && ![[data valueForKey:@"website"] isKindOfClass:[NSNull class]])
  2359. userProfile.webpage = [data valueForKey:@"website"];
  2360. if ([data valueForKey:@"zip"] && ![[data valueForKey:@"zip"] isKindOfClass:[NSNull class]])
  2361. userProfile.zip = [data valueForKey:@"zip"];
  2362. successRequest(response, userProfile, request.redirectedServer);
  2363. } else {
  2364. NSString *message = (NSString *)[meta objectForKey:@"message"];
  2365. if ([message isKindOfClass:[NSNull class]]) {
  2366. message = NSLocalizedString(@"_server_response_error_", nil);
  2367. }
  2368. failureRequest(response, [UtilsFramework getErrorWithCode:statusCode andCustomMessageFromTheServer:message], request.redirectedServer);
  2369. }
  2370. } else {
  2371. failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedString(@"_server_response_error_", nil)], request.redirectedServer);
  2372. }
  2373. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  2374. failureRequest(response, error, request.redirectedServer);
  2375. }];
  2376. }
  2377. - (void)putHCUserProfile:(NSString*)serverPath data:(NSString *)data onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer))successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
  2378. serverPath = [serverPath encodeString:NSUTF8StringEncoding];
  2379. OCWebDAVClient *request = [[OCWebDAVClient alloc] init];
  2380. request = [self getRequestWithCredentials:request];
  2381. [request putHCUserProfile:serverPath data:data onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *operation, id response) {
  2382. successRequest(response, request.redirectedServer);
  2383. } failure:^(NSHTTPURLResponse *response, id responseObject, NSError *error) {
  2384. failureRequest(response, error, request.redirectedServer);
  2385. }];
  2386. }
  2387. - (void)getHCFeatures:(NSString *)serverPath onCommunication:(OCCommunication *)sharedOCCommunication successRequest:(void(^)(NSHTTPURLResponse *response, HCFeatures *features, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest
  2388. {
  2389. serverPath = [serverPath encodeString:NSUTF8StringEncoding];
  2390. OCWebDAVClient *request = [OCWebDAVClient new];
  2391. request = [self getRequestWithCredentials:request];
  2392. [request getHCUserProfile:serverPath onCommunication:sharedOCCommunication success:^(NSHTTPURLResponse * _Nonnull operation, id _Nonnull response) {
  2393. NSData *responseData = (NSData*) response;
  2394. HCFeatures *features = [HCFeatures new];
  2395. //Parse
  2396. NSError *error;
  2397. NSDictionary *jsongParsed = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
  2398. NSLog(@"[LOG] User Profile Features : %@",jsongParsed);
  2399. if (jsongParsed && jsongParsed.allKeys > 0) {
  2400. NSDictionary *ocs = [jsongParsed valueForKey:@"ocs"];
  2401. NSDictionary *meta = [ocs valueForKey:@"meta"];
  2402. NSDictionary *data = [ocs valueForKey:@"data"];
  2403. NSInteger statusCode = [[meta valueForKey:@"statuscode"] integerValue];
  2404. data = [data valueForKey:@"data"];
  2405. if (statusCode == kOCUserProfileAPISuccessful) {
  2406. if ([data valueForKey:@"is_trial"] && ![[data valueForKey:@"is_trial"] isKindOfClass:[NSNull class]])
  2407. features.isTrial = [[data valueForKey:@"is_trial"] boolValue];
  2408. if ([data valueForKey:@"trial_expired"] && ![[data valueForKey:@"trial_expired"] isKindOfClass:[NSNull class]])
  2409. features.trialExpired = [[data valueForKey:@"trial_expired"] boolValue];
  2410. if ([data valueForKey:@"trial_remaining_sec"] && ![[data valueForKey:@"trial_remaining_sec"] isKindOfClass:[NSNull class]])
  2411. features.trialRemainingSec = [[data valueForKey:@"trial_remaining_sec"] integerValue];
  2412. if ([data valueForKey:@"trial_end_time"] && ![[data valueForKey:@"trial_end_time"] isKindOfClass:[NSNull class]])
  2413. features.trialEndTime = [[data valueForKey:@"trial_end_time"] integerValue];
  2414. if ([data valueForKey:@"trial_end"] && ![[data valueForKey:@"trial_end"] isKindOfClass:[NSNull class]])
  2415. features.trialEnd = [data valueForKey:@"trial_end"];
  2416. if ([data valueForKey:@"account_remove_expired"] && ![[data valueForKey:@"account_remove_expired"] isKindOfClass:[NSNull class]])
  2417. features.accountRemoveExpired = [[data valueForKey:@"account_remove_expired"] boolValue];
  2418. if ([data valueForKey:@"account_remove_remaining_sec"] && ![[data valueForKey:@"account_remove_remaining_sec"] isKindOfClass:[NSNull class]])
  2419. features.accountRemoveRemainingSec = [[data valueForKey:@"account_remove_remaining_sec"] integerValue];
  2420. if ([data valueForKey:@"account_remove_time"] && ![[data valueForKey:@"account_remove_time"] isKindOfClass:[NSNull class]])
  2421. features.accountRemoveTime = [[data valueForKey:@"account_remove_time"] integerValue];
  2422. if ([data valueForKey:@"account_remove"] && ![[data valueForKey:@"account_remove"] isKindOfClass:[NSNull class]])
  2423. features.accountRemove = [data valueForKey:@"account_remove"];
  2424. NSDictionary *nextGroupExpirationDic = [data valueForKey:@"next_group_expiration"];
  2425. if (nextGroupExpirationDic) {
  2426. if ([nextGroupExpirationDic valueForKey:@"group"] && ![[nextGroupExpirationDic valueForKey:@"group"] isKindOfClass:[NSNull class]])
  2427. features.nextGroupExpirationGroup = [nextGroupExpirationDic valueForKey:@"group"];
  2428. if ([nextGroupExpirationDic valueForKey:@"group_expired"] && ![[nextGroupExpirationDic valueForKey:@"group_expired"] isKindOfClass:[NSNull class]])
  2429. features.nextGroupExpirationGroupExpired = [[nextGroupExpirationDic valueForKey:@"group_expired"] boolValue];
  2430. if ([nextGroupExpirationDic valueForKey:@"expires_time"] && ![[nextGroupExpirationDic valueForKey:@"expires_time"] isKindOfClass:[NSNull class]])
  2431. features.nextGroupExpirationExpiresTime = [[nextGroupExpirationDic valueForKey:@"expires_time"] integerValue];
  2432. if ([nextGroupExpirationDic valueForKey:@"expires"] && ![[nextGroupExpirationDic valueForKey:@"expires"] isKindOfClass:[NSNull class]])
  2433. features.nextGroupExpirationExpires = [nextGroupExpirationDic valueForKey:@"expires"];
  2434. }
  2435. successRequest(response, features, request.redirectedServer);
  2436. } else {
  2437. NSString *message = (NSString *)[meta objectForKey:@"message"];
  2438. if ([message isKindOfClass:[NSNull class]]) {
  2439. message = NSLocalizedString(@"_server_response_error_", nil);
  2440. }
  2441. failureRequest(response, [UtilsFramework getErrorWithCode:statusCode andCustomMessageFromTheServer:message], request.redirectedServer);
  2442. }
  2443. } else {
  2444. failureRequest(response, [UtilsFramework getErrorWithCode:k_CCErrorWebdavResponseError andCustomMessageFromTheServer:NSLocalizedString(@"_server_response_error_", nil)], request.redirectedServer);
  2445. }
  2446. } failure:^(NSHTTPURLResponse *response, NSData *responseData, NSError *error) {
  2447. failureRequest(response, error, request.redirectedServer);
  2448. }];
  2449. }
  2450. #pragma mark - Manage Mobile Editor OCS API
  2451. - (void)eraseURLCache
  2452. {
  2453. [[NSURLCache sharedURLCache] setMemoryCapacity:0];
  2454. [[NSURLCache sharedURLCache] setDiskCapacity:0];
  2455. }
  2456. #pragma mark - Utils
  2457. - (void) addUserItemOfType:(NSInteger) shareeType fromArray:(NSArray*) usersArray ToList: (NSMutableArray *) itemList
  2458. {
  2459. for (NSDictionary *userFound in usersArray) {
  2460. OCShareUser *user = [OCShareUser new];
  2461. if ([[userFound valueForKey:@"label"] isKindOfClass:[NSNumber class]]) {
  2462. NSNumber *number = [userFound valueForKey:@"label"];
  2463. user.displayName = [NSString stringWithFormat:@"%ld", number.longValue];
  2464. }else{
  2465. user.displayName = [userFound valueForKey:@"label"];
  2466. }
  2467. NSDictionary *userValues = [userFound valueForKey:@"value"];
  2468. if ([[userValues valueForKey:@"shareWith"] isKindOfClass:[NSNumber class]]) {
  2469. NSNumber *number = [userValues valueForKey:@"shareWith"];
  2470. user.name = [NSString stringWithFormat:@"%ld", number.longValue];
  2471. }else{
  2472. user.name = [userValues valueForKey:@"shareWith"];
  2473. }
  2474. user.shareeType = shareeType;
  2475. user.server = [userValues valueForKey:@"server"];
  2476. [itemList addObject:user];
  2477. }
  2478. }
  2479. - (void) addGroupItemFromArray:(NSArray*) groupsArray ToList: (NSMutableArray *) itemList
  2480. {
  2481. for (NSDictionary *groupFound in groupsArray) {
  2482. OCShareUser *group = [OCShareUser new];
  2483. NSDictionary *groupValues = [groupFound valueForKey:@"value"];
  2484. if ([[groupValues valueForKey:@"shareWith"] isKindOfClass:[NSNumber class]]) {
  2485. NSNumber *number = [groupValues valueForKey:@"shareWith"];
  2486. group.name = [NSString stringWithFormat:@"%ld", number.longValue];
  2487. }else{
  2488. group.name = [groupValues valueForKey:@"shareWith"];
  2489. }
  2490. group.shareeType = shareTypeGroup;
  2491. [itemList addObject:group];
  2492. }
  2493. }
  2494. @end