OCCommunication.m 188 KB

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