Code cleanup 50/49350/2 accepted/tizen/mobile/20151013.040726 accepted/tizen/tv/20151013.040737 accepted/tizen/wearable/20151013.040751 submit/tizen/20151013.020448
authorMinje Ahn <minje.ahn@samsung.com>
Tue, 13 Oct 2015 01:19:41 +0000 (10:19 +0900)
committerMinje Ahn <minje.ahn@samsung.com>
Tue, 13 Oct 2015 01:51:23 +0000 (10:51 +0900)
Change-Id: I9bb372674a3fe257278b4867db0153d29b6a16da
Signed-off-by: Minje Ahn <minje.ahn@samsung.com>
server/thumb-server-internal.c
src/ipc/media-thumb-ipc.c
src/media-thumbnail.c
src/util/media-thumb-db.c

index e9e9530..88b6190 100755 (executable)
@@ -177,8 +177,13 @@ int _thumb_daemon_process_job(thumbMsg *req_msg, thumbMsg *res_msg, uid_t uid)
                        thumb_err("_media_thumb_process is failed: %d", err);
                        res_msg->status = THUMB_FAIL;
                } else {
-                       thumb_warn("_media_thumb_process is failed: %d, So use default thumb", err);
-                       res_msg->status = THUMB_SUCCESS;
+                       if (err != MS_MEDIA_ERR_FILE_NOT_EXIST) {
+                               thumb_warn("_media_thumb_process is failed: %d, So use default thumb", err);
+                               res_msg->status = THUMB_SUCCESS;
+                       } else {
+                               thumb_warn("_media_thumb_process is failed: %d, (file not exist) ", err);
+                               res_msg->status = THUMB_FAIL;
+                       }
                }
        } else {
                res_msg->status = THUMB_SUCCESS;
@@ -784,6 +789,7 @@ int _media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg, uid_t uid)
                                                thumb_err("_media_thumb_get_hash_name failed - %d", err);
                                                strncpy(thumb_path, default_path, max_length);
                                                free(default_path);
+                                               default_path = NULL;
                                        }
                                        _media_thumb_db_disconnect();
                                        return err;
@@ -804,6 +810,7 @@ int _media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg, uid_t uid)
                                thumb_err("_media_thumb_get_hash_name failed - %d", err);
                                strncpy(thumb_path, default_path, max_length);
                                free(default_path);
+                               default_path = NULL;
                        }
                        _media_thumb_db_disconnect();
                        return err;
@@ -828,6 +835,7 @@ int _media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg, uid_t uid)
                if(default_path) {
                        strncpy(thumb_path, default_path, max_length);
                        free(default_path);
+                       default_path = NULL;
                }
                goto DB_UPDATE;
 //             _media_thumb_db_disconnect();
@@ -869,6 +877,7 @@ int _media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg, uid_t uid)
                                if(default_path) {
                                        strncpy(thumb_path, default_path, max_length);
                                        free(default_path);
+                                       default_path = NULL;
                                }
                        }
                        _media_thumb_db_disconnect();
index bf9e568..76e7d0a 100755 (executable)
@@ -32,6 +32,7 @@
 #include <pwd.h>
 
 #define THUMB_SOCK_BLOCK_SIZE 512
+#define THUMB_IPC_PATH "/var/run/media-server/media_ipc_thumbcreator.socket"
 
 static GQueue *g_request_queue = NULL;
 static GQueue *g_manage_queue = NULL;
