diff options
Diffstat (limited to 'cpp')
54 files changed, 944 insertions, 701 deletions
diff --git a/cpp/allTests.py b/cpp/allTests.py index 8441273fbc9..7bbea9e64c8 100755 --- a/cpp/allTests.py +++ b/cpp/allTests.py @@ -35,6 +35,7 @@ tests = [ ("Ice/proxy", ["core"]), ("Ice/operations", ["core"]), ("Ice/exceptions", ["core"]), + ("Ice/info", ["core"]), ("Ice/inheritance", ["core"]), ("Ice/facets", ["core"]), ("Ice/objects", ["core"]), diff --git a/cpp/include/Ice/LocalObject.h b/cpp/include/Ice/LocalObject.h index 9fcd48e5715..3a19b322085 100644 --- a/cpp/include/Ice/LocalObject.h +++ b/cpp/include/Ice/LocalObject.h @@ -29,7 +29,12 @@ public: virtual bool operator==(const LocalObject&) const; virtual bool operator<(const LocalObject&) const; - virtual ::Ice::Int ice_hash() const; + virtual ::Ice::Int ice_getHash() const; + + ICE_DEPRECATED_API ::Ice::Int ice_hash() const + { + return ice_getHash(); + } }; } diff --git a/cpp/include/Ice/Object.h b/cpp/include/Ice/Object.h index f4d01da96cb..c3170a88ff3 100644 --- a/cpp/include/Ice/Object.h +++ b/cpp/include/Ice/Object.h @@ -74,7 +74,11 @@ public: virtual bool operator==(const Object&) const; virtual bool operator<(const Object&) const; - virtual Int ice_hash() const; + virtual Int ice_getHash() const; + ICE_DEPRECATED_API ::Ice::Int ice_hash() const + { + return ice_getHash(); + } virtual bool ice_isA(const std::string&, const Current& = Current()) const; DispatchStatus ___ice_isA(IceInternal::Incoming&, const Current&); diff --git a/cpp/include/IceSSL/Plugin.h b/cpp/include/IceSSL/Plugin.h index bd9c3e92580..67931610761 100644 --- a/cpp/include/IceSSL/Plugin.h +++ b/cpp/include/IceSSL/Plugin.h @@ -12,7 +12,7 @@ #include <IceUtil/Time.h> #include <Ice/Plugin.h> -#include <Ice/ConnectionF.h> +#include <IceSSL/ConnectionInfo.h> #include <vector> #include <list> @@ -355,52 +355,21 @@ private: }; // -// ConnectionInfo contains information that may be of use to a -// CertificateVerifier or an application that wants information -// about its peer. +// NativeConnectionInfo is an extension of IceSSL::ConnectionInfo that +// provides access to native certificates. // -struct ConnectionInfo +class NativeConnectionInfo : public ConnectionInfo { +public: + // // The certificate chain. This may be empty if the peer did not // supply a certificate. The peer's certificate (if any) is the // first one in the chain. // - std::vector<CertificatePtr> certs; - - // - // The name of the negotiated cipher. - // - std::string cipher; - - // - // The local TCP/IP host & port. - // - struct sockaddr_storage localAddr; - - // - // The remote TCP/IP host & port. - // - // NOTE: - // - // This value may not be available when using IPv6 on Windows XP SP2 due to a bug in - // the IPv6 implementation. In this case, remoteAddr.ss_family is set to AF_UNSPEC and - // the remainder of the value is filled with zeroes. - // - struct sockaddr_storage remoteAddr; - - // - // If the connection is incoming this bool is true, false - // otherwise. - // - bool incoming; - - // - // The name of the object adapter that hosts this endpoint, if - // any. - // - std::string adapterName; + std::vector<CertificatePtr> nativeCerts; }; +typedef IceUtil::Handle<NativeConnectionInfo> NativeConnectionInfoPtr; // // An application can customize the certificate verification process @@ -414,7 +383,7 @@ public: // Return false if the connection should be rejected, or true to // allow it. // - virtual bool verify(const ConnectionInfo&) = 0; + virtual bool verify(const NativeConnectionInfoPtr&) = 0; }; typedef IceUtil::Handle<CertificateVerifier> CertificateVerifierPtr; @@ -484,33 +453,6 @@ public: }; typedef IceUtil::Handle<Plugin> PluginPtr; -// -// Thrown if getConnectionInfo cannot retrieve the ConnectionInfo. -// -class ICE_SSL_API ConnectionInvalidException : public IceUtil::Exception -{ -public: - - ConnectionInvalidException(const char*, int, const std::string&); - virtual ~ConnectionInvalidException() throw(); - virtual std::string ice_name() const; - virtual IceUtil::Exception* ice_clone() const; - virtual void ice_throw() const; - - std::string reason; - -private: - - static const char* _name; -}; - -// -// This function obtains a ConnectionInfo value that describes a -// Connection. The function raises ConnectionInvalidException if the -// connection is closed or is not an SSL connection. -// -ICE_SSL_API ConnectionInfo getConnectionInfo(const ::Ice::ConnectionPtr&); - } #endif diff --git a/cpp/src/Glacier2/SessionRouterI.cpp b/cpp/src/Glacier2/SessionRouterI.cpp index cbb861fc345..de70d7dd4b2 100644 --- a/cpp/src/Glacier2/SessionRouterI.cpp +++ b/cpp/src/Glacier2/SessionRouterI.cpp @@ -483,23 +483,6 @@ private: } -namespace -{ - -template<class T> void populateContext(const IceInternal::Handle<T>& info, Ice::Context& context) -{ - ostringstream os; - os << info->remotePort; - context["_con.remotePort"] = os.str(); - context["_con.remoteAddress"] = info->remoteAddress; - os.str(""); - os << info->localPort; - context["_con.localPort"] = os.str(); - context["_con.localAddress"] = info->localAddress; -} - -} - using namespace Glacier2; Glacier2::CreateSession::CreateSession(const SessionRouterIPtr& sessionRouter, const string& user, @@ -513,17 +496,22 @@ Glacier2::CreateSession::CreateSession(const SessionRouterIPtr& sessionRouter, c { _context["_con.type"] = current.con->type(); { - Ice::TcpConnectionInfoPtr info = Ice::TcpConnectionInfoPtr::dynamicCast(current.con->getInfo()); + Ice::IPConnectionInfoPtr info = Ice::IPConnectionInfoPtr::dynamicCast(current.con->getInfo()); if(info) { - populateContext(info, _context); - } + ostringstream os; + os << info->remotePort; + _context["_con.remotePort"] = os.str(); + _context["_con.remoteAddress"] = info->remoteAddress; + os.str(""); + os << info->localPort; + _context["_con.localPort"] = os.str(); + _context["_con.localAddress"] = info->localAddress; } } { - IceSSL::SSLConnectionInfoPtr info = IceSSL::SSLConnectionInfoPtr::dynamicCast(current.con->getInfo()); + IceSSL::ConnectionInfoPtr info = IceSSL::ConnectionInfoPtr::dynamicCast(current.con->getInfo()); if(info) { - populateContext(info, _context); _context["_con.cipher"] = info->cipher; if(info->certs.size() > 0) { @@ -615,7 +603,7 @@ Glacier2::CreateSession::sessionCreated(const SessionPrx& session) // // DEPRECATED: Glacier2.AddSSLContext. // - IceSSL::SSLConnectionInfoPtr info = IceSSL::SSLConnectionInfoPtr::dynamicCast(_current.con->getInfo()); + IceSSL::ConnectionInfoPtr info = IceSSL::ConnectionInfoPtr::dynamicCast(_current.con->getInfo()); if(info && _instance->properties()->getPropertyAsInt("Glacier2.AddSSLContext") > 0) { _context["SSL.Active"] = "1"; @@ -907,7 +895,7 @@ Glacier2::SessionRouterI::createSessionFromSecureConnection_async( // try { - IceSSL::SSLConnectionInfoPtr info = IceSSL::SSLConnectionInfoPtr::dynamicCast(current.con->getInfo()); + IceSSL::ConnectionInfoPtr info = IceSSL::ConnectionInfoPtr::dynamicCast(current.con->getInfo()); if(!info) { amdCB->ice_exception(PermissionDeniedException("not ssl connection")); diff --git a/cpp/src/Ice/ConnectionI.cpp b/cpp/src/Ice/ConnectionI.cpp index b8942d42aec..310f4575395 100644 --- a/cpp/src/Ice/ConnectionI.cpp +++ b/cpp/src/Ice/ConnectionI.cpp @@ -988,6 +988,12 @@ Ice::ConnectionI::getAdapter() const return _adapter; } +EndpointPtr +Ice::ConnectionI::getEndpoint() const +{ + return _endpoint; // No mutex protection necessary, _endpoint is immutable. +} + ObjectPrx Ice::ConnectionI::createProxy(const Identity& ident) const { @@ -1434,23 +1440,13 @@ Ice::ConnectionI::getInfo() const { _exception->ice_throw(); } + ConnectionInfoPtr info = _transceiver->getInfo(); - info->endpoint = _endpoint->getInfo(); + info->incoming = _connector == 0; + info->adapterName = _adapter ? _adapter->getName() : string(); return info; } -// -// Only used by the SSL plug-in. -// -// The external party has to synchronize the connection, since the -// connection is the object that protects the transceiver. -// -IceInternal::TransceiverPtr -Ice::ConnectionI::getTransceiver() const -{ - return _transceiver; -} - void Ice::ConnectionI::exception(const LocalException& ex) { diff --git a/cpp/src/Ice/ConnectionI.h b/cpp/src/Ice/ConnectionI.h index 5c844ea5cb7..688a6f47ccd 100644 --- a/cpp/src/Ice/ConnectionI.h +++ b/cpp/src/Ice/ConnectionI.h @@ -114,6 +114,7 @@ public: virtual void setAdapter(const ObjectAdapterPtr&); // From Connection. virtual ObjectAdapterPtr getAdapter() const; // From Connection. + virtual EndpointPtr getEndpoint() const; // From Connection. virtual ObjectPrx createProxy(const Identity& ident) const; // From Connection. // @@ -134,9 +135,6 @@ public: virtual Ice::Int timeout() const; // From Connection. virtual ConnectionInfoPtr getInfo() const; // From Connection - // SSL plug-in needs to be able to get the transceiver. - IceInternal::TransceiverPtr getTransceiver() const; - void exception(const LocalException&); void invokeException(const LocalException&, int); diff --git a/cpp/src/Ice/EndpointI.cpp b/cpp/src/Ice/EndpointI.cpp index 64c6efa5cf2..9bfa1516065 100644 --- a/cpp/src/Ice/EndpointI.cpp +++ b/cpp/src/Ice/EndpointI.cpp @@ -13,13 +13,50 @@ #include <Ice/Network.h> #include <Ice/PropertiesI.h> #include <Ice/LoggerUtil.h> +#include <IceUtil/MutexPtrLock.h> using namespace std; using namespace IceInternal; +namespace +{ + +IceUtil::Mutex* hashMutex = 0; + +class Init +{ +public: + + Init() + { + hashMutex = new IceUtil::Mutex; + } + + ~Init() + { + delete hashMutex; + hashMutex = 0; + } +}; + +Init init; + +} + Ice::LocalObject* IceInternal::upCast(EndpointI* p) { return p; } IceUtil::Shared* IceInternal::upCast(EndpointHostResolver* p) { return p; } +Ice::Int +IceInternal::EndpointI::ice_getHash() const +{ + IceUtilInternal::MutexPtrLock<IceUtil::Mutex> lock(hashMutex); + if(!_hashInitialized) + { + _hashValue = hashInit(); + } + return _hashValue; +} + vector<ConnectorPtr> IceInternal::EndpointI::connectors(const vector<struct sockaddr_storage>& addrs) const { @@ -31,6 +68,10 @@ IceInternal::EndpointI::connectors(const vector<struct sockaddr_storage>& addrs) return vector<ConnectorPtr>(); } +IceInternal::EndpointI::EndpointI() : _hashInitialized(false) +{ +} + IceInternal::EndpointHostResolver::EndpointHostResolver(const InstancePtr& instance) : IceUtil::Thread("Ice endpoint host resolver thread"), _instance(instance), diff --git a/cpp/src/Ice/EndpointI.h b/cpp/src/Ice/EndpointI.h index 2dc851f4f42..1336ce31caa 100644 --- a/cpp/src/Ice/EndpointI.h +++ b/cpp/src/Ice/EndpointI.h @@ -135,47 +135,38 @@ public: // Check whether the endpoint is equivalent to another one. // virtual bool equivalent(const EndpointIPtr&) const = 0; - + // // Compare endpoints for sorting purposes. // - virtual bool operator==(const EndpointI&) const = 0; - virtual bool operator!=(const EndpointI&) const = 0; - virtual bool operator<(const EndpointI&) const = 0; - -#if defined(__BCPLUSPLUS__) - // - // COMPILERFIX: Avoid warnings about hiding members for C++Builder 2010 - // - // - virtual bool operator==(const Ice::LocalObject& rhs) const - { - return Ice::LocalObject::operator==(rhs); - } - - virtual bool operator<(const Ice::LocalObject& rhs) const - { - return Ice::LocalObject::operator<(rhs); - } -#endif + virtual bool operator==(const LocalObject&) const = 0; + virtual bool operator<(const LocalObject&) const = 0; + virtual ::Ice::Int ice_getHash() const; protected: virtual std::vector<ConnectorPtr> connectors(const std::vector<struct sockaddr_storage>&) const; friend class EndpointHostResolver; + EndpointI(); + virtual ::Ice::Int hashInit() const = 0; + private: -#if defined(__SUNPRO_CC) - // - // COMPILERFIX: prevent the compiler from emitting a warning about - // hidding these operators. - // - using LocalObject::operator==; - using LocalObject::operator<; -#endif + mutable bool _hashInitialized; + mutable Ice::Int _hashValue; }; +inline bool operator==(const EndpointI& l, const EndpointI& r) +{ + return static_cast<const ::Ice::LocalObject&>(l) == static_cast<const ::Ice::LocalObject&>(r); +} + +inline bool operator<(const EndpointI& l, const EndpointI& r) +{ + return static_cast<const ::Ice::LocalObject&>(l) < static_cast<const ::Ice::LocalObject&>(r); +} + class ICE_API EndpointHostResolver : public IceUtil::Thread, public IceUtil::Monitor<IceUtil::Mutex> { public: diff --git a/cpp/src/Ice/HashUtil.h b/cpp/src/Ice/HashUtil.h new file mode 100644 index 00000000000..ce2e8b941bc --- /dev/null +++ b/cpp/src/Ice/HashUtil.h @@ -0,0 +1,60 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#ifndef ICE_HASH_UTIL_H +#define ICE_HASH_UTIL_H + +namespace IceInternal +{ + +inline void +hashAdd(Ice::Int& hashCode, Ice::Int value) +{ + hashCode = hashCode * 5 + value; +} + +inline void +hashAdd(Ice::Int& hashCode, bool value) +{ + hashCode = hashCode * 5 + static_cast<Ice::Int>(value); +} + +inline void +hashAdd(Ice::Int& hashCode, const std::string& value) +{ + for(std::string::const_iterator p = value.begin(); p != value.end(); ++p) + { + hashCode = 5 * hashCode + *p; + } +} + +template<typename T> void +hashAdd(Ice::Int& hashCode, const std::vector<T>& seq) +{ + for(typename std::vector<T>::const_iterator p = seq.begin(); p != seq.end(); ++p) + { + hashAdd(hashCode, *p); + } +} + +template<typename K, typename V> void +hashAdd(Ice::Int& hashCode, const std::map<K, V>& map) +{ + for(typename std::map<K, V>::const_iterator p = map.begin(); p != map.end(); ++p) + { + hashAdd(hashCode, p->first); + hashAdd(hashCode, p->second); + } +} + + +} + +#endif + diff --git a/cpp/src/Ice/LocalObject.cpp b/cpp/src/Ice/LocalObject.cpp index 16e57a35324..a2be55cd02b 100644 --- a/cpp/src/Ice/LocalObject.cpp +++ b/cpp/src/Ice/LocalObject.cpp @@ -28,7 +28,7 @@ Ice::LocalObject::operator<(const LocalObject& r) const } Int -Ice::LocalObject::ice_hash() const +Ice::LocalObject::ice_getHash() const { return static_cast<Int>(reinterpret_cast<Long>(this) >> 4); } diff --git a/cpp/src/Ice/Object.cpp b/cpp/src/Ice/Object.cpp index 5d4f4fdca3a..0d102ae1a63 100644 --- a/cpp/src/Ice/Object.cpp +++ b/cpp/src/Ice/Object.cpp @@ -34,7 +34,7 @@ Ice::Object::operator<(const Object& r) const } Int -Ice::Object::ice_hash() const +Ice::Object::ice_getHash() const { return static_cast<Int>(reinterpret_cast<Long>(this) >> 4); } diff --git a/cpp/src/Ice/OpaqueEndpointI.cpp b/cpp/src/Ice/OpaqueEndpointI.cpp index 19c033881e7..9960872df1c 100644 --- a/cpp/src/Ice/OpaqueEndpointI.cpp +++ b/cpp/src/Ice/OpaqueEndpointI.cpp @@ -12,6 +12,7 @@ #include <Ice/Exception.h> #include <Ice/Instance.h> #include <Ice/Base64.h> +#include <Ice/HashUtil.h> using namespace std; using namespace Ice; @@ -282,7 +283,7 @@ IceInternal::OpaqueEndpointI::equivalent(const EndpointIPtr&) const } bool -IceInternal::OpaqueEndpointI::operator==(const EndpointI& r) const +IceInternal::OpaqueEndpointI::operator==(const LocalObject& r) const { const OpaqueEndpointI* p = dynamic_cast<const OpaqueEndpointI*>(&r); if(!p) @@ -309,18 +310,17 @@ IceInternal::OpaqueEndpointI::operator==(const EndpointI& r) const } bool -IceInternal::OpaqueEndpointI::operator!=(const EndpointI& r) const -{ - return !operator==(r); -} - -bool -IceInternal::OpaqueEndpointI::operator<(const EndpointI& r) const +IceInternal::OpaqueEndpointI::operator<(const LocalObject& r) const { const OpaqueEndpointI* p = dynamic_cast<const OpaqueEndpointI*>(&r); if(!p) { - return type() < r.type(); + const EndpointI* e = dynamic_cast<const EndpointI*>(&r); + if(!e) + { + return false; + } + return type() < e->type(); } if(this == p) @@ -348,3 +348,11 @@ IceInternal::OpaqueEndpointI::operator<(const EndpointI& r) const return false; } + +Ice::Int +IceInternal::OpaqueEndpointI::hashInit() const +{ + Ice::Int h = _type; + hashAdd(h, _rawBytes); + return h; +} diff --git a/cpp/src/Ice/OpaqueEndpointI.h b/cpp/src/Ice/OpaqueEndpointI.h index b89905563b0..609de265708 100644 --- a/cpp/src/Ice/OpaqueEndpointI.h +++ b/cpp/src/Ice/OpaqueEndpointI.h @@ -41,46 +41,16 @@ public: virtual std::vector<EndpointIPtr> expand() const; virtual bool equivalent(const EndpointIPtr&) const; - virtual bool operator==(const EndpointI&) const; - virtual bool operator!=(const EndpointI&) const; - virtual bool operator<(const EndpointI&) const; - -#if defined(__BCPLUSPLUS__) - // - // COMPILERFIX: Avoid warnings about hiding members for C++Builder 2010 - // - // - virtual bool operator==(const Ice::LocalObject& rhs) const - { - return EndpointI::operator==(rhs); - } - - virtual bool operator<(const Ice::LocalObject& rhs) const - { - return EndpointI::operator<(rhs); - } - - virtual std::vector<ConnectorPtr> connectors(const std::vector<struct sockaddr_storage>& v) const - { - return EndpointI::connectors(v); - } -#endif + virtual bool operator==(const LocalObject&) const; + virtual bool operator<(const LocalObject&) const; protected: + virtual ::Ice::Int hashInit() const; using EndpointI::connectors; private: -#if defined(__SUNPRO_CC) - // - // COMPILERFIX: prevent the compiler from emitting a warning about - // hidding these operators. - // - using LocalObject::operator==; - using LocalObject::operator<; -#endif - // // All members are const, because endpoints are immutable. // diff --git a/cpp/src/Ice/Reference.cpp b/cpp/src/Ice/Reference.cpp index 53f9bcfd70c..a4e41555f85 100644 --- a/cpp/src/Ice/Reference.cpp +++ b/cpp/src/Ice/Reference.cpp @@ -23,9 +23,11 @@ #include <Ice/ConnectionFactory.h> #include <Ice/LoggerUtil.h> #include <Ice/TraceLevels.h> +#include <Ice/HashUtil.h> #include <Ice/DefaultsAndOverrides.h> #include <IceUtil/StringUtil.h> #include <IceUtil/Random.h> +#include <IceUtil/MutexPtrLock.h> #include <functional> @@ -37,6 +39,27 @@ IceUtil::Shared* IceInternal::upCast(IceInternal::Reference* p) { return p; } namespace { + +IceUtil::Mutex* hashMutex = 0; + +class Init +{ +public: + + Init() + { + hashMutex = new IceUtil::Mutex; + } + + ~Init() + { + delete hashMutex; + hashMutex = 0; + } +}; + +Init init; + struct RandomNumberGenerator : public std::unary_function<ptrdiff_t, ptrdiff_t> { ptrdiff_t operator()(ptrdiff_t d) @@ -125,10 +148,11 @@ IceInternal::Reference::changeCompress(bool newCompress) const Int Reference::hash() const { - IceUtil::Mutex::Lock sync(_hashMutex); + IceUtilInternal::MutexPtrLock<IceUtil::Mutex> lock(hashMutex); if(!_hashInitialized) { - hashInit(); // Initialize _hashValue + _hashValue = hashInit(); + _hashInitialized = true; } return _hashValue; } @@ -434,45 +458,16 @@ IceInternal::Reference::Reference(const Reference& r) : { } -void +int IceInternal::Reference::hashInit() const { - string::const_iterator p; - Context::const_iterator q; - Int h = static_cast<Int>(_mode); - - for(p = _identity.name.begin(); p != _identity.name.end(); ++p) - { - h = 5 * h + *p; - } - - for(p = _identity.category.begin(); p != _identity.category.end(); ++p) - { - h = 5 * h + *p; - } - - for(q = _context->getValue().begin(); q != _context->getValue().end(); ++q) - { - for(p = q->first.begin(); p != q->first.end(); ++p) - { - h = 5 * h + *p; - } - for(p = q->second.begin(); p != q->second.end(); ++p) - { - h = 5 * h + *p; - } - } - - for(p = _facet.begin(); p != _facet.end(); ++p) - { - h = 5 * h + *p; - } - - h = 5 * h + static_cast<Int>(_secure); - - _hashValue = h; - _hashInitialized = true; + hashAdd(h, _identity.name); + hashAdd(h, _identity.category); + hashAdd(h, _context->getValue()); + hashAdd(h, _facet); + hashAdd(h, _secure); + return h; } IceUtil::Shared* IceInternal::upCast(IceInternal::FixedReference* p) { return p; } @@ -1139,20 +1134,11 @@ IceInternal::RoutableReference::toString() const } int -IceInternal::RoutableReference::hash() const +IceInternal::RoutableReference::hashInit() const { - IceUtil::Mutex::Lock sync(_hashMutex); - if(!_hashInitialized) - { - hashInit(); // Initializes _hashValue. - - // Add hash of adapter ID to base hash. - for(string::const_iterator p = _adapterId.begin(); p != _adapterId.end(); ++p) - { - _hashValue = 5 * _hashValue + *p; - } - } - return _hashValue; + int value = Reference::hashInit(); + hashAdd(value, _adapterId); + return value; } bool diff --git a/cpp/src/Ice/Reference.h b/cpp/src/Ice/Reference.h index 1dadba0465c..3d2b9b4701c 100644 --- a/cpp/src/Ice/Reference.h +++ b/cpp/src/Ice/Reference.h @@ -98,7 +98,7 @@ public: virtual ReferencePtr changeTimeout(int) const = 0; virtual ReferencePtr changeConnectionId(const std::string&) const = 0; - virtual int hash() const; // Conceptually const. + int hash() const; // Conceptually const. // // Utility methods. @@ -133,9 +133,8 @@ protected: Reference(const InstancePtr&, const Ice::CommunicatorPtr&, const Ice::Identity&, const std::string&, Mode, bool); Reference(const Reference&); - void hashInit() const; + virtual Ice::Int hashInit() const; - IceUtil::Mutex _hashMutex; // For lazy initialization of hash value. mutable Ice::Int _hashValue; mutable bool _hashInitialized; @@ -240,8 +239,6 @@ public: virtual ReferencePtr changeTimeout(int) const; virtual ReferencePtr changeConnectionId(const std::string&) const; - virtual int hash() const; - virtual bool isIndirect() const; virtual bool isWellKnown() const; @@ -268,6 +265,8 @@ protected: std::vector<EndpointIPtr> filterEndpoints(const std::vector<EndpointIPtr>&) const; + virtual int hashInit() const; + private: std::vector<EndpointIPtr> _endpoints; // Empty if indirect proxy. diff --git a/cpp/src/Ice/TcpConnector.cpp b/cpp/src/Ice/TcpConnector.cpp index 9d45fdf82bd..f8a5a53a33a 100644 --- a/cpp/src/Ice/TcpConnector.cpp +++ b/cpp/src/Ice/TcpConnector.cpp @@ -49,7 +49,7 @@ IceInternal::TcpConnector::connect() Short IceInternal::TcpConnector::type() const { - return TcpEndpointType; + return TCPEndpointType; } string diff --git a/cpp/src/Ice/TcpEndpointI.cpp b/cpp/src/Ice/TcpEndpointI.cpp index 9d8c761231f..c8e027b4ffb 100644 --- a/cpp/src/Ice/TcpEndpointI.cpp +++ b/cpp/src/Ice/TcpEndpointI.cpp @@ -16,6 +16,7 @@ #include <Ice/LocalException.h> #include <Ice/Instance.h> #include <Ice/DefaultsAndOverrides.h> +#include <Ice/HashUtil.h> using namespace std; using namespace Ice; @@ -177,7 +178,7 @@ IceInternal::TcpEndpointI::TcpEndpointI(BasicStream* s) : void IceInternal::TcpEndpointI::streamWrite(BasicStream* s) const { - s->write(TcpEndpointType); + s->write(TCPEndpointType); s->startWriteEncaps(); s->write(_host, false); s->write(_port); @@ -229,19 +230,19 @@ IceInternal::TcpEndpointI::toString() const EndpointInfoPtr IceInternal::TcpEndpointI::getInfo() const { - class InfoI : public Ice::TcpEndpointInfo + class InfoI : public Ice::TCPEndpointInfo { public: InfoI(Ice::Int to, bool comp, const string& host, Ice::Int port) : - TcpEndpointInfo(to, comp, host, port) + TCPEndpointInfo(to, comp, host, port) { } virtual Ice::Short type() const { - return TcpEndpointType; + return TCPEndpointType; } virtual bool @@ -263,7 +264,7 @@ IceInternal::TcpEndpointI::getInfo() const Short IceInternal::TcpEndpointI::type() const { - return TcpEndpointType; + return TCPEndpointType; } Int @@ -388,7 +389,7 @@ IceInternal::TcpEndpointI::equivalent(const EndpointIPtr& endpoint) const } bool -IceInternal::TcpEndpointI::operator==(const EndpointI& r) const +IceInternal::TcpEndpointI::operator==(const LocalObject& r) const { const TcpEndpointI* p = dynamic_cast<const TcpEndpointI*>(&r); if(!p) @@ -430,18 +431,17 @@ IceInternal::TcpEndpointI::operator==(const EndpointI& r) const } bool -IceInternal::TcpEndpointI::operator!=(const EndpointI& r) const -{ - return !operator==(r); -} - -bool -IceInternal::TcpEndpointI::operator<(const EndpointI& r) const +IceInternal::TcpEndpointI::operator<(const LocalObject& r) const { const TcpEndpointI* p = dynamic_cast<const TcpEndpointI*>(&r); if(!p) { - return type() < r.type(); + const EndpointI* e = dynamic_cast<const EndpointI*>(&r); + if(!e) + { + return false; + } + return type() < e->type(); } if(this == p) @@ -497,6 +497,18 @@ IceInternal::TcpEndpointI::operator<(const EndpointI& r) const return false; } +Ice::Int +IceInternal::TcpEndpointI::hashInit() const +{ + Ice::Int h = 0; + hashAdd(h, _host); + hashAdd(h, _port); + hashAdd(h, _timeout); + hashAdd(h, _connectionId); + hashAdd(h, _compress); + return h; +} + vector<ConnectorPtr> IceInternal::TcpEndpointI::connectors(const vector<struct sockaddr_storage>& addresses) const { @@ -520,7 +532,7 @@ IceInternal::TcpEndpointFactory::~TcpEndpointFactory() Short IceInternal::TcpEndpointFactory::type() const { - return TcpEndpointType; + return TCPEndpointType; } string diff --git a/cpp/src/Ice/TcpEndpointI.h b/cpp/src/Ice/TcpEndpointI.h index 1bf7829b397..7176154dbc4 100644 --- a/cpp/src/Ice/TcpEndpointI.h +++ b/cpp/src/Ice/TcpEndpointI.h @@ -16,8 +16,6 @@ namespace IceInternal { -const Ice::Short TcpEndpointType = 1; - class TcpEndpointI : public EndpointI { public: @@ -44,39 +42,14 @@ public: virtual std::vector<EndpointIPtr> expand() const; virtual bool equivalent(const EndpointIPtr&) const; - virtual bool operator==(const EndpointI&) const; - virtual bool operator!=(const EndpointI&) const; - virtual bool operator<(const EndpointI&) const; - -#if defined(__BCPLUSPLUS__) - // - // COMPILERFIX: Avoid warnings about hiding members for C++Builder 2010 - // - // - virtual bool operator==(const Ice::LocalObject& rhs) const - { - return EndpointI::operator==(rhs); - } - - virtual bool operator<(const Ice::LocalObject& rhs) const - { - return EndpointI::operator<(rhs); - } -#endif + virtual bool operator==(const LocalObject&) const; + virtual bool operator<(const LocalObject&) const; private: + virtual ::Ice::Int hashInit() const; virtual std::vector<ConnectorPtr> connectors(const std::vector<struct sockaddr_storage>&) const; -#if defined(__SUNPRO_CC) - // - // COMPILERFIX: prevent the compiler from emitting a warning about - // hidding these operators. - // - using LocalObject::operator==; - using LocalObject::operator<; -#endif - // // All members are const, because endpoints are immutable. // diff --git a/cpp/src/Ice/TcpTransceiver.cpp b/cpp/src/Ice/TcpTransceiver.cpp index 959c3ce6f87..d26545f22de 100644 --- a/cpp/src/Ice/TcpTransceiver.cpp +++ b/cpp/src/Ice/TcpTransceiver.cpp @@ -458,7 +458,7 @@ Ice::ConnectionInfoPtr IceInternal::TcpTransceiver::getInfo() const { assert(_fd != INVALID_SOCKET); - Ice::TcpConnectionInfoPtr info = new Ice::TcpConnectionInfo(); + Ice::TCPConnectionInfoPtr info = new Ice::TCPConnectionInfo(); fdToAddressAndPort(_fd, info->localAddress, info->localPort, info->remoteAddress, info->remotePort); return info; } diff --git a/cpp/src/Ice/UdpConnector.cpp b/cpp/src/Ice/UdpConnector.cpp index d8a4c5588df..e0d97ba37e9 100644 --- a/cpp/src/Ice/UdpConnector.cpp +++ b/cpp/src/Ice/UdpConnector.cpp @@ -26,7 +26,7 @@ IceInternal::UdpConnector::connect() Short IceInternal::UdpConnector::type() const { - return UdpEndpointType; + return UDPEndpointType; } string diff --git a/cpp/src/Ice/UdpEndpointI.cpp b/cpp/src/Ice/UdpEndpointI.cpp index bbd273cfa54..6d0ed5e6989 100644 --- a/cpp/src/Ice/UdpEndpointI.cpp +++ b/cpp/src/Ice/UdpEndpointI.cpp @@ -16,6 +16,7 @@ #include <Ice/Instance.h> #include <Ice/DefaultsAndOverrides.h> #include <Ice/Protocol.h> +#include <Ice/HashUtil.h> using namespace std; using namespace Ice; @@ -350,7 +351,7 @@ IceInternal::UdpEndpointI::UdpEndpointI(BasicStream* s) : void IceInternal::UdpEndpointI::streamWrite(BasicStream* s) const { - s->write(UdpEndpointType); + s->write(UDPEndpointType); s->startWriteEncaps(); s->write(_host, false); s->write(_port); @@ -435,13 +436,13 @@ IceInternal::UdpEndpointI::toString() const EndpointInfoPtr IceInternal::UdpEndpointI::getInfo() const { - class InfoI : public Ice::UdpEndpointInfo + class InfoI : public Ice::UDPEndpointInfo { public: InfoI(bool comp, const string& host, Ice::Int port, Ice::Byte protocolMajor, Ice::Byte protocolMinor, Ice::Byte encodingMajor, Ice::Byte encodingMinor, const std::string& mcastInterface, Ice::Int mcastTtl) : - UdpEndpointInfo(-1, comp, host, port, protocolMajor, protocolMinor, encodingMajor, encodingMinor, + UDPEndpointInfo(-1, comp, host, port, protocolMajor, protocolMinor, encodingMajor, encodingMinor, mcastInterface, mcastTtl) { } @@ -449,7 +450,7 @@ IceInternal::UdpEndpointI::getInfo() const virtual Ice::Short type() const { - return UdpEndpointType; + return UDPEndpointType; } virtual bool @@ -472,7 +473,7 @@ IceInternal::UdpEndpointI::getInfo() const Short IceInternal::UdpEndpointI::type() const { - return UdpEndpointType; + return UDPEndpointType; } Int @@ -595,7 +596,7 @@ IceInternal::UdpEndpointI::equivalent(const EndpointIPtr& endpoint) const } bool -IceInternal::UdpEndpointI::operator==(const EndpointI& r) const +IceInternal::UdpEndpointI::operator==(const LocalObject& r) const { const UdpEndpointI* p = dynamic_cast<const UdpEndpointI*>(&r); if(!p) @@ -667,18 +668,17 @@ IceInternal::UdpEndpointI::operator==(const EndpointI& r) const } bool -IceInternal::UdpEndpointI::operator!=(const EndpointI& r) const -{ - return !operator==(r); -} - -bool -IceInternal::UdpEndpointI::operator<(const EndpointI& r) const +IceInternal::UdpEndpointI::operator<(const LocalObject& r) const { const UdpEndpointI* p = dynamic_cast<const UdpEndpointI*>(&r); if(!p) { - return type() < r.type(); + const EndpointI* e = dynamic_cast<const EndpointI*>(&r); + if(!e) + { + return false; + } + return type() < e->type(); } if(this == p) @@ -788,6 +788,20 @@ IceInternal::UdpEndpointI::operator<(const EndpointI& r) const return false; } +Ice::Int +IceInternal::UdpEndpointI::hashInit() const +{ + Ice::Int h = 0; + hashAdd(h, _host); + hashAdd(h, _port); + hashAdd(h, _mcastInterface); + hashAdd(h, _mcastTtl); + hashAdd(h, _connect); + hashAdd(h, _connectionId); + hashAdd(h, _compress); + return h; +} + vector<ConnectorPtr> IceInternal::UdpEndpointI::connectors(const vector<struct sockaddr_storage>& addresses) const { @@ -812,7 +826,7 @@ IceInternal::UdpEndpointFactory::~UdpEndpointFactory() Short IceInternal::UdpEndpointFactory::type() const { - return UdpEndpointType; + return UDPEndpointType; } string diff --git a/cpp/src/Ice/UdpEndpointI.h b/cpp/src/Ice/UdpEndpointI.h index 1331d740085..e0894128bb8 100644 --- a/cpp/src/Ice/UdpEndpointI.h +++ b/cpp/src/Ice/UdpEndpointI.h @@ -16,8 +16,6 @@ namespace IceInternal { -const Ice::Short UdpEndpointType = 3; - class UdpEndpointI : public EndpointI { public: @@ -45,39 +43,14 @@ public: virtual std::vector<EndpointIPtr> expand() const; virtual bool equivalent(const EndpointIPtr&) const; - virtual bool operator==(const EndpointI&) const; - virtual bool operator!=(const EndpointI&) const; - virtual bool operator<(const EndpointI&) const; - -#if defined(__BCPLUSPLUS__) - // - // COMPILERFIX: Avoid warnings about hiding members for C++Builder 2010 - // - // - virtual bool operator==(const Ice::LocalObject& rhs) const - { - return EndpointI::operator==(rhs); - } - - virtual bool operator<(const Ice::LocalObject& rhs) const - { - return EndpointI::operator<(rhs); - } -#endif + virtual bool operator==(const LocalObject&) const; + virtual bool operator<(const LocalObject&) const; private: + virtual ::Ice::Int hashInit() const; virtual std::vector<ConnectorPtr> connectors(const std::vector<struct sockaddr_storage>&) const; -#if defined(__SUNPRO_CC) - // - // COMPILERFIX: prevent the compiler from emitting a warning about - // hidding these operators. - // - using LocalObject::operator==; - using LocalObject::operator<; -#endif - // // All members are const, because endpoints are immutable. // diff --git a/cpp/src/Ice/UdpTransceiver.cpp b/cpp/src/Ice/UdpTransceiver.cpp index fbf00a1048a..a2cdded6f8a 100644 --- a/cpp/src/Ice/UdpTransceiver.cpp +++ b/cpp/src/Ice/UdpTransceiver.cpp @@ -456,7 +456,7 @@ Ice::ConnectionInfoPtr IceInternal::UdpTransceiver::getInfo() const { assert(_fd != INVALID_SOCKET); - Ice::UdpConnectionInfoPtr info = new Ice::UdpConnectionInfo(); + Ice::UDPConnectionInfoPtr info = new Ice::UDPConnectionInfo(); fdToAddressAndPort(_fd, info->localAddress, info->localPort, info->remoteAddress, info->remotePort); addrToAddressAndPort(_mcastAddr, info->mcastAddress, info->mcastPort); return info; diff --git a/cpp/src/IceGrid/RegistryI.cpp b/cpp/src/IceGrid/RegistryI.cpp index d3caad319de..b1c91aee0b5 100644 --- a/cpp/src/IceGrid/RegistryI.cpp +++ b/cpp/src/IceGrid/RegistryI.cpp @@ -1239,7 +1239,7 @@ RegistryI::getSSLInfo(const ConnectionPtr& connection, string& userDN) Glacier2::SSLInfo sslinfo; try { - IceSSL::SSLConnectionInfoPtr info = IceSSL::SSLConnectionInfoPtr::dynamicCast(connection->getInfo()); + IceSSL::ConnectionInfoPtr info = IceSSL::ConnectionInfoPtr::dynamicCast(connection->getInfo()); if(!info) { PermissionDeniedException exc; diff --git a/cpp/src/IceSSL/EndpointI.cpp b/cpp/src/IceSSL/EndpointI.cpp index c21db89353c..78c76c10b79 100644 --- a/cpp/src/IceSSL/EndpointI.cpp +++ b/cpp/src/IceSSL/EndpointI.cpp @@ -16,6 +16,7 @@ #include <Ice/BasicStream.h> #include <Ice/LocalException.h> #include <Ice/DefaultsAndOverrides.h> +#include <Ice/HashUtil.h> using namespace std; using namespace Ice; @@ -229,12 +230,12 @@ IceSSL::EndpointI::toString() const Ice::EndpointInfoPtr IceSSL::EndpointI::getInfo() const { - class InfoI : public IceSSL::SSLEndpointInfo + class InfoI : public IceSSL::EndpointInfo { public: InfoI(Ice::Int to, bool comp, const string& host, Ice::Int port) : - SSLEndpointInfo(to, comp, host, port) + EndpointInfo(to, comp, host, port) { } @@ -387,7 +388,7 @@ IceSSL::EndpointI::equivalent(const IceInternal::EndpointIPtr& endpoint) const } bool -IceSSL::EndpointI::operator==(const IceInternal::EndpointI& r) const +IceSSL::EndpointI::operator==(const Ice::LocalObject& r) const { const EndpointI* p = dynamic_cast<const EndpointI*>(&r); if(!p) @@ -429,18 +430,17 @@ IceSSL::EndpointI::operator==(const IceInternal::EndpointI& r) const } bool -IceSSL::EndpointI::operator!=(const IceInternal::EndpointI& r) const -{ - return !operator==(r); -} - -bool -IceSSL::EndpointI::operator<(const IceInternal::EndpointI& r) const +IceSSL::EndpointI::operator<(const Ice::LocalObject& r) const { const EndpointI* p = dynamic_cast<const EndpointI*>(&r); if(!p) { - return type() < r.type(); + const IceInternal::EndpointI* e = dynamic_cast<const IceInternal::EndpointI*>(&r); + if(!e) + { + return false; + } + return type() < e->type(); } if(this == p) @@ -496,6 +496,18 @@ IceSSL::EndpointI::operator<(const IceInternal::EndpointI& r) const return false; } +Ice::Int +IceSSL::EndpointI::hashInit() const +{ + Ice::Int h = 0; + IceInternal::hashAdd(h, _host); + IceInternal::hashAdd(h, _port); + IceInternal::hashAdd(h, _timeout); + IceInternal::hashAdd(h, _connectionId); + IceInternal::hashAdd(h, _compress); + return h; +} + vector<IceInternal::ConnectorPtr> IceSSL::EndpointI::connectors(const vector<struct sockaddr_storage>& addresses) const { diff --git a/cpp/src/IceSSL/EndpointI.h b/cpp/src/IceSSL/EndpointI.h index 61f1751d48c..804c9a59d81 100644 --- a/cpp/src/IceSSL/EndpointI.h +++ b/cpp/src/IceSSL/EndpointI.h @@ -18,8 +18,6 @@ namespace IceSSL { -const Ice::Short EndpointType = 2; - class EndpointI : public IceInternal::EndpointI { public: @@ -46,38 +44,13 @@ public: virtual std::vector<IceInternal::EndpointIPtr> expand() const; virtual bool equivalent(const IceInternal::EndpointIPtr&) const; - virtual bool operator==(const IceInternal::EndpointI&) const; - virtual bool operator!=(const IceInternal::EndpointI&) const; - virtual bool operator<(const IceInternal::EndpointI&) const; - -#if defined(__BCPLUSPLUS__) - // - // COMPILERFIX: Avoid warnings about hiding members for C++Builder 2010 - // - // - virtual bool operator==(const Ice::LocalObject& rhs) const - { - return Ice::LocalObject::operator==(rhs); - } - - virtual bool operator<(const Ice::LocalObject& rhs) const - { - return Ice::LocalObject::operator<(rhs); - } -#endif + virtual bool operator==(const LocalObject&) const; + virtual bool operator<(const LocalObject&) const; private: - virtual std::vector<IceInternal::ConnectorPtr> connectors(const std::vector<struct sockaddr_storage>&) const; - -#if defined(__SUNPRO_CC) - // - // COMPILERFIX: prevent the compiler from emitting a warning about - // hidding these operators. - // - using LocalObject::operator==; - using LocalObject::operator<; -#endif + virtual ::Ice::Int hashInit() const; + virtual std::vector<IceInternal::ConnectorPtr> connectors(const std::vector<struct sockaddr_storage>&) const; // // All members are const, because endpoints are immutable. diff --git a/cpp/src/IceSSL/Instance.cpp b/cpp/src/IceSSL/Instance.cpp index 03bb4010062..66f148da791 100644 --- a/cpp/src/IceSSL/Instance.cpp +++ b/cpp/src/IceSSL/Instance.cpp @@ -783,7 +783,7 @@ IceSSL::Instance::securityTraceCategory() const } void -IceSSL::Instance::verifyPeer(SSL* ssl, SOCKET fd, const string& address, const string& adapterName, bool incoming) +IceSSL::Instance::verifyPeer(SSL* ssl, SOCKET fd, const string& address, const NativeConnectionInfoPtr& info) { long result = SSL_get_verify_result(ssl); if(result != X509_V_OK) @@ -935,13 +935,11 @@ IceSSL::Instance::verifyPeer(SSL* ssl, SOCKET fd, const string& address, const s } } - ConnectionInfo info = populateConnectionInfo(ssl, fd, adapterName, incoming); - - if(_verifyDepthMax > 0 && static_cast<int>(info.certs.size()) > _verifyDepthMax) + if(_verifyDepthMax > 0 && static_cast<int>(info->certs.size()) > _verifyDepthMax) { ostringstream ostr; - ostr << (incoming ? "incoming" : "outgoing") << " connection rejected:\n" - << "length of peer's certificate chain (" << info.certs.size() << ") exceeds maximum of " + ostr << (info->incoming ? "incoming" : "outgoing") << " connection rejected:\n" + << "length of peer's certificate chain (" << info->certs.size() << ") exceeds maximum of " << _verifyDepthMax; string msg = ostr.str(); if(_securityTraceLevel >= 1) @@ -955,7 +953,7 @@ IceSSL::Instance::verifyPeer(SSL* ssl, SOCKET fd, const string& address, const s if(!_trustManager->verify(info)) { - string msg = string(incoming ? "incoming" : "outgoing") + " connection rejected by trust manager"; + string msg = string(info->incoming ? "incoming" : "outgoing") + " connection rejected by trust manager"; if(_securityTraceLevel >= 1) { _logger->trace(_securityTraceCategory, msg + "\n" + IceInternal::fdToString(fd)); @@ -967,7 +965,7 @@ IceSSL::Instance::verifyPeer(SSL* ssl, SOCKET fd, const string& address, const s if(_verifier && !_verifier->verify(info)) { - string msg = string(incoming ? "incoming" : "outgoing") + " connection rejected by certificate verifier"; + string msg = string(info->incoming ? "incoming" : "outgoing") + " connection rejected by certificate verifier"; if(_securityTraceLevel >= 1) { _logger->trace(_securityTraceCategory, msg + "\n" + IceInternal::fdToString(fd)); diff --git a/cpp/src/IceSSL/Instance.h b/cpp/src/IceSSL/Instance.h index b459972007e..dee4a216969 100644 --- a/cpp/src/IceSSL/Instance.h +++ b/cpp/src/IceSSL/Instance.h @@ -45,7 +45,7 @@ public: int securityTraceLevel() const; std::string securityTraceCategory() const; - void verifyPeer(SSL*, SOCKET, const std::string&, const std::string&, bool); + void verifyPeer(SSL*, SOCKET, const std::string&, const NativeConnectionInfoPtr&); std::string sslErrors() const; diff --git a/cpp/src/IceSSL/PluginI.cpp b/cpp/src/IceSSL/PluginI.cpp index 67bf827d37e..414d205c37e 100644 --- a/cpp/src/IceSSL/PluginI.cpp +++ b/cpp/src/IceSSL/PluginI.cpp @@ -12,7 +12,6 @@ #include <IceSSL/TransceiverI.h> #include <Ice/LocalException.h> -#include <Ice/ConnectionI.h> // For implementation of getConnectionInfo. using namespace std; using namespace Ice; @@ -77,71 +76,3 @@ IceSSL::PluginI::setPasswordPrompt(const PasswordPromptPtr& prompt) { _instance->setPasswordPrompt(prompt); } - -const char* IceSSL::ConnectionInvalidException::_name = "IceSSL::ConnectionInvalidException"; - -ConnectionInvalidException::ConnectionInvalidException(const char* file, int line, const string& r) : - Exception(file, line), - reason(r) -{ -} - -ConnectionInvalidException::~ConnectionInvalidException() throw() -{ -} - -string -ConnectionInvalidException::ice_name() const -{ - return _name; -} - -Exception* -ConnectionInvalidException::ice_clone() const -{ - return new ConnectionInvalidException(*this); -} - -void -ConnectionInvalidException::ice_throw() const -{ - throw *this; -} - -IceSSL::ConnectionInfo -IceSSL::getConnectionInfo(const ConnectionPtr& connection) -{ - Ice::ConnectionIPtr con = Ice::ConnectionIPtr::dynamicCast(connection); - assert(con); - - // - // Lock the connection directly. This is done because the only - // thing that prevents the transceiver from being closed during - // the duration of the invocation is the connection. - // - IceUtil::Monitor<IceUtil::Mutex>::Lock sync(*con.get()); - IceInternal::TransceiverPtr transceiver = con->getTransceiver(); - if(!transceiver) - { - throw ConnectionInvalidException(__FILE__, __LINE__, "connection closed"); - } - - TransceiverIPtr ssltransceiver = TransceiverIPtr::dynamicCast(con->getTransceiver()); - if(!ssltransceiver) - { - throw ConnectionInvalidException(__FILE__, __LINE__, "not ssl connection"); - } - - try - { - return ssltransceiver->getConnectionInfo(); - } - catch(const Ice::LocalException& ex) - { - ostringstream os; - os << "couldn't get connection information:\n" << ex << endl; - throw ConnectionInvalidException(__FILE__, __LINE__, os.str()); - } - - return ConnectionInfo(); // Required to prevent compiler warning on Solaris. -} diff --git a/cpp/src/IceSSL/TransceiverI.cpp b/cpp/src/IceSSL/TransceiverI.cpp index 28f59e93756..38406abf16d 100644 --- a/cpp/src/IceSSL/TransceiverI.cpp +++ b/cpp/src/IceSSL/TransceiverI.cpp @@ -234,7 +234,7 @@ IceSSL::TransceiverI::initialize() } } - _instance->verifyPeer(_ssl, _fd, _host, _adapterName, _incoming); + _instance->verifyPeer(_ssl, _fd, _host, getNativeConnectionInfo()); _state = StateHandshakeComplete; } catch(const Ice::LocalException& ex) @@ -781,45 +781,7 @@ IceSSL::TransceiverI::toString() const Ice::ConnectionInfoPtr IceSSL::TransceiverI::getInfo() const { - assert(_fd != INVALID_SOCKET && _ssl != 0); - - SSLConnectionInfoPtr info = new SSLConnectionInfo(); - IceInternal::fdToAddressAndPort(_fd, info->localAddress, info->localPort, info->remoteAddress, info->remotePort); - - // - // On the client side, SSL_get_peer_cert_chain returns the entire chain of certs. - // On the server side, the peer certificate must be obtained separately. - // - // Since we have no clear idea whether the connection is server or client side, - // the peer certificate is obtained separately and compared against the first - // certificate in the chain. If they are not the same, it is added to the chain. - // - X509* cert = SSL_get_peer_certificate(_ssl); - STACK_OF(X509)* chain = SSL_get_peer_cert_chain(_ssl); - if(cert != 0 && (chain == 0 || sk_X509_num(chain) == 0 || cert != sk_X509_value(chain, 0))) - { - CertificatePtr certificate = new Certificate(cert); - info->certs.push_back(certificate->encode()); - } - else - { - X509_free(cert); - } - - if(chain != 0) - { - for(int i = 0; i < sk_X509_num(chain); ++i) - { - // - // Duplicate the certificate since the stack comes straight from the SSL connection. - // - CertificatePtr certificate = new Certificate(X509_dup(sk_X509_value(chain, i))); - info->certs.push_back(certificate->encode()); - } - } - - info->cipher = SSL_get_cipher_name(_ssl); // Nothing needs to be free'd. - return info; + return getNativeConnectionInfo(); } void @@ -831,16 +793,6 @@ IceSSL::TransceiverI::checkSendSize(const IceInternal::Buffer& buf, size_t messa } } -IceSSL::ConnectionInfo -IceSSL::TransceiverI::getConnectionInfo() const -{ - // - // This can only be called on an open transceiver. - // - assert(_fd != INVALID_SOCKET); - return populateConnectionInfo(_ssl, _fd, _adapterName, _incoming); -} - IceSSL::TransceiverI::TransceiverI(const InstancePtr& instance, SOCKET fd, const string& host, const struct sockaddr_storage& addr) : IceInternal::NativeInfo(fd), @@ -903,6 +855,53 @@ IceSSL::TransceiverI::~TransceiverI() assert(_fd == INVALID_SOCKET); } +NativeConnectionInfoPtr +IceSSL::TransceiverI::getNativeConnectionInfo() const +{ + assert(_fd != INVALID_SOCKET && _ssl != 0); + + NativeConnectionInfoPtr info = new NativeConnectionInfo(); + IceInternal::fdToAddressAndPort(_fd, info->localAddress, info->localPort, info->remoteAddress, info->remotePort); + + // + // On the client side, SSL_get_peer_cert_chain returns the entire chain of certs. + // On the server side, the peer certificate must be obtained separately. + // + // Since we have no clear idea whether the connection is server or client side, + // the peer certificate is obtained separately and compared against the first + // certificate in the chain. If they are not the same, it is added to the chain. + // + X509* cert = SSL_get_peer_certificate(_ssl); + STACK_OF(X509)* chain = SSL_get_peer_cert_chain(_ssl); + if(cert != 0 && (chain == 0 || sk_X509_num(chain) == 0 || cert != sk_X509_value(chain, 0))) + { + CertificatePtr certificate = new Certificate(cert); + info->nativeCerts.push_back(certificate); + info->certs.push_back(certificate->encode()); + } + else + { + X509_free(cert); + } + + if(chain != 0) + { + for(int i = 0; i < sk_X509_num(chain); ++i) + { + // + // Duplicate the certificate since the stack comes straight from the SSL connection. + // + CertificatePtr certificate = new Certificate(X509_dup(sk_X509_value(chain, i))); + info->nativeCerts.push_back(certificate); + info->certs.push_back(certificate->encode()); + } + } + + info->cipher = SSL_get_cipher_name(_ssl); // Nothing needs to be free'd. + info->adapterName = _adapterName; + info->incoming = _incoming; + return info; +} #ifdef ICE_USE_IOCP bool IceSSL::TransceiverI::receive() diff --git a/cpp/src/IceSSL/TransceiverI.h b/cpp/src/IceSSL/TransceiverI.h index f852d7df7c6..461221523ac 100644 --- a/cpp/src/IceSSL/TransceiverI.h +++ b/cpp/src/IceSSL/TransceiverI.h @@ -58,13 +58,13 @@ public: virtual Ice::ConnectionInfoPtr getInfo() const; virtual void checkSendSize(const IceInternal::Buffer&, size_t); - ConnectionInfo getConnectionInfo() const; - private: TransceiverI(const InstancePtr&, SOCKET, const std::string&, const struct sockaddr_storage&); TransceiverI(const InstancePtr&, SOCKET, const std::string&); virtual ~TransceiverI(); + + virtual NativeConnectionInfoPtr getNativeConnectionInfo() const; #ifdef ICE_USE_IOCP bool send(); diff --git a/cpp/src/IceSSL/TrustManager.cpp b/cpp/src/IceSSL/TrustManager.cpp index cc36d651ddc..31f8709b9b7 100644 --- a/cpp/src/IceSSL/TrustManager.cpp +++ b/cpp/src/IceSSL/TrustManager.cpp @@ -62,7 +62,7 @@ TrustManager::TrustManager(const Ice::CommunicatorPtr& communicator) : } bool -TrustManager::verify(const ConnectionInfo& info) +TrustManager::verify(const NativeConnectionInfoPtr& info) { list<list<DistinguishedName> > reject, accept; @@ -70,15 +70,15 @@ TrustManager::verify(const ConnectionInfo& info) { reject.push_back(_rejectAll); } - if(info.incoming) + if(info->incoming) { if(_rejectAllServer.size() > 0) { reject.push_back(_rejectAllServer); } - if(info.adapterName.size() > 0) + if(info->adapterName.size() > 0) { - map<string, list<DistinguishedName> >::const_iterator p = _rejectServer.find(info.adapterName); + map<string, list<DistinguishedName> >::const_iterator p = _rejectServer.find(info->adapterName); if(p != _rejectServer.end()) { reject.push_back(p->second); @@ -97,15 +97,15 @@ TrustManager::verify(const ConnectionInfo& info) { accept.push_back(_acceptAll); } - if(info.incoming) + if(info->incoming) { if(_acceptAllServer.size() > 0) { accept.push_back(_acceptAllServer); } - if(info.adapterName.size() > 0) + if(info->adapterName.size() > 0) { - map<string, list<DistinguishedName> >::const_iterator p = _acceptServer.find(info.adapterName); + map<string, list<DistinguishedName> >::const_iterator p = _acceptServer.find(info->adapterName); if(p != _acceptServer.end()) { accept.push_back(p->second); @@ -131,50 +131,26 @@ TrustManager::verify(const ConnectionInfo& info) // // If there is no certificate then we match false. // - if(info.certs.size() != 0) + if(info->nativeCerts.size() != 0) { - DistinguishedName subject = info.certs[0]->getSubjectDN(); + DistinguishedName subject = info->nativeCerts[0]->getSubjectDN(); if(_traceLevel > 0) { Ice::Trace trace(_communicator->getLogger(), "Security"); - if(info.incoming) + if(info->incoming) { trace << "trust manager evaluating client:\n" << "subject = " << string(subject) << '\n' - << "adapter = " << info.adapterName << '\n' - << "local addr = " << IceInternal::addrToString(info.localAddr) << '\n' - << "remote addr = "; - if(info.remoteAddr.ss_family == AF_UNSPEC) - { - // - // The remote address may not be available when using Windows XP Service Pack 2 - // and IPv6 (see populateConnectionInfo). - // - trace << "<not available>"; - } - else - { - trace << IceInternal::addrToString(info.remoteAddr); - } + << "adapter = " << info->adapterName << '\n' + << "local addr = " << info->localAddress << ":" << info->localPort << '\n' + << "remote addr = " << info->remoteAddress << ":" << info->remotePort; } else { trace << "trust manager evaluating server:\n" << "subject = " << string(subject) << '\n' - << "local addr = " << IceInternal::addrToString(info.localAddr) << '\n' - << "remote addr = "; - if(info.remoteAddr.ss_family == AF_UNSPEC) - { - // - // The remote address may not be available when using Windows XP Service Pack 2 - // and IPv6 (see populateConnectionInfo). - // - trace << "<not available>"; - } - else - { - trace << IceInternal::addrToString(info.remoteAddr); - } + << "local addr = " << info->localAddress << ":" << info->localPort << '\n' + << "remote addr = " << info->remoteAddress << ":" << info->remotePort; } } diff --git a/cpp/src/IceSSL/TrustManager.h b/cpp/src/IceSSL/TrustManager.h index 1e8eb09db2d..2adf4a5a972 100644 --- a/cpp/src/IceSSL/TrustManager.h +++ b/cpp/src/IceSSL/TrustManager.h @@ -25,7 +25,7 @@ public: TrustManager(const Ice::CommunicatorPtr&); - bool verify(const ConnectionInfo&); + bool verify(const NativeConnectionInfoPtr&); private: diff --git a/cpp/src/IceSSL/Util.cpp b/cpp/src/IceSSL/Util.cpp index e472d1f2e4e..54b9b9c3ebd 100644 --- a/cpp/src/IceSSL/Util.cpp +++ b/cpp/src/IceSSL/Util.cpp @@ -317,74 +317,6 @@ IceSSL::checkPath(string& path, const string& defaultDir, bool dir) return false; } -IceSSL::ConnectionInfo -IceSSL::populateConnectionInfo(SSL* ssl, SOCKET fd, const string& adapterName, bool incoming) -{ - ConnectionInfo info; - info.adapterName = adapterName; - info.incoming = incoming; - - assert(ssl != 0); - - // - // On the client side, SSL_get_peer_cert_chain returns the entire chain of certs. - // On the server side, the peer certificate must be obtained separately. - // - // Since we have no clear idea whether the connection is server or client side, - // the peer certificate is obtained separately and compared against the first - // certificate in the chain. If they are not the same, it is added to the chain. - // - X509* cert = SSL_get_peer_certificate(ssl); - STACK_OF(X509)* chain = SSL_get_peer_cert_chain(ssl); - if(cert != 0 && (chain == 0 || sk_X509_num(chain) == 0 || cert != sk_X509_value(chain, 0))) - { - info.certs.push_back(new Certificate(cert)); - } - else - { - X509_free(cert); - } - - if(chain != 0) - { - for(int i = 0; i < sk_X509_num(chain); ++i) - { - X509* cert = sk_X509_value(chain, i); - // - // Duplicate the certificate since the stack comes straight from the SSL connection. - // - info.certs.push_back(new Certificate(X509_dup(cert))); - } - } - - info.cipher = SSL_get_cipher_name(ssl); // Nothing needs to be free'd. - - IceInternal::fdToLocalAddress(fd, info.localAddr); - - if(!IceInternal::fdToRemoteAddress(fd, info.remoteAddr)) - { -#ifdef _WIN32 - // - // A bug exists in Windows XP Service Pack 2 that causes getpeername to return a - // "socket not connected" error when using IPv6. See the following bug report: - // - // https://connect.microsoft.com/WNDP/feedback/ViewFeedback.aspx?FeedbackID=338445 - // - // As a workaround, we do not raise a socket exception, but instead return a - // "null" value for the remote address. - // - memset(&info.remoteAddr, 0, sizeof(info.remoteAddr)); - info.remoteAddr.ss_family = AF_UNSPEC; -#else - SocketException ex(__FILE__, __LINE__); - ex.error = IceInternal::getSocketErrno(); - throw ex; -#endif - } - - return info; -} - string IceSSL::getSslErrors(bool verbose) { diff --git a/cpp/src/IceSSL/Util.h b/cpp/src/IceSSL/Util.h index 7696f6de547..a3f2cef105b 100644 --- a/cpp/src/IceSSL/Util.h +++ b/cpp/src/IceSSL/Util.h @@ -53,11 +53,6 @@ private: bool checkPath(std::string&, const std::string&, bool); // -// Create a ConnectionInfo value. -// -ConnectionInfo populateConnectionInfo(SSL*, SOCKET, const std::string&, bool); - -// // Accumulate the OpenSSL error stack into a string. // std::string getSslErrors(bool); diff --git a/cpp/test/Ice/Makefile b/cpp/test/Ice/Makefile index 7b0edc4d3d4..9c6489410b1 100644 --- a/cpp/test/Ice/Makefile +++ b/cpp/test/Ice/Makefile @@ -14,6 +14,7 @@ include $(top_srcdir)/config/Make.rules SUBDIRS = proxy \ operations \ exceptions \ + info \ inheritance \ facets \ objects \ diff --git a/cpp/test/Ice/Makefile.mak b/cpp/test/Ice/Makefile.mak index 56e917a4444..a9bd907f1a4 100644 --- a/cpp/test/Ice/Makefile.mak +++ b/cpp/test/Ice/Makefile.mak @@ -14,6 +14,7 @@ top_srcdir = ..\.. SUBDIRS = proxy \
operations \
exceptions \
+ info \
inheritance \
facets \
objects \
diff --git a/cpp/test/Ice/background/EndpointI.cpp b/cpp/test/Ice/background/EndpointI.cpp index dace5979f6c..84ba6837fbf 100644 --- a/cpp/test/Ice/background/EndpointI.cpp +++ b/cpp/test/Ice/background/EndpointI.cpp @@ -225,7 +225,7 @@ EndpointI::getInfo() const } bool -EndpointI::operator==(const IceInternal::EndpointI& r) const +EndpointI::operator==(const Ice::LocalObject& r) const { const EndpointI* p = dynamic_cast<const EndpointI*>(&r); if(!p) @@ -243,18 +243,17 @@ EndpointI::operator==(const IceInternal::EndpointI& r) const } bool -EndpointI::operator!=(const IceInternal::EndpointI& r) const -{ - return !operator==(r); -} - -bool -EndpointI::operator<(const IceInternal::EndpointI& r) const +EndpointI::operator<(const Ice::LocalObject& r) const { const EndpointI* p = dynamic_cast<const EndpointI*>(&r); if(!p) { - return type() < r.type(); + const IceInternal::EndpointI* e = dynamic_cast<const IceInternal::EndpointI*>(&r); + if(!e) + { + return false; + } + return type() < e->type(); } if(this == p) @@ -264,3 +263,9 @@ EndpointI::operator<(const IceInternal::EndpointI& r) const return *p->_endpoint < *_endpoint; } + +Ice::Int +EndpointI::hashInit() const +{ + return _endpoint->ice_getHash(); +} diff --git a/cpp/test/Ice/background/EndpointI.h b/cpp/test/Ice/background/EndpointI.h index 0a75031e14f..366afecd150 100644 --- a/cpp/test/Ice/background/EndpointI.h +++ b/cpp/test/Ice/background/EndpointI.h @@ -41,12 +41,12 @@ public: virtual bool datagram() const; virtual bool secure() const; - virtual bool operator==(const IceInternal::EndpointI&) const; - virtual bool operator!=(const IceInternal::EndpointI&) const; - virtual bool operator<(const IceInternal::EndpointI&) const; + virtual bool operator==(const Ice::LocalObject&) const; + virtual bool operator<(const Ice::LocalObject&) const; protected: + virtual Ice::Int hashInit() const; #if !defined(_MSC_VER) || _MSC_VER > 1300 using IceInternal::EndpointI::connectors; #endif @@ -56,15 +56,6 @@ private: EndpointI(const IceInternal::EndpointIPtr&); friend class EndpointFactory; -#if defined(__SUNPRO_CC) - // - // COMPILERFIX: prevent the compiler from emitting a warning about - // hidding these operators. - // - using LocalObject::operator==; - using LocalObject::operator<; -#endif - const IceInternal::EndpointIPtr _endpoint; const ConfigurationPtr _configuration; }; diff --git a/cpp/test/Ice/info/.depend b/cpp/test/Ice/info/.depend new file mode 100644 index 00000000000..519b9613f1b --- /dev/null +++ b/cpp/test/Ice/info/.depend @@ -0,0 +1,7 @@ +Test$(OBJEXT): Test.cpp Test.h $(includedir)/Ice/LocalObjectF.h $(includedir)/IceUtil/Shared.h $(includedir)/IceUtil/Config.h $(includedir)/Ice/Handle.h $(includedir)/IceUtil/Handle.h $(includedir)/IceUtil/Exception.h $(includedir)/Ice/Config.h $(includedir)/Ice/ProxyHandle.h $(includedir)/Ice/ProxyF.h $(includedir)/Ice/ObjectF.h $(includedir)/Ice/GCCountMap.h $(includedir)/Ice/GCShared.h $(includedir)/Ice/Exception.h $(includedir)/Ice/LocalObject.h $(includedir)/Ice/Proxy.h $(includedir)/IceUtil/Mutex.h $(includedir)/IceUtil/Lock.h $(includedir)/IceUtil/ThreadException.h $(includedir)/IceUtil/Time.h $(includedir)/IceUtil/MutexProtocol.h $(includedir)/Ice/ProxyFactoryF.h $(includedir)/Ice/ConnectionIF.h $(includedir)/Ice/RequestHandlerF.h $(includedir)/Ice/EndpointIF.h $(includedir)/Ice/EndpointF.h $(includedir)/Ice/UndefSysMacros.h $(includedir)/Ice/EndpointTypes.h $(includedir)/Ice/ObjectAdapterF.h $(includedir)/Ice/ReferenceF.h $(includedir)/Ice/OutgoingAsyncF.h $(includedir)/Ice/Current.h $(includedir)/Ice/ConnectionF.h $(includedir)/Ice/Identity.h $(includedir)/Ice/StreamF.h $(includedir)/Ice/CommunicatorF.h $(includedir)/Ice/Object.h $(includedir)/Ice/IncomingAsyncF.h $(includedir)/Ice/Outgoing.h $(includedir)/IceUtil/Monitor.h $(includedir)/IceUtil/Cond.h $(includedir)/Ice/InstanceF.h $(includedir)/Ice/BasicStream.h $(includedir)/Ice/ObjectFactoryF.h $(includedir)/Ice/Buffer.h $(includedir)/Ice/Protocol.h $(includedir)/Ice/StringConverter.h $(includedir)/Ice/Plugin.h $(includedir)/Ice/LoggerF.h $(includedir)/Ice/BuiltinSequences.h $(includedir)/IceUtil/Unicode.h $(includedir)/Ice/OutgoingAsync.h $(includedir)/IceUtil/Timer.h $(includedir)/IceUtil/Thread.h $(includedir)/Ice/Incoming.h $(includedir)/Ice/ServantLocatorF.h $(includedir)/Ice/ServantManagerF.h $(includedir)/Ice/Direct.h $(includedir)/Ice/LocalException.h $(includedir)/Ice/ObjectFactory.h $(includedir)/IceUtil/Iterator.h $(includedir)/IceUtil/ScopedArray.h +Client$(OBJEXT): Client.cpp $(includedir)/Ice/Ice.h $(includedir)/Ice/Initialize.h $(includedir)/Ice/CommunicatorF.h $(includedir)/Ice/LocalObjectF.h $(includedir)/IceUtil/Shared.h $(includedir)/IceUtil/Config.h $(includedir)/Ice/Handle.h $(includedir)/IceUtil/Handle.h $(includedir)/IceUtil/Exception.h $(includedir)/Ice/Config.h $(includedir)/Ice/ProxyHandle.h $(includedir)/Ice/ProxyF.h $(includedir)/Ice/ObjectF.h $(includedir)/Ice/GCCountMap.h $(includedir)/Ice/GCShared.h $(includedir)/Ice/Exception.h $(includedir)/Ice/LocalObject.h $(includedir)/Ice/UndefSysMacros.h $(includedir)/Ice/PropertiesF.h $(includedir)/Ice/Proxy.h $(includedir)/IceUtil/Mutex.h $(includedir)/IceUtil/Lock.h $(includedir)/IceUtil/ThreadException.h $(includedir)/IceUtil/Time.h $(includedir)/IceUtil/MutexProtocol.h $(includedir)/Ice/ProxyFactoryF.h $(includedir)/Ice/ConnectionIF.h $(includedir)/Ice/RequestHandlerF.h $(includedir)/Ice/EndpointIF.h $(includedir)/Ice/EndpointF.h $(includedir)/Ice/EndpointTypes.h $(includedir)/Ice/ObjectAdapterF.h $(includedir)/Ice/ReferenceF.h $(includedir)/Ice/OutgoingAsyncF.h $(includedir)/Ice/Current.h $(includedir)/Ice/ConnectionF.h $(includedir)/Ice/Identity.h $(includedir)/Ice/StreamF.h $(includedir)/Ice/Object.h $(includedir)/Ice/IncomingAsyncF.h $(includedir)/Ice/InstanceF.h $(includedir)/Ice/LoggerF.h $(includedir)/Ice/StatsF.h $(includedir)/Ice/StringConverter.h $(includedir)/Ice/Plugin.h $(includedir)/Ice/BuiltinSequences.h $(includedir)/IceUtil/Unicode.h $(includedir)/Ice/LocalException.h $(includedir)/Ice/Properties.h $(includedir)/Ice/Outgoing.h $(includedir)/IceUtil/Monitor.h $(includedir)/IceUtil/Cond.h $(includedir)/Ice/BasicStream.h $(includedir)/Ice/ObjectFactoryF.h $(includedir)/Ice/Buffer.h $(includedir)/Ice/Protocol.h $(includedir)/Ice/OutgoingAsync.h $(includedir)/IceUtil/Timer.h $(includedir)/IceUtil/Thread.h $(includedir)/Ice/Incoming.h $(includedir)/Ice/ServantLocatorF.h $(includedir)/Ice/ServantManagerF.h $(includedir)/Ice/Direct.h $(includedir)/Ice/Logger.h $(includedir)/Ice/LoggerUtil.h $(includedir)/Ice/Stats.h $(includedir)/Ice/Communicator.h $(includedir)/Ice/RouterF.h $(includedir)/Ice/LocatorF.h $(includedir)/Ice/PluginF.h $(includedir)/Ice/ImplicitContextF.h $(includedir)/Ice/ObjectFactory.h $(includedir)/Ice/ObjectAdapter.h $(includedir)/Ice/FacetMap.h $(includedir)/Ice/Endpoint.h $(includedir)/Ice/ServantLocator.h $(includedir)/Ice/IncomingAsync.h $(includedir)/Ice/Process.h $(includedir)/Ice/Application.h $(includedir)/Ice/Connection.h $(includedir)/Ice/Functional.h $(includedir)/IceUtil/Functional.h $(includedir)/Ice/Stream.h $(includedir)/Ice/ImplicitContext.h $(includedir)/Ice/Locator.h $(includedir)/Ice/FactoryTableInit.h $(includedir)/Ice/FactoryTable.h $(includedir)/IceUtil/StaticMutex.h $(includedir)/Ice/UserExceptionFactory.h $(includedir)/Ice/ProcessF.h $(includedir)/Ice/Router.h $(includedir)/Ice/DispatchInterceptor.h $(includedir)/Ice/IconvStringConverter.h ../../include/TestCommon.h Test.h +AllTests$(OBJEXT): AllTests.cpp $(includedir)/IceUtil/Random.h $(includedir)/IceUtil/Config.h $(includedir)/IceUtil/Exception.h $(includedir)/Ice/Ice.h $(includedir)/Ice/Initialize.h $(includedir)/Ice/CommunicatorF.h $(includedir)/Ice/LocalObjectF.h $(includedir)/IceUtil/Shared.h $(includedir)/Ice/Handle.h $(includedir)/IceUtil/Handle.h $(includedir)/Ice/Config.h $(includedir)/Ice/ProxyHandle.h $(includedir)/Ice/ProxyF.h $(includedir)/Ice/ObjectF.h $(includedir)/Ice/GCCountMap.h $(includedir)/Ice/GCShared.h $(includedir)/Ice/Exception.h $(includedir)/Ice/LocalObject.h $(includedir)/Ice/UndefSysMacros.h $(includedir)/Ice/PropertiesF.h $(includedir)/Ice/Proxy.h $(includedir)/IceUtil/Mutex.h $(includedir)/IceUtil/Lock.h $(includedir)/IceUtil/ThreadException.h $(includedir)/IceUtil/Time.h $(includedir)/IceUtil/MutexProtocol.h $(includedir)/Ice/ProxyFactoryF.h $(includedir)/Ice/ConnectionIF.h $(includedir)/Ice/RequestHandlerF.h $(includedir)/Ice/EndpointIF.h $(includedir)/Ice/EndpointF.h $(includedir)/Ice/EndpointTypes.h $(includedir)/Ice/ObjectAdapterF.h $(includedir)/Ice/ReferenceF.h $(includedir)/Ice/OutgoingAsyncF.h $(includedir)/Ice/Current.h $(includedir)/Ice/ConnectionF.h $(includedir)/Ice/Identity.h $(includedir)/Ice/StreamF.h $(includedir)/Ice/Object.h $(includedir)/Ice/IncomingAsyncF.h $(includedir)/Ice/InstanceF.h $(includedir)/Ice/LoggerF.h $(includedir)/Ice/StatsF.h $(includedir)/Ice/StringConverter.h $(includedir)/Ice/Plugin.h $(includedir)/Ice/BuiltinSequences.h $(includedir)/IceUtil/Unicode.h $(includedir)/Ice/LocalException.h $(includedir)/Ice/Properties.h $(includedir)/Ice/Outgoing.h $(includedir)/IceUtil/Monitor.h $(includedir)/IceUtil/Cond.h $(includedir)/Ice/BasicStream.h $(includedir)/Ice/ObjectFactoryF.h $(includedir)/Ice/Buffer.h $(includedir)/Ice/Protocol.h $(includedir)/Ice/OutgoingAsync.h $(includedir)/IceUtil/Timer.h $(includedir)/IceUtil/Thread.h $(includedir)/Ice/Incoming.h $(includedir)/Ice/ServantLocatorF.h $(includedir)/Ice/ServantManagerF.h $(includedir)/Ice/Direct.h $(includedir)/Ice/Logger.h $(includedir)/Ice/LoggerUtil.h $(includedir)/Ice/Stats.h $(includedir)/Ice/Communicator.h $(includedir)/Ice/RouterF.h $(includedir)/Ice/LocatorF.h $(includedir)/Ice/PluginF.h $(includedir)/Ice/ImplicitContextF.h $(includedir)/Ice/ObjectFactory.h $(includedir)/Ice/ObjectAdapter.h $(includedir)/Ice/FacetMap.h $(includedir)/Ice/Endpoint.h $(includedir)/Ice/ServantLocator.h $(includedir)/Ice/IncomingAsync.h $(includedir)/Ice/Process.h $(includedir)/Ice/Application.h $(includedir)/Ice/Connection.h $(includedir)/Ice/Functional.h $(includedir)/IceUtil/Functional.h $(includedir)/Ice/Stream.h $(includedir)/Ice/ImplicitContext.h $(includedir)/Ice/Locator.h $(includedir)/Ice/FactoryTableInit.h $(includedir)/Ice/FactoryTable.h $(includedir)/IceUtil/StaticMutex.h $(includedir)/Ice/UserExceptionFactory.h $(includedir)/Ice/ProcessF.h $(includedir)/Ice/Router.h $(includedir)/Ice/DispatchInterceptor.h $(includedir)/Ice/IconvStringConverter.h ../../include/TestCommon.h Test.h +TestI$(OBJEXT): TestI.cpp $(includedir)/Ice/Ice.h $(includedir)/Ice/Initialize.h $(includedir)/Ice/CommunicatorF.h $(includedir)/Ice/LocalObjectF.h $(includedir)/IceUtil/Shared.h $(includedir)/IceUtil/Config.h $(includedir)/Ice/Handle.h $(includedir)/IceUtil/Handle.h $(includedir)/IceUtil/Exception.h $(includedir)/Ice/Config.h $(includedir)/Ice/ProxyHandle.h $(includedir)/Ice/ProxyF.h $(includedir)/Ice/ObjectF.h $(includedir)/Ice/GCCountMap.h $(includedir)/Ice/GCShared.h $(includedir)/Ice/Exception.h $(includedir)/Ice/LocalObject.h $(includedir)/Ice/UndefSysMacros.h $(includedir)/Ice/PropertiesF.h $(includedir)/Ice/Proxy.h $(includedir)/IceUtil/Mutex.h $(includedir)/IceUtil/Lock.h $(includedir)/IceUtil/ThreadException.h $(includedir)/IceUtil/Time.h $(includedir)/IceUtil/MutexProtocol.h $(includedir)/Ice/ProxyFactoryF.h $(includedir)/Ice/ConnectionIF.h $(includedir)/Ice/RequestHandlerF.h $(includedir)/Ice/EndpointIF.h $(includedir)/Ice/EndpointF.h $(includedir)/Ice/EndpointTypes.h $(includedir)/Ice/ObjectAdapterF.h $(includedir)/Ice/ReferenceF.h $(includedir)/Ice/OutgoingAsyncF.h $(includedir)/Ice/Current.h $(includedir)/Ice/ConnectionF.h $(includedir)/Ice/Identity.h $(includedir)/Ice/StreamF.h $(includedir)/Ice/Object.h $(includedir)/Ice/IncomingAsyncF.h $(includedir)/Ice/InstanceF.h $(includedir)/Ice/LoggerF.h $(includedir)/Ice/StatsF.h $(includedir)/Ice/StringConverter.h $(includedir)/Ice/Plugin.h $(includedir)/Ice/BuiltinSequences.h $(includedir)/IceUtil/Unicode.h $(includedir)/Ice/LocalException.h $(includedir)/Ice/Properties.h $(includedir)/Ice/Outgoing.h $(includedir)/IceUtil/Monitor.h $(includedir)/IceUtil/Cond.h $(includedir)/Ice/BasicStream.h $(includedir)/Ice/ObjectFactoryF.h $(includedir)/Ice/Buffer.h $(includedir)/Ice/Protocol.h $(includedir)/Ice/OutgoingAsync.h $(includedir)/IceUtil/Timer.h $(includedir)/IceUtil/Thread.h $(includedir)/Ice/Incoming.h $(includedir)/Ice/ServantLocatorF.h $(includedir)/Ice/ServantManagerF.h $(includedir)/Ice/Direct.h $(includedir)/Ice/Logger.h $(includedir)/Ice/LoggerUtil.h $(includedir)/Ice/Stats.h $(includedir)/Ice/Communicator.h $(includedir)/Ice/RouterF.h $(includedir)/Ice/LocatorF.h $(includedir)/Ice/PluginF.h $(includedir)/Ice/ImplicitContextF.h $(includedir)/Ice/ObjectFactory.h $(includedir)/Ice/ObjectAdapter.h $(includedir)/Ice/FacetMap.h $(includedir)/Ice/Endpoint.h $(includedir)/Ice/ServantLocator.h $(includedir)/Ice/IncomingAsync.h $(includedir)/Ice/Process.h $(includedir)/Ice/Application.h $(includedir)/Ice/Connection.h $(includedir)/Ice/Functional.h $(includedir)/IceUtil/Functional.h $(includedir)/Ice/Stream.h $(includedir)/Ice/ImplicitContext.h $(includedir)/Ice/Locator.h $(includedir)/Ice/FactoryTableInit.h $(includedir)/Ice/FactoryTable.h $(includedir)/IceUtil/StaticMutex.h $(includedir)/Ice/UserExceptionFactory.h $(includedir)/Ice/ProcessF.h $(includedir)/Ice/Router.h $(includedir)/Ice/DispatchInterceptor.h $(includedir)/Ice/IconvStringConverter.h TestI.h Test.h +Server$(OBJEXT): Server.cpp $(includedir)/Ice/Ice.h $(includedir)/Ice/Initialize.h $(includedir)/Ice/CommunicatorF.h $(includedir)/Ice/LocalObjectF.h $(includedir)/IceUtil/Shared.h $(includedir)/IceUtil/Config.h $(includedir)/Ice/Handle.h $(includedir)/IceUtil/Handle.h $(includedir)/IceUtil/Exception.h $(includedir)/Ice/Config.h $(includedir)/Ice/ProxyHandle.h $(includedir)/Ice/ProxyF.h $(includedir)/Ice/ObjectF.h $(includedir)/Ice/GCCountMap.h $(includedir)/Ice/GCShared.h $(includedir)/Ice/Exception.h $(includedir)/Ice/LocalObject.h $(includedir)/Ice/UndefSysMacros.h $(includedir)/Ice/PropertiesF.h $(includedir)/Ice/Proxy.h $(includedir)/IceUtil/Mutex.h $(includedir)/IceUtil/Lock.h $(includedir)/IceUtil/ThreadException.h $(includedir)/IceUtil/Time.h $(includedir)/IceUtil/MutexProtocol.h $(includedir)/Ice/ProxyFactoryF.h $(includedir)/Ice/ConnectionIF.h $(includedir)/Ice/RequestHandlerF.h $(includedir)/Ice/EndpointIF.h $(includedir)/Ice/EndpointF.h $(includedir)/Ice/EndpointTypes.h $(includedir)/Ice/ObjectAdapterF.h $(includedir)/Ice/ReferenceF.h $(includedir)/Ice/OutgoingAsyncF.h $(includedir)/Ice/Current.h $(includedir)/Ice/ConnectionF.h $(includedir)/Ice/Identity.h $(includedir)/Ice/StreamF.h $(includedir)/Ice/Object.h $(includedir)/Ice/IncomingAsyncF.h $(includedir)/Ice/InstanceF.h $(includedir)/Ice/LoggerF.h $(includedir)/Ice/StatsF.h $(includedir)/Ice/StringConverter.h $(includedir)/Ice/Plugin.h $(includedir)/Ice/BuiltinSequences.h $(includedir)/IceUtil/Unicode.h $(includedir)/Ice/LocalException.h $(includedir)/Ice/Properties.h $(includedir)/Ice/Outgoing.h $(includedir)/IceUtil/Monitor.h $(includedir)/IceUtil/Cond.h $(includedir)/Ice/BasicStream.h $(includedir)/Ice/ObjectFactoryF.h $(includedir)/Ice/Buffer.h $(includedir)/Ice/Protocol.h $(includedir)/Ice/OutgoingAsync.h $(includedir)/IceUtil/Timer.h $(includedir)/IceUtil/Thread.h $(includedir)/Ice/Incoming.h $(includedir)/Ice/ServantLocatorF.h $(includedir)/Ice/ServantManagerF.h $(includedir)/Ice/Direct.h $(includedir)/Ice/Logger.h $(includedir)/Ice/LoggerUtil.h $(includedir)/Ice/Stats.h $(includedir)/Ice/Communicator.h $(includedir)/Ice/RouterF.h $(includedir)/Ice/LocatorF.h $(includedir)/Ice/PluginF.h $(includedir)/Ice/ImplicitContextF.h $(includedir)/Ice/ObjectFactory.h $(includedir)/Ice/ObjectAdapter.h $(includedir)/Ice/FacetMap.h $(includedir)/Ice/Endpoint.h $(includedir)/Ice/ServantLocator.h $(includedir)/Ice/IncomingAsync.h $(includedir)/Ice/Process.h $(includedir)/Ice/Application.h $(includedir)/Ice/Connection.h $(includedir)/Ice/Functional.h $(includedir)/IceUtil/Functional.h $(includedir)/Ice/Stream.h $(includedir)/Ice/ImplicitContext.h $(includedir)/Ice/Locator.h $(includedir)/Ice/FactoryTableInit.h $(includedir)/Ice/FactoryTable.h $(includedir)/IceUtil/StaticMutex.h $(includedir)/Ice/UserExceptionFactory.h $(includedir)/Ice/ProcessF.h $(includedir)/Ice/Router.h $(includedir)/Ice/DispatchInterceptor.h $(includedir)/Ice/IconvStringConverter.h TestI.h Test.h +Test.cpp: Test.ice +Test.ice: $(SLICE2CPP) $(SLICEPARSERLIB) diff --git a/cpp/test/Ice/info/.gitignore b/cpp/test/Ice/info/.gitignore new file mode 100644 index 00000000000..67872faa673 --- /dev/null +++ b/cpp/test/Ice/info/.gitignore @@ -0,0 +1,7 @@ +// Generated by makegitignore.py + +// IMPORTANT: Do not edit this file -- any edits made here will be lost! +client +server +Test.cpp +Test.h diff --git a/cpp/test/Ice/info/AllTests.cpp b/cpp/test/Ice/info/AllTests.cpp new file mode 100644 index 00000000000..b19ea3b6915 --- /dev/null +++ b/cpp/test/Ice/info/AllTests.cpp @@ -0,0 +1,169 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#include <Ice/Ice.h> +#include <IceSSL/IceSSL.h> +#include <TestCommon.h> +#include <TestI.h> + +using namespace std; +using namespace Test; + +void +allTests(const Ice::CommunicatorPtr& communicator) +{ + cout << "testing proxy endpoint information... " << flush; + { + Ice::ObjectPrx p1 = communicator->stringToProxy("test -t:default -h tcphost -p 10000 -t 1200 -z:" + "udp -h udphost -p 10001 --interface eth0 --ttl 5:" + "opaque -t 100 -v ABCD"); + + Ice::EndpointSeq endps = p1->ice_getEndpoints(); + + Ice::IPEndpointInfoPtr ipEndpoint = Ice::IPEndpointInfoPtr::dynamicCast(endps[0]->getInfo()); + test(ipEndpoint); + test(ipEndpoint->host == "tcphost"); + test(ipEndpoint->port == 10000); + test(ipEndpoint->timeout == 1200); + test(ipEndpoint->compress); + test(!ipEndpoint->datagram()); + test(ipEndpoint->type() == Ice::TCPEndpointType && !ipEndpoint->secure() || + ipEndpoint->type() == IceSSL::EndpointType && ipEndpoint->secure()); + test(ipEndpoint->type() == Ice::TCPEndpointType && Ice::TCPEndpointInfoPtr::dynamicCast(ipEndpoint) || + ipEndpoint->type() == IceSSL::EndpointType && IceSSL::EndpointInfoPtr::dynamicCast(ipEndpoint)); + + Ice::UDPEndpointInfoPtr udpEndpoint = Ice::UDPEndpointInfoPtr::dynamicCast(endps[1]->getInfo()); + test(udpEndpoint); + test(udpEndpoint->host == "udphost"); + test(udpEndpoint->port == 10001); + test(udpEndpoint->mcastInterface == "eth0"); + test(udpEndpoint->mcastTtl == 5); + test(udpEndpoint->timeout == -1); + test(!udpEndpoint->compress); + test(!udpEndpoint->secure()); + test(udpEndpoint->datagram()); + test(udpEndpoint->type() == 3); + + Ice::OpaqueEndpointInfoPtr opaqueEndpoint = Ice::OpaqueEndpointInfoPtr::dynamicCast(endps[2]->getInfo()); + test(opaqueEndpoint); + } + cout << "ok" << endl; + + string defaultHost = communicator->getProperties()->getProperty("Ice.Default.Host"); + cout << "test object adapter endpoint information... " << flush; + { + communicator->getProperties()->setProperty("TestAdapter.Endpoints", "default -t 15000:udp"); + Ice::ObjectAdapterPtr adapter = communicator->createObjectAdapter("TestAdapter"); + + Ice::EndpointSeq endpoints = adapter->getEndpoints(); + test(endpoints.size() == 2); + Ice::EndpointSeq publishedEndpoints = adapter->getPublishedEndpoints(); + test(endpoints == publishedEndpoints); + + Ice::IPEndpointInfoPtr ipEndpoint = Ice::IPEndpointInfoPtr::dynamicCast(endpoints[0]->getInfo()); + test(ipEndpoint); + test(ipEndpoint->type() == Ice::TCPEndpointType || ipEndpoint->type() == IceSSL::EndpointType); + test(ipEndpoint->host == defaultHost); + test(ipEndpoint->port > 0); + test(ipEndpoint->timeout == 15000); + + Ice::UDPEndpointInfoPtr udpEndpoint = Ice::UDPEndpointInfoPtr::dynamicCast(endpoints[1]->getInfo()); + test(udpEndpoint); + test(udpEndpoint->host == defaultHost); + test(udpEndpoint->datagram()); + test(udpEndpoint->port > 0); + + adapter->destroy(); + + communicator->getProperties()->setProperty("TestAdapter.Endpoints", "default -h * -p 12010"); + communicator->getProperties()->setProperty("TestAdapter.PublishedEndpoints", "default -h 127.0.0.1 -p 12010"); + adapter = communicator->createObjectAdapter("TestAdapter"); + + endpoints = adapter->getEndpoints(); + test(endpoints.size() >= 1); + publishedEndpoints = adapter->getPublishedEndpoints(); + test(publishedEndpoints.size() == 1); + + for(Ice::EndpointSeq::const_iterator p = endpoints.begin(); p != endpoints.end(); ++p) + { + ipEndpoint = Ice::IPEndpointInfoPtr::dynamicCast((*p)->getInfo()); + test(ipEndpoint->port == 12010); + } + + ipEndpoint = Ice::IPEndpointInfoPtr::dynamicCast(publishedEndpoints[0]->getInfo()); + test(ipEndpoint->host == "127.0.0.1"); + test(ipEndpoint->port == 12010); + + adapter->destroy(); + } + cout << "ok" << endl; + + communicator->getProperties()->setProperty("TestAdapter.Endpoints", "default -p 12010:udp -p 12010"); + communicator->getProperties()->setProperty("TestAdapter.PublishedEndpoints", ""); + Ice::ObjectAdapterPtr adapter = communicator->createObjectAdapter("TestAdapter"); + Ice::ObjectPrx base = adapter->addWithUUID(new TestI())->ice_collocationOptimized(false); + adapter->activate(); + + TestIntfPrx test = TestIntfPrx::uncheckedCast(base); + + cout << "test connection endpoint information... " << flush; + { + Ice::EndpointInfoPtr info = base->ice_getConnection()->getEndpoint()->getInfo(); + Ice::IPEndpointInfoPtr ipinfo = Ice::IPEndpointInfoPtr::dynamicCast(info); + test(ipinfo->port == 12010); + test(!ipinfo->compress); + test(ipinfo->host == defaultHost); + + ostringstream os; + + Ice::Context ctx = test->getEndpointInfoAsContext(); + test(ctx["host"] == ipinfo->host); + test(ctx["compress"] == "false"); + istringstream is(ctx["port"]); + int port; + is >> port; + test(port > 0); + + info = base->ice_datagram()->ice_getConnection()->getEndpoint()->getInfo(); + Ice::UDPEndpointInfoPtr udp = Ice::UDPEndpointInfoPtr::dynamicCast(info); + test(udp); + test(udp->port == 12010); + test(udp->host == defaultHost); + } + cout << "ok" << endl; + + cout << "testing connection information... " << flush; + { + Ice::IPConnectionInfoPtr info = Ice::IPConnectionInfoPtr::dynamicCast(base->ice_getConnection()->getInfo()); + test(info); + test(!info->incoming); + test(info->adapterName.empty()); + test(info->remotePort == 12010); + test(info->remoteAddress == defaultHost); + test(info->localAddress == defaultHost); + + ostringstream os; + + Ice::Context ctx = test->getConnectionInfoAsContext(); + test(ctx["incoming"] == "true"); + test(ctx["adapterName"] == "TestAdapter"); + test(ctx["remoteAddress"] == info->localAddress); + test(ctx["localAddress"] == info->remoteAddress); + os.str(""); + os << info->localPort; + test(ctx["remotePort"] == os.str()); + os.str(""); + os << info->remotePort; + test(ctx["localPort"] == os.str()); + } + cout << "ok" << endl; + + communicator->shutdown(); + communicator->waitForShutdown(); +} diff --git a/cpp/test/Ice/info/Client.cpp b/cpp/test/Ice/info/Client.cpp new file mode 100644 index 00000000000..aa569dcf1e9 --- /dev/null +++ b/cpp/test/Ice/info/Client.cpp @@ -0,0 +1,55 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#include <Ice/Ice.h> +#include <TestCommon.h> +#include <Test.h> + +using namespace std; + +int +run(int argc, char* argv[], const Ice::CommunicatorPtr& communicator) +{ + void allTests(const Ice::CommunicatorPtr&); + allTests(communicator); + return EXIT_SUCCESS; +} + +int +main(int argc, char* argv[]) +{ + int status; + Ice::CommunicatorPtr communicator; + + try + { + communicator = Ice::initialize(argc, argv); + status = run(argc, argv, communicator); + } + catch(const Ice::Exception& ex) + { + cerr << ex << endl; + status = EXIT_FAILURE; + } + + if(communicator) + { + try + { + communicator->destroy(); + } + catch(const Ice::Exception& ex) + { + cerr << ex << endl; + status = EXIT_FAILURE; + } + } + + return status; +} diff --git a/cpp/test/Ice/info/Makefile b/cpp/test/Ice/info/Makefile new file mode 100644 index 00000000000..088bc2bbf4c --- /dev/null +++ b/cpp/test/Ice/info/Makefile @@ -0,0 +1,33 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +top_srcdir = ../../.. + +CLIENT = client + +TARGETS = $(CLIENT) + +OBJS = Test.o \ + Client.o \ + AllTests.o \ + TestI.o + +SRCS = $(OBJS:.o=.cpp) + +SLICE_SRCS = Test.ice + +include $(top_srcdir)/config/Make.rules + +CPPFLAGS := -I. -I../../include $(CPPFLAGS) + +$(CLIENT): $(OBJS) + rm -f $@ + $(CXX) $(LDFLAGS) -o $@ $(OBJS) -lIceSSL $(LIBS) + +include .depend diff --git a/cpp/test/Ice/info/Makefile.mak b/cpp/test/Ice/info/Makefile.mak new file mode 100644 index 00000000000..de29a3bd9f8 --- /dev/null +++ b/cpp/test/Ice/info/Makefile.mak @@ -0,0 +1,39 @@ +# **********************************************************************
+#
+# Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved.
+#
+# This copy of Ice is licensed to you under the terms described in the
+# ICE_LICENSE file included in this distribution.
+#
+# **********************************************************************
+
+top_srcdir = ..\..\..
+
+CLIENT = client.exe
+
+TARGETS = $(CLIENT)
+
+OBJS = Test.obj \
+ TestI.obj \
+ Client.obj \
+ AllTests.obj
+
+SRCS = $(OBJS:.obj=.cpp)
+
+!include $(top_srcdir)/config/Make.rules.mak
+
+CPPFLAGS = -I. -I../../include $(CPPFLAGS) -DWIN32_LEAN_AND_MEAN
+
+!if "$(GENERATE_PDB)" == "yes"
+PDBFLAGS = /pdb:$(CLIENT:.exe=.pdb)
+!endif
+
+$(CLIENT): $(OBJS)
+ $(LINK) $(LD_EXEFLAGS) $(PDBFLAGS) $(SETARGV) $(OBJS) $(PREOUT)$@ $(PRELIBS)$(LIBS) icessl$(LIBSUFFIX).lib
+ @if exist $@.manifest echo ^ ^ ^ Embedding manifest using $(MT) && \
+ $(MT) -nologo -manifest $@.manifest -outputresource:$@;#1 && del /q $@.manifest
+
+clean::
+ del /q Test.cpp Test.h
+
+!include .depend
diff --git a/cpp/test/Ice/info/Test.ice b/cpp/test/Ice/info/Test.ice new file mode 100644 index 00000000000..a52655c43e2 --- /dev/null +++ b/cpp/test/Ice/info/Test.ice @@ -0,0 +1,29 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#ifndef TEST_ICE +#define TEST_ICE + +#include <Ice/Current.ice> + +module Test +{ + +interface TestIntf +{ + void shutdown(); + + Ice::Context getEndpointInfoAsContext(); + + Ice::Context getConnectionInfoAsContext(); +}; + +}; + +#endif diff --git a/cpp/test/Ice/info/TestI.cpp b/cpp/test/Ice/info/TestI.cpp new file mode 100644 index 00000000000..55ae27fc120 --- /dev/null +++ b/cpp/test/Ice/info/TestI.cpp @@ -0,0 +1,85 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#include <Ice/Ice.h> +#include <IceSSL/IceSSL.h> +#include <TestCommon.h> +#include <TestI.h> + +using namespace std; +using namespace Ice; +using namespace Test; + +void +TestI::shutdown(const Ice::Current& current) +{ + current.adapter->getCommunicator()->shutdown(); +} + +Ice::Context +TestI::getEndpointInfoAsContext(const Ice::Current& c) +{ + ostringstream os; + + Ice::Context ctx; + Ice::EndpointInfoPtr info = c.con->getEndpoint()->getInfo(); + os << info->timeout; + ctx["timeout"] = os.str(); + ctx["compress"] = info->compress ? "true" : "false"; + ctx["datagram"] = info->datagram() ? "true" : "false"; + ctx["secure"] = info->datagram() ? "true" : "false"; + os.str(""); + os << info->type(); + ctx["type"] = os.str(); + + Ice::IPEndpointInfoPtr ipinfo = Ice::IPEndpointInfoPtr::dynamicCast(info); + test(info); + ctx["host"] = ipinfo->host; + os.str(""); + os << ipinfo->port; + ctx["port"] = os.str(); + + if(Ice::UDPEndpointInfoPtr::dynamicCast(ipinfo)) + { + Ice::UDPEndpointInfoPtr udp = Ice::UDPEndpointInfoPtr::dynamicCast(ipinfo); + ctx["protocolMajor"] = udp->protocolMajor; + ctx["protocolMinor"] = udp->protocolMinor; + ctx["encodingMajor"] = udp->encodingMajor; + ctx["encodingMinor"] = udp->encodingMinor; + ctx["mcastInterface"] = udp->mcastInterface; + ctx["mcastTtl"] = udp->mcastTtl; + } + + return ctx; +} + +Ice::Context +TestI::getConnectionInfoAsContext(const Ice::Current& c) +{ + Ice::Context ctx; + Ice::ConnectionInfoPtr info = c.con->getInfo(); + ctx["adapterName"] = info->adapterName; + ctx["incoming"] = info->incoming ? "true" : "false"; + ostringstream os; + + Ice::IPConnectionInfoPtr ipinfo = Ice::IPConnectionInfoPtr::dynamicCast(info); + test(ipinfo); + ctx["localAddress"] = ipinfo->localAddress; + os.str(""); + os << ipinfo->localPort; + ctx["localPort"] = os.str(); + ctx["remoteAddress"] = ipinfo->remoteAddress; + os.str(""); + os << ipinfo->remotePort; + ctx["remotePort"] = os.str(); + + return ctx; +} + + diff --git a/cpp/test/Ice/info/TestI.h b/cpp/test/Ice/info/TestI.h new file mode 100644 index 00000000000..c0f49c49457 --- /dev/null +++ b/cpp/test/Ice/info/TestI.h @@ -0,0 +1,25 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#ifndef TEST_I_H +#define TEST_I_H + +#include <Test.h> + +class TestI : public Test::TestIntf +{ +public: + + virtual void shutdown(const Ice::Current&); + + virtual Ice::Context getEndpointInfoAsContext(const Ice::Current&); + virtual Ice::Context getConnectionInfoAsContext(const Ice::Current&); +}; + +#endif diff --git a/cpp/test/Ice/info/run.py b/cpp/test/Ice/info/run.py new file mode 100755 index 00000000000..95881aefef1 --- /dev/null +++ b/cpp/test/Ice/info/run.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +import os, sys + +path = [ ".", "..", "../..", "../../..", "../../../.." ] +head = os.path.dirname(sys.argv[0]) +if len(head) > 0: + path = [os.path.join(head, p) for p in path] +path = [os.path.abspath(p) for p in path if os.path.exists(os.path.join(p, "scripts", "TestUtil.py")) ] +if len(path) == 0: + raise "can't find toplevel directory!" +sys.path.append(os.path.join(path[0])) +from scripts import * + +client = os.path.join(os.getcwd(), "client") + +print "starting client...", +clientProc = TestUtil.startClient(client, startReader = False) +print "ok" + +clientProc.startReader() +clientProc.waitTestSuccess() + +TestUtil.cleanup() diff --git a/cpp/test/Ice/proxy/AllTests.cpp b/cpp/test/Ice/proxy/AllTests.cpp index 59b8ebcf246..6b26f035c5b 100644 --- a/cpp/test/Ice/proxy/AllTests.cpp +++ b/cpp/test/Ice/proxy/AllTests.cpp @@ -451,6 +451,13 @@ allTests(const Ice::CommunicatorPtr& communicator) test(compObj1 < compObj2); test(!(compObj2 < compObj1)); + Ice::EndpointSeq endpts1 = communicator->stringToProxy("foo:tcp -h 127.0.0.1 -p 10000")->ice_getEndpoints(); + Ice::EndpointSeq endpts2 = communicator->stringToProxy("foo:tcp -h 127.0.0.1 -p 10001")->ice_getEndpoints(); + test(endpts1 != endpts2); + test(endpts1 < endpts2); + test(!(endpts2 < endpts1)); + test(endpts1 == communicator->stringToProxy("foo:tcp -h 127.0.0.1 -p 10000")->ice_getEndpoints()); + // // TODO: Ideally we should also test comparison of fixed proxies. // @@ -712,31 +719,5 @@ allTests(const Ice::CommunicatorPtr& communicator) cout << "ok" << endl; - cout << "testing endpoint information... " << flush; - - p1 = communicator->stringToProxy("test -t:tcp -h tcphost -p 10000 -t 1200 -z:udp -h udphost -p 10001 --interface eth0 --ttl 5:opaque -t 100 -v ABCD"); - Ice::EndpointSeq endps = p1->ice_getEndpoints(); - - Ice::TcpEndpointInfoPtr tcpEndpoint = Ice::TcpEndpointInfoPtr::dynamicCast(endps[0]->getInfo()); - test(tcpEndpoint); - test(tcpEndpoint->host == "tcphost"); - test(tcpEndpoint->port == 10000); - test(tcpEndpoint->timeout == 1200); - test(tcpEndpoint->compress); - - Ice::UdpEndpointInfoPtr udpEndpoint = Ice::UdpEndpointInfoPtr::dynamicCast(endps[1]->getInfo()); - test(udpEndpoint); - test(udpEndpoint->host == "udphost"); - test(udpEndpoint->port == 10001); - test(udpEndpoint->mcastInterface == "eth0"); - test(udpEndpoint->mcastTtl == 5); - test(udpEndpoint->timeout == -1); - test(!udpEndpoint->compress); - - Ice::OpaqueEndpointInfoPtr opaqueEndpoint = Ice::OpaqueEndpointInfoPtr::dynamicCast(endps[2]->getInfo()); - test(opaqueEndpoint); - - cout << "ok" << endl; - return cl; } diff --git a/cpp/test/Ice/proxy/TestI.cpp b/cpp/test/Ice/proxy/TestI.cpp index 038759a3a28..14440ed68c4 100644 --- a/cpp/test/Ice/proxy/TestI.cpp +++ b/cpp/test/Ice/proxy/TestI.cpp @@ -11,6 +11,8 @@ #include <TestI.h> #include <TestCommon.h> +using namespace std; + MyDerivedClassI::MyDerivedClassI() { } diff --git a/cpp/test/IceSSL/configuration/AllTests.cpp b/cpp/test/IceSSL/configuration/AllTests.cpp index 3dee0ff41bc..d0a105fcae0 100644 --- a/cpp/test/IceSSL/configuration/AllTests.cpp +++ b/cpp/test/IceSSL/configuration/AllTests.cpp @@ -51,15 +51,15 @@ public: } virtual bool - verify(const IceSSL::ConnectionInfo& info) + verify(const IceSSL::NativeConnectionInfoPtr& info) { - if(info.certs.size() > 0) + if(info->nativeCerts.size() > 0) { // // Subject alternative name // { - vector<pair<int, string> > altNames = info.certs[0]->getSubjectAlternativeNames(); + vector<pair<int, string> > altNames = info->nativeCerts[0]->getSubjectAlternativeNames(); vector<string> ipAddresses; vector<string> dnsNames; for(vector<pair<int, string> >::const_iterator p = altNames.begin(); p != altNames.end(); ++p) @@ -82,7 +82,7 @@ public: // Issuer alternative name // { - vector<pair<int, string> > altNames = info.certs[0]->getIssuerAlternativeNames(); + vector<pair<int, string> > altNames = info->nativeCerts[0]->getIssuerAlternativeNames(); vector<string> ipAddresses; vector<string> emailAddresses; for(vector<pair<int, string> >::const_iterator p = altNames.begin(); p != altNames.end(); ++p) @@ -102,7 +102,7 @@ public: } } - _hadCert = info.certs.size() != 0; + _hadCert = info->nativeCerts.size() != 0; _invoked = true; return _returnValue; } @@ -280,10 +280,11 @@ allTests(const CommunicatorPtr& communicator, const string& testDir) // try { - IceSSL::ConnectionInfo info = IceSSL::getConnectionInfo(server->ice_getConnection()); - test(info.certs.size() == 2); + IceSSL::NativeConnectionInfoPtr info = + IceSSL::NativeConnectionInfoPtr::dynamicCast(server->ice_getConnection()->getInfo()); + test(info->nativeCerts.size() == 2); } - catch(const IceSSL::ConnectionInvalidException&) + catch(const Ice::LocalException&) { test(false); } @@ -385,23 +386,24 @@ allTests(const CommunicatorPtr& communicator, const string& testDir) test(serverCert->verify(caCert->getPublicKey())); test(caCert->verify(caCert->getPublicKey())); - IceSSL::ConnectionInfo info = IceSSL::getConnectionInfo(server->ice_getConnection()); + IceSSL::NativeConnectionInfoPtr info = + IceSSL::NativeConnectionInfoPtr::dynamicCast(server->ice_getConnection()->getInfo()); - test(info.certs.size() == 2); + test(info->nativeCerts.size() == 2); - test(caCert == info.certs[1]); - test(serverCert == info.certs[0]); + test(caCert == info->nativeCerts[1]); + test(serverCert == info->nativeCerts[0]); - test(serverCert != info.certs[1]); - test(caCert != info.certs[0]); + test(serverCert != info->nativeCerts[1]); + test(caCert != info->nativeCerts[0]); - test(info.certs[0]->checkValidity() && info.certs[1]->checkValidity()); - test(!info.certs[0]->checkValidity(IceUtil::Time::seconds(0)) && - !info.certs[1]->checkValidity(IceUtil::Time::seconds(0))); - test(info.certs[0]->verify(info.certs[1]->getPublicKey())); - test(info.certs.size() == 2 && - info.certs[0]->getSubjectDN() == serverCert->getSubjectDN() && - info.certs[0]->getIssuerDN() == serverCert->getIssuerDN()); + test(info->nativeCerts[0]->checkValidity() && info->nativeCerts[1]->checkValidity()); + test(!info->nativeCerts[0]->checkValidity(IceUtil::Time::seconds(0)) && + !info->nativeCerts[1]->checkValidity(IceUtil::Time::seconds(0))); + test(info->nativeCerts[0]->verify(info->nativeCerts[1]->getPublicKey())); + test(info->nativeCerts.size() == 2 && + info->nativeCerts[0]->getSubjectDN() == serverCert->getSubjectDN() && + info->nativeCerts[0]->getIssuerDN() == serverCert->getIssuerDN()); } catch(const LocalException&) { @@ -673,8 +675,9 @@ allTests(const CommunicatorPtr& communicator, const string& testDir) { string cipherSub = "ADH-"; server->checkCipher(cipherSub); - IceSSL::ConnectionInfo info = IceSSL::getConnectionInfo(server->ice_getConnection()); - test(info.cipher.compare(0, cipherSub.size(), cipherSub) == 0); + IceSSL::NativeConnectionInfoPtr info = + IceSSL::NativeConnectionInfoPtr::dynamicCast(server->ice_getConnection()->getInfo()); + test(info->cipher.compare(0, cipherSub.size(), cipherSub) == 0); } catch(const LocalException&) { @@ -1022,8 +1025,9 @@ allTests(const CommunicatorPtr& communicator, const string& testDir) { string cipherSub = "ADH-"; server->checkCipher(cipherSub); - IceSSL::ConnectionInfo info = IceSSL::getConnectionInfo(server->ice_getConnection()); - test(info.cipher.compare(0, cipherSub.size(), cipherSub) == 0); + IceSSL::NativeConnectionInfoPtr info = + IceSSL::NativeConnectionInfoPtr::dynamicCast(server->ice_getConnection()->getInfo()); + test(info->cipher.compare(0, cipherSub.size(), cipherSub) == 0); } catch(const LocalException&) { @@ -1199,7 +1203,7 @@ allTests2(const CommunicatorPtr& communicator, { server->ice_ping(); } - catch(const LocalException&) + catch(const LocalException& ex) { test(false); } diff --git a/cpp/test/IceSSL/configuration/TestI.cpp b/cpp/test/IceSSL/configuration/TestI.cpp index ac320a0f715..5c611d2a052 100644 --- a/cpp/test/IceSSL/configuration/TestI.cpp +++ b/cpp/test/IceSSL/configuration/TestI.cpp @@ -26,10 +26,10 @@ ServerI::noCert(const Ice::Current& c) { try { - IceSSL::ConnectionInfo info = IceSSL::getConnectionInfo(c.con); - test(info.certs.size() == 0); + IceSSL::NativeConnectionInfoPtr info = IceSSL::NativeConnectionInfoPtr::dynamicCast(c.con->getInfo()); + test(info->nativeCerts.size() == 0); } - catch(const IceSSL::ConnectionInvalidException&) + catch(const Ice::LocalException&) { test(false); } @@ -40,12 +40,12 @@ ServerI::checkCert(const string& subjectDN, const string& issuerDN, const Ice::C { try { - IceSSL::ConnectionInfo info = IceSSL::getConnectionInfo(c.con); - test(info.certs.size() == 2 && - info.certs[0]->getSubjectDN() == IceSSL::DistinguishedName(subjectDN) && - info.certs[0]->getIssuerDN() == IceSSL::DistinguishedName(issuerDN)); + IceSSL::NativeConnectionInfoPtr info = IceSSL::NativeConnectionInfoPtr::dynamicCast(c.con->getInfo()); + test(info->nativeCerts.size() == 2 && + info->nativeCerts[0]->getSubjectDN() == IceSSL::DistinguishedName(subjectDN) && + info->nativeCerts[0]->getIssuerDN() == IceSSL::DistinguishedName(issuerDN)); } - catch(const IceSSL::ConnectionInvalidException&) + catch(const Ice::LocalException&) { test(false); } @@ -56,10 +56,10 @@ ServerI::checkCipher(const string& cipher, const Ice::Current& c) { try { - IceSSL::ConnectionInfo info = IceSSL::getConnectionInfo(c.con); - test(info.cipher.compare(0, cipher.size(), cipher) == 0); + IceSSL::NativeConnectionInfoPtr info = IceSSL::NativeConnectionInfoPtr::dynamicCast(c.con->getInfo()); + test(info->cipher.compare(0, cipher.size(), cipher) == 0); } - catch(const IceSSL::ConnectionInvalidException&) + catch(const Ice::LocalException&) { test(false); } |