OCCommunication.m 185 KB

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