bug-wget
[Top][All Lists]
Advanced

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

[Bug-wget] [patch] uuid generation in warc.c


From: Jérémie Courrèges-Anglas
Subject: [Bug-wget] [patch] uuid generation in warc.c
Date: Tue, 16 Dec 2014 00:26:35 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (berkeley-unix)

Hi,

in src/warc.c three methods are provided to generate uuids: libuuid,
uuid functions from libc, and a fallback method.  At least OpenBSD,
FreeBSD and NetBSD provide those uuid functions in their libc.

  http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man3/uuid.3

This diff fixes the detection and use of those functions.  It does not
change the fact that libuuid is always preferred if present and not
explicitely disabled.

Regards,

>From 4e6196c11882ab2c86784af92bc7c977cb0948d5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Courr=C3=A8ges-Anglas?= <address@hidden>
Date: Tue, 16 Dec 2014 00:01:48 +0100
Subject: [PATCH] Fix use of uuid libc functions

* Always attempt to detect uuid.h and uuid_create().
* Split libuuid and uuid.h implementations of warc_uuid_str(), since
  those APIs vary significantly.
* Correctly use the uuid.h functions
---
 configure.ac | 13 ++++++-------
 src/warc.c   | 20 ++++++++++++++------
 2 files changed, 20 insertions(+), 13 deletions(-)

diff --git a/configure.ac b/configure.ac
index 7b4e2ad..ff016ce 100644
--- a/configure.ac
+++ b/configure.ac
@@ -652,13 +652,6 @@ AS_IF([test "X$with_libuuid" != "Xno"],[
     CFLAGS="$UUID_CFLAGS $CFLAGS"
     AC_DEFINE([HAVE_LIBUUID], [1], [Define if using libuuid.])
   ], [
-    AC_CHECK_HEADER(uuid.h,
-                    AC_CHECK_FUNC(uuid, uuid_create,
-                      [AC_DEFINE([HAVE_UUID_CREATE], 1,
-                                 [Define if uuid_create is available.])
-                      ])
-    )
-
     AC_CHECK_HEADER(uuid/uuid.h,
                     AC_CHECK_LIB(uuid, uuid_generate,
                       [LIBS="${LIBS} -luuid"
@@ -669,6 +662,12 @@ AS_IF([test "X$with_libuuid" != "Xno"],[
   ])
 ])
 
+AC_CHECK_HEADER(uuid.h,
+  AC_CHECK_FUNC(uuid_create,
+    [AC_DEFINE([HAVE_UUID_CREATE], 1, [Define if uuid_create is available.])]
+  )
+)
+
 dnl
 dnl Check for PCRE
 dnl
diff --git a/src/warc.c b/src/warc.c
index 5bdda1b..4959836 100644
--- a/src/warc.c
+++ b/src/warc.c
@@ -600,25 +600,33 @@ warc_timestamp (char *timestamp, size_t timestamp_size)
   return timestamp;
 }
 
-#if HAVE_LIBUUID || HAVE_UUID_CREATE
 /* Fills urn_str with a UUID in the format required
    for the WARC-Record-Id header.
    The string will be 47 characters long. */
+#if HAVE_LIBUUID
 void
 warc_uuid_str (char *urn_str)
 {
   char uuid_str[37];
+  uuid_t record_id;
+
+  uuid_generate (record_id);
+  uuid_unparse (record_id, uuid_str);
 
+  sprintf (urn_str, "<urn:uuid:%s>", uuid_str);
+}
+#elif HAVE_UUID_CREATE
+void
+warc_uuid_str (char *urn_str)
+{
+  char *uuid_str;
   uuid_t record_id;
-#if HAVE_UUID_CREATE
+
   uuid_create (&record_id, NULL);
   uuid_to_string (&record_id, &uuid_str, NULL);
-#else
-  uuid_generate (record_id);
-  uuid_unparse (record_id, uuid_str);
-#endif
 
   sprintf (urn_str, "<urn:uuid:%s>", uuid_str);
+  xfree (uuid_str);
 }
 #else
 /* Fills urn_str with a UUID based on random numbers in the format
-- 
2.2.0

-- 
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE

reply via email to

[Prev in Thread] Current Thread [Next in Thread]