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]);
 
  246       if (_dbus_socket_is_valid (socket_server->
fds[i]))
 
  249           _dbus_socket_invalidate (&socket_server->
fds[i]);
 
  261       _dbus_daemon_unpublish_session_bus_address();
 
  263   HAVE_LOCK_CHECK (server);
 
  299   if (socket_server == 
NULL)
 
  305   if (!socket_server->
fds)
 
  309   if (!socket_server->
watch)
 
  312   for (i = 0 ; i < n_fds ; i++)
 
  319                                socket_handle_watch, socket_server,
 
  324       socket_server->
n_fds++;
 
  325       socket_server->
fds[i] = fds[i];
 
  326       socket_server->
watch[i] = watch;
 
  330                                &socket_vtable, address,
 
  336   SERVER_LOCK (server);
 
  338   for (i = 0 ; i < n_fds ; i++)
 
  341                                    socket_server->
watch[i]))
 
  348           for (j = 0; j < n_fds; j++)
 
  349             _dbus_socket_invalidate (&socket_server->
fds[j]);
 
  354           for (j = i; j < n_fds; j++)
 
  361           _dbus_server_disconnect_unlocked (server);
 
  362           SERVER_UNLOCK (server);
 
  368   SERVER_UNLOCK (server);
 
  370   _dbus_server_trace_ref (&socket_server->
base, 0, 1, 
"new_for_socket");
 
  374   for (i = 0 ; i < n_fds ; i++)
 
  392     _DBUS_SET_OOM (error);
 
  426   int nlisten_fds = 0, i;
 
  432   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
 
  456   else if (strcmp (bind, 
"*") == 0)
 
  462   if (nlisten_fds <= 0)
 
  464       _DBUS_ASSERT_ERROR_IS_SET(error);
 
  488       if (noncefile == 
NULL)
 
  494       if (!_dbus_noncefile_create (noncefile, error))
 
  509       if (noncefile != 
NULL)
 
  522   _dbus_noncefile_delete (noncefile, 
NULL);
 
  528   for (i = 0 ; i < nlisten_fds ; i++)
 
  553 DBusServerListenResult
 
  564   if (strcmp (method, 
"tcp") == 0 || strcmp (method, 
"nonce-tcp") == 0)
 
  577                                                    family, error, strcmp (method, 
"nonce-tcp") == 0 ? 
TRUE : 
FALSE);
 
  581           _DBUS_ASSERT_ERROR_IS_CLEAR(error);
 
  582           return DBUS_SERVER_LISTEN_OK;
 
  586           _DBUS_ASSERT_ERROR_IS_SET(error);
 
  587           return DBUS_SERVER_LISTEN_DID_NOT_CONNECT;
 
  592       _DBUS_ASSERT_ERROR_IS_CLEAR(error);
 
  593       return DBUS_SERVER_LISTEN_NOT_HANDLED;
 
  
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.
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.
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.
DBusSocket _dbus_accept(DBusSocket listen_fd)
Accepts a connection on a listening socket.
void dbus_server_unref(DBusServer *server)
Decrements the reference count of a DBusServer.
void _dbus_string_free(DBusString *str)
Frees a string created by _dbus_string_init().
void _dbus_server_socket_own_filename(DBusServer *server, char *filename)
This is a bad hack since it's really unix domain socket specific.
DBusWatch ** watch
File descriptor watch.
void _dbus_server_remove_watch(DBusServer *server, DBusWatch *watch)
Removes a watch previously added with _dbus_server_remove_watch().
dbus_bool_t _dbus_set_socket_nonblocking(DBusSocket fd, DBusError *error)
Sets a file descriptor to be nonblocking.
Implementation of DBusWatch.
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...
char ** auth_mechanisms
Array of allowed authentication mechanisms.
const char * dbus_address_entry_get_method(DBusAddressEntry *entry)
Returns the method string of an address entry.
Implementation details of DBusConnection.
dbus_bool_t _dbus_string_init(DBusString *str)
Initializes a string.
dbus_bool_t _dbus_server_add_watch(DBusServer *server, DBusWatch *watch)
Adds a watch for this server, chaining out to application-provided watch handlers.
DBusNewConnectionFunction new_connection_function
Callback to invoke when a new connection is created.
@ DBUS_WATCH_READABLE
As in POLLIN.
@ DBUS_WATCH_ERROR
As in POLLERR (can't watch for this, but can be present in current state passed to dbus_watch_handle(...
dbus_bool_t _dbus_delete_file(const DBusString *filename, DBusError *error)
Deletes the given file.
void _dbus_watch_unref(DBusWatch *watch)
Decrements the reference count of a DBusWatch object and finalizes the object if the count reaches ze...
void dbus_free(void *memory)
Frees a block of memory previously allocated by dbus_malloc() or dbus_malloc0().
DBusConnection * _dbus_connection_new_for_transport(DBusTransport *transport)
Creates a new connection for the given transport.
DBusSocket * fds
File descriptor or DBUS_SOCKET_INVALID if disconnected.
dbus_bool_t published_address
flag which indicates that server has published its bus address.
Internals of DBusAddressEntry.
Object representing a transport such as a socket.
#define DBUS_ERROR_NO_MEMORY
There was not enough memory to complete an operation.
const char * dbus_address_entry_get_value(DBusAddressEntry *entry, const char *key)
Returns a value from a key of an entry.
dbus_bool_t _dbus_transport_set_auth_mechanisms(DBusTransport *transport, const char **mechanisms)
Sets the SASL authentication mechanisms supported by this transport.
void(* DBusNewConnectionFunction)(DBusServer *server, DBusConnection *new_connection, void *data)
Called when a new connection to the server is available.
DBusServer base
Parent class members.
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.
#define dbus_new(type, count)
dbus_bool_t _dbus_close_socket(DBusSocket fd, DBusError *error)
Closes a socket.
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...
#define _dbus_assert(condition)
Virtual table to be implemented by all server "subclasses".
Object representing an exception.
void _dbus_watch_invalidate(DBusWatch *watch)
Clears the file descriptor from a now-invalid watch object so that no one tries to use it.
DBusString guid_hex
Hex-encoded version of GUID.
void dbus_set_error(DBusError *error, const char *name, const char *format,...)
Assigns an error name and message to a DBusError.
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.
void _dbus_server_finalize_base(DBusServer *server)
Finalizes the members of the DBusServer base class.
Implementation details of DBusServerSocket.
void * new_connection_data
Data for new connection callback.
DBusNonceFile * noncefile
Nonce file used to authenticate clients.
void _dbus_string_init_const(DBusString *str, const char *value)
Initializes a constant string.
#define dbus_new0(type, count)
DBUS_PRIVATE_EXPORT void _dbus_server_ref_unlocked(DBusServer *server)
Like dbus_server_ref() but does not acquire the lock (must already be held)
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.
char * socket_name
Name of domain socket, to unlink if appropriate.
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)
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.
@ DBUS_WATCH_HANGUP
As in POLLHUP (can't watch for it, but can be present in current state passed to dbus_watch_handle())...
dbus_bool_t _dbus_string_append(DBusString *str, const char *buffer)
Appends a nul-terminated C-style string to a DBusString.
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.
void _dbus_connection_close_if_only_one_ref(DBusConnection *connection)
Used internally to handle the semantics of dbus_server_set_new_connection_function().
dbus_uint32_t dbus_bool_t