Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,12 @@ if(PAL_IMPLEMENTATION STREQUAL "CPP11")
../wrappers/obj-c/ODWPrivacyGuardInitConfig.mm
)
endif()
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/modules/sanitizer/ AND BUILD_SANITIZER)
list(APPEND SRCS
../wrappers/obj-c/ODWSanitizerInitConfig.mm
../wrappers/obj-c/ODWSanitizer.mm
)
endif()
endif()

if(APPLE AND BUILD_SWIFT_WRAPPER)
Expand Down
34 changes: 34 additions & 0 deletions wrappers/obj-c/ODWSanitizer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
//
#include "objc_begin.h"

NS_ASSUME_NONNULL_BEGIN

/*!
The <b>ODWSanitizer</b> class represents the Sanitizer inspector.
*/
@interface ODWSanitizer : NSObject

#pragma mark Behavior methods
/*!
@brief Set the Sanitizer enabled state.
@param enabled A boolean representing the enabled state for the Sanitizer.
*/
+(void)setEnabled:(bool)enabled;

/*!
@brief Check whether the Sanitizer is enabled.
@return True if the Sanitizer is enabled, otherwise false.
*/
+(bool)enabled;

/*!
@brief Reset the Sanitizer instance. This should be used after LogManager::FlushAndTeardown is called.
*/
+(void)resetSanitizerInstance;
@end

NS_ASSUME_NONNULL_END
#include "objc_end.h"
57 changes: 57 additions & 0 deletions wrappers/obj-c/ODWSanitizer.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
//
#include <stdexcept>
#include "ILogger.hpp"
#include "LogManager.hpp"
#include "Sanitizer.hpp"
#import <Foundation/Foundation.h>
#import "ODWLogConfiguration.h"
#import "ODWSanitizer.h"
#import "ODWSanitizer_private.h"
#import "ODWSanitizerInitConfig.h"

using namespace MAT;

@implementation ODWSanitizer

std::shared_ptr<Sanitizer> _sanitizerPtr;

+(void)initializeSanitizer:(ILogger *)logger withODWSanitizerInitConfig:(ODWSanitizerInitConfig *)initConfigObject;
{
if (_sanitizerPtr != nullptr)
{
return;
}

SanitizerConfiguration config(logger);

if ([initConfigObject notificationEventName] != nil)
{
config.NotificationEventName = [[initConfigObject notificationEventName] UTF8String];
}

_sanitizerPtr = std::make_shared<Sanitizer>(config);
LogManager::GetInstance()->SetDataInspector(_sanitizerPtr);
}

+(void)setEnabled:(bool)enabled
{
if(_sanitizerPtr != nullptr)
{
_sanitizerPtr->SetEnabled(enabled);
}
}

+(bool)enabled
{
return _sanitizerPtr != nullptr && _sanitizerPtr->IsEnabled();
}

+(void)resetSanitizerInstance
{
_sanitizerPtr = nullptr;
}

@end
21 changes: 21 additions & 0 deletions wrappers/obj-c/ODWSanitizerInitConfig.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
//
#include "objc_begin.h"

NS_ASSUME_NONNULL_BEGIN
/*!
@brief Sanitizer Initialization Configuration
*/
@interface ODWSanitizerInitConfig : NSObject

/*!
@brief (OPTIONAL) Custom event name to use when logging concerns from the sanitizer. Default value is `SanitizerConcerns`.
*/
@property(readwrite, copy, nonatomic) NSString* notificationEventName;

@end
NS_ASSUME_NONNULL_END

#include "objc_end.h"
13 changes: 13 additions & 0 deletions wrappers/obj-c/ODWSanitizerInitConfig.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
//
#import <Foundation/Foundation.h>
#import "ODWSanitizerInitConfig.h"

/*!
@brief Sanitizer Initialization Configuration
*/
@implementation ODWSanitizerInitConfig : NSObject

@end
28 changes: 28 additions & 0 deletions wrappers/obj-c/ODWSanitizer_private.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
//
#include "objc_begin.h"
#include "ILogger.hpp"
#import "ODWSanitizer.h"
#import "ODWSanitizerInitConfig.h"

NS_ASSUME_NONNULL_BEGIN

/*!
The <b>ODWSanitizer</b> class represents the sanitizer.
*/
@interface ODWSanitizer (Private)

#pragma mark Initialization methods

/*!
@brief Initializes the sanitizer
@param logger Logger used for reporting concerns
@param initConfigObject the configuration
*/
+(void)initializeSanitizer:(ILogger *)logger withODWSanitizerInitConfig:(ODWSanitizerInitConfig *)initConfigObject;
@end

NS_ASSUME_NONNULL_END
#include "objc_end.h"
1 change: 1 addition & 0 deletions wrappers/obj-c/OneDsCppSdk.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#import "ODWLogger.h"
#import "ODWLogManager.h"
#import "ODWPrivacyGuard.h"
#import "ODWSanitizer.h"
#import "ODWSemanticContext.h"

#endif
2 changes: 2 additions & 0 deletions wrappers/swift/Headers/ObjCModule-Bridging-Header.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@
#import "../../obj-c/ODWLogManager.h"
#import "../../obj-c/ODWPrivacyGuard.h"
#import "../../obj-c/ODWPrivacyGuardInitConfig.h"
#import "../../obj-c/ODWSanitizer.h"
#import "../../obj-c/ODWSanitizerInitConfig.h"
#import "../../obj-c/ODWSemanticContext.h"
30 changes: 30 additions & 0 deletions wrappers/swift/Sources/OneDSSwift/Sanitizer.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
//

import ObjCModule

/// Wrapper to `ODWSanitizer` representing the Sanitizer.
public final class Sanitizer {

/**
Set Sanitizer enabled.

- Parameters:
- enable: `True` to enable the Sanitizer, `False` otherwise.
*/
public static func setEnabled(_ enable: Bool) {
ODWSanitizer.setEnabled(enable)
}

/// Checks if the Sanitizer is enabled, returns `True` if it is, `False` otherwise.
public static func enabled() -> Bool {
return ODWSanitizer.enabled()
}

/// Resets the Sanitizer instance.
public static func resetPrivacyGuardInstance() {
ODWSanitizer.resetSanitizerInstance()
}
}
35 changes: 35 additions & 0 deletions wrappers/swift/Sources/OneDSSwift/SanitizerInitConfig.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
//

import ObjCModule

public final class SanitizerInitConfig {
let odwSanitizerInitConfig: ODWSanitizerInitConfig

/// Default constructor.
public init() {
odwSanitizerInitConfig = ODWSanitizerInitConfig()
}

/// (OPTIONAL) Custom event name to use when logging concerns from the sanitizer. Default value is `SanitizerConcerns`.
public var notificationEventName: String {
get {
odwSanitizerInitConfig.notificationEventName
}
set {
odwSanitizerInitConfig.notificationEventName = newValue
}
}

/**
Returns the Obj-C object of the wrapper.

- Return:
`ODWSanitizerInitConfig` object which class is wrapped around.
*/
func getODWSanitizerInitConfig() -> ODWSanitizerInitConfig {
return odwSanitizerInitConfig
}
}
Loading