summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Dufresne <nicolas.dufresne@collabora.co.uk>2010-10-01 16:28:38 -0400
committerNicolas Dufresne <nicolas.dufresne@collabora.co.uk>2010-10-04 13:46:15 -0400
commit595923caa8d994ec8fbba4b5c4e3506a29f1437a (patch)
tree0e4f7c4bbeafa0ccbbfffcef067e647f3083aaaf
parent8d152596eeb21b885a17632dff2526ec5d1cdc38 (diff)
Remove dependency to libuuid
Remove dependency on external libuuid by implementing an RFC4122 compliant UUID generator. (bugs.fd.o #28990)
-rw-r--r--NEWS2
-rw-r--r--configure.ac4
-rw-r--r--src/Makefile.am4
-rw-r--r--src/muc-factory.c2
-rw-r--r--src/util.c58
5 files changed, 55 insertions, 15 deletions
diff --git a/NEWS b/NEWS
index 4c7733a72..180ec6c87 100644
--- a/NEWS
+++ b/NEWS
@@ -129,6 +129,8 @@ Fixes:
› don't fail on missing CRLs if not in strict TLS verification mode
(fledermaus)
+• fd.o#28990: removed dependency to libuuid (stormer)
+
telepathy-gabble 0.9.17 (2010-08-26)
====================================
diff --git a/configure.ac b/configure.ac
index bc54c8c56..d811a0114 100644
--- a/configure.ac
+++ b/configure.ac
@@ -281,10 +281,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 ce8ef26fa..3d9721615 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -218,14 +218,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 a40084c2a..a6e9bfa94 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 f475c6546..01e1439de 100644
--- a/src/util.c
+++ b/src/util.c
@@ -36,8 +36,6 @@
#include <extensions/extensions.h>
-#include <uuid.h>
-
#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)