Transport opaque

This commit is contained in:
Armin Novak 2021-09-06 11:01:36 +02:00 committed by akallabeth
parent 6a5070722a
commit 17f530a866
17 changed files with 402 additions and 170 deletions

View File

@ -352,8 +352,7 @@ BOOL rdp_client_connect(rdpRdp* rdp)
}
/* everything beyond this point is event-driven and non blocking */
rdp->transport->ReceiveCallback = rdp_recv_callback;
rdp->transport->ReceiveExtra = rdp;
transport_set_recv_callbacks(rdp->transport, rdp_recv_callback, rdp);
transport_set_blocking_mode(rdp->transport, FALSE);
if (rdp_get_state(rdp) != CONNECTION_STATE_NLA)

View File

@ -554,13 +554,17 @@ static int fastpath_recv_update_data(rdpFastPath* fastpath, wStream* s)
}
else
{
rdpContext* context;
const size_t totalSize = Stream_GetPosition(fastpath->updateData);
WINPR_ASSERT(transport->settings);
if (totalSize > transport->settings->MultifragMaxRequestSize)
context = transport_get_context(transport);
WINPR_ASSERT(context);
WINPR_ASSERT(context->settings);
if (totalSize > context->settings->MultifragMaxRequestSize)
{
WLog_ERR(TAG, "Total size (%" PRIuz ") exceeds MultifragMaxRequestSize (%" PRIu32 ")",
totalSize, transport->settings->MultifragMaxRequestSize);
totalSize, context->settings->MultifragMaxRequestSize);
goto out_fail;
}

View File

@ -177,7 +177,8 @@ BOOL freerdp_connect(freerdp* instance)
{
pcap_get_next_record_header(update->pcap_rfx, &record);
if (!(s = StreamPool_Take(rdp->transport->ReceivePool, record.length)))
s = transport_take_from_pool(rdp->transport, record.length);
if (!s)
break;
record.data = Stream_Buffer(s);
@ -207,7 +208,8 @@ BOOL freerdp_connect(freerdp* instance)
if (rdp->errorInfo == ERRINFO_SERVER_INSUFFICIENT_PRIVILEGES)
freerdp_set_last_error_log(instance->context, FREERDP_ERROR_INSUFFICIENT_PRIVILEGES);
SetEvent(rdp->transport->connectedEvent);
transport_set_connected_event(rdp->transport);
freerdp_connect_finally:
EventArgsInit(&e, "freerdp");
e.result = status ? 0 : -1;
@ -898,12 +900,9 @@ void freerdp_free(freerdp* instance)
ULONG freerdp_get_transport_sent(rdpContext* context, BOOL resetCount)
{
ULONG written = context->rdp->transport->written;
if (resetCount)
context->rdp->transport->written = 0;
return written;
WINPR_ASSERT(context);
WINPR_ASSERT(context->rdp);
return transport_get_bytes_sent(context->rdp->transport, resetCount);
}
BOOL freerdp_nla_impersonate(rdpContext* context)
@ -919,7 +918,7 @@ BOOL freerdp_nla_impersonate(rdpContext* context)
if (!context->rdp->transport)
return FALSE;
nla = context->rdp->transport->nla;
nla = transport_get_nla(context->rdp->transport);
return nla_impersonate(nla);
}
@ -936,7 +935,7 @@ BOOL freerdp_nla_revert_to_self(rdpContext* context)
if (!context->rdp->transport)
return FALSE;
nla = context->rdp->transport->nla;
nla = transport_get_nla(context->rdp->transport);
return nla_revert_to_self(nla);
}

View File

