2012-11-15 22:31:47 +04:00
|
|
|
/**
|
2013-02-20 00:06:42 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Client
|
|
|
|
* FreeRDP Mac OS X Server
|
|
|
|
*
|
|
|
|
* Copyright 2012 Corey Clayton <can.of.tuna@gmail.com>
|
|
|
|
*
|
|
|
|
* 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-11-15 22:31:47 +04:00
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <freerdp/listener.h>
|
|
|
|
#include <freerdp/codec/rfx.h>
|
2013-03-22 00:45:25 +04:00
|
|
|
#include <winpr/stream.h>
|
2012-11-15 22:31:47 +04:00
|
|
|
|
2012-12-12 07:07:56 +04:00
|
|
|
#include <winpr/crt.h>
|
|
|
|
|
2012-11-15 22:31:47 +04:00
|
|
|
#include "mf_peer.h"
|
2012-11-16 03:34:33 +04:00
|
|
|
#include "mf_info.h"
|
2013-02-22 04:56:32 +04:00
|
|
|
#include "mf_input.h"
|
2012-11-15 22:31:47 +04:00
|
|
|
#include "mf_event.h"
|
2013-01-24 06:11:41 +04:00
|
|
|
#include "mf_rdpsnd.h"
|
2012-11-15 22:31:47 +04:00
|
|
|
|
|
|
|
#include <mach/clock.h>
|
|
|
|
#include <mach/mach.h>
|
|
|
|
#include <dispatch/dispatch.h>
|
|
|
|
|
|
|
|
#include "OpenGL/OpenGL.h"
|
|
|
|
#include "OpenGL/gl.h"
|
|
|
|
|
|
|
|
#include "CoreVideo/CoreVideo.h"
|
|
|
|
|
|
|
|
//refactor these
|
|
|
|
int info_last_sec = 0;
|
|
|
|
int info_last_nsec = 0;
|
|
|
|
|
|
|
|
dispatch_source_t info_timer;
|
|
|
|
dispatch_queue_t info_queue;
|
|
|
|
|
|
|
|
mfEventQueue* info_event_queue;
|
|
|
|
|
|
|
|
|
|
|
|
CGLContextObj glContext;
|
|
|
|
CGContextRef bmp;
|
|
|
|
CGImageRef img;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BOOL mf_peer_get_fds(freerdp_peer* client, void** rfds, int* rcount)
|
|
|
|
{
|
|
|
|
if (info_event_queue->pipe_fd[0] == -1)
|
|
|
|
return TRUE;
|
2013-02-20 00:06:42 +04:00
|
|
|
|
2012-11-15 22:31:47 +04:00
|
|
|
rfds[*rcount] = (void *)(long) info_event_queue->pipe_fd[0];
|
|
|
|
(*rcount)++;
|
2013-02-20 00:06:42 +04:00
|
|
|
|
2012-11-15 22:31:47 +04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL mf_peer_check_fds(freerdp_peer* client)
|
|
|
|
{
|
2013-02-20 00:06:42 +04:00
|
|
|
mfPeerContext* context = (mfPeerContext*) client->context;
|
2012-11-15 22:31:47 +04:00
|
|
|
mfEvent* event;
|
2013-02-20 00:06:42 +04:00
|
|
|
|
2012-11-15 22:31:47 +04:00
|
|
|
if (context->activated == FALSE)
|
|
|
|
return TRUE;
|
2013-02-20 00:06:42 +04:00
|
|
|
|
2012-11-15 22:31:47 +04:00
|
|
|
event = mf_event_peek(info_event_queue);
|
2013-02-20 00:06:42 +04:00
|
|
|
|
2012-11-15 22:31:47 +04:00
|
|
|
if (event != NULL)
|
|
|
|
{
|
|
|
|
if (event->type == MF_EVENT_TYPE_REGION)
|
|
|
|
{
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "unhandled event\n");
|
2012-11-15 22:31:47 +04:00
|
|
|
}
|
|
|
|
else if (event->type == MF_EVENT_TYPE_FRAME_TICK)
|
|
|
|
{
|
|
|
|
event = mf_event_pop(info_event_queue);
|
2012-12-12 06:20:10 +04:00
|
|
|
|
2013-02-20 00:06:42 +04:00
|
|
|
mf_peer_rfx_update(client);
|
|
|
|
|
2012-11-15 22:31:47 +04:00
|
|
|
mf_event_free(event);
|
|
|
|
}
|
|
|
|
}
|
2013-02-20 00:06:42 +04:00
|
|
|
|
2012-11-15 22:31:47 +04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void mf_peer_rfx_update(freerdp_peer* client)
|
|
|
|
{
|
2013-02-20 00:06:42 +04:00
|
|
|
//check
|
|
|
|
mfInfo* mfi = mf_info_get_instance();
|
|
|
|
|
|
|
|
mf_info_find_invalid_region(mfi);
|
|
|
|
|
|
|
|
if (mf_info_have_invalid_region(mfi) == false) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
long width;
|
|
|
|
long height;
|
|
|
|
int pitch;
|
|
|
|
BYTE* dataBits = NULL;
|
|
|
|
|
|
|
|
mf_info_getScreenData(mfi, &width, &height, &dataBits, &pitch);
|
|
|
|
|
|
|
|
mf_info_clear_invalid_region(mfi);
|
|
|
|
|
|
|
|
//encode
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
wStream* s;
|
2012-11-15 22:31:47 +04:00
|
|
|
RFX_RECT rect;
|
|
|
|
rdpUpdate* update;
|
|
|
|
mfPeerContext* mfp;
|
|
|
|
SURFACE_BITS_COMMAND* cmd;
|
2013-02-20 00:06:42 +04:00
|
|
|
|
2012-11-15 22:31:47 +04:00
|
|
|
update = client->update;
|
|
|
|
mfp = (mfPeerContext*) client->context;
|
|
|
|
cmd = &update->surface_bits_command;
|
2013-02-20 00:06:42 +04:00
|
|
|
|
|
|
|
|
|
|
|
s = mfp->s;
|
2013-05-02 02:15:55 +04:00
|
|
|
Stream_Clear(s);
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_SetPosition(s, 0);
|
2013-02-20 00:06:42 +04:00
|
|
|
|
|
|
|
UINT32 x = mfi->invalid.x / mfi->scale;
|
|
|
|
UINT32 y = mfi->invalid.y / mfi->scale;
|
|
|
|
|
|
|
|
rect.x = 0;
|
|
|
|
rect.y = 0;
|
|
|
|
rect.width = width;
|
|
|
|
rect.height = height;
|
|
|
|
|
|
|
|
mfp->rfx_context->width = mfi->servscreen_width;
|
|
|
|
mfp->rfx_context->height = mfi->servscreen_height;
|
|
|
|
|
|
|
|
rfx_compose_message(mfp->rfx_context, s, &rect, 1,
|
|
|
|
(BYTE*) dataBits, rect.width, rect.height, pitch);
|
|
|
|
|
|
|
|
cmd->destLeft = x;
|
|
|
|
cmd->destTop = y;
|
|
|
|
cmd->destRight = x + rect.width;
|
|
|
|
cmd->destBottom = y + rect.height;
|
|
|
|
|
|
|
|
|
2012-11-15 22:31:47 +04:00
|
|
|
cmd->bpp = 32;
|
|
|
|
cmd->codecID = 3;
|
2012-11-16 05:07:28 +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);
|
2013-02-20 00:06:42 +04:00
|
|
|
|
|
|
|
//send
|
|
|
|
|
|
|
|
update->SurfaceBits(update->context, cmd);
|
|
|
|
|
2013-02-20 01:26:06 +04:00
|
|
|
//clean up... maybe?
|
2013-02-20 00:06:42 +04:00
|
|
|
|
2012-11-15 22:31:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Called when we have a new peer connecting */
|
2013-06-14 05:34:46 +04:00
|
|
|
int mf_peer_context_new(freerdp_peer* client, mfPeerContext* context)
|
2012-11-15 22:31:47 +04:00
|
|
|
{
|
2013-02-20 00:06:42 +04:00
|
|
|
context->info = mf_info_get_instance();
|
2013-08-17 00:46:47 +04:00
|
|
|
context->rfx_context = rfx_context_new(TRUE);
|
2012-11-15 22:31:47 +04:00
|
|
|
context->rfx_context->mode = RLGR3;
|
|
|
|
context->rfx_context->width = client->settings->DesktopWidth;
|
|
|
|
context->rfx_context->height = client->settings->DesktopHeight;
|
2012-12-10 07:17:53 +04:00
|
|
|
rfx_context_set_pixel_format(context->rfx_context, RDP_PIXEL_FORMAT_B8G8R8A8);
|
2013-02-20 00:06:42 +04:00
|
|
|
|
2012-12-13 04:13:26 +04:00
|
|
|
//context->nsc_context = nsc_context_new();
|
|
|
|
//nsc_context_set_pixel_format(context->nsc_context, RDP_PIXEL_FORMAT_B8G8R8A8);
|
2013-02-20 00:06:42 +04:00
|
|
|
|
2013-05-09 01:48:30 +04:00
|
|
|
context->s = Stream_New(NULL, 0xFFFF);
|
2013-02-20 00:06:42 +04:00
|
|
|
|
|
|
|
//#ifdef WITH_SERVER_CHANNELS
|
2012-11-15 22:31:47 +04:00
|
|
|
context->vcm = WTSCreateVirtualChannelManager(client);
|
2013-02-20 00:06:42 +04:00
|
|
|
//#endif
|
|
|
|
|
|
|
|
mf_info_peer_register(context->info, context);
|
2013-06-14 05:34:46 +04:00
|
|
|
|
|
|
|
return 0;
|
2012-11-15 22:31:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Called after a peer disconnects */
|
|
|
|
void mf_peer_context_free(freerdp_peer* client, mfPeerContext* context)
|
|
|
|
{
|
|
|
|
if (context)
|
|
|
|
{
|
2013-02-20 00:06:42 +04:00
|
|
|
mf_info_peer_unregister(context->info, context);
|
|
|
|
|
|
|
|
dispatch_suspend(info_timer);
|
|
|
|
|
2013-05-09 01:48:30 +04:00
|
|
|
Stream_Free(context->s, TRUE);
|
2013-02-20 00:06:42 +04:00
|
|
|
|
2012-11-15 22:31:47 +04:00
|
|
|
rfx_context_free(context->rfx_context);
|
2012-12-13 04:13:26 +04:00
|
|
|
//nsc_context_free(context->nsc_context);
|
2013-02-20 00:06:42 +04:00
|
|
|
|
2012-11-15 22:31:47 +04:00
|
|
|
#ifdef CHANNEL_AUDIN_SERVER
|
|
|
|
if (context->audin)
|
|
|
|
audin_server_context_free(context->audin);
|
|
|
|
#endif
|
2013-02-20 00:06:42 +04:00
|
|
|
|
|
|
|
//#ifdef CHANNEL_RDPSND_SERVER
|
|
|
|
mf_peer_rdpsnd_stop();
|
2012-11-15 22:31:47 +04:00
|
|
|
if (context->rdpsnd)
|
|
|
|
rdpsnd_server_context_free(context->rdpsnd);
|
2013-02-20 00:06:42 +04:00
|
|
|
//#endif
|
|
|
|
|
|
|
|
//#ifdef WITH_SERVER_CHANNELS
|
2012-11-15 22:31:47 +04:00
|
|
|
WTSDestroyVirtualChannelManager(context->vcm);
|
2013-02-20 00:06:42 +04:00
|
|
|
//#endif
|
2012-11-15 22:31:47 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Called when a new client connects */
|
|
|
|
void mf_peer_init(freerdp_peer* client)
|
|
|
|
{
|
2013-06-14 05:34:46 +04:00
|
|
|
client->ContextSize = sizeof(mfPeerContext);
|
2012-11-15 22:31:47 +04:00
|
|
|
client->ContextNew = (psPeerContextNew) mf_peer_context_new;
|
|
|
|
client->ContextFree = (psPeerContextFree) mf_peer_context_free;
|
|
|
|
freerdp_peer_context_new(client);
|
2013-02-20 00:06:42 +04:00
|
|
|
|
|
|
|
info_event_queue = mf_event_queue_new();
|
|
|
|
|
2013-03-06 02:22:52 +04:00
|
|
|
info_queue = dispatch_queue_create("FreeRDP.update.timer", DISPATCH_QUEUE_SERIAL);
|
2013-02-20 00:06:42 +04:00
|
|
|
info_timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, info_queue);
|
|
|
|
|
|
|
|
if(info_timer)
|
|
|
|
{
|
2013-03-29 02:06:34 +04:00
|
|
|
//fprintf(stderr, "created timer\n");
|
2013-02-20 00:06:42 +04:00
|
|
|
dispatch_source_set_timer(info_timer, DISPATCH_TIME_NOW, 42ull * NSEC_PER_MSEC, 100ull * NSEC_PER_MSEC);
|
|
|
|
dispatch_source_set_event_handler(info_timer, ^{
|
2013-03-29 02:06:34 +04:00
|
|
|
//fprintf(stderr, "dispatch\n");
|
2013-02-20 00:06:42 +04:00
|
|
|
mfEvent* event = mf_event_new(MF_EVENT_TYPE_FRAME_TICK);
|
|
|
|
mf_event_push(info_event_queue, (mfEvent*) event);}
|
|
|
|
);
|
|
|
|
dispatch_resume(info_timer);
|
|
|
|
}
|
2012-11-15 22:31:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BOOL mf_peer_post_connect(freerdp_peer* client)
|
|
|
|
{
|
2013-01-24 06:11:41 +04:00
|
|
|
mfPeerContext* context = (mfPeerContext*) client->context;
|
2013-02-20 00:06:42 +04:00
|
|
|
rdpSettings* settings = client->settings;
|
|
|
|
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "Client %s post connect\n", client->hostname);
|
2013-02-20 00:06:42 +04:00
|
|
|
|
2012-11-15 22:31:47 +04:00
|
|
|
if (client->settings->AutoLogonEnabled)
|
|
|
|
{
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, " and wants to login automatically as %s\\%s",
|
2013-02-20 00:06:42 +04:00
|
|
|
client->settings->Domain ? client->settings->Domain : "",
|
|
|
|
client->settings->Username);
|
|
|
|
|
2012-11-15 22:31:47 +04:00
|
|
|
/* A real server may perform OS login here if NLA is not executed previously. */
|
|
|
|
}
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "\n");
|
2013-02-20 00:06:42 +04:00
|
|
|
|
|
|
|
mfInfo* mfi = mf_info_get_instance();
|
|
|
|
mfi->scale = 1;
|
|
|
|
|
|
|
|
//mfi->servscreen_width = 2880 / mfi->scale;
|
|
|
|
//mfi->servscreen_height = 1800 / mfi->scale;
|
|
|
|
UINT32 bitsPerPixel = 32;
|
|
|
|
|
|
|
|
if ((settings->DesktopWidth != mfi->servscreen_width) || (settings->DesktopHeight != mfi->servscreen_height))
|
2012-11-15 22:31:47 +04:00
|
|
|
{
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "Client requested resolution %dx%d, but will resize to %dx%d\n",
|
2013-02-20 00:06:42 +04:00
|
|
|
settings->DesktopWidth, settings->DesktopHeight, mfi->servscreen_width, mfi->servscreen_height);
|
|
|
|
}
|
|
|
|
|
|
|
|
settings->DesktopWidth = mfi->servscreen_width;
|
|
|
|
settings->DesktopHeight = mfi->servscreen_height;
|
|
|
|
settings->ColorDepth = bitsPerPixel;
|
|
|
|
|
|
|
|
client->update->DesktopResize(client->update->context);
|
|
|
|
|
2013-02-22 22:01:31 +04:00
|
|
|
mfi->mouse_down_left = FALSE;
|
|
|
|
mfi->mouse_down_right = FALSE;
|
|
|
|
mfi->mouse_down_other = FALSE;
|
|
|
|
|
2013-02-20 00:06:42 +04:00
|
|
|
|
|
|
|
//#ifdef WITH_SERVER_CHANNELS
|
2012-11-15 22:31:47 +04:00
|
|
|
/* Iterate all channel names requested by the client and activate those supported by the server */
|
2013-02-20 00:06:42 +04:00
|
|
|
int i;
|
2012-11-15 22:31:47 +04:00
|
|
|
for (i = 0; i < client->settings->ChannelCount; i++)
|
|
|
|
{
|
|
|
|
if (client->settings->ChannelDefArray[i].joined)
|
|
|
|
{
|
2013-02-20 00:06:42 +04:00
|
|
|
//#ifdef CHANNEL_RDPSND_SERVER
|
2012-11-15 22:31:47 +04:00
|
|
|
if (strncmp(client->settings->ChannelDefArray[i].Name, "rdpsnd", 6) == 0)
|
|
|
|
{
|
|
|
|
mf_peer_rdpsnd_init(context); /* Audio Output */
|
|
|
|
}
|
2013-02-20 00:06:42 +04:00
|
|
|
//#endif
|
2012-11-15 22:31:47 +04:00
|
|
|
}
|
|
|
|
}
|
2013-02-20 00:06:42 +04:00
|
|
|
|
2012-11-15 22:31:47 +04:00
|
|
|
/* Dynamic Virtual Channels */
|
2013-02-20 00:06:42 +04:00
|
|
|
//#endif
|
|
|
|
|
2012-11-15 22:31:47 +04:00
|
|
|
#ifdef CHANNEL_AUDIN_SERVER
|
|
|
|
mf_peer_audin_init(context); /* Audio Input */
|
|
|
|
#endif
|
2013-02-20 00:06:42 +04:00
|
|
|
|
2012-11-15 22:31:47 +04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BOOL mf_peer_activate(freerdp_peer* client)
|
|
|
|
{
|
|
|
|
mfPeerContext* context = (mfPeerContext*) client->context;
|
2013-02-20 00:06:42 +04:00
|
|
|
|
2012-11-15 22:31:47 +04:00
|
|
|
rfx_context_reset(context->rfx_context);
|
|
|
|
context->activated = TRUE;
|
2013-02-20 00:06:42 +04:00
|
|
|
|
2012-11-15 22:31:47 +04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*BOOL wf_peer_logon(freerdp_peer* client, SEC_WINNT_AUTH_IDENTITY* identity, BOOL automatic)
|
2013-02-20 00:06:42 +04:00
|
|
|
{
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "PeerLogon\n");
|
2013-02-20 00:06:42 +04:00
|
|
|
|
|
|
|
if (automatic)
|
|
|
|
{
|
|
|
|
_tprintf(_T("Logon: User:%s Domain:%s Password:%s\n"),
|
|
|
|
identity->User, identity->Domain, identity->Password);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wfreerdp_server_peer_callback_event(((rdpContext*) client->context)->peer->pId, WF_SRV_CALLBACK_EVENT_AUTH);
|
|
|
|
return TRUE;
|
|
|
|
}*/
|
2012-11-15 22:31:47 +04:00
|
|
|
|
|
|
|
void mf_peer_synchronize_event(rdpInput* input, UINT32 flags)
|
|
|
|
{
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "Client sent a synchronize event (flags:0x%08X)\n", flags);
|
2012-11-15 22:31:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void mf_peer_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
|
|
|
|
{
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "Client sent a keyboard event (flags:0x%04X code:0x%04X)\n", flags, code);
|
2013-02-20 00:06:42 +04:00
|
|
|
|
|
|
|
UINT16 down = 0x4000;
|
|
|
|
//UINT16 up = 0x8000;
|
|
|
|
|
|
|
|
bool state_down = FALSE;
|
|
|
|
|
|
|
|
if (flags == down)
|
|
|
|
{
|
|
|
|
state_down = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
CGEventRef event;
|
|
|
|
event = CGEventCreateKeyboardEvent(NULL, (CGKeyCode)code, state_down);
|
|
|
|
CGEventPost(kCGHIDEventTap, event);
|
|
|
|
CFRelease(event);
|
|
|
|
*/
|
2012-11-15 22:31:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void mf_peer_unicode_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
|
|
|
|
{
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "Client sent a unicode keyboard event (flags:0x%04X code:0x%04X)\n", flags, code);
|
2012-11-15 22:31:47 +04:00
|
|
|
}
|
|
|
|
|
2013-02-22 04:56:32 +04:00
|
|
|
/*void mf_peer_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
|
2012-11-15 22:31:47 +04:00
|
|
|
{
|
2013-03-29 02:06:34 +04:00
|
|
|
//fprintf(stderr, "Client sent a mouse event (flags:0x%04X pos: %d,%d)\n", flags, x, y);
|
2012-11-15 22:31:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void mf_peer_extended_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
|
|
|
|
{
|
2013-03-29 02:06:34 +04:00
|
|
|
//fprintf(stderr, "Client sent an extended mouse event (flags:0x%04X pos: %d,%d)\n", flags, x, y);
|
2012-11-15 22:31:47 +04:00
|
|
|
}
|
2013-02-22 04:56:32 +04:00
|
|
|
*/
|
2012-12-13 04:13:26 +04:00
|
|
|
/*static void mf_peer_refresh_rect(rdpContext* context, BYTE count, RECTANGLE_16* areas)
|
2013-02-20 00:06:42 +04:00
|
|
|
{
|
|
|
|
BYTE i;
|
|
|
|
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "Client requested to refresh:\n");
|
2013-02-20 00:06:42 +04:00
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, " (%d, %d) (%d, %d)\n", areas[i].left, areas[i].top, areas[i].right, areas[i].bottom);
|
2013-02-20 00:06:42 +04:00
|
|
|
}
|
|
|
|
}*/
|
2012-11-15 22:31:47 +04:00
|
|
|
|
|
|
|
static void mf_peer_suppress_output(rdpContext* context, BYTE allow, RECTANGLE_16* area)
|
|
|
|
{
|
|
|
|
if (allow > 0)
|
|
|
|
{
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "Client restore output (%d, %d) (%d, %d).\n", area->left, area->top, area->right, area->bottom);
|
2012-11-15 22:31:47 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "Client minimized and suppress output.\n");
|
2012-11-15 22:31:47 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void mf_peer_accepted(freerdp_listener* instance, freerdp_peer* client)
|
|
|
|
{
|
|
|
|
pthread_t th;
|
2013-02-20 00:06:42 +04:00
|
|
|
|
2012-11-15 22:31:47 +04:00
|
|
|
pthread_create(&th, 0, mf_peer_main_loop, client);
|
|
|
|
pthread_detach(th);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*DWORD WINAPI wf_peer_socket_listener(LPVOID lpParam)
|
2013-02-20 00:06:42 +04:00
|
|
|
{
|
|
|
|
int i, fds;
|
|
|
|
int rcount;
|
|
|
|
int max_fds;
|
|
|
|
void* rfds[32];
|
|
|
|
fd_set rfds_set;
|
|
|
|
wfPeerContext* context;
|
|
|
|
freerdp_peer* client = (freerdp_peer*) lpParam;
|
|
|
|
|
|
|
|
ZeroMemory(rfds, sizeof(rfds));
|
|
|
|
context = (wfPeerContext*) client->context;
|
|
|
|
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "PeerSocketListener\n");
|
2013-02-20 00:06:42 +04:00
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
rcount = 0;
|
|
|
|
|
|
|
|
if (client->GetFileDescriptor(client, rfds, &rcount) != TRUE)
|
|
|
|
{
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "Failed to get peer file descriptor\n");
|
2013-02-20 00:06:42 +04:00
|
|
|
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;
|
|
|
|
|
|
|
|
select(max_fds + 1, &rfds_set, NULL, NULL, NULL);
|
|
|
|
|
|
|
|
SetEvent(context->socketEvent);
|
|
|
|
WaitForSingleObject(context->socketSemaphore, INFINITE);
|
|
|
|
|
|
|
|
if (context->socketClose)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "Exiting Peer Socket Listener Thread\n");
|
2013-02-20 00:06:42 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void wf_peer_read_settings(freerdp_peer* client)
|
|
|
|
{
|
|
|
|
if (!wf_settings_read_string_ascii(HKEY_LOCAL_MACHINE, _T("Software\\FreeRDP\\Server"), _T("CertificateFile"), &(client->settings->CertificateFile)))
|
|
|
|
client->settings->CertificateFile = _strdup("server.crt");
|
|
|
|
|
|
|
|
if (!wf_settings_read_string_ascii(HKEY_LOCAL_MACHINE, _T("Software\\FreeRDP\\Server"), _T("PrivateKeyFile"), &(client->settings->PrivateKeyFile)))
|
|
|
|
client->settings->PrivateKeyFile = _strdup("server.key");
|
|
|
|
}*/
|
2012-11-15 22:31:47 +04:00
|
|
|
|
2012-11-16 00:43:58 +04:00
|
|
|
void* mf_peer_main_loop(void* arg)
|
2012-11-15 22:31:47 +04:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int fds;
|
|
|
|
int max_fds;
|
|
|
|
int rcount;
|
|
|
|
void* rfds[32];
|
|
|
|
fd_set rfds_set;
|
|
|
|
mfPeerContext* context;
|
|
|
|
freerdp_peer* client = (freerdp_peer*) arg;
|
2013-02-20 00:06:42 +04:00
|
|
|
|
2012-11-15 22:31:47 +04:00
|
|
|
memset(rfds, 0, sizeof(rfds));
|
2013-02-20 00:06:42 +04:00
|
|
|
|
2012-11-15 22:31:47 +04:00
|
|
|
mf_peer_init(client);
|
2013-02-20 00:06:42 +04:00
|
|
|
|
2012-11-15 22:31:47 +04:00
|
|
|
/* Initialize the real server settings here */
|
2012-12-12 07:07:56 +04:00
|
|
|
client->settings->CertificateFile = _strdup("server.crt");
|
|
|
|
client->settings->PrivateKeyFile = _strdup("server.key");
|
2012-11-15 22:31:47 +04:00
|
|
|
client->settings->NlaSecurity = FALSE;
|
|
|
|
client->settings->RemoteFxCodec = TRUE;
|
2013-01-28 02:17:04 +04:00
|
|
|
client->settings->ColorDepth = 32;
|
2012-11-15 22:31:47 +04:00
|
|
|
client->settings->SuppressOutput = TRUE;
|
2012-12-13 04:13:26 +04:00
|
|
|
client->settings->RefreshRect = FALSE;
|
2013-02-20 00:06:42 +04:00
|
|
|
|
2012-11-15 22:31:47 +04:00
|
|
|
client->PostConnect = mf_peer_post_connect;
|
|
|
|
client->Activate = mf_peer_activate;
|
2013-02-20 00:06:42 +04:00
|
|
|
|
2012-11-15 22:31:47 +04:00
|
|
|
client->input->SynchronizeEvent = mf_peer_synchronize_event;
|
2013-02-28 02:16:09 +04:00
|
|
|
client->input->KeyboardEvent = mf_input_keyboard_event;//mf_peer_keyboard_event;
|
2012-11-15 22:31:47 +04:00
|
|
|
client->input->UnicodeKeyboardEvent = mf_peer_unicode_keyboard_event;
|
2013-02-22 04:56:32 +04:00
|
|
|
client->input->MouseEvent = mf_input_mouse_event;
|
|
|
|
client->input->ExtendedMouseEvent = mf_input_extended_mouse_event;
|
2013-02-20 00:06:42 +04:00
|
|
|
|
2012-12-13 04:13:26 +04:00
|
|
|
//client->update->RefreshRect = mf_peer_refresh_rect;
|
2012-11-15 22:31:47 +04:00
|
|
|
client->update->SuppressOutput = mf_peer_suppress_output;
|
2013-02-20 00:06:42 +04:00
|
|
|
|
2012-11-15 22:31:47 +04:00
|
|
|
client->Initialize(client);
|
|
|
|
context = (mfPeerContext*) client->context;
|
2013-02-20 00:06:42 +04:00
|
|
|
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "We've got a client %s\n", client->local ? "(local)" : client->hostname);
|
2013-02-20 00:06:42 +04:00
|
|
|
|
2012-11-15 22:31:47 +04:00
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
rcount = 0;
|
2013-02-20 00:06:42 +04:00
|
|
|
|
2012-11-15 22:31:47 +04:00
|
|
|
if (client->GetFileDescriptor(client, rfds, &rcount) != TRUE)
|
|
|
|
{
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "Failed to get FreeRDP file descriptor\n");
|
2012-11-15 22:31:47 +04:00
|
|
|
break;
|
|
|
|
}
|
2013-02-20 00:06:42 +04:00
|
|
|
if (mf_peer_get_fds(client, rfds, &rcount) != TRUE)
|
2012-11-15 22:31:47 +04:00
|
|
|
{
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "Failed to get mfreerdp file descriptor\n");
|
2012-11-15 22:31:47 +04:00
|
|
|
break;
|
|
|
|
}
|
2013-02-20 00:06:42 +04:00
|
|
|
|
|
|
|
//#ifdef WITH_SERVER_CHANNELS
|
2012-11-15 22:31:47 +04:00
|
|
|
WTSVirtualChannelManagerGetFileDescriptor(context->vcm, rfds, &rcount);
|
2013-02-20 00:06:42 +04:00
|
|
|
//#endif
|
|
|
|
|
2012-11-15 22:31:47 +04:00
|
|
|
max_fds = 0;
|
|
|
|
FD_ZERO(&rfds_set);
|
2013-02-20 00:06:42 +04:00
|
|
|
|
2012-11-15 22:31:47 +04:00
|
|
|
for (i = 0; i < rcount; i++)
|
|
|
|
{
|
|
|
|
fds = (int)(long)(rfds[i]);
|
2013-02-20 00:06:42 +04:00
|
|
|
|
2012-11-15 22:31:47 +04:00
|
|
|
if (fds > max_fds)
|
|
|
|
max_fds = fds;
|
2013-02-20 00:06:42 +04:00
|
|
|
|
2012-11-15 22:31:47 +04:00
|
|
|
FD_SET(fds, &rfds_set);
|
|
|
|
}
|
2013-02-20 00:06:42 +04:00
|
|
|
|
2012-11-15 22:31:47 +04:00
|
|
|
if (max_fds == 0)
|
|
|
|
break;
|
2013-02-20 00:06:42 +04:00
|
|
|
|
2012-11-15 22:31:47 +04:00
|
|
|
if (select(max_fds + 1, &rfds_set, NULL, NULL, NULL) == -1)
|
|
|
|
{
|
|
|
|
/* these are not really errors */
|
|
|
|
if (!((errno == EAGAIN) ||
|
2013-02-20 00:06:42 +04:00
|
|
|
(errno == EWOULDBLOCK) ||
|
|
|
|
(errno == EINPROGRESS) ||
|
|
|
|
(errno == EINTR))) /* signal occurred */
|
2012-11-15 22:31:47 +04:00
|
|
|
{
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "select failed\n");
|
2012-11-15 22:31:47 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-02-20 00:06:42 +04:00
|
|
|
|
|
|
|
if (client->CheckFileDescriptor(client) != TRUE)
|
2012-11-15 22:31:47 +04:00
|
|
|
{
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "Failed to check freerdp file descriptor\n");
|
2012-11-15 22:31:47 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if ((mf_peer_check_fds(client)) != TRUE)
|
|
|
|
{
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "Failed to check mfreerdp file descriptor\n");
|
2012-11-15 22:31:47 +04:00
|
|
|
break;
|
|
|
|
}
|
2013-02-20 00:06:42 +04:00
|
|
|
|
|
|
|
|
|
|
|
//#ifdef WITH_SERVER_CHANNELS
|
2012-11-15 22:31:47 +04:00
|
|
|
if (WTSVirtualChannelManagerCheckFileDescriptor(context->vcm) != TRUE)
|
|
|
|
break;
|
2013-02-20 00:06:42 +04:00
|
|
|
//#endif
|
|
|
|
|
2012-11-15 22:31:47 +04:00
|
|
|
}
|
2013-02-20 00:06:42 +04:00
|
|
|
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "Client %s disconnected.\n", client->local ? "(local)" : client->hostname);
|
2013-02-20 00:06:42 +04:00
|
|
|
|
2012-11-15 22:31:47 +04:00
|
|
|
client->Disconnect(client);
|
|
|
|
freerdp_peer_context_free(client);
|
|
|
|
freerdp_peer_free(client);
|
2013-02-20 00:06:42 +04:00
|
|
|
|
2012-11-15 22:31:47 +04:00
|
|
|
return NULL;
|
2013-01-28 02:17:04 +04:00
|
|
|
}
|