diff options
author | Simon Josefsson <simon@josefsson.org> | 2010-03-16 10:45:27 +0100 |
---|---|---|
committer | Simon Josefsson <simon@josefsson.org> | 2010-03-16 10:45:27 +0100 |
commit | ccc6caebc0fdcf152be48ef150f9a98007ec7323 (patch) | |
tree | 4af8d2ad324067006274fe60e3eef184b7a2671c /lib | |
parent | 3b3f90198af1c612fa031629846381102a14d663 (diff) | |
download | libtasn1-ccc6caebc0fdcf152be48ef150f9a98007ec7323.tar.gz libtasn1-ccc6caebc0fdcf152be48ef150f9a98007ec7323.tar.bz2 libtasn1-ccc6caebc0fdcf152be48ef150f9a98007ec7323.zip |
asn1_check_version: Simplify.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Makefile.am | 3 | ||||
-rw-r--r-- | lib/parser_aux.c | 87 | ||||
-rw-r--r-- | lib/version.c | 52 |
3 files changed, 54 insertions, 88 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am index 0e37fab..aa6cddb 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -44,7 +44,8 @@ libtasn1_la_SOURCES = \ parser_aux.c \ parser_aux.h \ structure.c \ - structure.h + structure.h \ + version.c libtasn1_la_LDFLAGS = \ -no-undefined \ diff --git a/lib/parser_aux.c b/lib/parser_aux.c index 99da7c3..65d57d0 100644 --- a/lib/parser_aux.c +++ b/lib/parser_aux.c @@ -1095,90 +1095,3 @@ _asn1_set_default_tag (ASN1_TYPE node) return ASN1_SUCCESS; } - - - -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) - return NULL; - if (*s != '.') - { - *micro = 0; - return s; - } - s++; - s = parse_version_number (s, micro); - if (!s) - return NULL; - return s; /* patchlevel */ -} - -/** - * asn1_check_version: - * @req_version: Required version number, or NULL. - * - * Check that 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. - * - * See %ASN1_VERSION for a suitable @req_version string. - * - * Returns: Version string of run-time library, or %NULL if the - * run-time library does not meet the required version number. - */ -const char * -asn1_check_version (const char *req_version) -{ - const char *ver = ASN1_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/lib/version.c b/lib/version.c new file mode 100644 index 0000000..ad7b43e --- /dev/null +++ b/lib/version.c @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2000, 2001, 2004, 2006, 2007, 2008, 2009, 2010 Free + * Software Foundation, Inc. + * + * This file is part of LIBTASN1. + * + * The LIBTASN1 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 + */ + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +#include <string.h> /* for strverscmp */ + +#include "libtasn1.h" + +/** + * asn1_check_version: + * @req_version: Required version number, or %NULL. + * + * Check that 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. + * + * See %ASN1_VERSION for a suitable @req_version string. + * + * Returns: Version string of run-time library, or %NULL if the + * run-time library does not meet the required version number. + */ +const char * +asn1_check_version (const char *req_version) +{ + if (!req_version || strverscmp (req_version, ASN1_VERSION) <= 0) + return ASN1_VERSION; + + return NULL; +} |