/* *********************************************************
 * *                                                       * 
 * *                Configuration Library                  * 
 * *       Load license_setup Information From file        * 
 * *                                                       * 
 * *********************************************************
 * File: libs/config/license_load.c
 *
 *                       COPYRIGHT (c) 2003 BY 
 *          SIGMET INCORPORATED, WESTFORD MASSACHUSETTS, U.S.A.  
 * 
 * THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY BE USED AND  COPIED
 * ONLY  IN  ACCORDANCE WITH  THE  TERMS  OF  SUCH  LICENSE  AND WITH THE
 * INCLUSION OF THE ABOVE COPYRIGHT NOTICE.  THIS SOFTWARE  OR  ANY OTHER
 * COPIES  THEREOF MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY
 * OTHER PERSON.  NO TITLE TO AND OWNERSHIP OF  THE  SOFTWARE  IS  HEREBY
 * TRANSFERED. 
 */     
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "sigtypes.h"
#include "sigversion.h"
#include "setup.h"
#include "config_lib.h"

/* =================================================================== 
 * This subroutine reads the saved values from several different files
 * which together define the IRIS environment.
 */
MESSAGE license_load_setup
( const char *sRemoteHostname_a,
  volatile struct license_setup *pLSetup_a )
{
  MESSAGE istatus, iExitStatus = SS_NORMAL ;

  /* Initialize to all defaults in case of an early error
   */     
  memset( (void *)pLSetup_a, 0, sizeof( struct license_setup) ) ;
  istatus = setup_limits( "license_setup", pLSetup_a, SETUP_DEFVAL, NULL ) ;
  if( istatus != SS_NORMAL ) iExitStatus = istatus ;
      
  istatus = lim_loadFile( sRemoteHostname_a, "setup_license.conf", 
			  "license_setup", pLSetup_a, setup_limits ) ;
  if( istatus != SS_NORMAL ) iExitStatus = istatus ;

  return( iExitStatus ) ;
}

/* =================================================================== 
 * This subroutine writes the internal values into several different
 * files which together define the IRIS environment.
 */
MESSAGE license_save_setup
( const char *sRemoteHostname_a,
  const struct license_setup *pLSetup_a )
{
  MESSAGE istatus, iExitStatus = SS_NORMAL ;
  struct license_setup setup;

  /* Copy the structure in order to fill in the IRIS version.
   */
  setup = *pLSetup_a;

  strncpy( setup.sVersion, IRIS_VERSION, 8 ) ; setup.sVersion[7] = '\0' ;
  istatus = lim_saveFile( sRemoteHostname_a, "setup_license.conf", 
			  "license_setup", &setup, setup_limits ) ;
  if( istatus != SS_NORMAL ) iExitStatus = istatus ;

  return( iExitStatus ) ;
}
