]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
The *_free SSL API functions can not be used with TidyPointer in some OSes/compilers
authorChristos Tsantilas <chtsanti@users.sourceforge.net>
Mon, 6 Dec 2010 14:12:56 +0000 (16:12 +0200)
committerChristos Tsantilas <chtsanti@users.sourceforge.net>
Mon, 6 Dec 2010 14:12:56 +0000 (16:12 +0200)
The *_free SSL functions are declared as extern "C" and can not be used as
DeAllocator argument of the TidyPointer class with some compilers and OSes.
To solve this problem:

- Define the CtoCpp1 macro to allow easy implementation of the C++ equivalent
  function of an extern C function.
  Currently defined in gadgets.h file, if required in the future can be
  moved to TidyPointer.h file
- Use the CtoCpp macro to define the X509_free_cpp
- Remove the Ssl::BIO_free_wrapper function does not needed any more

src/ssl/gadgets.cc
src/ssl/gadgets.h

index 8926dd072d3d7699c0d8890fe778bf5e3e1327cc..057d3c766cbdaa0296e89a16759ce511fede27a9 100644 (file)
@@ -41,11 +41,6 @@ static bool makeRequest(Ssl::X509_REQ_Pointer & request, Ssl::EVP_PKEY_Pointer c
     return true;
 }
 
-void Ssl::BIO_free_wrapper(BIO * bio)
-{
-    BIO_free(bio);
-}
-
 EVP_PKEY * Ssl::createSslPrivateKey()
 {
     Ssl::EVP_PKEY_Pointer pkey(EVP_PKEY_new());
index 12f8f6d71f4a16310f11bdd7e4a29e2e5d81cc07..b2fb4f1a99a49674780193f6d6a9afb7177e7a1d 100644 (file)
@@ -25,27 +25,49 @@ namespace Ssl
  because they are used by ssl_crtd.
  */
 
-/**
- \ingroup SslCrtdSslAPI
- * Function for BIO delete for Deleter template.
-*/
-void BIO_free_wrapper(BIO * bio);
+// Macro to be used to define the C++ equivalent function of an extern "C" 
+// function. The C++ function suffixed with the _cpp extension
+#define CtoCpp1(function, argument) \
+        extern "C++" inline void function ## _cpp(argument a) { \
+            function(a); \
+        }
 
 /**
  \ingroup SslCrtdSslAPI
  * TidyPointer typedefs for  common SSL objects
  */
-typedef TidyPointer<X509, X509_free> X509_Pointer;
-typedef TidyPointer<EVP_PKEY, EVP_PKEY_free> EVP_PKEY_Pointer;
-typedef TidyPointer<BIGNUM, BN_free> BIGNUM_Pointer;
-typedef TidyPointer<BIO, BIO_free_wrapper> BIO_Pointer;
-typedef TidyPointer<ASN1_INTEGER, ASN1_INTEGER_free> ASN1_INT_Pointer;
-typedef TidyPointer<TXT_DB, TXT_DB_free> TXT_DB_Pointer;
-typedef TidyPointer<X509_NAME, X509_NAME_free> X509_NAME_Pointer;
-typedef TidyPointer<RSA, RSA_free> RSA_Pointer;
-typedef TidyPointer<X509_REQ, X509_REQ_free> X509_REQ_Pointer;
-typedef TidyPointer<SSL_CTX, SSL_CTX_free> SSL_CTX_Pointer;
-typedef  TidyPointer<SSL, SSL_free> SSL_Pointer;
+CtoCpp1(X509_free, X509 *)
+typedef TidyPointer<X509, X509_free_cpp> X509_Pointer;
+
+CtoCpp1(EVP_PKEY_free, EVP_PKEY *)
+typedef TidyPointer<EVP_PKEY, EVP_PKEY_free_cpp> EVP_PKEY_Pointer;
+
+CtoCpp1(BN_free, BIGNUM *)
+typedef TidyPointer<BIGNUM, BN_free_cpp> BIGNUM_Pointer;
+
+CtoCpp1(BIO_free, BIO *)
+typedef TidyPointer<BIO, BIO_free_cpp> BIO_Pointer;
+
+CtoCpp1(ASN1_INTEGER_free, ASN1_INTEGER *)
+typedef TidyPointer<ASN1_INTEGER, ASN1_INTEGER_free_cpp> ASN1_INT_Pointer;
+
+CtoCpp1(TXT_DB_free, TXT_DB *)
+typedef TidyPointer<TXT_DB, TXT_DB_free_cpp> TXT_DB_Pointer;
+
+CtoCpp1(X509_NAME_free, X509_NAME *)
+typedef TidyPointer<X509_NAME, X509_NAME_free_cpp> X509_NAME_Pointer;
+
+CtoCpp1(RSA_free, RSA *)
+typedef TidyPointer<RSA, RSA_free_cpp> RSA_Pointer;
+
+CtoCpp1(X509_REQ_free, X509_REQ *)
+typedef TidyPointer<X509_REQ, X509_REQ_free_cpp> X509_REQ_Pointer;
+
+CtoCpp1(SSL_CTX_free, SSL_CTX *)
+typedef TidyPointer<SSL_CTX, SSL_CTX_free_cpp> SSL_CTX_Pointer;
+
+CtoCpp1(SSL_free, SSL *)
+typedef TidyPointer<SSL, SSL_free_cpp> SSL_Pointer;
 
 
 /**