[glib-networking/mcatanzaro/base-rebase: 29/38] base: add GTLS_DEBUG to ease debugging



commit 1486ce036bcb2fca9d7517fbc4029e4a5a309fe7
Author: Michael Catanzaro <mcatanzaro igalia com>
Date:   Sun Apr 7 16:48:30 2019 -0500

    base: add GTLS_DEBUG to ease debugging
    
    Port f856e264e917d82131e441f19e73b08a7644cc55

 tls/base/gtlsconnection-base.c | 32 ++++++++++++++++++++++++++++++++
 tls/base/gtlsconnection-base.h |  4 ++++
 2 files changed, 36 insertions(+)
---
diff --git a/tls/base/gtlsconnection-base.c b/tls/base/gtlsconnection-base.c
index e57ea2a..7e46871 100644
--- a/tls/base/gtlsconnection-base.c
+++ b/tls/base/gtlsconnection-base.c
@@ -32,6 +32,7 @@
 #include "gtlsoutputstream.h"
 
 #include <glib/gi18n-lib.h>
+#include <glib/gprintf.h>
 
 /*
  * GTlsConnectionBase is the base abstract implementation of TLS and DTLS
@@ -2129,3 +2130,34 @@ g_tls_connection_base_datagram_based_iface_init (GDatagramBasedInterface *iface)
   iface->condition_check = g_tls_connection_base_condition_check;
   iface->condition_wait = g_tls_connection_base_condition_wait;
 }
+
+void
+GTLS_DEBUG (gpointer    gnutls,
+            const char *message,
+            ...)
+{
+  char *result = NULL;
+  int ret;
+
+  g_assert (G_IS_TLS_CONNECTION (gnutls));
+
+  va_list args;
+  va_start (args, message);
+
+  ret = g_vasprintf (&result, message, args);
+  g_assert (ret > 0);
+
+  if (G_IS_TLS_CLIENT_CONNECTION (gnutls))
+    g_printf ("CLIENT %p: ", gnutls);
+  else if (G_IS_TLS_SERVER_CONNECTION (gnutls))
+    g_printf ("SERVER %p: ", gnutls);
+  else
+    g_assert_not_reached ();
+
+  g_printf ("%s\n", result);
+
+  fflush (stdout);
+
+  g_free (result);
+  va_end (args);
+}
diff --git a/tls/base/gtlsconnection-base.h b/tls/base/gtlsconnection-base.h
index b3a700d..2bea4ad 100644
--- a/tls/base/gtlsconnection-base.h
+++ b/tls/base/gtlsconnection-base.h
@@ -166,6 +166,10 @@ gboolean g_tls_connection_base_ever_handshaked           (GTlsConnectionBase *tl
 gboolean g_tls_connection_base_request_certificate (GTlsConnectionBase  *tls,
                                                     GError             **error);
 
+void GTLS_DEBUG (gpointer    gnutls,
+                 const char *message,
+                 ...);
+
 G_END_DECLS
 
 #endif /* __G_TLS_CONNECTION_BASE_H___ */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]