Do not include the removed file status-table.h
[gpgme.git] / src / version.c
index dd23ccfc4f3736bf5fba82e150a14f18f3c4347d..3aef4045814ea834a9dcc4a9d208b03f3c1e9655 100644 (file)
@@ -22,6 +22,7 @@
 #if HAVE_CONFIG_H
 #include <config.h>
 #endif
+#include <stdlib.h>
 #include <string.h>
 #include <limits.h>
 #include <ctype.h>
 #include "gpgme.h"
 #include "priv-io.h"
 #include "debug.h"
+#include "context.h"
 
-/* For _gpgme_sema_subsystem_init ().  */
+/* For _gpgme_sema_subsystem_init and _gpgme_status_init.  */
 #include "sema.h"
+#include "util.h"
 
 #ifdef HAVE_ASSUAN_H
 #include "assuan.h"
 #endif
 
+#ifdef HAVE_W32_SYSTEM
+#include "windows.h"
+#endif
+
+/* We implement this function, so we have to disable the overriding
+   macro.  */
+#undef gpgme_check_version
+
 \f
 /* Bootstrap the subsystems needed for concurrent operation.  This
    must be done once at startup.  We can not guarantee this using a
@@ -54,21 +65,19 @@ do_subsystem_inits (void)
   if (done)
     return;
 
-  _gpgme_sema_subsystem_init ();
-#ifdef HAVE_ASSUAN_H
-  assuan_set_assuan_log_level (0);
-  assuan_set_assuan_err_source (GPG_ERR_SOURCE_GPGME);
-#endif /*HAVE_ASSUAN_H*/
-  _gpgme_debug_subsystem_init ();
-#if defined(HAVE_W32_SYSTEM) && defined(HAVE_ASSUAN_H)
-  _gpgme_io_subsystem_init ();
+#ifdef HAVE_W32_SYSTEM
   /* We need to make sure that the sockets are initialized.  */
   {
     WSADATA wsadat;
     
     WSAStartup (0x202, &wsadat);
   }
-#endif /*HAVE_W32_SYSTEM && HAVE_ASSUAN_H*/
+#endif
+
+  _gpgme_sema_subsystem_init ();
+  _gpgme_debug_subsystem_init ();
+  _gpgme_io_subsystem_init ();
+  _gpgme_status_init ();
 
   done = 1;
 }
@@ -172,16 +181,51 @@ _gpgme_compare_versions (const char *my_version,
 const char *
 gpgme_check_version (const char *req_version)
 {
+  char *result;
   do_subsystem_inits ();
 
   /* Catch-22: We need to get at least the debug subsystem ready
-     before using the tarce facility.  If we won't the tarce would
+     before using the trace facility.  If we won't the trace would
      automagically initialize the debug system with out the locks
      being initialized and missing the assuan log level setting. */
-  TRACE2 (DEBUG_INIT, "gpgme_check_version: ", 0,
-         "req_version=%s, VERSION=%s", req_version, VERSION);
+  TRACE2 (DEBUG_INIT, "gpgme_check_version", 0,
+         "req_version=%s, VERSION=%s",
+          req_version? req_version:"(null)", VERSION);
  
-  return _gpgme_compare_versions (VERSION, req_version) ? VERSION : NULL;
+  result = _gpgme_compare_versions (VERSION, req_version) ? VERSION : NULL;
+  if (result != NULL)
+    _gpgme_selftest = 0;
+
+  return result;
+}
+
+/* Check the version and also at runtime if the struct layout of the
+   library matches the one of the user.  This is particular useful for
+   Windows targets (-mms-bitfields).  */
+const char *
+gpgme_check_version_internal (const char *req_version,
+                             size_t offset_sig_validity)
+{
+  const char *result;
+
+  result = gpgme_check_version (req_version);
+  if (result == NULL)
+    return result;
+
+  /* Catch-22, see above.  */
+  TRACE2 (DEBUG_INIT, "gpgme_check_version_internal", 0,
+         "req_version=%s, offset_sig_validity=%i",
+         req_version ? req_version : "(null)", offset_sig_validity);
+
+  if (offset_sig_validity != offsetof (struct _gpgme_signature, validity))
+    {
+      TRACE1 (DEBUG_INIT, "gpgme_check_version_internal", 0,
+             "offset_sig_validity mismatch: expected %i",
+             offsetof (struct _gpgme_signature, validity));
+      _gpgme_selftest = GPG_ERR_SELFTEST_FAILED;
+    }
+
+  return result;
 }
 
 \f
@@ -260,7 +304,7 @@ _gpgme_get_program_version (const char *const file_name)
 
   cfd[0].fd = rp[1];
 
-  status = _gpgme_io_spawn (file_name, argv, cfd, NULL);
+  status = _gpgme_io_spawn (file_name, argv, 0, cfd, NULL, NULL, NULL);
   if (status < 0)
     {
       _gpgme_io_close (rp[0]);