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/13 21:30:32 UTC
svn commit: r943984 - in
/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf: internal/
internal/net/ssl/openssl/ lang/ util/
Author: tabish
Date: Thu May 13 19:30:31 2010
New Revision: 943984
URL: http://svn.apache.org/viewvc?rev=943984&view=rev
Log:
https://issues.apache.org/activemq/browse/AMQCPP-140
Add some code to allow System properties to specify where the SSL Key and Trust stores are located.
Modified:
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/DecafRuntime.cpp
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLContextSpi.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/lang/System.cpp
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/System.h
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Properties.cpp
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Properties.h
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/DecafRuntime.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/DecafRuntime.cpp?rev=943984&r1=943983&r2=943984&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/DecafRuntime.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/DecafRuntime.cpp Thu May 13 19:30:31 2010
@@ -21,6 +21,7 @@
#include <apr_general.h>
#include <apr_pools.h>
+#include <decaf/lang/System.h>
#include <decaf/lang/Thread.h>
#include <decaf/internal/net/Network.h>
@@ -92,7 +93,7 @@ Runtime* Runtime::getRuntime() {
}
////////////////////////////////////////////////////////////////////////////////
-void Runtime::initializeRuntime( int argc DECAF_UNUSED, char **argv DECAF_UNUSED ) {
+void Runtime::initializeRuntime( int argc, char **argv ) {
// Do this for now, once we remove APR we can do this in a way that
// makes more sense.
@@ -101,6 +102,9 @@ void Runtime::initializeRuntime( int arg
// Initialize any Platform specific Threading primitives
Thread::initThreading();
+ // Initialize the System Class to make things like Properties available.
+ System::initSystem( argc, argv );
+
// Initialize the Networking layer.
Network::initializeNetworking();
}
@@ -117,6 +121,10 @@ void Runtime::shutdownRuntime() {
// to be thread safe and require Threading primitives.
Network::shutdownNetworking();
+ // Shutdown the System class so that the Properties and other resources are
+ // cleaned up.
+ System::shutdownSystem();
+
// Threading is the last to by shutdown since most other parts of the Runtime
// need to make use of Thread primitives.
Thread::shutdownThreading();
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLContextSpi.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLContextSpi.cpp?rev=943984&r1=943983&r2=943984&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLContextSpi.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/openssl/OpenSSLContextSpi.cpp Thu May 13 19:30:31 2010
@@ -194,6 +194,14 @@ void OpenSSLContextSpi::providerInit( Se
throw OpenSSLSocketException( __FILE__, __LINE__ );
}
+ // Here we load the configured KeyStore and TrustStore files
+ std::string keyStorePath = System::getenv( "decaf.net.ssl.keyStore" );
+ std::string keyStoreFile = System::getenv( "decaf.net.ssl.keyStoreFile" );
+ std::string keyStorePassword = System::getenv( "decaf.net.ssl.keyStorePassword" );
+ std::string trustStorePath = System::getenv( "decaf.net.ssl.trustStore" );
+ std::string trustStoreFile = System::getenv( "decaf.net.ssl.trustStoreFile" );
+ std::string trustStorePassword = System::getenv( "decaf.net.ssl.trustStorePassword" );
+
// Now seed the OpenSSL RNG.
std::vector<unsigned char> seed( 128 );
random->nextBytes( seed );
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=943984&r1=943983&r2=943984&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 13 19:30:31 2010
@@ -465,6 +465,9 @@ void OpenSSLSocket::verifyServerCert( co
}
};
+ // Store the Certificate to be cleaned up when the method returns
+ Finalizer final( cert );
+
// We check the extensions first since newer x509v3 Certificates are recommended
// to store the FQDN in the dsnName field of the subjectAltName extension. If we
// don't find it there then we can check the commonName field which is where older
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/System.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/System.cpp?rev=943984&r1=943983&r2=943984&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/System.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/System.cpp Thu May 13 19:30:31 2010
@@ -24,6 +24,7 @@
#include <decaf/util/StringTokenizer.h>
#include <decaf/util/StlMap.h>
#include <decaf/util/concurrent/TimeUnit.h>
+#include <decaf/util/Properties.h>
#include <apr.h>
#include <apr_errno.h>
#include <apr_env.h>
@@ -62,10 +63,49 @@ using namespace decaf::internal;
using namespace decaf::lang::exceptions;
////////////////////////////////////////////////////////////////////////////////
+namespace decaf {
+namespace lang {
+
+ class SystemData {
+ public:
+
+ Properties systemProperties;
+
+ public:
+
+ SystemData() : systemProperties() {
+ }
+
+ ~SystemData() {
+ }
+ };
+
+}}
+
+////////////////////////////////////////////////////////////////////////////////
+SystemData* System::sys = NULL;
+
+////////////////////////////////////////////////////////////////////////////////
System::System() {
}
////////////////////////////////////////////////////////////////////////////////
+void System::initSystem( int argc DECAF_UNUSED, char **argv DECAF_UNUSED ) {
+
+ // TODO - Parse out properties specified at the Command Line level.
+
+ // Create the System Data class.
+ System::sys = new SystemData();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void System::shutdownSystem() {
+
+ // Destroy the System Data class.
+ delete System::sys;
+}
+
+////////////////////////////////////////////////////////////////////////////////
AprPool& System::getAprPool() {
static AprPool aprPool;
return aprPool;
@@ -94,6 +134,28 @@ void System::arraycopy( const unsigned c
}
////////////////////////////////////////////////////////////////////////////////
+void System::arraycopy( const short* src, std::size_t srcPos,
+ short* dest, std::size_t destPos, std::size_t length ) {
+
+ if( src == NULL ) {
+ throw NullPointerException(
+ __FILE__, __LINE__, "Given Source Pointer was null." );
+ }
+
+ if( src == NULL ) {
+ throw NullPointerException(
+ __FILE__, __LINE__, "Given Source Pointer was null." );
+ }
+
+ // Now we try and copy, could still segfault.
+ if( src != dest ) {
+ ::memcpy( dest + destPos, src + srcPos, length * sizeof( short ) );
+ } else {
+ ::memmove( dest + destPos, src + srcPos, length * sizeof( short ) );
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
void System::arraycopy( const int* src, std::size_t srcPos,
int* dest, std::size_t destPos, std::size_t length ) {
@@ -116,6 +178,28 @@ void System::arraycopy( const int* src,
}
////////////////////////////////////////////////////////////////////////////////
+void System::arraycopy( const long long* src, std::size_t srcPos,
+ long long* dest, std::size_t destPos, std::size_t length ) {
+
+ if( src == NULL ) {
+ throw NullPointerException(
+ __FILE__, __LINE__, "Given Source Pointer was null." );
+ }
+
+ if( src == NULL ) {
+ throw NullPointerException(
+ __FILE__, __LINE__, "Given Source Pointer was null." );
+ }
+
+ // Now we try and copy, could still segfault.
+ if( src != dest ) {
+ ::memcpy( dest + destPos, src + srcPos, length * sizeof( long long ) );
+ } else {
+ ::memmove( dest + destPos, src + srcPos, length * sizeof( long long ) );
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
void System::unsetenv( const std::string& name ) {
apr_status_t result = APR_SUCCESS;
@@ -375,3 +459,59 @@ int System::availableProcessors() {
return numCpus;
}
+
+////////////////////////////////////////////////////////////////////////////////
+decaf::util::Properties& System::getProperties() {
+ return System::sys->systemProperties;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::string System::getProperty( const std::string& key ) {
+
+ if( key.empty() ) {
+ throw IllegalArgumentException(
+ __FILE__, __LINE__, "Cannot pass an empty key to getProperty." );
+ }
+
+ return System::sys->systemProperties.getProperty( key, "" );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::string System::getProperty( const std::string& key, const std::string& defaultValue ) {
+
+ if( key.empty() ) {
+ throw IllegalArgumentException(
+ __FILE__, __LINE__, "Cannot pass an empty key to getProperty." );
+ }
+
+ return System::sys->systemProperties.getProperty( key, defaultValue );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::string System::setProperty( const std::string& key, const std::string& value ) {
+
+ if( key.empty() ) {
+ throw IllegalArgumentException(
+ __FILE__, __LINE__, "Cannot pass an empty key to setProperty." );
+ }
+
+ if( value == "" ) {
+ return System::clearProperty( key );
+ }
+
+ return System::sys->systemProperties.setProperty( key, value );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::string System::clearProperty( const std::string& key ) {
+
+ if( key.empty() ) {
+ throw IllegalArgumentException(
+ __FILE__, __LINE__, "Cannot pass an empty key to clearProperty." );
+ }
+
+ std::string oldValue = System::sys->systemProperties.getProperty( key, "" );
+ System::sys->systemProperties.remove( key );
+
+ return oldValue;
+}
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/System.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/System.h?rev=943984&r1=943983&r2=943984&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/System.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/System.h Thu May 13 19:30:31 2010
@@ -20,6 +20,7 @@
#include <decaf/util/Config.h>
#include <decaf/util/Map.h>
+#include <decaf/util/Properties.h>
#include <decaf/lang/Exception.h>
#include <decaf/lang/exceptions/NullPointerException.h>
#include <decaf/internal/AprPool.h>
@@ -28,7 +29,20 @@
namespace decaf{
namespace lang{
+ class Runtime;
+ class SystemData;
+
+ /**
+ * The System class provides static methods for accessing system level resources and performing
+ * some system dependent tasks such as looking up environment values and copying memory and arrays.
+ *
+ * @since 1.0
+ */
class DECAF_API System {
+ private:
+
+ static SystemData* sys;
+
protected:
System();
@@ -59,10 +73,71 @@ namespace lang{
*/
static void arraycopy( const unsigned char* src, std::size_t srcPos,
unsigned char* dest, std::size_t destPos, std::size_t length );
+
+ /**
+ * Copies the number of elements specified by length from the source array starting at
+ * the given source offset specified by srcPos to the dest array starting at the given
+ * destination offset given by destPos.
+ *
+ * @param src
+ * The source array to copy from.
+ * @param srcPos
+ * The position in the array to start copying from.
+ * @param dest
+ * The destination array to copy to.
+ * @param destPos
+ * The position in the destination array to start writing at.
+ * @param length
+ * The number of elements to copy from src to dest.
+ *
+ * @throws NullPointerException if src or dest are NULL.
+ */
+ static void arraycopy( const short* src, std::size_t srcPos,
+ short* dest, std::size_t destPos, std::size_t length );
+
+ /**
+ * Copies the number of elements specified by length from the source array starting at
+ * the given source offset specified by srcPos to the dest array starting at the given
+ * destination offset given by destPos.
+ *
+ * @param src
+ * The source array to copy from.
+ * @param srcPos
+ * The position in the array to start copying from.
+ * @param dest
+ * The destination array to copy to.
+ * @param destPos
+ * The position in the destination array to start writing at.
+ * @param length
+ * The number of elements to copy from src to dest.
+ *
+ * @throws NullPointerException if src or dest are NULL.
+ */
static void arraycopy( const int* src, std::size_t srcPos,
int* dest, std::size_t destPos, std::size_t length );
/**
+ * Copies the number of elements specified by length from the source array starting at
+ * the given source offset specified by srcPos to the dest array starting at the given
+ * destination offset given by destPos.
+ *
+ * @param src
+ * The source array to copy from.
+ * @param srcPos
+ * The position in the array to start copying from.
+ * @param dest
+ * The destination array to copy to.
+ * @param destPos
+ * The position in the destination array to start writing at.
+ * @param length
+ * The number of elements to copy from src to dest.
+ *
+ * @throws NullPointerException if src or dest are NULL.
+ */
+ static void arraycopy( const long long* src, std::size_t srcPos,
+ long long* dest, std::size_t destPos, std::size_t length );
+
+ /**
* Enumerates the system environment and returns a map of env variable
* names to the string values they hold.
*
@@ -156,6 +231,77 @@ namespace lang{
*/
static int availableProcessors();
+ /**
+ * Gets the Properties object that holds the Properties accessed from calls to
+ * getProperty and setProperty.
+ *
+ * If the Properties has not yet been created or are not yet initialized then they
+ * will be on the first call to a Properties accessor.
+ *
+ * @returns a reference to the static system Properties object.
+ */
+ static decaf::util::Properties& getProperties();
+
+ /**
+ * Gets the specified System property if set, otherwise returns an empty string.
+ *
+ * If the Properties has not yet been created or are not yet initialized then they
+ * will be on the first call to a Properties accessor.
+
+ * @param key
+ * The key name of the desired system property to retrieve.
+ *
+ * @returns an empty string if the named property is not set, otherwise returns the value.
+ *
+ * @throws IllegalArgumentException if key is an empty string.
+ */
+ static std::string getProperty( const std::string& key );
+
+ /**
+ * Gets the specified System property if set, otherwise returns the specified default value.
+ *
+ * If the Properties has not yet been created or are not yet initialized then they
+ * will be on the first call to a Properties accessor.
+ *
+ * @param key
+ * The key name of the desired system property to retrieve.
+ * @param defaultValue
+ * The default value to return if the key is not set in the System properties.
+ *
+ * @returns the value of the named system property or the defaultValue if the property isn't set..
+ *
+ * @throws IllegalArgumentException if key is an empty string.
+ */
+ static std::string getProperty( const std::string& key, const std::string& defaultValue );
+
+ /**
+ * Sets the System Property to the specified value.
+ *
+ * @param key
+ * The key name of the system property to set to the given value.
+ * @param value
+ * The value to assign to the key.
+ *
+ * @returns the previous value of the property named by key if there was one, otherwise
+ * returns an empty string.
+ *
+ * @throws IllegalArgumentException if key is an empty string.
+ */
+ static std::string setProperty( const std::string& key, const std::string& value );
+
+ /**
+ * Clear any value associated with the system property specified.
+ *
+ * @param key
+ * The key name of the system property to clear.
+ *
+ * @returns the previous value of the property named by key if there was one, otherwise
+ * returns an empty string.
+ *
+ * @throws IllegalArgumentException if key is an empty string.
+ */
+ static std::string clearProperty( const std::string& key );
+
private:
/**
@@ -174,6 +320,13 @@ namespace lang{
*/
static internal::AprPool& getAprPool();
+ private:
+
+ friend class decaf::lang::Runtime;
+
+ static void initSystem( int argc, char **argv );
+ static void shutdownSystem();
+
};
}}
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Properties.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Properties.cpp?rev=943984&r1=943983&r2=943984&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Properties.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Properties.cpp Thu May 13 19:30:31 2010
@@ -193,12 +193,20 @@ std::string Properties::getProperty( con
}
////////////////////////////////////////////////////////////////////////////////
-void Properties::setProperty( const std::string& name,
- const std::string& value ){
+std::string Properties::setProperty( const std::string& name, const std::string& value ){
+
+ std::string oldValue;
synchronized( &( internal->properties ) ) {
+
+ if( internal->properties.containsKey( name ) ) {
+ oldValue = internal->properties.get( name );
+ }
+
internal->properties.put( name, value );
}
+
+ return oldValue;
}
////////////////////////////////////////////////////////////////////////////////
@@ -212,12 +220,18 @@ bool Properties::hasProperty( const std:
}
////////////////////////////////////////////////////////////////////////////////
-void Properties::remove( const std::string& name ){
+std::string Properties::remove( const std::string& name ){
+
+ std::string oldValue;
+
synchronized( &( internal->properties ) ) {
if( this->internal->properties.containsKey( name ) ) {
+ oldValue = this->internal->properties.get( name );
this->internal->properties.remove( name );
}
}
+
+ return oldValue;
}
////////////////////////////////////////////////////////////////////////////////
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Properties.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Properties.h?rev=943984&r1=943983&r2=943984&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Properties.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Properties.h Thu May 13 19:30:31 2010
@@ -82,7 +82,8 @@ namespace util{
Properties& operator= ( const Properties& src );
/**
- * Returns true if the properties object is empty
+ * Returns true if the properties object is empty.
+ *
* @return true if empty
*/
bool isEmpty() const;
@@ -94,44 +95,60 @@ namespace util{
/**
* Looks up the value for the given property.
- * @param name The name of the property to be looked up.
+ *
+ * @param name
+ * The name of the property to be looked up.
+ *
* @return the value of the property with the given name, if it
- * exists. If it does not exist, returns NULL.
+ * exists. If it does not exist, returns NULL.
*/
const char* getProperty( const std::string& name ) const;
/**
* Looks up the value for the given property.
- * @param name the name of the property to be looked up.
- * @param defaultValue The value to be returned if the given
- * property does not exist.
+ *
+ * @param name
+ * The name of the property to be looked up.
+ * @param defaultValue
+ * The value to be returned if the given property does not exist.
+ *
* @return The value of the property specified by <code>name</code>, if it
- * exists, otherwise the <code>defaultValue</code>.
+ * exists, otherwise the <code>defaultValue</code>.
*/
- std::string getProperty( const std::string& name,
- const std::string& defaultValue ) const;
+ std::string getProperty( const std::string& name, const std::string& defaultValue ) const;
/**
* Sets the value for a given property. If the property already
* exists, overwrites the value.
- * @param name The name of the value to be written.
- * @param value The value to be written.
+ *
+ * @param name
+ * The name of the value to be written.
+ * @param value
+ * The value to be written.
+ *
+ * @returns the old value of the property or empty string if not set.
*/
- void setProperty( const std::string& name,
- const std::string& value );
+ std::string setProperty( const std::string& name, const std::string& value );
/**
- * Check to see if the Property exists in the set
- * @param name - property name to check for in this properties set.
+ * Check to see if the Property exists in the set.
+ *
+ * @param name
+ * The property name to check for in this properties set.
+ *
* @return true if property exists, false otherwise.
*/
bool hasProperty( const std::string& name ) const;
/**
* Removes the property with the given name.
- * @param name the name of the property to remove.
+ *
+ * @param name
+ * The name of the property to remove.
+ *
+ * @returns the previous value of the property if set, or empty string.
*/
- void remove( const std::string& name );
+ std::string remove( const std::string& name );
/**
* Returns an enumeration of all the keys in this property list, including distinct keys
@@ -144,10 +161,10 @@ namespace util{
std::vector<std::string> propertyNames() const;
/**
- * Method that serializes the contents of the property map to
- * an array.
+ * Method that serializes the contents of the property map to an array.
+ *
* @return list of pairs where the first is the name and the second
- * is the value.
+ * is the value.
*/
std::vector< std::pair< std::string, std::string > > toArray() const;
@@ -187,8 +204,8 @@ namespace util{
bool equals( const Properties& source ) const;
/**
- * Formats the contents of the Properties Object into a string
- * that can be logged, etc.
+ * Formats the contents of the Properties Object into a string that can be logged, etc.
+ *
* @returns string value of this object.
*/
std::string toString() const;