OCCommunication.m 183 KB

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