From: "Daniel P. Berrange" <berrange@redhat.com>
To: qemu-devel@nongnu.org
Cc: Gerd Hoffmann <kraxel@redhat.com>,
"Daniel P. Berrange" <berrange@redhat.com>
Subject: [Qemu-devel] [PATCH 7/8] util: add qemu_opt_get_all() to get repeated opts
Date: Thu, 5 Jan 2017 16:07:00 +0000 [thread overview]
Message-ID: <20170105160701.22118-8-berrange@redhat.com> (raw)
In-Reply-To: <20170105160701.22118-1-berrange@redhat.com>
The QemuOpts parser accepts repeated option names, storing
all the provided values. qemu_opt_get() then just returns
the last value. There is no way to get the other values
without using a callback function to iterate over all
option names. Add a qemu_opt_get_all() method to return
a string list of all values.
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
---
include/qemu/option.h | 1 +
util/qemu-option.c | 22 ++++++++++++++++++++++
2 files changed, 23 insertions(+)
diff --git a/include/qemu/option.h b/include/qemu/option.h
index 1f9e3f9..689e0a8 100644
--- a/include/qemu/option.h
+++ b/include/qemu/option.h
@@ -65,6 +65,7 @@ struct QemuOptsList {
};
const char *qemu_opt_get(QemuOpts *opts, const char *name);
+size_t qemu_opt_get_all(QemuOpts *opts, const char *name, char ***vals);
char *qemu_opt_get_del(QemuOpts *opts, const char *name);
/**
* qemu_opt_has_help_opt:
diff --git a/util/qemu-option.c b/util/qemu-option.c
index 3467dc2..0418d71 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -332,6 +332,28 @@ const char *qemu_opt_get(QemuOpts *opts, const char *name)
return opt ? opt->str : NULL;
}
+size_t qemu_opt_get_all(QemuOpts *opts, const char *name, char ***vals)
+{
+ QemuOpt *opt;
+ size_t nvals = 0;
+
+ *vals = NULL;
+
+ QTAILQ_FOREACH(opt, &opts->head, next) {
+ if (!g_str_equal(opt->name, name)) {
+ continue;
+ }
+
+ *vals = g_renew(char *, *vals, nvals + 1);
+ (*vals)[nvals++] = g_strdup(opt->str);
+ }
+ if (nvals) {
+ *vals = g_renew(char *, *vals, nvals + 1);
+ (*vals)[nvals] = NULL;
+ }
+ return nvals;
+}
+
/* Get a known option (or its default) and remove it from the list
* all in one action. Return a malloced string of the option value.
* Result must be freed by caller with g_free().
--
2.9.3
next prev parent reply other threads:[~2017-01-05 16:07 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-05 16:06 [Qemu-devel] [PATCH 0/8] Support multiple listening sockets per VNC server Daniel P. Berrange
2017-01-05 16:06 ` [Qemu-devel] [PATCH 1/8] ui: fix regression handling bare 'websocket' option to -vnc Daniel P. Berrange
2017-01-06 13:39 ` Eric Blake
2017-01-05 16:06 ` [Qemu-devel] [PATCH 2/8] ui: fix reporting of VNC auth in query-vnc-servers Daniel P. Berrange
2017-01-06 15:06 ` Eric Blake
2017-01-05 16:06 ` [Qemu-devel] [PATCH 3/8] ui: refactor VncDisplay to allow multiple listening sockets Daniel P. Berrange
2017-01-06 15:23 ` Eric Blake
2017-01-06 15:28 ` Daniel P. Berrange
2017-01-05 16:06 ` [Qemu-devel] [PATCH 4/8] ui: refactor code for populating SocketAddress from vnc_display_open Daniel P. Berrange
2017-01-06 15:47 ` Eric Blake
2017-01-05 16:06 ` [Qemu-devel] [PATCH 5/8] ui: extract code to connect/listen " Daniel P. Berrange
2017-01-06 16:00 ` Eric Blake
2017-01-05 16:06 ` [Qemu-devel] [PATCH 6/8] ui: let VNC server listen on all resolved IP addresses Daniel P. Berrange
2017-01-06 16:14 ` Eric Blake
2017-01-05 16:07 ` Daniel P. Berrange [this message]
2017-01-06 16:22 ` [Qemu-devel] [PATCH 7/8] util: add qemu_opt_get_all() to get repeated opts Eric Blake
2017-01-05 16:07 ` [Qemu-devel] [PATCH 8/8] ui: add ability to specify multiple VNC listen addresses Daniel P. Berrange
2017-01-06 16:34 ` Eric Blake
2017-01-05 17:26 ` [Qemu-devel] [PATCH 0/8] Support multiple listening sockets per VNC server no-reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170105160701.22118-8-berrange@redhat.com \
--to=berrange@redhat.com \
--cc=kraxel@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).