Code cleanup 61/213861/6
authorMinje Ahn <minje.ahn@samsung.com>
Mon, 16 Sep 2019 02:43:26 +0000 (11:43 +0900)
committerMinje Ahn <minje.ahn@samsung.com>
Mon, 16 Sep 2019 05:54:10 +0000 (14:54 +0900)
Change-Id: I89af900ba9477a68632482e7960683949df37107
Signed-off-by: Minje Ahn <minje.ahn@samsung.com>
server/thumb-server-internal.c
server/thumb-server.c
src/include/util/media-thumb-debug.h
src/ipc/media-thumb-ipc.c
src/media-thumb-internal.c
src/media-thumbnail.c
src/util/media-thumb-db.c

index 624938768e741ecfe431578e60f9101f8bd52926..79c2a80c8c86b5e6bd872030d60c584f8421daa9 100755 (executable)
 #define THUMB_COMM_SOCK_PATH tzplatform_mkpath(TZ_SYS_RUN, "media-server/media_ipc_thumbcomm.socket")
 #define THUMB_EMPTY_STR ""
 
-GMainLoop *g_thumb_server_mainloop; // defined in thumb-server.c as extern
+static void __thumb_server_send_deny_message(int sockfd)
+{
+       thumbMsg msg = {0};
 
-static gboolean __thumb_server_send_msg_to_agent(int msg_type);
-static gboolean _thumb_server_send_deny_message(int sockfd);
+       msg.msg_type = THUMB_RESPONSE;
+       msg.status = MS_MEDIA_ERR_PERMISSION_DENIED;
+
+       if (send(sockfd, &msg, sizeof(msg), 0) < 0)
+               thumb_stderror("send failed");
+}
 
 gboolean _thumb_daemon_start_jobs(gpointer data)
 {
-       thumb_dbg("");
-       __thumb_server_send_msg_to_agent(MS_MSG_THUMB_SERVER_READY);
+       int client_sock;
+       struct sockaddr_un serv_addr;
+       ms_thumb_server_msg send_msg;
+
+       if (ms_ipc_create_client_socket(MS_TIMEOUT_SEC_10, &client_sock) < 0) {
+               thumb_err("ms_ipc_create_server_socket failed");
+               return G_SOURCE_REMOVE;
+       }
+
+       memset(&serv_addr, 0, sizeof(serv_addr));
+
+       serv_addr.sun_family = AF_UNIX;
+       SAFE_STRLCPY(serv_addr.sun_path, THUMB_COMM_SOCK_PATH, sizeof(serv_addr.sun_path));
+
+       /* Connecting to the thumbnail server */
+       if (connect(client_sock, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) < 0) {
+               thumb_stderror("connect");
+               goto ERROR;
+       }
 
-       return FALSE;
+       send_msg.msg_type = MS_MSG_THUMB_SERVER_READY;
+
+       if (send(client_sock, &send_msg, sizeof(ms_thumb_server_msg), 0) < 0) {
+               thumb_stderror("send failed");
+               goto ERROR;
+       }
+
+       thumb_dbg("Sending msg to thumbnail agent[%d] is successful", send_msg.msg_type);
+ERROR:
+       close(client_sock);
+
+       return G_SOURCE_REMOVE;
 }
 
 int _thumb_daemon_process_job(thumbMsg *req_msg, thumbMsg *res_msg)
