From nobody Mon Feb 9 09:09:17 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.74 as permitted sender) client-ip=63.128.21.74; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-74.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.74 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1585120392; cv=none; d=zohomail.com; s=zohoarc; b=XUYxyAxEbiFB2GDqNHJ/tJBg/6i1kftgJ+3DhKUHgZP1s24i6QmUOdS1msgJkkAadG7BtRMZ7F5pXELOHLuJUbzWYurD8nVLHB/nPDTLXD9lGo3tT779G+PkioT3YiFuXTAu0XVUt6JLCgrTdMlY71A5PfoWd5DrXNv7d/QdBNE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585120392; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=Of7xkQLoOY7+z5TwNlGCR+1TKTGOkGXqe07c8dh9sXY=; b=CZzGA+SBAC5rnWn3fNSE7yeWELThr+lOQUtv7CWz2ZH0K0HyqpA2VU6HCtmB9HVHCWmiaLiMzJdRY4kL1mcU8fZLdbn/1GXY4zNRsAwEuLBupL0gjp9Wl6OB9c6DWCf4wO8UNFBirWxGV8tkAAFaSndMiKR0ZjKf84PQh9AjRnM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.74 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from us-smtp-delivery-74.mimecast.com (us-smtp-delivery-74.mimecast.com [63.128.21.74]) by mx.zohomail.com with SMTPS id 1585120392431659.3406394255093; Wed, 25 Mar 2020 00:13:12 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-338-Qoc3_CzTMU65UDRIVKYYJQ-1; Wed, 25 Mar 2020 03:13:08 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CD59E1085929; Wed, 25 Mar 2020 07:13:00 +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 9DA2460BF7; Wed, 25 Mar 2020 07:13:00 +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 4EB8D18089D6; Wed, 25 Mar 2020 07:13:00 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 02P7CU3j023920 for ; Wed, 25 Mar 2020 03:12:30 -0400 Received: by smtp.corp.redhat.com (Postfix) id 79AF5100D62; Wed, 25 Mar 2020 07:12:30 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 71CA3108BCC for ; Wed, 25 Mar 2020 07:12:29 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C868E8FF667 for ; Wed, 25 Mar 2020 07:12:29 +0000 (UTC) Received: from mail-m24147.qiye.163.com (mail-m24147.qiye.163.com [220.194.24.147]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-435-kaxtAr9yN9eFcbBT5nvHzA-1; Wed, 25 Mar 2020 03:12:26 -0400 Received: from localhost.localdomain (unknown [123.232.151.103]) by smtp4 (Coremail) with SMTP id JedpCgD3ftNNBHtey+koAw--.408S8; Wed, 25 Mar 2020 15:12:20 +0800 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585120391; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=Of7xkQLoOY7+z5TwNlGCR+1TKTGOkGXqe07c8dh9sXY=; b=af5J2X+cwYBwI89iFbeVMEBYb0J5xuFRXhbiQVAlGnHuxDTr9AHxh7fJdrNAVj6c9SVfPd pdrRXItplHAHmoiOIwmzYoRoO/wZleoSVa33CmbGaZctHFMs/kQY35RCMB0vAQ9pd/4qt0 f+eCUQb9JGN60MeKkGVUIMuVXGQO/iU= X-MC-Unique: Qoc3_CzTMU65UDRIVKYYJQ-1 X-MC-Unique: kaxtAr9yN9eFcbBT5nvHzA-1 From: Shi Lei To: libvir-list@redhat.com Subject: [RFC 06/29] util: Add a helper function virStringParseOnOff Date: Wed, 25 Mar 2020 15:11:46 +0800 Message-Id: <20200325071209.20841-7-shi_lei@massclouds.com> In-Reply-To: <20200325071209.20841-1-shi_lei@massclouds.com> References: <20200325071209.20841-1-shi_lei@massclouds.com> X-CM-TRANSID: JedpCgD3ftNNBHtey+koAw--.408S8 X-Coremail-Antispam: 1Uf129KBjDUn29KB7ZKAUJUUUU8529EdanIXcx71UUUUU7v73 VFW2AGmfu7bjvjm3AaLaJ3UbIYCTnIWIevJa73UjIFyTuYvjTRGnmiUUUUU X-Originating-IP: [123.232.151.103] X-CM-SenderInfo: pvklsz1hl6ztxvvfz0xxgvhudrp/1tbiTxTxT1f4p2CcUAAAsB X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 02P7CU3j023920 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 2 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" When RNG2C generates codes for builtin 'Bool.on_off', it includes virStringParseOnOff in those codes. Signed-off-by: Shi Lei --- src/util/virstring.c | 22 ++++++++++++++++++++++ src/util/virstring.h | 5 +++++ 2 files changed, 27 insertions(+) diff --git a/src/util/virstring.c b/src/util/virstring.c index e9e792f..2d0bb23 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -1404,3 +1404,25 @@ int virStringParseYesNo(const char *str, bool *resul= t) =20 return 0; } + + +/** + * virStringParseOnOff: + * @str: "on|off" to parse, must not be NULL. + * @result: pointer to the boolean result of @str conversion + * + * Parses a "on|off" string and converts it into a boolean. + * + * Returns 0 on success and -1 on error. + */ +int virStringParseOnOff(const char *str, bool *result) +{ + if (STREQ(str, "on")) + *result =3D true; + else if (STREQ(str, "off")) + *result =3D false; + else + return -1; + + return 0; +} diff --git a/src/util/virstring.h b/src/util/virstring.h index 360c683..c528e44 100644 --- a/src/util/virstring.h +++ b/src/util/virstring.h @@ -185,6 +185,11 @@ int virStringParsePort(const char *str, int virStringParseYesNo(const char *str, bool *result) G_GNUC_WARN_UNUSED_RESULT; + +int virStringParseOnOff(const char *str, + bool *result) + G_GNUC_WARN_UNUSED_RESULT; + /** * VIR_AUTOSTRINGLIST: * --=20 2.17.1