summaryrefslogtreecommitdiffstats
path: root/dbus/dbus-string.c
diff options
context:
space:
mode:
authorHavoc Pennington <hp@redhat.com>2005-02-11 03:37:03 +0000
committerHavoc Pennington <hp@redhat.com>2005-02-11 03:37:03 +0000
commitaa4f823781185fb18187714798795d7e4b0c9b65 (patch)
treee7f96d71925b867b85975f250616ba756c83ed6c /dbus/dbus-string.c
parent71f3b461b371d6bf7c7bc4e92578420b78d5c0d8 (diff)
2005-02-10 Havoc Pennington <hp@redhat.com>
* 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
Diffstat (limited to 'dbus/dbus-string.c')
-rw-r--r--dbus/dbus-string.c43
1 files changed, 33 insertions, 10 deletions
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
@@ -2237,6 +2237,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;
}