]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - tools/squidclient/Transport.cc
Source Format Enforcement (#763)
[thirdparty/squid.git] / tools / squidclient / Transport.cc
index 64a81bcea3f8bf1dd85272a01fcf4579a5a4f68a..658da8b48176e1b0d4a9b213534ffdd5b9b459ac 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
+ * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
  *
  * Squid software is distributed under GPLv2+ license and includes
  * contributions from numerous individuals and organizations.
@@ -235,7 +235,7 @@ Transport::Connect()
 }
 
 ssize_t
-Transport::Write(void *buf, size_t len)
+Transport::Write(const void *buf, size_t len)
 {
     if (conn < 0)
         return -1;
@@ -341,6 +341,14 @@ verifyTlsCertificate(gnutls_session_t session)
 }
 #endif
 
+#if USE_GNUTLS
+static void
+gnutlsDebugHandler(int level, const char *msg)
+{
+    debugVerbose(level, "GnuTLS: " << msg);
+}
+#endif
+
 void
 Transport::InitTls()
 {
@@ -348,12 +356,18 @@ Transport::InitTls()
     debugVerbose(3, "Initializing TLS library...");
     // NP: gnutls init is re-entrant and lock-counted with deinit but not thread safe.
     if (gnutls_global_init() != GNUTLS_E_SUCCESS) {
-        std::cerr << "FATAL ERROR: TLS Initialize failed: " << xstrerror() << std::endl;
+        int xerrno = errno;
+        std::cerr << "FATAL ERROR: TLS Initialize failed: " << xstrerr(xerrno) << std::endl;
         exit(1);
     }
 
     Config.tlsEnabled = true;
 
+#if USE_GNUTLS
+    gnutls_global_set_log_function(&gnutlsDebugHandler);
+    gnutls_global_set_log_level(scParams.verbosityLevel);
+#endif
+
     // Initialize for anonymous TLS
     gnutls_anon_allocate_client_credentials(&Config.anonCredentials);