License Definition Example

A license definition template can be large and complex, making it difficult to create and maintain. License Generation API contains functions that enable you to work with smaller component templates and to combine these component templates in order to generate a license.

For example: You can define a Product in an initial license definition template, using sntl_lg_start() or sntl_lg_apply_template(). Next, using the same handle, you can use sntl_lg_apply_template() to apply subsequent templates to add Features, Feature attributes, other Products, or protection key memory to the license state.

This topic demonstrates how you can generate a license by:

>applying a single license definition template that provides all the required license information.

OR

>applying multiple component license definition templates that combine to provide all the required license information.

The two methods demonstrated in this topic examples will generate the same license.

Contents of This Example

This topic contains sample license definition templates for two Products:

>Product 1 is ImageFilterSDK, with three Features for different type of filters (Blur Filter, Motion Blur Filter, and Find Edges Filter).

>Product 2 is Image Plug-in with one Feature - Text Finder Plug in.

The sample license definitions includes application data to be included in the read-only, read/write, and dynamic memory areas of the key.

The listings that follow demonstrate the following:

>How to generate a license by applying a single license definition template

Listing 1 shows a single license generation template that contains the license terms for all Features in the two Products.

Sequence 2 demonstrates how to apply the template from Listing 1 in a single operation, using only the sntl_lg_start() function.

Sequence 3 demonstrates how to apply the template from Listing 1 in a single operation, using the sntl_lg_apply_template() function.

>How to generate a license by applying multiple component license definition templates

Listings 4 through 11 show the license definition template from Listing 1, divided into separate component license definition templates:

Listing 4 defines the ImageFilterSDK Product.

Listing 5 adds the Blur Filter Feature to the Product.

Listing 6 adds the Motion Blur Feature to the Product.

Listing 7 adds the Find Edges Filter Feature (with an expiration date) to the Product.

Listing 8 adds concurrency and remote desktop access to the Find Edges Filter Feature.

Listing 9 adds the Image Plug-ins Product with Features to the license definition.

Listing 10 adds data to the read-only and read/write memory in the license definition.

Listing 11 adds dynamic memory to the license.

Sequence 12 demonstrates how to apply the component license definition templates in these listings by using multiple calls to the sntl_lg_apply_template() function.

Applying the Complete License Definition Template in a Single Function Call

You can introduce the complete license definition template (in Listing 1) in a single function call. Listing 2 and Listing 3 demonstrate different methods to perform this operation.

Listing 1. Single license definition template that contains the license terms for all Features in the two Products

 <?xml version="1.0" encoding="utf-8"?>
 <sentinel_ldk:license schema_version="1.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:sentinel_ldk="http://www.safenet-inc.com/sentinelldk">
   <enforcement_type>HL</enforcement_type>
   <product>
      <id>100</id>
      <name>ImageFilterSDK</name>
      <feature>
         <id>1</id>
         <name>Blur Filter</name>
         <license_properties>
            <perpetual/>
            <concurrency>
               <count>Unlimited</count>
               <network_access>Yes</network_access>
            </concurrency>
            <remote_desktop_access>Yes</remote_desktop_access>
         </license_properties>
      </feature>
      <feature>
         <id>2</id>
         <name>Motion Blur Filter</name>
         <license_properties>
            <execution_count>99</execution_count>
            <concurrency>
               <count>10</count>
               <count_criteria>Per Process</count_criteria>
               <network_access>No</network_access>
            </concurrency>
            <remote_desktop_access>No</remote_desktop_access>
         </license_properties>
      </feature>
      <feature>
         <id>3</id>
         <name>Find Edges Filter</name>
         <license_properties>
            <expiration_date>2023-03-31</expiration_date>
            <concurrency>
               <count>50</count>
               <count_criteria>Per Login</count_criteria>
               <network_access>No</network_access>
            </concurrency>
            <remote_desktop_access>Yes</remote_desktop_access>
         </license_properties>
      </feature>
   </product>
   <product>
      <id>200</id>
      <name>Image Plug-ins</name>
      <feature>
         <id>11</id>
         <name>Text Finder Plug in</name>
         <license_properties>
            <days_to_expiration>90</days_to_expiration>
            <concurrency>
               <count>12</count>
               <network_access>Yes</network_access>
            </concurrency>
            <remote_desktop_access>Yes</remote_desktop_access>
         </license_properties>
      </feature>
   </product>
   <memory>
      <ro_memory_segment>
         <offset>10</offset>
         <content>QVBQTEU=</content>
      </ro_memory_segment>
      <rw_memory_segment>
         <offset>10</offset>
         <content>QkFOQU5B</content>
      </rw_memory_segment>
   </memory>
   <dynamic_resource>    <isv_memory attribute="ro">     <file_id>1</file_id> <size>200</size> <segment>     <offset>0</offset> <content>cmVhZCBvbmx5IGR5bmFtaWMgcmVjb3VyY2U=</content> </segment>    </isv_memory>    </dynamic_resource> </sentinel_ldk:license>  

