OCCommunication.m 184 KB

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