Skip to content

Commit

Permalink
Merge pull request #18 from cryptlex/borrowing-develop
Browse files Browse the repository at this point in the history
borrowing develop
  • Loading branch information
ahmad-kemsan authored Aug 6, 2024
2 parents 2781d3c + ad913c4 commit 03a7a1b
Show file tree
Hide file tree
Showing 4 changed files with 336 additions and 18 deletions.
160 changes: 150 additions & 10 deletions lexfloatclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,22 @@ void floatingLicenseCallbackCgoGateway(int status);
*/
import "C"
import (
"encoding/json"
"strings"
"unsafe"
)


type HostConfig struct {
MaxOfflineLeaseDuration int `json:"maxOfflineLeaseDuration"`
}


type callbackType func(int)

const (
LA_USER uint = 0
LA_SYSTEM uint = 1
LA_IN_MEMORY uint = 2
LF_USER uint = 10
LF_ALL_USERS uint = 11
)

var floatingLicenseCallbackFunction callbackType
Expand All @@ -32,6 +39,31 @@ func floatingLicenseCallbackWrapper(status int) {
floatingLicenseCallbackFunction(status)
}
}
/*
FUNCTION: SetPermissionFlag()
PURPOSE: Sets the permission flag.
This function must be called on every start of your program after SetHostProductId()
function in case the application allows borrowing of licenses or system wide activation.
PARAMETERS:
* flags - depending on your application's requirements, choose one of
the following values: LF_USER, LF_ALL_USERS.
- LF_USER: This flag indicates that the application does not require
admin or root permissions to run.
- LF_ALL_USERS: This flag is specifically designed for Windows and should be used
for system-wide activations.
RETURN CODES: LF_OK, LF_E_PRODUCT_ID
*/
func SetPermissionFlag(flags uint) int {
cFlags := (C.uint)(flags)
status := C.SetPermissionFlag(cFlags)
return int(status)
}

/*
FUNCTION: SetHostProductId()
Expand All @@ -50,6 +82,7 @@ func SetHostProductId(productId string) int {
freeCString(cProductId)
return int(status)
}

/*
FUNCTION: SetHostUrl()
Expand Down Expand Up @@ -125,14 +158,14 @@ func SetFloatingClientMetadata(key string, value string) int {
PARAMETERS:
* libraryVersion - pointer to a buffer that receives the value of the string
* length - size of the buffer pointed to by the libraryVersion parameter
RETURN CODES: LF_OK, LF_E_BUFFER_SIZE
*/
func GetFloatingClientLibraryVersion(libraryVersion *string) int {
var cLibraryVersion = getCArray()
status := C.GetFloatingClientLibraryVersion(&cLibraryVersion[0], maxCArrayLength)
*libraryVersion = ctoGoString(&cLibraryVersion[0])
return int(status)
var cLibraryVersion = getCArray()
status := C.GetFloatingClientLibraryVersion(&cLibraryVersion[0], maxCArrayLength)
*libraryVersion = ctoGoString(&cLibraryVersion[0])
return int(status)
}

/*
Expand Down Expand Up @@ -193,7 +226,7 @@ func GetHostProductVersionFeatureFlag(name string, enabled *bool, data *string)
*enabled = cEnabled > 0
*data = ctoGoString(&cData[0])
return int(status)
}
}

/*
FUNCTION: GetHostLicenseMetadata()
Expand Down Expand Up @@ -242,6 +275,7 @@ func GetHostLicenseMeterAttribute(name string, allowedUses *uint, totalUses *uin
freeCString(cName)
return int(status)
}

/*
FUNCTION: GetHostLicenseExpiryDate()
Expand All @@ -258,6 +292,7 @@ func GetHostLicenseExpiryDate(expiryDate *uint) int {
*expiryDate = uint(cExpiryDate)
return int(status)
}

/*
FUNCTION: GetFloatingClientMeterAttributeUses()
Expand All @@ -277,6 +312,29 @@ func GetFloatingClientMeterAttributeUses(name string, uses *uint) int {
freeCString(cName)
return int(status)
}

/*
FUNCTION: GetFloatingClientMetadata()
PURPOSE: Gets the value of the floating client metadata.
PARAMETERS:
* key - key of the metadata field whose value you want to retrieve
* value - pointer to a buffer that receives the value of the string
RETURN CODES: LF_OK, LF_E_PRODUCT_ID, LF_E_NO_LICENSE, LF_E_BUFFER_SIZE,
LF_E_METADATA_KEY_NOT_FOUND
*/
func GetFloatingClientMetadata(key string, value *string) int {
cKey := goToCString(key)
var cValue = getCArray()
status := C.GetFloatingClientMetadata(cKey, &cValue[0], maxCArrayLength)
*value = ctoGoString(&cValue[0])
freeCString(cKey)
return int(status)

}

