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
|
|
|
* FreeRDP Test Server
|
|
|
|
*
|
|
|
|
* Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
2011-08-24 17:59:32 +04:00
|
|
|
* Copyright 2011 Vic Lee
|
2011-08-18 12:06:32 +04:00
|
|
|
*
|
|
|
|
* 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:20:53 +04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2011-08-18 12:06:32 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
2011-08-25 09:18:01 +04:00
|
|
|
#include <signal.h>
|
2012-08-15 01:20:53 +04:00
|
|
|
|
2012-10-09 07:42:01 +04:00
|
|
|
#include <winpr/crt.h>
|
2012-11-27 05:15:48 +04:00
|
|
|
#include <winpr/synch.h>
|
2012-10-09 07:42:01 +04:00
|
|
|
|
2011-08-23 19:28:54 +04:00
|
|
|
#include <freerdp/constants.h>
|
2013-06-24 20:02:21 +04:00
|
|
|
#include <freerdp/utils/tcp.h>
|
2012-10-09 00:12:03 +04:00
|
|
|
#include <freerdp/server/rdpsnd.h>
|
|
|
|
|
|
|
|
#include "sf_audin.h"
|
|
|
|
#include "sf_rdpsnd.h"
|
|
|
|
|
|
|
|
#include "sfreerdp.h"
|
2011-08-18 12:06:32 +04:00
|
|
|
|
2013-06-24 20:02:21 +04:00
|
|
|
#define SAMPLE_SERVER_USE_CLIENT_RESOLUTION 1
|
2013-06-21 18:46:46 +04:00
|
|
|
#define SAMPLE_SERVER_DEFAULT_WIDTH 1024
|
|
|
|
#define SAMPLE_SERVER_DEFAULT_HEIGHT 768
|
|
|
|
|
2011-08-29 07:39:04 +04:00
|
|
|
static char* test_pcap_file = NULL;
|
2012-10-09 10:38:39 +04:00
|
|
|
static BOOL test_dump_rfx_realtime = TRUE;
|
2011-08-29 07:39:04 +04:00
|
|
|
|
2011-10-18 11:10:12 +04:00
|
|
|
void test_peer_context_new(freerdp_peer* client, testPeerContext* context)
|
|
|
|
{
|
2013-08-17 00:46:47 +04:00
|
|
|
context->rfx_context = rfx_context_new(TRUE);
|
2011-10-18 11:10:12 +04:00
|
|
|
context->rfx_context->mode = RLGR3;
|
2013-06-21 18:46:46 +04:00
|
|
|
context->rfx_context->width = SAMPLE_SERVER_DEFAULT_WIDTH;
|
|
|
|
context->rfx_context->height = SAMPLE_SERVER_DEFAULT_HEIGHT;
|
2012-03-13 15:02:19 +04:00
|
|
|
rfx_context_set_pixel_format(context->rfx_context, RDP_PIXEL_FORMAT_R8G8B8);
|
2011-08-24 19:10:23 +04:00
|
|
|
|
2012-03-18 12:36:38 +04:00
|
|
|
context->nsc_context = nsc_context_new();
|
|
|
|
nsc_context_set_pixel_format(context->nsc_context, RDP_PIXEL_FORMAT_R8G8B8);
|
|
|
|
|
2013-05-09 01:48:30 +04:00
|
|
|
context->s = Stream_New(NULL, 65536);
|
2011-08-24 17:59:32 +04:00
|
|
|
|
2011-10-18 11:10:12 +04:00
|
|
|
context->icon_x = -1;
|
|
|
|
context->icon_y = -1;
|
2011-12-12 12:42:42 +04:00
|
|
|
|
|
|
|
context->vcm = WTSCreateVirtualChannelManager(client);
|
2011-08-24 17:59:32 +04:00
|
|
|
}
|
|
|
|
|
2011-10-18 11:10:12 +04:00
|
|
|
void test_peer_context_free(freerdp_peer* client, testPeerContext* context)
|
2011-08-24 17:59:32 +04:00
|
|
|
{
|
2011-10-18 11:10:12 +04:00
|
|
|
if (context)
|
2011-08-24 17:59:32 +04:00
|
|
|
{
|
2011-12-12 18:37:48 +04:00
|
|
|
if (context->debug_channel_thread)
|
|
|
|
{
|
2013-03-22 01:49:10 +04:00
|
|
|
SetEvent(context->stopEvent);
|
|
|
|
WaitForSingleObject(context->debug_channel_thread, INFINITE);
|
|
|
|
CloseHandle(context->debug_channel_thread);
|
2011-12-12 18:37:48 +04:00
|
|
|
}
|
2012-10-09 00:12:03 +04:00
|
|
|
|
2013-05-09 01:48:30 +04:00
|
|
|
Stream_Free(context->s, TRUE);
|
2012-10-09 07:21:26 +04:00
|
|
|
free(context->icon_data);
|
|
|
|
free(context->bg_data);
|
2012-10-09 00:12:03 +04:00
|
|
|
|
2011-10-18 11:10:12 +04:00
|
|
|
rfx_context_free(context->rfx_context);
|
2012-03-18 12:36:38 +04:00
|
|
|
nsc_context_free(context->nsc_context);
|
2012-10-09 00:12:03 +04:00
|
|
|
|
2011-12-12 12:42:42 +04:00
|
|
|
if (context->debug_channel)
|
|
|
|
WTSVirtualChannelClose(context->debug_channel);
|
2012-10-09 00:12:03 +04:00
|
|
|
|
2012-06-26 10:51:22 +04:00
|
|
|
if (context->audin)
|
|
|
|
audin_server_context_free(context->audin);
|
2012-10-09 00:12:03 +04:00
|
|
|
|
|
|
|
if (context->rdpsnd)
|
|
|
|
rdpsnd_server_context_free(context->rdpsnd);
|
|
|
|
|
2011-12-12 12:42:42 +04:00
|
|
|
WTSDestroyVirtualChannelManager(context->vcm);
|
2011-08-24 17:59:32 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-18 11:10:12 +04:00
|
|
|
static void test_peer_init(freerdp_peer* client)
|
|
|
|
{
|
2013-06-14 05:34:46 +04:00
|
|
|
client->ContextSize = sizeof(testPeerContext);
|
2011-10-18 11:10:12 +04:00
|
|
|
client->ContextNew = (psPeerContextNew) test_peer_context_new;
|
|
|
|
client->ContextFree = (psPeerContextFree) test_peer_context_free;
|
|
|
|
freerdp_peer_context_new(client);
|
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
static wStream* test_peer_stream_init(testPeerContext* context)
|
2011-08-24 17:59:32 +04:00
|
|
|
{
|
2013-05-02 02:15:55 +04:00
|
|
|
Stream_Clear(context->s);
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_SetPosition(context->s, 0);
|
2011-10-18 11:10:12 +04:00
|
|
|
return context->s;
|
2011-08-24 17:59:32 +04:00
|
|
|
}
|
2011-08-24 12:25:18 +04:00
|
|
|
|
2012-05-11 12:35:11 +04:00
|
|
|
static void test_peer_begin_frame(freerdp_peer* client)
|
|
|
|
{
|
|
|
|
rdpUpdate* update = client->update;
|
|
|
|
SURFACE_FRAME_MARKER* fm = &update->surface_frame_marker;
|
|
|
|
testPeerContext* context = (testPeerContext*) client->context;
|
|
|
|
|
|
|
|
fm->frameAction = SURFACECMD_FRAMEACTION_BEGIN;
|
|
|
|
fm->frameId = context->frame_id;
|
|
|
|
update->SurfaceFrameMarker(update->context, fm);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_peer_end_frame(freerdp_peer* client)
|
|
|
|
{
|
|
|
|
rdpUpdate* update = client->update;
|
|
|
|
SURFACE_FRAME_MARKER* fm = &update->surface_frame_marker;
|
|
|
|
testPeerContext* context = (testPeerContext*) client->context;
|
|
|
|
|
|
|
|
fm->frameAction = SURFACECMD_FRAMEACTION_END;
|
|
|
|
fm->frameId = context->frame_id;
|
|
|
|
update->SurfaceFrameMarker(update->context, fm);
|
|
|
|
|
|
|
|
context->frame_id++;
|
|
|
|
}
|
|
|
|
|
2011-08-24 17:59:32 +04:00
|
|
|
static void test_peer_draw_background(freerdp_peer* client)
|
2011-08-23 19:28:54 +04:00
|
|
|
{
|
2012-10-09 00:12:03 +04:00
|
|
|
int size;
|
2013-03-21 23:19:33 +04:00
|
|
|
wStream* s;
|
2011-08-24 17:59:32 +04:00
|
|
|
RFX_RECT rect;
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE* rgb_data;
|
2012-10-09 00:12:03 +04:00
|
|
|
rdpUpdate* update = client->update;
|
|
|
|
SURFACE_BITS_COMMAND* cmd = &update->surface_bits_command;
|
|
|
|
testPeerContext* context = (testPeerContext*) client->context;
|
2011-08-24 12:25:18 +04:00
|
|
|
|
2012-11-08 00:13:14 +04:00
|
|
|
if (!client->settings->RemoteFxCodec && !client->settings->NSCodec)
|
2011-08-24 12:25:18 +04:00
|
|
|
return;
|
2011-08-23 19:28:54 +04:00
|
|
|
|
2012-05-11 12:35:11 +04:00
|
|
|
test_peer_begin_frame(client);
|
|
|
|
|
2011-10-18 11:10:12 +04:00
|
|
|
s = test_peer_stream_init(context);
|
2011-08-23 19:28:54 +04:00
|
|
|
|
2011-08-24 17:59:32 +04:00
|
|
|
rect.x = 0;
|
|
|
|
rect.y = 0;
|
2012-11-26 21:38:28 +04:00
|
|
|
rect.width = client->settings->DesktopWidth;
|
|
|
|
rect.height = client->settings->DesktopHeight;
|
2011-08-23 19:28:54 +04:00
|
|
|
|
2011-08-24 17:59:32 +04:00
|
|
|
size = rect.width * rect.height * 3;
|
2012-10-09 07:21:26 +04:00
|
|
|
rgb_data = malloc(size);
|
2011-08-24 17:59:32 +04:00
|
|
|
memset(rgb_data, 0xA0, size);
|
2011-08-23 19:28:54 +04:00
|
|
|
|
2012-11-08 00:13:14 +04:00
|
|
|
if (client->settings->RemoteFxCodec)
|
2012-03-18 12:36:38 +04:00
|
|
|
{
|
|
|
|
rfx_compose_message(context->rfx_context, s,
|
|
|
|
&rect, 1, rgb_data, rect.width, rect.height, rect.width * 3);
|
2012-11-08 00:13:14 +04:00
|
|
|
cmd->codecID = client->settings->RemoteFxCodecId;
|
2012-03-18 12:36:38 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nsc_compose_message(context->nsc_context, s,
|
|
|
|
rgb_data, rect.width, rect.height, rect.width * 3);
|
2012-11-08 00:13:14 +04:00
|
|
|
cmd->codecID = client->settings->NSCodecId;
|
2012-03-18 12:36:38 +04:00
|
|
|
}
|
2011-08-23 19:28:54 +04:00
|
|
|
|
|
|
|
cmd->destLeft = 0;
|
|
|
|
cmd->destTop = 0;
|
2011-08-24 17:59:32 +04:00
|
|
|
cmd->destRight = rect.width;
|
|
|
|
cmd->destBottom = rect.height;
|
2011-08-23 19:28:54 +04:00
|
|
|
cmd->bpp = 32;
|
2011-08-24 17:59:32 +04:00
|
|
|
cmd->width = rect.width;
|
|
|
|
cmd->height = rect.height;
|
2013-04-30 06:35:15 +04:00
|
|
|
cmd->bitmapDataLength = Stream_GetPosition(s);
|
2013-05-09 00:27:21 +04:00
|
|
|
cmd->bitmapData = Stream_Buffer(s);
|
2011-11-22 04:41:49 +04:00
|
|
|
update->SurfaceBits(update->context, cmd);
|
2011-08-23 19:28:54 +04:00
|
|
|
|
2012-10-09 07:21:26 +04:00
|
|
|
free(rgb_data);
|
2012-05-11 12:35:11 +04:00
|
|
|
|
|
|
|
test_peer_end_frame(client);
|
2011-08-23 19:28:54 +04:00
|
|
|
}
|
|
|
|
|
2011-08-24 19:10:23 +04:00
|
|
|
static void test_peer_load_icon(freerdp_peer* client)
|
|
|
|
{
|
2011-10-18 11:10:12 +04:00
|
|
|
testPeerContext* context = (testPeerContext*) client->context;
|
2011-08-24 19:10:23 +04:00
|
|
|
FILE* fp;
|
|
|
|
int i;
|
|
|
|
char line[50];
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE* rgb_data;
|
2011-08-24 19:10:23 +04:00
|
|
|
int c;
|
|
|
|
|
2012-11-08 00:13:14 +04:00
|
|
|
if (!client->settings->RemoteFxCodec && !client->settings->NSCodec)
|
2011-08-24 19:10:23 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
if ((fp = fopen("test_icon.ppm", "r")) == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* P3 */
|
|
|
|
fgets(line, sizeof(line), fp);
|
|
|
|
/* Creater comment */
|
|
|
|
fgets(line, sizeof(line), fp);
|
|
|
|
/* width height */
|
|
|
|
fgets(line, sizeof(line), fp);
|
2011-10-18 11:10:12 +04:00
|
|
|
sscanf(line, "%d %d", &context->icon_width, &context->icon_height);
|
2011-08-24 19:10:23 +04:00
|
|
|
/* Max */
|
|
|
|
fgets(line, sizeof(line), fp);
|
|
|
|
|
2012-10-09 07:21:26 +04:00
|
|
|
rgb_data = malloc(context->icon_width * context->icon_height * 3);
|
2011-08-24 19:10:23 +04:00
|
|
|
|
2011-10-18 11:10:12 +04:00
|
|
|
for (i = 0; i < context->icon_width * context->icon_height * 3; i++)
|
2011-08-24 19:10:23 +04:00
|
|
|
{
|
|
|
|
if (fgets(line, sizeof(line), fp))
|
|
|
|
{
|
|
|
|
sscanf(line, "%d", &c);
|
2012-10-09 11:01:37 +04:00
|
|
|
rgb_data[i] = (BYTE)c;
|
2011-08-24 19:10:23 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-18 11:10:12 +04:00
|
|
|
context->icon_data = rgb_data;
|
2011-08-24 19:10:23 +04:00
|
|
|
|
2011-08-25 13:38:51 +04:00
|
|
|
/* background with same size, which will be used to erase the icon from old position */
|
2012-10-09 07:21:26 +04:00
|
|
|
context->bg_data = malloc(context->icon_width * context->icon_height * 3);
|
2011-10-18 11:10:12 +04:00
|
|
|
memset(context->bg_data, 0xA0, context->icon_width * context->icon_height * 3);
|
2011-08-24 19:10:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_peer_draw_icon(freerdp_peer* client, int x, int y)
|
|
|
|
{
|
2013-03-21 23:19:33 +04:00
|
|
|
wStream* s;
|
2012-10-09 00:12:03 +04:00
|
|
|
RFX_RECT rect;
|
2011-08-24 19:10:23 +04:00
|
|
|
rdpUpdate* update = client->update;
|
|
|
|
SURFACE_BITS_COMMAND* cmd = &update->surface_bits_command;
|
2012-10-09 00:12:03 +04:00
|
|
|
testPeerContext* context = (testPeerContext*) client->context;
|
2011-08-24 19:10:23 +04:00
|
|
|
|
2011-08-29 07:39:04 +04:00
|
|
|
if (client->update->dump_rfx)
|
|
|
|
return;
|
2012-10-09 00:12:03 +04:00
|
|
|
|
2012-03-18 12:36:38 +04:00
|
|
|
if (!context)
|
2011-08-24 19:10:23 +04:00
|
|
|
return;
|
2012-10-09 00:12:03 +04:00
|
|
|
|
2011-10-18 11:10:12 +04:00
|
|
|
if (context->icon_width < 1 || !context->activated)
|
2011-08-24 19:10:23 +04:00
|
|
|
return;
|
|
|
|
|
2012-05-11 12:35:11 +04:00
|
|
|
test_peer_begin_frame(client);
|
|
|
|
|
2011-08-25 13:38:51 +04:00
|
|
|
rect.x = 0;
|
|
|
|
rect.y = 0;
|
2011-10-18 11:10:12 +04:00
|
|
|
rect.width = context->icon_width;
|
|
|
|
rect.height = context->icon_height;
|
2011-08-24 19:10:23 +04:00
|
|
|
|
2011-10-18 11:10:12 +04:00
|
|
|
if (context->icon_x >= 0)
|
2011-08-24 19:10:23 +04:00
|
|
|
{
|
2011-10-18 11:10:12 +04:00
|
|
|
s = test_peer_stream_init(context);
|
2012-11-08 00:13:14 +04:00
|
|
|
if (client->settings->RemoteFxCodec)
|
2012-03-18 12:36:38 +04:00
|
|
|
{
|
|
|
|
rfx_compose_message(context->rfx_context, s,
|
|
|
|
&rect, 1, context->bg_data, rect.width, rect.height, rect.width * 3);
|
2012-11-08 00:13:14 +04:00
|
|
|
cmd->codecID = client->settings->RemoteFxCodecId;
|
2012-03-18 12:36:38 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nsc_compose_message(context->nsc_context, s,
|
|
|
|
context->bg_data, rect.width, rect.height, rect.width * 3);
|
2012-11-08 00:13:14 +04:00
|
|
|
cmd->codecID = client->settings->NSCodecId;
|
2012-03-18 12:36:38 +04:00
|
|
|
}
|
2011-10-18 11:10:12 +04:00
|
|
|
|
|
|
|
cmd->destLeft = context->icon_x;
|
|
|
|
cmd->destTop = context->icon_y;
|
|
|
|
cmd->destRight = context->icon_x + context->icon_width;
|
|
|
|
cmd->destBottom = context->icon_y + context->icon_height;
|
2011-08-25 13:38:51 +04:00
|
|
|
cmd->bpp = 32;
|
2011-10-18 11:10:12 +04:00
|
|
|
cmd->width = context->icon_width;
|
|
|
|
cmd->height = context->icon_height;
|
2013-04-30 06:35:15 +04:00
|
|
|
cmd->bitmapDataLength = Stream_GetPosition(s);
|
2013-05-09 00:27:21 +04:00
|
|
|
cmd->bitmapData = Stream_Buffer(s);
|
2011-11-22 04:41:49 +04:00
|
|
|
update->SurfaceBits(update->context, cmd);
|
2011-08-24 19:10:23 +04:00
|
|
|
}
|
|
|
|
|
2011-10-18 11:10:12 +04:00
|
|
|
s = test_peer_stream_init(context);
|
2012-10-09 00:12:03 +04:00
|
|
|
|
2012-11-08 00:13:14 +04:00
|
|
|
if (client->settings->RemoteFxCodec)
|
2012-03-18 12:36:38 +04:00
|
|
|
{
|
|
|
|
rfx_compose_message(context->rfx_context, s,
|
|
|
|
&rect, 1, context->icon_data, rect.width, rect.height, rect.width * 3);
|
2012-11-08 00:13:14 +04:00
|
|
|
cmd->codecID = client->settings->RemoteFxCodecId;
|
2012-03-18 12:36:38 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nsc_compose_message(context->nsc_context, s,
|
|
|
|
context->icon_data, rect.width, rect.height, rect.width * 3);
|
2012-11-08 00:13:14 +04:00
|
|
|
cmd->codecID = client->settings->NSCodecId;
|
2012-03-18 12:36:38 +04:00
|
|
|
}
|
2011-08-25 13:38:51 +04:00
|
|
|
|
2011-08-24 19:10:23 +04:00
|
|
|
cmd->destLeft = x;
|
|
|
|
cmd->destTop = y;
|
2011-10-18 11:10:12 +04:00
|
|
|
cmd->destRight = x + context->icon_width;
|
|
|
|
cmd->destBottom = y + context->icon_height;
|
2011-08-25 13:38:51 +04:00
|
|
|
cmd->bpp = 32;
|
2011-10-18 11:10:12 +04:00
|
|
|
cmd->width = context->icon_width;
|
|
|
|
cmd->height = context->icon_height;
|
2013-04-30 06:35:15 +04:00
|
|
|
cmd->bitmapDataLength = Stream_GetPosition(s);
|
2013-05-09 00:27:21 +04:00
|
|
|
cmd->bitmapData = Stream_Buffer(s);
|
2011-11-22 04:41:49 +04:00
|
|
|
update->SurfaceBits(update->context, cmd);
|
2011-08-24 19:10:23 +04:00
|
|
|
|
2011-10-18 11:10:12 +04:00
|
|
|
context->icon_x = x;
|
|
|
|
context->icon_y = y;
|
2012-05-11 12:35:11 +04:00
|
|
|
|
|
|
|
test_peer_end_frame(client);
|
2011-08-24 19:10:23 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
static BOOL test_sleep_tsdiff(UINT32 *old_sec, UINT32 *old_usec, UINT32 new_sec, UINT32 new_usec)
|
2011-10-18 20:36:34 +04:00
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
INT32 sec, usec;
|
2011-10-18 20:36:34 +04:00
|
|
|
|
|
|
|
if (*old_sec==0 && *old_usec==0)
|
|
|
|
{
|
|
|
|
*old_sec = new_sec;
|
|
|
|
*old_usec = new_usec;
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-10-18 20:36:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
sec = new_sec - *old_sec;
|
|
|
|
usec = new_usec - *old_usec;
|
|
|
|
|
|
|
|
if (sec<0 || (sec==0 && usec<0))
|
|
|
|
{
|
|
|
|
printf("Invalid time stamp detected.\n");
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-10-18 20:36:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
*old_sec = new_sec;
|
|
|
|
*old_usec = new_usec;
|
|
|
|
|
|
|
|
while (usec < 0)
|
|
|
|
{
|
|
|
|
usec += 1000000;
|
|
|
|
sec--;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sec > 0)
|
2012-12-14 09:58:48 +04:00
|
|
|
Sleep(sec * 1000);
|
2011-10-18 20:36:34 +04:00
|
|
|
|
|
|
|
if (usec > 0)
|
2012-12-14 09:58:48 +04:00
|
|
|
USleep(usec);
|
2011-10-18 20:36:34 +04:00
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-10-18 20:36:34 +04:00
|
|
|
}
|
|
|
|
|
2011-09-14 03:03:06 +04:00
|
|
|
void tf_peer_dump_rfx(freerdp_peer* client)
|
2011-08-27 05:44:37 +04:00
|
|
|
{
|
2013-03-21 23:19:33 +04:00
|
|
|
wStream* s;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 prev_seconds;
|
|
|
|
UINT32 prev_useconds;
|
2011-08-27 05:44:37 +04:00
|
|
|
rdpUpdate* update;
|
|
|
|
rdpPcap* pcap_rfx;
|
|
|
|
pcap_record record;
|
|
|
|
|
2013-05-09 01:48:30 +04:00
|
|
|
s = Stream_New(NULL, 512);
|
2011-08-27 05:44:37 +04:00
|
|
|
update = client->update;
|
2012-10-09 10:31:28 +04:00
|
|
|
client->update->pcap_rfx = pcap_open(test_pcap_file, FALSE);
|
2011-08-27 05:44:37 +04:00
|
|
|
pcap_rfx = client->update->pcap_rfx;
|
|
|
|
|
2011-10-20 16:25:25 +04:00
|
|
|
if (pcap_rfx == NULL)
|
|
|
|
return;
|
|
|
|
|
2011-10-18 20:36:34 +04:00
|
|
|
prev_seconds = prev_useconds = 0;
|
2011-09-01 04:56:17 +04:00
|
|
|
|
2011-08-27 05:44:37 +04:00
|
|
|
while (pcap_has_next_record(pcap_rfx))
|
|
|
|
{
|
|
|
|
pcap_get_next_record_header(pcap_rfx, &record);
|
|
|
|
|
2013-05-15 20:14:26 +04:00
|
|
|
Stream_Buffer(s) = realloc(Stream_Buffer(s), record.length);
|
|
|
|
record.data = Stream_Buffer(s);
|
|
|
|
Stream_Capacity(s) = record.length;
|
2011-08-27 05:44:37 +04:00
|
|
|
|
|
|
|
pcap_get_next_record_content(pcap_rfx, &record);
|
2013-05-15 20:14:26 +04:00
|
|
|
Stream_Pointer(s) = Stream_Buffer(s) + Stream_Capacity(s);
|
2011-08-27 05:44:37 +04:00
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
if (test_dump_rfx_realtime && test_sleep_tsdiff(&prev_seconds, &prev_useconds, record.header.ts_sec, record.header.ts_usec) == FALSE)
|
2011-10-18 20:36:34 +04:00
|
|
|
break;
|
2011-09-01 04:56:17 +04:00
|
|
|
|
2011-11-22 04:41:49 +04:00
|
|
|
update->SurfaceCommand(update->context, s);
|
2011-08-27 05:44:37 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-12 18:37:48 +04:00
|
|
|
static void* tf_debug_channel_thread_func(void* arg)
|
|
|
|
{
|
|
|
|
void* fd;
|
2013-03-21 23:19:33 +04:00
|
|
|
wStream* s;
|
2011-12-12 18:37:48 +04:00
|
|
|
void* buffer;
|
2013-08-21 03:26:36 +04:00
|
|
|
DWORD BytesReturned = 0;
|
2011-12-12 18:37:48 +04:00
|
|
|
testPeerContext* context = (testPeerContext*) arg;
|
|
|
|
|
2013-08-21 03:26:36 +04:00
|
|
|
if (WTSVirtualChannelQuery(context->debug_channel, WTSVirtualFileHandle, &buffer, &BytesReturned) == TRUE)
|
2011-12-12 18:37:48 +04:00
|
|
|
{
|
2012-11-27 05:15:48 +04:00
|
|
|
fd = *((void**) buffer);
|
2011-12-12 18:37:48 +04:00
|
|
|
WTSFreeMemory(buffer);
|
2013-03-22 01:49:10 +04:00
|
|
|
|
|
|
|
context->event = CreateWaitObjectEvent(NULL, TRUE, FALSE, fd);
|
2011-12-12 18:37:48 +04:00
|
|
|
}
|
|
|
|
|
2013-05-09 01:48:30 +04:00
|
|
|
s = Stream_New(NULL, 4096);
|
2011-12-12 18:37:48 +04:00
|
|
|
|
2013-08-21 03:26:36 +04:00
|
|
|
WTSVirtualChannelWrite(context->debug_channel, (PCHAR) "test1", 5, NULL);
|
2011-12-12 18:37:48 +04:00
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
2013-03-22 01:49:10 +04:00
|
|
|
WaitForSingleObject(context->event, INFINITE);
|
2012-10-09 00:12:03 +04:00
|
|
|
|
2013-03-22 01:49:10 +04:00
|
|
|
if (WaitForSingleObject(context->stopEvent, 0) == WAIT_OBJECT_0)
|
2011-12-12 18:37:48 +04:00
|
|
|
break;
|
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_SetPosition(s, 0);
|
2012-10-09 00:12:03 +04:00
|
|
|
|
2013-08-21 03:26:36 +04:00
|
|
|
if (WTSVirtualChannelRead(context->debug_channel, 0, (PCHAR) Stream_Buffer(s),
|
|
|
|
Stream_Capacity(s), &BytesReturned) == FALSE)
|
2011-12-12 18:37:48 +04:00
|
|
|
{
|
2013-08-21 03:26:36 +04:00
|
|
|
if (BytesReturned == 0)
|
2011-12-12 18:37:48 +04:00
|
|
|
break;
|
2012-10-09 00:12:03 +04:00
|
|
|
|
2013-08-21 03:26:36 +04:00
|
|
|
Stream_EnsureRemainingCapacity(s, BytesReturned);
|
2012-10-09 00:12:03 +04:00
|
|
|
|
2013-08-21 03:26:36 +04:00
|
|
|
if (WTSVirtualChannelRead(context->debug_channel, 0, (PCHAR) Stream_Buffer(s),
|
|
|
|
Stream_Capacity(s), &BytesReturned) == FALSE)
|
2011-12-12 18:37:48 +04:00
|
|
|
{
|
|
|
|
/* should not happen */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-10-09 00:12:03 +04:00
|
|
|
|
2013-08-21 03:26:36 +04:00
|
|
|
Stream_SetPosition(s, BytesReturned);
|
2011-12-12 18:37:48 +04:00
|
|
|
|
2013-08-21 03:26:36 +04:00
|
|
|
printf("got %d bytes\n", BytesReturned);
|
2011-12-12 18:37:48 +04:00
|
|
|
}
|
|
|
|
|
2013-05-09 01:48:30 +04:00
|
|
|
Stream_Free(s, TRUE);
|
2011-12-12 18:37:48 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-10-09 10:38:39 +04:00
|
|
|
BOOL tf_peer_post_connect(freerdp_peer* client)
|
2011-08-22 19:02:56 +04:00
|
|
|
{
|
2011-12-12 10:12:16 +04:00
|
|
|
int i;
|
|
|
|
testPeerContext* context = (testPeerContext*) client->context;
|
|
|
|
|
2011-08-22 19:02:56 +04:00
|
|
|
/**
|
|
|
|
* This callback is called when the entire connection sequence is done, i.e. we've received the
|
|
|
|
* Font List PDU from the client and sent out the Font Map PDU.
|
|
|
|
* The server may start sending graphics output and receiving keyboard/mouse input after this
|
|
|
|
* callback returns.
|
|
|
|
*/
|
2012-10-09 00:12:03 +04:00
|
|
|
|
2012-05-22 19:10:52 +04:00
|
|
|
printf("Client %s is activated (osMajorType %d osMinorType %d)", client->local ? "(local)" : client->hostname,
|
2012-11-08 00:13:14 +04:00
|
|
|
client->settings->OsMajorType, client->settings->OsMinorType);
|
2012-10-09 00:12:03 +04:00
|
|
|
|
2012-11-08 03:23:25 +04:00
|
|
|
if (client->settings->AutoLogonEnabled)
|
2011-08-22 19:02:56 +04:00
|
|
|
{
|
|
|
|
printf(" and wants to login automatically as %s\\%s",
|
2012-11-08 00:13:14 +04:00
|
|
|
client->settings->Domain ? client->settings->Domain : "",
|
|
|
|
client->settings->Username);
|
2011-08-22 19:02:56 +04:00
|
|
|
|
|
|
|
/* A real server may perform OS login here if NLA is not executed previously. */
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
|
2011-08-23 11:51:51 +04:00
|
|
|
printf("Client requested desktop: %dx%dx%d\n",
|
2012-11-26 21:38:28 +04:00
|
|
|
client->settings->DesktopWidth, client->settings->DesktopHeight, client->settings->ColorDepth);
|
2011-08-23 11:51:51 +04:00
|
|
|
|
2013-06-21 18:46:46 +04:00
|
|
|
#if (SAMPLE_SERVER_USE_CLIENT_RESOLUTION == 1)
|
|
|
|
context->rfx_context->width = client->settings->DesktopWidth;
|
|
|
|
context->rfx_context->height = client->settings->DesktopHeight;
|
|
|
|
printf("Using resolution requested by client.\n");
|
|
|
|
#else
|
|
|
|
client->settings->DesktopWidth = context->rfx_context->width;
|
|
|
|
client->settings->DesktopHeight = context->rfx_context->height;
|
|
|
|
printf("Resizing client to %dx%d\n", client->settings->DesktopWidth, client->settings->DesktopHeight);
|
|
|
|
client->update->DesktopResize(client->update->context);
|
|
|
|
#endif
|
|
|
|
|
2012-11-26 21:38:28 +04:00
|
|
|
/* A real server should tag the peer as activated here and start sending updates in main loop. */
|
2011-08-24 19:10:23 +04:00
|
|
|
test_peer_load_icon(client);
|
2011-08-23 19:28:54 +04:00
|
|
|
|
2011-12-12 10:12:16 +04:00
|
|
|
/* Iterate all channel names requested by the client and activate those supported by the server */
|
2012-10-09 00:29:40 +04:00
|
|
|
|
2012-11-08 08:29:24 +04:00
|
|
|
for (i = 0; i < client->settings->ChannelCount; i++)
|
2011-12-12 10:12:16 +04:00
|
|
|
{
|
2012-11-08 08:29:24 +04:00
|
|
|
if (client->settings->ChannelDefArray[i].joined)
|
2011-12-12 10:12:16 +04:00
|
|
|
{
|
2012-11-08 08:29:24 +04:00
|
|
|
if (strncmp(client->settings->ChannelDefArray[i].Name, "rdpdbg", 6) == 0)
|
2011-12-12 10:12:16 +04:00
|
|
|
{
|
2013-08-22 18:18:38 +04:00
|
|
|
context->debug_channel = WTSVirtualChannelManagerOpenEx(context->vcm, "rdpdbg", 0);
|
2012-10-09 00:12:03 +04:00
|
|
|
|
2011-12-12 10:12:16 +04:00
|
|
|
if (context->debug_channel != NULL)
|
|
|
|
{
|
|
|
|
printf("Open channel rdpdbg.\n");
|
2013-03-22 01:49:10 +04:00
|
|
|
|
|
|
|
context->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
|
|
|
|
|
|
|
|
context->debug_channel_thread = CreateThread(NULL, 0,
|
|
|
|
(LPTHREAD_START_ROUTINE) tf_debug_channel_thread_func, (void*) context, 0, NULL);
|
2011-12-12 10:12:16 +04:00
|
|
|
}
|
|
|
|
}
|
2012-11-08 08:29:24 +04:00
|
|
|
else if (strncmp(client->settings->ChannelDefArray[i].Name, "rdpsnd", 6) == 0)
|
2012-10-09 00:29:40 +04:00
|
|
|
{
|
|
|
|
sf_peer_rdpsnd_init(context); /* Audio Output */
|
|
|
|
}
|
2011-12-12 10:12:16 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-09 00:29:40 +04:00
|
|
|
/* Dynamic Virtual Channels */
|
|
|
|
|
2012-10-09 00:12:03 +04:00
|
|
|
sf_peer_audin_init(context); /* Audio Input */
|
2012-06-26 10:51:22 +04:00
|
|
|
|
2012-11-27 07:42:40 +04:00
|
|
|
/* Return FALSE here would stop the execution of the peer main loop. */
|
2012-10-09 00:12:03 +04:00
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-09-06 14:55:11 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 10:38:39 +04:00
|
|
|
BOOL tf_peer_activate(freerdp_peer* client)
|
2011-09-06 14:55:11 +04:00
|
|
|
{
|
2011-10-18 11:10:12 +04:00
|
|
|
testPeerContext* context = (testPeerContext*) client->context;
|
2011-09-06 14:55:11 +04:00
|
|
|
|
2011-10-18 11:10:12 +04:00
|
|
|
rfx_context_reset(context->rfx_context);
|
2012-10-09 10:31:28 +04:00
|
|
|
context->activated = TRUE;
|
2011-09-06 14:55:11 +04:00
|
|
|
|
2011-08-29 07:39:04 +04:00
|
|
|
if (test_pcap_file != NULL)
|
2011-08-27 05:44:37 +04:00
|
|
|
{
|
2012-10-09 10:31:28 +04:00
|
|
|
client->update->dump_rfx = TRUE;
|
2011-09-14 03:03:06 +04:00
|
|
|
tf_peer_dump_rfx(client);
|
2011-08-27 05:44:37 +04:00
|
|
|
}
|
2011-08-29 07:39:04 +04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
test_peer_draw_background(client);
|
|
|
|
}
|
2011-08-27 05:44:37 +04:00
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-08-22 19:02:56 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
void tf_peer_synchronize_event(rdpInput* input, UINT32 flags)
|
2011-08-23 07:50:41 +04:00
|
|
|
{
|
2011-08-23 11:51:51 +04:00
|
|
|
printf("Client sent a synchronize event (flags:0x%X)\n", flags);
|
2011-08-23 07:50:41 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
void tf_peer_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
|
2011-08-23 07:50:41 +04:00
|
|
|
{
|
2011-10-18 11:10:12 +04:00
|
|
|
freerdp_peer* client = input->context->peer;
|
2011-09-06 13:19:59 +04:00
|
|
|
rdpUpdate* update = client->update;
|
2011-10-18 11:10:12 +04:00
|
|
|
testPeerContext* context = (testPeerContext*) input->context;
|
2011-09-06 13:19:59 +04:00
|
|
|
|
2011-08-23 07:50:41 +04:00
|
|
|
printf("Client sent a keyboard event (flags:0x%X code:0x%X)\n", flags, code);
|
2011-09-06 13:19:59 +04:00
|
|
|
|
2012-10-09 00:12:03 +04:00
|
|
|
if ((flags & 0x4000) && code == 0x22) /* 'g' key */
|
2011-09-06 13:19:59 +04:00
|
|
|
{
|
2012-11-26 21:38:28 +04:00
|
|
|
if (client->settings->DesktopWidth != 800)
|
2011-09-06 13:19:59 +04:00
|
|
|
{
|
2012-11-26 21:38:28 +04:00
|
|
|
client->settings->DesktopWidth = 800;
|
|
|
|
client->settings->DesktopHeight = 600;
|
2011-09-06 13:19:59 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-06-24 20:02:21 +04:00
|
|
|
client->settings->DesktopWidth = SAMPLE_SERVER_DEFAULT_WIDTH;
|
|
|
|
client->settings->DesktopHeight = SAMPLE_SERVER_DEFAULT_HEIGHT;
|
2011-09-06 13:19:59 +04:00
|
|
|
}
|
2013-06-24 20:02:21 +04:00
|
|
|
context->rfx_context->width = client->settings->DesktopWidth;
|
|
|
|
context->rfx_context->height = client->settings->DesktopHeight;
|
2011-11-22 04:41:49 +04:00
|
|
|
update->DesktopResize(update->context);
|
2012-10-09 10:31:28 +04:00
|
|
|
context->activated = FALSE;
|
2011-09-06 13:19:59 +04:00
|
|
|
}
|
2011-12-12 18:37:48 +04:00
|
|
|
else if ((flags & 0x4000) && code == 0x2E) /* 'c' key */
|
|
|
|
{
|
|
|
|
if (context->debug_channel)
|
|
|
|
{
|
2013-08-22 18:18:38 +04:00
|
|
|
WTSVirtualChannelWrite(context->debug_channel, (PCHAR) "test2", 5, NULL);
|
2011-12-12 18:37:48 +04:00
|
|
|
}
|
|
|
|
}
|
2012-04-13 11:58:28 +04:00
|
|
|
else if ((flags & 0x4000) && code == 0x2D) /* 'x' key */
|
|
|
|
{
|
|
|
|
client->Close(client);
|
|
|
|
}
|
2012-06-25 12:41:59 +04:00
|
|
|
else if ((flags & 0x4000) && code == 0x13) /* 'r' key */
|
|
|
|
{
|
2012-06-26 10:51:22 +04:00
|
|
|
if (!context->audin_open)
|
2012-06-25 12:41:59 +04:00
|
|
|
{
|
2012-06-26 10:51:22 +04:00
|
|
|
context->audin->Open(context->audin);
|
2012-10-09 10:31:28 +04:00
|
|
|
context->audin_open = TRUE;
|
2012-06-25 12:41:59 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-06-26 10:51:22 +04:00
|
|
|
context->audin->Close(context->audin);
|
2012-10-09 10:31:28 +04:00
|
|
|
context->audin_open = FALSE;
|
2012-06-25 12:41:59 +04:00
|
|
|
}
|
|
|
|
}
|
2012-10-09 00:12:03 +04:00
|
|
|
else if ((flags & 0x4000) && code == 0x1F) /* 's' key */
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
2011-08-23 07:50:41 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
void tf_peer_unicode_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
|
2011-08-23 07:50:41 +04:00
|
|
|
{
|
2012-02-07 15:22:01 +04:00
|
|
|
printf("Client sent a unicode keyboard event (flags:0x%X code:0x%X)\n", flags, code);
|
2011-08-23 07:50:41 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
void tf_peer_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
|
2011-08-23 07:50:41 +04:00
|
|
|
{
|
2012-10-09 00:12:03 +04:00
|
|
|
//printf("Client sent a mouse event (flags:0x%X pos:%d,%d)\n", flags, x, y);
|
2011-08-24 19:10:23 +04:00
|
|
|
|
2011-10-18 11:10:12 +04:00
|
|
|
test_peer_draw_icon(input->context->peer, x + 10, y);
|
2011-08-23 07:50:41 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
void tf_peer_extended_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
|
2011-08-23 07:50:41 +04:00
|
|
|
{
|
2012-10-09 00:12:03 +04:00
|
|
|
//printf("Client sent an extended mouse event (flags:0x%X pos:%d,%d)\n", flags, x, y);
|
2011-08-23 07:50:41 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
static void tf_peer_refresh_rect(rdpContext* context, BYTE count, RECTANGLE_16* areas)
|
2012-05-26 17:34:09 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE i;
|
2012-05-26 17:34:09 +04:00
|
|
|
|
|
|
|
printf("Client requested to refresh:\n");
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
printf(" (%d, %d) (%d, %d)\n", areas[i].left, areas[i].top, areas[i].right, areas[i].bottom);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
static void tf_peer_suppress_output(rdpContext* context, BYTE allow, RECTANGLE_16* area)
|
2012-05-26 17:34:09 +04:00
|
|
|
{
|
|
|
|
if (allow > 0)
|
|
|
|
{
|
|
|
|
printf("Client restore output (%d, %d) (%d, %d).\n", area->left, area->top, area->right, area->bottom);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printf("Client minimized and suppress output.\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-18 12:06:32 +04:00
|
|
|
static void* test_peer_mainloop(void* arg)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int fds;
|
|
|
|
int max_fds;
|
|
|
|
int rcount;
|
|
|
|
void* rfds[32];
|
|
|
|
fd_set rfds_set;
|
2011-12-12 12:42:42 +04:00
|
|
|
testPeerContext* context;
|
2011-08-28 01:11:20 +04:00
|
|
|
freerdp_peer* client = (freerdp_peer*) arg;
|
2011-08-18 12:06:32 +04:00
|
|
|
|
2011-10-18 11:10:12 +04:00
|
|
|
test_peer_init(client);
|
2011-08-18 12:06:32 +04:00
|
|
|
|
2011-08-23 07:50:41 +04:00
|
|
|
/* Initialize the real server settings here */
|
2012-11-08 00:13:14 +04:00
|
|
|
client->settings->CertificateFile = _strdup("server.crt");
|
|
|
|
client->settings->PrivateKeyFile = _strdup("server.key");
|
2012-11-07 20:02:46 +04:00
|
|
|
client->settings->NlaSecurity = FALSE;
|
2012-11-08 00:13:14 +04:00
|
|
|
client->settings->RemoteFxCodec = TRUE;
|
2013-02-20 18:26:56 +04:00
|
|
|
client->settings->ColorDepth = 32;
|
2012-11-08 00:13:14 +04:00
|
|
|
client->settings->SuppressOutput = TRUE;
|
|
|
|
client->settings->RefreshRect = TRUE;
|
2011-08-22 19:02:56 +04:00
|
|
|
|
2011-09-14 03:03:06 +04:00
|
|
|
client->PostConnect = tf_peer_post_connect;
|
|
|
|
client->Activate = tf_peer_activate;
|
2011-08-23 07:50:41 +04:00
|
|
|
|
2011-09-14 03:03:06 +04:00
|
|
|
client->input->SynchronizeEvent = tf_peer_synchronize_event;
|
|
|
|
client->input->KeyboardEvent = tf_peer_keyboard_event;
|
|
|
|
client->input->UnicodeKeyboardEvent = tf_peer_unicode_keyboard_event;
|
|
|
|
client->input->MouseEvent = tf_peer_mouse_event;
|
|
|
|
client->input->ExtendedMouseEvent = tf_peer_extended_mouse_event;
|
2011-08-23 07:50:41 +04:00
|
|
|
|
2012-05-26 17:34:09 +04:00
|
|
|
client->update->RefreshRect = tf_peer_refresh_rect;
|
|
|
|
client->update->SuppressOutput = tf_peer_suppress_output;
|
|
|
|
|
2013-06-21 18:46:46 +04:00
|
|
|
client->settings->MultifragMaxRequestSize = 0xFFFFFF; /* FIXME */
|
|
|
|
|
2011-08-18 12:06:32 +04:00
|
|
|
client->Initialize(client);
|
2011-12-12 12:42:42 +04:00
|
|
|
context = (testPeerContext*) client->context;
|
2011-08-18 12:06:32 +04:00
|
|
|
|
2012-05-22 19:10:52 +04:00
|
|
|
printf("We've got a client %s\n", client->local ? "(local)" : client->hostname);
|
2011-10-18 11:10:12 +04:00
|
|
|
|
2011-08-18 12:06:32 +04:00
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
rcount = 0;
|
|
|
|
|
2013-08-30 16:19:50 +04:00
|
|
|
memset(rfds, 0, sizeof(rfds));
|
2012-10-09 10:31:28 +04:00
|
|
|
if (client->GetFileDescriptor(client, rfds, &rcount) != TRUE)
|
2011-08-18 12:06:32 +04:00
|
|
|
{
|
|
|
|
printf("Failed to get FreeRDP file descriptor\n");
|
|
|
|
break;
|
|
|
|
}
|
2013-06-24 20:02:21 +04:00
|
|
|
|
|
|
|
#ifndef _WIN32
|
|
|
|
/* winsock's select() only works with sockets ! */
|
2011-12-12 12:42:42 +04:00
|
|
|
WTSVirtualChannelManagerGetFileDescriptor(context->vcm, rfds, &rcount);
|
2013-06-24 20:02:21 +04:00
|
|
|
#endif
|
2011-08-18 12:06:32 +04:00
|
|
|
|
|
|
|
max_fds = 0;
|
|
|
|
FD_ZERO(&rfds_set);
|
|
|
|
|
|
|
|
for (i = 0; i < rcount; i++)
|
|
|
|
{
|
|
|
|
fds = (int)(long)(rfds[i]);
|
|
|
|
|
|
|
|
if (fds > max_fds)
|
|
|
|
max_fds = fds;
|
|
|
|
|
|
|
|
FD_SET(fds, &rfds_set);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (max_fds == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (select(max_fds + 1, &rfds_set, NULL, NULL, NULL) == -1)
|
|
|
|
{
|
2013-06-24 20:02:21 +04:00
|
|
|
#ifdef _WIN32
|
|
|
|
/* error codes set by windows sockets are not made available through errno ! */
|
|
|
|
int wsa_error = WSAGetLastError();
|
|
|
|
if (!((wsa_error == WSAEWOULDBLOCK) ||
|
|
|
|
(wsa_error == WSAEINPROGRESS) ||
|
|
|
|
(wsa_error == WSAEINTR)))
|
|
|
|
{
|
|
|
|
printf("select failed (WSAGetLastError: %d)\n", wsa_error);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#else
|
2011-08-18 12:06:32 +04:00
|
|
|
/* these are not really errors */
|
|
|
|
if (!((errno == EAGAIN) ||
|
|
|
|
(errno == EWOULDBLOCK) ||
|
|
|
|
(errno == EINPROGRESS) ||
|
|
|
|
(errno == EINTR))) /* signal occurred */
|
|
|
|
{
|
2013-06-24 20:02:21 +04:00
|
|
|
printf("select failed (errno: %d)\n", errno);
|
2011-08-18 12:06:32 +04:00
|
|
|
break;
|
|
|
|
}
|
2013-06-24 20:02:21 +04:00
|
|
|
#endif
|
2011-08-18 12:06:32 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
if (client->CheckFileDescriptor(client) != TRUE)
|
2011-12-12 12:42:42 +04:00
|
|
|
break;
|
2013-03-22 01:49:10 +04:00
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
if (WTSVirtualChannelManagerCheckFileDescriptor(context->vcm) != TRUE)
|
2011-08-18 12:06:32 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-05-22 19:10:52 +04:00
|
|
|
printf("Client %s disconnected.\n", client->local ? "(local)" : client->hostname);
|
2011-08-18 19:15:28 +04:00
|
|
|
|
2011-08-18 12:06:32 +04:00
|
|
|
client->Disconnect(client);
|
2011-10-18 11:10:12 +04:00
|
|
|
freerdp_peer_context_free(client);
|
2011-08-18 12:06:32 +04:00
|
|
|
freerdp_peer_free(client);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_peer_accepted(freerdp_listener* instance, freerdp_peer* client)
|
|
|
|
{
|
2013-06-24 20:02:21 +04:00
|
|
|
HANDLE hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) test_peer_mainloop, (void*) client, 0, NULL);
|
|
|
|
if (hThread != NULL) {
|
|
|
|
CloseHandle(hThread);
|
|
|
|
}
|
2011-08-18 12:06:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_server_mainloop(freerdp_listener* instance)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int fds;
|
|
|
|
int max_fds;
|
|
|
|
int rcount;
|
|
|
|
void* rfds[32];
|
|
|
|
fd_set rfds_set;
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
rcount = 0;
|
|
|
|
|
2013-08-30 16:19:50 +04:00
|
|
|
memset(rfds, 0, sizeof(rfds));
|
2012-10-09 10:31:28 +04:00
|
|
|
if (instance->GetFileDescriptor(instance, rfds, &rcount) != TRUE)
|
2011-08-18 12:06:32 +04:00
|
|
|
{
|
|
|
|
printf("Failed to get FreeRDP file descriptor\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
max_fds = 0;
|
|
|
|
FD_ZERO(&rfds_set);
|
|
|
|
|
|
|
|
for (i = 0; i < rcount; i++)
|
|
|
|
{
|
|
|
|
fds = (int)(long)(rfds[i]);
|
|
|
|
|
|
|
|
if (fds > max_fds)
|
|
|
|
max_fds = fds;
|
|
|
|
|
|
|
|
FD_SET(fds, &rfds_set);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (max_fds == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (select(max_fds + 1, &rfds_set, NULL, NULL, NULL) == -1)
|
|
|
|
{
|
|
|
|
/* these are not really errors */
|
|
|
|
if (!((errno == EAGAIN) ||
|
|
|
|
(errno == EWOULDBLOCK) ||
|
|
|
|
(errno == EINPROGRESS) ||
|
|
|
|
(errno == EINTR))) /* signal occurred */
|
|
|
|
{
|
|
|
|
printf("select failed\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
if (instance->CheckFileDescriptor(instance) != TRUE)
|
2011-08-18 12:06:32 +04:00
|
|
|
{
|
|
|
|
printf("Failed to check FreeRDP file descriptor\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
instance->Close(instance);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
freerdp_listener* instance;
|
|
|
|
|
|
|
|
instance = freerdp_listener_new();
|
|
|
|
|
|
|
|
instance->PeerAccepted = test_peer_accepted;
|
|
|
|
|
2011-08-29 07:39:04 +04:00
|
|
|
if (argc > 1)
|
|
|
|
test_pcap_file = argv[1];
|
2011-10-18 20:36:34 +04:00
|
|
|
|
|
|
|
if (argc > 2 && !strcmp(argv[2], "--fast"))
|
2012-10-09 10:31:28 +04:00
|
|
|
test_dump_rfx_realtime = FALSE;
|
2011-08-29 07:39:04 +04:00
|
|
|
|
2011-08-18 12:06:32 +04:00
|
|
|
/* Open the server socket and start listening. */
|
2013-06-24 20:02:21 +04:00
|
|
|
freerdp_wsa_startup();
|
2012-05-22 14:53:11 +04:00
|
|
|
if (instance->Open(instance, NULL, 3389) &&
|
|
|
|
instance->OpenLocal(instance, "/tmp/tfreerdp-server.0"))
|
2011-08-18 12:06:32 +04:00
|
|
|
{
|
|
|
|
/* Entering the server main loop. In a real server the listener can be run in its own thread. */
|
|
|
|
test_server_mainloop(instance);
|
|
|
|
}
|
2013-06-24 20:02:21 +04:00
|
|
|
freerdp_wsa_cleanup();
|
2011-08-18 12:06:32 +04:00
|
|
|
|
|
|
|
freerdp_listener_free(instance);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|