static int __media_db_request_update_async(ms_msg_type_e msg_type,
const char *storage_id,
- const char *request_msg,
+ const char *path,
scan_complete_cb user_callback,
void *user_data,
uid_t uid)
{
int ret = MS_MEDIA_ERR_NONE;
- int request_msg_size = 0;
int sockfd = -1;
- ms_comm_msg_s send_msg;
- char *request_path = NULL;
+ ms_comm_msg_s send_msg = { 0, };
+ g_autofree gchar *request_path = NULL;
- MSAPI_RETVM_IF(!ms_ipc_is_valid_msg(request_msg), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid request_msg");
+ MSAPI_RETVM_IF(!path || strlen(path) == 0, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid path");
+ MSAPI_RETVM_IF(!storage_id || strlen(storage_id) == 0, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_id");
- MSAPI_DBG_SLOG("REQUEST UPDATE ASYNC [%d][%s]", msg_type, request_msg);
+ request_path = g_canonicalize_filename(path, NULL);
+ MSAPI_DBG_SLOG("trimmed path[%s]", request_path);
- request_msg_size = strlen(request_msg);
- if (request_msg[request_msg_size - 1] == '/') {
- request_path = g_strndup(request_msg, request_msg_size - 1);
- request_msg_size = request_msg_size - 1;
- } else {
- request_path = g_strdup(request_msg);
- }
-
- MSAPI_DBG_SLOG("querysize[%d] path[%s] query[%s]", request_msg_size, request_msg, request_path);
-
- memset((void *)&send_msg, 0, sizeof(ms_comm_msg_s));
send_msg.msg_type = msg_type;
send_msg.pid = syscall(__NR_getpid);
send_msg.uid = uid;
- g_strlcpy(send_msg.msg, request_path, sizeof(send_msg.msg));
- if (MS_STRING_VALID(storage_id))
- g_strlcpy(send_msg.storage_id, storage_id, sizeof(send_msg.storage_id));
+ if (g_strlcpy(send_msg.msg, request_path, sizeof(send_msg.msg)) > MAX_MSG_SIZE) {
+ MSAPI_DBG_ERR("path exceeds MAX_MSG_SIZE");
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
+ }
+ if (g_strlcpy(send_msg.storage_id, storage_id, sizeof(send_msg.storage_id)) > MS_UUID_SIZE) {
+ MSAPI_DBG_ERR("storage_id exceeds MS_UUID_SIZE");
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
+ }
/*Create Socket*/
ret = ms_ipc_create_client_socket(0, &sockfd);
- if (ret != MS_MEDIA_ERR_NONE) {
- MSAPI_DBG_ERR("ms_ipc_create_client_socket failed : %d", ret);
- MS_SAFE_FREE(request_path);
- return ret;
- }
+ MSAPI_RETVM_IF(ret != MS_MEDIA_ERR_NONE, ret, "ms_ipc_create_client_socket failed[%d]", ret);
ret = ms_ipc_send_msg_to_server_tcp(sockfd, MS_SCANNER_PORT, &send_msg, NULL);
if (ret != MS_MEDIA_ERR_NONE) {
MSAPI_DBG_ERR("ms_ipc_send_msg_to_server failed : %d", ret);
- MS_SAFE_FREE(request_path);
close(sockfd);
return ret;
}
__attach_callback(request_path, &sockfd, user_callback, user_data);
- MS_SAFE_FREE(request_path);
return ret;
}
-static int __media_db_request_update_cancel(ms_msg_type_e msg_type, const char *request_msg)
+static int __media_db_request_update_cancel(ms_msg_type_e msg_type, const char *path)
{
int ret = MS_MEDIA_ERR_NONE;
- int request_msg_size = 0;
int sockfd = -1;
- ms_comm_msg_s send_msg;
- char *request_path = NULL;
-
- MSAPI_RETVM_IF(!ms_ipc_is_valid_msg(request_msg), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid request_msg");
+ ms_comm_msg_s send_msg = { 0, };
+ g_autofree gchar *request_path = NULL;
- MSAPI_DBG("REQUEST CANCEL DIRECTORY SCANNING[%s]", request_msg);
+ MSAPI_RETVM_IF(!path || strlen(path) == 0, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid path");
- request_msg_size = strlen(request_msg);
- if (request_msg[request_msg_size - 1] == '/') {
- request_path = g_strndup(request_msg, request_msg_size - 1);
- request_msg_size = request_msg_size - 1;
- } else {
- request_path = g_strdup(request_msg);
- }
+ request_path = g_canonicalize_filename(path, NULL);
+ MSAPI_DBG("REQUEST CANCEL DIRECTORY SCANNING[%s]", request_path);
- memset((void *)&send_msg, 0, sizeof(ms_comm_msg_s));
send_msg.msg_type = msg_type;
send_msg.pid = syscall(__NR_getpid);
- g_strlcpy(send_msg.msg, request_path, sizeof(send_msg.msg));
+ if (g_strlcpy(send_msg.msg, request_path, sizeof(send_msg.msg)) > MAX_MSG_SIZE) {
+ MSAPI_DBG_ERR("path exceeds MAX_MSG_SIZE");
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
+ }
/*Create Socket*/
ret = ms_ipc_create_client_socket(0, &sockfd);
- if (ret != MS_MEDIA_ERR_NONE) {
- MSAPI_DBG_ERR("ms_ipc_create_client_socket failed : %d", ret);
- MS_SAFE_FREE(request_path);
- return ret;
- }
+ MSAPI_RETVM_IF(ret != MS_MEDIA_ERR_NONE, ret, "ms_ipc_create_client_socket failed[%d]", ret);
ret = ms_ipc_send_msg_to_server_tcp(sockfd, MS_SCANNER_PORT, &send_msg, NULL);
close(sockfd);
- if (ret != MS_MEDIA_ERR_NONE) {
- MSAPI_DBG_ERR("ms_ipc_send_msg_to_server failed : %d", ret);
- MS_SAFE_FREE(request_path);
- return ret;
- }
+ MSAPI_RETVM_IF(ret != MS_MEDIA_ERR_NONE, ret, "ms_ipc_send_msg_to_server_tcp failed[%d]", ret);
- ret = __remove_request(request_path);
- MS_SAFE_FREE(request_path);
-
- return ret;
+ return __remove_request(request_path);
}
int media_directory_scanning_async(const char *directory_path,