- fixed dbus_bus_request_name
[platform/upstream/dbus.git] / dbus / dbus-connection.c
index b3fa9cf..d6a547e 100644 (file)
@@ -45,6 +45,7 @@
 #include "dbus-bus.h"
 #include "dbus-marshal-basic.h"
 #include "dbus-transport-kdbus.h"
+#include <stdlib.h>
 
 #ifdef DBUS_DISABLE_CHECKS
 #define TOOK_LOCK_CHECK(connection)
@@ -1845,21 +1846,6 @@ connection_try_from_address_entry (DBusAddressEntry *entry,
   _dbus_assert (!connection->have_connection_lock);
 #endif
 
-  /* kdbus add-on [RP] - bus register for kdbus
-   * Function checks if the method is kdbus. If yes - it registers on the bus, if no - does nothing and returns TRUE
-   * Must be invoked before dbus_bus_register because in kdbus it's realized in different manner
-   * and dbus_bus_register can not be used for that.
-   * It does not collide with dbus_bus_register because dbus_bus_register at the beginning checks
-   * whether unique_name has already been assigned and doesn't try to do it again.
-   */
-
-  if(!dbus_bus_register_kdbus(entry, connection, error))
-  {
-         _dbus_connection_close_possibly_shared (connection);
-      dbus_connection_unref (connection);
-      connection = NULL;
-  }
-
   return connection;
 }
 
@@ -2073,6 +2059,23 @@ _dbus_connection_send_preallocated_unlocked_no_update (DBusConnection       *con
   _dbus_verbose ("Message %p serial is %u\n",
                  message, dbus_message_get_serial (message));
   
+  if(dbus_transport_is_kdbus(connection))
+  {
+         const char* name;
+         char* sender;
+
+         name = dbus_bus_get_unique_name(connection);
+         sender = malloc (strlen(name) + 4);
+         if(sender)
+         {
+                 strcpy(sender,":1.");
+                 strcpy(&sender[3], name);
+                 _dbus_verbose ("Message sender: %s\n", sender);
+                 dbus_message_set_sender(message, sender);
+                 free((void*)sender);
+         }
+  }
+
   dbus_message_lock (message);
 
   /* Now we need to run an iteration to hopefully just write the messages
@@ -2206,7 +2209,7 @@ _dbus_memory_pause_based_on_timeout (int timeout_milliseconds)
     _dbus_sleep_milliseconds (1000);
 }
 
-static DBusMessage *
+DBusMessage *
 generate_local_error_message (dbus_uint32_t serial, 
                               char *error_name, 
                               char *error_msg)
@@ -3002,6 +3005,24 @@ dbus_connection_get_is_authenticated (DBusConnection *connection)
 }
 
 /**
+ * Sets authenticated status for connection. Needed for kdbus, where authentication is
+ * made in different manner.
+ *
+ * @param connection the connection
+ */
+dbus_bool_t
+dbus_connection_set_is_authenticated (DBusConnection *connection)
+{
+  _dbus_return_val_if_fail (connection != NULL, FALSE);
+
+  CONNECTION_LOCK (connection);
+  connection->transport->authenticated = TRUE;
+  CONNECTION_UNLOCK (connection);
+
+  return TRUE;
+}
+
+/**
  * Gets whether the connection is not authenticated as a specific
  * user.  If the connection is not authenticated, this function
  * returns #TRUE, and if it is authenticated but as an anonymous user,
@@ -4246,7 +4267,7 @@ static DBusDispatchStatus
 _dbus_connection_get_dispatch_status_unlocked (DBusConnection *connection)
 {
   HAVE_LOCK_CHECK (connection);
-  
+
   if (connection->n_incoming > 0)
     return DBUS_DISPATCH_DATA_REMAINS;
   else if (!_dbus_transport_queue_messages (connection->transport))
@@ -4255,7 +4276,7 @@ _dbus_connection_get_dispatch_status_unlocked (DBusConnection *connection)
     {
       DBusDispatchStatus status;
       dbus_bool_t is_connected;
-      
+
       status = _dbus_transport_get_dispatch_status (connection->transport);
       is_connected = _dbus_transport_get_is_connected (connection->transport);
 
@@ -6299,7 +6320,6 @@ dbus_connection_get_outgoing_unix_fds (DBusConnection *connection)
   return res;
 }
 
-//#ifdef DBUS_BUILD_TESTS
 /**
  * Returns the address of the transport object of this connection
  *
@@ -6311,6 +6331,14 @@ _dbus_connection_get_address (DBusConnection *connection)
 {
   return _dbus_transport_get_address (connection->transport);
 }
-//#endif
+
+DBusTransport*
+dbus_connection_get_transport(DBusConnection *connection)
+{
+       _dbus_return_val_if_fail (connection != NULL, NULL);
+
+       return connection->transport;
+}
+
 
 /** @} */