Skip to content

Commit

Permalink
Merge pull request #34 from cryptlex/ahmad/unlimited-syntax
Browse files Browse the repository at this point in the history
Implementation of unlimited syntax
  • Loading branch information
ahmad-kemsan authored Aug 2, 2024
2 parents 4f256af + 13b3c25 commit c9ff9f0
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import java.nio.ByteBuffer;
import java.io.UnsupportedEncodingException;
import com.sun.jna.ptr.IntByReference;
import com.sun.jna.ptr.LongByReference;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand All @@ -30,6 +32,11 @@ public class LexActivator {
public static final int LA_RELEASES_ALL = 1;
public static final int LA_RELEASES_ALLOWED = 2;

// Convert long to BigInteger to correctly handle unsigned 64-bit values
private static BigInteger toUnsignedBigInteger(long value) {
return BigInteger.valueOf(value).and(BigInteger.valueOf(0xFFFFFFFFFFFFFFFFL));
}

// Exceptions are not caught.
// static{
// try{
Expand Down Expand Up @@ -360,13 +367,14 @@ public static void SetReleaseChannel(String releaseChannel) throws LexActivatorE
}

/**
* Sets the lease duration for the activation.
* Sets the lease duration for the activation. The activation lease duration
* is honoured when the allow client lease duration property is enabled.
*
* @param leaseDuration
* @param leaseDuration value of the lease duration. A value of -1 indicates unlimited lease duration.
*
* @throws LexActivatorException
*/
public static void SetActivationLeaseDuration(int leaseDuration) throws LexActivatorException {
public static void SetActivationLeaseDuration(long leaseDuration) throws LexActivatorException {
int status;
status = LexActivatorNative.SetActivationLeaseDuration(leaseDuration);
if (LA_OK != status) {
Expand Down Expand Up @@ -547,14 +555,15 @@ public static String GetLicenseMetadata(String key) throws LexActivatorException
*/
public static LicenseMeterAttribute GetLicenseMeterAttribute(String name) throws LexActivatorException, UnsupportedEncodingException {
int status;
IntByReference allowedUses = new IntByReference(0);
IntByReference totalUses = new IntByReference(0);
IntByReference grossUses = new IntByReference(0);

LongByReference allowedUses = new LongByReference(0);
// These references can still hold the uint64_t values populated by the native function
LongByReference totalUses = new LongByReference(0);
LongByReference grossUses = new LongByReference(0);

status = LexActivatorNative.GetLicenseMeterAttribute(name, allowedUses, totalUses, grossUses);
if (LA_OK == status) {
return new LicenseMeterAttribute(name, allowedUses.getValue(), totalUses.getValue(), grossUses.getValue());
return new LicenseMeterAttribute(name, allowedUses.getValue(), toUnsignedBigInteger(totalUses.getValue()),
toUnsignedBigInteger(grossUses.getValue()));
}

throw new LexActivatorException(status);
Expand Down Expand Up @@ -585,9 +594,9 @@ public static String GetLicenseKey() throws LexActivatorException, UnsupportedEn
* @return Returns the allowed activations
* @throws LexActivatorException
*/
public static int GetLicenseAllowedActivations() throws LexActivatorException {
public static long GetLicenseAllowedActivations() throws LexActivatorException {
int status;
IntByReference allowedActivations = new IntByReference(0);
LongByReference allowedActivations = new LongByReference(0);
status = LexActivatorNative.GetLicenseAllowedActivations(allowedActivations);
switch (status) {
case LA_OK:
Expand Down Expand Up @@ -625,9 +634,9 @@ public static int GetLicenseTotalActivations() throws LexActivatorException {
* @return Returns the allowed deactivations
* @throws LexActivatorException
*/
public static int GetLicenseAllowedDeactivations() throws LexActivatorException {
public static long GetLicenseAllowedDeactivations() throws LexActivatorException {
int status;
IntByReference allowedDeactivations = new IntByReference(0);
LongByReference allowedDeactivations = new LongByReference(0);
status = LexActivatorNative.GetLicenseAllowedDeactivations(allowedDeactivations);
switch (status) {
case LA_OK:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.sun.jna.JNIEnv;
import java.nio.ByteBuffer;
import com.sun.jna.ptr.IntByReference;
import com.sun.jna.ptr.LongByReference;
import com.sun.jna.Callback;

public class LexActivatorNative implements Library {
Expand Down Expand Up @@ -62,7 +63,7 @@ public interface ReleaseUpdateCallbackType extends Callback {

public static native int SetReleaseChannel(String releaseChannel);

public static native int SetActivationLeaseDuration(int leaseDuration);
public static native int SetActivationLeaseDuration(long leaseDuration);

public static native int SetOfflineActivationRequestMeterAttributeUses(String name, int uses);

Expand All @@ -82,7 +83,7 @@ public interface ReleaseUpdateCallbackType extends Callback {

public static native int GetLicenseMetadata(String key, ByteBuffer value, int length);

public static native int GetLicenseMeterAttribute(String name, IntByReference allowedUses, IntByReference totalUses, IntByReference grossUses);
public static native int GetLicenseMeterAttribute(String name, LongByReference allowedUses, LongByReference totalUses, LongByReference grossUses);

public static native int GetLicenseKey(ByteBuffer licenseKey, int length);

Expand All @@ -96,11 +97,11 @@ public interface ReleaseUpdateCallbackType extends Callback {

public static native int GetLicenseMaxAllowedReleaseVersion(ByteBuffer maxAllowedReleaseVersion, int length);

public static native int GetLicenseAllowedActivations(IntByReference allowedActivations);
public static native int GetLicenseAllowedActivations(LongByReference allowedActivations);

public static native int GetLicenseTotalActivations(IntByReference totalActivations);

public static native int GetLicenseAllowedDeactivations(IntByReference allowedDeactivations);
public static native int GetLicenseAllowedDeactivations(LongByReference allowedDeactivations);

public static native int GetLicenseTotalDeactivations(IntByReference totalDeactivations);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
package com.cryptlex.android.lexactivator;
import java.math.BigInteger;

public class LicenseMeterAttribute {

/**
* The name of the meter attribute.
*/
public String name;

public int allowedUses;
/**
* The allowed uses of the meter attribute. A value of -1 indicates unlimited allowed uses.
*/
public long allowedUses;

public int totalUses;
/**
* The total uses of the meter attribute.
*/
public BigInteger totalUses;

public int grossUses;
/**
* The gross uses of the meter attribute.
*/
public BigInteger grossUses;

public LicenseMeterAttribute(String name, int allowedUses, int totalUses, int grossUses) {
public LicenseMeterAttribute(String name, long allowedUses, BigInteger totalUses, BigInteger grossUses) {
this.name = name;
this.allowedUses = allowedUses;
this.totalUses = totalUses;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,23 @@

public class UserLicense {

public int allowedActivations;
/**
* The allowed activations of the license. A value of -1 indicates unlimited number of activations.
*/
public long allowedActivations;

public int allowedDeactivations;
/**
* The allowed deactivations of the license. A value of -1 indicates unlimited number of deactivations.
*/
public long allowedDeactivations;

/**
* The license key.
*/
public String key;

/**
* The license type (node-locked or hosted-floating).
*/
public String type;
}

0 comments on commit c9ff9f0

Please sign in to comment.