freerdp-shadow: start new cross-platform shadowing server

This commit is contained in:
Marc-André Moreau 2014-07-10 15:46:34 -04:00
parent 2e1f6b0c6d
commit 0196a02354
24 changed files with 11 additions and 1979 deletions

View File

@ -1,8 +1,8 @@
/**
* FreeRDP: A Remote Desktop Protocol Implementation
* X11 Server Graphical Updates
* Session Shadowing
*
* Copyright 2013 Marc-Andre Moreau <marcandre.moreau@gmail.com>
* Copyright 2014 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.
@ -17,12 +17,13 @@
* limitations under the License.
*/
#ifndef __XF_UPDATE_H
#define __XF_UPDATE_H
#ifndef FREERDP_SERVER_SHADOW_H
#define FREERDP_SERVER_SHADOW_H
#include "xfreerdp.h"
#include <freerdp/api.h>
#include <freerdp/types.h>
void* xf_update_thread(void* param);
#endif /* __XF_UPDATE_H */
#endif /* FREERDP_SERVER_SHADOW_H */

1
server/.gitignore vendored
View File

@ -4,4 +4,5 @@
!/Sample
!/Windows
!/X11
!/Shadow
!/CmakeLists.txt

View File

@ -18,6 +18,7 @@
# Servers
add_subdirectory(common)
add_subdirectory(shadow)
if(FREERDP_VENDOR)
if(WITH_SAMPLE)
@ -25,10 +26,6 @@ if(FREERDP_VENDOR)
endif()
if(NOT WIN32)
if(WITH_X11)
add_subdirectory(X11)
endif()
if(APPLE AND (NOT IOS))
add_subdirectory(Mac)
endif()
@ -62,3 +59,4 @@ endforeach()
foreach(FREERDP_SERVER ${FREERDP_EXTRA_SERVERS})
add_subdirectory(${FREERDP_SERVER})
endforeach()

View File

@ -1,167 +0,0 @@
# FreeRDP: A Remote Desktop Protocol Implementation
# FreeRDP X11 Server cmake build script
#
# Copyright 2012 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.
set(MODULE_NAME "xfreerdp-server")
set(MODULE_PREFIX "FREERDP_SERVER_X11_CONTROL")
include_directories(${X11_INCLUDE_DIRS})
include_directories("../../winpr/tools/makecert")
set(${MODULE_PREFIX}_SRCS
xf_peer.c
xf_peer.h
xf_input.c
xf_input.h
xf_encode.c
xf_encode.h
xf_update.c
xf_update.h
xf_cursor.c
xf_cursor.h
xf_monitors.c
xf_monitors.h
xf_interface.c
xf_interface.h
xfreerdp.h)
if(WITH_SERVER_INTERFACE)
if(SERVER_INTERFACE_SHARED)
add_library(${MODULE_NAME} SHARED ${${MODULE_PREFIX}_SRCS})
else()
add_library(${MODULE_NAME} ${${MODULE_PREFIX}_SRCS})
endif()
set_target_properties(${MODULE_NAME} PROPERTIES VERSION ${FREERDP_VERSION} SOVERSION ${FREERDP_API_VERSION} PREFIX "lib")
else()
set(${MODULE_PREFIX}_SRCS ${${MODULE_PREFIX}_SRCS} cli/xfreerdp.c)
add_executable(${MODULE_NAME} ${${MODULE_PREFIX}_SRCS})
set_target_properties(${MODULE_NAME} PROPERTIES OUTPUT_NAME "xfreerdp-server")
endif()
set(XEXT_FEATURE_TYPE "RECOMMENDED")
set(XEXT_FEATURE_PURPOSE "X11 extension")
set(XEXT_FEATURE_DESCRIPTION "X11 core extensions")
set(XSHM_FEATURE_TYPE "RECOMMENDED")
set(XSHM_FEATURE_PURPOSE "X11 shared memory")
set(XSHM_FEATURE_DESCRIPTION "X11 shared memory extension")
set(XINERAMA_FEATURE_TYPE "RECOMMENDED")
set(XINERAMA_FEATURE_PURPOSE "multi-monitor")
set(XINERAMA_FEATURE_DESCRIPTION "X11 multi-monitor extension")
set(XTEST_FEATURE_TYPE "RECOMMENDED")
set(XTEST_FEATURE_PURPOSE "X11 input event injection")
set(XTEST_FEATURE_DESCRIPTION "X11 input event injection extension")
set(XCURSOR_FEATURE_TYPE "RECOMMENDED")
set(XCURSOR_FEATURE_PURPOSE "cursor")
set(XCURSOR_FEATURE_DESCRIPTION "X11 cursor extension")
set(XFIXES_FEATURE_TYPE "RECOMMENDED")
set(XFIXES_FEATURE_PURPOSE "X11 region")
set(XFIXES_FEATURE_DESCRIPTION "X11 region fix extension")
set(XRANDR_FEATURE_TYPE "RECOMMENDED")
set(XRANDR_FEATURE_PURPOSE "X11 resize, rotate and reflect")
set(XRANDR_FEATURE_DESCRIPTION "X11 resize, rotate and reflect extension")
set(XDAMAGE_FEATURE_TYPE "RECOMMENDED")
set(XDAMAGE_FEATURE_PURPOSE "X11 region damage")
set(XDAMAGE_FEATURE_DESCRIPTION "X11 region damage extension")
find_feature(Xext ${XEXT_FEATURE_TYPE} ${XEXT_FEATURE_PURPOSE} ${XEXT_FEATURE_DESCRIPTION})
find_feature(XShm ${XSHM_FEATURE_TYPE} ${XSHM_FEATURE_PURPOSE} ${XSHM_FEATURE_DESCRIPTION})
find_feature(XTest ${XTEST_FEATURE_TYPE} ${XTEST_FEATURE_PURPOSE} ${XTEST_FEATURE_DESCRIPTION})
find_feature(Xfixes ${XFIXES_FEATURE_TYPE} ${XFIXES_FEATURE_PURPOSE} ${XFIXES_FEATURE_DESCRIPTION})
find_feature(XRandR ${XRANDR_FEATURE_TYPE} ${XRANDR_FEATURE_PURPOSE} ${XRANDR_FEATURE_DESCRIPTION})
find_feature(Xdamage ${XDAMAGE_FEATURE_TYPE} ${XDAMAGE_FEATURE_PURPOSE} ${XDAMAGE_FEATURE_DESCRIPTION})
find_feature(Xcursor ${XCURSOR_FEATURE_TYPE} ${XCURSOR_FEATURE_PURPOSE} ${XCURSOR_FEATURE_DESCRIPTION})
find_feature(Xinerama ${XINERAMA_FEATURE_TYPE} ${XINERAMA_FEATURE_PURPOSE} ${XINERAMA_FEATURE_DESCRIPTION})
if(WITH_XSHM)
add_definitions(-DWITH_XSHM)
include_directories(${XSHM_INCLUDE_DIRS})
endif()
if(WITH_XEXT)
add_definitions(-DWITH_XEXT)
include_directories(${XEXT_INCLUDE_DIRS})
set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} ${XEXT_LIBRARIES})
endif()
if(WITH_XINERAMA)
add_definitions(-DWITH_XINERAMA)
include_directories(${XINERAMA_INCLUDE_DIRS})
set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} ${XINERAMA_LIBRARIES})
endif()
if(WITH_XCURSOR)
add_definitions(-DWITH_XCURSOR)
include_directories(${XCURSOR_INCLUDE_DIRS})
set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} ${XCURSOR_LIBRARIES})
endif()
if(WITH_XDAMAGE)
add_definitions(-DWITH_XDAMAGE)
include_directories(${XDAMAGE_INCLUDE_DIRS})
set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} ${XDAMAGE_LIBRARIES})
endif()
if(WITH_XFIXES)
add_definitions(-DWITH_XFIXES)
include_directories(${XFIXES_INCLUDE_DIRS})
target_link_libraries(${MODULE_NAME} ${XFIXES_LIBRARIES})
set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} ${XFIXES_LIBRARIES})
endif()
if(WITH_XTEST)
add_definitions(-DWITH_XTEST)
include_directories(${XTEST_INCLUDE_DIRS})
set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} ${XTEST_LIBRARIES})
endif()
if(WITH_XRANDR)
add_definitions(-DWITH_XRANDR)
include_directories(${XRANDR_INCLUDE_DIRS})
set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} ${XRANDR_LIBRARIES})
endif()
set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} ${X11_LIBRARIES})
set_complex_link_libraries(VARIABLE ${MODULE_PREFIX}_LIBS
MONOLITHIC ${MONOLITHIC_BUILD}
MODULE freerdp
MODULES freerdp-core freerdp-common freerdp-codec freerdp-primitives freerdp-utils freerdp-gdi freerdp-crypto freerdp-locale)
set_complex_link_libraries(VARIABLE ${MODULE_PREFIX}_LIBS
MONOLITHIC ${MONOLITHIC_BUILD}
MODULE winpr
MODULES winpr-sspi winpr-crt winpr-utils winpr-input winpr-sysinfo)
set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} winpr-makecert-tool)
target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS})
if(WITH_SERVER_INTERFACE)
install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libraries)
add_subdirectory(cli)
else()
install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT server)
endif()
set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Server/X11")

