summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--includes/gnutls/extra.h6
-rw-r--r--libextra/gnutls_extra.c77
-rw-r--r--libextra/libgnutls-extra.m419
3 files changed, 92 insertions, 10 deletions
diff --git a/includes/gnutls/extra.h b/includes/gnutls/extra.h
index dce465ad3f..a0881532be 100644
--- a/includes/gnutls/extra.h
+++ b/includes/gnutls/extra.h
@@ -25,6 +25,8 @@
#include <gnutls/gnutls.h>
+#define LIBGNUTLS_EXTRA_VERSION LIBGNUTLS_VERSION
+
/* SRP */
typedef struct DSTRUCT* gnutls_srp_server_credentials;
@@ -88,6 +90,10 @@ int gnutls_certificate_set_openpgp_keyring_file( gnutls_certificate_credentials
int gnutls_global_init_extra(void);
+/* returns libgnutls-extra version (call it with a NULL argument)
+ */
+const char* gnutls_extra_check_version( const char*);
+
/* Defines for compatibility with previous versions.
*/
#define GNUTLS_SRP_SERVER_CREDENTIALS gnutls_srp_server_credentials
diff --git a/libextra/gnutls_extra.c b/libextra/gnutls_extra.c
index 086272a182..2dab1b5d09 100644
--- a/libextra/gnutls_extra.c
+++ b/libextra/gnutls_extra.c
@@ -138,7 +138,7 @@ static void _gnutls_add_openpgp_functions(void) {
return;
}
-const char* gnutls_check_version( const char*);
+extern const char* gnutls_check_version( const char*);
static int _gnutls_init_extra = 0;
/**
@@ -208,3 +208,78 @@ int ret;
return 0;
}
+
+/* Taken from libgcrypt. Needed to configure scripts.
+ */
+
+static const char*
+parse_version_number( const char *s, int *number )
+{
+ int val = 0;
+
+ if( *s == '0' && isdigit(s[1]) )
+ return NULL; /* leading zeros are not allowed */
+ for ( ; isdigit(*s); s++ ) {
+ val *= 10;
+ val += *s - '0';
+ }
+ *number = val;
+ return val < 0? NULL : s;
+}
+
+/* The parse version functions were copied from libgcrypt.
+ */
+static const char *
+parse_version_string( const char *s, int *major, int *minor, int *micro )
+{
+ s = parse_version_number( s, major );
+ if( !s || *s != '.' )
+ return NULL;
+ s++;
+ s = parse_version_number( s, minor );
+ if( !s || *s != '.' )
+ return NULL;
+ s++;
+ s = parse_version_number( s, micro );
+ if( !s )
+ return NULL;
+ return s; /* patchlevel */
+}
+
+/****************
+ * Check that the the version of the library is at minimum the requested one
+ * and return the version string; return NULL if the condition is not
+ * satisfied. If a NULL is passed to this function, no check is done,
+ * but the version string is simply returned.
+ */
+const char *
+gnutls_extra_check_version( const char *req_version )
+{
+ const char *ver = GNUTLS_VERSION;
+ int my_major, my_minor, my_micro;
+ int rq_major, rq_minor, rq_micro;
+ const char *my_plvl, *rq_plvl;
+
+ if ( !req_version )
+ return ver;
+
+ my_plvl = parse_version_string( ver, &my_major, &my_minor, &my_micro );
+ if ( !my_plvl )
+ return NULL; /* very strange our own version is bogus */
+ rq_plvl = parse_version_string( req_version, &rq_major, &rq_minor,
+ &rq_micro );
+ if ( !rq_plvl )
+ return NULL; /* req version string is invalid */
+
+ if ( my_major > rq_major
+ || (my_major == rq_major && my_minor > rq_minor)
+ || (my_major == rq_major && my_minor == rq_minor
+ && my_micro > rq_micro)
+ || (my_major == rq_major && my_minor == rq_minor
+ && my_micro == rq_micro
+ && strcmp( my_plvl, rq_plvl ) >= 0) ) {
+ return ver;
+ }
+ return NULL;
+}
+
diff --git a/libextra/libgnutls-extra.m4 b/libextra/libgnutls-extra.m4
index 0aca5d3e69..716b0954e6 100644
--- a/libextra/libgnutls-extra.m4
+++ b/libextra/libgnutls-extra.m4
@@ -49,17 +49,17 @@ dnl
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <gnutls/gnutls.h>
+#include <gnutls/extra.h>
int
main ()
{
system ("touch conf.libgnutlstest");
- if( strcmp( gnutls_check_version(NULL), "$libgnutls_extra_config_version" ) )
+ if( strcmp( gnutls_extra_check_version(NULL), "$libgnutls_extra_config_version" ) )
{
printf("\n*** 'libgnutls-extra-config --version' returned %s, but LIBGNUTLS_EXTRA (%s)\n",
- "$libgnutls_extra_config_version", gnutls_check_version(NULL) );
+ "$libgnutls_extra_config_version", gnutls_extra_check_version(NULL) );
printf("*** was found! If libgnutls-extra-config was correct, then it is best\n");
printf("*** to remove the old version of LIBGNUTLS_EXTRA. You may also be able to fix the error\n");
printf("*** by modifying your LD_LIBRARY_PATH enviroment variable, or by editing\n");
@@ -69,21 +69,22 @@ main ()
printf("*** to point to the correct copy of libgnutls-extra-config, and remove the file config.cache\n");
printf("*** before re-running configure\n");
}
- else if ( strcmp(gnutls_check_version(NULL), LIBGNUTLS_EXTRA_VERSION ) )
+ else if ( strcmp(gnutls_extra_check_version(NULL), LIBGNUTLS_EXTRA_VERSION ) )
{
printf("\n*** LIBGNUTLS_EXTRA header file (version %s) does not match\n", LIBGNUTLS_EXTRA_VERSION);
- printf("*** library (version %s)\n", gnutls_check_version(NULL) );
+ printf("*** library (version %s). This is may be due to a different version of gnutls\n", gnutls_extra_check_version(NULL) );
+ printf("*** and gnutls-extra.\n");
}
else
{
- if ( gnutls_check_version( "$min_libgnutls_version" ) )
+ if ( gnutls_extra_check_version( "$min_libgnutls_version" ) )
{
return 0;
}
else
{
printf("no\n*** An old version of LIBGNUTLS_EXTRA (%s) was found.\n",
- gnutls_check_version(NULL) );
+ gnutls_extra_check_version(NULL) );
printf("*** You need a version of LIBGNUTLS_EXTRA newer than %s. The latest version of\n",
"$min_libgnutls_version" );
printf("*** LIBGNUTLS_EXTRA is always available from ftp://gnutls.hellug.gr/pub/gnutls.\n");
@@ -129,8 +130,8 @@ main ()
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <gnutls/gnutls.h>
-], [ return !!gnutls_check_version(NULL); ],
+#include <gnutls/extra.h>
+], [ return !!gnutls_extra_check_version(NULL); ],
[ echo "*** The test program compiled, but did not run. This usually means"
echo "*** that the run-time linker is not finding LIBGNUTLS_EXTRA or finding the wrong"
echo "*** version of LIBGNUTLS_EXTRA. If it is not finding LIBGNUTLS_EXTRA, you'll need to set your"