Microsoft Information Protection SDK - C++ 1.17
API Reference Documentation for C++
Loading...
Searching...
No Matches
protection_profile.h
Go to the documentation of this file.
1/*
2 *
3 * Copyright (c) Microsoft Corporation.
4 * All rights reserved.
5 *
6 * This code is licensed under the MIT License.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files(the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions :
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 * THE SOFTWARE.
25 *
26 */
33#ifndef API_MIP_PROTECTION_PROTECTION_PROFILE_H_
34#define API_MIP_PROTECTION_PROTECTION_PROFILE_H_
35
36#include <memory>
37#include <string>
38
39#include "mip/common_types.h"
40#include "mip/dns_redirection.h"
41#include "mip/error.h"
42#include "mip/http_delegate.h"
43#include "mip/logger_delegate.h"
44#include "mip/mip_context.h"
45#include "mip/mip_export.h"
46#include "mip/mip_namespace.h"
50#include "mip/xml_delegate.h"
51
52MIP_NAMESPACE_BEGIN
53
60public:
66 class Observer {
67 public:
69 virtual ~Observer() { }
82 virtual void OnLoadSuccess(
83 const std::shared_ptr<ProtectionProfile>& profile,
84 const std::shared_ptr<void>& context) { UNUSED(profile); UNUSED(context); }
85
96 virtual void OnLoadFailure(
97 const std::exception_ptr& error,
98 const std::shared_ptr<void>& context) { UNUSED(error); UNUSED(context); }
99
107 const std::vector<std::string>& engineIds,
108 const std::shared_ptr<void>& context) { UNUSED(engineIds); UNUSED(context); }
109
117 const std::exception_ptr& error,
118 const std::shared_ptr<void>& context) { UNUSED(error); UNUSED(context); }
119
126 virtual void OnAddEngineSuccess(
127 const std::shared_ptr<ProtectionEngine>& engine,
128 const std::shared_ptr<void>& context) { UNUSED(engine); UNUSED(context); }
129
136 virtual void OnAddEngineFailure(
137 const std::exception_ptr& error,
138 const std::shared_ptr<void>& context) { UNUSED(error); UNUSED(context); }
139
146 const std::shared_ptr<void>& context) { UNUSED(context); }
147
155 const std::exception_ptr& error,
156 const std::shared_ptr<void>& context) { UNUSED(error); UNUSED(context); }
157
159 protected:
160 Observer() { }
162 };
163
167 class Settings {
168 public:
179 const std::shared_ptr<MipContext>& mipContext,
180 CacheStorageType cacheStorageType,
181 const std::shared_ptr<ConsentDelegate>& consentDelegate,
182 const std::shared_ptr<ProtectionProfile::Observer>& observer)
183 : mMipContext(mipContext),
184 mCacheStorageType(cacheStorageType),
185 mConsentDelegate(consentDelegate),
186 mObserver(observer),
187 mCanCacheLicenses(true),
188#if defined(MIP_OFFLINE_PUBLISHING_ENABLED) || defined(SWIG) || defined(SWIG_DIRECTORS)
189 mOfflinePublishing(false),
190#endif // MIP_OFFLINE_PUBLISHING_ENABLED
192 }
193
203 const std::shared_ptr<MipContext>& mipContext,
204 CacheStorageType cacheStorageType,
205 const std::shared_ptr<ConsentDelegate>& consentDelegate)
206 : Settings(mipContext, cacheStorageType, consentDelegate, nullptr /*observer*/) {
207 }
208
210 ~Settings() { }
219
225 std::shared_ptr<ConsentDelegate> GetConsentDelegate() const { return mConsentDelegate; }
226
232 std::shared_ptr<ProtectionProfile::Observer> GetObserver() const { return mObserver; }
233
239 std::shared_ptr<MipContext> GetMipContext() const { return mMipContext; }
240
246 std::shared_ptr<HttpDelegate> GetHttpDelegate() const { return mHttpDelegate; }
247
253 void SetHttpDelegate(const std::shared_ptr<HttpDelegate>& httpDelegate) { mHttpDelegate = httpDelegate; }
254
260 std::shared_ptr<StorageDelegate> GetStorageDelegate() const { return mStorageDelegate; }
261
267 void SetStorageDelegate(const std::shared_ptr<StorageDelegate>& storageDelegate) { mStorageDelegate = storageDelegate; }
268
274 std::shared_ptr<TaskDispatcherDelegate> GetTaskDispatcherDelegate() const { return mTaskDispatcherDelegate; }
275
284 void SetTaskDispatcherDelegate(const std::shared_ptr<TaskDispatcherDelegate>& taskDispatcherDelegate) {
285 mTaskDispatcherDelegate = taskDispatcherDelegate;
286 }
287
293 void SetSessionId(const std::string& sessionId) { mSessionId = sessionId; }
294
300 const std::string& GetSessionId() const { return mSessionId; }
301
310 void SetCanCacheLicenses(bool canCacheLicenses) {
311 mCanCacheLicenses = canCacheLicenses;
312 }
313
319 bool CanCacheLicenses() const {
320 return mCanCacheLicenses;
321 }
322
328 void SetCustomSettings(const std::vector<std::pair<std::string, std::string>>& customSettings) {
329 mCustomSettings = customSettings;
330 }
331
337 const std::vector<std::pair<std::string, std::string>>& GetCustomSettings() const {
338 return mCustomSettings;
339 }
340
341#if !defined(SWIG) && !defined(SWIG_DIRECTORS)
347 const std::shared_ptr<void>& GetLoggerContext() const { return mLoggerContext; }
348#endif
349
356 void SetLoggerContext(const std::shared_ptr<void>& loggerContext) {
357 mLoggerContext = loggerContext;
358 }
359
371 void AddRedirectionUri(const std::string& originalUri, const std::string& redirectUri) {
372 mRedirectionUris[originalUri] = redirectUri;
373 }
374
380 const std::map<std::string, std::string>& GetRedirectionUris() const {
381 return mRedirectionUris;
382 }
383#if defined(MIP_OFFLINE_PUBLISHING_ENABLED) || defined(SWIG) || defined(SWIG_DIRECTORS)
389 bool GetOfflinePublishing() const {
390 return mOfflinePublishing;
391 }
392
399 void SetOfflinePublishing(bool offlinePublishing) {
400 mOfflinePublishing = offlinePublishing;
401 }
402#endif // MIP_OFFLINE_PUBLISHING_ENABLED
403
412
418 void SetDnsRedirection(DnsRedirection dnsRedirection) {
419 mDnsRedirection = dnsRedirection;
420 }
421
422 private:
423 std::shared_ptr<MipContext> mMipContext;
425 std::shared_ptr<ConsentDelegate> mConsentDelegate;
426 std::shared_ptr<ProtectionProfile::Observer> mObserver;
427 std::shared_ptr<HttpDelegate> mHttpDelegate;
428 std::shared_ptr<TaskDispatcherDelegate> mTaskDispatcherDelegate;
429 std::string mSessionId;
430 bool mCanCacheLicenses = true;
431 std::vector<std::pair<std::string, std::string>> mCustomSettings;
432 std::shared_ptr<void> mLoggerContext;
433 std::map<std::string, std::string> mRedirectionUris;
434 std::shared_ptr<StorageDelegate> mStorageDelegate;
435#if defined(MIP_OFFLINE_PUBLISHING_ENABLED) || defined(SWIG) || defined(SWIG_DIRECTORS)
436 bool mOfflinePublishing;
437#endif // MIP_OFFLINE_PUBLISHING_ENABLED
439 };
440
452 MIP_API static std::shared_ptr<AsyncControl> __CDECL LoadAsync(
453 const Settings& settings,
454 const std::shared_ptr<void>& context);
455
463 MIP_API static std::shared_ptr<ProtectionProfile> __CDECL Load(const Settings& settings);
464
470 MIP_API static const char* __CDECL GetVersion();
471
477 virtual const Settings& GetSettings() const = 0;
478
488 virtual std::shared_ptr<AsyncControl> ListEnginesAsync(const std::shared_ptr<void>& context) = 0;
489
495 virtual std::vector<std::string> ListEngines() = 0;
496
507 virtual std::shared_ptr<AsyncControl> AddEngineAsync(
508 const ProtectionEngine::Settings& settings,
509 const std::shared_ptr<void>& context) = 0;
510
518 virtual std::shared_ptr<ProtectionEngine> AddEngine(const ProtectionEngine::Settings& settings) = 0;
519
530 virtual std::shared_ptr<AsyncControl> DeleteEngineAsync(
531 const std::string& engineId,
532 const std::shared_ptr<void>& context) = 0;
533
539 virtual void DeleteEngine(const std::string& engineId) = 0;
540
541#ifndef MIP_CORE_PACKAGE
551#if !defined(SWIG) && !defined(SWIG_DIRECTORS)
552 [[deprecated("ProtectionProfile::GetPublishingLicenseInfo(const std::vector<uint8_t>&) is deprecated, use ProtectionProfile::GetPublishingLicenseInfo(const std::vector<uint8_t>&, const std::shared_ptr<MipContext>&)")]]
553#endif
554 MIP_API static std::shared_ptr<PublishingLicenseInfo> __CDECL GetPublishingLicenseInfo(
555 const std::vector<uint8_t>& serializedPublishingLicense);
556#endif // !MIP_CORE_PACKAGE
557
568 MIP_API static std::shared_ptr<PublishingLicenseInfo> __CDECL GetPublishingLicenseInfo(
569 const std::vector<uint8_t>& serializedPublishingLicense,
570 const std::shared_ptr<MipContext>& mipContext);
571
573 virtual ~ProtectionProfile() { }
575 };
576
577MIP_NAMESPACE_END
578
579#endif // API_MIP_PROTECTION_PROTECTION_PROFILE_H_
Settings used by ProtectionEngine during its creation and throughout its lifetime.
Definition protection_engine.h:309
Interface that receives notifications related to ProtectionProfile.
Definition protection_profile.h:66
virtual void OnListEnginesSuccess(const std::vector< std::string > &engineIds, const std::shared_ptr< void > &context)
Called when list of engines was generated successfully.
Definition protection_profile.h:106
virtual void OnDeleteEngineSuccess(const std::shared_ptr< void > &context)
Called when an engine was deleted successfully.
Definition protection_profile.h:145
virtual void OnLoadSuccess(const std::shared_ptr< ProtectionProfile > &profile, const std::shared_ptr< void > &context)
Called when profile was loaded successfully.
Definition protection_profile.h:82
virtual void OnAddEngineFailure(const std::exception_ptr &error, const std::shared_ptr< void > &context)
Called when adding a new engine resulted in an error.
Definition protection_profile.h:136
virtual void OnDeleteEngineFailure(const std::exception_ptr &error, const std::shared_ptr< void > &context)
Called when deleting an engine resulted in an error.
Definition protection_profile.h:154
virtual void OnAddEngineSuccess(const std::shared_ptr< ProtectionEngine > &engine, const std::shared_ptr< void > &context)
Called when a new engine was added successfully.
Definition protection_profile.h:126
virtual void OnLoadFailure(const std::exception_ptr &error, const std::shared_ptr< void > &context)
Called when loading a profile caused an error.
Definition protection_profile.h:96
virtual void OnListEnginesFailure(const std::exception_ptr &error, const std::shared_ptr< void > &context)
Called when listing engines resulted in an error.
Definition protection_profile.h:116
Settings used by ProtectionProfile during its creation and throughout its lifetime.
Definition protection_profile.h:167
std::shared_ptr< MipContext > mMipContext
Definition protection_profile.h:423
std::shared_ptr< HttpDelegate > mHttpDelegate
Definition protection_profile.h:427
std::shared_ptr< TaskDispatcherDelegate > mTaskDispatcherDelegate
Definition protection_profile.h:428
std::map< std::string, std::string > mRedirectionUris
Definition protection_profile.h:433
std::shared_ptr< ConsentDelegate > mConsentDelegate
Definition protection_profile.h:425
std::shared_ptr< ConsentDelegate > GetConsentDelegate() const
Gets the consent delegate used for connecting to services.
Definition protection_profile.h:225
Settings(const std::shared_ptr< MipContext > &mipContext, CacheStorageType cacheStorageType, const std::shared_ptr< ConsentDelegate > &consentDelegate, const std::shared_ptr< ProtectionProfile::Observer > &observer)
ProtectionProfile::Settings constructor that specifies an observer to be used for async operations.
Definition protection_profile.h:178
bool CanCacheLicenses() const
Gets whether or not end user licenses (EULs) are cached locally.
Definition protection_profile.h:319
std::shared_ptr< MipContext > GetMipContext() const
Get MIP context which represents shared state across all profiles.
Definition protection_profile.h:239
std::shared_ptr< StorageDelegate > mStorageDelegate
Definition protection_profile.h:434
void SetLoggerContext(const std::shared_ptr< void > &loggerContext)
Sets the logger context that will be opaquely passed to the logger delegate for logs associated with ...
Definition protection_profile.h:356
std::shared_ptr< HttpDelegate > GetHttpDelegate() const
Get the HTTP delegate (if any) provided by the application.
Definition protection_profile.h:246
CacheStorageType GetCacheStorageType() const
Get whether caches are stored in memory or on disk.
Definition protection_profile.h:218
void SetDnsRedirection(DnsRedirection dnsRedirection)
Sets the dns redirection mode that controls how redirection is handled during online operations.
Definition protection_profile.h:418
CacheStorageType mCacheStorageType
Definition protection_profile.h:424
DnsRedirection mDnsRedirection
Definition protection_profile.h:438
void SetTaskDispatcherDelegate(const std::shared_ptr< TaskDispatcherDelegate > &taskDispatcherDelegate)
Override default asynchonous task dispatching handling with client's own.
Definition protection_profile.h:284
const std::map< std::string, std::string > & GetRedirectionUris() const
Gets the redirection uris.
Definition protection_profile.h:380
std::vector< std::pair< std::string, std::string > > mCustomSettings
Definition protection_profile.h:431
void SetCustomSettings(const std::vector< std::pair< std::string, std::string > > &customSettings)
Set the custom settings, used for feature gating and testing.
Definition protection_profile.h:328
void SetStorageDelegate(const std::shared_ptr< StorageDelegate > &storageDelegate)
Override default storage cache with client's own implementation.
Definition protection_profile.h:267
std::shared_ptr< ProtectionProfile::Observer > mObserver
Definition protection_profile.h:426
void SetCanCacheLicenses(bool canCacheLicenses)
Configures whether or not end user licenses (EULs) will be cached locally.
Definition protection_profile.h:310
std::shared_ptr< void > mLoggerContext
Definition protection_profile.h:432
std::string mSessionId
Definition protection_profile.h:429
void SetHttpDelegate(const std::shared_ptr< HttpDelegate > &httpDelegate)
Override default HTTP stack with client's own.
Definition protection_profile.h:253
bool mCanCacheLicenses
Definition protection_profile.h:430
void AddRedirectionUri(const std::string &originalUri, const std::string &redirectUri)
Adds a redirect uri.
Definition protection_profile.h:371
std::shared_ptr< ProtectionProfile::Observer > GetObserver() const
Gets the observer that receives notifications of events related to ProtectionProfile.
Definition protection_profile.h:232
std::shared_ptr< TaskDispatcherDelegate > GetTaskDispatcherDelegate() const
Get the TaskDispatcher delegate (if any) provided by the application.
Definition protection_profile.h:274
DnsRedirection GetDnsRedirection() const
Gets the dns redirect mode.
Definition protection_profile.h:409
const std::shared_ptr< void > & GetLoggerContext() const
Get logger context that will be opaquely passed to the logger delegate for logs associated with the c...
Definition protection_profile.h:347
Settings(const std::shared_ptr< MipContext > &mipContext, CacheStorageType cacheStorageType, const std::shared_ptr< ConsentDelegate > &consentDelegate)
ProtectionProfile::Settings constructor, used for synchronous operations.
Definition protection_profile.h:202
void SetSessionId(const std::string &sessionId)
Sets the session ID.
Definition protection_profile.h:293
const std::string & GetSessionId() const
Gets the session ID.
Definition protection_profile.h:300
std::shared_ptr< StorageDelegate > GetStorageDelegate() const
Get the StorageDelegate (if any) provided by the application.
Definition protection_profile.h:260
const std::vector< std::pair< std::string, std::string > > & GetCustomSettings() const
Get the custom settings, used for feature gating and testing.
Definition protection_profile.h:337
ProtectionProfile is the root class for performing protection operations.
Definition protection_profile.h:59
virtual std::shared_ptr< AsyncControl > AddEngineAsync(const ProtectionEngine::Settings &settings, const std::shared_ptr< void > &context)=0
Starts adding a new protection engine to the profile.
virtual std::vector< std::string > ListEngines()=0
List engines.
static MIP_API std::shared_ptr< PublishingLicenseInfo > __CDECL GetPublishingLicenseInfo(const std::vector< uint8_t > &serializedPublishingLicense)
Creates a holder for details of a Publishing License and can be used to create a Protection Handler.
static MIP_API std::shared_ptr< PublishingLicenseInfo > __CDECL GetPublishingLicenseInfo(const std::vector< uint8_t > &serializedPublishingLicense, const std::shared_ptr< MipContext > &mipContext)
Creates a holder for details of a Publishing License and can be used to create a Protection Handler....
static MIP_API std::shared_ptr< ProtectionProfile > __CDECL Load(const Settings &settings)
Loading a profile based on the provided settings.
static MIP_API const char *__CDECL GetVersion()
Gets library version.
virtual void DeleteEngine(const std::string &engineId)=0
Delete the protection engine with the given ID. All data for the given engine will be deleted.
virtual std::shared_ptr< AsyncControl > ListEnginesAsync(const std::shared_ptr< void > &context)=0
Starts list engines operation.
static MIP_API std::shared_ptr< AsyncControl > __CDECL LoadAsync(const Settings &settings, const std::shared_ptr< void > &context)
Starts loading a profile based on the provided settings.
virtual const Settings & GetSettings() const =0
Gets settings used by ProtectionProfile during its initialization and throughout its lifetime.
virtual std::shared_ptr< ProtectionEngine > AddEngine(const ProtectionEngine::Settings &settings)=0
Add a new protection engine to the profile.
virtual std::shared_ptr< AsyncControl > DeleteEngineAsync(const std::string &engineId, const std::shared_ptr< void > &context)=0
Starts deleting the protection engine with the given ID. All data for the given engine will be delete...
A file Containing the common types used by the upe, file and protection modules.
CacheStorageType
Storage type for the caches.
Definition common_types.h:710
A file Containing types used to control dns redirection.
DnsRedirection
Storage type for the caches.
Definition dns_redirection.h:43
A file containing the MIP SDK error types.
Contains HttpDelegate interface definition used to override MIP HTTP stack.
A file containing the LoggerDelegate class to be used to override MIP logger.
File containing definition of MipContext.
A file export/import macros.
MIP namespace macros.
A file containing the common types used by the protection module.
Defines ProtectionEngine interface.
A file containing the TaskDispatcherDelegate interface to be used to override MIP async task executor...
Contains XmlDelegate interface definition used to parse xml recieved by mip.