From nobody Wed May 14 19:25:29 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1527254855762804.1319958361698; Fri, 25 May 2018 06:27:35 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5206C329DB1; Fri, 25 May 2018 13:27:33 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B4C1591B8C; Fri, 25 May 2018 13:27:32 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id F253D180BA82; Fri, 25 May 2018 13:27:31 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4PDRQ2M023584 for ; Fri, 25 May 2018 09:27:27 -0400 Received: by smtp.corp.redhat.com (Postfix) id D33AB2023488; Fri, 25 May 2018 13:27:26 +0000 (UTC) Received: from pessoa.redhat.com (unknown [10.40.205.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id D33B62023487; Fri, 25 May 2018 13:27:25 +0000 (UTC) From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= To: libvir-list@redhat.com Date: Fri, 25 May 2018 15:27:16 +0200 Message-Id: <20180525132717.17628-3-fidencio@redhat.com> In-Reply-To: <20180525132717.17628-1-fidencio@redhat.com> References: <20180525132717.17628-1-fidencio@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Cc: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= , =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Subject: [libvirt] [PATCH 2/3] vmx: convert to typesafe virConf accessors X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 25 May 2018 13:27:34 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Signed-off-by: Fabiano Fid=C3=AAncio --- src/vmx/vmx.c | 197 +++++++++++++++++++------------------------------- 1 file changed, 73 insertions(+), 124 deletions(-) diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c index df6a58a47..6247fa938 100644 --- a/src/vmx/vmx.c +++ b/src/vmx/vmx.c @@ -719,42 +719,36 @@ virVMXConvertToUTF8(const char *encoding, const char = *string) return result; } =20 - - static int -virVMXGetConfigString(virConfPtr conf, const char *name, char **string, - bool optional) +virVMXGetConfigStringHelper(virConfPtr conf, const char *name, char **stri= ng, + bool optional) { - virConfValuePtr value; - + int result; *string =3D NULL; - value =3D virConfGetValue(conf, name); =20 - if (value =3D=3D NULL) { - if (optional) - return 0; + result =3D virConfGetValueString(conf, name, string); + if (result =3D=3D 1 && *string !=3D NULL) + return 1; =20 - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Missing essential config entry '%s'"), name); - return -1; - } + if (optional) + return 0; =20 - if (value->type !=3D VIR_CONF_STRING) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Config entry '%s' must be a string"), name); - return -1; - } + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Missing essential config entry '%s'"), name); + return -1; +} =20 - if (value->str =3D=3D NULL) { - if (optional) - return 0; =20 - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Missing essential config entry '%s'"), name); +static int +virVMXGetConfigString(virConfPtr conf, const char *name, char **string, + bool optional) +{ + *string =3D NULL; + + if (virVMXGetConfigStringHelper(conf, name, string, optional) < 0) return -1; - } =20 - return VIR_STRDUP(*string, value->str); + return 0; } =20 =20 @@ -763,43 +757,26 @@ static int virVMXGetConfigUUID(virConfPtr conf, const char *name, unsigned char *uuid, bool optional) { - virConfValuePtr value; + char *string =3D NULL; + int result; =20 - value =3D virConfGetValue(conf, name); + result =3D virVMXGetConfigStringHelper(conf, name, &string, optional); + if (result <=3D 0) + return result; =20 - if (value =3D=3D NULL) { - if (optional) { - return 0; - } else { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Missing essential config entry '%s'"), name); - return -1; - } - } - - if (value->type !=3D VIR_CONF_STRING) { + if (virUUIDParse(string, uuid) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("Config entry '%s' must be a string"), name); - return -1; + _("Could not parse UUID from string '%s'"), string); + result =3D -1; + goto cleanup; } =20 - if (value->str =3D=3D NULL) { - if (optional) { - return 0; - } else { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Missing essential config entry '%s'"), name); - return -1; - } - } + result =3D 0; =20 - if (virUUIDParse(value->str, uuid) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Could not parse UUID from string '%s'"), value->= str); - return -1; - } + cleanup: + VIR_FREE(string); =20 - return 0; + return result; } =20 =20 @@ -808,47 +785,35 @@ static int virVMXGetConfigLong(virConfPtr conf, const char *name, long long *number, long long default_, bool optional) { - virConfValuePtr value; + char *string =3D NULL; + int result; =20 *number =3D default_; - value =3D virConfGetValue(conf, name); =20 - if (value =3D=3D NULL) { - if (optional) { - return 0; - } else { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Missing essential config entry '%s'"), name); - return -1; - } - } + result =3D virVMXGetConfigStringHelper(conf, name, &string, optional); + if (result <=3D 0) + return result; =20 - if (value->type =3D=3D VIR_CONF_STRING) { - if (value->str =3D=3D NULL) { - if (optional) { - return 0; - } else { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Missing essential config entry '%s'"), n= ame); - return -1; - } - } + if (STRCASEEQ(string, "unlimited")) { + *number =3D -1; + result =3D 0; + goto cleanup; + } =20 - if (STRCASEEQ(value->str, "unlimited")) { - *number =3D -1; - } else if (virStrToLong_ll(value->str, NULL, 10, number) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Config entry '%s' must represent an integer = value"), - name); - return -1; - } - } else { + if (virStrToLong_ll(string, NULL, 10, number) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("Config entry '%s' must be a string"), name); - return -1; + _("Config entry '%s' must represent an integer value"), + name); + result =3D -1; + goto cleanup; } =20 - return 0; + result =3D 0; + + cleanup: + VIR_FREE(string); + + return result; } =20 =20 @@ -857,49 +822,33 @@ static int virVMXGetConfigBoolean(virConfPtr conf, const char *name, bool *boolean_, bool default_, bool optional) { - virConfValuePtr value; + char *string =3D NULL; + int result; =20 *boolean_ =3D default_; - value =3D virConfGetValue(conf, name); =20 - if (value =3D=3D NULL) { - if (optional) { - return 0; - } else { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Missing essential config entry '%s'"), name); - return -1; - } - } + result =3D virVMXGetConfigStringHelper(conf, name, &string, optional); + if (result <=3D 0) + return result; =20 - if (value->type =3D=3D VIR_CONF_STRING) { - if (value->str =3D=3D NULL) { - if (optional) { - return 0; - } else { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Missing essential config entry '%s'"), n= ame); - return -1; - } - } - - if (STRCASEEQ(value->str, "true")) { - *boolean_ =3D 1; - } else if (STRCASEEQ(value->str, "false")) { - *boolean_ =3D 0; - } else { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Config entry '%s' must represent a boolean v= alue " - "(true|false)"), name); - return -1; - } + if (STRCASEEQ(string, "true")) { + *boolean_ =3D 1; + } else if (STRCASEEQ(string, "false")) { + *boolean_ =3D 0; } else { virReportError(VIR_ERR_INTERNAL_ERROR, - _("Config entry '%s' must be a string"), name); - return -1; + _("Config entry '%s' must represent a boolean value= " + "(true|false)"), name); + result =3D -1; + goto cleanup; } =20 - return 0; + result =3D 0; + + cleanup: + VIR_FREE(string); + + return result; } =20 =20 --=20 2.17.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list