Code Sync with Private GIT
authorBang Kwang min <justine.bang@samsung.com>
Fri, 24 Aug 2012 02:07:28 +0000 (11:07 +0900)
committerBang Kwang min <justine.bang@samsung.com>
Fri, 24 Aug 2012 02:07:28 +0000 (11:07 +0900)
changes)
fix the defects found by prevent tool
remove mutex lock/unlock in case of invalid id
support the status of download in case of getting new connection with requestid
clear db, register notification when stopped the download
Update notification function
Enable to set the defined file name by user
event thread does not deal in some state
fix the lockup by mutex and the crash by invaild socket event
Resolve a bug of return type

modified:   CMakeLists.txt
modified:   include/download-provider-db.h
modified:   include/download-provider-notification.h
modified:   include/download-provider.h
modified:   packaging/download-provider.spec
modified:   src/download-provider-db.c
modified:   src/download-provider-ipc.c
modified:   src/download-provider-notification.c
modified:   src/download-provider-receiver.c
modified:   src/download-provider-utils.c

CMakeLists.txt
include/download-provider-db.h
include/download-provider-notification.h
include/download-provider.h
packaging/download-provider.spec
src/download-provider-db.c
src/download-provider-ipc.c
src/download-provider-notification.c
src/download-provider-receiver.c
src/download-provider-utils.c

index cdce885..9470ff3 100644 (file)
@@ -24,6 +24,7 @@ pkg_check_modules(pkgs REQUIRED glib-2.0
                sqlite3
                capi-appfw-application
                capi-network-connection
+               bundle
                dlog)
 
 FOREACH(flag ${pkgs_CFLAGS})
index 957c613..a2ef14b 100644 (file)
@@ -42,11 +42,14 @@ int download_provider_db_requestinfo_remove(int uniqueid);
 int download_provider_db_requestinfo_update_column(download_clientinfo *clientinfo,
                                                        download_db_column_type type);
 download_dbinfo_list *download_provider_db_get_list(int state);
+download_dbinfo *download_provider_db_get_info(int requestid);
 void download_provider_db_list_free(download_dbinfo_list *list);
+void download_provider_db_info_free(download_dbinfo *info);
 int download_provider_db_list_count(int state);
 download_request_info *download_provider_db_get_requestinfo(download_dbinfo *dbinfo);
 int download_provider_db_history_new(download_clientinfo *clientinfo);
 int download_provider_db_history_remove(int uniqueid);
 int download_provider_db_history_limit_rows();
+download_dbinfo *download_provider_db_history_get_info(int requestid);
 
 #endif
index 6f526c4..d464daf 100644 (file)
@@ -6,5 +6,6 @@
 int set_downloadinginfo_appfw_notification(download_clientinfo *clientinfo);
 int set_downloadedinfo_appfw_notification(download_clientinfo *clientinfo);
 int destroy_appfw_notification(download_clientinfo *clientinfo);
+void clear_downloadinginfo_appfw_notification(void);
 
 #endif
index d97d273..a088a11 100644 (file)
@@ -98,6 +98,7 @@ extern "C" {
                download_flexible_string url;
                download_flexible_string install_path;
                download_flexible_string filename;
+               download_flexible_string service_data;
                download_flexible_double_string headers;
        } download_request_info;
 
index 784940d..df481f7 100644 (file)
@@ -15,6 +15,7 @@ BuildRequires:  pkgconfig(xdgmime)
 BuildRequires:  pkgconfig(vconf)
 BuildRequires:  pkgconfig(db-util)
 BuildRequires:  pkgconfig(sqlite3)
+BuildRequires:  pkgconfig(bundle)
 BuildRequires:  pkgconfig(capi-appfw-application)
 BuildRequires:  pkgconfig(capi-network-connection)
 
