From fe4715b656237b89767b5dc0cba4c107541b6e0d Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Sat, 16 Sep 2006 19:24:08 +0000 Subject: 2006-09-16 Havoc Pennington * dbus/dbus-transport.c (_dbus_transport_open): modify to delegate to _dbus_transport_open_platform_specific, _dbus_transport_open_socket, and _dbus_transport_open_debug_pipe * dbus/dbus-transport-protected.h: add _dbus_transport_open_platform_specific --- dbus/dbus-address.c | 133 +++++++++++++++++++++++++++++----------------------- 1 file changed, 75 insertions(+), 58 deletions(-) (limited to 'dbus/dbus-address.c') diff --git a/dbus/dbus-address.c b/dbus/dbus-address.c index 7dc33e3e..c6354f14 100644 --- a/dbus/dbus-address.c +++ b/dbus/dbus-address.c @@ -48,6 +48,81 @@ struct DBusAddressEntry DBusList *values; /**< List of values */ }; + +void +_dbus_set_bad_address (DBusError *error, + const char *address_problem_type, + const char *address_problem_field, + const char *address_problem_other) +{ + if (address_problem_type != NULL) + dbus_set_error (error, DBUS_ERROR_BAD_ADDRESS, + "Server address of type %s was missing argument %s", + address_problem_type, address_problem_field); + else + dbus_set_error (error, DBUS_ERROR_BAD_ADDRESS, + "Could not parse server address: %s", + address_problem_other); +} + +#define _DBUS_ADDRESS_OPTIONALLY_ESCAPED_BYTE(b) \ + (((b) >= 'a' && (b) <= 'z') || \ + ((b) >= 'A' && (b) <= 'Z') || \ + ((b) >= '0' && (b) <= '9') || \ + (b) == '-' || \ + (b) == '_' || \ + (b) == '/' || \ + (b) == '\\' || \ + (b) == '.') + +/** + * Appends an escaped version of one string to another string, + * using the D-Bus address escaping mechanism + * + * @param escaped the string to append to + * @param unescaped the string to escape + * @returns #FALSE if no memory + */ +dbus_bool_t +_dbus_address_append_escaped (DBusString *escaped, + const DBusString *unescaped) +{ + const char *p; + const char *end; + dbus_bool_t ret; + int orig_len; + + ret = FALSE; + + orig_len = _dbus_string_get_length (escaped); + p = _dbus_string_get_const_data (unescaped); + end = p + _dbus_string_get_length (unescaped); + while (p != end) + { + if (_DBUS_ADDRESS_OPTIONALLY_ESCAPED_BYTE (*p)) + { + if (!_dbus_string_append_byte (escaped, *p)) + goto out; + } + else + { + if (!_dbus_string_append_byte (escaped, '%')) + goto out; + if (!_dbus_string_append_byte_as_hex (escaped, *p)) + goto out; + } + + ++p; + } + + ret = TRUE; + + out: + if (!ret) + _dbus_string_set_length (escaped, orig_len); + return ret; +} + /** @} */ /* End of internals */ static void @@ -165,64 +240,6 @@ dbus_address_entry_get_value (DBusAddressEntry *entry, return NULL; } -#define _DBUS_ADDRESS_OPTIONALLY_ESCAPED_BYTE(b) \ - (((b) >= 'a' && (b) <= 'z') || \ - ((b) >= 'A' && (b) <= 'Z') || \ - ((b) >= '0' && (b) <= '9') || \ - (b) == '-' || \ - (b) == '_' || \ - (b) == '/' || \ - (b) == '\\' || \ - (b) == '.') - -/** - * Appends an escaped version of one string to another string, - * using the D-Bus address escaping mechanism - * - * @param escaped the string to append to - * @param unescaped the string to escape - * @returns #FALSE if no memory - */ -dbus_bool_t -_dbus_address_append_escaped (DBusString *escaped, - const DBusString *unescaped) -{ - const char *p; - const char *end; - dbus_bool_t ret; - int orig_len; - - ret = FALSE; - - orig_len = _dbus_string_get_length (escaped); - p = _dbus_string_get_const_data (unescaped); - end = p + _dbus_string_get_length (unescaped); - while (p != end) - { - if (_DBUS_ADDRESS_OPTIONALLY_ESCAPED_BYTE (*p)) - { - if (!_dbus_string_append_byte (escaped, *p)) - goto out; - } - else - { - if (!_dbus_string_append_byte (escaped, '%')) - goto out; - if (!_dbus_string_append_byte_as_hex (escaped, *p)) - goto out; - } - - ++p; - } - - ret = TRUE; - - out: - if (!ret) - _dbus_string_set_length (escaped, orig_len); - return ret; -} - static dbus_bool_t append_unescaped_value (DBusString *unescaped, const DBusString *escaped, -- cgit