View File

@ -1,4 +0,0 @@
set(FREERDP_SERVER_NAME "xfreerdp-server")
set(FREERDP_SERVER_PLATFORM "X11")
set(FREERDP_SERVER_VENDOR "FreeRDP")

View File

@ -1,36 +0,0 @@
# FreeRDP: A Remote Desktop Protocol Implementation
# FreeRDP X11 cmake build script
#
# Copyright 2012 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.
set(MODULE_NAME "xfreerdp-server-cli")
set(MODULE_PREFIX "FREERDP_SERVER_X11")
include_directories(..)
set(${MODULE_PREFIX}_SRCS
xfreerdp.c)
add_executable(${MODULE_NAME} ${${MODULE_PREFIX}_SRCS})
set_target_properties(${MODULE_NAME} PROPERTIES OUTPUT_NAME "xfreerdp-server" RUNTIME_OUTPUT_DIRECTORY "..")
set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} xfreerdp-server)
target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS})
install(TARGETS ${MODULE_NAME} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT server)
set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Server/X11")

View File

@ -1,52 +0,0 @@
/**
* FreeRDP: A Remote Desktop Protocol Implementation
* FreeRDP X11 Server
*
* 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.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "xf_interface.h"
int main(int argc, char* argv[])
{
HANDLE thread;
xfServer* server;
DWORD dwExitCode;
freerdp_server_global_init();
server = freerdp_server_new(argc, argv);
if (!server)
return 0;
freerdp_server_start(server);
thread = freerdp_server_get_thread(server);
WaitForSingleObject(thread, INFINITE);
GetExitCodeThread(thread, &dwExitCode);
freerdp_server_free(server);
freerdp_server_global_uninit();
return 0;
}

Binary file not shown.

View File

@ -1,17 +0,0 @@
-----BEGIN CERTIFICATE-----
MIICyzCCAbOgAwIBAgIJANbqtAWwlQZuMA0GCSqGSIb3DQEBBQUAMBIxEDAOBgNV
BAMTB0ZyZWVSRFAwHhcNMDkxMDI5MDA0MTQ5WhcNMDkxMTI4MDA0MTQ5WjASMRAw
DgYDVQQDEwdGcmVlUkRQMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA
q7mxFgRbS2FYJZX7BzpNd4T/n4nEVDBY6YaObLjGpaB1TptzXTcmfDrDslTGwcEY
hTFAC4ZvY6yOURExqbph4LSgvkoa6J722RjVPfshGa4mlh2SXvTiaV26VPPxddGb
o6fbs2u029lbtBlpIVbhx5RN9vstNkll26oSZ6wfEdBNHQJLd2SU4ItWHj8zjz1f
eGxjgChHihUlwcBYKDJsKFkzHZmLrMgB37KsGlXi/WV+eEsjgvz4yP7I3TL8+GsN
MjV8fRGVEKTbKSmgunO67d5u+IaqUQb0Ad1ha1jzDQ+a6hdymrulJSIhoOVfKkwi
ptTe43FgwxVRIygJP9HjHQIDAQABoyQwIjATBgNVHSUEDDAKBggrBgEFBQcDATAL
BgNVHQ8EBAMCBDAwDQYJKoZIhvcNAQEFBQADggEBAIOdEDhOX2kbl02znltd9hCr
nV4kRPKm979RKwBNkrEuwYSlcsjAHg5MZ5itH3wFOUo2s5pjt7/vMOAg+6rOBbIa
nqr22/gKBtOmuaJLG1yjxDC2vfez7f3B26pKgxa/krM8oxiFdT9n8QbdxdkN7/D9
3RLU/aCfgrMzXxRus7eq3kR00jnSs6ggnAfE1E9gric3vFgr1wCzdcriRXmXDfUb
hRq+4VG+ZWk16TwCofV5GVU39XWCv5HNO2swAdjkNXgI5e3tQbV3wWLZLqqYzBco
iWulAXtoCGmE81+u1Ms7hLLzpXitLZSGPu1r+sDdkKPLCmOvkAaljDQ4nBz7fIA=
-----END CERTIFICATE-----

View File

@ -1,27 +0,0 @@
-----BEGIN RSA PRIVATE KEY-----
MIIEogIBAAKCAQEAq7mxFgRbS2FYJZX7BzpNd4T/n4nEVDBY6YaObLjGpaB1Tptz
XTcmfDrDslTGwcEYhTFAC4ZvY6yOURExqbph4LSgvkoa6J722RjVPfshGa4mlh2S
XvTiaV26VPPxddGbo6fbs2u029lbtBlpIVbhx5RN9vstNkll26oSZ6wfEdBNHQJL
d2SU4ItWHj8zjz1feGxjgChHihUlwcBYKDJsKFkzHZmLrMgB37KsGlXi/WV+eEsj
gvz4yP7I3TL8+GsNMjV8fRGVEKTbKSmgunO67d5u+IaqUQb0Ad1ha1jzDQ+a6hdy
mrulJSIhoOVfKkwiptTe43FgwxVRIygJP9HjHQIDAQABAoIBAAVv5K54xtc1JtBR
1lfdPbSqDlnjx8aOnVIPg5TnqMp3sR8jBt0NsPc/+RA9ZOmfjoIxFAEJaZ9zSDJC
5BqmnxC5R1mfCQkSd2haQ+4pdFvWyrv4Bblh8YU6hXrJGn0LfO0KlIcywtAvKpsi
LtTyZkWmaW2HeF/+pO32jYygw38R1wd8Tl6GwjOXwTF6lFACJXOT4YAzcfp3FKSB
AiKBIGuMzozoSND7KPFNRrhGhNumJpdS5A8Fb8D2c/ZMv6Cq5IbwOgTfKun+Bz+s
mFbnzeb1uWRqQbsVXOBBW/zHfuG3SU5qeZsaAyuu4DTy+LE1oAHF9uhBSHuT5C6i
vCJ8A8ECgYEA1iaOmiEJYBrs25iAc4SjCKqhY0mwR3wtu3I06vmgUoML5fhPMv36
SvYQIqDyNw3p7TE6mZtw9+G+kK3PqhuJhogwSwg0a6o51RdKnhXH3/68oNWtKCLC
1AmR8q/Gd3FwAR3b49CuOIZ9uOiJrc/ejzKdFEJTDR1/TX1frWfZznECgYEAzUiz
XxFf7YrGel7JgmfRD2eZRYngOoteFlg5Tee42UjeAY2Pt2aiDLk+2TqQEdI9+Xg7
LcFdBqcSNd8bh33xSzgNthIkX+lTDzx0SmKGfyxfFBJcY8nzsLvvnNt3YeuMeaJQ
CPszwoZ0jcD46jTCjbrKhaLyEWmUkDp1O71NTW0CgYAXKF49Xpsz8FVyvcAOPeaf
dkwzf3F3mX8ciRId4taqdY9g1AREgGCDoK5IAF2RBIkqZCtxFvUVaS0BWjpdq9Ko
YKvQQVfh2KueVoF0LOjLWTGutsydzXyCD3Lf6pAstHCnPkJcFWHxrOGFkGfrCtKH
a7K+0RlIDsuIZqllCBjukQKBgA31+MTpYJW+D1t5IMkumEgs6n6RLt+sZLyuSU9k
B+03CGogn3qAj1rAKmcJlYywuKhDpfqpoNL3/8QMJUokpYlRCZWtTC39pzltCheY
9b6mXNz3lrLupBUL4vLO9iKBq28GO90wgEelbz3ItuTuq6CJ6IYIG+BVRtY8M4bZ
i+1NAoGANXZjYnJYDnh8Je9SDxDSc5byzK7ddkQoId64RCIfNHqNKH63P81vjgnH
YBIPtagY75ZVVNxujCF7m8Rety+d8tEFwfQKDin2EVI7PD2rOJra385/izp7HuBR
vqxvLzG9Xv3cNOU2l7PttVw4Pa2i5E37atKi3V3Zp2kMW+KaKPQ=
-----END RSA PRIVATE KEY-----

View File

@ -1,57 +0,0 @@
/**
* FreeRDP: A Remote Desktop Protocol Implementation
* X11 Server Cursor
*
* Copyright 2013 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.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#ifdef WITH_XCURSOR
#include <X11/Xcursor/Xcursor.h>
#endif
#ifdef WITH_XFIXES
#include <X11/extensions/Xfixes.h>
#endif
#include <winpr/crt.h>
#include "xf_cursor.h"
int xf_cursor_init(xfInfo* xfi)
{
#ifdef WITH_XFIXES
int event;
int error;
if (!XFixesQueryExtension(xfi->display, &event, &error))
{
fprintf(stderr, "XFixesQueryExtension failed\n");
return -1;
}
xfi->xfixes_notify_event = event + XFixesCursorNotify;
XFixesSelectCursorInput(xfi->display, DefaultRootWindow(xfi->display), XFixesDisplayCursorNotifyMask);
#endif
return 0;
}

View File

@ -1,27 +0,0 @@
/**
* FreeRDP: A Remote Desktop Protocol Implementation
* X11 Server Cursor
*
* Copyright 2013 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.
*/
#ifndef XFREERDP_SERVER_CURSOR_H
#define XFREERDP_SERVER_CURSOR_H
#include "xfreerdp.h"
int xf_cursor_init(xfInfo* xfi);
#endif /* XFREERDP_SERVER_CURSOR_H */

