From a43f0db9a3b179e1a24a9c902581b3c91e481055 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 | 37 +++++++++++++++++++++++++++++++------ 4 files changed, 33 insertions(+), 14 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..e52fd22 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,45 @@ 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; + const char *hex = "0123456789abcdef"; gchar *str; + int i; str = g_new0 (gchar, 37); - uuid_generate_random (uu); - uuid_unparse_lower (uu, str); + + /* Fill with random. The g_random_int() call uses Mersenne Twister PRNG + * seeded with /dev/random or the current time, which comply with + * RFC4122 requirement. + */ + for (i = 0; i < 37; i++) + str[i] = hex[g_random_int_range (0, 16)]; + + /* Add separators */ + str[8] = str[13] = str[18] = str[23] = '-'; + + /* Set the two most significant bits (bits 6 and 7) of the + * clock_seq_hi_and_rsv to zero and one, respectively. */ + str[19] = hex[g_random_int_range (8, 12)]; + + /* Set the four most significant bits (bits 12 through 15) of the + * time_hi_and_version field to 4 */ + str[14] = '4'; + return str; } + static void lm_message_node_add_nick (LmMessageNode *node, const gchar *nick) { @@ -119,6 +143,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