NCNetworkingSync.m 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 *)sharedManager {
  13. static NCNetworkingSync *sharedManager;
  14. @synchronized(self)
  15. {
  16. if (!sharedManager) {
  17. sharedManager = [NCNetworkingSync new];
  18. }
  19. return sharedManager;
  20. }
  21. }
  22. - (NSString *)lockEndToEndFolderEncrypted:(NSString *)user userID:(NSString *)userID password:(NSString *)password url:(NSString *)url fileID:(NSString *)fileID token:(NSString *)token
  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. dispatch_semaphore_signal(semaphore);
  34. }];
  35. while (dispatch_semaphore_wait(semaphore, DISPATCH_TIME_NOW))
  36. [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:k_timeout_webdav]];
  37. return returnToken;
  38. }
  39. - (NSError *)unlockEndToEndFolderEncrypted:(NSString *)user userID:(NSString *)userID password:(NSString *)password url:(NSString *)url fileID:(NSString *)fileID token:(NSString *)token
  40. {
  41. OCCommunication *communication = [CCNetworking sharedNetworking].sharedOCCommunication;
  42. __block NSError *returnError= nil;
  43. dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
  44. [communication setCredentialsWithUser:user andUserID:userID andPassword:password];
  45. [communication setUserAgent:[CCUtility getUserAgent]];
  46. [communication unlockEndToEndFolderEncrypted:[url stringByAppendingString:@"/"] fileID:fileID onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSString *redirectedServer) {
  47. dispatch_semaphore_signal(semaphore);
  48. } failureRequest:^(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer) {
  49. returnError = error;
  50. dispatch_semaphore_signal(semaphore);
  51. }];
  52. while (dispatch_semaphore_wait(semaphore, DISPATCH_TIME_NOW))
  53. [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:k_timeout_webdav]];
  54. return returnError;
  55. }
  56. - (NSError *)markEndToEndFolderEncrypted:(NSString *)user userID:(NSString *)userID password:(NSString *)password url:(NSString *)url fileID:(NSString *)fileID
  57. {
  58. OCCommunication *communication = [CCNetworking sharedNetworking].sharedOCCommunication;
  59. __block NSError *returnError= nil;
  60. dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
  61. [communication setCredentialsWithUser:user andUserID:userID andPassword:password];
  62. [communication setUserAgent:[CCUtility getUserAgent]];
  63. [communication markEndToEndFolderEncrypted:[url stringByAppendingString:@"/"] fileID:fileID onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSString *redirectedServer) {
  64. dispatch_semaphore_signal(semaphore);
  65. } failureRequest:^(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer) {
  66. returnError = error;
  67. dispatch_semaphore_signal(semaphore);
  68. }];
  69. while (dispatch_semaphore_wait(semaphore, DISPATCH_TIME_NOW))
  70. [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:k_timeout_webdav]];
  71. return returnError;
  72. }
  73. - (NSError *)deletemarkEndToEndFolderEncrypted:(NSString *)user userID:(NSString *)userID password:(NSString *)password url:(NSString *)url fileID:(NSString *)fileID
  74. {
  75. OCCommunication *communication = [CCNetworking sharedNetworking].sharedOCCommunication;
  76. __block NSError *returnError= nil;
  77. dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
  78. [communication setCredentialsWithUser:user andUserID:userID andPassword:password];
  79. [communication setUserAgent:[CCUtility getUserAgent]];
  80. [communication deletemarkEndToEndFolderEncrypted:[url stringByAppendingString:@"/"] fileID:fileID onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSString *redirectedServer) {
  81. dispatch_semaphore_signal(semaphore);
  82. } failureRequest:^(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer) {
  83. returnError = error;
  84. dispatch_semaphore_signal(semaphore);
  85. }];
  86. while (dispatch_semaphore_wait(semaphore, DISPATCH_TIME_NOW))
  87. [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:k_timeout_webdav]];
  88. return returnError;
  89. }
  90. @end