Merge pull request #719 from FreeRDP/cleanup

Code Cleanup
This commit is contained in:
Marc-André Moreau 2012-09-10 16:20:26 -07:00
commit 9f18c634da
24 changed files with 377 additions and 1647 deletions

View File

@ -87,7 +87,7 @@ void tsmf_playback_ack(IWTSVirtualChannelCallback* pChannelCallback,
stream_write_uint64(s, duration); /* DataDuration */
stream_write_uint64(s, data_size); /* cbData */
DEBUG_DVC("response size %d", stream_get_length(s));
DEBUG_DVC("response size %d", (int) stream_get_length(s));
error = callback->channel->Write(callback->channel, stream_get_length(s), stream_get_head(s), NULL);
if (error)
{

View File

@ -24,28 +24,37 @@ option(WITH_SERVER "Build server binaries" OFF)
option(WITH_CHANNELS "Build virtual channel plugins" ON)
option(WITH_THIRD_PARTY "Build third-party components" OFF)
option(WITH_DEBUG_CERTIFICATE "Print certificate related debug messages." OFF)
option(WITH_DEBUG_CHANNELS "Print channel manager debug messages." OFF)
option(WITH_DEBUG_CLIPRDR "Print clipboard redirection debug messages" OFF)
option(WITH_DEBUG_DVC "Print dynamic virtual channel debug messages." OFF)
option(WITH_DEBUG_GDI "Print graphics debug messages." OFF)
option(WITH_DEBUG_KBD "Print keyboard related debug messages." OFF)
option(WITH_DEBUG_LICENSE "Print license debug messages." OFF)
option(WITH_DEBUG_NEGO "Print negotiation related debug messages." OFF)
option(WITH_DEBUG_NLA "Print authentication related debug messages." OFF)
option(WITH_DEBUG_NTLM "Print NTLM debug messages" OFF)
option(WITH_DEBUG_TSG "Print Terminal Server Gateway debug messages" OFF)
option(WITH_DEBUG_ORDERS "Print drawing orders debug messages" OFF)
option(WITH_DEBUG_RAIL "Print RemoteApp debug messages" OFF)
option(WITH_DEBUG_RDP "Print RDP debug messages" OFF)
option(WITH_DEBUG_REDIR "Redirection debug messages" OFF)
option(WITH_DEBUG_RFX "Print RemoteFX debug messages." OFF)
option(WITH_DEBUG_SCARD "Print smartcard debug messages" OFF)
option(WITH_DEBUG_SVC "Print static virtual channel debug messages." OFF)
option(WITH_DEBUG_TRANSPORT "Print transport debug messages." OFF)
option(WITH_DEBUG_WND "Print window order debug messages" OFF)
option(WITH_DEBUG_X11_CLIPRDR "Print X11 clipboard redirection debug messages" OFF)
option(WITH_DEBUG_X11_LOCAL_MOVESIZE "Print X11 Client local movesize debug messages" OFF)
option(WITH_DEBUG_X11 "Print X11 Client debug messages" OFF)
option(WITH_DEBUG_XV "Print XVideo debug messages" OFF)
option(WITH_DEBUG_ALL "Print all debug messages." OFF)
if(WITH_DEBUG_ALL)
set(DEFAULT_DEBUG_OPTION "ON")
else()
set(DEFAULT_DEBUG_OPTION "OFF")
endif()
option(WITH_DEBUG_CERTIFICATE "Print certificate related debug messages." ${DEFAULT_DEBUG_OPTION})
option(WITH_DEBUG_CHANNELS "Print channel manager debug messages." ${DEFAULT_DEBUG_OPTION})
option(WITH_DEBUG_CLIPRDR "Print clipboard redirection debug messages" ${DEFAULT_DEBUG_OPTION})
option(WITH_DEBUG_DVC "Print dynamic virtual channel debug messages." ${DEFAULT_DEBUG_OPTION})
option(WITH_DEBUG_GDI "Print graphics debug messages." ${DEFAULT_DEBUG_OPTION})
option(WITH_DEBUG_KBD "Print keyboard related debug messages." ${DEFAULT_DEBUG_OPTION})
option(WITH_DEBUG_LICENSE "Print license debug messages." ${DEFAULT_DEBUG_OPTION})
option(WITH_DEBUG_NEGO "Print negotiation related debug messages." ${DEFAULT_DEBUG_OPTION})
option(WITH_DEBUG_NLA "Print authentication related debug messages." ${DEFAULT_DEBUG_OPTION})
option(WITH_DEBUG_NTLM "Print NTLM debug messages" ${DEFAULT_DEBUG_OPTION})
option(WITH_DEBUG_TSG "Print Terminal Server Gateway debug messages" ${DEFAULT_DEBUG_OPTION})
option(WITH_DEBUG_ORDERS "Print drawing orders debug messages" ${DEFAULT_DEBUG_OPTION})
option(WITH_DEBUG_RAIL "Print RemoteApp debug messages" ${DEFAULT_DEBUG_OPTION})
option(WITH_DEBUG_RDP "Print RDP debug messages" ${DEFAULT_DEBUG_OPTION})
option(WITH_DEBUG_REDIR "Redirection debug messages" ${DEFAULT_DEBUG_OPTION})
option(WITH_DEBUG_RFX "Print RemoteFX debug messages." ${DEFAULT_DEBUG_OPTION})
option(WITH_DEBUG_SCARD "Print smartcard debug messages" ${DEFAULT_DEBUG_OPTION})
option(WITH_DEBUG_SVC "Print static virtual channel debug messages." ${DEFAULT_DEBUG_OPTION})
option(WITH_DEBUG_TRANSPORT "Print transport debug messages." ${DEFAULT_DEBUG_OPTION})
option(WITH_DEBUG_TIMEZONE "Print timezone debug messages." ${DEFAULT_DEBUG_OPTION})
option(WITH_DEBUG_WND "Print window order debug messages" ${DEFAULT_DEBUG_OPTION})
option(WITH_DEBUG_X11_CLIPRDR "Print X11 clipboard redirection debug messages" ${DEFAULT_DEBUG_OPTION})
option(WITH_DEBUG_X11_LOCAL_MOVESIZE "Print X11 Client local movesize debug messages" ${DEFAULT_DEBUG_OPTION})
option(WITH_DEBUG_X11 "Print X11 Client debug messages" ${DEFAULT_DEBUG_OPTION})
option(WITH_DEBUG_XV "Print XVideo debug messages" ${DEFAULT_DEBUG_OPTION})

View File

@ -104,7 +104,6 @@ if(WITH_MONOLITHIC_BUILD)
else()
set(FREERDP_CORE_LIBS
winpr-utils
winpr-rpc
winpr-sspi)
if(NOT WIN32)

View File

@ -243,13 +243,13 @@ void rdp_read_bitmap_capability_set(STREAM* s, uint16 length, rdpSettings* setti
void rdp_write_bitmap_capability_set(STREAM* s, rdpSettings* settings)
{
uint8* header;
uint8 drawingFlags;
uint8 drawingFlags = 0;
uint16 desktopResizeFlag;
uint16 preferredBitsPerPixel;
header = rdp_capability_set_start(s);
drawingFlags = 0;
drawingFlags |= DRAW_ALLOW_SKIP_ALPHA;
if (settings->rdp_version > 5)
preferredBitsPerPixel = settings->color_depth;

View File

@ -78,13 +78,10 @@ boolean rdp_client_connect(rdpRdp* rdp)
nego_set_preconnection_blob(rdp->nego, settings->preconnection_blob);
nego_set_negotiation_enabled(rdp->nego, settings->security_layer_negotiation);
nego_enable_rdp(rdp->nego, settings->rdp_security);
if (!settings->ts_gateway)
{
nego_enable_nla(rdp->nego, settings->nla_security);
nego_enable_rdp(rdp->nego, settings->rdp_security);
nego_enable_tls(rdp->nego, settings->tls_security);
}
nego_enable_nla(rdp->nego, settings->nla_security);
if (!nego_connect(rdp->nego))
{

View File

@ -21,6 +21,8 @@
#include "config.h"
#endif
#include <winpr/crt.h>
#include <freerdp/utils/memory.h>
#include "http.h"

View File

@ -187,6 +187,7 @@ boolean nego_tcp_connect(rdpNego* nego)
{
if (!nego->tcp_connected)
nego->tcp_connected = transport_connect(nego->transport, nego->hostname, nego->port);
return nego->tcp_connected;
}
@ -219,6 +220,7 @@ int nego_transport_disconnect(rdpNego* nego)
nego->tcp_connected = 0;
nego->security_connected = 0;
return 1;
}
@ -503,9 +505,12 @@ boolean nego_read_request(rdpNego* nego, STREAM* s)
while (stream_get_left(s) > 0)
{
stream_read_uint8(s, c);
if (c != '\x0D')
continue;
stream_peek_uint8(s, c);
if (c != '\x0A')
continue;
@ -583,6 +588,7 @@ boolean nego_send_negotiation_request(rdpNego* nego)
}
DEBUG_NEGO("requested_protocols: %d", nego->requested_protocols);
if (nego->requested_protocols > PROTOCOL_RDP)
{
/* RDP_NEG_DATA must be present for TLS and NLA */

View File

@ -26,6 +26,7 @@
#include <stdlib.h>
#include <string.h>
#include <winpr/crt.h>
#include <openssl/rand.h>
#include "http.h"
@ -34,7 +35,6 @@
boolean ntlm_client_init(rdpNtlm* ntlm, boolean confidentiality, char* user, char* domain, char* password)
{
size_t size;
SECURITY_STATUS status;
sspi_GlobalInit();
@ -60,24 +60,7 @@ boolean ntlm_client_init(rdpNtlm* ntlm, boolean confidentiality, char* user, cha
ntlm->table = InitSecurityInterface();
#endif
ntlm->identity.Flags = SEC_WINNT_AUTH_IDENTITY_UNICODE;
ntlm->identity.User = (uint16*) freerdp_uniconv_out(ntlm->uniconv, user, &size);
ntlm->identity.UserLength = (uint32) size;
if (domain)
{
ntlm->identity.Domain = (uint16*) freerdp_uniconv_out(ntlm->uniconv, domain, &size);
ntlm->identity.DomainLength = (uint32) size;
}
else
{
ntlm->identity.Domain = (uint16*) NULL;
ntlm->identity.DomainLength = 0;
}
ntlm->identity.Password = (uint16*) freerdp_uniconv_out(ntlm->uniconv, (char*) password, &size);
ntlm->identity.PasswordLength = (uint32) size;
sspi_SetAuthIdentity(&(ntlm->identity), user, domain, password);
status = ntlm->table->QuerySecurityPackageInfo(NTLMSP_NAME, &ntlm->pPackageInfo);
@ -100,9 +83,9 @@ boolean ntlm_client_init(rdpNtlm* ntlm, boolean confidentiality, char* user, cha
ntlm->haveContext = false;
ntlm->haveInputBuffer = false;
memset(&ntlm->inputBuffer, 0, sizeof(SecBuffer));
memset(&ntlm->outputBuffer, 0, sizeof(SecBuffer));
memset(&ntlm->ContextSizes, 0, sizeof(SecPkgContext_Sizes));
ZeroMemory(&ntlm->inputBuffer, sizeof(SecBuffer));
ZeroMemory(&ntlm->outputBuffer, sizeof(SecBuffer));
ZeroMemory(&ntlm->ContextSizes, sizeof(SecPkgContext_Sizes));
ntlm->fContextReq = ISC_REQ_REPLAY_DETECT | ISC_REQ_SEQUENCE_DETECT | ISC_REQ_DELEGATE;
@ -379,7 +362,7 @@ boolean rpc_send_bind_pdu(rdpRpc* rpc)
STREAM* pdu;
rpcconn_bind_hdr_t* bind_pdu;
rdpSettings* settings = rpc->settings;
STREAM* ntlm_stream = stream_new(0xFFFF);
STREAM* ntlm_stream = stream_new(0);
rpc->ntlm = ntlm_new();
@ -512,8 +495,10 @@ int rpc_recv_bind_ack_pdu(rdpRpc* rpc)
int pdu_length = 0x8FFF;
pdu = xmalloc(pdu_length);
if (pdu == NULL)
return -1;
status = rpc_out_read(rpc, pdu, pdu_length);
if (status > 0)
@ -525,11 +510,13 @@ int rpc_recv_bind_ack_pdu(rdpRpc* rpc)
stream_free(s);
auth_data = xmalloc(header.auth_length);
if (auth_data == NULL)
{
xfree(pdu);
return -1;
}
p = (pdu + (header.frag_length - header.auth_length));
memcpy(auth_data, p, header.auth_length);
@ -610,6 +597,7 @@ int rpc_out_read(rdpRpc* rpc, uint8* data, int length)
rts_send_flow_control_ack_pdu(rpc); /* Send FlowControlAck every time AvailableWindow reaches the half */
pdu = xmalloc(0xFFFF);
if (pdu == NULL)
{
printf("rpc_out_read error: memory allocation failed") ;

File diff suppressed because it is too large Load Diff

View File

@ -28,6 +28,7 @@ typedef struct rdp_tsg rdpTsg;
#include <winpr/rpc.h>
#include <winpr/winpr.h>
#include <winpr/wtypes.h>
#include <time.h>
#include <freerdp/types.h>
@ -238,28 +239,6 @@ typedef struct _TSG_PACKET
TSG_PACKET_TYPE_UNION tsgPacket;
} TSG_PACKET, *PTSG_PACKET;
void Opnum0NotUsedOnWire(handle_t IDL_handle);
HRESULT TsProxyCreateTunnel(PTSG_PACKET tsgPacket, PTSG_PACKET* tsgPacketResponse,
PTUNNEL_CONTEXT_HANDLE_SERIALIZE* tunnelContext, unsigned long* tunnelId);
HRESULT TsProxyAuthorizeTunnel(PTUNNEL_CONTEXT_HANDLE_NOSERIALIZE tunnelContext,
PTSG_PACKET tsgPacket, PTSG_PACKET* tsgPacketResponse);
HRESULT TsProxyMakeTunnelCall(PTUNNEL_CONTEXT_HANDLE_NOSERIALIZE tunnelContext,
unsigned long procId, PTSG_PACKET tsgPacket, PTSG_PACKET* tsgPacketResponse);
HRESULT TsProxyCreateChannel(PTUNNEL_CONTEXT_HANDLE_NOSERIALIZE tunnelContext,
PTSENDPOINTINFO tsEndPointInfo, PCHANNEL_CONTEXT_HANDLE_SERIALIZE* channelContext, unsigned long* channelId);
void Opnum5NotUsedOnWire(handle_t IDL_handle);
HRESULT TsProxyCloseChannel(PCHANNEL_CONTEXT_HANDLE_NOSERIALIZE* context);
HRESULT TsProxyCloseTunnel(PTUNNEL_CONTEXT_HANDLE_SERIALIZE* context);
DWORD TsProxySetupReceivePipe(handle_t IDL_handle, byte pRpcMessage[]);
DWORD TsProxySendToServer(handle_t IDL_handle, byte pRpcMessage[], uint32 count, uint32* lengths);
boolean tsg_connect(rdpTsg* tsg, const char* hostname, uint16 port);

View File

@ -130,7 +130,7 @@ int credssp_ntlm_client_init(rdpCredssp* credssp)
#ifdef WITH_DEBUG_NLA
_tprintf(_T("User: %s Domain: %s Password: %s\n"),
credssp->identity.User, credssp->identity.Domain, credssp->identity.Password);
(char*) credssp->identity.User, (char*) credssp->identity.Domain, (char*) credssp->identity.Password);
#endif
sspi_SecBufferAlloc(&credssp->PublicKey, credssp->tls->public_key.length);

View File

@ -1681,8 +1681,8 @@ void freerdp_time_zone_detect(TIME_ZONE_INFO* clientTimeZone)
clientTimeZone->standardBias = clientTimeZone->bias;
clientTimeZone->daylightBias = clientTimeZone->bias + 60;
}
DEBUG_TIMEZONE("sbias=%d, bias=%d, stdBias=%d, dlBias=%d",
sbias, clientTimeZone->bias, clientTimeZone->standardBias,
DEBUG_TIMEZONE("Bias: %d, StandardBias: %d, DaylightBias: %d",
clientTimeZone->bias, clientTimeZone->standardBias,
clientTimeZone->daylightBias);
tz = freerdp_detect_windows_time_zone(clientTimeZone->bias);

View File

@ -395,7 +395,7 @@ int svc_plugin_send(rdpSvcPlugin* plugin, STREAM* data_out)
{
uint32 error = 0;
DEBUG_SVC("length %d", stream_get_length(data_out));
DEBUG_SVC("length %d", (int) stream_get_length(data_out));
error = plugin->channel_entry_points.pVirtualChannelWrite(plugin->priv->open_handle,
stream_get_data(data_out), stream_get_length(data_out), data_out);

View File

@ -27,6 +27,7 @@
#include <winpr/windows.h>
#include "wf_info.h"
#include "wf_update.h"
#include "wf_mirage.h"
static wfInfo* wfInfoInstance = NULL;
@ -103,6 +104,12 @@ wfInfo* wf_info_init()
if (wfi != NULL)
{
HKEY hKey;
LONG status;
DWORD dwType;
DWORD dwSize;
DWORD dwValue;
wfi->mutex = CreateMutex(NULL, FALSE, NULL);
if (wfi->mutex == NULL)
@ -110,9 +117,31 @@ wfInfo* wf_info_init()
_tprintf(_T("CreateMutex error: %d\n"), GetLastError());
}
wfi->updateEvent = CreateEvent(0, 1, 0, 0);
wfi->updateEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
wfi->updateSemaphore = CreateSemaphore(NULL, 0, 32, NULL);
wfi->updateThread = CreateThread(NULL, 0, wf_update_thread, wfi, CREATE_SUSPENDED, NULL);
if (!wfi->updateThread)
{
_tprintf(_T("Failed to create update thread\n"));
}
wfi->peers = (wfPeerContext**) malloc(sizeof(wfPeerContext*) * 32);
wfi->framesPerSecond = 24;
status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("Software\\FreeRDP\\Server"), 0, KEY_READ | KEY_WOW64_64KEY, &hKey);
if (status == ERROR_SUCCESS)
{
if (RegQueryValueEx(hKey, _T("FramesPerSecond"), NULL, &dwType, (BYTE*) &dwValue, &dwSize) == ERROR_SUCCESS)
wfi->framesPerSecond = dwValue;
}
RegCloseKey(hKey);
}
return wfi;
@ -126,28 +155,58 @@ wfInfo* wf_info_get_instance()
return wfInfoInstance;
}
void wf_update_encoder_init(wfInfo* wfi)
{
wfi->rfx_context = rfx_context_new();
wfi->rfx_context->mode = RLGR3;
wfi->rfx_context->width = wfi->width;
wfi->rfx_context->height = wfi->height;
rfx_context_set_pixel_format(wfi->rfx_context, RDP_PIXEL_FORMAT_B8G8R8A8);
wfi->s = stream_new(0xFFFF);
}
void wf_update_encoder_uninit(wfInfo* wfi)
{
if (wfi->rfx_context != NULL)
{
rfx_context_free(wfi->rfx_context);
wfi->rfx_context = NULL;
stream_free(wfi->s);
}
}
void wf_update_encoder_reinit(wfInfo* wfi)
{
wf_update_encoder_uninit(wfi);
wf_update_encoder_init(wfi);
}
void wf_mirror_driver_init(wfInfo* wfi)
{
wf_mirror_driver_find_display_device(wfi);
wf_mirror_driver_display_device_attach(wfi, 1);
wf_mirror_driver_update(wfi, FALSE);
wf_mirror_driver_map_memory(wfi);
}
void wf_mirror_driver_uninit(wfInfo* wfi)
{
wf_mirror_driver_cleanup(wfi);
wf_mirror_driver_display_device_attach(wfi, 0);
wf_mirror_driver_update(wfi, 1);
}
void wf_info_peer_register(wfInfo* wfi, wfPeerContext* context)
{
if (wf_info_lock(wfi) > 0)
{
context->info = wfi;
context->updateEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
if (wfi->peerCount < 1)
{
wf_check_disp_devices(wfi);
wf_disp_device_set_attach_mode(wfi, TRUE);
wf_update_mirror_drv(wfi, 0);
wf_map_mirror_mem(wfi);
wfi->rfx_context = rfx_context_new();
wfi->rfx_context->mode = RLGR3;
wfi->rfx_context->width = wfi->width;
wfi->rfx_context->height = wfi->height;
rfx_context_set_pixel_format(wfi->rfx_context, RDP_PIXEL_FORMAT_B8G8R8A8);
wfi->s = stream_new(65536);
}
wf_mirror_driver_init(wfi);
wf_update_encoder_reinit(wfi);
wfi->peers[wfi->peerCount++] = context;
wf_info_unlock(wfi);
@ -158,21 +217,10 @@ void wf_info_peer_unregister(wfInfo* wfi, wfPeerContext* context)
{
if (wf_info_lock(wfi) > 0)
{
if (wfi->peerCount <= 1)
{
wfi->peers[--(wfi->peerCount)] = NULL;
if (wfi->peerCount == 1)
wf_mirror_driver_uninit(wfi);
wf_mirror_cleanup(wfi);
wf_disp_device_set_attach_mode(context->info, FALSE);
wf_update_mirror_drv(wfi, 1);
stream_free(wfi->s);
rfx_context_free(wfi->rfx_context);
}
else
{
wfi->peers[--(wfi->peerCount)] = NULL;
}
wf_info_unlock(wfi);
}

View File

@ -31,12 +31,12 @@ struct wf_info
STREAM* s;
int width;
int height;
int bitsPerPix;
int bitsPerPixel;
HDC driverDC;
int peerCount;
int threadCount;
BOOL activated;
void* changeBuffer;
int framesPerSecond;
LPTSTR deviceKey;
TCHAR deviceName[32];
wfPeerContext** peers;
@ -45,6 +45,8 @@ struct wf_info
HANDLE mutex;
BOOL updatePending;
HANDLE updateEvent;
HANDLE updateThread;
HANDLE updateSemaphore;
RFX_CONTEXT* rfx_context;
unsigned long lastUpdate;
unsigned long nextUpdate;
@ -66,4 +68,4 @@ void wf_info_find_invalid_region(wfInfo* wfi);
void wf_info_clear_invalid_region(wfInfo* wfi);
BOOL wf_info_have_invalid_region(wfInfo* wfi);
#endif
#endif /* WF_INFO_H */

View File

@ -65,6 +65,7 @@ void wf_peer_unicode_keyboard_event(rdpInput* input, uint16 flags, uint16 code)
void wf_peer_mouse_event(rdpInput* input, uint16 flags, uint16 x, uint16 y)
{
INPUT mouse_event;
float width, height;
ZeroMemory(&mouse_event, sizeof(INPUT));
mouse_event.type = INPUT_MOUSE;
@ -81,12 +82,16 @@ void wf_peer_mouse_event(rdpInput* input, uint16 flags, uint16 x, uint16 y)
}
else
{
width = (float) GetSystemMetrics(SM_CXSCREEN);
height = (float) GetSystemMetrics(SM_CYSCREEN);
mouse_event.mi.dx = (LONG) ((float) x * (65535.0f / width));
mouse_event.mi.dy = (LONG) ((float) y * (65535.0f / height));
mouse_event.mi.dwFlags = MOUSEEVENTF_ABSOLUTE;
if (flags & PTR_FLAGS_MOVE)
{
mouse_event.mi.dx = x * (0xFFFF / GetSystemMetrics(SM_CXSCREEN));
mouse_event.mi.dy = y * (0xFFFF / GetSystemMetrics(SM_CYSCREEN));
mouse_event.mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE;
mouse_event.mi.dwFlags |= MOUSEEVENTF_MOVE;
SendInput(1, &mouse_event, sizeof(INPUT));
}

View File

@ -29,7 +29,7 @@ the mirror device we want to load. If found, it will then copy the registry
key corresponding to the device to the context and returns true. Otherwise
the function returns false.
*/
BOOL wf_check_disp_devices(wfInfo* context)
BOOL wf_mirror_driver_find_display_device(wfInfo* context)
{
BOOL result;
BOOL devFound;
@ -78,7 +78,7 @@ BOOL wf_check_disp_devices(wfInfo* context)
* false.
*/
BOOL wf_disp_device_set_attach_mode(wfInfo* context, DWORD mode)
BOOL wf_mirror_driver_display_device_attach(wfInfo* context, DWORD mode)
{
HKEY hKey;
LONG status;
@ -114,7 +114,7 @@ BOOL wf_disp_device_set_attach_mode(wfInfo* context, DWORD mode)
return TRUE;
}
void wf_disp_change_print_status(LONG status)
void wf_mirror_driver_print_display_change_status(LONG status)
{
TCHAR disp_change[64];
@ -170,16 +170,13 @@ void wf_disp_change_print_status(LONG status)
* If unload is nonzero then the the driver will be asked to remove itself.
*/
BOOL wf_update_mirror_drv(wfInfo* context, int unload)
BOOL wf_mirror_driver_update(wfInfo* context, int unload)
{
HDC dc;
BOOL status;
DWORD* extHdr;
WORD drvExtraSaved;
DEVMODE* deviceMode;
int currentScreenBPP;
int currentScreenPixHeight;
int currentScreenPixWidth;
LONG disp_change_status;
DWORD dmf_devmodewext_magic_sig = 0xDF20C0DE;
@ -189,22 +186,16 @@ BOOL wf_update_mirror_drv(wfInfo* context, int unload)
* Will have to come back to this for supporting non primary displays and multimonitor setups
*/
dc = GetDC(NULL);
currentScreenPixHeight = GetDeviceCaps(dc, VERTRES);
currentScreenPixWidth = GetDeviceCaps(dc, HORZRES);
currentScreenBPP = GetDeviceCaps(dc, BITSPIXEL);
context->width = GetDeviceCaps(dc, HORZRES);
context->height = GetDeviceCaps(dc, VERTRES);
context->bitsPerPixel = GetDeviceCaps(dc, BITSPIXEL);
ReleaseDC(NULL, dc);
context->height = currentScreenPixHeight;
context->width = currentScreenPixWidth;
context->bitsPerPix = currentScreenBPP;
_tprintf(_T("Detected current screen settings: %dx%dx%d\n"), currentScreenPixHeight, currentScreenPixWidth, currentScreenBPP);
}
else
{
currentScreenPixHeight = 0;
currentScreenPixWidth = 0;
currentScreenBPP = 0;
context->width = 0;
context->height = 0;
context->bitsPerPixel = 0;
}
deviceMode = (DEVMODE*) malloc(sizeof(DEVMODE) + EXT_DEVMODE_SIZE_MAX);
@ -219,9 +210,9 @@ BOOL wf_update_mirror_drv(wfInfo* context, int unload)
deviceMode->dmSize = sizeof(DEVMODE);
deviceMode->dmDriverExtra = drvExtraSaved;
deviceMode->dmPelsWidth = currentScreenPixWidth;
deviceMode->dmPelsHeight = currentScreenPixHeight;
deviceMode->dmBitsPerPel = currentScreenBPP;
deviceMode->dmPelsWidth = context->width;
deviceMode->dmPelsHeight = context->height;
deviceMode->dmBitsPerPel = context->bitsPerPixel;
deviceMode->dmPosition.x = 0;
deviceMode->dmPosition.y = 0;
@ -234,12 +225,12 @@ BOOL wf_update_mirror_drv(wfInfo* context, int unload)
status = (disp_change_status == DISP_CHANGE_SUCCESSFUL) ? TRUE : FALSE;
if (!status)
wf_disp_change_print_status(disp_change_status);
wf_mirror_driver_print_display_change_status(disp_change_status);
return status;
}
BOOL wf_map_mirror_mem(wfInfo* context)
BOOL wf_mirror_driver_map_memory(wfInfo* context)
{
int status;
GETCHANGESBUF* b;
@ -269,7 +260,7 @@ BOOL wf_map_mirror_mem(wfInfo* context)
/* Unmap the shared memory and release the DC */
BOOL wf_mirror_cleanup(wfInfo* context)
BOOL wf_mirror_driver_cleanup(wfInfo* context)
{
int status;

View File

@ -200,10 +200,10 @@ typedef struct
ULONG nColorBmPalEntries;
} Esc_dmf_pointer_shape_get_OUT;
BOOL wf_check_disp_devices(wfInfo* context);
BOOL wf_disp_device_set_attach_mode(wfInfo* context, DWORD mode);
BOOL wf_update_mirror_drv(wfInfo* context, int unload);
BOOL wf_map_mirror_mem(wfInfo* context);
BOOL wf_mirror_cleanup(wfInfo* context);
BOOL wf_mirror_driver_find_display_device(wfInfo* context);
BOOL wf_mirror_driver_display_device_attach(wfInfo* context, DWORD mode);
BOOL wf_mirror_driver_update(wfInfo* context, int unload);
BOOL wf_mirror_driver_map_memory(wfInfo* context);
BOOL wf_mirror_driver_cleanup(wfInfo* context);
#endif /* WF_MIRAGE_H */

View File

@ -46,93 +46,23 @@ void wf_peer_context_free(freerdp_peer* client, wfPeerContext* context)
wf_info_peer_unregister(context->info, context);
}
static DWORD WINAPI wf_peer_mirror_monitor(LPVOID lpParam)
{
DWORD fps;
wfInfo* wfi;
DWORD beg, end;
DWORD diff, rate;
freerdp_peer* client;
wfPeerContext* context;
fps = 24;
rate = 1000 / fps;
client = (freerdp_peer*) lpParam;
context = (wfPeerContext*) client->context;
wfi = context->info;
while (1)
{
beg = GetTickCount();
if (wf_info_lock(wfi) > 0)
{
if (wfi->peerCount > 0)
{
wf_info_update_changes(wfi);
if (wf_info_have_updates(wfi))
{
wf_update_encode(wfi);
SetEvent(wfi->updateEvent);
}
}
wf_info_unlock(wfi);
}
end = GetTickCount();
diff = end - beg;
if (diff < rate)
{
Sleep(rate - diff);
}
}
wf_info_lock(wfi);
wfi->threadCount--;
wf_info_unlock(wfi);
return 0;
}
void wf_peer_init(freerdp_peer* client)
{
wfInfo* wfi;
client->context_size = sizeof(wfPeerContext);
client->ContextNew = (psPeerContextNew) wf_peer_context_new;
client->ContextFree = (psPeerContextFree) wf_peer_context_free;
freerdp_peer_context_new(client);
wfi = ((wfPeerContext*) client->context)->info;
wf_info_lock(wfi);
if (wfi->threadCount < 1)
{
if (CreateThread(NULL, 0, wf_peer_mirror_monitor, client, 0, NULL) != 0)
{
wfi->threadCount++;
printf("started monitor thread\n");
}
else
{
_tprintf(_T("failed to create monitor thread\n"));
}
}
wf_info_unlock(wfi);
}
boolean wf_peer_post_connect(freerdp_peer* client)
{
wfInfo* wfi;
rdpSettings* settings;
wfPeerContext* context = (wfPeerContext*) client->context;
wfi = context->info;
settings = client->settings;
/**
* This callback is called when the entire connection sequence is done, i.e. we've received the
@ -141,28 +71,20 @@ boolean wf_peer_post_connect(freerdp_peer* client)
* callback returns.
*/
printf("Client %s is activated (osMajorType %d osMinorType %d)", client->local ? "(local)" : client->hostname,
client->settings->os_major_type, client->settings->os_minor_type);
if (client->settings->autologon)
if ((settings->width != wfi->width) || (settings->height != wfi->height))
{
printf(" and wants to login automatically as %s\\%s",
client->settings->domain ? client->settings->domain : "",
client->settings->username);
printf("Client requested resolution %dx%d, but will resize to %dx%d\n",
settings->width, settings->height, wfi->width, wfi->height);
/* 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);
printf("But we will try resizing to %dx%d\n", wfi->width, wfi->height);
client->settings->width = wfi->width;
client->settings->height = wfi->height;
settings->width = wfi->width;
settings->height = wfi->height;
settings->color_depth = wfi->bitsPerPixel;
client->update->DesktopResize(client->update->context);
client->activated = false;
}
ResumeThread(wfi->updateThread);
return true;
}

View File

@ -21,6 +21,8 @@
#include "config.h"
#endif
#include <winpr/windows.h>
#include <freerdp/freerdp.h>
#include <freerdp/listener.h>
@ -29,6 +31,58 @@
#include "wf_update.h"
DWORD WINAPI wf_update_thread(LPVOID lpParam)
{
int index;
DWORD fps;
wfInfo* wfi;
DWORD beg, end;
DWORD diff, rate;
wfi = (wfInfo*) lpParam;
fps = wfi->framesPerSecond;
rate = 1000 / fps;
while (1)
{
beg = GetTickCount();
if (wf_info_lock(wfi) > 0)
{
if (wfi->peerCount > 0)
{
wf_info_update_changes(wfi);
if (wf_info_have_updates(wfi))
{
wf_update_encode(wfi);
for (index = 0; index < wfi->peerCount; index++)
SetEvent(wfi->peers[index]->updateEvent);
for (index = 0; index < wfi->peerCount; index++)
WaitForSingleObject(wfi->updateSemaphore, INFINITE);
wfi->lastUpdate = wfi->nextUpdate;
}
}
wf_info_unlock(wfi);
}
end = GetTickCount();
diff = end - beg;
if (diff < rate)
{
Sleep(rate - diff);
}
}
return 0;
}
void wf_update_encode(wfInfo* wfi)
{
long offset;
@ -69,30 +123,11 @@ void wf_update_encode(wfInfo* wfi)
cmd->height = height;
cmd->bitmapDataLength = stream_get_length(wfi->s);
cmd->bitmapData = stream_get_head(wfi->s);
wfi->updatePending = TRUE;
}
void wf_update_send(wfInfo* wfi)
void wf_update_peer_send(wfInfo* wfi, wfPeerContext* context)
{
if (wf_info_lock(wfi) > 0)
{
if (wfi->updatePending)
{
int index;
freerdp_peer* client;
for (index = 0; index < wfi->peerCount; index++)
{
client = ((rdpContext*) wfi->peers[index])->peer;
freerdp_peer* client = ((rdpContext*) context)->peer;
wfi->cmd.codecID = client->settings->rfx_codec_id;
client->update->SurfaceBits(client->update->context, &wfi->cmd);
}
wfi->lastUpdate = wfi->nextUpdate;
wfi->updatePending = FALSE;
}
wf_info_unlock(wfi);
}
}

View File

@ -25,4 +25,10 @@
void wf_update_encode(wfInfo* wfi);
void wf_update_send(wfInfo* wfi);
DWORD WINAPI wf_update_thread(LPVOID lpParam);
void wf_update_begin(wfInfo* wfi);
void wf_update_peer_send(wfInfo* wfi, wfPeerContext* context);
void wf_update_end(wfInfo* wfi);
#endif /* WF_UPDATE_H */

View File

@ -64,7 +64,7 @@ static DWORD WINAPI wf_peer_socket_listener(LPVOID lpParam)
if (client->GetFileDescriptor(client, rfds, &rcount) != true)
{
printf("Failed to get FreeRDP file descriptor\n");
printf("Failed to get peer file descriptor\n");
break;
}
@ -81,30 +81,107 @@ static DWORD WINAPI wf_peer_socket_listener(LPVOID lpParam)
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;
}
return 0;
}
static void wf_peer_read_settings(freerdp_peer* client)
{
HKEY hKey;
int length;
LONG status;
DWORD dwType;
DWORD dwSize;
TCHAR* PrivateKeyFile;
TCHAR* CertificateFile;
char* PrivateKeyFileA;
char* CertificateFileA;
PrivateKeyFile = CertificateFile = NULL;
status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("Software\\FreeRDP\\Server"), 0, KEY_READ | KEY_WOW64_64KEY, &hKey);
if (status != ERROR_SUCCESS)
return;
status = RegQueryValueEx(hKey, _T("CertificateFile"), NULL, &dwType, NULL, &dwSize);
if (status == ERROR_SUCCESS)
{
CertificateFile = (LPTSTR) malloc(dwSize + sizeof(TCHAR));
status = RegQueryValueEx(hKey, _T("CertificateFile"), NULL, &dwType, (BYTE*) CertificateFile, &dwSize);
}
status = RegQueryValueEx(hKey, _T("PrivateKeyFile"), NULL, &dwType, NULL, &dwSize);
if (status == ERROR_SUCCESS)
{
PrivateKeyFile = (LPTSTR) malloc(dwSize + sizeof(TCHAR));
status = RegQueryValueEx(hKey, _T("PrivateKeyFile"), NULL, &dwType, (BYTE*) PrivateKeyFile, &dwSize);
}
if (CertificateFile)
{
#ifdef UNICODE
length = WideCharToMultiByte(CP_UTF8, 0, CertificateFile, lstrlenW(CertificateFile), NULL, 0, NULL, NULL);
CertificateFileA = (char*) malloc(length + 1);
WideCharToMultiByte(CP_UTF8, 0, CertificateFile, lstrlenW(CertificateFile), CertificateFileA, length, NULL, NULL);
CertificateFileA[length] = '\0';
free(CertificateFile);
#else
CertificateFileA = (char*) CertificateFile;
#endif
client->settings->cert_file = CertificateFileA;
}
else
{
client->settings->cert_file = _strdup("server.crt");
}
if (PrivateKeyFile)
{
#ifdef UNICODE
length = WideCharToMultiByte(CP_UTF8, 0, PrivateKeyFile, lstrlenW(PrivateKeyFile), NULL, 0, NULL, NULL);
PrivateKeyFileA = (char*) malloc(length + 1);
WideCharToMultiByte(CP_UTF8, 0, PrivateKeyFile, lstrlenW(PrivateKeyFile), PrivateKeyFileA, length, NULL, NULL);
PrivateKeyFileA[length] = '\0';
free(PrivateKeyFile);
#else
PrivateKeyFileA = (char*) PrivateKeyFile;
#endif
client->settings->privatekey_file = PrivateKeyFileA;
}
else
{
client->settings->privatekey_file = _strdup("server.key");
}
RegCloseKey(hKey);
}
static DWORD WINAPI wf_peer_main_loop(LPVOID lpParam)
{
wfInfo* wfi;
DWORD nCount;
DWORD status;
HANDLE handles[32];
wfPeerContext* context;
freerdp_peer* client = (freerdp_peer*) lpParam;
wf_peer_init(client);
/* Initialize the real server settings here */
client->settings->cert_file = xstrdup("server.crt");
client->settings->privatekey_file = xstrdup("server.key");
wf_peer_read_settings(client);
client->PostConnect = wf_peer_post_connect;
client->Activate = wf_peer_activate;
@ -118,29 +195,44 @@ static DWORD WINAPI wf_peer_main_loop(LPVOID lpParam)
client->Initialize(client);
context = (wfPeerContext*) client->context;
context->socketEvent = CreateEvent(0, 1, 0, 0);
CreateThread(NULL, 0, wf_peer_socket_listener, client, 0, NULL);
wfi = context->info;
context->socketEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
context->socketSemaphore = CreateSemaphore(NULL, 0, 1, NULL);
context->socketThread = CreateThread(NULL, 0, wf_peer_socket_listener, client, 0, NULL);
printf("We've got a client %s\n", client->local ? "(local)" : client->hostname);
nCount = 0;
handles[nCount++] = context->updateEvent;
handles[nCount++] = context->socketEvent;
handles[nCount++] = context->info->updateEvent;
while (1)
{
DWORD status;
status = WaitForMultipleObjects(nCount, handles, FALSE, INFINITE);
if (client->CheckFileDescriptor(client) != true)
if (WaitForSingleObject(context->updateEvent, 0) == 0)
{
printf("Failed to check FreeRDP file descriptor\n");
break;
if (client->activated)
wf_update_peer_send(wfi, context);
ResetEvent(context->updateEvent);
ReleaseSemaphore(wfi->updateSemaphore, 1, NULL);
}
if (client->activated)
wf_update_send(context->info);
if (WaitForSingleObject(context->socketEvent, 0) == 0)
{
if (client->CheckFileDescriptor(client) != true)
{
printf("Failed to check peer file descriptor\n");
context->socketClose = TRUE;
}
ResetEvent(context->socketEvent);
ReleaseSemaphore(context->socketSemaphore, 1, NULL);
if (context->socketClose)
break;
}
}
printf("Client %s disconnected.\n", client->local ? "(local)" : client->hostname);

View File

@ -30,7 +30,11 @@ struct wf_peer_context
wfInfo* info;
boolean activated;
HANDLE updateEvent;
BOOL socketClose;
HANDLE socketEvent;
HANDLE socketThread;
HANDLE socketSemaphore;
};
typedef struct wf_peer_context wfPeerContext;

1
third-party/VM-GuestHost-Services vendored Submodule

@ -0,0 +1 @@
Subproject commit 404b357c5b6e026177f02e3d33ef5fa59c651728