Merge pull request #2311 from awakecoding/master
Gateway Disconnect, Ring Buffer Fixes
This commit is contained in:
commit
5046b1d035
@ -229,41 +229,46 @@ wStream* http_request_write(HttpContext* http_context, HttpRequest* http_request
|
||||
char** lines;
|
||||
wStream* s;
|
||||
int length = 0;
|
||||
count = 9;
|
||||
lines = (char**)calloc(count, sizeof(char*));
|
||||
|
||||
count = 0;
|
||||
lines = (char**) calloc(32, sizeof(char*));
|
||||
|
||||
if (!lines)
|
||||
return NULL;
|
||||
|
||||
lines[0] = http_encode_header_line(http_request->Method, http_request->URI);
|
||||
lines[1] = http_encode_body_line("Cache-Control", http_context->CacheControl);
|
||||
lines[2] = http_encode_body_line("Connection", http_context->Connection);
|
||||
lines[3] = http_encode_body_line("Pragma", http_context->Pragma);
|
||||
lines[4] = http_encode_body_line("Accept", http_context->Accept);
|
||||
lines[5] = http_encode_body_line("User-Agent", http_context->UserAgent);
|
||||
lines[6] = http_encode_content_length_line(http_request->ContentLength);
|
||||
lines[7] = http_encode_body_line("Host", http_context->Host);
|
||||
lines[count++] = http_encode_header_line(http_request->Method, http_request->URI);
|
||||
lines[count++] = http_encode_body_line("Cache-Control", http_context->CacheControl);
|
||||
lines[count++] = http_encode_body_line("Connection", http_context->Connection);
|
||||
lines[count++] = http_encode_body_line("Pragma", http_context->Pragma);
|
||||
lines[count++] = http_encode_body_line("Accept", http_context->Accept);
|
||||
lines[count++] = http_encode_body_line("User-Agent", http_context->UserAgent);
|
||||
lines[count++] = http_encode_content_length_line(http_request->ContentLength);
|
||||
lines[count++] = http_encode_body_line("Host", http_context->Host);
|
||||
|
||||
/* check that everything went well */
|
||||
for (i = 0; i < 8; i++)
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
if (!lines[i])
|
||||
goto out_free;
|
||||
}
|
||||
|
||||
if (http_request->Authorization != NULL)
|
||||
if (http_request->Authorization)
|
||||
{
|
||||
lines[8] = http_encode_body_line("Authorization", http_request->Authorization);
|
||||
lines[count] = http_encode_body_line("Authorization", http_request->Authorization);
|
||||
|
||||
if (!lines[8])
|
||||
if (!lines[count])
|
||||
goto out_free;
|
||||
|
||||
count++;
|
||||
}
|
||||
else if ((http_request->AuthScheme != NULL) && (http_request->AuthParam != NULL))
|
||||
else if (http_request->AuthScheme && http_request->AuthParam)
|
||||
{
|
||||
lines[8] = http_encode_authorization_line(http_request->AuthScheme, http_request->AuthParam);
|
||||
lines[count] = http_encode_authorization_line(http_request->AuthScheme, http_request->AuthParam);
|
||||
|
||||
if (!lines[8])
|
||||
if (!lines[count])
|
||||
goto out_free;
|
||||
|
||||
count++;
|
||||
}
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
|
@ -31,15 +31,19 @@
|
||||
|
||||
#include <openssl/rand.h>
|
||||
|
||||
#define TAG FREERDP_TAG("core.gateway")
|
||||
|
||||
wStream* rpc_ntlm_http_request(rdpRpc* rpc, SecBuffer* ntlm_token, int content_length, TSG_CHANNEL channel)
|
||||
{
|
||||
wStream* s;
|
||||
char* base64_ntlm_token;
|
||||
HttpContext* http_context;
|
||||
HttpRequest* http_request;
|
||||
char* base64_ntlm_token = NULL;
|
||||
|
||||
http_request = http_request_new();
|
||||
base64_ntlm_token = crypto_base64_encode(ntlm_token->pvBuffer, ntlm_token->cbBuffer);
|
||||
|
||||
if (ntlm_token)
|
||||
base64_ntlm_token = crypto_base64_encode(ntlm_token->pvBuffer, ntlm_token->cbBuffer);
|
||||
|
||||
if (channel == TSG_CHANNEL_IN)
|
||||
{
|
||||
@ -59,8 +63,11 @@ wStream* rpc_ntlm_http_request(rdpRpc* rpc, SecBuffer* ntlm_token, int content_l
|
||||
http_request->ContentLength = content_length;
|
||||
http_request_set_uri(http_request, http_context->URI);
|
||||
|
||||
http_request_set_auth_scheme(http_request, "NTLM");
|
||||
http_request_set_auth_param(http_request, base64_ntlm_token);
|
||||
if (base64_ntlm_token)
|
||||
{
|
||||
http_request_set_auth_scheme(http_request, "NTLM");
|
||||
http_request_set_auth_param(http_request, base64_ntlm_token);
|
||||
}
|
||||
|
||||
s = http_request_write(http_context, http_request);
|
||||
http_request_free(http_request);
|
||||
@ -83,7 +90,7 @@ int rpc_ncacn_http_send_in_channel_request(rdpRpc* rpc)
|
||||
|
||||
s = rpc_ntlm_http_request(rpc, &ntlm->outputBuffer[0], content_length, TSG_CHANNEL_IN);
|
||||
|
||||
DEBUG_RPC("\n%s", Stream_Buffer(s));
|
||||
WLog_DBG(TAG, "\n%s", Stream_Buffer(s));
|
||||
rpc_in_write(rpc, Stream_Buffer(s), Stream_Length(s));
|
||||
Stream_Free(s, TRUE);
|
||||
|
||||
@ -215,7 +222,7 @@ int rpc_ncacn_http_send_out_channel_request(rdpRpc* rpc)
|
||||
|
||||
s = rpc_ntlm_http_request(rpc, &ntlm->outputBuffer[0], content_length, TSG_CHANNEL_OUT);
|
||||
|
||||
DEBUG_RPC("\n%s", Stream_Buffer(s));
|
||||
WLog_DBG(TAG, "\n%s", Stream_Buffer(s));
|
||||
rpc_out_write(rpc, Stream_Buffer(s), Stream_Length(s));
|
||||
Stream_Free(s, TRUE);
|
||||
|
||||
@ -249,6 +256,22 @@ int rpc_ncacn_http_recv_out_channel_response(rdpRpc* rpc)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int rpc_http_send_replacement_out_channel_request(rdpRpc* rpc)
|
||||
{
|
||||
wStream* s;
|
||||
int content_length;
|
||||
|
||||
content_length = 120;
|
||||
|
||||
s = rpc_ntlm_http_request(rpc, NULL, content_length, TSG_CHANNEL_OUT);
|
||||
|
||||
WLog_DBG(TAG, "\n%s", Stream_Buffer(s));
|
||||
rpc_out_write(rpc, Stream_Buffer(s), Stream_Length(s));
|
||||
Stream_Free(s, TRUE);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
BOOL rpc_ntlm_http_out_connect(rdpRpc* rpc)
|
||||
{
|
||||
rdpNtlm* ntlm = rpc->NtlmHttpOut->ntlm;
|
||||
|
@ -37,6 +37,8 @@ BOOL rpc_ntlm_http_in_connect(rdpRpc* rpc);
|
||||
|
||||
void rpc_ntlm_http_init_channel(rdpRpc* rpc, rdpNtlmHttp* ntlm_http, TSG_CHANNEL channel);
|
||||
|
||||
int rpc_http_send_replacement_out_channel_request(rdpRpc* rpc);
|
||||
|
||||
rdpNtlmHttp* ntlm_http_new(void);
|
||||
void ntlm_http_free(rdpNtlmHttp* ntlm_http);
|
||||
|
||||
|
@ -50,7 +50,7 @@
|
||||
|
||||
#include "rpc.h"
|
||||
|
||||
#define TAG FREERDP_TAG("core.gateway.rpc")
|
||||
#define TAG FREERDP_TAG("core.gateway")
|
||||
|
||||
/* Security Verification Trailer Signature */
|
||||
|
||||
@ -347,11 +347,6 @@ int rpc_out_write(rdpRpc* rpc, const BYTE* data, int length)
|
||||
int rpc_in_write(rdpRpc* rpc, const BYTE* data, int length)
|
||||
{
|
||||
int status;
|
||||
#ifdef WITH_DEBUG_TSG
|
||||
WLog_DBG(TAG, "Sending PDU (length: %d)", length);
|
||||
rpc_pdu_header_print((rpcconn_hdr_t*) data);
|
||||
winpr_HexDump(TAG, WLOG_DEBUG, data, length);
|
||||
#endif
|
||||
status = tls_write_all(rpc->TlsIn, data, length);
|
||||
return status;
|
||||
}
|
||||
@ -503,6 +498,7 @@ void rpc_client_virtual_connection_init(rdpRpc* rpc, RpcVirtualConnection* conne
|
||||
connection->DefaultInChannel->PingOriginator.ConnectionTimeout = 30;
|
||||
connection->DefaultInChannel->PingOriginator.KeepAliveInterval = 0;
|
||||
connection->DefaultInChannel->Mutex = CreateMutex(NULL, FALSE, NULL);
|
||||
|
||||
connection->DefaultOutChannel->State = CLIENT_OUT_CHANNEL_STATE_INITIAL;
|
||||
connection->DefaultOutChannel->BytesReceived = 0;
|
||||
connection->DefaultOutChannel->ReceiverAvailableWindow = rpc->ReceiveWindow;
|
||||
|
@ -721,6 +721,8 @@ typedef struct rpc_client RpcClient;
|
||||
struct rdp_rpc
|
||||
{
|
||||
RPC_CLIENT_STATE State;
|
||||
|
||||
UINT32 result;
|
||||
|
||||
rdpTls* TlsIn;
|
||||
rdpTls* TlsOut;
|
||||
@ -784,15 +786,4 @@ int rpc_write(rdpRpc* rpc, BYTE* data, int length, UINT16 opnum);
|
||||
rdpRpc* rpc_new(rdpTransport* transport);
|
||||
void rpc_free(rdpRpc* rpc);
|
||||
|
||||
#ifdef WITH_DEBUG_TSG
|
||||
#define WITH_DEBUG_RPC
|
||||
#endif
|
||||
|
||||
#define RPC_TAG FREERDP_TAG("core.gateway.rpc")
|
||||
#ifdef WITH_DEBUG_RPC
|
||||
#define DEBUG_RPC(fmt, ...) WLog_DBG(RPC_TAG, fmt, ## __VA_ARGS__)
|
||||
#else
|
||||
#define DEBUG_RPC(fmt, ...) do { } while (0)
|
||||
#endif
|
||||
|
||||
#endif /* FREERDP_CORE_RPC_H */
|
||||
|
@ -32,7 +32,7 @@
|
||||
|
||||
#include "rpc_bind.h"
|
||||
|
||||
#define TAG FREERDP_TAG("core.gateway.rpc_bind")
|
||||
#define TAG FREERDP_TAG("core.gateway")
|
||||
|
||||
/**
|
||||
* Connection-Oriented RPC Protocol Client Details:
|
||||
@ -103,7 +103,7 @@ int rpc_send_bind_pdu(rdpRpc* rpc)
|
||||
BOOL promptPassword = FALSE;
|
||||
freerdp* instance = (freerdp*) settings->instance;
|
||||
|
||||
DEBUG_RPC("Sending bind PDU");
|
||||
WLog_DBG(TAG, "Sending bind PDU");
|
||||
|
||||
if (rpc->ntlm)
|
||||
{
|
||||
@ -316,10 +316,12 @@ int rpc_send_rpc_auth_3_pdu(rdpRpc* rpc)
|
||||
RpcClientCall* clientCall;
|
||||
rpcconn_rpc_auth_3_hdr_t* auth_3_pdu;
|
||||
|
||||
DEBUG_RPC("Sending rpc_auth_3 PDU");
|
||||
WLog_DBG(TAG, "Sending rpc_auth_3 PDU");
|
||||
|
||||
auth_3_pdu = (rpcconn_rpc_auth_3_hdr_t*) malloc(sizeof(rpcconn_rpc_auth_3_hdr_t));
|
||||
ZeroMemory(auth_3_pdu, sizeof(rpcconn_rpc_auth_3_hdr_t));
|
||||
auth_3_pdu = (rpcconn_rpc_auth_3_hdr_t*) calloc(1, sizeof(rpcconn_rpc_auth_3_hdr_t));
|
||||
|
||||
if (!auth_3_pdu)
|
||||
return -1;
|
||||
|
||||
rpc_pdu_header_init(rpc, (rpcconn_hdr_t*) auth_3_pdu);
|
||||
|
||||
@ -346,6 +348,9 @@ int rpc_send_rpc_auth_3_pdu(rdpRpc* rpc)
|
||||
|
||||
buffer = (BYTE*) malloc(auth_3_pdu->frag_length);
|
||||
|
||||
if (!buffer)
|
||||
return -1;
|
||||
|
||||
CopyMemory(buffer, auth_3_pdu, 20);
|
||||
|
||||
offset = 20;
|
||||
|
@ -133,12 +133,15 @@ int rpc_client_on_fragment_received_event(rdpRpc* rpc)
|
||||
rts_recv_out_of_sequence_pdu(rpc, buffer, header->common.frag_length);
|
||||
rpc_client_fragment_pool_return(rpc, fragment);
|
||||
return 0;
|
||||
|
||||
case PTYPE_FAULT:
|
||||
rpc_recv_fault_pdu(header);
|
||||
Queue_Enqueue(rpc->client->ReceiveQueue, NULL);
|
||||
return -1;
|
||||
|
||||
case PTYPE_RESPONSE:
|
||||
break;
|
||||
|
||||
default:
|
||||
WLog_ERR(TAG, "unexpected RPC PDU type %d", header->common.ptype);
|
||||
Queue_Enqueue(rpc->client->ReceiveQueue, NULL);
|
||||
@ -157,13 +160,13 @@ int rpc_client_on_fragment_received_event(rdpRpc* rpc)
|
||||
|
||||
if (StubLength == 4)
|
||||
{
|
||||
//WLog_ERR(TAG, "Ignoring TsProxySendToServer Response");
|
||||
//WLog_DBG(TAG, "Got stub length 4 with flags %d and callid %d", header->common.pfc_flags, header->common.call_id);
|
||||
|
||||
/* received a disconnect request from the server? */
|
||||
if ((header->common.call_id == rpc->PipeCallId) && (header->common.pfc_flags & PFC_LAST_FRAG))
|
||||
{
|
||||
TerminateEventArgs e;
|
||||
|
||||
rpc->result = *((UINT32*) &buffer[StubOffset]);
|
||||
|
||||
rpc->context->rdp->disconnect = TRUE;
|
||||
rpc->transport->tsg->state = TSG_STATE_TUNNEL_CLOSE_PENDING;
|
||||
EventArgsInit(&e, "freerdp");
|
||||
@ -194,7 +197,6 @@ int rpc_client_on_fragment_received_event(rdpRpc* rpc)
|
||||
|
||||
if (rpc->VirtualConnection->DefaultOutChannel->ReceiverAvailableWindow < (rpc->ReceiveWindow / 2))
|
||||
{
|
||||
//WLog_ERR(TAG, "Sending Flow Control Ack PDU");
|
||||
rts_send_flow_control_ack_pdu(rpc);
|
||||
}
|
||||
|
||||
@ -238,10 +240,7 @@ int rpc_client_on_read_event(rdpRpc* rpc)
|
||||
RPC_COMMON_FIELDS_LENGTH - Stream_GetPosition(rpc->client->RecvFrag));
|
||||
|
||||
if (status < 0)
|
||||
{
|
||||
WLog_ERR(TAG, "rpc_client_frag_read: error reading header");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!status)
|
||||
return 0;
|
||||
@ -437,6 +436,7 @@ RPC_PDU* rpc_recv_dequeue_pdu(rdpRpc* rpc)
|
||||
RPC_PDU* pdu;
|
||||
DWORD dwMilliseconds;
|
||||
DWORD result;
|
||||
|
||||
dwMilliseconds = rpc->client->SynchronousReceive ? SYNCHRONOUS_TIMEOUT * 4 : 0;
|
||||
result = WaitForSingleObject(Queue_Event(rpc->client->ReceiveQueue), dwMilliseconds);
|
||||
|
||||
@ -449,20 +449,8 @@ RPC_PDU* rpc_recv_dequeue_pdu(rdpRpc* rpc)
|
||||
if (result != WAIT_OBJECT_0)
|
||||
return NULL;
|
||||
|
||||
pdu = (RPC_PDU*)Queue_Dequeue(rpc->client->ReceiveQueue);
|
||||
#ifdef WITH_DEBUG_TSG
|
||||
pdu = (RPC_PDU*) Queue_Dequeue(rpc->client->ReceiveQueue);
|
||||
|
||||
if (pdu)
|
||||
{
|
||||
WLog_DBG(TAG, "Receiving PDU (length: %d, CallId: %d)", pdu->s->length, pdu->CallId);
|
||||
winpr_HexDump(TAG, WLOG_DEBUG, Stream_Buffer(pdu->s), Stream_Length(pdu->s));
|
||||
}
|
||||
else
|
||||
{
|
||||
WLog_DBG(TAG, "Receiving a NULL PDU");
|
||||
}
|
||||
|
||||
#endif
|
||||
return pdu;
|
||||
}
|
||||
|
||||
@ -470,6 +458,7 @@ RPC_PDU* rpc_recv_peek_pdu(rdpRpc* rpc)
|
||||
{
|
||||
DWORD dwMilliseconds;
|
||||
DWORD result;
|
||||
|
||||
dwMilliseconds = rpc->client->SynchronousReceive ? SYNCHRONOUS_TIMEOUT : 0;
|
||||
result = WaitForSingleObject(Queue_Event(rpc->client->ReceiveQueue), dwMilliseconds);
|
||||
|
||||
@ -520,7 +509,10 @@ static void* rpc_client_thread(void* arg)
|
||||
if (WaitForSingleObject(ReadEvent, 0) == WAIT_OBJECT_0)
|
||||
{
|
||||
if (rpc_client_on_read_event(rpc) < 0)
|
||||
{
|
||||
rpc->transport->layer = TRANSPORT_LAYER_CLOSED;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (WaitForSingleObject(Queue_Event(rpc->client->SendQueue), 0) == WAIT_OBJECT_0)
|
||||
|
@ -31,7 +31,7 @@
|
||||
|
||||
#include "rts.h"
|
||||
|
||||
#define TAG FREERDP_TAG("core.gateway.rts")
|
||||
#define TAG FREERDP_TAG("core.gateway")
|
||||
|
||||
/**
|
||||
* [MS-RPCH]: Remote Procedure Call over HTTP Protocol Specification:
|
||||
@ -279,9 +279,7 @@ BOOL rts_connect(rdpRpc* rpc)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
#ifdef WITH_DEBUG_RTS
|
||||
|
||||
static const char* const RTS_CMD_STRINGS[] =
|
||||
const char* const RTS_CMD_STRINGS[] =
|
||||
{
|
||||
"ReceiveWindowSize",
|
||||
"FlowControlAck",
|
||||
@ -300,8 +298,6 @@ static const char* const RTS_CMD_STRINGS[] =
|
||||
"PingTrafficSentNotify"
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* RTS PDU Header
|
||||
*
|
||||
@ -690,7 +686,7 @@ int rts_send_CONN_A1_pdu(rdpRpc* rpc)
|
||||
header.Flags = RTS_FLAG_NONE;
|
||||
header.NumberOfCommands = 4;
|
||||
|
||||
DEBUG_RPC("Sending CONN_A1 RTS PDU");
|
||||
WLog_DBG(TAG, "Sending CONN_A1 RTS PDU");
|
||||
|
||||
rts_generate_cookie((BYTE*) &(rpc->VirtualConnection->Cookie));
|
||||
rts_generate_cookie((BYTE*) &(rpc->VirtualConnection->DefaultOutChannelCookie));
|
||||
@ -746,7 +742,7 @@ int rts_send_CONN_B1_pdu(rdpRpc* rpc)
|
||||
header.Flags = RTS_FLAG_NONE;
|
||||
header.NumberOfCommands = 6;
|
||||
|
||||
DEBUG_RPC("Sending CONN_B1 RTS PDU");
|
||||
WLog_DBG(TAG, "Sending CONN_B1 RTS PDU");
|
||||
|
||||
rts_generate_cookie((BYTE*) &(rpc->VirtualConnection->DefaultInChannelCookie));
|
||||
rts_generate_cookie((BYTE*) &(rpc->VirtualConnection->AssociationGroupId));
|
||||
@ -816,7 +812,7 @@ int rts_send_keep_alive_pdu(rdpRpc* rpc)
|
||||
header.Flags = RTS_FLAG_OTHER_CMD;
|
||||
header.NumberOfCommands = 1;
|
||||
|
||||
DEBUG_RPC("Sending Keep-Alive RTS PDU");
|
||||
WLog_DBG(TAG, "Sending Keep-Alive RTS PDU");
|
||||
|
||||
buffer = (BYTE*) malloc(header.frag_length);
|
||||
if (!buffer)
|
||||
@ -850,7 +846,7 @@ int rts_send_flow_control_ack_pdu(rdpRpc* rpc)
|
||||
header.Flags = RTS_FLAG_OTHER_CMD;
|
||||
header.NumberOfCommands = 2;
|
||||
|
||||
DEBUG_RPC("Sending FlowControlAck RTS PDU");
|
||||
WLog_DBG(TAG, "Sending FlowControlAck RTS PDU");
|
||||
|
||||
BytesReceived = rpc->VirtualConnection->DefaultOutChannel->BytesReceived;
|
||||
AvailableWindow = rpc->VirtualConnection->DefaultOutChannel->AvailableWindowAdvertised;
|
||||
@ -860,6 +856,7 @@ int rts_send_flow_control_ack_pdu(rdpRpc* rpc)
|
||||
rpc->VirtualConnection->DefaultOutChannel->AvailableWindowAdvertised;
|
||||
|
||||
buffer = (BYTE*) malloc(header.frag_length);
|
||||
|
||||
if (!buffer)
|
||||
return -1;
|
||||
|
||||
@ -873,9 +870,10 @@ int rts_send_flow_control_ack_pdu(rdpRpc* rpc)
|
||||
|
||||
if (rpc_in_write(rpc, buffer, length) < 0)
|
||||
{
|
||||
free (buffer);
|
||||
free(buffer);
|
||||
return -1;
|
||||
}
|
||||
|
||||
free(buffer);
|
||||
|
||||
return 0;
|
||||
@ -934,9 +932,9 @@ int rts_recv_flow_control_ack_with_destination_pdu(rdpRpc* rpc, BYTE* buffer, UI
|
||||
&BytesReceived, &AvailableWindow, (BYTE*) &ChannelCookie) + 4;
|
||||
|
||||
#if 0
|
||||
WLog_ERR(TAG, "Destination: %d BytesReceived: %d AvailableWindow: %d",
|
||||
WLog_ERR(TAG, "Destination: %d BytesReceived: %d AvailableWindow: %d",
|
||||
Destination, BytesReceived, AvailableWindow);
|
||||
WLog_ERR(TAG, "ChannelCookie: " RPC_UUID_FORMAT_STRING "", RPC_UUID_FORMAT_ARGUMENTS(ChannelCookie));
|
||||
WLog_ERR(TAG, "ChannelCookie: " RPC_UUID_FORMAT_STRING "", RPC_UUID_FORMAT_ARGUMENTS(ChannelCookie));
|
||||
#endif
|
||||
|
||||
rpc->VirtualConnection->DefaultInChannel->SenderAvailableWindow =
|
||||
@ -956,9 +954,10 @@ int rts_send_ping_pdu(rdpRpc* rpc)
|
||||
header.Flags = RTS_FLAG_PING;
|
||||
header.NumberOfCommands = 0;
|
||||
|
||||
DEBUG_RPC("Sending Ping RTS PDU");
|
||||
WLog_DBG(TAG, "Sending Ping RTS PDU");
|
||||
|
||||
buffer = (BYTE*) malloc(header.frag_length);
|
||||
|
||||
if (!buffer)
|
||||
return -1;
|
||||
|
||||
@ -1051,6 +1050,67 @@ int rts_command_length(rdpRpc* rpc, UINT32 CommandType, BYTE* buffer, UINT32 len
|
||||
return CommandLength;
|
||||
}
|
||||
|
||||
int rts_send_OUT_R1_A3_pdu(rdpRpc* rpc)
|
||||
{
|
||||
BYTE* buffer;
|
||||
rpcconn_rts_hdr_t header;
|
||||
UINT32 ReceiveWindowSize;
|
||||
BYTE* VirtualConnectionCookie;
|
||||
BYTE* PredecessorChannelCookie;
|
||||
BYTE* SuccessorChannelCookie;
|
||||
|
||||
rts_pdu_header_init(&header);
|
||||
header.frag_length = 96;
|
||||
header.Flags = RTS_FLAG_RECYCLE_CHANNEL;
|
||||
header.NumberOfCommands = 5;
|
||||
|
||||
WLog_DBG(TAG, "Sending OUT R1/A3 RTS PDU");
|
||||
|
||||
rts_generate_cookie((BYTE*) &(rpc->VirtualConnection->NonDefaultOutChannelCookie));
|
||||
|
||||
VirtualConnectionCookie = (BYTE*) &(rpc->VirtualConnection->Cookie);
|
||||
PredecessorChannelCookie = (BYTE*) &(rpc->VirtualConnection->DefaultOutChannelCookie);
|
||||
SuccessorChannelCookie = (BYTE*) &(rpc->VirtualConnection->NonDefaultOutChannelCookie);
|
||||
ReceiveWindowSize = rpc->VirtualConnection->DefaultOutChannel->ReceiveWindow;
|
||||
|
||||
buffer = (BYTE*) malloc(header.frag_length);
|
||||
|
||||
if (!buffer)
|
||||
return -1;
|
||||
|
||||
CopyMemory(buffer, ((BYTE*) &header), 20); /* RTS Header (20 bytes) */
|
||||
rts_version_command_write(&buffer[20]); /* Version (8 bytes) */
|
||||
rts_cookie_command_write(&buffer[28], VirtualConnectionCookie); /* VirtualConnectionCookie (20 bytes) */
|
||||
rts_cookie_command_write(&buffer[48], PredecessorChannelCookie); /* PredecessorChannelCookie (20 bytes) */
|
||||
rts_cookie_command_write(&buffer[68], SuccessorChannelCookie); /* SuccessorChannelCookie (20 bytes) */
|
||||
rts_receive_window_size_command_write(&buffer[88], ReceiveWindowSize); /* ReceiveWindowSize (8 bytes) */
|
||||
|
||||
rpc_out_write(rpc, buffer, header.frag_length);
|
||||
|
||||
free(buffer);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int rts_recv_OUT_R1_A2_pdu(rdpRpc* rpc, BYTE* buffer, UINT32 length)
|
||||
{
|
||||
UINT32 offset;
|
||||
UINT32 Destination = 0;
|
||||
|
||||
offset = 24;
|
||||
offset += rts_destination_command_read(rpc, &buffer[offset], length - offset, &Destination) + 4;
|
||||
|
||||
WLog_DBG(TAG, "Destination: %d", Destination);
|
||||
|
||||
WLog_ERR(TAG, "TS Gateway channel recycling is incomplete");
|
||||
|
||||
rpc_http_send_replacement_out_channel_request(rpc);
|
||||
|
||||
rts_send_OUT_R1_A3_pdu(rpc);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int rts_recv_out_of_sequence_pdu(rdpRpc* rpc, BYTE* buffer, UINT32 length)
|
||||
{
|
||||
UINT32 SignatureId;
|
||||
@ -1066,10 +1126,16 @@ int rts_recv_out_of_sequence_pdu(rdpRpc* rpc, BYTE* buffer, UINT32 length)
|
||||
{
|
||||
case RTS_PDU_FLOW_CONTROL_ACK:
|
||||
return rts_recv_flow_control_ack_pdu(rpc, buffer, length);
|
||||
|
||||
case RTS_PDU_FLOW_CONTROL_ACK_WITH_DESTINATION:
|
||||
return rts_recv_flow_control_ack_with_destination_pdu(rpc, buffer, length);
|
||||
|
||||
case RTS_PDU_PING:
|
||||
return rts_send_ping_pdu(rpc);
|
||||
|
||||
case RTS_PDU_OUT_R1_A2:
|
||||
return rts_recv_OUT_R1_A2_pdu(rpc, buffer, length);
|
||||
|
||||
default:
|
||||
WLog_ERR(TAG, "unimplemented signature id: 0x%08X", SignatureId);
|
||||
rts_print_pdu_signature(rpc, &signature);
|
||||
|
@ -145,68 +145,68 @@ RtsPduSignature RTS_PDU_FLOW_CONTROL_ACK_WITH_DESTINATION_SIGNATURE = { RTS_FLAG
|
||||
|
||||
RTS_PDU_SIGNATURE_ENTRY RTS_PDU_SIGNATURE_TABLE[] =
|
||||
{
|
||||
{ RTS_PDU_CONN_A1, &RTS_PDU_CONN_A1_SIGNATURE, "CONN/A1" },
|
||||
{ RTS_PDU_CONN_A2, &RTS_PDU_CONN_A2_SIGNATURE, "CONN/A2" },
|
||||
{ RTS_PDU_CONN_A3, &RTS_PDU_CONN_A3_SIGNATURE, "CONN/A3" },
|
||||
{ RTS_PDU_CONN_A1, FALSE, &RTS_PDU_CONN_A1_SIGNATURE, "CONN/A1" },
|
||||
{ RTS_PDU_CONN_A2, FALSE, &RTS_PDU_CONN_A2_SIGNATURE, "CONN/A2" },
|
||||
{ RTS_PDU_CONN_A3, TRUE, &RTS_PDU_CONN_A3_SIGNATURE, "CONN/A3" },
|
||||
|
||||
{ RTS_PDU_CONN_B1, &RTS_PDU_CONN_B1_SIGNATURE, "CONN/B1" },
|
||||
{ RTS_PDU_CONN_B2, &RTS_PDU_CONN_B2_SIGNATURE, "CONN/B2" },
|
||||
{ RTS_PDU_CONN_B3, &RTS_PDU_CONN_B3_SIGNATURE, "CONN/B3" },
|
||||
{ RTS_PDU_CONN_B1, FALSE, &RTS_PDU_CONN_B1_SIGNATURE, "CONN/B1" },
|
||||
{ RTS_PDU_CONN_B2, FALSE, &RTS_PDU_CONN_B2_SIGNATURE, "CONN/B2" },
|
||||
{ RTS_PDU_CONN_B3, FALSE, &RTS_PDU_CONN_B3_SIGNATURE, "CONN/B3" },
|
||||
|
||||
{ RTS_PDU_CONN_C1, &RTS_PDU_CONN_C1_SIGNATURE, "CONN/C1" },
|
||||
{ RTS_PDU_CONN_C2, &RTS_PDU_CONN_C2_SIGNATURE, "CONN/C2" },
|
||||
{ RTS_PDU_CONN_C1, FALSE, &RTS_PDU_CONN_C1_SIGNATURE, "CONN/C1" },
|
||||
{ RTS_PDU_CONN_C2, TRUE, &RTS_PDU_CONN_C2_SIGNATURE, "CONN/C2" },
|
||||
|
||||
{ RTS_PDU_IN_R1_A1, &RTS_PDU_IN_R1_A1_SIGNATURE, "IN_R1/A1" },
|
||||
{ RTS_PDU_IN_R1_A2, &RTS_PDU_IN_R1_A2_SIGNATURE, "IN_R1/A2" },
|
||||
{ RTS_PDU_IN_R1_A3, &RTS_PDU_IN_R1_A3_SIGNATURE, "IN_R1/A3" },
|
||||
{ RTS_PDU_IN_R1_A4, &RTS_PDU_IN_R1_A4_SIGNATURE, "IN_R1/A4" },
|
||||
{ RTS_PDU_IN_R1_A5, &RTS_PDU_IN_R1_A5_SIGNATURE, "IN_R1/A5" },
|
||||
{ RTS_PDU_IN_R1_A6, &RTS_PDU_IN_R1_A6_SIGNATURE, "IN_R1/A6" },
|
||||
{ RTS_PDU_IN_R1_A1, FALSE, &RTS_PDU_IN_R1_A1_SIGNATURE, "IN_R1/A1" },
|
||||
{ RTS_PDU_IN_R1_A2, FALSE, &RTS_PDU_IN_R1_A2_SIGNATURE, "IN_R1/A2" },
|
||||
{ RTS_PDU_IN_R1_A3, FALSE, &RTS_PDU_IN_R1_A3_SIGNATURE, "IN_R1/A3" },
|
||||
{ RTS_PDU_IN_R1_A4, TRUE, &RTS_PDU_IN_R1_A4_SIGNATURE, "IN_R1/A4" },
|
||||
{ RTS_PDU_IN_R1_A5, TRUE, &RTS_PDU_IN_R1_A5_SIGNATURE, "IN_R1/A5" },
|
||||
{ RTS_PDU_IN_R1_A6, FALSE, &RTS_PDU_IN_R1_A6_SIGNATURE, "IN_R1/A6" },
|
||||
|
||||
{ RTS_PDU_IN_R1_B1, &RTS_PDU_IN_R1_B1_SIGNATURE, "IN_R1/B1" },
|
||||
{ RTS_PDU_IN_R1_B2, &RTS_PDU_IN_R1_B2_SIGNATURE, "IN_R1/B2" },
|
||||
{ RTS_PDU_IN_R1_B1, FALSE, &RTS_PDU_IN_R1_B1_SIGNATURE, "IN_R1/B1" },
|
||||
{ RTS_PDU_IN_R1_B2, FALSE, &RTS_PDU_IN_R1_B2_SIGNATURE, "IN_R1/B2" },
|
||||
|
||||
{ RTS_PDU_IN_R2_A1, &RTS_PDU_IN_R2_A1_SIGNATURE, "IN_R2/A1" },
|
||||
{ RTS_PDU_IN_R2_A2, &RTS_PDU_IN_R2_A2_SIGNATURE, "IN_R2/A2" },
|
||||
{ RTS_PDU_IN_R2_A3, &RTS_PDU_IN_R2_A3_SIGNATURE, "IN_R2/A3" },
|
||||
{ RTS_PDU_IN_R2_A4, &RTS_PDU_IN_R2_A4_SIGNATURE, "IN_R2/A4" },
|
||||
{ RTS_PDU_IN_R2_A5, &RTS_PDU_IN_R2_A5_SIGNATURE, "IN_R2/A5" },
|
||||
{ RTS_PDU_IN_R2_A1, FALSE, &RTS_PDU_IN_R2_A1_SIGNATURE, "IN_R2/A1" },
|
||||
{ RTS_PDU_IN_R2_A2, FALSE, &RTS_PDU_IN_R2_A2_SIGNATURE, "IN_R2/A2" },
|
||||
{ RTS_PDU_IN_R2_A3, FALSE, &RTS_PDU_IN_R2_A3_SIGNATURE, "IN_R2/A3" },
|
||||
{ RTS_PDU_IN_R2_A4, TRUE, &RTS_PDU_IN_R2_A4_SIGNATURE, "IN_R2/A4" },
|
||||
{ RTS_PDU_IN_R2_A5, FALSE, &RTS_PDU_IN_R2_A5_SIGNATURE, "IN_R2/A5" },
|
||||
|
||||
{ RTS_PDU_OUT_R1_A1, &RTS_PDU_OUT_R1_A1_SIGNATURE, "OUT_R1/A1" },
|
||||
{ RTS_PDU_OUT_R1_A2, &RTS_PDU_OUT_R1_A2_SIGNATURE, "OUT_R1/A2" },
|
||||
{ RTS_PDU_OUT_R1_A3, &RTS_PDU_OUT_R1_A3_SIGNATURE, "OUT_R1/A3" },
|
||||
{ RTS_PDU_OUT_R1_A4, &RTS_PDU_OUT_R1_A4_SIGNATURE, "OUT_R1/A4" },
|
||||
{ RTS_PDU_OUT_R1_A5, &RTS_PDU_OUT_R1_A5_SIGNATURE, "OUT_R1/A5" },
|
||||
{ RTS_PDU_OUT_R1_A6, &RTS_PDU_OUT_R1_A6_SIGNATURE, "OUT_R1/A6" },
|
||||
{ RTS_PDU_OUT_R1_A7, &RTS_PDU_OUT_R1_A7_SIGNATURE, "OUT_R1/A7" },
|
||||
{ RTS_PDU_OUT_R1_A8, &RTS_PDU_OUT_R1_A8_SIGNATURE, "OUT_R1/A8" },
|
||||
{ RTS_PDU_OUT_R1_A9, &RTS_PDU_OUT_R1_A9_SIGNATURE, "OUT_R1/A9" },
|
||||
{ RTS_PDU_OUT_R1_A10, &RTS_PDU_OUT_R1_A10_SIGNATURE, "OUT_R1/A10" },
|
||||
{ RTS_PDU_OUT_R1_A11, &RTS_PDU_OUT_R1_A11_SIGNATURE, "OUT_R1/A11" },
|
||||
{ RTS_PDU_OUT_R1_A1, FALSE, &RTS_PDU_OUT_R1_A1_SIGNATURE, "OUT_R1/A1" },
|
||||
{ RTS_PDU_OUT_R1_A2, TRUE, &RTS_PDU_OUT_R1_A2_SIGNATURE, "OUT_R1/A2" },
|
||||
{ RTS_PDU_OUT_R1_A3, FALSE, &RTS_PDU_OUT_R1_A3_SIGNATURE, "OUT_R1/A3" },
|
||||
{ RTS_PDU_OUT_R1_A4, FALSE, &RTS_PDU_OUT_R1_A4_SIGNATURE, "OUT_R1/A4" },
|
||||
{ RTS_PDU_OUT_R1_A5, FALSE, &RTS_PDU_OUT_R1_A5_SIGNATURE, "OUT_R1/A5" },
|
||||
{ RTS_PDU_OUT_R1_A6, TRUE, &RTS_PDU_OUT_R1_A6_SIGNATURE, "OUT_R1/A6" },
|
||||
{ RTS_PDU_OUT_R1_A7, FALSE, &RTS_PDU_OUT_R1_A7_SIGNATURE, "OUT_R1/A7" },
|
||||
{ RTS_PDU_OUT_R1_A8, FALSE, &RTS_PDU_OUT_R1_A8_SIGNATURE, "OUT_R1/A8" },
|
||||
{ RTS_PDU_OUT_R1_A9, FALSE, &RTS_PDU_OUT_R1_A9_SIGNATURE, "OUT_R1/A9" },
|
||||
{ RTS_PDU_OUT_R1_A10, TRUE, &RTS_PDU_OUT_R1_A10_SIGNATURE, "OUT_R1/A10" },
|
||||
{ RTS_PDU_OUT_R1_A11, FALSE, &RTS_PDU_OUT_R1_A11_SIGNATURE, "OUT_R1/A11" },
|
||||
|
||||
{ RTS_PDU_OUT_R2_A1, &RTS_PDU_OUT_R2_A1_SIGNATURE, "OUT_R2/A1" },
|
||||
{ RTS_PDU_OUT_R2_A2, &RTS_PDU_OUT_R2_A2_SIGNATURE, "OUT_R2/A2" },
|
||||
{ RTS_PDU_OUT_R2_A3, &RTS_PDU_OUT_R2_A3_SIGNATURE, "OUT_R2/A3" },
|
||||
{ RTS_PDU_OUT_R2_A4, &RTS_PDU_OUT_R2_A4_SIGNATURE, "OUT_R2/A4" },
|
||||
{ RTS_PDU_OUT_R2_A5, &RTS_PDU_OUT_R2_A5_SIGNATURE, "OUT_R2/A5" },
|
||||
{ RTS_PDU_OUT_R2_A6, &RTS_PDU_OUT_R2_A6_SIGNATURE, "OUT_R2/A6" },
|
||||
{ RTS_PDU_OUT_R2_A7, &RTS_PDU_OUT_R2_A7_SIGNATURE, "OUT_R2/A7" },
|
||||
{ RTS_PDU_OUT_R2_A8, &RTS_PDU_OUT_R2_A8_SIGNATURE, "OUT_R2/A8" },
|
||||
{ RTS_PDU_OUT_R2_A1, FALSE, &RTS_PDU_OUT_R2_A1_SIGNATURE, "OUT_R2/A1" },
|
||||
{ RTS_PDU_OUT_R2_A2, TRUE, &RTS_PDU_OUT_R2_A2_SIGNATURE, "OUT_R2/A2" },
|
||||
{ RTS_PDU_OUT_R2_A3, FALSE, &RTS_PDU_OUT_R2_A3_SIGNATURE, "OUT_R2/A3" },
|
||||
{ RTS_PDU_OUT_R2_A4, FALSE, &RTS_PDU_OUT_R2_A4_SIGNATURE, "OUT_R2/A4" },
|
||||
{ RTS_PDU_OUT_R2_A5, FALSE, &RTS_PDU_OUT_R2_A5_SIGNATURE, "OUT_R2/A5" },
|
||||
{ RTS_PDU_OUT_R2_A6, TRUE, &RTS_PDU_OUT_R2_A6_SIGNATURE, "OUT_R2/A6" },
|
||||
{ RTS_PDU_OUT_R2_A7, FALSE, &RTS_PDU_OUT_R2_A7_SIGNATURE, "OUT_R2/A7" },
|
||||
{ RTS_PDU_OUT_R2_A8, FALSE, &RTS_PDU_OUT_R2_A8_SIGNATURE, "OUT_R2/A8" },
|
||||
|
||||
{ RTS_PDU_OUT_R2_B1, &RTS_PDU_OUT_R2_B1_SIGNATURE, "OUT_R2/B1" },
|
||||
{ RTS_PDU_OUT_R2_B2, &RTS_PDU_OUT_R2_B2_SIGNATURE, "OUT_R2/B2" },
|
||||
{ RTS_PDU_OUT_R2_B3, &RTS_PDU_OUT_R2_B3_SIGNATURE, "OUT_R2/B3" },
|
||||
{ RTS_PDU_OUT_R2_B1, FALSE, &RTS_PDU_OUT_R2_B1_SIGNATURE, "OUT_R2/B1" },
|
||||
{ RTS_PDU_OUT_R2_B2, FALSE, &RTS_PDU_OUT_R2_B2_SIGNATURE, "OUT_R2/B2" },
|
||||
{ RTS_PDU_OUT_R2_B3, TRUE, &RTS_PDU_OUT_R2_B3_SIGNATURE, "OUT_R2/B3" },
|
||||
|
||||
{ RTS_PDU_OUT_R2_C1, &RTS_PDU_OUT_R2_C1_SIGNATURE, "OUT_R2/C1" },
|
||||
{ RTS_PDU_OUT_R2_C1, FALSE, &RTS_PDU_OUT_R2_C1_SIGNATURE, "OUT_R2/C1" },
|
||||
|
||||
{ RTS_PDU_KEEP_ALIVE, &RTS_PDU_KEEP_ALIVE_SIGNATURE, "Keep-Alive" },
|
||||
{ RTS_PDU_PING_TRAFFIC_SENT_NOTIFY, &RTS_PDU_PING_TRAFFIC_SENT_NOTIFY_SIGNATURE, "Ping Traffic Sent Notify" },
|
||||
{ RTS_PDU_ECHO, &RTS_PDU_ECHO_SIGNATURE, "Echo" },
|
||||
{ RTS_PDU_PING, &RTS_PDU_PING_SIGNATURE, "Ping" },
|
||||
{ RTS_PDU_FLOW_CONTROL_ACK, &RTS_PDU_FLOW_CONTROL_ACK_SIGNATURE, "FlowControlAck" },
|
||||
{ RTS_PDU_FLOW_CONTROL_ACK_WITH_DESTINATION, &RTS_PDU_FLOW_CONTROL_ACK_WITH_DESTINATION_SIGNATURE, "FlowControlAckWithDestination" },
|
||||
{ RTS_PDU_KEEP_ALIVE, TRUE, &RTS_PDU_KEEP_ALIVE_SIGNATURE, "Keep-Alive" },
|
||||
{ RTS_PDU_PING_TRAFFIC_SENT_NOTIFY, TRUE, &RTS_PDU_PING_TRAFFIC_SENT_NOTIFY_SIGNATURE, "Ping Traffic Sent Notify" },
|
||||
{ RTS_PDU_ECHO, TRUE, &RTS_PDU_ECHO_SIGNATURE, "Echo" },
|
||||
{ RTS_PDU_PING, TRUE, &RTS_PDU_PING_SIGNATURE, "Ping" },
|
||||
{ RTS_PDU_FLOW_CONTROL_ACK, TRUE, &RTS_PDU_FLOW_CONTROL_ACK_SIGNATURE, "FlowControlAck" },
|
||||
{ RTS_PDU_FLOW_CONTROL_ACK_WITH_DESTINATION, TRUE, &RTS_PDU_FLOW_CONTROL_ACK_WITH_DESTINATION_SIGNATURE, "FlowControlAckWithDestination" },
|
||||
|
||||
{ 0, NULL }
|
||||
{ 0, 0, NULL }
|
||||
};
|
||||
|
||||
BOOL rts_match_pdu_signature(rdpRpc* rpc, RtsPduSignature* signature, rpcconn_rts_hdr_t* rts)
|
||||
@ -296,6 +296,9 @@ UINT32 rts_identify_pdu_signature(rdpRpc* rpc, RtsPduSignature* signature, RTS_P
|
||||
{
|
||||
pSignature = RTS_PDU_SIGNATURE_TABLE[i].Signature;
|
||||
|
||||
if (!RTS_PDU_SIGNATURE_TABLE[i].SignatureClient)
|
||||
continue;
|
||||
|
||||
if (signature->Flags != pSignature->Flags)
|
||||
continue;
|
||||
|
||||
|
@ -37,6 +37,7 @@ struct rts_pdu_signature
|
||||
struct _RTS_PDU_SIGNATURE_ENTRY
|
||||
{
|
||||
UINT32 SignatureId;
|
||||
BOOL SignatureClient;
|
||||
RtsPduSignature* Signature;
|
||||
const char* PduName;
|
||||
};
|
||||
|
@ -132,7 +132,7 @@ DWORD TsProxySendToServer(handle_t IDL_handle, byte pRpcMessage[], UINT32 count,
|
||||
|
||||
if (status <= 0)
|
||||
{
|
||||
WLog_ERR(TAG, "rpc_write failed!");
|
||||
WLog_ERR(TAG, "rpc_write failed!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -146,8 +146,13 @@ BOOL TsProxyCreateTunnelWriteRequest(rdpTsg* tsg)
|
||||
UINT32 length;
|
||||
UINT32 NapCapabilities;
|
||||
rdpRpc* rpc = tsg->rpc;
|
||||
|
||||
length = 108;
|
||||
buffer = (BYTE*) malloc(length);
|
||||
|
||||
if (!buffer)
|
||||
return FALSE;
|
||||
|
||||
*((UINT32*) &buffer[0]) = TSG_PACKET_TYPE_VERSIONCAPS; /* PacketId */
|
||||
*((UINT32*) &buffer[4]) = TSG_PACKET_TYPE_VERSIONCAPS; /* SwitchValue */
|
||||
*((UINT32*) &buffer[8]) = 0x00020000; /* PacketVersionCapsPtr */
|
||||
@ -163,6 +168,7 @@ BOOL TsProxyCreateTunnelWriteRequest(rdpTsg* tsg)
|
||||
*((UINT32*) &buffer[32]) = 0x00000001; /* MaxCount */
|
||||
*((UINT32*) &buffer[36]) = TSG_CAPABILITY_TYPE_NAP; /* CapabilityType */
|
||||
*((UINT32*) &buffer[40]) = TSG_CAPABILITY_TYPE_NAP; /* SwitchValue */
|
||||
|
||||
NapCapabilities =
|
||||
TSG_NAP_CAPABILITY_QUAR_SOH |
|
||||
TSG_NAP_CAPABILITY_IDLE_TIMEOUT |
|
||||
@ -178,7 +184,7 @@ BOOL TsProxyCreateTunnelWriteRequest(rdpTsg* tsg)
|
||||
* However, reduced capabilities may break connectivity with servers enforcing features, such as
|
||||
* "Only allow connections from Remote Desktop Services clients that support RD Gateway messaging"
|
||||
*/
|
||||
//NapCapabilities = TSG_NAP_CAPABILITY_IDLE_TIMEOUT;
|
||||
|
||||
*((UINT32*) &buffer[44]) = NapCapabilities; /* capabilities */
|
||||
CopyMemory(&buffer[48], TsProxyCreateTunnelUnknownTrailerBytes, 60);
|
||||
status = rpc_write(rpc, buffer, length, TsProxyCreateTunnelOpnum);
|
||||
@ -230,7 +236,7 @@ BOOL TsProxyCreateTunnelReadResponse(rdpTsg* tsg, RPC_PDU* pdu)
|
||||
{
|
||||
packetCapsResponse = (PTSG_PACKET_CAPS_RESPONSE) calloc(1, sizeof(TSG_PACKET_CAPS_RESPONSE));
|
||||
|
||||
if (!packetCapsResponse) // TODO: correct cleanup
|
||||
if (!packetCapsResponse)
|
||||
{
|
||||
free(packet);
|
||||
return FALSE;
|
||||
@ -253,7 +259,6 @@ BOOL TsProxyCreateTunnelReadResponse(rdpTsg* tsg, RPC_PDU* pdu)
|
||||
IsMessagePresent = *((UINT32*) &buffer[offset]);
|
||||
offset += 4;
|
||||
MessageSwitchValue = *((UINT32*) &buffer[offset]);
|
||||
DEBUG_TSG("IsMessagePresent %d MessageSwitchValue %d", IsMessagePresent, MessageSwitchValue);
|
||||
offset += 4;
|
||||
}
|
||||
|
||||
@ -282,7 +287,7 @@ BOOL TsProxyCreateTunnelReadResponse(rdpTsg* tsg, RPC_PDU* pdu)
|
||||
|
||||
versionCaps = (PTSG_PACKET_VERSIONCAPS) calloc(1, sizeof(TSG_PACKET_VERSIONCAPS));
|
||||
|
||||
if (!versionCaps) // TODO: correct cleanup
|
||||
if (!versionCaps)
|
||||
{
|
||||
free(packetCapsResponse);
|
||||
free(packet);
|
||||
@ -296,7 +301,7 @@ BOOL TsProxyCreateTunnelReadResponse(rdpTsg* tsg, RPC_PDU* pdu)
|
||||
|
||||
if (versionCaps->tsgHeader.ComponentId != TS_GATEWAY_TRANSPORT)
|
||||
{
|
||||
WLog_ERR(TAG, "Unexpected ComponentId: 0x%04X, Expected TS_GATEWAY_TRANSPORT",
|
||||
WLog_ERR(TAG, "Unexpected ComponentId: 0x%04X, Expected TS_GATEWAY_TRANSPORT",
|
||||
versionCaps->tsgHeader.ComponentId);
|
||||
free(packetCapsResponse);
|
||||
free(versionCaps);
|
||||
@ -330,7 +335,7 @@ BOOL TsProxyCreateTunnelReadResponse(rdpTsg* tsg, RPC_PDU* pdu)
|
||||
|
||||
if ((SwitchValue != TSG_CAPABILITY_TYPE_NAP) || (tsgCaps->capabilityType != TSG_CAPABILITY_TYPE_NAP))
|
||||
{
|
||||
WLog_ERR(TAG, "Unexpected CapabilityType: 0x%08X, Expected TSG_CAPABILITY_TYPE_NAP",
|
||||
WLog_ERR(TAG, "Unexpected CapabilityType: 0x%08X, Expected TSG_CAPABILITY_TYPE_NAP",
|
||||
tsgCaps->capabilityType);
|
||||
free(tsgCaps);
|
||||
free(versionCaps);
|
||||
@ -361,7 +366,7 @@ BOOL TsProxyCreateTunnelReadResponse(rdpTsg* tsg, RPC_PDU* pdu)
|
||||
|
||||
if (MsgBytes > TSG_MESSAGING_MAX_MESSAGE_LENGTH)
|
||||
{
|
||||
WLog_ERR(TAG, "Out of Spec Message Length %d", MsgBytes);
|
||||
WLog_ERR(TAG, "Out of Spec Message Length %d", MsgBytes);
|
||||
free(tsgCaps);
|
||||
free(versionCaps);
|
||||
free(packetCapsResponse);
|
||||
@ -371,13 +376,15 @@ BOOL TsProxyCreateTunnelReadResponse(rdpTsg* tsg, RPC_PDU* pdu)
|
||||
|
||||
offset += MsgBytes;
|
||||
break;
|
||||
|
||||
case TSG_ASYNC_MESSAGE_REAUTH:
|
||||
rpc_offset_align(&offset, 8);
|
||||
offset += 8; // UINT64 TunnelContext, not to be confused with
|
||||
// the ContextHandle TunnelContext below.
|
||||
break;
|
||||
|
||||
default:
|
||||
WLog_ERR(TAG, "Unexpected Message Type: 0x%X", (int) MessageSwitchValue);
|
||||
WLog_ERR(TAG, "Unexpected Message Type: 0x%X", (int) MessageSwitchValue);
|
||||
free(tsgCaps);
|
||||
free(versionCaps);
|
||||
free(packetCapsResponse);
|
||||
@ -392,10 +399,7 @@ BOOL TsProxyCreateTunnelReadResponse(rdpTsg* tsg, RPC_PDU* pdu)
|
||||
offset += 20;
|
||||
// UINT32 TunnelId
|
||||
// HRESULT ReturnValue
|
||||
#ifdef WITH_DEBUG_TSG
|
||||
WLog_DBG(TAG, "TSG TunnelContext:");
|
||||
winpr_HexDump(TAG, WLOG_DEBUG, (void*) &tsg->TunnelContext, 20);
|
||||
#endif
|
||||
|
||||
free(tsgCaps);
|
||||
free(versionCaps);
|
||||
free(packetCapsResponse);
|
||||
@ -404,7 +408,7 @@ BOOL TsProxyCreateTunnelReadResponse(rdpTsg* tsg, RPC_PDU* pdu)
|
||||
{
|
||||
packetQuarEncResponse = (PTSG_PACKET_QUARENC_RESPONSE) calloc(1, sizeof(TSG_PACKET_QUARENC_RESPONSE));
|
||||
|
||||
if (!packetQuarEncResponse) // TODO: handle cleanup
|
||||
if (!packetQuarEncResponse)
|
||||
{
|
||||
free(packet);
|
||||
return FALSE;
|
||||
@ -443,7 +447,7 @@ BOOL TsProxyCreateTunnelReadResponse(rdpTsg* tsg, RPC_PDU* pdu)
|
||||
|
||||
versionCaps = (PTSG_PACKET_VERSIONCAPS) calloc(1, sizeof(TSG_PACKET_VERSIONCAPS));
|
||||
|
||||
if (!versionCaps) // TODO: handle cleanup
|
||||
if (!versionCaps)
|
||||
{
|
||||
free(packetQuarEncResponse);
|
||||
free(packet);
|
||||
@ -457,7 +461,7 @@ BOOL TsProxyCreateTunnelReadResponse(rdpTsg* tsg, RPC_PDU* pdu)
|
||||
|
||||
if (versionCaps->tsgHeader.ComponentId != TS_GATEWAY_TRANSPORT)
|
||||
{
|
||||
WLog_ERR(TAG, "Unexpected ComponentId: 0x%04X, Expected TS_GATEWAY_TRANSPORT",
|
||||
WLog_ERR(TAG, "Unexpected ComponentId: 0x%04X, Expected TS_GATEWAY_TRANSPORT",
|
||||
versionCaps->tsgHeader.ComponentId);
|
||||
free(versionCaps);
|
||||
free(packetQuarEncResponse);
|
||||
@ -482,16 +486,13 @@ BOOL TsProxyCreateTunnelReadResponse(rdpTsg* tsg, RPC_PDU* pdu)
|
||||
CopyMemory(&tsg->TunnelContext.ContextType, &buffer[offset], 4); /* ContextType */
|
||||
CopyMemory(tsg->TunnelContext.ContextUuid, &buffer[offset + 4], 16); /* ContextUuid */
|
||||
offset += 20;
|
||||
#ifdef WITH_DEBUG_TSG
|
||||
WLog_DBG(TAG, "TSG TunnelContext:");
|
||||
winpr_HexDump(TAG, WLOG_DEBUG, (void*) &tsg->TunnelContext, 20);
|
||||
#endif
|
||||
|
||||
free(versionCaps);
|
||||
free(packetQuarEncResponse);
|
||||
}
|
||||
else
|
||||
{
|
||||
WLog_ERR(TAG, "Unexpected PacketId: 0x%08X, Expected TSG_PACKET_TYPE_CAPS_RESPONSE "
|
||||
WLog_ERR(TAG, "Unexpected PacketId: 0x%08X, Expected TSG_PACKET_TYPE_CAPS_RESPONSE "
|
||||
"or TSG_PACKET_TYPE_QUARENC_RESPONSE", packet->packetId);
|
||||
free(packet);
|
||||
return FALSE;
|
||||
@ -515,11 +516,12 @@ BOOL TsProxyCreateTunnel(rdpTsg* tsg, PTSG_PACKET tsgPacket, PTSG_PACKET* tsgPac
|
||||
* [out] unsigned long* tunnelId
|
||||
* );
|
||||
*/
|
||||
DEBUG_TSG("");
|
||||
|
||||
WLog_DBG(TAG, "TsProxyCreateTunnel");
|
||||
|
||||
if (!TsProxyCreateTunnelWriteRequest(tsg))
|
||||
{
|
||||
WLog_ERR(TAG, "error writing request");
|
||||
WLog_ERR(TAG, "error writing request");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@ -536,12 +538,18 @@ BOOL TsProxyAuthorizeTunnelWriteRequest(rdpTsg* tsg, PTUNNEL_CONTEXT_HANDLE_NOSE
|
||||
UINT32 offset;
|
||||
CONTEXT_HANDLE* handle;
|
||||
rdpRpc* rpc = tsg->rpc;
|
||||
|
||||
count = _wcslen(tsg->MachineName) + 1;
|
||||
offset = 64 + (count * 2);
|
||||
rpc_offset_align(&offset, 4);
|
||||
offset += 4;
|
||||
length = offset;
|
||||
|
||||
buffer = (BYTE*) malloc(length);
|
||||
|
||||
if (!buffer)
|
||||
return FALSE;
|
||||
|
||||
/* TunnelContext */
|
||||
handle = (CONTEXT_HANDLE*) tunnelContext;
|
||||
CopyMemory(&buffer[0], &handle->ContextType, 4); /* ContextType */
|
||||
@ -583,6 +591,7 @@ BOOL TsProxyAuthorizeTunnelReadResponse(rdpTsg* tsg, RPC_PDU* pdu)
|
||||
UINT32 Pointer;
|
||||
UINT32 SizeValue;
|
||||
UINT32 SwitchValue;
|
||||
UINT32 idleTimeout;
|
||||
PTSG_PACKET packet;
|
||||
rdpRpc* rpc = tsg->rpc;
|
||||
PTSG_PACKET_RESPONSE packetResponse;
|
||||
@ -596,37 +605,43 @@ BOOL TsProxyAuthorizeTunnelReadResponse(rdpTsg* tsg, RPC_PDU* pdu)
|
||||
if (!(pdu->Flags & RPC_PDU_FLAG_STUB))
|
||||
buffer = &buffer[24];
|
||||
|
||||
packet = (PTSG_PACKET) malloc(sizeof(TSG_PACKET));
|
||||
ZeroMemory(packet, sizeof(TSG_PACKET));
|
||||
packet = (PTSG_PACKET) calloc(1, sizeof(TSG_PACKET));
|
||||
|
||||
if (!packet)
|
||||
return FALSE;
|
||||
|
||||
offset = 4;
|
||||
packet->packetId = *((UINT32*) &buffer[offset]); /* PacketId */
|
||||
SwitchValue = *((UINT32*) &buffer[offset + 4]); /* SwitchValue */
|
||||
|
||||
if (packet->packetId == E_PROXY_NAP_ACCESSDENIED)
|
||||
{
|
||||
WLog_ERR(TAG, "status: E_PROXY_NAP_ACCESSDENIED (0x%08X)", E_PROXY_NAP_ACCESSDENIED);
|
||||
WLog_ERR(TAG, "Ensure that the Gateway Connection Authorization Policy is correct");
|
||||
WLog_ERR(TAG, "status: E_PROXY_NAP_ACCESSDENIED (0x%08X)", E_PROXY_NAP_ACCESSDENIED);
|
||||
WLog_ERR(TAG, "Ensure that the Gateway Connection Authorization Policy is correct");
|
||||
free(packet);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ((packet->packetId != TSG_PACKET_TYPE_RESPONSE) || (SwitchValue != TSG_PACKET_TYPE_RESPONSE))
|
||||
{
|
||||
WLog_ERR(TAG, "Unexpected PacketId: 0x%08X, Expected TSG_PACKET_TYPE_RESPONSE",
|
||||
WLog_ERR(TAG, "Unexpected PacketId: 0x%08X, Expected TSG_PACKET_TYPE_RESPONSE",
|
||||
packet->packetId);
|
||||
free(packet);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
packetResponse = (PTSG_PACKET_RESPONSE) malloc(sizeof(TSG_PACKET_RESPONSE));
|
||||
ZeroMemory(packetResponse, sizeof(TSG_PACKET_RESPONSE));
|
||||
packetResponse = (PTSG_PACKET_RESPONSE) calloc(1, sizeof(TSG_PACKET_RESPONSE));
|
||||
|
||||
if (!packetResponse)
|
||||
return FALSE;
|
||||
|
||||
packet->tsgPacket.packetResponse = packetResponse;
|
||||
Pointer = *((UINT32*) &buffer[offset + 8]); /* PacketResponsePtr */
|
||||
packetResponse->flags = *((UINT32*) &buffer[offset + 12]); /* Flags */
|
||||
|
||||
if (packetResponse->flags != TSG_PACKET_TYPE_QUARREQUEST)
|
||||
{
|
||||
WLog_ERR(TAG, "Unexpected Packet Response Flags: 0x%08X, Expected TSG_PACKET_TYPE_QUARREQUEST",
|
||||
WLog_ERR(TAG, "Unexpected Packet Response Flags: 0x%08X, Expected TSG_PACKET_TYPE_QUARREQUEST",
|
||||
packetResponse->flags);
|
||||
free(packet);
|
||||
free(packetResponse);
|
||||
@ -650,17 +665,28 @@ BOOL TsProxyAuthorizeTunnelReadResponse(rdpTsg* tsg, RPC_PDU* pdu)
|
||||
|
||||
if (SizeValue != packetResponse->responseDataLen)
|
||||
{
|
||||
WLog_ERR(TAG, "Unexpected size value: %d, expected: %d",
|
||||
WLog_ERR(TAG, "Unexpected size value: %d, expected: %d",
|
||||
SizeValue, packetResponse->responseDataLen);
|
||||
free(packetResponse);
|
||||
free(packet);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
offset += SizeValue; /* ResponseData */
|
||||
|
||||
if (SizeValue == 4)
|
||||
{
|
||||
idleTimeout = *((UINT32*) &buffer[offset]);
|
||||
offset += 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
offset += SizeValue; /* ResponseData */
|
||||
}
|
||||
|
||||
rpc_client_receive_pool_return(rpc, pdu);
|
||||
|
||||
free(packetResponse);
|
||||
free(packet);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -677,11 +703,12 @@ BOOL TsProxyAuthorizeTunnel(rdpTsg* tsg, PTUNNEL_CONTEXT_HANDLE_NOSERIALIZE tunn
|
||||
* );
|
||||
*
|
||||
*/
|
||||
DEBUG_TSG("");
|
||||
|
||||
WLog_DBG(TAG, "TsProxyAuthorizeTunnel");
|
||||
|
||||
if (!TsProxyAuthorizeTunnelWriteRequest(tsg, tunnelContext))
|
||||
{
|
||||
WLog_ERR(TAG, "error writing request");
|
||||
WLog_ERR(TAG, "error writing request");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@ -695,8 +722,13 @@ BOOL TsProxyMakeTunnelCallWriteRequest(rdpTsg* tsg, PTUNNEL_CONTEXT_HANDLE_NOSER
|
||||
UINT32 length;
|
||||
CONTEXT_HANDLE* handle;
|
||||
rdpRpc* rpc = tsg->rpc;
|
||||
|
||||
length = 40;
|
||||
buffer = (BYTE*) malloc(length);
|
||||
|
||||
if (!buffer)
|
||||
return FALSE;
|
||||
|
||||
/* TunnelContext */
|
||||
handle = (CONTEXT_HANDLE*) tunnelContext;
|
||||
CopyMemory(&buffer[0], &handle->ContextType, 4); /* ContextType */
|
||||
@ -754,14 +786,17 @@ BOOL TsProxyMakeTunnelCallReadResponse(rdpTsg* tsg, RPC_PDU* pdu)
|
||||
|
||||
if ((packet->packetId != TSG_PACKET_TYPE_MESSAGE_PACKET) || (SwitchValue != TSG_PACKET_TYPE_MESSAGE_PACKET))
|
||||
{
|
||||
WLog_ERR(TAG, "Unexpected PacketId: 0x%08X, Expected TSG_PACKET_TYPE_MESSAGE_PACKET",
|
||||
WLog_ERR(TAG, "Unexpected PacketId: 0x%08X, Expected TSG_PACKET_TYPE_MESSAGE_PACKET",
|
||||
packet->packetId);
|
||||
free(packet);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
packetMsgResponse = (PTSG_PACKET_MSG_RESPONSE) malloc(sizeof(TSG_PACKET_MSG_RESPONSE));
|
||||
ZeroMemory(packetMsgResponse, sizeof(TSG_PACKET_MSG_RESPONSE));
|
||||
packetMsgResponse = (PTSG_PACKET_MSG_RESPONSE) calloc(1, sizeof(TSG_PACKET_MSG_RESPONSE));
|
||||
|
||||
if (!packetMsgResponse)
|
||||
return FALSE;
|
||||
|
||||
packet->tsgPacket.packetMsgResponse = packetMsgResponse;
|
||||
Pointer = *((UINT32*) &buffer[offset + 8]); /* PacketMsgResponsePtr */
|
||||
packetMsgResponse->msgID = *((UINT32*) &buffer[offset + 12]); /* MsgId */
|
||||
@ -772,8 +807,11 @@ BOOL TsProxyMakeTunnelCallReadResponse(rdpTsg* tsg, RPC_PDU* pdu)
|
||||
switch (SwitchValue)
|
||||
{
|
||||
case TSG_ASYNC_MESSAGE_CONSENT_MESSAGE:
|
||||
packetStringMessage = (PTSG_PACKET_STRING_MESSAGE) malloc(sizeof(TSG_PACKET_STRING_MESSAGE));
|
||||
ZeroMemory(packetStringMessage, sizeof(TSG_PACKET_STRING_MESSAGE));
|
||||
packetStringMessage = (PTSG_PACKET_STRING_MESSAGE) calloc(1, sizeof(TSG_PACKET_STRING_MESSAGE));
|
||||
|
||||
if (!packetStringMessage)
|
||||
return FALSE;
|
||||
|
||||
packetMsgResponse->messagePacket.consentMessage = packetStringMessage;
|
||||
Pointer = *((UINT32*) &buffer[offset + 28]); /* ConsentMessagePtr */
|
||||
packetStringMessage->isDisplayMandatory = *((INT32*) &buffer[offset + 32]); /* IsDisplayMandatory */
|
||||
@ -784,12 +822,16 @@ BOOL TsProxyMakeTunnelCallReadResponse(rdpTsg* tsg, RPC_PDU* pdu)
|
||||
/* Offset */
|
||||
ActualCount = *((UINT32*) &buffer[offset + 56]); /* ActualCount */
|
||||
ConvertFromUnicode(CP_UTF8, 0, (WCHAR*) &buffer[offset + 60], ActualCount, &messageText, 0, NULL, NULL);
|
||||
WLog_ERR(TAG, "Consent Message: %s", messageText);
|
||||
WLog_ERR(TAG, "Consent Message: %s", messageText);
|
||||
free(messageText);
|
||||
break;
|
||||
|
||||
case TSG_ASYNC_MESSAGE_SERVICE_MESSAGE:
|
||||
packetStringMessage = (PTSG_PACKET_STRING_MESSAGE) malloc(sizeof(TSG_PACKET_STRING_MESSAGE));
|
||||
ZeroMemory(packetStringMessage, sizeof(TSG_PACKET_STRING_MESSAGE));
|
||||
packetStringMessage = (PTSG_PACKET_STRING_MESSAGE) calloc(1, sizeof(TSG_PACKET_STRING_MESSAGE));
|
||||
|
||||
if (!packetStringMessage)
|
||||
return FALSE;
|
||||
|
||||
packetMsgResponse->messagePacket.serviceMessage = packetStringMessage;
|
||||
Pointer = *((UINT32*) &buffer[offset + 28]); /* ServiceMessagePtr */
|
||||
packetStringMessage->isDisplayMandatory = *((INT32*) &buffer[offset + 32]); /* IsDisplayMandatory */
|
||||
@ -800,18 +842,22 @@ BOOL TsProxyMakeTunnelCallReadResponse(rdpTsg* tsg, RPC_PDU* pdu)
|
||||
/* Offset */
|
||||
ActualCount = *((UINT32*) &buffer[offset + 56]); /* ActualCount */
|
||||
ConvertFromUnicode(CP_UTF8, 0, (WCHAR*) &buffer[offset + 60], ActualCount, &messageText, 0, NULL, NULL);
|
||||
WLog_ERR(TAG, "Service Message: %s", messageText);
|
||||
WLog_ERR(TAG, "Service Message: %s", messageText);
|
||||
free(messageText);
|
||||
break;
|
||||
|
||||
case TSG_ASYNC_MESSAGE_REAUTH:
|
||||
packetReauthMessage = (PTSG_PACKET_REAUTH_MESSAGE) malloc(sizeof(TSG_PACKET_REAUTH_MESSAGE));
|
||||
ZeroMemory(packetReauthMessage, sizeof(TSG_PACKET_REAUTH_MESSAGE));
|
||||
packetReauthMessage = (PTSG_PACKET_REAUTH_MESSAGE) calloc(1, sizeof(TSG_PACKET_REAUTH_MESSAGE));
|
||||
|
||||
if (!packetReauthMessage)
|
||||
return FALSE;
|
||||
|
||||
packetMsgResponse->messagePacket.reauthMessage = packetReauthMessage;
|
||||
Pointer = *((UINT32*) &buffer[offset + 28]); /* ReauthMessagePtr */
|
||||
break;
|
||||
|
||||
default:
|
||||
WLog_ERR(TAG, "unexpected message type: %d",
|
||||
SwitchValue);
|
||||
WLog_ERR(TAG, "unexpected message type: %d", SwitchValue);
|
||||
rc = FALSE;
|
||||
break;
|
||||
}
|
||||
@ -845,11 +891,12 @@ BOOL TsProxyMakeTunnelCall(rdpTsg* tsg, PTUNNEL_CONTEXT_HANDLE_NOSERIALIZE tunne
|
||||
* [out, ref] PTSG_PACKET* tsgPacketResponse
|
||||
* );
|
||||
*/
|
||||
DEBUG_TSG("");
|
||||
|
||||
WLog_DBG(TAG, "TsProxyMakeTunnelCall");
|
||||
|
||||
if (!TsProxyMakeTunnelCallWriteRequest(tsg, tunnelContext, procId))
|
||||
{
|
||||
WLog_ERR(TAG, "error writing request");
|
||||
WLog_ERR(TAG, "error writing request");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@ -865,10 +912,7 @@ BOOL TsProxyCreateChannelWriteRequest(rdpTsg* tsg, PTUNNEL_CONTEXT_HANDLE_NOSERI
|
||||
CONTEXT_HANDLE* handle;
|
||||
rdpRpc* rpc = tsg->rpc;
|
||||
count = _wcslen(tsg->Hostname) + 1;
|
||||
#ifdef WITH_DEBUG_TSG
|
||||
WLog_DBG(TAG, "ResourceName:");
|
||||
winpr_HexDump(TAG, WLOG_DEBUG, (BYTE*) tsg->Hostname, (count - 1) * 2);
|
||||
#endif
|
||||
|
||||
length = 60 + (count * 2);
|
||||
buffer = (BYTE*) malloc(length);
|
||||
|
||||
@ -923,11 +967,9 @@ BOOL TsProxyCreateChannelReadResponse(rdpTsg* tsg, RPC_PDU* pdu)
|
||||
/* ChannelContext (20 bytes) */
|
||||
CopyMemory(&tsg->ChannelContext.ContextType, &buffer[offset], 4); /* ContextType (4 bytes) */
|
||||
CopyMemory(tsg->ChannelContext.ContextUuid, &buffer[offset + 4], 16); /* ContextUuid (16 bytes) */
|
||||
#ifdef WITH_DEBUG_TSG
|
||||
WLog_DBG(TAG, "ChannelContext:");
|
||||
winpr_HexDump(TAG, WLOG_DEBUG, (void*) &tsg->ChannelContext, 20);
|
||||
#endif
|
||||
|
||||
rpc_client_receive_pool_return(rpc, pdu);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -944,11 +986,12 @@ BOOL TsProxyCreateChannel(rdpTsg* tsg, PTUNNEL_CONTEXT_HANDLE_NOSERIALIZE tunnel
|
||||
* [out] unsigned long* channelId
|
||||
* );
|
||||
*/
|
||||
DEBUG_TSG("");
|
||||
|
||||
WLog_DBG(TAG, "TsProxyCreateChannel");
|
||||
|
||||
if (!TsProxyCreateChannelWriteRequest(tsg, tunnelContext))
|
||||
{
|
||||
WLog_ERR(TAG, "error writing request");
|
||||
WLog_ERR(TAG, "error writing request");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@ -961,8 +1004,13 @@ BOOL TsProxyCloseChannelWriteRequest(rdpTsg* tsg, PCHANNEL_CONTEXT_HANDLE_NOSERI
|
||||
BYTE* buffer;
|
||||
UINT32 length;
|
||||
rdpRpc* rpc = tsg->rpc;
|
||||
|
||||
length = 20;
|
||||
buffer = (BYTE*) malloc(length);
|
||||
|
||||
if (!buffer)
|
||||
return FALSE;
|
||||
|
||||
/* TunnelContext */
|
||||
CopyMemory(&buffer[0], &tsg->ChannelContext.ContextType, 4); /* ContextType */
|
||||
CopyMemory(&buffer[4], tsg->ChannelContext.ContextUuid, 16); /* ContextUuid */
|
||||
@ -1000,22 +1048,24 @@ BOOL TsProxyCloseChannelReadResponse(rdpTsg* tsg, RPC_PDU* pdu)
|
||||
HRESULT TsProxyCloseChannel(rdpTsg* tsg, PCHANNEL_CONTEXT_HANDLE_NOSERIALIZE* context)
|
||||
{
|
||||
RPC_PDU* pdu = NULL;
|
||||
|
||||
/**
|
||||
* HRESULT TsProxyCloseChannel(
|
||||
* [in, out] PCHANNEL_CONTEXT_HANDLE_NOSERIALIZE* context
|
||||
* );
|
||||
*/
|
||||
DEBUG_TSG("");
|
||||
|
||||
WLog_DBG(TAG, "TsProxyCloseChannel");
|
||||
|
||||
if (!TsProxyCloseChannelWriteRequest(tsg, context))
|
||||
{
|
||||
WLog_ERR(TAG, "error writing request");
|
||||
WLog_ERR(TAG, "error writing request");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!TsProxyCloseChannelReadResponse(tsg, pdu))
|
||||
{
|
||||
WLog_ERR(TAG, "error reading response");
|
||||
WLog_ERR(TAG, "error reading response");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@ -1028,8 +1078,13 @@ BOOL TsProxyCloseTunnelWriteRequest(rdpTsg* tsg, PTUNNEL_CONTEXT_HANDLE_SERIALIZ
|
||||
BYTE* buffer;
|
||||
UINT32 length;
|
||||
rdpRpc* rpc = tsg->rpc;
|
||||
|
||||
length = 20;
|
||||
buffer = (BYTE*) malloc(length);
|
||||
|
||||
if (!buffer)
|
||||
return FALSE;
|
||||
|
||||
/* TunnelContext */
|
||||
CopyMemory(&buffer[0], &tsg->TunnelContext.ContextType, 4); /* ContextType */
|
||||
CopyMemory(&buffer[4], tsg->TunnelContext.ContextUuid, 16); /* ContextUuid */
|
||||
@ -1048,6 +1103,7 @@ BOOL TsProxyCloseTunnelReadResponse(rdpTsg* tsg, RPC_PDU* pdu)
|
||||
UINT32 length;
|
||||
UINT32 offset;
|
||||
rdpRpc* rpc = tsg->rpc;
|
||||
|
||||
pdu = rpc_recv_dequeue_pdu(rpc);
|
||||
|
||||
if (!pdu)
|
||||
@ -1067,22 +1123,24 @@ BOOL TsProxyCloseTunnelReadResponse(rdpTsg* tsg, RPC_PDU* pdu)
|
||||
HRESULT TsProxyCloseTunnel(rdpTsg* tsg, PTUNNEL_CONTEXT_HANDLE_SERIALIZE* context)
|
||||
{
|
||||
RPC_PDU* pdu = NULL;
|
||||
|
||||
/**
|
||||
* HRESULT TsProxyCloseTunnel(
|
||||
* [in, out] PTUNNEL_CONTEXT_HANDLE_SERIALIZE* context
|
||||
* );
|
||||
*/
|
||||
DEBUG_TSG("");
|
||||
|
||||
WLog_DBG(TAG, "TsProxyCloseTunnel");
|
||||
|
||||
if (!TsProxyCloseTunnelWriteRequest(tsg, context))
|
||||
{
|
||||
WLog_ERR(TAG, "error writing request");
|
||||
WLog_ERR(TAG, "error writing request");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!TsProxyCloseTunnelReadResponse(tsg, pdu))
|
||||
{
|
||||
WLog_ERR(TAG, "error reading response");
|
||||
WLog_ERR(TAG, "error reading response");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@ -1095,8 +1153,13 @@ BOOL TsProxySetupReceivePipeWriteRequest(rdpTsg* tsg)
|
||||
BYTE* buffer;
|
||||
UINT32 length;
|
||||
rdpRpc* rpc = tsg->rpc;
|
||||
|
||||
length = 20;
|
||||
buffer = (BYTE*) malloc(length);
|
||||
|
||||
if (!buffer)
|
||||
return FALSE;
|
||||
|
||||
/* ChannelContext */
|
||||
CopyMemory(&buffer[0], &tsg->ChannelContext.ContextType, 4); /* ContextType */
|
||||
CopyMemory(&buffer[4], tsg->ChannelContext.ContextUuid, 16); /* ContextUuid */
|
||||
@ -1116,7 +1179,8 @@ BOOL TsProxySetupReceivePipeReadResponse(rdpTsg* tsg, RPC_PDU* pdu)
|
||||
|
||||
BOOL TsProxySetupReceivePipe(handle_t IDL_handle, BYTE* pRpcMessage)
|
||||
{
|
||||
rdpTsg* tsg;
|
||||
rdpTsg* tsg = (rdpTsg*) IDL_handle;
|
||||
|
||||
/**
|
||||
* OpNum = 8
|
||||
*
|
||||
@ -1124,12 +1188,12 @@ BOOL TsProxySetupReceivePipe(handle_t IDL_handle, BYTE* pRpcMessage)
|
||||
* [in, max_is(32767)] byte pRpcMessage[]
|
||||
* );
|
||||
*/
|
||||
tsg = (rdpTsg*) IDL_handle;
|
||||
DEBUG_TSG("");
|
||||
|
||||
WLog_DBG(TAG, "TsProxySetupReceivePipe");
|
||||
|
||||
if (!TsProxySetupReceivePipeWriteRequest(tsg))
|
||||
{
|
||||
WLog_ERR(TAG, "error writing request");
|
||||
WLog_ERR(TAG, "error writing request");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@ -1159,7 +1223,8 @@ BOOL tsg_connect(rdpTsg* tsg, const char* hostname, UINT16 port)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
DEBUG_TSG("rpc_connect success");
|
||||
WLog_DBG(TAG, "rpc_connect success");
|
||||
|
||||
tsg->state = TSG_STATE_INITIAL;
|
||||
rpc->client->SynchronousSend = TRUE;
|
||||
rpc->client->SynchronousReceive = TRUE;
|
||||
@ -1216,7 +1281,7 @@ BOOL tsg_connect(rdpTsg* tsg, const char* hostname, UINT16 port)
|
||||
|
||||
if (!TsProxyCreateTunnelReadResponse(tsg, pdu))
|
||||
{
|
||||
WLog_ERR(TAG, "error reading response");
|
||||
WLog_ERR(TAG, "error reading response");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@ -1262,7 +1327,7 @@ BOOL tsg_connect(rdpTsg* tsg, const char* hostname, UINT16 port)
|
||||
|
||||
if (!TsProxyAuthorizeTunnelReadResponse(tsg, pdu))
|
||||
{
|
||||
WLog_ERR(TAG, "error reading response");
|
||||
WLog_ERR(TAG, "error reading response");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@ -1302,7 +1367,7 @@ BOOL tsg_connect(rdpTsg* tsg, const char* hostname, UINT16 port)
|
||||
|
||||
if (!pdu)
|
||||
{
|
||||
WLog_ERR(TAG, "error reading response");
|
||||
WLog_ERR(TAG, "error reading response");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@ -1312,7 +1377,7 @@ BOOL tsg_connect(rdpTsg* tsg, const char* hostname, UINT16 port)
|
||||
{
|
||||
if (!TsProxyMakeTunnelCallReadResponse(tsg, pdu))
|
||||
{
|
||||
WLog_ERR(TAG, "error reading response");
|
||||
WLog_ERR(TAG, "error reading response");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@ -1321,7 +1386,7 @@ BOOL tsg_connect(rdpTsg* tsg, const char* hostname, UINT16 port)
|
||||
|
||||
if (!TsProxyCreateChannelReadResponse(tsg, pdu))
|
||||
{
|
||||
WLog_ERR(TAG, "error reading response");
|
||||
WLog_ERR(TAG, "error reading response");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@ -1345,22 +1410,11 @@ BOOL tsg_connect(rdpTsg* tsg, const char* hostname, UINT16 port)
|
||||
if (!TsProxySetupReceivePipe((handle_t) tsg, NULL))
|
||||
return FALSE;
|
||||
|
||||
#if 0
|
||||
pdu = rpc_recv_dequeue_pdu(rpc);
|
||||
|
||||
if (!pdu)
|
||||
return FALSE;
|
||||
|
||||
if (!TsProxySetupReceivePipeReadResponse(tsg, pdu))
|
||||
{
|
||||
WLog_ERR(TAG, "error reading response");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
#endif
|
||||
rpc->client->SynchronousSend = TRUE;
|
||||
rpc->client->SynchronousReceive = TRUE;
|
||||
|
||||
WLog_INFO(TAG, "TS Gateway Connection Success");
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -1385,7 +1439,8 @@ BOOL tsg_disconnect(rdpTsg* tsg)
|
||||
* |<-------------TsProxyCloseTunnel Response----------|
|
||||
* | |
|
||||
*/
|
||||
if (tsg == NULL)
|
||||
|
||||
if (!tsg)
|
||||
return FALSE;
|
||||
|
||||
tsg->rpc->client->SynchronousReceive = TRUE;
|
||||
@ -1417,20 +1472,19 @@ BOOL tsg_disconnect(rdpTsg* tsg)
|
||||
* @return < 0 on error; 0 if not enough data is available (non blocking mode); > 0 bytes to read
|
||||
*/
|
||||
|
||||
|
||||
int tsg_read(rdpTsg* tsg, BYTE* data, UINT32 length)
|
||||
{
|
||||
int CopyLength;
|
||||
rdpRpc* rpc;
|
||||
|
||||
if (tsg == NULL)
|
||||
if (!tsg)
|
||||
return -1;
|
||||
|
||||
rpc = tsg->rpc;
|
||||
|
||||
if (rpc->transport->layer == TRANSPORT_LAYER_CLOSED)
|
||||
{
|
||||
WLog_ERR(TAG, "tsg_read error: connection lost");
|
||||
WLog_ERR(TAG, "tsg_read error: connection lost");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -1451,7 +1505,6 @@ int tsg_read(rdpTsg* tsg, BYTE* data, UINT32 length)
|
||||
return CopyLength;
|
||||
}
|
||||
|
||||
|
||||
do
|
||||
{
|
||||
tsg->pdu = rpc_recv_peek_pdu(rpc);
|
||||
@ -1471,7 +1524,7 @@ int tsg_read(rdpTsg* tsg, BYTE* data, UINT32 length)
|
||||
/* ensure that the transport wasn't already closed - in case of a retry */
|
||||
if (rpc->transport->layer == TRANSPORT_LAYER_CLOSED)
|
||||
{
|
||||
WLog_ERR(TAG, "tsg_read error: connection lost");
|
||||
WLog_ERR(TAG, "tsg_read error: connection lost");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -1502,7 +1555,7 @@ int tsg_write(rdpTsg* tsg, BYTE* data, UINT32 length)
|
||||
|
||||
if (tsg->rpc->transport->layer == TRANSPORT_LAYER_CLOSED)
|
||||
{
|
||||
WLog_ERR(TAG, "error, connection lost");
|
||||
WLog_ERR(TAG, "error, connection lost");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -317,11 +317,4 @@ BOOL tsg_set_blocking_mode(rdpTsg* tsg, BOOL blocking);
|
||||
rdpTsg* tsg_new(rdpTransport* transport);
|
||||
void tsg_free(rdpTsg* tsg);
|
||||
|
||||
#define TSG_TAG FREERDP_TAG("core.gateway.tsg")
|
||||
#ifdef WITH_DEBUG_TSG
|
||||
#define DEBUG_TSG(fmt, ...) WLog_DBG(TSG_TAG, fmt, ## __VA_ARGS__)
|
||||
#else
|
||||
#define DEBUG_TSG(fmt, ...) do { } while (0)
|
||||
#endif
|
||||
|
||||
#endif /* FREERDP_CORE_TSG_H */
|
||||
|
@ -876,7 +876,10 @@ BIO *findBufferedBio(BIO *front)
|
||||
|
||||
int tls_write_all(rdpTls* tls, const BYTE* data, int length)
|
||||
{
|
||||
int status, nchunks, commitedBytes;
|
||||
int i;
|
||||
int status;
|
||||
int nchunks;
|
||||
int committedBytes;
|
||||
rdpTcp *tcp;
|
||||
#ifdef HAVE_POLL_H
|
||||
struct pollfd pollfds;
|
||||
@ -892,7 +895,7 @@ int tls_write_all(rdpTls* tls, const BYTE* data, int length)
|
||||
|
||||
if (!bufferedBio)
|
||||
{
|
||||
WLog_ERR(TAG, "error unable to retrieve the bufferedBio in the BIO chain");
|
||||
WLog_ERR(TAG, "error unable to retrieve the bufferedBio in the BIO chain");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -907,6 +910,7 @@ int tls_write_all(rdpTls* tls, const BYTE* data, int length)
|
||||
|
||||
if (!BIO_should_retry(bio))
|
||||
return -1;
|
||||
|
||||
#ifdef HAVE_POLL_H
|
||||
pollfds.fd = tcp->sockfd;
|
||||
pollfds.revents = 0;
|
||||
@ -922,7 +926,7 @@ int tls_write_all(rdpTls* tls, const BYTE* data, int length)
|
||||
}
|
||||
else
|
||||
{
|
||||
WLog_ERR(TAG, "weird we're blocked but the underlying is not read or write blocked !");
|
||||
WLog_ERR(TAG, "weird we're blocked but the underlying is not read or write blocked !");
|
||||
USleep(10);
|
||||
continue;
|
||||
}
|
||||
@ -950,7 +954,7 @@ int tls_write_all(rdpTls* tls, const BYTE* data, int length)
|
||||
}
|
||||
else
|
||||
{
|
||||
WLog_ERR(TAG, "weird we're blocked but the underlying is not read or write blocked !");
|
||||
WLog_ERR(TAG, "weird we're blocked but the underlying is not read or write blocked !");
|
||||
USleep(10);
|
||||
continue;
|
||||
}
|
||||
@ -966,11 +970,19 @@ int tls_write_all(rdpTls* tls, const BYTE* data, int length)
|
||||
while (TRUE);
|
||||
|
||||
/* make sure the output buffer is empty */
|
||||
commitedBytes = 0;
|
||||
while ((nchunks = ringbuffer_peek(&tcp->xmitBuffer, chunks, ringbuffer_used(&tcp->xmitBuffer))))
|
||||
|
||||
do
|
||||
{
|
||||
int i;
|
||||
|
||||
committedBytes = 0;
|
||||
|
||||
if (ringbuffer_used(&tcp->xmitBuffer) < 1)
|
||||
break;
|
||||
|
||||
nchunks = ringbuffer_peek(&tcp->xmitBuffer, chunks, ringbuffer_used(&tcp->xmitBuffer));
|
||||
|
||||
if (nchunks < 1)
|
||||
break;
|
||||
|
||||
for (i = 0; i < nchunks; i++)
|
||||
{
|
||||
while (chunks[i].size)
|
||||
@ -981,7 +993,7 @@ int tls_write_all(rdpTls* tls, const BYTE* data, int length)
|
||||
{
|
||||
chunks[i].size -= status;
|
||||
chunks[i].data += status;
|
||||
commitedBytes += status;
|
||||
committedBytes += status;
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -1011,14 +1023,17 @@ int tls_write_all(rdpTls* tls, const BYTE* data, int length)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
ringbuffer_commit_read_bytes(&tcp->xmitBuffer, commitedBytes);
|
||||
return length;
|
||||
|
||||
|
||||
ringbuffer_commit_read_bytes(&tcp->xmitBuffer, committedBytes);
|
||||
continue;
|
||||
|
||||
out_fail:
|
||||
ringbuffer_commit_read_bytes(&tcp->xmitBuffer, commitedBytes);
|
||||
return -1;
|
||||
ringbuffer_commit_read_bytes(&tcp->xmitBuffer, committedBytes);
|
||||
return -1;
|
||||
}
|
||||
while (TRUE);
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
int tls_set_alert_code(rdpTls* tls, int level, int description)
|
||||
|
@ -23,47 +23,60 @@
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <winpr/crt.h>
|
||||
#include <freerdp/log.h>
|
||||
|
||||
BOOL ringbuffer_init(RingBuffer *rb, size_t initialSize)
|
||||
#define TAG FREERDP_TAG("utils.ringbuffer")
|
||||
|
||||
BOOL ringbuffer_init(RingBuffer* rb, size_t initialSize)
|
||||
{
|
||||
rb->buffer = malloc(initialSize);
|
||||
|
||||
if (!rb->buffer)
|
||||
return FALSE;
|
||||
|
||||
rb->readPtr = rb->writePtr = 0;
|
||||
rb->initialSize = rb->size = rb->freeSize = initialSize;
|
||||
|
||||
WLog_DBG(TAG, "ringbuffer_init(%p)", rb);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
size_t ringbuffer_used(const RingBuffer *ringbuffer)
|
||||
size_t ringbuffer_used(const RingBuffer* rb)
|
||||
{
|
||||
return ringbuffer->size - ringbuffer->freeSize;
|
||||
return rb->size - rb->freeSize;
|
||||
}
|
||||
|
||||
size_t ringbuffer_capacity(const RingBuffer *ringbuffer)
|
||||
size_t ringbuffer_capacity(const RingBuffer* rb)
|
||||
{
|
||||
return ringbuffer->size;
|
||||
return rb->size;
|
||||
}
|
||||
|
||||
void ringbuffer_destroy(RingBuffer *ringbuffer)
|
||||
void ringbuffer_destroy(RingBuffer* rb)
|
||||
{
|
||||
free(ringbuffer->buffer);
|
||||
ringbuffer->buffer = 0;
|
||||
WLog_DBG(TAG, "ringbuffer_destroy(%p)", rb);
|
||||
|
||||
free(rb->buffer);
|
||||
rb->buffer = NULL;
|
||||
}
|
||||
|
||||
static BOOL ringbuffer_realloc(RingBuffer *rb, size_t targetSize)
|
||||
static BOOL ringbuffer_realloc(RingBuffer* rb, size_t targetSize)
|
||||
{
|
||||
BYTE *newData;
|
||||
BYTE* newData;
|
||||
|
||||
WLog_DBG(TAG, "ringbuffer_realloc(%p): targetSize: %d", rb, targetSize);
|
||||
|
||||
if (rb->writePtr == rb->readPtr)
|
||||
{
|
||||
/* when no size is used we can realloc() and set the heads at the
|
||||
* beginning of the buffer
|
||||
*/
|
||||
newData = (BYTE *)realloc(rb->buffer, targetSize);
|
||||
newData = (BYTE*) realloc(rb->buffer, targetSize);
|
||||
|
||||
if (!newData)
|
||||
return FALSE;
|
||||
|
||||
rb->readPtr = rb->writePtr = 0;
|
||||
rb->buffer = newData;
|
||||
}
|
||||
@ -77,7 +90,8 @@ static BOOL ringbuffer_realloc(RingBuffer *rb, size_t targetSize)
|
||||
* v v
|
||||
* [............|XXXXXXXXXXXXXX|..........]
|
||||
*/
|
||||
newData = (BYTE *)realloc(rb->buffer, targetSize);
|
||||
newData = (BYTE*) realloc(rb->buffer, targetSize);
|
||||
|
||||
if (!newData)
|
||||
return FALSE;
|
||||
|
||||
@ -88,9 +102,11 @@ static BOOL ringbuffer_realloc(RingBuffer *rb, size_t targetSize)
|
||||
/* in case of malloc the read head is moved at the beginning of the new buffer
|
||||
* and the write head is set accordingly
|
||||
*/
|
||||
newData = (BYTE *)malloc(targetSize);
|
||||
newData = (BYTE*) malloc(targetSize);
|
||||
|
||||
if (!newData)
|
||||
return FALSE;
|
||||
|
||||
if (rb->readPtr < rb->writePtr)
|
||||
{
|
||||
/* readPtr writePtr
|
||||
@ -107,12 +123,15 @@ static BOOL ringbuffer_realloc(RingBuffer *rb, size_t targetSize)
|
||||
* v v
|
||||
* [XXXXXXXXXXXX|..............|XXXXXXXXXX]
|
||||
*/
|
||||
BYTE *dst = newData;
|
||||
BYTE* dst = newData;
|
||||
|
||||
memcpy(dst, rb->buffer + rb->readPtr, rb->size - rb->readPtr);
|
||||
dst += (rb->size - rb->readPtr);
|
||||
|
||||
if (rb->writePtr)
|
||||
memcpy(dst, rb->buffer, rb->writePtr);
|
||||
}
|
||||
|
||||
rb->writePtr = rb->size - rb->freeSize;
|
||||
rb->readPtr = 0;
|
||||
free(rb->buffer);
|
||||
@ -121,6 +140,7 @@ static BOOL ringbuffer_realloc(RingBuffer *rb, size_t targetSize)
|
||||
|
||||
rb->freeSize += (targetSize - rb->size);
|
||||
rb->size = targetSize;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -131,11 +151,13 @@ static BOOL ringbuffer_realloc(RingBuffer *rb, size_t targetSize)
|
||||
* @param sz
|
||||
* @return
|
||||
*/
|
||||
BOOL ringbuffer_write(RingBuffer *rb, const BYTE *ptr, size_t sz)
|
||||
BOOL ringbuffer_write(RingBuffer* rb, const BYTE* ptr, size_t sz)
|
||||
{
|
||||
size_t toWrite;
|
||||
size_t remaining;
|
||||
|
||||
WLog_DBG(TAG, "ringbuffer_write(%p): sz: %d", rb, sz);
|
||||
|
||||
if ((rb->freeSize <= sz) && !ringbuffer_realloc(rb, rb->size + sz))
|
||||
return FALSE;
|
||||
|
||||
@ -147,6 +169,7 @@ BOOL ringbuffer_write(RingBuffer *rb, const BYTE *ptr, size_t sz)
|
||||
*/
|
||||
toWrite = sz;
|
||||
remaining = sz;
|
||||
|
||||
if (rb->size - rb->writePtr < sz)
|
||||
toWrite = rb->size - rb->writePtr;
|
||||
|
||||
@ -166,9 +189,10 @@ BOOL ringbuffer_write(RingBuffer *rb, const BYTE *ptr, size_t sz)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
BYTE *ringbuffer_ensure_linear_write(RingBuffer *rb, size_t sz)
|
||||
BYTE* ringbuffer_ensure_linear_write(RingBuffer* rb, size_t sz)
|
||||
{
|
||||
WLog_DBG(TAG, "ringbuffer_ensure_linear_write(%p): sz: %d", rb, sz);
|
||||
|
||||
if (rb->freeSize < sz)
|
||||
{
|
||||
if (!ringbuffer_realloc(rb, rb->size + sz - rb->freeSize + 32))
|
||||
@ -177,7 +201,7 @@ BYTE *ringbuffer_ensure_linear_write(RingBuffer *rb, size_t sz)
|
||||
|
||||
if (rb->writePtr == rb->readPtr)
|
||||
{
|
||||
rb->writePtr = rb->readPtr = 0;
|
||||
rb->writePtr = rb->readPtr = NULL;
|
||||
}
|
||||
|
||||
if (rb->writePtr + sz < rb->size)
|
||||
@ -196,28 +220,40 @@ BYTE *ringbuffer_ensure_linear_write(RingBuffer *rb, size_t sz)
|
||||
return rb->buffer + rb->writePtr;
|
||||
}
|
||||
|
||||
BOOL ringbuffer_commit_written_bytes(RingBuffer *rb, size_t sz)
|
||||
BOOL ringbuffer_commit_written_bytes(RingBuffer* rb, size_t sz)
|
||||
{
|
||||
WLog_DBG(TAG, "ringbuffer_commit_written_bytes(%p): sz: %d", rb, sz);
|
||||
|
||||
if (sz < 1)
|
||||
return TRUE;
|
||||
|
||||
if (rb->writePtr + sz > rb->size)
|
||||
return FALSE;
|
||||
|
||||
rb->writePtr = (rb->writePtr + sz) % rb->size;
|
||||
rb->freeSize -= sz;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int ringbuffer_peek(const RingBuffer *rb, DataChunk chunks[2], size_t sz)
|
||||
int ringbuffer_peek(const RingBuffer* rb, DataChunk chunks[2], size_t sz)
|
||||
{
|
||||
size_t remaining = sz;
|
||||
size_t toRead;
|
||||
int chunkIndex = 0;
|
||||
int ret = 0;
|
||||
int status = 0;
|
||||
|
||||
WLog_DBG(TAG, "ringbuffer_peek(%p): sz: %d", rb, sz);
|
||||
|
||||
if (rb->size - rb->freeSize < sz)
|
||||
if (sz < 1)
|
||||
return 0;
|
||||
|
||||
if ((rb->size - rb->freeSize) < sz)
|
||||
remaining = rb->size - rb->freeSize;
|
||||
|
||||
toRead = remaining;
|
||||
|
||||
if (rb->readPtr + remaining > rb->size)
|
||||
if ((rb->readPtr + remaining) > rb->size)
|
||||
toRead = rb->size - rb->readPtr;
|
||||
|
||||
if (toRead)
|
||||
@ -226,20 +262,26 @@ int ringbuffer_peek(const RingBuffer *rb, DataChunk chunks[2], size_t sz)
|
||||
chunks[0].size = toRead;
|
||||
remaining -= toRead;
|
||||
chunkIndex++;
|
||||
ret++;
|
||||
status++;
|
||||
}
|
||||
|
||||
if (remaining)
|
||||
{
|
||||
chunks[chunkIndex].data = rb->buffer;
|
||||
chunks[chunkIndex].size = remaining;
|
||||
ret++;
|
||||
status++;
|
||||
}
|
||||
return ret;
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
void ringbuffer_commit_read_bytes(RingBuffer *rb, size_t sz)
|
||||
void ringbuffer_commit_read_bytes(RingBuffer* rb, size_t sz)
|
||||
{
|
||||
WLog_DBG(TAG, "ringbuffer_commit_read_bytes(%p): sz: %d", rb, sz);
|
||||
|
||||
if (sz < 1)
|
||||
return;
|
||||
|
||||
assert(rb->size - rb->freeSize >= sz);
|
||||
|
||||
rb->readPtr = (rb->readPtr + sz) % rb->size;
|
||||
|
Loading…
Reference in New Issue
Block a user