RLMSyncManager.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. ////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright 2016 Realm Inc.
  4. //
  5. // Licensed under the Apache License, Version 2.0 (the "License");
  6. // you may not use this file except in compliance with the License.
  7. // You may obtain a copy of the License at
  8. //
  9. // http://www.apache.org/licenses/LICENSE-2.0
  10. //
  11. // Unless required by applicable law or agreed to in writing, software
  12. // distributed under the License is distributed on an "AS IS" BASIS,
  13. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. // See the License for the specific language governing permissions and
  15. // limitations under the License.
  16. //
  17. ////////////////////////////////////////////////////////////////////////////
  18. #import <Foundation/Foundation.h>
  19. #import "RLMSyncUtil.h"
  20. @class RLMSyncSession;
  21. /// An enum representing different levels of sync-related logging that can be configured.
  22. typedef RLM_CLOSED_ENUM(NSUInteger, RLMSyncLogLevel) {
  23. /// Nothing will ever be logged.
  24. RLMSyncLogLevelOff,
  25. /// Only fatal errors will be logged.
  26. RLMSyncLogLevelFatal,
  27. /// Only errors will be logged.
  28. RLMSyncLogLevelError,
  29. /// Warnings and errors will be logged.
  30. RLMSyncLogLevelWarn,
  31. /// Information about sync events will be logged. Fewer events will be logged in order to avoid overhead.
  32. RLMSyncLogLevelInfo,
  33. /// Information about sync events will be logged. More events will be logged than with `RLMSyncLogLevelInfo`.
  34. RLMSyncLogLevelDetail,
  35. /// Log information that can aid in debugging.
  36. ///
  37. /// - warning: Will incur a measurable performance impact.
  38. RLMSyncLogLevelDebug,
  39. /// Log information that can aid in debugging. More events will be logged than with `RLMSyncLogLevelDebug`.
  40. ///
  41. /// - warning: Will incur a measurable performance impact.
  42. RLMSyncLogLevelTrace,
  43. /// Log information that can aid in debugging. More events will be logged than with `RLMSyncLogLevelTrace`.
  44. ///
  45. /// - warning: Will incur a measurable performance impact.
  46. RLMSyncLogLevelAll
  47. };
  48. NS_ASSUME_NONNULL_BEGIN
  49. /// A block type representing a block which can be used to report a sync-related error to the application. If the error
  50. /// pertains to a specific session, that session will also be passed into the block.
  51. typedef void(^RLMSyncErrorReportingBlock)(NSError *, RLMSyncSession * _Nullable);
  52. /**
  53. A singleton manager which serves as a central point for sync-related configuration.
  54. */
  55. @interface RLMSyncManager : NSObject
  56. /**
  57. A block which can optionally be set to report sync-related errors to your application.
  58. Any error reported through this block will be of the `RLMSyncError` type, and marked
  59. with the `RLMSyncErrorDomain` domain.
  60. Errors reported through this mechanism are fatal, with several exceptions. Please consult
  61. `RLMSyncError` for information about the types of errors that can be reported through
  62. the block, and for for suggestions on handling recoverable error codes.
  63. @see `RLMSyncError`
  64. */
  65. @property (nullable, nonatomic, copy) RLMSyncErrorReportingBlock errorHandler;
  66. /**
  67. A reverse-DNS string uniquely identifying this application. In most cases this
  68. is automatically set by the SDK, and does not have to be explicitly configured.
  69. */
  70. @property (nonatomic, copy) NSString *appID;
  71. /**
  72. A string identifying this application which is included in the User-Agent
  73. header of sync connections. By default, this will be the application's bundle
  74. identifier.
  75. This property must be set prior to opening a synchronized Realm for the first
  76. time. Any modifications made after opening a Realm will be ignored.
  77. */
  78. @property (nonatomic, copy) NSString *userAgent;
  79. /**
  80. The logging threshold which newly opened synced Realms will use. Defaults to
  81. `RLMSyncLogLevelInfo`.
  82. Logging strings are output to Apple System Logger.
  83. @warning This property must be set before any synced Realms are opened. Setting it after
  84. opening any synced Realm will do nothing.
  85. */
  86. @property (nonatomic) RLMSyncLogLevel logLevel;
  87. /**
  88. The name of the HTTP header to send authorization data in when making requests to a Realm Object Server which has
  89. been configured to expect a custom authorization header.
  90. */
  91. @property (nullable, nonatomic, copy) NSString *authorizationHeaderName;
  92. /**
  93. Extra HTTP headers to append to every request to a Realm Object Server.
  94. */
  95. @property (nullable, nonatomic, copy) NSDictionary<NSString *, NSString *> *customRequestHeaders;
  96. /**
  97. A map of hostname to file URL for pinned certificates to use for HTTPS requests.
  98. When initiating a HTTPS connection to a server, if this dictionary contains an
  99. entry for the server's hostname, only the certificates stored in the file (or
  100. any certificates signed by it, if the file contains a CA cert) will be accepted
  101. when initiating a connection to a server. This prevents certain certain kinds
  102. of man-in-the-middle (MITM) attacks, and can also be used to trust a self-signed
  103. certificate which would otherwise be untrusted.
  104. On macOS, the certificate files may be in any of the formats supported by
  105. SecItemImport(), including PEM and .cer (see SecExternalFormat for a complete
  106. list of possible formats). On iOS and other platforms, only DER .cer files are
  107. supported.
  108. For example, to pin example.com to a .cer file included in your bundle:
  109. <pre>
  110. RLMSyncManager.sharedManager.pinnedCertificatePaths = @{
  111. @"example.com": [NSBundle.mainBundle pathForResource:@"example.com" ofType:@"cer"]
  112. };
  113. </pre>
  114. */
  115. @property (nullable, nonatomic, copy) NSDictionary<NSString *, NSURL *> *pinnedCertificatePaths;
  116. /// The sole instance of the singleton.
  117. + (instancetype)sharedManager NS_REFINED_FOR_SWIFT;
  118. /// :nodoc:
  119. - (instancetype)init __attribute__((unavailable("RLMSyncManager cannot be created directly")));
  120. /// :nodoc:
  121. + (instancetype)new __attribute__((unavailable("RLMSyncManager cannot be created directly")));
  122. NS_ASSUME_NONNULL_END
  123. @end