summaryrefslogtreecommitdiff
path: root/cpp/src/Ice/Instance.cpp
diff options
context:
space:
mode:
authorJose <jose@zeroc.com>2016-02-29 18:04:18 +0100
committerJose <jose@zeroc.com>2016-02-29 18:04:18 +0100
commit97554afcad548fcac64d399fd2e05af49ffcba12 (patch)
tree6916a256775181b7674f39ad7b3f3eeaa1fdfa62 /cpp/src/Ice/Instance.cpp
parentICE-6952 - identityToString/stringToIdentity non member functions (diff)
downloadice-97554afcad548fcac64d399fd2e05af49ffcba12.tar.bz2
ice-97554afcad548fcac64d399fd2e05af49ffcba12.tar.xz
ice-97554afcad548fcac64d399fd2e05af49ffcba12.zip
Rework previous fix for 3.6 compatibility
Diffstat (limited to 'cpp/src/Ice/Instance.cpp')
-rw-r--r--cpp/src/Ice/Instance.cpp115
1 files changed, 115 insertions, 0 deletions
diff --git a/cpp/src/Ice/Instance.cpp b/cpp/src/Ice/Instance.cpp
index 9639a28afa6..4b3590c01de 100644
--- a/cpp/src/Ice/Instance.cpp
+++ b/cpp/src/Ice/Instance.cpp
@@ -576,6 +576,121 @@ 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<int>(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)
{