g_dbus_address_escape_value: add

This is a GLib reimplementation of dbus_address_escape_value().
It's useful if you want to construct a D-Bus address from pieces:
for instance, if you have a listening Unix socket whose path is known,
and you want to connect a D-Bus peer to it.

Bug: https://bugzilla.gnome.org/show_bug.cgi?id=693673
Reviewed-by: Colin Walters <walters@verbum.org>
[amended to add Since: 2.36 as per review]
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
This commit is contained in:
Simon McVittie
2013-02-13 20:42:58 +00:00
parent 035cd81477
commit d200208d2b
3 changed files with 74 additions and 0 deletions

View File

@@ -102,6 +102,29 @@ test_mixed_address (void)
g_assert (!g_dbus_is_supported_address ("tcp:host=localhost,port=42;tcp:family=bla", NULL));
}
static const struct { const char *before; const char *after; } escaping[] = {
{ "foo", "foo" },
{ "/.\\-_", "/.\\-_" },
{ "<=>", "%3C%3D%3E" },
{ "/foo~1", "/foo%7E1" },
{ "\xe2\x98\xad\xff", "%E2%98%AD%FF" },
{ NULL, NULL }
};
static void
test_escape_address (void)
{
gsize i;
for (i = 0; escaping[i].before != NULL; i++)
{
gchar *s = g_dbus_address_escape_value (escaping[i].before);
g_assert_cmpstr (s, ==, escaping[i].after);
g_free (s);
}
}
int
main (int argc,
char *argv[])
@@ -116,6 +139,7 @@ main (int argc,
g_test_add_func ("/gdbus/tcp-address", test_tcp_address);
g_test_add_func ("/gdbus/autolaunch-address", test_autolaunch_address);
g_test_add_func ("/gdbus/mixed-address", test_mixed_address);
g_test_add_func ("/gdbus/escape-address", test_escape_address);
return g_test_run();
}