/*
FUNCTION: RequestFloatingLicense()
Expand All @@ -292,6 +350,23 @@ func RequestFloatingLicense() int {
return int(status)
}

/*
FUNCTION: GetFloatingClientLeaseExpiryDate()
PURPOSE: Gets the lease expiry date timestamp of the floating client.
PARAMETERS:
* leaseExpiryDate - pointer to the integer that receives the value
RETURN CODES: LF_OK, LF_E_PRODUCT_ID, LF_E_NO_LICENSE
*/
func GetFloatingClientLeaseExpiryDate(leaseExpiryDate *uint) int {
var cLeaseExpiryDate C.uint
status := C.GetFloatingClientLeaseExpiryDate(&cLeaseExpiryDate)
*leaseExpiryDate = uint(cLeaseExpiryDate)
return int(status)
}

/*
FUNCTION: DropFloatingLicense()
Expand Down Expand Up @@ -322,6 +397,72 @@ func HasFloatingLicense() int {
return int(status)
}

/*
FUNCTION: GetHostConfig()
PURPOSE: Gets the host configuration.
This function sends a network request to LexFloatServer to get the configuration details.
PARAMETERS:
* hostConfig - pointer to a buffer that receives the value of the string
* length - size of the buffer pointed to by the hostConfigPtr parameter
RETURN CODES: LF_OK, LF_E_PRODUCT_ID, LF_E_HOST_URL, LF_E_BUFFER_SIZE
LF_E_INET, LF_E_CLIENT, LF_E_IP, LF_E_SERVER
*/
func GetHostConfig(hostConfig *HostConfig) int {
var cHostConfig = getCArray()
hostConfigJson := ""
status := C.GetHostConfigInternal(&cHostConfig[0], maxCArrayLength)
hostConfigJson = strings.TrimRight(ctoGoString(&cHostConfig[0]), "\x00")
if hostConfigJson != "" {
config := []byte(hostConfigJson)
json.Unmarshal(config, hostConfig)
}
return int(status)
}

/*
FUNCTION: GetFloatinglicenseMode()
PURPOSE: Gets the mode of the floating license (online or offline).
PARAMETERS:
* mode - pointer to a buffer that receives the value of the string
* length - size of the buffer pointed to by the value parameter
RETURN CODES: LF_OK, LF_E_PRODUCT_ID, LF_E_NO_LICENSE, LF_E_BUFFER_SIZE
*/
func GetFloatingLicenseMode(mode *string) int {
var cMode = getCArray()
status := C.GetFloatingLicenseMode(&cMode[0], maxCArrayLength)
*mode= ctoGoString(&cMode[0])
return int(status)
}

/*
FUNCTION: RequestOfflineFloatingLicense()
PURPOSE: Sends the request to lease the license from the LexFloatServer for offline usage.
The maximum value of lease duration is configured in the config.yml of LexFloatServer
PARAMETERS:
* leaseDuration - value of the lease duration.
RETURN CODES: LF_OK, LF_FAIL, LF_E_PRODUCT_ID, LF_E_LICENSE_EXISTS, LF_E_HOST_URL,
LF_E_LICENSE_LIMIT_REACHED, LF_E_INET, LF_E_TIME, LF_E_CLIENT, LF_E_IP, LF_E_SERVER,
LF_E_SERVER_LICENSE_NOT_ACTIVATED, LF_E_SERVER_TIME_MODIFIED, LF_E_SERVER_LICENSE_SUSPENDED,
LF_E_SERVER_LICENSE_GRACE_PERIOD_OVER, LF_E_SERVER_LICENSE_EXPIRED, LF_E_WMIC, LF_E_SYSTEM_PERMISSION
*/
func RequestOfflineFloatingLicense(leaseDuration uint) int {
cLeaseDuration := (C.uint)(leaseDuration)
status := C.RequestOfflineFloatingLicense(cLeaseDuration)
return int(status)
}

