From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B4ABEC433F5 for ; Thu, 21 Oct 2021 10:05:05 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2EDB4610D0 for ; Thu, 21 Oct 2021 10:05:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 2EDB4610D0 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=proxmox.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:48320 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mdUwZ-0003i3-Q5 for qemu-devel@archiver.kernel.org; Thu, 21 Oct 2021 06:05:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55684) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mdUtQ-0001gw-5f for qemu-devel@nongnu.org; Thu, 21 Oct 2021 06:01:48 -0400 Received: from proxmox-new.maurer-it.com ([94.136.29.106]:62483) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mdUtN-0002mZ-57 for qemu-devel@nongnu.org; Thu, 21 Oct 2021 06:01:47 -0400 Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 2B8EE468EF; Thu, 21 Oct 2021 12:01:41 +0200 (CEST) From: Stefan Reiter To: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , "Dr. David Alan Gilbert" , Markus Armbruster , Paolo Bonzini , Eric Blake , Gerd Hoffmann , Wolfgang Bumiller , Thomas Lamprecht Subject: [PATCH v7 1/4] monitor/hmp: add support for flag argument with value Date: Thu, 21 Oct 2021 12:01:32 +0200 Message-Id: <20211021100135.4146766-2-s.reiter@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211021100135.4146766-1-s.reiter@proxmox.com> References: <20211021100135.4146766-1-s.reiter@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=94.136.29.106; envelope-from=s.reiter@proxmox.com; helo=proxmox-new.maurer-it.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, 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: qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Adds support for the "-xV" parameter type, where "-x" denotes a flag name and the "V" suffix indicates that this flag is supposed to take an arbitrary string parameter. These parameters are always optional, the entry in the qdict will be omitted if the flag is not given. Signed-off-by: Stefan Reiter --- v6: It wasn't possible to pass the 'connected' parameter to set_password, since the code to handle optional parameters couldn't live with a different param (not starting with '-') coming up instead - fix that by advancing over the 'value flag' modifier in case `*p != '-'`. Also change the modifier to 'V' instead of 'S' so it can be distinguished from an actual trailing 'S' type param. Discovered in testing. I dropped Eric's R-b due to the code change. monitor/hmp.c | 19 ++++++++++++++++++- monitor/monitor-internal.h | 3 ++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/monitor/hmp.c b/monitor/hmp.c index d50c3124e1..899e0c990f 100644 --- a/monitor/hmp.c +++ b/monitor/hmp.c @@ -980,6 +980,7 @@ static QDict *monitor_parse_arguments(Monitor *mon, { const char *tmp = p; int skip_key = 0; + int ret; /* option */ c = *typestr++; @@ -1002,11 +1003,27 @@ static QDict *monitor_parse_arguments(Monitor *mon, } if (skip_key) { p = tmp; + } else if (*typestr == 'V') { + /* has option with string value */ + typestr++; + tmp = p++; + while (qemu_isspace(*p)) { + p++; + } + ret = get_str(buf, sizeof(buf), &p); + if (ret < 0) { + monitor_printf(mon, "%s: value expected for -%c\n", + cmd->name, *tmp); + goto fail; + } + qdict_put_str(qdict, key, buf); } else { - /* has option */ + /* has boolean option */ p++; qdict_put_bool(qdict, key, true); } + } else if (*typestr == 'V') { + typestr++; } } break; diff --git a/monitor/monitor-internal.h b/monitor/monitor-internal.h index 9c3a09cb01..9e708b329d 100644 --- a/monitor/monitor-internal.h +++ b/monitor/monitor-internal.h @@ -63,7 +63,8 @@ * '.' other form of optional type (for 'i' and 'l') * 'b' boolean * user mode accepts "on" or "off" - * '-' optional parameter (eg. '-f') + * '-' optional parameter (eg. '-f'); if followed by an 'V', it + * specifies an optional string param (e.g. '-fV' allows '-f foo') * */ -- 2.30.2