Merge remote-tracking branch 'origin/issue-389-fix-missing-option-value-not-reported' into develop_integration_2019_w03
This commit is contained in:
@@ -75,6 +75,7 @@ int processoption(paramdef_t *cfgoptions, char *value) {
|
|||||||
if ( value == NULL) {
|
if ( value == NULL) {
|
||||||
if( (cfgoptions->paramflags &PARAMFLAG_BOOL) == 0 ) { /* not a boolean, argument required */
|
if( (cfgoptions->paramflags &PARAMFLAG_BOOL) == 0 ) { /* not a boolean, argument required */
|
||||||
fprintf(stderr,"[CONFIG] command line, option %s requires an argument\n",cfgoptions->optname);
|
fprintf(stderr,"[CONFIG] command line, option %s requires an argument\n",cfgoptions->optname);
|
||||||
|
exit_fun("[CONFIG] command line parsing fatal error");
|
||||||
return 0;
|
return 0;
|
||||||
} else { /* boolean value option without argument, set value to true*/
|
} else { /* boolean value option without argument, set value to true*/
|
||||||
tmpval = defbool;
|
tmpval = defbool;
|
||||||
@@ -143,7 +144,10 @@ int processoption(paramdef_t *cfgoptions, char *value) {
|
|||||||
return optisset;
|
return optisset;
|
||||||
}
|
}
|
||||||
|
|
||||||
int config_check_cmdlineopt(char *prefix) {
|
/*--------------------------------------------------------------------*/
|
||||||
|
/* check unknown options in the command line
|
||||||
|
*/
|
||||||
|
int config_check_unknown_cmdlineopt(char *prefix) {
|
||||||
int unknowndetected=0;
|
int unknowndetected=0;
|
||||||
char testprefix[CONFIG_MAXOPTLENGTH]="";
|
char testprefix[CONFIG_MAXOPTLENGTH]="";
|
||||||
int finalcheck = 0;
|
int finalcheck = 0;
|
||||||
@@ -161,6 +165,8 @@ int config_check_cmdlineopt(char *prefix) {
|
|||||||
|
|
||||||
if ( !finalcheck && testprefix[0]==0 && index(config_get_if()->argv[i],'.') != NULL) continue;
|
if ( !finalcheck && testprefix[0]==0 && index(config_get_if()->argv[i],'.') != NULL) continue;
|
||||||
|
|
||||||
|
if ( !finalcheck && isdigit(config_get_if()->argv[i][0])) continue;
|
||||||
|
|
||||||
if ( !finalcheck && config_get_if()->argv[i][0] == '-' && isdigit(config_get_if()->argv[i][1])) continue;
|
if ( !finalcheck && config_get_if()->argv[i][0] == '-' && isdigit(config_get_if()->argv[i][1])) continue;
|
||||||
|
|
||||||
if ( (config_get_if()->argv_info[i] & CONFIG_CMDLINEOPT_PROCESSED) == 0 ) {
|
if ( (config_get_if()->argv_info[i] & CONFIG_CMDLINEOPT_PROCESSED) == 0 ) {
|
||||||
@@ -173,7 +179,7 @@ int config_check_cmdlineopt(char *prefix) {
|
|||||||
printf_cmdl("[CONFIG] %i unknown option(s) in command line starting with %s (section %s)\n",
|
printf_cmdl("[CONFIG] %i unknown option(s) in command line starting with %s (section %s)\n",
|
||||||
unknowndetected,testprefix,((prefix==NULL)?"":prefix));
|
unknowndetected,testprefix,((prefix==NULL)?"":prefix));
|
||||||
return unknowndetected;
|
return unknowndetected;
|
||||||
} /* parse_cmdline*/
|
} /* config_check_unknown_cmdlineopt */
|
||||||
|
|
||||||
int config_process_cmdline(paramdef_t *cfgoptions,int numoptions, char *prefix) {
|
int config_process_cmdline(paramdef_t *cfgoptions,int numoptions, char *prefix) {
|
||||||
int c = config_get_if()->argc;
|
int c = config_get_if()->argc;
|
||||||
@@ -269,7 +275,7 @@ int config_process_cmdline(paramdef_t *cfgoptions,int numoptions, char *prefix)
|
|||||||
printf_cmdl("[CONFIG] %s %i options set from command line\n",((prefix == NULL) ? "(root)":prefix),j);
|
printf_cmdl("[CONFIG] %s %i options set from command line\n",((prefix == NULL) ? "(root)":prefix),j);
|
||||||
|
|
||||||
if ( !(CONFIG_ISFLAGSET( CONFIG_NOCHECKUNKOPT )) ) {
|
if ( !(CONFIG_ISFLAGSET( CONFIG_NOCHECKUNKOPT )) ) {
|
||||||
i=config_check_cmdlineopt(prefix);
|
i=config_check_unknown_cmdlineopt(prefix);
|
||||||
|
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
fprintf(stderr,"[CONFIG] %i unknown options for section %s detected in command line\n",
|
fprintf(stderr,"[CONFIG] %i unknown options for section %s detected in command line\n",
|
||||||
|
|||||||
@@ -370,6 +370,12 @@ int config_checkstr_assign_integer(paramdef_t *param) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void config_set_checkfunctions(paramdef_t *params, checkedparam_t *checkfunctions, int numparams) {
|
||||||
|
for (int i=0; i< numparams ; i++ ) {
|
||||||
|
params[i].chkPptr = &(checkfunctions[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int config_setdefault_string(paramdef_t *cfgoptions, char *prefix) {
|
int config_setdefault_string(paramdef_t *cfgoptions, char *prefix) {
|
||||||
int status = 0;
|
int status = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -57,10 +57,13 @@ extern int config_assign_ipv4addr(paramdef_t *cfgoptions, char *ipv4addr);
|
|||||||
|
|
||||||
/* apis to get/check parameters, to be used by oai modules, at configuration time */
|
/* apis to get/check parameters, to be used by oai modules, at configuration time */
|
||||||
#define CONFIG_CHECKALLSECTIONS "ALLSECTIONS"
|
#define CONFIG_CHECKALLSECTIONS "ALLSECTIONS"
|
||||||
extern int config_check_cmdlineopt(char *prefix);
|
extern int config_check_unknown_cmdlineopt(char *prefix);
|
||||||
extern int config_get(paramdef_t *params,int numparams, char *prefix);
|
extern int config_get(paramdef_t *params,int numparams, char *prefix);
|
||||||
extern int config_getlist(paramlist_def_t *ParamList, paramdef_t *params, int numparams, char *prefix);
|
extern int config_getlist(paramlist_def_t *ParamList, paramdef_t *params, int numparams, char *prefix);
|
||||||
|
|
||||||
|
/* apis to set some of the paramdef_t fields before using the get/getlist api's */
|
||||||
|
extern void config_set_checkfunctions(paramdef_t *params, checkedparam_t *checkfunctions, int numparams);
|
||||||
|
|
||||||
/* apis to retrieve parameters info after calling get or getlist functions */
|
/* apis to retrieve parameters info after calling get or getlist functions */
|
||||||
extern int config_isparamset(paramdef_t *params,int paramidx);
|
extern int config_isparamset(paramdef_t *params,int paramidx);
|
||||||
extern int config_get_processedint(paramdef_t *cfgoption);
|
extern int config_get_processedint(paramdef_t *cfgoption);
|
||||||
|
|||||||
@@ -42,60 +42,60 @@
|
|||||||
#include "errno.h"
|
#include "errno.h"
|
||||||
|
|
||||||
#if ( LIBCONFIG_VER_MAJOR == 1 && LIBCONFIG_VER_MINOR < 5)
|
#if ( LIBCONFIG_VER_MAJOR == 1 && LIBCONFIG_VER_MINOR < 5)
|
||||||
#define config_setting_lookup config_lookup_from
|
#define config_setting_lookup config_lookup_from
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void config_libconfig_end(void );
|
void config_libconfig_end(void );
|
||||||
|
|
||||||
int read_strlist(paramdef_t *cfgoptions,config_setting_t *setting, char *cfgpath)
|
int read_strlist(paramdef_t *cfgoptions,config_setting_t *setting, char *cfgpath) {
|
||||||
{
|
const char *str;
|
||||||
const char *str;
|
int st;
|
||||||
int st;
|
int numelt;
|
||||||
int numelt;
|
numelt=config_setting_length(setting);
|
||||||
|
config_check_valptr(cfgoptions,(char **)&(cfgoptions->strlistptr), sizeof(char *) * numelt);
|
||||||
|
st=0;
|
||||||
|
|
||||||
numelt=config_setting_length(setting);
|
for (int i=0; i< numelt ; i++) {
|
||||||
config_check_valptr(cfgoptions,(char **)&(cfgoptions->strlistptr), sizeof(char *) * numelt);
|
str=config_setting_get_string_elem(setting,i);
|
||||||
st=0;
|
|
||||||
for (int i=0; i< numelt ; i++) {
|
if (str==NULL) {
|
||||||
str=config_setting_get_string_elem(setting,i);
|
printf("[LIBCONFIG] %s%i not found in config file\n", cfgoptions->optname,i);
|
||||||
if (str==NULL) {
|
} else {
|
||||||
printf("[LIBCONFIG] %s%i not found in config file\n", cfgoptions->optname,i);
|
config_check_valptr(cfgoptions,&(cfgoptions->strlistptr[i]),strlen(str)+1);
|
||||||
} else {
|
sprintf(cfgoptions->strlistptr[i],"%s",str);
|
||||||
config_check_valptr(cfgoptions,&(cfgoptions->strlistptr[i]),strlen(str)+1);
|
st++;
|
||||||
sprintf(cfgoptions->strlistptr[i],"%s",str);
|
printf_params("[LIBCONFIG] %s%i: %s\n", cfgpath,i,cfgoptions->strlistptr[i]);
|
||||||
st++;
|
}
|
||||||
printf_params("[LIBCONFIG] %s%i: %s\n", cfgpath,i,cfgoptions->strlistptr[i]);
|
}
|
||||||
}
|
|
||||||
}
|
cfgoptions->numelt=numelt;
|
||||||
cfgoptions->numelt=numelt;
|
return st;
|
||||||
return st;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int read_intarray(paramdef_t *cfgoptions,config_setting_t *setting, char *cfgpath)
|
int read_intarray(paramdef_t *cfgoptions,config_setting_t *setting, char *cfgpath) {
|
||||||
{
|
cfgoptions->numelt=config_setting_length(setting);
|
||||||
|
|
||||||
cfgoptions->numelt=config_setting_length(setting);
|
if (cfgoptions->numelt > 0) {
|
||||||
|
cfgoptions->iptr=malloc(sizeof(int) * (cfgoptions->numelt));
|
||||||
if (cfgoptions->numelt > 0) {
|
|
||||||
cfgoptions->iptr=malloc(sizeof(int) * (cfgoptions->numelt));
|
for (int i=0; i< cfgoptions->numelt && cfgoptions->iptr != NULL; i++) {
|
||||||
for (int i=0; i< cfgoptions->numelt && cfgoptions->iptr != NULL; i++) {
|
cfgoptions->iptr[i]=config_setting_get_int_elem(setting,i);
|
||||||
cfgoptions->iptr[i]=config_setting_get_int_elem(setting,i);
|
printf_params("[LIBCONFIG] %s[%i]: %i\n", cfgpath,i,cfgoptions->iptr[i]);
|
||||||
printf_params("[LIBCONFIG] %s[%i]: %i\n", cfgpath,i,cfgoptions->iptr[i]);
|
} /* for loop on array element... */
|
||||||
} /* for loop on array element... */
|
}
|
||||||
}
|
|
||||||
return cfgoptions->numelt;
|
return cfgoptions->numelt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int config_libconfig_get(paramdef_t *cfgoptions,int numoptions, char *prefix )
|
int config_libconfig_get(paramdef_t *cfgoptions,int numoptions, char *prefix ) {
|
||||||
{
|
|
||||||
config_setting_t *setting;
|
config_setting_t *setting;
|
||||||
char *str;
|
char *str;
|
||||||
int i,u;
|
int i,u;
|
||||||
long long int llu;
|
long long int llu;
|
||||||
double dbl;
|
double dbl;
|
||||||
int rst;
|
int rst;
|
||||||
int status=0;
|
int status=0;
|
||||||
int notfound;
|
int notfound;
|
||||||
@@ -104,211 +104,244 @@ int config_libconfig_get(paramdef_t *cfgoptions,int numoptions, char *prefix )
|
|||||||
int numdefvals=0;
|
int numdefvals=0;
|
||||||
char cfgpath[512]; /* 512 should be enough for the sprintf below */
|
char cfgpath[512]; /* 512 should be enough for the sprintf below */
|
||||||
|
|
||||||
for(i=0;i<numoptions;i++) {
|
for(i=0; i<numoptions; i++) {
|
||||||
|
if (prefix != NULL) {
|
||||||
|
sprintf(cfgpath,"%s.%s",prefix,cfgoptions[i].optname);
|
||||||
|
} else {
|
||||||
|
sprintf(cfgpath,"%s",cfgoptions[i].optname);
|
||||||
|
}
|
||||||
|
|
||||||
if (prefix != NULL) {
|
if( (cfgoptions->paramflags & PARAMFLAG_DONOTREAD) != 0) {
|
||||||
sprintf(cfgpath,"%s.%s",prefix,cfgoptions[i].optname);
|
printf_params("[LIBCONFIG] %s.%s ignored\n", cfgpath,cfgoptions[i].optname );
|
||||||
} else {
|
continue;
|
||||||
sprintf(cfgpath,"%s",cfgoptions[i].optname);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if( (cfgoptions->paramflags & PARAMFLAG_DONOTREAD) != 0) {
|
notfound=0;
|
||||||
printf_params("[LIBCONFIG] %s.%s ignored\n", cfgpath,cfgoptions[i].optname );
|
defval=0;
|
||||||
continue;
|
|
||||||
}
|
switch(cfgoptions[i].type) {
|
||||||
notfound=0;
|
case TYPE_STRING:
|
||||||
defval=0;
|
if ( config_lookup_string(&(libconfig_privdata.cfg),cfgpath, (const char **)&str)) {
|
||||||
switch(cfgoptions[i].type)
|
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",
|
||||||
case TYPE_STRING:
|
cfgpath,str,cfgoptions[i].numelt);
|
||||||
if ( config_lookup_string(&(libconfig_privdata.cfg),cfgpath, (const char **)&str)) {
|
str[strlen(str)-1] = 0;
|
||||||
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);
|
if (cfgoptions[i].numelt == 0 ) {
|
||||||
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);
|
||||||
if (cfgoptions[i].numelt == 0 ) {
|
sprintf( *(cfgoptions[i].strptr) , "%s", str);
|
||||||
// config_check_valptr(&(cfgoptions[i]), (char **)(&(cfgoptions[i].strptr)), sizeof(char *));
|
printf_params("[LIBCONFIG] %s: \"%s\"\n", cfgpath,*(cfgoptions[i].strptr) );
|
||||||
config_check_valptr(&(cfgoptions[i]), cfgoptions[i].strptr, strlen(str)+1);
|
} else {
|
||||||
sprintf( *(cfgoptions[i].strptr) , "%s", str);
|
sprintf( (char *)(cfgoptions[i].strptr) , "%s", str);
|
||||||
printf_params("[LIBCONFIG] %s: \"%s\"\n", cfgpath,*(cfgoptions[i].strptr) );
|
printf_params("[LIBCONFIG] %s: \"%s\"\n", cfgpath,(char *)cfgoptions[i].strptr );
|
||||||
} else {
|
}
|
||||||
sprintf( (char *)(cfgoptions[i].strptr) , "%s", str);
|
|
||||||
printf_params("[LIBCONFIG] %s: \"%s\"\n", cfgpath,(char *)cfgoptions[i].strptr );
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
defval=config_setdefault_string(&(cfgoptions[i]),prefix);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case TYPE_STRINGLIST:
|
|
||||||
setting = config_setting_lookup (config_root_setting(&(libconfig_privdata.cfg)),cfgpath );
|
|
||||||
if ( setting != NULL) {
|
|
||||||
read_strlist(&cfgoptions[i],setting,cfgpath);
|
|
||||||
} else {
|
|
||||||
defval=config_setdefault_stringlist(&(cfgoptions[i]),prefix);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case TYPE_UINT8:
|
|
||||||
case TYPE_INT8:
|
|
||||||
case TYPE_UINT16:
|
|
||||||
case TYPE_INT16:
|
|
||||||
case TYPE_UINT32:
|
|
||||||
case TYPE_INT32:
|
|
||||||
case TYPE_MASK:
|
|
||||||
if ( config_lookup_int(&(libconfig_privdata.cfg),cfgpath, &u)) {
|
|
||||||
config_check_valptr(&(cfgoptions[i]), (char **)(&(cfgoptions[i].iptr)),sizeof(int32_t));
|
|
||||||
config_assign_int(&(cfgoptions[i]),cfgpath,u);
|
|
||||||
} else {
|
|
||||||
defval=config_setdefault_int(&(cfgoptions[i]),prefix);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case TYPE_UINT64:
|
|
||||||
case TYPE_INT64:
|
|
||||||
if ( config_lookup_int64(&(libconfig_privdata.cfg),cfgpath, &llu)) {
|
|
||||||
config_check_valptr(&(cfgoptions[i]), (char **)&(cfgoptions[i].i64ptr),sizeof(long long));
|
|
||||||
if(cfgoptions[i].type==TYPE_UINT64) {
|
|
||||||
*(cfgoptions[i].u64ptr) = (uint64_t)llu;
|
|
||||||
printf_params("[LIBCONFIG] %s: %llu\n", cfgpath,(long long unsigned)(*(cfgoptions[i].u64ptr)) );
|
|
||||||
} else {
|
|
||||||
*(cfgoptions[i].iptr) = llu;
|
|
||||||
printf_params("[LIBCONFIG] %s: %lli\n", cfgpath,(long long unsigned)(*(cfgoptions[i].i64ptr)) );
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
defval=config_setdefault_int64(&(cfgoptions[i]),prefix);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case TYPE_UINTARRAY:
|
|
||||||
case TYPE_INTARRAY:
|
|
||||||
setting = config_setting_lookup (config_root_setting(&(libconfig_privdata.cfg)),cfgpath );
|
|
||||||
if ( setting != NULL) {
|
|
||||||
read_intarray(&cfgoptions[i],setting,cfgpath);
|
|
||||||
} else {
|
|
||||||
defval=config_setdefault_intlist(&(cfgoptions[i]),prefix);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case TYPE_DOUBLE:
|
|
||||||
if ( config_lookup_float(&(libconfig_privdata.cfg),cfgpath, &dbl)) {
|
|
||||||
config_check_valptr(&(cfgoptions[i]), (char **)&(cfgoptions[i].dblptr),sizeof(double));
|
|
||||||
*(cfgoptions[i].dblptr) = dbl;
|
|
||||||
printf_params("[LIBCONFIG] %s: %lf\n", cfgpath,*(cfgoptions[i].dblptr) );
|
|
||||||
} else {
|
|
||||||
defval=config_setdefault_double(&(cfgoptions[i]),prefix);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case TYPE_IPV4ADDR:
|
|
||||||
if ( !config_lookup_string(&(libconfig_privdata.cfg),cfgpath, (const char **)&str)) {
|
|
||||||
defval=config_setdefault_ipv4addr(&(cfgoptions[i]),prefix);
|
|
||||||
} else {
|
|
||||||
rst=config_assign_ipv4addr(cfgoptions, str);
|
|
||||||
if (rst < 0) {
|
|
||||||
fprintf(stderr,"[LIBCONFIG] %s not valid for %s \n", str, cfgpath);
|
|
||||||
fatalerror=1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case TYPE_LIST:
|
|
||||||
setting = config_setting_lookup (config_root_setting(&(libconfig_privdata.cfg)),cfgpath );
|
|
||||||
if ( setting) {
|
|
||||||
cfgoptions[i].numelt=config_setting_length(setting);
|
|
||||||
} else {
|
|
||||||
notfound=1;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
fprintf(stderr,"[LIBCONFIG] %s type %i not supported\n", cfgpath,cfgoptions[i].type);
|
|
||||||
fatalerror=1;
|
|
||||||
break;
|
|
||||||
} /* switch on param type */
|
|
||||||
if( notfound == 1) {
|
|
||||||
printf("[LIBCONFIG] %s not found in %s ", cfgpath,libconfig_privdata.configfile );
|
|
||||||
if ( (cfgoptions[i].paramflags & PARAMFLAG_MANDATORY) != 0) {
|
|
||||||
fatalerror=1;
|
|
||||||
printf(" mandatory parameter missing\n");
|
|
||||||
} else {
|
} else {
|
||||||
printf("\n");
|
defval=config_setdefault_string(&(cfgoptions[i]),prefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TYPE_STRINGLIST:
|
||||||
|
setting = config_setting_lookup (config_root_setting(&(libconfig_privdata.cfg)),cfgpath );
|
||||||
|
|
||||||
|
if ( setting != NULL) {
|
||||||
|
read_strlist(&cfgoptions[i],setting,cfgpath);
|
||||||
|
} else {
|
||||||
|
defval=config_setdefault_stringlist(&(cfgoptions[i]),prefix);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TYPE_UINT8:
|
||||||
|
case TYPE_INT8:
|
||||||
|
case TYPE_UINT16:
|
||||||
|
case TYPE_INT16:
|
||||||
|
case TYPE_UINT32:
|
||||||
|
case TYPE_INT32:
|
||||||
|
case TYPE_MASK:
|
||||||
|
if ( config_lookup_int(&(libconfig_privdata.cfg),cfgpath, &u)) {
|
||||||
|
config_check_valptr(&(cfgoptions[i]), (char **)(&(cfgoptions[i].iptr)),sizeof(int32_t));
|
||||||
|
config_assign_int(&(cfgoptions[i]),cfgpath,u);
|
||||||
|
} else {
|
||||||
|
defval=config_setdefault_int(&(cfgoptions[i]),prefix);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TYPE_UINT64:
|
||||||
|
case TYPE_INT64:
|
||||||
|
if ( config_lookup_int64(&(libconfig_privdata.cfg),cfgpath, &llu)) {
|
||||||
|
config_check_valptr(&(cfgoptions[i]), (char **)&(cfgoptions[i].i64ptr),sizeof(long long));
|
||||||
|
|
||||||
|
if(cfgoptions[i].type==TYPE_UINT64) {
|
||||||
|
*(cfgoptions[i].u64ptr) = (uint64_t)llu;
|
||||||
|
printf_params("[LIBCONFIG] %s: %llu\n", cfgpath,(long long unsigned)(*(cfgoptions[i].u64ptr)) );
|
||||||
|
} else {
|
||||||
|
*(cfgoptions[i].iptr) = llu;
|
||||||
|
printf_params("[LIBCONFIG] %s: %llu\n", cfgpath,(long long unsigned)(*(cfgoptions[i].i64ptr)) );
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
defval=config_setdefault_int64(&(cfgoptions[i]),prefix);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TYPE_UINTARRAY:
|
||||||
|
case TYPE_INTARRAY:
|
||||||
|
setting = config_setting_lookup (config_root_setting(&(libconfig_privdata.cfg)),cfgpath );
|
||||||
|
|
||||||
|
if ( setting != NULL) {
|
||||||
|
read_intarray(&cfgoptions[i],setting,cfgpath);
|
||||||
|
} else {
|
||||||
|
defval=config_setdefault_intlist(&(cfgoptions[i]),prefix);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TYPE_DOUBLE:
|
||||||
|
if ( config_lookup_float(&(libconfig_privdata.cfg),cfgpath, &dbl)) {
|
||||||
|
config_check_valptr(&(cfgoptions[i]), (char **)&(cfgoptions[i].dblptr),sizeof(double));
|
||||||
|
*(cfgoptions[i].dblptr) = dbl;
|
||||||
|
printf_params("[LIBCONFIG] %s: %lf\n", cfgpath,*(cfgoptions[i].dblptr) );
|
||||||
|
} else {
|
||||||
|
defval=config_setdefault_double(&(cfgoptions[i]),prefix);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TYPE_IPV4ADDR:
|
||||||
|
if ( !config_lookup_string(&(libconfig_privdata.cfg),cfgpath, (const char **)&str)) {
|
||||||
|
defval=config_setdefault_ipv4addr(&(cfgoptions[i]),prefix);
|
||||||
|
} else {
|
||||||
|
rst=config_assign_ipv4addr(cfgoptions, str);
|
||||||
|
|
||||||
|
if (rst < 0) {
|
||||||
|
fprintf(stderr,"[LIBCONFIG] %s not valid for %s \n", str, cfgpath);
|
||||||
|
fatalerror=1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TYPE_LIST:
|
||||||
|
setting = config_setting_lookup (config_root_setting(&(libconfig_privdata.cfg)),cfgpath );
|
||||||
|
|
||||||
|
if ( setting) {
|
||||||
|
cfgoptions[i].numelt=config_setting_length(setting);
|
||||||
|
} else {
|
||||||
|
notfound=1;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
fprintf(stderr,"[LIBCONFIG] %s type %i not supported\n", cfgpath,cfgoptions[i].type);
|
||||||
|
fatalerror=1;
|
||||||
|
break;
|
||||||
|
} /* switch on param type */
|
||||||
|
|
||||||
|
if( notfound == 1) {
|
||||||
|
printf("[LIBCONFIG] %s not found in %s ", cfgpath,libconfig_privdata.configfile );
|
||||||
|
|
||||||
|
if ( (cfgoptions[i].paramflags & PARAMFLAG_MANDATORY) != 0) {
|
||||||
|
fatalerror=1;
|
||||||
|
printf(" mandatory parameter missing\n");
|
||||||
|
} else {
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (defval == 1) {
|
if (defval == 1) {
|
||||||
numdefvals++;
|
numdefvals++;
|
||||||
cfgoptions[i].paramflags = cfgoptions[i].paramflags | PARAMFLAG_PARAMSETDEF;
|
cfgoptions[i].paramflags = cfgoptions[i].paramflags | PARAMFLAG_PARAMSETDEF;
|
||||||
} else {
|
} else {
|
||||||
cfgoptions[i].paramflags = cfgoptions[i].paramflags | PARAMFLAG_PARAMSET;
|
cfgoptions[i].paramflags = cfgoptions[i].paramflags | PARAMFLAG_PARAMSET;
|
||||||
}
|
}
|
||||||
|
|
||||||
status++;
|
status++;
|
||||||
}
|
}
|
||||||
} /* for loop on options */
|
} /* for loop on options */
|
||||||
|
|
||||||
printf("[LIBCONFIG] %s: %i/%i parameters successfully set, (%i to default value)\n",
|
printf("[LIBCONFIG] %s: %i/%i parameters successfully set, (%i to default value)\n",
|
||||||
((prefix == NULL)?"(root)":prefix),
|
((prefix == NULL)?"(root)":prefix),
|
||||||
status,numoptions,numdefvals );
|
status,numoptions,numdefvals );
|
||||||
|
|
||||||
if (fatalerror == 1) {
|
if (fatalerror == 1) {
|
||||||
fprintf(stderr,"[LIBCONFIG] fatal errors found when processing %s \n", libconfig_privdata.configfile );
|
fprintf(stderr,"[LIBCONFIG] fatal errors found when processing %s \n", libconfig_privdata.configfile );
|
||||||
config_libconfig_end();
|
config_libconfig_end();
|
||||||
end_configmodule();
|
end_configmodule();
|
||||||
}
|
}
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
int config_libconfig_getlist(paramlist_def_t *ParamList,
|
int config_libconfig_getlist(paramlist_def_t *ParamList,
|
||||||
paramdef_t *params, int numparams, char *prefix)
|
paramdef_t *params, int numparams, char *prefix) {
|
||||||
{
|
config_setting_t *setting;
|
||||||
config_setting_t *setting;
|
int i,j,status;
|
||||||
int i,j,status;
|
char *listpath=NULL;
|
||||||
char *listpath=NULL;
|
char cfgpath[MAX_OPTNAME_SIZE*2 + 6]; /* prefix.listname.[listindex] */
|
||||||
char cfgpath[MAX_OPTNAME_SIZE*2 + 6]; /* prefix.listname.[listindex] */
|
|
||||||
|
|
||||||
if (prefix != NULL)
|
if (prefix != NULL) {
|
||||||
{
|
i=asprintf(&listpath ,"%s.%s",prefix,ParamList->listname);
|
||||||
i=asprintf(&listpath ,"%s.%s",prefix,ParamList->listname);
|
} else {
|
||||||
}
|
i=asprintf(&listpath ,"%s",ParamList->listname);
|
||||||
else
|
}
|
||||||
{
|
|
||||||
i=asprintf(&listpath ,"%s",ParamList->listname);
|
setting = config_lookup(&(libconfig_privdata.cfg), listpath);
|
||||||
}
|
|
||||||
setting = config_lookup(&(libconfig_privdata.cfg), listpath);
|
if ( setting) {
|
||||||
if ( setting) {
|
status = ParamList->numelt = config_setting_length(setting);
|
||||||
status = ParamList->numelt = config_setting_length(setting);
|
printf_params("[LIBCONFIG] %i %s in config file %s \n",
|
||||||
printf_params("[LIBCONFIG] %i %s in config file %s \n",
|
ParamList->numelt,listpath,libconfig_privdata.configfile );
|
||||||
ParamList->numelt,listpath,libconfig_privdata.configfile );
|
} else {
|
||||||
|
printf("[LIBCONFIG] list %s not found in config file %s \n",
|
||||||
|
listpath,libconfig_privdata.configfile );
|
||||||
|
ParamList->numelt= 0;
|
||||||
|
status = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ParamList->numelt > 0 && params != NULL) {
|
||||||
|
ParamList->paramarray = malloc(ParamList->numelt * sizeof(paramdef_t *));
|
||||||
|
|
||||||
|
if ( ParamList->paramarray != NULL) {
|
||||||
|
config_get_if()->ptrs[config_get_if()->numptrs] = (char *)(ParamList->paramarray);
|
||||||
|
config_get_if()->numptrs++;
|
||||||
} else {
|
} else {
|
||||||
printf("[LIBCONFIG] list %s not found in config file %s \n",
|
fprintf (stderr,"[LIBCONFIG] %s %d malloc error\n",__FILE__, __LINE__);
|
||||||
listpath,libconfig_privdata.configfile );
|
exit(-1);
|
||||||
ParamList->numelt= 0;
|
|
||||||
status = -1;
|
|
||||||
}
|
}
|
||||||
if (ParamList->numelt > 0 && params != NULL) {
|
|
||||||
ParamList->paramarray = malloc(ParamList->numelt * sizeof(paramdef_t *));
|
for (i=0 ; i < ParamList->numelt ; i++) {
|
||||||
if ( ParamList->paramarray != NULL) {
|
ParamList->paramarray[i] = malloc(numparams * sizeof(paramdef_t));
|
||||||
config_get_if()->ptrs[config_get_if()->numptrs] = (char *)(ParamList->paramarray);
|
|
||||||
config_get_if()->numptrs++;
|
if ( ParamList->paramarray[i] != NULL) {
|
||||||
} else {
|
config_get_if()->ptrs[config_get_if()->numptrs] = (char *)(ParamList->paramarray[i]);
|
||||||
fprintf (stderr,"[LIBCONFIG] %s %d malloc error\n",__FILE__, __LINE__);
|
config_get_if()->numptrs++;
|
||||||
exit(-1);
|
} else {
|
||||||
}
|
fprintf (stderr,"[LIBCONFIG] %s %d malloc error\n",__FILE__, __LINE__);
|
||||||
for (i=0 ; i < ParamList->numelt ; i++) {
|
exit(-1);
|
||||||
ParamList->paramarray[i] = malloc(numparams * sizeof(paramdef_t));
|
}
|
||||||
if ( ParamList->paramarray[i] != NULL) {
|
|
||||||
config_get_if()->ptrs[config_get_if()->numptrs] = (char *)(ParamList->paramarray[i]);
|
memcpy(ParamList->paramarray[i], params, sizeof(paramdef_t)*numparams);
|
||||||
config_get_if()->numptrs++;
|
|
||||||
} else {
|
for (j=0; j<numparams; j++) {
|
||||||
fprintf (stderr,"[LIBCONFIG] %s %d malloc error\n",__FILE__, __LINE__);
|
ParamList->paramarray[i][j].strptr = NULL ;
|
||||||
exit(-1);
|
}
|
||||||
}
|
|
||||||
|
sprintf(cfgpath,"%s.[%i]",listpath,i);
|
||||||
memcpy(ParamList->paramarray[i], params, sizeof(paramdef_t)*numparams);
|
config_libconfig_get(ParamList->paramarray[i], numparams, cfgpath );
|
||||||
for (j=0;j<numparams;j++) {
|
} /* for i... */
|
||||||
ParamList->paramarray[i][j].strptr = NULL ;
|
} /* ParamList->numelt > 0 && params != NULL */
|
||||||
}
|
|
||||||
sprintf(cfgpath,"%s.[%i]",listpath,i);
|
if (listpath != NULL)
|
||||||
config_libconfig_get(ParamList->paramarray[i], numparams, cfgpath );
|
free(listpath);
|
||||||
} /* for i... */
|
|
||||||
} /* ParamList->numelt > 0 && params != NULL */
|
return status;
|
||||||
if (listpath != NULL)
|
|
||||||
free(listpath);
|
|
||||||
return status;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int config_libconfig_init(char *cfgP[], int numP)
|
int config_libconfig_init(char *cfgP[], int numP) {
|
||||||
{
|
|
||||||
config_init(&(libconfig_privdata.cfg));
|
config_init(&(libconfig_privdata.cfg));
|
||||||
libconfig_privdata.configfile = strdup((char *)cfgP[0]);
|
libconfig_privdata.configfile = strdup((char *)cfgP[0]);
|
||||||
config_get_if()->numptrs=0;
|
config_get_if()->numptrs=0;
|
||||||
@@ -317,24 +350,22 @@ int config_libconfig_init(char *cfgP[], int numP)
|
|||||||
/* Read the file. If there is an error, report it and exit. */
|
/* Read the file. If there is an error, report it and exit. */
|
||||||
if(! config_read_file(&(libconfig_privdata.cfg), libconfig_privdata.configfile)) {
|
if(! config_read_file(&(libconfig_privdata.cfg), libconfig_privdata.configfile)) {
|
||||||
fprintf(stderr,"[LIBCONFIG] %s %d file %s - %d - %s\n",__FILE__, __LINE__,
|
fprintf(stderr,"[LIBCONFIG] %s %d file %s - %d - %s\n",__FILE__, __LINE__,
|
||||||
libconfig_privdata.configfile, config_error_line(&(libconfig_privdata.cfg)),
|
libconfig_privdata.configfile, config_error_line(&(libconfig_privdata.cfg)),
|
||||||
config_error_text(&(libconfig_privdata.cfg)));
|
config_error_text(&(libconfig_privdata.cfg)));
|
||||||
config_destroy(&(libconfig_privdata.cfg));
|
config_destroy(&(libconfig_privdata.cfg));
|
||||||
printf( "\n");
|
printf( "\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void config_libconfig_end(void )
|
void config_libconfig_end(void ) {
|
||||||
{
|
|
||||||
config_destroy(&(libconfig_privdata.cfg));
|
config_destroy(&(libconfig_privdata.cfg));
|
||||||
|
|
||||||
if ( libconfig_privdata.configfile != NULL ) {
|
if ( libconfig_privdata.configfile != NULL ) {
|
||||||
free(libconfig_privdata.configfile);
|
free(libconfig_privdata.configfile);
|
||||||
libconfig_privdata.configfile=NULL;
|
libconfig_privdata.configfile=NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -689,7 +689,7 @@ int main( int argc, char **argv ) {
|
|||||||
#if T_TRACER
|
#if T_TRACER
|
||||||
T_Config_Init();
|
T_Config_Init();
|
||||||
#endif
|
#endif
|
||||||
ret=config_check_cmdlineopt(NULL);
|
ret=config_check_unknown_cmdlineopt(NULL);
|
||||||
|
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
LOG_E(ENB_APP, "%i unknown options in command line\n",ret);
|
LOG_E(ENB_APP, "%i unknown options in command line\n",ret);
|
||||||
@@ -938,7 +938,7 @@ int main( int argc, char **argv ) {
|
|||||||
sync_var=0;
|
sync_var=0;
|
||||||
pthread_cond_broadcast(&sync_cond);
|
pthread_cond_broadcast(&sync_cond);
|
||||||
pthread_mutex_unlock(&sync_mutex);
|
pthread_mutex_unlock(&sync_mutex);
|
||||||
ret=config_check_cmdlineopt(CONFIG_CHECKALLSECTIONS);
|
ret=config_check_unknown_cmdlineopt(CONFIG_CHECKALLSECTIONS);
|
||||||
|
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
LOG_E(ENB_APP, "%i unknown options in command line (invalid section name)\n",ret);
|
LOG_E(ENB_APP, "%i unknown options in command line (invalid section name)\n",ret);
|
||||||
|
|||||||
@@ -1010,7 +1010,7 @@ int main( int argc, char **argv ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
ret=config_check_cmdlineopt(CONFIG_CHECKALLSECTIONS);
|
ret=config_check_unknown_cmdlineopt(CONFIG_CHECKALLSECTIONS);
|
||||||
|
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
LOG_E(ENB_APP, "%i unknown options in command line (invalid section name)\n",ret);
|
LOG_E(ENB_APP, "%i unknown options in command line (invalid section name)\n",ret);
|
||||||
|
|||||||
Reference in New Issue
Block a user