[Osp-Content] Update for GetMimeType and GetDownloadRequestN apis
[platform/framework/native/content.git] / src / FCnt_DownloadManagerImpl.cpp
index 5259269..8bef6df 100644 (file)
@@ -270,26 +270,12 @@ _DownloadManagerImpl::~_DownloadManagerImpl(void)
        }
 }
 
-result
-_DownloadManagerImpl::Construct(void)
-{
-       result r = E_SUCCESS;
-
-       r = __handleMap.Construct(100, 0);
-       SysTryReturnResult(NID_IO, r == E_SUCCESS, r, "Failed to initialize a download manager.");
-
-       return E_SUCCESS;
-}
-
 void
 _DownloadManagerImpl::InitSingleton(void)
 {
        unique_ptr<_DownloadManagerImpl> pImpl(new (std::nothrow) _DownloadManagerImpl);
        SysTryReturnVoidResult(NID_CNT, pImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
 
-       result r = pImpl->Construct();
-       SysTryReturnVoidResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] Failed to initialize download manager.");
-
        __pInstance = pImpl.release();
 
        std::atexit(DestroySingleton);
@@ -427,9 +413,6 @@ _DownloadManagerImpl::Start(const DownloadRequest& request, RequestId& reqId)
        // Set a request Id
        reqId = (long)download_id;
 
-       // Add a request Id to the handle map
-       __handleMap.Add(reqId, new DownloadRequest(request));
-
        return E_SUCCESS;
 
 CATCH:
@@ -494,38 +477,60 @@ _DownloadManagerImpl::GetDownloadRequestN(RequestId reqId)
 {
        result r = E_SUCCESS;
        DownloadRequest* pRequest = null;
+       int ret = 0;
+       char* pUrl = null;
+       char* pPath = null;
+       bool notification = false;
+       int length = 0;
+       char** pFields = null;
+       char* pValue = null;
+       char* pFileName = null;
+       download_network_type_e netType = (download_network_type_e)DOWNLOAD_NETWORK_DATA_NETWORK;
+
+       ret = download_get_url(reqId, &pUrl);
+       SysTryCatch(NID_CNT, (ret != DOWNLOAD_ERROR_ID_NOT_FOUND) && (ret != DOWNLOAD_ERROR_INVALID_PARAMETER), r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The argument is not valid");
+       ret = download_get_network_type(reqId, &netType);
+       SysTryCatch(NID_CNT, (ret != DOWNLOAD_ERROR_ID_NOT_FOUND) && (ret != DOWNLOAD_ERROR_INVALID_PARAMETER), r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The argument is not valid");
+       ret = download_get_destination(reqId, &pPath);
+       SysTryCatch(NID_CNT, (ret != DOWNLOAD_ERROR_ID_NOT_FOUND) && (ret != DOWNLOAD_ERROR_INVALID_PARAMETER), r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The argument is not valid");
+       ret = download_get_file_name(reqId, &pFileName);
+       SysTryCatch(NID_CNT, (ret != DOWNLOAD_ERROR_ID_NOT_FOUND) && (ret != DOWNLOAD_ERROR_INVALID_PARAMETER), r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The argument is not valid");
+       ret = download_get_notification(reqId, &notification);
+       SysTryCatch(NID_CNT, (ret != DOWNLOAD_ERROR_ID_NOT_FOUND) && (ret != DOWNLOAD_ERROR_INVALID_PARAMETER), r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The argument is not valid");
+       ret = download_get_http_header_field_list(reqId, &pFields, &length);
+       SysTryCatch(NID_CNT, (ret != DOWNLOAD_ERROR_ID_NOT_FOUND) && (ret != DOWNLOAD_ERROR_INVALID_PARAMETER), r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The argument is not valid");
+       pRequest = new (std::nothrow) DownloadRequest(pUrl, pPath);
+       SysTryCatch(NID_CNT, pRequest != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+       pRequest->SetFileName(pFileName);
+       pRequest->SetNotification(notification);
+       pRequest->SetNetworkType((DownloadNetworkType)netType);
+       //Get all the field values
+       for (int i = 0; i < length; i++)
+       {
+               ret = download_get_http_header_field(reqId, pFields[i], &pValue);
+               SysTryCatch(NID_CNT, (ret != DOWNLOAD_ERROR_ID_NOT_FOUND) && (ret != DOWNLOAD_ERROR_INVALID_PARAMETER), r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The argument is not valid");
+               pRequest->AddRequestHeader(pFields[i], pValue);
+               free(pValue);
+               free(pFields[i]);
+               pValue = null;
+       }
 
-       r = __handleMap.GetValue(reqId, pRequest);
-       SysTryReturn(NID_CNT, r == E_SUCCESS, null, E_INVALID_ARG, "[E_INVALID_ARG] There is no download request for the request ID.");
-
-       pRequest = new (std::nothrow) DownloadRequest(*pRequest);
-       SysTryReturn(NID_CNT, pRequest != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY]");
-
-       SetLastResult(E_SUCCESS);
+CATCH:
+       free(pUrl);
+       free(pPath);
+       free(pFileName);
+       SetLastResult(r);
        return pRequest;
 }
 
 result
 _DownloadManagerImpl::GetMimeType(RequestId reqId, String& mimeType)
 {
-       result r = E_SUCCESS;
        int ret = 0;
-
        char* pStr = null;
-       DownloadRequest* pRequest = null;
-
-       // Check the request is valid
-       pRequest = GetDownloadRequestN(reqId);
-       if(pRequest == null)
-       {
-               r = GetLastResult();
-               SysPropagate(NID_CNT, r);
-               return r;
-       }
-
-       delete pRequest;
 
        ret = download_get_mime_type((int)reqId, &pStr);
+       SysTryReturnResult(NID_CNT, (ret != DOWNLOAD_ERROR_ID_NOT_FOUND) && (ret != DOWNLOAD_ERROR_INVALID_PARAMETER), E_INVALID_ARG, "There is no download request for the request ID.");
        SysTryReturnResult(NID_CNT, ret != DOWNLOAD_ERROR_INVALID_STATE, E_INVALID_OPERATION, "The current download state is not downloading or paused.");
        SysTryReturnResult(NID_CNT, ret >= 0, E_SYSTEM, "The internal system service is not available. %d", ret);
 
@@ -631,7 +636,6 @@ _DownloadManagerImpl::DestroyResources(RequestId reqId)
 {
        int ret = 0;
        result r = E_SUCCESS;
-       DownloadRequest* pRequest = null;
 
        // Cancel the callback
        UnregisterCallback(reqId);
@@ -639,15 +643,6 @@ _DownloadManagerImpl::DestroyResources(RequestId reqId)
        // Remove the resource from url_download
        ret = download_destroy((int)reqId);
        SysTryLog(NID_CNT, ret >= 0, "url_download_destory fails %d", ret);
-
-       // Remove DownloadRequest from __handleMap
-       r = __handleMap.GetValue(reqId, pRequest);
-       SysTryLog(NID_CNT, r == E_SUCCESS, "[%s]", GetErrorMessage(r));
-
-       r = __handleMap.Remove(reqId);
-       SysTryLog(NID_CNT, r == E_SUCCESS, "[%s]", GetErrorMessage(r));
-
-       delete pRequest;
 }
 
 result