28#include "dbus-internals.h"
29#include "dbus-server-debug-pipe.h"
30#include "dbus-transport-socket.h"
31#include "dbus-connection-internal.h"
33#include "dbus-string.h"
34#include "dbus-protocol.h"
36#ifdef DBUS_ENABLE_EMBEDDED_TESTS
52typedef struct DBusServerDebugPipe DBusServerDebugPipe;
58struct DBusServerDebugPipe
64 dbus_bool_t disconnected;
69static int server_pipe_hash_refcount = 0;
74 if (!server_pipe_hash)
80 if (!server_pipe_hash)
84 server_pipe_hash_refcount = 1;
95 server_pipe_hash_refcount -= 1;
96 if (server_pipe_hash_refcount == 0)
99 server_pipe_hash =
NULL;
106 DBusServerDebugPipe *debug_server = (DBusServerDebugPipe*) server;
119 ((DBusServerDebugPipe*)server)->disconnected =
TRUE;
135_dbus_server_debug_pipe_new (
const char *server_name,
138 DBusServerDebugPipe *debug_server;
142 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
144 if (!pipe_hash_ref ())
154 debug_server =
dbus_new0 (DBusServerDebugPipe, 1);
155 if (debug_server ==
NULL)
167 if (debug_server->name ==
NULL)
171 &debug_vtable, &address,
184 _dbus_server_trace_ref (&debug_server->base, 0, 1,
"debug_pipe_new");
198 _DBUS_SET_OOM (error);
212_dbus_transport_debug_pipe_new (
const char *server_name,
222 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
224 if (server_pipe_hash ==
NULL)
232 if (server ==
NULL ||
233 ((DBusServerDebugPipe*)server)->disconnected)
255 _dbus_verbose (
"failed to create full duplex pipe\n");
263 if (client_transport ==
NULL)
274 _dbus_socket_invalidate (&client_fd);
277 &server->guid_hex,
NULL);
278 if (server_transport ==
NULL)
286 _dbus_socket_invalidate (&server_fd);
289 (
const char**) server->auth_mechanisms))
299 server_transport =
NULL;
301 if (connection ==
NULL)
311 if (server->new_connection_function)
314 (* server->new_connection_function) (server, connection,
315 server->new_connection_data);
325 return client_transport;
339DBusServerListenResult
350 if (strcmp (method,
"debug-pipe") == 0)
358 return DBUS_SERVER_LISTEN_BAD_ADDRESS;
361 *server_p = _dbus_server_debug_pipe_new (name, error);
365 _DBUS_ASSERT_ERROR_IS_CLEAR(error);
366 return DBUS_SERVER_LISTEN_OK;
370 _DBUS_ASSERT_ERROR_IS_SET(error);
371 return DBUS_SERVER_LISTEN_DID_NOT_CONNECT;
376 _DBUS_ASSERT_ERROR_IS_CLEAR(error);
377 return DBUS_SERVER_LISTEN_NOT_HANDLED;
389DBusTransportOpenResult
399 if (strcmp (method,
"debug-pipe") == 0)
407 return DBUS_TRANSPORT_OPEN_BAD_ADDRESS;
410 *transport_p = _dbus_transport_debug_pipe_new (name, error);
412 if (*transport_p ==
NULL)
414 _DBUS_ASSERT_ERROR_IS_SET (error);
415 return DBUS_TRANSPORT_OPEN_DID_NOT_CONNECT;
419 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
420 return DBUS_TRANSPORT_OPEN_OK;
425 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
426 return DBUS_TRANSPORT_OPEN_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...
void _dbus_set_bad_address(DBusError *error, const char *address_problem_type, const char *address_problem_field, const char *address_problem_other)
Sets DBUS_ERROR_BAD_ADDRESS.
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.
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_hash_table_insert_string(DBusHashTable *table, char *key, void *value)
Creates a hash entry with the given key and value.
void _dbus_hash_table_unref(DBusHashTable *table)
Decrements the reference count for a hash table, freeing the hash table if the count reaches zero.
DBusHashTable * _dbus_hash_table_new(DBusHashType type, DBusFreeFunction key_free_function, DBusFreeFunction value_free_function)
Constructs a new hash table.
void * _dbus_hash_table_lookup_string(DBusHashTable *table, const char *key)
Looks up the value for a given string in a hash table of type DBUS_HASH_STRING.
@ DBUS_HASH_STRING
Hash keys are strings.
#define _dbus_assert(condition)
Aborts with an error message if the condition is false.
char * _dbus_strdup(const char *str)
Duplicates a string.
#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_new0(type, count)
Safe macro for using dbus_malloc0().
#define DBUS_ERROR_ADDRESS_IN_USE
Can't bind a socket since its address is in use (i.e.
#define DBUS_ERROR_NO_SERVER
Unable to connect to server (probably caused by ECONNREFUSED on a socket).
#define DBUS_ERROR_FAILED
A generic error; "something went wrong" - see the error message for more.
#define DBUS_ERROR_NO_MEMORY
There was not enough memory to complete an operation.
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.
void dbus_server_unref(DBusServer *server)
Decrements the reference count of a DBusServer.
DBusServer * dbus_server_ref(DBusServer *server)
Increments the reference count of a DBusServer.
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_IN...
dbus_bool_t _dbus_socketpair(DBusSocket *fd1, DBusSocket *fd2, dbus_bool_t blocking, DBusError *error)
Creates pair of connect sockets (as in socketpair()).
dbus_bool_t _dbus_close_socket(DBusSocket *fd, DBusError *error)
Closes a socket and invalidates it.
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.
Internals of DBusAddressEntry.
Implementation details of DBusConnection.
Object representing an exception.
Internals of DBusHashTable.
Virtual table to be implemented by all server "subclasses".
Internals of DBusServer object.
Object representing a transport such as a socket.