diff options
author | Benoit Foucher <benoit@zeroc.com> | 2013-01-15 18:46:12 +0100 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2013-01-15 18:46:12 +0100 |
commit | f561241d76b7a3d58a8652a8ae6642361f6d596b (patch) | |
tree | 06602625807c74e6476043eee42f304e15609592 /cpp | |
parent | Fixed(ICE-5184) -IceGridGUI will not allow me to enter port in connection cre... (diff) | |
download | ice-f561241d76b7a3d58a8652a8ae6642361f6d596b.tar.bz2 ice-f561241d76b7a3d58a8652a8ae6642361f6d596b.tar.xz ice-f561241d76b7a3d58a8652a8ae6642361f6d596b.zip |
Fixed ICE-5131 - parsing of -p <version> for proxies, tweaked UDP endpoint deprecation warning for -v/-e
Diffstat (limited to 'cpp')
-rw-r--r-- | cpp/include/Ice/Protocol.h | 27 | ||||
-rw-r--r-- | cpp/src/Ice/Outgoing.cpp | 4 | ||||
-rw-r--r-- | cpp/src/Ice/OutgoingAsync.cpp | 4 | ||||
-rw-r--r-- | cpp/src/Ice/ReferenceFactory.cpp | 31 | ||||
-rw-r--r-- | cpp/src/Ice/UdpEndpointI.cpp | 28 | ||||
-rw-r--r-- | cpp/test/Ice/proxy/AllTests.cpp | 94 |
6 files changed, 118 insertions, 70 deletions
diff --git a/cpp/include/Ice/Protocol.h b/cpp/include/Ice/Protocol.h index 8470a4549d4..4ea8f2062e2 100644 --- a/cpp/include/Ice/Protocol.h +++ b/cpp/include/Ice/Protocol.h @@ -188,11 +188,36 @@ checkSupportedEncoding(const Ice::EncodingVersion& v) } // +// Either return the given protocol if not compatible, or the greatest +// supported protocol otherwise. +// +inline const Ice::ProtocolVersion +getCompatibleProtocol(const Ice::ProtocolVersion& v) +{ + if(v.major != Ice::currentProtocol.major) + { + return v; // Unsupported protocol, return as is. + } + else if(v.minor < Ice::currentProtocol.minor) + { + return v; // Supported protocol. + } + else + { + // + // Unsupported but compatible, use the currently supported + // protocol, that's the best we can do. + // + return Ice::currentProtocol; + } +} + +// // Either return the given encoding if not compatible, or the greatest // supported encoding otherwise. // inline const Ice::EncodingVersion& -checkForCompatibleEncoding(const Ice::EncodingVersion& v) +getCompatibleEncoding(const Ice::EncodingVersion& v) { if(v.major != Ice::currentEncoding.major) { diff --git a/cpp/src/Ice/Outgoing.cpp b/cpp/src/Ice/Outgoing.cpp index 51f41bedd2b..acd4856aace 100644 --- a/cpp/src/Ice/Outgoing.cpp +++ b/cpp/src/Ice/Outgoing.cpp @@ -87,12 +87,12 @@ IceInternal::Outgoing::Outgoing(RequestHandler* handler, const string& operation _handler(handler), _observer(observer), _state(StateUnsent), - _encoding(checkForCompatibleEncoding(handler->getReference()->getEncoding())), + _encoding(getCompatibleEncoding(handler->getReference()->getEncoding())), _is(handler->getReference()->getInstance().get(), Ice::currentProtocolEncoding), _os(handler->getReference()->getInstance().get(), Ice::currentProtocolEncoding), _sent(false) { - checkSupportedProtocol(handler->getReference()->getProtocol()); + checkSupportedProtocol(getCompatibleProtocol(handler->getReference()->getProtocol())); switch(_handler->getReference()->getMode()) { diff --git a/cpp/src/Ice/OutgoingAsync.cpp b/cpp/src/Ice/OutgoingAsync.cpp index 04e9eabdc02..9d15133ad8a 100644 --- a/cpp/src/Ice/OutgoingAsync.cpp +++ b/cpp/src/Ice/OutgoingAsync.cpp @@ -426,7 +426,7 @@ IceInternal::OutgoingAsync::OutgoingAsync(const ObjectPrx& prx, const Ice::LocalObjectPtr& cookie) : AsyncResult(prx->ice_getCommunicator(), prx->__reference()->getInstance(), operation, delegate, cookie), _proxy(prx), - _encoding(checkForCompatibleEncoding(prx->__reference()->getEncoding())) + _encoding(getCompatibleEncoding(prx->__reference()->getEncoding())) { } @@ -438,7 +438,7 @@ IceInternal::OutgoingAsync::__prepare(const std::string& operation, OperationMod _mode = mode; _sentSynchronously = false; - checkSupportedProtocol(_proxy->__reference()->getProtocol()); + checkSupportedProtocol(getCompatibleProtocol(_proxy->__reference()->getProtocol())); _observer.attach(_proxy.get(), operation, context); diff --git a/cpp/src/Ice/ReferenceFactory.cpp b/cpp/src/Ice/ReferenceFactory.cpp index b4193f3a374..57c01f213bf 100644 --- a/cpp/src/Ice/ReferenceFactory.cpp +++ b/cpp/src/Ice/ReferenceFactory.cpp @@ -190,6 +190,7 @@ IceInternal::ReferenceFactory::create(const string& str, const string& propertyP Reference::Mode mode = Reference::ModeTwoway; bool secure = false; Ice::EncodingVersion encoding = _instance->defaultsAndOverrides()->defaultEncoding; + Ice::ProtocolVersion protocol = Protocol_1_0; string adapter; while(true) @@ -372,7 +373,7 @@ IceInternal::ReferenceFactory::create(const string& str, const string& propertyP throw ex; } - try + try { encoding = Ice::stringToEncodingVersion(argument); } @@ -385,6 +386,28 @@ IceInternal::ReferenceFactory::create(const string& str, const string& propertyP break; } + case 'p': + { + if(argument.empty()) + { + Ice::ProxyParseException ex(__FILE__, __LINE__); + ex.str = "no argument provided for -p option in `" + s + "'"; + throw ex; + } + + try + { + protocol = Ice::stringToProtocolVersion(argument); + } + catch(const Ice::VersionParseException& e) + { + Ice::ProxyParseException ex(__FILE__, __LINE__); + ex.str = "invalid protocol version `" + argument + "' in `" + s + "':\n" + e.str; + throw ex; + } + break; + } + default: { ProxyParseException ex(__FILE__, __LINE__); @@ -396,7 +419,7 @@ IceInternal::ReferenceFactory::create(const string& str, const string& propertyP if(beg == string::npos) { - return create(ident, facet, mode, secure, Protocol_1_0, encoding, vector<EndpointIPtr>(), "", propertyPrefix); + return create(ident, facet, mode, secure, protocol, encoding, vector<EndpointIPtr>(), "", propertyPrefix); } vector<EndpointIPtr> endpoints; @@ -484,7 +507,7 @@ IceInternal::ReferenceFactory::create(const string& str, const string& propertyP } } - return create(ident, facet, mode, secure, Protocol_1_0, encoding, endpoints, "", propertyPrefix); + return create(ident, facet, mode, secure, protocol, encoding, endpoints, "", propertyPrefix); break; } case '@': @@ -548,7 +571,7 @@ IceInternal::ReferenceFactory::create(const string& str, const string& propertyP adapter = Ice::UTF8ToNative(_instance->initializationData().stringConverter, adapter); - return create(ident, facet, mode, secure, Protocol_1_0, encoding, endpoints, adapter, propertyPrefix); + return create(ident, facet, mode, secure, protocol, encoding, endpoints, adapter, propertyPrefix); break; } default: diff --git a/cpp/src/Ice/UdpEndpointI.cpp b/cpp/src/Ice/UdpEndpointI.cpp index 8d812e591dc..87cb12aafee 100644 --- a/cpp/src/Ice/UdpEndpointI.cpp +++ b/cpp/src/Ice/UdpEndpointI.cpp @@ -157,13 +157,29 @@ IceInternal::UdpEndpointI::UdpEndpointI(const InstancePtr& instance, const strin } const_cast<bool&>(_compress) = true; } - else if(option == "-v") + else if(option == "-v" || option == "-e") { - _instance->initializationData().logger->warning("deprecated udp endpoint option: -v"); - } - else if(option == "-e") - { - _instance->initializationData().logger->warning("deprecated udp endpoint option: -e"); + if(argument.empty()) + { + EndpointParseException ex(__FILE__, __LINE__); + ex.str = "no argument provided for " + option + " option in endpoint `udp " + str + "'"; + throw ex; + } + try + { + Ice::Byte major, minor; + IceInternal::stringToMajorMinor(argument, major, minor); + if(major != 1 || minor != 0) + { + _instance->initializationData().logger->warning("deprecated udp endpoint option: " + option); + } + } + catch(const VersionParseException& e) + { + EndpointParseException ex(__FILE__, __LINE__); + ex.str = "invalid version `" + argument + "' in endpoint `udp " + str + "':\n" + e.str; + throw ex; + } } else if(option == "--interface") { diff --git a/cpp/test/Ice/proxy/AllTests.cpp b/cpp/test/Ice/proxy/AllTests.cpp index 8715475f4a4..e9eba2918d4 100644 --- a/cpp/test/Ice/proxy/AllTests.cpp +++ b/cpp/test/Ice/proxy/AllTests.cpp @@ -220,6 +220,12 @@ allTests(const Ice::CommunicatorPtr& communicator) b1 = communicator->stringToProxy("test -e 6.5"); test(b1->ice_getEncodingVersion().major == 6 && b1->ice_getEncodingVersion().minor == 5); + b1 = communicator->stringToProxy("test -p 1.0 -e 1.0"); + test(b1->ice_toString() == "test -t"); + + b1 = communicator->stringToProxy("test -p 6.5 -e 1.0"); + test(b1->ice_toString() == "test -t -p 6.5"); + try { b1 = communicator->stringToProxy("test:tcp@adapterId"); @@ -623,61 +629,6 @@ allTests(const Ice::CommunicatorPtr& communicator) cout << "ok" << endl; - cout << "testing protocol versioning... " << flush; - { - Ice::OutputStreamPtr out = Ice::createOutputStream(communicator); - out->write(cl); - vector<Ice::Byte> inBytes; - out->finished(inBytes); - - // Protocol version 1.1 - inBytes[9] = 1; - inBytes[10] = 1; - - Ice::InputStreamPtr in = Ice::createInputStream(communicator, inBytes); - Test::MyClassPrx cl11; - in->read(cl11); - cl11 = cl11->ice_collocationOptimized(false); - if(communicator->getProperties()->getPropertyAsInt("Ice.IPv6") == 0) - { - string protocol = communicator->getProperties()->getPropertyWithDefault("Ice.Default.Protocol", "tcp"); - test(cl11->ice_toString() == "test -t -p 1.1 -e 1.1:" + protocol + " -h 127.0.0.1 -p 12010"); - } - try - { - cl11->ice_ping(); - test(false); - } - catch(const Ice::UnsupportedProtocolException&) - { - } - try - { - cl11->end_ice_ping(cl11->begin_ice_ping()); - test(false); - } - catch(const Ice::UnsupportedProtocolException&) - { - } - try - { - cl11->ice_flushBatchRequests(); - test(false); - } - catch(const Ice::UnsupportedProtocolException&) - { - } - try - { - cl11->end_ice_flushBatchRequests(cl11->begin_ice_flushBatchRequests()); - test(false); - } - catch(const Ice::UnsupportedProtocolException&) - { - } - } - cout << "ok" << endl; - cout << "testing encoding versioning... " << flush; string ref20 = "test -e 2.0:default -p 12010"; Test::MyClassPrx cl20 = Test::MyClassPrx::uncheckedCast(communicator->stringToProxy(ref20)); @@ -754,6 +705,39 @@ allTests(const Ice::CommunicatorPtr& communicator) cout << "ok" << endl; + cout << "testing protocol versioning... " << flush; + + ref20 = "test -p 2.0:default -p 12010"; + cl20 = Test::MyClassPrx::uncheckedCast(communicator->stringToProxy(ref20)); + try + { + cl20->ice_collocationOptimized(false)->ice_ping(); + test(false); + } + catch(const Ice::UnsupportedProtocolException&) + { + // Server 2.0 proxy doesn't support 1.0 version. + } + + ref10 = "test -p 1.0:default -p 12010"; + cl10 = Test::MyClassPrx::uncheckedCast(communicator->stringToProxy(ref10)); + cl10->ice_ping(); + + // 1.3 isn't supported but since a 1.3 proxy supports 1.0, the + // call will use the 1.0 encoding + ref13 = "test -p 1.3:default -p 12010"; + cl13 = Test::MyClassPrx::uncheckedCast(communicator->stringToProxy(ref13)); + cl13->ice_ping(); + try + { + cl13->end_ice_ping(cl13->begin_ice_ping()); + } + catch(const Ice::CollocationOptimizationException&) + { + } + + cout << "ok" <<endl; + cout << "testing opaque endpoints... " << flush; try |