/*
FUNCTION: IncrementFloatingClientMeterAttributeUses()
Expand All @@ -335,7 +476,6 @@ func HasFloatingLicense() int {
LF_E_INET, LF_E_LICENSE_NOT_FOUND, LF_E_CLIENT, LF_E_IP, LF_E_SERVER, LF_E_METER_ATTRIBUTE_USES_LIMIT_REACHED,
LF_E_SERVER_LICENSE_NOT_ACTIVATED, LF_E_SERVER_TIME_MODIFIED, LF_E_SERVER_LICENSE_SUSPENDED,
LF_E_SERVER_LICENSE_GRACE_PERIOD_OVER, LF_E_SERVER_LICENSE_EXPIRED
*/
func IncrementFloatingClientMeterAttributeUses(name string, increment uint) int {
cName := goToCString(name)
Expand Down
94 changes: 94 additions & 0 deletions lexfloatclient/LexFloatClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,28 @@
#endif
typedef void (LF_CC *CallbackType)(uint32_t);

/*
FUNCTION: SetPermissionFlag()
PURPOSE: Sets the permission flag.
This function must be called on every start of your program after SetHostProductId()
function in case the application allows borrowing of licenses or system wide activation.
PARAMETERS:
* flags - depending on your application's requirements, choose one of
the following values: LF_USER, LF_ALL_USERS.
- LF_USER: This flag indicates that the application does not require
admin or root permissions to run.
- LF_ALL_USERS: This flag is specifically designed for Windows and should be used
for system-wide activations.
RETURN CODES: LF_OK, LF_E_PRODUCT_ID
*/
LEXFLOATCLIENT_API int LF_CC SetPermissionFlag(uint32_t flags);

/*
FUNCTION: SetHostProductId()
Expand Down Expand Up @@ -124,6 +146,21 @@ LEXFLOATCLIENT_API int LF_CC SetFloatingLicenseCallback(CallbackType callback);
*/
LEXFLOATCLIENT_API int LF_CC SetFloatingClientMetadata(CSTRTYPE key, CSTRTYPE value);

/*
FUNCTION: GetHostConfigInternal()
PURPOSE: Gets the host configuration.
This function sends a network request to LexFloatServer to get the configuration details.
PARAMETERS:
* hostConfig - pointer to a buffer that receives the value of the string
* length - size of the buffer pointed to by the hostConfigPtr parameter
RETURN CODES: LF_OK, LF_E_PRODUCT_ID, LF_E_HOST_URL, LF_E_BUFFER_SIZE
LF_E_INET, LF_E_CLIENT, LF_E_IP, LF_E_SERVER
*/
LEXFLOATCLIENT_API int LF_CC GetHostConfigInternal(STRTYPE hostConfig, uint32_t length);

/*
FUNCTION: GetFloatingClientLibraryVersion()
Expand Down Expand Up @@ -233,6 +270,21 @@ LEXFLOATCLIENT_API int LF_CC GetHostLicenseExpiryDate(uint32_t *expiryDate);
*/
LEXFLOATCLIENT_API int LF_CC GetFloatingClientMeterAttributeUses(CSTRTYPE name, uint32_t *uses);

/*
FUNCTION: GetFloatingClientMetadata()
PURPOSE: Gets the value of the floating client metadata.
PARAMETERS:
* key - key of the metadata field whose value you want to retrieve
* value - pointer to a buffer that receives the value of the string
* length - size of the buffer pointed to by the value parameter
RETURN CODES: LF_OK, LF_E_PRODUCT_ID, LF_E_NO_LICENSE, LF_E_BUFFER_SIZE,
LF_E_METADATA_KEY_NOT_FOUND
*/
LEXFLOATCLIENT_API int LF_CC GetFloatingClientMetadata(CSTRTYPE key, STRTYPE value, uint32_t length);

/*
FUNCTION: RequestFloatingLicense()
Expand Down Expand Up @@ -269,6 +321,48 @@ LEXFLOATCLIENT_API int LF_CC DropFloatingLicense();
*/
LEXFLOATCLIENT_API int LF_CC HasFloatingLicense();

/*
FUNCTION: GetFloatinglicenseMode()
PURPOSE: Gets the mode of the floating license (online or offline).
PARAMETERS:
* modePtr - pointer to a buffer that receives the value of the string
* length - size of the buffer pointed to by the value parameter
RETURN CODES: LF_OK, LF_E_PRODUCT_ID, LF_E_NO_LICENSE, LF_E_BUFFER_SIZE
*/
LEXFLOATCLIENT_API int LF_CC GetFloatingLicenseMode(STRTYPE modePtr, uint32_t length);

/*
FUNCTION: RequestOfflineFloatingLicense()
PURPOSE: Sends the request to lease the license from the LexFloatServer for offline usage.
The maximum value of lease duration is configured in the config.yml of LexFloatServer
PARAMETERS:
* leaseDuration - value of the lease duration.
RETURN CODES: LF_OK, LF_FAIL, LF_E_PRODUCT_ID, LF_E_LICENSE_EXISTS, LF_E_HOST_URL,
LF_E_LICENSE_LIMIT_REACHED, LF_E_INET, LF_E_TIME, LF_E_CLIENT, LF_E_IP, LF_E_SERVER,
LF_E_SERVER_LICENSE_NOT_ACTIVATED, LF_E_SERVER_TIME_MODIFIED, LF_E_SERVER_LICENSE_SUSPENDED,
LF_E_SERVER_LICENSE_GRACE_PERIOD_OVER, LF_E_SERVER_LICENSE_EXPIRED, LF_E_WMIC, LF_E_SYSTEM_PERMISSION
*/
LEXFLOATCLIENT_API int LF_CC RequestOfflineFloatingLicense(uint32_t leaseDuration);

/*
FUNCTION: GetFloatingClientLeaseExpiryDate()
PURPOSE: Gets the lease expiry date timestamp of the floating client.
PARAMETERS:
* leaseExpiryDate - pointer to the integer that receives the value
RETURN CODES: LF_OK, LF_E_PRODUCT_ID, LF_E_NO_LICENSE
*/
LEXFLOATCLIENT_API int LF_CC GetFloatingClientLeaseExpiryDate(uint32_t *leaseExpiryDate);

/*
FUNCTION: IncrementFloatingClientMeterAttributeUses()
Expand Down
Loading

0 comments on commit 03a7a1b

Please sign in to comment.