Example #1
0
File: rpc.c Project: 4hosi/FreeRDP
int rpc_in_write(rdpRpc* rpc, BYTE* data, int length)
{
	int status;

#ifdef WITH_DEBUG_TSG
	rpc_pdu_header_print((rpcconn_hdr_t*) data);
	printf("Sending PDU (length: %d)\n", length);
	winpr_HexDump(data, length);
#endif
	
	status = tls_write_all(rpc->TlsIn, data, length);

	return status;
}
Example #2
0
File: rpc.c Project: d0rian/FreeRDP
int rpc_recv_pdu_fragment(rdpRpc* rpc)
{
	int status;
	int headerLength;
	int bytesRead = 0;
	rpcconn_hdr_t* header;

	WaitForSingleObject(rpc->VirtualConnection->DefaultInChannel->Mutex, INFINITE);

	status = rpc_recv_pdu_header(rpc, rpc->FragBuffer);
    
	if (status < 1)
	{
		printf("rpc_recv_pdu_header: error reading header\n");
		return status;
	}
    
	headerLength = status;
	header = (rpcconn_hdr_t*) rpc->FragBuffer;
	bytesRead += status;
	
	if (header->common.frag_length > rpc->FragBufferSize)
	{
		rpc->FragBufferSize = header->common.frag_length;
		rpc->FragBuffer = (BYTE*) realloc(rpc->FragBuffer, rpc->FragBufferSize);
		header = (rpcconn_hdr_t*) rpc->FragBuffer;
	}

	while (bytesRead < header->common.frag_length)
	{
		status = rpc_out_read(rpc, &rpc->FragBuffer[bytesRead], header->common.frag_length - bytesRead);

		if (status < 0)
		{
			printf("rpc_recv_pdu: error reading fragment\n");
			return status;
		}

		bytesRead += status;
	}

	ReleaseMutex(rpc->VirtualConnection->DefaultInChannel->Mutex);

	if (header->common.ptype == PTYPE_RTS) /* RTS PDU */
	{
		if (rpc->VirtualConnection->State < VIRTUAL_CONNECTION_STATE_OPENED)
			return header->common.frag_length;

		printf("Receiving Out-of-Sequence RTS PDU\n");
		rts_recv_out_of_sequence_pdu(rpc, rpc->FragBuffer, header->common.frag_length);

		return rpc_recv_pdu_fragment(rpc);
	}
	else if (header->common.ptype == PTYPE_FAULT)
	{
		rpc_recv_fault_pdu(header);
		return -1;
	}

	rpc->VirtualConnection->DefaultOutChannel->BytesReceived += header->common.frag_length;
	rpc->VirtualConnection->DefaultOutChannel->ReceiverAvailableWindow -= header->common.frag_length;

#if 0
	printf("BytesReceived: %d ReceiverAvailableWindow: %d ReceiveWindow: %d\n",
			rpc->VirtualConnection->DefaultOutChannel->BytesReceived,
			rpc->VirtualConnection->DefaultOutChannel->ReceiverAvailableWindow,
			rpc->ReceiveWindow);
#endif

	if (rpc->VirtualConnection->DefaultOutChannel->ReceiverAvailableWindow < (rpc->ReceiveWindow / 2))
	{
		printf("Sending Flow Control Ack PDU\n");
		rts_send_flow_control_ack_pdu(rpc);
	}

#ifdef WITH_DEBUG_RPC
	rpc_pdu_header_print((rpcconn_hdr_t*) header);
	printf("rpc_recv_pdu_fragment: length: %d\n", header->common.frag_length);
	freerdp_hexdump(rpc->FragBuffer, header->common.frag_length);
	printf("\n");
#endif

	return header->common.frag_length;
}