You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2010/05/27 21:25:27 UTC

svn commit: r948961 - in /activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf: internal/net/ internal/net/ssl/ internal/net/ssl/openssl/ net/ net/ssl/

Author: tabish
Date: Thu May 27 19:25:27 2010
New Revision: 948961

URL: http://svn.apache.org/viewvc?rev=948961&view=rev
Log:
https://issues.apache.org/activemq/browse/AMQCPP-140

Finish the OpenSSLServerSocket class and fill out all the convenience constructors and create methods for Socket based classes.

Modified:
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/DefaultSocketFactory.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/DefaultSocketFactory.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/DefaultSSLSocketFactory.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/DefaultSSLSocketFactory.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLParameters.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLParameters.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLServerSocket.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocket.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocket.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocketFactory.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocketFactory.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/Socket.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/Socket.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketFactory.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ssl/SSLSocket.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ssl/SSLSocket.h

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/DefaultSocketFactory.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/DefaultSocketFactory.cpp?rev=948961&r1=948960&r2=948961&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/DefaultSocketFactory.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/DefaultSocketFactory.cpp Thu May 27 19:25:27 2010
@@ -53,6 +53,55 @@ Socket* DefaultSocketFactory::createSock
 }
 
 ////////////////////////////////////////////////////////////////////////////////
