From patchwork Thu Sep 10 15:18:48 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark McLoughlin X-Patchwork-Id: 33330 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by bilbo.ozlabs.org (Postfix) with ESMTPS id E6A1AB7067 for ; Fri, 11 Sep 2009 01:43:16 +1000 (EST) Received: from localhost ([127.0.0.1]:49706 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mllnm-0005YX-4u for incoming@patchwork.ozlabs.org; Thu, 10 Sep 2009 11:43:14 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MllXz-0006H0-UJ for qemu-devel@nongnu.org; Thu, 10 Sep 2009 11:26:57 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MllXt-0006Cs-3L for qemu-devel@nongnu.org; Thu, 10 Sep 2009 11:26:53 -0400 Received: from [199.232.76.173] (port=40179 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MllXs-0006Co-NV for qemu-devel@nongnu.org; Thu, 10 Sep 2009 11:26:48 -0400 Received: from mail06.svc.cra.dublin.eircom.net ([159.134.118.22]:34308) by monty-python.gnu.org with smtp (Exim 4.60) (envelope-from ) id 1MllXs-00007A-3t for qemu-devel@nongnu.org; Thu, 10 Sep 2009 11:26:48 -0400 Received: (qmail 7632 messnum 12831029 invoked from network[83.71.108.236/83-71-108-236-dynamic.b-ras1.srl.dublin.eircom.net]); 10 Sep 2009 15:20:05 -0000 Received: from 83-71-108-236-dynamic.b-ras1.srl.dublin.eircom.net (HELO blaa.localdomain) (83.71.108.236) by mail06.svc.cra.dublin.eircom.net (qp 7632) with SMTP; 10 Sep 2009 15:20:05 -0000 Received: by blaa.localdomain (Postfix, from userid 500) id 8251341AB3; Thu, 10 Sep 2009 16:19:01 +0100 (IST) From: Mark McLoughlin To: qemu-devel@nongnu.org Date: Thu, 10 Sep 2009 16:18:48 +0100 Message-Id: <1252595941-15196-7-git-send-email-markmc@redhat.com> X-Mailer: git-send-email 1.6.2.5 In-Reply-To: <1252595941-15196-1-git-send-email-markmc@redhat.com> References: <1252595941-15196-1-git-send-email-markmc@redhat.com> X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Mark McLoughlin Subject: [Qemu-devel] [PATCH 06/19] Add qemu_opts_validate() for post parsing validation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Several qemu command line options have a parameter whose value affects what other parameters are accepted for the option. In these cases, we can have an empty description table in the QemuOptsList and once the option has been parsed we can use a suitable description table to validate the other parameters based on the value of that parameter. Signed-off-by: Mark McLoughlin --- qemu-option.c | 32 ++++++++++++++++++++++++++++++++ qemu-option.h | 1 + 2 files changed, 33 insertions(+), 0 deletions(-) diff --git a/qemu-option.c b/qemu-option.c index d312257..0f517d1 100644 --- a/qemu-option.c +++ b/qemu-option.c @@ -777,6 +777,38 @@ QemuOpts *qemu_opts_parse(QemuOptsList *list, const char *params, const char *fi return opts; } +/* Validate parsed opts against descriptions where no + * descriptions were provided in the QemuOptsList. + */ +int qemu_opts_validate(QemuOpts *opts, QemuOptDesc *desc) +{ + QemuOpt *opt; + + assert(opts->list->desc[0].name == NULL); + + TAILQ_FOREACH(opt, &opts->head, next) { + int i; + + for (i = 0; desc[i].name != NULL; i++) { + if (strcmp(desc[i].name, opt->name) == 0) { + break; + } + } + if (desc[i].name == NULL) { + fprintf(stderr, "option \"%s\" is not valid for %s\n", + opt->name, opts->list->name); + return -1; + } + + opt->desc = &desc[i]; + + if (qemu_opt_parse(opt) < 0) + return -1; + } + + return 0; +} + int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, void *opaque, int abort_on_failure) { diff --git a/qemu-option.h b/qemu-option.h index 9e52625..e816d95 100644 --- a/qemu-option.h +++ b/qemu-option.h @@ -114,6 +114,7 @@ int qemu_opts_set(QemuOptsList *list, const char *id, const char *name, const char *value); const char *qemu_opts_id(QemuOpts *opts); void qemu_opts_del(QemuOpts *opts); +int qemu_opts_validate(QemuOpts *opts, QemuOptDesc *desc); int qemu_opts_do_parse(QemuOpts *opts, const char *params, const char *firstname); QemuOpts *qemu_opts_parse(QemuOptsList *list, const char *params, const char *firstname);