View File

@ -1,149 +0,0 @@
/**
* FreeRDP: A Remote Desktop Protocol Implementation
* X11 RemoteFX Encoder
*
* 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.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <sys/select.h>
#include <sys/signal.h>
#include <winpr/crt.h>
#include "xf_encode.h"
XImage* xf_snapshot(xfPeerContext* xfp, int x, int y, int width, int height)
{
XImage* image;
xfInfo* xfi = xfp->info;
if (xfi->use_xshm)
{
XCopyArea(xfi->display, xfi->root_window, xfi->fb_pixmap, xfi->xdamage_gc, x, y, width, height, x, y);
image = xfi->fb_image;
}
else
{
image = XGetImage(xfi->display, xfi->root_window, x, y, width, height, AllPlanes, ZPixmap);
}
return image;
}
void xf_xdamage_subtract_region(xfPeerContext* xfp, int x, int y, int width, int height)
{
XRectangle region;
xfInfo* xfi = xfp->info;
region.x = x;
region.y = y;
region.width = width;
region.height = height;
#ifdef WITH_XFIXES
XFixesSetRegion(xfi->display, xfi->xdamage_region, &region, 1);
XDamageSubtract(xfi->display, xfi->xdamage, xfi->xdamage_region, None);
#endif
}
int xf_update_encode(freerdp_peer* client, int x, int y, int width, int height)
{
wStream* s;
BYTE* data;
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)
{
cmd->bitmapDataLength = 0;
return -1;
}
s = xfp->s;
Stream_Clear(s);
Stream_SetPosition(s, 0);
if (xfi->use_xshm)
{
/**
* Passing an offset source rectangle to rfx_compose_message()
* leads to protocol errors, so offset the data pointer instead.
*/
rect.x = 0;
rect.y = 0;
rect.width = width;
rect.height = height;
image = xf_snapshot(xfp, x, y, width, height);
data = (BYTE*) image->data;
data = &data[(y * image->bytes_per_line) + (x * image->bits_per_pixel / 8)];
rfx_compose_message(xfp->rfx_context, s, &rect, 1, 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;
image = xf_snapshot(xfp, x, y, width, height);
data = (BYTE*) image->data;
rfx_compose_message(xfp->rfx_context, s, &rect, 1, data,
width, height, image->bytes_per_line);
cmd->destLeft = x;
cmd->destTop = y;
cmd->destRight = x + width;
cmd->destBottom = y + height;
XDestroyImage(image);
}
cmd->bpp = 32;
cmd->codecID = client->settings->RemoteFxCodecId;
cmd->width = width;
cmd->height = height;
cmd->bitmapDataLength = Stream_GetPosition(s);
cmd->bitmapData = Stream_Buffer(s);
return 0;
}

