From patchwork Tue Oct 6 11:17:03 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark McLoughlin X-Patchwork-Id: 35091 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 ozlabs.org (Postfix) with ESMTPS id F22F5B7B92 for ; Tue, 6 Oct 2009 22:52:43 +1100 (EST) Received: from localhost ([127.0.0.1]:37840 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mv8au-0007bW-MT for incoming@patchwork.ozlabs.org; Tue, 06 Oct 2009 07:52:40 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Mv84M-0006vd-Rt for qemu-devel@nongnu.org; Tue, 06 Oct 2009 07:19:02 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Mv84F-0006qu-RN for qemu-devel@nongnu.org; Tue, 06 Oct 2009 07:19:00 -0400 Received: from [199.232.76.173] (port=40407 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mv84E-0006q9-FW for qemu-devel@nongnu.org; Tue, 06 Oct 2009 07:18:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50636) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Mv84D-0007sW-M2 for qemu-devel@nongnu.org; Tue, 06 Oct 2009 07:18:53 -0400 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n96BIq64008449 for ; Tue, 6 Oct 2009 07:18:53 -0400 Received: from blaa.localdomain (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n96BIqka023346; Tue, 6 Oct 2009 07:18:52 -0400 Received: by blaa.localdomain (Postfix, from userid 500) id ECF0B4ED63; Tue, 6 Oct 2009 12:17:18 +0100 (IST) From: Mark McLoughlin To: qemu-devel@nongnu.org Date: Tue, 6 Oct 2009 12:17:03 +0100 Message-Id: <1254827836-11021-14-git-send-email-markmc@redhat.com> In-Reply-To: <1254827783.2720.42.camel@blaa> References: <1254827783.2720.42.camel@blaa> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.17 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Mark McLoughlin Subject: [Qemu-devel] [PATCH] 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 | 33 +++++++++++++++++++++++++++++++++ qemu-option.h | 1 + 2 files changed, 34 insertions(+), 0 deletions(-) diff --git a/qemu-option.c b/qemu-option.c index 735259f..de41c06 100644 --- a/qemu-option.c +++ b/qemu-option.c @@ -778,6 +778,39 @@ 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); + + QTAILQ_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 525b9b6..666b666 100644 --- a/qemu-option.h +++ b/qemu-option.h @@ -115,6 +115,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);