27 #include "dbus-protocol.h"
28 #include "dbus-internals.h"
29 #include "dbus-message.h"
30 #include "dbus-marshal-validate.h"
31 #include "dbus-threads-internal.h"
32 #include "dbus-connection-internal.h"
33 #include "dbus-string.h"
81 unsigned int is_well_known : 1;
112 addresses_shutdown_func (
void *data)
119 if (bus_connections[i] !=
NULL)
120 _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.\n");
123 bus_connection_addresses[i] =
NULL;
133 get_from_env (
char **connection_p,
141 if (s ==
NULL || *s ==
'\0')
146 return *connection_p !=
NULL;
151 init_session_address (
void)
160 "DBUS_SESSION_BUS_ADDRESS");
176 if (supported && retval)
180 else if (supported && !retval)
185 _dbus_warn (
"Dynamic session lookup supported but failed silently\n");
208 init_connections_unlocked (
void)
218 bus_connections[i] =
NULL;
231 _dbus_verbose (
"Filling in system bus address...\n");
234 "DBUS_SYSTEM_BUS_ADDRESS"))
248 _dbus_verbose (
" used default system bus \"%s\"\n",
252 _dbus_verbose (
" used env var system bus \"%s\"\n",
257 _dbus_verbose (
"Filling in session bus address...\n");
259 if (!init_session_address ())
268 _dbus_verbose (
"Filling in activation bus address...\n");
271 "DBUS_STARTER_ADDRESS"))
274 _dbus_verbose (
" \"%s\"\n", bus_connection_addresses[DBUS_BUS_STARTER] ?
275 bus_connection_addresses[DBUS_BUS_STARTER] :
"none set");
285 _dbus_verbose (
"Bus activation type was set to \"%s\"\n", s);
287 if (strcmp (s,
"system") == 0)
289 else if (strcmp (s,
"session") == 0)
326 bus_data_free (
void *data)
343 bus_connections[i] =
NULL;
415 if (bus_connections[i] == connection)
417 bus_connections[i] =
NULL;
426 int timeout_milliseconds,
434 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
435 _dbus_return_val_if_error_is_set (error,
FALSE);
443 bd = ensure_bus_data (connection);
446 _DBUS_SET_OOM (error);
452 _dbus_verbose (
"Ignoring attempt to register the same DBusConnection %s with the message bus a second time.\n",
466 _DBUS_SET_OOM (error);
484 _DBUS_SET_OOM (error);
503 internal_open_and_register (
const char *address,
dbus_bool_t private,
int timeout_milliseconds,
DBusError *error)
517 if (!internal_register (connection, timeout_milliseconds, error))
540 #define OLD_SYSTEM_BUS_DEFAULT_ADDRESS "unix:path=/var/run/dbus/system_bus_socket"
541 #define INITIAL_TIMEOUT_MILLISECONDS 250
542 #define INCREMENT_TIMEOUT_MILLISECONDS 250
543 #define MAX_TIMEOUT_MILLISECONDS 10000
546 internal_open_and_register_with_fallback (
const char *address,
dbus_bool_t private,
DBusError *error)
549 int timeout_milliseconds;
551 for (timeout_milliseconds = INITIAL_TIMEOUT_MILLISECONDS;
552 connection ==
NULL && timeout_milliseconds < MAX_TIMEOUT_MILLISECONDS;
553 timeout_milliseconds += INCREMENT_TIMEOUT_MILLISECONDS)
555 connection = internal_open_and_register (address,
private, timeout_milliseconds,
NULL);
557 if (!connection && !strcmp (address, DBUS_SYSTEM_BUS_DEFAULT_ADDRESS))
558 connection = internal_open_and_register (OLD_SYSTEM_BUS_DEFAULT_ADDRESS,
private, timeout_milliseconds,
NULL);
565 connection = internal_open_and_register (address,
private, -1, error);
582 _dbus_return_val_if_error_is_set (error,
NULL);
588 if (!init_connections_unlocked ())
590 _DBUS_SET_OOM (error);
606 bus_connection_addresses[activation_bus_type] !=
NULL)
607 type = activation_bus_type;
609 if (!
private && bus_connections[type] !=
NULL)
611 connection = bus_connections[type];
616 address = bus_connection_addresses[address_type];
620 "Unable to determine the address of the message bus (try 'man dbus-launch' and 'man dbus-daemon' for help)");
624 connection = internal_open_and_register_with_fallback (address,
private, error);
637 bus_connections[type] = connection;
647 bd = ensure_bus_data (connection);
655 if (connection ==
NULL)
656 _DBUS_ASSERT_ERROR_IS_SET (error);
699 return internal_bus_get (type,
FALSE, error);
731 return internal_bus_get (type,
TRUE, error);
792 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
793 _dbus_return_val_if_error_is_set (error,
FALSE);
801 bd = ensure_bus_data (connection);
804 _DBUS_SET_OOM (error);
810 _dbus_verbose (
"Ignoring attempt to register the same DBusConnection %s with the message bus a second time.\n",
824 _DBUS_SET_OOM (error);
842 _DBUS_SET_OOM (error);
858 _DBUS_ASSERT_ERROR_IS_SET (error);
900 const char *unique_name)
905 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
906 _dbus_return_val_if_fail (unique_name !=
NULL,
FALSE);
910 bd = ensure_bus_data (connection);
947 const char *unique_name =
NULL;
949 _dbus_return_val_if_fail (connection !=
NULL,
NULL);
953 bd = ensure_bus_data (connection);
998 _dbus_return_val_if_fail (_dbus_check_is_valid_bus_name (name),
DBUS_UID_UNSET);
1004 "GetConnectionUnixUser");
1006 if (message ==
NULL)
1008 _DBUS_SET_OOM (error);
1017 _DBUS_SET_OOM (error);
1028 _DBUS_ASSERT_ERROR_IS_SET (error);
1034 _DBUS_ASSERT_ERROR_IS_SET (error);
1043 _DBUS_ASSERT_ERROR_IS_SET (error);
1050 return (
unsigned long) uid;
1077 const char *v_STRING;
1079 _dbus_return_val_if_fail (connection !=
NULL,
NULL);
1080 _dbus_return_val_if_error_is_set (error,
NULL);
1087 if (message ==
NULL)
1089 _DBUS_SET_OOM (error);
1100 _DBUS_ASSERT_ERROR_IS_SET (error);
1106 _DBUS_ASSERT_ERROR_IS_SET (error);
1116 _DBUS_ASSERT_ERROR_IS_SET (error);
1126 _DBUS_SET_OOM (error);
1244 _dbus_return_val_if_fail (connection !=
NULL, 0);
1245 _dbus_return_val_if_fail (name !=
NULL, 0);
1246 _dbus_return_val_if_fail (_dbus_check_is_valid_bus_name (name), 0);
1247 _dbus_return_val_if_error_is_set (error, 0);
1254 if (message ==
NULL)
1256 _DBUS_SET_OOM (error);
1266 _DBUS_SET_OOM (error);
1277 _DBUS_ASSERT_ERROR_IS_SET (error);
1283 _DBUS_ASSERT_ERROR_IS_SET (error);
1292 _DBUS_ASSERT_ERROR_IS_SET (error);
1329 _dbus_return_val_if_fail (connection !=
NULL, 0);
1330 _dbus_return_val_if_fail (name !=
NULL, 0);
1331 _dbus_return_val_if_fail (_dbus_check_is_valid_bus_name (name), 0);
1332 _dbus_return_val_if_error_is_set (error, 0);
1339 if (message ==
NULL)
1341 _DBUS_SET_OOM (error);
1350 _DBUS_SET_OOM (error);
1361 _DBUS_ASSERT_ERROR_IS_SET (error);
1367 _DBUS_ASSERT_ERROR_IS_SET (error);
1376 _DBUS_ASSERT_ERROR_IS_SET (error);
1411 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
1412 _dbus_return_val_if_fail (name !=
NULL,
FALSE);
1413 _dbus_return_val_if_fail (_dbus_check_is_valid_bus_name (name),
FALSE);
1414 _dbus_return_val_if_error_is_set (error,
FALSE);
1420 if (message ==
NULL)
1422 _DBUS_SET_OOM (error);
1431 _DBUS_SET_OOM (error);
1440 _DBUS_ASSERT_ERROR_IS_SET (error);
1448 _DBUS_ASSERT_ERROR_IS_SET (error);
1489 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
1490 _dbus_return_val_if_fail (_dbus_check_is_valid_bus_name (name),
FALSE);
1495 "StartServiceByName");
1501 _DBUS_SET_OOM (error);
1511 _DBUS_ASSERT_ERROR_IS_SET (error);
1517 _DBUS_ASSERT_ERROR_IS_SET (error);
1522 if (result !=
NULL &&
1526 _DBUS_ASSERT_ERROR_IS_SET (error);
1549 _DBUS_ASSERT_ERROR_IS_SET (error);
1656 _dbus_return_if_fail (rule !=
NULL);
1665 _DBUS_SET_OOM (error);
1673 _DBUS_SET_OOM (error);
1677 send_no_return_values (connection, msg, error);
1706 _dbus_return_if_fail (rule !=
NULL);
1717 _DBUS_SET_OOM (error);
1721 send_no_return_values (connection, msg, error);
unsigned int dbus_uint32_t
A 32-bit unsigned integer on all platforms.
const char * message
public error message field
#define NULL
A null pointer, defined appropriately for C or C++.
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, the other end of the connection may (but is not required to) optimize by not sending method return or error replies.
void dbus_free(void *memory)
Frees a block of memory previously allocated by dbus_malloc() or dbus_malloc0().
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...
DBusConnection * dbus_connection_ref(DBusConnection *connection)
Increments the reference count of a DBusConnection.
#define DBUS_TYPE_STRING
Type code marking a UTF-8 encoded, nul-terminated Unicode string.
#define _dbus_assert(condition)
Aborts with an error message if the condition is false.
#define DBUS_INTERFACE_DBUS
The interface exported by the object with DBUS_SERVICE_DBUS and DBUS_PATH_DBUS.
#define DBUS_ERROR_INIT
Expands to a suitable initializer for a DBusError on the stack.
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...
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...
#define N_BUS_TYPES
Number of bus types.
Implementation details of DBusConnection.
dbus_bool_t _dbus_string_init(DBusString *str)
Initializes a string.
Block of message-bus-related data we attach to each DBusConnection used with these convenience functi...
#define DBUS_UID_UNSET
an invalid UID used to represent an uninitialized dbus_uid_t field
void dbus_connection_free_data_slot(dbus_int32_t *slot_p)
Deallocates a global ID for connection data slots.
const char * _dbus_getenv(const char *varname)
Wrapper for getenv().
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_private(const char *address, DBusError *error)
Opens a new, dedicated connection to a remote address.
Internals of DBusMessage.
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...
#define dbus_new0(type, count)
Safe macro for using dbus_malloc0().
DBusConnection * connection
Connection we're associated with.
dbus_bool_t _dbus_setenv(const char *varname, const char *value)
Wrapper for setenv().
dbus_uint32_t dbus_bool_t
A boolean, valid values are TRUE and FALSE.
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.
#define DBUS_PATH_DBUS
The object path used to talk to the bus itself.
dbus_bool_t dbus_connection_send(DBusConnection *connection, DBusMessage *message, dbus_uint32_t *serial)
Adds a message to the outgoing message queue.
DBusConnection * dbus_bus_get(DBusBusType type, DBusError *error)
Connects to a bus daemon and registers the client with it.
void * dbus_connection_get_data(DBusConnection *connection, dbus_int32_t slot)
Retrieves data previously set with dbus_connection_set_data().
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.
void _dbus_warn(const char *format,...)
Prints a warning message to stderr.
char * unique_name
Unique name of this connection.
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_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_connection_open(const char *address, DBusError *error)
Gets a connection to a remote address.
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.
Object representing an exception.
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...
dbus_bool_t dbus_message_append_args(DBusMessage *message, int first_arg_type,...)
Appends fields to a message given a variable argument list.
void dbus_set_error(DBusError *error, const char *name, const char *format,...)
Assigns an error name and message to a DBusError.
#define DBUS_TYPE_UINT32
Type code marking a 32-bit unsigned integer.
#define _DBUS_UNLOCK(name)
Unlocks a global lock.
void _dbus_string_free(DBusString *str)
Frees a string created by _dbus_string_init().
#define TRUE
Expands to "1".
dbus_bool_t dbus_bus_register(DBusConnection *connection, DBusError *error)
Registers a connection with the bus.
#define DBUS_ERROR_FAILED
A generic error; "something went wrong" - see the error message for more.
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_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.
#define _DBUS_DEFINE_GLOBAL_LOCK(name)
Defines a global lock variable with the given name.
#define DBUS_TYPE_INVALID
Type code that is never equal to a legitimate type code.
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.
#define DBUS_TYPE_BOOLEAN
Type code marking a boolean.
unsigned int is_well_known
Is one of the well-known connections in our global array.
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...
The bus that started us, if any.
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. ...
void dbus_bus_add_match(DBusConnection *connection, const char *rule, DBusError *error)
Adds a match rule to match messages going through the message bus.
#define FALSE
Expands to "0".
const char * dbus_bus_get_unique_name(DBusConnection *connection)
Gets the unique name of the connection as assigned by the message bus.
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...
#define _DBUS_LOCK(name)
Locks a global lock.
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.
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_connection_unref(DBusConnection *connection)
Decrements the reference count of a DBusConnection, and finalizes it if the count reaches zero...
#define DBUS_SERVICE_DBUS
The bus name used to talk to the bus itself.
int dbus_int32_t
A 32-bit signed integer on all platforms.
char * _dbus_strdup(const char *str)
Duplicates a string.
DBusBusType
Well-known bus types.
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().
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_bus_name_has_owner(DBusConnection *connection, const char *name, DBusError *error)
Asks the bus whether a certain name has an owner.
DBusMessage * dbus_message_new_method_call(const char *destination, const char *path, const char *interface, const char *method)
Constructs a new message to invoke a method on a remote object.
dbus_bool_t dbus_error_is_set(const DBusError *error)
Checks whether an error occurred (the error is set).