summaryrefslogtreecommitdiff
path: root/cpp/src/IceSSL/EndpointI.cpp
diff options
context:
space:
mode:
authorMark Spruiell <mes@zeroc.com>2014-03-19 12:45:55 -0700
committerMark Spruiell <mes@zeroc.com>2014-03-19 12:45:55 -0700
commitcdcffbcc3c3c052afdeb772ff0167e7a90b525bb (patch)
tree4f16ee41ef7d33394c44e9db81e4d6cd89908250 /cpp/src/IceSSL/EndpointI.cpp
parentfixing testicedist.py for 5487 (diff)
downloadice-cdcffbcc3c3c052afdeb772ff0167e7a90b525bb.tar.bz2
ice-cdcffbcc3c3c052afdeb772ff0167e7a90b525bb.tar.xz
ice-cdcffbcc3c3c052afdeb772ff0167e7a90b525bb.zip
merging javascript branch
Diffstat (limited to 'cpp/src/IceSSL/EndpointI.cpp')
-rw-r--r--cpp/src/IceSSL/EndpointI.cpp456
1 files changed, 128 insertions, 328 deletions
diff --git a/cpp/src/IceSSL/EndpointI.cpp b/cpp/src/IceSSL/EndpointI.cpp
index 1c71eb560ab..de769b1186e 100644
--- a/cpp/src/IceSSL/EndpointI.cpp
+++ b/cpp/src/IceSSL/EndpointI.cpp
@@ -1,6 +1,6 @@
// **********************************************************************
//
-// Copyright (c) 2003-2013 ZeroC, Inc. All rights reserved.
+// Copyright (c) 2003-2014 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.
@@ -24,270 +24,68 @@ using namespace IceSSL;
IceSSL::EndpointI::EndpointI(const InstancePtr& instance, const string& ho, Int po, Int ti, const string& conId,
bool co) :
- IceInternal::EndpointI(conId),
+ IceInternal::IPEndpointI(instance, ho, po, conId),
_instance(instance),
- _host(ho),
- _port(po),
_timeout(ti),
_compress(co)
{
}
-IceSSL::EndpointI::EndpointI(const InstancePtr& instance, const string& str, bool oaEndpoint) :
- IceInternal::EndpointI(""),
+IceSSL::EndpointI::EndpointI(const InstancePtr& instance) :
+ IceInternal::IPEndpointI(instance),
_instance(instance),
- _port(0),
_timeout(-1),
_compress(false)
{
- const string delim = " \t\n\r";
-
- string::size_type beg;
- string::size_type end = 0;
-
- while(true)
- {
- beg = str.find_first_not_of(delim, end);
- if(beg == string::npos)
- {
- break;
- }
-
- end = str.find_first_of(delim, beg);
- if(end == string::npos)
- {
- end = str.length();
- }
-
- string option = str.substr(beg, end - beg);
- if(option.length() != 2 || option[0] != '-')
- {
- EndpointParseException ex(__FILE__, __LINE__);
- ex.str = "expected an endpoint option but found `" + option + "' in endpoint `ssl " + str + "'";
- throw ex;
- }
-
- string argument;
- string::size_type argumentBeg = str.find_first_not_of(delim, end);
- if(argumentBeg != string::npos && str[argumentBeg] != '-')
- {
- beg = argumentBeg;
- end = str.find_first_of(delim, beg);
- if(end == string::npos)
- {
- end = str.length();
- }
- argument = str.substr(beg, end - beg);
- if(argument[0] == '\"' && argument[argument.size() - 1] == '\"')
- {
- argument = argument.substr(1, argument.size() - 2);
- }
- }
-
- switch(option[1])
- {
- case 'h':
- {
- if(argument.empty())
- {
- EndpointParseException ex(__FILE__, __LINE__);
- ex.str = "no argument provided for -h option in endpoint `ssl " + str + "'";
- throw ex;
- }
- const_cast<string&>(_host) = argument;
- break;
- }
-
- case 'p':
- {
- if(argument.empty())
- {
- EndpointParseException ex(__FILE__, __LINE__);
- ex.str = "no argument provided for -p option in endpoint `ssl " + str + "'";
- throw ex;
- }
- istringstream p(argument);
- if(!(p >> const_cast<Int&>(_port)) || !p.eof())
- {
- EndpointParseException ex(__FILE__, __LINE__);
- ex.str = "invalid port value `" + argument + "' in endpoint `ssl " + str + "'";
- throw ex;
- }
- else if(_port < 0 || _port > 65535)
- {
- EndpointParseException ex(__FILE__, __LINE__);
- ex.str = "port value `" + argument + "' out of range in endpoint `ssl " + str + "'";
- throw ex;
- }
- break;
- }
-
- case 't':
- {
- if(argument.empty())
- {
- EndpointParseException ex(__FILE__, __LINE__);
- ex.str = "no argument provided for -t option in endpoint `ssl " + str + "'";
- throw ex;
- }
- istringstream t(argument);
- if(!(t >> const_cast<Int&>(_timeout)) || !t.eof())
- {
- EndpointParseException ex(__FILE__, __LINE__);
- ex.str = "invalid timeout value `" + argument + "' in endpoint `ssl " + str + "'";
- throw ex;
- }
- break;
- }
-
- case 'z':
- {
- if(!argument.empty())
- {
- EndpointParseException ex(__FILE__, __LINE__);
- ex.str = "unexpected argument `" + argument + "' provided for -z option in `ssl " + str + "'";
- throw ex;
- }
- const_cast<bool&>(_compress) = true;
- break;
- }
-
- default:
- {
- Ice::EndpointParseException ex(__FILE__, __LINE__);
- ex.str = "unknown option `" + option + "' in endpoint `ssl " + str + "'";
- throw ex;
- }
- }
- }
-
- if(_host.empty())
- {
- const_cast<string&>(_host) = _instance->defaultHost();
- }
- else if(_host == "*")
- {
- if(oaEndpoint)
- {
- const_cast<string&>(_host) = string();
- }
- else
- {
- EndpointParseException ex(__FILE__, __LINE__);
- ex.str = "`-h *' not valid for proxy endpoint `ssl " + str + "'";
- throw ex;
- }
- }
}
IceSSL::EndpointI::EndpointI(const InstancePtr& instance, IceInternal::BasicStream* s) :
+ IPEndpointI(instance, s),
_instance(instance),
- _port(0),
_timeout(-1),
_compress(false)
{
- s->startReadEncaps();
- s->read(const_cast<string&>(_host), false);
- s->read(const_cast<Int&>(_port));
s->read(const_cast<Int&>(_timeout));
s->read(const_cast<bool&>(_compress));
- s->endReadEncaps();
-}
-
-void
-IceSSL::EndpointI::streamWrite(IceInternal::BasicStream* s) const
-{
- s->write(EndpointType);
- s->startWriteEncaps();
- s->write(_host, false);
- s->write(_port);
- s->write(_timeout);
- s->write(_compress);
- s->endWriteEncaps();
-}
-
-string
-IceSSL::EndpointI::toString() const
-{
- //
- // WARNING: Certain features, such as proxy validation in Glacier2,
- // depend on the format of proxy strings. Changes to toString() and
- // methods called to generate parts of the reference string could break
- // these features. Please review for all features that depend on the
- // format of proxyToString() before changing this and related code.
- //
- ostringstream s;
- s << "ssl";
-
- if(!_host.empty())
- {
- s << " -h ";
- bool addQuote = _host.find(':') != string::npos;
- if(addQuote)
- {
- s << "\"";
- }
- s << _host;
- if(addQuote)
- {
- s << "\"";
- }
- }
-
- s << " -p " << _port;
- if(_timeout != -1)
- {
- s << " -t " << _timeout;
- }
- if(_compress)
- {
- s << " -z";
- }
- return s.str();
}
Ice::EndpointInfoPtr
IceSSL::EndpointI::getInfo() const
{
- class InfoI : public IceSSL::EndpointInfo
+ class InfoI : public EndpointInfo
{
public:
-
- InfoI(Int to, bool comp, const string& host, Int port) : IceSSL::EndpointInfo(to, comp, host, port)
+
+ InfoI(const IceInternal::EndpointIPtr& endpoint) : _endpoint(endpoint)
{
}
- virtual Short
+ virtual Ice::Short
type() const
{
- return EndpointType;
+ return _endpoint->type();
}
virtual bool
datagram() const
{
- return false;
+ return _endpoint->datagram();
}
-
+
virtual bool
secure() const
{
- return true;
+ return _endpoint->secure();
}
- };
- return new InfoI(_timeout, _compress, _host, _port);
-}
-Short
-IceSSL::EndpointI::type() const
-{
- return EndpointType;
-}
+ private:
+
+ const IceInternal::EndpointIPtr _endpoint;
+ };
-std::string
-IceSSL::EndpointI::protocol() const
-{
- return "ssl";
+ IPEndpointInfoPtr info = new InfoI(const_cast<EndpointI*>(this));
+ fillEndpointInfo(info.get());
+ return info;
}
Int
@@ -309,19 +107,6 @@ IceSSL::EndpointI::timeout(Int timeout) const
}
}
-IceInternal::EndpointIPtr
-IceSSL::EndpointI::connectionId(const string& connectionId) const
-{
- if(connectionId == _connectionId)
- {
- return const_cast<EndpointI*>(this);
- }
- else
- {
- return new EndpointI(_instance, _host, _port, _timeout, connectionId, _compress);
- }
-}
-
bool
IceSSL::EndpointI::compress() const
{
@@ -360,19 +145,6 @@ IceSSL::EndpointI::transceiver(IceInternal::EndpointIPtr& endp) const
return 0;
}
-vector<IceInternal::ConnectorPtr>
-IceSSL::EndpointI::connectors(Ice::EndpointSelectionType selType) const
-{
- return _instance->endpointHostResolver()->resolve(_host, _port, selType, const_cast<EndpointI*>(this));
-}
-
-void
-IceSSL::EndpointI::connectors_async(Ice::EndpointSelectionType selType,
- const IceInternal::EndpointI_connectorsPtr& callback) const
-{
- _instance->endpointHostResolver()->resolve(_host, _port, selType, const_cast<EndpointI*>(this), callback);
-}
-
IceInternal::AcceptorPtr
IceSSL::EndpointI::acceptor(IceInternal::EndpointIPtr& endp, const string& adapterName) const
{
@@ -381,51 +153,40 @@ IceSSL::EndpointI::acceptor(IceInternal::EndpointIPtr& endp, const string& adapt
return p;
}
-vector<IceInternal::EndpointIPtr>
-IceSSL::EndpointI::expand() const
+string
+IceSSL::EndpointI::options() const
{
- vector<IceInternal::EndpointIPtr> endps;
- vector<string> hosts = IceInternal::getHostsForEndpointExpand(_host, _instance->protocolSupport(), false);
- if(hosts.empty())
+ //
+ // WARNING: Certain features, such as proxy validation in Glacier2,
+ // depend on the format of proxy strings. Changes to toString() and
+ // methods called to generate parts of the reference string could break
+ // these features. Please review for all features that depend on the
+ // format of proxyToString() before changing this and related code.
+ //
+ ostringstream s;
+ s << IPEndpointI::options();
+
+ if(_timeout != -1)
{
- endps.push_back(const_cast<EndpointI*>(this));
+ s << " -t " << _timeout;
}
- else
+
+ if(_compress)
{
- for(vector<string>::const_iterator p = hosts.begin(); p != hosts.end(); ++p)
- {
- endps.push_back(new EndpointI(_instance, *p, _port, _timeout, _connectionId, _compress));
- }
+ s << " -z";
}
- return endps;
+
+ return s.str();
}
bool
-IceSSL::EndpointI::equivalent(const IceInternal::EndpointIPtr& endpoint) const
+IceSSL::EndpointI::operator==(const Ice::LocalObject& r) const
{
- const EndpointI* sslEndpointI = dynamic_cast<const EndpointI*>(endpoint.get());
- if(!sslEndpointI)
+ if(!IPEndpointI::operator==(r))
{
return false;
}
- return sslEndpointI->_host == _host && sslEndpointI->_port == _port;
-}
-
-vector<IceInternal::ConnectorPtr>
-IceSSL::EndpointI::connectors(const vector<IceInternal::Address>& addresses,
- const IceInternal::NetworkProxyPtr& proxy) const
-{
- vector<IceInternal::ConnectorPtr> connectors;
- for(unsigned int i = 0; i < addresses.size(); ++i)
- {
- connectors.push_back(new ConnectorI(_instance, _host, addresses[i], proxy, _timeout, _connectionId));
- }
- return connectors;
-}
-bool
-IceSSL::EndpointI::operator==(const Ice::LocalObject& r) const
-{
const EndpointI* p = dynamic_cast<const EndpointI*>(&r);
if(!p)
{
@@ -437,26 +198,11 @@ IceSSL::EndpointI::operator==(const Ice::LocalObject& r) const
return true;
}
- if(_host != p->_host)
- {
- return false;
- }
-
- if(_port != p->_port)
- {
- return false;
- }
-
if(_timeout != p->_timeout)
{
return false;
}
- if(_connectionId != p->_connectionId)
- {
- return false;
- }
-
if(_compress != p->_compress)
{
return false;
@@ -483,70 +229,116 @@ IceSSL::EndpointI::operator<(const Ice::LocalObject& r) const
{
return false;
}
-
- if(_host < p->_host)
+
+ if(_timeout < p->_timeout)
{
return true;
}
- else if (p->_host < _host)
+ else if(p->_timeout < _timeout)
{
return false;
}
- if(_port < p->_port)
+ if(!_compress && p->_compress)
{
return true;
}
- else if(p->_port < _port)
+ else if(p->_compress < _compress)
{
return false;
}
- if(_timeout < p->_timeout)
- {
- return true;
- }
- else if(p->_timeout < _timeout)
+ return IPEndpointI::operator<(r);
+}
+
+void
+IceSSL::EndpointI::streamWriteImpl(IceInternal::BasicStream* s) const
+{
+ IPEndpointI::streamWriteImpl(s);
+ s->write(_timeout);
+ s->write(_compress);
+}
+
+void
+IceSSL::EndpointI::hashInit(Ice::Int& h) const
+{
+ IPEndpointI::hashInit(h);
+ IceInternal::hashAdd(h, _timeout);
+ IceInternal::hashAdd(h, _compress);
+}
+
+void
+IceSSL::EndpointI::fillEndpointInfo(IPEndpointInfo* info) const
+{
+ IPEndpointI::fillEndpointInfo(info);
+ EndpointInfo* sslInfo = dynamic_cast<EndpointInfo*>(info);
+ if(sslInfo)
{
- return false;
+ sslInfo->timeout = _timeout;
+ sslInfo->compress = _compress;
}
+}
- if(_connectionId < p->_connectionId)
+bool
+IceSSL::EndpointI::checkOption(const string& option, const string& argument, const string& endpoint)
+{
+ if(IPEndpointI::checkOption(option, argument, endpoint))
{
return true;
}
- else if(p->_connectionId < _connectionId)
+
+ switch(option[1])
{
- return false;
+ case 't':
+ {
+ if(argument.empty())
+ {
+ EndpointParseException ex(__FILE__, __LINE__);
+ ex.str = "no argument provided for -t option in endpoint " + endpoint;
+ throw ex;
+ }
+ istringstream t(argument);
+ if(!(t >> const_cast<Int&>(_timeout)) || !t.eof())
+ {
+ EndpointParseException ex(__FILE__, __LINE__);
+ ex.str = "invalid timeout value `" + argument + "' in endpoint " + endpoint;
+ throw ex;
+ }
+ return true;
}
- if(!_compress && p->_compress)
+ case 'z':
{
+ if(!argument.empty())
+ {
+ EndpointParseException ex(__FILE__, __LINE__);
+ ex.str = "unexpected argument `" + argument + "' provided for -z option in " + endpoint;
+ throw ex;
+ }
+ const_cast<bool&>(_compress) = true;
return true;
}
- else if(p->_compress < _compress)
+
+ default:
{
return false;
}
+ }
+}
- return false;
+IceInternal::ConnectorPtr
+IceSSL::EndpointI::createConnector(const IceInternal::Address& address, const IceInternal::NetworkProxyPtr& proxy) const
+{
+ return new ConnectorI(_instance, _host, address, proxy, _timeout, _connectionId);
}
-Ice::Int
-IceSSL::EndpointI::hashInit() const
+IceInternal::IPEndpointIPtr
+IceSSL::EndpointI::createEndpoint(const string& host, int port, const string& connectionId) const
{
- Int h = 5381;
- IceInternal::hashAdd(h, EndpointType);
- IceInternal::hashAdd(h, _host);
- IceInternal::hashAdd(h, _port);
- IceInternal::hashAdd(h, _timeout);
- IceInternal::hashAdd(h, _connectionId);
- IceInternal::hashAdd(h, _compress);
- return h;
+ return new EndpointI(_instance, host, port, _timeout, connectionId, _compress);
}
-IceSSL::EndpointFactoryI::EndpointFactoryI(const InstancePtr& instance)
- : _instance(instance)
+IceSSL::EndpointFactoryI::EndpointFactoryI(const InstancePtr& instance) : _instance(instance)
{
}
@@ -557,19 +349,21 @@ IceSSL::EndpointFactoryI::~EndpointFactoryI()
Short
IceSSL::EndpointFactoryI::type() const
{
- return EndpointType;
+ return _instance->type();
}
string
IceSSL::EndpointFactoryI::protocol() const
{
- return "ssl";
+ return _instance->protocol();
}
IceInternal::EndpointIPtr
-IceSSL::EndpointFactoryI::create(const string& str, bool oaEndpoint) const
+IceSSL::EndpointFactoryI::create(vector<string>& args, bool oaEndpoint) const
{
- return new EndpointI(_instance, str, oaEndpoint);
+ IceInternal::IPEndpointIPtr endpt = new EndpointI(_instance);
+ endpt->initWithOptions(args, oaEndpoint);
+ return endpt;
}
IceInternal::EndpointIPtr
@@ -583,3 +377,9 @@ IceSSL::EndpointFactoryI::destroy()
{
_instance = 0;
}
+
+IceInternal::EndpointFactoryPtr
+IceSSL::EndpointFactoryI::clone(const IceInternal::ProtocolInstancePtr& instance) const
+{
+ return new EndpointFactoryI(new Instance(_instance->sharedInstance(), instance->type(), instance->protocol()));
+}