| KEYZY C++ Client Library 1.7.0 To develop software that is compiled with a C++ compiler and utilizes the KEYZY service (www.keyzy.io)

Loading...
Searching...
No Matches
Getting started with Keyzy C++ Client Library

# General overview of Keyzy C++ Client Library

The main idea behind the Keyzy C++ Client library is to offer simple methods for activating and validating your product's license management. Additionally, it provides functionality for registering trial licenses.

To activate and validate licenses, you need to utilize the following classes:

- KeyzyLicenseActivator
- KeyzyLicenseValidator

These classes provide the necessary functionality for license activation and validation within the Keyzy C++ Client library.

To deposit licenses from directly client-side, you will need to utilize the LicenseDepositHandler class. This class enables the depositing of licenses from the KEYZY service to the client device.

The KeyzyLicenseActivator class utilizes the ProductData structure as an input argument in its constructor. This allows the system to identify the specific product on the server side for license activation and validation purposes. By providing the relevant product information through the ProductData structure, the system can accurately handle the licensing operations associated with that product.

struct ProductData
{
ProductData() : _useHostIdInOffilneActivation(true) {}
ProductData(std::string appId, std::string apiKey, std::string productCode,
std::string cryptionKey, bool useHostIdInOfflineActivation = true)
: _appId(appId)
, _apiKey(apiKey)
, _productCode(productCode)
, _cryptionKey(cryptionKey)
, _useHostIdInOffilneActivation(useHostIdInOfflineActivation) {}
std::string _appId;
std::string _apiKey;
std::string _productCode;
std::string _cryptionKey; /** Offline activation schema only */
bool _useHostIdInOffilneActivation; /** Default set to "true" */
};

- You can obtain an appId and apiKey pair from the "App Keys" section of the Keyzy Admin Panel at App Keys .
- The product code can be obtained from the "Products" section of the Keyzy Admin Panel at Products .
- If you are using the offline activation/validation schema, you will need to set the _cryptionKey member. You can retrieve this key from the "Products" section of the Keyzy Admin Panel at Products as well.

# Product activation process

The product activation process should be performed only once for each run of the software, usually when users launch your application for the first time. The Keyzy C++ Client Library will internally store the provided data and use it for license validation purposes.

KeyzyLicenseActivator class provides the following methods that should be uses to activate or deactivate a license:

- LicenseStatus activateOnline(const std::string& serialNumber);
- LicenseStatus deactivateOnline();
- LicenseStatus activateSemiOnline(const std::string& serialNumber);
- LicenseStatus activateSemiOnline();
- LicenseStatus deactivateSemiOnline();
- LicenseStatus activateOffline(const std::string& licenseFilePath);
- bool deactivateOffline();

# License validation process

## Online license validation

The online validation process uses a serial number, which can be provided by the user or obtained through the LicenseDepositHandler along with other information such as ProductData or HostId. The information is used to send an HTTP POST request to the KEYZY Service to validate the license.

You need to call the LicenseStatus validateOnline() function from the KeyzyLicenseValidator class. If the serial number is valid, this function will return the value LicenseStatus::VALID.

## Offline license validation

The offline validation process uses a license file provided by the KeyzyLicenseActivator class and does not require an internet connection.

You need to call the LicenseStatus validateOffline() function from KeyzyLicenseValidator class. If the license file is valid, this function will return the value LicenseStatus::VALID.

Semi-Online activation schema uses the offline validation process as well.

## All error statuses

