From nobody Wed May 14 10:26:05 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; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 152746013661888.67198235674061; Sun, 27 May 2018 15:28:56 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2FB2930CADC5; Sun, 27 May 2018 22:28:55 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D2D075DD6B; Sun, 27 May 2018 22:28:54 +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 77C8E4CA81; Sun, 27 May 2018 22:28:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4RMSnw2015025 for ; Sun, 27 May 2018 18:28:49 -0400 Received: by smtp.corp.redhat.com (Postfix) id C07992010CF0; Sun, 27 May 2018 22:28:49 +0000 (UTC) Received: from mx1.redhat.com (ext-mx01.extmail.prod.ext.phx2.redhat.com [10.5.110.25]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B8EEF2010CEE for ; Sun, 27 May 2018 22:28:46 +0000 (UTC) Received: from mail-wm0-f66.google.com (mail-wm0-f66.google.com [74.125.82.66]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 61F58CD4CD for ; Sun, 27 May 2018 22:28:35 +0000 (UTC) Received: by mail-wm0-f66.google.com with SMTP id v131-v6so8142030wma.1 for ; Sun, 27 May 2018 15:28:35 -0700 (PDT) Received: from machado.local ([95.82.135.172]) by smtp.gmail.com with ESMTPSA id h81-v6sm23469897wmd.0.2018.05.27.15.28.32 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 27 May 2018 15:28:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fidencio-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KwDjwry99t46Fp6itpoRnYNn6oam+HVsTPoxKSvkapE=; b=zx+z5nUfPTnN3iFgAf0RPRAf76gaWkMk4BwyjWiyG9R4Z05tQXXPHnFUwpvt/q6OU2 zLa3KT/mHWzHHztHACIW06sZudWx8YhyK7lerM/EtYk0bHmRnu7GDG0z+rGR7STRSk9e drK/0lljN3PhbuQ0ugbpokCUEfBlyONHIT0kli5BJziQxeF79FoszRtK643Pz9TZO6fZ DmsVBNr7bUdkHP17WC8qD51NijtfoHb8hx7a8KY+orA73EXFLg1xygPxTXGLxf7PGeFH 8PSsGTf7DgOEj6/I+day+tw4giYbekNiz8cc2idGKerM1TPVoEXtF3jNEFKTcbd48RuK BOdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=KwDjwry99t46Fp6itpoRnYNn6oam+HVsTPoxKSvkapE=; b=CtIcOzM0RhN5p7pyqH9O6UcMxt0LDC4yTq9ZCdPReHphLi4F9zx5my+l2vGG/xBwat 7gU0i0XGobRbRADRFB5fhZt+eoreEVzj0RijAgaWiZRmqgKjyKWvtUfQjyBNE+ES7kfR epSNHE03a+ec4ZDWjBAui54rjQqlZzfNBp5KPxxVSFranHFynB+DGkwpaI3OQS8agPUn M3GwMqO2Kk1Svl8H4TJg35sI67B517/tTQ5OaBG6wAFw3pFnUFBqOdooRus14RQSxmk/ RODKBINmOkQufbkPuXvW9uXJXwTL58dAiObkIQ4coDDbJMPC92eWoOr9KQ2c7LJmVjWU EV9A== X-Gm-Message-State: ALKqPwf8S2V9Ss7fc+PkW8eyzPiWmOCeSneexR3V7kH809gYXlfWjRKc nVOjhtb2VUT2/UdLlf91UHdPw/Qk X-Google-Smtp-Source: ADUXVKIQRrEgns/S2xZjUgbmIbjE5dZlJMlOcivdjnbZF74dy1A49nzP6IwIalXoZhQvCLJeeQAoFg== X-Received: by 2002:a1c:9595:: with SMTP id x143-v6mr8186260wmd.146.1527460113864; Sun, 27 May 2018 15:28:33 -0700 (PDT) From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= To: libvir-list@redhat.com Date: Mon, 28 May 2018 00:28:22 +0200 Message-Id: <20180527222826.18525-4-fabiano@fidencio.org> In-Reply-To: <20180527222826.18525-1-fabiano@fidencio.org> References: <20180527222826.18525-1-fabiano@fidencio.org> MIME-Version: 1.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Sun, 27 May 2018 22:28:35 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Sun, 27 May 2018 22:28:35 +0000 (UTC) for IP:'74.125.82.66' DOMAIN:'mail-wm0-f66.google.com' HELO:'mail-wm0-f66.google.com' FROM:'fabiano@fidencio.org' RCPT:'' X-RedHat-Spam-Score: 0.08 (DKIM_SIGNED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID) 74.125.82.66 mail-wm0-f66.google.com 74.125.82.66 mail-wm0-f66.google.com X-Scanned-By: MIMEDefang 2.83 on 10.5.110.25 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-loop: libvir-list@redhat.com Cc: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Subject: [libvirt] [PATCHv3 3/7] 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.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Sun, 27 May 2018 22:28:55 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Signed-off-by: Fabiano Fid=C3=AAncio Reviewed-by: J=EF=BF=BDn Tomko --- src/vmx/vmx.c | 194 +++++++++++++++++++++---------------------------------= ---- 1 file changed, 70 insertions(+), 124 deletions(-) diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c index df6a58a474..b6df257144 100644 --- a/src/vmx/vmx.c +++ b/src/vmx/vmx.c @@ -722,39 +722,36 @@ virVMXConvertToUTF8(const char *encoding, const char = *string) =20 =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 rc; *string =3D NULL; - value =3D virConfGetValue(conf, name); =20 - if (value =3D=3D NULL) { - if (optional) - return 0; + rc =3D virConfGetValueString(conf, name, string); + if (rc =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 +760,26 @@ static int virVMXGetConfigUUID(virConfPtr conf, const char *name, unsigned char *uuid, bool optional) { - virConfValuePtr value; - - value =3D virConfGetValue(conf, name); + char *string =3D NULL; + int ret =3D -1; + int rc; =20 - if (value =3D=3D NULL) { - if (optional) { - return 0; - } else { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Missing essential config entry '%s'"), name); - return -1; - } - } + rc =3D virVMXGetConfigStringHelper(conf, name, &string, optional); + if (rc <=3D 0) + return rc; =20 - if (value->type !=3D VIR_CONF_STRING) { + rc =3D virUUIDParse(string, uuid); + if (rc < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("Config entry '%s' must be a string"), name); - return -1; - } - - if (value->str =3D=3D NULL) { - if (optional) { - return 0; - } else { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Missing essential config entry '%s'"), name); - return -1; - } + _("Could not parse UUID from string '%s'"), string); + goto cleanup; } =20 - if (virUUIDParse(value->str, uuid) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Could not parse UUID from string '%s'"), value->= str); - return -1; - } + ret =3D 0; =20 - return 0; + cleanup: + VIR_FREE(string); + return ret; } =20 =20 @@ -808,47 +788,30 @@ static int virVMXGetConfigLong(virConfPtr conf, const char *name, long long *number, long long default_, bool optional) { - virConfValuePtr value; + char *string =3D NULL; + int ret =3D -1; + int rc; =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; - } - } - - 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; - } - } + rc =3D virVMXGetConfigStringHelper(conf, name, &string, optional); + if (rc <=3D 0) + return rc; =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 (STRCASEEQ(string, "unlimited")) { + *number =3D -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); + goto cleanup; } =20 - return 0; + ret =3D 0; + + cleanup: + VIR_FREE(string); + return ret; } =20 =20 @@ -857,49 +820,32 @@ static int virVMXGetConfigBoolean(virConfPtr conf, const char *name, bool *boolean_, bool default_, bool optional) { - virConfValuePtr value; + char *string =3D NULL; + int ret =3D -1; + int rc; =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; - } - } - - 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; - } - } + rc =3D virVMXGetConfigStringHelper(conf, name, &string, optional); + if (rc <=3D 0) + return rc; =20 - 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); + goto cleanup; } =20 - return 0; + ret =3D 0; + + cleanup: + VIR_FREE(string); + return ret; } =20 =20 --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list