From nobody Wed May 14 10:55:02 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 1527368637961644.8155655025903; Sat, 26 May 2018 14:03:57 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3C29730C0F53; Sat, 26 May 2018 21:03:56 +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 DBD5C12A5E; Sat, 26 May 2018 21:03:55 +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 8C2DF180BA80; Sat, 26 May 2018 21:03:55 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4QL0kRO031700 for ; Sat, 26 May 2018 17:00:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6D0BD300165C; Sat, 26 May 2018 21:00:46 +0000 (UTC) Received: from mx1.redhat.com (ext-mx08.extmail.prod.ext.phx2.redhat.com [10.5.110.32]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6681B30012C3 for ; Sat, 26 May 2018 21:00:44 +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 21A16C104B4A for ; Sat, 26 May 2018 21:00:33 +0000 (UTC) Received: by mail-wm0-f66.google.com with SMTP id x2-v6so15474594wmh.5 for ; Sat, 26 May 2018 14:00:33 -0700 (PDT) Received: from machado.local ([95.82.135.172]) by smtp.gmail.com with ESMTPSA id u89-v6sm10748062wma.4.2018.05.26.14.00.30 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 26 May 2018 14:00:31 -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=5TZZxnBoS+IqAZjYsZjCkVkKWqoRCS7oJNjO7SZZ3Nw=; b=I9FZLo2LzcZn5HS2OOgEDXlMQ+5vS4g0Dpb6JsprVbcxni4nilK7k57h0pxYenKWIE QnAwRna5DdSKio1GO1+cYvS+3jdaJV2JHiE5HpSFaIsPlNYpfOBgEuUFSAgsxazTfiqq GypSy7dz5n3QNXVE8Qi6jQpbXKF6M0A46QuKq4CxoQsNH4EkA7Ors5eteP0lVnCMs/8E Zsf7mfYIMnXUGwIrc2KsC33Cjf2Xmmv4dFozDhspSJIYQHYfIlOFfAoyRkAlgIuJNq8r PhkioRTjoxiN+4rJJWRpj3xurTLj3CAOKQrij/IDNY3mrmYYkjVxPOLlO5Lr1Gn1e6RF l0Lg== 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=5TZZxnBoS+IqAZjYsZjCkVkKWqoRCS7oJNjO7SZZ3Nw=; b=CHDzrtYHRuiOAhsicyhE4rfrCvDNkXyFFsnFSiSwcvm/J1xixZQlIdiZRbNKQr6oeU ri1SP+Uaw1lqIRd6nvPJOsMhA3y/9rx30ekq2dFEZRPQY8i+9QEz9+zLQO2LW0vUpbBa KRiR4oBwufPvRnhMJtpKcu7cV3PV8x4a+BqJ8VPhSehgmOPRpy/0fzXZ715y9to7wCwf Y0gDeJ8YN0P3XDjaem4tYQjEy9/Dk/sH1yZ3aQawdbZ3irOwAoIWHNq9891sMCxhqpAI eHv8JSVMamuJOJ5ojiDB5+OtQS/v26wFMno6kMMIerSgMrd4iqLsA0IeNnGvxNBkcL40 8DLA== X-Gm-Message-State: ALKqPwdayYPFAO2MbaESYfrg0u1MpVL1mQHb+GlV8zmKiCZrkl6UqAiW 9fKwkzc37tcyLEjKacUJipVn2OVk X-Google-Smtp-Source: AB8JxZp4VLQqeA0vqUGqc+URfcerU+nHkK7IqcxNuBOQ6c/bmm+z3fkEX1fXxi+z9WECTQqvpAWsYw== X-Received: by 2002:a1c:820e:: with SMTP id e14-v6mr4810389wmd.34.1527368431582; Sat, 26 May 2018 14:00:31 -0700 (PDT) From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= To: libvir-list@redhat.com Date: Sat, 26 May 2018 23:00:26 +0200 Message-Id: <20180526210027.12066-3-fabiano@fidencio.org> In-Reply-To: <20180526210027.12066-1-fabiano@fidencio.org> References: <20180526210027.12066-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.32]); Sat, 26 May 2018 21:00:33 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Sat, 26 May 2018 21:00:33 +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.78 on 10.5.110.32 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-loop: libvir-list@redhat.com Cc: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= , =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Subject: [libvirt] [PATCHv2 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.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Sat, 26 May 2018 21:03:56 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 From: Fabiano Fid=C3=AAncio Signed-off-by: Fabiano Fid=C3=AAncio --- src/vmx/vmx.c | 196 ++++++++++++++++++++++--------------------------------= ---- 1 file changed, 73 insertions(+), 123 deletions(-) diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c index df6a58a474..54542c29a6 100644 --- a/src/vmx/vmx.c +++ b/src/vmx/vmx.c @@ -720,41 +720,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 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 +758,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 +786,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 +823,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.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list