View File

@ -1,31 +0,0 @@
/**
* FreeRDP: A Remote Desktop Protocol Implementation
* X11 RemoteFX Encoder
*
* 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.
*/
#ifndef __XF_ENCODE_H
#define __XF_ENCODE_H
#include "xfreerdp.h"
#include "xf_peer.h"
XImage* xf_snapshot(xfPeerContext* xfp, int x, int y, int width, int height);
void xf_xdamage_subtract_region(xfPeerContext* xfp, int x, int y, int width, int height);
int xf_update_encode(freerdp_peer* client, int x, int y, int width, int height);
#endif /* __XF_ENCODE_H */

View File

@ -1,155 +0,0 @@
/**
* FreeRDP: A Remote Desktop Protocol Implementation
* X11 Server Input
*
* 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.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <X11/Xlib.h>
#include <freerdp/locale/keyboard.h>
#include <winpr/crt.h>
#include <winpr/input.h>
#include "xf_peer.h"
#include "xf_input.h"
void xf_input_synchronize_event(rdpInput* input, UINT32 flags)
{
fprintf(stderr, "Client sent a synchronize event (flags:0x%X)\n", flags);
}
void xf_input_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
{
#ifdef WITH_XTEST
DWORD vkcode;
DWORD keycode;
BOOL extended = FALSE;
xfPeerContext* xfp = (xfPeerContext*) input->context;
xfInfo* xfi = xfp->info;
if (flags & KBD_FLAGS_EXTENDED)
extended = TRUE;
if (extended)
code |= KBDEXT;
vkcode = GetVirtualKeyCodeFromVirtualScanCode(code, 4);
keycode = GetKeycodeFromVirtualKeyCode(vkcode, KEYCODE_TYPE_EVDEV);
if (keycode != 0)
{
XTestGrabControl(xfi->display, True);
if (flags & KBD_FLAGS_DOWN)
XTestFakeKeyEvent(xfi->display, keycode, True, 0);
else if (flags & KBD_FLAGS_RELEASE)
XTestFakeKeyEvent(xfi->display, keycode, False, 0);
XTestGrabControl(xfi->display, False);
}
#endif
}
void xf_input_unicode_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
{
fprintf(stderr, "Client sent a unicode keyboard event (flags:0x%X code:0x%X)\n", flags, code);
}
void xf_input_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
{
#ifdef WITH_XTEST
xfPeerContext* xfp = (xfPeerContext*) input->context;
int button = 0;
BOOL down = FALSE;
xfInfo* xfi = xfp->info;
XTestGrabControl(xfi->display, True);
if (flags & PTR_FLAGS_WHEEL)
{
BOOL negative = FALSE;
if (flags & PTR_FLAGS_WHEEL_NEGATIVE)
negative = TRUE;
button = (negative) ? 5 : 4;
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;
if (flags & PTR_FLAGS_DOWN)
down = TRUE;
if (button != 0)
XTestFakeButtonEvent(xfi->display, button, down, 0);
}
XTestGrabControl(xfi->display, False);
#endif
}
void xf_input_extended_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
{
#ifdef WITH_XTEST
xfPeerContext* xfp = (xfPeerContext*) input->context;
int button = 0;
BOOL down = FALSE;
xfInfo* xfi = xfp->info;
XTestGrabControl(xfi->display, True);
XTestFakeMotionEvent(xfi->display, 0, x, y, CurrentTime);
if (flags & PTR_XFLAGS_BUTTON1)
button = 8;
else if (flags & PTR_XFLAGS_BUTTON2)
button = 9;
if (flags & PTR_XFLAGS_DOWN)
down = TRUE;
if (button != 0)
XTestFakeButtonEvent(xfi->display, button, down, 0);
XTestGrabControl(xfi->display, False);
#endif
}
void xf_input_register_callbacks(rdpInput* input)
{
input->SynchronizeEvent = xf_input_synchronize_event;
input->KeyboardEvent = xf_input_keyboard_event;
input->UnicodeKeyboardEvent = xf_input_unicode_keyboard_event;
input->MouseEvent = xf_input_mouse_event;
input->ExtendedMouseEvent = xf_input_extended_mouse_event;
}

View File

@ -1,34 +0,0 @@
/**
* FreeRDP: A Remote Desktop Protocol Implementation
* X11 Server Input
*
* 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.
*/
#ifndef __XF_INPUT_H
#define __XF_INPUT_H
#include <pthread.h>
#include "xfreerdp.h"
void xf_input_synchronize_event(rdpInput* input, UINT32 flags);
void xf_input_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code);
void xf_input_unicode_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code);
void xf_input_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y);
void xf_input_extended_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y);
void xf_input_register_callbacks(rdpInput* input);
#endif /* __XF_INPUT_H */

