From aa4f823781185fb18187714798795d7e4b0c9b65 Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Fri, 11 Feb 2005 03:37:03 +0000 Subject: 2005-02-10 Havoc Pennington * test/glib/test-dbus-glib.c (main): fix so this test doesn't fail (call dbus_g_proxy_add_signal) * dbus/dbus-server-unix.c (_dbus_server_new_for_tcp_socket): escape the hostname (_dbus_server_new_for_domain_socket): escape the path * dbus/dbus-address.c (dbus_address_escape_value): new (dbus_address_unescape_value): new (dbus_parse_address): unescape values * dbus/dbus-string.c (_dbus_string_append_byte_as_hex): new function * doc/dbus-specification.xml: explain how to escape values in addresses --- dbus/dbus-string.c | 43 +++++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-) (limited to 'dbus/dbus-string.c') diff --git a/dbus/dbus-string.c b/dbus/dbus-string.c index f64d4746..5088bca9 100644 --- a/dbus/dbus-string.c +++ b/dbus/dbus-string.c @@ -2236,6 +2236,38 @@ _dbus_string_starts_with_c_str (const DBusString *a, } #endif /* DBUS_BUILD_TESTS */ +/** + * Appends a two-character hex digit to a string, where the hex digit + * has the value of the given byte. + * + * @param str the string + * @param byte the byte + * @returns #FALSE if no memory + */ +dbus_bool_t +_dbus_string_append_byte_as_hex (DBusString *str, + int byte) +{ + const char hexdigits[16] = { + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', + 'a', 'b', 'c', 'd', 'e', 'f' + }; + + if (!_dbus_string_append_byte (str, + hexdigits[(byte >> 4)])) + return FALSE; + + if (!_dbus_string_append_byte (str, + hexdigits[(byte & 0x0f)])) + { + _dbus_string_set_length (str, + _dbus_string_get_length (str) - 1); + return FALSE; + } + + return TRUE; +} + /** * Encodes a string in hex, the way MD5 and SHA-1 are usually * encoded. (Each byte is two hex digits.) @@ -2253,10 +2285,6 @@ _dbus_string_hex_encode (const DBusString *source, int insert_at) { DBusString result; - const char hexdigits[16] = { - '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', - 'a', 'b', 'c', 'd', 'e', 'f' - }; const unsigned char *p; const unsigned char *end; dbus_bool_t retval; @@ -2274,14 +2302,9 @@ _dbus_string_hex_encode (const DBusString *source, while (p != end) { - if (!_dbus_string_append_byte (&result, - hexdigits[(*p >> 4)])) + if (!_dbus_string_append_byte_as_hex (&result, *p)) goto out; - if (!_dbus_string_append_byte (&result, - hexdigits[(*p & 0x0f)])) - goto out; - ++p; } -- cgit