Code Sync with Private GIT
authorBang Kwang min <justine.bang@samsung.com>
Mon, 27 Aug 2012 08:49:37 +0000 (17:49 +0900)
committerBang Kwang min <justine.bang@samsung.com>
Mon, 27 Aug 2012 08:49:37 +0000 (17:49 +0900)
changes )
Change the ownership of downloaded file
Add detached option when pthread is created
fix the failure getting history info from database
Resolve prevent defects for agent module
divide log level
fix the crash by double free
fix wrong checking of network status
fix first timeout takes a long time

12 files changed:
include/download-provider-log.h
src/agent/download-agent-basic.c
src/agent/download-agent-client-mgr.c
src/agent/download-agent-dl-info-util.c
src/agent/download-agent-dl-mgr.c
src/agent/download-agent-file.c
src/agent/download-agent-http-mgr.c
src/download-provider-db.c
src/download-provider-ipc.c
src/download-provider-main.c
src/download-provider-receiver.c
src/download-provider-utils.c

index 2416844..3f78795 100644 (file)
 #define LOG_TAG "download-provider"
 #define TRACE_DEBUG_MSG(format, ARG...)  \
 { \
-LOGD(format"[%s][%d]", ##ARG, __FUNCTION__, __LINE__); \
+LOGE(format"[%s][%d]", ##ARG, __FUNCTION__, __LINE__); \
+}
+#define TRACE_DEBUG_INFO_MSG(format, ARG...)  \
+{ \
+LOGI(format"[%s][%d]", ##ARG, __FUNCTION__, __LINE__); \
 }
-
 #else
 #define TRACE_DEBUG_MSG(format, ARG...) ;
 #endif
index db40f45..d069e7e 100644 (file)
@@ -64,6 +64,7 @@ da_result_t start_download_with_extension(
        client_input_t *client_input = DA_NULL;
        client_input_basic_t *client_input_basic = DA_NULL;
        download_thread_input *thread_info = DA_NULL;
+       pthread_attr_t thread_attr;
 
        DA_LOG_FUNC_START(Default);
 
@@ -132,7 +133,7 @@ da_result_t start_download_with_extension(
        }
 
        thread_info = (download_thread_input *)calloc(1, sizeof(download_thread_input));
-       if(!thread_info) {
+       if (!thread_info) {
                DA_LOG_ERR(Default, "DA_ERR_FAIL_TO_MEMALLOC");
                ret = DA_ERR_FAIL_TO_MEMALLOC;
                goto ERR;
@@ -140,8 +141,18 @@ da_result_t start_download_with_extension(
                thread_info->download_id = download_id;
                thread_info->client_input = client_input;
        }
+       if (pthread_attr_init(&thread_attr) != 0) {
+               ret = DA_ERR_FAIL_TO_CREATE_THREAD;
+               goto ERR;
+       }
+
+       if (pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED) != 0) {
+               ret = DA_ERR_FAIL_TO_CREATE_THREAD;
+               goto ERR;
+       }
 
-       if(pthread_create(&GET_DL_THREAD_ID(download_id), DA_NULL, __thread_start_download, thread_info) < 0) {
+       if (pthread_create(&GET_DL_THREAD_ID(download_id), &thread_attr,
+                       __thread_start_download, thread_info) < 0) {
                DA_LOG_ERR(Thread, "making thread failed..");
                ret = DA_ERR_FAIL_TO_CREATE_THREAD;
        } else {
index c9c04b3..4575fd7 100644 (file)
@@ -304,11 +304,12 @@ da_result_t  send_client_update_dl_info (
        if (http_response_header) {
                update_dl_info->http_response_header = strdup(http_response_header);
        }
-       if (http_chunked_data)
+       if (http_chunked_data) {
                update_dl_info->http_chunked_data = calloc (1, file_size);
                if (update_dl_info->http_chunked_data)
                        memcpy(update_dl_info->http_chunked_data, http_chunked_data,
                                file_size);
+       }
        DA_LOG(ClientNoti, "pushing file_size=%lu, download_id=%d, dl_req_id=%d",
                        file_size, download_id, dl_req_id);
 
index bf78d9d..98e8ff1 100644 (file)
@@ -102,9 +102,12 @@ da_result_t deinit_download_mgr(void) {
                        if (dl_info && dl_info->is_using) {
                                request_to_abort_http_download(GET_DL_CURRENT_STAGE(i));
                                DA_LOG_CRITICAL(Thread, "===download id[%d] thread id[%lu] join===",i, GET_DL_THREAD_ID(i));
+/* Because the download daemon can call the deinit function, the resources of pthread are not freed
+   FIXME later : It is needed to change the termination flow again.
                if (pthread_join(GET_DL_THREAD_ID(i), &t_return) < 0) {
                        DA_LOG_ERR(Thread, "join client thread is failed!!!");
                }
+*/
                DA_LOG_CRITICAL(Thread, "===download id[%d] thread join return[%d]===",i, (char*)t_return);
 }
 }
index fc654d4..c00d8a5 100644 (file)
@@ -160,9 +160,6 @@ static da_result_t __cancel_download_with_download_id(int download_id)
        }
        _da_thread_mutex_unlock (&mutex_download_state[download_id]);
 
-       if (ret != DA_RESULT_OK)
-               goto ERR;
-
        stage = GET_DL_CURRENT_STAGE(download_id);
        if (!stage)
                return DA_RESULT_OK;
@@ -278,9 +275,6 @@ static da_result_t __suspend_download_with_download_id(int download_id)
        DA_LOG(Default, "download_state = %d", GET_DL_STATE_ON_ID(download_id));
        _da_thread_mutex_unlock (&mutex_download_state[download_id]);
 
-       if (ret != DA_RESULT_OK)
-               goto ERR;
-
        stage = GET_DL_CURRENT_STAGE(download_id);
        if (!stage)
                return DA_ERR_CANNOT_SUSPEND;
@@ -390,9 +384,6 @@ static da_result_t __resume_download_with_download_id(int download_id)
        DA_LOG(Default, "download_state = %d", GET_DL_STATE_ON_ID(download_id));
        _da_thread_mutex_unlock (&mutex_download_state[download_id]);
 
-       if (ret != DA_RESULT_OK)
-               goto ERR;
-
        stage = GET_DL_CURRENT_STAGE(download_id);
 
        ret = request_to_resume_http_download(stage);
index 1f29205..cd5d4ad 100644 (file)
@@ -490,9 +490,6 @@ da_result_t __get_candidate_file_name(stage_info *stage, char **out_pure_file_na
        return DA_RESULT_OK;
 
 ERR:
-       if (pure_file_name)
-               free(pure_file_name);
-
        if (extension)
                free(extension);
 
index 02813d9..7f3b36f 100644 (file)
@@ -1686,10 +1686,6 @@ ERR:
                free(field);
                field = NULL;
        }
-       if (value) {
-               free(value);
-               value = NULL;
-       }
        return;
 }
 
index 06726b3..5e63b3a 100644 (file)
@@ -608,14 +608,10 @@ void download_provider_db_info_free(download_dbinfo *info)
        if (info->saved_path)
                free(info->saved_path);
        info->saved_path = NULL;
-       free(info);
-       info = NULL;
 }
 
 void download_provider_db_list_free(download_dbinfo_list *list)
 {
-       TRACE_DEBUG_MSG("");
-
        int i = 0;
        if (!list)
                return;
@@ -745,6 +741,7 @@ download_dbinfo *download_provider_db_get_info(int requestid)
                                sqlite3_errmsg(g_download_provider_db), errorcode);
                __download_provider_db_close();
                download_provider_db_info_free(dbinfo);
+               free(dbinfo);
                return NULL;
        }
        _download_provider_sql_close(stmt);
@@ -1016,7 +1013,7 @@ download_dbinfo *download_provider_db_history_get_info(int requestid)
 
        errorcode =
                sqlite3_prepare_v2(g_download_provider_db,
-                       "SELECT uniqueid, packagename, notification, installpath, filename, creationdate, state, url, mimetype, savedpath FROM history WHERE uniqueid = ?",
+                       "SELECT packagename, filename, creationdate, state, mimetype, savedpath FROM history WHERE uniqueid = ?",
                        -1, &stmt, NULL);
        if (errorcode != SQLITE_OK) {
                TRACE_DEBUG_MSG("sqlite3_prepare_v2 is failed. [%s]",
@@ -1033,8 +1030,8 @@ download_dbinfo *download_provider_db_history_get_info(int requestid)
 
        if ((errorcode = sqlite3_step(stmt)) == SQLITE_ROW) {
                dbinfo = (download_dbinfo *) calloc(1, sizeof(download_dbinfo));
-               dbinfo->requestid = sqlite3_column_int(stmt, 0);
-               buffer = (char *)(sqlite3_column_text(stmt, 1));
+               dbinfo->requestid = requestid;
+               buffer = (char *)(sqlite3_column_text(stmt, 0));
                dbinfo->packagename = NULL;
                if (buffer) {
                        buffer_length = strlen(buffer);
@@ -1044,18 +1041,7 @@ download_dbinfo *download_provider_db_history_get_info(int requestid)
                                        buffer_length * sizeof(char));
                        dbinfo->packagename[buffer_length] = '\0';
                }
-               dbinfo->notification = sqlite3_column_int(stmt, 2);
-               buffer = (char *)(sqlite3_column_text(stmt, 3));
-               dbinfo->installpath = NULL;
-               if (buffer) {
-                       buffer_length = strlen(buffer);
-                       dbinfo->installpath
-                               = (char *)calloc(buffer_length + 1, sizeof(char));
-                       memcpy(dbinfo->installpath, buffer,
-                                       buffer_length * sizeof(char));
-                       dbinfo->installpath[buffer_length] = '\0';
-               }
-               buffer = (char *)(sqlite3_column_text(stmt, 4));
+               buffer = (char *)(sqlite3_column_text(stmt, 1));
                dbinfo->filename = NULL;
                if (buffer) {
                        buffer_length = strlen(buffer);
@@ -1065,7 +1051,7 @@ download_dbinfo *download_provider_db_history_get_info(int requestid)
                                        buffer_length * sizeof(char));
                        dbinfo->filename[buffer_length] = '\0';
                }
-               buffer = (char *)(sqlite3_column_text(stmt, 5));
+               buffer = (char *)(sqlite3_column_text(stmt, 2));
                dbinfo->createdate = NULL;
                if (buffer) {
                        buffer_length = strlen(buffer);
@@ -1075,18 +1061,8 @@ download_dbinfo *download_provider_db_history_get_info(int requestid)
                                        buffer_length * sizeof(char));
                        dbinfo->createdate[buffer_length] = '\0';
                }
-               dbinfo->state = sqlite3_column_int(stmt, 6);
-               buffer = (char *)(sqlite3_column_text(stmt, 7));
-               dbinfo->url = NULL;
-               if (buffer) {
-                       buffer_length = strlen(buffer);
-                       dbinfo->url
-                               = (char *)calloc(buffer_length + 1, sizeof(char));
-                       memcpy(dbinfo->url, buffer,
-                                       buffer_length * sizeof(char));
-                       dbinfo->url[buffer_length] = '\0';
-               }
-               buffer = (char *)(sqlite3_column_text(stmt, 8));
+               dbinfo->state = sqlite3_column_int(stmt, 3);
+               buffer = (char *)(sqlite3_column_text(stmt, 4));
                dbinfo->mimetype = NULL;
                if (buffer) {
                        buffer_length = strlen(buffer);
@@ -1096,7 +1072,7 @@ download_dbinfo *download_provider_db_history_get_info(int requestid)
                                        buffer_length * sizeof(char));
                        dbinfo->mimetype[buffer_length] = '\0';
                }
-               buffer = (char *)(sqlite3_column_text(stmt, 9));
+               buffer = (char *)(sqlite3_column_text(stmt, 5));
                dbinfo->saved_path = NULL;
                if (buffer) {
                        buffer_length = strlen(buffer);
@@ -1111,6 +1087,7 @@ download_dbinfo *download_provider_db_history_get_info(int requestid)
                                sqlite3_errmsg(g_download_provider_db), errorcode);
                __download_provider_db_close();
                download_provider_db_info_free(dbinfo);
+               free(dbinfo);
                return NULL;
        }
        _download_provider_sql_close(stmt);
index 7cfb54f..18627a8 100644 (file)
@@ -162,7 +162,7 @@ int ipc_receive_request_msg(download_clientinfo *clientinfo)
                                                                requestinfo->
                                                                client_packagename.
                                                                length] = '\0';
-               TRACE_DEBUG_MSG("request client_packagename [%s]",
+               TRACE_DEBUG_INFO_MSG("request client_packagename [%s]",
                                clientinfo->requestinfo->client_packagename.
                                str);
        }
@@ -179,7 +179,7 @@ int ipc_receive_request_msg(download_clientinfo *clientinfo)
                }
                clientinfo->requestinfo->url.str[clientinfo->requestinfo->url.
                                                        length] = '\0';