View File

@ -1,173 +0,0 @@
/**
* FreeRDP: A Remote Desktop Protocol Implementation
* FreeRDP X11 Server Interface
*
* Copyright 2013 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 <assert.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <sys/select.h>
#include <sys/signal.h>
#include "xf_peer.h"
#include "xfreerdp.h"
#include "xf_interface.h"
void* xf_server_thread(void* param)
{
int i;
int fds;
int max_fds;
int rcount;
void* rfds[32];
fd_set rfds_set;
xfServer* server;
freerdp_listener* listener;
server = (xfServer*) param;
listener = server->listener;
while (1)
{
rcount = 0;
ZeroMemory(rfds, sizeof(rfds));
if (listener->GetFileDescriptor(listener, rfds, &rcount) != TRUE)
{
fprintf(stderr, "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 */
{
fprintf(stderr, "select failed\n");
break;
}
}
if (listener->CheckFileDescriptor(listener) != TRUE)
{
fprintf(stderr, "Failed to check FreeRDP file descriptor\n");
break;
}
}
ExitThread(0);
return NULL;
}
int freerdp_server_global_init()
{
/*
* ignore SIGPIPE, otherwise an SSL_write failure could crash the server
*/
signal(SIGPIPE, SIG_IGN);
return 0;
}
int freerdp_server_global_uninit()
{
return 0;
}
int freerdp_server_start(xfServer* server)
{
assert(NULL != server);
server->thread = NULL;
if (server->listener->Open(server->listener, NULL, 3389))
{
server->thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)
xf_server_thread, (void*) server, 0, NULL);
}
return 0;
}
int freerdp_server_stop(xfServer* server)
{
if (server->thread)
{
/* ATTENTION: Terminate thread kills a thread, assure
* no resources are allocated during thread execution,
* as they will not be freed! */
TerminateThread(server->thread, 0);
WaitForSingleObject(server->thread, INFINITE);
CloseHandle(server->thread);
server->listener->Close(server->listener);
}
return 0;
}
HANDLE freerdp_server_get_thread(xfServer* server)
{
return server->thread;
}
xfServer* freerdp_server_new(int argc, char** argv)
{
xfServer* server;
server = (xfServer*) malloc(sizeof(xfServer));
if (server)
{
server->listener = freerdp_listener_new();
server->listener->PeerAccepted = xf_peer_accepted;
}
return server;
}
void freerdp_server_free(xfServer* server)
{
if (server)
{
freerdp_listener_free(server->listener);
free(server);
}
}

View File

@ -1,54 +0,0 @@
/**
* FreeRDP: A Remote Desktop Protocol Implementation
* FreeRDP X11 Server Interface
*
* Copyright 2013 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.
*/
#ifndef XFREERDP_SERVER_INTERFACE_H
#define XFREERDP_SERVER_INTERFACE_H
#include <winpr/crt.h>
#include <freerdp/api.h>
#include <freerdp/freerdp.h>
typedef struct xf_info xfInfo;
typedef struct xf_server xfServer;
#ifdef __cplusplus
extern "C" {
#endif
/**
* Server Interface
*/
FREERDP_API int freerdp_server_global_init();
FREERDP_API int freerdp_server_global_uninit();
FREERDP_API int freerdp_server_start(xfServer* server);
FREERDP_API int freerdp_server_stop(xfServer* server);
FREERDP_API HANDLE freerdp_server_get_thread(xfServer* server);
FREERDP_API xfServer* freerdp_server_new(int argc, char** argv);
FREERDP_API void freerdp_server_free(xfServer* server);
#ifdef __cplusplus
}
#endif
#endif /* XFREERDP_SERVER_INTERFACE_H */

View File

@ -1,68 +0,0 @@
/**
* FreeRDP: A Remote Desktop Protocol Implementation
* X11 Server Monitors
*
* Copyright 2013 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.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <winpr/crt.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#ifdef WITH_XINERAMA
#include <X11/extensions/Xinerama.h>
#endif
#include "xf_monitors.h"
int xf_list_monitors(xfInfo* xfi)
{
#ifdef WITH_XINERAMAZ
int i, nmonitors = 0;
int ignored, ignored2;
XineramaScreenInfo* screen = NULL;
if (XineramaQueryExtension(xfi->display, &ignored, &ignored2))
{
if (XineramaIsActive(xfi->display))
{
screen = XineramaQueryScreens(xfi->display, &nmonitors);
for (i = 0; i < nmonitors; i++)
{
printf(" %s [%d] %dx%d\t+%d+%d\n",
(i == 0) ? "*" : " ", i,
screen[i].width, screen[i].height,
screen[i].x_org, screen[i].y_org);
}
XFree(screen);
}
}
#else
Screen* screen;
screen = ScreenOfDisplay(xfi->display, DefaultScreen(xfi->display));
printf(" * [0] %dx%d\t+%d+%d\n", WidthOfScreen(screen), HeightOfScreen(screen), 0, 0);
#endif
return 0;
}

View File

@ -1,28 +0,0 @@
/**
* FreeRDP: A Remote Desktop Protocol Implementation
* X11 Server Monitors
*
* Copyright 2013 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.
*/
#ifndef XFREERDP_SERVER_MONITORS_H
#define XFREERDP_SERVER_MONITORS_H
#include "xfreerdp.h"
int xf_list_monitors(xfInfo* xfi);
#endif /* XFREERDP_SERVER_MONITORS_H */