Sequence 2. Apply the complete template in a single call to the sntl_lg_start() function

 sntl_lg_handle_t handle;
 sntl_lg_status_t status;
 sntl_lg_vendor_code_t vendor_code; // put the Vendor Code
 char *current_state; // put the current state of the key.
 char *license_definition; // put the above sample template in this variable
 char *license = NULL;
 char *updated_state = NULL;
 status = sntl_lg_initialize(NULL, &handle);
 if (status)
 {
   // some error occurred.
 }
 // *** Do not forget to initialize the 'current_state' variable with the key's current state
 // *** Do not forget to initialize the 'vendor_code' variable with the assigned Vendor Code
 status = sntl_lg_start(handle, NULL, vendor_code, SNTL_LG_LICENSE_TYPE_UPDATE, license_definition, current_state);
 if (status)
 {
   // some error occurred.
 }
 status = sntl_lg_generate_license(handle, NULL, &license, &updated_state);
 if (status)
 {
   // some error occurred.
 }
 sntl_lg_free_memory(license);
 sntl_lg_free_memory(updated_state);
 sntl_lg_cleanup(&handle);
 

Sequence 3. Apply the complete template in a single call to the sntl_lg_apply_template() function

Note that sntl_lg_start() is first called to set the license state.

 sntl_lg_handle_t handle;
 sntl_lg_status_t status;
 sntl_lg_vendor_code_t vendor_code; // put the Vendor Code
 char *current_state; // put the current state of the key.
 char *license_definition; // put the above sample template in this variable
 char *license = NULL;
 char *updated_state = NULL;
 status = sntl_lg_initialize(NULL, &handle);
 if (status)
 {
   // some error occurred.
 }
 // *** Do not forget to initialize the 'current_state' variable with the key's current state
 // *** Do not forget to initialize the 'vendor_code' variable with the assigned Vendor Code
 status = sntl_lg_start(handle, NULL, vendor_code, SNTL_LG_LICENSE_TYPE_UPDATE, NULL, current_state);
 if (status)
 {
   // some error occurred.
 }
 status = sntl_lg_apply_template(handle, license_definition);
 if (status)
 {
   // some error occurred.
 }
 status = sntl_lg_generate_license(handle, NULL, &license, &updated_state);
 if (status)
 {
   // some error occurred.
 }
 sntl_lg_free_memory(license);
 sntl_lg_free_memory(updated_state);
 sntl_lg_cleanup(&handle);
 

Applying Component License Definition Templates in Multiple Function Calls

You can split a large license definition template (Listing 1) into several component templates (Listing 4 through Listing 11) and apply them using multiple calls to the sntl_lg_apply_template() function (Sequence 4).

