commit c3b766058c4cc8078fa35a29253649c80c753349 Author: Nicolas Dufresne Date: Mon Jul 5 16:59:50 2010 -0400 Made libuuid library optional libuuid is a library part of util-linux-ng that is not portable. This implementation should fake properly that behaviour of uuid and allow compilation on non-linux paltform. Note that if uuid is available it will be used. diff --git a/configure.ac b/configure.ac index e1b213f..9ceed92 100644 --- a/configure.ac +++ b/configure.ac @@ -273,9 +273,15 @@ 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 libuuid +PKG_CHECK_MODULES([UUID], [uuid], [HAVE_UUID=yes], [HAVE_UUID=no]) +if test x"$HAVE_UUID" = xyes; then + AC_SUBST([UUID_CFLAGS]) + AC_SUBST([UUID_LIBS]) + AC_DEFINE([HAVE_UUID], [1], [Define if libuuid is available]) +else + AC_MSG_WARN([libuuid not found, falling back to generating random IDs]) +fi dnl Check for MCE, a Maemo service used by Gabble to determine when the device dnl is idle. diff --git a/src/util.c b/src/util.c index 15dc1ae..4ca3743 100644 --- a/src/util.c +++ b/src/util.c @@ -36,7 +36,9 @@ #include -#include +#ifdef HAVE_UUID +# include +#endif #define DEBUG_FLAG GABBLE_DEBUG_JID @@ -84,13 +86,30 @@ gchar * gabble_generate_id (void) { /* generate random UUIDs */ - uuid_t uu; gchar *str; str = g_new0 (gchar, 37); - uuid_generate_random (uu); - uuid_unparse_lower (uu, str); - return str; + +#ifdef HAVE_UUID + { + uuid_t uu; + + uuid_generate_random (uu); + uuid_unparse_lower (uu, str); + } +#else + { + const char *hex = "0123456789abcdef"; + int i; + + for (i = 0; i < 36; i++) + str[i] = hex[g_random_int_range (0, 16)]; + + str[8] = str[13] = str[18] = str[23] = '-'; + } +#endif + + return str; } static void