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_ENABLE_EMBEDDED_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,
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);
276 if (server_transport ==
NULL)
284 _dbus_socket_invalidate (&server_fd);
297 server_transport =
NULL;
299 if (connection ==
NULL)
323 return client_transport;
337 DBusServerListenResult
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;
387 DBusTransportOpenResult
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_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().
dbus_bool_t _dbus_socketpair(DBusSocket *fd1, DBusSocket *fd2, dbus_bool_t blocking, DBusError *error)
Creates pair of connect sockets (as in socketpair()).
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_hash_table_unref(DBusHashTable *table)
Decrements the reference count for a hash table, freeing the hash table if the count reaches zero...
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.
DBusNewConnectionFunction new_connection_function
Callback to invoke when a new connection is created.
dbus_bool_t _dbus_close_socket(DBusSocket fd, DBusError *error)
Closes a socket.
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.
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.
#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.
DBusServer * dbus_server_ref(DBusServer *server)
Increments the reference count of a DBusServer.
dbus_bool_t _dbus_hash_table_insert_string(DBusHashTable *table, char *key, void *value)
Creates a hash entry with the given key and value.
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...
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.
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_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.
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_error_is_set(const DBusError *error)
Checks whether an error occurred (the error is set).
DBusHashTable * _dbus_hash_table_new(DBusHashType type, DBusFreeFunction key_free_function, DBusFreeFunction value_free_function)
Constructs a new hash table.
void _dbus_transport_unref(DBusTransport *transport)
Decrements the reference count for the transport.