[daemon-fix] fixed querying about name information
[platform/upstream/dbus.git] / dbus / dbus-bus.c
index 8329f49..3824b3f 100644 (file)
@@ -3,6 +3,7 @@
  *
  * Copyright (C) 2003  CodeFactory AB
  * Copyright (C) 2003  Red Hat, Inc.
+ * Copyright (C) 2013  Samsung Electronics
  *
  * Licensed under the Academic Free License version 2.1
  * 
 #include "dbus-threads-internal.h"
 #include "dbus-connection-internal.h"
 #include "dbus-string.h"
+#ifdef ENABLE_KDBUS_TRANSPORT
 #include "dbus-transport-kdbus.h"
 #include <stdlib.h>
 #include <limits.h>
 #include <stdio.h>
+#endif
 
 /**
  * @defgroup DBusBus Message bus APIs
@@ -139,6 +142,15 @@ get_from_env (char           **connection_p,
     }
 }
 
+#ifdef ENABLE_KDBUS_TRANSPORT
+void dbus_bus_set_bus_connection_address(DBusBusType address_type, char* address)
+{
+       if(bus_connection_addresses[address_type] != NULL)
+               free(bus_connection_addresses[address_type]);
+       bus_connection_addresses[address_type] = address;
+}
+#endif
+
 static dbus_bool_t
 init_session_address (void)
 {
@@ -490,8 +502,6 @@ internal_bus_get (DBusBusType  type,
       goto out;
     }
 
-  _dbus_verbose (" !!! dbus_connection_open finished successfully   !!!! \n");  //todo RP to be removed
-
   if (!dbus_bus_register (connection, error))
     {
       _dbus_connection_close_possibly_shared (connection);
@@ -692,48 +702,35 @@ dbus_bus_register (DBusConnection *connection,
       retval = TRUE;
       goto out;
     }
-  if(dbus_transport_is_kdbus(connection))
-  {
-         name = malloc(snprintf(name, 0, "%llu", ULLONG_MAX) + 1);
-         if(!bus_register_kdbus(name, connection, error))
-                 goto out;
-
-         if(!bus_register_policy_kdbus(name, connection, error))
-               goto out;
-
-         dbus_connection_set_is_authenticated(connection);
-  }
-  else
-  {
-         message = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
+  message = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
                                                                                          DBUS_PATH_DBUS,
                                                                                          DBUS_INTERFACE_DBUS,
                                                                                          "Hello");
-         if (!message)
-               {
-                 _DBUS_SET_OOM (error);
-                 goto out;
-               }
-
-         reply = dbus_connection_send_with_reply_and_block (connection, message, -1, error);
-
-         if (reply == NULL)
-               goto out;
-         else if (dbus_set_error_from_message (error, reply))
-               goto out;
-         else if (!dbus_message_get_args (reply, error,
-                                                                          DBUS_TYPE_STRING, &name,
-                                                                          DBUS_TYPE_INVALID))
-               goto out;
-  }
+  if (!message)
+       {
+         _DBUS_SET_OOM (error);
+         goto out;
+       }
+
+  reply = dbus_connection_send_with_reply_and_block (connection, message, -1, error);
+
+  if (reply == NULL)
+       goto out;
+  else if (dbus_set_error_from_message (error, reply))
+       goto out;
+  else if (!dbus_message_get_args (reply, error,
+                                                                  DBUS_TYPE_STRING, &name,
+                                                                  DBUS_TYPE_INVALID))
+       goto out;
 
   bd->unique_name = _dbus_strdup (name);
+
   if (bd->unique_name == NULL)
     {
       _DBUS_SET_OOM (error);
       goto out;
     }
-  //_dbus_verbose("-- Our uniqe name is: %s\n", bd->unique_name);
+
   retval = TRUE;
   
  out:
@@ -741,8 +738,6 @@ dbus_bus_register (DBusConnection *connection,
 
   if (message)
     dbus_message_unref (message);
-  else if (name)
-         free(name);
 
   if (reply)
     dbus_message_unref (reply);
@@ -1141,73 +1136,61 @@ dbus_bus_request_name (DBusConnection *connection,
                        DBusError      *error)
 {
        dbus_uint32_t result;
+       DBusMessage *message, *reply;
 
        _dbus_return_val_if_fail (connection != NULL, 0);
        _dbus_return_val_if_fail (name != NULL, 0);
        _dbus_return_val_if_fail (_dbus_check_is_valid_bus_name (name), 0);
        _dbus_return_val_if_error_is_set (error, 0);
 
-       if(!dbus_transport_is_kdbus(connection))
-       {
-               DBusMessage *message, *reply;
-
-               message = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
+       message = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
                                                                                          DBUS_PATH_DBUS,
                                                                                          DBUS_INTERFACE_DBUS,
                                                                                          "RequestName");
-               if (message == NULL)
-               {
-                 _DBUS_SET_OOM (error);
-                 return -1;
-               }
+       if (message == NULL)
+       {
+         _DBUS_SET_OOM (error);
+         return -1;
+       }
 
-               if (!dbus_message_append_args (message,
+       if (!dbus_message_append_args (message,
                                         DBUS_TYPE_STRING, &name,
                                         DBUS_TYPE_UINT32, &flags,
                                         DBUS_TYPE_INVALID))
-               {
-                 dbus_message_unref (message);
-                 _DBUS_SET_OOM (error);
-                 return -1;
-               }
+       {
+               dbus_message_unref (message);
+               _DBUS_SET_OOM (error);
+               return -1;
+       }
 
-               reply = dbus_connection_send_with_reply_and_block (connection, message, -1,
+       reply = dbus_connection_send_with_reply_and_block (connection, message, -1,
                                                                                                                 error);
 
-               dbus_message_unref (message);
+       dbus_message_unref (message);
 
-               if (reply == NULL)
-               {
-                 _DBUS_ASSERT_ERROR_IS_SET (error);
-                 return -1;
-               }
+       if (reply == NULL)
+       {
+               _DBUS_ASSERT_ERROR_IS_SET (error);
+               return -1;
+       }
 
-               if (dbus_set_error_from_message (error, reply))
-               {
-                 _DBUS_ASSERT_ERROR_IS_SET (error);
-                 dbus_message_unref (reply);
-                 return -1;
-               }
+       if (dbus_set_error_from_message (error, reply))
+       {
+               _DBUS_ASSERT_ERROR_IS_SET (error);
+               dbus_message_unref (reply);
+               return -1;
+       }
 
-               if (!dbus_message_get_args (reply, error,
+       if (!dbus_message_get_args (reply, error,
                                                                  DBUS_TYPE_UINT32, &result,
                                                                  DBUS_TYPE_INVALID))
-               {
-                 _DBUS_ASSERT_ERROR_IS_SET (error);
-                 dbus_message_unref (reply);
-                 return -1;
-               }
-
+       {
+               _DBUS_ASSERT_ERROR_IS_SET (error);
                dbus_message_unref (reply);
+               return -1;
        }
-       else
-       {
-               if(!bus_register_policy_kdbus(name, connection, error))
-                       return -1;
 
-               result = bus_request_name_kdbus(connection, name, flags, error);
-       }
-  
+       dbus_message_unref (reply);
        return result;
 }
 
@@ -1563,37 +1546,32 @@ dbus_bus_add_match (DBusConnection *connection,
                     const char     *rule,
                     DBusError      *error)
 {
-       _dbus_return_if_fail (rule != NULL);
+       DBusMessage *msg;
 
-       if(!dbus_transport_is_kdbus(connection))
-       {
-               DBusMessage *msg;
+       _dbus_return_if_fail (rule != NULL);
 
-               msg = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
+       msg = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
                                       DBUS_PATH_DBUS,
                                       DBUS_INTERFACE_DBUS,
                                       "AddMatch");
 
-         if (msg == NULL)
-               {
-                 _DBUS_SET_OOM (error);
-                 return;
-               }
+       if (msg == NULL)
+       {
+               _DBUS_SET_OOM (error);
+               return;
+       }
 
-         if (!dbus_message_append_args (msg, DBUS_TYPE_STRING, &rule,
+       if (!dbus_message_append_args (msg, DBUS_TYPE_STRING, &rule,
                                                                         DBUS_TYPE_INVALID))
-               {
-                 dbus_message_unref (msg);
-                 _DBUS_SET_OOM (error);
-                 return;
-               }
+       {
+               dbus_message_unref (msg);
+               _DBUS_SET_OOM (error);
+               return;
+       }
 
-         send_no_return_values (connection, msg, error);
+       send_no_return_values (connection, msg, error);
 
-         dbus_message_unref (msg);
-       }
-       else
-               dbus_bus_add_match_kdbus(connection, rule, error);
+       dbus_message_unref (msg);
 }
 
 /**
@@ -1618,31 +1596,26 @@ dbus_bus_remove_match (DBusConnection *connection,
                        const char     *rule,
                        DBusError      *error)
 {
-       if(!dbus_transport_is_kdbus(connection))
-       {
-               DBusMessage *msg;
+       DBusMessage *msg;
 
-         _dbus_return_if_fail (rule != NULL);
+       _dbus_return_if_fail (rule != NULL);
 
-         msg = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
+       msg = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
                                                                                  DBUS_PATH_DBUS,
                                                                                  DBUS_INTERFACE_DBUS,
                                                                                  "RemoveMatch");
 
-         if (!dbus_message_append_args (msg, DBUS_TYPE_STRING, &rule,
+       if (!dbus_message_append_args (msg, DBUS_TYPE_STRING, &rule,
                                                                         DBUS_TYPE_INVALID))
-               {
-                 dbus_message_unref (msg);
-                 _DBUS_SET_OOM (error);
-                 return;
-               }
+       {
+               dbus_message_unref (msg);
+               _DBUS_SET_OOM (error);
+               return;
+       }
 
-         send_no_return_values (connection, msg, error);
+       send_no_return_values (connection, msg, error);
 
-         dbus_message_unref (msg);
-       }
-       else
-               dbus_bus_remove_match_kdbus(connection, error);
+       dbus_message_unref (msg);
 }
 
 /** @} */