@@ -77,6 +111,7 @@ gboolean _thumb_server_read_socket(GIOChannel *src, GIOCondition condition, gpoi
        thumbMsg recv_msg;
        thumbMsg res_msg;
        ms_peer_credentials credentials;
+       GMainLoop *thumb_server = (GMainLoop *)data;
 
        int sock = -1;
        int client_sock = -1;
@@ -86,36 +121,30 @@ gboolean _thumb_server_read_socket(GIOChannel *src, GIOCondition condition, gpoi
        memset((void *)&credentials, 0, sizeof(credentials));
 
        sock = g_io_channel_unix_get_fd(src);
-       if (sock < 0) {
-               thumb_err("sock fd is invalid!");
-               return TRUE;
-       }
+       thumb_retvm_if(sock < 0, G_SOURCE_CONTINUE, "sock fd is invalid!");
 
        client_addr_len = sizeof(client_addr);
 
        if ((client_sock = accept(sock, (struct sockaddr*)&client_addr, &client_addr_len)) < 0) {
                thumb_stderror("accept failed");
-               return TRUE;
+               return G_SOURCE_CONTINUE;
        }
 
        if (ms_cynara_receive_untrusted_message_thumb(client_sock, &recv_msg, &credentials) != MS_MEDIA_ERR_NONE) {
                thumb_err("ms_cynara_receive_untrusted_message_thumb failed");
-               close(client_sock);
-               return FALSE;
+               goto ERROR;
        }
 
        if (recv_msg.msg_type != THUMB_REQUEST_KILL_SERVER) {
                if (ms_cynara_check(&credentials, MEDIA_STORAGE_PRIVILEGE) != MS_MEDIA_ERR_NONE) {
                        thumb_err("Cynara denied access to process request");
-                       _thumb_server_send_deny_message(client_sock);
-                       close(client_sock);
-                       return TRUE;
+                       __thumb_server_send_deny_message(client_sock);
+                       goto ERROR;
                }
        } else {
                thumb_warn("Shutting down...");
-               g_main_loop_quit(g_thumb_server_mainloop);
-               close(client_sock);
-               return TRUE;
+               g_main_loop_quit(thumb_server);
+               goto ERROR;
        }
 
        SAFE_FREE(credentials.smack);
@@ -152,62 +181,10 @@ gboolean _thumb_server_read_socket(GIOChannel *src, GIOCondition condition, gpoi
        SAFE_FREE(buf);
        SAFE_FREE(res_msg.thumb_data);
 
+ERROR:
        close(client_sock);
 
-       return TRUE;
-}
-
-static gboolean __thumb_server_send_msg_to_agent(int msg_type)
-{
-       int sock;
-       struct sockaddr_un serv_addr;
-       ms_thumb_server_msg send_msg;
-
-       if (ms_ipc_create_client_socket(MS_TIMEOUT_SEC_10, &sock) < 0) {
-               thumb_err("ms_ipc_create_server_socket failed");
-               return FALSE;
-       }
-
-       memset(&serv_addr, 0, sizeof(serv_addr));
-
-       serv_addr.sun_family = AF_UNIX;
-       SAFE_STRLCPY(serv_addr.sun_path, THUMB_COMM_SOCK_PATH, sizeof(serv_addr.sun_path));
-
-       /* Connecting to the thumbnail server */
-       if (connect(sock, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) < 0) {
-               thumb_stderror("connect");
-               close(sock);
-               return MS_MEDIA_ERR_SOCKET_CONN;
-       }
-
-       send_msg.msg_type = msg_type;
-
-       if (send(sock, &send_msg, sizeof(ms_thumb_server_msg), 0) < 0) {
-               thumb_stderror("send failed");
-               close(sock);
-               return FALSE;
-       }
-
-       thumb_dbg("Sending msg to thumbnail agent[%d] is successful", send_msg.msg_type);
-       close(sock);
-
-       return TRUE;
-}
-
-static gboolean _thumb_server_send_deny_message(int sockfd)
-{
-       thumbMsg msg = {0};
-       int bytes_to_send = sizeof(msg);
-
-       msg.msg_type = THUMB_RESPONSE;
-       msg.status = MS_MEDIA_ERR_PERMISSION_DENIED;
-
-       if (send(sockfd, &msg, bytes_to_send, 0) < 0) {
-               thumb_stderror("send failed");
-               return FALSE;
-       }
-
-       return TRUE;
+       return G_SOURCE_CONTINUE;
 }
 
 gboolean _thumb_server_prepare_socket(int *sock_fd)
@@ -235,17 +212,10 @@ int _thumbnail_get_data(const char *origin_path, char *thumb_path)
        int err = MS_MEDIA_ERR_NONE;
        int file_type = THUMB_NONE_TYPE;
 
-       if (origin_path == NULL) {
-               thumb_err("Original path is null");
-               return MS_MEDIA_ERR_INVALID_PARAMETER;
-       }
-
-       if (!g_file_test(origin_path, G_FILE_TEST_IS_REGULAR)) {
-               thumb_err("Original path (%s) does not exist", origin_path);
-               return MS_MEDIA_ERR_INVALID_PARAMETER;
-       }
-
+       thumb_retvm_if(!origin_path, MS_MEDIA_ERR_INVALID_PARAMETER, "Original path is null");
+       thumb_retvm_if(!g_file_test(origin_path, G_FILE_TEST_IS_REGULAR), MS_MEDIA_ERR_INVALID_PARAMETER, "Original path(%s) does not exist", origin_path);
        thumb_dbg("Origin path : %s", origin_path);
+
        file_type = _media_thumb_get_file_type(origin_path);
 
        if (file_type == THUMB_IMAGE_TYPE) {
index 4bb521f62f40d9de72799d9ddea23418f7ed9975..3541d44c10b7db39e90c63b5078775cf01f12f72 100755 (executable)
@@ -32,7 +32,7 @@
 
 #define LOG_TAG "MEDIA_THUMBNAIL_SERVER"
 
-extern GMainLoop *g_thumb_server_mainloop;
+static GMainLoop *g_thumb_server_mainloop;
 
 int main(void)
 {
@@ -60,7 +60,7 @@ int main(void)
        source = g_io_create_watch(channel, G_IO_IN);
 
        /* Set callback to be called when socket is readable */
-       g_source_set_callback(source, (GSourceFunc)_thumb_server_read_socket, NULL, NULL);
+       g_source_set_callback(source, (GSourceFunc)_thumb_server_read_socket, (gpointer)g_thumb_server_mainloop, NULL);
        g_source_attach(source, context);
 
        GSource *source_evas_init = NULL;
index b88ae4fc6939f5004fbd66cca3f8ac0a733dbb30..2aa517f66eb9b52e0ae71bd4405a3bd1f98f19ea 100755 (executable)
                SECURE_LOGE(FONT_COLOR_RED""fmt""FONT_COLOR_RESET, ##arg); \
                } while (0)
 
-#define ERR_BUF_LENGHT 256
+#define ERR_BUF_LENGTH 256
 #define thumb_stderror(fmt) do { \
-                       char thumb_stderror_buffer[ERR_BUF_LENGHT] = {0,}; \
-                       LOGE(FONT_COLOR_RED fmt" : standard error [%s]", strerror_r(errno, thumb_stderror_buffer, ERR_BUF_LENGHT)); \
+                       char thumb_stderror_buffer[ERR_BUF_LENGTH] = {0,}; \
+                       LOGE(FONT_COLOR_RED fmt" : standard error [%s]", strerror_r(errno, thumb_stderror_buffer, ERR_BUF_LENGTH)); \
                } while (0)
 
 #define thumb_retm_if(expr, fmt, arg...) do { \
index ed5ecb772e407e22504ab794100194550684b0c0..64afe5ac42c30ee294eec361d83139f8de06184a 100755 (executable)
@@ -63,11 +63,11 @@ typedef struct {
        thumbRawUserData *userData;
 } thumbRawReq;
 
-static int _media_thumb_send_request();
-static int _media_thumb_raw_data_send_request();
+static int __media_thumb_send_request(void);
+static int __media_thumb_raw_data_send_request(void);
 
 
-int _media_thumb_get_error()
+static int __media_thumb_get_error(void)
 {
        if (errno == EWOULDBLOCK) {
                thumb_err("Timeout. Can't try any more");
@@ -78,173 +78,162 @@ int _media_thumb_get_error()
        }
 }
 
-void __media_thumb_pop()
+static void __media_thumb_pop(void)
 {
        int len = 0;
        int sock = 0;
+       thumbReq *req = NULL;
 
-       if (g_manage_queue != NULL) {
-               thumbReq *req = (thumbReq *)g_queue_pop_head(g_manage_queue);
-               if (req != NULL) {
-                       GSource *source_id = g_main_context_find_source_by_id(g_main_context_get_thread_default(), req->source_id);
-                       sock = g_io_channel_unix_get_fd(req->channel);
-
-                       g_io_channel_shutdown(req->channel, TRUE, NULL);
-                       g_io_channel_unref(req->channel);
-                       close(sock);
-                       if (source_id != NULL) {
-                               g_source_destroy(source_id);
-                       } else {
-                               thumb_err("G_SOURCE_ID is NULL");
-                       }
+       if (!g_manage_queue)
+               return;
 
-                       SAFE_FREE(req->path);
-                       SAFE_FREE(req->userData);
-                       SAFE_FREE(req);
+       req = (thumbReq *)g_queue_pop_head(g_manage_queue);
+       if (req != NULL) {
+               GSource *source_id = g_main_context_find_source_by_id(g_main_context_get_thread_default(), req->source_id);
+               sock = g_io_channel_unix_get_fd(req->channel);
+
+               g_io_channel_shutdown(req->channel, TRUE, NULL);
+               g_io_channel_unref(req->channel);
+               close(sock);
+               if (source_id) {
+                       g_source_destroy(source_id);
+               } else {
+                       thumb_err("G_SOURCE_ID is NULL");
                }
 
-               /* Check manage queue */
-               len = g_queue_get_length(g_manage_queue);
-               if (len > 0)
-                       _media_thumb_send_request();
+               SAFE_FREE(req->path);
+               SAFE_FREE(req->userData);
+               SAFE_FREE(req);
        }
+
+       /* Check manage queue */
+       len = g_queue_get_length(g_manage_queue);
+       if (len > 0)
+               __media_thumb_send_request();
 }
 
-int __media_thumb_cancel(unsigned int request_id)
+static int __media_thumb_cancel(unsigned int request_id)
 {
        int len = 0, i;
-       bool flag = false;
-
-       if (g_manage_queue != NULL) {
-               len = g_queue_get_length(g_manage_queue);
 
-               for (i = 0; i < len; i++) {
-                       thumbReq *req = NULL;
-                       req = (thumbReq *)g_queue_peek_nth(g_manage_queue, i);
-                       if (req == NULL) continue;
+       thumb_retv_if(!g_manage_queue, MS_MEDIA_ERR_NONE);
 
-                       if (req->request_id == request_id) {
-                               if (req->isRequested == true) {
-                                       req->isCanceled = true;
-                               } else {
-                                       g_queue_pop_nth(g_manage_queue, i);
+       len = g_queue_get_length(g_manage_queue);
 
-                                       SAFE_FREE(req->path);
-                                       SAFE_FREE(req->userData);
-                                       SAFE_FREE(req);
-                               }
+       for (i = 0; i < len; i++) {
+               thumbReq *req = NULL;
+               req = (thumbReq *)g_queue_peek_nth(g_manage_queue, i);
+               if (req == NULL) continue;
 
-                               flag = true;
+               if (req->request_id == request_id) {
+                       if (req->isRequested) {
+                               req->isCanceled = true;
+                       } else {
+                               g_queue_pop_nth(g_manage_queue, i);
 
-                               break;
+                               SAFE_FREE(req->path);
+                               SAFE_FREE(req->userData);
+                               SAFE_FREE(req);
                        }
+
+                       return MS_MEDIA_ERR_NONE;
                }
        }
 
-       if (flag == false)
-               return MS_MEDIA_ERR_INTERNAL;
-
-       return MS_MEDIA_ERR_NONE;
+       return MS_MEDIA_ERR_INTERNAL;
 }
 
-void __media_thumb_pop_raw_data()
+static void __media_thumb_pop_raw_data(void)
 {
        int len = 0;
        int sock = 0;
+       thumbRawReq *req = NULL;
 
-       if (g_manage_raw_queue != NULL) {
-               thumbRawReq *req = (thumbRawReq *)g_queue_pop_head(g_manage_raw_queue);
-               if (req != NULL) {
-                       GSource *source_id = g_main_context_find_source_by_id(g_main_context_get_thread_default(), req->source_id);
-                       sock = g_io_channel_unix_get_fd(req->channel);
-
-                       g_io_channel_shutdown(req->channel, TRUE, NULL);
-                       g_io_channel_unref(req->channel);
-                       close(sock);
-                       if (source_id != NULL) {
-                               g_source_destroy(source_id);
-                       } else {
-                               thumb_err("G_SOURCE_ID is NULL");
-                       }
+       if (!g_manage_raw_queue)
+               return;
+
+       req = (thumbRawReq *)g_queue_pop_head(g_manage_raw_queue);
+       if (req != NULL) {
+               GSource *source_id = g_main_context_find_source_by_id(g_main_context_get_thread_default(), req->source_id);
+               sock = g_io_channel_unix_get_fd(req->channel);
 
-                       SAFE_FREE(req->path);
-                       SAFE_FREE(req->userData);
-                       SAFE_FREE(req);
+               g_io_channel_shutdown(req->channel, TRUE, NULL);
+               g_io_channel_unref(req->channel);
+               close(sock);
+               if (source_id) {
+                       g_source_destroy(source_id);
+               } else {
+                       thumb_err("G_SOURCE_ID is NULL");
                }
 
-               /* Check manage queue */
-               len = g_queue_get_length(g_manage_raw_queue);
-               if (len > 0)
-                       _media_thumb_raw_data_send_request();
+               SAFE_FREE(req->path);
+               SAFE_FREE(req->userData);
+               SAFE_FREE(req);
        }
+
+       /* Check manage queue */
+       len = g_queue_get_length(g_manage_raw_queue);
+       if (len > 0)
+               __media_thumb_raw_data_send_request();
 }
 
-int __media_thumb_cancel_raw_data(int request_id)
+static int __media_thumb_cancel_raw_data(int request_id)
 {
        int len = 0, i;
-       bool flag = false;
-
-       if (g_manage_raw_queue != NULL) {
-               len = g_queue_get_length(g_manage_raw_queue);
 
-               for (i = 0; i < len; i++) {
-                       thumbRawReq *req = NULL;
-                       req = (thumbRawReq *)g_queue_peek_nth(g_manage_raw_queue, i);
-                       if (req == NULL) continue;
+       thumb_retv_if(!g_manage_raw_queue, MS_MEDIA_ERR_NONE);
 
-                       if (req->request_id == request_id) {
-                               if (req->isRequested == true) {
-                                       req->isCanceled = true;
-                               } else {
-                                       g_queue_pop_nth(g_manage_raw_queue, i);
+       len = g_queue_get_length(g_manage_raw_queue);
 
-                                       SAFE_FREE(req->path);
-                                       SAFE_FREE(req->userData);
-                                       SAFE_FREE(req);
-                               }
+       for (i = 0; i < len; i++) {
+               thumbRawReq *req = NULL;
+               req = (thumbRawReq *)g_queue_peek_nth(g_manage_raw_queue, i);
+               if (req == NULL) continue;
 
-                               flag = true;
+               if (req->request_id == request_id) {
+                       if (req->isRequested) {
+                               req->isCanceled = true;
+                       } else {
+                               g_queue_pop_nth(g_manage_raw_queue, i);
 
-                               break;
+                               SAFE_FREE(req->path);
+                               SAFE_FREE(req->userData);
+                               SAFE_FREE(req);
                        }
+
+                       return MS_MEDIA_ERR_NONE;
                }
        }
 
-       if (flag == false)
-               return MS_MEDIA_ERR_INTERNAL;
-
-       return MS_MEDIA_ERR_NONE;
-
+       return MS_MEDIA_ERR_INTERNAL;
 }
 
-bool __media_thumb_check_cancel(void)
+static bool __media_thumb_check_cancel(void)
 {
        thumbReq *req = NULL;
        req = (thumbReq *)g_queue_peek_head(g_manage_queue);
 
-       if (req == NULL) {
+       if (!req)
                return false;
-       } else {
-               if (req->isCanceled)
-                       return false;
-               else
-                       return true;
-       }
+
+       if (req->isCanceled)
+               return false;
+       else
+               return true;
 }
 
-bool __media_thumb_check_cancel_for_raw(void)
+static bool __media_thumb_check_cancel_for_raw(void)
 {
        thumbRawReq *req = NULL;
        req = (thumbRawReq *)g_queue_peek_head(g_manage_raw_queue);
 
-       if (req == NULL) {
+       if (!req)
                return false;
-       } else {
-               if (req->isCanceled)
-                       return false;
-               else
-                       return true;
-       }
+
+       if (req->isCanceled)
+               return false;
+       else
+               return true;
 }
 
 int _media_thumb_recv_msg(int sock, int header_size, thumbMsg *msg)
@@ -265,7 +254,7 @@ int _media_thumb_recv_msg(int sock, int header_size, thumbMsg *msg)
                if ((recv_len = recv(sock, buf + recv_pos, header_size, 0)) < 0) {
                        thumb_stderror("recv failed");
                        SAFE_FREE(buf);
-                       return _media_thumb_get_error();
+                       return __media_thumb_get_error();
                }
                header_size -= recv_len;
                recv_pos += recv_len;
@@ -296,15 +285,13 @@ int _media_thumb_recv_msg(int sock, int header_size, thumbMsg *msg)
        if (msg->thumb_size > 0) {
                remain_size = msg->thumb_size;
                THUMB_MALLOC(buf, remain_size);
-               if (buf == NULL) {
-                       return MS_MEDIA_ERR_OUT_OF_MEMORY;
-               }
+               thumb_retv_if(!buf, MS_MEDIA_ERR_OUT_OF_MEMORY);
 
                while (remain_size > 0) {
                        if ((recv_len = recv(sock, buf + recv_pos, remain_size, 0)) < 0) {
                                thumb_stderror("recv failed");
                                SAFE_FREE(buf);
-                               return _media_thumb_get_error();
+                               return __media_thumb_get_error();
                        }
 
                        fsync(sock);
@@ -377,7 +364,7 @@ gboolean _media_thumb_write_socket(GIOChannel *src, GIOCondition condition, gpoi
                thumb_err("_media_thumb_recv_msg failed ");
                __media_thumb_pop();
 
-               return FALSE;
+               return G_SOURCE_REMOVE;
        }
 
        if (recv_msg.status != MS_MEDIA_ERR_NONE) {
@@ -397,7 +384,7 @@ gboolean _media_thumb_write_socket(GIOChannel *src, GIOCondition condition, gpoi
 
        thumb_dbg("Done");
 
-       return FALSE;
+       return G_SOURCE_REMOVE;
 }
 
 gboolean _media_thumb_raw_data_write_socket(GIOChannel *src, GIOCondition condition, gpointer data)
@@ -418,7 +405,7 @@ gboolean _media_thumb_raw_data_write_socket(GIOChannel *src, GIOCondition condit
                thumb_err("_media_thumb_recv_msg failed ");
                __media_thumb_pop_raw_data();
 
-               return FALSE;
+               return G_SOURCE_REMOVE;
        }
 
        if (recv_msg.status != MS_MEDIA_ERR_NONE) {
@@ -438,10 +425,10 @@ gboolean _media_thumb_raw_data_write_socket(GIOChannel *src, GIOCondition condit
 
        thumb_dbg("Done");
 
-       return FALSE;
+       return G_SOURCE_REMOVE;
 }
 
-static int _media_thumb_send_request()
+static int __media_thumb_send_request(void)
 {
        int err = MS_MEDIA_ERR_NONE;
        int sock = -1;
@@ -450,10 +437,7 @@ static int _media_thumb_send_request()
        int pid;
 
        err = ms_ipc_create_client_socket(MS_TIMEOUT_SEC_10, &sock);
-       if (err != MS_MEDIA_ERR_NONE) {
-               thumb_err("ms_ipc_create_client_socket failed");
-               return err;
-       }
+       thumb_retvm_if(err != MS_MEDIA_ERR_NONE, err, "ms_ipc_create_client_socket failed");
 
        memset(&serv_addr, 0, sizeof(serv_addr));
        serv_addr.sun_family = AF_UNIX;
@@ -531,7 +515,7 @@ static int _media_thumb_send_request()
        return err;
 }
 
-static int _media_thumb_raw_data_send_request()
+static int __media_thumb_raw_data_send_request(void)
 {
        int err = MS_MEDIA_ERR_NONE;
        int sock = -1;
@@ -540,10 +524,7 @@ static int _media_thumb_raw_data_send_request()
        int pid;
 
        err = ms_ipc_create_client_socket(MS_TIMEOUT_SEC_10, &sock);
-       if (err != MS_MEDIA_ERR_NONE) {
-               thumb_err("ms_ipc_create_client_socket failed");
-               return err;
-       }
+       thumb_retvm_if(err != MS_MEDIA_ERR_NONE, err, "ms_ipc_create_client_socket failed");
 
        memset(&serv_addr, 0, sizeof(serv_addr));
        serv_addr.sun_family = AF_UNIX;
@@ -647,7 +628,7 @@ int _media_thumb_request_async(int msg_type, unsigned int request_id, const char
        g_queue_push_tail(g_manage_queue, (gpointer)thumb_req);
 
        if (len == 0)
-               err = _media_thumb_send_request();
+               err = __media_thumb_send_request();
 
        return err;
 }
@@ -684,7 +665,7 @@ int _media_thumb_request_raw_data_async(int msg_type, int request_id, const char
        g_queue_push_tail(g_manage_raw_queue, (gpointer)thumb_req);
 
        if (len == 0)
-               err = _media_thumb_raw_data_send_request();
+               err = __media_thumb_raw_data_send_request();
 
        return err;
 }
index 9899783fe71fe3bf7829414ae5ee6d2d7dd41851..0514c6c20db73fac66fe6221904f45ebefb002b3 100755 (executable)
@@ -347,10 +347,10 @@ int _media_thumb_video(const char *origin_path, const char *thumb_path, int thum
                err = __get_video_thumb(width, height, frame, size, rot_type, NULL, thumb_width, thumb_height, &dst_img);
                if (err == MS_MEDIA_ERR_NONE) {
                        err = mm_image_get_image(dst_img, &width, &height, &format, &buf, &size);
-                                       thumb_info->data = buf;
-                                       thumb_info->size = size;
-                                       thumb_info->width = width;
-                                       thumb_info->height = height;
+                       thumb_info->data = buf;
+                       thumb_info->size = size;
+                       thumb_info->width = width;
+                       thumb_info->height = height;
                }
 
                mm_image_destroy_image(dst_img);
index be1b09af5edec1c41f0186abb72c85569c1771b0..474325b5ab587e81653b13bdedc777fed5041164 100755 (executable)
 int thumbnail_request_from_db_async(unsigned int request_id, const char *origin_path, ThumbFunc func, void *user_data, uid_t uid)
 {
        int err = MS_MEDIA_ERR_NONE;
+       ms_user_storage_type_e store_type = MS_USER_STORAGE_INTERNAL;
 
-       if (origin_path == NULL) {
-               thumb_err("Invalid parameter");
-               return MS_MEDIA_ERR_INVALID_PARAMETER;
-       }
-
-       if (!g_file_test(origin_path, G_FILE_TEST_IS_REGULAR)) {
-               thumb_err("Original path(%s) doesn't exist.", origin_path);
-               return MS_MEDIA_ERR_INVALID_PARAMETER;
-       }
+       thumb_retvm_if(!origin_path, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid parameter");
+       thumb_retvm_if(!g_file_test(origin_path, G_FILE_TEST_IS_REGULAR), MS_MEDIA_ERR_INVALID_PARAMETER, "No file [%s]", origin_path);
 
-       ms_user_storage_type_e store_type = -1;
        err = ms_user_get_storage_type(uid, origin_path, &store_type);
-
        if ((err != MS_MEDIA_ERR_NONE) || ((store_type != MS_USER_STORAGE_INTERNAL) && (store_type != MS_USER_STORAGE_EXTERNAL))) {
                thumb_err_slog("origin path(%s) is invalid. err : [%d] store_type [%d]", origin_path, err, store_type);
                return MS_MEDIA_ERR_INVALID_PARAMETER;
@@ -52,10 +44,8 @@ int thumbnail_request_from_db_async(unsigned int request_id, const char *origin_
        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;
-       }
+       thumb_retvm_if(!userData, MS_MEDIA_ERR_OUT_OF_MEMORY, "Allocation failed");
+
        userData->func = (ThumbFunc)func;
        userData->user_data = user_data;
 
@@ -75,10 +65,7 @@ int thumbnail_request_extract_raw_data_async(int request_id, const char *origin_
        int err = MS_MEDIA_ERR_NONE;
        int exist = 0;
 
-       if (origin_path == NULL || request_id == 0) {
-               thumb_err("original path is NULL. Or there is an error in request_id.");
-               return MS_MEDIA_ERR_INVALID_PARAMETER;
-       }
+       thumb_retvm_if(!origin_path || request_id == 0, MS_MEDIA_ERR_INVALID_PARAMETER, "original path is NULL. Or there is an error in request_id.");
 
        /* check the file exits actually */
        exist = open(origin_path, O_RDONLY);
@@ -96,10 +83,8 @@ 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;
-       }
+       thumb_retvm_if(!userData, MS_MEDIA_ERR_OUT_OF_MEMORY, "Allocation failed");
+
        userData->func = func;
        userData->user_data = user_data;
 
@@ -118,28 +103,19 @@ int thumbnail_request_cancel_media(unsigned int request_id)
        int err = MS_MEDIA_ERR_NONE;
 
        err = _media_thumb_request_async(THUMB_REQUEST_CANCEL_MEDIA, request_id, NULL, NULL, 0);
-       if (err != MS_MEDIA_ERR_NONE) {
-               thumb_err("_media_thumb_request failed : %d", err);
-               return err;
-       }
+       thumb_retvm_if(err != MS_MEDIA_ERR_NONE, err, "_media_thumb_request_async failed : %d", err);
 
-       return MS_MEDIA_ERR_NONE;
+       return err;
 }
 
 int thumbnail_request_cancel_raw_data(int request_id)
 {
        int err = MS_MEDIA_ERR_NONE;
 
-       if (request_id == 0) {
-               thumb_err("Invalid parameter");
-               return MS_MEDIA_ERR_INVALID_PARAMETER;
-       }
+       thumb_retvm_if(request_id == 0, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid parameter");
 
        err = _media_thumb_request_raw_data_async(THUMB_REQUEST_CANCEL_RAW_DATA, request_id, NULL, 0, 0, NULL, 0);
-       if (err != MS_MEDIA_ERR_NONE) {
-               thumb_err("_media_thumb_request failed : %d", err);
-               return err;
-       }
+       thumb_retvm_if(err != MS_MEDIA_ERR_NONE, err, "_media_thumb_request_raw_data_async failed : %d", err);
 
-       return MS_MEDIA_ERR_NONE;
+       return err;
 }
index 6f2d604ebc2946a02aca1cca03f9efa3130c7c2e..ae76d430b1e821df73c90557d619228c104c99a6 100755 (executable)
@@ -146,10 +146,7 @@ int _media_thumb_update_db(const char *origin_path, char *thumb_path, uid_t uid)
 
 int _media_thumb_get_storage_id_from_db(const char *origin_path, char **storage_id, uid_t uid)
 {
-       int err = MS_MEDIA_ERR_NONE;
        thumb_retvm_if(!STRING_VALID(origin_path), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid origin_path");
 
-       err = __media_thumb_get_storage_id(origin_path, uid, storage_id);
-
-       return err;
+       return __media_thumb_get_storage_id(origin_path, uid, storage_id);
 }
\ No newline at end of file