dbus-server.c
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
/* dbus-server.c DBusServer object
*
* Copyright (C) 2002, 2003, 2004, 2005 Red Hat Inc.
*
* SPDX-License-Identifier: AFL-2.1 OR GPL-2.0-or-later
*
* 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
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#include <config.h>
#include "dbus-server.h"
#include "dbus-server-socket.h"
#include "dbus-string.h"
#ifdef DBUS_ENABLE_EMBEDDED_TESTS
#include "dbus-server-debug-pipe.h"
#endif
#include "dbus-address.h"
#include "dbus-protocol.h"
#ifndef _dbus_server_trace_ref
void
_dbus_server_trace_ref (DBusServer *server,
int old_refcount,
int new_refcount,
const char *why)
{
static int enabled = -1;
_dbus_trace_ref ("DBusServer", server, old_refcount, new_refcount, why,
"DBUS_SERVER_TRACE", &enabled);
}
#endif
/* this is a little fragile since it assumes the address doesn't
* already have a guid, but it shouldn't
*/
static char*
copy_address_with_guid_appended (const DBusString *address,
const DBusString *guid_hex)
{
DBusString with_guid;
char *retval;
if (!_dbus_string_init (&with_guid))
return NULL;
if (!_dbus_string_copy (address, 0, &with_guid,
_dbus_string_get_length (&with_guid)) ||
!_dbus_string_append (&with_guid, ",guid=") ||
!_dbus_string_copy (guid_hex, 0,
&with_guid, _dbus_string_get_length (&with_guid)))
{
_dbus_string_free (&with_guid);
return NULL;
}
retval = NULL;
_dbus_string_steal_data (&with_guid, &retval);
_dbus_string_free (&with_guid);
return retval; /* may be NULL if steal_data failed */
}
dbus_bool_t
_dbus_server_init_base (DBusServer *server,
const DBusServerVTable *vtable,
const DBusString *address,
DBusError *error)
{
server->vtable = vtable;
#ifdef DBUS_DISABLE_ASSERT
_dbus_atomic_inc (&server->refcount);
#else
{
dbus_int32_t old_refcount = _dbus_atomic_inc (&server->refcount);
_dbus_assert (old_refcount == 0);
}
#endif
server->address = NULL;
server->watches = NULL;
server->timeouts = NULL;
server->published_address = FALSE;
if (!_dbus_string_init (&server->guid_hex))
{
_DBUS_SET_OOM (error);
return FALSE;
}
if (!_dbus_generate_uuid (&server->guid, error))
goto failed;
if (!_dbus_uuid_encode (&server->guid, &server->guid_hex))
goto oom;
server->address = copy_address_with_guid_appended (address,
&server->guid_hex);
if (server->address == NULL)
goto oom;
_dbus_rmutex_new_at_location (&server->mutex);
if (server->mutex == NULL)
goto oom;
server->watches = _dbus_watch_list_new ();
if (server->watches == NULL)
goto oom;
server->timeouts = _dbus_timeout_list_new ();
if (server->timeouts == NULL)
goto oom;
_dbus_data_slot_list_init (&server->slot_list);
_dbus_verbose ("Initialized server on address %s\n", server->address);
return TRUE;
oom:
_DBUS_SET_OOM (error);
failed:
_dbus_rmutex_free_at_location (&server->mutex);
server->mutex = NULL;
if (server->watches)
{
_dbus_watch_list_free (server->watches);
server->watches = NULL;
}
if (server->timeouts)
{
_dbus_timeout_list_free (server->timeouts);
server->timeouts = NULL;
}
if (server->address)
{
dbus_free (server->address);
server->address = NULL;
}
_dbus_string_free (&server->guid_hex);
return FALSE;
}
void
_dbus_server_finalize_base (DBusServer *server)
{
/* We don't have the lock, but nobody should be accessing
* concurrently since they don't have a ref
*/
#ifndef DBUS_DISABLE_CHECKS
_dbus_assert (!server->have_server_lock);
#endif
_dbus_assert (server->disconnected);
/* calls out to application code... */
_dbus_data_slot_list_free (&server->slot_list);
dbus_server_set_new_connection_function (server, NULL, NULL, NULL);
_dbus_watch_list_free (server->watches);
_dbus_timeout_list_free (server->timeouts);
_dbus_rmutex_free_at_location (&server->mutex);
dbus_free (server->address);
dbus_free_string_array (server->auth_mechanisms);
_dbus_string_free (&server->guid_hex);
}
typedef dbus_bool_t (* DBusWatchAddFunction) (DBusWatchList *list,
DBusWatch *watch);
typedef void (* DBusWatchRemoveFunction) (DBusWatchList *list,
DBusWatch *watch);
typedef void (* DBusWatchToggleFunction) (DBusWatchList *list,
DBusWatch *watch,
dbus_bool_t enabled);
static dbus_bool_t
protected_change_watch (DBusServer *server,
DBusWatch *watch,
DBusWatchAddFunction add_function,
DBusWatchRemoveFunction remove_function,
DBusWatchToggleFunction toggle_function,
dbus_bool_t enabled)
{
DBusWatchList *watches;
dbus_bool_t retval;
HAVE_LOCK_CHECK (server);
/* This isn't really safe or reasonable; a better pattern is the "do
* everything, then drop lock and call out" one; but it has to be
* propagated up through all callers
*/
watches = server->watches;
if (watches)
{
server->watches = NULL;
_dbus_server_ref_unlocked (server);
SERVER_UNLOCK (server);
if (add_function)
retval = (* add_function) (watches, watch);
else if (remove_function)
{
retval = TRUE;
(* remove_function) (watches, watch);
}
else
{
retval = TRUE;
(* toggle_function) (watches, watch, enabled);
}
SERVER_LOCK (server);
server->watches = watches;
_dbus_server_unref_unlocked (server);
return retval;
}
else
return FALSE;
}
dbus_bool_t
_dbus_server_add_watch (DBusServer *server,
DBusWatch *watch)
{
HAVE_LOCK_CHECK (server);
return protected_change_watch (server, watch,
_dbus_watch_list_add_watch,
NULL, NULL, FALSE);
}
void
_dbus_server_remove_watch (DBusServer *server,
DBusWatch *watch)
{
HAVE_LOCK_CHECK (server);
protected_change_watch (server, watch,
NULL,
_dbus_watch_list_remove_watch,
NULL, FALSE);
}
void
_dbus_server_toggle_all_watches (DBusServer *server,
dbus_bool_t enabled)
{
_dbus_watch_list_toggle_all_watches (server->watches, enabled);
}
typedef dbus_bool_t (* DBusTimeoutAddFunction) (DBusTimeoutList *list,
DBusTimeout *timeout);
typedef void (* DBusTimeoutRemoveFunction) (DBusTimeoutList *list,
DBusTimeout *timeout);
typedef void (* DBusTimeoutToggleFunction) (DBusTimeoutList *list,
DBusTimeout *timeout,
dbus_bool_t enabled);
static dbus_bool_t
protected_change_timeout (DBusServer *server,
DBusTimeout *timeout,
DBusTimeoutAddFunction add_function,
DBusTimeoutRemoveFunction remove_function,
DBusTimeoutToggleFunction toggle_function,
dbus_bool_t enabled)
{
DBusTimeoutList *timeouts;
dbus_bool_t retval;
HAVE_LOCK_CHECK (server);
/* This isn't really safe or reasonable; a better pattern is the "do everything, then
* drop lock and call out" one; but it has to be propagated up through all callers
*/
timeouts = server->timeouts;
if (timeouts)
{
server->timeouts = NULL;
_dbus_server_ref_unlocked (server);
SERVER_UNLOCK (server);
if (add_function)
retval = (* add_function) (timeouts, timeout);
else if (remove_function)
{
retval = TRUE;
(* remove_function) (timeouts, timeout);
}
else
{
retval = TRUE;
(* toggle_function) (timeouts, timeout, enabled);
}
SERVER_LOCK (server);
server->timeouts = timeouts;
_dbus_server_unref_unlocked (server);
return retval;
}
else
return FALSE;
}
dbus_bool_t
_dbus_server_add_timeout (DBusServer *server,
DBusTimeout *timeout)
{
return protected_change_timeout (server, timeout,
_dbus_timeout_list_add_timeout,
NULL, NULL, FALSE);
}
void
_dbus_server_remove_timeout (DBusServer *server,
DBusTimeout *timeout)
{
protected_change_timeout (server, timeout,
NULL,
_dbus_timeout_list_remove_timeout,
NULL, FALSE);
}
void
_dbus_server_toggle_timeout (DBusServer *server,
DBusTimeout *timeout,
dbus_bool_t enabled)
{
protected_change_timeout (server, timeout,
NULL, NULL,
_dbus_timeout_list_toggle_timeout,
enabled);
}
void
_dbus_server_ref_unlocked (DBusServer *server)
{
dbus_int32_t old_refcount;
_dbus_assert (server != NULL);
HAVE_LOCK_CHECK (server);
old_refcount = _dbus_atomic_inc (&server->refcount);
_dbus_assert (old_refcount > 0);
_dbus_server_trace_ref (server, old_refcount, old_refcount + 1,
"ref_unlocked");
}
void
_dbus_server_unref_unlocked (DBusServer *server)
{
dbus_int32_t old_refcount;
/* Keep this in sync with dbus_server_unref */
_dbus_assert (server != NULL);
HAVE_LOCK_CHECK (server);
old_refcount = _dbus_atomic_dec (&server->refcount);
_dbus_assert (old_refcount > 0);
_dbus_server_trace_ref (server, old_refcount, old_refcount - 1,
"unref_unlocked");
if (old_refcount == 1)
{
_dbus_assert (server->disconnected);
SERVER_UNLOCK (server);
_dbus_assert (server->vtable->finalize != NULL);
(* server->vtable->finalize) (server);
}
}
static const struct {
DBusServerListenResult (* func) (DBusAddressEntry *entry,
DBusServer **server_p,
DBusError *error);
} listen_funcs[] = {
{ _dbus_server_listen_socket }
, { _dbus_server_listen_unix_socket }
, { _dbus_server_listen_platform_specific }
#ifdef DBUS_ENABLE_EMBEDDED_TESTS
, { _dbus_server_listen_debug_pipe }
#endif
};
DBusServer*
dbus_server_listen (const char *address,
DBusError *error)
{
DBusServer *server;
DBusAddressEntry **entries;
int len, i;
DBusError first_connect_error = DBUS_ERROR_INIT;
dbus_bool_t handled_once;
_dbus_return_val_if_fail (address != NULL, NULL);
_dbus_return_val_if_error_is_set (error, NULL);
if (!dbus_parse_address (address, &entries, &len, error))
return NULL;
server = NULL;
handled_once = FALSE;
for (i = 0; i < len; i++)
{
int j;
for (j = 0; j < (int) _DBUS_N_ELEMENTS (listen_funcs); ++j)
{
DBusServerListenResult result;
DBusError tmp_error = DBUS_ERROR_INIT;
result = (* listen_funcs[j].func) (entries[i],
&server,
&tmp_error);
if (result == DBUS_SERVER_LISTEN_OK)
{
_dbus_assert (server != NULL);
_DBUS_ASSERT_ERROR_IS_CLEAR (&tmp_error);
handled_once = TRUE;
goto out;
}
else if (result == DBUS_SERVER_LISTEN_ADDRESS_ALREADY_USED)
{
_dbus_assert (server == NULL);
_DBUS_ASSERT_ERROR_IS_CLEAR (&tmp_error);
dbus_set_error (error,
DBUS_ERROR_ADDRESS_IN_USE,
"Address '%s' already used",
dbus_address_entry_get_method (entries[0]));
handled_once = TRUE;
goto out;
}
else if (result == DBUS_SERVER_LISTEN_BAD_ADDRESS)
{
_dbus_assert (server == NULL);
_DBUS_ASSERT_ERROR_IS_SET (&tmp_error);
dbus_move_error (&tmp_error, error);
handled_once = TRUE;
goto out;
}
else if (result == DBUS_SERVER_LISTEN_NOT_HANDLED)
{
_dbus_assert (server == NULL);
_DBUS_ASSERT_ERROR_IS_CLEAR (&tmp_error);
/* keep trying addresses */
}
else if (result == DBUS_SERVER_LISTEN_DID_NOT_CONNECT)
{
_dbus_assert (server == NULL);
_DBUS_ASSERT_ERROR_IS_SET (&tmp_error);
if (!dbus_error_is_set (&first_connect_error))
dbus_move_error (&tmp_error, &first_connect_error);
else
dbus_error_free (&tmp_error);
handled_once = TRUE;
/* keep trying addresses */
}
else
{
_dbus_assert_not_reached ("Unknown result in dbus_server_listen");
}
}
_dbus_assert (server == NULL);
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
}
out:
if (!handled_once)
{
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
if (len > 0)
dbus_set_error (error,
DBUS_ERROR_BAD_ADDRESS,
"Unknown address type '%s'",
dbus_address_entry_get_method (entries[0]));
else
dbus_set_error (error,
DBUS_ERROR_BAD_ADDRESS,
"Empty address '%s'",
address);
}
dbus_address_entries_free (entries);
if (server == NULL)
{
_dbus_assert (error == NULL || dbus_error_is_set (&first_connect_error) ||
dbus_error_is_set (error));
if (error && dbus_error_is_set (error))
{
/* already set the error */
}
else
{
/* didn't set the error but either error should be
* NULL or first_connect_error should be set.
*/
_dbus_assert (error == NULL || dbus_error_is_set (&first_connect_error));
dbus_move_error (&first_connect_error, error);
}
_DBUS_ASSERT_ERROR_IS_CLEAR (&first_connect_error); /* be sure we freed it */
_DBUS_ASSERT_ERROR_IS_SET (error);
return NULL;
}
else
{
dbus_error_free (&first_connect_error);
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
return server;
}
}
DBusServer *
dbus_server_ref (DBusServer *server)
{
dbus_int32_t old_refcount;
_dbus_return_val_if_fail (server != NULL, NULL);
old_refcount = _dbus_atomic_inc (&server->refcount);
#ifndef DBUS_DISABLE_CHECKS
if (_DBUS_UNLIKELY (old_refcount <= 0))
{
_dbus_atomic_dec (&server->refcount);
_dbus_warn_return_if_fail (_DBUS_FUNCTION_NAME, "old_refcount > 0",
__FILE__, __LINE__);
return NULL;
}
#endif
_dbus_server_trace_ref (server, old_refcount, old_refcount + 1, "ref");
return server;
}
void
dbus_server_unref (DBusServer *server)
{
dbus_int32_t old_refcount;
/* keep this in sync with unref_unlocked */
_dbus_return_if_fail (server != NULL);
old_refcount = _dbus_atomic_dec (&server->refcount);
#ifndef DBUS_DISABLE_CHECKS
if (_DBUS_UNLIKELY (old_refcount <= 0))
{
/* undo side-effect first
* please do not try to simplify the code here by using
* _dbus_atomic_get(), why we don't use it is
* because it issues another atomic operation even though
* DBUS_DISABLE_CHECKS defined.
* Bug: https://bugs.freedesktop.org/show_bug.cgi?id=68303
*/
_dbus_atomic_inc (&server->refcount);
_dbus_warn_return_if_fail (_DBUS_FUNCTION_NAME, "old_refcount > 0",
__FILE__, __LINE__);
return;
}
#endif
_dbus_server_trace_ref (server, old_refcount, old_refcount - 1, "unref");
if (old_refcount == 1)
{
/* lock not held! */
_dbus_assert (server->disconnected);
_dbus_assert (server->vtable->finalize != NULL);
(* server->vtable->finalize) (server);
}
}
void
_dbus_server_disconnect_unlocked (DBusServer *server)
{
_dbus_assert (server->vtable->disconnect != NULL);
if (!server->disconnected)
{
/* this has to be first so recursive calls to disconnect don't happen */
server->disconnected = TRUE;
(* server->vtable->disconnect) (server);
}
}
void
dbus_server_disconnect (DBusServer *server)
{
_dbus_return_if_fail (server != NULL);
dbus_server_ref (server);
SERVER_LOCK (server);
_dbus_server_disconnect_unlocked (server);
SERVER_UNLOCK (server);
dbus_server_unref (server);
}
dbus_bool_t
dbus_server_get_is_connected (DBusServer *server)
{
dbus_bool_t retval;
_dbus_return_val_if_fail (server != NULL, FALSE);
SERVER_LOCK (server);
retval = !server->disconnected;
SERVER_UNLOCK (server);
return retval;
}
char*
dbus_server_get_address (DBusServer *server)
{
char *retval;
_dbus_return_val_if_fail (server != NULL, NULL);
SERVER_LOCK (server);
retval = _dbus_strdup (server->address);
SERVER_UNLOCK (server);
return retval;
}
char*
dbus_server_get_id (DBusServer *server)
{
char *retval;
_dbus_return_val_if_fail (server != NULL, NULL);
SERVER_LOCK (server);
retval = NULL;
_dbus_string_copy_data (&server->guid_hex, &retval);
SERVER_UNLOCK (server);
return retval;
}
void
dbus_server_set_new_connection_function (DBusServer *server,
DBusNewConnectionFunction function,
void *data,
DBusFreeFunction free_data_function)
{
DBusFreeFunction old_free_function;
void *old_data;
_dbus_return_if_fail (server != NULL);
SERVER_LOCK (server);
old_free_function = server->new_connection_free_data_function;
old_data = server->new_connection_data;
server->new_connection_function = function;
server->new_connection_data = data;
server->new_connection_free_data_function = free_data_function;
SERVER_UNLOCK (server);
if (old_free_function != NULL)
(* old_free_function) (old_data);
}
dbus_bool_t
dbus_server_set_watch_functions (DBusServer *server,
DBusAddWatchFunction add_function,
DBusRemoveWatchFunction remove_function,
DBusWatchToggledFunction toggled_function,
void *data,
DBusFreeFunction free_data_function)
{
dbus_bool_t result;
DBusWatchList *watches;
_dbus_return_val_if_fail (server != NULL, FALSE);
SERVER_LOCK (server);
watches = server->watches;
server->watches = NULL;
if (watches)
{
SERVER_UNLOCK (server);
result = _dbus_watch_list_set_functions (watches,
add_function,
remove_function,
toggled_function,
data,
free_data_function);
SERVER_LOCK (server);
}
else
{
_dbus_warn_check_failed ("Re-entrant call to %s", _DBUS_FUNCTION_NAME);
result = FALSE;
}
server->watches = watches;
SERVER_UNLOCK (server);
return result;
}
dbus_bool_t
dbus_server_set_timeout_functions (DBusServer *server,
DBusAddTimeoutFunction add_function,
DBusRemoveTimeoutFunction remove_function,
DBusTimeoutToggledFunction toggled_function,
void *data,
DBusFreeFunction free_data_function)
{
dbus_bool_t result;
DBusTimeoutList *timeouts;
_dbus_return_val_if_fail (server != NULL, FALSE);
SERVER_LOCK (server);
timeouts = server->timeouts;
server->timeouts = NULL;
if (timeouts)
{
SERVER_UNLOCK (server);
result = _dbus_timeout_list_set_functions (timeouts,
add_function,
remove_function,
toggled_function,
data,
free_data_function);
SERVER_LOCK (server);
}
else
{
_dbus_warn_check_failed ("Re-entrant call to %s", _DBUS_FUNCTION_NAME);
result = FALSE;
}
server->timeouts = timeouts;
SERVER_UNLOCK (server);
return result;
}
dbus_bool_t
dbus_server_set_auth_mechanisms (DBusServer *server,
const char **mechanisms)
{
char **copy;
_dbus_return_val_if_fail (server != NULL, FALSE);
SERVER_LOCK (server);
if (mechanisms != NULL)
{
copy = _dbus_dup_string_array (mechanisms);
if (copy == NULL)
{
SERVER_UNLOCK (server);
return FALSE;
}
}
else
copy = NULL;
dbus_free_string_array (server->auth_mechanisms);
server->auth_mechanisms = copy;
SERVER_UNLOCK (server);
return TRUE;
}
static DBusDataSlotAllocator slot_allocator =
_DBUS_DATA_SLOT_ALLOCATOR_INIT (_DBUS_LOCK_NAME (server_slots));
dbus_bool_t
dbus_server_allocate_data_slot (dbus_int32_t *slot_p)
{
return _dbus_data_slot_allocator_alloc (&slot_allocator,
slot_p);
}
void
dbus_server_free_data_slot (dbus_int32_t *slot_p)
{
_dbus_return_if_fail (*slot_p >= 0);
_dbus_data_slot_allocator_free (&slot_allocator, slot_p);
}
dbus_bool_t
dbus_server_set_data (DBusServer *server,
int slot,
void *data,
DBusFreeFunction free_data_func)
{
DBusFreeFunction old_free_func;
void *old_data;
dbus_bool_t retval;
_dbus_return_val_if_fail (server != NULL, FALSE);
SERVER_LOCK (server);
retval = _dbus_data_slot_list_set (&slot_allocator,
&server->slot_list,
slot, data, free_data_func,
&old_free_func, &old_data);
SERVER_UNLOCK (server);
if (retval)
{
/* Do the actual free outside the server lock */
if (old_free_func)
(* old_free_func) (old_data);
}
return retval;
}
void*
dbus_server_get_data (DBusServer *server,
int slot)
{
void *res;
_dbus_return_val_if_fail (server != NULL, NULL);
SERVER_LOCK (server);
res = _dbus_data_slot_list_get (&slot_allocator,
&server->slot_list,
slot);
SERVER_UNLOCK (server);
return res;
}
dbus_address_entries_free
void dbus_address_entries_free(DBusAddressEntry **entries)
Frees a NULL-terminated array of address entries.
Definition dbus-address.c:194
dbus_parse_address
dbus_bool_t dbus_parse_address(const char *address, DBusAddressEntry ***entry_result, int *array_len, DBusError *error)
Parses an address string of the form:
Definition dbus-address.c:368
dbus_address_entry_get_method
const char * dbus_address_entry_get_method(DBusAddressEntry *entry)
Returns the method string of an address entry.
Definition dbus-address.c:232
DBusWatchRemoveFunction
void(* DBusWatchRemoveFunction)(DBusWatchList *list, DBusWatch *watch)
Function to be called in protected_change_watch() with refcount held.
Definition dbus-connection.c:677
DBusTimeoutToggleFunction
void(* DBusTimeoutToggleFunction)(DBusTimeoutList *list, DBusTimeout *timeout, dbus_bool_t enabled)
Function to be called in protected_change_timeout() with refcount held.
Definition dbus-connection.c:804
DBusTimeoutRemoveFunction
void(* DBusTimeoutRemoveFunction)(DBusTimeoutList *list, DBusTimeout *timeout)
Function to be called in protected_change_timeout() with refcount held.
Definition dbus-connection.c:801
DBusTimeoutAddFunction
dbus_bool_t(* DBusTimeoutAddFunction)(DBusTimeoutList *list, DBusTimeout *timeout)
Function to be called in protected_change_timeout() with refcount held.
Definition dbus-connection.c:798
DBusWatchToggleFunction
void(* DBusWatchToggleFunction)(DBusWatchList *list, DBusWatch *watch, dbus_bool_t enabled)
Function to be called in protected_change_watch() with refcount held.
Definition dbus-connection.c:680
DBusWatchAddFunction
dbus_bool_t(* DBusWatchAddFunction)(DBusWatchList *list, DBusWatch *watch)
Function to be called in protected_change_watch() with refcount held.
Definition dbus-connection.c:674
DBusWatchToggledFunction
void(* DBusWatchToggledFunction)(DBusWatch *watch, void *data)
Called when dbus_watch_get_enabled() may return a different value than it did before.
Definition dbus-connection.h:100
DBusAddWatchFunction
dbus_bool_t(* DBusAddWatchFunction)(DBusWatch *watch, void *data)
Called when libdbus needs a new watch to be monitored by the main loop.
Definition dbus-connection.h:94
DBusTimeoutToggledFunction
void(* DBusTimeoutToggledFunction)(DBusTimeout *timeout, void *data)
Called when dbus_timeout_get_enabled() may return a different value than it did before.
Definition dbus-connection.h:120
DBusAddTimeoutFunction
dbus_bool_t(* DBusAddTimeoutFunction)(DBusTimeout *timeout, void *data)
Called when libdbus needs a new timeout to be monitored by the main loop.
Definition dbus-connection.h:113
DBusRemoveWatchFunction
void(* DBusRemoveWatchFunction)(DBusWatch *watch, void *data)
Called when libdbus no longer needs a watch to be monitored by the main loop.
Definition dbus-connection.h:106
DBusRemoveTimeoutFunction
void(* DBusRemoveTimeoutFunction)(DBusTimeout *timeout, void *data)
Called when libdbus no longer needs a timeout to be monitored by the main loop.
Definition dbus-connection.h:126
_dbus_data_slot_allocator_free
void _dbus_data_slot_allocator_free(DBusDataSlotAllocator *allocator, dbus_int32_t *slot_id_p)
Deallocates an ID previously allocated with _dbus_data_slot_allocator_alloc().
Definition dbus-dataslot.c:157
_dbus_data_slot_list_init
void _dbus_data_slot_list_init(DBusDataSlotList *list)
Initializes a slot list.
Definition dbus-dataslot.c:200
_dbus_data_slot_list_free
void _dbus_data_slot_list_free(DBusDataSlotList *list)
Frees the data slot list and all data slots contained in it, calling application-provided free functi...
Definition dbus-dataslot.c:343
_dbus_data_slot_list_get
void * _dbus_data_slot_list_get(DBusDataSlotAllocator *allocator, DBusDataSlotList *list, int slot)
Retrieves data previously set with _dbus_data_slot_list_set_data().
Definition dbus-dataslot.c:288
_dbus_data_slot_list_set
dbus_bool_t _dbus_data_slot_list_set(DBusDataSlotAllocator *allocator, DBusDataSlotList *list, int slot, void *data, DBusFreeFunction free_data_func, DBusFreeFunction *old_free_func, void **old_data)
Stores a pointer in the data slot list, along with an optional function to be used for freeing the da...
Definition dbus-dataslot.c:224
_dbus_data_slot_allocator_alloc
dbus_bool_t _dbus_data_slot_allocator_alloc(DBusDataSlotAllocator *allocator, dbus_int32_t *slot_id_p)
Allocates an integer ID to be used for storing data in a DBusDataSlotList.
Definition dbus-dataslot.c:72
DBUS_ERROR_INIT
#define DBUS_ERROR_INIT
Expands to a suitable initializer for a DBusError on the stack.
Definition dbus-errors.h:64
dbus_move_error
void dbus_move_error(DBusError *src, DBusError *dest)
Moves an error src into dest, freeing src and overwriting dest.
Definition dbus-errors.c:281
dbus_set_error
void dbus_set_error(DBusError *error, const char *name, const char *format,...)
Assigns an error name and message to a DBusError.
Definition dbus-errors.c:356
dbus_error_free
void dbus_error_free(DBusError *error)
Frees an error that's been set (or just initialized), then reinitializes the error as in dbus_error_i...
Definition dbus-errors.c:213
dbus_error_is_set
dbus_bool_t dbus_error_is_set(const DBusError *error)
Checks whether an error occurred (the error is set).
Definition dbus-errors.c:331
_dbus_assert_not_reached
#define _dbus_assert_not_reached(explanation)
Aborts with an error message if called.
Definition dbus-internals.h:164
_dbus_assert
#define _dbus_assert(condition)
Aborts with an error message if the condition is false.
Definition dbus-internals.h:153
_dbus_generate_uuid
dbus_bool_t _dbus_generate_uuid(DBusGUID *uuid, DBusError *error)
Generates a new UUID.
Definition dbus-internals.c:752
_dbus_warn_check_failed
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...
Definition dbus-internals.c:310
_dbus_strdup
char * _dbus_strdup(const char *str)
Duplicates a string.
Definition dbus-internals.c:621
_DBUS_N_ELEMENTS
#define _DBUS_N_ELEMENTS(array)
Computes the number of elements in a fixed-size array using sizeof().
Definition dbus-internals.h:189
_DBUS_LOCK_NAME
#define _DBUS_LOCK_NAME(name)
Expands to name of a global lock variable.
Definition dbus-internals.h:436
_dbus_uuid_encode
dbus_bool_t _dbus_uuid_encode(const DBusGUID *uuid, DBusString *encoded)
Hex-encode a UUID.
Definition dbus-internals.c:788
_dbus_dup_string_array
char ** _dbus_dup_string_array(const char **array)
Duplicates a string array.
Definition dbus-internals.c:672
NULL
#define NULL
A null pointer, defined appropriately for C or C++.
Definition dbus-macros.h:51
TRUE
#define TRUE
Expands to "1".
Definition dbus-macros.h:41
FALSE
#define FALSE
Expands to "0".
Definition dbus-macros.h:44
dbus_free
void dbus_free(void *memory)
Frees a block of memory previously allocated by dbus_malloc() or dbus_malloc0().
Definition dbus-memory.c:710
DBusFreeFunction
void(* DBusFreeFunction)(void *memory)
The type of a function which frees a block of memory.
Definition dbus-memory.h:65
dbus_free_string_array
void dbus_free_string_array(char **str_array)
Frees a NULL-terminated array of strings.
Definition dbus-memory.c:758
DBUS_ERROR_ADDRESS_IN_USE
#define DBUS_ERROR_ADDRESS_IN_USE
Can't bind a socket since its address is in use (i.e.
Definition dbus-protocol.h:393
DBUS_ERROR_BAD_ADDRESS
#define DBUS_ERROR_BAD_ADDRESS
A D-Bus bus address was malformed.
Definition dbus-protocol.h:373
_dbus_server_add_watch
dbus_bool_t _dbus_server_add_watch(DBusServer *server, DBusWatch *watch)
Adds a watch for this server, chaining out to application-provided watch handlers.
Definition dbus-server.c:297
_dbus_server_remove_watch
void _dbus_server_remove_watch(DBusServer *server, DBusWatch *watch)
Removes a watch previously added with _dbus_server_remove_watch().
Definition dbus-server.c:313
_dbus_server_remove_timeout
void _dbus_server_remove_timeout(DBusServer *server, DBusTimeout *timeout)
Removes a timeout previously added with _dbus_server_add_timeout().
Definition dbus-server.c:421
_dbus_server_unref_unlocked
void _dbus_server_unref_unlocked(DBusServer *server)
Like dbus_server_unref() but does not acquire the lock (must already be held).
Definition dbus-server.c:476
_dbus_server_toggle_timeout
void _dbus_server_toggle_timeout(DBusServer *server, DBusTimeout *timeout, dbus_bool_t enabled)
Toggles a timeout and notifies app via server's DBusTimeoutToggledFunction if available.
Definition dbus-server.c:440
_dbus_server_add_timeout
dbus_bool_t _dbus_server_add_timeout(DBusServer *server, DBusTimeout *timeout)
Adds a timeout for this server, chaining out to application-provided timeout handlers.
Definition dbus-server.c:406
_dbus_server_init_base
dbus_bool_t _dbus_server_init_base(DBusServer *server, const DBusServerVTable *vtable, const DBusString *address, DBusError *error)
Initializes the members of the DBusServer base class.
Definition dbus-server.c:113
_dbus_server_finalize_base
void _dbus_server_finalize_base(DBusServer *server)
Finalizes the members of the DBusServer base class.
Definition dbus-server.c:202
_dbus_server_ref_unlocked
void _dbus_server_ref_unlocked(DBusServer *server)
Like dbus_server_ref() but does not acquire the lock (must already be held).
Definition dbus-server.c:457
_dbus_server_toggle_all_watches
void _dbus_server_toggle_all_watches(DBusServer *server, dbus_bool_t enabled)
Toggles all watch and notifies app via server's DBusWatchToggledFunction if available.
Definition dbus-server.c:331
_dbus_server_listen_socket
DBusServerListenResult _dbus_server_listen_socket(DBusAddressEntry *entry, DBusServer **server_p, DBusError *error)
Tries to interpret the address entry for various socket-related addresses (well, currently only tcp a...
Definition dbus-server-socket.c:540
_dbus_server_listen_unix_socket
DBusServerListenResult _dbus_server_listen_unix_socket(DBusAddressEntry *entry, DBusServer **server_p, DBusError *error)
Tries to interpret the address entry for UNIX socket addresses.
Definition dbus-server-socket.c:761
_dbus_server_listen_platform_specific
DBusServerListenResult _dbus_server_listen_platform_specific(DBusAddressEntry *entry, DBusServer **server_p, DBusError *error)
Tries to interpret the address entry in a platform-specific way, creating a platform-specific server ...
Definition dbus-server-unix.c:55
dbus_server_allocate_data_slot
dbus_bool_t dbus_server_allocate_data_slot(dbus_int32_t *slot_p)
Allocates an integer ID to be used for storing application-specific data on any DBusServer.
Definition dbus-server.c:1100
dbus_server_disconnect
void dbus_server_disconnect(DBusServer *server)
Releases the server's address and stops listening for new clients.
Definition dbus-server.c:798
dbus_server_set_auth_mechanisms
dbus_bool_t dbus_server_set_auth_mechanisms(DBusServer *server, const char **mechanisms)
Sets the authentication mechanisms that this server offers to clients, as a NULL-terminated array of ...
Definition dbus-server.c:1053
dbus_server_get_id
char * dbus_server_get_id(DBusServer *server)
Returns the unique ID of the server, as a newly-allocated string which must be freed by the caller.
Definition dbus-server.c:874
dbus_server_listen
DBusServer * dbus_server_listen(const char *address, DBusError *error)
Listens for new connections on the given address.
Definition dbus-server.c:559
dbus_server_get_address
char * dbus_server_get_address(DBusServer *server)
Returns the address of the server, as a newly-allocated string which must be freed by the caller.
Definition dbus-server.c:838
dbus_server_get_is_connected
dbus_bool_t dbus_server_get_is_connected(DBusServer *server)
Returns TRUE if the server is still listening for new connections.
Definition dbus-server.c:817
dbus_server_unref
void dbus_server_unref(DBusServer *server)
Decrements the reference count of a DBusServer.
Definition dbus-server.c:735
dbus_server_set_new_connection_function
void dbus_server_set_new_connection_function(DBusServer *server, DBusNewConnectionFunction function, void *data, DBusFreeFunction free_data_function)
Sets a function to be used for handling new connections.
Definition dbus-server.c:909
dbus_server_set_watch_functions
dbus_bool_t dbus_server_set_watch_functions(DBusServer *server, DBusAddWatchFunction add_function, DBusRemoveWatchFunction remove_function, DBusWatchToggledFunction toggled_function, void *data, DBusFreeFunction free_data_function)
Sets the watch functions for the server.
Definition dbus-server.c:949
dbus_server_set_data
dbus_bool_t dbus_server_set_data(DBusServer *server, int slot, void *data, DBusFreeFunction free_data_func)
Stores a pointer on a DBusServer, along with an optional function to be used for freeing the data whe...
Definition dbus-server.c:1139
dbus_server_ref
DBusServer * dbus_server_ref(DBusServer *server)
Increments the reference count of a DBusServer.
Definition dbus-server.c:703
dbus_server_get_data
void * dbus_server_get_data(DBusServer *server, int slot)
Retrieves data previously set with dbus_server_set_data().
Definition dbus-server.c:1179
dbus_server_free_data_slot
void dbus_server_free_data_slot(dbus_int32_t *slot_p)
Deallocates a global ID for server data slots.
Definition dbus-server.c:1118
dbus_server_set_timeout_functions
dbus_bool_t dbus_server_set_timeout_functions(DBusServer *server, DBusAddTimeoutFunction add_function, DBusRemoveTimeoutFunction remove_function, DBusTimeoutToggledFunction toggled_function, void *data, DBusFreeFunction free_data_function)
Sets the timeout functions for the server.
Definition dbus-server.c:1002
DBusNewConnectionFunction
void(* DBusNewConnectionFunction)(DBusServer *server, DBusConnection *new_connection, void *data)
Called when a new connection to the server is available.
Definition dbus-server.h:50
_dbus_string_append
dbus_bool_t _dbus_string_append(DBusString *str, const char *buffer)
Appends a nul-terminated C-style string to a DBusString.
Definition dbus-string.c:980
_dbus_string_init
dbus_bool_t _dbus_string_init(DBusString *str)
Initializes a string.
Definition dbus-string.c:182
_dbus_string_copy
dbus_bool_t _dbus_string_copy(const DBusString *source, int start, DBusString *dest, int insert_at)
Like _dbus_string_move(), but does not delete the section of the source string that's copied to the d...
Definition dbus-string.c:1345
_dbus_string_steal_data
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.
Definition dbus-string.c:686
_dbus_string_free
void _dbus_string_free(DBusString *str)
Frees a string created by _dbus_string_init(), and fills it with the same contents as _DBUS_STRING_IN...
Definition dbus-string.c:278
_dbus_string_copy_data
dbus_bool_t _dbus_string_copy_data(const DBusString *str, char **data_return)
Copies the data from the string into a char*.
Definition dbus-string.c:717
_dbus_atomic_dec
dbus_int32_t _dbus_atomic_dec(DBusAtomic *atomic)
Atomically decrement an integer.
Definition dbus-sysdeps-unix.c:3205
_dbus_atomic_inc
dbus_int32_t _dbus_atomic_inc(DBusAtomic *atomic)
Atomically increments an integer.
Definition dbus-sysdeps-unix.c:3178
_dbus_rmutex_new_at_location
void _dbus_rmutex_new_at_location(DBusRMutex **location_p)
Creates a new mutex or creates a no-op mutex if threads are not initialized.
Definition dbus-threads.c:56
_dbus_rmutex_free_at_location
void _dbus_rmutex_free_at_location(DBusRMutex **location_p)
Frees a DBusRMutex; does nothing if passed a NULL pointer.
Definition dbus-threads.c:97
_dbus_timeout_list_add_timeout
dbus_bool_t _dbus_timeout_list_add_timeout(DBusTimeoutList *timeout_list, DBusTimeout *timeout)
Adds a new timeout to the timeout list, invoking the application DBusAddTimeoutFunction if appropriat...
Definition dbus-timeout.c:314
_dbus_timeout_list_free
void _dbus_timeout_list_free(DBusTimeoutList *timeout_list)
Frees a DBusTimeoutList.
Definition dbus-timeout.c:217
_dbus_timeout_list_toggle_timeout
void _dbus_timeout_list_toggle_timeout(DBusTimeoutList *timeout_list, DBusTimeout *timeout, dbus_bool_t enabled)
Sets a timeout to the given enabled state, invoking the application's DBusTimeoutToggledFunction if a...
Definition dbus-timeout.c:366
_dbus_timeout_list_new
DBusTimeoutList * _dbus_timeout_list_new(void)
Creates a new timeout list.
Definition dbus-timeout.c:200
_dbus_timeout_list_set_functions
dbus_bool_t _dbus_timeout_list_set_functions(DBusTimeoutList *timeout_list, DBusAddTimeoutFunction add_function, DBusRemoveTimeoutFunction remove_function, DBusTimeoutToggledFunction toggled_function, void *data, DBusFreeFunction free_data_function)
Sets the timeout functions.
Definition dbus-timeout.c:243
_dbus_timeout_list_remove_timeout
void _dbus_timeout_list_remove_timeout(DBusTimeoutList *timeout_list, DBusTimeout *timeout)
Removes a timeout from the timeout list, invoking the application's DBusRemoveTimeoutFunction if appr...
Definition dbus-timeout.c:344
dbus_int32_t
int dbus_int32_t
A 32-bit signed integer on all platforms.
Definition dbus-arch-deps.h:44
dbus_bool_t
dbus_uint32_t dbus_bool_t
A boolean, valid values are TRUE and FALSE.
Definition dbus-types.h:37
_dbus_watch_list_add_watch
dbus_bool_t _dbus_watch_list_add_watch(DBusWatchList *watch_list, DBusWatch *watch)
Adds a new watch to the watch list, invoking the application DBusAddWatchFunction if appropriate.
Definition dbus-watch.c:383
_dbus_watch_list_new
DBusWatchList * _dbus_watch_list_new(void)
Creates a new watch list.
Definition dbus-watch.c:234
_dbus_watch_list_free
void _dbus_watch_list_free(DBusWatchList *watch_list)
Frees a DBusWatchList.
Definition dbus-watch.c:251
_dbus_watch_list_set_functions
dbus_bool_t _dbus_watch_list_set_functions(DBusWatchList *watch_list, DBusAddWatchFunction add_function, DBusRemoveWatchFunction remove_function, DBusWatchToggledFunction toggled_function, void *data, DBusFreeFunction free_data_function)
Sets the watch functions.
Definition dbus-watch.c:297
_dbus_watch_list_toggle_all_watches
void _dbus_watch_list_toggle_all_watches(DBusWatchList *watch_list, dbus_bool_t enabled)
Sets all watches to the given enabled state, invoking the application's DBusWatchToggledFunction if a...
Definition dbus-watch.c:474
_dbus_watch_list_remove_watch
void _dbus_watch_list_remove_watch(DBusWatchList *watch_list, DBusWatch *watch)
Removes a watch from the watch list, invoking the application's DBusRemoveWatchFunction if appropriat...
Definition dbus-watch.c:416
DBusAddressEntry
Internals of DBusAddressEntry.
Definition dbus-address.c:49
DBusDataSlotAllocator
An allocator that tracks a set of slot IDs.
Definition dbus-dataslot.h:58
DBusError
Object representing an exception.
Definition dbus-errors.h:51
DBusServerVTable
Virtual table to be implemented by all server "subclasses".
Definition dbus-server-protected.h:46
DBusServerVTable::disconnect
void(* disconnect)(DBusServer *server)
Disconnect this server.
Definition dbus-server-protected.h:50
DBusServerVTable::finalize
void(* finalize)(DBusServer *server)
The finalize method must free the server.
Definition dbus-server-protected.h:47
DBusServer
Internals of DBusServer object.
Definition dbus-server-protected.h:59
DBusServer::published_address
dbus_bool_t published_address
flag which indicates that server has published its bus address.
Definition dbus-server-protected.h:72
DBusServer::slot_list
DBusDataSlotList slot_list
Data stored by allocated integer ID.
Definition dbus-server-protected.h:76
DBusServer::address
char * address
Address this server is listening on.
Definition dbus-server-protected.h:71
DBusServer::new_connection_free_data_function
DBusFreeFunction new_connection_free_data_function
Callback to invoke to free new_connection_data when server is finalized or data is replaced.
Definition dbus-server-protected.h:82
DBusServer::refcount
DBusAtomic refcount
Reference count.
Definition dbus-server-protected.h:60
DBusServer::watches
DBusWatchList * watches
Our watches.
Definition dbus-server-protected.h:68
DBusServer::guid
DBusGUID guid
Globally unique ID of server.
Definition dbus-server-protected.h:64
DBusServer::guid_hex
DBusString guid_hex
Hex-encoded version of GUID.
Definition dbus-server-protected.h:66
DBusServer::disconnected
unsigned int disconnected
TRUE if we are disconnected.
Definition dbus-server-protected.h:89
DBusServer::mutex
DBusRMutex * mutex
Lock on the server object.
Definition dbus-server-protected.h:62
DBusServer::new_connection_function
DBusNewConnectionFunction new_connection_function
Callback to invoke when a new connection is created.
Definition dbus-server-protected.h:78
DBusServer::vtable
const DBusServerVTable * vtable
Virtual methods for this instance.
Definition dbus-server-protected.h:61
DBusServer::new_connection_data
void * new_connection_data
Data for new connection callback.
Definition dbus-server-protected.h:80
DBusServer::have_server_lock
unsigned int have_server_lock
Does someone have the server mutex locked.
Definition dbus-server-protected.h:92
DBusServer::auth_mechanisms
char ** auth_mechanisms
Array of allowed authentication mechanisms.
Definition dbus-server-protected.h:87
DBusServer::timeouts
DBusTimeoutList * timeouts
Our timeouts.
Definition dbus-server-protected.h:69
DBusString
Definition dbus-string.h:47
DBusTimeoutList
DBusTimeoutList implementation details.
Definition dbus-timeout.c:183
DBusTimeout
Internals of DBusTimeout.
Definition dbus-timeout.c:43
DBusWatchList
DBusWatchList implementation details.
Definition dbus-watch.c:217
DBusWatch
Implementation of DBusWatch.
Definition dbus-watch.c:43