27#include "dbus-protocol.h"
28#include "dbus-internals.h"
29#include "dbus-message.h"
30#include "dbus-marshal-validate.h"
32#include "dbus-threads-internal.h"
33#include "dbus-connection-internal.h"
34#include "dbus-string.h"
88static dbus_int32_t bus_data_slot = -1;
101addresses_shutdown_func (
void *data)
108 if (bus_connections[i] !=
NULL)
109 _dbus_warn_check_failed (
"dbus_shutdown() called but connections were still live. This probably means the application did not drop all its references to bus connections.");
112 bus_connection_addresses[i] =
NULL;
122get_from_env (
char **connection_p,
130 if (s ==
NULL || *s ==
'\0')
135 return *connection_p !=
NULL;
140init_session_address (
void)
149 "DBUS_SESSION_BUS_ADDRESS");
165 if (supported && retval)
169 else if (supported && !retval)
174 _dbus_warn (
"Dynamic session lookup supported but failed silently");
197init_connections_unlocked (
void)
207 bus_connections[i] =
NULL;
220 _dbus_verbose (
"Filling in system bus address...\n");
223 "DBUS_SYSTEM_BUS_ADDRESS"))
237 _dbus_verbose (
" used default system bus \"%s\"\n",
241 _dbus_verbose (
" used env var system bus \"%s\"\n",
246 _dbus_verbose (
"Filling in session bus address...\n");
248 if (!init_session_address ())
257 _dbus_verbose (
"Filling in activation bus address...\n");
260 "DBUS_STARTER_ADDRESS"))
274 _dbus_verbose (
"Bus activation type was set to \"%s\"\n", s);
276 if (strcmp (s,
"system") == 0)
278 else if (strcmp (s,
"session") == 0)
309bus_data_free (
void *data)
319 "when we attached bus data");
330 bus_connections[i] =
NULL;
407 if (bus_connections[i] == connection)
409 bus_connections[i] =
NULL;
427 _dbus_return_val_if_error_is_set (error,
NULL);
433 _DBUS_SET_OOM (error);
438 if (!init_connections_unlocked ())
440 _DBUS_SET_OOM (error);
456 bus_connection_addresses[activation_bus_type] !=
NULL)
457 type = activation_bus_type;
459 if (!
private && bus_connections[type] !=
NULL)
461 connection = bus_connections[type];
466 address = bus_connection_addresses[address_type];
470 "Unable to determine the address of the message bus (try 'man dbus-launch' and 'man dbus-daemon' for help)");
498 bus_connections[type] = connection;
510 bd = ensure_bus_data (connection);
518 if (connection ==
NULL)
519 _DBUS_ASSERT_ERROR_IS_SET (error);
562 return internal_bus_get (type,
FALSE, error);
594 return internal_bus_get (type,
TRUE, error);
655 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
656 _dbus_return_val_if_error_is_set (error,
FALSE);
664 _DBUS_SET_OOM (error);
669 bd = ensure_bus_data (connection);
672 _DBUS_SET_OOM (error);
678 _dbus_verbose (
"Ignoring attempt to register the same DBusConnection %s with the message bus a second time.\n",
692 _DBUS_SET_OOM (error);
710 _DBUS_SET_OOM (error);
726 _DBUS_ASSERT_ERROR_IS_SET (error);
768 const char *unique_name)
773 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
774 _dbus_return_val_if_fail (unique_name !=
NULL,
FALSE);
782 bd = ensure_bus_data (connection);
819 const char *unique_name =
NULL;
821 _dbus_return_val_if_fail (connection !=
NULL,
NULL);
830 bd = ensure_bus_data (connection);
875 _dbus_return_val_if_fail (_dbus_check_is_valid_bus_name (name),
DBUS_UID_UNSET);
881 "GetConnectionUnixUser");
885 _DBUS_SET_OOM (error);
894 _DBUS_SET_OOM (error);
905 _DBUS_ASSERT_ERROR_IS_SET (error);
911 _DBUS_ASSERT_ERROR_IS_SET (error);
920 _DBUS_ASSERT_ERROR_IS_SET (error);
927 return (
unsigned long) uid;
954 const char *v_STRING;
956 _dbus_return_val_if_fail (connection !=
NULL,
NULL);
957 _dbus_return_val_if_error_is_set (error,
NULL);
966 _DBUS_SET_OOM (error);
977 _DBUS_ASSERT_ERROR_IS_SET (error);
983 _DBUS_ASSERT_ERROR_IS_SET (error);
993 _DBUS_ASSERT_ERROR_IS_SET (error);
1003 _DBUS_SET_OOM (error);
1119 dbus_uint32_t result;
1121 _dbus_return_val_if_fail (connection !=
NULL, 0);
1122 _dbus_return_val_if_fail (name !=
NULL, 0);
1123 _dbus_return_val_if_fail (_dbus_check_is_valid_bus_name (name), 0);
1124 _dbus_return_val_if_error_is_set (error, 0);
1131 if (message ==
NULL)
1133 _DBUS_SET_OOM (error);
1143 _DBUS_SET_OOM (error);
1154 _DBUS_ASSERT_ERROR_IS_SET (error);
1160 _DBUS_ASSERT_ERROR_IS_SET (error);
1169 _DBUS_ASSERT_ERROR_IS_SET (error);
1204 dbus_uint32_t result;
1206 _dbus_return_val_if_fail (connection !=
NULL, 0);
1207 _dbus_return_val_if_fail (name !=
NULL, 0);
1208 _dbus_return_val_if_fail (_dbus_check_is_valid_bus_name (name), 0);
1209 _dbus_return_val_if_error_is_set (error, 0);
1216 if (message ==
NULL)
1218 _DBUS_SET_OOM (error);
1227 _DBUS_SET_OOM (error);
1238 _DBUS_ASSERT_ERROR_IS_SET (error);
1244 _DBUS_ASSERT_ERROR_IS_SET (error);
1253 _DBUS_ASSERT_ERROR_IS_SET (error);
1288 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
1289 _dbus_return_val_if_fail (name !=
NULL,
FALSE);
1290 _dbus_return_val_if_fail (_dbus_check_is_valid_bus_name (name),
FALSE);
1291 _dbus_return_val_if_error_is_set (error,
FALSE);
1297 if (message ==
NULL)
1299 _DBUS_SET_OOM (error);
1308 _DBUS_SET_OOM (error);
1317 _DBUS_ASSERT_ERROR_IS_SET (error);
1325 _DBUS_ASSERT_ERROR_IS_SET (error);
1359 dbus_uint32_t flags,
1360 dbus_uint32_t *result,
1366 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
1367 _dbus_return_val_if_fail (_dbus_check_is_valid_bus_name (name),
FALSE);
1372 "StartServiceByName");
1378 _DBUS_SET_OOM (error);
1388 _DBUS_ASSERT_ERROR_IS_SET (error);
1394 _DBUS_ASSERT_ERROR_IS_SET (error);
1399 if (result !=
NULL &&
1403 _DBUS_ASSERT_ERROR_IS_SET (error);
1426 _DBUS_ASSERT_ERROR_IS_SET (error);
1533 _dbus_return_if_fail (rule !=
NULL);
1542 _DBUS_SET_OOM (error);
1550 _DBUS_SET_OOM (error);
1554 send_no_return_values (connection, msg, error);
1583 _dbus_return_if_fail (rule !=
NULL);
1594 _DBUS_SET_OOM (error);
1598 send_no_return_values (connection, msg, error);
void _dbus_bus_notify_shared_connection_disconnected_unlocked(DBusConnection *connection)
Internal function that checks to see if this is a shared connection owned by the bus and if it is unr...
#define N_BUS_TYPES
Number of bus types.
dbus_bool_t dbus_bus_set_unique_name(DBusConnection *connection, const char *unique_name)
Sets the unique name of the connection, as assigned by the message bus.
dbus_bool_t dbus_bus_register(DBusConnection *connection, DBusError *error)
Registers a connection with the bus.
char * dbus_bus_get_id(DBusConnection *connection, DBusError *error)
Asks the bus to return its globally unique ID, as described in the D-Bus specification.
unsigned long dbus_bus_get_unix_user(DBusConnection *connection, const char *name, DBusError *error)
Asks the bus to return the UID the named connection authenticated as, if any.
void dbus_bus_add_match(DBusConnection *connection, const char *rule, DBusError *error)
Adds a match rule to match messages going through the message bus.
dbus_bool_t dbus_bus_name_has_owner(DBusConnection *connection, const char *name, DBusError *error)
Asks the bus whether a certain name has an owner.
void dbus_bus_remove_match(DBusConnection *connection, const char *rule, DBusError *error)
Removes a previously-added match rule "by value" (the most recently-added identical rule gets removed...
DBusConnection * dbus_bus_get(DBusBusType type, DBusError *error)
Connects to a bus daemon and registers the client with it.
dbus_bool_t dbus_bus_start_service_by_name(DBusConnection *connection, const char *name, dbus_uint32_t flags, dbus_uint32_t *result, DBusError *error)
Starts a service that will request ownership of the given name.
int dbus_bus_request_name(DBusConnection *connection, const char *name, unsigned int flags, DBusError *error)
Asks the bus to assign the given name to this connection by invoking the RequestName method on the bu...
const char * dbus_bus_get_unique_name(DBusConnection *connection)
Gets the unique name of the connection as assigned by the message bus.
DBusConnection * dbus_bus_get_private(DBusBusType type, DBusError *error)
Connects to a bus daemon and registers the client with it as with dbus_bus_register().
int dbus_bus_release_name(DBusConnection *connection, const char *name, DBusError *error)
Asks the bus to unassign the given name from this connection by invoking the ReleaseName method on th...
void _dbus_connection_close_possibly_shared(DBusConnection *connection)
Closes a shared OR private connection, while dbus_connection_close() can only be used on private conn...
void dbus_connection_set_exit_on_disconnect(DBusConnection *connection, dbus_bool_t exit_on_disconnect)
Set whether _exit() should be called when the connection receives a disconnect signal.
void * dbus_connection_get_data(DBusConnection *connection, dbus_int32_t slot)
Retrieves data previously set with dbus_connection_set_data().
DBusConnection * dbus_connection_open_private(const char *address, DBusError *error)
Opens a new, dedicated connection to a remote address.
void dbus_connection_unref(DBusConnection *connection)
Decrements the reference count of a DBusConnection, and finalizes it if the count reaches zero.
dbus_bool_t dbus_connection_allocate_data_slot(dbus_int32_t *slot_p)
Allocates an integer ID to be used for storing application-specific data on any DBusConnection.
void dbus_connection_free_data_slot(dbus_int32_t *slot_p)
Deallocates a global ID for connection data slots.
dbus_bool_t dbus_connection_set_data(DBusConnection *connection, dbus_int32_t slot, void *data, DBusFreeFunction free_data_func)
Stores a pointer on a DBusConnection, along with an optional function to be used for freeing the data...
DBusMessage * dbus_connection_send_with_reply_and_block(DBusConnection *connection, DBusMessage *message, int timeout_milliseconds, DBusError *error)
Sends a message and blocks a certain time period while waiting for a reply.
DBusConnection * dbus_connection_open(const char *address, DBusError *error)
Gets a connection to a remote address.
dbus_bool_t dbus_connection_send(DBusConnection *connection, DBusMessage *message, dbus_uint32_t *serial)
Adds a message to the outgoing message queue.
DBusConnection * dbus_connection_ref(DBusConnection *connection)
Increments the reference count of a DBusConnection.
#define DBUS_ERROR_INIT
Expands to a suitable initializer for a DBusError on the stack.
void dbus_set_error(DBusError *error, const char *name, const char *format,...)
Assigns an error name and message to a DBusError.
dbus_bool_t dbus_error_is_set(const DBusError *error)
Checks whether an error occurred (the error is set).
#define _dbus_assert_not_reached(explanation)
Aborts with an error message if called.
#define _dbus_assert(condition)
Aborts with an error message if the condition is false.
#define _DBUS_UNLOCK(name)
Unlocks a global lock.
#define _DBUS_LOCK(name)
Locks a global lock, initializing it first if necessary.
void _dbus_warn_check_failed(const char *format,...)
Prints a "critical" warning to stderr when an assertion fails; differs from _dbus_warn primarily in t...
char * _dbus_strdup(const char *str)
Duplicates a string.
void _dbus_warn(const char *format,...)
Prints a warning message to stderr.
#define NULL
A null pointer, defined appropriately for C or C++.
#define TRUE
Expands to "1".
#define FALSE
Expands to "0".
DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_register_shutdown_func(DBusShutdownFunction function, void *data)
Register a cleanup function to be called exactly once the next time dbus_shutdown() is called.
void dbus_free(void *memory)
Frees a block of memory previously allocated by dbus_malloc() or dbus_malloc0().
#define dbus_new0(type, count)
Safe macro for using dbus_malloc0().
void dbus_message_set_no_reply(DBusMessage *message, dbus_bool_t no_reply)
Sets a flag indicating that the message does not want a reply; if this flag is set,...
dbus_bool_t dbus_message_append_args(DBusMessage *message, int first_arg_type,...)
Appends fields to a message given a variable argument list.
DBusMessage * dbus_message_new_method_call(const char *destination, const char *path, const char *iface, const char *method)
Constructs a new message to invoke a method on a remote object.
void dbus_message_unref(DBusMessage *message)
Decrements the reference count of a DBusMessage, freeing the message if the count reaches 0.
dbus_bool_t dbus_set_error_from_message(DBusError *error, DBusMessage *message)
Sets a DBusError based on the contents of the given message.
dbus_bool_t dbus_message_get_args(DBusMessage *message, DBusError *error, int first_arg_type,...)
Gets arguments from a message given a variable argument list.
#define DBUS_TYPE_BOOLEAN
Type code marking a boolean.
#define DBUS_TYPE_STRING
Type code marking a UTF-8 encoded, nul-terminated Unicode string.
#define DBUS_TYPE_INVALID
Type code that is never equal to a legitimate type code.
#define DBUS_ERROR_FAILED
A generic error; "something went wrong" - see the error message for more.
#define DBUS_TYPE_UINT32
Type code marking a 32-bit unsigned integer.
#define DBUS_PATH_DBUS
The object path used to talk to the bus itself.
DBusBusType
Well-known bus types.
#define DBUS_SERVICE_DBUS
The bus name used to talk to the bus itself.
#define DBUS_INTERFACE_DBUS
The interface exported by the object with DBUS_SERVICE_DBUS and DBUS_PATH_DBUS.
@ DBUS_BUS_SESSION
The login session bus.
@ DBUS_BUS_STARTER
The bus that started us, if any.
@ DBUS_BUS_SYSTEM
The systemwide bus.
dbus_bool_t _dbus_string_init(DBusString *str)
Initializes a string.
dbus_bool_t _dbus_string_steal_data(DBusString *str, char **data_return)
Like _dbus_string_get_data(), but removes the gotten data from the original string.
void _dbus_string_free(DBusString *str)
Frees a string created by _dbus_string_init(), and fills it with the same contents as #_DBUS_STRING_I...
#define DBUS_UID_UNSET
an invalid UID used to represent an uninitialized dbus_uid_t field
const char * _dbus_getenv(const char *varname)
Wrapper for getenv().
dbus_bool_t _dbus_lookup_session_address(dbus_bool_t *supported, DBusString *address, DBusError *error)
Determines the address of the session bus by querying a platform-specific method.
dbus_uint32_t dbus_bool_t
A boolean, valid values are TRUE and FALSE.
Block of message-bus-related data we attach to each DBusConnection used with these convenience functi...
unsigned int is_well_known
Is one of the well-known connections in our global array.
DBusConnection * connection
Connection we're associated with.
char * unique_name
Unique name of this connection.
Implementation details of DBusConnection.
Object representing an exception.
const char * message
public error message field
Internals of DBusMessage.