int ms_cynara_receive_untrusted_message_thumb(int sockfd, thumbMsg *recv_msg, ms_peer_credentials *credentials)
{
int ret = 0;
- unsigned int header_size = 0;
- int recv_msg_size = 0;
- unsigned char *buf = NULL;
if (!recv_msg || !credentials)
return MS_MEDIA_ERR_INVALID_PARAMETER;
- header_size = sizeof(thumbMsg) - sizeof(unsigned char *);
- buf = g_malloc0(header_size);
-
- if ((recv_msg_size = recv(sockfd, buf, header_size, 0)) < 0) {
+ if (recv(sockfd, recv_msg, sizeof(thumbMsg), 0) < 0) {
MSAPI_DBG_STRERROR("recv failed");
- g_free(buf);
return MS_MEDIA_ERR_IPC;
}
- memcpy(recv_msg, buf, header_size);
- MS_SAFE_FREE(buf);
-
/* Can be null (kill server msg) */
if (strlen(recv_msg->org_path) >= MAX_FILEPATH_LEN) {
MSAPI_DBG_ERR("org_path size is invalid[%zu]", strlen(recv_msg->org_path));
return MS_MEDIA_ERR_IPC;
}
- /* Can be null (raw request case) */
if (strlen(recv_msg->dst_path) >= MAX_FILEPATH_LEN) {
MSAPI_DBG_ERR("dst_path size is invalid[%zu]", strlen(recv_msg->dst_path));
return MS_MEDIA_ERR_IPC;
return MS_MEDIA_ERR_NONE;
}
-
static int __ms_thumb_recv_msg(int sock, thumbMsg *msg)
{
- int remain_size = 0;
- int recv_pos = 0;
- int recv_len = 0;
- unsigned char *buf = NULL;
- unsigned int header_size = sizeof(thumbMsg) - sizeof(unsigned char *);
-
- buf = g_malloc0(header_size);
-
- while (header_size > 0) {
- if ((recv_len = recv(sock, buf + recv_pos, header_size, 0)) < 0) {
- MS_DBG_STRERROR("recv failed");
- g_free(buf);
- return MS_MEDIA_ERR_IPC;
- }
- header_size -= recv_len;
- recv_pos += recv_len;
- }
-
- header_size = recv_pos;
- recv_pos = 0;
+ if (!msg)
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
- memcpy(msg, buf, header_size);
- g_free(buf);
+ if (recv(sock, msg, sizeof(thumbMsg), 0) < 0) {
+ MS_DBG_STRERROR("recv failed");
+ return MS_MEDIA_ERR_IPC;
+ }
MS_DBG("status[%d]", msg->status);
-
MS_DBG_RETVM_IF(msg->msg_type == THUMB_REQUEST_KILL_SERVER, MS_MEDIA_ERR_IPC, "Wrong msg");
MS_DBG_RETVM_IF(strlen(msg->org_path) == 0 || strlen(msg->org_path) >= MS_FILE_PATH_LEN_MAX, MS_MEDIA_ERR_IPC, "Invalid org_path");
MS_DBG_RETVM_IF(strlen(msg->dst_path) >= MS_FILE_PATH_LEN_MAX, MS_MEDIA_ERR_IPC, "Invalid dst_path");
- MS_DBG_RETVM_IF(msg->thumb_size < 0, MS_MEDIA_ERR_IPC, "Invalid thumb_size");
- MS_DBG_RETV_IF(msg->thumb_size == 0, MS_MEDIA_ERR_NONE);
-
- remain_size = msg->thumb_size;
-
- buf = g_malloc0(remain_size);
-
- while (remain_size > 0) {
- if ((recv_len = recv(sock, buf + recv_pos, remain_size, 0)) < 0) {
- MS_DBG_STRERROR("recv failed");
- g_free(buf);
- return MS_MEDIA_ERR_IPC;
- }
- fsync(sock);
-
- recv_pos += recv_len;
- remain_size -= recv_len;
- }
-
- g_free(msg->thumb_data);
-
- msg->thumb_data = g_memdup2(buf, msg->thumb_size);
-
- g_free(buf);
-
- return MS_MEDIA_ERR_NONE;
-}
-
-static int __ms_thumb_set_buffer(thumbMsg *req_msg, unsigned char **buf, int *buf_size)
-{
- int header_size = sizeof(thumbMsg) - sizeof(unsigned char *);
- unsigned int size = 0;
-
- MS_DBG_RETV_IF(!req_msg || !buf || req_msg->thumb_size < 0, MS_MEDIA_ERR_INVALID_PARAMETER);
-
- 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 + req_msg->thumb_size;
-
- *buf = g_malloc0(size);
-
- memcpy(*buf, req_msg, header_size);
-
- if (req_msg->thumb_size > 0)
- memcpy((*buf) + header_size, req_msg->thumb_data, req_msg->thumb_size);
-
- *buf_size = size;
return MS_MEDIA_ERR_NONE;
}
{
int sock;
struct sockaddr_un serv_addr;
- int buf_size = 0;
- unsigned char *buf = NULL;
MS_DBG_RETVM_IF(!recv_msg || strlen(recv_msg->org_path) >= MAX_FILEPATH_LEN, FALSE, "Invalid msg");
return FALSE;
}
- __ms_thumb_set_buffer(recv_msg, &buf, &buf_size);
-
- if (send(sock, buf, buf_size, 0) < 0) {
+ if (send(sock, recv_msg, sizeof(thumbMsg), 0) < 0) {
MS_DBG_STRERROR("send failed");
- g_free(buf);
close(sock);
return FALSE;
}
- g_free(buf);
MS_DBG_SLOG("Sending msg to thumbnail server is successful");
if (recv_msg->msg_type == THUMB_REQUEST_KILL_SERVER) {
res_msg.status = MS_MEDIA_ERR_INTERNAL;
SAFE_STRLCPY(res_msg.org_path, recv_msg->org_path, sizeof(res_msg.org_path));
res_msg.dst_path[0] = '\0';
- res_msg.thumb_data = NULL;
- res_msg.thumb_size = 0;
- int buf_size = 0;
- unsigned char *buf = NULL;
- __ms_thumb_set_buffer(&res_msg, &buf, &buf_size);
-
- if (send(client_sock, buf, buf_size, 0) < 0)
+ if (send(client_sock, &res_msg, sizeof(thumbMsg), 0) < 0)
MS_DBG_STRERROR("send failed");
else
MS_DBG("Sent Refuse msg from %s", recv_msg->org_path);
close(client_sock);
- g_free(buf);
g_free(req->recv_msg);
g_free(req);
SAFE_STRLCPY(res_msg.org_path, recv_msg->org_path, sizeof(res_msg.org_path));
- int buf_size = 0;
- int send_len = 0;
- int send_pos = 0;
- unsigned char *buf = NULL;
- __ms_thumb_set_buffer(&res_msg, &buf, &buf_size);
-
- while (buf_size > 0) {
- if ((send_len = send(client_sock, buf + send_pos, buf_size, 0)) < 0) {
- MS_DBG_STRERROR("send failed");
- break;
- }
-
- send_pos += send_len;
- buf_size -= send_len;
- }
+ if (send(client_sock, &res_msg, sizeof(thumbMsg), 0) < 0)
+ MS_DBG_STRERROR("send failed");
close(client_sock);
- g_free(buf);
g_free(req->recv_msg);
g_free(req);
- MS_SAFE_FREE(res_msg.thumb_data);
return G_SOURCE_CONTINUE;
}
thumbMsg *recv_msg = NULL;
int sock = -1;
int client_sock = -1;
- unsigned char *buf = NULL;
thumbRequest *thumb_req = NULL;
sock = g_io_channel_unix_get_fd(src);
res_msg.status = MS_MEDIA_ERR_INTERNAL;
SAFE_STRLCPY(res_msg.org_path, recv_msg->org_path, sizeof(res_msg.org_path));
res_msg.dst_path[0] = '\0';
- res_msg.thumb_size = 0;
- int buf_size = 0;
- __ms_thumb_set_buffer(&res_msg, &buf, &buf_size);
-
- if (send(client_sock, buf, buf_size, 0) < 0)
+ if (send(client_sock, &res_msg, sizeof(thumbMsg), 0) < 0)
MS_DBG_STRERROR("send failed");
else
MS_DBG("Sent Refuse msg from %s", recv_msg->org_path);
- g_free(buf);
goto ERROR;
}
return G_SOURCE_CONTINUE;
ERROR:
close(client_sock);
- g_free(recv_msg->thumb_data);
g_free(recv_msg);
g_free(thumb_req);
return G_SOURCE_CONTINUE;
return NULL;
}
-