Commit ee27481d authored by Havoc Pennington's avatar Havoc Pennington

2005-02-26 Havoc Pennington <hp@redhat.com>

	* doc/TODO: remove the "guid" item

	* test/glib/test-profile.c (no_bus_thread_func): use open_private
	(with_bus_thread_func): use open_private

	* dbus/dbus-connection.c (dbus_connection_open_private): new
	function that works like the old dbus_connection_open()
	(dbus_connection_open): now returns an existing connection if
	possible

	* dbus/dbus-server-unix.c (handle_new_client_fd_and_unlock): pass
	through the GUID to the transport

	* dbus/dbus-server.c (_dbus_server_init_base): keep around the
	GUID in hex-encoded form.

	* dbus/dbus-server-debug-pipe.c (_dbus_transport_debug_pipe_new):
	pass GUID argument in to the transport

	* dbus/dbus-transport-unix.c (_dbus_transport_new_for_fd): add
	guid argument

	* dbus/dbus-transport.c (_dbus_transport_init_base): add guid argument

	* dbus/dbus-auth.c (_dbus_auth_server_new): add guid argument
parent 7ce7502e
2005-02-26 Havoc Pennington <hp@redhat.com>
* doc/TODO: remove the "guid" item
* test/glib/test-profile.c (no_bus_thread_func): use open_private
(with_bus_thread_func): use open_private
* dbus/dbus-connection.c (dbus_connection_open_private): new
function that works like the old dbus_connection_open()
(dbus_connection_open): now returns an existing connection if
possible
* dbus/dbus-server-unix.c (handle_new_client_fd_and_unlock): pass
through the GUID to the transport
* dbus/dbus-server.c (_dbus_server_init_base): keep around the
GUID in hex-encoded form.
* dbus/dbus-server-debug-pipe.c (_dbus_transport_debug_pipe_new):
pass GUID argument in to the transport
* dbus/dbus-transport-unix.c (_dbus_transport_new_for_fd): add
guid argument
* dbus/dbus-transport.c (_dbus_transport_init_base): add guid argument
* dbus/dbus-auth.c (_dbus_auth_server_new): add guid argument
2005-02-25 Havoc Pennington <hp@redhat.com>
* doc/dbus-specification.xml: document the GUID thing
......
......@@ -231,10 +231,12 @@ _dbus_auth_script_run (const DBusString *filename)
DBusString from_auth;
DBusAuthState state;
DBusString context;
DBusString guid;
retval = FALSE;
auth = NULL;
_dbus_string_init_const (&guid, "5fa01f4202cd837709a3274ca0df9d00");
_dbus_string_init_const (&context, "org_freedesktop_test");
if (!_dbus_string_init (&file))
......@@ -334,7 +336,7 @@ _dbus_auth_script_run (const DBusString *filename)
goto out;
}
auth = _dbus_auth_server_new ();
auth = _dbus_auth_server_new (&guid);
if (auth == NULL)
{
_dbus_warn ("no memory to create DBusAuth\n");
......
......@@ -211,6 +211,8 @@ typedef struct
int failures; /**< Number of times client has been rejected */
int max_failures; /**< Number of times we reject before disconnect */
DBusString guid; /**< Our globally unique ID in hex encoding */
} DBusAuthServer;
......@@ -1923,20 +1925,35 @@ process_command (DBusAuth *auth)
* @returns the new object or #NULL if no memory
*/
DBusAuth*
_dbus_auth_server_new (void)
_dbus_auth_server_new (const DBusString *guid)
{
DBusAuth *auth;
DBusAuthServer *server_auth;
DBusString guid_copy;
auth = _dbus_auth_new (sizeof (DBusAuthServer));
if (auth == NULL)
if (!_dbus_string_init (&guid_copy))
return NULL;
if (!_dbus_string_copy (guid, 0, &guid_copy, 0))
{
_dbus_string_free (&guid_copy);
return NULL;
}
auth = _dbus_auth_new (sizeof (DBusAuthServer));
if (auth == NULL)
{
_dbus_string_free (&guid_copy);
return NULL;
}
auth->side = auth_side_server;
auth->state = &server_state_waiting_for_auth;
server_auth = DBUS_AUTH_SERVER (auth);
server_auth->guid = guid_copy;
/* perhaps this should be per-mechanism with a lower
* max
*/
......@@ -2012,6 +2029,12 @@ _dbus_auth_unref (DBusAuth *auth)
{
_dbus_list_clear (& DBUS_AUTH_CLIENT (auth)->mechs_to_try);
}
else
{
_dbus_assert (DBUS_AUTH_IS_SERVER (auth));
_dbus_string_free (& DBUS_AUTH_SERVER (auth)->guid);
}
if (auth->keyring)
_dbus_keyring_unref (auth->keyring);
......
......@@ -41,7 +41,7 @@ typedef enum
DBUS_AUTH_STATE_AUTHENTICATED
} DBusAuthState;
DBusAuth* _dbus_auth_server_new (void);
DBusAuth* _dbus_auth_server_new (const DBusString *guid);
DBusAuth* _dbus_auth_client_new (void);
DBusAuth* _dbus_auth_ref (DBusAuth *auth);
void _dbus_auth_unref (DBusAuth *auth);
......
This diff is collapsed.
......@@ -89,6 +89,8 @@ typedef DBusHandlerResult (* DBusHandleMessageFunction) (DBusConnection *con
DBusConnection* dbus_connection_open (const char *address,
DBusError *error);
DBusConnection* dbus_connection_open_private (const char *address,
DBusError *error);
DBusConnection* dbus_connection_ref (DBusConnection *connection);
void dbus_connection_unref (DBusConnection *connection);
void dbus_connection_disconnect (DBusConnection *connection);
......
......@@ -280,7 +280,8 @@ _DBUS_DECLARE_GLOBAL_LOCK (bus);
_DBUS_DECLARE_GLOBAL_LOCK (shutdown_funcs);
_DBUS_DECLARE_GLOBAL_LOCK (system_users);
_DBUS_DECLARE_GLOBAL_LOCK (message_cache);
#define _DBUS_N_GLOBAL_LOCKS (10)
_DBUS_DECLARE_GLOBAL_LOCK (shared_connections);
#define _DBUS_N_GLOBAL_LOCKS (11)
dbus_bool_t _dbus_threads_init_debug (void);
......
......@@ -270,9 +270,9 @@ _dbus_transport_debug_pipe_new (const char *server_name,
_dbus_string_free (&address);
client_fd = -1;
server_transport = _dbus_transport_new_for_fd (server_fd,
TRUE, NULL);
&server->guid_hex, NULL);
if (server_transport == NULL)
{
_dbus_transport_unref (client_transport);
......
......@@ -31,6 +31,7 @@
#include <dbus/dbus-watch.h>
#include <dbus/dbus-resources.h>
#include <dbus/dbus-dataslot.h>
#include <dbus/dbus-string.h>
DBUS_BEGIN_DECLS
......@@ -67,7 +68,9 @@ struct DBusServer
const DBusServerVTable *vtable; /**< Virtual methods for this instance. */
DBusMutex *mutex; /**< Lock on the server object */
DBusGUID guid; /**< Globally unique ID of server */
DBusGUID guid; /**< Globally unique ID of server */
DBusString guid_hex; /**< Hex-encoded version of GUID */
DBusWatchList *watches; /**< Our watches */
DBusTimeoutList *timeouts; /**< Our timeouts */
......
......@@ -99,7 +99,7 @@ handle_new_client_fd_and_unlock (DBusServer *server,
return TRUE;
}
transport = _dbus_transport_new_for_fd (client_fd, TRUE, NULL);
transport = _dbus_transport_new_for_fd (client_fd, &server->guid_hex, NULL);
if (transport == NULL)
{
close (client_fd);
......
......@@ -75,33 +75,30 @@ init_guid (DBusGUID *guid)
*/
static char*
copy_address_with_guid_appended (const DBusString *address,
const DBusGUID *guid)
const DBusString *guid_hex)
{
DBusString with_guid;
DBusString guid_str;
char *retval;
if (!_dbus_string_init (&with_guid))
return NULL;
_dbus_string_init_const_len (&guid_str, guid->as_bytes,
sizeof (guid->as_bytes));
if (!_dbus_string_copy (address, 0, &with_guid, 0) ||
if (!_dbus_string_copy (address, 0, &with_guid,
_dbus_string_get_length (&with_guid)) ||
!_dbus_string_append (&with_guid, ",guid=") ||
!_dbus_string_hex_encode (&guid_str, 0,
&with_guid, _dbus_string_get_length (&with_guid)))
!_dbus_string_copy (guid_hex, 0,
&with_guid, _dbus_string_get_length (&with_guid)))
{
_dbus_string_free (&with_guid);
return NULL;
}
retval = NULL;
_dbus_string_copy_data (&with_guid, &retval);
_dbus_string_steal_data (&with_guid, &retval);
_dbus_string_free (&with_guid);
return retval; /* may be NULL if copy failed */
return retval; /* may be NULL if steal_data failed */
}
/**
......@@ -117,7 +114,9 @@ dbus_bool_t
_dbus_server_init_base (DBusServer *server,
const DBusServerVTable *vtable,
const DBusString *address)
{
{
DBusString guid_raw;
server->vtable = vtable;
server->refcount.value = 1;
......@@ -125,10 +124,20 @@ _dbus_server_init_base (DBusServer *server,
server->watches = NULL;
server->timeouts = NULL;
if (!_dbus_string_init (&server->guid_hex))
return FALSE;
init_guid (&server->guid);
_dbus_string_init_const_len (&guid_raw, server->guid.as_bytes,
sizeof (server->guid.as_bytes));
if (!_dbus_string_hex_encode (&guid_raw, 0,
&server->guid_hex,
_dbus_string_get_length (&server->guid_hex)))
goto failed;
server->address = copy_address_with_guid_appended (address,
&server->guid);
&server->guid_hex);
if (server->address == NULL)
goto failed;
......@@ -171,6 +180,7 @@ _dbus_server_init_base (DBusServer *server,
dbus_free (server->address);
server->address = NULL;
}
_dbus_string_free (&server->guid_hex);
return FALSE;
}
......@@ -205,6 +215,8 @@ _dbus_server_finalize_base (DBusServer *server)
dbus_free (server->address);
dbus_free_string_array (server->auth_mechanisms);
_dbus_string_free (&server->guid_hex);
}
......
......@@ -231,7 +231,8 @@ init_global_locks (void)
LOCK_ADDR (bus),
LOCK_ADDR (shutdown_funcs),
LOCK_ADDR (system_users),
LOCK_ADDR (message_cache)
LOCK_ADDR (message_cache),
LOCK_ADDR (shared_connections)
#undef LOCK_ADDR
};
......
......@@ -113,7 +113,7 @@ struct DBusTransport
dbus_bool_t _dbus_transport_init_base (DBusTransport *transport,
const DBusTransportVTable *vtable,
dbus_bool_t server,
const DBusString *server_guid,
const DBusString *address);
void _dbus_transport_finalize_base (DBusTransport *transport);
......
......@@ -1114,13 +1114,13 @@ static DBusTransportVTable unix_vtable = {
* boil down to a full duplex file descriptor.
*
* @param fd the file descriptor.
* @param server #TRUE if this transport is on the server side of a connection
* @param server_guid non-#NULL 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,
const DBusString *server_guid,
const DBusString *address)
{
DBusTransportUnix *unix_transport;
......@@ -1151,7 +1151,7 @@ _dbus_transport_new_for_fd (int fd,
if (!_dbus_transport_init_base (&unix_transport->base,
&unix_vtable,
server, address))
server_guid, address))
goto failed_4;
unix_transport->fd = fd;
......
......@@ -28,7 +28,7 @@
DBUS_BEGIN_DECLS
DBusTransport* _dbus_transport_new_for_fd (int fd,
dbus_bool_t server,
const DBusString *server_guid,
const DBusString *address);
DBusTransport* _dbus_transport_new_for_domain_socket (const char *path,
dbus_bool_t abstract,
......
This diff is collapsed.
......@@ -26,12 +26,13 @@
#include <dbus/dbus-internals.h>
#include <dbus/dbus-connection.h>
#include <dbus/dbus-protocol.h>
#include <dbus/dbus-address.h>
DBUS_BEGIN_DECLS
typedef struct DBusTransport DBusTransport;
DBusTransport* _dbus_transport_open (const char *address,
DBusTransport* _dbus_transport_open (DBusAddressEntry *entry,
DBusError *error);
DBusTransport* _dbus_transport_ref (DBusTransport *transport);
void _dbus_transport_unref (DBusTransport *transport);
......
......@@ -33,21 +33,9 @@ Important for 1.0
- dbus-pending-call.c has some API and thread safety issues to review
- make dbus_connection_open() return a shared connection from a pool.
Add dbus_connection_open_private() that works like the current one.
To do this, each DBusServer could have a 128-bit GUID. This GUID
would be in the address from dbus_server_get_address(). On
connection to a server, the GUID would be provided as the first
thing in the auth protocol, and verified vs. the expected GUID if a
GUID was in the address used to connect. A hash from GUID to
connection would be kept, so attempts to connect to a GUID already
in the hash would return a shared existing connection.
The purpose of all this is to allow a dbus_g_proxy_to_string() that
would convert the proxy to an "IOR" and dbus_g_proxy_from_string()
that would decode; using these, dbus-glib users could avoid
DBusConnection entirely. Of course the same applies to other kinds
of binding.
- transmit GUID from server to client in the auth protocol, so
connections can be shared even if the address used to connect
to them didn't have a GUID in it.
Important for 1.0 GLib Bindings
===
......@@ -74,6 +62,13 @@ Might as Well for 1.0
Can Be Post 1.0
===
- Allow a dbus_g_proxy_to_string()/g_object_to_string() that
would convert the proxy to an "IOR" and dbus_g_proxy_from_string()
that would decode; using these, dbus-glib users could avoid
DBusConnection entirely. Of course the same applies to other kinds
of binding. This would use dbus_connection_open()'s connection-sharing
feature to avoid massive proliferation of connections.
- DBusWatchList/TimeoutList duplicate a lot of code, as do
protected_change_watch/protected_change_timeout in dbus-connection.c
and dbus-server.c. This could all be mopped up, cut-and-paste
......
......@@ -190,7 +190,7 @@ no_bus_thread_func (void *data)
g_printerr ("Starting client thread %p\n", g_thread_self());
dbus_error_init (&error);
connection = dbus_connection_open (messages_address, &error);
connection = dbus_connection_open_private (messages_address, &error);
if (connection == NULL)
{
g_printerr ("could not open connection: %s\n", error.message);
......@@ -361,7 +361,7 @@ with_bus_thread_func (void *data)
}
dbus_error_init (&error);
connection = dbus_connection_open (address, &error);
connection = dbus_connection_open_private (address, &error);
if (connection == NULL)
{
g_printerr ("could not open connection to bus: %s\n", error.message);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment