OCCommunication.m 188 KB

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