From 85ba7af004edfd8df3d0074442cb5bc7f6094f10 Mon Sep 17 00:00:00 2001 From: "Evgeny Grin (Karlson2k)" Date: Sun, 24 Nov 2024 20:30:24 +0300 Subject: [PATCH] Added TLS lib debug messages printing --- src/incl_priv/mhd_sys_options.h | 11 +++++++++++ src/mhd2/tls_gnu_funcs.c | 25 +++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/src/incl_priv/mhd_sys_options.h b/src/incl_priv/mhd_sys_options.h index bee7a8c7..d4761081 100644 --- a/src/incl_priv/mhd_sys_options.h +++ b/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 diff --git a/src/mhd2/tls_gnu_funcs.c b/src/mhd2/tls_gnu_funcs.c index 18a8c4bf..4cc28c28 100644 --- a/src/mhd2/tls_gnu_funcs.c +++ b/src/mhd2/tls_gnu_funcs.c @@ -58,10 +58,26 @@ # include "tls_dh_params.h" #endif +#ifdef mhd_USE_TLS_DEBUG_MESSAGES +# include /* 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;