-               TRACE_DEBUG_MSG("request url [%s]",
+               TRACE_DEBUG_INFO_MSG("request url [%s]",
                                clientinfo->requestinfo->url.str);
        }
        if (clientinfo->requestinfo->install_path.length > 1) {
@@ -201,7 +201,7 @@ int ipc_receive_request_msg(download_clientinfo *clientinfo)
                                                                requestinfo->
                                                                install_path.length] =
                        '\0';
-               TRACE_DEBUG_MSG("request install_path [%s]",
+               TRACE_DEBUG_INFO_MSG("request install_path [%s]",
                                clientinfo->requestinfo->install_path.str);
        }
        if (clientinfo->requestinfo->filename.length > 1) {
@@ -221,7 +221,7 @@ int ipc_receive_request_msg(download_clientinfo *clientinfo)
                }
                clientinfo->requestinfo->filename.str[clientinfo->requestinfo->
                                                                filename.length] = '\0';
-               TRACE_DEBUG_MSG("request filename [%s]",
+               TRACE_DEBUG_INFO_MSG("request filename [%s]",
                                clientinfo->requestinfo->filename.str);
        }
        if (clientinfo->requestinfo->service_data.length > 1) {
@@ -289,7 +289,7 @@ int ipc_receive_request_msg(download_clientinfo *clientinfo)
                                return -1;
                        }
                        if (clientinfo->requestinfo->headers.str[i].length > 1) {
-                               TRACE_DEBUG_MSG("headers[%d] length[%d]", i,
+                               TRACE_DEBUG_INFO_MSG("headers[%d] length[%d]", i,
                                                clientinfo->requestinfo->
                                                headers.str[i].length);
                                clientinfo->requestinfo->headers.str[i].str =
@@ -310,7 +310,7 @@ int ipc_receive_request_msg(download_clientinfo *clientinfo)
                                clientinfo->requestinfo->headers.str[i].
                                        str[clientinfo->requestinfo->headers.str[i].
                                        length] = '\0';
-                               TRACE_DEBUG_MSG("headers[%d][%s]", i,
+                               TRACE_DEBUG_INFO_MSG("headers[%d][%s]", i,
                                                clientinfo->requestinfo->
                                                headers.str[i].str);
                        }
index 907a22e..46a0334 100644 (file)
@@ -16,7 +16,7 @@ void *run_manage_download_server(void *args);
 
 void TerminateDaemon(int signo)
 {
-       TRACE_DEBUG_MSG("Received SIGTERM");
+       TRACE_DEBUG_INFO_MSG("Received SIGTERM");
        if (g_main_loop_is_running(gMainLoop))
                g_main_loop_quit(gMainLoop);
 }
@@ -81,7 +81,7 @@ int main()
 
        g_main_loop_run(gMainLoop);
 
-       TRACE_DEBUG_MSG("Download-Provider will be terminated.");
+       TRACE_DEBUG_INFO_MSG("Download-Provider will be terminated.");
 
        pthread_cancel(gRequestThreadPid);
        pthread_join(gRequestThreadPid, NULL);
index 452ab69..2af1fb0 100644 (file)
@@ -170,7 +170,7 @@ void *_start_download(void *args)
 
        // 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_DEBUG_MSG("change to pended request [%d]", da_ret);
+               TRACE_DEBUG_INFO_MSG("change to pended request [%d]", da_ret);
                CLIENT_MUTEX_LOCK(&(clientinfo->client_mutex));
                clientinfo->state = DOWNLOAD_STATE_PENDED;
                clientinfo->err = DOWNLOAD_ERROR_TOO_MANY_DOWNLOADS;
@@ -180,7 +180,7 @@ void *_start_download(void *args)
                CLIENT_MUTEX_UNLOCK(&(clientinfo->client_mutex));
                return 0;
        } else if (da_ret != DA_RESULT_OK) {
-               TRACE_DEBUG_MSG("Fail to request start [%d]", da_ret);
+               TRACE_DEBUG_INFO_MSG("Fail to request start [%d]", da_ret);
                /* FIXME : need to seperate in detail according to error return values */
                CLIENT_MUTEX_LOCK(&(clientinfo->client_mutex));
                clientinfo->state = DOWNLOAD_STATE_FAILED;
@@ -194,7 +194,7 @@ void *_start_download(void *args)
 
        CLIENT_MUTEX_LOCK(&(clientinfo->client_mutex));
 
-       TRACE_DEBUG_MSG("started download [%d]", da_ret);
+       TRACE_DEBUG_INFO_MSG("started download [%d]", da_ret);
 
        clientinfo->req_id = req_dl_id;
        clientinfo->state = DOWNLOAD_STATE_DOWNLOADING;
@@ -229,7 +229,7 @@ int _handle_new_connection(download_clientinfo_slot *clientinfo_list, download_c
                (request_clientinfo->clientfd, SOL_SOCKET,
                SO_PEERCRED, &request_clientinfo->credentials,
                &cr_len) == 0) {
-               TRACE_DEBUG_MSG
+               TRACE_DEBUG_INFO_MSG
                        ("Client Info : pid=%d, uid=%d, gid=%d\n",
                        request_clientinfo->credentials.pid,
                        request_clientinfo->credentials.uid,
@@ -239,7 +239,7 @@ int _handle_new_connection(download_clientinfo_slot *clientinfo_list, download_c
 
        download_controls type =
                ipc_receive_header(request_clientinfo->clientfd);
-       TRACE_DEBUG_MSG("[ACCEPT] HEADER : [%d] ", type);
+       TRACE_DEBUG_INFO_MSG("[ACCEPT] HEADER : [%d] ", type);
        // first of all, receive requestinfo .
        if (type <= 0 || ipc_receive_request_msg(request_clientinfo) < 0) {
                TRACE_DEBUG_MSG("Ignore this connection, Invalid command");
@@ -257,7 +257,7 @@ int _handle_new_connection(download_clientinfo_slot *clientinfo_list, download_c
                                                        (clientinfo_list,
                                                        request_clientinfo->requestinfo->requestid);
                        if (type == DOWNLOAD_CONTROL_STOP) {
-                               TRACE_DEBUG_MSG("Request : DOWNLOAD_CONTROL_STOP");
+                               TRACE_DEBUG_INFO_MSG("Request : DOWNLOAD_CONTROL_STOP");
                                if (searchindex >= 0) {
                                        if (da_cancel_download
                                                (clientinfo_list[searchindex].clientinfo->req_id)
@@ -327,7 +327,7 @@ int _handle_new_connection(download_clientinfo_slot *clientinfo_list, download_c
                int searchindex = get_same_request_slot_index(clientinfo_list,
                                                request_clientinfo->requestinfo->requestid);
                if (searchindex < 0) {
-                       TRACE_DEBUG_MSG("Not Found Same Request ID");
+                       TRACE_DEBUG_INFO_MSG("Not Found Same Request ID");
                        // Invalid id
                        request_clientinfo->state = DOWNLOAD_STATE_FAILED;
                        request_clientinfo->err = DOWNLOAD_ERROR_INVALID_PARAMETER;
@@ -336,7 +336,7 @@ int _handle_new_connection(download_clientinfo_slot *clientinfo_list, download_c
                        return 0;
                } else {        // found request id. // how to deal etag ?
                        // connect to slot.
-                       TRACE_DEBUG_MSG("Found Same Request ID slot[%d]", searchindex);
+                       TRACE_DEBUG_INFO_MSG("Found Same Request ID slot[%d]", searchindex);
                        CLIENT_MUTEX_LOCK(&(request_clientinfo->client_mutex));
                        // close previous socket.
                        if (clientinfo_list[searchindex].clientinfo->clientfd > 0)
@@ -380,7 +380,7 @@ int _handle_new_connection(download_clientinfo_slot *clientinfo_list, download_c
 
        clientinfo_list[searchslot].clientinfo = request_clientinfo;
 
-       TRACE_DEBUG_MSG("New Connection slot [%d] max [%d] max once [%d]",
+       TRACE_DEBUG_INFO_MSG("New Connection slot [%d] max [%d] max once [%d]",
                                                                                        searchslot,
                                                                                        MAX_CLIENT,
                                                                                        DA_MAX_DOWNLOAD_REQ_AT_ONCE);
@@ -395,7 +395,7 @@ int _handle_new_connection(download_clientinfo_slot *clientinfo_list, download_c
                        (clientinfo_list[searchslot].clientinfo,
                        DOWNLOAD_DB_STATE);
                ipc_send_request_stateinfo(clientinfo_list[searchslot].clientinfo);
-               TRACE_DEBUG_MSG ("Pended Request is saved to [%d/%d]",
+               TRACE_DEBUG_INFO_MSG ("Pended Request is saved to [%d/%d]",
                        searchslot, MAX_CLIENT);
                CLIENT_MUTEX_UNLOCK(&(clientinfo_list[searchslot].clientinfo->client_mutex));
                sleep(5);       // provider need the time of refresh.
@@ -406,8 +406,8 @@ int _handle_new_connection(download_clientinfo_slot *clientinfo_list, download_c
                        (&clientinfo_list[searchslot].clientinfo->thread_pid,
                        &g_download_provider_thread_attr, _start_download,
                        &clientinfo_list[searchslot]) != 0) {
-                       TRACE_DEBUG_MSG("failed to call pthread_create for client");
-                       TRACE_DEBUG_MSG("Change to pended job");
+                       TRACE_DEBUG_INFO_MSG("failed to call pthread_create for client");
+                       TRACE_DEBUG_INFO_MSG("Change to pended job");
                        CLIENT_MUTEX_LOCK(&(clientinfo_list[searchslot].clientinfo->client_mutex));
                        clientinfo_list[searchslot].clientinfo->state =
                                DOWNLOAD_STATE_PENDED;
@@ -437,7 +437,7 @@ int _handle_client_request(download_clientinfo* clientinfo)
 
        switch (msgType = ipc_receive_header(clientinfo->clientfd)) {
        case DOWNLOAD_CONTROL_STOP:
-               TRACE_DEBUG_MSG("DOWNLOAD_CONTROL_STOP");
+               TRACE_DEBUG_INFO_MSG("DOWNLOAD_CONTROL_STOP");
                da_ret = da_cancel_download(clientinfo->req_id);
                CLIENT_MUTEX_LOCK(&(clientinfo->client_mutex));
                if (da_ret != DA_RESULT_OK) {
@@ -460,7 +460,7 @@ int _handle_client_request(download_clientinfo* clientinfo)
                CLIENT_MUTEX_UNLOCK(&(clientinfo->client_mutex));
                break;
        case DOWNLOAD_CONTROL_PAUSE:
-               TRACE_DEBUG_MSG("DOWNLOAD_CONTROL_PAUSE");
+               TRACE_DEBUG_INFO_MSG("DOWNLOAD_CONTROL_PAUSE");
                da_ret = da_suspend_download(clientinfo->req_id);
                CLIENT_MUTEX_LOCK(&(clientinfo->client_mutex));
                if (da_ret != DA_RESULT_OK) {
@@ -476,7 +476,7 @@ int _handle_client_request(download_clientinfo* clientinfo)
                CLIENT_MUTEX_UNLOCK(&(clientinfo->client_mutex));
                break;
        case DOWNLOAD_CONTROL_RESUME:
-               TRACE_DEBUG_MSG("DOWNLOAD_CONTROL_RESUME");
+               TRACE_DEBUG_INFO_MSG("DOWNLOAD_CONTROL_RESUME");
                da_ret = da_resume_download(clientinfo->req_id);
                CLIENT_MUTEX_LOCK(&(clientinfo->client_mutex));
                if (da_ret != DA_RESULT_OK) {
@@ -492,13 +492,13 @@ int _handle_client_request(download_clientinfo* clientinfo)
                CLIENT_MUTEX_UNLOCK(&(clientinfo->client_mutex));
                break;
        case DOWNLOAD_CONTROL_GET_STATE_INFO:   // sync call
-               TRACE_DEBUG_MSG("DOWNLOAD_CONTROL_GET_STATE_INFO");
+               TRACE_DEBUG_INFO_MSG("DOWNLOAD_CONTROL_GET_STATE_INFO");
                CLIENT_MUTEX_LOCK(&(clientinfo->client_mutex));
                ipc_send_stateinfo(clientinfo);
                CLIENT_MUTEX_UNLOCK(&(clientinfo->client_mutex));
                break;
        case DOWNLOAD_CONTROL_GET_DOWNLOAD_INFO:        // sync call
-               TRACE_DEBUG_MSG("DOWNLOAD_CONTROL_GET_DOWNLOAD_INFO");
+               TRACE_DEBUG_INFO_MSG("DOWNLOAD_CONTROL_GET_DOWNLOAD_INFO");
                CLIENT_MUTEX_LOCK(&(clientinfo->client_mutex));
                ipc_send_downloadinfo(clientinfo);
                CLIENT_MUTEX_UNLOCK(&(clientinfo->client_mutex));
@@ -577,7 +577,7 @@ void *run_manage_download_server(void *args)
        }
 
        maxfd = listenfd;
-       TRACE_DEBUG_MSG("Ready to listen IPC [%d][%s]", listenfd,
+       TRACE_DEBUG_INFO_MSG("Ready to listen IPC [%d][%s]", listenfd,
                        DOWNLOAD_PROVIDER_IPC);
 
        // allocation the array structure for managing the clients.
@@ -625,6 +625,7 @@ void *run_manage_download_server(void *args)
                rset = g_download_provider_socket_readset;
                exceptset = g_download_provider_socket_exceptset;
 
+               memset(&timeout, 0x00, sizeof(struct timeval));
                timeout.tv_sec = flexible_timeout;
 
                if (select((maxfd + 1), &rset, 0, &exceptset, &timeout) < 0) {
@@ -647,7 +648,7 @@ void *run_manage_download_server(void *args)
                        if (clientinfo_list[i].clientinfo->clientfd <= 0)
                                continue;
                        if (FD_ISSET(clientinfo_list[i].clientinfo->clientfd, &rset) > 0) {
-                               TRACE_DEBUG_MSG("FD_ISSET [%d] readset slot[%d]",
+                               TRACE_DEBUG_INFO_MSG("FD_ISSET [%d] readset slot[%d]",
                                        clientinfo_list[i].clientinfo->clientfd, i);
                                _handle_client_request(clientinfo_list[i].clientinfo);
                        } else if (FD_ISSET(clientinfo_list[i].clientinfo->clientfd, &exceptset) > 0) {
@@ -661,7 +662,7 @@ void *run_manage_download_server(void *args)
                        TerminateDaemon(SIGTERM);
                        break;
                } else if (FD_ISSET(listenfd, &rset) > 0) { // new connection
-                       TRACE_DEBUG_MSG("FD_ISSET listenfd rset");
+                       TRACE_DEBUG_INFO_MSG("FD_ISSET listenfd rset");
                        // reset timeout.
                        flexible_timeout =
                                DOWNLOAD_PROVIDER_CARE_CLIENT_MIN_INTERVAL;
@@ -718,7 +719,7 @@ void *run_manage_download_server(void *args)
                                if (clientinfo_list[searchslot].clientinfo) {
                                        if (clientinfo_list[searchslot].clientinfo->state ==
                                                DOWNLOAD_STATE_PENDED) {
-                                               TRACE_DEBUG_MSG
+                                               TRACE_DEBUG_INFO_MSG
                                                        ("Retry Pended Request [%d/%d] state [%d/%d]",
                                                        searchslot, MAX_CLIENT,
                                                        count_downloading_threads,
@@ -744,31 +745,61 @@ void *run_manage_download_server(void *args)
                                DA_MAX_DOWNLOAD_REQ_AT_ONCE) {
                                // Auto re-download feature. ethernet may be connected with other downloading items.
                                connection_h network_handle = NULL;
-                               connection_ethernet_state_e system_network_state
-                                       = CONNECTION_ETHERNET_STATE_DISCONNECTED;
                                if (connection_create(&network_handle) < 0) {
                                        TRACE_DEBUG_MSG
                                                ("Failed connection_create");
                                        continue;
                                }
+
+                               connection_ethernet_state_e system_network_state
+                                       = CONNECTION_ETHERNET_STATE_DISCONNECTED;
                                if (connection_get_ethernet_state(network_handle,
                                                                                        &system_network_state) !=
                                        CONNECTION_ERROR_NONE)
                                        TRACE_DEBUG_MSG
                                                ("Failed connection_get_ethernet_state");
+                               TRACE_DEBUG_INFO_MSG
+                                       ("ethernet check result : [%d]", (int)system_network_state);
+
+                               connection_cellular_state_e system_cellular_state
+                                       = CONNECTION_CELLULAR_STATE_OUT_OF_SERVICE;
+                               if (connection_get_cellular_state(network_handle,
+                                                                                       &system_cellular_state) !=
+                                       CONNECTION_ERROR_NONE)
+                                       TRACE_DEBUG_MSG
+                                               ("Failed connection_get_ethernet_state");
+                               TRACE_DEBUG_INFO_MSG
+                                       ("cellula check result : [%d]", (int)system_cellular_state);
+
+                               connection_wifi_state_e system_wifi_state
+                                       = CONNECTION_WIFI_STATE_DEACTIVATED;
+                               if (connection_get_wifi_state(network_handle,
+                                                                                       &system_wifi_state) !=
+                                       CONNECTION_ERROR_NONE)
+                                       TRACE_DEBUG_MSG
+                                               ("Failed connection_get_ethernet_state");
+                               TRACE_DEBUG_INFO_MSG
+                                       ("wifi check result : [%d]", (int)system_wifi_state);
+
                                if (connection_destroy(network_handle) !=
                                        CONNECTION_ERROR_NONE)
                                        TRACE_DEBUG_MSG
                                                ("Failed connection_destroy");
-                               if (system_network_state !=
-                                       CONNECTION_ETHERNET_STATE_CONNECTED)
+
+                               if (!(system_network_state
+                                               == CONNECTION_ETHERNET_STATE_CONNECTED
+                                       || system_cellular_state
+                                               == CONNECTION_CELLULAR_STATE_AVAILABLE
+                                       || system_wifi_state
+                                               == CONNECTION_WIFI_STATE_CONNECTED))
                                        continue;
+
                                // check auto-retrying list regardless state. pended state is also included to checking list.
                                int i = 0;
                                download_dbinfo_list *db_list =
                                        download_provider_db_get_list(DOWNLOAD_STATE_NONE);
                                if (!db_list || db_list->count <= 0) {
-                                       TRACE_DEBUG_MSG
+                                       TRACE_DEBUG_INFO_MSG
                                                ("provider does not need to check DB anymore. in this life.");
                                        check_retry = 0;        // provider does not need to check DB anymore. in this life.
                                        if (db_list)
@@ -784,14 +815,14 @@ void *run_manage_download_server(void *args)
                                        if (get_same_request_slot_index
                                                (clientinfo_list,db_list->item[i].requestid) < 0) {
                                                // not found requestid in memory
-                                               TRACE_DEBUG_MSG
+                                               TRACE_DEBUG_INFO_MSG
                                                        ("Retry download [%d]",
                                                        db_list->item[i].requestid);
                                                //search empty slot. copy db info to slot.
                                                searchslot =
                                                        get_empty_slot_index(clientinfo_list);
                                                if (searchslot < 0) {
-                                                       TRACE_DEBUG_MSG
+                                                       TRACE_DEBUG_INFO_MSG
                                                                ("download-provider is busy, try later");
                                                        flexible_timeout =
                                                                flexible_timeout * 2;
@@ -816,7 +847,7 @@ void *run_manage_download_server(void *args)
                                                clientinfo_list[searchslot].clientinfo =
                                                        request_clientinfo;
 
-                                               TRACE_DEBUG_MSG
+                                               TRACE_DEBUG_INFO_MSG
                                                        ("Retry download [%d/%d][%d/%d]",
                                                        searchslot, MAX_CLIENT,
                                                        count_downloading_threads,
@@ -853,7 +884,7 @@ void *run_manage_download_server(void *args)
                                DOWNLOAD_PROVIDER_CARE_CLIENT_MAX_INTERVAL)
                                flexible_timeout =
                                        DOWNLOAD_PROVIDER_CARE_CLIENT_MAX_INTERVAL;
-                       TRACE_DEBUG_MSG("Next Timeout after [%ld] sec",
+                       TRACE_DEBUG_INFO_MSG("Next Timeout after [%ld] sec",
                                        flexible_timeout);
 
                } // if (i >= MAX_CLIENT) { // timeout
@@ -898,8 +929,8 @@ void __download_info_cb(user_download_info_t *download_info, void *user_data)
                TRACE_DEBUG_MSG("[CRITICAL] clientinfo is NULL");
                return;
        }
-       TRACE_DEBUG_MSG("id[%d],size[%lu]",
-                       download_info->da_dl_req_id, download_info->file_size)
+       TRACE_DEBUG_INFO_MSG("id[%d],size[%lu]",
+                       download_info->da_dl_req_id, download_info->file_size);
 
        if (clientinfo->req_id != download_info->da_dl_req_id) {
                TRACE_DEBUG_MSG("[CRITICAL] req_id[%d] da_dl_req_id[%d}",
@@ -914,7 +945,7 @@ void __download_info_cb(user_download_info_t *download_info, void *user_data)
        if (clientinfo->downloadinfo)
                clientinfo->downloadinfo->file_size = download_info->file_size;
        if (download_info->file_type) {
-               TRACE_DEBUG_MSG("mime[%s]", download_info->file_type);
+               TRACE_DEBUG_INFO_MSG("mime[%s]", download_info->file_type);
 
                len = strlen(download_info->file_type);
                if (len > (DP_MAX_STR_LEN - 1))
@@ -928,7 +959,7 @@ void __download_info_cb(user_download_info_t *download_info, void *user_data)
        }
        if (download_info->tmp_saved_path) {
                char *str = NULL;
-               TRACE_DEBUG_MSG("tmp path[%s]", download_info->tmp_saved_path);
+               TRACE_DEBUG_INFO_MSG("tmp path[%s]", download_info->tmp_saved_path);
                clientinfo->tmp_saved_path =
                        strdup(download_info->tmp_saved_path);
                download_provider_db_requestinfo_update_column(clientinfo,
@@ -944,7 +975,7 @@ void __download_info_cb(user_download_info_t *download_info, void *user_data)
                                        str, len);
                                download_provider_db_requestinfo_update_column
                                        (clientinfo, DOWNLOAD_DB_FILENAME);
-                               TRACE_DEBUG_MSG("content_name[%s]",
+                               TRACE_DEBUG_INFO_MSG("content_name[%s]",
                                                clientinfo->downloadinfo->
                                                content_name);
                        }
@@ -988,13 +1019,18 @@ void __downloading_info_cb(user_downloading_info_t *download_info,
                clientinfo->downloadinginfo->received_size =
                        download_info->total_received_size;
        if (download_info->saved_path) {
-               TRACE_DEBUG_MSG("tmp path[%s]", download_info->saved_path);
+               TRACE_DEBUG_INFO_MSG("tmp path[%s]", download_info->saved_path);
                len = strlen(download_info->saved_path);
                if (len > (DP_MAX_PATH_LEN - 1))
                        len = DP_MAX_PATH_LEN - 1;
                if (clientinfo->downloadinginfo)
                        strncpy(clientinfo->downloadinginfo->saved_path,
                                download_info->saved_path, len);
+               /* FIXME : This should be reviewd again after smack rules is applied */
+               if (chown(clientinfo->downloadinginfo->saved_path,
+                               clientinfo->credentials.uid,
+                               clientinfo->credentials.gid) < 0)
+                       TRACE_DEBUG_INFO_MSG("Fail to chown [%s]", strerror(errno));
        }
 
        static size_t updated_second;
@@ -1027,7 +1063,7 @@ void __notify_cb(user_notify_info_t *notify_info, void *user_data)
                return;
        }
 
-       TRACE_DEBUG_MSG("id[%d],state[%d],err[%d]",
+       TRACE_DEBUG_INFO_MSG("id[%d],state[%d],err[%d]",
                        notify_info->da_dl_req_id,
                        notify_info->state, notify_info->err);
        if (clientinfo->req_id != notify_info->da_dl_req_id) {
@@ -1049,11 +1085,11 @@ void __notify_cb(user_notify_info_t *notify_info, void *user_data)
                                requestinfo->requestid);
                }
                download_provider_db_history_new(clientinfo);
-               TRACE_DEBUG_MSG("[TEST]Finish clientinfo[%p],fd[%d]",
+               TRACE_DEBUG_INFO_MSG("[TEST]Finish clientinfo[%p],fd[%d]",
                        clientinfo, clientinfo->clientfd);
        }
 
-       TRACE_DEBUG_MSG("state[%d]", clientinfo->state);
+       TRACE_DEBUG_INFO_MSG("state[%d]", clientinfo->state);
        ipc_send_stateinfo(clientinfo);
 
        CLIENT_MUTEX_UNLOCK(&(clientinfo->client_mutex));
@@ -1065,44 +1101,44 @@ int __change_state(da_state state)
        switch (state) {
        case DA_STATE_WAITING:
        case DA_STATE_DOWNLOAD_STARTED:
-               TRACE_DEBUG_MSG("DA_STATE_DOWNLOAD_STARTED");
+               TRACE_DEBUG_INFO_MSG("DA_STATE_DOWNLOAD_STARTED");
                ret = DOWNLOAD_STATE_READY;
                break;
        case DA_STATE_DOWNLOADING:
-               TRACE_DEBUG_MSG("DA_STATE_DOWNLOADING");
+               TRACE_DEBUG_INFO_MSG("DA_STATE_DOWNLOADING");
                ret = DOWNLOAD_STATE_DOWNLOADING;
                break;
        case DA_STATE_DOWNLOAD_COMPLETE:
-               TRACE_DEBUG_MSG("DA_STATE_COMPLETE");
+               TRACE_DEBUG_INFO_MSG("DA_STATE_COMPLETE");
                ret = DOWNLOAD_STATE_INSTALLING;
                break;
        case DA_STATE_CANCELED:
-               TRACE_DEBUG_MSG("DA_STATE_CANCELED");
+               TRACE_DEBUG_INFO_MSG("DA_STATE_CANCELED");
                ret = DOWNLOAD_STATE_STOPPED;
                break;
        case DA_STATE_CANCELED_ALL:
-               TRACE_DEBUG_MSG("DA_STATE_CANCELED_ALL");
+               TRACE_DEBUG_INFO_MSG("DA_STATE_CANCELED_ALL");
                break;
        case DA_STATE_SUSPENDED:
-               TRACE_DEBUG_MSG("DA_STATE_SUSPENDED");
+               TRACE_DEBUG_INFO_MSG("DA_STATE_SUSPENDED");
                ret = DOWNLOAD_STATE_PAUSED;
                break;
        case DA_STATE_SUSPENDED_ALL:
-               TRACE_DEBUG_MSG("DA_STATE_SUSPENDED_ALL");
+               TRACE_DEBUG_INFO_MSG("DA_STATE_SUSPENDED_ALL");
                break;
        case DA_STATE_RESUMED:
-               TRACE_DEBUG_MSG("DA_STATE_RESUMED");
+               TRACE_DEBUG_INFO_MSG("DA_STATE_RESUMED");
                ret = DOWNLOAD_STATE_DOWNLOADING;
                break;
        case DA_STATE_RESUMED_ALL:
-               TRACE_DEBUG_MSG("DA_STATE_RESUMED_ALL");
+               TRACE_DEBUG_INFO_MSG("DA_STATE_RESUMED_ALL");
                break;
        case DA_STATE_FINISHED:
-               TRACE_DEBUG_MSG("DA_STATE_FINISHED");
+               TRACE_DEBUG_INFO_MSG("DA_STATE_FINISHED");
                ret = DOWNLOAD_STATE_FINISHED;
                break;
        case DA_STATE_FAILED:
-               TRACE_DEBUG_MSG("DA_STATE_FAILED");
+               TRACE_DEBUG_INFO_MSG("DA_STATE_FAILED");
                ret = DOWNLOAD_STATE_FAILED;
                break;
        default:
index 2270534..59b19ca 100644 (file)
@@ -27,7 +27,7 @@ int get_download_request_id(void)
                        uniquetime = uniquetime + (tval.tv_usec + 1) % 0xfffff;
                else
                        uniquetime = uniquetime + tval.tv_usec;
-               TRACE_DEBUG_MSG("ID : %d", uniquetime);
+               TRACE_DEBUG_INFO_MSG("ID : %d", uniquetime);
        } while (last_uniquetime == uniquetime);
        last_uniquetime = uniquetime;   // store
        return uniquetime;
@@ -49,7 +49,7 @@ void clear_socket(download_clientinfo *clientinfo)
 
 void clear_clientinfo(download_clientinfo *clientinfo)
 {
-       TRACE_DEBUG_MSG("[TEST] clear [%p]",clientinfo);
+       TRACE_DEBUG_INFO_MSG("[TEST] clear [%p]",clientinfo);
        // clear this slot
        if (!clientinfo)
                return;
@@ -111,7 +111,6 @@ void clear_clientinfo(download_clientinfo *clientinfo)
 
 void clear_clientinfoslot(download_clientinfo_slot *clientinfoslot)
 {
-       TRACE_DEBUG_MSG("");
        // clear this slot
        if (!clientinfoslot)
                return;