Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class Sanitizer {
/**
* Initializes the sanitizer with the provided configuration.
*
* @param config The configuration object containing logger and event name.
* @param config The configuration settings used to initialize a sanitizer.
* @return true if initialization succeeds, false otherwise.
* @throws IllegalArgumentException if config or any required field is null or invalid.
*/
Expand All @@ -21,16 +21,19 @@ public static boolean initialize(SanitizerConfiguration config) {
}

// Ensure the logger instance is provided
if(config.loggerInstance == null) {
if(config.getLogger() == null) {
throw new IllegalArgumentException(("loggerInstance cannot be null in config."));
}

// Ensure the notification event name is not null or empty
if (config.notificationEventName == null || config.notificationEventName.isEmpty()) {
if (config.getNotificationEventName() == null || config.getNotificationEventName().isEmpty()) {
throw new IllegalArgumentException(("notificationEventName cannot be null in config."));
}

return nativeInitialize(config.loggerInstance.getNativeILoggerPtr(), config.notificationEventName);
return nativeInitialize(
config.getLogger().getNativeILoggerPtr(),
config.getNotificationEventName(),
config.isWarningsOff());
}

/**
Expand All @@ -45,9 +48,10 @@ public static boolean initialize(SanitizerConfiguration config) {
*
* @param loggerNativePtr Native pointer to ILogger.
* @param notificationEventName Optional event name for sanitizer notifications.
* @param warningsOff Flag to control whether warnings are suppressed.
* @return true if initialization was successful, false otherwise.
*/
public static native boolean nativeInitialize(long loggerNativePtr, String notificationEventName);
public static native boolean nativeInitialize(long loggerNativePtr, String notificationEventName, boolean warningsOff);

/**
* Uninitializes the sanitizer.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
package com.microsoft.applications.events;

/**
* Represents the configuration settings used to initialize a sanitizer instance.
* Represents the configuration settings used to initialize a sanitizer.
*/

public class SanitizerConfiguration {
Expand All @@ -14,15 +14,21 @@ public class SanitizerConfiguration {
* The logger instance used to record privacy concern events.
* This field is required.
*/
public final ILogger loggerInstance;
private final ILogger loggerInstance;

/**
     * The custom event name used when logging sanitizer concerns.
     * Optional. Defaults to "SanitizerConcerns" if not specified.
     */
public String notificationEventName = "SanitizerConcerns";
private String notificationEventName = "SanitizerConcerns";

/**
/**
* Flag to control whether sanitizer warnings are suppressed.
* Optional. Defaults to true.
*/
private boolean warningsOff = true;

/**
     * Constructs a new SanitizerConfiguration with the specified logger.
     *
     * @param logger The ILogger implementation used to log privacy concern events.
Expand All @@ -36,4 +42,34 @@ public SanitizerConfiguration(ILogger logger) {

this.loggerInstance = logger;
}

// Returns the logger instance used to record privacy concern events.
public ILogger getLogger() {
return this.loggerInstance;
}

// Returns the current event name used for logging sanitizer concerns. Defaults to "SanitizerConcerns" if not specified.
public String getNotificationEventName() {
return this.notificationEventName;
}

// Sets a custom event name for logging sanitizer concerns.
// Ignores null or empty strings to preserve the default value.
public void setEventName(String eventName) {
if (eventName != null && !eventName.trim().isEmpty()) {
this.notificationEventName = eventName;
}
}


// Returns whether warnings are currently turned off.
// True means enforcing sanitization; false means warnings are enabled.
public boolean isWarningsOff() {
return warningsOff;
}

// Sets the flag to enable or disable warnings.
public void setWarningsOff(boolean warningsOff) {
this.warningsOff = warningsOff;
}
}
5 changes: 4 additions & 1 deletion lib/jni/Sanitizer_jni.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ JNIEXPORT jboolean JNICALL
Java_com_microsoft_applications_events_Sanitizer_nativeInitialize(
JNIEnv *env, jclass /* this */,
jlong iLoggerNativePtr,
jstring notificationEventName) {
jstring notificationEventName,
jboolean warningsToSanitization) {

if (spSanitizer != nullptr) {
return false;
Expand All @@ -40,6 +41,8 @@ Java_com_microsoft_applications_events_Sanitizer_nativeInitialize(
sanitizerConfig.NotificationEventName = JStringToStdString(env, notificationEventName).c_str();
}

sanitizerConfig.SetAllWarningsToSanitizations = static_cast<bool>(warningsToSanitization);

spSanitizer = std::make_shared<Sanitizer>(sanitizerConfig);
return true;
}
Expand Down
1 change: 1 addition & 0 deletions wrappers/obj-c/ODWSanitizer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ +(void)initializeSanitizer:(ILogger *)logger withODWSanitizerInitConfig:(ODWSani
{
config.NotificationEventName = [[initConfigObject notificationEventName] UTF8String];
}
config.SetAllWarningsToSanitizations = initConfigObject.setWarningsToSanitization;

_sanitizerPtr = std::make_shared<Sanitizer>(config);
LogManager::GetInstance()->SetDataInspector(_sanitizerPtr);
Expand Down
8 changes: 8 additions & 0 deletions wrappers/obj-c/ODWSanitizerInitConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property(readwrite, copy, nonatomic) NSString* notificationEventName;

/*!
@brief (OPTIONAL) If enabled this will force sanitization for Urls, emails and site paths. The Default value is `YES`.
*/
@property(readwrite, nonatomic) BOOL setWarningsToSanitization;

// Initializer
- (instancetype)init;

@end
NS_ASSUME_NONNULL_END

Expand Down
9 changes: 9 additions & 0 deletions wrappers/obj-c/ODWSanitizerInitConfig.mm
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,13 @@
*/
@implementation ODWSanitizerInitConfig : NSObject

- (instancetype)init {
self = [super init];
if (self) {
_notificationEventName = @"SanitizerConcerns"; // Default event name
_setWarningsToSanitization = YES; // Default to true
}
return self;
}

@end
2 changes: 1 addition & 1 deletion wrappers/swift/Sources/OneDSSwift/Sanitizer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public final class Sanitizer {
}

/// Resets the Sanitizer instance.
public static func resetPrivacyGuardInstance() {
public static func resetSanitizerInstance() {
ODWSanitizer.resetSanitizerInstance()
}
}
10 changes: 10 additions & 0 deletions wrappers/swift/Sources/OneDSSwift/SanitizerInitConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ public final class SanitizerInitConfig {
}
}

/// (OPTIONAL) If enabled this will force sanitization for Urls, emails and site paths.
public var setWarningsToSanitization: Bool {
get {
odwSanitizerInitConfig.setWarningsToSanitization
}
set {
odwSanitizerInitConfig.setWarningsToSanitization = newValue
}
}

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

Expand Down
Loading