dbus/dbus dbus-bus.c, 1.40, 1.41 dbus-dataslot.c, 1.9, 1.10 dbus-internals.h, 1.53, 1.54 dbus-list.c, 1.20, 1.21 dbus-message.c, 1.165, 1.166 dbus-server-protected.h, 1.17, 1.18 dbus-server.c, 1.39, 1.40 dbus-string-util.c, 1.2, 1.3 dbus-string.c, 1.66, 1.67 dbus-sysdeps.c, 1.90, 1.91 dbus-sysdeps.h, 1.46, 1.47

Havoc Pennington hp at freedesktop.org
Fri Feb 25 14:03:32 PST 2005


Update of /cvs/dbus/dbus/dbus
In directory gabe:/tmp/cvs-serv11412/dbus

Modified Files:
	dbus-bus.c dbus-dataslot.c dbus-internals.h dbus-list.c 
	dbus-message.c dbus-server-protected.h dbus-server.c 
	dbus-string-util.c dbus-string.c dbus-sysdeps.c dbus-sysdeps.h 
Log Message:
2005-02-25  Havoc Pennington  <hp at 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



Index: dbus-bus.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-bus.c,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -d -r1.40 -r1.41
--- dbus-bus.c	17 Feb 2005 21:19:49 -0000	1.40
+++ dbus-bus.c	25 Feb 2005 22:03:30 -0000	1.41
@@ -27,6 +27,7 @@
 #include "dbus-internals.h"
 #include "dbus-message.h"
 #include "dbus-marshal-validate.h"
+#include "dbus-threads-internal.h"
 #include <string.h>
 
 /**

Index: dbus-dataslot.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-dataslot.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- dbus-dataslot.c	24 Feb 2005 18:37:16 -0000	1.9
+++ dbus-dataslot.c	25 Feb 2005 22:03:30 -0000	1.10
@@ -21,7 +21,7 @@
  *
  */
 #include "dbus-dataslot.h"
-#include "dbus-threads.h"
+#include "dbus-threads-internal.h"
 
 /**
  * @defgroup DBusDataSlot Data slots

Index: dbus-internals.h
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-internals.h,v
retrieving revision 1.53
retrieving revision 1.54
diff -u -d -r1.53 -r1.54
--- dbus-internals.h	24 Feb 2005 18:37:16 -0000	1.53
+++ dbus-internals.h	25 Feb 2005 22:03:30 -0000	1.54
@@ -33,7 +33,7 @@
 #include <dbus/dbus-types.h>
 #include <dbus/dbus-errors.h>
 #include <dbus/dbus-sysdeps.h>
-#include <dbus/dbus-threads.h>
+#include <dbus/dbus-threads-internal.h>
 
 DBUS_BEGIN_DECLS
 

Index: dbus-list.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-list.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- dbus-list.c	17 Jan 2005 03:53:40 -0000	1.20
+++ dbus-list.c	25 Feb 2005 22:03:30 -0000	1.21
@@ -24,7 +24,7 @@
 #include "dbus-internals.h"
 #include "dbus-list.h"
 #include "dbus-mempool.h"
-#include "dbus-threads.h"
+#include "dbus-threads-internal.h"
 
 /**
  * @defgroup DBusList Linked list

Index: dbus-message.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-message.c,v
retrieving revision 1.165
retrieving revision 1.166
diff -u -d -r1.165 -r1.166
--- dbus-message.c	24 Feb 2005 16:03:56 -0000	1.165
+++ dbus-message.c	25 Feb 2005 22:03:30 -0000	1.166
@@ -32,6 +32,7 @@
 #include "dbus-object-tree.h"
 #include "dbus-memory.h"
 #include "dbus-list.h"
+#include "dbus-threads-internal.h"
 #include <string.h>
 
 /**

Index: dbus-server-protected.h
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-server-protected.h,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- dbus-server-protected.h	24 Feb 2005 18:37:16 -0000	1.17
+++ dbus-server-protected.h	25 Feb 2005 22:03:30 -0000	1.18
@@ -35,6 +35,16 @@
 DBUS_BEGIN_DECLS
 
 typedef struct DBusServerVTable DBusServerVTable;
+typedef union DBusGUID DBusGUID;
+
+/**
+ * A server's globally unique ID
+ */
+union DBusGUID
+{
+  dbus_uint32_t as_uint32s[4];
+  unsigned char as_bytes[16];
+};
 
 /**
  * Virtual table to be implemented by all server "subclasses"
@@ -56,6 +66,9 @@
   DBusAtomic refcount;                        /**< Reference count. */
   const DBusServerVTable *vtable;             /**< Virtual methods for this instance. */
   DBusMutex *mutex;                           /**< Lock on the server object */
+
+  DBusGUID guid;                              /**< Globally unique ID of server */ 
+  
   DBusWatchList *watches;                     /**< Our watches */
   DBusTimeoutList *timeouts;                  /**< Our timeouts */  
 