@@ -513,7 +514,7 @@ _media_thumb_request(int msg_type, const char *origin_path, char *thumb_path, in
        memset(&serv_addr, 0, sizeof(serv_addr));
        sock = sock_info.sock_fd;
        serv_addr.sun_family = AF_UNIX;
-       strcpy(serv_addr.sun_path, "/var/run/media-server/media_ipc_thumbcreator.socket");
+       strncpy(serv_addr.sun_path, THUMB_IPC_PATH, strlen(THUMB_IPC_PATH));
 
        /* Connecting to the thumbnail server */
        if (connect(sock, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) < 0) {
@@ -752,7 +753,7 @@ int _media_thumb_send_request() {
        memset(&serv_addr, 0, sizeof(serv_addr));
        sock = sock_info.sock_fd;
        serv_addr.sun_family = AF_UNIX;
-       strcpy(serv_addr.sun_path, "/var/run/media-server/media_ipc_thumbcreator.socket");
+       strncpy(serv_addr.sun_path, THUMB_IPC_PATH, strlen(THUMB_IPC_PATH));
 
        GIOChannel *channel = NULL;
        channel = g_io_channel_unix_new(sock);
@@ -855,7 +856,7 @@ int _media_thumb_raw_data_send_request() {
        memset(&serv_addr, 0, sizeof(serv_addr));
        sock = sock_info.sock_fd;
        serv_addr.sun_family = AF_UNIX;
-       strcpy(serv_addr.sun_path, "/var/run/media-server/media_ipc_thumbcreator.socket");
+       strncpy(serv_addr.sun_path, THUMB_IPC_PATH, strlen(THUMB_IPC_PATH));
 
        GIOChannel *channel = NULL;
        channel = g_io_channel_unix_new(sock);
index dd16356..0920eec 100755 (executable)
@@ -121,6 +121,10 @@ int thumbnail_request_from_db_async(const char *origin_path, ThumbFunc func, voi
        thumb_dbg_slog("Path : %s", origin_path);
 
        thumbUserData *userData = (thumbUserData*)malloc(sizeof(thumbUserData));
+       if (userData == NULL) {
+               thumb_err("memory allocation failed");
+               return MS_MEDIA_ERR_OUT_OF_MEMORY;
+       }
        userData->func = (ThumbFunc)func;
        userData->user_data = user_data;
 
@@ -152,6 +156,10 @@ int thumbnail_request_extract_raw_data_async(int request_id, const char *origin_
        thumb_dbg_slog("Path : %s", origin_path);
 
        thumbRawUserData *userData = (thumbRawUserData*)malloc(sizeof(thumbRawUserData));
+       if(userData == NULL) {
+               thumb_err("userData malloc failed : %d", err);
+               return MS_MEDIA_ERR_OUT_OF_MEMORY;
+       }
        userData->func = func;
        userData->user_data = user_data;
 
index 8e77b95..06f028a 100755 (executable)
 #include <glib.h>
 #include <string.h>
 #include <unistd.h>
-#include <util-func.h>
 
 static __thread  MediaDBHandle *db_handle;
 
-static int _media_thumb_busy_handler(void *pData, int count)
-{
-       usleep(50000);
-       thumb_dbg("_media_thumb_busy_handler called : %d\n", count);
-
-       return 100 - count;
-}
-
 sqlite3 *_media_thumb_db_get_handle()
 {
        return db_handle;
 }
 
-int _media_thumb_sqlite_connect(sqlite3 **handle)
-{
-       int err = MS_MEDIA_ERR_NONE;
-
-       err = db_util_open(MEDIA_DATABASE_NAME, handle,
-                        DB_UTIL_REGISTER_HOOK_METHOD);
-
-       if (SQLITE_OK != err) {
-               *handle = NULL;
-               return MS_MEDIA_ERR_INVALID_PARAMETER;
-       }
-
-       /*Register busy handler*/
-       if (*handle) {
-               err = sqlite3_busy_handler(*handle, _media_thumb_busy_handler, NULL);
-               if (SQLITE_OK != err) {
-                       if (*handle) {
-                               thumb_err("[sqlite] %s\n", sqlite3_errmsg(*handle));
-                               db_util_close(*handle);
-                       }
-                       *handle = NULL;
-
-                       return MS_MEDIA_ERR_INVALID_PARAMETER;
-               }
-       } else {
-               *handle = NULL;
-               return MS_MEDIA_ERR_INVALID_PARAMETER;
-       }
-
-       return MS_MEDIA_ERR_NONE;
-}
-
-int _media_thumb_sqlite_disconnect(sqlite3 *handle)
-{
-       int err = MS_MEDIA_ERR_NONE;
-       if (handle != NULL) {
-               err = db_util_close(handle);
-
-               if (SQLITE_OK != err) {
-                       handle = NULL;
-                       return MS_MEDIA_ERR_INVALID_PARAMETER;
-               }
-       }
-
-       return MS_MEDIA_ERR_NONE;
-}
-
-int
-_media_thumb_get_type_from_db(sqlite3 *handle,
+int _media_thumb_get_type_from_db(sqlite3 *handle,
                                                                        const char *origin_path,
                                                                        int *type)
 {
+       int err = MS_MEDIA_ERR_NONE;
+       char *path_string = NULL;
+       char *query_string = NULL;
+       sqlite3_stmt *stmt = NULL;
+
        thumb_dbg_slog("Origin path : %s", origin_path);
 
        if (handle == NULL) {
@@ -102,11 +50,6 @@ _media_thumb_get_type_from_db(sqlite3 *handle,
                return MS_MEDIA_ERR_INVALID_PARAMETER;
        }
 
-       int err = -1;
-       char *path_string = NULL;
-       char *query_string = NULL;
-       sqlite3_stmt *stmt = NULL;
-
        path_string = sqlite3_mprintf("%s", origin_path);
        query_string = sqlite3_mprintf(SELECT_TYPE_BY_PATH, path_string);