2005-11-15 Robert McQueen <robot101@debian.org>
[platform/upstream/dbus.git] / dbus / dbus-bus.c
index ea6a8bb..9016f1b 100644 (file)
@@ -4,7 +4,7 @@
  * Copyright (C) 2003  CodeFactory AB
  * Copyright (C) 2003  Red Hat, Inc.
  *
- * Licensed under the Academic Free License version 2.0
+ * Licensed under the Academic Free License version 2.1
  * 
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -26,6 +26,8 @@
 #include "dbus-protocol.h"
 #include "dbus-internals.h"
 #include "dbus-message.h"
+#include "dbus-marshal-validate.h"
+#include "dbus-threads-internal.h"
 #include <string.h>
 
 /**
  * Block of message-bus-related data we attach to each
  * #DBusConnection used with these convenience functions.
  *
- *
- * @todo get rid of most of these; they should be done
- * with DBusGProxy and the Qt equivalent, i.e. the same
- * way any other interface would be used.
  */
 typedef struct
 {
   DBusConnection *connection; /**< Connection we're associated with */
-  char *base_service; /**< Base service name of this connection */
+  char *unique_name; /**< Unique name of this connection */
 
   unsigned int is_well_known : 1; /**< Is one of the well-known connections in our global array */
 } BusData;
@@ -76,7 +74,7 @@ static dbus_int32_t bus_data_slot = -1;
 static DBusConnection *bus_connections[N_BUS_TYPES];
 static char *bus_connection_addresses[N_BUS_TYPES] = { NULL, NULL, NULL };
 
-static DBusBusType activation_bus_type = DBUS_BUS_ACTIVATION;
+static DBusBusType activation_bus_type = DBUS_BUS_STARTER;
 
 static dbus_bool_t initialized = FALSE;
 
@@ -101,7 +99,7 @@ addresses_shutdown_func (void *data)
       ++i;
     }
 
-  activation_bus_type = DBUS_BUS_ACTIVATION;
+  activation_bus_type = DBUS_BUS_STARTER;
 }
 
 static dbus_bool_t
@@ -180,22 +178,22 @@ init_connections_unlocked (void)
                          bus_connection_addresses[DBUS_BUS_SESSION] : "none set");
         }
 
-      if (bus_connection_addresses[DBUS_BUS_ACTIVATION] == NULL)
+      if (bus_connection_addresses[DBUS_BUS_STARTER] == NULL)
         {
           _dbus_verbose ("Filling in activation bus address...\n");
           
-          if (!get_from_env (&bus_connection_addresses[DBUS_BUS_ACTIVATION],
-                             "DBUS_ACTIVATION_ADDRESS"))
+          if (!get_from_env (&bus_connection_addresses[DBUS_BUS_STARTER],
+                             "DBUS_STARTER_ADDRESS"))
             return FALSE;
           
-          _dbus_verbose ("  \"%s\"\n", bus_connection_addresses[DBUS_BUS_ACTIVATION] ?
-                         bus_connection_addresses[DBUS_BUS_ACTIVATION] : "none set");
+          _dbus_verbose ("  \"%s\"\n", bus_connection_addresses[DBUS_BUS_STARTER] ?
+                         bus_connection_addresses[DBUS_BUS_STARTER] : "none set");
         }
 
 
-      if (bus_connection_addresses[DBUS_BUS_ACTIVATION] != NULL)
+      if (bus_connection_addresses[DBUS_BUS_STARTER] != NULL)
         {
-          s = _dbus_getenv ("DBUS_ACTIVATION_BUS_TYPE");
+          s = _dbus_getenv ("DBUS_STARTER_BUS_TYPE");
               
           if (s != NULL)
             {
@@ -212,9 +210,9 @@ init_connections_unlocked (void)
           /* Default to the session bus instead if available */
           if (bus_connection_addresses[DBUS_BUS_SESSION] != NULL)
             {
-              bus_connection_addresses[DBUS_BUS_ACTIVATION] =
+              bus_connection_addresses[DBUS_BUS_STARTER] =
                 _dbus_strdup (bus_connection_addresses[DBUS_BUS_SESSION]);
-              if (bus_connection_addresses[DBUS_BUS_ACTIVATION] == NULL)
+              if (bus_connection_addresses[DBUS_BUS_STARTER] == NULL)
                 return FALSE;
             }
         }
@@ -260,7 +258,7 @@ bus_data_free (void *data)
       _DBUS_UNLOCK (bus);
     }
   
