media-scanner \
mediadb-update
-media_server_SOURCES = src/common/media-common-drm.c \
- src/common/media-common-utils.c \
+media_server_SOURCES = src/common/media-common-utils.c \
src/common/media-common-external-storage.c \
src/server/media-server-db-svc.c \
src/server/media-server-db.c \
$(GLIB_CFLAGS) \
$(PHONESTATUS_CFLAGS) \
$(DLOG_CFLAGS) \
- $(DRM_SERVICE_CFLAGS) \
$(AUL_CFLAG)\
$(LIBPMCONTROL_CFLAGS) \
$(HEYNOTI_CFLAGS) \
$(DBUS_CFLAGS) \
- $(STATUS_CFLAGS)
+ $(STATUS_CFLAGS) \
+ $(SECURITY_CFLAGS)
media_server_LDADD = libmedia-utils.la \
$(GLIB_LIBS) \
$(GTHREAD_LIBS) \
$(PHONESTATUS_LIBS) \
$(DLOG_LIBS) \
- $(DRM_SERVICE_LIBS) \
$(AUL_LIBS) \
$(LIBPMCONTROL_LIBS) \
$(HEYNOTI_LIBS) \
$(DBUS_LIBS) \
-ldl \
- $(STATUS_LIBS)
+ $(STATUS_LIBS) \
+ $(SECURITY_LIBS)
+
media_scanner_SOURCES = src/common/media-common-utils.c \
src/common/media-common-external-storage.c \
- src/common/media-common-drm.c \
src/scanner/media-scanner-db-svc.c \
src/scanner/media-scanner-scan.c \
src/scanner/media-scanner-socket.c \
$(GLIB_CFLAGS) \
$(PHONESTATUS_CFLAGS) \
$(DLOG_CFLAGS) \
- $(DRM_SERVICE_CFLAGS) \
- $(AUL_CFLAG)\
+ $(AUL_CFLAG)\
$(LIBPMCONTROL_CFLAGS) \
$(HEYNOTI_CFLAGS) \
$(DBUS_CFLAGS) \
$(GTHREAD_LIBS) \
$(PHONESTATUS_LIBS) \
$(DLOG_LIBS) \
- $(DRM_SERVICE_LIBS) \
$(AUL_LIBS) \
$(LIBPMCONTROL_LIBS) \
$(THUMB_GEN_LIBS) \
### includeheaders ###
includeheadersdir = $(includedir)/media-utils
-includeheaders_HEADERS = lib/include/media-util-noti.h \
+includeheaders_HEADERS = lib/include/media-util-noti-common.h \
+ lib/include/media-util-noti.h \
lib/include/media-util-register.h \
lib/include/media-util-err.h \
lib/include/media-util-db.h \
CPPFLAGS="${CPPFLAGS} -DRND_LINUX"
#using UDS socket
-#CPPFLAGS="${CPPFLAGS} -D_USE_UDS_SOCKET_"
-CPPFLAGS="${CPPFLAGS} -D_USE_UDS_SOCKET_TCP_"
+CPPFLAGS="${CPPFLAGS} -D_USE_UDS_SOCKET_"
# FMS_DEBUG - File Manager Service debug options
# To open debug options:
AC_SUBST(DLOG_CFLAGS)
AC_SUBST(DLOG_LIBS)
-PKG_CHECK_MODULES(DRM_SERVICE, drm-client)
-AC_SUBST(DRM_SERVICE_CFLAGS)
-AC_SUBST(DRM_SERVICE_LIBS)
-
PKG_CHECK_MODULES(PHONESTATUS, vconf)
AC_SUBST(PHONESTATUS_CFLAGS)
AC_SUBST(PHONESTATUS_LIBS)
AC_SUBST(STATUS_CFLAGS)
AC_SUBST(STATUS_LIBS)
+#sercurity server
+PKG_CHECK_MODULES(SECURITY, security-server)
+AC_SUBST(SECURITY_CFLAGS)
+AC_SUBST(SECURITY_LIBS)
+
#Checks for header files.
AC_HEADER_DIRENT
AC_HEADER_STDC
typedef enum{
MS_DB_BATCH_UPDATE_PORT = 0, /**< Media DB batch update */
MS_SCAN_DAEMON_PORT, /**< Port of communication between scanner and server */
- MS_SCAN_COMM_PORT, /**< Port of communication between scanner and server */
MS_SCANNER_PORT, /**< Directory Scanner */
MS_DB_UPDATE_PORT, /**< Media DB Update */
MS_THUMB_CREATOR_PORT, /**< Create thumbnail */
#define MS_THUMB_COMM_PORT 1005 /**< Port of communication between creator and server */
#define MS_DB_BATCH_UPDATE_PORT 1006 /**< Media DB batch update */
#define MS_SCAN_DAEMON_PORT 1007 /**< Port of communication between scanner and server */
-#define MS_SCAN_COMM_PORT 1008 /**< Port of communication between scanner and server */
-#endif
-
-#ifdef _USE_UDS_SOCKET_TCP_
-typedef enum{
- MS_DB_BATCH_UPDATE_TCP_PORT = 0, /**< Media DB batch update */
- MS_THUMB_CREATOR_TCP_PORT, /**< Create thumbnail */
- MS_PORT_MAX,
-}ms_msg_port_type_e;
#endif
#define MAX_MSG_SIZE 4096
MS_MSG_MAX /**< Invalid msg type */
}ms_msg_type_e;
+#define MS_SCANNER_FIFO_PATH_REQ "/tmp/media-scanner-fifo-req"
+#define MS_SCANNER_FIFO_PATH_RES "/tmp/media-scanner-fifo-res"
+#define MS_SCANNER_FIFO_MODE 0666
+
+#ifdef _USE_UDS_SOCKET_
+typedef struct
+{
+ int sock_fd;
+ char *sock_path;
+}ms_sock_info_s;
+#endif
+
typedef struct
{
ms_msg_type_e msg_type;
int media_db_request_directory_scan(const char *directory_path);
+int media_db_request_update_db_batch_clear(void);
+
/**
* @}
*/
#define FONT_COLOR_CYAN "\033[36m"
#define FONT_COLOR_GRAY "\033[37m"
+#define MSAPI_DBG_SLOG(fmt, args...) SECURE_LOGD(fmt "\n", ##args);
+
#define MSAPI_DBG(fmt, arg...) do { \
LOGD(FONT_COLOR_RESET fmt, ##arg); \
} while (0)
#define MS_MEDIA_ERR_ALLOCATE_MEMORY_FAIL -5 /**< exception of memory allocation */
#define MS_MEDIA_ERR_DIR_OPEN_FAIL -6 /**< exception of dir open*/
#define MS_MEDIA_ERR_FILE_OPEN_FAIL -7 /**< exception of file doesn't exist*/
+#define MS_MEDIA_ERR_FILE_READ_FAIL -8 /**< file reading fails */
+#define MS_MEDIA_ERR_FILE_WRITE_FAIL -9 /**< file writing fails */
+#define MS_MEDIA_ERR_MAKE_FIFO_FAIL -10 /**< FIFO making fails */
/*DB operation error*/
#define MS_MEDIA_ERR_DB_CONNECT_FAIL -11 /**< connecting database fails */
#define MS_MEDIA_ERR_DB_UPDATE_FAIL -15 /**< updating record fails */
#define MS_MEDIA_ERR_DB_EXIST_ITEM_FAIL -16 /**< item does not exist */
#define MS_MEDIA_ERR_DB_BUSY_FAIL -17 /**< DB Busy */
+#define MS_MEDIA_ERR_DB_CONSTRAINT_FAIL -18 /**< DB CONSTRAINT fails - In case of insert, the record already exists */
/*DRM operation error*/
#define MS_MEDIA_ERR_DRM_REGISTER_FAIL -21 /**< interting into drm db fails */
#define MS_MEDIA_ERR_MIME_GET_FAIL -53 /**< not media file*/
#define MS_MEDIA_ERR_SCANNER_NOT_READY -54 /**< not media file*/
#define MS_MEDIA_ERR_DYNAMIC_LINK -55
+#define MS_MEDIA_ERR_PERMISSION_DENIED -56
+#define MS_MEDIA_ERR_INVALID_IPC_MESSAGE -57
#define MS_MEDIA_ERR_MAX -999 /**< not media file*/
#define MS_STRING_VALID(str) \
((str != NULL && strlen(str) > 0) ? TRUE : FALSE)
-#define MS_MEDIA_DBUS_PATH "/com/mediaserver/dbus/notify"
-#define MS_MEDIA_DBUS_INTERFACE "com.mediaserver.dbus.Signal"
-#define MS_MEDIA_DBUS_NAME "ms_db_updated"
-#define MS_MEDIA_DBUS_MATCH_RULE "type='signal',interface='com.mediaserver.dbus.Signal'"
-
int media_db_update_db(MediaDBHandle *handle, const char *query_str);
int media_db_update_db_batch_start(const char *query_str);
#else
#include <sys/socket.h>
#endif
-
-#ifdef _USE_UDS_SOCKET_TCP_
-#include <sys/un.h>
-#endif
-
#include <netinet/in.h>
#include <arpa/inet.h>
MS_PROTOCOL_TCP
} ms_protocol_e;
-#ifdef _USE_UDS_SOCKET_
-int ms_ipc_create_client_socket(ms_protocol_e protocol, int timeout_sec, int *sock_fd, int port);
-#else
-int ms_ipc_create_client_socket(ms_protocol_e protocol, int timeout_sec, int *sock_fd);
-#endif
-
-#ifdef _USE_UDS_SOCKET_TCP_
-int ms_ipc_create_client_tcp_socket(ms_protocol_e protocol, int timeout_sec, int *sock_fd, int port);
-int ms_ipc_create_server_tcp_socket(ms_protocol_e protocol, int port, int *sock_fd);
-#endif
-int ms_ipc_create_server_socket(ms_protocol_e protocol, int port, int *sock_fd);
#ifdef _USE_UDS_SOCKET_
-int ms_ipc_send_msg_to_server(int sockfd, int port, ms_comm_msg_s *send_msg, struct sockaddr_un *serv_addr);
+int ms_ipc_create_client_socket(ms_protocol_e protocol, int timeout_sec, ms_sock_info_s* sock_info);
+int ms_ipc_create_server_socket(ms_protocol_e protocol, ms_msg_port_type_e port, int *sock_fd);
+int ms_ipc_send_msg_to_server(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_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(int sockfd, ms_comm_msg_s *send_msg, struct sockaddr_un *client_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_receive_message(int sockfd, void *recv_msg, unsigned int msg_size, struct sockaddr_un *client_addr, unsigned int *size);
int ms_ipc_wait_message(int sockfd, void *recv_msg, unsigned int msg_size, struct sockaddr_un *recv_addr, unsigned int *size);
+int ms_ipc_delete_client_socket(ms_sock_info_s* sock_info);
#else
+int ms_ipc_create_client_socket(ms_protocol_e protocol, int timeout_sec, int *sock_fd);
+int ms_ipc_create_server_socket(ms_protocol_e protocol, int port, int *sock_fd);
int ms_ipc_send_msg_to_server(int sockfd, int port, ms_comm_msg_s *send_msg, struct sockaddr_in *serv_addr);
+int ms_ipc_send_msg_to_server_tcp(int sockfd, int port, ms_comm_msg_s *send_msg, struct sockaddr_in *serv_addr);
int ms_ipc_send_msg_to_client(int sockfd, ms_comm_msg_s *send_msg, struct sockaddr_in *client_addr);
+int ms_ipc_send_msg_to_client_tcp(int sockfd, ms_comm_msg_s *send_msg, struct sockaddr_in *client_addr);
int ms_ipc_receive_message(int sockfd, void *recv_msg, unsigned int msg_size, struct sockaddr_in *client_addr, unsigned int *size);
int ms_ipc_wait_message(int sockfd, void *recv_msg, unsigned int msg_size, struct sockaddr_in *recv_addr, unsigned int *size);
#endif
--- /dev/null
+/*
+ * Media Utility
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Yong Yeon Kim <yy9875.kim@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+/**
+ * This file defines api utilities of contents manager engines.
+ *
+ * @file media-util-not-commoni.h
+ * @author Yong Yeon Kim(yy9875.kim@samsung.com)
+ * @version 1.0
+ * @brief
+ */
+ #ifndef _MEDIA_UTIL_NOTI_COMMON_H_
+#define _MEDIA_UTIL_NOTI_COMMON_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef enum {
+ MS_MEDIA_ITEM_FILE = 0,
+ MS_MEDIA_ITEM_DIRECTORY = 1,
+}media_item_type_e;
+
+typedef enum {
+ MS_MEDIA_ITEM_INSERT = 0,
+ MS_MEDIA_ITEM_DELETE = 1,
+ 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_update_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 */
+ char *mime_type, /* optional */
+ void *user_data);
+
+typedef void *MediaNotiHandle; /**< Handle */
+
+#define MS_MEDIA_DBUS_PATH "/com/mediaserver/dbus/notify"
+#define MS_MEDIA_DBUS_INTERFACE "com.mediaserver.dbus.Signal"
+#define MS_MEDIA_DBUS_MATCH_RULE "type='signal',interface='com.mediaserver.dbus.Signal'"
+
+/**
+* @}
+*/
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /*_MEDIA_UTIL_NOTI_COMMON_H_*/
extern "C" {
#endif
+#include "media-util-noti-common.h"
+
/**
* @fn int media_db_update_subscribe(void);
* @brief This function announce media database is updated to other applications.<br>
*/
-typedef enum {
- MS_MEDIA_ITEM_FILE = 0,
- MS_MEDIA_ITEM_DIRECTORY = 1,
-}media_item_type_e;
-
-typedef enum {
- MS_MEDIA_ITEM_INSERT = 0,
- MS_MEDIA_ITEM_DELETE = 1,
- 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_update_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 */
- char *mime_type, /* optional */
- void *user_data);
-
int media_db_update_subscribe(db_update_cb user_cb, void *user_data);
int media_db_update_unsubscribe(void);
#define MEDIA_ROOT_PATH_INTERNAL MOUNT_PATH"/media"
#define MEDIA_ROOT_PATH_SDCARD "/opt/storage/sdcard"
#define MEDIA_DATA_PATH MOUNT_PATH"/data/file-manager-service"
-#define MEDIA_THUMB_ROOT_PATH MOUNT_PATH"/media"
+#define MEDIA_THUMB_ROOT_PATH MOUNT_PATH"/media"
#define MEDIA_DB_NAME MOUNT_PATH"/dbspace/.media.db" /**< media db name*/
#endif /*_MEDIA_UTIL_H_*/
static int __media_db_disconnect_db_with_handle(sqlite3 *db_handle);
static int __media_db_request_update(ms_msg_type_e msg_type, const char *request_msg);
-void __media_db_destroy_sql_list()
+static void __media_db_destroy_sql_list()
{
int i = 0;
int sockfd = -1;
int err = -1;
#ifdef _USE_UDS_SOCKET_
+ ms_sock_info_s sock_info;
struct sockaddr_un serv_addr;
#else
struct sockaddr_in serv_addr;
/*Create Socket*/
#ifdef _USE_UDS_SOCKET_
- ret = ms_ipc_create_client_socket(MS_PROTOCOL_UDP, MS_TIMEOUT_SEC_10, &sockfd, port);
+ ret = ms_ipc_create_client_socket(MS_PROTOCOL_TCP, MS_TIMEOUT_SEC_10, &sock_info);
+ sockfd = sock_info.sock_fd;
#else
- ret = ms_ipc_create_client_socket(MS_PROTOCOL_UDP, MS_TIMEOUT_SEC_10, &sockfd);
+ ret = ms_ipc_create_client_socket(MS_PROTOCOL_TCP, MS_TIMEOUT_SEC_10, &sockfd);
#endif
MSAPI_RETV_IF(ret != MS_MEDIA_ERR_NONE, ret);
- ret = ms_ipc_send_msg_to_server(sockfd, port, &send_msg, &serv_addr);
+ ret = ms_ipc_send_msg_to_server_tcp(sockfd, port, &send_msg, &serv_addr);
if (ret != MS_MEDIA_ERR_NONE) {
MSAPI_DBG_ERR("ms_ipc_send_msg_to_server failed : %d", ret);
+#ifdef _USE_UDS_SOCKET_
+ ms_ipc_delete_client_socket(&sock_info);
+#else
close(sockfd);
+#endif
return ret;
}
-
/*Receive Response*/
ms_comm_msg_s recv_msg;
serv_addr_len = sizeof(serv_addr);
ret = recv_msg.result;
}
+#ifdef _USE_UDS_SOCKET_
+ ms_ipc_delete_client_socket(&sock_info);
+#else
close(sockfd);
+#endif
return ret;
}
-static int g_tcp_client_sock = -1;
+#ifdef _USE_UDS_SOCKET_
+extern char MEDIA_IPC_PATH[][50];
+#endif
-static int __media_db_get_client_tcp_sock()
+static int __media_db_request_update_tcp(ms_msg_type_e msg_type, const char *request_msg)
{
- return g_tcp_client_sock;
-}
+ int ret = MS_MEDIA_ERR_NONE;
+ int request_msg_size = 0;
+ int sockfd = -1;
+#ifdef _USE_UDS_SOCKET_
+ ms_sock_info_s sock_info;
+ struct sockaddr_un serv_addr;
+#else
+ struct sockaddr_in serv_addr;
+#endif
+ int port = MS_DB_UPDATE_PORT;
+
+ if(!MS_STRING_VALID(request_msg))
+ {
+ MSAPI_DBG_ERR("invalid query");
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
+ }
+
+ request_msg_size = strlen(request_msg);
+ if(request_msg_size >= MAX_MSG_SIZE)
+ {
+ MSAPI_DBG_ERR("Query is Too long. [%d] query size limit is [%d]", request_msg_size, MAX_MSG_SIZE);
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
+ }
+
+// MSAPI_DBG("querysize[%d] query[%s]", request_msg_size, request_msg);
+
+ ms_comm_msg_s send_msg;
+ memset((void *)&send_msg, 0, sizeof(ms_comm_msg_s));
+
+ send_msg.msg_type = msg_type;
+ send_msg.msg_size = request_msg_size;
+ strncpy(send_msg.msg, request_msg, request_msg_size);
+ /*Create Socket*/
#ifdef _USE_UDS_SOCKET_
-extern char MEDIA_IPC_PATH[][50];
-#elif defined(_USE_UDS_SOCKET_TCP_)
-extern char MEDIA_IPC_PATH[][50];
+ ret = ms_ipc_create_client_socket(MS_PROTOCOL_TCP, MS_TIMEOUT_SEC_10, &sock_info);
+ sockfd = sock_info.sock_fd;
+#else
+ ret = ms_ipc_create_client_socket(MS_PROTOCOL_TCP, MS_TIMEOUT_SEC_10, &sockfd);
+#endif
+ MSAPI_RETV_IF(ret != MS_MEDIA_ERR_NONE, ret);
+
+ /*Set server Address*/
+ memset(&serv_addr, 0, sizeof(serv_addr));
+#ifdef _USE_UDS_SOCKET_
+ serv_addr.sun_family = AF_UNIX;
+ MSAPI_DBG("%s", MEDIA_IPC_PATH[port]);
+ strcpy(serv_addr.sun_path, MEDIA_IPC_PATH[port]);
+#else
+ serv_addr.sin_family = AF_INET;
+ serv_addr.sin_addr.s_addr = inet_addr(SERVER_IP);
+ serv_addr.sin_port = htons(port);
#endif
+ /* Connecting to the media db server */
+ if (connect(sockfd, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) < 0) {
+ MSAPI_DBG_ERR("connect error : %s", strerror(errno));
+ close(sockfd);
+ return MS_MEDIA_ERR_SOCKET_CONN;
+ }
+
+ MSAPI_DBG("Connected successfully");
+
+ /* Send request */
+ if (send(sockfd, &send_msg, sizeof(send_msg), 0) != sizeof(send_msg)) {
+ MSAPI_DBG_ERR("send failed : %s", strerror(errno));
+ close(sockfd);
+ return MS_MEDIA_ERR_SOCKET_SEND;
+ } else {
+ MSAPI_DBG("Sent successfully");
+ }
+
+ /*Receive Response*/
+ int recv_msg_size = -1;
+ int recv_msg = -1;
+ if ((recv_msg_size = recv(sockfd, &recv_msg, sizeof(recv_msg), 0)) < 0) {
+ MSAPI_DBG_ERR("recv failed : %s[%d]", strerror(errno), sockfd);
+
+ close(sockfd);
+ if (errno == EWOULDBLOCK) {
+ MSAPI_DBG_ERR("Timeout. Can't try any more");
+ return MS_MEDIA_ERR_SOCKET_RECEIVE_TIMEOUT;
+ } else {
+ MSAPI_DBG_ERR("recv failed : %s", strerror(errno));
+ return MS_MEDIA_ERR_SOCKET_RECEIVE;
+ }
+ }
+
+ MSAPI_DBG("RECEIVE OK [%d]", recv_msg);
+ ret = recv_msg;
+
+ close(sockfd);
+
+ return ret;
+}
+
+static __thread int g_tcp_client_sock = -1;
+
+static int __media_db_get_client_tcp_sock()
+{
+ return g_tcp_client_sock;
+}
+
static int __media_db_prepare_tcp_client_socket()
{
int ret = MS_MEDIA_ERR_NONE;
int sockfd = -1;
#ifdef _USE_UDS_SOCKET_
- struct sockaddr_un serv_addr;
-#elif defined(_USE_UDS_SOCKET_TCP_)
+ ms_sock_info_s sock_info;
struct sockaddr_un serv_addr;
#else
struct sockaddr_in serv_addr;
/*Create TCP Socket*/
#ifdef _USE_UDS_SOCKET_
- ret = ms_ipc_create_client_socket(MS_PROTOCOL_TCP, MS_TIMEOUT_SEC_10, &sockfd, 0);
-#elif defined(_USE_UDS_SOCKET_TCP_)
- ret = ms_ipc_create_client_tcp_socket(MS_PROTOCOL_TCP, MS_TIMEOUT_SEC_10, &sockfd, MS_DB_BATCH_UPDATE_TCP_PORT);
+ ret = ms_ipc_create_client_socket(MS_PROTOCOL_TCP, MS_TIMEOUT_SEC_10, &sock_info);
+ sockfd = sock_info.sock_fd;
#else
ret = ms_ipc_create_client_socket(MS_PROTOCOL_TCP, MS_TIMEOUT_SEC_10, &sockfd);
#endif
serv_addr.sun_family = AF_UNIX;
MSAPI_DBG("%s", MEDIA_IPC_PATH[port]);
strcpy(serv_addr.sun_path, MEDIA_IPC_PATH[port]);
-#elif defined(_USE_UDS_SOCKET_TCP_)
- serv_addr.sun_family = AF_UNIX;
- MSAPI_DBG("%s", MEDIA_IPC_PATH[MS_DB_BATCH_UPDATE_TCP_PORT]);
- strcpy(serv_addr.sun_path, MEDIA_IPC_PATH[MS_DB_BATCH_UPDATE_TCP_PORT]);
#else
serv_addr.sin_family = AF_INET;
- serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
- //serv_addr.sin_addr.s_addr = inet_addr(SERVER_IP);
+ serv_addr.sin_addr.s_addr = inet_addr(SERVER_IP);
serv_addr.sin_port = htons(port);
#endif
static int __media_db_close_tcp_client_socket()
{
- close(g_tcp_client_sock);
+ int ret = MS_MEDIA_ERR_NONE;
+
+ if (close(g_tcp_client_sock)<0) {
+ MSAPI_DBG_ERR("close failed [%s]", strerror(errno));
+ ret = MS_MEDIA_ERR_SOCKET_INTERNAL;
+ }
g_tcp_client_sock = -1;
- return 0;
+ return ret;
}
static int __media_db_request_batch_update(ms_msg_type_e msg_type, const char *request_msg)
return MS_MEDIA_ERR_INVALID_PARAMETER;
}
- MSAPI_DBG("querysize[%d] query[%s]", request_msg_size, request_msg);
+ MSAPI_DBG_SLOG("querysize[%d] query[%s]", request_msg_size, request_msg);
ms_comm_msg_s send_msg;
memset((void *)&send_msg, 0, sizeof(ms_comm_msg_s));
/* Send request */
if (send(sockfd, &send_msg, sizeof(send_msg), 0) != sizeof(send_msg)) {
MSAPI_DBG_ERR("send failed : %s", strerror(errno));
- __media_db_close_tcp_client_socket(sockfd);
+ __media_db_close_tcp_client_socket();
return MS_MEDIA_ERR_SOCKET_SEND;
} else {
MSAPI_DBG("Sent successfully");
int recv_msg_size = -1;
int recv_msg = -1;
if ((recv_msg_size = recv(sockfd, &recv_msg, sizeof(recv_msg), 0)) < 0) {
- MSAPI_DBG_ERR("recv failed : %s", strerror(errno));
+ MSAPI_DBG_ERR("recv failed : %s[%d]", strerror(errno), sockfd);
- __media_db_close_tcp_client_socket(sockfd);
+ __media_db_close_tcp_client_socket();
if (errno == EWOULDBLOCK) {
MSAPI_DBG_ERR("Timeout. Can't try any more");
return MS_MEDIA_ERR_SOCKET_RECEIVE_TIMEOUT;
int ret = MS_MEDIA_ERR_NONE;
char *zErrMsg = NULL;
- MSAPI_DBG_INFO("SQL = [%s]", sql_str);
+// MSAPI_DBG_SLOG("SQL = [%s]", sql_str);
ret = sqlite3_exec(db_handle, sql_str, NULL, NULL, &zErrMsg);
MSAPI_DBG_ERR("DB Update Fail SQL:%s [%s], err[%d]", sql_str, zErrMsg, ret);
if (ret == SQLITE_BUSY)
ret = MS_MEDIA_ERR_DB_BUSY_FAIL;
+ else if (ret == SQLITE_CONSTRAINT)
+ ret = MS_MEDIA_ERR_DB_CONSTRAINT_FAIL;
else
ret = MS_MEDIA_ERR_DB_UPDATE_FAIL;
} else {
MSAPI_RETVM_IF(!MS_STRING_VALID(query_str), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid Query");
- ret = __media_db_request_update(MS_MSG_DB_UPDATE, query_str);
+ ret = __media_db_request_update_tcp(MS_MSG_DB_UPDATE, query_str);
return ret;
}
MSAPI_RETVM_IF(!MS_STRING_VALID(query_str), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid Query");
ret = __media_db_prepare_tcp_client_socket();
-
if (ret < MS_MEDIA_ERR_NONE) {
MSAPI_DBG_ERR("__media_db_prepare_tcp_client_socket failed : %d", ret);
__media_db_close_tcp_client_socket();
return ret;
}
+
+int media_db_request_update_db_batch_clear(void)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+
+ __media_db_destroy_sql_list();
+
+ return ret;
+}
#include <string.h>
#include <unistd.h>
#include <errno.h>
-#include <sys/types.h>
#include <sys/stat.h>
#include "media-util-dbg.h"
#ifdef _USE_UDS_SOCKET_
char MEDIA_IPC_PATH[][50] ={
- {"/tmp/media_ipc_dbbatchupdate.dat"},
- {"/tmp/media_ipc_scandaemon.dat"},
- {"/tmp/media_ipc_scancomm.dat"},
- {"/tmp/media_ipc_scanner.dat"},
- {"/tmp/media_ipc_dbupdate.dat"},
- {"/tmp/media_ipc_thumbcreator.dat"},
- {"/tmp/media_ipc_thumbcomm.dat"},
- {"/tmp/media_ipc_thumbdaemon.dat"},
+ {"/tmp/.media_ipc_dbbatchupdate"},
+ {"/tmp/.media_ipc_scandaemon"},
+ {"/tmp/.media_ipc_scanner"},
+ {"/tmp/.media_ipc_dbupdate"},
+ {"/tmp/.media_ipc_thumbcreator"},
+ {"/tmp/.media_ipc_thumbcomm"},
+ {"/tmp/.media_ipc_thumbdaemon"},
};
-char MEDIA_IPC_PATH_CLIENT[][50] ={
- {"/tmp/media_ipc_dbbatchupdate_client.dat"},
- {"/tmp/media_ipc_scandaemon_client.dat"},
- {"/tmp/media_ipc_scancomm_client.dat"},
- {"/tmp/media_ipc_scanner_client.dat"},
- {"/tmp/media_ipc_dbupdate_client.dat"},
- {"/tmp/media_ipc_thumbcreator_client.dat"},
- {"/tmp/media_ipc_thumbcomm_client.dat"},
- {"/tmp/media_ipc_thumbdaemon_client.dat"},
-};
-#elif defined(_USE_UDS_SOCKET_TCP_)
-char MEDIA_IPC_PATH[][50] ={
- {"/tmp/media_ipc_dbbatchupdate.dat"},
- {"/tmp/media_ipc_thumbcreator.dat"},
-};
+#define MS_SOCK_PATH_PRFX "/tmp/.media_ipc_client"
+#define MS_SOCK_PATH_TEMPLATE "XXXXXX"
+#define MS_SOCK_PATH MS_SOCK_PATH_PRFX MS_SOCK_PATH_TEMPLATE
+
+static const char abc[] =
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
+
+static int __make_rand_sock_and_bind(int sockfd, struct sockaddr_un *serv_addr, char *sock_path)
+{
+ int count;
+ char *rand_str = NULL;
+ int len = 0;
+ int ret = MS_MEDIA_ERR_NONE;
+
+ len = strlen(sock_path);
+
+ rand_str = &sock_path[len -strlen(MS_SOCK_PATH_TEMPLATE)];
+
+ for (count = 0; count < TMP_MAX; count++) {
+
+ srand((unsigned int) time(0) + getpid());
+
+ rand_str[0] = abc[rand() % 62];
+ rand_str[1] = abc[rand() % 62];
+ rand_str[2] = abc[rand() % 62];
+ rand_str[3] = abc[rand() % 62];
+ rand_str[4] = abc[rand() % 62];
+ rand_str[5] = abc[rand() % 62];
+
+ strcpy(serv_addr->sun_path, sock_path);
+
+ /* Bind to the local address */
+ if (bind(sockfd, (struct sockaddr *)serv_addr, sizeof(struct sockaddr_un)) < 0) {
+ MSAPI_DBG_ERR("bind failed : %s", strerror(errno));
+ if(errno == EADDRINUSE) {
+ if (count == TMP_MAX -1) {
+ MSAPI_DBG_ERR("bind failed : arrive max count %d", TMP_MAX);
+ ret = MS_MEDIA_ERR_SOCKET_BIND;
+ break;
+ }
+ MSAPI_DBG_ERR("retry bind %d", count);
+ continue;
+ } else {
+ MSAPI_DBG_ERR("socket bind failed");
+ close(sockfd);
+ ret= MS_MEDIA_ERR_SOCKET_BIND;
+ break;
+ }
+ } else {
+ ret = MS_MEDIA_ERR_NONE;
+ break;
+ }
+ }
+
+ return ret;
+}
#endif
#ifdef _USE_UDS_SOCKET_
-int ms_ipc_create_client_socket(ms_protocol_e protocol, int timeout_sec, int *sock_fd, int port)
+int ms_ipc_create_client_socket(ms_protocol_e protocol, int timeout_sec, ms_sock_info_s* sock_info)
#else
int ms_ipc_create_client_socket(ms_protocol_e protocol, int timeout_sec, int *sock_fd)
#endif
{
int sock = -1;
+#ifdef _USE_UDS_SOCKET_
+ int err = MS_MEDIA_ERR_NONE;
+ struct sockaddr_un serv_addr;
+ char sock_path_temp[] = MS_SOCK_PATH;
+#endif
struct timeval tv_timeout = { timeout_sec, 0 };
if(protocol == MS_PROTOCOL_UDP)
{
-#ifdef _USE_UDS_SOCKET_
- struct sockaddr_un serv_addr;
-#endif
-
/* Create a datagram/UDP socket */
#ifdef _USE_UDS_SOCKET_
if ((sock = socket(PF_FILE, SOCK_DGRAM, 0)) < 0) {
#ifdef _USE_UDS_SOCKET_
memset(&serv_addr, 0, sizeof(serv_addr));
serv_addr.sun_family = AF_UNIX;
- MSAPI_DBG("%s", MEDIA_IPC_PATH_CLIENT[port]);
- unlink(MEDIA_IPC_PATH_CLIENT[port]);
- strcpy(serv_addr.sun_path, MEDIA_IPC_PATH_CLIENT[port]);
-
- /* Bind to the local address */
- if (bind(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) {
- MSAPI_DBG_ERR("bind failed : %s", strerror(errno));
- close(sock);
- return MS_MEDIA_ERR_SOCKET_CONN;
+ /* make temp file for socket*/
+ err = __make_rand_sock_and_bind(sock, &serv_addr, sock_path_temp);
+ if (err != MS_MEDIA_ERR_NONE) {
+ MSAPI_DBG_ERR("__make_rand_sock_and_bind failed");
+ return err;
}
#endif
}
}
}
+#ifdef _USE_UDS_SOCKET_
+ sock_info->sock_fd = sock;
+ if(protocol == MS_PROTOCOL_UDP)
+ sock_info->sock_path = strdup(sock_path_temp);
+ else
+ sock_info->sock_path = NULL;
+#else
*sock_fd = sock;
+#endif
return MS_MEDIA_ERR_NONE;
}
-#ifdef _USE_UDS_SOCKET_TCP_
-int ms_ipc_create_client_tcp_socket(ms_protocol_e protocol, int timeout_sec, int *sock_fd, int port)
-{
- int sock = -1;
-
- struct timeval tv_timeout = { timeout_sec, 0 };
-
- /*Create TCP Socket*/
- if ((sock = socket(PF_FILE, SOCK_STREAM, 0)) < 0) {
- MSAPI_DBG_ERR("socket failed: %s", strerror(errno));
- return MS_MEDIA_ERR_SOCKET_CONN;
- }
-
- if (timeout_sec > 0) {
- if (setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, &tv_timeout, sizeof(tv_timeout)) == -1) {
- MSAPI_DBG_ERR("setsockopt failed: %s", strerror(errno));
- close(sock);
- return MS_MEDIA_ERR_SOCKET_CONN;
- }
- }
-
- *sock_fd = sock;
-
- return MS_MEDIA_ERR_NONE;
-}
-
-int ms_ipc_create_server_tcp_socket(ms_protocol_e protocol, int port, int *sock_fd)
+#ifdef _USE_UDS_SOCKET_
+int ms_ipc_delete_client_socket(ms_sock_info_s* sock_info)
{
- int i;
- bool bind_success = false;
- int sock = -1;
-
- struct sockaddr_un serv_addr;
- mode_t orig_mode;
- orig_mode = umask(0);
-
- /* Create a TCP socket */
- if ((sock = socket(PF_FILE, SOCK_STREAM, 0)) < 0) {
- MSAPI_DBG_ERR("socket failed: %s", strerror(errno));
- return MS_MEDIA_ERR_SOCKET_CONN;
- }
-
- memset(&serv_addr, 0, sizeof(serv_addr));
-
- serv_addr.sun_family = AF_UNIX;
- MSAPI_DBG("%s", MEDIA_IPC_PATH[port]);
- unlink(MEDIA_IPC_PATH[port]);
- strcpy(serv_addr.sun_path, MEDIA_IPC_PATH[port]);
-
- /* Bind to the local address */
- for (i = 0; i < 20; i ++) {
- if (bind(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) == 0) {
- bind_success = true;
- break;
+ int err = 0;
+
+ close(sock_info->sock_fd);
+ MSAPI_DBG_ERR("sockfd %d close", sock_info->sock_fd);
+ if (sock_info->sock_path != NULL) {
+ err = unlink(sock_info->sock_path);
+ if (err< 0) {
+ MSAPI_DBG_ERR("unlink failed: %s", strerror(errno));
}
- MSAPI_DBG("%d",i);
- usleep(250000);
- }
-
- if (bind_success == false) {
- MSAPI_DBG_ERR("bind failed : %s %d_", strerror(errno), errno);
- close(sock);
- return MS_MEDIA_ERR_SOCKET_CONN;
- }
-
- MSAPI_DBG("bind success");
-
- /* Listening */
- if (listen(sock, SOMAXCONN) < 0) {
- MSAPI_DBG_ERR("listen failed : %s", strerror(errno));
- close(sock);
- return MS_MEDIA_ERR_SOCKET_CONN;
+ free(sock_info->sock_path);
}
- MSAPI_DBG("Listening...");
-
- *sock_fd = sock;
-
- umask(orig_mode);
- return MS_MEDIA_ERR_NONE;
+ return 0;
}
-
#endif
+#ifdef _USE_UDS_SOCKET_
+int ms_ipc_create_server_socket(ms_protocol_e protocol, ms_msg_port_type_e port, int *sock_fd)
+#else
int ms_ipc_create_server_socket(ms_protocol_e protocol, int port, int *sock_fd)
+#endif
{
int i;
bool bind_success = false;
int sock = -1;
- int n_reuse = 1;
#ifdef _USE_UDS_SOCKET_
struct sockaddr_un serv_addr;
#else
+ int n_reuse = 1;
struct sockaddr_in serv_addr;
#endif
unsigned short serv_port;
strcpy(serv_addr.sun_path, MEDIA_IPC_PATH[serv_port]);
#else
serv_addr.sin_family = AF_INET;
- serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
-// serv_addr.sin_addr.s_addr = inet_addr(SERVER_IP);
+// serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
+ serv_addr.sin_addr.s_addr = inet_addr(SERVER_IP);
serv_addr.sin_port = htons(serv_port);
#endif
/* Bind to the local address */
MSAPI_DBG("Listening...");
}
-
+#ifdef _USE_UDS_SOCKET_
+ /*change permission of sock file*/
+ if (chmod(MEDIA_IPC_PATH[serv_port], 0660) < 0)
+ MSAPI_DBG_ERR("chmod failed [%s]", strerror(errno));
+ if (chown(MEDIA_IPC_PATH[serv_port], 0, 5000) < 0)
+ MSAPI_DBG_ERR("chown failed [%s]", strerror(errno));
+#endif
*sock_fd = sock;
return MS_MEDIA_ERR_NONE;
}
#ifdef _USE_UDS_SOCKET_
-int ms_ipc_send_msg_to_server(int sockfd, int port, ms_comm_msg_s *send_msg, struct sockaddr_un *serv_addr)
+int ms_ipc_send_msg_to_server(int sockfd, ms_msg_port_type_e port, ms_comm_msg_s *send_msg, struct sockaddr_un *serv_addr)
#else
int ms_ipc_send_msg_to_server(int sockfd, int port, ms_comm_msg_s *send_msg, struct sockaddr_in *serv_addr)
#endif
struct sockaddr_in addr;
#endif
- /* Set server Address */
+/* Set server Address */
memset(&addr, 0, sizeof(addr));
#ifdef _USE_UDS_SOCKET_
addr.sun_family = AF_UNIX;
MSAPI_DBG_ERR("sendto failed [%s]", strerror(errno));
res = MS_MEDIA_ERR_SOCKET_SEND;
} else {
- MSAPI_DBG("sent %d", send_msg->result);
- MSAPI_DBG("sent %s", send_msg->msg);
+ MSAPI_DBG("sent result [%d]", send_msg->result);
+ MSAPI_DBG_SLOG("result message [%s]", send_msg->msg);
+ if (serv_addr != NULL)
+ *serv_addr = addr;
+ }
+
+ return res;
+}
+
+#ifdef _USE_UDS_SOCKET_
+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)
+#else
+int ms_ipc_send_msg_to_server_tcp(int sockfd, int port, ms_comm_msg_s *send_msg, struct sockaddr_in *serv_addr)
+#endif
+{
+ int res = MS_MEDIA_ERR_NONE;
+#ifdef _USE_UDS_SOCKET_
+ struct sockaddr_un addr;
+#else
+ struct sockaddr_in addr;
+#endif
+
+ /* Set server Address */
+ memset(&addr, 0, sizeof(addr));
+#ifdef _USE_UDS_SOCKET_
+ addr.sun_family = AF_UNIX;
+ strcpy(addr.sun_path, MEDIA_IPC_PATH[port]);
+ MSAPI_DBG("%s", addr.sun_path);
+#else
+ addr.sin_family = AF_INET;
+ addr.sin_addr.s_addr = inet_addr(SERVER_IP);
+ addr.sin_port = htons(port);
+#endif
+
+ /* Connecting to the media db server */
+ if (connect(sockfd, (struct sockaddr*)&addr, sizeof(addr)) < 0) {
+ MSAPI_DBG_ERR("connect error : %s", strerror(errno));
+ close(sockfd);
+ return MS_MEDIA_ERR_SOCKET_CONN;
+ }
+
+ if (write(sockfd, send_msg, sizeof(*(send_msg))) != sizeof(*(send_msg))) {
+ MSAPI_DBG_ERR("write failed [%s]", strerror(errno));
+ res = MS_MEDIA_ERR_SOCKET_SEND;
+ } else {
+ MSAPI_DBG("sent result [%d]", send_msg->result);
+ MSAPI_DBG_SLOG("result message [%s]", send_msg->msg);
if (serv_addr != NULL)
*serv_addr = addr;
}
int res = MS_MEDIA_ERR_NONE;
#ifdef _USE_UDS_SOCKET_
- MSAPI_DBG("the path of client address : %s", client_addr->sun_path);
+ MSAPI_DBG_SLOG("the path of client address : %s", client_addr->sun_path);
#endif
if (sendto(sockfd, send_msg, sizeof(*(send_msg)), 0, (struct sockaddr *)client_addr, sizeof(*(client_addr))) != sizeof(*(send_msg))) {
MSAPI_DBG_ERR("sendto failed [%s]", strerror(errno));
res = MS_MEDIA_ERR_SOCKET_SEND;
} else {
- MSAPI_DBG("sent %d", send_msg->result);
- MSAPI_DBG("sent %s", send_msg->msg);
+ MSAPI_DBG("sent result [%d]", send_msg->result);
+ MSAPI_DBG_SLOG("result message [%s]", send_msg->msg);
+ }
+
+ return MS_MEDIA_ERR_NONE;
+}
+
+#ifdef _USE_UDS_SOCKET_
+int ms_ipc_send_msg_to_client_tcp(int sockfd, ms_comm_msg_s *send_msg, struct sockaddr_un *client_addr)
+#else
+int ms_ipc_send_msg_to_client_tcp(int sockfd, ms_comm_msg_s *send_msg, struct sockaddr_in *client_addr)
+#endif
+{
+ int res = MS_MEDIA_ERR_NONE;
+
+#ifdef _USE_UDS_SOCKET_
+// MSAPI_DBG_SLOG("the path of client address : %s", client_addr->sun_path);
+#endif
+
+ if (write(sockfd, send_msg, sizeof(*(send_msg))) != sizeof(*(send_msg))) {
+ MSAPI_DBG_ERR("sendto failed [%s]", strerror(errno));
+ res = MS_MEDIA_ERR_SOCKET_SEND;
+ } else {
+ MSAPI_DBG("sent result [%d]", send_msg->result);
+ MSAPI_DBG_SLOG("result message [%s]", send_msg->msg);
}
return MS_MEDIA_ERR_NONE;
}
#ifdef _USE_UDS_SOCKET_
- MSAPI_DBG("the path of received client address : %s", addr.sun_path);
+ MSAPI_DBG_SLOG("the path of received client address : %s", addr.sun_path);
#endif
if (recv_addr != NULL)
#include "media-util-internal.h"
#include "media-util-dbg.h"
#include "media-util.h"
+#include "media-util-noti.h"
DBusConnection *g_bus;
void *g_data_store;
-GMutex *noti_mutex = NULL;
+GArray *handle_list;
+static GStaticMutex noti_mutex = G_STATIC_MUTEX_INIT;
int ref_count;
+#define MS_MEDIA_DBUS_NAME "ms_db_updated"
+
typedef struct noti_callback_data{
db_update_cb user_callback;
void *user_data;
g_data_store = NULL;
}
-static DBusHandlerResult
-__message_filter (DBusConnection *connection, DBusMessage *message, void *user_data)
+DBusHandlerResult
+__get_message(DBusMessage *message, db_update_cb user_cb, void *userdata)
{
- db_update_cb user_cb = ((noti_callback_data*)user_data)->user_callback;
- void *userdata = ((noti_callback_data*)user_data)->user_data;
-
/* A Ping signal on the com.burtonini.dbus.Signal interface */
if (dbus_message_is_signal (message, MS_MEDIA_DBUS_INTERFACE, MS_MEDIA_DBUS_NAME)) {
int i = 0;
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
+static DBusHandlerResult
+__message_filter (DBusConnection *connection, DBusMessage *message, void *user_data)
+{
+ db_update_cb user_cb = ((noti_callback_data*)user_data)->user_callback;
+ void *userdata = ((noti_callback_data*)user_data)->user_data;
+ DBusHandlerResult ret;
+
+ ret = __get_message(message, user_cb, userdata);
+
+ return ret;
+}
+
+
int media_db_update_subscribe(db_update_cb user_cb, void *user_data)
{
int ret = MS_MEDIA_ERR_NONE;
DBusError error;
noti_callback_data *callback_data = NULL;
- if (noti_mutex == NULL) {
- noti_mutex = g_mutex_new();
- if (noti_mutex == NULL) {
- return MS_MEDIA_ERR_ALLOCATE_MEMORY_FAIL;
- }
- }
-
- g_mutex_lock(noti_mutex);
+ g_static_mutex_lock(¬i_mutex);
if (g_bus == NULL) {
dbus_g_thread_init();
ref_count ++;
- g_mutex_unlock(noti_mutex);
+ g_static_mutex_unlock(¬i_mutex);
return MS_MEDIA_ERR_NONE;
}
MS_SAFE_FREE(callback_data);
- g_mutex_unlock(noti_mutex);
- g_mutex_free(noti_mutex);
- noti_mutex = NULL;
+ g_static_mutex_unlock(¬i_mutex);
return ret;
}
return MS_MEDIA_ERR_NONE;
}
- g_mutex_lock(noti_mutex);
+ g_static_mutex_lock(¬i_mutex);
if (ref_count == 1) {
dbus_connection_remove_filter(g_bus, __message_filter, g_data_store);
ref_count --;
- g_mutex_unlock(noti_mutex);
-
- if (ref_count == 0) {
- g_mutex_free(noti_mutex);
- noti_mutex = NULL;
- }
+ g_static_mutex_unlock(¬i_mutex);
return MS_MEDIA_ERR_NONE;
}
char *mime_type /* optional */
)
{
- DBusMessage *message;
- DBusConnection *bus;
+ DBusMessage *message = NULL;
+ DBusConnection *bus = NULL;
DBusError error;
unsigned char *path_array = NULL;
int path_length = strlen(path) + 1;
DBUS_TYPE_INVALID);
} else {
MSAPI_DBG_ERR("uuid or mime_type is NULL");
- dbus_connection_unref(bus);
+ MS_SAFE_FREE(path_array);
+ dbus_message_unref (message);
return MS_MEDIA_ERR_INVALID_PARAMETER;
}
} else if (item == MS_MEDIA_ITEM_DIRECTORY) {
GSource *source;
scan_complete_cb user_callback;
void *user_data;
+ char *sock_path;
} media_callback_data;
static bool _is_valid_path(const char *path)
void *user_data = NULL;
ms_comm_msg_s recv_msg;
media_request_result_s req_result;
- int ret;
int sockfd = -1;
+ char *sock_path = NULL;
+ int recv_msg_size = 0;
sockfd = g_io_channel_unix_get_fd(src);
if (sockfd < 0) {
}
memset(&recv_msg, 0x0, sizeof(ms_comm_msg_s));
+ memset(&req_result, 0x0, sizeof(media_request_result_s));
- /* Socket is readable */
- ret = ms_ipc_receive_message(sockfd, &recv_msg, sizeof(recv_msg), NULL, NULL);
- if (ret != MS_MEDIA_ERR_NONE) {
- MSAPI_DBG("ms_ipc_receive_message failed");
- return TRUE;
+ if ((recv_msg_size = read(sockfd, &recv_msg, sizeof(ms_comm_msg_s))) < 0) {
+ MSAPI_DBG_ERR("recv failed : %s", strerror(errno));
+ req_result.pid = -1;
+ req_result.result = MS_MEDIA_ERR_SOCKET_RECEIVE;
+ req_result.complete_path = NULL;
+ req_result.request_type = -1;
+ goto ERROR;
}
- memset(&req_result, 0x0, sizeof(media_request_result_s));
req_result.pid = recv_msg.pid;
req_result.result = recv_msg.result;
if (recv_msg.msg_type ==MS_MSG_SCANNER_RESULT) {
MSAPI_DBG("result :%d", req_result.result);
MSAPI_DBG("request_type :%d", req_result.request_type);
+ERROR:
source = ((media_callback_data *)data)->source;
user_callback = ((media_callback_data *)data)->user_callback;
user_data = ((media_callback_data *)data)->user_data;
+ sock_path = ((media_callback_data *)data)->sock_path;
/*call user define function*/
user_callback(&req_result, user_data);
g_source_destroy(source);
close(sockfd);
+ if (sock_path != NULL) {
+ MSAPI_DBG("delete path :%s", sock_path);
+ unlink(sock_path);
+ MS_SAFE_FREE(sock_path);
+ }
MS_SAFE_FREE(data);
return TRUE;
}
-static int _attach_callback(int *sockfd, scan_complete_cb user_callback, void *user_data)
+static int _attach_callback(int *sockfd, char* sock_path, scan_complete_cb user_callback, void *user_data)
{
GIOChannel *channel = NULL;
GMainContext *context = NULL;
cb_data->source = source;
cb_data->user_callback = user_callback;
cb_data->user_data = user_data;
+ cb_data->sock_path = sock_path;
/* Set callback to be called when socket is readable */
g_source_set_callback(source, (GSourceFunc)_read_socket, cb_data, NULL);
int sockfd = -1;
int port = MS_SCANNER_PORT;
ms_comm_msg_s send_msg;
-
+ char *sock_path = NULL;
+#ifdef _USE_UDS_SOCKET_
+ ms_sock_info_s sock_info;
+#endif
if(!MS_STRING_VALID(request_msg))
{
MSAPI_DBG_ERR("invalid query");
/*Create Socket*/
#ifdef _USE_UDS_SOCKET_
- ret = ms_ipc_create_client_socket(MS_PROTOCOL_UDP, 0, &sockfd, port);
+ ret = ms_ipc_create_client_socket(MS_PROTOCOL_TCP, 0, &sock_info);
+ sockfd = sock_info.sock_fd;
+ if (sock_info.sock_path != NULL)
+ sock_path = sock_info.sock_path;
#else
- ret = ms_ipc_create_client_socket(MS_PROTOCOL_UDP, 0, &sockfd);
+ ret = ms_ipc_create_client_socket(MS_PROTOCOL_TCP, 0, &sockfd);
#endif
+
MSAPI_RETV_IF(ret != MS_MEDIA_ERR_NONE, ret);
- ret = ms_ipc_send_msg_to_server(sockfd, port, &send_msg, NULL);
+ ret = ms_ipc_send_msg_to_server_tcp(sockfd, port, &send_msg, NULL);
if (ret != MS_MEDIA_ERR_NONE) {
MSAPI_DBG_ERR("ms_ipc_send_msg_to_server failed : %d", ret);
+#ifdef _USE_UDS_SOCKET_
+ ms_ipc_delete_client_socket(&sock_info);
+#else
close(sockfd);
+#endif
return ret;
}
- ret = _attach_callback(&sockfd, user_callback ,user_data);
+ ret = _attach_callback(&sockfd, sock_path, user_callback ,user_data);
if(ret != MS_MEDIA_ERR_NONE)
return ret;
Name: media-server
Summary: File manager service server.
-Version: 0.2.49
+Version: 0.2.50
Release: 1
Group: utils
License: Apache License, Version 2.0
BuildRequires: pkgconfig(glib-2.0)
BuildRequires: pkgconfig(vconf)
BuildRequires: pkgconfig(dlog)
-BuildRequires: pkgconfig(drm-client)
BuildRequires: pkgconfig(aul)
BuildRequires: pkgconfig(pmapi)
BuildRequires: pkgconfig(heynoti)
BuildRequires: pkgconfig(sqlite3)
BuildRequires: pkgconfig(db-util)
BuildRequires: pkgconfig(notification)
+BuildRequires: pkgconfig(security-server)
+
%description
Description: File manager service server
#endif
#define LOG_TAG "MEDIA_COMMON"
+#define MS_DBG_SLOG(fmt, args...) SECURE_LOGD(fmt "\n", ##args);
+
#define MS_DBG(fmt, args...) LOGD(fmt "\n", ##args);
#define MS_DBG_INFO(fmt, args...) do{ if (true) { \
- LOGE(fmt "\n" , ##args); \
+ LOGI(fmt "\n" , ##args); \
}} while(false)
#define MS_DBG_WARN(fmt, args...) do{ if (true) { \
+++ /dev/null
-/*
- * Media Server
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Yong Yeon Kim <yy9875.kim@samsung.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-/**
- * This file defines api utilities of contents manager engines.
- *
- * @file media-server-drm.h
- * @author Yong Yeon Kim(yy9875.kim@samsung.com)
- * @version 1.0
- * @brief This file implements main database operation.
- */
-#ifndef _MEDIA_SERVER_DRM_H_
-#define _MEDIA_SERVER_DRM_H_
-
-bool
-ms_is_drm_file(const char *path);
-
-int
-ms_get_mime_in_drm_info(const char *path, char *mime);
-
-int
-ms_drm_register(const char* path);
-
-void
-ms_drm_unregister(const char* path);
-
-void
-ms_drm_unregister_all(void);
-
-bool
-ms_drm_insert_ext_memory(void);
-
-bool
-ms_drm_extract_ext_memory(void);
-
-#endif /*_MEDIA_SERVER_DRM_H_*/
\ No newline at end of file
ms_get_storage_type_by_full(const char *path);
int
-ms_get_mime(const char *path, char *mimetype);
-
-int
ms_strappend(char *res, const int size, const char *pattern,
const char *str1, const char *str2);
+++ /dev/null
-/*
- * Media Server
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Yong Yeon Kim <yy9875.kim@samsung.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-/**
- * This file defines api utilities of contents manager engines.
- *
- * @file media-server-drm.c
- * @author Yong Yeon Kim(yy9875.kim@samsung.com)
- * @version 1.0
- * @brief This file implements main database operation.
- */
-#include <drm_client_types.h>
-#include <drm_client.h>
-
-#include "media-util.h"
-
-#include "media-common-dbg.h"
-#include "media-common-types.h"
-#include "media-common-drm.h"
-
-bool
-ms_is_drm_file(const char *path)
-{
-#ifdef __SUPPORT_DRM
- int ret;
- drm_bool_type_e is_drm_file = DRM_UNKNOWN;
-
- ret = drm_is_drm_file(path,&is_drm_file);
- if(DRM_RETURN_SUCCESS == ret && DRM_TRUE == is_drm_file)
- return true;
-#endif
- return false;
-}
-
-int
-ms_get_mime_in_drm_info(const char *path, char *mime)
-{
-#ifdef __SUPPORT_DRM
- int ret;
- drm_content_info_s contentInfo;
- drm_file_type_e file_type = DRM_TYPE_UNDEFINED;
-
- if (path == NULL || mime == NULL)
- return MS_MEDIA_ERR_INVALID_PARAMETER;
-
- /* check drm type */
- ret = drm_get_file_type(path, &file_type);
- if (ret != DRM_RETURN_SUCCESS) {
- MS_DBG_ERR("drm_get_file_type() failed");
- MS_DBG_ERR("%s [%d]", path, ret);
- return MS_MEDIA_ERR_DRM_GET_INFO_FAIL;
- } else {
- /* if a drm file is OMA drm, use DRM API for getting mime information */
- if (file_type == DRM_TYPE_OMA_V1
- || file_type == DRM_TYPE_OMA_V2
- || file_type == DRM_TYPE_OMA_PD) {
- MS_DBG_ERR("THIS IS OMA DRM");
- memset(&contentInfo,0x0,sizeof(drm_content_info_s));
- ret = drm_get_content_info(path, &contentInfo);
- if (ret != DRM_RETURN_SUCCESS) {
- MS_DBG_ERR("drm_svc_get_content_info() failed");
- MS_DBG_ERR("%s [%d]", path, ret);
- return MS_MEDIA_ERR_DRM_GET_INFO_FAIL;
- }
- strncpy(mime, contentInfo.mime_type, 100);
- } else {
- MS_DBG_ERR("THIS IS DRM BUT YOU SHOULD USE API OF AUL LIBRARY");
- return MS_MEDIA_ERR_DRM_GET_INFO_FAIL;
- }
- }
-
- return MS_MEDIA_ERR_NONE;
-#else
- return MS_MEDIA_ERR_DRM_GET_INFO_FAIL;
-#endif
-}
-
-int
-ms_drm_register(const char* path)
-{
-
- int res = MS_MEDIA_ERR_NONE;
-#ifdef __SUPPORT_DRM
- int ret;
- ret = drm_process_request(DRM_REQUEST_TYPE_REGISTER_FILE, (void *)path, NULL);
- if (ret != DRM_RETURN_SUCCESS) {
- MS_DBG_ERR("drm_svc_register_file error : %d", ret);
- res = MS_MEDIA_ERR_DRM_REGISTER_FAIL;
- }
-#endif
- return res;
-}
-
-void
-ms_drm_unregister(const char* path)
-{
-#ifdef __SUPPORT_DRM
- int ret;
-
- ret = drm_process_request(DRM_REQUEST_TYPE_UNREGISTER_FILE, (void *)path, NULL);
- if (ret != DRM_RETURN_SUCCESS)
- MS_DBG_ERR("drm_process_request error : %d", ret);
-#endif
-}
-
-void
-ms_drm_unregister_all(void)
-{
-#ifdef __SUPPORT_DRM
- if (drm_process_request(DRM_REQUEST_TYPE_UNREGISTER_ALL_FILES , NULL, NULL) == DRM_RETURN_SUCCESS)
- MS_DBG("drm_svc_unregister_all_contents OK");
-#endif
-}
-
-bool
-ms_drm_insert_ext_memory(void)
-{
-#ifdef __SUPPORT_DRM
- MS_DBG("");
- if (drm_process_request(DRM_REQUEST_TYPE_INSERT_EXT_MEMORY, NULL, NULL) != DRM_RETURN_SUCCESS)
- return false;
-#endif
- return true;
-}
-
-bool
-ms_drm_extract_ext_memory(void)
-{
-#ifdef __SUPPORT_DRM
- MS_DBG("");
- if (drm_process_request(DRM_REQUEST_TYPE_EXTRACT_EXT_MEMORY , NULL, NULL) != DRM_RETURN_SUCCESS)
- return false;
-#endif
- return true;
-}
-
#include "media-server-ipc.h"
#include "media-common-dbg.h"
#include "media-common-utils.h"
-#include "media-common-drm.h"
#include "media-common-external-storage.h"
#define MMC_INFO_SIZE 256
#include "media-util.h"
#include "media-server-ipc.h"
#include "media-common-dbg.h"
-#include "media-common-drm.h"
#include "media-common-utils.h"
#ifdef FMS_PERF
}
int
-ms_get_mime(const char *path, char *mimetype)
-{
- int ret = MS_MEDIA_ERR_NONE;
-
- if (path == NULL)
- return MS_MEDIA_ERR_INVALID_PARAMETER;
-
- /*get content type and mime type from file. */
- /*in case of drm file. */
- if (ms_is_drm_file(path)) {
- if (ms_get_mime_in_drm_info(path, mimetype) != MS_MEDIA_ERR_NONE) {
- MS_DBG_ERR("Fail to get mime from drm API");
- if (aul_get_mime_from_file(path, mimetype, 255) < 0) {
- MS_DBG_ERR("aul_get_mime_from_file fail");
- ret = MS_MEDIA_ERR_MIME_GET_FAIL;
- } else {
- MS_DBG_ERR("aul_get_mime_from_file success");
- ret = MS_MEDIA_ERR_NONE;
- }
- }
- } else {
- /*in case of normal files */
- if (aul_get_mime_from_file(path, mimetype, 255) < 0) {
- MS_DBG_ERR("aul_get_mime_from_file fail");
- ret = MS_MEDIA_ERR_MIME_GET_FAIL;
- }
- }
-
- return ret;
-}
-
-int
ms_strappend(char *res, const int size, const char *pattern,
const char *str1, const char *str2)
{
#undef LOG_TAG
#endif
#define LOG_TAG "MEDIA_SCANNER"
+
+#define MSC_DBG_SLOG(fmt, args...) SECURE_LOGD(fmt "\n", ##args);
#define MSC_DBG_INFO(fmt, args...) LOGD(fmt "\n" , ##args);
#define MSC_DBG_ERR(fmt, args...) do{ if (true) { \
LOGE(fmt "\n", ##args); \
#include "media-util.h"
#include "media-common-utils.h"
-#include "media-common-drm.h"
#include "media-scanner-dbg.h"
#include "media-scanner-db-svc.h"
/*check exist in Media DB, If file is not exist, insert data in DB. */
ret = ((CHECK_ITEM_EXIST)func_array[lib_index][eEXIST])(handle[lib_index], path, storage_type, &err_msg); /*dlopen*/
if (ret != 0) {
- MSC_DBG_ERR("not exist in %d. insert data", lib_index);
MS_SAFE_FREE(err_msg);
ret = ((INSERT_ITEM)func_array[lib_index][eINSERT_BATCH])(handle[lib_index], path, storage_type, &err_msg); /*dlopen*/
if (ret != 0) {
MSC_DBG_ERR("error : %s [%s] %s", g_array_index(so_array, char*, lib_index), err_msg, path);
- MSC_DBG_ERR("[%s]", path);
MS_SAFE_FREE(err_msg);
res = MS_MEDIA_ERR_DB_INSERT_FAIL;
} else {
ret = ((SET_ITEM_VALIDITY)func_array[lib_index][eSET_VALIDITY])(handle[lib_index], path, true, true, &err_msg); /*dlopen*/
if (ret != 0) {
MSC_DBG_ERR("error : %s [%s] %s", g_array_index(so_array, char*, lib_index), err_msg, path);
- MSC_DBG_ERR("[%s]", path);;
MS_SAFE_FREE(err_msg);
res = MS_MEDIA_ERR_DB_UPDATE_FAIL;
}
}
} else {
- MSC_DBG_ERR("check category failed");
- MSC_DBG_ERR("[%s]", path);
+ MSC_DBG_ERR("check category failed [%s]", path);
}
}
- if (ms_is_drm_file(path)) {
- ret = ms_drm_register(path);
- }
-
return res;
}
if (!_msc_check_category(path, lib_index)) {
ret = ((INSERT_ITEM)func_array[lib_index][eINSERT_BATCH])(handle[lib_index], path, storage_type, &err_msg); /*dlopen*/
if (ret != 0) {
- MSC_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg);
- MSC_DBG_ERR("[%s]", path);
+ MSC_DBG_ERR("error : %s [%s] %s", g_array_index(so_array, char*, lib_index), err_msg, path);
MS_SAFE_FREE(err_msg);
res = MS_MEDIA_ERR_DB_INSERT_FAIL;
}
} else {
- MSC_DBG_ERR("check category failed");
- MSC_DBG_ERR("[%s]", path);
+ MSC_DBG_ERR("check category failed [%s]", path);
}
}
- if (ms_is_drm_file(path)) {
- ret = ms_drm_register(path);
- res = ret;
- }
-
return res;
}
if (!_msc_check_category(path, lib_index)) {
ret = ((INSERT_BURST_ITEM)func_array[lib_index][eINSERT_BURST])(handle[lib_index], path, storage_type, &err_msg); /*dlopen*/
if (ret != 0) {
- MSC_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg);
- MSC_DBG_ERR("[%s]", path);
+ MSC_DBG_ERR("error : %s [%s] %s", g_array_index(so_array, char*, lib_index), err_msg, path);
MS_SAFE_FREE(err_msg);
res = MS_MEDIA_ERR_DB_INSERT_FAIL;
}
} else {
- MSC_DBG_ERR("check category failed");
- MSC_DBG_ERR("[%s]", path);
+ MSC_DBG_ERR("check category failed [%s]", path);
}
}
- if (ms_is_drm_file(path)) {
- ret = ms_drm_register(path);
- res = ret;
- }
-
return res;
}
/*check poweroff status*/
if (power_off) {
- MSC_DBG_INFO("Power off");
+ MSC_DBG_ERR("Power off");
ret = MS_MEDIA_ERR_SCANNER_FORCE_STOP;
}
/*check SD card in out */
if ((mmc_state != VCONFKEY_SYSMAN_MMC_MOUNTED) && (storage_type == MS_STORAGE_EXTERNAL)) {
- MSC_DBG_INFO("Directory scanning is stopped");
+ MSC_DBG_ERR("Directory scanning is stopped");
ret = MS_MEDIA_ERR_SCANNER_FORCE_STOP;
}
GArray *dir_array = NULL;
struct dirent entry;
struct dirent *result = NULL;
- int i;
int ret = MS_MEDIA_ERR_NONE;
char *new_path = NULL;
char *current_path = NULL;
/*delete all node*/
if(dir_array != NULL) {
- for (i =0; i < dir_array->len; i++) {
+ while(dir_array->len != 0) {
char *data = NULL;
data = g_array_index(dir_array , char*, 0);
g_array_remove_index (dir_array, 0);
MS_SAFE_FREE(data);
}
- g_array_free (dir_array, TRUE);
+ g_array_free (dir_array, FALSE);
dir_array = NULL;
}
sync();
- MSC_DBG_INFO("ret : %d", err);
-
return err;
}
while (1) {
scan_data = g_async_queue_pop(scan_queue);
if (scan_data->pid == POWEROFF) {
- MSC_DBG_INFO("power off");
+ MSC_DBG_ERR("power off");
goto _POWEROFF;
}
- MSC_DBG_INFO("DIRECTORY SCAN START");
+ MSC_DBG_ERR("DIRECTORY SCAN START [%s]", scan_data->msg);
/*connect to media db, if conneting is failed, db updating is stopped*/
err = msc_connect_db(&handle);
MS_SAFE_FREE(scan_data);
- MSC_DBG_INFO("DIRECTORY SCAN END");
+ MSC_DBG_ERR("DIRECTORY SCAN END [%d]", ret);
} /*thread while*/
_POWEROFF:
while (1) {
scan_data = g_async_queue_pop(storage_queue);
if (scan_data->pid == POWEROFF) {
- MSC_DBG_INFO("power off");
+ MSC_DBG_ERR("power off");
goto _POWEROFF;
}
- MSC_DBG_INFO("STORAGE SCAN START");
+ MSC_DBG_ERR("STORAGE SCAN START [%s]", scan_data->msg);
scan_type = scan_data->msg_type;
if (scan_type != MS_MSG_STORAGE_ALL
}
storage_type = ms_get_storage_type_by_full(scan_data->msg);
- MSC_DBG_INFO("%d", storage_type);
/*connect to media db, if conneting is failed, db updating is stopped*/
err = msc_connect_db(&handle);
MS_SAFE_FREE(scan_data);
- MSC_DBG_INFO("STORAGE SCAN END");
+ MSC_DBG_ERR("STORAGE SCAN END[%d]", ret);
} /*thread while*/
_POWEROFF:
register_data = g_array_index(register_array, ms_comm_msg_s*, 0);
g_array_remove_index (register_array, 0);
if (register_data->pid == POWEROFF) {
- MSC_DBG_INFO("power off");
+ MSC_DBG_ERR("power off");
goto _POWEROFF;
}
} else if (length != 0) {
while(fgets(buf, MS_FILE_PATH_LEN_MAX, fp) != NULL) {
length = strlen(buf); /*the return value of function, strlen(), includes "\n" */
path = strndup(buf, length - 1); /*copying except "\n" and strndup fuction adds "\0" at the end of the copying string */
- MSC_DBG_INFO("insert path : %s [%d]", path, strlen(path));
/* insert getted path to the list */
if (g_array_append_val(path_array, path) == NULL) {
MSC_DBG_ERR("g_array_append_val failed");
goto FREE_RESOURCE;
}
+ MSC_DBG_ERR("BULK REGISTER START [%s]", register_data->msg);
+
/* get the inserting file path from array and insert to db */
for (i = 0; i < path_array->len; i++) {
/* it is really regular file */
ret = _check_file_path(insert_path);
if (ret != MS_MEDIA_ERR_NONE) {
- MSC_DBG_ERR("Can't insert the meta of the path");
+ MSC_DBG_ERR("Can't insert the meta of the path[%s]", insert_path);
continue;
}
err = insert_function(handle, insert_path);
if (power_off) {
- MSC_DBG_INFO("power off");
+ MSC_DBG_ERR("power off");
/*call for bundle commit*/
msc_register_end(handle);
goto _POWEROFF;
/* If register_files operation is stopped, there is no necessrty for sending result. */
msc_send_register_result(MS_MEDIA_ERR_NONE, register_data);
+
+ MSC_DBG_ERR("BULK REGISTER END[%s]", register_data->msg);
FREE_RESOURCE:
if (path_array) {
- g_array_free(path_array, TRUE);
+ while(path_array->len != 0) {
+ char *data = NULL;
+ data = g_array_index(path_array , char*, 0);
+ g_array_remove_index (path_array, 0);
+ MS_SAFE_FREE(data);
+ }
+ g_array_free(path_array, FALSE);
path_array = NULL;
}
_POWEROFF:
MS_SAFE_FREE(file_path);
MS_SAFE_FREE(register_data);
- if (register_array) g_array_free (register_array, TRUE);
- if (path_array) g_array_free (path_array, TRUE);
+ if (register_array) {
+ while(register_array->len != 0) {
+ ms_comm_msg_s *data = NULL;
+ data = g_array_index(register_array , ms_comm_msg_s*, 0);
+ g_array_remove_index (register_array, 0);
+ MS_SAFE_FREE(data);
+ }
+ g_array_free (register_array, FALSE);
+ register_array = NULL;
+ }
+
+ if (path_array) {
+ while(path_array->len != 0) {
+ char *data = NULL;
+ data = g_array_index(path_array , char*, 0);
+ g_array_remove_index (path_array, 0);
+ MS_SAFE_FREE(data);
+ }
+ g_array_free(path_array, FALSE);
+ path_array = NULL;
+ }
if (handle) msc_disconnect_db(&handle);
if(fp) fclose(fp);
*/
#include <arpa/inet.h>
#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <errno.h>
#ifdef _USE_UDS_SOCKET_
#include <sys/un.h>
#else
int sockfd = MS_SOCK_NOT_ALLOCATE;
int req_num = MS_MSG_MAX;
int pid = -1;
- int ret = MS_MEDIA_ERR_NONE;
+ int err = -1;
sockfd = g_io_channel_unix_get_fd(src);
if (sockfd < 0) {
return TRUE;
}
- /* Socket is readable */
- ret = ms_ipc_receive_message(sockfd, recv_msg, sizeof(*recv_msg), NULL, NULL);
- if (ret != MS_MEDIA_ERR_NONE) {
+ /* read() is blocked until media scanner sends message */
+ err = read(sockfd, recv_msg, sizeof(ms_comm_msg_s));
+ if (err < 0) {
+ MSC_DBG_ERR("fifo read failed [%s]", strerror(errno));
MS_SAFE_FREE(recv_msg);
- return TRUE;
+ return MS_MEDIA_ERR_FILE_READ_FAIL;
}
MSC_DBG_INFO("receive msg from [%d] %d, %s", recv_msg->pid, recv_msg->msg_type, recv_msg->msg);
/*Create Socket*/
#ifdef _USE_UDS_SOCKET_
- ret = ms_ipc_create_client_socket(MS_PROTOCOL_UDP, 0, &sockfd, MS_SCAN_COMM_PORT);
+ ms_sock_info_s sock_info;
+ ret = ms_ipc_create_client_socket(MS_PROTOCOL_TCP, 0, &sock_info);
+ sockfd = sock_info.sock_fd;
#else
- ret = ms_ipc_create_client_socket(MS_PROTOCOL_UDP, 0, &sockfd);
+ ret = ms_ipc_create_client_socket(MS_PROTOCOL_TCP, 0, &sockfd);
#endif
if (ret != MS_MEDIA_ERR_NONE)
return MS_MEDIA_ERR_SOCKET_CONN;
send_msg.msg_size = strlen(scan_data->msg);
strncpy(send_msg.msg, scan_data->msg, send_msg.msg_size);
- ret = ms_ipc_send_msg_to_server(sockfd, MS_SCAN_COMM_PORT, &send_msg, NULL);
+ ret = ms_ipc_send_msg_to_server_tcp(sockfd, MS_SCANNER_PORT, &send_msg, NULL);
if (ret != MS_MEDIA_ERR_NONE)
res = ret;
+#ifdef _USE_UDS_SOCKET_
+ ms_ipc_delete_client_socket(&sock_info);
+#else
close(sockfd);
+#endif
return res;
}
/*Create Socket*/
#ifdef _USE_UDS_SOCKET_
- ret = ms_ipc_create_client_socket(MS_PROTOCOL_UDP, 0, &sockfd, MS_SCAN_COMM_PORT);
+ ms_sock_info_s sock_info;
+ ret = ms_ipc_create_client_socket(MS_PROTOCOL_TCP, 0, &sock_info);
+ sockfd = sock_info.sock_fd;
#else
- ret = ms_ipc_create_client_socket(MS_PROTOCOL_UDP, 0, &sockfd);
+ ret = ms_ipc_create_client_socket(MS_PROTOCOL_TCP, 0, &sockfd);
#endif
if (ret != MS_MEDIA_ERR_NONE)
return MS_MEDIA_ERR_SOCKET_CONN;
- /* send ready message */
+ /* send result message */
memset(&send_msg, 0x0, sizeof(ms_comm_msg_s));
send_msg.msg_type = MS_MSG_SCANNER_BULK_RESULT;
send_msg.pid = reg_data->pid;
send_msg.msg_size = reg_data->msg_size;
strncpy(send_msg.msg, reg_data->msg, send_msg.msg_size);
- ret = ms_ipc_send_msg_to_server(sockfd, MS_SCAN_COMM_PORT, &send_msg, NULL);
+ ret = ms_ipc_send_msg_to_server_tcp(sockfd, MS_SCANNER_PORT, &send_msg, NULL);
+#ifdef _USE_UDS_SOCKET_
+ ms_ipc_delete_client_socket(&sock_info);
+#else
close(sockfd);
+#endif
return ret;
}
int msc_send_ready(void)
{
- int ret;
int res = MS_MEDIA_ERR_NONE;
- int sockfd = -1;
ms_comm_msg_s send_msg;
+ int fd = -1;
+ int err = -1;
- /*Create Socket*/
-#ifdef _USE_UDS_SOCKET_
- ret = ms_ipc_create_client_socket(MS_PROTOCOL_UDP, 0, &sockfd, MS_SCAN_COMM_PORT);
-#else
- ret = ms_ipc_create_client_socket(MS_PROTOCOL_UDP, 0, &sockfd);
-#endif
- if (ret != MS_MEDIA_ERR_NONE)
- return MS_MEDIA_ERR_SOCKET_CONN;
+ fd = open(MS_SCANNER_FIFO_PATH_RES, O_WRONLY);
+ if (fd < 0) {
+ MSC_DBG_ERR("fifo open failed", strerror(errno));
+ return MS_MEDIA_ERR_FILE_OPEN_FAIL;
+ }
/* send ready message */
memset(&send_msg, 0, sizeof(send_msg));
send_msg.msg_type = MS_MSG_SCANNER_READY;
-
- ret = ms_ipc_send_msg_to_server(sockfd, MS_SCAN_COMM_PORT, &send_msg, NULL);
- if (ret != MS_MEDIA_ERR_NONE)
- res = ret;
- close(sockfd);
+ /* send ready message */
+ err = write(fd, &send_msg, sizeof(send_msg));
+ if (err < 0) {
+ MSC_DBG_ERR("fifo write failed", strerror(errno));
+ res = MS_MEDIA_ERR_FILE_READ_FAIL;
+ }
+
+ close(fd);
return res;
}
#include <dirent.h>
#include <vconf.h>
#include <heynoti.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <errno.h>
#include "media-common-utils.h"
-#include "media-common-drm.h"
#include "media-common-external-storage.h"
#include "media-util.h"
GIOChannel *channel = NULL;
GMainContext *context = NULL;
- int sockfd = -1;
- int err;
+ int err = -1;
+ int fd = -1;
#if 0 /* temporary */
check_result = check_process();
} else {
err = heynoti_subscribe(heynoti_id, POWEROFF_NOTI_NAME, _power_off_cb, NULL);
if (err < 0)
- MSC_DBG_INFO("heynoti_subscribe failed");
+ MSC_DBG_ERR("heynoti_subscribe failed");
err = heynoti_attach_handler(heynoti_id);
if (err < 0)
- MSC_DBG_INFO("heynoti_attach_handler failed");
+ MSC_DBG_ERR("heynoti_attach_handler failed");
}
/*load functions from plusin(s)*/
/*Init mutex variable*/
if (!db_mutex) db_mutex = g_mutex_new();
- /*prepare socket*/
- /* Create and bind new UDP socket */
- if (ms_ipc_create_server_socket(MS_PROTOCOL_UDP, MS_SCAN_DAEMON_PORT, &sockfd)
- != MS_MEDIA_ERR_NONE) {
- MSC_DBG_ERR("Failed to create socket\n");
- exit(0);
- } else {
- context = g_main_loop_get_context(scanner_mainloop);
+ /* Create pipe */
+ err = unlink(MS_SCANNER_FIFO_PATH_REQ);
+ if (err !=0) {
+ MSC_DBG_ERR("unlink failed [%s]", strerror(errno));
+ }
- /* Create new channel to watch udp socket */
- channel = g_io_channel_unix_new(sockfd);
- source = g_io_create_watch(channel, G_IO_IN);
+ err = mkfifo(MS_SCANNER_FIFO_PATH_REQ, MS_SCANNER_FIFO_MODE);
+ if (err !=0) {
+ MSC_DBG_ERR("mkfifo failed [%s]", strerror(errno));
+ return MS_MEDIA_ERR_MAKE_FIFO_FAIL;
+ }
- /* Set callback to be called when socket is readable */
- g_source_set_callback(source, (GSourceFunc)msc_receive_request, NULL, NULL);
- g_source_attach(source, context);
- g_source_unref(source);
+ fd = open(MS_SCANNER_FIFO_PATH_REQ, O_RDWR);
+ if (fd < 0) {
+ MSC_DBG_ERR("fifo open failed [%s]", strerror(errno));
+ return MS_MEDIA_ERR_FILE_OPEN_FAIL;
}
+ context = g_main_loop_get_context(scanner_mainloop);
+
+ /* Create new channel to watch pipe */
+ channel = g_io_channel_unix_new(fd);
+ source = g_io_create_watch(channel, G_IO_IN);
+
+ /* Set callback to be called when pipe is readable */
+ g_source_set_callback(source, (GSourceFunc)msc_receive_request, NULL, NULL);
+ g_source_attach(source, context);
+ g_source_unref(source);
+
/*create each threads*/
storage_scan_thread = g_thread_new("storage_scan_thread", (GThreadFunc)msc_storage_scan_thread, NULL);
scan_thread = g_thread_new("scanner_thread", (GThreadFunc)msc_directory_scan_thread, NULL);
msc_send_ready();
- MSC_DBG_INFO("*****************************************");
- MSC_DBG_INFO("*** Scanner is running ***");
- MSC_DBG_INFO("*****************************************");
+ MSC_DBG_ERR("*****************************************");
+ MSC_DBG_ERR("*** Scanner is running ***");
+ MSC_DBG_ERR("*****************************************");
g_main_loop_run(scanner_mainloop);
/*Clear db mutex variable*/
if (db_mutex) g_mutex_free (db_mutex);
- /*close socket*/
- close(sockfd);
+ /*close pipe*/
+ close(fd);
/*unload functions*/
msc_unload_functions();
#endif
#define LOG_TAG "MEDIA_SERVER"
+#define MS_DBG_SLOG(fmt, args...) SECURE_LOGD(fmt "\n", ##args);
+
#define MS_DBG(fmt, args...) LOGD(fmt "\n", ##args);
#define MS_DBG_INFO(fmt, args...) do{ if (true) { \
- LOGE(fmt "\n" , ##args); \
+ LOGI(fmt "\n" , ##args); \
}} while(false)
#define MS_DBG_WARN(fmt, args...) do{ if (true) { \
gboolean ms_read_socket(GIOChannel *src, GIOCondition condition, gpointer data);
-gboolean ms_receive_message_from_scanner(GIOChannel *src, GIOCondition condition, gpointer data);
+gboolean ms_read_db_tcp_socket(GIOChannel *src, GIOCondition condition, gpointer data);
+
+gboolean ms_read_db_tcp_batch_socket(GIOChannel *src, GIOCondition condition, gpointer data);
int ms_send_scan_request(ms_comm_msg_s *send_msg);
int ms_send_storage_scan_request(ms_storage_type_t storage_type, ms_dir_scan_type_t scan_type);
-gboolean ms_read_db_socket(GIOChannel *src, GIOCondition condition, gpointer data);
-gboolean ms_read_db_tcp_socket(GIOChannel *src, GIOCondition condition, gpointer data);
-
#endif /*_MEDIA_SERVER_SOCKET_H_*/
#include "media-util.h"
#include "media-common-utils.h"
-#include "media-common-drm.h"
#include "media-server-dbg.h"
#include "media-server-db-svc.h"
return FALSE;
}
- /* Create Socket*/
- ret = ms_ipc_create_server_socket(MS_PROTOCOL_UDP, MS_DB_UPDATE_PORT, &sockfd);
+ /* Create TCP Socket*/
+ ret = ms_ipc_create_server_socket(MS_PROTOCOL_TCP, MS_DB_UPDATE_PORT, &sockfd);
if(ret != MS_MEDIA_ERR_NONE) {
/* Disconnect DB*/
media_db_disconnect(db_handle);
-
MS_DBG_ERR("Failed to create socket\n");
return FALSE;
}
/* Create TCP Socket for batch query*/
-#ifdef _USE_UDS_SOCKET_TCP_
- ret = ms_ipc_create_server_tcp_socket(MS_PROTOCOL_TCP, MS_DB_BATCH_UPDATE_TCP_PORT, &tcp_sockfd);
-#else
ret = ms_ipc_create_server_socket(MS_PROTOCOL_TCP, MS_DB_BATCH_UPDATE_PORT, &tcp_sockfd);
-#endif
if(ret != MS_MEDIA_ERR_NONE) {
/* Disconnect DB*/
media_db_disconnect(db_handle);
g_db_mainloop = g_main_loop_new(context, FALSE);
//context = g_main_loop_get_context(g_db_mainloop);
- /* Create new channel to watch udp socket */
+ /* Create new channel to watch UDP socket */
channel = g_io_channel_unix_new(sockfd);
source = g_io_create_watch(channel, G_IO_IN);
/* Set callback to be called when socket is readable */
- g_source_set_callback(source, (GSourceFunc)ms_read_db_socket, db_handle, NULL);
+ g_source_set_callback(source, (GSourceFunc)ms_read_db_tcp_socket, db_handle, NULL);
g_source_attach(source, context);
/* Create new channel to watch TCP socket */
tcp_source = g_io_create_watch(tcp_channel, G_IO_IN);
/* Set callback to be called when socket is readable */
- g_source_set_callback(tcp_source, (GSourceFunc)ms_read_db_tcp_socket, db_handle, NULL);
+ g_source_set_callback(tcp_source, (GSourceFunc)ms_read_db_tcp_batch_socket, db_handle, NULL);
g_source_attach(tcp_source, context);
g_main_context_push_thread_default(context);
#include "media-util.h"
#include "media-common-utils.h"
-#include "media-common-drm.h"
#include "media-common-external-storage.h"
#include "media-server-dbg.h"
#include "media-server-db-svc.h"
static void _power_off_cb(void* data)
{
- MS_DBG("++++++++++++++++++++++++++++++++++++++");
- MS_DBG("POWER OFF");
- MS_DBG("++++++++++++++++++++++++++++++++++++++");
+ MS_DBG_ERR("POWER OFF");
/*Quit Thumbnail Thread*/
GMainLoop *thumb_mainloop = ms_get_thumb_thread_mainloop();
void _ms_signal_handler(int n)
{
- MS_DBG("Receive SIGNAL");
int stat, pid, thumb_pid;
int scanner_pid;
thumb_pid = ms_thumb_get_server_pid();
- MS_DBG("Thumbnail server pid : %d", thumb_pid);
-
scanner_pid = ms_get_scanner_pid();
pid = waitpid(-1, &stat, WNOHANG);
/* check pid of child process of thumbnail thread */
- MS_DBG_ERR("[PID %d] signal ID %d", pid, n);
if (pid == thumb_pid) {
- MS_DBG_ERR("Thumbnail server is dead");
+ MS_DBG_ERR("[%d] Thumbnail server is dead", pid);
ms_thumb_reset_server_status();
} else if (pid == scanner_pid) {
- MS_DBG_ERR("Scanner is dead");
+ MS_DBG_ERR("[%d] Scanner is dead", pid);
ms_reset_scanner_status();
} else if (pid == -1) {
MS_DBG_ERR("%s", strerror(errno));
MS_DBG_ERR("Get VCONFKEY_SYSMAN_MMC_STATUS failed.");
}
- MS_DBG("VCONFKEY_SYSMAN_MMC_STATUS :%d", status);
+ MS_DBG_ERR("CURRENT STATUS OF SD CARD[%d]", status);
/* If scanner is not working, media server executes media scanner and sends request. */
/* If scanner is working, it detects changing status of SD card. */
/*remove added watch descriptors */
ms_present_mmc_status(MS_SDCARD_REMOVED);
- if (!ms_drm_extract_ext_memory())
- MS_DBG_ERR("ms_drm_extract_ext_memory failed");
-
ms_send_storage_scan_request(MS_STORAGE_EXTERNAL, MS_SCAN_INVALID);
} else if (status == VCONFKEY_SYSMAN_MMC_MOUNTED) {
ms_present_mmc_status(MS_SDCARD_INSERTED);
- if (!ms_drm_insert_ext_memory())
- MS_DBG_ERR("ms_drm_insert_ext_memory failed");
-
ms_send_storage_scan_request(MS_STORAGE_EXTERNAL, ms_get_mmc_state());
}
/*heynoti for power off*/
if ((heynoti_id = heynoti_init()) <0) {
- MS_DBG("heynoti_init failed");
+ MS_DBG_ERR("heynoti_init failed");
} else {
err = heynoti_subscribe(heynoti_id, POWEROFF_NOTI_NAME, _power_off_cb, NULL);
if (err < 0)
- MS_DBG("heynoti_subscribe failed");
+ MS_DBG_ERR("heynoti_subscribe failed");
err = heynoti_attach_handler(heynoti_id);
if (err < 0)
- MS_DBG("heynoti_attach_handler failed");
+ MS_DBG_ERR("heynoti_attach_handler failed");
}
_ms_new_global_variable();
/*prepare socket*/
/* Create and bind new UDP socket */
- if (ms_ipc_create_server_socket(MS_PROTOCOL_UDP, MS_SCANNER_PORT, &sockfd)
+ if (ms_ipc_create_server_socket(MS_PROTOCOL_TCP, MS_SCANNER_PORT, &sockfd)
!= MS_MEDIA_ERR_NONE) {
MS_DBG_ERR("Failed to create socket");
} else {
if (err == -1)
MS_DBG_ERR("add call back function for event %s fails", VCONFKEY_SYSMAN_MMC_STATUS);
- MS_DBG("*********************************************************");
- MS_DBG("*** Begin to check tables of file manager in database ***");
- MS_DBG("*********************************************************");
/* Add signal handler */
sigemptyset(&sigset.sa_mask);
sigaddset(&sigset.sa_mask, SIGCHLD);
- sigset.sa_flags = 0;
+ sigset.sa_flags = SA_RESTART;
sigset.sa_handler = _ms_signal_handler;
if (sigaction(SIGCHLD, &sigset, NULL) < 0) {
MS_DBG_ERR("sigaction failed [%s]", strerror(errno));
- } else {
- MS_DBG("handler ok");
- }
+ }
/*clear previous data of sdcard on media database and check db status for updating*/
while(!ms_db_get_thread_status()) {
- MS_DBG("wait db thread");
+ MS_DBG_ERR("wait db thread");
sleep(1);
}
ms_send_storage_scan_request(MS_STORAGE_INTERNAL, MS_SCAN_PART);
if (ms_is_mmc_inserted()) {
- if (!ms_drm_insert_ext_memory())
- MS_DBG_ERR("ms_drm_insert_ext_memory failed");
-
ms_make_default_path_mmc();
ms_present_mmc_status(MS_SDCARD_INSERTED);
/*Active flush */
malloc_trim(0);
- MS_DBG("*****************************************");
- MS_DBG("*** Server of File Manager is running ***");
- MS_DBG("*****************************************");
+ MS_DBG_ERR("*** Media Server is running ***");
g_main_loop_run(mainloop);
g_thread_join(db_thread);
#include <unistd.h>
#include <glib.h>
#include <vconf.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
#include "media-util.h"
#include "media-server-ipc.h"
static bool scanner_ready;
static int alarm_id;
-static int receive_id;
static int child_pid;
-
-
static int _ms_check_remain_task(void)
{
int remain_task;
static gboolean _ms_stop_scanner (gpointer user_data)
{
- int sockfd;
- int task_num;
- GIOChannel *src = user_data;
+ int task_num = MS_NO_REMAIN_TASK;
g_mutex_lock(scanner_mutex);
return TRUE;
}
}
- /* close socket */
- sockfd = g_io_channel_unix_get_fd(src);
- g_io_channel_shutdown(src, FALSE, NULL);
- g_io_channel_unref(src);
- close(sockfd);
+ MS_DBG("KILL SCANNER");
+ /* close FIFO */
+ unlink(MS_SCANNER_FIFO_PATH_RES);
+ unlink(MS_SCANNER_FIFO_PATH_REQ);
+
+// ms_reset_scanner_status();
g_source_destroy(g_main_context_find_source_by_id(g_main_loop_get_context (mainloop), alarm_id));
- g_source_destroy(g_main_context_find_source_by_id(g_main_loop_get_context (mainloop), receive_id));
return FALSE;
}
-
static void _ms_add_timeout(guint interval, GSourceFunc func, gpointer data)
{
MS_DBG("");
GSource *src;
src = g_timeout_source_new_seconds(interval);
- g_source_set_callback(src, func, data, NULL);
+ g_source_set_callback(src, func, NULL, NULL);
alarm_id = g_source_attach(src, g_main_loop_get_context (mainloop));
g_source_unref(src);
}
if((pid = fork()) < 0) {
MS_DBG_ERR("Fork error\n");
+ g_mutex_unlock(scanner_mutex);
} else if (pid > 0) {
/* parent process */
/* wait until scanner is ready*/
int ret = MS_MEDIA_ERR_NONE;
- int sockfd = -1;
int err = -1;
- int n_reuse = 1;
-#ifdef _USE_UDS_SOCKET_
- struct sockaddr_un serv_addr;
-#else
- struct sockaddr_in serv_addr;
-#endif
- unsigned int serv_addr_len = -1;
- int port = MS_SCAN_COMM_PORT;
+ int fd = -1;
ms_comm_msg_s recv_msg;
+ int scanner_status = -1;
- GSource *res_source = NULL;
- GIOChannel *res_channel = NULL;
- GMainContext *res_context = NULL;
-
- /*Create Socket*/
-#ifdef _USE_UDS_SOCKET_
- ret = ms_ipc_create_server_socket(MS_PROTOCOL_UDP, MS_SCAN_COMM_PORT, &sockfd);
- if (ret != MS_MEDIA_ERR_NONE) {
- MS_DBG_ERR("ms_ipc_create_server_socket failed [%d]",ret);
- g_mutex_unlock(scanner_mutex);
- return MS_MEDIA_ERR_SOCKET_CONN;
+ err = unlink(MS_SCANNER_FIFO_PATH_RES);
+ if (err !=0) {
+ MS_DBG_ERR("unlink failed [%s]", strerror(errno));
}
-#else
- ret = ms_ipc_create_client_socket(MS_PROTOCOL_UDP, MS_TIMEOUT_SEC_10, &sockfd);
- if (ret != MS_MEDIA_ERR_NONE) {
- MS_DBG_ERR("ms_ipc_create_client_socket failed [%d]",ret);
- g_mutex_unlock(scanner_mutex);
- return MS_MEDIA_ERR_SOCKET_CONN;
+ err = mkfifo(MS_SCANNER_FIFO_PATH_RES, MS_SCANNER_FIFO_MODE);
+ if (err !=0) {
+ MS_DBG_ERR("mkfifo failed [%s]", strerror(errno));
+ return MS_MEDIA_ERR_MAKE_FIFO_FAIL;
}
- /* set socket re-use */
- if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &n_reuse, sizeof(n_reuse)) == -1) {
- MS_DBG_ERR("setsockopt failed: %s", strerror(errno));
- close(sockfd);
- g_mutex_unlock(scanner_mutex);
- return MS_MEDIA_ERR_SOCKET_INTERNAL;
+
+ fd = open(MS_SCANNER_FIFO_PATH_RES, O_RDWR);
+ if (fd < 0) {
+ MS_DBG_ERR("fifo open failed [%s]", strerror(errno));
+ return MS_MEDIA_ERR_FILE_OPEN_FAIL;
}
- /*Set server Address*/
- memset(&serv_addr, 0, sizeof(serv_addr));
- serv_addr.sin_family = AF_INET;
- serv_addr.sin_addr.s_addr = inet_addr(SERVER_IP);
- serv_addr.sin_port = htons(port);
- /* Bind to the local address */
- if (bind(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) {
- MS_DBG_ERR("bind failed [%s]", strerror(errno));
- close(sockfd);
- g_mutex_unlock(scanner_mutex);
- return MS_MEDIA_ERR_SOCKET_BIND;
+
+ /* read() is blocked until media scanner sends message */
+ err = read(fd, &recv_msg, sizeof(recv_msg));
+ if (err < 0) {
+ MS_DBG_ERR("fifo read failed [%s]", strerror(errno));
+ close(fd);
+ return MS_MEDIA_ERR_FILE_READ_FAIL;
}
-#endif
-
- /*Receive Response*/
- serv_addr_len = sizeof(serv_addr);
- err = ms_ipc_wait_message(sockfd, &recv_msg, sizeof(recv_msg), &serv_addr, NULL);
- if (err != MS_MEDIA_ERR_NONE) {
- ret = err;
- close(sockfd);
+
+ scanner_status = recv_msg.msg_type;
+ if (scanner_status == MS_MSG_SCANNER_READY) {
+ MS_DBG_ERR("SCANNER is ready");
+ scanner_ready = true;
+ child_pid = pid;
+
+ _ms_add_timeout(30, (GSourceFunc)_ms_stop_scanner, NULL);
+
+ ret = MS_MEDIA_ERR_NONE;
} else {
- int scanner_status = recv_msg.msg_type;
- if (scanner_status == MS_MSG_SCANNER_READY) {
- MS_DBG("RECEIVE OK [%d] %d", recv_msg.msg_type, pid);
- scanner_ready = true;
- child_pid = pid;
-
- /* attach result receiving socket to mainloop */
- res_context = g_main_loop_get_context(mainloop);
-
- /* Create new channel to watch udp socket */
- res_channel = g_io_channel_unix_new(sockfd);
- res_source = g_io_create_watch(res_channel, G_IO_IN);
-
- /* Set callback to be called when socket is readable */
- g_source_set_callback(res_source, (GSourceFunc)ms_receive_message_from_scanner, NULL, NULL);
- receive_id = g_source_attach(res_source, res_context);
- g_source_unref(res_source);
-
- _ms_add_timeout(30, (GSourceFunc)_ms_stop_scanner, res_channel);
-
- ret = MS_MEDIA_ERR_NONE;
- } else {
- MS_DBG_ERR("Receive wrong message from scanner[%d]", scanner_status);
- close(sockfd);
- ret = MS_MEDIA_ERR_SOCKET_RECEIVE;
- }
+ MS_DBG_ERR("SCANNER is not ready");
+ ret = MS_MEDIA_ERR_SCANNER_NOT_READY;
}
+ /*close pipe*/
+ close(fd);
g_mutex_unlock(scanner_mutex);
int ms_get_scanner_pid(void)
{
return child_pid;
-}
\ No newline at end of file
+}
*/
#include <arpa/inet.h>
#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
#ifdef _USE_UDS_SOCKET_
#include <sys/un.h>
#else
#include <errno.h>
#include <malloc.h>
#include <vconf.h>
+#include <security-server.h>
#include "media-util.h"
#include "media-util-internal.h"
#include "media-server-ipc.h"
#include "media-common-utils.h"
#include "media-server-dbg.h"
-#include "media-server-db-svc.h"
#include "media-server-scanner.h"
#include "media-server-socket.h"
-#include "media-server-db.h"
extern GAsyncQueue *scan_queue;
GAsyncQueue* ret_queue;
{
int pid;
int index;
-#ifdef _USE_UDS_SOCKET_
- struct sockaddr_un *client_addr;
-#else
- struct sockaddr_in *client_addr;
-#endif
+ int client_sockfd;
}ms_req_owner_data;
-int _ms_add_owner(ms_req_owner_data *owner_data)
+static int __ms_add_owner(ms_req_owner_data *owner_data)
{
// MS_DBG("the length of array : %d", owner_list->len);
// MS_DBG("pid : %d", owner_data->pid);
return MS_MEDIA_ERR_NONE;
}
-int _ms_find_owner(int pid, ms_req_owner_data **owner_data)
+static int __ms_find_owner(int pid, ms_req_owner_data **owner_data)
{
int i;
int len = owner_list->len;
return MS_MEDIA_ERR_NONE;
}
-int _ms_delete_owner(ms_req_owner_data *owner_data)
+static int __ms_delete_owner(ms_req_owner_data *owner_data)
{
if (owner_data->index != -1) {
g_array_remove_index(owner_list, owner_data->index);
- MS_SAFE_FREE(owner_data->client_addr);
MS_SAFE_FREE(owner_data);
MS_DBG("DELETE OWNER");
}
return MS_MEDIA_ERR_NONE;
}
+static int __ms_privilege_check(const char *msg, gboolean *privilege)
+{
+#define operation_cnt 3
+#define db_table_cnt 5
+
+ int o_idx = 0;
+ int t_idx = 0;
+ gboolean is_privilege = TRUE;
+
+ char *operation[operation_cnt] = {
+ "INSERT INTO ",
+ "DELETE FROM ",
+ "UPDATE "
+ };
+
+ char *db_table[db_table_cnt] = {
+ "playlist_map",
+ "playlist",
+ "tag_map",
+ "tag",
+ "bookmark"
+ };
+
+ if(strlen(msg) < 30) {
+ MS_DBG_ERR("msg is too short!!");
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
+ }
+
+ for(o_idx = 0; o_idx < operation_cnt; o_idx++) {
+ if(strncmp(operation[o_idx], msg, strlen(operation[o_idx])) == 0) {
+ for(t_idx = 0; t_idx < db_table_cnt; t_idx++) {
+ if(strncmp(db_table[t_idx], msg+strlen(operation[o_idx]), strlen(db_table[t_idx])) == 0) {
+ MS_DBG("Non privilege [%s][%s]", operation[o_idx], db_table[t_idx]);
+ is_privilege = FALSE;
+ break;
+ }
+ }
+ break;
+ }
+ }
+
+ *privilege = is_privilege;
+
+ return MS_MEDIA_ERR_NONE;
+}
+
+static int __ms_privilege_ask(int client_sockfd)
+{
+ int ret = 0;
+ int res = MS_MEDIA_ERR_NONE;
+
+ MS_DBG_SLOG("CHECK PERMISSION");
+ ret = security_server_check_privilege_by_sockfd(client_sockfd, "media-data::db", "w");
+ if (ret == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) {
+ MS_DBG_ERR("You do not have permission for this operation.");
+ res = MS_MEDIA_ERR_PERMISSION_DENIED;
+ } else {
+ MS_DBG_SLOG("PERMISSION OK");
+ }
+
+ return res;
+}
+
gboolean ms_read_socket(GIOChannel *src, GIOCondition condition, gpointer data)
{
#ifdef _USE_UDS_SOCKET_
- struct sockaddr_un *client_addr = NULL;
+ struct sockaddr_un client_addr;
#else
- struct sockaddr_in *client_addr = NULL;
+ struct sockaddr_in client_addr;
#endif
socklen_t client_addr_len;
ms_comm_msg_s recv_msg;
int msg_size;
int sockfd = MS_SOCK_NOT_ALLOCATE;
int ret;
+ int res;
int pid;
int req_num;
int path_size;
+ int client_sock = -1;
+ int recv_msg_size = 0;
g_mutex_lock(scanner_mutex);
return TRUE;
}
- /* Socket is readable */
-#ifdef _USE_UDS_SOCKET_
- MS_MALLOC(client_addr, sizeof(struct sockaddr_un));
-#else
- MS_MALLOC(client_addr, sizeof(struct sockaddr_in));
-#endif
- if (client_addr == NULL) {
- MS_DBG_ERR("malloc failed");
- g_mutex_unlock(scanner_mutex);
- return TRUE;
- }
#ifdef _USE_UDS_SOCKET_
client_addr_len = sizeof(struct sockaddr_un);
#else
client_addr_len = sizeof(struct sockaddr_in);
#endif
- ret = ms_ipc_receive_message(sockfd, &recv_msg, sizeof(recv_msg), client_addr, NULL);
- if (ret != MS_MEDIA_ERR_NONE) {
- MS_DBG_ERR("ms_ipc_receive_message failed");
- MS_SAFE_FREE(client_addr);
+
+ if ((client_sock = accept(sockfd, (struct sockaddr*)&client_addr, &client_addr_len)) < 0) {
+ MS_DBG_ERR("accept failed : %s", strerror(errno));
g_mutex_unlock(scanner_mutex);
return TRUE;
}
+ if ((recv_msg_size = read(client_sock, &recv_msg, sizeof(ms_comm_msg_s))) < 0) {
+ if (errno == EWOULDBLOCK) {
+ MS_DBG_ERR("Timeout. Can't try any more");
+ res = MS_MEDIA_ERR_SOCKET_RECEIVE_TIMEOUT;
+ goto ERROR;
+ } else {
+ MS_DBG_ERR("recv failed : %s", strerror(errno));
+ res = MS_MEDIA_ERR_SOCKET_RECEIVE;
+ goto ERROR;
+ }
+ }
+
+ ret = __ms_privilege_ask(client_sock);
+ if (ret == MS_MEDIA_ERR_PERMISSION_DENIED) {
+ res = MS_MEDIA_ERR_PERMISSION_DENIED;
+ goto ERROR;
+ }
+
MS_DBG("receive msg from [%d] %d, %s", recv_msg.pid, recv_msg.msg_type, recv_msg.msg);
if (recv_msg.msg_size > 0 && recv_msg.msg_size < MS_FILE_PATH_LEN_MAX) {
path_size = msg_size + 1;
} else {
/*NEED IMPLEMETATION*/
- MS_SAFE_FREE(client_addr);
- g_mutex_unlock(scanner_mutex);
- return TRUE;
+ res = MS_MEDIA_ERR_INVALID_IPC_MESSAGE;
+ goto ERROR;
}
/* copy received data */
owner_list = g_array_new (FALSE, FALSE, sizeof (ms_req_owner_data *));
if (owner_list == NULL) {
MS_DBG_ERR("g_array_new error");
- MS_SAFE_FREE(client_addr);
- g_mutex_unlock(scanner_mutex);
- return TRUE;
+ res = MS_MEDIA_ERR_ALLOCATE_MEMORY_FAIL;
+ goto ERROR;
}
}
/* store pid and client address */
MS_MALLOC(owner_data, sizeof(ms_req_owner_data));
owner_data->pid = recv_msg.pid;
- owner_data->client_addr = client_addr;
+ owner_data->client_sockfd = client_sock;
- _ms_add_owner(owner_data);
+ __ms_add_owner(owner_data);
/* create send message for media scanner */
scan_msg.msg_type = req_num;
MS_DBG("Scanner starting failed. %d", ret);
}
}
- } else {
- /* NEED IMPLEMENTATION */
- MS_SAFE_FREE(client_addr);
- g_mutex_unlock(scanner_mutex);
- }
-
- /*Active flush */
- malloc_trim(0);
-
- return TRUE;
-}
-gboolean ms_receive_message_from_scanner(GIOChannel *src, GIOCondition condition, gpointer data)
-{
- ms_comm_msg_s recv_msg;
- int sockfd = MS_SOCK_NOT_ALLOCATE;
- int msg_type;
- int ret;
-
- sockfd = g_io_channel_unix_get_fd(src);
- if (sockfd < 0) {
- MS_DBG_ERR("sock fd is invalid!");
- return TRUE;
- }
-
- /* Socket is readable */
- ret = ms_ipc_receive_message(sockfd, &recv_msg, sizeof(recv_msg), NULL, NULL);
- if (ret != MS_MEDIA_ERR_NONE) {
- MS_DBG_ERR("ms_ipc_receive_message failed [%s]", strerror(errno));
- return TRUE;
- }
-
- MS_DBG("receive msg from [%d] %d, %s", recv_msg.pid, recv_msg.msg_type, recv_msg.msg);
-
- msg_type = recv_msg.msg_type;
- if ((msg_type == MS_MSG_SCANNER_RESULT) ||
- (msg_type == MS_MSG_SCANNER_BULK_RESULT)) {
+ } else if ((req_num == MS_MSG_SCANNER_RESULT) ||
+ (req_num == MS_MSG_SCANNER_BULK_RESULT)) {
if (owner_list != NULL) {
/* If the owner of result message is not media-server, media-server notify to the owner */
/* The owner of message is distingushied by pid in received message*/
/* find owner data */
ms_req_owner_data *owner_data = NULL;
- _ms_find_owner(recv_msg.pid, &owner_data);
+ __ms_find_owner(recv_msg.pid, &owner_data);
if (owner_data != NULL) {
MS_DBG("PID : %d", owner_data->pid);
- if (msg_type == MS_MSG_SCANNER_RESULT) {
+ if (req_num == MS_MSG_SCANNER_RESULT) {
MS_DBG("DIRECTORY SCANNING IS DONE");
}
/* owner data exists */
/* send result to the owner of request */
- ms_ipc_send_msg_to_client(sockfd, &recv_msg, owner_data->client_addr);
+ ms_ipc_send_msg_to_client_tcp(owner_data->client_sockfd, &recv_msg, NULL);
+ close(owner_data->client_sockfd);
/* free owner data*/
- _ms_delete_owner(owner_data);
+ __ms_delete_owner(owner_data);
}
} else {
/* owner data does not exist*/
/* this is result of request of media server*/
}
+ close(client_sock);
+ g_mutex_unlock(scanner_mutex);
} else {
- MS_DBG_ERR("This result message is wrong : %d", recv_msg.msg_type );
+ /* NEED IMPLEMENTATION */
+ close(client_sock);
+ g_mutex_unlock(scanner_mutex);
+ }
+
+ /*Active flush */
+ malloc_trim(0);
+
+ return TRUE;
+ERROR:
+ {
+ ms_comm_msg_s res_msg;
+
+ memset(&res_msg, 0x0, sizeof(ms_comm_msg_s));
+
+ if (req_num == MS_MSG_DIRECTORY_SCANNING
+ ||req_num == MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE) {
+ res_msg.msg_type = MS_MSG_SCANNER_RESULT;
+ } else if (req_num == MS_MSG_BULK_INSERT
+ || req_num == MS_MSG_BURSTSHOT_INSERT) {
+ res_msg.msg_type = MS_MSG_SCANNER_BULK_RESULT;
+ }
+
+ res_msg.result = res;
+
+ ms_ipc_send_msg_to_client_tcp(client_sock, &res_msg, NULL);
+ close(client_sock);
+
+ g_mutex_unlock(scanner_mutex);
}
return TRUE;
int ms_send_scan_request(ms_comm_msg_s *send_msg)
{
- int ret;
int res = MS_MEDIA_ERR_NONE;
- int sockfd = -1;
+ int fd = -1;
+ int err = -1;
- /*Create Socket*/
-#ifdef _USE_UDS_SOCKET_
- ret = ms_ipc_create_client_socket(MS_PROTOCOL_UDP, 0, &sockfd, MS_SCAN_DAEMON_PORT);
-#else
- ret = ms_ipc_create_client_socket(MS_PROTOCOL_UDP, 0, &sockfd);
-#endif
- if (ret != MS_MEDIA_ERR_NONE)
- return MS_MEDIA_ERR_SOCKET_CONN;
+ fd = open(MS_SCANNER_FIFO_PATH_REQ, O_WRONLY);
+ if (fd < 0) {
+ MS_DBG_ERR("fifo open failed [%s]", strerror(errno));
+ return MS_MEDIA_ERR_FILE_OPEN_FAIL;
+ }
- ret = ms_ipc_send_msg_to_server(sockfd, MS_SCAN_DAEMON_PORT, send_msg, NULL);
- if (ret != MS_MEDIA_ERR_NONE)
- res = ret;
+ /* send message */
+ err = write(fd, send_msg, sizeof(ms_comm_msg_s));
+ if (err < 0) {
+ MS_DBG_ERR("fifo write failed [%s]", strerror(errno));
+ close(fd);
+ return MS_MEDIA_ERR_FILE_READ_FAIL;
+ }
- close(sockfd);
+ close(fd);
return res;
}
return ret;
}
-gboolean ms_read_db_socket(GIOChannel *src, GIOCondition condition, gpointer data)
+gboolean ms_read_db_tcp_socket(GIOChannel *src, GIOCondition condition, gpointer data)
{
#ifdef _USE_UDS_SOCKET_
struct sockaddr_un client_addr;
#else
struct sockaddr_in client_addr;
#endif
-
+ int sock = -1;
+ int client_sock = -1;
+ int recv_msg_size = -1;
+ char * sql_query = NULL;
ms_comm_msg_s recv_msg;
- int send_msg = MS_MEDIA_ERR_NONE;
- int sockfd = MS_SOCK_NOT_ALLOCATE;
+ unsigned int client_addr_len;
int ret = MS_MEDIA_ERR_NONE;
MediaDBHandle *db_handle = (MediaDBHandle *)data;
- ms_comm_msg_s msg;
- char * sql_query = NULL;
-
- memset(&recv_msg, 0, sizeof(recv_msg));
+ int send_msg = MS_MEDIA_ERR_NONE;
+ gboolean privilege = TRUE;
- sockfd = g_io_channel_unix_get_fd(src);
- if (sockfd < 0) {
+ sock = g_io_channel_unix_get_fd(src);
+ if (sock < 0) {
MS_DBG_ERR("sock fd is invalid!");
return TRUE;
}
- ret = ms_ipc_receive_message(sockfd, &recv_msg, sizeof(recv_msg), &client_addr, NULL);
- if (ret != MS_MEDIA_ERR_NONE) {
- MS_DBG_ERR("ms_ipc_receive_message failed");
+ if ((client_sock = accept(sock, (struct sockaddr*)&client_addr, &client_addr_len)) < 0) {
+ MS_DBG_ERR("accept failed : %s", strerror(errno));
return TRUE;
}
-// MS_DBG("msg_type[%d], msg_size[%d] msg[%s]", recv_msg.msg_type, recv_msg.msg_size, recv_msg.msg);
+ if ((recv_msg_size = read(client_sock, &recv_msg, sizeof(ms_comm_msg_s))) < 0) {
+ if (errno == EWOULDBLOCK) {
+ MS_DBG_ERR("Timeout. Can't try any more");
+ send_msg = MS_MEDIA_ERR_SOCKET_RECEIVE_TIMEOUT;
+ goto ERROR;
+ } else {
+ MS_DBG_ERR("recv failed : %s", strerror(errno));
+ send_msg = MS_MEDIA_ERR_SOCKET_RECEIVE;
+ goto ERROR;
+ }
+ }
- if((recv_msg.msg_size <= 0) ||(recv_msg.msg_size > MS_FILE_PATH_LEN_MAX) || (!MS_STRING_VALID(recv_msg.msg))) {
+ if((recv_msg.msg_size <= 0) ||(recv_msg.msg_size > MAX_MSG_SIZE) || (!MS_STRING_VALID(recv_msg.msg))) {
MS_DBG_ERR("invalid query. size[%d]", recv_msg.msg_size);
- return TRUE;
+ send_msg = MS_MEDIA_ERR_SOCKET_RECEIVE;
+ goto ERROR;
+ }
+
+ /* check privileage */
+ if(__ms_privilege_check(recv_msg.msg, &privilege) != MS_MEDIA_ERR_NONE) {
+ MS_DBG_ERR("invalid query. size[%d]", recv_msg.msg_size);
+ send_msg = MS_MEDIA_ERR_SOCKET_RECEIVE;
+ goto ERROR;
+ }
+
+ if (privilege == TRUE) {
+ MS_DBG_SLOG("NEED CHECKING PERMISSION");
+ ret = __ms_privilege_ask(client_sock);
+ if (ret == MS_MEDIA_ERR_PERMISSION_DENIED) {
+ send_msg = MS_MEDIA_ERR_PERMISSION_DENIED;
+ goto ERROR;
+ }
}
sql_query = strndup(recv_msg.msg, recv_msg.msg_size);
send_msg = MS_MEDIA_ERR_ALLOCATE_MEMORY_FAIL;
}
- memset(&msg, 0x0, sizeof(ms_comm_msg_s));
- msg.result = send_msg;
-
- ms_ipc_send_msg_to_client(sockfd, &msg, &client_addr);
+ERROR:
+ if (write(client_sock, &send_msg, sizeof(send_msg)) != sizeof(send_msg)) {
+ MS_DBG_ERR("send failed : %s", strerror(errno));
+ } else {
+ MS_DBG("Sent successfully");
+ }
- /*Active flush */
- malloc_trim(0);
+ if (close(client_sock) <0) {
+ MS_DBG_ERR("close failed [%s]", strerror(errno));
+ }
return TRUE;
}
-gboolean ms_read_db_tcp_socket(GIOChannel *src, GIOCondition condition, gpointer data)
-{
-#ifdef _USE_UDS_SOCKET_
- struct sockaddr_un client_addr;
-#elif defined(_USE_UDS_SOCKET_TCP_)
- struct sockaddr_un client_addr;
-#else
- struct sockaddr_in client_addr;
-#endif
- unsigned int client_addr_len;
- ms_comm_msg_s recv_msg;
- int sock = -1;
- int client_sock = -1;
- int send_msg = MS_MEDIA_ERR_NONE;
- int recv_msg_size = -1;
+gboolean _ms_process_tcp_message(void *data)
+{
int ret = MS_MEDIA_ERR_NONE;
+ int recv_msg_size = -1;
char * sql_query = NULL;
- MediaDBHandle *db_handle = (MediaDBHandle *)data;
+ ms_comm_msg_s recv_msg;
+ int client_sock = GPOINTER_TO_INT (data);
+ int send_msg = MS_MEDIA_ERR_NONE;
+ MediaDBHandle *db_handle = NULL;
- sock = g_io_channel_unix_get_fd(src);
- if (sock < 0) {
- MS_DBG_ERR("sock fd is invalid!");
- return TRUE;
- }
memset((void *)&recv_msg, 0, sizeof(ms_comm_msg_s));
- if ((client_sock = accept(sock, (struct sockaddr*)&client_addr, &client_addr_len)) < 0) {
- MS_DBG_ERR("accept failed : %s", strerror(errno));
- return TRUE;
+ /* Connect Media DB*/
+ if(media_db_connect(&db_handle) != MS_MEDIA_ERR_NONE) {
+ MS_DBG_ERR("Failed to connect DB");
+ return FALSE;
}
- MS_DBG("Client[%d] is accepted", client_sock);
+ MS_DBG_ERR("client sokcet : %d", client_sock);
while(1) {
- if ((recv_msg_size = recv(client_sock, &recv_msg, sizeof(ms_comm_msg_s), 0)) < 0) {
+ MS_DBG("_________________________________ WAIT MESSAGE _________________________________");
+ if ((recv_msg_size = read(client_sock, &recv_msg, sizeof(ms_comm_msg_s))) < 0) {
MS_DBG_ERR("recv failed : %s", strerror(errno));
+ if (errno == EINTR) {
+ MS_DBG_ERR("interrupt system call but wait next message");
+ continue;
+ }
- close(client_sock);
+ media_db_request_update_db_batch_clear();
if (errno == EWOULDBLOCK) {
MS_DBG_ERR("Timeout. Can't try any more");
- return MS_MEDIA_ERR_SOCKET_RECEIVE_TIMEOUT;
+ break;
} else {
MS_DBG_ERR("recv failed : %s", strerror(errno));
- return MS_MEDIA_ERR_SOCKET_RECEIVE;
+ break;
}
}
-// MS_DBG("Received [%d](%d) [%s]", recv_msg.msg_type, recv_msg.msg_size, recv_msg.msg);
+ MS_DBG_SLOG("(%d)Received [%d] [%s]", recv_msg.pid, recv_msg.msg_type, recv_msg.msg);
- if((recv_msg.msg_size <= 0) ||(recv_msg.msg_size > MS_FILE_PATH_LEN_MAX) || (!MS_STRING_VALID(recv_msg.msg))) {
+ //if((recv_msg.msg_size <= 0) ||(recv_msg.msg_size > MS_FILE_PATH_LEN_MAX) || (!MS_STRING_VALID(recv_msg.msg))) {
+ if((recv_msg.msg_size <= 0) ||(recv_msg.msg_size > MAX_MSG_SIZE) || (!MS_STRING_VALID(recv_msg.msg))) {
MS_DBG_ERR("invalid query. size[%d]", recv_msg.msg_size);
MS_DBG_ERR("Received [%d](%d) [%s]", recv_msg.msg_type, recv_msg.msg_size, recv_msg.msg);
- close(client_sock);
- return TRUE;
+ MS_DBG_ERR("client sokcet : %d", client_sock);
+ media_db_request_update_db_batch_clear();
+ break;
}
sql_query = strndup(recv_msg.msg, recv_msg.msg_size);
MS_SAFE_FREE(sql_query);
send_msg = ret;
- if (send(client_sock, &send_msg, sizeof(send_msg), 0) != sizeof(send_msg)) {
+ if (write(client_sock, &send_msg, sizeof(send_msg)) != sizeof(send_msg)) {
MS_DBG_ERR("send failed : %s", strerror(errno));
} else {
MS_DBG("Sent successfully");
}
- if (recv_msg.msg_type == MS_MSG_DB_UPDATE_BATCH_END)
+ MS_DBG_ERR("client sokcet : %d", client_sock);
+ if (recv_msg.msg_type == MS_MSG_DB_UPDATE_BATCH_END) {
+ MS_DBG_WARN("Batch job is successfull!");
+ MS_DBG_ERR("client sokcet : %d", client_sock);
break;
+ }
+
+ if (ret < MS_MEDIA_ERR_NONE && recv_msg.msg_type == MS_MSG_DB_UPDATE_BATCH_START) {
+ MS_DBG_ERR("Batch job start is failed!");
+ MS_DBG_ERR("client sokcet : %d", client_sock);
+ media_db_request_update_db_batch_clear();
+ break;
+ }
memset((void *)&recv_msg, 0, sizeof(ms_comm_msg_s));
} else {
MS_DBG_ERR("MS_MALLOC failed");
- close(client_sock);
- return TRUE;
+ media_db_request_update_db_batch_clear();
+ break;
}
}
- close(client_sock);
+ if (close(client_sock) <0) {
+ MS_DBG_ERR("close failed [%s]", strerror(errno));
+ }
+
+ /* Disconnect DB*/
+ media_db_disconnect(db_handle);
+
+ g_thread_exit(0);
+}
+
+gboolean ms_read_db_tcp_batch_socket(GIOChannel *src, GIOCondition condition, gpointer data)
+{
+#ifdef _USE_UDS_SOCKET_
+ struct sockaddr_un client_addr;
+#else
+ struct sockaddr_in client_addr;
+#endif
+ unsigned int client_addr_len;
+
+ int sock = -1;
+ int client_sock = -1;
+
+ sock = g_io_channel_unix_get_fd(src);
+ if (sock < 0) {
+ MS_DBG_ERR("sock fd is invalid!");
+ return TRUE;
+ }
+
+ if ((client_sock = accept(sock, (struct sockaddr*)&client_addr, &client_addr_len)) < 0) {
+ MS_DBG_ERR("accept failed : %s", strerror(errno));
+ media_db_request_update_db_batch_clear();
+ return TRUE;
+ }
+
+ MS_DBG_SLOG("Client[%d] is accepted", client_sock);
+
+ g_thread_new("message_thread", (GThreadFunc)_ms_process_tcp_message, GINT_TO_POINTER(client_sock));
+
return TRUE;
}
static GIOChannel *g_udp_channel = NULL;
static gboolean g_folk_thumb_server = FALSE;
static gboolean g_thumb_server_extracting = FALSE;
+static gboolean g_shutdowning_thumb_server = FALSE;
+static gboolean g_thumb_server_queued_all_extracting_request = FALSE;
static int g_communicate_sock = 0;
static int g_timer_id = 0;
static int g_server_pid = 0;
extern char MEDIA_IPC_PATH[][50];
#endif
+gboolean _ms_thumb_check_queued_request(gpointer data);
+
gboolean _ms_thumb_agent_start_jobs(gpointer data)
{
MS_DBG("");
void ms_thumb_reset_server_status()
{
g_folk_thumb_server = FALSE;
+ g_shutdowning_thumb_server = FALSE;
if (g_timer_id > 0) {
g_source_destroy(g_main_context_find_source_by_id(g_main_context_get_thread_default(), g_timer_id));
#ifdef _USE_UDS_SOCKET_
if ((sock_fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
-#elif defined(_USE_UDS_SOCKET_TCP_)
- if ((sock_fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
#else
if ((sock_fd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
#endif
org_path_len = strlen(req_msg->org_path) + 1;
dst_path_len = strlen(req_msg->dst_path) + 1;
- //MS_DBG("Basic Size : %d, org_path : %s[%d], dst_path : %s[%d]", header_size, req_msg->org_path, org_path_len, req_msg->dst_path, dst_path_len);
+ MS_DBG("Basic Size : %d, org_path : %s[%d], dst_path : %s[%d]", header_size, req_msg->org_path, org_path_len, req_msg->dst_path, dst_path_len);
size = header_size + org_path_len + dst_path_len;
*buf = malloc(size);
{
int sockfd = -1;
+ /* Once all-thumb extraction is done, check if there is queued all-thumb request */
+ GSource *check_queued_all_thumb_request = NULL;
+ check_queued_all_thumb_request = g_idle_source_new ();
+ g_source_set_callback (check_queued_all_thumb_request, _ms_thumb_check_queued_request, NULL, NULL);
+ g_source_attach (check_queued_all_thumb_request, g_main_context_get_thread_default());
+
+ if (g_thumb_server_extracting == FALSE) {
+ MS_DBG_WARN("Recv thumb server extracting done already");
+ return FALSE;
+ }
+
sockfd = g_io_channel_unix_get_fd(src);
if (sockfd < 0) {
MS_DBG_ERR("sock fd is invalid!");
ms_thumb_server_msg recv_msg;
int recv_msg_size = 0;
+ MS_DBG_ERR("THUMB SERVER SOCKET %d", sockfd);
+
recv_msg_size = ms_ipc_receive_message(sockfd, &recv_msg, sizeof(ms_thumb_server_msg), NULL, NULL);
if (recv_msg_size != MS_MEDIA_ERR_NONE) {
MS_DBG_ERR("ms_ipc_receive_message failed : %s\n", strerror(errno));
return FALSE;
}
+gboolean _ms_thumb_check_queued_request(gpointer data)
+{
+ if (g_thumb_server_queued_all_extracting_request) {
+ MS_DBG_WARN("There is queued request");
+
+ /* request all-thumb extraction to thumbnail server */
+ thumbMsg msg;
+ thumbMsg recv_msg;
+ memset((void *)&msg, 0, sizeof(msg));
+ memset((void *)&recv_msg, 0, sizeof(recv_msg));
+
+ msg.msg_type = 2; // THUMB_REQUEST_ALL_MEDIA
+ msg.org_path[0] = '\0';
+ msg.origin_path_size = 1;
+ msg.dst_path[0] = '\0';
+ msg.dest_path_size = 1;
+
+ /* Command All-thumb extraction to thumbnail server */
+ if (!_ms_thumb_agent_send_msg_to_thumb_server(&msg, &recv_msg)) {
+ MS_DBG_ERR("_ms_thumb_agent_send_msg_to_thumb_server is failed");
+ }
+
+ g_thumb_server_queued_all_extracting_request = FALSE;
+ } else {
+ MS_DBG("There is no queued request");
+ return FALSE;
+ }
+
+ return FALSE;
+}
+
gboolean _ms_thumb_agent_execute_server()
{
int pid;
gboolean _ms_thumb_agent_send_msg_to_thumb_server(thumbMsg *recv_msg, thumbMsg *res_msg)
{
int sock;
- const char *serv_ip = "127.0.0.1";
#ifdef _USE_UDS_SOCKET_
+ ms_sock_info_s sock_info;
struct sockaddr_un serv_addr;
#else
+ const char *serv_ip = "127.0.0.1";
struct sockaddr_in serv_addr;
#endif
}
#endif
#ifdef _USE_UDS_SOCKET_
- if (ms_ipc_create_client_socket(MS_PROTOCOL_UDP, MS_TIMEOUT_SEC_10, &sock, MS_THUMB_DAEMON_PORT) < 0) {
+ if (ms_ipc_create_client_socket(MS_PROTOCOL_UDP, MS_TIMEOUT_SEC_10, &sock_info) < 0) {
#else
if (ms_ipc_create_client_socket(MS_PROTOCOL_UDP, MS_TIMEOUT_SEC_10, &sock) < 0) {
#endif
memset(&serv_addr, 0, sizeof(serv_addr));
#ifdef _USE_UDS_SOCKET_
+ sock = sock_info.sock_fd;
serv_addr.sun_family = AF_UNIX;
MS_DBG("%s", MEDIA_IPC_PATH[MS_THUMB_DAEMON_PORT]);
strcpy(serv_addr.sun_path, MEDIA_IPC_PATH[MS_THUMB_DAEMON_PORT]);
if (sendto(sock, buf, buf_size, 0, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) != buf_size) {
MS_DBG_ERR("sendto failed: %s\n", strerror(errno));
MS_SAFE_FREE(buf);
+#ifdef _USE_UDS_SOCKET_
+ ms_ipc_delete_client_socket(&sock_info);
+#else
close(sock);
+#endif
return FALSE;
}
if (_ms_thumb_recv_udp_msg(sock, header_size, res_msg, &client_addr, &client_addr_len) < 0) {
MS_DBG_ERR("_ms_thumb_recv_udp_msg failed");
+#ifdef _USE_UDS_SOCKET_
+ ms_ipc_delete_client_socket(&sock_info);
+#else
close(sock);
+#endif
return FALSE;
}
MS_DBG("recv %s from thumb daemon is successful", res_msg->dst_path);
- close(sock);
+#ifdef _USE_UDS_SOCKET_
+ ms_ipc_delete_client_socket(&sock_info);
+#else
+ close(sock);
+#endif
if (res_msg->msg_type == 2 && g_communicate_sock > 0) { // THUMB_REQUEST_ALL_MEDIA
/* Create new channel to watch udp socket */
msg.dest_path_size = 1;
/* Command Kill to thumbnail server */
+ g_shutdowning_thumb_server = TRUE;
if (!_ms_thumb_agent_send_msg_to_thumb_server(&msg, &recv_msg)) {
MS_DBG_ERR("_ms_thumb_agent_send_msg_to_thumb_server is failed");
+ g_shutdowning_thumb_server = FALSE;
}
#endif
usleep(200000);
+
} else {
MS_DBG_ERR("g_server_pid is %d. Maybe there's problem in thumbnail-server", g_server_pid);
}
return FALSE;
}
+ if (g_shutdowning_thumb_server) {
+ MS_DBG_ERR("Thumb server is shutting down... wait for complete");
+ usleep(10000);
+ return TRUE;
+ }
+
if (g_folk_thumb_server == FALSE && g_thumb_server_extracting == FALSE) {
if(_ms_thumb_check_process() == FALSE) { // This logic is temporary
MS_DBG_WARN("Thumb server is not running.. so start it");
}
if (recv_msg) {
- if (!_ms_thumb_agent_send_msg_to_thumb_server(recv_msg, &res_msg)) {
- MS_DBG_ERR("_ms_thumb_agent_send_msg_to_thumb_server is failed");
+ if (recv_msg->msg_type == 2 && g_thumb_server_extracting) { // THUMB_REQUEST_ALL_MEDIA
+ MS_DBG_WARN("Thumbnail server is already extracting..This request is queued.");
+ g_thumb_server_queued_all_extracting_request = TRUE;
+ } else {
+ if (!_ms_thumb_agent_send_msg_to_thumb_server(recv_msg, &res_msg)) {
+ MS_DBG_ERR("_ms_thumb_agent_send_msg_to_thumb_server is failed");
- close(client_sock);
- MS_SAFE_FREE(req->recv_msg);
- MS_SAFE_FREE(req);
- return TRUE;
+ close(client_sock);
+ MS_SAFE_FREE(req->recv_msg);
+ MS_SAFE_FREE(req);
+ return TRUE;
+ }
}
} else {
MS_DBG_ERR("recv_msg is NULL from queue request");
{
#ifdef _USE_UDS_SOCKET_
struct sockaddr_un client_addr;
-#elif defined(_USE_UDS_SOCKET_TCP_)
- struct sockaddr_un client_addr;
#else
struct sockaddr_in client_addr;
#endif
int sock;
unsigned short serv_port;
-#ifdef _USE_UDS_SOCKET_TCP_
- serv_port = MS_THUMB_CREATOR_TCP_PORT;
-#else
serv_port = MS_THUMB_CREATOR_PORT;
-#endif
#if 0
#ifdef _USE_UDS_SOCKET_
MS_DBG("Listening...");
#endif
-
-#ifdef _USE_UDS_SOCKET_TCP_
- if (ms_ipc_create_server_tcp_socket(MS_PROTOCOL_TCP, serv_port, &sock) < 0) {
-#else
if (ms_ipc_create_server_socket(MS_PROTOCOL_TCP, serv_port, &sock) < 0) {
-#endif
MS_DBG_ERR("_ms_thumb_create_socket failed");
return FALSE;
}