NCNetworkingSync.m 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. @implementation NCNetworkingSync
  12. + (NCNetworkingSync *)sharedNetworking {
  13. static NCNetworkingSync *sharedNetworking;
  14. @synchronized(self)
  15. {
  16. if (!sharedNetworking) {
  17. sharedNetworking = [NCNetworkingSync new];
  18. }
  19. return sharedNetworking;
  20. }
  21. }
  22. + (NSString *)lockEndToEndFolderEncrypted:(NSString *)user userID:(NSString *)userID password:(NSString *)password url:(NSString *)url fileID:(NSString *)fileID token:(NSString *)token delegate:(UIViewController *)delegate
  23. {
  24. OCCommunication *communication = [CCNetworking sharedNetworking].sharedOCCommunication;
  25. __block NSString *returnToken = nil;
  26. dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
  27. [communication setCredentialsWithUser:user andUserID:userID andPassword:password];
  28. [communication setUserAgent:[CCUtility getUserAgent]];
  29. [communication lockEndToEndFolderEncrypted:[url stringByAppendingString:@"/"] fileID:fileID token:token onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSString *token, NSString *redirectedServer) {
  30. returnToken = token;
  31. dispatch_semaphore_signal(semaphore);
  32. } failureRequest:^(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer) {
  33. // Request trusted certificated
  34. if ([error code] == NSURLErrorServerCertificateUntrusted)
  35. [[CCCertificate sharedManager] presentViewControllerCertificateWithTitle:[error localizedDescription] viewController:delegate delegate:self];
  36. dispatch_semaphore_signal(semaphore);
  37. }];
  38. while (dispatch_semaphore_wait(semaphore, DISPATCH_TIME_NOW))
  39. [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:k_timeout_webdav]];
  40. return returnToken;
  41. }
  42. @end