From 197b6de9281b52d0b53c4b3fa3312e371b4469a9 Mon Sep 17 00:00:00 2001 From: Dwayne Boone Date: Tue, 9 May 2006 13:07:41 +0000 Subject: Fixed proxy and identity t/from string functions to use string converters --- cppe/src/IceE/Instance.cpp | 149 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 148 insertions(+), 1 deletion(-) (limited to 'cppe/src/IceE/Instance.cpp') 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 #endif - #include +#include #ifdef _WIN32 # include @@ -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(ident.name.data()), + reinterpret_cast(ident.name.data() + ident.name.size()), + tmpString); + ident.name = tmpString; + + _initData.stringConverter->fromUTF8(reinterpret_cast(ident.category.data()), + reinterpret_cast(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; +} -- cgit v1.2.3