Commit 68a3c593 authored by Havoc Pennington's avatar Havoc Pennington

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"
parent 95717a93
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
......
......@@ -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");
......
......@@ -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);
......
......@@ -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)
{
_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))
if (!dbus_message_is_error (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;
}
}
......
......@@ -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);
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);
_dbus_verbose ("Driver got a message: %s\n",
dbus_message_get_name (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;