diff options
author | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2002-10-05 07:46:40 +0000 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2002-10-05 07:46:40 +0000 |
commit | c11eec4003581ae95f0b6042ede6add69478a8f2 (patch) | |
tree | 4dfe04d0c74f01ca33e3ee86d3b6accdbbbd2eba /libextra/gnutls_extra.c | |
parent | b779bef09dc1a975ae2c97a96286f36520b4c953 (diff) | |
download | gnutls-c11eec4003581ae95f0b6042ede6add69478a8f2.tar.gz |
Corrected the broken detection of libgnutls-extra. Bug reported by Ivo Timmermans.
Diffstat (limited to 'libextra/gnutls_extra.c')
-rw-r--r-- | libextra/gnutls_extra.c | 77 |
1 files changed, 76 insertions, 1 deletions
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; +} + |