Apply secure logs
[platform/framework/native/appfw.git] / src / app / FApp_SqlDataControlImpl.cpp
old mode 100644 (file)
new mode 100755 (executable)
index d7bb7d9..5ddbe2e
 #include <FBaseColIMap.h>
 #include <FBaseColIMapEnumerator.h>
 #include <FBaseRtIEventArg.h>
+#include <FBaseSysLog.h>
 #include <FIoFile.h>
+#include <FAppApp.h>
 #include <FAppSqlDataControl.h>
 #include <FAppISqlDataControlResponseListener.h>
 
-#include <FBaseSysLog.h>
-
+#include <FBase_StringConverter.h>
 #include <FIo_DataControlResultSetEnumerator.h>
 
 #include "FApp_AppControlManager.h"
@@ -46,6 +47,8 @@
 #include "FApp_AppArg.h"
 #include "FApp_DataControlManager.h"
 
+#define DATACONTROL_PROTOCOL_VER_2_1_0_2 // ver_2.1.0.2
+
 using namespace std;
 
 using namespace Tizen::Base;
@@ -59,6 +62,8 @@ namespace Tizen { namespace App
 
 static const int MAX_REQUEST_COUNT = 128;
 static const int _MAX_ARGUMENT_SIZE = 16384; // 16KB
+static const int _MAX_REQUEST_ARGUMENT_SIZE = 1048576; // 1MB
+static const char* _DATACONTROL_REQUEST_DIR = "/tmp/osp/DataControlRequest/\0";
 
 class _SqlDataControlEventArg
        : public IEventArg
@@ -314,7 +319,7 @@ _SqlDataControlImpl::Select(const String& dataId, const IList* pColumnList, cons
 
        reqId = static_cast< RequestId >(id);
 
-       SysLog(NID_APP, "[DC_CALLER_SEND] dataId: %ls, pColumnList: 0x%x, pWhere: 0x%x, pOrder: 0x%x, reqId: %d, pageNo: %d, countPerPage: %d",
+       SysLog(NID_APP, "[DC_CALLER_SEND] data: %ls, pColumnList: 0x%x, pWhere: 0x%x, pOrder: 0x%x, req: %d, pageNo: %d, countPerPage: %d",
                        dataId.GetPointer(), pColumnList, pWhere, pOrder, reqId, pageNo, countPerPage);
 
        // fall through
@@ -326,7 +331,7 @@ CATCH:
 }
 
 result
-_SqlDataControlImpl::SqlDataControlCallback(void* data, _AppArg* pArg, _AppArg* pResArg, service_result_e res, int prop)
+_SqlDataControlImpl::SqlDataControlCallback(void* data, _AppArg* pArg, _AppArg* pResArg, service_result_e res, int prop, int option)
 {
        ArrayList* pResultList = null;
        String* pResult = null;
@@ -339,11 +344,13 @@ _SqlDataControlImpl::SqlDataControlCallback(void* data, _AppArg* pArg, _AppArg*
        _DataControlResultSetEnumerator* pResultSetEnum = null;
        int requestType = 0;
        int reqId = 0;
+       int launchReqId = 0;
        int providerRes = 0;
        bool providerResult = true;
        //bundle* origBundle = null;
        bundle* resBundle = null;
        _SqlDataControlEventArg* pEventArg = null;
+       const char* p = null;
        result r = E_SUCCESS;
 
        SysTryReturnResult(NID_APP, pResArg != null, E_INVALID_ARG, "Empty result callback.");
@@ -352,7 +359,7 @@ _SqlDataControlImpl::SqlDataControlCallback(void* data, _AppArg* pArg, _AppArg*
        resBundle = pResArg->GetBundle();
        if (resBundle)
        {
-               const char* p = appsvc_get_data(resBundle, OSP_K_REQUEST_ID);
+               p = appsvc_get_data(resBundle, OSP_K_REQUEST_ID);
                SysTryCatch(NID_APP, p, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid bundle");
                reqId = atoi(p);
                Integer key(reqId);
@@ -404,7 +411,7 @@ _SqlDataControlImpl::SqlDataControlCallback(void* data, _AppArg* pArg, _AppArg*
                        SysTryCatch(NID_APP, pDataId, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
                                        "[E_OUT_OF_MEMORY] The memory is insufficient.");
 
-                       SysLog(NID_APP, "[DC_CALLER_RECV] provider result: %ld, requestType: %d, reqId: %d, providerId: %ls, dataId: %ls, errorMsg: %ls ",
+                       SysSecureLog(NID_APP, "[DC_CALLER_RECV] provider result: %ld, requestType: %d, req: %d, provider: %ls, data: %ls, errorMsg: %ls ",
                                        providerRes, requestType, reqId, pProviderId->GetPointer(), pDataId->GetPointer(), pErrorMsg->GetPointer());
 
                        switch (static_cast <_DataControlRequestType>(requestType))
@@ -488,9 +495,13 @@ _SqlDataControlImpl::SqlDataControlCallback(void* data, _AppArg* pArg, _AppArg*
                }
        }
 
+       p = appsvc_get_data(pArg->GetBundle(), OSP_K_REQUEST_ID);
+       SysTryCatch(NID_APP, p, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid bundle");
+       launchReqId = atoi(p);
+
        // Remove the request count
-       SysLog(NID_APP, "Remove a launch request: reqId: %d", reqId);
-       _AppControlManager::GetInstance()->RemoveLaunchRequest(reqId);
+       SysLog(NID_APP, "Remove a launch request: req: %d", launchReqId);
+       _AppControlManager::GetInstance()->RemoveLaunchRequest(launchReqId);
 
        return E_SUCCESS;
 
@@ -514,24 +525,84 @@ _SqlDataControlImpl::Insert(const String& dataId, const IMap& insertMap, Request
        int columnCount = 0;
        int id = 0;
        int i = 0;
+       int uniqueId = -1;
+       File request;
+       IMapEnumerator* pMapEnum = null;
        result r = E_SUCCESS;
        SysLog(NID_APP, "[DC_CALLER_SEND] SqlDataControl INSERT");
 
        columnCount = insertMap.GetCount();
        SysTryReturnResult(NID_APP, columnCount > 0, E_INVALID_ARG, "The specified insertMap parameter is empty.");
 
-       ArrayList* pArgList = new ArrayList();
+       ArrayList* pArgList = new (std::nothrow) ArrayList();
        pArgList->Construct();
 
-       pArgList->Add(*(new String(dataId))); // list(0): data ID
+       pArgList->Add(new (std::nothrow) String(dataId)); // list[0]: data ID
        long long argSize = dataId.GetLength() * sizeof(wchar_t);
 
-       pArgList->Add(*(new String(Integer::ToString(columnCount)))); // list(1): inserted column count
+       pArgList->Add(new (std::nothrow) String(Integer::ToString(columnCount))); // list[1]: inserted column count
        SysLog(NID_APP, "[DC_CALLER_SEND] inserted column count: %d", columnCount);
 
-       IMapEnumerator* pMapEnum = const_cast< IMap* >(&insertMap)->GetMapEnumeratorN();
-       while (pMapEnum->MoveNext() == E_SUCCESS) // list(2): column-value pairs
+#ifdef DATACONTROL_PROTOCOL_VER_2_1_0_2
+       String tmpPath(_DATACONTROL_REQUEST_DIR);
+       tmpPath.Append(App::GetInstance()->GetAppId());
+
+       _DataControlManager* pDcMgr = _DataControlManager::GetInstance();
+       SysTryCatch(NID_APP, pDcMgr, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Failed to get _DataControlManager instance.");
+       uniqueId = pDcMgr->GetUniqueId();
+
+       tmpPath.Append(uniqueId);
+       SysLog(NID_APP, "[DC_CALLER_SEND] request: %ls", tmpPath.GetPointer());
+
+       r = request.Construct(tmpPath, L"w+", true);
+       SysTryCatch(NID_APP, !IsFailed(r), r = E_SYSTEM, E_SYSTEM, "[%s] Failed to create request (%ls).",
+                       GetErrorMessage(r), tmpPath.GetPointer());
+
+       pArgList->Add(new (std::nothrow) String(tmpPath)); // list[2]: path 
+#endif
+
+       pMapEnum = const_cast< IMap* >(&insertMap)->GetMapEnumeratorN();
+       while (pMapEnum->MoveNext() == E_SUCCESS) // list: column-value pairs
        {
+#ifdef DATACONTROL_PROTOCOL_VER_2_1_0_2
+               int length = 0;
+               String* pColumn = null;
+               String* pValue = null;
+               unique_ptr< char[] > pData(null);
+
+               pColumn = dynamic_cast< String* >(pMapEnum->GetKey());
+               SysTryCatch(NID_APP, pColumn != null, r = E_INVALID_ARG, E_INVALID_ARG,
+                               "[E_INVALID_ARG] The object is not String class.");
+
+               pData.reset(_StringConverter::CopyToCharArrayN(*pColumn));
+               SysTryCatch(NID_APP, pData != null, r = GetLastResult(), GetLastResult(), "[%s] Invalid request value",
+                               GetErrorMessage(GetLastResult()));
+
+               length = strlen(pData.get());
+               r = request.Write(&length, sizeof(int)); // data length
+               SysTryCatch(NID_APP, !IsFailed(r), , E_SYSTEM, "[%s] Failed to send request.", GetErrorMessage(r));
+
+               r = request.Write(pData.get(), length); // data
+               SysTryCatch(NID_APP, !IsFailed(r), , E_SYSTEM, "[%s] Failed to send request.", GetErrorMessage(r));
+
+               pValue = dynamic_cast< String* >(pMapEnum->GetValue());
+               SysTryCatch(NID_APP, pValue != null, r = E_INVALID_ARG, E_INVALID_ARG,
+                               "[E_INVALID_ARG] The object is not String class.");
+
+               pData.reset(_StringConverter::CopyToCharArrayN(*pValue));
+               SysTryCatch(NID_APP, pData != null, r = GetLastResult(), GetLastResult(), "[%s] Invalid request value",
+                               GetErrorMessage(GetLastResult()));
+
+               length = strlen(pData.get());
+               r = request.Write(&length, sizeof(int)); // data length
+               SysTryCatch(NID_APP, !IsFailed(r), , E_SYSTEM, "[%s] Failed to send request.", GetErrorMessage(r));
+
+               r = request.Write(pData.get(), length); // data
+               SysTryCatch(NID_APP, !IsFailed(r), , E_SYSTEM, "[%s] Failed to send request.", GetErrorMessage(r));
+
+               argSize += pColumn->GetLength() * sizeof(wchar_t);
+               argSize += pValue->GetLength() * sizeof(wchar_t);
+#else
                String* pColumn = dynamic_cast< String* >(pMapEnum->GetKey());
                SysTryCatch(NID_APP, pColumn != null, r = E_INVALID_ARG, E_INVALID_ARG,
                                "[E_INVALID_ARG] The object is not String class.");
@@ -549,16 +620,21 @@ _SqlDataControlImpl::Insert(const String& dataId, const IMap& insertMap, Request
                argSize += pColumn->GetLength() * sizeof(wchar_t);
                argSize += pValue->GetLength() * sizeof(wchar_t);
                i++;
+#endif
        }
-       SysTryCatch(NID_APP, argSize <= _MAX_ARGUMENT_SIZE, r = E_MAX_EXCEEDED, E_MAX_EXCEEDED,
+       SysTryCatch(NID_APP, argSize <= _MAX_REQUEST_ARGUMENT_SIZE, r = E_MAX_EXCEEDED, E_MAX_EXCEEDED,
                        "[E_MAX_EXCEEDED] The size of sending argument (%d) exceeds the maximum limit.", argSize);
 
+#ifdef DATACONTROL_PROTOCOL_VER_2_1_0_2
+       request.Flush();
+#endif
+
        r = StartSqlDataControl(_DATACONTROL_REQUEST_TYPE_SQL_INSERT, pArgList, &id);
        SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagating to caller...", GetErrorMessage(r));
 
        reqId = static_cast< RequestId >(id);
 
-       SysLog(NID_APP, "[DC_CALLER_SEND] dataId: %ls, insertMap: 0x%x, reqId: %d", dataId.GetPointer(), &insertMap, reqId);
+       SysLog(NID_APP, "[DC_CALLER_SEND] data: %ls, insertMap: 0x%x, req: %d", dataId.GetPointer(), &insertMap, reqId);
 
        // fall through
 CATCH:
@@ -578,6 +654,9 @@ _SqlDataControlImpl::Update(const String& dataId, const IMap& updateMap, const S
        int columnCount = 0;
        int id = 0;
        int i = 0;
+       int uniqueId = -1;
+       File request;
+       IMapEnumerator* pMapEnum = null;
        result r = E_SUCCESS;
        SysLog(NID_APP, "[DC_CALLER_SEND] SqlDataControl UPDATE");
 
@@ -587,15 +666,72 @@ _SqlDataControlImpl::Update(const String& dataId, const IMap& updateMap, const S
        ArrayList* pArgList = new ArrayList();
        pArgList->Construct();
 
-       pArgList->Add(*(new String(dataId))); // list(0): data ID
+       pArgList->Add(new (std::nothrow) String(dataId)); // list[0]: data ID
        long long argSize = dataId.GetLength() * sizeof(wchar_t);
 
-       pArgList->Add(*(new String(Integer::ToString(columnCount)))); // list(1): updated column count
+       pArgList->Add(new (std::nothrow) String(Integer::ToString(columnCount))); // list[1]: updated column count
        SysLog(NID_APP, "[DC_CALLER_SEND] updated column count: %d", columnCount);
 
-       IMapEnumerator* pMapEnum = const_cast< IMap* >(&updateMap)->GetMapEnumeratorN();
-       while (pMapEnum->MoveNext() == E_SUCCESS) // list(2): column-value pairs
+#ifdef DATACONTROL_PROTOCOL_VER_2_1_0_2
+       String tmpPath(_DATACONTROL_REQUEST_DIR);
+       tmpPath.Append(App::GetInstance()->GetAppId());
+
+       _DataControlManager* pDcMgr = _DataControlManager::GetInstance();
+       SysTryCatch(NID_APP, pDcMgr, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Failed to get _DataControlManager instance.");
+       uniqueId = pDcMgr->GetUniqueId();
+
+       tmpPath.Append(uniqueId);
+       SysLog(NID_APP, "[DC_CALLER_SEND] request: %ls", tmpPath.GetPointer());
+
+       r = request.Construct(tmpPath, L"w+", true);
+       SysTryCatch(NID_APP, !IsFailed(r), r = E_SYSTEM, E_SYSTEM, "[%s] Failed to create request (%ls).",
+                       GetErrorMessage(r), tmpPath.GetPointer());
+
+       pArgList->Add(new (std::nothrow) String(tmpPath)); // list[2]: path 
+#endif
+
+       pMapEnum = const_cast< IMap* >(&updateMap)->GetMapEnumeratorN();
+       while (pMapEnum->MoveNext() == E_SUCCESS) // list: column-value pairs
        {
+#ifdef DATACONTROL_PROTOCOL_VER_2_1_0_2
+               int length = 0;
+               String* pColumn = null;
+               String* pValue = null;
+               unique_ptr< char[] > pData(null);
+
+               pColumn = dynamic_cast< String* >(pMapEnum->GetKey());
+               SysTryCatch(NID_APP, pColumn != null, r = E_INVALID_ARG, E_INVALID_ARG,
+                               "[E_INVALID_ARG] The object is not String class.");
+
+               pData.reset(_StringConverter::CopyToCharArrayN(*pColumn));
+               SysTryCatch(NID_APP, pData != null, r = GetLastResult(), GetLastResult(), "[%s] Invalid request value",
+                               GetErrorMessage(GetLastResult()));
+
+               length = strlen(pData.get());
+               r = request.Write(&length, sizeof(int)); // data length
+               SysTryCatch(NID_APP, !IsFailed(r), , E_SYSTEM, "[%s] Failed to send request.", GetErrorMessage(r));
+
+               r = request.Write(pData.get(), length); // data
+               SysTryCatch(NID_APP, !IsFailed(r), , E_SYSTEM, "[%s] Failed to send request.", GetErrorMessage(r));
+
+               pValue = dynamic_cast< String* >(pMapEnum->GetValue());
+               SysTryCatch(NID_APP, pValue != null, r = E_INVALID_ARG, E_INVALID_ARG,
+                               "[E_INVALID_ARG] The object is not String class.");
+
+               pData.reset(_StringConverter::CopyToCharArrayN(*pValue));
+               SysTryCatch(NID_APP, pData != null, r = GetLastResult(), GetLastResult(), "[%s] Invalid request value",
+                               GetErrorMessage(GetLastResult()));
+
+               length = strlen(pData.get());
+               r = request.Write(&length, sizeof(int)); // data length
+               SysTryCatch(NID_APP, !IsFailed(r), , E_SYSTEM, "[%s] Failed to send request.", GetErrorMessage(r));
+
+               r = request.Write(pData.get(), length); // data
+               SysTryCatch(NID_APP, !IsFailed(r), , E_SYSTEM, "[%s] Failed to send request.", GetErrorMessage(r));
+
+               argSize += pColumn->GetLength() * sizeof(wchar_t);
+               argSize += pValue->GetLength() * sizeof(wchar_t);
+#else
                String* pColumn = dynamic_cast< String* >(pMapEnum->GetKey());
                SysTryCatch(NID_APP, pColumn != null, r = E_INVALID_ARG, E_INVALID_ARG,
                                "[E_INVALID_ARG] The object is not String class.");
@@ -613,19 +749,24 @@ _SqlDataControlImpl::Update(const String& dataId, const IMap& updateMap, const S
                argSize += pColumn->GetLength() * sizeof(wchar_t);
                argSize += pValue->GetLength() * sizeof(wchar_t);
                i++;
+#endif
        }
 
-       if (pWhere != null)     // list(3): where clause
+#ifdef DATACONTROL_PROTOCOL_VER_2_1_0_2
+       request.Flush();
+#endif
+
+       if (pWhere != null)     // list: where clause
        {
-               pArgList->Add(*(new String(*pWhere)));
+               pArgList->Add(new (std::nothrow) String(*pWhere));
                argSize += pWhere->GetLength() * sizeof(wchar_t);
                SysLog(NID_APP, "[DC_CALLER_SEND] pWhere: %ls", pWhere->GetPointer());
        }
        else
        {
-               pArgList->Add(*(new String(L"NULL")));
+               pArgList->Add(new (std::nothrow) String(L"NULL"));
        }
-       SysTryCatch(NID_APP, argSize <= _MAX_ARGUMENT_SIZE, r = E_MAX_EXCEEDED, E_MAX_EXCEEDED,
+       SysTryCatch(NID_APP, argSize <= _MAX_REQUEST_ARGUMENT_SIZE, r = E_MAX_EXCEEDED, E_MAX_EXCEEDED,
                        "[E_MAX_EXCEEDED] The size of sending argument (%d) exceeds the maximum limit.", argSize);
 
        r = StartSqlDataControl(_DATACONTROL_REQUEST_TYPE_SQL_UPDATE, pArgList, &id);
@@ -633,7 +774,7 @@ _SqlDataControlImpl::Update(const String& dataId, const IMap& updateMap, const S
 
        reqId = static_cast< RequestId >(id);
 
-       SysLog(NID_APP, "[DC_CALLER_SEND] dataId: %ls, updateMap: 0x%x, pWhere: 0x%x, reqId: %d",
+       SysLog(NID_APP, "[DC_CALLER_SEND] data: %ls, updateMap: 0x%x, pWhere: 0x%x, req: %d",
                                dataId.GetPointer(), &updateMap, pWhere, reqId);
 
        // fall through
@@ -679,7 +820,7 @@ _SqlDataControlImpl::Delete(const String& dataId, const String* pWhere, RequestI
 
        reqId = static_cast< RequestId >(id);
 
-       SysLog(NID_APP, "[DC_CALLER_SEND] dataId: %ls, pWhere: 0x%x, reqId: %d", dataId.GetPointer(), pWhere, reqId);
+       SysLog(NID_APP, "[DC_CALLER_SEND] data: %ls, pWhere: 0x%x, req: %d", dataId.GetPointer(), pWhere, reqId);
 
        // fall through
 CATCH: