Skip to content

chore: add feature entitlements #4

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
42 changes: 38 additions & 4 deletions examples/LexActivator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module LexActivator
extend FFI::Library
ffi_lib ["LexActivator", "./libLexActivator.so", "#{File.dirname(__FILE__)}/LexActivator.dll"]
ffi_lib ["#{File.dirname(__FILE__)}/libLexActivator.dylib", "./libLexActivator.so", "#{File.dirname(__FILE__)}/LexActivator.dll"]
callback :license_callback, [:uint], :void
callback :release_update_callback, [:uint], :void

Expand Down Expand Up @@ -60,6 +60,12 @@ class UserLicense < FFI::Struct
:metadata, [Metadata, MAX_METADATA_SIZE]
end

class FeatureEntitlement < FFI::Struct
layout :featureName, [:char, BUFFER_SIZE_256],
:featureDisplayName, [:char, BUFFER_SIZE_256],
:value, [:char, BUFFER_SIZE_256]
end

# @method SetProductFile(file_path)
# @param [String] file_path
# @return [Integer]
Expand Down Expand Up @@ -252,6 +258,34 @@ class UserLicense < FFI::Struct
# @scope class
attach_function :GetProductVersionFeatureFlag, :GetProductVersionFeatureFlag, [:string, :pointer, :pointer, :uint], :int

# @method GetLicenseEntitlementSetName(name, length)
# @param [String] name
# @param [Integer] length
# @return [Integer]
# @scope class
attach_function :GetLicenseEntitlementSetName, :GetLicenseEntitlementSetName, [:pointer, :uint], :int

# @method GetLicenseEntitlementSetDisplayName(displayName, length)
# @param [String] displayName
# @param [Integer] length
# @return [Integer]
# @scope class
attach_function :GetLicenseEntitlementSetDisplayName, :GetLicenseEntitlementSetDisplayName, [:pointer, :uint], :int

# @method GetFeatureEntitlements(featureEntitlements, length)
# @param [FFI::Pointer(*FeatureEntitlement)] featureEntitlements - Pointer to an array of FeatureEntitlement structs
# @param [Integer] length - The number of FeatureEntitlement structs in the array
# @return [Integer]
# @scope class
attach_function :GetFeatureEntitlements, :GetFeatureEntitlements, [:pointer, :uint], :int

# @method GetFeatureEntitlement(featureName, featureEntitlement)
# @param [String] featureName - The name of the feature
# @param [FFI::Pointer(*FeatureEntitlement)] featureEntitlement - Pointer to a FeatureEntitlement struct
# @return [Integer]
# @scope class
attach_function :GetFeatureEntitlement, :GetFeatureEntitlement, [:string, :pointer], :int

# @method GetLicenseMetadata(key, value, length)
# @param [String] key
# @param [String] value
Expand Down Expand Up @@ -330,9 +364,9 @@ class UserLicense < FFI::Struct
# @scope class
attach_function :GetLicenseOrganizationAddress, :GetLicenseOrganizationAddress, [:pointer], :int

# @method GetUserLicenses(userLicense, length)
# @param [FFI::Pointer(UserLicense)] userLicense
# @param [Integer] length
# @method GetUserLicenses(userLicenses, length)
# @param [FFI::Pointer(UserLicense)] userLicenses - Pointer to an array of UserLicense structs
# @param [Integer] length - The number of UserLicense structs in the array
# @return [Integer]
# @scope class
attach_function :GetUserLicenses, :GetUserLicenses, [:pointer, :uint], :int
Expand Down
22 changes: 21 additions & 1 deletion examples/LexStatusCodes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,10 @@ module LexStatusCodes
# MESSAGE: Client error.
LA_E_CLIENT = 92

# CODE: LA_E_ACCOUNT_ID
# MESSAGE: Invalid account ID.
LA_E_ACCOUNT_ID = 93

