2011-09-14 00:30:16 +04:00
|
|
|
/**
|
|
|
|
* FreeRDP: A Remote Desktop Protocol Client
|
|
|
|
* X11 Peer
|
|
|
|
*
|
|
|
|
* Copyright 2011 Marc-Andre Moreau <marcandre.moreau@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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2012-01-08 06:36:12 +04:00
|
|
|
#include <unistd.h>
|
2012-01-10 07:08:25 +04:00
|
|
|
#include <sys/ipc.h>
|
|
|
|
#include <sys/shm.h>
|
2011-10-27 21:41:39 +04:00
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <X11/Xutil.h>
|
|
|
|
#include <sys/select.h>
|
2012-01-09 05:32:50 +04:00
|
|
|
#include <freerdp/kbd/kbd.h>
|
2012-01-08 06:36:12 +04:00
|
|
|
#include <freerdp/codec/color.h>
|
2012-01-31 05:35:33 +04:00
|
|
|
#include <freerdp/utils/file.h>
|
2011-09-14 00:30:16 +04:00
|
|
|
#include <freerdp/utils/sleep.h>
|
|
|
|
#include <freerdp/utils/memory.h>
|
|
|
|
#include <freerdp/utils/thread.h>
|
|
|
|
|
|
|
|
extern char* xf_pcap_file;
|
2011-10-20 16:25:25 +04:00
|
|
|
extern boolean xf_pcap_dump_realtime;
|
2011-09-14 00:30:16 +04:00
|
|
|
|
2011-09-14 03:03:06 +04:00
|
|
|
#include "xf_encode.h"
|
|
|
|
|
2011-09-14 00:30:16 +04:00
|
|
|
#include "xf_peer.h"
|
|
|
|
|
2012-01-03 07:33:35 +04:00
|
|
|
#ifdef WITH_XDAMAGE
|
|
|
|
|
|
|
|
void xf_xdamage_init(xfInfo* xfi)
|
|
|
|
{
|
2012-01-10 07:08:25 +04:00
|
|
|
Bool pixmaps;
|
2012-01-03 07:33:35 +04:00
|
|
|
int damage_event;
|
|
|
|
int damage_error;
|
|
|
|
int major, minor;
|
|
|
|
XGCValues values;
|
|
|
|
|
2012-01-10 07:08:25 +04:00
|
|
|
if (XShmQueryExtension(xfi->display) != False)
|
|
|
|
{
|
|
|
|
XShmQueryVersion(xfi->display, &major, &minor, &pixmaps);
|
|
|
|
|
|
|
|
if (pixmaps != True)
|
|
|
|
{
|
|
|
|
printf("XShmQueryVersion failed\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printf("XShmQueryExtension failed\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-01-03 07:33:35 +04:00
|
|
|
if (XDamageQueryExtension(xfi->display, &damage_event, &damage_error) == 0)
|
|
|
|
{
|
|
|
|
printf("XDamageQueryExtension failed\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
XDamageQueryVersion(xfi->display, &major, &minor);
|
|
|
|
|
|
|
|
if (XDamageQueryVersion(xfi->display, &major, &minor) == 0)
|
|
|
|
{
|
|
|
|
printf("XDamageQueryVersion failed\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (major < 1)
|
|
|
|
{
|
|
|
|
printf("XDamageQueryVersion failed: major:%d minor:%d\n", major, minor);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
xfi->xdamage_notify_event = damage_event + XDamageNotify;
|
2012-01-10 07:08:25 +04:00
|
|
|
xfi->xdamage = XDamageCreate(xfi->display, xfi->root_window, XDamageReportDeltaRectangles);
|
2012-01-03 07:33:35 +04:00
|
|
|
|
|
|
|
if (xfi->xdamage == None)
|
|
|
|
{
|
|
|
|
printf("XDamageCreate failed\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef WITH_XFIXES
|
|
|
|
xfi->xdamage_region = XFixesCreateRegion(xfi->display, NULL, 0);
|
|
|
|
|
|
|
|
if (xfi->xdamage_region == None)
|
|
|
|
{
|
|
|
|
printf("XFixesCreateRegion failed\n");
|
|
|
|
XDamageDestroy(xfi->display, xfi->xdamage);
|
|
|
|
xfi->xdamage = None;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
values.subwindow_mode = IncludeInferiors;
|
2012-01-10 07:08:25 +04:00
|
|
|
xfi->xdamage_gc = XCreateGC(xfi->display, xfi->root_window, GCSubwindowMode, &values);
|
2012-01-03 07:33:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2012-01-10 07:08:25 +04:00
|
|
|
void xf_xshm_init(xfInfo* xfi)
|
|
|
|
{
|
|
|
|
xfi->use_xshm = false;
|
|
|
|
xfi->fb_shm_info.shmid = -1;
|
|
|
|
xfi->fb_shm_info.shmaddr = (char*) -1;
|
|
|
|
|
|
|
|
xfi->fb_image = XShmCreateImage(xfi->display, xfi->visual, xfi->depth,
|
|
|
|
ZPixmap, NULL, &(xfi->fb_shm_info), xfi->width, xfi->height);
|
|
|
|
|
|
|
|
if (xfi->fb_image == NULL)
|
|
|
|
{
|
|
|
|
printf("XShmCreateImage failed\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
xfi->fb_shm_info.shmid = shmget(IPC_PRIVATE,
|
|
|
|
xfi->fb_image->bytes_per_line * xfi->fb_image->height, IPC_CREAT | 0600);
|
|
|
|
|
|
|
|
if (xfi->fb_shm_info.shmid == -1)
|
|
|
|
{
|
|
|
|
printf("shmget failed\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
xfi->fb_shm_info.readOnly = False;
|
|
|
|
xfi->fb_shm_info.shmaddr = shmat(xfi->fb_shm_info.shmid, 0, 0);
|
|
|
|
xfi->fb_image->data = xfi->fb_shm_info.shmaddr;
|
|
|
|
|
|
|
|
if (xfi->fb_shm_info.shmaddr == ((char*) -1))
|
|
|
|
{
|
|
|
|
printf("shmat failed\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
XShmAttach(xfi->display, &(xfi->fb_shm_info));
|
|
|
|
XSync(xfi->display, False);
|
|
|
|
|
|
|
|
shmctl(xfi->fb_shm_info.shmid, IPC_RMID, 0);
|
|
|
|
|
|
|
|
xfi->fb_pixmap = XShmCreatePixmap(xfi->display,
|
|
|
|
xfi->root_window, xfi->fb_image->data, &(xfi->fb_shm_info),
|
|
|
|
xfi->fb_image->width, xfi->fb_image->height, xfi->fb_image->depth);
|
|
|
|
|
|
|
|
//xfi->use_xshm = true;
|
|
|
|
}
|
|
|
|
|
2011-10-18 11:10:12 +04:00
|
|
|
xfInfo* xf_info_init()
|
2011-09-14 00:30:16 +04:00
|
|
|
{
|
2011-10-18 11:10:12 +04:00
|
|
|
int i;
|
|
|
|
xfInfo* xfi;
|
|
|
|
int pf_count;
|
|
|
|
int vi_count;
|
|
|
|
XVisualInfo* vi;
|
|
|
|
XVisualInfo* vis;
|
|
|
|
XVisualInfo template;
|
|
|
|
XPixmapFormatValues* pf;
|
|
|
|
XPixmapFormatValues* pfs;
|
|
|
|
|
|
|
|
xfi = xnew(xfInfo);
|
|
|
|
|
|
|
|
xfi->display = XOpenDisplay(NULL);
|
|
|
|
|
2012-01-08 06:36:12 +04:00
|
|
|
XInitThreads();
|
|
|
|
|
2011-10-18 11:10:12 +04:00
|
|
|
if (xfi->display == NULL)
|
2011-10-20 16:25:25 +04:00
|
|
|
{
|
2011-10-18 11:10:12 +04:00
|
|
|
printf("failed to open display: %s\n", XDisplayName(NULL));
|
2011-10-20 16:25:25 +04:00
|
|
|
exit(1);
|
|
|
|
}
|
2011-10-18 11:10:12 +04:00
|
|
|
|
|
|
|
xfi->number = DefaultScreen(xfi->display);
|
|
|
|
xfi->screen = ScreenOfDisplay(xfi->display, xfi->number);
|
|
|
|
xfi->depth = DefaultDepthOfScreen(xfi->screen);
|
|
|
|
xfi->width = WidthOfScreen(xfi->screen);
|
|
|
|
xfi->height = HeightOfScreen(xfi->screen);
|
2012-01-10 07:08:25 +04:00
|
|
|
xfi->root_window = DefaultRootWindow(xfi->display);
|
2011-10-18 11:10:12 +04:00
|
|
|
|
|
|
|
pfs = XListPixmapFormats(xfi->display, &pf_count);
|
|
|
|
|
|
|
|
if (pfs == NULL)
|
|
|
|
{
|
|
|
|
printf("XListPixmapFormats failed\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < pf_count; i++)
|
|
|
|
{
|
|
|
|
pf = pfs + i;
|
|
|
|
|
|
|
|
if (pf->depth == xfi->depth)
|
|
|
|
{
|
|
|
|
xfi->bpp = pf->bits_per_pixel;
|
|
|
|
xfi->scanline_pad = pf->scanline_pad;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
XFree(pfs);
|
|
|
|
|
|
|
|
memset(&template, 0, sizeof(template));
|
|
|
|
template.class = TrueColor;
|
|
|
|
template.screen = xfi->number;
|
|
|
|
|
|
|
|
vis = XGetVisualInfo(xfi->display, VisualClassMask | VisualScreenMask, &template, &vi_count);
|
2011-09-14 00:30:16 +04:00
|
|
|
|
2011-10-18 11:10:12 +04:00
|
|
|
if (vis == NULL)
|
|
|
|
{
|
|
|
|
printf("XGetVisualInfo failed\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < vi_count; i++)
|
|
|
|
{
|
|
|
|
vi = vis + i;
|
|
|
|
|
|
|
|
if (vi->depth == xfi->depth)
|
|
|
|
{
|
|
|
|
xfi->visual = vi->visual;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
XFree(vis);
|
2011-09-14 00:30:16 +04:00
|
|
|
|
2011-10-18 11:10:12 +04:00
|
|
|
xfi->clrconv = (HCLRCONV) xnew(HCLRCONV);
|
|
|
|
xfi->clrconv->invert = 1;
|
|
|
|
xfi->clrconv->alpha = 1;
|
2011-09-14 00:30:16 +04:00
|
|
|
|
2012-01-10 07:08:25 +04:00
|
|
|
XSelectInput(xfi->display, xfi->root_window, SubstructureNotifyMask);
|
2012-01-03 07:33:35 +04:00
|
|
|
|
2011-12-05 18:20:59 +04:00
|
|
|
#ifdef WITH_XDAMAGE
|
2012-01-03 07:33:35 +04:00
|
|
|
xf_xdamage_init(xfi);
|
2012-01-10 07:08:25 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
xf_xshm_init(xfi);
|
|
|
|
|
|
|
|
xfi->bytesPerPixel = (xfi->use_xshm) ? 4 : 3;
|
2011-11-08 02:20:00 +04:00
|
|
|
|
2012-01-09 05:32:50 +04:00
|
|
|
freerdp_kbd_init(xfi->display, 0);
|
|
|
|
|
2011-10-18 11:10:12 +04:00
|
|
|
return xfi;
|
|
|
|
}
|
2011-09-14 00:30:16 +04:00
|
|
|
|
2011-10-18 11:10:12 +04:00
|
|
|
void xf_peer_context_new(freerdp_peer* client, xfPeerContext* context)
|
2011-09-14 00:30:16 +04:00
|
|
|
{
|
2011-10-18 11:10:12 +04:00
|
|
|
context->info = xf_info_init();
|
2011-10-29 18:01:50 +04:00
|
|
|
context->rfx_context = rfx_context_new();
|
2011-10-18 11:10:12 +04:00
|
|
|
context->rfx_context->mode = RLGR3;
|
2011-11-08 02:20:00 +04:00
|
|
|
context->rfx_context->width = context->info->width;
|
|
|
|
context->rfx_context->height = context->info->height;
|
2012-01-10 07:08:25 +04:00
|
|
|
|
|
|
|
if (context->info->use_xshm)
|
|
|
|
rfx_context_set_pixel_format(context->rfx_context, RFX_PIXEL_FORMAT_BGRA);
|
|
|
|
else
|
|
|
|
rfx_context_set_pixel_format(context->rfx_context, RFX_PIXEL_FORMAT_RGB);
|
2011-10-18 11:10:12 +04:00
|
|
|
|
|
|
|
context->s = stream_new(65536);
|
|
|
|
}
|
2011-09-14 00:30:16 +04:00
|
|
|
|
2011-10-18 11:10:12 +04:00
|
|
|
void xf_peer_context_free(freerdp_peer* client, xfPeerContext* context)
|
|
|
|
{
|
|
|
|
if (context)
|
2011-09-14 00:30:16 +04:00
|
|
|
{
|
2011-10-18 11:10:12 +04:00
|
|
|
stream_free(context->s);
|
|
|
|
rfx_context_free(context->rfx_context);
|
|
|
|
xfree(context);
|
2011-09-14 00:30:16 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-18 11:10:12 +04:00
|
|
|
void xf_peer_init(freerdp_peer* client)
|
|
|
|
{
|
2012-01-08 06:36:12 +04:00
|
|
|
xfPeerContext* xfp;
|
|
|
|
|
2011-10-30 09:43:04 +04:00
|
|
|
client->context_size = sizeof(xfPeerContext);
|
2011-10-18 11:10:12 +04:00
|
|
|
client->ContextNew = (psPeerContextNew) xf_peer_context_new;
|
|
|
|
client->ContextFree = (psPeerContextFree) xf_peer_context_free;
|
|
|
|
freerdp_peer_context_new(client);
|
2012-01-08 06:36:12 +04:00
|
|
|
|
|
|
|
xfp = (xfPeerContext*) client->context;
|
|
|
|
|
|
|
|
xfp->pipe_fd[0] = -1;
|
|
|
|
xfp->pipe_fd[1] = -1;
|
|
|
|
|
|
|
|
if (pipe(xfp->pipe_fd) < 0)
|
|
|
|
printf("xf_peer_init: pipe failed\n");
|
|
|
|
|
|
|
|
xfp->thread = 0;
|
|
|
|
xfp->activations = 0;
|
|
|
|
|
|
|
|
xfp->stopwatch = stopwatch_create();
|
|
|
|
|
|
|
|
xfp->hdc = gdi_GetDC();
|
|
|
|
|
|
|
|
xfp->hdc->hwnd = (HGDI_WND) malloc(sizeof(GDI_WND));
|
|
|
|
xfp->hdc->hwnd->invalid = gdi_CreateRectRgn(0, 0, 0, 0);
|
|
|
|
xfp->hdc->hwnd->invalid->null = 1;
|
|
|
|
|
|
|
|
xfp->hdc->hwnd->count = 32;
|
|
|
|
xfp->hdc->hwnd->cinvalid = (HGDI_RGN) malloc(sizeof(GDI_RGN) * xfp->hdc->hwnd->count);
|
|
|
|
xfp->hdc->hwnd->ninvalid = 0;
|
2012-01-08 06:57:42 +04:00
|
|
|
|
|
|
|
pthread_mutex_init(&(xfp->mutex), NULL);
|
2011-10-18 11:10:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
STREAM* xf_peer_stream_init(xfPeerContext* context)
|
2011-09-14 00:30:16 +04:00
|
|
|
{
|
2011-10-18 11:10:12 +04:00
|
|
|
stream_clear(context->s);
|
|
|
|
stream_set_pos(context->s, 0);
|
|
|
|
return context->s;
|
2011-09-14 00:30:16 +04:00
|
|
|
}
|
|
|
|
|
2012-01-08 06:36:12 +04:00
|
|
|
int xf_is_event_set(xfPeerContext* xfp)
|
|
|
|
{
|
|
|
|
fd_set rfds;
|
|
|
|
int num_set;
|
|
|
|
struct timeval time;
|
|
|
|
|
|
|
|
FD_ZERO(&rfds);
|
|
|
|
FD_SET(xfp->pipe_fd[0], &rfds);
|
|
|
|
memset(&time, 0, sizeof(time));
|
|
|
|
num_set = select(xfp->pipe_fd[0] + 1, &rfds, 0, 0, &time);
|
|
|
|
|
|
|
|
return (num_set == 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void xf_signal_event(xfPeerContext* xfp)
|
|
|
|
{
|
|
|
|
int length;
|
|
|
|
|
|
|
|
length = write(xfp->pipe_fd[1], "sig", 4);
|
|
|
|
|
|
|
|
if (length != 4)
|
|
|
|
printf("xf_signal_event: error\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void xf_clear_event(xfPeerContext* xfp)
|
|
|
|
{
|
|
|
|
int length;
|
|
|
|
|
|
|
|
while (xf_is_event_set(xfp))
|
|
|
|
{
|
|
|
|
length = read(xfp->pipe_fd[0], &length, 4);
|
|
|
|
|
|
|
|
if (length != 4)
|
|
|
|
printf("xf_clear_event: error\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void* xf_monitor_graphics(void* param)
|
2011-09-14 03:03:06 +04:00
|
|
|
{
|
|
|
|
xfInfo* xfi;
|
2012-01-03 08:13:54 +04:00
|
|
|
XEvent xevent;
|
2012-01-08 06:36:12 +04:00
|
|
|
uint32 sec, usec;
|
|
|
|
XRectangle region;
|
2011-10-18 11:10:12 +04:00
|
|
|
xfPeerContext* xfp;
|
2012-01-08 06:36:12 +04:00
|
|
|
freerdp_peer* client;
|
|
|
|
int x, y, width, height;
|
|
|
|
XDamageNotifyEvent* notify;
|
2011-09-14 03:03:06 +04:00
|
|
|
|
2012-01-08 06:36:12 +04:00
|
|
|
client = (freerdp_peer*) param;
|
2011-10-18 11:10:12 +04:00
|
|
|
xfp = (xfPeerContext*) client->context;
|
2012-01-08 06:36:12 +04:00
|
|
|
xfi = xfp->info;
|
2011-09-14 03:03:06 +04:00
|
|
|
|
2012-01-10 07:08:25 +04:00
|
|
|
xfp->capture_buffer = (uint8*) xmalloc(xfi->width * xfi->height * xfi->bytesPerPixel);
|
2012-01-08 06:36:12 +04:00
|
|
|
|
|
|
|
pthread_detach(pthread_self());
|
|
|
|
|
|
|
|
stopwatch_start(xfp->stopwatch);
|
2012-01-03 08:13:54 +04:00
|
|
|
|
2012-01-08 06:36:12 +04:00
|
|
|
while (1)
|
|
|
|
{
|
2012-01-08 06:57:42 +04:00
|
|
|
pthread_mutex_lock(&(xfp->mutex));
|
|
|
|
|
2012-01-08 06:36:12 +04:00
|
|
|
while (XPending(xfi->display))
|
2012-01-03 10:56:08 +04:00
|
|
|
{
|
2012-01-08 06:36:12 +04:00
|
|
|
memset(&xevent, 0, sizeof(xevent));
|
|
|
|
XNextEvent(xfi->display, &xevent);
|
|
|
|
|
|
|
|
if (xevent.type == xfi->xdamage_notify_event)
|
|
|
|
{
|
|
|
|
notify = (XDamageNotifyEvent*) &xevent;
|
|
|
|
|
|
|
|
x = notify->area.x;
|
|
|
|
y = notify->area.y;
|
|
|
|
width = notify->area.width;
|
|
|
|
height = notify->area.height;
|
|
|
|
|
|
|
|
region.x = x;
|
|
|
|
region.y = y;
|
|
|
|
region.width = width;
|
|
|
|
region.height = height;
|
2012-01-03 10:56:08 +04:00
|
|
|
|
|
|
|
#ifdef WITH_XFIXES
|
2012-01-08 06:36:12 +04:00
|
|
|
XFixesSetRegion(xfi->display, xfi->xdamage_region, ®ion, 1);
|
|
|
|
XDamageSubtract(xfi->display, xfi->xdamage, xfi->xdamage_region, None);
|
2012-01-03 08:13:54 +04:00
|
|
|
#endif
|
2012-01-08 06:36:12 +04:00
|
|
|
|
|
|
|
gdi_InvalidateRegion(xfp->hdc, x, y, width, height);
|
|
|
|
|
|
|
|
stopwatch_stop(xfp->stopwatch);
|
|
|
|
stopwatch_get_elapsed_time_in_useconds(xfp->stopwatch, &sec, &usec);
|
|
|
|
|
2012-01-09 06:22:50 +04:00
|
|
|
if ((sec > 0) || (usec > 30))
|
2012-01-08 06:36:12 +04:00
|
|
|
break;
|
|
|
|
}
|
2012-01-03 10:56:08 +04:00
|
|
|
}
|
2012-01-08 06:36:12 +04:00
|
|
|
|
|
|
|
stopwatch_stop(xfp->stopwatch);
|
|
|
|
stopwatch_get_elapsed_time_in_useconds(xfp->stopwatch, &sec, &usec);
|
|
|
|
|
2012-01-09 06:22:50 +04:00
|
|
|
if ((sec > 0) || (usec > 30))
|
2012-01-08 06:36:12 +04:00
|
|
|
{
|
|
|
|
HGDI_RGN region;
|
|
|
|
|
|
|
|
stopwatch_reset(xfp->stopwatch);
|
|
|
|
stopwatch_start(xfp->stopwatch);
|
|
|
|
|
|
|
|
region = xfp->hdc->hwnd->invalid;
|
2012-01-08 06:57:42 +04:00
|
|
|
pthread_mutex_unlock(&(xfp->mutex));
|
2012-01-08 06:36:12 +04:00
|
|
|
|
|
|
|
xf_signal_event(xfp);
|
|
|
|
}
|
2012-01-08 06:57:42 +04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
pthread_mutex_unlock(&(xfp->mutex));
|
|
|
|
}
|
2012-01-09 06:22:50 +04:00
|
|
|
|
|
|
|
freerdp_usleep(30);
|
2012-01-03 10:56:08 +04:00
|
|
|
}
|
2012-01-08 06:36:12 +04:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void xf_peer_live_rfx(freerdp_peer* client)
|
|
|
|
{
|
|
|
|
xfPeerContext* xfp = (xfPeerContext*) client->context;
|
|
|
|
|
|
|
|
if (xfp->activations == 1)
|
|
|
|
pthread_create(&(xfp->thread), 0, xf_monitor_graphics, (void*) client);
|
2011-09-14 03:03:06 +04:00
|
|
|
}
|
|
|
|
|
2011-10-20 16:25:25 +04:00
|
|
|
static boolean xf_peer_sleep_tsdiff(uint32 *old_sec, uint32 *old_usec, uint32 new_sec, uint32 new_usec)
|
|
|
|
{
|
|
|
|
sint32 sec, usec;
|
|
|
|
|
2011-11-08 02:20:00 +04:00
|
|
|
if (*old_sec == 0 && *old_usec == 0)
|
2011-10-20 16:25:25 +04:00
|
|
|
{
|
|
|
|
*old_sec = new_sec;
|
|
|
|
*old_usec = new_usec;
|
2011-11-19 21:19:16 +04:00
|
|
|
return true;
|
2011-10-20 16:25:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
sec = new_sec - *old_sec;
|
|
|
|
usec = new_usec - *old_usec;
|
|
|
|
|
2011-11-08 02:20:00 +04:00
|
|
|
if (sec < 0 || (sec == 0 && usec < 0))
|
2011-10-20 16:25:25 +04:00
|
|
|
{
|
|
|
|
printf("Invalid time stamp detected.\n");
|
2011-11-19 21:19:16 +04:00
|
|
|
return false;
|
2011-10-20 16:25:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
*old_sec = new_sec;
|
|
|
|
*old_usec = new_usec;
|
|
|
|
|
|
|
|
while (usec < 0)
|
|
|
|
{
|
|
|
|
usec += 1000000;
|
|
|
|
sec--;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sec > 0)
|
|
|
|
freerdp_sleep(sec);
|
|
|
|
|
|
|
|
if (usec > 0)
|
|
|
|
freerdp_usleep(usec);
|
|
|
|
|
2011-11-19 21:19:16 +04:00
|
|
|
return true;
|
2011-10-20 16:25:25 +04:00
|
|
|
}
|
|
|
|
|
2011-09-14 00:30:16 +04:00
|
|
|
void xf_peer_dump_rfx(freerdp_peer* client)
|
|
|
|
{
|
|
|
|
STREAM* s;
|
2011-10-20 16:25:25 +04:00
|
|
|
uint32 prev_seconds;
|
|
|
|
uint32 prev_useconds;
|
2011-09-14 00:30:16 +04:00
|
|
|
rdpUpdate* update;
|
|
|
|
rdpPcap* pcap_rfx;
|
|
|
|
pcap_record record;
|
|
|
|
|
|
|
|
s = stream_new(512);
|
|
|
|
update = client->update;
|
2011-11-19 21:19:16 +04:00
|
|
|
client->update->pcap_rfx = pcap_open(xf_pcap_file, false);
|
2011-09-14 00:30:16 +04:00
|
|
|
pcap_rfx = client->update->pcap_rfx;
|
|
|
|
|
2011-10-20 16:25:25 +04:00
|
|
|
if (pcap_rfx == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
prev_seconds = prev_useconds = 0;
|
2011-09-14 00:30:16 +04:00
|
|
|
|
|
|
|
while (pcap_has_next_record(pcap_rfx))
|
|
|
|
{
|
|
|
|
pcap_get_next_record_header(pcap_rfx, &record);
|
|
|
|
|
|
|
|
s->data = xrealloc(s->data, record.length);
|
|
|
|
record.data = s->data;
|
|
|
|
s->size = record.length;
|
|
|
|
|
|
|
|
pcap_get_next_record_content(pcap_rfx, &record);
|
|
|
|
s->p = s->data + s->size;
|
|
|
|
|
2011-11-19 21:19:16 +04:00
|
|
|
if (xf_pcap_dump_realtime && xf_peer_sleep_tsdiff(&prev_seconds, &prev_useconds, record.header.ts_sec, record.header.ts_usec) == false)
|
2011-10-20 16:25:25 +04:00
|
|
|
break;
|
2011-09-14 00:30:16 +04:00
|
|
|
|
2011-11-22 04:41:49 +04:00
|
|
|
update->SurfaceCommand(update->context, s);
|
2011-09-14 00:30:16 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-08 06:36:12 +04:00
|
|
|
void xf_peer_rfx_update(freerdp_peer* client, int x, int y, int width, int height)
|
|
|
|
{
|
|
|
|
STREAM* s;
|
|
|
|
xfInfo* xfi;
|
|
|
|
RFX_RECT rect;
|
|
|
|
XImage* image;
|
|
|
|
rdpUpdate* update;
|
|
|
|
xfPeerContext* xfp;
|
|
|
|
SURFACE_BITS_COMMAND* cmd;
|
|
|
|
|
|
|
|
update = client->update;
|
|
|
|
xfp = (xfPeerContext*) client->context;
|
|
|
|
cmd = &update->surface_bits_command;
|
|
|
|
xfi = xfp->info;
|
|
|
|
|
|
|
|
if (width * height <= 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
s = xf_peer_stream_init(xfp);
|
|
|
|
|
2012-01-08 06:57:42 +04:00
|
|
|
image = xf_snapshot(xfp, x, y, width, height);
|
2012-01-08 06:36:12 +04:00
|
|
|
|
2012-01-10 07:08:25 +04:00
|
|
|
if (xfi->use_xshm)
|
|
|
|
{
|
|
|
|
rect.x = 0;
|
|
|
|
rect.y = 0;
|
|
|
|
rect.width = width;
|
|
|
|
rect.height = height;
|
|
|
|
|
|
|
|
rfx_compose_message(xfp->rfx_context, s, &rect, 1,
|
|
|
|
(uint8*) image->data, width, height, image->bytes_per_line);
|
|
|
|
|
|
|
|
cmd->destLeft = x;
|
|
|
|
cmd->destTop = y;
|
|
|
|
cmd->destRight = x + width;
|
|
|
|
cmd->destBottom = y + height;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rect.x = 0;
|
|
|
|
rect.y = 0;
|
|
|
|
rect.width = width;
|
|
|
|
rect.height = height;
|
2012-01-08 06:36:12 +04:00
|
|
|
|
2012-01-10 07:08:25 +04:00
|
|
|
freerdp_image_convert((uint8*) image->data, xfp->capture_buffer,
|
|
|
|
width, height, 32, 24, xfi->clrconv);
|
2012-01-08 06:36:12 +04:00
|
|
|
|
2012-01-10 07:08:25 +04:00
|
|
|
rfx_compose_message(xfp->rfx_context, s, &rect, 1,
|
|
|
|
xfp->capture_buffer, width, height, width * xfi->bytesPerPixel);
|
|
|
|
|
|
|
|
cmd->destLeft = x;
|
|
|
|
cmd->destTop = y;
|
|
|
|
cmd->destRight = x + width;
|
|
|
|
cmd->destBottom = y + height;
|
|
|
|
}
|
2012-01-08 06:36:12 +04:00
|
|
|
|
|
|
|
cmd->bpp = 32;
|
|
|
|
cmd->codecID = client->settings->rfx_codec_id;
|
|
|
|
cmd->width = width;
|
|
|
|
cmd->height = height;
|
|
|
|
cmd->bitmapDataLength = stream_get_length(s);
|
|
|
|
cmd->bitmapData = stream_get_head(s);
|
|
|
|
|
|
|
|
update->SurfaceBits(update->context, cmd);
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean xf_peer_get_fds(freerdp_peer* client, void** rfds, int* rcount)
|
|
|
|
{
|
|
|
|
xfPeerContext* xfp = (xfPeerContext*) client->context;
|
|
|
|
|
|
|
|
if (xfp->pipe_fd[0] == -1)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
rfds[*rcount] = (void *)(long) xfp->pipe_fd[0];
|
|
|
|
(*rcount)++;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean xf_peer_check_fds(freerdp_peer* client)
|
|
|
|
{
|
|
|
|
xfInfo* xfi;
|
|
|
|
xfPeerContext* xfp;
|
|
|
|
|
|
|
|
xfp = (xfPeerContext*) client->context;
|
|
|
|
xfi = xfp->info;
|
|
|
|
|
|
|
|
if (xfp->pipe_fd[0] == -1)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (xfp->activated == false)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (xf_is_event_set(xfp))
|
|
|
|
{
|
|
|
|
HGDI_RGN region;
|
|
|
|
|
|
|
|
xf_clear_event(xfp);
|
|
|
|
|
|
|
|
region = xfp->hdc->hwnd->invalid;
|
|
|
|
|
|
|
|
if (region->null)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
xf_peer_rfx_update(client, region->x, region->y, region->w, region->h);
|
|
|
|
region->null = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-12-15 00:08:09 +04:00
|
|
|
boolean xf_peer_capabilities(freerdp_peer* client)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-09-14 00:30:16 +04:00
|
|
|
boolean xf_peer_post_connect(freerdp_peer* client)
|
|
|
|
{
|
2011-11-08 02:20:00 +04:00
|
|
|
xfInfo* xfi;
|
|
|
|
xfPeerContext* xfp;
|
|
|
|
|
|
|
|
xfp = (xfPeerContext*) client->context;
|
|
|
|
xfi = (xfInfo*) xfp->info;
|
|
|
|
|
2011-09-14 00:30:16 +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.
|
|
|
|
*/
|
2011-10-18 11:10:12 +04:00
|
|
|
printf("Client %s is activated", client->hostname);
|
2011-09-14 00:30:16 +04:00
|
|
|
if (client->settings->autologon)
|
|
|
|
{
|
|
|
|
printf(" and wants to login automatically as %s\\%s",
|
|
|
|
client->settings->domain ? client->settings->domain : "",
|
|
|
|
client->settings->username);
|
|
|
|
|
|
|
|
/* A real server may perform OS login here if NLA is not executed previously. */
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
printf("Client requested desktop: %dx%dx%d\n",
|
|
|
|
client->settings->width, client->settings->height, client->settings->color_depth);
|
|
|
|
|
|
|
|
/* A real server should tag the peer as activated here and start sending updates in mainloop. */
|
|
|
|
|
2011-11-08 02:20:00 +04:00
|
|
|
client->settings->width = xfi->width;
|
|
|
|
client->settings->height = xfi->height;
|
2012-01-03 08:13:54 +04:00
|
|
|
|
2011-11-22 04:41:49 +04:00
|
|
|
client->update->DesktopResize(client->update->context);
|
2011-11-19 21:19:16 +04:00
|
|
|
xfp->activated = false;
|
2011-11-08 02:20:00 +04:00
|
|
|
|
2011-11-19 21:19:16 +04:00
|
|
|
/* Return false here would stop the execution of the peer mainloop. */
|
|
|
|
return true;
|
2011-09-14 00:30:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
boolean xf_peer_activate(freerdp_peer* client)
|
|
|
|
{
|
2011-10-18 11:10:12 +04:00
|
|
|
xfPeerContext* xfp = (xfPeerContext*) client->context;
|
2011-09-14 00:30:16 +04:00
|
|
|
|
2011-10-18 11:10:12 +04:00
|
|
|
rfx_context_reset(xfp->rfx_context);
|
2011-11-19 21:19:16 +04:00
|
|
|
xfp->activated = true;
|
2011-09-14 00:30:16 +04:00
|
|
|
|
|
|
|
if (xf_pcap_file != NULL)
|
|
|
|
{
|
2011-11-19 21:19:16 +04:00
|
|
|
client->update->dump_rfx = true;
|
2011-09-14 00:30:16 +04:00
|
|
|
xf_peer_dump_rfx(client);
|
|
|
|
}
|
2011-09-14 03:03:06 +04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
xf_peer_live_rfx(client);
|
2012-01-08 06:36:12 +04:00
|
|
|
xfp->activations++;
|
2011-09-14 03:03:06 +04:00
|
|
|
}
|
2011-09-14 00:30:16 +04:00
|
|
|
|
2011-11-19 21:19:16 +04:00
|
|
|
return true;
|
2011-09-14 00:30:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void xf_peer_synchronize_event(rdpInput* input, uint32 flags)
|
|
|
|
{
|
|
|
|
printf("Client sent a synchronize event (flags:0x%X)\n", flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
void xf_peer_keyboard_event(rdpInput* input, uint16 flags, uint16 code)
|
|
|
|
{
|
2012-01-09 05:32:50 +04:00
|
|
|
unsigned int keycode;
|
|
|
|
boolean extended = false;
|
2011-10-18 11:10:12 +04:00
|
|
|
xfPeerContext* xfp = (xfPeerContext*) input->context;
|
2012-01-09 05:32:50 +04:00
|
|
|
xfInfo* xfi = xfp->info;
|
2011-09-14 00:30:16 +04:00
|
|
|
|
2012-01-09 05:32:50 +04:00
|
|
|
if (flags & KBD_FLAGS_EXTENDED)
|
|
|
|
extended = true;
|
|
|
|
|
|
|
|
keycode = freerdp_kbd_get_keycode_by_scancode(code, extended);
|
|
|
|
|
|
|
|
if (keycode != 0)
|
2011-09-14 00:30:16 +04:00
|
|
|
{
|
2012-01-09 05:32:50 +04:00
|
|
|
#ifdef WITH_XTEST
|
|
|
|
pthread_mutex_lock(&(xfp->mutex));
|
|
|
|
|
|
|
|
if (flags & KBD_FLAGS_DOWN)
|
|
|
|
XTestFakeKeyEvent(xfi->display, keycode, True, 0);
|
|
|
|
else if (flags & KBD_FLAGS_RELEASE)
|
|
|
|
XTestFakeKeyEvent(xfi->display, keycode, False, 0);
|
|
|
|
|
|
|
|
pthread_mutex_unlock(&(xfp->mutex));
|
|
|
|
#endif
|
2011-09-14 00:30:16 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void xf_peer_unicode_keyboard_event(rdpInput* input, uint16 code)
|
|
|
|
{
|
|
|
|
printf("Client sent a unicode keyboard event (code:0x%X)\n", code);
|
|
|
|
}
|
|
|
|
|
|
|
|
void xf_peer_mouse_event(rdpInput* input, uint16 flags, uint16 x, uint16 y)
|
|
|
|
{
|
2012-01-08 06:57:42 +04:00
|
|
|
int button = 0;
|
|
|
|
boolean down = false;
|
|
|
|
xfPeerContext* xfp = (xfPeerContext*) input->context;
|
|
|
|
xfInfo* xfi = xfp->info;
|
|
|
|
|
|
|
|
pthread_mutex_lock(&(xfp->mutex));
|
2012-01-08 06:36:12 +04:00
|
|
|
#ifdef WITH_XTEST
|
2012-01-08 06:57:42 +04:00
|
|
|
|
2012-01-09 06:22:50 +04:00
|
|
|
if (flags & PTR_FLAGS_WHEEL)
|
|
|
|
{
|
|
|
|
boolean negative = false;
|
|
|
|
|
|
|
|
if (flags & PTR_FLAGS_WHEEL_NEGATIVE)
|
|
|
|
negative = true;
|
2012-01-08 06:57:42 +04:00
|
|
|
|
2012-01-09 06:22:50 +04:00
|
|
|
button = (negative) ? 5 : 4;
|
2012-01-08 06:57:42 +04:00
|
|
|
|
2012-01-09 06:22:50 +04:00
|
|
|
XTestFakeButtonEvent(xfi->display, button, True, 0);
|
|
|
|
XTestFakeButtonEvent(xfi->display, button, False, 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (flags & PTR_FLAGS_MOVE)
|
|
|
|
XTestFakeMotionEvent(xfi->display, 0, x, y, 0);
|
|
|
|
|
|
|
|
if (flags & PTR_FLAGS_BUTTON1)
|
|
|
|
button = 1;
|
|
|
|
else if (flags & PTR_FLAGS_BUTTON2)
|
|
|
|
button = 3;
|
|
|
|
else if (flags & PTR_FLAGS_BUTTON3)
|
|
|
|
button = 2;
|
2012-01-08 06:57:42 +04:00
|
|
|
|
2012-01-09 06:22:50 +04:00
|
|
|
if (flags & PTR_FLAGS_DOWN)
|
|
|
|
down = true;
|
|
|
|
|
|
|
|
if (button != 0)
|
|
|
|
XTestFakeButtonEvent(xfi->display, button, down, 0);
|
|
|
|
}
|
2012-01-08 06:36:12 +04:00
|
|
|
#endif
|
2012-01-08 06:57:42 +04:00
|
|
|
pthread_mutex_unlock(&(xfp->mutex));
|
2011-09-14 00:30:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void xf_peer_extended_mouse_event(rdpInput* input, uint16 flags, uint16 x, uint16 y)
|
|
|
|
{
|
2012-01-08 06:57:42 +04:00
|
|
|
xfPeerContext* xfp = (xfPeerContext*) input->context;
|
|
|
|
xfInfo* xfi = xfp->info;
|
|
|
|
|
|
|
|
pthread_mutex_lock(&(xfp->mutex));
|
2012-01-08 06:36:12 +04:00
|
|
|
#ifdef WITH_XTEST
|
2012-01-08 06:57:42 +04:00
|
|
|
XTestFakeMotionEvent(xfi->display, 0, x, y, CurrentTime);
|
2012-01-08 06:36:12 +04:00
|
|
|
#endif
|
2012-01-08 06:57:42 +04:00
|
|
|
pthread_mutex_unlock(&(xfp->mutex));
|
2011-09-14 00:30:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void* xf_peer_main_loop(void* arg)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int fds;
|
|
|
|
int max_fds;
|
|
|
|
int rcount;
|
|
|
|
void* rfds[32];
|
|
|
|
fd_set rfds_set;
|
2012-01-31 05:35:33 +04:00
|
|
|
rdpSettings* settings;
|
|
|
|
char* server_file_path;
|
2011-09-14 00:30:16 +04:00
|
|
|
freerdp_peer* client = (freerdp_peer*) arg;
|
|
|
|
|
|
|
|
memset(rfds, 0, sizeof(rfds));
|
|
|
|
|
2011-10-18 11:10:12 +04:00
|
|
|
printf("We've got a client %s\n", client->hostname);
|
|
|
|
|
|
|
|
xf_peer_init(client);
|
2012-01-31 05:35:33 +04:00
|
|
|
settings = client->settings;
|
2011-09-14 00:30:16 +04:00
|
|
|
|
|
|
|
/* Initialize the real server settings here */
|
2012-01-31 05:35:33 +04:00
|
|
|
|
|
|
|
if (settings->development_mode)
|
|
|
|
{
|
|
|
|
server_file_path = freerdp_construct_path(settings->development_path, "server/X11");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
server_file_path = freerdp_construct_path(settings->config_path, "server");
|
|
|
|
|
|
|
|
if (!freerdp_check_file_exists(server_file_path))
|
|
|
|
freerdp_mkdir(server_file_path);
|
|
|
|
}
|
|
|
|
|
|
|
|
settings->cert_file = freerdp_construct_path(server_file_path, "server.crt");
|
|
|
|
settings->privatekey_file = freerdp_construct_path(server_file_path, "server.key");
|
|
|
|
|
|
|
|
settings->nla_security = false;
|
|
|
|
settings->rfx_codec = true;
|
2011-09-14 00:30:16 +04:00
|
|
|
|
2011-12-15 00:08:09 +04:00
|
|
|
client->Capabilities = xf_peer_capabilities;
|
2011-09-14 00:30:16 +04:00
|
|
|
client->PostConnect = xf_peer_post_connect;
|
|
|
|
client->Activate = xf_peer_activate;
|
|
|
|
|
|
|
|
client->input->SynchronizeEvent = xf_peer_synchronize_event;
|
|
|
|
client->input->KeyboardEvent = xf_peer_keyboard_event;
|
|
|
|
client->input->UnicodeKeyboardEvent = xf_peer_unicode_keyboard_event;
|
|
|
|
client->input->MouseEvent = xf_peer_mouse_event;
|
|
|
|
client->input->ExtendedMouseEvent = xf_peer_extended_mouse_event;
|
|
|
|
|
|
|
|
client->Initialize(client);
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
rcount = 0;
|
|
|
|
|
2011-11-19 21:19:16 +04:00
|
|
|
if (client->GetFileDescriptor(client, rfds, &rcount) != true)
|
2011-09-14 00:30:16 +04:00
|
|
|
{
|
|
|
|
printf("Failed to get FreeRDP file descriptor\n");
|
|
|
|
break;
|
|
|
|
}
|
2012-01-08 06:36:12 +04:00
|
|
|
if (xf_peer_get_fds(client, rfds, &rcount) != true)
|
|
|
|
{
|
|
|
|
printf("Failed to get xfreerdp file descriptor\n");
|
|
|
|
break;
|
|
|
|
}
|
2011-09-14 00:30:16 +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)
|
|
|
|
{
|
|
|
|
/* these are not really errors */
|
|
|
|
if (!((errno == EAGAIN) ||
|
|
|
|
(errno == EWOULDBLOCK) ||
|
|
|
|
(errno == EINPROGRESS) ||
|
|
|
|
(errno == EINTR))) /* signal occurred */
|
|
|
|
{
|
|
|
|
printf("select failed\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-19 21:19:16 +04:00
|
|
|
if (client->CheckFileDescriptor(client) != true)
|
2012-01-08 06:36:12 +04:00
|
|
|
{
|
|
|
|
printf("Failed to check freerdp file descriptor\n");
|
2011-09-14 00:30:16 +04:00
|
|
|
break;
|
2012-01-08 06:36:12 +04:00
|
|
|
}
|
|
|
|
if ((xf_peer_check_fds(client)) != true)
|
|
|
|
{
|
|
|
|
printf("Failed to check xfreerdp file descriptor\n");
|
|
|
|
break;
|
|
|
|
}
|
2011-09-14 00:30:16 +04:00
|
|
|
}
|
|
|
|
|
2011-10-18 11:10:12 +04:00
|
|
|
printf("Client %s disconnected.\n", client->hostname);
|
2011-09-14 00:30:16 +04:00
|
|
|
|
|
|
|
client->Disconnect(client);
|
2011-10-18 11:10:12 +04:00
|
|
|
freerdp_peer_context_free(client);
|
2011-09-14 00:30:16 +04:00
|
|
|
freerdp_peer_free(client);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void xf_peer_accepted(freerdp_listener* instance, freerdp_peer* client)
|
|
|
|
{
|
|
|
|
pthread_t th;
|
2011-09-14 03:03:06 +04:00
|
|
|
|
2011-09-14 00:30:16 +04:00
|
|
|
pthread_create(&th, 0, xf_peer_main_loop, client);
|
|
|
|
pthread_detach(th);
|
|
|
|
}
|