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

Re: [libvirt] [PATCH] Fix detection of GnuTLS 1.x.y



2011/8/3 Eric Blake <eblake redhat com>:
> On 08/03/2011 08:22 AM, Matthias Bolte wrote:
>>
>> Detection based on gnutls_session doesn't work because GnuTLS 2.x.y
>> comes with a compat.h that defines gnutls_session to gnutls_session_t.
>>
>> Instead detect this based on LIBGNUTLS_VERSION_MAJOR.
>> ---
>>  configure.ac |   22 +++++++++++++++-------
>>  1 files changed, 15 insertions(+), 7 deletions(-)
>
> ACK for correctness.
>
> However, I wonder if it is the most efficient.  We aren't using this as a
> Makefile conditional, and LIBGNUTLS_VERSION_MAJOR is available at compile
> time.  That is, I think that we could skip the configure check altogether,
> and just move the #if LIBGNUTLS_VERSION_MAJOR < 2 check into a common header
> used by all files that want to use gnutls in the first place, for a slightly
> smaller and faster configure.

Here's a v2 that does this.

-- 
Matthias Bolte
http://photron.blogspot.com
From 08d8effff6a4413fd8bb562d42a7bc242806ed5a Mon Sep 17 00:00:00 2001
From: Matthias Bolte <matthias bolte googlemail com>
Date: Wed, 3 Aug 2011 18:23:21 +0200
Subject: [PATCH] Fix detection of GnuTLS 1.x.y

Detection based on gnutls_session doesn't work because GnuTLS 2.x.y
comes with a compat.h that defines gnutls_session to gnutls_session_t.

Instead detect this based on LIBGNUTLS_VERSION_MAJOR. Move this from
configure/config.h to gnutls_1_0_compat.h and make sure that all users
include gnutls_1_0_compat.h properly.

Also fix header guard in gnutls_1_0_compat.h.
---
 configure.ac                 |   14 --------------
 src/gnutls_1_0_compat.h      |    8 ++++++++
 tests/virnettlscontexttest.c |    6 +++---
 3 files changed, 11 insertions(+), 17 deletions(-)

diff --git a/configure.ac b/configure.ac
index c8d291b..fe700b9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -834,20 +834,6 @@ fi
 AC_SUBST([GNUTLS_CFLAGS])
 AC_SUBST([GNUTLS_LIBS])
 
-dnl Old versions of GnuTLS uses types like 'gnutls_session' instead
-dnl of 'gnutls_session_t'.  Try to detect this type if defined so
-dnl that we can offer backwards compatibility.
-old_cflags="$CFLAGS"
-old_libs="$LIBS"
-CFLAGS="$CFLAGS $GNUTLS_CFLAGS"
-LIBS="$LIBS $GNUTLS_LIBS"
-AC_CHECK_TYPE([gnutls_session],
-	AC_DEFINE([GNUTLS_1_0_COMPAT],[],
-		[enable GnuTLS 1.0 compatibility macros]),,
-	[#include <gnutls/gnutls.h>])
-CFLAGS="$old_cflags"
-LIBS="$old_libs"
-
 
 dnl Cyrus SASL
 AC_ARG_WITH([sasl],
diff --git a/src/gnutls_1_0_compat.h b/src/gnutls_1_0_compat.h
index fb423f1..fd9cc1c 100644
--- a/src/gnutls_1_0_compat.h
+++ b/src/gnutls_1_0_compat.h
@@ -21,9 +21,17 @@
  */
 
 #ifndef LIBVIRT_GNUTLS_1_0_COMPAT_H__
+# define LIBVIRT_GNUTLS_1_0_COMPAT_H__
 
 # include <config.h>
 
+# include <gnutls/gnutls.h>
+
+/* enable backward compatibility macros for gnutls 1.x.y */
+# if LIBGNUTLS_VERSION_MAJOR < 2
+#  define GNUTLS_1_0_COMPAT
+# endif
+
 # ifdef GNUTLS_1_0_COMPAT
 #  define gnutls_session_t                 gnutls_session
 #  define gnutls_x509_crt_t                gnutls_x509_crt
diff --git a/tests/virnettlscontexttest.c b/tests/virnettlscontexttest.c
index 520b006..ee7b6b4 100644
--- a/tests/virnettlscontexttest.c
+++ b/tests/virnettlscontexttest.c
@@ -23,6 +23,8 @@
 #include <stdlib.h>
 #include <fcntl.h>
 #include <sys/socket.h>
+#include <gnutls/gnutls.h>
+#include <gnutls/x509.h>
 
 #include "testutils.h"
 #include "util.h"
@@ -32,12 +34,10 @@
 #include "virfile.h"
 #include "command.h"
 #include "network.h"
+#include "gnutls_1_0_compat.h"
 
 #if !defined WIN32 && HAVE_LIBTASN1_H && !defined GNUTLS_1_0_COMPAT
 # include <libtasn1.h>
-# include <gnutls/gnutls.h>
-# include <gnutls/x509.h>
-# include "gnutls_1_0_compat.h"
 
 # include "rpc/virnettlscontext.h"
 
-- 
1.7.4.1


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