if (!recv_msg || !credentials)
return MS_MEDIA_ERR_INVALID_PARAMETER;
- header_size = sizeof(thumbMsg) -(MAX_FILEPATH_LEN * 2) - sizeof(unsigned char *);
+ header_size = sizeof(thumbMsg) - sizeof(unsigned char *);
MS_MALLOC(buf, header_size);
if ((recv_msg_size = recv(sockfd, buf, header_size, 0)) < 0) {
memcpy(recv_msg, buf, header_size);
MS_SAFE_FREE(buf);
- if (recv_msg->origin_path_size <= 0) {
- MSAPI_DBG_ERR("msg->origin_path_size is invalid %d", recv_msg->origin_path_size);
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
-
- MS_MALLOC(buf, (unsigned int)(recv_msg->origin_path_size));
- if (buf == NULL) {
- MSAPI_DBG_STRERROR("malloc failed");
- return MS_MEDIA_ERR_OUT_OF_MEMORY;
- }
-
- if ((recv_msg_size = recv(sockfd, buf, recv_msg->origin_path_size, 0)) < 0) {
- MS_SAFE_FREE(buf);
- 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");
- return MS_MEDIA_ERR_SOCKET_RECEIVE;
- }
-
- }
-
- SAFE_STRLCPY(recv_msg->org_path, (char*)buf, sizeof(recv_msg->org_path));
- MS_SAFE_FREE(buf);
-
- if (recv_msg->dest_path_size <= 0) {
- MSAPI_DBG_ERR("msg->origin_path_size is invalid %d", recv_msg->dest_path_size);
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
-
- MS_MALLOC(buf, (unsigned int)(recv_msg->dest_path_size));
- if (buf == NULL) {
- MSAPI_DBG_STRERROR("malloc failed");
- return MS_MEDIA_ERR_OUT_OF_MEMORY;
- }
-
- if ((recv_msg_size = recv(sockfd, buf, recv_msg->dest_path_size, 0)) < 0) {
- MS_SAFE_FREE(buf);
- 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");
- return MS_MEDIA_ERR_SOCKET_RECEIVE;
- }
-
- }
-
- SAFE_STRLCPY(recv_msg->dst_path, (char*)buf, sizeof(recv_msg->dst_path));
- MS_SAFE_FREE(buf);
-
ret = cynara_creds_socket_get_pid(sockfd, &(credentials->pid));
MSAPI_RETVM_IF(ret != 0, MS_MEDIA_ERR_INTERNAL, "[CYNARA]Failed to get pid");
unsigned int header_size = 0;
- header_size = sizeof(thumbMsg) -(MAX_FILEPATH_LEN * 2) - sizeof(unsigned char *);
+ header_size = sizeof(thumbMsg) - sizeof(unsigned char *);
MS_MALLOC(buf, header_size);
if (buf == NULL) {
}
memcpy(msg, buf, header_size);
- MS_DBG("origin_path_size : %d, dest_path_size : %d, thumb_size : %d, status : %d", msg->origin_path_size, msg->dest_path_size, msg->thumb_size, msg->status);
+ MS_DBG("status[%d]", msg->status);
MS_SAFE_FREE(buf);
return MS_MEDIA_ERR_NONE;
}
- MS_MALLOC(block_buf, MS_SOCK_BLOCK_SIZE);
-
- remain_size = msg->origin_path_size + msg->dest_path_size + msg->thumb_size;
- MS_MALLOC(buf, remain_size);
- if (buf == NULL) {
- MS_SAFE_FREE(block_buf);
- return MS_MEDIA_ERR_OUT_OF_MEMORY;
- }
-
- while (remain_size > 0) {
- if (remain_size < MS_SOCK_BLOCK_SIZE)
- block_size = remain_size;
-
- if ((recv_msg_len = recv(sock, block_buf, block_size, 0)) < 0) {
- MS_DBG_STRERROR("recv failed");
- MS_SAFE_FREE(buf);
- MS_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;
- memset(block_buf, 0, MS_SOCK_BLOCK_SIZE);
- }
-
- MS_SAFE_FREE(block_buf);
-
- if (msg->origin_path_size <= 0 || msg->origin_path_size > MS_FILE_PATH_LEN_MAX) {
- MS_SAFE_FREE(buf);
- MS_DBG_ERR("msg->origin_path_size is invalid %d", msg->origin_path_size);
+ if (strlen(msg->org_path) == 0 || strlen(msg->org_path) > MS_FILE_PATH_LEN_MAX) {
+ MS_DBG_ERR("org_path size is invalid %d", strlen(msg->org_path));
return MS_MEDIA_ERR_DATA_TAINTED;
}
- SAFE_STRLCPY(msg->org_path, (char*)buf, sizeof(msg->org_path));
-
- if (msg->dest_path_size <= 0 || msg->dest_path_size > MS_FILE_PATH_LEN_MAX) {
- MS_SAFE_FREE(buf);
- MS_DBG_ERR("msg->dest_path_size is invalid %d", msg->dest_path_size);
+ /* it can be empty string */
+ if (strlen(msg->dst_path) > MS_FILE_PATH_LEN_MAX) {
+ MS_DBG_ERR("dst_path size is invalid %d", strlen(msg->dst_path));
return MS_MEDIA_ERR_DATA_TAINTED;
}
- SAFE_STRLCPY(msg->dst_path, (char *)buf + msg->origin_path_size, sizeof(msg->dst_path));
-
- MS_SAFE_FREE(msg->thumb_data);
-
if (msg->thumb_size < 0) {
- MS_SAFE_FREE(buf);
MS_DBG_ERR("msg->thumb_size is invalid %d", msg->thumb_size);
return MS_MEDIA_ERR_DATA_TAINTED;
}
if (msg->thumb_size > 0) {
+ remain_size = msg->thumb_size;
+ MS_MALLOC(block_buf, MS_SOCK_BLOCK_SIZE);
+ if (block_buf == NULL) {
+ return MS_MEDIA_ERR_OUT_OF_MEMORY;
+ }
+
+ MS_MALLOC(buf, remain_size);
+ if (buf == NULL) {
+ MS_SAFE_FREE(block_buf);
+ return MS_MEDIA_ERR_OUT_OF_MEMORY;
+ }
+
+ while (remain_size > 0) {
+ if (remain_size < MS_SOCK_BLOCK_SIZE)
+ block_size = remain_size;
+
+ if ((recv_msg_len = recv(sock, block_buf, block_size, 0)) < 0) {
+ MS_DBG_STRERROR("recv failed");
+ MS_SAFE_FREE(buf);
+ MS_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;
+ memset(block_buf, 0, MS_SOCK_BLOCK_SIZE);
+ }
+
+ MS_SAFE_FREE(block_buf);
+ MS_SAFE_FREE(msg->thumb_data);
+
MS_MALLOC(msg->thumb_data, (unsigned int)(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 {
MS_SAFE_FREE(buf);
return MS_MEDIA_ERR_OUT_OF_MEMORY;
}
- }
- MS_SAFE_FREE(buf);
+ MS_SAFE_FREE(buf);
+ }
return MS_MEDIA_ERR_NONE;
}
if (req_msg == NULL || buf == NULL)
return -1;
- int org_path_len = 0;
- int dst_path_len = 0;
int data_len = 0;
int header_size = 0;
unsigned int 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 *);
data_len = req_msg->thumb_size;
- if ((org_path_len < 0 || org_path_len > MAX_FILEPATH_LEN) || (dst_path_len < 0 || dst_path_len > MAX_FILEPATH_LEN) || data_len < 0) {
+ if (data_len < 0) {
MS_DBG_ERR("msg size is wrong");
return -1;
}
- MS_DBG_SLOG("Basic Size : %d, org_path : %s[%d], dst_path : %s[%d], thumb_data : %d", header_size, req_msg->org_path, org_path_len, req_msg->dst_path, dst_path_len, req_msg->thumb_size);
+ MS_DBG_SLOG("Basic Size[%d] org_path[%s] dst_path[%s] thumb_data[%d]", header_size, req_msg->org_path, req_msg->dst_path, req_msg->thumb_size);
- size = header_size + org_path_len + dst_path_len + data_len;
+ size = header_size + data_len;
MS_MALLOC(*buf, size);
if (*buf == NULL) {
MS_DBG_STRERROR("MALLOC failed");
}
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 (data_len > 0)
- memcpy((*buf)+header_size + org_path_len + dst_path_len, req_msg->thumb_data, data_len);
+ memcpy((*buf) + header_size, req_msg->thumb_data, data_len);
*buf_size = size;
msg.msg_type = THUMB_REQUEST_KILL_SERVER;
msg.org_path[0] = '\0';
- msg.origin_path_size = 1;
msg.dst_path[0] = '\0';
- msg.dest_path_size = 1;
msg.thumb_size = 0;
/* Command Kill to thumbnail server */
res_msg.msg_type = THUMB_RESPONSE;
res_msg.status = MS_MEDIA_ERR_INTERNAL;
- res_msg.origin_path_size = strlen(recv_msg->org_path);
SAFE_STRLCPY(res_msg.org_path, recv_msg->org_path, sizeof(res_msg.org_path));
res_msg.dst_path[0] = '\0';
- res_msg.dest_path_size = 1;
- res_msg.thumb_data = (unsigned char *)"\0";
- res_msg.thumb_size = 1;
+ res_msg.thumb_data = NULL;
+ res_msg.thumb_size = 0;
int buf_size = 0;
unsigned char *buf = NULL;
}
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;
- res_msg.dest_path_size = strlen(res_msg.dst_path) + 1;
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;
_ms_thumb_set_buffer(&res_msg, &buf, &buf_size);
res_msg.msg_type = THUMB_RESPONSE;
res_msg.status = MS_MEDIA_ERR_INTERNAL;
- res_msg.origin_path_size = recv_msg->origin_path_size;
SAFE_STRLCPY(res_msg.org_path, recv_msg->org_path, sizeof(res_msg.org_path));
res_msg.dst_path[0] = '\0';
- res_msg.dest_path_size = 1;
res_msg.thumb_size = 0;
int buf_size = 0;