[gupnp] Use GUUL for native UUID support



commit 9eca22a207f09b9d481b96dcae840effd24a337e
Author: Jens Georg <mail jensge org>
Date:   Sun Jan 25 12:28:24 2015 +0100

    Use GUUL for native UUID support
    
    Signed-off-by: Jens Georg <mail jensge org>
    
    https://bugzilla.gnome.org/show_bug.cgi?id=743072

 configure.ac             |   12 +++----
 libgupnp/Makefile.am     |    5 ++-
 libgupnp/gupnp-service.c |   31 +++--------------
 libgupnp/guul.c          |   82 ++++++++++++++++++++++++++++++++++++++++++++++
 libgupnp/guul.h          |   38 +++++++++++++++++++++
 m4/guul.m4               |   54 ++++++++++++++++++++++++++++++
 6 files changed, 189 insertions(+), 33 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 8d869b0..b6fbe17 100644
--- a/configure.ac
+++ b/configure.ac
@@ -27,6 +27,9 @@ AC_SYS_LARGEFILE
 LT_PREREQ([2.2])
 LT_INIT
 
+GUUL_CHECK_UUID([internal])
+UUID_LIBS=$GUUL_PKG
+AC_SUBST([UUID_LIBS])
 
 AC_MSG_CHECKING([operating system])
 os_win32=no
@@ -34,26 +37,21 @@ case "$target_os" in
      mingw*|cygwin*)
         os_win32=yes
         AC_MSG_RESULT(Win32)
-        UUID_LIBS=
         ;;
      darwin*)
         AC_MSG_RESULT(Darwin)
-        UUID_LIBS=
         ;;
      *)
         AC_MSG_RESULT($target_os)
-        UUID_LIBS=uuid
         ;;
 esac
-AC_SUBST([UUID_LIBS])
 
 PKG_CHECK_MODULES(LIBGUPNP, glib-2.0 >= 2.40.0 \
                             gio-2.0 \
                             gmodule-2.0 \
                             gssdp-1.0 >= 0.13.0 \
                             libsoup-2.4 >= 2.48.0 \
-                            libxml-2.0 \
-                            $UUID_LIBS)
+                            libxml-2.0)
 PKG_CHECK_MODULES(GTHREAD, gthread-2.0)
 
 AM_CONDITIONAL(OS_WIN32, test "x$os_win32" = "xyes")
@@ -64,7 +62,6 @@ if test "x$os_win32" = "xno"; then
                         [Context Manager backend to use]),,
             [with_context_manager="none"])
 else
-    LIBGUPNP_LIBS="$LIBGUPNP_LIBS -lrpcrt4"
     with_context_manager="windows"
 fi
 
@@ -181,4 +178,5 @@ echo "
     GObject-Introspection: ${found_introspection}
     VALA bindings:         ${have_vapigen}
     Context manager:       ${with_context_manager}
+    UUID Library:          ${GUUL_FLAVOR}
 "
diff --git a/libgupnp/Makefile.am b/libgupnp/Makefile.am
index 771434d..e1890a9 100644
--- a/libgupnp/Makefile.am
+++ b/libgupnp/Makefile.am
@@ -41,6 +41,7 @@ endif
 AM_CFLAGS = $(LIBGUPNP_CFLAGS) \
            $(DBUS_GLIB_CFLAGS) \
            $(NETLINK_CFLAGS) \
+               $(GUUL_CFLAGS) \
            -I$(top_srcdir) \
            $(CONTEXT_MANAGER_CFLAGS)
 
@@ -115,9 +116,11 @@ libgupnp_1_0_la_SOURCES = $(introspection_sources)         \
                          xml-util.c                            \
                          xml-util.h                            \
                          gena-protocol.h                       \
+                         guul.c \
+                         guul.h \
                          $(BUILT_SOURCES)
 
-libgupnp_1_0_la_LIBADD = $(LIBGUPNP_LIBS) $(DBUS_GLIB_LIBS) $(CONTEXT_MANAGER_LIBS)
+libgupnp_1_0_la_LIBADD = $(LIBGUPNP_LIBS) $(DBUS_GLIB_LIBS) $(CONTEXT_MANAGER_LIBS) $(GUUL_LIBS)
 
 EXTRA_DIST = gupnp-marshal.list           \
             gupnp-network-manager.c       \
diff --git a/libgupnp/gupnp-service.c b/libgupnp/gupnp-service.c
index 54372b7..989b43b 100644
--- a/libgupnp/gupnp-service.c
+++ b/libgupnp/gupnp-service.c
@@ -43,11 +43,7 @@
 #include "xml-util.h"
 #include "gvalue-util.h"
 
-#ifdef G_OS_WIN32
-#include <rpc.h>
-#else
-#include <uuid/uuid.h>
-#endif
+#include "guul.h"
 
 #define SUBSCRIPTION_TIMEOUT 300 /* DLNA (7.2.22.1) enforced */
 
