conf: introduce SCConfGetNonNull

Ticket: 8651

Behaves like SCConfGet but returns 0 on null value
pull/15636/head
Philippe Antoine 2 months ago committed by Victor Julien
parent e0152178da
commit a9e1dff4a6

@ -262,6 +262,11 @@ extern "C" {
name: *const ::std::os::raw::c_char, vptr: *mut *const ::std::os::raw::c_char, name: *const ::std::os::raw::c_char, vptr: *mut *const ::std::os::raw::c_char,
) -> ::std::os::raw::c_int; ) -> ::std::os::raw::c_int;
} }
extern "C" {
pub fn SCConfGetNonNull(
name: *const ::std::os::raw::c_char, vptr: *mut *const ::std::os::raw::c_char,
) -> ::std::os::raw::c_int;
}
extern "C" { extern "C" {
pub fn SCConfGetInt( pub fn SCConfGetInt(
name: *const ::std::os::raw::c_char, val: *mut intmax_t, name: *const ::std::os::raw::c_char, val: *mut intmax_t,

@ -361,6 +361,30 @@ int SCConfGet(const char *name, const char **vptr)
} }
} }
/**
* \brief Retrieve the non-null value of a configuration node.
*
* This function will return the value for a configuration node based
* on the full name of the node. If the value were NULL, return 0
* (this could happen if the requested node does exist but is not a node
* that contains a value, but contains children SCConfNodes instead.)
*
* \param name Name of configuration parameter to get.
* \param vptr Pointer that will be set to the configuration value parameter.
* Note that this is just a reference to the actual value, not a copy.
*
* \retval 1 will be returned if the value is found, otherwise 0 will
* be returned.
*/
int SCConfGetNonNull(const char *name, const char **vptr)
{
int r = SCConfGet(name, vptr);
if (r == 1 && *vptr == NULL) {
return 0;
}
return r;
}
int SCConfGetChildValue(const SCConfNode *base, const char *name, const char **vptr) int SCConfGetChildValue(const SCConfNode *base, const char *name, const char **vptr)
{ {
SCConfNode *node = SCConfNodeLookupChild(base, name); SCConfNode *node = SCConfNodeLookupChild(base, name);
@ -500,7 +524,7 @@ int SCConfGetBool(const char *name, int *val)
const char *strval = NULL; const char *strval = NULL;
*val = 0; *val = 0;
if (SCConfGet(name, &strval) != 1) if (SCConfGetNonNull(name, &strval) != 1)
return 0; return 0;
*val = SCConfValIsTrue(strval); *val = SCConfValIsTrue(strval);
@ -604,7 +628,7 @@ int SCConfGetDouble(const char *name, double *val)
double tmpdo; double tmpdo;
char *endptr; char *endptr;
if (SCConfGet(name, &strval) == 0) if (SCConfGetNonNull(name, &strval) == 0)
return 0; return 0;
errno = 0; errno = 0;
@ -634,7 +658,7 @@ int SCConfGetFloat(const char *name, float *val)
double tmpfl; double tmpfl;
char *endptr; char *endptr;
if (SCConfGet(name, &strval) == 0) if (SCConfGetNonNull(name, &strval) == 0)
return 0; return 0;
errno = 0; errno = 0;

@ -63,6 +63,7 @@ void SCConfInit(void);
void SCConfDeInit(void); void SCConfDeInit(void);
SCConfNode *SCConfGetRootNode(void); SCConfNode *SCConfGetRootNode(void);
int SCConfGet(const char *name, const char **vptr); int SCConfGet(const char *name, const char **vptr);
int SCConfGetNonNull(const char *name, const char **vptr);
int SCConfGetInt(const char *name, intmax_t *val); int SCConfGetInt(const char *name, intmax_t *val);
int SCConfGetBool(const char *name, int *val); int SCConfGetBool(const char *name, int *val);
int SCConfGetDouble(const char *name, double *val); int SCConfGetDouble(const char *name, double *val);

Loading…
Cancel
Save