Skip to content

Commit 190dfb6

Browse files
authored
Merge branch 'master' into ahmad/unlimited-syntax
2 parents 728e11f + 84ea24e commit 190dfb6

6 files changed

Lines changed: 272 additions & 9 deletions

File tree

.github/workflows/maven-publish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,5 @@ jobs:
5858
server_id: ossrh
5959
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
6060
gpg_passphrase: ${{ secrets.GPG_PASSPHRASE }}
61-
nexus_username: ${{ secrets.OSSRH_USERNAME }}
62-
nexus_password: ${{ secrets.OSSRH_PASSWORD }}
61+
nexus_username: ${{ secrets.MAVEN_USERNAME }}
62+
nexus_password: ${{ secrets.MAVEN_PASSWORD }}

pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@
4343
<artifactId>jna</artifactId>
4444
<version>5.10.0</version>
4545
</dependency>
46+
<dependency>
47+
<groupId>com.fasterxml.jackson.core</groupId>
48+
<artifactId>jackson-databind</artifactId>
49+
<version>2.14.2</version>
50+
</dependency>
4651
</dependencies>
4752

4853
<distributionManagement>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.cryptlex.lexfloatclient;
2+
3+
public class HostConfig {
4+
public String maxOfflineLeaseDuration;
5+
}

src/main/java/com/cryptlex/lexfloatclient/LexFloatClient.java

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import com.sun.jna.ptr.IntByReference;
99
import com.sun.jna.ptr.LongByReference;
1010
import java.math.BigInteger;
11+
import com.fasterxml.jackson.databind.ObjectMapper;
12+
import com.fasterxml.jackson.core.JsonProcessingException;
1113
import java.util.ArrayList;
1214
import java.util.List;
1315

@@ -63,6 +65,28 @@ public static void SetHostUrl(String hostUrl) throws LexFloatClientException {
6365
}
6466
}
6567

