[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 31/54] qemu-option: has_help_option() and is_valid_op
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PULL 31/54] qemu-option: has_help_option() and is_valid_option_list() |
Date: |
Fri, 21 Feb 2014 23:12:28 +0100 |
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 <address@hidden>
Reviewed-by: Jeff Cody <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
---
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
- [Qemu-devel] [PULL 21/54] qcow: correctly propagate errors, (continued)
- [Qemu-devel] [PULL 21/54] qcow: correctly propagate errors, Kevin Wolf, 2014/02/21
- [Qemu-devel] [PULL 22/54] qed: correctly propagate errors, Kevin Wolf, 2014/02/21
- [Qemu-devel] [PULL 23/54] vhdx: correctly propagate errors, Kevin Wolf, 2014/02/21
- [Qemu-devel] [PULL 25/54] vmdk: extract vmdk_read_desc, Kevin Wolf, 2014/02/21
- [Qemu-devel] [PULL 26/54] vmdk: push vmdk_read_desc up to caller, Kevin Wolf, 2014/02/21
- [Qemu-devel] [PULL 24/54] vvfat: correctly propagate errors, Kevin Wolf, 2014/02/21
- [Qemu-devel] [PULL 27/54] vmdk: do not try opening a file as both image and descriptor, Kevin Wolf, 2014/02/21
- [Qemu-devel] [PULL 28/54] vmdk: correctly propagate errors, Kevin Wolf, 2014/02/21
- [Qemu-devel] [PULL 29/54] block: do not abuse EMEDIUMTYPE, Kevin Wolf, 2014/02/21
- [Qemu-devel] [PULL 30/54] vdi: say why an image is bad, Kevin Wolf, 2014/02/21
- [Qemu-devel] [PULL 31/54] qemu-option: has_help_option() and is_valid_option_list(),
Kevin Wolf <=
- [Qemu-devel] [PULL 32/54] qemu-img create: Support multiple -o options, Kevin Wolf, 2014/02/21
- [Qemu-devel] [PULL 33/54] qemu-img convert: Support multiple -o options, Kevin Wolf, 2014/02/21
- [Qemu-devel] [PULL 34/54] qemu-img amend: Support multiple -o options, Kevin Wolf, 2014/02/21
- [Qemu-devel] [PULL 35/54] qemu-img: Allow -o help with incomplete argument list, Kevin Wolf, 2014/02/21
- [Qemu-devel] [PULL 36/54] qemu-iotests: Check qemu-img command line parsing, Kevin Wolf, 2014/02/21
- [Qemu-devel] [PULL 37/54] qemu-config: Sections must consist of keys, Kevin Wolf, 2014/02/21
- [Qemu-devel] [PULL 38/54] qdict: Extract non-QDicts in qdict_array_split(), Kevin Wolf, 2014/02/21
- [Qemu-devel] [PULL 41/54] quorum: Create quorum.c, add QuorumChildRequest and QuorumAIOCB., Kevin Wolf, 2014/02/21
- [Qemu-devel] [PULL 42/54] quorum: Create BDRVQuorumState and BlkDriver and do init., Kevin Wolf, 2014/02/21
- [Qemu-devel] [PULL 43/54] quorum: Add quorum_aio_writev and its dependencies., Kevin Wolf, 2014/02/21