Commit 32786cc7 authored by Francois TABURET's avatar Francois TABURET

Integration of configuration module. Temporarily keep the legacy mode.

lte-softmodem -O <config file> will trigger legacy config mode
ltesoftmodem  -O libconfig:<config file> will trigger configuration module usage.
parent 293bcf13
......@@ -37,43 +37,73 @@
int processoption(paramdef_t *cfgoptions, char *value)
{
int ret = 0;
int optisset=0;
int noarg=0;
if ((cfgoptions->paramflags &PARAMFLAG_BOOL) == 0) {
if (value == NULL) {
noarg=1;
} else if ( value[0] == '-') {
noarg = 1;
}
if (noarg == 1) {
fprintf(stderr,"[CONFIG] command line, option %s requires an argument\n",cfgoptions->optname);
return 0;
}
}
switch(cfgoptions->type)
{
case TYPE_STRING:
check_valptr(cfgoptions, (char **)(cfgoptions->strptr), sizeof(char *));
check_valptr(cfgoptions, cfgoptions->strptr, strlen(value+1));
config_check_valptr(cfgoptions, (char **)(cfgoptions->strptr), sizeof(char *));
config_check_valptr(cfgoptions, cfgoptions->strptr, strlen(value+1));
sprintf(*(cfgoptions->strptr), "%s",value);
printf_cmdl("[LIBCONFIG] %s set to %s from command line\n", cfgoptions->optname, value);
ret++;
break;
case TYPE_STRINGLIST:
break;
printf_cmdl("[CONFIG] %s set to %s from command line\n", cfgoptions->optname, value);
optisset=1;
break;
case TYPE_UINT:
case TYPE_INT:
case TYPE_STRINGLIST:
break;
case TYPE_UINT32:
case TYPE_INT32:
case TYPE_UINT16:
case TYPE_INT16:
case TYPE_UINT8:
case TYPE_INT8:
config_check_valptr(cfgoptions, (char **)&(cfgoptions->iptr),sizeof(int32_t));
config_assign_int(cfgoptions,cfgoptions->optname,(int32_t)strtol(value,NULL,0));
optisset=1;
break;
case TYPE_UINT64:
case TYPE_INT64:
check_valptr(cfgoptions, (char **)&(cfgoptions->i64ptr),sizeof(uint64_t));
*(cfgoptions->uptr) =strtol(value,NULL,0);
printf_cmdl("[LIBCONFIG] %s set to %lli from command line\n", cfgoptions->optname, (long long)*(cfgoptions->i64ptr));
ret++;
config_check_valptr(cfgoptions, (char **)&(cfgoptions->i64ptr),sizeof(uint64_t));
*(cfgoptions->i64ptr)=strtoll(value,NULL,0);
printf_cmdl("[CONFIG] %s set to %lli from command line\n", cfgoptions->optname, (long long)*(cfgoptions->i64ptr));
optisset=1;
break;
case TYPE_UINTARRAY:
case TYPE_INTARRAY:
break;
case TYPE_DOUBLE:
config_check_valptr(cfgoptions, (char **)&(cfgoptions->dblptr),sizeof(double));
*(cfgoptions->dblptr) = strtof(value,NULL);
printf_cmdl("[CONFIG] %s set to %lf from command line\n", cfgoptions->optname, *(cfgoptions->dblptr));
optisset=1;
break;
case TYPE_IPV4ADDR:
break;
default:
fprintf(stderr,"[LIBCONFIG] command line, %s type %i not supported\n",cfgoptions->optname, cfgoptions->type);
fprintf(stderr,"[CONFIG] command line, %s type %i not supported\n",cfgoptions->optname, cfgoptions->type);
break;
} /* switch on param type */
return ret;
if (optisset == 1) {
cfgoptions->paramflags = cfgoptions->paramflags | PARAMFLAG_PARAMSET;
}
return optisset;
}
int config_process_cmdline(paramdef_t *cfgoptions,int numoptions, char *prefix)
......@@ -101,9 +131,13 @@ char *cfgpath;
if ( ( cfgoptions[i].paramflags & PARAMFLAG_DISABLECMDLINE) != 0) {
continue;
}
sprintf(cfgpath,"%s.%s",prefix,cfgoptions[i].optname);
if ( strcmp(*p + 1,cfgoptions[i].shortopt) == 0 ||
strcmp(*p + 2,cfgpath ) == 0 ) {
if (prefix != NULL) {
sprintf(cfgpath,"%s.%s",prefix,cfgoptions[i].optname);
} else {
sprintf(cfgpath,"%s",cfgoptions[i].optname);
}
if ( ((strlen(*p) > 1) && (strcmp(*p + 1,cfgoptions[i].shortopt) == 0)) ||
((strlen(*p) > 2) && (strcmp(*p + 2,cfgpath ) == 0 )) ) {
p++;
j =+ processoption(&(cfgoptions[i]), *p);
c--;
......
......@@ -42,7 +42,7 @@
#include "config_userapi.h"
#define CONFIG_SHAREDLIBFORMAT "libparams_%s.so"
int load_config_sharedlib(char *cfgmode, char *cfgP[], int numP, configmodule_interface_t *cfgptr)
int load_config_sharedlib(configmodule_interface_t *cfgptr)
{
void *lib_handle;
char fname[128];
......@@ -50,46 +50,46 @@ char libname[FILENAME_MAX];
int st;
st=0;
sprintf(libname,CONFIG_SHAREDLIBFORMAT,cfgmode);
sprintf(libname,CONFIG_SHAREDLIBFORMAT,cfgptr->cfgmode);
lib_handle = dlopen(libname,RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE);
if (!lib_handle) {
fprintf(stderr,"[CONFIG] %s %d Error calling dlopen(%s): %s\n",__FILE__, __LINE__, libname,dlerror());
st = -1;
} else {
sprintf (fname,"config_%s_init",cfgmode);
sprintf (fname,"config_%s_init",cfgptr->cfgmode);
cfgptr->init = dlsym(lib_handle,fname);
if (cfgptr->init == NULL ) {
printf("[CONFIG] %s %d no function %s for config mode %s\n",
__FILE__, __LINE__,fname, cfgmode);
__FILE__, __LINE__,fname, cfgptr->cfgmode);
} else {
st=cfgptr->init(cfgP,numP);
st=cfgptr->init(cfgptr->cfgP,cfgptr->num_cfgP);
printf("[CONFIG] function %s returned %i\n",
fname, st);
}
sprintf (fname,"config_%s_get",cfgmode);
sprintf (fname,"config_%s_get",cfgptr->cfgmode);
cfgptr->get = dlsym(lib_handle,fname);
if (cfgptr->get == NULL ) {
printf("[CONFIG] %s %d no function %s for config mode %s\n",
__FILE__, __LINE__,fname, cfgmode);
__FILE__, __LINE__,fname, cfgptr->cfgmode);
st = -1;
}
sprintf (fname,"config_%s_getlist",cfgmode);
sprintf (fname,"config_%s_getlist",cfgptr->cfgmode);
cfgptr->getlist = dlsym(lib_handle,fname);
if (cfgptr->getlist == NULL ) {
printf("[CONFIG] %s %d no function %s for config mode %s\n",
__FILE__, __LINE__,fname, cfgmode);
__FILE__, __LINE__,fname, cfgptr->cfgmode);
st = -1;
}
sprintf (fname,"config_%s_end",cfgmode);
sprintf (fname,"config_%s_end",cfgptr->cfgmode);
cfgptr->end = dlsym(lib_handle,fname);
if (cfgptr->getlist == NULL ) {
printf("[CONFIG] %s %d no function %s for config mode %s\n",
__FILE__, __LINE__,fname, cfgmode);
__FILE__, __LINE__,fname, cfgptr->cfgmode);
}
}
......@@ -105,16 +105,11 @@ char *cfgparam=NULL;
char *modeparams=NULL;
char *cfgmode=NULL;
char *strtokctx=NULL;
char *cfgP[CONFIG_MAX_OOPT_PARAMS];
int i;
int p;
char *atoken;
int i;
for(i=0; i<CONFIG_MAX_OOPT_PARAMS ; i++) {
cfgP[i]=NULL;
}
/* first parse the command line to look for the -O option */
opterr=0;
while ((i = getopt(argc, argv, "O:")) != -1) {
......@@ -122,6 +117,8 @@ int p;
cfgparam = optarg;
}
}
optind=1;
/* look for the OAI_CONFIGMODULE environement variable */
if ( cfgparam == NULL ) {
cfgparam = getenv("OAI_CONFIGMODULE");
......@@ -138,36 +135,47 @@ int p;
return NULL;
}
else if ( i == 1 ) {
/* -O argument doesn't contain ":" separator, legacy -O <conf file> option, default cfgmode to libconfig
with one parameter, the path to the configuration file */
modeparams=cfgmode;
cfgmode=strdup("libconfig");
}
cfgptr = malloc(sizeof(configmodule_interface_t));
p=0;
cfgP[p]=strtok_r(modeparams,":",&strtokctx);
while ( p< CONFIG_MAX_OOPT_PARAMS && cfgP[p] != NULL) {
memset(cfgptr,0,sizeof(configmodule_interface_t));
/* temporary, legacy mode */
if (i==1) cfgptr->rtflags = cfgptr->rtflags | CONFIG_LEGACY;
/*--*/
cfgptr->argc = argc;
cfgptr->argv = argv;
cfgptr->cfgmode=strdup(cfgmode);
cfgptr->num_cfgP=0;
atoken=strtok_r(modeparams,":",&strtokctx);
while ( cfgptr->num_cfgP< CONFIG_MAX_OOPT_PARAMS && atoken != NULL) {
/* look for debug level in the config parameters, it is commom to all config mode
and will be removed frome the parameter array passed to the shared module */
char *aptr;
aptr=strcasestr(cfgP[p],"dbgl");
aptr=strcasestr(atoken,"dbgl");
if (aptr != NULL) {
cfgptr->rtflags = strtol(aptr+4,NULL,0);
Config_Params[CONFIGPARAM_DEBUGFLAGS_IDX].paramflags = Config_Params[CONFIGPARAM_DEBUGFLAGS_IDX].paramflags | PARAMFLAG_DONOTREAD;
for (int j=p; j<(CONFIG_MAX_OOPT_PARAMS-1); j++) cfgP[j] = cfgP[j+1];
p--;
cfgptr->rtflags = cfgptr->rtflags | strtol(aptr+4,NULL,0);
} else {
cfgptr->cfgP[cfgptr->num_cfgP] = strdup(atoken);
cfgptr->num_cfgP++;
}
p++;
cfgP[p] = strtok_r(NULL,":",&strtokctx);
atoken = strtok_r(NULL,":",&strtokctx);
}
printf("[CONFIG] get parameters from %s ",cfgmode);
for (i=0;i<p; i++) {
printf("%s ",cfgP[i]);
for (i=0;i<cfgptr->num_cfgP; i++) {
printf("%s ",cfgptr->cfgP[i]);
}
printf("\n");
i=load_config_sharedlib(cfgmode, cfgP,p,cfgptr);
i=load_config_sharedlib(cfgptr);
if (i< 0) {
fprintf(stderr,"[CONFIG] %s %d config module %s couldn't be loaded\n", __FILE__, __LINE__,cfgmode);
return NULL;
......@@ -180,26 +188,30 @@ int p;
if (modeparams != NULL) free(modeparams);
if (cfgmode != NULL) free(cfgmode);
optind=1;
cfgptr->argc = argc;
cfgptr->argv = argv;
return cfgptr;
}
void end_configmodule()
{
if (cfgptr != NULL) {
printf ("[CONFIG] free %u pointers\n",cfgptr->numptrs);
if (cfgptr->end != NULL) {
printf ("[CONFIG] calling config module end function...\n");
cfgptr->end();
}
if( cfgptr->cfgmode != NULL) free(cfgptr->cfgmode);
printf ("[CONFIG] free %u config parameter pointers\n",cfgptr->num_cfgP);
for (int i=0; i<cfgptr->num_cfgP; i++) {
if ( cfgptr->cfgP[i] != NULL) free(cfgptr->cfgP[i]);
}
printf ("[CONFIG] free %u config value pointers\n",cfgptr->numptrs);
for(int i=0; i<cfgptr->numptrs ; i++) {
if (cfgptr->ptrs[i] != NULL) {
free(cfgptr->ptrs[i]);
}
cfgptr->ptrs[i]=NULL;
}
if (cfgptr->end != NULL) {
printf ("[CONFIG] calling config module end function...\n");
cfgptr->end();
}
free(cfgptr);
cfgptr=NULL;
}
......
......@@ -38,28 +38,34 @@
#include <stdlib.h>
#include "common/config/config_paramdesc.h"
#define CONFIG_MAX_OOPT_PARAMS 10 // maximum number of parameters in the -O option (-O <cfgmode>:P1:P2...
#define CONFIG_MAX_ALLOCATEDPTRS 1024 // maximum number of parameters that can be dynamicaly alloted in the config module
#define CONFIG_MAX_ALLOCATEDPTRS 1024 // maximum number of parameters that can be dynamicaly allocated in the config module
/* rtflags bit position definitions */
#define CONFIG_PRINTPARAMS 1 // print parameters values while processing
#define CONFIG_DEBUGPTR 2 // print memory allocation/free debug messages
#define CONFIG_DEBUGCMDLINE 4 // print command line processing messages
/* temporary flag to be able to use legacy config mechanism */
#define CONFIG_LEGACY (1 << 10)
typedef int(*configmodule_initfunc_t)(char *cfgP[],int numP);
typedef int(*configmodule_getfunc_t)(paramdef_t *,int numparams, char *prefix);
typedef int(*configmodule_getlistfunc_t)(paramlist_def_t *, paramdef_t *,int numparams, char *prefix);
typedef void(*configmodule_endfunc_t)(void);
typedef struct configmodule_interface
{
int argc;
char **argv;
int argc;
char **argv;
char *cfgmode;
int num_cfgP;
char *cfgP[CONFIG_MAX_OOPT_PARAMS];
configmodule_initfunc_t init;
configmodule_getfunc_t get;
configmodule_getlistfunc_t getlist;
configmodule_endfunc_t end;
uint32_t numptrs;
uint32_t rtflags;
char *ptrs[CONFIG_MAX_ALLOCATEDPTRS];
uint32_t numptrs;
uint32_t rtflags;
char *ptrs[CONFIG_MAX_ALLOCATEDPTRS];
} configmodule_interface_t;
#ifdef CONFIG_LOADCONFIG_MAIN
......@@ -75,7 +81,7 @@ static char config_helpstr [] =" \
#define CONFIGPARAM_DEBUGFLAGS_IDX 0
static paramdef_t Config_Params[] = {
{"debugflags", "", config_helpstr, 0, uptr:NULL, defintval:0, TYPE_UINT, 0},
{"debugflags", "", config_helpstr, 0, uptr:NULL, defintval:0, TYPE_MASK, 0},
};
#else
......
......@@ -42,51 +42,64 @@
/* parameter flags definitions */
/* Flags to be used by calling modules in their parameters definitions: */
#define PARAMFLAG_DISABLECMDLINE (1 << 0) // parameter can bet set from comand line
/* Flags to be used by calling modules in their parameters definitions to modify config module behavior*/
#define PARAMFLAG_MANDATORY (1 << 0) // parameter must be explicitely set, default value ignored
#define PARAMFLAG_DISABLECMDLINE (1 << 1) // parameter cannot bet set from comand line
#define PARAMFLAG_DONOTREAD (1 << 2) // parameter must be ignored in get function
#define PARAMFLAG_NOFREE (1 << 3) // don't free parameter in end function
#define PARAMFLAG_BOOL (1 << 4) // integer param can be 0 or 1
/* Flags used by config modules: */
/* flags to be used by caller modules when defining parameters */
#define PARAMFLAG_MANDATORY (1 << 1) // parameter must be explicitely set, default value ignored
/* flags used by config modules, at runtime to manage memory allocations */
#define PARAMFLAG_MALLOCINCONFIG (1 << 15) // parameter allocated in config module
#define PARAMFLAG_NOFREE (1 << 14) // don't free parameter in end function
/* flags to be used by caller modules to modify get behavior */
#define PARAMFLAG_DONOTREAD (1 << 20) // parameter must be ignored in get function
/* Flags used by config modules to return info to calling modules and/or to for internal usage*/
#define PARAMFLAG_MALLOCINCONFIG (1 << 15) // parameter allocated in config module
#define PARAMFLAG_PARAMSET (1 << 16) // parameter has been explicitely set in get functions
#define PARAMFLAG_PARAMSETDEF (1 << 17) // parameter has been set to default value in get functions
typedef struct paramdef
{
char optname[MAX_OPTNAME_SIZE];
char shortopt[MAX_SHORTOPT_SIZE];
char *helpstr;
unsigned int paramflags;
union {
char optname[MAX_OPTNAME_SIZE]; /* parameter name, can be used as long command line option */
char shortopt[MAX_SHORTOPT_SIZE]; /* short command line option */
char *helpstr; /* help string */
unsigned int paramflags; /* value is a "ored" combination of above PARAMFLAG_XXXX values */
union { /* pointer to the parameter value, completed by the config module */
char **strptr;
char **strlistptr;
uint32_t *uptr;
int32_t *iptr;
uint64_t *u64ptr;
int64_t *i64ptr;
uint8_t *u8ptr;
char *i8ptr;
uint16_t *u16ptr;
int16_t *i16ptr;
uint32_t *uptr;
int32_t *iptr;
uint64_t *u64ptr;
int64_t *i64ptr;
double *dblptr;
} ;
union {
union { /* default parameter value, to be used when PARAMFLAG_MANDATORY is not specified */
char *defstrval;
char **defstrlistval;
uint32_t defuintval;
int defintval;
uint64_t defint64val;
int *defintarrayval;
double defdblval;
} ;
char type;
int numelt;
char type; /* parameter value type, as listed below as TYPE_XXXX macro */
int numelt; /* number of elements in a list or array parameters or max size of string value */
} paramdef_t;
#define TYPE_INT TYPE_INT32
#define TYPE_UINT TYPE_UINT32
#define TYPE_STRING 1
#define TYPE_INT 2
#define TYPE_UINT 3
#define TYPE_INT64 4
#define TYPE_UINT64 5
#define TYPE_INT8 2
#define TYPE_UINT8 3
#define TYPE_INT16 4
#define TYPE_UINT16 5
#define TYPE_INT32 6
#define TYPE_UINT32 7
#define TYPE_INT64 8
#define TYPE_UINT64 9
#define TYPE_MASK 10
#define TYPE_DOUBLE 16
#define TYPE_IPV4ADDR 20
......@@ -94,7 +107,7 @@ typedef struct paramdef
#define TYPE_INTARRAY 51
#define TYPE_UINTARRAY 52
#define TYPE_LIST 55
#define NO_UINTDEFAULT ((int)(-1))
#define ANY_IPV4ADDR_STRING "0.0.0.0"
typedef struct paramlist_def {
......
......@@ -47,7 +47,7 @@ configmodule_interface_t *config_get_if(void)
return cfgptr;
}
char * check_valptr(paramdef_t *cfgoptions, char **ptr, int length)
char * config_check_valptr(paramdef_t *cfgoptions, char **ptr, int length)
{
printf_ptrs("-- %s 0x%08lx %i\n",cfgoptions->optname,(uintptr_t)(*ptr),length);
......@@ -60,13 +60,54 @@ char * check_valptr(paramdef_t *cfgoptions, char **ptr, int length)
config_get_if()->numptrs++;
}
} else {
fprintf (stderr,"[LIBCONFIG] %s %d malloc error\n",__FILE__, __LINE__);
fprintf (stderr,"[CONFIG] %s %d malloc error\n",__FILE__, __LINE__);
exit(-1);
}
}
return *ptr;
}
void config_assign_int(paramdef_t *cfgoptions, char *fullname, int val)
{
int tmpval=val;
if ( ((cfgoptions->paramflags &PARAMFLAG_BOOL) != 0) && tmpval >1) {
tmpval =1;
}
switch (cfgoptions->type) {
case TYPE_UINT8:
*(cfgoptions->u8ptr) = (uint8_t)tmpval;
printf_params("[CONFIG] %s: %u\n", fullname, (uint8_t)tmpval);
break;
case TYPE_INT8:
*(cfgoptions->i8ptr) = (int8_t)tmpval;
printf_params("[CONFIG] %s: %i\n", fullname, (int8_t)tmpval);
break;
case TYPE_UINT16:
*(cfgoptions->u16ptr) = (uint16_t)tmpval;
printf_params("[CONFIG] %s: %hu\n", fullname, (uint16_t)tmpval);
break;
case TYPE_INT16:
*(cfgoptions->i16ptr) = (int16_t)tmpval;
printf_params("[CONFIG] %s: %hi\n", fullname, (int16_t)tmpval);
break;
case TYPE_UINT32:
*(cfgoptions->uptr) = (uint32_t)tmpval;
printf_params("[CONFIG] %s: %u\n", fullname, (uint32_t)tmpval);
break;
case TYPE_MASK:
*(cfgoptions->uptr) = *(cfgoptions->uptr) | (uint32_t)tmpval;
printf_params("[CONFIG] %s: 0x%08x\n", fullname, (uint32_t)tmpval);
break;
case TYPE_INT32:
*(cfgoptions->iptr) = (int32_t)tmpval;
printf_params("[CONFIG] %s: %i\n", fullname, (int32_t)tmpval);
break;
default:
fprintf (stderr,"[CONFIG] %s %i type %i non integer parameter %s not assigned\n",__FILE__, __LINE__,cfgoptions->type,fullname);
break;
}
}
void config_printhelp(paramdef_t *params,int numparams)
{
for (int i=0 ; i<numparams ; i++) {
......@@ -80,12 +121,21 @@ int config_get(paramdef_t *params,int numparams, char *prefix)
{
int ret= -1;
configmodule_interface_t *cfgif = config_get_if();
if (cfgif != NULL) {
ret = config_get_if()->get(params, numparams,prefix);
if (ret >= 0) {
config_process_cmdline(params,numparams,prefix);
}
if (cfgif != NULL) {
ret = config_get_if()->get(params, numparams,prefix);
if (ret >= 0) {
config_process_cmdline(params,numparams,prefix);
}
return ret;
}
return ret;
}
return ret;
int config_isparamset(paramdef_t *params,int paramidx)
{
if ((params[paramidx].paramflags & PARAMFLAG_PARAMSET) != 0) {
return 1;
} else {
return 0;
}
}
......@@ -38,12 +38,19 @@
extern "C"
{
#endif
#define CONFIG_GETSOURCE ( (config_get_if()==NULL) ? NULL : config_get_if()->cfgmode )
#define CONFIG_GETNUMP ( (config_get_if()==NULL) ? 0 : config_get_if()->num_cfgP )
#define CONFIG_GETP(P) ( (config_get_if()==NULL) ? NULL : config_get_if()->cfgP[P] )
#define CONFIG_ISFLAGSET(P) ( (config_get_if()==NULL) ? 0 : !!(config_get_if()->rtflags & P))
extern configmodule_interface_t *config_get_if(void);
extern char * check_valptr(paramdef_t *cfgoptions, char **ptr, int length) ;
extern char * config_check_valptr(paramdef_t *cfgoptions, char **ptr, int length) ;
extern void config_printhelp(paramdef_t *,int numparams);
extern int config_process_cmdline(paramdef_t *params,int numparams, char *prefix);
extern int config_get(paramdef_t *params,int numparams, char *prefix);
extern int config_isparamset(paramdef_t *params,int paramidx);
extern void config_assign_int(paramdef_t *cfgoptions, char *fullname, int val);
extern int config_process_cmdline(paramdef_t *cfgoptions,int numoptions, char *prefix);
#define config_getlist config_get_if()->getlist
......
......@@ -58,16 +58,18 @@ int config_libconfig_get(paramdef_t *cfgoptions,int numoptions, char *prefix )
config_setting_t *setting;
const char *str;
char *str;
int i,u;
long long int llu;
double dbl;
int rst;
int status=0;
int notfound;
int defval;
int fatalerror=0;
char *cfgpath; /* listname.[listindex].paramname */
int defvals=0;
int numdefvals=0;
i = (prefix ==NULL) ? 0 : strlen(prefix);
cfgpath = malloc( i+ MAX_OPTNAME_SIZE +1);
if (cfgpath == NULL) {
......@@ -87,20 +89,26 @@ int config_libconfig_get(paramdef_t *cfgoptions,int numoptions, char *prefix )
continue;
}
notfound=0;
defval=0;
switch(cfgoptions[i].type)
{
case TYPE_STRING:
if ( config_lookup_string(&(libconfig_privdata.cfg),cfgpath, &str)) {
check_valptr(&(cfgoptions[i]), (char **)(&(cfgoptions[i].strptr)), sizeof(char *));
check_valptr(&(cfgoptions[i]), cfgoptions[i].strptr, strlen(str)+1);
if ( config_lookup_string(&(libconfig_privdata.cfg),cfgpath, (const char **)&str)) {
if ( cfgoptions[i].numelt > 0 && str != NULL && strlen(str) >= cfgoptions[i].numelt ) {
fprintf(stderr,"[LIBCONFIG] %s: %s exceeds maximum length of %i bytes, value truncated\n",
cfgpath,str,cfgoptions[i].numelt);
str[strlen(str)-1] = 0;
}
config_check_valptr(&(cfgoptions[i]), (char **)(&(cfgoptions[i].strptr)), sizeof(char *));
config_check_valptr(&(cfgoptions[i]), cfgoptions[i].strptr, strlen(str)+1);
sprintf( *(cfgoptions[i].strptr) , "%s", str);
printf_params("[LIBCONFIG] %s: %s\n", cfgpath,*(cfgoptions[i].strptr) );
} else {
if( cfgoptions[i].defstrval != NULL) {
defvals++;
check_valptr(&(cfgoptions[i]), (char **)(&(cfgoptions[i].strptr)), sizeof(char *));
check_valptr(&(cfgoptions[i]), cfgoptions[i].strptr, strlen(cfgoptions[i].defstrval)+1);
defval=1;
config_check_valptr(&(cfgoptions[i]), (char **)(&(cfgoptions[i].strptr)), sizeof(char *));
config_check_valptr(&(cfgoptions[i]), cfgoptions[i].strptr, strlen(cfgoptions[i].defstrval)+1);
sprintf(*(cfgoptions[i].strptr), "%s",cfgoptions[i].defstrval);
printf_params("[LIBCONFIG] %s set to default value %s\n", cfgpath, *(cfgoptions[i].strptr));
} else {
......@@ -114,8 +122,8 @@ int config_libconfig_get(paramdef_t *cfgoptions,int numoptions, char *prefix )
read_strlist(&cfgoptions[i],setting,cfgpath);
} else {
if( cfgoptions[i].defstrlistval != NULL) {
cfgoptions[i].strlistptr=cfgoptions[i].defstrlistval;
defvals++;
cfgoptions[i].strlistptr=cfgoptions[i].defstrlistval;
defval=1;
for(int j=0; j<cfgoptions[i].numelt; j++)
printf_params("[LIBCONFIG] %s%i set to default value %s\n", cfgpath,j, cfgoptions[i].strlistptr[j]);
} else {
......@@ -123,23 +131,21 @@ int config_libconfig_get(paramdef_t *cfgoptions,int numoptions, char *prefix )
}
}
break;
case TYPE_UINT:
case TYPE_INT:
check_valptr(&(cfgoptions[i]), (char **)(&(cfgoptions[i].iptr)),sizeof(int));
case TYPE_UINT8:
case TYPE_INT8:
case TYPE_UINT16:
case TYPE_INT16:
case TYPE_UINT32:
case TYPE_INT32:
case TYPE_MASK:
config_check_valptr(&(cfgoptions[i]), (char **)(&(cfgoptions[i].iptr)),sizeof(int32_t));
if ( config_lookup_int(&(libconfig_privdata.cfg),cfgpath, &u)) {
if(cfgoptions[i].type==TYPE_UINT) {
*(cfgoptions[i].uptr) = (unsigned int)u;
printf_params("[LIBCONFIG] %s: %u\n", cfgpath,*(cfgoptions[i].uptr) );
} else {
*(cfgoptions[i].iptr) = u;
printf_params("[LIBCONFIG] %s: %i\n", cfgpath,*(cfgoptions[i].iptr) );
}
config_assign_int(&(cfgoptions[i]),cfgpath,u);
} else {
if( cfgoptions[i].defuintval != NO_UINTDEFAULT) {
*(cfgoptions[i].uptr)=cfgoptions[i].defuintval;
defvals++;
printf_params("[LIBCONFIG] %s set to default value %i\n", cfgpath, (int32_t)(*(cfgoptions[i].uptr)));
if( ((cfgoptions[i].paramflags & PARAMFLAG_MANDATORY) == 0)) {
config_assign_int(&(cfgoptions[i]),cfgpath,cfgoptions[i].defintval);
defval=1;
printf_params("[LIBCONFIG] %s set to default value\n", cfgpath);
} else {
notfound=1;
}
......@@ -147,7 +153,7 @@ int config_libconfig_get(paramdef_t *cfgoptions,int numoptions, char *prefix )
break;
case TYPE_UINT64:
case TYPE_INT64:
check_valptr(&(cfgoptions[i]), (char **)&(cfgoptions[i].i64ptr),sizeof(long long));
config_check_valptr(&(cfgoptions[i]), (char **)&(cfgoptions[i].i64ptr),sizeof(long long));
if ( config_lookup_int64(&(libconfig_privdata.cfg),cfgpath, &llu)) {
if(cfgoptions[i].type==TYPE_UINT64) {
*(cfgoptions[i].u64ptr) = (uint64_t)llu;
......@@ -157,9 +163,9 @@ int config_libconfig_get(paramdef_t *cfgoptions,int numoptions, char *prefix )
printf_params("[LIBCONFIG] %s: %lli\n", cfgpath,(long long unsigned)(*(cfgoptions[i].i64ptr)) );
}
} else {
if( cfgoptions[i].defuintval != NO_UINTDEFAULT) {
if( ((cfgoptions[i].paramflags & PARAMFLAG_MANDATORY) == 0)) {
*(cfgoptions[i].u64ptr)=cfgoptions[i].defuintval;
defvals++;
defval=1;
printf_params("[LIBCONFIG] %s set to default value %llu\n", cfgpath, (long long unsigned)(*(cfgoptions[i].u64ptr)));
} else {
notfound=1;
......@@ -173,9 +179,9 @@ int config_libconfig_get(paramdef_t *cfgoptions,int numoptions, char *prefix )
read_intarray(&cfgoptions[i],setting,cfgpath);
} else {
if( cfgoptions[i].defintarrayval != NULL) {
check_valptr(&(cfgoptions[i]),(char **)&(cfgoptions[i].iptr), sizeof(int32_t));
config_check_valptr(&(cfgoptions[i]),(char **)&(cfgoptions[i].iptr), sizeof(int32_t));
cfgoptions[i].iptr=cfgoptions[i].defintarrayval;
defvals++;
defval=1;
for (int j=0; j<cfgoptions[i].numelt ; j++) {
printf_params("[LIBCONFIG] %s[%i] set to default value %i\n", cfgpath,j,(int)cfgoptions[i].iptr[j]);