-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathODWPrivacyGuard.mm
More file actions
156 lines (135 loc) · 4.98 KB
/
ODWPrivacyGuard.mm
File metadata and controls
156 lines (135 loc) · 4.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
//
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
//
#include <stdexcept>
#include "ILogger.hpp"
#include "LogManager.hpp"
#include "PrivacyGuard.hpp"
#import <Foundation/Foundation.h>
#import "ODWLogConfiguration.h"
#import "ODWPrivacyGuard.h"
#import "ODWPrivacyGuard_private.h"
#import "ODWPrivacyGuardInitConfig.h"
using namespace MAT;
@implementation ODWPrivacyGuard
std::shared_ptr<PrivacyGuard> _privacyGuardPtr;
+(CommonDataContext)convertToNativeCommonDataContexts:(ODWCommonDataContext *)odwCDC
{
CommonDataContext cdc;
if([ [odwCDC DomainName] length] != 0)
{
cdc.DomainName = [[odwCDC DomainName] UTF8String];
}
if([[odwCDC MachineName] length] != 0)
{
cdc.MachineName = [[odwCDC MachineName] UTF8String];
}
if([odwCDC UserNames] != nil && [[odwCDC UserNames] count] != 0)
{
for(NSString* userName in [odwCDC UserNames])
{
cdc.UserNames.push_back([userName UTF8String]);
}
}
if([odwCDC UserAliases] != nil && [[odwCDC UserAliases] count] != 0)
{
for(NSString* userAlias in [odwCDC UserAliases])
{
cdc.UserAliases.push_back([userAlias UTF8String]);
}
}
if([odwCDC IpAddresses] != nil && [[odwCDC IpAddresses] count] != 0)
{
for(NSString* ipAddress in [odwCDC IpAddresses])
{
cdc.IpAddresses.push_back([ipAddress UTF8String]);
}
}
if([odwCDC LanguageIdentifiers] != nil && [[odwCDC LanguageIdentifiers] count] != 0)
{
for(NSString* languageIdentifiers in [odwCDC LanguageIdentifiers])
{
cdc.LanguageIdentifiers.push_back([languageIdentifiers UTF8String]);
}
}
if([odwCDC MachineIds] != nil && [[odwCDC MachineIds] count] != 0)
{
for(NSString* machineIds in [odwCDC MachineIds])
{
cdc.MachineIds.push_back([machineIds UTF8String]);
}
}
if([odwCDC OutOfScopeIdentifiers] != nil && [[odwCDC OutOfScopeIdentifiers] count] != 0)
{
for(NSString* outOfScopeIdentifiers in [odwCDC OutOfScopeIdentifiers])
{
cdc.OutOfScopeIdentifiers.push_back([outOfScopeIdentifiers UTF8String]);
}
}
return cdc;
}
+(void)initializePrivacyGuard:(ILogger *)logger withODWPrivacyGuardInitConfig:(ODWPrivacyGuardInitConfig *)initConfigObject
{
if (_privacyGuardPtr != nullptr)
{
return;
}
InitializationConfiguration config(logger, [ODWPrivacyGuard convertToNativeCommonDataContexts:[initConfigObject dataContext]]);
if ([initConfigObject notificationEventName] != nil)
{
config.NotificationEventName = [[initConfigObject notificationEventName] UTF8String];
}
if ([initConfigObject semanticContextNotificationEventName] != nil)
{
config.SemanticContextNotificationEventName = [[initConfigObject semanticContextNotificationEventName] UTF8String];
}
if ([initConfigObject metadataProvider] != nill)
{
config.metadataProvider = [[]]
}
if ([initConfigObject summaryEventName] != nil)
{
config.SummaryEventName = [[initConfigObject summaryEventName] UTF8String];
}
config.UseEventFieldPrefix = [initConfigObject useEventFieldPrefix];
config.ScanForUrls = [initConfigObject scanForUrls];
config.DisableAdvancedScans = [initConfigObject disableAdvancedScans];
config.StampEventIKeyForConcerns = [initConfigObject stampEventIKeyForConcerns];
_privacyGuardPtr = std::make_shared<PrivacyGuard>(config);
LogManager::GetInstance()->SetDataInspector(_privacyGuardPtr);
}
+(void)setEnabled:(bool)enabled
{
if(_privacyGuardPtr != nullptr)
{
_privacyGuardPtr->SetEnabled(enabled);
}
}
+(bool)enabled
{
return _privacyGuardPtr != nullptr && _privacyGuardPtr->IsEnabled();
}
+(void)appendCommonDataContext:(ODWCommonDataContext *) freshCommonDataContexts
{
_privacyGuardPtr->AppendCommonDataContext([ODWPrivacyGuard convertToNativeCommonDataContexts:freshCommonDataContexts]);
}
/*!
@brief Add ignored concern to prevent generation of notification signals when this
concern is found for the given EventName and Field combination.
@param EventName Event that the ignored concern should apply to. <b>Note:</b> If the ignored concern applies to Semantic Context field, set the Event name to 'SemanticContext'.
@param FieldName Field that the ignored concern should apply to.
@param IgnoredConcern The concern that is expected and should be ignored.
*/
+(void)addIgnoredConcern:(NSString *) EventName withNSString:(NSString *)FieldName withODWDataConcernType:(ODWDataConcernType)IgnoredConcern
{
const std::string eventName = [EventName UTF8String];
const std::string fieldName = [FieldName UTF8String];
const uint8_t ignoredConcern = (uint8_t)IgnoredConcern;
_privacyGuardPtr->AddIgnoredConcern(eventName, fieldName, static_cast<DataConcernType>(ignoredConcern));
}
+(void)resetPrivacyGuardInstance
{
_privacyGuardPtr = nullptr;
}
@end