Index: dbus-server.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-server.c,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -d -r1.39 -r1.40
--- dbus-server.c	24 Feb 2005 18:37:16 -0000	1.39
+++ dbus-server.c	25 Feb 2005 22:03:30 -0000	1.40
@@ -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_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 @@
   
   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)
 	{

Index: dbus-string-util.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-string-util.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- dbus-string-util.c	6 Feb 2005 04:21:57 -0000	1.2
+++ dbus-string-util.c	25 Feb 2005 22:03:30 -0000	1.3
@@ -32,30 +32,6 @@
  */
 
 /**
- * Copies the contents of a DBusString into a different
- * buffer. The resulting buffer will be nul-terminated.
- * 
- * @param str a string
- * @param buffer a C buffer to copy data to
- * @param avail_len maximum length of C buffer
- */
-void
-_dbus_string_copy_to_buffer (const DBusString  *str,
-			     char              *buffer,
-			     int                avail_len)
-{
-  int copy_len;
-  DBUS_CONST_STRING_PREAMBLE (str);
-
-  _dbus_assert (avail_len >= 0);
-
-  copy_len = MIN (avail_len, real->len+1);
-  memcpy (buffer, real->str, copy_len);
-  if (avail_len > 0 && avail_len == copy_len)
-    buffer[avail_len-1] = '\0';
-}
-
-/**
  * Returns whether a string ends with the given suffix
  *
  * @todo memcmp might make this faster.

Index: dbus-string.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-string.c,v
retrieving revision 1.66
retrieving revision 1.67
diff -u -d -r1.66 -r1.67
--- dbus-string.c	11 Feb 2005 03:37:03 -0000	1.66
+++ dbus-string.c	25 Feb 2005 22:03:30 -0000	1.67
@@ -708,6 +708,30 @@
   return TRUE;
 }
 
+/**
+ * Copies the contents of a DBusString into a different
+ * buffer. The resulting buffer will be nul-terminated.
+ * 
+ * @param str a string
+ * @param buffer a C buffer to copy data to
+ * @param avail_len maximum length of C buffer
+ */
+void
+_dbus_string_copy_to_buffer (const DBusString  *str,
+			     char              *buffer,
+			     int                avail_len)
+{
+  int copy_len;
+  DBUS_CONST_STRING_PREAMBLE (str);
+
+  _dbus_assert (avail_len >= 0);
+
+  copy_len = MIN (avail_len, real->len+1);
+  memcpy (buffer, real->str, copy_len);
+  if (avail_len > 0 && avail_len == copy_len)
+    buffer[avail_len-1] = '\0';
+}
+
 #ifdef DBUS_BUILD_TESTS
 /**
  * Copies a segment of the string into a char*

Index: dbus-sysdeps.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-sysdeps.c,v
retrieving revision 1.90
retrieving revision 1.91
diff -u -d -r1.90 -r1.91
--- dbus-sysdeps.c	21 Jan 2005 04:14:54 -0000	1.90
+++ dbus-sysdeps.c	25 Feb 2005 22:03:30 -0000	1.91
@@ -2328,15 +2328,12 @@
 }
 
 static dbus_bool_t
-pseudorandom_generate_random_bytes (DBusString *str,
-                                    int         n_bytes)
+pseudorandom_generate_random_bytes_buffer (char *buffer,
+                                           int   n_bytes)
 {
-  int old_len;
   unsigned long tv_usec;
   int i;
   
-  old_len = _dbus_string_get_length (str);
-
   /* fall back to pseudorandom */
   _dbus_verbose ("Falling back to pseudorandom for %d bytes\n",
                  n_bytes);
@@ -2352,18 +2349,56 @@
           
       r = rand ();
       b = (r / (double) RAND_MAX) * 255.0;
-          
-      if (!_dbus_string_append_byte (str, b))
-        goto failed;
-          
+
+      buffer[i] = b;
+
       ++i;
     }
+}
+
+static dbus_bool_t
+pseudorandom_generate_random_bytes (DBusString *str,
+                                    int         n_bytes)
+{
+  int old_len;
+  char *p;
+  
+  old_len = _dbus_string_get_length (str);
+
+  if (!_dbus_string_lengthen (str, n_bytes))
+    return FALSE;
+
+  p = _dbus_string_get_data_len (str, old_len, n_bytes);
+
+  pseudorandom_generate_random_bytes_buffer (p, n_bytes);
 
   return TRUE;
+}
 
- failed:
-  _dbus_string_set_length (str, old_len);
-  return FALSE;
+/**
+ * Fills n_bytes of the given buffer with random bytes.
+ *
+ * @param buffer an allocated buffer
+ * @param n_bytes the number of bytes in buffer to write to
+ */
+void
+_dbus_generate_random_bytes_buffer (char *buffer,
+                                    int   n_bytes)
+{
+  DBusString str;
+
+  if (!_dbus_string_init (&str))
+    return pseudorandom_generate_random_bytes_buffer (buffer, n_bytes);
+
+  if (!_dbus_generate_random_bytes (&str, n_bytes))
+    {
+      _dbus_string_free (&str);
+      return pseudorandom_generate_random_bytes_buffer (buffer, n_bytes);
+    }
+
+  _dbus_string_copy_to_buffer (&str, buffer, n_bytes);
+
+  _dbus_string_free (&str);
 }
 
 /**

Index: dbus-sysdeps.h
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-sysdeps.h,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -d -r1.46 -r1.47
--- dbus-sysdeps.h	17 Jan 2005 01:20:02 -0000	1.46
+++ dbus-sysdeps.h	25 Feb 2005 22:03:30 -0000	1.47
@@ -256,10 +256,12 @@
 void         _dbus_directory_close         (DBusDirIter      *iter);
 
 
-dbus_bool_t _dbus_generate_random_bytes (DBusString *str,
-                                         int         n_bytes);
-dbus_bool_t _dbus_generate_random_ascii (DBusString *str,
-                                         int         n_bytes);
+void        _dbus_generate_random_bytes_buffer (char       *buffer,
+                                                int         n_bytes);
+dbus_bool_t _dbus_generate_random_bytes        (DBusString *str,
+                                                int         n_bytes);
+dbus_bool_t _dbus_generate_random_ascii        (DBusString *str,
+                                                int         n_bytes);
 
 const char *_dbus_errno_to_string  (int errnum);
 const char* _dbus_error_from_errno (int error_number);



More information about the dbus-commit mailing list