@ -1639,8 +1639,8 @@ static BOOL rdg_tls_connect(rdpRdg* rdg, rdpTls* tls, const char* peerAddress, i
if (settings->GatewayPort > UINT16_MAX)
return FALSE;
sockfd = freerdp_tcp_connect(rdg->context, settings, peerAddress ? peerAddress : peerHostname,
peerPort, timeout);
sockfd = freerdp_tcp_connect(rdg->context, peerAddress ? peerAddress : peerHostname, peerPort,
timeout);
if (sockfd < 0)
{
@ -1855,7 +1855,10 @@ static BOOL rdg_tunnel_connect(rdpRdg* rdg)
if (!status)
{
rdg->context->rdp->transport->layer = TRANSPORT_LAYER_CLOSED;
WINPR_ASSERT(rdg);
WINPR_ASSERT(rdg->context);
WINPR_ASSERT(rdg->context->rdp);
transport_set_layer(rdg->context->rdp->transport, TRANSPORT_LAYER_CLOSED);
return FALSE;
}
}
@ -1893,7 +1896,10 @@ BOOL rdg_connect(rdpRdg* rdg, DWORD timeout, BOOL* rpcFallback)
if (!status)
{
rdg->context->rdp->transport->layer = TRANSPORT_LAYER_CLOSED;
WINPR_ASSERT(rdg);
WINPR_ASSERT(rdg->context);
WINPR_ASSERT(rdg->context->rdp);
transport_set_layer(rdg->context->rdp->transport, TRANSPORT_LAYER_CLOSED);
return FALSE;
}

View File

@ -649,8 +649,8 @@ static BOOL rpc_channel_tls_connect(RpcChannel* channel, int timeout)
proxyUsername = freerdp_settings_get_string(settings, FreeRDP_ProxyUsername);
proxyPassword = freerdp_settings_get_string(settings, FreeRDP_ProxyPassword);
{
sockfd = freerdp_tcp_connect(context, settings, channel->client->host,
channel->client->port, timeout);
sockfd =
freerdp_tcp_connect(context, channel->client->host, channel->client->port, timeout);
if (sockfd < 0)
return FALSE;
@ -846,8 +846,9 @@ rdpRpc* rpc_new(rdpTransport* transport)
rpc->State = RPC_CLIENT_STATE_INITIAL;
rpc->transport = transport;
rpc->settings = transport->settings;
rpc->context = transport->context;
rpc->context = transport_get_context(transport);
WINPR_ASSERT(rpc->context);
rpc->settings = rpc->context->settings;
rpc->SendSeqNum = 0;
rpc->ntlm = ntlm_new();

View File

@ -174,7 +174,12 @@ static int rpc_client_recv_pdu(rdpRpc* rpc, RPC_PDU* pdu)
{
int status = -1;
rpcconn_rts_hdr_t* rts;
rdpTsg* tsg = rpc->transport->tsg;
rdpTsg* tsg;
WINPR_ASSERT(rpc);
WINPR_ASSERT(pdu);
tsg = transport_get_tsg(rpc->transport);
if (rpc->VirtualConnection->State < VIRTUAL_CONNECTION_STATE_OPENED)
{
@ -337,9 +342,10 @@ static int rpc_client_recv_fragment(rdpRpc* rpc, wStream* fragment)
{
/* End of TsProxySetupReceivePipe */
TerminateEventArgs e;
rdpTsg* tsg = transport_get_tsg(rpc->transport);
rpc->result = *((UINT32*)&buffer[StubOffset]);
freerdp_abort_connect(rpc->context->instance);
tsg_set_state(rpc->transport->tsg, TSG_STATE_TUNNEL_CLOSE_PENDING);
tsg_set_state(tsg, TSG_STATE_TUNNEL_CLOSE_PENDING);
EventArgsInit(&e, "freerdp");
e.code = 0;
PubSub_OnTerminate(rpc->context->pubSub, rpc->context, &e);

View File

@ -222,7 +222,6 @@ struct rdp_tsg
UINT32 TunnelId;
UINT32 ChannelId;
BOOL reauthSequence;
rdpSettings* settings;
rdpTransport* transport;
UINT64 ReauthTunnelContext;
CONTEXT_HANDLE TunnelContext;
@ -2079,7 +2078,7 @@ BOOL tsg_connect(rdpTsg* tsg, const char* hostname, UINT16 port, DWORD timeout)
if (!tsg_check_event_handles(tsg))
{
WLog_ERR(TAG, "tsg_check failure");
transport->layer = TRANSPORT_LAYER_CLOSED;
transport_set_layer(transport, TRANSPORT_LAYER_CLOSED);
return FALSE;
}
}
@ -2148,7 +2147,7 @@ static int tsg_read(rdpTsg* tsg, BYTE* data, UINT32 length)
rpc = tsg->rpc;
if (rpc->transport->layer == TRANSPORT_LAYER_CLOSED)
if (transport_get_layer(rpc->transport) == TRANSPORT_LAYER_CLOSED)
{
WLog_ERR(TAG, "tsg_read error: connection lost");
return -1;
@ -2161,10 +2160,10 @@ static int tsg_read(rdpTsg* tsg, BYTE* data, UINT32 length)
if (status < 0)
return -1;
if (!status && !rpc->transport->blocking)
if (!status && !transport_get_blocking(rpc->transport))
return 0;
if (rpc->transport->layer == TRANSPORT_LAYER_CLOSED)
if (transport_get_layer(rpc->transport) == TRANSPORT_LAYER_CLOSED)
{
WLog_ERR(TAG, "tsg_read error: connection lost");
return -1;
@ -2173,7 +2172,7 @@ static int tsg_read(rdpTsg* tsg, BYTE* data, UINT32 length)
if (status > 0)
break;
if (rpc->transport->blocking)
if (transport_get_blocking(rpc->transport))
{
while (WaitForSingleObject(rpc->client->PipeEvent, 0) != WAIT_OBJECT_0)
{
@ -2183,7 +2182,7 @@ static int tsg_read(rdpTsg* tsg, BYTE* data, UINT32 length)
WaitForSingleObject(rpc->client->PipeEvent, 100);
}
}
} while (rpc->transport->blocking);
} while (transport_get_blocking(rpc->transport));
return status;
}
@ -2195,7 +2194,7 @@ static int tsg_write(rdpTsg* tsg, const BYTE* data, UINT32 length)
if (!tsg || !data || !tsg->rpc || !tsg->rpc->transport)
return -1;
if (tsg->rpc->transport->layer == TRANSPORT_LAYER_CLOSED)
if (transport_get_layer(tsg->rpc->transport) == TRANSPORT_LAYER_CLOSED)
{
WLog_ERR(TAG, "error, connection lost");
return -1;
@ -2218,7 +2217,6 @@ rdpTsg* tsg_new(rdpTransport* transport)
return NULL;
tsg->transport = transport;
tsg->settings = transport->settings;
tsg->rpc = rpc_new(tsg->transport);
if (!tsg->rpc)

View File

@ -492,13 +492,16 @@ BOOL gcc_read_client_data_blocks(wStream* s, rdpMcs* mcs, UINT16 length)
BOOL gcc_write_client_data_blocks(wStream* s, rdpMcs* mcs)
{
rdpContext* context;
rdpSettings* settings;
WINPR_ASSERT(s);
WINPR_ASSERT(mcs);
WINPR_ASSERT(mcs->transport);
settings = mcs->transport->settings;
context = transport_get_context(mcs->transport);
WINPR_ASSERT(context);
settings = context->settings;
WINPR_ASSERT(settings);
if (!gcc_write_client_core_data(s, mcs) || !gcc_write_client_cluster_data(s, mcs) ||
@ -698,13 +701,16 @@ BOOL gcc_read_client_core_data(wStream* s, rdpMcs* mcs, UINT16 blockLength)
UINT16 supportedColorDepths = 0;
UINT32 serverSelectedProtocol = 0;
UINT16 earlyCapabilityFlags = 0;
rdpContext* context;
rdpSettings* settings;
WINPR_ASSERT(s);
WINPR_ASSERT(mcs);
WINPR_ASSERT(mcs->transport);
settings = mcs->transport->settings;
context = transport_get_context(mcs->transport);
WINPR_ASSERT(context);
settings = context->settings;
WINPR_ASSERT(settings);
/* Length of all required fields, until imeFileName */
@ -960,14 +966,16 @@ BOOL gcc_write_client_core_data(wStream* s, rdpMcs* mcs)
UINT16 earlyCapabilityFlags;
WCHAR* clientDigProductId = NULL;
int clientDigProductIdLength;
rdpContext* context;
rdpSettings* settings;
WINPR_ASSERT(s);
WINPR_ASSERT(mcs);
WINPR_ASSERT(mcs->transport);
settings = mcs->transport->settings;
context = transport_get_context(mcs->transport);
WINPR_ASSERT(context);
settings = context->settings;
WINPR_ASSERT(settings);
if (!gcc_write_user_data_header(s, CS_CORE, 234))
@ -1071,14 +1079,16 @@ BOOL gcc_read_server_core_data(wStream* s, rdpMcs* mcs)
UINT32 serverVersion;
UINT32 clientRequestedProtocols;
UINT32 earlyCapabilityFlags;
rdpContext* context;
rdpSettings* settings;
WINPR_ASSERT(s);
WINPR_ASSERT(mcs);
WINPR_ASSERT(mcs->transport);
settings = mcs->transport->settings;
context = transport_get_context(mcs->transport);
WINPR_ASSERT(context);
settings = context->settings;
WINPR_ASSERT(settings);
if (Stream_GetRemainingLength(s) < 4)
@ -1103,13 +1113,16 @@ BOOL gcc_read_server_core_data(wStream* s, rdpMcs* mcs)
BOOL gcc_write_server_core_data(wStream* s, const rdpMcs* mcs)
{
UINT32 earlyCapabilityFlags = 0;
const rdpSettings* settings;
rdpContext* context;
rdpSettings* settings;
WINPR_ASSERT(s);
WINPR_ASSERT(mcs);
WINPR_ASSERT(mcs->transport);
settings = mcs->transport->settings;
context = transport_get_context(mcs->transport);
WINPR_ASSERT(context);
settings = context->settings;
WINPR_ASSERT(settings);
if (!gcc_write_user_data_header(s, SC_CORE, 16))
@ -1133,14 +1146,16 @@ BOOL gcc_write_server_core_data(wStream* s, const rdpMcs* mcs)
BOOL gcc_read_client_security_data(wStream* s, rdpMcs* mcs, UINT16 blockLength)
{
rdpContext* context;
rdpSettings* settings;
WINPR_ASSERT(s);
WINPR_ASSERT(mcs);
WINPR_ASSERT(mcs->transport);
settings = mcs->transport->settings;
context = transport_get_context(mcs->transport);
WINPR_ASSERT(context);
settings = context->settings;
WINPR_ASSERT(settings);
if (blockLength < 8)
@ -1172,13 +1187,16 @@ BOOL gcc_read_client_security_data(wStream* s, rdpMcs* mcs, UINT16 blockLength)
BOOL gcc_write_client_security_data(wStream* s, const rdpMcs* mcs)
{
const rdpSettings* settings;
rdpContext* context;
rdpSettings* settings;
WINPR_ASSERT(s);
WINPR_ASSERT(mcs);
WINPR_ASSERT(mcs->transport);
settings = mcs->transport->settings;
context = transport_get_context(mcs->transport);
WINPR_ASSERT(context);
settings = context->settings;
WINPR_ASSERT(settings);
if (!gcc_write_user_data_header(s, CS_SECURITY, 12))
@ -1202,19 +1220,20 @@ BOOL gcc_read_server_security_data(wStream* s, rdpMcs* mcs)
{
const BYTE* data;
UINT32 length;
BOOL validCryptoConfig = FALSE;
UINT32 serverEncryptionMethod;
rdpContext* context;
rdpSettings* settings;
WINPR_ASSERT(s);
WINPR_ASSERT(mcs);
WINPR_ASSERT(mcs->transport);
settings = mcs->transport->settings;
context = transport_get_context(mcs->transport);
WINPR_ASSERT(context);
settings = context->settings;
WINPR_ASSERT(settings);
BOOL validCryptoConfig = FALSE;
UINT32 serverEncryptionMethod;
if (Stream_GetRemainingLength(s) < 8)
return FALSE;
@ -1398,14 +1417,16 @@ BOOL gcc_write_server_security_data(wStream* s, rdpMcs* mcs)
BYTE encryptedSignature[TSSK_KEY_LENGTH];
BYTE signature[sizeof(initial_signature)];
UINT32 headerLen, serverRandomLen, serverCertLen, wPublicKeyBlobLen;
rdpContext* context;
rdpSettings* settings;
WINPR_ASSERT(s);
WINPR_ASSERT(mcs);
WINPR_ASSERT(mcs->transport);
settings = mcs->transport->settings;
context = transport_get_context(mcs->transport);
WINPR_ASSERT(context);
settings = context->settings;
WINPR_ASSERT(settings);
/**
@ -1781,14 +1802,16 @@ BOOL gcc_read_client_cluster_data(wStream* s, rdpMcs* mcs, UINT16 blockLength)
{
UINT32 flags;
UINT32 redirectedSessionId;
rdpContext* context;
rdpSettings* settings;
WINPR_ASSERT(s);
WINPR_ASSERT(mcs);
WINPR_ASSERT(mcs->transport);
settings = mcs->transport->settings;
context = transport_get_context(mcs->transport);
WINPR_ASSERT(context);
settings = context->settings;
WINPR_ASSERT(settings);
if (blockLength < 8)
@ -1822,13 +1845,16 @@ BOOL gcc_read_client_cluster_data(wStream* s, rdpMcs* mcs, UINT16 blockLength)
BOOL gcc_write_client_cluster_data(wStream* s, const rdpMcs* mcs)
{
UINT32 flags;
const rdpSettings* settings;
rdpContext* context;
rdpSettings* settings;
WINPR_ASSERT(s);
WINPR_ASSERT(mcs);
WINPR_ASSERT(mcs->transport);
settings = mcs->transport->settings;
context = transport_get_context(mcs->transport);
WINPR_ASSERT(context);
settings = context->settings;
WINPR_ASSERT(settings);
if (!gcc_write_user_data_header(s, CS_CLUSTER, 12))
@ -1859,14 +1885,16 @@ BOOL gcc_read_client_monitor_data(wStream* s, rdpMcs* mcs, UINT16 blockLength)
UINT32 flags;
UINT32 monitorCount;
UINT32 left, top, right, bottom;
rdpContext* context;
rdpSettings* settings;
WINPR_ASSERT(s);
WINPR_ASSERT(mcs);
WINPR_ASSERT(mcs->transport);
settings = mcs->transport->settings;
context = transport_get_context(mcs->transport);
WINPR_ASSERT(context);
settings = context->settings;
WINPR_ASSERT(settings);
if (blockLength < 8)
@ -1927,13 +1955,16 @@ BOOL gcc_write_client_monitor_data(wStream* s, const rdpMcs* mcs)
UINT16 length;
UINT32 left, top, right, bottom, flags;
INT32 baseX = 0, baseY = 0;
const rdpSettings* settings;
rdpContext* context;
rdpSettings* settings;
WINPR_ASSERT(s);
WINPR_ASSERT(mcs);
WINPR_ASSERT(mcs->transport);
settings = mcs->transport->settings;
context = transport_get_context(mcs->transport);
WINPR_ASSERT(context);
settings = context->settings;
WINPR_ASSERT(settings);
if (settings->MonitorCount > 1)
@ -1979,14 +2010,16 @@ BOOL gcc_read_client_monitor_extended_data(wStream* s, rdpMcs* mcs, UINT16 block
UINT32 flags;
UINT32 monitorCount;
UINT32 monitorAttributeSize;
rdpContext* context;
rdpSettings* settings;
WINPR_ASSERT(s);
WINPR_ASSERT(mcs);
WINPR_ASSERT(mcs->transport);
settings = mcs->transport->settings;
context = transport_get_context(mcs->transport);
WINPR_ASSERT(context);
settings = context->settings;
WINPR_ASSERT(settings);
if (blockLength < 12)
@ -2029,13 +2062,16 @@ BOOL gcc_write_client_monitor_extended_data(wStream* s, const rdpMcs* mcs)
{
UINT32 i;
UINT16 length;
const rdpSettings* settings;
rdpContext* context;
rdpSettings* settings;
WINPR_ASSERT(s);
WINPR_ASSERT(mcs);
WINPR_ASSERT(mcs->transport);
settings = mcs->transport->settings;
context = transport_get_context(mcs->transport);
WINPR_ASSERT(context);
settings = context->settings;
WINPR_ASSERT(settings);
if (settings->HasMonitorAttributes)
@ -2093,13 +2129,16 @@ BOOL gcc_read_client_message_channel_data(wStream* s, rdpMcs* mcs, UINT16 blockL
BOOL gcc_write_client_message_channel_data(wStream* s, const rdpMcs* mcs)
{
const rdpSettings* settings;
rdpContext* context;
rdpSettings* settings;
WINPR_ASSERT(s);
WINPR_ASSERT(mcs);
WINPR_ASSERT(mcs->transport);
settings = mcs->transport->settings;
context = transport_get_context(mcs->transport);
WINPR_ASSERT(context);
settings = context->settings;
WINPR_ASSERT(settings);
if (settings->NetworkAutoDetect || settings->SupportHeartbeatPdu ||
@ -2164,13 +2203,16 @@ BOOL gcc_read_client_multitransport_channel_data(wStream* s, rdpMcs* mcs, UINT16
BOOL gcc_write_client_multitransport_channel_data(wStream* s, const rdpMcs* mcs)
{
const rdpSettings* settings;
rdpContext* context;
rdpSettings* settings;
WINPR_ASSERT(s);
WINPR_ASSERT(mcs);
WINPR_ASSERT(mcs->transport);
settings = mcs->transport->settings;
context = transport_get_context(mcs->transport);
WINPR_ASSERT(context);
settings = context->settings;
WINPR_ASSERT(settings);
if (!gcc_write_user_data_header(s, CS_MULTITRANSPORT, 8))

View File

@ -692,12 +692,15 @@ BOOL mcs_send_connect_initial(rdpMcs* mcs)
size_t bm, em;
wStream* gcc_CCrq = NULL;
wStream* client_data = NULL;
rdpContext* context;
if (!mcs)
return FALSE;
WINPR_ASSERT(mcs->transport);
mcs_initialize_client_channels(mcs, mcs->transport->settings);
context = transport_get_context(mcs->transport);
WINPR_ASSERT(context);
mcs_initialize_client_channels(mcs, context->settings);
client_data = Stream_New(NULL, 512);
if (!client_data)
@ -1253,7 +1256,7 @@ BOOL mcs_client_begin(rdpMcs* mcs)
if (!mcs || !mcs->transport)
return FALSE;
context = mcs->transport->context;
context = transport_get_context(mcs->transport);
if (!context)
return FALSE;

View File

@ -104,11 +104,14 @@ static BOOL nego_process_negotiation_failure(rdpNego* nego, wStream* s);
BOOL nego_connect(rdpNego* nego)
{
rdpContext* context;
rdpSettings* settings;
WINPR_ASSERT(nego);
WINPR_ASSERT(nego->transport);
settings = nego->transport->settings;
context = transport_get_context(nego->transport);
WINPR_ASSERT(context);
settings = context->settings;
WINPR_ASSERT(settings);
if (nego_get_state(nego) == NEGO_STATE_INITIAL)
{
if (nego->EnabledProtocols[PROTOCOL_HYBRID_EX])
@ -192,7 +195,8 @@ BOOL nego_connect(rdpNego* nego)
if (nego_get_state(nego) == NEGO_STATE_FAIL)
{
if (freerdp_get_last_error(nego->transport->context) == FREERDP_ERROR_SUCCESS)
if (freerdp_get_last_error(transport_get_context(nego->transport)) ==
FREERDP_ERROR_SUCCESS)
WLog_ERR(TAG, "Protocol Security Negotiation Failure");
nego_set_state(nego, NEGO_STATE_FINAL);
@ -283,11 +287,17 @@ BOOL nego_security_connect(rdpNego* nego)
static BOOL nego_tcp_connect(rdpNego* nego)
{
rdpContext* context;
WINPR_ASSERT(nego);
if (!nego->TcpConnected)
{
const UINT32 TcpConnectTimeout = freerdp_settings_get_uint32(
nego->transport->context->settings, FreeRDP_TcpConnectTimeout);
UINT32 TcpConnectTimeout;
context = transport_get_context(nego->transport);
WINPR_ASSERT(context);
TcpConnectTimeout =
freerdp_settings_get_uint32(context->settings, FreeRDP_TcpConnectTimeout);
if (nego->GatewayEnabled)
{
@ -1076,14 +1086,17 @@ BOOL nego_send_negotiation_response(rdpNego* nego)
BOOL status;
wStream* s;
BYTE flags;
rdpContext* context;
rdpSettings* settings;
WINPR_ASSERT(nego);
WINPR_ASSERT(nego->transport);
context = transport_get_context(nego->transport);
WINPR_ASSERT(context);
settings = context->settings;
WINPR_ASSERT(settings);
status = TRUE;
settings = nego->transport->settings;
WINPR_ASSERT(settings);
s = Stream_New(NULL, 512);
@ -1496,10 +1509,12 @@ BOOL nego_set_state(rdpNego* nego, NEGO_STATE state)
SEC_WINNT_AUTH_IDENTITY* nego_get_identity(rdpNego* nego)
{
rdpNla* nla;
if (!nego)
return NULL;
return nla_get_identity(nego->transport->nla);
nla = transport_get_nla(nego->transport);
return nla_get_identity(nla);
}
void nego_free_nla(rdpNego* nego)
@ -1507,8 +1522,7 @@ void nego_free_nla(rdpNego* nego)
if (!nego || !nego->transport)
return;
nla_free(nego->transport->nla);
nego->transport->nla = NULL;
transport_set_nla(nego->transport, NULL);
}
const BYTE* nego_get_routing_token(rdpNego* nego, DWORD* RoutingTokenLength)

View File

@ -653,7 +653,7 @@ static int nla_client_init(rdpNla* nla)
}
}
tls = nla->transport->tls;
tls = transport_get_tls(nla->transport);
if (!tls)
{
@ -989,7 +989,7 @@ fail:
static int nla_server_init(rdpNla* nla)
{
rdpTls* tls = nla->transport->tls;
rdpTls* tls = transport_get_tls(nla->transport);
if (!nla_sec_buffer_alloc_from_data(&nla->PublicKey, tls->PublicKey, 0, tls->PublicKeyLength))
{

View File

@ -282,9 +282,7 @@ static HANDLE freerdp_peer_get_event_handle(freerdp_peer* client)
WINPR_ASSERT(client->context->rdp);
transport = client->context->rdp->transport;
WINPR_ASSERT(transport);
BIO_get_event(transport->frontBio, &hEvent);
hEvent = transport_get_front_bio(transport);
return hEvent;
}
@ -881,8 +879,7 @@ static BOOL freerdp_peer_has_more_to_read(freerdp_peer* peer)
WINPR_ASSERT(peer);
WINPR_ASSERT(peer->context);
WINPR_ASSERT(peer->context->rdp);
WINPR_ASSERT(peer->context->rdp->transport);
return peer->context->rdp->transport->haveMoreBytesToRead;
return transport_have_more_bytes_to_read(peer->context->rdp->transport);
}
static LicenseCallbackResult freerdp_peer_nolicense(freerdp_peer* peer, wStream* s)
@ -949,8 +946,7 @@ BOOL freerdp_peer_context_new(freerdp_peer* client)
if (!transport_attach(rdp->transport, client->sockfd))
goto fail_transport_attach;
rdp->transport->ReceiveCallback = peer_recv_callback;
rdp->transport->ReceiveExtra = client;
transport_set_recv_callbacks(rdp->transport, peer_recv_callback, client);
transport_set_blocking_mode(rdp->transport, FALSE);
client->IsWriteBlocked = freerdp_peer_is_write_blocked;
client->DrainOutputBuffer = freerdp_peer_drain_output_buffer;

View File

@ -925,7 +925,8 @@ int rdp_recv_data_pdu(rdpRdp* rdp, wStream* s)
if (bulk_decompress(rdp->bulk, Stream_Pointer(s), SrcSize, &pDstData, &DstSize,
compressedType))
{
if (!(cs = StreamPool_Take(rdp->transport->ReceivePool, DstSize)))
cs = transport_take_from_pool(rdp->transport, DstSize);
if (!cs)
{
WLog_ERR(TAG, "Couldn't take stream from pool");
return -1;
@ -1719,12 +1720,15 @@ BOOL rdp_send_error_info(rdpRdp* rdp)
int rdp_check_fds(rdpRdp* rdp)
{
int status;
rdpTransport* transport = rdp->transport;
rdpTsg* tsg;
rdpTransport* transport;
if (transport->tsg)
WINPR_ASSERT(rdp);
transport = rdp->transport;
tsg = transport_get_tsg(transport);
if (tsg)
{
rdpTsg* tsg = transport->tsg;
if (!tsg_check_event_handles(tsg))
{
WLog_ERR(TAG, "rdp_check_fds: tsg_check_event_handles()");
@ -1953,7 +1957,7 @@ void rdp_reset(rdpRdp* rdp)
rdp->nego = nego_new(rdp->transport);
rdp->mcs = mcs_new(rdp->transport);
rdp->fastpath = fastpath_new(rdp);
rdp->transport->layer = TRANSPORT_LAYER_TCP;
transport_set_layer(rdp->transport, TRANSPORT_LAYER_TCP);
rdp->errorInfo = 0;
rdp->deactivation_reactivation = 0;
rdp->finalize_sc_pdus = 0;

View File

@ -1057,8 +1057,7 @@ static BOOL freerdp_tcp_set_keep_alive_mode(const rdpSettings* settings, int soc
return TRUE;
}
int freerdp_tcp_connect(rdpContext* context, rdpSettings* settings, const char* hostname, int port,
DWORD timeout)
int freerdp_tcp_connect(rdpContext* context, const char* hostname, int port, DWORD timeout)
{
rdpTransport* transport;
if (!context || !context->rdp)
@ -1066,7 +1065,7 @@ int freerdp_tcp_connect(rdpContext* context, rdpSettings* settings, const char*
transport = context->rdp->transport;
if (!transport)
return -1;
return IFCALLRESULT(-1, transport->io.TCPConnect, context, settings, hostname, port, timeout);
return transport_tcp_connect(context->rdp->transport, hostname, port, timeout);
}
int freerdp_tcp_default_connect(rdpContext* context, rdpSettings* settings, const char* hostname,

View File

@ -63,8 +63,8 @@
FREERDP_LOCAL BIO_METHOD* BIO_s_simple_socket(void);
FREERDP_LOCAL BIO_METHOD* BIO_s_buffered_socket(void);
FREERDP_LOCAL int freerdp_tcp_connect(rdpContext* context, rdpSettings* settings,
const char* hostname, int port, DWORD timeout);
FREERDP_LOCAL int freerdp_tcp_connect(rdpContext* context, const char* hostname, int port,
DWORD timeout);
FREERDP_LOCAL int freerdp_tcp_default_connect(rdpContext* context, rdpSettings* settings,
const char* hostname, int port, DWORD timeout);

View File

@ -59,6 +59,33 @@
#define BUFFER_SIZE 16384
struct rdp_transport
{
TRANSPORT_LAYER layer;
BIO* frontBio;
rdpRdg* rdg;
rdpTsg* tsg;
rdpTls* tls;
rdpContext* context;
rdpNla* nla;
rdpSettings* settings;
void* ReceiveExtra;
wStream* ReceiveBuffer;
TransportRecv ReceiveCallback;
wStreamPool* ReceivePool;
HANDLE connectedEvent;
BOOL NlaMode;
BOOL blocking;
BOOL GatewayEnabled;
CRITICAL_SECTION ReadLock;
CRITICAL_SECTION WriteLock;
ULONG written;
HANDLE rereadEvent;
BOOL haveMoreBytesToRead;
wLog* log;
rdpTransportIo io;
};
static void transport_ssl_cb(SSL* ssl, int where, int ret)
{
if (where & SSL_CB_ALERT)
@ -70,10 +97,10 @@ static void transport_ssl_cb(SSL* ssl, int where, int ret)
{
case (SSL3_AL_FATAL << 8) | SSL_AD_ACCESS_DENIED:
{
if (!freerdp_get_last_error(transport->context))
if (!freerdp_get_last_error(transport_get_context(transport)))
{
WLog_Print(transport->log, WLOG_ERROR, "%s: ACCESS DENIED", __FUNCTION__);
freerdp_set_last_error_log(transport->context,
freerdp_set_last_error_log(transport_get_context(transport),
FREERDP_ERROR_AUTHENTICATION_FAILED);
}
}
@ -83,12 +110,12 @@ static void transport_ssl_cb(SSL* ssl, int where, int ret)
{
if (transport->NlaMode)
{
if (!freerdp_get_last_error(transport->context))
if (!freerdp_get_last_error(transport_get_context(transport)))
{
UINT32 kret = nla_get_error(transport->nla);
if (kret == 0)
kret = FREERDP_ERROR_CONNECT_PASSWORD_CERTAINLY_EXPIRED;
freerdp_set_last_error_log(transport->context, kret);
freerdp_set_last_error_log(transport_get_context(transport), kret);
}
}
@ -169,7 +196,7 @@ BOOL transport_connect_rdp(rdpTransport* transport)
if (!transport)
return FALSE;
switch (utils_authenticate(transport->context->instance, AUTH_RDP, FALSE))
switch (utils_authenticate(transport_get_context(transport)->instance, AUTH_RDP, FALSE))
{
case AUTH_SKIP:
case AUTH_SUCCESS:
@ -190,7 +217,7 @@ BOOL transport_connect_tls(rdpTransport* transport)
/* Only prompt for password if we use TLS (NLA also calls this function) */
if (transport->settings->SelectedProtocol == PROTOCOL_SSL)
{
switch (utils_authenticate(transport->context->instance, AUTH_TLS, FALSE))
switch (utils_authenticate(transport_get_context(transport)->instance, AUTH_TLS, FALSE))
{
case AUTH_SKIP:
case AUTH_SUCCESS:
@ -213,7 +240,7 @@ static BOOL transport_default_connect_tls(rdpTransport* transport)
WINPR_ASSERT(transport);
context = transport->context;
context = transport_get_context(transport);
WINPR_ASSERT(context);
settings = transport->settings;
@ -274,7 +301,7 @@ BOOL transport_connect_nla(rdpTransport* transport)
if (!transport)
return FALSE;
context = transport->context;
context = transport_get_context(transport);
settings = context->settings;
instance = context->instance;
rdp = context->rdp;
@ -331,7 +358,7 @@ BOOL transport_connect(rdpTransport* transport, const char* hostname, UINT16 por
WINPR_ASSERT(hostname);
settings = transport->settings;
context = transport->context;
context = transport_get_context(transport);
rpcFallback = !settings->GatewayHttpTransport;
WINPR_ASSERT(settings);
WINPR_ASSERT(context);
@ -393,9 +420,9 @@ BOOL transport_connect(rdpTransport* transport, const char* hostname, UINT16 por
proxy_prepare(settings, &proxyHostname, &peerPort, &proxyUsername, &proxyPassword);
if (isProxyConnection)
sockfd = freerdp_tcp_connect(context, settings, proxyHostname, peerPort, timeout);
sockfd = transport_tcp_connect(transport, proxyHostname, peerPort, timeout);
else
sockfd = freerdp_tcp_connect(context, settings, hostname, port, timeout);
sockfd = transport_tcp_connect(transport, hostname, port, timeout);
if (sockfd < 0)
return FALSE;
@ -541,17 +568,20 @@ static SSIZE_T transport_read_layer(rdpTransport* transport, BYTE* data, size_t
{
SSIZE_T read = 0;
rdpRdp* rdp;
rdpContext* context;
WINPR_ASSERT(transport);
WINPR_ASSERT(transport->context);
rdp = transport->context->rdp;
context = transport_get_context(transport);
WINPR_ASSERT(context);
rdp = context->rdp;
WINPR_ASSERT(rdp);
if (!transport->frontBio || (bytes > SSIZE_MAX))
{
transport->layer = TRANSPORT_LAYER_CLOSED;
freerdp_set_last_error_if_not(transport->context, FREERDP_ERROR_CONNECT_TRANSPORT_FAILED);
freerdp_set_last_error_if_not(context, FREERDP_ERROR_CONNECT_TRANSPORT_FAILED);
return -1;
}
@ -574,8 +604,7 @@ static SSIZE_T transport_read_layer(rdpTransport* transport, BYTE* data, size_t
WLog_ERR_BIO(transport, "BIO_read", transport->frontBio);
transport->layer = TRANSPORT_LAYER_CLOSED;
freerdp_set_last_error_if_not(transport->context,
FREERDP_ERROR_CONNECT_TRANSPORT_FAILED);
freerdp_set_last_error_if_not(context, FREERDP_ERROR_CONNECT_TRANSPORT_FAILED);
return -1;
}
@ -844,21 +873,23 @@ static int transport_default_write(rdpTransport* transport, wStream* s)
int status = -1;
int writtenlength = 0;
rdpRdp* rdp;
rdpContext* context;
if (!s)
return -1;
if (!transport || !transport->context)
context = transport_get_context(transport);
if (!transport || !context)
goto fail;
rdp = transport->context->rdp;
rdp = context->rdp;
if (!rdp)
goto fail;
if (!transport->frontBio)
{
transport->layer = TRANSPORT_LAYER_CLOSED;
freerdp_set_last_error_if_not(transport->context, FREERDP_ERROR_CONNECT_TRANSPORT_FAILED);
freerdp_set_last_error_if_not(context, FREERDP_ERROR_CONNECT_TRANSPORT_FAILED);
goto fail;
}
@ -937,7 +968,7 @@ out_cleanup:
{
/* A write error indicates that the peer has dropped the connection */
transport->layer = TRANSPORT_LAYER_CLOSED;
freerdp_set_last_error_if_not(transport->context, FREERDP_ERROR_CONNECT_TRANSPORT_FAILED);
freerdp_set_last_error_if_not(context, FREERDP_ERROR_CONNECT_TRANSPORT_FAILED);
}
LeaveCriticalSection(&(transport->WriteLock));
@ -1067,13 +1098,17 @@ int transport_check_fds(rdpTransport* transport)
wStream* received;
UINT64 now = GetTickCount64();
UINT64 dueDate = 0;
rdpContext* context;
WINPR_ASSERT(transport);
context = transport_get_context(transport);
WINPR_ASSERT(context);
if (transport->layer == TRANSPORT_LAYER_CLOSED)
{
WLog_Print(transport->log, WLOG_DEBUG, "transport_check_fds: transport layer closed");
freerdp_set_last_error_if_not(transport->context, FREERDP_ERROR_CONNECT_TRANSPORT_FAILED);
freerdp_set_last_error_if_not(context, FREERDP_ERROR_CONNECT_TRANSPORT_FAILED);
return -1;
}
@ -1088,8 +1123,8 @@ int transport_check_fds(rdpTransport* transport)
while (now < dueDate)
{
WINPR_ASSERT(transport->context);
if (freerdp_shall_disconnect(transport->context->instance))
WINPR_ASSERT(context);
if (freerdp_shall_disconnect(context->instance))
{
return -1;
}
@ -1329,3 +1364,125 @@ rdpTransport* freerdp_get_transport(rdpContext* context)
WINPR_ASSERT(context->rdp);
return context->rdp->transport;
}
BOOL transport_set_nla(rdpTransport* transport, rdpNla* nla)
{
WINPR_ASSERT(transport);
nla_free(transport->nla);
transport->nla = nla;
return TRUE;
}
rdpNla* transport_get_nla(rdpTransport* transport)
{
WINPR_ASSERT(transport);
return transport->nla;
}
BOOL transport_set_tls(rdpTransport* transport, rdpTls* tls)
{
WINPR_ASSERT(transport);
tls_free(transport->tls);
transport->tls = tls;
return TRUE;
}
rdpTls* transport_get_tls(rdpTransport* transport)
{
WINPR_ASSERT(transport);
return transport->tls;
}
BOOL transport_set_tsg(rdpTransport* transport, rdpTsg* tsg)
{
WINPR_ASSERT(transport);
tsg_free(transport->tsg);
transport->tsg = tsg;
return TRUE;
}
rdpTsg* transport_get_tsg(rdpTransport* transport)
{
WINPR_ASSERT(transport);
return transport->tsg;
}
wStream* transport_take_from_pool(rdpTransport* transport, size_t size)
{
WINPR_ASSERT(transport);
return StreamPool_Take(transport->ReceivePool, size);
}
ULONG transport_get_bytes_sent(rdpTransport* transport, BOOL resetCount)
{
ULONG rc;
WINPR_ASSERT(transport);
rc = transport->written;
if (resetCount)
transport->written = 0;
return rc;
}
TRANSPORT_LAYER transport_get_layer(rdpTransport* transport)
{
WINPR_ASSERT(transport);
return transport->layer;
}
BOOL transport_set_layer(rdpTransport* transport, TRANSPORT_LAYER layer)
{
WINPR_ASSERT(transport);
transport->layer = layer;
return TRUE;
}
BOOL transport_set_connected_event(rdpTransport* transport)
{
WINPR_ASSERT(transport);
return SetEvent(transport->connectedEvent);
}
BOOL transport_set_recv_callbacks(rdpTransport* transport, TransportRecv recv, void* extra)
{
WINPR_ASSERT(transport);
transport->ReceiveCallback = recv;
transport->ReceiveExtra = extra;
}
BOOL transport_get_blocking(rdpTransport* transport)
{
WINPR_ASSERT(transport);
return transport->blocking;
}
BOOL transport_set_blocking(rdpTransport* transport, BOOL blocking)
{
WINPR_ASSERT(transport);
transport->blocking = blocking;
return TRUE;
}
BOOL transport_have_more_bytes_to_read(rdpTransport* transport)
{
WINPR_ASSERT(transport);
return transport->haveMoreBytesToRead;
}
int transport_tcp_connect(rdpTransport* transport, const char* hostname, int port, DWORD timeout)
{
rdpContext* context = transport_get_context(transport);
WINPR_ASSERT(context);
WINPR_ASSERT(context->settings);
return IFCALLRESULT(-1, transport->io.TCPConnect, context, context->settings, hostname, port,
timeout);
}
HANDLE transport_get_front_bio(rdpTransport* transport)
{
HANDLE hEvent = NULL;
WINPR_ASSERT(transport);
WINPR_ASSERT(transport->frontBio);
BIO_get_event(transport->frontBio, &hEvent);
return hEvent;
}

View File

@ -52,33 +52,6 @@ typedef enum
typedef int (*TransportRecv)(rdpTransport* transport, wStream* stream, void* extra);
struct rdp_transport
{
TRANSPORT_LAYER layer;
BIO* frontBio;
rdpRdg* rdg;
rdpTsg* tsg;
rdpTls* tls;
rdpContext* context;
rdpNla* nla;
rdpSettings* settings;
void* ReceiveExtra;
wStream* ReceiveBuffer;
TransportRecv ReceiveCallback;
wStreamPool* ReceivePool;
HANDLE connectedEvent;
BOOL NlaMode;
BOOL blocking;
BOOL GatewayEnabled;
CRITICAL_SECTION ReadLock;
CRITICAL_SECTION WriteLock;
ULONG written;
HANDLE rereadEvent;
BOOL haveMoreBytesToRead;
wLog* log;
rdpTransportIo io;
};
FREERDP_LOCAL wStream* transport_send_stream_init(rdpTransport* transport, size_t size);
FREERDP_LOCAL BOOL transport_connect(rdpTransport* transport, const char* hostname, UINT16 port,
DWORD timeout);
@ -99,6 +72,7 @@ FREERDP_LOCAL int transport_check_fds(rdpTransport* transport);
FREERDP_LOCAL DWORD transport_get_event_handles(rdpTransport* transport, HANDLE* events,
DWORD nCount);
FREERDP_LOCAL HANDLE transport_get_front_bio(rdpTransport* transport);
FREERDP_LOCAL BOOL transport_set_blocking_mode(rdpTransport* transport, BOOL blocking);
FREERDP_LOCAL void transport_set_gateway_enabled(rdpTransport* transport, BOOL GatewayEnabled);
@ -112,6 +86,36 @@ FREERDP_LOCAL int transport_receive_pool_return(rdpTransport* transport, wStream
FREERDP_LOCAL const rdpTransportIo* transport_get_io_callbacks(rdpTransport* transport);
FREERDP_LOCAL BOOL transport_set_io_callbacks(rdpTransport* transport,
const rdpTransportIo* io_callbacks);
FREERDP_LOCAL BOOL transport_set_nla(rdpTransport* transport, rdpNla* nla);
FREERDP_LOCAL rdpNla* transport_get_nla(rdpTransport* transport);
FREERDP_LOCAL BOOL transport_set_tls(rdpTransport* transport, rdpTls* tls);
FREERDP_LOCAL rdpTls* transport_get_tls(rdpTransport* transport);
FREERDP_LOCAL BOOL transport_set_tsg(rdpTransport* transport, rdpTsg* tsg);
FREERDP_LOCAL rdpTsg* transport_get_tsg(rdpTransport* transport);
FREERDP_LOCAL wStream* transport_take_from_pool(rdpTransport* transport, size_t size);
FREERDP_LOCAL ULONG transport_get_bytes_sent(rdpTransport* transport, BOOL resetCount);
FREERDP_LOCAL BOOL transport_have_more_bytes_to_read(rdpTransport* transport);
FREERDP_LOCAL TRANSPORT_LAYER transport_get_layer(rdpTransport* transport);
FREERDP_LOCAL BOOL transport_set_layer(rdpTransport* transport, TRANSPORT_LAYER layer);
FREERDP_LOCAL BOOL transport_get_blocking(rdpTransport* transport);
FREERDP_LOCAL BOOL transport_set_blocking(rdpTransport* transport, BOOL blocking);
FREERDP_LOCAL BOOL transport_set_connected_event(rdpTransport* transport);
FREERDP_LOCAL BOOL transport_set_recv_callbacks(rdpTransport* transport, TransportRecv recv,
void* extra);
FREERDP_LOCAL transport_tcp_connect(rdpTransport* transport, const char* hostname, int port,
DWORD timeout);
FREERDP_LOCAL rdpTransport* transport_new(rdpContext* context);
FREERDP_LOCAL void transport_free(rdpTransport* transport);