Status | Explanation
--- | ---
LicenseStatus::EXPIRED | If local trial is expired, it is returned by validateTrialLicense() method from KeyzyLicenseValidator class.
LicenseStatus::NOT_AUTHORIZED | If your appId and apiKey pair is wrong, it is returned by validateOnline() method from KeyzyLicenseValidator class.
LicenseStatus::SERIAL_INVALID | If the serial number is invalid or not registered, it is returned by related member functions (validateOnline() method from KeyzyLicenseValidator class and downloadLicenseFile() method from KeyzyLicenseManager class).
LicenseStatus::PRODUCT_NOT_EXIST | If the product code does not exist, it is returned by related member functions (validateOnline() method from KeyzyLicenseValidator class and downloadLicenseFile() method from KeyzyLicenseManager class).
LicenseStatus::PRODUCT_NOT_EXIST_FOR_USER | If the product code does not exist, it is returned by related member functions (validateOnline() method from KeyzyLicenseValidator class and downloadLicenseFile() method from KeyzyLicenseManager class).
LicenseStatus::PRODUCT_NOT_ACTIVE | If the product is not active, it is returned by related member functions (validateOnline() method from KeyzyLicenseValidator class and downloadLicenseFile() method from KeyzyLicenseManager class).
LicenseStatus::SKU_NOT_EXIST | If the SKU does not exist, it is returned by related member functions (validateOnline() method from KeyzyLicenseValidator class and downloadLicenseFile() method from KeyzyLicenseManager class).
LicenseStatus::SKU_NOT_ACTIVE | If the SKU is not active, it is returned by related member functions (validateOnline() method from KeyzyLicenseValidator class and downloadLicenseFile() method from KeyzyLicenseManager class).
LicenseStatus::REACHED_MAX_NUMBER_OF_HOST | If activation host count is exceed, it is returned by related member functions (validateOnline() method from KeyzyLicenseValidator class and downloadLicenseFile() method from KeyzyLicenseManager class).
LicenseStatus::PRODUCT_NOT_EXIST_FOR_SKU | If the product exists but not included the SKU which connected to the license, it is returned by related member functions (validateOnline() method from KeyzyLicenseValidator class and downloadLicenseFile() method from KeyzyLicenseManager class).
LicenseStatus::ACTIVATION_DEACTIVATED | If an activation is deactivated, it is returned by related member functions (validateOnline() method from KeyzyLicenseValidator class and downloadLicenseFile() method from KeyzyLicenseManager class).
LicenseStatus::SUBSCRIPTION_LICENSE_EXPIRED | If a subscription license is expired, it is returned by related member functions (validateOnline() method from KeyzyLicenseValidator class and downloadLicenseFile() method from KeyzyLicenseManager class).
LicenseStatus::SUBSCRIPTION_LICENSE_NOT_STARTED | If a subscription license is not started yet (e.g. has a future start time), it is returned by related member functions (validateOnline() method from KeyzyLicenseValidator class and downloadLicenseFile() method from KeyzyLicenseManager class).
LicenseStatus::TRIAL_LICENSE_EXPIRED | If a server trial license is expired, it is returned by related member functions (validateOnline() method from KeyzyLicenseValidator class and downloadLicenseFile() method from KeyzyLicenseManager class).
LicenseStatus::TRIAL_LICENSE_NOT_STARTED | If a server trial license is not started yet (e.g. has a future start time), it is returned by related member functions (validateOnline() method from KeyzyLicenseValidator class and downloadLicenseFile() method from KeyzyLicenseManager class).
LicenseStatus::CANNOT_KEEP_SERIAL | If client side cannot keep the serial number in the device, it is returned.
LicenseStatus::CANNOT_KEEP_LICENSE_FILE | If client side cannot keep the license file in the device (cannot copy the file to the path, probably input file path is wrong), it is returned.
LicenseStatus::ACTIVATION_DELETED | If the activation is deleted successfully in KEYZY servers, it is returned.
LicenseStatus::CLIENT_SERIAL_DOES_NOT_EXIST | If there is no serial number exists in the device, it is returned.
LicenseStatus::CONNECTION_ERROR | Network or firewall error. Internet connection is intermittent or firewall on.
LicenseStatus::TOO_MANY_REQUESTS | If the client-side sends lots of requests in a short time, it is returned.
LicenseStatus::NO_ACTIVE_SUBSCRIPTION | The account holder has a subscription issue in KEYZY.
LicenseStatus::CURRENT_LICENSE_DOES_NOT_EXIST | The serial number that belongs to current license does not exist in the KEYZY servers.
LicenseStatus::UPGRADE_LICENSE_DOES_NOT_EXIST | The serial number that belongs to upgrade license does not exist in the KEYZY servers.
LicenseStatus::UPGRADE_LICENSE_DOES_NOT_MATCH | The upgrade license does not match for upgrade with the current license!
LicenseStatus::ANOTHER_TRIAL_LICENSE_ALREADY_ACTIVATED | Another trial license has already been activated on this device!
LicenseStatus::SKU_NUMBER_VALIDATION | sku_number parameter cannot be validated!
LicenseStatus::PRODUCT_CODE_VALIDATION | product_code parameter cannot be validated!
LicenseStatus::NAME_VALIDATION | name parameter cannot be validated!
LicenseStatus::EMAIL_VALIDATION | email parameter cannot be validated!
LicenseStatus::NO_FREE_LICENSES | You do not have any free licenses for this sku. Please generate new licenses for this sku!
LicenseStatus::NAME_OR_EMAIL_VALIDATION | Either the name or email filed must be filled!
LicenseStatus::LICENSE_NOT_EXIST_NOT_ASSIGNED_DEALER_ALREADY_DEPOSITED | The license does not exist or is not assigned to a dealer or is already deposited!
LicenseStatus::INVALID | It is returned for the rest.

