25 #include "dbus-internals.h"    26 #include "dbus-server-socket.h"    27 #include "dbus-transport-socket.h"    28 #include "dbus-connection-internal.h"    29 #include "dbus-memory.h"    30 #include "dbus-nonce.h"    31 #include "dbus-string.h"    68   for (i = 0 ; i < socket_server->
n_fds ; i++)
    69     if (socket_server->
watch[i])
    86 handle_new_client_fd_and_unlock (
DBusServer *server,
    92   void *new_connection_data;
    94   _dbus_verbose (
"Creating new client connection with fd %" DBUS_SOCKET_FORMAT 
"\n",
    95                  _dbus_socket_printable (client_fd));
    97   HAVE_LOCK_CHECK (server);
   101       SERVER_UNLOCK (server);
   106   if (transport == 
NULL)
   109       SERVER_UNLOCK (server);
   117       SERVER_UNLOCK (server);
   129   if (connection == 
NULL)
   131       SERVER_UNLOCK (server);
   142   SERVER_UNLOCK (server);
   144   if (new_connection_function)
   146       (* new_connection_function) (server, connection,
   147                                    new_connection_data);
   166 #ifndef DBUS_DISABLE_ASSERT   171   SERVER_LOCK (server);
   173 #ifndef DBUS_DISABLE_ASSERT   174   for (i = 0 ; i < socket_server->
n_fds ; i++)
   176       if (socket_server->
watch[i] == watch)
   182   _dbus_verbose (
"Handling client connection, flags 0x%x\n", flags);
   190       listen_fd = _dbus_watch_get_socket (watch);
   193           client_fd = _dbus_accept_with_noncefile (listen_fd, socket_server->
noncefile);
   197       saved_errno = _dbus_save_socket_errno ();
   199       if (!_dbus_socket_is_valid (client_fd))
   204             _dbus_verbose (
"No client available to accept after all\n");
   206             _dbus_verbose (
"Failed to accept a client connection: %s\n",
   207                            _dbus_strerror (saved_errno));
   209           SERVER_UNLOCK (server);
   213           if (!handle_new_client_fd_and_unlock (server, client_fd))
   214             _dbus_verbose (
"Rejected client connection due to lack of memory\n");
   219     _dbus_verbose (
"Error on server listening socket\n");
   222     _dbus_verbose (
"Hangup on server listening socket\n");
   233   HAVE_LOCK_CHECK (server);
   235   for (i = 0 ; i < socket_server->
n_fds ; i++)
   237       if (socket_server->
watch[i])
   240                                      socket_server->
watch[i]);
   247       _dbus_socket_invalidate (&socket_server->
fds[i]);
   258       _dbus_daemon_unpublish_session_bus_address();
   260   HAVE_LOCK_CHECK (server);
   296   if (socket_server == 
NULL)
   302   if (!socket_server->
fds)
   306   if (!socket_server->
watch)
   309   for (i = 0 ; i < 
n_fds ; i++)
   316                                socket_handle_watch, socket_server,
   321       socket_server->
n_fds++;
   322       socket_server->
fds[i] = fds[i];
   327                                &socket_vtable, address,
   333   SERVER_LOCK (server);
   335   for (i = 0 ; i < 
n_fds ; i++)
   338                                    socket_server->
watch[i]))
   341           for (j = 0 ; j < i ; j++)
   343                                        socket_server->
watch[j]);
   345           SERVER_UNLOCK (server);
   351   SERVER_UNLOCK (server);
   353   _dbus_server_trace_ref (&socket_server->
base, 0, 1, 
"new_for_socket");
   357   for (i = 0 ; i < 
n_fds ; i++)
   374     _DBUS_SET_OOM (error);
   408   int nlisten_fds = 0, i;
   414   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
   438   else if (strcmp (bind, 
"*") == 0)
   444   if (nlisten_fds <= 0)
   446       _DBUS_ASSERT_ERROR_IS_SET(error);
   470       if (noncefile == 
NULL)
   476       if (!_dbus_noncefile_create (noncefile, error))
   491       if (noncefile != 
NULL)
   504   _dbus_noncefile_delete (noncefile, 
NULL);
   510   for (i = 0 ; i < nlisten_fds ; i++)
   535 DBusServerListenResult
   546   if (strcmp (method, 
"tcp") == 0 || strcmp (method, 
"nonce-tcp") == 0)
   559                                                    family, error, strcmp (method, 
"nonce-tcp") == 0 ? 
TRUE : 
FALSE);
   563           _DBUS_ASSERT_ERROR_IS_CLEAR(error);
   564           return DBUS_SERVER_LISTEN_OK;
   568           _DBUS_ASSERT_ERROR_IS_SET(error);
   569           return DBUS_SERVER_LISTEN_DID_NOT_CONNECT;
   574       _DBUS_ASSERT_ERROR_IS_CLEAR(error);
   575       return DBUS_SERVER_LISTEN_NOT_HANDLED;
 dbus_bool_t _dbus_string_append(DBusString *str, const char *buffer)
Appends a nul-terminated C-style string to a DBusString. 
dbus_bool_t _dbus_server_add_watch(DBusServer *server, DBusWatch *watch)
Adds a watch for this server, chaining out to application-provided watch handlers. 
DBusWatch * _dbus_watch_new(DBusPollable fd, unsigned int flags, dbus_bool_t enabled, DBusWatchHandler handler, void *data, DBusFreeFunction free_data_function)
Creates a new DBusWatch. 
DBusNonceFile * noncefile
Nonce file used to authenticate clients. 
Implementation of DBusWatch. 
#define NULL
A null pointer, defined appropriately for C or C++. 
void dbus_free(void *memory)
Frees a block of memory previously allocated by dbus_malloc() or dbus_malloc0(). 
#define dbus_new(type, count)
Safe macro for using dbus_malloc(). 
Internals of DBusServer object. 
#define _dbus_assert(condition)
Aborts with an error message if the condition is false. 
const char * dbus_address_entry_get_method(DBusAddressEntry *entry)
Returns the method string of an address entry. 
void _dbus_connection_close_if_only_one_ref(DBusConnection *connection)
Used internally to handle the semantics of dbus_server_set_new_connection_function(). 
Implementation details of DBusConnection. 
dbus_bool_t _dbus_string_init(DBusString *str)
Initializes a string. 
DBUS_PRIVATE_EXPORT void _dbus_server_ref_unlocked(DBusServer *server)
Like dbus_server_ref() but does not acquire the lock (must already be held) 
void(* DBusNewConnectionFunction)(DBusServer *server, DBusConnection *new_connection, void *data)
Called when a new connection to the server is available. 
DBusNewConnectionFunction new_connection_function
Callback to invoke when a new connection is created. 
dbus_bool_t _dbus_close_socket(DBusSocket fd, DBusError *error)
Closes a socket. 
DBusServer * _dbus_server_new_for_tcp_socket(const char *host, const char *bind, const char *port, const char *family, DBusError *error, dbus_bool_t use_nonce)
Creates a new server listening on TCP. 
char ** auth_mechanisms
Array of allowed authentication mechanisms. 
dbus_bool_t _dbus_delete_file(const DBusString *filename, DBusError *error)
Deletes the given file. 
dbus_bool_t _dbus_transport_set_auth_mechanisms(DBusTransport *transport, const char **mechanisms)
Sets the SASL authentication mechanisms supported by this transport. 
DBusServer * _dbus_server_new_for_socket(DBusSocket *fds, int n_fds, const DBusString *address, DBusNonceFile *noncefile, DBusError *error)
Creates a new server listening on the given file descriptor. 
const char * dbus_address_entry_get_value(DBusAddressEntry *entry, const char *key)
Returns a value from a key of an entry. 
Implementation details of DBusServerSocket. 
DBusTransport * _dbus_transport_new_for_socket(DBusSocket fd, const DBusString *server_guid, const DBusString *address)
Creates a new transport for the given socket file descriptor. 
#define dbus_new0(type, count)
Safe macro for using dbus_malloc0(). 
dbus_bool_t _dbus_get_is_errno_eagain_or_ewouldblock(int e)
See if errno is EAGAIN or EWOULDBLOCK (this has to be done differently for Winsock so is abstracted) ...
dbus_uint32_t dbus_bool_t
A boolean, valid values are TRUE and FALSE. 
void _dbus_string_init_const(DBusString *str, const char *value)
Initializes a constant string. 
void _dbus_server_socket_own_filename(DBusServer *server, char *filename)
This is a bad hack since it's really unix domain socket specific. 
DBusSocket _dbus_accept(DBusSocket listen_fd)
Accepts a connection on a listening socket. 
Internals of DBusAddressEntry. 
void _dbus_server_remove_watch(DBusServer *server, DBusWatch *watch)
Removes a watch previously added with _dbus_server_remove_watch(). 
void _dbus_watch_invalidate(DBusWatch *watch)
Clears the file descriptor from a now-invalid watch object so that no one tries to use it...
Object representing an exception. 
dbus_bool_t _dbus_address_append_escaped(DBusString *escaped, const DBusString *unescaped)
Appends an escaped version of one string to another string, using the D-Bus address escaping mechanis...
int _dbus_listen_tcp_socket(const char *host, const char *port, const char *family, DBusString *retport, DBusSocket **fds_p, DBusError *error)
Creates a socket and binds it to the given path, then listens on the socket. 
DBusSocket * fds
File descriptor or DBUS_SOCKET_INVALID if disconnected. 
void dbus_set_error(DBusError *error, const char *name, const char *format,...)
Assigns an error name and message to a DBusError. 
void _dbus_server_finalize_base(DBusServer *server)
Finalizes the members of the DBusServer base class. 
Virtual table to be implemented by all server "subclasses". 
void dbus_server_unref(DBusServer *server)
Decrements the reference count of a DBusServer. 
As in POLLERR (can't watch for this, but can be present in current state passed to dbus_watch_handle(...
DBusConnection * _dbus_connection_new_for_transport(DBusTransport *transport)
Creates a new connection for the given transport. 
void _dbus_string_free(DBusString *str)
Frees a string created by _dbus_string_init(). 
#define TRUE
Expands to "1". 
As in POLLHUP (can't watch for it, but can be present in current state passed to dbus_watch_handle())...
dbus_bool_t published_address
flag which indicates that server has published its bus address. 
Object representing a transport such as a socket. 
void * new_connection_data
Data for new connection callback. 
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...
DBusServer base
Parent class members. 
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. 
char * socket_name
Name of domain socket, to unlink if appropriate. 
void _dbus_watch_unref(DBusWatch *watch)
Decrements the reference count of a DBusWatch object and finalizes the object if the count reaches ze...
dbus_bool_t _dbus_set_socket_nonblocking(DBusSocket fd, DBusError *error)
Sets a file descriptor to be nonblocking. 
DBusString guid_hex
Hex-encoded version of GUID. 
#define DBUS_ERROR_NO_MEMORY
There was not enough memory to complete an operation. 
#define FALSE
Expands to "0". 
int n_fds
Number of active file handles. 
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_error_is_set(const DBusError *error)
Checks whether an error occurred (the error is set). 
void _dbus_transport_unref(DBusTransport *transport)
Decrements the reference count for the transport. 
DBusWatch ** watch
File descriptor watch.