unix-fd: introduce dbus_connection_can_send_type()
authorLennart Poettering <lennart@poettering.net>
Wed, 22 Apr 2009 01:56:18 +0000 (03:56 +0200)
committerLennart Poettering <lennart@poettering.net>
Wed, 20 May 2009 00:09:30 +0000 (02:09 +0200)
This is just a wrapper around _dbus_transport_can_pass_unix_fd() however
it is more generic.

The reason for keeping this generic is to ease later addition of more
types without having to add a new API for that.

dbus/dbus-connection.c
dbus/dbus-connection.h

index afa0ca6..fc872bc 100644 (file)
@@ -33,6 +33,7 @@
 #include "dbus-list.h"
 #include "dbus-hash.h"
 #include "dbus-message-internal.h"
+#include "dbus-message-private.h"
 #include "dbus-threads.h"
 #include "dbus-protocol.h"
 #include "dbus-dataslot.h"
@@ -41,6 +42,7 @@
 #include "dbus-object-tree.h"
 #include "dbus-threads-internal.h"
 #include "dbus-bus.h"
+#include "dbus-marshal-basic.h"
 
 #ifdef DBUS_DISABLE_CHECKS
 #define TOOK_LOCK_CHECK(connection)
@@ -2932,15 +2934,59 @@ dbus_connection_get_server_id (DBusConnection *connection)
   char *id;
 
   _dbus_return_val_if_fail (connection != NULL, NULL);
-  
+
   CONNECTION_LOCK (connection);
   id = _dbus_strdup (_dbus_transport_get_server_id (connection->transport));
   CONNECTION_UNLOCK (connection);
-  
+
   return id;
 }
 
 /**
+ * Tests whether a certain type can be send via the connection. This
+ * will always return TRUE for all types, with the exception of
+ * DBUS_TYPE_UNIX_FD. The function will return TRUE for
+ * DBUS_TYPE_UNIX_FD only on systems that know Unix file descriptors
+ * and can send them via the chosen transport and when the remote side
+ * supports this.
+ *
+ * This function can be used to do runtime checking for types that
+ * might be unknown to the specific D-Bus client implementation
+ * version, i.e. it will return FALSE for all types this
+ * implementation does not know.
+ *
+ * @param connection the connection
+ * @param type the type to check
+ * @returns TRUE if the type may be send via the connection
+ */
+dbus_bool_t
+dbus_connection_can_send_type(DBusConnection *connection,
+                                  int type)
+{
+  _dbus_return_val_if_fail (connection != NULL, FALSE);
+
+  if (!_dbus_type_is_valid(type))
+    return FALSE;
+
+  if (type != DBUS_TYPE_UNIX_FD)
+    return TRUE;
+
+#ifdef HAVE_UNIX_FD_PASSING
+  {
+    dbus_bool_t b;
+
+    CONNECTION_LOCK(connection);
+    b = _dbus_transport_can_pass_unix_fd(connection->transport);
+    CONNECTION_UNLOCK(connection);
+
+    return b;
+  }
+#endif
+
+  return FALSE;
+}
+
+/**
  * Set whether _exit() should be called when the connection receives a
  * disconnect signal. The call to _exit() comes after any handlers for
  * the disconnect signal run; handlers can cancel the exit by calling
index b8fd35f..c9b9aa3 100644 (file)
@@ -180,6 +180,8 @@ dbus_bool_t        dbus_connection_get_is_connected             (DBusConnection
 dbus_bool_t        dbus_connection_get_is_authenticated         (DBusConnection             *connection);
 dbus_bool_t        dbus_connection_get_is_anonymous             (DBusConnection             *connection);
 char*              dbus_connection_get_server_id                (DBusConnection             *connection);
+dbus_bool_t        dbus_connection_can_send_type                (DBusConnection             *connection,
+                                                                 int                         type);
 void               dbus_connection_set_exit_on_disconnect       (DBusConnection             *connection,
                                                                  dbus_bool_t                 exit_on_disconnect);
 void               dbus_connection_flush                        (DBusConnection             *connection);