From: "Daniel P. Berrange" <berrange@redhat.com>
To: Sage Weil <sage@newdream.net>
Cc: libvir-list@redhat.com, ceph-devel@vger.kernel.org
Subject: Re: [libvirt] [PATCH 4/5] buf: implement generic virBufferEscape
Date: Tue, 11 Oct 2011 11:39:35 +0100 [thread overview]
Message-ID: <20111011103935.GB16057@redhat.com> (raw)
In-Reply-To: <1316492023-17749-5-git-send-email-sage@newdream.net>
On Mon, Sep 19, 2011 at 09:13:42PM -0700, Sage Weil wrote:
> Implement a generic helper to escape a given set of characters with a
> leading '\'. Generalizes virBufferEscapeSexpr().
>
> Signed-off-by: Sage Weil <sage@newdream.net>
> ---
> src/libvirt_private.syms | 1 +
> src/util/buf.c | 33 ++++++++++++++++++++++++++-------
> src/util/buf.h | 1 +
> 3 files changed, 28 insertions(+), 7 deletions(-)
>
> diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
> index 830222b..d230fab 100644
> --- a/src/libvirt_private.syms
> +++ b/src/libvirt_private.syms
> @@ -25,6 +25,7 @@ virBufferAddChar;
> virBufferAsprintf;
> virBufferContentAndReset;
> virBufferError;
> +virBufferEscape;
> virBufferEscapeSexpr;
> virBufferEscapeString;
> virBufferFreeAndReset;
> diff --git a/src/util/buf.c b/src/util/buf.c
> index 5002486..7d0d2d3 100644
> --- a/src/util/buf.c
> +++ b/src/util/buf.c
> @@ -383,9 +383,29 @@ virBufferEscapeSexpr(const virBufferPtr buf,
> const char *format,
> const char *str)
> {
> + virBufferEscape(buf, "\\\'", format, str);
> +}
> +
> +/**
> + * virBufferEscape:
> + * @buf: the buffer to dump
> + * @toescape: NULL-terminated list of characters to escape
> + * @format: a printf like format string but with only one %s parameter
> + * @str: the string argument which need to be escaped
> + *
> + * Do a formatted print with a single string to a buffer. Any characters
> + * in the provided list are escaped with a preceeding \.
> + */
> +void
> +virBufferEscape(const virBufferPtr buf,
> + const char *toescape,
> + const char *format,
> + const char *str)
> +{
> int len;
> char *escaped, *out;
> const char *cur;
> + const char *p;
>
> if ((format == NULL) || (buf == NULL) || (str == NULL))
> return;
> @@ -408,14 +428,13 @@ virBufferEscapeSexpr(const virBufferPtr buf,
> cur = str;
> out = escaped;
> while (*cur != 0) {
> - switch (*cur) {
> - case '\\':
> - case '\'':
> - *out++ = '\\';
> - /* fallthrough */
> - default:
> - *out++ = *cur;
> + for (p = toescape; *p; ++p) {
> + if (*cur == *p) {
> + *out++ = '\\';
> + break;
> + }
> }
> + *out++ = *cur;
> cur++;
> }
> *out = 0;
> diff --git a/src/util/buf.h b/src/util/buf.h
> index 06d01ba..e545ed9 100644
> --- a/src/util/buf.h
> +++ b/src/util/buf.h
> @@ -50,6 +50,7 @@ void virBufferStrcat(const virBufferPtr buf, ...)
> ATTRIBUTE_SENTINEL;
> void virBufferEscapeString(const virBufferPtr buf, const char *format, const char *str);
> void virBufferEscapeSexpr(const virBufferPtr buf, const char *format, const char *str);
> +void virBufferEscape(const virBufferPtr buf, const char *toescape, const char *format, const char *str);
> void virBufferURIEncodeString (const virBufferPtr buf, const char *str);
>
> # define virBufferAddLit(buf_, literal_string_) \
ACK, trivial isolated patch
Daniel
--
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org -o- http://virt-manager.org :|
|: http://autobuild.org -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
next prev parent reply other threads:[~2011-10-11 10:39 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-20 4:13 [PATCH 0/5 v2] Improve Ceph Qemu+RBD support Sage Weil
2011-09-20 4:13 ` [PATCH 1/5] secret: add Ceph secret type Sage Weil
2011-10-12 16:36 ` [libvirt] " Daniel P. Berrange
2011-09-20 4:13 ` [PATCH 2/5] storage: add authId, authDomain to virDomainDiskDef Sage Weil
2011-10-12 16:38 ` [libvirt] " Daniel P. Berrange
2011-09-20 4:13 ` [PATCH 3/5] qemu: pass virConnectPtr into Domain{Attach,Detach}* Sage Weil
2011-10-12 16:40 ` [libvirt] [PATCH 3/5] qemu: pass virConnectPtr into Domain{Attach, Detach}* Daniel P. Berrange
2011-09-20 4:13 ` [PATCH 4/5] buf: implement generic virBufferEscape Sage Weil
2011-10-11 10:39 ` Daniel P. Berrange [this message]
2011-10-12 17:09 ` [libvirt] " Eric Blake
2011-09-20 4:13 ` [PATCH 5/5] qemu/rbd: improve rbd device specification Sage Weil
2011-10-12 16:48 ` [libvirt] " Daniel P. Berrange
2011-09-27 20:40 ` [PATCH 0/5 v2] Improve Ceph Qemu+RBD support Sage Weil
2011-10-07 11:39 ` Wido den Hollander
2011-10-07 12:17 ` [libvirt] " Daniel P. Berrange
2011-10-12 16:33 ` Daniel P. Berrange
2011-10-12 16:45 ` Sage Weil
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=20111011103935.GB16057@redhat.com \
--to=berrange@redhat.com \
--cc=ceph-devel@vger.kernel.org \
--cc=libvir-list@redhat.com \
--cc=sage@newdream.net \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.