9ae3a8
From 8720a390e468547c84e8143ee5cf81263d0fb4f3 Mon Sep 17 00:00:00 2001
9ae3a8
From: Kevin Wolf <kwolf@redhat.com>
9ae3a8
Date: Tue, 25 Feb 2014 15:00:00 +0100
9ae3a8
Subject: [PATCH 2/7] qemu-option: has_help_option() and is_valid_option_list()
9ae3a8
9ae3a8
RH-Author: Kevin Wolf <kwolf@redhat.com>
9ae3a8
Message-id: <1393340405-9936-2-git-send-email-kwolf@redhat.com>
9ae3a8
Patchwork-id: 57793
9ae3a8
O-Subject: [RHEL-7.0 qemu-kvm PATCH 1/6] qemu-option: has_help_option() and is_valid_option_list()
9ae3a8
Bugzilla: 1065873
9ae3a8
RH-Acked-by: Juan Quintela <quintela@redhat.com>
9ae3a8
RH-Acked-by: Fam Zheng <famz@redhat.com>
9ae3a8
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
9ae3a8
has_help_option() checks if any help option ('help' or '?') occurs
9ae3a8
anywhere in an option string, so that things like 'cluster_size=4k,help'
9ae3a8
are recognised.
9ae3a8
9ae3a8
is_valid_option_list() ensures that the option list doesn't have options
9ae3a8
with leading commas or trailing unescaped commas.
9ae3a8
9ae3a8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
Reviewed-by: Jeff Cody <jcody@redhat.com>
9ae3a8
Reviewed-by: Eric Blake <eblake@redhat.com>
9ae3a8
(cherry picked from commit 7cc07ab8daa01f100f36ab63382d491f2d278c64)
9ae3a8
9ae3a8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
---
9ae3a8
 include/qemu/option.h |  2 ++
9ae3a8
 util/qemu-option.c    | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
9ae3a8
 2 files changed, 51 insertions(+)
9ae3a8
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 include/qemu/option.h |    2 ++
9ae3a8
 util/qemu-option.c    |   49 +++++++++++++++++++++++++++++++++++++++++++++++++
9ae3a8
 2 files changed, 51 insertions(+), 0 deletions(-)
9ae3a8
9ae3a8
diff --git a/include/qemu/option.h b/include/qemu/option.h
9ae3a8
index 5c0c6dd..e1d3dd0 100644
9ae3a8
--- a/include/qemu/option.h
9ae3a8
+++ b/include/qemu/option.h
9ae3a8
@@ -79,6 +79,8 @@ void parse_option_size(const char *name, const char *value,
9ae3a8
 void free_option_parameters(QEMUOptionParameter *list);
9ae3a8
 void print_option_parameters(QEMUOptionParameter *list);
9ae3a8
 void print_option_help(QEMUOptionParameter *list);
9ae3a8
+bool has_help_option(const char *param);
9ae3a8
+bool is_valid_option_list(const char *param);
9ae3a8
 
9ae3a8
 /* ------------------------------------------------------------------ */
9ae3a8
 
9ae3a8
diff --git a/util/qemu-option.c b/util/qemu-option.c
9ae3a8
index 2445406..4de5d13 100644
9ae3a8
--- a/util/qemu-option.c
9ae3a8
+++ b/util/qemu-option.c
9ae3a8
@@ -450,6 +450,55 @@ fail:
9ae3a8
     return NULL;
9ae3a8
 }
9ae3a8
 
9ae3a8
+bool has_help_option(const char *param)
9ae3a8
+{
9ae3a8
+    size_t buflen = strlen(param) + 1;
9ae3a8
+    char *buf = g_malloc0(buflen);
9ae3a8
+    const char *p = param;
9ae3a8
+    bool result = false;
9ae3a8
+
9ae3a8
+    while (*p) {
9ae3a8
+        p = get_opt_value(buf, buflen, p);
9ae3a8
+        if (*p) {
9ae3a8
+            p++;
9ae3a8
+        }
9ae3a8
+
9ae3a8
+        if (is_help_option(buf)) {
9ae3a8
+            result = true;
9ae3a8
+            goto out;
9ae3a8
+        }
9ae3a8
+    }
9ae3a8
+
9ae3a8
+out:
9ae3a8
+    free(buf);
9ae3a8
+    return result;
9ae3a8
+}
9ae3a8
+
9ae3a8
+bool is_valid_option_list(const char *param)
9ae3a8
+{
9ae3a8
+    size_t buflen = strlen(param) + 1;
9ae3a8
+    char *buf = g_malloc0(buflen);
9ae3a8
+    const char *p = param;
9ae3a8
+    bool result = true;
9ae3a8
+
9ae3a8
+    while (*p) {
9ae3a8
+        p = get_opt_value(buf, buflen, p);
9ae3a8
+        if (*p && !*++p) {
9ae3a8
+            result = false;
9ae3a8
+            goto out;
9ae3a8
+        }
9ae3a8
+
9ae3a8
+        if (!*buf || *buf == ',') {
9ae3a8
+            result = false;
9ae3a8
+            goto out;
9ae3a8
+        }
9ae3a8
+    }
9ae3a8
+
9ae3a8
+out:
9ae3a8
+    free(buf);
9ae3a8
+    return result;
9ae3a8
+}
9ae3a8
+
9ae3a8
 /*
9ae3a8
  * Prints all options of a list that have a value to stdout
9ae3a8
  */
9ae3a8
-- 
9ae3a8
1.7.1
9ae3a8