Listing 4 - Define the Product "ImageFilterSDK"

 <?xml version="1.0" encoding="utf-8"?>
 <sentinel_ldk:license schema_version="1.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:sentinel_ldk="http://www.safenet-inc.com/sentinelldk">
   <enforcement_type>HL</enforcement_type>
   <product>
      <id>100</id>
      <name>ImageFilterSDK</name>
   </product>
 </sentinel_ldk:license>
 

Listing 5 - Add the  "Blur Filter" Feature to the "ImageFilterSDK" Product

 <?xml version="1.0" encoding="utf-8"?>
 <sentinel_ldk:license schema_version="1.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:sentinel_ldk="http://www.safenet-inc.com/sentinelldk">
   <enforcement_type>HL</enforcement_type>
   <product>
      <id>100</id>
      <feature>
         <id>1</id>
         <name>Blur Filter</name>
         <license_properties>
            <perpetual/>
            <concurrency>
               <count>Unlimited</count>
               <network_access>Yes</network_access>
            </concurrency>
            <remote_desktop_access>Yes</remote_desktop_access>
         </license_properties>
      </feature>
   </product>
 </sentinel_ldk:license>
 

Listing 6 - Add the "Motion Blur Filter" Feature to the "ImageFilterSDK" Product

 <?xml version="1.0" encoding="utf-8"?>
 <sentinel_ldk:license schema_version="1.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:sentinel_ldk="http://www.safenet-inc.com/sentinelldk">
   <enforcement_type>HL</enforcement_type>
   <product>
      <id>100</id>
      <feature>
         <id>2</id>
         <name>Motion Blur Filter</name>
         <license_properties>
            <execution_count>99</execution_count>
            <concurrency>
               <count>10</count>
               <count_criteria>Per Process</count_criteria>
               <network_access>No</network_access>
            </concurrency>
            <remote_desktop_access>No</remote_desktop_access>
         </license_properties>
      </feature>
   </product>
 </sentinel_ldk:license>
 

Listing 7 - Add the "Find Edge Filter" Feature to the "ImageFilterSDK" Product (the only Feature attribute defined is expiration date).

 <?xml version="1.0" encoding="utf-8"?>
 <sentinel_ldk:license schema_version="1.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:sentinel_ldk="http://www.safenet-inc.com/sentinelldk">
   <enforcement_type>HL</enforcement_type>
   <product>
      <id>100</id>
      <feature>
         <id>3</id>
         <name>Find Edges Filter</name>
         <license_properties>
            <expiration_date>2023-03-31</expiration_date>
         </license_properties>
      </feature>
   </product>
 </sentinel_ldk:license> 

Listing 8 - Add concurrency information to the "Find Edge Filter" Feature of the "ImageFilterSDK" Product

 <?xml version="1.0" encoding="utf-8"?>
 <sentinel_ldk:license schema_version="1.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:sentinel_ldk="http://www.safenet-inc.com/sentinelldk">
   <enforcement_type>HL</enforcement_type>
   <product>
      <id>100</id>
      <feature>
         <id>3</id>
         <license_properties>
            <concurrency>
               <count>50</count>
               <count_criteria>Per Login</count_criteria>
               <network_access>No</network_access>
            </concurrency>
            <remote_desktop_access>Yes</remote_desktop_access>
         </license_properties>
      </feature>
   </product>
 </sentinel_ldk:license>
 

Listing 9 - Add "Image Plug-ins" Product with "Text Finder Plug in" Feature

 <?xml version="1.0" encoding="utf-8"?>
 <sentinel_ldk:license schema_version="1.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:sentinel_ldk="http://www.safenet-inc.com/sentinelldk">
   <enforcement_type>HL</enforcement_type>
   <product>
      <id>200</id>
      <name>Image Plug-ins</name>
      <feature>
         <id>11</id>
         <name>Text Finder Plug in</name>
         <license_properties>
            <days_to_expiration>90</days_to_expiration>
            <concurrency>
               <count>12</count>
               <network_access>Yes</network_access>
            </concurrency>
            <remote_desktop_access>Yes</remote_desktop_access>
         </license_properties>
      </feature>
   </product>
 </sentinel_ldk:license>
 