# CODE: LA_E_LOGIN_TEMPORARILY_LOCKED
# MESSAGE: The user account has been temporarily locked for 5 mins due to 5 failed attempts.
LA_E_LOGIN_TEMPORARILY_LOCKED = 100
Expand All @@ -286,5 +290,21 @@ module LexStatusCodes

# CODE: LA_E_FREE_PLAN_ACTIVATION_LIMIT_REACHED
# MESSAGE: The free plan has reached its activation limit.
LA_E_INVALID_PERMISSION_FLAG = 106
LA_E_FREE_PLAN_ACTIVATION_LIMIT_REACHED = 106

# CODE: LA_E_FEATURE_ENTITLEMENTS_INVALID
# MESSAGE: Invalid feature entitlements.
LA_E_FEATURE_ENTITLEMENTS_INVALID = 107

# CODE: LA_E_FEATURE_ENTITLEMENT_NOT_FOUND
# MESSAGE: The feature entitlement does not exist.
LA_E_FEATURE_ENTITLEMENT_NOT_FOUND = 108

# CODE: LA_E_ENTITLEMENT_SET_NOT_LINKED
# MESSAGE: No entitlement set is linked to the license.
LA_E_ENTITLEMENT_SET_NOT_LINKED = 109

# CODE: LA_E_LICENSE_NOT_EFFECTIVE
# MESSAGE: The license cannot be activated before its effective date.
LA_E_LICENSE_NOT_EFFECTIVE = 110
end
16 changes: 11 additions & 5 deletions examples/sample.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
require "./LexActivator"
require "./LexStatusCodes"


# Refer to following link for LexActivator API docs:
# https://github.com/cryptlex/lexactivator-c/blob/master/examples/LexActivator.h

def init()
# status = LexActivator.SetProductFile("ABSOLUTE_PATH_OF_PRODUCT.DAT_FILE")

status = LexActivator.SetProductData(LexActivator::encode_utf16("PASTE_CONTENT_OF_PRODUCT.DAT_FILE"))
if LexStatusCodes::LA_OK != status
puts "Error Code: #{status}"
Expand All @@ -18,7 +19,7 @@ def init()
exit(status)
end

status = LexActivator.SetAppVersion(LexActivator::encode_utf16("PASTE_YOUR_APP_VERION"))
status = LexActivator.SetReleaseVersion(LexActivator::encode_utf16("1.0.0"))
if LexStatusCodes::LA_OK != status
puts "Error Code: #{status}"
exit(status)
Expand All @@ -39,10 +40,11 @@ def activate()
end

status = LexActivator.ActivateLicense()
if LexStatusCodes::LA_OK == status || LexStatusCodes::LA_EXPIRED == status || LexStatusCodes::LA_SUSPENDED == status
if [LexStatusCodes::LA_OK, LexStatusCodes::LA_EXPIRED, LexStatusCodes::LA_SUSPENDED].include?(status)
puts "License activated successfully: #{status}"
else
puts "License activation failed: #{status}"
exit(status)
end
end

Expand All @@ -63,6 +65,7 @@ def activate_trial()
end
end

# License callback (optional)
LicenseCallback = FFI::Function.new(:void, [:uint]) do |status|
puts "License status: #{status}"
end
Expand All @@ -71,8 +74,9 @@ def activate_trial()
puts "Release status: #{status}"
end

# Run it
init()
# activate()
activate() # uncomment this to activate the license
LexActivator.SetLicenseCallback(LicenseCallback)
status = LexActivator.IsLicenseGenuine()
if LexStatusCodes::LA_OK == status
Expand All @@ -88,7 +92,6 @@ def activate_trial()
email = LexActivator::decode_utf16(buffer.read_string(buffer.size).rstrip)
puts "License user email: #{email}"
puts "License is genuinely activated!"

# puts "Checking for software release update..."
# status = LexActivator.CheckForReleaseUpdate("windows", "1.0.0", "stable", SoftwareReleaseUpdateCallback)
# if LexStatusCodes::LA_OK != status
Expand Down Expand Up @@ -118,3 +121,6 @@ def activate_trial()
activate_trial()
end
end

puts "Press Enter to exit..."
gets