[svn] gpgme - r1311 - trunk/gpgme
svn author wk
cvs at cvs.gnupg.org
Tue May 6 10:13:40 CEST 2008
Author: wk
Date: 2008-05-06 10:13:39 +0200 (Tue, 06 May 2008)
New Revision: 1311
Modified:
trunk/gpgme/ChangeLog
trunk/gpgme/version.c
Log:
Allow for engine version lines with a suffix.
Modified: trunk/gpgme/ChangeLog
===================================================================
--- trunk/gpgme/ChangeLog 2008-04-28 18:42:56 UTC (rev 1310)
+++ trunk/gpgme/ChangeLog 2008-05-06 08:13:39 UTC (rev 1311)
@@ -1,3 +1,9 @@
+2008-05-06 Werner Koch <wk at g10code.com>
+
+ * version.c (extract_version_string): New.
+ (_gpgme_get_program_version): Use it to allow for suffixes in the
+ version line.
+
2008-04-28 Werner Koch <wk at g10code.com>
* engine-gpgconf.c (gpgconf_read): Fixed segv. Avoid memmove for
Modified: trunk/gpgme/version.c
===================================================================
--- trunk/gpgme/version.c 2008-04-28 18:42:56 UTC (rev 1310)
+++ trunk/gpgme/version.c 2008-05-06 08:13:39 UTC (rev 1311)
@@ -1,6 +1,6 @@
/* version.c - Version check routines.
Copyright (C) 2000 Werner Koch (dd9jn)
- Copyright (C) 2001, 2002, 2003, 2004, 2005, 2007 g10 Code GmbH
+ Copyright (C) 2001, 2002, 2003, 2004, 2005, 2007, 2008 g10 Code GmbH
This file is part of GPGME.
@@ -187,6 +187,55 @@
#define LINELENGTH 80
+/* Extract the version string of a program from STRING. The version
+ number is expected to be in GNU style format:
+
+ foo 1.2.3
+ foo (bar system) 1.2.3
+ foo 1.2.3 cruft
+ foo (bar system) 1.2.3 cruft.
+
+ Spaces and tabs are skipped and used as delimiters, a term in
+ (nested) parenthesis before the version string is skipped, the
+ version string may consist of any non-space and non-tab characters
+ but needs to bstart with a digit.
+*/
+static const char *
+extract_version_string (const char *string, size_t *r_len)
+{
+ const char *s;
+ int count, len;
+
+ for (s=string; *s; s++)
+ if (*s == ' ' || *s == '\t')
+ break;
+ while (*s == ' ' || *s == '\t')
+ s++;
+ if (*s == '(')
+ {
+ for (count=1, s++; count && *s; s++)
+ if (*s == '(')
+ count++;
+ else if (*s == ')')
+ count--;
+ }
+ /* For robustness we look for a digit. */
+ while ( *s && !(*s >= '0' && *s <= '9') )
+ s++;
+ if (*s >= '0' && *s <= '9')
+ {
+ for (len=0; s[len]; len++)
+ if (s[len] == ' ' || s[len] == '\t')
+ break;
+ }
+ else
+ len = 0;
+
+ *r_len = len;
+ return s;
+}
+
+
/* Retrieve the version number from the --version output of the
program FILE_NAME. */
char *
@@ -243,10 +292,18 @@
if (mark)
{
- mark = strrchr (line, ' ');
+ size_t len;
+ const char *s;
+
+ s = extract_version_string (line, &len);
+ if (!len)
+ return NULL;
+ mark = malloc (len + 1);
if (!mark)
return NULL;
- return strdup (mark + 1);
+ memcpy (mark, s, len);
+ mark[len] = 0;
+ return mark;
}
return NULL;
More information about the Gnupg-commits
mailing list