-  dbus_free (bd->base_service);
+  dbus_free (bd->unique_name);
   dbus_free (bd);
 
   dbus_connection_free_data_slot (&bus_data_slot);
@@ -304,26 +302,9 @@ ensure_bus_data (DBusConnection *connection)
   return bd;
 }
 
-/** @} */ /* end of implementation details docs */
-
-/**
- * @addtogroup DBusBus
- * @{
- */
-
-/**
- * Connects to a bus daemon and registers the client with it.
- * If a connection to the bus already exists, then that connection is returned.
- *
- * @todo alex thinks we should nullify the connection when we get a disconnect-message.
- *
- * @param type bus type
- * @param error address where an error can be returned.
- * @returns a DBusConnection
- */
-DBusConnection *
-dbus_bus_get (DBusBusType  type,
-             DBusError   *error)
+static DBusConnection *
+internal_bus_get (DBusBusType  type,
+             DBusError   *error, dbus_bool_t private)
 {
   const char *address;
   DBusConnection *connection;
@@ -338,7 +319,7 @@ dbus_bus_get (DBusBusType  type,
   if (!init_connections_unlocked ())
     {
       _DBUS_UNLOCK (bus);
-      dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
+      _DBUS_SET_OOM (error);
       return NULL;
     }
 
@@ -351,13 +332,13 @@ dbus_bus_get (DBusBusType  type,
   /* Use the real type of the activation bus for getting its
    * connection, but only if the real type's address is available. (If
    * the activating bus isn't a well-known bus then
-   * activation_bus_type == DBUS_BUS_ACTIVATION)
+   * activation_bus_type == DBUS_BUS_STARTER)
    */
-  if (type == DBUS_BUS_ACTIVATION &&
+  if (type == DBUS_BUS_STARTER &&
       bus_connection_addresses[activation_bus_type] != NULL)
     type = activation_bus_type;
   
-  if (bus_connections[type] != NULL)
+  if (!private && bus_connections[type] != NULL)
     {
       connection = bus_connections[type];
       dbus_connection_ref (connection);
@@ -375,7 +356,10 @@ dbus_bus_get (DBusBusType  type,
       return NULL;
     }
 
-  connection = dbus_connection_open (address, error);
+  if (private)
+    connection = dbus_connection_open_private(address, error);
+  else
+    connection = dbus_connection_open (address, error);
   
   if (!connection)
     {
@@ -393,14 +377,16 @@ dbus_bus_get (DBusBusType  type,
   if (!dbus_bus_register (connection, error))
     {
       _DBUS_ASSERT_ERROR_IS_SET (error);
-      dbus_connection_disconnect (connection);
+      dbus_connection_close (connection);
       dbus_connection_unref (connection);
 
       _DBUS_UNLOCK (bus);
       return NULL;
     }
 
-  bus_connections[type] = connection;
+  if (!private)
+    bus_connections[type] = connection;
+  
   bd = ensure_bus_data (connection);
   _dbus_assert (bd != NULL);
 
@@ -411,14 +397,51 @@ dbus_bus_get (DBusBusType  type,
 }
 
 
+/** @} */ /* end of implementation details docs */
+
+/**
+ * @addtogroup DBusBus
+ * @{
+ */
+
+/**
+ * Connects to a bus daemon and registers the client with it.  If a
+ * connection to the bus already exists, then that connection is
+ * returned.  Caller owns a reference to the bus.
+ *
+ * @todo alex thinks we should nullify the connection when we get a disconnect-message.
+ *
+ * @param type bus type
+ * @param error address where an error can be returned.
+ * @returns a DBusConnection with new ref
+ */
+DBusConnection *
+dbus_bus_get (DBusBusType  type,
+             DBusError   *error) {
+  return internal_bus_get(type, error, FALSE);
+}
+
+/**
+ * Connects to a bus daemon and registers the client with it.  Unlike
+ * dbus_bus_get(), always creates a new connection. This connection
+ * will not be saved or recycled by libdbus. Caller owns a reference
+ * to the bus.
+ *
+ * @param type bus type
+ * @param error address where an error can be returned.
+ * @returns a DBusConnection with new ref
+ */
+DBusConnection *
+dbus_bus_get_private (DBusBusType  type,
+             DBusError   *error) {
+  return internal_bus_get(type, error, TRUE);
+}
+
 /**
  * Registers a connection with the bus. This must be the first
  * thing an application does when connecting to the message bus.
- * If registration succeeds, the base service name will be set,
- * and can be obtained using dbus_bus_get_base_service().
- *
- * @todo if we get an error reply, it has to be converted into
- * DBusError and returned
+ * If registration succeeds, the unique name will be set,
+ * and can be obtained using dbus_bus_get_unique_name().
  * 
  * @param connection the connection
  * @param error place to store errors
@@ -445,7 +468,7 @@ dbus_bus_register (DBusConnection *connection,
       return FALSE;
     }
 
-  if (bd->base_service != NULL)
+  if (bd->unique_name != NULL)
     {
       _dbus_warn ("Attempt to register the same DBusConnection with the message bus, but it is already registered\n");
       /* This isn't an error, it's a programming bug. We'll be nice
@@ -454,9 +477,9 @@ dbus_bus_register (DBusConnection *connection,
       return TRUE;
     }
   
-  message = dbus_message_new_method_call (DBUS_SERVICE_ORG_FREEDESKTOP_DBUS,
-                                          DBUS_PATH_ORG_FREEDESKTOP_DBUS,
-                                          DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS,
+  message = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
+                                          DBUS_PATH_DBUS,
+                                          DBUS_INTERFACE_DBUS,
                                           "Hello"); 
 
   if (!message)
@@ -478,8 +501,13 @@ dbus_bus_register (DBusConnection *connection,
                                    DBUS_TYPE_INVALID))
     goto out;
   
-  bd->base_service = name;
-
+  bd->unique_name = _dbus_strdup (name);
+  if (bd->unique_name == NULL)
+    {
+      _DBUS_SET_OOM (error);
+      goto out;
+    }
+  
   retval = TRUE;
   
  out:
@@ -494,45 +522,45 @@ dbus_bus_register (DBusConnection *connection,
 
 
 /**
- * Sets the base service name of the connection.
- * Can only be used if you registered with the
- * bus manually (i.e. if you did not call
- * dbus_bus_register()). Can only be called
- * once per connection.
+ * Sets the unique name of the connection.  Can only be used if you
+ * registered with the bus manually (i.e. if you did not call
+ * dbus_bus_register()). Can only be called once per connection.
  *
  * @param connection the connection
- * @param base_service the base service name
+ * @param unique_name the unique name
  * @returns #FALSE if not enough memory
  */
 dbus_bool_t
-dbus_bus_set_base_service (DBusConnection *connection,
-                           const char     *base_service)
+dbus_bus_set_unique_name (DBusConnection *connection,
+                          const char     *unique_name)
 {
   BusData *bd;
 
   _dbus_return_val_if_fail (connection != NULL, FALSE);
-  _dbus_return_val_if_fail (base_service != NULL, FALSE);
+  _dbus_return_val_if_fail (unique_name != NULL, FALSE);
   
   bd = ensure_bus_data (connection);
   if (bd == NULL)
     return FALSE;
 
-  _dbus_assert (bd->base_service == NULL);
+  _dbus_assert (bd->unique_name == NULL);
   
-  bd->base_service = _dbus_strdup (base_service);
-  return bd->base_service != NULL;
+  bd->unique_name = _dbus_strdup (unique_name);
+  return bd->unique_name != NULL;
 }
 
 /**
- * Gets the base service name of the connection.
- * Only possible after the connection has been registered
- * with the message bus.
+ * Gets the unique name of the connection.  Only possible after the
+ * connection has been registered with the message bus.
  *
+ * The name remains valid for the duration of the connection and
+ * should not be freed by the caller.
+ * 
  * @param connection the connection
- * @returns the base service name
+ * @returns the unique name or NULL on error
  */
 const char*
-dbus_bus_get_base_service (DBusConnection *connection)
+dbus_bus_get_unique_name (DBusConnection *connection)
 {
   BusData *bd;
 
@@ -542,41 +570,164 @@ dbus_bus_get_base_service (DBusConnection *connection)
   if (bd == NULL)
     return NULL;
   
-  return bd->base_service;
+  return bd->unique_name;
+}
+
+/**
+ * Asks the bus to return the uid of the named
+ * connection.
+ *
+ * @param connection the connection
+ * @param name a name owned by the connection
+ * @param error location to store the error
+ * @returns a result code, -1 if error is set
+ */ 
+unsigned long
+dbus_bus_get_unix_user (DBusConnection *connection,
+                        const char     *name,
+                        DBusError      *error)
+{
+  DBusMessage *message, *reply;
+  dbus_uint32_t uid;
+
+  _dbus_return_val_if_fail (connection != NULL, DBUS_UID_UNSET);
+  _dbus_return_val_if_fail (name != NULL, DBUS_UID_UNSET);
+  _dbus_return_val_if_fail (_dbus_check_is_valid_bus_name (name), DBUS_UID_UNSET);
+  _dbus_return_val_if_error_is_set (error, DBUS_UID_UNSET);
+  
+  message = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
+                                          DBUS_PATH_DBUS,
+                                          DBUS_INTERFACE_DBUS,
+                                          "GetConnectionUnixUser");
+
+  if (message == NULL)
+    {
+      _DBUS_SET_OOM (error);
+      return DBUS_UID_UNSET;
+    }
+  if (!dbus_message_append_args (message,
+                                DBUS_TYPE_STRING, &name,
+                                DBUS_TYPE_INVALID))
+    {
+      dbus_message_unref (message);
+      _DBUS_SET_OOM (error);
+      return DBUS_UID_UNSET;
+    }
+  
+  reply = dbus_connection_send_with_reply_and_block (connection, message, -1,
+                                                     error);
+  
+  dbus_message_unref (message);
+  
+  if (reply == NULL)
+    {
+      _DBUS_ASSERT_ERROR_IS_SET (error);
+      return DBUS_UID_UNSET;
+    }  
+
+  if (dbus_set_error_from_message (error, reply))
+    {
+      _DBUS_ASSERT_ERROR_IS_SET (error);
+      dbus_message_unref (reply);
+      return DBUS_UID_UNSET;
+    }
+  
+  if (!dbus_message_get_args (reply, error,
+                              DBUS_TYPE_UINT32, &uid,
+                              DBUS_TYPE_INVALID))
+    {
+      _DBUS_ASSERT_ERROR_IS_SET (error);
+      dbus_message_unref (reply);
+      return DBUS_UID_UNSET;
+    }
+
+  dbus_message_unref (reply);
+  
+  return (unsigned long) uid;
 }
 
+
 /**
- * Asks the bus to try to acquire a certain service.
+ * Asks the bus to assign the given name to this connection by invoking
+ * the RequestName method on the bus. This method is fully documented
+ * in the D-BUS specification. For quick reference, the flags and
+ * result codes are discussed here, but the specification is the
+ * canonical version of this information.
+ *
+ * The #DBUS_NAME_FLAG_PROHIBIT_REPLACEMENT flag indicates that
+ * if the name is successfully requested, other applications
+ * will not be able to take over the name. i.e. the name's
+ * owner (the application calling this function) must let go of
+ * the name, it will not lose it involuntarily.
+ *
+ * The #DBUS_NAME_FLAG_REPLACE_EXISTING flag indicates that the caller
+ * would like to take over the name from the current owner.
+ * If the current name owner used #DBUS_NAME_FLAG_PROHIBIT_REPLACEMENT
+ * then this flag indicates that the caller would like to be placed
+ * in the queue to own the name when the current owner lets go.
  *
- * @todo these docs are not complete, need to document the
- * return value and flags
+ * If no flags are given, an application will receive the requested
+ * name only if the name is currently unowned; and it will give
+ * up the name if another application asks to take it over using
+ * #DBUS_NAME_FLAG_REPLACE_EXISTING.
+ *
+ * This function returns a result code. The possible result codes
+ * are as follows.
  * 
- * @todo if we get an error reply, it has to be converted into
- * DBusError and returned
+ * #DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER means that the name had no
+ * existing owner, and the caller is now the primary owner; or that
+ * the name had an owner, and the caller specified
+ * #DBUS_NAME_FLAG_REPLACE_EXISTING, and the current owner did not
+ * specify #DBUS_NAME_FLAG_PROHIBIT_REPLACEMENT.
+ *
+ * #DBUS_REQUEST_NAME_REPLY_IN_QUEUE happens only if the current owner
+ * specified #DBUS_NAME_FLAG_PROHIBIT_REPLACEMENT and the caller specified
+ * #DBUS_NAME_FLAG_REPLACE_EXISTING. In this case the caller ends up in
+ * a queue to own the name after the current owner gives it up.
+ *
+ * #DBUS_REQUEST_NAME_REPLY_EXISTS happens if the name has an owner
+ * #already and DBUS_NAME_FLAG_REPLACE_EXISTING was not specified.
  *
+ * #DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER happens if an application
+ * requests a name it already owns.
+ *
+ * When a service represents an application, say "text editor," then
+ * it should specify #DBUS_NAME_FLAG_PROHIBIT_REPLACEMENT if it wants
+ * the first editor started to be the user's editor vs. the last one
+ * started.  Then any editor that can be the user's editor should
+ * specify #DBUS_NAME_FLAG_REPLACE_EXISTING to either take over
+ * (last-started-wins) or be queued up (first-started-wins) according
+ * to whether #DBUS_NAME_FLAG_PROHIBIT_REPLACEMENT was given.
+ * 
+ * @todo this all seems sort of broken. Shouldn't the flags be a property
+ * of the name, not the app requesting the name? What are the use-cases
+ * other than the "text editor" thing and how are we supporting them?
+ * 
  * @param connection the connection
- * @param service_name the service name
+ * @param name the name to request
  * @param flags flags
  * @param error location to store the error
  * @returns a result code, -1 if error is set
  */ 
 int
-dbus_bus_acquire_service (DBusConnection *connection,
-                         const char     *service_name,
-                         unsigned int    flags,
-                          DBusError      *error)
+dbus_bus_request_name (DBusConnection *connection,
+                       const char     *name,
+                       unsigned int    flags,
+                       DBusError      *error)
 {
   DBusMessage *message, *reply;
-  dbus_uint32_t service_result;
+  dbus_uint32_t result;
 
   _dbus_return_val_if_fail (connection != NULL, 0);
-  _dbus_return_val_if_fail (service_name != 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);
   
-  message = dbus_message_new_method_call (DBUS_SERVICE_ORG_FREEDESKTOP_DBUS,
-                                          DBUS_PATH_ORG_FREEDESKTOP_DBUS,
-                                          DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS,
-                                          "AcquireService");
+  message = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
+                                          DBUS_PATH_DBUS,
+                                          DBUS_INTERFACE_DBUS,
+                                          "RequestName");
 
   if (message == NULL)
     {
@@ -585,8 +736,8 @@ dbus_bus_acquire_service (DBusConnection *connection,
     }
  
   if (!dbus_message_append_args (message,
-                                DBUS_TYPE_STRING, service_name,
-                                DBUS_TYPE_UINT32, flags,
+                                DBUS_TYPE_STRING, &name,
+                                DBUS_TYPE_UINT32, &flags,
                                 DBUS_TYPE_INVALID))
     {
       dbus_message_unref (message);
@@ -613,7 +764,7 @@ dbus_bus_acquire_service (DBusConnection *connection,
     }
   
   if (!dbus_message_get_args (reply, error,
-                              DBUS_TYPE_UINT32, &service_result,
+                              DBUS_TYPE_UINT32, &result,
                               DBUS_TYPE_INVALID))
     {
       _DBUS_ASSERT_ERROR_IS_SET (error);
@@ -623,35 +774,99 @@ dbus_bus_acquire_service (DBusConnection *connection,
 
   dbus_message_unref (reply);
   
-  return service_result;
+  return result;
+}
+
+int
+dbus_bus_release_name (DBusConnection *connection,
+                       const char     *name,
+                       DBusError      *error)
+{
+  DBusMessage *message, *reply;
+  dbus_uint32_t result;
+
+  _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);
+
+  message = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
+                                          DBUS_PATH_DBUS,
+                                          DBUS_INTERFACE_DBUS,
+                                          "ReleaseName");
+
+  if (message == NULL)
+    {
+      _DBUS_SET_OOM (error);
+      return -1;
+    }
+
+  if (!dbus_message_append_args (message,
+                                 DBUS_TYPE_STRING, &name,
+                                 DBUS_TYPE_INVALID))
+    {
+      dbus_message_unref (message);
+      _DBUS_SET_OOM (error);
+      return -1;
+    }
+
+  reply = dbus_connection_send_with_reply_and_block (connection, message, -1,
+                                                     error);
+
+  dbus_message_unref (message);
+
+  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_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_message_unref (reply);
+
+  return result;
 }
 
 /**
- * Checks whether a certain service exists.
- *
- * @todo the SERVICE_EXISTS message should use BOOLEAN not UINT32
+ * Checks whether a certain name has an owner.
  *
  * @param connection the connection
- * @param service_name the service name
+ * @param name the name
  * @param error location to store any errors
- * @returns #TRUE if the service exists, #FALSE if not or on error
+ * @returns #TRUE if the name exists, #FALSE if not or on error
  */
 dbus_bool_t
-dbus_bus_service_exists (DBusConnection *connection,
-                        const char     *service_name,
+dbus_bus_name_has_owner (DBusConnection *connection,
+                        const char     *name,
                          DBusError      *error)
 {
   DBusMessage *message, *reply;
-  unsigned int exists;
+  dbus_bool_t exists;
 
   _dbus_return_val_if_fail (connection != NULL, FALSE);
-  _dbus_return_val_if_fail (service_name != NULL, FALSE);
+  _dbus_return_val_if_fail (name != NULL, FALSE);
+  _dbus_return_val_if_fail (_dbus_check_is_valid_bus_name (name), FALSE);
   _dbus_return_val_if_error_is_set (error, FALSE);
   
-  message = dbus_message_new_method_call (DBUS_SERVICE_ORG_FREEDESKTOP_DBUS,
-                                          DBUS_PATH_ORG_FREEDESKTOP_DBUS,
-                                          DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS,
-                                          "ServiceExists");
+  message = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
+                                          DBUS_PATH_DBUS,
+                                          DBUS_INTERFACE_DBUS,
+                                          "NameHasOwner");
   if (message == NULL)
     {
       _DBUS_SET_OOM (error);
@@ -659,7 +874,7 @@ dbus_bus_service_exists (DBusConnection *connection,
     }
   
   if (!dbus_message_append_args (message,
-                                DBUS_TYPE_STRING, service_name,
+                                DBUS_TYPE_STRING, &name,
                                 DBUS_TYPE_INVALID))
     {
       dbus_message_unref (message);
@@ -677,48 +892,54 @@ dbus_bus_service_exists (DBusConnection *connection,
     }
 
   if (!dbus_message_get_args (reply, error,
-                              DBUS_TYPE_UINT32, &exists,
+                              DBUS_TYPE_BOOLEAN, &exists,
                               DBUS_TYPE_INVALID))
     {
       _DBUS_ASSERT_ERROR_IS_SET (error);
+      dbus_message_unref (reply);
       return FALSE;
     }
   
-  return (exists != FALSE);
+  dbus_message_unref (reply);
+  return exists;
 }
 
 /**
- * Activates a given service
+ * Starts a service that will request ownership of the given name.
+ * The returned result will be one of be one of
+ * #DBUS_START_REPLY_SUCCESS or #DBUS_START_REPLY_ALREADY_RUNNING if
+ * successful.  Pass #NULL if you don't care about the result.
+ * 
+ * The flags parameter is for future expansion, currently you should
+ * specify 0.
  *
  * @param connection the connection
- * @param service_name the service name
- * @param flags the flags
- * @param result a place to store the result of the activation, which will
- * be one of DBUS_ACTIVATION_REPLY_ACTIVATED or
- * DBUS_ACTIVATION_REPLY_ALREADY_ACTIVE if successful.  Pass NULL if you
- * don't care about the result.
+ * @param name the name we want the new service to request
+ * @param flags the flags (should always be 0 for now)
+ * @param result a place to store the result or #NULL
  * @param error location to store any errors
  * @returns #TRUE if the activation succeeded, #FALSE if not
- *
- * @todo document what the flags do
  */
 dbus_bool_t
-dbus_bus_activate_service (DBusConnection *connection,
-                          const char     *service_name,
-                          dbus_uint32_t   flags,
-                          dbus_uint32_t  *result,
-                          DBusError      *error)
+dbus_bus_start_service_by_name (DBusConnection *connection,
+                                const char     *name,
+                                dbus_uint32_t   flags,
+                                dbus_uint32_t  *result,
+                                DBusError      *error)
 {
   DBusMessage *msg;
   DBusMessage *reply;
 
-  msg = dbus_message_new_method_call (DBUS_SERVICE_ORG_FREEDESKTOP_DBUS,
-                                      DBUS_PATH_ORG_FREEDESKTOP_DBUS,
-                                      DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS,
-                                      "ActivateService");
+  _dbus_return_val_if_fail (connection != NULL, FALSE);
+  _dbus_return_val_if_fail (_dbus_check_is_valid_bus_name (name), FALSE);
+  
+  msg = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
+                                      DBUS_PATH_DBUS,
+                                      DBUS_INTERFACE_DBUS,
+                                      "StartServiceByName");
 
-  if (!dbus_message_append_args (msg, DBUS_TYPE_STRING, service_name,
-                                DBUS_TYPE_UINT32, flags, DBUS_TYPE_INVALID))
+  if (!dbus_message_append_args (msg, DBUS_TYPE_STRING, &name,
+                                DBUS_TYPE_UINT32, &flags, DBUS_TYPE_INVALID))
     {
       dbus_message_unref (msg);
       _DBUS_SET_OOM (error);
@@ -769,25 +990,15 @@ send_no_return_values (DBusConnection *connection,
                                                          -1, error);
       
       if (reply == NULL)
-        {
-          _DBUS_ASSERT_ERROR_IS_SET (error);
-          return;
-        }
-
-      if (dbus_set_error_from_message (error, reply))
-        {
-          _DBUS_ASSERT_ERROR_IS_SET (error);
-          dbus_message_unref (reply);
-          return;
-        }
-
-      dbus_message_unref (reply);
+        _DBUS_ASSERT_ERROR_IS_SET (error);
+      else
+        dbus_message_unref (reply);
     }
   else
     {
       /* Silently-fail nonblocking codepath */
-      if (!dbus_connection_send (connection, msg, NULL))
-        return;
+      dbus_message_set_no_reply (msg, TRUE);
+      dbus_connection_send (connection, msg, NULL);
     }
 }
 
@@ -820,12 +1031,20 @@ dbus_bus_add_match (DBusConnection *connection,
 {
   DBusMessage *msg;
 
-  msg = dbus_message_new_method_call (DBUS_SERVICE_ORG_FREEDESKTOP_DBUS,
-                                      DBUS_PATH_ORG_FREEDESKTOP_DBUS,
-                                      DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS,
+  _dbus_return_if_fail (rule != NULL);
+
+  msg = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
+                                      DBUS_PATH_DBUS,
+                                      DBUS_INTERFACE_DBUS,
                                       "AddMatch");
 
-  if (!dbus_message_append_args (msg, DBUS_TYPE_STRING, rule,
+  if (msg == NULL)
+    {
+      _DBUS_SET_OOM (error);
+      return;
+    }
+
+  if (!dbus_message_append_args (msg, DBUS_TYPE_STRING, &rule,
                                  DBUS_TYPE_INVALID))
     {
       dbus_message_unref (msg);
@@ -858,12 +1077,14 @@ dbus_bus_remove_match (DBusConnection *connection,
 {
   DBusMessage *msg;
 
-  msg = dbus_message_new_method_call (DBUS_SERVICE_ORG_FREEDESKTOP_DBUS,
-                                      DBUS_PATH_ORG_FREEDESKTOP_DBUS,
-                                      DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS,
+  _dbus_return_if_fail (rule != NULL);
+  
+  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);