Zentitle SDK and Library
LICENSE-CODE-BASICS

Pseudo-code for simplest Nalpeiron Licensing using a license code.
See C codekit, and here, for actual implementation details.

Pseudo-code docs in this series, illustrating various capabilities:
1) License Code Basics (this page)
2) Library Info Calls
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. There are
    // several creative ways to do this; the simple method outlined here
    // can be used in addition to NSLGetLicenseStatus above. It just
    // checks the time until license lease expiration, and renews the lease
    // if expired. Place at appropriatelocations in your app, or use with
    // a timer. 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).
    returnValue = xxxNSLGetLeaseExpSec(secExp, secEpoch, libHandle); // secExp - seconds until lease expirtation
    returnValue = returnValue - offset; // test return value, see code kits
    if ((returnValue == 0) && (secExp == 0)) // lease has expired
    {
        // check first for a license code in the license file
        returnValue = xxxNSLGetLicenseCode(lc, libHandle); // license code returned in lc
        returnValue = returnValue - offset; // test return value, see code kits
        if ((returnValue == 0) && (lc != NULL)) // license code available
        {
            returnValue = xxxNSLObtainLicense(lc, licenseStatus, NULL, NULL, libHandle);
            returnValue = returnValue - offset; // test return value and licenseStatus, see code kits
        }
        else // prompt user for license code, then call NSLObtainLicense
    }

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