# Example of register offline distributed license process

Demonstrates depositing an offline license by the client side. It updated the name and the email address of an offline license.

#include <KeyzyLicenseActivator.h>
#include <iostream> // for std::cout
using namespace Keyzy;
int main()
{
ProductData data;
const std::string serialNumber = "****-****-****-****-****";
data._appId = "********";
data._apiKey = "****************************************";
data._productCode = "********-****-****-****-************";
data._cryptionKey = "********************************";
std::unique_ptr<KeyzyLicenseActivator> pLicenseActivator = std::make_unique<KeyzyLicenseActivator>(data);
std::shared_ptr<LicenseDepositHandler> pLicenseDepositHandler = pLicenseActivator->getLicenseDepositHandler();
LicenseStatus registerDistributedLicenseStatus = LicenseStatus::VALID;
registerDistributedLicenseStatus = pLicenseDepositHandler->registerOfflineDistributedLicense(serialNumber, "John Doe", "john@doe.com");
if (registerDistributedLicenseStatus != LicenseStatus::VALID) {
std::cout << errorStatuses(registerDistributedLicenseStatus) << std::endl;
} else {
std::cout << "The license successfully registered.";
}
return 0;
}
// please find errorStatuses() function below of this page

# Example of register trial license process

Demonstrates depositing a trial license from the client side. Sends a trial license request with the provided SKU number to the KEYZY service. If a free trial license is available for the given SKU number, KEYZY deposits the license and responds with the information.

#include <KeyzyLicenseActivator.h>
#include <iostream> // for std::cout
using namespace Keyzy;
int main()
{
ProductData data;
std::string serialNumber = "";
data._appId = "********";
data._apiKey = "****************************************";
data._productCode = "********-****-****-****-************";
data._cryptionKey = "********************************";
std::unique_ptr<KeyzyLicenseActivator> pLicenseActivator = std::make_unique<KeyzyLicenseActivator>(data);
std::shared_ptr<LicenseDepositHandler> pLicenseDepositHandler = pLicenseActivator->getLicenseDepositHandler();
LicenseStatus registerTrialStatus = LicenseStatus::VALID;
LicenseInfo licenseInfo;
registerTrialStatus = pLicenseDepositHandler->registerTrial(licenseInfo, "your-sku-number", "optional-licensee-name");
if (registerTrialStatus != LicenseStatus::VALID) {
std::cout << errorStatuses(registerTrialStatus) << std::endl;
} else {
std::cout << "Start Time : " << licenseInfo._startTime << std::endl;
std::cout << "End Time : " << licenseInfo._endTime << std::endl;
std::cout << "Serial Number : " << licenseInfo._serialNumber << std::endl;
serialNumber = licenseInfo._serialNumber;
}
return 0;
}
// please find errorStatuses() function below of this page

# Example of upgrade license process

The upgradeLicense() method only performs the upgrade on the KEYZY server. It does not activate or validate the new license, and does not store the target serial on the device. To activate the target serial afterward, use one of the activation methods (e.g. activateOnline, activateSemiOnline).

## Upgrade using stored serial (recommended)

If the source serial is already stored on the device (from a previous activation), you only need to provide the target serial:

