2005-01-15 Havoc Pennington <hp@redhat.com>

* Land the new message args API and type system.

	This patch is huge, but the public API change is not
	really large. The set of D-BUS types has changed somewhat,
	and the arg "getters" are more geared toward language bindings;
	they don't make a copy, etc.

	There are also some known issues. See these emails for details
	on this huge patch:
	http://lists.freedesktop.org/archives/dbus/2004-December/001836.html
        http://lists.freedesktop.org/archives/dbus/2005-January/001922.html

	* dbus/dbus-marshal-*: all the new stuff

	* dbus/dbus-message.c: basically rewritten

	* dbus/dbus-memory.c (check_guards): with "guards" enabled, init
	freed blocks to be all non-nul bytes so using freed memory is less
	likely to work right

	* dbus/dbus-internals.c (_dbus_test_oom_handling): add
	DBUS_FAIL_MALLOC=N environment variable, so you can do
	DBUS_FAIL_MALLOC=0 to skip the out-of-memory checking, or
	DBUS_FAIL_MALLOC=10 to make it really, really, really slow and
	thorough.

	* qt/message.cpp: port to the new message args API
	(operator<<): use str.utf8() rather than str.unicode()
	(pretty sure this is right from the Qt docs?)

	* glib/dbus-gvalue.c: port to the new message args API

	* bus/dispatch.c, bus/driver.c: port to the new message args API

	* dbus/dbus-string.c (_dbus_string_init_const_len): initialize the
	"locked" flag to TRUE and align_offset to 0; I guess we never
	looked at these anyhow, but seems cleaner.

	* dbus/dbus-string.h (_DBUS_STRING_ALLOCATION_PADDING):
	move allocation padding macro to this header; use it to implement
	(_DBUS_STRING_STATIC): ability to declare a static string.

	* dbus/dbus-message.c (_dbus_message_has_type_interface_member):
	change to return TRUE if the interface is not set.

	* dbus/dbus-string.[hc]: move the D-BUS specific validation stuff
	to dbus-marshal-validate.[hc]

	* dbus/dbus-marshal-basic.c (_dbus_type_to_string): move here from
	dbus-internals.c

	* dbus/Makefile.am: cut over from dbus-marshal.[hc]
	to dbus-marshal-*.[hc]

	* dbus/dbus-object-tree.c (_dbus_decompose_path): move this
	function here from dbus-marshal.c
This commit is contained in:
Havoc Pennington 2005-01-15 07:15:38 +00:00
parent 6ec04e917c
commit 9c3d566e95
56 changed files with 6700 additions and 10040 deletions

View file

@ -1,3 +1,62 @@
2005-01-15 Havoc Pennington <hp@redhat.com>
* Land the new message args API and type system.
This patch is huge, but the public API change is not
really large. The set of D-BUS types has changed somewhat,
and the arg "getters" are more geared toward language bindings;
they don't make a copy, etc.
There are also some known issues. See these emails for details
on this huge patch:
http://lists.freedesktop.org/archives/dbus/2004-December/001836.html
http://lists.freedesktop.org/archives/dbus/2005-January/001922.html
* dbus/dbus-marshal-*: all the new stuff
* dbus/dbus-message.c: basically rewritten
* dbus/dbus-memory.c (check_guards): with "guards" enabled, init
freed blocks to be all non-nul bytes so using freed memory is less
likely to work right
* dbus/dbus-internals.c (_dbus_test_oom_handling): add
DBUS_FAIL_MALLOC=N environment variable, so you can do
DBUS_FAIL_MALLOC=0 to skip the out-of-memory checking, or
DBUS_FAIL_MALLOC=10 to make it really, really, really slow and
thorough.
* qt/message.cpp: port to the new message args API
(operator<<): use str.utf8() rather than str.unicode()
(pretty sure this is right from the Qt docs?)
* glib/dbus-gvalue.c: port to the new message args API
* bus/dispatch.c, bus/driver.c: port to the new message args API
* dbus/dbus-string.c (_dbus_string_init_const_len): initialize the
"locked" flag to TRUE and align_offset to 0; I guess we never
looked at these anyhow, but seems cleaner.
* dbus/dbus-string.h (_DBUS_STRING_ALLOCATION_PADDING):
move allocation padding macro to this header; use it to implement
(_DBUS_STRING_STATIC): ability to declare a static string.
* dbus/dbus-message.c (_dbus_message_has_type_interface_member):
change to return TRUE if the interface is not set.
* dbus/dbus-string.[hc]: move the D-BUS specific validation stuff
to dbus-marshal-validate.[hc]
* dbus/dbus-marshal-basic.c (_dbus_type_to_string): move here from
dbus-internals.c
* dbus/Makefile.am: cut over from dbus-marshal.[hc]
to dbus-marshal-*.[hc]
* dbus/dbus-object-tree.c (_dbus_decompose_path): move this
function here from dbus-marshal.c
2005-01-12 Joe Shaw <joeshaw@novell.com>
* NEWS: Update for 0.23.

11
HACKING
View file

@ -127,6 +127,17 @@ dbus_realloc to fail if the number of bytes to be allocated is greater
than the specified number. This only works if D-BUS has been compiled with
--enable-tests.
DBUS_TEST_MALLOC_FAILURES=n
Many of the D-BUS tests will run over and over, once for each malloc
involved in the test. Each run will fail a different malloc, plus some
number of mallocs following that malloc (because a fair number of bugs
only happen if two or more mallocs fail in a row, e.g. error recovery
that itself involves malloc). This env variable sets the number of
mallocs to fail.
Here's why you care: If set to 0, then the malloc checking is skipped,
which makes the test suite a heck of a lot faster. Just run with this
env variable unset before you commit.
Tests
===

View file

