From b65638b7e078ba9a0e772558be301efa3f465af9 Mon Sep 17 00:00:00 2001 From: "minje.ahn" Date: Wed, 6 Mar 2024 17:31:27 +0900 Subject: [PATCH] media-util.h cleanup Change-Id: Id626fcc5d5d0b0a9b0b6a656763a184ee6661e60 Signed-off-by: minje.ahn --- lib/include/media-util-ipc.h | 2 + lib/include/media-util-noti.h | 13 +-- lib/include/media-util-user.h | 4 +- lib/include/media-util.h | 8 -- lib/media-util-cynara.c | 2 +- lib/media-util-db.c | 170 ++--------------------------- lib/media-util-ipc.c | 185 ++++++++++++++++++++++++++++++-- lib/media-util-noti.c | 10 +- lib/media-util-register.c | 6 +- lib/media-util-user.c | 19 ++-- src/common/include/media-common-utils.h | 6 +- src/common/media-common-db-svc.c | 4 +- src/server/media-server-device-block.c | 8 +- 13 files changed, 225 insertions(+), 212 deletions(-) diff --git a/lib/include/media-util-ipc.h b/lib/include/media-util-ipc.h index 46e92c3..0dbe44c 100644 --- a/lib/include/media-util-ipc.h +++ b/lib/include/media-util-ipc.h @@ -79,6 +79,8 @@ int ms_ipc_create_server_socket(ms_msg_port_type_e port, int *sock_fd); int ms_ipc_send_msg_to_server_tcp(int sockfd, ms_msg_port_type_e port, ms_comm_msg_s *send_msg, struct sockaddr_un *serv_addr); int ms_ipc_send_msg_to_client_tcp(int sockfd, ms_comm_msg_s *send_msg, struct sockaddr_un *client_addr); int ms_ipc_accept_client_tcp(int serv_sock, int* client_sock); +int ms_ipc_request_recovery(uid_t uid); +int ms_ipc_request_update_tcp(ms_msg_type_e msg_type, const char *request_msg, uid_t uid); #ifdef __cplusplus } diff --git a/lib/include/media-util-noti.h b/lib/include/media-util-noti.h index e48f2e2..c1505cd 100644 --- a/lib/include/media-util-noti.h +++ b/lib/include/media-util-noti.h @@ -44,21 +44,12 @@ typedef enum { MS_MEDIA_ITEM_UPDATE = 2, } media_item_update_type_e; -typedef enum { - MS_MEDIA_UNKNOWN = -1, /**< Unknown Conntent*/ - MS_MEDIA_IMAGE = 0, /**< Image Content*/ - MS_MEDIA_VIDEO = 1, /**< Video Content*/ - MS_MEDIA_SOUND = 2, /**< Sound Content like Ringtone*/ - MS_MEDIA_MUSIC = 3, /**< Music Content like mp3*/ - MS_MEDIA_OTHER = 4, /**< Invalid Content*/ -} media_type_e; - typedef void (*db_updated_cb)(int pid, /* mandatory */ media_item_type_e item, /* mandatory */ media_item_update_type_e update_type, /* mandatory */ char *path, /* mandatory */ char *uuid, /* optional */ - media_type_e media_type, /* optional */ + int media_type, /* optional */ char *mime_type, /* optional */ void *user_data); @@ -69,7 +60,7 @@ int media_db_update_send(int pid, /* mandatory */ media_item_update_type_e update_type, /* mandatory */ const char *path, /* mandatory */ const char *uuid, /* optional */ - media_type_e media_type, /* optional */ + int media_type, /* optional */ const char *mime_type /* optional */ ); diff --git a/lib/include/media-util-user.h b/lib/include/media-util-user.h index 6532eb4..f6c1748 100644 --- a/lib/include/media-util-user.h +++ b/lib/include/media-util-user.h @@ -21,6 +21,8 @@ #define _MEDIA_UTIL_USER_H_ #include +#include +#include #ifdef __cplusplus extern "C" { @@ -38,7 +40,7 @@ int ms_user_get_mediashared_path(uid_t uid, char **path); #endif size_t ms_user_get_root_length(const char *path, uid_t uid); -char *ms_user_get_ipc_path(ms_msg_port_type_e type); +int ms_user_make_ipc_path(char *dest, const char *src, size_t dest_len); #ifdef __cplusplus } diff --git a/lib/include/media-util.h b/lib/include/media-util.h index 034ceae..ad4c964 100644 --- a/lib/include/media-util.h +++ b/lib/include/media-util.h @@ -28,12 +28,4 @@ #include #include -#ifdef _USE_TVPD_MODE -#define MEDIA_DB_SIZE_LIMIT_2 20000000 -#define MEDIA_DB_SIZE_LIMIT_1 10000000 -#define MEDIA_DB_SPACE_LIMIT 20971520 -#endif - -#define MS_SAFE_FREE(src) { if (src) {free(src); src = NULL; } } - #endif /*_MEDIA_UTIL_H_*/ diff --git a/lib/media-util-cynara.c b/lib/media-util-cynara.c index 9840b19..3bd5ed0 100644 --- a/lib/media-util-cynara.c +++ b/lib/media-util-cynara.c @@ -99,7 +99,7 @@ int ms_cynara_receive_untrusted_message(int sockfd, ms_comm_msg_s *recv_msg, ms_ return MS_MEDIA_ERR_IPC; } - MSAPI_RETVM_IF(!strlen(recv_msg->msg) == 0 || strlen(recv_msg->msg) >= MAX_MSG_SIZE, MS_MEDIA_ERR_IPC, "Invalid msg"); + MSAPI_RETVM_IF(strlen(recv_msg->msg) == 0 || strlen(recv_msg->msg) >= MAX_MSG_SIZE, MS_MEDIA_ERR_IPC, "Invalid msg"); MSAPI_DBG_SLOG("receive msg from P[%d] T[%d] M[%.*s] S[%.*s]", recv_msg->pid, recv_msg->msg_type, MAX_MSG_SIZE, recv_msg->msg, MS_UUID_SIZE, recv_msg->storage_id); diff --git a/lib/media-util-db.c b/lib/media-util-db.c index 08d618d..6e8bab8 100644 --- a/lib/media-util-db.c +++ b/lib/media-util-db.c @@ -27,11 +27,10 @@ #include #include "media-util-dbg.h" -#include "media-util.h" - -#define MS_TIMEOUT_SEC 10 - -static int __media_db_request_recovery(uid_t uid); +#include "media-util-ipc.h" +#include "media-util-db.h" +#include "media-util-err.h" +#include "media-util-user.h" static int __media_db_busy_handler(void *pData, int count) { @@ -123,7 +122,8 @@ static int __media_db_connect_db_with_handle(sqlite3 **db_handle, uid_t uid, boo char *sql = NULL; MSAPI_DBG_ERR("need_write[%d]", need_write); ret = ms_user_get_media_db_path(uid, &db_path); - MSAPI_RETVM_IF(ret != MS_MEDIA_ERR_NONE, MS_MEDIA_ERR_DB_INTERNAL, "ms_user_get_media_db_path failed"); + MSAPI_RETVM_IF(ret != MS_MEDIA_ERR_NONE, ret, "ms_user_get_media_db_path failed"); + MSAPI_RETVM_IF(!db_path, MS_MEDIA_ERR_DB_INTERNAL, "db_path is NULL"); /*Connect DB*/ if (need_write) @@ -133,11 +133,11 @@ static int __media_db_connect_db_with_handle(sqlite3 **db_handle, uid_t uid, boo if (SQLITE_OK != ret) { MSAPI_DBG_ERR("error when db open path[%s],ret[%d]", db_path, ret); - g_free(db_path); + free(db_path); *db_handle = NULL; return MS_MEDIA_ERR_DB_INTERNAL; } - g_free(db_path); + free(db_path); if (*db_handle == NULL) { MSAPI_DBG_ERR("*db_handle is NULL"); @@ -181,81 +181,6 @@ static int __media_db_connect_db_with_handle(sqlite3 **db_handle, uid_t uid, boo return MS_MEDIA_ERR_NONE; } -#define MAX_RETRY_COUNT 3 - -static int __media_db_request_update_tcp(ms_msg_type_e msg_type, const char *request_msg, uid_t uid) -{ - int ret = MS_MEDIA_ERR_NONE; - int sockfd = -1; - struct sockaddr_un serv_addr = { 0, }; - int retry_count = 0; - g_autofree gchar *ipc_path = NULL; - - MSAPI_RETVM_IF(!request_msg || strlen(request_msg) == 0, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid request_msg"); - - ms_comm_msg_s send_msg = { 0, }; - - send_msg.msg_type = msg_type; - if (g_strlcpy(send_msg.msg, request_msg, sizeof(send_msg.msg)) >= MAX_MSG_SIZE) { - MSAPI_DBG_ERR("request_msg exceeds MAX_MSG_SIZE"); - return MS_MEDIA_ERR_INVALID_PARAMETER; - } - - send_msg.uid = uid; - - /*Create Socket*/ - ret = ms_ipc_create_client_socket(MS_TIMEOUT_SEC, &sockfd); - MSAPI_RETV_IF(ret != MS_MEDIA_ERR_NONE, ret); - - /*Set server Address*/ - serv_addr.sun_family = AF_UNIX; - ipc_path = ms_user_get_ipc_path(MS_DB_UPDATE_PORT); - MSAPI_RETV_IF(!ipc_path, MS_MEDIA_ERR_INTERNAL); - g_strlcpy(serv_addr.sun_path, ipc_path, sizeof(serv_addr.sun_path)); - - /* Connecting to the media db server */ - if (connect(sockfd, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) < 0) { - MSAPI_DBG_STRERROR("connect error"); - close(sockfd); - if (errno == EACCES) - return MS_MEDIA_ERR_PERMISSION_DENIED; - else - return MS_MEDIA_ERR_IPC; - } - - /* Send request */ - if (send(sockfd, &send_msg, sizeof(send_msg), 0) != sizeof(send_msg)) { - MSAPI_DBG_STRERROR("send failed"); - close(sockfd); - return MS_MEDIA_ERR_IPC; - } - - /*Receive Response*/ - int recv_msg_size = -1; - int recv_msg = -1; -RETRY: - if ((recv_msg_size = recv(sockfd, &recv_msg, sizeof(recv_msg), 0)) < 0) { - MSAPI_DBG_STRERROR("recv failed"); - - if (errno == EINTR || errno == EWOULDBLOCK) { - if (retry_count < MAX_RETRY_COUNT) { - MSAPI_DBG_ERR("TIME OUT[%d]", retry_count); - retry_count++; - goto RETRY; - } - } - close(sockfd); - return MS_MEDIA_ERR_IPC; - } - - MSAPI_DBG("RECEIVE OK [%d]", recv_msg); - ret = recv_msg; - - close(sockfd); - - return ret; -} - #define RETRY_CNT 9 #define SLEEP_TIME 1000 * 1000 static int __media_db_update_directly(sqlite3 *db_handle, const char *sql_str) @@ -338,7 +263,7 @@ RETRY_CONN: if (ret == MS_MEDIA_ERR_DB_CORRUPT && retry_cnt == 0) { retry_cnt++; - ret = __media_db_request_recovery(uid); + ret = ms_ipc_request_recovery(uid); if (ret == MS_MEDIA_ERR_NONE) goto RETRY_CONN; else @@ -370,9 +295,9 @@ int media_db_request_update_db(const char *query_str, uid_t uid) MSAPI_RETVM_IF(!query_str || strlen(query_str) == 0, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid Query"); - ret = __media_db_request_update_tcp(MS_MSG_DB_UPDATE, query_str, uid); + ret = ms_ipc_request_update_tcp(MS_MSG_DB_UPDATE, query_str, uid); if (ret != MS_MEDIA_ERR_NONE) - MSAPI_DBG_ERR("__media_db_request_update_tcp failed : %d", ret); + MSAPI_DBG_ERR("ms_ipc_request_update_tcp failed : %d", ret); return ret; } @@ -398,79 +323,6 @@ int media_db_update_db_direct(const char *query_str, uid_t uid) return ret; } -static int __media_db_request_recovery(uid_t uid) -{ - int ret = MS_MEDIA_ERR_NONE; - int sockfd = -1; - struct sockaddr_un serv_addr = { 0, }; - int retry_count = 0; - char *db_path = NULL; - g_autofree gchar *ipc_path = NULL; - - ret = ms_user_get_media_db_path(uid, &db_path); - MSAPI_RETVM_IF(ret != MS_MEDIA_ERR_NONE, MS_MEDIA_ERR_INVALID_PARAMETER, "ms_user_get_media_db_path failed"); - MSAPI_RETVM_IF(!db_path, MS_MEDIA_ERR_INVALID_PARAMETER, "db_path is NULL"); - - ms_comm_msg_s send_msg = { 0, }; - - send_msg.msg_type = MS_MSG_MEDIA_DB_MALFORMED; - if (g_strlcpy(send_msg.msg, db_path, sizeof(send_msg.msg)) >= MAX_MSG_SIZE) { - MSAPI_DBG_ERR("db_path exceeds MAX_MSG_SIZE"); - return MS_MEDIA_ERR_INVALID_PARAMETER; - } - g_free(db_path); - send_msg.uid = uid; - - /*Create Socket*/ - ret = ms_ipc_create_client_socket(MS_TIMEOUT_SEC, &sockfd); - MSAPI_RETV_IF(ret != MS_MEDIA_ERR_NONE, ret); - - /*Set server Address*/ - serv_addr.sun_family = AF_UNIX; - ipc_path = ms_user_get_ipc_path(MS_SCANNER_PORT); - MSAPI_RETV_IF(!ipc_path, MS_MEDIA_ERR_INTERNAL); - g_strlcpy(serv_addr.sun_path, ipc_path, sizeof(serv_addr.sun_path)); - - /* Connecting to the media db server */ - if (connect(sockfd, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) < 0) { - MSAPI_DBG_STRERROR("connect error"); - close(sockfd); - return MS_MEDIA_ERR_IPC; - } - - /* Send request */ - if (send(sockfd, &send_msg, sizeof(send_msg), 0) != sizeof(send_msg)) { - MSAPI_DBG_STRERROR("send failed"); - close(sockfd); - return MS_MEDIA_ERR_IPC; - } - - /*Receive Response*/ - int recv_msg_size = -1; - ms_comm_msg_s recv_msg; -RETRY: - if ((recv_msg_size = recv(sockfd, &recv_msg, sizeof(recv_msg), 0)) < 0) { - MSAPI_DBG_STRERROR("recv failed"); - - if (errno == EINTR || errno == EWOULDBLOCK) { - if (retry_count < MAX_RETRY_COUNT) { - MSAPI_DBG_ERR("TIME OUT[%d]", retry_count); - retry_count++; - goto RETRY; - } - } - close(sockfd); - return MS_MEDIA_ERR_IPC; - } - - MSAPI_DBG("RECEIVE OK [%d]", recv_msg.result); - ret = recv_msg.result; - - close(sockfd); - - return ret; -} - int media_db_get_result(sqlite3 *handle, char *sql_str, sqlite3_stmt **stmt) { int err = -1; diff --git a/lib/media-util-ipc.c b/lib/media-util-ipc.c index a3cc247..b942c3d 100644 --- a/lib/media-util-ipc.c +++ b/lib/media-util-ipc.c @@ -21,9 +21,17 @@ #include #include #include +#include #include "media-util-dbg.h" -#include "media-util.h" +#include "media-util-err.h" +#include "media-util-ipc.h" +#include "media-util-user.h" + +#define MAX_RETRY_COUNT 3 +#define MS_TIMEOUT_SEC 10 +#define MS_DB_SOCK_PATH "media-server/media_ipc_dbupdate.socket" +#define MS_SCAN_SOCK_PATH "media-server/media_ipc_scanner.socket" int ms_ipc_create_client_socket(int timeout_sec, int *sock_fd) { @@ -51,10 +59,11 @@ int ms_ipc_create_client_socket(int timeout_sec, int *sock_fd) int ms_ipc_create_server_socket(ms_msg_port_type_e port, int *sock_fd) { + int ret = MS_MEDIA_ERR_NONE; int i; int sock = -1; struct sockaddr_un serv_addr = { 0, }; - g_autofree gchar *ipc_path = NULL; + /* Create a TCP socket */ if ((sock = socket(PF_FILE, SOCK_STREAM, 0)) < 0) { MSAPI_DBG_STRERROR("socket failed"); @@ -62,10 +71,15 @@ int ms_ipc_create_server_socket(ms_msg_port_type_e port, int *sock_fd) } serv_addr.sun_family = AF_UNIX; - ipc_path = ms_user_get_ipc_path(port); - MSAPI_RETV_IF(!ipc_path, MS_MEDIA_ERR_INTERNAL); - unlink(ipc_path); - g_strlcpy(serv_addr.sun_path, ipc_path, sizeof(serv_addr.sun_path)); + if (port == MS_DB_UPDATE_PORT) + ret = ms_user_make_ipc_path(serv_addr.sun_path, MS_DB_SOCK_PATH, sizeof(serv_addr.sun_path)); + else + ret = ms_user_make_ipc_path(serv_addr.sun_path, MS_SCAN_SOCK_PATH, sizeof(serv_addr.sun_path)); + if (ret != MS_MEDIA_ERR_NONE) { + MSAPI_DBG_ERR("ms_user_make_ipc_path failed[%d]", ret); + goto ERROR; + } + unlink(serv_addr.sun_path); /* Bind to the local address */ for (i = 0; i < 100; i++) { @@ -89,7 +103,7 @@ int ms_ipc_create_server_socket(ms_msg_port_type_e port, int *sock_fd) MSAPI_DBG("Listening..."); /*change permission of sock file*/ - if (chmod(ipc_path, 0776) < 0) + if (chmod(serv_addr.sun_path, 0776) < 0) MSAPI_DBG_STRERROR("chmod failed"); *sock_fd = sock; @@ -103,13 +117,15 @@ ERROR: int ms_ipc_send_msg_to_server_tcp(int sockfd, ms_msg_port_type_e port, ms_comm_msg_s *send_msg, struct sockaddr_un *serv_addr) { + int ret = MS_MEDIA_ERR_NONE; struct sockaddr_un addr = { 0, }; - g_autofree gchar *ipc_path = NULL; addr.sun_family = AF_UNIX; - ipc_path = ms_user_get_ipc_path(port); - MSAPI_RETV_IF(!ipc_path, MS_MEDIA_ERR_INTERNAL); - g_strlcpy(addr.sun_path, ipc_path, sizeof(addr.sun_path)); + if (port == MS_DB_UPDATE_PORT) + ret = ms_user_make_ipc_path(addr.sun_path, MS_DB_SOCK_PATH, sizeof(addr.sun_path)); + else + ret = ms_user_make_ipc_path(addr.sun_path, MS_SCAN_SOCK_PATH, sizeof(addr.sun_path)); + MSAPI_RETV_IF(ret != MS_MEDIA_ERR_NONE, ret); /* Connecting to the media db server */ if (connect(sockfd, (struct sockaddr*)&addr, sizeof(addr)) < 0) { @@ -163,3 +179,150 @@ int ms_ipc_accept_client_tcp(int serv_sock, int* client_sock) return MS_MEDIA_ERR_NONE; } + +int ms_ipc_request_recovery(uid_t uid) +{ + int ret = MS_MEDIA_ERR_NONE; + int sockfd = -1; + struct sockaddr_un serv_addr = { 0, }; + int retry_count = 0; + g_autofree gchar *db_path = NULL; + + ret = ms_user_get_media_db_path(uid, &db_path); + MSAPI_RETVM_IF(ret != MS_MEDIA_ERR_NONE, MS_MEDIA_ERR_INVALID_PARAMETER, "ms_user_get_media_db_path failed"); + MSAPI_RETVM_IF(!db_path, MS_MEDIA_ERR_INVALID_PARAMETER, "db_path is NULL"); + + ms_comm_msg_s send_msg = { 0, }; + + send_msg.msg_type = MS_MSG_MEDIA_DB_MALFORMED; + if (g_strlcpy(send_msg.msg, db_path, sizeof(send_msg.msg)) >= MAX_MSG_SIZE) { + MSAPI_DBG_ERR("db_path exceeds MAX_MSG_SIZE"); + return MS_MEDIA_ERR_INVALID_PARAMETER; + } + send_msg.uid = uid; + + /*Create Socket*/ + ret = ms_ipc_create_client_socket(MS_TIMEOUT_SEC, &sockfd); + MSAPI_RETV_IF(ret != MS_MEDIA_ERR_NONE, ret); + + /*Set server Address*/ + serv_addr.sun_family = AF_UNIX; + ret = ms_user_make_ipc_path(serv_addr.sun_path, MS_DB_SOCK_PATH, sizeof(serv_addr.sun_path)); + if (ret != MS_MEDIA_ERR_NONE) { + close(sockfd); + return ret; + } + + /* Connecting to the media db server */ + if (connect(sockfd, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) < 0) { + MSAPI_DBG_STRERROR("connect error"); + close(sockfd); + return MS_MEDIA_ERR_IPC; + } + + /* Send request */ + if (send(sockfd, &send_msg, sizeof(send_msg), 0) != sizeof(send_msg)) { + MSAPI_DBG_STRERROR("send failed"); + close(sockfd); + return MS_MEDIA_ERR_IPC; + } + + /*Receive Response*/ + int recv_msg_size = -1; + ms_comm_msg_s recv_msg; +RETRY: + if ((recv_msg_size = recv(sockfd, &recv_msg, sizeof(recv_msg), 0)) < 0) { + MSAPI_DBG_STRERROR("recv failed"); + + if (errno == EINTR || errno == EWOULDBLOCK) { + if (retry_count < MAX_RETRY_COUNT) { + MSAPI_DBG_ERR("TIME OUT[%d]", retry_count); + retry_count++; + goto RETRY; + } + } + close(sockfd); + return MS_MEDIA_ERR_IPC; + } + + MSAPI_DBG("RECEIVE OK [%d]", recv_msg.result); + ret = recv_msg.result; + + close(sockfd); + + return ret; +} + +int ms_ipc_request_update_tcp(ms_msg_type_e msg_type, const char *request_msg, uid_t uid) +{ + int ret = MS_MEDIA_ERR_NONE; + int sockfd = -1; + struct sockaddr_un serv_addr = { 0, }; + int retry_count = 0; + + MSAPI_RETVM_IF(!request_msg || strlen(request_msg) == 0, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid request_msg"); + + ms_comm_msg_s send_msg = { 0, }; + + send_msg.msg_type = msg_type; + if (g_strlcpy(send_msg.msg, request_msg, sizeof(send_msg.msg)) >= MAX_MSG_SIZE) { + MSAPI_DBG_ERR("request_msg exceeds MAX_MSG_SIZE"); + return MS_MEDIA_ERR_INVALID_PARAMETER; + } + + send_msg.uid = uid; + + /*Create Socket*/ + ret = ms_ipc_create_client_socket(MS_TIMEOUT_SEC, &sockfd); + MSAPI_RETV_IF(ret != MS_MEDIA_ERR_NONE, ret); + + /*Set server Address*/ + serv_addr.sun_family = AF_UNIX; + ret = ms_user_make_ipc_path(serv_addr.sun_path, MS_DB_SOCK_PATH, sizeof(serv_addr.sun_path)); + if (ret != MS_MEDIA_ERR_NONE) { + close(sockfd); + return ret; + } + + /* Connecting to the media db server */ + if (connect(sockfd, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) < 0) { + MSAPI_DBG_STRERROR("connect error"); + close(sockfd); + if (errno == EACCES) + return MS_MEDIA_ERR_PERMISSION_DENIED; + else + return MS_MEDIA_ERR_IPC; + } + + /* Send request */ + if (send(sockfd, &send_msg, sizeof(send_msg), 0) != sizeof(send_msg)) { + MSAPI_DBG_STRERROR("send failed"); + close(sockfd); + return MS_MEDIA_ERR_IPC; + } + + /*Receive Response*/ + int recv_msg_size = -1; + int recv_msg = -1; +RETRY: + if ((recv_msg_size = recv(sockfd, &recv_msg, sizeof(recv_msg), 0)) < 0) { + MSAPI_DBG_STRERROR("recv failed"); + + if (errno == EINTR || errno == EWOULDBLOCK) { + if (retry_count < MAX_RETRY_COUNT) { + MSAPI_DBG_ERR("TIME OUT[%d]", retry_count); + retry_count++; + goto RETRY; + } + } + close(sockfd); + return MS_MEDIA_ERR_IPC; + } + + MSAPI_DBG("RECEIVE OK [%d]", recv_msg); + ret = recv_msg; + + close(sockfd); + + return ret; +} \ No newline at end of file diff --git a/lib/media-util-noti.c b/lib/media-util-noti.c index 3bcbc82..16b02f4 100644 --- a/lib/media-util-noti.c +++ b/lib/media-util-noti.c @@ -26,11 +26,13 @@ * @brief */ +#include #include #include #include "media-util-dbg.h" -#include "media-util.h" +#include "media-util-noti.h" +#include "media-util-err.h" static GList *handle_list; static GMutex noti_mutex; @@ -51,7 +53,7 @@ int media_db_update_send(int pid, /* mandatory */ media_item_update_type_e update_type, /* mandatory */ const char *path, /* mandatory */ const char *uuid, /* optional */ - media_type_e media_type, /* optional */ + int media_type, /* optional */ const char *mime_type /* optional */ ) { @@ -116,7 +118,7 @@ static void __get_message(GVariant *message, db_updated_cb user_cb, void *userda { gint32 item = -1; gint32 pid = 0; - gint32 update_type = MS_MEDIA_UNKNOWN; + gint32 update_type = 0; gint32 content_type = -1; char *update_path = NULL; char *uuid = NULL; @@ -132,7 +134,7 @@ static void __get_message(GVariant *message, db_updated_cb user_cb, void *userda g_variant_get(message, "(iiis)", &item, &pid, &update_type, &update_path); if (item == MS_MEDIA_ITEM_DIRECTORY) - content_type = MS_MEDIA_UNKNOWN; + content_type = 0; /* getting data complete */ user_cb(pid, item, update_type, update_path, uuid, content_type, mime_type, userdata); diff --git a/lib/media-util-register.c b/lib/media-util-register.c index f3525cd..cf9eb40 100644 --- a/lib/media-util-register.c +++ b/lib/media-util-register.c @@ -19,9 +19,13 @@ #include #include +#include #include "media-util-dbg.h" -#include "media-util.h" +#include "media-util-register.h" +#include "media-util-err.h" +#include "media-util-user.h" +#include "media-util-ipc.h" static GMutex scan_req_mutex; diff --git a/lib/media-util-user.c b/lib/media-util-user.c index 071bdc4..b1c3474 100644 --- a/lib/media-util-user.c +++ b/lib/media-util-user.c @@ -18,7 +18,8 @@ */ #include "media-util-dbg.h" -#include "media-util.h" +#include "media-util-err.h" +#include "media-util-user.h" #include #include @@ -177,16 +178,16 @@ int ms_user_get_mediashared_path(uid_t uid, char **path) } #endif -static char MEDIA_IPC_PATH[][70] = { - {"media-server/media_ipc_scanner.socket"}, - {"media-server/media_ipc_dbupdate.socket"}, -}; -char *ms_user_get_ipc_path(ms_msg_port_type_e type) +int ms_user_make_ipc_path(char *dest, const char *src, size_t dest_len) { - if (type != MS_SCANNER_PORT && type != MS_DB_UPDATE_PORT) - return NULL; + MSAPI_RETVM_IF(!dest, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid dest"); + MSAPI_RETVM_IF(!src, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid src"); + MSAPI_RETVM_IF(dest_len == 0, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid dest_len"); - return g_strdup(tzplatform_mkpath(TZ_SYS_RUN, MEDIA_IPC_PATH[type])); + if (snprintf(dest, dest_len, "%s/%s", tzplatform_getenv(TZ_SYS_RUN), src) < 0) + return MS_MEDIA_ERR_INTERNAL; + + return MS_MEDIA_ERR_NONE; } size_t ms_user_get_root_length(const char *path, uid_t uid) diff --git a/src/common/include/media-common-utils.h b/src/common/include/media-common-utils.h index c8aaacb..ff111be 100644 --- a/src/common/include/media-common-utils.h +++ b/src/common/include/media-common-utils.h @@ -26,8 +26,13 @@ #ifdef _USE_TVPD_MODE #include +#define MEDIA_DB_SIZE_LIMIT_2 20000000 +#define MEDIA_DB_SIZE_LIMIT_1 10000000 +#define MEDIA_DB_SPACE_LIMIT 20971520 #endif +#define MS_SAFE_FREE(src) { if (src) {free(src); src = NULL; } } + bool ms_is_valid_symlink(const char *path); int ms_verify_all_parent_dirs(const char *full_path, uid_t uid); int ms_check_scan_ignore(char *path, uid_t uid); @@ -35,7 +40,6 @@ int ms_set_power_mode(ms_db_status_type_t status); void ms_trim_dir_path(char *dir_path); #ifdef _USE_TVPD_MODE - bool ms_config_get_int(const char *key, int *value); bool ms_config_set_int(const char *key, int value); int ms_set_db_status(ms_db_status_type_t status); diff --git a/src/common/media-common-db-svc.c b/src/common/media-common-db-svc.c index 945656c..dfee86d 100644 --- a/src/common/media-common-db-svc.c +++ b/src/common/media-common-db-svc.c @@ -38,7 +38,7 @@ typedef int (*INSERT_ITEM_END)(uid_t); typedef int (*SEND_DIR_UPDATE_NOTI)(const char *, const char *, int, int); typedef int (*INSERT_ITEM)(sqlite3 *, const char *, const char *, uid_t); -typedef int (*SET_ITEM_VALIDITY)(const char *, const char *, int, int, uid_t); +typedef int (*SET_ITEM_VALIDITY)(const char *, const char *, int, uid_t); typedef int (*GET_STORAGE_ID)(sqlite3 *, const char *, char *, uid_t uid); typedef int (*INSERT_FOLDER)(sqlite3 *, const char *, const char *, uid_t); typedef int (*SET_FOLDER_VALIDITY)(sqlite3 *, const char *, const char *, int, bool, uid_t); @@ -276,7 +276,7 @@ int ms_validate_item(sqlite3 *handle, const char *storage_id, const char *path, #endif } else if (ret == MS_MEDIA_ERR_NONE) { if (!modified) { - ret = ((SET_ITEM_VALIDITY)func_array[eSET_VALIDITY])(storage_id, path, true, true, uid); + ret = ((SET_ITEM_VALIDITY)func_array[eSET_VALIDITY])(storage_id, path, true, uid); MS_DBG_RETVM_IF(ret != MS_MEDIA_ERR_NONE, ret, "SET_ITEM_VALIDITY failed [%d]", ret); } else { ret = ((REFRESH_ITEM)func_array[eREFRESH_ITEM])(handle, storage_id, path, uid); diff --git a/src/server/media-server-device-block.c b/src/server/media-server-device-block.c index 55e0b8d..7598707 100644 --- a/src/server/media-server-device-block.c +++ b/src/server/media-server-device-block.c @@ -93,7 +93,7 @@ int ms_storage_insert_handler(const char *mount_path, const char *mount_uuid) #ifdef _USE_TVPD_MODE media_db_update_send(getpid(), MS_MEDIA_ITEM_STORAGE, MS_MEDIA_ITEM_INSERT, - mount_path, mount_uuid, MS_MEDIA_UNKNOWN, PROD_CUSTOM_MIME_ADDED); + mount_path, mount_uuid, 0, PROD_CUSTOM_MIME_ADDED); #endif } @@ -164,12 +164,12 @@ static void __ms_usb_add_event(const char *mount_path) if (ms_set_storage_scan_status(handle, storage_id, MEDIA_SCAN_PREPARE, uid) != MS_MEDIA_ERR_NONE) MS_DBG_ERR("ms_set_storage_scan_status failed"); - media_db_update_send(getpid(), MS_MEDIA_ITEM_STORAGE, MS_MEDIA_ITEM_UPDATE, mount_path, storage_id, MS_MEDIA_UNKNOWN, PROD_CUSTOM_MIME_ADDED); + media_db_update_send(getpid(), MS_MEDIA_ITEM_STORAGE, MS_MEDIA_ITEM_UPDATE, mount_path, storage_id, 0, PROD_CUSTOM_MIME_ADDED); } else { /* there is no information of this storage in Media DB */ ret = ms_insert_storage(handle, storage_id, mount_path, uid); - media_db_update_send(getpid(), MS_MEDIA_ITEM_STORAGE, MS_MEDIA_ITEM_INSERT, mount_path, storage_id, MS_MEDIA_UNKNOWN, PROD_CUSTOM_MIME_ADDED); + media_db_update_send(getpid(), MS_MEDIA_ITEM_STORAGE, MS_MEDIA_ITEM_INSERT, mount_path, storage_id, 0, PROD_CUSTOM_MIME_ADDED); } } else { MS_DBG_ERR("STORAGE ID IS NUILL"); @@ -232,7 +232,7 @@ static void __ms_usb_remove_event(const char *mount_path) ms_send_storage_otg_scan_request(mount_path, device_id, MS_SCAN_INVALID, uid); } - media_db_update_send(getpid(), MS_MEDIA_ITEM_STORAGE, MS_MEDIA_ITEM_UPDATE, mount_path, device_id, MS_MEDIA_UNKNOWN, PROD_CUSTOM_MIME_REMOVED); + media_db_update_send(getpid(), MS_MEDIA_ITEM_STORAGE, MS_MEDIA_ITEM_UPDATE, mount_path, device_id, 0, PROD_CUSTOM_MIME_REMOVED); } ms_disconnect_db(handle); -- 2.7.4