#include <iostream> // for std::cout
#include <KeyzyLicenseActivator.h>
using namespace Keyzy;
std::string errorStatuses(LicenseStatus status);
int main()
{
// fill ProductData struct to identify specific product
ProductData data;
data._appId = "xxxxxxxx";
data._apiKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
data._productCode = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
// Get an activator object
std::unique_ptr<KeyzyLicenseActivator> pLicenseActivator = std::make_unique<KeyzyLicenseActivator>(data);
// Source serial is read from the device automatically
LicenseStatus status = pLicenseActivator->upgradeLicense("TARG-ETSE-RIAL-XXXX-XXXX");
std::cout << "Upgrade License Status: " << errorStatuses(status) << std::endl;
if (status == LicenseStatus::VALID) {
// Activate the target serial on the device
status = pLicenseActivator->activateOnline("TARG-ETSE-RIAL-XXXX-XXXX");
std::cout << "Activation Status: " << errorStatuses(status) << std::endl;
}
}
// please find errorStatuses() function below of this page

## Upgrade with explicit source and target serials

You can also provide both serials explicitly:

#include <iostream> // for std::cout
#include <KeyzyLicenseActivator.h>
using namespace Keyzy;
std::string errorStatuses(LicenseStatus status);
int main()
{
// fill ProductData struct to identify specific product
ProductData data;
data._appId = "xxxxxxxx";
data._apiKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
data._productCode = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
// Get an activator object
std::unique_ptr<KeyzyLicenseActivator> pLicenseActivator = std::make_unique<KeyzyLicenseActivator>(data);
LicenseStatus status = pLicenseActivator->upgradeLicense("SOUR-CESE-RIAL-XXXX-XXXX", "TARG-ETSE-RIAL-XXXX-XXXX");
std::cout << "Upgrade License Status: " << errorStatuses(status) << std::endl;
if (status == LicenseStatus::VALID) {
// Activate the target serial on the device
status = pLicenseActivator->activateOnline("TARG-ETSE-RIAL-XXXX-XXXX");
std::cout << "Activation Status: " << errorStatuses(status) << std::endl;
}
}
// please find errorStatuses() function below of this page

# Example of depositing a trial license using the LicenseDepositHandle class

#include <iostream> // for std::cout
#include <KeyzyLicenseActivator.h>
using namespace Keyzy;
std::string errorStatuses(LicenseStatus status);
int main()
{
// fill ProductData struct to identify specific product
ProductData data;
data._appId = "xxxxxxxx";
data._apiKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
data._productCode = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
data._cryptionKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
// Get an activator object
std::unique_ptr<KeyzyLicenseActivator> pLicenseActivator =
std::make_unique<KeyzyLicenseActivator>(data);
// Get a deposit handler object
std::shared_ptr<LicenseDepositHandler> pLicenseDepositHandler =
pLicenseActivator->getLicenseDepositHandler();
// Get a status enum object
LicenseStatus registerTrialStatus = LicenseStatus::VALID;
// Get a license info object
LicenseInfo licenseInfo;
// Perform the registration process
registerTrialStatus = pLicenseDepositHandler->registerTrial(licenseInfo, "your-sku-number", "optional-licensee-name", "optional-licensee-email");
// Check the result
if (registerTrialStatus != LicenseStatus::VALID) {
// Error
std::cout << errorStatuses(registerTrialStatus) << std::endl;
} else {
std::cout << "Start Time : " << licenseInfo._startTime << std::endl;
std::cout << "End Time : " << licenseInfo._endTime << std::endl;
std::cout << "Serial Number : " << licenseInfo._serialNumber << std::endl;
// Get the serial number to use in one of the activation process
serialNumber = licenseInfo._serialNumber;
}
}
// please find errorStatuses() function below of this page

# Example of online license validation and activation process

