From nobody Sun May 12 11:08:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602401944; cv=none; d=zohomail.com; s=zohoarc; b=RvyriqHFFwUbvGa5nCdY++s/HCvRgv3tGKp8iGVAPIJ6tCTAe7E9j1q5e1BdGpYqBk0pcftzlt+It34iVUxOqz3Y+hZwdA8Sk2XXqA3QfPhbC/8Iz6ypfI6f8pvZmcS1muwequNER1Ogrp3y5PbXp/VQbatBe89U6KTNSITdsJ0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602401944; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=EiSiGe2Sr1BVyh/nVct1USJZCm5n8JYMclTN1VuwLl8=; b=hGI1OLr5aOBqwZyi8xUeY4h7hRnXD31LBuZvpmNusynml+2RfDCNpy1XgHjQ11CLQ/F05hLBiBR5oX1yn0WcXIlPyGtrKtkU1gZLlCZPHQ7ynIj0XgEQsbeBqG/TaCnhsOPQEREjakK5AfeqeDJnMa65Z5Jagbu+91PRk58kiAE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602401944067451.72150920413253; Sun, 11 Oct 2020 00:39:04 -0700 (PDT) Received: from localhost ([::1]:50008 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kRVwc-0003IA-Ol for importer@patchew.org; Sun, 11 Oct 2020 03:39:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35910) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kRVt2-0006Fh-Df for qemu-devel@nongnu.org; Sun, 11 Oct 2020 03:35:20 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:58205) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kRVsx-0003Gs-Ew for qemu-devel@nongnu.org; Sun, 11 Oct 2020 03:35:20 -0400 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-445-1y5CB0R-PSK_jlPu_GSm3A-1; Sun, 11 Oct 2020 03:35:07 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C80F7107ACF5; Sun, 11 Oct 2020 07:35:06 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-182.ams2.redhat.com [10.36.112.182]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9761646; Sun, 11 Oct 2020 07:35:06 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 1537A11329AF; Sun, 11 Oct 2020 09:35:05 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602401711; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EiSiGe2Sr1BVyh/nVct1USJZCm5n8JYMclTN1VuwLl8=; b=QE6pEKpcOievGzHuZdiXZ/VhTO3DRhc6+/SrlQbvJC+QZNjs6qHrBnXFZMKdNkrjlrsAhc lD0qZ8WnZaLErgX1gwCXTwwYsN3up3lRvWoUT3IbmD6XvwKoaRf4e0ne0uzcpxYg8ILXyg cAehSIIhpzJHam9sdox074rD2QWRg1A= X-MC-Unique: 1y5CB0R-PSK_jlPu_GSm3A-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v4 1/7] keyval: Fix and clarify grammar Date: Sun, 11 Oct 2020 09:34:59 +0200 Message-Id: <20201011073505.1185335-2-armbru@redhat.com> In-Reply-To: <20201011073505.1185335-1-armbru@redhat.com> References: <20201011073505.1185335-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/11 02:10:40 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The grammar has a few issues: * key-fragment =3D / [^=3D,.]* / Prose restricts key fragments: they "must be valid QAPI names or consist only of decimal digits". Technically, '' consists only of decimal digits. The code rejects that. Fix the grammar. * val =3D { / [^,]* / | ',,' } Use + instead of *. Accepts the same language. * val-no-key =3D / [^=3D,]* / The code rejects an empty value. Fix the grammar. * Section "Additional syntax for use with an implied key" is confusing. Rewrite it. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- util/keyval.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/util/keyval.c b/util/keyval.c index 13def4af54..82d8497c71 100644 --- a/util/keyval.c +++ b/util/keyval.c @@ -16,8 +16,8 @@ * key-vals =3D [ key-val { ',' key-val } [ ',' ] ] * key-val =3D key '=3D' val * key =3D key-fragment { '.' key-fragment } - * key-fragment =3D / [^=3D,.]* / - * val =3D { / [^,]* / | ',,' } + * key-fragment =3D / [^=3D,.]+ / + * val =3D { / [^,]+ / | ',,' } * * Semantics defined by reduction to JSON: * @@ -71,12 +71,16 @@ * Awkward. Note that we carefully restrict alternate types to avoid * similar ambiguity. * - * Additional syntax for use with an implied key: + * Alternative syntax for use with an implied key: * - * key-vals-ik =3D val-no-key [ ',' key-vals ] - * val-no-key =3D / [^=3D,]* / + * key-vals =3D [ key-val-1st { ',' key-val } [ ',' ] ] + * key-val-1st =3D val-no-key | key-val + * val-no-key =3D / [^=3D,]+ / * - * where no-key is syntactic sugar for implied-key=3Dval-no-key. + * where val-no-key is syntactic sugar for implied-key=3Dval-no-key. + * + * Note that you can't use the sugared form when the value contains + * '=3D' or ','. */ =20 #include "qemu/osdep.h" --=20 2.26.2 From nobody Sun May 12 11:08:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602401796; cv=none; d=zohomail.com; s=zohoarc; b=febdW5Q+e5ZypMDJ8QgsQ3kR97lBhmYAPAzlSIkmtdWa9636V8dBJMMjwDL2FsKuBw5J+FdJ7Y+toh/FsAyit30QD551Szw7dMAEdl2l/Nrjqp5zmzerw+yCrDLG7fUAbNKBnoJlovqvfg8YWaMkuTsy1/TAc+jkKwMDSmNqSk4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602401796; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Nqq9WXlOV9+QZ91BW/WxEh1wTlCTvfPI2ol0WEsH7YE=; b=D3TDQvFdnDn4KihAhLekeIlR1H87guXnis9db43AOSiKLfD2T2YVJTzwdqDfIzwIzy9NEXkOzWFEJh+j88DOws7x51dZCoAU8ZUxbNzJQbBaT52fCKCxvWVC5dLdwlkxkg9oRPjcpLKvJdi8Mzoi+gbJrc50p/Q4ZKIiGYf7EpI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602401796962352.1272471577654; Sun, 11 Oct 2020 00:36:36 -0700 (PDT) Received: from localhost ([::1]:40662 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kRVuE-0007tU-Sz for importer@patchew.org; Sun, 11 Oct 2020 03:36:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35824) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kRVsy-0006CW-2J for qemu-devel@nongnu.org; Sun, 11 Oct 2020 03:35:16 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:32133) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kRVst-0003GL-CC for qemu-devel@nongnu.org; Sun, 11 Oct 2020 03:35:15 -0400 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-326--0ojqNL2MzW48740habyuA-1; Sun, 11 Oct 2020 03:35:07 -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 CC6E3835B67; Sun, 11 Oct 2020 07:35:06 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-182.ams2.redhat.com [10.36.112.182]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9B63561177; Sun, 11 Oct 2020 07:35:06 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 1838E1132946; Sun, 11 Oct 2020 09:35:05 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602401710; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Nqq9WXlOV9+QZ91BW/WxEh1wTlCTvfPI2ol0WEsH7YE=; b=JtL07gwNAVYInVq6jFp33ZgdkIT6I1+xnIrnGayQE2RQevLsdVUhS0EwgPzhUmg9Y80e8v LWwF52QbWKDlolnHFXTmq/2qxSFJEMUFK26MvmO3gh7ceJ8ifwpxbMxwfdcKe0tOWik0pe BlfGodIoqKn3oMnZ+MSk1A+8QfEAE+s= X-MC-Unique: -0ojqNL2MzW48740habyuA-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v4 2/7] test-keyval: Demonstrate misparse of ', ' with implied key Date: Sun, 11 Oct 2020 09:35:00 +0200 Message-Id: <20201011073505.1185335-3-armbru@redhat.com> In-Reply-To: <20201011073505.1185335-1-armbru@redhat.com> References: <20201011073505.1185335-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/11 00:55:29 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Add a test for "val,,ue" with implied key. Documentation says this should parse as implied key with value "val", then fail. The code parses it as implied key with value "val,ue", then succeeds. The next commit will fix it. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- tests/test-keyval.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/test-keyval.c b/tests/test-keyval.c index e331a84149..f02bdf7029 100644 --- a/tests/test-keyval.c +++ b/tests/test-keyval.c @@ -182,6 +182,13 @@ static void test_keyval_parse(void) error_free_or_abort(&err); g_assert(!qdict); =20 + /* Implied key's value can't have comma (qemu_opts_parse(): it can) */ + /* BUG: it can */ + qdict =3D keyval_parse("val,,ue", "implied", &error_abort); + g_assert_cmpuint(qdict_size(qdict), =3D=3D, 1); + g_assert_cmpstr(qdict_get_try_str(qdict, "implied"), =3D=3D, "val,ue"); + qobject_unref(qdict); + /* Empty key is not an implied key */ qdict =3D keyval_parse("=3Dval", "implied", &err); error_free_or_abort(&err); --=20 2.26.2 From nobody Sun May 12 11:08:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602402051; cv=none; d=zohomail.com; s=zohoarc; b=Z6x7r0DOW/A7HVHJYhuiUTQQeeMdMN4vJlc4w8U65GTOxaSiu0XY4wBmJjNV5Qz/9okb2hU8ROd2iAacba99H8BmOJCiWILaMzkPyyNgxvKDEzuZjybKLZsMNmetPcUzuiMRb9sSppCb/1jIInCb2jb7tVNTy4vW+PmmdzSb7ok= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602402051; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=fHPYCqiyKGAD+Zc8/zz2fhKOml70BFrb+sHIjUM/cYM=; b=dtmPFeTX59rWCxEypXrhpu8sLTxTknFVAVazMcV/v0namQqxzPzH/8aLv703wNnPbl4Zo4/5JEU/lf/Qvy4Z04vbNILwicx/fBw6u1YKvLkHt2AxAfi0NnW1ibwL4vPeJUmceKAAX/a2yKX2AjgNYczzKPrEPWPP/I2evkJH6x8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602402051202665.2464437530315; Sun, 11 Oct 2020 00:40:51 -0700 (PDT) Received: from localhost ([::1]:55896 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kRVyM-0005gj-0f for importer@patchew.org; Sun, 11 Oct 2020 03:40:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35916) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kRVt2-0006GC-J7 for qemu-devel@nongnu.org; Sun, 11 Oct 2020 03:35:20 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:42852) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kRVsx-0003H4-M5 for qemu-devel@nongnu.org; Sun, 11 Oct 2020 03:35:20 -0400 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-445-RqBuCnqFO4msgEnCJJzFiA-1; Sun, 11 Oct 2020 03:35:07 -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 CC192107AD96; Sun, 11 Oct 2020 07:35:06 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-182.ams2.redhat.com [10.36.112.182]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9B5C160C07; Sun, 11 Oct 2020 07:35:06 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 1B7D4112CE10; Sun, 11 Oct 2020 09:35:05 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602401711; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fHPYCqiyKGAD+Zc8/zz2fhKOml70BFrb+sHIjUM/cYM=; b=fqqRQ0kZdWjF5iMPR8+QEa7j05tOMJy8w1EYH8zfcUu6GVnljBvBOo24FUck7EobjCvtHK ZE9MzpYSK+/KyvRXi1mexzHgO2gRrlXoHX6ztJLpvNiMOQTvaQNzYOLLuu+diksdUTqtVt 2o29IOojGx6rGIL+2oMrPOWAnECRKCI= X-MC-Unique: RqBuCnqFO4msgEnCJJzFiA-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v4 3/7] keyval: Fix parsing of ',' in value of implied key Date: Sun, 11 Oct 2020 09:35:01 +0200 Message-Id: <20201011073505.1185335-4-armbru@redhat.com> In-Reply-To: <20201011073505.1185335-1-armbru@redhat.com> References: <20201011073505.1185335-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/11 02:10:40 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The previous commit demonstrated documentation and code disagree on parsing of ',' in the value of an implied key. Fix the code to match the documentation. This breaks uses of keyval_parse() that pass an implied key and accept a value containing ','. None of the existing uses does: * audiodev: implied key "driver" is enum AudiodevDriver, none of the values contains ',' * display: implied key "type" is enum DisplayType, none of the values contains ',' * blockdev: implied key "driver is enum BlockdevDriver, none of the values contains ',' * export: implied key "type" is enum BlockExportType, none of the values contains ',' * monitor: implied key "mode" is enum MonitorMode, none of the values contains ',' * nbd-server: no implied key. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- tests/test-keyval.c | 8 +++----- util/keyval.c | 28 +++++++++++++++++----------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/tests/test-keyval.c b/tests/test-keyval.c index f02bdf7029..04c62cf045 100644 --- a/tests/test-keyval.c +++ b/tests/test-keyval.c @@ -183,11 +183,9 @@ static void test_keyval_parse(void) g_assert(!qdict); =20 /* Implied key's value can't have comma (qemu_opts_parse(): it can) */ - /* BUG: it can */ - qdict =3D keyval_parse("val,,ue", "implied", &error_abort); - g_assert_cmpuint(qdict_size(qdict), =3D=3D, 1); - g_assert_cmpstr(qdict_get_try_str(qdict, "implied"), =3D=3D, "val,ue"); - qobject_unref(qdict); + qdict =3D keyval_parse("val,,ue", "implied", &err); + error_free_or_abort(&err); + g_assert(!qdict); =20 /* Empty key is not an implied key */ qdict =3D keyval_parse("=3Dval", "implied", &err); diff --git a/util/keyval.c b/util/keyval.c index 82d8497c71..8f33a36a7c 100644 --- a/util/keyval.c +++ b/util/keyval.c @@ -173,7 +173,7 @@ static const char *keyval_parse_one(QDict *qdict, const= char *params, const char *implied_key, Error **errp) { - const char *key, *key_end, *s, *end; + const char *key, *key_end, *val_end, *s, *end; size_t len; char key_in_cur[128]; QDict *cur; @@ -182,10 +182,12 @@ static const char *keyval_parse_one(QDict *qdict, con= st char *params, QString *val; =20 key =3D params; + val_end =3D NULL; len =3D strcspn(params, "=3D,"); if (implied_key && len && key[len] !=3D '=3D') { /* Desugar implied key */ key =3D implied_key; + val_end =3D params + len; len =3D strlen(implied_key); } key_end =3D key + len; @@ -241,7 +243,11 @@ static const char *keyval_parse_one(QDict *qdict, cons= t char *params, =20 if (key =3D=3D implied_key) { assert(!*s); - s =3D params; + val =3D qstring_from_substr(params, 0, val_end - params); + s =3D val_end; + if (*s =3D=3D ',') { + s++; + } } else { if (*s !=3D '=3D') { error_setg(errp, "Expected '=3D' after parameter '%.*s'", @@ -249,19 +255,19 @@ static const char *keyval_parse_one(QDict *qdict, con= st char *params, return NULL; } s++; - } =20 - val =3D qstring_new(); - for (;;) { - if (!*s) { - break; - } else if (*s =3D=3D ',') { - s++; - if (*s !=3D ',') { + val =3D qstring_new(); + for (;;) { + if (!*s) { break; + } else if (*s =3D=3D ',') { + s++; + if (*s !=3D ',') { + break; + } } + qstring_append_chr(val, *s++); } - qstring_append_chr(val, *s++); } =20 if (!keyval_parse_put(cur, key_in_cur, val, key, key_end, errp)) { --=20 2.26.2 From nobody Sun May 12 11:08:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602401945; cv=none; d=zohomail.com; s=zohoarc; b=eGuTSIHRxvBpQ0a1+WGoaW1d8IoSdwu75FzCwDWfMpZrOGqm2AH7AoTyNk7VXU5tDnFSWZRVmm1bd6dY/nLTyMWYQfTLi3gVCa4Oqbc7/030OZnyP5rDrF2fnn8l835UrPV/6zmyqh/cjV0WH+RB8Jg/MtB2fj4tVtiOi/YyuEs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602401945; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ZTl0kR94cDCo2wcg1ej3auFcYnpluSbKmityLUPHEcw=; b=aQpj+NVWFPL+CU44OzqncahIJcuZiT11jgfnEHh/BBKciT+0VGI53E92H63iWirJ9Ku42NOYBEOt4l/dxykfgyHaUVwiLg+JV7M2e9El3KVMfpzZhpNf5lCU47RX5LGNiAlIE2GQv/PZQJZWOTwlF5rim3tp4H8FRJKnTZG7Vas= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602401945801762.7459293885662; Sun, 11 Oct 2020 00:39:05 -0700 (PDT) Received: from localhost ([::1]:50136 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kRVwe-0003LY-JI for importer@patchew.org; Sun, 11 Oct 2020 03:39:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35886) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kRVt0-0006Dx-OB for qemu-devel@nongnu.org; Sun, 11 Oct 2020 03:35:18 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:38902) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kRVst-0003Gc-Sl for qemu-devel@nongnu.org; Sun, 11 Oct 2020 03:35:18 -0400 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-132-S9O-7PqTP-W8cEPRCII9BA-1; Sun, 11 Oct 2020 03:35:08 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 47D47427FA; Sun, 11 Oct 2020 07:35:07 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-182.ams2.redhat.com [10.36.112.182]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9B772709BB; Sun, 11 Oct 2020 07:35:06 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 1F41A112CE12; Sun, 11 Oct 2020 09:35:05 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602401710; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZTl0kR94cDCo2wcg1ej3auFcYnpluSbKmityLUPHEcw=; b=br1lR/2wAlgKNdR3UvHzwp5f6Q09P5HB1SM6krJpBV8e2KCA2Me53h3smJAnBquaZOxvPS dxulmz1UTd4ffFo8qJqI/qX0wYsdj1Kd/N1CcrOSa4oRRtZso+WMutG1zkkyqXe5z5L+fz SnEem56WT+Jql3Kz5swqEIKgOrRrlA0= X-MC-Unique: S9O-7PqTP-W8cEPRCII9BA-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v4 4/7] keyval: Parse help options Date: Sun, 11 Oct 2020 09:35:02 +0200 Message-Id: <20201011073505.1185335-5-armbru@redhat.com> In-Reply-To: <20201011073505.1185335-1-armbru@redhat.com> References: <20201011073505.1185335-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/11 00:55:29 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Kevin Wolf This adds a special meaning for 'help' and '?' as options to the keyval parser. Instead of being an error (because of a missing value) or a value for an implied key, they now request help, which is a new boolean output of the parser in addition to the QDict. A new parameter 'p_help' is added to keyval_parse() that contains on return whether help was requested. If NULL is passed, requesting help results in an error and all other cases work like before. Turning previous error cases into help is a compatible extension. The behaviour potentially changes for implied keys: They could previously get 'help' as their value, which is now interpreted as requesting help. This is not a problem in practice because 'help' and '?' are not a valid values for the implied key of any option parsed with keyval_parse(): * audiodev: union Audiodev, implied key "driver" is enum AudiodevDriver, "help" and "?" are not among its values * display: union DisplayOptions, implied key "type" is enum DisplayType, "help" and "?" are not among its values * blockdev: union BlockdevOptions, implied key "driver is enum BlockdevDriver, "help" and "?" are not among its values * export: union BlockExport, implied key "type" is enum BlockExportType, "help" and "?" are not among its values * monitor: struct MonitorOptions, implied key "mode" is enum MonitorMode, "help" and "?" are not among its values * nbd-server: struct NbdServerOptions, no implied key. Signed-off-by: Kevin Wolf Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- include/qemu/help_option.h | 11 ++ include/qemu/option.h | 2 +- qapi/qobject-input-visitor.c | 2 +- storage-daemon/qemu-storage-daemon.c | 2 +- tests/test-keyval.c | 184 ++++++++++++++++++--------- util/keyval.c | 63 +++++++-- 6 files changed, 186 insertions(+), 78 deletions(-) diff --git a/include/qemu/help_option.h b/include/qemu/help_option.h index 328d2a89fd..ca6389a154 100644 --- a/include/qemu/help_option.h +++ b/include/qemu/help_option.h @@ -19,4 +19,15 @@ static inline bool is_help_option(const char *s) return !strcmp(s, "?") || !strcmp(s, "help"); } =20 +static inline int starts_with_help_option(const char *s) +{ + if (*s =3D=3D '?') { + return 1; + } + if (g_str_has_prefix(s, "help")) { + return 4; + } + return 0; +} + #endif diff --git a/include/qemu/option.h b/include/qemu/option.h index 05e8a15c73..ac69352e0e 100644 --- a/include/qemu/option.h +++ b/include/qemu/option.h @@ -149,6 +149,6 @@ void qemu_opts_free(QemuOptsList *list); QemuOptsList *qemu_opts_append(QemuOptsList *dst, QemuOptsList *list); =20 QDict *keyval_parse(const char *params, const char *implied_key, - Error **errp); + bool *help, Error **errp); =20 #endif diff --git a/qapi/qobject-input-visitor.c b/qapi/qobject-input-visitor.c index f918a05e5f..7b184b50a7 100644 --- a/qapi/qobject-input-visitor.c +++ b/qapi/qobject-input-visitor.c @@ -757,7 +757,7 @@ Visitor *qobject_input_visitor_new_str(const char *str, assert(args); v =3D qobject_input_visitor_new(QOBJECT(args)); } else { - args =3D keyval_parse(str, implied_key, errp); + args =3D keyval_parse(str, implied_key, NULL, errp); if (!args) { return NULL; } diff --git a/storage-daemon/qemu-storage-daemon.c b/storage-daemon/qemu-sto= rage-daemon.c index 1ae1cda481..6f0e0cfb36 100644 --- a/storage-daemon/qemu-storage-daemon.c +++ b/storage-daemon/qemu-storage-daemon.c @@ -278,7 +278,7 @@ static void process_options(int argc, char *argv[]) } qemu_opts_del(opts); =20 - args =3D keyval_parse(optarg, "qom-type", &error_fatal); + args =3D keyval_parse(optarg, "qom-type", NULL, &error_fat= al); user_creatable_add_dict(args, true, &error_fatal); qobject_unref(args); break; diff --git a/tests/test-keyval.c b/tests/test-keyval.c index 04c62cf045..7b459900af 100644 --- a/tests/test-keyval.c +++ b/tests/test-keyval.c @@ -1,3 +1,4 @@ + /* * Unit tests for parsing of KEY=3DVALUE,... strings * @@ -27,27 +28,28 @@ static void test_keyval_parse(void) QDict *qdict, *sub_qdict; char long_key[129]; char *params; + bool help; =20 /* Nothing */ - qdict =3D keyval_parse("", NULL, &error_abort); + qdict =3D keyval_parse("", NULL, NULL, &error_abort); g_assert_cmpuint(qdict_size(qdict), =3D=3D, 0); qobject_unref(qdict); =20 /* Empty key (qemu_opts_parse() accepts this) */ - qdict =3D keyval_parse("=3Dval", NULL, &err); + qdict =3D keyval_parse("=3Dval", NULL, NULL, &err); error_free_or_abort(&err); g_assert(!qdict); =20 /* Empty key fragment */ - qdict =3D keyval_parse(".", NULL, &err); + qdict =3D keyval_parse(".", NULL, NULL, &err); error_free_or_abort(&err); g_assert(!qdict); - qdict =3D keyval_parse("key.", NULL, &err); + qdict =3D keyval_parse("key.", NULL, NULL, &err); error_free_or_abort(&err); g_assert(!qdict); =20 /* Invalid non-empty key (qemu_opts_parse() doesn't care) */ - qdict =3D keyval_parse("7up=3Dval", NULL, &err); + qdict =3D keyval_parse("7up=3Dval", NULL, NULL, &err); error_free_or_abort(&err); g_assert(!qdict); =20 @@ -56,25 +58,25 @@ static void test_keyval_parse(void) long_key[127] =3D 'z'; long_key[128] =3D 0; params =3D g_strdup_printf("k.%s=3Dv", long_key); - qdict =3D keyval_parse(params + 2, NULL, &err); + qdict =3D keyval_parse(params + 2, NULL, NULL, &err); error_free_or_abort(&err); g_assert(!qdict); =20 /* Overlong key fragment */ - qdict =3D keyval_parse(params, NULL, &err); + qdict =3D keyval_parse(params, NULL, NULL, &err); error_free_or_abort(&err); g_assert(!qdict); g_free(params); =20 /* Long key (qemu_opts_parse() accepts and truncates silently) */ params =3D g_strdup_printf("k.%s=3Dv", long_key + 1); - qdict =3D keyval_parse(params + 2, NULL, &error_abort); + qdict =3D keyval_parse(params + 2, NULL, NULL, &error_abort); g_assert_cmpuint(qdict_size(qdict), =3D=3D, 1); g_assert_cmpstr(qdict_get_try_str(qdict, long_key + 1), =3D=3D, "v"); qobject_unref(qdict); =20 /* Long key fragment */ - qdict =3D keyval_parse(params, NULL, &error_abort); + qdict =3D keyval_parse(params, NULL, NULL, &error_abort); g_assert_cmpuint(qdict_size(qdict), =3D=3D, 1); sub_qdict =3D qdict_get_qdict(qdict, "k"); g_assert(sub_qdict); @@ -84,25 +86,25 @@ static void test_keyval_parse(void) g_free(params); =20 /* Crap after valid key */ - qdict =3D keyval_parse("key[0]=3Dval", NULL, &err); + qdict =3D keyval_parse("key[0]=3Dval", NULL, NULL, &err); error_free_or_abort(&err); g_assert(!qdict); =20 /* Multiple keys, last one wins */ - qdict =3D keyval_parse("a=3D1,b=3D2,,x,a=3D3", NULL, &error_abort); + qdict =3D keyval_parse("a=3D1,b=3D2,,x,a=3D3", NULL, NULL, &error_abor= t); g_assert_cmpuint(qdict_size(qdict), =3D=3D, 2); g_assert_cmpstr(qdict_get_try_str(qdict, "a"), =3D=3D, "3"); g_assert_cmpstr(qdict_get_try_str(qdict, "b"), =3D=3D, "2,x"); qobject_unref(qdict); =20 /* Even when it doesn't in qemu_opts_parse() */ - qdict =3D keyval_parse("id=3Dfoo,id=3Dbar", NULL, &error_abort); + qdict =3D keyval_parse("id=3Dfoo,id=3Dbar", NULL, NULL, &error_abort); g_assert_cmpuint(qdict_size(qdict), =3D=3D, 1); g_assert_cmpstr(qdict_get_try_str(qdict, "id"), =3D=3D, "bar"); qobject_unref(qdict); =20 /* Dotted keys */ - qdict =3D keyval_parse("a.b.c=3D1,a.b.c=3D2,d=3D3", NULL, &error_abort= ); + qdict =3D keyval_parse("a.b.c=3D1,a.b.c=3D2,d=3D3", NULL, NULL, &error= _abort); g_assert_cmpuint(qdict_size(qdict), =3D=3D, 2); sub_qdict =3D qdict_get_qdict(qdict, "a"); g_assert(sub_qdict); @@ -115,48 +117,48 @@ static void test_keyval_parse(void) qobject_unref(qdict); =20 /* Inconsistent dotted keys */ - qdict =3D keyval_parse("a.b=3D1,a=3D2", NULL, &err); + qdict =3D keyval_parse("a.b=3D1,a=3D2", NULL, NULL, &err); error_free_or_abort(&err); g_assert(!qdict); - qdict =3D keyval_parse("a.b=3D1,a.b.c=3D2", NULL, &err); + qdict =3D keyval_parse("a.b=3D1,a.b.c=3D2", NULL, NULL, &err); error_free_or_abort(&err); g_assert(!qdict); =20 /* Trailing comma is ignored */ - qdict =3D keyval_parse("x=3Dy,", NULL, &error_abort); + qdict =3D keyval_parse("x=3Dy,", NULL, NULL, &error_abort); g_assert_cmpuint(qdict_size(qdict), =3D=3D, 1); g_assert_cmpstr(qdict_get_try_str(qdict, "x"), =3D=3D, "y"); qobject_unref(qdict); =20 /* Except when it isn't */ - qdict =3D keyval_parse(",", NULL, &err); + qdict =3D keyval_parse(",", NULL, NULL, &err); error_free_or_abort(&err); g_assert(!qdict); =20 /* Value containing ,id=3D not misinterpreted as qemu_opts_parse() doe= s */ - qdict =3D keyval_parse("x=3D,,id=3Dbar", NULL, &error_abort); + qdict =3D keyval_parse("x=3D,,id=3Dbar", NULL, NULL, &error_abort); g_assert_cmpuint(qdict_size(qdict), =3D=3D, 1); g_assert_cmpstr(qdict_get_try_str(qdict, "x"), =3D=3D, ",id=3Dbar"); qobject_unref(qdict); =20 /* Anti-social ID is left to caller (qemu_opts_parse() rejects it) */ - qdict =3D keyval_parse("id=3D666", NULL, &error_abort); + qdict =3D keyval_parse("id=3D666", NULL, NULL, &error_abort); g_assert_cmpuint(qdict_size(qdict), =3D=3D, 1); g_assert_cmpstr(qdict_get_try_str(qdict, "id"), =3D=3D, "666"); qobject_unref(qdict); =20 /* Implied value not supported (unlike qemu_opts_parse()) */ - qdict =3D keyval_parse("an,noaus,noaus=3D", NULL, &err); + qdict =3D keyval_parse("an,noaus,noaus=3D", NULL, NULL, &err); error_free_or_abort(&err); g_assert(!qdict); =20 /* Implied value, key "no" (qemu_opts_parse(): negated empty key) */ - qdict =3D keyval_parse("no", NULL, &err); + qdict =3D keyval_parse("no", NULL, NULL, &err); error_free_or_abort(&err); g_assert(!qdict); =20 /* Implied key */ - qdict =3D keyval_parse("an,aus=3Doff,noaus=3D", "implied", &error_abor= t); + qdict =3D keyval_parse("an,aus=3Doff,noaus=3D", "implied", NULL, &erro= r_abort); g_assert_cmpuint(qdict_size(qdict), =3D=3D, 3); g_assert_cmpstr(qdict_get_try_str(qdict, "implied"), =3D=3D, "an"); g_assert_cmpstr(qdict_get_try_str(qdict, "aus"), =3D=3D, "off"); @@ -164,7 +166,7 @@ static void test_keyval_parse(void) qobject_unref(qdict); =20 /* Implied dotted key */ - qdict =3D keyval_parse("val", "eins.zwei", &error_abort); + qdict =3D keyval_parse("val", "eins.zwei", NULL, &error_abort); g_assert_cmpuint(qdict_size(qdict), =3D=3D, 1); sub_qdict =3D qdict_get_qdict(qdict, "eins"); g_assert(sub_qdict); @@ -173,24 +175,81 @@ static void test_keyval_parse(void) qobject_unref(qdict); =20 /* Implied key with empty value (qemu_opts_parse() accepts this) */ - qdict =3D keyval_parse(",", "implied", &err); + qdict =3D keyval_parse(",", "implied", NULL, &err); error_free_or_abort(&err); g_assert(!qdict); =20 /* Likewise (qemu_opts_parse(): implied key with comma value) */ - qdict =3D keyval_parse(",,,a=3D1", "implied", &err); + qdict =3D keyval_parse(",,,a=3D1", "implied", NULL, &err); error_free_or_abort(&err); g_assert(!qdict); =20 /* Implied key's value can't have comma (qemu_opts_parse(): it can) */ - qdict =3D keyval_parse("val,,ue", "implied", &err); + qdict =3D keyval_parse("val,,ue", "implied", NULL, &err); error_free_or_abort(&err); g_assert(!qdict); =20 /* Empty key is not an implied key */ - qdict =3D keyval_parse("=3Dval", "implied", &err); + qdict =3D keyval_parse("=3Dval", "implied", NULL, &err); error_free_or_abort(&err); g_assert(!qdict); + + /* "help" by itself, without implied key */ + qdict =3D keyval_parse("help", NULL, &help, &error_abort); + g_assert_cmpuint(qdict_size(qdict), =3D=3D, 0); + g_assert(help); + qobject_unref(qdict); + + /* "help" by itself, with implied key */ + qdict =3D keyval_parse("help", "implied", &help, &error_abort); + g_assert_cmpuint(qdict_size(qdict), =3D=3D, 0); + g_assert(help); + qobject_unref(qdict); + + /* "help" when no help is available, without implied key */ + qdict =3D keyval_parse("help", NULL, NULL, &err); + error_free_or_abort(&err); + g_assert(!qdict); + + /* "help" when no help is available, with implied key */ + qdict =3D keyval_parse("help", "implied", NULL, &err); + error_free_or_abort(&err); + g_assert(!qdict); + + /* Key "help" */ + qdict =3D keyval_parse("help=3Don", NULL, &help, &error_abort); + g_assert_cmpuint(qdict_size(qdict), =3D=3D, 1); + g_assert_cmpstr(qdict_get_try_str(qdict, "help"), =3D=3D, "on"); + g_assert(!help); + qobject_unref(qdict); + + /* "help" followed by crap, without implied key */ + qdict =3D keyval_parse("help.abc", NULL, &help, &err); + error_free_or_abort(&err); + g_assert(!qdict); + + /* "help" followed by crap, with implied key */ + qdict =3D keyval_parse("help.abc", "implied", &help, &err); + g_assert_cmpuint(qdict_size(qdict), =3D=3D, 1); + g_assert_cmpstr(qdict_get_try_str(qdict, "implied"), =3D=3D, "help.abc= "); + g_assert(!help); + qobject_unref(qdict); + + /* "help" with other stuff, without implied key */ + qdict =3D keyval_parse("number=3D42,help,foo=3Dbar", NULL, &help, &err= or_abort); + g_assert_cmpuint(qdict_size(qdict), =3D=3D, 2); + g_assert_cmpstr(qdict_get_try_str(qdict, "number"), =3D=3D, "42"); + g_assert_cmpstr(qdict_get_try_str(qdict, "foo"), =3D=3D, "bar"); + g_assert(help); + qobject_unref(qdict); + + /* "help" with other stuff, with implied key */ + qdict =3D keyval_parse("val,help,foo=3Dbar", "implied", &help, &error_= abort); + g_assert_cmpuint(qdict_size(qdict), =3D=3D, 2); + g_assert_cmpstr(qdict_get_try_str(qdict, "implied"), =3D=3D, "val"); + g_assert_cmpstr(qdict_get_try_str(qdict, "foo"), =3D=3D, "bar"); + g_assert(help); + qobject_unref(qdict); } =20 static void check_list012(QList *qlist) @@ -215,26 +274,26 @@ static void test_keyval_parse_list(void) QDict *qdict, *sub_qdict; =20 /* Root can't be a list */ - qdict =3D keyval_parse("0=3D1", NULL, &err); + qdict =3D keyval_parse("0=3D1", NULL, NULL, &err); error_free_or_abort(&err); g_assert(!qdict); =20 /* List elements need not be in order */ - qdict =3D keyval_parse("list.0=3Dnull,list.2=3Dzwei,list.1=3Deins", - NULL, &error_abort); + qdict =3D keyval_parse("list.0=3Dnull,list.2=3Dzwei,list.1=3Deins", NU= LL, NULL, + &error_abort); g_assert_cmpint(qdict_size(qdict), =3D=3D, 1); check_list012(qdict_get_qlist(qdict, "list")); qobject_unref(qdict); =20 /* Multiple indexes, last one wins */ qdict =3D keyval_parse("list.1=3Dgoner,list.0=3Dnull,list.01=3Deins,li= st.2=3Dzwei", - NULL, &error_abort); + NULL, NULL, &error_abort); g_assert_cmpint(qdict_size(qdict), =3D=3D, 1); check_list012(qdict_get_qlist(qdict, "list")); qobject_unref(qdict); =20 /* List at deeper nesting */ - qdict =3D keyval_parse("a.list.1=3Deins,a.list.00=3Dnull,a.list.2=3Dzw= ei", + qdict =3D keyval_parse("a.list.1=3Deins,a.list.00=3Dnull,a.list.2=3Dzw= ei", NULL, NULL, &error_abort); g_assert_cmpint(qdict_size(qdict), =3D=3D, 1); sub_qdict =3D qdict_get_qdict(qdict, "a"); @@ -243,18 +302,19 @@ static void test_keyval_parse_list(void) qobject_unref(qdict); =20 /* Inconsistent dotted keys: both list and dictionary */ - qdict =3D keyval_parse("a.b.c=3D1,a.b.0=3D2", NULL, &err); + qdict =3D keyval_parse("a.b.c=3D1,a.b.0=3D2", NULL, NULL, &err); error_free_or_abort(&err); g_assert(!qdict); - qdict =3D keyval_parse("a.0.c=3D1,a.b.c=3D2", NULL, &err); + qdict =3D keyval_parse("a.0.c=3D1,a.b.c=3D2", NULL, NULL, &err); error_free_or_abort(&err); g_assert(!qdict); =20 /* Missing list indexes */ - qdict =3D keyval_parse("list.1=3Dlonely", NULL, &err); + qdict =3D keyval_parse("list.1=3Dlonely", NULL, NULL, &err); error_free_or_abort(&err); g_assert(!qdict); - qdict =3D keyval_parse("list.0=3Dnull,list.2=3Deins,list.02=3Dzwei", N= ULL, &err); + qdict =3D keyval_parse("list.0=3Dnull,list.2=3Deins,list.02=3Dzwei", N= ULL, NULL, + &err); error_free_or_abort(&err); g_assert(!qdict); } @@ -266,7 +326,7 @@ static void test_keyval_visit_bool(void) QDict *qdict; bool b; =20 - qdict =3D keyval_parse("bool1=3Don,bool2=3Doff", NULL, &error_abort); + qdict =3D keyval_parse("bool1=3Don,bool2=3Doff", NULL, NULL, &error_ab= ort); v =3D qobject_input_visitor_new_keyval(QOBJECT(qdict)); qobject_unref(qdict); visit_start_struct(v, NULL, NULL, 0, &error_abort); @@ -278,7 +338,7 @@ static void test_keyval_visit_bool(void) visit_end_struct(v, NULL); visit_free(v); =20 - qdict =3D keyval_parse("bool1=3Doffer", NULL, &error_abort); + qdict =3D keyval_parse("bool1=3Doffer", NULL, NULL, &error_abort); v =3D qobject_input_visitor_new_keyval(QOBJECT(qdict)); qobject_unref(qdict); visit_start_struct(v, NULL, NULL, 0, &error_abort); @@ -296,7 +356,7 @@ static void test_keyval_visit_number(void) uint64_t u; =20 /* Lower limit zero */ - qdict =3D keyval_parse("number1=3D0", NULL, &error_abort); + qdict =3D keyval_parse("number1=3D0", NULL, NULL, &error_abort); v =3D qobject_input_visitor_new_keyval(QOBJECT(qdict)); qobject_unref(qdict); visit_start_struct(v, NULL, NULL, 0, &error_abort); @@ -307,7 +367,7 @@ static void test_keyval_visit_number(void) visit_free(v); =20 /* Upper limit 2^64-1 */ - qdict =3D keyval_parse("number1=3D18446744073709551615,number2=3D-1", + qdict =3D keyval_parse("number1=3D18446744073709551615,number2=3D-1", = NULL, NULL, &error_abort); v =3D qobject_input_visitor_new_keyval(QOBJECT(qdict)); qobject_unref(qdict); @@ -321,8 +381,8 @@ static void test_keyval_visit_number(void) visit_free(v); =20 /* Above upper limit */ - qdict =3D keyval_parse("number1=3D18446744073709551616", - NULL, &error_abort); + qdict =3D keyval_parse("number1=3D18446744073709551616", NULL, NULL, + &error_abort); v =3D qobject_input_visitor_new_keyval(QOBJECT(qdict)); qobject_unref(qdict); visit_start_struct(v, NULL, NULL, 0, &error_abort); @@ -332,8 +392,8 @@ static void test_keyval_visit_number(void) visit_free(v); =20 /* Below lower limit */ - qdict =3D keyval_parse("number1=3D-18446744073709551616", - NULL, &error_abort); + qdict =3D keyval_parse("number1=3D-18446744073709551616", NULL, NULL, + &error_abort); v =3D qobject_input_visitor_new_keyval(QOBJECT(qdict)); qobject_unref(qdict); visit_start_struct(v, NULL, NULL, 0, &error_abort); @@ -343,8 +403,7 @@ static void test_keyval_visit_number(void) visit_free(v); =20 /* Hex and octal */ - qdict =3D keyval_parse("number1=3D0x2a,number2=3D052", - NULL, &error_abort); + qdict =3D keyval_parse("number1=3D0x2a,number2=3D052", NULL, NULL, &er= ror_abort); v =3D qobject_input_visitor_new_keyval(QOBJECT(qdict)); qobject_unref(qdict); visit_start_struct(v, NULL, NULL, 0, &error_abort); @@ -357,8 +416,7 @@ static void test_keyval_visit_number(void) visit_free(v); =20 /* Trailing crap */ - qdict =3D keyval_parse("number1=3D3.14,number2=3D08", - NULL, &error_abort); + qdict =3D keyval_parse("number1=3D3.14,number2=3D08", NULL, NULL, &err= or_abort); v =3D qobject_input_visitor_new_keyval(QOBJECT(qdict)); qobject_unref(qdict); visit_start_struct(v, NULL, NULL, 0, &error_abort); @@ -378,7 +436,7 @@ static void test_keyval_visit_size(void) uint64_t sz; =20 /* Lower limit zero */ - qdict =3D keyval_parse("sz1=3D0", NULL, &error_abort); + qdict =3D keyval_parse("sz1=3D0", NULL, NULL, &error_abort); v =3D qobject_input_visitor_new_keyval(QOBJECT(qdict)); qobject_unref(qdict); visit_start_struct(v, NULL, NULL, 0, &error_abort); @@ -394,7 +452,7 @@ static void test_keyval_visit_size(void) qdict =3D keyval_parse("sz1=3D9007199254740991," "sz2=3D9007199254740992," "sz3=3D9007199254740993", - NULL, &error_abort); + NULL, NULL, &error_abort); v =3D qobject_input_visitor_new_keyval(QOBJECT(qdict)); qobject_unref(qdict); visit_start_struct(v, NULL, NULL, 0, &error_abort); @@ -411,7 +469,7 @@ static void test_keyval_visit_size(void) /* Close to signed upper limit 0x7ffffffffffffc00 (53 msbs set) */ qdict =3D keyval_parse("sz1=3D9223372036854774784," /* 7ffffffffffffc0= 0 */ "sz2=3D9223372036854775295", /* 7ffffffffffffdff = */ - NULL, &error_abort); + NULL, NULL, &error_abort); v =3D qobject_input_visitor_new_keyval(QOBJECT(qdict)); qobject_unref(qdict); visit_start_struct(v, NULL, NULL, 0, &error_abort); @@ -426,7 +484,7 @@ static void test_keyval_visit_size(void) /* Close to actual upper limit 0xfffffffffffff800 (53 msbs set) */ qdict =3D keyval_parse("sz1=3D18446744073709549568," /* fffffffffffff8= 00 */ "sz2=3D18446744073709550591", /* fffffffffffffbff= */ - NULL, &error_abort); + NULL, NULL, &error_abort); v =3D qobject_input_visitor_new_keyval(QOBJECT(qdict)); qobject_unref(qdict); visit_start_struct(v, NULL, NULL, 0, &error_abort); @@ -441,7 +499,7 @@ static void test_keyval_visit_size(void) /* Beyond limits */ qdict =3D keyval_parse("sz1=3D-1," "sz2=3D18446744073709550592", /* fffffffffffffc00= */ - NULL, &error_abort); + NULL, NULL, &error_abort); v =3D qobject_input_visitor_new_keyval(QOBJECT(qdict)); qobject_unref(qdict); visit_start_struct(v, NULL, NULL, 0, &error_abort); @@ -454,7 +512,7 @@ static void test_keyval_visit_size(void) =20 /* Suffixes */ qdict =3D keyval_parse("sz1=3D8b,sz2=3D1.5k,sz3=3D2M,sz4=3D0.1G,sz5=3D= 16777215T", - NULL, &error_abort); + NULL, NULL, &error_abort); v =3D qobject_input_visitor_new_keyval(QOBJECT(qdict)); qobject_unref(qdict); visit_start_struct(v, NULL, NULL, 0, &error_abort); @@ -473,7 +531,7 @@ static void test_keyval_visit_size(void) visit_free(v); =20 /* Beyond limit with suffix */ - qdict =3D keyval_parse("sz1=3D16777216T", NULL, &error_abort); + qdict =3D keyval_parse("sz1=3D16777216T", NULL, NULL, &error_abort); v =3D qobject_input_visitor_new_keyval(QOBJECT(qdict)); qobject_unref(qdict); visit_start_struct(v, NULL, NULL, 0, &error_abort); @@ -483,7 +541,7 @@ static void test_keyval_visit_size(void) visit_free(v); =20 /* Trailing crap */ - qdict =3D keyval_parse("sz1=3D0Z,sz2=3D16Gi", NULL, &error_abort); + qdict =3D keyval_parse("sz1=3D0Z,sz2=3D16Gi", NULL, NULL, &error_abort= ); v =3D qobject_input_visitor_new_keyval(QOBJECT(qdict)); qobject_unref(qdict); visit_start_struct(v, NULL, NULL, 0, &error_abort); @@ -502,7 +560,7 @@ static void test_keyval_visit_dict(void) QDict *qdict; int64_t i; =20 - qdict =3D keyval_parse("a.b.c=3D1,a.b.c=3D2,d=3D3", NULL, &error_abort= ); + qdict =3D keyval_parse("a.b.c=3D1,a.b.c=3D2,d=3D3", NULL, NULL, &error= _abort); v =3D qobject_input_visitor_new_keyval(QOBJECT(qdict)); qobject_unref(qdict); visit_start_struct(v, NULL, NULL, 0, &error_abort); @@ -520,7 +578,7 @@ static void test_keyval_visit_dict(void) visit_end_struct(v, NULL); visit_free(v); =20 - qdict =3D keyval_parse("a.b=3D", NULL, &error_abort); + qdict =3D keyval_parse("a.b=3D", NULL, NULL, &error_abort); v =3D qobject_input_visitor_new_keyval(QOBJECT(qdict)); qobject_unref(qdict); visit_start_struct(v, NULL, NULL, 0, &error_abort); @@ -542,7 +600,7 @@ static void test_keyval_visit_list(void) QDict *qdict; char *s; =20 - qdict =3D keyval_parse("a.0=3D,a.1=3DI,a.2.0=3DII", NULL, &error_abort= ); + qdict =3D keyval_parse("a.0=3D,a.1=3DI,a.2.0=3DII", NULL, NULL, &error= _abort); /* TODO empty list */ v =3D qobject_input_visitor_new_keyval(QOBJECT(qdict)); qobject_unref(qdict); @@ -566,7 +624,7 @@ static void test_keyval_visit_list(void) visit_end_struct(v, NULL); visit_free(v); =20 - qdict =3D keyval_parse("a.0=3D,b.0.0=3Dhead", NULL, &error_abort); + qdict =3D keyval_parse("a.0=3D,b.0.0=3Dhead", NULL, NULL, &error_abort= ); v =3D qobject_input_visitor_new_keyval(QOBJECT(qdict)); qobject_unref(qdict); visit_start_struct(v, NULL, NULL, 0, &error_abort); @@ -595,7 +653,7 @@ static void test_keyval_visit_optional(void) bool present; int64_t i; =20 - qdict =3D keyval_parse("a.b=3D1", NULL, &error_abort); + qdict =3D keyval_parse("a.b=3D1", NULL, NULL, &error_abort); v =3D qobject_input_visitor_new_keyval(QOBJECT(qdict)); qobject_unref(qdict); visit_start_struct(v, NULL, NULL, 0, &error_abort); @@ -631,7 +689,7 @@ static void test_keyval_visit_alternate(void) * the string variant if there is one, else an error. * TODO make it work for unambiguous cases like AltEnumBool below */ - qdict =3D keyval_parse("a=3D1,b=3D2,c=3Don", NULL, &error_abort); + qdict =3D keyval_parse("a=3D1,b=3D2,c=3Don", NULL, NULL, &error_abort); v =3D qobject_input_visitor_new_keyval(QOBJECT(qdict)); qobject_unref(qdict); visit_start_struct(v, NULL, NULL, 0, &error_abort); @@ -655,7 +713,7 @@ static void test_keyval_visit_any(void) QList *qlist; QString *qstr; =20 - qdict =3D keyval_parse("a.0=3Dnull,a.1=3D1", NULL, &error_abort); + qdict =3D keyval_parse("a.0=3Dnull,a.1=3D1", NULL, NULL, &error_abort); v =3D qobject_input_visitor_new_keyval(QOBJECT(qdict)); qobject_unref(qdict); visit_start_struct(v, NULL, NULL, 0, &error_abort); diff --git a/util/keyval.c b/util/keyval.c index 8f33a36a7c..14fdd364fa 100644 --- a/util/keyval.c +++ b/util/keyval.c @@ -14,10 +14,11 @@ * KEY=3DVALUE,... syntax: * * key-vals =3D [ key-val { ',' key-val } [ ',' ] ] - * key-val =3D key '=3D' val + * key-val =3D key '=3D' val | help * key =3D key-fragment { '.' key-fragment } * key-fragment =3D / [^=3D,.]+ / * val =3D { / [^,]+ / | ',,' } + * help =3D 'help | '?' * * Semantics defined by reduction to JSON: * @@ -54,6 +55,9 @@ * * The length of any key-fragment must be between 1 and 127. * + * If any key-val is help, the object is to be treated as a help + * request. + * * Design flaw: there is no way to denote an empty array or non-root * object. While interpreting "key absent" as empty seems natural * (removing a key-val from the input string removes the member when @@ -75,7 +79,7 @@ * * key-vals =3D [ key-val-1st { ',' key-val } [ ',' ] ] * key-val-1st =3D val-no-key | key-val - * val-no-key =3D / [^=3D,]+ / + * val-no-key =3D / [^=3D,]+ / - help * * where val-no-key is syntactic sugar for implied-key=3Dval-no-key. * @@ -89,6 +93,7 @@ #include "qapi/qmp/qlist.h" #include "qapi/qmp/qstring.h" #include "qemu/cutils.h" +#include "qemu/help_option.h" #include "qemu/option.h" =20 /* @@ -162,15 +167,20 @@ static QObject *keyval_parse_put(QDict *cur, } =20 /* - * Parse one KEY=3DVALUE from @params, store result in @qdict. + * Parse one parameter from @params. + * + * If we're looking at KEY=3DVALUE, store result in @qdict. * The first fragment of KEY applies to @qdict. Subsequent fragments * apply to nested QDicts, which are created on demand. @implied_key * is as in keyval_parse(). - * On success, return a pointer to the next KEY=3DVALUE, or else to '\0'. + * + * If we're looking at "help" or "?", set *help to true. + * + * On success, return a pointer to the next parameter, or else to '\0'. * On failure, return NULL. */ static const char *keyval_parse_one(QDict *qdict, const char *params, - const char *implied_key, + const char *implied_key, bool *help, Error **errp) { const char *key, *key_end, *val_end, *s, *end; @@ -184,11 +194,21 @@ static const char *keyval_parse_one(QDict *qdict, con= st char *params, key =3D params; val_end =3D NULL; len =3D strcspn(params, "=3D,"); - if (implied_key && len && key[len] !=3D '=3D') { - /* Desugar implied key */ - key =3D implied_key; - val_end =3D params + len; - len =3D strlen(implied_key); + if (len && key[len] !=3D '=3D') { + if (starts_with_help_option(key) =3D=3D len) { + *help =3D true; + s =3D key + len; + if (*s =3D=3D ',') { + s++; + } + return s; + } + if (implied_key) { + /* Desugar implied key */ + key =3D implied_key; + val_end =3D params + len; + len =3D strlen(implied_key); + } } key_end =3D key + len; =20 @@ -398,21 +418,32 @@ static QObject *keyval_listify(QDict *cur, GSList *ke= y_of_cur, Error **errp) =20 /* * Parse @params in QEMU's traditional KEY=3DVALUE,... syntax. + * * If @implied_key, the first KEY=3D can be omitted. @implied_key is * implied then, and VALUE can't be empty or contain ',' or '=3D'. + * + * A parameter "help" or "?" without a value isn't added to the + * resulting dictionary, but instead is interpreted as help request. + * All other options are parsed and returned normally so that context + * specific help can be printed. + * + * If @p_help is not NULL, store whether help is requested there. + * If @p_help is NULL and help is requested, fail. + * * On success, return a dictionary of the parsed keys and values. * On failure, store an error through @errp and return NULL. */ QDict *keyval_parse(const char *params, const char *implied_key, - Error **errp) + bool *p_help, Error **errp) { QDict *qdict =3D qdict_new(); QObject *listified; const char *s; + bool help =3D false; =20 s =3D params; while (*s) { - s =3D keyval_parse_one(qdict, s, implied_key, errp); + s =3D keyval_parse_one(qdict, s, implied_key, &help, errp); if (!s) { qobject_unref(qdict); return NULL; @@ -420,6 +451,14 @@ QDict *keyval_parse(const char *params, const char *im= plied_key, implied_key =3D NULL; } =20 + if (p_help) { + *p_help =3D help; + } else if (help) { + error_setg(errp, "Help is not available for this option"); + qobject_unref(qdict); + return NULL; + } + listified =3D keyval_listify(qdict, NULL, errp); if (!listified) { qobject_unref(qdict); --=20 2.26.2 From nobody Sun May 12 11:08:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602401807; cv=none; d=zohomail.com; s=zohoarc; b=Mc7E9QmFYOd5+kybASR6MdhDyrZXZbPdj3MYq8fS9iGplSNSTsy8/56mAfwYf2lQ6tIJl/CfofJuaeEdlgtYPgQkRmlSckm7tQSFYn7g8hVw+jfrIppbOHnwW0M0FwgYlwnVWUBvFiO9zssJB8YOpa1+M76q6Da083h4hKYF6FI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602401807; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=XKop1u7RPhHp0tHVpIDvStALvns7nF1iAQPtk7a6IfE=; b=fKy7eHpPMtZvamlYriKrLgPyoKG4sVjH6BcqNH/XCbfaeuicAe2t1QqXbniE+Z2fV2LHYqFXr6k2bBvopwiy+KU23r2b4CGIo+QtSdBvKAAh0xgX0yHKi8N2Wk1y5muRsTMnANsPyNTyw74ncWd8jvs/qXENkVwAiE2H2IAxXOI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602401807764948.7684102561025; Sun, 11 Oct 2020 00:36:47 -0700 (PDT) Received: from localhost ([::1]:41534 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kRVuQ-0008Fr-KW for importer@patchew.org; Sun, 11 Oct 2020 03:36:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35906) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kRVt2-0006FH-7p for qemu-devel@nongnu.org; Sun, 11 Oct 2020 03:35:20 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:31676) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kRVsx-0003Gx-Ff for qemu-devel@nongnu.org; Sun, 11 Oct 2020 03:35:19 -0400 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-368-GmX4ENotP1GrqXiIhZQIlA-1; Sun, 11 Oct 2020 03:35:09 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 454301005E5C; Sun, 11 Oct 2020 07:35:08 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-182.ams2.redhat.com [10.36.112.182]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1362A10013C1; Sun, 11 Oct 2020 07:35:08 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 226CA112CE14; Sun, 11 Oct 2020 09:35:05 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602401711; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XKop1u7RPhHp0tHVpIDvStALvns7nF1iAQPtk7a6IfE=; b=C6Ip1pGAfhDhLiIUDV+4I2P8VrvGl6Bhw6ReqCTyt3XyiyRdNxBgS5CND7wGCXyG6nZBcS MlRnxQMHBKYd8ZYuHLwxwMwNvNAYvatRh2vvEX94nTBKwhYjQX0hpZf+Gx8HFoqVIkyUez VJ/zUxX2VlXGSKoerYJb4lkZnhjyykw= X-MC-Unique: GmX4ENotP1GrqXiIhZQIlA-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v4 5/7] qom: Factor out helpers from user_creatable_print_help() Date: Sun, 11 Oct 2020 09:35:03 +0200 Message-Id: <20201011073505.1185335-6-armbru@redhat.com> In-Reply-To: <20201011073505.1185335-1-armbru@redhat.com> References: <20201011073505.1185335-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/11 00:55:29 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Kevin Wolf This creates separate helper functions for printing a list of user creatable object types and for printing a list of properties of a given type. This will allow using these parts without having a QemuOpts. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: Markus Armbruster --- qom/object_interfaces.c | 90 ++++++++++++++++++++++++----------------- 1 file changed, 52 insertions(+), 38 deletions(-) diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c index e8e1523960..3fd1da157e 100644 --- a/qom/object_interfaces.c +++ b/qom/object_interfaces.c @@ -214,52 +214,66 @@ char *object_property_help(const char *name, const ch= ar *type, return g_string_free(str, false); } =20 -bool user_creatable_print_help(const char *type, QemuOpts *opts) +static void user_creatable_print_types(void) +{ + GSList *l, *list; + + printf("List of user creatable objects:\n"); + list =3D object_class_get_list_sorted(TYPE_USER_CREATABLE, false); + for (l =3D list; l !=3D NULL; l =3D l->next) { + ObjectClass *oc =3D OBJECT_CLASS(l->data); + printf(" %s\n", object_class_get_name(oc)); + } + g_slist_free(list); +} + +static bool user_creatable_print_type_properites(const char *type) { ObjectClass *klass; + ObjectPropertyIterator iter; + ObjectProperty *prop; + GPtrArray *array; + int i; =20 - if (is_help_option(type)) { - GSList *l, *list; + klass =3D object_class_by_name(type); + if (!klass) { + return false; + } =20 - printf("List of user creatable objects:\n"); - list =3D object_class_get_list_sorted(TYPE_USER_CREATABLE, false); - for (l =3D list; l !=3D NULL; l =3D l->next) { - ObjectClass *oc =3D OBJECT_CLASS(l->data); - printf(" %s\n", object_class_get_name(oc)); + array =3D g_ptr_array_new(); + object_class_property_iter_init(&iter, klass); + while ((prop =3D object_property_iter_next(&iter))) { + if (!prop->set) { + continue; } - g_slist_free(list); + + g_ptr_array_add(array, + object_property_help(prop->name, prop->type, + prop->defval, prop->descripti= on)); + } + g_ptr_array_sort(array, (GCompareFunc)qemu_pstrcmp0); + if (array->len > 0) { + printf("%s options:\n", type); + } else { + printf("There are no options for %s.\n", type); + } + for (i =3D 0; i < array->len; i++) { + printf("%s\n", (char *)array->pdata[i]); + } + g_ptr_array_set_free_func(array, g_free); + g_ptr_array_free(array, true); + return true; +} + +bool user_creatable_print_help(const char *type, QemuOpts *opts) +{ + if (is_help_option(type)) { + user_creatable_print_types(); return true; } =20 - klass =3D object_class_by_name(type); - if (klass && qemu_opt_has_help_opt(opts)) { - ObjectPropertyIterator iter; - ObjectProperty *prop; - GPtrArray *array =3D g_ptr_array_new(); - int i; - - object_class_property_iter_init(&iter, klass); - while ((prop =3D object_property_iter_next(&iter))) { - if (!prop->set) { - continue; - } - - g_ptr_array_add(array, - object_property_help(prop->name, prop->type, - prop->defval, prop->descr= iption)); - } - g_ptr_array_sort(array, (GCompareFunc)qemu_pstrcmp0); - if (array->len > 0) { - printf("%s options:\n", type); - } else { - printf("There are no options for %s.\n", type); - } - for (i =3D 0; i < array->len; i++) { - printf("%s\n", (char *)array->pdata[i]); - } - g_ptr_array_set_free_func(array, g_free); - g_ptr_array_free(array, true); - return true; + if (qemu_opt_has_help_opt(opts)) { + return user_creatable_print_type_properites(type); } =20 return false; --=20 2.26.2 From nobody Sun May 12 11:08:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602401806; cv=none; d=zohomail.com; s=zohoarc; b=WeosENTAQwegfSIgX5/KU27bIgwtuuJCax/OSwU41qADz7n/GHRn6Bt9k407GVmxncwCLMGs3zY5LLm7DAiWbiNbkNyhbJnWllfGVCV/8+2Q69VvuHazYqTmm8QoSKEulB3arhDs+uum19hJsfBJE4H6aj92/5XAflcP7+HDMSQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602401806; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=2jndvphJf6bhjIWF1IlqwE7u2yBn/WmGzn8tICZ1U2c=; b=ToSGUT5/sMIluxHSwAMWGWtB8o9kwvh9b6aEfjtqzbkSyWAgcXzO7g9wUr6wvVx0w1bycBv1x+D2BCEGm5GtsVRBIN24GAfDW3SVT7tsbIbT0z+Q7e/CxBewPflDPPBcsdFniM4MY6CSS3qFxnFOm3x3uFW3v6vvzkfBf7QOoIQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602401806832576.761764185274; Sun, 11 Oct 2020 00:36:46 -0700 (PDT) Received: from localhost ([::1]:41448 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kRVuP-0008Ds-GP for importer@patchew.org; Sun, 11 Oct 2020 03:36:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35860) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kRVsz-0006Dn-QJ for qemu-devel@nongnu.org; Sun, 11 Oct 2020 03:35:18 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:23694) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kRVsu-0003Gl-00 for qemu-devel@nongnu.org; Sun, 11 Oct 2020 03:35:17 -0400 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-561-kdPdQbPQM7OFWogbdncHig-1; Sun, 11 Oct 2020 03:35:09 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4412B10054FF; Sun, 11 Oct 2020 07:35:08 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-182.ams2.redhat.com [10.36.112.182]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 137985D9CC; Sun, 11 Oct 2020 07:35:08 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 25B9C112CE16; Sun, 11 Oct 2020 09:35:05 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602401711; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2jndvphJf6bhjIWF1IlqwE7u2yBn/WmGzn8tICZ1U2c=; b=C8Kkiu/l7ZtSSUbcMeZZM97zAS/qbwrOP6YqXVSUer/CWQEChkSkqEguSthz6KDH/CEbJl ekWgIR2z/WkRxgYWBEMmuXb1OuBG7am7cBi6ExFfX62j9TUlT02vZXIVfw50+f/Swqin2S L/p0uUNP+7KIVZIVLX7t6kCVng97Kjo= X-MC-Unique: kdPdQbPQM7OFWogbdncHig-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v4 6/7] qom: Add user_creatable_print_help_from_qdict() Date: Sun, 11 Oct 2020 09:35:04 +0200 Message-Id: <20201011073505.1185335-7-armbru@redhat.com> In-Reply-To: <20201011073505.1185335-1-armbru@redhat.com> References: <20201011073505.1185335-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/11 02:10:40 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Kevin Wolf This adds a function that, given a QDict of non-help options, prints help for user creatable objects. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: Markus Armbruster --- include/qom/object_interfaces.h | 21 ++++++++++++++++++--- qom/object_interfaces.c | 9 +++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/include/qom/object_interfaces.h b/include/qom/object_interface= s.h index f118fb516b..07d5cc8832 100644 --- a/include/qom/object_interfaces.h +++ b/include/qom/object_interfaces.h @@ -154,13 +154,28 @@ int user_creatable_add_opts_foreach(void *opaque, * @type: the QOM type to be added * @opts: options to create * - * Prints help if requested in @opts. + * Prints help if requested in @type or @opts. Note that if @type is neith= er + * "help"/"?" nor a valid user creatable type, no help will be printed + * regardless of @opts. * - * Returns: true if @opts contained a help option and help was printed, fa= lse - * if no help option was found. + * Returns: true if a help option was found and help was printed, false + * otherwise. */ bool user_creatable_print_help(const char *type, QemuOpts *opts); =20 +/** + * user_creatable_print_help_from_qdict: + * @args: options to create + * + * Prints help considering the other options given in @args (if "qom-type"= is + * given and valid, print properties for the type, otherwise print valid t= ypes) + * + * In contrast to user_creatable_print_help(), this function can't return = that + * no help was requested. It should only be called if we know that help is + * requested and it will always print some help. + */ +void user_creatable_print_help_from_qdict(QDict *args); + /** * user_creatable_del: * @id: the unique ID for the object diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c index 3fd1da157e..ed896fe764 100644 --- a/qom/object_interfaces.c +++ b/qom/object_interfaces.c @@ -279,6 +279,15 @@ bool user_creatable_print_help(const char *type, QemuO= pts *opts) return false; } =20 +void user_creatable_print_help_from_qdict(QDict *args) +{ + const char *type =3D qdict_get_try_str(args, "qom-type"); + + if (!type || !user_creatable_print_type_properites(type)) { + user_creatable_print_types(); + } +} + bool user_creatable_del(const char *id, Error **errp) { Object *container; --=20 2.26.2 From nobody Sun May 12 11:08:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602401842; cv=none; d=zohomail.com; s=zohoarc; b=K73lsmlGipsAp2VsZdzdNshCbP8VrMMsuC5aQxCkr0SYBHOdf4n0csvridr2mnwkQAkyrRMepO4W6Rj/hUP/7LqqW+PLpUWBeZYQXik+2jZdL89k0tH9ZYeC4en+2JKbzEIB2g/xUckw/M9CffGKO+tBVjUtpH9nHkffzU7bu5M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602401842; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=GX/HabaKBqEVmDHPN8PoGq+SKbFdVtXttZ72lwfKSO4=; b=n+GzsMsU2iHYbCDZFwlfI3DYAoZznUi/E0ex2KCTWSDyssnxvqAHcu8kMhixUQaUvbSuzpc6yEj1O6Hbs9hwlFQlQ3Co0qOWTWZGePYOIzEbVjtsYM38CVGc92L3uV6FiraLsOSHiTjWenWsD/O3Fo/l6f00NnaOB6bvG7P+yiI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602401842664440.5160277429119; Sun, 11 Oct 2020 00:37:22 -0700 (PDT) Received: from localhost ([::1]:43444 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kRVuz-0000b2-Ek for importer@patchew.org; Sun, 11 Oct 2020 03:37:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35924) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kRVt3-0006K3-Jk for qemu-devel@nongnu.org; Sun, 11 Oct 2020 03:35:21 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:44691) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kRVsx-0003Gz-ME for qemu-devel@nongnu.org; Sun, 11 Oct 2020 03:35:21 -0400 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-368-uX0rMu7GN0qs6flFof_2-A-1; Sun, 11 Oct 2020 03:35:09 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 42EC7427F4; Sun, 11 Oct 2020 07:35:08 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-182.ams2.redhat.com [10.36.112.182]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1368076663; Sun, 11 Oct 2020 07:35:08 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 29009112CE18; Sun, 11 Oct 2020 09:35:05 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602401711; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GX/HabaKBqEVmDHPN8PoGq+SKbFdVtXttZ72lwfKSO4=; b=hyiX3C9y6vryLd7PAheURWpcH39ax9VElbSHXiMu6TI/N0bwF9xEPNvfLQ5AoX7ez8Vj+O +CrovfLo1keG3/2/kfiFjLNmb24hljjZqxflacP2vU29qTaCsgj4D4Bp18JHFgOuT3QNqC +9M2EON/KzjGSeNkmBZ64/UaJC2VKFQ= X-MC-Unique: uX0rMu7GN0qs6flFof_2-A-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v4 7/7] qemu-storage-daemon: Remove QemuOpts from --object parser Date: Sun, 11 Oct 2020 09:35:05 +0200 Message-Id: <20201011073505.1185335-8-armbru@redhat.com> In-Reply-To: <20201011073505.1185335-1-armbru@redhat.com> References: <20201011073505.1185335-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/11 00:55:29 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Kevin Wolf The command line parser for --object parses the input twice: Once into QemuOpts just for detecting help options, and then again into a QDict using the keyval parser for actually creating the object. Now that the keyval parser can also detect help options, we can simplify this and remove the QemuOpts part. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: Markus Armbruster --- storage-daemon/qemu-storage-daemon.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/storage-daemon/qemu-storage-daemon.c b/storage-daemon/qemu-sto= rage-daemon.c index 6f0e0cfb36..e419ba9f19 100644 --- a/storage-daemon/qemu-storage-daemon.c +++ b/storage-daemon/qemu-storage-daemon.c @@ -264,21 +264,14 @@ static void process_options(int argc, char *argv[]) } case OPTION_OBJECT: { - QemuOpts *opts; - const char *type; QDict *args; + bool help; =20 - /* FIXME The keyval parser rejects 'help' arguments, so we= must - * unconditionall try QemuOpts first. */ - opts =3D qemu_opts_parse(&qemu_object_opts, - optarg, true, &error_fatal); - type =3D qemu_opt_get(opts, "qom-type"); - if (type && user_creatable_print_help(type, opts)) { + args =3D keyval_parse(optarg, "qom-type", &help, &error_fa= tal); + if (help) { + user_creatable_print_help_from_qdict(args); exit(EXIT_SUCCESS); } - qemu_opts_del(opts); - - args =3D keyval_parse(optarg, "qom-type", NULL, &error_fat= al); user_creatable_add_dict(args, true, &error_fatal); qobject_unref(args); break; --=20 2.26.2