OCCommunication.m 186 KB

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