diff options
author | Dwayne Boone <dwayne@zeroc.com> | 2006-05-09 13:07:41 +0000 |
---|---|---|
committer | Dwayne Boone <dwayne@zeroc.com> | 2006-05-09 13:07:41 +0000 |
commit | 197b6de9281b52d0b53c4b3fa3312e371b4469a9 (patch) | |
tree | bae93f8155da0770f5dd45d12ef1160ee99aed54 /cppe/src/IceE/Instance.cpp | |
parent | Added identityToString and stringToIdentity to Communicator (diff) | |
download | ice-197b6de9281b52d0b53c4b3fa3312e371b4469a9.tar.bz2 ice-197b6de9281b52d0b53c4b3fa3312e371b4469a9.tar.xz ice-197b6de9281b52d0b53c4b3fa3312e371b4469a9.zip |
Fixed proxy and identity t/from string functions to use string converters
Diffstat (limited to 'cppe/src/IceE/Instance.cpp')
-rw-r--r-- | cppe/src/IceE/Instance.cpp | 149 |
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; +} |