diff options
author | Havoc Pennington <hp@redhat.com> | 2005-02-25 22:03:30 +0000 |
---|---|---|
committer | Havoc Pennington <hp@redhat.com> | 2005-02-25 22:03:30 +0000 |
commit | 7ce7502e1ae23766ba40105327de787c2d1cef9d (patch) | |
tree | 06fcb80d134ca45a88a510e0f53d34e2f415fd50 /dbus/dbus-server.c | |
parent | 1b5dace8e6986965af7b573b3b2c5991af11cf6e (diff) |
2005-02-25 Havoc Pennington <hp@redhat.com>
* doc/dbus-specification.xml: document the GUID thing
* dbus/dbus-server.c (_dbus_server_init_base): initialize a
globally unique ID for the server, and put a "guid=hexencoded"
field in the address
* dbus/dbus-bus.c: fix missing #include of dbus-threads-internal.h
* dbus/dbus-message.c: ditto
* dbus/dbus-dataslot.c: ditto
* dbus/dbus-list.c: ditto
* dbus/dbus-internals.h: wait, just include
dbus-threads-internal.h here
* dbus/dbus-string.c (_dbus_string_copy_to_buffer): move back for
use in main library
* dbus/dbus-sysdeps.c (_dbus_generate_random_bytes_buffer): new function
Diffstat (limited to 'dbus/dbus-server.c')
-rw-r--r-- | dbus/dbus-server.c | 68 |
1 files changed, 63 insertions, 5 deletions
diff --git a/dbus/dbus-server.c b/dbus/dbus-server.c index 156d5ccd..20fb5f3c 100644 --- a/dbus/dbus-server.c +++ b/dbus/dbus-server.c @@ -52,6 +52,58 @@ * @{ */ +static void +init_guid (DBusGUID *guid) +{ + long now; + char *p; + int ts_size; + + _dbus_get_current_time (&now, NULL); + + guid->as_uint32s[0] = now; + + ts_size = sizeof (guid->as_uint32s[0]); + p = ((char*)guid->as_bytes) + ts_size; + + _dbus_generate_random_bytes_buffer (p, + sizeof (guid->as_bytes) - ts_size); +} + +/* this is a little fragile since it assumes the address doesn't + * already have a guid, but it shouldn't + */ +static char* +copy_address_with_guid_appended (const DBusString *address, + const DBusGUID *guid) +{ + 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) || + !_dbus_string_append (&with_guid, ",guid=") || + !_dbus_string_hex_encode (&guid_str, 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_free (&with_guid); + + return retval; /* may be NULL if copy failed */ +} + /** * Initializes the members of the DBusServer base class. * Chained up to by subclass constructors. @@ -65,17 +117,21 @@ dbus_bool_t _dbus_server_init_base (DBusServer *server, const DBusServerVTable *vtable, const DBusString *address) -{ +{ server->vtable = vtable; server->refcount.value = 1; server->address = NULL; server->watches = NULL; server->timeouts = NULL; - - if (!_dbus_string_copy_data (address, &server->address)) - goto failed; + init_guid (&server->guid); + + server->address = copy_address_with_guid_appended (address, + &server->guid); + if (server->address == NULL) + goto failed; + server->mutex = _dbus_mutex_new (); if (server->mutex == NULL) goto failed; @@ -438,7 +494,9 @@ dbus_server_listen (const char *address, for (i = 0; i < len; i++) { - const char *method = dbus_address_entry_get_method (entries[i]); + const char *method; + + method = dbus_address_entry_get_method (entries[i]); if (strcmp (method, "unix") == 0) { |