cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to get the expiration date of borrowed license

How to get the expiration date of borrowed license

Sample Code to get  the expiration date of borrowed license

 

/**************************************************************************************************
* Copyright (c) 1997-2018 Flexera. All Rights Reserved.
**************************************************************************************************/
/*
 *
 *	Description:	This is a sample application program, to illustrate
 *			the use of the Flexible License Manager.
 *
 */

#include "lmclient.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "lm_attr.h"
#include "lm_redir_std.h"

#ifdef PC
#define LICPATH "@localhost"
#else
#define LICPATH "@localhost:license.dat:."
#endif /* PC */

#define FEATURE "f1"
VENDORCODE code;
LM_HANDLE *lm_job;

LM_BORROW_STAT *s;
static void init(struct flexinit_property_handle **);
static void cleanup(struct flexinit_property_handle *);

int
main(int argc, char * argv[])
{
	char feature[MAX_FEATURE_LEN * 2] = {'\0'};
	struct flexinit_property_handle *initHandle = NULL;
	int nlic = 1;
		char expiration_date[100];
	struct tm *tm;

	init(&initHandle);

	if (argc > 1)
	{
		nlic = atoi(argv[1]);
	}

	if (lc_new_job(0, lc_new_job_arg2, &code, &lm_job))
	{
		lc_perror(lm_job, "lc_new_job failed");
		cleanup(initHandle);
		exit(lc_get_errno(lm_job));
	}

	printf("Enter \"f1\" to demo floating functionality\n");
	printf("Enter \"f2\" to demo node-locked functionality\n");
	printf("Enter feature to checkout [default: \"%s\"]: ", FEATURE);


	fgets(feature, MAX_FEATURE_LEN + 2, lm_flex_stdin());	/*	add 2 for \n and \0	*/
	feature[strlen(feature) - 1] = '\0';
	if(!*feature)
		strcpy(feature, FEATURE);

	(void)lc_set_attr(lm_job, LM_A_LICENSE_DEFAULT, (LM_A_VAL_TYPE)LICPATH);
	
		lc_get_attr(lm_job, LM_A_BORROW_STAT, &s);
    for(; s; s = s->next)
    {
        printf("Borrowed Feature is %s\n", s->feature);
        tm = localtime(&s->end);
 
        sprintf(expiration_date, "%d-%s-%02d %02d:%02d",
            tm->tm_mday,
            tm->tm_mon == 0 ? "Jan" :
            tm->tm_mon == 1 ? "Feb" :
            tm->tm_mon == 2 ? "Mar" :
            tm->tm_mon == 3 ? "Apr" :
            tm->tm_mon == 4 ? "May" :
            tm->tm_mon == 5 ? "Jun" :
            tm->tm_mon == 6 ? "Jul" :
            tm->tm_mon == 7 ? "Aug" :
            tm->tm_mon == 8 ? "Sep" :
            tm->tm_mon == 9 ? "Oct" :
            tm->tm_mon == 10 ? "Nov" : "Dec",
            (tm->tm_year + 1900) % 2000,
                tm->tm_hour, tm->tm_min);
 
        printf("Expiration Date is %s\n",expiration_date);
        getchar();
        break;
    }

	if(lc_checkout(lm_job, feature, "1.0", nlic, LM_CO_NOWAIT, &code, LM_DUP_NONE))
	{
		lc_perror(lm_job, "checkout failed");
		cleanup(initHandle);
		exit (lc_get_errno(lm_job));
	}
	


	
	printf("%s checked out...", feature);
	printf("press return to exit...");

	/*
	*	Wait till user hits return
	*/
	getchar();
	lc_checkin(lm_job, feature, 0);
	lc_free_job(lm_job);
	cleanup(initHandle);
	return 0;
}

static void init(struct flexinit_property_handle **handle)
{
#ifndef NO_ACTIVATION_SUPPORT
	struct flexinit_property_handle *ourHandle = NULL;
	int stat;

	if ((stat = lc_flexinit_property_handle_create(&ourHandle)))
	{
		fprintf(lm_flex_stderr(), "lc_flexinit_property_handle_create() failed: %d\n", stat);
		exit(1);
	}
	if ((stat = lc_flexinit_property_handle_set(ourHandle,
			(FLEXINIT_PROPERTY_TYPE)FLEXINIT_PROPERTY_USE_TRUSTED_STORAGE,
			(FLEXINIT_VALUE_TYPE)1)))
	{
		fprintf(lm_flex_stderr(), "lc_flexinit_property_handle_set failed: %d\n", stat);
	    exit(1);
	}
	if ((stat = lc_flexinit(ourHandle)))
	{
		fprintf(lm_flex_stderr(), "lc_flexinit failed: %d\n", stat);
	    exit(1);
	}
	*handle = ourHandle;
#endif /* NO_ACTIVATION_SUPPORT */
}

static void cleanup(struct flexinit_property_handle *initHandle)
{
#ifndef NO_ACTIVATION_SUPPORT
	int stat;

	if ((stat = lc_flexinit_cleanup(initHandle)))
	{
		fprintf(lm_flex_stderr(), "lc_flexinit_cleanup failed: %d\n", stat);
	}
	if ((stat = lc_flexinit_property_handle_free(initHandle)))
	{
		fprintf(lm_flex_stderr(), "lc_flexinit_property_handle_free failed: %d\n", stat);
	}
#endif /* NO_ACTIVATION_SUPPORT */
}

 

 

Was this article helpful? Yes No
No ratings
Version history
Last update:
‎Aug 27, 2020 01:29 AM
Updated by:
Contributors