2006-02-22 Marcus Brinkmann <marcus@g10code.de>
authorMarcus Brinkmann <mb@g10code.com>
Wed, 22 Feb 2006 11:44:16 +0000 (11:44 +0000)
committerMarcus Brinkmann <mb@g10code.com>
Wed, 22 Feb 2006 11:44:16 +0000 (11:44 +0000)
* engine.c (gpgme_engine_check_version): Reimplemented to allow
checking the version correctly even after changing the engine
information.  Bug reported by Stéphane Corthésy.

gpgme/ChangeLog
gpgme/engine.c

index 29113948fffc4630ed90a5281339be415befaa09..cf149c2da8428cbfb22ed06407a6c46c9eee8672 100644 (file)
@@ -1,5 +1,9 @@
 2006-02-22  Marcus Brinkmann  <marcus@g10code.de>
 
+       * engine.c (gpgme_engine_check_version): Reimplemented to allow
+       checking the version correctly even after changing the engine
+       information.  Bug reported by Stéphane Corthésy.
+
        * rungpg.c (read_colon_line): Invoke colon preprocess handler if
        it is set.
        (colon_preprocessor_t): New type.
index a07fcdc410312b28803d32a5e7068a353aa87d7c..d9753568f15b3a2e0725d9a6ef994aaaf0e72754 100644 (file)
@@ -106,14 +106,33 @@ engine_get_req_version (gpgme_protocol_t proto)
 gpgme_error_t
 gpgme_engine_check_version (gpgme_protocol_t proto)
 {
+  gpgme_error_t err;
+  gpgme_engine_info_t info;
   int result;
-  char *engine_version = engine_get_version (proto, NULL);
 
-  result = _gpgme_compare_versions (engine_version,
-                                   engine_get_req_version (proto));
-  if (engine_version)
-    free (engine_version);
+  LOCK (engine_info_lock);
+  info = engine_info;
+  if (!info)
+    {
+      /* Make sure it is initialized.  */
+      UNLOCK (engine_info_lock);
+      err = gpgme_get_engine_info (&info);
+      if (err)
+       return err;
 
+      LOCK (engine_info_lock);
+    }
+
+  while (info && info->protocol != proto)
+    info = info->next;
+
+  if (!info)
+    result = 0;
+  else
+    result = _gpgme_compare_versions (info->version,
+                                     info->req_version);
+
+  UNLOCK (engine_info_lock);
   return result ? 0 : gpg_error (GPG_ERR_INV_ENGINE);
 }