#include <iostream> // for std::cout
#include <KeyzyLicenseActivator.h>
using namespace Keyzy;
std::string errorStatuses(LicenseStatus status);
int main()
{
// fill ProductData struct to identify specific product
ProductData data;
data._appId = "xxxxxxxx";
data._apiKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
data._productCode = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
// Get an activator object
std::unique_ptr<KeyzyLicenseActivator> pLicenseActivator =
std::make_unique<KeyzyLicenseActivator>(data);
// Get a validator object
std::shared_ptr<KeyzyLicenseValidator> pLicenseValidator =
pLicenseActivator->getLicenseValidator();
const std::string serialNumber = "XXXX-XXXX-XXXX-XXXX-XXXX";
LicenseStatus status = LicenseStatus::VALID;
if (pLicenseValidator->validateOnline() != LicenseStatus::VALID) {
// bring serial number input window to the user
status = pLicenseActivator->activateOnline(serialNumber);
std::cout << std::endl;
std::cout << "Online Activation Status: " << errorStatuses(status) << std::endl << std::endl;
std::cout << "Licensee's Name: " << pLicenseValidator->getLicenseeName() << std::endl;
std::cout << "Licensee's Email: " << pLicenseValidator->getLicenseeEmail() << std::endl;
std::cout << "Version: " << pLicenseValidator->getVersion() << std::endl;
std::cout << "Sku: " << pLicenseValidator->getSku() << std::endl;
std::cout << "License Type: " << pLicenseValidator->getLicenseType() << std::endl;
std::cout << "Start Time: " << pLicenseValidator->getStartTime() << std::endl;
std::cout << "End Time: " << pLicenseValidator->getEndTime() << std::endl;
std::cout << "Info: " << pLicenseValidator->getInfo() << std::endl;
} else {
std::cout << "Licensee's Name: " << pLicenseValidator->getLicenseeName() << std::endl;
std::cout << "Licensee's Email: " << pLicenseValidator->getLicenseeEmail() << std::endl;
std::cout << "Version: " << pLicenseValidator->getVersion() << std::endl;
std::cout << "Sku: " << pLicenseValidator->getSku() << std::endl;
std::cout << "License Type: " << pLicenseValidator->getLicenseType() << std::endl;
std::cout << "Start Time: " << pLicenseValidator->getStartTime() << std::endl;
std::cout << "End Time: " << pLicenseValidator->getEndTime() << std::endl;
std::cout << "Info: " << pLicenseValidator->getInfo() << std::endl;
std::cout << "Online Validation Status: " << errorStatuses(status) << std::endl << std::endl;
}
status = pLicenseActivator->deactivateOnline();
std::cout << "Online Deactivation Status: " << errorStatuses(status) << std::endl << std::endl;
}
// please find errorStatuses() function below of this page

# Example of offline license validation and activation process

#include <iostream> // for std::cout
#include <KeyzyLicenseActivator.h>
#include <KeyzyLicenseValidator.h>
using namespace Keyzy;
std::string errorStatuses(LicenseStatus status);
int main()
{
// fill ProductData struct to identify specific product
ProductData data;
data._appId = "xxxxxxxx";
data._apiKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
data._productCode = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
data._cryptionKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
// Get an activator object
std::unique_ptr<KeyzyLicenseActivator> pLicenseActivator =
std::make_unique<KeyzyLicenseActivator>(data);
// Get a validator object
std::shared_ptr<KeyzyLicenseValidator> pLicenseValidator =
pLicenseActivator->getLicenseValidator();
LicenseStatus status = LicenseStatus::VALID;
if (pLicenseValidator->validateOffline() != LicenseStatus::VALID) {
status = pLicenseActivator->activateOffline("/Users/user111/Downloads/license_file.lic");
std::cout << "Offline Activation Status: " << errorStatuses(status) << std::endl << std::endl;
std::cout << "Licensee Name: " << pLicenseValidator->getLicenseeName() << std::endl;
std::cout << "Licensee Email: " << pLicenseValidator->getLicenseeEmail() << std::endl;
std::cout << "Version: " << pLicenseValidator->getVersion() << std::endl;
std::cout << "Sku: " << pLicenseValidator->getSku() << std::endl;
std::cout << "License Type: " << pLicenseValidator->getLicenseType() << std::endl;
std::cout << "Start Time: " << pLicenseValidator->getStartTime() << std::endl;
std::cout << "End Time: " << pLicenseValidator->getEndTime() << std::endl;
std::cout << "Info: " << pLicenseValidator->getInfo() << std::endl;
} else {
std::cout << "Licensee Name: " << pLicenseValidator->getLicenseeName() << std::endl;
std::cout << "Licensee Email: " << pLicenseValidator->getLicenseeEmail() << std::endl;
std::cout << "Version: " << pLicenseValidator->getVersion() << std::endl;
std::cout << "Sku: " << pLicenseValidator->getSku() << std::endl;
std::cout << "License Type: " << pLicenseValidator->getLicenseType() << std::endl;
std::cout << "Start Time: " << pLicenseValidator->getStartTime() << std::endl;
std::cout << "End Time: " << pLicenseValidator->getEndTime() << std::endl;
std::cout << "Info: " << pLicenseValidator->getInfo() << std::endl;
}
// This won't deactivate the license in KEYZY servers. Only delete the license file locally.
bool res = pLicenseActivator->deactivateOffline();
if (!res)
status = LicenseStatus::INVALID;
else
status = LicenseStatus::ACTIVATION_DELETED;
std::cout << "Offline Deactivation Status: " << errorStatuses(status) << std::endl << std::endl;
}
// please find errorStatuses() function below of this page