68+
/**
69+
* Sets the permission flag. This function must be called on every start of your program
70+
* after SetHostProductId() function in case the application allows borrowing of licenses
71+
* or system wide activation.
72+
*
73+
* @param flag depending on your application's requirements, choose one of
74+
* the following values: LF_USER, LF_ALL_USERS.
75+
* <ul>
76+
* <li> LF_USER: This flag indicates that the application does not require admin or root permissions to run.</li>
77+
* <li> LF_ALL_USERS: This flag is specifically designed for Windows and should be used for system-wide activations.</li>
78+
* </ul>
79+
* @throws LexFloatClientException
80+
*/
81+
public static void SetPermissionFlag(int flag) throws LexFloatClientException {
82+
int status;
83+
status = LexFloatClientNative.SetPermissionFlag(flag)
84+
85+
if (LF_OK != status) {
86+
throw new LexFloatClientException(status);
87+
}
88+
}
89+
6690
/**
6791
* Sets the renew license callback function.<br>
6892
* Whenever the license lease is about to expire, a renew request is sent to
@@ -120,6 +144,24 @@ public static void SetFloatingClientMetadata(String key, String value) throws Le
120144
}
121145
}
122146

147+
/**
148+
* Gets the lease expiry date timestamp of the floating client.
149+
*
150+
* @return Returns the timestamp
151+
* @throws LexFloatClientException
152+
*/
153+
public static int GetFloatingClientLeaseExpiryDate() throws LexFloatClientException {
154+
int status;
155+
IntByReference expiryDate = new IntByReference(0);
156+
status = LexFloatClientNative.GetFloatingClientLeaseExpiryDate(expiryDate);
157+
switch (status) {
158+
case LF_OK:
159+
return expiryDate.getValue();
160+
default:
161+
throw new LexFloatClientException(status);
162+
}
163+
}
164+
123165
/**
124166
* Gets the version of this library.
125167
*
@@ -145,6 +187,53 @@ public static String GetFloatingClientLibraryVersion() throws LexFloatClientExce
145187
throw new LexFloatClientException(status);
146188
}
147189

190+
/**
191+
* Gets the host configuration.
192+
* This function sends a network request to LexFloatServer to get the configuration details.
193+
194+
* @return Returns host configuration.
195+
* @throws LexFloatClientException
196+
* @throws UnsupportedEncodingException
197+
*/
198+
public static HostConfig GetHostConfig() throws LexFloatClientException, UnsupportedEncodingException {
199+
int status;
200+
int bufferSize = 1024;
201+
if (Platform.isWindows()) {
202+
CharBuffer buffer = CharBuffer.allocate(bufferSize);
203+
status = LexFloatClientNative.GetHostConfigInternal(buffer, bufferSize);
204+
if (LF_OK == status) {
205+
String hostConfigJson = buffer.toString().trim();
206+
if (!hostConfigJson.isEmpty()) {
207+
HostConfig hostConfig = null;
208+
ObjectMapper objectMapper = new ObjectMapper();
209+
try {
210+
hostConfig = objectMapper.readValue(hostConfigJson, HostConfig.class);
211+
} catch (JsonProcessingException e) {}
212+
return hostConfig;
213+
} else {
214+
return null;
215+
}
216+
}
217+
} else {
218+
ByteBuffer buffer = ByteBuffer.allocate(bufferSize);
219+
status = LexFloatClientNative.GetHostConfigInternal(buffer, bufferSize);
220+
if (LF_OK == status) {
221+
String hostConfigJson = new String(buffer.array(), "UTF-8").trim();
222+
if (!hostConfigJson.isEmpty()) {
223+
HostConfig hostConfig = null;
224+
ObjectMapper objectMapper = new ObjectMapper();
225+
try {
226+
hostConfig = objectMapper.readValue(hostConfigJson, HostConfig.class);
227+
} catch (JsonProcessingException e) {}
228+
return hostConfig;
229+
} else {
230+
return null;
231+
}
232+
}
233+
}
234+
throw new LexFloatClientException(status);
235+
}
236+
148237
/**
149238
* Gets the product version name.
150239
*
@@ -252,6 +341,32 @@ public static String GetHostLicenseMetadata(String key) throws LexFloatClientExc
252341
}
253342
throw new LexFloatClientException(status);
254343
}
344+
345+
/**
346+
* Get the value of the license metadata field associated with the LexFloatServer license.
347+
*
348+
* @param key key of the metadata field whose value you want to get
349+
* @return Returns the metadata key value
350+
* @throws LexFloatClientException
351+
* @throws UnsupportedEncodingException
352+
*/
353+
public static String GetFloatingClientMetadata(String key) throws LexFloatClientException, UnsupportedEncodingException {
354+
int status;
355+
if (Platform.isWindows()) {
356+
CharBuffer buffer = CharBuffer.allocate(256);
357+
status = LexFloatClientNative.GetFloatingClientMetadata(new WString(key), buffer, 256);
358+
if (LF_OK == status) {
359+
return buffer.toString().trim();
360+
}
361+
} else {
362+
ByteBuffer buffer = ByteBuffer.allocate(256);
363+
status = LexFloatClientNative.GetFloatingClientMetadata(key, buffer, 256);
364+
if (LF_OK == status) {
365+
return new String(buffer.array(), "UTF-8");
366+
}
367+
}
368+
throw new LexFloatClientException(status);
369+
}
255370

