Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add user metadata #19

Merged
merged 8 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
14 changes: 9 additions & 5 deletions src/extern_functions.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::ffi::{c_char, c_int, c_uint};
//https://doc.rust-lang.org/std/os/raw/index.html#types
use std::ffi::{c_char, c_int, c_uint, c_longlong, c_ulonglong};

Check warning on line 2 in src/extern_functions.rs

View workflow job for this annotation

GitHub Actions / test (windows-latest)

unused import: `c_char`

use crate::LexActivatorCode;

Check warning on line 4 in src/extern_functions.rs

View workflow job for this annotation

GitHub Actions / test (macos-latest)

unused import: `crate::LexActivatorCode`

Check warning on line 4 in src/extern_functions.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

unused import: `crate::LexActivatorCode`

Check warning on line 4 in src/extern_functions.rs

View workflow job for this annotation

GitHub Actions / test (windows-latest)

unused import: `crate::LexActivatorCode`

#[cfg(windows)]
macro_rules! cstrtype {
Expand Down Expand Up @@ -35,16 +36,19 @@
extern "C" {
// --------------- Setter Functions ---------------
pub fn SetProductData(productData: cstrtype!()) -> c_int;
pub fn SetProductFile(filePath: cstrtype!()) -> c_int;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@muneebkq Remove this function, as we have deprecated SetProductFile(), so we will not include it in our rust wrapper.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

pub fn SetProductId(productId: cstrtype!() , flags: c_uint) -> c_int;
pub fn SetDataDirectory(dataDir: cstrtype!()) -> c_int;
pub fn SetDebugMode(enable: c_uint) -> c_uint;
pub fn SetCacheMode(mode: c_uint) -> c_uint;
pub fn SetCustomDeviceFingerprint(deviceFingerprint: cstrtype!()) -> c_int;
pub fn SetLicenseKey(licenseKey: cstrtype!()) -> c_int;
pub fn SetLicenseUserCredential(email: cstrtype!(), password: cstrtype!()) -> c_int;
pub fn SetLicenseCallback(callback: CallbackType) ->c_int;
pub fn SetActivationLeaseDuration(leaseDuration: c_uint) -> c_int;
pub fn SetActivationLeaseDuration(leaseDuration: c_longlong) -> c_int;
pub fn SetActivationMetadata(key: cstrtype!(), value: cstrtype!()) -> c_int;
pub fn SetTrialActivationMetadata(key: cstrtype!(), value: cstrtype!()) -> c_int;
pub fn SetAppVersion(appVersion: cstrtype!()) -> c_int;
pub fn SetReleaseVersion(releaseVersion: cstrtype!()) -> c_int;
pub fn SetReleasePublishedDate(releasePublishedDate: c_uint) -> c_int;
pub fn SetReleasePlatform(platform: cstrtype!()) -> c_int;
Expand All @@ -62,8 +66,8 @@
pub fn GetProductVersionFeatureFlag(name: cstrtype!(), enabled: *mut c_uint, data: strtype!(), length: c_uint) -> c_int;
pub fn GetLicenseMetadata(key: cstrtype!(), value: strtype!(), length: c_uint) -> c_int;
pub fn GetLicenseKey(licenseKey: strtype!(), length: c_uint) -> c_int;
pub fn GetLicenseAllowedActivations(allowedActivations: *mut c_uint) -> c_int;
pub fn GetLicenseAllowedDeactivations(allowedDeactivations: *mut c_uint) -> c_int;
pub fn GetLicenseAllowedActivations(allowedActivations: *mut c_longlong) -> c_int;
pub fn GetLicenseAllowedDeactivations(allowedDeactivations: *mut c_longlong) -> c_int;
pub fn GetLicenseTotalActivations(totalActivations: *mut c_uint) -> c_int;
pub fn GetLicenseTotalDeactivations(totalDeactivations: *mut c_uint) -> c_int;
pub fn GetLicenseCreationDate(creationDate: *mut c_uint) -> c_int;
Expand All @@ -89,7 +93,7 @@
pub fn GetTrialId(trialId: strtype!(), length: c_uint) -> c_int;
pub fn GetLocalTrialExpiryDate(localTrialExpiryDate: *mut c_uint) -> c_int;
pub fn GetLibraryVersion(libraryVersion: strtype!(), length: c_uint) -> c_int;
pub fn GetLicenseMeterAttribute(name: cstrtype!(), allowedUses: *mut c_uint, totalUses: *mut c_uint, expiryDate: *mut c_uint) -> c_int;
pub fn GetLicenseMeterAttribute(name: cstrtype!(), allowedUses: *mut c_longlong, totalUses: *mut c_ulonglong, grossUses: *mut c_ulonglong) -> c_int;

// --------------- LexActivator Action Functions ---------------

Expand Down
138 changes: 118 additions & 20 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
/// The name of the meter attribute.
pub name: String,
/// The number of allowed uses for the meter attribute.
pub allowed_uses: u32,
pub allowed_uses: i64,
/// The total number of uses recorded for the meter attribute.
pub total_uses: u32,
pub total_uses: u64,
/// The gross number of uses for the meter attribute.
pub gross_uses: u32
pub gross_uses: u64
}

/// Represents a product version feature flag.
Expand All @@ -45,6 +45,15 @@
pub current_mode: String
}

