diff options
119 files changed, 2019 insertions, 1386 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); } diff --git a/cs/allTests.py b/cs/allTests.py index c93794983ea..1c29ffbbc38 100755 --- a/cs/allTests.py +++ b/cs/allTests.py @@ -29,6 +29,7 @@ tests = [ ("Ice/proxy", ["core"]), ("Ice/operations", ["core"]), ("Ice/exceptions", ["core"]), + ("Ice/info", ["core"]), ("Ice/inheritance", ["core"]), ("Ice/facets", ["core"]), ("Ice/hold", ["core"]), diff --git a/cs/src/Ice/ConnectionI.cs b/cs/src/Ice/ConnectionI.cs index 29bfd692f4f..be475b92c9a 100644 --- a/cs/src/Ice/ConnectionI.cs +++ b/cs/src/Ice/ConnectionI.cs @@ -871,6 +871,11 @@ namespace Ice } } + public Endpoint getEndpoint() + { + return _endpoint; // No mutex protection necessary, _endpoint is immutable. + } + public ObjectPrx createProxy(Identity ident) { // @@ -1341,22 +1346,12 @@ namespace Ice throw _exception; } ConnectionInfo info = _transceiver.getInfo(); - info.endpoint = _endpoint.getInfo(); + info.adapterName = _adapter != null ? _adapter.getName() : ""; + info.incoming = _connector == null; 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. - // - public IceInternal.Transceiver getTransceiver() - { - return _transceiver; - } - public string ice_toString_() { return ToString(); diff --git a/cs/src/Ice/TcpConnector.cs b/cs/src/Ice/TcpConnector.cs index 8a4659c953a..ae31d9afbe5 100644 --- a/cs/src/Ice/TcpConnector.cs +++ b/cs/src/Ice/TcpConnector.cs @@ -50,7 +50,7 @@ namespace IceInternal public short type() { - return TcpEndpointI.TYPE; + return Ice.UDPEndpointType.value; } // diff --git a/cs/src/Ice/TcpEndpointI.cs b/cs/src/Ice/TcpEndpointI.cs index 26e5fd1de8e..8203dd30f55 100644 --- a/cs/src/Ice/TcpEndpointI.cs +++ b/cs/src/Ice/TcpEndpointI.cs @@ -15,8 +15,6 @@ namespace IceInternal sealed class TcpEndpointI : EndpointI { - internal const short TYPE = 1; - public TcpEndpointI(Instance instance, string ho, int po, int ti, string conId, bool co) { _instance = instance; @@ -197,7 +195,7 @@ namespace IceInternal // public override void streamWrite(BasicStream s) { - s.writeShort(TYPE); + s.writeShort(Ice.TCPEndpointType.value); s.startWriteEncaps(); s.writeString(_host); s.writeInt(_port); @@ -247,7 +245,7 @@ namespace IceInternal return s; } - private sealed class InfoI : Ice.TcpEndpointInfo + private sealed class InfoI : Ice.TCPEndpointInfo { public InfoI(int to, bool comp, string host, int port) : base(to, comp, host, port) { @@ -255,7 +253,7 @@ namespace IceInternal override public short type() { - return TYPE; + return Ice.TCPEndpointType.value; } override public bool datagram() @@ -282,7 +280,7 @@ namespace IceInternal // public override short type() { - return TYPE; + return Ice.TCPEndpointType.value; } // @@ -538,7 +536,7 @@ namespace IceInternal _hashCode = 5 * _hashCode + _port; _hashCode = 5 * _hashCode + _timeout; _hashCode = 5 * _hashCode + _connectionId.GetHashCode(); - _hashCode = 5 * _hashCode + (_compress? 1 : 0); + _hashCode = 5 * _hashCode + (_compress ? 1 : 0); } private Instance _instance; @@ -559,7 +557,7 @@ namespace IceInternal public short type() { - return TcpEndpointI.TYPE; + return Ice.TCPEndpointType.value; } public string protocol() diff --git a/cs/src/Ice/TcpTransceiver.cs b/cs/src/Ice/TcpTransceiver.cs index 64e3f91bae5..a54fa4bff3a 100644 --- a/cs/src/Ice/TcpTransceiver.cs +++ b/cs/src/Ice/TcpTransceiver.cs @@ -423,11 +423,11 @@ namespace IceInternal getInfo() { Debug.Assert(_fd != null); - Ice.TcpConnectionInfo info = new Ice.TcpConnectionInfo(); + Ice.TCPConnectionInfo info = new Ice.TCPConnectionInfo(); IPEndPoint localEndpoint = Network.getLocalAddress(_fd); info.localAddress = localEndpoint.Address.ToString(); info.localPort = localEndpoint.Port; - IPEndPoint remoteEndpoint = Network.getLocalAddress(_fd); + IPEndPoint remoteEndpoint = Network.getRemoteAddress(_fd); if(remoteEndpoint != null) { info.remoteAddress = remoteEndpoint.Address.ToString(); diff --git a/cs/src/Ice/UdpConnector.cs b/cs/src/Ice/UdpConnector.cs index f92b170616e..a6ec005976f 100644 --- a/cs/src/Ice/UdpConnector.cs +++ b/cs/src/Ice/UdpConnector.cs @@ -23,7 +23,7 @@ namespace IceInternal public short type() { - return UdpEndpointI.TYPE; + return Ice.UDPEndpointType.value; } // diff --git a/cs/src/Ice/UdpEndpointI.cs b/cs/src/Ice/UdpEndpointI.cs index c584901ea25..6a4bd689192 100644 --- a/cs/src/Ice/UdpEndpointI.cs +++ b/cs/src/Ice/UdpEndpointI.cs @@ -17,8 +17,6 @@ namespace IceInternal sealed class UdpEndpointI : EndpointI { - internal const short TYPE = 3; - public UdpEndpointI(Instance instance, string ho, int po, string mif, int mttl, byte pma, byte pmi, byte ema, byte emi, bool conn, string conId, bool co) { @@ -387,7 +385,7 @@ namespace IceInternal // public override void streamWrite(BasicStream s) { - s.writeShort(TYPE); + s.writeShort(Ice.UDPEndpointType.value); s.startWriteEncaps(); s.writeString(_host); s.writeInt(_port); @@ -467,7 +465,7 @@ namespace IceInternal return s; } - private sealed class InfoI : Ice.UdpEndpointInfo + private sealed class InfoI : Ice.UDPEndpointInfo { public InfoI(bool comp, string host, int port, byte protocolMajor, byte protocolMinor, byte encodingMajor, byte encodingMinor, string mcastInterface, int mcastTtl) : @@ -478,7 +476,7 @@ namespace IceInternal override public short type() { - return TYPE; + return Ice.UDPEndpointType.value; } override public bool datagram() @@ -506,7 +504,7 @@ namespace IceInternal // public override short type() { - return TYPE; + return Ice.UDPEndpointType.value; } // @@ -845,7 +843,7 @@ namespace IceInternal public short type() { - return UdpEndpointI.TYPE; + return Ice.UDPEndpointType.value; } public string protocol() diff --git a/cs/src/Ice/UdpTransceiver.cs b/cs/src/Ice/UdpTransceiver.cs index 69ce6b9ed00..7df1270aded 100644 --- a/cs/src/Ice/UdpTransceiver.cs +++ b/cs/src/Ice/UdpTransceiver.cs @@ -548,7 +548,7 @@ namespace IceInternal getInfo() { Debug.Assert(_fd != null); - Ice.UdpConnectionInfo info = new Ice.UdpConnectionInfo(); + Ice.UDPConnectionInfo info = new Ice.UDPConnectionInfo(); IPEndPoint localEndpoint = Network.getLocalAddress(_fd); info.localAddress = localEndpoint.Address.ToString(); info.localPort = localEndpoint.Port; diff --git a/cs/src/IceSSL/EndpointI.cs b/cs/src/IceSSL/EndpointI.cs index 6b01a4ce357..141d9c3dc28 100644 --- a/cs/src/IceSSL/EndpointI.cs +++ b/cs/src/IceSSL/EndpointI.cs @@ -15,8 +15,6 @@ namespace IceSSL sealed class EndpointI : IceInternal.EndpointI { - internal const short TYPE = 2; - internal EndpointI(Instance instance, string ho, int po, int ti, string conId, bool co) { _instance = instance; @@ -197,7 +195,7 @@ namespace IceSSL // public override void streamWrite(IceInternal.BasicStream s) { - s.writeShort(TYPE); + s.writeShort(EndpointType.value); s.startWriteEncaps(); s.writeString(_host); s.writeInt(_port); @@ -246,7 +244,7 @@ namespace IceSSL return s; } - private sealed class InfoI : IceSSL.SSLEndpointInfo + private sealed class InfoI : IceSSL.EndpointInfo { public InfoI(int to, bool comp, string host, int port) : base(to, comp, host, port) { @@ -254,7 +252,7 @@ namespace IceSSL override public short type() { - return TYPE; + return EndpointType.value; } override public bool datagram() @@ -281,7 +279,7 @@ namespace IceSSL // public override short type() { - return TYPE; + return EndpointType.value; } // @@ -559,7 +557,7 @@ namespace IceSSL public short type() { - return EndpointI.TYPE; + return EndpointType.value; } public string protocol() diff --git a/cs/src/IceSSL/Instance.cs b/cs/src/IceSSL/Instance.cs index 5ecedaa8cf4..3d6187a73ea 100644 --- a/cs/src/IceSSL/Instance.cs +++ b/cs/src/IceSSL/Instance.cs @@ -374,13 +374,13 @@ namespace IceSSL communicator().getLogger().trace(_securityTraceCategory, s.ToString()); } - internal void verifyPeer(ConnectionInfo info, System.Net.Sockets.Socket fd, string address, bool incoming) + internal void verifyPeer(NativeConnectionInfo info, System.Net.Sockets.Socket fd, string address) { // // For an outgoing connection, we compare the proxy address (if any) against // fields in the server's certificate (if any). // - if(info.certs != null && info.certs.Length > 0 && address.Length > 0) + if(info.nativeCerts != null && info.nativeCerts.Length > 0 && address.Length > 0) { // // Extract the IP addresses and the DNS names from the subject @@ -408,7 +408,7 @@ namespace IceSSL // registeredID [8] OBJECT IDENTIFIER // } // - foreach(X509Extension ext in info.certs[0].Extensions) + foreach(X509Extension ext in info.nativeCerts[0].Extensions) { if(ext.Oid.Value.Equals("2.5.29.17") && ext.RawData.Length > 0) { @@ -481,7 +481,7 @@ namespace IceSSL // Compare the peer's address against the common name as well as // the dnsName and ipAddress values in the subject alternative name. // - string dn = info.certs[0].Subject; + string dn = info.nativeCerts[0].Subject; string addrLower = address.ToLower(); bool certNameOK = false; { @@ -568,10 +568,10 @@ namespace IceSSL } } - if(_verifyDepthMax > 0 && info.certs != null && info.certs.Length > _verifyDepthMax) + if(_verifyDepthMax > 0 && info.nativeCerts != null && info.nativeCerts.Length > _verifyDepthMax) { - string msg = (incoming ? "incoming" : "outgoing") + " connection rejected:\n" + - "length of peer's certificate chain (" + info.certs.Length + ") exceeds maximum of " + + string msg = (info.incoming ? "incoming" : "outgoing") + " connection rejected:\n" + + "length of peer's certificate chain (" + info.nativeCerts.Length + ") exceeds maximum of " + _verifyDepthMax + "\n" + IceInternal.Network.fdToString(fd); if(_securityTraceLevel >= 1) @@ -585,7 +585,7 @@ namespace IceSSL if(!_trustManager.verify(info)) { - string msg = (incoming ? "incoming" : "outgoing") + " connection rejected by trust manager\n" + + string msg = (info.incoming ? "incoming" : "outgoing") + " connection rejected by trust manager\n" + IceInternal.Network.fdToString(fd); if(_securityTraceLevel >= 1) { @@ -599,8 +599,8 @@ namespace IceSSL if(_verifier != null && !_verifier.verify(info)) { - string msg = (incoming ? "incoming" : "outgoing") + " connection rejected by certificate verifier\n" + - IceInternal.Network.fdToString(fd); + string msg = (info.incoming ? "incoming" : "outgoing") + + " connection rejected by certificate verifier\n" + IceInternal.Network.fdToString(fd); if(_securityTraceLevel >= 1) { _logger.trace(_securityTraceCategory, msg); diff --git a/cs/src/IceSSL/Plugin.cs b/cs/src/IceSSL/Plugin.cs index 06d9da2c887..369b9549fb8 100644 --- a/cs/src/IceSSL/Plugin.cs +++ b/cs/src/IceSSL/Plugin.cs @@ -22,7 +22,7 @@ namespace IceSSL // Return true to allow a connection using the provided certificate // information, or false to reject the connection. // - bool verify(ConnectionInfo info); + bool verify(NativeConnectionInfo info); } /// <summary> diff --git a/cs/src/IceSSL/TransceiverI.cs b/cs/src/IceSSL/TransceiverI.cs index 5a0435eff45..06b51fcb78a 100644 --- a/cs/src/IceSSL/TransceiverI.cs +++ b/cs/src/IceSSL/TransceiverI.cs @@ -352,34 +352,7 @@ namespace IceSSL public Ice.ConnectionInfo getInfo() { - Debug.Assert(_fd != null && _stream != null); - IceSSL.SSLConnectionInfo info = new IceSSL.SSLConnectionInfo(); - IPEndPoint localEndpoint = IceInternal.Network.getLocalAddress(_fd); - info.localAddress = localEndpoint.Address.ToString(); - info.localPort = localEndpoint.Port; - IPEndPoint remoteEndpoint = IceInternal.Network.getLocalAddress(_fd); - if(remoteEndpoint != null) - { - info.remoteAddress = remoteEndpoint.Address.ToString(); - info.remotePort = remoteEndpoint.Port; - } - else - { - info.remoteAddress = ""; - info.remotePort = -1; - } - info.cipher = _stream.CipherAlgorithm.ToString(); - List<string> certs = new List<string>(); - foreach(X509Certificate2 cert in _chain) - { - StringBuilder s = new StringBuilder(); - s.Append("-----BEGIN CERTIFICATE-----\n"); - s.Append(Convert.ToBase64String(cert.Export(X509ContentType.Cert))); - s.Append("\n-----END CERTIFICATE-----"); - certs.Add(s.ToString()); - } - info.certs = certs.ToArray(); - return info; + return getNativeConnectionInfo(); } public void checkSendSize(IceInternal.Buffer buf, int messageSizeMax) @@ -444,6 +417,42 @@ namespace IceSSL } } + + private NativeConnectionInfo getNativeConnectionInfo() + { + Debug.Assert(_fd != null && _stream != null); + IceSSL.NativeConnectionInfo info = new IceSSL.NativeConnectionInfo(); + IPEndPoint localEndpoint = IceInternal.Network.getLocalAddress(_fd); + info.localAddress = localEndpoint.Address.ToString(); + info.localPort = localEndpoint.Port; + IPEndPoint remoteEndpoint = IceInternal.Network.getLocalAddress(_fd); + if(remoteEndpoint != null) + { + info.remoteAddress = remoteEndpoint.Address.ToString(); + info.remotePort = remoteEndpoint.Port; + } + else + { + info.remoteAddress = ""; + info.remotePort = -1; + } + info.cipher = _stream.CipherAlgorithm.ToString(); + info.nativeCerts = _chain; + List<string> certs = new List<string>(); + foreach(X509Certificate2 cert in info.nativeCerts) + { + StringBuilder s = new StringBuilder(); + s.Append("-----BEGIN CERTIFICATE-----\n"); + s.Append(Convert.ToBase64String(cert.Export(X509ContentType.Cert))); + s.Append("\n-----END CERTIFICATE-----"); + certs.Add(s.ToString()); + } + info.certs = certs.ToArray(); + info.adapterName = _adapterName; + info.incoming = _adapterName != null; + return info; + } + private bool beginAuthenticate(AsyncCallback callback, object state) { NetworkStream ns = new NetworkStream(_fd, true); @@ -521,8 +530,7 @@ namespace IceSSL _stream.EndAuthenticateAsServer(_writeResult); } - _info = Util.populateConnectionInfo(_stream, _fd, _chain, _adapterName, _adapterName != null); - _instance.verifyPeer(_info, _fd, _host, _adapterName != null); + _instance.verifyPeer(getNativeConnectionInfo(), _fd, _host); if(_instance.networkTraceLevel() >= 1) { diff --git a/cs/src/IceSSL/TrustManager.cs b/cs/src/IceSSL/TrustManager.cs index bae942ebae7..f81071ca8de 100644 --- a/cs/src/IceSSL/TrustManager.cs +++ b/cs/src/IceSSL/TrustManager.cs @@ -58,7 +58,7 @@ namespace IceSSL } } - internal bool verify(ConnectionInfo info) + internal bool verify(NativeConnectionInfo info) { List<List<List<RFC2253.RDNPair>>> reject = new List<List<List<RFC2253.RDNPair>>>(), accept = new List<List<List<RFC2253.RDNPair>>>(); @@ -128,9 +128,9 @@ namespace IceSSL // // If there is no certificate then we match false. // - if(info.certs != null && info.certs.Length > 0) + if(info.nativeCerts != null && info.nativeCerts.Length > 0) { - X500DistinguishedName subjectDN = info.certs[0].SubjectName; + X500DistinguishedName subjectDN = info.nativeCerts[0].SubjectName; string subjectName = subjectDN.Name; Debug.Assert(subjectName != null); try @@ -145,15 +145,15 @@ namespace IceSSL communicator_.getLogger().trace("Security", "trust manager evaluating client:\n" + "subject = " + subjectName + "\n" + "adapter = " + info.adapterName + "\n" + - "local addr = " + IceInternal.Network.addrToString(info.localAddr) + "\n" + - "remote addr = " + IceInternal.Network.addrToString(info.remoteAddr)); + "local addr = " + info.localAddress + ":" + info.localPort + "\n" + + "remote addr = " + info.remoteAddress + ":" + info.remotePort); } else { communicator_.getLogger().trace("Security", "trust manager evaluating server:\n" + "subject = " + subjectName + "\n" + - "local addr = " + IceInternal.Network.addrToString(info.localAddr) + "\n" + - "remote addr = " + IceInternal.Network.addrToString(info.remoteAddr)); + "local addr = " + info.localAddress + ":" + info.localPort + "\n" + + "remote addr = " + info.remoteAddress + ":" + info.remotePort); } } diff --git a/cs/src/IceSSL/Util.cs b/cs/src/IceSSL/Util.cs index 4eacf11b5a3..e93c104bfdf 100644 --- a/cs/src/IceSSL/Util.cs +++ b/cs/src/IceSSL/Util.cs @@ -18,179 +18,18 @@ namespace IceSSL /// that require information about a peer, for example, to implement /// a CertificateVerifier. /// </summary> - public sealed class ConnectionInfo + public sealed class NativeConnectionInfo : ConnectionInfo { /// <summary> /// The certificate chain. This may be null if the peer did not /// supply a certificate. The peer's certificate (if any) is the /// first one in the chain. /// </summary> - public System.Security.Cryptography.X509Certificates.X509Certificate2[] certs; - - /// <summary> - /// The name of the negotiated cipher. - /// </summary> - public string cipher; - - /// <summary> - /// The local TCP host and port. - /// </summary> - public System.Net.IPEndPoint localAddr; - - /// <summary> - /// The remote TCP host and port. - /// </summary> - public System.Net.IPEndPoint remoteAddr; - - /// <summary> - /// True if the connection is incoming; false otherwise. - /// </summary> - public bool incoming; - - /// <summary> - /// The name of the object adapter that hosts this endpoint, if - /// any. - /// </summary> - public string adapterName; - } - - /// <summary> - /// Indicates that a connection is not an SSL connection. - /// </summary> - public class ConnectionInvalidException : Ice.LocalException - { - #region Slice data members - - /// <summary> - /// The reason why the connection is considered invalid. - /// </summary> - public string reason; - - #endregion - - #region Constructors - - /// <summary> - /// Creates an instance with an empty reason code field. - /// </summary> - public ConnectionInvalidException() - { - } - - /// <summary> - /// Creates an instance with specified reason code field. - /// </summary> - public ConnectionInvalidException(System.Exception ex__) : base(ex__) - { - } - - #endregion - - /// <summary> - /// Returns the name of this exception. - /// </summary> - /// <returns>Returns "Ice::ConnectionInvalidException".</returns> - public override string ice_name() - { - return "IceSSL::ConnectionInvalidException"; - } - - #region Object members - - public override int GetHashCode() - { - int h__ = 0; - if((object)reason != null) - { - h__ = 5 * h__ + reason.GetHashCode(); - } - return h__; - } - - public override bool Equals(object other__) - { - if(other__ == null) - { - return false; - } - if(object.ReferenceEquals(this, other__)) - { - return true; - } - if(!(other__ is ConnectionInvalidException)) - { - return false; - } - if(reason == null) - { - if(((ConnectionInvalidException)other__).reason != null) - { - return false; - } - } - else - { - if(!reason.Equals(((ConnectionInvalidException)other__).reason)) - { - return false; - } - } - return true; - } - - #endregion - - #region Comparison members - - public static bool operator==(ConnectionInvalidException lhs__, ConnectionInvalidException rhs__) - { - return Equals(lhs__, rhs__); - } - - public static bool operator!=(ConnectionInvalidException lhs__, ConnectionInvalidException rhs__) - { - return !Equals(lhs__, rhs__); - } - - #endregion + public System.Security.Cryptography.X509Certificates.X509Certificate2[] nativeCerts; } public sealed class Util { - public static ConnectionInfo getConnectionInfo(Ice.Connection connection) - { - Ice.ConnectionI con = (Ice.ConnectionI)connection; - Debug.Assert(con != null); - - // - // 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. - // - lock(con) - { - IceInternal.Transceiver transceiver = con.getTransceiver(); - if(transceiver == null) - { - ConnectionInvalidException ex = new ConnectionInvalidException(); - ex.reason = "connection closed"; - throw ex; - } - - try - { - TransceiverI sslTransceiver = (TransceiverI)transceiver; - return sslTransceiver.getConnectionInfo(); - } - catch(InvalidCastException) - { - ConnectionInvalidException e = new ConnectionInvalidException(); - e.reason = "not ssl connection"; - throw e; - } - } - } - public static X509Certificate2 createCertificate(string certPEM) { char[] chars = certPEM.ToCharArray(); @@ -201,26 +40,5 @@ namespace IceSSL } return new X509Certificate2(bytes); } - - internal static ConnectionInfo - populateConnectionInfo(System.Net.Security.SslStream stream, System.Net.Sockets.Socket fd, - X509Certificate2[] certs, string adapterName, bool incoming) - { - ConnectionInfo info = new ConnectionInfo(); - info.certs = certs; - info.cipher = stream.CipherAlgorithm.ToString(); - try - { - info.localAddr = (System.Net.IPEndPoint)fd.LocalEndPoint; - info.remoteAddr = (System.Net.IPEndPoint)fd.RemoteEndPoint; - } - catch(System.Net.Sockets.SocketException ex) - { - throw new Ice.SocketException(ex); - } - info.incoming = incoming; - info.adapterName = adapterName; - return info; - } } } diff --git a/cs/test/Ice/Makefile b/cs/test/Ice/Makefile index c2dcf77afa7..b107871678c 100644 --- a/cs/test/Ice/Makefile +++ b/cs/test/Ice/Makefile @@ -16,6 +16,7 @@ SUBDIRS = application \ exceptions \ facets \ faultTolerance \ + info \ inheritance \ hold \ location \ diff --git a/cs/test/Ice/Makefile.mak b/cs/test/Ice/Makefile.mak index e3f9a255e03..6f7bc5006da 100644 --- a/cs/test/Ice/Makefile.mak +++ b/cs/test/Ice/Makefile.mak @@ -16,6 +16,7 @@ SUBDIRS = application \ exceptions \
facets \
faultTolerance \
+ info \
inheritance \
hold \
location \
diff --git a/cs/test/Ice/info/.depend b/cs/test/Ice/info/.depend new file mode 100644 index 00000000000..e452bf88cbb --- /dev/null +++ b/cs/test/Ice/info/.depend @@ -0,0 +1 @@ +generated/Test.cs: ./Test.ice $(SLICE2CS) $(SLICEPARSERLIB) diff --git a/cs/test/Ice/info/AllTests.cs b/cs/test/Ice/info/AllTests.cs new file mode 100644 index 00000000000..671420ef0a7 --- /dev/null +++ b/cs/test/Ice/info/AllTests.cs @@ -0,0 +1,172 @@ +// ********************************************************************** +// +// 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. +// +// ********************************************************************** + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Diagnostics; +using System.Threading; +using Test; + +public class AllTests +{ + private static void test(bool b) + { + if(!b) + { + throw new System.Exception(); + } + } + + + public static void allTests(Ice.Communicator communicator) + { + Console.Out.Write("testing proxy endpoint information... "); + Console.Out.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.Endpoint[] endps = p1.ice_getEndpoints(); + + + Ice.IPEndpointInfo ipEndpoint = (Ice.IPEndpointInfo)endps[0].getInfo(); + test(ipEndpoint.host.Equals("tcphost")); + test(ipEndpoint.port == 10000); + test(ipEndpoint.timeout == 1200); + test(ipEndpoint.compress); + test(!ipEndpoint.datagram()); + +// test(ipEndpoint.type() == Ice.TCPEndpointType.value && !ipEndpoint.secure() || +// ipEndpoint.type() == IceSSL.EndpointType.value && ipEndpoint.secure()); + +// test(ipEndpoint.type() == Ice.TCPEndpointType.value && ipEndpoint is Ice.TCPEndpointInfo || +// ipEndpoint.type() == IceSSL.EndpointType.value && ipEndpoint is IceSSL.EndpointInfo); + + Ice.UDPEndpointInfo udpEndpoint = (Ice.UDPEndpointInfo)endps[1].getInfo(); + test(udpEndpoint.host.Equals("udphost")); + test(udpEndpoint.port == 10001); + test(udpEndpoint.mcastInterface.Equals("eth0")); + test(udpEndpoint.mcastTtl == 5); + test(udpEndpoint.timeout == -1); + test(!udpEndpoint.compress); + test(!udpEndpoint.secure()); + test(udpEndpoint.datagram()); + test(udpEndpoint.type() == 3); + + Ice.OpaqueEndpointInfo opaqueEndpoint = (Ice.OpaqueEndpointInfo)endps[2].getInfo(); + test(opaqueEndpoint.rawBytes.Length > 0); + } + Console.Out.WriteLine("ok"); + + string defaultHost = communicator.getProperties().getProperty("Ice.Default.Host"); + Ice.ObjectAdapter adapter; + + Console.Out.Write("test object adapter endpoint information... "); + Console.Out.Flush(); + { + communicator.getProperties().setProperty("TestAdapter.Endpoints", "default -t 15000:udp"); + adapter = communicator.createObjectAdapter("TestAdapter"); + + Ice.Endpoint[] endpoints = adapter.getEndpoints(); + test(endpoints.Length == 2); + Ice.Endpoint[] publishedEndpoints = adapter.getPublishedEndpoints(); + test(IceUtilInternal.Arrays.Equals(endpoints, publishedEndpoints)); + + Ice.IPEndpointInfo ipEndpoint = (Ice.IPEndpointInfo)endpoints[0].getInfo(); + //test(ipEndpoint.type() == Ice.TCPEndpointType.value || ipEndpoint.type() == IceSSL.EndpointType.value); + test(ipEndpoint.host.Equals(defaultHost)); + test(ipEndpoint.port > 0); + test(ipEndpoint.timeout == 15000); + + Ice.UDPEndpointInfo udpEndpoint = (Ice.UDPEndpointInfo)endpoints[1].getInfo(); + test(udpEndpoint.host.Equals(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.Length >= 1); + publishedEndpoints = adapter.getPublishedEndpoints(); + test(publishedEndpoints.Length == 1); + + foreach(Ice.Endpoint endpoint in endpoints) + { + ipEndpoint = (Ice.IPEndpointInfo)endpoint.getInfo(); + test(ipEndpoint.port == 12010); + } + + ipEndpoint = (Ice.IPEndpointInfo)publishedEndpoints[0].getInfo(); + test(ipEndpoint.host.Equals("127.0.0.1")); + test(ipEndpoint.port == 12010); + + adapter.destroy(); + } + Console.Out.WriteLine("ok"); + + communicator.getProperties().setProperty("TestAdapter.Endpoints", "default -p 12010:udp -p 12010"); + communicator.getProperties().setProperty("TestAdapter.PublishedEndpoints", ""); + adapter = communicator.createObjectAdapter("TestAdapter"); + Ice.ObjectPrx @base = adapter.addWithUUID(new TestI()).ice_collocationOptimized(false); + adapter.activate(); + + TestIntfPrx testIntf = TestIntfPrxHelper.uncheckedCast(@base); + + Console.Out.Write("test connection endpoint information... "); + Console.Out.Flush(); + { + Ice.EndpointInfo info = @base.ice_getConnection().getEndpoint().getInfo(); + Ice.IPEndpointInfo ipinfo = (Ice.IPEndpointInfo)info; + test(ipinfo.port == 12010); + test(!ipinfo.compress); + test(ipinfo.host.Equals(defaultHost)); + + Dictionary<string, string> ctx = testIntf.getEndpointInfoAsContext(); + test(ctx["host"].Equals(ipinfo.host)); + test(ctx["compress"].Equals("false")); + int port = System.Int32.Parse(ctx["port"]); + test(port > 0); + + info = @base.ice_datagram().ice_getConnection().getEndpoint().getInfo(); + Ice.UDPEndpointInfo udp = (Ice.UDPEndpointInfo)info; + test(udp.port == 12010); + test(udp.host.Equals(defaultHost)); + } + Console.Out.WriteLine("ok"); + + Console.Out.Write("testing connection information... "); + Console.Out.Flush(); + { + Ice.IPConnectionInfo info = (Ice.IPConnectionInfo)@base.ice_getConnection().getInfo(); + test(!info.incoming); + test(info.adapterName.Length == 0); + test(info.remotePort == 12010); + test(info.remoteAddress.Equals(defaultHost)); + test(info.localAddress.Equals(defaultHost)); + + Dictionary<string, string> ctx = testIntf.getConnectionInfoAsContext(); + test(ctx["incoming"].Equals("true")); + test(ctx["adapterName"].Equals("TestAdapter")); + test(ctx["remoteAddress"].Equals(info.localAddress)); + test(ctx["localAddress"].Equals(info.remoteAddress)); + test(ctx["remotePort"].Equals(info.localPort.ToString())); + test(ctx["localPort"].Equals(info.remotePort.ToString())); + } + Console.Out.WriteLine("ok"); + + communicator.shutdown(); + communicator.waitForShutdown(); + } +} diff --git a/cs/test/Ice/info/Client.cs b/cs/test/Ice/info/Client.cs new file mode 100644 index 00000000000..ea0a2ba4af6 --- /dev/null +++ b/cs/test/Ice/info/Client.cs @@ -0,0 +1,64 @@ +// ********************************************************************** +// +// 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. +// +// ********************************************************************** + +using System; +using System.Diagnostics; +using System.Reflection; + +[assembly: CLSCompliant(true)] + +[assembly: AssemblyTitle("IceTest")] +[assembly: AssemblyDescription("Ice test")] +[assembly: AssemblyCompany("ZeroC, Inc.")] + +public class Client +{ + private static int run(string[] args, Ice.Communicator communicator) + { + AllTests.allTests(communicator); + return 0; + } + + public static void Main(string[] args) + { + int status = 0; + Ice.Communicator communicator = null; + + Debug.Listeners.Add(new ConsoleTraceListener()); + + try + { + communicator = Ice.Util.initialize(ref args); + status = run(args, communicator); + } + catch(System.Exception ex) + { + System.Console.Error.WriteLine(ex); + status = 1; + } + + if(communicator != null) + { + try + { + communicator.destroy(); + } + catch(Ice.LocalException ex) + { + System.Console.Error.WriteLine(ex); + status = 1; + } + } + + if(status != 0) + { + System.Environment.Exit(status); + } + } +} diff --git a/cs/test/Ice/info/Makefile b/cs/test/Ice/info/Makefile new file mode 100644 index 00000000000..2668d8d2c82 --- /dev/null +++ b/cs/test/Ice/info/Makefile @@ -0,0 +1,31 @@ +# ********************************************************************** +# +# 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 = ../../.. + +TARGETS = client.exe + +SRCS = AllTests.cs Client.cs TestI.cs + +SLICE_SRCS = $(SDIR)/Test.ice + +SDIR = . + +GDIR = generated + +include $(top_srcdir)/config/Make.rules.cs + +MCSFLAGS := $(MCSFLAGS) -target:exe + +SLICE2CSFLAGS := $(SLICE2CSFLAGS) -I. -I$(slicedir) + +client.exe: $(SRCS) $(GEN_SRCS) + $(MCS) $(MCSFLAGS) -out:$@ $(call ref,Ice) $(subst /,$(DSEP),$^) + +include .depend diff --git a/cs/test/Ice/info/Makefile.mak b/cs/test/Ice/info/Makefile.mak new file mode 100644 index 00000000000..27e945fab53 --- /dev/null +++ b/cs/test/Ice/info/Makefile.mak @@ -0,0 +1,32 @@ +# **********************************************************************
+#
+# 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 = ..\..\..
+
+TARGETS = client.exe
+TARGETS_CONFIG = $(TARGETS:.exe=.exe.config)
+
+SRCS = AllTests.cs Client.cs TestI.cs
+
+GEN_SRCS = $(GDIR)\Test.cs
+
+SDIR = .
+
+GDIR = generated
+
+!include $(top_srcdir)\config\Make.rules.mak.cs
+
+MCSFLAGS = $(MCSFLAGS) -target:exe
+
+SLICE2CSFLAGS = $(SLICE2CSFLAGS) -I. -I$(slicedir)
+
+client.exe: $(SRCS) $(GEN_SRCS)
+ $(MCS) $(MCSFLAGS) -out:$@ -r:$(refdir)\Ice.dll $(SRCS) $(GEN_SRCS)
+
+!include .depend
diff --git a/cs/test/Ice/info/Test.ice b/cs/test/Ice/info/Test.ice new file mode 100644 index 00000000000..a52655c43e2 --- /dev/null +++ b/cs/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/cs/test/Ice/info/TestI.cs b/cs/test/Ice/info/TestI.cs new file mode 100644 index 00000000000..7aa5e0adc55 --- /dev/null +++ b/cs/test/Ice/info/TestI.cs @@ -0,0 +1,64 @@ +// ********************************************************************** +// +// 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. +// +// ********************************************************************** + +using Test; +using System.Collections.Generic; + +public class TestI : TestIntfDisp_ +{ + override public void shutdown(Ice.Current current) + { + current.adapter.getCommunicator().shutdown(); + } + + override public Dictionary<string, string> getEndpointInfoAsContext(Ice.Current c) + { + Dictionary<string, string> ctx = new Dictionary<string, string>(); + Ice.EndpointInfo info = c.con.getEndpoint().getInfo(); + ctx["timeout"] = info.timeout.ToString(); + ctx["compress"] = info.compress ? "true" : "false"; + ctx["datagram"] = info.datagram() ? "true" : "false"; + ctx["secure"] = info.datagram() ? "true" : "false"; + ctx["type"] = info.type().ToString(); + + Ice.IPEndpointInfo ipinfo = (Ice.IPEndpointInfo)info; + ctx["host"] = ipinfo.host; + ctx["port"] = ipinfo.port.ToString(); + + if(ipinfo is Ice.UDPEndpointInfo) + { + Ice.UDPEndpointInfo udp = (Ice.UDPEndpointInfo)ipinfo; + ctx["protocolMajor"] = udp.protocolMajor.ToString(); + ctx["protocolMinor"] = udp.protocolMinor.ToString(); + ctx["encodingMajor"] = udp.encodingMajor.ToString(); + ctx["encodingMinor"] = udp.encodingMinor.ToString(); + ctx["mcastInterface"] = udp.mcastInterface; + ctx["mcastTtl"] = udp.mcastTtl.ToString(); + } + + return ctx; + } + + override public Dictionary<string, string> getConnectionInfoAsContext(Ice.Current c) + { + Dictionary<string, string> ctx = new Dictionary<string, string>(); + Ice.ConnectionInfo info = c.con.getInfo(); + ctx["adapterName"] = info.adapterName; + ctx["incoming"] = info.incoming ? "true" : "false"; + + Ice.IPConnectionInfo ipinfo = (Ice.IPConnectionInfo)info; + ctx["localAddress"] = ipinfo.localAddress; + ctx["localPort"] = ipinfo.localPort.ToString(); + ctx["remoteAddress"] = ipinfo.remoteAddress; + ctx["remotePort"] = ipinfo.remotePort.ToString(); + + return ctx; + } +} + diff --git a/cs/test/Ice/info/generated/.gitignore b/cs/test/Ice/info/generated/.gitignore new file mode 100644 index 00000000000..39af5887579 --- /dev/null +++ b/cs/test/Ice/info/generated/.gitignore @@ -0,0 +1 @@ +# Dummy file, so that git retains this otherwise empty directory. diff --git a/cs/test/Ice/info/run.py b/cs/test/Ice/info/run.py new file mode 100755 index 00000000000..a781885f446 --- /dev/null +++ b/cs/test/Ice/info/run.py @@ -0,0 +1,31 @@ +#!/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, getopt + +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) +print "ok" + +clientProc.waitTestSuccess() + +TestUtil.cleanup() diff --git a/cs/test/Ice/proxy/AllTests.cs b/cs/test/Ice/proxy/AllTests.cs index 8b2361114f7..5c2c72bfc3c 100644 --- a/cs/test/Ice/proxy/AllTests.cs +++ b/cs/test/Ice/proxy/AllTests.cs @@ -423,6 +423,11 @@ public class AllTests compObj2 = communicator.stringToProxy("foo@MyAdapter1"); test(!compObj1.Equals(compObj2)); + Ice.Endpoint[] endpts1 = communicator.stringToProxy("foo:tcp -h 127.0.0.1 -p 10000").ice_getEndpoints(); + Ice.Endpoint[] endpts2 = communicator.stringToProxy("foo:tcp -h 127.0.0.1 -p 10001").ice_getEndpoints(); + test(!endpts1[0].Equals(endpts2[0])); + test(endpts1[0].Equals(communicator.stringToProxy("foo:tcp -h 127.0.0.1 -p 10000").ice_getEndpoints()[0])); + // // TODO: Ideally we should also test comparison of fixed proxies. // @@ -632,32 +637,6 @@ public class AllTests Console.Out.WriteLine("ok"); - Console.Out.Write("testing endpoint information... "); - Console.Out.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.Endpoint[] endps = p1.ice_getEndpoints(); - - test(endps[0].getInfo() is Ice.TcpEndpointInfo); - Ice.TcpEndpointInfo tcpEndpoint = (Ice.TcpEndpointInfo)endps[0].getInfo(); - test(tcpEndpoint.host == "tcphost"); - test(tcpEndpoint.port == 10000); - test(tcpEndpoint.timeout == 1200); - test(tcpEndpoint.compress); - - test(endps[1].getInfo() is Ice.UdpEndpointInfo); - Ice.UdpEndpointInfo udpEndpoint = (Ice.UdpEndpointInfo)endps[1].getInfo(); - test(udpEndpoint.host == "udphost"); - test(udpEndpoint.port == 10001); - test(udpEndpoint.mcastInterface == "eth0"); - test(udpEndpoint.mcastTtl == 5); - test(udpEndpoint.timeout == -1); - test(!udpEndpoint.compress); - - test(endps[2].getInfo() is Ice.OpaqueEndpointInfo); - - Console.Out.WriteLine("ok"); - return cl; } } diff --git a/cs/test/IceSSL/configuration/AllTests.cs b/cs/test/IceSSL/configuration/AllTests.cs index 4548bda6a19..45e1a37a3cf 100644 --- a/cs/test/IceSSL/configuration/AllTests.cs +++ b/cs/test/IceSSL/configuration/AllTests.cs @@ -225,10 +225,10 @@ public class AllTests // try { - IceSSL.ConnectionInfo info = IceSSL.Util.getConnectionInfo(server.ice_getConnection()); + IceSSL.NativeConnectionInfo info = (IceSSL.NativeConnectionInfo)server.ice_getConnection().getInfo(); test(info.certs != null); } - catch(IceSSL.ConnectionInvalidException) + catch(Ice.LocalException) { test(false); } @@ -287,7 +287,7 @@ public class AllTests new X509Certificate2(defaultDir + "/s_rsa_nopass_ca1.pfx", "password"); X509Certificate2 caCert = new X509Certificate2(defaultDir + "/cacert1.pem"); - IceSSL.ConnectionInfo info = IceSSL.Util.getConnectionInfo(server.ice_getConnection()); + IceSSL.NativeConnectionInfo info = (IceSSL.NativeConnectionInfo)server.ice_getConnection().getInfo(); test(caCert.Equals(info.certs[1])); test(serverCert.Equals(info.certs[0])); @@ -515,7 +515,8 @@ public class AllTests Test.ServerPrx server = fact.createServer(d); try { - IceSSL.ConnectionInfo info = IceSSL.Util.getConnectionInfo(server.ice_getConnection()); + IceSSL.NativeConnectionInfo info = + (IceSSL.NativeConnectionInfo)server.ice_getConnection().getInfo(); server.checkCipher(info.cipher); } catch(Ice.LocalException) diff --git a/cs/test/IceSSL/configuration/CertificateVerifierI.cs b/cs/test/IceSSL/configuration/CertificateVerifierI.cs index a074442294d..8ff004d0741 100644 --- a/cs/test/IceSSL/configuration/CertificateVerifierI.cs +++ b/cs/test/IceSSL/configuration/CertificateVerifierI.cs @@ -16,9 +16,9 @@ public class CertificateVerifierI : IceSSL.CertificateVerifier reset(); } - public bool verify(IceSSL.ConnectionInfo info) + public bool verify(IceSSL.NativeConnectionInfo info) { - hadCert_ = info.certs != null; + hadCert_ = info.nativeCerts != null; invoked_ = true; return returnValue_; } diff --git a/cs/test/IceSSL/configuration/TestI.cs b/cs/test/IceSSL/configuration/TestI.cs index adcf047e92b..ed227e19b4e 100644 --- a/cs/test/IceSSL/configuration/TestI.cs +++ b/cs/test/IceSSL/configuration/TestI.cs @@ -24,10 +24,10 @@ internal sealed class ServerI : ServerDisp_ { try { - IceSSL.ConnectionInfo info = IceSSL.Util.getConnectionInfo(current.con); - test(info.certs == null); + IceSSL.NativeConnectionInfo info = (IceSSL.NativeConnectionInfo)current.con.getInfo(); + test(info.nativeCerts == null); } - catch(IceSSL.ConnectionInvalidException) + catch(Ice.LocalException) { test(false); } @@ -38,12 +38,12 @@ internal sealed class ServerI : ServerDisp_ { try { - IceSSL.ConnectionInfo info = IceSSL.Util.getConnectionInfo(current.con); - test(info.certs.Length == 2 && - info.certs[0].Subject.Equals(subjectDN) && - info.certs[0].Issuer.Equals(issuerDN)); + IceSSL.NativeConnectionInfo info = (IceSSL.NativeConnectionInfo)current.con.getInfo(); + test(info.nativeCerts.Length == 2 && + info.nativeCerts[0].Subject.Equals(subjectDN) && + info.nativeCerts[0].Issuer.Equals(issuerDN)); } - catch(IceSSL.ConnectionInvalidException) + catch(Ice.LocalException) { test(false); } @@ -54,10 +54,10 @@ internal sealed class ServerI : ServerDisp_ { try { - IceSSL.ConnectionInfo info = IceSSL.Util.getConnectionInfo(current.con); + IceSSL.NativeConnectionInfo info = (IceSSL.NativeConnectionInfo)current.con.getInfo(); test(info.cipher.Equals(cipher)); } - catch(IceSSL.ConnectionInvalidException) + catch(Ice.LocalException) { test(false); } diff --git a/java/allTests.py b/java/allTests.py index 94ce71eade5..0bbe5ea4b6a 100755 --- a/java/allTests.py +++ b/java/allTests.py @@ -36,6 +36,7 @@ tests = [ ("Ice/operations", ["core"]), ("Ice/seqMapping", ["core"]), ("Ice/exceptions", ["core"]), + ("Ice/info", ["core"]), ("Ice/inheritance", ["core"]), ("Ice/facets", ["core"]), ("Ice/objects", ["core"]), diff --git a/java/build.xml b/java/build.xml index 63baedf8144..bd4cd3da84d 100644 --- a/java/build.xml +++ b/java/build.xml @@ -279,6 +279,9 @@ <fileset dir="test/Ice/hold"> <include name="Test.ice" /> </fileset> + <fileset dir="test/Ice/info"> + <include name="Test.ice" /> + </fileset> <fileset dir="test/Ice/inheritance"> <include name="Test.ice" /> </fileset> diff --git a/java/src/Ice/ConnectionI.java b/java/src/Ice/ConnectionI.java index da2b0b1aab6..7fb693abf3c 100644 --- a/java/src/Ice/ConnectionI.java +++ b/java/src/Ice/ConnectionI.java @@ -832,6 +832,12 @@ public final class ConnectionI extends IceInternal.EventHandler implements Conne return _adapter; } + public Endpoint + getEndpoint() + { + return _endpoint; // No mutex protection necessary, _endpoint is immutable. + } + public ObjectPrx createProxy(Identity ident) { @@ -1203,22 +1209,11 @@ public final class ConnectionI extends IceInternal.EventHandler implements Conne throw (Ice.LocalException)_exception.fillInStackTrace(); } ConnectionInfo info = _transceiver.getInfo(); - info.endpoint = _endpoint.getInfo(); + info.adapterName = _adapter != null ? _adapter.getName() : ""; + info.incoming = _connector == null; 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. - // - public IceInternal.Transceiver - getTransceiver() - { - return _transceiver; - } - public String _toString() { diff --git a/java/src/IceInternal/TcpConnector.java b/java/src/IceInternal/TcpConnector.java index ae5d618be99..cadc4335ffc 100644 --- a/java/src/IceInternal/TcpConnector.java +++ b/java/src/IceInternal/TcpConnector.java @@ -50,7 +50,7 @@ final class TcpConnector implements Connector public short type() { - return TcpEndpointI.TYPE; + return Ice.TCPEndpointType.value; } public String diff --git a/java/src/IceInternal/TcpEndpointFactory.java b/java/src/IceInternal/TcpEndpointFactory.java index 25bdfdb557a..48952c04e89 100644 --- a/java/src/IceInternal/TcpEndpointFactory.java +++ b/java/src/IceInternal/TcpEndpointFactory.java @@ -19,7 +19,7 @@ final class TcpEndpointFactory implements EndpointFactory public short type() { - return TcpEndpointI.TYPE; + return Ice.TCPEndpointType.value; } public String diff --git a/java/src/IceInternal/TcpEndpointI.java b/java/src/IceInternal/TcpEndpointI.java index 44fc624af8d..27618d8ccc5 100644 --- a/java/src/IceInternal/TcpEndpointI.java +++ b/java/src/IceInternal/TcpEndpointI.java @@ -11,8 +11,6 @@ package IceInternal; final class TcpEndpointI extends EndpointI { - final static short TYPE = 1; - public TcpEndpointI(Instance instance, String ho, int po, int ti, String conId, boolean co) { @@ -178,7 +176,7 @@ final class TcpEndpointI extends EndpointI public void streamWrite(BasicStream s) { - s.writeShort(TYPE); + s.writeShort(Ice.TCPEndpointType.value); s.startWriteEncaps(); s.writeString(_host); s.writeInt(_port); @@ -236,11 +234,11 @@ final class TcpEndpointI extends EndpointI public Ice.EndpointInfo getInfo() { - return new Ice.TcpEndpointInfo(_timeout, _compress, _host, _port) + return new Ice.TCPEndpointInfo(_timeout, _compress, _host, _port) { public short type() { - return TYPE; + return Ice.TCPEndpointType.value; } public boolean datagram() @@ -261,7 +259,7 @@ final class TcpEndpointI extends EndpointI public short type() { - return TYPE; + return Ice.TCPEndpointType.value; } // diff --git a/java/src/IceInternal/TcpTransceiver.java b/java/src/IceInternal/TcpTransceiver.java index fef0558e62c..cd4e325772e 100644 --- a/java/src/IceInternal/TcpTransceiver.java +++ b/java/src/IceInternal/TcpTransceiver.java @@ -225,7 +225,7 @@ final class TcpTransceiver implements Transceiver getInfo() { assert(_fd != null); - Ice.TcpConnectionInfo info = new Ice.TcpConnectionInfo(); + Ice.TCPConnectionInfo info = new Ice.TCPConnectionInfo(); java.net.Socket socket = _fd.socket(); info.localAddress = socket.getLocalAddress().getHostAddress(); info.localPort = socket.getLocalPort(); diff --git a/java/src/IceInternal/UdpConnector.java b/java/src/IceInternal/UdpConnector.java index edff81e92a2..f8f5c651ed9 100644 --- a/java/src/IceInternal/UdpConnector.java +++ b/java/src/IceInternal/UdpConnector.java @@ -27,7 +27,7 @@ final class UdpConnector implements Connector public short type() { - return UdpEndpointI.TYPE; + return Ice.UDPEndpointType.value; } public String diff --git a/java/src/IceInternal/UdpEndpointFactory.java b/java/src/IceInternal/UdpEndpointFactory.java index a92b443b1d8..1f08169199b 100644 --- a/java/src/IceInternal/UdpEndpointFactory.java +++ b/java/src/IceInternal/UdpEndpointFactory.java @@ -19,7 +19,7 @@ final class UdpEndpointFactory implements EndpointFactory public short type() { - return UdpEndpointI.TYPE; + return Ice.UDPEndpointType.value; } public String diff --git a/java/src/IceInternal/UdpEndpointI.java b/java/src/IceInternal/UdpEndpointI.java index 846b4f41c48..880eae25473 100644 --- a/java/src/IceInternal/UdpEndpointI.java +++ b/java/src/IceInternal/UdpEndpointI.java @@ -11,8 +11,6 @@ package IceInternal; final class UdpEndpointI extends EndpointI { - final static short TYPE = 3; - public UdpEndpointI(Instance instance, String ho, int po, String mif, int mttl, byte pma, byte pmi, byte ema, byte emi, boolean conn, String conId, boolean co) @@ -315,7 +313,7 @@ final class UdpEndpointI extends EndpointI public void streamWrite(BasicStream s) { - s.writeShort(TYPE); + s.writeShort(Ice.UDPEndpointType.value); s.startWriteEncaps(); s.writeString(_host); s.writeInt(_port); @@ -402,12 +400,12 @@ final class UdpEndpointI extends EndpointI public Ice.EndpointInfo getInfo() { - return new Ice.UdpEndpointInfo(-1, _compress, _host, _port, _protocolMajor, _protocolMinor, _encodingMajor, + return new Ice.UDPEndpointInfo(-1, _compress, _host, _port, _protocolMajor, _protocolMinor, _encodingMajor, _encodingMinor, _mcastInterface, _mcastTtl) { public short type() { - return TYPE; + return Ice.UDPEndpointType.value; } public boolean datagram() @@ -428,7 +426,7 @@ final class UdpEndpointI extends EndpointI public short type() { - return TYPE; + return Ice.UDPEndpointType.value; } // diff --git a/java/src/IceInternal/UdpTransceiver.java b/java/src/IceInternal/UdpTransceiver.java index 10f4c531935..bd18ad77678 100644 --- a/java/src/IceInternal/UdpTransceiver.java +++ b/java/src/IceInternal/UdpTransceiver.java @@ -234,7 +234,7 @@ final class UdpTransceiver implements Transceiver { assert(_fd != null); - Ice.UdpConnectionInfo info = new Ice.UdpConnectionInfo(); + Ice.UDPConnectionInfo info = new Ice.UDPConnectionInfo(); java.net.DatagramSocket socket = _fd.socket(); info.localAddress = socket.getLocalAddress().getHostAddress(); info.localPort = socket.getLocalPort(); diff --git a/java/src/IceSSL/CertificateVerifier.java b/java/src/IceSSL/CertificateVerifier.java index eae8cd936e5..b9e52fca064 100644 --- a/java/src/IceSSL/CertificateVerifier.java +++ b/java/src/IceSSL/CertificateVerifier.java @@ -22,5 +22,5 @@ public interface CertificateVerifier * @return <code>true</code> if the connection should be accepted; * <code>false</code>, otherwise. **/ - boolean verify(ConnectionInfo info); + boolean verify(NativeConnectionInfo info); } diff --git a/java/src/IceSSL/ConnectionInfo.java b/java/src/IceSSL/ConnectionInfo.java deleted file mode 100644 index 7f086722200..00000000000 --- a/java/src/IceSSL/ConnectionInfo.java +++ /dev/null @@ -1,52 +0,0 @@ -// ********************************************************************** -// -// 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. -// -// ********************************************************************** - -package IceSSL; - -/** - * This class provides information about a connection to applications - * that require information about a peer, for example, to implement - * a CertificateVerifier. - * - * @see CertificateVerifier - **/ -public class ConnectionInfo -{ - /** - * The certificate chain. This may be null if the peer did not - * supply a certificate. The peer's certificate (if any) is the - * first one in the chain. - **/ - public java.security.cert.Certificate[] certs; - - /** - * The name of the negotiated cipher. - **/ - public String cipher; - - /** - * The local TCP/IP host & port. - **/ - public java.net.InetSocketAddress localAddr; - - /** - * The remote TCP/IP host & port. - **/ - public java.net.InetSocketAddress remoteAddr; - - /** - * <code>true</code> if the connection is incoming; <code>false</code> otherwise. - **/ - public boolean incoming; - - /** - * The name of the object adapter that hosts this endpoint, if any. - **/ - public String adapterName; -} diff --git a/java/src/IceSSL/ConnectionInvalidException.java b/java/src/IceSSL/ConnectionInvalidException.java deleted file mode 100644 index 67751a6ea76..00000000000 --- a/java/src/IceSSL/ConnectionInvalidException.java +++ /dev/null @@ -1,49 +0,0 @@ -// ********************************************************************** -// -// 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. -// -// ********************************************************************** - -package IceSSL; - -/** - * Indicates that a connection is not an SSL connection. - **/ -public final class ConnectionInvalidException extends Ice.LocalException -{ - /** - * Creates an instance with a <code>null</code> <code>reason</code> field. - **/ - public ConnectionInvalidException() - { - } - - /** - * Creates an instance with the specified <code>reason</code>field. - * - * @param reason The reason why the connection is considered invalid. - **/ - public ConnectionInvalidException(String reason) - { - this.reason = reason; - } - - /** - * Returns the name of this exception. - * - * @return Returns <code>"Ice::ConnectionInvalidException"</code>. - **/ - public String - ice_name() - { - return "Ice::ConnectionInvalidException"; - } - - /** - * The reason why the connection is considered invalid. - **/ - public String reason; -} diff --git a/java/src/IceSSL/ConnectorI.java b/java/src/IceSSL/ConnectorI.java index 32e8d4cf817..282336b19f7 100644 --- a/java/src/IceSSL/ConnectorI.java +++ b/java/src/IceSSL/ConnectorI.java @@ -61,7 +61,7 @@ final class ConnectorI implements IceInternal.Connector public short type() { - return EndpointI.TYPE; + return EndpointType.value; } public String diff --git a/java/src/IceSSL/EndpointFactoryI.java b/java/src/IceSSL/EndpointFactoryI.java index 5e380ea6a24..3219de15596 100644 --- a/java/src/IceSSL/EndpointFactoryI.java +++ b/java/src/IceSSL/EndpointFactoryI.java @@ -19,7 +19,7 @@ final class EndpointFactoryI implements IceInternal.EndpointFactory public short type() { - return EndpointI.TYPE; + return EndpointType.value; } public String diff --git a/java/src/IceSSL/EndpointI.java b/java/src/IceSSL/EndpointI.java index 77e70e0671d..9c0282750da 100644 --- a/java/src/IceSSL/EndpointI.java +++ b/java/src/IceSSL/EndpointI.java @@ -11,8 +11,6 @@ package IceSSL; final class EndpointI extends IceInternal.EndpointI { - final static short TYPE = 2; - public EndpointI(Instance instance, String ho, int po, int ti, String conId, boolean co) { @@ -178,7 +176,7 @@ final class EndpointI extends IceInternal.EndpointI public void streamWrite(IceInternal.BasicStream s) { - s.writeShort(TYPE); + s.writeShort(EndpointType.value); s.startWriteEncaps(); s.writeString(_host); s.writeInt(_port); @@ -236,11 +234,11 @@ final class EndpointI extends IceInternal.EndpointI public Ice.EndpointInfo getInfo() { - return new IceSSL.SSLEndpointInfo(_timeout, _compress, _host, _port) + return new IceSSL.EndpointInfo(_timeout, _compress, _host, _port) { public short type() { - return TYPE; + return EndpointType.value; } public boolean datagram() @@ -261,7 +259,7 @@ final class EndpointI extends IceInternal.EndpointI public short type() { - return TYPE; + return EndpointType.value; } // diff --git a/java/src/IceSSL/Instance.java b/java/src/IceSSL/Instance.java index ee33751ae49..866d0d62821 100644 --- a/java/src/IceSSL/Instance.java +++ b/java/src/IceSSL/Instance.java @@ -869,15 +869,15 @@ class Instance } void - verifyPeer(ConnectionInfo info, java.nio.channels.SelectableChannel fd, String address, boolean incoming) + verifyPeer(NativeConnectionInfo info, java.nio.channels.SelectableChannel fd, String address) { // // For an outgoing connection, we compare the proxy address (if any) against // fields in the server's certificate (if any). // - if(info.certs != null && info.certs.length > 0 && address.length() > 0) + if(info.nativeCerts != null && info.nativeCerts.length > 0 && address.length() > 0) { - java.security.cert.X509Certificate cert = (java.security.cert.X509Certificate)info.certs[0]; + java.security.cert.X509Certificate cert = (java.security.cert.X509Certificate)info.nativeCerts[0]; // // Extract the IP addresses and the DNS names from the subject @@ -1005,10 +1005,10 @@ class Instance } } - if(_verifyDepthMax > 0 && info.certs != null && info.certs.length > _verifyDepthMax) + if(_verifyDepthMax > 0 && info.nativeCerts != null && info.nativeCerts.length > _verifyDepthMax) { - String msg = (incoming ? "incoming" : "outgoing") + " connection rejected:\n" + - "length of peer's certificate chain (" + info.certs.length + ") exceeds maximum of " + + String msg = (info.incoming ? "incoming" : "outgoing") + " connection rejected:\n" + + "length of peer's certificate chain (" + info.nativeCerts.length + ") exceeds maximum of " + _verifyDepthMax + "\n" + IceInternal.Network.fdToString(fd); if(_securityTraceLevel >= 1) @@ -1022,7 +1022,7 @@ class Instance if(!_trustManager.verify(info)) { - String msg = (incoming ? "incoming" : "outgoing") + " connection rejected by trust manager\n" + + String msg = (info.incoming ? "incoming" : "outgoing") + " connection rejected by trust manager\n" + IceInternal.Network.fdToString(fd); if(_securityTraceLevel >= 1) { @@ -1035,7 +1035,7 @@ class Instance if(_verifier != null && !_verifier.verify(info)) { - String msg = (incoming ? "incoming" : "outgoing") + " connection rejected by certificate verifier\n" + + String msg = (info.incoming ? "incoming" : "outgoing") + " connection rejected by certificate verifier\n" + IceInternal.Network.fdToString(fd); if(_securityTraceLevel >= 1) { diff --git a/java/src/IceSSL/NativeConnectionInfo.java b/java/src/IceSSL/NativeConnectionInfo.java new file mode 100644 index 00000000000..f84705fbd69 --- /dev/null +++ b/java/src/IceSSL/NativeConnectionInfo.java @@ -0,0 +1,28 @@ +// ********************************************************************** +// +// 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. +// +// ********************************************************************** + +package IceSSL; + +/** + * + * This class is a native extension of the Slice local class + * IceSSL::ConnectionInfo. It provides access to the native Java + * certificates. + * + * @see CertificateVerifier + **/ +public class NativeConnectionInfo extends ConnectionInfo +{ + /** + * The certificate chain. This may be null if the peer did not + * supply a certificate. The peer's certificate (if any) is the + * first one in the chain. + **/ + public java.security.cert.Certificate[] nativeCerts; +} diff --git a/java/src/IceSSL/TransceiverI.java b/java/src/IceSSL/TransceiverI.java index 54687c5f052..05af29c35a6 100644 --- a/java/src/IceSSL/TransceiverI.java +++ b/java/src/IceSSL/TransceiverI.java @@ -277,44 +277,7 @@ final class TransceiverI implements IceInternal.Transceiver public Ice.ConnectionInfo getInfo() { - assert(_fd != null); - - IceSSL.SSLConnectionInfo info = new IceSSL.SSLConnectionInfo(); - java.net.Socket socket = _fd.socket(); - info.localAddress = socket.getLocalAddress().getHostAddress(); - info.localPort = socket.getLocalPort(); - if(socket.getInetAddress() != null) - { - info.remoteAddress = socket.getInetAddress().getHostAddress(); - info.remotePort = socket.getPort(); - } - else - { - info.remoteAddress = ""; - info.remotePort = -1; - } - SSLSession session = _engine.getSession(); - info.cipher = session.getCipherSuite(); - try - { - java.util.ArrayList<String> certs = new java.util.ArrayList<String>(); - for(java.security.cert.Certificate c : session.getPeerCertificates()) - { - StringBuffer s = new StringBuffer("-----BEGIN CERTIFICATE-----\n"); - s.append(IceUtilInternal.Base64.encode(c.getEncoded())); - s.append("\n-----END CERTIFICATE-----"); - certs.add(s.toString()); - } - info.certs = certs.toArray(new String[0]); - } - catch(java.security.cert.CertificateEncodingException ex) - { - } - catch(javax.net.ssl.SSLPeerUnverifiedException ex) - { - // No peer certificates. - } - return info; + return getNativeConnectionInfo(); } public void @@ -326,16 +289,6 @@ final class TransceiverI implements IceInternal.Transceiver } } - ConnectionInfo - getConnectionInfo() - { - // - // This can only be called on an open transceiver. - // - assert(_fd != null); - return _info; - } - // // Only for use by ConnectorI, AcceptorI. // @@ -388,6 +341,55 @@ final class TransceiverI implements IceInternal.Transceiver super.finalize(); } + private NativeConnectionInfo + getNativeConnectionInfo() + { + // + // This can only be called on an open transceiver. + // + assert(_fd != null); + + NativeConnectionInfo info = new NativeConnectionInfo(); + java.net.Socket socket = _fd.socket(); + info.localAddress = socket.getLocalAddress().getHostAddress(); + info.localPort = socket.getLocalPort(); + if(socket.getInetAddress() != null) + { + info.remoteAddress = socket.getInetAddress().getHostAddress(); + info.remotePort = socket.getPort(); + } + else + { + info.remoteAddress = ""; + info.remotePort = -1; + } + SSLSession session = _engine.getSession(); + info.cipher = session.getCipherSuite(); + try + { + java.util.ArrayList<String> certs = new java.util.ArrayList<String>(); + info.nativeCerts = session.getPeerCertificates(); + for(java.security.cert.Certificate c : info.nativeCerts) + { + StringBuffer s = new StringBuffer("-----BEGIN CERTIFICATE-----\n"); + s.append(IceUtilInternal.Base64.encode(c.getEncoded())); + s.append("\n-----END CERTIFICATE-----"); + certs.add(s.toString()); + } + info.certs = certs.toArray(new String[0]); + } + catch(java.security.cert.CertificateEncodingException ex) + { + } + catch(javax.net.ssl.SSLPeerUnverifiedException ex) + { + // No peer certificates. + } + info.adapterName = _adapterName; + info.incoming = _incoming; + return info; + } + private int handshakeNonBlocking() { @@ -535,8 +537,7 @@ final class TransceiverI implements IceInternal.Transceiver // // Additional verification. // - _info = Util.populateConnectionInfo(_engine.getSession(), _fd.socket(), _adapterName, _incoming); - _instance.verifyPeer(_info, _fd, _host, _incoming); + _instance.verifyPeer(getNativeConnectionInfo(), _fd, _host); if(_instance.networkTraceLevel() >= 1) { @@ -805,7 +806,6 @@ final class TransceiverI implements IceInternal.Transceiver private ByteBuffer _netInput; // Holds encrypted data read from the socket. private ByteBuffer _netOutput; // Holds encrypted data to be written to the socket. private static ByteBuffer _emptyBuffer = ByteBuffer.allocate(0); // Used during handshaking. - private ConnectionInfo _info; private static final int StateNeedConnect = 0; private static final int StateConnectPending = 1; diff --git a/java/src/IceSSL/TrustManager.java b/java/src/IceSSL/TrustManager.java index b54b18d16e9..46fdc3eabb5 100644 --- a/java/src/IceSSL/TrustManager.java +++ b/java/src/IceSSL/TrustManager.java @@ -55,7 +55,7 @@ class TrustManager } boolean - verify(ConnectionInfo info) + verify(NativeConnectionInfo info) { java.util.List<java.util.List<java.util.List<RFC2253.RDNPair> > > reject = new java.util.LinkedList<java.util.List<java.util.List<RFC2253.RDNPair> > >(), @@ -126,10 +126,10 @@ class TrustManager // // If there is no certificate then we match false. // - if(info.certs != null && info.certs.length > 0) + if(info.nativeCerts != null && info.nativeCerts.length > 0) { javax.security.auth.x500.X500Principal subjectDN = (javax.security.auth.x500.X500Principal) - ((java.security.cert.X509Certificate)info.certs[0]).getSubjectX500Principal(); + ((java.security.cert.X509Certificate)info.nativeCerts[0]).getSubjectX500Principal(); String subjectName = subjectDN.getName(javax.security.auth.x500.X500Principal.RFC2253); assert subjectName != null; try @@ -144,15 +144,15 @@ class TrustManager _communicator.getLogger().trace("Security", "trust manager evaluating client:\n" + "subject = " + subjectName + "\n" + "adapter = " + info.adapterName + "\n" + - "local addr = " + IceInternal.Network.addrToString(info.localAddr) + "\n" + - "remote addr = " + IceInternal.Network.addrToString(info.remoteAddr)); + "local addr = " + info.localAddress + ":" + info.localPort + "\n" + + "remote addr = " + info.remoteAddress + ":" + info.remotePort); } else { _communicator.getLogger().trace("Security", "trust manager evaluating server:\n" + "subject = " + subjectName + "\n" + - "local addr = " + IceInternal.Network.addrToString(info.localAddr) + "\n" + - "remote addr = " + IceInternal.Network.addrToString(info.remoteAddr)); + "local addr = " + info.localAddress + ":" + info.localPort + "\n" + + "remote addr = " + info.remoteAddress + ":" + info.remotePort); } } java.util.List<RFC2253.RDNPair> dn = RFC2253.parseStrict(subjectName); diff --git a/java/src/IceSSL/Util.java b/java/src/IceSSL/Util.java index ae3e5ced65f..05e3f5613a2 100644 --- a/java/src/IceSSL/Util.java +++ b/java/src/IceSSL/Util.java @@ -11,41 +11,6 @@ package IceSSL; public final class Util { - public static ConnectionInfo - getConnectionInfo(Ice.Connection connection) - { - Ice.ConnectionI con = (Ice.ConnectionI)connection; - assert(con != null); - - // - // 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. - // - synchronized(con) - { - IceInternal.Transceiver transceiver = con.getTransceiver(); - if(transceiver == null) - { - ConnectionInvalidException ex = new ConnectionInvalidException(); - ex.reason = "connection closed"; - throw ex; - } - - try - { - TransceiverI sslTransceiver = (TransceiverI)transceiver; - return sslTransceiver.getConnectionInfo(); - } - catch(ClassCastException ex) - { - ConnectionInvalidException e = new ConnectionInvalidException(); - e.reason = "not ssl connection"; - throw e; - } - } - } - // // Create a certificate from a PEM-encoded string. // @@ -94,26 +59,6 @@ public final class Util return (java.security.cert.X509Certificate)cf.generateCertificate(in); } - static ConnectionInfo - populateConnectionInfo(javax.net.ssl.SSLSession session, java.net.Socket fd, String adapterName, boolean incoming) - { - ConnectionInfo info = new ConnectionInfo(); - try - { - info.certs = session.getPeerCertificates(); - } - catch(javax.net.ssl.SSLPeerUnverifiedException ex) - { - // No peer certificates. - } - info.cipher = session.getCipherSuite(); - info.localAddr = (java.net.InetSocketAddress)fd.getLocalSocketAddress(); - info.remoteAddr = (java.net.InetSocketAddress)fd.getRemoteSocketAddress(); - info.adapterName = adapterName; - info.incoming = incoming; - return info; - } - public final static String jdkTarget = "1.5"; // diff --git a/java/test/Ice/classLoader/CertificateVerifierI.java b/java/test/Ice/classLoader/CertificateVerifierI.java index b5439bd7e80..d29fd279732 100644 --- a/java/test/Ice/classLoader/CertificateVerifierI.java +++ b/java/test/Ice/classLoader/CertificateVerifierI.java @@ -11,7 +11,7 @@ package test.Ice.classLoader; public class CertificateVerifierI implements IceSSL.CertificateVerifier { - public boolean verify(IceSSL.ConnectionInfo info) + public boolean verify(IceSSL.NativeConnectionInfo info) { return true; } diff --git a/java/test/Ice/info/AllTests.java b/java/test/Ice/info/AllTests.java new file mode 100644 index 00000000000..6b26d81abf2 --- /dev/null +++ b/java/test/Ice/info/AllTests.java @@ -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. +// +// ********************************************************************** + +package test.Ice.info; + +import java.io.PrintWriter; + +import test.Ice.info.Test.TestIntfPrx; +import test.Ice.info.Test.TestIntfPrxHelper; + +public class AllTests +{ + private static void + test(boolean b) + { + if(!b) + { + throw new RuntimeException(); + } + } + + public static void + allTests(Ice.Communicator communicator, PrintWriter out) + { + out.print("testing proxy endpoint information... "); + out.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.Endpoint[] endps = p1.ice_getEndpoints(); + + + Ice.IPEndpointInfo ipEndpoint = (Ice.IPEndpointInfo)endps[0].getInfo(); + test(ipEndpoint.host.equals("tcphost")); + test(ipEndpoint.port == 10000); + test(ipEndpoint.timeout == 1200); + test(ipEndpoint.compress); + test(!ipEndpoint.datagram()); + test(ipEndpoint.type() == Ice.TCPEndpointType.value && !ipEndpoint.secure() || + ipEndpoint.type() == IceSSL.EndpointType.value && ipEndpoint.secure()); + + test(ipEndpoint.type() == Ice.TCPEndpointType.value && ipEndpoint instanceof Ice.TCPEndpointInfo || + ipEndpoint.type() == IceSSL.EndpointType.value && ipEndpoint instanceof IceSSL.EndpointInfo); + + Ice.UDPEndpointInfo udpEndpoint = (Ice.UDPEndpointInfo)endps[1].getInfo(); + test(udpEndpoint.host.equals("udphost")); + test(udpEndpoint.port == 10001); + test(udpEndpoint.mcastInterface.equals("eth0")); + test(udpEndpoint.mcastTtl == 5); + test(udpEndpoint.timeout == -1); + test(!udpEndpoint.compress); + test(!udpEndpoint.secure()); + test(udpEndpoint.datagram()); + test(udpEndpoint.type() == 3); + + Ice.OpaqueEndpointInfo opaqueEndpoint = (Ice.OpaqueEndpointInfo)endps[2].getInfo(); + } + out.println("ok"); + + String defaultHost = communicator.getProperties().getProperty("Ice.Default.Host"); + out.print("test object adapter endpoint information... "); + out.flush(); + { + communicator.getProperties().setProperty("TestAdapter.Endpoints", "default -t 15000:udp"); + Ice.ObjectAdapter adapter = communicator.createObjectAdapter("TestAdapter"); + + Ice.Endpoint[] endpoints = adapter.getEndpoints(); + test(endpoints.length == 2); + Ice.Endpoint[] publishedEndpoints = adapter.getPublishedEndpoints(); + test(java.util.Arrays.equals(endpoints, publishedEndpoints)); + + Ice.IPEndpointInfo ipEndpoint = (Ice.IPEndpointInfo)endpoints[0].getInfo(); + test(ipEndpoint.type() == Ice.TCPEndpointType.value || ipEndpoint.type() == IceSSL.EndpointType.value); + test(ipEndpoint.host.equals(defaultHost)); + test(ipEndpoint.port > 0); + test(ipEndpoint.timeout == 15000); + + Ice.UDPEndpointInfo udpEndpoint = (Ice.UDPEndpointInfo)endpoints[1].getInfo(); + test(udpEndpoint.host.equals(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.length >= 1); + publishedEndpoints = adapter.getPublishedEndpoints(); + test(publishedEndpoints.length == 1); + + for(Ice.Endpoint endpoint : endpoints) + { + ipEndpoint = (Ice.IPEndpointInfo)endpoint.getInfo(); + test(ipEndpoint.port == 12010); + } + + ipEndpoint = (Ice.IPEndpointInfo)publishedEndpoints[0].getInfo(); + test(ipEndpoint.host.equals("127.0.0.1")); + test(ipEndpoint.port == 12010); + + adapter.destroy(); + } + out.println("ok"); + + communicator.getProperties().setProperty("TestAdapter.Endpoints", "default -p 12010:udp -p 12010"); + communicator.getProperties().setProperty("TestAdapter.PublishedEndpoints", ""); + Ice.ObjectAdapter adapter = communicator.createObjectAdapter("TestAdapter"); + Ice.ObjectPrx base = adapter.addWithUUID(new TestI()).ice_collocationOptimized(false); + adapter.activate(); + + TestIntfPrx test = TestIntfPrxHelper.uncheckedCast(base); + + out.print("test connection endpoint information... "); + out.flush(); + { + Ice.EndpointInfo info = base.ice_getConnection().getEndpoint().getInfo(); + Ice.IPEndpointInfo ipinfo = (Ice.IPEndpointInfo)info; + test(ipinfo.port == 12010); + test(!ipinfo.compress); + test(ipinfo.host.equals(defaultHost)); + + java.util.Map<String, String> ctx = test.getEndpointInfoAsContext(); + test(ctx.get("host").equals(ipinfo.host)); + test(ctx.get("compress").equals("false")); + int port = Integer.parseInt(ctx.get("port")); + test(port > 0); + + info = base.ice_datagram().ice_getConnection().getEndpoint().getInfo(); + Ice.UDPEndpointInfo udp = (Ice.UDPEndpointInfo)info; + test(udp.port == 12010); + test(udp.host.equals(defaultHost)); + } + out.println("ok"); + + out.print("testing connection information... "); + out.flush(); + { + Ice.IPConnectionInfo info = (Ice.IPConnectionInfo)base.ice_getConnection().getInfo(); + test(!info.incoming); + test(info.adapterName.length() == 0); + test(info.remotePort == 12010); + test(info.remoteAddress.equals(defaultHost)); + test(info.localAddress.equals(defaultHost)); + + java.util.Map<String, String> ctx = test.getConnectionInfoAsContext(); + test(ctx.get("incoming").equals("true")); + test(ctx.get("adapterName").equals("TestAdapter")); + test(ctx.get("remoteAddress").equals(info.localAddress)); + test(ctx.get("localAddress").equals(info.remoteAddress)); + test(ctx.get("remotePort").equals(Integer.toString(info.localPort))); + test(ctx.get("localPort").equals(Integer.toString(info.remotePort))); + } + out.println("ok"); + + communicator.shutdown(); + communicator.waitForShutdown(); + } +} diff --git a/java/test/Ice/info/Client.java b/java/test/Ice/info/Client.java new file mode 100644 index 00000000000..6da2d2fe6de --- /dev/null +++ b/java/test/Ice/info/Client.java @@ -0,0 +1,35 @@ +// ********************************************************************** +// +// 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. +// +// ********************************************************************** + +package test.Ice.info; + +public class Client extends test.Util.Application +{ + public int run(String[] args) + { + AllTests.allTests(communicator(), getWriter()); + return 0; + } + + protected Ice.InitializationData getInitData(Ice.StringSeqHolder argsH) + { + Ice.InitializationData initData = new Ice.InitializationData(); + initData.properties = Ice.Util.createProperties(argsH); + initData.properties.setProperty("Ice.Package.Test", "test.Ice.info"); + return initData; + } + + public static void main(String[] args) + { + Client app = new Client(); + int result = app.main("Client", args); + System.gc(); + System.exit(result); + } +} diff --git a/java/test/Ice/info/Test.ice b/java/test/Ice/info/Test.ice new file mode 100644 index 00000000000..6b95fe13feb --- /dev/null +++ b/java/test/Ice/info/Test.ice @@ -0,0 +1,30 @@ +// ********************************************************************** +// +// 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> + +[["java:package:test.Ice.info"]] +module Test +{ + +interface TestIntf +{ + void shutdown(); + + Ice::Context getEndpointInfoAsContext(); + + Ice::Context getConnectionInfoAsContext(); +}; + +}; + +#endif diff --git a/java/test/Ice/info/TestI.java b/java/test/Ice/info/TestI.java new file mode 100644 index 00000000000..23548cb1289 --- /dev/null +++ b/java/test/Ice/info/TestI.java @@ -0,0 +1,67 @@ +// ********************************************************************** +// +// 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. +// +// ********************************************************************** + +package test.Ice.info; +import test.Ice.info.Test._TestIntfDisp; + +public class TestI extends _TestIntfDisp +{ + TestI() + { + } + + public void shutdown(Ice.Current current) + { + current.adapter.getCommunicator().shutdown(); + } + + public java.util.Map<String, String> getEndpointInfoAsContext(Ice.Current c) + { + java.util.Map<String, String> ctx = new java.util.HashMap<String, String>(); + Ice.EndpointInfo info = c.con.getEndpoint().getInfo(); + ctx.put("timeout", Integer.toString(info.timeout)); + ctx.put("compress", info.compress ? "true" : "false"); + ctx.put("datagram", info.datagram() ? "true" : "false"); + ctx.put("secure", info.datagram() ? "true" : "false"); + ctx.put("type", Integer.toString(info.type())); + + Ice.IPEndpointInfo ipinfo = (Ice.IPEndpointInfo)info; + ctx.put("host", ipinfo.host); + ctx.put("port", Integer.toString(ipinfo.port)); + + if(ipinfo instanceof Ice.UDPEndpointInfo) + { + Ice.UDPEndpointInfo udp = (Ice.UDPEndpointInfo)ipinfo; + ctx.put("protocolMajor", Byte.toString(udp.protocolMajor)); + ctx.put("protocolMinor", Byte.toString(udp.protocolMinor)); + ctx.put("encodingMajor", Byte.toString(udp.encodingMajor)); + ctx.put("encodingMinor", Byte.toString(udp.encodingMinor)); + ctx.put("mcastInterface", udp.mcastInterface); + ctx.put("mcastTtl", Integer.toString(udp.mcastTtl)); + } + + return ctx; + } + + public java.util.Map<String, String> getConnectionInfoAsContext(Ice.Current c) + { + java.util.Map<String, String> ctx = new java.util.HashMap<String, String>(); + Ice.ConnectionInfo info = c.con.getInfo(); + ctx.put("adapterName", info.adapterName); + ctx.put("incoming", info.incoming ? "true" : "false"); + + Ice.IPConnectionInfo ipinfo = (Ice.IPConnectionInfo)info; + ctx.put("localAddress", ipinfo.localAddress); + ctx.put("localPort", Integer.toString(ipinfo.localPort)); + ctx.put("remoteAddress", ipinfo.remoteAddress); + ctx.put("remotePort", Integer.toString(ipinfo.remotePort)); + + return ctx; + } +} diff --git a/java/test/Ice/info/run.py b/java/test/Ice/info/run.py new file mode 100755 index 00000000000..4ebbde42d9a --- /dev/null +++ b/java/test/Ice/info/run.py @@ -0,0 +1,29 @@ +#!/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 * + +print "starting client...", +clientProc = TestUtil.startClient("test.Ice.info.Client") +print "ok" + +clientProc.waitTestSuccess() + +TestUtil.cleanup() diff --git a/java/test/Ice/proxy/AllTests.java b/java/test/Ice/proxy/AllTests.java index 4d1f804e9c6..208cb87e32c 100644 --- a/java/test/Ice/proxy/AllTests.java +++ b/java/test/Ice/proxy/AllTests.java @@ -430,6 +430,11 @@ public class AllTests compObj2 = communicator.stringToProxy("foo@MyAdapter1"); test(!compObj1.equals(compObj2)); + Ice.Endpoint[] endpts1 = communicator.stringToProxy("foo:tcp -h 127.0.0.1 -p 10000").ice_getEndpoints(); + Ice.Endpoint[] endpts2 = communicator.stringToProxy("foo:tcp -h 127.0.0.1 -p 10001").ice_getEndpoints(); + test(!endpts1[0].equals(endpts2[0])); + test(endpts1[0].equals(communicator.stringToProxy("foo:tcp -h 127.0.0.1 -p 10000").ice_getEndpoints()[0])); + // // TODO: Ideally we should also test comparison of fixed proxies. // @@ -646,32 +651,6 @@ public class AllTests } out.println("ok"); - out.print("testing endpoint information... "); - out.flush(); - - Ice.ObjectPrx p = 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.Endpoint[] endps = p.ice_getEndpoints(); - - test(endps[0].getInfo() instanceof Ice.TcpEndpointInfo); - Ice.TcpEndpointInfo tcpEndpoint = (Ice.TcpEndpointInfo)endps[0].getInfo(); - test(tcpEndpoint.host.equals("tcphost")); - test(tcpEndpoint.port == 10000); - test(tcpEndpoint.timeout == 1200); - test(tcpEndpoint.compress); - - test(endps[1].getInfo() instanceof Ice.UdpEndpointInfo); - Ice.UdpEndpointInfo udpEndpoint = (Ice.UdpEndpointInfo)endps[1].getInfo(); - test(udpEndpoint.host.equals("udphost")); - test(udpEndpoint.port == 10001); - test(udpEndpoint.mcastInterface.equals("eth0")); - test(udpEndpoint.mcastTtl == 5); - test(udpEndpoint.timeout == -1); - test(!udpEndpoint.compress); - - test(endps[2].getInfo() instanceof Ice.OpaqueEndpointInfo); - - out.println("ok"); - return cl; } } diff --git a/java/test/IceSSL/configuration/AllTests.java b/java/test/IceSSL/configuration/AllTests.java index bf7fba3f762..6f8ad228f67 100644 --- a/java/test/IceSSL/configuration/AllTests.java +++ b/java/test/IceSSL/configuration/AllTests.java @@ -162,10 +162,10 @@ public class AllTests // try { - IceSSL.ConnectionInfo info = IceSSL.Util.getConnectionInfo(server.ice_getConnection()); - test(info.certs.length == 2); + IceSSL.NativeConnectionInfo info = (IceSSL.NativeConnectionInfo)server.ice_getConnection().getInfo(); + test(info.nativeCerts.length == 2); } - catch(IceSSL.ConnectionInvalidException ex) + catch(Ice.LocalException ex) { test(false); } @@ -317,12 +317,12 @@ public class AllTests java.security.cert.X509Certificate caCert = (java.security.cert.X509Certificate)serverKeystore.getCertificate("cacert"); - IceSSL.ConnectionInfo info = IceSSL.Util.getConnectionInfo(server.ice_getConnection()); + IceSSL.NativeConnectionInfo info = (IceSSL.NativeConnectionInfo)server.ice_getConnection().getInfo(); - test(info.certs.length == 2); + test(info.nativeCerts.length == 2); - test(caCert.equals(info.certs[1])); - test(serverCert.equals(info.certs[0])); + test(caCert.equals(info.nativeCerts[1])); + test(serverCert.equals(info.nativeCerts[0])); } catch(Exception ex) { @@ -584,7 +584,7 @@ public class AllTests { String cipherSub = "DH_anon"; server.checkCipher(cipherSub); - IceSSL.ConnectionInfo info = IceSSL.Util.getConnectionInfo(server.ice_getConnection()); + IceSSL.NativeConnectionInfo info = (IceSSL.NativeConnectionInfo)server.ice_getConnection().getInfo(); test(info.cipher.indexOf(cipherSub) >= 0); } catch(Ice.LocalException ex) diff --git a/java/test/IceSSL/configuration/CertificateVerifierI.java b/java/test/IceSSL/configuration/CertificateVerifierI.java index 570860ddbd4..ce25fad0d3e 100644 --- a/java/test/IceSSL/configuration/CertificateVerifierI.java +++ b/java/test/IceSSL/configuration/CertificateVerifierI.java @@ -19,14 +19,14 @@ public class CertificateVerifierI implements IceSSL.CertificateVerifier } public boolean - verify(IceSSL.ConnectionInfo info) + verify(IceSSL.NativeConnectionInfo info) { - if(info.certs != null) + if(info.nativeCerts != null) { try { java.util.Collection<java.util.List<?> > subjectAltNames = - ((java.security.cert.X509Certificate)info.certs[0]).getSubjectAlternativeNames(); + ((java.security.cert.X509Certificate)info.nativeCerts[0]).getSubjectAlternativeNames(); test(subjectAltNames != null); java.util.List<String> ipAddresses = new java.util.ArrayList<String>(); java.util.List<String> dnsNames = new java.util.ArrayList<String>(); @@ -53,7 +53,7 @@ public class CertificateVerifierI implements IceSSL.CertificateVerifier } } - _hadCert = info.certs != null; + _hadCert = info.nativeCerts != null; _invoked = true; return _returnValue; } diff --git a/java/test/IceSSL/configuration/ServerI.java b/java/test/IceSSL/configuration/ServerI.java index 8a6f5ce3816..91e60bebd85 100644 --- a/java/test/IceSSL/configuration/ServerI.java +++ b/java/test/IceSSL/configuration/ServerI.java @@ -22,10 +22,10 @@ class ServerI extends _ServerDisp { try { - IceSSL.ConnectionInfo info = IceSSL.Util.getConnectionInfo(current.con); + IceSSL.NativeConnectionInfo info = (IceSSL.NativeConnectionInfo)current.con.getInfo(); test(info.certs == null); } - catch(IceSSL.ConnectionInvalidException ex) + catch(Ice.LocalException ex) { test(false); } @@ -36,13 +36,13 @@ class ServerI extends _ServerDisp { try { - IceSSL.ConnectionInfo info = IceSSL.Util.getConnectionInfo(current.con); - java.security.cert.X509Certificate cert = (java.security.cert.X509Certificate)info.certs[0]; - test(info.certs.length == 2 && + IceSSL.NativeConnectionInfo info = (IceSSL.NativeConnectionInfo)current.con.getInfo(); + java.security.cert.X509Certificate cert = (java.security.cert.X509Certificate)info.nativeCerts[0]; + test(info.nativeCerts.length == 2 && cert.getSubjectDN().toString().equals(subjectDN) && cert.getIssuerDN().toString().equals(issuerDN)); } - catch(IceSSL.ConnectionInvalidException ex) + catch(Ice.LocalException ex) { test(false); } @@ -53,10 +53,10 @@ class ServerI extends _ServerDisp { try { - IceSSL.ConnectionInfo info = IceSSL.Util.getConnectionInfo(current.con); + IceSSL.NativeConnectionInfo info = (IceSSL.NativeConnectionInfo)current.con.getInfo(); test(info.cipher.indexOf(cipher) >= 0); } - catch(IceSSL.ConnectionInvalidException ex) + catch(Ice.LocalException ex) { test(false); } diff --git a/slice/Ice/Connection.ice b/slice/Ice/Connection.ice index 468fefbae7f..9320eaa66e3 100644 --- a/slice/Ice/Connection.ice +++ b/slice/Ice/Connection.ice @@ -23,10 +23,18 @@ local class ConnectionInfo { /** * - * The endpoint used to establish the connection. + * Whether or not the connection is an incoming or outgoing + * connection. + * + **/ + bool incoming; + + /** + * + * The name of the adapter associated with the connection. * **/ - EndpointInfo endpoint; + string adapterName; }; /** @@ -105,6 +113,15 @@ local interface Connection /** * + * Get the endpoint from which the creation was created. + * + * @return The endpoint from which the connection was created. + * + **/ + ["cpp:const"] Endpoint getEndpoint(); + + /** + * * Flush any pending batch requests for this connection. This * causes all batch requests that were sent via proxies that use * this connection to be sent to the server. @@ -154,10 +171,10 @@ local interface Connection /** * - * Provides access to the connection details of a TCP connection + * Provides access to the connection details of an IP connection * **/ -local class TcpConnectionInfo extends ConnectionInfo +local class IPConnectionInfo extends ConnectionInfo { /** The local address. */ string localAddress; @@ -174,23 +191,20 @@ local class TcpConnectionInfo extends ConnectionInfo /** * - * Provides access to the connection details of a UDP connection + * Provides access to the connection details of a TCP connection * **/ -local class UdpConnectionInfo extends ConnectionInfo +local class TCPConnectionInfo extends IPConnectionInfo { - /** The local address. */ - string localAddress; - - /** The local port. */ - int localPort; - - /** The remote address. */ - string remoteAddress; - - /** The remote port. */ - int remotePort; +}; +/** + * + * Provides access to the connection details of a UDP connection + * + **/ +local class UDPConnectionInfo extends IPConnectionInfo +{ /** The multicast address. */ string mcastAddress; diff --git a/slice/Ice/Endpoint.ice b/slice/Ice/Endpoint.ice index bf377abc023..a3356c3b672 100644 --- a/slice/Ice/Endpoint.ice +++ b/slice/Ice/Endpoint.ice @@ -18,6 +18,9 @@ module Ice { +const short TCPEndpointType = 1; +const short UDPEndpointType = 3; + /** * * The user-level interface to an endpoint. @@ -91,12 +94,12 @@ local interface Endpoint /** * - * Provides access to the address details of a TCP endpoint. + * Provides access to the address details of a IP endpoint. * * @see Endpoint * **/ -local class TcpEndpointInfo extends EndpointInfo +local class IPEndpointInfo extends EndpointInfo { /** * @@ -107,7 +110,7 @@ local class TcpEndpointInfo extends EndpointInfo /** * - * The TCP port number. + * The port number. * **/ int port; @@ -115,27 +118,24 @@ local class TcpEndpointInfo extends EndpointInfo /** * - * Provides access to the address details of a UDP endpoint. + * Provides access to a TCP endpoint information. * * @see Endpoint * **/ -local class UdpEndpointInfo extends EndpointInfo +local class TCPEndpointInfo extends IPEndpointInfo { - /** - * - * The host or address configured with the endpoint. - * - **/ - string host; - - /** - * - * The TCP port number. - * - **/ - int port; +}; +/** + * + * Provides access to an UDP endpoint information. + * + * @see Endpoint + * + **/ +local class UDPEndpointInfo extends IPEndpointInfo +{ /** * * The protocol version supported by the endpoint. diff --git a/slice/IceSSL/ConnectionInfo.ice b/slice/IceSSL/ConnectionInfo.ice index 3d258315f4b..e2851db8a30 100644 --- a/slice/IceSSL/ConnectionInfo.ice +++ b/slice/IceSSL/ConnectionInfo.ice @@ -22,20 +22,8 @@ module IceSSL * Provides access to the connection details of an SSL connection * **/ -local class SSLConnectionInfo extends Ice::ConnectionInfo +local class ConnectionInfo extends Ice::IPConnectionInfo { - /** The local address. */ - string localAddress; - - /** The local port. */ - int localPort; - - /** The remote address. */ - string remoteAddress; - - /** The remote port. */ - int remotePort; - /** The negotiated cipher suite. */ string cipher; diff --git a/slice/IceSSL/EndpointInfo.ice b/slice/IceSSL/EndpointInfo.ice index 47b5cb1aad4..44249b4a5e8 100644 --- a/slice/IceSSL/EndpointInfo.ice +++ b/slice/IceSSL/EndpointInfo.ice @@ -15,31 +15,22 @@ #include <Ice/Endpoint.ice> /** + * * IceSSL provides a secure transport for Ice. + * **/ module IceSSL { +const short EndpointType = 2; + /** * - * Provides access to the address details of an SSL endpoint. + * Provides access to an SSL endpoint information. * **/ -local class SSLEndpointInfo extends Ice::EndpointInfo +local class EndpointInfo extends Ice::IPEndpointInfo { - /** - * - * The host or address configured with the endpoint. - * - **/ - string host; - - /** - * - * The TCP port number. - * - **/ - int port; }; }; |