PageRenderTime 50ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/Frameworks/OmniDAV/ODAVConnection.h

http://github.com/omnigroup/OmniGroup
C Header | 172 lines | 108 code | 48 blank | 16 comment | 0 complexity | e8252f2ad49c40a982d8137564e0fd10 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. // Copyright 2008-2019 Omni Development, Inc. All rights reserved.
  2. //
  3. // This software may only be used and reproduced according to the
  4. // terms in the file OmniSourceLicense.html, which should be
  5. // distributed with this project and can also be found at
  6. // <http://www.omnigroup.com/developer/sourcecode/sourcelicense/>.
  7. #import <Foundation/NSObject.h>
  8. #import <Foundation/NSURLSession.h>
  9. #import <OmniDAV/ODAVFeatures.h>
  10. #import <OmniDAV/ODAVConnectionTimeoutDelegate.h>
  11. #import <OmniBase/macros.h>
  12. NS_ASSUME_NONNULL_BEGIN
  13. @class NSURLCredential, NSURLAuthenticationChallenge, NSOperation;
  14. @class ODAVMultipleFileInfoResult, ODAVSingleFileInfoResult, ODAVFileInfo, ODAVOperation, ODAVRedirect, ODAVURLResult, ODAVURLAndDataResult;
  15. @protocol OFCertificateTrustDisposition, OFCredentialChallengeDisposition;
  16. typedef void (^ODAVConnectionBasicCompletionHandler)(NSError * _Nullable errorOrNil);
  17. typedef void (^ODAVConnectionOperationCompletionHandler)(ODAVOperation *op);
  18. typedef void (^ODAVConnectionURLCompletionHandler)(ODAVURLResult * _Nullable result, NSError * _Nullable errorOrNil);
  19. typedef void (^ODAVConnectionURLAndDataCompletionHandler)(ODAVURLAndDataResult * _Nullable result, NSError * _Nullable errorOrNil);
  20. typedef void (^ODAVConnectionStringCompletionHandler)(NSString * _Nullable resultString, NSError * _Nullable errorOrNil);
  21. typedef void (^ODAVConnectionMultipleFileInfoCompletionHandler)(ODAVMultipleFileInfoResult * _Nullable properties, NSError * _Nullable errorOrNil);
  22. typedef void (^ODAVConnectionSingleFileInfoCompletionHandler)(ODAVSingleFileInfoResult * _Nullable properties, NSError * _Nullable errorOrNil);
  23. typedef NS_ENUM(NSUInteger, ODAVDepth) {
  24. ODAVDepthLocal,
  25. ODAVDepthChildren,
  26. ODAVDepthInfinite, // Not always supported by servers
  27. };
  28. @interface ODAVConnectionConfiguration : NSObject
  29. + (NSString *)userAgentStringByAddingComponents:(nullable NSArray *)components;
  30. @property(nonatomic,copy) NSString *userAgent;
  31. @property(nonatomic) BOOL HTTPShouldUsePipelining;
  32. @property(nonatomic) NSInteger maximumChallengeRetryCount;
  33. @end
  34. @interface ODAVConnection : NSObject
  35. @property(class,nonatomic,weak) id <ODAVConnectionTimeoutDelegate> timeoutDelegate;
  36. - (instancetype)init NS_UNAVAILABLE;
  37. - initWithSessionConfiguration:(ODAVConnectionConfiguration *)configuration baseURL:(NSURL *)baseURL NS_DESIGNATED_INITIALIZER;
  38. @property(nonatomic,readonly) ODAVConnectionConfiguration *configuration;
  39. @property(nonatomic,readonly) NSURL *originalBaseURL;
  40. @property(nonatomic,readonly) NSURL *baseURL; // Possibly redirected
  41. - (void)updateBaseURLWithRedirects:(NSArray <ODAVRedirect *> *)redirects;
  42. - (NSURL *)suggestRedirectedURLForURL:(NSURL *)url;
  43. // Completely override the user agent string, otherwise the configuration's userAgent will be used.
  44. @property(nonatomic,copy) NSString *userAgent;
  45. @property(nonatomic,copy) NSString *operationReason;
  46. @property(nonatomic,copy,nullable) NSDictionary <NSString *, NSString *> *customHeaderValues;
  47. // NOTE: These get called on a private queue, not the queue the connection was created on or the queue the operations were created or started on
  48. // validateCertificateForChallenge: Decide whether to trust a server (NSURLAuthenticationMethodServerTrust), and return the adjusted SecTrustRef credential if so. Returning nil is equivalent to not setting a callback in the first place, which results in NSURLSessionAuthChallengeRejectProtectionSpace. (TODO: Should it be default handling instead of reject?)
  49. // This callback should simply apply any stored exceptions or similar overrides, but probably shouldn't prompt the user: if it takes too long the server may drop the connection, and NSURLSession doesn't automatically handle that timeout. Instead, users of OmniDAV should run a trust dialog if an operation fails for a server-trust-related reason.
  50. @property(nonatomic,copy,nullable) NSURLCredential * _Nullable (^validateCertificateForChallenge)(NSURLAuthenticationChallenge *challenge);
  51. // findCredentialsForChallenge: Start an operation to get a username+password for an operation, and return it. The DAV operation will be canceled, but the NSOperation will be returned in the error block for the caller to wait on if it wants. (In the future we may want the DAV operation to wait on the NSOperation automatically.)
  52. @property(nonatomic,copy,nullable) NSOperation <OFCredentialChallengeDisposition> *(^findCredentialsForChallenge)(NSURLAuthenticationChallenge *challenge);
  53. - (void)deleteURL:(NSURL *)url withETag:(nullable NSString *)ETag completionHandler:(nullable ODAVConnectionBasicCompletionHandler)completionHandler;
  54. - (ODAVOperation *)asynchronousDeleteURL:(NSURL *)url withETag:(nullable NSString *)ETag;
  55. - (void)makeCollectionAtURL:(NSURL *)url completionHandler:(ODAVConnectionURLCompletionHandler)completionHandler;
  56. - (void)makeCollectionAtURLIfMissing:(NSURL *)url baseURL:(nullable NSURL *)baseURL completionHandler:(ODAVConnectionURLCompletionHandler)completionHandler;
  57. - (void)fileInfosAtURL:(NSURL *)url ETag:(nullable NSString *)predicateETag depth:(ODAVDepth)depth completionHandler:(ODAVConnectionMultipleFileInfoCompletionHandler)completionHandler;
  58. - (void)fileInfoAtURL:(NSURL *)url ETag:(nullable NSString *)predicateETag completionHandler:(void (^)(ODAVSingleFileInfoResult * _Nullable result, NSError * _Nullable error))completionHandler;
  59. // Removes the directory URL itself, "._" files, and does some more error checking for non-directory cases.
  60. - (void)directoryContentsAtURL:(NSURL *)url withETag:(nullable NSString *)ETag completionHandler:(ODAVConnectionMultipleFileInfoCompletionHandler)completionHandler;
  61. - (void)getContentsOfURL:(NSURL *)url ETag:(nullable NSString *)ETag completionHandler:(ODAVConnectionOperationCompletionHandler)completionHandler;
  62. - (ODAVOperation *)asynchronousGetContentsOfURL:(NSURL *)url; // Returns an unstarted operation
  63. - (ODAVOperation *)asynchronousGetContentsOfURL:(NSURL *)url withETag:(nullable NSString *)ETag range:(nullable NSString *)range;
  64. - (void)postData:(NSData *)data toURL:(NSURL *)url completionHandler:(ODAVConnectionURLAndDataCompletionHandler)completionHandler;
  65. - (void)putData:(NSData *)data toURL:(NSURL *)url completionHandler:(ODAVConnectionURLCompletionHandler)completionHandler;
  66. - (ODAVOperation *)asynchronousPutData:(NSData *)data toURL:(NSURL *)url; // Returns an unstarted operation
  67. - (void)copyURL:(NSURL *)sourceURL toURL:(NSURL *)destURL withSourceETag:(nullable NSString *)ETag overwrite:(BOOL)overwrite completionHandler:(ODAVConnectionURLCompletionHandler)completionHandler;
  68. - (void)moveURL:(NSURL *)sourceURL toURL:(NSURL *)destURL completionHandler:(ODAVConnectionURLCompletionHandler)completionHandler;
  69. - (void)moveURL:(NSURL *)sourceURL toURL:(NSURL *)destURL withSourceETag:(nullable NSString *)ETag overwrite:(BOOL)overwrite completionHandler:(ODAVConnectionURLCompletionHandler)completionHandler;
  70. - (void)moveURL:(NSURL *)sourceURL toURL:(NSURL *)destURL withDestinationETag:(nullable NSString *)ETag overwrite:(BOOL)overwrite completionHandler:(ODAVConnectionURLCompletionHandler)completionHandler;
  71. - (void)moveURL:(NSURL *)sourceURL toURL:(NSURL *)destURL withSourceLock:(nullable NSString *)lock overwrite:(BOOL)overwrite completionHandler:(ODAVConnectionURLCompletionHandler)completionHandler;
  72. - (void)moveURL:(NSURL *)sourceURL toURL:(NSURL *)destURL withDestinationLock:(nullable NSString *)lock overwrite:(BOOL)overwrite completionHandler:(ODAVConnectionURLCompletionHandler)completionHandler;
  73. - (void)moveURL:(NSURL *)sourceURL toMissingURL:(NSURL *)destURL completionHandler:(ODAVConnectionURLCompletionHandler)completionHandler;
  74. - (void)moveURL:(NSURL *)sourceURL toURL:(NSURL *)destURL ifURLExists:(NSURL *)tagURL completionHandler:(ODAVConnectionURLCompletionHandler)completionHandler;
  75. - (void)lockURL:(NSURL *)url completionHandler:(ODAVConnectionStringCompletionHandler)completionHandler;
  76. - (void)unlockURL:(NSURL *)url token:(NSString *)lockToken completionHandler:(ODAVConnectionBasicCompletionHandler)completionHandler;
  77. @end
  78. @interface ODAVOperationResult : NSObject
  79. @property(nullable,nonatomic,copy) NSArray <ODAVRedirect *> *redirects;
  80. @property(nullable,nonatomic,copy) NSDate *serverDate;
  81. @end
  82. @interface ODAVMultipleFileInfoResult : ODAVOperationResult
  83. @property(nullable,nonatomic,copy) NSArray <ODAVFileInfo *> *fileInfos;
  84. @end
  85. @interface ODAVSingleFileInfoResult : ODAVOperationResult
  86. @property(nullable,nonatomic,copy) ODAVFileInfo *fileInfo;
  87. @end
  88. @interface ODAVURLResult : ODAVOperationResult
  89. @property(nullable,nonatomic,copy) NSURL *URL;
  90. @end
  91. @interface ODAVURLAndDataResult : ODAVOperationResult
  92. @property(nullable,nonatomic,copy) NSURL *URL;
  93. @property(nullable,nonatomic,copy) NSData *responseData;
  94. @end
  95. // Utilities to help when we want synchronous operations.
  96. // Adding a macro to wrap this up is a pain since we can't set breakpoints inside the block easily (and we have to wrap the block in an extra (...) if it has embedded commas that aren't inside parens already).
  97. typedef void (^ODAVOperationDone)(void);
  98. typedef void (^ODAVAddOperation)(ODAVOperationDone done);
  99. extern void ODAVSyncOperation(const char *file, unsigned line, ODAVAddOperation op);
  100. // Each call to the 'add' block must be balanced by a call to the 'done' block.
  101. typedef void (^ODAVFinishAction)(void);
  102. typedef void (^ODAVFinishOperation)(ODAVFinishAction completionAction);
  103. typedef void (^ODAVStartAction)(ODAVFinishOperation finish);
  104. typedef void (^OFXStartOperation)(ODAVStartAction backgroundAction);
  105. typedef void (^ODAVAddOperations)(OFXStartOperation start);
  106. extern void ODAVSyncOperations(const char *file, unsigned line, ODAVAddOperations addOperations);
  107. // Synchronous wrappers
  108. @interface ODAVConnection (ODAVSyncExtensions)
  109. - (BOOL)synchronousDeleteURL:(NSURL *)url withETag:(nullable NSString *)ETag error:(NSError **)outError;
  110. - (nullable ODAVURLResult *)synchronousMakeCollectionAtURL:(NSURL *)url error:(NSError **)outError;
  111. - (nullable ODAVFileInfo *)synchronousFileInfoAtURL:(NSURL *)url error:(NSError **)outError;
  112. - (nullable ODAVFileInfo *)synchronousFileInfoAtURL:(NSURL *)url serverDate:(NSDate * __nullable OB_AUTORELEASING * __nullable)outServerDate error:(NSError **)outError;
  113. - (nullable ODAVMultipleFileInfoResult *)synchronousDirectoryContentsAtURL:(NSURL *)url withETag:(nullable NSString *)ETag error:(NSError **)outError;
  114. - (nullable NSData *)synchronousGetContentsOfURL:(NSURL *)url ETag:(nullable NSString *)ETag error:(NSError **)outError;
  115. - (nullable NSURL *)synchronousPutData:(NSData *)data toURL:(NSURL *)url error:(NSError **)outError;
  116. - (nullable NSURL *)synchronousCopyURL:(NSURL *)sourceURL toURL:(NSURL *)destURL withSourceETag:(nullable NSString *)eTag overwrite:(BOOL)overwrite error:(NSError **)outError;
  117. - (nullable NSURL *)synchronousMoveURL:(NSURL *)sourceURL toURL:(NSURL *)destURL withDestinationETag:(nullable NSString *)ETag overwrite:(BOOL)overwrite error:(NSError **)outError;
  118. - (nullable NSURL *)synchronousMoveURL:(NSURL *)sourceURL toURL:(NSURL *)destURL withSourceLock:(nullable NSString *)lock overwrite:(BOOL)overwrite error:(NSError **)outError;
  119. - (nullable NSURL *)synchronousMoveURL:(NSURL *)sourceURL toURL:(NSURL *)destURL withDestinationLock:(nullable NSString *)lock overwrite:(BOOL)overwrite error:(NSError **)outError;
  120. - (nullable NSURL *)synchronousMoveURL:(NSURL *)sourceURL toMissingURL:(NSURL *)destURL error:(NSError **)outError;
  121. - (nullable NSString *)synchronousLockURL:(NSURL *)url error:(NSError **)outError;
  122. - (BOOL)synchronousUnlockURL:(NSURL *)url token:(NSString *)lockToken error:(NSError **)outError;
  123. @end
  124. NS_ASSUME_NONNULL_END