*/
#include "thumb-server-internal.h"
+#include "media-thumb-util.h"
+#include "media-thumb-debug.h"
+#include <fcntl.h>
#include <unistd.h>
#include <dirent.h>
#include <stdio.h>
#include <string.h>
-#include <Ecore_Evas.h>
-#include <vconf.h>
+#include <tzplatform_config.h>
#ifdef LOG_TAG
#undef LOG_TAG
#endif
#define LOG_TAG "MEDIA_THUMBNAIL_SERVER"
+#define THUMB_DEFAULT_WIDTH 320
+#define THUMB_DEFAULT_HEIGHT 240
+#define THUMB_COMM_SOCK_PATH tzplatform_mkpath(TZ_SYS_RUN, "media-server/media_ipc_thumbcomm.socket")
+#define THUMB_EMPTY_STR ""
-static __thread char **arr_path;
-static __thread int g_idx = 0;
-static __thread int g_cur_idx = 0;
+static int __thumbnail_get_data(const char *origin_path, char *thumb_path)
+{
+ int err = MS_MEDIA_ERR_NONE;
+ int file_type = THUMB_NONE_TYPE;
-GMainLoop *g_thumb_server_mainloop; // defined in thumb-server.c as extern
+ 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);
-#ifdef _USE_MEDIA_UTIL_
-gboolean _thumb_server_send_msg_to_agent(int msg_type);
-#endif
-void _thumb_daemon_stop_job();
+ file_type = _media_thumb_get_file_type(origin_path);
-gboolean _thumb_daemon_start_jobs(gpointer data)
-{
- thumb_dbg("");
- /* Initialize ecore-evas to use evas library */
- ecore_evas_init();
+ if (file_type == THUMB_IMAGE_TYPE) {
+ err = _media_thumb_image(origin_path, thumb_path, THUMB_DEFAULT_WIDTH, THUMB_DEFAULT_HEIGHT, NULL);
+ thumb_retvm_if(err != MS_MEDIA_ERR_NONE, err, "_media_thumb_image failed");
+ } else if (file_type == THUMB_VIDEO_TYPE) {
+ err = _media_thumb_video(origin_path, thumb_path, THUMB_DEFAULT_WIDTH, THUMB_DEFAULT_HEIGHT, NULL);
+ thumb_retvm_if(err != MS_MEDIA_ERR_NONE, err, "_media_thumb_video failed");
+ } else {
+ thumb_err("invalid file type");
+ return MS_MEDIA_ERR_THUMB_UNSUPPORTED;
+ }
-#ifdef _USE_MEDIA_UTIL_
- _thumb_server_send_msg_to_agent(MS_MSG_THUMB_SERVER_READY);
-#endif
- return FALSE;
+ thumb_dbg("Thumb data is generated successfully");
+
+ return MS_MEDIA_ERR_NONE;
}
-void _thumb_daemon_finish_jobs()
+static int __thumbnail_get_raw_data(const char *origin_path, int *width, int *height, unsigned char **data, int *size)
{
- sqlite3 *sqlite_db_handle = _media_thumb_db_get_handle();
+ int err = MS_MEDIA_ERR_NONE;
+ int thumb_width = -1;
+ int thumb_height = -1;
- if (sqlite_db_handle != NULL) {
- _media_thumb_db_disconnect();
- thumb_dbg("sqlite3 handle is alive. So disconnect to sqlite3");
+ if (origin_path == NULL || *width <= 0 || *height <= 0) {
+ thumb_err("Invalid parameter");
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
}
- /* Shutdown ecore-evas */
- ecore_evas_shutdown();
+ 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;
+ }
+
+ int file_type = THUMB_NONE_TYPE;
+ media_thumb_info thumb_info = {0,};
+ file_type = _media_thumb_get_file_type(origin_path);
+ thumb_width = *width;
+ thumb_height = *height;
+
+ if (file_type == THUMB_IMAGE_TYPE) {
+ err = _media_thumb_image(origin_path, NULL, thumb_width, thumb_height, &thumb_info);
+ thumb_retvm_if(err != MS_MEDIA_ERR_NONE, err, "_media_thumb_image failed");
+ } else if (file_type == THUMB_VIDEO_TYPE) {
+ err = _media_thumb_video(origin_path, NULL, thumb_width, thumb_height, &thumb_info);
+ thumb_retvm_if(err != MS_MEDIA_ERR_NONE, err, "_media_thumb_video failed");
+ } else {
+ thumb_err("invalid file type");
+ return MS_MEDIA_ERR_THUMB_UNSUPPORTED;
+ }
- return;
+ if (size) *size = thumb_info.size;
+ *data = thumb_info.data;
+ *width = thumb_info.width;
+ *height = thumb_info.height;
+
+ return MS_MEDIA_ERR_NONE;
}
-void _thumb_daemon_vconf_cb(void *data)
+static int __media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg)
{
- int err = -1;
- int status = 0;
+ int err = MS_MEDIA_ERR_NONE;
+
+ thumb_retvm_if(!req_msg || !res_msg, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid msg");
- thumb_warn("_thumb_daemon_vconf_cb called");
+ memset(res_msg->dst_path, 0, MAX_FILEPATH_LEN);
+ res_msg->status = MS_MEDIA_ERR_NONE;
- err = vconf_get_int(VCONFKEY_SYSMAN_MMC_FORMAT, &status);
- if (err == 0) {
- if (status == VCONFKEY_SYSMAN_MMC_FORMAT_COMPLETED) {
- thumb_warn("SD card format is completed. So media-thumbnail-server stops jobs to extract all thumbnails");
+ if (!g_file_test(req_msg->org_path, G_FILE_TEST_IS_REGULAR)) {
+ thumb_err("origin_path does not exist in file system.");
+ res_msg->status = MS_MEDIA_ERR_FILE_NOT_EXIST;
+ return MS_MEDIA_ERR_FILE_NOT_EXIST;
+ }
- _thumb_daemon_stop_job();
- } else {
- thumb_dbg("not completed");
+ err = _media_thumb_get_thumb_from_db(req_msg->org_path, res_msg->dst_path, MAX_FILEPATH_LEN, req_msg->uid);
+ thumb_retvm_if(err == MS_MEDIA_ERR_NONE, err, "Already exists");
+ if (strlen(res_msg->dst_path) == 0) {
+ err = _media_thumb_get_hash_name(req_msg->org_path, res_msg->dst_path, MAX_FILEPATH_LEN, req_msg->uid);
+ if (err != MS_MEDIA_ERR_NONE) {
+ thumb_err("_media_thumb_get_hash_name failed - %d", err);
+ SAFE_STRLCPY(res_msg->dst_path, THUMB_EMPTY_STR, MAX_FILEPATH_LEN);
+ res_msg->status = err;
+ return err;
}
- } else if (err == -1) {
- thumb_err("vconf_get_int failed : %d", err);
- } else {
- thumb_err("vconf_get_int Unexpected error code: %d", err);
}
- return;
-}
+ thumb_dbg_slog("Thumb path : %s", res_msg->dst_path);
-void _thumb_daemon_stop_job()
-{
- int i = 0;
- char *path = NULL;
+ err = __thumbnail_get_data(req_msg->org_path, res_msg->dst_path);
+ if (err != MS_MEDIA_ERR_NONE) {
+ thumb_err("_thumbnail_get_data failed - %d", err);
+ SAFE_STRLCPY(res_msg->dst_path, THUMB_EMPTY_STR, MAX_FILEPATH_LEN);
+ res_msg->status = err;
+
+ goto DB_UPDATE;
+ }
- thumb_warn("There are %d jobs in the queue. But all jobs will be stopped", g_idx - g_cur_idx);
+ res_msg->msg_type = THUMB_RESPONSE;
- for (i = g_cur_idx; i < g_idx; i++) {
- path = arr_path[g_cur_idx++];
- SAFE_FREE(path);
+DB_UPDATE:
+ err = _media_thumb_update_db(req_msg->org_path, res_msg->dst_path, req_msg->uid);
+ if (err != MS_MEDIA_ERR_NONE) {
+ thumb_err("_media_thumb_update_db failed : %d", err);
+ res_msg->status = err;
}
- return;
+ return err;
}
-int _thumb_daemon_process_job(thumbMsg *req_msg, thumbMsg *res_msg)
+static int __media_thumb_process_raw(thumbMsg *req_msg, thumbMsg *res_msg)
{
- int err = -1;
+ int err = MS_MEDIA_ERR_NONE;
+ unsigned char *data = NULL;
+ int thumb_size = 0;
+ int thumb_w = 0;
+ int thumb_h = 0;
+
+ thumb_retvm_if(!req_msg || !res_msg, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid msg");
+
+ thumb_w = (req_msg->thumb_width > 0) ? req_msg->thumb_width : THUMB_DEFAULT_WIDTH;
+ thumb_h = (req_msg->thumb_height > 0) ? req_msg->thumb_height : THUMB_DEFAULT_HEIGHT;
+
+ res_msg->status = MS_MEDIA_ERR_NONE;
+ res_msg->msg_type = THUMB_RESPONSE_RAW_DATA;
+
+ err = __thumbnail_get_raw_data(req_msg->org_path, &thumb_w, &thumb_h, &data, &thumb_size);
+ if (err != MS_MEDIA_ERR_NONE) {
+ thumb_err("_thumbnail_get_data failed - %d", err);
+ res_msg->status = err;
+ res_msg->thumb_size = 0;
+ goto ERROR;
+ }
- err = _media_thumb_process(req_msg, res_msg);
- if (err < 0) {
- if (req_msg->msg_type == THUMB_REQUEST_SAVE_FILE) {
- thumb_err("_media_thumb_process is failed: %d", err);
- res_msg->status = THUMB_FAIL;
- } else {
- thumb_warn("_media_thumb_process is failed: %d, So use default thumb", err);
- res_msg->status = THUMB_SUCCESS;
- }
+ res_msg->thumb_width = thumb_w;
+ res_msg->thumb_height = thumb_h;
+ res_msg->thumb_size = thumb_size;
+ res_msg->thumb_data = malloc(thumb_size * sizeof(unsigned char));
+ if (res_msg->thumb_data) {
+ memcpy(res_msg->thumb_data, data, thumb_size);
} else {
- res_msg->status = THUMB_SUCCESS;
+ thumb_err("Allocation failed");
+ err = MS_MEDIA_ERR_OUT_OF_MEMORY;
}
+ERROR:
+ SAFE_FREE(data);
+
return err;
}
-int _thumb_daemon_all_extract()
+static int __thumb_daemon_process_job(thumbMsg *req_msg, thumbMsg *res_msg)
{
- int err = -1;
- int count = 0;
- char query_string[MAX_PATH_SIZE + 1] = { 0, };
- char path[MAX_PATH_SIZE + 1] = { 0, };
- sqlite3 *sqlite_db_handle = NULL;
- sqlite3_stmt *sqlite_stmt = NULL;
-
- err = _media_thumb_db_connect();
- if (err < 0) {
- thumb_err("_media_thumb_db_connect failed: %d", err);
- return MEDIA_THUMB_ERROR_DB;
- }
-
- sqlite_db_handle = _media_thumb_db_get_handle();
- if (sqlite_db_handle == NULL) {
- thumb_err("sqlite handle is NULL");
- return MEDIA_THUMB_ERROR_DB;
+ int err = MS_MEDIA_ERR_NONE;
+
+ if (req_msg->msg_type == THUMB_REQUEST_RAW_DATA) {
+ err = __media_thumb_process_raw(req_msg, res_msg);
+ if (err != MS_MEDIA_ERR_NONE)
+ thumb_err("_media_thumb_process_raw is failed: %d", err);
+ } else if (req_msg->msg_type == THUMB_REQUEST_DB_INSERT) {
+ err = __media_thumb_process(req_msg, res_msg);
+ if (err != MS_MEDIA_ERR_NONE)
+ thumb_err("_media_thumb_process is failed: %d", err);
}
- snprintf(query_string, sizeof(query_string), SELECT_PATH_FROM_UNEXTRACTED_THUMB_MEDIA);
- thumb_dbg("Query: %s", query_string);
-
- err = sqlite3_prepare_v2(sqlite_db_handle, query_string, strlen(query_string), &sqlite_stmt, NULL);
- if (SQLITE_OK != err) {
- thumb_err("prepare error [%s]\n", sqlite3_errmsg(sqlite_db_handle));
- _media_thumb_db_disconnect();
- return MEDIA_THUMB_ERROR_DB;
- }
+ return err;
+}
- while(1) {
- err = sqlite3_step(sqlite_stmt);
- if (err != SQLITE_ROW) {
- thumb_dbg("end of row [%s]\n", sqlite3_errmsg(sqlite_db_handle));
- break;
- }
+static void __thumb_server_send_deny_message(int sockfd)
+{
+ thumbMsg msg = {0};
- strncpy(path, (const char *)sqlite3_column_text(sqlite_stmt, 0), sizeof(path));
- path[sizeof(path) - 1] = '\0';
- count = sqlite3_column_int(sqlite_stmt, 1);
+ msg.msg_type = THUMB_RESPONSE;
+ msg.status = MS_MEDIA_ERR_PERMISSION_DENIED;
- thumb_dbg("Path : %s", path);
+ if (send(sockfd, &msg, sizeof(msg), 0) < 0)
+ thumb_stderror("send failed");
+}
- if (g_idx == 0) {
- arr_path = (char**)malloc(sizeof(char*));
- } else {
- arr_path = (char**)realloc(arr_path, (g_idx + 1) * sizeof(char*));
- }
+gboolean _thumb_daemon_start_jobs(gpointer data)
+{
+ int client_sock;
+ struct sockaddr_un serv_addr;
+ ms_thumb_server_msg send_msg;
- arr_path[g_idx++] = strdup(path);
+ 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;
}
- sqlite3_finalize(sqlite_stmt);
- _media_thumb_db_disconnect();
-
- return MEDIA_THUMB_ERROR_NONE;
-}
+ memset(&serv_addr, 0, sizeof(serv_addr));
-int _thumb_daemon_process_queue_jobs(gpointer data)
-{
- int err = -1;
- char *path = NULL;
-
- if (g_cur_idx < g_idx) {
- thumb_dbg("There are %d jobs in the queue", g_idx - g_cur_idx);
- thumb_dbg("Current idx : [%d]", g_cur_idx);
- path = arr_path[g_cur_idx++];
-
- thumbMsg recv_msg, res_msg;
- memset(&recv_msg, 0x00, sizeof(thumbMsg));
- memset(&res_msg, 0x00, sizeof(thumbMsg));
-
- recv_msg.msg_type = THUMB_REQUEST_DB_INSERT;
- recv_msg.thumb_type = MEDIA_THUMB_LARGE;
- strncpy(recv_msg.org_path, path, sizeof(recv_msg.org_path));
- recv_msg.org_path[sizeof(recv_msg.org_path) - 1] = '\0';
-
- _thumb_daemon_process_job(&recv_msg, &res_msg);
-
- if (res_msg.status == THUMB_SUCCESS) {
-
- err = _media_thumb_db_connect();
- if (err < 0) {
- thumb_err("_media_thumb_mb_svc_connect failed: %d", err);
- return TRUE;
- }
-
- /* Need to update DB once generating thumb is done */
- err = _media_thumb_update_db(recv_msg.org_path,
- res_msg.dst_path,
- res_msg.origin_width,
- res_msg.origin_height);
- if (err < 0) {
- thumb_err("_media_thumb_update_db failed : %d", err);
- }
-
- _media_thumb_db_disconnect();
- }
+ serv_addr.sun_family = AF_UNIX;
+ SAFE_STRLCPY(serv_addr.sun_path, THUMB_COMM_SOCK_PATH, sizeof(serv_addr.sun_path));
- SAFE_FREE(path);
- } else {
- g_cur_idx = 0;
- g_idx = 0;
- thumb_warn("Deleting array");
- SAFE_FREE(arr_path);
- //_media_thumb_db_disconnect();
+ /* Connecting to the thumbnail server */
+ if (connect(client_sock, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) < 0) {
+ thumb_stderror("connect");
+ goto ERROR;
+ }
- _thumb_server_send_msg_to_agent(MS_MSG_THUMB_EXTRACT_ALL_DONE); // MS_MSG_THUMB_EXTRACT_ALL_DONE
+ send_msg.msg_type = MS_MSG_THUMB_SERVER_READY;
- return FALSE;
+ if (send(client_sock, &send_msg, sizeof(ms_thumb_server_msg), 0) < 0) {
+ thumb_stderror("send failed");
+ goto ERROR;
}
- return TRUE;
+ thumb_dbg("Sending msg to thumbnail agent[%d] is successful", send_msg.msg_type);
+ERROR:
+ close(client_sock);
+
+ return G_SOURCE_REMOVE;
}
-gboolean _thumb_server_read_socket(GIOChannel *src,
- GIOCondition condition,
- gpointer data)
+gboolean _thumb_server_read_socket(GIOChannel *src, GIOCondition condition, gpointer data)
{
- struct sockaddr_in client_addr;
+ struct sockaddr_un client_addr;
unsigned int client_addr_len;
-#ifndef _USE_MEDIA_UTIL_
- int client_sock;
-#endif
-
thumbMsg recv_msg;
thumbMsg res_msg;
+ ms_peer_credentials credentials;
+ GMainLoop *thumb_server = (GMainLoop *)data;
int sock = -1;
- int header_size = 0;
+ int client_sock = -1;
+
+ int buf_size = 0;
+ int send_len = 0;
+ int send_pos = 0;
+ unsigned char *buf = NULL;
memset((void *)&recv_msg, 0, sizeof(recv_msg));
memset((void *)&res_msg, 0, sizeof(res_msg));
+ 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!");
- header_size = sizeof(thumbMsg) - MAX_PATH_SIZE*2;
+ client_addr_len = sizeof(client_addr);
-#ifndef _USE_MEDIA_UTIL_
if ((client_sock = accept(sock, (struct sockaddr*)&client_addr, &client_addr_len)) < 0) {
- thumb_err("accept failed : %s", strerror(errno));
- return TRUE;
+ thumb_stderror("accept failed");
+ return G_SOURCE_CONTINUE;
}
-
- thumb_dbg("Client[%d] is accepted", client_sock);
-
- if (_media_thumb_recv_msg(client_sock, header_size, &recv_msg) < 0) {
- thumb_err("_media_thumb_recv_msg failed ");
- close(client_sock);
- return TRUE;
+ 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");
+ goto ERROR;
}
-#else
- if (_media_thumb_recv_udp_msg(sock, header_size, &recv_msg, &client_addr, &client_addr_len) < 0) {
- thumb_err("_media_thumb_recv_udp_msg failed");
- return FALSE;
+ 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);
+ goto ERROR;
+ }
+ } else {
+ thumb_warn("Shutting down...");
+ g_main_loop_quit(thumb_server);
+ goto ERROR;
}
-#endif
-
- thumb_warn("Received [%d] %s(%d) from PID(%d) \n", recv_msg.msg_type, recv_msg.org_path, strlen(recv_msg.org_path), recv_msg.pid);
- if (recv_msg.msg_type == THUMB_REQUEST_ALL_MEDIA) {
- thumb_dbg("All thumbnails are being extracted now");
- _thumb_daemon_all_extract();
- g_idle_add(_thumb_daemon_process_queue_jobs, NULL);
- } else if(recv_msg.msg_type == THUMB_REQUEST_KILL_SERVER) {
- thumb_warn("received KILL msg from thumbnail agent.");
- } else {
- long start = thumb_get_debug_time();
+ SAFE_FREE(credentials.smack);
+ SAFE_FREE(credentials.uid);
- _thumb_daemon_process_job(&recv_msg, &res_msg);
+ thumb_warn_slog("Received [%d] %.*s(%zu) from PID(%d)", recv_msg.msg_type, MAX_FILEPATH_LEN, recv_msg.org_path, strlen(recv_msg.org_path), recv_msg.pid);
- long end = thumb_get_debug_time();
- thumb_dbg("Time : %f (%s)", ((double)(end - start) / (double)CLOCKS_PER_SEC), recv_msg.org_path);
- }
+ __thumb_daemon_process_job(&recv_msg, &res_msg);
- res_msg.msg_type = recv_msg.msg_type;
- strncpy(res_msg.org_path, recv_msg.org_path, recv_msg.origin_path_size);
- res_msg.origin_path_size = recv_msg.origin_path_size;
- res_msg.dest_path_size = strlen(res_msg.dst_path) + 1;
+ if (res_msg.msg_type == 0)
+ res_msg.msg_type = recv_msg.msg_type;
+ res_msg.request_id = recv_msg.request_id;
+ SAFE_STRLCPY(res_msg.org_path, recv_msg.org_path, sizeof(res_msg.org_path));
+ if (res_msg.msg_type != THUMB_RESPONSE_RAW_DATA)
+ res_msg.thumb_size = 0;
+ else
+ res_msg.dst_path[0] = '\0';
- int buf_size = 0;
- unsigned char *buf = NULL;
_media_thumb_set_buffer(&res_msg, &buf, &buf_size);
- //thumb_dbg("buffer size : %d", buf_size);
-
-#ifndef _USE_MEDIA_UTIL_
- if (send(client_sock, buf, buf_size, 0) != buf_size) {
- thumb_err("sendto failed : %s", strerror(errno));
- } else {
- thumb_dbg("Sent %s(%d) \n", res_msg.dst_path, strlen(res_msg.dst_path));
- }
-
- close(client_sock);
-#else
- if (sendto(sock, buf, buf_size, 0, (struct sockaddr *)&client_addr, sizeof(client_addr)) != buf_size) {
- thumb_err("sendto failed: %s\n", strerror(errno));
- SAFE_FREE(buf);
- return FALSE;
+ while (buf_size > 0) {
+ if ((send_len = send(client_sock, buf + send_pos, buf_size, 0)) < 0) {
+ thumb_stderror("send failed");
+ break;
+ }
+ send_pos += send_len;
+ buf_size -= send_len;
}
-#endif
-
- thumb_warn("Sent %s(%d)", res_msg.dst_path, strlen(res_msg.dst_path));
SAFE_FREE(buf);
+ SAFE_FREE(res_msg.thumb_data);
- if(recv_msg.msg_type == THUMB_REQUEST_KILL_SERVER) {
- thumb_warn("Shutting down...");
- g_main_loop_quit(g_thumb_server_mainloop);
- }
-
- return TRUE;
-}
-
-#ifdef _USE_MEDIA_UTIL_
-gboolean _thumb_server_send_msg_to_agent(int msg_type)
-{
- int sock;
- const char *serv_ip = "127.0.0.1";
- struct sockaddr_in serv_addr;
- ms_thumb_server_msg send_msg;
-#if 0
- /* Creaete a UDP socket */
- if (_media_thumb_create_udp_socket(&sock) < 0) {
- thumb_err("_media_thumb_create_udp_socket failed");
- return FALSE;
- }
-#endif
- if (ms_ipc_create_client_socket(MS_PROTOCOL_UDP, 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.sin_family = AF_INET;
- serv_addr.sin_addr.s_addr = inet_addr(serv_ip);
- serv_addr.sin_port = htons(MS_THUMB_COMM_PORT);
-
- send_msg.msg_type = msg_type;
-
- if (sendto(sock, &send_msg, sizeof(ms_thumb_server_msg), 0, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) != sizeof(ms_thumb_server_msg)) {
- thumb_err("sendto failed: %s\n", strerror(errno));
- close(sock);
- return FALSE;
- }
-
- thumb_dbg("Sending msg to thumbnail agent[%d] is successful", send_msg.msg_type);
+ERROR:
+ close(client_sock);
- close(sock);
- return TRUE;
+ return G_SOURCE_CONTINUE;
}
-#endif
gboolean _thumb_server_prepare_socket(int *sock_fd)
{
int sock;
- unsigned short serv_port;
-
- thumbMsg recv_msg;
- thumbMsg res_msg;
-
- memset((void *)&recv_msg, 0, sizeof(recv_msg));
- memset((void *)&res_msg, 0, sizeof(res_msg));
-#ifdef _USE_MEDIA_UTIL_
- serv_port = MS_THUMB_DAEMON_PORT;
- if (ms_ipc_create_server_socket(MS_PROTOCOL_UDP, serv_port, &sock) < 0) {
+ if (ms_ipc_create_server_socket(MS_THUMB_DAEMON_PORT, &sock) < 0) {
thumb_err("ms_ipc_create_server_socket failed");
return FALSE;
}
-#if 0
- /* Creaete a UDP socket */
- if (_media_thumb_create_udp_socket(&sock) < 0) {
- thumb_err("_media_thumb_create_udp_socket failed");
- return FALSE;
- }
-#endif
-#else
- char thumb_path[MAX_PATH_SIZE + 1];
- struct sockaddr_in serv_addr;
- serv_port = THUMB_DAEMON_PORT;
-
- /* Creaete a TCP socket */
- if (_media_thumb_create_socket(SERVER_SOCKET, &sock) < 0) {
- thumb_err("_media_thumb_create_socket failed");
- return FALSE;
- }
-
- memset(thumb_path, 0, sizeof(thumb_path));
- memset(&serv_addr, 0, sizeof(serv_addr));
- serv_addr.sin_family = AF_INET;
- serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
- serv_addr.sin_port = htons(serv_port);
- /* Bind to the local address */
- if (bind(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) {
- thumb_err("bind failed : %s", strerror(errno));
+ if (ms_cynara_enable_credentials_passing(sock) != MS_MEDIA_ERR_NONE) {
+ thumb_err("ms_cynara_enable_credentials_passing failed");
+ close(sock);
return FALSE;
}
- thumb_dbg("bind success");
-
- /* Listening */
- if (listen(sock, SOMAXCONN) < 0) {
- thumb_err("listen failed : %s", strerror(errno));
- }
-
- thumb_dbg("Listening...");
-#endif
-
*sock_fd = sock;
return TRUE;
}
-