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/11 22:57:59 UTC
svn commit: r943289 [2/2] - in /activemq/activemq-cpp/trunk/activemq-cpp: ./
src/main/ src/main/decaf/internal/ src/main/decaf/internal/net/
src/main/decaf/internal/net/ssl/ src/main/decaf/internal/net/ssl/openssl/
src/main/decaf/internal/net/tcp/ src/...
Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocketOutputStream.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocketOutputStream.h?rev=943289&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocketOutputStream.h (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocketOutputStream.h Tue May 11 20:57:57 2010
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _DECAF_INTERNAL_NET_SSL_OPENSSL_OPENSSLSOCKETOUTPUTSTREAM_H_
+#define _DECAF_INTERNAL_NET_SSL_OPENSSL_OPENSSLSOCKETOUTPUTSTREAM_H_
+
+#include <decaf/util/Config.h>
+
+#include <decaf/io/OutputStream.h>
+
+namespace decaf {
+namespace internal {
+namespace net {
+namespace ssl {
+namespace openssl {
+
+ class OpenSSLSocket;
+
+ /**
+ * OutputStream implementation used to write data to an OpenSSLSocket instance.
+ *
+ * @since 1.0
+ */
+ class DECAF_API OpenSSLSocketOutputStream : public decaf::io::OutputStream {
+ private:
+
+ OpenSSLSocket* socket;
+ volatile bool closed;
+
+ public:
+
+ OpenSSLSocketOutputStream( OpenSSLSocket* socket );
+
+ virtual ~OpenSSLSocketOutputStream();
+
+ virtual void close() throw( decaf::io::IOException );
+
+ protected:
+
+ virtual void doWriteByte( unsigned char c ) throw ( decaf::io::IOException );
+
+ virtual void doWriteArrayBounded( const unsigned char* buffer, int size, int offset, int length )
+ throw ( decaf::io::IOException,
+ decaf::lang::exceptions::NullPointerException,
+ decaf::lang::exceptions::IndexOutOfBoundsException );
+
+ };
+
+}}}}}
+
+#endif /* _DECAF_INTERNAL_NET_SSL_OPENSSL_OPENSSLSOCKETOUTPUTSTREAM_H_ */
Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocketOutputStream.h
------------------------------------------------------------------------------
svn:eol-style = native
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/tcp/TcpSocket.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/tcp/TcpSocket.cpp?rev=943289&r1=943288&r2=943289&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/tcp/TcpSocket.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/tcp/TcpSocket.cpp Tue May 11 20:57:57 2010
@@ -59,6 +59,22 @@ using namespace decaf::lang;
using namespace decaf::lang::exceptions;
////////////////////////////////////////////////////////////////////////////////
+namespace {
+
+ class SocketFileDescriptor : public FileDescriptor {
+ public:
+
+ SocketFileDescriptor( apr_socket_t* socket ) : FileDescriptor() {
+ apr_os_sock_t osSocket = -1;
+ apr_os_sock_get( &osSocket, socket );
+ this->descriptor = (int)osSocket;
+ }
+
+ };
+
+}
+
+////////////////////////////////////////////////////////////////////////////////
TcpSocket::TcpSocket() throw ( SocketException )
: socketHandle( NULL ),
localAddress( NULL ),
@@ -110,6 +126,9 @@ void TcpSocket::create() throw( decaf::i
// Create the actual socket.
checkResult( apr_socket_create( &socketHandle, AF_INET, SOCK_STREAM,
APR_PROTO_TCP, apr_pool.getAprPool() ) );
+
+ // Initialize the Socket's FileDescriptor
+ this->fd = new SocketFileDescriptor( socketHandle );
}
DECAF_CATCH_RETHROW( decaf::io::IOException )
DECAF_CATCH_EXCEPTION_CONVERT( Exception, decaf::io::IOException )
@@ -441,11 +460,15 @@ void TcpSocket::close() throw( decaf::io
// When connected we first shutdown, which breaks our reads and writes
// then we close to free APR resources.
if( isConnected() ) {
+ // Destory the allocated resources.
apr_socket_shutdown( socketHandle, APR_SHUTDOWN_READWRITE );
apr_socket_close( socketHandle );
- socketHandle = NULL;
- port = 0;
- localPort = 0;
+ delete this->fd;
+
+ // Clear out the member data.
+ this->socketHandle = NULL;
+ this->port = 0;
+ this->localPort = 0;
}
}
DECAF_CATCH_RETHROW( decaf::io::IOException )
@@ -604,8 +627,7 @@ int TcpSocket::read( unsigned char* buff
try{
if( this->isClosed() ){
throw IOException(
- __FILE__, __LINE__,
- "decaf::io::TcpSocketInputStream::read - The Stream has been closed" );
+ __FILE__, __LINE__, "The Stream has been closed" );
}
if( this->inputShutdown == true ) {
@@ -618,8 +640,7 @@ int TcpSocket::read( unsigned char* buff
if( buffer == NULL ) {
throw NullPointerException(
- __FILE__, __LINE__,
- "TcpSocketInputStream::read - Buffer passed is Null" );
+ __FILE__, __LINE__, "Buffer passed is Null" );
}
if( size < 0 ) {
@@ -654,14 +675,13 @@ int TcpSocket::read( unsigned char* buff
if( isClosed() ){
throw IOException(
- __FILE__, __LINE__,
- "decaf::io::TcpSocketInputStream::read - The connection is broken" );
+ __FILE__, __LINE__, "The connection is closed" );
}
if( result != APR_SUCCESS ){
throw IOException(
__FILE__, __LINE__,
- "decaf::net::TcpSocketInputStream::read - %s",
+ "Socket Read Error - %s",
SocketError::getErrorString().c_str() );
}
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/tcp/TcpSocketInputStream.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/tcp/TcpSocketInputStream.h?rev=943289&r1=943288&r2=943289&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/tcp/TcpSocketInputStream.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/tcp/TcpSocketInputStream.h Tue May 11 20:57:57 2010
@@ -43,7 +43,7 @@ namespace tcp {
TcpSocket* socket;
- bool closed;
+ volatile bool closed;
public:
Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/GenericResource.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/GenericResource.h?rev=943289&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/GenericResource.h (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/GenericResource.h Tue May 11 20:57:57 2010
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _DECAF_INTERNAL_UTIL_GENERICRESOURCE_H_
+#define _DECAF_INTERNAL_UTIL_GENERICRESOURCE_H_
+
+#include <decaf/util/Config.h>
+
+#include <decaf/internal/util/Resource.h>
+
+namespace decaf {
+namespace internal {
+namespace util {
+
+ /**
+ * A Generic Resource wraps some type and will delete it when the Resource itself
+ * is deleted.
+ *
+ * @since 1.0
+ */
+ template<typename T>
+ class GenericResource : public Resource {
+ private:
+
+ T* managed;
+
+ public:
+
+ explicit GenericResource( T* value ) : managed( value ) {
+ }
+
+ virtual ~GenericResource() {
+ try{
+ delete managed;
+ } catch(...) {}
+ }
+
+ T* getManaged() const {
+ return this->managed;
+ }
+
+ void setManaged( T* value ) {
+ this->managed = value;
+ }
+
+ };
+
+}}}
+
+#endif /* _DECAF_INTERNAL_UTIL_GENERICRESOURCE_H_ */
Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/GenericResource.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/Resource.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/Resource.cpp?rev=943289&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/Resource.cpp (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/Resource.cpp Tue May 11 20:57:57 2010
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "Resource.h"
+
+using namespace decaf;
+using namespace decaf::internal;
+using namespace decaf::internal::util;
+
+////////////////////////////////////////////////////////////////////////////////
+Resource::~Resource() {
+}
Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/Resource.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/Resource.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/Resource.h?rev=943289&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/Resource.h (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/Resource.h Tue May 11 20:57:57 2010
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _DECAF_INTERNAL_UTIL_RESOURCE_H_
+#define _DECAF_INTERNAL_UTIL_RESOURCE_H_
+
+#include <decaf/util/Config.h>
+
+namespace decaf {
+namespace internal {
+namespace util {
+
+ /**
+ * Interface for all Managed Resources in Decaf, these objects are added to the
+ * Runtime System and are destroyed at shutdown.
+ *
+ * @since 1.0
+ */
+ class DECAF_API Resource {
+ public:
+
+ virtual ~Resource();
+
+ };
+
+}}}
+
+#endif /* _DECAF_INTERNAL_UTIL_RESOURCE_H_ */
Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/Resource.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/ResourceLifecycleManager.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/ResourceLifecycleManager.cpp?rev=943289&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/ResourceLifecycleManager.cpp (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/ResourceLifecycleManager.cpp Tue May 11 20:57:57 2010
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "ResourceLifecycleManager.h"
+
+#include <decaf/lang/Exception.h>
+
+#include <decaf/util/Iterator.h>
+
+using namespace decaf;
+using namespace decaf::internal;
+using namespace decaf::internal::util;
+using namespace decaf::lang;
+using namespace decaf::util;
+
+////////////////////////////////////////////////////////////////////////////////
+ResourceLifecycleManager::ResourceLifecycleManager() : resources() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ResourceLifecycleManager::~ResourceLifecycleManager() {
+ try{
+ this->destroyResources();
+ }
+ DECAF_CATCH_NOTHROW( Exception )
+ DECAF_CATCHALL_NOTHROW()
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ResourceLifecycleManager::addResource( Resource* value ) {
+
+ if( value == NULL ) {
+ return;
+ }
+
+ this->resources.add( value );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ResourceLifecycleManager::destroyResources() {
+
+ try{
+
+ std::auto_ptr< Iterator<Resource*> > iterator( this->resources.iterator() );
+
+ while( iterator->hasNext() ) {
+ delete iterator->next();
+ }
+
+ this->resources.clear();
+ }
+ DECAF_CATCH_RETHROW( Exception )
+ DECAF_CATCHALL_THROW( Exception )
+}
Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/ResourceLifecycleManager.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/ResourceLifecycleManager.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/ResourceLifecycleManager.h?rev=943289&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/ResourceLifecycleManager.h (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/ResourceLifecycleManager.h Tue May 11 20:57:57 2010
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _DECAF_INTERNAL_UTIL_RESOURCELIFECYCLEMANAGER_H_
+#define _DECAF_INTERNAL_UTIL_RESOURCELIFECYCLEMANAGER_H_
+
+#include <decaf/util/Config.h>
+
+#include <decaf/util/StlSet.h>
+#include <decaf/internal/util/Resource.h>
+
+namespace decaf {
+namespace internal {
+namespace util {
+
+ /**
+ *
+ * @since 1.0
+ */
+ class DECAF_API ResourceLifecycleManager {
+ private:
+
+ decaf::util::StlSet<Resource*> resources;
+
+ public:
+
+ ResourceLifecycleManager();
+
+ virtual ~ResourceLifecycleManager();
+
+ virtual void addResource( Resource* value );
+
+ protected:
+
+ virtual void destroyResources();
+
+ };
+
+}}}
+
+#endif /* _DECAF_INTERNAL_UTIL_RESOURCELIFECYCLEMANAGER_H_ */
Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/ResourceLifecycleManager.h
------------------------------------------------------------------------------
svn:eol-style = native
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=943289&r1=943288&r2=943289&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 Tue May 11 20:57:57 2010
@@ -46,8 +46,6 @@ namespace net{
// Factory for creating sockets, if not set a Plan TCP Socket is created
static SocketImplFactory* factory;
- // The actual Socket that this Socket represents.
- mutable SocketImpl* impl;
mutable volatile bool created;
bool connected;
@@ -58,6 +56,11 @@ namespace net{
friend class ServerSocket;
+ protected:
+
+ // The actual Socket that this Socket represents.
+ mutable SocketImpl* impl;
+
public:
/**
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketImpl.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketImpl.cpp?rev=943289&r1=943288&r2=943289&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketImpl.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketImpl.cpp Tue May 11 20:57:57 2010
@@ -24,7 +24,7 @@ using namespace decaf::net;
using namespace decaf::lang;
////////////////////////////////////////////////////////////////////////////////
-SocketImpl::SocketImpl() : port(0), localPort(0), address() {
+SocketImpl::SocketImpl() : port(0), localPort(0), address(), fd(NULL) {
}
////////////////////////////////////////////////////////////////////////////////
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketImpl.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketImpl.h?rev=943289&r1=943288&r2=943289&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketImpl.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketImpl.h Tue May 11 20:57:57 2010
@@ -23,6 +23,7 @@
#include <decaf/io/IOException.h>
#include <decaf/io/InputStream.h>
#include <decaf/io/OutputStream.h>
+#include <decaf/io/FileDescriptor.h>
#include <decaf/net/SocketException.h>
#include <decaf/net/SocketTimeoutException.h>
@@ -41,10 +42,26 @@ namespace net {
class DECAF_API SocketImpl : public SocketOptions {
protected:
+ /**
+ * The remote port that this Socket is connected to.
+ */
int port;
+
+ /**
+ * The port on the Local Machine that this Socket is Bound to.
+ */
int localPort;
+
+ /**
+ * The Remote Address that the Socket is connected to.
+ */
std::string address;
+ /**
+ * The File Descriptor for this Socket.
+ */
+ io::FileDescriptor* fd;
+
public:
SocketImpl();
@@ -229,6 +246,16 @@ namespace net {
}
/**
+ * Gets the FileDescriptor for this Socket, the Object is owned by this Socket and
+ * should not be deleted by the caller.
+ *
+ * @returns a pointer to this Socket's FileDescriptor object.
+ */
+ const decaf::io::FileDescriptor* getFileDescriptor() const {
+ return this->fd;
+ }
+
+ /**
* Gets the value of the local Inet address the Socket is bound to if bound, otherwise
* return the InetAddress ANY value "0.0.0.0".
*
Copied: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ssl/SSLContext.cpp (from r939856, activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ssl/SSLContent.cpp)
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ssl/SSLContext.cpp?p2=activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ssl/SSLContext.cpp&p1=activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ssl/SSLContent.cpp&r1=939856&r2=943289&rev=943289&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ssl/SSLContent.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ssl/SSLContext.cpp Tue May 11 20:57:57 2010
@@ -15,17 +15,97 @@
* limitations under the License.
*/
-#include "SSLContent.h"
+#include "SSLContext.h"
+
+#include <decaf/lang/exceptions/IllegalStateException.h>
+#include <decaf/lang/exceptions/NullPointerException.h>
+
+#include <decaf/net/SocketFactory.h>
+#include <decaf/net/ssl/SSLParameters.h>
+
+#include <decaf/internal/net/ssl/DefaultSSLContext.h>
using namespace decaf;
using namespace decaf::net;
using namespace decaf::net::ssl;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
+using namespace decaf::internal;
+using namespace decaf::internal::net;
+using namespace decaf::internal::net::ssl;
+
+////////////////////////////////////////////////////////////////////////////////
+SSLContext* SSLContext::defaultSSLContext = NULL;
+
+////////////////////////////////////////////////////////////////////////////////
+SSLContext::SSLContext( SSLContextSpi* contextImpl ) : contextImpl( contextImpl ) {
+
+ if( contextImpl == NULL ) {
+ throw NullPointerException(
+ __FILE__, __LINE__, "SSLContextSpi cannot be NULL" );
+ }
+}
////////////////////////////////////////////////////////////////////////////////
-SSLContent::SSLContent() {
+SSLContext::~SSLContext() {
+ try{
+ delete contextImpl;
+ }
+ DECAF_CATCH_NOTHROW( Exception )
+ DECAF_CATCHALL_NOTHROW()
}
////////////////////////////////////////////////////////////////////////////////
-SSLContent::~SSLContent() {
+SSLContext* SSLContext::getDefault() {
+ try{
+ if( SSLContext::defaultSSLContext != NULL ) {
+ return SSLContext::defaultSSLContext;
+ }
+
+ return DefaultSSLContext::getContext();
+ }
+ DECAF_CATCH_RETHROW( IllegalStateException )
+ DECAF_CATCH_EXCEPTION_CONVERT( Exception, IllegalStateException)
+ DECAF_CATCHALL_THROW( IllegalStateException)
}
+////////////////////////////////////////////////////////////////////////////////
+void SSLContext::setDefault( SSLContext* context ) {
+
+ if( context == NULL ) {
+ throw NullPointerException(
+ __FILE__, __LINE__, "SSLContextSpi cannot be NULL" );
+ }
+
+ SSLContext::defaultSSLContext = context;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+SocketFactory* SSLContext::getSocketFactory() {
+ try{
+ return this->contextImpl->providerGetSocketFactory();
+ }
+ DECAF_CATCH_RETHROW( IllegalStateException )
+ DECAF_CATCH_EXCEPTION_CONVERT( Exception, IllegalStateException)
+ DECAF_CATCHALL_THROW( IllegalStateException)
+}
+
+////////////////////////////////////////////////////////////////////////////////
+SSLParameters* SSLContext::getDefaultSSLParameters() {
+ try{
+ return this->contextImpl->providerGetDefaultSSLParameters();
+ }
+ DECAF_CATCH_RETHROW( IllegalStateException )
+ DECAF_CATCH_EXCEPTION_CONVERT( Exception, IllegalStateException)
+ DECAF_CATCHALL_THROW( IllegalStateException)
+}
+
+////////////////////////////////////////////////////////////////////////////////
+SSLParameters* SSLContext::getSupportedSSLParameters() {
+ try{
+ return this->contextImpl->providerGetSupportedSSLParameters();
+ }
+ DECAF_CATCH_RETHROW( IllegalStateException )
+ DECAF_CATCH_EXCEPTION_CONVERT( Exception, IllegalStateException)
+ DECAF_CATCHALL_THROW( IllegalStateException)
+}
Copied: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ssl/SSLContext.h (from r939856, activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ssl/SSLContent.h)
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ssl/SSLContext.h?p2=activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ssl/SSLContext.h&p1=activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ssl/SSLContent.h&r1=939856&r2=943289&rev=943289&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ssl/SSLContent.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ssl/SSLContext.h Tue May 11 20:57:57 2010
@@ -15,28 +15,93 @@
* limitations under the License.
*/
-#ifndef _DECAF_NET_SSL_SSLCONTENT_H_
-#define _DECAF_NET_SSL_SSLCONTENT_H_
+#ifndef _DECAF_NET_SSL_SSLCONTEXT_H_
+#define _DECAF_NET_SSL_SSLCONTEXT_H_
#include <decaf/util/Config.h>
+#include <decaf/net/ssl/SSLContextSpi.h>
+
namespace decaf {
namespace net {
namespace ssl {
/**
+ * Represents on implementation of the Secure Socket Layer for streaming based sockets.
+ *
+ * This class servers a a source of factories to be used to create new SSL Socket instances.
*
* @since 1.0
*/
- class DECAF_API SSLContent {
+ class DECAF_API SSLContext {
+ private:
+
+ static SSLContext* defaultSSLContext;
+
+ SSLContextSpi* contextImpl;
+
+ private:
+
+ SSLContext( const SSLContext& );
+ SSLContext& operator= ( const SSLContext& );
+
public:
- SSLContent();
+ /**
+ * Gets the Default SSLContext.
+ *
+ * The default instance of the SSLContext should be immediately usable without any need
+ * for the client to initialize this context.
+ *
+ * @returns a pointer to the Default SSLContext instance.
+ */
+ static SSLContext* getDefault();
+
+ /**
+ * Sets the default SSLContext to be returned from future calls to getDefault.
+ *
+ * The set SSLContext must be fully initialized and usable. The caller is responsible for
+ * deleting this object before the Library shutdown methods are called.
+ *
+ * @throws NullPointerException if the context passed is NULL.
+ */
+ static void setDefault( SSLContext* context );
+
+ public:
+
+ SSLContext( SSLContextSpi* contextImpl );
+
+ virtual ~SSLContext();
- virtual ~SSLContent();
+ /**
+ * Returns an SocketFactory instance for use with this Context, the SocketFactory is owned
+ * by the Context and should not be deleted by the caller.
+ *
+ * @returns a pointer to this SSLContext's SocketFactory for creating SSLSocket objects.
+ *
+ * @throws IllegalStateException if the SSLContextSpi requires initialization but it
+ * has not yet been initialized.
+ */
+ SocketFactory* getSocketFactory();
+
+ /**
+ * @return a new instance of an SSLParameters object containing the default set
+ * of settings for this SSLContext.
+ *
+ * @throws UnsupportedOperationException if the parameters cannot be retrieved.
+ */
+ SSLParameters* getDefaultSSLParameters();
+
+ /**
+ * @return a new instance of an SSLParameters object containing the complete set
+ * of settings for this SSLContext.
+ *
+ * @throws UnsupportedOperationException if the parameters cannot be retrieved.
+ */
+ SSLParameters* getSupportedSSLParameters();
};
}}}
-#endif /* _DECAF_NET_SSL_SSLCONTENT_H_ */
+#endif /* _DECAF_NET_SSL_SSLCONTEXT_H_ */
Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ssl/SSLContextSpi.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ssl/SSLContextSpi.cpp?rev=943289&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ssl/SSLContextSpi.cpp (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ssl/SSLContextSpi.cpp Tue May 11 20:57:57 2010
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "SSLContextSpi.h"
+
+#include <decaf/net/ssl/SSLSocket.h>
+#include <decaf/net/ssl/SSLSocketFactory.h>
+#include <decaf/net/ssl/SSLParameters.h>
+
+#include <decaf/lang/exceptions/UnsupportedOperationException.h>
+
+#include <memory>
+
+using namespace decaf;
+using namespace decaf::net;
+using namespace decaf::net::ssl;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
+
+////////////////////////////////////////////////////////////////////////////////
+SSLContextSpi::~SSLContextSpi() {
+
+}
+
+////////////////////////////////////////////////////////////////////////////////
+SSLParameters* SSLContextSpi::providerGetSupportedSSLParameters() {
+
+ std::auto_ptr<SSLParameters> params( new SSLParameters() );
+ std::auto_ptr<SocketFactory> factory;
+ std::auto_ptr<SSLSocket> socket;
+
+ try{
+
+ factory.reset( SSLSocketFactory::getDefault() );
+
+ socket.reset( dynamic_cast<SSLSocket*>( factory->createSocket() ) );
+
+ if( socket.get() == NULL ) {
+ return NULL;
+ }
+
+ params->setCipherSuites( socket->getSupportedCipherSuites() );
+ params->setProtocols( socket->getSupportedProtocols() );
+
+ return params.release();
+ }
+ DECAF_CATCH_RETHROW( UnsupportedOperationException )
+ DECAF_CATCH_EXCEPTION_CONVERT( Exception, UnsupportedOperationException )
+ DECAF_CATCHALL_THROW( UnsupportedOperationException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+SSLParameters* SSLContextSpi::providerGetDefaultSSLParameters() {
+
+ std::auto_ptr<SSLParameters> params( new SSLParameters() );
+ std::auto_ptr<SocketFactory> factory;
+ std::auto_ptr<SSLSocket> socket;
+
+ try{
+
+ factory.reset( SSLSocketFactory::getDefault() );
+
+ socket.reset( dynamic_cast<SSLSocket*>( factory->createSocket() ) );
+
+ if( socket.get() == NULL ) {
+ return NULL;
+ }
+
+ params->setCipherSuites( socket->getEnabledCipherSuites() );
+ params->setProtocols( socket->getEnabledProtocols() );
+
+ return params.release();
+ }
+ DECAF_CATCH_RETHROW( UnsupportedOperationException )
+ DECAF_CATCH_EXCEPTION_CONVERT( Exception, UnsupportedOperationException )
+ DECAF_CATCHALL_THROW( UnsupportedOperationException )
+}
Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ssl/SSLContextSpi.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ssl/SSLContextSpi.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ssl/SSLContextSpi.h?rev=943289&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ssl/SSLContextSpi.h (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ssl/SSLContextSpi.h Tue May 11 20:57:57 2010
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _DECAF_NET_SSL_SSLCONTEXTSPI_H_
+#define _DECAF_NET_SSL_SSLCONTEXTSPI_H_
+
+#include <decaf/util/Config.h>
+
+#include <decaf/security/SecureRandom.h>
+
+namespace decaf {
+namespace net {
+
+ class SocketFactory;
+
+namespace ssl {
+
+ class SSLParameters;
+
+ /**
+ * Defines the interface that should be provided by an SSLContext provider.
+ *
+ * @since 1.0
+ */
+ class DECAF_API SSLContextSpi {
+ public:
+
+ virtual ~SSLContextSpi();
+
+ /**
+ * Perform the initialization of this Context.
+ *
+ * @param random
+ * Pointer to an instance of a secure random number generator.
+ *
+ * @throw NullPointerException if the SecureRandom instance is NULL.
+ * @throw KeyManagementException if an error occurs while initializing the context.
+ */
+ virtual void providerInit( security::SecureRandom* random ) = 0;
+
+ /**
+ * Creates a returns a new SSLParameters instance that contains the default settings for
+ * this Providers SSLContext.
+ *
+ * The returned SSLParameters instance is requires to have non-empty values in its ciphersuites
+ * and protocols.
+ *
+ * @returns new SSLParameters instance with the SSLContext defaults.
+ *
+ * @throws UnsupportedOperationException if the defaults cannot be obtained.
+ */
+ virtual SSLParameters* providerGetDefaultSSLParameters();
+
+ /**
+ * Creates and returns a new SSLParameters instance that contains the full set of supported
+ * parameters for this SSL Context.
+ *
+ * The returned SSLParameters instance is requires to have non-empty values in its ciphersuites
+ * and protocols.
+ *
+ * @returns a new SSLParameters instance with the full set of settings that are supported.
+ *
+ * @throws UnsupportedOperationException if the supported parameters cannot be obtained.
+ */
+ virtual SSLParameters* providerGetSupportedSSLParameters();
+
+ /**
+ * Returns a SocketFactory instance that can be used to create new SSLSocket objects.
+ *
+ * The SocketFactory is owned by the Service Provider and should not be destroyed by the caller.
+ *
+ * @returns SocketFactory instance that can be used to create new SSLSockets.
+ *
+ * @throws IllegalStateException if the SSLContextSpi object requires initialization but
+ * has not been initialized yet.
+ */
+ virtual SocketFactory* providerGetSocketFactory() = 0;
+
+ };
+
+}}}
+
+#endif /* _DECAF_NET_SSL_SSLCONTEXTSPI_H_ */
Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ssl/SSLContextSpi.h
------------------------------------------------------------------------------
svn:eol-style = native
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=943289&r1=943288&r2=943289&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 Tue May 11 20:57:57 2010
@@ -17,9 +17,13 @@
#include "SSLSocket.h"
+#include <decaf/lang/exceptions/IllegalArgumentException.h>
+
using namespace decaf;
using namespace decaf::net;
using namespace decaf::net::ssl;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
////////////////////////////////////////////////////////////////////////////////
SSLSocket::SSLSocket() {
@@ -28,3 +32,40 @@ SSLSocket::SSLSocket() {
////////////////////////////////////////////////////////////////////////////////
SSLSocket::~SSLSocket() {
}
+
+////////////////////////////////////////////////////////////////////////////////
+SSLParameters SSLSocket::getSSLParameters() const {
+
+ SSLParameters params( this->getEnabledCipherSuites(),
+ this->getEnabledProtocols() );
+
+ params.setWantClientAuth( this->getWantClientAuth() );
+ params.setNeedClientAuth( this->getNeedClientAuth() );
+
+ return params;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void SSLSocket::setSSLParameters( const SSLParameters& value ) {
+
+ try{
+
+ if( !value.getCipherSuites().empty() ) {
+ this->setEnabledCipherSuites( value.getCipherSuites() );
+ }
+
+ if( !value.getProtocols().empty() ) {
+ this->setEnabledProtocols( value.getProtocols() );
+ }
+
+ if( value.getWantClientAuth() || value.getNeedClientAuth() ) {
+ this->setNeedClientAuth( value.getNeedClientAuth() );
+ this->setWantClientAuth( value.getWantClientAuth() );
+ } else {
+ this->setWantClientAuth( false );
+ }
+ }
+ DECAF_CATCH_RETHROW( IllegalArgumentException )
+ DECAF_CATCH_EXCEPTION_CONVERT( Exception, IllegalArgumentException )
+ DECAF_CATCHALL_THROW( IllegalArgumentException )
+}
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=943289&r1=943288&r2=943289&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 Tue May 11 20:57:57 2010
@@ -21,6 +21,7 @@
#include <decaf/util/Config.h>
#include <decaf/net/Socket.h>
+#include <decaf/net/ssl/SSLParameters.h>
namespace decaf {
namespace net {
@@ -37,6 +38,122 @@ namespace ssl {
virtual ~SSLSocket();
+ public:
+
+ /**
+ * Gets a vector containing the names of all the cipher suites that are supported by this
+ * SSLSocket. Normally not all of these cipher suites will be enabled on the Socket.
+ *
+ * @returns a vector containing the names of all the supported cipher suites.
+ */
+ virtual std::vector<std::string> getSupportedCipherSuites() const = 0;
+
+ /**
+ * Gets a vector containing the names of all the protocols that could be enabled for
+ * this SSLSocket instance.
+ *
+ * @returns a vector containing the names of all the supported protocols.
+ */
+ virtual std::vector<std::string> getSupportedProtocols() const = 0;
+
+ /**
+ * Returns a vector containing the names of all the currently enabled Cipher Suites for
+ * this SSL Socket.
+ *
+ * @return vector of the names of all enabled Cipher Suites.
+ */
+ virtual std::vector<std::string> getEnabledCipherSuites() const = 0;
+
+ /**
+ * Sets the Cipher Suites that are to be enabled on the SSL Socket connection. Each of the
+ * named Cipher Suites must appear in the list of supported cipher suites for this connection
+ * or an exception will be thrown.
+ *
+ * @param suites
+ * An Vector of names for all the Cipher Suites that are to be enabled.
+ *
+ * @throws IllegalArgumentException if the vector is empty or one of the names is invalid.
+ */
+ virtual void setEnabledCipherSuites( const std::vector<std::string>& suites ) = 0;
+
+ /**
+ * Returns a vector containing the names of all the currently enabled Protocols for
+ * this SSL Socket.
+ *
+ * @return vector of the names of all enabled Protocols.
+ */
+ virtual std::vector<std::string> getEnabledProtocols() const = 0;
+
+ /**
+ * Sets the Protocols that are to be enabled on the SSL Socket connection. Each of the
+ * named Protocols must appear in the list of supported protocols suites for this connection
+ * or an exception will be thrown.
+ *
+ * @param protocols
+ * An Vector of names for all the Protocols that are to be enabled.
+ *
+ * @throws IllegalArgumentException if the vector is empty or one of the names is invalid.
+ */
+ virtual void setEnabledProtocols( const std::vector<std::string>& protocols ) = 0;
+
+ /**
+ * Returns an SSLParameters object for this SSLSocket instance.
+ *
+ * The cipherSuites and protocols vectors in the returned SSLParameters reference will
+ * never be empty.
+ *
+ * @returns an SSLParameters object with the settings in use for the SSLSocket.
+ */
+ virtual SSLParameters getSSLParameters() const;
+
+ /**
+ * Sets the SSLParameters for this SSLSocket using the supplied SSLParameters instance.
+ *
+ * If the cipherSutes vector in the SSLParameters instance is not empty them the
+ * setEnabledCipherSuites method is called with that vector, if the protocols vector in
+ * the SSLParameters instance is not empty then the setEnabledProtocols method is called
+ * with that vector. If the needClientAuth value or the wantClientAuth value is true then
+ * the setNeedClientAuth and setWantClientAuth methods are called respectively with a
+ * value of true, otherwise the setWantClientAuth method is called with a value of false.
+ *
+ * @param value
+ * The SSLParameters instance that is used to update this SSLSocket's settings.
+ *
+ * @throws IllegalArgumentException if an error occurs while calling setEnabledCipherSuites
+ * or setEnabledProtocols.
+ */
+ virtual void setSSLParameters( const SSLParameters& value );
+
+ /**
+ * @returns true if the Socket request client Authentication.
+ */
+ virtual bool getWantClientAuth() const = 0;
+
+ /**
+ * Sets whether or not this Socket will request Client Authentication. If set to true the
+ * Socket (when used in server mode) will request that the client authenticate itself, if the
+ * client doesn't send authentication the socket will still allow negotiation to continue.
+ *
+ * @param value
+ * Whether the server socket should request client authentication.
+ */
+ virtual void setWantClientAuth( bool value ) = 0;
+
+ /**
+ * @returns true if the Socket requires client Authentication.
+ */
+ virtual bool getNeedClientAuth() const = 0;
+
+ /**
+ * Sets whether or not this Socket will require Client Authentication. If set to true the
+ * Socket (when used in server mode) will require that the client authenticate itself, if the
+ * client doesn't send authentication the socket will not allow negotiation to continue.
+ *
+ * @param value
+ * Whether the server socket should require client authentication.
+ */
+ virtual void setNeedClientAuth( bool value ) = 0;
+
};
}}}
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ssl/SSLSocketFactory.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ssl/SSLSocketFactory.cpp?rev=943289&r1=943288&r2=943289&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ssl/SSLSocketFactory.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ssl/SSLSocketFactory.cpp Tue May 11 20:57:57 2010
@@ -17,14 +17,21 @@
#include "SSLSocketFactory.h"
+#include <decaf/internal/net/Network.h>
+
+#include <decaf/internal/net/ssl/DefaultSSLContext.h>
#include <decaf/internal/net/ssl/DefaultSSLSocketFactory.h>
using namespace decaf;
using namespace decaf::net;
using namespace decaf::net::ssl;
+using namespace decaf::internal::net;
using namespace decaf::internal::net::ssl;
////////////////////////////////////////////////////////////////////////////////
+SocketFactory* SSLSocketFactory::defaultSocketFactory = NULL;
+
+////////////////////////////////////////////////////////////////////////////////
SSLSocketFactory::SSLSocketFactory() {
}
@@ -34,5 +41,28 @@ SSLSocketFactory::~SSLSocketFactory() {
////////////////////////////////////////////////////////////////////////////////
SocketFactory* SSLSocketFactory::getDefault() {
- return new DefaultSSLSocketFactory( "SSL Support is not enabled in this build." );
+
+ if( SSLSocketFactory::defaultSocketFactory != NULL ) {
+ return SSLSocketFactory::defaultSocketFactory;
+ }
+
+ // Check the DefaultSSLContext to see if any SSL Providers are enabled
+ SSLContext* context = DefaultSSLContext::getContext();
+ if( context != NULL ) {
+
+ // The SSLContext owns the Factory returned here, no need to manage it.
+ SSLSocketFactory::defaultSocketFactory = context->getSocketFactory();
+ }
+
+ // Non found, use the non-functional default one.
+ if( SSLSocketFactory::defaultSocketFactory == NULL ) {
+ SSLSocketFactory::defaultSocketFactory =
+ new DefaultSSLSocketFactory( "SSL Support is not enabled in this build." );
+
+ // Since we created this one we need to make sure it is destroyed when the Network
+ // Runtime is shutdown.
+ Network::getNetworkRuntime()->addAsResource( SSLSocketFactory::defaultSocketFactory );
+ }
+
+ return SSLSocketFactory::defaultSocketFactory;
}
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ssl/SSLSocketFactory.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ssl/SSLSocketFactory.h?rev=943289&r1=943288&r2=943289&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ssl/SSLSocketFactory.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ssl/SSLSocketFactory.h Tue May 11 20:57:57 2010
@@ -35,12 +35,14 @@ namespace ssl {
* @since 1.0
*/
class DECAF_API SSLSocketFactory : public SocketFactory {
- protected:
+ private:
- SSLSocketFactory();
+ static SocketFactory* defaultSocketFactory;
public:
+ SSLSocketFactory();
+
virtual ~SSLSocketFactory();
/**
@@ -52,7 +54,7 @@ namespace ssl {
* that is successful and the object is an instance of SSLSocketFactory, it is made the
* default SSL socket factory.
*
- * Otherwise, this method returns SSLContext::getDefault().getSocketFactory(). If that
+ * Otherwise, this method returns SSLContext::getDefault()->getSocketFactory(). If that
* call fails, an non-functional factory is returned.
*
* @returns the default SSL SocketFactory pointer.
@@ -105,8 +107,7 @@ namespace ssl {
* @throws IOException if an I/O exception occurs while performing this operation.
* @throws UnknownHostException if the host is unknown.
*/
- virtual Socket* createSocket( Socket* socket, std::string host, int port, bool autoClose )
- throw( decaf::io::IOException, decaf::net::UnknownHostException ) = 0;
+ virtual Socket* createSocket( Socket* socket, std::string host, int port, bool autoClose ) = 0;
};
Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/security/SecureRandom.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/security/SecureRandom.cpp?rev=943289&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/security/SecureRandom.cpp (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/security/SecureRandom.cpp Tue May 11 20:57:57 2010
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "SecureRandom.h"
+
+using namespace decaf;
+using namespace decaf::security;
+
+////////////////////////////////////////////////////////////////////////////////
+SecureRandom::SecureRandom() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+SecureRandom::SecureRandom( const std::vector<unsigned char>& seed DECAF_UNUSED ) {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+SecureRandom::~SecureRandom() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void SecureRandom::nextBytes( std::vector<unsigned char>& buf ) {
+ Random::nextBytes( buf );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void SecureRandom::setSeed( unsigned long long seed ) {
+
+ Random::setSeed( seed );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void SecureRandom::setSeed( const std::vector<unsigned char>& seed DECAF_UNUSED ) {
+
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int SecureRandom::next( int bits ) {
+ return Random::next( bits );
+}
Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/security/SecureRandom.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/security/SecureRandom.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/security/SecureRandom.h?rev=943289&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/security/SecureRandom.h (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/security/SecureRandom.h Tue May 11 20:57:57 2010
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _DECAF_SECURITY_SECURERANDOM_H_
+#define _DECAF_SECURITY_SECURERANDOM_H_
+
+#include <decaf/util/Config.h>
+
+#include <decaf/util/Random.h>
+
+namespace decaf {
+namespace security {
+
+ /**
+ * @since 1.0
+ */
+ class DECAF_API SecureRandom : public decaf::util::Random {
+ private:
+
+ public:
+
+ /**
+ * Creates a new instance of a secure random number generator that implements the
+ * default random number algorithm.
+ *
+ * The SecureRandom instance that is created with this constructor is unseeded and
+ * can be seeded by calling the setSeed method. Calls to nextBytes on an unseeded
+ * SecureRandom result in the object seeding itself.
+ */
+ SecureRandom();
+
+ /**
+ * Creates a new instance of a secure random number generator that implements the
+ * default random number algorithm.
+ *
+ * The SecureRandom instance created by this constructor is seeded using the passed
+ * byte array.
+ *
+ * @param seed
+ * The seed bytes to use to seed this secure random number generator.
+ */
+ SecureRandom( const std::vector<unsigned char>& seed );
+
+ virtual ~SecureRandom();
+
+ public: // Virtual Methods
+
+ /**
+ * {@inheritDoc}
+ */
+ virtual void nextBytes( std::vector<unsigned char>& buf );
+
+ /**
+ * {@inheritDoc}
+ */
+ virtual void setSeed( unsigned long long seed );
+
+ /**
+ * Supplements or sets the seed of this secure random number generator, calls to this
+ * method never reduces randomness.
+ *
+ * @param seed
+ * A vector of bytes that is used update the seed of the RNG.
+ */
+ virtual void setSeed( const std::vector<unsigned char>& seed );
+
+ protected: // Virtual method used by all non-virtual methods in Random.
+
+ /**
+ * {@inheritDoc}
+ */
+ virtual int next( int bits );
+
+ };
+
+}}
+
+#endif /* _DECAF_SECURITY_SECURERANDOM_H_ */
Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/security/SecureRandom.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/security/SecureRandomSpi.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/security/SecureRandomSpi.cpp?rev=943289&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/security/SecureRandomSpi.cpp (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/security/SecureRandomSpi.cpp Tue May 11 20:57:57 2010
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "SecureRandomSpi.h"
+
+using namespace decaf;
+using namespace decaf::security;
+
+////////////////////////////////////////////////////////////////////////////////
+SecureRandomSpi::~SecureRandomSpi() {
+}
Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/security/SecureRandomSpi.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/security/SecureRandomSpi.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/security/SecureRandomSpi.h?rev=943289&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/security/SecureRandomSpi.h (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/security/SecureRandomSpi.h Tue May 11 20:57:57 2010
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _DECAF_SECURITY_SECURERANDOMSPI_H_
+#define _DECAF_SECURITY_SECURERANDOMSPI_H_
+
+#include <decaf/util/Config.h>
+
+namespace decaf {
+namespace security {
+
+ /**
+ * Interface class used by Security Service Providers to implement a source of secure random
+ * bytes.
+ *
+ * @since 1.0
+ */
+ class DECAF_API SecureRandomSpi {
+ public:
+
+ virtual ~SecureRandomSpi();
+
+ /**
+ * Reseed the Random Number Generator, the value given supplements the previous seed value
+ * if any instead of replacing it.
+ *
+ * @param seed
+ * The array of bytes used to update the generators seed.
+ * @param size
+ * The size of the passed byte array.
+ */
+ virtual void providerSetSeed( unsigned char* seed, int size ) = 0;
+
+ /**
+ * Generates the number of random bytes specified by the size parameter and write them to
+ * the passed bytes array. The array must have already been allocated and be of the correct
+ * size to prevent segmentation faults.
+ *
+ * @param bytes
+ * The array that will be filled with random bytes equal to size.
+ * @param numBytes
+ * The number of bytes to generate and write into the bytes array.
+ */
+ virtual void providerNextBytes( unsigned char* bytes, int numBytes ) = 0;
+
+ /**
+ * Generates a new set of seed bytes, the returned value may be used to seed another
+ * Random Number Generator. The caller owns the returned array and must delete it.
+ *
+ * @param numBytes
+ * The number of bytes that should be generated for the new seed array.
+ */
+ virtual unsigned char* providerGenerateSeed( int numBytes ) = 0;
+
+ };
+
+}}
+
+#endif /* _DECAF_SECURITY_SECURERANDOMSPI_H_ */
Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/security/SecureRandomSpi.h
------------------------------------------------------------------------------
svn:eol-style = native