Listing 10 - Add data to the RO and RW memory areas of the key

 <?xml version="1.0" encoding="utf-8"?>
 <sentinel_ldk:license schema_version="1.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:sentinel_ldk="http://www.safenet-inc.com/sentinelldk">
   <enforcement_type>HL</enforcement_type>
   <memory>
      <ro_memory_segment>
         <offset>10</offset>
         <content>QVBQTEU=</content>
      </ro_memory_segment>
      <rw_memory_segment>
         <offset>10</offset>
         <content>QkFOQU5B</content>
      </rw_memory_segment>
   </memory>
 </sentinel_ldk:license>
 

Listing 11 - Add a file to the dynamic memory of the key

<?xml version="1.0" encoding="utf-8"?>
<sentinel_ldk:license schema_version="1.0"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:sentinel_ldk="http://www.safenet-inc.com/sentinelldk"> <enforcement_type>HL</enforcement_type> <dynamic_resource> <isv_memory attribute="ro"> <file_id>1</file_id> <size>100</size> <segment> <offset>0</offset> <content>cmVhZCBvbmx5IGR5bmFtaWMgcmVjb3VyY2U=</content> </segment> </isv_memory> </dynamic_resource> </sentinel_ldk:license>

Sequence 4. Sample code to use the sntl_lg_apply_template() function to apply multiple templates

The code that follows uses multiple calls to the sntl_lg_apply_template() function to apply the component license templates in Listing 4 through Listing 11.

 sntl_lg_handle_t handle;
 sntl_lg_status_t status;
 sntl_lg_vendor_code_t vendor_code; // put the Vendor Code
 char *current_state; // put the current state of the key.
 char *license_definition_4; // put the sample in Listing 4 here.
 char *license_definition_5; // put the sample in Listing 5 here.
 char *license_definition_6; // put the sample in Listing 6 here.
 char *license_definition_7; // put the sample in Listing 7 here.
 char *license_definition_8; // put the sample in Listing 8 here.
 char *license_definition_9; // put the sample in Listing 9 here.
 char *license_definition_10; // put the sample in Listing 10 here.
char *license_definition_11; // put the sample in Listing 11 here.
 char *license = NULL;  char *updated_state = NULL;  status = sntl_lg_initialize(NULL, &handle);  if (status)  {    // some error occurred.  }  // *** Do not forget to initialize the 'current_state' variable with the key's current state  // *** Do not forget to initialize the 'vendor_code' variable with the assigned Vendor Code  status = sntl_lg_start(handle, NULL, vendor_code, SNTL_LG_LICENSE_TYPE_UPDATE, NULL, current_state);  if (status)  {    // some error occurred.  }  status = sntl_lg_apply_template(handle, license_definition_4);  if (status)  {    // some error occurred.  }  status = sntl_lg_apply_template(handle, license_definition_5);  if (status)  {    // some error occurred.  }  status = sntl_lg_apply_template(handle, license_definition_6);  if (status)  {    // some error occurred.  }  status = sntl_lg_apply_template(handle, license_definition_7);  if (status)  {    // some error occurred.  }  status = sntl_lg_apply_template(handle, license_definition_8);  if (status)  {    // some error occurred.  }  status = sntl_lg_apply_template(handle, license_definition_9);  if (status)  {    // some error occurred.  }  status = sntl_lg_apply_template(handle, license_definition_10);  if (status)  {    // some error occurred.
}
status = sntl_lg_apply_template(handle, license_definition_11); if (status) { // some error occurred. }  status = sntl_lg_generate_license(handle, NULL, &license, &updated_state);  if (status)  {    // some error occurred.  }  sntl_lg_free_memory(license);  sntl_lg_free_memory(updated_state);  sntl_lg_cleanup(&handle);  

Related Topics

License Definition Input XML Templates