View File

@ -1,634 +0,0 @@
/**
* FreeRDP: A Remote Desktop Protocol Implementation
* 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.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <assert.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <sys/select.h>
#include <winpr/crt.h>
#include <winpr/file.h>
#include <winpr/path.h>
#include <winpr/synch.h>
#include <winpr/thread.h>
#include <freerdp/freerdp.h>
#include <freerdp/codec/color.h>
#include <freerdp/locale/keyboard.h>
#include "xf_input.h"
#include "xf_cursor.h"
#include "xf_encode.h"
#include "xf_update.h"
#include "xf_monitors.h"
#include <winpr/tools/makecert.h>
#include "xf_peer.h"
#ifdef WITH_XDAMAGE
void xf_xdamage_init(xfInfo* xfi)
{
int damage_event;
int damage_error;
int major, minor;
XGCValues values;
if (XDamageQueryExtension(xfi->display, &damage_event, &damage_error) == 0)
{
fprintf(stderr, "XDamageQueryExtension failed\n");
return;
}
XDamageQueryVersion(xfi->display, &major, &minor);
if (XDamageQueryVersion(xfi->display, &major, &minor) == 0)
{
fprintf(stderr, "XDamageQueryVersion failed\n");
return;
}
else if (major < 1)
{
fprintf(stderr, "XDamageQueryVersion failed: major:%d minor:%d\n", major, minor);
return;
}
xfi->xdamage_notify_event = damage_event + XDamageNotify;
xfi->xdamage = XDamageCreate(xfi->display, xfi->root_window, XDamageReportDeltaRectangles);
if (xfi->xdamage == None)
{
fprintf(stderr, "XDamageCreate failed\n");
return;
}
#ifdef WITH_XFIXES
xfi->xdamage_region = XFixesCreateRegion(xfi->display, NULL, 0);
if (xfi->xdamage_region == None)
{
fprintf(stderr, "XFixesCreateRegion failed\n");
XDamageDestroy(xfi->display, xfi->xdamage);
xfi->xdamage = None;
return;
}
#endif
values.subwindow_mode = IncludeInferiors;
xfi->xdamage_gc = XCreateGC(xfi->display, xfi->root_window, GCSubwindowMode, &values);
XSetFunction(xfi->display, xfi->xdamage_gc, GXcopy);
}
#endif
int xf_xshm_init(xfInfo* xfi)
{
Bool pixmaps;
int major, minor;
if (XShmQueryExtension(xfi->display) != False)
{
XShmQueryVersion(xfi->display, &major, &minor, &pixmaps);
if (pixmaps != True)
{
fprintf(stderr, "XShmQueryVersion failed\n");
return -1;
}
}
else
{
fprintf(stderr, "XShmQueryExtension failed\n");
return -1;
}
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)
{
fprintf(stderr, "XShmCreateImage failed\n");
return -1;
}
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)
{
fprintf(stderr, "shmget failed\n");
return -1;
}
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))
{
fprintf(stderr, "shmat failed\n");
return -1;
}
XShmAttach(xfi->display, &(xfi->fb_shm_info));
XSync(xfi->display, False);
shmctl(xfi->fb_shm_info.shmid, IPC_RMID, 0);
fprintf(stderr, "display: %p root_window: %p width: %d height: %d depth: %d\n",
xfi->display, (void*) xfi->root_window, xfi->fb_image->width, xfi->fb_image->height, xfi->fb_image->depth);
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);
return 0;
}
void xf_info_free(xfInfo *info)
{
assert(NULL != info);
if (info->display)
XCloseDisplay(info->display);
freerdp_clrconv_free(info->clrconv);
free(info);
}
xfInfo* xf_info_init()
{
int i;
xfInfo* xfi;
int pf_count;
int vi_count;
XVisualInfo* vi;
XVisualInfo* vis;
XVisualInfo template;
XPixmapFormatValues* pf;
XPixmapFormatValues* pfs;
xfi = (xfInfo*) malloc(sizeof(xfInfo));
ZeroMemory(xfi, sizeof(xfInfo));
/**
* Recent X11 servers drop support for shared pixmaps
* To see if your X11 server supports shared pixmaps, use:
* xdpyinfo -ext MIT-SHM | grep "shared pixmaps"
*/
xfi->use_xshm = TRUE;
setenv("DISPLAY", ":0", 1); /* Set DISPLAY variable if not already set */
if (!XInitThreads())
fprintf(stderr, "warning: XInitThreads() failure\n");
xfi->display = XOpenDisplay(NULL);
if (!xfi->display)
{
fprintf(stderr, "failed to open display: %s\n", XDisplayName(NULL));
exit(1);
}
xf_list_monitors(xfi);
xfi->xfds = ConnectionNumber(xfi->display);
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);
xfi->root_window = DefaultRootWindow(xfi->display);
pfs = XListPixmapFormats(xfi->display, &pf_count);
if (!pfs)
{
fprintf(stderr, "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);
ZeroMemory(&template, sizeof(template));
template.class = TrueColor;
template.screen = xfi->number;
vis = XGetVisualInfo(xfi->display, VisualClassMask | VisualScreenMask, &template, &vi_count);
if (!vis)
{
fprintf(stderr, "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);
xfi->clrconv = freerdp_clrconv_new(CLRCONV_ALPHA | CLRCONV_INVERT);
XSelectInput(xfi->display, xfi->root_window, SubstructureNotifyMask);
if (xfi->use_xshm)
{
if (xf_xshm_init(xfi) < 0)
xfi->use_xshm = FALSE;
}
if (xfi->use_xshm)
printf("Using X Shared Memory Extension (XShm)\n");
#ifdef WITH_XDAMAGE
xf_xdamage_init(xfi);
#endif
xf_cursor_init(xfi);
xfi->bytesPerPixel = 4;
xfi->activePeerCount = 0;
freerdp_keyboard_init(0);
return xfi;
}
void xf_peer_context_new(freerdp_peer* client, xfPeerContext* context)
{
context->info = xf_info_init();
context->rfx_context = rfx_context_new(TRUE);
context->rfx_context->mode = RLGR3;
context->rfx_context->width = context->info->width;
context->rfx_context->height = context->info->height;
rfx_context_set_pixel_format(context->rfx_context, RDP_PIXEL_FORMAT_B8G8R8A8);
context->s = Stream_New(NULL, 65536);
Stream_Clear(context->s);
context->updateReadyEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
context->updateSentEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
}
void xf_peer_context_free(freerdp_peer* client, xfPeerContext* context)
{
if (context)
{
xf_info_free(context->info);
CloseHandle(context->updateReadyEvent);
CloseHandle(context->updateSentEvent);
Stream_Free(context->s, TRUE);
rfx_context_free(context->rfx_context);
}
}
void xf_peer_init(freerdp_peer* client)
{
xfInfo* xfi;
xfPeerContext* xfp;
client->ContextSize = sizeof(xfPeerContext);
client->ContextNew = (psPeerContextNew) xf_peer_context_new;
client->ContextFree = (psPeerContextFree) xf_peer_context_free;
freerdp_peer_context_new(client);
xfp = (xfPeerContext*) client->context;
xfp->fps = 16;
xfi = xfp->info;
xfp->mutex = CreateMutex(NULL, FALSE, NULL);
}
void xf_peer_send_update(freerdp_peer* client)
{
rdpUpdate* update;
SURFACE_BITS_COMMAND* cmd;
update = client->update;
cmd = &update->surface_bits_command;
if (cmd->bitmapDataLength)
update->SurfaceBits(update->context, cmd);
}
BOOL xf_peer_get_fds(freerdp_peer* client, void** rfds, int* rcount)
{
int fds;
HANDLE event;
xfPeerContext* xfp = (xfPeerContext*) client->context;
event = xfp->updateReadyEvent;
fds = GetEventFileDescriptor(event);
rfds[*rcount] = (void*) (long) fds;
(*rcount)++;
return TRUE;
}
BOOL xf_peer_check_fds(freerdp_peer* client)
{
xfInfo* xfi;
xfPeerContext* xfp;
xfp = (xfPeerContext*) client->context;
xfi = xfp->info;
if (WaitForSingleObject(xfp->updateReadyEvent, 0) == WAIT_OBJECT_0)
{
if (!xfp->activated)
return TRUE;
xf_peer_send_update(client);
ResetEvent(xfp->updateReadyEvent);
SetEvent(xfp->updateSentEvent);
}
return TRUE;
}
BOOL xf_peer_capabilities(freerdp_peer* client)
{
return TRUE;
}
BOOL xf_peer_post_connect(freerdp_peer* client)
{
xfInfo* xfi;
xfPeerContext* xfp;
xfp = (xfPeerContext*) client->context;
xfi = (xfInfo*) xfp->info;
/**
* 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.
*/
fprintf(stderr, "Client %s is activated", client->hostname);
if (client->settings->AutoLogonEnabled)
{
fprintf(stderr, " 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. */
}
fprintf(stderr, "\n");
fprintf(stderr, "Client requested desktop: %dx%dx%d\n",
client->settings->DesktopWidth, client->settings->DesktopHeight, client->settings->ColorDepth);
if (!client->settings->RemoteFxCodec)
{
fprintf(stderr, "Client does not support RemoteFX\n");
return FALSE;
}
/* A real server should tag the peer as activated here and start sending updates in main loop. */
client->settings->DesktopWidth = xfi->width;
client->settings->DesktopHeight = xfi->height;
client->update->DesktopResize(client->update->context);
/* Return FALSE here would stop the execution of the peer main loop. */
return TRUE;
}
BOOL xf_peer_activate(freerdp_peer* client)
{
xfPeerContext* xfp = (xfPeerContext*) client->context;
rfx_context_reset(xfp->rfx_context);
xfp->activated = TRUE;
xfp->info->activePeerCount++;
xfp->monitorThread = CreateThread(NULL, 0,
(LPTHREAD_START_ROUTINE) xf_update_thread, (void*) client, 0, NULL);
return TRUE;
}
const char* makecert_argv[4] =
{
"makecert",
"-rdp",
"-live",
"-silent"
};
int makecert_argc = (sizeof(makecert_argv) / sizeof(char*));
int xf_generate_certificate(rdpSettings* settings)
{
char* server_file_path;
MAKECERT_CONTEXT* context;
server_file_path = GetCombinedPath(settings->ConfigPath, "server");
if (!PathFileExistsA(server_file_path))
CreateDirectoryA(server_file_path, 0);
settings->CertificateFile = GetCombinedPath(server_file_path, "server.crt");
settings->PrivateKeyFile = GetCombinedPath(server_file_path, "server.key");
if ((!PathFileExistsA(settings->CertificateFile)) ||
(!PathFileExistsA(settings->PrivateKeyFile)))
{
context = makecert_context_new();
makecert_context_process(context, makecert_argc, (char**) makecert_argv);
makecert_context_set_output_file_name(context, "server");
if (!PathFileExistsA(settings->CertificateFile))
makecert_context_output_certificate_file(context, server_file_path);
if (!PathFileExistsA(settings->PrivateKeyFile))
makecert_context_output_private_key_file(context, server_file_path);
makecert_context_free(context);
}
free(server_file_path);
return 0;
}
static void* xf_peer_main_loop(void* arg)
{
int i;
int fds;
int max_fds;
int rcount;
void* rfds[32];
fd_set rfds_set;
rdpSettings* settings;
xfPeerContext* xfp;
struct timeval timeout;
freerdp_peer* client = (freerdp_peer*) arg;
assert(NULL != client);
ZeroMemory(rfds, sizeof(rfds));
ZeroMemory(&timeout, sizeof(struct timeval));
fprintf(stderr, "We've got a client %s\n", client->hostname);
xf_peer_init(client);
xfp = (xfPeerContext*) client->context;
settings = client->settings;
xf_generate_certificate(settings);
settings->RemoteFxCodec = TRUE;
settings->ColorDepth = 32;
settings->NlaSecurity = FALSE;
settings->TlsSecurity = TRUE;
settings->RdpSecurity = FALSE;
client->Capabilities = xf_peer_capabilities;
client->PostConnect = xf_peer_post_connect;
client->Activate = xf_peer_activate;
xf_input_register_callbacks(client->input);
client->Initialize(client);
while (1)
{
rcount = 0;
if (client->GetFileDescriptor(client, rfds, &rcount) != TRUE)
{
fprintf(stderr, "Failed to get FreeRDP file descriptor\n");
break;
}
if (xf_peer_get_fds(client, rfds, &rcount) != TRUE)
{
fprintf(stderr, "Failed to get xfreerdp 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;
timeout.tv_sec = 0;
timeout.tv_usec = 100;
if (select(max_fds + 1, &rfds_set, NULL, NULL, &timeout) == -1)
{
/* these are not really errors */
if (!((errno == EAGAIN) ||
(errno == EWOULDBLOCK) ||
(errno == EINPROGRESS) ||
(errno == EINTR))) /* signal occurred */
{
fprintf(stderr, "select failed\n");
break;
}
}
if (client->CheckFileDescriptor(client) != TRUE)
{
fprintf(stderr, "Failed to check freerdp file descriptor\n");
break;
}
if ((xf_peer_check_fds(client)) != TRUE)
{
fprintf(stderr, "Failed to check xfreerdp file descriptor\n");
break;
}
}
fprintf(stderr, "Client %s disconnected.\n", client->hostname);
client->Disconnect(client);
freerdp_peer_context_free(client);
freerdp_peer_free(client);
ExitThread(0);
return NULL;
}
void xf_peer_accepted(freerdp_listener* instance, freerdp_peer* client)
{
HANDLE thread;
thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) xf_peer_main_loop, client, 0, NULL);
}

View File

@ -1,63 +0,0 @@
/**
* FreeRDP: A Remote Desktop Protocol Implementation
* 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.
*/
#ifndef __XF_PEER_H
#define __XF_PEER_H
#include <winpr/crt.h>
#include <winpr/synch.h>
#include <winpr/thread.h>
#include <winpr/stream.h>
#include <winpr/collections.h>
#include <freerdp/gdi/gdi.h>
#include <freerdp/gdi/dc.h>
#include <freerdp/gdi/region.h>
#include <freerdp/codec/rfx.h>
#include <freerdp/listener.h>
#include <freerdp/utils/stopwatch.h>
typedef struct xf_peer_context xfPeerContext;
#include "xfreerdp.h"
#define PeerEvent_Base 0
#define PeerEvent_Class (PeerEvent_Base + 1)
#define PeerEvent_EncodeRegion 1
struct xf_peer_context
{
rdpContext _p;
int fps;
wStream* s;
xfInfo* info;
HANDLE mutex;
BOOL activated;
HANDLE monitorThread;
HANDLE updateReadyEvent;
HANDLE updateSentEvent;
RFX_CONTEXT* rfx_context;
};
void xf_peer_accepted(freerdp_listener* instance, freerdp_peer* client);
#endif /* __XF_PEER_H */

View File

@ -1,100 +0,0 @@
/**
* FreeRDP: A Remote Desktop Protocol Implementation
* X11 Server Graphical Updates
*
* Copyright 2013 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.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <X11/Xlib.h>
#include <winpr/crt.h>
#include <winpr/synch.h>
#include <winpr/sysinfo.h>
#include "xf_peer.h"
#include "xf_encode.h"
#include "xf_update.h"
void* xf_update_thread(void* param)
{
xfInfo* xfi;
HANDLE event;
XEvent xevent;
DWORD beg, end;
DWORD diff, rate;
xfPeerContext* xfp;
freerdp_peer* client;
int x, y, width, height;
XDamageNotifyEvent* notify;
client = (freerdp_peer*) param;
xfp = (xfPeerContext*) client->context;
xfi = xfp->info;
rate = 1000 / xfp->fps;
event = CreateFileDescriptorEvent(NULL, FALSE, FALSE, xfi->xfds);
while (WaitForSingleObject(event, INFINITE) == WAIT_OBJECT_0)
{
beg = GetTickCount();
while (XPending(xfi->display) > 0)
{
ZeroMemory(&xevent, 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;
if (xf_update_encode(client, x, y, width, height) >= 0)
{
xf_xdamage_subtract_region(xfp, x, y, width, height);
SetEvent(xfp->updateReadyEvent);
WaitForSingleObject(xfp->updateSentEvent, INFINITE);
ResetEvent(xfp->updateSentEvent);
}
}
#ifdef WITH_XFIXES
else if (xevent.type == xfi->xfixes_notify_event)
{
XFixesCursorImage* ci = XFixesGetCursorImage(xfi->display);
XFree(ci);
}
#endif
}
end = GetTickCount();
diff = end - beg;
if (diff < rate)
Sleep(rate - diff);
}
return NULL;
}

View File

@ -1,92 +0,0 @@
/**
* FreeRDP: A Remote Desktop Protocol Implementation
* FreeRDP X11 Server
*
* 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.
*/
#ifndef __XFREERDP_H
#define __XFREERDP_H
#include "xf_interface.h"
#include <freerdp/api.h>
#include <freerdp/freerdp.h>
#include <freerdp/listener.h>
#include <freerdp/codec/color.h>
#include <X11/Xlib.h>
#ifdef WITH_XSHM
#include <X11/extensions/XShm.h>
#endif
#ifdef WITH_XFIXES
#include <X11/extensions/Xfixes.h>
#endif
#ifdef WITH_XTEST
#include <X11/extensions/XTest.h>
#endif
#ifdef WITH_XDAMAGE
#include <X11/extensions/Xdamage.h>
#endif
struct xf_info
{
int bpp;
int xfds;
int depth;
int width;
int height;
int number;
XImage* image;
Screen* screen;
Visual* visual;
Display* display;
int scanline_pad;
int bytesPerPixel;
HCLRCONV clrconv;
BOOL use_xshm;
int activePeerCount;
XImage* fb_image;
Pixmap fb_pixmap;
Window root_window;
XShmSegmentInfo fb_shm_info;
#ifdef WITH_XDAMAGE
GC xdamage_gc;
Damage xdamage;
int xdamage_notify_event;
XserverRegion xdamage_region;
#endif
#ifdef WITH_XFIXES
int xfixes_notify_event;
#endif
};
struct xf_server
{
DWORD port;
HANDLE thread;
freerdp_listener* listener;
};
void* xf_server_thread(void* param);
#endif /* __XFREERDP_H */