Updated source code for download-provider from tizen 2.2.1 git branch 64/16564/3
authoramit.dhiman <amit.dhiman@samsung.com>
Wed, 19 Feb 2014 07:45:58 +0000 (13:15 +0530)
committeramit.dhiman <amit.dhiman@samsung.com>
Thu, 20 Feb 2014 15:25:36 +0000 (20:55 +0530)
[customer] OPEN
[issue#] N/A
[problem] Updated the source code by using base of tizen 2.2.1 git branch
[cause] N/A
[solution] N/A

Change-Id: Ic9b95e7994c947f4b73420569a4b8a946ab81638
Signed-off-by: amit.dhiman <amit.dhiman@samsung.com>
117 files changed:
CMakeLists.txt
agent/download-agent-basic.c
agent/download-agent-client-mgr.c
agent/download-agent-dl-info-util.c
agent/download-agent-dl-mgr.c
agent/download-agent-encoding.c
agent/download-agent-file.c
agent/download-agent-http-mgr.c
agent/download-agent-http-misc.c
agent/download-agent-http-msg-handler.c
agent/download-agent-http-queue.c
agent/download-agent-interface.c
agent/download-agent-mime-util.c
agent/download-agent-plugin-conf.c
agent/download-agent-plugin-libsoup.c
agent/download-agent-utils-dl-id-history.c
agent/download-agent-utils.c
agent/include/download-agent-debug.h
agent/include/download-agent-defs.h
agent/include/download-agent-dl-info-util.h
agent/include/download-agent-file.h
agent/include/download-agent-http-queue.h
agent/include/download-agent-interface.h
agent/include/download-agent-mime-util.h
agent/include/download-agent-plugin-conf.h
agent/include/download-agent-utils.h
download-provider-schema.sql [new file with mode: 0644]
download-provider-service [deleted file]
download-provider.manifest [new file with mode: 0644]
download-provider.rule [new file with mode: 0644]
org.download-provider.service.in [deleted file]
packaging/download-provider.changes [deleted file]
packaging/download-provider.manifest [deleted file]
packaging/download-provider.spec
packaging/org.download-provider.conf [deleted file]
po/CMakeLists.txt [new file with mode: 0755]
po/POTFILES.in.in [new file with mode: 0755]
po/ar.po [new file with mode: 0755]
po/az.po [new file with mode: 0755]
po/bg.po [new file with mode: 0755]
po/ca.po [new file with mode: 0755]
po/cs.po [new file with mode: 0755]
po/da.po [new file with mode: 0755]
po/de_DE.po [new file with mode: 0755]
po/el_GR.po [new file with mode: 0755]
po/en.po [new file with mode: 0755]
po/en_PH.po [new file with mode: 0755]
po/en_US.po [new file with mode: 0755]
po/es_ES.po [new file with mode: 0755]
po/es_MX.po [new file with mode: 0755]
po/et.po [new file with mode: 0755]
po/eu.po [new file with mode: 0755]
po/fi.po [new file with mode: 0755]
po/fr_CA.po [new file with mode: 0755]
po/fr_FR.po [new file with mode: 0755]
po/ga.po [new file with mode: 0755]
po/gl.po [new file with mode: 0755]
po/hi.po [new file with mode: 0755]
po/hr.po [new file with mode: 0755]
po/hu.po [new file with mode: 0755]
po/hy.po [new file with mode: 0755]
po/is.po [new file with mode: 0755]
po/it_IT.po [new file with mode: 0755]
po/ja_JP.po [new file with mode: 0755]
po/ka.po [new file with mode: 0755]
po/kk.po [new file with mode: 0755]
po/ko_KR.po [new file with mode: 0755]
po/lt.po [new file with mode: 0755]
po/lv.po [new file with mode: 0755]
po/mk.po [new file with mode: 0755]
po/nb.po [new file with mode: 0755]
po/nl_NL.po [new file with mode: 0755]
po/pl.po [new file with mode: 0755]
po/pt_BR.po [new file with mode: 0755]
po/pt_PT.po [new file with mode: 0755]
po/ro.po [new file with mode: 0755]
po/ru_RU.po [new file with mode: 0755]
po/sk.po [new file with mode: 0755]
po/sl.po [new file with mode: 0755]
po/sr.po [new file with mode: 0755]
po/sv.po [new file with mode: 0755]
po/tr_TR.po [new file with mode: 0755]
po/uk.po [new file with mode: 0755]
po/uz.po [new file with mode: 0755]
po/zh_CN.po [new file with mode: 0755]
po/zh_HK.po [new file with mode: 0755]
po/zh_SG.po [new file with mode: 0755]
po/zh_TW.po [new file with mode: 0755]
provider-interface/CMakeLists.txt
provider-interface/download-provider-interface.c
provider-interface/include/download-provider-interface.h
provider/CMakeLists.txt
provider/download-provider-da-interface.c
provider/download-provider-db.c
provider/download-provider-main.c
provider/download-provider-network.c
provider/download-provider-notification.c
provider/download-provider-request.c
provider/download-provider-slots.c
provider/download-provider-socket.c
provider/download-provider-thread-queue.c
provider/download-provider-thread-request.c
provider/include/download-provider-config.h
provider/include/download-provider-db.h
provider/include/download-provider-defs.h
provider/include/download-provider-log.h
provider/include/download-provider-network.h
provider/include/download-provider-request.h
provider/include/download-provider-slots.h
provider/include/download-provider-socket.h
provider/include/download-provider.h
res/images/Notification_download_animation.gif [new file with mode: 0644]
res/images/Q02_Notification_Download_failed.png [deleted file]
res/images/Q02_Notification_download_complete.png [new file with mode: 0644]
res/images/Q02_Notification_download_failed.png [new file with mode: 0644]
systemd/download-provider.service [moved from packaging/download-provider.service with 69% similarity]
systemd/download-provider.socket [new file with mode: 0644]

index efa8c18..2511e8e 100755 (executable)
@@ -7,13 +7,6 @@ MESSAGE("PROJECT : ${PKG_NAME}")
 SET(VERSION ${PKG_VERSION}-${PKG_RELEASE})
 MESSAGE("VERSION : ${VERSION}")
 
-IF(DEFINED SUPPORT_DBUS_SYSTEM)
-       MESSAGE("SUPPORT DBUS SYSTEM : ${SUPPORT_DBUS_SYSTEM}")
-       IF(SUPPORT_DBUS_SYSTEM)
-               ADD_DEFINITIONS(-DDP_SUPPORT_DBUS_ACTIVATION)
-       ENDIF(SUPPORT_DBUS_SYSTEM)
-ENDIF(DEFINED SUPPORT_DBUS_SYSTEM)
-
 IF(DEFINED SUPPORT_WIFI_DIRECT)
        MESSAGE("SUPPORT_WIFI_DIRECT: ${SUPPORT_WIFI_DIRECT}")
        IF(SUPPORT_WIFI_DIRECT)
@@ -40,6 +33,8 @@ ENDIF(DEFINED SUPPORT_CHECK_IPC)
 ADD_SUBDIRECTORY(agent)
 ADD_SUBDIRECTORY(provider-interface)
 ADD_SUBDIRECTORY(provider)
+# i18n
+ADD_SUBDIRECTORY(po)
 
 # INSTALL
 
@@ -49,20 +44,24 @@ SET(PACKAGE_DESCRIPTION "Defines for ${PROJECT_NAME}")
 CONFIGURE_FILE(download-provider.pc.in download-provider.pc @ONLY)
 INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/download-provider.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
 
-INSTALL(PROGRAMS download-provider-service DESTINATION /etc/rc.d/init.d)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/systemd/download-provider.service DESTINATION /usr/lib/systemd/system)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/systemd/download-provider.socket DESTINATION /usr/lib/systemd/system)
+
+INSTALL(FILES ${CMAKE_SOURCE_DIR}/download-provider-schema.sql DESTINATION ${DATABASE_SCHEMA_DIR})
 
 # install images
 INSTALL(DIRECTORY ${CMAKE_SOURCE_DIR}/res/images/ DESTINATION ${IMAGE_DIR}
                FILES_MATCHING
                PATTERN "*.png"
+               PATTERN "*.gif"
                )
 
-IF(DEFINED DBUS_SERVICE_DIR)
-       CONFIGURE_FILE(org.download-provider.service.in org.download-provider.service @ONLY)
-       INSTALL(FILES org.download-provider.service DESTINATION ${DBUS_SERVICE_DIR})
-ENDIF(DEFINED DBUS_SERVICE_DIR)
-
 IF(DEFINED LICENSE_DIR)
        CONFIGURE_FILE(LICENSE.APLv2 share/license/${PROJECT_NAME})
        INSTALL(FILES share/license/${PROJECT_NAME} DESTINATION ${LICENSE_DIR})
 ENDIF(DEFINED LICENSE_DIR)
+
+IF(DEFINED SMACK_RULE_DIR)
+       INSTALL(FILES ${PROJECT_NAME}.rule DESTINATION ${SMACK_RULE_DIR})
+ENDIF(DEFINED SMACK_RULE_DIR)
+
index 8a7681c..73fc892 100755 (executable)
@@ -36,7 +36,7 @@ static da_result_t __download_content(stage_info *stage);
 
 da_result_t start_download(const char *url , int *dl_id)
 {
-       DA_LOG_FUNC_START(Default);
+       DA_LOG_FUNC_LOGD(Default);
        return start_download_with_extension(url, dl_id, NULL);
 }
 
@@ -52,6 +52,7 @@ da_result_t start_download_with_extension(
        const char *file_name = DA_NULL;
        const char *etag = DA_NULL;
        const char *temp_file_path = DA_NULL;
+       const char *pkg_name = DA_NULL;
        int request_header_count = 0;
        void *user_data = DA_NULL;
        client_input_t *client_input = DA_NULL;
@@ -59,7 +60,7 @@ da_result_t start_download_with_extension(
        download_thread_input *thread_info = DA_NULL;
        pthread_attr_t thread_attr;
 
-       DA_LOG_FUNC_START(Default);
+       DA_LOG_FUNC_LOGV(Default);
 
        if (extension_data) {
                request_header = extension_data->request_header;
@@ -70,6 +71,7 @@ da_result_t start_download_with_extension(
                user_data = extension_data->user_data;
                etag = extension_data->etag;
                temp_file_path = extension_data->temp_file_path;
+               pkg_name = extension_data->pkg_name;
        }
 
        ret = get_available_slot_id(&slot_id);
@@ -114,6 +116,11 @@ da_result_t start_download_with_extension(
                                strncpy(client_input->temp_file_path, temp_file_path, strlen(temp_file_path));
                }
 
+               if (pkg_name) {
+                       client_input->pkg_name = (char *)calloc(strlen(pkg_name)+1, sizeof(char));
+                       if (client_input->pkg_name)
+                               strncpy(client_input->pkg_name, pkg_name, strlen(pkg_name));
+               }
                client_input_basic = &(client_input->client_input_basic);
                client_input_basic->req_url = (char *)calloc(strlen(url)+1, sizeof(char));
                if(DA_NULL == client_input_basic->req_url) {
@@ -172,7 +179,7 @@ da_result_t start_download_with_extension(
                        goto ERR;
                }
        }
-       DA_LOG_CRITICAL(Thread, "download thread create slot_id[%d] thread id[%lu]",
+       DA_LOG_DEBUG(Thread, "download thread create slot_id[%d] thread id[%lu]",
                        slot_id,GET_DL_THREAD_ID(slot_id));
 
 ERR:
@@ -200,7 +207,7 @@ da_result_t __make_source_info_basic_download(
        source_info_t *source_info = DA_NULL;
        source_info_basic_t *source_info_basic = DA_NULL;
 
-       DA_LOG_FUNC_START(Default);
+       DA_LOG_FUNC_LOGV(Default);
 
        if (!stage) {
                DA_LOG_ERR(Default, "no stage; DA_ERR_INVALID_ARGUMENT");
@@ -239,8 +246,8 @@ da_result_t __make_source_info_basic_download(
 
        source_info->source_info_type.source_info_basic = source_info_basic;
 
-       DA_LOG(Default, "BASIC HTTP STARTED: URL=%s",
-                       source_info->source_info_type.source_info_basic->url);
+//     DA_SECURE_LOGI("BASIC HTTP STARTED: URL=%s",
+//                     source_info->source_info_type.source_info_basic->url);
 ERR:
        return ret;
 }
@@ -260,7 +267,7 @@ static void *__thread_start_download(void *data)
 
        int slot_id = DA_INVALID_ID;
 
-       DA_LOG_FUNC_START(Thread);
+       DA_LOG_FUNC_LOGV(Thread);
 
        pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, DA_NULL);
 
@@ -299,7 +306,7 @@ static void *__thread_start_download(void *data)
                DA_LOG_ERR(Default, "STAGE ADDITION FAIL!");
                goto ERR;
        }
-       DA_LOG(Default, "new added Stage : %p", stage);
+       DA_LOG_VERBOSE(Default, "new added Stage : %p", stage);
 
        GET_DL_USER_DATA(slot_id) = client_input->user_data;
        client_input->user_data = DA_NULL;
@@ -311,17 +318,23 @@ static void *__thread_start_download(void *data)
        client_input->etag = DA_NULL;
        GET_DL_USER_TEMP_FILE_PATH(slot_id) = client_input->temp_file_path;
        client_input->temp_file_path = DA_NULL;
+
        ret = __make_source_info_basic_download(stage, client_input);
-       /* to save memory */
-       if (client_input) {
-               clean_up_client_input_info(client_input);
-               free(client_input);
-               client_input = DA_NULL;
-       }
 
-       if (ret == DA_RESULT_OK)
-               ret = __download_content(stage);
+       if (ret == DA_RESULT_OK) {
+               /* to save memory */
+               if (client_input) {
+                       clean_up_client_input_info(client_input);
+                       free(client_input);
+                       client_input = DA_NULL;
+               }
 
+               ret = __download_content(stage);
+               if (stage != GET_DL_CURRENT_STAGE(slot_id)) {
+                       DA_LOG_ERR(Default,"Playready download case. The next stage is present stage");
+                       stage = GET_DL_CURRENT_STAGE(slot_id);
+               }
+       }
 ERR:
        if (client_input) {
                clean_up_client_input_info(client_input);
@@ -334,7 +347,7 @@ ERR:
                char *etag = DA_NULL;
                req_dl_info *request_info = NULL;
                file_info *file_storage = NULL;
-               DA_LOG_CRITICAL(Default, "Whole download flow is finished.");
+               DA_LOG_VERBOSE(Default, "Whole download flow is finished.");
                _da_thread_mutex_lock (&mutex_download_state[GET_STAGE_DL_ID(stage)]);
                download_state = GET_DL_STATE_ON_STAGE(stage);
                _da_thread_mutex_unlock (&mutex_download_state[GET_STAGE_DL_ID(stage)]);
@@ -367,7 +380,7 @@ ERR:
        }
 
        pthread_cleanup_pop(0);
-       DA_LOG_CRITICAL(Thread, "=====thread_start_download - EXIT=====");
+       DA_LOG_CRITICAL(Thread, "==thread_start_download - EXIT==");
        pthread_exit((void *)NULL);
        return DA_NULL;
 }
@@ -379,7 +392,7 @@ da_result_t __download_content(stage_info *stage)
        da_bool_t isDownloadComplete = DA_FALSE;
        int slot_id = DA_INVALID_ID;
 
-       DA_LOG_FUNC_START(Default);
+       DA_LOG_FUNC_LOGV(Default);
 
        slot_id = GET_STAGE_DL_ID(stage);
        CHANGE_DOWNLOAD_STATE(DOWNLOAD_STATE_NEW_DOWNLOAD, stage);
@@ -388,7 +401,7 @@ da_result_t __download_content(stage_info *stage)
                stage = GET_DL_CURRENT_STAGE(slot_id);
                _da_thread_mutex_lock (&mutex_download_state[GET_STAGE_DL_ID(stage)]);
                download_state = GET_DL_STATE_ON_STAGE(stage);
-               DA_LOG(Default, "download_state to - [%d] ", download_state);
+               DA_LOG_VERBOSE(Default, "download_state to - [%d] ", download_state);
                _da_thread_mutex_unlock (&mutex_download_state[GET_STAGE_DL_ID(stage)]);
 
                switch(download_state) {
index a19e3ba..b27a2d4 100755 (executable)
@@ -36,7 +36,7 @@ void destroy_client_noti(client_noti_t *client_noti);
 
 da_result_t init_client_app_mgr()
 {
-       DA_LOG_FUNC_START(ClientNoti);
+       DA_LOG_FUNC_LOGV(ClientNoti);
 
        if(client_app_mgr.is_init)
                return DA_RESULT_OK;
@@ -61,7 +61,7 @@ da_result_t reg_client_app(
        client_queue_t *queue = DA_NULL;
        client_noti_t *client_noti = DA_NULL;
 
-       DA_LOG_FUNC_START(ClientNoti);
+       DA_LOG_FUNC_LOGD(ClientNoti);
 
        memset(&(client_app_mgr.client_app_info.client_callback),
                        0, sizeof(da_client_cb_t));
@@ -90,7 +90,7 @@ da_result_t dereg_client_app(void)
 {
        client_noti_t *client_noti = DA_NULL;
 
-       DA_LOG_FUNC_START(ClientNoti);
+       DA_LOG_FUNC_LOGV(ClientNoti);
 
        client_noti = (client_noti_t *)calloc(1, sizeof(client_noti_t));
        if (!client_noti) {
@@ -104,8 +104,10 @@ da_result_t dereg_client_app(void)
 
        _da_thread_mutex_lock(&(client_app_mgr.mutex_client_mgr));
        if (client_app_mgr.is_thread_init != DA_TRUE) {
-               DA_LOG_CRITICAL(ClientNoti, "try to cancel client mgr thread id[%lu]", client_app_mgr.thread_id);
-               if (client_app_mgr.thread_id && pthread_cancel(client_app_mgr.thread_id) < 0) {
+               DA_LOG_CRITICAL(ClientNoti, "try to cancel client mgr thread id[%lu]",
+                               client_app_mgr.thread_id);
+               if (client_app_mgr.thread_id &&
+                               pthread_cancel(client_app_mgr.thread_id) < 0) {
                        DA_LOG_ERR(ClientNoti, "cancel thread is failed!!!");
                }
                free(client_noti);
@@ -113,11 +115,13 @@ da_result_t dereg_client_app(void)
                void *t_return = NULL;
                DA_LOG_VERBOSE(ClientNoti, "pushing Q_CLIENT_NOTI_TYPE_TERMINATE");
                push_client_noti(client_noti);
-               DA_LOG_CRITICAL(Thread, "===try to join client mgr thread id[%lu]===", client_app_mgr.thread_id);
-               if (client_app_mgr.thread_id && pthread_join(client_app_mgr.thread_id, &t_return) < 0) {
+               DA_LOG_DEBUG(Thread, "===try to join client mgr thread id[%lu]===",
+                               client_app_mgr.thread_id);
+               if (client_app_mgr.thread_id &&
+                               pthread_join(client_app_mgr.thread_id, &t_return) < 0) {
                        DA_LOG_ERR(Thread, "join client thread is failed!!!");
                }
-               DA_LOG_CRITICAL(Thread, "===thread join return[%d]===", (char*)t_return);
+               DA_LOG_DEBUG(Thread, "===thread join return[%d]===", (char*)t_return);
        }
        _da_thread_mutex_unlock(&(client_app_mgr.mutex_client_mgr));
 
@@ -139,7 +143,7 @@ da_result_t send_client_paused_info(int slot_id)
        user_paused_info_t *paused_info = DA_NULL;
        download_state_t state = GET_DL_STATE_ON_ID(slot_id);
 
-       DA_LOG_FUNC_START(ClientNoti);
+       DA_LOG_FUNC_LOGD(ClientNoti);
 
        if (!GET_DL_ENABLE_PAUSE_UPDATE(slot_id)) {
                DA_LOG(ClientNoti, "Do not call pause cb");
@@ -186,7 +190,7 @@ da_result_t  send_client_update_progress_info (
        client_noti_t *client_noti = DA_NULL;
        user_progress_info_t *progress_info = DA_NULL;
 
-       //DA_LOG_FUNC_START(ClientNoti);
+       DA_LOG_FUNC_LOGV(ClientNoti);
 
        if (!is_valid_slot_id(slot_id)) {
                DA_LOG_ERR(ClientNoti, "Download ID is not valid");
@@ -230,7 +234,7 @@ da_result_t  send_client_update_dl_info (
        user_download_info_t *update_dl_info = DA_NULL;
        int len = 0;
 
-       DA_LOG_FUNC_START(ClientNoti);
+       DA_LOG_FUNC_LOGV(ClientNoti);
 
        if (!is_valid_slot_id(slot_id)) {
                DA_LOG_ERR(ClientNoti, "Download ID is not valid");
@@ -271,8 +275,7 @@ da_result_t  send_client_update_dl_info (
 
        if (etag)
                update_dl_info->etag = strdup(etag);
-       DA_LOG(ClientNoti, "pushing file_size=%lu, slot_id=%d, dl_id=%d",
-                       file_size, slot_id, dl_id);
+       DA_LOG_DEBUG(ClientNoti, "pushing slot_id=%d, dl_id=%d", slot_id, dl_id);
 
        push_client_noti(client_noti);
 
@@ -291,7 +294,7 @@ da_result_t  send_client_finished_info (
        client_noti_t *client_noti = DA_NULL;
        user_finished_info_t *finished_info = DA_NULL;
 
-       DA_LOG_FUNC_START(ClientNoti);
+       DA_LOG_FUNC_LOGV(ClientNoti);
 
        if (!is_valid_slot_id(slot_id)) {
                DA_LOG_ERR(ClientNoti, "Download ID is not valid");
@@ -316,14 +319,14 @@ da_result_t  send_client_finished_info (
 
        if (saved_path) {
                finished_info->saved_path = strdup(saved_path);
-               DA_LOG(ClientNoti, "saved path=%s", saved_path);
+               DA_SECURE_LOGD("saved path=%s", saved_path);
        }
        if (etag) {
                finished_info->etag = strdup(etag);
-               DA_LOG(ClientNoti, "pushing finished info. etag[%s]", etag);
+               DA_SECURE_LOGD("pushing finished info. etag[%s]", etag);
        }
-       DA_LOG(ClientNoti, "user_data=%p", client_noti->user_data);
-       DA_LOG(ClientNoti, "http_status=%d", http_status);
+       DA_LOG_VERBOSE(ClientNoti, "user_data=%p", client_noti->user_data);
+       DA_LOG_VERBOSE(ClientNoti, "http_status=%d", http_status);
        DA_LOG(ClientNoti, "pushing slot_id=%d, dl_id=%d err=%d", slot_id, dl_id, error);
 
        push_client_noti(client_noti);
@@ -335,13 +338,14 @@ da_result_t  __launch_client_thread(void)
 {
        pthread_t thread_id = 0;
 
-       DA_LOG_FUNC_START(Thread);
+       DA_LOG_FUNC_LOGV(Thread);
 
-       if (pthread_create(&thread_id,DA_NULL,__thread_for_client_noti,DA_NULL) < 0) {
+       if (pthread_create(&thread_id, DA_NULL,
+                       __thread_for_client_noti,DA_NULL) < 0) {
                DA_LOG_ERR(Thread, "making thread failed..");
                return DA_ERR_FAIL_TO_CREATE_THREAD;
        }
-       DA_LOG(Thread, "client mgr thread id[%d]", thread_id);
+       DA_LOG_VERBOSE(Thread, "client mgr thread id[%d]", thread_id);
        client_app_mgr.thread_id = thread_id;
        return DA_RESULT_OK;
 }
@@ -390,8 +394,6 @@ void push_client_noti(client_noti_t *client_noti)
        client_noti_t *pre = DA_NULL;
        client_noti_t *cur = DA_NULL;
 
-       /* DA_LOG_FUNC_START(ClientNoti); */
-
        queue = &(client_app_mgr.client_queue);
        _da_thread_mutex_lock (&(queue->mutex_client_queue));
 
@@ -444,8 +446,6 @@ void __pop_client_noti(client_noti_t **out_client_noti)
 {
        client_queue_t *queue = DA_NULL;
 
-       /* DA_LOG_FUNC_START(ClientNoti); */
-
        queue = &(client_app_mgr.client_queue);
 
        _da_thread_mutex_lock (&(queue->mutex_client_queue));
@@ -474,9 +474,6 @@ void __pop_client_noti(client_noti_t **out_client_noti)
 void __client_q_goto_sleep_without_lock(void)
 {
        client_queue_t *queue = DA_NULL;
-
-       /* DA_LOG_FUNC_START(ClientNoti); */
-
        queue = &(client_app_mgr.client_queue);
        _da_thread_cond_wait(&(queue->cond_client_queue), &(queue->mutex_client_queue));
 }
@@ -484,9 +481,6 @@ void __client_q_goto_sleep_without_lock(void)
 void __client_q_wake_up_without_lock(void)
 {
        client_queue_t *queue = DA_NULL;
-
-       /* DA_LOG_FUNC_START(ClientNoti); */
-
        queue = &(client_app_mgr.client_queue);
        _da_thread_cond_signal(&(queue->cond_client_queue));
 }
@@ -503,7 +497,7 @@ static void *__thread_for_client_noti(void *data)
        client_queue_t *queue = DA_NULL;
        client_noti_t *client_noti = DA_NULL;
 
-       //DA_LOG_FUNC_START(Thread);
+       DA_LOG_FUNC_LOGV(Thread);
 
        _da_thread_mutex_lock(&(client_app_mgr.mutex_client_mgr));
        client_app_mgr.is_thread_init = DA_TRUE;
@@ -541,11 +535,11 @@ static void *__thread_for_client_noti(void *data)
                                        if (client_app_mgr.client_app_info.client_callback.update_dl_info_cb) {
                                                client_app_mgr.client_app_info.client_callback.update_dl_info_cb(update_dl_info, client_noti->user_data);
                                                if (update_dl_info->etag)
-                                                       DA_LOG(ClientNoti, "Etag:[%s]", update_dl_info->etag);
-                                               DA_LOG(ClientNoti, "Update download info for slot_id=%d, dl_id=%d, received size=%lu- DONE",
+                                                       DA_SECURE_LOGD("Etag:[%s]", update_dl_info->etag);
+                                               DA_SECURE_LOGD("file size=%lu", update_dl_info->file_size);
+                                               DA_LOG(ClientNoti, "Update download info for slot_id=%d, dl_id=%d- DONE",
                                                                client_noti->slot_id,
-                                                               update_dl_info->download_id,
-                                                               update_dl_info->file_size
+                                                               update_dl_info->download_id
                                                                );
                                        }
                                }
@@ -570,14 +564,16 @@ static void *__thread_for_client_noti(void *data)
                                        if (client_app_mgr.client_app_info.client_callback.finished_info_cb) {
                                                client_app_mgr.client_app_info.client_callback.finished_info_cb(
                                                        finished_info, client_noti->user_data);
-                                               DA_LOG(ClientNoti, "Completed info for slot_id=%d, dl_id=%d, saved_path=%s etag=%s err=%d http_state=%d user_data=%p- DONE",
+                                               DA_LOG(ClientNoti, "Completed info for slot_id=%d, dl_id=%d, err=%d http_state=%d user_data=%p- DONE",
                                                                client_noti->slot_id,
                                                                finished_info->download_id,
-                                                               finished_info->saved_path,
-                                                               finished_info->etag,
                                                                finished_info->err,
                                                                finished_info->http_status,
                                                                client_noti->user_data);
+                                               if (finished_info->etag)
+                                                       DA_SECURE_LOGD("Completed info for etag=%s - DONE",
+                                                                       finished_info->etag);
+
                                        }
                                }
                                break;
@@ -596,7 +592,7 @@ static void *__thread_for_client_noti(void *data)
                                }
                                break;
                                case Q_CLIENT_NOTI_TYPE_TERMINATE:
-                                       DA_LOG_CRITICAL(ClientNoti, "Q_CLIENT_NOTI_TYPE_TERMINATE");
+                                       DA_LOG_VERBOSE(ClientNoti, "Q_CLIENT_NOTI_TYPE_TERMINATE");
                                        need_wait = DA_FALSE;
                                        break;
                                }
@@ -621,7 +617,7 @@ static void *__thread_for_client_noti(void *data)
        _da_thread_cond_destroy(&(queue->cond_client_queue));
 
        pthread_cleanup_pop(0);
-       DA_LOG_CRITICAL(Thread, "=====thread_for_client_noti- EXIT=====");
+       DA_LOG_DEBUG(Thread, "=====thread_for_client_noti- EXIT=====");
        pthread_exit((void *)NULL);
        return DA_NULL;
 }
index 8e3bb78..2b66357 100755 (executable)
@@ -36,7 +36,7 @@ da_result_t init_download_mgr() {
        da_result_t ret = DA_RESULT_OK;
        int i = 0;
 
-       DA_LOG_FUNC_START(Default);
+       DA_LOG_FUNC_LOGV(Default);
 
        _da_thread_mutex_lock(&mutex_download_mgr);
 
@@ -58,7 +58,7 @@ da_result_t init_download_mgr() {
 da_result_t deinit_download_mgr(void) {
        da_result_t ret = DA_RESULT_OK;
 
-       DA_LOG_FUNC_START(Default);
+       DA_LOG_FUNC_LOGV(Default);
 
        _da_thread_mutex_lock(&mutex_download_mgr);
        if (download_mgr.is_init == DA_TRUE) {
@@ -90,12 +90,10 @@ void init_download_info(int slot_id)
 {
        dl_info_t *dl_info = DA_NULL;
 
-//     DA_LOG_FUNC_START(Default);
+       DA_LOG_FUNC_LOGV(Default);
 
        _da_thread_mutex_lock(&mutex_download_state[slot_id]);
-//     DA_LOG_VERBOSE(Default, "Init slot_id [%d] Info", slot_id);
        dl_info = &(download_mgr.dl_info[slot_id]);
-
        dl_info->is_using = DA_FALSE;
        dl_info->state = DOWNLOAD_STATE_IDLE;
        dl_info->download_stage_data = DA_NULL;
@@ -120,9 +118,7 @@ void destroy_download_info(int slot_id)
 {
        dl_info_t *dl_info = DA_NULL;
 
-       DA_LOG_FUNC_START(Default);
-
-       DA_LOG(Default, "Destroying slot_id [%d] Info", slot_id);
+       DA_LOG_VERBOSE(Default, "Destroying slot_id [%d] Info", slot_id);
 
        if (slot_id == DA_INVALID_ID) {
                DA_LOG_ERR(Default, "invalid slot_id");
@@ -131,14 +127,11 @@ void destroy_download_info(int slot_id)
 
        dl_info = &(download_mgr.dl_info[slot_id]);
        if (DA_FALSE == dl_info->is_using) {
-/*             DA_LOG_ERR(Default, "invalid slot_id"); */
                return;
        }
 
        _da_thread_mutex_lock (&mutex_download_state[slot_id]);
        dl_info->state = DOWNLOAD_STATE_IDLE;
-       DA_LOG(Default, "Changed download_state to - [%d] ", dl_info->state);
-
        dl_info->active_dl_thread_id = 0;
 
        if (dl_info->download_stage_data != DA_NULL) {
@@ -162,9 +155,9 @@ void destroy_download_info(int slot_id)
                dl_info->user_etag = DA_NULL;
        }
 
-       if (dl_info->user_temp_file_path ) {
-               free(dl_info->user_temp_file_path );
-               dl_info->user_temp_file_path  = DA_NULL;
+       if (dl_info->user_temp_file_path) {
+               free(dl_info->user_temp_file_path);
+               dl_info->user_temp_file_path = DA_NULL;
        }
 
        dl_info->user_data = DA_NULL;
@@ -174,7 +167,7 @@ void destroy_download_info(int slot_id)
 
        dl_info->is_using = DA_FALSE;
 
-       DA_LOG(Default, "Destroying slot_id [%d] Info END", slot_id);
+       DA_LOG_DEBUG(Default, "Destroying slot_id [%d] Info END", slot_id);
        _da_thread_mutex_unlock (&mutex_download_state[slot_id]);
        return;
 }
@@ -184,7 +177,7 @@ void *Add_new_download_stage(int slot_id)
        stage_info *download_stage_data = NULL;
        stage_info *new_download_stage_data = NULL;
 
-       DA_LOG_FUNC_START(Default);
+       DA_LOG_FUNC_LOGV(Default);
 
        new_download_stage_data = (stage_info*)calloc(1, sizeof(stage_info));
        if (!new_download_stage_data)
@@ -201,7 +194,7 @@ void *Add_new_download_stage(int slot_id)
        } else {
                GET_DL_CURRENT_STAGE(slot_id) = new_download_stage_data;
        }
-       DA_LOG(Default, "NEW STAGE ADDED FOR DOWNLOAD ID[%d] new_stage[%p]", slot_id,new_download_stage_data);
+       DA_LOG_VERBOSE(Default, "NEW STAGE ADDED FOR DOWNLOAD ID[%d] new_stage[%p]", slot_id,new_download_stage_data);
 
 ERR:
        return new_download_stage_data;
@@ -211,7 +204,7 @@ void remove_download_stage(int slot_id, stage_info *in_stage)
 {
        stage_info *stage = DA_NULL;
 
-       DA_LOG_FUNC_START(Default);
+       DA_LOG_FUNC_LOGV(Default);
 
        stage = GET_DL_CURRENT_STAGE(slot_id);
        if (DA_NULL == stage) {
@@ -256,9 +249,7 @@ void empty_stage_info(stage_info *in_stage)
        req_dl_info *request_download_info = NULL;
        file_info *file_information = NULL;
 
-       DA_LOG_FUNC_START(Default);
-
-       DA_LOG(Default, "Stage to Remove:[%p]", in_stage);
+       DA_LOG_VERBOSE(Default, "Stage to Remove:[%p]", in_stage);
        source_information = GET_STAGE_SOURCE_INFO(in_stage);
 
        cleanup_source_info_basic_download(
@@ -277,7 +268,7 @@ void cleanup_source_info_basic_download(source_info_basic_t *source_info_basic)
        if (NULL == source_info_basic)
                goto ERR;
 
-       DA_LOG_FUNC_START(Default);
+       DA_LOG_FUNC_LOGV(Default);
 
        if (NULL != source_info_basic->url) {
                free(source_info_basic->url);
@@ -291,16 +282,18 @@ ERR:
 
 void cleanup_req_dl_info_http(req_dl_info *http_download)
 {
-       DA_LOG_FUNC_START(Default);
+       DA_LOG_FUNC_LOGV(Default);
 
        if (http_download->http_info.http_msg_request) {
                http_msg_request_destroy(
                                &(http_download->http_info.http_msg_request));
+               http_download->http_info.http_msg_request = DA_NULL;
        }
 
        if (http_download->http_info.http_msg_response) {
                http_msg_response_destroy(
                                &(http_download->http_info.http_msg_response));
+               http_download->http_info.http_msg_response = DA_NULL;
        }
 
        if (DA_NULL != http_download->location_url) {
@@ -328,7 +321,7 @@ void cleanup_req_dl_info_http(req_dl_info *http_download)
 
 void destroy_file_info(file_info *file_information)
 {
-//     DA_LOG_FUNC_START(Default);
+       DA_LOG_FUNC_LOGV(Default);
 
        if (!file_information)
                return;
@@ -357,7 +350,7 @@ void destroy_file_info(file_info *file_information)
 
 void clean_up_client_input_info(client_input_t *client_input)
 {
-       DA_LOG_FUNC_START(Default);
+       DA_LOG_FUNC_LOGV(Default);
 
        if (client_input) {
                client_input->user_data = NULL;
@@ -382,6 +375,11 @@ void clean_up_client_input_info(client_input_t *client_input)
                        client_input->temp_file_path = DA_NULL;
                }
 
+               if (client_input->pkg_name) {
+                       free(client_input->pkg_name);
+                       client_input->pkg_name = DA_NULL;
+               }
+
                client_input_basic_t *client_input_basic =
                                &(client_input->client_input_basic);
 
@@ -457,7 +455,7 @@ da_result_t get_available_slot_id(int *available_id)
                                = get_available_dl_id(&(download_mgr.dl_id_history));
 
                        *available_id = i;
-                       DA_LOG_CRITICAL(Default, "available download id = %d", *available_id);
+                       DA_LOG_VERBOSE(Default, "available download id = %d", *available_id);
                        ret = DA_RESULT_OK;
 
                        break;
index cf3ad52..7a2ce0d 100755 (executable)
@@ -32,7 +32,7 @@ da_result_t requesting_download(stage_info *stage)
        da_result_t ret = DA_RESULT_OK;
        req_dl_info *request_session = DA_NULL;
 
-       DA_LOG_FUNC_START(Default);
+       DA_LOG_FUNC_LOGV(Default);
 
        if (!stage) {
                DA_LOG_ERR(Default, "stage is null..");
@@ -47,7 +47,7 @@ da_result_t requesting_download(stage_info *stage)
        request_session = GET_STAGE_TRANSACTION_INFO(stage);
        ret = request_http_download(stage);
        if (DA_RESULT_OK == ret) {
-               DA_LOG(Default, "Http download is complete.");
+               DA_LOG_VERBOSE(Default, "Http download is complete.");
        } else {
                DA_LOG_ERR(Default, "Http download is failed. ret = %d", ret);
                goto ERR;
@@ -61,7 +61,7 @@ da_result_t handle_after_download(stage_info *stage)
        da_result_t ret = DA_RESULT_OK;
        da_mime_type_id_t mime_type = DA_MIME_TYPE_NONE;
 
-       DA_LOG_FUNC_START(Default);
+       DA_LOG_FUNC_LOGV(Default);
 
        mime_type = get_mime_type_id(
                        GET_CONTENT_STORE_CONTENT_TYPE(GET_STAGE_CONTENT_STORE_INFO(stage)));
@@ -85,7 +85,7 @@ static da_result_t __cancel_download_with_slot_id(int slot_id)
        download_state_t download_state;
        stage_info *stage = DA_NULL;
 
-       DA_LOG_FUNC_START(Default);
+       DA_LOG_FUNC_LOGD(Default);
 
        _da_thread_mutex_lock (&mutex_download_state[slot_id]);
        download_state = GET_DL_STATE_ON_ID(slot_id);
@@ -117,7 +117,7 @@ da_result_t cancel_download(int dl_id)
 
        int slot_id = DA_INVALID_ID;
 
-       DA_LOG_FUNC_START(Default);
+       DA_LOG_FUNC_LOGD(Default);
 
        ret = get_slot_id_for_dl_id(dl_id, &slot_id);
        if (ret != DA_RESULT_OK) {
@@ -144,7 +144,7 @@ static da_result_t __suspend_download_with_slot_id(int slot_id)
        download_state_t download_state;
        stage_info *stage = DA_NULL;
 
-       DA_LOG_FUNC_START(Default);
+       DA_LOG_FUNC_LOGD(Default);
 
        _da_thread_mutex_lock (&mutex_download_state[slot_id]);
        download_state = GET_DL_STATE_ON_ID(slot_id);
@@ -168,7 +168,7 @@ da_result_t suspend_download(int dl_id, da_bool_t is_enable_cb)
        da_result_t ret = DA_RESULT_OK;
        int slot_id = DA_INVALID_ID;
 
-       DA_LOG_FUNC_START(Default);
+       DA_LOG_FUNC_LOGD(Default);
 
        ret = get_slot_id_for_dl_id(dl_id, &slot_id);
        if (ret != DA_RESULT_OK) {
@@ -195,7 +195,7 @@ static da_result_t __resume_download_with_slot_id(int slot_id)
        download_state_t download_state;
        stage_info *stage = DA_NULL;
 
-       DA_LOG_FUNC_START(Default);
+       DA_LOG_FUNC_LOGD(Default);
 
        _da_thread_mutex_lock (&mutex_download_state[slot_id]);
        download_state = GET_DL_STATE_ON_ID(slot_id);
@@ -217,7 +217,7 @@ da_result_t resume_download(int dl_id)
        da_result_t ret = DA_RESULT_OK;
        int slot_id = DA_INVALID_ID;
 
-       DA_LOG_FUNC_START(Default);
+       DA_LOG_FUNC_LOGD(Default);
 
        ret = get_slot_id_for_dl_id(dl_id, &slot_id);
        if (ret != DA_RESULT_OK)
@@ -239,14 +239,14 @@ da_result_t send_user_noti_and_finish_download_flow(
                int slot_id, char *installed_path, char *etag)
 {
        da_result_t ret = DA_RESULT_OK;
-       download_state_t download_state = DA_NULL;
+       download_state_t download_state = HTTP_STATE_READY_TO_DOWNLOAD;
        da_bool_t need_destroy_download_info = DA_FALSE;
 
-       DA_LOG_FUNC_START(Default);
+       DA_LOG_FUNC_LOGV(Default);
 
        _da_thread_mutex_lock (&mutex_download_state[slot_id]);
        download_state = GET_DL_STATE_ON_ID(slot_id);
-       DA_LOG(Default, "state = %d", download_state);
+       DA_LOG_DEBUG(Default, "state = %d", download_state);
        _da_thread_mutex_unlock (&mutex_download_state[slot_id]);
 
        switch (download_state) {
index ae2fdf4..1955fcd 100755 (executable)
@@ -47,14 +47,14 @@ da_bool_t is_base64_encoded_word(const char *in_str)
                snprintf(second_needle, sizeof(second_needle), "%s", "?=");     // ?=
        }
 
-//     DA_LOG(Default, "needle = [%s], haystack = [%s]", first_needle, haystack);
+//     DA_SECURE_LOGD("needle = [%s], haystack = [%s]", first_needle, haystack);
 
        found_str = strstr(haystack, first_needle);
        if (found_str) {
                if (found_str == haystack) {
-//                     DA_LOG(Default, "Input string is starting with %s", needle);
+//                     DA_SECURE_LOGD("Input string is starting with %s", needle);
                        haystack = haystack + strlen(haystack) - strlen(second_needle);
-//                     DA_LOG(Default, "second haystack is [%s]", haystack);
+//                     DA_SECURE_LOGD("second haystack is [%s]", haystack);
                        if(!strcmp(haystack, second_needle))
                                return DA_TRUE;
                }
@@ -76,7 +76,7 @@ da_result_t decode_base64_encoded_str(const char *in_encoded_str,
        guchar *g_decoded_text = NULL;
        gsize g_decoded_text_len = 0;
 
-       DA_LOG(Default, "input str = [%s]", in_encoded_str);
+       DA_SECURE_LOGD("input str = [%s]", in_encoded_str);
 
        org_str = in_encoded_str;
        if(!org_str) {
@@ -91,7 +91,7 @@ da_result_t decode_base64_encoded_str(const char *in_encoded_str,
                goto ERR;
        }
 
-//     DA_LOG(Default, "charset = [%s], encoding = [%c], raw = [%s]", charset_type, encoding_type, raw_encoded_str);
+//     DA_SECURE_LOGD("charset = [%s], encoding = [%c], raw = [%s]", charset_type, encoding_type, raw_encoded_str);
 
        if(encoding_type != 'B') {
                DA_LOG_ERR(Default, "Encoded Word is not encoded with Base64, but %c. We can only handle Base64.", encoding_type);
@@ -109,7 +109,7 @@ da_result_t decode_base64_encoded_str(const char *in_encoded_str,
        g_decoded_text = g_base64_decode(g_encoded_text, &g_decoded_text_len);
 
        if(g_decoded_text) {
-               DA_LOG(Default, "g_decoded_text = [%s]", g_decoded_text);
+               DA_SECURE_LOGD("g_decoded_text = [%s]", g_decoded_text);
                decoded_str = (char*)calloc(1, g_decoded_text_len+1);
                if(!decoded_str) {
                        DA_LOG_ERR(Default, "DA_ERR_FAIL_TO_MEMALLOC");
@@ -119,7 +119,7 @@ da_result_t decode_base64_encoded_str(const char *in_encoded_str,
                        memcpy(decoded_str, g_decoded_text, g_decoded_text_len);
                }
        }
-       DA_LOG(Default, "decoded_str = [%s]", decoded_str);
+       DA_SECURE_LOGD("decoded_str = [%s]", decoded_str);
 
 ERR:
        *out_decoded_ascii_str = decoded_str;
@@ -179,7 +179,7 @@ da_result_t _parsing_base64_encoded_str(const char *in_encoded_str,
                goto ERR;
        } else {
                wanted_str = wanted_str_end + strlen(needle);
-               DA_LOG(Default, "strip [%s]", wanted_str);
+               DA_SECURE_LOGD("strip [%s]", wanted_str);
        }
 
        // for charset
@@ -232,7 +232,7 @@ da_result_t _parsing_base64_encoded_str(const char *in_encoded_str,
                        wanted_str = NULL;
                }
 
-               DA_LOG(Default, "raw encoded str [%s]", raw_encoded_str);
+               DA_SECURE_LOGD("raw encoded str [%s]", raw_encoded_str);
        }
 
 ERR:
index 9df7099..0da5445 100755 (executable)
  * limitations under the License.
  */
 
+#include <stdio.h>
 #include <dirent.h>
 #include <unistd.h>
 #include <math.h>
-
+#include <errno.h>
 #include "download-agent-client-mgr.h"
 #include "download-agent-debug.h"
 #include "download-agent-utils.h"
 #include "download-agent-http-mgr.h"
 #include "download-agent-plugin-conf.h"
 
-#ifdef _ENABLE_OMA_DRM
-#include "download-agent-plugin-drm.h"
-#endif
-
-
 #define NO_NAME_TEMP_STR "No name"
 
 static da_result_t  __set_file_size(stage_info *stage);
@@ -54,7 +50,6 @@ static da_result_t __file_write_buf_copy_to_buf(file_info *file_storage,
 static da_result_t __file_write_buf_directly_write(stage_info *stage,
                file_info *file_storage, char *body, int body_len);
 
-
 da_result_t clean_files_from_dir(char *dir_path)
 {
        da_result_t ret = DA_RESULT_OK;
@@ -62,7 +57,7 @@ da_result_t clean_files_from_dir(char *dir_path)
        DIR *dir;
        char file_path[DA_MAX_FULL_PATH_LEN] = { 0, };
 
-       DA_LOG_FUNC_START(FileManager);
+       DA_LOG_FUNC_LOGD(FileManager);
 
        if (dir_path == DA_NULL)
                return DA_ERR_INVALID_ARGUMENT;
@@ -70,11 +65,11 @@ da_result_t clean_files_from_dir(char *dir_path)
        if (is_dir_exist(dir_path)) {
                dir = opendir(dir_path);
                if (DA_NULL == dir) {
-                       DA_LOG_ERR(FileManager, "opendir() for %s is failed.", dir_path);
+                       DA_LOG_ERR(FileManager, "opendir() is failed.");
                        ret = DA_ERR_INVALID_INSTALL_PATH;
                } else {
                        while (DA_NULL != (d = readdir(dir))) {
-                               DA_LOG(FileManager, "%s",d->d_name);
+                               DA_SECURE_LOGD("%s",d->d_name);
                                if (0 == strncmp(d->d_name, ".", strlen("."))
                                                || 0 == strncmp(d->d_name,
                                                                "..",
@@ -114,7 +109,7 @@ da_result_t get_mime_type(stage_info *stage, char **out_mime_type)
        /* Priority 1 */
        if (GET_REQUEST_HTTP_HDR_CONT_TYPE(GET_STAGE_TRANSACTION_INFO(stage))) {
                mime_type = GET_REQUEST_HTTP_HDR_CONT_TYPE(GET_STAGE_TRANSACTION_INFO(stage));
-                DA_LOG(FileManager, "content type from HTTP response header [%s]", mime_type);
+//             DA_SECURE_LOGI("content type from HTTP response header [%s]", mime_type);
        }
 
        if (!mime_type) {
@@ -126,14 +121,14 @@ da_result_t get_mime_type(stage_info *stage, char **out_mime_type)
        *out_mime_type = (char *)calloc(1, strlen(mime_type) + 1);
        if (*out_mime_type) {
                strncpy(*out_mime_type, mime_type, strlen(mime_type));
-               DA_LOG_VERBOSE(FileManager, "out_mime_type str[%s] ptr[%p] len[%d]",
-                               *out_mime_type,*out_mime_type,strlen(*out_mime_type));
+//             DA_SECURE_LOGD("out_mime_type str[%s] ptr[%p] len[%d]",
+//                             *out_mime_type,*out_mime_type,strlen(*out_mime_type));
        } else {
                DA_LOG_ERR(FileManager, "fail to allocate memory");
                return DA_ERR_FAIL_TO_MEMALLOC;
        }
 
-       DA_LOG(FileManager, "mime type = %s", *out_mime_type);
+//     DA_SECURE_LOGD("mime type = %s", *out_mime_type);
        return DA_RESULT_OK;
 }
 
@@ -151,7 +146,7 @@ da_bool_t is_file_exist(const char *file_path)
 
        if (stat_ret == 0) {
                if (dir_state.st_mode & S_IFREG) {
-                       DA_LOG(FileManager, "Exist! %s is a regular file & its size = %lu", file_path, dir_state.st_size);
+                       DA_SECURE_LOGD("Exist! %s is a regular file & its size = %lu", file_path, dir_state.st_size);
                        return DA_TRUE;
                }
 
@@ -175,7 +170,7 @@ da_bool_t is_dir_exist(const char *file_path)
 
        if (stat_ret == 0) {
                if (dir_state.st_mode & S_IFDIR) {
-                       DA_LOG(FileManager, "Exist! %s is a directory.", file_path);
+                       DA_LOG_VERBOSE(FileManager, "Existed directory.");
                        return DA_TRUE;
                }
 
@@ -217,28 +212,29 @@ da_result_t __saved_file_open(stage_info *stage)
        char *actual_file_path = DA_NULL;
        void *fd = DA_NULL;
 
-       DA_LOG_FUNC_START(FileManager);
+       DA_LOG_FUNC_LOGV(FileManager);
 
        file_storage = GET_STAGE_CONTENT_STORE_INFO(stage);
        if (!file_storage)
                return DA_ERR_INVALID_ARGUMENT;
 
        actual_file_path = GET_CONTENT_STORE_ACTUAL_FILE_NAME(file_storage);
-       DA_LOG(FileManager, "actual_file_path = %s", actual_file_path);
        if (!actual_file_path)
                return DA_ERR_INVALID_ARGUMENT;
 
-
        fd = fopen(actual_file_path, "a+"); // for resume
        if (fd == DA_NULL) {
                DA_LOG_ERR(FileManager, "File open failed");
-               ret = DA_ERR_FAIL_TO_ACCESS_FILE;
+               if (errno == ENOSPC)
+                       ret = DA_ERR_DISK_FULL;
+               else
+                       ret = DA_ERR_FAIL_TO_ACCESS_FILE;
                goto ERR;
        }
        GET_CONTENT_STORE_FILE_HANDLE(file_storage) = fd;
 
-       DA_LOG(FileManager, "file path for saving = %s",
-                       GET_CONTENT_STORE_ACTUAL_FILE_NAME(file_storage));
+//     DA_SECURE_LOGD("file path for saving = %s",
+//                     GET_CONTENT_STORE_ACTUAL_FILE_NAME(file_storage));
 
 ERR:
        if (DA_RESULT_OK != ret) {
@@ -253,7 +249,7 @@ da_result_t __set_file_size(stage_info *stage)
        req_dl_info *stage_req_info = DA_NULL;
        file_info *file_storage = DA_NULL;
 
-       DA_LOG_FUNC_START(FileManager);
+       DA_LOG_FUNC_LOGV(FileManager);
 
        if (!stage) {
                ret = DA_ERR_INVALID_ARGUMENT;
@@ -266,13 +262,13 @@ da_result_t __set_file_size(stage_info *stage)
        if (!file_storage)
                goto ERR;
 
-       if (GET_REQUEST_HTTP_HDR_CONT_LEN(stage_req_info) != DA_NULL) {
+       if (GET_REQUEST_HTTP_HDR_CONT_LEN(stage_req_info) != 0) {
                GET_CONTENT_STORE_FILE_SIZE(file_storage)
                                = GET_REQUEST_HTTP_HDR_CONT_LEN(stage_req_info);
        } else {
                GET_CONTENT_STORE_FILE_SIZE(file_storage) = 0;
        }
-       DA_LOG(FileManager, "file size = %d", GET_CONTENT_STORE_FILE_SIZE(file_storage));
+       DA_LOG_VERBOSE(FileManager, "file size = %d", GET_CONTENT_STORE_FILE_SIZE(file_storage));
 ERR:
        return ret;
 
@@ -315,7 +311,7 @@ char *__derive_extension(stage_info *stage)
                                DA_NULL, &file_name);
                if (b_ret && file_name) {
                        char *extension = DA_NULL;
-                       DA_LOG(FileManager, "Name from Content-Disposition :[%s]", file_name);
+                       DA_SECURE_LOGD("Name from Content-Disposition :[%s]", file_name);
                        __divide_file_name_into_pure_name_N_extesion(file_name, DA_NULL, &extension);
                                if (file_name) {
                                free(file_name);
@@ -333,7 +329,7 @@ char *__derive_extension(stage_info *stage)
        else
                url = GET_SOURCE_BASIC_URL(source_info);
        if (url) {
-               DA_LOG(FileManager, "url:[%s]", url);
+               DA_SECURE_LOGD("url:[%s]", url);
                da_bool_t b_ret = da_get_extension_name_from_url(url, &extension);
                if (b_ret && extension)
                        return extension;
@@ -355,7 +351,7 @@ da_result_t __get_candidate_file_name(stage_info *stage, char **out_pure_file_na
        char *pure_file_name = DA_NULL;
        char *extension = DA_NULL;
 
-       DA_LOG_FUNC_START(FileManager);
+       DA_LOG_FUNC_LOGV(FileManager);
 
        if (!stage || !out_pure_file_name)
                return DA_ERR_INVALID_ARGUMENT;
@@ -381,8 +377,8 @@ da_result_t __get_candidate_file_name(stage_info *stage, char **out_pure_file_na
                        da_bool_t b_ret = http_msg_response_get_content_disposition(http_msg_response,
                                        DA_NULL, &file_name);
                        if (b_ret && file_name) {
-                               DA_LOG(FileManager, "Name from Content-Disposition :[%s]", file_name);
-                               __divide_file_name_into_pure_name_N_extesion(file_name, &pure_file_name, DA_NULL);
+                               DA_SECURE_LOGD("Name from Content-Disposition :[%s]", file_name);
+                               __divide_file_name_into_pure_name_N_extesion(file_name, &pure_file_name, &extension);
                                if (file_name) {
                                        free(file_name);
                                        file_name = DA_NULL;
@@ -402,7 +398,7 @@ da_result_t __get_candidate_file_name(stage_info *stage, char **out_pure_file_na
                else
                        url = GET_SOURCE_BASIC_URL(source_info);
                if (url) {
-                       DA_LOG(FileManager, "url: [%s]", url);
+                       DA_SECURE_LOGD("url: [%s]", url);
                        da_get_file_name_from_url(url, &pure_file_name);
                }
        }
@@ -418,7 +414,7 @@ da_result_t __get_candidate_file_name(stage_info *stage, char **out_pure_file_na
 
        *out_pure_file_name = pure_file_name;
        pure_file_name = DA_NULL;
-       DA_LOG(FileManager, "candidate file name [%s]", *out_pure_file_name);
+       DA_SECURE_LOGD("candidate file name [%s]", *out_pure_file_name);
 
        if (out_extension) {
                if (extension) {
@@ -426,7 +422,7 @@ da_result_t __get_candidate_file_name(stage_info *stage, char **out_pure_file_na
                        extension = DA_NULL;
                } else {
                        *out_extension = __derive_extension(stage);
-                       DA_LOG(FileManager, "candidate extension [%s]", *out_extension);
+                       DA_SECURE_LOGD("candidate extension [%s]", *out_extension);
                }
        }
 
@@ -452,7 +448,7 @@ da_result_t __decide_file_path(stage_info *stage)
        char *user_install_path = DA_NULL;
        file_info *file_info_data = DA_NULL;
        int len = 0;
-       DA_LOG_FUNC_START(FileManager);
+       DA_LOG_FUNC_LOGV(FileManager);
 
        file_info_data = GET_STAGE_CONTENT_STORE_INFO(stage);
        if (!file_info_data)
@@ -506,7 +502,7 @@ da_result_t __decide_file_path(stage_info *stage)
        }
 
 ERR:
-       DA_LOG(FileManager, "decided file path = %s", GET_CONTENT_STORE_ACTUAL_FILE_NAME(file_info_data));
+       DA_SECURE_LOGI("decided file path = %s", GET_CONTENT_STORE_ACTUAL_FILE_NAME(file_info_data));
        if (temp_dir) {
                free(temp_dir);
                temp_dir = DA_NULL;
@@ -532,15 +528,14 @@ char *get_full_path_avoided_duplication(char *in_dir, char *in_candidate_file_na
        int final_path_len = 0;
        int extension_len = 0;
 
-       int suffix_count = 0;   /* means suffix on file name. up to "_99" */
-       const int max_suffix_count = 99;
+       int suffix_count = 0;   /* means suffix on file name. up to "_1000000000" */
+       const int max_suffix_count = 1000000000;
        int suffix_len = (int)log10(max_suffix_count+1) + 1;    /* 1 means "_" */
 
        if (!in_dir || !in_candidate_file_name)
                return DA_NULL;
 
-//     DA_LOG_FUNC_START(FileManager);
-       DA_LOG(FileManager, "in_candidate_file_name=[%s], in_extension=[%s]", in_candidate_file_name, in_extension);
+//     DA_SECURE_LOGD("in_candidate_file_name=[%s], in_extension=[%s]", in_candidate_file_name, in_extension);
 
        if (extension)
                extension_len = strlen(extension);
@@ -592,7 +587,7 @@ char *get_full_path_avoided_duplication(char *in_dir, char *in_candidate_file_na
                break;
        } while (1);
 
-       DA_LOG(FileManager, "decided path = [%s]", final_path);
+//     DA_SECURE_LOGD("decided path = [%s]", final_path);
        return final_path;
 }
 
@@ -605,7 +600,7 @@ da_result_t __divide_file_name_into_pure_name_N_extesion(const char *in_file_nam
        int len = 0;
        da_result_t ret = DA_RESULT_OK;
 
-       DA_LOG_FUNC_START(FileManager);
+       DA_LOG_FUNC_LOGD(FileManager);
 
        if (!in_file_name)
                return DA_ERR_INVALID_ARGUMENT;
@@ -617,7 +612,7 @@ da_result_t __divide_file_name_into_pure_name_N_extesion(const char *in_file_nam
        if (tmp_ptr && out_extension) {
                strncpy((char*) tmp_ext, tmp_ptr, sizeof(tmp_ext) - 1);
                *out_extension = strdup((const char*) tmp_ext);
-               DA_LOG(FileManager, "extension [%s]", *out_extension);
+               DA_SECURE_LOGD("extension [%s]", *out_extension);
        }
 
        if (!out_pure_file_name)
@@ -644,7 +639,7 @@ da_result_t __divide_file_name_into_pure_name_N_extesion(const char *in_file_nam
                                (const char*) temp_file);
        }
 
-       DA_LOG(FileManager, "pure file name [%s]", *out_pure_file_name);
+       DA_SECURE_LOGD("pure file name [%s]", *out_pure_file_name);
        return ret;
 }
 
@@ -653,7 +648,7 @@ da_result_t __file_write_buf_make_buf(file_info *file_storage)
        da_result_t ret = DA_RESULT_OK;
        char *buffer = DA_NULL;
 
-       DA_LOG_FUNC_START(FileManager);
+       DA_LOG_FUNC_LOGV(FileManager);
 
        buffer = (char*) calloc(DOWNLOAD_NOTIFY_LIMIT, 1);
        if (DA_NULL == buffer) {
@@ -671,7 +666,7 @@ da_result_t __file_write_buf_destroy_buf(file_info *file_storage)
 {
        da_result_t ret = DA_RESULT_OK;
 
-       DA_LOG_FUNC_START(FileManager);
+       DA_LOG_FUNC_LOGV(FileManager);
 
        if (GET_CONTENT_STORE_FILE_BUFFER(file_storage))
                free(GET_CONTENT_STORE_FILE_BUFFER(file_storage));
@@ -690,7 +685,7 @@ da_result_t __file_write_buf_flush_buf(stage_info *stage, file_info *file_storag
        int write_success_len = 0;
        void *fd = DA_NULL;
 
-       //      DA_LOG_FUNC_START(FileManager);
+       DA_LOG_FUNC_LOGV(FileManager);
 
        buffer = GET_CONTENT_STORE_FILE_BUFFER(file_storage);
        buffer_size = GET_CONTENT_STORE_FILE_BUFF_LEN(file_storage);
@@ -707,7 +702,6 @@ da_result_t __file_write_buf_flush_buf(stage_info *stage, file_info *file_storag
                ret = DA_ERR_FAIL_TO_ACCESS_FILE;
                goto ERR;
        }
-
        write_success_len = fwrite(buffer, sizeof(char), buffer_size,
                        (FILE *) fd);
        /* FIXME : This can be necessary later due to progressive download.
@@ -715,13 +709,15 @@ da_result_t __file_write_buf_flush_buf(stage_info *stage, file_info *file_storag
        //fflush((FILE *) fd);
        if (write_success_len != buffer_size) {
                DA_LOG_ERR(FileManager, "write  fails ");
-               ret = DA_ERR_FAIL_TO_ACCESS_FILE;
+               if (errno == ENOSPC)
+                       ret = DA_ERR_DISK_FULL;
+               else
+                       ret = DA_ERR_FAIL_TO_ACCESS_FILE;
                goto ERR;
        }
        GET_CONTENT_STORE_CURRENT_FILE_SIZE(GET_STAGE_CONTENT_STORE_INFO(stage))
                        += write_success_len;
-       DA_LOG(FileManager, "write %d bytes", write_success_len);
-
+       DA_LOG_VERBOSE(FileManager, "write %d bytes", write_success_len);
        IS_CONTENT_STORE_FILE_BYTES_WRITTEN_TO_FILE(file_storage) = DA_TRUE;
        GET_CONTENT_STORE_FILE_BUFF_LEN(file_storage) = 0;
 
@@ -736,7 +732,7 @@ da_result_t __file_write_buf_copy_to_buf(file_info *file_storage, char *body,
        char *buffer = DA_NULL;
        int buffer_size = 0;
 
-       //      DA_LOG_FUNC_START(FileManager);
+       DA_LOG_FUNC_LOGV(FileManager);
 
        buffer = GET_CONTENT_STORE_FILE_BUFFER(file_storage);
        buffer_size = GET_CONTENT_STORE_FILE_BUFF_LEN(file_storage);
@@ -754,7 +750,7 @@ da_result_t __file_write_buf_directly_write(stage_info *stage,
        int write_success_len = 0;
        void *fd = DA_NULL;
 
-       //      DA_LOG_FUNC_START(FileManager);
+       DA_LOG_FUNC_LOGV(FileManager);
 
        fd = GET_CONTENT_STORE_FILE_HANDLE(file_storage);
        if (DA_NULL == fd) {
@@ -763,7 +759,6 @@ da_result_t __file_write_buf_directly_write(stage_info *stage,
                ret = DA_ERR_FAIL_TO_ACCESS_FILE;
                goto ERR;
        }
-
        write_success_len = fwrite(body, sizeof(char), body_len,
                        (FILE *) fd);
        /* FIXME : This can be necessary later due to progressive download.
@@ -771,7 +766,10 @@ da_result_t __file_write_buf_directly_write(stage_info *stage,
        //fflush((FILE *) fd);
        if (write_success_len != body_len) {
                DA_LOG_ERR(FileManager, "write  fails ");
-               ret = DA_ERR_FAIL_TO_ACCESS_FILE;
+               if (errno == ENOSPC)
+                       ret = DA_ERR_DISK_FULL;
+               else
+                       ret = DA_ERR_FAIL_TO_ACCESS_FILE;
                goto ERR;
        }
        GET_CONTENT_STORE_CURRENT_FILE_SIZE(GET_STAGE_CONTENT_STORE_INFO(stage))
@@ -790,7 +788,7 @@ da_result_t file_write_ongoing(stage_info *stage, char *body, int body_len)
        int buffer_size = 0;
        char *buffer = DA_NULL;
 
-       //      DA_LOG_FUNC_START(FileManager);
+       DA_LOG_FUNC_LOGV(FileManager);
 
        file_storage = GET_STAGE_CONTENT_STORE_INFO(stage);
        if (!file_storage) {
@@ -861,7 +859,7 @@ da_result_t file_write_complete(stage_info *stage)
        unsigned int buffer_size = 0;
        void *fd = DA_NULL;
 
-       DA_LOG_FUNC_START(FileManager);
+       DA_LOG_FUNC_LOGV(FileManager);
 
        file_storage = GET_STAGE_CONTENT_STORE_INFO(stage);
        if (!file_storage) {
@@ -899,7 +897,7 @@ da_result_t start_file_writing(stage_info *stage)
        da_result_t ret = DA_RESULT_OK;
        file_info *file_info_data = DA_NULL;
 
-       DA_LOG_FUNC_START(FileManager);
+       DA_LOG_FUNC_LOGV(FileManager);
 
        file_info_data = GET_STAGE_CONTENT_STORE_INFO(stage);
        ret = get_mime_type(stage,
@@ -929,7 +927,7 @@ da_result_t start_file_writing_append(stage_info *stage)
 {
        da_result_t ret = DA_RESULT_OK;
 
-       DA_LOG_FUNC_START(FileManager);
+       DA_LOG_FUNC_LOGD(FileManager);
 
        ret = __saved_file_open(stage);
 
@@ -948,7 +946,7 @@ da_result_t start_file_writing_append_with_new_download(stage_info *stage)
        req_dl_info *request_info = DA_NULL;
        unsigned long long temp_file_size = 0;
 
-       DA_LOG_FUNC_START(FileManager);
+       DA_LOG_FUNC_LOGD(FileManager);
 
        file_storage = GET_STAGE_CONTENT_STORE_INFO(stage);
        if (!file_storage)
@@ -1026,7 +1024,7 @@ da_result_t discard_download(stage_info *stage)
        file_info *file_storage = DA_NULL;
        FILE *f_handle = DA_NULL;
 
-       DA_LOG_FUNC_START(FileManager);
+       DA_LOG_FUNC_LOGD(FileManager);
 
        file_storage = GET_STAGE_CONTENT_STORE_INFO(stage);
 
@@ -1044,7 +1042,7 @@ void clean_paused_file(stage_info *stage)
        char *paused_file_path = DA_NULL;
        FILE *fd = DA_NULL;
 
-       DA_LOG_FUNC_START(FileManager);
+       DA_LOG_FUNC_LOGD(FileManager);
 
        file_info_data = GET_STAGE_CONTENT_STORE_INFO(stage);
 
@@ -1067,7 +1065,7 @@ da_result_t replace_content_file_in_stage(stage_info *stage,
        char *dd_file_path = DA_NULL;
        int len;
 
-       DA_LOG_FUNC_START(FileManager);
+       DA_LOG_FUNC_LOGD(FileManager);
 
        if (!dest_dd_file_path
                        && (DA_FALSE == is_file_exist(dest_dd_file_path))) {
@@ -1105,7 +1103,7 @@ da_result_t copy_file(const char *src, const char *dest)
        int fwritenum = 0;
        char buff[4096] = { 0, };
 
-       DA_LOG_FUNC_START(FileManager);
+       DA_LOG_FUNC_LOGD(FileManager);
 
        /* open files to copy */
        fs = fopen(src, "rb");
@@ -1150,10 +1148,10 @@ da_result_t create_dir(const char *install_dir)
                /* read/write/search permissions for owner and group,
                 * and with read/search permissions for others. */
        if (mkdir(install_dir, S_IRWXU | S_IRWXG | S_IRWXO)) {
-               DA_LOG_ERR(FileManager, "Fail to creaate directory [%s]", install_dir);
+               DA_LOG_ERR(FileManager, "Fail to creaate directory");
                ret = DA_ERR_FAIL_TO_ACCESS_STORAGE;
        } else {
-               DA_LOG(FileManager, "[%s] is created!", install_dir);
+               DA_SECURE_LOGD("[%s] is created!", install_dir);
                if (chown(install_dir, 5000, 5000) < 0) {
                        DA_LOG_ERR(FileManager, "Fail to chown");
                        ret = DA_ERR_FAIL_TO_ACCESS_STORAGE;
@@ -1162,37 +1160,9 @@ da_result_t create_dir(const char *install_dir)
        return ret;
 }
 
-
-da_result_t get_default_dir(char **out_path)
-{
-       char *tmp_default_path = DA_NULL;
-       int len = 0;
-
-       if (!out_path) {
-               DA_LOG_ERR(ClientNoti, "DA_ERR_INVALID_ARGUMENT");
-               return DA_ERR_INVALID_ARGUMENT;
-       }
-
-       len = strlen(DA_DEFAULT_FILE_DIR_PATH);
-       tmp_default_path = calloc(len + 1, sizeof(char));
-       if (!tmp_default_path) {
-               return DA_ERR_FAIL_TO_MEMALLOC;
-       }
-
-       memcpy(tmp_default_path, DA_DEFAULT_FILE_DIR_PATH, len);
-       tmp_default_path[len] = '\0';
-
-       *out_path = tmp_default_path;
-
-       DA_LOG_VERBOSE(FileManager, "default temp path = [%s]", *out_path);
-
-       return DA_RESULT_OK;
-}
-
 da_result_t get_default_install_dir(char **out_path)
 {
        char *default_path = DA_NULL;
-       da_storage_type_t type;
        da_result_t ret = DA_RESULT_OK;
        int len = 0;
 
@@ -1200,22 +1170,15 @@ da_result_t get_default_install_dir(char **out_path)
                DA_LOG_ERR(ClientNoti, "DA_ERR_INVALID_ARGUMENT");
                return DA_ERR_INVALID_ARGUMENT;
        }
-       ret = get_storage_type(&type);
-       if (DA_RESULT_OK != ret)
-               return ret;
-       if (type == DA_STORAGE_MMC)
-               len = strlen(DA_DEFAULT_INSTALL_PATH_FOR_MMC);
-       else
-               len = strlen(DA_DEFAULT_INSTALL_PATH_FOR_PHONE);
+
+       len = strlen(DA_DEFAULT_INSTALL_PATH_FOR_PHONE);
 
        default_path = calloc(len + 1, sizeof(char));
        if (!default_path) {
                return DA_ERR_FAIL_TO_MEMALLOC;
        }
-       if (type == DA_STORAGE_MMC)
-               memcpy(default_path, DA_DEFAULT_INSTALL_PATH_FOR_MMC, len);
-       else // DA_STROAGE_PHONE
-               memcpy(default_path, DA_DEFAULT_INSTALL_PATH_FOR_PHONE, len);
+
+       memcpy(default_path, DA_DEFAULT_INSTALL_PATH_FOR_PHONE, len);
        default_path[len] = '\0';
 
        *out_path = default_path;
@@ -1223,6 +1186,6 @@ da_result_t get_default_install_dir(char **out_path)
        if (!is_dir_exist(default_path)) {
                ret = create_dir(default_path);
        }
-       DA_LOG_VERBOSE(FileManager, "default temp path = [%s]", *out_path);
+       DA_SECURE_LOGD("default temp path = [%s]", *out_path);
        return DA_RESULT_OK;
 }
index 52d72c9..bbc69f0 100755 (executable)
@@ -84,7 +84,7 @@ da_result_t init_http_mgr(void)
 {
        da_result_t ret = DA_RESULT_OK;
 
-       DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGV(HTTPManager);
 
        if (http_mgr.is_http_init == DA_FALSE) {
                http_mgr.is_http_init = DA_TRUE;
@@ -100,7 +100,7 @@ da_result_t request_to_abort_http_download(stage_info *stage)
        da_result_t ret = DA_RESULT_OK;
        q_event_t *q_event = DA_NULL;
 
-       DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGD(HTTPManager);
        if (!stage) {
                DA_LOG_ERR(HTTPManager, "Stage is NULL. download info is already destroyed");
                return DA_ERR_INVALID_ARGUMENT;
@@ -122,7 +122,7 @@ ERR:
 
 void deinit_http_mgr(void)
 {
-       DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGV(HTTPManager);
 
        if (http_mgr.is_http_init == DA_TRUE) {
                http_mgr.is_http_init = DA_FALSE;
@@ -143,13 +143,11 @@ da_result_t request_http_download(stage_info *stage)
        queue_t *queue = DA_NULL;
        req_dl_info *req_info = DA_NULL;
 
-       DA_LOG_FUNC_START(HTTPManager);
-
        slot_id = GET_STAGE_DL_ID(stage);
        queue = GET_DL_QUEUE(slot_id);
        req_info = GET_STAGE_TRANSACTION_INFO(stage);
 
-       DA_LOG(HTTPManager, "queue = %p", GET_DL_QUEUE(slot_id));
+       DA_LOG_VERBOSE(HTTPManager, "queue = %p", GET_DL_QUEUE(slot_id));
 
        CHANGE_HTTP_STATE(HTTP_STATE_READY_TO_DOWNLOAD, stage);
 
@@ -189,7 +187,7 @@ da_result_t request_http_download(stage_info *stage)
 #ifdef PAUSE_EXIT
                case HTTP_STATE_PAUSED:
 #endif
-                       DA_LOG(HTTPManager, "exiting...");
+                       DA_LOG_VERBOSE(HTTPManager, "exiting...");
                        need_wait = DA_FALSE;
                        break;
 
@@ -202,9 +200,9 @@ da_result_t request_http_download(stage_info *stage)
                        if (DA_FALSE == GET_IS_Q_HAVING_DATA(queue)) {
                                unpause_for_flow_control(stage);
 
-//                             DA_LOG(HTTPManager, "Waiting for input");
+//                             DA_LOG_VERBOSE(HTTPManager, "Waiting for input");
                                Q_goto_sleep(queue);
-//                             DA_LOG(HTTPManager, "Woke up to receive new packet or control event");
+//                             DA_LOG_VERBOSE(HTTPManager, "Woke up to receive new packet or control event");
                        }
                        _da_thread_mutex_unlock (&(queue->mutex_queue));
 
@@ -213,7 +211,8 @@ da_result_t request_http_download(stage_info *stage)
        } while (need_wait == DA_TRUE);
 
        ret = GET_REQUEST_HTTP_RESULT(req_info);
-       DA_LOG(HTTPManager, "--------------Exiting request_http_download! ret = %d", ret);
+       DA_LOG_DEBUG(HTTPManager, "Exit request_http_download! ret[%d]slot_id[%d]",
+                       ret, slot_id);
        return ret;
 }
 
@@ -222,7 +221,7 @@ da_result_t request_to_cancel_http_download(stage_info *stage)
        da_result_t ret = DA_RESULT_OK;
        q_event_t *q_event = DA_NULL;
 
-       DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGD(HTTPManager);
 
        DA_LOG(HTTPManager, "Q_EVENT_TYPE_CONTROL_CANCEL");
        ret = Q_make_control_event(Q_EVENT_TYPE_CONTROL_CANCEL, &q_event);
@@ -244,7 +243,7 @@ da_result_t request_to_suspend_http_download(stage_info *stage)
        http_state_t http_state = 0;
        q_event_t *q_event = DA_NULL;
 
-       DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGD(HTTPManager);
 
        _da_thread_mutex_lock(&(GET_REQUEST_HTTP_MUTEX_HTTP_STATE(stage)));
        http_state = GET_HTTP_STATE_ON_STAGE(stage);
@@ -284,7 +283,7 @@ da_result_t request_to_resume_http_download(stage_info *stage)
        http_state_t http_state = 0;
        q_event_t *q_event = DA_NULL;
 
-       DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGD(HTTPManager);
 
        _da_thread_mutex_lock(&(GET_REQUEST_HTTP_MUTEX_HTTP_STATE(stage)));
        http_state = GET_HTTP_STATE_ON_STAGE(stage);
@@ -353,7 +352,7 @@ da_result_t make_default_http_request_hdr(const char *url,
        http_msg_request_t *http_msg_request = NULL;
        char *user_agent = NULL;
 
-       DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGV(HTTPManager);
 
        if (!url) {
                DA_LOG_ERR(HTTPManager, "DA_ERR_NO_URL");
@@ -443,7 +442,7 @@ da_result_t set_http_request_hdr(stage_info *stage)
        char *user_request_temp_file_path = DA_NULL;
        http_msg_request_t* http_msg_request = NULL;
 
-       DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGV(HTTPManager);
 
        request_info = GET_STAGE_TRANSACTION_INFO(stage);
 
@@ -463,9 +462,9 @@ da_result_t set_http_request_hdr(stage_info *stage)
        user_request_temp_file_path = GET_REQUEST_HTTP_USER_REQUEST_TEMP_FILE_PATH(
                                request_info);
        if (user_request_etag) {
-               DA_LOG(HTTPManager, "user_request_etag[%s]",user_request_etag);
+               DA_SECURE_LOGD("user_request_etag[%s]",user_request_etag);
        } else {
-               DA_LOG_ERR(HTTPManager, "user_request_etag is NULL");
+               DA_LOG_VERBOSE(HTTPManager, "user_request_etag is NULL");
        }
        ret = make_default_http_request_hdr(url, user_request_header,
                user_request_header_count, &http_msg_request,
@@ -487,7 +486,7 @@ da_result_t make_transaction_info_and_start_transaction(stage_info *stage)
 
        input_for_tranx_t *input_for_tranx = DA_NULL;
 
-       DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGV(HTTPManager);
 
        slot_id = GET_STAGE_DL_ID(stage);
 
@@ -537,7 +536,7 @@ da_result_t make_req_dl_info_http(stage_info *stage, req_dl_info *out_info)
        int dl_id = -1;
        source_info_t *source_info = DA_NULL;
 
-       DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGV(HTTPManager);
 
        if (!stage) {
                DA_LOG_ERR(HTTPManager, "stage is NULL");
@@ -555,7 +554,7 @@ da_result_t make_req_dl_info_http(stage_info *stage, req_dl_info *out_info)
        user_request_etag = GET_DL_USER_ETAG(GET_STAGE_DL_ID(stage));
        user_request_temp_file_path = GET_DL_USER_TEMP_FILE_PATH(GET_STAGE_DL_ID(stage));
 
-       DA_LOG(HTTPManager, "url [%s]", url);
+       DA_SECURE_LOGD("url [%s]", url);
 
        if (url) {
                GET_REQUEST_HTTP_REQ_URL(out_info) = url;
@@ -585,7 +584,7 @@ da_result_t unpause_for_flow_control(stage_info *stage)
 {
        da_result_t ret = DA_RESULT_OK;
 
-       //      DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGV(HTTPManager);
 
        PI_http_unpause_transaction(
                        GET_REQUEST_HTTP_TRANS_ID(GET_STAGE_TRANSACTION_INFO(stage)));
@@ -596,7 +595,7 @@ da_result_t handle_event_abort(stage_info *stage)
        da_result_t ret = DA_RESULT_OK;
        http_state_t state = 0;
 
-       DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGD(HTTPManager);
 
        _da_thread_mutex_lock(&(GET_REQUEST_HTTP_MUTEX_HTTP_STATE(stage)));
        state = GET_HTTP_STATE_ON_STAGE(stage);
@@ -635,7 +634,7 @@ da_result_t handle_event_cancel(stage_info *stage)
        da_result_t ret = DA_RESULT_OK;
        http_state_t state = 0;
 
-       DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGD(HTTPManager);
 
        _da_thread_mutex_lock(&(GET_REQUEST_HTTP_MUTEX_HTTP_STATE(stage)));
        state = GET_HTTP_STATE_ON_STAGE(stage);
@@ -768,7 +767,7 @@ da_result_t create_resume_http_request_hdr(stage_info *stage,
        char *etag_from_response = NULL;
        char *date_from_response = NULL;
 
-       DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGD(HTTPManager);
 
        request_info = GET_STAGE_TRANSACTION_INFO(stage);
 
@@ -784,14 +783,14 @@ da_result_t create_resume_http_request_hdr(stage_info *stage,
                if (b_ret) {
                        etag_from_response = value;
                        value = NULL;
-                       DA_LOG(HTTPManager, "[ETag][%s]", etag_from_response);
+                       DA_SECURE_LOGD("[ETag][%s]", etag_from_response);
                }
 
                b_ret = http_msg_response_get_date(first_response, &value);
                if (b_ret) {
                        date_from_response = value;
                        value = NULL;
-                       DA_LOG(HTTPManager, "[Date][%s]", date_from_response);
+                       DA_SECURE_LOGD("[Date][%s]", date_from_response);
                }
 
                downloaded_data_size
@@ -845,13 +844,13 @@ da_result_t handle_any_input(stage_info *stage)
        queue_t *queue = DA_NULL;
        q_event_t *event = DA_NULL;
 
-       //      DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGV(HTTPManager);
 
        queue = GET_DL_QUEUE(slot_id);
 
        Q_pop_event(queue, &event);
        if (event == DA_NULL) {
-               DA_LOG(HTTPManager, "There is no data on the queue!");
+               DA_LOG_DEBUG(HTTPManager, "There is no data on the queue!");
                return DA_RESULT_OK;
        }
 
@@ -879,7 +878,7 @@ da_result_t handle_event_control(stage_info *stage, q_event_t *event)
 {
        da_result_t ret = DA_RESULT_OK;
 
-       DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGD(HTTPManager);
 
        if (event->event_type == Q_EVENT_TYPE_CONTROL) {
                switch (event->type.q_event_control.control_type) {
@@ -905,6 +904,10 @@ da_result_t handle_event_control(stage_info *stage, q_event_t *event)
                case Q_EVENT_TYPE_CONTROL_NET_DISCONNECTED:
                        DA_LOG(HTTPManager, "Q_EVENT_TYPE_CONTROL_NET_DISCONNECTED");
                        break;
+               case Q_EVENT_TYPE_CONTROL_NONE:
+               default:
+                       DA_LOG_ERR(HTTPManager, "Cannot enter here");
+                       break;
                }
        }
 
@@ -916,26 +919,21 @@ da_result_t handle_event_http(stage_info *stage, q_event_t *event)
        da_result_t ret = DA_RESULT_OK;
        q_event_data_http_t *q_event_data_http = DA_NULL;
 
-       //      DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGV(HTTPManager);
 
        if (event->event_type == Q_EVENT_TYPE_DATA_HTTP) {
                q_event_data_http = &(event->type.q_event_data_http);
                switch (q_event_data_http->data_type) {
                case Q_EVENT_TYPE_DATA_PACKET:
                        ret = handle_event_http_packet(stage, event);
-
                        break;
-
                case Q_EVENT_TYPE_DATA_FINAL:
-                       DA_LOG(HTTPManager, "Q_EVENT_TYPE_DATA_FINAL");
+                       DA_LOG_VERBOSE(HTTPManager, "Q_EVENT_TYPE_DATA_FINAL");
                        ret = handle_event_http_final(stage, event);
-
                        break;
-
                case Q_EVENT_TYPE_DATA_ABORT:
-                       DA_LOG(HTTPManager, "Q_EVENT_TYPE_DATA_ABORT");
+                       DA_LOG_VERBOSE(HTTPManager, "Q_EVENT_TYPE_DATA_ABORT");
                        ret = handle_event_http_abort(stage, event);
-
                        break;
                }
        }
@@ -948,7 +946,7 @@ da_result_t handle_event_http_packet(stage_info *stage, q_event_t *event)
        da_bool_t is_handle_hdr_success = DA_TRUE;
        q_event_data_http_t *received_data = DA_NULL;
 
-       //      DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGV(HTTPManager);
 
        received_data = &(event->type.q_event_data_http);
 
@@ -977,11 +975,13 @@ da_result_t handle_event_http_packet(stage_info *stage, q_event_t *event)
 da_result_t handle_event_http_final(stage_info *stage, q_event_t *event)
 {
        da_result_t ret = DA_RESULT_OK;
-
        http_state_t http_state = 0;
        int slot_id = DA_INVALID_ID;
+       int http_status = 0;
+       q_event_data_http_t *received_data = DA_NULL;
 
-       DA_LOG_FUNC_START(HTTPManager);
+
+       DA_LOG_FUNC_LOGV(HTTPManager);
 
        slot_id = GET_STAGE_DL_ID(stage);
        _disconnect_transaction(stage);
@@ -999,22 +999,34 @@ da_result_t handle_event_http_final(stage_info *stage, q_event_t *event)
        case HTTP_STATE_DOWNLOAD_REQUESTED:
                DA_LOG(HTTPManager, "case HTTP_STATE_DOWNLOAD_REQUESTED");
                CHANGE_HTTP_STATE(HTTP_STATE_DOWNLOAD_FINISH, stage);
+               /* Most of http status is decided when got headers.
+                * But it is ignored for credential url when got headers in case of 401 status code.
+                * So, when the download is finished, it means unauthorized error if the status code has still 401.
+                */
+               received_data = &(event->type.q_event_data_http);
+               http_status = received_data->status_code;
+               if (http_status == 401) {
+                       store_http_status(slot_id, http_status);
+                       ret = DA_ERR_NETWORK_FAIL;
+               }
                break;
 
        case HTTP_STATE_DOWNLOADING:
-               DA_LOG(HTTPManager, "case HTTP_STATE_DOWNLOADING");
+               DA_LOG_VERBOSE(HTTPManager, "case HTTP_STATE_DOWNLOADING");
                ret = file_write_complete(stage);
                if (ret != DA_RESULT_OK) {
                        discard_download(stage);
                        goto ERR;
                }
-               /*                      ret = _check_downloaded_file_size_is_same_with_header_content_size(stage);
-                if(ret != DA_RESULT_OK)
-                {
-                discard_download(stage) ;
-                goto ERR;
-                }
+               /* Sometimes, the server can send "0" byte package data although whole data are not sent.
+                * At that case, the libsoup call finished callback function with 200 Ok.
+                * Only if the DA know content size form response header, it can check the error or not
                 */
+               ret = _check_downloaded_file_size_is_same_with_header_content_size(stage);
+               if(ret != DA_RESULT_OK) {
+                       discard_download(stage) ;
+                       goto ERR;
+               }
                CHANGE_HTTP_STATE(HTTP_STATE_DOWNLOAD_FINISH, stage);
                send_client_update_progress_info(
                                slot_id,
@@ -1026,14 +1038,16 @@ da_result_t handle_event_http_final(stage_info *stage, q_event_t *event)
        case HTTP_STATE_REQUEST_PAUSE:
                if (GET_CONTENT_STORE_FILE_HANDLE(GET_STAGE_CONTENT_STORE_INFO(stage))) {
                        ret = file_write_complete(stage);
+
+                       IS_CONTENT_STORE_FILE_BYTES_WRITTEN_TO_FILE(GET_STAGE_CONTENT_STORE_INFO(stage))
+                                       = DA_FALSE;
+
                        send_client_update_progress_info(
                                        slot_id,
                                        GET_DL_ID(slot_id),
                                        GET_CONTENT_STORE_CURRENT_FILE_SIZE(GET_STAGE_CONTENT_STORE_INFO(stage))
                                        );
 
-                       IS_CONTENT_STORE_FILE_BYTES_WRITTEN_TO_FILE(GET_STAGE_CONTENT_STORE_INFO(stage))
-                                       = DA_FALSE;
                }
                CHANGE_HTTP_STATE(HTTP_STATE_PAUSED,stage);
                CHANGE_DOWNLOAD_STATE(DOWNLOAD_STATE_PAUSED, stage);
@@ -1076,7 +1090,7 @@ da_result_t handle_event_http_abort(stage_info *stage, q_event_t *event)
 {
        da_result_t ret = DA_RESULT_OK;
        http_state_t http_state = 0;
-       DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGD(HTTPManager);
 
        GET_REQUEST_HTTP_RESULT(GET_STAGE_TRANSACTION_INFO(stage))
                = event->type.q_event_data_http.error_type;
@@ -1126,13 +1140,13 @@ da_result_t handle_http_hdr(stage_info *stage,
        int slot_id = DA_INVALID_ID;
        http_state_t http_state = 0;
 
-       DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGV(HTTPManager);
 
        slot_id = GET_STAGE_DL_ID(stage);
 
        _da_thread_mutex_lock(&(GET_REQUEST_HTTP_MUTEX_HTTP_STATE(stage)));
        http_state = GET_HTTP_STATE_ON_STAGE(stage);
-       DA_LOG(HTTPManager, "http_state = %d", http_state);
+       DA_LOG_DEBUG(HTTPManager, "http_state = %d", http_state);
        _da_thread_mutex_unlock(&(GET_REQUEST_HTTP_MUTEX_HTTP_STATE(stage)));
 
        switch (http_state) {
@@ -1168,7 +1182,7 @@ da_result_t handle_http_status_code(stage_info *stage,
        req_dl_info *request_info = DA_NULL;
        http_state_t http_state = 0;
 
-       DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGV(HTTPManager);
 
        slot_id = GET_STAGE_DL_ID(stage);
        request_info = GET_STAGE_TRANSACTION_INFO(stage);
@@ -1178,7 +1192,7 @@ da_result_t handle_http_status_code(stage_info *stage,
 
        _da_thread_mutex_lock(&(GET_REQUEST_HTTP_MUTEX_HTTP_STATE(stage)));
        http_state = GET_HTTP_STATE_ON_STAGE(stage);
-       DA_LOG(HTTPManager, "http_state = %d", http_state);
+       DA_LOG_VERBOSE(HTTPManager, "http_state = %d", http_state);
        _da_thread_mutex_unlock(&(GET_REQUEST_HTTP_MUTEX_HTTP_STATE(stage)));
 
        store_http_status(slot_id, http_status);
@@ -1241,6 +1255,7 @@ da_result_t handle_http_status_code(stage_info *stage,
                        goto ERR;
                CHANGE_HTTP_STATE(HTTP_STATE_REDIRECTED,stage);
                http_msg_response_destroy(&http_msg_response);
+               request_info->http_info.http_msg_response = DA_NULL;
                break;
 
        case 100:
@@ -1272,10 +1287,10 @@ da_result_t exchange_url_from_header_for_redirection(stage_info *stage,
        da_result_t ret = DA_RESULT_OK;
        char *location = DA_NULL;
 
-       DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGD(HTTPManager);
 
        if (http_msg_response_get_location(http_msg_response, &location)) {
-               DA_LOG(HTTPManager, "location  = %s\n", location);
+               DA_SECURE_LOGD("location  = %s\n", location);
                GET_REQUEST_HTTP_REQ_LOCATION(GET_STAGE_TRANSACTION_INFO(stage)) = location;
        }
 
@@ -1288,7 +1303,7 @@ da_result_t handle_http_body(stage_info *stage, char *body, int body_len)
        http_state_t http_state = 0;
        int slot_id = DA_INVALID_ID;
 
-       //      DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGV(HTTPManager);
 
        slot_id = GET_STAGE_DL_ID(stage);
 
@@ -1301,7 +1316,6 @@ da_result_t handle_http_body(stage_info *stage, char *body, int body_len)
 
        _da_thread_mutex_lock(&(GET_REQUEST_HTTP_MUTEX_HTTP_STATE(stage)));
        http_state = GET_HTTP_STATE_ON_STAGE(stage);
-       //      DA_LOG(HTTPManager, "http_state = %d", http_state);
        _da_thread_mutex_unlock(&(GET_REQUEST_HTTP_MUTEX_HTTP_STATE(stage)));
 
        if (http_state == HTTP_STATE_DOWNLOAD_STARTED) {
@@ -1344,7 +1358,6 @@ da_result_t handle_http_body(stage_info *stage, char *body, int body_len)
 
        _da_thread_mutex_lock(&(GET_REQUEST_HTTP_MUTEX_HTTP_STATE(stage)));
        http_state = GET_HTTP_STATE_ON_STAGE(stage);
-       //      DA_LOG(HTTPManager, "http_state = %d", http_state);
        _da_thread_mutex_unlock(&(GET_REQUEST_HTTP_MUTEX_HTTP_STATE(stage)));
 
        switch (http_state) {
@@ -1360,14 +1373,15 @@ da_result_t handle_http_body(stage_info *stage, char *body, int body_len)
                        goto ERR;
                if ((DA_TRUE ==
                                IS_CONTENT_STORE_FILE_BYTES_WRITTEN_TO_FILE(GET_STAGE_CONTENT_STORE_INFO(stage)))) {
+
+                       IS_CONTENT_STORE_FILE_BYTES_WRITTEN_TO_FILE(GET_STAGE_CONTENT_STORE_INFO(stage))
+                                       = DA_FALSE;
                        send_client_update_progress_info(
                                        slot_id,
                                        GET_DL_ID(slot_id),
                                        GET_CONTENT_STORE_CURRENT_FILE_SIZE(GET_STAGE_CONTENT_STORE_INFO(stage))
                                        );
 
-                       IS_CONTENT_STORE_FILE_BYTES_WRITTEN_TO_FILE(GET_STAGE_CONTENT_STORE_INFO(stage))
-                                       = DA_FALSE;
                }
                break;
 
@@ -1399,7 +1413,7 @@ da_result_t set_hdr_fields_on_download_info(stage_info *stage)
        char *value = NULL;
        unsigned long long size = 0;
 
-       DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGV(HTTPManager);
 
        request_info = GET_STAGE_TRANSACTION_INFO(stage);
 
@@ -1415,7 +1429,7 @@ da_result_t set_hdr_fields_on_download_info(stage_info *stage)
        if (b_ret) {
                GET_REQUEST_HTTP_HDR_CONT_TYPE(request_info) = value;
                value = NULL;
-               DA_LOG_VERBOSE(HTTPManager, "[Content-Type][%s] - stored", GET_REQUEST_HTTP_HDR_CONT_TYPE(request_info));
+//             DA_SECURE_LOGD("[Content-Type][%s] - stored", GET_REQUEST_HTTP_HDR_CONT_TYPE(request_info));
        }
 
        b_ret = http_msg_response_get_content_length(http_msg_response,
@@ -1423,14 +1437,13 @@ da_result_t set_hdr_fields_on_download_info(stage_info *stage)
        if (b_ret) {
                GET_REQUEST_HTTP_HDR_CONT_LEN(request_info) = size;
                size = 0;
-               DA_LOG_VERBOSE(HTTPManager, "[Content-Length][%d] - stored", GET_REQUEST_HTTP_HDR_CONT_LEN(request_info));
        }
 
        b_ret = http_msg_response_get_ETag(http_msg_response, &value);
        if (b_ret) {
                GET_REQUEST_HTTP_HDR_ETAG(request_info) = value;
                value = NULL;
-               DA_LOG_VERBOSE(HTTPManager, "[ETag][%s] - stored ", GET_REQUEST_HTTP_HDR_ETAG(request_info));
+               DA_SECURE_LOGD("[ETag][%s] - stored ", GET_REQUEST_HTTP_HDR_ETAG(request_info));
        }
 
 ERR:
@@ -1444,7 +1457,7 @@ da_result_t _check_content_type_is_matched(stage_info *stage)
        source_info_t *source_info = DA_NULL;
        char *content_type_from_server = DA_NULL;
 
-       DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGV(HTTPManager);
 
        request_info = GET_STAGE_TRANSACTION_INFO(stage);
        source_info = GET_STAGE_SOURCE_INFO(stage);
@@ -1464,22 +1477,23 @@ da_result_t _check_enough_memory_for_this_download(stage_info *stage)
 
        req_dl_info *request_info = DA_NULL;
 
-       long long cont_len = 0;
+       unsigned long long cont_len = 0;
        da_storage_size_t memory;
 
-       DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGV(HTTPManager);
 
        memset(&memory, 0x00, sizeof(da_storage_size_t));
        request_info = GET_STAGE_TRANSACTION_INFO(stage);
 
-       cont_len = (long long) GET_REQUEST_HTTP_HDR_CONT_LEN(request_info);
+       cont_len = (unsigned long long) GET_REQUEST_HTTP_HDR_CONT_LEN(request_info);
        if (cont_len) {
-               ret = get_available_memory(DA_STORAGE_PHONE, &memory);
+               ret = get_available_memory(&memory);
                if (DA_RESULT_OK == ret) {
-                       DA_LOG(HTTPManager, "Memory avail: %lu, Memory block :%lu Content: %llu",memory.b_available,memory.b_size, cont_len);
+                       DA_LOG(HTTPManager, "Memory avail: %lu, Memory block :%lu Content: %llu",
+                                       memory.b_available,memory.b_size, cont_len);
                        if (memory.b_available < ((cont_len
-                                       + SAVE_FILE_BUFFERING_SIZE_50KB)
-                                       / memory.b_size)) /* 50KB buffering */
+                                       + (unsigned long long)SAVE_FILE_BUFFERING_SIZE_50KB)
+                                       / (unsigned long long)memory.b_size)) /* 50KB buffering */
                        {
                                ret = DA_ERR_DISK_FULL;
                                goto ERR;
@@ -1503,7 +1517,7 @@ da_result_t _check_this_partial_download_is_available(stage_info *stage,
        char *value = NULL;
        unsigned long long size = 0;
 
-       DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGD(HTTPManager);
 
        origin_ETag
                        = GET_REQUEST_HTTP_HDR_ETAG(GET_STAGE_TRANSACTION_INFO(stage));
@@ -1520,7 +1534,7 @@ da_result_t _check_this_partial_download_is_available(stage_info *stage,
        if (b_ret) {
                new_ETag = value;
                value = NULL;
-               DA_LOG(HTTPManager, "[new ETag][%s]", new_ETag);
+               DA_SECURE_LOGD("[new ETag][%s]", new_ETag);
        } else {
                goto ERR;
        }
@@ -1535,7 +1549,7 @@ da_result_t _check_this_partial_download_is_available(stage_info *stage,
        }
 
        if (remained_content_len) {
-               ret = get_available_memory(DA_STORAGE_PHONE, &memory);
+               ret = get_available_memory(&memory);
                if (DA_RESULT_OK == ret) {
                        DA_LOG(HTTPManager, "Memory avail: %lu, Memory block :%lu Content: %llu",
                                        memory.b_available,memory.b_size, remained_content_len);
@@ -1572,7 +1586,7 @@ da_result_t _check_resume_download_is_available(stage_info *stage,
        char *temp_file_path = DA_NULL;
        req_dl_info *request_info = DA_NULL;
 
-       DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGD(HTTPManager);
 
        request_info = GET_STAGE_TRANSACTION_INFO(stage);
        origin_ETag
@@ -1590,7 +1604,7 @@ da_result_t _check_resume_download_is_available(stage_info *stage,
        if (b_ret) {
                new_ETag = value;
                value = NULL;
-               DA_LOG(HTTPManager, "[new ETag][%s]", new_ETag);
+               DA_SECURE_LOGD("[new ETag][%s]", new_ETag);
        } else {
                goto ERR;
        }
@@ -1605,7 +1619,7 @@ da_result_t _check_resume_download_is_available(stage_info *stage,
        }
 
        if (remained_content_len) {
-               ret = get_available_memory(DA_STORAGE_PHONE, &memory);
+               ret = get_available_memory(&memory);
                if (DA_RESULT_OK == ret) {
                        DA_LOG(HTTPManager, "Memory avail: %lu, Memory block :%lu Content: %llu",
                                        memory.b_available,memory.b_size, remained_content_len);
@@ -1622,13 +1636,13 @@ da_result_t _check_resume_download_is_available(stage_info *stage,
        if (b_ret) {
                GET_REQUEST_HTTP_HDR_CONT_TYPE(request_info) = value;
                value = NULL;
-               DA_LOG(HTTPManager, "[Content-Type][%s]",
+               DA_SECURE_LOGD("[Content-Type][%s]",
                                GET_REQUEST_HTTP_HDR_CONT_TYPE(request_info));
        }
        temp_file_path = GET_REQUEST_HTTP_USER_REQUEST_TEMP_FILE_PATH(request_info);
        get_file_size(temp_file_path, &size);
        GET_REQUEST_HTTP_HDR_CONT_LEN(request_info) =   remained_content_len + size;
-       DA_LOG(HTTPManager, "[Content-Length][%d]",
+       DA_SECURE_LOGD("[Content-Length][%llu]",
                        GET_REQUEST_HTTP_HDR_CONT_LEN(request_info));
 
 
@@ -1654,7 +1668,7 @@ da_result_t _check_downloaded_file_size_is_same_with_header_content_size(
        unsigned long long content_size_from_real_file = 0;
        unsigned long long content_size_from_http_header = 0;
 
-       DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGD(HTTPManager);
 
        request_info = GET_STAGE_TRANSACTION_INFO(stage);
        file_info_data = GET_STAGE_CONTENT_STORE_INFO(stage);
@@ -1671,7 +1685,8 @@ da_result_t _check_downloaded_file_size_is_same_with_header_content_size(
 
                if (content_size_from_real_file
                                != content_size_from_http_header) {
-                       DA_LOG_ERR(HTTPManager, "size from header = %llu, real size = %llu, DA_ERR_MISMATCH_CONTENT_SIZE",
+                       DA_SECURE_LOGE("size from header = %llu, real size = %llu,\
+                                       DA_ERR_MISMATCH_CONTENT_SIZE",
                                        content_size_from_http_header, content_size_from_real_file);
                        ret = DA_ERR_MISMATCH_CONTENT_SIZE;
                }
@@ -1685,7 +1700,7 @@ da_result_t _disconnect_transaction(stage_info *stage)
        da_result_t ret = DA_RESULT_OK;
        int transaction_id = DA_INVALID_ID;
 
-       DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGV(HTTPManager);
 
        transaction_id
                        = GET_REQUEST_HTTP_TRANS_ID(GET_STAGE_TRANSACTION_INFO(stage));
@@ -1706,7 +1721,7 @@ da_result_t _cancel_transaction(stage_info *stage)
        da_result_t ret = DA_RESULT_OK;
        int transaction_id = DA_INVALID_ID;
 
-       DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGD(HTTPManager);
 
        transaction_id
                        = GET_REQUEST_HTTP_TRANS_ID(GET_STAGE_TRANSACTION_INFO(stage));
@@ -1717,13 +1732,15 @@ da_result_t _cancel_transaction(stage_info *stage)
                http_state_t state = 0;
                _da_thread_mutex_lock(&(GET_REQUEST_HTTP_MUTEX_HTTP_STATE(stage)));
                state = GET_HTTP_STATE_ON_STAGE(stage);
-               if (state <= HTTP_STATE_DOWNLOAD_REQUESTED)
+               if (state <= HTTP_STATE_DOWNLOAD_REQUESTED) {
+                       _da_thread_mutex_unlock(&(GET_REQUEST_HTTP_MUTEX_HTTP_STATE(stage)));
                        ret = PI_http_cancel_transaction(transaction_id, DA_TRUE);
-               else
+               } else {
+                       _da_thread_mutex_unlock(&(GET_REQUEST_HTTP_MUTEX_HTTP_STATE(stage)));
                        ret = PI_http_cancel_transaction(transaction_id, DA_FALSE);
-               _da_thread_mutex_unlock(&(GET_REQUEST_HTTP_MUTEX_HTTP_STATE(stage)));
-       }
+               }
 
+       }
        return ret;
 }
 
@@ -1736,7 +1753,7 @@ void __parsing_user_request_header(char *user_request_header,
        char *field = NULL;
        char *value = NULL;
 
-       DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGV(HTTPManager);
 
        if (!user_request_header) {
                DA_LOG_ERR(HTTPManager, "user_request_header is NULL");
@@ -1783,7 +1800,7 @@ void __parsing_user_request_header(char *user_request_header,
        strncpy(value, pos, len);
        *out_field = field;
        *out_value = value;
-       DA_LOG(HTTPManager, "field[%s], value[%s]", field, value);
+       DA_SECURE_LOGD("field[%s], value[%s]", field, value);
 
        return;
 ERR:
index 67483b0..08cd8ec 100755 (executable)
@@ -29,7 +29,7 @@ char *get_user_agent()
 {
        char *uagent_str = DA_NULL;
 
-       DA_LOG_FUNC_START(Default);
+       DA_LOG_FUNC_LOGV(Default);
 
        uagent_str = get_client_user_agent_string();
        if (!uagent_str) {
index 05a0a68..6064c37 100755 (executable)
@@ -57,7 +57,7 @@ da_result_t http_msg_request_create(http_msg_request_t **http_msg_request)
 {
        http_msg_request_t *temp_http_msg_request = NULL;
 
-       DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGV(HTTPManager);
 
        temp_http_msg_request = (http_msg_request_t *)calloc(1,
                sizeof(http_msg_request_t));
@@ -73,7 +73,7 @@ da_result_t http_msg_request_create(http_msg_request_t **http_msg_request)
        temp_http_msg_request->http_body = NULL;
 
        *http_msg_request = temp_http_msg_request;
-       DA_LOG(HTTPManager, "http_msg_request: %x", (unsigned int)(*http_msg_request));
+       DA_LOG_DEBUG(HTTPManager, "http_msg_request: %x", (unsigned int)(*http_msg_request));
 
        return DA_RESULT_OK;
 }
@@ -82,7 +82,7 @@ void http_msg_request_destroy(http_msg_request_t **http_msg_request)
 {
        http_msg_request_t *temp_http_msg_request = *http_msg_request;
 
-       DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGV(HTTPManager);
 
        if (temp_http_msg_request) {
                if (temp_http_msg_request->http_method) {
@@ -111,7 +111,7 @@ void http_msg_request_destroy(http_msg_request_t **http_msg_request)
 da_result_t http_msg_request_set_method(http_msg_request_t *http_msg_request,
        const char *method)
 {
-       DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGD(HTTPManager);
 
        if (!http_msg_request || !method) {
                DA_LOG_ERR(HTTPManager, "DA_ERR_INVALID_ARGUMENT");
@@ -130,7 +130,7 @@ da_result_t http_msg_request_set_method(http_msg_request_t *http_msg_request,
 da_result_t http_msg_request_get_method(http_msg_request_t *http_msg_request,
        const char **method)
 {
-       //      DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGV(HTTPManager);
 
        if (!http_msg_request) {
                DA_LOG_ERR(HTTPManager, "DA_ERR_INVALID_ARGUMENT");
@@ -149,7 +149,7 @@ da_result_t http_msg_request_get_method(http_msg_request_t *http_msg_request,
 da_result_t http_msg_request_set_url(http_msg_request_t *http_msg_request,
        const char *url)
 {
-       DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGV(HTTPManager);
 
        if (!http_msg_request) {
                DA_LOG_ERR(HTTPManager, "http_msg_request is NULL; DA_ERR_INVALID_ARGUMENT");
@@ -163,7 +163,7 @@ da_result_t http_msg_request_set_url(http_msg_request_t *http_msg_request,
 
        http_msg_request->url = strdup(url);
 
-       DA_LOG(HTTPManager, "http url : %s", http_msg_request->url);
+       //DA_SECURE_LOGD("http url : %s", http_msg_request->url);
 
        return DA_RESULT_OK;
 }
@@ -171,7 +171,7 @@ da_result_t http_msg_request_set_url(http_msg_request_t *http_msg_request,
 da_result_t http_msg_request_get_url(http_msg_request_t *http_msg_request,
        const char **url)
 {
-       //      DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGV(HTTPManager);
 
        if (!http_msg_request) {
                DA_LOG_ERR(HTTPManager, "http_msg_request is NULL; DA_ERR_INVALID_ARGUMENT");
@@ -190,7 +190,7 @@ da_result_t http_msg_request_get_url(http_msg_request_t *http_msg_request,
 da_result_t http_msg_request_set_body(http_msg_request_t *http_msg_request,
        const char *body)
 {
-       //      DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGV(HTTPManager);
 
        if (!http_msg_request) {
                DA_LOG_ERR(HTTPManager, "DA_ERR_INVALID_ARGUMENT");
@@ -202,7 +202,7 @@ da_result_t http_msg_request_set_body(http_msg_request_t *http_msg_request,
 
        http_msg_request->http_body = strdup(body);
 
-       DA_LOG(HTTPManager, "http body : %s", http_msg_request->http_body);
+       DA_SECURE_LOGD("http body : %s", http_msg_request->http_body);
 
        return DA_RESULT_OK;
 }
@@ -210,7 +210,7 @@ da_result_t http_msg_request_set_body(http_msg_request_t *http_msg_request,
 da_result_t http_msg_request_get_body(http_msg_request_t *http_msg_request,
        const char **body)
 {
-       //      DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGV(HTTPManager);
 
        if (!http_msg_request) {
                DA_LOG_ERR(HTTPManager, "DA_ERR_INVALID_ARGUMENT");
@@ -230,7 +230,7 @@ da_result_t http_msg_request_get_body(http_msg_request_t *http_msg_request,
 da_result_t http_msg_request_add_field(http_msg_request_t *http_msg_request,
        const char *field, const char *value)
 {
-       //      DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGV(HTTPManager);
 
        if (!http_msg_request) {
                DA_LOG_ERR(HTTPManager, "DA_ERR_INVALID_ARGUMENT");
@@ -244,7 +244,7 @@ da_result_t http_msg_response_create(http_msg_response_t **http_msg_response)
 {
        http_msg_response_t *temp_http_msg_response = NULL;
 
-       DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGV(HTTPManager);
 
        temp_http_msg_response = (http_msg_response_t *)calloc(1,
                sizeof(http_msg_response_t));
@@ -265,7 +265,7 @@ void http_msg_response_destroy(http_msg_response_t **http_msg_response)
 {
        http_msg_response_t *temp_http_msg_response = *http_msg_response;
 
-       DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGV(HTTPManager);
        if (temp_http_msg_response) {
                __http_header_destroy_all_field(&(temp_http_msg_response->head));
 
@@ -277,7 +277,7 @@ void http_msg_response_destroy(http_msg_response_t **http_msg_response)
 da_result_t http_msg_response_set_status_code(
        http_msg_response_t *http_msg_response, int status_code)
 {
-       //      DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGV(HTTPManager);
 
        if (!http_msg_response) {
                DA_LOG_ERR(HTTPManager, "DA_ERR_INVALID_ARGUMENT");
@@ -292,7 +292,7 @@ da_result_t http_msg_response_set_status_code(
 da_result_t http_msg_response_get_status_code(
        http_msg_response_t *http_msg_response, int *status_code)
 {
-       DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGD(HTTPManager);
 
        if (!http_msg_response) {
                DA_LOG_ERR(HTTPManager, "DA_ERR_INVALID_ARGUMENT");
@@ -307,7 +307,7 @@ da_result_t http_msg_response_get_status_code(
 da_result_t http_msg_response_add_field(http_msg_response_t *http_msg_response,
        const char *field, const char *value)
 {
-       //      DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGV(HTTPManager);
 
        if (!http_msg_response) {
                DA_LOG_ERR(HTTPManager, "DA_ERR_INVALID_ARGUMENT");
@@ -323,8 +323,7 @@ da_result_t __http_header_add_field(http_header_t **head,
        http_header_t *pre = NULL;
        http_header_t *cur = NULL;
 
-       //      DA_LOG_FUNC_START(HTTPManager);
-       DA_LOG(HTTPManager, "[%s][%s]", field, value);
+       //DA_SECURE_LOGD("[%s][%s]", field, value);
 
        pre = cur = *head;
        while (cur) {
@@ -333,8 +332,8 @@ da_result_t __http_header_add_field(http_header_t **head,
                 * Remove the value which is stored before and add a new value.
                */
                if (cur->field && cur->raw_value &&
-                               strncmp(cur->field, field, strlen(field)) == 0) {
-                       DA_LOG(HTTPManager, "Remove value for replacement [%s][%s]", cur->field, cur->raw_value);
+                               strncasecmp(cur->field, field, strlen(field)) == 0) {
+                       DA_SECURE_LOGD("Remove value for replacement [%s][%s]", cur->field, cur->raw_value);
                        if (cur->field) {
                                free(cur->field);
                                cur->field = NULL;
@@ -378,13 +377,12 @@ void __http_header_destroy_all_field(http_header_t **head)
        http_header_t *pre = NULL;
        http_header_t *cur = NULL;
 
-       //      DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGV(HTTPManager);
 
        cur = *head;
 
        while (cur) {
                if (cur->field) {
-                       DA_LOG_VERBOSE(HTTPManager, "field= %s", cur->field);
                        free(cur->field);
                        cur->field = DA_NULL;
                }
@@ -435,13 +433,13 @@ void __http_header_destroy_all_option(http_header_options_t **head)
        http_header_options_t *pre = NULL;
        http_header_options_t *cur = NULL;
 
-       //      DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGV(HTTPManager);
 
        cur = *head;
 
        while (cur) {
                if (cur->field) {
-                       DA_LOG_VERBOSE(HTTPManager, "field= %s", cur->field);
+                       DA_LOG_VERBOSE("field= %s", cur->field);
                        free(cur->field);
                        cur->field = DA_NULL;
                }
@@ -463,7 +461,7 @@ void __http_header_destroy_all_option(http_header_options_t **head)
 da_result_t http_msg_request_get_iter(http_msg_request_t *http_msg_request,
        http_msg_iter_t *http_msg_iter)
 {
-       DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGV(HTTPManager);
 
        if (!http_msg_request) {
                DA_LOG_ERR(HTTPManager, "DA_ERR_INVALID_ARGUMENT");
@@ -478,15 +476,13 @@ da_result_t http_msg_request_get_iter(http_msg_request_t *http_msg_request,
 da_result_t http_msg_response_get_iter(http_msg_response_t *http_msg_response,
        http_msg_iter_t *http_msg_iter)
 {
-       //      DA_LOG_FUNC_START(HTTPManager);
-
        if (!http_msg_response) {
                DA_LOG_ERR(HTTPManager, "DA_ERR_INVALID_ARGUMENT");
                return DA_ERR_INVALID_ARGUMENT;
        }
 
        *http_msg_iter = http_msg_response->head;
-       //      DA_LOG(HTTPManager, "retrieve iter = 0x%x", (unsigned int)http_msg_iter);
+       //      DA_LOG_VERBOSE(HTTPManager, "retrieve iter = 0x%x", (unsigned int)http_msg_iter);
 
        return DA_RESULT_OK;
 }
@@ -496,9 +492,7 @@ da_bool_t http_msg_get_field_with_iter(http_msg_iter_t *http_msg_iter,
 {
        http_header_t *cur = *http_msg_iter;
 
-       //      DA_LOG_FUNC_START(HTTPManager);
-
-       //      DA_LOG(HTTPManager, "getting iter = 0x%x", (unsigned int)cur);
+       //      DA_LOG_VERBOSE(HTTPManager, "getting iter = 0x%x", (unsigned int)cur);
 
        if (cur) {
                *out_field = cur->field;
@@ -507,7 +501,7 @@ da_bool_t http_msg_get_field_with_iter(http_msg_iter_t *http_msg_iter,
 
                return DA_TRUE;
        } else {
-               //              DA_LOG(HTTPManager, "end of iter");
+               //      DA_LOG_VERBOSE(HTTPManager, "end of iter");
                return DA_FALSE;
        }
 }
@@ -517,9 +511,7 @@ da_bool_t http_msg_get_header_with_iter(http_msg_iter_t *http_msg_iter,
 {
        http_header_t *cur = *http_msg_iter;
 
-       //      DA_LOG_FUNC_START(HTTPManager);
-
-       //      DA_LOG(HTTPManager, "getting iter = 0x%x", (unsigned int)cur);
+       //      DA_LOG_VERBOSE(HTTPManager, "getting iter = 0x%x", (unsigned int)cur);
 
        if (cur) {
                *out_field = cur->field;
@@ -528,7 +520,7 @@ da_bool_t http_msg_get_header_with_iter(http_msg_iter_t *http_msg_iter,
 
                return DA_TRUE;
        } else {
-               //              DA_LOG(HTTPManager, "end of iter");
+               //      DA_LOG_VERBOSE(HTTPManager, "end of iter");
                return DA_FALSE;
        }
 }
@@ -553,7 +545,7 @@ http_header_options_t *__parsing_N_create_option_str(char *org_str)
        int i = 0;
        http_header_options_t *option = NULL;
 
-       //      DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGV(HTTPManager);
 
        if (!org_str)
                return NULL;
@@ -619,8 +611,8 @@ http_header_options_t *__parsing_N_create_option_str(char *org_str)
                working_pos = working_str = NULL;
        }
 
-       DA_LOG(HTTPManager, "option_field = [%s], option_value = [%s]",
-               option_field, option_value);
+//     DA_SECURE_LOGD("option_field = [%s], option_value = [%s]",
+//             option_field, option_value);
 
        if (option_field || option_value) {
                option = __create_http_header_option(
@@ -651,13 +643,13 @@ http_header_options_t *__parsing_options(char *org_str)
        char *wanted_str_end = NULL;
        char *cur_pos = NULL;
 
-       DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGV(HTTPManager);
 
        if (!org_str)
                return NULL;
 
        /* Do Not use strtok(). It's not thread safe. */
-       //      DA_LOG_CRITICAL(HTTPManager, "org_str = %s", org_str);
+       //      DA_SECURE_LOGD("org_str = %s", org_str);
 
        cur_pos = org_str;
 
@@ -680,7 +672,7 @@ http_header_options_t *__parsing_options(char *org_str)
                }
                strncpy(wanted_str, wanted_str_start, wanted_str_len);
 
-               //              DA_LOG_CRITICAL(HTTPManager, "wanted_str = [%s]", wanted_str);
+               //              DA_SECURE_LOGD("wanted_str = [%s]", wanted_str);
                cur = __parsing_N_create_option_str(wanted_str);
                if (pre) {
                        pre->next = cur;
@@ -711,10 +703,8 @@ void __parsing_raw_value(http_header_t *http_header_field)
        char *trimed_value_start = NULL;
        char *trimed_value_end = NULL;
 
-       //      DA_LOG_FUNC_START(HTTPManager);
-
        raw_value = http_header_field->raw_value;
-       //      DA_LOG_CRITICAL(HTTPManager, "raw_value = [%s]", raw_value);
+       //      DA_SECURE_LOGD("raw_value = [%s]", raw_value);
 
        if (!raw_value)
                return;
@@ -751,7 +741,7 @@ void __parsing_raw_value(http_header_t *http_header_field)
 
        cur = http_header_field->options;
        while (cur) {
-               DA_LOG(HTTPManager, "field = [%s], value = [%s]", cur->field, cur->value);
+//             DA_SECURE_LOGD("field = [%s], value = [%s]", cur->field, cur->value);
                cur = cur->next;
        }
 
@@ -763,7 +753,7 @@ da_bool_t __get_http_header_option_for_field(
 {
        http_header_options_t *cur = NULL;
 
-       //      DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGV(HTTPManager);
 
        if (!header_option) {
                DA_LOG_ERR(HTTPManager, "input header_option is NULL.");
@@ -773,9 +763,9 @@ da_bool_t __get_http_header_option_for_field(
        cur = header_option;
        while (cur) {
                if (cur->field) {
-                       if (!strncmp(cur->field, in_field, strlen(cur->field)) &&
+                       if (!strncasecmp(cur->field, in_field, strlen(cur->field)) &&
                                        cur->value) {
-                               DA_LOG(HTTPManager, "[%s][%s]", cur->field, cur->value);
+                               DA_SECURE_LOGD("[%s][%s]", cur->field, cur->value);
                                *out_value = cur->value;
                                return DA_TRUE;
                        }
@@ -794,12 +784,12 @@ da_bool_t __get_http_header_for_field(http_msg_response_t *http_msg_response,
        http_header_t *header = NULL;
        char *field = NULL;
 
-       //DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGV(HTTPManager);
 
        http_msg_response_get_iter(http_msg_response, &http_msg_iter);
        while (http_msg_get_header_with_iter(&http_msg_iter, &field, &header)) {
-               if (field && header && !strncmp(field, in_field, strlen(field))) {
-                       DA_LOG_VERBOSE(HTTPManager, "[%s][%s]", field, header->value);
+               if (field && header && !strncasecmp(field, in_field, strlen(field))) {
+//                     DA_SECURE_LOGD("[%s][%s]", field, header->value);
                        *out_header = header;
                        return DA_TRUE;
                }
@@ -810,7 +800,7 @@ da_bool_t __get_http_header_for_field(http_msg_response_t *http_msg_response,
 
 void __exchange_header_value(http_header_t *header, const char *in_raw_value)
 {
-       DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGV(HTTPManager);
 
        if (!header || !in_raw_value)
                return;
@@ -835,7 +825,7 @@ da_bool_t http_msg_response_get_content_type(
        da_bool_t b_ret = DA_FALSE;
        http_header_t *header = NULL;
 
-       DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGV(HTTPManager);
 
        b_ret = __get_http_header_for_field(http_msg_response, "Content-Type",
                &header);
@@ -856,7 +846,7 @@ void http_msg_response_set_content_type(http_msg_response_t *http_msg_response,
        da_bool_t b_ret = DA_FALSE;
        http_header_t *header = NULL;
 
-       DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGV(HTTPManager);
 
        if (!http_msg_response || !in_type)
                return;
@@ -868,7 +858,7 @@ void http_msg_response_set_content_type(http_msg_response_t *http_msg_response,
                        strlen(header->raw_value))))
                        return;
 
-               DA_LOG(HTTPManager, "exchange Content-Type to [%s] from [%s]", in_type, header->value);
+               DA_SECURE_LOGD("exchange Content-Type to [%s] from [%s]", in_type, header->value);
                __exchange_header_value(header, in_type);
        } else {
                __http_header_add_field(&(http_msg_response->head),
@@ -882,7 +872,7 @@ da_bool_t http_msg_response_get_content_length(
        da_bool_t b_ret = DA_FALSE;
        http_header_t *header = NULL;
 
-       DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGV(HTTPManager);
 
        b_ret = __get_http_header_for_field(http_msg_response,
                "Content-Length", &header);
@@ -911,12 +901,12 @@ da_bool_t http_msg_response_get_content_disposition(
        char *decoded_str = NULL;
        int wanted_str_len = 0;
 
-       DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGV(HTTPManager);
 
        b_ret = __get_http_header_for_field(http_msg_response,
                "Content-Disposition", &header);
        if (!b_ret) {
-               DA_LOG(HTTPManager, "no Content-Disposition");
+               DA_LOG_VERBOSE(HTTPManager, "no Content-Disposition");
                return DA_FALSE;
        }
 
@@ -939,7 +929,7 @@ da_bool_t http_msg_response_get_content_disposition(
                *out_file_name = strdup(file_name);
                return DA_TRUE;
        } else {
-               //              DA_LOG(HTTPManager, "wanted_str_start = [%s]", wanted_str_start);
+               //              DA_SECURE_LOGD("wanted_str_start = [%s]", wanted_str_start);
                wanted_str_start++;
                wanted_str_end = strchr(wanted_str_start, '"');
                if (wanted_str_end) {
@@ -956,7 +946,7 @@ da_bool_t http_msg_response_get_content_disposition(
                                DA_LOG(HTTPManager, "It's base64 encoded-word string");
                                if (DA_RESULT_OK == decode_base64_encoded_str(
                                        wanted_str, &decoded_str)) {
-                                       DA_LOG(HTTPManager, "base64 decoded str = [%s]", decoded_str);
+                                       DA_SECURE_LOGD("base64 decoded str = [%s]", decoded_str);
                                        free(wanted_str);
                                        wanted_str = decoded_str;
                                        decoded_str = NULL;
@@ -969,7 +959,7 @@ da_bool_t http_msg_response_get_content_disposition(
                        decode_url_encoded_str(wanted_str, &decoded_str);
                        /* If it is url encoded string */
                        if (decoded_str) {
-                               DA_LOG(HTTPManager, "Url decoded str = [%s]", decoded_str);
+                               DA_SECURE_LOGD("Url decoded str = [%s]", decoded_str);
                                free(wanted_str);
                                wanted_str = decoded_str;
                                decoded_str = NULL;
@@ -977,7 +967,7 @@ da_bool_t http_msg_response_get_content_disposition(
 
                        *out_file_name = wanted_str;
 
-                       DA_LOG(HTTPManager, "out_file_name = [%s]", *out_file_name);
+                       DA_SECURE_LOGD("out_file_name = [%s]", *out_file_name);
 
                        return DA_TRUE;
                } else {
@@ -993,11 +983,11 @@ da_bool_t http_msg_response_get_ETag(http_msg_response_t *http_msg_response,
        da_bool_t b_ret = DA_FALSE;
        http_header_t *header = NULL;
 
-       DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGV(HTTPManager);
 
        b_ret = __get_http_header_for_field(http_msg_response, "ETag", &header);
        if (!b_ret) {
-               DA_LOG(HTTPManager, "no ETag");
+               DA_LOG_VERBOSE(HTTPManager, "no ETag");
                return DA_FALSE;
        }
 
@@ -1013,7 +1003,7 @@ da_bool_t http_msg_response_get_date(http_msg_response_t *http_msg_response,
        da_bool_t b_ret = DA_FALSE;
        http_header_t *header = NULL;
 
-       DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGV(HTTPManager);
 
        b_ret = __get_http_header_for_field(http_msg_response, "Date", &header);
        if (!b_ret) {
@@ -1033,7 +1023,7 @@ da_bool_t http_msg_response_get_location(http_msg_response_t *http_msg_response,
        da_bool_t b_ret = DA_FALSE;
        http_header_t *header = NULL;
 
-       DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGV(HTTPManager);
 
        b_ret = __get_http_header_for_field(http_msg_response, "Location", &header);
        if (!b_ret) {
@@ -1056,7 +1046,7 @@ da_result_t http_msg_response_get_boundary(
        char *value = NULL;
        char *boundary = NULL;
 
-       DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGV(HTTPManager);
 
        if (!http_msg_response) {
                DA_LOG_ERR(HTTPManager, "DA_ERR_INVALID_ARGUMENT");
@@ -1066,7 +1056,7 @@ da_result_t http_msg_response_get_boundary(
        http_msg_response_get_iter(http_msg_response, &http_msg_iter);
        while (http_msg_get_field_with_iter(&http_msg_iter, &field, &value)) {
                if ((field != DA_NULL) && (value != DA_NULL)) {
-                       if (!strncmp(field, "Content-Type",
+                       if (!strncasecmp(field, "Content-Type",
                                strlen("Content-Type"))) {
                                char *org_str = NULL;
                                char *boundary_str_start = NULL;
@@ -1111,7 +1101,7 @@ da_result_t http_msg_response_get_boundary(
                                }
                                strncpy(boundary, boundary_value_start,
                                        boundary_value_len);
-                               DA_LOG(HTTPManager, "[boundary][%s]", boundary);
+                               DA_SECURE_LOGD("[boundary][%s]", boundary);
                                break;
                        }
                }
@@ -1133,7 +1123,7 @@ char *get_http_response_header_raw(http_msg_response_t *http_msg_response)
        int len = 0;
        char *buff = NULL;
 
-       DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGV(HTTPManager);
 
        http_msg_response_get_iter(http_msg_response, &http_msg_iter);
        while (http_msg_get_header_with_iter(&http_msg_iter, &field, &header)) {
@@ -1152,7 +1142,7 @@ char *get_http_response_header_raw(http_msg_response_t *http_msg_response)
                        return DA_NULL;
                }
                memcpy(buff, tmp_buf, strlen(tmp_buf));
-               DA_LOG(HTTPManager, "\n---raw response header---\n%s\n------\n",buff);
+               DA_SECURE_LOGD("\n---raw response header---\n%s\n------\n",buff);
                return buff;
        } else {
                return DA_NULL;
@@ -1297,7 +1287,7 @@ da_bool_t extract_attribute_from_header(
        startPos = index;
 
        /* Find the end of data. */
-       if (0 == strcmp(szFindStr, "Location"))//terminate character list does not contain ';' in case of URI
+       if (0 == strncasecmp(szFindStr, "Location", strlen("Location")))//terminate character list does not contain ';' in case of URI
        {
                while (DA_FALSE == IS_URI_TERMINATING_CHAR(pValuePos[index])) {
                        index++;
index b81f9d8..06fe084 100755 (executable)
@@ -37,7 +37,7 @@ void Q_destroy_queue(queue_t *queue)
 {
        q_event_t *event = DA_NULL;
 
-       DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGV(HTTPManager);
 
        do {
                Q_pop_event(queue, &event);
@@ -80,8 +80,6 @@ void Q_destroy_q_event(q_event_t **in_q_event)
        if(q_event == DA_NULL)
                return;
 
-//     DA_LOG(HTTPManager, "destroying size = %d", q_event->size);
-
        switch(q_event->event_type)     {
                case Q_EVENT_TYPE_DATA_HTTP:
                        init_q_event_data_http(q_event);
@@ -110,7 +108,7 @@ da_result_t  Q_make_control_event(q_event_type_control control_type, q_event_t *
        da_result_t  ret = DA_RESULT_OK;
        q_event_t *q_event = DA_NULL;
 
-       DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGD(HTTPManager);
 
        q_event = (q_event_t *)calloc(1, sizeof(q_event_t));
        if(q_event == DA_NULL) {
@@ -134,7 +132,7 @@ da_result_t  Q_make_http_data_event(q_event_type_data data_type, q_event_t **out
        da_result_t  ret = DA_RESULT_OK;
        q_event_t *q_event = DA_NULL;
 
-//     DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGV(HTTPManager);
 
        q_event = (q_event_t *)calloc(1, sizeof(q_event_t));
        if(q_event == DA_NULL) {
@@ -148,7 +146,7 @@ da_result_t  Q_make_http_data_event(q_event_type_data data_type, q_event_t **out
 
                *out_event = q_event;
 
-//             DA_LOG(HTTPManager, "made event = %x", *out_event);
+//             DA_LOG_VERBOSE(HTTPManager, "made event = %x", *out_event);
        }
 
        return ret;
@@ -159,7 +157,7 @@ da_result_t  Q_set_status_code_on_http_data_event(q_event_t *q_event, int status
 {
        da_result_t  ret = DA_RESULT_OK;
 
-//     DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGV(HTTPManager);
 
        if(q_event->event_type != Q_EVENT_TYPE_DATA_HTTP) {
                DA_LOG_ERR(HTTPManager, "status_code can be set only for Q_EVENT_TYPE_DATA_HTTP.");
@@ -169,7 +167,7 @@ da_result_t  Q_set_status_code_on_http_data_event(q_event_t *q_event, int status
 
        q_event->type.q_event_data_http.status_code = status_code;
 
-//     DA_LOG(HTTPManager, "status_code = %d, q_event = %x", q_event->type.q_event_data_http.status_code, q_event);
+//     DA_LOG_VERBOSE(HTTPManager, "status_code = %d, q_event = %x", q_event->type.q_event_data_http.status_code, q_event);
 
 ERR:
        return ret;
@@ -180,7 +178,7 @@ da_result_t  Q_set_http_body_on_http_data_event(q_event_t *q_event, int body_len
 {
        da_result_t  ret = DA_RESULT_OK;
 
-//     DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGV(HTTPManager);
 
        if(q_event->event_type != Q_EVENT_TYPE_DATA_HTTP) {
                DA_LOG_ERR(HTTPManager, "http body can be set only for Q_EVENT_TYPE_DATA_HTTP.");
@@ -192,7 +190,7 @@ da_result_t  Q_set_http_body_on_http_data_event(q_event_t *q_event, int body_len
        q_event->type.q_event_data_http.body_data = body_data;
        q_event->size = body_len;
 
-//     DA_LOG(HTTPManager, "body_len = %d, body_data = %x, q_event = %x", q_event->type.q_event_data_http.body_len, q_event->type.q_event_data_http.body_data, q_event);
+//     DA_LOG_VERBOSE(HTTPManager, "body_len = %d, body_data = %x, q_event = %x", q_event->type.q_event_data_http.body_len, q_event->type.q_event_data_http.body_data, q_event);
 
 ERR:
        return ret;
@@ -203,7 +201,7 @@ da_result_t  Q_set_error_type_on_http_data_event(q_event_t *q_event, int error_t
 {
        da_result_t  ret = DA_RESULT_OK;
 
-//     DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGV(HTTPManager);
 
        if(q_event->event_type != Q_EVENT_TYPE_DATA_HTTP) {
                DA_LOG_ERR(HTTPManager, "error_type can be set only for Q_EVENT_TYPE_DATA_HTTP.");
@@ -213,7 +211,7 @@ da_result_t  Q_set_error_type_on_http_data_event(q_event_t *q_event, int error_t
 
        q_event->type.q_event_data_http.error_type = error_type;
 
-       DA_LOG(HTTPManager, "error_type = %d, q_event = %p", q_event->type.q_event_data_http.error_type, q_event);
+       DA_LOG_VERBOSE(HTTPManager, "error_type = %d, q_event = %p", q_event->type.q_event_data_http.error_type, q_event);
 
 ERR:
        return ret;
@@ -241,8 +239,7 @@ da_bool_t Q_push_event_without_lock(const queue_t *in_queue, const q_event_t *in
        q_event_t *head = DA_NULL;
        q_event_t *cur = DA_NULL;
 
-//     DA_LOG_FUNC_START(HTTPManager);
-//     DA_LOG(HTTPManager, "queue = %x", in_queue);
+//     DA_LOG_VERBOSE(HTTPManager, "queue = %x", in_queue);
 
        event_type = event->event_type;
 
@@ -275,7 +272,7 @@ da_bool_t Q_push_event_without_lock(const queue_t *in_queue, const q_event_t *in
                        }
 
                        queue->queue_size += event->size;
-//                     DA_LOG(HTTPManager, "queue size is %d", queue->queue_size);
+//                     DA_LOG_VERBOSE(HTTPManager, "queue size is %d", queue->queue_size);
 
                        b_ret = DA_TRUE;
                } else {
@@ -294,8 +291,7 @@ void Q_pop_event(const queue_t *in_queue, q_event_t **out_event)
 {
        queue_t *queue = (queue_t*)in_queue;
 
-//     DA_LOG_FUNC_START(HTTPManager);
-//     DA_LOG(HTTPManager, "queue = %x", in_queue);
+//     DA_LOG_VERBOSE(HTTPManager, "queue = %x", in_queue);
 
        /** Pop Priority
          * 1. If there are control event, control event should pop first
@@ -313,7 +309,7 @@ void Q_pop_event(const queue_t *in_queue, q_event_t **out_event)
                        *out_event = queue->data_head;
                        queue->data_head = queue->data_head->next;
                        queue->queue_size -= (*out_event)->size;
-//                     DA_LOG(HTTPManager, "queue size is %d", queue->queue_size);
+                       DA_LOG_VERBOSE(HTTPManager, "queue size is %d", queue->queue_size);
                } else {/* Priority 3 */
                        *out_event = DA_NULL;
                }
@@ -331,7 +327,6 @@ void Q_pop_event(const queue_t *in_queue, q_event_t **out_event)
 
 void Q_goto_sleep(const queue_t *in_queue)
 {
-//     DA_LOG_FUNC_START(HTTPManager);
        DA_LOG_VERBOSE(HTTPManager, "sleep for %p", in_queue);
 
 //** SHOULD NOT use mutex **//
@@ -343,7 +338,6 @@ void Q_goto_sleep(const queue_t *in_queue)
 
 void Q_wake_up(const queue_t *in_queue)
 {
-//     DA_LOG_FUNC_START(HTTPManager);
        DA_LOG_VERBOSE(HTTPManager, "wake up for %p", in_queue);
 
 //** SHOULD NOT use mutex **//
@@ -357,15 +351,16 @@ void init_q_event_data_http(q_event_t *q_event)
 {
        q_event_data_http_t *q_event_data_http;
 
-//     DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGV(HTTPManager);
 
        if(q_event->event_type == Q_EVENT_TYPE_DATA_HTTP) {
                q_event_data_http = &(q_event->type.q_event_data_http);
 
                if(q_event_data_http) {
-                       q_event_data_http->status_code = DA_NULL;
+                       q_event_data_http->status_code = 0;
                        if(q_event_data_http->http_response_msg) {
                                http_msg_response_destroy(&(q_event_data_http->http_response_msg));
+                               q_event_data_http->http_response_msg = DA_NULL;
                        }
 
                        if(q_event_data_http->body_len > 0 ) {
@@ -374,7 +369,7 @@ void init_q_event_data_http(q_event_t *q_event)
                                        q_event_data_http->body_data = DA_NULL;
                                }
                        }
-                       q_event_data_http->error_type = DA_NULL;
+                       q_event_data_http->error_type = 0;
                }
        }
 }
@@ -383,12 +378,12 @@ void init_q_event_control(q_event_t *q_event)
 {
        q_event_control_t *q_event_control;
 
-//     DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGV(HTTPManager);
 
        if(q_event->event_type == Q_EVENT_TYPE_CONTROL) {
                q_event_control = &(q_event->type.q_event_control);
                if(q_event_control) {
-                       q_event_control->control_type = DA_NULL;
+                       q_event_control->control_type = Q_EVENT_TYPE_CONTROL_NONE;
                }
        }
 
index e16d6ff..7d994e6 100755 (executable)
@@ -29,7 +29,7 @@ int da_init(
 {
        da_result_t ret = DA_RESULT_OK;
 
-       DA_LOG_FUNC_START(Default);
+       DA_LOG_FUNC_LOGD(Default);
 
        if (!da_client_callback) {
                ret = DA_ERR_INVALID_ARGUMENT;
@@ -70,7 +70,7 @@ int da_deinit()
 {
        da_result_t ret = DA_RESULT_OK;
 
-       DA_LOG_FUNC_START(Default);
+       DA_LOG_FUNC_LOGV(Default);
 
        deinit_http_mgr();
        deinit_download_mgr();
@@ -89,14 +89,14 @@ int da_start_download(
 {
        da_result_t ret = DA_RESULT_OK;
 
-       DA_LOG_FUNC_START(Default);
+       DA_LOG_FUNC_LOGD(Default);
 
        *download_id = DA_INVALID_ID;
 
        if (DA_FALSE == is_valid_url(url, &ret))
                goto ERR;
 
-       DA_LOG(Default, "url = %s", url);
+       DA_SECURE_LOGI("url = %s", url);
 
        ret = start_download(url, download_id);
        if (ret != DA_RESULT_OK)
@@ -117,14 +117,14 @@ int da_start_download_with_extension(
        int req_header_count = 0;
        int i = 0;
 
-       DA_LOG_FUNC_START(Default);
+       DA_LOG_FUNC_LOGV(Default);
 
        *download_id = DA_INVALID_ID;
 
        if (DA_FALSE == is_valid_url(url, &ret))
                goto ERR;
 
-       DA_LOG(Default, "url = %s", url);
+       DA_SECURE_LOGI("url = %s", url);
 
        if (ret != DA_RESULT_OK)
                goto ERR;
@@ -139,11 +139,11 @@ int da_start_download_with_extension(
                for (i = 0; i < extension_data->request_header_count; i++) {
                        if (extension_data->request_header[i]) {
                                req_header_count++;
-                               DA_LOG_VERBOSE(Default, "request_header = [%s]",
+                               DA_SECURE_LOGI("request_header = [%s]",
                                        extension_data->request_header[i]);
                        }
                }
-               DA_LOG(Default, "actual request_header_count = [%d]", req_header_count);
+               DA_LOG_VERBOSE(Default, "actual request_header_count = [%d]", req_header_count);
                if (extension_data->request_header_count != req_header_count) {
                        DA_LOG_ERR(Default, "Request header count is not matched with number of request header array");
                        extension_data->request_header = NULL;
@@ -156,16 +156,17 @@ int da_start_download_with_extension(
        if (extension_data->install_path) {
                if (!is_dir_exist(extension_data->install_path))
                        return DA_ERR_INVALID_INSTALL_PATH;
-               DA_LOG_VERBOSE(Default, "install_path = [%s]", extension_data->install_path);
+               DA_SECURE_LOGI("install_path = [%s]", extension_data->install_path);
        }
 
        if (extension_data->file_name)
-               DA_LOG_VERBOSE(Default, "file_name = [%s]", extension_data->file_name);
+               DA_SECURE_LOGI("file_name = [%s]", extension_data->file_name);
        if (extension_data->temp_file_path)
-               DA_LOG_VERBOSE(Default, "temp_file_path = [%s]", extension_data->temp_file_path);
+               DA_SECURE_LOGI("temp_file_path = [%s]", extension_data->temp_file_path);
        if (extension_data->etag)
-               DA_LOG_VERBOSE(Default, "etag = [%s]", extension_data->etag);
-
+               DA_SECURE_LOGI("etag = [%s]", extension_data->etag);
+       if (extension_data->pkg_name)
+               DA_SECURE_LOGI("pkg_name = [%s]", extension_data->pkg_name);
        if (extension_data->user_data)
                DA_LOG_VERBOSE(Default, "user_data = [%p]", extension_data->user_data);
 
index ef7f4ed..53bab8b 100755 (executable)
 #include "download-agent-mime-util.h"
 #include "download-agent-pthread.h"
 
-#define IS_PROHIBITED_CHAR(c)  ((c) == ';' || (c) == '\\' || (c) == '/' || (c) == ':' || (c) == '*' || (c) == '?' || (c) == '"' || (c) == '>' || (c) == '<' || (c) == '|' || (c) == '(' || (c) == ')')
-#define IS_SPACE_CHARACTER(c)          ((c) == ' ' || (c) == '\t')
+#define IS_PROHIBITED_CHAR(c)  ((c) == ';' || (c) == '\\' || (c) == '/' || (c) == ':' || (c) == '*' || (c) == '?' || (c) == '"' || (c) == '>' || (c) == '<' || (c) == '|' || (c) == '(' || (c) == ')')
+#define IS_SPACE_CHARACTER(c)  ((c) == '\t')
 
-#define DD_MIME_STR "application/vnd.oma.dd+xml"
-#define DD_EXT_STR "*.dd"
-#define DRM_MIME_STR "application/vnd.oma.drm.message"
-#define DRM_EXT_STR "*.dcf"
 #define MAX_EXT_TABLE_INDEX 16
 Ext_translation_table ext_trans_table [MAX_EXT_TABLE_INDEX] = {
                {"*.xla",                       "*.xls"},
@@ -73,7 +69,7 @@ pthread_mutex_t mutex_for_xdgmime = PTHREAD_MUTEX_INITIALIZER;
 
 da_bool_t is_ambiguous_MIME_Type(const char *in_mime_type)
 {
-//     DA_LOG_FUNC_START(Default);
+       DA_LOG_FUNC_LOGV(Default);
 
        if (!in_mime_type)
                return DA_FALSE;
@@ -83,7 +79,7 @@ da_bool_t is_ambiguous_MIME_Type(const char *in_mime_type)
        for (index = 0 ; index < list_size ; index++) {
                if (0 == strncmp(in_mime_type, ambiguous_MIME_Type_list[index],
                                strlen(ambiguous_MIME_Type_list[index]))) {
-                       DA_LOG(Default,"It is ambiguous! [%s]", ambiguous_MIME_Type_list[index]);
+                       DA_SECURE_LOGD("It is ambiguous! [%s]", ambiguous_MIME_Type_list[index]);
                        return DA_TRUE;
                }
        }
@@ -99,14 +95,14 @@ da_result_t da_mime_get_ext_name(char *mime, char **ext)
        char ext_temp[DA_MAX_STR_LEN] = {0,};
        char *temp = NULL;
 
-       DA_LOG_FUNC_START(Default);
+       DA_LOG_FUNC_LOGV(Default);
 
        if (DA_NULL == mime || DA_NULL == ext) {
                ret = DA_ERR_INVALID_ARGUMENT;
                DA_LOG_ERR(Default,"Invalid mime type");
                goto ERR;
        }
-       DA_LOG_VERBOSE(Default,"mime str[%s]ptr[%p]len[%d]",mime,mime,strlen(mime));
+//     DA_SECURE_LOGD("mime str[%s]ptr[%p]len[%d]",mime,mime,strlen(mime));
        /* unaliased_mimetype means representative mime among similar types */
        _da_thread_mutex_lock(&mutex_for_xdgmime);
        unaliased_mimetype = xdg_mime_unalias_mime_type(mime);
@@ -117,7 +113,7 @@ da_result_t da_mime_get_ext_name(char *mime, char **ext)
                DA_LOG_ERR(Default,"Invalid mime type : No unsaliased mime type");
                goto ERR;
        }
-       DA_LOG(Default,"unaliased_mimetype[%s]\n",unaliased_mimetype);
+       DA_SECURE_LOGD("unaliased_mimetype[%s]\n",unaliased_mimetype);
 
        /* Get extension name from shared-mime-info */
        _da_thread_mutex_lock(&mutex_for_xdgmime);
@@ -138,7 +134,7 @@ da_result_t da_mime_get_ext_name(char *mime, char **ext)
                }
 #endif
        } else { /* For drm case, this else statement is needed */
-               DA_LOG(Default,"extlist[%s]\n",*extlist);
+               DA_SECURE_LOGD("extlist[%s]\n",*extlist);
                strncpy(ext_temp, *extlist, DA_MAX_STR_LEN);
                /* If only one extension name is existed, don't enter here */
                while (*extlist != NULL) {
@@ -155,25 +151,26 @@ da_result_t da_mime_get_ext_name(char *mime, char **ext)
                                        break;
                                }
                        }
-                       DA_LOG(Default,"index[%d]\n",i);
+                       DA_LOG_VERBOSE(Default,"index[%d]\n",i);
                        /* If there is a mime at extension transform table */
                        if (i < MAX_EXT_TABLE_INDEX) {
                                break;
                        }
-                       DA_LOG(Default,"extlist[%s]\n",*extlist);
+                       DA_SECURE_LOGD("extlist[%s]\n",*extlist);
                        extlist++;
                }
-               DA_LOG(Default,"extension from shared mime info[%s]",ext_temp);
+//             DA_SECURE_LOGD("extension from shared mime info[%s]",ext_temp);
        }
 
        if (strlen(ext_temp) < 1) {
-               /* If there is no mime string for OMD descriptor mime type */
-               if (strncmp(DD_MIME_STR,mime,strlen(DD_MIME_STR)) == 0) {
+               /* If there is no mime string for OMA descriptor mime type */
+               if (strncmp(DD_MIME_STR, mime, strlen(DD_MIME_STR)) == 0) {
                        strncpy(ext_temp, DD_EXT_STR, DA_MAX_STR_LEN-1);
                        ret = DA_RESULT_OK;
                        /* If there is no extension name for "applicaion/vnd.oma.drm.messeages"
                         *  at shared-mime-info*/
-               } else if (strncmp(DRM_MIME_STR,mime,strlen(DD_MIME_STR)) == 0) {
+               } else if (strncmp(DRM_MIME_MSG_STR, mime,
+                               strlen(DRM_MIME_MSG_STR)) == 0) {
                        strncpy(ext_temp, DRM_EXT_STR, DA_MAX_STR_LEN-1);
                        /* If there is extension name at extlist, the return value can have an error.*/
                        ret = DA_RESULT_OK;
@@ -191,7 +188,6 @@ da_result_t da_mime_get_ext_name(char *mime, char **ext)
        else
                temp++;
 
-       DA_LOG(Default,"final extension name:[%s]",temp);
        *ext = (char*)calloc(1, strlen(temp) + 1);
        if (*ext != DA_NULL) {
                strncpy(*ext, temp,strlen(temp));
@@ -210,7 +206,7 @@ da_bool_t da_get_extension_name_from_url(char *url, char **ext)
        char *temp_str = DA_NULL;
        int buf_len = 0;
 
-       DA_LOG_FUNC_START(Default);
+       DA_LOG_FUNC_LOGV(Default);
 
        if (DA_NULL == url || DA_NULL == ext) {
                ret = DA_FALSE;
@@ -237,7 +233,7 @@ da_bool_t da_get_extension_name_from_url(char *url, char **ext)
                                goto ERR;
                        }
                        strncpy(*ext,buff,buf_len);
-                       DA_LOG(Default,"extention name[%s]",*ext);
+                       DA_SECURE_LOGD("extention name[%s]",*ext);
                        return ret;
                }
        }
@@ -262,7 +258,7 @@ da_bool_t da_get_file_name_from_url(char *url, char **name)
        int len_name = 0;
        char name_buff[DA_MAX_FILE_PATH_LEN] = {0,};
 
-       DA_LOG_FUNC_START(Default);
+       DA_LOG_FUNC_LOGV(Default);
 
        if (DA_NULL == url || DA_NULL == name) {
                ret = DA_FALSE;
@@ -341,16 +337,16 @@ da_bool_t da_get_file_name_from_url(char *url, char **name)
                if (End != NULL) {
                        *End = '\0';
                }
-               DA_LOG(Default,"file name BEFORE removing prohibited character = %s", name_buff);
+//             DA_SECURE_LOGD("file name BEFORE removing prohibited character = %s", name_buff);
                delete_prohibited_char(name_buff, strlen(name_buff));
-               DA_LOG(Default,"file name AFTER removing prohibited character = %s", name_buff);
+//             DA_SECURE_LOGD("file name AFTER removing prohibited character = %s", name_buff);
                len_name = strlen(name_buff);
                *name = (char*) calloc(1, len_name + 1);
                if (*name) {
                        strncpy(*name, name_buff,len_name);
                }
        }
-       DA_LOG(Default,"Extracted file name : %s", *name);
+//     DA_SECURE_LOGD("Extracted file name : %s", *name);
 ERR:
        if (buff) {
                free (buff);
index f0ce27f..8a547f7 100755 (executable)
@@ -50,51 +50,6 @@ da_result_t __get_conf_string(const char *key, char **out_string)
 #endif
 }
 
-da_result_t get_storage_type(da_storage_type_t *type)
-{
-  da_result_t ret = DA_RESULT_OK;
-#ifdef _EFL_PLATFORM
-  int value = -1;
-#endif
-
-  if (!type)  {
-    DA_LOG_ERR(Default,"DA_ERR_CONF_FAIL");
-       ret = DA_ERR_INVALID_ARGUMENT;
-       goto ERR;
-  }
-
-#ifdef _EFL_PLATFORM
-       if (0 != vconf_get_int(VCONFKEY_SETAPPL_DEFAULT_MEM_WAP_INT, &value)) {
-               DA_LOG_ERR(Default,"DA_ERR_CONF_FAIL");
-               ret = DA_ERR_FAIL_TO_GET_CONF_VALUE;
-               goto ERR;
-       }
-
-       switch (value) {
-       case SETTING_DEF_MEMORY_PHONE:
-               DA_LOG(Default,"Storage set - DA_STORAGE_PHONE");
-               *type = DA_STORAGE_PHONE;
-               break;
-       case SETTING_DEF_MEMORY_MMC:
-               *type = DA_STORAGE_MMC;
-               DA_LOG(Default,"Storage set - DA_STORAGE_MMC");
-               break;
-       case SETTING_DEF_MEMORY_MAX:
-               *type = DA_STORAGE_SYSTEM;
-               DA_LOG(Default,"Storage set - DA_STORAGE_SYSTEM");
-               break;
-       default:
-               DA_LOG_ERR(Default,"DA_ERR_CONF_FAIL");
-               ret = DA_ERR_FAIL_TO_GET_CONF_VALUE;
-               break;
-       }
-#endif
-
-ERR:
-   return ret;
-
-}
-
 da_result_t get_user_agent_string(char **uagent_str)
 {
        da_result_t  ret = DA_RESULT_OK;
@@ -102,7 +57,7 @@ da_result_t get_user_agent_string(char **uagent_str)
        char *key = DA_NULL;
 #endif
 
-       DA_LOG_FUNC_START(Default);
+       DA_LOG_FUNC_LOGV(Default);
 
        if (!uagent_str) {
                DA_LOG_ERR(Default,"Invalid Argument");
@@ -114,7 +69,7 @@ da_result_t get_user_agent_string(char **uagent_str)
        ret = __get_conf_string(key, uagent_str);
        if(ret == DA_RESULT_OK) {
                if(*uagent_str) {
-                       DA_LOG(Default,"getting uagent_str = \n%s", *uagent_str);
+                       DA_SECURE_LOGD("getting uagent_str = \n%s", *uagent_str);
                        return ret;
                }
        }
@@ -135,7 +90,7 @@ char *get_proxy_address(void)
        connection_h handle = NULL;
     connection_address_family_e family = CONNECTION_ADDRESS_FAMILY_IPV4;
 
-    DA_LOG_FUNC_START(Default);
+    DA_LOG_FUNC_LOGV(Default);
     if (connection_create(&handle) < 0) {
                DA_LOG_ERR(Default,"Fail to create connection handle");
                return NULL;
@@ -148,7 +103,7 @@ char *get_proxy_address(void)
        }
 
        if (proxyRet) {
-               DA_LOG(Default,"===== Proxy address[%s] =====", proxyRet);
+               DA_SECURE_LOGD("===== Proxy address[%s] =====", proxyRet);
                proxy = strdup(proxyRet);
                free(proxyRet);
                proxyRet = NULL;
index 8f3a66e..6d54afd 100755 (executable)
@@ -33,7 +33,7 @@ da_bool_t _pi_http_is_this_session_table_entry_using(
 
 da_result_t PI_http_init(void)
 {
-       DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGV(HTTPManager);
 
        using_content_sniffing = DA_TRUE;
 
@@ -42,7 +42,7 @@ da_result_t PI_http_init(void)
 
 void PI_http_deinit(void)
 {
-       DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGV(HTTPManager);
 
        return;
 }
@@ -53,10 +53,10 @@ da_result_t _set_proxy_on_soup_session(SoupSession *session, char *proxy_addr)
 
 
        if (proxy_addr && strlen(proxy_addr) > 0) {
-               DA_LOG_CRITICAL(HTTPManager,"received proxy = %s \n", proxy_addr);
+               DA_SECURE_LOGD("received proxy = %s \n", proxy_addr);
                if (!strstr(proxy_addr, "0.0.0.0")) {
                        if (strstr((const char *)proxy_addr, "http") == DA_NULL) {
-                               /* DA_LOG(Default,"There is no \"http://\" on received uri, so, add it."); */
+                               DA_LOG_VERBOSE(Default,"There is no \"http://\" on received uri, so, add it.");
 
                                char *tmp_str = DA_NULL;
                                int needed_len = 0;
@@ -83,7 +83,7 @@ da_result_t _set_proxy_on_soup_session(SoupSession *session, char *proxy_addr)
                        }
                }
        } else {
-               DA_LOG(HTTPManager,"There is no proxy value");
+               DA_LOG_VERBOSE(HTTPManager,"There is no proxy value");
        }
 ERR:
        return ret;
@@ -107,7 +107,7 @@ void _fill_soup_msg_header(SoupMessage *msg,
        http_msg_iter_pre = http_msg_iter;
        while (http_msg_get_field_with_iter(&http_msg_iter, &field, &value)) {
                if ((field != DA_NULL) && (value != DA_NULL)) {
-                       DA_LOG(HTTPManager,"[%s] %s", field, value);
+                       DA_SECURE_LOGD("[%s] %s", field, value);
                        soup_message_headers_append(headers, field, value);
                }
                http_msg_iter_pre = http_msg_iter;
@@ -139,7 +139,7 @@ da_result_t PI_http_start_transaction(const input_for_tranx_t *input_for_tranx,
        SoupSession *session = DA_NULL;
        SoupMessage *msg = DA_NULL;
 
-       DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGV(HTTPManager);
 
        if (DA_FALSE == _pi_http_is_valid_input_for_tranx(input_for_tranx)) {
                DA_LOG_ERR(HTTPManager,"input_for_tranx is invalid");
@@ -156,7 +156,7 @@ da_result_t PI_http_start_transaction(const input_for_tranx_t *input_for_tranx,
                ret = DA_ERR_ALREADY_MAX_DOWNLOAD;
                goto ERR;
        }
-       DA_LOG(HTTPManager,"session_table_entry = %d", session_table_entry);
+       DA_LOG_VERBOSE(HTTPManager,"session_table_entry = %d", session_table_entry);
 
        if (DA_FALSE == _pi_http_register_queue_to_session_table(
                        session_table_entry, queue)) {
@@ -207,7 +207,7 @@ da_result_t PI_http_start_transaction(const input_for_tranx_t *input_for_tranx,
                DA_LOG_ERR(HTTPManager,"Cannot enter here");
                break;
        }
-       DA_LOG(HTTPManager,"msg[%p]", msg);
+       DA_LOG_VERBOSE(HTTPManager,"msg[%p]", msg);
        /* if it is failed to create a msg, the url can be invalid, becasue of the input argument of soup_message_new API */
        if (msg == NULL) {
                DA_LOG_ERR(HTTPManager,"Fail to create message");
@@ -254,9 +254,7 @@ da_result_t PI_http_disconnect_transaction(int in_tranx_id)
        da_result_t ret = DA_RESULT_OK;
        int session_table_entry = -1;
 
-       DA_LOG_FUNC_START(HTTPManager);
-
-       DA_LOG(HTTPManager,"in_tranx_id = %d", in_tranx_id);
+       DA_LOG_VERBOSE(HTTPManager,"in_tranx_id = %d", in_tranx_id);
 
        session_table_entry = in_tranx_id;
 
@@ -272,9 +270,7 @@ da_result_t PI_http_cancel_transaction(int in_tranx_id, da_bool_t abort_option)
        SoupMessage *msg;
        int session_table_entry = -1;
 
-       DA_LOG_FUNC_START(HTTPManager);
-
-       DA_LOG(HTTPManager,"in_tranx_id = %d", in_tranx_id);
+       DA_LOG_FUNC_LOGV(HTTPManager);
 
        session_table_entry = in_tranx_id;
        if (!_pi_http_is_this_session_table_entry_using(session_table_entry)) {
@@ -293,12 +289,13 @@ da_result_t PI_http_cancel_transaction(int in_tranx_id, da_bool_t abort_option)
                DA_LOG_ERR(HTTPManager,"invalid message = %p", msg);
                goto ERR;
        }
-       DA_LOG(HTTPManager,"Call soup cancel API : abort option[%d]",abort_option);
+       DA_LOG(HTTPManager,"soup cancel API:abort option[%d] tranx_id[%d]",
+                       abort_option, in_tranx_id);
        if (abort_option)
                soup_session_abort(session);
        else
                soup_session_cancel_message(session, msg, SOUP_STATUS_CANCELLED);
-       DA_LOG(HTTPManager,"Call soup cancel API-Done");
+       DA_LOG(HTTPManager,"soup cancel API-Done");
 ERR:
        return ret;
 }
@@ -309,7 +306,7 @@ void PI_http_pause_transaction(int transaction_id)
        pthread_mutex_t *mutex;
        pthread_cond_t *cond;
 
-       DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGD(HTTPManager);
 
        DA_LOG(HTTPManager,"in_tranx_id = %d", transaction_id);
 
@@ -341,7 +338,7 @@ void PI_http_unpause_transaction(int transaction_id)
        pthread_mutex_t *mutex;
        pthread_cond_t *cond;
 
-       /*      DA_LOG_FUNC_START(Default); */
+       DA_LOG_FUNC_LOGV(Default);
 
        session_table_entry = transaction_id;
 
@@ -616,8 +613,6 @@ void _pi_http_store_read_header_to_queue(SoupMessage *msg, const char *sniffedTy
 
        http_msg_response_t *http_msg_response = NULL;
 
-       /*      DA_LOG_FUNC_START(Default); */
-
        if (msg->response_headers) {
                ret = http_msg_response_create(&http_msg_response);
                if (ret != DA_RESULT_OK)
@@ -626,8 +621,8 @@ void _pi_http_store_read_header_to_queue(SoupMessage *msg, const char *sniffedTy
                http_msg_response_set_status_code(http_msg_response,
                                msg->status_code);
 
-               DA_LOG(HTTPManager,"\n----raw header---------------------------------------------");
-               DA_LOG_CRITICAL(HTTPManager,"status code = %d", msg->status_code);
+               DA_LOG_VERBOSE(HTTPManager,"\n----raw header---------------------------------------------");
+               DA_LOG(HTTPManager,"status code = %d", msg->status_code);
                soup_message_headers_iter_init(&headers_iter,
                                msg->response_headers);
                while (soup_message_headers_iter_next(&headers_iter,
@@ -636,9 +631,10 @@ void _pi_http_store_read_header_to_queue(SoupMessage *msg, const char *sniffedTy
                                        != DA_NULL)) {
                                http_msg_response_add_field(http_msg_response,
                                                header_name, header_value);
+                               DA_SECURE_LOGI("[%s][%s]", header_name, header_value);
                        }
                }
-               DA_LOG(HTTPManager,"\n-------------------------------------------------------------\n");
+               DA_LOG_VERBOSE(HTTPManager,"\n-------------------------------------------------------------\n");
 
        }
 
@@ -691,8 +687,6 @@ void _pi_http_store_read_data_to_queue(SoupMessage *msg, const char *body_data,
        int session_table_entry = -1;
        int http_status = -1;
 
-       /*      DA_LOG_FUNC_START(Default); */
-
        http_status = msg->status_code;
 
        session_table_entry
@@ -704,7 +698,7 @@ void _pi_http_store_read_data_to_queue(SoupMessage *msg, const char *body_data,
        }
 
        if (received_body_len == 0) {
-               DA_LOG(HTTPManager,"Q_EVENT_TYPE_DATA_FINAL");
+               DA_LOG_VERBOSE(HTTPManager,"Q_EVENT_TYPE_DATA_FINAL");
                da_event_type_data = Q_EVENT_TYPE_DATA_FINAL;
        } else {
                da_event_type_data = Q_EVENT_TYPE_DATA_PACKET;
@@ -811,7 +805,7 @@ void _pi_http_store_neterr_to_queue(SoupMessage *msg)
        q_event_t *da_event = NULL;
        int session_table_entry = -1;
 
-       DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGD(HTTPManager);
 
        error_type = _translate_error_code(msg->status_code);
 
@@ -877,7 +871,7 @@ void _pi_http_finished_cb(SoupSession *session, SoupMessage *msg, gpointer data)
 {
        char *url = NULL;
 
-       DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGV(HTTPManager);
 
        if (!msg) {
                DA_LOG_ERR(HTTPManager, "Check NULL:msg");
@@ -886,7 +880,7 @@ void _pi_http_finished_cb(SoupSession *session, SoupMessage *msg, gpointer data)
 
        url = soup_uri_to_string(soup_message_get_uri(msg), DA_FALSE);
 
-       DA_LOG(HTTPManager,"status_code[%d], reason[%s], url[%s]",msg->status_code,msg->reason_phrase,url);
+       DA_SECURE_LOGI("status_code[%d], reason[%s], url[%s]",msg->status_code,msg->reason_phrase,url);
 
        if (url) {
                free(url);
@@ -908,7 +902,7 @@ void _pi_http_finished_cb(SoupSession *session, SoupMessage *msg, gpointer data)
 /* this callback is called in case of redirection */
 void _pi_http_restarted_cb(SoupMessage *msg, gpointer data)
 {
-       DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGD(HTTPManager);
        /* Location URL is needed when extracting the file name from url.
         * So, the response header should be handled by http mgr.*/
 
@@ -926,7 +920,7 @@ void _pi_http_restarted_cb(SoupMessage *msg, gpointer data)
 
 void _pi_http_gotheaders_cb(SoupMessage *msg, gpointer data)
 {
-       DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGV(HTTPManager);
 
        if (!msg) {
                DA_LOG_ERR(HTTPManager, "Check NULL:msg");
@@ -950,13 +944,13 @@ void _pi_http_gotheaders_cb(SoupMessage *msg, gpointer data)
        if (!using_content_sniffing)
                _pi_http_store_read_header_to_queue(msg, NULL);
        else
-               DA_LOG(HTTPManager,"ignore because content sniffing is turned on");
+               DA_LOG_DEBUG(HTTPManager,"ignore because content sniffing is turned on");
 }
 
 void _pi_http_contentsniffed_cb(SoupMessage *msg, const char *sniffedType,
                GHashTable *params, gpointer data)
 {
-       DA_LOG_FUNC_START(HTTPManager);
+       DA_LOG_FUNC_LOGD(HTTPManager);
 
        if (!msg) {
                DA_LOG_ERR(HTTPManager, "Check NULL:msg");
@@ -981,7 +975,7 @@ void _pi_http_contentsniffed_cb(SoupMessage *msg, const char *sniffedType,
 
 void _pi_http_gotchunk_cb(SoupMessage *msg, SoupBuffer *chunk, gpointer data)
 {
-//     DA_LOG_FUNC_START(HTTPManager);
+//     DA_LOG_FUNC_LOGV(HTTPManager);
 
        if (!msg) {
                DA_LOG_ERR(HTTPManager, "Check NULL:msg");
index 1d06722..c6e747d 100755 (executable)
@@ -31,7 +31,7 @@ da_result_t init_dl_id_history(dl_id_history_t *dl_id_history)
        dl_id_history->cur_dl_id = DA_INVALID_ID;
        _da_thread_mutex_unlock(&(dl_id_history->mutex));
 
-       DA_LOG_CRITICAL(Default,"starting num = %d", dl_id_history->starting_num);
+       DA_LOG_VERBOSE(Default,"starting num = %d", dl_id_history->starting_num);
        return ret;
 }
 
@@ -66,6 +66,6 @@ int get_available_dl_id(dl_id_history_t *dl_id_history)
 
        _da_thread_mutex_unlock(&(dl_id_history->mutex));
 
-       DA_LOG_CRITICAL(Default,"dl_id = %d", dl_id);
+       DA_LOG_VERBOSE(Default,"dl_id = %d", dl_id);
        return dl_id;
 }
index 3ac9710..71aca16 100755 (executable)
@@ -65,19 +65,19 @@ da_result_t get_extension_from_mime_type(char *mime_type, char **extension)
        da_result_t ret = DA_RESULT_OK;
        char *ext = DA_NULL;
 
-       DA_LOG_FUNC_START(Default);
+       DA_LOG_FUNC_LOGV(Default);
        if (DA_NULL == mime_type || DA_NULL == extension) {
                DA_LOG_ERR(Default,"received mime_type is null");
                ret = DA_ERR_INVALID_ARGUMENT;
                goto ERR;
        }
-       DA_LOG(Default,"input mime type = %s", mime_type);
+//     DA_SECURE_LOGD("input mime type = %s", mime_type);
        if (DA_RESULT_OK != (ret = da_mime_get_ext_name(mime_type, &ext))) {
                DA_LOG_ERR(Default,"can't find proper extension!");
                goto ERR;
        }
        *extension = ext;
-       DA_LOG(Default,"found extension = %s", *extension);
+//     DA_SECURE_LOGD("found extension = %s", *extension);
 
 ERR:
        return ret;
@@ -99,7 +99,7 @@ int read_data_from_file(char *file, char **out_buffer)
        /* open file with "rb", because fread() handles the file as binary mode */
        fd = fopen(file, "rb");
        if (!fd) {
-               DA_LOG_ERR(FileManager,"File open err! received file path = [%s]", file);
+               DA_LOG_ERR(FileManager,"File open err! received file path");
                return 0;
        }
 
@@ -137,16 +137,14 @@ int read_data_from_file(char *file, char **out_buffer)
        return buffer_len;
 }
 
-da_result_t get_available_memory(
-        da_storage_type_t storage_type,
-        da_storage_size_t *avail_memory)
+da_result_t get_available_memory(da_storage_size_t *avail_memory)
 {
        da_result_t ret = DA_RESULT_OK;
        int fs_ret = 0;
        struct statfs filesys_info = {0, };
        char *default_install_dir = NULL;
 
-       DA_LOG_FUNC_START(Default);
+       DA_LOG_FUNC_LOGD(Default);
 
        if (!avail_memory)
                return DA_ERR_INVALID_ARGUMENT;
@@ -168,10 +166,9 @@ da_result_t get_available_memory(
        avail_memory->b_available = filesys_info.f_bavail;
        avail_memory->b_size = filesys_info.f_bsize;
 
-       DA_LOG(Default, "Memory type : %d", storage_type);
-       DA_LOG_VERBOSE(Default, "Available Memory(f_bavail) : %lu", filesys_info.f_bavail);
+       DA_LOG_VERBOSE(Default, "Available Memory(f_bavail) : %llu", filesys_info.f_bavail);
        DA_LOG_VERBOSE(Default, "Available Memory(f_bsize) : %d", filesys_info.f_bsize);
-       DA_LOG(Default, "Available Memory(kbytes) : %lu", (filesys_info.f_bavail/1024)*filesys_info.f_bsize);
+       DA_LOG_VERBOSE(Default, "Available Memory(kbytes) : %lu", (filesys_info.f_bavail/1024)*filesys_info.f_bsize);
 
        free(default_install_dir);
        return DA_RESULT_OK;
@@ -181,12 +178,8 @@ da_mime_type_id_t get_mime_type_id(char *content_type)
 {
        int i = 0;
 
-       DA_LOG_FUNC_START(Default);
-
-       DA_LOG(Default,"received content_type = %s", content_type);
-
        if (content_type == NULL) {
-               DA_LOG_ERR(Default, "No Mime Type\n");
+               DA_LOG_CRITICAL(Default, "No Mime Type Id");
                return DA_MIME_TYPE_NONE;
        }
 
@@ -197,7 +190,7 @@ da_mime_type_id_t get_mime_type_id(char *content_type)
                }
                i++;
        }
-       DA_LOG(Default, "dd mime type check: index[%d] type[%d]", i, descriptor_mime_table[i].mime_type);
+       //DA_LOG_VERBOSE(Default, "dd mime type check: index[%d] type[%d]", i, descriptor_mime_table[i].mime_type);
        return descriptor_mime_table[i].mime_type;
 }
 
@@ -281,10 +274,10 @@ da_result_t move_file(const char *from_path, const char *to_path)
 
 void remove_file(const char *file_path)
 {
-       DA_LOG_FUNC_START(FileManager);
+       DA_LOG_FUNC_LOGD(FileManager);
 
        if (file_path && is_file_exist(file_path)) {
-               DA_LOG(FileManager,"remove file [%s]", file_path);
+               DA_SECURE_LOGD("remove file [%s]", file_path);
                if (unlink(file_path) < 0) {
                        DA_LOG_ERR(FileManager,"file removing failed.");
                }
index e12a40b..24ac67e 100755 (executable)
@@ -49,7 +49,11 @@ da_result_t init_log_mgr(void);
        #define DA_LOG_CRITICAL(channel, format, ...) ((void)0)
        #define DA_LOG_VERBOSE(channel, format, ...) ((void)0)
        #define DA_LOG_ERR(channel, format, ...) ((void)0)
-       #define DA_LOG_FUNC_START(channel, ...) ((void)0)
+       #define DA_LOG_FUNC_LOGD(channel, ...) ((void)0)
+       #define DA_LOG_FUNC_LOGV(channel, ...) ((void)0)
+       #define DA_SECURE_LOGD(format, ...) ((void)0)
+       #define DA_SECURE_LOGI(format, ...) ((void)0)
+       #define DA_SECURE_LOGE(format, ...) ((void)0)
 
 #else /* NODEBUG */
 #include <stdio.h>
@@ -63,11 +67,16 @@ da_result_t init_log_mgr(void);
        #endif /*  LOG_TAG */
        #define LOG_TAG "DOWNLOAD_AGENT"
 
-       #define DA_LOG(channel, format, ...) LOGD_IF(IS_LOG_ON(channel), format, ##__VA_ARGS__);
-       #define DA_LOG_CRITICAL(channel, format, ...) LOGE_IF(IS_LOG_ON(channel), format, ##__VA_ARGS__);
-       #define DA_LOG_VERBOSE(channel, format, ...) LOGV_IF(IS_LOG_ON(channel), format, ##__VA_ARGS__);
-       #define DA_LOG_ERR(channel, format, ...) LOGE_IF(IS_LOG_ON(channel), "ERR! "format, ##__VA_ARGS__);
-       #define DA_LOG_FUNC_START(channel, ...) LOGV_IF(IS_LOG_ON(channel), "starting...");
+       #define DA_LOG(channel, format, ...) LOGI_IF(IS_LOG_ON(channel), format, ##__VA_ARGS__)
+       #define DA_LOG_DEBUG(channel, format, ...) LOGD_IF(IS_LOG_ON(channel), format, ##__VA_ARGS__)
+       #define DA_LOG_CRITICAL(channel, format, ...) LOGI_IF(IS_LOG_ON(channel), format, ##__VA_ARGS__)
+       #define DA_LOG_VERBOSE(channel, format, ...) ((void)0)//LOGD_IF(IS_LOG_ON(channel), format, ##__VA_ARGS__)
+       #define DA_LOG_ERR(channel, format, ...) LOGE_IF(IS_LOG_ON(channel), "ERR! "format, ##__VA_ARGS__)
+       #define DA_LOG_FUNC_LOGD(channel, ...) LOGD_IF(IS_LOG_ON(channel), "starting...")
+       #define DA_LOG_FUNC_LOGV(channel, ...) ((void)0)//LOGD_IF(IS_LOG_ON(channel), "starting...")
+       #define DA_SECURE_LOGD(format, ...) SECURE_LOGD(format, ##__VA_ARGS__)
+       #define DA_SECURE_LOGI(format, ...) SECURE_LOGI(format, ##__VA_ARGS__)
+       #define DA_SECURE_LOGE(format, ...) SECURE_LOGE(format, ##__VA_ARGS__)
 #else /* DA_DEBUG_USING_DLOG */
        #include <unistd.h>
        #include <syscall.h>
@@ -82,13 +91,17 @@ da_result_t init_log_mgr(void);
                                ? fprintf(stderr, "[DA][%u][ERR][%s(): %d]\n",(unsigned int)syscall(__NR_gettid), __FUNCTION__,__LINE__, ##__VA_ARGS__) \
                                : ((void)0); \
        }while(0)
-       #define DA_LOG_FUNC_START(channel, ...) do {\
+       #define DA_LOG_FUNC_LOGD(channel, ...) do {\
                IS_LOG_ON(channel) \
                                ? fprintf(stderr, "[DA][%u][%s(): %d] starting\n",(unsigned int)syscall(__NR_gettid), __FUNCTION__,__LINE__) \
                                : ((void)0); \
        }while(0)
        #define DA_LOG_CRITICAL DA_LOG
        #define DA_LOG_VERBOSE DA_LOG
+       #define DA_LOG_FUNC_LOGV ((void)0)
+       #define DA_SECURE_LOGD(format, ...) ((void)0)
+       #define DA_SECURE_LOGI(format, ...) ((void)0)
+       #define DA_SECURE_LOGE(format, ...) ((void)0)
 #endif /* DA_DEBUG_USING_DLOG */
 #endif /* NDEBUG */
 #endif /* _Download_Agent_Debug_H */
index 3b2e77b..b69690a 100755 (executable)
@@ -31,7 +31,7 @@
 
 #define DA_TRUE                1
 #define DA_FALSE               0
-#define DA_NULL                0
+#define DA_NULL                (void *)0
 #define DA_INVALID_ID  -1
 
 #define DA_RESULT_USER_CANCELED -10 
index e78491f..d6e20a8 100755 (executable)
@@ -64,6 +64,7 @@ typedef struct _client_input_t {
        char *file_name;
        char *etag;
        char *temp_file_path;
+       char *pkg_name;
        client_input_basic_t client_input_basic;
 } client_input_t;
 
@@ -109,7 +110,7 @@ typedef struct _req_dl_info {
        /*************** will be depreciated ***********************/
        /* ToDo : previous http_info should be saved in case of pause */
        char *content_type_from_header; /* calloced in set hdr fiels on download info */
-       int content_len_from_header;
+       unsigned long long content_len_from_header;
        char *etag_from_header;
 
        unsigned long int downloaded_data_size;
@@ -134,7 +135,7 @@ typedef struct _req_dl_info {
 #define CHANGE_HTTP_STATE(STATE,STAGE) {\
        _da_thread_mutex_lock(&(GET_REQUEST_HTTP_MUTEX_HTTP_STATE(STAGE)));\
        GET_HTTP_STATE_ON_STAGE(STAGE) = STATE;\
-       DA_LOG_CRITICAL(Default, "Changed http_state to - [%d] ", GET_HTTP_STATE_ON_STAGE(STAGE));\
+       DA_LOG_DEBUG(Default, "Changed http_state to - [%d] ", GET_HTTP_STATE_ON_STAGE(STAGE));\
        _da_thread_mutex_unlock(&(GET_REQUEST_HTTP_MUTEX_HTTP_STATE(STAGE)));\
 }
 
@@ -164,6 +165,7 @@ typedef struct _file_info {
 
 typedef struct _stage_info {
        int dl_id;
+       int thread_id;
        source_info_t dl_request;
        req_dl_info dl_tansaction_context;
        file_info dl_content_storage;
@@ -171,6 +173,7 @@ typedef struct _stage_info {
 } stage_info;
 
 #define        GET_STAGE_DL_ID(STAGE)                                  ((STAGE)->dl_id)
+#define        GET_STAGE_THREAD_ID(STAGE)                              ((STAGE)->thread_id)
 #define        GET_STAGE_SOURCE_INFO(STAGE)                    (&((STAGE)->dl_request))
 #define        GET_STAGE_TRANSACTION_INFO(STAGE)               (&((STAGE)->dl_tansaction_context))
 #define        GET_STAGE_CONTENT_STORE_INFO(STAGE)             (&((STAGE)->dl_content_storage))
@@ -211,7 +214,7 @@ typedef struct {
 #define CHANGE_DOWNLOAD_STATE(STATE,STAGE) {\
        _da_thread_mutex_lock (&mutex_download_state[GET_STAGE_DL_ID(STAGE)]);\
        GET_DL_STATE_ON_STAGE(STAGE) = STATE;\
-       DA_LOG_CRITICAL(Default, "Changed download_state to - [%d] ", GET_DL_STATE_ON_STAGE(STAGE));\
+       DA_LOG_DEBUG(Default, "Changed download_state to - [%d] ", GET_DL_STATE_ON_STAGE(STAGE));\
        _da_thread_mutex_unlock (&mutex_download_state[GET_STAGE_DL_ID(STAGE)]);\
        }
 
index fa886f7..b4d3995 100755 (executable)
@@ -24,9 +24,7 @@
 #include "download-agent-type.h"
 #include "download-agent-dl-mgr.h"
 
-#define DA_DEFAULT_FILE_DIR_PATH       "/opt/usr/media/.tmp_download"
 #define DA_DEFAULT_INSTALL_PATH_FOR_PHONE "/opt/usr/media/Downloads"
-#define DA_DEFAULT_INSTALL_PATH_FOR_MMC "/opt/storage/sdcard/Downloads"
 
 da_bool_t is_file_exist(const char *file_path);
 da_bool_t is_dir_exist(const char *dir_path);
@@ -34,8 +32,6 @@ da_bool_t is_dir_exist(const char *dir_path);
 void get_file_size(char *file_path, unsigned long long *out_file_size);
 
 da_result_t clean_files_from_dir(char *dir_path);
-da_result_t create_saved_dir(void);
-
 da_result_t file_write_ongoing(stage_info *stage, char *body, int body_len);
 da_result_t file_write_complete(stage_info *stage);
 da_result_t start_file_writing(stage_info *stage);
@@ -51,7 +47,6 @@ char *get_full_path_avoided_duplication(char *in_dir, char *in_candidate_file_na
 
 da_result_t copy_file(const char *src, const char *dest);
 da_result_t create_dir(const char *install_dir);
-da_result_t get_default_dir(char **out_path);
 da_result_t get_default_install_dir(char **out_path);
 
 #endif
index 68bb910..9973698 100755 (executable)
@@ -35,6 +35,7 @@ typedef enum
 
 typedef enum
 {
+       Q_EVENT_TYPE_CONTROL_NONE = 0,
        Q_EVENT_TYPE_CONTROL_CANCEL,
        Q_EVENT_TYPE_CONTROL_SUSPEND,
        Q_EVENT_TYPE_CONTROL_RESUME,
index 83d6a0f..44081bd 100755 (executable)
@@ -98,6 +98,7 @@ typedef struct {
        const char *file_name;
        const char *temp_file_path; /* For resume download, the "etag" value should be existed together */
        const char *etag; /* For resume download */
+       const char *pkg_name; /* For system resource */
        void *user_data;
 } extension_data_t;
 
index 2e03c80..5f143e9 100755 (executable)
 
 #define NO_EXTENSION_NAME_STR "dat"
 
+#define DD_MIME_STR "application/vnd.oma.dd+xml"
+#define DD_EXT_STR "*.dd"
+#define DRM_MIME_MSG_STR "application/vnd.oma.drm.message"
+#define DRM_EXT_STR "*.dm"
+#define DRM_MIME_CONTENT_STR "application/vnd.oma.drm.content"
+
 typedef struct {
        char *standard;
        char *normal;
index a549c23..2c4f55f 100755 (executable)
@@ -22,7 +22,6 @@
 #include "download-agent-utils.h"
 
 da_result_t get_user_agent_string(char **uagent_str);
-da_result_t get_storage_type(da_storage_type_t *type);
 char *get_proxy_address(void);
 
 #endif
index 4361ad5..ee73307 100755 (executable)
 #include "download-agent-interface.h"
 #include "download-agent-dl-mgr.h"
 
-/* Todo : move these to mime-util.c */
-#define MIME_DRM_MESSAGE       "application/vnd.oma.drm.message"
-#define MIME_ODF                               "application/vnd.oasis.opendocument.formula"
-#define MIME_OMA_DD                    "application/vnd.oma.dd+xml"
-#define MIME_MIDP_JAR          "application/vnd.sun.j2me.java-archive"
-#define MIME_MULTIPART_MESSAGE "multipart/related"
-#define MIME_TEXT_PLAIN                "text/plain"
-
 #define SAVE_FILE_BUFFERING_SIZE_50KB (50*1024)
 #define SAVE_FILE_BUFFERING_SIZE_5MB (5*1024*1024)
 
                nanosleep(&interval,&remainder); \
        } while(0)
 
-typedef enum {
-       DA_STORAGE_PHONE,                       /*To Store in Phone memory*/
-       DA_STORAGE_MMC,                     /*To Store in MMC */
-       DA_STORAGE_SYSTEM                       /*To Store in both Phone and MMC*/
-} da_storage_type_t;
-
 typedef struct _da_storage_size_t {
        unsigned long b_available;
        unsigned long b_size;
@@ -63,7 +49,7 @@ void get_random_number(int *out_num);
 da_result_t  get_available_dd_id(int *available_id);
 da_result_t  get_extension_from_mime_type(char *mime_type, char **extension);
 da_mime_type_id_t get_mime_type_id(char *content_type);
-da_result_t  get_available_memory(da_storage_type_t storage_type, da_storage_size_t *avail_memory);
+da_result_t  get_available_memory(da_storage_size_t *avail_memory);
 da_bool_t is_valid_url(const char *url, da_result_t *err_code);
 
 int read_data_from_file(char *file, char**out_buffer);
diff --git a/download-provider-schema.sql b/download-provider-schema.sql
new file mode 100644 (file)
index 0000000..44beda2
--- /dev/null
@@ -0,0 +1,74 @@
+CREATE TABLE IF NOT EXISTS groups
+(
+id INTEGER UNIQUE PRIMARY KEY,
+uid INTEGER DEFAULT 0,
+gid INTEGER DEFAULT 0,
+extra_int INTEGER DEFAULT 0,
+packagename TEXT DEFAULT NULL,
+smack_label TEXT DEFAULT NULL,
+extra TEXT DEFAULT NULL,
+date_first_connected DATE,
+date_last_connected DATE
+);
+
+CREATE TABLE IF NOT EXISTS logging
+(
+id INTEGER UNIQUE PRIMARY KEY,
+state INTEGER DEFAULT 0,
+errorcode INTEGER DEFAULT 0,
+startcount INTEGER DEFAULT 0,
+packagename TEXT DEFAULT NULL,
+createtime DATE,
+accesstime DATE
+);
+
+CREATE TABLE IF NOT EXISTS requestinfo
+(
+id INTEGER UNIQUE PRIMARY KEY,
+auto_download BOOLEAN DEFAULT 0,
+state_event BOOLEAN DEFAULT 0,
+progress_event BOOLEAN DEFAULT 0,
+noti_enable BOOLEAN DEFAULT 0,
+network_type TINYINT DEFAULT 0,
+filename TEXT DEFAULT NULL,
+destination TEXT DEFAULT NULL,
+url TEXT DEFAULT NULL,
+FOREIGN KEY(id) REFERENCES logging(id) ON DELETE CASCADE
+);
+
+CREATE TABLE IF NOT EXISTS downloadinfo
+(
+id INTEGER UNIQUE PRIMARY KEY,
+http_status INTEGER DEFAULT 0,
+content_size UNSIGNED BIG INT DEFAULT 0,
+mimetype VARCHAR(64) DEFAULT NULL,
+content_name TEXT DEFAULT NULL,
+saved_path TEXT DEFAULT NULL,
+tmp_saved_path TEXT DEFAULT NULL,
+etag TEXT DEFAULT NULL,
+FOREIGN KEY(id) REFERENCES logging(id) ON DELETE CASCADE
+);
+
+CREATE TABLE IF NOT EXISTS httpheaders
+(
+id INTEGER NOT NULL,
+header_field TEXT DEFAULT NULL,
+header_data TEXT DEFAULT NULL,
+FOREIGN KEY(id) REFERENCES logging(id) ON DELETE CASCADE
+);
+
+CREATE TABLE IF NOT EXISTS notification
+(
+id INTEGER NOT NULL,
+extra_key TEXT DEFAULT NULL,
+extra_data TEXT DEFAULT NULL,
+raw_bundle_data_complete_state BLOB DEFAULT NULL,
+raw_bundle_data_fail_state BLOB DEFAULT NULL,
+raw_bundle_data_ongoing_state BLOB DEFAULT NULL,
+title TEXT DEFAULT NULL,
+description TEXT DEFAULT NULL,
+noti_type INTEGER DEFAULT 0,
+FOREIGN KEY(id) REFERENCES logging(id) ON DELETE CASCADE
+);
+
+CREATE UNIQUE INDEX IF NOT EXISTS requests_index ON logging (id, state, errorcode, packagename, createtime, accesstime);
diff --git a/download-provider-service b/download-provider-service
deleted file mode 100644 (file)
index 40fa113..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-#!/bin/sh
-
-### A script for running download daemon in booting time.
-#dlogutil -v long -f /var/log/download-capi.log -r 100 -n 10 TIZEN_N_URL_DOWNLOAD &
-#dlogutil -v long -f /var/log/download-daemon.log -r 1000 -n 10 download-provider DownloadAgent &
-
-if [ -x /usr/bin/download-provider ]; then
-/usr/bin/download-provider &
-fi
diff --git a/download-provider.manifest b/download-provider.manifest
new file mode 100644 (file)
index 0000000..ffeb523
--- /dev/null
@@ -0,0 +1,34 @@
+<manifest>
+       <define>
+               <domain name="download-provider" />
+               <provide>
+                       <label name="download-provider::db" />
+               </provide>
+               <request>
+                       <smack request="download-provider::db" type="rw" />
+                       <smack request="system::use_internet" type="w" />
+                       <smack request="sys-assert::core" type="rwxat" />
+                       <smack request="device::sys_logging" type="w" />
+                       <smack request="system::media" type="arwxt" />
+                       <smack request="system::ext_media" type="arwxt" />
+                       <smack request="connman" type="rw" />
+                       <smack request="net-config" type="rw" />
+               </request>
+               <permit>
+                       <smack permit="org.tizen.indicator" type="rx" />
+                       <smack permit="org.tizen.quickpanel" type="rx" />
+                       <smack permit="system::use_internet" type="w" />
+               </permit>
+       </define>
+       <request>
+               <domain name="download-provider" />
+       </request>
+       <assign>
+               <filesystem path="/usr/lib/libdownload-provider-interface.so*" label="_" exec_label="none" />
+               <filesystem path="/usr/lib/libdownloadagent2.so*" label="_" exec_label="none" />
+               <filesystem path="/usr/lib/systemd/user/download-provider.service" label="_" exec_label="none" />
+               <filesystem path="/usr/lib/systemd/user/tizen-middleware.target.wants/download-provider.service" label="_" exec_label="none" />
+               <filesystem path="/usr/lib/systemd/user/download-provider.socket" label="_" exec_label="none" />
+               <filesystem path="/usr/lib/systemd/user/sockets.target.wants/download-provider.socket" label="_" exec_label="none" />
+       </assign>
+</manifest>
diff --git a/download-provider.rule b/download-provider.rule
new file mode 100644 (file)
index 0000000..9739e6d
--- /dev/null
@@ -0,0 +1,17 @@
+root download-provider rw---
+_default_ download-provider rw---
+download-provider _ -w---
+download-provider data-provider-master::notification.client -w---
+download-provider data-provider-master::notification rw---
+download-provider ail::db rw---
+download-provider device::app_logging -w---
+download-provider system::vconf rwx--
+download-provider system::ext_media rwxat
+download-provider system::media rwxat
+download-provider device::sys_logging -w---
+download-provider sys-assert::core rwxat
+download-provider system::use_internet -w---
+download-provider download-provider::db rw---
+system::use_internet download-provider -w---
+org.tizen.quickpanel download-provider r-x--
+org.tizen.indicator download-provider rwx--
diff --git a/org.download-provider.service.in b/org.download-provider.service.in
deleted file mode 100755 (executable)
index 76676fa..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-[D-BUS Service]
-Name=org.download-provider
-Exec=/usr/bin/download-provider service
-User=root
diff --git a/packaging/download-provider.changes b/packaging/download-provider.changes
deleted file mode 100644 (file)
index f8c2e3b..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-* Tue Nov 26 2013 Baptiste DURAND <baptiste.durand@eurogiciel.fr> ivi_oct_m2@db80c75
-- Fix TIVI-2045 : move systemd service from user directory to system directory
-- add dbus policy conf file
-- keep only one %manifest entry in spec file
-- Fix and install .service files into dbus system service directory
-
-* Wed Jun 05 2013 Xavier Roche <xavrock.os@gmail.com> submit/tizen/20130523.172942@a691ed7
-- Replace manifest with default floor
-
-* Wed Jun 05 2013 Xavier Roche <xavrock.os@gmail.com> submit/tizen/20130523.172942@cc56f08
-- Fix rpmlint issues
-
-* Tue May 21 2013 Rusty Lynch <rusty.lynch@intel.com> accepted/tizen/20130520.101559@b4e2464
-- Fix spec file according to RPMLINT rules
-- Fix build for 64 bits arch
-
diff --git a/packaging/download-provider.manifest b/packaging/download-provider.manifest
deleted file mode 100644 (file)
index 017d22d..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-<manifest>
- <request>
-    <domain name="_"/>
- </request>
-</manifest>
index 740e723..81ed6f7 100755 (executable)
@@ -1,23 +1,26 @@
-
 Name:       download-provider
 Summary:    Download the contents in background
-Version:    1.0.5
-Release:    10
+Version:    1.1.6
+Release:    0
 Group:      Development/Libraries
 License:    Apache License, Version 2.0
 Source0:    %{name}-%{version}.tar.gz
-Source1:    download-provider.service
-Source101:  org.download-provider.conf
-Source1001:    download-provider.manifest
-Requires(post): /usr/bin/sqlite3
+Requires(post): sys-assert
+Requires(post): libdevice-node
+Requires(post): org.tizen.indicator
+Requires(post): org.tizen.quickpanel
+Requires(post): sqlite
+Requires(post): connman
+Requires(post): /sbin/ldconfig
+Requires(postun): /sbin/ldconfig
 BuildRequires:  cmake
+BuildRequires:  libprivilege-control-conf
 BuildRequires:  pkgconfig(glib-2.0)
 BuildRequires:  pkgconfig(gobject-2.0)
 BuildRequires:  pkgconfig(dlog)
 BuildRequires:  pkgconfig(libsoup-2.4)
 BuildRequires:  pkgconfig(xdgmime)
 BuildRequires:  pkgconfig(vconf)
-BuildRequires:  pkgconfig(db-util)
 BuildRequires:  pkgconfig(sqlite3)
 BuildRequires:  pkgconfig(bundle)
 BuildRequires:  pkgconfig(capi-base-common)
@@ -25,10 +28,11 @@ BuildRequires:  pkgconfig(capi-appfw-app-manager)
 BuildRequires:  pkgconfig(capi-network-connection)
 BuildRequires:  pkgconfig(notification)
 BuildRequires:  pkgconfig(appsvc)
-BuildRequires:  pkgconfig(dbus-1)
 BuildRequires:  pkgconfig(wifi-direct)
-Requires(post): /sbin/ldconfig
-Requires(postun): /sbin/ldconfig
+BuildRequires:  pkgconfig(libsmack)
+BuildRequires:  gettext-devel
+BuildRequires:  pkgconfig(libsystemd-daemon)
+
 %description
 Description: download the contents in background
 
@@ -38,19 +42,20 @@ Group:      Development/Libraries
 Requires:   %{name} = %{version}-%{release}
 
 %description devel
-Description: download the contents in background (developement files)
+Description: download the contents in background (development files)
 
 %prep
 %setup -q
-cp %{SOURCE101} .
-cp %{SOURCE1001} .
 
-%define _imagedir /usr/share/download-provider
+%define _data_install_path /usr/share/%{name}
+%define _imagedir %{_data_install_path}/images
+%define _localedir %{_data_install_path}/locales
+%define _sqlschemadir %{_data_install_path}/sql
 %define _databasedir /opt/usr/dbspace
 %define _databasefile %{_databasedir}/.download-provider.db
-%define _dbusservicedir /usr/share/dbus-1/system-services
-%define _dbuspolicydir /etc/dbus-1/system.d
+%define _sqlschemafile %{_sqlschemadir}/download-provider-schema.sql
 %define _licensedir /usr/share/license
+%define _smackruledir /opt/etc/smack/accesses.d
 
 %define cmake \
        CFLAGS="${CFLAGS:-%optflags} -fPIC -D_REENTRANT -fvisibility=hidden"; export CFLAGS \
@@ -65,10 +70,12 @@ cp %{SOURCE1001} .
                -DPKG_VERSION=%{version} \\\
                -DPKG_RELEASE=%{release} \\\
                -DIMAGE_DIR:PATH=%{_imagedir} \\\
+               -DLOCALE_DIR:PATH=%{_localedir} \\\
+               -DDATABASE_SCHEMA_DIR=%{_sqlschemadir} \\\
                -DDATABASE_FILE:PATH=%{_databasefile} \\\
-               -DDBUS_SERVICE_DIR:PATH=%{_dbusservicedir} \\\
+               -DDATABASE_SCHEMA_FILE=%{_sqlschemafile} \\\
                -DLICENSE_DIR:PATH=%{_licensedir} \\\
-               -DSUPPORT_DBUS_SYSTEM:BOOL=ON \\\
+               -DSMACK_RULE_DIR:PATH=%{_smackruledir} \\\
                -DSUPPORT_WIFI_DIRECT:BOOL=OFF \\\
                -DSUPPORT_LOG_MESSAGE:BOOL=ON \\\
                -DSUPPORT_CHECK_IPC:BOOL=ON \\\
@@ -79,122 +86,66 @@ cp %{SOURCE1001} .
                -DBUILD_SHARED_LIBS:BOOL=ON
 
 %build
+%if 0%{?tizen_build_binary_release_type_eng}
+export CFLAGS="$CFLAGS -DTIZEN_ENGINEER_MODE"
+export CXXFLAGS="$CXXFLAGS -DTIZEN_ENGINEER_MODE"
+export FFLAGS="$FFLAGS -DTIZEN_ENGINEER_MODE"
+%endif
 %cmake .
 make %{?jobs:-j%jobs}
 
 %install
 rm -rf %{buildroot}
 %make_install
-
-install -d -m 755 %{buildroot}%{_dbuspolicydir}
-install -m 644 %{SOURCE101} %{buildroot}%{_dbuspolicydir}
-
 mkdir -p %{buildroot}%{_licensedir}
-mkdir -p  %{buildroot}%{_sysconfdir}/rc.d/rc3.d
-ln -s %{_sysconfdir}/rc.d/init.d/download-provider-service  %{buildroot}%{_sysconfdir}/rc.d/rc3.d/S70download-provider-service
-mkdir -p  %{buildroot}%{_sysconfdir}/rc.d/rc5.d
-ln -s %{_sysconfdir}/rc.d/init.d/download-provider-service  %{buildroot}%{_sysconfdir}/rc.d/rc5.d/S70download-provider-service
-
-mkdir -p %{buildroot}/%{_unitdir}/graphical.target.wants
-install %{SOURCE1} %{buildroot}/%{_unitdir}/
-ln -s ../download-provider.service %{buildroot}/%{_unitdir}/graphical.target.wants/
-
-mkdir -p %{buildroot}/opt/data/%{name}
-mkdir -p %{buildroot}%{_databasedir}
-if [ ! -f %{buildroot}%{_databasefile} ];
-then
-sqlite3 %{buildroot}%{_databasefile} 'PRAGMA journal_mode=PERSIST;
-PRAGMA foreign_keys=ON;
-CREATE TABLE logging
-(
-id INTEGER UNIQUE PRIMARY KEY,
-state INTEGER DEFAULT 0,
-errorcode INTEGER DEFAULT 0,
-startcount INTEGER DEFAULT 0,
-packagename TEXT DEFAULT NULL,
-createtime DATE,
-accesstime DATE
-);
-
-CREATE TABLE requestinfo
-(
-id INTEGER UNIQUE PRIMARY KEY,
-auto_download BOOLEAN DEFAULT 0,
-state_event BOOLEAN DEFAULT 0,
-progress_event BOOLEAN DEFAULT 0,
-noti_enable BOOLEAN DEFAULT 0,
-network_type TINYINT DEFAULT 0,
-filename TEXT DEFAULT NULL,
-destination TEXT DEFAULT NULL,
-url TEXT DEFAULT NULL,
-FOREIGN KEY(id) REFERENCES logging(id) ON DELETE CASCADE
-);
-
-CREATE TABLE downloadinfo
-(
-id INTEGER UNIQUE PRIMARY KEY,
-http_status INTEGER DEFAULT 0,
-content_size UNSIGNED BIG INT DEFAULT 0,
-mimetype VARCHAR(64) DEFAULT NULL,
-content_name TEXT DEFAULT NULL,
-saved_path TEXT DEFAULT NULL,
-tmp_saved_path TEXT DEFAULT NULL,
-etag TEXT DEFAULT NULL,
-FOREIGN KEY(id) REFERENCES logging(id) ON DELETE CASCADE
-);
-
-CREATE TABLE httpheaders
-(
-id INTEGER NOT NULL,
-header_field TEXT DEFAULT NULL,
-header_data TEXT DEFAULT NULL,
-FOREIGN KEY(id) REFERENCES logging(id) ON DELETE CASCADE
-);
-
-CREATE TABLE notification
-(
-id INTEGER NOT NULL,
-extra_key TEXT DEFAULT NULL,
-extra_data TEXT DEFAULT NULL,
-FOREIGN KEY(id) REFERENCES logging(id) ON DELETE CASCADE
-);
-
-CREATE UNIQUE INDEX requests_index ON logging (id, state, errorcode, packagename, createtime, accesstime);
-'
-fi
+mkdir -p %{buildroot}/%{_data_install_path}
+mkdir -p %{buildroot}%{_libdir}/systemd/system/graphical.target.wants
+mkdir -p %{buildroot}%{_libdir}/systemd/system/sockets.target.wants
+ln -s ../download-provider.service %{buildroot}%{_libdir}/systemd/system/graphical.target.wants/
+ln -s ../download-provider.socket %{buildroot}%{_libdir}/systemd/system/sockets.target.wants/
 
+%post devel
+/sbin/ldconfig
 
-%post
+%postun devel
 /sbin/ldconfig
 
 %postun
 /sbin/ldconfig
 
+%post
+mkdir -p %{_databasedir}
+/sbin/ldconfig
+
+if [ ! -f %{_databasefile} ];
+then
+sqlite3 %{_databasefile} '.read %{_sqlschemafile}'
+chmod 660 %{_databasefile}
+chmod 660 %{_databasefile}-journal
+fi
 
 %files
 %defattr(-,root,root,-)
-%manifest %{name}.manifest
-%dir %attr(0775,root,app) /opt/data/%{name}
+%manifest download-provider.manifest
 %{_imagedir}/*.png
+%{_imagedir}/*.gif
+%{_localedir}/*
 %{_libdir}/libdownloadagent2.so.0.0.1
 %{_libdir}/libdownloadagent2.so
-%{_unitdir}/download-provider.service
-%{_unitdir}/graphical.target.wants/download-provider.service
+%{_libdir}/systemd/system/download-provider.service
+%{_libdir}/systemd/system/graphical.target.wants/download-provider.service
+%{_libdir}/systemd/system/download-provider.socket
+%{_libdir}/systemd/system/sockets.target.wants/download-provider.socket
 %{_libdir}/libdownload-provider-interface.so.%{version}
 %{_libdir}/libdownload-provider-interface.so.0
 %{_bindir}/%{name}
-%{_sysconfdir}/rc.d/init.d/download-provider-service
-%{_sysconfdir}/rc.d/rc3.d/S70download-provider-service
-%{_sysconfdir}/rc.d/rc5.d/S70download-provider-service
 %{_licensedir}/%{name}
-%{_dbusservicedir}/org.download-provider.service
-%{_dbuspolicydir}/org.download-provider.conf
-%attr(660,root,app) /opt/usr/dbspace/.download-provider.db
-%attr(660,root,app) /opt/usr/dbspace/.download-provider.db-journal
+%{_smackruledir}/%{name}.rule
+%{_sqlschemafile}
 
 %files devel
-%manifest %{name}.manifest
 %defattr(-,root,root,-)
+%{_libdir}/libdownloadagent2.so.0.0.1
 %{_libdir}/libdownloadagent2.so
 %{_libdir}/libdownload-provider-interface.so
 %{_includedir}/download-provider/download-provider-defs.h
@@ -203,3 +154,4 @@ fi
 %{_libdir}/pkgconfig/download-provider.pc
 %{_libdir}/pkgconfig/download-provider-interface.pc
 
+%changelog
diff --git a/packaging/org.download-provider.conf b/packaging/org.download-provider.conf
deleted file mode 100644 (file)
index 945c394..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
- "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
-<busconfig>
-    <policy user="root">
-        <allow own="org.download-provider"/>
-    </policy>
-    <policy context="default">
-        <allow send_destination="org.download-provider"/>
-    </policy>
-</busconfig>
-
diff --git a/po/CMakeLists.txt b/po/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..9e2d8c6
--- /dev/null
@@ -0,0 +1,28 @@
+# for i18n
+
+SET(POFILES ar.po az.po bg.po ca.po cs.po da.po de_DE.po el_GR.po en.po en_PH.po
+       en_US.po es_ES.po es_MX.po et.po eu.po fi.po fr_CA.po fr_FR.po ga.po gl.po hi.po
+       hr.po hu.po hy.po is.po it_IT.po ja_JP.po ka.po kk.po ko_KR.po lt.po lv.po mk.po
+       nb.po nl_NL.po pl.po pt_BR.po pt_PT.po ro.po ru_RU.po sk.po sl.po sr.po sv.po
+       tr_TR.po uk.po uz.po zh_CN.po zh_HK.po zh_SG.po zh_TW.po)
+
+SET(MSGFMT "/usr/bin/msgfmt")
+
+FOREACH(pofile ${POFILES})
+       SET(pofile ${CMAKE_CURRENT_SOURCE_DIR}/${pofile})
+       MESSAGE("PO: ${pofile}")
+       GET_FILENAME_COMPONENT(absPofile ${pofile} ABSOLUTE)
+       GET_FILENAME_COMPONENT(lang ${absPofile} NAME_WE)
+       SET(moFile ${CMAKE_CURRENT_BINARY_DIR}/${lang}.mo)
+       ADD_CUSTOM_COMMAND(
+                       OUTPUT ${moFile}
+                       COMMAND ${MSGFMT} -o ${moFile} ${absPofile}
+                       DEPENDS ${absPofile}
+       )
+       INSTALL(FILES ${moFile}
+                       DESTINATION ${LOCALE_DIR}/${lang}/LC_MESSAGES RENAME ${PKG_NAME}.mo)
+       SET(moFiles ${moFiles} ${moFile})
+ENDFOREACH(pofile)
+
+MESSAGE(".mo files: ${moFiles}")
+ADD_CUSTOM_TARGET(po ALL DEPENDS ${moFiles})
diff --git a/po/POTFILES.in.in b/po/POTFILES.in.in
new file mode 100755 (executable)
index 0000000..bcb7f1f
--- /dev/null
@@ -0,0 +1,2 @@
+# List of source files containing translatable strings.
+@@APPNAME@@.c
diff --git a/po/ar.po b/po/ar.po
new file mode 100755 (executable)
index 0000000..db4e25e
--- /dev/null
+++ b/po/ar.po
@@ -0,0 +1,3 @@
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "تم التنزيل"
+
diff --git a/po/az.po b/po/az.po
new file mode 100755 (executable)
index 0000000..8120d37
--- /dev/null
+++ b/po/az.po
@@ -0,0 +1,3 @@
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Yükləmə tamamlandı"
+
diff --git a/po/bg.po b/po/bg.po
new file mode 100755 (executable)
index 0000000..b8b9584
--- /dev/null
+++ b/po/bg.po
@@ -0,0 +1,3 @@
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Изтеглянето завършено"
+
diff --git a/po/ca.po b/po/ca.po
new file mode 100755 (executable)
index 0000000..291f7a7
--- /dev/null
+++ b/po/ca.po
@@ -0,0 +1,3 @@
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Descàrrega completa"
+
diff --git a/po/cs.po b/po/cs.po
new file mode 100755 (executable)
index 0000000..cf228be
--- /dev/null
+++ b/po/cs.po
@@ -0,0 +1,3 @@
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Stahování dokončeno"
+
diff --git a/po/da.po b/po/da.po
new file mode 100755 (executable)
index 0000000..ffba089
--- /dev/null
+++ b/po/da.po
@@ -0,0 +1,3 @@
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Overførsel fuldført"
+
diff --git a/po/de_DE.po b/po/de_DE.po
new file mode 100755 (executable)
index 0000000..1c9c61a
--- /dev/null
@@ -0,0 +1,3 @@
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Download beendet"
+
diff --git a/po/el_GR.po b/po/el_GR.po
new file mode 100755 (executable)
index 0000000..29efbc7
--- /dev/null
@@ -0,0 +1,3 @@
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Η λήψη ολοκληρώθηκε"
+
diff --git a/po/en.po b/po/en.po
new file mode 100755 (executable)
index 0000000..03ffa61
--- /dev/null
+++ b/po/en.po
@@ -0,0 +1,3 @@
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Download complete"
+
diff --git a/po/en_PH.po b/po/en_PH.po
new file mode 100755 (executable)
index 0000000..03ffa61
--- /dev/null
@@ -0,0 +1,3 @@
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Download complete"
+
diff --git a/po/en_US.po b/po/en_US.po
new file mode 100755 (executable)
index 0000000..03ffa61
--- /dev/null
@@ -0,0 +1,3 @@
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Download complete"
+
diff --git a/po/es_ES.po b/po/es_ES.po
new file mode 100755 (executable)
index 0000000..3cd494a
--- /dev/null
@@ -0,0 +1,3 @@
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Descarga completa"
+
diff --git a/po/es_MX.po b/po/es_MX.po
new file mode 100755 (executable)
index 0000000..3cd494a
--- /dev/null
@@ -0,0 +1,3 @@
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Descarga completa"
+
diff --git a/po/et.po b/po/et.po
new file mode 100755 (executable)
index 0000000..4ad6fad
--- /dev/null
+++ b/po/et.po
@@ -0,0 +1,3 @@
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Allalaadimine on lõpule viidud"
+
diff --git a/po/eu.po b/po/eu.po
new file mode 100755 (executable)
index 0000000..b1e418a
--- /dev/null
+++ b/po/eu.po
@@ -0,0 +1,3 @@
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Deskarga osatuta"
+
diff --git a/po/fi.po b/po/fi.po
new file mode 100755 (executable)
index 0000000..058a8d6
--- /dev/null
+++ b/po/fi.po
@@ -0,0 +1,3 @@
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Lataus valmis"
+
diff --git a/po/fr_CA.po b/po/fr_CA.po
new file mode 100755 (executable)
index 0000000..64e4156
--- /dev/null
@@ -0,0 +1,3 @@
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Téléchargement terminé"
+
diff --git a/po/fr_FR.po b/po/fr_FR.po
new file mode 100755 (executable)
index 0000000..64e4156
--- /dev/null
@@ -0,0 +1,3 @@
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Téléchargement terminé"
+
diff --git a/po/ga.po b/po/ga.po
new file mode 100755 (executable)
index 0000000..5e9474a
--- /dev/null
+++ b/po/ga.po
@@ -0,0 +1,3 @@
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Íoslódáilte"
+
diff --git a/po/gl.po b/po/gl.po
new file mode 100755 (executable)
index 0000000..3cd494a
--- /dev/null
+++ b/po/gl.po
@@ -0,0 +1,3 @@
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Descarga completa"
+
diff --git a/po/hi.po b/po/hi.po
new file mode 100755 (executable)
index 0000000..5ece567
--- /dev/null
+++ b/po/hi.po
@@ -0,0 +1,3 @@
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "डाउनलोड पूर्ण"
+
diff --git a/po/hr.po b/po/hr.po
new file mode 100755 (executable)
index 0000000..b4ae9f2
--- /dev/null
+++ b/po/hr.po
@@ -0,0 +1,3 @@
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Skidanje dovršeno"
+
diff --git a/po/hu.po b/po/hu.po
new file mode 100755 (executable)
index 0000000..239c6b9
--- /dev/null
+++ b/po/hu.po
@@ -0,0 +1,3 @@
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "A letöltés befejeződött"
+
diff --git a/po/hy.po b/po/hy.po
new file mode 100755 (executable)
index 0000000..12ea497
--- /dev/null
+++ b/po/hy.po
@@ -0,0 +1,3 @@
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Ներբեռնումն ավարտվեց"
+
diff --git a/po/is.po b/po/is.po
new file mode 100755 (executable)
index 0000000..470a453
--- /dev/null
+++ b/po/is.po
@@ -0,0 +1,3 @@
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Niðurhali lokið"
+
diff --git a/po/it_IT.po b/po/it_IT.po
new file mode 100755 (executable)
index 0000000..e96495c
--- /dev/null
@@ -0,0 +1,3 @@
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Download completato"
+
diff --git a/po/ja_JP.po b/po/ja_JP.po
new file mode 100755 (executable)
index 0000000..41ea60e
--- /dev/null
@@ -0,0 +1,3 @@
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "ダウンロード完了"
+
diff --git a/po/ka.po b/po/ka.po
new file mode 100755 (executable)
index 0000000..10a084d
--- /dev/null
+++ b/po/ka.po
@@ -0,0 +1,3 @@
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "ჩამოტვირთვა დასრულდა"
+
diff --git a/po/kk.po b/po/kk.po
new file mode 100755 (executable)
index 0000000..40ff8b2
--- /dev/null
+++ b/po/kk.po
@@ -0,0 +1,3 @@
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Жүктеу аяқталды"
+
diff --git a/po/ko_KR.po b/po/ko_KR.po
new file mode 100755 (executable)
index 0000000..1f47a18
--- /dev/null
@@ -0,0 +1,3 @@
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "다운로드 완료"
+
diff --git a/po/lt.po b/po/lt.po
new file mode 100755 (executable)
index 0000000..ea1075f
--- /dev/null
+++ b/po/lt.po
@@ -0,0 +1,3 @@
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Atsisiuntimas baigtas"
+
diff --git a/po/lv.po b/po/lv.po
new file mode 100755 (executable)
index 0000000..d3bf10c
--- /dev/null
+++ b/po/lv.po
@@ -0,0 +1,3 @@
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Lejupielāde pabeigta"
+
diff --git a/po/mk.po b/po/mk.po
new file mode 100755 (executable)
index 0000000..8ae0de2
--- /dev/null
+++ b/po/mk.po
@@ -0,0 +1,3 @@
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Преземањето заврши"
+
diff --git a/po/nb.po b/po/nb.po
new file mode 100755 (executable)
index 0000000..33af7b7
--- /dev/null
+++ b/po/nb.po
@@ -0,0 +1,3 @@
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Nedlasting fullført"
+
diff --git a/po/nl_NL.po b/po/nl_NL.po
new file mode 100755 (executable)
index 0000000..2273390
--- /dev/null
@@ -0,0 +1,3 @@
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Downloaden voltooid"
+
diff --git a/po/pl.po b/po/pl.po
new file mode 100755 (executable)
index 0000000..8a48b82
--- /dev/null
+++ b/po/pl.po
@@ -0,0 +1,3 @@
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Pobieranie zakończone"
+
diff --git a/po/pt_BR.po b/po/pt_BR.po
new file mode 100755 (executable)
index 0000000..f97065e
--- /dev/null
@@ -0,0 +1,3 @@
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Download concluído"
+
diff --git a/po/pt_PT.po b/po/pt_PT.po
new file mode 100755 (executable)
index 0000000..cbe7377
--- /dev/null
@@ -0,0 +1,3 @@
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Transferência concluída"
+
diff --git a/po/ro.po b/po/ro.po
new file mode 100755 (executable)
index 0000000..d82366c
--- /dev/null
+++ b/po/ro.po
@@ -0,0 +1,3 @@
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Descărcare finalizată"
+
diff --git a/po/ru_RU.po b/po/ru_RU.po
new file mode 100755 (executable)
index 0000000..27aa56c
--- /dev/null
@@ -0,0 +1,3 @@
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Загрузка завершена"
+
diff --git a/po/sk.po b/po/sk.po
new file mode 100755 (executable)
index 0000000..178001d
--- /dev/null
+++ b/po/sk.po
@@ -0,0 +1,3 @@
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Sťahovanie je dokončené"
+
diff --git a/po/sl.po b/po/sl.po
new file mode 100755 (executable)
index 0000000..d031ce5
--- /dev/null
+++ b/po/sl.po
@@ -0,0 +1,3 @@
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Prenos je končan"
+
diff --git a/po/sr.po b/po/sr.po
new file mode 100755 (executable)
index 0000000..e21e6d3
--- /dev/null
+++ b/po/sr.po
@@ -0,0 +1,3 @@
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Preuzimanje završeno"
+
diff --git a/po/sv.po b/po/sv.po
new file mode 100755 (executable)
index 0000000..8f0dce9
--- /dev/null
+++ b/po/sv.po
@@ -0,0 +1,3 @@
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Hämtningen är klar"
+
diff --git a/po/tr_TR.po b/po/tr_TR.po
new file mode 100755 (executable)
index 0000000..ec760e5
--- /dev/null
@@ -0,0 +1,3 @@
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "İndirme tamamlandı"
+
diff --git a/po/uk.po b/po/uk.po
new file mode 100755 (executable)
index 0000000..504e5f1
--- /dev/null
+++ b/po/uk.po
@@ -0,0 +1,3 @@
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Завантаження завершено"
+
diff --git a/po/uz.po b/po/uz.po
new file mode 100755 (executable)
index 0000000..c97fec7
--- /dev/null
+++ b/po/uz.po
@@ -0,0 +1,3 @@
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Yuklab olish yakunlandi"
+
diff --git a/po/zh_CN.po b/po/zh_CN.po
new file mode 100755 (executable)
index 0000000..3238acd
--- /dev/null
@@ -0,0 +1,3 @@
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "下载完成"
+
diff --git a/po/zh_HK.po b/po/zh_HK.po
new file mode 100755 (executable)
index 0000000..51101ba
--- /dev/null
@@ -0,0 +1,3 @@
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "下載完成"
+
diff --git a/po/zh_SG.po b/po/zh_SG.po
new file mode 100755 (executable)
index 0000000..3238acd
--- /dev/null
@@ -0,0 +1,3 @@
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "下载完成"
+
diff --git a/po/zh_TW.po b/po/zh_TW.po
new file mode 100755 (executable)
index 0000000..51101ba
--- /dev/null
@@ -0,0 +1,3 @@
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "下載完成"
+
index 1253d80..eb523c4 100755 (executable)
@@ -8,7 +8,7 @@ IF("${CMAKE_BUILD_TYPE}" STREQUAL "")
 ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "")
 MESSAGE("Build type: ${CMAKE_BUILD_TYPE}")
 
-SET(PC_REQUIRED "glib-2.0 gobject-2.0 dlog capi-base-common capi-appfw-app-manager dbus-1")
+SET(PC_REQUIRED "glib-2.0 gobject-2.0 dlog capi-base-common capi-appfw-app-manager bundle")
 
 INCLUDE(FindPkgConfig)
 
index 2705077..5bccd8c 100755 (executable)
 #include <download-provider-interface.h>
 #include <download-provider.h>
 
-#ifdef DP_DBUS_ACTIVATION
-#include <dbus/dbus.h>
-#endif
-
 #ifdef SUPPORT_CHECK_IPC
 #include <sys/ioctl.h>
 #endif
 
 #define DP_CHECK_CONNECTION do {\
-       TRACE_INFO("");\
        if (__check_connections() != DP_ERROR_NONE) {\
                pthread_mutex_unlock(&g_function_mutex);\
                return DOWNLOAD_ADAPTOR_ERROR_IO_ERROR;\
@@ -52,9 +47,9 @@
        errorcode = __ipc_check_ready_status(g_interface_info->cmd_socket);\
        if (errorcode != DP_ERROR_NONE) {\
                pthread_mutex_unlock(&g_interface_info->mutex);\
-               pthread_mutex_unlock(&g_function_mutex);\
                if (errorcode == DP_ERROR_IO_ERROR)\
                        __disconnect_from_provider();\
+               pthread_mutex_unlock(&g_function_mutex);\
                return DOWNLOAD_ADAPTOR_ERROR_IO_ERROR;\
        }\
 } while(0)
 #undef LOG_TAG
 #endif
 #define LOG_TAG "DOWNLOAD_PROVIDER_INTERFACE"
-#define TRACE_ERROR(format, ARG...)  \
-{ \
-LOGE(format, ##ARG); \
-}
-#define TRACE_STRERROR(format, ARG...)  \
-{ \
-LOGE(format" [%s]", ##ARG, strerror(errno)); \
-}
-#define TRACE_INFO(format, ARG...)  \
-{ \
-LOGI(format, ##ARG); \
-}
+#define TRACE_DEBUG(format, ARG...) LOGD(format, ##ARG)
+#define TRACE_ERROR(format, ARG...) LOGE(format, ##ARG)
+#define TRACE_STRERROR(format, ARG...) LOGE(format" [%s]", ##ARG, strerror(errno))
+#define TRACE_INFO(format, ARG...) LOGI(format, ##ARG)
+
+#ifdef SECURE_LOGD
+#define TRACE_SECURE_DEBUG(format, ARG...) SECURE_LOGD(format, ##ARG)
 #else
-#define TRACE_ERROR(format, ARG...) ;
-#define TRACE_STRERROR(format, ARG...) ;
-#define TRACE_INFO(format, ARG...) ;
+#define TRACE_SECURE_DEBUG(...) do { } while(0)
+#endif
+#ifdef SECURE_LOGI
+#define TRACE_SECURE_INFO(format, ARG...) SECURE_LOGI(format, ##ARG)
+#else
+#define TRACE_SECURE_INFO(...) do { } while(0)
+#endif
+#ifdef SECURE_LOGE
+#define TRACE_SECURE_ERROR(format, ARG...) SECURE_LOGE(format, ##ARG)
+#else
+#define TRACE_SECURE_ERROR(...) do { } while(0)
+#endif
+
+#else
+#define TRACE_DEBUG(...) do { } while(0)
+#define TRACE_ERROR(...) do { } while(0)
+#define TRACE_STRERROR(...) do { } while(0)
+#define TRACE_INFO(...) do { } while(0)
+#define TRACE_SECURE_DEBUG(...) do { } while(0)
+#define TRACE_SECURE_INFO(...) do { } while(0)
+#define TRACE_SECURE_ERROR(...) do { } while(0)
 #endif
 
 // define type
@@ -117,49 +125,9 @@ typedef struct {
 dp_interface_info *g_interface_info = NULL;
 dp_interface_slot g_interface_slots[MAX_DOWNLOAD_HANDLE];
 static pthread_mutex_t g_function_mutex = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t g_clear_mutex = PTHREAD_MUTEX_INITIALIZER;
 static pthread_t g_interface_event_thread_id = 0;
 
-#ifdef DP_DBUS_ACTIVATION
-/* DBUS Activation */
-static int __dp_call_dp_interface_service(void)
-{
-       DBusConnection *connection = NULL;
-       DBusError dbus_error;
-
-       dbus_error_init(&dbus_error);
-
-       connection = dbus_bus_get(DBUS_BUS_SYSTEM, &dbus_error);
-       if (connection == NULL) {
-               TRACE_ERROR("[ERROR] dbus_bus_get");
-               if (dbus_error_is_set(&dbus_error)) {
-                       TRACE_ERROR("[DBUS] dbus_bus_get: %s", dbus_error.message);
-                       dbus_error_free(&dbus_error);
-               }
-               return -1;
-       }
-
-       dbus_uint32_t result = 0;
-       if (dbus_bus_start_service_by_name
-                       (connection,
-                       DP_DBUS_SERVICE_DBUS, 0, &result, &dbus_error) == FALSE) {
-               if (dbus_error_is_set(&dbus_error)) {
-                       TRACE_ERROR("[DBUS] dbus_bus_start_service_by_name: %s",
-                               dbus_error.message);
-                       dbus_error_free(&dbus_error);
-               }
-               dbus_connection_unref(connection);
-               return -1;
-       }
-       if (result == DBUS_START_REPLY_ALREADY_RUNNING) {
-               TRACE_INFO("DBUS_START_REPLY_ALREADY_RUNNING [%d]", result);
-       } else if (result == DBUS_START_REPLY_SUCCESS) {
-               TRACE_INFO("DBUS_START_REPLY_SUCCESS [%d]", result);
-       }
-       dbus_connection_unref(connection);
-       return 0;
-}
-#endif
-
 //////////// defines functions /////////////////
 
 
@@ -173,10 +141,12 @@ static int __dp_interface_convert_network_adaptor(int type)
                return DP_NETWORK_TYPE_DATA_NETWORK;
        case DOWNLOAD_ADAPTOR_NETWORK_WIFI_DIRECT:
                return DP_NETWORK_TYPE_WIFI_DIRECT;
+       case DOWNLOAD_ADAPTOR_NETWORK_ALL:
+               return DP_NETWORK_TYPE_ALL;
        default:
                break;
        }
-       return DP_NETWORK_TYPE_ALL;
+       return type;
 }
 
 static int __dp_interface_convert_network_provider(int type)
@@ -188,41 +158,43 @@ static int __dp_interface_convert_network_provider(int type)
                return DOWNLOAD_ADAPTOR_NETWORK_DATA_NETWORK;
        case DP_NETWORK_TYPE_WIFI_DIRECT:
                return DOWNLOAD_ADAPTOR_NETWORK_WIFI_DIRECT;
+       case DOWNLOAD_ADAPTOR_NETWORK_ALL:
+               return DP_NETWORK_TYPE_ALL;
        default:
                break;
        }
-       return DOWNLOAD_ADAPTOR_NETWORK_ALL;
+       return type;
 }
 
 static int __dp_interface_convert_state(int state)
 {
        switch (state) {
        case DP_STATE_READY:
-               TRACE_INFO("READY");
+               TRACE_DEBUG("READY");
                return DOWNLOAD_ADPATOR_STATE_READY;
        case DP_STATE_CONNECTING:
-               TRACE_INFO("CONNECTING/QUEUED");
+               TRACE_DEBUG("CONNECTING/QUEUED");
                return DOWNLOAD_ADPATOR_STATE_QUEUED;
        case DP_STATE_QUEUED:
-               TRACE_INFO("QUEUED");
+               TRACE_DEBUG("QUEUED");
                return DOWNLOAD_ADPATOR_STATE_QUEUED;
        case DP_STATE_DOWNLOADING:
-               TRACE_INFO("DOWNLOADING");
+               TRACE_DEBUG("DOWNLOADING");
                return DOWNLOAD_ADPATOR_STATE_DOWNLOADING;
        case DP_STATE_PAUSE_REQUESTED:
-               TRACE_INFO("PAUSE_REQUESTED/DOWNLOADING");
+               TRACE_DEBUG("PAUSE_REQUESTED/DOWNLOADING");
                return DOWNLOAD_ADPATOR_STATE_DOWNLOADING;
        case DP_STATE_PAUSED:
-               TRACE_INFO("PAUSED");
+               TRACE_DEBUG("PAUSED");
                return DOWNLOAD_ADPATOR_STATE_PAUSED;
        case DP_STATE_COMPLETED:
-               TRACE_INFO("COMPLETED");
+               TRACE_DEBUG("COMPLETED");
                return DOWNLOAD_ADPATOR_STATE_COMPLETED;
        case DP_STATE_CANCELED:
-               TRACE_INFO("CANCELED");
+               TRACE_DEBUG("CANCELED");
                return DOWNLOAD_ADPATOR_STATE_CANCELED;
        case DP_STATE_FAILED:
-               TRACE_INFO("FAILED");
+               TRACE_DEBUG("FAILED");
                return DOWNLOAD_ADPATOR_STATE_FAILED;
        default:
                break;
@@ -234,70 +206,72 @@ static int __dp_interface_convert_errorcode(int errorcode)
 {
        switch (errorcode) {
        case DP_ERROR_NONE:
-               TRACE_INFO("ERROR_NONE");
                return DOWNLOAD_ADAPTOR_ERROR_NONE;
        case DP_ERROR_INVALID_PARAMETER:
-               TRACE_INFO("ERROR_INVALID_PARAMETER");
+               TRACE_DEBUG("ERROR_INVALID_PARAMETER");
                return DOWNLOAD_ADAPTOR_ERROR_INVALID_PARAMETER;
        case DP_ERROR_OUT_OF_MEMORY:
-               TRACE_INFO("ERROR_OUT_OF_MEMORY");
+               TRACE_DEBUG("ERROR_OUT_OF_MEMORY");
                return DOWNLOAD_ADAPTOR_ERROR_OUT_OF_MEMORY;
        case DP_ERROR_IO_EAGAIN:
-               TRACE_INFO("ERROR_IO_ERROR(EAGAIN)");
+               TRACE_DEBUG("ERROR_IO_ERROR(EAGAIN)");
                return DOWNLOAD_ADAPTOR_ERROR_IO_ERROR;
        case DP_ERROR_IO_EINTR:
-               TRACE_INFO("ERROR_IO_ERROR(EINTR)");
+               TRACE_DEBUG("ERROR_IO_ERROR(EINTR)");
                return DOWNLOAD_ADAPTOR_ERROR_IO_ERROR;
        case DP_ERROR_IO_ERROR:
-               TRACE_INFO("ERROR_IO_ERROR");
+               TRACE_DEBUG("ERROR_IO_ERROR");
                return DOWNLOAD_ADAPTOR_ERROR_IO_ERROR;
        case DP_ERROR_NETWORK_UNREACHABLE:
-               TRACE_INFO("ERROR_NETWORK_UNREACHABLE");
+               TRACE_DEBUG("ERROR_NETWORK_UNREACHABLE");
                return DOWNLOAD_ADAPTOR_ERROR_NETWORK_UNREACHABLE;
        case DP_ERROR_NO_SPACE:
-               TRACE_INFO("ERROR_NO_SPACE");
+               TRACE_DEBUG("ERROR_NO_SPACE");
                return DOWNLOAD_ADAPTOR_ERROR_NO_SPACE;
        case DP_ERROR_FIELD_NOT_FOUND:
-               TRACE_INFO("ERROR_FIELD_NOT_FOUND");
+               TRACE_DEBUG("ERROR_FIELD_NOT_FOUND");
                return DOWNLOAD_ADAPTOR_ERROR_FIELD_NOT_FOUND;
        case DP_ERROR_INVALID_STATE:
-               TRACE_INFO("ERROR_INVALID_STATE");
+               TRACE_DEBUG("ERROR_INVALID_STATE");
                return DOWNLOAD_ADAPTOR_ERROR_INVALID_STATE;
        case DP_ERROR_CONNECTION_FAILED:
-               TRACE_INFO("ERROR_CONNECTION_TIMED_OUT/CONNECTION_FAILED");
+               TRACE_DEBUG("ERROR_CONNECTION_TIMED_OUT/CONNECTION_FAILED");
                return DOWNLOAD_ADAPTOR_ERROR_CONNECTION_TIMED_OUT;
        case DP_ERROR_INVALID_URL:
-               TRACE_INFO("ERROR_INVALID_URL");
+               TRACE_DEBUG("ERROR_INVALID_URL");
                return DOWNLOAD_ADAPTOR_ERROR_INVALID_URL;
        case DP_ERROR_INVALID_DESTINATION:
-               TRACE_INFO("ERROR_INVALID_DESTINATION");
+               TRACE_DEBUG("ERROR_INVALID_DESTINATION");
                return DOWNLOAD_ADAPTOR_ERROR_INVALID_DESTINATION;
+       case DP_ERROR_PERMISSION_DENIED:
+               TRACE_DEBUG("ERROR_PERMISSION_DENIED");
+               return DOWNLOAD_ADAPTOR_ERROR_PERMISSION_DENIED;
        case DP_ERROR_QUEUE_FULL:
-               TRACE_INFO("ERROR_QUEUE_FULL");
+               TRACE_DEBUG("ERROR_QUEUE_FULL");
                return DOWNLOAD_ADAPTOR_ERROR_QUEUE_FULL;
        case DP_ERROR_ALREADY_COMPLETED:
-               TRACE_INFO("ERROR_ALREADY_COMPLETED");
+               TRACE_DEBUG("ERROR_ALREADY_COMPLETED");
                return DOWNLOAD_ADAPTOR_ERROR_ALREADY_COMPLETED;
        case DP_ERROR_FILE_ALREADY_EXISTS:
-               TRACE_INFO("ERROR_FILE_ALREADY_EXISTS");
+               TRACE_DEBUG("ERROR_FILE_ALREADY_EXISTS");
                return DOWNLOAD_ADAPTOR_ERROR_FILE_ALREADY_EXISTS;
        case DP_ERROR_TOO_MANY_DOWNLOADS:
-               TRACE_INFO("ERROR_TOO_MANY_DOWNLOADS");
+               TRACE_DEBUG("ERROR_TOO_MANY_DOWNLOADS");
                return DOWNLOAD_ADAPTOR_ERROR_TOO_MANY_DOWNLOADS;
        case DP_ERROR_NO_DATA:
-               TRACE_INFO("ERROR_NO_DATA");
+               TRACE_DEBUG("ERROR_NO_DATA");
                return DOWNLOAD_ADAPTOR_ERROR_NO_DATA;
        case DP_ERROR_UNHANDLED_HTTP_CODE:
-               TRACE_INFO("ERROR_UNHANDLED_HTTP_CODE");
+               TRACE_DEBUG("ERROR_UNHANDLED_HTTP_CODE");
                return DOWNLOAD_ADAPTOR_ERROR_UNHANDLED_HTTP_CODE;
        case DP_ERROR_CANNOT_RESUME:
-               TRACE_INFO("ERROR_CANNOT_RESUME");
+               TRACE_DEBUG("ERROR_CANNOT_RESUME");
                return DOWNLOAD_ADAPTOR_ERROR_CANNOT_RESUME;
        case DP_ERROR_ID_NOT_FOUND:
-               TRACE_INFO("ERROR_ID_NOT_FOUND");
+               TRACE_DEBUG("ERROR_ID_NOT_FOUND");
                return DOWNLOAD_ADAPTOR_ERROR_ID_NOT_FOUND;
        case DP_ERROR_UNKNOWN:
-               TRACE_INFO("ERROR_INVALID_STATE/UNKNOWN");
+               TRACE_DEBUG("ERROR_INVALID_STATE/UNKNOWN");
                return DOWNLOAD_ADAPTOR_ERROR_INVALID_STATE;
        default:
                break;
@@ -337,7 +311,7 @@ static dp_error_type __get_standard_errorcode(dp_error_type basecode)
                errorcode = DP_ERROR_IO_EAGAIN;
        } else if (errno == EINTR) {
                TRACE_ERROR("[EINTR] Interrupted System Call [%d]", errno);
-               errorcode = DP_ERROR_IO_EINTR;
+               errorcode = DP_ERROR_IO_ERROR;
        }
        return errorcode;
 }
@@ -357,7 +331,8 @@ static int __ipc_read_custom_type(int fd, void *value, size_t type_size)
                return -1;
        }
 
-       if (read(fd, value, type_size) < 0) {
+       ssize_t recv_bytes = read(fd, value, type_size);
+       if (recv_bytes < 0) {
                TRACE_STRERROR("[CRITICAL] read");
                return -1;
        }
@@ -372,26 +347,53 @@ static int __ipc_read_int(int fd)
                TRACE_ERROR("[CHECK SOCKET]");
                return -1;
        }
-       if (read(fd, &value, sizeof(int)) < 0) {
+       ssize_t recv_bytes = read(fd, &value, sizeof(int));
+       if (recv_bytes < 0) {
                TRACE_STRERROR("[CRITICAL] read");
                return -1;
        }
        return value;
 }
 
+static int __ipc_read_download_id(int fd)
+{
+       int value = -1;
+       int read_len = 0;
+       int try_count = 5;
+
+       if (fd < 0) {
+               TRACE_ERROR("[CHECK SOCKET]");
+               return -1;
+       }
+       do {
+               read_len = read(fd, &value, sizeof(int));
+               if (read_len < 0) {
+                       TRACE_STRERROR("[CRITICAL] read");
+                       return -1;
+               }
+               try_count--;
+       } while (read_len == 0 && value == 0 && try_count > 0);
+       return value;
+}
+
 // keep the order/ unsigned , str
 static char *__ipc_read_string(int fd)
 {
        unsigned length = 0;
+       size_t recv_size = 0;
+       unsigned remain_size = 0;
+       size_t buffer_size = 0;
        char *str = NULL;
 
        if (fd < 0) {
-               TRACE_ERROR("[CHECK FD]");
+               TRACE_ERROR("[ERROR] CHECK FD[%d]", fd);
                return NULL;
        }
 
-       if (read(fd, &length, sizeof(unsigned)) < 0) {
-               TRACE_STRERROR("failed to read length [%d]", length);
+       // read flexible URL from client.
+       ssize_t recv_bytes = read(fd, &length, sizeof(unsigned));
+       if (recv_bytes < 0) {
+               TRACE_STRERROR("[ERROR] read FD[%d] length[%d]", fd, length);
                return NULL;
        }
        if (length < 1 || length > DP_MAX_URL_LEN) {
@@ -400,19 +402,89 @@ static char *__ipc_read_string(int fd)
        }
        str = (char *)calloc((length + 1), sizeof(char));
        if (str == NULL) {
-               TRACE_STRERROR("[CRITICAL] allocation");
+               TRACE_STRERROR("[ERROR] calloc length:%d FD[%d]", length, fd);
                return NULL;
        }
-       if (read(fd, str, length * sizeof(char)) < 0) {
-               TRACE_STRERROR("failed to read string");
+       remain_size = length;
+       do {
+               buffer_size = 0;
+               if (remain_size > DP_DEFAULT_BUFFER_SIZE)
+                       buffer_size = DP_DEFAULT_BUFFER_SIZE;
+               else
+                       buffer_size = remain_size;
+               recv_size = (size_t)read(fd, str + (int)(length - remain_size),
+                               buffer_size * sizeof(char));
+               if (recv_size > DP_DEFAULT_BUFFER_SIZE) {
+                       recv_size = -1;
+                       break;
+               }
+               if (recv_size > 0)
+                       remain_size = remain_size - (unsigned)recv_size;
+       } while (recv_size > 0 && remain_size > 0);
+
+       if (recv_size == 0) {
+               TRACE_STRERROR("[ERROR] closed peer:%d", fd);
                free(str);
-               str = NULL;
                return NULL;
        }
        str[length] = '\0';
        return str;
 }
 
+int __ipc_read_bundle(int fd, bundle_raw **b)
+{
+       unsigned length = 0;
+       size_t recv_size = 0;
+       unsigned remain_size = 0;
+       size_t buffer_size = 0;
+       bundle_raw *b_raw = NULL;
+
+       if (fd < 0) {
+               TRACE_ERROR("[ERROR] CHECK FD[%d]", fd);
+               return 0;
+       }
+
+       // read bundle data from client.
+       ssize_t recv_bytes = read(fd, &length, sizeof(unsigned));
+       if (recv_bytes < 0) {
+               TRACE_STRERROR("[ERROR] read FD[%d] length[%d]", fd, length);
+               return 0;
+       }
+       if (length < 1 || length > DP_MAX_URL_LEN) {
+               TRACE_ERROR("[STRING LEGNTH] [%d]", length);
+               return 0;
+       }
+       b_raw = (bundle_raw *)calloc(length, 1);
+       if (b_raw == NULL) {
+               TRACE_STRERROR("[ERROR] calloc length:%d FD[%d]", length, fd);
+               return 0;
+       }
+       remain_size = length;
+       do {
+               buffer_size = 0;
+               if (remain_size > DP_DEFAULT_BUFFER_SIZE)
+                       buffer_size = DP_DEFAULT_BUFFER_SIZE;
+               else
+                       buffer_size = remain_size;
+               recv_size = (size_t)read(fd, b_raw + (int)(length - remain_size),
+                               buffer_size);
+               if (recv_size > DP_DEFAULT_BUFFER_SIZE) {
+                       recv_size = -1;
+                       break;
+               }
+               if (recv_size > 0)
+                       remain_size = remain_size - (unsigned)recv_size;
+       } while (recv_size > 0 && remain_size > 0);
+
+       if (recv_size == 0) {
+               TRACE_STRERROR("[ERROR] closed peer:%d", fd);
+               bundle_free_encoded_rawdata(&b_raw);
+               return 0;
+       }
+       *b = b_raw;
+       return (int)length;
+}
+
 static dp_error_type __ipc_return(int fd)
 {
        dp_error_type errorcode = DP_ERROR_NONE;
@@ -421,12 +493,13 @@ static dp_error_type __ipc_return(int fd)
                TRACE_ERROR("[CHECK SOCKET]");
                return DP_ERROR_IO_ERROR;
        }
-
-       if (read(fd, &errorcode, sizeof(dp_error_type)) < 0) {
+       ssize_t recv_bytes = read(fd, &errorcode, sizeof(dp_error_type));
+       if (recv_bytes < 0) {
                TRACE_STRERROR("[CRITICAL] read");
                return __get_standard_errorcode(DP_ERROR_IO_ERROR);
        }
-       TRACE_INFO("return : %d", errorcode);
+       if (errorcode != DP_ERROR_NONE)
+               TRACE_ERROR("return : %d", errorcode);
        return errorcode;
 }
 
@@ -444,14 +517,12 @@ static dp_event_info* __ipc_event(int fd)
                TRACE_ERROR("[CHECK ALLOCATION]");
                return NULL;
        }
-       if (read(fd, event, sizeof(dp_event_info)) < 0) {
+       ssize_t recv_bytes = read(fd, event, sizeof(dp_event_info));
+       if (recv_bytes < 0) {
                TRACE_STRERROR("[CRITICAL] read");
                free(event);
                return NULL;
        }
-
-       TRACE_INFO("EVENT INFO (ID : %d state : %d error : %d)",
-               event->id, event->state, event->err);
        return event;
 }
 
@@ -494,6 +565,31 @@ static dp_error_type __ipc_send_string(int fd, const char *str)
        return DP_ERROR_NONE;
 }
 
+static dp_error_type __ipc_send_raw_bundle(int fd, int type, const bundle_raw *b, int len)
+{
+       if (fd < 0) {
+               TRACE_ERROR("[CHECK FD]");
+               return DP_ERROR_IO_ERROR;
+       }
+       if (b == NULL || len <= 0) {
+               TRACE_ERROR("[CHECK STRING]");
+               return DP_ERROR_INVALID_PARAMETER;
+       }
+       if (fd >= 0 && write(fd, &type, sizeof(unsigned)) < 0) {
+               TRACE_STRERROR("[CRITICAL] send");
+               return DP_ERROR_IO_ERROR;
+       }
+       if (fd >= 0 && write(fd, &len, sizeof(unsigned)) < 0) {
+               TRACE_STRERROR("[CRITICAL] send");
+               return DP_ERROR_IO_ERROR;
+       }
+       if (fd >= 0 && write(fd, b, len) < 0) {
+               TRACE_STRERROR("[CRITICAL] send");
+               return DP_ERROR_IO_ERROR;
+       }
+       return DP_ERROR_NONE;
+}
+
 static dp_error_type __ipc_send_command
        (int fd, int id, dp_command_type cmd)
 {
@@ -515,8 +611,6 @@ static dp_error_type __ipc_send_command
 static dp_error_type __ipc_send_command_return
        (int id, dp_command_type cmd)
 {
-       TRACE_INFO("");
-
        if (cmd <= DP_CMD_NONE) {
                TRACE_ERROR("[CHECK COMMAND] (%d)", cmd);
                return DP_ERROR_INVALID_PARAMETER;
@@ -535,8 +629,6 @@ static int __create_socket()
        struct timeval tv_timeo = { 2, 500000 }; //2.5 second
        struct sockaddr_un clientaddr;
 
-       TRACE_INFO("");
-
        if ((sockfd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
                TRACE_STRERROR("[CRITICAL] socket system error");
                return -1;
@@ -559,14 +651,14 @@ static int __create_socket()
                close(sockfd);
                return -1;
        }
-       TRACE_INFO("sockfd [%d]", sockfd);
+       TRACE_DEBUG("sockfd [%d]", sockfd);
        return sockfd;
 }
 
-static int __disconnect_from_provider()
+static void __clear_interface()
 {
-       TRACE_INFO("");
-
+       TRACE_DEBUG("");
+       pthread_mutex_lock(&g_clear_mutex);
        if (g_interface_info != NULL) {
                shutdown(g_interface_info->cmd_socket, 0);
                close(g_interface_info->cmd_socket);
@@ -578,12 +670,20 @@ static int __disconnect_from_provider()
                free(g_interface_info);
                g_interface_info = NULL;
        }
-       if (g_interface_event_thread_id > 0) {
-               TRACE_INFO("STOP event thread");
-               pthread_cancel(g_interface_event_thread_id);
+       pthread_mutex_unlock(&g_clear_mutex);
+}
+
+static int __disconnect_from_provider()
+{
+       TRACE_DEBUG("");
+       if (g_interface_event_thread_id > 0 &&
+                       pthread_kill(g_interface_event_thread_id, 0) != ESRCH) {
+               if (pthread_cancel(g_interface_event_thread_id) != 0) {
+                       TRACE_STRERROR("pthread:%d", (int)g_interface_event_thread_id);
+               }
                g_interface_event_thread_id = 0;
-               TRACE_INFO("OK terminate event thread");
        }
+       __clear_interface();
        return DP_ERROR_NONE;
 }
 
@@ -598,7 +698,7 @@ static void __clear_read_buffer(int fd)
        // FIONREAD : Returns the number of bytes immediately readable
        if (ioctl(fd, FIONREAD, &unread_count) >= 0) {
                if (unread_count > 0) {
-                       TRACE_INFO("[CLEAN] garbage packet[%ld]", unread_count);
+                       TRACE_DEBUG("[CLEAN] garbage packet[%ld]", unread_count);
                        for ( i = 0; i < unread_count; i++) {
                                if (read(fd, &tmp_char, sizeof(char)) < 0) {
                                        TRACE_STRERROR("[CHECK] read");
@@ -643,16 +743,16 @@ static void *__dp_interface_event_manager(void *arg)
                return 0;
        }
 
-       // deferred wait to cencal until next function called.
+       // deferred wait to cancal until next function called.
        // ex) function : select, read in this thread
        pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL);
 
-       TRACE_INFO("FD [%d]", g_interface_info->event_socket);
-
        maxfd = g_interface_info->event_socket;
        FD_ZERO(&read_fdset);
        FD_SET(g_interface_info->event_socket, &read_fdset);
 
+       int sock = g_interface_info->event_socket;
+
        while(g_interface_info != NULL
                        && g_interface_info->event_socket >= 0) {
                rset = read_fdset;
@@ -667,102 +767,67 @@ static void *__dp_interface_event_manager(void *arg)
                                ("[CRITICAL] [CHECK TID] SELF ID [%d] Global ID (%d)",
                                pthread_self(), g_interface_event_thread_id);
                        // another thread may work. just terminate
-                       return 0;
-               }
-
-               pthread_mutex_lock(&g_function_mutex);
-
-               if (g_interface_info == NULL
-                       || g_interface_info->event_socket < 0) {
-                       TRACE_ERROR("[CRITICAL] IPC BROKEN Ending Event Thread");
-                       pthread_mutex_unlock(&g_function_mutex);
-                       // disconnected by main thread. just terminate
-                       return 0;
+                       break;
                }
 
-               if (FD_ISSET(g_interface_info->event_socket, &rset) > 0) {
+               if (FD_ISSET(sock, &rset) > 0) {
                        // read state info from socket
-                       eventinfo = __ipc_event(g_interface_info->event_socket);
+                       eventinfo = __ipc_event(sock);
                        if (eventinfo == NULL || eventinfo->id <= 0) {
                                // failed to read from socket // ignore this status
                                free(eventinfo);
                                TRACE_STRERROR("[CRITICAL] Can not read Event packet");
-                               pthread_mutex_unlock(&g_function_mutex);
-                               if (__get_standard_errorcode(DP_ERROR_IO_ERROR) ==
-                                               DP_ERROR_IO_ERROR) // if not timeout. end thread
-                                       break;
-                               continue;
+                               g_interface_event_thread_id = 0;
+                               __clear_interface();
+                               return 0;
                        }
 
                        if ((index = __get_my_slot_index(eventinfo->id)) < 0) {
                                TRACE_ERROR("[CRITICAL] not found slot for [%d]",
                                        eventinfo->id);
                                free(eventinfo);
-                               pthread_mutex_unlock(&g_function_mutex);
                                continue;
                        }
 
-                       pthread_mutex_unlock(&g_function_mutex);
-
-                       // begin protect callback sections
+                       // begin protect callback sections & thread safe
                        pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
-
                        dp_interface_callback *callback =
                                &g_interface_slots[index].callback;
 
                        if (eventinfo->state == DP_STATE_DOWNLOADING
                                && eventinfo->received_size > 0) {
-                               if (callback->progress != NULL) {
+                               if (eventinfo->id == g_interface_slots[index].id &&
+                                       callback->progress != NULL) {
                                        // progress event
-                                       TRACE_INFO("ID %d progress callback %p",
-                                               eventinfo->id, callback->progress );
                                        callback->progress(eventinfo->id,
                                                eventinfo->received_size,
                                                callback->progress_data);
                                }
                        } else {
-                               if (callback->state != NULL) {
+                               if (eventinfo->id == g_interface_slots[index].id &&
+                                       callback->state != NULL) {
                                        // state event
-                                       TRACE_INFO("ID %d state callback %p", eventinfo->id,
-                                               callback->state);
                                        callback->state(eventinfo->id,
                                                __dp_interface_convert_state(eventinfo->state),
                                                callback->state_data);
                                }
                        }
                        free(eventinfo);
-
-                       // end protect callback sections
-                       pthread_setcancelstate (PTHREAD_CANCEL_ENABLE,  NULL);
-                       continue;
+                       pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
                }
-               pthread_mutex_unlock(&g_function_mutex);
        } // while
 
-       FD_ZERO(&read_fdset);
-
-       TRACE_INFO("Terminate Event Thread");
-       pthread_mutex_lock(&g_function_mutex);
-       TRACE_INFO("Disconnect All Connection");
+       FD_CLR(sock, &read_fdset);
        g_interface_event_thread_id = 0; // set 0 to not call pthread_cancel
-       __disconnect_from_provider();
-       pthread_mutex_unlock(&g_function_mutex);
+       TRACE_DEBUG("thread end by itself");
        return 0;
 }
 
 static int __connect_to_provider()
 {
-       TRACE_INFO("");
-
+       pthread_mutex_lock(&g_clear_mutex);
        if (g_interface_info == NULL) {
 
-#ifdef DP_DBUS_ACTIVATION
-               if (__dp_call_dp_interface_service() < 0) {
-                       TRACE_ERROR("[DBUS IO] __dp_call_dp_interface_service");
-                       return DP_ERROR_IO_ERROR;
-               }
-#endif
-
                g_interface_info =
                        (dp_interface_info *) calloc(1, sizeof(dp_interface_info));
        }
@@ -780,6 +845,7 @@ static int __connect_to_provider()
                        TRACE_STRERROR("[CRITICAL] connect system error");
                        free(g_interface_info);
                        g_interface_info = NULL;
+                       pthread_mutex_unlock(&g_clear_mutex);
                        return DP_ERROR_IO_ERROR;
                }
                // send a command
@@ -788,6 +854,7 @@ static int __connect_to_provider()
                        close(g_interface_info->cmd_socket);
                        free(g_interface_info);
                        g_interface_info = NULL;
+                       pthread_mutex_unlock(&g_clear_mutex);
                        return DP_ERROR_IO_ERROR;
                }
 #ifndef SO_PEERCRED
@@ -796,6 +863,21 @@ static int __connect_to_provider()
                        close(g_interface_info->cmd_socket);
                        free(g_interface_info);
                        g_interface_info = NULL;
+                       pthread_mutex_unlock(&g_clear_mutex);
+                       return DP_ERROR_IO_ERROR;
+               }
+               if (__ipc_send_int(g_interface_info->cmd_socket, getuid()) < 0) {
+                       close(g_interface_info->cmd_socket);
+                       free(g_interface_info);
+                       g_interface_info = NULL;
+                       pthread_mutex_unlock(&g_clear_mutex);
+                       return DP_ERROR_IO_ERROR;
+               }
+               if (__ipc_send_int(g_interface_info->cmd_socket, getgid()) < 0) {
+                       close(g_interface_info->cmd_socket);
+                       free(g_interface_info);
+                       g_interface_info = NULL;
+                       pthread_mutex_unlock(&g_clear_mutex);
                        return DP_ERROR_IO_ERROR;
                }
 #endif
@@ -805,6 +887,7 @@ static int __connect_to_provider()
                        close(g_interface_info->cmd_socket);
                        free(g_interface_info);
                        g_interface_info = NULL;
+                       pthread_mutex_unlock(&g_clear_mutex);
                        return DP_ERROR_IO_ERROR;
                }
                // send a command
@@ -814,6 +897,7 @@ static int __connect_to_provider()
                        close(g_interface_info->event_socket);
                        free(g_interface_info);
                        g_interface_info = NULL;
+                       pthread_mutex_unlock(&g_clear_mutex);
                        return DP_ERROR_IO_ERROR;
                }
 #ifndef SO_PEERCRED
@@ -824,6 +908,7 @@ static int __connect_to_provider()
                        close(g_interface_info->event_socket);
                        free(g_interface_info);
                        g_interface_info = NULL;
+                       pthread_mutex_unlock(&g_clear_mutex);
                        return DP_ERROR_IO_ERROR;
                }
 #endif
@@ -831,32 +916,35 @@ static int __connect_to_provider()
                int ret = pthread_mutex_init(&g_interface_info->mutex, NULL);
                if (ret != 0) {
                        TRACE_STRERROR("ERR:pthread_mutex_init FAIL with %d.", ret);
-                       __disconnect_from_provider();
+                       __clear_interface();
+                       pthread_mutex_unlock(&g_clear_mutex);
                        return DP_ERROR_IO_ERROR;
                }
 
-               if (g_interface_event_thread_id <= 0) {
-                       // create thread here ( getting event_socket )
-                       pthread_attr_t thread_attr;
-                       if (pthread_attr_init(&thread_attr) != 0) {
-                               TRACE_STRERROR("[CRITICAL] pthread_attr_init");
-                               __disconnect_from_provider();
-                               return DP_ERROR_IO_ERROR;
-                       }
-                       if (pthread_attr_setdetachstate(&thread_attr,
-                               PTHREAD_CREATE_DETACHED) != 0) {
-                               TRACE_STRERROR
-                                       ("[CRITICAL] pthread_attr_setdetachstate");
-                               __disconnect_from_provider();
-                               return DP_ERROR_IO_ERROR;
-                       }
-                       if (pthread_create(&g_interface_event_thread_id,
-                                       &thread_attr, __dp_interface_event_manager,
-                                       g_interface_info) != 0) {
-                               TRACE_STRERROR("[CRITICAL] pthread_create");
-                               __disconnect_from_provider();
-                               return DP_ERROR_IO_ERROR;
-                       }
+       }
+       pthread_mutex_unlock(&g_clear_mutex);
+       if (g_interface_event_thread_id <= 0) {
+               // create thread here ( getting event_socket )
+               pthread_attr_t thread_attr;
+               if (pthread_attr_init(&thread_attr) != 0) {
+                       TRACE_STRERROR("[CRITICAL] pthread_attr_init");
+                       __disconnect_from_provider();
+                       return DP_ERROR_IO_ERROR;
+               }
+               if (pthread_attr_setdetachstate(&thread_attr,
+                       PTHREAD_CREATE_DETACHED) != 0) {
+                       TRACE_STRERROR
+                               ("[CRITICAL] pthread_attr_setdetachstate");
+                       __disconnect_from_provider();
+                       return DP_ERROR_IO_ERROR;
+               }
+               if (pthread_create(&g_interface_event_thread_id,
+                               &thread_attr, __dp_interface_event_manager,
+                               g_interface_info) != 0) {
+                       TRACE_STRERROR("[CRITICAL] pthread_create");
+                       __clear_interface();
+                       g_interface_event_thread_id = 0;
+                       return DP_ERROR_IO_ERROR;
                }
        }
        return DP_ERROR_NONE;
@@ -900,7 +988,7 @@ static dp_error_type __dp_interface_set_string
        int fd = g_interface_info->cmd_socket;
 
        // send commnad with ID
-       errorcode = __ipc_send_command(fd, id, cmd);
+       errorcode = __ipc_send_command_return(id, cmd);
        if (errorcode == DP_ERROR_NONE) {
                // send string
                errorcode = __ipc_send_string(fd, value);
@@ -939,7 +1027,7 @@ static dp_error_type __dp_interface_set_strings
        int fd = g_interface_info->cmd_socket;
 
        // send commnad with ID
-       errorcode = __ipc_send_command(fd, id, cmd);
+       errorcode = __ipc_send_command_return(id, cmd);
        if (errorcode == DP_ERROR_NONE) {
                if (__ipc_send_int(fd, (int)count) == 0) {
                        int i = 0;
@@ -1029,7 +1117,7 @@ static dp_error_type __dp_interface_get_strings
 
        int fd = g_interface_info->cmd_socket;
 
-       errorcode = __ipc_send_command(fd, id, cmd);
+       errorcode = __ipc_send_command_return(id, cmd);
        if (errorcode == DP_ERROR_NONE) {
                if (length > 0 && strings != NULL) {
                        if (__ipc_send_int(fd, (int)length) == 0) {
@@ -1114,7 +1202,7 @@ static dp_error_type __dp_interface_get_int
                recv_int = __ipc_read_int(fd);
                if (recv_int >= 0) {
                        *value = recv_int;
-                       TRACE_INFO("ID : %d recv_int : %d", id, *value);
+                       TRACE_DEBUG("ID : %d recv_int : %d", id, *value);
                } else {
                        errorcode = __get_standard_errorcode(DP_ERROR_IO_ERROR);
                }
@@ -1144,7 +1232,7 @@ static dp_error_type __dp_interface_set_int
        int fd = g_interface_info->cmd_socket;
 
        // send commnad with ID
-       errorcode = __ipc_send_command(fd, id, cmd);
+       errorcode = __ipc_send_command_return(id, cmd);
        if (errorcode == DP_ERROR_NONE) {
                // send string
                if (__ipc_send_int(fd, value) == 0) {
@@ -1161,6 +1249,94 @@ static dp_error_type __dp_interface_set_int
        return __dp_interface_convert_errorcode(errorcode);
 }
 
+static dp_error_type __dp_interface_set_raw_bundle
+       (const int id, const dp_command_type cmd, int type, const bundle_raw *b, int len)
+{
+       dp_error_type errorcode = DP_ERROR_NONE;
+       if (b == NULL) {
+               TRACE_ERROR("[CHECK bundle]");
+               return DOWNLOAD_ADAPTOR_ERROR_INVALID_PARAMETER;
+       }
+
+       DP_PRE_CHECK_ID;
+
+       pthread_mutex_lock(&g_function_mutex);
+
+       DP_CHECK_CONNECTION;
+
+       pthread_mutex_lock(&g_interface_info->mutex);
+
+       DP_CHECK_PROVIDER_STATUS;
+
+       int fd = g_interface_info->cmd_socket;
+
+       // send commnad with ID
+       errorcode = __ipc_send_command_return(id, cmd);
+       if (errorcode == DP_ERROR_NONE) {
+               // send raw bundle
+               errorcode = __ipc_send_raw_bundle(fd, type, b, len);
+               if (errorcode == DP_ERROR_NONE) {
+                       // return from provider.
+                       errorcode = __ipc_return(fd);
+               }
+       }
+       pthread_mutex_unlock(&g_interface_info->mutex);
+       if (errorcode == DP_ERROR_IO_ERROR)
+               __disconnect_from_provider();
+       pthread_mutex_unlock(&g_function_mutex);
+       return __dp_interface_convert_errorcode(errorcode);
+}
+
+static dp_error_type __dp_interface_get_raw_bundle
+       (const int id, const dp_command_type cmd, int type, bundle_raw **value, int *len)
+{
+       int errorcode = DP_ERROR_NONE;
+
+       if (value == NULL) {
+               TRACE_ERROR("[CHECK buffer]");
+               return DOWNLOAD_ADAPTOR_ERROR_INVALID_PARAMETER;
+       }
+
+       DP_PRE_CHECK_ID;
+
+       pthread_mutex_lock(&g_function_mutex);
+
+       DP_CHECK_CONNECTION;
+
+       pthread_mutex_lock(&g_interface_info->mutex);
+
+       DP_CHECK_PROVIDER_STATUS;
+
+       int fd = g_interface_info->cmd_socket;
+
+       errorcode = __ipc_send_command_return(id, cmd);
+       if (errorcode == DP_ERROR_NONE) {
+               errorcode = __ipc_send_int(fd, type);
+               if(errorcode == 0) {
+                       errorcode = __ipc_return(g_interface_info->cmd_socket);
+                       if (errorcode == DP_ERROR_NONE) {
+                               *len = __ipc_read_bundle(fd, value);
+                               if (*len <= 0)
+                                       errorcode = __get_standard_errorcode(DP_ERROR_IO_ERROR);
+                       } else {
+                               TRACE_ERROR("[ERROR] Fail to get result for sending type value]");
+                               errorcode = DP_ERROR_IO_ERROR;
+                       }
+               } else {
+                       TRACE_ERROR("[ERROR] Fail to send type]");
+                       errorcode = DP_ERROR_IO_ERROR;
+               }
+       } else {
+               TRACE_ERROR("[ERROR] Fail to send command]");
+               errorcode = DP_ERROR_IO_ERROR;
+       }
+       pthread_mutex_unlock(&g_interface_info->mutex);
+       if (errorcode == DP_ERROR_IO_ERROR)
+               __disconnect_from_provider();
+       pthread_mutex_unlock(&g_function_mutex);
+       return __dp_interface_convert_errorcode(errorcode);
+}
+
 
 /////////////////////// APIs /////////////////////////////////
 
@@ -1193,8 +1369,8 @@ int dp_interface_create(int *id)
        errorcode = __ipc_send_command_return(-1, DP_CMD_CREATE);
        if (errorcode == DP_ERROR_NONE) {
                // getting state with ID from provider.
-               t_id = __ipc_read_int(g_interface_info->cmd_socket);
-               if (t_id >= 0) {
+               t_id = __ipc_read_download_id(g_interface_info->cmd_socket);
+               if (t_id > 0) {
                        *id = t_id;
                        g_interface_slots[index].id = t_id;
                        g_interface_slots[index].callback.state = NULL;
@@ -1238,7 +1414,6 @@ int dp_interface_destroy(const int id)
        errorcode = __ipc_send_command_return(id, DP_CMD_DESTROY);
        if (errorcode == DP_ERROR_NONE) {
                // after getting errorcode, send FREE to provider.
-               TRACE_INFO("Request to Free the memory for ID : %d", id);
                // send again DP_CMD_FREE with ID.
                errorcode = __ipc_send_command
                        (g_interface_info->cmd_socket, id, DP_CMD_FREE);
@@ -1318,26 +1493,22 @@ int dp_interface_cancel(const int id)
 
 int dp_interface_set_url(const int id, const char *url)
 {
-       TRACE_INFO("");
        return __dp_interface_set_string(id, DP_CMD_SET_URL, url);
 }
 
 int dp_interface_get_url(const int id, char **url)
 {
-       TRACE_INFO("");
        return __dp_interface_get_string(id, DP_CMD_GET_URL, url);
 }
 
 int dp_interface_set_network_type(const int id, int net_type)
 {
-       TRACE_INFO("");
        return __dp_interface_set_int(id, DP_CMD_SET_NETWORK_TYPE,
                __dp_interface_convert_network_adaptor(net_type));
 }
 
 int dp_interface_get_network_type(const int id, int *net_type)
 {
-       TRACE_INFO("");
        if (net_type == NULL) {
                TRACE_ERROR("[CHECK buffer]");
                return DOWNLOAD_ADAPTOR_ERROR_INVALID_PARAMETER;
@@ -1353,26 +1524,22 @@ int dp_interface_get_network_type(const int id, int *net_type)
 
 int dp_interface_set_destination(const int id, const char *path)
 {
-       TRACE_INFO("");
        return __dp_interface_set_string(id, DP_CMD_SET_DESTINATION, path);
 }
 
 
 int dp_interface_get_destination(const int id, char **path)
 {
-       TRACE_INFO("");
        return __dp_interface_get_string(id, DP_CMD_GET_DESTINATION, path);
 }
 
 int dp_interface_set_file_name(const int id, const char *file_name)
 {
-       TRACE_INFO("");
        return __dp_interface_set_string(id, DP_CMD_SET_FILENAME, file_name);
 }
 
 int dp_interface_get_file_name(const int id, char **file_name)
 {
-       TRACE_INFO("");
        return __dp_interface_get_string(id, DP_CMD_GET_FILENAME, file_name);
 }
 
@@ -1383,7 +1550,6 @@ int dp_interface_set_ongoing_notification(const int id, int enable)
 
 int dp_interface_set_notification(const int id, int enable)
 {
-       TRACE_INFO("");
        return __dp_interface_set_int(id, DP_CMD_SET_NOTIFICATION, enable);
 }
 
@@ -1394,13 +1560,11 @@ int dp_interface_get_ongoing_notification(const int id, int *enable)
 
 int dp_interface_get_notification(const int id, int *enable)
 {
-       TRACE_INFO("");
        return __dp_interface_get_int(id, DP_CMD_GET_NOTIFICATION, enable);
 }
 
 int dp_interface_get_downloaded_file_path(const int id, char **path)
 {
-       TRACE_INFO("");
        return __dp_interface_get_string(id, DP_CMD_GET_SAVED_PATH, path);
 }
 
@@ -1511,7 +1675,6 @@ int dp_interface_get_notification_extra_param(const int id, char **key,
 
        *key = key_str;
        *value = value_str;
-       TRACE_INFO("ID : %d key : %s value : %s", id, *key, *value);
        pthread_mutex_unlock(&g_function_mutex);
 #endif
        return DOWNLOAD_ADAPTOR_ERROR_NONE;
@@ -1538,9 +1701,8 @@ int dp_interface_add_http_header_field(const int id, const char *field,
        DP_CHECK_PROVIDER_STATUS;
 
        // send commnad with ID
-       if (__ipc_send_command
-               (g_interface_info->cmd_socket, id, DP_CMD_SET_HTTP_HEADER)
-               != DP_ERROR_NONE) {
+       if (__ipc_send_command_return(id, DP_CMD_SET_HTTP_HEADER) !=
+                       DP_ERROR_NONE) {
                pthread_mutex_unlock(&g_interface_info->mutex);
                __disconnect_from_provider();
                pthread_mutex_unlock(&g_function_mutex);
@@ -1594,9 +1756,8 @@ int dp_interface_get_http_header_field(const int id, const char *field,
 
        DP_CHECK_PROVIDER_STATUS;
 
-       if (__ipc_send_command
-               (g_interface_info->cmd_socket, id, DP_CMD_GET_HTTP_HEADER)
-               != DP_ERROR_NONE) {
+       if (__ipc_send_command_return(id, DP_CMD_GET_HTTP_HEADER) !=
+                       DP_ERROR_NONE) {
                pthread_mutex_unlock(&g_interface_info->mutex);
                __disconnect_from_provider();
                pthread_mutex_unlock(&g_function_mutex);
@@ -1617,7 +1778,6 @@ int dp_interface_get_http_header_field(const int id, const char *field,
                str = __ipc_read_string(g_interface_info->cmd_socket);
                if (str != NULL) {
                        *value = str;
-                       TRACE_INFO("ID : %d field:%s value: %s", id, field, *value);
                } else {
                        errorcode = __get_standard_errorcode(DP_ERROR_IO_ERROR);
                }
@@ -1632,7 +1792,6 @@ int dp_interface_get_http_header_field(const int id, const char *field,
 int dp_interface_get_http_header_field_list(const int id, char ***fields,
        int *length)
 {
-       TRACE_INFO("");
        return __dp_interface_get_strings(id, DP_CMD_GET_HTTP_HEADER_LIST,
                NULL, 0, fields, (unsigned *)length);
 }
@@ -1658,9 +1817,8 @@ int dp_interface_remove_http_header_field(const int id,
        DP_CHECK_PROVIDER_STATUS;
 
        // send commnad with ID
-       if (__ipc_send_command
-               (g_interface_info->cmd_socket, id, DP_CMD_DEL_HTTP_HEADER)
-               != DP_ERROR_NONE) {
+       if (__ipc_send_command_return(id, DP_CMD_DEL_HTTP_HEADER) !=
+                       DP_ERROR_NONE) {
                pthread_mutex_unlock(&g_interface_info->mutex);
                __disconnect_from_provider();
                pthread_mutex_unlock(&g_function_mutex);
@@ -1792,7 +1950,6 @@ int dp_interface_unset_progress_cb(const int id)
 
 int dp_interface_get_state(const int id, int *state)
 {
-       TRACE_INFO("");
        if (state == NULL) {
                TRACE_ERROR("[CHECK buffer]");
                return DOWNLOAD_ADAPTOR_ERROR_INVALID_PARAMETER;
@@ -1806,14 +1963,12 @@ int dp_interface_get_state(const int id, int *state)
 
 int dp_interface_get_temp_path(const int id, char **temp_path)
 {
-       TRACE_INFO("");
        return __dp_interface_get_string
                (id, DP_CMD_GET_TEMP_SAVED_PATH, temp_path);
 }
 
 int dp_interface_get_content_name(const int id, char **content_name)
 {
-       TRACE_INFO("");
        return __dp_interface_get_string
                (id, DP_CMD_GET_CONTENT_NAME, content_name);
 }
@@ -1845,8 +2000,6 @@ int dp_interface_get_content_size(const int id,
                if (__ipc_read_custom_type(g_interface_info->cmd_socket,
                                content_size, sizeof(unsigned long long)) < 0) {
                        errorcode = __get_standard_errorcode(DP_ERROR_IO_ERROR);
-               } else {
-                       TRACE_INFO("ID : %d content_size %lld", id, *content_size);
                }
        }
        pthread_mutex_unlock(&g_interface_info->mutex);
@@ -1858,26 +2011,22 @@ int dp_interface_get_content_size(const int id,
 
 int dp_interface_get_mime_type(const int id, char **mime_type)
 {
-       TRACE_INFO("");
        return __dp_interface_get_string
                (id, DP_CMD_GET_MIME_TYPE, mime_type);
 }
 
 int dp_interface_set_auto_download(const int id, int enable)
 {
-       TRACE_INFO("");
        return __dp_interface_set_int(id, DP_CMD_SET_AUTO_DOWNLOAD, enable);
 }
 
 int dp_interface_get_auto_download(const int id, int *enable)
 {
-       TRACE_INFO("");
        return __dp_interface_get_int(id, DP_CMD_GET_AUTO_DOWNLOAD, enable);
 }
 
 int dp_interface_get_error(const int id, int *error)
 {
-       TRACE_INFO("");
        if (error == NULL) {
                TRACE_ERROR("[CHECK buffer error]");
                return DOWNLOAD_ADAPTOR_ERROR_INVALID_PARAMETER;
@@ -1891,7 +2040,6 @@ int dp_interface_get_error(const int id, int *error)
 
 int dp_interface_get_http_status(const int id, int *http_status)
 {
-       TRACE_INFO("");
        return __dp_interface_get_int
                (id, DP_CMD_GET_HTTP_STATUS, http_status);
 }
@@ -1901,8 +2049,6 @@ int dp_interface_add_noti_extra(const int id, const char *key,
 {
        int i = 0;
 
-       TRACE_INFO("");
-
        if (key == NULL || values == NULL) {
                TRACE_ERROR("[CHECK key/values] (%d)", id);
                return DOWNLOAD_ADAPTOR_ERROR_INVALID_PARAMETER;
@@ -1924,14 +2070,77 @@ int dp_interface_add_noti_extra(const int id, const char *key,
 int dp_interface_get_noti_extra_values(const int id, const char *key,
        char ***values, unsigned *length)
 {
-       TRACE_INFO("");
        return __dp_interface_get_strings(id, DP_CMD_GET_EXTRA_PARAM,
                &key, 1, values, length);
 }
 
 int dp_interface_remove_noti_extra_key(const int id, const char *key)
 {
-       TRACE_INFO("");
        return __dp_interface_set_string
                (id, DP_CMD_REMOVE_EXTRA_PARAM, key);
 }
+
+int dp_interface_set_notification_bundle(const int id, int type, bundle *b)
+{
+       bundle_raw *r = NULL;
+       int len = 0;
+       int retval = -1;
+       retval = bundle_encode_raw(b, &r, &len);
+       if (retval == 0)
+               retval = __dp_interface_set_raw_bundle(id, DP_CMD_SET_NOTIFICATION_BUNDLE, type, r, len);
+       else {
+               bundle_free_encoded_rawdata(&r);
+               return DOWNLOAD_ADAPTOR_ERROR_INVALID_PARAMETER;
+       }
+       bundle_free_encoded_rawdata(&r);
+       return retval;
+}
+
+int dp_interface_get_notification_bundle(const int id, int type, bundle **b)
+{
+       bundle_raw *r = NULL;
+       int len = 0;
+       download_adaptor_error_e error = DOWNLOAD_ADAPTOR_ERROR_NONE;
+
+       if (b == NULL) {
+               TRACE_ERROR("[CHECK bundle] (%d)", id);
+               return DOWNLOAD_ADAPTOR_ERROR_INVALID_PARAMETER;
+       }
+
+       error = __dp_interface_get_raw_bundle(id, DP_CMD_GET_NOTIFICATION_BUNDLE, type, &r, &len);
+       if (error == DOWNLOAD_ADAPTOR_ERROR_NONE) {
+               *b = bundle_decode_raw(r, len);
+       }
+       bundle_free_encoded_rawdata(&r);
+       return error;
+}
+
+int dp_interface_set_notification_title(const int id, const char *title)
+{
+       return __dp_interface_set_string(id, DP_CMD_SET_NOTIFICATION_TITLE, title);
+}
+
+int dp_interface_get_notification_title(const int id, char **title)
+{
+       return __dp_interface_get_string(id, DP_CMD_GET_NOTIFICATION_TITLE, title);
+}
+
+int dp_interface_set_notification_description(const int id, const char *description)
+{
+       return __dp_interface_set_string(id, DP_CMD_SET_NOTIFICATION_DESCRIPTION, description);
+}
+
+int dp_interface_get_notification_description(const int id, char **description)
+{
+       return __dp_interface_get_string(id, DP_CMD_GET_NOTIFICATION_DESCRIPTION, description);
+}
+
+int dp_interface_set_notification_type(const int id, int type)
+{
+       return __dp_interface_set_int(id, DP_CMD_SET_NOTIFICATION_TYPE, type);
+}
+
+int dp_interface_get_notification_type(const int id, int *type)
+{
+       return __dp_interface_get_int(id, DP_CMD_GET_NOTIFICATION_TYPE, type);
+}
index 7a6efe6..eb96e19 100755 (executable)
@@ -22,6 +22,7 @@
 #endif
 
 #include <tizen.h>
+#include <bundle.h>
 
 #ifdef __cplusplus
 extern "C"
@@ -58,6 +59,7 @@ typedef enum
        DOWNLOAD_ADAPTOR_ERROR_CONNECTION_TIMED_OUT = TIZEN_ERROR_CONNECTION_TIME_OUT, /**< Http session time-out */
        DOWNLOAD_ADAPTOR_ERROR_NO_SPACE = TIZEN_ERROR_FILE_NO_SPACE_ON_DEVICE, /**< No space left on device */
        DOWNLOAD_ADAPTOR_ERROR_FIELD_NOT_FOUND = TIZEN_ERROR_KEY_NOT_AVAILABLE, /**< Specified field not found */
+       DOWNLOAD_ADAPTOR_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Permission denied */
        DOWNLOAD_ADAPTOR_ERROR_INVALID_STATE = TIZEN_ERROR_WEB_CLASS | 0x21, /**< Invalid state */
        DOWNLOAD_ADAPTOR_ERROR_CONNECTION_FAILED = TIZEN_ERROR_WEB_CLASS | 0x22, /**< Connection failed */
        DOWNLOAD_ADAPTOR_ERROR_INVALID_URL = TIZEN_ERROR_WEB_CLASS | 0x24, /**< Invalid URL */
@@ -76,8 +78,6 @@ typedef enum
        DOWNLOAD_ADAPTOR_ERROR_NO_DATA = TIZEN_ERROR_NO_DATA, /**< No data because the set API is not called */
        DOWNLOAD_ADAPTOR_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR , /**< Internal I/O error */
 } download_adaptor_error_e;
-// sync with url-download
-
 
 // sync types with url-download..
 typedef void (*dp_interface_state_changed_cb) (int id, int state, void *user_data);
@@ -130,6 +130,14 @@ EXPORT_API int dp_interface_add_noti_extra(const int id, const char *key, const
 EXPORT_API int dp_interface_get_noti_extra_values(const int id, const char *key, char ***values, unsigned *length);
 EXPORT_API int dp_interface_remove_noti_extra_key(const int id, const char *key);
 
+EXPORT_API int dp_interface_set_notification_bundle(const int id, int type, bundle *b);
+EXPORT_API int dp_interface_get_notification_bundle(const int id, int type, bundle **b);
+EXPORT_API int dp_interface_set_notification_title(const int id, const char *title);
+EXPORT_API int dp_interface_get_notification_title(const int id, char **title);
+EXPORT_API int dp_interface_set_notification_description(const int id, const char *description);
+EXPORT_API int dp_interface_get_notification_description(const int id, char **description);
+EXPORT_API int dp_interface_set_notification_type(const int id, int type);
+EXPORT_API int dp_interface_get_notification_type(const int id, int *type);
 #ifdef __cplusplus
 }
 #endif
index 0828e65..be89a9d 100755 (executable)
@@ -11,16 +11,16 @@ INCLUDE(FindPkgConfig)
 
 pkg_check_modules(dp2_pkgs REQUIRED glib-2.0
                gobject-2.0
-               db-util
                sqlite3
                capi-appfw-app-manager
                capi-network-connection
                wifi-direct
                notification
                appsvc
-               dbus-1
                bundle
-               dlog)
+               libsmack
+               dlog
+               libsystemd-daemon)
 
 FOREACH(flag ${dp2_pkgs_CFLAGS})
        SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
@@ -33,7 +33,6 @@ set(DP2_LINK_LIBRARIES ${GLIB-2_LIBRARIES}
                ${GOBJECT-2_LIBRARIES}
                pthread
                capi-appfw-app-manager
-               downloadagent2
        )
 
 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
@@ -43,10 +42,20 @@ IF(DEFINED DATABASE_FILE)
        ADD_DEFINITIONS(-DDATABASE_FILE=\"${DATABASE_FILE}\")
 ENDIF(DEFINED DATABASE_FILE)
 
+IF(DEFINED DATABASE_SCHEMA_FILE)
+       ADD_DEFINITIONS(-DDATABASE_SCHEMA_FILE=\"${DATABASE_SCHEMA_FILE}\")
+ENDIF(DEFINED DATABASE_SCHEMA_FILE)
+
 IF(DEFINED IMAGE_DIR)
        ADD_DEFINITIONS(-DIMAGE_DIR=\"${IMAGE_DIR}\")
 ENDIF(DEFINED IMAGE_DIR)
 
+IF(DEFINED LOCALE_DIR)
+       ADD_DEFINITIONS(-DPKG_NAME=\"${PKG_NAME}\")
+       ADD_DEFINITIONS(-DLOCALE_DIR=\"${LOCALE_DIR}\")
+ENDIF(DEFINED LOCALE_DIR)
+
+
 ADD_EXECUTABLE(${PROJECT_NAME}
        ${CMAKE_CURRENT_SOURCE_DIR}/download-provider-pid.c
        ${CMAKE_CURRENT_SOURCE_DIR}/download-provider-socket.c
@@ -59,7 +68,7 @@ ADD_EXECUTABLE(${PROJECT_NAME}
        ${CMAKE_CURRENT_SOURCE_DIR}/download-provider-thread-queue.c
        ${CMAKE_CURRENT_SOURCE_DIR}/download-provider-notification.c
        ${CMAKE_CURRENT_SOURCE_DIR}/download-provider-main.c )
-TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${dp2_pkgs_LDFLAGS} ${DP2_LINK_LIBRARIES})
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${dp2_pkgs_LDFLAGS} ${DP2_LINK_LIBRARIES} -ldl)
 INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${BIN_INSTALL_DIR})
 
 INSTALL(FILES include/download-provider-defs.h DESTINATION ${INCLUDE_INSTALL_DIR}/${PKG_NAME})
index e311899..f0b222a 100755 (executable)
 #include <unistd.h>
 #include <time.h>
 #include <sys/time.h>
+#include <string.h>
+#include <dlfcn.h> // dlopen
 
+#include <sys/smack.h>
 #include "download-provider.h"
 #include "download-provider-log.h"
 #include "download-provider-pthread.h"
 #include "download-provider-queue.h"
 #include "download-provider-notification.h"
 #include "download-provider-request.h"
+#include "download-provider-network.h"
+#include "download-provider-da-interface.h"
 
 #include "download-agent-defs.h"
 #include "download-agent-interface.h"
 
+#define DP_SDCARD_MNT_POINT "/opt/storage/sdcard"
+
+static void *g_da_handle = NULL;
+static int (*download_agent_init)(da_client_cb_t *) = NULL; // int da_init(da_client_cb_t *da_client_callback);
+static int (*download_agent_deinit)() = NULL; //  int da_deinit();
+static int (*download_agent_is_alive)(int) = NULL;  // int da_is_valid_download_id(int download_id);
+static int (*download_agent_suspend)(int) = NULL; // int da_suspend_download(int download_id);
+static int (*download_agent_resume)(int) = NULL; // int da_resume_download(int download_id);
+static int (*download_agent_cancel)(int) = NULL; // int da_cancel_download(int download_id);
+static int (*download_agent_start)(const char *, extension_data_t *, int *) = NULL; // int da_start_download_with_extension(const char *url, extension_data_t *ext_data, int *download_id);
+
+
 int dp_is_file_exist(const char *file_path)
 {
        struct stat file_state;
@@ -109,87 +126,102 @@ static void __download_info_cb(user_download_info_t *info, void *user_data)
                return ;
        }
        dp_request_slots *request_slot = (dp_request_slots *) user_data;
-       if (request_slot == NULL || request_slot->request == NULL) {
+       if (request_slot == NULL) {
+               TRACE_ERROR("[NULL-CHECK] request req_id:%d", info->download_id);
+               return ;
+       }
+       CLIENT_MUTEX_LOCK(&request_slot->mutex);
+       if (request_slot->request == NULL) {
                TRACE_ERROR("[NULL-CHECK] request req_id:%d", info->download_id);
+               CLIENT_MUTEX_UNLOCK(&request_slot->mutex);
                return ;
        }
        dp_request *request = request_slot->request;
        if (request->id < 0 || (request->agent_id != info->download_id)) {
                TRACE_ERROR("[NULL-CHECK] agent_id : %d req_id %d",
                        request->agent_id, info->download_id);
+               CLIENT_MUTEX_UNLOCK(&request_slot->mutex);
                return ;
        }
 
        int request_id = request->id;
 
        // update info before sending event
-       if (info->tmp_saved_path) {
-               TRACE_INFO("[STARTED][%d] [%s]", request_id, info->tmp_saved_path);
-               if (dp_db_replace_column(request_id, DP_DB_TABLE_DOWNLOAD_INFO,
-                               DP_DB_COL_TMP_SAVED_PATH, DP_DB_COL_TYPE_TEXT,
-                               info->tmp_saved_path) == 0) {
-                       if (info->file_type) {
-                               TRACE_INFO("[MIME-TYPE][%d] [%s]", request_id, info->file_type);
-                               if (dp_db_set_column(request_id, DP_DB_TABLE_DOWNLOAD_INFO,
-                                               DP_DB_COL_MIMETYPE, DP_DB_COL_TYPE_TEXT,
-                                               info->file_type) < 0)
-                                       TRACE_ERROR("[ERROR][%d][SQL]", request_id);
-                       }
-
-                       if (info->file_size > 0) {
-                               TRACE_INFO
-                                       ("[FILE-SIZE][%d] [%lld]", request_id, info->file_size);
-                               CLIENT_MUTEX_LOCK(&request->mutex);
-                               request->file_size = info->file_size;
-                               CLIENT_MUTEX_UNLOCK(&request->mutex);
-                               if (dp_db_set_column
-                                               (request_id, DP_DB_TABLE_DOWNLOAD_INFO,
-                                               DP_DB_COL_CONTENT_SIZE,
-                                               DP_DB_COL_TYPE_INT64, &info->file_size) < 0)
-                                       TRACE_ERROR("[ERROR][%d][SQL]", request_id);
-                       }
+       if (info->tmp_saved_path != NULL) {
+
+               TRACE_SECURE_DEBUG("[STARTED][%d] [%s]", request_id, info->tmp_saved_path);
+               int conds_count = 6; // id + tmp_saved_path + file_size + content_name + etag
+               int conds_index = 0;
+               db_conds_list_fmt conds_p[conds_count];
+               memset(&conds_p, 0x00, conds_count * sizeof(db_conds_list_fmt));
+
+               conds_p[conds_index].column = DP_DB_COL_TMP_SAVED_PATH;
+               conds_p[conds_index].type = DP_DB_COL_TYPE_TEXT;
+               conds_p[conds_index].value = info->tmp_saved_path;
+               conds_index++;
+               if (info->file_type != NULL) {
+                       conds_p[conds_index].column = DP_DB_COL_MIMETYPE;
+                       conds_p[conds_index].type = DP_DB_COL_TYPE_TEXT;
+                       conds_p[conds_index].value = info->file_type;
+                       conds_index++;
+               }
+               if (info->content_name != NULL) {
+                       conds_p[conds_index].column = DP_DB_COL_CONTENT_NAME;
+                       conds_p[conds_index].type = DP_DB_COL_TYPE_TEXT;
+                       conds_p[conds_index].value = info->content_name;
+                       conds_index++;
+               }
+               if (info->etag != NULL) {
+                       conds_p[conds_index].column = DP_DB_COL_ETAG;
+                       conds_p[conds_index].type = DP_DB_COL_TYPE_TEXT;
+                       conds_p[conds_index].value = info->etag;
+                       conds_index++;
+               }
+               if (info->file_size > 0) {
+                       request->file_size = info->file_size;
+                       conds_p[conds_index].column = DP_DB_COL_CONTENT_SIZE;
+                       conds_p[conds_index].type = DP_DB_COL_TYPE_INT64;
+                       conds_p[conds_index].value = &info->file_size;
+                       conds_index++;
+               }
 
-                       if (info->content_name) {
-                               TRACE_INFO
-                                       ("[CONTENTNAME][%d] [%s]", request_id, info->content_name);
-                               if (dp_db_set_column
-                                               (request_id, DP_DB_TABLE_DOWNLOAD_INFO,
-                                               DP_DB_COL_CONTENT_NAME,
-                                               DP_DB_COL_TYPE_TEXT, info->content_name) < 0)
-                                       TRACE_ERROR("[ERROR][%d][SQL]", request_id);
+               int check_id = dp_db_get_int_column(request_id, DP_DB_TABLE_DOWNLOAD_INFO, DP_DB_COL_ID);
+               if (check_id == request_id) { // update
+                       if (dp_db_update_columns(request_id, DP_DB_TABLE_DOWNLOAD_INFO, conds_index, conds_p) < 0) {
+                               if (dp_db_is_full_error() == 0) {
+                                       request->error = DP_ERROR_NO_SPACE;
+                                       TRACE_ERROR("[SQLITE_FULL][%d]", request_id);
+                                       if (dp_cancel_agent_download(request->agent_id) < 0)
+                                               TRACE_ERROR("[fail][%d]cancel_agent", request_id);
+                                       CLIENT_MUTEX_UNLOCK(&request_slot->mutex);
+                                       return ;
+                               }
                        }
-                       if (info->etag) {
-                               TRACE_INFO("[ETAG][%d] [%s]", request_id, info->etag);
-                               if (dp_db_replace_column
-                                               (request_id, DP_DB_TABLE_DOWNLOAD_INFO, DP_DB_COL_ETAG,
-                                               DP_DB_COL_TYPE_TEXT, info->etag) < 0)
-                                       TRACE_ERROR("[ERROR][%d][SQL]", request_id);
+               } else { // insert
+                       conds_p[conds_index].column = DP_DB_COL_ID;
+                       conds_p[conds_index].type = DP_DB_COL_TYPE_INT;
+                       conds_p[conds_index].value = &request_id;
+                       conds_index++;
+                       if (dp_db_insert_columns(DP_DB_TABLE_DOWNLOAD_INFO, conds_index, conds_p) < 0) {
+                               if (dp_db_is_full_error() == 0) {
+                                       request->error = DP_ERROR_NO_SPACE;
+                                       TRACE_ERROR("[SQLITE_FULL][%d]", request_id);
+                                       if (dp_cancel_agent_download(request->agent_id) < 0)
+                                               TRACE_ERROR("[fail][%d]cancel_agent", request_id);
+                                       CLIENT_MUTEX_UNLOCK(&request_slot->mutex);
+                                       return ;
+                               }
                        }
-               } else {
-                       TRACE_ERROR
-                               ("[ERROR][%d][SQL] failed to insert downloadinfo",
-                               request_id);
                }
-       }
 
-       CLIENT_MUTEX_LOCK(&request->mutex);
+       }
 
+       request->ip_changed = 0;
        request->state = DP_STATE_DOWNLOADING;
-       if (dp_db_set_column(request->id, DP_DB_TABLE_LOG, DP_DB_COL_STATE,
-                       DP_DB_COL_TYPE_INT, &request->state) < 0)
-               TRACE_ERROR("[ERROR][%d][SQL]", request->id);
-
-       if (request->group && request->group->event_socket >= 0 &&
-               request->state_cb)
-               dp_ipc_send_event(request->group->event_socket,
-                       request->id, DP_STATE_DOWNLOADING, DP_ERROR_NONE, 0);
+       request->error = DP_ERROR_NONE;
+       dp_request_state_response(request);
 
-       if (request->auto_notification)
-               request->noti_priv_id =
-                       dp_set_downloadinginfo_notification
-                               (request->id, request->packagename);
-
-       CLIENT_MUTEX_UNLOCK(&request->mutex);
+       CLIENT_MUTEX_UNLOCK(&request_slot->mutex);
 }
 
 static void __progress_cb(user_progress_info_t *info, void *user_data)
@@ -199,18 +231,24 @@ static void __progress_cb(user_progress_info_t *info, void *user_data)
                return ;
        }
        dp_request_slots *request_slot = (dp_request_slots *) user_data;
-       if (request_slot == NULL || request_slot->request == NULL) {
+       if (request_slot == NULL) {
                TRACE_ERROR("[NULL-CHECK] request req_id:%d", info->download_id);
                return ;
        }
+       CLIENT_MUTEX_LOCK(&request_slot->mutex);
+       if (request_slot->request == NULL) {
+               TRACE_ERROR("[NULL-CHECK] request req_id:%d", info->download_id);
+               CLIENT_MUTEX_UNLOCK(&request_slot->mutex);
+               return ;
+       }
        dp_request *request = request_slot->request;
        if (request->id < 0 || (request->agent_id != info->download_id)) {
                TRACE_ERROR("[NULL-CHECK] agent_id : %d req_id %d",
                        request->agent_id, info->download_id);
+               CLIENT_MUTEX_UNLOCK(&request_slot->mutex);
                return ;
        }
 
-       CLIENT_MUTEX_LOCK(&request->mutex);
        if (request->state == DP_STATE_DOWNLOADING) {
                request->received_size = info->received_size;
                time_t tt = time(NULL);
@@ -218,20 +256,148 @@ static void __progress_cb(user_progress_info_t *info, void *user_data)
                // send event every 1 second.
                if (request->progress_lasttime != localTime->tm_sec) {
                        request->progress_lasttime = localTime->tm_sec;
-                       if (request->progress_cb && request->group &&
-                               request->group->event_socket >= 0 &&
-                               request->received_size > 0)
-                               dp_ipc_send_event(request->group->event_socket,
-                                       request->id, request->state, request->error,
-                                       request->received_size);
-                       if (request->auto_notification)
+                       if (request->auto_notification) {
                                dp_update_downloadinginfo_notification
                                        (request->noti_priv_id,
                                        (double)request->received_size,
                                        (double)request->file_size);
+                       } else {
+                               int noti_type = dp_db_get_int_column(request->id, DP_DB_TABLE_NOTIFICATION, DP_DB_COL_NOTI_TYPE);
+                               if(noti_type == DP_NOTIFICATION_TYPE_ALL)
+                                       dp_update_downloadinginfo_notification
+                                               (request->noti_priv_id,
+                                               (double)request->received_size,
+                                               (double)request->file_size);
+                       }
+
+                       if (request->progress_cb && request->group != NULL &&
+                                       request->group->event_socket >= 0 &&
+                                       request->received_size > 0)
+                               dp_ipc_send_event(request->group->event_socket,
+                                       request->id, request->state, request->error,
+                                       request->received_size);
                }
        }
-       CLIENT_MUTEX_UNLOCK(&request->mutex);
+       CLIENT_MUTEX_UNLOCK(&request_slot->mutex);
+}
+
+static int __is_transmute_smack(char *path)
+{
+       char *dir_label = NULL;
+       int ret = -1;
+       if (smack_getlabel(path, &dir_label, SMACK_LABEL_TRANSMUTE) == 0 &&
+                       dir_label != NULL) {
+               if (strncmp(dir_label, "TRUE", strlen(dir_label)) == 0)
+                       ret = 0;
+       }
+       free(dir_label);
+       return ret;
+}
+
+static dp_error_type __set_dir_smack_label(char *smack_label, char *dir_path, char *saved_path)
+{
+       if (smack_label == NULL || dir_path== NULL || saved_path == NULL)
+               return DP_ERROR_PERMISSION_DENIED;
+
+       int is_setted_dir_label = 0;
+       dp_error_type errorcode = DP_ERROR_NONE;
+
+       TRACE_SECURE_INFO("[PARSE] dir path [%s]", dir_path);
+       if (__is_transmute_smack(dir_path) < 0) {
+               TRACE_DEBUG("[SMACK] no transmute");
+       } else {
+               char *dir_label = NULL;
+               if (smack_getlabel(dir_path, &dir_label,
+                               SMACK_LABEL_ACCESS) == 0) {
+                       if (smack_have_access(smack_label, dir_label, "t") > 0) {
+                               if (smack_setlabel(saved_path, dir_label,
+                                               SMACK_LABEL_ACCESS) != 0) {
+                                       TRACE_SECURE_ERROR("[SMACK ERROR] label:%s",
+                                               dir_label);
+                                       errorcode = DP_ERROR_PERMISSION_DENIED;
+                               } else {
+                                       is_setted_dir_label = 1;
+                               }
+                       } else {
+                               TRACE_SECURE_ERROR("[SMACK ERROR] access:%s/%s",
+                                       smack_label, dir_label);
+                               errorcode = DP_ERROR_PERMISSION_DENIED;
+                       }
+               } else {
+                       TRACE_SECURE_ERROR("[SMACK ERROR] no label:", dir_path);
+                       errorcode = DP_ERROR_PERMISSION_DENIED;
+               }
+               free(dir_label);
+       }
+       if (is_setted_dir_label == 0 &&
+                       smack_setlabel(saved_path, smack_label,
+                               SMACK_LABEL_ACCESS) != 0) {
+               TRACE_SECURE_ERROR("[SMACK ERROR] label:%s", smack_label);
+               errorcode = DP_ERROR_PERMISSION_DENIED;
+               // remove file.
+               if (dp_is_file_exist(saved_path) == 0)
+                       unlink(saved_path);
+       }
+       return errorcode;
+}
+
+static dp_error_type __set_file_permission_to_client(dp_request *request, char *saved_path)
+{
+       dp_error_type errorcode = DP_ERROR_NONE;
+       char *str = NULL;
+       char *smack_label = NULL;
+       str = strrchr(saved_path, '/');
+       dp_credential cred;
+       if (request->group == NULL) {
+               cred.uid = dp_db_cond_get_int(DP_DB_TABLE_GROUPS,
+                                       DP_DB_GROUPS_COL_UID,
+                                       DP_DB_GROUPS_COL_PKG,
+                                       DP_DB_COL_TYPE_TEXT, request->packagename);
+               cred.gid = dp_db_cond_get_int(DP_DB_TABLE_GROUPS,
+                                       DP_DB_GROUPS_COL_GID,
+                                       DP_DB_GROUPS_COL_PKG,
+                                       DP_DB_COL_TYPE_TEXT, request->packagename);
+       } else {
+               cred = request->group->credential;
+       }
+       TRACE_DEBUG
+               ("[chown][%d] [%d][%d]", request->id, cred.uid, cred.gid);
+       if (chown(saved_path, cred.uid, cred.gid) < 0)
+               TRACE_STRERROR("[ERROR][%d] chown", request->id);
+       if (chmod(saved_path,
+                       S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) < 0)
+               TRACE_STRERROR("[ERROR][%d] chmod", request->id);
+       if (dp_is_smackfs_mounted() == 1) {
+               if (request->group == NULL) {
+                       // get smack_label from sql
+                       smack_label =
+                               dp_db_cond_get_text(DP_DB_TABLE_GROUPS,
+                                       DP_DB_GROUPS_COL_SMACK_LABEL,
+                                       DP_DB_GROUPS_COL_PKG,
+                                       DP_DB_COL_TYPE_TEXT, request->packagename);
+               } else {
+                       smack_label = dp_strdup(request->group->smack_label);
+               }
+               if (smack_label == NULL) {
+                       TRACE_SECURE_ERROR("[SMACK][%d] no label", request->id);
+                       errorcode = DP_ERROR_PERMISSION_DENIED;
+               } else {
+                       size_t len = str - (saved_path);
+                       char *dir_path = (char *)calloc(len + 1, sizeof(char));
+                       if (dir_path != NULL) {
+                               strncpy(dir_path, saved_path, len);
+                               errorcode =
+                                       __set_dir_smack_label(smack_label, dir_path,
+                                               saved_path);
+                               free(dir_path);
+                       } else {
+                               TRACE_SECURE_ERROR("[ERROR] calloc");
+                               errorcode = DP_ERROR_OUT_OF_MEMORY;
+                       }
+                       free(smack_label);
+               }
+       }
+       return errorcode;
 }
 
 static void __finished_cb(user_finished_info_t *info, void *user_data)
@@ -240,33 +406,29 @@ static void __finished_cb(user_finished_info_t *info, void *user_data)
                TRACE_ERROR("[NULL-CHECK] Agent info");
                return ;
        }
-       TRACE_INFO("Agent ID[%d] err[%d] http_status[%d]",
-               info->download_id, info->err, info->http_status);
        dp_request_slots *request_slot = (dp_request_slots *) user_data;
-       if (request_slot == NULL || request_slot->request == NULL) {
+       if (request_slot == NULL) {
                TRACE_ERROR("[NULL-CHECK] request req_id:%d", info->download_id);
                return ;
        }
+       CLIENT_MUTEX_LOCK(&request_slot->mutex);
+       if (request_slot->request == NULL) {
+               TRACE_ERROR("[NULL-CHECK] request req_id:%d", info->download_id);
+               CLIENT_MUTEX_UNLOCK(&request_slot->mutex);
+               return ;
+       }
        dp_request *request = request_slot->request;
        if (request->id < 0 || (request->agent_id != info->download_id)) {
                TRACE_ERROR("[NULL-CHECK] agent_id : %d req_id %d",
                        request->agent_id, info->download_id);
+               CLIENT_MUTEX_UNLOCK(&request_slot->mutex);
                return ;
        }
 
-       CLIENT_MUTEX_LOCK(&request->mutex);
-
        int request_id = request->id;
-       dp_credential cred = request->credential;
-       CLIENT_MUTEX_UNLOCK(&request->mutex);
        dp_state_type state = DP_STATE_NONE;
        dp_error_type errorcode = DP_ERROR_NONE;
 
-       // update info before sending event
-       if (dp_db_update_date
-                       (request_id, DP_DB_TABLE_LOG, DP_DB_COL_ACCESS_TIME) < 0)
-               TRACE_ERROR("[ERROR][%d][SQL]", request_id);
-
        if (info->http_status > 0)
                if (dp_db_replace_column(request_id, DP_DB_TABLE_DOWNLOAD_INFO,
                                DP_DB_COL_HTTP_STATUS,
@@ -274,173 +436,269 @@ static void __finished_cb(user_finished_info_t *info, void *user_data)
                        TRACE_ERROR("[ERROR][%d][SQL]", request_id);
 
        if (info->err == DA_RESULT_OK) {
-               if (info->saved_path) {
-                       char *str = NULL;
-                       char *content_name = NULL;
 
+               int conds_count = 5; // id + saved_path + content_name + http_status + file_size
+               int conds_index = 0;
+               db_conds_list_fmt conds_p[conds_count];
+               memset(&conds_p, 0x00, conds_count * sizeof(db_conds_list_fmt));
+
+               char *content_name = NULL;
+               if (info->saved_path != NULL) {
+                       char *str = NULL;
+                       if(!(strncmp(DP_SDCARD_MNT_POINT, info->saved_path,
+                               strlen(DP_SDCARD_MNT_POINT)) == 0)) {
+                               errorcode = __set_file_permission_to_client(request,
+                                       info->saved_path);
+                       }
                        str = strrchr(info->saved_path, '/');
-                       if (str) {
+                       if (str != NULL) {
                                str++;
                                content_name = dp_strdup(str);
-                               TRACE_INFO("[PARSE][%d] content_name [%s]",
+                               TRACE_SECURE_DEBUG("[PARSE][%d] content_name [%s]",
                                        request_id, content_name);
                        }
-                       TRACE_INFO
-                               ("[chown][%d] [%d][%d]", request_id, cred.uid, cred.gid);
-                       if (chown(info->saved_path, cred.uid, cred.gid) < 0)
-                               TRACE_STRERROR("[ERROR][%d] chown", request_id);
-                       if (dp_db_replace_column
-                                       (request_id, DP_DB_TABLE_DOWNLOAD_INFO,
-                                       DP_DB_COL_SAVED_PATH,
-                                       DP_DB_COL_TYPE_TEXT, info->saved_path) == 0) {
-                               if (content_name != NULL) {
-                                       if (dp_db_set_column
-                                                       (request_id, DP_DB_TABLE_DOWNLOAD_INFO,
-                                                       DP_DB_COL_CONTENT_NAME,
-                                                       DP_DB_COL_TYPE_TEXT, content_name) < 0)
-                                               TRACE_ERROR("[ERROR][%d][SQL]", request_id);
-                               }
-                       } else {
-                               TRACE_ERROR("[ERROR][%d][SQL]", request_id);
-                       }
-                       if (content_name != NULL)
-                               free(content_name);
 
-                       errorcode = DP_ERROR_NONE;
-                       state = DP_STATE_COMPLETED;
+                       conds_p[conds_index].column = DP_DB_COL_SAVED_PATH;
+                       conds_p[conds_index].type = DP_DB_COL_TYPE_TEXT;
+                       conds_p[conds_index].value = info->saved_path;
+                       conds_index++;
+                       if (content_name != NULL) {
+                               conds_p[conds_index].column = DP_DB_COL_CONTENT_NAME;
+                               conds_p[conds_index].type = DP_DB_COL_TYPE_TEXT;
+                               conds_p[conds_index].value = content_name;
+                               conds_index++;
+                       }
 
-                       TRACE_INFO("[COMPLETED][%d] saved to [%s]",
+                       if (errorcode == DP_ERROR_NONE) {
+                               state = DP_STATE_COMPLETED;
+                               TRACE_SECURE_INFO("[COMPLETED][%d] saved to [%s]",
+                                       request_id, info->saved_path);
+                       } else {
+                               state = DP_STATE_FAILED;
+                               TRACE_SECURE_INFO("[FAILED][%d] saved to [%s]",
                                        request_id, info->saved_path);
+                       }
                } else {
                        TRACE_ERROR("Cannot enter here");
                        TRACE_ERROR("[ERROR][%d] No SavedPath", request_id);
                        errorcode = DP_ERROR_INVALID_DESTINATION;
                        state = DP_STATE_FAILED;
                }
-               CLIENT_MUTEX_LOCK(&request->mutex);
                if (request->file_size == 0) {
                        request->file_size = request->received_size;
-                       if (dp_db_replace_column
-                                       (request_id, DP_DB_TABLE_DOWNLOAD_INFO,
-                                       DP_DB_COL_CONTENT_SIZE,
-                                       DP_DB_COL_TYPE_INT64, &request->file_size ) < 0)
-                               TRACE_ERROR("[ERROR][%d][SQL]", request_id);
+                       conds_p[conds_index].column = DP_DB_COL_CONTENT_SIZE;
+                       conds_p[conds_index].type = DP_DB_COL_TYPE_INT64;
+                       conds_p[conds_index].value = &request->file_size;
+                       conds_index++;
+               }
+
+               int check_id = dp_db_get_int_column(request_id, DP_DB_TABLE_DOWNLOAD_INFO, DP_DB_COL_ID);
+               if (check_id == request_id) { // update
+                       if (dp_db_update_columns(request_id, DP_DB_TABLE_DOWNLOAD_INFO, conds_index, conds_p) < 0) {
+                               if (dp_db_is_full_error() == 0) {
+                                       request->error = DP_ERROR_NO_SPACE;
+                                       TRACE_ERROR("[SQLITE_FULL][%d]", request_id);
+                                       if (dp_cancel_agent_download(request->agent_id) < 0)
+                                               TRACE_ERROR("[fail][%d]cancel_agent", request_id);
+                                       CLIENT_MUTEX_UNLOCK(&request_slot->mutex);
+                                       return ;
+                               }
+                       }
+               } else { // insert
+                       conds_p[conds_index].column = DP_DB_COL_ID;
+                       conds_p[conds_index].type = DP_DB_COL_TYPE_INT;
+                       conds_p[conds_index].value = &request_id;
+                       conds_index++;
+                       if (dp_db_insert_columns(DP_DB_TABLE_DOWNLOAD_INFO, conds_index, conds_p) < 0) {
+                               if (dp_db_is_full_error() == 0) {
+                                       request->error = DP_ERROR_NO_SPACE;
+                                       TRACE_ERROR("[SQLITE_FULL][%d]", request_id);
+                                       if (dp_cancel_agent_download(request->agent_id) < 0)
+                                               TRACE_ERROR("[fail][%d]cancel_agent", request_id);
+                                       CLIENT_MUTEX_UNLOCK(&request_slot->mutex);
+                                       return ;
+                               }
+                       }
                }
-               CLIENT_MUTEX_UNLOCK(&request->mutex);
-       } else if (info->err == DA_RESULT_USER_CANCELED) {
-               state = DP_STATE_CANCELED;
-               errorcode = DP_ERROR_NONE;
-               TRACE_INFO("[CANCELED][%d]", request_id);
+               free(content_name);
        } else {
-               state = DP_STATE_FAILED;
-               errorcode = __change_error(info->err);
-               TRACE_INFO("[FAILED][%d][%s]", request_id,
-                               dp_print_errorcode(errorcode));
-       }
+               char *tmp_saved_path =
+                       dp_request_get_tmpsavedpath(request_id, request, &errorcode);
 
-       if (dp_db_set_column
-                       (request_id, DP_DB_TABLE_LOG, DP_DB_COL_STATE,
-                       DP_DB_COL_TYPE_INT, &state) < 0)
-               TRACE_ERROR("[ERROR][%d][SQL]", request_id);
+               if (tmp_saved_path != NULL) {
+                       errorcode = __set_file_permission_to_client(request, tmp_saved_path);
+                       free(tmp_saved_path);
+               } else {
+                       TRACE_ERROR("Cannot enter here");
+                       TRACE_ERROR("[ERROR][%d] No SavedPath", request_id);
+               }
 
-       if (errorcode != DP_ERROR_NONE) {
-               if (dp_db_set_column(request_id, DP_DB_TABLE_LOG,
-                               DP_DB_COL_ERRORCODE, DP_DB_COL_TYPE_INT,
-                               &errorcode) < 0)
-                       TRACE_ERROR("[ERROR][%d][SQL]", request_id);
+               if (info->err == DA_RESULT_USER_CANCELED) {
+                       state = DP_STATE_CANCELED;
+                       errorcode = request->error;
+                       TRACE_INFO("[CANCELED][%d]", request_id);
+               } else {
+                       state = DP_STATE_FAILED;
+                       errorcode = __change_error(info->err);
+                       TRACE_ERROR("[FAILED][%d][%s]", request_id,
+                                       dp_print_errorcode(errorcode));
+               }
        }
 
-       // need MUTEX LOCK
-       CLIENT_MUTEX_LOCK(&request->mutex);
-
        request->state = state;
        request->error = errorcode;
 
-       // stay on memory till called destroy by client or timeout
-       if (request->group != NULL && request->group->event_socket >= 0) {
-               /* update the received file size.
-               * The last received file size cannot update
-               * because of reducing update algorithm*/
-               if (request->received_size > 0)
-                       dp_ipc_send_event(request->group->event_socket,
-                               request->id, DP_STATE_DOWNLOADING, request->error,
-                               request->received_size);
-               if (request->state_cb)
-                       dp_ipc_send_event(request->group->event_socket,
-                               request->id, request->state, request->error, 0);
-               request->group->queued_count--;
+       // auto resume when failed by ip_changed.
+       if (state == DP_STATE_FAILED && info->err == DA_ERR_NETWORK_FAIL &&
+                       request->network_type != DP_NETWORK_TYPE_WIFI_DIRECT) {
+               if (request->ip_changed == 1 &&
+                               dp_get_network_connection_instant_status() !=
+                               DP_NETWORK_TYPE_OFF) {
+                       // resume
+                       TRACE_DEBUG("[RESUME][%d] will be queued", request_id);
+                       request->state = DP_STATE_QUEUED;
+                       request->error = DP_ERROR_NONE;
+               } else {
+                       TRACE_DEBUG("[CHECK][%d] check again in timeout", request_id);
+               }
+       } else {
+               // stay on memory till called destroy by client or timeout
+               if (request->group != NULL &&
+                               request->group->event_socket >= 0) {
+                       /* update the received file size.
+                       * The last received file size cannot update
+                       * because of reducing update algorithm*/
+                       if (request->received_size > 0) {
+                               dp_ipc_send_event(request->group->event_socket,
+                                       request->id, DP_STATE_DOWNLOADING, request->error,
+                                       request->received_size);
+                       }
+               }
+               dp_request_state_response(request);
        }
 
-       // to prevent the crash . check packagename of request
-       if (request->auto_notification && request->packagename != NULL)
-               request->noti_priv_id =
-                       dp_set_downloadedinfo_notification(request->noti_priv_id,
-                               request->id, request->packagename, request->state);
-
-       request->stop_time = (int)time(NULL);
-
-       CLIENT_MUTEX_UNLOCK(&request->mutex);
+       CLIENT_MUTEX_UNLOCK(&request_slot->mutex);
 
        dp_thread_queue_manager_wake_up();
 }
 
 static void __paused_cb(user_paused_info_t *info, void *user_data)
 {
-       TRACE_INFO("");
        dp_request_slots *request_slot = (dp_request_slots *) user_data;
-       if (request_slot == NULL || request_slot->request == NULL) {
+       if (request_slot == NULL) {
+               TRACE_ERROR("[NULL-CHECK] request req_id:%d", info->download_id);
+               return ;
+       }
+       CLIENT_MUTEX_LOCK(&request_slot->mutex);
+       if (request_slot->request == NULL) {
                TRACE_ERROR("[NULL-CHECK] request req_id:%d", info->download_id);
+               CLIENT_MUTEX_UNLOCK(&request_slot->mutex);
                return ;
        }
        dp_request *request = request_slot->request;
        if (request->id < 0 || (request->agent_id != info->download_id)) {
                TRACE_ERROR("[NULL-CHECK] agent_id : %d req_id %d",
                        request->agent_id, info->download_id);
+               CLIENT_MUTEX_UNLOCK(&request_slot->mutex);
+               return ;
+       }
+
+       if (request->state != DP_STATE_PAUSE_REQUESTED) {
+               TRACE_ERROR("[CHECK] now status:%d", request->state);
+               CLIENT_MUTEX_UNLOCK(&request_slot->mutex);
                return ;
        }
 
-       CLIENT_MUTEX_LOCK(&request->mutex);
        int request_id = request->id;
-       CLIENT_MUTEX_UNLOCK(&request->mutex);
 
        if (dp_db_update_date
                        (request_id, DP_DB_TABLE_LOG, DP_DB_COL_ACCESS_TIME) < 0)
                TRACE_ERROR("[ERROR][%d][SQL]", request_id);
 
-       // need MUTEX LOCK
-       CLIENT_MUTEX_LOCK(&request->mutex);
-
        request->state = DP_STATE_PAUSED;
+       request->error = DP_ERROR_NONE;
+       dp_request_state_response(request);
 
-       if (dp_db_set_column
-                       (request->id, DP_DB_TABLE_LOG, DP_DB_COL_STATE,
-                       DP_DB_COL_TYPE_INT, &request->state) < 0) {
-               TRACE_ERROR("[ERROR][%d][SQL]", request->id);
-       }
-
-       if (request->group &&
-               request->group->event_socket >= 0 && request->state_cb)
-               dp_ipc_send_event(request->group->event_socket,
-                       request->id, request->state, request->error, 0);
-
-       if (request->group)
-               request->group->queued_count--;
-
-       CLIENT_MUTEX_UNLOCK(&request->mutex);
+       CLIENT_MUTEX_UNLOCK(&request_slot->mutex);
 
        dp_thread_queue_manager_wake_up();
 }
 
 int dp_init_agent()
 {
-       int da_ret = 0;
+
+       g_da_handle = dlopen("/usr/lib/libdownloadagent2.so", RTLD_LAZY | RTLD_GLOBAL);
+       if (!g_da_handle) {
+               TRACE_ERROR("[dlopen] %s", dlerror());
+               g_da_handle = NULL;
+               return DP_ERROR_OUT_OF_MEMORY;
+       }
+       dlerror();    /* Clear any existing error */
+
+       *(void **) (&download_agent_init) = dlsym(g_da_handle, "da_init");
+       if (download_agent_init == NULL ) {
+               TRACE_ERROR("[dlsym] da_init:%s", dlerror());
+               dlclose(g_da_handle);
+               g_da_handle = NULL;
+               return DP_ERROR_OUT_OF_MEMORY;
+       }
+
+       *(void **) (&download_agent_deinit)  = dlsym(g_da_handle, "da_deinit");
+       if (download_agent_deinit == NULL ) {
+               TRACE_ERROR("[dlsym] da_deinit:%s", dlerror());
+               dlclose(g_da_handle);
+               g_da_handle = NULL;
+               return DP_ERROR_OUT_OF_MEMORY;
+       }
+
+       *(void **) (&download_agent_is_alive)  = dlsym(g_da_handle, "da_is_valid_download_id");
+       if (download_agent_is_alive == NULL ) {
+               TRACE_ERROR("[dlsym] da_is_valid_download_id:%s", dlerror());
+               dlclose(g_da_handle);
+               g_da_handle = NULL;
+               return DP_ERROR_OUT_OF_MEMORY;
+       }
+
+       *(void **) (&download_agent_suspend)  = dlsym(g_da_handle, "da_suspend_download");
+       if (download_agent_suspend == NULL ) {
+               TRACE_ERROR("[dlsym] da_suspend_download:%s", dlerror());
+               dlclose(g_da_handle);
+               g_da_handle = NULL;
+               return DP_ERROR_OUT_OF_MEMORY;
+       }
+
+       *(void **) (&download_agent_resume)  = dlsym(g_da_handle, "da_resume_download");
+       if (download_agent_resume == NULL ) {
+               TRACE_ERROR("[dlsym] da_resume_download:%s", dlerror());
+               dlclose(g_da_handle);
+               g_da_handle = NULL;
+               return DP_ERROR_OUT_OF_MEMORY;
+       }
+
+       *(void **) (&download_agent_cancel)  = dlsym(g_da_handle, "da_cancel_download");
+       if (download_agent_cancel == NULL ) {
+               TRACE_ERROR("[dlsym] da_cancel_download:%s", dlerror());
+               dlclose(g_da_handle);
+               g_da_handle = NULL;
+               return DP_ERROR_OUT_OF_MEMORY;
+       }
+
+       *(void **) (&download_agent_start)  = dlsym(g_da_handle, "da_start_download_with_extension");
+       if (download_agent_start == NULL ) {
+               TRACE_ERROR("[dlsym] da_start_download_with_extension:%s", dlerror());
+               dlclose(g_da_handle);
+               g_da_handle = NULL;
+               return DP_ERROR_OUT_OF_MEMORY;
+       }
+
+       int da_ret = -1;
        da_client_cb_t da_cb = {
                __download_info_cb,
                __progress_cb,
                __finished_cb,
                __paused_cb
        };
-       da_ret = da_init(&da_cb);
+       da_ret = (*download_agent_init)(&da_cb);
        if (da_ret != DA_RESULT_OK) {
                return DP_ERROR_OUT_OF_MEMORY;
        }
@@ -449,7 +707,13 @@ int dp_init_agent()
 
 void dp_deinit_agent()
 {
-       da_deinit();
+       if (g_da_handle != NULL) {
+               if (download_agent_deinit != NULL)
+                       (*download_agent_deinit)();
+
+               dlclose(g_da_handle);
+               g_da_handle = NULL;
+       }
 }
 
 // 1 : alive
@@ -461,7 +725,8 @@ int dp_is_alive_download(int req_id)
                TRACE_ERROR("[NULL-CHECK] req_id");
                return 0;
        }
-       da_ret = da_is_valid_download_id(req_id);
+       if (download_agent_is_alive != NULL)
+               da_ret = (*download_agent_is_alive)(req_id);
        return da_ret;
 }
 
@@ -477,8 +742,10 @@ dp_error_type dp_cancel_agent_download(int req_id)
                TRACE_ERROR("[CHECK agent-id:%d] dead request", req_id);
                return -1;
        }
-       if (da_cancel_download(req_id) == DA_RESULT_OK)
-               return 0;
+       if (download_agent_cancel != NULL) {
+               if ((*download_agent_cancel)(req_id) == DA_RESULT_OK)
+                       return 0;
+       }
        return -1;
 }
 
@@ -494,8 +761,10 @@ dp_error_type dp_pause_agent_download(int req_id)
                TRACE_ERROR("[CHECK agent-id:%d] dead request", req_id);
                return -1;
        }
-       if (da_suspend_download(req_id) == DA_RESULT_OK)
-               return 0;
+       if (download_agent_suspend != NULL) {
+               if ((*download_agent_suspend)(req_id) == DA_RESULT_OK)
+                       return 0;
+       }
        return -1;
 }
 
@@ -511,18 +780,21 @@ dp_error_type dp_start_agent_download(dp_request_slots *request_slot)
        extension_data_t ext_data = {0,};
        char *etag = NULL;
 
-       TRACE_INFO("");
-       if (request_slot == NULL || request_slot->request == NULL) {
+       if (request_slot == NULL) {
                TRACE_ERROR("[NULL-CHECK] download_clientinfo_slot");
                return DP_ERROR_INVALID_PARAMETER;
        }
+
+       if (request_slot->request == NULL) {
+               TRACE_ERROR("[NULL-CHECK] download_clientinfo_slot");
+               return DP_ERROR_INVALID_PARAMETER;
+       }
+
        dp_request *request = request_slot->request;
-       CLIENT_MUTEX_LOCK(&(request->mutex));
 
-       char *url = dp_request_get_url(request->id, request, &errorcode);
+       char *url = dp_request_get_url(request->id, &errorcode);
        if (url == NULL) {
                TRACE_ERROR("[ERROR][%d] URL is NULL", request->id);
-               CLIENT_MUTEX_UNLOCK(&(request->mutex));
                return DP_ERROR_INVALID_URL;
        }
        char *destination =
@@ -542,13 +814,13 @@ dp_error_type dp_start_agent_download(dp_request_slots *request_slot)
        if (tmp_saved_path) {
                etag = dp_request_get_etag(request->id, request, &errorcode);
                if (etag) {
-                       TRACE_INFO("[RESUME][%d]", request->id);
+                       TRACE_DEBUG("[RESUME][%d]", request->id);
                        ext_data.etag = etag;
                        ext_data.temp_file_path = tmp_saved_path;
                } else {
                        /* FIXME later : It is better to handle the unlink function in download agaent module
                         * or in upload the request data to memory after the download provider process is restarted */
-                       TRACE_INFO("[RESTART][%d] try to remove tmp file [%s]",
+                       TRACE_SECURE_INFO("[RESTART][%d] try to remove tmp file [%s]",
                                request->id, tmp_saved_path);
                        if (dp_is_file_exist(tmp_saved_path) == 0)
                                if (unlink(tmp_saved_path) != 0)
@@ -556,6 +828,9 @@ dp_error_type dp_start_agent_download(dp_request_slots *request_slot)
                                                ("[ERROR][%d] remove file", request->id);
                }
        }
+       char *pkg_name = dp_request_get_pkg_name(request->id, request, &errorcode);
+       if (pkg_name != NULL)
+               ext_data.pkg_name = pkg_name;
        // get headers list from httpheaders table(DB)
        int headers_count = dp_db_get_cond_rows_count
                        (request->id, DP_DB_TABLE_HTTP_HEADERS, NULL, 0, NULL);
@@ -570,8 +845,8 @@ dp_error_type dp_start_agent_download(dp_request_slots *request_slot)
        ext_data.user_data = (void *)request_slot;
 
        // call start API of agent lib
-       da_ret =
-               da_start_download_with_extension(url, &ext_data, &req_dl_id);
+       if (download_agent_start != NULL)
+               da_ret = (*download_agent_start)(url, &ext_data, &req_dl_id);
        if (ext_data.request_header_count > 0) {
                int len = 0;
                int i = 0;
@@ -591,23 +866,22 @@ dp_error_type dp_start_agent_download(dp_request_slots *request_slot)
                free(tmp_saved_path);
        if (etag)
                free(etag);
+       if (pkg_name)
+               free(pkg_name);
 
        // if start_download() return error cause of maximun download limitation,
        // set state to DOWNLOAD_STATE_PENDED.
        if (da_ret == DA_ERR_ALREADY_MAX_DOWNLOAD) {
-               TRACE_INFO("[PENDING][%d] DA_ERR_ALREADY_MAX_DOWNLOAD [%d]",
+               TRACE_DEBUG("[PENDING][%d] DA_ERR_ALREADY_MAX_DOWNLOAD [%d]",
                        request->id, da_ret);
-               CLIENT_MUTEX_UNLOCK(&(request->mutex));
                return DP_ERROR_TOO_MANY_DOWNLOADS;
        } else if (da_ret != DA_RESULT_OK) {
                TRACE_ERROR("[ERROR][%d] DP_ERROR_CONNECTION_FAILED [%d]",
                        request->id, da_ret);
-               CLIENT_MUTEX_UNLOCK(&(request->mutex));
                return __change_error(da_ret);
        }
-       TRACE_INFO("[SUCCESS][%d] agent_id [%d]", request->id, req_dl_id);
+       TRACE_DEBUG("[SUCCESS][%d] agent_id [%d]", request->id, req_dl_id);
        request->agent_id = req_dl_id;
-       CLIENT_MUTEX_UNLOCK(&(request->mutex));
        return DP_ERROR_NONE;
 }
 
@@ -618,7 +892,8 @@ dp_error_type dp_resume_agent_download(int req_id)
                TRACE_ERROR("[NULL-CHECK] req_id");
                return DP_ERROR_INVALID_PARAMETER;
        }
-       da_ret = da_resume_download(req_id);
+       if (download_agent_resume != NULL)
+               da_ret = (*download_agent_resume)(req_id);
        if (da_ret == DA_RESULT_OK)
                return DP_ERROR_NONE;
        else if (da_ret == DA_ERR_INVALID_STATE)
index ead22ca..4bc1353 100755 (executable)
  * limitations under the License.
  */
 
-#include <db-util.h>
-
+#include <stdio.h>
 #include <string.h>
 #include <errno.h>
 
+#include <stdlib.h>
+#include <sqlite3.h>
+
 #include "download-provider-config.h"
 #include "download-provider-db.h"
 #include "download-provider-slots.h"
@@ -43,44 +45,125 @@ typedef enum {
 } db_query_type;
 
 sqlite3 *g_dp_db_handle = 0;
+sqlite3_stmt *g_dp_db_logging_new_stmt = NULL;
+sqlite3_stmt *g_dp_db_logging_status_stmt = NULL;
+sqlite3_stmt *g_dp_db_logging_get_state_stmt = NULL;
+
+static void __dp_finalize(sqlite3_stmt *stmt)
+{
+       if (sqlite3_finalize(stmt) != SQLITE_OK)
+               TRACE_ERROR("failed sqlite3_finalize [%s]",
+                       sqlite3_errmsg(g_dp_db_handle));
+}
 
 // called when terminating process
 void dp_db_close()
 {
        if (g_dp_db_handle) {
+               if (g_dp_db_logging_new_stmt != NULL)
+                       __dp_finalize(g_dp_db_logging_new_stmt);
+               if (g_dp_db_logging_status_stmt != NULL)
+                       __dp_finalize(g_dp_db_logging_status_stmt);
                sqlite3_exec(g_dp_db_handle, "VACUUM;", 0, 0, 0); // remove empty page of db
-               db_util_close(g_dp_db_handle);
+               sqlite3_close(g_dp_db_handle);
        }
        g_dp_db_handle = 0;
 }
 
+static void __load_sql_schema()
+{
+       char *rebuild_query =
+               sqlite3_mprintf("sqlite3 %s '.read %s'", DATABASE_FILE, DATABASE_SCHEMA_FILE);
+       if (rebuild_query != NULL) {
+               TRACE_SECURE_INFO("[QUERY] %s", rebuild_query);
+               system(rebuild_query);
+               sqlite3_free(rebuild_query);
+       }
+}
+
+static int __dp_sql_open()
+{
+       return dp_db_open();
+}
+
+static int __check_table(char *table)
+{
+       //"SELECT name FROM sqlite_master WHERE type='table' AND name='" + table +"'";
+       sqlite3_stmt *stmt = NULL;
+
+       if (table == NULL) {
+               TRACE_ERROR("[CHECK TABLE NAME]");
+               return -1;
+       }
+
+       if (__dp_sql_open() < 0) {
+               TRACE_ERROR("[OPEN] [%s]", sqlite3_errmsg(g_dp_db_handle));
+               return -1;
+       }
+
+       char *query = sqlite3_mprintf("SELECT name FROM sqlite_master WHERE type='table' AND name='%s'", table);
+       if (query == NULL) {
+               TRACE_ERROR("[CHECK COMBINE]");
+               return -1;
+       }
+
+       int ret = sqlite3_prepare_v2(g_dp_db_handle, query, -1, &stmt, NULL);
+       sqlite3_free(query);
+       if (ret != SQLITE_OK) {
+               TRACE_ERROR("[PREPARE] [%s]", sqlite3_errmsg(g_dp_db_handle));
+               __dp_finalize(stmt);
+               return -1;
+       }
+       if (sqlite3_step(stmt) == SQLITE_ROW) {
+               __dp_finalize(stmt);
+               return 1;
+       }
+       __dp_finalize(stmt);
+       return 0;
+}
+
 // called when launching process or in every API
 int dp_db_open()
 {
        if (g_dp_db_handle == 0) {
-               if (db_util_open(DATABASE_FILE, &g_dp_db_handle,
-                               DB_UTIL_REGISTER_HOOK_METHOD) != SQLITE_OK) {
-                       TRACE_ERROR("failed db_util_open [%s][%s]", DATABASE_FILE,
+               TRACE_SECURE_INFO("TRY to open [%s]", DATABASE_FILE);
+               if (sqlite3_open_v2(DATABASE_FILE, &g_dp_db_handle,
+                               SQLITE_OPEN_READWRITE, NULL) != SQLITE_OK) {
+                       TRACE_ERROR("[ERROR][%s][%s]", DATABASE_FILE,
                                sqlite3_errmsg(g_dp_db_handle));
+                       int errorcode = sqlite3_errcode(g_dp_db_handle);
                        dp_db_close();
+                       if (errorcode == SQLITE_CORRUPT) {
+                               TRACE_SECURE_INFO("unlink [%s]", DATABASE_FILE);
+                               unlink(DATABASE_FILE);
+                               errorcode = SQLITE_CANTOPEN;
+                       }
+                       if (errorcode == SQLITE_CANTOPEN) {
+                               __load_sql_schema();
+                               return dp_db_open();
+                       }
                        return -1;
                }
                sqlite3_exec(g_dp_db_handle, "PRAGMA journal_mode=PERSIST;", 0, 0, 0);
                sqlite3_exec(g_dp_db_handle, "PRAGMA foreign_keys=ON;", 0, 0, 0);
+
+               // if not found group table. load again. (FOTA)
+               // new table(groups) created by smack_label. 2013.07.09
+               if (__check_table(DP_DB_TABLE_GROUPS) == 0)
+                       __load_sql_schema();
        }
        return g_dp_db_handle ? 0 : -1;
 }
 
-static int __dp_sql_open()
-{
-       return dp_db_open();
-}
-
-static void __dp_finalize(sqlite3_stmt *stmt)
+int dp_db_is_full_error()
 {
-       if (sqlite3_finalize(stmt) != SQLITE_OK)
-               TRACE_ERROR("failed sqlite3_finalize [%s]",
-                       sqlite3_errmsg(g_dp_db_handle));
+       if (g_dp_db_handle == 0) {
+               TRACE_ERROR("HANDLE is null");
+               return -1;
+       }
+       if (sqlite3_errcode(g_dp_db_handle) == SQLITE_FULL)
+               return 0;
+       return -1;
 }
 
 int dp_db_get_count_by_limit_time()
@@ -154,9 +237,6 @@ int dp_db_get_list_by_limit_time(dp_request_slots *requests, int limit)
                requests[i].request->id = sqlite3_column_int(stmt, 0);
                // state
                requests[i].request->state = sqlite3_column_int(stmt, 1);
-
-               TRACE_INFO("ID : %d",  requests[i].request->id);
-               TRACE_INFO("state : %d",  requests[i].request->state);
                i++;
        }
 
@@ -237,10 +317,6 @@ int dp_db_crashed_list(dp_request_slots *requests, int limit)
                                requests[i].request->packagename[buffer_length] = '\0';
                        }
                }
-
-               TRACE_INFO("ID : %d",  requests[i].request->id);
-               TRACE_INFO("state : %d",  requests[i].request->state);
-               TRACE_INFO("packagename : %s",  requests[i].request->packagename);
                i++;
        }
 
@@ -469,8 +545,6 @@ static sqlite3_stmt *__prepare_query(sqlite3 *handle,
                return NULL;
        }
 
-       TRACE_INFO("[QUERY] %s", query);
-
        ret = sqlite3_prepare_v2(handle, query, -1, &stmt, NULL);
        sqlite3_free(query);
        if ( ret != SQLITE_OK) {
@@ -557,6 +631,64 @@ int dp_db_insert_column(int id, char *table, char *column,
        return -1;
 }
 
+int dp_db_insert_blob_column(int id, char *table, char *column,
+                                               void *value, unsigned length)
+{
+       sqlite3_stmt *stmt = NULL;
+
+       if (id <= 0) {
+               TRACE_ERROR("[CHECK ID]");
+               return -1;
+       }
+
+       if (!table) {
+               TRACE_ERROR("[CHECK TABLE NAME]");
+               return -1;
+       }
+
+       if (!column) {
+               TRACE_ERROR("[CHECK COLUMN NAME]");
+               return -1;
+       }
+
+       if (__dp_sql_open() < 0) {
+               TRACE_ERROR("[OPEN] [%s]", sqlite3_errmsg(g_dp_db_handle));
+               return -1;
+       }
+
+       stmt = __prepare_query
+                       (g_dp_db_handle, DP_DB_QUERY_TYPE_INSERT, table, column);
+       if (stmt == NULL) {
+               TRACE_ERROR("[PREPARE] [%s]", sqlite3_errmsg(g_dp_db_handle));
+               return -1;
+       }
+
+       int errorcode = SQLITE_OK;
+       errorcode = sqlite3_bind_blob(stmt, 2, value, (int)length, NULL);
+
+       if (errorcode != SQLITE_OK) {
+               TRACE_ERROR("[BIND] [%s]", sqlite3_errmsg(g_dp_db_handle));
+               __dp_finalize(stmt);
+               return -1;
+       }
+
+       // VALUES ( id )
+       if (sqlite3_bind_int(stmt, 1, id) != SQLITE_OK) {
+               TRACE_ERROR("[BIND] [%s]", sqlite3_errmsg(g_dp_db_handle));
+               __dp_finalize(stmt);
+               return -1;
+       }
+
+       errorcode = sqlite3_step(stmt);
+       if (errorcode == SQLITE_OK || errorcode == SQLITE_DONE) {
+               __dp_finalize(stmt);
+               return 0;
+       }
+       TRACE_ERROR("[SQL] [%s]", sqlite3_errmsg(g_dp_db_handle));
+       __dp_finalize(stmt);
+       return -1;
+}
+
 int dp_db_set_column(int id, char *table, char *column,
                                                db_column_data_type datatype, void *value)
 {
@@ -633,6 +765,64 @@ int dp_db_set_column(int id, char *table, char *column,
        return -1;
 }
 
+int dp_db_set_blob_column(int id, char *table, char *column,
+                                               void *value, unsigned length)
+{
+       sqlite3_stmt *stmt = NULL;
+
+       if (id <= 0) {
+               TRACE_ERROR("[CHECK ID]");
+               return -1;
+       }
+
+       if (!table) {
+               TRACE_ERROR("[CHECK TABLE NAME]");
+               return -1;
+       }
+
+       if (!column) {
+               TRACE_ERROR("[CHECK COLUMN NAME]");
+               return -1;
+       }
+
+       if (__dp_sql_open() < 0) {
+               TRACE_ERROR("[OPEN] [%s]", sqlite3_errmsg(g_dp_db_handle));
+               return -1;
+       }
+
+       stmt = __prepare_query
+                       (g_dp_db_handle, DP_DB_QUERY_TYPE_SET, table, column);
+       if (stmt == NULL) {
+               TRACE_ERROR("[PREPARE] [%s]", sqlite3_errmsg(g_dp_db_handle));
+               return -1;
+       }
+
+       int errorcode = SQLITE_OK;
+       errorcode = sqlite3_bind_blob(stmt, 1, value, (int)length, NULL);
+
+       if (errorcode != SQLITE_OK) {
+               TRACE_ERROR("[BIND] [%s]", sqlite3_errmsg(g_dp_db_handle));
+               __dp_finalize(stmt);
+               return -1;
+       }
+
+       // WHERE id = ?
+       if (sqlite3_bind_int(stmt, 2, id) != SQLITE_OK) {
+               TRACE_ERROR("[BIND] [%s]", sqlite3_errmsg(g_dp_db_handle));
+               __dp_finalize(stmt);
+               return -1;
+       }
+
+       errorcode = sqlite3_step(stmt);
+       if (errorcode == SQLITE_OK || errorcode == SQLITE_DONE) {
+               __dp_finalize(stmt);
+               return 0;
+       }
+       TRACE_ERROR("[SQL] [%s]", sqlite3_errmsg(g_dp_db_handle));
+       __dp_finalize(stmt);
+       return -1;
+}
+
 int dp_db_replace_column(int id, char *table, char *column,
                                                db_column_data_type datatype, void *value)
 {
@@ -658,6 +848,30 @@ int dp_db_replace_column(int id, char *table, char *column,
        return dp_db_set_column(id, table, column, datatype, value);
 }
 
+int dp_db_replace_blob_column(int id, char *table, char *column1,
+                                               void *value, unsigned length)
+{
+       if (id <= 0) {
+               TRACE_ERROR("[CHECK ID]");
+               return -1;
+       }
+       if (!table) {
+               TRACE_ERROR("[CHECK TABLE NAME]");
+               return -1;
+       }
+       if (!column1) {
+               TRACE_ERROR("[CHECK COLUMN NAME]");
+               return -1;
+       }
+       int check_id = dp_db_get_int_column(id, table, DP_DB_COL_ID);
+       if (check_id != id) // INSERT
+       {
+               return dp_db_insert_blob_column(id, table, column1, value, length);
+       }
+       // UPDATE
+       return dp_db_set_blob_column(id, table, column1, value, length);
+}
+
 // success : 0
 // error   : -1
 char *dp_db_get_text_column(int id, char *table, char *column)
@@ -710,11 +924,76 @@ char *dp_db_get_text_column(int id, char *table, char *column)
                __dp_finalize(stmt);
                return columntext;
        }
-       TRACE_INFO("[No DATA]");
        __dp_finalize(stmt);
        return NULL;
 }
 
+// success : 0
+// error   : -1
+void *dp_db_get_blob_column(int id, char *table, char *column, int *length)
+{
+       sqlite3_stmt *stmt = NULL;
+
+       if (id <= 0) {
+               TRACE_ERROR("[CHECK ID]");
+               return NULL;
+       }
+
+       if (!table) {
+               TRACE_ERROR("[CHECK TABLE NAME]");
+               return NULL;
+       }
+
+       if (!column) {
+               TRACE_ERROR("[CHECK COLUMN NAME]");
+               return NULL;
+       }
+
+       if (__dp_sql_open() < 0) {
+               TRACE_ERROR("[OPEN] [%s]", sqlite3_errmsg(g_dp_db_handle));
+               return NULL;
+       }
+
+       stmt = __prepare_query
+                       (g_dp_db_handle, DP_DB_QUERY_TYPE_GET, table, column);
+       if (stmt == NULL) {
+               TRACE_ERROR("[PREPARE] [%s]", sqlite3_errmsg(g_dp_db_handle));
+               return NULL;
+       }
+
+       // WHERE id = ?
+       if (sqlite3_bind_int(stmt, 1, id) != SQLITE_OK) {
+               TRACE_ERROR("[BIND] [%s]", sqlite3_errmsg(g_dp_db_handle));
+               __dp_finalize(stmt);
+               return NULL;
+       }
+
+       if (sqlite3_step(stmt) == SQLITE_ROW) {
+               int blob_length = 0;
+               void *blob_data = NULL;
+               blob_length = sqlite3_column_bytes(stmt, 0);
+               if(blob_length > 0){
+                       blob_data = (void*)calloc(blob_length, sizeof(unsigned char));
+                       if(blob_data != NULL){
+                               memcpy(blob_data, sqlite3_column_blob(stmt, 0),
+                                       sizeof(unsigned char)*blob_length);
+                       } else {
+                               TRACE_ERROR("[MEM] allocating");
+                               blob_length = -1;
+                       }
+               } else {
+                       TRACE_ERROR("NO DATA");
+                       blob_length = -1;
+               }
+               __dp_finalize(stmt);
+               *length = blob_length;
+               return blob_data;
+       }
+       __dp_finalize(stmt);
+       return NULL;
+}
+
+
 int dp_db_get_int_column(int id, char *table, char *column)
 {
        sqlite3_stmt *stmt = NULL;
@@ -758,7 +1037,6 @@ int dp_db_get_int_column(int id, char *table, char *column)
                __dp_finalize(stmt);
                return columnvalue;
        }
-       TRACE_INFO("[No DATA]");
        __dp_finalize(stmt);
        return -1;
 }
@@ -806,7 +1084,6 @@ long long dp_db_get_int64_column(int id, char *table, char *column)
                __dp_finalize(stmt);
                return columnvalue;
        }
-       TRACE_INFO("[No DATA]");
        __dp_finalize(stmt);
        return -1;
 }
@@ -878,8 +1155,6 @@ static sqlite3_stmt *__prepare_cond_query(sqlite3 *handle,
                return NULL;
        }
 
-       TRACE_INFO("[QUERY] %s", query);
-
        ret = sqlite3_prepare_v2(handle, query, -1, &stmt, NULL);
        sqlite3_free(query);
        if ( ret != SQLITE_OK) {
@@ -1118,8 +1393,6 @@ int dp_db_cond_remove(int id, char *table,
                return -1;
        }
 
-       TRACE_INFO("[QUERY] %s", query);
-
        ret = sqlite3_prepare_v2(g_dp_db_handle, query, -1, &stmt, NULL);
        sqlite3_free(query);
        if ( ret != SQLITE_OK) {
@@ -1170,13 +1443,167 @@ int dp_db_cond_remove(int id, char *table,
        return -1;
 }
 
-int dp_db_get_cond_rows_count(int id, char *table,
-                                               char *condcolumn, db_column_data_type condtype,
-                                               void *condvalue)
+static int __dp_sql_bind_value(sqlite3_stmt *stmt,
+                               db_column_data_type condtype,  void *value, int index)
 {
-       int errorcode = SQLITE_OK;
-       int ret = -1;
-       sqlite3_stmt *stmt = NULL;
+       int errorcode = SQLITE_ERROR;
+       int *cast_value = 0;
+
+       if (stmt == NULL)
+               return SQLITE_ERROR;
+
+       switch (condtype) {
+       case DP_DB_COL_TYPE_INT:
+               cast_value = value;
+               errorcode = sqlite3_bind_int(stmt, index, *cast_value);
+               break;
+       case DP_DB_COL_TYPE_INT64:
+#ifdef SQLITE_INT64_TYPE
+               sqlite3_int64 *cast_value = value;
+               errorcode = sqlite3_bind_int64(stmt, index, *cast_value);
+#else
+               cast_value = value;
+               errorcode = sqlite3_bind_int(stmt, index, *cast_value);
+#endif
+               break;
+       case DP_DB_COL_TYPE_TEXT:
+               errorcode =
+                       sqlite3_bind_text(stmt, index, (char *)value, -1, SQLITE_STATIC);
+               break;
+       default:
+               errorcode = SQLITE_ERROR;
+               break;
+       }
+       return errorcode;
+}
+
+char *dp_db_cond_get_text(char *table, char *column, char *condcolumn,
+                                               db_column_data_type condtype, void *condvalue)
+{
+       sqlite3_stmt *stmt = NULL;
+       char *query = NULL;
+       int ret = -1;
+
+       if (table == NULL) {
+               TRACE_ERROR("[CHECK TABLE NAME]");
+               return NULL;
+       }
+
+       if (column == NULL) {
+               TRACE_ERROR("[CHECK COLUMN NAME]");
+               return NULL;
+       }
+       if (condcolumn == NULL) {
+               TRACE_ERROR("[CHECK Condition]");
+               return NULL;
+       }
+
+       if (__dp_sql_open() < 0) {
+               TRACE_ERROR("__dp_sql_open[%s]", sqlite3_errmsg(g_dp_db_handle));
+               return NULL;
+       }
+
+       query = sqlite3_mprintf("SELECT %s FROM %s WHERE %s IS ?",
+                       column, table, condcolumn);
+       if (query == NULL) {
+               TRACE_ERROR("[CHECK COMBINE]");
+               return NULL;
+       }
+       ret = sqlite3_prepare_v2(g_dp_db_handle, query, -1, &stmt, NULL);
+       sqlite3_free(query);
+       if ( ret != SQLITE_OK) {
+               TRACE_ERROR("[PREPARE] [%s]", sqlite3_errmsg(g_dp_db_handle));
+               __dp_finalize(stmt);
+               return NULL;
+       }
+
+       if (__dp_sql_bind_value(stmt, condtype, condvalue, 1) != SQLITE_OK) {
+               TRACE_ERROR
+                       ("[BIND][%d][%s]", condtype, sqlite3_errmsg(g_dp_db_handle));
+               __dp_finalize(stmt);
+               return NULL;
+       }
+       if (sqlite3_step(stmt) == SQLITE_ROW &&
+                       sqlite3_column_type(stmt, 0) == SQLITE_TEXT) {
+               int getbytes = sqlite3_column_bytes(stmt, 0);
+               if (getbytes > 0) {
+                       char *getstr = (char *)calloc(getbytes + 1, sizeof(char));
+                       if (getstr != NULL) {
+                               memcpy(getstr, sqlite3_column_text(stmt, 0),
+                                       getbytes * sizeof(char));
+                               getstr[getbytes] = '\0';
+                       }
+                       __dp_finalize(stmt);
+                       return getstr;
+               }
+       }
+       __dp_finalize(stmt);
+       return NULL;
+}
+
+int dp_db_cond_get_int(char *table, char *column, char *condcolumn,
+                                               db_column_data_type condtype, void *condvalue)
+{
+       sqlite3_stmt *stmt = NULL;
+       char *query = NULL;
+       int ret = -1;
+
+       if (table == NULL) {
+               TRACE_ERROR("[CHECK TABLE NAME]");
+               return -1;
+       }
+
+       if (column == NULL) {
+               TRACE_ERROR("[CHECK COLUMN NAME]");
+               return -1;
+       }
+       if (condcolumn == NULL) {
+               TRACE_ERROR("[CHECK Condition]");
+               return -1;
+       }
+
+       if (__dp_sql_open() < 0) {
+               TRACE_ERROR("__dp_sql_open[%s]", sqlite3_errmsg(g_dp_db_handle));
+               return -1;
+       }
+
+       query = sqlite3_mprintf("SELECT %s FROM %s WHERE %s IS ?",
+                       column, table, condcolumn);
+       if (query == NULL) {
+               TRACE_ERROR("[CHECK COMBINE]");
+               return -1;
+       }
+       ret = sqlite3_prepare_v2(g_dp_db_handle, query, -1, &stmt, NULL);
+       sqlite3_free(query);
+       if ( ret != SQLITE_OK) {
+               TRACE_ERROR("[PREPARE] [%s]", sqlite3_errmsg(g_dp_db_handle));
+               __dp_finalize(stmt);
+               return -1;
+       }
+
+       if (__dp_sql_bind_value(stmt, condtype, condvalue, 1) != SQLITE_OK) {
+               TRACE_ERROR
+                       ("[BIND][%d][%s]", condtype, sqlite3_errmsg(g_dp_db_handle));
+               __dp_finalize(stmt);
+               return -1;
+       }
+       if (sqlite3_step(stmt) == SQLITE_ROW &&
+                       sqlite3_column_type(stmt, 0) == SQLITE_INTEGER) {
+               int columnvalue = sqlite3_column_int(stmt, 0);
+               __dp_finalize(stmt);
+               return columnvalue;
+       }
+       __dp_finalize(stmt);
+       return -1;
+}
+
+int dp_db_get_cond_rows_count(int id, char *table,
+                                               char *condcolumn, db_column_data_type condtype,
+                                               void *condvalue)
+{
+       int errorcode = SQLITE_OK;
+       int ret = -1;
+       sqlite3_stmt *stmt = NULL;
        char *query = NULL;
 
        if (id <= 0) {
@@ -1210,11 +1637,9 @@ int dp_db_get_cond_rows_count(int id, char *table,
                return -1;
        }
 
-       TRACE_INFO("[QUERY] %s", query);
-
        ret = sqlite3_prepare_v2(g_dp_db_handle, query, -1, &stmt, NULL);
        sqlite3_free(query);
-       if ( ret != SQLITE_OK) {
+       if (ret != SQLITE_OK) {
                TRACE_ERROR("[PREPARE] [%s]", sqlite3_errmsg(g_dp_db_handle));
                __dp_finalize(stmt);
                return -1;
@@ -1386,17 +1811,14 @@ static int __bind_value(sqlite3_stmt *stmt,
        case DP_DB_COL_TYPE_INT:
                cast_value = value;
                errorcode = sqlite3_bind_int(stmt, index, *cast_value);
-               TRACE_INFO("INT %d", *cast_value);
                break;
        case DP_DB_COL_TYPE_INT64:
 #ifdef SQLITE_INT64_TYPE
                sqlite3_int64 *cast_value = value;
                errorcode = sqlite3_bind_int64(stmt, index, *cast_value);
-               TRACE_INFO("INT %ld", *cast_value);
 #else
                cast_value = value;
                errorcode = sqlite3_bind_int(stmt, index, *cast_value);
-               TRACE_INFO("INT %d", *cast_value);
 #endif
                break;
        case DP_DB_COL_TYPE_TEXT:
@@ -1451,8 +1873,77 @@ int dp_db_insert_columns(char *table, int column_count,
                TRACE_ERROR("[CHECK COMBINE]");
                return -1;
        }
+       TRACE_DEBUG("query:%s", query);
+
+       ret = sqlite3_prepare_v2(g_dp_db_handle, query, -1, &stmt, NULL);
+       sqlite3_free(query);
+       if ( ret != SQLITE_OK) {
+               TRACE_ERROR("[PREPARE] [%s]", sqlite3_errmsg(g_dp_db_handle));
+               __dp_finalize(stmt);
+               return -1;
+       }
+
+       for (i = 0; i < column_count; i++) {
+               if (__bind_value
+                               (stmt, columns[i].type, columns[i].value, (i + 1)) !=
+                               SQLITE_OK) {
+                       TRACE_ERROR("[BIND][%d][%s]", columns[i].type,
+                               sqlite3_errmsg(g_dp_db_handle));
+                       __dp_finalize(stmt);
+                       return -1;
+               }
+       }
+
+       errorcode = sqlite3_step(stmt);
+       if (errorcode == SQLITE_OK || errorcode == SQLITE_DONE) {
+               __dp_finalize(stmt);
+               return 0;
+       }
+       TRACE_ERROR("[SQL] [%s]", sqlite3_errmsg(g_dp_db_handle));
+       __dp_finalize(stmt);
+       return -1;
+}
+
+int dp_db_update_columns(int id, char *table, int column_count,
+                                               db_conds_list_fmt *columns)
+{
+       int errorcode = SQLITE_OK;
+       int ret = -1;
+       sqlite3_stmt *stmt = NULL;
+       char *query = NULL;
+       int i = 0;
+
+       if (id <= 0) {
+               TRACE_ERROR("[CHECK ID]");
+               return -1;
+       }
+       if (table == NULL) {
+               TRACE_ERROR("[CHECK TABLE NAME]");
+               return -1;
+       }
+       if (column_count <= 0) {
+               TRACE_ERROR("[CHECK db_conds_list_fmt count]");
+               return -1;
+       }
+       if (__dp_sql_open() < 0) {
+               TRACE_ERROR("[SQL HANDLE] [%s]", sqlite3_errmsg(g_dp_db_handle));
+               return -1;
+       }
 
-       TRACE_INFO("[QUERY] %s", query);
+       query =
+               sqlite3_mprintf("UPDATE %s SET %s = ?", table, columns[0].column);
+       for (i = 1; i < column_count; i++) {
+               char *column_query = NULL;
+               column_query = sqlite3_mprintf("%s = ?", columns[i].column);
+               query = __merge_strings(query, column_query, ',');
+               sqlite3_free(column_query);
+       }
+       query = __merge_strings(query, "WHERE id = ?", ' ');
+       if (query == NULL) {
+               TRACE_ERROR("[CHECK COMBINE]");
+               return -1;
+       }
+       TRACE_DEBUG("query:%s", query);
 
        ret = sqlite3_prepare_v2(g_dp_db_handle, query, -1, &stmt, NULL);
        sqlite3_free(query);
@@ -1472,6 +1963,11 @@ int dp_db_insert_columns(char *table, int column_count,
                        return -1;
                }
        }
+       if (sqlite3_bind_int(stmt, column_count + 1, id) != SQLITE_OK) {
+               TRACE_ERROR("[BIND] ID [%s]", sqlite3_errmsg(g_dp_db_handle));
+               __dp_finalize(stmt);
+               return -1;
+       }
 
        errorcode = sqlite3_step(stmt);
        if (errorcode == SQLITE_OK || errorcode == SQLITE_DONE) {
@@ -1528,8 +2024,6 @@ int dp_db_get_conds_rows_count(char *table,
                return -1;
        }
 
-       TRACE_INFO("[QUERY] %s", query);
-
        ret = sqlite3_prepare_v2(g_dp_db_handle, query, -1, &stmt, NULL);
        sqlite3_free(query);
        if (ret != SQLITE_OK) {
@@ -1626,7 +2120,6 @@ int dp_db_get_conds_list(char *table, char *getcolumn,
                TRACE_ERROR("[CHECK COMBINE]");
                return -1;
        }
-       TRACE_INFO("[QUERY] %s", query);
 
        errorcode =
                sqlite3_prepare_v2(g_dp_db_handle, query, -1, &stmt, NULL);
@@ -1691,3 +2184,166 @@ int dp_db_get_conds_list(char *table, char *getcolumn,
        return rows_count;
 }
 
+static void __dp_db_reset(sqlite3_stmt *stmt)
+{
+       if (stmt != 0) {
+               sqlite3_clear_bindings(stmt);
+               if (sqlite3_reset(stmt) != SQLITE_OK) {
+                       sqlite3 *handle = sqlite3_db_handle(stmt);
+                       TRACE_ERROR("failed sqlite3_reset [%s]",
+                               sqlite3_errmsg(handle));
+               }
+       }
+}
+
+int dp_db_request_new_logging(const int id, const int state, const char *pkgname)
+{
+       int errorcode = SQLITE_OK;
+       int ret = -1;
+       char *query = NULL;
+
+       if (__dp_sql_open() < 0) {
+               TRACE_ERROR("[SQL HANDLE] [%s]", sqlite3_errmsg(g_dp_db_handle));
+               return -1;
+       }
+
+       if (g_dp_db_logging_new_stmt == NULL) {
+               query =
+                       sqlite3_mprintf("INSERT INTO %s (%s, %s, %s, %s) VALUES (?, ?, ?, DATETIME('now'))",
+                               DP_DB_TABLE_LOG, DP_DB_COL_ID, DP_DB_COL_STATE,
+                               DP_DB_COL_PACKAGENAME, DP_DB_COL_CREATE_TIME);
+               if (query == NULL) {
+                       TRACE_ERROR("[CHECK COMBINE]");
+                       return -1;
+               }
+
+               TRACE_DEBUG("query:%s", query);
+
+               ret = sqlite3_prepare_v2(g_dp_db_handle, query, -1, &g_dp_db_logging_new_stmt, NULL);
+               sqlite3_free(query);
+               if (ret != SQLITE_OK) {
+                       TRACE_ERROR("[PREPARE] [%s]", sqlite3_errmsg(g_dp_db_handle));
+                       return -1;
+               }
+       }
+       if (sqlite3_bind_int(g_dp_db_logging_new_stmt, 1, id) != SQLITE_OK) {
+               TRACE_ERROR("[BIND] [%s]", sqlite3_errmsg(g_dp_db_handle));
+               __dp_db_reset(g_dp_db_logging_new_stmt);
+               return -1;
+       }
+       if (sqlite3_bind_int(g_dp_db_logging_new_stmt, 2, state) != SQLITE_OK) {
+               TRACE_ERROR("[BIND] [%s]", sqlite3_errmsg(g_dp_db_handle));
+               __dp_db_reset(g_dp_db_logging_new_stmt);
+               return -1;
+       }
+       if (sqlite3_bind_text(g_dp_db_logging_new_stmt, 3, pkgname, -1, SQLITE_STATIC) != SQLITE_OK) {
+               TRACE_ERROR("[BIND] [%s]", sqlite3_errmsg(g_dp_db_handle));
+               __dp_db_reset(g_dp_db_logging_new_stmt);
+               return -1;
+       }
+
+       errorcode = sqlite3_step(g_dp_db_logging_new_stmt);
+       __dp_db_reset(g_dp_db_logging_new_stmt);
+       if (errorcode == SQLITE_OK || errorcode == SQLITE_DONE) {
+               return 0;
+       }
+       return -1;
+}
+
+int dp_db_request_update_status(const int id, const int state, const int download_error)
+{
+       int errorcode = SQLITE_OK;
+       int ret = -1;
+       char *query = NULL;
+
+       if (__dp_sql_open() < 0) {
+               TRACE_ERROR("[SQL HANDLE] [%s]", sqlite3_errmsg(g_dp_db_handle));
+               return -1;
+       }
+
+       if (g_dp_db_logging_status_stmt == NULL) {
+               query =
+                       sqlite3_mprintf("UPDATE %s SET %s = ?, %s = ?, %s = DATETIME('now') WHERE %s = ?",
+                               DP_DB_TABLE_LOG, DP_DB_COL_STATE, DP_DB_COL_ERRORCODE,
+                               DP_DB_COL_ACCESS_TIME, DP_DB_COL_ID);
+               if (query == NULL) {
+                       TRACE_ERROR("[CHECK COMBINE]");
+                       return -1;
+               }
+
+               TRACE_DEBUG("query:%s", query);
+
+               ret = sqlite3_prepare_v2(g_dp_db_handle, query, -1, &g_dp_db_logging_status_stmt, NULL);
+               sqlite3_free(query);
+               if (ret != SQLITE_OK) {
+                       TRACE_ERROR("[PREPARE] [%s]", sqlite3_errmsg(g_dp_db_handle));
+                       return -1;
+               }
+       }
+       if (sqlite3_bind_int(g_dp_db_logging_status_stmt, 1, state) != SQLITE_OK) {
+               TRACE_ERROR("[BIND] [%s]", sqlite3_errmsg(g_dp_db_handle));
+               __dp_db_reset(g_dp_db_logging_status_stmt);
+               return -1;
+       }
+       if (sqlite3_bind_int(g_dp_db_logging_status_stmt, 2, download_error) != SQLITE_OK) {
+               TRACE_ERROR("[BIND] [%s]", sqlite3_errmsg(g_dp_db_handle));
+               __dp_db_reset(g_dp_db_logging_status_stmt);
+               return -1;
+       }
+       if (sqlite3_bind_int(g_dp_db_logging_status_stmt, 3, id) != SQLITE_OK) {
+               TRACE_ERROR("[BIND] [%s]", sqlite3_errmsg(g_dp_db_handle));
+               __dp_db_reset(g_dp_db_logging_status_stmt);
+               return -1;
+       }
+
+       errorcode = sqlite3_step(g_dp_db_logging_status_stmt);
+       __dp_db_reset(g_dp_db_logging_status_stmt);
+       if (errorcode == SQLITE_OK || errorcode == SQLITE_DONE) {
+               return 0;
+       }
+       return -1;
+}
+
+int dp_db_get_state(int id)
+{
+       if (id <= 0) {
+               TRACE_ERROR("[CHECK ID]");
+               return -1;
+       }
+
+       if (__dp_sql_open() < 0) {
+               TRACE_ERROR("[OPEN] [%s]", sqlite3_errmsg(g_dp_db_handle));
+               return -1;
+       }
+
+       if (g_dp_db_logging_get_state_stmt == NULL) {
+               char *query = sqlite3_mprintf("SELECT %s FROM %s WHERE %s = ?",
+                               DP_DB_COL_STATE, DP_DB_TABLE_LOG, DP_DB_COL_ID);
+               if (query == NULL) {
+                       TRACE_ERROR("[CHECK COMBINE]");
+                       return -1;
+               }
+
+               TRACE_DEBUG("query:%s", query);
+
+               int ret = sqlite3_prepare_v2(g_dp_db_handle, query, -1, &g_dp_db_logging_get_state_stmt, NULL);
+               sqlite3_free(query);
+               if (ret != SQLITE_OK) {
+                       TRACE_ERROR("[PREPARE] [%s]", sqlite3_errmsg(g_dp_db_handle));
+                       return -1;
+               }
+       }
+
+       if (sqlite3_bind_int(g_dp_db_logging_get_state_stmt, 1, id) != SQLITE_OK) {
+               TRACE_ERROR("[BIND] [%s]", sqlite3_errmsg(g_dp_db_handle));
+               __dp_db_reset(g_dp_db_logging_get_state_stmt);
+               return -1;
+       }
+
+       int state = DP_STATE_NONE;
+       if (sqlite3_step(g_dp_db_logging_get_state_stmt) == SQLITE_ROW) {
+               state = sqlite3_column_int(g_dp_db_logging_get_state_stmt, 0);
+       }
+       __dp_db_reset(g_dp_db_logging_get_state_stmt);
+       return state;
+}
index 630f0c7..6e71cb5 100755 (executable)
 #include <glib.h>
 #include <glib-object.h>
 #include <pthread.h>
+#include <locale.h>
+#include <libintl.h>
+#include <systemd/sd-daemon.h>
 
-#ifdef DP_SUPPORT_DBUS_ACTIVATION
-#include <dbus/dbus.h>
-#endif
+#include "vconf.h"
 
 #include "download-provider-config.h"
 #include "download-provider-log.h"
@@ -45,48 +46,15 @@ static pthread_t g_dp_thread_queue_manager_pid = 0;
 // need for libsoup, decided the life-time by mainloop.
 GMainLoop *g_main_loop_handle = 0;
 
-#ifdef DP_SUPPORT_DBUS_ACTIVATION
-static int __register_dbus_service(void)
-{
-       DBusError dbus_error;
-       DBusConnection *dp_dbus_connection = NULL;
-
-       dbus_error_init(&dbus_error);
-
-       dp_dbus_connection = dbus_bus_get(DBUS_BUS_SYSTEM, &dbus_error);
-       if (dp_dbus_connection == NULL) {
-               TRACE_ERROR("[DBUS] dbus_bus_get: %s", dbus_error.message);
-               dbus_error_free(&dbus_error);
-               return -1;
-       }
-
-       if (dbus_bus_request_name
-                       (dp_dbus_connection, DP_DBUS_SERVICE_DBUS, 0, &dbus_error) < 0 ||
-                       dbus_error_is_set(&dbus_error)) {
-               TRACE_ERROR("[DBUS] request_name %s", dbus_error.message);
-               dbus_error_free(&dbus_error);
-               dbus_connection_unref(dp_dbus_connection);
-               dp_dbus_connection = NULL;
-               return -1;
-       }
-       dbus_connection_unref(dp_dbus_connection);
-       dp_dbus_connection = NULL;
-       return 0;
-}
-
-#endif
-
 void dp_terminate(int signo)
 {
-       TRACE_INFO("Received SIGTERM");
+       TRACE_DEBUG("Received SIGTERM:%d", signo);
        if (g_main_loop_is_running(g_main_loop_handle))
                g_main_loop_quit(g_main_loop_handle);
 }
 
 static gboolean __dp_idle_start_service(void *data)
 {
-       TRACE_INFO("Launch threads .....");
-
        // declare all resources
        pthread_t thread_pid;
        pthread_attr_t thread_attr;
@@ -124,6 +92,22 @@ static gboolean __dp_idle_start_service(void *data)
        return FALSE;
 }
 
+void __set_locale()
+{
+       char *str = NULL;
+       str = vconf_get_str(VCONFKEY_LANGSET);
+       if (str != NULL) {
+               setlocale(LC_ALL, str);
+               bindtextdomain(PKG_NAME, LOCALE_DIR);
+               textdomain(PKG_NAME);
+       }
+       free(str);
+}
+void __lang_changed_cb(keynode_t *key, void* data)
+{
+       __set_locale();
+}
+
 int main(int argc, char **argv)
 {
        dp_privates *privates = NULL;
@@ -149,6 +133,10 @@ int main(int argc, char **argv)
                TRACE_ERROR("failed to register signal callback");
                exit(EXIT_FAILURE);
        }
+       if (signal(SIGINT, dp_terminate) == SIG_ERR) {
+               TRACE_ERROR("failed to register signal callback");
+               exit(EXIT_FAILURE);
+       }
        // write IPC_FD_PATH. and lock
        if ((lock_fd = dp_lock_pid(DP_LOCK_PID)) < 0) {
                TRACE_ERROR
@@ -157,13 +145,14 @@ int main(int argc, char **argv)
                                DP_LOCK_PID);
                exit(EXIT_FAILURE);
        }
-       // if exit socket file, delete it
-       if (access(DP_IPC, F_OK) == 0) {
-               unlink(DP_IPC);
-       }
 
        g_type_init();
 
+       // locale
+       __set_locale();
+       if (vconf_notify_key_changed(VCONFKEY_LANGSET, __lang_changed_cb, NULL) != 0)
+               TRACE_ERROR("Fail to set language changed vconf callback");
+
        privates = (dp_privates *) calloc(1, sizeof(dp_privates));
        if (!privates) {
                TRACE_ERROR("[CRITICAL] failed to alloc for private info");
@@ -187,16 +176,6 @@ int main(int argc, char **argv)
                goto DOWNLOAD_EXIT;
        }
 
-#ifdef DP_SUPPORT_DBUS_ACTIVATION
-       TRACE_INFO("SUPPORT DBUS-ACTIVATION");
-       if (__register_dbus_service() < 0) {
-               TRACE_ERROR("[LAUNCH ERROR] __register_dbus_service");
-               goto DOWNLOAD_EXIT;
-       }
-#else
-       TRACE_INFO("Not SUPPORT DBUS-ACTIVATION");
-#endif
-
        dp_db_open();
 
        // convert to request type, insert all to privates->requests
@@ -208,7 +187,7 @@ int main(int argc, char **argv)
                        if (!privates->requests[i].request)
                                continue;
                        dp_request *request = privates->requests[i].request;
-                       TRACE_INFO
+                       TRACE_DEBUG
                                ("ID [%d] state[%d]", request->id, request->state);
 
                        // load to memory, Can be started automatically.
@@ -256,13 +235,15 @@ int main(int argc, char **argv)
                }
        } // query crashed_list
 
+#if 0
        if (argc != 2 || memcmp(argv[1], "service", 7) != 0) {
                // in first launch in booting time, not request. terminate by self
                if (dp_get_request_count(privates->requests) <= 0) {
-                       TRACE_INFO("First Boot, No Request");
+                       TRACE_DEBUG("First Boot, No Request");
                        goto DOWNLOAD_EXIT;
                }
        }
+#endif
 
        dp_clear_downloadinginfo_notification();
 
@@ -274,7 +255,7 @@ int main(int argc, char **argv)
        privates->connection = 0;
        privates->network_status = DP_NETWORK_TYPE_OFF;
        if (dp_network_connection_init(privates) < 0) {
-               TRACE_INFO("use instant network check");
+               TRACE_DEBUG("use instant network check");
                privates->connection = 0;
        }
 
@@ -283,11 +264,15 @@ int main(int argc, char **argv)
 
        g_idle_add(__dp_idle_start_service, privates);
 
+       sd_notify(0, "READY=1");
+
        g_main_loop_run(g_main_loop_handle);
 
 DOWNLOAD_EXIT :
 
-       TRACE_INFO("Download-Provider will be terminated.");
+       TRACE_DEBUG("Download-Provider will be terminated.");
+       if (vconf_ignore_key_changed(VCONFKEY_LANGSET, __lang_changed_cb) != 0)
+               TRACE_ERROR("Fail to unset language changed vconf callback");
 
        dp_deinit_agent();
 
@@ -296,10 +281,9 @@ DOWNLOAD_EXIT :
                if (privates->connection)
                        dp_network_connection_destroy(privates->connection);
 
-               if (privates->listen_fd >= 0) {
-                       dp_socket_free(privates->listen_fd);
+               if (privates->listen_fd >= 0)
                        privates->listen_fd = -1;
-               }
+
                if (g_dp_thread_queue_manager_pid > 0 &&
                                pthread_kill(g_dp_thread_queue_manager_pid, 0) != ESRCH) {
                        //pthread_cancel(g_dp_thread_queue_manager_pid);
@@ -318,10 +302,6 @@ DOWNLOAD_EXIT :
        }
        dp_db_close();
 
-       // if exit socket file, delete it
-       if (access(DP_IPC, F_OK) == 0) {
-               unlink(DP_IPC);
-       }
        // delete pid file
        if (access(DP_LOCK_PID, F_OK) == 0) {
                close(lock_fd);
index 1c5bcf5..ac3fc5b 100755 (executable)
@@ -80,46 +80,46 @@ static void __print_connection_errorcode_to_string(connection_error_e errorcode)
        switch(errorcode)
        {
                case CONNECTION_ERROR_INVALID_PARAMETER :
-                       TRACE_INFO("CONNECTION_ERROR_INVALID_PARAMETER");
+                       TRACE_DEBUG("CONNECTION_ERROR_INVALID_PARAMETER");
                        break;
                case CONNECTION_ERROR_OUT_OF_MEMORY :
-                       TRACE_INFO("CONNECTION_ERROR_OUT_OF_MEMORY");
+                       TRACE_DEBUG("CONNECTION_ERROR_OUT_OF_MEMORY");
                        break;
                case CONNECTION_ERROR_INVALID_OPERATION :
-                       TRACE_INFO("CONNECTION_ERROR_INVALID_OPERATION");
+                       TRACE_DEBUG("CONNECTION_ERROR_INVALID_OPERATION");
                        break;
                case CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED :
-                       TRACE_INFO("CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED");
+                       TRACE_DEBUG("CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED");
                        break;
                case CONNECTION_ERROR_OPERATION_FAILED :
-                       TRACE_INFO("CONNECTION_ERROR_OPERATION_FAILED");
+                       TRACE_DEBUG("CONNECTION_ERROR_OPERATION_FAILED");
                        break;
                case CONNECTION_ERROR_ITERATOR_END :
-                       TRACE_INFO("CONNECTION_ERROR_ITERATOR_END");
+                       TRACE_DEBUG("CONNECTION_ERROR_ITERATOR_END");
                        break;
                case CONNECTION_ERROR_NO_CONNECTION :
-                       TRACE_INFO("CONNECTION_ERROR_NO_CONNECTION");
+                       TRACE_DEBUG("CONNECTION_ERROR_NO_CONNECTION");
                        break;
                case CONNECTION_ERROR_NOW_IN_PROGRESS :
-                       TRACE_INFO("CONNECTION_ERROR_NOW_IN_PROGRESS");
+                       TRACE_DEBUG("CONNECTION_ERROR_NOW_IN_PROGRESS");
                        break;
                case CONNECTION_ERROR_ALREADY_EXISTS :
-                       TRACE_INFO("CONNECTION_ERROR_ALREADY_EXISTS");
+                       TRACE_DEBUG("CONNECTION_ERROR_ALREADY_EXISTS");
                        break;
                case CONNECTION_ERROR_OPERATION_ABORTED :
-                       TRACE_INFO("CONNECTION_ERROR_OPERATION_ABORTED");
+                       TRACE_DEBUG("CONNECTION_ERROR_OPERATION_ABORTED");
                        break;
                case CONNECTION_ERROR_DHCP_FAILED :
-                       TRACE_INFO("CONNECTION_ERROR_DHCP_FAILED");
+                       TRACE_DEBUG("CONNECTION_ERROR_DHCP_FAILED");
                        break;
                case CONNECTION_ERROR_INVALID_KEY :
-                       TRACE_INFO("CONNECTION_ERROR_INVALID_KEY");
+                       TRACE_DEBUG("CONNECTION_ERROR_INVALID_KEY");
                        break;
                case CONNECTION_ERROR_NO_REPLY :
-                       TRACE_INFO("CONNECTION_ERROR_NO_REPLY");
+                       TRACE_DEBUG("CONNECTION_ERROR_NO_REPLY");
                        break;
                default :
-                       TRACE_INFO("CONNECTION_ERROR_NONE");
+                       TRACE_DEBUG("CONNECTION_ERROR_NONE");
                        break;
        }
 }
@@ -130,8 +130,6 @@ static void __print_connection_errorcode_to_string(connection_error_e errorcode)
 // support WIFI-Direct
 static void __dp_network_wifi_direct_connection_state_changed_cb(wifi_direct_error_e error_code, wifi_direct_connection_state_e connection_state, const char *mac_address, void *data)
 {
-       TRACE_INFO("");
-
        dp_privates *privates = (dp_privates*)data;
        if (privates == NULL) {
                TRACE_ERROR("[CRITICAL] Invalid data");
@@ -139,7 +137,7 @@ static void __dp_network_wifi_direct_connection_state_changed_cb(wifi_direct_err
        }
 
        if (connection_state == WIFI_DIRECT_CONNECTION_RSP) {
-               TRACE_INFO("WIFI_DIRECT_CONNECTION_RSP");
+               TRACE_DEBUG("WIFI_DIRECT_CONNECTION_RSP");
                privates->is_connected_wifi_direct = 1;
                return ;
        }
@@ -155,29 +153,29 @@ int dp_network_wifi_direct_is_connected()
                switch (wifi_state)
                {
                        case WIFI_DIRECT_STATE_DEACTIVATED :
-                               TRACE_INFO("WIFI_DIRECT_STATE_DEACTIVATED");
+                               TRACE_DEBUG("WIFI_DIRECT_STATE_DEACTIVATED");
                                break;
                        case WIFI_DIRECT_STATE_DEACTIVATING :
-                               TRACE_INFO("WIFI_DIRECT_STATE_DEACTIVATING");
+                               TRACE_DEBUG("WIFI_DIRECT_STATE_DEACTIVATING");
                                break;
                        case WIFI_DIRECT_STATE_ACTIVATING :
-                               TRACE_INFO("WIFI_DIRECT_STATE_ACTIVATING");
+                               TRACE_DEBUG("WIFI_DIRECT_STATE_ACTIVATING");
                                break;
                        case WIFI_DIRECT_STATE_ACTIVATED :
-                               TRACE_INFO("WIFI_DIRECT_STATE_ACTIVATED");
+                               TRACE_DEBUG("WIFI_DIRECT_STATE_ACTIVATED");
                                break;
                        case WIFI_DIRECT_STATE_DISCOVERING :
-                               TRACE_INFO("WIFI_DIRECT_STATE_DISCOVERING");
+                               TRACE_DEBUG("WIFI_DIRECT_STATE_DISCOVERING");
                                break;
                        case WIFI_DIRECT_STATE_CONNECTING :
-                               TRACE_INFO("WIFI_DIRECT_STATE_CONNECTING");
+                               TRACE_DEBUG("WIFI_DIRECT_STATE_CONNECTING");
                                break;
                        case WIFI_DIRECT_STATE_DISCONNECTING :
-                               TRACE_INFO("WIFI_DIRECT_STATE_DISCONNECTING");
+                               TRACE_DEBUG("WIFI_DIRECT_STATE_DISCONNECTING");
                                break;
                        case WIFI_DIRECT_STATE_CONNECTED :
                                is_connected = 0;
-                               TRACE_INFO("WIFI_DIRECT_STATE_CONNECTED");
+                               TRACE_DEBUG("WIFI_DIRECT_STATE_CONNECTED");
                                break;
                        default :
                                break;
@@ -201,10 +199,10 @@ static dp_network_type __dp_get_network_connection_status(connection_h connectio
                        (connection, &wifi_state) != CONNECTION_ERROR_NONE)
                        TRACE_ERROR("Failed connection_get_wifi_state");
                if (wifi_state == CONNECTION_WIFI_STATE_CONNECTED) {
-                       TRACE_INFO("[CONNECTION_WIFI] CONNECTED");
+                       TRACE_DEBUG("[CONNECTION_WIFI] CONNECTED");
                        network_type = DP_NETWORK_TYPE_WIFI;
                } else {
-                       TRACE_INFO("[CONNECTION_WIFI] [%d]", wifi_state);
+                       TRACE_DEBUG("[CONNECTION_WIFI] [%d]", wifi_state);
                }
        } else if (type == CONNECTION_TYPE_CELLULAR) {
                connection_cellular_state_e cellular_state;
@@ -213,10 +211,10 @@ static dp_network_type __dp_get_network_connection_status(connection_h connectio
                        (connection, &cellular_state) != CONNECTION_ERROR_NONE)
                        TRACE_ERROR("Failed connection_get_cellular_state");
                if (cellular_state == CONNECTION_CELLULAR_STATE_CONNECTED) {
-                       TRACE_INFO("[CONNECTION_CELLULAR] DATA NETWORK CONNECTED");
+                       TRACE_DEBUG("[CONNECTION_CELLULAR] DATA NETWORK CONNECTED");
                        network_type = DP_NETWORK_TYPE_DATA_NETWORK;
                } else {
-                       TRACE_INFO("[CONNECTION_CELLULAR] [%d]", cellular_state);
+                       TRACE_DEBUG("[CONNECTION_CELLULAR] [%d]", cellular_state);
                }
        } else if (type == CONNECTION_TYPE_ETHERNET) {
                connection_ethernet_state_e ethernet_state;
@@ -225,13 +223,13 @@ static dp_network_type __dp_get_network_connection_status(connection_h connectio
                        (connection, &ethernet_state) != CONNECTION_ERROR_NONE)
                        TRACE_ERROR("Failed connection_get_ethernet_state");
                if (ethernet_state == CONNECTION_ETHERNET_STATE_CONNECTED) {
-                       TRACE_INFO("[CONNECTION_ETHERNET] ETHERNET CONNECTED");
+                       TRACE_DEBUG("[CONNECTION_ETHERNET] ETHERNET CONNECTED");
                        network_type = DP_NETWORK_TYPE_ETHERNET;
                } else {
-                       TRACE_INFO("[CONNECTION_ETHERNET] [%d]", ethernet_state);
+                       TRACE_DEBUG("[CONNECTION_ETHERNET] [%d]", ethernet_state);
                }
        } else {
-               TRACE_INFO("[DISCONNECTED]");
+               TRACE_DEBUG("[DISCONNECTED]");
                network_type = DP_NETWORK_TYPE_OFF;
        }
        return network_type;
@@ -242,25 +240,24 @@ static dp_network_type __dp_get_network_connection_status(connection_h connectio
 /// @todo              care requests by network status
 static void __dp_network_connection_type_changed_cb(connection_type_e type, void *data)
 {
-       TRACE_INFO("type[%d]", type);
        dp_privates *privates = (dp_privates*)data;
-       if (!privates) {
+       if (privates == NULL) {
                TRACE_ERROR("[CRITICAL] Invalid data");
                return ;
        }
        CLIENT_MUTEX_LOCK(&(g_dp_queue_mutex));
        #if 1 // this callback guarantee that already connectdd
        if (type == CONNECTION_TYPE_WIFI) {
-               TRACE_INFO("[CONNECTION_WIFI] CONNECTED");
+               TRACE_DEBUG("[CONNECTION_WIFI] CONNECTED");
                privates->network_status = DP_NETWORK_TYPE_WIFI;
        } else if (type == CONNECTION_TYPE_CELLULAR) {
-               TRACE_INFO("[CONNECTION_CELLULAR] DATA NETWORK CONNECTED");
+               TRACE_DEBUG("[CONNECTION_CELLULAR] DATA NETWORK CONNECTED");
                privates->network_status = DP_NETWORK_TYPE_DATA_NETWORK;
        } else if (type == CONNECTION_TYPE_ETHERNET) {
-               TRACE_INFO("[CONNECTION_ETHERNET] ETHERNET CONNECTED");
+               TRACE_DEBUG("[CONNECTION_ETHERNET] ETHERNET CONNECTED");
                privates->network_status = DP_NETWORK_TYPE_ETHERNET;
        } else {
-               TRACE_INFO("[DISCONNECTED]");
+               TRACE_DEBUG("[DISCONNECTED]");
                privates->network_status = DP_NETWORK_TYPE_OFF;
        }
        if (privates->network_status != DP_NETWORK_TYPE_OFF)
@@ -273,13 +270,42 @@ static void __dp_network_connection_type_changed_cb(connection_type_e type, void
 }
 
 //////////////////////////////////////////////////////////////////////////
+/// @brief             [callback] called when changed network ip
+/// @todo              auto resume feature
+static void __dp_network_connection_ip_changed_cb(const char *ip, const char *ipv6, void *data)
+{
+       dp_privates *privates = (dp_privates*)data;
+       if (privates == NULL) {
+               TRACE_ERROR("[CRITICAL] Invalid data");
+               return ;
+       }
+       if (privates->network_status != DP_NETWORK_TYPE_OFF) {
+               dp_request_slots *requests = privates->requests;
+               int i = 0;
+               for (i = 0; i < DP_MAX_REQUEST; i++) {
+                       int locked = pthread_mutex_trylock(&requests[i].mutex);
+                       // locking failure means it used by other thread.
+                       if (locked == 0) {
+                               if (requests[i].request != NULL) {
+                                       if (requests[i].request->state == DP_STATE_DOWNLOADING ||
+                                               (requests[i].request->state == DP_STATE_FAILED &&
+                                               requests[i].request->error == DP_ERROR_CONNECTION_FAILED)) {
+                                               requests[i].request->ip_changed = 1;
+                                       }
+                               }
+                               CLIENT_MUTEX_UNLOCK(&requests[i].mutex);
+                       }
+               }
+       }
+}
+
+//////////////////////////////////////////////////////////////////////////
 /// @brief             create connection handle & regist callback
 /// @return    0 : success -1 : failed
 int dp_network_connection_init(dp_privates *privates)
 {
        int retcode = 0;
 
-       TRACE_INFO("");
        if (!privates) {
                TRACE_ERROR("[CRITICAL] Invalid data");
                return -1;
@@ -306,6 +332,13 @@ int dp_network_connection_init(dp_privates *privates)
                connection_destroy(privates->connection);
                return -1;
        }
+       if ((retcode = connection_set_ip_address_changed_cb
+                       (privates->connection, __dp_network_connection_ip_changed_cb,
+                               privates)) != CONNECTION_ERROR_NONE) {
+               TRACE_ERROR("Failed __dp_network_connection_ip_changed_cb [%d]", retcode);
+               connection_destroy(privates->connection);
+               return -1;
+       }
        connection_type_e type = CONNECTION_TYPE_DISCONNECTED;
        if ((retcode = connection_get_type(privates->connection, &type)) !=
                        CONNECTION_ERROR_NONE) {
@@ -322,14 +355,13 @@ int dp_network_connection_init(dp_privates *privates)
 /// @brief             destroy connection handle
 void dp_network_connection_destroy(connection_h connection)
 {
-       TRACE_INFO("");
-
 #ifdef SUPPORT_WIFI_DIRECT
        wifi_direct_unset_connection_state_changed_cb();
        wifi_direct_deinitialize();
 #endif
 
-       connection_unset_type_changed_cb (connection);
+       connection_unset_type_changed_cb(connection);
+       connection_unset_ip_address_changed_cb(connection);
        connection_destroy(connection);
 }
 
index b7967e8..f6e2f8b 100755 (executable)
 #include <time.h>
 #include <sys/time.h>
 #include <stdlib.h>
+#include <stdio.h>
 
 #include "bundle.h"
 #include "notification.h"
 #include "appsvc.h"
 
+#include "download-provider-defs.h"
+
 #include "download-provider-notification.h"
 #include "download-provider-request.h"
 #include "download-provider-db.h"
 
 #include <libintl.h>
 #define S_(s) dgettext("sys_string", s)
+#define __(s) dgettext(PKG_NAME, s)
 
-#define DP_NOTIFICATION_ICON_PATH IMAGE_DIR"/Q02_Notification_Download_failed.png"
+#define DP_NOTIFICATION_ICON_PATH IMAGE_DIR"/Q02_Notification_download_complete.png"
+#define DP_NOTIFICATION_ONGOING_ICON_PATH IMAGE_DIR"/Notification_download_animation.gif"
+#define DP_NOTIFICATION_DOWNLOADING_ICON_PATH "reserved://indicator/ani/downloading"
+#define DP_NOTIFICATION_FAILED_ICON_PATH IMAGE_DIR"/Q02_Notification_download_failed.png"
 
 static const char *__noti_error_str(
                notification_error_e err)
@@ -54,137 +61,102 @@ static const char *__noti_error_str(
        return "Unknown error";
 }
 
+static char *__get_string_sender(char *url)
+{
+       char *temp = NULL;
+       char *found = NULL;
+       char *found1 = NULL;
+       char *sender = NULL;
+       char *credential_sender = NULL;
+
+       if (url == NULL)
+               return NULL;
+
+       found = strstr(url, "://");
+       if (found) {
+               temp = found + 3;
+       } else {
+               temp = url;
+       }
+       found = strchr(temp, '/');
+       if (found) {
+               int len = 0;
+               len = found - temp;
+               sender = calloc(len + 1, sizeof(char));
+               if (sender == NULL)
+                       return NULL;
+               snprintf(sender, len + 1, "%s", temp);
+       } else {
+               sender = dp_strdup(temp);
+       }
+
+       // For credential URL
+       found = strchr(sender, '@');
+       found1 = strchr(sender, ':');
+       if (found && found1 && found1 < found) {
+               int len = 0;
+               found = found + 1;
+               len = strlen(found);
+               credential_sender = calloc(len + 1, sizeof(char));
+               if (credential_sender == NULL) {
+                       free(sender);
+                       return NULL;
+               }
+               snprintf(credential_sender, len + 1, "%s", found);
+               free(sender);
+               return credential_sender;
+       } else {
+               return sender;
+       }
+}
+
+static char *__get_string_size(long long file_size)
+{
+       const char *unitStr[4] = {"B", "KB", "MB", "GB"};
+       double doubleTypeBytes = 0.0;
+       int unit = 0;
+       long long bytes = file_size;
+       long long unitBytes = bytes;
+       char *temp = NULL;
+
+       /* using bit operation to avoid floating point arithmetic */
+       for (unit = 0; (unitBytes > 1024 && unit < 4); unit++) {
+               unitBytes = unitBytes >> 10;
+       }
+       unitBytes = 1 << (10 * unit);
+
+       if (unit > 3)
+               unit = 3;
+
+       char str[64] = {0};
+       if (unit == 0) {
+               snprintf(str, sizeof(str), "%lld %s", bytes, unitStr[unit]);
+       } else {
+               doubleTypeBytes = ((double)bytes / (double)unitBytes);
+               snprintf(str, sizeof(str), "%.2f %s", doubleTypeBytes, unitStr[unit]);
+       }
+
+       str[63] = '\0';
+       temp = dp_strdup(str);
+       return temp;
+}
+
 static char *__get_string_status(dp_state_type state)
 {
        char *message = NULL;
        switch (state) {
        case DP_STATE_COMPLETED:
-               //message = S_("IDS_COM_POP_SUCCESS");
-               message = "Completed";
+               message = __("IDS_DM_HEADER_DOWNLOAD_COMPLETE");
                break;
        case DP_STATE_CANCELED:
-               //message = S_("IDS_COM_POP_CANCELLED");
-               message = "Canceled";
-               break;
        case DP_STATE_FAILED:
-               //message = S_("IDS_COM_POP_FAILED");
-               message = "Failed";
+               message = S_("IDS_COM_POP_DOWNLOAD_FAILED");
                break;
        default:
                break;
        }
        return message;
 }
-static void __free_char_pointer_array(char **array, int count)
-{
-       int i = 0;
-       if (count < 0)
-               count = 0;
-       for (i = 0; i < count; i++) {
-               if (array[i])
-                       free(array[i]);
-       }
-       free(array);
-}
-
-static int __set_extra_data(bundle *b, int id)
-{
-       db_conds_list_fmt conds_p;
-       int conds_count = 0;
-       int count = 0;
-       // get count of key list.
-       conds_count = 1;
-       memset(&conds_p, 0x00, sizeof(db_conds_list_fmt));
-       conds_p.column = DP_DB_COL_ID;
-       conds_p.type = DP_DB_COL_TYPE_INT;
-       conds_p.value = &id;
-       count = dp_db_get_conds_rows_count(DP_DB_TABLE_NOTIFICATION,
-                       DP_DB_COL_DISTINCT_EXTRA_KEY, "AND", 1, &conds_p);
-       if (count > 0) {
-               char **keys_array = NULL;
-               int i = 0;
-               keys_array = (char **)calloc(count, sizeof(char *));
-               if (keys_array == NULL) {
-                       TRACE_ERROR("[FAIL] calloc failed");
-                       return -1;
-               }
-               // get key list
-               int keys_count =
-                       dp_db_get_conds_list(DP_DB_TABLE_NOTIFICATION,
-                                       DP_DB_COL_DISTINCT_EXTRA_KEY , DP_DB_COL_TYPE_TEXT,
-                                       (void **)keys_array, count, -1, NULL, NULL,
-                                       "AND", 1, &conds_p);
-               if (keys_count <= 0) {
-                       TRACE_ERROR("[FAIL] Wrong db data");
-                       __free_char_pointer_array(keys_array, 0);
-                       return -1;
-               }
-               for (i = 0; i < keys_count; i++) {
-                       db_conds_list_fmt conds_p2[2];
-                       int conds_count2 = 2;
-                       char **values_array = NULL;
-                       int check_rows = 0;
-                       int values_count = 0;
-
-                       memset(conds_p2, 0x00, conds_count2 * sizeof(db_conds_list_fmt));
-                       conds_p2[0].column = DP_DB_COL_ID;
-                       conds_p2[0].type = DP_DB_COL_TYPE_INT;
-                       conds_p2[0].value = &id;
-                       conds_p2[1].column = DP_DB_COL_EXTRA_KEY;
-                       conds_p2[1].type = DP_DB_COL_TYPE_TEXT;
-                       conds_p2[1].value = (void *)(keys_array[i]);
-                       // get value list
-                       check_rows = dp_db_get_conds_rows_count(
-                                       DP_DB_TABLE_NOTIFICATION, DP_DB_COL_EXTRA_VALUE, "AND",
-                                       conds_count2, conds_p2);
-                       if (check_rows <= 0) {
-                               TRACE_ERROR("[FAIL] No values about key");
-                               __free_char_pointer_array(keys_array, keys_count);
-                               return -1;
-                       }
-                       values_array = (char **)calloc(check_rows, sizeof(char *));
-                       if (values_array == NULL) {
-                               TRACE_ERROR("[FAIL] calloc failed");
-                               __free_char_pointer_array(keys_array, keys_count);
-                               return -1;
-                       }
-                       values_count =
-                               dp_db_get_conds_list(DP_DB_TABLE_NOTIFICATION,
-                                       DP_DB_COL_EXTRA_VALUE, DP_DB_COL_TYPE_TEXT,
-                                       (void **)values_array, check_rows, -1, NULL, NULL,
-                                       "AND", conds_count2, conds_p2);
-                       if (values_count <= 0) {
-                               TRACE_ERROR("[FAIL] No values about key");
-                               __free_char_pointer_array(keys_array, keys_count);
-                               __free_char_pointer_array(values_array, 0);
-                               return -1;
-                       }
-                       if (values_count == 1) {
-                               char *key = keys_array[i];
-                               char *value = values_array[values_count-1];
-                               if (appsvc_add_data(b, key, value) !=
-                                       APPSVC_RET_OK) {
-                                       TRACE_ERROR("[FAIL] set add data");
-                                       __free_char_pointer_array(keys_array, keys_count);
-                                       __free_char_pointer_array(values_array, values_count);
-                                       return -1;
-                               }
-                       } else {
-                               char *key = keys_array[i];
-                               if (appsvc_add_data_array(b, key, (const char **)values_array,
-                                               values_count) !=        APPSVC_RET_OK) {
-                                       TRACE_ERROR("[FAIL] set add data");
-                                       __free_char_pointer_array(keys_array, keys_count);
-                                       __free_char_pointer_array(values_array, values_count);
-                                       return -1;
-                               }
-                       }
-                       __free_char_pointer_array(values_array, values_count);
-               }
-               __free_char_pointer_array(keys_array, keys_count);
-       }
-       return 0;
-}
 
 int dp_set_downloadinginfo_notification(int id, char *packagename)
 {
@@ -192,6 +164,9 @@ int dp_set_downloadinginfo_notification(int id, char *packagename)
        notification_error_e err = NOTIFICATION_ERROR_NONE;
        int privId = 0;
        bundle *b = NULL;
+       void *blob_data = NULL;
+       bundle_raw* b_raw = NULL;
+       int length;
 
        noti_handle = notification_create(NOTIFICATION_TYPE_ONGOING);
        if (!noti_handle) {
@@ -199,18 +174,31 @@ int dp_set_downloadinginfo_notification(int id, char *packagename)
                return -1;
        }
 
-       char *content_name =
-               dp_db_get_text_column
-                       (id, DP_DB_TABLE_DOWNLOAD_INFO, DP_DB_COL_CONTENT_NAME);
+       char *title = dp_db_get_text_column(id,
+               DP_DB_TABLE_NOTIFICATION, DP_DB_COL_TITLE);
+       if(title != NULL) {
+               err = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_TITLE,
+                       title, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+               free(title);
+               if (err != NOTIFICATION_ERROR_NONE) {
+                       TRACE_ERROR("[FAIL] set title [%s]", __noti_error_str(err));
+                       notification_free(noti_handle);
+                       return -1;
+               }
+       } else {
+               char *content_name =
+                       dp_db_get_text_column
+                               (id, DP_DB_TABLE_DOWNLOAD_INFO, DP_DB_COL_CONTENT_NAME);
 
-       if (content_name == NULL)
-               content_name = strdup("No Name");
+               if (content_name == NULL)
+                       content_name = strdup("No Name");
 
-       err = notification_set_text(noti_handle,
-                       NOTIFICATION_TEXT_TYPE_TITLE, content_name, NULL,
-                       NOTIFICATION_VARIABLE_TYPE_NONE);
-       if (content_name)
-               free(content_name);
+               err = notification_set_text(noti_handle,
+                               NOTIFICATION_TEXT_TYPE_TITLE, content_name, NULL,
+                               NOTIFICATION_VARIABLE_TYPE_NONE);
+               if (content_name)
+                       free(content_name);
+       }
 
        if (err != NOTIFICATION_ERROR_NONE) {
                TRACE_ERROR("[FAIL] set title [%s]", __noti_error_str(err));
@@ -219,49 +207,79 @@ int dp_set_downloadinginfo_notification(int id, char *packagename)
        }
 
        err = notification_set_image(noti_handle,
-                       NOTIFICATION_IMAGE_TYPE_ICON, DP_NOTIFICATION_ICON_PATH);
+                       NOTIFICATION_IMAGE_TYPE_ICON, DP_NOTIFICATION_ONGOING_ICON_PATH);
        if (err != NOTIFICATION_ERROR_NONE) {
                TRACE_ERROR("[FAIL] set icon [%s]", __noti_error_str(err));
                notification_free(noti_handle);
                return -1;
        }
 
-       b = bundle_create();
-       if (!b) {
-               TRACE_ERROR("[FAIL] create bundle");
-               notification_free(noti_handle);
-               return -1;
-       }
+       blob_data = dp_db_get_blob_column
+                               (id, DP_DB_TABLE_NOTIFICATION, DP_DB_COL_RAW_BUNDLE_ONGOING, &length);
+       if (blob_data != NULL) {
+               b_raw = (bundle_raw*)blob_data;
+               if (b_raw != NULL) {
+                       b = bundle_decode_raw(b_raw, length);
+                       if (b != NULL) {
+                               err = notification_set_execute_option(noti_handle,
+                                       NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, "View", NULL, b);
+
+                               if (err != NOTIFICATION_ERROR_NONE) {
+                                       TRACE_ERROR("[FAIL] set execute option [%s]", __noti_error_str(err));
+                                       bundle_free_encoded_rawdata(&b_raw);
+                                       bundle_free(b);
+                                       notification_free(noti_handle);
+                                       return -1;
+                               }
+                               bundle_free_encoded_rawdata(&b_raw);
+                               bundle_free(b);
+                       }
+               }
+       } else {
+               b = bundle_create();
+               if (!b) {
+                       TRACE_ERROR("[FAIL] create bundle");
+                       notification_free(noti_handle);
+                       return -1;
+               }
 
-       if (packagename &&
-               appsvc_set_pkgname(b, packagename) != APPSVC_RET_OK) {
-               TRACE_ERROR("[FAIL] set pkg name");
-               bundle_free(b);
-               notification_free(noti_handle);
-               return -1;
-       }
+               if (packagename &&
+                       appsvc_set_pkgname(b, packagename) != APPSVC_RET_OK) {
+                       TRACE_ERROR("[FAIL] set pkg name");
+                       bundle_free(b);
+                       notification_free(noti_handle);
+                       return -1;
+               }
+               err = notification_set_execute_option(noti_handle,
+                       NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, "View", NULL, b);
 
-       if (__set_extra_data(b, id) < 0) {
+               if (err != NOTIFICATION_ERROR_NONE) {
+                       TRACE_ERROR("[FAIL] set execute option [%s]", __noti_error_str(err));
+                       bundle_free(b);
+                       notification_free(noti_handle);
+                       return -1;
+               }
                bundle_free(b);
+       }
+       err = notification_set_property(noti_handle,
+                       NOTIFICATION_PROP_DISABLE_TICKERNOTI);
+       if (err != NOTIFICATION_ERROR_NONE) {
+               TRACE_ERROR("[FAIL] set property [%s]", __noti_error_str(err));
                notification_free(noti_handle);
                return -1;
        }
 
-       err = notification_set_execute_option(noti_handle,
-                       NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, "View", NULL, b);
-
+       err = notification_set_image(noti_handle,
+               NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, DP_NOTIFICATION_DOWNLOADING_ICON_PATH);
        if (err != NOTIFICATION_ERROR_NONE) {
-               TRACE_ERROR("[FAIL] set execute option [%s]", __noti_error_str(err));
-               bundle_free(b);
+               TRACE_ERROR("[FAIL] set icon indicator [%s]", __noti_error_str(err));
                notification_free(noti_handle);
                return -1;
        }
-       bundle_free(b);
 
-       err = notification_set_property(noti_handle,
-                       NOTIFICATION_PROP_DISABLE_TICKERNOTI);
+       err = notification_set_display_applist(noti_handle, NOTIFICATION_DISPLAY_APP_ALL);
        if (err != NOTIFICATION_ERROR_NONE) {
-               TRACE_ERROR("[FAIL] set property [%s]", __noti_error_str(err));
+               TRACE_ERROR("[FAIL] set disable icon [%s]", __noti_error_str(err));
                notification_free(noti_handle);
                return -1;
        }
@@ -273,7 +291,7 @@ int dp_set_downloadinginfo_notification(int id, char *packagename)
                return -1;
        }
 
-       TRACE_INFO("m_noti_id [%d]", privId);
+       TRACE_DEBUG("m_noti_id [%d]", privId);
        notification_free(noti_handle);
        return privId;
 }
@@ -284,6 +302,9 @@ int dp_set_downloadedinfo_notification(int priv_id, int id, char *packagename, d
        notification_error_e err = NOTIFICATION_ERROR_NONE;
        int privId = 0;
        bundle *b = NULL;
+       void *blob_data = NULL;
+       bundle_raw* b_raw = NULL;
+       int length = 0;
 
        if (priv_id >= 0) {
                err = notification_delete_by_priv_id(NULL, NOTIFICATION_TYPE_ONGOING,
@@ -301,99 +322,218 @@ int dp_set_downloadedinfo_notification(int priv_id, int id, char *packagename, d
                return -1;
        }
 
-       char *content_name =
-               dp_db_get_text_column
-                       (id, DP_DB_TABLE_DOWNLOAD_INFO, DP_DB_COL_CONTENT_NAME);
-
-       if (content_name == NULL)
-               content_name = strdup("No Name");
-
-       err = notification_set_text(noti_handle,
-                       NOTIFICATION_TEXT_TYPE_TITLE, content_name,
-                       NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-       if (content_name)
-               free(content_name);
-
        if (err != NOTIFICATION_ERROR_NONE) {
                TRACE_ERROR("[FAIL] set title [%s]", __noti_error_str(err));
                notification_free(noti_handle);
                return -1;
        }
 
-       err = notification_set_text(noti_handle,
-                       NOTIFICATION_TEXT_TYPE_CONTENT,
-                       __get_string_status(state), NULL,
-                       NOTIFICATION_VARIABLE_TYPE_NONE);
+       err = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_TITLE,
+                       __get_string_status(state), NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
        if (err != NOTIFICATION_ERROR_NONE) {
-               TRACE_ERROR("[FAIL] set text [%s]", __noti_error_str(err));
-               notification_free(noti_handle);
-               return -1;
-       }
-       time_t tt = time(NULL);
-
-       err = notification_set_time(noti_handle, tt);
-       if (err != NOTIFICATION_ERROR_NONE) {
-               TRACE_ERROR("[FAIL] set time [%s]", __noti_error_str(err));
-               notification_free(noti_handle);
-               return -1;
-       }
-
-       b = bundle_create();
-       if (!b) {
-               TRACE_ERROR("[FAIL] create bundle");
+               TRACE_ERROR("[FAIL] set title [%s]", __noti_error_str(err));
                notification_free(noti_handle);
                return -1;
        }
 
-       if (state == DP_STATE_COMPLETED) {
-               if (appsvc_set_operation(b, APPSVC_OPERATION_VIEW) != APPSVC_RET_OK) {
-                       TRACE_ERROR("[FAIL] appsvc set operation");
-                       bundle_free(b);
+       char *description =
+               dp_db_get_text_column
+                       (id, DP_DB_TABLE_NOTIFICATION, DP_DB_COL_DESCRIPTION);
+       if(description != NULL) {
+               err = notification_set_text(noti_handle,
+                               NOTIFICATION_TEXT_TYPE_INFO_2, description,
+                               NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+               free(description);
+               if (err != NOTIFICATION_ERROR_NONE) {
+                       TRACE_ERROR("[FAIL] set description [%s]", __noti_error_str(err));
                        notification_free(noti_handle);
                        return -1;
                }
-               
-               char *savedpath =
-                       dp_db_get_text_column
-                               (id, DP_DB_TABLE_DOWNLOAD_INFO, DP_DB_COL_SAVED_PATH);
-               if (savedpath && appsvc_set_uri(b, savedpath) !=
-                               APPSVC_RET_OK) {
-                       TRACE_ERROR("[FAIL] appsvc set uri");
-                       free(savedpath);
-                       bundle_free(b);
-                       notification_free(noti_handle);
-                       return -1;
+       } else {
+               char *url = NULL;
+               url = dp_db_get_text_column
+                                       (id, DP_DB_TABLE_REQUEST_INFO, DP_DB_COL_URL);
+               if (url) {
+                       char *sender_str = __get_string_sender(url);
+                       err = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_INFO_2,
+                                       sender_str, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+                       if (err != NOTIFICATION_ERROR_NONE) {
+                               TRACE_ERROR("[FAIL] set title [%s]", __noti_error_str(err));
+                               free(sender_str);
+                               free(url);
+                               notification_free(noti_handle);
+                               return -1;
+                       }
+                       free(sender_str);
+                       free(url);
                }
-               if (savedpath)
-                       free(savedpath);
-               err = notification_set_execute_option(noti_handle,
-                               NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, "View", NULL, b);
+       }
+
+       char *title = dp_db_get_text_column(id,
+               DP_DB_TABLE_NOTIFICATION, DP_DB_COL_TITLE);
+       if(title != NULL) {
+               err = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_CONTENT,
+                       title, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+               free(title);
                if (err != NOTIFICATION_ERROR_NONE) {
-                       TRACE_ERROR("[FAIL] set execute option[%s]", __noti_error_str(err));
-                       bundle_free(b);
+                       TRACE_ERROR("[FAIL] set title [%s]", __noti_error_str(err));
                        notification_free(noti_handle);
                        return -1;
                }
+       } else {
+               char *content_name =
+                               dp_db_get_text_column
+                                       (id, DP_DB_TABLE_DOWNLOAD_INFO, DP_DB_COL_CONTENT_NAME);
+               if (content_name == NULL)
+                       content_name = strdup("No Name");
+
+               err = notification_set_text(noti_handle,
+                               NOTIFICATION_TEXT_TYPE_CONTENT, content_name,
+                               NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+               free(content_name);
+       }
 
-       } else if (state == DP_STATE_CANCELED || state == DP_STATE_FAILED) {
-               if (__set_extra_data(b, id) < 0) {
+       time_t tt = time(NULL);
+       err = notification_set_time_to_text(noti_handle,
+                       NOTIFICATION_TEXT_TYPE_INFO_SUB_1, tt);
+       if (err != NOTIFICATION_ERROR_NONE) {
+               TRACE_ERROR("[FAIL] set time [%s]", __noti_error_str(err));
+               notification_free(noti_handle);
+               return -1;
+       }
+       if (state == DP_STATE_COMPLETED) {
+               blob_data = dp_db_get_blob_column
+                                       (id, DP_DB_TABLE_NOTIFICATION, DP_DB_COL_RAW_BUNDLE_COMPLETE, &length);
+               if (blob_data != NULL) {
+                       b_raw = (bundle_raw*)blob_data;
+                       if (b_raw != NULL) {
+                               b = bundle_decode_raw(b_raw, length);
+                               if (b != NULL) {
+                                       err = notification_set_execute_option(noti_handle,
+                                               NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, "View", NULL, b);
+
+                                       if (err != NOTIFICATION_ERROR_NONE) {
+                                               TRACE_ERROR("[FAIL] set execute option [%s]", __noti_error_str(err));
+                                               bundle_free_encoded_rawdata(&b_raw);
+                                               bundle_free(b);
+                                               notification_free(noti_handle);
+                                               return -1;
+                                       }
+                                       bundle_free_encoded_rawdata(&b_raw);
+                               }
+                       }
+               } else {
+                       char *file_path = NULL;
+                       b = bundle_create();
+                       if (!b) {
+                               TRACE_ERROR("[FAIL] create bundle");
+                               notification_free(noti_handle);
+                               return -1;
+                       }
+                       if (appsvc_set_operation(b, APPSVC_OPERATION_VIEW) != APPSVC_RET_OK) {
+                               TRACE_ERROR("[FAIL] appsvc set operation");
+                               bundle_free(b);
+                               notification_free(noti_handle);
+                               return -1;
+                       }
+                       file_path = dp_db_get_text_column
+                                       (id, DP_DB_TABLE_DOWNLOAD_INFO, DP_DB_COL_SAVED_PATH);
+                       if (file_path == NULL) {
+                               TRACE_ERROR("[FAIL] get file path");
+                               bundle_free(b);
+                               notification_free(noti_handle);
+                               return -1;
+
+                       }
+                       if (appsvc_set_uri(b, file_path) != APPSVC_RET_OK) {
+                               TRACE_ERROR("[FAIL] appsvc set uri");
+                               bundle_free(b);
+                               notification_free(noti_handle);
+                               free(file_path);
+                               return -1;
+                       }
+                       free(file_path);
+                       err = notification_set_execute_option(noti_handle,
+                               NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, "View", NULL, b);
+                       if (err != NOTIFICATION_ERROR_NONE) {
+                               TRACE_ERROR("[FAIL] set execute option[%s]", __noti_error_str(err));
+                               bundle_free(b);
+                               notification_free(noti_handle);
+                               return -1;
+                       }
+               }
+               long long file_size = dp_db_get_int64_column(id,
+                               DP_DB_TABLE_DOWNLOAD_INFO, DP_DB_COL_CONTENT_SIZE);
+               char *size_str = __get_string_size(file_size);
+
+               err = notification_set_text(noti_handle,        NOTIFICATION_TEXT_TYPE_INFO_1,
+                               size_str, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+
+               if (err != NOTIFICATION_ERROR_NONE) {
+                       TRACE_ERROR("[FAIL] set title [%s]", __noti_error_str(err));
+                       free(size_str);
                        bundle_free(b);
                        notification_free(noti_handle);
                        return -1;
                }
+               free(size_str);
 
-               if (packagename &&
-                       appsvc_set_pkgname(b, packagename) !=
-                       APPSVC_RET_OK) {
-                       TRACE_ERROR("[FAIL] set pkg name");
-                       bundle_free(b);
+               err = notification_set_image(noti_handle, NOTIFICATION_IMAGE_TYPE_ICON,
+                               DP_NOTIFICATION_ICON_PATH);
+               if (err != NOTIFICATION_ERROR_NONE) {
+                       TRACE_ERROR("[FAIL] set icon [%s]", __noti_error_str(err));
                        notification_free(noti_handle);
                        return -1;
                }
-               err = notification_set_execute_option(noti_handle,
-                               NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, "View", NULL, b);
+       } else if (state == DP_STATE_CANCELED || state == DP_STATE_FAILED) {
+               blob_data = dp_db_get_blob_column
+                                       (id, DP_DB_TABLE_NOTIFICATION, DP_DB_COL_RAW_BUNDLE_FAIL, &length);
+               if (blob_data != NULL) {
+                       b_raw = (bundle_raw *)blob_data;
+                       if (b_raw != NULL) {
+                               b = bundle_decode_raw(b_raw, length);
+                               if (b != NULL) {
+                                       err = notification_set_execute_option(noti_handle,
+                                               NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, "View", NULL, b);
+
+                                       if (err != NOTIFICATION_ERROR_NONE) {
+                                               TRACE_ERROR("[FAIL] set execute option [%s]", __noti_error_str(err));
+                                               bundle_free_encoded_rawdata(&b_raw);
+                                               bundle_free(b);
+                                               notification_free(noti_handle);
+                                               return -1;
+                                       }
+                                       bundle_free_encoded_rawdata(&b_raw);
+                               }
+                       }
+               } else {
+                       b = bundle_create();
+                       if (!b) {
+                               TRACE_ERROR("[FAIL] create bundle");
+                               notification_free(noti_handle);
+                               return -1;
+                       }
+                       if (packagename &&
+                               appsvc_set_pkgname(b, packagename) !=
+                               APPSVC_RET_OK) {
+                               TRACE_ERROR("[FAIL] set pkg name");
+                               bundle_free(b);
+                               notification_free(noti_handle);
+                               return -1;
+                       }
+                       err = notification_set_execute_option(noti_handle,
+                                       NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, "View", NULL, b);
+                       if (err != NOTIFICATION_ERROR_NONE) {
+                               TRACE_ERROR("[FAIL] set execute option[%s]", __noti_error_str(err));
+                               bundle_free(b);
+                               notification_free(noti_handle);
+                               return -1;
+                       }
+               }
+               err = notification_set_image(noti_handle, NOTIFICATION_IMAGE_TYPE_ICON,
+                               DP_NOTIFICATION_FAILED_ICON_PATH);
                if (err != NOTIFICATION_ERROR_NONE) {
-                       TRACE_ERROR("[FAIL] set execute option[%s]", __noti_error_str(err));
+                       TRACE_ERROR("[FAIL] set icon [%s]", __noti_error_str(err));
                        bundle_free(b);
                        notification_free(noti_handle);
                        return -1;
@@ -414,18 +554,18 @@ int dp_set_downloadedinfo_notification(int priv_id, int id, char *packagename, d
 
        bundle_free(b);
 
-       err = notification_set_image(noti_handle, NOTIFICATION_IMAGE_TYPE_ICON,
-                       DP_NOTIFICATION_ICON_PATH);
+       err = notification_set_property(noti_handle,
+                       NOTIFICATION_PROP_DISABLE_TICKERNOTI);
        if (err != NOTIFICATION_ERROR_NONE) {
-               TRACE_ERROR("[FAIL] set icon [%s]", __noti_error_str(err));
+               TRACE_ERROR("[FAIL] set property [%s]", __noti_error_str(err));
                notification_free(noti_handle);
                return -1;
        }
 
-       err = notification_set_property(noti_handle,
-                       NOTIFICATION_PROP_DISABLE_TICKERNOTI);
+       err = notification_set_display_applist(noti_handle,
+                       NOTIFICATION_DISPLAY_APP_ALL ^ NOTIFICATION_DISPLAY_APP_INDICATOR);
        if (err != NOTIFICATION_ERROR_NONE) {
-               TRACE_ERROR("[FAIL] set property [%s]", __noti_error_str(err));
+               TRACE_ERROR("[FAIL] set disable icon [%s]", __noti_error_str(err));
                notification_free(noti_handle);
                return -1;
        }
@@ -437,7 +577,7 @@ int dp_set_downloadedinfo_notification(int priv_id, int id, char *packagename, d
                return -1;
        }
 
-       TRACE_INFO("m_noti_id [%d]", privId);
+       TRACE_DEBUG("m_noti_id [%d]", privId);
        notification_free(noti_handle);
        return privId;
 }
index f766840..10fea00 100755 (executable)
@@ -17,9 +17,8 @@
 #include <stdio.h>
 #include <stdlib.h>
 
-#include <time.h>
 #include <sys/time.h>
-
+#include <sys/statfs.h>
 #include "download-provider.h"
 #include "download-provider-log.h"
 
 #include "download-provider-db.h"
 #include "download-provider-pthread.h"
 
+#include "download-provider-notification.h"
 
+#define SMACKFS_MAGIC 0x43415d53
+#define SMACKFS_MNT "/smack"
 ///////// below functions are called by main thread of thread-request.c
 
-
-
 //////////////////////////////////////////////////////////////////////////
 /// @brief             create unique id as integer type
 /// @return    unique id combined local time and the special calculation
 static int __get_download_request_id(void)
 {
-       int uniquetime = 0;
-       struct timeval tval;
        static int last_uniquetime = 0;
+       int uniquetime = 0;
 
        do {
-               uniquetime = (int)time(NULL);
+               struct timeval tval;
+               int cipher = 1;
+               int c = 0;
+
                gettimeofday(&tval, NULL);
+
+               int usec = tval.tv_usec;
+               for (c = 0; ; c++, cipher++) {
+                       if ((usec /= 10) <= 0)
+                               break;
+               }
                if (tval.tv_usec == 0)
-                       uniquetime = uniquetime + (tval.tv_usec + 1) % 0xfffff;
-               else
-                       uniquetime = uniquetime + tval.tv_usec;
-               TRACE_INFO("ID : %d", uniquetime);
+                       tval.tv_usec = (tval.tv_sec & 0x0fff);
+               int disit_unit = 10;
+               for (c = 0; c < cipher - 3; c++)
+                       disit_unit = disit_unit * 10;
+               uniquetime = tval.tv_sec + ((tval.tv_usec << 2) * 100) +
+                               ((tval.tv_usec >> (cipher - 1)) * disit_unit) +
+                               ((tval.tv_usec + (tval.tv_usec % 10)) & 0x0fff);
        } while (last_uniquetime == uniquetime);
-       last_uniquetime = uniquetime;   // store
+       last_uniquetime = uniquetime;
        return uniquetime;
 }
 
@@ -127,6 +138,8 @@ char *dp_print_errorcode(dp_error_type errorcode)
                        return "UNHANDLED_HTTP_CODE";
                case DP_ERROR_CANNOT_RESUME :
                        return "CANNOT_RESUME";
+               case DP_ERROR_PERMISSION_DENIED :
+                       return "PERMISSION_DENIED";
                case DP_ERROR_RESPONSE_TIMEOUT :
                        return "RESPONSE_TIMEOUT";
                case DP_ERROR_REQUEST_TIMEOUT :
@@ -143,6 +156,24 @@ char *dp_print_errorcode(dp_error_type errorcode)
        return "UNKNOWN";
 }
 
+int dp_is_smackfs_mounted()
+{
+       struct statfs sfs;
+       int ret;
+       do {
+               ret = statfs(SMACKFS_MNT, &sfs);
+       } while (ret < 0 && errno == EINTR);
+       if (ret) {
+               TRACE_ERROR("[SMACK ERROR]");
+               return -1;
+       }
+       if (sfs.f_type == SMACKFS_MAGIC) {
+               return 1;
+       }
+       TRACE_ERROR("[SMACK DISABLE]");
+       return 0;
+}
+
 char *dp_strdup(char *src)
 {
        char *dest = NULL;
@@ -192,11 +223,16 @@ dp_error_type dp_request_create(int id, dp_client_group *group, dp_request **emp
                return DP_ERROR_OUT_OF_MEMORY;
        }
 
-       new_request->id = __get_download_request_id();
+       int check_id = -1;
+       do {
+               new_request->id = __get_download_request_id();
+               check_id = dp_db_get_int_column(new_request->id,
+                                                       DP_DB_TABLE_LOG, DP_DB_COL_ID);
+       } while (check_id == new_request->id); // means duplicated id
+
        new_request->group = group;
-       if (group->pkgname && strlen(group->pkgname) > 1)
+       if (group->pkgname != NULL && strlen(group->pkgname) > 1)
                new_request->packagename = dp_strdup(group->pkgname);
-       new_request->credential = group->credential;
        if (new_request->packagename == NULL) {
                dp_request_free(new_request);
                TRACE_ERROR("[ERROR][%d] OUT_OF_MEMORY [PACKAGENAME]", id);
@@ -204,29 +240,17 @@ dp_error_type dp_request_create(int id, dp_client_group *group, dp_request **emp
        }
        new_request->state = DP_STATE_READY;
        new_request->error = DP_ERROR_NONE;
+       new_request->create_time = (int)time(NULL);
 
-       int conds_count = 3; // id + state + pkgname
-       db_conds_list_fmt conds_p[conds_count];
-       memset(&conds_p, 0x00, conds_count * sizeof(db_conds_list_fmt));
-       conds_p[0].column = DP_DB_COL_ID;
-       conds_p[0].type = DP_DB_COL_TYPE_INT;
-       conds_p[0].value = &new_request->id;
-       conds_p[1].column = DP_DB_COL_STATE;
-       conds_p[1].type = DP_DB_COL_TYPE_INT;
-       conds_p[1].value = &new_request->state;
-       conds_p[2].column = DP_DB_COL_PACKAGENAME;
-       conds_p[2].type = DP_DB_COL_TYPE_TEXT;
-       conds_p[2].value = new_request->packagename;
-       if (dp_db_insert_columns(DP_DB_TABLE_LOG, conds_count, conds_p) < 0) {
+       if (dp_db_request_new_logging(new_request->id, new_request->state,
+                       new_request->packagename) < 0) {
                dp_request_free(new_request);
+               if (dp_db_is_full_error() == 0) {
+                       TRACE_ERROR("[SQLITE_FULL]");
+                       return DP_ERROR_NO_SPACE;
+               }
                return DP_ERROR_OUT_OF_MEMORY;
        }
-
-       if (dp_db_update_date(new_request->id, DP_DB_TABLE_LOG,
-                       DP_DB_COL_CREATE_TIME) < 0)
-               TRACE_ERROR("[CHECK SQL][%d]", id);
-       new_request->create_time = (int)time(NULL);
-
        *empty_slot = new_request;
        return DP_ERROR_NONE;
 }
@@ -247,8 +271,7 @@ dp_error_type dp_request_set_url(int id, dp_request *request, char *url)
                }
        } else {
                // check id in logging table.
-               dp_state_type state =
-                       dp_db_get_int_column(id, DP_DB_TABLE_LOG, DP_DB_COL_STATE);
+               dp_state_type state = dp_db_get_state(id);
                // check again from logging table
                if (state == DP_STATE_CONNECTING ||
                                state == DP_STATE_DOWNLOADING ||
@@ -262,6 +285,10 @@ dp_error_type dp_request_set_url(int id, dp_request *request, char *url)
                        (id, DP_DB_TABLE_REQUEST_INFO, DP_DB_COL_URL,
                        DP_DB_COL_TYPE_TEXT, url) < 0) {
                TRACE_ERROR("[CHECK SQL][%d]", id);
+               if (dp_db_is_full_error() == 0) {
+                       TRACE_ERROR("[SQLITE_FULL][%d]", id);
+                       return DP_ERROR_NO_SPACE;
+               }
                return DP_ERROR_OUT_OF_MEMORY;
        }
        return DP_ERROR_NONE;
@@ -283,8 +310,7 @@ dp_error_type dp_request_set_destination(int id, dp_request *request, char *dest
                }
        } else {
                // check id in logging table.
-               dp_state_type state =
-                       dp_db_get_int_column(id, DP_DB_TABLE_LOG, DP_DB_COL_STATE);
+               dp_state_type state = dp_db_get_state(id);
                // check again from logging table
                if (state == DP_STATE_CONNECTING ||
                        state == DP_STATE_DOWNLOADING ||
@@ -298,6 +324,10 @@ dp_error_type dp_request_set_destination(int id, dp_request *request, char *dest
                        (id, DP_DB_TABLE_REQUEST_INFO, DP_DB_COL_DESTINATION,
                        DP_DB_COL_TYPE_TEXT, dest) < 0) {
                TRACE_ERROR("[CHECK SQL][%d]", id);
+               if (dp_db_is_full_error() == 0) {
+                       TRACE_ERROR("[SQLITE_FULL][%d]", id);
+                       return DP_ERROR_NO_SPACE;
+               }
                return DP_ERROR_OUT_OF_MEMORY;
        }
        return DP_ERROR_NONE;
@@ -319,8 +349,7 @@ dp_error_type dp_request_set_filename(int id, dp_request *request, char *filenam
                }
        } else {
                // check id in logging table.
-               dp_state_type state =
-                       dp_db_get_int_column(id, DP_DB_TABLE_LOG, DP_DB_COL_STATE);
+               dp_state_type state = dp_db_get_state(id);
                // check again from logging table
                if (state == DP_STATE_CONNECTING ||
                        state == DP_STATE_DOWNLOADING ||
@@ -334,10 +363,177 @@ dp_error_type dp_request_set_filename(int id, dp_request *request, char *filenam
                        (id, DP_DB_TABLE_REQUEST_INFO, DP_DB_COL_FILENAME,
                        DP_DB_COL_TYPE_TEXT, filename) < 0) {
                TRACE_ERROR("[CHECK SQL][%d]", id);
+               if (dp_db_is_full_error() == 0) {
+                       TRACE_ERROR("[SQLITE_FULL][%d]", id);
+                       return DP_ERROR_NO_SPACE;
+               }
+               return DP_ERROR_OUT_OF_MEMORY;
+       }
+
+       TRACE_SECURE_DEBUG("ID [%d] Filename[%s]", id, filename);
+       return DP_ERROR_NONE;
+}
+
+dp_error_type dp_request_set_title(int id, dp_request *request, char *title)
+{
+       int length = 0;
+       if (!title || (length = strlen(title)) <= 1)
+               return DP_ERROR_INVALID_PARAMETER;
+
+       if (request != NULL) {
+               if (request->state == DP_STATE_COMPLETED) {
+                       TRACE_ERROR
+                       ("[ERROR][%d] now[%s]", id, dp_print_state(request->state));
+                       return DP_ERROR_INVALID_STATE;
+               }
+       } else {
+               // check id in logging table.
+               dp_state_type state = dp_db_get_state(id);
+               // check again from logging table
+               if (state == DP_STATE_COMPLETED) {
+                       TRACE_ERROR("[ERROR][%d] now[%s]", id, dp_print_state(state));
+                       return DP_ERROR_INVALID_STATE;
+               }
+       }
+
+       if (dp_db_replace_column
+                       (id, DP_DB_TABLE_NOTIFICATION, DP_DB_COL_TITLE,
+                       DP_DB_COL_TYPE_TEXT, title) < 0) {
+               TRACE_ERROR("[CHECK SQL][%d]", id);
+               if (dp_db_is_full_error() == 0) {
+                       TRACE_ERROR("[SQLITE_FULL][%d]", id);
+                       return DP_ERROR_NO_SPACE;
+               }
+               return DP_ERROR_OUT_OF_MEMORY;
+       }
+
+       TRACE_SECURE_DEBUG("ID [%d] title[%s]", id, title);
+       return DP_ERROR_NONE;
+}
+
+dp_error_type dp_request_set_bundle(int id, dp_request *request, int type, bundle_raw *b, unsigned length)
+{
+       char *column = NULL;
+       if (b == NULL || (length  < 1))
+               return DP_ERROR_INVALID_PARAMETER;
+
+       if (request != NULL) {
+               if (request->state == DP_STATE_COMPLETED) {
+                       TRACE_ERROR
+                       ("[ERROR][%d] now[%s]", id, dp_print_state(request->state));
+                       return DP_ERROR_INVALID_STATE;
+               }
+       } else {
+               // check id in logging table.
+               dp_state_type state = dp_db_get_state(id);
+               // check again from logging table
+               if (state == DP_STATE_COMPLETED) {
+                       TRACE_ERROR("[ERROR][%d] now[%s]", id, dp_print_state(state));
+                       return DP_ERROR_INVALID_STATE;
+               }
+       }
+
+       switch(type) {
+       case DP_NOTIFICATION_BUNDLE_TYPE_ONGOING:
+               column = DP_DB_COL_RAW_BUNDLE_ONGOING;
+               break;
+       case DP_NOTIFICATION_BUNDLE_TYPE_COMPLETE:
+               column = DP_DB_COL_RAW_BUNDLE_COMPLETE;
+               break;
+       case DP_NOTIFICATION_BUNDLE_TYPE_FAILED:
+               column = DP_DB_COL_RAW_BUNDLE_FAIL;
+               break;
+       default:
+               TRACE_ERROR("[CHECK TYPE][%d]", type);
+               return DP_ERROR_INVALID_PARAMETER;
+       }
+       if (dp_db_replace_blob_column
+                       (id, DP_DB_TABLE_NOTIFICATION, column, b, length) < 0) {
+               TRACE_ERROR("[CHECK SQL][%d]", id);
+               if (dp_db_is_full_error() == 0) {
+                       TRACE_ERROR("[SQLITE_FULL][%d]", id);
+                       return DP_ERROR_NO_SPACE;
+               }
+               return DP_ERROR_OUT_OF_MEMORY;
+       }
+
+       //TRACE_SECURE_DEBUG("ID [%d] title[%s]", id, title);
+       return DP_ERROR_NONE;
+}
+
+dp_error_type dp_request_set_description(int id, dp_request *request, char *description)
+{
+       int length = 0;
+       if (!description || (length = strlen(description)) <= 1)
+               return DP_ERROR_INVALID_PARAMETER;
+
+       if (request != NULL) {
+               if (request->state == DP_STATE_COMPLETED) {
+                       TRACE_ERROR
+                       ("[ERROR][%d] now[%s]", id, dp_print_state(request->state));
+                       return DP_ERROR_INVALID_STATE;
+               }
+       } else {
+               // check id in logging table.
+               dp_state_type state = dp_db_get_state(id);
+               // check again from logging table
+               if (state == DP_STATE_COMPLETED) {
+                       TRACE_ERROR("[ERROR][%d] now[%s]", id, dp_print_state(state));
+                       return DP_ERROR_INVALID_STATE;
+               }
+       }
+
+       if (dp_db_replace_column
+                       (id, DP_DB_TABLE_NOTIFICATION, DP_DB_COL_DESCRIPTION,
+                       DP_DB_COL_TYPE_TEXT, description) < 0) {
+               TRACE_ERROR("[CHECK SQL][%d]", id);
+               if (dp_db_is_full_error() == 0) {
+                       TRACE_ERROR("[SQLITE_FULL][%d]", id);
+                       return DP_ERROR_NO_SPACE;
+               }
                return DP_ERROR_OUT_OF_MEMORY;
        }
 
-       TRACE_INFO("ID [%d] Filename[%s]", id, filename);
+       TRACE_SECURE_DEBUG("ID [%d] description[%s]", id, description);
+       return DP_ERROR_NONE;
+}
+
+dp_error_type dp_request_set_noti_type(int id, dp_request *request, unsigned type)
+{
+       if (request != NULL) {
+               if (request->state == DP_STATE_COMPLETED) {
+                       TRACE_ERROR
+                       ("[ERROR][%d] now[%s]", id, dp_print_state(request->state));
+                       return DP_ERROR_INVALID_STATE;
+               }
+       } else {
+               // check id in logging table.
+               dp_state_type state = dp_db_get_state(id);
+               // check again from logging table
+               if (state == DP_STATE_COMPLETED) {
+                       TRACE_ERROR("[ERROR][%d] now[%s]", id, dp_print_state(state));
+                       return DP_ERROR_INVALID_STATE;
+               }
+       }
+
+       if (dp_db_replace_column
+                       (id, DP_DB_TABLE_NOTIFICATION, DP_DB_COL_NOTI_TYPE,
+                       DP_DB_COL_TYPE_INT, &type) < 0) {
+               TRACE_ERROR("[CHECK SQL][%d]", id);
+               if (dp_db_is_full_error() == 0) {
+                       TRACE_ERROR("[SQLITE_FULL][%d]", id);
+                       return DP_ERROR_NO_SPACE;
+               }
+               return DP_ERROR_OUT_OF_MEMORY;
+       }
+       if (request)
+       {
+               if(!type)
+                       request->auto_notification = 0;
+               else
+                       request->auto_notification = 1;
+       }
+       TRACE_SECURE_DEBUG("ID [%d] enable[%d]", id, type);
        return DP_ERROR_NONE;
 }
 
@@ -351,8 +547,7 @@ dp_error_type dp_request_set_notification(int id, dp_request *request, unsigned
                }
        } else {
                // check id in logging table.
-               dp_state_type state =
-                       dp_db_get_int_column(id, DP_DB_TABLE_LOG, DP_DB_COL_STATE);
+               dp_state_type state = dp_db_get_state(id);
                // check again from logging table
                if (state == DP_STATE_COMPLETED) {
                        TRACE_ERROR("[ERROR][%d] now[%s]", id, dp_print_state(state));
@@ -384,8 +579,7 @@ dp_error_type dp_request_set_auto_download(int id, dp_request *request, unsigned
                }
        } else {
                // check id in logging table.
-               dp_state_type state =
-                       dp_db_get_int_column(id, DP_DB_TABLE_LOG, DP_DB_COL_STATE);
+               dp_state_type state = dp_db_get_state(id);
                // check again from logging table
                if (state == DP_STATE_COMPLETED) {
                        TRACE_ERROR("[ERROR][%d] now[%s]", id, dp_print_state(state));
@@ -407,8 +601,7 @@ dp_error_type dp_request_set_state_event(int id, dp_request *request, unsigned e
 {
        if (request == NULL) {
                // check id in logging table.
-               dp_state_type state =
-                       dp_db_get_int_column(id, DP_DB_TABLE_LOG, DP_DB_COL_STATE);
+               dp_state_type state = dp_db_get_state(id);
 
                if (state == DP_STATE_DOWNLOADING ||
                        state == DP_STATE_COMPLETED) {
@@ -425,7 +618,7 @@ dp_error_type dp_request_set_state_event(int id, dp_request *request, unsigned e
                return DP_ERROR_OUT_OF_MEMORY;
        }
        // update memory
-       if (request)
+       if (request != NULL)
                request->state_cb = enable;
        return DP_ERROR_NONE;
 }
@@ -434,8 +627,7 @@ dp_error_type dp_request_set_progress_event(int id, dp_request *request, unsigne
 {
        if (request == NULL) {
                // check id in logging table.
-               dp_state_type state =
-                       dp_db_get_int_column(id, DP_DB_TABLE_LOG, DP_DB_COL_STATE);
+               dp_state_type state = dp_db_get_state(id);
 
                if (state == DP_STATE_DOWNLOADING ||
                        state == DP_STATE_COMPLETED) {
@@ -469,8 +661,7 @@ dp_error_type dp_request_set_network_type(int id, dp_request *request, int type)
                }
        } else {
                // check id in logging table.
-               dp_state_type state =
-                       dp_db_get_int_column(id, DP_DB_TABLE_LOG, DP_DB_COL_STATE);
+               dp_state_type state = dp_db_get_state(id);
                // check again from logging table
                if (state == DP_STATE_CONNECTING ||
                        state == DP_STATE_DOWNLOADING ||
@@ -493,7 +684,7 @@ dp_error_type dp_request_set_network_type(int id, dp_request *request, int type)
        return DP_ERROR_NONE;
 }
 
-char *dp_request_get_url(int id, dp_request *request, dp_error_type *errorcode)
+char *dp_request_get_url(int id, dp_error_type *errorcode)
 {
        char *url = NULL;
        url = dp_db_get_text_column
@@ -529,6 +720,55 @@ char *dp_request_get_filename(int id, dp_request *request, dp_error_type *errorc
        return filename;
 }
 
+char *dp_request_get_title(int id, dp_request *request, dp_error_type *errorcode)
+{
+       char *title = NULL;
+       title = dp_db_get_text_column
+                               (id, DP_DB_TABLE_NOTIFICATION, DP_DB_COL_TITLE);
+       if (title == NULL) {
+               *errorcode = DP_ERROR_NO_DATA;
+               return NULL;
+       }
+       return title;
+}
+
+bundle_raw *dp_request_get_bundle(int id, dp_request *request, dp_error_type *errorcode, char* column, int *length)
+{
+       void *blob_data = NULL;
+       blob_data = dp_db_get_blob_column
+                               (id, DP_DB_TABLE_NOTIFICATION, column, length);
+       if (blob_data == NULL) {
+               *errorcode = DP_ERROR_NO_DATA;
+               return NULL;
+       }
+       return (bundle_raw*)blob_data;
+}
+
+
+char *dp_request_get_description(int id, dp_request *request, dp_error_type *errorcode)
+{
+       char *description = NULL;
+       description = dp_db_get_text_column
+                               (id, DP_DB_TABLE_NOTIFICATION, DP_DB_COL_DESCRIPTION);
+       if (description == NULL) {
+               *errorcode = DP_ERROR_NO_DATA;
+               return NULL;
+       }
+       return description;
+}
+
+int dp_request_get_noti_type(int id, dp_request *request, dp_error_type *errorcode)
+{
+       int type = -1;
+       type = dp_db_get_int_column
+                               (id, DP_DB_TABLE_NOTIFICATION, DP_DB_COL_NOTI_TYPE);
+       if (type == -1)
+               *errorcode = DP_ERROR_NO_DATA;
+       return type;
+}
+
+
+
 char *dp_request_get_contentname(int id, dp_request *request, dp_error_type *errorcode)
 {
        char *content = NULL;
@@ -589,6 +829,18 @@ char *dp_request_get_mimetype(int id, dp_request *request, dp_error_type *errorc
        return mimetype;
 }
 
+char *dp_request_get_pkg_name(int id, dp_request *request, dp_error_type *errorcode)
+{
+       char *pkg_name = NULL;
+       pkg_name = dp_db_get_text_column
+                               (id, DP_DB_TABLE_LOG, DP_DB_COL_PACKAGENAME);
+       if (pkg_name == NULL) {
+               *errorcode = DP_ERROR_NO_DATA;
+               return NULL;
+       }
+       return pkg_name;
+}
+
 dp_request *dp_request_load_from_log(int id, dp_error_type *errorcode)
 {
        dp_request *request = NULL;
@@ -608,3 +860,82 @@ dp_request *dp_request_load_from_log(int id, dp_error_type *errorcode)
        return request;
 }
 
+
+void dp_request_state_response(dp_request *request)
+{
+       if (request == NULL) {
+               return ;
+       }
+
+       TRACE_INFO("[INFO][%d] state:%s error:%s", request->id,
+                       dp_print_state(request->state),
+                       dp_print_errorcode(request->error));
+
+       if (dp_db_request_update_status(request->id, request->state,
+                       request->error) < 0)
+               TRACE_ERROR("[ERROR][%d][SQL]", request->id);
+
+       if (request->group != NULL && request->group->event_socket >= 0 &&
+                       request->state_cb == 1) {
+               dp_ipc_send_event(request->group->event_socket, request->id,
+                       request->state, request->error, 0);
+       }
+
+       if (request->state == DP_STATE_DOWNLOADING) {
+               if (request->auto_notification == 1 &&
+                               request->packagename != NULL) {
+                       if (request->noti_priv_id != -1) {
+                               dp_update_downloadinginfo_notification
+                                       (request->noti_priv_id,
+                                       (double)request->received_size,
+                                       (double)request->file_size);
+                       } else {
+                               request->noti_priv_id = dp_set_downloadinginfo_notification
+                                       (request->id, request->packagename);
+                       }
+               } else {
+                       int noti_type = dp_db_get_int_column(request->id,
+                                       DP_DB_TABLE_NOTIFICATION, DP_DB_COL_NOTI_TYPE);
+                       if (noti_type == DP_NOTIFICATION_TYPE_ALL &&
+                                       request->packagename != NULL) {
+                               if (request->noti_priv_id != -1) {
+                                       dp_update_downloadinginfo_notification
+                                               (request->noti_priv_id,
+                                               (double)request->received_size,
+                                               (double)request->file_size);
+                               } else {
+                                       request->noti_priv_id = dp_set_downloadinginfo_notification
+                                               (request->id, request->packagename);
+                               }
+                       }
+               }
+               request->start_time = (int)time(NULL);
+               request->pause_time = 0;
+               request->stop_time = 0;
+       } else if (request->state == DP_STATE_PAUSED) {
+               if (request->group != NULL)
+                       request->group->queued_count--;
+               request->pause_time = (int)time(NULL);
+       } else {
+               if (request->group != NULL )
+                       request->group->queued_count--;
+
+               if (request->auto_notification == 1 &&
+                               request->packagename != NULL) {
+                       request->noti_priv_id = dp_set_downloadedinfo_notification
+                                       (request->noti_priv_id, request->id,
+                                       request->packagename, request->state);
+
+               } else {
+                       int noti_type = dp_db_get_int_column(request->id,
+                                       DP_DB_TABLE_NOTIFICATION, DP_DB_COL_NOTI_TYPE);
+                       if (noti_type > DP_NOTIFICATION_TYPE_NONE &&
+                                       request->packagename != NULL)
+                               request->noti_priv_id = dp_set_downloadedinfo_notification
+                                               (request->noti_priv_id, request->id,
+                                               request->packagename, request->state);
+               }
+
+               request->stop_time = (int)time(NULL);
+       }
+}
index e2c4732..ad39ee8 100755 (executable)
@@ -30,7 +30,6 @@
 
 dp_group_slots *dp_client_group_slots_new(int size)
 {
-       TRACE_INFO("");
        dp_group_slots *slots = NULL;
        if (size <= 0)
                return NULL;
@@ -41,19 +40,20 @@ dp_group_slots *dp_client_group_slots_new(int size)
 
 dp_request_slots *dp_request_slots_new(int size)
 {
-       TRACE_INFO("");
+       int i = 0;
        dp_request_slots *slots = NULL;
        if (size <= 0)
                return NULL;
        slots = (dp_request_slots *) calloc(size,
                        sizeof(dp_request_slots));
+       for (; i < size; i++)
+               CLIENT_MUTEX_INIT(&slots[i].mutex, NULL);
        return slots;
 }
 
 void dp_request_init(dp_request *request)
 {
-       TRACE_INFO("");
-       if (!request)
+       if (request == NULL)
                return ;
 
        request->id = -1;
@@ -84,30 +84,33 @@ dp_request *dp_request_new()
                        sizeof(dp_request));
        if (!request)
                return NULL;
-       CLIENT_MUTEX_INIT(&(request->mutex), NULL);
        dp_request_init(request);
        return request;
 }
 
-int dp_request_free(dp_request *request)
+int dp_request_slot_free(dp_request_slots *request_slot)
 {
-       TRACE_INFO("");
+       if (request_slot == NULL)
+               return -1;
+       CLIENT_MUTEX_LOCK(&request_slot->mutex);
+       dp_request_free(request_slot->request);
+       request_slot->request = NULL;
+       CLIENT_MUTEX_UNLOCK(&request_slot->mutex);
+       return 0;
+}
 
-       if (!request)
+int dp_request_free(dp_request *request)
+{
+       if (request == NULL)
                return -1;
-       CLIENT_MUTEX_LOCK(&(request->mutex));
-       if (request->packagename)
-               free(request->packagename);
+       free(request->packagename);
        dp_request_init(request);
-       CLIENT_MUTEX_UNLOCK(&(request->mutex));
-       CLIENT_MUTEX_DESTROY(&(request->mutex));
        free(request);
        return 0;
 }
 
 int dp_client_group_free(dp_client_group *group)
 {
-       TRACE_INFO("");
        if (group != NULL) {
                if (group->cmd_socket > 0)
                        dp_socket_free(group->cmd_socket);
@@ -117,6 +120,7 @@ int dp_client_group_free(dp_client_group *group)
                group->event_socket = -1;
                group->queued_count = 0;
                free(group->pkgname);
+               free(group->smack_label);
                free(group);
        }
        return 0;
@@ -124,7 +128,6 @@ int dp_client_group_free(dp_client_group *group)
 
 int dp_client_group_slots_free(dp_group_slots *slots, int size)
 {
-       TRACE_INFO("");
        int i = 0;
        if (slots) {
                for (; i < size; i++) {
@@ -140,13 +143,12 @@ int dp_client_group_slots_free(dp_group_slots *slots, int size)
 
 int dp_request_slots_free(dp_request_slots *slots, int size)
 {
-       TRACE_INFO("");
        int i = 0;
-       if (slots) {
+       if (slots != NULL) {
                for (; i < size; i++) {
-                       if (slots->request)
-                               dp_request_free(slots->request);
-                       slots->request = NULL;
+                       dp_request_free(slots[i].request);
+                       slots[i].request = NULL;
+                       CLIENT_MUTEX_DESTROY(&slots[i].mutex);
                }
                free(slots);
        }
@@ -164,8 +166,9 @@ int dp_get_request_count(dp_request_slots *slots)
        if (!slots)
                return -1;
 
-       for (i = 0; i < DP_MAX_REQUEST; i++)
-               if (slots[i].request)
+       for (i = 0; i < DP_MAX_REQUEST; i++) {
+               if (slots[i].request != NULL)
                        count++;
+       }
        return count;
 }
index 7dca271..7feabf8 100755 (executable)
@@ -26,7 +26,7 @@
 #include <sys/socket.h>
 #include <sys/un.h>
 #include <sys/stat.h>
-
+#include <systemd/sd-daemon.h>
 #include <signal.h>
 
 #include "download-provider.h"
@@ -79,6 +79,9 @@ int dp_ipc_send_event(int fd, int id, dp_state_type state,
 char *dp_ipc_read_string(int fd)
 {
        unsigned length = 0;
+       size_t recv_size = 0;
+       unsigned remain_size = 0;
+       size_t buffer_size = 0;
        char *str = NULL;
 
        if (fd < 0) {
@@ -87,7 +90,8 @@ char *dp_ipc_read_string(int fd)
        }
 
        // read flexible URL from client.
-       if (read(fd, &length, sizeof(unsigned)) < 0) {
+       ssize_t recv_bytes = read(fd, &length, sizeof(unsigned));
+       if (recv_bytes < 0) {
                TRACE_STRERROR("[ERROR] read FD[%d] length[%d]", fd, length);
                return NULL;
        }
@@ -96,16 +100,105 @@ char *dp_ipc_read_string(int fd)
                return NULL;
        }
        str = (char *)calloc((length + 1), sizeof(char));
-       if (read(fd, str, length * sizeof(char)) < 0) {
-               TRACE_STRERROR("[ERROR] read FD[%d]", fd);
+       if (str == NULL) {
+               TRACE_STRERROR("[ERROR] calloc length:%d FD[%d]", length, fd);
+               return NULL;
+       }
+       remain_size = length;
+       do {
+               buffer_size = 0;
+               if (remain_size > DP_DEFAULT_BUFFER_SIZE)
+                       buffer_size = DP_DEFAULT_BUFFER_SIZE;
+               else
+                       buffer_size = remain_size;
+               recv_size = (size_t)read(fd, str + (int)(length - remain_size),
+                               buffer_size * sizeof(char));
+               if (recv_size > DP_DEFAULT_BUFFER_SIZE) {
+                       recv_size = -1;
+                       break;
+               }
+               if (recv_size > 0)
+                       remain_size = remain_size - (unsigned)recv_size;
+       } while (recv_size > 0 && remain_size > 0);
+
+       if (recv_size == 0) {
+               TRACE_STRERROR("[ERROR] closed peer:%d", fd);
                free(str);
-               str = NULL;
                return NULL;
        }
        str[length] = '\0';
        return str;
 }
 
+
+// 0 : Socket Error
+// -1 : Invalid type
+unsigned dp_ipc_read_bundle(int fd, int *type, bundle_raw **b)
+{
+       unsigned length = 0;
+       size_t recv_size = 0;
+       unsigned remain_size = 0;
+       size_t buffer_size = 0;
+       bundle_raw *b_raw = NULL;
+
+       if (fd < 0) {
+               TRACE_ERROR("[ERROR] CHECK FD[%d]", fd);
+               return 0;
+       }
+
+       // read flexible URL from client.
+       ssize_t recv_bytes = read(fd, type, sizeof(int));
+       if (recv_bytes < 0) {
+               TRACE_STRERROR("[ERROR] read FD[%d] type[%d]", fd, type);
+               return 0;
+       }
+       if ((*type) != DP_NOTIFICATION_BUNDLE_TYPE_ONGOING &&
+                       (*type) !=  DP_NOTIFICATION_BUNDLE_TYPE_COMPLETE &&
+                       (*type) !=  DP_NOTIFICATION_BUNDLE_TYPE_FAILED) {
+               TRACE_ERROR("[NOTI TYPE] [%d]", *type);
+               return -1;
+       }
+       // read flexible URL from client.
+       recv_bytes = read(fd, &length, sizeof(unsigned));
+       if (recv_bytes < 0) {
+               TRACE_STRERROR("[ERROR] read FD[%d] length[%d]", fd, length);
+               return 0;
+       }
+       if (length < 1 || length > DP_MAX_URL_LEN) {
+               TRACE_ERROR("[STRING LEGNTH] [%d]", length);
+               return 0;
+       }
+       b_raw = (bundle_raw *)calloc(length, 1);
+       if (b_raw == NULL) {
+               TRACE_STRERROR("[ERROR] calloc length:%d FD[%d]", length, fd);
+               return 0;
+       }
+       remain_size = length;
+       do {
+               buffer_size = 0;
+               if (remain_size > DP_DEFAULT_BUFFER_SIZE)
+                       buffer_size = DP_DEFAULT_BUFFER_SIZE;
+               else
+                       buffer_size = remain_size;
+               recv_size = (size_t)read(fd, b_raw + (int)(length - remain_size),
+                               buffer_size * sizeof(char));
+               if (recv_size > DP_DEFAULT_BUFFER_SIZE) {
+                       recv_size = -1;
+                       break;
+               }
+               if (recv_size > 0)
+                       remain_size = remain_size - (unsigned)recv_size;
+       } while (recv_size > 0 && remain_size > 0);
+
+       if (recv_size <= 0) {
+               TRACE_STRERROR("[ERROR] closed peer:%d", fd);
+               bundle_free_encoded_rawdata(&b_raw);
+               return 0;
+       }
+       *b = b_raw;
+       return length;
+}
+
 // keep the order/ unsigned , str
 int dp_ipc_send_string(int fd, const char *str)
 {
@@ -136,6 +229,32 @@ int dp_ipc_send_string(int fd, const char *str)
        return 0;
 }
 
+int dp_ipc_send_bundle(int fd, bundle_raw *b, unsigned length)
+{
+       if (fd < 0) {
+               TRACE_ERROR("[ERROR] CHECK FD[%d]", fd);
+               return -1;
+       }
+       if (b == NULL) {
+               TRACE_ERROR("[ERROR] CHECK STRING FD[%d]", fd);
+               return -1;
+       }
+
+       if (length < 1) {
+               TRACE_ERROR("[ERROR] CHECK LENGTH FD[%d]", fd);
+               return -1;
+       }
+       if (fd >= 0 && write(fd, &length, sizeof(unsigned)) <= 0) {
+               TRACE_STRERROR("[ERROR] read FD[%d] length[%d]", fd, length);
+               return -1;
+       }
+       if (fd >= 0 && write(fd, b, length) <= 0) {
+               TRACE_STRERROR("[ERROR] write FD[%d]", fd);
+               return -1;
+       }
+       return 0;
+}
+
 int dp_ipc_send_custom_type(int fd, void *value, size_t type_size)
 {
        if (fd < 0) {
@@ -164,7 +283,8 @@ int dp_ipc_read_custom_type(int fd, void *value, size_t type_size)
                return -1;
        }
 
-       if (read(fd, value, type_size) < 0) {
+       ssize_t recv_bytes = read(fd, value, type_size);
+       if (recv_bytes < 0) {
                TRACE_STRERROR("[ERROR] read FD[%d]", fd);
                return -1;
        }
@@ -176,40 +296,53 @@ int dp_accept_socket_new()
        int sockfd = -1;
        struct sockaddr_un listenaddr;
 
-       if ((sockfd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
-               TRACE_STRERROR("failed to create socket");
+       int n = sd_listen_fds(1);
+       if (n > 1) {
+               TRACE_STRERROR("too many file descriptors received");
                return -1;
-       }
+       } else if (n == 1) {
+               int r;
+               if ((r = sd_is_socket_unix(SD_LISTEN_FDS_START, SOCK_STREAM, 1, DP_IPC, 0)) <= 0) {
+                       TRACE_STRERROR("passed systemd file descriptor is of wrong type");
+                       return -1;
+               }
+               sockfd = SD_LISTEN_FDS_START + 0;
+       } else {
+               if ((sockfd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
+                       TRACE_STRERROR("failed to create socket");
+                       return -1;
+               }
 
-       bzero(&listenaddr, sizeof(listenaddr));
-       listenaddr.sun_family = AF_UNIX;
-       strcpy(listenaddr.sun_path, DP_IPC);
+               bzero(&listenaddr, sizeof(listenaddr));
+               listenaddr.sun_family = AF_UNIX;
+               strcpy(listenaddr.sun_path, DP_IPC);
 
-       if (bind(sockfd, (struct sockaddr *)&listenaddr, sizeof listenaddr) !=
-               0) {
-               TRACE_STRERROR("[CRITICAL] bind");
-               close(sockfd);
-               return -1;
-       }
+               if (bind(sockfd, (struct sockaddr *)&listenaddr, sizeof listenaddr) !=
+                       0) {
+                       TRACE_STRERROR("[CRITICAL] bind");
+                       close(sockfd);
+                       return -1;
+               }
 
-       if (chmod(listenaddr.sun_path, 0777) < 0) {
-               TRACE_STRERROR("[CRITICAL] chmod");
-               close(sockfd);
-               return -1;
-       }
+               if (chmod(listenaddr.sun_path, 0777) < 0) {
+                       TRACE_STRERROR("[CRITICAL] chmod");
+                       close(sockfd);
+                       return -1;
+               }
 
-       // need 3 socket per a group
-       if (listen(sockfd, DP_MAX_GROUP * 3) != 0) {
-               TRACE_STRERROR("[CRITICAL] listen");
-               close(sockfd);
-               return -1;
+               // need 3 socket per a group
+               if (listen(sockfd, DP_MAX_GROUP * 3) != 0) {
+                       TRACE_STRERROR("[CRITICAL] listen");
+                       close(sockfd);
+                       return -1;
+               }
        }
        return sockfd;
 }
 
 int dp_socket_free(int sockfd)
 {
-       TRACE_INFO("[%d]", sockfd);
+       TRACE_DEBUG("[%d]", sockfd);
        if (sockfd < 0)
                return -1;
        shutdown(sockfd, 0);
index a145ce0..b82618d 100755 (executable)
@@ -26,6 +26,8 @@
 
 #include <signal.h>
 
+#include <pthread.h>
+
 #include "download-provider.h"
 #include "download-provider-log.h"
 #include "download-provider-config.h"
@@ -73,14 +75,19 @@ static unsigned __get_active_count(dp_request_slots *requests)
        unsigned count = 0;
        unsigned i = 0;
 
-       if (!requests)
+       if (requests == NULL)
                return 0;
 
        for (i = 0; i < DP_MAX_REQUEST; i++) {
-               if (requests[i].request) {
-                       if (requests[i].request->state == DP_STATE_CONNECTING ||
-                               requests[i].request->state == DP_STATE_DOWNLOADING)
-                               count++;
+               int locked = pthread_mutex_trylock(&requests[i].mutex);
+               // locking failure means it used by other thread.
+               if (locked == 0) {
+                       if (requests[i].request != NULL) {
+                               if (requests[i].request->state == DP_STATE_CONNECTING ||
+                                       requests[i].request->state == DP_STATE_DOWNLOADING)
+                                       count++;
+                       }
+                       CLIENT_MUTEX_UNLOCK(&requests[i].mutex);
                }
        }
        return count;
@@ -95,19 +102,24 @@ static int __get_oldest_request_with_network(dp_request_slots *requests, dp_stat
        oldest_time++; // most last time
        int oldest_index = -1;
 
-       if (!requests)
+       if (requests == NULL)
                return -1;
 
        for (i = 0; i < DP_MAX_REQUEST; i++) {
-               if (requests[i].request != NULL) {
-                       if (requests[i].request->state == state &&
-                               requests[i].request->start_time > 0 &&
-                               requests[i].request->start_time < oldest_time &&
-                               __is_matched_network
-                                       (now_state, requests[i].request->network_type) == 0) {
-                               oldest_time = requests[i].request->start_time;
-                               oldest_index = i;
+               int locked = pthread_mutex_trylock(&requests[i].mutex);
+               // locking failure means it used by other thread.
+               if (locked == 0) {
+                       if (requests[i].request != NULL) {
+                               if (requests[i].request->state == state &&
+                                       requests[i].request->start_time > 0 &&
+                                       requests[i].request->start_time < oldest_time &&
+                                       __is_matched_network(now_state,
+                                                       requests[i].request->network_type) == 0) {
+                                       oldest_time = requests[i].request->start_time;
+                                       oldest_index = i;
+                               }
                        }
+                       CLIENT_MUTEX_UNLOCK(&requests[i].mutex);
                }
        }
        return oldest_index;
@@ -123,11 +135,21 @@ static void *__request_download_start_agent(void *args)
        dp_error_type errcode = DP_ERROR_NONE;
 
        dp_request_slots *request_slot = (dp_request_slots *) args;
-       if (request_slot == NULL || request_slot->request == NULL) {
-               TRACE_ERROR("[NULL-CHECK] download_clientinfo_slot");
+       if (request_slot == NULL) {
+               TRACE_ERROR("[NULL-CHECK] request_slot");
+               pthread_exit(NULL);
+               return 0;
+       }
+
+       CLIENT_MUTEX_LOCK(&request_slot->mutex);
+
+       if (request_slot->request == NULL) {
+               TRACE_ERROR("[NULL-CHECK] request");
+               CLIENT_MUTEX_UNLOCK(&request_slot->mutex);
                pthread_exit(NULL);
                return 0;
        }
+
        dp_request *request = request_slot->request;
 
        if (dp_is_alive_download(request->agent_id)) {
@@ -136,8 +158,6 @@ static void *__request_download_start_agent(void *args)
                // call agent start function
                errcode = dp_start_agent_download(request_slot);
        }
-
-       CLIENT_MUTEX_LOCK(&(request->mutex));
        // send to state callback.
        if (errcode == DP_ERROR_NONE) {
                // CONNECTING
@@ -156,22 +176,39 @@ static void *__request_download_start_agent(void *args)
                // FAILED
                request->state = DP_STATE_FAILED;
                request->error = DP_ERROR_CONNECTION_FAILED;
-               dp_ipc_send_event(request->group->event_socket,
-                       request->id, request->state, request->error, 0);
-               dp_thread_queue_manager_wake_up();
+               if (request->group != NULL &&
+                       request->group->event_socket >= 0) {
+                       dp_ipc_send_event(request->group->event_socket,
+                               request->id, request->state, request->error, 0);
+               }
+       } else if (errcode == DP_ERROR_INVALID_STATE) {
+               // API FAILED
+               request->error = DP_ERROR_INVALID_STATE;
+               if (request->group != NULL &&
+                       request->group->event_socket >= 0) {
+                       dp_ipc_send_event(request->group->event_socket,
+                               request->id, request->state, request->error, 0);
+               }
        } else {
                request->state = DP_STATE_FAILED;
                request->error = errcode;
-               dp_ipc_send_event(request->group->event_socket,
-                       request->id, request->state, request->error, 0);
-               dp_thread_queue_manager_wake_up();
+               if (request->group != NULL &&
+                       request->group->event_socket >= 0) {
+                       dp_ipc_send_event(request->group->event_socket,
+                               request->id, request->state, request->error, 0);
+               }
        }
-       if (dp_db_set_column
-                       (request->id, DP_DB_TABLE_LOG, DP_DB_COL_STATE,
-                       DP_DB_COL_TYPE_INT, &request->state) < 0)
+       if (dp_db_request_update_status(request->id, request->state, request->error) < 0) {
                TRACE_ERROR("[ERROR][%d][SQL]", request->id);
+       }
+
+       CLIENT_MUTEX_UNLOCK(&request_slot->mutex);
+
+       if (errcode == DP_ERROR_NONE) {
+               TRACE_DEBUG("try other requests -----------------");
+               dp_thread_queue_manager_wake_up();
+       }
 
-       CLIENT_MUTEX_UNLOCK(&(request->mutex));
        pthread_exit(NULL);
        return 0;
 }
@@ -186,7 +223,6 @@ static int __request_download_start_thread(dp_request_slots *request_slot)
        pthread_t thread_pid;
        pthread_attr_t thread_attr;
 
-       TRACE_INFO("");
        if (request_slot == NULL || request_slot->request == NULL) {
                TRACE_ERROR("[CRITICAL] Invalid Address");
                return -1;
@@ -220,7 +256,6 @@ static int __request_download_start_thread(dp_request_slots *request_slot)
 
 void dp_thread_queue_manager_wake_up()
 {
-       TRACE_INFO("");
        CLIENT_MUTEX_LOCK(&(g_dp_queue_mutex));
        pthread_cond_signal(&g_dp_queue_cond);
        CLIENT_MUTEX_UNLOCK(&(g_dp_queue_mutex));
@@ -236,8 +271,6 @@ void *dp_thread_queue_manager(void *arg)
        dp_client_group *group = NULL;
        dp_request *request = NULL;
 
-       TRACE_INFO("Start Queue Thread");
-
        dp_privates *privates = (dp_privates*)arg;
        if (!privates) {
                TRACE_ERROR("[CRITICAL] Invalid Address");
@@ -252,10 +285,12 @@ void *dp_thread_queue_manager(void *arg)
                CLIENT_MUTEX_LOCK(&(g_dp_queue_mutex));
                pthread_cond_wait(&g_dp_queue_cond, &g_dp_queue_mutex);
 
+               // request thread response instantly
+               CLIENT_MUTEX_UNLOCK(&(g_dp_queue_mutex));
+
                if (privates == NULL || privates->requests == NULL ||
                        privates->listen_fd < 0) {
-                       TRACE_INFO("Terminate Thread");
-                       CLIENT_MUTEX_UNLOCK(&(g_dp_queue_mutex));
+                       TRACE_DEBUG("Terminate Thread");
                        break;
                }
 
@@ -275,13 +310,15 @@ void *dp_thread_queue_manager(void *arg)
 
                if (privates->network_status == DP_NETWORK_TYPE_OFF &&
                        privates->is_connected_wifi_direct == 0) {
-                       TRACE_INFO("[CHECK NETWORK STATE]");
-                       CLIENT_MUTEX_UNLOCK(&(g_dp_queue_mutex));
+                       TRACE_DEBUG("[CHECK NETWORK STATE]");
                        continue;
                }
 
                active_count = __get_active_count(privates->requests);
 
+               TRACE_DEBUG("Status Queue: now active[%d] max[%d]",
+                                       active_count, DP_MAX_DOWNLOAD_AT_ONCE);
+
                // Start Conditions
                // 1. state is QUEUED
                // 2. 1 QUEUED per 1 Group : need not to check max limitation.!!
@@ -294,8 +331,9 @@ void *dp_thread_queue_manager(void *arg)
                // guarantee 1 instant download per 1 group
                if (active_count >= DP_MAX_DOWNLOAD_AT_ONCE) {
                        for (i = 0; i < DP_MAX_REQUEST; i++) {
+                               CLIENT_MUTEX_LOCK(&privates->requests[i].mutex);
                                request = privates->requests[i].request;
-                               if (request && request->state == DP_STATE_QUEUED) {
+                               if (request != NULL && request->state == DP_STATE_QUEUED) {
                                        group = privates->requests[i].request->group;
                                        if (group && group->queued_count == 1) {
                                                if (__is_matched_network
@@ -305,20 +343,20 @@ void *dp_thread_queue_manager(void *arg)
                                                                request->network_type ==
                                                                        DP_NETWORK_TYPE_WIFI_DIRECT)) {
                                                        if (__request_download_start_thread(&privates->requests[i]) == 0) {
-                                                               TRACE_INFO
+                                                               TRACE_DEBUG
                                                                        ("[Guarantee Intant Download] Group [%s]", group->pkgname);
                                                                active_count++;
                                                        }
                                                }
                                        }
                                }
+                               CLIENT_MUTEX_UNLOCK(&privates->requests[i].mutex);
                        }
                }
 
                if (active_count >= DP_MAX_DOWNLOAD_AT_ONCE) {
-                       TRACE_INFO("[BUSY] Active[%d] Max[%d]",
+                       TRACE_DEBUG("[BUSY] Active[%d] Max[%d]",
                                active_count, DP_MAX_DOWNLOAD_AT_ONCE);
-                       CLIENT_MUTEX_UNLOCK(&(g_dp_queue_mutex));
                        continue;
                }
 
@@ -332,8 +370,7 @@ void *dp_thread_queue_manager(void *arg)
                                i = __get_oldest_request_with_network(privates->requests,
                                                DP_STATE_QUEUED, DP_NETWORK_TYPE_WIFI_DIRECT);
                                if (i >= 0) {
-                                       TRACE_INFO("Found WIFI-Direct request %d", i);
-                                       request = privates->requests[i].request;
+                                       TRACE_DEBUG("Found WIFI-Direct request %d", i);
                                        if (__request_download_start_thread(&privates->requests[i]) == 0)
                                                active_count++;
                                        continue;
@@ -344,18 +381,16 @@ void *dp_thread_queue_manager(void *arg)
                        i = __get_oldest_request_with_network(privates->requests,
                                        DP_STATE_QUEUED, privates->network_status);
                        if (i < 0) {
-                               TRACE_INFO
+                               TRACE_DEBUG
                                        ("No Request now active[%d] max[%d]",
                                        active_count, DP_MAX_DOWNLOAD_AT_ONCE);
                                break;
                        }
-                       TRACE_INFO("QUEUE Status now %d active %d/%d", i,
+                       TRACE_DEBUG("QUEUE Status now %d active %d/%d", i,
                                active_count, DP_MAX_DOWNLOAD_AT_ONCE);
-                       request = privates->requests[i].request;
                        __request_download_start_thread(&privates->requests[i]);
                        active_count++;
                }
-               CLIENT_MUTEX_UNLOCK(&(g_dp_queue_mutex));
        }
        pthread_cond_destroy(&g_dp_queue_cond);
        pthread_exit(NULL);
index e8262b2..1f1e151 100755 (executable)
 #include <sys/socket.h>
 #include <sys/un.h>
 #include <sys/stat.h>
+#include <sys/types.h>
 
 #include <signal.h>
 
 #include <app_manager.h>
+#include <sys/smack.h>
+#include <bundle.h>
 
 #include "download-provider.h"
 #include "download-provider-log.h"
@@ -38,7 +41,9 @@
 #include "download-provider-db.h"
 #include "download-provider-queue.h"
 #include "download-provider-request.h"
+#include "download-provider-network.h"
 #include "download-provider-da-interface.h"
+#include "download-provider-notification.h"
 
 void dp_terminate(int signo);
 
@@ -132,6 +137,22 @@ static char *__print_command(dp_command_type cmd)
                        return "SET_COMMAND_SOCKET";
                case DP_CMD_SET_EVENT_SOCKET :
                        return "SET_EVENT_SOCKET";
+               case DP_CMD_SET_NOTIFICATION_BUNDLE:
+                       return "SET_NOTIFICATION_BUNDLE";
+               case DP_CMD_SET_NOTIFICATION_TITLE:
+                       return "SET_NOTIFICATION_TITLE";
+               case DP_CMD_SET_NOTIFICATION_DESCRIPTION:
+                       return "SET_NOTIFICATION_DESCRIPTION";
+               case DP_CMD_SET_NOTIFICATION_TYPE:
+                       return "SET_NOTIFICATION_TYPE";
+               case DP_CMD_GET_NOTIFICATION_BUNDLE:
+                       return "GET_NOTIFICATION_BUNDLE";
+               case DP_CMD_GET_NOTIFICATION_TITLE:
+                       return "GET_NOTIFICATION_TITLE";
+               case DP_CMD_GET_NOTIFICATION_DESCRIPTION:
+                       return "GET_NOTIFICATION_DESCRIPTION";
+               case DP_CMD_GET_NOTIFICATION_TYPE:
+                       return "GET_NOTIFICATION_TYPE";
                default :
                        break;
        }
@@ -144,7 +165,7 @@ static int __cmp_string(char *s1, char *s2)
        size_t s1_len = 0;
        size_t s2_len = 0;
 
-       if (!s1 || !s2) {
+       if (s1 == NULL || s2 == NULL) {
                TRACE_ERROR("[CHECK PARAM]");
                return -1;
        }
@@ -180,12 +201,13 @@ static int __get_empty_request_index(dp_request_slots *slots)
 {
        int i = 0;
 
-       if (!slots)
+       if (slots == NULL)
                return -1;
 
-       for (i = 0; i < DP_MAX_REQUEST; i++)
-               if (!slots[i].request)
+       for (i = 0; i < DP_MAX_REQUEST; i++) {
+               if (slots[i].request == NULL)
                        return i;
+       }
        return -1;
 }
 
@@ -200,10 +222,9 @@ static int __get_same_request_index(dp_request_slots *slots, int id)
                return -1;
 
        for (i = 0; i < DP_MAX_REQUEST; i++) {
-               if (slots[i].request) {
-                       if (slots[i].request->id == id) {
+               if (slots[i].request != NULL) {
+                       if (slots[i].request->id == id)
                                return i;
-                       }
                }
        }
        return -1;
@@ -244,78 +265,42 @@ static void __clear_group(dp_privates *privates, dp_client_group *group)
 {
        dp_request *request = NULL;
        int i = 0;
-       int state = DP_STATE_FAILED;
-       int errorcode = DP_ERROR_CLIENT_DOWN;
-
-       TRACE_INFO("");
 
        for (i = 0; i < DP_MAX_REQUEST; i++) {
-               if (privates->requests[i].request == NULL)
-                       continue;
-               if (privates->requests[i].request->group == NULL)
-                       continue;
-               if (privates->requests[i].request->id <= 0)
-                       continue;
-               if (privates->requests[i].request->group != group)
+
+               CLIENT_MUTEX_LOCK(&privates->requests[i].mutex);
+
+               if (privates->requests[i].request == NULL) {
+                       CLIENT_MUTEX_UNLOCK(&privates->requests[i].mutex);
                        continue;
+               }
 
                request = privates->requests[i].request;
 
-               CLIENT_MUTEX_LOCK(&request->mutex);
+               if (request->group == NULL || request->id <= 0 ||
+                               request->group != group) {
+                       CLIENT_MUTEX_UNLOCK(&privates->requests[i].mutex);
+                       continue;
+               }
 
                // if stopped, paused or not started yet, clear request
                if (__is_started(request->state) < 0) {
-                       TRACE_INFO("[FREE][%d] state[%s]", request->id,
+                       TRACE_DEBUG("[FREE][%d] state[%s]", request->id,
                                dp_print_state(request->state));
-                       CLIENT_MUTEX_UNLOCK(&request->mutex);
-                       dp_request_free(request);
-                       privates->requests[i].request = NULL;
+                       CLIENT_MUTEX_UNLOCK(&privates->requests[i].mutex);
+                       dp_request_slot_free(&privates->requests[i]);
                        continue;
                }
 
                // disconnect the request from group.
-               TRACE_INFO("[DISCONNECT][%d] state:%s pkg:%s sock:%d",
+               TRACE_SECURE_DEBUG("[DISCONNECT][%d] state:%s pkg:%s sock:%d",
                        request->id, dp_print_state(request->state),
                        request->group->pkgname, request->group->cmd_socket);
                request->group = NULL;
                request->state_cb = 0;
                request->progress_cb = 0;
 
-               // care started requests (queued, connecting, downloading)
-               int auto_download = dp_db_get_int_column(request->id,
-                               DP_DB_TABLE_REQUEST_INFO, DP_DB_COL_AUTO_DOWNLOAD);
-               if (auto_download <= 0) {
-                       // cancel the requests which not setted auto-downloading
-                       TRACE_INFO("[CLEAR][%d] no-auto state:%s",
-                               request->id, dp_print_state(request->state));
-
-                       if (dp_db_set_column(request->id, DP_DB_TABLE_LOG,
-                                       DP_DB_COL_STATE, DP_DB_COL_TYPE_INT, &state) == 0) {
-                               if (dp_db_set_column(request->id, DP_DB_TABLE_LOG,
-                                               DP_DB_COL_ERRORCODE, DP_DB_COL_TYPE_INT,
-                                               &errorcode) < 0) {
-                                       TRACE_ERROR("[fail][%d][sql] set error:%s",
-                                               request->id, dp_print_errorcode(errorcode));
-                               }
-                               // regardless errorcode, if success to update the state.
-                               if (request->agent_id >= 0) {
-                                       TRACE_INFO("[%d]cancel_agent(%d) state:%s error:%s",
-                                               request->id, request->agent_id,
-                                               dp_print_state(state),
-                                               dp_print_errorcode(errorcode));
-                                       if (dp_cancel_agent_download(request->agent_id) < 0)
-                                               TRACE_INFO("[fail][%d]cancel_agent", request->id);
-                               }
-                               CLIENT_MUTEX_UNLOCK(&request->mutex);
-                               dp_request_free(request);
-                               privates->requests[i].request = NULL;
-                               continue;
-                       } else {
-                               TRACE_ERROR("[fail][%d][sql] set state:%s", request->id,
-                                       dp_print_state(state));
-                       }
-               }
-               CLIENT_MUTEX_UNLOCK(&request->mutex);
+               CLIENT_MUTEX_UNLOCK(&privates->requests[i].mutex);
 
        }
        // clear this group
@@ -330,13 +315,85 @@ static void __dp_remove_tmpfile(int id, dp_request *request)
        if (errorcode == DP_ERROR_NONE &&
                        (path != NULL && strlen(path) > 0) &&
                        dp_is_file_exist(path) == 0) {
-               TRACE_INFO("[REMOVE][%d] TEMP FILE [%s]", id, path);
+               TRACE_SECURE_DEBUG("[REMOVE][%d] TEMP FILE [%s]", id, path);
                if (unlink(path) != 0)
                        TRACE_STRERROR("[ERROR][%d] remove file", id);
        }
        free(path);
 }
 
+static int __dp_check_valid_directory(dp_request *request, char *dir)
+{
+       int ret = -1;
+       int ret_val = 0;
+       char *dir_label = NULL;
+       struct stat dir_state;
+
+       ret_val = stat(dir, &dir_state);
+       if (ret_val == 0) {
+               dp_credential cred;
+               if (request->group == NULL) {
+                       cred.uid = dp_db_cond_get_int(DP_DB_TABLE_GROUPS,
+                                               DP_DB_GROUPS_COL_UID,
+                                               DP_DB_GROUPS_COL_PKG,
+                                               DP_DB_COL_TYPE_TEXT, request->packagename);
+                       cred.gid = dp_db_cond_get_int(DP_DB_TABLE_GROUPS,
+                                               DP_DB_GROUPS_COL_GID,
+                                               DP_DB_GROUPS_COL_PKG,
+                                               DP_DB_COL_TYPE_TEXT, request->packagename);
+               } else {
+                       cred = request->group->credential;
+               }
+               if (dir_state.st_uid == cred.uid
+                               && (dir_state.st_mode & (S_IRUSR | S_IWUSR))
+                               == (S_IRUSR | S_IWUSR)) {
+                       ret = 0;
+               } else if (dir_state.st_gid == cred.gid
+                               && (dir_state.st_mode & (S_IRGRP | S_IWGRP))
+                               == (S_IRGRP | S_IWGRP)) {
+                       ret = 0;
+               } else if ((dir_state.st_mode & (S_IROTH | S_IWOTH))
+                               == (S_IROTH | S_IWOTH)) {
+                       ret = 0;
+               }
+       }
+
+       if (ret != 0)
+               return ret;
+
+       ret_val = smack_getlabel(dir, &dir_label, SMACK_LABEL_ACCESS);
+       if (ret_val != 0) {
+               TRACE_SECURE_ERROR("[ERROR][%d][SMACK ERROR]", request->id);
+               free(dir_label);
+               return -1;
+       }
+
+       char *smack_label = NULL;
+       if (request->group == NULL) {
+               // get smack_label from sql
+               smack_label = dp_db_cond_get_text(DP_DB_TABLE_GROUPS,
+                               DP_DB_GROUPS_COL_SMACK_LABEL, DP_DB_GROUPS_COL_PKG,
+                               DP_DB_COL_TYPE_TEXT, request->packagename);
+               if (smack_label != NULL) {
+                       ret_val = smack_have_access(smack_label, dir_label, "rw");
+                       free(smack_label);
+               }
+       } else {
+               if (request->group->smack_label != NULL) {
+                       ret_val = smack_have_access(request->group->smack_label, dir_label, "rw");
+               }
+       }
+       if (ret_val == 0) {
+               TRACE_SECURE_ERROR("[ERROR][%d][SMACK NO RULE]", request->id);
+               ret = -1;
+       } else if (ret_val < 0){
+               TRACE_SECURE_ERROR("[ERROR][%d][SMACK ERROR]", request->id);
+               ret = -1;
+       }
+       free(dir_label);
+       return ret;
+}
+
 static int __dp_call_cancel_agent(dp_request *request)
 {
        int ret = -1;
@@ -347,7 +404,7 @@ static int __dp_call_cancel_agent(dp_request *request)
                        if (dp_cancel_agent_download(request->agent_id) == 0)
                                ret = 0;
                } else {
-                       TRACE_INFO("[CHECK] agent-id");
+                       TRACE_DEBUG("[CHECK] agent-id");
                }
        }
        return ret;
@@ -375,7 +432,7 @@ static int __dp_add_extra_param(int fd, int id)
                TRACE_ERROR("[ERROR][%d] [DP_ERROR_IO_ERROR]", id);
                ret = DP_ERROR_IO_ERROR;
        } else {
-               TRACE_INFO("[RECV] length %d", length);
+               TRACE_DEBUG("[RECV] length %d", length);
                if (length <= 0) {
                        ret = DP_ERROR_INVALID_PARAMETER;
                } else {
@@ -385,7 +442,7 @@ static int __dp_add_extra_param(int fd, int id)
                                ret = DP_ERROR_IO_ERROR;
                        } else {
                                if (length > 1) {
-                                       TRACE_INFO("[RECV] key : %s", key);
+                                       TRACE_SECURE_DEBUG("[RECV] key : %s", key);
                                        // get values
                                        values = (char **)calloc((length - 1), sizeof(char *));
                                        if (values == NULL) {
@@ -429,7 +486,12 @@ static int __dp_add_extra_param(int fd, int id)
                                // insert
                                if (dp_db_insert_columns(DP_DB_TABLE_NOTIFICATION,
                                                conds_count, conds_p) < 0) {
-                                       ret = DP_ERROR_OUT_OF_MEMORY;
+                                       if (dp_db_is_full_error() == 0) {
+                                               TRACE_ERROR("[SQLITE_FULL][%d]", id);
+                                               ret = DP_ERROR_NO_SPACE;
+                                       } else {
+                                               ret = DP_ERROR_OUT_OF_MEMORY;
+                                       }
                                        break;
                                }
                        } // else skip. already exist
@@ -464,7 +526,7 @@ static int __dp_get_extra_param_values(int fd, int id, char ***values,
                TRACE_ERROR("[ERROR][%d] [DP_ERROR_IO_ERROR]", id);
                ret = DP_ERROR_IO_ERROR;
        } else {
-               TRACE_INFO("[RECV] length %d", length);
+               TRACE_DEBUG("[RECV] length %d", length);
                if (length != 1) { // only a key
                        ret = DP_ERROR_INVALID_PARAMETER;
                } else {
@@ -537,12 +599,13 @@ static int __dp_remove_extra_param(int fd, int id)
        if (ret == DP_ERROR_NONE) {
                if (dp_db_cond_remove(id, DP_DB_TABLE_NOTIFICATION,
                                DP_DB_COL_EXTRA_KEY, DP_DB_COL_TYPE_TEXT, key) < 0) {
-                       TRACE_ERROR("[fail][%d][sql] set key:%s", id, key);
+                       TRACE_ERROR("[fail][%d][sql]", id);
+                       TRACE_SECURE_ERROR("[fail]key:%s", key);
                        ret = DP_ERROR_OUT_OF_MEMORY;
                }
        }
-       TRACE_ERROR
-               ("[ERROR][%d][%s] key:%s", id, dp_print_errorcode(ret), key);
+       TRACE_DEBUG("[ERROR][%d][%s]", id, dp_print_errorcode(ret));
+       TRACE_SECURE_DEBUG("key:%s", key);
        free(key);
        return ret;
 }
@@ -606,6 +669,8 @@ static int __dp_set_group_new(int clientfd, dp_group_slots *groups,
        int i = 0;
        struct timeval tv_timeo; // 2.5 sec
        char *pkgname = NULL;
+       char *smack_label = NULL;
+       int ret = 0;
 
        tv_timeo.tv_sec = 2;
        tv_timeo.tv_usec = 500000;
@@ -618,14 +683,14 @@ static int __dp_set_group_new(int clientfd, dp_group_slots *groups,
        // getting the package name via pid
        if (app_manager_get_package(credential.pid, &pkgname) ==
                        APP_MANAGER_ERROR_NONE) {
-               TRACE_INFO("package : %s", pkgname);
+               TRACE_SECURE_DEBUG("package : %s", pkgname);
        } else
                TRACE_ERROR("[CRITICAL] app_manager_get_package");
 
        //// TEST CODE ... to allow sample client ( no package name ).
        if (pkgname == NULL) {
                pkgname = dp_strdup("unknown_app");
-               TRACE_INFO("default package naming : %s", pkgname);
+               TRACE_DEBUG("default package naming : %s", pkgname);
        }
 
        if (pkgname == NULL) {
@@ -651,7 +716,7 @@ static int __dp_set_group_new(int clientfd, dp_group_slots *groups,
                                        strncmp(groups[i].group->pkgname, pkgname,
                                                pkg_len) == 0 ) {
                                // Found Same Group
-                               TRACE_INFO("UPDATE Group: slot:%d pid:%d sock:%d [%s]",
+                               TRACE_SECURE_INFO("UPDATE Group: slot:%d pid:%d sock:%d [%s]",
                                        i, credential.pid, clientfd, pkgname);
                                if (groups[i].group->cmd_socket > 0 &&
                                                groups[i].group->cmd_socket != clientfd) {
@@ -683,6 +748,7 @@ static int __dp_set_group_new(int clientfd, dp_group_slots *groups,
                free(pkgname);
                return -1;
        }
+
        // fill info
        groups[i].group->cmd_socket = clientfd;
        groups[i].group->event_socket = -1;
@@ -691,7 +757,48 @@ static int __dp_set_group_new(int clientfd, dp_group_slots *groups,
        groups[i].group->credential.pid = credential.pid;
        groups[i].group->credential.uid = credential.uid;
        groups[i].group->credential.gid = credential.gid;
-       TRACE_INFO("New Group: slot:%d pid:%d sock:%d [%s]", i,
+
+       int conds_count = 4;
+       db_conds_list_fmt conds_p[conds_count];
+       memset(&conds_p, 0x00, conds_count * sizeof(db_conds_list_fmt));
+       conds_p[0].column = DP_DB_GROUPS_COL_UID;
+       conds_p[0].type = DP_DB_COL_TYPE_INT;
+       conds_p[0].value = &credential.uid;
+       conds_p[1].column = DP_DB_GROUPS_COL_GID;
+       conds_p[1].type = DP_DB_COL_TYPE_INT;
+       conds_p[1].value = &credential.gid;
+       conds_p[2].column = DP_DB_GROUPS_COL_PKG;
+       conds_p[2].type = DP_DB_COL_TYPE_TEXT;
+       conds_p[2].value = pkgname;
+
+       if (dp_is_smackfs_mounted() == 1) {
+               ret = smack_new_label_from_socket(clientfd, &smack_label);
+               if (ret != 0) {
+                       TRACE_ERROR("[CRITICAL] cannot get smack label");
+                       free(pkgname);
+                       free(smack_label);
+                       return -1;
+               }
+               TRACE_SECURE_INFO("credential label:[%s]", smack_label);
+               groups[i].group->smack_label = smack_label;
+
+               conds_p[3].column = DP_DB_GROUPS_COL_SMACK_LABEL;
+               conds_p[3].type = DP_DB_COL_TYPE_TEXT;
+               conds_p[3].value = smack_label;
+       } else {
+               conds_count = 3; // ignore smack label
+               groups[i].group->smack_label = NULL;
+       }
+
+       if (dp_db_insert_columns(DP_DB_TABLE_GROUPS, conds_count, conds_p) < 0) {
+               free(pkgname);
+               free(smack_label);
+               if (dp_db_is_full_error() == 0)
+                       TRACE_ERROR("[SQLITE_FULL]");
+               return -1;
+       }
+
+       TRACE_SECURE_INFO("New Group: slot:%d pid:%d sock:%d [%s]", i,
                credential.pid, clientfd, pkgname);
        free(pkgname);
        return 0;
@@ -703,7 +810,7 @@ static int __dp_set_group_event_sock(int clientfd,
 {
        int i = 0;
 
-       TRACE_INFO("Check event pid:%d sock:%d", credential.pid, clientfd);
+       TRACE_DEBUG("Check event pid:%d sock:%d", credential.pid, clientfd);
        // search same pid in groups
        for (i = 0; i < DP_MAX_GROUP; i++) {
                if (groups[i].group != NULL &&
@@ -712,7 +819,7 @@ static int __dp_set_group_event_sock(int clientfd,
                                        groups[i].group->event_socket != clientfd)
                                dp_socket_free(groups[i].group->event_socket);
                        groups[i].group->event_socket = clientfd;
-                       TRACE_INFO
+                       TRACE_SECURE_INFO
                                ("Found Group : slot:%d pid:%d csock:%d esock:%d [%s]",
                                        i, credential.pid, groups[i].group->cmd_socket,
                                        clientfd, groups[i].group->pkgname);
@@ -727,6 +834,758 @@ static int __dp_set_group_event_sock(int clientfd,
        return 0;
 }
 
+static dp_error_type __dp_do_get_command(int sock, dp_command* cmd, dp_request *request)
+{
+       unsigned is_checked = 1;
+       dp_error_type errorcode = DP_ERROR_NONE;
+
+       char *read_str = NULL;
+       // No read(), write a string
+       switch(cmd->cmd) {
+       case DP_CMD_GET_URL:
+               read_str = dp_request_get_url(cmd->id, &errorcode);
+               break;
+       case DP_CMD_GET_DESTINATION:
+               read_str = dp_request_get_destination(cmd->id, request, &errorcode);
+               break;
+       case DP_CMD_GET_FILENAME:
+               read_str = dp_request_get_filename(cmd->id, request, &errorcode);
+               break;
+       case DP_CMD_GET_SAVED_PATH:
+               read_str = dp_request_get_savedpath(cmd->id, request, &errorcode);
+               break;
+       case DP_CMD_GET_TEMP_SAVED_PATH:
+               read_str = dp_request_get_tmpsavedpath(cmd->id, request, &errorcode);
+               break;
+       case DP_CMD_GET_MIME_TYPE:
+               read_str = dp_request_get_mimetype(cmd->id, request, &errorcode);
+               break;
+       case DP_CMD_GET_CONTENT_NAME:
+               read_str = dp_request_get_contentname(cmd->id, request, &errorcode);
+               break;
+       case DP_CMD_GET_ETAG:
+               read_str = dp_request_get_etag(cmd->id, request, &errorcode);
+               break;
+       case DP_CMD_GET_NOTIFICATION_TITLE:
+               read_str = dp_request_get_title(cmd->id, request, &errorcode);
+               break;
+       case DP_CMD_GET_NOTIFICATION_DESCRIPTION:
+               read_str = dp_request_get_description(cmd->id, request, &errorcode);
+               break;
+       default:
+               is_checked = 0;
+               break;
+       }
+       if (is_checked == 1) {
+               if (read_str == NULL || strlen(read_str) < 1)
+                       errorcode = DP_ERROR_NO_DATA;
+               dp_ipc_send_errorcode(sock, errorcode);
+               if (errorcode == DP_ERROR_NONE) {
+                       dp_ipc_send_string(sock, read_str);
+               } else {
+                       TRACE_ERROR("[ERROR][%d][%s][%s]", cmd->id,
+                               __print_command(cmd->cmd), dp_print_errorcode(errorcode));
+               }
+               free(read_str);
+               return errorcode;
+       }
+
+       // No read(), write a integer variable
+       int read_int = 0;
+       errorcode = DP_ERROR_NONE;
+       is_checked = 1;
+       switch(cmd->cmd) {
+       case DP_CMD_GET_NOTIFICATION:
+               read_int = dp_db_get_int_column(cmd->id, DP_DB_TABLE_REQUEST_INFO,
+                                               DP_DB_COL_NOTIFICATION_ENABLE);
+               break;
+       case DP_CMD_GET_AUTO_DOWNLOAD:
+               read_int = dp_db_get_int_column(cmd->id, DP_DB_TABLE_REQUEST_INFO,
+                                               DP_DB_COL_AUTO_DOWNLOAD);
+               break;
+       case DP_CMD_GET_NETWORK_TYPE:
+               read_int = dp_db_get_int_column(cmd->id, DP_DB_TABLE_REQUEST_INFO,
+                                               DP_DB_COL_NETWORK_TYPE);
+               break;
+       case DP_CMD_GET_HTTP_STATUS:
+               read_int = dp_db_get_int_column(cmd->id, DP_DB_TABLE_DOWNLOAD_INFO,
+                                               DP_DB_COL_HTTP_STATUS);
+               break;
+       case DP_CMD_GET_STATE:
+               if (request == NULL) {
+                       read_int =  dp_db_get_state(cmd->id);
+               } else {
+                       read_int = request->state;
+               }
+               break;
+       case DP_CMD_GET_NOTIFICATION_TYPE:
+               TRACE_DEBUG("DP_CMD_GET_NOTIFICATION_TYPE");
+               read_int = dp_request_get_noti_type(cmd->id, request, &errorcode);
+               break;
+       case DP_CMD_GET_ERROR:
+               if (request == NULL) {
+                       read_int = dp_db_get_int_column(cmd->id,
+                                       DP_DB_TABLE_LOG, DP_DB_COL_ERRORCODE);
+               } else {
+                       read_int = request->error;
+               }
+               break;
+       default:
+               is_checked = 0;
+               break;
+       }
+       if (is_checked == 1) {
+               if (read_int < 0)
+                       errorcode = DP_ERROR_NO_DATA;
+               dp_ipc_send_errorcode(sock, errorcode);
+               if (errorcode == DP_ERROR_NONE) {
+                       dp_ipc_send_custom_type(sock, &read_int, sizeof(int));
+               } else {
+                       TRACE_ERROR("[ERROR][%d][%s][%s]", cmd->id,
+                               __print_command(cmd->cmd), dp_print_errorcode(errorcode));
+               }
+               return errorcode;
+       }
+
+       // No read(), write a long long variable
+       unsigned long long recv_long = 0;
+       errorcode = DP_ERROR_NONE;
+       is_checked = 1;
+       switch(cmd->cmd) {
+       case DP_CMD_GET_RECEIVED_SIZE:
+               if (request == NULL)
+                       errorcode = DP_ERROR_NO_DATA;
+               else
+                       recv_long = request->received_size;
+               break;
+       case DP_CMD_GET_TOTAL_FILE_SIZE:
+               if (request != NULL) {
+                       recv_long = request->file_size;
+               } else {
+                       long long file_size =
+                               dp_db_get_int64_column(cmd->id,
+                                       DP_DB_TABLE_DOWNLOAD_INFO, DP_DB_COL_CONTENT_SIZE);
+                       if (file_size < 0)
+                               errorcode = DP_ERROR_NO_DATA;
+                       else // casting
+                               recv_long = file_size;
+               }
+               break;
+       default:
+               is_checked = 0;
+               break;
+       }
+       if (is_checked == 1) {
+               dp_ipc_send_errorcode(sock, errorcode);
+               if (errorcode == DP_ERROR_NONE) {
+                       dp_ipc_send_custom_type(sock, &recv_long,
+                               sizeof(unsigned long long));
+               } else {
+                       TRACE_ERROR("[ERROR][%d][%s][%s]", cmd->id,
+                               __print_command(cmd->cmd), dp_print_errorcode(errorcode));
+               }
+               return errorcode;
+       }
+
+       // No read(), write a bundle variable
+       bundle_raw *b_raw = NULL;
+       int length = -1;
+       char *column = NULL;
+       errorcode = DP_ERROR_NONE;
+       is_checked = 1;
+       switch(cmd->cmd) {
+       case DP_CMD_GET_NOTIFICATION_BUNDLE:
+               TRACE_DEBUG("DP_CMD_GET_NOTIFICATION_BUNDLE");
+               dp_ipc_send_errorcode(sock, DP_ERROR_NONE);
+               if ((dp_ipc_read_custom_type(sock, &read_int, sizeof(int)) < 0)) {
+                       TRACE_ERROR("DP_CMD_GET_NOTIFICATION_BUNDLE read fail");
+                       errorcode = DP_ERROR_IO_ERROR;
+                       break;
+               }
+               switch(read_int) {
+               case DP_NOTIFICATION_BUNDLE_TYPE_ONGOING:
+                       column = DP_DB_COL_RAW_BUNDLE_ONGOING;
+                       break;
+               case DP_NOTIFICATION_BUNDLE_TYPE_COMPLETE:
+                       column = DP_DB_COL_RAW_BUNDLE_COMPLETE;
+                       break;
+               case DP_NOTIFICATION_BUNDLE_TYPE_FAILED:
+                       column = DP_DB_COL_RAW_BUNDLE_FAIL;
+                       break;
+               default:
+                       TRACE_ERROR("[CHECK TYPE][%d]", read_int);
+                       errorcode = DP_ERROR_INVALID_PARAMETER;
+                       break;
+               }
+               b_raw = dp_request_get_bundle(cmd->id, request,
+                                               &errorcode, column, &length);
+               break;
+       default:
+               is_checked = 0;
+               break;
+       }
+       if (is_checked == 1) {
+               dp_ipc_send_errorcode(sock, errorcode);
+               if (errorcode == DP_ERROR_NONE) {
+                       dp_ipc_send_bundle(sock, b_raw, length);
+               } else {
+                       TRACE_ERROR("[ERROR][%d][%s][%s]", cmd->id,
+                               __print_command(cmd->cmd), dp_print_errorcode(errorcode));
+               }
+               bundle_free_encoded_rawdata(&b_raw);
+               return errorcode;
+       }
+
+       dp_ipc_send_errorcode(sock, DP_ERROR_NONE);
+       // complex read() and write().
+       char *read_str2 = NULL;
+       errorcode = DP_ERROR_NONE;
+       read_str = NULL;
+       is_checked = 1;
+       switch(cmd->cmd) {
+       case DP_CMD_GET_HTTP_HEADER:
+               if ((read_str = dp_ipc_read_string(sock)) == NULL) {
+                       errorcode = DP_ERROR_IO_ERROR;
+                       break;
+               }
+               read_str2 = dp_db_cond_get_text_column(cmd->id,
+                       DP_DB_TABLE_HTTP_HEADERS, DP_DB_COL_HEADER_DATA,
+                       DP_DB_COL_HEADER_FIELD, DP_DB_COL_TYPE_TEXT, read_str);
+               if (read_str2 == NULL)
+                       errorcode = DP_ERROR_NO_DATA;
+               dp_ipc_send_errorcode(sock, errorcode);
+               if (errorcode == DP_ERROR_NONE)
+                       dp_ipc_send_string(sock, read_str2);
+               break;
+       case DP_CMD_GET_HTTP_HEADER_LIST:
+       {
+               char **values = NULL;
+               unsigned rows_count = 0;
+               errorcode = __dp_get_http_header_fields(sock,
+                               cmd->id, &values, &rows_count);
+               if (errorcode == DP_ERROR_NONE) {
+                       __send_return_custom_type(sock, DP_ERROR_NONE,
+                               &rows_count, sizeof(int));
+                       // sending strings
+                       int i = 0;
+                       for (i = 0; i < rows_count; i++) {
+                               if (dp_ipc_send_string(sock, values[i]) < 0)
+                                       break;
+                       }
+                       for (i = 0; i < rows_count; i++)
+                               free(values[i]);
+               } else {
+                       if (errorcode != DP_ERROR_IO_ERROR)
+                               dp_ipc_send_errorcode(sock, errorcode);
+               }
+               free(values);
+               break;
+       }
+       case DP_CMD_GET_EXTRA_PARAM:
+       {
+               char **values = NULL;
+               unsigned rows_count = 0;
+               errorcode = __dp_get_extra_param_values(sock,
+                               cmd->id, &values, &rows_count);
+               if (errorcode == DP_ERROR_NONE) {
+                       __send_return_custom_type(sock, DP_ERROR_NONE,
+                               &rows_count, sizeof(int));
+                       // sending strings
+                       int i = 0;
+                       for (i = 0; i < rows_count; i++) {
+                               if (dp_ipc_send_string(sock, values[i]) < 0)
+                                       break;
+                       }
+               for (i = 0; i < rows_count; i++)
+                               free(values[i]);
+               } else {
+                       if (errorcode != DP_ERROR_IO_ERROR)
+                               dp_ipc_send_errorcode(sock, errorcode);
+               }
+               free(values);
+               break;
+       }
+       default:
+               is_checked = 0;
+               break;
+       }
+       if (is_checked == 1) {
+               if (errorcode != DP_ERROR_NONE) {
+                       TRACE_ERROR("[ERROR][%d][%s][%s]", cmd->id,
+                               __print_command(cmd->cmd), dp_print_errorcode(errorcode));
+               }
+               free(read_str);
+               free(read_str2);
+               return errorcode;
+       }
+       return DP_ERROR_UNKNOWN;
+}
+
+static dp_error_type __dp_do_set_command(int sock, dp_command *cmd, dp_request *request)
+{
+       unsigned is_checked = 1;
+       int read_int = 0;
+       dp_error_type errorcode = DP_ERROR_NONE;
+       char *read_str = NULL;
+       bundle_raw *b_raw = NULL;
+       unsigned bundle_length = 0;
+       int noti_bundle_type = 0;
+
+       dp_ipc_send_errorcode(sock, DP_ERROR_NONE);
+       // read a interger or a string, return errorcode.
+       errorcode = DP_ERROR_NONE;
+       switch(cmd->cmd) {
+       case DP_CMD_SET_STATE_CALLBACK:
+               if (dp_ipc_read_custom_type(sock, &read_int, sizeof(int)) < 0) {
+                       errorcode = DP_ERROR_IO_ERROR;
+                       break;
+               }
+               errorcode = dp_request_set_state_event(cmd->id, request, read_int);
+               break;
+       case DP_CMD_SET_PROGRESS_CALLBACK:
+               if (dp_ipc_read_custom_type(sock, &read_int, sizeof(int)) < 0) {
+                       errorcode = DP_ERROR_IO_ERROR;
+                       break;
+               }
+               errorcode = dp_request_set_progress_event(cmd->id, request, read_int);
+               break;
+       case DP_CMD_SET_NETWORK_TYPE:
+               if (dp_ipc_read_custom_type(sock, &read_int, sizeof(int)) < 0) {
+                       errorcode = DP_ERROR_IO_ERROR;
+                       break;
+               }
+               if (read_int == DP_NETWORK_TYPE_ALL ||
+                               read_int == DP_NETWORK_TYPE_WIFI ||
+                               read_int == DP_NETWORK_TYPE_DATA_NETWORK ||
+                               read_int == DP_NETWORK_TYPE_ETHERNET ||
+                               read_int == DP_NETWORK_TYPE_WIFI_DIRECT)
+                       errorcode = dp_request_set_network_type(cmd->id, request, read_int);
+               else
+                       errorcode = DP_ERROR_INVALID_PARAMETER;
+               break;
+       case DP_CMD_SET_AUTO_DOWNLOAD:
+               if (dp_ipc_read_custom_type(sock, &read_int, sizeof(int)) < 0) {
+                       errorcode = DP_ERROR_IO_ERROR;
+                       break;
+               }
+               errorcode = dp_request_set_auto_download(cmd->id, request, read_int);
+               break;
+       case DP_CMD_SET_NOTIFICATION:
+               if (dp_ipc_read_custom_type(sock, &read_int, sizeof(int)) < 0) {
+                       errorcode = DP_ERROR_IO_ERROR;
+                       break;
+               }
+               errorcode = dp_request_set_notification(cmd->id, request, read_int);
+               break;
+       case DP_CMD_SET_URL:
+               if ((read_str = dp_ipc_read_string(sock)) == NULL) {
+                       errorcode = DP_ERROR_IO_ERROR;
+                       break;
+               }
+               errorcode = dp_request_set_url(cmd->id, request, read_str);
+               break;
+       case DP_CMD_SET_DESTINATION:
+               if ((read_str = dp_ipc_read_string(sock)) == NULL) {
+                       errorcode = DP_ERROR_IO_ERROR;
+                       break;
+               }
+               if (dp_is_smackfs_mounted() == 1 &&
+                               __dp_check_valid_directory(request, read_str) != 0){
+                       errorcode = DP_ERROR_PERMISSION_DENIED;
+                       break;
+               }
+               errorcode = dp_request_set_destination(cmd->id, request, read_str);
+               break;
+       case DP_CMD_SET_FILENAME:
+               if ((read_str = dp_ipc_read_string(sock)) == NULL) {
+                       errorcode = DP_ERROR_IO_ERROR;
+                       break;
+               }
+               errorcode = dp_request_set_filename(cmd->id, request, read_str);
+               break;
+       case DP_CMD_SET_NOTIFICATION_BUNDLE:
+               bundle_length = dp_ipc_read_bundle(sock, &noti_bundle_type, &b_raw);
+               if (bundle_length == 0) {
+                       errorcode = DP_ERROR_IO_ERROR;
+                       break;
+               } else if (bundle_length == -1) {
+                       errorcode = DP_ERROR_INVALID_PARAMETER;
+                       break;
+               }
+               errorcode = dp_request_set_bundle(cmd->id, request,
+                               noti_bundle_type, b_raw, bundle_length);
+               break;
+       case DP_CMD_SET_NOTIFICATION_TITLE:
+               if ((read_str = dp_ipc_read_string(sock)) == NULL) {
+                       errorcode = DP_ERROR_IO_ERROR;
+                       break;
+               }
+               errorcode = dp_request_set_title(cmd->id, request, read_str);
+               break;
+       case DP_CMD_SET_NOTIFICATION_DESCRIPTION:
+               if ((read_str = dp_ipc_read_string(sock)) == NULL) {
+                       errorcode = DP_ERROR_IO_ERROR;
+                       break;
+               }
+               errorcode = dp_request_set_description(cmd->id, request, read_str);
+               break;
+       case DP_CMD_SET_NOTIFICATION_TYPE:
+               if ((dp_ipc_read_custom_type(sock, &read_int, sizeof(int)) < 0)) {
+                       errorcode = DP_ERROR_IO_ERROR;
+                       break;
+               }
+               if (read_int == DP_NOTIFICATION_TYPE_NONE ||
+                               read_int == DP_NOTIFICATION_TYPE_COMPLETE_ONLY ||
+                               read_int == DP_NOTIFICATION_TYPE_ALL)
+                       errorcode = dp_request_set_noti_type(cmd->id, request, read_int);
+               else
+                       errorcode = DP_ERROR_INVALID_PARAMETER;
+               break;
+       default:
+               is_checked = 0;
+               break;
+       }
+       if (is_checked == 1) {
+               free(read_str);
+               bundle_free_encoded_rawdata(&b_raw);
+               if (errorcode != DP_ERROR_NONE) {
+                       TRACE_ERROR("[ERROR][%d][%s][%s]", cmd->id,
+                               __print_command(cmd->cmd), dp_print_errorcode(errorcode));
+               }
+               if (errorcode == DP_ERROR_IO_ERROR)
+                       return errorcode;
+               dp_ipc_send_errorcode(sock, errorcode);
+               return errorcode;
+       }
+
+       // complex read() and write().
+       char *read_str2 = NULL;
+       errorcode = DP_ERROR_NONE;
+       read_str = NULL;
+       is_checked = 1;
+       switch(cmd->cmd) {
+       case DP_CMD_SET_HTTP_HEADER:
+       {
+               if ((read_str = dp_ipc_read_string(sock)) == NULL) {
+                       errorcode = DP_ERROR_IO_ERROR;
+                       break;
+               }
+               if ((read_str2 = dp_ipc_read_string(sock)) == NULL) {
+                       errorcode = DP_ERROR_IO_ERROR;
+                       break;
+               }
+               int conds_count = 3; // id + field + data
+               db_conds_list_fmt conds_p[conds_count];
+               memset(&conds_p, 0x00,
+               conds_count * sizeof(db_conds_list_fmt));
+               conds_p[0].column = DP_DB_COL_ID;
+               conds_p[0].type = DP_DB_COL_TYPE_INT;
+               conds_p[0].value = &cmd->id;
+               conds_p[1].column = DP_DB_COL_HEADER_FIELD;
+               conds_p[1].type = DP_DB_COL_TYPE_TEXT;
+               conds_p[1].value = read_str;
+               conds_p[2].column = DP_DB_COL_HEADER_DATA;
+               conds_p[2].type = DP_DB_COL_TYPE_TEXT;
+               conds_p[2].value = read_str2;
+               if (dp_db_get_conds_rows_count(DP_DB_TABLE_HTTP_HEADERS,
+                               DP_DB_COL_ID, "AND", 2, conds_p) <= 0) { // insert
+                       if (dp_db_insert_columns(DP_DB_TABLE_HTTP_HEADERS,
+                                       conds_count, conds_p) < 0) {
+                               if (dp_db_is_full_error() == 0) {
+                                       TRACE_ERROR("[SQLITE_FULL][%d]", cmd->id);
+                                       errorcode = DP_ERROR_NO_SPACE;
+                               } else {
+                                       errorcode = DP_ERROR_OUT_OF_MEMORY;
+                               }
+                       }
+               } else { // update data by field
+                       if (dp_db_cond_set_column(cmd->id, DP_DB_TABLE_HTTP_HEADERS,
+                                       DP_DB_COL_HEADER_DATA, DP_DB_COL_TYPE_TEXT, read_str2,
+                                       DP_DB_COL_HEADER_FIELD, DP_DB_COL_TYPE_TEXT, read_str) < 0) {
+                               if (dp_db_is_full_error() == 0) {
+                                       TRACE_ERROR("[SQLITE_FULL][%d]", cmd->id);
+                                       errorcode = DP_ERROR_NO_SPACE;
+                               } else {
+                                       errorcode = DP_ERROR_OUT_OF_MEMORY;
+                               }
+                       }
+               }
+               dp_ipc_send_errorcode(sock, errorcode);
+               break;
+       }
+       case DP_CMD_DEL_HTTP_HEADER:
+               if ((read_str = dp_ipc_read_string(sock)) == NULL) {
+                       errorcode = DP_ERROR_IO_ERROR;
+                       break;
+               }
+               if (dp_db_get_cond_rows_count(cmd->id, DP_DB_TABLE_HTTP_HEADERS,
+                               DP_DB_COL_HEADER_FIELD, DP_DB_COL_TYPE_TEXT,
+                               read_str) <= 0) {
+                       errorcode = DP_ERROR_NO_DATA;
+               } else {
+                       if (dp_db_cond_remove(cmd->id, DP_DB_TABLE_HTTP_HEADERS,
+                                       DP_DB_COL_HEADER_FIELD, DP_DB_COL_TYPE_TEXT, read_str) < 0)
+                               errorcode = DP_ERROR_OUT_OF_MEMORY;
+               }
+               dp_ipc_send_errorcode(sock, errorcode);
+               break;
+       case DP_CMD_ADD_EXTRA_PARAM:
+               errorcode = __dp_add_extra_param(sock, cmd->id);
+               if (errorcode != DP_ERROR_IO_ERROR)
+                       dp_ipc_send_errorcode(sock, errorcode);
+               break;
+       case DP_CMD_REMOVE_EXTRA_PARAM:
+               errorcode = __dp_remove_extra_param(sock, cmd->id);
+               if (errorcode != DP_ERROR_IO_ERROR)
+                       dp_ipc_send_errorcode(sock, errorcode);
+               break;
+       default:
+               is_checked = 0;
+               break;
+       }
+       if (is_checked == 1) {
+               if (errorcode != DP_ERROR_NONE) {
+                       TRACE_ERROR("[ERROR][%d][%s][%s]", cmd->id,
+                               __print_command(cmd->cmd), dp_print_errorcode(errorcode));
+               }
+               free(read_str);
+               free(read_str2);
+               return errorcode;
+       }
+       return DP_ERROR_UNKNOWN;
+}
+
+static dp_error_type __dp_do_action_command(int sock, dp_command* cmd, dp_request *request)
+{
+       unsigned is_checked = 1;
+       int read_int = 0;
+       dp_error_type errorcode = DP_ERROR_NONE;
+
+       read_int = 0;
+       errorcode = DP_ERROR_NONE;
+       is_checked = 1;
+       switch(cmd->cmd) {
+       case DP_CMD_DESTROY:
+               if (request != NULL) {// just update the state
+                       if (__is_started(request->state) == 0) {
+                               read_int = DP_STATE_CANCELED;
+                               if (dp_db_set_column(cmd->id, DP_DB_TABLE_LOG, DP_DB_COL_STATE,
+                                       DP_DB_COL_TYPE_INT, &read_int) < 0) {
+                                       errorcode = DP_ERROR_OUT_OF_MEMORY;
+                               } else {
+                                       if (__dp_call_cancel_agent(request) < 0)
+                                               TRACE_ERROR("[fail][%d]cancel_agent", cmd->id);
+                                       request->state = DP_STATE_CANCELED;
+                                       if (request->auto_notification == 1 &&
+                                                                       request->packagename != NULL) {
+                                               request->noti_priv_id = dp_set_downloadedinfo_notification
+                                                               (request->noti_priv_id, request->id,
+                                                               request->packagename, request->state);
+                                       } else {
+                                               int noti_type = dp_db_get_int_column(request->id,
+                                                               DP_DB_TABLE_NOTIFICATION, DP_DB_COL_NOTI_TYPE);
+                                               if (noti_type > DP_NOTIFICATION_TYPE_NONE &&
+                                                               request->packagename != NULL)
+                                                       request->noti_priv_id = dp_set_downloadedinfo_notification
+                                                                       (request->noti_priv_id, request->id,
+                                                                       request->packagename, request->state);
+                                       }
+                               }
+                       }
+               }
+               break;
+       case DP_CMD_PAUSE:
+       {
+               // to check fastly, divide the case by request value
+               if (request == NULL) {
+                       dp_state_type state = dp_db_get_state(cmd->id);
+                       // already paused or stopped
+                       if (state > DP_STATE_DOWNLOADING) {
+                               errorcode = DP_ERROR_INVALID_STATE;
+                       } else {
+                               // change state to paused.
+                               state = DP_STATE_PAUSED;
+                               if (dp_db_set_column(cmd->id, DP_DB_TABLE_LOG,
+                                               DP_DB_COL_STATE, DP_DB_COL_TYPE_INT, &state) < 0)
+                                       errorcode = DP_ERROR_OUT_OF_MEMORY;
+                       }
+                       break;
+               }
+
+               if (request->state > DP_STATE_DOWNLOADING) {
+                       errorcode = DP_ERROR_INVALID_STATE;
+                       break;
+               }
+
+               // before downloading including QUEUED
+               if (__is_downloading(request->state) < 0) {
+                       dp_state_type state = DP_STATE_PAUSED;
+                       if (dp_db_set_column(cmd->id, DP_DB_TABLE_LOG, DP_DB_COL_STATE,
+                                       DP_DB_COL_TYPE_INT, &state) < 0) {
+                               errorcode = DP_ERROR_OUT_OF_MEMORY;
+                       } else {
+                               request->state = state;
+                       }
+                       break;
+               }
+               // only downloading.
+               dp_state_type state = DP_STATE_PAUSE_REQUESTED;
+               if (dp_db_set_column(cmd->id, DP_DB_TABLE_LOG,
+                               DP_DB_COL_STATE, DP_DB_COL_TYPE_INT, &state) < 0) {
+                       errorcode = DP_ERROR_OUT_OF_MEMORY;
+               } else {
+                       TRACE_INFO("[%s][%d]pause_agent(%d) state:%s",
+                               __print_command(cmd->cmd), cmd->id,
+                               request->agent_id,
+                               dp_print_state(request->state));
+                       if (dp_pause_agent_download
+                                       (request->agent_id) < 0) {
+                               TRACE_ERROR("[fail][%d]pause_agent(%d)",
+                                       cmd->id, request->agent_id);
+                       }
+                       request->state = state;
+                       request->error = DP_ERROR_NONE;
+                       request->pause_time = (int)time(NULL);
+                       dp_db_update_date(cmd->id, DP_DB_TABLE_LOG,
+                               DP_DB_COL_ACCESS_TIME);
+               }
+               break;
+       }
+       case DP_CMD_CANCEL:
+       {
+               // to check fastly, divide the case by request value
+               if (request == NULL) {
+                       dp_state_type state = dp_db_get_state(cmd->id);
+                       // already paused or stopped
+                       if (__is_stopped(state) == 0) {
+                               errorcode = DP_ERROR_INVALID_STATE;
+                       } else {
+                               // change state to canceled.
+                               state = DP_STATE_CANCELED;
+                               if (dp_db_set_column(cmd->id, DP_DB_TABLE_LOG,
+                                               DP_DB_COL_STATE, DP_DB_COL_TYPE_INT, &state) < 0)
+                                       errorcode = DP_ERROR_OUT_OF_MEMORY;
+                       }
+                       break;
+               }
+
+               if (__is_stopped(request->state) == 0) {
+                       TRACE_ERROR("[%s][%d]__is_stopped agentid:%d state:%s",
+                               __print_command(cmd->cmd), cmd->id,
+                               request->agent_id, dp_print_state(request->state));
+                       errorcode = DP_ERROR_INVALID_STATE;
+               } else {
+                       // change state to canceled.
+                       dp_state_type state = DP_STATE_CANCELED;
+                       if (dp_db_set_column(cmd->id, DP_DB_TABLE_LOG, DP_DB_COL_STATE,
+                                       DP_DB_COL_TYPE_INT, &state) < 0)
+                               errorcode = DP_ERROR_OUT_OF_MEMORY;
+               }
+               if (errorcode == DP_ERROR_NONE) {
+                       if (__dp_call_cancel_agent(request) < 0)
+                               TRACE_ERROR("[fail][%d]cancel_agent", cmd->id);
+                       request->state = DP_STATE_CANCELED;
+               }
+               dp_db_update_date(cmd->id, DP_DB_TABLE_LOG, DP_DB_COL_ACCESS_TIME);
+               break;
+       }
+       default:
+               is_checked = 0;
+               break;
+       }
+       if (is_checked == 1) {
+               if (errorcode != DP_ERROR_NONE) {
+                       TRACE_ERROR("[ERROR][%d][%s][%s]", cmd->id,
+                               __print_command(cmd->cmd), dp_print_errorcode(errorcode));
+               }
+               dp_ipc_send_errorcode(sock, errorcode);
+               return errorcode;
+       }
+       return DP_ERROR_UNKNOWN;
+}
+
+static dp_error_type __do_dp_start_command(int sock, int id, dp_privates *privates,
+       dp_client_group *group, dp_request *request)
+{
+       dp_error_type errorcode = DP_ERROR_NONE;
+
+       // need URL at least
+       char *url = dp_request_get_url(id, &errorcode);
+       free(url);
+       if (errorcode == DP_ERROR_NO_DATA) {
+               errorcode = DP_ERROR_INVALID_URL;
+               dp_ipc_send_errorcode(sock, errorcode);
+               return errorcode;
+       }
+
+       if (request == NULL) { // Support Re-download
+               // Support Re-download
+               int index = __get_empty_request_index(privates->requests);
+               if (index < 0) { // Busy, No Space in slot
+                       errorcode = DP_ERROR_QUEUE_FULL;
+                       TRACE_SECURE_ERROR("[ERROR][%d][RESTORE][%s]", id,
+                               dp_print_errorcode(errorcode));
+               } else {
+                       CLIENT_MUTEX_LOCK(&privates->requests[index].mutex);
+                       dp_request *tmp_request =
+                               dp_request_load_from_log (id, &errorcode);
+                       if (tmp_request != NULL) {
+                               // restore callback info
+                               tmp_request->state_cb = dp_db_get_int_column(id,
+                                               DP_DB_TABLE_REQUEST_INFO, DP_DB_COL_STATE_EVENT);
+                               tmp_request->progress_cb = dp_db_get_int_column(id,
+                                               DP_DB_TABLE_REQUEST_INFO, DP_DB_COL_PROGRESS_EVENT);
+                               tmp_request->auto_notification =
+                                       dp_db_get_int_column(id, DP_DB_TABLE_REQUEST_INFO,
+                                               DP_DB_COL_NOTIFICATION_ENABLE);
+                               if (group != NULL) // for send event to client
+                                       tmp_request->group = group;
+                               privates->requests[index].request = tmp_request;
+                               request = privates->requests[index].request;
+                       } else {
+                               TRACE_SECURE_ERROR("[ERROR][%d][RESTORE][%s]", id,
+                                       dp_print_errorcode(errorcode));
+                               dp_ipc_send_errorcode(sock, errorcode);
+                               CLIENT_MUTEX_UNLOCK(&privates->requests[index].mutex);
+                               return errorcode;
+                       }
+                       CLIENT_MUTEX_UNLOCK(&privates->requests[index].mutex);
+               }
+       }
+
+       // check status
+       if (errorcode == DP_ERROR_NONE &&
+                       (__is_started(request->state) == 0 ||
+                       request->state == DP_STATE_COMPLETED))
+               errorcode = DP_ERROR_INVALID_STATE;
+
+       if (errorcode == DP_ERROR_NONE) {
+
+               dp_state_type state = DP_STATE_QUEUED;
+               if (dp_db_set_column(id, DP_DB_TABLE_LOG,
+                               DP_DB_COL_STATE, DP_DB_COL_TYPE_INT, &state) < 0) {
+                       errorcode = DP_ERROR_OUT_OF_MEMORY;
+               } else {
+                       if (group != NULL)
+                               group->queued_count++;
+                       request->start_time = (int)time(NULL);
+                       request->pause_time = 0;
+                       request->stop_time = 0;
+                       request->state = state;
+                       request->error = DP_ERROR_NONE;
+                       dp_db_update_date(id, DP_DB_TABLE_LOG, DP_DB_COL_ACCESS_TIME);
+               }
+
+       }
+
+       dp_ipc_send_errorcode(sock, errorcode);
+       if (errorcode != DP_ERROR_NONE) {
+               TRACE_SECURE_ERROR("[ERROR][%d][START][%s]", id,
+                       dp_print_errorcode(errorcode));
+       }
+       return errorcode;
+}
+
 // in url-download, make 3 connection before send CREATE command.
 // after accepting, fill info to pacakgelist.
 // 3 socket per 1 package ( info/request/progress )
@@ -754,7 +1613,7 @@ void *dp_thread_requests_manager(void *arg)
        listenfd = privates->listen_fd;
        maxfd = listenfd;
 
-       TRACE_INFO("Ready to listen [%d][%s]", listenfd, DP_IPC);
+       TRACE_DEBUG("Ready to listen [%d][%s]", listenfd, DP_IPC);
 
        FD_ZERO(&listen_fdset);
        FD_ZERO(&except_fdset);
@@ -781,8 +1640,8 @@ void *dp_thread_requests_manager(void *arg)
                        break;
                }
 
-               if (privates == NULL) {
-                       TRACE_INFO("Terminate Thread");
+               if (privates == NULL || privates->listen_fd < 0) {
+                       TRACE_DEBUG("Terminate Thread");
                        break;
                }
 
@@ -825,7 +1684,7 @@ void *dp_thread_requests_manager(void *arg)
                        socklen_t cr_len = sizeof(credential);
                        if (getsockopt(clientfd, SOL_SOCKET, SO_PEERCRED,
                                &credential, &cr_len) == 0) {
-                               TRACE_INFO
+                               TRACE_DEBUG
                                        ("credential : pid=%d, uid=%d, gid=%d",
                                        credential.pid, credential.uid, credential.gid);
                        }
@@ -843,8 +1702,18 @@ void *dp_thread_requests_manager(void *arg)
                                continue;
                        }
                        credential.pid = client_pid;
-                       credential.uid = 5000;
-                       credential.gid = 5000;
+                       if (dp_ipc_read_custom_type(clientfd,
+                                       &credential.uid, sizeof(int)) < 0) {
+                               TRACE_ERROR("[CRITICAL] not support SO_PEERCRED");
+                               close(clientfd);
+                               continue;
+                       }
+                       if (dp_ipc_read_custom_type(clientfd,
+                                       &credential.gid, sizeof(int)) < 0) {
+                               TRACE_ERROR("[CRITICAL] not support SO_PEERCRED");
+                               close(clientfd);
+                               continue;
+                       }
 #endif
 
                        switch(connect_cmd) {
@@ -876,6 +1745,7 @@ void *dp_thread_requests_manager(void *arg)
                        if (group == NULL || group->cmd_socket < 0)
                                continue;
                        const int sock = group->cmd_socket;
+                       int time_of_job = (int)time(NULL);
                        if (FD_ISSET(sock, &rset) > 0) {
                                int index = -1;
                                dp_command command;
@@ -891,13 +1761,8 @@ void *dp_thread_requests_manager(void *arg)
                                        continue;
                                }
 
-                               // print detail info
-                               TRACE_INFO("[%s] id:%d sock:%d pkg:%s pid:%d slot:%d",
-                                       __print_command(command.cmd), command.id, sock,
-                                       group->pkgname, group->credential.pid, i);
-
-                               if (command.cmd == 0) { // Client meet some Error.
-                                       TRACE_INFO("[Closed Peer] pkg:%s sock:%d slot:%d",
+                               if (command.cmd == 0 || command.cmd >= DP_CMD_LAST_SECT) { // Client meet some Error.
+                                       TRACE_SECURE_INFO("[Closed Peer] pkg:%s sock:%d slot:%d",
                                                group->pkgname, sock, i);
                                        // check all request included to this group
                                        FD_CLR(sock, &listen_fdset);
@@ -909,10 +1774,11 @@ void *dp_thread_requests_manager(void *arg)
                                // Echo .client can check whether provider is busy
                                if (command.cmd == DP_CMD_ECHO) {
                                        // provider can clear read buffer here
-                                       TRACE_INFO("[ECHO] sock:%d", sock);
+                                       TRACE_DEBUG("[ECHO] sock:%d", sock);
                                        if (dp_ipc_send_errorcode(sock,
                                                        DP_ERROR_NONE) < 0) {
                                                // disconnect this group, bad client
+                                               TRACE_ERROR("[ECHO] IO ERROR CLEAN sock:%d", sock);
                                                FD_CLR(sock, &listen_fdset);
                                                __clear_group(privates, group);
                                                privates->groups[i].group = NULL;
@@ -921,6 +1787,9 @@ void *dp_thread_requests_manager(void *arg)
                                }
 
                                if (command.cmd == DP_CMD_CREATE) {
+                                       TRACE_SECURE_INFO("[CREATE] id:%d sock:%d pid:%d gindex:%d pkg:%s",
+                                               command.id, sock,
+                                               group->credential.pid, i, group->pkgname);
                                        // search empty slot in privates->requests
                                        index =
                                                __get_empty_request_index(privates->requests);
@@ -930,20 +1799,22 @@ void *dp_thread_requests_manager(void *arg)
                                                dp_ipc_send_errorcode(sock, DP_ERROR_QUEUE_FULL);
                                        } else {
                                                errorcode = DP_ERROR_NONE;
+                                               CLIENT_MUTEX_LOCK(&privates->requests[index].mutex);
                                                errorcode = dp_request_create(command.id, group,
                                                        &privates->requests[index].request);
                                                dp_ipc_send_errorcode(sock, errorcode);
                                                if (errorcode == DP_ERROR_NONE) {
-                                                       TRACE_INFO("[CREATE] GOOD id:%d slot:%d",
-                                                               privates->requests[index].request->id,
-                                                               index);
                                                        dp_ipc_send_custom_type(sock,
                                                                &privates->requests[index].request->id,
                                                                sizeof(int));
+                                                       TRACE_DEBUG("[CREATE] GOOD id:%d slot:%d time:%d",
+                                                               privates->requests[index].request->id,
+                                                               index, ((int)time(NULL) - time_of_job));
                                                } else {
                                                        TRACE_ERROR("[ERROR][%s]",
                                                                dp_print_errorcode(errorcode));
                                                }
+                                               CLIENT_MUTEX_UNLOCK(&privates->requests[index].mutex);
                                        }
                                        continue;
                                }
@@ -965,718 +1836,123 @@ void *dp_thread_requests_manager(void *arg)
                                index = __get_same_request_index(privates->requests,
                                                command.id);
 
-                               // GET API works even if request is NULL.
-                               dp_request *request = NULL;
-                               if (index >= 0)
-                                       request = privates->requests[index].request;
+                               dp_request_slots *request_slot = NULL;
+                               unsigned is_loaded = 0;
+                               errorcode = DP_ERROR_NONE;
 
-                               // check for all command.
-                               if (request == NULL) {
-                                       int check_id = dp_db_get_int_column(command.id,
-                                                       DP_DB_TABLE_LOG, DP_DB_COL_ID);
-                                       if (check_id < 0 || check_id != command.id) {
-                                               errorcode = DP_ERROR_ID_NOT_FOUND;
-                                               TRACE_ERROR("[ERROR][%d][%s]", command.id,
-                                                       dp_print_errorcode(errorcode));
-                                               dp_ipc_send_errorcode(sock, errorcode);
-                                               continue;
-                                       }
+                               if (index >= 0) {
+                                       CLIENT_MUTEX_LOCK(&privates->requests[index].mutex);
+                                       if (privates->requests[index].request != NULL)
+                                               is_loaded = 1;
+                                       else
+                                               CLIENT_MUTEX_UNLOCK(&privates->requests[index].mutex);
                                }
 
-                               // Authentication by packagename.
-                               char *auth_pkgname = NULL;
-                               errorcode = DP_ERROR_NONE;
-                               if (request != NULL) {
-                                       auth_pkgname = dp_strdup(request->packagename);
-                                       if (auth_pkgname == NULL)
-                                               errorcode = DP_ERROR_OUT_OF_MEMORY;
-                               } else {
-                                       auth_pkgname = dp_db_get_text_column(command.id,
-                                                       DP_DB_TABLE_LOG, DP_DB_COL_PACKAGENAME);
-                                       if (auth_pkgname == NULL)
-                                               errorcode = DP_ERROR_ID_NOT_FOUND;
-                               }
-                               if (errorcode == DP_ERROR_NONE) {
-                                       // auth by pkgname
-                                       if (__cmp_string(group->pkgname, auth_pkgname) < 0) {
-                                               TRACE_ERROR("[ERROR][%d] Auth [%s]/[%s]",
-                                                       command.id, group->pkgname, auth_pkgname);
-                                               errorcode = DP_ERROR_INVALID_PARAMETER;
-                                       }
-                               }
-                               free(auth_pkgname);
-                               if (errorcode != DP_ERROR_NONE) {
-                                       TRACE_ERROR("[ERROR][%d][%s]", command.id,
-                                                       dp_print_errorcode(errorcode));
-                                       dp_ipc_send_errorcode(sock, errorcode);
-                                       continue;
-                               }
+                               errorcode = DP_ERROR_UNKNOWN; // check matched command
 
-                               // if no group, update group.
-                               if (request != NULL && request->group == NULL)
-                                       request->group = group;
+                               // divide on memory or from DB
+                               if (is_loaded == 1 && index >= 0) { // already locked
 
-                               unsigned is_checked = 1;
-                               int read_int = 0;
-                               char *read_str = NULL;
+                                       TRACE_SECURE_INFO("[%s] id:%d sock:%d pid:%d gindex:%d slot:%d pkg:%s",
+                                               __print_command(command.cmd), command.id, sock,
+                                               group->credential.pid, i, index, group->pkgname);
 
-                               // read a interger or a string, return errorcode.
-                               errorcode = DP_ERROR_NONE;
-                               switch(command.cmd) {
-                               case DP_CMD_SET_STATE_CALLBACK:
-                                       if (dp_ipc_read_custom_type(sock, &read_int,
-                                                       sizeof(int)) < 0) {
-                                               errorcode = DP_ERROR_IO_ERROR;
-                                               break;
-                                       }
-                                       errorcode = dp_request_set_state_event(command.id,
-                                                       request, read_int);
-                                       break;
-                               case DP_CMD_SET_PROGRESS_CALLBACK:
-                                       if (dp_ipc_read_custom_type(sock, &read_int,
-                                                       sizeof(int)) < 0) {
-                                               errorcode = DP_ERROR_IO_ERROR;
-                                               break;
-                                       }
-                                       errorcode = dp_request_set_progress_event
-                                                       (command.id, request, read_int);
-                                       break;
-                               case DP_CMD_SET_NETWORK_TYPE:
-                                       if (dp_ipc_read_custom_type(sock, &read_int,
-                                                       sizeof(int)) < 0) {
-                                               errorcode = DP_ERROR_IO_ERROR;
-                                               break;
-                                       }
-                                       errorcode = dp_request_set_network_type(command.id,
-                                                       request, read_int);
-                                       break;
-                               case DP_CMD_SET_AUTO_DOWNLOAD:
-                                       if (dp_ipc_read_custom_type(sock, &read_int,
-                                                       sizeof(int)) < 0) {
-                                               errorcode = DP_ERROR_IO_ERROR;
-                                               break;
-                                       }
-                                       errorcode = dp_request_set_auto_download(command.id,
-                                                       request, read_int);
-                                       break;
-                               case DP_CMD_SET_NOTIFICATION:
-                                       if (dp_ipc_read_custom_type(sock, &read_int,
-                                                       sizeof(int)) < 0) {
-                                               errorcode = DP_ERROR_IO_ERROR;
-                                               break;
-                                       }
-                                       errorcode = dp_request_set_notification(command.id,
-                                                       request, read_int);
-                                       break;
-                               case DP_CMD_SET_URL:
-                                       if ((read_str = dp_ipc_read_string(sock)) == NULL) {
-                                               errorcode = DP_ERROR_IO_ERROR;
-                                               break;
-                                       }
-                                       errorcode = dp_request_set_url(command.id, request,
-                                                       read_str);
-                                       break;
-                               case DP_CMD_SET_DESTINATION:
-                                       if ((read_str = dp_ipc_read_string(sock)) == NULL) {
-                                               errorcode = DP_ERROR_IO_ERROR;
-                                               break;
-                                       }
-                                       errorcode = dp_request_set_destination(command.id,
-                                                       request, read_str);
-                                       break;
-                               case DP_CMD_SET_FILENAME:
-                                       if ((read_str = dp_ipc_read_string(sock)) == NULL) {
-                                               errorcode = DP_ERROR_IO_ERROR;
-                                               break;
-                                       }
-                                       errorcode = dp_request_set_filename(command.id,
-                                                       request, read_str);
-                                       break;
-                               default:
-                                       is_checked = 0;
-                                       break;
-                               }
-                               if (is_checked == 1) {
-                                       free(read_str);
-                                       if (errorcode != DP_ERROR_NONE) {
-                                               TRACE_ERROR("[ERROR][%d][%s][%s]", command.id,
-                                                       __print_command(command.cmd),
-                                                       dp_print_errorcode(errorcode));
-                                       }
-                                       if (errorcode == DP_ERROR_IO_ERROR) {
-                                               FD_CLR(sock, &listen_fdset);
-                                               __clear_group(privates, group);
-                                               privates->groups[i].group = NULL;
+                                       request_slot = &privates->requests[index];
+
+                                       // auth by pkgname
+                                       if (__cmp_string(group->pkgname, request_slot->request->packagename) < 0) {
+                                               TRACE_SECURE_ERROR("[ERROR][%d] Auth [%s]/[%s]",
+                                                       command.id, group->pkgname, request_slot->request->packagename);
+                                               TRACE_ERROR("[ERROR][%d][INVALID_PARAMETER]", command.id);
+                                               dp_ipc_send_errorcode(sock, DP_ERROR_INVALID_PARAMETER);
+                                               CLIENT_MUTEX_UNLOCK(&request_slot->mutex);
                                                continue;
                                        }
-                                       dp_ipc_send_errorcode(sock, errorcode);
-                                       continue;
-                               }
 
-                               // No read(), write a string
-                               read_str = NULL;
-                               errorcode = DP_ERROR_NONE;
-                               is_checked = 1;
-                               switch(command.cmd) {
-                               case DP_CMD_GET_URL:
-                                       read_str = dp_request_get_url(command.id, request,
-                                                       &errorcode);
-                                       break;
-                               case DP_CMD_GET_DESTINATION:
-                                       read_str = dp_request_get_destination(command.id,
-                                                       request, &errorcode);
-                                       break;
-                               case DP_CMD_GET_FILENAME:
-                                       read_str = dp_request_get_filename(command.id,
-                                                       request, &errorcode);
-                                       break;
-                               case DP_CMD_GET_SAVED_PATH:
-                                       read_str = dp_request_get_savedpath(command.id,
-                                                       request, &errorcode);
-                                       break;
-                               case DP_CMD_GET_TEMP_SAVED_PATH:
-                                       read_str = dp_request_get_tmpsavedpath(command.id,
-                                                       request, &errorcode);
-                                       break;
-                               case DP_CMD_GET_MIME_TYPE:
-                                       read_str = dp_request_get_mimetype(command.id,
-                                                       request, &errorcode);
-                                       break;
-                               case DP_CMD_GET_CONTENT_NAME:
-                                       read_str = dp_request_get_contentname(command.id,
-                                                       request, &errorcode);
-                                       break;
-                               case DP_CMD_GET_ETAG:
-                                       read_str = dp_request_get_etag(command.id, request,
-                                                       &errorcode);
-                                       break;
-                               default:
-                                       is_checked = 0;
-                                       break;
-                               }
-                               if (is_checked == 1) {
-                                       if (read_str == NULL || strlen(read_str) < 1)
-                                               errorcode = DP_ERROR_NO_DATA;
-                                       dp_ipc_send_errorcode(sock, errorcode);
-                                       if (errorcode == DP_ERROR_NONE) {
-                                               dp_ipc_send_string(sock, read_str);
-                                       } else {
-                                               TRACE_ERROR("[ERROR][%d][%s][%s]", command.id,
-                                                       __print_command(command.cmd),
-                                                       dp_print_errorcode(errorcode));
-                                       }
-                                       free(read_str);
-                                       continue;
-                               }
+                                       // if no group, update group.
+                                       if (request_slot->request->group == NULL)
+                                               request_slot->request->group = group;
 
-                               // No read(), write a integer variable
-                               read_int = 0;
-                               errorcode = DP_ERROR_NONE;
-                               is_checked = 1;
-                               switch(command.cmd) {
-                               case DP_CMD_GET_NOTIFICATION:
-                                       read_int = dp_db_get_int_column(command.id,
-                                                                       DP_DB_TABLE_REQUEST_INFO,
-                                                                       DP_DB_COL_NOTIFICATION_ENABLE);
-                                       break;
-                               case DP_CMD_GET_AUTO_DOWNLOAD:
-                                       read_int = dp_db_get_int_column(command.id,
-                                                                       DP_DB_TABLE_REQUEST_INFO,
-                                                                       DP_DB_COL_AUTO_DOWNLOAD);
-                                       break;
-                               case DP_CMD_GET_NETWORK_TYPE:
-                                       read_int = dp_db_get_int_column(command.id,
-                                                                       DP_DB_TABLE_REQUEST_INFO,
-                                                                       DP_DB_COL_NETWORK_TYPE);
-                                       break;
-                               case DP_CMD_GET_HTTP_STATUS:
-                                       read_int = dp_db_get_int_column(command.id,
-                                                                       DP_DB_TABLE_DOWNLOAD_INFO,
-                                                                       DP_DB_COL_HTTP_STATUS);
-                                       break;
-                               case DP_CMD_GET_STATE:
-                                       if (request == NULL) {
-                                               read_int = dp_db_get_int_column(command.id,
-                                                               DP_DB_TABLE_LOG, DP_DB_COL_STATE);
-                                       } else {
-                                               CLIENT_MUTEX_LOCK(&request->mutex);
-                                               read_int = request->state;
-                                               CLIENT_MUTEX_UNLOCK(&request->mutex);
-                                       }
-                                       break;
-                               case DP_CMD_GET_ERROR:
-                                       if (request == NULL) {
-                                               read_int = dp_db_get_int_column(command.id,
-                                                               DP_DB_TABLE_LOG, DP_DB_COL_ERRORCODE);
-                                       } else {
-                                               CLIENT_MUTEX_LOCK(&request->mutex);
-                                               read_int = request->error;
-                                               CLIENT_MUTEX_UNLOCK(&request->mutex);
-                                       }
-                                       break;
-                               default:
-                                       is_checked = 0;
-                                       break;
-                               }
-                               if (is_checked == 1) {
-                                       if (read_int < 0)
-                                               errorcode = DP_ERROR_NO_DATA;
-                                       dp_ipc_send_errorcode(sock, errorcode);
-                                       if (errorcode == DP_ERROR_NONE) {
-                                               dp_ipc_send_custom_type(sock, &read_int,
-                                                       sizeof(int));
-                                       } else {
-                                               TRACE_ERROR("[ERROR][%d][%s][%s]", command.id,
-                                                       __print_command(command.cmd),
-                                                       dp_print_errorcode(errorcode));
-                                       }
-                                       continue;
-                               }
-
-                               // No read(), write a long long variable
-                               unsigned long long recv_long = 0;
-                               errorcode = DP_ERROR_NONE;
-                               is_checked = 1;
-                               switch(command.cmd) {
-                               case DP_CMD_GET_RECEIVED_SIZE:
-                                       if (request == NULL) {
-                                               errorcode = DP_ERROR_NO_DATA;
-                                       } else {
-                                               CLIENT_MUTEX_LOCK(&request->mutex);
-                                               recv_long = request->received_size;
-                                               CLIENT_MUTEX_UNLOCK(&request->mutex);
-                                       }
-                                       break;
-                               case DP_CMD_GET_TOTAL_FILE_SIZE:
-                                       if (request != NULL) {
-                                               CLIENT_MUTEX_LOCK(&request->mutex);
-                                               recv_long = request->file_size;
-                                               CLIENT_MUTEX_UNLOCK(&request->mutex);
-                                       } else {
-                                               long long file_size = dp_db_get_int64_column
-                                                               (command.id, DP_DB_TABLE_DOWNLOAD_INFO,
-                                                               DP_DB_COL_CONTENT_SIZE);
-                                               if (file_size < 0)
-                                                       errorcode = DP_ERROR_NO_DATA;
-                                               else // casting
-                                                       recv_long = file_size;
-                                       }
-                                       break;
-                               default:
-                                       is_checked = 0;
-                                       break;
-                               }
-                               if (is_checked == 1) {
-                                       dp_ipc_send_errorcode(sock, errorcode);
-                                       if (errorcode == DP_ERROR_NONE) {
-                                               dp_ipc_send_custom_type(sock, &recv_long,
-                                                       sizeof(unsigned long long));
-                                       } else {
-                                               TRACE_ERROR("[ERROR][%d][%s][%s]", command.id,
-                                                       __print_command(command.cmd),
-                                                       dp_print_errorcode(errorcode));
-                                       }
-                                       continue;
-                               }
+                                       if (command.cmd == DP_CMD_START)
+                                               errorcode = __do_dp_start_command(sock, command.id, privates, group, request_slot->request);
+                                       else if (command.cmd > DP_CMD_SET_SECT && command.cmd < DP_CMD_LAST_SECT)
+                                               errorcode = __dp_do_set_command(sock, &command, request_slot->request);
+                                       else if (command.cmd > DP_CMD_GET_SECT && command.cmd < DP_CMD_SET_SECT)
+                                               errorcode = __dp_do_get_command(sock, &command, request_slot->request);
+                                       else if (command.cmd > DP_CMD_ACTION_SECT && command.cmd < DP_CMD_GET_SECT)
+                                               errorcode = __dp_do_action_command(sock, &command, request_slot->request);
 
-                               read_int = 0;
-                               errorcode = DP_ERROR_NONE;
-                               is_checked = 1;
-                               switch(command.cmd) {
-                               case DP_CMD_DESTROY:
-                                       if (request == NULL) {// just update the state
-                                               if (dp_db_set_column(command.id,
-                                                               DP_DB_TABLE_LOG, DP_DB_COL_STATE,
-                                                               DP_DB_COL_TYPE_INT, &read_int) < 0)
-                                                       errorcode = DP_ERROR_OUT_OF_MEMORY;
-                                               break;
-                                       }
-                                       if (request != NULL) { // call cancel in some cases
-                                               CLIENT_MUTEX_LOCK(&request->mutex);
-                                               if (__is_started(request->state) == 0) {
-                                                       read_int = DP_STATE_CANCELED;
-                                                       if (dp_db_set_column(command.id,
-                                                               DP_DB_TABLE_LOG, DP_DB_COL_STATE,
-                                                               DP_DB_COL_TYPE_INT, &read_int) < 0) {
-                                                               errorcode = DP_ERROR_OUT_OF_MEMORY;
-                                                       } else {
-                                                               if (__dp_call_cancel_agent(request) < 0)
-                                                                       TRACE_INFO("[fail][%d]cancel_agent",
-                                                                               command.id);
-                                                               request->state = DP_STATE_CANCELED;
-                                                       }
-                                               }
-                                               CLIENT_MUTEX_UNLOCK(&request->mutex);
-                                       }
-                                       break;
-                               case DP_CMD_FREE:
-                                       // [destory]-[return]-[free]
-                                       // No return errorcode
-                                       if (request != NULL) {
-                                               dp_request_free(request);
-                                               privates->requests[index].request = NULL;
-                                       }
-                                       break;
-                               case DP_CMD_START:
-                               {
-                                       if (request != NULL) {
-                                               CLIENT_MUTEX_LOCK(&request->mutex);
-                                               if (__is_started(request->state) == 0 ||
-                                                               request->state == DP_STATE_COMPLETED)
-                                                       errorcode = DP_ERROR_INVALID_STATE;
-                                               CLIENT_MUTEX_UNLOCK(&request->mutex);
-                                       }
-                                       if (errorcode != DP_ERROR_NONE)
-                                               break;
-
-                                       // need URL at least
-                                       char *url = dp_request_get_url(command.id, request,
-                                                       &errorcode);
-                                       if (url == NULL) {
-                                               errorcode = DP_ERROR_INVALID_URL;
-                                               break;
-                                       }
-                                       free(url);
+                                       CLIENT_MUTEX_UNLOCK(&request_slot->mutex);
 
-                                       if (request == NULL) { // Support Re-download
-                                               index = __get_empty_request_index
-                                                               (privates->requests);
-                                               if (index < 0) { // Busy, No Space in slot
-                                                       errorcode = DP_ERROR_QUEUE_FULL;
-                                               } else {
-                                                       request = dp_request_load_from_log
-                                                                               (command.id, &errorcode);
-                                                       if (request != NULL) {
-                                                               // restore callback info
-                                                               CLIENT_MUTEX_LOCK(&request->mutex);
-                                                               request->state_cb =
-                                                                       dp_db_get_int_column(command.id,
-                                                                                       DP_DB_TABLE_REQUEST_INFO,
-                                                                                       DP_DB_COL_STATE_EVENT);
-                                                               request->progress_cb =
-                                                                       dp_db_get_int_column(command.id,
-                                                                                       DP_DB_TABLE_REQUEST_INFO,
-                                                                                       DP_DB_COL_PROGRESS_EVENT);
-                                                               privates->requests[index].request =
-                                                                       request;
-                                                               CLIENT_MUTEX_UNLOCK(&request->mutex);
-                                                       }
-                                               }
-                                       }
-                                       if (errorcode != DP_ERROR_NONE)
-                                               break;
-
-                                       dp_state_type state = DP_STATE_QUEUED;
-                                       if (dp_db_set_column(command.id, DP_DB_TABLE_LOG,
-                                                       DP_DB_COL_STATE, DP_DB_COL_TYPE_INT,
-                                                       &state) < 0) {
-                                               errorcode = DP_ERROR_OUT_OF_MEMORY;
-                                       } else {
-                                               group->queued_count++;
-                                               CLIENT_MUTEX_LOCK(&request->mutex);
-                                               request->start_time = (int)time(NULL);
-                                               request->pause_time = 0;
-                                               request->stop_time = 0;
-                                               request->state = state;
-                                               request->error = DP_ERROR_NONE;
-                                               CLIENT_MUTEX_UNLOCK(&request->mutex);
-                                               dp_db_update_date(command.id, DP_DB_TABLE_LOG,
-                                                       DP_DB_COL_ACCESS_TIME);
+                                       if (command.cmd == DP_CMD_START && errorcode == DP_ERROR_NONE) {
                                                //send signal to queue thread
                                                dp_thread_queue_manager_wake_up();
                                        }
-                                       break;
-                               }
-                               case DP_CMD_PAUSE:
-                               {
-                                       // to check fastly, divide the case by request value
-                                       if (request == NULL) {
-                                               dp_state_type state =
-                                                       dp_db_get_int_column(command.id,
-                                                               DP_DB_TABLE_LOG, DP_DB_COL_STATE);
-                                               // already paused or stopped
-                                               if (state > DP_STATE_DOWNLOADING) {
-                                                       errorcode = DP_ERROR_INVALID_STATE;
-                                               } else {
-                                                       // change state to paused.
-                                                       state = DP_STATE_PAUSED;
-                                                       if (dp_db_set_column(command.id,
-                                                                       DP_DB_TABLE_LOG, DP_DB_COL_STATE,
-                                                                       DP_DB_COL_TYPE_INT, &state) < 0)
-                                                               errorcode = DP_ERROR_OUT_OF_MEMORY;
-                                               }
-                                               break;
+                                       if (command.cmd == DP_CMD_FREE) {// enter after unlock
+                                               dp_request_slot_free(request_slot);
+                                               errorcode = DP_ERROR_NONE;
                                        }
 
-                                       CLIENT_MUTEX_LOCK(&request->mutex);
+                               } else { // not found on the slots
 
-                                       if (request->state > DP_STATE_DOWNLOADING) {
-                                               errorcode = DP_ERROR_INVALID_STATE;
-                                               CLIENT_MUTEX_UNLOCK(&request->mutex);
-                                               break;
-                                       }
+                                       TRACE_SECURE_INFO("[%s] id:%d sock:%d pid:%d gindex:%d slot:no pkg:%s",
+                                               __print_command(command.cmd), command.id, sock,
+                                               group->credential.pid, i, group->pkgname);
 
-                                       // before downloading including QUEUED
-                                       if (__is_downloading(request->state) < 0) {
-                                               dp_state_type state = DP_STATE_PAUSED;
-                                               if (dp_db_set_column(command.id,
-                                                               DP_DB_TABLE_LOG, DP_DB_COL_STATE,
-                                                               DP_DB_COL_TYPE_INT, &state) < 0) {
-                                                       errorcode = DP_ERROR_OUT_OF_MEMORY;
-                                               } else {
-                                                       request->state = state;
-                                               }
-                                               CLIENT_MUTEX_UNLOCK(&request->mutex);
-                                               break;
+                                       int check_id = dp_db_get_int_column(command.id,
+                                                       DP_DB_TABLE_LOG, DP_DB_COL_ID);
+                                       if (check_id < 0 || check_id != command.id) {
+                                               errorcode = DP_ERROR_ID_NOT_FOUND;
+                                               TRACE_ERROR("[ERROR][%d][ID_NOT_FOUND]", command.id);
+                                               dp_ipc_send_errorcode(sock, DP_ERROR_ID_NOT_FOUND);
+                                               continue;
                                        }
-                                       // only downloading.
-                                       dp_state_type state = DP_STATE_PAUSE_REQUESTED;
-                                       if (dp_db_set_column(command.id, DP_DB_TABLE_LOG,
-                                                       DP_DB_COL_STATE, DP_DB_COL_TYPE_INT,
-                                                       &state) < 0) {
-                                               errorcode = DP_ERROR_OUT_OF_MEMORY;
-                                       } else {
-                                               TRACE_INFO("[%s][%d]pause_agent(%d) state:%s",
-                                                       __print_command(command.cmd), command.id,
-                                                       request->agent_id,
-                                                       dp_print_state(request->state));
-                                               if (dp_pause_agent_download
-                                                               (request->agent_id) < 0) {
-                                                       TRACE_INFO("[fail][%d]pause_agent(%d)",
-                                                               command.id, request->agent_id);
-                                               }
-                                               request->state = state;
-                                               request->error = DP_ERROR_NONE;
-                                               request->pause_time = (int)time(NULL);
-                                               dp_db_update_date(command.id, DP_DB_TABLE_LOG,
-                                                       DP_DB_COL_ACCESS_TIME);
+                                       // auth by pkgname
+                                       char *auth_pkgname = dp_db_get_text_column(command.id,
+                                                       DP_DB_TABLE_LOG, DP_DB_COL_PACKAGENAME);
+                                       if (auth_pkgname == NULL) {
+                                               TRACE_ERROR("[ERROR][%d][ID_NOT_FOUND]", command.id);
+                                               dp_ipc_send_errorcode(sock, DP_ERROR_ID_NOT_FOUND);
+                                               continue;
                                        }
-                                       CLIENT_MUTEX_UNLOCK(&request->mutex);
-                                       break;
-                               }
-                               case DP_CMD_CANCEL:
-                               {
-                                       // to check fastly, divide the case by request value
-                                       if (request == NULL) {
-                                               dp_state_type state =
-                                                       dp_db_get_int_column(command.id,
-                                                               DP_DB_TABLE_LOG, DP_DB_COL_STATE);
-                                               // already paused or stopped
-                                               if (__is_stopped(state) == 0) {
-                                                       errorcode = DP_ERROR_INVALID_STATE;
-                                               } else {
-                                                       // change state to canceled.
-                                                       state = DP_STATE_CANCELED;
-                                                       if (dp_db_set_column(command.id,
-                                                                       DP_DB_TABLE_LOG, DP_DB_COL_STATE,
-                                                                       DP_DB_COL_TYPE_INT, &state) < 0)
-                                                               errorcode = DP_ERROR_OUT_OF_MEMORY;
-                                               }
-                                               break;
+                                       // auth by pkgname
+                                       if (__cmp_string(group->pkgname, auth_pkgname) < 0) {
+                                               TRACE_SECURE_ERROR("[ERROR][%d] Auth [%s]/[%s]",
+                                                       command.id, group->pkgname, auth_pkgname);
+                                               TRACE_ERROR("[ERROR][%d][INVALID_PARAMETER]", command.id);
+                                               dp_ipc_send_errorcode(sock, DP_ERROR_INVALID_PARAMETER);
+                                               free(auth_pkgname);
+                                               continue;
                                        }
+                                       free(auth_pkgname);
 
-                                       CLIENT_MUTEX_LOCK(&request->mutex);
-
-                                       if (__is_stopped(request->state) == 0) {
-                                               errorcode = DP_ERROR_INVALID_STATE;
-                                       } else {
-                                               // change state to canceled.
-                                               dp_state_type state = DP_STATE_CANCELED;
-                                               if (dp_db_set_column(command.id,
-                                                               DP_DB_TABLE_LOG, DP_DB_COL_STATE,
-                                                               DP_DB_COL_TYPE_INT, &state) < 0)
-                                                       errorcode = DP_ERROR_OUT_OF_MEMORY;
-                                       }
-                                       if (errorcode == DP_ERROR_NONE) {
-                                               TRACE_INFO("[%s][%d]cancel_agent(%d) state:%s",
-                                                       __print_command(command.cmd), command.id,
-                                                       request->agent_id,
-                                                       dp_print_state(request->state));
-                                               if (__dp_call_cancel_agent(request) < 0)
-                                                       TRACE_INFO("[fail][%d]cancel_agent",
-                                                               command.id);
-                                               request->state = DP_STATE_CANCELED;
-                                       }
-                                       CLIENT_MUTEX_UNLOCK(&request->mutex);
-                                       dp_db_update_date(command.id, DP_DB_TABLE_LOG,
-                                                       DP_DB_COL_ACCESS_TIME);
-                                       break;
-                               }
-                               default:
-                                       is_checked = 0;
-                                       break;
-                               }
-                               if (is_checked == 1) {
-                                       if (errorcode != DP_ERROR_NONE) {
-                                               TRACE_ERROR("[ERROR][%d][%s][%s]", command.id,
-                                                       __print_command(command.cmd),
-                                                       dp_print_errorcode(errorcode));
+                                       if (command.cmd == DP_CMD_START)
+                                               errorcode = __do_dp_start_command(sock, command.id, privates, group, NULL);
+                                       else if (command.cmd == DP_CMD_FREE)
+                                               errorcode = DP_ERROR_NONE;
+                                       else if (command.cmd > DP_CMD_SET_SECT && command.cmd < DP_CMD_LAST_SECT)
+                                               errorcode = __dp_do_set_command(sock, &command, NULL);
+                                       else if (command.cmd > DP_CMD_GET_SECT && command.cmd < DP_CMD_SET_SECT)
+                                               errorcode = __dp_do_get_command(sock, &command, NULL);
+                                       else if (command.cmd > DP_CMD_ACTION_SECT && command.cmd < DP_CMD_GET_SECT)
+                                               errorcode = __dp_do_action_command(sock, &command, NULL);
+
+                                       if (command.cmd == DP_CMD_START && errorcode == DP_ERROR_NONE) {
+                                               //send signal to queue thread
+                                               dp_thread_queue_manager_wake_up();
                                        }
-                                       if (command.cmd != DP_CMD_FREE) // free no return
-                                               dp_ipc_send_errorcode(sock, errorcode);
-                                       continue;
                                }
 
-                               // complex read() and write().
-                               char *read_str2 = NULL;
-                               errorcode = DP_ERROR_NONE;
-                               read_str = NULL;
-                               is_checked = 1;
-                               switch(command.cmd) {
-                               case DP_CMD_SET_HTTP_HEADER:
-                               {
-                                       if ((read_str = dp_ipc_read_string(sock)) == NULL) {
-                                               errorcode = DP_ERROR_IO_ERROR;
-                                               break;
-                                       }
-                                       read_str2 = dp_ipc_read_string(sock);
-                                       if (read_str2 == NULL) {
-                                               errorcode = DP_ERROR_IO_ERROR;
-                                               break;
-                                       }
-                                       int conds_count = 3; // id + field + data
-                                       db_conds_list_fmt conds_p[conds_count];
-                                       memset(&conds_p, 0x00,
-                                               conds_count * sizeof(db_conds_list_fmt));
-                                       conds_p[0].column = DP_DB_COL_ID;
-                                       conds_p[0].type = DP_DB_COL_TYPE_INT;
-                                       conds_p[0].value = &command.id;
-                                       conds_p[1].column = DP_DB_COL_HEADER_FIELD;
-                                       conds_p[1].type = DP_DB_COL_TYPE_TEXT;
-                                       conds_p[1].value = read_str;
-                                       conds_p[2].column = DP_DB_COL_HEADER_DATA;
-                                       conds_p[2].type = DP_DB_COL_TYPE_TEXT;
-                                       conds_p[2].value = read_str2;
-                                       if (dp_db_get_conds_rows_count
-                                                       (DP_DB_TABLE_HTTP_HEADERS, DP_DB_COL_ID,
-                                                       "AND", 2, conds_p) <= 0) { // insert
-                                               if (dp_db_insert_columns
-                                                               (DP_DB_TABLE_HTTP_HEADERS, conds_count,
-                                                               conds_p) < 0)
-                                                       errorcode = DP_ERROR_OUT_OF_MEMORY;
-                                       } else { // update data by field
-                                               if (dp_db_cond_set_column(command.id,
-                                                               DP_DB_TABLE_HTTP_HEADERS,
-                                                               DP_DB_COL_HEADER_DATA,
-                                                               DP_DB_COL_TYPE_TEXT, read_str2,
-                                                               DP_DB_COL_HEADER_FIELD,
-                                                               DP_DB_COL_TYPE_TEXT, read_str) < 0)
-                                                       errorcode = DP_ERROR_OUT_OF_MEMORY;
-                                       }
-                                       dp_ipc_send_errorcode(sock, errorcode);
-                                       break;
-                               }
-                               case DP_CMD_DEL_HTTP_HEADER:
-                                       if ((read_str = dp_ipc_read_string(sock)) == NULL) {
-                                               errorcode = DP_ERROR_IO_ERROR;
-                                               break;
-                                       }
-                                       if (dp_db_get_cond_rows_count(command.id,
-                                                       DP_DB_TABLE_HTTP_HEADERS,
-                                                       DP_DB_COL_HEADER_FIELD, DP_DB_COL_TYPE_TEXT,
-                                                       read_str) < 0) {
-                                               errorcode = DP_ERROR_NO_DATA;
-                                       } else {
-                                               if (dp_db_cond_remove(command.id,
-                                                               DP_DB_TABLE_HTTP_HEADERS,
-                                                               DP_DB_COL_HEADER_FIELD,
-                                                               DP_DB_COL_TYPE_TEXT, read_str) < 0)
-                                                       errorcode = DP_ERROR_OUT_OF_MEMORY;
-                                       }
-                                       dp_ipc_send_errorcode(sock, errorcode);
-                                       break;
-                               case DP_CMD_GET_HTTP_HEADER:
-                                       if ((read_str = dp_ipc_read_string(sock)) == NULL) {
-                                               errorcode = DP_ERROR_IO_ERROR;
-                                               break;
-                                       }
-                                       read_str2 = dp_db_cond_get_text_column(command.id,
-                                               DP_DB_TABLE_HTTP_HEADERS, DP_DB_COL_HEADER_DATA,
-                                               DP_DB_COL_HEADER_FIELD, DP_DB_COL_TYPE_TEXT,
-                                               read_str);
-                                       if (read_str2 == NULL)
-                                               errorcode = DP_ERROR_NO_DATA;
-                                       dp_ipc_send_errorcode(sock, errorcode);
-                                       if (errorcode == DP_ERROR_NONE)
-                                               dp_ipc_send_string(sock, read_str2);
-                                       break;
-                               case DP_CMD_GET_HTTP_HEADER_LIST:
-                               {
-                                       char **values = NULL;
-                                       unsigned rows_count = 0;
-                                       errorcode = __dp_get_http_header_fields(sock,
-                                                       command.id, &values, &rows_count);
-                                       if (errorcode == DP_ERROR_NONE) {
-                                               __send_return_custom_type(sock, DP_ERROR_NONE,
-                                                       &rows_count, sizeof(int));
-                                               // sending strings
-                                               int i = 0;
-                                               for (i = 0; i < rows_count; i++) {
-                                                       if (dp_ipc_send_string(sock, values[i]) < 0)
-                                                               break;
-                                               }
-                                               for (i = 0; i < rows_count; i++)
-                                                       free(values[i]);
-                                       } else {
-                                               if (errorcode != DP_ERROR_IO_ERROR)
-                                                       dp_ipc_send_errorcode(sock, errorcode);
-                                       }
-                                       free(values);
-                                       break;
-                               }
-                               case DP_CMD_ADD_EXTRA_PARAM:
-                                       errorcode = __dp_add_extra_param(sock, command.id);
-                                       if (errorcode != DP_ERROR_IO_ERROR)
-                                               dp_ipc_send_errorcode(sock, errorcode);
-                                       break;
-                               case DP_CMD_GET_EXTRA_PARAM:
-                               {
-                                       char **values = NULL;
-                                       unsigned rows_count = 0;
-                                       errorcode = __dp_get_extra_param_values(sock,
-                                                       command.id, &values, &rows_count);
-                                       if (errorcode == DP_ERROR_NONE) {
-                                               __send_return_custom_type(sock, DP_ERROR_NONE,
-                                                       &rows_count, sizeof(int));
-                                               // sending strings
-                                               int i = 0;
-                                               for (i = 0; i < rows_count; i++) {
-                                                       if (dp_ipc_send_string(sock, values[i]) < 0)
-                                                               break;
-                                               }
-                                               for (i = 0; i < rows_count; i++)
-                                                       free(values[i]);
-                                       } else {
-                                               if (errorcode != DP_ERROR_IO_ERROR)
-                                                       dp_ipc_send_errorcode(sock, errorcode);
-                                       }
-                                       free(values);
-                                       break;
-                               }
-                               case DP_CMD_REMOVE_EXTRA_PARAM:
-                                       errorcode =
-                                               __dp_remove_extra_param(sock, command.id);
-                                       if (errorcode != DP_ERROR_IO_ERROR)
-                                               dp_ipc_send_errorcode(sock, errorcode);
-                                       break;
-                               default: // UNKNOWN COMMAND
-                                       is_checked = 0;
-                                       break;
+                               if (errorcode == DP_ERROR_IO_ERROR) {
+                                       TRACE_ERROR("[IO_ERROR][%d] slot:%d pid:%d",
+                                               command.id, i,
+                                               privates->groups[i].group->credential.pid);
+                                       FD_CLR(sock, &listen_fdset);
+                                       __clear_group(privates, group);
+                                       privates->groups[i].group = NULL;
+                                       continue;
                                }
-                               if (is_checked == 1) {
-                                       if (errorcode != DP_ERROR_NONE) {
-                                               TRACE_ERROR("[ERROR][%d][%s][%s]", command.id,
-                                                       __print_command(command.cmd),
-                                                       dp_print_errorcode(errorcode));
-                                               if (errorcode == DP_ERROR_IO_ERROR) {
-                                                       FD_CLR(sock, &listen_fdset);
-                                                       __clear_group(privates, group);
-                                                       privates->groups[i].group = NULL;
-                                               }
-                                       }
-                                       free(read_str);
-                                       free(read_str2);
-                               } else { // UnKnown Command
+                               if (errorcode == DP_ERROR_UNKNOWN) { // UnKnown Command
                                        TRACE_INFO("[UNKNOWN][%d] slot:%d pid:%d",
                                                command.id, i,
                                                privates->groups[i].group->credential.pid);
@@ -1693,10 +1969,14 @@ void *dp_thread_requests_manager(void *arg)
                // timeout
                if (is_timeout == 1) {
                        int now_timeout = (int)time(NULL);
-                       TRACE_INFO("[TIMEOUT] prev %ld, now %ld, setted %ld sec",
+                       TRACE_DEBUG("[TIMEOUT] prev %ld, now %ld, setted %ld sec",
                                prev_timeout, now_timeout, flexible_timeout);
                        if (prev_timeout == 0) {
                                prev_timeout = now_timeout;
+                       } else if (now_timeout < prev_timeout ||
+                               (now_timeout - prev_timeout) > flexible_timeout) {
+                               TRACE_ERROR("[WARN] check system date prev[%ld]now[%ld]",
+                                       prev_timeout, now_timeout);
                        } else {
                                if ((now_timeout - prev_timeout) <
                                                DP_CARE_CLIENT_MIN_INTERVAL) {
@@ -1717,7 +1997,7 @@ void *dp_thread_requests_manager(void *arg)
                                if (old_request_count > DP_LOG_DB_CLEAR_LIMIT_ONE_TIME)
                                        old_request_count = DP_LOG_DB_CLEAR_LIMIT_ONE_TIME;
 
-                               TRACE_INFO
+                               TRACE_DEBUG
                                        ("[CLEAR] [%d] old reqeusts", old_request_count);
 
                                dp_request_slots *old_requests =
@@ -1731,21 +2011,20 @@ void *dp_thread_requests_manager(void *arg)
                                                                (privates->requests,
                                                                old_requests[i].request->id);
                                                if (index >= 0) {
+                                                       CLIENT_MUTEX_LOCK(&privates->requests[index].mutex);
                                                        dp_request *request =
                                                                privates->requests[index].request;
                                                        // if downloading..remain it.
-                                                       CLIENT_MUTEX_LOCK(&request->mutex);
-                                                       if (__is_downloading(request->state) == 0) {
-                                                               CLIENT_MUTEX_UNLOCK(&request->mutex);
+                                                       if (request == NULL || __is_downloading(request->state) == 0) {
+                                                               CLIENT_MUTEX_UNLOCK(&privates->requests[index].mutex);
                                                                continue;
                                                        }
-                                                       CLIENT_MUTEX_UNLOCK(&request->mutex);
-                                                       TRACE_INFO("[CLEAR][%d] 48 hour state:%s",
+                                                       CLIENT_MUTEX_UNLOCK(&privates->requests[index].mutex);
+                                                       TRACE_DEBUG("[CLEAR][%d] 48 hour state:%s",
                                                                request->id,
                                                                dp_print_state(request->state));
                                                        // unload from slots ( memory )
-                                                       dp_request_free(request);
-                                                       privates->requests[index].request = NULL;
+                                                       dp_request_slot_free(&privates->requests[index]);
                                                }
                                                // remove tmp file regardless 
                                                __dp_remove_tmpfile
@@ -1761,28 +2040,28 @@ void *dp_thread_requests_manager(void *arg)
                        // clean slots
                        int ready_requests = 0;
                        for (i = 0; i < DP_MAX_REQUEST; i++) {
-                               if (privates->requests[i].request == NULL)
+                               CLIENT_MUTEX_LOCK(&privates->requests[i].mutex);
+                               if (privates->requests[i].request == NULL) {
+                                       CLIENT_MUTEX_UNLOCK(&privates->requests[i].mutex);
                                        continue;
+                               }
                                dp_request *request = privates->requests[i].request;
 
-                               CLIENT_MUTEX_LOCK(&request->mutex);
-
                                // If downloading is too slow ? how to deal this request?
                                // can limit too slot download using starttime.(48 hours)
                                if (__is_downloading(request->state) == 0) {
-                                       CLIENT_MUTEX_UNLOCK(&request->mutex);
+                                       CLIENT_MUTEX_UNLOCK(&privates->requests[i].mutex);
                                        continue;
                                }
 
                                // paused & agent_id not exist.... unload from memory.
                                if (request->state == DP_STATE_PAUSED &&
                                                dp_is_alive_download(request->agent_id) == 0) {
-                                       CLIENT_MUTEX_UNLOCK(&request->mutex);
-                                       TRACE_INFO("[FREE][%d] dead agent-id(%d) state:%s",
+                                       TRACE_DEBUG("[FREE][%d] dead agent-id(%d) state:%s",
                                                request->id, request->agent_id,
                                                dp_print_state(request->state));
-                                       dp_request_free(request);
-                                       privates->requests[i].request = NULL;
+                                       CLIENT_MUTEX_UNLOCK(&privates->requests[i].mutex);
+                                       dp_request_slot_free(&privates->requests[i]);
                                        continue;
                                }
 
@@ -1794,7 +2073,7 @@ void *dp_thread_requests_manager(void *arg)
                                        int download_id = request->id;
                                        dp_state_type state = DP_STATE_FAILED;
                                        errorcode = DP_ERROR_RESPONSE_TIMEOUT;
-                                       TRACE_INFO
+                                       TRACE_DEBUG
                                                ("[FREE][%d] start in %d sec state:%s last:%ld",
                                                download_id, DP_CARE_CLIENT_MAX_INTERVAL,
                                                dp_print_state(request->state),
@@ -1804,37 +2083,46 @@ void *dp_thread_requests_manager(void *arg)
                                                        request->group->event_socket >= 0)
                                                dp_ipc_send_event(request->group->event_socket,
                                                        download_id, state, errorcode, 0);
-                                       CLIENT_MUTEX_UNLOCK(&request->mutex);
-                                       dp_request_free(request);
-                                       privates->requests[i].request = NULL;
+                                       CLIENT_MUTEX_UNLOCK(&privates->requests[i].mutex);
+                                       dp_request_slot_free(&privates->requests[i]);
                                        // no problem although updating is failed.
-                                       if (dp_db_set_column(download_id, DP_DB_TABLE_LOG,
-                                                       DP_DB_COL_STATE, DP_DB_COL_TYPE_INT,
-                                                       &state) < 0)
-                                               TRACE_ERROR("[fail][%d][sql] set state:%s",
-                                                       download_id, dp_print_state(state));
-                                       if (dp_db_set_column(download_id, DP_DB_TABLE_LOG,
-                                                       DP_DB_COL_ERRORCODE, DP_DB_COL_TYPE_INT,
-                                                       &errorcode) < 0)
-                                               TRACE_ERROR("[fail][%d][sql] set error:%s",
-                                                       download_id, dp_print_errorcode(errorcode));
+                                       if (dp_db_request_update_status(download_id, state, errorcode) < 0) {
+                                               TRACE_ERROR("[fail][%d][sql] set state:%s error:%s",
+                                                       download_id, dp_print_state(state), dp_print_errorcode(errorcode));
+                                       }
                                        continue;
                                }
 
-                               // client should call DESTROY command in 60 sec after finished
+                               // stopped by ipchanged. decide auto resume
+                               if (request->stop_time <= 0 &&
+                                               request->state == DP_STATE_FAILED &&
+                                               request->error == DP_ERROR_CONNECTION_FAILED) {
+                                       if (dp_get_network_connection_instant_status() !=
+                                                       DP_NETWORK_TYPE_OFF &&
+                                                       request->ip_changed == 1) {
+                                               TRACE_DEBUG("[RESUME][%d] will be queued",
+                                                       request->id);
+                                               request->state = DP_STATE_QUEUED;
+                                               request->error = DP_ERROR_NONE;
+                                               ready_requests++;
+                                       } else {
+                                               dp_request_state_response(request);
+                                       }
+                               }
+
+                               // client should call DESTROY command in MAX_INTERVAL sec after finished
                                if (request->stop_time > 0 &&
                                                (now_timeout - request->stop_time) >
                                                DP_CARE_CLIENT_MAX_INTERVAL) {
                                        // check state again. stop_time means it's stopped
                                        if (__is_stopped(request->state) == 0) {
-                                               CLIENT_MUTEX_UNLOCK(&request->mutex);
-                                               TRACE_INFO
+                                               TRACE_DEBUG
                                                        ("[FREE][%d] by timeout state:%s stop:%ld",
                                                        request->id,
                                                        dp_print_state(request->state),
                                                        request->stop_time);
-                                               dp_request_free(request);
-                                               privates->requests[i].request = NULL;
+                                               CLIENT_MUTEX_UNLOCK(&privates->requests[i].mutex);
+                                               dp_request_slot_free(&privates->requests[i]);
                                                continue;
                                        }
                                }
@@ -1843,27 +2131,27 @@ void *dp_thread_requests_manager(void *arg)
                                if (request->state == DP_STATE_QUEUED)
                                        ready_requests++;
 
-                               CLIENT_MUTEX_UNLOCK(&request->mutex);
+                               CLIENT_MUTEX_UNLOCK(&privates->requests[i].mutex);
                        }
 
                        if (ready_requests > 0) {
                                //send signal to queue thread will check queue.
                                dp_thread_queue_manager_wake_up();
                        } else {
-#ifdef DP_SUPPORT_DBUS_ACTIVATION
                                // if no request & timeout is bigger than 60 sec
                                // terminate by self.
                                if ((now_timeout - prev_timeout) >= flexible_timeout &&
                                        dp_get_request_count(privates->requests) <= 0) {
-                                       TRACE_INFO("No Request. Terminate Daemon");
+                                       TRACE_DEBUG("No Request. Terminate Daemon");
                                        break;
                                }
-#endif
                        }
                        prev_timeout = now_timeout;
-               } // timeout
+               } else {
+                       prev_timeout = 0;
+               }
        }
-       TRACE_INFO("terminate main thread ...");
+       TRACE_DEBUG("terminate main thread ...");
        dp_terminate(SIGTERM);
        pthread_exit(NULL);
        return 0;
index b59abe1..96862ec 100755 (executable)
@@ -25,7 +25,7 @@
 #define DP_LOCK_PID "/tmp/download-provider.lock"
 
 #define DP_CARE_CLIENT_MIN_INTERVAL 5
-#define DP_CARE_CLIENT_MAX_INTERVAL 60
+#define DP_CARE_CLIENT_MAX_INTERVAL 120
 
 // check this value should be lower than DP_MAX_REQUEST
 #define DP_MAX_DOWNLOAD_AT_ONCE 50
index f964676..24a7d27 100755 (executable)
  *                             notification    : id, noti_enable, extra_key, extra_data
  */
 /*
+CREATE TABLE IF NOT EXISTS groups
+(
+        id             INTEGER UNIQUE PRIMARY KEY,
+        uid            INTEGER DEFAULT 0,
+        gid            INTEGER DEFAULT 0,
+        extra_int      INTEGER DEFAULT 0,
+        packagename    TEXT DEFAULT NULL,
+        smack_label    TEXT DEFAULT NULL,
+        extra          TEXT DEFAULT NULL,
+        date_first_connected DATE,
+        date_last_connected DATE
+);
+
 CREATE TABLE logging
 (
         id              INTEGER UNIQUE PRIMARY KEY,
@@ -87,6 +100,7 @@ CREATE TABLE notification
 CREATE UNIQUE INDEX requests_index ON logging (id, state, errorcode, packagename, createtime, accesstime);
 */
 
+#define DP_DB_TABLE_GROUPS "groups"
 #define DP_DB_TABLE_LOG "logging"
 #define DP_DB_TABLE_REQUEST_INFO "requestinfo"
 #define DP_DB_TABLE_DOWNLOAD_INFO "downloadinfo"
@@ -120,6 +134,18 @@ CREATE UNIQUE INDEX requests_index ON logging (id, state, errorcode, packagename
 #define DP_DB_COL_EXTRA_KEY "extra_key"
 #define DP_DB_COL_DISTINCT_EXTRA_KEY "DISTINCT extra_key"
 #define DP_DB_COL_EXTRA_VALUE "extra_data"
+#define DP_DB_COL_RAW_BUNDLE_ONGOING "raw_bundle_data_ongoing_state"
+#define DP_DB_COL_RAW_BUNDLE_COMPLETE "raw_bundle_data_complete_state"
+#define DP_DB_COL_RAW_BUNDLE_FAIL "raw_bundle_data_fail_state"
+#define DP_DB_COL_TITLE "title"
+#define DP_DB_COL_DESCRIPTION "description"
+#define DP_DB_COL_NOTI_TYPE "noti_type"
+
+#define DP_DB_GROUPS_COL_UID "uid"
+#define DP_DB_GROUPS_COL_GID "gid"
+#define DP_DB_GROUPS_COL_PKG "packagename"
+#define DP_DB_GROUPS_COL_SMACK_LABEL "smack_label"
+
 
 typedef enum {
        DP_DB_COL_TYPE_NONE = 0,
@@ -138,15 +164,24 @@ typedef struct {
 int dp_db_open();
 void dp_db_close();
 
+int dp_db_is_full_error();
+
 int dp_db_remove_all(int id);
 int dp_db_remove(int id, char *table);
 int dp_db_insert_column(int id, char *table, char *column,
                                                db_column_data_type datatype, void *value);
+int dp_db_insert_blob_column(int id, char *table, char *column,
+                                               void *value, unsigned length);
 int dp_db_set_column(int id, char *table, char *column,
                                                db_column_data_type datatype, void *value);
+int dp_db_set_blob_column(int id, char *table, char *column,
+                                               void *value, unsigned length);
 int dp_db_replace_column(int id, char *table, char *column,
                                                db_column_data_type datatype, void *value);
+int dp_db_replace_blob_column(int id, char *table, char *column,
+                                               void *value, unsigned length);
 char *dp_db_get_text_column(int id, char *table, char *column);
+void *dp_db_get_blob_column(int id, char *table, char *column, int *length);
 int dp_db_get_int_column(int id, char *table, char *column);
 long long dp_db_get_int64_column(int id, char *table, char *column);
 int dp_db_update_date(int id, char *table, char *column);
@@ -166,6 +201,11 @@ int dp_db_get_cond_rows_count(int id, char *table,
                                                char *condcolumn, db_column_data_type condtype,
                                                void *condvalue);
 
+char *dp_db_cond_get_text(char *table, char *column, char *condcolumn,
+                                               db_column_data_type condtype, void *condvalue);
+int dp_db_cond_get_int(char *table, char *column, char *condcolumn,
+                                               db_column_data_type condtype, void *condvalue);
+
 // Special API for http headers
 int dp_db_get_http_headers_list(int id, char **headers);
 
@@ -182,6 +222,8 @@ int dp_db_get_list_by_limit_time(dp_request_slots *requests, int limit);
 
 int dp_db_insert_columns(char *table, int column_count,
                                                db_conds_list_fmt *columns);
+int dp_db_update_columns(int id, char *table, int column_count,
+                                               db_conds_list_fmt *columns);
 
 int dp_db_get_conds_rows_count(char *table, char *getcolumn, char *op,
                                                int conds_count, db_conds_list_fmt *conds);
@@ -192,4 +234,10 @@ int dp_db_get_conds_list(char *table, char *getcolumn,
                                                char *ordercolumn, char *ordering,
                                                char *op, int conds_count,
                                                db_conds_list_fmt *conds);
+
+int dp_db_request_new_logging(const int id, const int state, const char *pkgname);
+int dp_db_request_update_status(const int id, const int state, const int download_error);
+int dp_db_get_state(int id);
+int dp_db_request_new_logging(const int id,
+                                               const int state, const char *pkgname);
 #endif
index 98228fb..af166fd 100755 (executable)
 extern "C" {
 #endif
 
-#ifdef DP_SUPPORT_DBUS_ACTIVATION
-#define DP_DBUS_ACTIVATION
-#define DP_DBUS_SERVICE_DBUS           "org.download-provider"
-#endif
-
 typedef enum {
        DP_STATE_NONE = 0,
        DP_STATE_READY = DP_STATE_NONE + 5, // created id, set some info.
@@ -40,7 +35,7 @@ typedef enum {
 } dp_state_type;
 
 typedef enum {
-       DP_ERROR_NONE = 0,
+       DP_ERROR_NONE = 10,
        DP_ERROR_INVALID_PARAMETER = DP_ERROR_NONE + 1,
        DP_ERROR_OUT_OF_MEMORY = DP_ERROR_NONE + 2,
        DP_ERROR_IO_ERROR = DP_ERROR_NONE + 3,
@@ -59,6 +54,7 @@ typedef enum {
        DP_ERROR_NO_DATA = DP_ERROR_NONE + 17,
        DP_ERROR_UNHANDLED_HTTP_CODE = DP_ERROR_NONE + 18,
        DP_ERROR_CANNOT_RESUME = DP_ERROR_NONE + 19,
+       DP_ERROR_PERMISSION_DENIED = DP_ERROR_NONE + 20,
        DP_ERROR_RESPONSE_TIMEOUT = DP_ERROR_NONE + 50,
        DP_ERROR_REQUEST_TIMEOUT = DP_ERROR_NONE + 55,
        DP_ERROR_SYSTEM_DOWN = DP_ERROR_NONE + 60,
@@ -79,6 +75,18 @@ typedef enum {
        DP_NETWORK_TYPE_WIFI_DIRECT = 4
 } dp_network_type;
 
+typedef enum {
+       DP_NOTIFICATION_BUNDLE_TYPE_ONGOING = 0, // Ongoing, Failed
+       DP_NOTIFICATION_BUNDLE_TYPE_COMPLETE, // Completed
+       DP_NOTIFICATION_BUNDLE_TYPE_FAILED // Failed
+} dp_notification_bundle_type;
+
+typedef enum {
+       DP_NOTIFICATION_TYPE_NONE = 0, // Not register Noti.
+       DP_NOTIFICATION_TYPE_COMPLETE_ONLY, // Success, Failed
+       DP_NOTIFICATION_TYPE_ALL // Ongoing, Success, Failed
+} dp_notification_type;
+
 #ifdef __cplusplus
 }
 #endif
index dc7e7da..e828905 100755 (executable)
 #undef LOG_TAG
 #endif
 #define LOG_TAG "DOWNLOAD_PROVIDER"
-#define TRACE_ERROR(format, ARG...)  \
-{ \
-LOGE(format, ##ARG); \
-}
-#define TRACE_STRERROR(format, ARG...)  \
-{ \
-LOGE(format" [%s]", ##ARG, strerror(errno)); \
-}
-#define TRACE_INFO(format, ARG...)  \
-{ \
-LOGI(format, ##ARG); \
-}
+#define TRACE_DEBUG(format, ARG...) LOGD(format, ##ARG)
+#define TRACE_ERROR(format, ARG...) LOGE(format, ##ARG)
+#define TRACE_STRERROR(format, ARG...) LOGE(format" [%s]", ##ARG, strerror(errno))
+#define TRACE_INFO(format, ARG...) LOGI(format, ##ARG)
+
+#ifdef SECURE_LOGD
+#define TRACE_SECURE_DEBUG(format, ARG...) SECURE_LOGD(format, ##ARG)
+#else
+#define TRACE_SECURE_DEBUG(...) do { } while(0)
+#endif
+#ifdef SECURE_LOGI
+#define TRACE_SECURE_INFO(format, ARG...) SECURE_LOGI(format, ##ARG)
+#else
+#define TRACE_SECURE_INFO(...) do { } while(0)
+#endif
+#ifdef SECURE_LOGE
+#define TRACE_SECURE_ERROR(format, ARG...) SECURE_LOGE(format, ##ARG)
+#else
+#define TRACE_SECURE_ERROR(...) do { } while(0)
+#endif
+
 #else
-#define TRACE_ERROR(format, ARG...) ;
-#define TRACE_STRERROR(format, ARG...) ;
-#define TRACE_INFO(format, ARG...) ;
+#define TRACE_DEBUG(...) do { } while(0)
+#define TRACE_ERROR(...) do { } while(0)
+#define TRACE_STRERROR(...) do { } while(0)
+#define TRACE_INFO(...) do { } while(0)
+#define TRACE_SECURE_DEBUG(...) do { } while(0)
+#define TRACE_SECURE_INFO(...) do { } while(0)
+#define TRACE_SECURE_ERROR(...) do { } while(0)
 #endif
 
 #endif
index dc2dd02..98a9b43 100755 (executable)
@@ -17,6 +17,8 @@
 #ifndef DOWNLOAD_PROVIDER2_NETWORK_H
 #define DOWNLOAD_PROVIDER2_NETWORK_H
 
+#include <net_connection.h>
+
 #include "download-provider.h"
 
 dp_network_type dp_get_network_connection_status(connection_h connection, connection_type_e type);
index 63aee32..bc26953 100755 (executable)
 #define DOWNLOAD_PROVIDER2_REQUEST_H
 
 #include "download-provider.h"
+#include <bundle.h>
 
 // for Debugging
 char *dp_print_state(dp_state_type state);
 char *dp_print_errorcode(dp_error_type errorcode);
 
+int dp_is_smackfs_mounted(void);
 char *dp_strdup(char *src);
 
 dp_error_type dp_request_create(int id, dp_client_group *group, dp_request** empty_slot);
 dp_error_type dp_request_set_url(int id, dp_request *request, char *url);
 dp_error_type dp_request_set_destination(int id, dp_request *request, char *dest);
 dp_error_type dp_request_set_filename(int id, dp_request *request, char *filename);
+dp_error_type dp_request_set_title(int id, dp_request *request, char *filename);
+dp_error_type dp_request_set_bundle(int id, dp_request *request, int type, bundle_raw *b, unsigned length);
+dp_error_type dp_request_set_description(int id, dp_request *request, char *description);
+dp_error_type dp_request_set_noti_type(int id, dp_request *request, unsigned type);
 dp_error_type dp_request_set_notification(int id, dp_request *request, unsigned enable);
 dp_error_type dp_request_set_auto_download(int id, dp_request *request, unsigned enable);
 dp_error_type dp_request_set_state_event(int id, dp_request *request, unsigned enable);
 dp_error_type dp_request_set_progress_event(int id, dp_request *request, unsigned enable);
 dp_error_type dp_request_set_network_type(int id, dp_request *request, int type);
-char *dp_request_get_url(int id, dp_request *request, dp_error_type *errorcode);
+char *dp_request_get_url(int id, dp_error_type *errorcode);
 char *dp_request_get_destination(int id, dp_request *request, dp_error_type *errorcode);
 char *dp_request_get_filename(int id, dp_request *request, dp_error_type *errorcode);
+char *dp_request_get_title(int id, dp_request *request, dp_error_type *errorcode);
+bundle_raw *dp_request_get_bundle(int id, dp_request *request, dp_error_type *errorcode, char* column, int* length);
+char *dp_request_get_description(int id, dp_request *request, dp_error_type *errorcode);
+int dp_request_get_noti_type(int id, dp_request *request, dp_error_type *errorcode);
 char *dp_request_get_contentname(int id, dp_request *request, dp_error_type *errorcode);
 char *dp_request_get_etag(int id, dp_request *request, dp_error_type *errorcode);
 char *dp_request_get_savedpath(int id, dp_request *request, dp_error_type *errorcode);
 char *dp_request_get_tmpsavedpath(int id, dp_request *request, dp_error_type *errorcode);
 char *dp_request_get_mimetype(int id, dp_request *request, dp_error_type *errorcode);
+char *dp_request_get_pkg_name(int id, dp_request *request, dp_error_type *errorcode);
 dp_request *dp_request_load_from_log(int id, dp_error_type *errorcode);
+void dp_request_state_response(dp_request *request);
 #endif
index cccbddf..53859f8 100755 (executable)
@@ -39,6 +39,7 @@ typedef struct {
        // fill by app-manager
        char *pkgname;
        dp_credential credential;
+       char *smack_label;
 } dp_client_group;
 
 typedef struct {
@@ -53,6 +54,7 @@ typedef struct {
        unsigned progress_cb; // set : 1 unset : 0
        unsigned startcount;
        unsigned auto_notification;
+       unsigned ip_changed;
        dp_state_type state; // downloading state
        dp_error_type error;
        dp_network_type network_type;
@@ -60,9 +62,7 @@ typedef struct {
        unsigned long long received_size; // progress
        unsigned long long file_size;
        char *packagename;
-       dp_credential credential;
        dp_client_group *group; // indicate dp_client_group included this request
-       pthread_mutex_t mutex;
 } dp_request;
 
 typedef struct {
@@ -70,6 +70,7 @@ typedef struct {
 } dp_group_slots;
 
 typedef struct {
+       pthread_mutex_t mutex;
        dp_request *request;
 } dp_request_slots;
 
@@ -82,6 +83,7 @@ int dp_client_group_slots_free(dp_group_slots *slots, int size);
 dp_request *dp_request_new();
 void dp_request_init(dp_request *request);
 int dp_request_free(dp_request *request);
+int dp_request_slot_free(dp_request_slots *request_slot);
 int dp_request_slots_free(dp_request_slots *slots, int size);
 int dp_get_request_count(dp_request_slots *slots);
 
index 7ec708a..b5a37cb 100755 (executable)
@@ -17,6 +17,7 @@
 #ifndef DOWNLOAD_PROVIDER2_SOCKET_H
 #define DOWNLOAD_PROVIDER2_SOCKET_H
 
+#include <bundle.h>
 #include "download-provider.h"
 #include "download-provider-slots.h"
 
@@ -31,7 +32,9 @@ int dp_ipc_send_stateinfo(int fd, int id, dp_state_type state,
        dp_error_type errorcode);
 #endif
 char *dp_ipc_read_string(int fd);
+unsigned dp_ipc_read_bundle(int fd, int *type, bundle_raw **b);
 int dp_ipc_send_string(int fd, const char *str);
+int dp_ipc_send_bundle(int fd, bundle_raw *b, unsigned length);
 int dp_ipc_send_custom_type(int fd, void *value, size_t type_size);
 int dp_ipc_read_custom_type(int fd, void *value, size_t type_size);
 int dp_accept_socket_new();
index 4968c2a..a1f22f3 100755 (executable)
@@ -29,53 +29,70 @@ extern "C" {
 #define DP_MAX_STR_LEN 256
 #define DP_MAX_PATH_LEN DP_MAX_STR_LEN
 #define DP_MAX_URL_LEN 2048
+#define DP_DEFAULT_BUFFER_SIZE 1024
 
 typedef enum {
        DP_CMD_NONE = 0,
-       DP_CMD_CREATE = DP_CMD_NONE + 1,
-       DP_CMD_START = DP_CMD_NONE + 2,
-       DP_CMD_PAUSE = DP_CMD_NONE + 3,
-       DP_CMD_CANCEL = DP_CMD_NONE + 4,
-       DP_CMD_DESTROY = DP_CMD_NONE + 9,
-       DP_CMD_FREE = DP_CMD_NONE + 10,
-       DP_CMD_ECHO = DP_CMD_NONE + 15,
-       DP_CMD_SET_URL = DP_CMD_NONE + 21,
-       DP_CMD_SET_DESTINATION = DP_CMD_NONE + 22,
-       DP_CMD_SET_FILENAME = DP_CMD_NONE + 23,
-       DP_CMD_SET_NOTIFICATION = DP_CMD_NONE + 24,
-       DP_CMD_SET_STATE_CALLBACK = DP_CMD_NONE + 25,
-       DP_CMD_SET_PROGRESS_CALLBACK = DP_CMD_NONE + 26,
-       DP_CMD_SET_AUTO_DOWNLOAD = DP_CMD_NONE + 28,
-       DP_CMD_SET_NETWORK_TYPE = DP_CMD_NONE + 29,
-       DP_CMD_SET_HTTP_HEADER = DP_CMD_NONE + 30,
-       DP_CMD_SET_EXTRA_PARAM = DP_CMD_NONE + 31, // prevent build error
-       DP_CMD_DEL_HTTP_HEADER = DP_CMD_NONE + 35,
-       DP_CMD_GET_URL = DP_CMD_NONE + 41,
-       DP_CMD_GET_DESTINATION = DP_CMD_NONE + 42,
-       DP_CMD_GET_FILENAME = DP_CMD_NONE + 43,
-       DP_CMD_GET_NOTIFICATION = DP_CMD_NONE + 44,
-       DP_CMD_GET_STATE_CALLBACK = DP_CMD_NONE + 45,
-       DP_CMD_GET_PROGRESS_CALLBACK = DP_CMD_NONE + 46,
-       DP_CMD_GET_HTTP_HEADERS = DP_CMD_NONE + 47,
-       DP_CMD_GET_AUTO_DOWNLOAD = DP_CMD_NONE + 48,
-       DP_CMD_GET_NETWORK_TYPE = DP_CMD_NONE + 49,
-       DP_CMD_GET_SAVED_PATH = DP_CMD_NONE + 50,
-       DP_CMD_GET_TEMP_SAVED_PATH = DP_CMD_NONE + 51,
-       DP_CMD_GET_MIME_TYPE = DP_CMD_NONE + 52,
-       DP_CMD_GET_HTTP_HEADER = DP_CMD_NONE + 53,
-       DP_CMD_GET_HTTP_HEADER_LIST = DP_CMD_NONE + 54,
-       DP_CMD_ADD_EXTRA_PARAM = DP_CMD_NONE + 63,
-       DP_CMD_GET_EXTRA_PARAM = DP_CMD_NONE + 64,
-       DP_CMD_REMOVE_EXTRA_PARAM = DP_CMD_NONE + 65,
-       DP_CMD_GET_RECEIVED_SIZE = DP_CMD_NONE + 71,
-       DP_CMD_GET_TOTAL_FILE_SIZE = DP_CMD_NONE + 72,
-       DP_CMD_GET_CONTENT_NAME = DP_CMD_NONE + 73,
-       DP_CMD_GET_HTTP_STATUS = DP_CMD_NONE + 74,
-       DP_CMD_GET_ETAG = DP_CMD_NONE + 75,
-       DP_CMD_GET_STATE = DP_CMD_NONE + 81,
-       DP_CMD_GET_ERROR = DP_CMD_NONE + 91,
-       DP_CMD_SET_COMMAND_SOCKET = DP_CMD_NONE + 100,
-       DP_CMD_SET_EVENT_SOCKET = DP_CMD_NONE + 101
+       DP_CMD_ECHO,
+       DP_CMD_CREATE,
+       DP_CMD_START,
+       DP_CMD_SET_COMMAND_SOCKET,
+       DP_CMD_SET_EVENT_SOCKET,
+       DP_CMD_FREE,
+
+       DP_CMD_ACTION_SECT = 100,
+       DP_CMD_PAUSE,
+       DP_CMD_CANCEL,
+       DP_CMD_DESTROY,
+
+       DP_CMD_GET_SECT = 200,
+       DP_CMD_GET_URL,
+       DP_CMD_GET_DESTINATION,
+       DP_CMD_GET_FILENAME,
+       DP_CMD_GET_NOTIFICATION,
+       DP_CMD_GET_STATE_CALLBACK,
+       DP_CMD_GET_PROGRESS_CALLBACK,
+       DP_CMD_GET_HTTP_HEADERS,
+       DP_CMD_GET_AUTO_DOWNLOAD,
+       DP_CMD_GET_NETWORK_TYPE,
+       DP_CMD_GET_SAVED_PATH,
+       DP_CMD_GET_TEMP_SAVED_PATH,
+       DP_CMD_GET_MIME_TYPE,
+       DP_CMD_GET_HTTP_HEADER,
+       DP_CMD_GET_HTTP_HEADER_LIST,
+       DP_CMD_GET_EXTRA_PARAM,
+       DP_CMD_GET_RECEIVED_SIZE,
+       DP_CMD_GET_TOTAL_FILE_SIZE,
+       DP_CMD_GET_CONTENT_NAME,
+       DP_CMD_GET_HTTP_STATUS,
+       DP_CMD_GET_ETAG,
+       DP_CMD_GET_STATE,
+       DP_CMD_GET_ERROR,
+       DP_CMD_GET_NOTIFICATION_BUNDLE,
+       DP_CMD_GET_NOTIFICATION_TITLE,
+       DP_CMD_GET_NOTIFICATION_DESCRIPTION,
+       DP_CMD_GET_NOTIFICATION_TYPE,
+
+       DP_CMD_SET_SECT = 300,
+       DP_CMD_SET_URL,
+       DP_CMD_SET_DESTINATION,
+       DP_CMD_SET_FILENAME,
+       DP_CMD_SET_NOTIFICATION,
+       DP_CMD_SET_STATE_CALLBACK,
+       DP_CMD_SET_PROGRESS_CALLBACK,
+       DP_CMD_SET_AUTO_DOWNLOAD,
+       DP_CMD_SET_NETWORK_TYPE,
+       DP_CMD_SET_HTTP_HEADER,
+       DP_CMD_SET_EXTRA_PARAM, // prevent build error
+       DP_CMD_DEL_HTTP_HEADER,
+       DP_CMD_ADD_EXTRA_PARAM,
+       DP_CMD_REMOVE_EXTRA_PARAM,
+       DP_CMD_SET_NOTIFICATION_BUNDLE,
+       DP_CMD_SET_NOTIFICATION_TITLE,
+       DP_CMD_SET_NOTIFICATION_DESCRIPTION,
+       DP_CMD_SET_NOTIFICATION_TYPE,
+
+       DP_CMD_LAST_SECT = 400
 } dp_command_type;
 
 typedef struct {
diff --git a/res/images/Notification_download_animation.gif b/res/images/Notification_download_animation.gif
new file mode 100644 (file)
index 0000000..17dd2bb
Binary files /dev/null and b/res/images/Notification_download_animation.gif differ
diff --git a/res/images/Q02_Notification_Download_failed.png b/res/images/Q02_Notification_Download_failed.png
deleted file mode 100644 (file)
index 04ec4f0..0000000
Binary files a/res/images/Q02_Notification_Download_failed.png and /dev/null differ
diff --git a/res/images/Q02_Notification_download_complete.png b/res/images/Q02_Notification_download_complete.png
new file mode 100644 (file)
index 0000000..7a11f3e
Binary files /dev/null and b/res/images/Q02_Notification_download_complete.png differ
diff --git a/res/images/Q02_Notification_download_failed.png b/res/images/Q02_Notification_download_failed.png
new file mode 100644 (file)
index 0000000..d59dd6f
Binary files /dev/null and b/res/images/Q02_Notification_download_failed.png differ
similarity index 69%
rename from packaging/download-provider.service
rename to systemd/download-provider.service
index da1ea5f..30b14d7 100644 (file)
@@ -1,10 +1,11 @@
 [Unit]
 Description=Download provider service
+After=check-mount.service
 
 [Service]
 Type=simple
 ExecStart=/usr/bin/download-provider
 
 [Install]
-WantedBy=tizen-middleware.target
+WantedBy=graphical.target
 
diff --git a/systemd/download-provider.socket b/systemd/download-provider.socket
new file mode 100644 (file)
index 0000000..944b28d
--- /dev/null
@@ -0,0 +1,6 @@
+[Socket]
+ListenStream=/tmp/download-provider
+SocketMode=0777
+
+[Install]
+WantedBy=sockets.target