26 #include "dbus-internals.h"
27 #include "dbus-server-debug-pipe.h"
28 #include "dbus-transport-socket.h"
29 #include "dbus-connection-internal.h"
30 #include "dbus-hash.h"
31 #include "dbus-string.h"
32 #include "dbus-protocol.h"
34 #ifdef DBUS_BUILD_TESTS
50 typedef struct DBusServerDebugPipe DBusServerDebugPipe;
56 struct DBusServerDebugPipe
67 static int server_pipe_hash_refcount = 0;
72 if (!server_pipe_hash)
78 if (!server_pipe_hash)
82 server_pipe_hash_refcount = 1;
88 pipe_hash_unref (
void)
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))
181 _dbus_server_trace_ref (&debug_server->base, 0, 1,
"debug_pipe_new");
208 _dbus_transport_debug_pipe_new (
const char *server_name,
214 int client_fd, server_fd;
218 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
220 if (server_pipe_hash ==
NULL)
228 if (server ==
NULL ||
229 ((DBusServerDebugPipe*)server)->disconnected)
252 _dbus_verbose (
"failed to create full duplex pipe\n");
260 if (client_transport ==
NULL)
275 if (server_transport ==
NULL)
296 server_transport =
NULL;
298 if (connection ==
NULL)
322 return client_transport;
336 DBusServerListenResult
347 if (strcmp (method,
"debug-pipe") == 0)
355 return DBUS_SERVER_LISTEN_BAD_ADDRESS;
358 *server_p = _dbus_server_debug_pipe_new (name, error);
362 _DBUS_ASSERT_ERROR_IS_CLEAR(error);
363 return DBUS_SERVER_LISTEN_OK;
367 _DBUS_ASSERT_ERROR_IS_SET(error);
368 return DBUS_SERVER_LISTEN_DID_NOT_CONNECT;
373 _DBUS_ASSERT_ERROR_IS_CLEAR(error);
374 return DBUS_SERVER_LISTEN_NOT_HANDLED;
386 DBusTransportOpenResult
396 if (strcmp (method,
"debug-pipe") == 0)
404 return DBUS_TRANSPORT_OPEN_BAD_ADDRESS;
407 *transport_p = _dbus_transport_debug_pipe_new (name, error);
409 if (*transport_p ==
NULL)
411 _DBUS_ASSERT_ERROR_IS_SET (error);
412 return DBUS_TRANSPORT_OPEN_DID_NOT_CONNECT;
416 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
417 return DBUS_TRANSPORT_OPEN_OK;
422 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
423 return DBUS_TRANSPORT_OPEN_NOT_HANDLED;
dbus_bool_t _dbus_string_append(DBusString *str, const char *buffer)
Appends a nul-terminated C-style string to a DBusString.
#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().
Internals of DBusServer object.
#define _dbus_assert(condition)
Aborts with an error message if the condition is false.
dbus_bool_t _dbus_full_duplex_pipe(int *fd1, int *fd2, dbus_bool_t blocking, DBusError *error)
Creates a full-duplex pipe (as in socketpair()).
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().
Implementation details of DBusConnection.
dbus_bool_t _dbus_string_init(DBusString *str)
Initializes a string.
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 _dbus_hash_table_unref(DBusHashTable *table)
Decrements the reference count for a hash table, freeing the hash table if the count reaches zero...
DBusNewConnectionFunction new_connection_function
Callback to invoke when a new connection is created.
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.
#define DBUS_ERROR_NO_SERVER
Unable to connect to server (probably caused by ECONNREFUSED on a socket).
const char * dbus_address_entry_get_value(DBusAddressEntry *entry, const char *key)
Returns a value from a key of an entry.
#define dbus_new0(type, count)
Safe macro for using dbus_malloc0().
DBusHashTable * _dbus_hash_table_new(DBusHashType type, DBusFreeFunction key_free_function, DBusFreeFunction value_free_function)
Constructs a new hash table.
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.
DBusServer * dbus_server_ref(DBusServer *server)
Increments the reference count of a DBusServer.
Internals of DBusAddressEntry.
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.
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.
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_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.
#define DBUS_ERROR_ADDRESS_IN_USE
Can't bind a socket since its address is in use (i.e.
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".
#define DBUS_ERROR_FAILED
A generic error; "something went wrong" - see the error message for more.
Object representing a transport such as a socket.
void * new_connection_data
Data for new connection callback.
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".
void dbus_connection_unref(DBusConnection *connection)
Decrements the reference count of a DBusConnection, and finalizes it if the count reaches zero...
Internals of DBusHashTable.
char * _dbus_strdup(const char *str)
Duplicates a string.
dbus_bool_t _dbus_close_socket(int fd, DBusError *error)
Closes a socket.
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.
void _dbus_transport_unref(DBusTransport *transport)
Decrements the reference count for the transport.