From 05f2548dc1b12b4b5afd3406af3bd899c17f85be Mon Sep 17 00:00:00 2001 From: Jose Date: Mon, 29 Feb 2016 15:56:29 +0100 Subject: ICE-6952 - identityToString/stringToIdentity non member functions --- cpp/src/Glacier2Lib/SessionHelper.cpp | 12 +--- cpp/src/Ice/CommunicatorI.cpp | 4 +- cpp/src/Ice/Incoming.cpp | 4 +- cpp/src/Ice/Initialize.cpp | 116 ++++++++++++++++++++++++++++++++++ cpp/src/Ice/Instance.cpp | 115 --------------------------------- cpp/src/Ice/Instance.h | 2 - cpp/src/Ice/LocatorInfo.cpp | 12 ++-- cpp/src/Ice/ObjectAdapterI.cpp | 2 +- cpp/src/Ice/Reference.cpp | 2 +- cpp/src/Ice/ReferenceFactory.cpp | 2 +- cpp/src/Ice/ServantManager.cpp | 6 +- cpp/src/Ice/TraceUtil.cpp | 2 +- 12 files changed, 134 insertions(+), 145 deletions(-) (limited to 'cpp/src') diff --git a/cpp/src/Glacier2Lib/SessionHelper.cpp b/cpp/src/Glacier2Lib/SessionHelper.cpp index 7ce2d2c3eb9..623e0a2a869 100644 --- a/cpp/src/Glacier2Lib/SessionHelper.cpp +++ b/cpp/src/Glacier2Lib/SessionHelper.cpp @@ -1162,17 +1162,7 @@ string Glacier2::SessionFactoryHelper::createProxyStr(const Ice::Identity& ident) { ostringstream os; - os << "\""; - // - // TODO replace with identityToString, we cannot use the Communicator::identityToString - // current implementation because we need to do that before the communicator has been - // initialized. - // - if(!ident.category.empty()) - { - os << ident.category << "/"; - } - os << ident.name << "\":" << _protocol << " -p " << getPortInternal() << " -h \"" << _routerHost << "\""; + os << "\"" << Ice::identityToString(ident) << "\":" << _protocol << " -p " << getPortInternal() << " -h \"" << _routerHost << "\""; if(_timeout > 0) { os << " -t " << _timeout; diff --git a/cpp/src/Ice/CommunicatorI.cpp b/cpp/src/Ice/CommunicatorI.cpp index 985acb23aa9..3232cf57e5d 100644 --- a/cpp/src/Ice/CommunicatorI.cpp +++ b/cpp/src/Ice/CommunicatorI.cpp @@ -83,13 +83,13 @@ Ice::CommunicatorI::proxyToProperty(const ObjectPrx& proxy, const string& proper Identity Ice::CommunicatorI::stringToIdentity(const string& s) const { - return _instance->stringToIdentity(s); + return Ice::stringToIdentity(s); } string Ice::CommunicatorI::identityToString(const Identity& ident) const { - return _instance->identityToString(ident); + return Ice::identityToString(ident); } ObjectAdapterPtr diff --git a/cpp/src/Ice/Incoming.cpp b/cpp/src/Ice/Incoming.cpp index 8b7e8a33ea4..f0de7b3c8e8 100644 --- a/cpp/src/Ice/Incoming.cpp +++ b/cpp/src/Ice/Incoming.cpp @@ -172,7 +172,7 @@ IceInternal::IncomingBase::__warning(const Exception& ex) const Warning out(_os.instance()->initializationData().logger); out << "dispatch exception: " << ex; - out << "\nidentity: " << _os.instance()->identityToString(_current.id); + out << "\nidentity: " << Ice::identityToString(_current.id); out << "\nfacet: " << IceUtilInternal::escapeString(_current.facet, ""); out << "\noperation: " << _current.operation; @@ -193,7 +193,7 @@ IceInternal::IncomingBase::__warning(const string& msg) const Warning out(_os.instance()->initializationData().logger); out << "dispatch exception: " << msg; - out << "\nidentity: " << _os.instance()->identityToString(_current.id); + out << "\nidentity: " << Ice::identityToString(_current.id); out << "\nfacet: " << IceUtilInternal::escapeString(_current.facet, ""); out << "\noperation: " << _current.operation; diff --git a/cpp/src/Ice/Initialize.cpp b/cpp/src/Ice/Initialize.cpp index bc29df15d75..e2d26dfffd6 100644 --- a/cpp/src/Ice/Initialize.cpp +++ b/cpp/src/Ice/Initialize.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -420,3 +421,118 @@ Ice::newBatchRequestInterceptor(const ::std::function(pos)- escapes > 0 && s[pos - escapes - 1] == '\\') + { + escapes++; + } + + // + // We ignore escaped escapes + // + if(escapes % 2 == 0) + { + if(slash == string::npos) + { + slash = pos; + } + else + { + // + // Extra unescaped slash found. + // + IdentityParseException ex(__FILE__, __LINE__); + ex.str = "unescaped backslash in identity `" + s + "'"; + throw ex; + } + } + pos++; + } + + if(slash == string::npos) + { + try + { + ident.name = IceUtilInternal::unescapeString(s, 0, s.size()); + } + catch(const IceUtil::IllegalArgumentException& e) + { + IdentityParseException ex(__FILE__, __LINE__); + ex.str = "invalid identity name `" + s + "': " + e.reason(); + throw ex; + } + } + else + { + try + { + ident.category = IceUtilInternal::unescapeString(s, 0, slash); + } + catch(const IceUtil::IllegalArgumentException& e) + { + IdentityParseException ex(__FILE__, __LINE__); + ex.str = "invalid category in identity `" + s + "': " + e.reason(); + throw ex; + } + if(slash + 1 < s.size()) + { + try + { + ident.name = IceUtilInternal::unescapeString(s, slash + 1, s.size()); + } + catch(const IceUtil::IllegalArgumentException& e) + { + IdentityParseException ex(__FILE__, __LINE__); + ex.str = "invalid name in identity `" + s + "': " + e.reason(); + throw ex; + } + } + } + + ident.name = UTF8ToNative(ident.name, IceUtil::getProcessStringConverter()); + ident.category = UTF8ToNative(ident.category, IceUtil::getProcessStringConverter()); + + return ident; +} + +string +Ice::identityToString(const Identity& ident) +{ + // + // This method returns the stringified identity. The returned string only + // contains printable ascii. It can contain UTF8 in the escaped form. + // + string name = nativeToUTF8(ident.name, IceUtil::getProcessStringConverter()); + string category = nativeToUTF8(ident.category, IceUtil::getProcessStringConverter()); + + if(category.empty()) + { + return IceUtilInternal::escapeString(name, "/"); + } + else + { + return IceUtilInternal::escapeString(category, "/") + '/' + IceUtilInternal::escapeString(name, "/"); + } +} diff --git a/cpp/src/Ice/Instance.cpp b/cpp/src/Ice/Instance.cpp index 4b3590c01de..9639a28afa6 100644 --- a/cpp/src/Ice/Instance.cpp +++ b/cpp/src/Ice/Instance.cpp @@ -576,121 +576,6 @@ IceInternal::Instance::serverACM() const return _serverACM; } -Identity -IceInternal::Instance::stringToIdentity(const string& s) const -{ - // - // This method only accepts printable ascii. Since printable ascii is a subset - // of all narrow string encodings, it is not necessary to convert the string - // from the native string encoding. Any characters other than printable-ASCII - // will cause an IllegalArgumentException. Note that it can contain Unicode - // encoded in the escaped form which is the reason why we call fromUTF8 after - // unespcaping the printable ASCII string. - // - - Identity ident; - - // - // Find unescaped separator; note that the string may contain an escaped - // backslash before the separator. - // - string::size_type slash = string::npos, pos = 0; - while((pos = s.find('/', pos)) != string::npos) - { - int escapes = 0; - while(static_cast(pos)- escapes > 0 && s[pos - escapes - 1] == '\\') - { - escapes++; - } - - // - // We ignore escaped escapes - // - if(escapes % 2 == 0) - { - if(slash == string::npos) - { - slash = pos; - } - else - { - // - // Extra unescaped slash found. - // - IdentityParseException ex(__FILE__, __LINE__); - ex.str = "unescaped backslash in identity `" + s + "'"; - throw ex; - } - } - pos++; - } - - if(slash == string::npos) - { - try - { - ident.name = IceUtilInternal::unescapeString(s, 0, s.size()); - } - catch(const IceUtil::IllegalArgumentException& e) - { - IdentityParseException ex(__FILE__, __LINE__); - ex.str = "invalid identity name `" + s + "': " + e.reason(); - throw ex; - } - } - else - { - try - { - ident.category = IceUtilInternal::unescapeString(s, 0, slash); - } - catch(const IceUtil::IllegalArgumentException& e) - { - IdentityParseException ex(__FILE__, __LINE__); - ex.str = "invalid category in identity `" + s + "': " + e.reason(); - throw ex; - } - if(slash + 1 < s.size()) - { - try - { - ident.name = IceUtilInternal::unescapeString(s, slash + 1, s.size()); - } - catch(const IceUtil::IllegalArgumentException& e) - { - IdentityParseException ex(__FILE__, __LINE__); - ex.str = "invalid name in identity `" + s + "': " + e.reason(); - throw ex; - } - } - } - - ident.name = UTF8ToNative(ident.name, _stringConverter); - ident.category = UTF8ToNative(ident.category, _stringConverter); - - return ident; -} - -string -IceInternal::Instance::identityToString(const Identity& ident) const -{ - // - // This method returns the stringified identity. The returned string only - // contains printable ascii. It can contain UTF8 in the escaped form. - // - string name = nativeToUTF8(ident.name, _stringConverter); - string category = nativeToUTF8(ident.category, _stringConverter); - - if(category.empty()) - { - return IceUtilInternal::escapeString(name, "/"); - } - else - { - return IceUtilInternal::escapeString(category, "/") + '/' + IceUtilInternal::escapeString(name, "/"); - } -} - Ice::ObjectPrx IceInternal::Instance::createAdmin(const ObjectAdapterPtr& adminAdapter, const Identity& adminIdentity) { diff --git a/cpp/src/Ice/Instance.h b/cpp/src/Ice/Instance.h index a6e9182b136..40b766d14ee 100644 --- a/cpp/src/Ice/Instance.h +++ b/cpp/src/Ice/Instance.h @@ -113,8 +113,6 @@ public: bool collectObjects() const { return _collectObjects; } const ACMConfig& clientACM() const; const ACMConfig& serverACM() const; - Ice::Identity stringToIdentity(const std::string&) const; - std::string identityToString(const Ice::Identity&) const; Ice::ObjectPrx createAdmin(const Ice::ObjectAdapterPtr&, const Ice::Identity&); Ice::ObjectPrx getAdmin(); diff --git a/cpp/src/Ice/LocatorInfo.cpp b/cpp/src/Ice/LocatorInfo.cpp index b4ea96998b1..15ea04f2187 100644 --- a/cpp/src/Ice/LocatorInfo.cpp +++ b/cpp/src/Ice/LocatorInfo.cpp @@ -745,12 +745,12 @@ IceInternal::LocatorInfo::getEndpointsException(const ReferencePtr& ref, const I Trace out(ref->getInstance()->initializationData().logger, ref->getInstance()->traceLevels()->locationCat); out << "object not found" << "\n"; - out << "object = " << ref->getInstance()->identityToString(ref->getIdentity()); + out << "object = " << Ice::identityToString(ref->getIdentity()); } NotRegisteredException ex(__FILE__, __LINE__); ex.kindOfObject = "object"; - ex.id = ref->getInstance()->identityToString(ref->getIdentity()); + ex.id = Ice::identityToString(ref->getIdentity()); throw ex; } catch(const NotRegisteredException&) @@ -765,7 +765,7 @@ IceInternal::LocatorInfo::getEndpointsException(const ReferencePtr& ref, const I out << "couldn't contact the locator to retrieve adapter endpoints\n"; if(ref->getAdapterId().empty()) { - out << "object = " << ref->getInstance()->identityToString(ref->getIdentity()) << "\n"; + out << "object = " << Ice::identityToString(ref->getIdentity()) << "\n"; } else { @@ -800,7 +800,7 @@ IceInternal::LocatorInfo::getEndpointsTrace(const ReferencePtr& ref, if(ref->getAdapterId().empty()) { out << "object\n"; - out << "object = " << ref->getInstance()->identityToString(ref->getIdentity()); + out << "object = " << Ice::identityToString(ref->getIdentity()); } else { @@ -823,7 +823,7 @@ IceInternal::LocatorInfo::trace(const string& msg, const ReferencePtr& ref, cons } else { - out << "object = " << ref->getInstance()->identityToString(ref->getIdentity()) << '\n'; + out << "object = " << Ice::identityToString(ref->getIdentity()) << '\n'; } const char* sep = endpoints.size() > 1 ? ":" : ""; @@ -861,7 +861,7 @@ IceInternal::LocatorInfo::getObjectRequest(const ReferencePtr& ref) if(ref->getInstance()->traceLevels()->location >= 1) { Trace out(ref->getInstance()->initializationData().logger, ref->getInstance()->traceLevels()->locationCat); - out << "searching for object by id\nobject = " << ref->getInstance()->identityToString(ref->getIdentity()); + out << "searching for object by id\nobject = " << Ice::identityToString(ref->getIdentity()); } map::const_iterator p = _objectRequests.find(ref->getIdentity()); diff --git a/cpp/src/Ice/ObjectAdapterI.cpp b/cpp/src/Ice/ObjectAdapterI.cpp index 220811dda07..2513179cbc3 100644 --- a/cpp/src/Ice/ObjectAdapterI.cpp +++ b/cpp/src/Ice/ObjectAdapterI.cpp @@ -958,7 +958,7 @@ Ice::ObjectAdapterI::initialize(const RouterPrx& router) if(_routerInfo->getAdapter()) { throw AlreadyRegisteredException(__FILE__, __LINE__, "object adapter with router", - _instance->identityToString(router->ice_getIdentity())); + Ice::identityToString(router->ice_getIdentity())); } // diff --git a/cpp/src/Ice/Reference.cpp b/cpp/src/Ice/Reference.cpp index c461535c33e..5425b17c372 100644 --- a/cpp/src/Ice/Reference.cpp +++ b/cpp/src/Ice/Reference.cpp @@ -233,7 +233,7 @@ IceInternal::Reference::toString() const // the reference parser uses as separators, then we enclose // the identity string in quotes. // - string id = _instance->identityToString(_identity); + string id = Ice::identityToString(_identity); if(id.find_first_of(" :@") != string::npos) { s << '"' << id << '"'; diff --git a/cpp/src/Ice/ReferenceFactory.cpp b/cpp/src/Ice/ReferenceFactory.cpp index 24c5d1d384b..f3df46b5427 100644 --- a/cpp/src/Ice/ReferenceFactory.cpp +++ b/cpp/src/Ice/ReferenceFactory.cpp @@ -155,7 +155,7 @@ IceInternal::ReferenceFactory::create(const string& str, const string& propertyP // // Parsing the identity may raise IdentityParseException. // - Identity ident = _instance->stringToIdentity(idstr); + Identity ident = Ice::stringToIdentity(idstr); if(ident.name.empty()) { // diff --git a/cpp/src/Ice/ServantManager.cpp b/cpp/src/Ice/ServantManager.cpp index be20f45e704..2d95dc1027d 100644 --- a/cpp/src/Ice/ServantManager.cpp +++ b/cpp/src/Ice/ServantManager.cpp @@ -44,7 +44,7 @@ IceInternal::ServantManager::addServant(const ObjectPtr& object, const Identity& { AlreadyRegisteredException ex(__FILE__, __LINE__); ex.kindOfObject = "servant"; - ex.id = _instance->identityToString(ident); + ex.id = Ice::identityToString(ident); if(!facet.empty()) { string fs = nativeToUTF8(facet, _instance->getStringConverter()); @@ -104,7 +104,7 @@ IceInternal::ServantManager::removeServant(const Identity& ident, const string& { NotRegisteredException ex(__FILE__, __LINE__); ex.kindOfObject = "servant"; - ex.id = _instance->identityToString(ident); + ex.id = Ice::identityToString(ident); if(!facet.empty()) { string fs = nativeToUTF8(facet, _instance->getStringConverter()); @@ -178,7 +178,7 @@ IceInternal::ServantManager::removeAllFacets(const Identity& ident) { NotRegisteredException ex(__FILE__, __LINE__); ex.kindOfObject = "servant"; - ex.id = _instance->identityToString(ident); + ex.id = Ice::identityToString(ident); throw ex; } diff --git a/cpp/src/Ice/TraceUtil.cpp b/cpp/src/Ice/TraceUtil.cpp index c0c19e7a22b..09634522617 100644 --- a/cpp/src/Ice/TraceUtil.cpp +++ b/cpp/src/Ice/TraceUtil.cpp @@ -30,7 +30,7 @@ printIdentityFacetOperation(ostream& s, BasicStream& stream) { Identity identity; stream.read(identity); - s << "\nidentity = " << stream.instance()->identityToString(identity); + s << "\nidentity = " << Ice::identityToString(identity); vector facet; stream.read(facet); -- cgit v1.2.3