summaryrefslogtreecommitdiff
path: root/dbus
diff options
context:
space:
mode:
authorHavoc Pennington <hp@redhat.com>2003-03-31 08:19:50 +0000
committerHavoc Pennington <hp@redhat.com>2003-03-31 08:19:50 +0000
commit29c71168cd17b11eed65023c97aff401d5305b01 (patch)
tree431a05106d857cf38abbdea74a375326f395485e /dbus
parentbc86794f23fa538a405813fb61b531c2eacc9ae1 (diff)
downloaddbus-29c71168cd17b11eed65023c97aff401d5305b01.tar.gz
2003-03-31 Havoc Pennington <hp@pobox.com>
* dbus/dbus-transport-unix.c (_dbus_transport_new_for_domain_socket) (_dbus_transport_new_for_tcp_socket): these didn't need the "server" argument since they are always client side * dbus/dbus-server.c (dbus_server_get_address): new function * bus/main.c (main): take the configuration file as an argument. * test/data/valid-config-files/debug-allow-all.conf: new file to use with dispatch.c tests for example * bus/test-main.c (main): require test data dir * bus/bus.c (bus_context_new): change this to take a configuration file name as argument * doc/config-file.txt (Elements): add <servicedir> * bus/system.conf, bus/session.conf: new files * dbus/dbus-bus.c (dbus_bus_get): look for system bus on well-known socket if none set * configure.in: create system.conf and session.conf
Diffstat (limited to 'dbus')
-rw-r--r--dbus/Makefile.am3
-rw-r--r--dbus/dbus-bus.c12
-rw-r--r--dbus/dbus-server-debug-pipe.c87
-rw-r--r--dbus/dbus-server-debug.c52
-rw-r--r--dbus/dbus-server-protected.h5
-rw-r--r--dbus/dbus-server-unix.c64
-rw-r--r--dbus/dbus-server-unix.h14
-rw-r--r--dbus/dbus-server.c68
-rw-r--r--dbus/dbus-server.h1
-rw-r--r--dbus/dbus-transport-debug.c25
-rw-r--r--dbus/dbus-transport-protected.h5
-rw-r--r--dbus/dbus-transport-unix.c64
-rw-r--r--dbus/dbus-transport-unix.h18
-rw-r--r--dbus/dbus-transport.c47
-rw-r--r--dbus/dbus-transport.h1
15 files changed, 343 insertions, 123 deletions
diff --git a/dbus/Makefile.am b/dbus/Makefile.am
index 20be7919..475f0cb7 100644
--- a/dbus/Makefile.am
+++ b/dbus/Makefile.am
@@ -1,5 +1,6 @@
-INCLUDES=-I$(top_srcdir) $(DBUS_CLIENT_CFLAGS) -DDBUS_COMPILATION
+INCLUDES=-I$(top_srcdir) $(DBUS_CLIENT_CFLAGS) -DDBUS_COMPILATION \
+ -DDBUS_SYSTEM_BUS_PATH=\""$(localstatedir)/@DBUS_SYSTEM_SOCKET@"\"
dbusincludedir=$(includedir)/dbus-1.0/dbus
diff --git a/dbus/dbus-bus.c b/dbus/dbus-bus.c
index c3978db2..22af3dab 100644
--- a/dbus/dbus-bus.c
+++ b/dbus/dbus-bus.c
@@ -221,10 +221,18 @@ dbus_bus_get (DBusBusType type,
value = _dbus_getenv (name);
- if (!value)
+ if (type == DBUS_BUS_SYSTEM &&
+ (value == NULL || *value == '\0'))
+ {
+ /* Use default system bus address if none set */
+ value = "unix:path=" DBUS_SYSTEM_BUS_PATH;
+ }
+
+ if (value == NULL || *value == '\0')
{
dbus_set_error (error, DBUS_ERROR_FAILED,
- "Could not get bus daemon address.");
+ "Environment variable %s not set, address of message bus unknown",
+ name);
_DBUS_UNLOCK (bus);
return NULL;
diff --git a/dbus/dbus-server-debug-pipe.c b/dbus/dbus-server-debug-pipe.c
index c6dc9f70..ed65298b 100644
--- a/dbus/dbus-server-debug-pipe.c
+++ b/dbus/dbus-server-debug-pipe.c
@@ -141,7 +141,8 @@ _dbus_server_debug_pipe_new (const char *server_name,
DBusError *error)
{
DBusServerDebugPipe *debug_server;
-
+ DBusString address;
+
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
if (!pipe_hash_ref ())
@@ -155,52 +156,47 @@ _dbus_server_debug_pipe_new (const char *server_name,
}
debug_server = dbus_new0 (DBusServerDebugPipe, 1);
-
if (debug_server == NULL)
- {
- pipe_hash_unref ();
- return NULL;
- }
+ goto nomem_0;
+
+ if (!_dbus_string_init (&address, _DBUS_INT_MAX))
+ goto nomem_1;
+ if (!_dbus_string_append (&address, "debug-pipe:name=") ||
+ !_dbus_string_append (&address, server_name))
+ goto nomem_2;
+
debug_server->name = _dbus_strdup (server_name);
if (debug_server->name == NULL)
- {
- dbus_free (debug_server->name);
- dbus_free (debug_server);
-
- dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
-
- pipe_hash_unref ();
- return NULL;
- }
+ goto nomem_2;
if (!_dbus_server_init_base (&debug_server->base,
- &debug_vtable))
- {
- dbus_free (debug_server->name);
- dbus_free (debug_server);
-
- dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
-
- pipe_hash_unref ();
- return NULL;
- }
+ &debug_vtable, &address))
+ goto nomem_3;
if (!_dbus_hash_table_insert_string (server_pipe_hash,
debug_server->name,
debug_server))
- {
- _dbus_server_finalize_base (&debug_server->base);
- dbus_free (debug_server->name);
- dbus_free (debug_server);
+ goto nomem_4;
- dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
+ _dbus_string_free (&address);
- pipe_hash_unref ();
- return NULL;
- }
+ /* server keeps the pipe hash ref */
return (DBusServer *)debug_server;
+
+ nomem_4:
+ _dbus_server_finalize_base (&debug_server->base);
+ nomem_3:
+ dbus_free (debug_server->name);
+ nomem_2:
+ _dbus_string_free (&address);
+ nomem_1:
+ dbus_free (debug_server);
+ nomem_0:
+ pipe_hash_unref ();
+ dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
+ return NULL;
}
/**
@@ -221,7 +217,8 @@ _dbus_transport_debug_pipe_new (const char *server_name,
DBusConnection *connection;
int client_fd, server_fd;
DBusServer *server;
-
+ DBusString address;
+
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
server = _dbus_hash_table_lookup_string (server_pipe_hash,
@@ -232,12 +229,27 @@ _dbus_transport_debug_pipe_new (const char *server_name,
dbus_set_error (error, DBUS_ERROR_BAD_ADDRESS, NULL);
return NULL;
}
+
+ if (!_dbus_string_init (&address, _DBUS_INT_MAX))
+ {
+ dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
+ return NULL;
+ }
+
+ if (!_dbus_string_append (&address, "debug-pipe:name=") ||
+ !_dbus_string_append (&address, server_name))
+ {
+ dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
+ _dbus_string_free (&address);
+ return NULL;
+ }
if (!_dbus_full_duplex_pipe (&client_fd, &server_fd,
NULL))
{
_dbus_verbose ("failed to create full duplex pipe\n");
dbus_set_error (error, DBUS_ERROR_FAILED, "Could not create full-duplex pipe");
+ _dbus_string_free (&address);
return NULL;
}
@@ -245,19 +257,22 @@ _dbus_transport_debug_pipe_new (const char *server_name,
_dbus_fd_set_close_on_exec (server_fd);
client_transport = _dbus_transport_new_for_fd (client_fd,
- FALSE);
+ FALSE, &address);
if (client_transport == NULL)
{
_dbus_close (client_fd, NULL);
_dbus_close (server_fd, NULL);
dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
+ _dbus_string_free (&address);
return NULL;
}
+ _dbus_string_free (&address);
+
client_fd = -1;
server_transport = _dbus_transport_new_for_fd (server_fd,
- TRUE);
+ TRUE, NULL);
if (server_transport == NULL)
{
_dbus_transport_unref (client_transport);
diff --git a/dbus/dbus-server-debug.c b/dbus/dbus-server-debug.c
index 7af2336b..e61f8099 100644
--- a/dbus/dbus-server-debug.c
+++ b/dbus/dbus-server-debug.c
@@ -117,7 +117,8 @@ _dbus_server_debug_new (const char *server_name,
DBusError *error)
{
DBusServerDebug *debug_server;
-
+ DBusString address;
+
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
if (!server_hash)
@@ -143,40 +144,43 @@ _dbus_server_debug_new (const char *server_name,
if (debug_server == NULL)
return NULL;
+ if (!_dbus_string_init (&address, _DBUS_INT_MAX))
+ goto nomem_0;
+
+ if (!_dbus_string_append (&address, "debug:name=") ||
+ !_dbus_string_append (&address, server_name))
+ goto nomem_1;
+
debug_server->name = _dbus_strdup (server_name);
if (debug_server->name == NULL)
- {
- dbus_free (debug_server->name);
- dbus_free (debug_server);
-
- dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
- }
+ goto nomem_1;
if (!_dbus_server_init_base (&debug_server->base,
- &debug_vtable))
- {
- dbus_free (debug_server->name);
- dbus_free (debug_server);
-
- dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
-
- return NULL;
- }
+ &debug_vtable,
+ &address))
+ goto nomem_2;
if (!_dbus_hash_table_insert_string (server_hash,
debug_server->name,
debug_server))
- {
- _dbus_server_finalize_base (&debug_server->base);
- dbus_free (debug_server->name);
- dbus_free (debug_server);
+ goto nomem_3;
- dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
-
- return NULL;
- }
+ _dbus_string_free (&address);
return (DBusServer *)debug_server;
+
+ nomem_3:
+ _dbus_server_finalize_base (&debug_server->base);
+ nomem_2:
+ dbus_free (debug_server->name);
+ nomem_1:
+ _dbus_string_free (&address);
+ nomem_0:
+ dbus_free (debug_server);
+
+ dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
+
+ return NULL;
}
typedef struct
diff --git a/dbus/dbus-server-protected.h b/dbus/dbus-server-protected.h
index d47215b7..475bf3a2 100644
--- a/dbus/dbus-server-protected.h
+++ b/dbus/dbus-server-protected.h
@@ -61,6 +61,8 @@ struct DBusServer
* to this server
*/
+ char *address; /**< Address this server is listening on. */
+
int max_connections; /**< Max number of connections allowed at once. */
DBusDataSlotList slot_list; /**< Data stored by allocated integer ID */
@@ -78,7 +80,8 @@ struct DBusServer
};
dbus_bool_t _dbus_server_init_base (DBusServer *server,
- const DBusServerVTable *vtable);
+ const DBusServerVTable *vtable,
+ const DBusString *address);
void _dbus_server_finalize_base (DBusServer *server);
dbus_bool_t _dbus_server_add_watch (DBusServer *server,
DBusWatch *watch);
diff --git a/dbus/dbus-server-unix.c b/dbus/dbus-server-unix.c
index 41553fe2..ee26b243 100644
--- a/dbus/dbus-server-unix.c
+++ b/dbus/dbus-server-unix.c
@@ -83,7 +83,7 @@ handle_new_client_fd (DBusServer *server,
if (!_dbus_set_fd_nonblocking (client_fd, NULL))
return TRUE;
- transport = _dbus_transport_new_for_fd (client_fd, TRUE);
+ transport = _dbus_transport_new_for_fd (client_fd, TRUE, NULL);
if (transport == NULL)
{
close (client_fd);
@@ -201,11 +201,13 @@ static DBusServerVTable unix_vtable = {
* accept new client connections.
*
* @param fd the file descriptor.
+ * @param address the server's address
* @returns the new server, or #NULL if no memory.
*
*/
DBusServer*
-_dbus_server_new_for_fd (int fd)
+_dbus_server_new_for_fd (int fd,
+ const DBusString *address)
{
DBusServerUnix *unix_server;
DBusWatch *watch;
@@ -224,7 +226,7 @@ _dbus_server_new_for_fd (int fd)
}
if (!_dbus_server_init_base (&unix_server->base,
- &unix_vtable))
+ &unix_vtable, address))
{
_dbus_watch_unref (watch);
dbus_free (unix_server);
@@ -259,23 +261,44 @@ _dbus_server_new_for_domain_socket (const char *path,
{
DBusServer *server;
int listen_fd;
-
+ DBusString address;
+
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
+
+ if (!_dbus_string_init (&address, _DBUS_INT_MAX))
+ {
+ dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
+ return NULL;
+ }
+
+ if (!_dbus_string_append (&address, "unix:path=") ||
+ !_dbus_string_append (&address, path))
+ {
+ _dbus_string_free (&address);
+ dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
+ return NULL;
+ }
listen_fd = _dbus_listen_unix_socket (path, error);
_dbus_fd_set_close_on_exec (listen_fd);
if (listen_fd < 0)
- return NULL;
+ {
+ _dbus_string_free (&address);
+ return NULL;
+ }
- server = _dbus_server_new_for_fd (listen_fd);
+ server = _dbus_server_new_for_fd (listen_fd, &address);
if (server == NULL)
{
dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
close (listen_fd);
+ _dbus_string_free (&address);
return NULL;
}
+ _dbus_string_free (&address);
+
return server;
}
@@ -295,23 +318,46 @@ _dbus_server_new_for_tcp_socket (const char *host,
{
DBusServer *server;
int listen_fd;
-
+ DBusString address;
+
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
+
+ if (!_dbus_string_init (&address, _DBUS_INT_MAX))
+ {
+ dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
+ return NULL;
+ }
+
+ if (!_dbus_string_append (&address, "tcp:host=") ||
+ !_dbus_string_append (&address, host) ||
+ !_dbus_string_append (&address, ",port=") ||
+ !_dbus_string_append_int (&address, port))
+ {
+ _dbus_string_free (&address);
+ dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
+ return NULL;
+ }
listen_fd = _dbus_listen_tcp_socket (host, port, error);
_dbus_fd_set_close_on_exec (listen_fd);
if (listen_fd < 0)
- return NULL;
+ {
+ _dbus_string_free (&address);
+ return NULL;
+ }
- server = _dbus_server_new_for_fd (listen_fd);
+ server = _dbus_server_new_for_fd (listen_fd, &address);
if (server == NULL)
{
dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
close (listen_fd);
+ _dbus_string_free (&address);
return NULL;
}
+ _dbus_string_free (&address);
+
return server;
diff --git a/dbus/dbus-server-unix.h b/dbus/dbus-server-unix.h
index 947425b1..1d038db0 100644
--- a/dbus/dbus-server-unix.h
+++ b/dbus/dbus-server-unix.h
@@ -28,12 +28,14 @@
DBUS_BEGIN_DECLS;
-DBusServer* _dbus_server_new_for_fd (int fd);
-DBusServer* _dbus_server_new_for_domain_socket (const char *path,
- DBusError *error);
-DBusServer* _dbus_server_new_for_tcp_socket (const char *host,
- dbus_uint32_t port,
- DBusError *error);
+DBusServer* _dbus_server_new_for_fd (int fd,
+ const DBusString *address);
+DBusServer* _dbus_server_new_for_domain_socket (const char *path,
+ DBusError *error);
+DBusServer* _dbus_server_new_for_tcp_socket (const char *host,
+ dbus_uint32_t port,
+ DBusError *error);
+
DBUS_END_DECLS;
diff --git a/dbus/dbus-server.c b/dbus/dbus-server.c
index 6b9f17e8..9f70649b 100644
--- a/dbus/dbus-server.c
+++ b/dbus/dbus-server.c
@@ -57,43 +57,68 @@
*
* @param server the server.
* @param vtable the vtable for the subclass.
+ * @param address the server's address
* @returns #TRUE on success.
*/
dbus_bool_t
_dbus_server_init_base (DBusServer *server,
- const DBusServerVTable *vtable)
+ const DBusServerVTable *vtable,
+ const DBusString *address)
{
server->vtable = vtable;
server->refcount = 1;
+ server->address = NULL;
+ server->watches = NULL;
+ server->timeouts = NULL;
+ server->connection_counter = NULL;
+
+ if (!_dbus_string_copy_data (address, &server->address))
+ goto failed;
+
server->watches = _dbus_watch_list_new ();
if (server->watches == NULL)
- return FALSE;
+ goto failed;
server->timeouts = _dbus_timeout_list_new ();
if (server->timeouts == NULL)
- {
- _dbus_watch_list_free (server->watches);
- server->watches = NULL;
- return FALSE;
- }
+ goto failed;
server->connection_counter = _dbus_counter_new ();
if (server->connection_counter == NULL)
+ goto failed;
+
+ server->max_connections = 256; /* same as an X server, seems like a nice default */
+
+ _dbus_data_slot_list_init (&server->slot_list);
+
+ _dbus_verbose ("Initialized server on address %s\n", server->address);
+
+ return TRUE;
+
+ failed:
+ if (server->watches)
{
_dbus_watch_list_free (server->watches);
server->watches = NULL;
+ }
+ if (server->timeouts)
+ {
_dbus_timeout_list_free (server->timeouts);
server->timeouts = NULL;
-
- return FALSE;
}
-
- server->max_connections = 256; /* same as an X server, seems like a nice default */
-
- _dbus_data_slot_list_init (&server->slot_list);
+ if (server->connection_counter)
+ {
+ _dbus_counter_unref (server->connection_counter);
+ server->connection_counter = NULL;
+ }
+ if (server->address)
+ {
+ dbus_free (server->address);
+ server->address = NULL;
+ }
- return TRUE;
+ return FALSE;
}
/**
@@ -116,6 +141,8 @@ _dbus_server_finalize_base (DBusServer *server)
_dbus_watch_list_free (server->watches);
_dbus_timeout_list_free (server->timeouts);
_dbus_counter_unref (server->connection_counter);
+
+ dbus_free (server->address);
}
/**
@@ -445,6 +472,19 @@ dbus_server_get_is_connected (DBusServer *server)
}
/**
+ * Returns the address of the server, as a newly-allocated
+ * string which must be freed by the caller.
+ *
+ * @param server the server
+ * @returns the address or #NULL if no memory
+ */
+char*
+dbus_server_get_address (DBusServer *server)
+{
+ return _dbus_strdup (server->address);
+}
+
+/**
* Sets a function to be used for handling new connections. The given
* function is passed each new connection as the connection is
* created. If the new connection function increments the connection's
diff --git a/dbus/dbus-server.h b/dbus/dbus-server.h
index fcfc6e70..e36ed86e 100644
--- a/dbus/dbus-server.h
+++ b/dbus/dbus-server.h
@@ -45,6 +45,7 @@ void dbus_server_ref (DBusServer *server);
void dbus_server_unref (DBusServer *server);
void dbus_server_disconnect (DBusServer *server);
dbus_bool_t dbus_server_get_is_connected (DBusServer *server);
+char* dbus_server_get_address (DBusServer *server);
void dbus_server_set_new_connection_function (DBusServer *server,
DBusNewConnectionFunction function,
void *data,
diff --git a/dbus/dbus-transport-debug.c b/dbus/dbus-transport-debug.c
index 03b40593..a1b2a64a 100644
--- a/dbus/dbus-transport-debug.c
+++ b/dbus/dbus-transport-debug.c
@@ -277,7 +277,7 @@ _dbus_transport_debug_server_new (DBusTransport *client)
if (!_dbus_transport_init_base (&debug_transport->base,
&debug_vtable,
- TRUE))
+ TRUE, NULL))
{
dbus_free (debug_transport);
return NULL;
@@ -316,7 +316,8 @@ _dbus_transport_debug_client_new (const char *server_name,
{
DBusServer *debug_server;
DBusTransportDebug *debug_transport;
-
+ DBusString address;
+
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
debug_server = _dbus_server_debug_lookup (server_name);
@@ -327,21 +328,39 @@ _dbus_transport_debug_client_new (const char *server_name,
return NULL;
}
+ if (!_dbus_string_init (&address, _DBUS_INT_MAX))
+ {
+ dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
+ return NULL;
+ }
+
+ if (!_dbus_string_append (&address, "debug-pipe:name=") ||
+ !_dbus_string_append (&address, server_name))
+ {
+ dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
+ _dbus_string_free (&address);
+ return NULL;
+ }
+
debug_transport = dbus_new0 (DBusTransportDebug, 1);
if (debug_transport == NULL)
{
dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
+ _dbus_string_free (&address);
return NULL;
}
if (!_dbus_transport_init_base (&debug_transport->base,
&debug_vtable,
- FALSE))
+ FALSE, &address))
{
dbus_free (debug_transport);
dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
+ _dbus_string_free (&address);
return NULL;
}
+
+ _dbus_string_free (&address);
if (!create_timeout_object (debug_transport))
{
diff --git a/dbus/dbus-transport-protected.h b/dbus/dbus-transport-protected.h
index 31668389..052c15fa 100644
--- a/dbus/dbus-transport-protected.h
+++ b/dbus/dbus-transport-protected.h
@@ -88,6 +88,8 @@ struct DBusTransport
DBusCounter *live_messages_size; /**< Counter for size of all live messages. */
+ char *address; /**< Address of this server */
+
DBusAllowUnixUserFunction unix_user_function; /**< Function for checking whether a user is authorized. */
void *unix_user_data; /**< Data for unix_user_function */
DBusFreeFunction free_unix_user_data; /**< Function to free unix_user_data */
@@ -102,7 +104,8 @@ struct DBusTransport
dbus_bool_t _dbus_transport_init_base (DBusTransport *transport,
const DBusTransportVTable *vtable,
- dbus_bool_t server);
+ dbus_bool_t server,
+ const DBusString *address);
void _dbus_transport_finalize_base (DBusTransport *transport);
diff --git a/dbus/dbus-transport-unix.c b/dbus/dbus-transport-unix.c
index d34565eb..81672de5 100644
--- a/dbus/dbus-transport-unix.c
+++ b/dbus/dbus-transport-unix.c
@@ -963,11 +963,13 @@ static DBusTransportVTable unix_vtable = {
*
* @param fd the file descriptor.
* @param server #TRUE if this transport is on the server side of a connection
+ * @param address the transport's address
* @returns the new transport, or #NULL if no memory.
*/
DBusTransport*
-_dbus_transport_new_for_fd (int fd,
- dbus_bool_t server)
+_dbus_transport_new_for_fd (int fd,
+ dbus_bool_t server,
+ const DBusString *address)
{
DBusTransportUnix *unix_transport;
@@ -997,7 +999,7 @@ _dbus_transport_new_for_fd (int fd,
if (!_dbus_transport_init_base (&unix_transport->base,
&unix_vtable,
- server))
+ server, address))
goto failed_4;
unix_transport->fd = fd;
@@ -1024,27 +1026,41 @@ _dbus_transport_new_for_fd (int fd,
/**
* Creates a new transport for the given Unix domain socket
- * path.
+ * path. This creates a client-side of a transport.
*
* @param path the path to the domain socket.
- * @param server #TRUE if this transport is on the server side of a connection
* @param error address where an error can be returned.
* @returns a new transport, or #NULL on failure.
*/
DBusTransport*
_dbus_transport_new_for_domain_socket (const char *path,
- dbus_bool_t server,
DBusError *error)
{
int fd;
DBusTransport *transport;
-
+ DBusString address;
+
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
+
+ if (!_dbus_string_init (&address, _DBUS_INT_MAX))
+ {
+ dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
+ return NULL;
+ }
+
+ if (!_dbus_string_append (&address, "unix:path=") ||
+ !_dbus_string_append (&address, path))
+ {
+ _dbus_string_free (&address);
+ dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
+ return NULL;
+ }
fd = _dbus_connect_unix_socket (path, error);
if (fd < 0)
{
_DBUS_ASSERT_ERROR_IS_SET (error);
+ _dbus_string_free (&address);
return NULL;
}
@@ -1052,14 +1068,17 @@ _dbus_transport_new_for_domain_socket (const char *path,
_dbus_verbose ("Successfully connected to unix socket %s\n",
path);
-
- transport = _dbus_transport_new_for_fd (fd, server);
+
+ transport = _dbus_transport_new_for_fd (fd, FALSE, &address);
if (transport == NULL)
{
dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
+ _dbus_string_free (&address);
_dbus_close (fd, NULL);
fd = -1;
}
+
+ _dbus_string_free (&address);
return transport;
}
@@ -1069,25 +1088,41 @@ _dbus_transport_new_for_domain_socket (const char *path,
*
* @param host the host to connect to
* @param port the port to connect to
- * @param server #TRUE if this transport is on the server side of a connection
* @param error location to store reason for failure.
* @returns a new transport, or #NULL on failure.
*/
DBusTransport*
_dbus_transport_new_for_tcp_socket (const char *host,
dbus_int32_t port,
- dbus_bool_t server,
DBusError *error)
{
int fd;
DBusTransport *transport;
-
+ DBusString address;
+
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
+
+ if (!_dbus_string_init (&address, _DBUS_INT_MAX))
+ {
+ dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
+ return NULL;
+ }
+
+ if (!_dbus_string_append (&address, "tcp:host=") ||
+ !_dbus_string_append (&address, host) ||
+ !_dbus_string_append (&address, ",port=") ||
+ !_dbus_string_append_int (&address, port))
+ {
+ _dbus_string_free (&address);
+ dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
+ return NULL;
+ }
fd = _dbus_connect_tcp_socket (host, port, error);
if (fd < 0)
{
_DBUS_ASSERT_ERROR_IS_SET (error);
+ _dbus_string_free (&address);
return NULL;
}
@@ -1096,14 +1131,17 @@ _dbus_transport_new_for_tcp_socket (const char *host,
_dbus_verbose ("Successfully connected to tcp socket %s:%d\n",
host, port);
- transport = _dbus_transport_new_for_fd (fd, server);
+ transport = _dbus_transport_new_for_fd (fd, FALSE, &address);
if (transport == NULL)
{
dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
_dbus_close (fd, NULL);
+ _dbus_string_free (&address);
fd = -1;
}
+ _dbus_string_free (&address);
+
return transport;
}
diff --git a/dbus/dbus-transport-unix.h b/dbus/dbus-transport-unix.h
index 595fbc18..ef7ac9b1 100644
--- a/dbus/dbus-transport-unix.h
+++ b/dbus/dbus-transport-unix.h
@@ -27,15 +27,15 @@
DBUS_BEGIN_DECLS;
-DBusTransport* _dbus_transport_new_for_fd (int fd,
- dbus_bool_t server);
-DBusTransport* _dbus_transport_new_for_domain_socket (const char *path,
- dbus_bool_t server,
- DBusError *error);
-DBusTransport* _dbus_transport_new_for_tcp_socket (const char *host,
- dbus_int32_t port,
- dbus_bool_t server,
- DBusError *error);
+DBusTransport* _dbus_transport_new_for_fd (int fd,
+ dbus_bool_t server,
+ const DBusString *address);
+DBusTransport* _dbus_transport_new_for_domain_socket (const char *path,
+ DBusError *error);
+DBusTransport* _dbus_transport_new_for_tcp_socket (const char *host,
+ dbus_int32_t port,
+ DBusError *error);
+
DBUS_END_DECLS;
diff --git a/dbus/dbus-transport.c b/dbus/dbus-transport.c
index 41466ec9..a7aecc3f 100644
--- a/dbus/dbus-transport.c
+++ b/dbus/dbus-transport.c
@@ -82,16 +82,19 @@ live_messages_size_notify (DBusCounter *counter,
* @param transport the transport being created.
* @param vtable the subclass vtable.
* @param server #TRUE if this transport is on the server side of a connection
+ * @param address the address of the transport
* @returns #TRUE on success.
*/
dbus_bool_t
_dbus_transport_init_base (DBusTransport *transport,
const DBusTransportVTable *vtable,
- dbus_bool_t server)
+ dbus_bool_t server,
+ const DBusString *address)
{
DBusMessageLoader *loader;
DBusAuth *auth;
DBusCounter *counter;
+ char *address_copy;
loader = _dbus_message_loader_new ();
if (loader == NULL)
@@ -113,6 +116,24 @@ _dbus_transport_init_base (DBusTransport *transport,
_dbus_auth_unref (auth);
_dbus_message_loader_unref (loader);
return FALSE;
+ }
+
+ if (server)
+ {
+ _dbus_assert (address == NULL);
+ address_copy = NULL;
+ }
+ else
+ {
+ _dbus_assert (address != NULL);
+
+ if (!_dbus_string_copy_data (address, &address_copy))
+ {
+ _dbus_counter_unref (counter);
+ _dbus_auth_unref (auth);
+ _dbus_message_loader_unref (loader);
+ return FALSE;
+ }
}
transport->refcount = 1;
@@ -126,7 +147,8 @@ _dbus_transport_init_base (DBusTransport *transport,
transport->send_credentials_pending = !server;
transport->receive_credentials_pending = server;
transport->is_server = server;
-
+ transport->address = address_copy;
+
transport->unix_user_function = NULL;
transport->unix_user_data = NULL;
transport->free_unix_user_data = NULL;
@@ -144,6 +166,9 @@ _dbus_transport_init_base (DBusTransport *transport,
transport->max_live_messages_size,
live_messages_size_notify,
transport);
+
+ if (transport->address)
+ _dbus_verbose ("Initialized transport on address %s\n", transport->address);
return TRUE;
}
@@ -168,6 +193,7 @@ _dbus_transport_finalize_base (DBusTransport *transport)
_dbus_counter_set_notify (transport->live_messages_size,
0, NULL, NULL);
_dbus_counter_unref (transport->live_messages_size);
+ dbus_free (transport->address);
}
/**
@@ -217,7 +243,7 @@ _dbus_transport_open (const char *address,
goto bad_address;
}
- transport = _dbus_transport_new_for_domain_socket (path, FALSE, error);
+ transport = _dbus_transport_new_for_domain_socket (path, error);
}
else if (strcmp (method, "tcp") == 0)
{
@@ -244,7 +270,7 @@ _dbus_transport_open (const char *address,
goto bad_address;
}
- transport = _dbus_transport_new_for_tcp_socket (host, lport, FALSE, error);
+ transport = _dbus_transport_new_for_tcp_socket (host, lport, error);
}
#ifdef DBUS_BUILD_TESTS
else if (strcmp (method, "debug") == 0)
@@ -461,6 +487,19 @@ _dbus_transport_get_is_authenticated (DBusTransport *transport)
}
/**
+ * Gets the address of a transport. It will be
+ * #NULL for a server-side transport.
+ *
+ * @param transport the transport
+ * @returns transport's address
+ */
+const char*
+_dbus_transport_get_address (DBusTransport *transport)
+{
+ return transport->address;
+}
+
+/**
* Handles a watch by reading data, writing data, or disconnecting
* the transport, as appropriate for the given condition.
*
diff --git a/dbus/dbus-transport.h b/dbus/dbus-transport.h
index d129ccef..128f0fe3 100644
--- a/dbus/dbus-transport.h
+++ b/dbus/dbus-transport.h
@@ -37,6 +37,7 @@ void _dbus_transport_unref (DBusTransport
void _dbus_transport_disconnect (DBusTransport *transport);
dbus_bool_t _dbus_transport_get_is_connected (DBusTransport *transport);
dbus_bool_t _dbus_transport_get_is_authenticated (DBusTransport *transport);
+const char* _dbus_transport_get_address (DBusTransport *transport);
dbus_bool_t _dbus_transport_handle_watch (DBusTransport *transport,
DBusWatch *watch,
unsigned int condition);