Avoid using non-portable debian.h
[yaz-moved-to-github.git] / src / init_globals.c
index 0800a4b..5442c4b 100644 (file)
 #include <config.h>
 #endif
 
+#include <yaz/log.h>
+
 #if YAZ_POSIX_THREADS
 #include <pthread.h>
 #endif
+#include <errno.h>
 
 #if HAVE_GNUTLS_H
 #include <gnutls/gnutls.h>
 #endif
 
-#if HAVE_GCRYPT_H
-#include <gcrypt.h>
+#if YAZ_HAVE_XML2
+#include <libxml/parser.h>
+#endif
+
+#if YAZ_HAVE_XSLT
+#include <libxslt/xslt.h>
 #endif
 
 #if YAZ_HAVE_EXSLT
@@ -34,6 +41,7 @@ static pthread_mutex_t yaz_init_mutex = PTHREAD_MUTEX_INITIALIZER;
 #endif
 
 extern void yaz_log_init_globals(void);
+extern void yaz_log_deinit_globals(void);
 
 void yaz_init_globals(void)
 {
@@ -48,18 +56,43 @@ void yaz_init_globals(void)
 #if HAVE_GNUTLS_H
         gnutls_global_init();
 #endif
-#if HAVE_GCRYPT_H
-        /* most likely, GnuTLS has already initialized libgcrypt */
-        if (gcry_control(GCRYCTL_ANY_INITIALIZATION_P) == 0)
-        {
-            gcry_control(GCRYCTL_INITIALIZATION_FINISHED, NULL, 0);
-        }
+#if YAZ_HAVE_XML2
+        xmlInitParser();
+#endif
+#if YAZ_HAVE_XSLT
+        xsltInit();
 #endif
-        yaz_init_flag = 1;
-    }
 #if YAZ_HAVE_EXSLT
-    exsltRegisterAll();
+        exsltRegisterAll();
+#endif
+        yaz_init_flag = 1; /* must be last, before unlocking */
+    }
+#if YAZ_POSIX_THREADS
+    pthread_mutex_unlock(&yaz_init_mutex);
+#endif
+}
+
+void yaz_deinit_globals(void)
+{
+    if (!yaz_init_flag)
+        return;
+#if YAZ_POSIX_THREADS
+    pthread_mutex_lock(&yaz_init_mutex);
+#endif
+    if (yaz_init_flag)
+    {
+        yaz_log_deinit_globals();
+#if HAVE_GNUTLS_H
+        gnutls_global_deinit();
 #endif
+#if YAZ_HAVE_XSLT
+        xsltCleanupGlobals();
+#endif
+#if YAZ_HAVE_XML2
+        xmlCleanupParser();
+#endif
+        yaz_init_flag = 0;
+    }
 #if YAZ_POSIX_THREADS
     pthread_mutex_unlock(&yaz_init_mutex);
 #endif