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 2013/02/11 23:36:09 UTC
svn commit: r1444986 - in
/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net:
Inet4Address.cpp Inet4Address.h Inet6Address.cpp Inet6Address.h
InetAddress.cpp InetAddress.h
Author: tabish
Date: Mon Feb 11 22:36:08 2013
New Revision: 1444986
URL: http://svn.apache.org/r1444986
Log:
Code cleanup
Modified:
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/Inet4Address.cpp
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/Inet4Address.h
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/Inet6Address.cpp
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/Inet6Address.h
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/InetAddress.cpp
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/InetAddress.h
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/Inet4Address.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/Inet4Address.cpp?rev=1444986&r1=1444985&r2=1444986&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/Inet4Address.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/Inet4Address.cpp Mon Feb 11 22:36:08 2013
@@ -25,13 +25,13 @@ Inet4Address::Inet4Address() {
}
////////////////////////////////////////////////////////////////////////////////
-Inet4Address::Inet4Address( const unsigned char* ipAddress, int numBytes ) :
- InetAddress( ipAddress, numBytes ) {
+Inet4Address::Inet4Address(const unsigned char* ipAddress, int numBytes) :
+ InetAddress(ipAddress, numBytes) {
}
////////////////////////////////////////////////////////////////////////////////
-Inet4Address::Inet4Address( const std::string& hostname, const unsigned char* ipAddress, int numBytes ) :
- InetAddress( hostname, ipAddress, numBytes ) {
+Inet4Address::Inet4Address(const std::string& hostname, const unsigned char* ipAddress, int numBytes) :
+ InetAddress(hostname, ipAddress, numBytes) {
}
////////////////////////////////////////////////////////////////////////////////
@@ -40,15 +40,14 @@ Inet4Address::~Inet4Address() {
////////////////////////////////////////////////////////////////////////////////
InetAddress* Inet4Address::clone() const {
-
- return new Inet4Address( *this );
+ return new Inet4Address(*this);
}
////////////////////////////////////////////////////////////////////////////////
bool Inet4Address::isAnyLocalAddress() const {
- for( int ix = 0; ix < 4; ix++ ) {
- if( this->addressBytes[ix] != 0 ) {
+ for (int ix = 0; ix < 4; ix++) {
+ if (this->addressBytes[ix] != 0) {
return false;
}
}
@@ -63,41 +62,40 @@ bool Inet4Address::isLoopbackAddress() c
////////////////////////////////////////////////////////////////////////////////
bool Inet4Address::isMulticastAddress() const {
- return ( this->addressBytes[0] & 0xF0 ) == 0xE0;
+ return (this->addressBytes[0] & 0xF0) == 0xE0;
}
////////////////////////////////////////////////////////////////////////////////
bool Inet4Address::isLinkLocalAddress() const {
- return ( ( this->addressBytes[0] == 169 ) && ( this->addressBytes[1] == 254 ) );
+ return ((this->addressBytes[0] == 169) && (this->addressBytes[1] == 254));
}
////////////////////////////////////////////////////////////////////////////////
bool Inet4Address::isSiteLocalAddress() const {
- return ( this->addressBytes[0] == 10 ) ||
- ( ( this->addressBytes[0] == 172 ) && ( ( this->addressBytes[1] > 15 ) && ( this->addressBytes[1] < 32 ) ) ) ||
- ( ( this->addressBytes[0] == 192 ) && ( this->addressBytes[1] == 168 ) );
+ return (this->addressBytes[0] == 10) || ((this->addressBytes[0] == 172) && ((this->addressBytes[1] > 15) && (this->addressBytes[1] < 32)))
+ || ((this->addressBytes[0] == 192) && (this->addressBytes[1] == 168));
}
////////////////////////////////////////////////////////////////////////////////
bool Inet4Address::isMCGlobal() const {
// Check if we have a prefix of 1110
- if( !isMulticastAddress() ) {
+ if (!isMulticastAddress()) {
return false;
}
- unsigned int address = InetAddress::bytesToInt( addressBytes.get(), 0 );
+ unsigned int address = InetAddress::bytesToInt(addressBytes.get(), 0);
// Now check the boundaries of the global space if we have an address
// that is prefixed by something less than 111000000000000000000001
// it is not multicast. ( < 224.0.1.0)
- if( ( address >> 8 ) < 0xE00001 ) {
+ if ((address >> 8) < 0xE00001) {
return false;
}
// Now check the high boundary which is prefixed by 11101110 = 0xEE. If
// the value is higher than this than it is not MCGlobal ( > 238.255.255.255 )
- if( ( address >> 24 ) > 0xEE ) {
+ if ((address >> 24) > 0xEE) {
return false;
}
@@ -106,23 +104,22 @@ bool Inet4Address::isMCGlobal() const {
////////////////////////////////////////////////////////////////////////////////
bool Inet4Address::isMCNodeLocal() const {
-
// Never true for IPV4
return false;
}
////////////////////////////////////////////////////////////////////////////////
bool Inet4Address::isMCLinkLocal() const {
- return ( InetAddress::bytesToInt( addressBytes.get(), 0 ) >> 8 ) == 0xE00000;
+ return (InetAddress::bytesToInt(addressBytes.get(), 0) >> 8) == 0xE00000;
}
////////////////////////////////////////////////////////////////////////////////
bool Inet4Address::isMCSiteLocal() const {
- return ( InetAddress::bytesToInt( addressBytes.get(), 0 ) >> 16 ) == 0xEFFF;
+ return (InetAddress::bytesToInt(addressBytes.get(), 0) >> 16) == 0xEFFF;
}
////////////////////////////////////////////////////////////////////////////////
bool Inet4Address::isMCOrgLocal() const {
- unsigned int prefix = InetAddress::bytesToInt( addressBytes.get(), 0 ) >> 16;
+ unsigned int prefix = InetAddress::bytesToInt(addressBytes.get(), 0) >> 16;
return prefix >= 0xEFC0 && prefix <= 0xEFC3;
}
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/Inet4Address.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/Inet4Address.h?rev=1444986&r1=1444985&r2=1444986&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/Inet4Address.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/Inet4Address.h Mon Feb 11 22:36:08 2013
@@ -25,7 +25,7 @@
namespace decaf {
namespace net {
- class DECAF_API Inet4Address : public InetAddress {
+ class DECAF_API Inet4Address: public InetAddress {
private:
friend class InetAddress;
@@ -33,8 +33,8 @@ namespace net {
protected:
Inet4Address();
- Inet4Address( const unsigned char* ipAddress, int numBytes );
- Inet4Address( const std::string& hostname, const unsigned char* ipAddress, int numBytes );
+ Inet4Address(const unsigned char* ipAddress, int numBytes);
+ Inet4Address(const std::string& hostname, const unsigned char* ipAddress, int numBytes);
public:
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/Inet6Address.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/Inet6Address.cpp?rev=1444986&r1=1444985&r2=1444986&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/Inet6Address.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/Inet6Address.cpp Mon Feb 11 22:36:08 2013
@@ -25,13 +25,12 @@ Inet6Address::Inet6Address() {
}
////////////////////////////////////////////////////////////////////////////////
-Inet6Address::Inet6Address( const unsigned char* ipAddress, int numBytes ) :
- InetAddress( ipAddress, numBytes ) {
+Inet6Address::Inet6Address(const unsigned char* ipAddress, int numBytes) : InetAddress(ipAddress, numBytes) {
}
////////////////////////////////////////////////////////////////////////////////
-Inet6Address::Inet6Address( const std::string& hostname, const unsigned char* ipAddress, int numBytes ) :
- InetAddress( hostname, ipAddress, numBytes ) {
+Inet6Address::Inet6Address(const std::string& hostname, const unsigned char* ipAddress, int numBytes) :
+ InetAddress(hostname, ipAddress, numBytes) {
}
////////////////////////////////////////////////////////////////////////////////
@@ -40,6 +39,5 @@ Inet6Address::~Inet6Address() {
////////////////////////////////////////////////////////////////////////////////
InetAddress* Inet6Address::clone() const {
-
return NULL;
}
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/Inet6Address.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/Inet6Address.h?rev=1444986&r1=1444985&r2=1444986&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/Inet6Address.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/Inet6Address.h Mon Feb 11 22:36:08 2013
@@ -25,7 +25,7 @@
namespace decaf {
namespace net {
- class DECAF_API Inet6Address : public InetAddress {
+ class DECAF_API Inet6Address: public InetAddress {
private:
friend class InetAddress;
@@ -33,8 +33,8 @@ namespace net {
protected:
Inet6Address();
- Inet6Address( const unsigned char* ipAddress, int numBytes );
- Inet6Address( const std::string& hostname, const unsigned char* ipAddress, int numBytes );
+ Inet6Address(const unsigned char* ipAddress, int numBytes);
+ Inet6Address(const std::string& hostname, const unsigned char* ipAddress, int numBytes);
public:
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/InetAddress.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/InetAddress.cpp?rev=1444986&r1=1444985&r2=1444986&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/InetAddress.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/InetAddress.cpp Mon Feb 11 22:36:08 2013
@@ -42,41 +42,37 @@ InetAddress::InetAddress() : hostname(),
}
////////////////////////////////////////////////////////////////////////////////
-InetAddress::InetAddress( const unsigned char* ipAddress, int numBytes ) :
- hostname(), reached(false), addressBytes() {
+InetAddress::InetAddress(const unsigned char* ipAddress, int numBytes) :
+ hostname(), reached(false), addressBytes() {
- if( ipAddress == NULL ) {
- throw NullPointerException(
- __FILE__, __LINE__, "InetAddress constructor called with null address array." );
+ if (ipAddress == NULL) {
+ throw NullPointerException(__FILE__, __LINE__, "InetAddress constructor called with null address array.");
}
- if( numBytes < 0 ) {
- throw IllegalArgumentException(
- __FILE__, __LINE__, "Number of bytes value is invalid: %d", numBytes );
+ if (numBytes < 0) {
+ throw IllegalArgumentException(__FILE__, __LINE__, "Number of bytes value is invalid: %d", numBytes);
}
unsigned char* copy = new unsigned char[numBytes];
- System::arraycopy( ipAddress, 0, copy, 0, numBytes );
- this->addressBytes.reset( copy, numBytes );
+ System::arraycopy(ipAddress, 0, copy, 0, numBytes);
+ this->addressBytes.reset(copy, numBytes);
}
////////////////////////////////////////////////////////////////////////////////
-InetAddress::InetAddress( const std::string& hostname, const unsigned char* ipAddress, int numBytes ) :
- hostname(hostname), reached(false), addressBytes() {
+InetAddress::InetAddress(const std::string& hostname, const unsigned char* ipAddress, int numBytes) :
+ hostname(hostname), reached(false), addressBytes() {
- if( ipAddress == NULL ) {
- throw NullPointerException(
- __FILE__, __LINE__, "InetAddress constructor called with null address array." );
+ if (ipAddress == NULL) {
+ throw NullPointerException(__FILE__, __LINE__, "InetAddress constructor called with null address array.");
}
- if( numBytes < 0 ) {
- throw IllegalArgumentException(
- __FILE__, __LINE__, "Number of bytes value is invalid: %d", numBytes );
+ if (numBytes < 0) {
+ throw IllegalArgumentException(__FILE__, __LINE__, "Number of bytes value is invalid: %d", numBytes);
}
unsigned char* copy = new unsigned char[numBytes];
- System::arraycopy( ipAddress, 0, copy, 0, numBytes );
- this->addressBytes.reset( copy, numBytes );
+ System::arraycopy(ipAddress, 0, copy, 0, numBytes);
+ this->addressBytes.reset(copy, numBytes);
}
////////////////////////////////////////////////////////////////////////////////
@@ -85,8 +81,7 @@ InetAddress::~InetAddress() {
////////////////////////////////////////////////////////////////////////////////
InetAddress* InetAddress::clone() const {
-
- return new InetAddress( *this );
+ return new InetAddress(*this);
}
////////////////////////////////////////////////////////////////////////////////
@@ -99,10 +94,10 @@ std::string InetAddress::getHostAddress(
std::string address;
- for( int ix = 0; ix < this->addressBytes.length(); ix++ ) {
- address.append( Byte::toString( addressBytes[ix] ) );
+ for (int ix = 0; ix < this->addressBytes.length(); ix++) {
+ address.append(Byte::toString(addressBytes[ix]));
- if( ix < this->addressBytes.length() - 1 ) {
+ if (ix < this->addressBytes.length() - 1) {
address.append(".");
}
}
@@ -112,7 +107,7 @@ std::string InetAddress::getHostAddress(
////////////////////////////////////////////////////////////////////////////////
std::string InetAddress::getHostName() const {
- if( !this->hostname.empty() ) {
+ if (!this->hostname.empty()) {
return this->hostname;
}
@@ -125,72 +120,70 @@ std::string InetAddress::toString() cons
}
////////////////////////////////////////////////////////////////////////////////
-InetAddress InetAddress::getByAddress( const std::string& hostname, const unsigned char* bytes, int numBytes ) {
+InetAddress InetAddress::getByAddress(const std::string& hostname, const unsigned char* bytes, int numBytes) {
- if( numBytes == 4 ) {
- return Inet4Address( hostname, bytes, numBytes );
- } else if( numBytes == 16 ) {
- return Inet6Address( hostname, bytes, numBytes );
+ if (numBytes == 4) {
+ return Inet4Address(hostname, bytes, numBytes);
+ } else if (numBytes == 16) {
+ return Inet6Address(hostname, bytes, numBytes);
} else {
- throw UnknownHostException(
- __FILE__, __LINE__, "Number of Bytes passed was invalid: %d", numBytes );
+ throw UnknownHostException(__FILE__, __LINE__, "Number of Bytes passed was invalid: %d", numBytes);
}
}
////////////////////////////////////////////////////////////////////////////////
-InetAddress InetAddress::getByAddress( const unsigned char* bytes, int numBytes ) {
+InetAddress InetAddress::getByAddress(const unsigned char* bytes, int numBytes) {
- if( numBytes == 4 ) {
- return Inet4Address( bytes, numBytes );
- } else if( numBytes == 16 ) {
- return Inet6Address( bytes, numBytes );
+ if (numBytes == 4) {
+ return Inet4Address(bytes, numBytes);
+ } else if (numBytes == 16) {
+ return Inet6Address(bytes, numBytes);
} else {
- throw UnknownHostException(
- __FILE__, __LINE__, "Number of Bytes passed was invalid: %d", numBytes );
+ throw UnknownHostException(__FILE__, __LINE__, "Number of Bytes passed was invalid: %d", numBytes);
}
}
////////////////////////////////////////////////////////////////////////////////
InetAddress InetAddress::getLocalHost() {
- char hostname[APRMAXHOSTLEN + 1] = {0};
+ char hostname[APRMAXHOSTLEN + 1] = { 0 };
- try{
+ try {
AprPool pool;
apr_status_t result = APR_SUCCESS;
try {
- result = apr_gethostname( hostname, APRMAXHOSTLEN+1, pool.getAprPool() );
+ result = apr_gethostname(hostname, APRMAXHOSTLEN + 1, pool.getAprPool());
- if( result != APR_SUCCESS ) {
+ if (result != APR_SUCCESS) {
return getLoopbackAddress();
}
- } catch(...) {}
+ } catch (...) {
+ }
apr_sockaddr_t* address = NULL;
- result = apr_sockaddr_info_get( &address, hostname, APR_UNSPEC, 0, APR_IPV4_ADDR_OK, pool.getAprPool() );
+ result = apr_sockaddr_info_get(&address, hostname, APR_UNSPEC, 0, APR_IPV4_ADDR_OK, pool.getAprPool());
- if( result != APR_SUCCESS ) {
- throw UnknownHostException(
- __FILE__, __LINE__, "Could not resolve the IP Address of this host." );
+ if (result != APR_SUCCESS) {
+ throw UnknownHostException(__FILE__, __LINE__, "Could not resolve the IP Address of this host.");
}
- if( address->family == APR_INET ) {
- return Inet4Address( hostname, (const unsigned char*)address->ipaddr_ptr, address->ipaddr_len );
+ if (address->family == APR_INET) {
+ return Inet4Address(hostname, (const unsigned char*) address->ipaddr_ptr, address->ipaddr_len);
} else {
- return Inet6Address( hostname, (const unsigned char*)address->ipaddr_ptr, address->ipaddr_len );
+ return Inet6Address(hostname, (const unsigned char*) address->ipaddr_ptr, address->ipaddr_len);
}
}
- DECAF_CATCH_RETHROW( UnknownHostException )
- DECAF_CATCH_EXCEPTION_CONVERT( Exception, UnknownHostException )
- DECAF_CATCHALL_THROW( UnknownHostException )
+ DECAF_CATCH_RETHROW( UnknownHostException)
+ DECAF_CATCH_EXCEPTION_CONVERT( Exception, UnknownHostException)
+ DECAF_CATCHALL_THROW( UnknownHostException)
}
////////////////////////////////////////////////////////////////////////////////
-unsigned int InetAddress::bytesToInt( const unsigned char* bytes, int start ) {
+unsigned int InetAddress::bytesToInt(const unsigned char* bytes, int start) {
// First mask the byte with 255, as when a negative
// signed byte converts to an integer, it has bits
@@ -198,20 +191,17 @@ unsigned int InetAddress::bytesToInt( co
// about the right-most 8 bits.
// Then shift the rightmost byte to align with its
// position in the integer.
- int value = ( ( bytes[start + 3] & 255 ) ) |
- ( ( bytes[start + 2] & 255 ) << 8 ) |
- ( ( bytes[start + 1] & 255 ) << 16 ) |
- ( ( bytes[start] & 255 ) << 24 );
+ int value = ((bytes[start + 3] & 255)) | ((bytes[start + 2] & 255) << 8) | ((bytes[start + 1] & 255) << 16) | ((bytes[start] & 255) << 24);
return value;
}
////////////////////////////////////////////////////////////////////////////////
InetAddress InetAddress::getAnyAddress() {
- return Inet4Address( "localhost", InetAddress::loopbackBytes, 4 );
+ return Inet4Address("localhost", InetAddress::loopbackBytes, 4);
}
////////////////////////////////////////////////////////////////////////////////
InetAddress InetAddress::getLoopbackAddress() {
- return Inet4Address( InetAddress::anyBytes, 4 );
+ return Inet4Address(InetAddress::anyBytes, 4);
}
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/InetAddress.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/InetAddress.h?rev=1444986&r1=1444985&r2=1444986&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/InetAddress.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/InetAddress.h Mon Feb 11 22:36:08 2013
@@ -45,8 +45,8 @@ namespace net {
protected:
InetAddress();
- InetAddress( const unsigned char* ipAddress, int numBytes );
- InetAddress( const std::string& hostname, const unsigned char* ipAddress, int numBytes );
+ InetAddress(const unsigned char* ipAddress, int numBytes);
+ InetAddress(const std::string& hostname, const unsigned char* ipAddress, int numBytes);
public:
@@ -96,7 +96,8 @@ namespace net {
*/
virtual InetAddress* clone() const;
- public: // Address Property Tests, override in the subclasses for correct results
+ public:
+ // Address Property Tests, override in the subclasses for correct results
/**
* Check if this InetAddress is a valid wildcard address.
@@ -188,7 +189,8 @@ namespace net {
return false;
}
- public: // Static Create methods.
+ public:
+ // Static Create methods.
/**
* Given a raw IP Address in byte array form, create and return a new InetAddress instance.
@@ -199,7 +201,7 @@ namespace net {
*
* @throws UnknownHostException if the address array length is invalid.
*/
- static InetAddress getByAddress( const unsigned char* bytes, int numBytes );
+ static InetAddress getByAddress(const unsigned char* bytes, int numBytes);
/**
* Given a host name and IPAddress return a new InetAddress. There is no name service checking or
@@ -212,7 +214,7 @@ namespace net {
*
* @throws UnknownHostException if the address array length is invalid.
*/
- static InetAddress getByAddress( const std::string& hostname, const unsigned char* bytes, int numBytes );
+ static InetAddress getByAddress(const std::string& hostname, const unsigned char* bytes, int numBytes);
/**
* Gets an InetAddress that is the local host address. If the localhost value cannot
@@ -237,7 +239,7 @@ namespace net {
*
* @return an unsigned int that represents the address value.
*/
- static unsigned int bytesToInt( const unsigned char* bytes, int start );
+ static unsigned int bytesToInt(const unsigned char* bytes, int start);
static InetAddress getAnyAddress();