@@ -1092,30 +1088,15 @@ subscription_response (GUPnPService *service,
 static char *
 generate_sid (void)
 {
-#ifdef G_OS_WIN32
         char *ret = NULL;
-        UUID uuid;
-        RPC_STATUS stat;
-        stat = UuidCreate (&uuid);
-        if (stat == RPC_S_OK) {
-                unsigned char* uuidStr = NULL;
-                stat = UuidToString (&uuid, &uuidStr);
-                if (stat == RPC_S_OK) {
-                        ret = g_strdup_printf ("uuid:%s", uuidStr);
-                        RpcStringFree (&uuidStr);
-                }
-        }
+        char *uuid;
 
-        return ret;
-#else
-        uuid_t id;
-        char out[39];
 
-        uuid_generate (id);
-        uuid_unparse (id, out);
+        uuid = guul_get_uuid ();
+        ret = g_strdup_printf ("uuid:%s", uuid);
+        g_free (uuid);
 
-        return g_strdup_printf ("uuid:%s", out);
-#endif
+        return ret;
 }
 
 /* Subscription expired */
diff --git a/libgupnp/guul.c b/libgupnp/guul.c
new file mode 100644
index 0000000..5138de3
--- /dev/null
+++ b/libgupnp/guul.c
@@ -0,0 +1,82 @@
+/*
+ * GUUL - GUUL Unified UUID Library
+ * Copyright (C) 2015 Jens Georg.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include <stdlib.h>
+
+#include <guul.h>
+
+#if defined(GUUL_PLATFORM_GENERIC) || defined(GUUL_PLATFORM_OSX) || defined(GUUL_PLATFORM_BSD)
+#   include <uuid.h>
+#endif
+
+#if defined(GUUL_PLATFORM_WINDOWS)
+#    include <rpc.h>
+#endif
+
+#if defined(GUUL_PLATFORM_GENERIC) || defined(GUUL_PLATFORM_OSX)
+char *
+guul_get_uuid()
+{
+        uuid_t uuid;
+        char *out;
+
+        out = calloc (41, sizeof (char));
+
+        uuid_generate (uuid);
+        uuid_unparse (uuid, out);
+
+        return out;
+}
+#endif
+
+#if GUUL_PLATFORM_BSD
+char *
+guul_get_uuid()
+{
+        uuid_t uuid;
+        uint32_t status;
+        char *result = NULL;
+
+        uuid_create (&uuid, &status);
+        uuid_to_string (&uuid, &result, &status);
+
+        return result;
+}
+#endif
+
+#ifdef GUUL_PLATFORM_WINDOWS
+char *
+guul_get_uuid()
+{
+    char *ret = NULL;
+    UUID uuid;
+    RPC_STATUS stat;
+    stat = UuidCreate (&uuid);
+    if (stat == RPC_S_OK) {
+            unsigned char* uuidStr = NULL;
+            stat = UuidToString (&uuid, &uuidStr);
+            if (stat == RPC_S_OK) {
+                    ret = g_strdup (uuidStr);
+                    RpcStringFree (&uuidStr);
+            }
+    }
+
+    return ret;
+}
+#endif
diff --git a/libgupnp/guul.h b/libgupnp/guul.h
new file mode 100644
index 0000000..5c0703e
--- /dev/null
+++ b/libgupnp/guul.h
@@ -0,0 +1,38 @@
+/*
+ * GUUL - GUUL Unified UUID Library
+ * Copyright (C) 2015 Jens Georg.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef __GUUL_H
+#define __GUUL_H
+
+#ifdef HAVE_CONFIG_H
+#   include <config.h>
+#endif
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+#ifdef GUUL_INTERNAL
+G_GNUC_INTERNAL
+#endif
+char *guul_get_uuid ();
+
+G_END_DECLS
+
+#endif /* __GUUL_H */
diff --git a/m4/guul.m4 b/m4/guul.m4
new file mode 100644
index 0000000..5bc3620
--- /dev/null
+++ b/m4/guul.m4
@@ -0,0 +1,54 @@
+AC_DEFUN([GUUL_CHECK_UUID],
+[
+    AS_IF([test "x$1" = "xinternal"],
+          [AC_DEFINE([GUUL_INTERNAL],[1],[GUUL will be used internally])])
+
+    GUUL_LIBS=
+    GUUL_CFLAGS=
+    AC_MSG_CHECKING([for uuid library])
+    case "$host" in
+        *-*-mingw*)
+            uuid_found=windows
+            AC_DEFINE([GUUL_PLATFORM_WINDOWS],[1],[Compiling for windows])
+            GUUL_LIBS=-lrpcrt4
+            ;;
+        *darwin*)
+            uuid_found=macosx
+            AC_DEFINE([GUUL_PLATFORM_OSX],[1],[Compiling for OS X])
+            ;;
+        *bsd*)
+            uuid_found=bsd
+            ;;
+        *)
+            uuid_found=generic
+            ;;
+    esac
+
+    dnl do fallback if we have a BSD that does not have the necessary functions
+    AS_IF([test "x$uuid_found" = "xbsd"],
+          [AC_SEARCH_LIBS([uuid_to_string], [c],
+            [UUID_LIBS=
+             AC_DEFINE([GUUL_PLATFORM_BSD],[1],[Compiling for BSD flavor])
+            ],
+            [uuid_found=generic])
+          ])
+
+    dnl for other platforms, use libuuid from the e2fs project
+    AS_IF([test "x$uuid_found" = "xgeneric"],
+          [PKG_CHECK_MODULES(UUID, [uuid],
+            [
+              AC_DEFINE([GUUL_PLATFORM_GENERIC],[1],[Using external library])
+              GUUL_LIBS="$UUID_LIBS"
+              GUUL_CFLAGS="$UUID_CFLAGS"
+              GUUL_PKG=uuid
+            ],
+            [AC_MSG_ERROR([none])
+          ])
+    ])
+
+    AC_SUBST(GUUL_LIBS)
+    AC_SUBST(GUUL_CFLAGS)
+    AC_SUBST(GUUL_PKG)
+    GUUL_FLAVOR=$uuid_found
+    AC_MSG_RESULT([using flavor $uuid_found])
+])


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]