NCNetworkingSync.m 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  1. //
  2. // NCNetworkingSync.m
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 29/10/17.
  6. // Copyright © 2017 TWS. All rights reserved.
  7. //
  8. #import "NCNetworkingSync.h"
  9. #import "CCUtility.h"
  10. #import "CCCertificate.h"
  11. #import "NCBridgeSwift.h"
  12. @implementation NCNetworkingSync
  13. + (NCNetworkingSync *)sharedManager {
  14. static NCNetworkingSync *sharedManager;
  15. @synchronized(self)
  16. {
  17. if (!sharedManager) {
  18. sharedManager = [NCNetworkingSync new];
  19. }
  20. return sharedManager;
  21. }
  22. }
  23. #pragma --------------------------------------------------------------------------------------------
  24. #pragma mark ============================
  25. #pragma --------------------------------------------------------------------------------------------
  26. - (NSError *)uploadFile:(NSString *)localFilePathName remoteFilePathName:(NSString *)remoteFilePathName user:(NSString *)user userID:(NSString *)userID password:(NSString *)password
  27. {
  28. OCCommunication *communication = [CCNetworking sharedNetworking].sharedOCCommunication;
  29. __block NSError *returnError = nil;
  30. dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
  31. [communication setCredentialsWithUser:user andUserID:userID andPassword:password];
  32. [communication setUserAgent:[CCUtility getUserAgent]];
  33. [communication uploadFileSession:localFilePathName toDestiny:remoteFilePathName onCommunication:communication progress:^(NSProgress *progress) {
  34. // Progress
  35. } successRequest:^(NSURLResponse *response, NSString *redirectedServer) {
  36. dispatch_semaphore_signal(semaphore);
  37. } failureRequest:^(NSURLResponse *response, NSString *redirectedServer, NSError *error) {
  38. NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*)response;
  39. returnError = [NSError errorWithDomain:@"com.nextcloud.nextcloud" code:httpResponse.statusCode userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"Upload file error %lu", httpResponse.statusCode] forKey:NSLocalizedDescriptionKey]];
  40. dispatch_semaphore_signal(semaphore);
  41. } failureBeforeRequest:^(NSError *error) {
  42. returnError = error;
  43. dispatch_semaphore_signal(semaphore);
  44. }];
  45. while (dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER))
  46. [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:k_timeout_webdav]];
  47. return returnError;
  48. }
  49. - (NSError *)checkServer:(NSString *)serverUrl user:(NSString *)user userID:(NSString *)userID password:(NSString *)password
  50. {
  51. OCCommunication *communication = [CCNetworking sharedNetworking].sharedOCCommunication;
  52. __block NSError *returnError = nil;
  53. dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
  54. [communication setCredentialsWithUser:user andUserID:userID andPassword:password];
  55. [communication setUserAgent:[CCUtility getUserAgent]];
  56. [communication checkServer:serverUrl onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSString *redirectedServer) {
  57. dispatch_semaphore_signal(semaphore);
  58. } failureRequest:^(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer) {
  59. returnError = [NSError errorWithDomain:@"com.nextcloud.nextcloud" code:response.statusCode userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"Check server error %lu", response.statusCode] forKey:NSLocalizedDescriptionKey]];
  60. dispatch_semaphore_signal(semaphore);
  61. }];
  62. while (dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER))
  63. [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:k_timeout_webdav]];
  64. return returnError;
  65. }
  66. - (NSError *)readFile:(NSString *)filePathName user:(NSString *)user userID:(NSString *)userID password:(NSString *)password
  67. {
  68. OCCommunication *communication = [CCNetworking sharedNetworking].sharedOCCommunication;
  69. __block NSError *returnError = nil;
  70. dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
  71. [communication setCredentialsWithUser: user andUserID: userID andPassword: password];
  72. [communication setUserAgent:[CCUtility getUserAgent]];
  73. [communication readFile:filePathName onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSArray *items, NSString *redirectedServer) {
  74. dispatch_semaphore_signal(semaphore);
  75. } failureRequest:^(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer) {
  76. returnError = [NSError errorWithDomain:@"com.nextcloud.nextcloud" code:response.statusCode userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"Read file error %lu", response.statusCode] forKey:NSLocalizedDescriptionKey]];
  77. dispatch_semaphore_signal(semaphore);
  78. }];
  79. while (dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER))
  80. [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:k_timeout_webdav]];
  81. return returnError;
  82. }
  83. - (NSError *)readFolder:(NSString *)serverUrl user:(NSString *)user userID:(NSString *)userID password:(NSString *)password items:(NSArray **)items
  84. {
  85. OCCommunication *communication = [CCNetworking sharedNetworking].sharedOCCommunication;
  86. __block NSError *returnError = nil;
  87. __block NSArray *returnItems = nil;
  88. dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
  89. [communication setCredentialsWithUser:user andUserID:userID andPassword:password];
  90. [communication setUserAgent:[CCUtility getUserAgent]];
  91. [communication readFolder:serverUrl depth:0 withUserSessionToken:nil onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSArray *items, NSString *redirectedServer, NSString *token) {
  92. returnItems = items;
  93. dispatch_semaphore_signal(semaphore);
  94. } failureRequest:^(NSHTTPURLResponse *response, NSError *error, NSString *token, NSString *redirectedServer) {
  95. returnError = [NSError errorWithDomain:@"com.nextcloud.nextcloud" code:response.statusCode userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"Read folder error %lu", response.statusCode] forKey:NSLocalizedDescriptionKey]];
  96. dispatch_semaphore_signal(semaphore);
  97. }];
  98. while (dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER))
  99. [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:k_timeout_webdav]];
  100. *items = returnItems;
  101. return returnError;
  102. }
  103. #pragma --------------------------------------------------------------------------------------------
  104. #pragma mark ===== End-to-End Encryption =====
  105. #pragma --------------------------------------------------------------------------------------------
  106. - (NSError *)markEndToEndFolderEncrypted:(NSString *)user userID:(NSString *)userID password:(NSString *)password url:(NSString *)url fileID:(NSString *)fileID token:(NSString **)token
  107. {
  108. OCCommunication *communication = [CCNetworking sharedNetworking].sharedOCCommunication;
  109. __block NSError *returnError = nil;
  110. __block NSString *returnToken = nil;
  111. dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
  112. [communication setCredentialsWithUser:user andUserID:userID andPassword:password];
  113. [communication setUserAgent:[CCUtility getUserAgent]];
  114. // LOCK
  115. [communication lockEndToEndFolderEncrypted:[url stringByAppendingString:@"/"] fileID:fileID token:*token onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSString *token, NSString *redirectedServer) {
  116. returnToken = token;
  117. [[NCManageDatabase sharedInstance] setDirectoryE2ETokenLockWithFileID:fileID token:returnToken];
  118. // REMOVE METADATA
  119. [communication deleteEndToEndMetadata:[url stringByAppendingString:@"/"] fileID:fileID onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSString *redirectedServer) {
  120. NSLog(@"Found metadata and delete");
  121. } failureRequest:^(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer) {
  122. NSLog(@"%@", [NSString stringWithFormat:@"Remove metadata error %lu", response.statusCode]);
  123. }];
  124. // MARK
  125. [communication markEndToEndFolderEncrypted:[url stringByAppendingString:@"/"] fileID:fileID onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSString *redirectedServer) {
  126. // UNLOCK
  127. [communication unlockEndToEndFolderEncrypted:[url stringByAppendingString:@"/"] fileID:fileID token:returnToken onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSString *redirectedServer) {
  128. returnToken = nil;
  129. [[NCManageDatabase sharedInstance] setDirectoryE2ETokenLockWithFileID:fileID token:@""];
  130. dispatch_semaphore_signal(semaphore);
  131. } failureRequest:^(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer) {
  132. returnError = [NSError errorWithDomain:@"com.nextcloud.nextcloud" code:response.statusCode userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"Unlock folder error %lu", response.statusCode] forKey:NSLocalizedDescriptionKey]];
  133. dispatch_semaphore_signal(semaphore);
  134. }];
  135. } failureRequest:^(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer) {
  136. returnError = [NSError errorWithDomain:@"com.nextcloud.nextcloud" code:response.statusCode userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"Mark folder as encrypted error %lu", response.statusCode] forKey:NSLocalizedDescriptionKey]];
  137. dispatch_semaphore_signal(semaphore);
  138. }];
  139. } failureRequest:^(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer) {
  140. returnError = [NSError errorWithDomain:@"com.nextcloud.nextcloud" code:response.statusCode userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"Lock folder error %lu", response.statusCode] forKey:NSLocalizedDescriptionKey]];
  141. dispatch_semaphore_signal(semaphore);
  142. }];
  143. while (dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER))
  144. [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:k_timeout_webdav]];
  145. *token = returnToken;
  146. return returnError;
  147. }
  148. - (NSError *)deletemarkEndToEndFolderEncrypted:(NSString *)user userID:(NSString *)userID password:(NSString *)password url:(NSString *)url fileID:(NSString *)fileID token:(NSString **)token
  149. {
  150. OCCommunication *communication = [CCNetworking sharedNetworking].sharedOCCommunication;
  151. __block NSError *returnError = nil;
  152. __block NSString *returnToken = nil;
  153. dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
  154. [communication setCredentialsWithUser:user andUserID:userID andPassword:password];
  155. [communication setUserAgent:[CCUtility getUserAgent]];
  156. // LOCK
  157. [communication lockEndToEndFolderEncrypted:[url stringByAppendingString:@"/"] fileID:fileID token:*token onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSString *token, NSString *redirectedServer) {
  158. returnToken = token;
  159. [[NCManageDatabase sharedInstance] setDirectoryE2ETokenLockWithFileID:fileID token:returnToken];
  160. // REMOVE METADATA
  161. [communication deleteEndToEndMetadata:[url stringByAppendingString:@"/"] fileID:fileID onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSString *redirectedServer) {
  162. NSLog(@"Found metadata and delete");
  163. } failureRequest:^(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer) {
  164. NSLog(@"%@", [NSString stringWithFormat:@"Remove metadata error %lu", response.statusCode]);
  165. }];
  166. // DELETE MARK
  167. [communication deletemarkEndToEndFolderEncrypted:[url stringByAppendingString:@"/"] fileID:fileID onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSString *redirectedServer) {
  168. // UNLOCK
  169. [communication unlockEndToEndFolderEncrypted:[url stringByAppendingString:@"/"] fileID:fileID token:returnToken onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSString *redirectedServer) {
  170. returnToken = nil;
  171. [[NCManageDatabase sharedInstance] setDirectoryE2ETokenLockWithFileID:fileID token:@""];
  172. dispatch_semaphore_signal(semaphore);
  173. } failureRequest:^(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer) {
  174. returnError = [NSError errorWithDomain:@"com.nextcloud.nextcloud" code:response.statusCode userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"Unlock folder error %lu", response.statusCode] forKey:NSLocalizedDescriptionKey]];
  175. dispatch_semaphore_signal(semaphore);
  176. }];
  177. } failureRequest:^(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer) {
  178. returnError = [NSError errorWithDomain:@"com.nextcloud.nextcloud" code:response.statusCode userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"Delete mark folder as encrypted error %lu", response.statusCode] forKey:NSLocalizedDescriptionKey]];
  179. dispatch_semaphore_signal(semaphore);
  180. }];
  181. } failureRequest:^(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer) {
  182. returnError = [NSError errorWithDomain:@"com.nextcloud.nextcloud" code:response.statusCode userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"Lock folder error %lu", response.statusCode] forKey:NSLocalizedDescriptionKey]];
  183. dispatch_semaphore_signal(semaphore);
  184. }];
  185. while (dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER))
  186. [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:k_timeout_webdav]];
  187. *token = returnToken;
  188. return returnError;
  189. }
  190. - (NSError *)getEndToEndMetadata:(NSString *)user userID:(NSString *)userID password:(NSString *)password url:(NSString *)url fileID:(NSString *)fileID metadata:(NSString **)metadata
  191. {
  192. OCCommunication *communication = [CCNetworking sharedNetworking].sharedOCCommunication;
  193. __block NSError *returnError = nil;
  194. __block NSString *returnMetadata = nil;
  195. dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
  196. [communication setCredentialsWithUser:user andUserID:userID andPassword:password];
  197. [communication setUserAgent:[CCUtility getUserAgent]];
  198. [communication getEndToEndMetadata:[url stringByAppendingString:@"/"] fileID:fileID onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSString *encryptedMetadata, NSString *redirectedServer) {
  199. returnMetadata = encryptedMetadata;
  200. dispatch_semaphore_signal(semaphore);
  201. } failureRequest:^(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer) {
  202. returnError = [NSError errorWithDomain:@"com.nextcloud.nextcloud" code:response.statusCode userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"Get metadata error %lu", response.statusCode] forKey:NSLocalizedDescriptionKey]];
  203. dispatch_semaphore_signal(semaphore);
  204. }];
  205. while (dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER))
  206. [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:k_timeout_webdav]];
  207. *metadata = returnMetadata;
  208. return returnError;
  209. }
  210. - (NSError *)storeEndToEndMetadata:(NSString *)user userID:(NSString *)userID password:(NSString *)password url:(NSString *)url fileID:(NSString *)fileID metadata:(NSString *)metadata token:(NSString **)token
  211. {
  212. OCCommunication *communication = [CCNetworking sharedNetworking].sharedOCCommunication;
  213. __block NSError *returnError = nil;
  214. __block NSString *returnToken = nil;
  215. dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
  216. [communication setCredentialsWithUser:user andUserID:userID andPassword:password];
  217. [communication setUserAgent:[CCUtility getUserAgent]];
  218. // LOCK
  219. [communication lockEndToEndFolderEncrypted:[url stringByAppendingString:@"/"] fileID:fileID token:*token onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSString *token, NSString *redirectedServer) {
  220. returnToken = token;
  221. [[NCManageDatabase sharedInstance] setDirectoryE2ETokenLockWithFileID:fileID token:returnToken];
  222. // STORE METADATA
  223. [communication storeEndToEndMetadata:[url stringByAppendingString:@"/"] fileID:fileID encryptedMetadata:metadata onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSString *encryptedMetadata, NSString *redirectedServer) {
  224. // UNLOCK
  225. [communication unlockEndToEndFolderEncrypted:[url stringByAppendingString:@"/"] fileID:fileID token:returnToken onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSString *redirectedServer) {
  226. returnToken = nil;
  227. [[NCManageDatabase sharedInstance] setDirectoryE2ETokenLockWithFileID:fileID token:@""];
  228. dispatch_semaphore_signal(semaphore);
  229. } failureRequest:^(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer) {
  230. returnError = [NSError errorWithDomain:@"com.nextcloud.nextcloud" code:response.statusCode userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"Unlock folder error %lu", response.statusCode] forKey:NSLocalizedDescriptionKey]];
  231. dispatch_semaphore_signal(semaphore);
  232. }];
  233. } failureRequest:^(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer) {
  234. returnError = [NSError errorWithDomain:@"com.nextcloud.nextcloud" code:response.statusCode userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"Store metadata error %lu", response.statusCode] forKey:NSLocalizedDescriptionKey]];
  235. dispatch_semaphore_signal(semaphore);
  236. }];
  237. } failureRequest:^(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer) {
  238. returnError = [NSError errorWithDomain:@"com.nextcloud.nextcloud" code:response.statusCode userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"Lock folder error %lu", response.statusCode] forKey:NSLocalizedDescriptionKey]];
  239. dispatch_semaphore_signal(semaphore);
  240. }];
  241. while (dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER))
  242. [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:k_timeout_webdav]];
  243. *token = returnToken;
  244. return returnError;
  245. }
  246. - (NSError *)updateEndToEndMetadata:(NSString *)user userID:(NSString *)userID password:(NSString *)password url:(NSString *)url fileID:(NSString *)fileID metadata:(NSString *)metadata token:(NSString **)token
  247. {
  248. OCCommunication *communication = [CCNetworking sharedNetworking].sharedOCCommunication;
  249. __block NSError *returnError = nil;
  250. __block NSString *returnToken = nil;
  251. dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
  252. [communication setCredentialsWithUser:user andUserID:userID andPassword:password];
  253. [communication setUserAgent:[CCUtility getUserAgent]];
  254. // LOCK
  255. [communication lockEndToEndFolderEncrypted:[url stringByAppendingString:@"/"] fileID:fileID token:*token onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSString *token, NSString *redirectedServer) {
  256. returnToken = token;
  257. [[NCManageDatabase sharedInstance] setDirectoryE2ETokenLockWithFileID:fileID token:returnToken];
  258. // UPDATA METADATA
  259. [communication updateEndToEndMetadata:[url stringByAppendingString:@"/"] fileID:fileID encryptedMetadata:metadata token:returnToken onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSString *encryptedMetadata, NSString *redirectedServer) {
  260. // UNLOCK
  261. [communication unlockEndToEndFolderEncrypted:[url stringByAppendingString:@"/"] fileID:fileID token:returnToken onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSString *redirectedServer) {
  262. returnToken = nil;
  263. [[NCManageDatabase sharedInstance] setDirectoryE2ETokenLockWithFileID:fileID token:@""];
  264. dispatch_semaphore_signal(semaphore);
  265. } failureRequest:^(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer) {
  266. returnError = [NSError errorWithDomain:@"com.nextcloud.nextcloud" code:response.statusCode userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"Unlock folder error %lu", response.statusCode] forKey:NSLocalizedDescriptionKey]];
  267. dispatch_semaphore_signal(semaphore);
  268. }];
  269. } failureRequest:^(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer) {
  270. returnError = [NSError errorWithDomain:@"com.nextcloud.nextcloud" code:response.statusCode userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"Update metadata error %lu", response.statusCode] forKey:NSLocalizedDescriptionKey]];
  271. dispatch_semaphore_signal(semaphore);
  272. }];
  273. } failureRequest:^(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer) {
  274. returnError = [NSError errorWithDomain:@"com.nextcloud.nextcloud" code:response.statusCode userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"Lock folder error %lu", response.statusCode] forKey:NSLocalizedDescriptionKey]];
  275. dispatch_semaphore_signal(semaphore);
  276. }];
  277. while (dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER))
  278. [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:k_timeout_webdav]];
  279. *token = returnToken;
  280. return returnError;
  281. }
  282. @end