26 #include "dbus-address.h" 27 #include "dbus-internals.h" 28 #include "dbus-list.h" 29 #include "dbus-string.h" 30 #include "dbus-protocol.h" 31 #include <dbus/dbus-test-tap.h> 67 const char *address_problem_type,
68 const char *address_problem_field,
69 const char *address_problem_other)
71 if (address_problem_type !=
NULL)
73 "Server address of type %s was missing argument %s",
74 address_problem_type, address_problem_field);
77 "Could not parse server address: %s",
78 address_problem_other);
85 #define _DBUS_ADDRESS_OPTIONALLY_ESCAPED_BYTE(b) \ 86 (((b) >= 'a' && (b) <= 'z') || \ 87 ((b) >= 'A' && (b) <= 'Z') || \ 88 ((b) >= '0' && (b) <= '9') || \ 108 const unsigned char *p;
109 const unsigned char *end;
115 orig_len = _dbus_string_get_length (escaped);
116 p = _dbus_string_get_const_udata (unescaped);
117 end = p + _dbus_string_get_length (unescaped);
194 for (i = 0; entries[i] !=
NULL; i++)
195 dbus_address_entry_free (entries[i]);
230 return _dbus_string_get_const_data (&entry->
method);
258 return _dbus_string_get_const_data (values->
data);
268 append_unescaped_value (
DBusString *unescaped,
280 p = _dbus_string_get_const_data (escaped) + escaped_start;
281 end = p + escaped_len;
301 "In D-Bus address, percent character was not followed by two hex digits");
314 _dbus_string_get_length (unescaped)))
320 "In D-Bus address, percent character was followed by characters other than hex digits");
328 "In D-Bus address, character '%c' should have been escaped\n",
340 _DBUS_SET_OOM (error);
370 int pos, end_pos, len, i;
374 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
380 len = _dbus_string_get_length (&str);
385 "Empty address '%s'", address);
395 entry = create_entry ();
407 dbus_address_entry_free (entry);
430 while (pos < end_pos)
432 int comma_pos, equals_pos;
438 equals_pos == pos || equals_pos + 1 == comma_pos)
441 "'=' character not found or has no value following it");
495 if (!append_unescaped_value (value, &str, equals_pos + 1,
496 comma_pos - equals_pos - 1, error))
545 entry_array [*array_len] =
NULL;
551 entry_array[i] = link->
data;
557 *entry_result = entry_array;
566 dbus_address_entry_free (link->
data);
632 if (!append_unescaped_value (&unescaped, &escaped,
633 0, _dbus_string_get_length (&escaped),
642 _DBUS_SET_OOM (error);
652 #ifdef DBUS_ENABLE_EMBEDDED_TESTS 654 #ifndef DOXYGEN_SHOULD_SKIP_THIS 656 #include "dbus-test.h" 662 const char *unescaped;
665 static const EscapeTest escape_tests[] = {
666 {
"abcde",
"abcde" },
671 {
"abc%24",
"abc$" },
672 {
"%24abc",
"$abc" },
673 {
"abc%24abc",
"abc$abc" },
684 {
"%c3%b6",
"\xc3\xb6" }
687 static const char* invalid_escaped_values[] = {
701 _dbus_address_test (
void)
711 const EscapeTest *test = &escape_tests[i];
717 _dbus_test_fatal (
"oom");
719 if (strcmp (escaped, test->escaped) != 0)
721 _dbus_warn (
"Escaped '%s' as '%s' should have been '%s'",
722 test->unescaped, escaped, test->escaped);
728 if (unescaped ==
NULL)
736 if (strcmp (unescaped, test->unescaped) != 0)
738 _dbus_warn (
"Unescaped '%s' as '%s' should have been '%s'",
739 test->escaped, unescaped, test->unescaped);
754 if (unescaped !=
NULL)
756 _dbus_warn (
"Should not have successfully unescaped '%s' to '%s'",
757 invalid_escaped_values[i], unescaped);
769 &entries, &len, &error))
770 _dbus_test_fatal (
"could not parse address");
780 _dbus_test_fatal (
"Parsed incorrect address.");
785 _dbus_test_fatal (
"Parsed incorrect address.");
790 _dbus_test_fatal (
"Parsed incorrect address.");
795 _dbus_test_fatal (
"Parsed incorrect address.");
800 _dbus_test_fatal (
"Parsed incorrect address.");
805 _dbus_test_fatal (
"Parsed incorrect address.");
810 _dbus_test_fatal (
"Parsed incorrect address.");
815 _dbus_test_fatal (
"Parsed incorrect address.");
820 _dbus_test_fatal (
"Parsed incorrect address.");
const char * message
public error message field
#define NULL
A null pointer, defined appropriately for C or C++.
void dbus_free(void *memory)
Frees a block of memory previously allocated by dbus_malloc() or dbus_malloc0().
#define _DBUS_ADDRESS_OPTIONALLY_ESCAPED_BYTE(b)
TRUE if the byte need not be escaped when found in a dbus address.
#define dbus_new(type, count)
Safe macro for using dbus_malloc().
DBusString method
The address type (unix, tcp, etc.)
#define _dbus_assert(condition)
Aborts with an error message if the condition is false.
#define DBUS_ERROR_INIT
Expands to a suitable initializer for a DBusError on the stack.
void * data
Data stored at this element.
const char * dbus_address_entry_get_method(DBusAddressEntry *entry)
Returns the method string of an address entry.
void dbus_error_free(DBusError *error)
Frees an error that's been set (or just initialized), then reinitializes the error as in dbus_error_i...
void dbus_address_entries_free(DBusAddressEntry **entries)
Frees a NULL-terminated array of address entries.
dbus_bool_t _dbus_string_init(DBusString *str)
Initializes a string.
dbus_bool_t _dbus_string_find(const DBusString *str, int start, const char *substr, int *found)
Finds the given substring in the string, returning TRUE and filling in the byte index where the subst...
#define _dbus_list_get_next_link(list, link)
Gets the next link in the list, or NULL if there are no more links.
const char * dbus_address_entry_get_value(DBusAddressEntry *entry, const char *key)
Returns a value from a key of an entry.
#define dbus_new0(type, count)
Safe macro for using dbus_malloc0().
dbus_bool_t _dbus_string_equal_c_str(const DBusString *a, const char *c_str)
Checks whether a string is equal to a C string.
dbus_uint32_t dbus_bool_t
A boolean, valid values are TRUE and FALSE.
void _dbus_string_init_const(DBusString *str, const char *value)
Initializes a constant string.
void _dbus_warn(const char *format,...)
Prints a warning message to stderr.
dbus_bool_t _dbus_list_append(DBusList **list, void *data)
Appends a value to the list.
Internals of DBusAddressEntry.
void _dbus_set_bad_address(DBusError *error, const char *address_problem_type, const char *address_problem_field, const char *address_problem_other)
Sets DBUS_ERROR_BAD_ADDRESS.
Object representing an exception.
dbus_bool_t _dbus_address_append_escaped(DBusString *escaped, const DBusString *unescaped)
Appends an escaped version of one string to another string, using the D-Bus address escaping mechanis...
#define DBUS_ERROR_BAD_ADDRESS
A D-Bus bus address was malformed.
void dbus_set_error(DBusError *error, const char *name, const char *format,...)
Assigns an error name and message to a DBusError.
#define _DBUS_N_ELEMENTS(array)
Computes the number of elements in a fixed-size array using sizeof().
dbus_bool_t _dbus_string_append_byte(DBusString *str, unsigned char byte)
Appends a single byte to the string, returning FALSE if not enough memory.
void _dbus_string_free(DBusString *str)
Frees a string created by _dbus_string_init(), and fills it with the same contents as #_DBUS_STRING_I...
#define TRUE
Expands to "1".
char * dbus_address_unescape_value(const char *value, DBusError *error)
Unescapes the given string as a value in a key=value pair for a D-Bus address.
DBusList * keys
List of keys.
char * dbus_address_escape_value(const char *value)
Escapes the given string as a value in a key=value pair for a D-Bus address.
dbus_bool_t _dbus_string_hex_decode(const DBusString *source, int start, int *end_return, DBusString *dest, int insert_at)
Decodes a string from hex encoding.
dbus_bool_t _dbus_string_append_byte_as_hex(DBusString *str, unsigned char byte)
Appends a two-character hex digit to a string, where the hex digit has the value of the given byte...
dbus_bool_t _dbus_string_find_to(const DBusString *str, int start, int end, const char *substr, int *found)
Finds the given substring in the string, up to a certain position, returning TRUE and filling in the ...
int _dbus_list_get_length(DBusList **list)
Gets the length of a list.
#define DBUS_ERROR_NO_MEMORY
There was not enough memory to complete an operation.
DBusList * _dbus_list_get_first_link(DBusList **list)
Gets the first link in the list.
#define FALSE
Expands to "0".
dbus_bool_t _dbus_string_set_length(DBusString *str, int length)
Sets the length of a string.
dbus_bool_t _dbus_string_copy_len(const DBusString *source, int start, int len, DBusString *dest, int insert_at)
Like _dbus_string_copy(), but can copy a segment from the middle of the source string.
dbus_bool_t _dbus_string_steal_data(DBusString *str, char **data_return)
Like _dbus_string_get_data(), but removes the gotten data from the original string.
dbus_bool_t dbus_error_is_set(const DBusError *error)
Checks whether an error occurred (the error is set).
dbus_bool_t dbus_parse_address(const char *address, DBusAddressEntry ***entry_result, int *array_len, DBusError *error)
Parses an address string of the form:
void _dbus_list_clear(DBusList **list)
Frees all links in the list and sets the list head to NULL.
DBusList * values
List of values.