/// Represents a metadata
#[derive(Debug, Deserialize, Default)]
pub struct Metadata {
/// The key of the metadata.
pub key: String,
/// The value of the metadata.
pub value: String,
}

/// Represents an organization address.
#[derive(Debug, Deserialize, Default)]
pub struct OrganizationAddress {
Expand All @@ -70,15 +79,17 @@
pub struct UserLicense {
/// The allowed activations count of a license.
#[serde(rename = "allowedActivations")]
pub allowed_activations: u32,
pub allowed_activations: i64,
/// The allowed deactivations count of a license.
#[serde(rename = "allowedDeactivations")]
pub allowed_deactivations: u32,
pub allowed_deactivations: i64,
/// The license key.
pub key: String,
/// The license type.
#[serde(rename = "type")]
pub license_type: String
pub license_type: String,
/// Optional metadata associated with the license.
pub metadata: Vec<Metadata>
}

/// Represents various permission flags.
Expand All @@ -96,7 +107,41 @@
}

// --------------- Setter functions ------------------------

Check warning on line 110 in src/lib.rs

View workflow job for this annotation

GitHub Actions / test (macos-latest)

variant `LA_USER` should have an upper camel case name

Check warning on line 110 in src/lib.rs

View workflow job for this annotation

GitHub Actions / test (macos-latest)

variant `LA_USER` should have an upper camel case name

Check warning on line 110 in src/lib.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

variant `LA_USER` should have an upper camel case name

Check warning on line 110 in src/lib.rs

View workflow job for this annotation

GitHub Actions / test (windows-latest)

variant `LA_USER` should have an upper camel case name
/// Sets the absolute path of the Product.dat file.
///

Check warning on line 112 in src/lib.rs

View workflow job for this annotation

GitHub Actions / test (macos-latest)

variant `LA_SYSTEM` should have an upper camel case name

Check warning on line 112 in src/lib.rs

View workflow job for this annotation

GitHub Actions / test (macos-latest)

variant `LA_SYSTEM` should have an upper camel case name

Check warning on line 112 in src/lib.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

variant `LA_SYSTEM` should have an upper camel case name

Check warning on line 112 in src/lib.rs

View workflow job for this annotation

GitHub Actions / test (windows-latest)

variant `LA_SYSTEM` should have an upper camel case name
/// This function must be called on every start of your program before any other functions are called.
///

Check warning on line 114 in src/lib.rs

View workflow job for this annotation

GitHub Actions / test (macos-latest)

variant `LA_ALL_USERS` should have an upper camel case name

Check warning on line 114 in src/lib.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

variant `LA_ALL_USERS` should have an upper camel case name

Check warning on line 114 in src/lib.rs

View workflow job for this annotation

GitHub Actions / test (windows-latest)

variant `LA_ALL_USERS` should have an upper camel case name
///
/// # Arguments
///

Check warning on line 117 in src/lib.rs

View workflow job for this annotation

GitHub Actions / test (macos-latest)

variant `LA_IN_MEMORY` should have an upper camel case name

Check warning on line 117 in src/lib.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

variant `LA_IN_MEMORY` should have an upper camel case name

Check warning on line 117 in src/lib.rs

View workflow job for this annotation

GitHub Actions / test (windows-latest)

variant `LA_IN_MEMORY` should have an upper camel case name
/// * `file_path` - absolute path of the product file (Product.dat).
///
/// # Returns
///
/// Returns `Ok(())` if the product path is set successfully, If an error occurs, an `Err` containing the `LexActivatorError`is returned.


pub fn set_product_file(file_path: String) -> Result<(), LexActivatorError> {

let status: i32;
#[cfg(windows)]
{
let file_path = to_utf16(file_path);
status = unsafe { SetProductFile(file_path.as_ptr()) };
}
#[cfg(not(windows))]
{
let file_path = string_to_cstring(file_path)?;
status = unsafe { SetProductFile(file_path.as_ptr()) };
}
if status == 0 {
Ok(())
} else {
return Err(LexActivatorError::from(status));
}
}

/// Embeds the Product.dat file in the application.
///
/// This function must be called on every start of your program before any other functions are called.
Expand All @@ -113,7 +158,7 @@


