On 2020-12-05 at 02:02, DanielP. Berrangé wrote:
On Fri, Sep 04, 2020 at 11:34:57AM +0800, Shi Lei wrote:
> Signed-off-by: Shi Lei <shi_lei(a)massclouds.com>
> ---
> src/libvirt_private.syms | 3 +++
> src/util/virstring.c | 57 ++++++++++++++++++++++++++++++++++++++++
> src/util/virstring.h | 9 +++++++
> 3 files changed, 69 insertions(+)
>
> diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
> index 191eab0..4ad9d1e 100644
> --- a/src/libvirt_private.syms
> +++ b/src/libvirt_private.syms
> @@ -3242,6 +3242,7 @@ virStringStripSuffix;
> virStringToUpper;
> virStringTrimOptionalNewline;
> virStrncpy;
> +virStrToBool;
> virStrToDouble;
> virStrToLong_i;
> virStrToLong_l;
> @@ -3252,6 +3253,8 @@ virStrToLong_ul;
> virStrToLong_ull;
> virStrToLong_ullp;
> virStrToLong_ulp;
> +virStrToTime;
> +virTimeFormatBuf;
> virTrimSpaces;
>
>
> diff --git a/src/util/virstring.c b/src/util/virstring.c
> index de2ef96..23ade40 100644
> --- a/src/util/virstring.c
> +++ b/src/util/virstring.c
> @@ -1349,3 +1349,60 @@ int virStringParseYesNo(const char *str, bool *result)
>
> return 0;
> }
> +
> +
> +int
> +virStrToBool(const char *str, const char *truevalue, bool *result)
> +{
> + if (STREQ(str, truevalue))
> + *result = true;
> + else
> + *result = false;
> +
> + return 0;
> +}
I'd suggest we should explicitly check both the true and false
values, and raise an error for any other value.
I think we probably ought to have wrappers for the pairs of words
we consider sane. eg virStrToBoolYesNo, virStrToBoolTrueFalse
and virStrToBoolOnOff I think are probably the only ones we want
to permit
Okay.
Shi Lei