summaryrefslogtreecommitdiff
path: root/p11-kit
diff options
context:
space:
mode:
authorStef Walter <stefw@gnome.org>2013-05-21 16:41:09 +0200
committerStef Walter <stefw@gnome.org>2013-05-27 10:46:11 +0200
commitcb8f2e3a04d9365121ffea0d76d8b3d47e2cc1ec (patch)
tree0f1b8a6d70ef15f4e3154def0f4a316fb717cce6 /p11-kit
parent4fd057258177f4f14bbe78c2d02d5a65eaf3f3dc (diff)
url: Encode directly to a buffer
Diffstat (limited to 'p11-kit')
-rw-r--r--p11-kit/uri.c32
1 files changed, 19 insertions, 13 deletions
diff --git a/p11-kit/uri.c b/p11-kit/uri.c
index a811b92..df069f4 100644
--- a/p11-kit/uri.c
+++ b/p11-kit/uri.c
@@ -625,6 +625,18 @@ p11_kit_uri_new (void)
return uri;
}
+static void
+format_name_equals (p11_buffer *buffer,
+ bool *is_first,
+ const char *name)
+{
+ if (!*is_first)
+ p11_buffer_add (buffer, ";", 1);
+ p11_buffer_add (buffer, name, -1);
+ p11_buffer_add (buffer, "=", 1);
+ *is_first = false;
+}
+
static bool
format_raw_string (p11_buffer *buffer,
bool *is_first,
@@ -635,12 +647,8 @@ format_raw_string (p11_buffer *buffer,
if (!value)
return true;
- if (!*is_first)
- p11_buffer_add (buffer, ";", 1);
- p11_buffer_add (buffer, name, -1);
- p11_buffer_add (buffer, "=", 1);
+ format_name_equals (buffer, is_first, name);
p11_buffer_add (buffer, value, -1);
- *is_first = false;
return p11_buffer_ok (buffer);
}
@@ -653,16 +661,14 @@ format_encode_string (p11_buffer *buffer,
size_t n_value,
bool force)
{
- char *encoded;
- bool ret;
+ /* Not set */
+ if (!value)
+ return true;
- encoded = p11_url_encode (value, value + n_value,
- force ? "" : P11_URL_VERBATIM, NULL);
- return_val_if_fail (encoded != NULL, false);
+ format_name_equals (buffer, is_first, name);
+ p11_url_encode (value, value + n_value, force ? "" : P11_URL_VERBATIM, buffer);
- ret = format_raw_string (buffer, is_first, name, encoded);
- free (encoded);
- return ret;
+ return p11_buffer_ok (buffer);
}