pub fn set_product_data(product_data: String) -> Result<(), LexActivatorError> {

let status: i32;
#[cfg(windows)]
{
Expand Down Expand Up @@ -229,6 +274,28 @@
let c_enable: c_uint = enable as c_uint;
unsafe { SetDebugMode(c_enable) };
}

/// Enables or disables in-memory caching for LexActivator.
///
/// This function is designed to control caching behavior to suit specific application requirements.
///
/// Caching is enabled by default to enhance performance.
///
/// Disabling caching is recommended in environments where multiple processes access the same license on a
///
/// single machine and require real-time updates to the license state.
///
/// # Arguments
///
/// * `mode` - False or True to disable or enable caching.
///
/// Returns `Ok(())` if mode is set successfully.

pub fn set_cache_mode(mode: bool) -> c_uint {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@muneebkq Please follow the Result return pattern for set_cache_mode().

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jsdoc?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

result pattern followed

let c_mode: c_uint = if mode { 1 } else { 0 };
unsafe { SetCacheMode(c_mode) }
}


/// In case you don't want to use the LexActivator's advanced device fingerprinting algorithm, this function can be used to set a custom device fingerprint.
///
Expand Down Expand Up @@ -353,14 +420,14 @@
///
/// # Arguments
///
/// * `lease_duration` - The lease duration in seconds.
/// * `lease_duration` - The lease duration in seconds. A value of -1 indicates unlimited lease duration.
///
/// # Returns
///
/// Returns `Ok(())` if the activation lease duration is set successfully, If an error occurs, an `Err` containing the `LexActivatorError`is returned.

pub fn set_activation_lease_duration(lease_duration: u32) -> Result<(), LexActivatorError> {
let c_lease_duration: c_uint = lease_duration as c_uint;
pub fn set_activation_lease_duration(lease_duration: i64) -> Result<(), LexActivatorError> {
let c_lease_duration: c_longlong = lease_duration as c_longlong;
let status = unsafe { SetActivationLeaseDuration(c_lease_duration) };
if status == 0 {
Ok(())
Expand Down Expand Up @@ -433,6 +500,37 @@
}
}

/// Sets the current app version of your application.
/// The app version appears along with the activation details in dashboard.
/// It is also used to generate app analytics.

/// # Arguments
///
/// * `app_version` - string of maximum length 256 characters.
///
/// # Returns
///
/// Returns `Ok(())` if the release version is set successfully, If an error occurs, an `Err` containing the `LexActivatorError`is returned.

pub fn set_app_version(app_version: String) -> Result<(), LexActivatorError> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@muneebkq There is no need for adding set_app_version(). This function has been deprecated as we already have the set_release_version().

let status: i32;
#[cfg(windows)]
{
let c_app_version = to_utf16(app_version);
status = unsafe { SetAppVersion(c_app_version.as_ptr()) };
}
#[cfg(not(windows))]
{
let c_app_version = string_to_cstring(app_version)?;
status = unsafe { SetAppVersion(c_app_version.as_ptr()) };
}
if status == 0 {
Ok(())
} else {
return Err(LexActivatorError::from(status));
}
}

/// Sets the release version.
///
/// # Arguments
Expand Down Expand Up @@ -834,9 +932,9 @@
pub fn get_license_meterattribute(name: String) -> Result<LicenseMeterAttribute, LexActivatorError> {
let status: i32;
let meter_attribute_name: String = name.clone();
let mut c_allowed_uses: c_uint = 0;
let mut c_total_uses: c_uint = 0;
let mut c_gross_uses: c_uint = 0;
let mut c_allowed_uses: c_longlong = 0;
let mut c_total_uses: c_ulonglong = 0;
let mut c_gross_uses: c_ulonglong = 0;
#[cfg(windows)]
{
let c_name = to_utf16(name);
Expand Down Expand Up @@ -893,10 +991,10 @@
///
/// # Returns
///
/// Returns `Ok(u32)` with the number of allowed activations if it is retrieved successfully, If an error occurs, an `Err` containing the `LexActivatorError`is returned.
/// Returns `Ok(i64)` with the number of allowed activations if it is retrieved successfully, If an error occurs, an `Err` containing the `LexActivatorError`is returned.

pub fn get_license_allowed_activations() -> Result<u32, LexActivatorError> {
let mut allowed_activations: c_uint = 0;
pub fn get_license_allowed_activations() -> Result<i64, LexActivatorError> {
let mut allowed_activations: c_longlong = 0;
let status = unsafe { GetLicenseAllowedActivations(&mut allowed_activations) };
if status == 0 {
Ok(allowed_activations)
Expand Down Expand Up @@ -925,10 +1023,10 @@
///
/// # Returns
///
/// Returns `Ok(u32)` with the number of allowed deactivations if it is retrieved successfully, If an error occurs, an `Err` containing the `LexActivatorError`is returned.
/// Returns `Ok(i64)` with the number of allowed deactivations if it is retrieved successfully, If an error occurs, an `Err` containing the `LexActivatorError`is returned.

pub fn get_license_allowed_deactivations() -> Result<u32, LexActivatorError> {
let mut allowed_deactivations: c_uint = 0;
pub fn get_license_allowed_deactivations() -> Result<i64, LexActivatorError> {
let mut allowed_deactivations: c_longlong = 0;
let status = unsafe { GetLicenseAllowedDeactivations(&mut allowed_deactivations) };
if status == 0 {
Ok(allowed_deactivations)
Expand Down Expand Up @@ -1243,7 +1341,7 @@

pub fn get_user_licenses() -> Result<Vec<UserLicense>, LexActivatorError> {
let status: i32;
const LENGTH: usize = 256;
const LENGTH: usize = 1024;
let user_licenses_json: String;
#[cfg(windows)]
{
Expand Down
Loading