From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47734) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WGrxl-0006P5-HY for qemu-devel@nongnu.org; Fri, 21 Feb 2014 10:24:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WGrxf-0001Nu-Cu for qemu-devel@nongnu.org; Fri, 21 Feb 2014 10:24:29 -0500 Received: from mx1.redhat.com ([209.132.183.28]:10506) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WGrxf-0001Mg-3Y for qemu-devel@nongnu.org; Fri, 21 Feb 2014 10:24:23 -0500 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s1LFOMF7017385 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 21 Feb 2014 10:24:22 -0500 From: Kevin Wolf Date: Fri, 21 Feb 2014 16:24:03 +0100 Message-Id: <1392996248-26781-2-git-send-email-kwolf@redhat.com> In-Reply-To: <1392996248-26781-1-git-send-email-kwolf@redhat.com> References: <1392996248-26781-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PATCH v3 1/6] qemu-option: has_help_option() and is_valid_option_list() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, jcody@redhat.com, stefanha@redhat.com has_help_option() checks if any help option ('help' or '?') occurs anywhere in an option string, so that things like 'cluster_size=4k,help' are recognised. is_valid_option_list() ensures that the option list doesn't have options with leading commas or trailing unescaped commas. Signed-off-by: Kevin Wolf --- include/qemu/option.h | 2 ++ util/qemu-option.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/include/qemu/option.h b/include/qemu/option.h index 3ea871a..8c0ac34 100644 --- a/include/qemu/option.h +++ b/include/qemu/option.h @@ -79,6 +79,8 @@ void parse_option_size(const char *name, const char *value, void free_option_parameters(QEMUOptionParameter *list); void print_option_parameters(QEMUOptionParameter *list); void print_option_help(QEMUOptionParameter *list); +bool has_help_option(const char *param); +bool is_valid_option_list(const char *param); /* ------------------------------------------------------------------ */ diff --git a/util/qemu-option.c b/util/qemu-option.c index fd76cd2..9d898af 100644 --- a/util/qemu-option.c +++ b/util/qemu-option.c @@ -450,6 +450,55 @@ fail: return NULL; } +bool has_help_option(const char *param) +{ + size_t buflen = strlen(param) + 1; + char *buf = g_malloc0(buflen); + const char *p = param; + bool result = false; + + while (*p) { + p = get_opt_value(buf, buflen, p); + if (*p) { + p++; + } + + if (is_help_option(buf)) { + result = true; + goto out; + } + } + +out: + free(buf); + return result; +} + +bool is_valid_option_list(const char *param) +{ + size_t buflen = strlen(param) + 1; + char *buf = g_malloc0(buflen); + const char *p = param; + bool result = true; + + while (*p) { + p = get_opt_value(buf, buflen, p); + if (*p && !*++p) { + result = false; + goto out; + } + + if (!*buf || *buf == ',') { + result = false; + goto out; + } + } + +out: + free(buf); + return result; +} + /* * Prints all options of a list that have a value to stdout */ -- 1.8.1.4