# Full example (Online Activation, Semi-Online Activation, Offline Activation, Trial Due Date Activation)

#include <KeyzyLicenseActivator.h>
#include <KeyzyLicenseValidator.h>
#include <iostream> // for std::cout
using namespace Keyzy;
std::string errorStatuses(LicenseStatus status);
int main()
{
ProductData data;
data._appId = "xxxxxxxx";
data._apiKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
data._productCode = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
data._cryptionKey = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
std::unique_ptr<KeyzyLicenseActivator> pLicenseActivator = std::make_unique<KeyzyLicenseActivator>(data);
std::shared_ptr<KeyzyLicenseValidator> pLicenseValidator = pLicenseActivator->getLicenseValidator();
LicenseStatus status = LicenseStatus::VALID;
// bring serial number input window to the user
std::string serialNumber = "";
// ------
// online
// ------
if (pLicenseValidator->validateOnline() != LicenseStatus::VALID) {
// bring serial number input window to the user
status = pLicenseActivator->activateOnline(serialNumber);
std::cout << std::endl;
std::cout << "Online Activation Status: " << errorStatuses(status) << std::endl << std::endl;
std::cout << "Licensee's Name: " << pLicenseValidator->getLicenseeName() << std::endl;
std::cout << "Licensee's Email: " << pLicenseValidator->getLicenseeEmail() << std::endl;
std::cout << "Version: " << pLicenseValidator->getVersion() << std::endl;
std::cout << "Sku: " << pLicenseValidator->getSku() << std::endl;
std::cout << "License Type: " << pLicenseValidator->getLicenseType() << std::endl;
std::cout << "Start Time: " << pLicenseValidator->getStartTime() << std::endl;
std::cout << "End Time: " << pLicenseValidator->getEndTime() << std::endl;
std::cout << "Info: " << pLicenseValidator->getInfo() << std::endl;
} else {
std::cout << "Licensee's Name: " << pLicenseValidator->getLicenseeName() << std::endl;
std::cout << "Licensee's Email: " << pLicenseValidator->getLicenseeEmail() << std::endl;
std::cout << "Version: " << pLicenseValidator->getVersion() << std::endl;
std::cout << "Sku: " << pLicenseValidator->getSku() << std::endl;
std::cout << "License Type: " << pLicenseValidator->getLicenseType() << std::endl;
std::cout << "Start Time: " << pLicenseValidator->getStartTime() << std::endl;
std::cout << "End Time: " << pLicenseValidator->getEndTime() << std::endl;
std::cout << "Info: " << pLicenseValidator->getInfo() << std::endl;
std::cout << "Online Validation Status: " << errorStatuses(status) << std::endl << std::endl;
}
status = pLicenseActivator->deactivateOnline();
std::cout << "Online Deactivation Status: " << errorStatuses(status) << std::endl << std::endl;
// -----------
// semi-online
// -----------
if (pLicenseValidator->validateOffline() != LicenseStatus::VALID) {
status = pLicenseActivator->activateSemiOnline(serialNumber);
std::cout << "Semi Online Activation Status: " << errorStatuses(status) << std::endl << std::endl;
std::cout << "Version: " << pLicenseValidator->getVersion() << std::endl;
std::cout << "Sku: " << pLicenseValidator->getSku() << std::endl;
std::cout << "License Type: " << pLicenseValidator->getLicenseType() << std::endl;
std::cout << "Start Time: " << pLicenseValidator->getStartTime() << std::endl;
std::cout << "End Time: " << pLicenseValidator->getEndTime() << std::endl;
std::cout << "Info: " << pLicenseValidator->getInfo() << std::endl;
}
if (status == LicenseStatus::VALID) {
// You may need to use semi-online activation without giving a serial number.
// First two cases are:
// 1- You may choose to renew weekly the offline license of the users with Semi Online activation.
// You don't want to ask the serial number again and again.
// 2- You may set Offline License Life (recommended) to 30 days. After 30 days, the offline license
// will be INVALID. Then you will need to activate it again without a serial number.
status = pLicenseActivator->activateSemiOnline();
std::cout << "Semi Online Renew Activation Status: " << errorStatuses(status) << std::endl << std::endl;
std::cout << "Version: " << pLicenseValidator->getVersion() << std::endl;
std::cout << "Licensee's Name: " << pLicenseValidator->getLicenseeName() << std::endl;
std::cout << "Licensee's Email: " << pLicenseValidator->getLicenseeEmail() << std::endl;
std::cout << "Sku: " << pLicenseValidator->getSku() << std::endl;
std::cout << "License Type: " << pLicenseValidator->getLicenseType() << std::endl;
std::cout << "Start Time: " << pLicenseValidator->getStartTime() << std::endl;
std::cout << "End Time: " << pLicenseValidator->getEndTime() << std::endl;
std::cout << "Info: " << pLicenseValidator->getInfo() << std::endl;
}
status = pLicenseActivator->deactivateSemiOnline();
std::cout << "Semi Online Deactivation Status: " << errorStatuses(status) << std::endl << std::endl;
// Now, the license status is not valid. The license is deleted from the device.
// If you try to use semi online activation without a serial number. You’ll have an error.
if (status != LicenseStatus::VALID) {
status = pLicenseActivator->activateSemiOnline();
std::cout << "Semi Online Renew Activation Status 2 (Error expected): " << errorStatuses(status) << std::endl << std::endl;
}
// -------
// offline
// -------
if (pLicenseValidator->validateOffline() != LicenseStatus::VALID) {
status = pLicenseActivator->activateOffline("/Users/user111/Downloads/license_file.lic");
std::cout << "Offline Activation Status: " << errorStatuses(status) << std::endl << std::endl;
std::cout << "Licensee Name: " << pLicenseValidator->getLicenseeName() << std::endl;
std::cout << "Licensee Email: " << pLicenseValidator->getLicenseeEmail() << std::endl;
std::cout << "Version: " << pLicenseValidator->getVersion() << std::endl;
std::cout << "Sku: " << pLicenseValidator->getSku() << std::endl;
std::cout << "License Type: " << pLicenseValidator->getLicenseType() << std::endl;
std::cout << "Start Time: " << pLicenseValidator->getStartTime() << std::endl;
std::cout << "End Time: " << pLicenseValidator->getEndTime() << std::endl;
std::cout << "Info: " << pLicenseValidator->getInfo() << std::endl;
} else {
std::cout << "Licensee Name: " << pLicenseValidator->getLicenseeName() << std::endl;
std::cout << "Licensee Email: " << pLicenseValidator->getLicenseeEmail() << std::endl;
std::cout << "Version: " << pLicenseValidator->getVersion() << std::endl;
std::cout << "Sku: " << pLicenseValidator->getSku() << std::endl;
std::cout << "License Type: " << pLicenseValidator->getLicenseType() << std::endl;
std::cout << "Start Time: " << pLicenseValidator->getStartTime() << std::endl;
std::cout << "End Time: " << pLicenseValidator->getEndTime() << std::endl;
std::cout << "Info: " << pLicenseValidator->getInfo() << std::endl;
}
bool res = pLicenseActivator->deactivateOffline();
if (!res)
status = LicenseStatus::INVALID;
else
status = LicenseStatus::ACTIVATION_DELETED;
std::cout << "Offline Deactivation Status: " << errorStatuses(status) << std::endl << std::endl;
// ------------
// client-trial
// This trial license only stored in the client side
// There is no relationship with KEYZY servers
// ------------
if (pLicenseValidator->validateTrialLicense() != LicenseStatus::VALID) {
std::time_t t = std::time(0); // get time now
std::tm trialExpiryTime = *std::localtime(&t); // get local time
trialExpiryTime.tm_hour += 24 * 30; // add 30 days
mktime(&trialExpiryTime);
status = pLicenseActivator->activateClientTrial(trialExpiryTime);
std::cout << "Client Trial Activation Status: " << errorStatuses(status) << std::endl << std::endl;
}
bool resTrial = pLicenseActivator->deactivateClientTrial();
std::cout << "Client Trial Deactivation Status: " << resTrial << std::endl << std::endl;
}
// please find errorStatuses() function below of this page

