From e10f2207aeea99bcde0258359d4d336d4ae9d253 Mon Sep 17 00:00:00 2001 From: Jiyong Min Date: Thu, 6 Apr 2017 19:45:54 +0900 Subject: [PATCH] Check Error type and remove Unused code 1. Check Proper Error Type when create thumbnail and return it to App. 2. Remove unused THUMB_REQUEST_SAVE_FILE related code Change-Id: Idf40c8f3a515319bcccce81dcd49d7cda8d56165 Signed-off-by: Jiyong Min --- packaging/libmedia-thumbnail.spec | 2 +- server/thumb-server-internal.c | 72 +++++++++++---------------------------- src/include/ipc/media-thumb-ipc.h | 19 ----------- src/ipc/media-thumb-ipc.c | 27 +++++---------- src/media-thumb-internal.c | 2 +- 5 files changed, 31 insertions(+), 91 deletions(-) diff --git a/packaging/libmedia-thumbnail.spec b/packaging/libmedia-thumbnail.spec index 5ab4763..6c79e24 100644 --- a/packaging/libmedia-thumbnail.spec +++ b/packaging/libmedia-thumbnail.spec @@ -1,6 +1,6 @@ Name: libmedia-thumbnail Summary: Media thumbnail service library for multimedia applications -Version: 0.1.104 +Version: 0.1.105 Release: 0 Group: Multimedia/Libraries License: Apache-2.0 and public domain diff --git a/server/thumb-server-internal.c b/server/thumb-server-internal.c index 2e6bc8c..8e0cff7 100755 --- a/server/thumb-server-internal.c +++ b/server/thumb-server-internal.c @@ -167,22 +167,8 @@ int _thumb_daemon_process_job(thumbMsg *req_msg, thumbMsg *res_msg) int err = MS_MEDIA_ERR_NONE; err = _media_thumb_process(req_msg, res_msg); - if (err != MS_MEDIA_ERR_NONE) { - if (req_msg->msg_type == THUMB_REQUEST_SAVE_FILE) { - thumb_err("_media_thumb_process is failed: %d", err); - res_msg->status = THUMB_FAIL; - } else { - 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; - } + if (err != MS_MEDIA_ERR_NONE) + thumb_warn("_media_thumb_process is failed: %d", err); return err; } @@ -192,12 +178,8 @@ static int __thumb_daemon_process_job_raw(thumbMsg *req_msg, thumbMsg *res_msg) int err = MS_MEDIA_ERR_NONE; err = _media_thumb_process_raw(req_msg, res_msg); - if (err != MS_MEDIA_ERR_NONE) { - thumb_warn("_media_thumb_process is failed: %d", err); - res_msg->status = THUMB_FAIL; - } else { - res_msg->status = THUMB_SUCCESS; - } + if (err != MS_MEDIA_ERR_NONE) + thumb_warn("_media_thumb_process_raw is failed: %d", err); return err; } @@ -288,30 +270,8 @@ int _thumb_daemon_process_queue_jobs(gpointer data) recv_msg.org_path[sizeof(recv_msg.org_path) - 1] = '\0'; err = _thumb_daemon_process_job(&recv_msg, &res_msg); - if (err == MS_MEDIA_ERR_FILE_NOT_EXIST) { + if (err != MS_MEDIA_ERR_NONE) thumb_err("Thumbnail processing is failed : %d", err); - } else { - if (res_msg.status == THUMB_SUCCESS) { - - err = _media_thumb_db_connect(uid); - if (err != MS_MEDIA_ERR_NONE) { - thumb_err("_media_thumb_mb_svc_connect failed: %d", err); - return TRUE; - } - - /* Need to update DB once generating thumb is done */ - err = _media_thumb_update_db(recv_msg.org_path, - res_msg.dst_path, - res_msg.origin_width, - res_msg.origin_height, - uid); - if (err != MS_MEDIA_ERR_NONE) { - thumb_err("_media_thumb_update_db failed : %d", err); - } - - _media_thumb_db_disconnect(); - } - } SAFE_FREE(path); } else { @@ -488,7 +448,7 @@ static gboolean _thumb_server_send_deny_message(int sockfd) int bytes_to_send = sizeof(msg) - sizeof(msg.org_path) - sizeof(msg.dst_path); msg.msg_type = THUMB_RESPONSE; - msg.status = THUMB_FAIL; + msg.status = MS_MEDIA_ERR_PERMISSION_DENIED; if (send(sockfd, &msg, bytes_to_send, 0) != bytes_to_send) { thumb_stderror("send failed"); @@ -587,7 +547,7 @@ int _thumbnail_get_data(const char *origin_path, } } else { thumb_err("invalid file type"); - return MS_MEDIA_ERR_INVALID_PARAMETER; + return MS_MEDIA_ERR_THUMB_UNSUPPORTED; } if (size) *size = thumb_info.size; @@ -692,15 +652,18 @@ int _media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg) thumb_path = res_msg->dst_path; thumb_path[0] = '\0'; max_length = sizeof(res_msg->dst_path) -1; + res_msg->status = MS_MEDIA_ERR_NONE; if (!g_file_test(origin_path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) { thumb_err("origin_path does not exist in file system."); + res_msg->status = MS_MEDIA_ERR_FILE_NOT_EXIST; return MS_MEDIA_ERR_FILE_NOT_EXIST; } err = _media_thumb_db_connect(req_msg->uid); if (err != MS_MEDIA_ERR_NONE) { thumb_err("_media_thumb_mb_svc_connect failed: %d", err); + res_msg->status = MS_MEDIA_ERR_DB_CONNECT_FAIL; return err; } @@ -718,6 +681,7 @@ int _media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg) thumb_err("_media_thumb_get_hash_name failed - %d", err); strncpy(thumb_path, THUMB_EMPTY_STR, max_length); _media_thumb_db_disconnect(); + res_msg->status = err; return err; } @@ -725,15 +689,13 @@ int _media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg) } } - } else if (msg_type == THUMB_REQUEST_SAVE_FILE) { - strncpy(thumb_path, req_msg->dst_path, max_length); - } else if (msg_type == THUMB_REQUEST_ALL_MEDIA) { err = _media_thumb_get_hash_name(origin_path, thumb_path, max_length, req_msg->uid); if (err != MS_MEDIA_ERR_NONE) { thumb_err("_media_thumb_get_hash_name failed - %d", err); strncpy(thumb_path, THUMB_EMPTY_STR, max_length); _media_thumb_db_disconnect(); + res_msg->status = err; return err; } @@ -752,6 +714,7 @@ int _media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg) thumb_err("_thumbnail_get_data failed - %d", err); SAFE_FREE(data); strncpy(thumb_path, THUMB_EMPTY_STR, max_length); + res_msg->status = err; goto DB_UPDATE; } @@ -786,6 +749,7 @@ int _media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg) strncpy(thumb_path, THUMB_EMPTY_STR, max_length); } _media_thumb_db_disconnect(); + res_msg->status = err; return err; } else { thumb_dbg("file save success"); @@ -803,6 +767,7 @@ int _media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg) err = fsync(fd); if (err == -1) { thumb_warn("fsync failed"); + res_msg->status = MS_MEDIA_ERR_INTERNAL; } close(fd); @@ -816,12 +781,13 @@ DB_UPDATE: err = _media_thumb_update_db(origin_path, thumb_path, res_msg->origin_width, res_msg->origin_height, req_msg->uid); if (err != MS_MEDIA_ERR_NONE) { thumb_err("_media_thumb_update_db failed : %d", err); + res_msg->status = err; } } _media_thumb_db_disconnect(); - return MS_MEDIA_ERR_NONE; + return err; } int @@ -843,11 +809,13 @@ _media_thumb_process_raw(thumbMsg *req_msg, thumbMsg *res_msg) media_thumb_format thumb_format = MEDIA_THUMB_BGRA; thumb_w = req_msg->thumb_width; thumb_h = req_msg->thumb_height; + res_msg->status = MS_MEDIA_ERR_NONE; err = _thumbnail_get_raw_data(origin_path, thumb_format, &thumb_w, &thumb_h, &data, &thumb_size); if (err != MS_MEDIA_ERR_NONE) { thumb_err("_thumbnail_get_data failed - %d", err); + res_msg->status = err; SAFE_FREE(data); } @@ -860,5 +828,5 @@ _media_thumb_process_raw(thumbMsg *req_msg, thumbMsg *res_msg) SAFE_FREE(data); - return MS_MEDIA_ERR_NONE; + return err; } diff --git a/src/include/ipc/media-thumb-ipc.h b/src/include/ipc/media-thumb-ipc.h index 1b5b17f..a7cce71 100755 --- a/src/include/ipc/media-thumb-ipc.h +++ b/src/include/ipc/media-thumb-ipc.h @@ -40,25 +40,6 @@ #define MAX_PATH_SIZE 4096 #define MAX_TRIES 3 -enum { - THUMB_REQUEST_DB_INSERT, - THUMB_REQUEST_SAVE_FILE, - THUMB_REQUEST_ALL_MEDIA, - THUMB_REQUEST_CANCEL_MEDIA, - THUMB_REQUEST_CANCEL_ALL, - THUMB_REQUEST_KILL_SERVER, - THUMB_RESPONSE, - THUMB_REQUEST_RAW_DATA, - THUMB_REQUEST_CANCEL_RAW_DATA, - THUMB_REQUEST_CANCEL_ALL_RAW_DATA, - THUMB_RESPONSE_RAW_DATA, -}; - -enum { - THUMB_SUCCESS, - THUMB_FAIL -}; - int _media_thumb_recv_msg(int sock, int header_size, thumbMsg *msg); int _media_thumb_recv_udp_msg(int sock, int header_size, thumbMsg *msg, struct sockaddr_un *from_addr, unsigned int *from_size); diff --git a/src/ipc/media-thumb-ipc.c b/src/ipc/media-thumb-ipc.c index 6aee3a3..693a3fa 100755 --- a/src/ipc/media-thumb-ipc.c +++ b/src/ipc/media-thumb-ipc.c @@ -585,11 +585,6 @@ _media_thumb_request(int msg_type, const char *origin_path, char *thumb_path, in strncpy(req_msg.org_path, origin_path, sizeof(req_msg.org_path)); req_msg.org_path[strlen(req_msg.org_path)] = '\0'; - if (msg_type == THUMB_REQUEST_SAVE_FILE) { - strncpy(req_msg.dst_path, thumb_path, sizeof(req_msg.dst_path)); - req_msg.dst_path[strlen(req_msg.dst_path)] = '\0'; - } - req_msg.origin_path_size = strlen(req_msg.org_path) + 1; req_msg.dest_path_size = strlen(req_msg.dst_path) + 1; req_msg.thumb_size = 0; @@ -635,15 +630,13 @@ _media_thumb_request(int msg_type, const char *origin_path, char *thumb_path, in return MS_MEDIA_ERR_INVALID_PARAMETER; } - if (recv_msg.status == THUMB_FAIL) { + if (recv_msg.status != MS_MEDIA_ERR_NONE) { thumb_err("Failed to make thumbnail"); SAFE_FREE(recv_msg.thumb_data); - return MS_MEDIA_ERR_INVALID_PARAMETER; + return recv_msg.status; } - if (msg_type != THUMB_REQUEST_SAVE_FILE) { - strncpy(thumb_path, recv_msg.dst_path, max_length); - } + strncpy(thumb_path, recv_msg.dst_path, max_length); thumb_info->origin_width = recv_msg.origin_width; thumb_info->origin_height = recv_msg.origin_height; @@ -678,11 +671,9 @@ gboolean _media_thumb_write_socket(GIOChannel *src, GIOCondition condition, gpoi return FALSE; } - //thumb_dbg("Completed..%s", recv_msg.org_path); - - if (recv_msg.status == THUMB_FAIL) { - thumb_err("Failed to make thumbnail"); - err = MS_MEDIA_ERR_INTERNAL; + if (recv_msg.status != MS_MEDIA_ERR_NONE) { + err = recv_msg.status; + thumb_err("Failed to make thumbnail (%d)", err); } if (__media_thumb_check_cancel()) { @@ -729,9 +720,9 @@ gboolean _media_thumb_raw_data_write_socket(GIOChannel *src, GIOCondition condit g_io_channel_shutdown(src, TRUE, NULL); g_io_channel_unref(src); - if (recv_msg.status == THUMB_FAIL) { - thumb_err("Failed to make thumbnail"); - err = MS_MEDIA_ERR_INTERNAL; + if (recv_msg.status != MS_MEDIA_ERR_NONE) { + err = recv_msg.status; + thumb_err("Failed to make thumbnail (%d)", err); } if (__media_thumb_check_cancel_for_raw()) { diff --git a/src/media-thumb-internal.c b/src/media-thumb-internal.c index adc96e4..28914f0 100755 --- a/src/media-thumb-internal.c +++ b/src/media-thumb-internal.c @@ -1310,7 +1310,7 @@ int _media_thumb_image(const char *origin_path, } thumb_warn("Unsupported image type"); - return MS_MEDIA_ERR_INVALID_PARAMETER; + return MS_MEDIA_ERR_THUMB_UNSUPPORTED; } return err; -- 2.7.4