index edf02cc..06726b3 100644 (file)
@@ -49,7 +49,7 @@ int _download_provider_sql_open()
 int download_provider_db_requestinfo_remove(int uniqueid)
 {
        int errorcode;
-       sqlite3_stmt *stmt;
+       sqlite3_stmt *stmt = NULL;
 
        if (uniqueid <= 0) {
                TRACE_DEBUG_MSG("[NULL-CHECK]");
@@ -92,7 +92,7 @@ int download_provider_db_requestinfo_remove(int uniqueid)
 int download_provider_db_requestinfo_new(download_clientinfo *clientinfo)
 {
        int errorcode;
-       sqlite3_stmt *stmt;
+       sqlite3_stmt *stmt = NULL;
 
        if (!clientinfo || !clientinfo->requestinfo
                || clientinfo->requestinfo->requestid <= 0) {
@@ -123,7 +123,7 @@ int download_provider_db_requestinfo_new(download_clientinfo *clientinfo)
                _download_provider_sql_close(stmt);
                return -1;
        }
-       if (clientinfo->requestinfo->client_packagename.length > 0) {
+       if (clientinfo->requestinfo->client_packagename.length > 1) {
                if (sqlite3_bind_text
                    (stmt, 2, clientinfo->requestinfo->client_packagename.str,
                     -1, NULL) != SQLITE_OK) {
@@ -141,7 +141,7 @@ int download_provider_db_requestinfo_new(download_clientinfo *clientinfo)
                _download_provider_sql_close(stmt);
                return -1;
        }
-       if (clientinfo->downloadinfo && clientinfo->downloadinfo->content_name) {
+       if (clientinfo->downloadinfo && sizeof(clientinfo->downloadinfo->content_name) > 1) {
                if (sqlite3_bind_text
                    (stmt, 5, clientinfo->downloadinfo->content_name, -1,
                     NULL) != SQLITE_OK) {
@@ -157,7 +157,7 @@ int download_provider_db_requestinfo_new(download_clientinfo *clientinfo)
                _download_provider_sql_close(stmt);
                return -1;
        }
-       if (clientinfo->requestinfo->url.length > 0) {
+       if (clientinfo->requestinfo->url.length > 1) {
                if (sqlite3_bind_text
                    (stmt, 7, clientinfo->requestinfo->url.str, -1,
                     NULL) != SQLITE_OK) {
@@ -167,7 +167,7 @@ int download_provider_db_requestinfo_new(download_clientinfo *clientinfo)
                        return -1;
                }
        }
-       if (clientinfo->downloadinfo && clientinfo->downloadinfo->mime_type) {
+       if (clientinfo->downloadinfo && sizeof(clientinfo->downloadinfo->mime_type) > 1) {
                if (sqlite3_bind_text
                    (stmt, 8, clientinfo->downloadinfo->mime_type, -1,
                     NULL) != SQLITE_OK) {
@@ -202,7 +202,7 @@ int download_provider_db_requestinfo_update_column(download_clientinfo *clientin
                                                   download_db_column_type type)
 {
        int errorcode;
-       sqlite3_stmt *stmt;
+       sqlite3_stmt *stmt = NULL;
 
        if (!clientinfo || !clientinfo->requestinfo
                || clientinfo->requestinfo->requestid <= 0) {
@@ -218,7 +218,7 @@ int download_provider_db_requestinfo_update_column(download_clientinfo *clientin
 
        switch (type) {
        case DOWNLOAD_DB_PACKAGENAME:
-               if (clientinfo->requestinfo->client_packagename.length <= 0
+               if (clientinfo->requestinfo->client_packagename.length <= 1
                        || !clientinfo->requestinfo->client_packagename.str) {
                        TRACE_DEBUG_MSG("[NULL-CHECK] type [%d]", type);
                        _download_provider_sql_close(stmt);
@@ -308,7 +308,7 @@ int download_provider_db_requestinfo_update_column(download_clientinfo *clientin
                break;
        case DOWNLOAD_DB_FILENAME:
                if (!clientinfo->downloadinfo
-                       || !clientinfo->downloadinfo->content_name) {
+                       || sizeof(clientinfo->downloadinfo->content_name) < 1) {
                        TRACE_DEBUG_MSG("[NULL-CHECK] type [%d]", type);
                        _download_provider_sql_close(stmt);
                        return -1;
@@ -387,7 +387,7 @@ download_dbinfo_list *download_provider_db_get_list(int state)
        int listcount;
        int i = 0;
        int buffer_length = 0;
-       sqlite3_stmt *stmt;
+       sqlite3_stmt *stmt = NULL;
        char *buffer;
        download_dbinfo_list *m_list = NULL;
 
@@ -529,7 +529,7 @@ int download_provider_db_list_count(int state)
 {
        int errorcode;
        int count = 0;
-       sqlite3_stmt *stmt;
+       sqlite3_stmt *stmt = NULL;
 
        if (_download_provider_sql_open() < 0) {
                TRACE_DEBUG_MSG("db_util_open is failed [%s]",
@@ -578,6 +578,40 @@ int download_provider_db_list_count(int state)
        return 0;
 }
 
+void download_provider_db_info_free(download_dbinfo *info)
+{
+       if (!info)
+               return;
+
+       info->requestid = 0;
+       if (info->packagename)
+               free(info->packagename);
+       info->packagename = NULL;
+       if (info->installpath)
+               free(info->installpath);
+       info->installpath = NULL;
+       if (info->filename)
+               free(info->filename);
+       info->filename = NULL;
+       if (info->createdate)
+               free(info->createdate);
+       info->createdate = NULL;
+       if (info->url)
+               free(info->url);
+       info->url = NULL;
+       if (info->mimetype)
+               free(info->mimetype);
+       info->mimetype = NULL;
+       if (info->etag)
+               free(info->etag);
+       info->etag = NULL;
+       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("");
@@ -587,33 +621,9 @@ void download_provider_db_list_free(download_dbinfo_list *list)
                return;
 
        if (list->count > 0 && list->item) {
-               for (i = 0; i < list->count; i++) {
-                       list->item[i].requestid = 0;
-                       if (list->item[i].packagename)
-                               free(list->item[i].packagename);
-                       list->item[i].packagename = NULL;
-                       if (list->item[i].installpath)
-                               free(list->item[i].installpath);
-                       list->item[i].installpath = NULL;
-                       if (list->item[i].filename)
-                               free(list->item[i].filename);
-                       list->item[i].filename = NULL;
-                       if (list->item[i].createdate)
-                               free(list->item[i].createdate);
-                       list->item[i].createdate = NULL;
-                       if (list->item[i].url)
-                               free(list->item[i].url);
-                       list->item[i].url = NULL;
-                       if (list->item[i].mimetype)
-                               free(list->item[i].mimetype);
-                       list->item[i].mimetype = NULL;
-                       if (list->item[i].etag)
-                               free(list->item[i].etag);
-                       list->item[i].etag = NULL;
-                       if (list->item[i].saved_path)
-                               free(list->item[i].saved_path);
-                       list->item[i].saved_path = NULL;
-               }
+               for (i = 0; i < list->count; i++)
+                       download_provider_db_info_free(&list->item[i]);
+               list->count = 0;
                free(list->item);
                list->item = NULL;
        }
@@ -621,6 +631,126 @@ void download_provider_db_list_free(download_dbinfo_list *list)
        list = NULL;
 }
 
+download_dbinfo *download_provider_db_get_info(int requestid)
+{
+       if (requestid <= 0)
+               return NULL;
+
+       int errorcode;
+       int buffer_length = 0;
+       sqlite3_stmt *stmt = NULL;
+       char *buffer = NULL;
+       download_dbinfo *dbinfo = NULL;
+
+       if (_download_provider_sql_open() < 0) {
+               TRACE_DEBUG_MSG("db_util_open is failed [%s]",
+                               sqlite3_errmsg(g_download_provider_db));
+               return NULL;
+       }
+
+       errorcode =
+               sqlite3_prepare_v2(g_download_provider_db,
+                       "SELECT uniqueid, packagename, notification, installpath, filename, creationdate, state, url, mimetype, savedpath FROM downloading WHERE uniqueid = ?",
+                       -1, &stmt, NULL);
+       if (errorcode != SQLITE_OK) {
+               TRACE_DEBUG_MSG("sqlite3_prepare_v2 is failed. [%s]",
+                               sqlite3_errmsg(g_download_provider_db));
+               _download_provider_sql_close(stmt);
+               return NULL;
+       }
+       if (sqlite3_bind_int(stmt, 1, requestid) != SQLITE_OK) {
+               TRACE_DEBUG_MSG("sqlite3_bind_int is failed. [%s]",
+                               sqlite3_errmsg(g_download_provider_db));
+               _download_provider_sql_close(stmt);
+               return NULL;
+       }
+
+       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->packagename = NULL;
+               if (buffer) {
+                       buffer_length = strlen(buffer);
+                       dbinfo->packagename
+                               = (char *)calloc(buffer_length + 1, sizeof(char));
+                       memcpy(dbinfo->packagename, buffer,
+                                       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));
+               dbinfo->filename = NULL;
+               if (buffer) {
+                       buffer_length = strlen(buffer);
+                       dbinfo->filename
+                               = (char *)calloc(buffer_length + 1, sizeof(char));
+                       memcpy(dbinfo->filename, buffer,
+                                       buffer_length * sizeof(char));
+                       dbinfo->filename[buffer_length] = '\0';
+               }
+               buffer = (char *)(sqlite3_column_text(stmt, 5));
+               dbinfo->createdate = NULL;
+               if (buffer) {
+                       buffer_length = strlen(buffer);
+                       dbinfo->createdate
+                               = (char *)calloc(buffer_length + 1, sizeof(char));
+                       memcpy(dbinfo->createdate, buffer,
+                                       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->mimetype = NULL;
+               if (buffer) {
+                       buffer_length = strlen(buffer);
+                       dbinfo->mimetype
+                               = (char *)calloc(buffer_length + 1, sizeof(char));
+                       memcpy(dbinfo->mimetype, buffer,
+                                       buffer_length * sizeof(char));
+                       dbinfo->mimetype[buffer_length] = '\0';
+               }
+               buffer = (char *)(sqlite3_column_text(stmt, 9));
+               dbinfo->saved_path = NULL;
+               if (buffer) {
+                       buffer_length = strlen(buffer);
+                       dbinfo->saved_path
+                               = (char *)calloc(buffer_length + 1, sizeof(char));
+                       memcpy(dbinfo->saved_path, buffer,
+                               buffer_length * sizeof(char));
+                       dbinfo->saved_path[buffer_length] = '\0';
+               }
+       } else {
+               TRACE_DEBUG_MSG("sqlite3_step is failed. [%s] errorcode[%d]",
+                               sqlite3_errmsg(g_download_provider_db), errorcode);
+               __download_provider_db_close();
+               download_provider_db_info_free(dbinfo);
+               return NULL;
+       }
+       _download_provider_sql_close(stmt);
+       return dbinfo;
+}
+
 download_request_info *download_provider_db_get_requestinfo(download_dbinfo *dbinfo)
 {
        if (!dbinfo || dbinfo->requestid <= 0)
@@ -632,7 +762,7 @@ download_request_info *download_provider_db_get_requestinfo(download_dbinfo *dbi
        if (dbinfo->packagename) {
                requestinfo->client_packagename.length =
                        strlen(dbinfo->packagename);
-               if (requestinfo->client_packagename.length > 0) {
+               if (requestinfo->client_packagename.length > 1) {
                        requestinfo->client_packagename.str
                                =
                                (char *)
@@ -649,7 +779,7 @@ download_request_info *download_provider_db_get_requestinfo(download_dbinfo *dbi
        }
        if (dbinfo->url) {
                requestinfo->url.length = strlen(dbinfo->url);
-               if (requestinfo->url.length > 0) {
+               if (requestinfo->url.length > 1) {
                        requestinfo->url.str
                                =
                                (char *)calloc((requestinfo->url.length + 1),
@@ -661,7 +791,7 @@ download_request_info *download_provider_db_get_requestinfo(download_dbinfo *dbi
        }
        if (dbinfo->installpath) {
                requestinfo->install_path.length = strlen(dbinfo->installpath);
-               if (requestinfo->install_path.length > 0) {
+               if (requestinfo->install_path.length > 1) {
                        requestinfo->install_path.str
                                =
                                (char *)
@@ -676,7 +806,7 @@ download_request_info *download_provider_db_get_requestinfo(download_dbinfo *dbi
        }
        if (dbinfo->filename) {
                requestinfo->filename.length = strlen(dbinfo->filename);
-               if (requestinfo->filename.length > 0) {
+               if (requestinfo->filename.length > 1) {
                        requestinfo->filename.str
                                =
                                (char *)calloc((requestinfo->filename.length + 1),
@@ -696,7 +826,7 @@ download_request_info *download_provider_db_get_requestinfo(download_dbinfo *dbi
 int download_provider_db_history_new(download_clientinfo *clientinfo)
 {
        int errorcode;
-       sqlite3_stmt *stmt;
+       sqlite3_stmt *stmt = NULL;
 
        if (!clientinfo || !clientinfo->requestinfo
                || clientinfo->requestinfo->requestid <= 0) {
@@ -727,7 +857,7 @@ int download_provider_db_history_new(download_clientinfo *clientinfo)
                _download_provider_sql_close(stmt);
                return -1;
        }
-       if (clientinfo->requestinfo->client_packagename.length > 0) {
+       if (clientinfo->requestinfo->client_packagename.length > 1) {
                if (sqlite3_bind_text
                        (stmt, 2, clientinfo->requestinfo->client_packagename.str,
                         -1, NULL) != SQLITE_OK) {
@@ -737,7 +867,7 @@ int download_provider_db_history_new(download_clientinfo *clientinfo)
                        return -1;
                }
        }
-       if (clientinfo->downloadinfo && clientinfo->downloadinfo->content_name) {
+       if (clientinfo->downloadinfo && sizeof(clientinfo->downloadinfo->content_name) > 1) {
                if (sqlite3_bind_text
                        (stmt, 3, clientinfo->downloadinfo->content_name, -1,
                        NULL) != SQLITE_OK) {
@@ -753,7 +883,7 @@ int download_provider_db_history_new(download_clientinfo *clientinfo)
                _download_provider_sql_close(stmt);
                return -1;
        }
-       if (clientinfo->downloadinfo && clientinfo->downloadinfo->mime_type) {
+       if (clientinfo->downloadinfo && sizeof(clientinfo->downloadinfo->mime_type) > 1) {
                if (sqlite3_bind_text
                        (stmt, 5, clientinfo->downloadinfo->mime_type, -1,
                        NULL) != SQLITE_OK) {
@@ -788,7 +918,7 @@ int download_provider_db_history_new(download_clientinfo *clientinfo)
 int download_provider_db_history_remove(int uniqueid)
 {
        int errorcode;
-       sqlite3_stmt *stmt;
+       sqlite3_stmt *stmt = NULL;
 
        if (uniqueid <= 0) {
                TRACE_DEBUG_MSG("[NULL-CHECK]");
@@ -831,7 +961,7 @@ int download_provider_db_history_remove(int uniqueid)
 int download_provider_db_history_limit_rows()
 {
        int errorcode;
-       sqlite3_stmt *stmt;
+       sqlite3_stmt *stmt = NULL;
 
        if (_download_provider_sql_open() < 0) {
                TRACE_DEBUG_MSG("db_util_open is failed [%s]",
@@ -866,3 +996,123 @@ int download_provider_db_history_limit_rows()
        __download_provider_db_close();
        return -1;
 }
+
+download_dbinfo *download_provider_db_history_get_info(int requestid)
+{
+       if (requestid <= 0)
+               return NULL;
+
+       int errorcode;
+       int buffer_length = 0;
+       sqlite3_stmt *stmt = NULL;
+       char *buffer = NULL;
+       download_dbinfo *dbinfo = NULL;
+
+       if (_download_provider_sql_open() < 0) {
+               TRACE_DEBUG_MSG("db_util_open is failed [%s]",
+                               sqlite3_errmsg(g_download_provider_db));
+               return NULL;
+       }
+
+       errorcode =
+               sqlite3_prepare_v2(g_download_provider_db,
+                       "SELECT uniqueid, packagename, notification, installpath, filename, creationdate, state, url, mimetype, savedpath FROM history WHERE uniqueid = ?",
+                       -1, &stmt, NULL);
+       if (errorcode != SQLITE_OK) {
+               TRACE_DEBUG_MSG("sqlite3_prepare_v2 is failed. [%s]",
+                               sqlite3_errmsg(g_download_provider_db));
+               _download_provider_sql_close(stmt);
+               return NULL;
+       }
+       if (sqlite3_bind_int(stmt, 1, requestid) != SQLITE_OK) {
+               TRACE_DEBUG_MSG("sqlite3_bind_int is failed. [%s]",
+                               sqlite3_errmsg(g_download_provider_db));
+               _download_provider_sql_close(stmt);
+               return NULL;
+       }
+
+       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->packagename = NULL;
+               if (buffer) {
+                       buffer_length = strlen(buffer);
+                       dbinfo->packagename
+                               = (char *)calloc(buffer_length + 1, sizeof(char));
+                       memcpy(dbinfo->packagename, buffer,
+                                       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));
+               dbinfo->filename = NULL;
+               if (buffer) {
+                       buffer_length = strlen(buffer);
+                       dbinfo->filename
+                               = (char *)calloc(buffer_length + 1, sizeof(char));
+                       memcpy(dbinfo->filename, buffer,
+                                       buffer_length * sizeof(char));
+                       dbinfo->filename[buffer_length] = '\0';
+               }
+               buffer = (char *)(sqlite3_column_text(stmt, 5));
+               dbinfo->createdate = NULL;
+               if (buffer) {
+                       buffer_length = strlen(buffer);
+                       dbinfo->createdate
+                               = (char *)calloc(buffer_length + 1, sizeof(char));
+                       memcpy(dbinfo->createdate, buffer,
+                                       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->mimetype = NULL;
+               if (buffer) {
+                       buffer_length = strlen(buffer);
+                       dbinfo->mimetype
+                               = (char *)calloc(buffer_length + 1, sizeof(char));
+                       memcpy(dbinfo->mimetype, buffer,
+                                       buffer_length * sizeof(char));
+                       dbinfo->mimetype[buffer_length] = '\0';
+               }
+               buffer = (char *)(sqlite3_column_text(stmt, 9));
+               dbinfo->saved_path = NULL;
+               if (buffer) {
+                       buffer_length = strlen(buffer);
+                       dbinfo->saved_path
+                               = (char *)calloc(buffer_length + 1, sizeof(char));
+                       memcpy(dbinfo->saved_path, buffer,
+                               buffer_length * sizeof(char));
+                       dbinfo->saved_path[buffer_length] = '\0';
+               }
+       } else {
+               TRACE_DEBUG_MSG("sqlite3_step is failed. [%s] errorcode[%d]",
+                               sqlite3_errmsg(g_download_provider_db), errorcode);
+               __download_provider_db_close();
+               download_provider_db_info_free(dbinfo);
+               return NULL;
+       }
+       _download_provider_sql_close(stmt);
+       return dbinfo;
+}
index 66e94ad..7cfb54f 100644 (file)
@@ -7,6 +7,7 @@
 
 #include "download-provider-ipc.h"
 #include "download-provider-log.h"
+#include "bundle.h"
 
 int ipc_receive_header(int fd)
 {
@@ -122,6 +123,7 @@ int ipc_send_downloadinginfo(download_clientinfo *clientinfo)
        return type;
 }
 
+extern int service_import_from_bundle(service_h service, bundle *data);
 int ipc_receive_request_msg(download_clientinfo *clientinfo)
 {
        if (!clientinfo || clientinfo->clientfd <= 0)
@@ -141,7 +143,7 @@ int ipc_receive_request_msg(download_clientinfo *clientinfo)
                TRACE_DEBUG_MSG("failed to read message header");
                return -1;
        }
-       if (clientinfo->requestinfo->client_packagename.length > 0) {
+       if (clientinfo->requestinfo->client_packagename.length > 1) {
                clientinfo->requestinfo->client_packagename.str =
                        (char *)
                        calloc((clientinfo->requestinfo->client_packagename.length +
@@ -164,7 +166,7 @@ int ipc_receive_request_msg(download_clientinfo *clientinfo)
                                clientinfo->requestinfo->client_packagename.
                                str);
        }
-       if (clientinfo->requestinfo->url.length > 0) {
+       if (clientinfo->requestinfo->url.length > 1) {
                clientinfo->requestinfo->url.str =
                        (char *)calloc((clientinfo->requestinfo->url.length + 1),
                                        sizeof(char));
@@ -180,7 +182,7 @@ int ipc_receive_request_msg(download_clientinfo *clientinfo)
                TRACE_DEBUG_MSG("request url [%s]",
                                clientinfo->requestinfo->url.str);
        }
-       if (clientinfo->requestinfo->install_path.length > 0) {
+       if (clientinfo->requestinfo->install_path.length > 1) {
                clientinfo->requestinfo->install_path.str =
                        (char *)
                        calloc((clientinfo->requestinfo->install_path.length + 1),
@@ -202,7 +204,7 @@ int ipc_receive_request_msg(download_clientinfo *clientinfo)
                TRACE_DEBUG_MSG("request install_path [%s]",
                                clientinfo->requestinfo->install_path.str);
        }
-       if (clientinfo->requestinfo->filename.length > 0) {
+       if (clientinfo->requestinfo->filename.length > 1) {
                clientinfo->requestinfo->filename.str =
                        (char *)
                        calloc((clientinfo->requestinfo->filename.length + 1),
@@ -222,6 +224,55 @@ int ipc_receive_request_msg(download_clientinfo *clientinfo)
                TRACE_DEBUG_MSG("request filename [%s]",
                                clientinfo->requestinfo->filename.str);
        }
+       if (clientinfo->requestinfo->service_data.length > 1) {
+               bundle_raw *raw_data = NULL;
+               int len = 0;
+               bundle *b = NULL;
+               service_h service_handle;
+               clientinfo->requestinfo->service_data.str =
+                       (char *)
+                       calloc((clientinfo->requestinfo->service_data.length + 1),
+                               sizeof(char));
+               if (read
+                       (clientinfo->clientfd,
+                       clientinfo->requestinfo->service_data.str,
+                       clientinfo->requestinfo->service_data.length * sizeof(char)) <
+                       0) {
+                       TRACE_DEBUG_MSG
+                               ("failed to read message header filename(%s)",
+                               strerror(errno));
+                       return -1;
+               }
+               clientinfo->requestinfo->service_data.str[clientinfo->requestinfo->
+                                                               service_data.length] = '\0';
+               raw_data = (bundle_raw *)clientinfo->requestinfo->service_data.str;
+               len = clientinfo->requestinfo->service_data.length;
+               if ((b = bundle_decode(raw_data, len)) == NULL) {
+                       TRACE_DEBUG_MSG("Failed to decode bundle raw data");
+                       return -1;
+               }
+               if (service_create(&service_handle) < 0) {
+                       TRACE_DEBUG_MSG("Failed to create service handle");
+                       bundle_free(b);
+                       return -1;
+               }
+               if (service_import_from_bundle(service_handle, b) < 0) {
+                       TRACE_DEBUG_MSG("Failed to import service handle");
+                       bundle_free(b);
+                       service_destroy(service_handle);
+                       return -1;
+               }
+
+               clientinfo->service_handle = service_handle;
+               char *pkg = NULL;
+               service_get_package(service_handle, &pkg);
+               if (pkg) {
+                       TRACE_DEBUG_MSG("operation### [%s]",pkg);
+                       free(pkg);
+               }
+
+               bundle_free(b);
+       }
        if (clientinfo->requestinfo->headers.rows) {
                clientinfo->requestinfo->headers.str =
                        (download_flexible_string *) calloc(clientinfo->requestinfo->headers.
@@ -237,7 +288,7 @@ int ipc_receive_request_msg(download_clientinfo *clientinfo)
                                        strerror(errno));
                                return -1;
                        }
-                       if (clientinfo->requestinfo->headers.str[i].length > 0) {
+                       if (clientinfo->requestinfo->headers.str[i].length > 1) {
                                TRACE_DEBUG_MSG("headers[%d] length[%d]", i,
                                                clientinfo->requestinfo->
                                                headers.str[i].length);
index ba38bb1..1ce130d 100644 (file)
@@ -76,17 +76,17 @@ char *__get_string_status(int state)
 {
        char *message = NULL;
        switch (state) {
-       case DOWNLOAD_STATE_INSTALLING:
-               message = S_("IDS_COM_POP_INSTALLING_ING");
-               break;
        case DOWNLOAD_STATE_FINISHED:
-               message = strdup("Completed");
+               //message = S_("IDS_COM_POP_SUCCESS");
+               message = "Completed";
                break;
        case DOWNLOAD_STATE_STOPPED:
-               message = S_("IDS_COM_POP_CANCELLED");
+               //message = S_("IDS_COM_POP_CANCELLED");
+               message = "Canclled";
                break;
        case DOWNLOAD_STATE_FAILED:
-               message = S_("IDS_COM_POP_FAILED");
+               //message = S_("IDS_COM_POP_FAILED");
+               message = "Failed";
                break;
        default:
                break;
@@ -179,25 +179,34 @@ int destroy_appfw_service(download_clientinfo *clientinfo)
        return 0;
 }
 
-int create_appfw_service(download_clientinfo *clientinfo)
+int create_appfw_service(download_clientinfo *clientinfo, bool ongoing)
 {
        if (!clientinfo)
                return -1;
 
-       if (!clientinfo->service_handle)
-               destroy_appfw_service(clientinfo);
-       if (service_create(&clientinfo->service_handle) < 0) {
-               TRACE_DEBUG_MSG("failed service_create (%s)", strerror(errno));
-               return false;
-       }
-
-       if (clientinfo->requestinfo
-               && clientinfo->requestinfo->client_packagename.str) {
-               if (service_set_package(clientinfo->service_handle,
-                                       clientinfo->requestinfo->
-                                       client_packagename.str) < 0)
-                       TRACE_DEBUG_MSG("failed service_set_package (%s)",
-                                       strerror(errno));
+       if (ongoing) {
+               if (!clientinfo->service_handle) {
+                       if (service_create(&clientinfo->service_handle) < 0) {
+                               TRACE_DEBUG_MSG("failed service_create (%s)", strerror(errno));
+                               return false;
+                       }
+                       if (clientinfo->requestinfo
+                               && clientinfo->requestinfo->client_packagename.str) {
+                               if (service_set_package(clientinfo->service_handle,
+                                                       clientinfo->requestinfo->
+                                                       client_packagename.str) < 0)
+                                       TRACE_DEBUG_MSG("failed service_set_package (%s)",
+                                                       strerror(errno));
+                       }
+               }
+       } else {
+               if (clientinfo->service_handle) {
+                       destroy_appfw_service(clientinfo);
+               }
+               if (service_create(&clientinfo->service_handle) < 0) {
+                       TRACE_DEBUG_MSG("failed service_create (%s)", strerror(errno));
+                       return false;
+               }
        }
        return 0;
 }
@@ -237,16 +246,18 @@ int create_appfw_notification(download_clientinfo *clientinfo, bool ongoing)
        }
 
        if (clientinfo->downloadinfo) {
-               if (clientinfo->downloadinfo->content_name) {
-                       if (ui_notification_set_title
-                               (clientinfo->ui_notification_handle,
-                               clientinfo->downloadinfo->content_name) < 0) {
-                               TRACE_DEBUG_MSG
-                                       ("failed ui_notification_set_title (%s)",
-                                       strerror(errno));
-                               destroy_appfw_notification(clientinfo);
-                               return -1;
-                       }
+               TRACE_DEBUG_MSG("###content_name[%s]", clientinfo->downloadinfo->content_name);
+               char *title = clientinfo->downloadinfo->content_name;
+               if (!title)
+                       //title = S_("IDS_COM_BODY_NO_NAME");
+                       title = "No name";
+               if (ui_notification_set_title(
+                               clientinfo->ui_notification_handle, title) < 0) {
+                       TRACE_DEBUG_MSG
+                               ("failed ui_notification_set_title (%s)",
+                               strerror(errno));
+                       destroy_appfw_notification(clientinfo);
+                       return -1;
                }
        }
 
@@ -259,36 +270,39 @@ int create_appfw_notification(download_clientinfo *clientinfo, bool ongoing)
                return -1;
        }
 
-       create_appfw_service(clientinfo);
 
-       if (clientinfo->service_handle) {
-               if (!ongoing) {
-                       // view the special viewer by contents
-                       if (clientinfo->service_handle
-                               && clientinfo->downloadinginfo
-                               && clientinfo->downloadinginfo->saved_path
-                               && clientinfo->state == DOWNLOAD_STATE_FINISHED) {
-                               if (service_set_operation
-                                       (clientinfo->service_handle,
-                                       SERVICE_OPERATION_VIEW) < 0) {
-                                       TRACE_DEBUG_MSG
-                                               ("Fail service_set_operation");
-                                       destroy_appfw_service(clientinfo);
-                               }
-                               if (service_set_uri(clientinfo->service_handle,
-                                                       clientinfo->downloadinginfo->saved_path)
-                                       < 0) {
-                                       TRACE_DEBUG_MSG("Fail service_set_uri");
-                                       destroy_appfw_service(clientinfo);
-                               }
+       create_appfw_service(clientinfo, ongoing);
+       if (!ongoing) {
+               // view the special viewer by contents
+               if (clientinfo->downloadinginfo
+                       && clientinfo->downloadinginfo->saved_path
+                       && clientinfo->state == DOWNLOAD_STATE_FINISHED) {
+                       if (service_set_operation
+                               (clientinfo->service_handle,
+                               SERVICE_OPERATION_VIEW) < 0) {
+                               TRACE_DEBUG_MSG
+                                       ("Fail service_set_operation");
+                               destroy_appfw_service(clientinfo);
                        }
+                       if (service_set_uri(clientinfo->service_handle,
+                                               clientinfo->downloadinginfo->saved_path)
+                               < 0) {
+                               TRACE_DEBUG_MSG("Fail service_set_uri");
+                               destroy_appfw_service(clientinfo);
+                       }
+               } else {
+                       if (service_set_package(clientinfo->service_handle,
+                                               clientinfo->requestinfo->
+                                               client_packagename.str) < 0)
+                               TRACE_DEBUG_MSG("failed service_set_package (%s)",
+                                               strerror(errno));
                }
-               if (ui_notification_set_service
-                       (clientinfo->ui_notification_handle,
-                       clientinfo->service_handle) < 0) {
-                       TRACE_DEBUG_MSG("Fail ui_notification_set_service");
-                       destroy_appfw_service(clientinfo);
-               }
+       }
+       if (ui_notification_set_service
+               (clientinfo->ui_notification_handle,
+               clientinfo->service_handle) < 0) {
+               TRACE_DEBUG_MSG("Fail ui_notification_set_service");
+               destroy_appfw_service(clientinfo);
        }
 
        if ((ret =
@@ -373,3 +387,9 @@ int set_downloadedinfo_appfw_notification(download_clientinfo *clientinfo)
        destroy_appfw_notification(clientinfo);
        return 0;
 }
+
+void clear_downloadinginfo_appfw_notification()
+{
+       ui_notification_cancel_all_by_type(true);
+       return;
+}
index 63e656b..452ab69 100644 (file)
@@ -75,47 +75,97 @@ void *_start_download(void *args)
                for (i = 0; i < len; i++)
                        req_header[i] =
                                strdup(clientinfo->requestinfo->headers.str[i].str);
-               if (clientinfo->requestinfo->install_path.length > 0)
-                       da_ret =
-                               da_start_download_with_extension(clientinfo->requestinfo->
+               if (clientinfo->requestinfo->install_path.length > 1) {
+                       if (clientinfo->requestinfo->filename.length > 1)
+                               da_ret =
+                                       da_start_download_with_extension(clientinfo->requestinfo->
                                                        url.str, &req_dl_id,
                                                        DA_FEATURE_REQUEST_HEADER,
                                                        req_header, &len,
                                                        DA_FEATURE_INSTALL_PATH,
                                                        clientinfo->requestinfo->install_path.str,
+                                                       DA_FEATURE_FILE_NAME,
+                                                       clientinfo->requestinfo->filename.str,
                                                        DA_FEATURE_USER_DATA,
                                                        (void *)clientinfoslot,
                                                        NULL);
-               else
-                       da_ret =
-                               da_start_download_with_extension(clientinfo->requestinfo->
+                       else
+                               da_ret =
+                                       da_start_download_with_extension(clientinfo->requestinfo->
+                                                       url.str, &req_dl_id,
+                                                       DA_FEATURE_REQUEST_HEADER,
+                                                       req_header, &len,
+                                                       DA_FEATURE_INSTALL_PATH,
+                                                       clientinfo->requestinfo->install_path.str,
+                                                       DA_FEATURE_USER_DATA,
+                                                       (void *)clientinfoslot,
+                                                       NULL);
+               } else {
+                       if (clientinfo->requestinfo->filename.length > 1)
+                               da_ret =
+                                       da_start_download_with_extension(clientinfo->requestinfo->
+                                                       url.str, &req_dl_id,
+                                                       DA_FEATURE_REQUEST_HEADER,
+                                                       req_header, &len,
+                                                       DA_FEATURE_FILE_NAME,
+                                                       clientinfo->requestinfo->filename.str,
+                                                       DA_FEATURE_USER_DATA,
+                                                       (void *)clientinfoslot,
+                                                       NULL);
+                       else
+                               da_ret =
+                                       da_start_download_with_extension(clientinfo->requestinfo->
                                                        url.str, &req_dl_id,
                                                        DA_FEATURE_REQUEST_HEADER,
                                                        req_header, &len,
                                                        DA_FEATURE_USER_DATA,
                                                        (void *)clientinfoslot,
                                                        NULL);
+               }
                for (i = 0; i < len; i++) {
                        if (req_header[i])
                                free(req_header[i]);
                }
        } else {
-               if (clientinfo->requestinfo->install_path.length > 0)
-                       da_ret =
-                               da_start_download_with_extension(clientinfo->requestinfo->
+               if (clientinfo->requestinfo->install_path.length > 1) {
+                       if (clientinfo->requestinfo->filename.length > 1)
+                               da_ret =
+                                       da_start_download_with_extension(clientinfo->requestinfo->
+                                                       url.str, &req_dl_id,
+                                                       DA_FEATURE_INSTALL_PATH,
+                                                       clientinfo->requestinfo->install_path.str,
+                                                       DA_FEATURE_FILE_NAME,
+                                                       clientinfo->requestinfo->filename.str,
+                                                       DA_FEATURE_USER_DATA,
+                                                       (void *)clientinfoslot,
+                                                       NULL);
+                       else
+                               da_ret =
+                                       da_start_download_with_extension(clientinfo->requestinfo->
                                                        url.str, &req_dl_id,
                                                        DA_FEATURE_INSTALL_PATH,
                                                        clientinfo->requestinfo->install_path.str,
                                                        DA_FEATURE_USER_DATA,
                                                        (void *)clientinfoslot,
                                                        NULL);
-               else
-                       da_ret =
-                               da_start_download_with_extension(clientinfo->requestinfo->
+               } else {
+                       if (clientinfo->requestinfo->filename.length > 1)
+                               da_ret =
+                                       da_start_download_with_extension(clientinfo->requestinfo->
                                                        url.str, &req_dl_id,
+                                                       DA_FEATURE_FILE_NAME,
+                                                       clientinfo->requestinfo->filename.str,
                                                        DA_FEATURE_USER_DATA,
                                                        (void *)clientinfoslot,
                                                        NULL);
+                       else
+                               da_ret =
+                                       da_start_download_with_extension(clientinfo->requestinfo->
+                                                       url.str, &req_dl_id,
+                                                       DA_FEATURE_USER_DATA,
+                                                       (void *)clientinfoslot,
+                                                       NULL);
+               }
        }
 
        // if start_download() return error cause of maximun download limitation, set state to DOWNLOAD_STATE_PENDED.
@@ -139,7 +189,6 @@ void *_start_download(void *args)
                                                        requestinfo->requestid);
                ipc_send_request_stateinfo(clientinfo);
                CLIENT_MUTEX_UNLOCK(&(clientinfo->client_mutex));
-               clear_clientinfoslot(clientinfoslot);
                return 0;
        }
 
@@ -209,29 +258,54 @@ int _handle_new_connection(download_clientinfo_slot *clientinfo_list, download_c
                                                        request_clientinfo->requestinfo->requestid);
                        if (type == DOWNLOAD_CONTROL_STOP) {
                                TRACE_DEBUG_MSG("Request : DOWNLOAD_CONTROL_STOP");
-                               // remove info from downloading table.
-                               download_provider_db_requestinfo_remove
-                                       (request_clientinfo->requestinfo->requestid);
                                if (searchindex >= 0) {
-                                       CLIENT_MUTEX_LOCK(&
-                                               (clientinfo_list[searchindex].clientinfo->client_mutex));
                                        if (da_cancel_download
                                                (clientinfo_list[searchindex].clientinfo->req_id)
                                                == DA_RESULT_OK) {
                                                request_clientinfo->state = DOWNLOAD_STATE_STOPPED;
                                                request_clientinfo->err = DOWNLOAD_ERROR_NONE;
+                                               if (clientinfo_list[searchindex].clientinfo->requestinfo
+                                                       && clientinfo_list[searchindex].clientinfo->requestinfo->notification)
+                                                       set_downloadedinfo_appfw_notification(clientinfo_list[searchindex].clientinfo);
+                                               download_provider_db_requestinfo_remove(request_clientinfo->requestinfo->requestid);
+                                               download_provider_db_history_new(clientinfo_list[searchindex].clientinfo);
                                        } else {
                                                request_clientinfo->state = DOWNLOAD_STATE_FAILED;
                                                request_clientinfo->err = DOWNLOAD_ERROR_INVALID_PARAMETER;
                                        }
-                                       ipc_send_stateinfo(request_clientinfo);
-                                       CLIENT_MUTEX_UNLOCK(&
-                                               (clientinfo_list[searchindex].clientinfo->client_mutex));
+                               } else { // no found
+                                       request_clientinfo->state = DOWNLOAD_STATE_NONE;
+                                       request_clientinfo->err = DOWNLOAD_ERROR_NONE;
                                }
-                       } else if (type == DOWNLOAD_CONTROL_GET_STATE_INFO)
-                       {
-                               // not implemented yet
+                               ipc_send_stateinfo(request_clientinfo);
+                       } else if (type == DOWNLOAD_CONTROL_GET_STATE_INFO) {
                                // search slots/downloading db/history db
+                               if (searchindex > 0) { // exist in slots (memory)
+                                       request_clientinfo->state =
+                                               clientinfo_list[searchindex].clientinfo->state;
+                                       request_clientinfo->err =
+                                               clientinfo_list[searchindex].clientinfo->err;
+                               } else {  //search downloading db or history db
+                                       download_dbinfo* dbinfo =
+                                               download_provider_db_get_info(
+                                                       request_clientinfo->requestinfo->requestid);
+                                       if (dbinfo) { // found in downloading db..it means crashed job
+                                               request_clientinfo->state = DOWNLOAD_STATE_PENDED;
+                                               request_clientinfo->err = DOWNLOAD_ERROR_TOO_MANY_DOWNLOADS;
+                                       } else { // no exist in downloading db
+                                               dbinfo = download_provider_db_history_get_info(
+                                                       request_clientinfo->requestinfo->requestid);
+                                               if (!dbinfo) { // no info anywhere
+                                                       request_clientinfo->state = DOWNLOAD_STATE_NONE;
+                                                       request_clientinfo->err = DOWNLOAD_ERROR_NONE;
+                                               } else { //history info
+                                                       request_clientinfo->state = dbinfo->state;
+                                                       request_clientinfo->err = DOWNLOAD_ERROR_NONE;
+                                               }
+                                       }
+                                       download_provider_db_info_free(dbinfo);
+                               }
+                               ipc_send_stateinfo(request_clientinfo);
                                // estabilish the spec of return value.
                        }
                }
@@ -253,14 +327,11 @@ 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) {
-                       CLIENT_MUTEX_LOCK(&(request_clientinfo->client_mutex));
                        TRACE_DEBUG_MSG("Not Found Same Request ID");
-                       request_clientinfo->requestinfo->requestid = 0;
                        // Invalid id
                        request_clientinfo->state = DOWNLOAD_STATE_FAILED;
                        request_clientinfo->err = DOWNLOAD_ERROR_INVALID_PARAMETER;
                        ipc_send_request_stateinfo(request_clientinfo);
-                       CLIENT_MUTEX_UNLOCK(&(request_clientinfo->client_mutex));
                        clear_clientinfo(request_clientinfo);
                        return 0;
                } else {        // found request id. // how to deal etag ?
@@ -364,11 +435,11 @@ int _handle_client_request(download_clientinfo* clientinfo)
                return -1;
        }
 
-       CLIENT_MUTEX_LOCK(&(clientinfo->client_mutex));
        switch (msgType = ipc_receive_header(clientinfo->clientfd)) {
        case DOWNLOAD_CONTROL_STOP:
                TRACE_DEBUG_MSG("DOWNLOAD_CONTROL_STOP");
                da_ret = da_cancel_download(clientinfo->req_id);
+               CLIENT_MUTEX_LOCK(&(clientinfo->client_mutex));
                if (da_ret != DA_RESULT_OK) {
                        /* FIXME : need to seperate in detail according to error return values */
                        clientinfo->state = DOWNLOAD_STATE_FAILED;
@@ -377,12 +448,21 @@ int _handle_client_request(download_clientinfo* clientinfo)
                } else {
                        clientinfo->state = DOWNLOAD_STATE_STOPPED;
                        clientinfo->err = DOWNLOAD_ERROR_NONE;
+                       if (clientinfo->requestinfo) {
+                               if (clientinfo->requestinfo->notification)
+                                       set_downloadedinfo_appfw_notification(clientinfo);
+                               download_provider_db_requestinfo_remove(clientinfo->
+                                       requestinfo->requestid);
+                       }
+                       download_provider_db_history_new(clientinfo);
                }
                ipc_send_stateinfo(clientinfo);
+               CLIENT_MUTEX_UNLOCK(&(clientinfo->client_mutex));
                break;
        case DOWNLOAD_CONTROL_PAUSE:
                TRACE_DEBUG_MSG("DOWNLOAD_CONTROL_PAUSE");
                da_ret = da_suspend_download(clientinfo->req_id);
+               CLIENT_MUTEX_LOCK(&(clientinfo->client_mutex));
                if (da_ret != DA_RESULT_OK) {
                        /* FIXME : need to seperate in detail according to error return values */
                        clientinfo->state = DOWNLOAD_STATE_FAILED;
@@ -393,10 +473,12 @@ int _handle_client_request(download_clientinfo* clientinfo)
                        clientinfo->err = DOWNLOAD_ERROR_NONE;
                }
                ipc_send_stateinfo(clientinfo);
+               CLIENT_MUTEX_UNLOCK(&(clientinfo->client_mutex));
                break;
        case DOWNLOAD_CONTROL_RESUME:
                TRACE_DEBUG_MSG("DOWNLOAD_CONTROL_RESUME");
                da_ret = da_resume_download(clientinfo->req_id);
+               CLIENT_MUTEX_LOCK(&(clientinfo->client_mutex));
                if (da_ret != DA_RESULT_OK) {
                        /* FIXME : need to seperate in detail according to error return values */
                        clientinfo->state = DOWNLOAD_STATE_FAILED;
@@ -407,14 +489,19 @@ int _handle_client_request(download_clientinfo* clientinfo)
                        clientinfo->err = DOWNLOAD_ERROR_NONE;
                }
                ipc_send_stateinfo(clientinfo);
+               CLIENT_MUTEX_UNLOCK(&(clientinfo->client_mutex));
                break;
        case DOWNLOAD_CONTROL_GET_STATE_INFO:   // sync call
                TRACE_DEBUG_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");
+               CLIENT_MUTEX_LOCK(&(clientinfo->client_mutex));
                ipc_send_downloadinfo(clientinfo);
+               CLIENT_MUTEX_UNLOCK(&(clientinfo->client_mutex));
                break;
        case -1:
        case 0:
@@ -423,14 +510,11 @@ int _handle_client_request(download_clientinfo* clientinfo)
                // bloken socket... it seems the client is dead or closed by agent thread.
                // close socket, this will break the loop. and terminate this thread.
                clear_socket(clientinfo);
-               CLIENT_MUTEX_UNLOCK(&(clientinfo->client_mutex));
                return -1;
        default:
                TRACE_DEBUG_MSG("Unknow message [%d]", msgType);
-               CLIENT_MUTEX_UNLOCK(&(clientinfo->client_mutex));
                return -1;
        }
-       CLIENT_MUTEX_UNLOCK(&(clientinfo->client_mutex));
        return 0;
 }
 
@@ -460,6 +544,7 @@ void *run_manage_download_server(void *args)
                TerminateDaemon(SIGTERM);
                return 0;
        }
+       clear_downloadinginfo_appfw_notification();
 
        if ((listenfd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
                TRACE_DEBUG_MSG("failed to create socket");
@@ -530,14 +615,11 @@ void *run_manage_download_server(void *args)
                for (i=0; i < MAX_CLIENT; i++) {
                        if (!clientinfo_list[i].clientinfo)
                                continue;
-                       CLIENT_MUTEX_LOCK(&(clientinfo_list[i].clientinfo->client_mutex));
                        // clear slot.
                        if (clientinfo_list[i].clientinfo->state >= DOWNLOAD_STATE_FINISHED) {
-                               CLIENT_MUTEX_UNLOCK(&(clientinfo_list[i].clientinfo->client_mutex));
                                clear_clientinfoslot(&clientinfo_list[i]);
                                continue;
                        }
-                       CLIENT_MUTEX_UNLOCK(&(clientinfo_list[i].clientinfo->client_mutex));
                }
 
                rset = g_download_provider_socket_readset;
@@ -555,9 +637,12 @@ void *run_manage_download_server(void *args)
                for (i=0; i < MAX_CLIENT; i++) {  // find the socket received the packet.
                        if (!clientinfo_list[i].clientinfo)
                                continue;
+                       // ignore it is not started yet.
+                       if (clientinfo_list[i].clientinfo->state <= DOWNLOAD_STATE_READY)
+                               continue;
                        // ignore if finished
-                       //if (clientinfo_list[i].clientinfo->state >= DOWNLOAD_STATE_FINISHED)
-                               //continue;
+                       if (clientinfo_list[i].clientinfo->state >= DOWNLOAD_STATE_FINISHED)
+                               continue;
                        //Even if no socket, downloading should be progressed.
                        if (clientinfo_list[i].clientinfo->clientfd <= 0)
                                continue;
@@ -604,15 +689,17 @@ void *run_manage_download_server(void *args)
                                sleep(5);       // provider need the time of refresh.
                                continue;
                        }
-                       FD_SET(request_clientinfo->clientfd, &g_download_provider_socket_readset);      // add new descriptor to set
-                       FD_SET(request_clientinfo->clientfd, &g_download_provider_socket_exceptset);
-                       if (request_clientinfo->clientfd > maxfd )
-                               maxfd = request_clientinfo->clientfd;   /* for select */
-
                        if (_handle_new_connection(clientinfo_list, request_clientinfo) < 0) {
                                sleep(1);
                                continue;
                        }
+                       // after starting the download by DA, event thread will start to get the event from client.
+                       if (request_clientinfo && request_clientinfo->clientfd > 0) {
+                               FD_SET(request_clientinfo->clientfd, &g_download_provider_socket_readset);      // add new descriptor to set
+                               FD_SET(request_clientinfo->clientfd, &g_download_provider_socket_exceptset);
+                               if (request_clientinfo->clientfd > maxfd )
+                                       maxfd = request_clientinfo->clientfd;   /* for select */
+                       }
                }
 
                if (i >= MAX_CLIENT) { // timeout
@@ -939,20 +1026,22 @@ void __notify_cb(user_notify_info_t *notify_info, void *user_data)
                TRACE_DEBUG_MSG("[CRITICAL] clientinfo is NULL");
                return;
        }
-       CLIENT_MUTEX_LOCK(&(clientinfo->client_mutex));
+
        TRACE_DEBUG_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) {
                TRACE_DEBUG_MSG("[CRITICAL] req_id[%d] da_dl_req_id[%d}",
                                clientinfo->req_id, notify_info->da_dl_req_id);
-               CLIENT_MUTEX_UNLOCK(&(clientinfo->client_mutex));
                return;
        }
 
+       CLIENT_MUTEX_LOCK(&(clientinfo->client_mutex));
+
        clientinfo->state = __change_state(notify_info->state);
        clientinfo->err = __change_error(notify_info->err);
-       if (clientinfo->state >= DOWNLOAD_STATE_FINISHED) {
+       if (clientinfo->state == DOWNLOAD_STATE_FINISHED ||
+                       clientinfo->state == DOWNLOAD_STATE_FAILED) {
                if (clientinfo->requestinfo) {
                        if (clientinfo->requestinfo->notification)
                                set_downloadedinfo_appfw_notification(clientinfo);
index 8b43cd9..2270534 100644 (file)
@@ -72,6 +72,9 @@ void clear_clientinfo(download_clientinfo *clientinfo)
                if (clientinfo->requestinfo->filename.str)
                        free(clientinfo->requestinfo->filename.str);
                clientinfo->requestinfo->filename.str = NULL;
+               if (clientinfo->requestinfo->service_data.str)
+                       free(clientinfo->requestinfo->service_data.str);
+               clientinfo->requestinfo->service_data.str = NULL;
                if (clientinfo->requestinfo->headers.rows) {
                        int i = 0;
                        for (i = 0; i < clientinfo->requestinfo->headers.rows;