00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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;
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;
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;
00094 rq_plvl = parse_version_string (req_version, &rq_major, &rq_minor,
00095 &rq_micro);
00096 if (!rq_plvl)
00097 return NULL;
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 }