*
* 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
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
+#include <config.h>
#include "dispatch.h"
#include "connection.h"
#include "driver.h"
#include <unistd.h>
#endif
+#ifdef DBUS_UNIX
+#define TEST_CONNECTION "debug-pipe:name=test-server"
+#else
+#define TEST_CONNECTION "tcp:host=localhost,port=1234"
+#endif
+
static dbus_bool_t
send_one_message (DBusConnection *connection,
BusContext *context,
message,
NULL))
return TRUE; /* silently don't send it */
+
+ if (dbus_message_contains_unix_fds(message) &&
+ !dbus_connection_can_send_type(connection, DBUS_TYPE_UNIX_FD))
+ return TRUE; /* silently don't send it */
if (!bus_transaction_send (transaction,
connection,
_dbus_assert (sender == NULL || bus_connection_is_active (sender));
_dbus_assert (dbus_message_get_sender (message) != NULL);
+ context = bus_transaction_get_context (transaction);
+
+ /* First, send the message to the addressed_recipient, if there is one. */
+ if (addressed_recipient != NULL)
+ {
+ if (!bus_context_check_security_policy (context, transaction,
+ sender, addressed_recipient,
+ addressed_recipient,
+ message, error))
+ return FALSE;
+
+ if (dbus_message_contains_unix_fds (message) &&
+ !dbus_connection_can_send_type (addressed_recipient,
+ DBUS_TYPE_UNIX_FD))
+ {
+ dbus_set_error (error,
+ DBUS_ERROR_NOT_SUPPORTED,
+ "Tried to send message with Unix file descriptors"
+ "to a client that doesn't support that.");
+ return FALSE;
+ }
+
+ /* Dispatch the message */
+ if (!bus_transaction_send (transaction, addressed_recipient, message))
+ {
+ BUS_SET_OOM (error);
+ return FALSE;
+ }
+ }
+
+ /* Now dispatch to others who look interested in this message */
connections = bus_transaction_get_connections (transaction);
-
dbus_error_init (&tmp_error);
- context = bus_transaction_get_context (transaction);
matchmaker = bus_context_get_matchmaker (context);
recipients = NULL;
{
addressed_recipient = bus_service_get_primary_owners_connection (service);
_dbus_assert (addressed_recipient != NULL);
-
- if (!bus_context_check_security_policy (context, transaction,
- connection, addressed_recipient,
- addressed_recipient,
- message, &error))
- goto out;
-
- /* Dispatch the message */
- if (!bus_transaction_send (transaction, addressed_recipient, message))
- {
- BUS_SET_OOM (&error);
- goto out;
- }
}
}
- /* Now match the messages against any match rules, which will send
- * out signals and such. addressed_recipient may == NULL.
+ /* Now send the message to its destination (or not, if
+ * addressed_recipient == NULL), and match it against other connections'
+ * match rules.
*/
if (!bus_dispatch_matches (transaction, connection, addressed_recipient, message, &error))
goto out;
dbus_error_init (&error);
- connection = dbus_connection_open_private ("debug-pipe:name=test-server", &error);
+ connection = dbus_connection_open_private (TEST_CONNECTION, &error);
if (connection == NULL)
{
_DBUS_ASSERT_ERROR_IS_SET (&error);
if (!_dbus_string_array_contains ((const char **)services, existent))
{
_dbus_warn ("Did not get the expected %s from ListActivatableNames\n", existent);
+ dbus_free_string_array (services);
return FALSE;
}
if (context == NULL)
return FALSE;
- foo = dbus_connection_open_private ("debug-pipe:name=test-server", &error);
+ foo = dbus_connection_open_private (TEST_CONNECTION, &error);
if (foo == NULL)
_dbus_assert_not_reached ("could not alloc connection");
if (!check_add_match_all (context, foo))
_dbus_assert_not_reached ("AddMatch message failed");
- bar = dbus_connection_open_private ("debug-pipe:name=test-server", &error);
+ bar = dbus_connection_open_private (TEST_CONNECTION, &error);
if (bar == NULL)
_dbus_assert_not_reached ("could not alloc connection");
if (!check_add_match_all (context, bar))
_dbus_assert_not_reached ("AddMatch message failed");
- baz = dbus_connection_open_private ("debug-pipe:name=test-server", &error);
+ baz = dbus_connection_open_private (TEST_CONNECTION, &error);
if (baz == NULL)
_dbus_assert_not_reached ("could not alloc connection");
if (!check_add_match_all (context, baz))
_dbus_assert_not_reached ("AddMatch message failed");
+#ifdef DBUS_WIN_FIXME
+ _dbus_warn("TODO: testing of GetConnectionUnixUser message skipped for now\n");
+ _dbus_warn("TODO: testing of GetConnectionUnixProcessID message skipped for now\n");
+#else
if (!check_get_connection_unix_user (context, baz))
_dbus_assert_not_reached ("GetConnectionUnixUser message failed");
if (!check_get_connection_unix_process_id (context, baz))
_dbus_assert_not_reached ("GetConnectionUnixProcessID message failed");
+#endif
if (!check_list_services (context, baz))
_dbus_assert_not_reached ("ListActivatableNames message failed");
if (context == NULL)
return FALSE;
- foo = dbus_connection_open_private ("debug-pipe:name=test-server", &error);
+ foo = dbus_connection_open_private (TEST_CONNECTION, &error);
if (foo == NULL)
_dbus_assert_not_reached ("could not alloc connection");
if (context == NULL)
return FALSE;
- foo = dbus_connection_open_private ("debug-pipe:name=test-server", &error);
+ foo = dbus_connection_open_private (TEST_CONNECTION, &error);
if (foo == NULL)
_dbus_assert_not_reached ("could not alloc connection");
if (context == NULL)
_dbus_assert_not_reached ("could not alloc context");
- foo = dbus_connection_open_private ("debug-pipe:name=test-server", &error);
+ foo = dbus_connection_open_private (TEST_CONNECTION, &error);
if (foo == NULL)
_dbus_assert_not_reached ("could not alloc connection");
if (!check_add_match_all (context, foo))
_dbus_assert_not_reached ("AddMatch message failed");
- bar = dbus_connection_open_private ("debug-pipe:name=test-server", &error);
+ bar = dbus_connection_open_private (TEST_CONNECTION, &error);
if (bar == NULL)
_dbus_assert_not_reached ("could not alloc connection");
if (!_dbus_close(two[0], &error))
_dbus_assert_not_reached("Failed to close pipe #2 ");
+ if (!(dbus_connection_can_send_type(foo, DBUS_TYPE_UNIX_FD)))
+ _dbus_assert_not_reached("Connection cannot do fd passing");
+
+ if (!(dbus_connection_can_send_type(bar, DBUS_TYPE_UNIX_FD)))
+ _dbus_assert_not_reached("Connection cannot do fd passing");
if (!dbus_connection_send (foo, m, NULL))
_dbus_assert_not_reached("Failed to send fds");