From 458067fb35c25825dfbffda449ad0ee11221e5cc Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Fri, 1 Oct 2010 16:28:38 -0400 Subject: [PATCH] Remove dependency to libuuid Remove dependency on external libuuid by implementing an RFC4122 compliant UUID generator. --- configure.ac | 4 --- src/Makefile.am | 4 +- src/muc-factory.c | 2 - src/util.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++------ 4 files changed, 53 insertions(+), 15 deletions(-) diff --git a/configure.ac b/configure.ac index 1bb4247..d662009 100644 --- a/configure.ac +++ b/configure.ac @@ -278,10 +278,6 @@ PKG_CHECK_MODULES(NICE, nice >= 0.0.11) AC_SUBST(NICE_CFLAGS) AC_SUBST(NICE_LIBS) -PKG_CHECK_MODULES([UUID], [uuid]) -AC_SUBST([UUID_CFLAGS]) -AC_SUBST([UUID_LIBS]) - dnl Check for MCE, a Maemo service used by Gabble to determine when the device dnl is idle. PKG_CHECK_MODULES([MCE], mce >= 1.5, [HAVE_MCE=yes], [HAVE_MCE=no]) diff --git a/src/Makefile.am b/src/Makefile.am index 3357e85..8e77117 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -226,14 +226,14 @@ noinst_LTLIBRARIES = libgabble-convenience.la AM_CFLAGS = $(ERROR_CFLAGS) -I$(top_srcdir) -I$(top_builddir) \ @DBUS_CFLAGS@ @GLIB_CFLAGS@ @WOCKY_CFLAGS@ \ @HANDLE_LEAK_DEBUG_CFLAGS@ @TP_GLIB_CFLAGS@ \ - @SOUP_CFLAGS@ @NICE_CFLAGS@ @UUID_CFLAGS@ @GMODULE_CFLAGS@ \ + @SOUP_CFLAGS@ @NICE_CFLAGS@ @GMODULE_CFLAGS@ \ @SQLITE_CFLAGS@ \ -I $(top_srcdir)/lib -I $(top_builddir)/lib \ -DG_LOG_DOMAIN=\"gabble\" \ -DPLUGIN_DIR=\"$(libdir)/telepathy/gabble-0\" ALL_LIBS = @DBUS_LIBS@ @GLIB_LIBS@ @WOCKY_LIBS@ @TP_GLIB_LIBS@ \ - @SOUP_LIBS@ @NICE_LIBS@ @UUID_LIBS@ @GMODULE_LIBS@ @SQLITE_LIBS@ + @SOUP_LIBS@ @NICE_LIBS@ @GMODULE_LIBS@ @SQLITE_LIBS@ # build gibber first all: gibber diff --git a/src/muc-factory.c b/src/muc-factory.c index 1663acc..24ef182 100644 --- a/src/muc-factory.c +++ b/src/muc-factory.c @@ -1367,8 +1367,6 @@ handle_text_channel_request (GabbleMucFactory *self, } } - /* N.B. gabble_generate_id() requires libuuid to generate valid UUIDs - * for Google PMUCs */ uuid = gabble_generate_id (); id = g_strdup_printf ("private-chat-%s%s", uuid, server); diff --git a/src/util.c b/src/util.c index 97dbbda..7347a41 100644 --- a/src/util.c +++ b/src/util.c @@ -36,8 +36,6 @@ #include -#include - #define DEBUG_FLAG GABBLE_DEBUG_JID #include "base64.h" @@ -80,19 +78,64 @@ sha1_bin (const gchar *bytes, g_checksum_free (checksum); } + +/** gabble_generate_id: + * + * RFC4122 version 4 compliant random UUIDs generator. + * + * Returns: A string with RFC41122 version 4 random UUID, must be freed with + * g_free(). + */ gchar * gabble_generate_id (void) { - /* generate random UUIDs */ - uuid_t uu; + GRand *grand; gchar *str; + struct { + guint32 time_low; + guint16 time_mid; + guint16 time_hi_and_version; + guint8 clock_seq_hi_and_rsv; + guint8 clock_seq_low; + guint16 node_hi; + guint32 node_low; + } uuid; + + /* Fill with random. Every new GRand are seede with 128 bit read from + * /dev/urandom (or the current time on non-unix systems). This makes the + * random source good enough for our usage, but may not be suitable for all + * situation outside Gabble. */ + grand = g_rand_new (); + uuid.time_low = g_rand_int (grand); + uuid.time_mid = (guint16) g_rand_int_range (grand, 0, G_MAXUINT16); + uuid.time_hi_and_version = (guint16) g_rand_int_range (grand, 0, G_MAXUINT16); + uuid.clock_seq_hi_and_rsv = (guint8) g_rand_int_range (grand, 0, G_MAXUINT8); + uuid.clock_seq_low = (guint8) g_rand_int_range (grand, 0, G_MAXUINT8); + uuid.node_hi = (guint16) g_rand_int_range (grand, 0, G_MAXUINT16); + uuid.node_low = g_rand_int (grand); + g_rand_free (grand); + + /* Set the two most significant bits (bits 6 and 7) of the + * clock_seq_hi_and_rsv to zero and one, respectively. */ + uuid.clock_seq_hi_and_rsv = (uuid.clock_seq_hi_and_rsv & 0x3F) | 0x80; + + /* Set the four most significant bits (bits 12 through 15) of the + * time_hi_and_version field to 4 */ + uuid.time_hi_and_version = (uuid.time_hi_and_version & 0x0fff) | 0x4000; + + str = g_strdup_printf ("%08x-%04x-%04x-%02x%02x-%04x%08x", + uuid.time_low, + uuid.time_mid, + uuid.time_hi_and_version, + uuid.clock_seq_hi_and_rsv, + uuid.clock_seq_low, + uuid.node_hi, + uuid.node_low); - str = g_new0 (gchar, 37); - uuid_generate_random (uu); - uuid_unparse_lower (uu, str); return str; } + static void lm_message_node_add_nick (LmMessageNode *node, const gchar *nick) { @@ -119,6 +162,7 @@ lm_message_node_add_own_nick (LmMessageNode *node, g_free (nick); } + void lm_message_node_steal_children (LmMessageNode *snatcher, LmMessageNode *mum) -- 1.7.2.3