Zentitle SDK and Library
ABL-BASICS

Pseudo-code for simplest Nalpeiron Licensing using Account Based Licensing (ABL).
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
3) Licensing Features
4) Licensing Analytics
5) Account Based Licensing (ABL) Basics (this page)

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"
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
    // Set userName and passWord used by the opened library for ABL logins
    returnValue = xxxNSLSetCredentials(userName, passWord, NULL, 0, NULL, 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 (licenseStatus == -70) // verify credentials set with NSLSetCredentials against those in the license file
    {
        returnValue = xxxNSLCheckCredentials(libHandle);
        returnValue = returnValue - offset; // test return value, see code kits
        if (returnValue < 0)
        {
            returnValue = xxxNSLReturnLicense(userName, licenseStatus, libHandle);
            returnValue = returnValue - offset; // test return value and licenseStatus, see code kits
        }
        else
        {
            // Check license status (returned in licenseStatus)
            returnValue = xxxNSLGetLicenseStatus(licenseStatus, libHandle);
            returnValue = returnValue - offset; // test return value and licenseStatus, see code kits
        }
    }
    // get ABL license
    if ((returnValue < 0) || (licenseStatus <= 0)) // need to renew (reset lease) or get a license
    {
        returnValue = xxxNSLObtainLicense(userName, 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 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.

    // Return the curent license (avoids -70 error on restart, and makes ABL license available to another)
    returnValue = xxxNSLReturnLicense(userName, licenseStatus, libHandle);
    returnValue = returnValue - offset; // test return value and licenseStatus, see code kits
    // Close the library just before the application exits
    returnValue = xxxNalpLibClose(libHandle); // see code kits for additional cleanup
}