summaryrefslogtreecommitdiff
path: root/server/thumb-server-internal.c
diff options
context:
space:
mode:
authorMinje Ahn <minje.ahn@samsung.com>2019-09-16 02:43:26 (GMT)
committerMinje Ahn <minje.ahn@samsung.com>2019-09-16 05:54:10 (GMT)
commitae9e34e2114f65b9f2cf5af8b9297d5c45ff0673 (patch)
tree9e6c684710546a408d3d91859e216fd3445a1758 /server/thumb-server-internal.c
parente00db9e711125bb169a49c46456ad7083cb243d2 (diff)
downloadlibmedia-thumbnail-ae9e34e2114f65b9f2cf5af8b9297d5c45ff0673.zip
libmedia-thumbnail-ae9e34e2114f65b9f2cf5af8b9297d5c45ff0673.tar.gz
libmedia-thumbnail-ae9e34e2114f65b9f2cf5af8b9297d5c45ff0673.tar.bz2
Change-Id: I89af900ba9477a68632482e7960683949df37107 Signed-off-by: Minje Ahn <minje.ahn@samsung.com>
Diffstat (limited to 'server/thumb-server-internal.c')
-rwxr-xr-xserver/thumb-server-internal.c136
1 files changed, 53 insertions, 83 deletions
diff --git a/server/thumb-server-internal.c b/server/thumb-server-internal.c
index 6249387..79c2a80 100755
--- a/server/thumb-server-internal.c
+++ b/server/thumb-server-internal.c
@@ -40,17 +40,51 @@
#define THUMB_COMM_SOCK_PATH tzplatform_mkpath(TZ_SYS_RUN, "media-server/media_ipc_thumbcomm.socket")
#define THUMB_EMPTY_STR ""
-GMainLoop *g_thumb_server_mainloop; // defined in thumb-server.c as extern
+static void __thumb_server_send_deny_message(int sockfd)
+{
+ thumbMsg msg = {0};
-static gboolean __thumb_server_send_msg_to_agent(int msg_type);
-static gboolean _thumb_server_send_deny_message(int sockfd);
+ msg.msg_type = THUMB_RESPONSE;
+ msg.status = MS_MEDIA_ERR_PERMISSION_DENIED;
+
+ if (send(sockfd, &msg, sizeof(msg), 0) < 0)
+ thumb_stderror("send failed");
+}
gboolean _thumb_daemon_start_jobs(gpointer data)
{
- thumb_dbg("");
- __thumb_server_send_msg_to_agent(MS_MSG_THUMB_SERVER_READY);
+ int client_sock;
+ struct sockaddr_un serv_addr;
+ ms_thumb_server_msg send_msg;
+
+ if (ms_ipc_create_client_socket(MS_TIMEOUT_SEC_10, &client_sock) < 0) {
+ thumb_err("ms_ipc_create_server_socket failed");
+ return G_SOURCE_REMOVE;
+ }
+
+ memset(&serv_addr, 0, sizeof(serv_addr));
+
+ serv_addr.sun_family = AF_UNIX;
+ SAFE_STRLCPY(serv_addr.sun_path, THUMB_COMM_SOCK_PATH, sizeof(serv_addr.sun_path));
+
+ /* Connecting to the thumbnail server */
+ if (connect(client_sock, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) < 0) {
+ thumb_stderror("connect");
+ goto ERROR;
+ }
- return FALSE;
+ send_msg.msg_type = MS_MSG_THUMB_SERVER_READY;
+
+ if (send(client_sock, &send_msg, sizeof(ms_thumb_server_msg), 0) < 0) {
+ thumb_stderror("send failed");
+ goto ERROR;
+ }
+
+ thumb_dbg("Sending msg to thumbnail agent[%d] is successful", send_msg.msg_type);
+ERROR:
+ close(client_sock);
+
+ return G_SOURCE_REMOVE;
}
int _thumb_daemon_process_job(thumbMsg *req_msg, thumbMsg *res_msg)
@@ -77,6 +111,7 @@ gboolean _thumb_server_read_socket(GIOChannel *src, GIOCondition condition, gpoi
thumbMsg recv_msg;
thumbMsg res_msg;
ms_peer_credentials credentials;
+ GMainLoop *thumb_server = (GMainLoop *)data;
int sock = -1;
int client_sock = -1;
@@ -86,36 +121,30 @@ gboolean _thumb_server_read_socket(GIOChannel *src, GIOCondition condition, gpoi
memset((void *)&credentials, 0, sizeof(credentials));
sock = g_io_channel_unix_get_fd(src);
- if (sock < 0) {
- thumb_err("sock fd is invalid!");
- return TRUE;
- }
+ thumb_retvm_if(sock < 0, G_SOURCE_CONTINUE, "sock fd is invalid!");
client_addr_len = sizeof(client_addr);
if ((client_sock = accept(sock, (struct sockaddr*)&client_addr, &client_addr_len)) < 0) {
thumb_stderror("accept failed");
- return TRUE;
+ return G_SOURCE_CONTINUE;
}
if (ms_cynara_receive_untrusted_message_thumb(client_sock, &recv_msg, &credentials) != MS_MEDIA_ERR_NONE) {
thumb_err("ms_cynara_receive_untrusted_message_thumb failed");
- close(client_sock);
- return FALSE;
+ goto ERROR;
}
if (recv_msg.msg_type != THUMB_REQUEST_KILL_SERVER) {
if (ms_cynara_check(&credentials, MEDIA_STORAGE_PRIVILEGE) != MS_MEDIA_ERR_NONE) {
thumb_err("Cynara denied access to process request");
- _thumb_server_send_deny_message(client_sock);
- close(client_sock);
- return TRUE;
+ __thumb_server_send_deny_message(client_sock);
+ goto ERROR;
}
} else {
thumb_warn("Shutting down...");
- g_main_loop_quit(g_thumb_server_mainloop);
- close(client_sock);
- return TRUE;
+ g_main_loop_quit(thumb_server);
+ goto ERROR;
}
SAFE_FREE(credentials.smack);
@@ -152,62 +181,10 @@ gboolean _thumb_server_read_socket(GIOChannel *src, GIOCondition condition, gpoi
SAFE_FREE(buf);
SAFE_FREE(res_msg.thumb_data);
+ERROR:
close(client_sock);
- return TRUE;
-}
-
-static gboolean __thumb_server_send_msg_to_agent(int msg_type)
-{
- int sock;
- struct sockaddr_un serv_addr;
- ms_thumb_server_msg send_msg;
-
- if (ms_ipc_create_client_socket(MS_TIMEOUT_SEC_10, &sock) < 0) {
- thumb_err("ms_ipc_create_server_socket failed");
- return FALSE;
- }
-
- memset(&serv_addr, 0, sizeof(serv_addr));
-
- serv_addr.sun_family = AF_UNIX;
- SAFE_STRLCPY(serv_addr.sun_path, THUMB_COMM_SOCK_PATH, sizeof(serv_addr.sun_path));
-
- /* Connecting to the thumbnail server */
- if (connect(sock, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) < 0) {
- thumb_stderror("connect");
- close(sock);
- return MS_MEDIA_ERR_SOCKET_CONN;
- }
-
- send_msg.msg_type = msg_type;
-
- if (send(sock, &send_msg, sizeof(ms_thumb_server_msg), 0) < 0) {
- thumb_stderror("send failed");
- close(sock);
- return FALSE;
- }
-
- thumb_dbg("Sending msg to thumbnail agent[%d] is successful", send_msg.msg_type);
- close(sock);
-
- return TRUE;
-}
-
-static gboolean _thumb_server_send_deny_message(int sockfd)
-{
- thumbMsg msg = {0};
- int bytes_to_send = sizeof(msg);
-
- msg.msg_type = THUMB_RESPONSE;
- msg.status = MS_MEDIA_ERR_PERMISSION_DENIED;
-
- if (send(sockfd, &msg, bytes_to_send, 0) < 0) {
- thumb_stderror("send failed");
- return FALSE;
- }
-
- return TRUE;
+ return G_SOURCE_CONTINUE;
}
gboolean _thumb_server_prepare_socket(int *sock_fd)
@@ -235,17 +212,10 @@ int _thumbnail_get_data(const char *origin_path, char *thumb_path)
int err = MS_MEDIA_ERR_NONE;
int file_type = THUMB_NONE_TYPE;
- if (origin_path == NULL) {
- thumb_err("Original path is null");
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
-
- if (!g_file_test(origin_path, G_FILE_TEST_IS_REGULAR)) {
- thumb_err("Original path (%s) does not exist", origin_path);
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
-
+ thumb_retvm_if(!origin_path, MS_MEDIA_ERR_INVALID_PARAMETER, "Original path is null");
+ thumb_retvm_if(!g_file_test(origin_path, G_FILE_TEST_IS_REGULAR), MS_MEDIA_ERR_INVALID_PARAMETER, "Original path(%s) does not exist", origin_path);
thumb_dbg("Origin path : %s", origin_path);
+
file_type = _media_thumb_get_file_type(origin_path);
if (file_type == THUMB_IMAGE_TYPE) {