2011-08-18 12:06:32 +04:00
|
|
|
/**
|
2012-10-09 07:02:04 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2011-08-18 12:06:32 +04:00
|
|
|
* RDP Server Peer
|
|
|
|
*
|
|
|
|
* Copyright 2011 Vic Lee
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2012-08-15 01:09:01 +04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2012-02-17 09:58:30 +04:00
|
|
|
#include "certificate.h"
|
2012-03-18 21:13:34 +04:00
|
|
|
#include <freerdp/utils/tcp.h>
|
2012-02-17 09:58:30 +04:00
|
|
|
|
2011-08-18 12:06:32 +04:00
|
|
|
#include "peer.h"
|
|
|
|
|
2012-10-09 10:38:39 +04:00
|
|
|
static BOOL freerdp_peer_initialize(freerdp_peer* client)
|
2011-08-18 12:06:32 +04:00
|
|
|
{
|
2012-10-09 10:31:28 +04:00
|
|
|
client->context->rdp->settings->server_mode = TRUE;
|
2012-05-11 12:35:11 +04:00
|
|
|
client->context->rdp->settings->frame_acknowledge = 0;
|
2012-05-22 19:21:09 +04:00
|
|
|
client->context->rdp->settings->local = client->local;
|
2011-10-18 11:10:12 +04:00
|
|
|
client->context->rdp->state = CONNECTION_STATE_INITIAL;
|
2012-03-18 21:13:34 +04:00
|
|
|
|
|
|
|
if (client->context->rdp->settings->rdp_key_file != NULL)
|
|
|
|
{
|
2012-01-25 19:45:21 +04:00
|
|
|
client->context->rdp->settings->server_key =
|
|
|
|
key_new(client->context->rdp->settings->rdp_key_file);
|
|
|
|
}
|
2011-08-18 19:15:28 +04:00
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-08-18 12:06:32 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 10:38:39 +04:00
|
|
|
static BOOL freerdp_peer_get_fds(freerdp_peer* client, void** rfds, int* rcount)
|
2011-08-18 12:06:32 +04:00
|
|
|
{
|
2011-10-18 11:10:12 +04:00
|
|
|
rfds[*rcount] = (void*)(long)(client->context->rdp->transport->tcp->sockfd);
|
2011-08-18 12:06:32 +04:00
|
|
|
(*rcount)++;
|
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-08-18 12:06:32 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 10:38:39 +04:00
|
|
|
static BOOL freerdp_peer_check_fds(freerdp_peer* client)
|
2011-08-18 12:06:32 +04:00
|
|
|
{
|
2011-08-18 19:15:28 +04:00
|
|
|
int status;
|
2012-03-18 21:13:34 +04:00
|
|
|
rdpRdp* rdp;
|
2011-08-18 19:15:28 +04:00
|
|
|
|
2011-10-18 11:10:12 +04:00
|
|
|
rdp = client->context->rdp;
|
2011-08-18 19:15:28 +04:00
|
|
|
|
|
|
|
status = rdp_check_fds(rdp);
|
2012-03-18 21:13:34 +04:00
|
|
|
|
2011-08-18 19:15:28 +04:00
|
|
|
if (status < 0)
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-08-18 19:15:28 +04:00
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-08-18 12:06:32 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 10:38:39 +04:00
|
|
|
static BOOL peer_recv_data_pdu(freerdp_peer* client, STREAM* s)
|
2011-08-21 18:52:37 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE type;
|
|
|
|
UINT16 length;
|
2011-08-21 18:52:37 +04:00
|
|
|
uint32 share_id;
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE compressed_type;
|
|
|
|
UINT16 compressed_len;
|
2011-08-21 18:52:37 +04:00
|
|
|
|
2011-09-08 09:17:58 +04:00
|
|
|
if (!rdp_read_share_data_header(s, &length, &type, &share_id, &compressed_type, &compressed_len))
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-08-21 18:52:37 +04:00
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case DATA_PDU_TYPE_SYNCHRONIZE:
|
2012-01-09 01:02:59 +04:00
|
|
|
if (!rdp_recv_client_synchronize_pdu(client->context->rdp, s))
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-08-21 18:52:37 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_PDU_TYPE_CONTROL:
|
2011-10-18 11:10:12 +04:00
|
|
|
if (!rdp_server_accept_client_control_pdu(client->context->rdp, s))
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-08-21 19:20:37 +04:00
|
|
|
break;
|
|
|
|
|
2012-02-07 16:38:27 +04:00
|
|
|
case DATA_PDU_TYPE_INPUT:
|
|
|
|
if (!input_recv(client->context->rdp->input, s))
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2012-02-07 16:38:27 +04:00
|
|
|
break;
|
|
|
|
|
2011-08-21 19:20:37 +04:00
|
|
|
case DATA_PDU_TYPE_BITMAP_CACHE_PERSISTENT_LIST:
|
|
|
|
/* TODO: notify server bitmap cache data */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_PDU_TYPE_FONT_LIST:
|
2012-03-18 21:13:34 +04:00
|
|
|
|
2011-10-18 11:10:12 +04:00
|
|
|
if (!rdp_server_accept_client_font_list_pdu(client->context->rdp, s))
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2012-03-18 21:13:34 +04:00
|
|
|
|
2012-09-16 23:30:11 +04:00
|
|
|
if (!client->connected)
|
2011-08-22 19:02:56 +04:00
|
|
|
{
|
2011-09-06 14:28:03 +04:00
|
|
|
/**
|
|
|
|
* PostConnect should only be called once and should not be called
|
|
|
|
* after a reactivation sequence.
|
|
|
|
*/
|
2012-03-18 21:13:34 +04:00
|
|
|
|
2012-09-16 23:30:11 +04:00
|
|
|
IFCALLRET(client->PostConnect, client->connected, client);
|
|
|
|
|
|
|
|
if (!client->connected)
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-09-06 14:48:17 +04:00
|
|
|
}
|
2012-03-18 21:13:34 +04:00
|
|
|
|
2012-09-16 23:30:11 +04:00
|
|
|
if (!client->activated)
|
2012-09-17 05:05:51 +04:00
|
|
|
{
|
|
|
|
/* Activate will be called everytime after the client is activated/reactivated. */
|
|
|
|
|
|
|
|
IFCALLRET(client->Activate, client->activated, client);
|
|
|
|
|
|
|
|
if (!client->activated)
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2012-09-17 05:05:51 +04:00
|
|
|
}
|
2012-06-24 18:20:45 +04:00
|
|
|
|
2011-08-21 18:52:37 +04:00
|
|
|
break;
|
|
|
|
|
2011-08-26 14:14:34 +04:00
|
|
|
case DATA_PDU_TYPE_SHUTDOWN_REQUEST:
|
2011-10-18 11:10:12 +04:00
|
|
|
mcs_send_disconnect_provider_ultimatum(client->context->rdp->mcs);
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-08-26 14:14:34 +04:00
|
|
|
|
2012-05-11 12:35:11 +04:00
|
|
|
case DATA_PDU_TYPE_FRAME_ACKNOWLEDGE:
|
|
|
|
stream_read_uint32(s, client->ack_frame_id);
|
|
|
|
break;
|
|
|
|
|
2012-05-26 17:34:09 +04:00
|
|
|
case DATA_PDU_TYPE_REFRESH_RECT:
|
|
|
|
if (!update_read_refresh_rect(client->update, s))
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2012-05-26 17:34:09 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_PDU_TYPE_SUPPRESS_OUTPUT:
|
|
|
|
if (!update_read_suppress_output(client->update, s))
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2012-05-26 17:34:09 +04:00
|
|
|
break;
|
|
|
|
|
2011-08-21 18:52:37 +04:00
|
|
|
default:
|
|
|
|
printf("Data PDU type %d\n", type);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-08-21 18:52:37 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 10:38:39 +04:00
|
|
|
static BOOL peer_recv_tpkt_pdu(freerdp_peer* client, STREAM* s)
|
2011-08-21 18:52:37 +04:00
|
|
|
{
|
2012-03-18 21:13:34 +04:00
|
|
|
rdpRdp* rdp;
|
2012-10-09 11:01:37 +04:00
|
|
|
UINT16 length;
|
|
|
|
UINT16 pduType;
|
|
|
|
UINT16 pduLength;
|
|
|
|
UINT16 pduSource;
|
|
|
|
UINT16 channelId;
|
|
|
|
UINT16 securityFlags;
|
2011-08-21 18:52:37 +04:00
|
|
|
|
2012-01-25 19:30:54 +04:00
|
|
|
rdp = client->context->rdp;
|
|
|
|
|
|
|
|
if (!rdp_read_header(rdp, s, &length, &channelId))
|
2011-08-21 18:52:37 +04:00
|
|
|
{
|
|
|
|
printf("Incorrect RDP header.\n");
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-08-21 18:52:37 +04:00
|
|
|
}
|
|
|
|
|
2012-01-25 19:30:54 +04:00
|
|
|
if (rdp->settings->encryption)
|
|
|
|
{
|
|
|
|
rdp_read_security_header(s, &securityFlags);
|
2012-03-18 21:13:34 +04:00
|
|
|
|
2012-01-25 19:30:54 +04:00
|
|
|
if (securityFlags & SEC_ENCRYPT)
|
|
|
|
{
|
|
|
|
if (!rdp_decrypt(rdp, s, length - 4, securityFlags))
|
|
|
|
{
|
|
|
|
printf("rdp_decrypt failed\n");
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2012-01-25 19:30:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-21 18:52:37 +04:00
|
|
|
if (channelId != MCS_GLOBAL_CHANNEL_ID)
|
|
|
|
{
|
2011-12-10 12:41:29 +04:00
|
|
|
freerdp_channel_peer_process(client, s, channelId);
|
2011-08-21 18:52:37 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-11-19 11:33:49 +04:00
|
|
|
if (!rdp_read_share_control_header(s, &pduLength, &pduType, &pduSource))
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-08-21 18:52:37 +04:00
|
|
|
|
2011-11-19 11:33:49 +04:00
|
|
|
client->settings->pdu_source = pduSource;
|
|
|
|
|
2011-08-21 18:52:37 +04:00
|
|
|
switch (pduType)
|
|
|
|
{
|
|
|
|
case PDU_TYPE_DATA:
|
2011-10-18 11:10:12 +04:00
|
|
|
if (!peer_recv_data_pdu(client, s))
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-08-21 18:52:37 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
printf("Client sent pduType %d\n", pduType);
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-08-21 18:52:37 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-08-21 18:52:37 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 10:38:39 +04:00
|
|
|
static BOOL peer_recv_fastpath_pdu(freerdp_peer* client, STREAM* s)
|
2011-08-21 18:52:37 +04:00
|
|
|
{
|
2011-09-27 09:30:58 +04:00
|
|
|
rdpRdp* rdp;
|
2012-10-09 11:01:37 +04:00
|
|
|
UINT16 length;
|
2011-09-27 09:30:58 +04:00
|
|
|
rdpFastPath* fastpath;
|
|
|
|
|
2011-10-18 11:10:12 +04:00
|
|
|
rdp = client->context->rdp;
|
2011-09-27 09:30:58 +04:00
|
|
|
fastpath = rdp->fastpath;
|
|
|
|
length = fastpath_read_header_rdp(fastpath, s);
|
2011-08-23 11:51:51 +04:00
|
|
|
|
2011-09-15 01:14:50 +04:00
|
|
|
if (length == 0 || length > stream_get_left(s))
|
2011-08-23 11:51:51 +04:00
|
|
|
{
|
|
|
|
printf("incorrect FastPath PDU header length %d\n", length);
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-08-23 11:51:51 +04:00
|
|
|
}
|
|
|
|
|
2011-09-27 09:30:58 +04:00
|
|
|
if (fastpath->encryptionFlags & FASTPATH_OUTPUT_ENCRYPTED)
|
2011-09-15 01:14:50 +04:00
|
|
|
{
|
2012-01-24 18:58:30 +04:00
|
|
|
rdp_decrypt(rdp, s, length, (fastpath->encryptionFlags & FASTPATH_OUTPUT_SECURE_CHECKSUM) ? SEC_SECURE_CHECKSUM : 0);
|
2011-09-15 01:14:50 +04:00
|
|
|
}
|
|
|
|
|
2011-09-27 09:30:58 +04:00
|
|
|
return fastpath_recv_inputs(fastpath, s);
|
2011-08-21 18:52:37 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 10:38:39 +04:00
|
|
|
static BOOL peer_recv_pdu(freerdp_peer* client, STREAM* s)
|
2011-08-21 18:52:37 +04:00
|
|
|
{
|
|
|
|
if (tpkt_verify_header(s))
|
2011-10-18 11:10:12 +04:00
|
|
|
return peer_recv_tpkt_pdu(client, s);
|
2011-08-21 18:52:37 +04:00
|
|
|
else
|
2011-10-18 11:10:12 +04:00
|
|
|
return peer_recv_fastpath_pdu(client, s);
|
2011-08-21 18:52:37 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 10:38:39 +04:00
|
|
|
static BOOL peer_recv_callback(rdpTransport* transport, STREAM* s, void* extra)
|
2011-08-18 19:15:28 +04:00
|
|
|
{
|
2011-10-18 11:10:12 +04:00
|
|
|
freerdp_peer* client = (freerdp_peer*) extra;
|
2012-09-16 23:30:11 +04:00
|
|
|
rdpRdp* rdp = client->context->rdp;
|
2011-08-18 19:15:28 +04:00
|
|
|
|
2012-09-16 23:30:11 +04:00
|
|
|
switch (rdp->state)
|
2011-08-18 19:15:28 +04:00
|
|
|
{
|
|
|
|
case CONNECTION_STATE_INITIAL:
|
2012-09-16 23:30:11 +04:00
|
|
|
if (!rdp_server_accept_nego(rdp, s))
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2012-09-16 23:30:11 +04:00
|
|
|
|
|
|
|
if (rdp->nego->selected_protocol & PROTOCOL_NLA)
|
|
|
|
{
|
|
|
|
sspi_CopyAuthIdentity(&client->identity, &(rdp->nego->transport->credssp->identity));
|
2012-10-09 10:31:28 +04:00
|
|
|
IFCALLRET(client->Logon, client->authenticated, client, &client->identity, TRUE);
|
2012-09-16 23:30:11 +04:00
|
|
|
credssp_free(rdp->nego->transport->credssp);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-10-09 10:31:28 +04:00
|
|
|
IFCALLRET(client->Logon, client->authenticated, client, &client->identity, FALSE);
|
2012-09-16 23:30:11 +04:00
|
|
|
}
|
|
|
|
|
2011-08-19 13:39:37 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CONNECTION_STATE_NEGO:
|
2012-09-16 23:30:11 +04:00
|
|
|
if (!rdp_server_accept_mcs_connect_initial(rdp, s))
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-08-19 22:03:48 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CONNECTION_STATE_MCS_CONNECT:
|
2012-09-16 23:30:11 +04:00
|
|
|
if (!rdp_server_accept_mcs_erect_domain_request(rdp, s))
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-08-19 22:03:48 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CONNECTION_STATE_MCS_ERECT_DOMAIN:
|
2012-09-16 23:30:11 +04:00
|
|
|
if (!rdp_server_accept_mcs_attach_user_request(rdp, s))
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-08-20 10:05:03 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CONNECTION_STATE_MCS_ATTACH_USER:
|
2012-09-16 23:30:11 +04:00
|
|
|
if (!rdp_server_accept_mcs_channel_join_request(rdp, s))
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-08-20 14:22:14 +04:00
|
|
|
break;
|
|
|
|
|
2011-08-22 11:03:58 +04:00
|
|
|
case CONNECTION_STATE_MCS_CHANNEL_JOIN:
|
2012-09-16 23:30:11 +04:00
|
|
|
if (rdp->settings->encryption)
|
|
|
|
{
|
|
|
|
if (!rdp_server_accept_client_keys(rdp, s))
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2012-01-25 20:08:10 +04:00
|
|
|
break;
|
|
|
|
}
|
2012-09-16 23:30:11 +04:00
|
|
|
rdp->state = CONNECTION_STATE_ESTABLISH_KEYS;
|
2012-01-25 20:08:10 +04:00
|
|
|
/* FALLTHROUGH */
|
|
|
|
|
|
|
|
case CONNECTION_STATE_ESTABLISH_KEYS:
|
2012-09-16 23:30:11 +04:00
|
|
|
if (!rdp_server_accept_client_info(rdp, s))
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2012-03-18 21:13:34 +04:00
|
|
|
|
2011-12-15 00:08:09 +04:00
|
|
|
IFCALL(client->Capabilities, client);
|
2012-03-18 21:13:34 +04:00
|
|
|
|
2012-09-16 23:30:11 +04:00
|
|
|
if (!rdp_send_demand_active(rdp))
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-08-21 11:52:44 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CONNECTION_STATE_LICENSE:
|
2012-09-16 23:30:11 +04:00
|
|
|
if (!rdp_server_accept_confirm_active(rdp, s))
|
2011-12-18 21:13:09 +04:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* During reactivation sequence the client might sent some input or channel data
|
|
|
|
* before receiving the Deactivate All PDU. We need to process them as usual.
|
|
|
|
*/
|
|
|
|
stream_set_pos(s, 0);
|
|
|
|
return peer_recv_pdu(client, s);
|
|
|
|
}
|
2011-08-21 18:52:37 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CONNECTION_STATE_ACTIVE:
|
2011-10-18 11:10:12 +04:00
|
|
|
if (!peer_recv_pdu(client, s))
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-08-19 05:54:43 +04:00
|
|
|
break;
|
2011-08-18 19:15:28 +04:00
|
|
|
|
|
|
|
default:
|
2012-09-16 23:30:11 +04:00
|
|
|
printf("Invalid state %d\n", rdp->state);
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-08-18 19:15:28 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-08-18 19:15:28 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 10:38:39 +04:00
|
|
|
static BOOL freerdp_peer_close(freerdp_peer* client)
|
2012-04-13 11:58:28 +04:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* [MS-RDPBCGR] 1.3.1.4.2 User-Initiated Disconnection Sequence on Server
|
|
|
|
* The server first sends the client a Deactivate All PDU followed by an
|
|
|
|
* optional MCS Disconnect Provider Ultimatum PDU.
|
|
|
|
*/
|
|
|
|
if (!rdp_send_deactivate_all(client->context->rdp))
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2012-04-13 11:58:28 +04:00
|
|
|
return mcs_send_disconnect_provider_ultimatum(client->context->rdp->mcs);
|
|
|
|
}
|
|
|
|
|
2011-08-18 12:06:32 +04:00
|
|
|
static void freerdp_peer_disconnect(freerdp_peer* client)
|
|
|
|
{
|
2011-10-18 11:10:12 +04:00
|
|
|
transport_disconnect(client->context->rdp->transport);
|
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
static int freerdp_peer_send_channel_data(freerdp_peer* client, int channelId, BYTE* data, int size)
|
2011-12-10 12:41:29 +04:00
|
|
|
{
|
|
|
|
return rdp_send_channel_data(client->context->rdp, channelId, data, size);
|
|
|
|
}
|
|
|
|
|
2011-10-18 11:10:12 +04:00
|
|
|
void freerdp_peer_context_new(freerdp_peer* client)
|
|
|
|
{
|
|
|
|
rdpRdp* rdp;
|
|
|
|
|
|
|
|
rdp = rdp_new(NULL);
|
|
|
|
client->input = rdp->input;
|
|
|
|
client->update = rdp->update;
|
|
|
|
client->settings = rdp->settings;
|
|
|
|
|
2011-10-30 09:43:04 +04:00
|
|
|
client->context = (rdpContext*) xzalloc(client->context_size);
|
2011-10-18 11:10:12 +04:00
|
|
|
client->context->rdp = rdp;
|
|
|
|
client->context->peer = client;
|
|
|
|
|
|
|
|
client->update->context = client->context;
|
|
|
|
client->input->context = client->context;
|
|
|
|
|
|
|
|
update_register_server_callbacks(client->update);
|
|
|
|
|
|
|
|
transport_attach(rdp->transport, client->sockfd);
|
2011-08-23 12:14:32 +04:00
|
|
|
|
2011-10-18 11:10:12 +04:00
|
|
|
rdp->transport->recv_callback = peer_recv_callback;
|
|
|
|
rdp->transport->recv_extra = client;
|
2012-10-09 10:31:28 +04:00
|
|
|
transport_set_blocking_mode(rdp->transport, FALSE);
|
2011-10-18 11:10:12 +04:00
|
|
|
|
|
|
|
IFCALL(client->ContextNew, client, client->context);
|
|
|
|
}
|
|
|
|
|
|
|
|
void freerdp_peer_context_free(freerdp_peer* client)
|
|
|
|
{
|
|
|
|
IFCALL(client->ContextFree, client, client->context);
|
2011-08-18 12:06:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
freerdp_peer* freerdp_peer_new(int sockfd)
|
|
|
|
{
|
|
|
|
freerdp_peer* client;
|
|
|
|
|
|
|
|
client = xnew(freerdp_peer);
|
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
freerdp_tcp_set_no_delay(sockfd, TRUE);
|
2012-03-18 21:13:34 +04:00
|
|
|
|
2011-10-30 09:43:04 +04:00
|
|
|
if (client != NULL)
|
|
|
|
{
|
|
|
|
client->sockfd = sockfd;
|
|
|
|
client->context_size = sizeof(rdpContext);
|
|
|
|
client->Initialize = freerdp_peer_initialize;
|
|
|
|
client->GetFileDescriptor = freerdp_peer_get_fds;
|
|
|
|
client->CheckFileDescriptor = freerdp_peer_check_fds;
|
2012-04-13 11:58:28 +04:00
|
|
|
client->Close = freerdp_peer_close;
|
2011-10-30 09:43:04 +04:00
|
|
|
client->Disconnect = freerdp_peer_disconnect;
|
2011-12-10 12:41:29 +04:00
|
|
|
client->SendChannelData = freerdp_peer_send_channel_data;
|
2011-10-30 09:43:04 +04:00
|
|
|
}
|
2011-08-18 12:06:32 +04:00
|
|
|
|
|
|
|
return client;
|
|
|
|
}
|
|
|
|
|
|
|
|
void freerdp_peer_free(freerdp_peer* client)
|
|
|
|
{
|
2011-10-18 11:10:12 +04:00
|
|
|
if (client)
|
|
|
|
{
|
|
|
|
rdp_free(client->context->rdp);
|
2012-10-09 07:21:26 +04:00
|
|
|
free(client->context);
|
|
|
|
free(client);
|
2011-10-18 11:10:12 +04:00
|
|
|
}
|
2011-08-18 12:06:32 +04:00
|
|
|
}
|