26#include "dbus-internals.h"
27#include "dbus-server-debug-pipe.h"
28#include "dbus-transport-socket.h"
29#include "dbus-connection-internal.h"
31#include "dbus-string.h"
32#include "dbus-protocol.h"
34#ifdef DBUS_ENABLE_EMBEDDED_TESTS
50typedef struct DBusServerDebugPipe DBusServerDebugPipe;
56struct DBusServerDebugPipe
67static int server_pipe_hash_refcount = 0;
72 if (!server_pipe_hash)
78 if (!server_pipe_hash)
82 server_pipe_hash_refcount = 1;
93 server_pipe_hash_refcount -= 1;
94 if (server_pipe_hash_refcount == 0)
97 server_pipe_hash =
NULL;
104 DBusServerDebugPipe *debug_server = (DBusServerDebugPipe*) server;
117 ((DBusServerDebugPipe*)server)->disconnected =
TRUE;
133_dbus_server_debug_pipe_new (
const char *server_name,
136 DBusServerDebugPipe *debug_server;
140 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
142 if (!pipe_hash_ref ())
152 debug_server =
dbus_new0 (DBusServerDebugPipe, 1);
153 if (debug_server ==
NULL)
165 if (debug_server->name ==
NULL)
169 &debug_vtable, &address,
182 _dbus_server_trace_ref (&debug_server->base, 0, 1,
"debug_pipe_new");
196 _DBUS_SET_OOM (error);
210_dbus_transport_debug_pipe_new (
const char *server_name,
220 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
222 if (server_pipe_hash ==
NULL)
230 if (server ==
NULL ||
231 ((DBusServerDebugPipe*)server)->disconnected)
253 _dbus_verbose (
"failed to create full duplex pipe\n");
261 if (client_transport ==
NULL)
272 _dbus_socket_invalidate (&client_fd);
275 &server->guid_hex,
NULL);
276 if (server_transport ==
NULL)
284 _dbus_socket_invalidate (&server_fd);
287 (
const char**) server->auth_mechanisms))
297 server_transport =
NULL;
299 if (connection ==
NULL)
309 if (server->new_connection_function)
312 (* server->new_connection_function) (server, connection,
313 server->new_connection_data);
323 return client_transport;
337DBusServerListenResult
348 if (strcmp (method,
"debug-pipe") == 0)
356 return DBUS_SERVER_LISTEN_BAD_ADDRESS;
359 *server_p = _dbus_server_debug_pipe_new (name, error);
363 _DBUS_ASSERT_ERROR_IS_CLEAR(error);
364 return DBUS_SERVER_LISTEN_OK;
368 _DBUS_ASSERT_ERROR_IS_SET(error);
369 return DBUS_SERVER_LISTEN_DID_NOT_CONNECT;
374 _DBUS_ASSERT_ERROR_IS_CLEAR(error);
375 return DBUS_SERVER_LISTEN_NOT_HANDLED;
387DBusTransportOpenResult
397 if (strcmp (method,
"debug-pipe") == 0)
405 return DBUS_TRANSPORT_OPEN_BAD_ADDRESS;
408 *transport_p = _dbus_transport_debug_pipe_new (name, error);
410 if (*transport_p ==
NULL)
412 _DBUS_ASSERT_ERROR_IS_SET (error);
413 return DBUS_TRANSPORT_OPEN_DID_NOT_CONNECT;
417 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
418 return DBUS_TRANSPORT_OPEN_OK;
423 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
424 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_I...
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.
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.
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.