@ -93,6 +93,7 @@ typedef struct
unsigned int timeout_added : 1;
} BusPendingActivation;
#if 0
static BusServiceDirectory *
bus_service_directory_ref (BusServiceDirectory *dir)
{
@ -102,6 +103,7 @@ bus_service_directory_ref (BusServiceDirectory *dir)
return dir;
}
#endif
static void
bus_service_directory_unref (BusServiceDirectory *dir)
@ -909,15 +911,19 @@ bus_activation_service_created (BusActivation *activation,
/* Only send activation replies to regular activation requests. */
if (!entry->auto_activation)
{
dbus_uint32_t result;
message = dbus_message_new_method_return (entry->activation_message);
if (!message)
{
BUS_SET_OOM (error);
goto error;
}
result = DBUS_ACTIVATION_REPLY_ACTIVATED;
if (!dbus_message_append_args (message,
DBUS_TYPE_UINT32, DBUS_ACTIVATION_REPLY_ACTIVATED,
DBUS_TYPE_UINT32, &result,
DBUS_TYPE_INVALID))
{
dbus_message_unref (message);
@ -1328,6 +1334,8 @@ bus_activation_activate_service (BusActivation *activation,
_dbus_string_init_const (&service_str, service_name);
if (bus_registry_lookup (bus_context_get_registry (activation->context), &service_str) != NULL)
{
dbus_uint32_t result;
_dbus_verbose ("Service \"%s\" is already active\n", service_name);
message = dbus_message_new_method_return (activation_message);
@ -1339,8 +1347,10 @@ bus_activation_activate_service (BusActivation *activation,
return FALSE;
}
result = DBUS_ACTIVATION_REPLY_ALREADY_ACTIVE;
if (!dbus_message_append_args (message,
DBUS_TYPE_UINT32, DBUS_ACTIVATION_REPLY_ALREADY_ACTIVE,
DBUS_TYPE_UINT32, &result,
DBUS_TYPE_INVALID))
{
_dbus_verbose ("No memory to set args of reply to activate message\n");

View file

@ -1398,6 +1398,7 @@ bus_pending_reply_send_no_reply (BusConnections *connections,
DBusMessage *message;
DBusMessageIter iter;
dbus_bool_t retval;
const char *errmsg;
retval = FALSE;
@ -1414,9 +1415,10 @@ bus_pending_reply_send_no_reply (BusConnections *connections,
if (!dbus_message_set_error_name (message,
DBUS_ERROR_NO_REPLY))
goto out;
errmsg = "Message did not receive a reply (timeout by message bus)";
dbus_message_append_iter_init (message, &iter);
if (!dbus_message_iter_append_string (&iter, "Message did not receive a reply (timeout by message bus)"))
if (!dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &errmsg))
goto out;
if (!bus_transaction_send_from_driver (transaction, pending->will_get_reply,

View file

@ -2,7 +2,7 @@
/* dispatch.c Message dispatcher
*
* Copyright (C) 2003 CodeFactory AB
* Copyright (C) 2003, 2004 Red Hat, Inc.
* Copyright (C) 2003, 2004, 2005 Red Hat, Inc.
* Copyright (C) 2004 Imendio HB
*
* Licensed under the Academic Free License version 2.1
@ -526,7 +526,7 @@ check_service_owner_changed_foreach (DBusConnection *connection,
CheckServiceOwnerChangedData *d = data;
DBusMessage *message;
DBusError error;
char *service_name, *old_owner, *new_owner;
const char *service_name, *old_owner, *new_owner;
if (d->expected_kind == SERVICE_CREATED
&& connection == d->skip_connection)
@ -567,9 +567,6 @@ check_service_owner_changed_foreach (DBusConnection *connection,
{
if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY))
{
dbus_free (service_name);
dbus_free (old_owner);
dbus_free (new_owner);
dbus_error_free (&error);
_dbus_wait_for_memory ();
goto reget_service_info_data;
@ -609,9 +606,6 @@ check_service_owner_changed_foreach (DBusConnection *connection,
d->failed = FALSE;
out:
dbus_free (service_name);
dbus_free (old_owner);
dbus_free (new_owner);
dbus_error_free (&error);
if (message)
@ -725,7 +719,11 @@ check_no_leftovers (BusContext *context)
&nmd);
if (nmd.failed)
return FALSE;
{
_dbus_verbose ("%s: leftover message found\n",
_DBUS_FUNCTION_NAME);
return FALSE;
}
else
return TRUE;
}
@ -738,17 +736,19 @@ check_hello_message (BusContext *context,
DBusConnection *connection)
{
DBusMessage *message;
DBusMessage *name_message;
dbus_uint32_t serial;
dbus_bool_t retval;
DBusError error;
char *name;
char *acquired;
const char *name;
const char *acquired;
retval = FALSE;
dbus_error_init (&error);
name = NULL;
acquired = NULL;
message = NULL;
name_message = NULL;
_dbus_verbose ("check_hello_message for %p\n", connection);
@ -889,9 +889,10 @@ check_hello_message (BusContext *context,
if (socd.failed)
goto out;
name_message = message;
/* Client should also have gotten ServiceAcquired */
dbus_message_unref (message);
message = pop_message_waiting_for_memory (connection);
if (message == NULL)
{
@ -935,6 +936,7 @@ check_hello_message (BusContext *context,
acquired, name);
goto out;
}
acquired = NULL;
}
if (!check_no_leftovers (context))
@ -943,13 +945,15 @@ check_hello_message (BusContext *context,
retval = TRUE;
out:
dbus_error_free (&error);
_dbus_verbose ("ending %s retval = %d\n", _DBUS_FUNCTION_NAME, retval);
dbus_free (name);
dbus_free (acquired);
dbus_error_free (&error);
if (message)
dbus_message_unref (message);
if (name_message)
dbus_message_unref (name_message);
return retval;
}
@ -1075,7 +1079,7 @@ check_get_connection_unix_user (BusContext *context,
base_service_name = dbus_bus_get_base_service (connection);
if (!dbus_message_append_args (message,
DBUS_TYPE_STRING, base_service_name,
DBUS_TYPE_STRING, &base_service_name,
DBUS_TYPE_INVALID))
{
dbus_message_unref (message);
@ -1212,7 +1216,7 @@ check_get_connection_unix_process_id (BusContext *context,
base_service_name = dbus_bus_get_base_service (connection);
if (!dbus_message_append_args (message,
DBUS_TYPE_STRING, base_service_name,
DBUS_TYPE_STRING, &base_service_name,
DBUS_TYPE_INVALID))
{
dbus_message_unref (message);
@ -1344,6 +1348,7 @@ check_add_match_all (BusContext *context,
dbus_bool_t retval;
dbus_uint32_t serial;
DBusError error;
const char *empty = "";
retval = FALSE;
dbus_error_init (&error);
@ -1360,7 +1365,7 @@ check_add_match_all (BusContext *context,
return TRUE;
/* empty string match rule matches everything */
if (!dbus_message_append_args (message, DBUS_TYPE_STRING, "",
if (!dbus_message_append_args (message, DBUS_TYPE_STRING, &empty,
DBUS_TYPE_INVALID))
{
dbus_message_unref (message);
@ -1525,6 +1530,8 @@ check_nonexistent_service_activation (BusContext *context,
DBusMessage *message;
dbus_uint32_t serial;
dbus_bool_t retval;
const char *nonexistent = NONEXISTENT_SERVICE_NAME;
dbus_uint32_t flags;
message = dbus_message_new_method_call (DBUS_SERVICE_ORG_FREEDESKTOP_DBUS,
DBUS_PATH_ORG_FREEDESKTOP_DBUS,
@ -1534,9 +1541,10 @@ check_nonexistent_service_activation (BusContext *context,
if (message == NULL)
return TRUE;
flags = 0;
if (!dbus_message_append_args (message,
DBUS_TYPE_STRING, NONEXISTENT_SERVICE_NAME,
DBUS_TYPE_UINT32, 0,
DBUS_TYPE_STRING, &nonexistent,
DBUS_TYPE_UINT32, &flags,
DBUS_TYPE_INVALID))
{
dbus_message_unref (message);
@ -1715,12 +1723,12 @@ static dbus_bool_t
check_base_service_activated (BusContext *context,
DBusConnection *connection,
DBusMessage *initial_message,
char **base_service_p)
const char **base_service_p)
{
DBusMessage *message;
dbus_bool_t retval;
DBusError error;
char *base_service, *base_service_from_bus, *old_owner;
const char *base_service, *base_service_from_bus, *old_owner;
retval = FALSE;
@ -1752,9 +1760,6 @@ check_base_service_activated (BusContext *context,
if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY))
{
dbus_error_free (&error);
dbus_free (base_service);
dbus_free (old_owner);
dbus_free (base_service_from_bus);
_dbus_wait_for_memory ();
goto reget_service_name_arg;
}
@ -1805,20 +1810,14 @@ check_base_service_activated (BusContext *context,
goto out;
}
retval = TRUE;
if (base_service_p)
{
*base_service_p = base_service;
base_service = NULL;
}
*base_service_p = base_service;
retval = TRUE;
out:
if (message)
dbus_message_unref (message);
dbus_free (base_service);
dbus_free (base_service_from_bus);
dbus_free (old_owner);
dbus_error_free (&error);
return retval;
@ -1848,7 +1847,7 @@ check_service_activated (BusContext *context,
"ServiceOwnerChanged"))
{
CheckServiceOwnerChangedData socd;
char *service_name, *base_service_from_bus, *old_owner;
const char *service_name, *base_service_from_bus, *old_owner;
reget_service_name_arg:
service_name = NULL;
@ -1864,9 +1863,6 @@ check_service_activated (BusContext *context,
if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY))
{
dbus_error_free (&error);
dbus_free (service_name);
dbus_free (old_owner);
dbus_free (base_service_from_bus);
_dbus_wait_for_memory ();
goto reget_service_name_arg;
}
@ -1875,9 +1871,6 @@ check_service_activated (BusContext *context,
_dbus_warn ("Message %s doesn't have a service name: %s\n",
"ServiceOwnerChanged (creation)",
error.message);
dbus_free (service_name);
dbus_free (old_owner);
dbus_free (base_service_from_bus);
goto out;
}
}
@ -1886,9 +1879,6 @@ check_service_activated (BusContext *context,
{
_dbus_warn ("Expected to see service %s created, saw %s instead\n",
activated_name, service_name);
dbus_free (service_name);
dbus_free (old_owner);
dbus_free (base_service_from_bus);
goto out;
}
@ -1896,23 +1886,16 @@ check_service_activated (BusContext *context,
{
_dbus_warn ("ServiceOwnerChanged reports wrong base service: %s owner, expected %s instead\n",
base_service_from_bus, base_service_name);
dbus_free (service_name);
dbus_free (old_owner);
dbus_free (base_service_from_bus);
goto out;
}
dbus_free (base_service_from_bus);
if (old_owner[0])
{
_dbus_warn ("expected a %s, got a %s\n",
"ServiceOwnerChanged (creation)",
"ServiceOwnerChanged (change)");
dbus_free (service_name);
dbus_free (old_owner);
goto out;
}
dbus_free (old_owner);
socd.expected_kind = SERVICE_CREATED;
socd.skip_connection = connection;
@ -1920,13 +1903,15 @@ check_service_activated (BusContext *context,
socd.expected_service_name = service_name;
bus_test_clients_foreach (check_service_owner_changed_foreach,
&socd);
dbus_free (service_name);
if (socd.failed)
goto out;
dbus_message_unref (message);
service_name = NULL;
old_owner = NULL;
base_service_from_bus = NULL;
message = pop_message_waiting_for_memory (connection);
if (message == NULL)
{
@ -2018,7 +2003,7 @@ check_service_auto_activated (BusContext *context,
DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS,
"ServiceOwnerChanged"))
{
char *service_name;
const char *service_name;
CheckServiceOwnerChangedData socd;
reget_service_name_arg:
@ -2046,7 +2031,6 @@ check_service_auto_activated (BusContext *context,
{
_dbus_warn ("Expected to see service %s created, saw %s instead\n",
activated_name, service_name);
dbus_free (service_name);
goto out;
}
@ -2057,8 +2041,6 @@ check_service_auto_activated (BusContext *context,
bus_test_clients_foreach (check_service_owner_changed_foreach,
&socd);
dbus_free (service_name);
if (socd.failed)
goto out;
@ -2068,6 +2050,7 @@ check_service_auto_activated (BusContext *context,
dbus_message_unref (message);
message = NULL;
service_name = NULL;
}
else
{
@ -2245,7 +2228,7 @@ check_send_exit_to_service (BusContext *context,
if (!dbus_message_is_error (message,
DBUS_ERROR_NO_REPLY))
{
warn_unexpected (connection, NULL,
warn_unexpected (connection, message,
"NoReply error from Exit() method call");
goto out;
}
@ -2355,7 +2338,7 @@ check_got_service_info (DBusMessage *message)
"ServiceOwnerChanged"))
{
DBusError error;
char *service_name, *old_owner, *new_owner;
const char *service_name, *old_owner, *new_owner;
dbus_error_init (&error);
reget_service_info_data:
@ -2373,9 +2356,6 @@ check_got_service_info (DBusMessage *message)
if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY))
{
dbus_error_free (&error);
dbus_free (service_name);
dbus_free (old_owner);
dbus_free (new_owner);
goto reget_service_info_data;
}
else
@ -2391,9 +2371,6 @@ check_got_service_info (DBusMessage *message)
else
message_kind = GOT_SOMETHING_ELSE;
dbus_free (service_name);
dbus_free (old_owner);
dbus_free (new_owner);
dbus_error_free (&error);
}
else if (dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_ERROR)
@ -2414,11 +2391,14 @@ check_existent_service_activation (BusContext *context,
DBusConnection *connection)
{
DBusMessage *message;
DBusMessage *base_service_message;
const char *base_service;
dbus_uint32_t serial;
dbus_bool_t retval;
char *base_service;
const char *existent = EXISTENT_SERVICE_NAME;
dbus_uint32_t flags;
base_service = NULL;
base_service_message = NULL;
message = dbus_message_new_method_call (DBUS_SERVICE_ORG_FREEDESKTOP_DBUS,
DBUS_PATH_ORG_FREEDESKTOP_DBUS,
@ -2428,9 +2408,10 @@ check_existent_service_activation (BusContext *context,
if (message == NULL)
return TRUE;
flags = 0;
if (!dbus_message_append_args (message,
DBUS_TYPE_STRING, EXISTENT_SERVICE_NAME,
DBUS_TYPE_UINT32, 0,
DBUS_TYPE_STRING, &existent,
DBUS_TYPE_UINT32, &flags,
DBUS_TYPE_INVALID))
{
dbus_message_unref (message);
@ -2511,7 +2492,7 @@ check_existent_service_activation (BusContext *context,
message, &base_service))
goto out;
dbus_message_unref (message);
base_service_message = message;
message = NULL;
/* We may need to block here for the test service to exit or finish up */
@ -2620,8 +2601,8 @@ check_existent_service_activation (BusContext *context,
if (message)
dbus_message_unref (message);
if (base_service)
dbus_free (base_service);
if (base_service_message)
dbus_message_unref (base_service_message);
return retval;
}
@ -2636,6 +2617,8 @@ check_segfault_service_activation (BusContext *context,
DBusMessage *message;
dbus_uint32_t serial;
dbus_bool_t retval;
const char *segv_service;
dbus_uint32_t flags;
message = dbus_message_new_method_call (DBUS_SERVICE_ORG_FREEDESKTOP_DBUS,
DBUS_PATH_ORG_FREEDESKTOP_DBUS,
@ -2645,10 +2628,11 @@ check_segfault_service_activation (BusContext *context,
if (message == NULL)
return TRUE;
segv_service = "org.freedesktop.DBus.TestSuiteSegfaultService";
flags = 0;
if (!dbus_message_append_args (message,
DBUS_TYPE_STRING,
"org.freedesktop.DBus.TestSuiteSegfaultService",
DBUS_TYPE_UINT32, 0,
DBUS_TYPE_STRING, &segv_service,
DBUS_TYPE_UINT32, &flags,
DBUS_TYPE_INVALID))
{
dbus_message_unref (message);
@ -2833,11 +2817,13 @@ check_existent_service_auto_activation (BusContext *context,
DBusConnection *connection)
{
DBusMessage *message;
DBusMessage *base_service_message;
dbus_uint32_t serial;
dbus_bool_t retval;
char *base_service;
const char *base_service;
const char *text;
base_service = NULL;
base_service_message = NULL;
message = dbus_message_new_method_call (EXISTENT_SERVICE_NAME,
"/org/freedesktop/TestSuite",
@ -2849,8 +2835,9 @@ check_existent_service_auto_activation (BusContext *context,
dbus_message_set_auto_activation (message, TRUE);
text = TEST_ECHO_MESSAGE;
if (!dbus_message_append_args (message,
DBUS_TYPE_STRING, TEST_ECHO_MESSAGE,
DBUS_TYPE_STRING, &text,
DBUS_TYPE_INVALID))
{
dbus_message_unref (message);
@ -2902,7 +2889,7 @@ check_existent_service_auto_activation (BusContext *context,
message, &base_service))
goto out;
dbus_message_unref (message);
base_service_message = message;
message = NULL;
/* We may need to block here for the test service to exit or finish up */
@ -3010,8 +2997,8 @@ check_existent_service_auto_activation (BusContext *context,
if (message)
dbus_message_unref (message);
if (base_service)
dbus_free (base_service);
if (base_service_message)
dbus_message_unref (base_service_message);
return retval;
}

View file

@ -47,10 +47,11 @@ bus_driver_send_service_owner_changed (const char *service_name,
{
DBusMessage *message;
dbus_bool_t retval;
const char null_service[] = { '\000' };
const char *null_service;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
null_service = "";
_dbus_verbose ("sending service owner changed: %s [%s -> %s]\n",
service_name,
old_owner ? old_owner : null_service,
@ -70,9 +71,9 @@ bus_driver_send_service_owner_changed (const char *service_name,
goto oom;
if (!dbus_message_append_args (message,
DBUS_TYPE_STRING, service_name,
DBUS_TYPE_STRING, old_owner ? old_owner : null_service,
DBUS_TYPE_STRING, new_owner ? new_owner : null_service,
DBUS_TYPE_STRING, &service_name,
DBUS_TYPE_STRING, old_owner ? &old_owner : &null_service,
DBUS_TYPE_STRING, new_owner ? &new_owner : &null_service,
DBUS_TYPE_INVALID))
goto oom;
@ -111,7 +112,7 @@ bus_driver_send_service_lost (DBusConnection *connection,
if (!dbus_message_set_destination (message, bus_connection_get_name (connection)) ||
!dbus_message_append_args (message,
DBUS_TYPE_STRING, service_name,
DBUS_TYPE_STRING, &service_name,
DBUS_TYPE_INVALID))
{
dbus_message_unref (message);
@ -154,7 +155,7 @@ bus_driver_send_service_acquired (DBusConnection *connection,
if (!dbus_message_set_destination (message, bus_connection_get_name (connection)) ||
!dbus_message_append_args (message,
DBUS_TYPE_STRING, service_name,
DBUS_TYPE_STRING, &service_name,
DBUS_TYPE_INVALID))
{
dbus_message_unref (message);
@ -341,7 +342,7 @@ bus_driver_send_welcome_message (DBusConnection *connection,
}
if (!dbus_message_append_args (welcome,
DBUS_TYPE_STRING, name,
DBUS_TYPE_STRING, &name,
DBUS_TYPE_INVALID))
{
dbus_message_unref (welcome);
@ -374,6 +375,9 @@ bus_driver_handle_list_services (DBusConnection *connection,
int len;
char **services;
BusRegistry *registry;
int i;
DBusMessageIter iter;
DBusMessageIter sub;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
@ -392,10 +396,12 @@ bus_driver_handle_list_services (DBusConnection *connection,
BUS_SET_OOM (error);
return FALSE;
}
dbus_message_append_iter_init (reply, &iter);
if (!dbus_message_append_args (reply,
DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, services, len,
DBUS_TYPE_INVALID))
if (!dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY,
DBUS_TYPE_STRING_AS_STRING,
&sub))
{
dbus_free_string_array (services);
dbus_message_unref (reply);
@ -403,6 +409,28 @@ bus_driver_handle_list_services (DBusConnection *connection,
return FALSE;
}
i = 0;
while (i < len)
{
if (!dbus_message_iter_append_basic (&sub, DBUS_TYPE_STRING,
&services[i]))
{
dbus_free_string_array (services);
dbus_message_unref (reply);
BUS_SET_OOM (error);
return FALSE;
}
++i;
}
if (!dbus_message_iter_close_container (&iter, &sub))
{
dbus_free_string_array (services);
dbus_message_unref (reply);
BUS_SET_OOM (error);
return FALSE;
}
dbus_free_string_array (services);
if (!bus_transaction_send_from_driver (transaction, connection, reply))
@ -426,7 +454,7 @@ bus_driver_handle_acquire_service (DBusConnection *connection,
{
DBusMessage *reply;
DBusString service_name;
char *name;
const char *name;
int service_reply;
dbus_uint32_t flags;
dbus_bool_t retval;
@ -462,7 +490,7 @@ bus_driver_handle_acquire_service (DBusConnection *connection,
goto out;
}
if (!dbus_message_append_args (reply, DBUS_TYPE_UINT32, service_reply, DBUS_TYPE_INVALID))
if (!dbus_message_append_args (reply, DBUS_TYPE_UINT32, &service_reply, DBUS_TYPE_INVALID))
{
BUS_SET_OOM (error);
goto out;
@ -477,7 +505,6 @@ bus_driver_handle_acquire_service (DBusConnection *connection,
retval = TRUE;
out:
dbus_free (name);
if (reply)
dbus_message_unref (reply);
return retval;
@ -492,8 +519,8 @@ bus_driver_handle_service_exists (DBusConnection *connection,
DBusMessage *reply;
DBusString service_name;
BusService *service;
dbus_bool_t service_exists;
char *name;
unsigned char service_exists;
const char *name;
dbus_bool_t retval;
BusRegistry *registry;
@ -527,7 +554,7 @@ bus_driver_handle_service_exists (DBusConnection *connection,
}
if (!dbus_message_append_args (reply,
DBUS_TYPE_BOOLEAN, service_exists,
DBUS_TYPE_BOOLEAN, &service_exists,
0))
{
BUS_SET_OOM (error);
@ -545,7 +572,6 @@ bus_driver_handle_service_exists (DBusConnection *connection,
out:
if (reply)
dbus_message_unref (reply);
dbus_free (name);
return retval;
}
@ -557,7 +583,7 @@ bus_driver_handle_activate_service (DBusConnection *connection,
DBusError *error)
{
dbus_uint32_t flags;
char *name;
const char *name;
dbus_bool_t retval;
BusActivation *activation;
@ -588,7 +614,6 @@ bus_driver_handle_activate_service (DBusConnection *connection,
retval = TRUE;
out:
dbus_free (name);
return retval;
}
@ -626,7 +651,7 @@ bus_driver_handle_add_match (DBusConnection *connection,
DBusError *error)
{
BusMatchRule *rule;
char *text;
const char *text;
DBusString str;
BusMatchmaker *matchmaker;
@ -677,7 +702,6 @@ bus_driver_handle_add_match (DBusConnection *connection,
}
bus_match_rule_unref (rule);
dbus_free (text);
return TRUE;
@ -685,8 +709,6 @@ bus_driver_handle_add_match (DBusConnection *connection,
_DBUS_ASSERT_ERROR_IS_SET (error);
if (rule)
bus_match_rule_unref (rule);
if (text)
dbus_free (text);
return FALSE;
}
@ -697,7 +719,7 @@ bus_driver_handle_remove_match (DBusConnection *connection,
DBusError *error)
{
BusMatchRule *rule;
char *text;
const char *text;
DBusString str;
BusMatchmaker *matchmaker;
@ -733,7 +755,6 @@ bus_driver_handle_remove_match (DBusConnection *connection,
goto failed;
bus_match_rule_unref (rule);
dbus_free (text);
return TRUE;
@ -741,8 +762,6 @@ bus_driver_handle_remove_match (DBusConnection *connection,
_DBUS_ASSERT_ERROR_IS_SET (error);
if (rule)
bus_match_rule_unref (rule);
if (text)
dbus_free (text);
return FALSE;
}
@ -752,7 +771,7 @@ bus_driver_handle_get_service_owner (DBusConnection *connection,
DBusMessage *message,
DBusError *error)
{
char *text;
const char *text;
const char *base_name;
DBusString str;
BusRegistry *registry;
@ -796,7 +815,7 @@ bus_driver_handle_get_service_owner (DBusConnection *connection,
goto oom;
if (! dbus_message_append_args (reply,
DBUS_TYPE_STRING, base_name,
DBUS_TYPE_STRING, &base_name,
DBUS_TYPE_INVALID))
goto oom;
@ -804,7 +823,6 @@ bus_driver_handle_get_service_owner (DBusConnection *connection,
goto oom;
dbus_message_unref (reply);
dbus_free (text);
return TRUE;
@ -815,7 +833,6 @@ bus_driver_handle_get_service_owner (DBusConnection *connection,
_DBUS_ASSERT_ERROR_IS_SET (error);
if (reply)
dbus_message_unref (reply);
dbus_free (text);
return FALSE;
}
@ -825,13 +842,14 @@ bus_driver_handle_get_connection_unix_user (DBusConnection *connection,
DBusMessage *message,
DBusError *error)
{
char *service;
const char *service;
DBusString str;
BusRegistry *registry;
BusService *serv;
DBusConnection *conn;
DBusMessage *reply;
unsigned long uid;
dbus_uint32_t uid32;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
@ -871,8 +889,9 @@ bus_driver_handle_get_connection_unix_user (DBusConnection *connection,
goto failed;
}
uid32 = uid;
if (! dbus_message_append_args (reply,
DBUS_TYPE_UINT32, (dbus_uint32_t) uid,
DBUS_TYPE_UINT32, &uid32,
DBUS_TYPE_INVALID))
goto oom;
@ -880,7 +899,6 @@ bus_driver_handle_get_connection_unix_user (DBusConnection *connection,
goto oom;
dbus_message_unref (reply);
dbus_free (service);
return TRUE;
@ -891,7 +909,6 @@ bus_driver_handle_get_connection_unix_user (DBusConnection *connection,
_DBUS_ASSERT_ERROR_IS_SET (error);
if (reply)
dbus_message_unref (reply);
dbus_free (service);
return FALSE;
}
@ -901,13 +918,14 @@ bus_driver_handle_get_connection_unix_process_id (DBusConnection *connection,
DBusMessage *message,
DBusError *error)
{
char *service;
const char *service;
DBusString str;
BusRegistry *registry;
BusService *serv;
DBusConnection *conn;
DBusMessage *reply;
unsigned long pid;
dbus_uint32_t pid32;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
@ -947,8 +965,9 @@ bus_driver_handle_get_connection_unix_process_id (DBusConnection *connection,
goto failed;
}
pid32 = pid;
if (! dbus_message_append_args (reply,
DBUS_TYPE_UINT32, (dbus_uint32_t) pid,
DBUS_TYPE_UINT32, &pid32,
DBUS_TYPE_INVALID))
goto oom;
@ -956,7 +975,6 @@ bus_driver_handle_get_connection_unix_process_id (DBusConnection *connection,
goto oom;
dbus_message_unref (reply);
dbus_free (service);
return TRUE;
@ -967,7 +985,6 @@ bus_driver_handle_get_connection_unix_process_id (DBusConnection *connection,
_DBUS_ASSERT_ERROR_IS_SET (error);
if (reply)
dbus_message_unref (reply);
dbus_free (service);
return FALSE;
}

View file

@ -156,13 +156,18 @@ bus_registry_ensure (BusRegistry *registry,
service->registry = registry;
service->refcount = 1;
_dbus_verbose ("copying string %p '%s' to service->name\n",
service_name, _dbus_string_get_const_data (service_name));
if (!_dbus_string_copy_data (service_name, &service->name))
{
_dbus_mem_pool_dealloc (registry->service_pool, service);
BUS_SET_OOM (error);
return NULL;
}
_dbus_verbose ("copied string %p '%s' to '%s'\n",
service_name, _dbus_string_get_const_data (service_name),
service->name);
if (!bus_driver_send_service_owner_changed (service->name,
NULL,

View file

@ -23,6 +23,7 @@
#include "signals.h"
#include "services.h"
#include "utils.h"
#include <dbus/dbus-marshal-validate.h>
struct BusMatchRule
{
@ -656,7 +657,7 @@ bus_match_rule_parse (DBusConnection *matches_go_to,
goto failed;
}
if (!_dbus_string_validate_service (&tmp_str, 0, len))
if (!_dbus_validate_service (&tmp_str, 0, len))
{
dbus_set_error (error, DBUS_ERROR_MATCH_RULE_INVALID,
"Sender service name '%s' is invalid\n", value);
@ -678,7 +679,7 @@ bus_match_rule_parse (DBusConnection *matches_go_to,
goto failed;
}
if (!_dbus_string_validate_interface (&tmp_str, 0, len))
if (!_dbus_validate_interface (&tmp_str, 0, len))
{
dbus_set_error (error, DBUS_ERROR_MATCH_RULE_INVALID,
"Interface name '%s' is invalid\n", value);
@ -700,7 +701,7 @@ bus_match_rule_parse (DBusConnection *matches_go_to,
goto failed;
}
if (!_dbus_string_validate_member (&tmp_str, 0, len))
if (!_dbus_validate_member (&tmp_str, 0, len))
{
dbus_set_error (error, DBUS_ERROR_MATCH_RULE_INVALID,
"Member name '%s' is invalid\n", value);
@ -722,7 +723,7 @@ bus_match_rule_parse (DBusConnection *matches_go_to,
goto failed;
}
if (!_dbus_string_validate_path (&tmp_str, 0, len))
if (!_dbus_validate_path (&tmp_str, 0, len))
{
dbus_set_error (error, DBUS_ERROR_MATCH_RULE_INVALID,
"Path '%s' is invalid\n", value);
@ -744,7 +745,7 @@ bus_match_rule_parse (DBusConnection *matches_go_to,
goto failed;
}
if (!_dbus_string_validate_service (&tmp_str, 0, len))
if (!_dbus_validate_service (&tmp_str, 0, len))
{
dbus_set_error (error, DBUS_ERROR_MATCH_RULE_INVALID,
"Destination service name '%s' is invalid\n", value);

View file

@ -12,3 +12,5 @@ dbus-test
dbus-arch-deps.h
.dbus-keyrings
dbus-glib-error-enum.h
*.gcno
*.gcda

View file

@ -54,6 +54,12 @@ DBUS_LIB_SOURCES= \
dbus-errors.c \
dbus-keyring.c \
dbus-keyring.h \
dbus-marshal-header.c \
dbus-marshal-header.h \
dbus-marshal-recursive.c \
dbus-marshal-recursive.h \
dbus-marshal-validate.c \
dbus-marshal-validate.h \
dbus-message.c \
dbus-message-internal.h \
dbus-object-tree.c \
@ -98,13 +104,11 @@ DBUS_SHARED_SOURCES= \
dbus-internals.h \
dbus-list.c \
dbus-list.h \
dbus-marshal.c \
dbus-marshal.h \
dbus-marshal-basic.c \
dbus-marshal-basic.h \
dbus-memory.c \
dbus-mempool.c \
dbus-mempool.h \
dbus-message-builder.c \
dbus-message-builder.h \
dbus-spawn.c \
dbus-spawn.h \
dbus-string.c \

View file

@ -29,7 +29,6 @@
#include "dbus-string.h"
#include "dbus-hash.h"
#include "dbus-internals.h"
#include "dbus-marshal.h"
#include "dbus-userdb.h"
/**

View file

@ -479,8 +479,13 @@ dbus_bus_register (DBusConnection *connection,
DBUS_TYPE_INVALID))
goto out;
bd->base_service = name;
bd->base_service = _dbus_strdup (name);
if (bd->base_service == NULL)
{
_DBUS_SET_OOM (error);
goto out;
}
retval = TRUE;
out:
@ -578,7 +583,7 @@ dbus_bus_get_unix_user (DBusConnection *connection,
}
if (!dbus_message_append_args (message,
DBUS_TYPE_STRING, service,
DBUS_TYPE_STRING, &service,
DBUS_TYPE_INVALID))
{
dbus_message_unref (message);
@ -659,8 +664,8 @@ dbus_bus_acquire_service (DBusConnection *connection,
}
if (!dbus_message_append_args (message,
DBUS_TYPE_STRING, service_name,
DBUS_TYPE_UINT32, flags,
DBUS_TYPE_STRING, &service_name,
DBUS_TYPE_UINT32, &flags,
DBUS_TYPE_INVALID))
{
dbus_message_unref (message);
@ -731,7 +736,7 @@ dbus_bus_service_exists (DBusConnection *connection,
}
if (!dbus_message_append_args (message,
DBUS_TYPE_STRING, service_name,
DBUS_TYPE_STRING, &service_name,
DBUS_TYPE_INVALID))
{
dbus_message_unref (message);
@ -791,8 +796,8 @@ dbus_bus_activate_service (DBusConnection *connection,
DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS,
"ActivateService");
if (!dbus_message_append_args (msg, DBUS_TYPE_STRING, service_name,
DBUS_TYPE_UINT32, flags, DBUS_TYPE_INVALID))
if (!dbus_message_append_args (msg, DBUS_TYPE_STRING, &service_name,
DBUS_TYPE_UINT32, &flags, DBUS_TYPE_INVALID))
{
dbus_message_unref (msg);
_DBUS_SET_OOM (error);
@ -895,7 +900,7 @@ dbus_bus_add_match (DBusConnection *connection,
return;
}
if (!dbus_message_append_args (msg, DBUS_TYPE_STRING, rule,
if (!dbus_message_append_args (msg, DBUS_TYPE_STRING, &rule,
DBUS_TYPE_INVALID))
{
dbus_message_unref (msg);
@ -933,7 +938,7 @@ dbus_bus_remove_match (DBusConnection *connection,
DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS,
"RemoveMatch");
if (!dbus_message_append_args (msg, DBUS_TYPE_STRING, rule,
if (!dbus_message_append_args (msg, DBUS_TYPE_STRING, &rule,
DBUS_TYPE_INVALID))
{
dbus_message_unref (msg);

View file

@ -38,7 +38,6 @@
#include "dbus-string.h"
#include "dbus-pending-call.h"
#include "dbus-object-tree.h"
#include "dbus-marshal.h"
#if 0
#define CONNECTION_LOCK(connection) do { \
@ -1562,15 +1561,6 @@ _dbus_connection_send_preallocated_unlocked (DBusConnection *connection,
connection->n_outgoing += 1;
sig = dbus_message_get_signature (message);
#ifndef DBUS_DISABLE_ASSERT
{
DBusString foo;
_dbus_verbose (" validating signature '%s'\n", sig);
_dbus_string_init_const (&foo, sig);
_dbus_assert (_dbus_string_validate_signature (&foo, 0,
_dbus_string_get_length (&foo)));
}
#endif
_dbus_verbose ("Message %p (%d %s %s '%s') added to outgoing queue %p, %d pending to send\n",
message,

View file

@ -354,42 +354,6 @@ _dbus_string_array_contains (const char **array,
return FALSE;
}
/**
* Returns a string describing the given type.
*
* @param type the type to describe
* @returns a constant string describing the type
*/
const char *
_dbus_type_to_string (int type)
{
switch (type)
{
case DBUS_TYPE_INVALID:
return "invalid";
case DBUS_TYPE_NIL:
return "nil";
case DBUS_TYPE_BOOLEAN:
return "boolean";
case DBUS_TYPE_INT32:
return "int32";
case DBUS_TYPE_UINT32:
return "uint32";
case DBUS_TYPE_DOUBLE:
return "double";
case DBUS_TYPE_STRING:
return "string";
case DBUS_TYPE_CUSTOM:
return "custom";
case DBUS_TYPE_ARRAY:
return "array";
case DBUS_TYPE_DICT:
return "dict";
default:
return "unknown";
}
}
/**
* Returns a string describing the given name.
*
@ -525,6 +489,9 @@ _dbus_test_oom_handling (const char *description,
void *data)
{
int approx_mallocs;
const char *setting;
int max_failures_to_try;
int i;
/* Run once to see about how many mallocs are involved */
@ -540,21 +507,30 @@ _dbus_test_oom_handling (const char *description,
_dbus_verbose ("\n=================\n%s: about %d mallocs total\n=================\n",
description, approx_mallocs);
_dbus_set_fail_alloc_failures (1);
if (!run_failing_each_malloc (approx_mallocs, description, func, data))
return FALSE;
setting = _dbus_getenv ("DBUS_TEST_MALLOC_FAILURES");
if (setting != NULL)
{
DBusString str;
long v;
_dbus_string_init_const (&str, setting);
v = 4;
if (!_dbus_string_parse_int (&str, 0, &v, NULL))
_dbus_warn ("couldn't parse '%s' as integer\n", setting);
max_failures_to_try = v;
}
else
{
max_failures_to_try = 4;
}
_dbus_set_fail_alloc_failures (2);
if (!run_failing_each_malloc (approx_mallocs, description, func, data))
return FALSE;
_dbus_set_fail_alloc_failures (3);
if (!run_failing_each_malloc (approx_mallocs, description, func, data))
return FALSE;
_dbus_set_fail_alloc_failures (4);
if (!run_failing_each_malloc (approx_mallocs, description, func, data))
return FALSE;
i = setting ? max_failures_to_try - 1 : 1;
while (i < max_failures_to_try)
{
_dbus_set_fail_alloc_failures (i);
if (!run_failing_each_malloc (approx_mallocs, description, func, data))
return FALSE;
++i;
}
_dbus_verbose ("\n=================\n%s: all iterations passed\n=================\n",
description);

View file

@ -170,6 +170,7 @@ extern const char _dbus_return_if_fail_warning_format[];
#define _DBUS_ALIGN_ADDRESS(this, boundary) \
((void*)_DBUS_ALIGN_VALUE(this, boundary))
char* _dbus_strdup (const char *str);
void* _dbus_memdup (const void *mem,
size_t n_bytes);
@ -207,13 +208,12 @@ dbus_bool_t _dbus_set_fd_nonblocking (int fd,
DBusError *error);
void _dbus_verbose_bytes (const unsigned char *data,
int len);
int len,
int offset);
void _dbus_verbose_bytes_of_string (const DBusString *str,
int start,
int len);
const char* _dbus_type_to_string (int type);
const char* _dbus_header_field_to_string (int header_field);
extern const char _dbus_no_memory_message[];

View file

@ -30,7 +30,7 @@
#define MAINLOOP_SPEW 0
#ifdef MAINLOOP_SPEW
#if MAINLOOP_SPEW
#ifdef DBUS_ENABLE_VERBOSE_MODE
static const char*
watch_flags_to_string (int flags)

View file

@ -150,6 +150,7 @@ swap_8_octets (DBusBasicValue *value,
}
}
#if 0
static DBusBasicValue
unpack_8_octets (int byte_order,
const unsigned char *data)
@ -171,6 +172,7 @@ unpack_8_octets (int byte_order,
return r;
}
#endif
/**
* Unpacks a 32 bit unsigned integer from a data pointer
@ -404,10 +406,12 @@ _dbus_marshal_set_basic (DBusString *str,
break;
case DBUS_TYPE_STRING:
case DBUS_TYPE_OBJECT_PATH:
_dbus_assert (vp->str != NULL);
return set_string (str, pos, vp->str, byte_order,
old_end_pos, new_end_pos);
break;
case DBUS_TYPE_SIGNATURE:
_dbus_assert (vp->str != NULL);
return set_signature (str, pos, vp->str, byte_order,
old_end_pos, new_end_pos);
break;
@ -429,6 +433,8 @@ read_4_octets (const DBusString *str,
if (new_pos)
*new_pos = pos + 4;
_dbus_assert (pos + 4 <= _dbus_string_get_length (str));
return unpack_4_octets (byte_order,
_dbus_string_get_const_data (str) + pos);
}
@ -554,52 +560,52 @@ _dbus_marshal_read_basic (const DBusString *str,
}
/**
* Reads an array of fixed-length basic values. Does not work for
* arrays of string or container types.
* Reads a block of fixed-length basic values, as an optimization
* vs. reading each one individually into a new buffer.
*
* This function returns the array in-place; it does not make a copy,
* This function returns the data in-place; it does not make a copy,
* and it does not swap the bytes.
*
* If you ask for #DBUS_TYPE_DOUBLE you will get a "const double*" back
* and the "value" argument should be a "const double**" and so on.
*
* @todo last I checked only the test suite uses this function
*
* @todo we aren't using this function (except in the test suite)
*
* @param str the string to read from
* @param pos position to read from
* @param element_type type of array elements
* @param value place to return the array
* @param n_elements place to return number of array elements
* @param n_elements number of array elements to read
* @param byte_order the byte order, used to read the array length
* @param new_pos #NULL or location to store a position after the elements
*/
void
_dbus_marshal_read_fixed_array (const DBusString *str,
_dbus_marshal_read_fixed_multi (const DBusString *str,
int pos,
int element_type,
void *value,
int *n_elements,
int n_elements,
int byte_order,
int *new_pos)
{
dbus_uint32_t array_len;
int array_len;
int alignment;
_dbus_assert (_dbus_type_is_fixed (element_type));
_dbus_assert (_dbus_type_is_basic (element_type));
pos = _DBUS_ALIGN_VALUE (pos, 4);
array_len = _dbus_marshal_read_uint32 (str, pos, byte_order, &pos);
#if 0
_dbus_verbose ("reading %d elements of %s\n",
n_elements, _dbus_type_to_string (element_type));
#endif
alignment = _dbus_type_get_alignment (element_type);
pos = _DBUS_ALIGN_VALUE (pos, alignment);
array_len = n_elements * alignment;
*(const DBusBasicValue**) value = (void*) _dbus_string_get_const_data_len (str, pos, array_len);
*n_elements = array_len / alignment;
if (new_pos)
*new_pos = pos + array_len;
}
@ -682,16 +688,12 @@ marshal_len_followed_by_bytes (int marshal_as,
if (insert_at > _dbus_string_get_length (str))
_dbus_warn ("insert_at = %d string len = %d data_len = %d\n",
insert_at, _dbus_string_get_length (str), data_len);
if (marshal_as == MARSHAL_AS_BYTE_ARRAY)
value_len = data_len;
else
value_len = data_len + 1; /* value has a nul */
/* FIXME this is probably broken for byte arrays because
* DBusString wants strings to be nul-terminated?
* Maybe I planned on this when writing init_const_len though
*/
_dbus_string_init_const_len (&value_str, value, value_len);
pos = insert_at;
@ -814,9 +816,11 @@ _dbus_marshal_write_basic (DBusString *str,
case DBUS_TYPE_STRING:
case DBUS_TYPE_OBJECT_PATH:
_dbus_assert (vp->str != NULL);
return marshal_string (str, insert_at, vp->str, byte_order, pos_after);
break;
case DBUS_TYPE_SIGNATURE:
_dbus_assert (vp->str != NULL);
return marshal_signature (str, insert_at, vp->str, pos_after);
break;
default:
@ -834,9 +838,23 @@ marshal_1_octets_array (DBusString *str,
int byte_order,
int *pos_after)
{
return marshal_len_followed_by_bytes (MARSHAL_AS_BYTE_ARRAY,
str, insert_at, value, n_elements,
byte_order, pos_after);
int pos;
DBusString value_str;
_dbus_string_init_const_len (&value_str, value, n_elements);
pos = insert_at;
if (!_dbus_string_copy_len (&value_str, 0, n_elements,
str, pos))
return FALSE;
pos += n_elements;
if (pos_after)
*pos_after = pos;
return TRUE;
}
static void
@ -885,7 +903,7 @@ swap_array (DBusString *str,
}
static dbus_bool_t
marshal_fixed_array (DBusString *str,
marshal_fixed_multi (DBusString *str,
int insert_at,
const DBusBasicValue *value,
int n_elements,
@ -896,18 +914,15 @@ marshal_fixed_array (DBusString *str,
int old_string_len;
int array_start;
DBusString t;
int len_in_bytes;
_dbus_assert (n_elements <= DBUS_MAXIMUM_ARRAY_LENGTH / alignment);
old_string_len = _dbus_string_get_length (str);
/* The array length is the length in bytes of the array,
* *excluding* alignment padding.
*/
if (!marshal_4_octets (str, insert_at, n_elements * alignment,
byte_order, &array_start))
goto error;
_dbus_verbose ("marshaled len %d at %d array start %d\n", n_elements * alignment, insert_at, array_start);
len_in_bytes = n_elements * alignment;
array_start = insert_at;
/* Note that we do alignment padding unconditionally
* even if the array is empty; this means that
* padding + len is always equal to the number of bytes
@ -919,7 +934,7 @@ marshal_fixed_array (DBusString *str,
_dbus_string_init_const_len (&t,
(const unsigned char*) value,
n_elements * alignment);
len_in_bytes);
if (!_dbus_string_copy (&t, 0,
str, array_start))
@ -927,6 +942,9 @@ marshal_fixed_array (DBusString *str,
swap_array (str, array_start, n_elements, byte_order, alignment);
if (pos_after)
*pos_after = array_start + len_in_bytes;
return TRUE;
error:
@ -937,9 +955,9 @@ marshal_fixed_array (DBusString *str,
}
/**
* Marshals an array of values of fixed-length type.
* _dbus_type_is_fixed() returns #TRUE for these types,
* which are the basic types minus the string-like types.
* Marshals a block of values of fixed-length type all at once, as an
* optimization. _dbus_type_is_fixed() returns #TRUE for fixed-length
* types, which are the basic types minus the string-like types.
*
* The value argument should be the adddress of an
* array, so e.g. "const dbus_uint32_t**"
@ -948,13 +966,13 @@ marshal_fixed_array (DBusString *str,
* @param insert_at where to insert the value
* @param element_type type of array elements
* @param value address of an array to marshal
* @param len number of elements in the array
* @param n_elements number of elements in the array
* @param byte_order byte order
* @param pos_after #NULL or the position after the type
* @returns #TRUE on success
**/
dbus_bool_t
_dbus_marshal_write_fixed_array (DBusString *str,
_dbus_marshal_write_fixed_multi (DBusString *str,
int insert_at,
int element_type,
const void *value,
@ -963,9 +981,15 @@ _dbus_marshal_write_fixed_array (DBusString *str,
int *pos_after)
{
const void* vp = *(const DBusBasicValue**)value;
_dbus_assert (_dbus_type_is_fixed (element_type));
_dbus_assert (n_elements >= 0);
#if 0
_dbus_verbose ("writing %d elements of %s\n",
n_elements, _dbus_type_to_string (element_type));
#endif
switch (element_type)
{
case DBUS_TYPE_BOOLEAN:
@ -976,12 +1000,12 @@ _dbus_marshal_write_fixed_array (DBusString *str,
break;
case DBUS_TYPE_INT32:
case DBUS_TYPE_UINT32:
return marshal_fixed_array (str, insert_at, vp, n_elements, byte_order, 4, pos_after);
return marshal_fixed_multi (str, insert_at, vp, n_elements, byte_order, 4, pos_after);
break;
case DBUS_TYPE_INT64:
case DBUS_TYPE_UINT64:
case DBUS_TYPE_DOUBLE:
return marshal_fixed_array (str, insert_at, vp, n_elements, byte_order, 8, pos_after);
return marshal_fixed_multi (str, insert_at, vp, n_elements, byte_order, 8, pos_after);
break;
default:
@ -1008,6 +1032,9 @@ _dbus_marshal_skip_basic (const DBusString *str,
int byte_order,
int *pos)
{
_dbus_assert (byte_order == DBUS_LITTLE_ENDIAN ||
byte_order == DBUS_BIG_ENDIAN);
switch (type)
{
case DBUS_TYPE_BYTE:
@ -1031,7 +1058,7 @@ _dbus_marshal_skip_basic (const DBusString *str,
int len;
len = _dbus_marshal_read_uint32 (str, *pos, byte_order, pos);
*pos += len + 1; /* length plus nul */
}
break;
@ -1231,6 +1258,50 @@ _dbus_type_is_fixed (int typecode)
}
}
/**
* Returns a string describing the given type.
*
* @param typecode the type to describe
* @returns a constant string describing the type
*/
const char *
_dbus_type_to_string (int typecode)
{
switch (typecode)
{
case DBUS_TYPE_INVALID:
return "invalid";
case DBUS_TYPE_BOOLEAN:
return "boolean";
case DBUS_TYPE_BYTE:
return "byte";
case DBUS_TYPE_INT32:
return "int32";
case DBUS_TYPE_UINT32:
return "uint32";
case DBUS_TYPE_DOUBLE:
return "double";
case DBUS_TYPE_STRING:
return "string";
case DBUS_TYPE_OBJECT_PATH:
return "object_path";
case DBUS_TYPE_SIGNATURE:
return "signature";
case DBUS_TYPE_STRUCT:
return "struct";
case DBUS_TYPE_ARRAY:
return "array";
case DBUS_TYPE_VARIANT:
return "variant";
case DBUS_STRUCT_BEGIN_CHAR:
return "begin_struct";
case DBUS_STRUCT_END_CHAR:
return "end_struct";
default:
return "unknown";
}
}
/**
* If in verbose mode, print a block of binary data.
*
@ -1367,6 +1438,10 @@ swap_test_array (void *array,
int alignment)
{
DBusString t;
if (alignment == 1)
return;
_dbus_string_init_const_len (&t, array, len_bytes);
swap_array (&t, 0, len_bytes / alignment, byte_order, alignment);
}
@ -1420,8 +1495,13 @@ swap_test_array (void *array,
#define MARSHAL_FIXED_ARRAY(typename, byte_order, literal) \
do { \
int next; \
v_UINT32 = sizeof(literal); \
if (!_dbus_marshal_write_basic (&str, pos, DBUS_TYPE_UINT32, &v_UINT32, \
byte_order, &next)) \
_dbus_assert_not_reached ("no memory"); \
v_ARRAY_##typename = literal; \
if (!_dbus_marshal_write_fixed_array (&str, pos, DBUS_TYPE_##typename, \
if (!_dbus_marshal_write_fixed_multi (&str, next, DBUS_TYPE_##typename, \
&v_ARRAY_##typename, _DBUS_N_ELEMENTS(literal), \
byte_order, NULL)) \
_dbus_assert_not_reached ("no memory"); \
@ -1429,10 +1509,14 @@ swap_test_array (void *array,
#define DEMARSHAL_FIXED_ARRAY(typename, byte_order) \
do { \
_dbus_marshal_read_fixed_array (&str, pos, DBUS_TYPE_##typename, &v_ARRAY_##typename, \
&n_elements, byte_order, &pos); \
swap_test_array (v_ARRAY_##typename, n_elements * sizeof(v_ARRAY_##typename[0]), \
byte_order, sizeof(v_ARRAY_##typename[0])); \
int next; \
alignment = _dbus_type_get_alignment (DBUS_TYPE_##typename); \
v_UINT32 = _dbus_marshal_read_uint32 (&str, dump_pos, byte_order, &next); \
_dbus_marshal_read_fixed_multi (&str, next, DBUS_TYPE_##typename, &v_ARRAY_##typename, \
v_UINT32/alignment, \
byte_order, NULL); \
swap_test_array (v_ARRAY_##typename, v_UINT32, \
byte_order, alignment); \
} while (0)
#define DEMARSHAL_FIXED_ARRAY_AND_CHECK(typename, byte_order, literal) \
@ -1461,9 +1545,10 @@ swap_test_array (void *array,
dbus_bool_t
_dbus_marshal_test (void)
{
int alignment;
DBusString str;
int pos, dump_pos;
int n_elements;
unsigned char array1[5] = { 3, 4, 0, 1, 9 };
dbus_int32_t array4[3] = { 123, 456, 789 };
#ifdef DBUS_HAVE_INT64
dbus_int64_t array8[3] = { DBUS_INT64_CONSTANT (0x123ffffffff),
@ -1471,6 +1556,7 @@ _dbus_marshal_test (void)
DBUS_INT64_CONSTANT (0x789ffffffff) };
dbus_int64_t *v_ARRAY_INT64;
#endif
unsigned char *v_ARRAY_BYTE;
dbus_int32_t *v_ARRAY_INT32;
double *v_ARRAY_DOUBLE;
DBusString t;
@ -1553,6 +1639,9 @@ _dbus_marshal_test (void)
MARSHAL_TEST_FIXED_ARRAY (INT32, DBUS_BIG_ENDIAN, array4);
MARSHAL_TEST_FIXED_ARRAY (INT32, DBUS_LITTLE_ENDIAN, array4);
MARSHAL_TEST_FIXED_ARRAY (BYTE, DBUS_BIG_ENDIAN, array1);
MARSHAL_TEST_FIXED_ARRAY (BYTE, DBUS_LITTLE_ENDIAN, array1);
#ifdef DBUS_HAVE_INT64
MARSHAL_TEST_FIXED_ARRAY (INT64, DBUS_BIG_ENDIAN, array8);
MARSHAL_TEST_FIXED_ARRAY (INT64, DBUS_LITTLE_ENDIAN, array8);
@ -1675,16 +1764,18 @@ _dbus_marshal_test (void)
_dbus_string_get_const_data (&str)));
/* unsigned little */
_dbus_marshal_set_uint32 (&str, DBUS_LITTLE_ENDIAN,
0, 0x123456);
_dbus_marshal_set_uint32 (&str,
0, 0x123456,
DBUS_LITTLE_ENDIAN);
_dbus_assert (0x123456 ==
_dbus_unpack_uint32 (DBUS_LITTLE_ENDIAN,
_dbus_string_get_const_data (&str)));
/* unsigned big */
_dbus_marshal_set_uint32 (&str, DBUS_BIG_ENDIAN,
0, 0x123456);
_dbus_marshal_set_uint32 (&str,
0, 0x123456,
DBUS_BIG_ENDIAN);
_dbus_assert (0x123456 ==
_dbus_unpack_uint32 (DBUS_BIG_ENDIAN,

View file

@ -35,120 +35,6 @@
#error "config.h not included here"
#endif
/****************************************************** Remove later */
#undef DBUS_TYPE_INVALID
#undef DBUS_TYPE_NIL
#undef DBUS_TYPE_CUSTOM
#undef DBUS_TYPE_BYTE
#undef DBUS_TYPE_INT32
#undef DBUS_TYPE_UINT32
#undef DBUS_TYPE_INT64
#undef DBUS_TYPE_UINT64
#undef DBUS_TYPE_DOUBLE
#undef DBUS_TYPE_STRING
#undef DBUS_TYPE_OBJECT_PATH
#undef DBUS_TYPE_ARRAY
#undef DBUS_TYPE_DICT
#undef DBUS_TYPE_VARIANT
#undef DBUS_TYPE_STRUCT
#undef DBUS_NUMBER_OF_TYPES
/* Never a legitimate type */
#define DBUS_TYPE_INVALID ((int) '\0')
#define DBUS_TYPE_INVALID_AS_STRING "\0"
/* Primitive types */
#define DBUS_TYPE_BYTE ((int) 'y')
#define DBUS_TYPE_BYTE_AS_STRING "y"
#define DBUS_TYPE_BOOLEAN ((int) 'b')
#define DBUS_TYPE_BOOLEAN_AS_STRING "b"
#define DBUS_TYPE_INT32 ((int) 'i')
#define DBUS_TYPE_INT32_AS_STRING "i"
#define DBUS_TYPE_UINT32 ((int) 'u')
#define DBUS_TYPE_UINT32_AS_STRING "u"
#define DBUS_TYPE_INT64 ((int) 'x')
#define DBUS_TYPE_INT64_AS_STRING "x"
#define DBUS_TYPE_UINT64 ((int) 't')
#define DBUS_TYPE_UINT64_AS_STRING "t"
#define DBUS_TYPE_DOUBLE ((int) 'd')
#define DBUS_TYPE_DOUBLE_AS_STRING "d"
#define DBUS_TYPE_STRING ((int) 's')
#define DBUS_TYPE_STRING_AS_STRING "s"
#define DBUS_TYPE_OBJECT_PATH ((int) 'o')
#define DBUS_TYPE_OBJECT_PATH_AS_STRING "o"
#define DBUS_TYPE_SIGNATURE ((int) 'g')
#define DBUS_TYPE_SIGNATURE_AS_STRING "g"
/* Compound types */
#define DBUS_TYPE_ARRAY ((int) 'a')
#define DBUS_TYPE_ARRAY_AS_STRING "a"
#define DBUS_TYPE_VARIANT ((int) 'v')
#define DBUS_TYPE_VARIANT_AS_STRING "v"
/* STRUCT is sort of special since its code can't appear in a type string,
* instead DBUS_STRUCT_BEGIN_CHAR has to appear
*/
#define DBUS_TYPE_STRUCT ((int) 'r')
#define DBUS_TYPE_STRUCT_AS_STRING "r"
/* Does not count INVALID */
#define DBUS_NUMBER_OF_TYPES (13)
/* characters other than typecodes that appear in type signatures */
#define DBUS_STRUCT_BEGIN_CHAR ((int) '(')
#define DBUS_STRUCT_BEGIN_CHAR_AS_STRING "("
#define DBUS_STRUCT_END_CHAR ((int) ')')
#define DBUS_STRUCT_END_CHAR_AS_STRING ")"
#define DBUS_MAXIMUM_SIGNATURE_LENGTH 255
#define DBUS_MAXIMUM_ARRAY_LENGTH (67108864)
#define DBUS_MAXIMUM_ARRAY_LENGTH_BITS 26
#define DBUS_MAXIMUM_MESSAGE_LENGTH (DBUS_MAXIMUM_ARRAY_LENGTH * 2)
#define DBUS_MAXIMUM_MESSAGE_LENGTH_BITS 27
static const char *
_hack_dbus_type_to_string (int type)
{
switch (type)
{
case DBUS_TYPE_INVALID:
return "invalid";
case DBUS_TYPE_BOOLEAN:
return "boolean";
case DBUS_TYPE_INT32:
return "int32";
case DBUS_TYPE_UINT32:
return "uint32";
case DBUS_TYPE_DOUBLE:
return "double";
case DBUS_TYPE_STRING:
return "string";
case DBUS_TYPE_OBJECT_PATH:
return "object_path";
case DBUS_TYPE_SIGNATURE:
return "signature";
case DBUS_TYPE_STRUCT:
return "struct";
case DBUS_TYPE_ARRAY:
return "array";
case DBUS_TYPE_VARIANT:
return "variant";
case DBUS_STRUCT_BEGIN_CHAR:
return "begin_struct";
case DBUS_STRUCT_END_CHAR:
return "end_struct";
default:
return "unknown";
}
}
#define _dbus_type_to_string(t) _hack_dbus_type_to_string(t)
/****************************************************** Remove later */
#ifdef WORDS_BIGENDIAN
#define DBUS_COMPILER_BYTE_ORDER DBUS_BIG_ENDIAN
#else
@ -275,7 +161,7 @@ dbus_bool_t _dbus_marshal_write_basic (DBusString *str,
const void *value,
int byte_order,
int *pos_after);
dbus_bool_t _dbus_marshal_write_fixed_array (DBusString *str,
dbus_bool_t _dbus_marshal_write_fixed_multi (DBusString *str,
int insert_at,
int element_type,
const void *value,
@ -288,11 +174,11 @@ void _dbus_marshal_read_basic (const DBusString *str,
void *value,
int byte_order,
int *new_pos);
void _dbus_marshal_read_fixed_array (const DBusString *str,
void _dbus_marshal_read_fixed_multi (const DBusString *str,
int pos,
int element_type,
void *value,
int *n_elements,
int n_elements,
int byte_order,
int *new_pos);
void _dbus_marshal_skip_basic (const DBusString *str,
@ -316,7 +202,7 @@ int _dbus_type_get_alignment (int typecode);
dbus_bool_t _dbus_type_is_basic (int typecode);
dbus_bool_t _dbus_type_is_container (int typecode);
dbus_bool_t _dbus_type_is_fixed (int typecode);
const char* _dbus_type_to_string (int typecode);

1435
dbus/dbus-marshal-header.c Normal file

File diff suppressed because it is too large Load diff

128
dbus/dbus-marshal-header.h Normal file
View file

@ -0,0 +1,128 @@
/* -*- mode: C; c-file-style: "gnu" -*- */
/* dbus-marshal-header.h Managing marshaling/demarshaling of message headers
*
* Copyright (C) 2005 Red Hat, Inc.
*
* Licensed under the Academic Free License version 2.1
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef DBUS_MARSHAL_HEADER_H
#define DBUS_MARSHAL_HEADER_H
#include <config.h>
#include <dbus/dbus-marshal-basic.h>
#include <dbus/dbus-marshal-validate.h>
#ifndef PACKAGE
#error "config.h not included here"
#endif
typedef struct DBusHeader DBusHeader;
typedef struct DBusHeaderField DBusHeaderField;
#define _DBUS_HEADER_FIELD_VALUE_UNKNOWN -1
#define _DBUS_HEADER_FIELD_VALUE_NONEXISTENT -2
/**
* Cached information about a header field in the message
*/
struct DBusHeaderField
{
int value_pos; /**< Position of field value, or -1/-2 */
};
struct DBusHeader
{
DBusString data; /**< Header network data, stored
* separately from body so we can
* independently realloc it.
*/
DBusHeaderField fields[DBUS_HEADER_FIELD_LAST + 1]; /**< Track the location
* of each field in header
*/
dbus_uint32_t padding : 3; /**< bytes of alignment in header */
dbus_uint32_t byte_order : 8; /**< byte order of header */
};
dbus_bool_t _dbus_header_init (DBusHeader *header,
int byte_order);
void _dbus_header_free (DBusHeader *header);
void _dbus_header_reinit (DBusHeader *header,
int byte_order);
dbus_bool_t _dbus_header_create (DBusHeader *header,
int type,
const char *destination,
const char *path,
const char *interface,
const char *member,
const char *error_name);
dbus_bool_t _dbus_header_copy (const DBusHeader *header,
DBusHeader *dest);
int _dbus_header_get_message_type (DBusHeader *header);
void _dbus_header_set_serial (DBusHeader *header,
dbus_uint32_t serial);
dbus_uint32_t _dbus_header_get_serial (DBusHeader *header);
void _dbus_header_update_lengths (DBusHeader *header,
int body_len);
dbus_bool_t _dbus_header_set_field_basic (DBusHeader *header,
int field,
int type,
const void *value);
dbus_bool_t _dbus_header_get_field_basic (DBusHeader *header,
int field,
int type,
void *value);
dbus_bool_t _dbus_header_get_field_raw (DBusHeader *header,
int field,
const DBusString **str,
int *pos);
dbus_bool_t _dbus_header_delete_field (DBusHeader *header,
int field);
void _dbus_header_toggle_flag (DBusHeader *header,
dbus_uint32_t flag,
dbus_bool_t value);
dbus_bool_t _dbus_header_get_flag (DBusHeader *header,
dbus_uint32_t flag);
dbus_bool_t _dbus_header_ensure_signature (DBusHeader *header,
DBusString **type_str,
int *type_pos);
dbus_bool_t _dbus_header_have_message_untrusted (int max_message_length,
DBusValidity *validity,
int *byte_order,
int *fields_array_len,
int *header_len,
int *body_len,
const DBusString *str,
int start,
int len);
dbus_bool_t _dbus_header_load_untrusted (DBusHeader *header,
DBusValidity *validity,
int byte_order,
int fields_array_len,
int header_len,
int body_len,
const DBusString *str,
int start,
int len);
#endif /* DBUS_MARSHAL_HEADER_H */

File diff suppressed because it is too large Load diff

View file

@ -1,7 +1,7 @@
/* -*- mode: C; c-file-style: "gnu" -*- */
/* dbus-marshal-recursive.h Marshalling routines for recursive types
*
* Copyright (C) 2004 Red Hat, Inc.
* Copyright (C) 2004, 2005 Red Hat, Inc.
*
* Licensed under the Academic Free License version 2.1
*
@ -148,12 +148,16 @@ void _dbus_type_reader_init_types_only_from_mark (DBusTypeReader *
void _dbus_type_reader_save_mark (const DBusTypeReader *reader,
DBusTypeMark *mark);
int _dbus_type_reader_get_current_type (const DBusTypeReader *reader);
int _dbus_type_reader_get_array_type (const DBusTypeReader *reader);
int _dbus_type_reader_get_value_pos (const DBusTypeReader *reader);
dbus_bool_t _dbus_type_reader_array_is_empty (const DBusTypeReader *reader);
void _dbus_type_reader_read_basic (const DBusTypeReader *reader,
void *value);
void _dbus_type_reader_read_fixed_array (const DBusTypeReader *reader,
void _dbus_type_reader_read_fixed_multi (const DBusTypeReader *reader,
void *value,
int *n_elements);
void _dbus_type_reader_read_raw (const DBusTypeReader *reader,
const unsigned char **value_location);
void _dbus_type_reader_recurse (DBusTypeReader *reader,
DBusTypeReader *subreader);
dbus_bool_t _dbus_type_reader_next (DBusTypeReader *reader);
@ -176,6 +180,14 @@ void _dbus_type_writer_init (DBusTypeWriter *write
int type_pos,
DBusString *value_str,
int value_pos);
void _dbus_type_writer_init_types_delayed (DBusTypeWriter *writer,
int byte_order,
DBusString *value_str,
int value_pos);
void _dbus_type_writer_add_types (DBusTypeWriter *writer,
DBusString *type_str,
int type_pos);
void _dbus_type_writer_remove_types (DBusTypeWriter *writer);
void _dbus_type_writer_init_values_only (DBusTypeWriter *writer,
int byte_order,
const DBusString *type_str,
@ -185,7 +197,7 @@ void _dbus_type_writer_init_values_only (DBusTypeWriter *write
dbus_bool_t _dbus_type_writer_write_basic (DBusTypeWriter *writer,
int type,
const void *value);
dbus_bool_t _dbus_type_writer_write_fixed_array (DBusTypeWriter *writer,
dbus_bool_t _dbus_type_writer_write_fixed_multi (DBusTypeWriter *writer,
int element_type,
const void *value,
int n_elements);
@ -196,6 +208,10 @@ dbus_bool_t _dbus_type_writer_recurse (DBusTypeWriter *write
DBusTypeWriter *sub);
dbus_bool_t _dbus_type_writer_unrecurse (DBusTypeWriter *writer,
DBusTypeWriter *sub);
dbus_bool_t _dbus_type_writer_append_array (DBusTypeWriter *writer,
const DBusString *contained_type,
int contained_type_start,
DBusTypeWriter *sub);
dbus_bool_t _dbus_type_writer_write_reader (DBusTypeWriter *writer,
DBusTypeReader *reader);
dbus_bool_t _dbus_type_writer_write_reader_partial (DBusTypeWriter *writer,
@ -208,5 +224,4 @@ void _dbus_type_writer_set_enabled (DBusTypeWriter *write
dbus_bool_t enabled);
#endif /* DBUS_MARSHAL_RECURSIVE_H */

File diff suppressed because it is too large Load diff

View file

@ -31,5 +31,133 @@
#error "config.h not included here"
#endif
/**
* This is primarily used in unit testing, so we can verify that each
* invalid message is invalid for the expected reasons. Thus we really
* want a distinct enum value for every codepath leaving the validator
* functions. Enum values are specified manually for ease of debugging
* (so you can see the enum value given a printf)
*/
typedef enum
{
DBUS_VALID = 0,
DBUS_INVALID_UNKNOWN_TYPECODE = 1,
DBUS_INVALID_MISSING_ARRAY_ELEMENT_TYPE = 2,
DBUS_INVALID_SIGNATURE_TOO_LONG = 3,
DBUS_INVALID_EXCEEDED_MAXIMUM_ARRAY_RECURSION = 4,
DBUS_INVALID_EXCEEDED_MAXIMUM_STRUCT_RECURSION = 5,
DBUS_INVALID_STRUCT_ENDED_BUT_NOT_STARTED = 6,
DBUS_INVALID_STRUCT_STARTED_BUT_NOT_ENDED = 7,
DBUS_INVALID_STRUCT_HAS_NO_FIELDS = 8,
DBUS_INVALID_ALIGNMENT_PADDING_NOT_NUL = 9,
DBUS_INVALID_BOOLEAN_NOT_ZERO_OR_ONE = 10,
DBUS_INVALID_NOT_ENOUGH_DATA = 11,
DBUS_INVALID_TOO_MUCH_DATA = 12,
DBUS_INVALID_BAD_BYTE_ORDER = 13,
DBUS_INVALID_BAD_PROTOCOL_VERSION = 14,
DBUS_INVALID_BAD_MESSAGE_TYPE = 15,
DBUS_INVALID_BAD_SERIAL = 16,
DBUS_INVALID_INSANE_FIELDS_ARRAY_LENGTH = 17,
DBUS_INVALID_INSANE_BODY_LENGTH = 18,
DBUS_INVALID_MESSAGE_TOO_LONG = 19,
DBUS_INVALID_HEADER_FIELD_CODE = 20,
DBUS_INVALID_HEADER_FIELD_HAS_WRONG_TYPE = 21,
DBUS_INVALID_USES_LOCAL_INTERFACE = 22,
DBUS_INVALID_USES_LOCAL_PATH = 23,
DBUS_INVALID_HEADER_FIELD_APPEARS_TWICE = 24,
DBUS_INVALID_BAD_DESTINATION = 25,
DBUS_INVALID_BAD_INTERFACE = 26,
DBUS_INVALID_BAD_MEMBER = 27,
DBUS_INVALID_BAD_ERROR_NAME = 28,
DBUS_INVALID_BAD_SENDER = 29,
DBUS_INVALID_MISSING_PATH = 30,
DBUS_INVALID_MISSING_INTERFACE = 31,
DBUS_INVALID_MISSING_MEMBER = 32,
DBUS_INVALID_MISSING_ERROR_NAME = 33,
DBUS_INVALID_MISSING_REPLY_SERIAL = 34,
DBUS_INVALID_STRING_LENGTH_OUT_OF_BOUNDS = 35,
DBUS_INVALID_ARRAY_LENGTH_OUT_OF_BOUNDS = 36,
DBUS_INVALID_ARRAY_LENGTH_EXCEEDS_MAXIMUM = 37,
DBUS_INVALID_BAD_PATH = 38,
DBUS_INVALID_SIGNATURE_LENGTH_OUT_OF_BOUNDS = 39,
DBUS_INVALID_BAD_SIGNATURE = 40,
DBUS_INVALID_BAD_UTF8_IN_STRING = 41,
DBUS_INVALID_ARRAY_LENGTH_INCORRECT = 42,
DBUS_INVALID_VARIANT_SIGNATURE_LENGTH_OUT_OF_BOUNDS = 43,
DBUS_INVALID_VARIANT_SIGNATURE_BAD = 44,
DBUS_INVALID_VARIANT_SIGNATURE_EMPTY = 45,
DBUS_INVALID_VARIANT_SIGNATURE_SPECIFIES_MULTIPLE_VALUES = 46,
DBUS_INVALID_VARIANT_SIGNATURE_MISSING_NUL = 47,
DBUS_INVALID_STRING_MISSING_NUL = 48,
DBUS_INVALID_SIGNATURE_MISSING_NUL = 49,
} DBusValidity;
DBusValidity _dbus_validate_signature_with_reason (const DBusString *type_str,
int type_pos,
int len);
DBusValidity _dbus_validate_body_with_reason (const DBusString *expected_signature,
int expected_signature_start,
int byte_order,
int *bytes_remaining,
const DBusString *value_str,
int value_pos,
int len);
dbus_bool_t _dbus_validate_path (const DBusString *str,
int start,
int len);
dbus_bool_t _dbus_validate_interface (const DBusString *str,
int start,
int len);
dbus_bool_t _dbus_validate_member (const DBusString *str,
int start,
int len);
dbus_bool_t _dbus_validate_error_name (const DBusString *str,
int start,
int len);
dbus_bool_t _dbus_validate_service (const DBusString *str,
int start,
int len);
dbus_bool_t _dbus_validate_signature (const DBusString *str,
int start,
int len);
#ifdef DBUS_DISABLE_CHECKS
/* Be sure they don't exist, since we don't want to use them outside of checks
* and so we want the compile failure.
*/
#define DECLARE_DBUS_NAME_CHECK(what)
#define DEFINE_DBUS_NAME_CHECK(what)
#else /* !DBUS_DISABLE_CHECKS */
/* A name check is used in _dbus_return_if_fail(), it's not suitable
* for validating untrusted data. use _dbus_validate_##what for that.
*/
#define DECLARE_DBUS_NAME_CHECK(what) \
dbus_bool_t _dbus_check_is_valid_##what (const char *name)
#define DEFINE_DBUS_NAME_CHECK(what) \
dbus_bool_t \
_dbus_check_is_valid_##what (const char *name) \
{ \
DBusString str; \
\
if (name == NULL) \
return FALSE; \
\
_dbus_string_init_const (&str, name); \
return _dbus_validate_##what (&str, 0, \
_dbus_string_get_length (&str)); \
}
#endif /* !DBUS_DISABLE_CHECKS */
DECLARE_DBUS_NAME_CHECK(path);
DECLARE_DBUS_NAME_CHECK(interface);
DECLARE_DBUS_NAME_CHECK(member);
DECLARE_DBUS_NAME_CHECK(error_name);
DECLARE_DBUS_NAME_CHECK(service);
DECLARE_DBUS_NAME_CHECK(signature);
#endif /* DBUS_MARSHAL_VALIDATE_H */

File diff suppressed because it is too large Load diff

View file

@ -1,348 +0,0 @@
/* -*- mode: C; c-file-style: "gnu" -*- */
/* dbus-marshal.h Marshalling routines
*
* Copyright (C) 2002 CodeFactory AB
*
* Licensed under the Academic Free License version 2.1
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef DBUS_MARSHAL_H
#define DBUS_MARSHAL_H
#include <config.h>
#include <dbus/dbus-protocol.h>
#include <dbus/dbus-types.h>
#include <dbus/dbus-arch-deps.h>
#include <dbus/dbus-string.h>
#ifndef PACKAGE
#error "config.h not included here"
#endif
#ifdef WORDS_BIGENDIAN
#define DBUS_COMPILER_BYTE_ORDER DBUS_BIG_ENDIAN
#else
#define DBUS_COMPILER_BYTE_ORDER DBUS_LITTLE_ENDIAN
#endif
#define DBUS_UINT32_SWAP_LE_BE_CONSTANT(val) ((dbus_uint32_t) ( \
(((dbus_uint32_t) (val) & (dbus_uint32_t) 0x000000ffU) << 24) | \
(((dbus_uint32_t) (val) & (dbus_uint32_t) 0x0000ff00U) << 8) | \
(((dbus_uint32_t) (val) & (dbus_uint32_t) 0x00ff0000U) >> 8) | \
(((dbus_uint32_t) (val) & (dbus_uint32_t) 0xff000000U) >> 24)))
#ifdef DBUS_HAVE_INT64
#define DBUS_UINT64_SWAP_LE_BE_CONSTANT(val) ((dbus_uint64_t) ( \
(((dbus_uint64_t) (val) & \
(dbus_uint64_t) DBUS_UINT64_CONSTANT (0x00000000000000ff)) << 56) | \
(((dbus_uint64_t) (val) & \
(dbus_uint64_t) DBUS_UINT64_CONSTANT (0x000000000000ff00)) << 40) | \
(((dbus_uint64_t) (val) & \
(dbus_uint64_t) DBUS_UINT64_CONSTANT (0x0000000000ff0000)) << 24) | \
(((dbus_uint64_t) (val) & \
(dbus_uint64_t) DBUS_UINT64_CONSTANT (0x00000000ff000000)) << 8) | \
(((dbus_uint64_t) (val) & \
(dbus_uint64_t) DBUS_UINT64_CONSTANT (0x000000ff00000000)) >> 8) | \
(((dbus_uint64_t) (val) & \
(dbus_uint64_t) DBUS_UINT64_CONSTANT (0x0000ff0000000000)) >> 24) | \
(((dbus_uint64_t) (val) & \
(dbus_uint64_t) DBUS_UINT64_CONSTANT (0x00ff000000000000)) >> 40) | \
(((dbus_uint64_t) (val) & \
(dbus_uint64_t) DBUS_UINT64_CONSTANT (0xff00000000000000)) >> 56)))
#endif /* DBUS_HAVE_INT64 */
#define DBUS_UINT32_SWAP_LE_BE(val) (DBUS_UINT32_SWAP_LE_BE_CONSTANT (val))
#define DBUS_INT32_SWAP_LE_BE(val) ((dbus_int32_t)DBUS_UINT32_SWAP_LE_BE_CONSTANT (val))
#ifdef DBUS_HAVE_INT64
#define DBUS_UINT64_SWAP_LE_BE(val) (DBUS_UINT64_SWAP_LE_BE_CONSTANT (val))
#define DBUS_INT64_SWAP_LE_BE(val) ((dbus_int64_t)DBUS_UINT64_SWAP_LE_BE_CONSTANT (val))
#endif /* DBUS_HAVE_INT64 */
#ifdef WORDS_BIGENDIAN
#define DBUS_INT32_TO_BE(val) ((dbus_int32_t) (val))
#define DBUS_UINT32_TO_BE(val) ((dbus_uint32_t) (val))
#define DBUS_INT32_TO_LE(val) (DBUS_INT32_SWAP_LE_BE (val))
#define DBUS_UINT32_TO_LE(val) (DBUS_UINT32_SWAP_LE_BE (val))
# ifdef DBUS_HAVE_INT64
#define DBUS_INT64_TO_BE(val) ((dbus_int64_t) (val))
#define DBUS_UINT64_TO_BE(val) ((dbus_uint64_t) (val))
#define DBUS_INT64_TO_LE(val) (DBUS_INT64_SWAP_LE_BE (val))
#define DBUS_UINT64_TO_LE(val) (DBUS_UINT64_SWAP_LE_BE (val))
# endif /* DBUS_HAVE_INT64 */
#else
#define DBUS_INT32_TO_LE(val) ((dbus_int32_t) (val))
#define DBUS_UINT32_TO_LE(val) ((dbus_uint32_t) (val))
#define DBUS_INT32_TO_BE(val) ((dbus_int32_t) DBUS_UINT32_SWAP_LE_BE (val))
#define DBUS_UINT32_TO_BE(val) (DBUS_UINT32_SWAP_LE_BE (val))
# ifdef DBUS_HAVE_INT64
#define DBUS_INT64_TO_LE(val) ((dbus_int64_t) (val))
#define DBUS_UINT64_TO_LE(val) ((dbus_uint64_t) (val))
#define DBUS_INT64_TO_BE(val) ((dbus_int64_t) DBUS_UINT64_SWAP_LE_BE (val))
#define DBUS_UINT64_TO_BE(val) (DBUS_UINT64_SWAP_LE_BE (val))
# endif /* DBUS_HAVE_INT64 */
#endif
/* The transformation is symmetric, so the FROM just maps to the TO. */
#define DBUS_INT32_FROM_LE(val) (DBUS_INT32_TO_LE (val))
#define DBUS_UINT32_FROM_LE(val) (DBUS_UINT32_TO_LE (val))
#define DBUS_INT32_FROM_BE(val) (DBUS_INT32_TO_BE (val))
#define DBUS_UINT32_FROM_BE(val) (DBUS_UINT32_TO_BE (val))
#ifdef DBUS_HAVE_INT64
#define DBUS_INT64_FROM_LE(val) (DBUS_INT64_TO_LE (val))
#define DBUS_UINT64_FROM_LE(val) (DBUS_UINT64_TO_LE (val))
#define DBUS_INT64_FROM_BE(val) (DBUS_INT64_TO_BE (val))
#define DBUS_UINT64_FROM_BE(val) (DBUS_UINT64_TO_BE (val))
#endif /* DBUS_HAVE_INT64 */
void _dbus_pack_int32 (dbus_int32_t value,
int byte_order,
unsigned char *data);
dbus_int32_t _dbus_unpack_int32 (int byte_order,
const unsigned char *data);
void _dbus_pack_uint32 (dbus_uint32_t value,
int byte_order,
unsigned char *data);
dbus_uint32_t _dbus_unpack_uint32 (int byte_order,
const unsigned char *data);
#ifdef DBUS_HAVE_INT64
void _dbus_pack_int64 (dbus_int64_t value,
int byte_order,
unsigned char *data);
dbus_int64_t _dbus_unpack_int64 (int byte_order,
const unsigned char *data);
void _dbus_pack_uint64 (dbus_uint64_t value,
int byte_order,
unsigned char *data);
dbus_uint64_t _dbus_unpack_uint64 (int byte_order,
const unsigned char *data);
#endif /* DBUS_HAVE_INT64 */
void _dbus_marshal_set_int32 (DBusString *str,
int byte_order,
int offset,
dbus_int32_t value);
void _dbus_marshal_set_uint32 (DBusString *str,
int byte_order,
int offset,
dbus_uint32_t value);
#ifdef DBUS_HAVE_INT64
void _dbus_marshal_set_int64 (DBusString *str,
int byte_order,
int offset,
dbus_int64_t value);
void _dbus_marshal_set_uint64 (DBusString *str,
int byte_order,
int offset,
dbus_uint64_t value);
#endif /* DBUS_HAVE_INT64 */
dbus_bool_t _dbus_marshal_set_string (DBusString *str,
int byte_order,
int offset,
const DBusString *value,
int len);
void _dbus_marshal_set_object_path (DBusString *str,
int byte_order,
int offset,
const char **path,
int path_len);
dbus_bool_t _dbus_marshal_int32 (DBusString *str,
int byte_order,
dbus_int32_t value);
dbus_bool_t _dbus_marshal_uint32 (DBusString *str,
int byte_order,
dbus_uint32_t value);
#ifdef DBUS_HAVE_INT64
dbus_bool_t _dbus_marshal_int64 (DBusString *str,
int byte_order,
dbus_int64_t value);
dbus_bool_t _dbus_marshal_uint64 (DBusString *str,
int byte_order,
dbus_uint64_t value);
#endif /* DBUS_HAVE_INT64 */
dbus_bool_t _dbus_marshal_double (DBusString *str,
int byte_order,
double value);
dbus_bool_t _dbus_marshal_string (DBusString *str,
int byte_order,
const char *value);
dbus_bool_t _dbus_marshal_string_len (DBusString *str,
int byte_order,
const char *value,
int len);
dbus_bool_t _dbus_marshal_basic_type (DBusString *str,
char type,
void *value,
int byte_order);
dbus_bool_t _dbus_marshal_byte_array (DBusString *str,
int byte_order,
const unsigned char *value,
int len);
dbus_bool_t _dbus_marshal_int32_array (DBusString *str,
int byte_order,
const dbus_int32_t *value,
int len);
dbus_bool_t _dbus_marshal_uint32_array (DBusString *str,
int byte_order,
const dbus_uint32_t *value,
int len);
#ifdef DBUS_HAVE_INT64
dbus_bool_t _dbus_marshal_int64_array (DBusString *str,
int byte_order,
const dbus_int64_t *value,
int len);
dbus_bool_t _dbus_marshal_uint64_array (DBusString *str,
int byte_order,
const dbus_uint64_t *value,
int len);
#endif /* DBUS_HAVE_INT64 */
dbus_bool_t _dbus_marshal_double_array (DBusString *str,
int byte_order,
const double *value,
int len);
dbus_bool_t _dbus_marshal_basic_type_array (DBusString *str,
char element_type,
const void *value,
int len,
int byte_order);
dbus_bool_t _dbus_marshal_string_array (DBusString *str,
int byte_order,
const char **value,
int len);
dbus_bool_t _dbus_marshal_object_path (DBusString *str,
int byte_order,
const char **path,
int path_len);
double _dbus_demarshal_double (const DBusString *str,
int byte_order,
int pos,
int *new_pos);
dbus_int32_t _dbus_demarshal_int32 (const DBusString *str,
int byte_order,
int pos,
int *new_pos);
dbus_uint32_t _dbus_demarshal_uint32 (const DBusString *str,
int byte_order,
int pos,
int *new_pos);
#ifdef DBUS_HAVE_INT64
dbus_int64_t _dbus_demarshal_int64 (const DBusString *str,
int byte_order,
int pos,
int *new_pos);
dbus_uint64_t _dbus_demarshal_uint64 (const DBusString *str,
int byte_order,
int pos,
int *new_pos);
#endif /* DBUS_HAVE_INT64 */
void _dbus_demarshal_basic_type (const DBusString *str,
int type,
void *value,
int byte_order,
int *pos);
char * _dbus_demarshal_string (const DBusString *str,
int byte_order,
int pos,
int *new_pos);
dbus_bool_t _dbus_demarshal_byte_array (const DBusString *str,
int byte_order,
int pos,
int *new_pos,
unsigned char **array,
int *array_len);
dbus_bool_t _dbus_demarshal_int32_array (const DBusString *str,
int byte_order,
int pos,
int *new_pos,
dbus_int32_t **array,
int *array_len);
dbus_bool_t _dbus_demarshal_uint32_array (const DBusString *str,
int byte_order,
int pos,
int *new_pos,
dbus_uint32_t **array,
int *array_len);
#ifdef DBUS_HAVE_INT64
dbus_bool_t _dbus_demarshal_int64_array (const DBusString *str,
int byte_order,
int pos,
int *new_pos,
dbus_int64_t **array,
int *array_len);
dbus_bool_t _dbus_demarshal_uint64_array (const DBusString *str,
int byte_order,
int pos,
int *new_pos,
dbus_uint64_t **array,
int *array_len);
#endif /* DBUS_HAVE_INT64 */
dbus_bool_t _dbus_demarshal_double_array (const DBusString *str,
int byte_order,
int pos,
int *new_pos,
double **array,
int *array_len);
dbus_bool_t _dbus_demarshal_basic_type_array (const DBusString *str,
int type,
void **array,
int *array_len,
int byte_order,
int *pos);
dbus_bool_t _dbus_demarshal_string_array (const DBusString *str,
int byte_order,
int pos,
int *new_pos,
char ***array,
int *array_len);
dbus_bool_t _dbus_decompose_path (const char* data,
int len,
char ***path,
int *path_len);
dbus_bool_t _dbus_demarshal_object_path (const DBusString *str,
int byte_order,
int pos,
int *new_pos,
char ***path,
int *path_len);
dbus_bool_t _dbus_marshal_get_arg_end_pos (const DBusString *str,
int byte_order,
int type,
int pos,
int *end_pos);
dbus_bool_t _dbus_marshal_validate_type (const DBusString *str,
int pos,
int *type,
int *end_pos);
dbus_bool_t _dbus_marshal_validate_arg (const DBusString *str,
int depth,
int byte_order,
int type,
int array_type_pos,
int pos,
int *end_pos);
dbus_bool_t _dbus_type_is_valid (int typecode);
#endif /* DBUS_MARSHAL_H */

View file

@ -317,7 +317,8 @@ source_string (BlockSource source)
}
static void
check_guards (void *free_block)
check_guards (void *free_block,
dbus_bool_t overwrite)
{
if (free_block != NULL)
{
@ -364,6 +365,10 @@ check_guards (void *free_block)
i += 4;
}
/* set memory to anything but nul bytes */
if (overwrite)
memset (free_block, 'g', requested_bytes);
if (failed)
_dbus_assert_not_reached ("guard value corruption");
}
@ -401,7 +406,7 @@ set_guards (void *real_block,
i += 4;
}
check_guards (block + GUARD_START_OFFSET);
check_guards (block + GUARD_START_OFFSET, FALSE);
return block + GUARD_START_OFFSET;
}
@ -558,7 +563,7 @@ dbus_realloc (void *memory,
size_t old_bytes;
void *block;
check_guards (memory);
check_guards (memory, FALSE);
block = realloc (((unsigned char*)memory) - GUARD_START_OFFSET,
bytes + GUARD_EXTRA_SIZE);
@ -566,7 +571,7 @@ dbus_realloc (void *memory,
old_bytes = *(dbus_uint32_t*)block;
if (block && bytes >= old_bytes)
/* old guards shouldn't have moved */
check_guards (((unsigned char*)block) + GUARD_START_OFFSET);
check_guards (((unsigned char*)block) + GUARD_START_OFFSET, FALSE);
return set_guards (block, bytes, SOURCE_REALLOC);
}
@ -607,7 +612,7 @@ dbus_free (void *memory)
#ifdef DBUS_BUILD_TESTS
if (guards)
{
check_guards (memory);
check_guards (memory, TRUE);
if (memory)
{
n_blocks_outstanding -= 1;

View file

@ -1051,9 +1051,10 @@ _dbus_message_data_load (DBusString *dest,
goto parse_failed;
}
_dbus_marshal_set_uint32 (dest, endian, size_offset,
_dbus_marshal_set_uint32 (dest, size_offset,
/* subtract 1 for nul */
_dbus_string_get_length (dest) - old_len - 1);
_dbus_string_get_length (dest) - old_len - 1,
endian);
PERFORM_UNALIGN (dest);
}
@ -1094,9 +1095,10 @@ _dbus_message_data_load (DBusString *dest,
goto parse_failed;
}
_dbus_marshal_set_uint32 (dest, endian, size_offset,
_dbus_marshal_set_uint32 (dest, size_offset,
/* subtract 1 for nul */
_dbus_string_get_length (dest) - old_len - 1);
_dbus_string_get_length (dest) - old_len - 1,
endian);
PERFORM_UNALIGN (dest);
}

View file

@ -38,7 +38,7 @@ void _dbus_message_get_network_data (DBusMessage *message,
void _dbus_message_lock (DBusMessage *message);
void _dbus_message_unlock (DBusMessage *message);
void _dbus_message_set_serial (DBusMessage *message,
dbus_int32_t serial);
dbus_uint32_t serial);
dbus_bool_t _dbus_message_add_size_counter (DBusMessage *message,
DBusCounter *counter);
void _dbus_message_add_size_counter_link (DBusMessage *message,

File diff suppressed because it is too large Load diff

View file

@ -144,14 +144,6 @@ dbus_bool_t dbus_message_get_args_valist (DBusMessage *message,
DBusError *error,
int first_arg_type,
va_list var_args);
dbus_bool_t dbus_message_iter_get_args (DBusMessageIter *iter,
DBusError *error,
int first_arg_type,
...);
dbus_bool_t dbus_message_iter_get_args_valist (DBusMessageIter *iter,
DBusError *error,
int first_arg_type,
va_list var_args);
dbus_bool_t dbus_message_iter_init (DBusMessage *message,
@ -160,125 +152,29 @@ dbus_bool_t dbus_message_iter_has_next (DBusMessageIter *iter
dbus_bool_t dbus_message_iter_next (DBusMessageIter *iter);
int dbus_message_iter_get_arg_type (DBusMessageIter *iter);
int dbus_message_iter_get_array_type (DBusMessageIter *iter);
unsigned char dbus_message_iter_get_byte (DBusMessageIter *iter);
dbus_bool_t dbus_message_iter_get_boolean (DBusMessageIter *iter);
dbus_int32_t dbus_message_iter_get_int32 (DBusMessageIter *iter);
dbus_uint32_t dbus_message_iter_get_uint32 (DBusMessageIter *iter);
#ifdef DBUS_HAVE_INT64
dbus_int64_t dbus_message_iter_get_int64 (DBusMessageIter *iter);
dbus_uint64_t dbus_message_iter_get_uint64 (DBusMessageIter *iter);
#endif /* DBUS_HAVE_INT64 */
double dbus_message_iter_get_double (DBusMessageIter *iter);
char * dbus_message_iter_get_string (DBusMessageIter *iter);
char * dbus_message_iter_get_object_path (DBusMessageIter *iter);
char * dbus_message_iter_get_dict_key (DBusMessageIter *iter);
dbus_bool_t dbus_message_iter_get_custom (DBusMessageIter *iter,
char **name,
unsigned char **value,
int *len);
dbus_bool_t dbus_message_iter_init_array_iterator (DBusMessageIter *iter,
DBusMessageIter *array_iter,
int *array_type);
dbus_bool_t dbus_message_iter_init_dict_iterator (DBusMessageIter *iter,
DBusMessageIter *dict_iter);
dbus_bool_t dbus_message_iter_get_byte_array (DBusMessageIter *iter,
unsigned char **value,
int *len);
dbus_bool_t dbus_message_iter_get_boolean_array (DBusMessageIter *iter,
unsigned char **value,
int *len);
dbus_bool_t dbus_message_iter_get_int32_array (DBusMessageIter *iter,
dbus_int32_t **value,
int *len);
dbus_bool_t dbus_message_iter_get_uint32_array (DBusMessageIter *iter,
dbus_uint32_t **value,
int *len);
#ifdef DBUS_HAVE_INT64
dbus_bool_t dbus_message_iter_get_int64_array (DBusMessageIter *iter,
dbus_int64_t **value,
int *len);
dbus_bool_t dbus_message_iter_get_uint64_array (DBusMessageIter *iter,
dbus_uint64_t **value,
int *len);
#endif /* DBUS_HAVE_INT64 */
dbus_bool_t dbus_message_iter_get_double_array (DBusMessageIter *iter,
double **value,
int *len);
dbus_bool_t dbus_message_iter_get_string_array (DBusMessageIter *iter,
char ***value,
int *len);
dbus_bool_t dbus_message_iter_get_object_path_array (DBusMessageIter *iter,
char ***value,
int *len);
void dbus_message_append_iter_init (DBusMessage *message,
DBusMessageIter *iter);
dbus_bool_t dbus_message_iter_append_nil (DBusMessageIter *iter);
dbus_bool_t dbus_message_iter_append_boolean (DBusMessageIter *iter,
dbus_bool_t value);
dbus_bool_t dbus_message_iter_append_byte (DBusMessageIter *iter,
unsigned char value);
dbus_bool_t dbus_message_iter_append_int32 (DBusMessageIter *iter,
dbus_int32_t value);
dbus_bool_t dbus_message_iter_append_uint32 (DBusMessageIter *iter,
dbus_uint32_t value);
#ifdef DBUS_HAVE_INT64
dbus_bool_t dbus_message_iter_append_int64 (DBusMessageIter *iter,
dbus_int64_t value);
dbus_bool_t dbus_message_iter_append_uint64 (DBusMessageIter *iter,
dbus_uint64_t value);
#endif /* DBUS_HAVE_INT64 */
dbus_bool_t dbus_message_iter_append_double (DBusMessageIter *iter,
double value);
dbus_bool_t dbus_message_iter_append_string (DBusMessageIter *iter,
const char *value);
dbus_bool_t dbus_message_iter_append_object_path (DBusMessageIter *iter,
const char *value);
dbus_bool_t dbus_message_iter_append_custom (DBusMessageIter *iter,
const char *name,
const unsigned char *data,
int len);
dbus_bool_t dbus_message_iter_append_dict_key (DBusMessageIter *iter,
const char *value);
dbus_bool_t dbus_message_iter_append_array (DBusMessageIter *iter,
DBusMessageIter *array_iter,
int element_type);
dbus_bool_t dbus_message_iter_append_dict (DBusMessageIter *iter,
DBusMessageIter *dict_iter);
/* Helpers for normal types: */
dbus_bool_t dbus_message_iter_append_boolean_array (DBusMessageIter *iter,
unsigned const char *value,
int len);
dbus_bool_t dbus_message_iter_append_int32_array (DBusMessageIter *iter,
const dbus_int32_t *value,
int len);
dbus_bool_t dbus_message_iter_append_uint32_array (DBusMessageIter *iter,
const dbus_uint32_t *value,
int len);
#ifdef DBUS_HAVE_INT64
dbus_bool_t dbus_message_iter_append_int64_array (DBusMessageIter *iter,
const dbus_int64_t *value,
int len);
dbus_bool_t dbus_message_iter_append_uint64_array (DBusMessageIter *iter,
const dbus_uint64_t *value,
int len);
#endif /* DBUS_HAVE_INT64 */
dbus_bool_t dbus_message_iter_append_double_array (DBusMessageIter *iter,
const double *value,
int len);
dbus_bool_t dbus_message_iter_append_byte_array (DBusMessageIter *iter,
unsigned const char *value,
int len);
dbus_bool_t dbus_message_iter_append_string_array (DBusMessageIter *iter,
const char **value,
int len);
dbus_bool_t dbus_message_iter_append_object_path_array (DBusMessageIter *iter,
const char **value,
int len);
void dbus_message_iter_recurse (DBusMessageIter *iter,
DBusMessageIter *sub);
void dbus_message_iter_get_basic (DBusMessageIter *iter,
void *value);
void dbus_message_iter_get_fixed_array (DBusMessageIter *iter,
void *value,
int *n_elements);
void dbus_message_append_iter_init (DBusMessage *message,
DBusMessageIter *iter);
dbus_bool_t dbus_message_iter_append_basic (DBusMessageIter *iter,
int type,
const void *value);
dbus_bool_t dbus_message_iter_append_fixed_array (DBusMessageIter *iter,
int element_type,
const void *value,
int n_elements);
dbus_bool_t dbus_message_iter_open_container (DBusMessageIter *iter,
int type,
const char *contained_signature,
DBusMessageIter *sub);
dbus_bool_t dbus_message_iter_close_container (DBusMessageIter *iter,
DBusMessageIter *sub);
dbus_bool_t dbus_set_error_from_message (DBusError *error,

View file

@ -937,7 +937,96 @@ _dbus_object_tree_list_registered_and_unlock (DBusObjectTree *tree,
return result;
}
/** Set to 1 to get a bunch of spew about disassembling the path string */
#define VERBOSE_DECOMPOSE 0
/**
* Decompose an object path. A path of just "/" is
* represented as an empty vector of strings.
*
* @param data the path data
* @param len the length of the path string
* @param path address to store new object path
* @param path_len length of stored path
*/
dbus_bool_t
_dbus_decompose_path (const char* data,
int len,
char ***path,
int *path_len)
{
char **retval;
int n_components;
int i, j, comp;
_dbus_assert (data != NULL);
#if VERBOSE_DECOMPOSE
_dbus_verbose ("Decomposing path \"%s\"\n",
data);
#endif
n_components = 0;
i = 0;
while (i < len)
{
if (data[i] == '/')
n_components += 1;
++i;
}
retval = dbus_new0 (char*, n_components + 1);
if (retval == NULL)
return FALSE;
comp = 0;
i = 0;
while (i < len)
{
if (data[i] == '/')
++i;
j = i;
while (j < len && data[j] != '/')
++j;
/* Now [i, j) is the path component */
_dbus_assert (i < j);
_dbus_assert (data[i] != '/');
_dbus_assert (j == len || data[j] == '/');
#if VERBOSE_DECOMPOSE
_dbus_verbose (" (component in [%d,%d))\n",
i, j);
#endif
retval[comp] = _dbus_memdup (&data[i], j - i + 1);
if (retval[comp] == NULL)
{
dbus_free_string_array (retval);
return FALSE;
}
retval[comp][j-i] = '\0';
#if VERBOSE_DECOMPOSE
_dbus_verbose (" (component %d = \"%s\")\n",
comp, retval[comp]);
#endif
++comp;
i = j;
}
_dbus_assert (i == len);
*path = retval;
if (path_len)
*path_len = n_components;
return TRUE;
}
/** @} */
#ifdef DBUS_BUILD_TESTS

View file

@ -47,6 +47,12 @@ void _dbus_object_tree_free_all_unlocked (DBusObjectTree
dbus_bool_t _dbus_object_tree_list_registered_and_unlock (DBusObjectTree *tree,
const char **parent_path,
char ***child_entries);
dbus_bool_t _dbus_decompose_path (const char *data,
int len,
char ***path,
int *path_len);
DBUS_END_DECLS
#endif /* DBUS_OBJECT_TREE_H */

View file

@ -1,226 +0,0 @@
/* -*- mode: C; c-file-style: "gnu" -*- */
/* dbus-protocol.h D-Bus protocol constants
*
* Copyright (C) 2002, 2003 CodeFactory AB
* Copyright (C) 2004 Red Hat, Inc.
*
* Licensed under the Academic Free License version 2.1
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef DBUS_PROTOCOL_H
#define DBUS_PROTOCOL_H
/* Don't include anything in here from anywhere else. It's
* intended for use by any random library.
*/
#ifdef __cplusplus
extern "C" {
#endif
/* Message byte order */
#define DBUS_LITTLE_ENDIAN ('l') /* LSB first */
#define DBUS_BIG_ENDIAN ('B') /* MSB first */
/* Protocol version */
#define DBUS_MAJOR_PROTOCOL_VERSION 1
/* Never a legitimate type */
#define DBUS_TYPE_INVALID ((int) '\0')
#define DBUS_TYPE_INVALID_AS_STRING "\0"
/* Primitive types */
#define DBUS_TYPE_BYTE ((int) 'y')
#define DBUS_TYPE_BYTE_AS_STRING "y"
#define DBUS_TYPE_BOOLEAN ((int) 'b')
#define DBUS_TYPE_BOOLEAN_AS_STRING "b"
#define DBUS_TYPE_INT32 ((int) 'i')
#define DBUS_TYPE_INT32_AS_STRING "i"
#define DBUS_TYPE_UINT32 ((int) 'u')
#define DBUS_TYPE_UINT32_AS_STRING "u"
#define DBUS_TYPE_INT64 ((int) 'x')
#define DBUS_TYPE_INT64_AS_STRING "x"
#define DBUS_TYPE_UINT64 ((int) 't')
#define DBUS_TYPE_UINT64_AS_STRING "t"
#define DBUS_TYPE_DOUBLE ((int) 'd')
#define DBUS_TYPE_DOUBLE_AS_STRING "d"
#define DBUS_TYPE_STRING ((int) 's')
#define DBUS_TYPE_STRING_AS_STRING "s"
#define DBUS_TYPE_OBJECT_PATH ((int) 'o')
#define DBUS_TYPE_OBJECT_PATH_AS_STRING "o"
#define DBUS_TYPE_SIGNATURE ((int) 'g')
#define DBUS_TYPE_SIGNATURE_AS_STRING "g"
/* Compound types */
#define DBUS_TYPE_ARRAY ((int) 'a')
#define DBUS_TYPE_ARRAY_AS_STRING "a"
#define DBUS_TYPE_VARIANT ((int) 'v')
#define DBUS_TYPE_VARIANT_AS_STRING "v"
/* STRUCT is sort of special since its code can't appear in a type string,
* instead DBUS_STRUCT_BEGIN_CHAR has to appear
*/
#define DBUS_TYPE_STRUCT ((int) 'r')
#define DBUS_TYPE_STRUCT_AS_STRING "r"
/* Does not count INVALID */
#define DBUS_NUMBER_OF_TYPES (13)
/* characters other than typecodes that appear in type signatures */
#define DBUS_STRUCT_BEGIN_CHAR ((int) '(')
#define DBUS_STRUCT_BEGIN_CHAR_AS_STRING "("
#define DBUS_STRUCT_END_CHAR ((int) ')')
#define DBUS_STRUCT_END_CHAR_AS_STRING ")"
/* Max length in bytes of a service or interface or member name (not
* object path, paths are unlimited). This is limited because lots of
* stuff is O(n) in this number, plus it would be obnoxious to type in
* a paragraph-long method name so most likely something like that
* would be an exploit.
*/
#define DBUS_MAXIMUM_NAME_LENGTH 255
/* This one is 255 so it fits in a byte */
#define DBUS_MAXIMUM_SIGNATURE_LENGTH 255
/* Max length of a match rule string; to keep people from hosing the
* daemon with some huge rule
*/
#define DBUS_MAXIMUM_MATCH_RULE_LENGTH 1024
/* Max length of a marshaled array in bytes (64M, 2^26) We use signed
* int for lengths so must be INT_MAX or less. We need something a
* bit smaller than INT_MAX because the array is inside a message with
* header info, etc. so an INT_MAX array wouldn't allow the message
* overhead. The 64M number is an attempt at a larger number than
* we'd reasonably ever use, but small enough that your bus would chew
* through it fairly quickly without locking up forever. If you have
* data that's likely to be larger than this, you should probably be
* sending it in multiple incremental messages anyhow.
*/
#define DBUS_MAXIMUM_ARRAY_LENGTH (67108864)
/* Number of bits you need in an unsigned to store the max array size */
#define DBUS_MAXIMUM_ARRAY_LENGTH_BITS 26
/* The maximum total message size including header and body; similar
* rationale to max array size.
*/
#define DBUS_MAXIMUM_MESSAGE_LENGTH (DBUS_MAXIMUM_ARRAY_LENGTH * 2)
/* Number of bits you need in an unsigned to store the max message size */
#define DBUS_MAXIMUM_MESSAGE_LENGTH_BITS 27
/* Types of message */
#define DBUS_MESSAGE_TYPE_INVALID 0
#define DBUS_MESSAGE_TYPE_METHOD_CALL 1
#define DBUS_MESSAGE_TYPE_METHOD_RETURN 2
#define DBUS_MESSAGE_TYPE_ERROR 3
#define DBUS_MESSAGE_TYPE_SIGNAL 4
/* Header flags */
#define DBUS_HEADER_FLAG_NO_REPLY_EXPECTED 0x1
#define DBUS_HEADER_FLAG_AUTO_ACTIVATION 0x2
/* Header fields */
#define DBUS_HEADER_FIELD_INVALID 0
#define DBUS_HEADER_FIELD_PATH 1
#define DBUS_HEADER_FIELD_INTERFACE 2
#define DBUS_HEADER_FIELD_MEMBER 3
#define DBUS_HEADER_FIELD_ERROR_NAME 4
#define DBUS_HEADER_FIELD_REPLY_SERIAL 5
#define DBUS_HEADER_FIELD_DESTINATION 6
#define DBUS_HEADER_FIELD_SENDER 7
#define DBUS_HEADER_FIELD_SIGNATURE 8
#define DBUS_HEADER_FIELD_LAST DBUS_HEADER_FIELD_SIGNATURE
/* Services */
#define DBUS_SERVICE_ORG_FREEDESKTOP_DBUS "org.freedesktop.DBus"
/* Paths */
#define DBUS_PATH_ORG_FREEDESKTOP_DBUS "/org/freedesktop/DBus"
#define DBUS_PATH_ORG_FREEDESKTOP_LOCAL "/org/freedesktop/Local"
/* Interfaces, these #define don't do much other than
* catch typos at compile time
*/
#define DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS "org.freedesktop.DBus"
#define DBUS_INTERFACE_ORG_FREEDESKTOP_INTROSPECTABLE "org.freedesktop.Introspectable"
/* This is a special interface whose methods can only be invoked
* by the local implementation (messages from remote apps aren't
* allowed to specify this interface).
*/
#define DBUS_INTERFACE_ORG_FREEDESKTOP_LOCAL "org.freedesktop.Local"
/* Service owner flags */
#define DBUS_SERVICE_FLAG_PROHIBIT_REPLACEMENT 0x1
#define DBUS_SERVICE_FLAG_REPLACE_EXISTING 0x2
/* Service replies */
#define DBUS_SERVICE_REPLY_PRIMARY_OWNER 0x1
#define DBUS_SERVICE_REPLY_IN_QUEUE 0x2
#define DBUS_SERVICE_REPLY_SERVICE_EXISTS 0x4
#define DBUS_SERVICE_REPLY_ALREADY_OWNER 0x8
/* Activation replies */
#define DBUS_ACTIVATION_REPLY_ACTIVATED 0x0
#define DBUS_ACTIVATION_REPLY_ALREADY_ACTIVE 0x1
/* Errors */
/* WARNING these get autoconverted to an enum in dbus-glib.h. Thus,
* if you change the order it breaks the ABI. Keep them in order.
* Also, don't change the formatting since that will break the sed
* script.
*/
#define DBUS_ERROR_FAILED "org.freedesktop.DBus.Error.Failed"
#define DBUS_ERROR_NO_MEMORY "org.freedesktop.DBus.Error.NoMemory"
#define DBUS_ERROR_ACTIVATE_SERVICE_NOT_FOUND "org.freedesktop.DBus.Error.ServiceNotFound"
#define DBUS_ERROR_SERVICE_DOES_NOT_EXIST "org.freedesktop.DBus.Error.ServiceDoesNotExist"
#define DBUS_ERROR_SERVICE_HAS_NO_OWNER "org.freedesktop.DBus.Error.ServiceHasNoOwner"
#define DBUS_ERROR_NO_REPLY "org.freedesktop.DBus.Error.NoReply"
#define DBUS_ERROR_IO_ERROR "org.freedesktop.DBus.Error.IOError"
#define DBUS_ERROR_BAD_ADDRESS "org.freedesktop.DBus.Error.BadAddress"
#define DBUS_ERROR_NOT_SUPPORTED "org.freedesktop.DBus.Error.NotSupported"
#define DBUS_ERROR_LIMITS_EXCEEDED "org.freedesktop.DBus.Error.LimitsExceeded"
#define DBUS_ERROR_ACCESS_DENIED "org.freedesktop.DBus.Error.AccessDenied"
#define DBUS_ERROR_AUTH_FAILED "org.freedesktop.DBus.Error.AuthFailed"
#define DBUS_ERROR_NO_SERVER "org.freedesktop.DBus.Error.NoServer"
#define DBUS_ERROR_TIMEOUT "org.freedesktop.DBus.Error.Timeout"
#define DBUS_ERROR_NO_NETWORK "org.freedesktop.DBus.Error.NoNetwork"
#define DBUS_ERROR_ADDRESS_IN_USE "org.freedesktop.DBus.Error.AddressInUse"
#define DBUS_ERROR_DISCONNECTED "org.freedesktop.DBus.Error.Disconnected"
#define DBUS_ERROR_INVALID_ARGS "org.freedesktop.DBus.Error.InvalidArgs"
#define DBUS_ERROR_FILE_NOT_FOUND "org.freedesktop.DBus.Error.FileNotFound"
#define DBUS_ERROR_UNKNOWN_METHOD "org.freedesktop.DBus.Error.UnknownMethod"
#define DBUS_ERROR_TIMED_OUT "org.freedesktop.DBus.Error.TimedOut"
#define DBUS_ERROR_MATCH_RULE_NOT_FOUND "org.freedesktop.DBus.Error.MatchRuleNotFound"
#define DBUS_ERROR_MATCH_RULE_INVALID "org.freedesktop.DBus.Error.MatchRuleInvalid"
#define DBUS_ERROR_SPAWN_EXEC_FAILED "org.freedesktop.DBus.Error.Spawn.ExecFailed"
#define DBUS_ERROR_SPAWN_FORK_FAILED "org.freedesktop.DBus.Error.Spawn.ForkFailed"
#define DBUS_ERROR_SPAWN_CHILD_EXITED "org.freedesktop.DBus.Error.Spawn.ChildExited"
#define DBUS_ERROR_SPAWN_CHILD_SIGNALED "org.freedesktop.DBus.Error.Spawn.ChildSignaled"
#define DBUS_ERROR_SPAWN_FAILED "org.freedesktop.DBus.Error.Spawn.Failed"
#define DBUS_ERROR_UNIX_PROCESS_ID_UNKNOWN "org.freedesktop.DBus.Error.UnixProcessIdUnknown"
#ifdef __cplusplus
}
#endif
#endif /* DBUS_PROTOCOL_H */

View file

@ -2,9 +2,10 @@
/* dbus-protocol.h D-Bus protocol constants
*
* Copyright (C) 2002, 2003 CodeFactory AB
* Copyright (C) 2004, 2005 Red Hat, Inc.
*
* Licensed under the Academic Free License version 2.1
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
@ -14,7 +15,7 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
@ -34,46 +35,115 @@ extern "C" {
/* Message byte order */
#define DBUS_LITTLE_ENDIAN ('l') /* LSB first */
#define DBUS_BIG_ENDIAN ('B') /* MSB first */
#define DBUS_BIG_ENDIAN ('B') /* MSB first */
/* Protocol version */
#define DBUS_MAJOR_PROTOCOL_VERSION 0
#define DBUS_MAJOR_PROTOCOL_VERSION 1
/* Data types */
/* Never a legitimate type */
#define DBUS_TYPE_INVALID ((int) '\0')
#define DBUS_TYPE_NIL ((int) 'v')
#define DBUS_TYPE_BYTE ((int) 'y')
#define DBUS_TYPE_BOOLEAN ((int) 'b')
#define DBUS_TYPE_INT32 ((int) 'i')
#define DBUS_TYPE_UINT32 ((int) 'u')
#define DBUS_TYPE_INT64 ((int) 'x')
#define DBUS_TYPE_UINT64 ((int) 't')
#define DBUS_TYPE_DOUBLE ((int) 'd')
#define DBUS_TYPE_STRING ((int) 's')
#define DBUS_TYPE_CUSTOM ((int) 'c')
#define DBUS_TYPE_ARRAY ((int) 'a')
#define DBUS_TYPE_DICT ((int) 'm')
#define DBUS_TYPE_OBJECT_PATH ((int) 'o')
#define DBUS_TYPE_INVALID_AS_STRING "\0"
/* Primitive types */
#define DBUS_TYPE_BYTE ((int) 'y')
#define DBUS_TYPE_BYTE_AS_STRING "y"
#define DBUS_TYPE_BOOLEAN ((int) 'b')
#define DBUS_TYPE_BOOLEAN_AS_STRING "b"
#define DBUS_TYPE_INT32 ((int) 'i')
#define DBUS_TYPE_INT32_AS_STRING "i"
#define DBUS_TYPE_UINT32 ((int) 'u')
#define DBUS_TYPE_UINT32_AS_STRING "u"
#define DBUS_TYPE_INT64 ((int) 'x')
#define DBUS_TYPE_INT64_AS_STRING "x"
#define DBUS_TYPE_UINT64 ((int) 't')
#define DBUS_TYPE_UINT64_AS_STRING "t"
#define DBUS_TYPE_DOUBLE ((int) 'd')
#define DBUS_TYPE_DOUBLE_AS_STRING "d"
#define DBUS_TYPE_STRING ((int) 's')
#define DBUS_TYPE_STRING_AS_STRING "s"
#define DBUS_TYPE_OBJECT_PATH ((int) 'o')
#define DBUS_TYPE_OBJECT_PATH_AS_STRING "o"
#define DBUS_TYPE_SIGNATURE ((int) 'g')
#define DBUS_TYPE_SIGNATURE_AS_STRING "g"
/* Compound types */
#define DBUS_TYPE_ARRAY ((int) 'a')
#define DBUS_TYPE_ARRAY_AS_STRING "a"
#define DBUS_TYPE_VARIANT ((int) 'v')
#define DBUS_TYPE_VARIANT_AS_STRING "v"
/* STRUCT is sort of special since its code can't appear in a type string,
* instead DBUS_STRUCT_BEGIN_CHAR has to appear
*/
#define DBUS_TYPE_STRUCT ((int) 'r')
#define DBUS_TYPE_STRUCT_AS_STRING "r"
/* Does not count INVALID */
#define DBUS_NUMBER_OF_TYPES (13)
/* Max length in bytes of a service or interface or member name */
#define DBUS_MAXIMUM_NAME_LENGTH 256
/* characters other than typecodes that appear in type signatures */
#define DBUS_STRUCT_BEGIN_CHAR ((int) '(')
#define DBUS_STRUCT_BEGIN_CHAR_AS_STRING "("
#define DBUS_STRUCT_END_CHAR ((int) ')')
#define DBUS_STRUCT_END_CHAR_AS_STRING ")"
/* Max length of a match rule string */
/* Max length in bytes of a service or interface or member name (not
* object path, paths are unlimited). This is limited because lots of
* stuff is O(n) in this number, plus it would be obnoxious to type in
* a paragraph-long method name so most likely something like that
* would be an exploit.
*/
#define DBUS_MAXIMUM_NAME_LENGTH 255
/* This one is 255 so it fits in a byte */
#define DBUS_MAXIMUM_SIGNATURE_LENGTH 255
/* Max length of a match rule string; to keep people from hosing the
* daemon with some huge rule
*/
#define DBUS_MAXIMUM_MATCH_RULE_LENGTH 1024
/* Max length of a marshaled array in bytes (64M, 2^26) We use signed
* int for lengths so must be INT_MAX or less. We need something a
* bit smaller than INT_MAX because the array is inside a message with
* header info, etc. so an INT_MAX array wouldn't allow the message
* overhead. The 64M number is an attempt at a larger number than
* we'd reasonably ever use, but small enough that your bus would chew
* through it fairly quickly without locking up forever. If you have
* data that's likely to be larger than this, you should probably be
* sending it in multiple incremental messages anyhow.
*/
#define DBUS_MAXIMUM_ARRAY_LENGTH (67108864)
/* Number of bits you need in an unsigned to store the max array size */
#define DBUS_MAXIMUM_ARRAY_LENGTH_BITS 26
/* The maximum total message size including header and body; similar
* rationale to max array size.
*/
#define DBUS_MAXIMUM_MESSAGE_LENGTH (DBUS_MAXIMUM_ARRAY_LENGTH * 2)
/* Number of bits you need in an unsigned to store the max message size */
#define DBUS_MAXIMUM_MESSAGE_LENGTH_BITS 27
/* Depth of recursion in the type tree. This is automatically limited
* to DBUS_MAXIMUM_SIGNATURE_LENGTH since you could only have an array
* of array of array of ... that fit in the max signature. But that's
* probably a bit too large.
*/
#define DBUS_MAXIMUM_TYPE_RECURSION_DEPTH 32
/* Types of message */
#define DBUS_MESSAGE_TYPE_INVALID 0
#define DBUS_MESSAGE_TYPE_METHOD_CALL 1
#define DBUS_MESSAGE_TYPE_METHOD_RETURN 2
#define DBUS_MESSAGE_TYPE_ERROR 3
#define DBUS_MESSAGE_TYPE_SIGNAL 4
/* Header flags */
#define DBUS_HEADER_FLAG_NO_REPLY_EXPECTED 0x1
#define DBUS_HEADER_FLAG_AUTO_ACTIVATION 0x2
/* Header fields */
#define DBUS_HEADER_FIELD_INVALID 0
#define DBUS_HEADER_FIELD_PATH 1
@ -87,25 +157,52 @@ extern "C" {
#define DBUS_HEADER_FIELD_LAST DBUS_HEADER_FIELD_SIGNATURE
/* Header format is defined as a signature:
* byte byte order
* byte message type ID
* byte flags
* byte protocol version
* uint32 body length
* uint32 serial
* array of struct (byte,variant) (field name, value)
*
* The length of the header can be computed as the
* fixed size of the initial data, plus the length of
* the array at the end, plus padding to an 8-boundary.
*/
#define DBUS_HEADER_SIGNATURE \
DBUS_TYPE_BYTE_AS_STRING \
DBUS_TYPE_BYTE_AS_STRING \
DBUS_TYPE_BYTE_AS_STRING \
DBUS_TYPE_BYTE_AS_STRING \
DBUS_TYPE_UINT32_AS_STRING \
DBUS_TYPE_UINT32_AS_STRING \
DBUS_TYPE_ARRAY_AS_STRING \
DBUS_STRUCT_BEGIN_CHAR_AS_STRING \
DBUS_TYPE_BYTE_AS_STRING \
DBUS_TYPE_VARIANT_AS_STRING \
DBUS_STRUCT_END_CHAR_AS_STRING
/* Services */
#define DBUS_SERVICE_ORG_FREEDESKTOP_DBUS "org.freedesktop.DBus"
/* Paths */
#define DBUS_PATH_ORG_FREEDESKTOP_DBUS "/org/freedesktop/DBus"
#define DBUS_PATH_ORG_FREEDESKTOP_LOCAL "/org/freedesktop/Local"
/* Interfaces, these #define don't do much other than
* catch typos at compile time
*/
#define DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS "org.freedesktop.DBus"
#define DBUS_INTERFACE_ORG_FREEDESKTOP_INTROSPECTABLE "org.freedesktop.Introspectable"
/* This is a special interface whose methods can only be invoked
* by the local implementation (messages from remote apps aren't
* allowed to specify this interface).
*/
#define DBUS_INTERFACE_ORG_FREEDESKTOP_LOCAL "org.freedesktop.Local"
/* Service owner flags */
#define DBUS_SERVICE_FLAG_PROHIBIT_REPLACEMENT 0x1
#define DBUS_SERVICE_FLAG_REPLACE_EXISTING 0x2

View file

@ -23,8 +23,8 @@
*/
#include "dbus-internals.h"
#include "dbus-marshal.h"
#include "dbus-sha.h"
#include "dbus-marshal-basic.h" /* for byteswap routines */
#include <string.h>
/* The following comments have the history of where this code

View file

@ -27,10 +27,11 @@
#include <string.h>
/* for vsnprintf */
#include <stdio.h>
#include "dbus-marshal.h"
#define DBUS_CAN_USE_DBUS_STRING_PRIVATE 1
#include "dbus-string-private.h"
#include "dbus-protocol.h"
#include "dbus-marshal-basic.h" /* probably should be removed by moving the usage of DBUS_TYPE
* into the marshaling-related files
*/
/* for DBUS_VA_COPY */
#include "dbus-sysdeps.h"
@ -77,25 +78,18 @@
* @{
*/
/**
* We allocate 1 byte for nul termination, plus 7 bytes for possible
* align_offset, so we always need 8 bytes on top of the string's
* length to be in the allocated block.
*/
#define ALLOCATION_PADDING 8
/**
* This is the maximum max length (and thus also the maximum length)
* of a DBusString
*/
#define MAX_MAX_LENGTH (_DBUS_INT_MAX - ALLOCATION_PADDING)
#define MAX_MAX_LENGTH (_DBUS_INT_MAX - _DBUS_STRING_ALLOCATION_PADDING)
/**
* Checks a bunch of assertions about a string object
*
* @param real the DBusRealString
*/
#define DBUS_GENERIC_STRING_PREAMBLE(real) _dbus_assert ((real) != NULL); _dbus_assert (!(real)->invalid); _dbus_assert ((real)->len >= 0); _dbus_assert ((real)->allocated >= 0); _dbus_assert ((real)->max_length >= 0); _dbus_assert ((real)->len <= ((real)->allocated - ALLOCATION_PADDING)); _dbus_assert ((real)->len <= (real)->max_length)
#define DBUS_GENERIC_STRING_PREAMBLE(real) _dbus_assert ((real) != NULL); _dbus_assert (!(real)->invalid); _dbus_assert ((real)->len >= 0); _dbus_assert ((real)->allocated >= 0); _dbus_assert ((real)->max_length >= 0); _dbus_assert ((real)->len <= ((real)->allocated - _DBUS_STRING_ALLOCATION_PADDING)); _dbus_assert ((real)->len <= (real)->max_length)
/**
* Checks assertions about a string object that needs to be
@ -142,7 +136,7 @@ fixup_alignment (DBusRealString *real)
unsigned int old_align_offset;
/* we have to have extra space in real->allocated for the align offset and nul byte */
_dbus_assert (real->len <= real->allocated - ALLOCATION_PADDING);
_dbus_assert (real->len <= real->allocated - _DBUS_STRING_ALLOCATION_PADDING);
old_align_offset = real->align_offset;
real_block = real->str - old_align_offset;
@ -205,11 +199,11 @@ _dbus_string_init_preallocated (DBusString *str,
* an existing string, e.g. in _dbus_string_steal_data()
*/
real->str = dbus_malloc (ALLOCATION_PADDING + allocate_size);
real->str = dbus_malloc (_DBUS_STRING_ALLOCATION_PADDING + allocate_size);
if (real->str == NULL)
return FALSE;
real->allocated = ALLOCATION_PADDING + allocate_size;
real->allocated = _DBUS_STRING_ALLOCATION_PADDING + allocate_size;
real->len = 0;
real->str[real->len] = '\0';
@ -299,10 +293,12 @@ _dbus_string_init_const_len (DBusString *str,
real->str = (char*) value;
real->len = len;
real->allocated = real->len + ALLOCATION_PADDING; /* a lie, just to avoid special-case assertions... */
real->allocated = real->len + _DBUS_STRING_ALLOCATION_PADDING; /* a lie, just to avoid special-case assertions... */
real->max_length = real->len + 1;
real->constant = TRUE;
real->locked = TRUE;
real->invalid = FALSE;
real->align_offset = 0;
/* We don't require const strings to be 8-byte aligned as the
* memory is coming from elsewhere.
@ -356,7 +352,7 @@ _dbus_string_lock (DBusString *str)
char *new_str;
int new_allocated;
new_allocated = real->len + ALLOCATION_PADDING;
new_allocated = real->len + _DBUS_STRING_ALLOCATION_PADDING;
new_str = dbus_realloc (real->str - real->align_offset,
new_allocated);
@ -380,8 +376,8 @@ reallocate_for_length (DBusRealString *real,
/* at least double our old allocation to avoid O(n), avoiding
* overflow
*/
if (real->allocated > (MAX_MAX_LENGTH + ALLOCATION_PADDING) / 2)
new_allocated = MAX_MAX_LENGTH + ALLOCATION_PADDING;
if (real->allocated > (MAX_MAX_LENGTH + _DBUS_STRING_ALLOCATION_PADDING) / 2)
new_allocated = MAX_MAX_LENGTH + _DBUS_STRING_ALLOCATION_PADDING;
else
new_allocated = real->allocated * 2;
@ -403,7 +399,7 @@ reallocate_for_length (DBusRealString *real,
/* But be sure we always alloc at least space for the new length */
new_allocated = MAX (new_allocated,
new_length + ALLOCATION_PADDING);
new_length + _DBUS_STRING_ALLOCATION_PADDING);
_dbus_assert (new_allocated >= real->allocated); /* code relies on this */
new_str = dbus_realloc (real->str - real->align_offset, new_allocated);
@ -426,7 +422,7 @@ set_length (DBusRealString *real,
/* exceeding max length is the same as failure to allocate memory */
if (_DBUS_UNLIKELY (new_length > real->max_length))
return FALSE;
else if (new_length > (real->allocated - ALLOCATION_PADDING) &&
else if (new_length > (real->allocated - _DBUS_STRING_ALLOCATION_PADDING) &&
_DBUS_UNLIKELY (!reallocate_for_length (real, new_length)))
return FALSE;
else
@ -1179,10 +1175,10 @@ _dbus_string_insert_alignment (DBusString *str,
{
DBUS_STRING_PREAMBLE (str);
if (!align_insert_point_then_open_gap (str, insert_at, 8, 0))
if (!align_insert_point_then_open_gap (str, insert_at, alignment, 0))
return FALSE;
_dbus_assert (_DBUS_ALIGN_VALUE (*insert_at, 8) == (unsigned) *insert_at);
_dbus_assert (_DBUS_ALIGN_VALUE (*insert_at, alignment) == (unsigned) *insert_at);
return TRUE;
}
@ -2752,387 +2748,6 @@ _dbus_string_validate_nul (const DBusString *str,
return TRUE;
}
/**
* Checks that the given range of the string is a valid object path
* name in the D-BUS protocol. This includes a length restriction,
* etc., see the specification. It does not validate UTF-8, that has
* to be done separately for now.
*
* @todo this is inconsistent with most of DBusString in that
* it allows a start,len range that extends past the string end.
*
* @todo change spec to disallow more things, such as spaces in the
* path name
*
* @param str the string
* @param start first byte index to check
* @param len number of bytes to check
* @returns #TRUE if the byte range exists and is a valid name
*/
dbus_bool_t
_dbus_string_validate_path (const DBusString *str,
int start,
int len)
{
const unsigned char *s;
const unsigned char *end;
const unsigned char *last_slash;
DBUS_CONST_STRING_PREAMBLE (str);
_dbus_assert (start >= 0);
_dbus_assert (len >= 0);
_dbus_assert (start <= real->len);
if (len > real->len - start)
return FALSE;
if (len > DBUS_MAXIMUM_NAME_LENGTH)
return FALSE;
if (len == 0)
return FALSE;
s = real->str + start;
end = s + len;
if (*s != '/')
return FALSE;
last_slash = s;
++s;
while (s != end)
{
if (*s == '/')
{
if ((s - last_slash) < 2)
return FALSE; /* no empty path components allowed */
last_slash = s;
}
++s;
}
if ((end - last_slash) < 2 &&
len > 1)
return FALSE; /* trailing slash not allowed unless the string is "/" */
return TRUE;
}
/**
* Determine wether the given charater is valid as the first charater
* in a name.
*/
#define VALID_INITIAL_NAME_CHARACTER(c) \
( ((c) >= 'A' && (c) <= 'Z') || \
((c) >= 'a' && (c) <= 'z') || \
((c) == '_') )
/**
* Determine wether the given charater is valid as a second or later
* character in a nam
*/
#define VALID_NAME_CHARACTER(c) \
( ((c) >= '0' && (c) <= '9') || \
((c) >= 'A' && (c) <= 'Z') || \
((c) >= 'a' && (c) <= 'z') || \
((c) == '_') )
/**
* Checks that the given range of the string is a valid interface name
* in the D-BUS protocol. This includes a length restriction and an
* ASCII subset, see the specification.
*
* @todo this is inconsistent with most of DBusString in that
* it allows a start,len range that extends past the string end.
*
* @param str the string
* @param start first byte index to check
* @param len number of bytes to check
* @returns #TRUE if the byte range exists and is a valid name
*/
dbus_bool_t
_dbus_string_validate_interface (const DBusString *str,
int start,
int len)
{
const unsigned char *s;
const unsigned char *end;
const unsigned char *iface;
const unsigned char *last_dot;
DBUS_CONST_STRING_PREAMBLE (str);
_dbus_assert (start >= 0);
_dbus_assert (len >= 0);
_dbus_assert (start <= real->len);
if (len > real->len - start)
return FALSE;
if (len > DBUS_MAXIMUM_NAME_LENGTH)
return FALSE;
if (len == 0)
return FALSE;
last_dot = NULL;
iface = real->str + start;
end = iface + len;
s = iface;
/* check special cases of first char so it doesn't have to be done
* in the loop. Note we know len > 0
*/
if (_DBUS_UNLIKELY (*s == '.')) /* disallow starting with a . */
return FALSE;
else if (_DBUS_UNLIKELY (!VALID_INITIAL_NAME_CHARACTER (*s)))
return FALSE;
else
++s;
while (s != end)
{
if (*s == '.')
{
if (_DBUS_UNLIKELY ((s + 1) == end))
return FALSE;
else if (_DBUS_UNLIKELY (!VALID_INITIAL_NAME_CHARACTER (*(s + 1))))
return FALSE;
last_dot = s;
++s; /* we just validated the next char, so skip two */
}
else if (_DBUS_UNLIKELY (!VALID_NAME_CHARACTER (*s)))
{
return FALSE;
}
++s;
}
if (_DBUS_UNLIKELY (last_dot == NULL))
return FALSE;
return TRUE;
}
/**
* Checks that the given range of the string is a valid member name
* in the D-BUS protocol. This includes a length restriction, etc.,
* see the specification.
*
* @todo this is inconsistent with most of DBusString in that
* it allows a start,len range that extends past the string end.
*
* @param str the string
* @param start first byte index to check
* @param len number of bytes to check
* @returns #TRUE if the byte range exists and is a valid name
*/
dbus_bool_t
_dbus_string_validate_member (const DBusString *str,
int start,
int len)
{
const unsigned char *s;
const unsigned char *end;
const unsigned char *member;
DBUS_CONST_STRING_PREAMBLE (str);
_dbus_assert (start >= 0);
_dbus_assert (len >= 0);
_dbus_assert (start <= real->len);
if (len > real->len - start)
return FALSE;
if (len > DBUS_MAXIMUM_NAME_LENGTH)
return FALSE;
if (len == 0)
return FALSE;
member = real->str + start;
end = member + len;
s = member;
/* check special cases of first char so it doesn't have to be done
* in the loop. Note we know len > 0
*/
if (_DBUS_UNLIKELY (!VALID_INITIAL_NAME_CHARACTER (*s)))
return FALSE;
else
++s;
while (s != end)
{
if (_DBUS_UNLIKELY (!VALID_NAME_CHARACTER (*s)))
{
return FALSE;
}
++s;
}
return TRUE;
}
/**
* Checks that the given range of the string is a valid error name
* in the D-BUS protocol. This includes a length restriction, etc.,
* see the specification.
*
* @todo this is inconsistent with most of DBusString in that
* it allows a start,len range that extends past the string end.
*
* @param str the string
* @param start first byte index to check
* @param len number of bytes to check
* @returns #TRUE if the byte range exists and is a valid name
*/
dbus_bool_t
_dbus_string_validate_error_name (const DBusString *str,
int start,
int len)
{
/* Same restrictions as interface name at the moment */
return _dbus_string_validate_interface (str, start, len);
}
/* This assumes the first char exists and is ':' */
static dbus_bool_t
_dbus_string_validate_base_service (const DBusString *str,
int start,
int len)
{
const unsigned char *s;
const unsigned char *end;
const unsigned char *service;
DBUS_CONST_STRING_PREAMBLE (str);
_dbus_assert (start >= 0);
_dbus_assert (len >= 0);
_dbus_assert (start <= real->len);
if (len > real->len - start)
return FALSE;
if (len > DBUS_MAXIMUM_NAME_LENGTH)
return FALSE;
_dbus_assert (len > 0);
service = real->str + start;
end = service + len;
_dbus_assert (*service == ':');
s = service + 1;
while (s != end)
{
if (*s == '.')
{
if (_DBUS_UNLIKELY ((s + 1) == end))
return FALSE;
if (_DBUS_UNLIKELY (!VALID_NAME_CHARACTER (*(s + 1))))
return FALSE;
++s; /* we just validated the next char, so skip two */
}
else if (_DBUS_UNLIKELY (!VALID_NAME_CHARACTER (*s)))
{
return FALSE;
}
++s;
}
return TRUE;
}
/**
* Checks that the given range of the string is a valid service name
* in the D-BUS protocol. This includes a length restriction, etc.,
* see the specification.
*
* @todo this is inconsistent with most of DBusString in that
* it allows a start,len range that extends past the string end.
*
* @param str the string
* @param start first byte index to check
* @param len number of bytes to check
* @returns #TRUE if the byte range exists and is a valid name
*/
dbus_bool_t
_dbus_string_validate_service (const DBusString *str,
int start,
int len)
{
if (_DBUS_UNLIKELY (len == 0))
return FALSE;
if (_dbus_string_get_byte (str, start) == ':')
return _dbus_string_validate_base_service (str, start, len);
else
return _dbus_string_validate_interface (str, start, len);
}
/**
* Checks that the given range of the string is a valid message type
* signature in the D-BUS protocol.
*
* @todo this is inconsistent with most of DBusString in that
* it allows a start,len range that extends past the string end.
*
* @param str the string
* @param start first byte index to check
* @param len number of bytes to check
* @returns #TRUE if the byte range exists and is a valid signature
*/
dbus_bool_t
_dbus_string_validate_signature (const DBusString *str,
int start,
int len)
{
const unsigned char *s;
const unsigned char *end;
DBUS_CONST_STRING_PREAMBLE (str);
_dbus_assert (start >= 0);
_dbus_assert (start <= real->len);
_dbus_assert (len >= 0);
if (len > real->len - start)
return FALSE;
s = real->str + start;
end = s + len;
while (s != end)
{
switch (*s)
{
case DBUS_TYPE_NIL:
case DBUS_TYPE_BYTE:
case DBUS_TYPE_BOOLEAN:
case DBUS_TYPE_INT32:
case DBUS_TYPE_UINT32:
case DBUS_TYPE_INT64:
case DBUS_TYPE_UINT64:
case DBUS_TYPE_DOUBLE:
case DBUS_TYPE_STRING:
case DBUS_TYPE_CUSTOM:
case DBUS_TYPE_ARRAY:
case DBUS_TYPE_DICT:
case DBUS_TYPE_OBJECT_PATH:
break;
default:
return FALSE;
}
++s;
}
return TRUE;
}
/**
* Clears all allocated bytes in the string to zero.
*
@ -3393,127 +3008,6 @@ _dbus_string_test (void)
int lens[] = { 0, 1, 2, 3, 4, 5, 10, 16, 17, 18, 25, 31, 32, 33, 34, 35, 63, 64, 65, 66, 67, 68, 69, 70, 71, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136 };
char *s;
dbus_unichar_t ch;
const char *valid_paths[] = {
"/",
"/foo/bar",
"/foo",
"/foo/bar/baz"
};
const char *invalid_paths[] = {
"bar",
"bar/baz",
"/foo/bar/",
"/foo/"
"foo/",
"boo//blah",
"//",
"///",
"foo///blah/",
"Hello World",
"",
" ",
"foo bar"
};
const char *valid_interfaces[] = {
"org.freedesktop.Foo",
"Bar.Baz",
"Blah.Blah.Blah.Blah.Blah",
"a.b",
"a.b.c.d.e.f.g",
"a0.b1.c2.d3.e4.f5.g6",
"abc123.foo27"
};
const char *invalid_interfaces[] = {
".",
"",
"..",
".Foo.Bar",
"..Foo.Bar",
"Foo.Bar.",
"Foo.Bar..",
"Foo",
"9foo.bar.baz",
"foo.bar..baz",
"foo.bar...baz",
"foo.bar.b..blah",
":",
":0-1",
"10",
":11.34324",
"0.0.0",
"0..0",
"foo.Bar.%",
"foo.Bar!!",
"!Foo.bar.bz",
"foo.$.blah",
"",
" ",
"foo bar"
};
const char *valid_base_services[] = {
":0",
":a",
":",
":.a",
":.1",
":0.1",
":000.2222",
":.blah",
":abce.freedesktop.blah"
};
const char *invalid_base_services[] = {
":-",
":!",
":0-10",
":blah.",
":blah.",
":blah..org",
":blah.org..",
":..blah.org",
"",
" ",
"foo bar"
};
const char *valid_members[] = {
"Hello",
"Bar",
"foobar",
"_foobar",
"foo89"
};
const char *invalid_members[] = {
"9Hello",
"10",
"1",
"foo-bar",
"blah.org",
".blah",
"blah.",
"Hello.",
"!foo",
"",
" ",
"foo bar"
};
const char *valid_signatures[] = {
"",
"sss",
"i",
"b"
};
const char *invalid_signatures[] = {
" ",
"not a valid signature",
"123",
".",
"("
};
i = 0;
while (i < _DBUS_N_ELEMENTS (lens))
@ -3901,284 +3395,6 @@ _dbus_string_test (void)
_dbus_string_free (&other);
test_roundtrips (test_hex_roundtrip);
/* Path validation */
i = 0;
while (i < (int) _DBUS_N_ELEMENTS (valid_paths))
{
_dbus_string_init_const (&str, valid_paths[i]);
if (!_dbus_string_validate_path (&str, 0,
_dbus_string_get_length (&str)))
{
_dbus_warn ("Path \"%s\" should have been valid\n", valid_paths[i]);
_dbus_assert_not_reached ("invalid path");
}
++i;
}
i = 0;
while (i < (int) _DBUS_N_ELEMENTS (invalid_paths))
{
_dbus_string_init_const (&str, invalid_paths[i]);
if (_dbus_string_validate_path (&str, 0,
_dbus_string_get_length (&str)))
{
_dbus_warn ("Path \"%s\" should have been invalid\n", invalid_paths[i]);
_dbus_assert_not_reached ("valid path");
}
++i;
}
/* Interface validation */
i = 0;
while (i < (int) _DBUS_N_ELEMENTS (valid_interfaces))
{
_dbus_string_init_const (&str, valid_interfaces[i]);
if (!_dbus_string_validate_interface (&str, 0,
_dbus_string_get_length (&str)))
{
_dbus_warn ("Interface \"%s\" should have been valid\n", valid_interfaces[i]);
_dbus_assert_not_reached ("invalid interface");
}
++i;
}
i = 0;
while (i < (int) _DBUS_N_ELEMENTS (invalid_interfaces))
{
_dbus_string_init_const (&str, invalid_interfaces[i]);
if (_dbus_string_validate_interface (&str, 0,
_dbus_string_get_length (&str)))
{
_dbus_warn ("Interface \"%s\" should have been invalid\n", invalid_interfaces[i]);
_dbus_assert_not_reached ("valid interface");
}
++i;
}
/* Service validation (check that valid interfaces are valid services,
* and invalid interfaces are invalid services except if they start with ':')
*/
i = 0;
while (i < (int) _DBUS_N_ELEMENTS (valid_interfaces))
{
_dbus_string_init_const (&str, valid_interfaces[i]);
if (!_dbus_string_validate_service (&str, 0,
_dbus_string_get_length (&str)))
{
_dbus_warn ("Service \"%s\" should have been valid\n", valid_interfaces[i]);
_dbus_assert_not_reached ("invalid service");
}
++i;
}
i = 0;
while (i < (int) _DBUS_N_ELEMENTS (invalid_interfaces))
{
if (invalid_interfaces[i][0] != ':')
{
_dbus_string_init_const (&str, invalid_interfaces[i]);
if (_dbus_string_validate_service (&str, 0,
_dbus_string_get_length (&str)))
{
_dbus_warn ("Service \"%s\" should have been invalid\n", invalid_interfaces[i]);
_dbus_assert_not_reached ("valid service");
}
}
++i;
}
/* Base service validation */
i = 0;
while (i < (int) _DBUS_N_ELEMENTS (valid_base_services))
{
_dbus_string_init_const (&str, valid_base_services[i]);
if (!_dbus_string_validate_service (&str, 0,
_dbus_string_get_length (&str)))
{
_dbus_warn ("Service \"%s\" should have been valid\n", valid_base_services[i]);
_dbus_assert_not_reached ("invalid base service");
}
++i;
}
i = 0;
while (i < (int) _DBUS_N_ELEMENTS (invalid_base_services))
{
_dbus_string_init_const (&str, invalid_base_services[i]);
if (_dbus_string_validate_service (&str, 0,
_dbus_string_get_length (&str)))
{
_dbus_warn ("Service \"%s\" should have been invalid\n", invalid_base_services[i]);
_dbus_assert_not_reached ("valid base service");
}
++i;
}
/* Error name validation (currently identical to interfaces)
*/
i = 0;
while (i < (int) _DBUS_N_ELEMENTS (valid_interfaces))
{
_dbus_string_init_const (&str, valid_interfaces[i]);
if (!_dbus_string_validate_error_name (&str, 0,
_dbus_string_get_length (&str)))
{
_dbus_warn ("Error name \"%s\" should have been valid\n", valid_interfaces[i]);
_dbus_assert_not_reached ("invalid error name");
}
++i;
}
i = 0;
while (i < (int) _DBUS_N_ELEMENTS (invalid_interfaces))
{
if (invalid_interfaces[i][0] != ':')
{
_dbus_string_init_const (&str, invalid_interfaces[i]);
if (_dbus_string_validate_error_name (&str, 0,
_dbus_string_get_length (&str)))
{
_dbus_warn ("Error name \"%s\" should have been invalid\n", invalid_interfaces[i]);
_dbus_assert_not_reached ("valid error name");
}
}
++i;
}
/* Member validation */
i = 0;
while (i < (int) _DBUS_N_ELEMENTS (valid_members))
{
_dbus_string_init_const (&str, valid_members[i]);
if (!_dbus_string_validate_member (&str, 0,
_dbus_string_get_length (&str)))
{
_dbus_warn ("Member \"%s\" should have been valid\n", valid_members[i]);
_dbus_assert_not_reached ("invalid member");
}
++i;
}
i = 0;
while (i < (int) _DBUS_N_ELEMENTS (invalid_members))
{
_dbus_string_init_const (&str, invalid_members[i]);
if (_dbus_string_validate_member (&str, 0,
_dbus_string_get_length (&str)))
{
_dbus_warn ("Member \"%s\" should have been invalid\n", invalid_members[i]);
_dbus_assert_not_reached ("valid member");
}
++i;
}
/* Signature validation */
i = 0;
while (i < (int) _DBUS_N_ELEMENTS (valid_signatures))
{
_dbus_string_init_const (&str, valid_signatures[i]);
if (!_dbus_string_validate_signature (&str, 0,
_dbus_string_get_length (&str)))
{
_dbus_warn ("Signature \"%s\" should have been valid\n", valid_signatures[i]);
_dbus_assert_not_reached ("invalid signature");
}
++i;
}
i = 0;
while (i < (int) _DBUS_N_ELEMENTS (invalid_signatures))
{
_dbus_string_init_const (&str, invalid_signatures[i]);
if (_dbus_string_validate_signature (&str, 0,
_dbus_string_get_length (&str)))
{
_dbus_warn ("Signature \"%s\" should have been invalid\n", invalid_signatures[i]);
_dbus_assert_not_reached ("valid signature");
}
++i;
}
/* Validate claimed length longer than real length */
_dbus_string_init_const (&str, "abc.efg");
if (_dbus_string_validate_service (&str, 0, 8))
_dbus_assert_not_reached ("validated too-long string");
if (_dbus_string_validate_interface (&str, 0, 8))
_dbus_assert_not_reached ("validated too-long string");
if (_dbus_string_validate_error_name (&str, 0, 8))
_dbus_assert_not_reached ("validated too-long string");
_dbus_string_init_const (&str, "abc");
if (_dbus_string_validate_member (&str, 0, 4))
_dbus_assert_not_reached ("validated too-long string");
_dbus_string_init_const (&str, "sss");
if (_dbus_string_validate_signature (&str, 0, 4))
_dbus_assert_not_reached ("validated too-long signature");
/* Validate string exceeding max name length */
if (!_dbus_string_init (&str))
_dbus_assert_not_reached ("no memory");
while (_dbus_string_get_length (&str) <= DBUS_MAXIMUM_NAME_LENGTH)
if (!_dbus_string_append (&str, "abc.def"))
_dbus_assert_not_reached ("no memory");
if (_dbus_string_validate_service (&str, 0, _dbus_string_get_length (&str)))
_dbus_assert_not_reached ("validated overmax string");
if (_dbus_string_validate_interface (&str, 0, _dbus_string_get_length (&str)))
_dbus_assert_not_reached ("validated overmax string");
if (_dbus_string_validate_error_name (&str, 0, _dbus_string_get_length (&str)))
_dbus_assert_not_reached ("validated overmax string");
/* overlong member */
_dbus_string_set_length (&str, 0);
while (_dbus_string_get_length (&str) <= DBUS_MAXIMUM_NAME_LENGTH)
if (!_dbus_string_append (&str, "abc"))
_dbus_assert_not_reached ("no memory");
if (_dbus_string_validate_member (&str, 0, _dbus_string_get_length (&str)))
_dbus_assert_not_reached ("validated overmax string");
/* overlong base service */
_dbus_string_set_length (&str, 0);
_dbus_string_append (&str, ":");
while (_dbus_string_get_length (&str) <= DBUS_MAXIMUM_NAME_LENGTH)
if (!_dbus_string_append (&str, "abc"))
_dbus_assert_not_reached ("no memory");
if (_dbus_string_validate_service (&str, 0, _dbus_string_get_length (&str)))
_dbus_assert_not_reached ("validated overmax string");
_dbus_string_free (&str);

View file

@ -39,10 +39,10 @@ DBUS_BEGIN_DECLS
*/
struct DBusString
{
void *dummy1; /**< placeholder */
int dummy2; /**< placeholder */
int dummy3; /**< placeholder */
int dummy4; /**< placeholder */
const void *dummy1; /**< placeholder */
int dummy2; /**< placeholder */
int dummy3; /**< placeholder */
int dummy4; /**< placeholder */
unsigned int dummy5 : 1; /**< placeholder */
unsigned int dummy6 : 1; /**< placeholder */
unsigned int dummy7 : 1; /**< placeholder */
@ -264,27 +264,32 @@ dbus_bool_t _dbus_string_validate_utf8 (const DBusString *str,
dbus_bool_t _dbus_string_validate_nul (const DBusString *str,
int start,
int len);
dbus_bool_t _dbus_string_validate_path (const DBusString *str,
int start,
int len);
dbus_bool_t _dbus_string_validate_interface (const DBusString *str,
int start,
int len);
dbus_bool_t _dbus_string_validate_member (const DBusString *str,
int start,
int len);
dbus_bool_t _dbus_string_validate_error_name (const DBusString *str,
int start,
int len);
dbus_bool_t _dbus_string_validate_service (const DBusString *str,
int start,
int len);
dbus_bool_t _dbus_string_validate_signature (const DBusString *str,
int start,
int len);
void _dbus_string_zero (DBusString *str);
/**
* We allocate 1 byte for nul termination, plus 7 bytes for possible
* align_offset, so we always need 8 bytes on top of the string's
* length to be in the allocated block.
*/
#define _DBUS_STRING_ALLOCATION_PADDING 8
/**
* Defines a static const variable with type #DBusString called "name"
* containing the given string literal.
*
* @param name the name of the variable
* @param str the string value
*/
#define _DBUS_STRING_DEFINE_STATIC(name, str) \
static const char _dbus_static_string_##name[] = str; \
static const DBusString name = { _dbus_static_string_##name, \
sizeof(_dbus_static_string_##name), \
sizeof(_dbus_static_string_##name) + \
_DBUS_STRING_ALLOCATION_PADDING, \
sizeof(_dbus_static_string_##name), \
TRUE, TRUE, FALSE, 0 }
DBUS_END_DECLS
#endif /* DBUS_STRING_H */

View file

@ -118,6 +118,16 @@ dbus_internal_do_not_use_run_tests (const char *test_data_dir)
check_memleaks ();
#if 1
printf ("%s: running recursive marshalling tests\n", "dbus-test");
if (!_dbus_marshal_recursive_test ())
die ("recursive marshal");
check_memleaks ();
#else
_dbus_warn ("recursive marshal tests disabled\n");
#endif
printf ("%s: running memory tests\n", "dbus-test");
if (!_dbus_memory_test ())
die ("memory");
@ -135,6 +145,18 @@ dbus_internal_do_not_use_run_tests (const char *test_data_dir)
die ("lists");
check_memleaks ();
printf ("%s: running validation tests\n", "dbus-test");
if (!_dbus_marshal_validate_test ())
die ("validation");
check_memleaks ();
printf ("%s: running header marshal tests\n", "dbus-test");
if (!_dbus_marshal_header_test ())
die ("header marshal");
check_memleaks ();
printf ("%s: running message tests\n", "dbus-test");
if (!_dbus_message_test (test_data_dir))
@ -197,5 +219,3 @@ dbus_internal_do_not_use_run_tests (const char *test_data_dir)
printf ("Not compiled with unit tests, not running any\n");
#endif
}

View file

@ -35,26 +35,29 @@ typedef enum
_DBUS_MESSAGE_UNKNOWN
} DBusMessageValidity;
dbus_bool_t _dbus_hash_test (void);
dbus_bool_t _dbus_dict_test (void);
dbus_bool_t _dbus_list_test (void);
dbus_bool_t _dbus_marshal_test (void);
dbus_bool_t _dbus_mem_pool_test (void);
dbus_bool_t _dbus_string_test (void);
dbus_bool_t _dbus_address_test (void);
dbus_bool_t _dbus_server_test (void);
dbus_bool_t _dbus_message_test (const char *test_data_dir);
dbus_bool_t _dbus_auth_test (const char *test_data_dir);
dbus_bool_t _dbus_md5_test (void);
dbus_bool_t _dbus_sha_test (const char *test_data_dir);
dbus_bool_t _dbus_keyring_test (void);
dbus_bool_t _dbus_data_slot_test (void);
dbus_bool_t _dbus_sysdeps_test (void);
dbus_bool_t _dbus_spawn_test (const char *test_data_dir);
dbus_bool_t _dbus_userdb_test (const char *test_data_dir);
dbus_bool_t _dbus_memory_test (void);
dbus_bool_t _dbus_object_tree_test (void);
dbus_bool_t _dbus_pending_call_test (const char *test_data_dir);
dbus_bool_t _dbus_hash_test (void);
dbus_bool_t _dbus_dict_test (void);
dbus_bool_t _dbus_list_test (void);
dbus_bool_t _dbus_marshal_test (void);
dbus_bool_t _dbus_marshal_recursive_test (void);
dbus_bool_t _dbus_marshal_header_test (void);
dbus_bool_t _dbus_marshal_validate_test (void);
dbus_bool_t _dbus_mem_pool_test (void);
dbus_bool_t _dbus_string_test (void);
dbus_bool_t _dbus_address_test (void);
dbus_bool_t _dbus_server_test (void);
dbus_bool_t _dbus_message_test (const char *test_data_dir);
dbus_bool_t _dbus_auth_test (const char *test_data_dir);
dbus_bool_t _dbus_md5_test (void);
dbus_bool_t _dbus_sha_test (const char *test_data_dir);
dbus_bool_t _dbus_keyring_test (void);
dbus_bool_t _dbus_data_slot_test (void);
dbus_bool_t _dbus_sysdeps_test (void);
dbus_bool_t _dbus_spawn_test (const char *test_data_dir);
dbus_bool_t _dbus_userdb_test (const char *test_data_dir);
dbus_bool_t _dbus_memory_test (void);
dbus_bool_t _dbus_object_tree_test (void);
dbus_bool_t _dbus_pending_call_test (const char *test_data_dir);
void dbus_internal_do_not_use_run_tests (const char *test_data_dir);
dbus_bool_t dbus_internal_do_not_use_try_message_file (const DBusString *filename,

View file

@ -15,11 +15,11 @@ Important for 1.0
which of these functions to include, in light of the fact that
GLib/Qt native stubs will probably also exist.
- the invalid messages in the test suite are all useless because
they are invalid for the wrong reasons due to protocol changes.
(Consider extending test suite to validate that they are
invalid for right reason, e.g. an "INVALID_ERROR Foo" line
in the message files)
- the "break loader" and valid/invalid message tests are all disabled;
they need to be fixed and re-enabled with the new message args stuff.
I think I want to drop the .message files thing and just have code
that generates messages, more like the tests for
dbus-marshal-recursive.c
- modify the auth protocol to also support other initial-handshake
type of information:
@ -30,26 +30,6 @@ Important for 1.0
since protocol probably modifies the API. But we could have it there
as a safety net.
- re_align_field_recurse() in dbus-message.c is broken because it
crashes on some types of header field values. security problem.
- modify the wire protocol to keep the args signature separate
from the args themselves. Make the name of TYPE_CUSTOM part
of the type signature, rather than part of the value.
Then you have the full typecheck in a single string.
See http://freedesktop.org/pipermail/dbus/2004-June/001169.html
Subnote: STRING_OR_NIL is wrong, doesn't work in C++ etc. ; should
not have done that. Use empty string or special string values or separate functions/signals
or whatever instead.
Subnote: For recursive types, one approach is that "structs" are done as parens,
so e.g. s(ii) is a string and struct { int; int; } etc. Type codes
then all have to be done as strings not single ints.
We could also put the type signature for the message body in a
header field.
An "any" type has the type string included in the value.
- need to define bus behavior if you send a message to
yourself; is it an error, or allowed? If allowed,
we need to have a test for it in the test suite.
@ -58,9 +38,12 @@ Important for 1.0
(though they are kind of a pita to pass in as size_t with the
varargs, so maybe not - what does glib do with g_object_get()?)
- it's probably obnoxious that reading/writing bools doesn't return dbus_bool_t;
the only possible solution I think is to change dbus_bool_t to unsigned char,
but that may cause wackiness elsewhere.
- it's probably obnoxious that reading/writing bools doesn't return
dbus_bool_t; solution is probably to change bool to 32 bits on the
wire
- maybe change and don't align variant bodies to 8-boundary, it uses
up lots of space in a typical header
- rename the service thing. unique service names (":1") and well-known
("org.foo.bar") should have different names probably; something like
@ -68,6 +51,12 @@ Important for 1.0
"application id" for the unique and "common name" or "published
name" for the well-known; not sure yet.
- things are broken now when mixing endianness, because DBusMessage
doesn't autoswap itself when you access a message of alternate
endian.
- add string array support back to append_args()
Important for 1.0 GLib Bindings
===
@ -103,6 +92,8 @@ Might as Well for 1.0
- connection_open/connection_disconnect lacks symmetry, open/close
or connect/disconnect
- protocol version in each message is pretty silly
Can Be Post 1.0
===

View file

@ -308,7 +308,7 @@ handle_introspect (DBusConnection *connection,
g_error ("Out of memory");
dbus_message_append_args (message,
DBUS_TYPE_STRING, xml->str,
DBUS_TYPE_STRING, &xml->str,
DBUS_TYPE_INVALID);
dbus_connection_send (connection, message, NULL);

View file

@ -941,8 +941,8 @@ dbus_g_proxy_new_for_service_owner (DBusGConnection *connection,
DBusGProxy *proxy;
DBusMessage *request, *reply;
DBusError derror;
char *base_service_name;
const char *base_service_name;
g_return_val_if_fail (connection != NULL, NULL);
g_return_val_if_fail (service_name != NULL, NULL);
g_return_val_if_fail (path_name != NULL, NULL);
@ -962,7 +962,7 @@ dbus_g_proxy_new_for_service_owner (DBusGConnection *connection,
g_error ("Out of memory");
if (! dbus_message_append_args (request,
DBUS_TYPE_STRING, service_name,
DBUS_TYPE_STRING, &service_name,
DBUS_TYPE_INVALID))
g_error ("Out of memory");
@ -997,7 +997,6 @@ dbus_g_proxy_new_for_service_owner (DBusGConnection *connection,
dbus_message_unref (request);
if (reply)
dbus_message_unref (reply);
dbus_free (base_service_name);
return proxy;
}

View file

@ -84,10 +84,10 @@ _dbus_gutils_type_to_string (int type)
{
case DBUS_TYPE_INVALID:
return "invalid";
case DBUS_TYPE_NIL:
return "nil";
case DBUS_TYPE_BOOLEAN:
return "boolean";
case DBUS_TYPE_BYTE:
return "byte";
case DBUS_TYPE_INT32:
return "int32";
case DBUS_TYPE_UINT32:
@ -96,16 +96,20 @@ _dbus_gutils_type_to_string (int type)
return "double";
case DBUS_TYPE_STRING:
return "string";
case DBUS_TYPE_CUSTOM:
return "custom";
case DBUS_TYPE_OBJECT_PATH:
return "object_path";
case DBUS_TYPE_SIGNATURE:
return "signature";
case DBUS_TYPE_STRUCT:
return "struct";
case DBUS_TYPE_ARRAY:
return "array";
case DBUS_TYPE_DICT:
return "dict";
case DBUS_TYPE_INT64:
return "int64";
case DBUS_TYPE_UINT64:
return "uint64";
case DBUS_TYPE_VARIANT:
return "variant";
case DBUS_STRUCT_BEGIN_CHAR:
return "begin_struct";
case DBUS_STRUCT_END_CHAR:
return "end_struct";
default:
return "unknown";
}

View file

@ -1,3 +1,26 @@
/* -*- mode: C; c-file-style: "gnu" -*- */
/* dbus-gvalue.c GValue to-from DBusMessageIter
*
* Copyright (C) 2004 Ximian, Inc.
*
* Licensed under the Academic Free License version 2.1
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include <dbus-gvalue.h>
gboolean
@ -5,41 +28,43 @@ dbus_gvalue_demarshal (DBusMessageIter *iter, GValue *value)
{
gboolean can_convert = TRUE;
/* This is slightly evil, we don't use g_value_set_foo() functions */
#define MAP_BASIC(d_t, g_t) \
case DBUS_TYPE_##d_t: \
g_value_init (value, G_TYPE_##g_t); \
dbus_message_iter_get_basic (iter, &value->data[0]); \
break
switch (dbus_message_iter_get_arg_type (iter))
{
#define MAP(d_t, d_get, g_t, g_set) \
case DBUS_##d_t: \
g_value_init (value, G_##g_t); \
g_value_##g_set (value, dbus_message_iter_##d_get (iter)); \
break
MAP(TYPE_BYTE, get_byte, TYPE_UCHAR, set_uchar);
MAP(TYPE_BOOLEAN, get_boolean, TYPE_BOOLEAN , set_boolean);
MAP(TYPE_INT32, get_int32, TYPE_INT , set_int);
MAP(TYPE_UINT32, get_uint32, TYPE_UINT , set_uint);
#ifdef DBUS_HAVE_INT64
MAP(TYPE_INT64, get_int64, TYPE_INT64 , set_int64);
MAP(TYPE_UINT64, get_uint64, TYPE_UINT64 , set_uint64);
#endif
MAP(TYPE_DOUBLE, get_double, TYPE_DOUBLE , set_double);
MAP_BASIC (BOOLEAN, BOOLEAN);
MAP_BASIC (BYTE, UCHAR);
MAP_BASIC (INT32, INT);
MAP_BASIC (UINT32, UINT);
MAP_BASIC (INT64, INT64);
MAP_BASIC (UINT64, UINT64);
MAP_BASIC (DOUBLE, DOUBLE);
case DBUS_TYPE_STRING:
case DBUS_TYPE_OBJECT_PATH:
case DBUS_TYPE_SIGNATURE:
{
char *s; /* FIXME use a const string accessor */
const char *s;
g_value_init (value, G_TYPE_STRING);
s = dbus_message_iter_get_string (iter);
dbus_message_iter_get_basic (iter, &s);
g_value_set_string (value, s);
g_free (s);
}
break;
case DBUS_TYPE_STRUCT:
case DBUS_TYPE_ARRAY:
case DBUS_TYPE_VARIANT:
default:
/* FIXME: we need to define custom boxed types for arrays
etc. so we can map them transparently / pleasantly */
can_convert = FALSE;
break;
}
#undef MAP
#undef MAP_BASIC
return can_convert;
}
@ -54,59 +79,120 @@ dbus_gvalue_marshal (DBusMessageIter *iter, GValue *value)
switch (value_type)
{
case G_TYPE_CHAR:
dbus_message_iter_append_byte (iter,
g_value_get_char (value));
{
char b = g_value_get_char (value);
if (!dbus_message_iter_append_basic (iter,
DBUS_TYPE_BYTE,
&b))
goto nomem;
}
break;
case G_TYPE_UCHAR:
dbus_message_iter_append_byte (iter,
g_value_get_uchar (value));
{
unsigned char b = g_value_get_uchar (value);
if (!dbus_message_iter_append_basic (iter,
DBUS_TYPE_BYTE,
&b))
goto nomem;
}
break;
case G_TYPE_BOOLEAN:
dbus_message_iter_append_boolean (iter,
g_value_get_boolean (value));
{
unsigned char b = g_value_get_boolean (value);
if (!dbus_message_iter_append_basic (iter,
DBUS_TYPE_BOOLEAN,
&b))
goto nomem;
}
break;
case G_TYPE_INT:
dbus_message_iter_append_int32 (iter,
g_value_get_int (value));
{
dbus_int32_t v = g_value_get_int (value);
if (!dbus_message_iter_append_basic (iter,
DBUS_TYPE_INT32,
&v))
goto nomem;
}
break;
case G_TYPE_UINT:
dbus_message_iter_append_uint32 (iter,
g_value_get_uint (value));
{
dbus_uint32_t v = g_value_get_uint (value);
if (!dbus_message_iter_append_basic (iter,
DBUS_TYPE_UINT32,
&v))
goto nomem;
}
break;
/* long gets cut to 32 bits so the remote API is consistent
* on all architectures
*/
case G_TYPE_LONG:
dbus_message_iter_append_int32 (iter,
g_value_get_long (value));
{
dbus_int32_t v = g_value_get_long (value);
if (!dbus_message_iter_append_basic (iter,
DBUS_TYPE_INT32,
&v))
goto nomem;
}
break;
case G_TYPE_ULONG:
dbus_message_iter_append_uint32 (iter,
g_value_get_ulong (value));
{
dbus_uint32_t v = g_value_get_ulong (value);
if (!dbus_message_iter_append_basic (iter,
DBUS_TYPE_UINT32,
&v))
goto nomem;
}
break;
#ifdef DBUS_HAVE_INT64
case G_TYPE_INT64:
dbus_message_iter_append_int64 (iter,
g_value_get_int64 (value));
{
gint64 v = g_value_get_int64 (value);
if (!dbus_message_iter_append_basic (iter,
DBUS_TYPE_INT64,
&v))
goto nomem;
}
break;
case G_TYPE_UINT64:
dbus_message_iter_append_uint64 (iter,
g_value_get_uint64 (value));
{
guint64 v = g_value_get_uint64 (value);
if (!dbus_message_iter_append_basic (iter,
DBUS_TYPE_UINT64,
&v))
goto nomem;
}
break;
#endif
case G_TYPE_FLOAT:
dbus_message_iter_append_double (iter,
g_value_get_float (value));
{
double v = g_value_get_float (value);
if (!dbus_message_iter_append_basic (iter,
DBUS_TYPE_DOUBLE,
&v))
goto nomem;
}
break;
case G_TYPE_DOUBLE:
dbus_message_iter_append_double (iter,
g_value_get_double (value));
{
double v = g_value_get_double (value);
if (!dbus_message_iter_append_basic (iter,
DBUS_TYPE_DOUBLE,
&v))
goto nomem;
}
break;
case G_TYPE_STRING:
/* FIXME, the GValue string may not be valid UTF-8 */
dbus_message_iter_append_string (iter,
g_value_get_string (value));
{
const char *v = g_value_get_string (value);
if (!dbus_message_iter_append_basic (iter,
DBUS_TYPE_STRING,
&v))
goto nomem;
}
break;
default:
/* FIXME: we need to define custom boxed types for arrays
etc. so we can map them transparently / pleasantly */
@ -115,5 +201,9 @@ dbus_gvalue_marshal (DBusMessageIter *iter, GValue *value)
}
return can_convert;
nomem:
g_error ("no memory");
return FALSE;
}

View file

@ -185,19 +185,31 @@ QVariant Message::iterator::marshallBaseType( DBusMessageIter* i )
QVariant ret;
switch (dbus_message_iter_get_arg_type(i)) {
case DBUS_TYPE_INT32:
ret = QVariant( dbus_message_iter_get_int32(i) );
{
dbus_int32_t v;
dbus_message_iter_get_basic (i, &v);
ret = QVariant( v );
}
break;
case DBUS_TYPE_UINT32:
ret = QVariant( dbus_message_iter_get_uint32(i) );
{
dbus_uint32_t v;
dbus_message_iter_get_basic (i, &v);
ret = QVariant( v );
}
break;
case DBUS_TYPE_DOUBLE:
ret = QVariant( dbus_message_iter_get_double(i) );
{
double v;
dbus_message_iter_get_basic (i, &v);
ret = QVariant( v );
}
break;
case DBUS_TYPE_STRING:
{
char *str = dbus_message_iter_get_string(i);
ret = QVariant( QString::fromLatin1(str) );
dbus_free(str);
const char *v;
dbus_message_iter_get_basic (i, &v);
ret = QVariant( v );
}
break;
default:
@ -224,14 +236,16 @@ Message::iterator::fillVar()
switch ( dbus_message_iter_get_array_type( d->iter ) ) {
case DBUS_TYPE_STRING: {
QStringList tempList;
int count;
char** charArray;
dbus_message_iter_get_string_array( d->iter, &charArray, &count );
for ( int i=0; i < count; i++ ) {
tempList.append( QString( charArray[i] ) );
}
DBusMessageIter sub;
dbus_message_iter_recurse (d->iter, &sub);
while (dbus_message_iter_get_arg_type (&sub) != DBUS_TYPE_INVALID)
{
const char *v;
dbus_message_iter_get_basic (&sub, &v);
tempList.append( QString( v ) );
dbus_message_iter_next (&sub);
}
d->var = QVariant( tempList );
dbus_free( charArray );
break;
}
default:
@ -241,6 +255,11 @@ Message::iterator::fillVar()
}
break;
}
#if 0
/* DICT is gone for now, but expected to be reintroduced, or else
* reintroduced as a flag on the introspection data that can
* apply to array of struct of two fields
*/
case DBUS_TYPE_DICT: {
qDebug( "Got a hash!" );
QMap<QString, QVariant> tempMap;
@ -258,6 +277,7 @@ Message::iterator::fillVar()
d->var = QVariant();
break;
}
#endif
default:
qDebug( "not implemented" );
d->var = QVariant();
@ -485,49 +505,51 @@ Message::message() const
Message& Message::operator<<( bool b )
{
dbus_message_append_args( d->msg, DBUS_TYPE_BOOLEAN, b,
const unsigned char byte = b;
dbus_message_append_args( d->msg, DBUS_TYPE_BOOLEAN, &byte,
DBUS_TYPE_INVALID );
}
Message& Message::operator<<( Q_INT8 byte )
{
dbus_message_append_args( d->msg, DBUS_TYPE_BYTE, byte,
dbus_message_append_args( d->msg, DBUS_TYPE_BYTE, &byte,
DBUS_TYPE_INVALID );
}
Message& Message::operator<<( Q_INT32 num )
{
dbus_message_append_args( d->msg, DBUS_TYPE_INT32, num,
dbus_message_append_args( d->msg, DBUS_TYPE_INT32, &num,
DBUS_TYPE_INVALID );
}
Message& Message::operator<<( Q_UINT32 num )
{
dbus_message_append_args( d->msg, DBUS_TYPE_UINT32, num,
dbus_message_append_args( d->msg, DBUS_TYPE_UINT32, &num,
DBUS_TYPE_INVALID );
}
Message& Message::operator<<( Q_INT64 num )
{
dbus_message_append_args( d->msg, DBUS_TYPE_INT64, num,
dbus_message_append_args( d->msg, DBUS_TYPE_INT64, &num,
DBUS_TYPE_INVALID );
}
Message& Message::operator<<( Q_UINT64 num )
{
dbus_message_append_args( d->msg, DBUS_TYPE_UINT64, num,
dbus_message_append_args( d->msg, DBUS_TYPE_UINT64, &num,
DBUS_TYPE_INVALID );
}
Message& Message::operator<<( double num )
{
dbus_message_append_args( d->msg, DBUS_TYPE_DOUBLE, num,
dbus_message_append_args( d->msg, DBUS_TYPE_DOUBLE, &num,
DBUS_TYPE_INVALID );
}
Message& Message::operator<<( const QString& str )
{
dbus_message_append_args( d->msg, DBUS_TYPE_STRING, str.unicode(),
const char *u = str.utf8();
dbus_message_append_args( d->msg, DBUS_TYPE_STRING, &u,
DBUS_TYPE_INVALID );
}

View file

@ -10,7 +10,8 @@ INCLUDES=-I$(top_srcdir) $(DBUS_TEST_CFLAGS)
if DBUS_BUILD_TESTS
TEST_BINARIES=test-service break-loader spawn-test test-segfault test-exit test-sleep-forever
## break-loader removed for now
TEST_BINARIES=test-service spawn-test test-segfault test-exit test-sleep-forever
else
TEST_BINARIES=
endif
@ -28,8 +29,8 @@ test_service_SOURCES= \
test-utils.c \
test-utils.h
break_loader_SOURCES= \
break-loader.c
##break_loader_SOURCES= \
## break-loader.c
spawn_test_SOURCES= \
spawn-test.c
@ -49,7 +50,7 @@ decode_gcov_SOURCES= \
TEST_LIBS=$(DBUS_TEST_LIBS) $(top_builddir)/dbus/libdbus-convenience.la
test_service_LDADD=$(TEST_LIBS)
break_loader_LDADD= $(TEST_LIBS)
## break_loader_LDADD= $(TEST_LIBS)
spawn_test_LDADD=$(TEST_LIBS)
decode_gcov_LDADD=$(TEST_LIBS)

View file

@ -36,7 +36,7 @@
#include <dbus/dbus-string.h>
#include <dbus/dbus-internals.h>
#include <dbus/dbus-test.h>
#include <dbus/dbus-marshal.h>
#include <dbus/dbus-marshal-basic.h>
#undef DBUS_COMPILATION
static DBusString failure_dir;

View file

@ -61,9 +61,9 @@ if test x$MODE = xprofile ; then
if test x$PROFILE_TYPE = x ; then
PROFILE_TYPE=all
fi
$DEBUG $DBUS_TOP_BUILDDIR/test/glib/test-profile $PROFILE_TYPE || die "test-profile failed"
libtool --mode=execute $DEBUG $DBUS_TOP_BUILDDIR/test/glib/test-profile $PROFILE_TYPE || die "test-profile failed"
else
$DEBUG $DBUS_TOP_BUILDDIR/test/glib/test-dbus-glib || die "test-dbus-glib failed"
libtool --mode=execute $DEBUG $DBUS_TOP_BUILDDIR/test/glib/test-dbus-glib || die "test-dbus-glib failed"
fi
## we kill -TERM so gcov data can be written out

View file

@ -62,8 +62,9 @@ main (int argc, char **argv)
int service_list_len;
int i;
guint32 result;
char *str;
const char *v_STRING;
guint32 v_UINT32;
g_type_init ();
loop = g_main_loop_new (NULL, FALSE);
@ -115,12 +116,14 @@ main (int argc, char **argv)
g_strfreev (service_list);
/* Test handling of unknown method */
v_STRING = "blah blah blah blah blah";
v_UINT32 = 10;
call = dbus_g_proxy_begin_call (driver, "ThisMethodDoesNotExist",
DBUS_TYPE_STRING,
"blah blah blah blah blah",
DBUS_TYPE_INT32,
10,
DBUS_TYPE_INVALID);
DBUS_TYPE_STRING,
&v_STRING,
DBUS_TYPE_INT32,
&v_UINT32,
DBUS_TYPE_INVALID);
error = NULL;
if (dbus_g_proxy_end_call (driver, call, &error,
@ -135,17 +138,19 @@ main (int argc, char **argv)
g_error_free (error);
/* Activate a service */
v_STRING = "org.freedesktop.DBus.TestSuiteEchoService";
v_UINT32 = 0;
call = dbus_g_proxy_begin_call (driver, "ActivateService",
DBUS_TYPE_STRING,
"org.freedesktop.DBus.TestSuiteEchoService",
DBUS_TYPE_UINT32,
0,
DBUS_TYPE_INVALID);
DBUS_TYPE_STRING,
&v_STRING,
DBUS_TYPE_UINT32,
&v_UINT32,
DBUS_TYPE_INVALID);
error = NULL;
if (!dbus_g_proxy_end_call (driver, call, &error,
DBUS_TYPE_UINT32, &result,
DBUS_TYPE_INVALID))
DBUS_TYPE_UINT32, &result,
DBUS_TYPE_INVALID))
{
g_printerr ("Failed to complete Activate call: %s\n",
error->message);
@ -156,12 +161,14 @@ main (int argc, char **argv)
g_print ("Activation of echo service = 0x%x\n", result);
/* Activate a service again */
v_STRING = "org.freedesktop.DBus.TestSuiteEchoService";
v_UINT32 = 0;
call = dbus_g_proxy_begin_call (driver, "ActivateService",
DBUS_TYPE_STRING,
"org.freedesktop.DBus.TestSuiteEchoService",
DBUS_TYPE_UINT32,
0,
DBUS_TYPE_INVALID);
DBUS_TYPE_STRING,
&v_STRING,
DBUS_TYPE_UINT32,
&v_UINT32,
DBUS_TYPE_INVALID);
error = NULL;
if (!dbus_g_proxy_end_call (driver, call, &error,
@ -192,15 +199,16 @@ main (int argc, char **argv)
exit (1);
}
v_STRING = "my string hello";
call = dbus_g_proxy_begin_call (proxy, "Echo",
DBUS_TYPE_STRING,
"my string hello",
DBUS_TYPE_INVALID);
DBUS_TYPE_STRING,
&v_STRING,
DBUS_TYPE_INVALID);
error = NULL;
if (!dbus_g_proxy_end_call (proxy, call, &error,
DBUS_TYPE_STRING, &str,
DBUS_TYPE_INVALID))
DBUS_TYPE_STRING, &v_STRING,
DBUS_TYPE_INVALID))
{
g_printerr ("Failed to complete Echo call: %s\n",
error->message);
@ -208,8 +216,7 @@ main (int argc, char **argv)
exit (1);
}
g_print ("String echoed = \"%s\"\n", str);
g_free (str);
g_print ("String echoed = \"%s\"\n", v_STRING);
/* Test oneway call and signal handling */

View file

@ -48,7 +48,7 @@
*/
#define N_CLIENT_THREADS 1
/* It seems like at least 750000 or so iterations reduces the variability to sane levels */
#define N_ITERATIONS 750000
#define N_ITERATIONS 7500
#define N_PROGRESS_UPDATES 20
/* Don't make PAYLOAD_SIZE too huge because it gets used as a static buffer size */
#define PAYLOAD_SIZE 0
@ -103,17 +103,19 @@ static void
send_echo_method_call (DBusConnection *connection)
{
DBusMessage *message;
const char *hello = "Hello World!";
dbus_int32_t i32 = 123456;
message = dbus_message_new_method_call (ECHO_SERVICE,
ECHO_PATH,
ECHO_INTERFACE,
ECHO_PING_METHOD);
dbus_message_append_args (message,
DBUS_TYPE_STRING, "Hello World!",
DBUS_TYPE_INT32, 123456,
DBUS_TYPE_STRING, &hello,
DBUS_TYPE_INT32, &i32,
#if PAYLOAD_SIZE > 0
DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE,
payload, PAYLOAD_SIZE,
&payload, PAYLOAD_SIZE,
#endif
DBUS_TYPE_INVALID);
@ -277,10 +279,6 @@ no_bus_init_server (ServerData *sd)
{
DBusServer *server;
DBusError error;
#ifndef DBUS_DISABLE_ASSERT
g_printerr ("You should probably --disable-asserts before you profile as they have noticeable overhead\n");
#endif
dbus_error_init (&error);
server = dbus_server_listen ("unix:tmpdir="DBUS_TEST_SOCKET_DIR,
@ -511,14 +509,6 @@ with_bus_init_server (ServerData *sd)
g_printerr ("You have to run with_bus mode with the run-test.sh script\n");
exit (1);
}
#ifndef DBUS_DISABLE_ASSERT
g_printerr ("You should probably --disable-asserts before you profile as they have noticeable overhead\n");
#endif
#ifdef DBUS_ENABLE_VERBOSE_MODE
g_printerr ("You should probably --disable-verbose-mode before you profile as verbose has noticeable overhead\n");
#endif
/* Note that we use the standard global bus connection for the
* server, and the clients open their own connections so they can
@ -1111,6 +1101,14 @@ main (int argc, char *argv[])
g_thread_init (NULL);
dbus_g_thread_init ();
#ifndef DBUS_DISABLE_ASSERT
g_printerr ("You should probably --disable-asserts before you profile as they have noticeable overhead\n");
#endif
#if DBUS_ENABLE_VERBOSE_MODE
g_printerr ("You should probably --disable-verbose-mode before you profile as verbose has noticeable overhead\n");
#endif
payload = g_malloc (PAYLOAD_SIZE);
/* The actual size of the DBusMessage on the wire, as of Nov 23 2004,

View file

@ -26,18 +26,18 @@ thread_func (gpointer data)
dbus_message_append_iter_init (message, &iter);
if (!dbus_message_iter_append_int32 (&iter, threadnr))
if (!dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &threadnr))
{
g_print ("thread %d: append threadnr failed\n", threadnr);
}
if (!dbus_message_iter_append_uint32 (&iter, counter))
if (!dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &counter))
{
g_print ("thread %d: append counter (%d) failed\n", threadnr, counter);
}
str = g_strdup_printf ("Thread %d-%d\n", threadnr, counter);
if (!dbus_message_iter_append_string (&iter, str))
if (!dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str))
{
g_print ("thread %d: append string (%s) failed\n", threadnr, str);
}

View file

@ -34,7 +34,8 @@ filter_test_message (DBusConnection *connection,
DBusMessageIter iter;
gint32 threadnr;
guint32 counter;
char *str, *expected_str;
const char *str;
char *expected_str;
GString *counter_str;
int i;
@ -49,7 +50,7 @@ filter_test_message (DBusConnection *connection,
g_print ("First arg not right type\n");
goto out;
}
threadnr = dbus_message_iter_get_int32 (&iter);
dbus_message_iter_get_basic (&iter, &threadnr);
if (threadnr < 0 || threadnr >= N_TEST_THREADS)
{
g_print ("Invalid thread nr\n");
@ -68,7 +69,7 @@ filter_test_message (DBusConnection *connection,
goto out;
}
counter = dbus_message_iter_get_uint32 (&iter);
dbus_message_iter_get_basic (&iter, &counter);
if (counter != data->counters[threadnr])
{
@ -89,7 +90,7 @@ filter_test_message (DBusConnection *connection,
goto out;
}
str = dbus_message_iter_get_string (&iter);
dbus_message_iter_get_basic (&iter, &str);
if (str == NULL)
{
@ -103,7 +104,6 @@ filter_test_message (DBusConnection *connection,
g_print ("Wrong string '%s', expected '%s'\n", str, expected_str);
goto out;
}
g_free (str);
g_free (expected_str);
if (dbus_message_iter_next (&iter))

View file

@ -58,7 +58,7 @@ handle_echo (DBusConnection *connection,
die ("No memory\n");
if (!dbus_message_append_args (reply,
DBUS_TYPE_STRING, s,
DBUS_TYPE_STRING, &s,
DBUS_TYPE_INVALID))
die ("No memory");
@ -67,8 +67,6 @@ handle_echo (DBusConnection *connection,
fprintf (stderr, "Echo service echoed string: \"%s\"\n", s);
dbus_free (s);
dbus_message_unref (reply);
return DBUS_HANDLER_RESULT_HANDLED;
@ -104,6 +102,7 @@ path_message_func (DBusConnection *connection,
{
/* Emit the Foo signal */
DBusMessage *signal;
double v_DOUBLE;
_dbus_verbose ("emitting signal Foo\n");
@ -112,9 +111,10 @@ path_message_func (DBusConnection *connection,
"Foo");
if (signal == NULL)
die ("No memory\n");
v_DOUBLE = 42.6;
if (!dbus_message_append_args (signal,
DBUS_TYPE_DOUBLE, 42.6,
DBUS_TYPE_DOUBLE, &v_DOUBLE,
DBUS_TYPE_INVALID))
die ("No memory");

View file

@ -84,7 +84,7 @@ print_message (DBusMessage *message)
do
{
int type = dbus_message_iter_get_arg_type (&iter);
char *str;
const char *str;
dbus_uint32_t uint32;
dbus_int32_t int32;
double d;
@ -97,32 +97,32 @@ print_message (DBusMessage *message)
switch (type)
{
case DBUS_TYPE_STRING:
str = dbus_message_iter_get_string (&iter);
dbus_message_iter_get_basic (&iter, &str);
printf ("string:%s\n", str);
break;
case DBUS_TYPE_INT32:
int32 = dbus_message_iter_get_int32 (&iter);
dbus_message_iter_get_basic (&iter, &int32);
printf ("int32:%d\n", int32);
break;
case DBUS_TYPE_UINT32:
uint32 = dbus_message_iter_get_uint32 (&iter);
dbus_message_iter_get_basic (&iter, &uint32);
printf ("int32:%u\n", uint32);
break;
case DBUS_TYPE_DOUBLE:
d = dbus_message_iter_get_double (&iter);
dbus_message_iter_get_basic (&iter, &d);
printf ("double:%f\n", d);
break;
case DBUS_TYPE_BYTE:
byte = dbus_message_iter_get_byte (&iter);
dbus_message_iter_get_basic (&iter, &byte);
printf ("byte:%d\n", byte);
break;
case DBUS_TYPE_BOOLEAN:
boolean = dbus_message_iter_get_boolean (&iter);
dbus_message_iter_get_basic (&iter, &boolean);
printf ("boolean:%s\n", boolean ? "true" : "false");
break;

View file

@ -215,33 +215,39 @@ main (int argc, char *argv[])
{
case DBUS_TYPE_BYTE:
byte = strtoul (c, NULL, 0);
dbus_message_iter_append_byte (&iter, byte);
dbus_message_iter_append_basic (&iter, DBUS_TYPE_BYTE, &byte);
break;
case DBUS_TYPE_DOUBLE:
d = strtod (c, NULL);
dbus_message_iter_append_double (&iter, d);
dbus_message_iter_append_basic (&iter, DBUS_TYPE_DOUBLE, &d);
break;
case DBUS_TYPE_INT32:
int32 = strtol (c, NULL, 0);
dbus_message_iter_append_int32 (&iter, int32);
dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &int32);
break;
case DBUS_TYPE_UINT32:
uint32 = strtoul (c, NULL, 0);
dbus_message_iter_append_uint32 (&iter, uint32);
dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &uint32);
break;
case DBUS_TYPE_STRING:
dbus_message_iter_append_string (&iter, c);
dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &c);
break;
case DBUS_TYPE_BOOLEAN:
if (strcmp(c, "true") == 0)
dbus_message_iter_append_boolean (&iter, TRUE);
{
byte = TRUE;
dbus_message_iter_append_basic (&iter, DBUS_TYPE_BOOLEAN, &c);
}
else if (strcmp(c, "false") == 0)
dbus_message_iter_append_boolean (&iter, FALSE);
{
byte = FALSE;
dbus_message_iter_append_basic (&iter, DBUS_TYPE_BOOLEAN, &c);
}
else
{
fprintf (stderr, "%s: Expected \"true\" or \"false\" instead of \"%s\"\n", argv[0], c);