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 %d\n", client_fd);
96 HAVE_LOCK_CHECK (server);
98 if (!_dbus_set_fd_nonblocking (client_fd,
NULL))
100 SERVER_UNLOCK (server);
105 if (transport ==
NULL)
108 SERVER_UNLOCK (server);
116 SERVER_UNLOCK (server);
128 if (connection ==
NULL)
130 SERVER_UNLOCK (server);
141 SERVER_UNLOCK (server);
143 if (new_connection_function)
145 (* new_connection_function) (server, connection,
146 new_connection_data);
165 #ifndef DBUS_DISABLE_ASSERT
170 SERVER_LOCK (server);
172 #ifndef DBUS_DISABLE_ASSERT
173 for (i = 0 ; i < socket_server->
n_fds ; i++)
175 if (socket_server->
watch[i] == watch)
181 _dbus_verbose (
"Handling client connection, flags 0x%x\n", flags);
191 client_fd = _dbus_accept_with_noncefile (listen_fd, socket_server->
noncefile);
200 _dbus_verbose (
"No client available to accept after all\n");
202 _dbus_verbose (
"Failed to accept a client connection: %s\n",
205 SERVER_UNLOCK (server);
209 if (!handle_new_client_fd_and_unlock (server, client_fd))
210 _dbus_verbose (
"Rejected client connection due to lack of memory\n");
215 _dbus_verbose (
"Error on server listening socket\n");
218 _dbus_verbose (
"Hangup on server listening socket\n");
229 HAVE_LOCK_CHECK (server);
231 for (i = 0 ; i < socket_server->
n_fds ; i++)
233 if (socket_server->
watch[i])
236 socket_server->
watch[i]);
243 socket_server->
fds[i] = -1;
254 _dbus_daemon_unpublish_session_bus_address();
256 HAVE_LOCK_CHECK (server);
290 if (socket_server ==
NULL)
296 if (!socket_server->
fds)
300 if (!socket_server->
watch)
303 for (i = 0 ; i < n_fds ; i++)
310 socket_handle_watch, socket_server,
315 socket_server->
n_fds++;
316 socket_server->
fds[i] = fds[i];
317 socket_server->
watch[i] = watch;
321 &socket_vtable, address))
326 SERVER_LOCK (server);
328 for (i = 0 ; i < n_fds ; i++)
331 socket_server->
watch[i]))
334 for (j = 0 ; j < i ; j++)
336 socket_server->
watch[j]);
338 SERVER_UNLOCK (server);
344 SERVER_UNLOCK (server);
346 _dbus_server_trace_ref (&socket_server->
base, 0, 1,
"new_for_socket");
350 for (i = 0 ; i < n_fds ; i++)
396 int *listen_fds =
NULL;
397 int nlisten_fds = 0, i;
403 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
427 else if (strcmp (bind,
"*") == 0)
433 if (nlisten_fds <= 0)
435 _DBUS_ASSERT_ERROR_IS_SET(error);
459 if (noncefile ==
NULL)
465 if (!_dbus_noncefile_create (noncefile, error))
481 if (noncefile !=
NULL)
494 _dbus_noncefile_delete (noncefile,
NULL);
500 for (i = 0 ; i < nlisten_fds ; i++)
525 DBusServerListenResult
536 if (strcmp (method,
"tcp") == 0 || strcmp (method,
"nonce-tcp") == 0)
549 family, error, strcmp (method,
"nonce-tcp") == 0 ?
TRUE :
FALSE);
553 _DBUS_ASSERT_ERROR_IS_CLEAR(error);
554 return DBUS_SERVER_LISTEN_OK;
558 _DBUS_ASSERT_ERROR_IS_SET(error);
559 return DBUS_SERVER_LISTEN_DID_NOT_CONNECT;
564 _DBUS_ASSERT_ERROR_IS_CLEAR(error);
565 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.
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().
void _dbus_watch_invalidate(DBusWatch *watch)
Clears the file descriptor from a now-invalid watch object so that no one tries to use it...
#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().
int _dbus_accept(int listen_fd)
Accepts a connection on a listening socket.
Implementation details of DBusConnection.
dbus_bool_t _dbus_string_init(DBusString *str)
Initializes a string.
void _dbus_server_ref_unlocked(DBusServer *server)
Like dbus_server_ref() but does not acquire the lock (must already be held)
DBusTransport * _dbus_transport_new_for_socket(int fd, const DBusString *server_guid, const DBusString *address)
Creates a new transport for the given socket file descriptor.
void(* DBusNewConnectionFunction)(DBusServer *server, DBusConnection *new_connection, void *data)
Called when a new connection to the server is available.
int * fds
File descriptor or -1 if disconnected.
DBusNewConnectionFunction new_connection_function
Callback to invoke when a new connection is created.
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_transport_set_auth_mechanisms(DBusTransport *transport, const char **mechanisms)
Sets the SASL authentication mechanisms supported by this transport.
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.
#define dbus_new0(type, count)
Safe macro for using dbus_malloc0().
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.
DBUS_EXPORT int dbus_watch_get_socket(DBusWatch *watch)
Returns a socket to be watched, on UNIX this will return -1 if our transport is not socket-based so d...
void _dbus_server_socket_own_filename(DBusServer *server, char *filename)
This is a bad hack since it's really unix domain socket specific.
DBusServer * _dbus_server_new_for_socket(int *fds, int n_fds, const DBusString *address, DBusNonceFile *noncefile)
Creates a new server listening on the given file descriptor.
Internals of DBusAddressEntry.
void _dbus_server_remove_watch(DBusServer *server, DBusWatch *watch)
Removes a watch previously added with _dbus_server_remove_watch().
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...
dbus_bool_t _dbus_server_init_base(DBusServer *server, const DBusServerVTable *vtable, const DBusString *address)
Initializes the members of the DBusServer base class.
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.
const char * _dbus_strerror_from_errno(void)
Get error message from errno.
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.
DBusWatch * _dbus_watch_new(int 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(void)
See if errno is EAGAIN or EWOULDBLOCK (this has to be done differently for Winsock so is abstracted) ...
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_watch_unref(DBusWatch *watch)
Decrements the reference count of a DBusWatch object and finalizes the object if the count reaches ze...
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_close_socket(int fd, DBusError *error)
Closes a socket.
dbus_bool_t _dbus_delete_file(const DBusString *filename, DBusError *error)
Deletes the given file.
void _dbus_transport_unref(DBusTransport *transport)
Decrements the reference count for the transport.
int _dbus_listen_tcp_socket(const char *host, const char *port, const char *family, DBusString *retport, int **fds_p, DBusError *error)
Creates a socket and binds it to the given path, then listens on the socket.
DBusWatch ** watch
File descriptor watch.