[SATIZENVUL-1315/SATIZENVUL-1316] Remove msg size from thumbMsg 95/169495/3
authorMinje Ahn <minje.ahn@samsung.com>
Wed, 7 Feb 2018 05:46:11 +0000 (14:46 +0900)
committerMinje ahn <minje.ahn@samsung.com>
Thu, 8 Feb 2018 07:32:45 +0000 (07:32 +0000)
Change-Id: Iaae0d5707294314a1bf856857521f95fb8582691
Signed-off-by: Minje Ahn <minje.ahn@samsung.com>
server/thumb-server-internal.c
src/ipc/media-thumb-ipc.c

index 2f85b30..9116c05 100755 (executable)
@@ -126,33 +126,29 @@ gboolean _thumb_server_read_socket(GIOChannel *src, GIOCondition condition, gpoi
                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));
-       res_msg.origin_path_size = recv_msg.origin_path_size;
-       if (res_msg.msg_type != THUMB_RESPONSE_RAW_DATA) {
-               res_msg.dest_path_size = strlen(res_msg.dst_path)+1;
+       if (res_msg.msg_type != THUMB_RESPONSE_RAW_DATA)
                res_msg.thumb_size = 0;
-       } else {
-               res_msg.dest_path_size = 1;
+       else
                res_msg.dst_path[0] = '\0';
-       }
 
        int buf_size = 0;
        int sending_block = 0;
-       int block_size = sizeof(res_msg) - MAX_FILEPATH_LEN * 2 - sizeof(unsigned char *);
+       int block_size = sizeof(res_msg) - sizeof(unsigned char *);
        unsigned char *buf = NULL;
        _media_thumb_set_buffer(&res_msg, &buf, &buf_size);
 
        while (buf_size > 0) {
-               if (buf_size < THUMB_BLOCK_SIZE) {
+               if (buf_size < THUMB_BLOCK_SIZE)
                        block_size = buf_size;
-               }
+
                if (send(client_sock, buf+sending_block, block_size, 0) != block_size) {
                        thumb_stderror("sendto failed");
+                       break;
                }
                sending_block += block_size;
                buf_size -= block_size;
-               if (block_size < THUMB_BLOCK_SIZE) {
+               if (block_size < THUMB_BLOCK_SIZE)
                        block_size = THUMB_BLOCK_SIZE;
-               }
        }
 
        thumb_dbg_slog("Sent data(%d) from %s", res_msg.thumb_size, res_msg.org_path);
@@ -210,7 +206,7 @@ static gboolean __thumb_server_send_msg_to_agent(int msg_type)
 static gboolean _thumb_server_send_deny_message(int sockfd)
 {
        thumbMsg msg = {0};
-       int bytes_to_send = sizeof(msg) - sizeof(msg.org_path) - sizeof(msg.dst_path);
+       int bytes_to_send = sizeof(msg);
 
        msg.msg_type = THUMB_RESPONSE;
        msg.status = MS_MEDIA_ERR_PERMISSION_DENIED;
index 6a06281..4fb6cd8 100755 (executable)
@@ -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);