Sfoglia il codice sorgente

Added TLS lib debug messages printing

Evgeny Grin (Karlson2k) 1 anno fa
parent
commit
85ba7af004
2 ha cambiato i file con 36 aggiunte e 0 eliminazioni
  1. 11 0
      src/incl_priv/mhd_sys_options.h
  2. 25 0
      src/mhd2/tls_gnu_funcs.c

+ 11 - 0
src/incl_priv/mhd_sys_options.h

@@ -466,6 +466,17 @@
         __pragma(runtime_checks("c", restore))
 #endif /* _MSC_FULL_VER */
 
+#ifdef _DEBUG
+#  ifndef MHD_NO_TLS_DEBUG_MESSAGES
+#    ifndef mhd_USE_TLS_DEBUG_MESSAGES
+/**
+ * Enable debugging output on TLS library (if possible)
+ */
+#      define mhd_USE_TLS_DEBUG_MESSAGES    1
+#    endif
+#  endif
+#endif
+
 /* Un-define some HAVE_DECL_* macro if they equal zero.
    This should allow safely use #ifdef in the code.
    Define HAS_DECL_* macros only if matching HAVE_DECL_* macro

+ 25 - 0
src/mhd2/tls_gnu_funcs.c

@@ -58,10 +58,26 @@
 #  include "tls_dh_params.h"
 #endif
 
+#ifdef mhd_USE_TLS_DEBUG_MESSAGES
+#  include <stdio.h> /* For TLS debug printing */
+#endif
+
 struct mhd_TlsGnuDaemonData;    /* Forward declaration */
 
 struct mhd_TlsGnuConnData;      /* Forward declaration */
 
+#ifdef mhd_USE_TLS_DEBUG_MESSAGES
+static void
+mhd_tls_gnu_debug_print (int level, const char *msg)
+{
+  (void) fprintf (stderr, "## GnuTLS %02i: %s",
+                  level,
+                  msg);
+  (void) fflush (stderr);
+}
+
+
+#endif /* mhd_USE_TLS_DEBUG_MESSAGES */
 
 /* ** Global initialisation / de-initialisation ** */
 
@@ -77,12 +93,21 @@ mhd_tls_gnu_global_init (void)
 #endif
   gnutls_lib_inited =
     gnutls_lib_inited && (GNUTLS_E_SUCCESS == gnutls_global_init ());
+
+#ifdef mhd_USE_TLS_DEBUG_MESSAGES
+  gnutls_global_set_log_function (&mhd_tls_gnu_debug_print);
+  gnutls_global_set_log_level (2);
+#endif
 }
 
 
 MHD_INTERNAL void
 mhd_tls_gnu_global_deinit (void)
 {
+#ifdef mhd_USE_TLS_DEBUG_MESSAGES
+  gnutls_global_set_log_level (0);
+#endif
+
   if (gnutls_lib_inited)
     gnutls_global_deinit ();
   gnutls_lib_inited = false;