256371
/**
257372
* Gets the license meter attribute allowed uses and total uses associated
@@ -301,6 +416,31 @@ public static int GetHostLicenseExpiryDate() throws LexFloatClientException {
301416
}
302417
}
303418

419+
/**
420+
* Gets the mode of the floating license (online or offline).
421+
*
422+
* @return mode - Returns the floating license mode.
423+
* @throws LexFloatClientException
424+
* @throws UnsupportedEncodingException
425+
*/
426+
public static String GetFloatingLicenseMode() throws LexFloatClientException, UnsupportedEncodingException {
427+
int status;
428+
if (Platform.isWindows()) {
429+
CharBuffer buffer = CharBuffer.allocate(256);
430+
status = LexFloatClientNative.GetFloatingLicenseMode(buffer, 256);
431+
if (LF_OK == status) {
432+
return buffer.toString().trim();
433+
}
434+
} else {
435+
ByteBuffer buffer = ByteBuffer.allocate(256);
436+
status = LexFloatClientNative.GetFloatingLicenseMode(buffer, 256);
437+
if (LF_OK == status) {
438+
return new String(buffer.array(), "UTF-8").trim();
439+
}
440+
}
441+
throw new LexFloatClientException(status);
442+
}
443+
304444
/**
305445
* Gets the meter attribute uses consumed by the floating client.
306446
*
@@ -326,6 +466,21 @@ public static int GetFloatingClientMeterAttributeUses(String name) throws LexFlo
326466
throw new LexFloatClientException(status);
327467
}
328468

469+
/**
470+
* Sends the request to lease the license from the LexFloatServer for offline usage.
471+
* The maximum value of lease duration is configured in the config.yml of LexFloatServer.
472+
*
473+
* @param leaseDuration value of the lease duration.
474+
* @throws LexFloatClientException
475+
*/
476+
public static void RequestOfflineFloatingLicense(int leaseDuration) throws LexFloatClientException {
477+
int status;
478+
status = LexFloatClientNative.RequestOfflineFloatingLicense(leaseDuration);
479+
if (LF_OK != status) {
480+
throw new LexFloatClientException(status);
481+
}
482+
}
483+
329484
/**
330485
* Sends the request to lease the license from the LexFloatServer
331486
*
@@ -368,6 +523,8 @@ public static boolean HasFloatingLicense() throws LexFloatClientException {
368523
return true;
369524
case LexFloatClientException.LF_E_NO_LICENSE:
370525
return false;
526+
case LexFloatClientException.LF_FAIL:
527+
return false;
371528
default:
372529
throw new LexFloatClientException(status);
373530
}

src/main/java/com/cryptlex/lexfloatclient/LexFloatClientException.java

Lines changed: 81 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,32 @@ public static String getErrorMessage(int errorCode) {
7575
message = "No product version is linked with the license.";
7676
break;
7777
case LF_E_FEATURE_FLAG_NOT_FOUND:
78-
message = "The product version feature flag does not exist.";
78+
message = "The product version feature flag does not exist.";
7979
break;
8080
case LF_E_IP:
8181
message = "IP address is not allowed.";
8282
break;
83+
case LF_E_SYSTEM_PERMISSION:
84+
message = "Insufficient system permissions.";
85+
break;
86+
case LF_E_INVALID_PERMISSION_FLAG:
87+
message = "Invalid permission flag.";
88+
break;
89+
case LF_E_OFFLINE_FLOATING_LICENSE_NOT_ALLOWED:
90+
message = "Offline floating license is not allowed for per-instance leasing strategy.";
91+
break;
92+
case LF_E_MAX_OFFLINE_LEASE_DURATION_EXCEEDED:
93+
message = "Maximum offline lease duration exceeded.";
94+
break;
95+
case LF_E_ALLOWED_OFFLINE_FLOATING_CLIENTS_LIMIT_REACHED:
96+
message = "Allowed offline floating clients limit reached.";
97+
break;
98+
case LF_E_WMIC:
99+
message = "Fingerprint couldn't be generated because Windows Management Instrumentation (WMI) service has been disabled.";
100+
break;
101+
case LF_E_MACHINE_FINGERPRINT:
102+
message = "Machine fingerprint has changed since activation.";
103+
break;
83104
case LF_E_CLIENT:
84105
message = "Client error.";
85106
break;
@@ -101,13 +122,14 @@ public static String getErrorMessage(int errorCode) {
101122
case LF_E_SERVER_LICENSE_GRACE_PERIOD_OVER:
102123
message = "The grace period for server license is over.";
103124
break;
125+
case LF_E_PROXY_NOT_TRUSTED:
126+
message = "Request blocked due to untrusted proxy.";
127+
break;
104128
default:
105129
message = "Unknown error!";
106-
107130
}
108131
return message;
109132
}
110-
111133
/*
112134
* CODE: LF_OK
113135
*
@@ -245,25 +267,78 @@ public static String getErrorMessage(int errorCode) {
245267

246268
/*
247269
* CODE: LF_E_PRODUCT_VERSION_NOT_LINKED
248-
*
270+
*
249271
* MESSAGE: No product version is linked with the license.
250272
*/
251273
public static final int LF_E_PRODUCT_VERSION_NOT_LINKED = 57;
252274

