version.c

Go to the documentation of this file.
00001 /* version.c --- Version handling.
00002  * Copyright (C) 2002, 2003, 2004  Simon Josefsson
00003  * Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
00004  *
00005  * This file is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU Lesser General Public
00007  * License as published by the Free Software Foundation; either
00008  * version 2.1 of the License, or (at your option) any later version.
00009  *
00010  * This file is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Lesser General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Lesser General Public
00016  * License along with this file; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
00018  *
00019  */
00020 
00021 /* This file is based on src/global.c from Werner Koch's libgcrypt */
00022 
00023 #ifdef HAVE_CONFIG_H
00024 # include "config.h"
00025 #endif
00026 
00027 #include <ctype.h>
00028 #include <string.h>
00029 
00030 #include "stringprep.h"
00031 
00032 static const char *
00033 parse_version_number (const char *s, int *number)
00034 {
00035   int val = 0;
00036 
00037   if (*s == '0' && isdigit (s[1]))
00038     return NULL;                /* leading zeros are not allowed */
00039   for (; isdigit (*s); s++)
00040     {
00041       val *= 10;
00042       val += *s - '0';
00043     }
00044   *number = val;
00045   return val < 0 ? NULL : s;
00046 }
00047 
00048 
00049 static const char *
00050 parse_version_string (const char *s, int *major, int *minor, int *micro)
00051 {
00052   s = parse_version_number (s, major);
00053   if (!s || *s != '.')
00054     return NULL;
00055   s++;
00056   s = parse_version_number (s, minor);
00057   if (!s || *s != '.')
00058     return NULL;
00059   s++;
00060   s = parse_version_number (s, micro);
00061   if (!s)
00062     return NULL;
00063   return s;                     /* patchlevel */
00064 }
00065 
00080 const char *
00081 stringprep_check_version (const char *req_version)
00082 {
00083   const char *ver = VERSION;
00084   int my_major, my_minor, my_micro;
00085   int rq_major, rq_minor, rq_micro;
00086   const char *my_plvl, *rq_plvl;
00087 
00088   if (!req_version)
00089     return ver;
00090 
00091   my_plvl = parse_version_string (ver, &my_major, &my_minor, &my_micro);
00092   if (!my_plvl)
00093     return NULL;                /* very strange our own version is bogus */
00094   rq_plvl = parse_version_string (req_version, &rq_major, &rq_minor,
00095                                   &rq_micro);
00096   if (!rq_plvl)
00097     return NULL;                /* req version string is invalid */
00098 
00099   if (my_major > rq_major
00100       || (my_major == rq_major && my_minor > rq_minor)
00101       || (my_major == rq_major && my_minor == rq_minor
00102           && my_micro > rq_micro)
00103       || (my_major == rq_major && my_minor == rq_minor
00104           && my_micro == rq_micro && strcmp (my_plvl, rq_plvl) >= 0))
00105     {
00106       return ver;
00107     }
00108   return NULL;
00109 }

Generated on Wed Sep 13 10:20:31 2006 for libidn by  doxygen 1.4.7