From nobody Wed Nov 27 10:50:58 2024 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; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1552318955513748.7162373091869; Mon, 11 Mar 2019 08:42:35 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A557B87624; Mon, 11 Mar 2019 15:42:33 +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 7B9A3608E2; Mon, 11 Mar 2019 15:42:33 +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 16D47247E3; Mon, 11 Mar 2019 15:42:33 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2BFcbSh002188 for ; Mon, 11 Mar 2019 11:38:37 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7F13A1001DDB; Mon, 11 Mar 2019 15:38:37 +0000 (UTC) Received: from mx1.redhat.com (ext-mx20.extmail.prod.ext.phx2.redhat.com [10.5.110.49]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 798B8100194A for ; Mon, 11 Mar 2019 15:38:34 +0000 (UTC) Received: from mail-pf1-f196.google.com (mail-pf1-f196.google.com [209.85.210.196]) (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 73DE930001D9 for ; Mon, 11 Mar 2019 15:38:33 +0000 (UTC) Received: by mail-pf1-f196.google.com with SMTP id j5so3971438pfa.2 for ; Mon, 11 Mar 2019 08:38:33 -0700 (PDT) Received: from localhost.localdomain (KD036012073125.au-net.ne.jp. [36.12.73.125]) by smtp.googlemail.com with ESMTPSA id v1sm9191073pff.9.2019.03.11.08.38.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 11 Mar 2019 08:38:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=yN62uG6d65MfKbANkIUgwYsMpzC7Yb6YqGk6T4Nv4s8=; b=VRRK7W3M7wIKhXo4SAoaMY9ROpOhzUZPVesHBwbshQhyjz+mNxcj4qZ4hdRw0ZDBGC tIpsqlXdS0EqTcRCeroiIcyid7KJVp5E1dJPpfh91a3RKNxE7eqsq/gCpGQW3SzUk6K7 N5pyMpi+fcPy9IFSkhhnTaJysXhdOpkvnL2+zO5OZtp0sWTSYgijNzhmIUnSTIUyW+Ez +L1pFHmhRHbhgEVrVBZUp21Akbv2c/fu/XyopiA6ay/vPUkxNl818jbja1jweO7RQVaD nX6vybUONNjKK849yLf//zXdm6hy7BWhZWaZUxKwnpdmmPaQn+ND64do6Yg7ZQb26dxT OsqA== 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=yN62uG6d65MfKbANkIUgwYsMpzC7Yb6YqGk6T4Nv4s8=; b=VDzB2+Enjx05IQKVg8+S3ET0tYa2r6WDdivlfoUJfO4yoKYg6YyRUPYJrBCDPoKU7l KUHicCgAZpgJdvrCEmZuhDjHdatFnVtqy6gniWDSmjJ0W7lFp+aLgypwOQHkePTVy5aa Dk3JwzBmu0Lrxc2SQeELRhCYDLJiPJRef09Rzrg2mFqsbmXwiKhIxpb8XJX+kwi7zQIw cXujYRT8nCDARhncZqSKMjCzh7DivVZ5uGGluyuYyHy5s/FzvAhqlvzsr9tEDpXE1zSb MKoJrJZUhalZy0tVxMbN7mdW2c/8T+wmoZ+4fkg4TV+IAygrxHy5VddAJ4S2zewtwIgD KtuA== X-Gm-Message-State: APjAAAVrXXoIR3njjb+stQWEdqKxkEqiX6pmvc8dLv0g3eix5ECs/yKa bfNWyPWxSYL1hEonxAdqnlPFbwN+ X-Google-Smtp-Source: APXvYqzBs2RPSoSTgqaEt/OgdvEl5dkfZ0jArzyxJeFKi157hanLDGMb/WhGb+FPoVubFAy1XKjgZg== X-Received: by 2002:a63:101c:: with SMTP id f28mr29900021pgl.224.1552318712320; Mon, 11 Mar 2019 08:38:32 -0700 (PDT) From: Shotaro Gotanda To: libvir-list@redhat.com Date: Tue, 12 Mar 2019 00:38:05 +0900 Message-Id: <20190311153806.31327-2-g.sho1500@gmail.com> In-Reply-To: <20190311153806.31327-1-g.sho1500@gmail.com> References: <20190311153806.31327-1-g.sho1500@gmail.com> MIME-Version: 1.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Mon, 11 Mar 2019 15:38:33 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Mon, 11 Mar 2019 15:38:33 +0000 (UTC) for IP:'209.85.210.196' DOMAIN:'mail-pf1-f196.google.com' HELO:'mail-pf1-f196.google.com' FROM:'g.sho1500@gmail.com' RCPT:'' X-RedHat-Spam-Score: 0.12 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS) 209.85.210.196 mail-pf1-f196.google.com 209.85.210.196 mail-pf1-f196.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.49 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Cc: Shotaro Gotanda Subject: [libvirt] [PATCH 1/2] util: add virStringParseYesNo() 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-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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Mon, 11 Mar 2019 15:42:34 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This function parse and convert string "yes|no" into bool true|false. Signed-off-by: Shotaro Gotanda --- src/util/virstring.c | 32 ++++++++++++++++++++++++++++++++ src/util/virstring.h | 3 +++ 2 files changed, 35 insertions(+) diff --git a/src/util/virstring.c b/src/util/virstring.c index 33f8191f45..70018459de 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -1548,3 +1548,35 @@ virStringParsePort(const char *str, =20 return 0; } + + +/** + * virStringParseYesNo: + * @str: "yes|no" to parse + * @port: pointer to parse and convert "yes|no" into + * + * Parses a string "yes|no" and convert it into true|false. Returns + * 0 on success and -1 on error. + */ +int virStringParseYesNo(const char *str, + bool *result) +{ + bool r =3D false; + + if (!str) + return -1; + + if (STREQ(str, "yes")) { + r =3D true; + } else if (STREQ(str, "no")) { + r =3D false; + } else { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Invalid value, '%s' must be either 'yes' or 'no'"), st= r); + return -1; + } + + *result =3D r; + + return 0; +} diff --git a/src/util/virstring.h b/src/util/virstring.h index 1e36ac459c..b921d5407b 100644 --- a/src/util/virstring.h +++ b/src/util/virstring.h @@ -316,6 +316,9 @@ int virStringParsePort(const char *str, unsigned int *port) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK; =20 +int virStringParseYesNo(const char *str, + bool *result); + /** * VIR_AUTOSTRINGLIST: * --=20 2.19.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list