summaryrefslogtreecommitdiff
path: root/cppe/src/IceE/Instance.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cppe/src/IceE/Instance.cpp')
-rw-r--r--cppe/src/IceE/Instance.cpp149
1 files changed, 148 insertions, 1 deletions
diff --git a/cppe/src/IceE/Instance.cpp b/cppe/src/IceE/Instance.cpp
index 25def1ce6ee..9dc797bef7c 100644
--- a/cppe/src/IceE/Instance.cpp
+++ b/cppe/src/IceE/Instance.cpp
@@ -29,8 +29,8 @@
#ifndef ICEE_PURE_CLIENT
# include <IceE/ObjectAdapterFactory.h>
#endif
-
#include <IceE/StaticMutex.h>
+#include <IceE/StringUtil.h>
#ifdef _WIN32
# include <winsock2.h>
@@ -222,6 +222,109 @@ IceInternal::Instance::flushBatchRequests()
}
#endif
+Identity
+IceInternal::Instance::stringToIdentity(const string& s) const
+{
+ Identity ident;
+
+ //
+ // Find unescaped separator.
+ //
+ string::size_type slash = string::npos, pos = 0;
+ while((pos = s.find('/', pos)) != string::npos)
+ {
+ if(pos == 0 || s[pos - 1] != '\\')
+ {
+ if(slash == string::npos)
+ {
+ slash = pos;
+ }
+ else
+ {
+ //
+ // Extra unescaped slash found.
+ //
+ IdentityParseException ex(__FILE__, __LINE__);
+ ex.str = s;
+ throw ex;
+ }
+ }
+ pos++;
+ }
+
+ if(slash == string::npos)
+ {
+ if(!IceUtil::unescapeString(s, 0, s.size(), ident.name))
+ {
+ IdentityParseException ex(__FILE__, __LINE__);
+ ex.str = s;
+ throw ex;
+ }
+ }
+ else
+ {
+ if(!IceUtil::unescapeString(s, 0, slash, ident.category))
+ {
+ IdentityParseException ex(__FILE__, __LINE__);
+ ex.str = s;
+ throw ex;
+ }
+ if(slash + 1 < s.size())
+ {
+ if(!IceUtil::unescapeString(s, slash + 1, s.size(), ident.name))
+ {
+ IdentityParseException ex(__FILE__, __LINE__);
+ ex.str = s;
+ throw ex;
+ }
+ }
+ }
+
+ if(_initData.stringConverter)
+ {
+ string tmpString;
+ _initData.stringConverter->fromUTF8(reinterpret_cast<const Byte*>(ident.name.data()),
+ reinterpret_cast<const Byte*>(ident.name.data() + ident.name.size()),
+ tmpString);
+ ident.name = tmpString;
+
+ _initData.stringConverter->fromUTF8(reinterpret_cast<const Byte*>(ident.category.data()),
+ reinterpret_cast<const Byte*>(ident.category.data() + ident.name.size()),
+ tmpString);
+ ident.category = tmpString;
+ }
+
+ return ident;
+}
+
+string
+IceInternal::Instance::identityToString(const Identity& ident) const
+{
+ string name = ident.name;
+ string category = ident.category;
+ if(_initData.stringConverter)
+ {
+ UTF8BufferI buffer;
+ Byte* last = _initData.stringConverter->toUTF8(ident.name.data(), ident.name.data() + ident.name.size(),
+ buffer);
+ name = string(buffer.getBuffer(), last);
+
+ buffer.reset();
+ last = _initData.stringConverter->toUTF8(ident.category.data(), ident.category.data() + ident.category.size(),
+ buffer);
+ category = string(buffer.getBuffer(), last);
+ }
+
+ if(category.empty())
+ {
+ return IceUtil::escapeString(name, "/");
+ }
+ else
+ {
+ return IceUtil::escapeString(category, "/") + '/' + IceUtil::escapeString(name, "/");
+ }
+}
+
IceInternal::Instance::Instance(const CommunicatorPtr& communicator, const InitializationData& initData) :
_state(StateActive),
_initData(initData),
@@ -612,3 +715,47 @@ IceInternal::Instance::destroy()
_state = StateDestroyed;
}
}
+
+IceInternal::UTF8BufferI::UTF8BufferI() :
+ _buffer(0),
+ _offset(0)
+{
+}
+
+IceInternal::UTF8BufferI::~UTF8BufferI()
+{
+ free(_buffer);
+}
+
+Byte*
+IceInternal::UTF8BufferI::getMoreBytes(size_t howMany, Byte* firstUnused)
+{
+ if(_buffer == 0)
+ {
+ _buffer = (Byte*)malloc(howMany);
+ }
+ else
+ {
+ if(firstUnused != 0)
+ {
+ _offset = firstUnused - _buffer;
+ }
+ _buffer = (Byte*)realloc(_buffer, _offset + howMany);
+ }
+
+ return _buffer + _offset;
+}
+
+Byte*
+IceInternal::UTF8BufferI::getBuffer()
+{
+ return _buffer;
+}
+
+void
+IceInternal::UTF8BufferI::reset()
+{
+ free(_buffer);
+ _buffer = 0;
+ _offset = 0;
+}