Blame SOURCES/kvm-qemu-option-has_help_option-and-is_valid_option_list.patch

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