File tree Expand file tree Collapse file tree 10 files changed +227
-0
lines changed
Expand file tree Collapse file tree 10 files changed +227
-0
lines changed Original file line number Diff line number Diff line change @@ -187,6 +187,12 @@ if(PAL_IMPLEMENTATION STREQUAL "CPP11")
187187 ../wrappers/obj-c/ODWPrivacyGuardInitConfig.mm
188188 )
189189 endif ()
190+ if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR} /modules/sanitizer/ AND BUILD_SANITIZER)
191+ list (APPEND SRCS
192+ ../wrappers/obj-c/ODWSanitizerInitConfig.mm
193+ ../wrappers/obj-c/ODWSanitizer.mm
194+ )
195+ endif ()
190196 endif ()
191197
192198 if (APPLE AND BUILD_SWIFT_WRAPPER)
Original file line number Diff line number Diff line change 1+ //
2+ // Copyright (c) Microsoft Corporation. All rights reserved.
3+ // SPDX-License-Identifier: Apache-2.0
4+ //
5+ #include " objc_begin.h"
6+
7+ NS_ASSUME_NONNULL_BEGIN
8+
9+ /* !
10+ The <b>ODWSanitizer</b> class represents the Sanitizer inspector.
11+ */
12+ @interface ODWSanitizer : NSObject
13+
14+ #pragma mark Behavior methods
15+ /* !
16+ @brief Set the Sanitizer enabled state.
17+ @param enabled A boolean representing the enabled state for the Sanitizer.
18+ */
19+ +(void )setEnabled : (bool )enabled ;
20+
21+ /* !
22+ @brief Check whether the Sanitizer is enabled.
23+ @return True if the Sanitizer is enabled, otherwise false.
24+ */
25+ +(bool )enabled ;
26+
27+ /* !
28+ @brief Reset the Sanitizer instance. This should be used after LogManager::FlushAndTeardown is called.
29+ */
30+ +(void )resetSanitizerInstance ;
31+ @end
32+
33+ NS_ASSUME_NONNULL_END
34+ #include " objc_end.h"
Original file line number Diff line number Diff line change 1+ //
2+ // Copyright (c) Microsoft Corporation. All rights reserved.
3+ // SPDX-License-Identifier: Apache-2.0
4+ //
5+ #include < stdexcept>
6+ #include " ILogger.hpp"
7+ #include " LogManager.hpp"
8+ #include " Sanitizer.hpp"
9+ #import < Foundation/Foundation.h>
10+ #import " ODWLogConfiguration.h"
11+ #import " ODWSanitizer.h"
12+ #import " ODWSanitizer_private.h"
13+ #import " ODWSanitizerInitConfig.h"
14+
15+ using namespace MAT ;
16+
17+ @implementation ODWSanitizer
18+
19+ std::shared_ptr<Sanitizer> _sanitizerPtr;
20+
21+ +(void )initializeSanitizer : (ILogger *)logger withODWSanitizerInitConfig : (ODWSanitizerInitConfig *)initConfigObject ;
22+ {
23+ if (_sanitizerPtr != nullptr )
24+ {
25+ return ;
26+ }
27+
28+ SanitizerConfiguration config (logger);
29+
30+ if ([initConfigObject notificationEventName ] != nil )
31+ {
32+ config.NotificationEventName = [[initConfigObject notificationEventName ] UTF8String ];
33+ }
34+
35+ _sanitizerPtr = std::make_shared<Sanitizer>(config);
36+ LogManager::GetInstance ()->SetDataInspector (_sanitizerPtr);
37+ }
38+
39+ +(void )setEnabled : (bool )enabled
40+ {
41+ if (_sanitizerPtr != nullptr )
42+ {
43+ _sanitizerPtr->SetEnabled (enabled);
44+ }
45+ }
46+
47+ +(bool )enabled
48+ {
49+ return _sanitizerPtr != nullptr && _sanitizerPtr->IsEnabled ();
50+ }
51+
52+ +(void )resetSanitizerInstance
53+ {
54+ _sanitizerPtr = nullptr ;
55+ }
56+
57+ @end
Original file line number Diff line number Diff line change 1+ //
2+ // Copyright (c) Microsoft Corporation. All rights reserved.
3+ // SPDX-License-Identifier: Apache-2.0
4+ //
5+ #include " objc_begin.h"
6+
7+ NS_ASSUME_NONNULL_BEGIN
8+ /* !
9+ @brief Sanitizer Initialization Configuration
10+ */
11+ @interface ODWSanitizerInitConfig : NSObject
12+
13+ /* !
14+ @brief (OPTIONAL) Custom event name to use when logging concerns from the sanitizer. Default value is `SanitizerConcerns`.
15+ */
16+ @property (readwrite , copy , nonatomic ) NSString * notificationEventName;
17+
18+ @end
19+ NS_ASSUME_NONNULL_END
20+
21+ #include " objc_end.h"
Original file line number Diff line number Diff line change 1+ //
2+ // Copyright (c) Microsoft Corporation. All rights reserved.
3+ // SPDX-License-Identifier: Apache-2.0
4+ //
5+ #import < Foundation/Foundation.h>
6+ #import " ODWSanitizerInitConfig.h"
7+
8+ /* !
9+ @brief Sanitizer Initialization Configuration
10+ */
11+ @implementation ODWSanitizerInitConfig : NSObject
12+
13+ @end
Original file line number Diff line number Diff line change 1+ //
2+ // Copyright (c) Microsoft Corporation. All rights reserved.
3+ // SPDX-License-Identifier: Apache-2.0
4+ //
5+ #include " objc_begin.h"
6+ #include " ILogger.hpp"
7+ #import " ODWSanitizer.h"
8+ #import " ODWSanitizerInitConfig.h"
9+
10+ NS_ASSUME_NONNULL_BEGIN
11+
12+ /* !
13+ The <b>ODWSanitizer</b> class represents the sanitizer.
14+ */
15+ @interface ODWSanitizer (Private)
16+
17+ #pragma mark Initialization methods
18+
19+ /* !
20+ @brief Initializes the sanitizer
21+ @param logger Logger used for reporting concerns
22+ @param initConfigObject the configuration
23+ */
24+ +(void )initializeSanitizer : (ILogger *)logger withODWSanitizerInitConfig : (ODWSanitizerInitConfig *)initConfigObject ;
25+ @end
26+
27+ NS_ASSUME_NONNULL_END
28+ #include " objc_end.h"
Original file line number Diff line number Diff line change 1212#import " ODWLogger.h"
1313#import " ODWLogManager.h"
1414#import " ODWPrivacyGuard.h"
15+ #import " ODWSanitizer.h"
1516#import " ODWSemanticContext.h"
1617
1718#endif
Original file line number Diff line number Diff line change 1414#import " ../../obj-c/ODWLogManager.h"
1515#import " ../../obj-c/ODWPrivacyGuard.h"
1616#import " ../../obj-c/ODWPrivacyGuardInitConfig.h"
17+ #import " ../../obj-c/ODWSanitizer.h"
18+ #import " ../../obj-c/ODWSanitizerInitConfig.h"
1719#import " ../../obj-c/ODWSemanticContext.h"
Original file line number Diff line number Diff line change 1+ //
2+ // Copyright (c) Microsoft Corporation. All rights reserved.
3+ // SPDX-License-Identifier: Apache-2.0
4+ //
5+
6+ import ObjCModule
7+
8+ /// Wrapper to `ODWSanitizer` representing the Sanitizer.
9+ public final class Sanitizer {
10+
11+ /**
12+ Set Sanitizer enabled.
13+
14+ - Parameters:
15+ - enable: `True` to enable the Sanitizer, `False` otherwise.
16+ */
17+ public static func setEnabled( _ enable: Bool ) {
18+ ODWSanitizer . setEnabled ( enable)
19+ }
20+
21+ /// Checks if the Sanitizer is enabled, returns `True` if it is, `False` otherwise.
22+ public static func enabled( ) -> Bool {
23+ return ODWSanitizer . enabled ( )
24+ }
25+
26+ /// Resets the Sanitizer instance.
27+ public static func resetPrivacyGuardInstance( ) {
28+ ODWSanitizer . resetSanitizerInstance ( )
29+ }
30+ }
Original file line number Diff line number Diff line change 1+ //
2+ // Copyright (c) Microsoft Corporation. All rights reserved.
3+ // SPDX-License-Identifier: Apache-2.0
4+ //
5+
6+ import ObjCModule
7+
8+ public final class SanitizerInitConfig {
9+ let odwSanitizerInitConfig : ODWSanitizerInitConfig
10+
11+ /// Default constructor.
12+ public init ( ) {
13+ odwSanitizerInitConfig = ODWSanitizerInitConfig ( )
14+ }
15+
16+ /// (OPTIONAL) Custom event name to use when logging concerns from the sanitizer. Default value is `SanitizerConcerns`.
17+ public var notificationEventName : String {
18+ get {
19+ odwSanitizerInitConfig. notificationEventName
20+ }
21+ set {
22+ odwSanitizerInitConfig. notificationEventName = newValue
23+ }
24+ }
25+
26+ /**
27+ Returns the Obj-C object of the wrapper.
28+
29+ - Return:
30+ `ODWSanitizerInitConfig` object which class is wrapped around.
31+ */
32+ func getODWSanitizerInitConfig( ) -> ODWSanitizerInitConfig {
33+ return odwSanitizerInitConfig
34+ }
35+ }
You can’t perform that action at this time.
0 commit comments