253275
/*
254276
* CODE: LF_E_FEATURE_FLAG_NOT_FOUND
255-
*
277+
*
256278
* MESSAGE: The product version feature flag does not exist.
257279
*/
258280
public static final int LF_E_FEATURE_FLAG_NOT_FOUND = 58;
259281

282+
/*
283+
* Insufficient system permissions.
284+
*/
285+
public static final int LF_E_SYSTEM_PERMISSION = 59;
286+
260287
/*
261288
* CODE: LF_E_IP
262289
*
263290
* MESSAGE: IP address is not allowed.
264291
*/
265292
public static final int LF_E_IP = 60;
266293

294+
/*
295+
* CODE: LF_E_INVALID_PERMISSION_FLAG
296+
*
297+
* MESSAGE: Invalid permission flag.
298+
*/
299+
public static final int LF_E_INVALID_PERMISSION_FLAG = 61;
300+
301+
/*
302+
* CODE: LF_E_OFFLINE_FLOATING_LICENSE_NOT_ALLOWED
303+
*
304+
* MESSAGE: Offline floating license is not allowed for per-instance leasing strategy.
305+
*/
306+
public static final int LF_E_OFFLINE_FLOATING_LICENSE_NOT_ALLOWED = 62;
307+
308+
/*
309+
* CODE: LF_E_MAX_OFFLINE_LEASE_DURATION_EXCEEDED
310+
*
311+
* MESSAGE: Maximum offline lease duration exceeded.
312+
*/
313+
public static final int LF_E_MAX_OFFLINE_LEASE_DURATION_EXCEEDED = 63;
314+
315+
/*
316+
* CODE: LF_E_ALLOWED_OFFLINE_FLOATING_CLIENTS_LIMIT_REACHED
317+
*
318+
* MESSAGE: Allowed offline floating clients limit reached.
319+
*/
320+
public static final int LF_E_ALLOWED_OFFLINE_FLOATING_CLIENTS_LIMIT_REACHED = 64;
321+
322+
/*
323+
* CODE: LF_E_WMIC
324+
*
325+
* MESSAGE: Fingerprint couldn't be generated because Windows Management Instrumentation (WMI) service has been disabled.
326+
*/
327+
public static final int LF_E_WMIC = 65;
328+
329+
/*
330+
* CODE: LF_E_MACHINE_FINGERPRINT
331+
*
332+
* MESSAGE: Machine fingerprint has changed since activation.
333+
*/
334+
public static final int LF_E_MACHINE_FINGERPRINT = 66;
335+
/*
336+
* CODE: LF_E_PROXY_NOT_TRUSTED
337+
*
338+
* MESSAGE: Request blocked due to untrusted proxy.
339+
*/
340+
public static final int LF_E_PROXY_NOT_TRUSTED = 67;
341+
267342
/*
268343
* CODE: LF_E_CLIENT
269344
*
@@ -313,4 +388,4 @@ public static String getErrorMessage(int errorCode) {
313388
* MESSAGE: The grace period for server license is over.
314389
*/
315390
public static final int LF_E_SERVER_LICENSE_GRACE_PERIOD_OVER = 76;
316-
}
391+
}

0 commit comments

Comments
 (0)