From: Sunwook Bae Date: Fri, 5 Apr 2013 11:01:06 +0000 (+0900) Subject: Update the size check in MessagePort X-Git-Tag: accepted/tizen_2.1/20130425.034849~146^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7004eb0d606ebd97b132f24077a1b6fd3fdec67d;p=platform%2Fframework%2Fnative%2Fappfw.git Update the size check in MessagePort Change-Id: Icdfc706560d1aa7cbb5f5c0bee07aeb0ce08664a Signed-off-by: Sunwook Bae --- diff --git a/inc/FIoRemoteMessagePort.h b/inc/FIoRemoteMessagePort.h index 6ac2304..2facefb 100644 --- a/inc/FIoRemoteMessagePort.h +++ b/inc/FIoRemoteMessagePort.h @@ -147,13 +147,13 @@ public: * * @return An error code * @param[in] pMessage A pointer to an argument map of key (String) and value (String or ByteBuffer) pair @n - * The recommended message size is under 4KB. + * The recommended message size is under 16KB. * @exception E_SUCCESS The method is successful. * @exception E_INVALID_ARG The message argument is not a map of key (String) and value (String or ByteBuffer) pair. * @exception E_OBJ_NOT_FOUND The message port of the target application is not found. * @exception E_MAX_EXCEEDED The size of @c pMessage has exceeded the maximum limit. * @exception E_SYSTEM The method has failed due to a severe system error. - * @remarks The recommended message size is under 4KB because severe system performance degradation may occur for large messages. E_MAX_EXCEEDED may be returned for messages over 4KB size. + * @remarks The recommended message size is under 16KB because severe system performance degradation may occur for large messages. E_MAX_EXCEEDED may be returned for messages over 16KB size. */ result SendMessage(const Tizen::Base::Collection::IMap* pMessage); @@ -166,7 +166,7 @@ public: * @return An error code * @param[in] pLocalMessagePort The local message port * @param[in] pMessage A pointer to an argument map of key (String) and value (String or ByteBuffer) pair @n - * The recommended message size is under 4KB. + * The recommended message size is under 16KB. * @exception E_SUCCESS The method is successful. * @exception E_INVALID_ARG Either of the following conditions has occurred: @n * - The local message port is @c null. @n @@ -174,7 +174,7 @@ public: * @exception E_OBJ_NOT_FOUND The message port of the target application is not found. * @exception E_MAX_EXCEEDED The size of @c pMessage has exceeded the maximum limit. * @exception E_SYSTEM The method has failed due to a severe system error. - * @remarks The recommended message size is under 4KB because severe system performance degradation may occur for large messages. E_MAX_EXCEEDED may be returned for messages over 4KB size. + * @remarks The recommended message size is under 16KB because severe system performance degradation may occur for large messages. E_MAX_EXCEEDED may be returned for messages over 16KB size. */ result SendMessage(const LocalMessagePort* pLocalMessagePort, const Tizen::Base::Collection::IMap* pMessage); diff --git a/src/io/FIo_MessagePortProxy.cpp b/src/io/FIo_MessagePortProxy.cpp index 57a7217..3e8c9cb 100644 --- a/src/io/FIo_MessagePortProxy.cpp +++ b/src/io/FIo_MessagePortProxy.cpp @@ -46,6 +46,8 @@ using namespace Tizen::Base::Runtime; namespace Tizen { namespace Io { +static const int MAX_MESSAGE_SIZE = 16 * 1024; + static void ConvertBundleToMap(const char *pKey, const int type, const bundle_keyval_t *pVal, void *pData) { @@ -319,10 +321,12 @@ _MessagePortProxy::SendMessage(const AppId& remoteAppId, const String& remotePor SysLog(NID_IO, "Send a unidirectional message to remote port [%ls:%ls]", remoteAppId.GetPointer(), remotePort.GetPointer()); int ret = 0; + int size = 0; // Convert Map to bundle - bundle* b = ConvertMapToBundleN(pMap); - SysTryReturnResult(NID_IO, b != null, E_SYSTEM, "Internal system errors."); + bundle* b = ConvertMapToBundleN(pMap, &size); + SysTryReturnResult(NID_IO, b != null, E_INVALID_ARG, "The argument is invalid."); + SysTryReturnResult(NID_IO, size <= MAX_MESSAGE_SIZE, E_MAX_EXCEEDED, "The size of the message has exceeded the maximum limit."); unique_ptr pRemoteAppId(_StringConverter::CopyToCharArrayN(remoteAppId)); unique_ptr pRemotePort(_StringConverter::CopyToCharArrayN(remotePort)); @@ -344,8 +348,6 @@ _MessagePortProxy::SendMessage(const AppId& remoteAppId, const String& remotePor SysTryReturnResult(NID_IO, r != E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "The remote message port is not found."); SysTryReturnResult(NID_IO, r != E_CERTIFICATE_VERIFICATION_FAILED, E_CERTIFICATE_VERIFICATION_FAILED, "The target application is not signed with the same certificate."); - SysTryReturnResult(NID_IO, r != E_MAX_EXCEEDED, E_MAX_EXCEEDED, "The size of the message has exceeded the maximum limit."); - SysLogException(NID_IO, E_SYSTEM, "[E_SYSTEM] Failed to request the remote message port."); return r; @@ -373,9 +375,12 @@ _MessagePortProxy::SendMessage(const String& localPort, bool isTrustedLocal, con SysTryReturnResult(NID_IO, r == E_SUCCESS, E_SYSTEM, "Internal system errors."); + int size = 0; + // Convert Map to bundle - bundle* b = ConvertMapToBundleN(pMap); - SysTryReturnResult(NID_IO, b != null, E_SYSTEM, "Internal system errors."); + bundle* b = ConvertMapToBundleN(pMap, &size); + SysTryReturnResult(NID_IO, b != null, E_INVALID_ARG, "The argument is invalid."); + SysTryReturnResult(NID_IO, size <= MAX_MESSAGE_SIZE, E_MAX_EXCEEDED, "The size of the message has exceeded the maximum limit."); unique_ptr pRemoteAppId(_StringConverter::CopyToCharArrayN(remoteAppId)); unique_ptr pRemotePort(_StringConverter::CopyToCharArrayN(remotePort)); @@ -461,9 +466,10 @@ _MessagePortProxy::ConvertToResult(int error) } bundle* -_MessagePortProxy::ConvertMapToBundleN(const HashMap* pMap) +_MessagePortProxy::ConvertMapToBundleN(const HashMap* pMap, int* pSize) { bundle *b = bundle_create(); + int size = 0; std::unique_ptr pEnum (pMap->GetMapEnumeratorN()); while(pEnum->MoveNext() == E_SUCCESS) @@ -477,7 +483,10 @@ _MessagePortProxy::ConvertMapToBundleN(const HashMap* pMap) if (typeid(*pValue) == typeid(const String)) // String { - unique_ptr pValueData(_StringConverter::CopyToCharArrayN(*(static_cast(pValue)))); + const String* pStr = static_cast(pValue); + size += pStr->GetLength() * sizeof(wchar_t); + + unique_ptr pValueData(_StringConverter::CopyToCharArrayN(*pStr)); //SysLog(NID_IO, "key: %s, value: %s", pKeyData.get(), pValueData.get()); @@ -488,15 +497,15 @@ _MessagePortProxy::ConvertMapToBundleN(const HashMap* pMap) if (typeid(*pValue) == typeid(const ByteBuffer)) // ByteBuffer { const ByteBuffer* pBuffer = static_cast(pValue); + size += pBuffer->GetLimit(); - // Add a byte data to bundle - SysLog(NID_IO, "Add a string key: %s, byte value: %s", pKeyData.get(), pBuffer->GetPointer()); + //SysLog(NID_IO, "Add a string key: %s, byte value: %s", pKeyData.get(), pBuffer->GetPointer()); bundle_add_byte(b, pKeyData.get(), pBuffer->GetPointer(), pBuffer->GetLimit()); } else { - SysLog(NID_IO, "Not supported"); + SysLog(NID_IO, "The value type is not supported."); bundle_free(b); return null; @@ -505,13 +514,14 @@ _MessagePortProxy::ConvertMapToBundleN(const HashMap* pMap) } else { - SysLog(NID_IO, "Not supported"); + SysLog(NID_IO, "The key type is not supported."); bundle_free(b); return null; } } + *pSize = size; return b; } diff --git a/src/io/FIo_RemoteMessagePortImpl.cpp b/src/io/FIo_RemoteMessagePortImpl.cpp index 00df8cf..e657308 100644 --- a/src/io/FIo_RemoteMessagePortImpl.cpp +++ b/src/io/FIo_RemoteMessagePortImpl.cpp @@ -88,7 +88,6 @@ result _RemoteMessagePortImpl::SendMessage(const IMap* pMessage) { SysTryReturnResult(NID_IO, pMessage != null, E_INVALID_ARG, "The argument is null."); - SysTryReturnResult(NID_IO, CheckMessageType(pMessage), E_INVALID_ARG, "The argument is invalid."); return _MessagePortProxy::GetProxy()->SendMessage(__remoteAppId, __remotePort, __isTrusted, (HashMap*)pMessage); } @@ -98,39 +97,10 @@ _RemoteMessagePortImpl::SendMessage(const LocalMessagePort* pLocalMessagePort, c { SysTryReturnResult(NID_IO, pLocalMessagePort != null, E_INVALID_ARG, "The argument is null."); SysTryReturnResult(NID_IO, pMessage != null, E_INVALID_ARG, "The argument is null."); - SysTryReturnResult(NID_IO, CheckMessageType(pMessage), E_INVALID_ARG, "The argument is invalid."); return _MessagePortProxy::GetProxy()->SendMessage(pLocalMessagePort->GetName(), pLocalMessagePort->IsTrusted(), __remoteAppId, __remotePort, __isTrusted, (HashMap*)pMessage); } -bool -_RemoteMessagePortImpl::CheckMessageType(const IMap* pMessage) -{ - std::unique_ptr pEnum (pMessage->GetMapEnumeratorN()); - while(pEnum->MoveNext() == E_SUCCESS) - { - const String* pKey = dynamic_cast(pEnum->GetKey()); - const Object* pValue = pEnum->GetValue(); - - if (pKey && pValue) - { - if (typeid(*pValue) != typeid(const String)) - { - if (typeid(*pValue) != typeid(const ByteBuffer)) - { - return false; - } - } - } - else - { - return false; - } - } - - return true; -} - RemoteMessagePort* _RemoteMessagePortImpl::GetMessagePort(const AppId& remoteAppId, const String& remotePort, bool isTrusted) { @@ -143,8 +113,6 @@ _RemoteMessagePortImpl::GetMessagePort(const AppId& remoteAppId, const String& r SysTryCatch(NID_IO, pImpl != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient."); r = pImpl->Construct(remoteAppId, remotePort, isTrusted); - //SysTryCatch(NID_IO, r != E_OBJ_NOT_FOUND, , E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] The remote message port is not found."); - //SysTryCatch(NID_IO, r != E_CERTIFICATE_VERIFICATION_FAILED, , E_CERTIFICATE_VERIFICATION_FAILED, "[E_CERTIFICATE_VERIFICATION_FAILED] The target application is not signed with the same certificate."); SysTryCatch(NID_IO, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r)); pRemoteMessagePort->__pRemoteMessagePortImpl = pImpl.release(); diff --git a/src/io/inc/FIo_MessagePortProxy.h b/src/io/inc/FIo_MessagePortProxy.h index 50af7ce..27bc09b 100644 --- a/src/io/inc/FIo_MessagePortProxy.h +++ b/src/io/inc/FIo_MessagePortProxy.h @@ -72,7 +72,7 @@ public: static _MessagePortProxy* GetProxy(void); - bundle* ConvertMapToBundleN(const Tizen::Base::Collection::HashMap* pMap); + bundle* ConvertMapToBundleN(const Tizen::Base::Collection::HashMap* pMap, int* pSize); private: result ConvertToResult(int error); diff --git a/src/io/inc/FIo_RemoteMessagePortImpl.h b/src/io/inc/FIo_RemoteMessagePortImpl.h index da8326e..f4ba4ef 100644 --- a/src/io/inc/FIo_RemoteMessagePortImpl.h +++ b/src/io/inc/FIo_RemoteMessagePortImpl.h @@ -69,8 +69,6 @@ private: _RemoteMessagePortImpl& operator =(const _RemoteMessagePortImpl& value); - bool CheckMessageType(const Tizen::Base::Collection::IMap* pMessage); - private: Tizen::App::AppId __remoteAppId; Tizen::Base::String __remotePort;