summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rwxr-xr-xsrc/ipc/media-thumb-ipc.c93
1 files changed, 32 insertions, 61 deletions
diff --git a/src/ipc/media-thumb-ipc.c b/src/ipc/media-thumb-ipc.c
index 6a06281..4fb6cd8 100755
--- a/src/ipc/media-thumb-ipc.c
+++ b/src/ipc/media-thumb-ipc.c
@@ -270,45 +270,42 @@ int _media_thumb_recv_msg(int sock, int header_size, thumbMsg *msg)
}
memcpy(msg, buf, header_size);
- //thumb_dbg("origin_path_size : %d, dest_path_size : %d, thumb_size : %d", msg->origin_path_size, msg->dest_path_size, msg->thumb_size);
+ //thumb_dbg("thumb_size : %d", msg->thumb_size);
SAFE_FREE(buf);
- if (msg->origin_path_size < 0 || msg->dest_path_size < 0 || msg->thumb_size < 0) {
+ if (msg->thumb_size < 0) {
thumb_err("recv data is wrong");
SAFE_FREE(block_buf);
return MS_MEDIA_ERR_SOCKET_RECEIVE;
}
- remain_size = msg->origin_path_size + msg->dest_path_size + msg->thumb_size;
- THUMB_MALLOC(buf, remain_size);
- if (buf == NULL) {
- SAFE_FREE(block_buf);
- return MS_MEDIA_ERR_OUT_OF_MEMORY;
- }
-
- while (remain_size > 0) {
- if (remain_size < THUMB_SOCK_BLOCK_SIZE) {
- block_size = remain_size;
- }
- if ((recv_msg_len = recv(sock, block_buf, block_size, 0)) < 0) {
- thumb_stderror("recv failed");
- SAFE_FREE(buf);
+ if (msg->thumb_size > 0) {
+ remain_size = msg->thumb_size;
+ THUMB_MALLOC(buf, remain_size);
+ if (buf == NULL) {
SAFE_FREE(block_buf);
- return _media_thumb_get_error();
+ return MS_MEDIA_ERR_OUT_OF_MEMORY;
}
- memcpy(buf+recv_block, block_buf, block_size);
- recv_block += block_size;
- remain_size -= block_size;
- }
- SAFE_STRLCPY(msg->org_path, (char *)buf, sizeof(msg->org_path));
- SAFE_STRLCPY(msg->dst_path, (char *)buf + msg->origin_path_size, sizeof(msg->dst_path));
+ while (remain_size > 0) {
+ if (remain_size < THUMB_SOCK_BLOCK_SIZE) {
+ block_size = remain_size;
+ }
+ if ((recv_msg_len = recv(sock, block_buf, block_size, 0)) < 0) {
+ thumb_stderror("recv failed");
+ SAFE_FREE(buf);
+ SAFE_FREE(block_buf);
+ return _media_thumb_get_error();
+ }
+ memcpy(buf+recv_block, block_buf, block_size);
+ recv_block += block_size;
+ remain_size -= block_size;
+ }
- SAFE_FREE(msg->thumb_data);
- if (msg->thumb_size > 0) {
+ SAFE_FREE(msg->thumb_data);
THUMB_MALLOC(msg->thumb_data, msg->thumb_size);
if (msg->thumb_data != NULL) {
- memcpy(msg->thumb_data, buf + msg->origin_path_size + msg->dest_path_size, msg->thumb_size);
+ memcpy(msg->thumb_data, buf, msg->thumb_size);
} else {
SAFE_FREE(buf);
SAFE_FREE(block_buf);
@@ -325,34 +322,29 @@ int _media_thumb_recv_msg(int sock, int header_size, thumbMsg *msg)
int _media_thumb_set_buffer(thumbMsg *req_msg, unsigned char **buf, int *buf_size)
{
- if (req_msg == NULL || buf == NULL) {
+ if (req_msg == NULL || buf == NULL)
return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
- int org_path_len = 0;
- int dst_path_len = 0;
int thumb_data_len = 0;
int size = 0;
int header_size = 0;
- header_size = sizeof(thumbMsg) -(MAX_FILEPATH_LEN * 2) - sizeof(unsigned char *);
- org_path_len = req_msg->origin_path_size;
- dst_path_len = req_msg->dest_path_size;
+ header_size = sizeof(thumbMsg) - sizeof(unsigned char *);
thumb_data_len = req_msg->thumb_size;
+ if (thumb_data_len < 0)
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
- //thumb_dbg("Basic Size : %d, org_path : %s[%d], dst_path : %s[%d], thumb_data_len : %d", header_size, req_msg->org_path, org_path_len, req_msg->dst_path, dst_path_len, thumb_data_len);
+ //thumb_dbg("Basic Size[%d] org_path[%s] dst_path[%s] thumb_data_len[%d]", header_size, req_msg->org_path, req_msg->dst_path, thumb_data_len);
- size = header_size + org_path_len + dst_path_len + thumb_data_len;
+ size = header_size + thumb_data_len;
THUMB_MALLOC(*buf, size);
if (*buf == NULL) {
*buf_size = 0;
return 0;
}
memcpy(*buf, req_msg, header_size);
- memcpy((*buf)+header_size, req_msg->org_path, org_path_len);
- memcpy((*buf)+header_size + org_path_len, req_msg->dst_path, dst_path_len);
if (thumb_data_len > 0)
- memcpy((*buf)+header_size + org_path_len + dst_path_len, req_msg->thumb_data, thumb_data_len);
+ memcpy((*buf) + header_size, req_msg->thumb_data, thumb_data_len);
*buf_size = size;
@@ -369,7 +361,7 @@ gboolean _media_thumb_write_socket(GIOChannel *src, GIOCondition condition, gpoi
memset((void *)&recv_msg, 0, sizeof(thumbMsg));
sock = g_io_channel_unix_get_fd(src);
- header_size = sizeof(thumbMsg) - MAX_PATH_SIZE*2 - sizeof(unsigned char *);
+ header_size = sizeof(thumbMsg) - sizeof(unsigned char *);
thumb_err("_media_thumb_write_socket socket : %d", sock);
@@ -410,7 +402,7 @@ gboolean _media_thumb_raw_data_write_socket(GIOChannel *src, GIOCondition condit
memset((void *)&recv_msg, 0, sizeof(thumbMsg));
sock = g_io_channel_unix_get_fd(src);
- header_size = sizeof(thumbMsg) - MAX_PATH_SIZE*2 - sizeof(unsigned char *);
+ header_size = sizeof(thumbMsg) - sizeof(unsigned char *);
thumb_err("_media_thumb_write_socket socket : %d", sock);
@@ -494,7 +486,6 @@ static int _media_thumb_send_request()
source_id = g_source_attach(source, g_main_context_get_thread_default());
thumbMsg req_msg;
-
memset((void *)&req_msg, 0, sizeof(thumbMsg));
pid = getpid();
@@ -504,18 +495,8 @@ static int _media_thumb_send_request()
req_msg.uid = req_manager->uid;
SAFE_STRLCPY(req_msg.org_path, req_manager->path, sizeof(req_msg.org_path));
req_msg.dst_path[0] = '\0';
- req_msg.origin_path_size = strlen(req_msg.org_path) + 1;
- req_msg.dest_path_size = 1;
req_msg.thumb_size = 0;
- if (req_msg.origin_path_size > MAX_PATH_SIZE || req_msg.dest_path_size > MAX_PATH_SIZE) {
- thumb_err("path's length exceeds %d", MAX_PATH_SIZE);
- g_io_channel_shutdown(channel, TRUE, NULL);
- g_io_channel_unref(channel);
- close(sock);
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
-
unsigned char *buf = NULL;
int buf_size = 0;
_media_thumb_set_buffer(&req_msg, &buf, &buf_size);
@@ -606,18 +587,8 @@ static int _media_thumb_raw_data_send_request()
SAFE_STRLCPY(req_msg.org_path, req_manager->path, sizeof(req_msg.org_path));
req_msg.dst_path[0] = '\0';
-
- req_msg.origin_path_size = strlen(req_msg.org_path) + 1;
- req_msg.dest_path_size = 1;
req_msg.thumb_size = 0;
- if (req_msg.origin_path_size > MAX_PATH_SIZE) {
- thumb_err("path's length exceeds %d", MAX_PATH_SIZE);
- g_io_channel_shutdown(channel, TRUE, NULL);
- g_io_channel_unref(channel);
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
-
unsigned char *buf = NULL;
int buf_size = 0;
_media_thumb_set_buffer(&req_msg, &buf, &buf_size);