Zentitle SDK and Library
LICENSE-CODE-BASICS-LIBINFO

Pseudo-code for simplest Nalpeiron Licensing using a license code,
including calls that provide basic info about the library and license.
See C codekit, and here, for actual implementation details.

Pseudo-code docs in this series, illustrating various capabilities:
1) License Code Basics
2) Library Info Calls (this page)
3) Licensing Features
4) Licensing Analytics
5) Account Based Licensing (ABL) Basics

Library calls below are clickable; HOVER over comments or code for important tooltips.

// Library security constants
#define    XAUTH    111
#define    YAUTH    555
#define    ZAUTH    333
#define    CUSTID  4321
#define    PRODID   123 // last 5 digits of full ProductID, excluding any leading zeros
// Location of the licensing library
#define    LIBPATH    "/full/path/to/mylibrary.so"
// Directory where cache, license, log, and info files are stored
#define    WORKDIR    "/my/workdir"
// Logging level
#define    LOGLEVEL   "4"
// License code given to your customer
#define    LICENSECODE  "432100001817930859"
main()
{
    // 'security' is used along with the authentication values stamped into the
    // library to create a unique offset that is added to all returns (except
    // library open and Nalpeiron Analytics calls). Using a random number for
    // 'security' ensures that the offset is different for every run of your
    // software.
    security = 1 + (unsigned int)(500.0 * rand() / (RAND_MAX + 1.0));
    offset = XAUTH + ((security * YAUTH) % ZAUTH);
    // Load library
    libHandle = dlopen(LIBPATH, RTLD_LOCAL | RTLD_LAZY);
    // Open and initialize library
    returnValue = xxxNalpLibOpen(xmlParams, libHandle); // test return value, see code kits
    // Validate the library
    returnValue = xxxNSLValidateLibrary(custID, prodID, libHandle);
    returnValue = returnValue - offset; // test return value, see code kits
    // Check license status (returned in licenseStatus)
    returnValue = xxxNSLGetLicenseStatus(licenseStatus, libHandle);
    returnValue = returnValue - offset; // test return value and licenseStatus, see code kits
    if ((returnValue < 0) || (licenseStatus <= 0)) // need to renew (reset lease) or get a license
    {
        returnValue = xxxNSLObtainLicense(LICENSECODE, licenseStatus, NULL, NULL, libHandle);
        returnValue = returnValue - offset; // test return value and licenseStatus, see code kits
    }
    // If the application has a valid license, app execution may proceed.
    // If the license has a finite lease period (typically hours, or days),
    // the license status will have to be checked periodically. The simplest
    // method is to set a lease period of one day, and just check license 
    // status at app startup as above (assumes app is started/stopped
    // once per day). See License Code Basics for another approach.
    // Other useful library info calls
    // Get info on type and activation method for valid license
    if (licenseStatus > 0)
    {
        returnValue = xxxNSLGetLicenseInfo(licenseType, actType, libHandle);
        returnValue = returnValue - offset; // test return value, see code kits
    }
    // Get local computer ID (returned in char *computerID)
    returnValue = xxxNSLGetComputerID(computerID, libHandle); free computerID with NSLFree
    returnValue = returnValue - offset; // test return value, see code kits
    // Get the complete filename and path of *.log, *.cache, *.sinfo, or *.lic (returned in char *filepath)
    returnValue = xxxNalpGetFilepath(".fileExtension", filepath, libHandle); // free filepath with NSLFree
    // Get virtual machine info (returned in char *vmType)
    returnValue = xxxNSLGetVMInfo(isVM, vmType, libHandle); // free vmType with NSLFree
    returnValue = returnValue - offset; // test return value, see code kits
    // Get the version of the NSL library being accessed (returned in char *version)
    returnValue = xxxNSLGetVersion(version, libHandle); // free version with NSLFree
    returnValue = returnValue - offset; // test return value, see code kits
    // Get server name the library contacts for licensing information (returned in char *hostName)
    returnValue = xxxNSLGetHostName(hostName, libHandle); // free hostName with NSLFree
    returnValue = returnValue - offset; // test return value, see code kits
    // Test connection to the server
    returnValue = xxxNSLTestConnection2(connectionTimeOut, trasnactionTimeOut, libHandle);
    returnValue = returnValue - offset; // test return value, see code kits

    // Return a concurrent (cloud) or network license just before the application exits
    returnValue = xxxNSLReturnLicense(LICENSECODE, licenseStatus, libHandle);
    returnValue = returnValue - offset;
    // Close the library just before the application exits
    returnValue = xxxNalpLibClose(libHandle); // see code kits for additional cleanup
}