# Error function

Find the error function for all examples following.

std::string errorStatuses(LicenseStatus status)
{
switch(status) {
case LicenseStatus::EXPIRED:
return "Expired";
case LicenseStatus::INVALID:
return "Invalid";
case LicenseStatus::NOT_AUTHORIZED:
return "Not authorized";
case LicenseStatus::SERIAL_INVALID:
return "Serial invalid";
case LicenseStatus::PRODUCT_NOT_EXIST:
return "Product does not exist";
case LicenseStatus::PRODUCT_NOT_EXIST_FOR_USER:
return "Product does not exist";
case LicenseStatus::PRODUCT_NOT_ACTIVE:
return "Product is not active";
case LicenseStatus::SKU_NOT_EXIST:
return "SKU does not exist";
case LicenseStatus::SKU_NOT_ACTIVE:
return "SKU is not active";
case LicenseStatus::REACHED_MAX_NUMBER_OF_HOST:
return "Reached maximum number of host";
case LicenseStatus::PRODUCT_NOT_EXIST_FOR_SKU:
return "Product does not exist for this SKU";
case LicenseStatus::ACTIVATION_DEACTIVATED:
return "Activation is deactivated";
case LicenseStatus::SUBSCRIPTION_LICENSE_EXPIRED:
return "Subscription license expired!";
case LicenseStatus::SUBSCRIPTION_LICENSE_NOT_STARTED:
return "Subscription license not started!";
case LicenseStatus::TRIAL_LICENSE_EXPIRED:
return "Trial license expired!";
case LicenseStatus::TRIAL_LICENSE_NOT_STARTED:
return "Trial license not started!";
case LicenseStatus::CANNOT_KEEP_SERIAL:
return "Cannot keep serial!";
case LicenseStatus::CANNOT_KEEP_LICENSE_FILE:
return "Cannot keep license file!";
case LicenseStatus::ACTIVATION_DELETED:
return "Activation deleted!";
case LicenseStatus::CLIENT_SERIAL_DOES_NOT_EXIST:
return "Client serial does not exist!";
case LicenseStatus::CONNECTION_ERROR:
return "Connection Error!";
case LicenseStatus::TOO_MANY_REQUESTS:
return "Too Many Requests!";
case LicenseStatus::NO_ACTIVE_SUBSCRIPTION:
return "No Active Subscription!";
case LicenseStatus::CURRENT_LICENSE_DOES_NOT_EXIST:
return "Current license does not exist!";
case LicenseStatus::UPGRADE_LICENSE_DOES_NOT_EXIST:
return "Upgrade license does not exist!";
case LicenseStatus::UPGRADE_LICENSE_DOES_NOT_MATCH:
return "Upgrade license does not match for upgrade with current license!";
case LicenseStatus::ANOTHER_TRIAL_LICENSE_ALREADY_ACTIVATED:
return "Another trial license has already been activated on this device!";
case LicenseStatus::SKU_NUMBER_VALIDATION:
return "sku_number parameter cannot be validated!";
case LicenseStatus::PRODUCT_CODE_VALIDATION:
return "product_code parameter cannot be validated!";
case LicenseStatus::NAME_VALIDATION:
return "name parameter cannot be validated!";
case LicenseStatus::EMAIL_VALIDATION:
return "email parameter cannot be validated!";
case LicenseStatus::NO_FREE_LICENSES:
return "You do not have any free licenses for this sku. Please generate new licenses for this sku!";
case LicenseStatus::NAME_OR_EMAIL_VALIDATION:
return "Either the name or email filed must be filled!";
case LicenseStatus::LICENSE_NOT_EXIST_NOT_ASSIGNED_DEALER_ALREADY_DEPOSITED:
return "The license does not exist or is not assigned to a dealer or is already deposited!";
case LicenseStatus::VALID: // Just in case
return "Valid";
default:
return "Unknown";
}
}