Change to use secure log in IO
[platform/framework/native/appfw.git] / src / io / FIo_MessagePortProxy.cpp
index 3e8c9cb..d2e32fb 100644 (file)
@@ -51,7 +51,7 @@ static const int MAX_MESSAGE_SIZE = 16 * 1024;
 static void
 ConvertBundleToMap(const char *pKey, const int type, const bundle_keyval_t *pVal, void *pData)
 {
-       SysLog(NID_IO, "CB key = %s", pKey);
+       //SysLog(NID_IO, "CB key = %s", pKey);
 
        HashMap* pMap = static_cast<HashMap*>(pData);
 
@@ -72,16 +72,18 @@ ConvertBundleToMap(const char *pKey, const int type, const bundle_keyval_t *pVal
                        case BUNDLE_TYPE_BYTE:
                                bundle_keyval_get_basic_val(const_cast<bundle_keyval_t*>(pVal), reinterpret_cast<void**>(&pStr), &size);
 
-                               SysLog(NID_IO, "Bundle byte value = %s, size = %d", pStr, size);
+                               //SysLog(NID_IO, "Bundle byte value = %s, size = %d", pStr, size);
 
                                if (pStr)
                                {
                                        ByteBuffer* pBuffer = new (std::nothrow) ByteBuffer();
-                                       SysTryReturn(NID_IO, pMap != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+                                       SysTryReturnVoidResult(NID_IO, pMap != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
                                        result r = pBuffer->Construct(size);
-                                       SysTryReturn(NID_IO, r == E_SUCCESS, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+                                       SysTryCatch(NID_IO, r == E_SUCCESS, delete pBuffer, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+
+                                       r = pBuffer->SetArray((const byte*)pStr, 0, size);
+                                       SysTryCatch(NID_IO, r == E_SUCCESS, delete pBuffer, E_INVALID_ARG, "[E_INVALID_ARG] The buffer argument is invalid.");
 
-                                       pBuffer->SetArray((const byte*)pStr, 0, size);
                                        pBuffer->Flip();
 
                                        pMap->Add(new (std::nothrow) String(pKey), pBuffer);
@@ -93,6 +95,9 @@ ConvertBundleToMap(const char *pKey, const int type, const bundle_keyval_t *pVal
                                break;
                }
        }
+
+CATCH:
+       return;
 }
 
 static void
@@ -108,13 +113,13 @@ OnMessageReceived(int id, const char* remote_app_id, const char* remote_port, bo
        ret = messageport_get_local_port_name(id, &pLocalPort);
        if (pLocalPort == null)
        {
-               SysLog(NID_IO, "No local port for id: %d", id);
+               SysSecureLog(NID_IO, "No local port for id: %d", id);
 
                bundle_free(data);
                return;
        }
 
-       SysLog(NID_IO, "local port name: %s", pLocalPort);
+       //SysLog(NID_IO, "local port name: %s", pLocalPort);
 
        _IMessagePortListener* pListener = null;
        p->__listeners.GetValue(pLocalPort, pListener);
@@ -129,8 +134,6 @@ OnMessageReceived(int id, const char* remote_app_id, const char* remote_port, bo
                result r = pMap->Construct();
                SysTryCatch(NID_IO, r == E_SUCCESS, delete pMap, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
 
-               SysLog(NID_IO, "bundle to map");
-
                bundle_foreach(data, ConvertBundleToMap, pMap);
 
                if (remote_app_id == null) // Uni-directional
@@ -139,7 +142,7 @@ OnMessageReceived(int id, const char* remote_app_id, const char* remote_port, bo
                }
                else // Bi-directional
                {
-                       SysLog(NID_IO, "Message received from [%s:%s], trusted: %d", remote_app_id, remote_port, trusted_port);
+                       SysSecureLog(NID_IO, "Message received from [%s:%s], trusted: %d", remote_app_id, remote_port, trusted_port);
 
                        pListener->OnMessageReceivedN(remote_app_id, remote_port, trusted_port, pMap);
                }
@@ -161,7 +164,7 @@ OnTrustedMessageReceived(int id, const char* remote_app_id, const char* remote_p
        ret = messageport_get_local_port_name(id, &pLocalPort);
        if (pLocalPort == null)
        {
-               SysLog(NID_IO, "No local port for id: %d", id);
+               SysSecureLog(NID_IO, "No local port for id: %d", id);
 
                bundle_free(data);
                return;
@@ -188,7 +191,8 @@ OnTrustedMessageReceived(int id, const char* remote_app_id, const char* remote_p
                }
                else // Bi-directional
                {
-                       SysLog(NID_IO, "Trusted message received from [%s:%s], trusted: %d", remote_app_id, remote_port, trusted_port);
+                       SysSecureLog(NID_IO, "Trusted message received from [%s:%s], trusted: %d", remote_app_id, remote_port, trusted_port);
+
                        pListener->OnMessageReceivedN(remote_app_id, remote_port, trusted_port, pMap);
                }
        }
@@ -226,7 +230,7 @@ result
 _MessagePortProxy::RegisterMessagePort(const String& localPort,        bool isTrusted,
                                                                        const _IMessagePortListener& listener)
 {
-       SysLog(NID_IO, "Register a message port : [%ls:%ls]", __appId.GetPointer(), localPort.GetPointer());
+       SysSecureLog(NID_IO, "Register a message port : [%ls:%ls]", __appId.GetPointer(), localPort.GetPointer());
 
        result r = E_SUCCESS;
        int ret = 0;
@@ -281,7 +285,7 @@ _MessagePortProxy::RequestRemotePort(const AppId& remoteAppId,
                                                                        const String& remotePort,
                                                                        bool isTrusted)
 {
-       SysLog(NID_IO, "Request a remote message port [%ls:%ls]", remoteAppId.GetPointer(), remotePort.GetPointer());
+       SysSecureLog(NID_IO, "Request a remote message port [%ls:%ls]", remoteAppId.GetPointer(), remotePort.GetPointer());
 
        result r = E_SUCCESS;
        int ret = 0;
@@ -318,7 +322,7 @@ _MessagePortProxy::RequestRemotePort(const AppId& remoteAppId,
 result
 _MessagePortProxy::SendMessage(const AppId& remoteAppId, const String& remotePort, bool isTrusted, const HashMap* pMap)
 {
-       SysLog(NID_IO, "Send a unidirectional message to remote port [%ls:%ls]", remoteAppId.GetPointer(), remotePort.GetPointer());
+       SysSecureLog(NID_IO, "Send a unidirectional message to remote port [%ls:%ls]", remoteAppId.GetPointer(), remotePort.GetPointer());
 
        int ret = 0;
        int size = 0;
@@ -326,7 +330,7 @@ _MessagePortProxy::SendMessage(const AppId& remoteAppId, const String& remotePor
        // Convert Map to bundle
        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.");
+       //SysTryReturnResult(NID_IO, size <= MAX_MESSAGE_SIZE, E_MAX_EXCEEDED, "The size of the message has exceeded the maximum limit.");
 
        unique_ptr<char[]> pRemoteAppId(_StringConverter::CopyToCharArrayN(remoteAppId));
        unique_ptr<char[]> pRemotePort(_StringConverter::CopyToCharArrayN(remotePort));
@@ -348,6 +352,8 @@ _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;
@@ -359,7 +365,7 @@ _MessagePortProxy::SendMessage(const AppId& remoteAppId, const String& remotePor
 result
 _MessagePortProxy::SendMessage(const String& localPort, bool isTrustedLocal, const AppId& remoteAppId, const String& remotePort, bool isTrustedRemote, const HashMap* pMap)
 {
-       SysLog(NID_IO, "Send a bidirectional message from [%ls:%ls] to [%ls:%ls]", __appId.GetPointer(), localPort.GetPointer(), remoteAppId.GetPointer(), remotePort.GetPointer());
+       SysSecureLog(NID_IO, "Send a bidirectional message from [%ls:%ls] to [%ls:%ls]", __appId.GetPointer(), localPort.GetPointer(), remoteAppId.GetPointer(), remotePort.GetPointer());
 
        result r = E_SUCCESS;
        int id = 0;
@@ -380,7 +386,7 @@ _MessagePortProxy::SendMessage(const String& localPort, bool isTrustedLocal, con
        // Convert Map to bundle
        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.");
+       //SysTryReturnResult(NID_IO, size <= MAX_MESSAGE_SIZE, E_MAX_EXCEEDED, "The size of the message has exceeded the maximum limit.");
 
        unique_ptr<char[]> pRemoteAppId(_StringConverter::CopyToCharArrayN(remoteAppId));
        unique_ptr<char[]> pRemotePort(_StringConverter::CopyToCharArrayN(remotePort));