2003-08-18 Havoc Pennington <hp@redhat.com>

* dbus/dbus-hash.c (_dbus_hash_table_insert_two_strings): fix

	* dbus/dbus-message.c (_dbus_message_loader_queue_messages): fix
	dumb bug created earlier (wrong order of args to
	decode_header_data())

	* tools/dbus-send.c: port

	* tools/dbus-print-message.c (print_message): port

        * test/data/*messages: port all messages over

        * dbus/dbus-message-builder.c: support including
	message type

        * bus/driver.c: port over

	* bus/dispatch.c: port over to new stuff

	* dbus/dbus-connection.c (_dbus_connection_new_for_transport):
	rename disconnect signal to "Disconnected"
This commit is contained in:
Havoc Pennington 2003-08-18 22:43:30 +00:00
parent 95717a938b
commit 68a3c593b9
53 changed files with 677 additions and 286 deletions

View file

@ -1,3 +1,27 @@
2003-08-18 Havoc Pennington <hp@redhat.com>
* dbus/dbus-hash.c (_dbus_hash_table_insert_two_strings): fix
* dbus/dbus-message.c (_dbus_message_loader_queue_messages): fix
dumb bug created earlier (wrong order of args to
decode_header_data())
* tools/dbus-send.c: port
* tools/dbus-print-message.c (print_message): port
* test/data/*messages: port all messages over
* dbus/dbus-message-builder.c: support including
message type
* bus/driver.c: port over
* bus/dispatch.c: port over to new stuff
* dbus/dbus-connection.c (_dbus_connection_new_for_transport):
rename disconnect signal to "Disconnected"
2003-08-17 Havoc Pennington <hp@pobox.com>
This doesn't compile yet, but syncing up so I can hack on it from

View file

@ -870,8 +870,9 @@ bus_context_check_security_policy (BusContext *context,
* the hello message to the bus driver
*/
if (recipient == NULL &&
dbus_message_has_interface (message, DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS) &&
dbus_message_has_member (message, "Hello"))
dbus_message_is_method_call (message,
DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS,
"Hello"))
{
_dbus_verbose ("security check allowing %s message\n",
"Hello");

View file

@ -1560,7 +1560,7 @@ bus_transaction_send_error_reply (BusTransaction *transaction,
_dbus_assert (error != NULL);
_DBUS_ASSERT_ERROR_IS_SET (error);
_dbus_verbose ("Sending error reply %s \"%s\"\n",
error->name, error->message);

View file

@ -152,8 +152,9 @@ bus_dispatch (DBusConnection *connection,
*/
if (service_name == NULL)
{
if (dbus_message_has_interface (message, DBUS_INTERFACE_ORG_FREEDESKTOP_LOCAL) &&
dbus_message_has_member (message, "Disconnect"))
if (dbus_message_is_signal (message,
DBUS_INTERFACE_ORG_FREEDESKTOP_LOCAL,
"Disconnected"))
bus_connection_disconnected (connection);
/* DBusConnection also handles some of these automatically, we leave
@ -215,7 +216,7 @@ bus_dispatch (DBusConnection *connection,
* on services that all service owners will get messages to it, not just
* the primary owner.
*/
else if (strcmp (service_name, DBUS_SERVICE_BROADCAST) == 0) /* spam! */
else if (strcmp (service_name, DBUS_SERVICE_ORG_FREEDESKTOP_BROADCAST) == 0) /* spam! */
{
if (!bus_dispatch_broadcast_message (transaction, connection, message, &error))
goto out;
@ -416,6 +417,22 @@ pop_message_waiting_for_memory (DBusConnection *connection)
return dbus_connection_pop_message (connection);
}
static void
warn_unexpected (DBusConnection *connection,
DBusMessage *message,
const char *expected)
{
_dbus_warn ("Received message interface \"%s\" member \"%s\" error name \"%s\" on %p, expecting %s\n",
dbus_message_get_interface (message) ?
dbus_message_get_interface (message) : "(unset)",
dbus_message_get_member (message) ?
dbus_message_get_member (message) : "(unset)",
dbus_message_get_error_name (message) ?
dbus_message_get_error_name (message) : "(unset)",
connection,
expected);
}
typedef struct
{
const char *expected_service_name;
@ -439,14 +456,15 @@ check_service_deleted_foreach (DBusConnection *connection,
if (message == NULL)
{
_dbus_warn ("Did not receive a message on %p, expecting %s\n",
connection, DBUS_MESSAGE_SERVICE_DELETED);
connection, "ServiceDeleted");
goto out;
}
else if (!dbus_message_has_name (message, DBUS_MESSAGE_SERVICE_DELETED))
else if (!dbus_message_is_signal (message,
DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS,
"ServiceDeleted"))
{
_dbus_warn ("Received message %s on %p, expecting %s\n",
dbus_message_get_name (message),
connection, DBUS_MESSAGE_SERVICE_DELETED);
warn_unexpected (connection, message, "ServiceDeleted");
goto out;
}
else
@ -569,8 +587,8 @@ check_no_messages_foreach (DBusConnection *connection,
message = pop_message_waiting_for_memory (connection);
if (message != NULL)
{
_dbus_warn ("Received message %s on %p, expecting no messages\n",
dbus_message_get_name (message), connection);
warn_unexpected (connection, message, "no messages");
d->failed = TRUE;
}
@ -606,14 +624,14 @@ check_service_created_foreach (DBusConnection *connection,
if (message == NULL)
{
_dbus_warn ("Did not receive a message on %p, expecting %s\n",
connection, DBUS_MESSAGE_SERVICE_CREATED);
connection, "ServiceCreated");
goto out;
}
else if (!dbus_message_has_name (message, DBUS_MESSAGE_SERVICE_CREATED))
else if (!dbus_message_is_signal (message,
DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS,
"ServiceCreated"))
{
_dbus_warn ("Received message %s on %p, expecting %s\n",
dbus_message_get_name (message),
connection, DBUS_MESSAGE_SERVICE_CREATED);
warn_unexpected (connection, message, "ServiceCreated");
goto out;
}
else
@ -689,7 +707,8 @@ check_hello_message (BusContext *context,
acquired = NULL;
message = NULL;
message = dbus_message_new_method_call (DBUS_MESSAGE_HELLO,
message = dbus_message_new_method_call (DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS,
"Hello",
DBUS_SERVICE_ORG_FREEDESKTOP_DBUS);
if (message == NULL)
@ -725,12 +744,12 @@ check_hello_message (BusContext *context,
if (message == NULL)
{
_dbus_warn ("Did not receive a reply to %s %d on %p\n",
DBUS_MESSAGE_HELLO, serial, connection);
"Hello", serial, connection);
goto out;
}
_dbus_verbose ("Received %s on %p\n",
dbus_message_get_name (message), connection);
_dbus_verbose ("Received message %p on %p\n",
message, connection);
if (!dbus_message_has_sender (message, DBUS_SERVICE_ORG_FREEDESKTOP_DBUS))
{
@ -742,15 +761,15 @@ check_hello_message (BusContext *context,
if (dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_ERROR)
{
if (dbus_message_has_name (message,
if (dbus_message_is_error (message,
DBUS_ERROR_NO_MEMORY))
{
; /* good, this is a valid response */
}
else
{
_dbus_warn ("Did not expect error %s\n",
dbus_message_get_name (message));
warn_unexpected (connection, message, "not this error");
goto out;
}
}
@ -758,15 +777,14 @@ check_hello_message (BusContext *context,
{
CheckServiceCreatedData scd;
if (dbus_message_has_name (message,
DBUS_MESSAGE_HELLO))
if (dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_METHOD_RETURN)
{
; /* good, expected */
}
else
{
_dbus_warn ("Did not expect reply %s\n",
dbus_message_get_name (message));
warn_unexpected (connection, message, "method return for Hello");
goto out;
}
@ -810,7 +828,7 @@ check_hello_message (BusContext *context,
if (message == NULL)
{
_dbus_warn ("Expecting %s, got nothing\n",
DBUS_MESSAGE_SERVICE_ACQUIRED);
"ServiceAcquired");
goto out;
}
@ -921,7 +939,8 @@ check_nonexistent_service_activation (BusContext *context,
dbus_error_init (&error);
message = dbus_message_new_method_call (DBUS_MESSAGE_ACTIVATE_SERVICE,
message = dbus_message_new_method_call (DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS,
"ActivateService",
DBUS_SERVICE_ORG_FREEDESKTOP_DBUS);
if (message == NULL)
@ -961,12 +980,12 @@ check_nonexistent_service_activation (BusContext *context,
if (message == NULL)
{
_dbus_warn ("Did not receive a reply to %s %d on %p\n",
DBUS_MESSAGE_ACTIVATE_SERVICE, serial, connection);
"ActivateService", serial, connection);
goto out;
}
_dbus_verbose ("Received %s on %p\n",
dbus_message_get_name (message), connection);
_dbus_verbose ("Received message %p on %p\n",
message, connection);
if (dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_ERROR)
{
@ -978,20 +997,19 @@ check_nonexistent_service_activation (BusContext *context,
goto out;
}
if (dbus_message_has_name (message,
if (dbus_message_is_error (message,
DBUS_ERROR_NO_MEMORY))
{
; /* good, this is a valid response */
}
else if (dbus_message_has_name (message,
else if (dbus_message_is_error (message,
DBUS_ERROR_ACTIVATE_SERVICE_NOT_FOUND))
{
; /* good, this is expected also */
}
else
{
_dbus_warn ("Did not expect error %s\n",
dbus_message_get_name (message));
warn_unexpected (connection, message, "not this error");
goto out;
}
}
@ -1030,7 +1048,9 @@ check_base_service_activated (BusContext *context,
message = initial_message;
dbus_message_ref (message);
if (dbus_message_has_name (message, DBUS_MESSAGE_SERVICE_CREATED))
if (dbus_message_is_signal (message,
DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS,
"ServiceCreated"))
{
char *service_name;
CheckServiceCreatedData scd;
@ -1049,7 +1069,7 @@ check_base_service_activated (BusContext *context,
else
{
_dbus_warn ("Message %s doesn't have a service name: %s\n",
dbus_message_get_name (message),
"ServiceCreated",
error.message);
dbus_error_free (&error);
goto out;
@ -1077,8 +1097,8 @@ check_base_service_activated (BusContext *context,
}
else
{
_dbus_warn ("Expected to get base service ServiceCreated, instead got %s\n",
dbus_message_get_name (message));
warn_unexpected (connection, message, "ServiceCreated for base service");
goto out;
}
@ -1119,7 +1139,9 @@ check_service_activated (BusContext *context,
message = initial_message;
dbus_message_ref (message);
if (dbus_message_has_name (message, DBUS_MESSAGE_SERVICE_CREATED))
if (dbus_message_is_signal (message,
DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS,
"ServiceCreated"))
{
char *service_name;
CheckServiceCreatedData scd;
@ -1138,7 +1160,7 @@ check_service_activated (BusContext *context,
else
{
_dbus_warn ("Message %s doesn't have a service name: %s\n",
dbus_message_get_name (message),
"ServiceCreated",
error.message);
dbus_error_free (&error);
goto out;
@ -1169,22 +1191,21 @@ check_service_activated (BusContext *context,
if (message == NULL)
{
_dbus_warn ("Expected a reply to %s, got nothing\n",
DBUS_MESSAGE_ACTIVATE_SERVICE);
"ActivateService");
goto out;
}
}
else
{
_dbus_warn ("Expected to get service %s ServiceCreated, instead got %s\n",
activated_name, dbus_message_get_name (message));
warn_unexpected (connection, message, "ServiceCreated for the activated name");
goto out;
}
if (!dbus_message_has_name (message, DBUS_MESSAGE_ACTIVATE_SERVICE))
if (dbus_message_get_type (message) != DBUS_MESSAGE_TYPE_METHOD_RETURN)
{
_dbus_warn ("Expected reply to %s, got message %s instead\n",
DBUS_MESSAGE_ACTIVATE_SERVICE,
dbus_message_get_name (message));
warn_unexpected (connection, message, "reply to ActivateService");
goto out;
}
@ -1196,7 +1217,7 @@ check_service_activated (BusContext *context,
if (!dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY))
{
_dbus_warn ("Did not have activation result first argument to %s: %s\n",
DBUS_MESSAGE_ACTIVATE_SERVICE, error.message);
"ActivateService", error.message);
dbus_error_free (&error);
goto out;
}
@ -1302,7 +1323,8 @@ check_send_exit_to_service (BusContext *context,
retval = FALSE;
/* Kill off the test service by sending it a quit message */
message = dbus_message_new_method_call ("org.freedesktop.DBus.TestSuiteExit",
message = dbus_message_new_method_call ("org.freedesktop.TestSuite",
"Exit",
service_name);
if (message == NULL)
@ -1359,21 +1381,16 @@ check_send_exit_to_service (BusContext *context,
message = pop_message_waiting_for_memory (connection);
_dbus_assert (message != NULL);
if (dbus_message_get_type (message) != DBUS_MESSAGE_TYPE_ERROR)
if (!dbus_message_is_error (message,
DBUS_ERROR_NO_MEMORY))
{
_dbus_warn ("expecting an error reply to asking test service to exit, got %s\n",
dbus_message_get_name (message));
goto out;
}
else if (!dbus_message_has_name (message, DBUS_ERROR_NO_MEMORY))
{
_dbus_warn ("not expecting error %s when asking test service to exit\n",
dbus_message_get_name (message));
warn_unexpected (connection, message,
"a no memory error from asking test service to exit");
goto out;
}
_dbus_verbose ("Got error %s when asking test service to exit\n",
dbus_message_get_name (message));
dbus_message_get_error_name (message));
/* Do this again; we still need the service to exit... */
if (!check_send_exit_to_service (context, connection,
@ -1419,8 +1436,8 @@ check_got_error (BusContext *context,
if (dbus_message_get_type (message) != DBUS_MESSAGE_TYPE_ERROR)
{
_dbus_warn ("Expected an error, got %s\n",
dbus_message_get_name (message));
warn_unexpected (connection, message, "an error");
goto out;
}
@ -1430,7 +1447,7 @@ check_got_error (BusContext *context,
error_name = first_error_name;
while (error_name != NULL)
{
if (dbus_message_has_name (message, error_name))
if (dbus_message_is_error (message, error_name))
{
error_found = TRUE;
break;
@ -1443,7 +1460,7 @@ check_got_error (BusContext *context,
{
_dbus_warn ("Expected error %s or other, got %s instead\n",
first_error_name,
dbus_message_get_name (message));
dbus_message_get_error_name (message));
goto out;
}
@ -1475,7 +1492,8 @@ check_existent_service_activation (BusContext *context,
dbus_error_init (&error);
message = dbus_message_new_method_call (DBUS_MESSAGE_ACTIVATE_SERVICE,
message = dbus_message_new_method_call (DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS,
"ActivateService",
DBUS_SERVICE_ORG_FREEDESKTOP_DBUS);
if (message == NULL)
@ -1520,13 +1538,12 @@ check_existent_service_activation (BusContext *context,
if (message == NULL)
{
_dbus_warn ("Did not receive any messages after %s %d on %p\n",
DBUS_MESSAGE_ACTIVATE_SERVICE, serial, connection);
"ActivateService", serial, connection);
goto out;
}
_dbus_verbose ("Received %s on %p after sending %s\n",
dbus_message_get_name (message), connection,
DBUS_MESSAGE_ACTIVATE_SERVICE);
_dbus_verbose ("Received message %p on %p after sending %s\n",
message, connection, "ActivateService");
if (dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_ERROR)
{
@ -1538,12 +1555,12 @@ check_existent_service_activation (BusContext *context,
goto out;
}
if (dbus_message_has_name (message,
if (dbus_message_is_error (message,
DBUS_ERROR_NO_MEMORY))
{
; /* good, this is a valid response */
}
else if (dbus_message_has_name (message,
else if (dbus_message_is_error (message,
DBUS_ERROR_SPAWN_CHILD_EXITED))
{
; /* good, this is expected also */
@ -1551,7 +1568,7 @@ check_existent_service_activation (BusContext *context,
else
{
_dbus_warn ("Did not expect error %s\n",
dbus_message_get_name (message));
dbus_message_get_error_name (message));
goto out;
}
}
@ -1577,7 +1594,9 @@ check_existent_service_activation (BusContext *context,
goto out;
}
got_service_deleted = dbus_message_has_name (message, DBUS_MESSAGE_SERVICE_DELETED);
got_service_deleted = dbus_message_is_signal (message,
DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS,
"ServiceDeleted");
got_error = dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_ERROR;
dbus_connection_return_message (connection, message);
@ -1683,7 +1702,8 @@ check_segfault_service_activation (BusContext *context,
dbus_error_init (&error);
message = dbus_message_new_method_call (DBUS_MESSAGE_ACTIVATE_SERVICE,
message = dbus_message_new_method_call (DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS,
"ActivateService",
DBUS_SERVICE_ORG_FREEDESKTOP_DBUS);
if (message == NULL)
@ -1724,12 +1744,12 @@ check_segfault_service_activation (BusContext *context,
if (message == NULL)
{
_dbus_warn ("Did not receive a reply to %s %d on %p\n",
DBUS_MESSAGE_ACTIVATE_SERVICE, serial, connection);
"ActivateService", serial, connection);
goto out;
}
_dbus_verbose ("Received %s on %p\n",
dbus_message_get_name (message), connection);
_dbus_verbose ("Received message %p on %p\n",
message, connection);
if (dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_ERROR)
{
@ -1741,20 +1761,20 @@ check_segfault_service_activation (BusContext *context,
goto out;
}
if (dbus_message_has_name (message,
DBUS_ERROR_NO_MEMORY))
if (dbus_message_is_error (message,
DBUS_ERROR_NO_MEMORY))
{
; /* good, this is a valid response */
}
else if (dbus_message_has_name (message,
DBUS_ERROR_SPAWN_CHILD_SIGNALED))
else if (dbus_message_is_error (message,
DBUS_ERROR_SPAWN_CHILD_SIGNALED))
{
; /* good, this is expected also */
}
else
{
_dbus_warn ("Did not expect error %s\n",
dbus_message_get_name (message));
warn_unexpected (connection, message, "not this error");
goto out;
}
}

View file

@ -49,7 +49,8 @@ bus_driver_send_service_deleted (const char *service_name,
_dbus_verbose ("sending service deleted: %s\n", service_name);
message = dbus_message_new_signal (DBUS_MESSAGE_SERVICE_DELETED);
message = dbus_message_new_signal (DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS,
"ServiceDeleted");
if (message == NULL)
{
@ -57,7 +58,7 @@ bus_driver_send_service_deleted (const char *service_name,
return FALSE;
}
if (!dbus_message_set_sender (message, DBUS_SERVICE_DBUS) ||
if (!dbus_message_set_sender (message, DBUS_SERVICE_ORG_FREEDESKTOP_DBUS) ||
!dbus_message_append_args (message,
DBUS_TYPE_STRING, service_name,
DBUS_TYPE_INVALID))
@ -83,7 +84,8 @@ bus_driver_send_service_created (const char *service_name,
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
message = dbus_message_new_signal (DBUS_MESSAGE_SERVICE_CREATED);
message = dbus_message_new_signal (DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS,
"ServiceCreated");
if (message == NULL)
{
@ -91,7 +93,7 @@ bus_driver_send_service_created (const char *service_name,
return FALSE;
}
if (!dbus_message_set_sender (message, DBUS_SERVICE_DBUS))
if (!dbus_message_set_sender (message, DBUS_SERVICE_ORG_FREEDESKTOP_DBUS))
{
dbus_message_unref (message);
BUS_SET_OOM (error);
@ -123,7 +125,8 @@ bus_driver_send_service_lost (DBusConnection *connection,
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
message = dbus_message_new_signal (DBUS_MESSAGE_SERVICE_LOST);
message = dbus_message_new_signal (DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS,
"ServiceLost");
if (message == NULL)
{
@ -164,7 +167,8 @@ bus_driver_send_service_acquired (DBusConnection *connection,
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
message = dbus_message_new_signal (DBUS_MESSAGE_SERVICE_ACQUIRED);
message = dbus_message_new_signal (DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS,
"ServiceAcquired");
if (message == NULL)
{
@ -604,11 +608,11 @@ struct
DBusMessage *message,
DBusError *error);
} message_handlers[] = {
{ DBUS_MESSAGE_ACQUIRE_SERVICE, bus_driver_handle_acquire_service },
{ DBUS_MESSAGE_ACTIVATE_SERVICE, bus_driver_handle_activate_service },
{ DBUS_MESSAGE_HELLO, bus_driver_handle_hello },
{ DBUS_MESSAGE_SERVICE_EXISTS, bus_driver_handle_service_exists },
{ DBUS_MESSAGE_LIST_SERVICES, bus_driver_handle_list_services }
{ "AcquireService", bus_driver_handle_acquire_service },
{ "ActivateService", bus_driver_handle_activate_service },
{ "Hello", bus_driver_handle_hello },
{ "ServiceExists", bus_driver_handle_service_exists },
{ "ListServices", bus_driver_handle_list_services }
};
dbus_bool_t
@ -621,15 +625,32 @@ bus_driver_handle_message (DBusConnection *connection,
int i;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
_dbus_verbose ("Driver got a message: %s\n",
dbus_message_get_name (message));
name = dbus_message_get_name (message);
sender = dbus_message_get_sender (message);
if (dbus_message_get_type (message) != DBUS_MESSAGE_TYPE_METHOD_CALL)
{
_dbus_verbose ("Driver got a non-method-call message, ignoring\n");
return TRUE; /* we just ignore this */
}
_dbus_assert (dbus_message_get_interface (message) != NULL);
_dbus_assert (dbus_message_get_member (message) != NULL);
name = dbus_message_get_member (message);
sender = dbus_message_get_sender (message);
if (strcmp (dbus_message_get_interface (message),
DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS) != 0)
{
_dbus_verbose ("Driver got message to unknown interface \"%s\"\n",
dbus_message_get_interface (message));
goto unknown;
}
_dbus_verbose ("Driver got a method call: %s\n",
dbus_message_get_member (message));
/* security checks should have kept this from getting here */
_dbus_assert (sender != NULL || strcmp (name, DBUS_MESSAGE_HELLO) == 0);
_dbus_assert (sender != NULL || strcmp (name, "Hello") == 0);
if (dbus_message_get_reply_serial (message) == 0)
{
@ -660,11 +681,13 @@ bus_driver_handle_message (DBusConnection *connection,
++i;
}
_dbus_verbose ("No driver handler for %s\n", name);
unknown:
_dbus_verbose ("No driver handler for message \"%s\"\n",
name);
dbus_set_error (error, DBUS_ERROR_UNKNOWN_METHOD,
"%s does not understand message %s",
DBUS_SERVICE_DBUS, name);
DBUS_SERVICE_ORG_FREEDESKTOP_DBUS, name);
return FALSE;
}

View file

@ -801,8 +801,9 @@ bus_client_policy_check_can_send (BusClientPolicy *policy,
if (rule->d.send.interface != NULL)
{
if (!dbus_message_has_interface (message,
rule->d.send.interface))
if (dbus_message_get_interface (message) == NULL ||
strcmp (dbus_message_get_interface (message),
rule->d.send.interface) != 0)
{
_dbus_verbose (" (policy) skipping rule for different interface\n");
continue;
@ -810,8 +811,9 @@ bus_client_policy_check_can_send (BusClientPolicy *policy,
}
else if (rule->d.send.member != NULL)
{
if (!dbus_message_has_member (message,
rule->d.send.member))
if (dbus_message_get_member (message) == NULL ||
strcmp (dbus_message_get_member (message),
rule->d.send.member) != 0)
{
_dbus_verbose (" (policy) skipping rule for different member\n");
continue;
@ -819,8 +821,9 @@ bus_client_policy_check_can_send (BusClientPolicy *policy,
}
else if (rule->d.send.error != NULL)
{
if (!dbus_message_has_error_name (message,
rule->d.send.error))
if (dbus_message_get_error_name (message) == NULL ||
strcmp (dbus_message_get_error_name (message),
rule->d.send.error) != 0)
{
_dbus_verbose (" (policy) skipping rule for different error name\n");
continue;
@ -914,8 +917,9 @@ bus_client_policy_check_can_receive (BusClientPolicy *policy,
if (rule->d.receive.interface != NULL)
{
if (!dbus_message_has_interface (message,
rule->d.receive.interface))
if (dbus_message_get_interface (message) == NULL ||
strcmp (dbus_message_get_interface (message),
rule->d.receive.interface) != 0)
{
_dbus_verbose (" (policy) skipping rule for different interface\n");
continue;
@ -923,8 +927,9 @@ bus_client_policy_check_can_receive (BusClientPolicy *policy,
}
else if (rule->d.receive.member != NULL)
{
if (!dbus_message_has_member (message,
rule->d.receive.member))
if (dbus_message_get_member (message) == NULL ||
strcmp (dbus_message_get_member (message),
rule->d.receive.member) != 0)
{
_dbus_verbose (" (policy) skipping rule for different member\n");
continue;
@ -932,8 +937,9 @@ bus_client_policy_check_can_receive (BusClientPolicy *policy,
}
else if (rule->d.receive.error != NULL)
{
if (!dbus_message_has_error_name (message,
rule->d.receive.error))
if (dbus_message_get_error_name (message) == NULL ||
strcmp (dbus_message_get_error_name (message),
rule->d.receive.error) != 0)
{
_dbus_verbose (" (policy) skipping rule for different error name\n");
continue;

View file

@ -107,8 +107,9 @@ client_disconnect_handler (DBusMessageHandler *handler,
DBusMessage *message,
void *user_data)
{
if (!dbus_message_has_name (message,
DBUS_MESSAGE_LOCAL_DISCONNECT))
if (!dbus_message_is_signal (message,
DBUS_INTERFACE_ORG_FREEDESKTOP_LOCAL,
"Disconnected"))
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
_dbus_verbose ("Removing client %p in disconnect handler\n",

View file

@ -826,7 +826,7 @@ _dbus_connection_new_for_transport (DBusTransport *transport)
goto error;
disconnect_message = dbus_message_new_signal (DBUS_INTERFACE_ORG_FREEDESKTOP_LOCAL,
"Disconnect");
"Disconnected");
if (disconnect_message == NULL)
goto error;

View file

@ -1423,17 +1423,24 @@ _dbus_hash_table_insert_two_strings (DBusHashTable *table,
char *key,
void *value)
{
DBusPreallocatedHash *preallocated;
_dbus_assert (table->key_type == DBUS_HASH_TWO_STRINGS);
preallocated = _dbus_hash_table_preallocate_entry (table);
if (preallocated == NULL)
return FALSE;
_dbus_hash_table_insert_string_preallocated (table, preallocated,
key, value);
DBusHashEntry *entry;
_dbus_assert (table->key_type == DBUS_HASH_TWO_STRINGS);
entry = (* table->find_function) (table, key, TRUE, NULL, NULL);
if (entry == NULL)
return FALSE; /* no memory */
if (table->free_key_function && entry->key != key)
(* table->free_key_function) (entry->key);
if (table->free_value_function && entry->value != value)
(* table->free_value_function) (entry->value);
entry->key = key;
entry->value = value;
return TRUE;
}
@ -1811,8 +1818,8 @@ _dbus_hash_test (void)
if (value == NULL)
goto out;
if (!_dbus_hash_table_insert_string (table4,
key, value))
if (!_dbus_hash_table_insert_two_strings (table4,
key, value))
goto out;
_dbus_assert (count_entries (table1) == i + 1);
@ -1832,9 +1839,9 @@ _dbus_hash_test (void)
_dbus_assert (value != NULL);
_dbus_assert (strcmp (value, keys[i]) == 0);
value = _dbus_hash_table_lookup_ulong (table4, i);
value = _dbus_hash_table_lookup_two_strings (table4, keys[i]);
_dbus_assert (value != NULL);
_dbus_assert (strcmp (value, keys[i]) == 0);
_dbus_assert (strcmp (value, "Value!") == 0);
++i;
}

View file

@ -265,6 +265,29 @@ append_saved_length (DBusString *dest,
return TRUE;
}
static int
message_type_from_string (const DBusString *str,
int start)
{
const char *s;
s = _dbus_string_get_const_data_len (str, start,
_dbus_string_get_length (str) - start);
if (strncmp (s, "method_call", strlen ("method_call")) == 0)
return DBUS_MESSAGE_TYPE_METHOD_CALL;
else if (strncmp (s, "method_return", strlen ("method_return")) == 0)
return DBUS_MESSAGE_TYPE_METHOD_RETURN;
else if (strncmp (s, "signal", strlen ("signal")) == 0)
return DBUS_MESSAGE_TYPE_SIGNAL;
else if (strncmp (s, "error", strlen ("error")) == 0)
return DBUS_MESSAGE_TYPE_ERROR;
else if (strncmp (s, "invalid", strlen ("invalid")) == 0)
return DBUS_MESSAGE_TYPE_INVALID;
else
return -1;
}
/**
* Reads the given filename, which should be in "message description
* language" (look at some examples), and builds up the message data
@ -274,7 +297,7 @@ append_saved_length (DBusString *dest,
*
* The file format is:
* @code
* VALID_HEADER normal header; byte order, padding, header len, body len, serial
* VALID_HEADER <type> normal header; byte order, type, padding, header len, body len, serial
* BIG_ENDIAN switch to big endian
* LITTLE_ENDIAN switch to little endian
* OPPOSITE_ENDIAN switch to opposite endian
@ -386,6 +409,13 @@ _dbus_message_data_load (DBusString *dest,
{
int i;
DBusString name;
int message_type;
if (_dbus_string_get_length (&line) < strlen ("VALID_HEADER "))
{
_dbus_warn ("no args to VALID_HEADER\n");
goto parse_failed;
}
if (!_dbus_string_append_byte (dest, endian))
{
@ -393,7 +423,15 @@ _dbus_message_data_load (DBusString *dest,
goto parse_failed;
}
if (!_dbus_string_append_byte (dest, DBUS_MESSAGE_TYPE_METHOD_CALL))
message_type = message_type_from_string (&line,
strlen ("VALID_HEADER "));
if (message_type < 0)
{
_dbus_warn ("VALID_HEADER not followed by space then known message type\n");
goto parse_failed;
}
if (!_dbus_string_append_byte (dest, message_type))
{
_dbus_warn ("could not append message type\n");
goto parse_failed;

View file

@ -4049,55 +4049,115 @@ dbus_message_get_sender (DBusMessage *message)
return get_string_field (message, FIELD_SENDER, NULL);
}
static dbus_bool_t
_dbus_message_has_type_interface_member (DBusMessage *message,
int type,
const char *interface,
const char *method)
{
const char *n;
_dbus_assert (message != NULL);
_dbus_assert (interface != NULL);
_dbus_assert (method != NULL);
if (dbus_message_get_type (message) != type)
return FALSE;
/* Optimize by checking the short method name first
* instead of the longer interface name
*/
n = dbus_message_get_member (message);
if (n && strcmp (n, method) == 0)
{
n = dbus_message_get_interface (message);
if (n && strcmp (n, interface) == 0)
return TRUE;
}
return FALSE;
}
/**
* Checks whether the message has the given interface field. If the
* message has no interface field or has a different one, returns
* #FALSE.
* Checks whether the message is a method call with the given
* interface and member fields. If the message is not
* #DBUS_MESSAGE_TYPE_METHOD_CALL, or has a different interface or member field,
* returns #FALSE.
*
* @param message the message
* @param interface the name to check (must not be #NULL)
* @param method the name to check (must not be #NULL)
*
* @returns #TRUE if the message has the given name
* @returns #TRUE if the message is the specified method call
*/
dbus_bool_t
dbus_message_has_interface (DBusMessage *message,
const char *interface)
dbus_message_is_method_call (DBusMessage *message,
const char *interface,
const char *method)
{
const char *n;
_dbus_return_val_if_fail (message != NULL, FALSE);
_dbus_return_val_if_fail (interface != NULL, FALSE);
n = dbus_message_get_interface (message);
_dbus_return_val_if_fail (method != NULL, FALSE);
if (n && strcmp (n, interface) == 0)
return TRUE;
else
return FALSE;
return _dbus_message_has_type_interface_member (message,
DBUS_MESSAGE_TYPE_METHOD_CALL,
interface, method);
}
/**
* Checks whether the message has the given member field. If the
* message has no member field or has a different one, returns #FALSE.
* Checks whether the message is a signal with the given
* interface and member fields. If the message is not
* #DBUS_MESSAGE_TYPE_SIGNAL, or has a different interface or member field,
* returns #FALSE.
*
* @param message the message
* @param member the name to check (must not be #NULL)
* @param interface the name to check (must not be #NULL)
* @param signal_name the name to check (must not be #NULL)
*
* @returns #TRUE if the message has the given name
* @returns #TRUE if the message is the specified signal
*/
dbus_bool_t
dbus_message_has_member (DBusMessage *message,
const char *member)
dbus_message_is_signal (DBusMessage *message,
const char *interface,
const char *signal_name)
{
_dbus_return_val_if_fail (message != NULL, FALSE);
_dbus_return_val_if_fail (interface != NULL, FALSE);
_dbus_return_val_if_fail (signal_name != NULL, FALSE);
return _dbus_message_has_type_interface_member (message,
DBUS_MESSAGE_TYPE_SIGNAL,
interface, signal_name);
}
/**
* Checks whether the message is an error reply with the given error
* name. If the message is not #DBUS_MESSAGE_TYPE_ERROR, or has a
* different name, returns #FALSE.
*
* @param message the message
* @param error_name the name to check (must not be #NULL)
*
* @returns #TRUE if the message is the specified error
*/
dbus_bool_t
dbus_message_is_error (DBusMessage *message,
const char *error_name)
{
const char *n;
_dbus_return_val_if_fail (message != NULL, FALSE);
_dbus_return_val_if_fail (member != NULL, FALSE);
_dbus_return_val_if_fail (message != NULL, FALSE);
_dbus_return_val_if_fail (error_name != NULL, FALSE);
if (dbus_message_get_type (message) != DBUS_MESSAGE_TYPE_ERROR)
return FALSE;
n = dbus_message_get_member (message);
if (n && strcmp (n, member) == 0)
if (n && strcmp (n, error_name) == 0)
return TRUE;
else
return FALSE;
@ -4507,7 +4567,10 @@ decode_header_data (const DBusString *data,
int type;
if (header_len < 16)
return FALSE;
{
_dbus_verbose ("Header length %d is too short\n", header_len);
return FALSE;
}
i = 0;
while (i < FIELD_LAST)
@ -4532,7 +4595,10 @@ decode_header_data (const DBusString *data,
pos = _DBUS_ALIGN_VALUE (pos, 4);
if ((pos + 4) > header_len)
return FALSE;
{
_dbus_verbose ("not enough space remains in header for header field value\n");
return FALSE;
}
field =_dbus_string_get_const_data_len (data, pos, 4);
pos += 4;
@ -4809,8 +4875,9 @@ _dbus_message_loader_queue_messages (DBusMessageLoader *loader)
#if 0
_dbus_verbose_bytes_of_string (&loader->data, 0, header_len + body_len);
#endif
if (!decode_header_data (&loader->data, message_type,
if (!decode_header_data (&loader->data,
header_len, byte_order,
message_type,
fields, &header_padding))
{
_dbus_verbose ("Header was invalid\n");
@ -5919,10 +5986,11 @@ process_test_subdir (const DBusString *test_base_dir,
printf (" %s\n",
_dbus_string_get_const_data (&filename));
_dbus_verbose (" expecting %s\n",
_dbus_verbose (" expecting %s for %s\n",
validity == _DBUS_MESSAGE_VALID ? "valid" :
(validity == _DBUS_MESSAGE_INVALID ? "invalid" :
(validity == _DBUS_MESSAGE_INCOMPLETE ? "incomplete" : "unknown")));
(validity == _DBUS_MESSAGE_INCOMPLETE ? "incomplete" : "unknown")),
_dbus_string_get_const_data (&filename));
if (! (*function) (&full_path, is_raw, validity, user_data))
{
@ -6245,8 +6313,8 @@ _dbus_message_test (const char *test_data_dir)
"TestMethod",
"org.freedesktop.DBus.TestService");
_dbus_assert (dbus_message_has_destination (message, "org.freedesktop.DBus.TestService"));
_dbus_assert (dbus_message_has_interface (message, "Foo.TestInterface"));
_dbus_assert (dbus_message_has_member (message, "TestMethod"));
_dbus_assert (dbus_message_is_method_call (message, "Foo.TestInterface",
"TestMethod"));
_dbus_message_set_serial (message, 1234);
dbus_message_set_sender (message, "org.foo.bar");
_dbus_assert (dbus_message_has_sender (message, "org.foo.bar"));

View file

@ -91,12 +91,14 @@ const char* dbus_message_get_sender (DBusMessage *message);
void dbus_message_set_no_reply (DBusMessage *message,
dbus_bool_t no_reply);
dbus_bool_t dbus_message_get_no_reply (DBusMessage *message);
dbus_bool_t dbus_message_has_interface (DBusMessage *message,
const char *interface);
dbus_bool_t dbus_message_has_member (DBusMessage *message,
const char *member);
dbus_bool_t dbus_message_has_error_name (DBusMessage *message,
const char *name);
dbus_bool_t dbus_message_is_method_call (DBusMessage *message,
const char *interface,
const char *method);
dbus_bool_t dbus_message_is_signal (DBusMessage *message,
const char *interface,
const char *signal_name);
dbus_bool_t dbus_message_is_error (DBusMessage *message,
const char *error_name);
dbus_bool_t dbus_message_has_destination (DBusMessage *message,
const char *service);
dbus_bool_t dbus_message_has_sender (DBusMessage *message,

View file

@ -106,20 +106,6 @@ extern "C" {
* allowed to specify this interface).
*/
#define DBUS_INTERFACE_ORG_FREEDESKTOP_LOCAL "org.freedesktop.Local"
#if 0
/* these are a bad idea, FIXME */
#define DBUS_METHOD_ORG_FREEDESKTOP_DBUS_ACTIVATE_SERVICE "ActivateService"
#define DBUS_METHOD_ORG_FREEDESKTOP_DBUS_SERVICE_EXISTS "ServiceExists"
#define DBUS_METHOD_ORG_FREEDESKTOP_DBUS_HELLO "Hello"
#define DBUS_METHOD_ORG_FREEDESKTOP_DBUS_LIST_SERVICES "ListServices"
#define DBUS_METHOD_ORG_FREEDESKTOP_DBUS_ACQUIRE_SERVICE "AcquireService"
#define DBUS_SIGNAL_ORG_FREEDESKTOP_DBUS_SERVICE_ACQUIRED "ServiceAcquired"
#define DBUS_SIGNAL_ORG_FREEDESKTOP_DBUS_SERVICE_CREATED "ServiceCreated"
#define DBUS_SIGNAL_ORG_FREEDESKTOP_DBUS_SERVICE_DELETED "ServiceDeleted"
#define DBUS_SIGNAL_ORG_FREEDESKTOP_DBUS_SERVICE_LOST "ServiceLost"
#endif /* #if 0 */
#ifdef __cplusplus
}

View file

@ -2853,6 +2853,9 @@ _dbus_string_validate_nul (const DBusString *str,
*
* @todo this is inconsistent with most of DBusString in that
* it allows a start,len range that isn't in the string.
*
* @todo change spec to disallow more things, such as spaces in the
* interface name
*
* @param str the string
* @param start first byte index to check
@ -2911,6 +2914,9 @@ _dbus_string_validate_interface (const DBusString *str,
* @todo this is inconsistent with most of DBusString in that
* it allows a start,len range that isn't in the string.
*
* @todo change spec to disallow more things, such as spaces in the
* member name
*
* @param str the string
* @param start first byte index to check
* @param len number of bytes to check
@ -2991,6 +2997,9 @@ _dbus_string_validate_error_name (const DBusString *str,
*
* @todo this is inconsistent with most of DBusString in that
* it allows a start,len range that isn't in the string.
*
* @todo change spec to disallow more things, such as spaces in the
* service name
*
* @param str the string
* @param start first byte index to check

View file

@ -23,9 +23,6 @@
(changing get_string to have an error return, and allowing a type error
as a possible return)
- We might consider returning a "no such operation" error in dbus-connection.c
for unhandled messages.
- The convenience functions in dbus-bus.h should perhaps have
the signatures that they would have if they were autogenerated
stubs. e.g. the acquire service function. We should also evaluate

View file

@ -30,8 +30,9 @@ main (int argc, char **argv)
dbus_connection_setup_with_g_main (connection, NULL);
message = dbus_message_new_method_call (DBUS_MESSAGE_HELLO,
DBUS_SERVICE_DBUS);
message = dbus_message_new_method_call (DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS,
"Hello",
DBUS_SERVICE_ORG_FREEDESKTOP_DBUS);
dbus_error_init (&error);
reply = dbus_connection_send_with_reply_and_block (connection, message, -1, &error);
@ -42,7 +43,7 @@ main (int argc, char **argv)
return 1;
}
g_print ("reply name: %s\n", dbus_message_get_name (reply));
g_print ("reply received\n");
g_main_loop_run (loop);

View file

@ -21,6 +21,11 @@
*
*/
/* FIXME this test is wacky since both client and server keep
* sending each other method calls, but nobody sends
* a DBUS_MESSAGE_TYPE_METHOD_RETURN
*/
#include <config.h>
#include <glib.h>
#include "dbus-glib.h"
@ -29,7 +34,9 @@
#define N_CLIENT_THREADS 1
#define N_ITERATIONS 1000
#define PAYLOAD_SIZE 30
#define ECHO_MESSAGE "org.freedesktop.DBus.Test.EchoProfile"
#define ECHO_INTERFACE "org.freedekstop.EchoTest"
#define ECHO_METHOD "EchoProfile"
static const char *address;
static unsigned char *payload;
@ -38,7 +45,7 @@ send_echo_message (DBusConnection *connection)
{
DBusMessage *message;
message = dbus_message_new_method_call (ECHO_MESSAGE, NULL);
message = dbus_message_new_method_call (ECHO_INTERFACE, ECHO_METHOD, NULL);
dbus_message_append_args (message,
DBUS_TYPE_STRING, "Hello World!",
DBUS_TYPE_INT32, 123456,
@ -61,13 +68,15 @@ client_filter (DBusMessageHandler *handler,
{
int *iterations = user_data;
if (dbus_message_has_name (message, DBUS_MESSAGE_LOCAL_DISCONNECT))
if (dbus_message_is_signal (message,
DBUS_INTERFACE_ORG_FREEDESKTOP_LOCAL,
"Disconnected"))
{
g_printerr ("Client thread disconnected\n");
exit (1);
}
else if (dbus_message_has_name (message,
ECHO_MESSAGE))
else if (dbus_message_is_method_call (message,
ECHO_INTERFACE, ECHO_METHOD))
{
*iterations += 1;
if (*iterations >= N_ITERATIONS)
@ -139,13 +148,16 @@ server_filter (DBusMessageHandler *handler,
DBusMessage *message,
void *user_data)
{
if (dbus_message_has_name (message, DBUS_MESSAGE_LOCAL_DISCONNECT))
if (dbus_message_is_signal (message,
DBUS_INTERFACE_ORG_FREEDESKTOP_LOCAL,
"Disconnected"))
{
g_printerr ("Server thread disconnected\n");
exit (1);
}
else if (dbus_message_has_name (message,
ECHO_MESSAGE))
else if (dbus_message_is_method_call (message,
ECHO_INTERFACE,
ECHO_METHOD))
{
send_echo_message (connection);
return DBUS_HANDLER_RESULT_HANDLED;

View file

@ -19,7 +19,8 @@ thread_func (gpointer data)
while (1)
{
message = dbus_message_new_method_call ("org.freedesktop.ThreadTest", NULL);
message = dbus_message_new_method_call ("org.freedesktop.ThreadTest",
"TestMethod", NULL);
dbus_message_append_iter_init (message, &iter);

View file

@ -43,7 +43,8 @@ handle_test_message (DBusMessageHandler *handler,
GString *counter_str;
int i;
if (!dbus_message_has_name (message, "org.freedesktop.ThreadTest"))
if (!dbus_message_is_method_call (message, "org.freedesktop.ThreadTest",
"TestMethod"))
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
dbus_message_iter_init (message, &iter);
@ -145,7 +146,8 @@ handle_disconnect (DBusMessageHandler *handler,
DBusMessage *message,
void *user_data)
{
if (!dbus_message_has_name (message, DBUS_MESSAGE_LOCAL_DISCONNECT))
if (!dbus_message_is_signal (message, DBUS_INTERFACE_ORG_FREEDESKTOP_LOCAL,
"Disconnected"))
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
g_print ("connection disconnected\n");

View file

@ -1,9 +1,12 @@
## message that's missing an expected body
VALID_HEADER
FIELD_NAME name
VALID_HEADER method_call
FIELD_NAME ifce
TYPE STRING
STRING 'org.freedesktop.Foo'
FIELD_NAME mebr
TYPE STRING
STRING 'Bar'
END_LENGTH Header
ALIGN 8

View file

@ -1,9 +1,14 @@
# Message with an array of NIL (not allowed)
VALID_HEADER
FIELD_NAME name
VALID_HEADER method_call
FIELD_NAME ifce
TYPE STRING
STRING 'org.freedesktop.Foo'
FIELD_NAME mebr
TYPE STRING
STRING 'Bar'
END_LENGTH Header
ALIGN 8
START_LENGTH Body

View file

@ -1,10 +1,15 @@
# Message with an array of array where the child arrays are of
# different types
VALID_HEADER
FIELD_NAME name
VALID_HEADER method_call
FIELD_NAME ifce
TYPE STRING
STRING 'org.freedesktop.Foo'
FIELD_NAME mebr
TYPE STRING
STRING 'Bar'
END_LENGTH Header
ALIGN 8
START_LENGTH Body

View file

@ -1,10 +1,15 @@
## a message with an invalid boolean array
## VALID_HEADER includes a LENGTH Header and LENGTH Body
VALID_HEADER
FIELD_NAME name
VALID_HEADER method_call
FIELD_NAME ifce
TYPE STRING
STRING 'org.freedesktop.Foo'
FIELD_NAME mebr
TYPE STRING
STRING 'Bar'
ALIGN 8
END_LENGTH Header
START_LENGTH Body

View file

@ -1,10 +1,15 @@
## a message with an invalid boolean value
## VALID_HEADER includes a LENGTH Header and LENGTH Body
VALID_HEADER
FIELD_NAME name
VALID_HEADER method_call
FIELD_NAME ifce
TYPE STRING
STRING 'org.freedesktop.Foo'
FIELD_NAME mebr
TYPE STRING
STRING 'Bar'
ALIGN 8
END_LENGTH Header
START_LENGTH Body

View file

@ -4,10 +4,20 @@ BYTE 'i'
BYTE 1
BYTE 0
BYTE 0
LENGTH Header
LENGTH Body
## client serial
INT32 7
FIELD_NAME ifce
TYPE STRING
STRING 'org.freedesktop.Foo'
FIELD_NAME mebr
TYPE STRING
STRING 'Bar'
ALIGN 8
END_LENGTH Header
START_LENGTH Body
END_LENGTH Body

View file

@ -2,10 +2,15 @@
## invalid
## VALID_HEADER includes a LENGTH Header and LENGTH Body
VALID_HEADER
FIELD_NAME name
VALID_HEADER method_call
FIELD_NAME ifce
TYPE STRING
STRING 'org.freedesktop.Local.Disconnect'
STRING 'org.freedesktop.Local'
FIELD_NAME mebr
TYPE STRING
STRING 'Disconnected'
ALIGN 8
END_LENGTH Header
START_LENGTH Body

View file

@ -1,10 +1,15 @@
## a message with dotless name
## a message with dotless interface
## VALID_HEADER includes a LENGTH Header and LENGTH Body
VALID_HEADER
FIELD_NAME name
VALID_HEADER method_call
FIELD_NAME ifce
TYPE STRING
STRING 'NoNamespaceHere'
STRING 'NoDotInHere'
FIELD_NAME mebr
TYPE STRING
STRING 'Bar'
ALIGN 8
END_LENGTH Header
START_LENGTH Body

View file

@ -1,7 +1,15 @@
## has one non-nul byte in header padding
## VALID_HEADER includes a LENGTH Header and LENGTH Body
VALID_HEADER
VALID_HEADER method_call
FIELD_NAME ifce
TYPE STRING
STRING 'org.freedesktop.Foo'
FIELD_NAME mebr
TYPE STRING
STRING 'Bar'
FIELD_NAME unkn
TYPE STRING
STRING 'a'

View file

@ -1,10 +1,15 @@
## a message with too-long name field
## VALID_HEADER includes a LENGTH Header and LENGTH Body
VALID_HEADER
FIELD_NAME name
VALID_HEADER method_call
FIELD_NAME ifce
TYPE STRING
STRING 'org.foo.bar.this.is.really.long 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200'
FIELD_NAME mebr
TYPE STRING
STRING 'Bar'
ALIGN 8
END_LENGTH Header
START_LENGTH Body

View file

@ -1,7 +1,15 @@
## has one byte missing from header padding
## VALID_HEADER includes a LENGTH Header and LENGTH Body
VALID_HEADER
VALID_HEADER method_call
FIELD_NAME ifce
TYPE STRING
STRING 'org.freedesktop.Foo'
FIELD_NAME mebr
TYPE STRING
STRING 'Bar'
FIELD_NAME unkn
TYPE STRING
STRING 'a'

View file

@ -1,7 +1,15 @@
## has one byte extra header padding
## VALID_HEADER includes a LENGTH Header and LENGTH Body
VALID_HEADER
VALID_HEADER method_call
FIELD_NAME ifce
TYPE STRING
STRING 'org.freedesktop.Foo'
FIELD_NAME mebr
TYPE STRING
STRING 'Bar'
FIELD_NAME unkn
TYPE STRING
STRING 'a'

View file

@ -1,7 +1,15 @@
## has one byte extra header padding
## VALID_HEADER includes a LENGTH Header and LENGTH Body
VALID_HEADER
VALID_HEADER method_call
FIELD_NAME ifce
TYPE STRING
STRING 'org.freedesktop.Foo'
FIELD_NAME mebr
TYPE STRING
STRING 'Bar'
FIELD_NAME unkn
TYPE STRING
STRING 'a'

View file

@ -1,11 +1,18 @@
# Message with lots of different argument types
VALID_HEADER
FIELD_NAME name
VALID_HEADER method_call
FIELD_NAME ifce
TYPE STRING
STRING 'org.freedesktop.Foo'
END_LENGTH Header
FIELD_NAME mebr
TYPE STRING
STRING 'Bar'
ALIGN 8
END_LENGTH Header
START_LENGTH Body
TYPE DICT
LENGTH Dict

View file

@ -1,9 +1,12 @@
# Message with an array of array of uint32
VALID_HEADER
FIELD_NAME name
VALID_HEADER method_call
FIELD_NAME ifce
TYPE STRING
STRING 'org.freedesktop.Foo'
FIELD_NAME mebr
TYPE STRING
STRING 'Bar'
END_LENGTH Header
ALIGN 8
START_LENGTH Body

View file

@ -1,9 +1,12 @@
# A simple dict
VALID_HEADER
FIELD_NAME name
VALID_HEADER method_call
FIELD_NAME ifce
TYPE STRING
STRING 'org.freedesktop.Foo'
FIELD_NAME mebr
TYPE STRING
STRING 'Bar'
END_LENGTH Header
ALIGN 8
START_LENGTH Body

View file

@ -1,9 +1,12 @@
# Dict with different values
VALID_HEADER
FIELD_NAME name
VALID_HEADER method_call
FIELD_NAME ifce
TYPE STRING
STRING 'org.freedesktop.Foo'
FIELD_NAME mebr
TYPE STRING
STRING 'Bar'
ALIGN 8
END_LENGTH Header
START_LENGTH Body

View file

@ -1,9 +1,12 @@
# Empty arrays and strings
VALID_HEADER
FIELD_NAME name
VALID_HEADER method_call
FIELD_NAME ifce
TYPE STRING
STRING 'org.freedesktop.Foo'
FIELD_NAME mebr
TYPE STRING
STRING 'Bar'
END_LENGTH Header
ALIGN 8
START_LENGTH Body

View file

@ -1,9 +1,12 @@
# Message with lots of different argument types
VALID_HEADER
FIELD_NAME name
VALID_HEADER method_call
FIELD_NAME ifce
TYPE STRING
STRING 'org.freedesktop.Foo'
FIELD_NAME mebr
TYPE STRING
STRING 'Bar'
END_LENGTH Header
ALIGN 8
START_LENGTH Body

View file

@ -1,11 +1,14 @@
## Message with no header padding
## VALID_HEADER includes a LENGTH Header and LENGTH Body
VALID_HEADER
VALID_HEADER method_call
FIELD_NAME name
FIELD_NAME ifce
TYPE STRING
STRING 'org.freedesktop.Foo'
FIELD_NAME mebr
TYPE STRING
STRING 'Bar'
## this byte array is filled with zeros to the natural length
## of the header

View file

@ -3,15 +3,14 @@
OPPOSITE_ENDIAN
## VALID_HEADER includes a LENGTH Header and LENGTH Body
VALID_HEADER
VALID_HEADER method_call
FIELD_NAME rply
TYPE UINT32
UINT32 10000
FIELD_NAME name
FIELD_NAME ifce
TYPE STRING
STRING 'org.freedesktop.Foo'
FIELD_NAME mebr
TYPE STRING
STRING 'Bar'
FIELD_NAME unkn
TYPE INT32

View file

@ -1,11 +1,14 @@
## Message with recursive types
## VALID_HEADER includes a LENGTH Header and LENGTH Body
VALID_HEADER
VALID_HEADER method_call
FIELD_NAME name
FIELD_NAME ifce
TYPE STRING
STRING 'org.freedesktop.Foo'
FIELD_NAME mebr
TYPE STRING
STRING 'Bar'
END_LENGTH Header
START_LENGTH Body

View file

@ -10,9 +10,14 @@ LENGTH Header
LENGTH Body
## client serial
INT32 7
FIELD_NAME name
FIELD_NAME ifce
TYPE STRING
STRING 'org.freedesktop.Foo'
FIELD_NAME mebr
TYPE STRING
STRING 'Bar'
ALIGN 8
END_LENGTH Header
START_LENGTH Body

View file

@ -1,10 +1,15 @@
## simplest possible valid message
## VALID_HEADER includes a LENGTH Header and LENGTH Body
VALID_HEADER
FIELD_NAME name
VALID_HEADER method_call
FIELD_NAME ifce
TYPE STRING
STRING 'org.freedesktop.Foo'
FIELD_NAME mebr
TYPE STRING
STRING 'Bar'
ALIGN 8
END_LENGTH Header
START_LENGTH Body

View file

@ -1,9 +1,12 @@
# Standard org.freedesktop.DBus.AcquireService message
VALID_HEADER
FIELD_NAME name
VALID_HEADER method_call
FIELD_NAME ifce
TYPE STRING
STRING 'org.freedesktop.DBus.AcquireService'
STRING 'org.freedesktop.DBus'
FIELD_NAME mebr
TYPE STRING
STRING 'AcquireService'
FIELD_NAME srvc
TYPE STRING
STRING 'org.freedesktop.DBus'

View file

@ -1,9 +1,12 @@
# Standard org.freedesktop.DBus.Hello message
VALID_HEADER
FIELD_NAME name
VALID_HEADER method_call
FIELD_NAME ifce
TYPE STRING
STRING 'org.freedesktop.DBus.Hello'
STRING 'org.freedesktop.DBus'
FIELD_NAME mebr
TYPE STRING
STRING 'Hello'
FIELD_NAME srvc
TYPE STRING
STRING 'org.freedesktop.DBus'

View file

@ -1,9 +1,12 @@
# Standard org.freedesktop.DBus.ListServices message
VALID_HEADER
FIELD_NAME name
VALID_HEADER method_call
FIELD_NAME ifce
TYPE STRING
STRING 'org.freedesktop.DBus.ListServices'
STRING 'org.freedesktop.DBus'
FIELD_NAME mebr
TYPE STRING
STRING 'ListServices'
FIELD_NAME srvc
TYPE STRING
STRING 'org.freedesktop.DBus'

View file

@ -1,9 +1,12 @@
# Standard org.freedesktop.DBus.ServiceExists message
VALID_HEADER
FIELD_NAME name
VALID_HEADER method_call
FIELD_NAME ifce
TYPE STRING
STRING 'org.freedesktop.DBus.ServiceExists'
STRING 'org.freedesktop.DBus'
FIELD_NAME mebr
TYPE STRING
STRING 'ServiceExists'
FIELD_NAME srvc
TYPE STRING
STRING 'org.freedesktop.DBus'

View file

@ -1,10 +1,13 @@
## message with a 'name' header field and unknown 'unkn' field
## VALID_HEADER includes a LENGTH Header and LENGTH Body
VALID_HEADER
FIELD_NAME name
VALID_HEADER method_call
FIELD_NAME ifce
TYPE STRING
STRING 'org.freedesktop.Foo'
FIELD_NAME mebr
TYPE STRING
STRING 'Bar'
FIELD_NAME unkn
TYPE INT32
INT32 0xfeeb

View file

@ -77,10 +77,16 @@ filter_func (DBusMessageHandler *handler,
DBusMessage *message,
void *user_data)
{
if (dbus_message_has_name (message, "org.freedesktop.DBus.TestSuiteEcho"))
if (dbus_message_is_method_call (message,
"org.freedesktop.TestSuite",
"Echo"))
return handle_echo (connection, message);
else if (dbus_message_has_name (message, "org.freedesktop.DBus.TestSuiteExit") ||
dbus_message_has_name (message, DBUS_MESSAGE_LOCAL_DISCONNECT))
else if (dbus_message_is_method_call (message,
"org.freedesktop.TestSuite",
"Exit") ||
dbus_message_is_signal (message,
DBUS_INTERFACE_ORG_FREEDESKTOP_LOCAL,
"Disconnected"))
{
dbus_connection_disconnect (connection);
quit ();

View file

@ -37,7 +37,9 @@ handler_func (DBusMessageHandler *handler,
{
print_message (message);
if (dbus_message_has_name (message, DBUS_MESSAGE_LOCAL_DISCONNECT))
if (dbus_message_is_signal (message,
DBUS_INTERFACE_ORG_FREEDESKTOP_LOCAL,
"Disconnected"))
exit (0);
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;

View file

@ -48,12 +48,37 @@ print_message (DBusMessage *message)
message_type = dbus_message_get_type (message);
sender = dbus_message_get_sender (message);
printf ("%s name=%s; sender=%s\n",
type_to_name (message_type),
dbus_message_get_name (message),
sender ? sender : "(no sender)");
switch (message_type)
{
case DBUS_MESSAGE_TYPE_METHOD_CALL:
case DBUS_MESSAGE_TYPE_SIGNAL:
printf ("%s interface=%s; member=%s; sender=%s\n",
type_to_name (message_type),
dbus_message_get_interface (message),
dbus_message_get_member (message),
sender ? sender : "(no sender)");
break;
case DBUS_MESSAGE_TYPE_METHOD_RETURN:
printf ("%s; sender=%s\n",
type_to_name (message_type),
sender ? sender : "(no sender)");
break;
case DBUS_MESSAGE_TYPE_ERROR:
printf ("%s name=%s; sender=%s\n",
type_to_name (message_type),
dbus_message_get_error_name (message),
sender ? sender : "(no sender)");
break;
default:
printf ("Message of unknown type %d received\n",
message_type);
break;
}
dbus_message_iter_init (message, &iter);
do

View file

@ -42,12 +42,16 @@ byte, boolean. (D-BUS supports more types than these, but
Here is an example invocation:
.nf
dbus-send \-\-dest='org.freedesktop.ExampleService' \\
org.freedesktop.ExampleMessage \\
dbus-send \-\-dest='org.freedesktop.ExampleService' \\
org.freedesktop.ExampleInterface.ExampleMethod \\
int32:47 string:'hello world' double:65.32
.fi
Note that the interface is separated from a method or signal
name by a dot, though in the actual protocol the interface
and the interface member are separate fields.
.SH OPTIONS
The following options are supported:
.TP

View file

@ -44,7 +44,7 @@ main (int argc, char *argv[])
DBusMessageIter iter;
int i;
DBusBusType type = DBUS_BUS_SESSION;
const char *dest = DBUS_SERVICE_BROADCAST;
const char *dest = DBUS_SERVICE_ORG_FREEDESKTOP_BROADCAST;
char *name = NULL;
int message_type = DBUS_MESSAGE_TYPE_SIGNAL;
const char *type_str = NULL;
@ -106,11 +106,35 @@ main (int argc, char *argv[])
if (message_type == DBUS_MESSAGE_TYPE_METHOD_CALL)
{
message = dbus_message_new_method_call (name, NULL);
char *last_dot;
last_dot = strrchr (name, '.');
if (last_dot == NULL)
{
fprintf (stderr, "Must use org.mydomain.Interface.Method notation, no dot in \"%s\"\n",
name);
exit (1);
}
*last_dot = '\0';
message = dbus_message_new_method_call (name,
last_dot + 1,
NULL);
}
else if (message_type == DBUS_MESSAGE_TYPE_SIGNAL)
{
message = dbus_message_new_signal (name);
char *last_dot;
last_dot = strrchr (name, '.');
if (last_dot == NULL)
{
fprintf (stderr, "Must use org.mydomain.Interface.Signal notation, no dot in \"%s\"\n",
name);
exit (1);
}
*last_dot = '\0';
message = dbus_message_new_signal (name, last_dot + 1);
}
else
{