+Socket* DefaultSocketFactory::createSocket( const decaf::net::InetAddress* host, int port )
+    throw( decaf::io::IOException, decaf::net::UnknownHostException ) {
+
+    try {
+
+        // Ensure something is actually passed in for the URI
+        if( host == NULL ) {
+            throw SocketException( __FILE__, __LINE__, "host address not provided" );
+        }
+
+        if( port <= 0 ) {
+            throw SocketException( __FILE__, __LINE__, "valid port not provided" );
+        }
+
+        std::auto_ptr<Socket> socket( new Socket( host, port ) );
+
+        return socket.release();
+    }
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, IOException )
+    DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Socket* DefaultSocketFactory::createSocket( const decaf::net::InetAddress* host, int port,
+                                            const decaf::net::InetAddress* ifAddress, int localPort )
+    throw( decaf::io::IOException, decaf::net::UnknownHostException ) {
+
+    try {
+
+        // Ensure something is actually passed in for the URI
+        if( host == NULL ) {
+            throw SocketException( __FILE__, __LINE__, "host addres not provided" );
+        }
+
+        if( port <= 0 ) {
+            throw SocketException( __FILE__, __LINE__, "valid port not provided" );
+        }
+
+        std::auto_ptr<Socket> socket( new Socket( host, port, ifAddress, localPort ) );
+
+        return socket.release();
+    }
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, IOException )
+    DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
 Socket* DefaultSocketFactory::createSocket( const std::string& hostname, int port )
     throw( decaf::io::IOException, decaf::net::UnknownHostException ) {
 

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/DefaultSocketFactory.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/DefaultSocketFactory.h?rev=948961&r1=948960&r2=948961&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/DefaultSocketFactory.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/DefaultSocketFactory.h Thu May 27 19:25:27 2010
@@ -52,6 +52,19 @@ namespace net {
         /**
          * {@inheritDoc}
          */
+        virtual decaf::net::Socket* createSocket( const decaf::net::InetAddress* host, int port )
+            throw( decaf::io::IOException, decaf::net::UnknownHostException );
+
+        /**
+         * {@inheritDoc}
+         */
+        virtual decaf::net::Socket* createSocket( const decaf::net::InetAddress* host, int port,
+                                                  const decaf::net::InetAddress* ifAddress, int localPort )
+            throw( decaf::io::IOException, decaf::net::UnknownHostException );
+
+        /**
+         * {@inheritDoc}
+         */
         virtual decaf::net::Socket* createSocket( const std::string& name, int port )
             throw( decaf::io::IOException, decaf::net::UnknownHostException );
 

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/DefaultSSLSocketFactory.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/DefaultSSLSocketFactory.cpp?rev=948961&r1=948960&r2=948961&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/DefaultSSLSocketFactory.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/DefaultSSLSocketFactory.cpp Thu May 27 19:25:27 2010
@@ -44,6 +44,21 @@ decaf::net::Socket* DefaultSSLSocketFact
 }
 
 ////////////////////////////////////////////////////////////////////////////////
+Socket* DefaultSSLSocketFactory::createSocket( const decaf::net::InetAddress* host DECAF_UNUSED, int port DECAF_UNUSED )
+    throw( decaf::io::IOException, decaf::net::UnknownHostException ) {
+
+    throw IOException( __FILE__, __LINE__, errorMessage.c_str() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Socket* DefaultSSLSocketFactory::createSocket( const decaf::net::InetAddress* host DECAF_UNUSED, int port DECAF_UNUSED,
+                                               const decaf::net::InetAddress* ifAddress DECAF_UNUSED, int localPort DECAF_UNUSED )
+    throw( decaf::io::IOException, decaf::net::UnknownHostException ) {
+
+    throw IOException( __FILE__, __LINE__, errorMessage.c_str() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
 decaf::net::Socket* DefaultSSLSocketFactory::createSocket( const std::string& name DECAF_UNUSED, int port DECAF_UNUSED )
     throw( decaf::io::IOException, decaf::net::UnknownHostException ) {
 

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/DefaultSSLSocketFactory.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/DefaultSSLSocketFactory.h?rev=948961&r1=948960&r2=948961&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/DefaultSSLSocketFactory.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/DefaultSSLSocketFactory.h Thu May 27 19:25:27 2010
@@ -57,6 +57,19 @@ namespace ssl {
         /**
          * {@inheritDoc}
          */
+        virtual decaf::net::Socket* createSocket( const decaf::net::InetAddress* host, int port )
+            throw( decaf::io::IOException, decaf::net::UnknownHostException );
+
+        /**
+         * {@inheritDoc}
+         */
+        virtual decaf::net::Socket* createSocket( const decaf::net::InetAddress* host, int port,
+                                                  const decaf::net::InetAddress* ifAddress, int localPort )
+            throw( decaf::io::IOException, decaf::net::UnknownHostException );
+
+        /**
+         * {@inheritDoc}
+         */
         virtual decaf::net::Socket* createSocket( const std::string& name, int port )
             throw( decaf::io::IOException, decaf::net::UnknownHostException );
 

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLParameters.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLParameters.cpp?rev=948961&r1=948960&r2=948961&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLParameters.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLParameters.cpp Thu May 27 19:25:27 2010
@@ -98,7 +98,7 @@ void OpenSSLParameters::setEnabledProtoc
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-OpenSSLParameters* OpenSSLParameters::clonse() const {
+OpenSSLParameters* OpenSSLParameters::clone() const {
 
 #ifdef HAVE_OPENSSL
 

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLParameters.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLParameters.h?rev=948961&r1=948960&r2=948961&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLParameters.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLParameters.h Thu May 27 19:25:27 2010
@@ -115,7 +115,7 @@ namespace openssl {
          * Creates a clone of this object such that all settings are transferred to a new
          * instance of an SSL object whose parent is the same SSL_CTX as this object's.
          */
-        OpenSSLParameters* clonse() const;
+        OpenSSLParameters* clone() const;
 
     };
 

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLServerSocket.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLServerSocket.cpp?rev=948961&r1=948960&r2=948961&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLServerSocket.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLServerSocket.cpp Thu May 27 19:25:27 2010
@@ -31,6 +31,7 @@
 #include <decaf/lang/exceptions/IndexOutOfBoundsException.h>
 #include <decaf/internal/net/SocketFileDescriptor.h>
 #include <decaf/internal/net/ssl/openssl/OpenSSLParameters.h>
+#include <decaf/internal/net/ssl/openssl/OpenSSLSocket.h>
 #include <decaf/internal/net/ssl/openssl/OpenSSLSocketException.h>
 
 using namespace decaf;
@@ -89,14 +90,12 @@ OpenSSLServerSocket::~OpenSSLServerSocke
 
 ////////////////////////////////////////////////////////////////////////////////
 std::vector<std::string> OpenSSLServerSocket::getSupportedCipherSuites() const {
-
-    return std::vector<std::string>();
+    return this->parameters->getSupportedCipherSuites();
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 std::vector<std::string> OpenSSLServerSocket::getSupportedProtocols() const {
-
-    return std::vector<std::string>();
+    return this->parameters->getSupportedProtocols();
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -142,5 +141,15 @@ void OpenSSLServerSocket::setWantClientA
 ////////////////////////////////////////////////////////////////////////////////
 Socket* OpenSSLServerSocket::accept() throw( decaf::io::IOException ) {
 
-    return NULL;
+    try{
+
+        std::auto_ptr<OpenSSLSocket> socket( new OpenSSLSocket( this->parameters->clone() ) );
+        this->implAccept( socket.get() );
+        socket->startHandshake();
+
+        return socket.release();
+    }
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, IOException )
+    DECAF_CATCHALL_THROW( IOException )
 }

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocket.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocket.cpp?rev=948961&r1=948960&r2=948961&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocket.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocket.cpp Thu May 27 19:25:27 2010
@@ -101,6 +101,51 @@ OpenSSLSocket::OpenSSLSocket( OpenSSLPar
 }
 
 ////////////////////////////////////////////////////////////////////////////////
+OpenSSLSocket::OpenSSLSocket( OpenSSLParameters* parameters, const InetAddress* address, int port )  :
+    SSLSocket( address, port ), data( new SocketData() ), parameters( parameters ), input( NULL ), output( NULL ) {
+
+    if( parameters == NULL ) {
+        throw NullPointerException(
+            __FILE__, __LINE__, "The OpenSSL Parameters object instance passed was NULL." );
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+OpenSSLSocket::OpenSSLSocket( OpenSSLParameters* parameters, const InetAddress* address, int port,
+                              const InetAddress* localAddress, int localPort ) :
+    SSLSocket( address, port, localAddress, localPort ),
+    data( new SocketData() ), parameters( parameters ), input( NULL ), output( NULL ) {
+
+    if( parameters == NULL ) {
+        throw NullPointerException(
+            __FILE__, __LINE__, "The OpenSSL Parameters object instance passed was NULL." );
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+OpenSSLSocket::OpenSSLSocket( OpenSSLParameters* parameters, const std::string& host, int port ) :
+    SSLSocket( host, port ),
+    data( new SocketData() ), parameters( parameters ), input( NULL ), output( NULL ) {
+
+    if( parameters == NULL ) {
+        throw NullPointerException(
+            __FILE__, __LINE__, "The OpenSSL Parameters object instance passed was NULL." );
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+OpenSSLSocket::OpenSSLSocket( OpenSSLParameters* parameters, const std::string& host, int port,
+                              const InetAddress* localAddress, int localPort ) :
+    SSLSocket( host, port, localAddress, localPort ),
+    data( new SocketData() ), parameters( parameters ), input( NULL ), output( NULL ) {
+
+    if( parameters == NULL ) {
+        throw NullPointerException(
+            __FILE__, __LINE__, "The OpenSSL Parameters object instance passed was NULL." );
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
 OpenSSLSocket::~OpenSSLSocket() {
     try{
 
@@ -256,36 +301,32 @@ void OpenSSLSocket::sendUrgentData( int 
 
 ////////////////////////////////////////////////////////////////////////////////
 std::vector<std::string> OpenSSLSocket::getSupportedCipherSuites() const {
-
-    return std::vector<std::string>();
+    return this->parameters->getSupportedCipherSuites();
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 std::vector<std::string> OpenSSLSocket::getSupportedProtocols() const {
-
-    return std::vector<std::string>();
+    return this->parameters->getSupportedProtocols();
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 std::vector<std::string> OpenSSLSocket::getEnabledCipherSuites() const {
-
-    return std::vector<std::string>();
+    return this->parameters->getEnabledCipherSuites();
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void OpenSSLSocket::setEnabledCipherSuites( const std::vector<std::string>& suites DECAF_UNUSED ) {
-
+void OpenSSLSocket::setEnabledCipherSuites( const std::vector<std::string>& suites ) {
+    this->parameters->setEnabledCipherSuites( suites );
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 std::vector<std::string> OpenSSLSocket::getEnabledProtocols() const {
-
-    return std::vector<std::string>();
+    return this->parameters->getEnabledProtocols();
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void OpenSSLSocket::setEnabledProtocols( const std::vector<std::string>& protocols DECAF_UNUSED ) {
-
+void OpenSSLSocket::setEnabledProtocols( const std::vector<std::string>& protocols ) {
+    this->parameters->setEnabledProtocols( protocols );
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -325,8 +366,6 @@ void OpenSSLSocket::startHandshake() {
                 switch( SSL_get_error( this->parameters->getSSL(), result ) ) {
                     case SSL_ERROR_NONE:
                         verifyServerCert( this->data->commonName );
-                        std::cout << "OpenSSLSocket::startHandshake() - Verified name: "
-                                  << this->data->commonName << std::endl;
                         break;
                     case SSL_ERROR_SSL:
                     case SSL_ERROR_ZERO_RETURN:

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocket.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocket.h?rev=948961&r1=948960&r2=948961&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocket.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocket.h Thu May 27 19:25:27 2010
@@ -59,6 +59,16 @@ namespace openssl {
 
         OpenSSLSocket( OpenSSLParameters* parameters );
 
+        OpenSSLSocket( OpenSSLParameters* parameters, const decaf::net::InetAddress* address, int port );
+
+        OpenSSLSocket( OpenSSLParameters* parameters, const decaf::net::InetAddress* address, int port,
+                       const decaf::net::InetAddress* localAddress, int localPort );
+
+        OpenSSLSocket( OpenSSLParameters* parameters, const std::string& host, int port );
+
+        OpenSSLSocket( OpenSSLParameters* parameters, const std::string& host, int port,
+                       const decaf::net::InetAddress* localAddress, int localPort );
+
         virtual ~OpenSSLSocket();
 
     public:  // Socket Overrides.

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocketFactory.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocketFactory.cpp?rev=948961&r1=948960&r2=948961&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocketFactory.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocketFactory.cpp Thu May 27 19:25:27 2010
@@ -86,6 +86,50 @@ Socket* OpenSSLSocketFactory::createSock
 }
 
 ////////////////////////////////////////////////////////////////////////////////
+Socket* OpenSSLSocketFactory::createSocket( const decaf::net::InetAddress* host, int port )
+    throw( decaf::io::IOException, decaf::net::UnknownHostException ) {
+
+    try{
+
+#ifdef HAVE_OPENSSL
+        // Create a new SSL object for the Socket then create a new unconnected Socket.
+        SSL_CTX* ctx = static_cast<SSL_CTX*>( this->parent->getOpenSSLCtx() );
+        std::auto_ptr<OpenSSLParameters> parameters( new OpenSSLParameters( ctx ) );
+        std::auto_ptr<SSLSocket> socket( new OpenSSLSocket( parameters.release(), host, port ) );
+        return socket.release();
+#else
+        return NULL;
+#endif
+    }
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, IOException )
+    DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Socket* OpenSSLSocketFactory::createSocket( const decaf::net::InetAddress* host, int port,
+                                            const decaf::net::InetAddress* ifAddress, int localPort )
+    throw( decaf::io::IOException, decaf::net::UnknownHostException ) {
+
+    try{
+
+#ifdef HAVE_OPENSSL
+        // Create a new SSL object for the Socket then create a new unconnected Socket.
+        SSL_CTX* ctx = static_cast<SSL_CTX*>( this->parent->getOpenSSLCtx() );
+        std::auto_ptr<OpenSSLParameters> parameters( new OpenSSLParameters( ctx ) );
+        std::auto_ptr<SSLSocket> socket(
+            new OpenSSLSocket( parameters.release(), host, port, ifAddress, localPort ) );
+        return socket.release();
+#else
+        return NULL;
+#endif
+    }
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, IOException )
+    DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
 Socket* OpenSSLSocketFactory::createSocket( const std::string& hostname, int port )
     throw( decaf::io::IOException, decaf::net::UnknownHostException ) {
 
@@ -95,8 +139,7 @@ Socket* OpenSSLSocketFactory::createSock
         // Create a new SSL object for the Socket then create a new unconnected Socket.
         SSL_CTX* ctx = static_cast<SSL_CTX*>( this->parent->getOpenSSLCtx() );
         std::auto_ptr<OpenSSLParameters> parameters( new OpenSSLParameters( ctx ) );
-        std::auto_ptr<SSLSocket> socket( new OpenSSLSocket( parameters.release() ) );
-        socket->connect( hostname, port );
+        std::auto_ptr<SSLSocket> socket( new OpenSSLSocket( parameters.release(), hostname, port ) );
         return socket.release();
 #else
         return NULL;
@@ -118,10 +161,8 @@ Socket* OpenSSLSocketFactory::createSock
         // Create a new SSL object for the Socket then create a new unconnected Socket.
         SSL_CTX* ctx = static_cast<SSL_CTX*>( this->parent->getOpenSSLCtx() );
         std::auto_ptr<OpenSSLParameters> parameters( new OpenSSLParameters( ctx ) );
-        std::auto_ptr<SSLSocket> socket( new OpenSSLSocket( parameters.release() ) );
-        std::string bindAddress = ifAddress == NULL ? "0.0.0.0" : ifAddress->getHostAddress();
-        socket->bind( bindAddress, localPort );
-        socket->connect( hostname, port );
+        std::auto_ptr<SSLSocket> socket(
+            new OpenSSLSocket( parameters.release(), hostname, port, ifAddress, localPort ) );
         return socket.release();
 #else
         return NULL;

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocketFactory.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocketFactory.h?rev=948961&r1=948960&r2=948961&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocketFactory.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocketFactory.h Thu May 27 19:25:27 2010
@@ -54,6 +54,19 @@ namespace openssl {
         /**
          * {@inheritDoc}
          */
+        virtual decaf::net::Socket* createSocket( const decaf::net::InetAddress* host, int port )
+            throw( decaf::io::IOException, decaf::net::UnknownHostException );
+
+        /**
+         * {@inheritDoc}
+         */
+        virtual decaf::net::Socket* createSocket( const decaf::net::InetAddress* host, int port,
+                                                  const decaf::net::InetAddress* ifAddress, int localPort )
+            throw( decaf::io::IOException, decaf::net::UnknownHostException );
+
+        /**
+         * {@inheritDoc}
+         */
         virtual decaf::net::Socket* createSocket( const std::string& hostname, int port )
             throw( decaf::io::IOException, decaf::net::UnknownHostException );
 

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/Socket.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/Socket.cpp?rev=948961&r1=948960&r2=948961&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/Socket.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/Socket.cpp Thu May 27 19:25:27 2010
@@ -57,6 +57,68 @@ Socket::Socket( SocketImpl* impl ) : imp
 }
 
 ////////////////////////////////////////////////////////////////////////////////
+Socket::Socket( const InetAddress* address, int port ) : impl(NULL), created(false), connected(false),
+                                                         closed(false), bound(false),
+                                                         inputShutdown(false), outputShutdown(false){
+
+    if( address == NULL ) {
+        throw NullPointerException(
+            __FILE__, __LINE__, "The InetAddress to connect to cannot be NULL" );
+    }
+
+    if( port < 0 || port > 65535 ) {
+        throw IllegalArgumentException(
+            __FILE__, __LINE__, "Port specified is out of range: %d", port );
+    }
+
+    try{
+
+        if( this->factory != NULL ) {
+            this->impl = factory->createSocketImpl();
+        } else {
+            this->impl = new TcpSocket();
+        }
+
+        this->initSocketImpl( address->getHostAddress(), port, NULL, 0 );
+    }
+    DECAF_CATCH_RETHROW( UnknownHostException )
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, IOException )
+    DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Socket::Socket( const InetAddress* address, int port, const InetAddress* localAddress, int localPort ) :
+    impl(NULL), created(false), connected(false), closed(false), bound(false),
+    inputShutdown(false), outputShutdown(false) {
+
+    if( address == NULL ) {
+        throw NullPointerException(
+            __FILE__, __LINE__, "The InetAddress to connect to cannot be NULL" );
+    }
+
+    if( port < 0 || port > 65535 ) {
+        throw IllegalArgumentException(
+            __FILE__, __LINE__, "Port specified is out of range: %d", port );
+    }
+
+    try{
+
+        if( this->factory != NULL ) {
+            this->impl = factory->createSocketImpl();
+        } else {
+            this->impl = new TcpSocket();
+        }
+
+        this->initSocketImpl( address->getHostAddress(), port, localAddress, localPort );
+    }
+    DECAF_CATCH_RETHROW( UnknownHostException )
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, IOException )
+    DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
 Socket::Socket( const std::string& host, int port ) : impl(NULL), created(false), connected(false),
                                                       closed(false), bound(false),
                                                       inputShutdown(false), outputShutdown(false){

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/Socket.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/Socket.h?rev=948961&r1=948960&r2=948961&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/Socket.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/Socket.h Thu May 27 19:25:27 2010
@@ -83,6 +83,47 @@ namespace net{
         Socket( SocketImpl* impl );
 
         /**
+         * Creates a new Socket instance and connects it to the given address and port.  If
+         * there is a SocketImplFactory set then the SokcetImpl is created using the factory
+         * otherwise the default Socket implementation is used.
+         *
+         * If the host parameter is empty then the loop back address is used.
+         *
+         * @param address
+         *      The address to connect to.
+         * @param port
+         *      The port number to connect to [0...65535]
+         *
+         * @throws UnknownHostException if the host cannot be resolved.
+         * @throws IOException if an I/O error occurs while connecting the Socket.
+         * @throws NullPointerException if the InetAddress instance in NULL.
+         * @throws IllegalArgumentException if the port if not in range [0...65535]
+         */
+        Socket( const InetAddress* address, int port );
+
+        /**
+         * Creates a new Socket instance and connects it to the given address and port.  If
+         * there is a SocketImplFactory set then the SokcetImpl is created using the factory
+         * otherwise the default Socket implementation is used.  The Socket will also bind
+         * to the local address and port specified.
+         *
+         * @param address
+         *      The address to connect to.
+         * @param port
+         *      The port number to connect to [0...65535]
+         * @param localAddress
+         *      The IP address on the local machine to bind to.
+         * @param localPort
+         *      The port on the local machine to bind to.
+         *
+         * @throws UnknownHostException if the host cannot be resolved.
+         * @throws IOException if an I/O error occurs while connecting the Socket.
+         * @throws NullPointerException if the InetAddress instance in NULL.
+         * @throws IllegalArgumentException if the port if not in range [0...65535]
+         */
+        Socket( const InetAddress* address, int port, const InetAddress* localAddress, int localPort );
+
+        /**
          * Creates a new Socket instance and connects it to the given host and port.  If
          * there is a SocketImplFactory set then the SokcetImpl is created using the factory
          * otherwise the default Socket implementation is used.

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketFactory.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketFactory.h?rev=948961&r1=948960&r2=948961&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketFactory.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketFactory.h Thu May 27 19:25:27 2010
@@ -63,6 +63,46 @@ namespace net{
          * port using the configuration of this SocketFactory.
          *
          * @param host
+         *      The host to connect the socket to.
+         * @param port
+         *      The port on the remote host to connect to.
+         *
+         * @return a new Socket object, caller must free this object when done.
+         *
+         * @throws IOException if an I/O error occurs while creating the Socket object.
+         * @throws UnknownHostException if the host name is not known.
+         */
+        virtual Socket* createSocket( const InetAddress* host, int port )
+            throw( decaf::io::IOException, decaf::net::UnknownHostException ) = 0;
+
+        /**
+         * Creates a new Socket object and connects it to the specified remote host and
+         * port using the configuration of this SocketFactory.  The Socket will be bound
+         * to the specified local address and port.
+         *
+         * @param host
+         *      The host to connect the socket to.
+         * @param port
+         *      The port on the remote host to connect to.
+         * @param ifAddress
+         *      The address on the local machine to bind the Socket to.
+         * @param localPort
+         *      The local port to bind the Socket to.
+         *
+         * @return a new Socket object, caller must free this object when done.
+         *
+         * @throws IOException if an I/O error occurs while creating the Socket object.
+         * @throws UnknownHostException if the host name is not known.
+         */
+        virtual Socket* createSocket( const InetAddress* host, int port,
+                                      const InetAddress* ifAddress, int localPort )
+            throw( decaf::io::IOException, decaf::net::UnknownHostException ) = 0;
+
+        /**
+         * Creates a new Socket object and connects it to the specified remote host and
+         * port using the configuration of this SocketFactory.
+         *
+         * @param host
          *      The host name or IP address to connect the socket to.
          * @param port
          *      The port on the remote host to connect to.
@@ -93,7 +133,8 @@ namespace net{
          * @throws IOException if an I/O error occurs while creating the Socket object.
          * @throws UnknownHostException if the host name is not known.
          */
-        virtual Socket* createSocket( const std::string& name, int port, const InetAddress* ifAddress, int localPort )
+        virtual Socket* createSocket( const std::string& name, int port,
+                                      const InetAddress* ifAddress, int localPort )
             throw( decaf::io::IOException, decaf::net::UnknownHostException ) = 0;
 
         /**

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ssl/SSLSocket.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ssl/SSLSocket.cpp?rev=948961&r1=948960&r2=948961&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ssl/SSLSocket.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ssl/SSLSocket.cpp Thu May 27 19:25:27 2010
@@ -26,7 +26,25 @@ using namespace decaf::lang;
 using namespace decaf::lang::exceptions;
 
 ////////////////////////////////////////////////////////////////////////////////
-SSLSocket::SSLSocket() {
+SSLSocket::SSLSocket() : Socket() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+SSLSocket::SSLSocket( const InetAddress* address, int port ) : Socket( address, port ) {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+SSLSocket::SSLSocket( const InetAddress* address, int port, const InetAddress* localAddress, int localPort ) :
+    Socket( address, port, localAddress, localPort ) {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+SSLSocket::SSLSocket( const std::string& host, int port ) : Socket( host, port ) {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+SSLSocket::SSLSocket( const std::string& host, int port, const InetAddress* localAddress, int localPort ) :
+    Socket( host, port, localAddress, localPort ) {
 }
 
 ////////////////////////////////////////////////////////////////////////////////

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ssl/SSLSocket.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ssl/SSLSocket.h?rev=948961&r1=948960&r2=948961&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ssl/SSLSocket.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ssl/SSLSocket.h Thu May 27 19:25:27 2010
@@ -36,6 +36,79 @@ namespace ssl {
 
         SSLSocket();
 
+        /**
+         * Creates a new SSLSocket instance and connects it to the given address and port.
+         *
+         * If the host parameter is empty then the loop back address is used.
+         *
+         * @param address
+         *      The address to connect to.
+         * @param port
+         *      The port number to connect to [0...65535]
+         *
+         * @throws UnknownHostException if the host cannot be resolved.
+         * @throws IOException if an I/O error occurs while connecting the Socket.
+         * @throws NullPointerException if the InetAddress instance in NULL.
+         * @throws IllegalArgumentException if the port if not in range [0...65535]
+         */
+        SSLSocket( const InetAddress* address, int port );
+
+        /**
+         * Creates a new SSLSocket instance and connects it to the given address and port.
+         * The Socket will also bind to the local address and port specified.
+         *
+         * @param address
+         *      The address to connect to.
+         * @param port
+         *      The port number to connect to [0...65535]
+         * @param localAddress
+         *      The IP address on the local machine to bind to.
+         * @param localPort
+         *      The port on the local machine to bind to.
+         *
+         * @throws UnknownHostException if the host cannot be resolved.
+         * @throws IOException if an I/O error occurs while connecting the Socket.
+         * @throws NullPointerException if the InetAddress instance in NULL.
+         * @throws IllegalArgumentException if the port if not in range [0...65535]
+         */
+        SSLSocket( const InetAddress* address, int port, const InetAddress* localAddress, int localPort );
+
+        /**
+         * Creates a new SSLSocket instance and connects it to the given host and port.
+         *
+         * If the host parameter is empty then the loop back address is used.
+         *
+         * @param host
+         *      The host name or IP address to connect to, empty string means loopback.
+         * @param port
+         *      The port number to connect to [0...65535]
+         *
+         * @throws UnknownHostException if the host cannot be resolved.
+         * @throws IOException if an I/O error occurs while connecting the Socket.
+         * @throws IllegalArgumentException if the port if not in range [0...65535]
+         */
+        SSLSocket( const std::string& host, int port );
+
+        /**
+         * Creates a new SSLSocket instance and connects it to the given host and port.
+         *
+         * If the host parameter is empty then the loop back address is used.
+         *
+         * @param host
+         *      The host name or IP address to connect to, empty string means loopback.
+         * @param port
+         *      The port number to connect to [0...65535]
+         * @param localAddress
+         *      The IP address on the local machine to bind to.
+         * @param localPort
+         *      The port on the local machine to bind to.
+         *
+         * @throws UnknownHostException if the host cannot be resolved.
+         * @throws IOException if an I/O error occurs while connecting the Socket.
+         * @throws IllegalArgumentException if the port if not in range [0...65535]
+         */
+        SSLSocket( const std::string& host, int port, const InetAddress* localAddress, int localPort );
+
         virtual ~SSLSocket();
 
     public: