Return-Path: Delivered-To: apmail-activemq-commits-archive@www.apache.org Received: (qmail 5935 invoked from network); 13 May 2010 19:30:54 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 13 May 2010 19:30:54 -0000 Received: (qmail 96935 invoked by uid 500); 13 May 2010 19:30:54 -0000 Delivered-To: apmail-activemq-commits-archive@activemq.apache.org Received: (qmail 96914 invoked by uid 500); 13 May 2010 19:30:54 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 96907 invoked by uid 99); 13 May 2010 19:30:54 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 13 May 2010 19:30:54 +0000 X-ASF-Spam-Status: No, hits=-1265.2 required=10.0 tests=ALL_TRUSTED,AWL X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 13 May 2010 19:30:52 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 7806523888FE; Thu, 13 May 2010 19:30:32 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r943984 - in /activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf: internal/ internal/net/ssl/openssl/ lang/ util/ Date: Thu, 13 May 2010 19:30:32 -0000 To: commits@activemq.apache.org From: tabish@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100513193032.7806523888FE@eris.apache.org> 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 #include +#include #include #include @@ -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 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 #include #include +#include #include #include #include @@ -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 #include +#include #include #include #include @@ -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 name, if it - * exists, otherwise the defaultValue. + * exists, otherwise the defaultValue. */ - 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 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;