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])
84handle_new_client_fd_and_unlock (
DBusServer *server,
90 void *new_connection_data;
92 _dbus_verbose (
"Creating new client connection with fd %" DBUS_SOCKET_FORMAT
"\n",
93 _dbus_socket_printable (client_fd));
95 HAVE_LOCK_CHECK (server);
99 SERVER_UNLOCK (server);
104 if (transport ==
NULL)
107 SERVER_UNLOCK (server);
115 SERVER_UNLOCK (server);
127 if (connection ==
NULL)
129 SERVER_UNLOCK (server);
140 SERVER_UNLOCK (server);
142 if (new_connection_function)
144 (* new_connection_function) (server, connection,
145 new_connection_data);
164#ifndef DBUS_DISABLE_ASSERT
169 SERVER_LOCK (server);
171#ifndef DBUS_DISABLE_ASSERT
172 for (i = 0 ; i < socket_server->
n_fds ; i++)
174 if (socket_server->
watch[i] == watch)
180 _dbus_verbose (
"Handling client connection, flags 0x%x\n", flags);
188 listen_fd = _dbus_watch_get_socket (watch);
191 client_fd = _dbus_accept_with_noncefile (listen_fd, socket_server->
noncefile);
195 saved_errno = _dbus_save_socket_errno ();
197 if (!_dbus_socket_is_valid (client_fd))
202 _dbus_verbose (
"No client available to accept after all\n");
204 _dbus_verbose (
"Failed to accept a client connection: %s\n",
205 _dbus_strerror (saved_errno));
207 SERVER_UNLOCK (server);
211 if (!handle_new_client_fd_and_unlock (server, client_fd))
212 _dbus_verbose (
"Rejected client connection due to lack of memory\n");
217 _dbus_verbose (
"Error on server listening socket\n");
220 _dbus_verbose (
"Hangup on server listening socket\n");
231 HAVE_LOCK_CHECK (server);
233 for (i = 0 ; i < socket_server->
n_fds ; i++)
235 if (socket_server->
watch[i])
238 socket_server->
watch[i]);
244 if (_dbus_socket_is_valid (socket_server->
fds[i]))
247 _dbus_socket_invalidate (&socket_server->
fds[i]);
259 _dbus_daemon_unpublish_session_bus_address();
261 HAVE_LOCK_CHECK (server);
297 if (socket_server ==
NULL)
303 if (!socket_server->
fds)
307 if (!socket_server->
watch)
310 for (i = 0 ; i < n_fds ; i++)
317 socket_handle_watch, socket_server,
322 socket_server->
n_fds++;
323 socket_server->
fds[i] = fds[i];
324 socket_server->
watch[i] = watch;
328 &socket_vtable, address,
334 SERVER_LOCK (server);
336 for (i = 0 ; i < n_fds ; i++)
339 socket_server->
watch[i]))
346 for (j = 0; j < n_fds; j++)
347 _dbus_socket_invalidate (&socket_server->
fds[j]);
352 for (j = i; j < n_fds; j++)
359 _dbus_server_disconnect_unlocked (server);
360 SERVER_UNLOCK (server);
366 SERVER_UNLOCK (server);
368 _dbus_server_trace_ref (&socket_server->
base, 0, 1,
"new_for_socket");
372 if (socket_server !=
NULL)
376 for (i = 0; i < n_fds; i++)
393 _DBUS_SET_OOM (error);
427 int nlisten_fds = 0, i;
428 DBusString address = _DBUS_STRING_INIT_INVALID;
430 DBusString port_str = _DBUS_STRING_INIT_INVALID;
432 const char *family_used =
NULL;
434 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
456 else if (strcmp (bind,
"*") == 0)
463 if (nlisten_fds <= 0)
465 _DBUS_ASSERT_ERROR_IS_SET(error);
488 if (!_dbus_noncefile_create (&noncefile, error))
511 _dbus_noncefile_delete (&noncefile,
NULL);
513 if (listen_fds !=
NULL)
515 for (i = 0; i < nlisten_fds; i++)
537DBusServerListenResult
548 if (strcmp (method,
"tcp") == 0 || strcmp (method,
"nonce-tcp") == 0)
561 family, error, strcmp (method,
"nonce-tcp") == 0 ?
TRUE :
FALSE);
565 _DBUS_ASSERT_ERROR_IS_CLEAR(error);
566 return DBUS_SERVER_LISTEN_OK;
570 _DBUS_ASSERT_ERROR_IS_SET(error);
571 return DBUS_SERVER_LISTEN_DID_NOT_CONNECT;
576 _DBUS_ASSERT_ERROR_IS_CLEAR(error);
577 return DBUS_SERVER_LISTEN_NOT_HANDLED;
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...
const char * dbus_address_entry_get_method(DBusAddressEntry *entry)
Returns the method string of an address entry.
const char * dbus_address_entry_get_value(DBusAddressEntry *entry, const char *key)
Returns a value from a key of an entry.
DBusConnection * _dbus_connection_new_for_transport(DBusTransport *transport)
Creates a new connection for the given transport.
void _dbus_connection_close_if_only_one_ref(DBusConnection *connection)
Used internally to handle the semantics of dbus_server_set_new_connection_function().
void dbus_connection_unref(DBusConnection *connection)
Decrements the reference count of a DBusConnection, and finalizes it if the count reaches zero.
@ DBUS_WATCH_READABLE
As in POLLIN.
@ DBUS_WATCH_HANGUP
As in POLLHUP (can't watch for it, but can be present in current state passed to dbus_watch_handle())...
@ DBUS_WATCH_ERROR
As in POLLERR (can't watch for this, but can be present in current state passed to dbus_watch_handle(...
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).
dbus_bool_t _dbus_delete_file(const DBusString *filename, DBusError *error)
Deletes the given file.
#define _dbus_assert(condition)
Aborts with an error message if the condition is false.
#define NULL
A null pointer, defined appropriately for C or C++.
#define TRUE
Expands to "1".
#define FALSE
Expands to "0".
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().
#define dbus_new0(type, count)
Safe macro for using dbus_malloc0().
#define DBUS_ERROR_NO_MEMORY
There was not enough memory to complete an operation.
dbus_bool_t _dbus_server_add_watch(DBusServer *server, DBusWatch *watch)
Adds a watch for this server, chaining out to application-provided watch handlers.
void _dbus_server_remove_watch(DBusServer *server, DBusWatch *watch)
Removes a watch previously added with _dbus_server_remove_watch().
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.
void _dbus_server_finalize_base(DBusServer *server)
Finalizes the members of the DBusServer base class.
DBUS_PRIVATE_EXPORT void _dbus_server_ref_unlocked(DBusServer *server)
Like dbus_server_ref() but does not acquire the lock (must already be held)
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.
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.
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...
void _dbus_server_socket_own_filename(DBusServer *server, char *filename)
This is a bad hack since it's really unix domain socket specific.
void dbus_server_unref(DBusServer *server)
Decrements the reference count of a DBusServer.
void(* DBusNewConnectionFunction)(DBusServer *server, DBusConnection *new_connection, void *data)
Called when a new connection to the server is available.
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_string_init(DBusString *str)
Initializes a string.
void _dbus_string_init_const(DBusString *str, const char *value)
Initializes a constant 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...
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_bool_t _dbus_close_socket(DBusSocket fd, DBusError *error)
Closes a socket.
dbus_bool_t _dbus_set_socket_nonblocking(DBusSocket fd, DBusError *error)
Sets a file descriptor to be nonblocking.
int _dbus_listen_tcp_socket(const char *host, const char *port, const char *family, DBusString *retport, const char **retfamily, DBusSocket **fds_p, DBusError *error)
Creates a socket and binds it to the given path, then listens on the socket.
DBusSocket _dbus_accept(DBusSocket listen_fd)
Accepts a connection on a listening socket.
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_bool_t _dbus_transport_set_auth_mechanisms(DBusTransport *transport, const char **mechanisms)
Sets the SASL authentication mechanisms supported by this transport.
void _dbus_transport_unref(DBusTransport *transport)
Decrements the reference count for the transport.
dbus_uint32_t dbus_bool_t
A boolean, valid values are TRUE and FALSE.
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.
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_watch_invalidate(DBusWatch *watch)
Clears the file descriptor from a now-invalid watch object so that no one tries to use it.
Internals of DBusAddressEntry.
Implementation details of DBusConnection.
Object representing an exception.
Implementation details of DBusServerSocket.
int n_fds
Number of active file handles.
DBusSocket * fds
File descriptor or DBUS_SOCKET_INVALID if disconnected.
DBusNonceFile * noncefile
Nonce file used to authenticate clients.
DBusWatch ** watch
File descriptor watch.
DBusServer base
Parent class members.
char * socket_name
Name of domain socket, to unlink if appropriate.
Virtual table to be implemented by all server "subclasses".
Internals of DBusServer object.
dbus_bool_t published_address
flag which indicates that server has published its bus address.
DBusString guid_hex
Hex-encoded version of GUID.
DBusNewConnectionFunction new_connection_function
Callback to invoke when a new connection is created.
void * new_connection_data
Data for new connection callback.
char ** auth_mechanisms
Array of allowed authentication mechanisms.
Object representing a transport such as a socket.
Implementation of DBusWatch.