Implementing CustomEx Locking
Declare Variables/Constants
The implementation of callback function of type sntl_licensing_callback is defined below:
long callback_impl_custom(char* pcInput, char *pcOutput, unsigned int *piSizeOutput)
{
if (pcOutput == NULL)
{
// Means licensing library is asking for the size of memory
buffer to be allocated.
if (piSizeOutput)
{
*piSizeOutput = strlen(CALLBACK_OUTPUT_XML);
//Output XML described above
}
else
{
return 1; // return error
}
}
else
{
// Non-NULL means licensing library has allocated the required
buffer space and asking for the actual data to be copied
into this buffer.
// Means licensing library is asking for the size of memory
buffer to be allocated.
if (piSizeOutput)
{
strncpy(pcOutput,SAMPLE_CALLBACK_OUTPUT_XML, *piSizeOutput);}
else
{
return 1; // return error
}
}
return (0); // return 0 to indicate success
}
Where the SAMPLE_CALLBACK_OUTPUT_XML is defined as below:
static char * SAMPLE_CALLBACK_OUTPUT_XML = "
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<callbackOutputData>
<customFingerprint>
<item>
<rawValue>111222333444555666777888999aaab</rawValue>
</item>
<item>
<rawValue>abcdef0123456789abcdef012345678</rawValue>
</item>
</customFingerprint>
</callbackOutputData>";
This output response should follow the below XML format:
<?xml version="1.0" encoding="utf-8"?>
<callbackOutputData>
<customFingerprint>
<item>
<rawValue></rawValue>
</item>
<item>
<rawValue></rawValue>
</item>
</customFingerprint>
</callbackOutputData>
API Calls
To register the custom locking callback in your application, execute the APIs in the specified sequential order only:
sntl_licensing_register_callback(NULL, SNTL_CALLBACK_TYPE_CUSTOM_FINGERPRINT, callback_impl_custom);
>If the sntl_licensing_register_callback() call is successful, the registered callback is invoked by the licensing library whenever locking-related information is sought by the licensing library.
Notes
>The sntl_licensing_register_callback() API has global scope and its effect is valid for all the application contexts once set. This API should be called before creating any application context. If this API is called after performing any licensing-related operations, then the licensing library is re-initialized meaning that all application contexts created before become invalid and also all earlier licenses are reloaded if library is in standalone mode.
>The registered callback is invoked twice by the licensing library for every atomic operation:
•First invocation is to ask the callback about the buffer size (in bytes) that is needed to hold the response output buffer.
•In the second invocation it expects the callback to write the output contents into the allocated buffer passed as the second argument.
>For illustration purpose, static contents for variable SAMPLE_CALLBACK_OUTPUT_XML are used here. In real world applications, this output could be built dynamically depending upon vendor’s requirements.