From 5b5791c8d73b85109fd4912ea92bf66c2c3f87d7 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Fri, 12 Sep 2014 17:38:12 +0200 Subject: [PATCH] Using wlog for server now. --- server/Mac/mf_audin.c | 9 +- server/Mac/mf_event.c | 15 +- server/Mac/mf_info.c | 517 +++++++++---------- server/Mac/mf_input.c | 12 +- server/Mac/mf_mountain_lion.c | 18 +- server/Mac/mf_peer.c | 873 ++++++++++++++++---------------- server/Mac/mf_rdpsnd.c | 21 +- server/Mac/mfreerdp.c | 9 +- server/Sample/sf_audin.c | 11 +- server/Sample/sf_rdpsnd.c | 7 +- server/Sample/sfreerdp.c | 75 ++- server/Windows/cli/wfreerdp.c | 44 +- server/Windows/wf_directsound.c | 46 +- server/Windows/wf_dxgi.c | 51 +- server/Windows/wf_info.c | 619 +++++++++++----------- server/Windows/wf_interface.c | 14 +- server/Windows/wf_interface.h | 1 - server/Windows/wf_mirage.c | 646 +++++++++++------------ server/Windows/wf_peer.c | 618 +++++++++++----------- server/Windows/wf_rdpsnd.c | 13 +- server/Windows/wf_update.c | 31 +- server/Windows/wf_wasapi.c | 55 +- server/shadow/Win/win_dxgi.c | 31 +- server/shadow/Win/win_rdp.c | 21 +- server/shadow/Win/win_shadow.c | 7 +- server/shadow/Win/win_wds.c | 75 +-- server/shadow/X11/x11_shadow.c | 17 +- server/shadow/shadow_capture.c | 24 +- server/shadow/shadow_client.c | 12 +- server/shadow/shadow_encomsp.c | 5 +- server/shadow/shadow_server.c | 47 +- 31 files changed, 1986 insertions(+), 1958 deletions(-) diff --git a/server/Mac/mf_audin.c b/server/Mac/mf_audin.c index c4b2d8f39..3893f7b5a 100644 --- a/server/Mac/mf_audin.c +++ b/server/Mac/mf_audin.c @@ -25,6 +25,9 @@ #include "mf_audin.h" +#include +#define TAG SERVER_TAG("mac") + static const AUDIO_FORMAT supported_audio_formats[] = { @@ -34,19 +37,19 @@ static const AUDIO_FORMAT supported_audio_formats[] = static void mf_peer_audin_opening(audin_server_context* context) { - DEBUG_WARN( "AUDIN opening.\n"); + WLog_INFO(TAG, "AUDIN opening."); /* Simply choose the first format supported by the client. */ context->SelectFormat(context, 0); } static void mf_peer_audin_open_result(audin_server_context* context, UINT32 result) { - DEBUG_WARN( "AUDIN open result %d.\n", result); + WLog_INFO(TAG, "AUDIN open result %d.", result); } static void mf_peer_audin_receive_samples(audin_server_context* context, const void* buf, int nframes) { - DEBUG_WARN( "AUDIN receive %d frames.\n", nframes); + WLog_INFO(TAG, "AUDIN receive %d frames.", nframes); } void mf_peer_audin_init(mfPeerContext* context) diff --git a/server/Mac/mf_event.c b/server/Mac/mf_event.c index a2e2e1a40..ff3d2a21f 100644 --- a/server/Mac/mf_event.c +++ b/server/Mac/mf_event.c @@ -30,6 +30,9 @@ #include "mf_event.h" +#include +#define TAG SERVER_TAG("mac") + int mf_is_event_set(mfEventQueue* event_queue) { fd_set rfds; @@ -51,7 +54,7 @@ void mf_signal_event(mfEventQueue* event_queue) length = write(event_queue->pipe_fd[1], "sig", 4); if (length != 4) - DEBUG_WARN( "mf_signal_event: error\n"); + WLog_ERR(TAG, "mf_signal_event: error"); } void mf_set_event(mfEventQueue* event_queue) @@ -61,7 +64,7 @@ void mf_set_event(mfEventQueue* event_queue) length = write(event_queue->pipe_fd[1], "sig", 4); if (length != 4) - DEBUG_WARN( "mf_set_event: error\n"); + WLog_ERR(TAG, "mf_set_event: error"); } void mf_clear_events(mfEventQueue* event_queue) @@ -73,7 +76,7 @@ void mf_clear_events(mfEventQueue* event_queue) length = read(event_queue->pipe_fd[0], &length, 4); if (length != 4) - DEBUG_WARN( "mf_clear_event: error\n"); + WLog_ERR(TAG, "mf_clear_event: error"); } } @@ -84,7 +87,7 @@ void mf_clear_event(mfEventQueue* event_queue) length = read(event_queue->pipe_fd[0], &length, 4); if (length != 4) - DEBUG_WARN( "mf_clear_event: error\n"); + WLog_ERR(TAG, "mf_clear_event: error"); } void mf_event_push(mfEventQueue* event_queue, mfEvent* event) @@ -188,8 +191,8 @@ mfEventQueue* mf_event_queue_new() event_queue->events = (mfEvent**) malloc(sizeof(mfEvent*) * event_queue->size); if (pipe(event_queue->pipe_fd) < 0) - DEBUG_WARN( "mf_event_queue_new: pipe failed\n"); - + WLog_ERR(TAG, "mf_event_queue_new: pipe failed"); + pthread_mutex_init(&(event_queue->mutex), NULL); } diff --git a/server/Mac/mf_info.c b/server/Mac/mf_info.c index dfa686a5f..fb261c04c 100644 --- a/server/Mac/mf_info.c +++ b/server/Mac/mf_info.c @@ -1,309 +1,312 @@ -/** - * FreeRDP: A Remote Desktop Protocol Client - * FreeRDP Mac OS X Server - * - * Copyright 2012 Corey Clayton - * - * 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 -#include - -#include "mf_info.h" -#include "mf_mountain_lion.h" -//#include "mf_update.h" - -static mfInfo* mfInfoInstance = NULL; -//static int _IDcount = 0; - -int mf_info_lock(mfInfo* mfi) -{ +/** + * FreeRDP: A Remote Desktop Protocol Client + * FreeRDP Mac OS X Server + * + * Copyright 2012 Corey Clayton + * + * 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 +#include + +#include "mf_info.h" +#include "mf_mountain_lion.h" +//#include "mf_update.h" + +#include +#define TAG SERVER_TAG("mac") + +static mfInfo* mfInfoInstance = NULL; +//static int _IDcount = 0; + +int mf_info_lock(mfInfo* mfi) +{ - int status = pthread_mutex_lock(&mfi->mutex); + int status = pthread_mutex_lock(&mfi->mutex); switch (status) { - case 0: - return TRUE; - break; + case 0: + return TRUE; + break; - default: - DEBUG_MSG("mf_info_lock failed with %#X\n", status); - return -1; - break; - } + default: + WLog_ERR(TAG, "mf_info_lock failed with %#X", status); + return -1; + break; + } -} - -int mf_info_try_lock(mfInfo* mfi, UINT32 ms) -{ +} + +int mf_info_try_lock(mfInfo* mfi, UINT32 ms) +{ - int status = pthread_mutex_trylock(&mfi->mutex); + int status = pthread_mutex_trylock(&mfi->mutex); switch (status) { - case 0: - return TRUE; - break; + case 0: + return TRUE; + break; - case EBUSY: - return FALSE; - break; + case EBUSY: + return FALSE; + break; - default: - DEBUG_MSG("mf_info_try_lock failed with %#X\n", status); - return -1; - break; - } + default: + WLog_ERR(TAG, "mf_info_try_lock failed with %#X", status); + return -1; + break; + } -} - -int mf_info_unlock(mfInfo* mfi) -{ - int status = pthread_mutex_unlock(&mfi->mutex); +} + +int mf_info_unlock(mfInfo* mfi) +{ + int status = pthread_mutex_unlock(&mfi->mutex); switch (status) { - case 0: - return TRUE; - break; + case 0: + return TRUE; + break; - default: - DEBUG_MSG("mf_info_unlock failed with %#X\n", status); - return -1; - break; - } + default: + WLog_ERR(TAG, "mf_info_unlock failed with %#X", status); + return -1; + break; + } -} - -mfInfo* mf_info_init() -{ - mfInfo* mfi; +} + +mfInfo* mf_info_init() +{ + mfInfo* mfi; - mfi = (mfInfo*) malloc(sizeof(mfInfo)); - memset(mfi, 0, sizeof(mfInfo)); + mfi = (mfInfo*) malloc(sizeof(mfInfo)); + memset(mfi, 0, sizeof(mfInfo)); - if (mfi != NULL) - { - /* HKEY hKey; - LONG status; - DWORD dwType; - DWORD dwSize; - DWORD dwValue; - */ + if (mfi != NULL) + { + /* HKEY hKey; + LONG status; + DWORD dwType; + DWORD dwSize; + DWORD dwValue; + */ - int mutexInitStatus = pthread_mutex_init(&mfi->mutex, NULL); + int mutexInitStatus = pthread_mutex_init(&mfi->mutex, NULL); - if (mutexInitStatus != 0) - { - DEBUG_MSG(_T("CreateMutex error: %#X\n"), mutexInitStatus); - } + if (mutexInitStatus != 0) + { + WLog_ERR(TAG, _T("CreateMutex error: %#X"), mutexInitStatus); + } - mfi->peers = (freerdp_peer**) malloc(sizeof(freerdp_peer*) * MF_INFO_MAXPEERS); - memset(mfi->peers, 0, sizeof(freerdp_peer*) * MF_INFO_MAXPEERS); + mfi->peers = (freerdp_peer**) malloc(sizeof(freerdp_peer*) * MF_INFO_MAXPEERS); + memset(mfi->peers, 0, sizeof(freerdp_peer*) * MF_INFO_MAXPEERS); - //Set FPS - mfi->framesPerSecond = MF_INFO_DEFAULT_FPS; + //Set FPS + mfi->framesPerSecond = MF_INFO_DEFAULT_FPS; - /*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) - mfi->framesPerSecond = dwValue; - } - RegCloseKey(hKey);*/ + /*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) + mfi->framesPerSecond = dwValue; + } + RegCloseKey(hKey);*/ - //Set input toggle - mfi->input_disabled = FALSE; + //Set input toggle + mfi->input_disabled = FALSE; - /*status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("Software\\FreeRDP\\Server"), 0, KEY_READ | KEY_WOW64_64KEY, &hKey); - if (status == ERROR_SUCCESS) - { - if (RegQueryValueEx(hKey, _T("DisableInput"), NULL, &dwType, (BYTE*) &dwValue, &dwSize) == ERROR_SUCCESS) - { - if (dwValue != 0) - mfi->input_disabled = TRUE; - } - } - RegCloseKey(hKey);*/ + /*status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("Software\\FreeRDP\\Server"), 0, KEY_READ | KEY_WOW64_64KEY, &hKey); + if (status == ERROR_SUCCESS) + { + if (RegQueryValueEx(hKey, _T("DisableInput"), NULL, &dwType, (BYTE*) &dwValue, &dwSize) == ERROR_SUCCESS) + { + if (dwValue != 0) + mfi->input_disabled = TRUE; + } + } + RegCloseKey(hKey);*/ - } + } - return mfi; -} - -mfInfo* mf_info_get_instance() -{ - if (mfInfoInstance == NULL) - mfInfoInstance = mf_info_init(); + return mfi; +} + +mfInfo* mf_info_get_instance() +{ + if (mfInfoInstance == NULL) + mfInfoInstance = mf_info_init(); - return mfInfoInstance; -} - -void mf_info_peer_register(mfInfo* mfi, mfPeerContext* context) -{ - if (mf_info_lock(mfi) > 0) - { - int i; - int peerId; - if (mfi->peerCount == MF_INFO_MAXPEERS) - { - DEBUG_MSG("TODO: socketClose on OS X\n"); - //context->socketClose = TRUE; - mf_info_unlock(mfi); - return; - } + return mfInfoInstance; +} + +void mf_info_peer_register(mfInfo* mfi, mfPeerContext* context) +{ + if (mf_info_lock(mfi) > 0) + { + int i; + int peerId; + if (mfi->peerCount == MF_INFO_MAXPEERS) + { + WLog_ERR(TAG, "TODO: socketClose on OS X"); + //context->socketClose = TRUE; + mf_info_unlock(mfi); + return; + } - context->info = mfi; + context->info = mfi; - //get the offset of the top left corner of selected screen - //EnumDisplayMonitors(NULL, NULL, mf_info_monEnumCB, 0); - //_IDcount = 0; + //get the offset of the top left corner of selected screen + //EnumDisplayMonitors(NULL, NULL, mf_info_monEnumCB, 0); + //_IDcount = 0; - //initialize screen capture - if (mfi->peerCount == 0) - { - mf_mlion_display_info(&mfi->servscreen_width, &mfi->servscreen_height, &mfi->scale); - mf_mlion_screen_updates_init(); - mf_mlion_start_getting_screen_updates(); - } + //initialize screen capture + if (mfi->peerCount == 0) + { + mf_mlion_display_info(&mfi->servscreen_width, &mfi->servscreen_height, &mfi->scale); + mf_mlion_screen_updates_init(); + mf_mlion_start_getting_screen_updates(); + } - //look trhough the array of peers until an empty slot - peerId = NULL; + //look trhough the array of peers until an empty slot + peerId = NULL; for(i=0; ipeers[i] == NULL) - { - peerId = i; - break; - } - } + { + //empty index will be our peer id + if (mfi->peers[i] == NULL) + { + peerId = i; + break; + } + } - mfi->peers[peerId] = ((rdpContext*) context)->peer; - mfi->peers[peerId]->pId = peerId; - mfi->peerCount++; - //printf("Registering Peer: id=%d #=%d\n", peerId, mfi->peerCount); + mfi->peers[peerId] = ((rdpContext*) context)->peer; + mfi->peers[peerId]->pId = peerId; + mfi->peerCount++; + //WLog_DBG(TAG, "Registering Peer: id=%d #=%d\n", peerId, mfi->peerCount); - mf_info_unlock(mfi); + mf_info_unlock(mfi); - //mfreerdp_server_peer_callback_event(peerId, MF_SRV_CALLBACK_EVENT_CONNECT); - } -} - -void mf_info_peer_unregister(mfInfo* mfi, mfPeerContext* context) -{ - if (mf_info_lock(mfi) > 0) - { - int peerId; + //mfreerdp_server_peer_callback_event(peerId, MF_SRV_CALLBACK_EVENT_CONNECT); + } +} + +void mf_info_peer_unregister(mfInfo* mfi, mfPeerContext* context) +{ + if (mf_info_lock(mfi) > 0) + { + int peerId; - peerId = ((rdpContext*) context)->peer->pId; - mfi->peers[peerId] = NULL; - mfi->peerCount--; + peerId = ((rdpContext*) context)->peer->pId; + mfi->peers[peerId] = NULL; + mfi->peerCount--; - //printf("Unregistering Peer: id=%d, #=%d\n", peerId, mfi->peerCount); + //WLog_DBG(TAG, "Unregistering Peer: id=%d, #=%d\n", peerId, mfi->peerCount); - //screen capture cleanup - if (mfi->peerCount == 0) - { - mf_mlion_stop_getting_screen_updates(); - } - mf_info_unlock(mfi); + //screen capture cleanup + if (mfi->peerCount == 0) + { + mf_mlion_stop_getting_screen_updates(); + } + mf_info_unlock(mfi); - //mfreerdp_server_peer_callback_event(peerId, MF_SRV_CALLBACK_EVENT_DISCONNECT); - } -} - -BOOL mf_info_have_updates(mfInfo* mfi) -{ + //mfreerdp_server_peer_callback_event(peerId, MF_SRV_CALLBACK_EVENT_DISCONNECT); + } +} + +BOOL mf_info_have_updates(mfInfo* mfi) +{ if(mfi->framesWaiting == 0) - return FALSE; + return FALSE; - return TRUE; -} - -void mf_info_update_changes(mfInfo* mfi) -{ - /*#ifdef WITH_WIN8 - mf_dxgi_nextFrame(mfi, mfi->framesPerSecond * 1000); - #else - GETCHANGESBUF* buf; + return TRUE; +} + +void mf_info_update_changes(mfInfo* mfi) +{ + /*#ifdef WITH_WIN8 + mf_dxgi_nextFrame(mfi, mfi->framesPerSecond * 1000); + #else + GETCHANGESBUF* buf; - buf = (GETCHANGESBUF*) mfi->changeBuffer; - mfi->nextUpdate = buf->buffer->counter; - #endif*/ -} - -void mf_info_find_invalid_region(mfInfo* mfi) -{ - mf_mlion_get_dirty_region(&mfi->invalid); -} - -void mf_info_clear_invalid_region(mfInfo* mfi) -{ - mf_mlion_clear_dirty_region(); - mfi->invalid.height = 0; - mfi->invalid.width = 0; -} - -void mf_info_invalidate_full_screen(mfInfo* mfi) -{ - mfi->invalid.x = 0; - mfi->invalid.y = 0; - mfi->invalid.height = mfi->servscreen_height; - mfi->invalid.height = mfi->servscreen_width; -} - -BOOL mf_info_have_invalid_region(mfInfo* mfi) -{ + buf = (GETCHANGESBUF*) mfi->changeBuffer; + mfi->nextUpdate = buf->buffer->counter; + #endif*/ +} + +void mf_info_find_invalid_region(mfInfo* mfi) +{ + mf_mlion_get_dirty_region(&mfi->invalid); +} + +void mf_info_clear_invalid_region(mfInfo* mfi) +{ + mf_mlion_clear_dirty_region(); + mfi->invalid.height = 0; + mfi->invalid.width = 0; +} + +void mf_info_invalidate_full_screen(mfInfo* mfi) +{ + mfi->invalid.x = 0; + mfi->invalid.y = 0; + mfi->invalid.height = mfi->servscreen_height; + mfi->invalid.height = mfi->servscreen_width; +} + +BOOL mf_info_have_invalid_region(mfInfo* mfi) +{ if (mfi->invalid.width * mfi->invalid.height == 0) { - return FALSE; - } - return TRUE; -} - -void mf_info_getScreenData(mfInfo* mfi, long* width, long* height, BYTE** pBits, int* pitch) -{ - *width = mfi->invalid.width / mfi->scale; - *height = mfi->invalid.height / mfi->scale; - *pitch = mfi->servscreen_width * mfi->scale * 4; + return FALSE; + } + return TRUE; +} + +void mf_info_getScreenData(mfInfo* mfi, long* width, long* height, BYTE** pBits, int* pitch) +{ + *width = mfi->invalid.width / mfi->scale; + *height = mfi->invalid.height / mfi->scale; + *pitch = mfi->servscreen_width * mfi->scale * 4; - mf_mlion_get_pixelData(mfi->invalid.x / mfi->scale, mfi->invalid.y / mfi->scale, *width, *height, pBits); + mf_mlion_get_pixelData(mfi->invalid.x / mfi->scale, mfi->invalid.y / mfi->scale, *width, *height, pBits); - *pBits = *pBits + (mfi->invalid.x * 4) + (*pitch * mfi->invalid.y); + *pBits = *pBits + (mfi->invalid.x * 4) + (*pitch * mfi->invalid.y); -} - -/* - BOOL CALLBACK mf_info_monEnumCB(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData) - { - mfInfo * mfi; +} + +/* + BOOL CALLBACK mf_info_monEnumCB(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData) + { + mfInfo * mfi; - mfi = mf_info_get_instance(); + mfi = mf_info_get_instance(); - if(_IDcount == mfi->screenID) - { - mfi->servscreen_xoffset = lprcMonitor->left; - mfi->servscreen_yoffset = lprcMonitor->top; - } + if(_IDcount == mfi->screenID) + { + mfi->servscreen_xoffset = lprcMonitor->left; + mfi->servscreen_yoffset = lprcMonitor->top; + } - _IDcount++; + _IDcount++; - return TRUE; - } - */ + return TRUE; + } + */ diff --git a/server/Mac/mf_input.c b/server/Mac/mf_input.c index d74cd9c26..1e53fc75a 100644 --- a/server/Mac/mf_input.c +++ b/server/Mac/mf_input.c @@ -29,7 +29,11 @@ #include "mf_input.h" #include "mf_info.h" -static const CGKeyCode keymap[256] = { +#include +#define TAG SERVER_TAG("mac") + +static const CGKeyCode keymap[256] = +{ 0xFF, //0x0 kVK_Escape, //0x1 kVK_ANSI_1, //0x2 @@ -356,8 +360,8 @@ void mf_input_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code) /* if (flags & KBD_FLAGS_EXTENDED) - DEBUG_WARN( "extended "); - DEBUG_WARN( "keypress: down = %d, SCAN=%#0X, VK=%#0X\n", keyDown, code, keymap[code]); + WLog_ERR(TAG, "extended "); + WLog_ERR(TAG, "keypress: down = %d, SCAN=%#0X, VK=%#0X", keyDown, code, keymap[code]); */ } @@ -548,7 +552,7 @@ void mf_input_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y) void mf_input_extended_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y) { - DEBUG_WARN( "Unhandled mouse event!!!\n"); + WLog_ERR(TAG, "Unhandled mouse event!!!"); /* if ((flags & PTR_XFLAGS_BUTTON1) || (flags & PTR_XFLAGS_BUTTON2)) { diff --git a/server/Mac/mf_mountain_lion.c b/server/Mac/mf_mountain_lion.c index f9777a261..f32a86da9 100644 --- a/server/Mac/mf_mountain_lion.c +++ b/server/Mac/mf_mountain_lion.c @@ -25,6 +25,9 @@ #include "mf_mountain_lion.h" +#include +#define TAG SERVER_TAG("mac") + dispatch_semaphore_t region_sem; dispatch_semaphore_t data_sem; dispatch_queue_t screen_update_q; @@ -86,21 +89,20 @@ void (^streamHandler)(CGDisplayStreamFrameStatus, uint64_t, IOSurfaceRef, CGDisp switch(status) { case kCGDisplayStreamFrameStatusFrameIdle: - DEBUG_MSG("kCGDisplayStreamFrameStatusFrameIdle\n"); + WLog_DBG(TAG, "kCGDisplayStreamFrameStatusFrameIdle"); break; case kCGDisplayStreamFrameStatusStopped: //we dont need to clean up - //printf("kCGDisplayStreamFrameStatusStopped\n"); + //WLog_DBG(TAG, "kCGDisplayStreamFrameStatusStopped"); break; case kCGDisplayStreamFrameStatusFrameBlank: - DEBUG_MSG("kCGDisplayStreamFrameStatusFrameBlank\n"); + WLog_DBG(TAG, "kCGDisplayStreamFrameStatusFrameBlank"); break; default: - DEBUG_MSG("Unhandled Frame Status!!!\n"); - + WLog_WARN(TAG, "Unhandled Frame Status!!!"); } } else if (lastUpdate == NULL) @@ -193,7 +195,7 @@ int mf_mlion_start_getting_screen_updates() err = CGDisplayStreamStart(stream); if(err != kCGErrorSuccess) { - DEBUG_MSG("Failed to start displaystream!! err = %d\n", err); + WLog_WARN(TAG, "Failed to start displaystream!! err = %d", err); return 1; } @@ -207,13 +209,11 @@ int mf_mlion_stop_getting_screen_updates() err = CGDisplayStreamStop(stream); if(err != kCGErrorSuccess) { - DEBUG_MSG("Failed to stop displaystream!! err = %d\n", err); + WLog_WARN(TAG, "Failed to stop displaystream!! err = %d", err); return 1; } return 0; - - return 0; } int mf_mlion_get_dirty_region(RFX_RECT* invalid) diff --git a/server/Mac/mf_peer.c b/server/Mac/mf_peer.c index 6eee3d892..d1de819ec 100644 --- a/server/Mac/mf_peer.c +++ b/server/Mac/mf_peer.c @@ -1,501 +1,498 @@ -/** - * FreeRDP: A Remote Desktop Protocol Client - * FreeRDP Mac OS X Server - * - * Copyright 2012 Corey Clayton - * - * 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 -#include -#include - -#include - -#include "mf_peer.h" -#include "mf_info.h" -#include "mf_input.h" -#include "mf_event.h" -#include "mf_rdpsnd.h" - -#include -#include -#include - -#include "OpenGL/OpenGL.h" -#include "OpenGL/gl.h" - -#include "CoreVideo/CoreVideo.h" - -//refactor these -int info_last_sec = 0; -int info_last_nsec = 0; - -dispatch_source_t info_timer; -dispatch_queue_t info_queue; - -mfEventQueue* info_event_queue; - - -CGLContextObj glContext; -CGContextRef bmp; -CGImageRef img; - - - -BOOL mf_peer_get_fds(freerdp_peer* client, void** rfds, int* rcount) -{ - if (info_event_queue->pipe_fd[0] == -1) - return TRUE; +/** + * FreeRDP: A Remote Desktop Protocol Client + * FreeRDP Mac OS X Server + * + * Copyright 2012 Corey Clayton + * + * 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 +#include +#include + +#include + +#include "mf_peer.h" +#include "mf_info.h" +#include "mf_input.h" +#include "mf_event.h" +#include "mf_rdpsnd.h" + +#include +#include +#include + +#include "OpenGL/OpenGL.h" +#include "OpenGL/gl.h" + +#include "CoreVideo/CoreVideo.h" + +#include +#define TAG SERVER_TAG("mac") + +//refactor these +int info_last_sec = 0; +int info_last_nsec = 0; + +dispatch_source_t info_timer; +dispatch_queue_t info_queue; + +mfEventQueue* info_event_queue; + + +CGLContextObj glContext; +CGContextRef bmp; +CGImageRef img; + + + +BOOL mf_peer_get_fds(freerdp_peer* client, void** rfds, int* rcount) +{ + if (info_event_queue->pipe_fd[0] == -1) + return TRUE; rfds[*rcount] = (void *)(long) info_event_queue->pipe_fd[0]; - (*rcount)++; + (*rcount)++; - return TRUE; -} - -BOOL mf_peer_check_fds(freerdp_peer* client) -{ - mfPeerContext* context = (mfPeerContext*) client->context; - mfEvent* event; + return TRUE; +} + +BOOL mf_peer_check_fds(freerdp_peer* client) +{ + mfPeerContext* context = (mfPeerContext*) client->context; + mfEvent* event; - if (context->activated == FALSE) - return TRUE; + if (context->activated == FALSE) + return TRUE; - event = mf_event_peek(info_event_queue); + event = mf_event_peek(info_event_queue); - if (event != NULL) - { - if (event->type == MF_EVENT_TYPE_REGION) - { - DEBUG_WARN( "unhandled event\n"); - } - else if (event->type == MF_EVENT_TYPE_FRAME_TICK) - { - event = mf_event_pop(info_event_queue); + if (event != NULL) + { + if (event->type == MF_EVENT_TYPE_REGION) + { + WLog_ERR(TAG, "unhandled event"); + } + else if (event->type == MF_EVENT_TYPE_FRAME_TICK) + { + event = mf_event_pop(info_event_queue); - mf_peer_rfx_update(client); + mf_peer_rfx_update(client); - mf_event_free(event); - } - } + mf_event_free(event); + } + } - return TRUE; -} - -void mf_peer_rfx_update(freerdp_peer* client) -{ - //check - mfInfo* mfi = mf_info_get_instance(); + return TRUE; +} + +void mf_peer_rfx_update(freerdp_peer* client) +{ + //check + mfInfo* mfi = mf_info_get_instance(); - mf_info_find_invalid_region(mfi); + mf_info_find_invalid_region(mfi); if (mf_info_have_invalid_region(mfi) == false) { - return; - } + return; + } - long width; - long height; - int pitch; - BYTE* dataBits = NULL; + long width; + long height; + int pitch; + BYTE* dataBits = NULL; - mf_info_getScreenData(mfi, &width, &height, &dataBits, &pitch); + mf_info_getScreenData(mfi, &width, &height, &dataBits, &pitch); - mf_info_clear_invalid_region(mfi); + mf_info_clear_invalid_region(mfi); - //encode + //encode - wStream* s; - RFX_RECT rect; - rdpUpdate* update; - mfPeerContext* mfp; - SURFACE_BITS_COMMAND* cmd; + wStream* s; + RFX_RECT rect; + rdpUpdate* update; + mfPeerContext* mfp; + SURFACE_BITS_COMMAND* cmd; - update = client->update; - mfp = (mfPeerContext*) client->context; - cmd = &update->surface_bits_command; + update = client->update; + mfp = (mfPeerContext*) client->context; + cmd = &update->surface_bits_command; - s = mfp->s; - Stream_Clear(s); - Stream_SetPosition(s, 0); + s = mfp->s; + Stream_Clear(s); + Stream_SetPosition(s, 0); - UINT32 x = mfi->invalid.x / mfi->scale; - UINT32 y = mfi->invalid.y / mfi->scale; + UINT32 x = mfi->invalid.x / mfi->scale; + UINT32 y = mfi->invalid.y / mfi->scale; - rect.x = 0; - rect.y = 0; - rect.width = width; - rect.height = height; + rect.x = 0; + rect.y = 0; + rect.width = width; + rect.height = height; - mfp->rfx_context->width = mfi->servscreen_width; - mfp->rfx_context->height = mfi->servscreen_height; + mfp->rfx_context->width = mfi->servscreen_width; + mfp->rfx_context->height = mfi->servscreen_height; - rfx_compose_message(mfp->rfx_context, s, &rect, 1, + rfx_compose_message(mfp->rfx_context, s, &rect, 1, (BYTE*) dataBits, rect.width, rect.height, pitch); - cmd->destLeft = x; - cmd->destTop = y; - cmd->destRight = x + rect.width; - cmd->destBottom = y + rect.height; + cmd->destLeft = x; + cmd->destTop = y; + cmd->destRight = x + rect.width; + cmd->destBottom = y + rect.height; - cmd->bpp = 32; - cmd->codecID = 3; - cmd->width = rect.width; - cmd->height = rect.height; - cmd->bitmapDataLength = Stream_GetPosition(s); - cmd->bitmapData = Stream_Buffer(s); + cmd->bpp = 32; + cmd->codecID = 3; + cmd->width = rect.width; + cmd->height = rect.height; + cmd->bitmapDataLength = Stream_GetPosition(s); + cmd->bitmapData = Stream_Buffer(s); - //send + //send - update->SurfaceBits(update->context, cmd); + update->SurfaceBits(update->context, cmd); - //clean up... maybe? + //clean up... maybe? -} +} + +/* Called when we have a new peer connecting */ +int mf_peer_context_new(freerdp_peer* client, mfPeerContext* context) +{ + context->info = mf_info_get_instance(); + context->rfx_context = rfx_context_new(TRUE); + context->rfx_context->mode = RLGR3; + context->rfx_context->width = client->settings->DesktopWidth; + context->rfx_context->height = client->settings->DesktopHeight; + rfx_context_set_pixel_format(context->rfx_context, RDP_PIXEL_FORMAT_B8G8R8A8); + + //context->nsc_context = nsc_context_new(); + //nsc_context_set_pixel_format(context->nsc_context, RDP_PIXEL_FORMAT_B8G8R8A8); + + context->s = Stream_New(NULL, 0xFFFF); + + context->vcm = WTSOpenServerA((LPSTR) client->context); + + mf_info_peer_register(context->info, context); -/* Called when we have a new peer connecting */ -int mf_peer_context_new(freerdp_peer* client, mfPeerContext* context) -{ - context->info = mf_info_get_instance(); - context->rfx_context = rfx_context_new(TRUE); - context->rfx_context->mode = RLGR3; - context->rfx_context->width = client->settings->DesktopWidth; - context->rfx_context->height = client->settings->DesktopHeight; - rfx_context_set_pixel_format(context->rfx_context, RDP_PIXEL_FORMAT_B8G8R8A8); - - //context->nsc_context = nsc_context_new(); - //nsc_context_set_pixel_format(context->nsc_context, RDP_PIXEL_FORMAT_B8G8R8A8); - - context->s = Stream_New(NULL, 0xFFFF); - - context->vcm = WTSOpenServerA((LPSTR) client->context); - - mf_info_peer_register(context->info, context); - - return 0; -} - -/* Called after a peer disconnects */ -void mf_peer_context_free(freerdp_peer* client, mfPeerContext* context) -{ - if (context) - { - mf_info_peer_unregister(context->info, context); + return 0; +} + +/* Called after a peer disconnects */ +void mf_peer_context_free(freerdp_peer* client, mfPeerContext* context) +{ + if (context) + { + mf_info_peer_unregister(context->info, context); - dispatch_suspend(info_timer); + dispatch_suspend(info_timer); - Stream_Free(context->s, TRUE); + Stream_Free(context->s, TRUE); - rfx_context_free(context->rfx_context); - //nsc_context_free(context->nsc_context); + rfx_context_free(context->rfx_context); + //nsc_context_free(context->nsc_context); -#ifdef CHANNEL_AUDIN_SERVER - if (context->audin) - audin_server_context_free(context->audin); -#endif +#ifdef CHANNEL_AUDIN_SERVER + if (context->audin) + audin_server_context_free(context->audin); +#endif - //#ifdef CHANNEL_RDPSND_SERVER - mf_peer_rdpsnd_stop(); - if (context->rdpsnd) - rdpsnd_server_context_free(context->rdpsnd); - //#endif + //#ifdef CHANNEL_RDPSND_SERVER + mf_peer_rdpsnd_stop(); + if (context->rdpsnd) + rdpsnd_server_context_free(context->rdpsnd); + //#endif - WTSCloseServer(context->vcm); - } -} - -/* Called when a new client connects */ -void mf_peer_init(freerdp_peer* client) -{ - client->ContextSize = sizeof(mfPeerContext); - client->ContextNew = (psPeerContextNew) mf_peer_context_new; - client->ContextFree = (psPeerContextFree) mf_peer_context_free; - freerdp_peer_context_new(client); + WTSCloseServer(context->vcm); + } +} + +/* Called when a new client connects */ +void mf_peer_init(freerdp_peer* client) +{ + client->ContextSize = sizeof(mfPeerContext); + client->ContextNew = (psPeerContextNew) mf_peer_context_new; + client->ContextFree = (psPeerContextFree) mf_peer_context_free; + freerdp_peer_context_new(client); - info_event_queue = mf_event_queue_new(); + info_event_queue = mf_event_queue_new(); - info_queue = dispatch_queue_create("FreeRDP.update.timer", DISPATCH_QUEUE_SERIAL); - info_timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, info_queue); + info_queue = dispatch_queue_create("FreeRDP.update.timer", DISPATCH_QUEUE_SERIAL); + info_timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, info_queue); if(info_timer) - { - //DEBUG_WARN( "created timer\n"); - dispatch_source_set_timer(info_timer, DISPATCH_TIME_NOW, 42ull * NSEC_PER_MSEC, 100ull * NSEC_PER_MSEC); - dispatch_source_set_event_handler(info_timer, ^{ - //DEBUG_WARN( "dispatch\n"); - mfEvent* event = mf_event_new(MF_EVENT_TYPE_FRAME_TICK); + { + //WLog_ERR(TAG, "created timer"); + dispatch_source_set_timer(info_timer, DISPATCH_TIME_NOW, 42ull * NSEC_PER_MSEC, 100ull * NSEC_PER_MSEC); + dispatch_source_set_event_handler(info_timer, ^{ + //WLog_ERR(TAG, "dispatch"); + mfEvent* event = mf_event_new(MF_EVENT_TYPE_FRAME_TICK); mf_event_push(info_event_queue, (mfEvent*) event);} ); - dispatch_resume(info_timer); - } -} - -BOOL mf_peer_post_connect(freerdp_peer* client) -{ - mfPeerContext* context = (mfPeerContext*) client->context; - rdpSettings* settings = client->settings; + dispatch_resume(info_timer); + } +} + +BOOL mf_peer_post_connect(freerdp_peer* client) +{ + mfPeerContext* context = (mfPeerContext*) client->context; + rdpSettings* settings = client->settings; + WLog_INFO(TAG, "Client %s post connect", client->hostname); + + if (client->settings->AutoLogonEnabled) + { + WLog_INFO(TAG, " 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. */ + } + + mfInfo* mfi = mf_info_get_instance(); + mfi->scale = 1; - DEBUG_WARN( "Client %s post connect\n", client->hostname); + //mfi->servscreen_width = 2880 / mfi->scale; + //mfi->servscreen_height = 1800 / mfi->scale; + UINT32 bitsPerPixel = 32; - if (client->settings->AutoLogonEnabled) - { - DEBUG_WARN( " and wants to login automatically as %s\\%s", - client->settings->Domain ? client->settings->Domain : "", - client->settings->Username); + if ((settings->DesktopWidth != mfi->servscreen_width) || (settings->DesktopHeight != mfi->servscreen_height)) + { + WLog_INFO(TAG, "Client requested resolution %dx%d, but will resize to %dx%d", + settings->DesktopWidth, settings->DesktopHeight, mfi->servscreen_width, mfi->servscreen_height); + } + + settings->DesktopWidth = mfi->servscreen_width; + settings->DesktopHeight = mfi->servscreen_height; + settings->ColorDepth = bitsPerPixel; + + client->update->DesktopResize(client->update->context); + + mfi->mouse_down_left = FALSE; + mfi->mouse_down_right = FALSE; + mfi->mouse_down_other = FALSE; + + if (WTSVirtualChannelManagerIsChannelJoined(context->vcm, "rdpsnd")) + { + mf_peer_rdpsnd_init(context); /* Audio Output */ + } + + /* Dynamic Virtual Channels */ + +#ifdef CHANNEL_AUDIN_SERVER + mf_peer_audin_init(context); /* Audio Input */ +#endif + + return TRUE; +} + +BOOL mf_peer_activate(freerdp_peer* client) +{ + mfPeerContext* context = (mfPeerContext*) client->context; + + rfx_context_reset(context->rfx_context); + context->activated = TRUE; + + return TRUE; +} + +void mf_peer_synchronize_event(rdpInput* input, UINT32 flags) +{ + WLog_WARN(TAG, "Client sent a synchronize event (flags:0x%08X)", flags); +} + +void mf_peer_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code) +{ + WLog_INFO(TAG, "Client sent a keyboard event (flags:0x%04X code:0x%04X)", flags, code); + UINT16 down = 0x4000; + //UINT16 up = 0x8000; + + bool state_down = FALSE; + + if (flags == down) + { + state_down = TRUE; + } + + /* + CGEventRef event; + event = CGEventCreateKeyboardEvent(NULL, (CGKeyCode)code, state_down); + CGEventPost(kCGHIDEventTap, event); + CFRelease(event); + */ +} + +void mf_peer_unicode_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code) +{ + WLog_ERR(TAG, "Client sent a unicode keyboard event (flags:0x%04X code:0x%04X)", flags, code); +} + +/*void mf_peer_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y) +{ + //WLog_ERR(TAG, "Client sent a mouse event (flags:0x%04X pos: %d,%d)", flags, x, y); +} + +void mf_peer_extended_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y) +{ + //WLog_ERR(TAG, "Client sent an extended mouse event (flags:0x%04X pos: %d,%d)", flags, x, y); +} +*/ +/*static void mf_peer_refresh_rect(rdpContext* context, BYTE count, RECTANGLE_16* areas) + { + BYTE i; + + WLog_ERR(TAG, "Client requested to refresh:"); + + for (i = 0; i < count; i++) + { + WLog_ERR(TAG, " (%d, %d) (%d, %d)", areas[i].left, areas[i].top, areas[i].right, areas[i].bottom); + } + }*/ + +static void mf_peer_suppress_output(rdpContext* context, BYTE allow, RECTANGLE_16* area) +{ + if (allow > 0) + { + WLog_WARN(TAG, "Client restore output (%d, %d) (%d, %d).", area->left, area->top, area->right, area->bottom); + } + else + { + WLog_WARN(TAG, "Client minimized and suppress output."); + } +} + +void mf_peer_accepted(freerdp_listener* instance, freerdp_peer* client) +{ + pthread_t th; + + pthread_create(&th, 0, mf_peer_main_loop, client); + pthread_detach(th); +} + +void* mf_peer_main_loop(void* arg) +{ + int i; + int fds; + int max_fds; + int rcount; + void* rfds[32]; + fd_set rfds_set; + mfPeerContext* context; + freerdp_peer* client = (freerdp_peer*) arg; + + memset(rfds, 0, sizeof(rfds)); + + mf_peer_init(client); + + /* Initialize the real server settings here */ + client->settings->CertificateFile = _strdup("server.crt"); + client->settings->PrivateKeyFile = _strdup("server.key"); + client->settings->NlaSecurity = FALSE; + client->settings->RemoteFxCodec = TRUE; + client->settings->ColorDepth = 32; + client->settings->SuppressOutput = TRUE; + client->settings->RefreshRect = FALSE; + + client->PostConnect = mf_peer_post_connect; + client->Activate = mf_peer_activate; + + client->input->SynchronizeEvent = mf_peer_synchronize_event; + client->input->KeyboardEvent = mf_input_keyboard_event;//mf_peer_keyboard_event; + client->input->UnicodeKeyboardEvent = mf_peer_unicode_keyboard_event; + client->input->MouseEvent = mf_input_mouse_event; + client->input->ExtendedMouseEvent = mf_input_extended_mouse_event; + + //client->update->RefreshRect = mf_peer_refresh_rect; + client->update->SuppressOutput = mf_peer_suppress_output; + + client->Initialize(client); + context = (mfPeerContext*) client->context; + WLog_INFO(TAG, "We've got a client %s", client->local ? "(local)" : client->hostname); + + while (1) + { + rcount = 0; - /* A real server may perform OS login here if NLA is not executed previously. */ - } - DEBUG_WARN( "\n"); - - mfInfo* mfi = mf_info_get_instance(); - mfi->scale = 1; - - //mfi->servscreen_width = 2880 / mfi->scale; - //mfi->servscreen_height = 1800 / mfi->scale; - UINT32 bitsPerPixel = 32; - - if ((settings->DesktopWidth != mfi->servscreen_width) || (settings->DesktopHeight != mfi->servscreen_height)) - { - DEBUG_WARN( "Client requested resolution %dx%d, but will resize to %dx%d\n", - settings->DesktopWidth, settings->DesktopHeight, mfi->servscreen_width, mfi->servscreen_height); - } - - settings->DesktopWidth = mfi->servscreen_width; - settings->DesktopHeight = mfi->servscreen_height; - settings->ColorDepth = bitsPerPixel; - - client->update->DesktopResize(client->update->context); - - mfi->mouse_down_left = FALSE; - mfi->mouse_down_right = FALSE; - mfi->mouse_down_other = FALSE; - - if (WTSVirtualChannelManagerIsChannelJoined(context->vcm, "rdpsnd")) - { - mf_peer_rdpsnd_init(context); /* Audio Output */ - } - - /* Dynamic Virtual Channels */ - -#ifdef CHANNEL_AUDIN_SERVER - mf_peer_audin_init(context); /* Audio Input */ -#endif - - return TRUE; -} - -BOOL mf_peer_activate(freerdp_peer* client) -{ - mfPeerContext* context = (mfPeerContext*) client->context; - - rfx_context_reset(context->rfx_context); - context->activated = TRUE; - - return TRUE; -} - -void mf_peer_synchronize_event(rdpInput* input, UINT32 flags) -{ - DEBUG_WARN( "Client sent a synchronize event (flags:0x%08X)\n", flags); -} - -void mf_peer_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code) -{ - DEBUG_WARN( "Client sent a keyboard event (flags:0x%04X code:0x%04X)\n", flags, code); - - UINT16 down = 0x4000; - //UINT16 up = 0x8000; - - bool state_down = FALSE; - - if (flags == down) - { - state_down = TRUE; - } - - /* - CGEventRef event; - event = CGEventCreateKeyboardEvent(NULL, (CGKeyCode)code, state_down); - CGEventPost(kCGHIDEventTap, event); - CFRelease(event); - */ -} - -void mf_peer_unicode_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code) -{ - DEBUG_WARN( "Client sent a unicode keyboard event (flags:0x%04X code:0x%04X)\n", flags, code); -} - -/*void mf_peer_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y) -{ - //DEBUG_WARN( "Client sent a mouse event (flags:0x%04X pos: %d,%d)\n", flags, x, y); -} - -void mf_peer_extended_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y) -{ - //DEBUG_WARN( "Client sent an extended mouse event (flags:0x%04X pos: %d,%d)\n", flags, x, y); -} -*/ -/*static void mf_peer_refresh_rect(rdpContext* context, BYTE count, RECTANGLE_16* areas) - { - BYTE i; - - DEBUG_WARN( "Client requested to refresh:\n"); - - for (i = 0; i < count; i++) - { - DEBUG_WARN( " (%d, %d) (%d, %d)\n", areas[i].left, areas[i].top, areas[i].right, areas[i].bottom); - } - }*/ - -static void mf_peer_suppress_output(rdpContext* context, BYTE allow, RECTANGLE_16* area) -{ - if (allow > 0) - { - DEBUG_WARN( "Client restore output (%d, %d) (%d, %d).\n", area->left, area->top, area->right, area->bottom); - } - else - { - DEBUG_WARN( "Client minimized and suppress output.\n"); - } -} - -void mf_peer_accepted(freerdp_listener* instance, freerdp_peer* client) -{ - pthread_t th; - - pthread_create(&th, 0, mf_peer_main_loop, client); - pthread_detach(th); -} - -void* mf_peer_main_loop(void* arg) -{ - int i; - int fds; - int max_fds; - int rcount; - void* rfds[32]; - fd_set rfds_set; - mfPeerContext* context; - freerdp_peer* client = (freerdp_peer*) arg; - - memset(rfds, 0, sizeof(rfds)); - - mf_peer_init(client); - - /* Initialize the real server settings here */ - client->settings->CertificateFile = _strdup("server.crt"); - client->settings->PrivateKeyFile = _strdup("server.key"); - client->settings->NlaSecurity = FALSE; - client->settings->RemoteFxCodec = TRUE; - client->settings->ColorDepth = 32; - client->settings->SuppressOutput = TRUE; - client->settings->RefreshRect = FALSE; - - client->PostConnect = mf_peer_post_connect; - client->Activate = mf_peer_activate; - - client->input->SynchronizeEvent = mf_peer_synchronize_event; - client->input->KeyboardEvent = mf_input_keyboard_event;//mf_peer_keyboard_event; - client->input->UnicodeKeyboardEvent = mf_peer_unicode_keyboard_event; - client->input->MouseEvent = mf_input_mouse_event; - client->input->ExtendedMouseEvent = mf_input_extended_mouse_event; - - //client->update->RefreshRect = mf_peer_refresh_rect; - client->update->SuppressOutput = mf_peer_suppress_output; - - client->Initialize(client); - context = (mfPeerContext*) client->context; - - DEBUG_WARN( "We've got a client %s\n", client->local ? "(local)" : client->hostname); - - while (1) - { - rcount = 0; + if (client->GetFileDescriptor(client, rfds, &rcount) != TRUE) + { + WLog_ERR(TAG, "Failed to get FreeRDP file descriptor"); + break; + } + if (mf_peer_get_fds(client, rfds, &rcount) != TRUE) + { + WLog_ERR(TAG, "Failed to get mfreerdp file descriptor"); + break; + } - if (client->GetFileDescriptor(client, rfds, &rcount) != TRUE) - { - DEBUG_WARN( "Failed to get FreeRDP file descriptor\n"); - break; - } - if (mf_peer_get_fds(client, rfds, &rcount) != TRUE) - { - DEBUG_WARN( "Failed to get mfreerdp file descriptor\n"); - break; - } + WTSVirtualChannelManagerGetFileDescriptor(context->vcm, rfds, &rcount); - WTSVirtualChannelManagerGetFileDescriptor(context->vcm, rfds, &rcount); + max_fds = 0; + FD_ZERO(&rfds_set); - max_fds = 0; - FD_ZERO(&rfds_set); - - for (i = 0; i < rcount; i++) - { - fds = (int)(long)(rfds[i]); + for (i = 0; i < rcount; i++) + { + fds = (int)(long)(rfds[i]); - if (fds > max_fds) - max_fds = fds; + if (fds > max_fds) + max_fds = fds; - FD_SET(fds, &rfds_set); - } + FD_SET(fds, &rfds_set); + } - if (max_fds == 0) - break; + if (max_fds == 0) + break; - if (select(max_fds + 1, &rfds_set, NULL, NULL, NULL) == -1) - { - /* these are not really errors */ - if (!((errno == EAGAIN) || + 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 */ - { - DEBUG_WARN( "select failed\n"); - break; - } - } + { + WLog_ERR(TAG, "select failed"); + break; + } + } - if (client->CheckFileDescriptor(client) != TRUE) - { - DEBUG_WARN( "Failed to check freerdp file descriptor\n"); - break; - } + if (client->CheckFileDescriptor(client) != TRUE) + { + WLog_ERR(TAG, "Failed to check freerdp file descriptor"); + break; + } - if ((mf_peer_check_fds(client)) != TRUE) - { - DEBUG_WARN( "Failed to check mfreerdp file descriptor\n"); - break; - } + if ((mf_peer_check_fds(client)) != TRUE) + { + WLog_ERR(TAG, "Failed to check mfreerdp file descriptor"); + break; + } - if (WTSVirtualChannelManagerCheckFileDescriptor(context->vcm) != TRUE) - { - break; - } - } + if (WTSVirtualChannelManagerCheckFileDescriptor(context->vcm) != TRUE) + { + break; + } + } + + WLog_INFO(TAG, "Client %s disconnected.", client->local ? "(local)" : client->hostname); + client->Disconnect(client); + freerdp_peer_context_free(client); + freerdp_peer_free(client); - DEBUG_WARN( "Client %s disconnected.\n", client->local ? "(local)" : client->hostname); - - client->Disconnect(client); - freerdp_peer_context_free(client); - freerdp_peer_free(client); - - return NULL; -} + return NULL; +} diff --git a/server/Mac/mf_rdpsnd.c b/server/Mac/mf_rdpsnd.c index 5278713ac..4c9cb32d9 100644 --- a/server/Mac/mf_rdpsnd.c +++ b/server/Mac/mf_rdpsnd.c @@ -21,14 +21,14 @@ #include "config.h" #endif -#include -#include - #include #include "mf_info.h" #include "mf_rdpsnd.h" +#include +#define TAG SERVER_TAG("mac") + AQRecorderState recorderState; static const AUDIO_FORMAT supported_audio_formats[] = @@ -46,9 +46,8 @@ static void mf_peer_rdpsnd_activated(RdpsndServerContext* context) //we should actually loop through the list of client formats here //and see if we can send the client something that it supports... - - DEBUG_MSG("Client supports the following %d formats: \n", context->num_client_formats); - + WLog_DBG(TAG, "Client supports the following %d formats: ", context->num_client_formats); + for (i = 0; i < context->num_client_formats; i++) { /* TODO: improve the way we agree on a format */ @@ -58,7 +57,7 @@ static void mf_peer_rdpsnd_activated(RdpsndServerContext* context) (context->client_formats[i].nChannels == context->server_formats[j].nChannels) && (context->client_formats[i].nSamplesPerSec == context->server_formats[j].nSamplesPerSec)) { - DEBUG_MSG("agreed on format!\n"); + WLog_DBG(TAG, "agreed on format!"); formatAgreed = TRUE; agreedFormat = (AUDIO_FORMAT*)&context->server_formats[j]; break; @@ -71,10 +70,10 @@ static void mf_peer_rdpsnd_activated(RdpsndServerContext* context) if (formatAgreed == FALSE) { - DEBUG_MSG("Could not agree on a audio format with the server\n"); + WLog_DBG(TAG, "Could not agree on a audio format with the server"); return; } - + context->SelectFormat(context, i); context->SetVolume(context, 0x7FFF, 0x7FFF); @@ -114,7 +113,7 @@ static void mf_peer_rdpsnd_activated(RdpsndServerContext* context) if (status != noErr) { - DEBUG_MSG("Failed to create a new Audio Queue. Status code: %d\n", status); + WLog_DBG(TAG, "Failed to create a new Audio Queue. Status code: %d", status); } @@ -211,7 +210,7 @@ void mf_peer_rdpsnd_input_callback (void *inUserD if (status != noErr) { - DEBUG_MSG("AudioQueueEnqueueBuffer() returned status = %d\n", status); + WLog_DBG(TAG, "AudioQueueEnqueueBuffer() returned status = %d", status); } } diff --git a/server/Mac/mfreerdp.c b/server/Mac/mfreerdp.c index 1a1092964..982e34461 100644 --- a/server/Mac/mfreerdp.c +++ b/server/Mac/mfreerdp.c @@ -43,6 +43,9 @@ #include "mfreerdp.h" #include "mf_peer.h" +#include +#define TAG SERVER_TAG("mac") + static void mf_server_main_loop(freerdp_listener* instance) { int i; @@ -60,7 +63,7 @@ static void mf_server_main_loop(freerdp_listener* instance) if (instance->GetFileDescriptor(instance, rfds, &rcount) != TRUE) { - DEBUG_WARN( "Failed to get FreeRDP file descriptor\n"); + WLog_ERR(TAG, "Failed to get FreeRDP file descriptor"); break; } @@ -88,14 +91,14 @@ static void mf_server_main_loop(freerdp_listener* instance) (errno == EINPROGRESS) || (errno == EINTR))) /* signal occurred */ { - DEBUG_WARN( "select failed\n"); + WLog_ERR(TAG, "select failed"); break; } } if (instance->CheckFileDescriptor(instance) != TRUE) { - DEBUG_WARN( "Failed to check FreeRDP file descriptor\n"); + WLog_ERR(TAG, "Failed to check FreeRDP file descriptor"); break; } } diff --git a/server/Sample/sf_audin.c b/server/Sample/sf_audin.c index 5edc16357..1fdf0f1fe 100644 --- a/server/Sample/sf_audin.c +++ b/server/Sample/sf_audin.c @@ -21,12 +21,15 @@ #include "config.h" #endif -#include + #include "sfreerdp.h" #include "sf_audin.h" +#include +#define TAG SERVER_TAG("sample") + static const AUDIO_FORMAT test_audio_formats[] = { { WAVE_FORMAT_PCM, 2, 44100, 176400, 4, 16, 0, NULL }, @@ -35,19 +38,19 @@ static const AUDIO_FORMAT test_audio_formats[] = static void sf_peer_audin_opening(audin_server_context* context) { - DEBUG_MSG("AUDIN opening.\n"); + WLog_DBG(TAG, "AUDIN opening."); /* Simply choose the first format supported by the client. */ context->SelectFormat(context, 0); } static void sf_peer_audin_open_result(audin_server_context* context, UINT32 result) { - DEBUG_MSG("AUDIN open result %d.\n", result); + WLog_DBG(TAG, "AUDIN open result %d.", result); } static void sf_peer_audin_receive_samples(audin_server_context* context, const void* buf, int nframes) { - DEBUG_MSG("AUDIN receive %d frames.\n", nframes); + WLog_DBG(TAG, "AUDIN receive %d frames.", nframes); } void sf_peer_audin_init(testPeerContext* context) diff --git a/server/Sample/sf_rdpsnd.c b/server/Sample/sf_rdpsnd.c index 3b5ee0126..0475b9f9a 100644 --- a/server/Sample/sf_rdpsnd.c +++ b/server/Sample/sf_rdpsnd.c @@ -22,10 +22,13 @@ #endif #include -#include + #include "sf_rdpsnd.h" +#include +#define TAG SERVER_TAG("sample") + static const AUDIO_FORMAT test_audio_formats[] = { { WAVE_FORMAT_PCM, 2, 44100, 176400, 4, 16, 0, NULL }, @@ -34,7 +37,7 @@ static const AUDIO_FORMAT test_audio_formats[] = static void sf_peer_rdpsnd_activated(RdpsndServerContext* context) { - DEBUG_MSG("RDPSND Activated\n"); + WLog_DBG(TAG, "RDPSND Activated"); } BOOL sf_peer_rdpsnd_init(testPeerContext* context) diff --git a/server/Sample/sfreerdp.c b/server/Sample/sfreerdp.c index 784bba1e2..c39b9566c 100644 --- a/server/Sample/sfreerdp.c +++ b/server/Sample/sfreerdp.c @@ -33,7 +33,7 @@ #include #include -#include + #include #include @@ -45,6 +45,9 @@ #include "sfreerdp.h" +#include +#define TAG SERVER_TAG("sample") + #define SAMPLE_SERVER_USE_CLIENT_RESOLUTION 1 #define SAMPLE_SERVER_DEFAULT_WIDTH 1024 #define SAMPLE_SERVER_DEFAULT_HEIGHT 768 @@ -342,7 +345,7 @@ static BOOL test_sleep_tsdiff(UINT32 *old_sec, UINT32 *old_usec, UINT32 new_sec, if ((sec < 0) || ((sec == 0) && (usec < 0))) { - DEBUG_MSG("Invalid time stamp detected.\n"); + WLog_ERR(TAG, "Invalid time stamp detected."); return FALSE; } @@ -451,8 +454,7 @@ static void* tf_debug_channel_thread_func(void* arg) } Stream_SetPosition(s, BytesReturned); - - DEBUG_MSG("got %lu bytes\n", BytesReturned); + WLog_DBG(TAG, "got %lu bytes", BytesReturned); } Stream_Free(s, TRUE); @@ -470,31 +472,28 @@ BOOL tf_peer_post_connect(freerdp_peer* client) * The server may start sending graphics output and receiving keyboard/mouse input after this * callback returns. */ - - DEBUG_MSG("Client %s is activated (osMajorType %d osMinorType %d)", client->local ? "(local)" : client->hostname, - client->settings->OsMajorType, client->settings->OsMinorType); + WLog_DBG(TAG, "Client %s is activated (osMajorType %d osMinorType %d)", client->local ? "(local)" : client->hostname, + client->settings->OsMajorType, client->settings->OsMinorType); if (client->settings->AutoLogonEnabled) { - DEBUG_MSG(" and wants to login automatically as %s\\%s", - client->settings->Domain ? client->settings->Domain : "", - client->settings->Username); - + WLog_DBG(TAG, " 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. */ } - DEBUG_MSG("\n"); - - DEBUG_MSG("Client requested desktop: %dx%dx%d\n", - client->settings->DesktopWidth, client->settings->DesktopHeight, client->settings->ColorDepth); + WLog_DBG(TAG, ""); + WLog_DBG(TAG, "Client requested desktop: %dx%dx%d", + client->settings->DesktopWidth, client->settings->DesktopHeight, client->settings->ColorDepth); #if (SAMPLE_SERVER_USE_CLIENT_RESOLUTION == 1) context->rfx_context->width = client->settings->DesktopWidth; context->rfx_context->height = client->settings->DesktopHeight; - DEBUG_MSG("Using resolution requested by client.\n"); + WLog_DBG(TAG, "Using resolution requested by client."); #else client->settings->DesktopWidth = context->rfx_context->width; client->settings->DesktopHeight = context->rfx_context->height; - DEBUG_MSG("Resizing client to %dx%d\n", client->settings->DesktopWidth, client->settings->DesktopHeight); + WLog_DBG(TAG, "Resizing client to %dx%d", client->settings->DesktopWidth, client->settings->DesktopHeight); client->update->DesktopResize(client->update->context); #endif @@ -507,8 +506,7 @@ BOOL tf_peer_post_connect(freerdp_peer* client) if (context->debug_channel != NULL) { - DEBUG_MSG("Open channel rdpdbg.\n"); - + WLog_DBG(TAG, "Open channel rdpdbg."); context->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL); context->debug_channel_thread = CreateThread(NULL, 0, @@ -562,7 +560,7 @@ BOOL tf_peer_activate(freerdp_peer* client) void tf_peer_synchronize_event(rdpInput* input, UINT32 flags) { - DEBUG_MSG("Client sent a synchronize event (flags:0x%X)\n", flags); + WLog_DBG(TAG, "Client sent a synchronize event (flags:0x%X)", flags); } void tf_peer_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code) @@ -570,8 +568,7 @@ void tf_peer_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code) freerdp_peer* client = input->context->peer; rdpUpdate* update = client->update; testPeerContext* context = (testPeerContext*) input->context; - - DEBUG_MSG("Client sent a keyboard event (flags:0x%X code:0x%X)\n", flags, code); + WLog_DBG(TAG, "Client sent a keyboard event (flags:0x%X code:0x%X)", flags, code); if ((flags & 0x4000) && code == 0x22) /* 'g' key */ { @@ -623,30 +620,28 @@ void tf_peer_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code) void tf_peer_unicode_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code) { - DEBUG_MSG("Client sent a unicode keyboard event (flags:0x%X code:0x%X)\n", flags, code); + WLog_DBG(TAG, "Client sent a unicode keyboard event (flags:0x%X code:0x%X)", flags, code); } void tf_peer_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y) { - //printf("Client sent a mouse event (flags:0x%X pos:%d,%d)\n", flags, x, y); - + //WLog_DBG(TAG, "Client sent a mouse event (flags:0x%X pos:%d,%d)", flags, x, y); test_peer_draw_icon(input->context->peer, x + 10, y); } void tf_peer_extended_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y) { - //printf("Client sent an extended mouse event (flags:0x%X pos:%d,%d)\n", flags, x, y); + //WLog_DBG(TAG, "Client sent an extended mouse event (flags:0x%X pos:%d,%d)", flags, x, y); } static void tf_peer_refresh_rect(rdpContext* context, BYTE count, RECTANGLE_16* areas) { BYTE i; - - DEBUG_MSG("Client requested to refresh:\n"); + WLog_DBG(TAG, "Client requested to refresh:"); for (i = 0; i < count; i++) { - DEBUG_MSG(" (%d, %d) (%d, %d)\n", areas[i].left, areas[i].top, areas[i].right, areas[i].bottom); + WLog_DBG(TAG, " (%d, %d) (%d, %d)", areas[i].left, areas[i].top, areas[i].right, areas[i].bottom); } } @@ -654,11 +649,11 @@ static void tf_peer_suppress_output(rdpContext* context, BYTE allow, RECTANGLE_1 { if (allow > 0) { - DEBUG_MSG("Client restore output (%d, %d) (%d, %d).\n", area->left, area->top, area->right, area->bottom); + WLog_DBG(TAG, "Client restore output (%d, %d) (%d, %d).", area->left, area->top, area->right, area->bottom); } else { - DEBUG_MSG("Client minimized and suppress output.\n"); + WLog_DBG(TAG, "Client minimized and suppress output."); } } @@ -700,8 +695,7 @@ static void* test_peer_mainloop(void* arg) client->Initialize(client); context = (testPeerContext*) client->context; - - DEBUG_MSG("We've got a client %s\n", client->local ? "(local)" : client->hostname); + WLog_INFO(TAG, "We've got a client %s", client->local ? "(local)" : client->hostname); while (1) { @@ -710,7 +704,7 @@ static void* test_peer_mainloop(void* arg) memset(rfds, 0, sizeof(rfds)); if (client->GetFileDescriptor(client, rfds, &rcount) != TRUE) { - DEBUG_MSG("Failed to get FreeRDP file descriptor\n"); + WLog_ERR(TAG, "Failed to get FreeRDP file descriptor"); break; } @@ -744,7 +738,7 @@ static void* test_peer_mainloop(void* arg) (wsa_error == WSAEINPROGRESS) || (wsa_error == WSAEINTR))) { - DEBUG_MSG("select failed (WSAGetLastError: %d)\n", wsa_error); + WLog_ERR(TAG, "select failed (WSAGetLastError: %d)", wsa_error); break; } #else @@ -754,7 +748,7 @@ static void* test_peer_mainloop(void* arg) (errno == EINPROGRESS) || (errno == EINTR))) /* signal occurred */ { - DEBUG_MSG("select failed (errno: %d)\n", errno); + WLog_ERR(TAG, "select failed (errno: %d)", errno); break; } #endif @@ -767,8 +761,7 @@ static void* test_peer_mainloop(void* arg) break; } - DEBUG_MSG("Client %s disconnected.\n", client->local ? "(local)" : client->hostname); - + WLog_INFO(TAG, "Client %s disconnected.", client->local ? "(local)" : client->hostname); client->Disconnect(client); freerdp_peer_context_free(client); freerdp_peer_free(client); @@ -800,7 +793,7 @@ static void test_server_mainloop(freerdp_listener* instance) memset(rfds, 0, sizeof(rfds)); if (instance->GetFileDescriptor(instance, rfds, &rcount) != TRUE) { - DEBUG_MSG("Failed to get FreeRDP file descriptor\n"); + WLog_ERR(TAG, "Failed to get FreeRDP file descriptor"); break; } @@ -828,14 +821,14 @@ static void test_server_mainloop(freerdp_listener* instance) (errno == EINPROGRESS) || (errno == EINTR))) /* signal occurred */ { - DEBUG_MSG("select failed\n"); + WLog_ERR(TAG, "select failed"); break; } } if (instance->CheckFileDescriptor(instance) != TRUE) { - DEBUG_MSG("Failed to check FreeRDP file descriptor\n"); + WLog_ERR(TAG, "Failed to check FreeRDP file descriptor"); break; } } diff --git a/server/Windows/cli/wfreerdp.c b/server/Windows/cli/wfreerdp.c index 48a5cd900..5599d13b1 100644 --- a/server/Windows/cli/wfreerdp.c +++ b/server/Windows/cli/wfreerdp.c @@ -32,14 +32,16 @@ #include "wfreerdp.h" +#include +#define TAG SERVER_TAG("windows") + int IDcount = 0; BOOL CALLBACK moncb(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData) { - DEBUG_MSG("%d\t(%d, %d), (%d, %d)\n", - IDcount, lprcMonitor->left, lprcMonitor->top, - lprcMonitor->right, lprcMonitor->bottom); - + WLog_DBG(TAG, "%d\t(%d, %d), (%d, %d)", + IDcount, lprcMonitor->left, lprcMonitor->top, + lprcMonitor->right, lprcMonitor->bottom); IDcount++; return TRUE; @@ -67,10 +69,9 @@ int main(int argc, char* argv[]) int height; int bpp; int i; + WLog_INFO(TAG, "Detecting screens..."); + WLog_INFO(TAG, "ID\tResolution\t\tName (Interface)"); - _tprintf(_T("Detecting screens...\n")); - _tprintf(_T("\nID\tResolution\t\tName (Interface)\n\n")); - for (i=0; ; i++) { if (get_screen_info(i, name, &width, &height, &bpp) != 0) @@ -78,8 +79,8 @@ int main(int argc, char* argv[]) if ( (width * height * bpp) == 0 ) continue; - _tprintf(_T("%d\t%dx%dx%d\t"), i, width, height, bpp); - _tprintf(_T("%s\n"), name); + WLog_INFO(TAG, "%d\t%dx%dx%d\t", i, width, height, bpp); + WLog_INFO(TAG, "%s", name); } else { @@ -92,11 +93,10 @@ int main(int argc, char* argv[]) int vscreen_h; vscreen_w = GetSystemMetrics(SM_CXVIRTUALSCREEN); vscreen_h = GetSystemMetrics(SM_CYVIRTUALSCREEN); - - DEBUG_MSG("\n"); + WLog_INFO(TAG, ""); EnumDisplayMonitors(NULL, NULL, moncb, 0); IDcount = 0; - DEBUG_MSG("\nVirtual Screen = %dx%d\n", vscreen_w, vscreen_h); + WLog_INFO(TAG, "Virtual Screen = %dx%d", vscreen_w, vscreen_h); } return 0; @@ -108,7 +108,7 @@ int main(int argc, char* argv[]) index++; if (index == argc) { - DEBUG_MSG("missing screen id parameter\n"); + WLog_INFO(TAG, "missing screen id parameter"); return 0; } @@ -130,10 +130,9 @@ int main(int argc, char* argv[]) int height; int bpp; int i; - - _tprintf(_T("screen id not provided. attempting to detect...\n")); - _tprintf(_T("Detecting screens...\n")); - _tprintf(_T("\nID\tResolution\t\tName (Interface)\n\n")); + WLog_INFO(TAG, "screen id not provided. attempting to detect..."); + WLog_INFO(TAG, "Detecting screens..."); + WLog_INFO(TAG, "ID\tResolution\t\tName (Interface)"); for (i=0; ; i++) { @@ -142,8 +141,8 @@ int main(int argc, char* argv[]) if ( (width * height * bpp) == 0 ) continue; - _tprintf(_T("%d\t%dx%dx%d\t"), i, width, height, bpp); - _tprintf(_T("%s\n"), name); + WLog_INFO(TAG, "%d\t%dx%dx%d\t", i, width, height, bpp); + WLog_INFO(TAG, "%s", name); set_screen_id(i); break; } @@ -154,14 +153,11 @@ int main(int argc, char* argv[]) } } - DEBUG_MSG("Starting server\n"); - + WLog_INFO(TAG, "Starting server"); wfreerdp_server_start(server); WaitForSingleObject(server->thread, INFINITE); - - DEBUG_MSG("Stopping server\n"); - + WLog_INFO(TAG, "Stopping server"); wfreerdp_server_stop(server); wfreerdp_server_free(server); diff --git a/server/Windows/wf_directsound.c b/server/Windows/wf_directsound.c index 74c66adb9..37c31205d 100644 --- a/server/Windows/wf_directsound.c +++ b/server/Windows/wf_directsound.c @@ -14,6 +14,9 @@ #include #include +#include +#define TAG SERVER_TAG("windows") + IDirectSoundCapture8* cap; IDirectSoundCaptureBuffer8* capBuf; DSCBUFFERDESC dscbd; @@ -34,18 +37,16 @@ int wf_directsound_activate(RdpsndServerContext* context) LPDIRECTSOUNDCAPTUREBUFFER pDSCB; wfi = wf_info_get_instance(); - - DEBUG_MSG("RDPSND (direct sound) Activated\n"); - + WLog_DBG(TAG, "RDPSND (direct sound) Activated"); hr = DirectSoundCaptureCreate8(NULL, &cap, NULL); if (FAILED(hr)) { - _tprintf(_T("Failed to create sound capture device\n")); + WLog_ERR(TAG, "Failed to create sound capture device"); return 1; } - _tprintf(_T("Created sound capture device\n")); + WLog_INFO(TAG, "Created sound capture device"); dscbd.dwSize = sizeof(DSCBUFFERDESC); dscbd.dwFlags = 0; dscbd.dwBufferBytes = wfi->agreed_format->nAvgBytesPerSec; @@ -58,18 +59,17 @@ int wf_directsound_activate(RdpsndServerContext* context) if (FAILED(hr)) { - _tprintf(_T("Failed to create capture buffer\n")); + WLog_ERR(TAG, "Failed to create capture buffer"); } - _tprintf(_T("Created capture buffer")); + WLog_INFO(TAG, "Created capture buffer"); hr = pDSCB->lpVtbl->QueryInterface(pDSCB, &IID_IDirectSoundCaptureBuffer8, (LPVOID*)&capBuf); if (FAILED(hr)) { - _tprintf(_T("Failed to QI capture buffer\n")); + WLog_ERR(TAG, "Failed to QI capture buffer"); } - _tprintf(_T("Created IDirectSoundCaptureBuffer8\n")); - pDSCB->lpVtbl->Release(pDSCB); - + WLog_INFO(TAG, "Created IDirectSoundCaptureBuffer8"); + pDSCB->lpVtbl->Release(pDSCB); lastPos = 0; CreateThread(NULL, 0, wf_rdpsnd_directsound_thread, latestPeer, 0, NULL); @@ -98,14 +98,13 @@ DWORD WINAPI wf_rdpsnd_directsound_thread(LPVOID lpParam) context = (wfPeerContext*)lpParam; rate = 1000 / 24; - - _tprintf(_T("Trying to start capture\n")); + WLog_INFO(TAG, "Trying to start capture"); hr = capBuf->lpVtbl->Start(capBuf, DSCBSTART_LOOPING); if (FAILED(hr)) { - _tprintf(_T("Failed to start capture\n")); + WLog_ERR(TAG, "Failed to start capture"); } - _tprintf(_T("Capture started\n")); + WLog_INFO(TAG, "Capture started"); while (1) { @@ -132,7 +131,7 @@ DWORD WINAPI wf_rdpsnd_directsound_thread(LPVOID lpParam) hr = capBuf->lpVtbl->GetCurrentPosition(capBuf, NULL, &dwReadPos); if (FAILED(hr)) { - _tprintf(_T("Failed to get read pos\n")); + WLog_ERR(TAG, "Failed to get read pos"); wf_rdpsnd_unlock(); break; } @@ -140,9 +139,9 @@ DWORD WINAPI wf_rdpsnd_directsound_thread(LPVOID lpParam) lLockSize = dwReadPos - lastPos;//dscbd.dwBufferBytes; if (lLockSize < 0) lLockSize += dscbd.dwBufferBytes; - //printf("Last, read, lock = [%d, %d, %d]\n", lastPos, dwReadPos, lLockSize); + //WLog_DBG(TAG, "Last, read, lock = [%d, %d, %d]\n", lastPos, dwReadPos, lLockSize); - if (lLockSize == 0) + if (lLockSize == 0) { wf_rdpsnd_unlock(); continue; @@ -152,7 +151,7 @@ DWORD WINAPI wf_rdpsnd_directsound_thread(LPVOID lpParam) hr = capBuf->lpVtbl->Lock(capBuf, lastPos, lLockSize, &pbCaptureData, &dwCaptureLength, &pbCaptureData2, &dwCaptureLength2, 0L); if (FAILED(hr)) { - _tprintf(_T("Failed to lock sound capture buffer\n")); + WLog_ERR(TAG, "Failed to lock sound capture buffer"); wf_rdpsnd_unlock(); break; } @@ -169,7 +168,7 @@ DWORD WINAPI wf_rdpsnd_directsound_thread(LPVOID lpParam) hr = capBuf->lpVtbl->Unlock(capBuf, pbCaptureData, dwCaptureLength, pbCaptureData2, dwCaptureLength2); if (FAILED(hr)) { - _tprintf(_T("Failed to unlock sound capture buffer\n")); + WLog_ERR(TAG, "Failed to unlock sound capture buffer"); wf_rdpsnd_unlock(); return 0; } @@ -186,13 +185,14 @@ DWORD WINAPI wf_rdpsnd_directsound_thread(LPVOID lpParam) } - _tprintf(_T("Trying to stop sound capture\n")); + WLog_INFO(TAG, "Trying to stop sound capture"); hr = capBuf->lpVtbl->Stop(capBuf); if (FAILED(hr)) { - _tprintf(_T("Failed to stop capture\n")); + WLog_ERR(TAG, "Failed to stop capture"); } - _tprintf(_T("Capture stopped\n")); + + WLog_INFO(TAG, "Capture stopped"); capBuf->lpVtbl->Release(capBuf); cap->lpVtbl->Release(cap); diff --git a/server/Windows/wf_dxgi.c b/server/Windows/wf_dxgi.c index fdaacca2d..a2801f665 100644 --- a/server/Windows/wf_dxgi.c +++ b/server/Windows/wf_dxgi.c @@ -33,6 +33,9 @@ #include #include "wf_dxgi.h" +#include +#define TAG SERVER_TAG("windows") + /* Driver types supported */ D3D_DRIVER_TYPE DriverTypes[] = { @@ -94,12 +97,12 @@ int wf_dxgi_createDevice(wfInfo* wfi) if (SUCCEEDED(status)) break; - _tprintf(_T("D3D11CreateDevice returned [%d] for Driver Type %d\n"), status, DriverTypes[DriverTypeIndex]); + WLog_INFO(TAG, "D3D11CreateDevice returned [%d] for Driver Type %d", status, DriverTypes[DriverTypeIndex]); } if (FAILED(status)) { - _tprintf(_T("Failed to create device in InitializeDx\n")); + WLog_ERR(TAG, "Failed to create device in InitializeDx"); return 1; } @@ -121,7 +124,7 @@ int wf_dxgi_getDuplication(wfInfo* wfi) if (FAILED(status)) { - _tprintf(_T("Failed to get QI for DXGI Device\n")); + WLog_ERR(TAG, "Failed to get QI for DXGI Device"); return 1; } @@ -131,7 +134,7 @@ int wf_dxgi_getDuplication(wfInfo* wfi) if (FAILED(status)) { - _tprintf(_T("Failed to get parent DXGI Adapter\n")); + WLog_ERR(TAG, "Failed to get parent DXGI Adapter"); return 1; } @@ -146,11 +149,11 @@ int wf_dxgi_getDuplication(wfInfo* wfi) if (FAILED(status)) { - _tprintf(_T("Failed to get description\n")); + WLog_ERR(TAG, "Failed to get description"); return 1; } - _tprintf(_T("Output %d: [%s] [%d]\n"), i, pDesc->DeviceName, pDesc->AttachedToDesktop); + WLog_INFO(TAG, "Output %d: [%s] [%d]", i, pDesc->DeviceName, pDesc->AttachedToDesktop); if (pDesc->AttachedToDesktop) dTop = i; @@ -167,7 +170,7 @@ int wf_dxgi_getDuplication(wfInfo* wfi) if (FAILED(status)) { - _tprintf(_T("Failed to get output\n")); + WLog_ERR(TAG, "Failed to get output"); return 1; } @@ -177,7 +180,7 @@ int wf_dxgi_getDuplication(wfInfo* wfi) if (FAILED(status)) { - _tprintf(_T("Failed to get IDXGIOutput1\n")); + WLog_ERR(TAG, "Failed to get IDXGIOutput1"); return 1; } @@ -189,11 +192,11 @@ int wf_dxgi_getDuplication(wfInfo* wfi) { if (status == DXGI_ERROR_NOT_CURRENTLY_AVAILABLE) { - _tprintf(_T("There is already the maximum number of applications using the Desktop Duplication API running, please close one of those applications and then try again.\n")); + WLog_ERR(TAG, "There is already the maximum number of applications using the Desktop Duplication API running, please close one of those applications and then try again.")); return 1; } - - _tprintf(_T("Failed to get duplicate output. Status = %#X\n"), status); + + WLog_ERR(TAG, "Failed to get duplicate output. Status = %#X", status); return 1; } @@ -265,8 +268,9 @@ int wf_dxgi_nextFrame(wfInfo* wfi, UINT timeout) { if (status == DXGI_ERROR_ACCESS_LOST) { - _tprintf(_T("Failed to acquire next frame with status=%#X\n"), status); - _tprintf(_T("Trying to reinitialize due to ACCESS LOST...")); + WLog_ERR(TAG, "Failed to acquire next frame with status=%#X", status); + WLog_ERR(TAG, "Trying to reinitialize due to ACCESS LOST..."); + if (gAcquiredDesktopImage) { gAcquiredDesktopImage->lpVtbl->Release(gAcquiredDesktopImage); @@ -285,13 +289,12 @@ int wf_dxgi_nextFrame(wfInfo* wfi, UINT timeout) } else { - _tprintf(_T("Failed to acquire next frame with status=%#X\n"), status); - + WLog_ERR(TAG, "Failed to acquire next frame with status=%#X", status); status = gOutputDuplication->lpVtbl->ReleaseFrame(gOutputDuplication); if (FAILED(status)) { - _tprintf(_T("Failed to release frame with status=%d\n"), status); + WLog_ERR(TAG, "Failed to release frame with status=%d", status); } return 1; @@ -315,7 +318,7 @@ int wf_dxgi_nextFrame(wfInfo* wfi, UINT timeout) if (FAILED(status)) { - _tprintf(_T("Failed to release frame with status=%d\n"), status); + WLog_ERR(TAG, "Failed to release frame with status=%d", status); } } @@ -352,7 +355,7 @@ int wf_dxgi_getPixelData(wfInfo* wfi, BYTE** data, int* pitch, RECT* invalid) if (FAILED(status)) { - _tprintf(_T("Failed to create staging surface\n")); + WLog_ERR(TAG, "Failed to create staging surface"); exit(1); return 1; } @@ -363,7 +366,7 @@ int wf_dxgi_getPixelData(wfInfo* wfi, BYTE** data, int* pitch, RECT* invalid) if (FAILED(status)) { - _tprintf(_T("Failed to QI staging surface\n")); + WLog_ERR(TAG, "Failed to QI staging surface"); exit(1); return 1; } @@ -372,7 +375,7 @@ int wf_dxgi_getPixelData(wfInfo* wfi, BYTE** data, int* pitch, RECT* invalid) if (FAILED(status)) { - _tprintf(_T("Failed to map staging surface\n")); + WLog_ERR(TAG, "Failed to map staging surface"); exit(1); return 1; } @@ -397,7 +400,7 @@ int wf_dxgi_releasePixelData(wfInfo* wfi) if (FAILED(status)) { - _tprintf(_T("Failed to release frame\n")); + WLog_ERR(TAG, "Failed to release frame"); return 1; } @@ -438,7 +441,7 @@ int wf_dxgi_getInvalidRegion(RECT* invalid) if (!DataBuffer) { DataBufferSize = 0; - _tprintf(_T("Failed to allocate memory for metadata\n")); + WLog_ERR(TAG, "Failed to allocate memory for metadata"); exit(1); } @@ -451,7 +454,7 @@ int wf_dxgi_getInvalidRegion(RECT* invalid) if (FAILED(status)) { - _tprintf(_T("Failed to get frame move rects\n")); + WLog_ERR(TAG, "Failed to get frame move rects"); return 1; } @@ -462,7 +465,7 @@ int wf_dxgi_getInvalidRegion(RECT* invalid) if (FAILED(status)) { - _tprintf(_T("Failed to get frame dirty rects\n")); + WLog_ERR(TAG, "Failed to get frame dirty rects"); return 1; } dirty = BufSize / sizeof(RECT); diff --git a/server/Windows/wf_info.c b/server/Windows/wf_info.c index 4300c5513..f8263e1bb 100644 --- a/server/Windows/wf_info.c +++ b/server/Windows/wf_info.c @@ -1,47 +1,50 @@ -/** -* FreeRDP: A Remote Desktop Protocol Client -* FreeRDP Windows Server -* -* Copyright 2012 Corey Clayton -* -* 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. -*/ +/** +* FreeRDP: A Remote Desktop Protocol Client +* FreeRDP Windows Server +* +* Copyright 2012 Corey Clayton +* +* 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 + +#include +#include + +#include "wf_info.h" +#include "wf_update.h" +#include "wf_mirage.h" +#include "wf_dxgi.h" + +#include +#define TAG SERVER_TAG("windows") + +static wfInfo* wfInfoInstance = NULL; +static int _IDcount = 0; + +int wf_info_lock(wfInfo* wfi) +{ + DWORD dRes; -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include - -#include -#include - -#include "wf_info.h" -#include "wf_update.h" -#include "wf_mirage.h" -#include "wf_dxgi.h" - -static wfInfo* wfInfoInstance = NULL; -static int _IDcount = 0; - -int wf_info_lock(wfInfo* wfi) -{ - DWORD dRes; - - dRes = WaitForSingleObject(wfi->mutex, INFINITE); - - switch (dRes) - { + dRes = WaitForSingleObject(wfi->mutex, INFINITE); + + switch (dRes) + { case WAIT_ABANDONED: case WAIT_OBJECT_0: return TRUE; @@ -52,22 +55,22 @@ int wf_info_lock(wfInfo* wfi) break; case WAIT_FAILED: - DEBUG_WARN("wf_info_lock failed with 0x%08X\n", GetLastError()); + WLog_ERR(TAG, "wf_info_lock failed with 0x%08X", GetLastError()); return -1; break; - } + } + + return -1; +} + +int wf_info_try_lock(wfInfo* wfi, DWORD dwMilliseconds) +{ + DWORD dRes; - return -1; -} - -int wf_info_try_lock(wfInfo* wfi, DWORD dwMilliseconds) -{ - DWORD dRes; - - dRes = WaitForSingleObject(wfi->mutex, dwMilliseconds); - - switch (dRes) - { + dRes = WaitForSingleObject(wfi->mutex, dwMilliseconds); + + switch (dRes) + { case WAIT_ABANDONED: case WAIT_OBJECT_0: return TRUE; @@ -78,293 +81,291 @@ int wf_info_try_lock(wfInfo* wfi, DWORD dwMilliseconds) break; case WAIT_FAILED: - DEBUG_WARN("wf_info_try_lock failed with 0x%08X\n", GetLastError()); + WLog_ERR(TAG, "wf_info_try_lock failed with 0x%08X", GetLastError()); return -1; break; - } + } + + return -1; +} + +int wf_info_unlock(wfInfo* wfi) +{ + if (ReleaseMutex(wfi->mutex) == 0) + { + WLog_ERR(TAG, "wf_info_unlock failed with 0x%08X", GetLastError()); + return -1; + } + + return TRUE; +} + +wfInfo* wf_info_init() +{ + wfInfo* wfi; - return -1; -} - -int wf_info_unlock(wfInfo* wfi) -{ - if (ReleaseMutex(wfi->mutex) == 0) - { - DEBUG_WARN("wf_info_unlock failed with 0x%08X\n", GetLastError()); - return -1; - } - - return TRUE; -} - -wfInfo* wf_info_init() -{ - wfInfo* wfi; - - wfi = (wfInfo*) malloc(sizeof(wfInfo)); - ZeroMemory(wfi, sizeof(wfInfo)); - - if (wfi != NULL) - { - HKEY hKey; - LONG status; - DWORD dwType; - DWORD dwSize; - DWORD dwValue; - - wfi->mutex = CreateMutex(NULL, FALSE, NULL); + wfi = (wfInfo*) malloc(sizeof(wfInfo)); + ZeroMemory(wfi, sizeof(wfInfo)); + + if (wfi != NULL) + { + HKEY hKey; + LONG status; + DWORD dwType; + DWORD dwSize; + DWORD dwValue; + wfi->mutex = CreateMutex(NULL, FALSE, NULL); + if (wfi->mutex == NULL) - { - _tprintf(_T("CreateMutex error: %d\n"), GetLastError()); - } + { + WLog_ERR(TAG, "CreateMutex error: %d", GetLastError()); + } + + wfi->updateSemaphore = CreateSemaphore(NULL, 0, 32, NULL); - wfi->updateSemaphore = CreateSemaphore(NULL, 0, 32, NULL); + wfi->updateThread = CreateThread(NULL, 0, wf_update_thread, wfi, CREATE_SUSPENDED, NULL); + + if (!wfi->updateThread) + { + WLog_ERR(TAG, "Failed to create update thread"); + } + + wfi->peers = (freerdp_peer**) malloc(sizeof(freerdp_peer*) * WF_INFO_MAXPEERS); + memset(wfi->peers, 0, sizeof(freerdp_peer*) * WF_INFO_MAXPEERS); - wfi->updateThread = CreateThread(NULL, 0, wf_update_thread, wfi, CREATE_SUSPENDED, NULL); + //Set FPS + wfi->framesPerSecond = WF_INFO_DEFAULT_FPS; - if (!wfi->updateThread) - { - _tprintf(_T("Failed to create update thread\n")); - } - - wfi->peers = (freerdp_peer**) malloc(sizeof(freerdp_peer*) * WF_INFO_MAXPEERS); - memset(wfi->peers, 0, sizeof(freerdp_peer*) * WF_INFO_MAXPEERS); - - //Set FPS - wfi->framesPerSecond = WF_INFO_DEFAULT_FPS; - - 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) + 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); + + //Set input toggle + wfi->input_disabled = FALSE; - //Set input toggle - wfi->input_disabled = FALSE; - - status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("Software\\FreeRDP\\Server"), 0, KEY_READ | KEY_WOW64_64KEY, &hKey); - if (status == ERROR_SUCCESS) - { - if (RegQueryValueEx(hKey, _T("DisableInput"), NULL, &dwType, (BYTE*) &dwValue, &dwSize) == ERROR_SUCCESS) - { - if (dwValue != 0) - wfi->input_disabled = TRUE; - } - } - RegCloseKey(hKey); - } - - return wfi; -} - -wfInfo* wf_info_get_instance() -{ - if (wfInfoInstance == NULL) - wfInfoInstance = wf_info_init(); - - return wfInfoInstance; -} - -void wf_info_peer_register(wfInfo* wfi, wfPeerContext* context) -{ - if (wf_info_lock(wfi) > 0) - { - int i; - int peerId; - if (wfi->peerCount == WF_INFO_MAXPEERS) - { - context->socketClose = TRUE; - wf_info_unlock(wfi); - return; - } - - context->info = wfi; - context->updateEvent = CreateEvent(NULL, TRUE, FALSE, NULL); - - //get the offset of the top left corner of selected screen - EnumDisplayMonitors(NULL, NULL, wf_info_monEnumCB, 0); - _IDcount = 0; + status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("Software\\FreeRDP\\Server"), 0, KEY_READ | KEY_WOW64_64KEY, &hKey); + if (status == ERROR_SUCCESS) + { + if (RegQueryValueEx(hKey, _T("DisableInput"), NULL, &dwType, (BYTE*) &dwValue, &dwSize) == ERROR_SUCCESS) + { + if (dwValue != 0) + wfi->input_disabled = TRUE; + } + } + RegCloseKey(hKey); + } + + return wfi; +} + +wfInfo* wf_info_get_instance() +{ + if (wfInfoInstance == NULL) + wfInfoInstance = wf_info_init(); + + return wfInfoInstance; +} + +void wf_info_peer_register(wfInfo* wfi, wfPeerContext* context) +{ + if (wf_info_lock(wfi) > 0) + { + int i; + int peerId; + if (wfi->peerCount == WF_INFO_MAXPEERS) + { + context->socketClose = TRUE; + wf_info_unlock(wfi); + return; + } + + context->info = wfi; + context->updateEvent = CreateEvent(NULL, TRUE, FALSE, NULL); + //get the offset of the top left corner of selected screen + EnumDisplayMonitors(NULL, NULL, wf_info_monEnumCB, 0); + _IDcount = 0; + #ifdef WITH_DXGI_1_2 - if (wfi->peerCount == 0) - wf_dxgi_init(wfi); -#else - if (wf_mirror_driver_activate(wfi) == FALSE) - { - context->socketClose = TRUE; - wf_info_unlock(wfi); - return; - } -#endif - //look trhough the array of peers until an empty slot + if (wfi->peerCount == 0) + wf_dxgi_init(wfi); +#else + if (wf_mirror_driver_activate(wfi) == FALSE) + { + context->socketClose = TRUE; + wf_info_unlock(wfi); + return; + } +#endif + //look trhough the array of peers until an empty slot for(i=0; ipeers[i] == NULL) - { - peerId = i; - break; - } - } + { + //empty index will be our peer id + if (wfi->peers[i] == NULL) + { + peerId = i; + break; + } + } + + wfi->peers[peerId] = ((rdpContext*) context)->peer; + wfi->peers[peerId]->pId = peerId; + wfi->peerCount++; + WLog_INFO(TAG, "Registering Peer: id=%d #=%d", peerId, wfi->peerCount); + wf_info_unlock(wfi); - wfi->peers[peerId] = ((rdpContext*) context)->peer; - wfi->peers[peerId]->pId = peerId; - wfi->peerCount++; - DEBUG_WARN("Registering Peer: id=%d #=%d\n", peerId, wfi->peerCount); + wfreerdp_server_peer_callback_event(peerId, WF_SRV_CALLBACK_EVENT_CONNECT); + } +} + +void wf_info_peer_unregister(wfInfo* wfi, wfPeerContext* context) +{ + if (wf_info_lock(wfi) > 0) + { + int peerId; - wf_info_unlock(wfi); + peerId = ((rdpContext*) context)->peer->pId; + wfi->peers[peerId] = NULL; + wfi->peerCount--; + CloseHandle(context->updateEvent); + WLog_INFO(TAG, "Unregistering Peer: id=%d, #=%d", peerId, wfi->peerCount); + +#ifdef WITH_DXGI_1_2 + if (wfi->peerCount == 0) + wf_dxgi_cleanup(wfi); +#endif + + wf_info_unlock(wfi); - wfreerdp_server_peer_callback_event(peerId, WF_SRV_CALLBACK_EVENT_CONNECT); - } -} - -void wf_info_peer_unregister(wfInfo* wfi, wfPeerContext* context) -{ - if (wf_info_lock(wfi) > 0) - { - int peerId; - - peerId = ((rdpContext*) context)->peer->pId; - wfi->peers[peerId] = NULL; - wfi->peerCount--; - CloseHandle(context->updateEvent); - - DEBUG_WARN("Unregistering Peer: id=%d, #=%d\n", peerId, wfi->peerCount); - -#ifdef WITH_DXGI_1_2 - if (wfi->peerCount == 0) - wf_dxgi_cleanup(wfi); -#endif - - wf_info_unlock(wfi); - - wfreerdp_server_peer_callback_event(peerId, WF_SRV_CALLBACK_EVENT_DISCONNECT); - } -} - -BOOL wf_info_have_updates(wfInfo* wfi) -{ + wfreerdp_server_peer_callback_event(peerId, WF_SRV_CALLBACK_EVENT_DISCONNECT); + } +} + +BOOL wf_info_have_updates(wfInfo* wfi) +{ #ifdef WITH_DXGI_1_2 if(wfi->framesWaiting == 0) - return FALSE; -#else - if (wfi->nextUpdate == wfi->lastUpdate) - return FALSE; -#endif - return TRUE; -} - -void wf_info_update_changes(wfInfo* wfi) -{ + return FALSE; +#else + if (wfi->nextUpdate == wfi->lastUpdate) + return FALSE; +#endif + return TRUE; +} + +void wf_info_update_changes(wfInfo* wfi) +{ #ifdef WITH_DXGI_1_2 - wf_dxgi_nextFrame(wfi, wfi->framesPerSecond * 1000); -#else - GETCHANGESBUF* buf; + wf_dxgi_nextFrame(wfi, wfi->framesPerSecond * 1000); +#else + GETCHANGESBUF* buf; - buf = (GETCHANGESBUF*) wfi->changeBuffer; - wfi->nextUpdate = buf->buffer->counter; -#endif -} - -void wf_info_find_invalid_region(wfInfo* wfi) -{ + buf = (GETCHANGESBUF*) wfi->changeBuffer; + wfi->nextUpdate = buf->buffer->counter; +#endif +} + +void wf_info_find_invalid_region(wfInfo* wfi) +{ #ifdef WITH_DXGI_1_2 - wf_dxgi_getInvalidRegion(&wfi->invalid); -#else - int i; - GETCHANGESBUF* buf; + wf_dxgi_getInvalidRegion(&wfi->invalid); +#else + int i; + GETCHANGESBUF* buf; - buf = (GETCHANGESBUF*) wfi->changeBuffer; - - for (i = wfi->lastUpdate; i != wfi->nextUpdate; i = (i + 1) % MAXCHANGES_BUF) - { - LPRECT lpR = &buf->buffer->pointrect[i].rect; - - //need to make sure we only get updates from the selected screen + buf = (GETCHANGESBUF*) wfi->changeBuffer; + + for (i = wfi->lastUpdate; i != wfi->nextUpdate; i = (i + 1) % MAXCHANGES_BUF) + { + LPRECT lpR = &buf->buffer->pointrect[i].rect; + + //need to make sure we only get updates from the selected screen if ( (lpR->left >= wfi->servscreen_xoffset) && (lpR->right <= (wfi->servscreen_xoffset + wfi->servscreen_width) ) && (lpR->top >= wfi->servscreen_yoffset) && (lpR->bottom <= (wfi->servscreen_yoffset + wfi->servscreen_height) ) ) - { - UnionRect(&wfi->invalid, &wfi->invalid, lpR); - } - else - { - continue; - } - } -#endif - - if (wfi->invalid.left < 0) - wfi->invalid.left = 0; - - if (wfi->invalid.top < 0) - wfi->invalid.top = 0; - - if (wfi->invalid.right >= wfi->servscreen_width) - wfi->invalid.right = wfi->servscreen_width - 1; - - if (wfi->invalid.bottom >= wfi->servscreen_height) - wfi->invalid.bottom = wfi->servscreen_height - 1; - - //printf("invalid region: (%d, %d), (%d, %d)\n", wfi->invalid.left, wfi->invalid.top, wfi->invalid.right, wfi->invalid.bottom); -} - -void wf_info_clear_invalid_region(wfInfo* wfi) -{ - wfi->lastUpdate = wfi->nextUpdate; - SetRectEmpty(&wfi->invalid); -} - -void wf_info_invalidate_full_screen(wfInfo* wfi) -{ - SetRect(&wfi->invalid, 0, 0, wfi->servscreen_width, wfi->servscreen_height); -} - -BOOL wf_info_have_invalid_region(wfInfo* wfi) -{ - return IsRectEmpty(&wfi->invalid); -} - -void wf_info_getScreenData(wfInfo* wfi, long* width, long* height, BYTE** pBits, int* pitch) -{ - *width = (wfi->invalid.right - wfi->invalid.left); - *height = (wfi->invalid.bottom - wfi->invalid.top); + { + UnionRect(&wfi->invalid, &wfi->invalid, lpR); + } + else + { + continue; + } + } +#endif + + if (wfi->invalid.left < 0) + wfi->invalid.left = 0; + + if (wfi->invalid.top < 0) + wfi->invalid.top = 0; + + if (wfi->invalid.right >= wfi->servscreen_width) + wfi->invalid.right = wfi->servscreen_width - 1; + + if (wfi->invalid.bottom >= wfi->servscreen_height) + wfi->invalid.bottom = wfi->servscreen_height - 1; + + //WLog_DBG(TAG, "invalid region: (%d, %d), (%d, %d)", wfi->invalid.left, wfi->invalid.top, wfi->invalid.right, wfi->invalid.bottom); +} + +void wf_info_clear_invalid_region(wfInfo* wfi) +{ + wfi->lastUpdate = wfi->nextUpdate; + SetRectEmpty(&wfi->invalid); +} + +void wf_info_invalidate_full_screen(wfInfo* wfi) +{ + SetRect(&wfi->invalid, 0, 0, wfi->servscreen_width, wfi->servscreen_height); +} + +BOOL wf_info_have_invalid_region(wfInfo* wfi) +{ + return IsRectEmpty(&wfi->invalid); +} + +void wf_info_getScreenData(wfInfo* wfi, long* width, long* height, BYTE** pBits, int* pitch) +{ + *width = (wfi->invalid.right - wfi->invalid.left); + *height = (wfi->invalid.bottom - wfi->invalid.top); #ifdef WITH_DXGI_1_2 - wf_dxgi_getPixelData(wfi, pBits, pitch, &wfi->invalid); -#else - { - long offset; - GETCHANGESBUF* changes; - changes = (GETCHANGESBUF*) wfi->changeBuffer; + wf_dxgi_getPixelData(wfi, pBits, pitch, &wfi->invalid); +#else + { + long offset; + GETCHANGESBUF* changes; + changes = (GETCHANGESBUF*) wfi->changeBuffer; - *width += 1; - *height += 1; + *width += 1; + *height += 1; - offset = (4 * wfi->invalid.left) + (wfi->invalid.top * wfi->virtscreen_width * 4); + offset = (4 * wfi->invalid.left) + (wfi->invalid.top * wfi->virtscreen_width * 4); *pBits = ((BYTE*) (changes->Userbuffer)) + offset; - *pitch = wfi->virtscreen_width * 4; - } -#endif -} - -BOOL CALLBACK wf_info_monEnumCB(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData) -{ + *pitch = wfi->virtscreen_width * 4; + } +#endif +} + +BOOL CALLBACK wf_info_monEnumCB(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData) +{ wfInfo * wfi; - wfi = wf_info_get_instance(); - + wfi = wf_info_get_instance(); + if(_IDcount == wfi->screenID) - { - wfi->servscreen_xoffset = lprcMonitor->left; - wfi->servscreen_yoffset = lprcMonitor->top; - } + { + wfi->servscreen_xoffset = lprcMonitor->left; + wfi->servscreen_yoffset = lprcMonitor->top; + } _IDcount++; - - return TRUE; -} + + return TRUE; +} diff --git a/server/Windows/wf_interface.c b/server/Windows/wf_interface.c index 80262649d..e2ece59b3 100644 --- a/server/Windows/wf_interface.c +++ b/server/Windows/wf_interface.c @@ -102,7 +102,7 @@ DWORD WINAPI wf_server_main_loop(LPVOID lpParam) if (instance->GetFileDescriptor(instance, rfds, &rcount) != TRUE) { - DEBUG_WARN("Failed to get FreeRDP file descriptor\n"); + WLog_ERR(TAG, "Failed to get FreeRDP file descriptor"); break; } @@ -127,13 +127,12 @@ DWORD WINAPI wf_server_main_loop(LPVOID lpParam) if (instance->CheckFileDescriptor(instance) != TRUE) { - DEBUG_WARN("Failed to check FreeRDP file descriptor\n"); + WLog_ERR(TAG, "Failed to check FreeRDP file descriptor"); break; } } - DEBUG_WARN("wf_server_main_loop terminating\n"); - + WLog_INFO(TAG, "wf_server_main_loop terminating"); instance->Close(instance); return 0; @@ -163,8 +162,7 @@ BOOL wfreerdp_server_stop(wfServer* server) wfInfo* wfi; wfi = wf_info_get_instance(); - - DEBUG_WARN("Stopping server\n"); + WLog_INFO(TAG, "Stopping server"); wfi->force_all_disconnect = TRUE; server->instance->Close(server->instance); return TRUE; @@ -210,7 +208,7 @@ FREERDP_API BOOL wfreerdp_server_is_running(wfServer* server) bRet = GetExitCodeThread(server->thread, &tStatus); if (bRet == 0) { - DEBUG_WARN("Error in call to GetExitCodeThread\n"); + WLog_ERR(TAG, "Error in call to GetExitCodeThread"); return FALSE; } @@ -245,7 +243,7 @@ FREERDP_API UINT32 wfreerdp_server_get_peer_hostname(int pId, wchar_t * dstStr) } else { - DEBUG_WARN("nonexistent peer id=%d\n", pId); + WLog_WARN(TAG, "nonexistent peer id=%d", pId); return 0; } } diff --git a/server/Windows/wf_interface.h b/server/Windows/wf_interface.h index 9a2c72215..6ab6b6f3e 100644 --- a/server/Windows/wf_interface.h +++ b/server/Windows/wf_interface.h @@ -29,7 +29,6 @@ #include #include -#include #include diff --git a/server/Windows/wf_mirage.c b/server/Windows/wf_mirage.c index be1fedca1..b3fa6c504 100644 --- a/server/Windows/wf_mirage.c +++ b/server/Windows/wf_mirage.c @@ -1,366 +1,368 @@ -/** - * FreeRDP: A Remote Desktop Protocol Implementation - * FreeRDP Windows Server - * - * Copyright 2012 Marc-Andre Moreau - * Copyright 2012-2013 Corey Clayton - * - * 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. - */ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * FreeRDP Windows Server + * + * Copyright 2012 Marc-Andre Moreau + * Copyright 2012-2013 Corey Clayton + * + * 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 +#include + +#include "wf_mirage.h" + +#define DEVICE_KEY_PREFIX _T("\\Registry\\Machine\\") +/* +This function will iterate over the loaded display devices until it finds +the mirror device we want to load. If found, it will then copy the registry +key corresponding to the device to the wfi and returns TRUE. Otherwise +the function returns FALSE. +*/ +BOOL wf_mirror_driver_find_display_device(wfInfo* wfi) +{ + BOOL result; + BOOL devFound; + DWORD deviceNumber; + DISPLAY_DEVICE deviceInfo; -#include -#include + devFound = FALSE; + deviceNumber = 0; + deviceInfo.cb = sizeof(deviceInfo); + + while (result = EnumDisplayDevices(NULL, deviceNumber, &deviceInfo, 0)) + { + if (_tcscmp(deviceInfo.DeviceString, _T("Mirage Driver")) == 0) + { + int deviceKeyLength; + int deviceKeyPrefixLength; -#include "wf_mirage.h" + deviceKeyPrefixLength = _tcslen(DEVICE_KEY_PREFIX); + + if (_tcsnicmp(deviceInfo.DeviceKey, DEVICE_KEY_PREFIX, deviceKeyPrefixLength) == 0) + { + deviceKeyLength = _tcslen(deviceInfo.DeviceKey) - deviceKeyPrefixLength; + wfi->deviceKey = (LPTSTR) malloc((deviceKeyLength + 1) * sizeof(TCHAR)); -#define DEVICE_KEY_PREFIX _T("\\Registry\\Machine\\") -/* -This function will iterate over the loaded display devices until it finds -the mirror device we want to load. If found, it will then copy the registry -key corresponding to the device to the wfi and returns TRUE. Otherwise -the function returns FALSE. -*/ -BOOL wf_mirror_driver_find_display_device(wfInfo* wfi) -{ - BOOL result; - BOOL devFound; - DWORD deviceNumber; - DISPLAY_DEVICE deviceInfo; - - devFound = FALSE; - deviceNumber = 0; - deviceInfo.cb = sizeof(deviceInfo); - - while (result = EnumDisplayDevices(NULL, deviceNumber, &deviceInfo, 0)) - { - if (_tcscmp(deviceInfo.DeviceString, _T("Mirage Driver")) == 0) - { - int deviceKeyLength; - int deviceKeyPrefixLength; - - deviceKeyPrefixLength = _tcslen(DEVICE_KEY_PREFIX); - - if (_tcsnicmp(deviceInfo.DeviceKey, DEVICE_KEY_PREFIX, deviceKeyPrefixLength) == 0) - { - deviceKeyLength = _tcslen(deviceInfo.DeviceKey) - deviceKeyPrefixLength; - wfi->deviceKey = (LPTSTR) malloc((deviceKeyLength + 1) * sizeof(TCHAR)); - - _tcsncpy_s(wfi->deviceKey, deviceKeyLength + 1, + _tcsncpy_s(wfi->deviceKey, deviceKeyLength + 1, &deviceInfo.DeviceKey[deviceKeyPrefixLength], deviceKeyLength); - } - - _tcsncpy_s(wfi->deviceName, 32, deviceInfo.DeviceName, _tcslen(deviceInfo.DeviceName)); - return TRUE; - } - - deviceNumber++; - } - - return FALSE; -} - -/** - * This function will attempt to access the the windows registry using the device - * key stored in the current wfi. It will attempt to read the value of the - * "Attach.ToDesktop" subkey and will return TRUE if the value is already set to + } + + _tcsncpy_s(wfi->deviceName, 32, deviceInfo.DeviceName, _tcslen(deviceInfo.DeviceName)); + return TRUE; + } + + deviceNumber++; + } + + return FALSE; +} + +/** + * This function will attempt to access the the windows registry using the device + * key stored in the current wfi. It will attempt to read the value of the + * "Attach.ToDesktop" subkey and will return TRUE if the value is already set to * val. If unable to read the subkey, this function will return FALSE. If the * subkey is not set to val it will then attempt to set it to val and return TRUE. If * unsuccessful or an unexpected value is encountered, the function returns - * FALSE. - */ + * FALSE. + */ + +BOOL wf_mirror_driver_display_device_attach(wfInfo* wfi, DWORD mode) +{ + HKEY hKey; + LONG status; + DWORD dwType; + DWORD dwSize; + DWORD dwValue; -BOOL wf_mirror_driver_display_device_attach(wfInfo* wfi, DWORD mode) -{ - HKEY hKey; - LONG status; - DWORD dwType; - DWORD dwSize; - DWORD dwValue; - - status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, wfi->deviceKey, + status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, wfi->deviceKey, 0, KEY_ALL_ACCESS | KEY_WOW64_64KEY, &hKey); - - if (status != ERROR_SUCCESS) - { - DEBUG_WARN("Error opening RegKey: status=%0X\n", status); - if (status == ERROR_ACCESS_DENIED) - DEBUG_WARN("access denied. Do you have admin privleges?\n"); - return FALSE; - } - - dwSize = sizeof(DWORD); - status = RegQueryValueEx(hKey, _T("Attach.ToDesktop"), + + if (status != ERROR_SUCCESS) + { + WLog_DBG(TAG, "Error opening RegKey: status=%0X", status); + + if (status == ERROR_ACCESS_DENIED) + WLog_DBG(TAG, "access denied. Do you have admin privleges?"); + + return FALSE; + } + + dwSize = sizeof(DWORD); + status = RegQueryValueEx(hKey, _T("Attach.ToDesktop"), NULL, &dwType, (BYTE*) &dwValue, &dwSize); + + if (status != ERROR_SUCCESS) + { + WLog_DBG(TAG, "Error querying RegKey: status=%0X", status); + + if (status == ERROR_ACCESS_DENIED) + WLog_DBG(TAG, "access denied. Do you have admin privleges?"); + + return FALSE; + } + + if (dwValue ^ mode) //only if we want to change modes + { + dwValue = mode; + dwSize = sizeof(DWORD); - if (status != ERROR_SUCCESS) - { - DEBUG_WARN("Error querying RegKey: status=%0X\n", status); - if (status == ERROR_ACCESS_DENIED) - DEBUG_WARN("access denied. Do you have admin privleges?\n"); - return FALSE; - } - - if (dwValue ^ mode) //only if we want to change modes - { - dwValue = mode; - dwSize = sizeof(DWORD); - - status = RegSetValueEx(hKey, _T("Attach.ToDesktop"), + status = RegSetValueEx(hKey, _T("Attach.ToDesktop"), 0, REG_DWORD, (BYTE*) &dwValue, dwSize); + + if (status != ERROR_SUCCESS) + { + WLog_DBG(TAG, "Error writing registry key: %d ", status); + + if (status == ERROR_ACCESS_DENIED) + WLog_DBG(TAG, "access denied. Do you have admin privleges?"); + + WLog_DBG(TAG, ""); + return FALSE; + } + } + + return TRUE; +} + +void wf_mirror_driver_print_display_change_status(LONG status) +{ + TCHAR disp_change[64]; + + switch (status) + { + case DISP_CHANGE_SUCCESSFUL: + _tcscpy(disp_change, _T("DISP_CHANGE_SUCCESSFUL")); + break; - if (status != ERROR_SUCCESS) - { - DEBUG_WARN("Error writing registry key: %d ", status); - if (status == ERROR_ACCESS_DENIED) - DEBUG_WARN("access denied. Do you have admin privleges?"); - DEBUG_WARN("\n"); - return FALSE; - } - } + case DISP_CHANGE_BADDUALVIEW: + _tcscpy(disp_change, _T("DISP_CHANGE_BADDUALVIEW")); + break; - return TRUE; -} + case DISP_CHANGE_BADFLAGS: + _tcscpy(disp_change, _T("DISP_CHANGE_BADFLAGS")); + break; -void wf_mirror_driver_print_display_change_status(LONG status) -{ - TCHAR disp_change[64]; + case DISP_CHANGE_BADMODE: + _tcscpy(disp_change, _T("DISP_CHANGE_BADMODE")); + break; - switch (status) - { - case DISP_CHANGE_SUCCESSFUL: - _tcscpy(disp_change, _T("DISP_CHANGE_SUCCESSFUL")); - break; + case DISP_CHANGE_BADPARAM: + _tcscpy(disp_change, _T("DISP_CHANGE_BADPARAM")); + break; - case DISP_CHANGE_BADDUALVIEW: - _tcscpy(disp_change, _T("DISP_CHANGE_BADDUALVIEW")); - break; + case DISP_CHANGE_FAILED: + _tcscpy(disp_change, _T("DISP_CHANGE_FAILED")); + break; - case DISP_CHANGE_BADFLAGS: - _tcscpy(disp_change, _T("DISP_CHANGE_BADFLAGS")); - break; + case DISP_CHANGE_NOTUPDATED: + _tcscpy(disp_change, _T("DISP_CHANGE_NOTUPDATED")); + break; - case DISP_CHANGE_BADMODE: - _tcscpy(disp_change, _T("DISP_CHANGE_BADMODE")); - break; + case DISP_CHANGE_RESTART: + _tcscpy(disp_change, _T("DISP_CHANGE_RESTART")); + break; - case DISP_CHANGE_BADPARAM: - _tcscpy(disp_change, _T("DISP_CHANGE_BADPARAM")); - break; - - case DISP_CHANGE_FAILED: - _tcscpy(disp_change, _T("DISP_CHANGE_FAILED")); - break; - - case DISP_CHANGE_NOTUPDATED: - _tcscpy(disp_change, _T("DISP_CHANGE_NOTUPDATED")); - break; - - case DISP_CHANGE_RESTART: - _tcscpy(disp_change, _T("DISP_CHANGE_RESTART")); - break; - - default: - _tcscpy(disp_change, _T("DISP_CHANGE_UNKNOWN")); - break; - } - - if (status != DISP_CHANGE_SUCCESSFUL) - _tprintf(_T("ChangeDisplaySettingsEx() failed with %s (%d)\n"), disp_change, status); - else - _tprintf(_T("ChangeDisplaySettingsEx() succeeded with %s (%d)\n"), disp_change, status); -} - -/** + default: + _tcscpy(disp_change, _T("DISP_CHANGE_UNKNOWN")); + break; + } + + if (status != DISP_CHANGE_SUCCESSFUL) + WLog_ERR(TAG, "ChangeDisplaySettingsEx() failed with %s (%d)", disp_change, status); + else + WLog_INFO(TAG, "ChangeDisplaySettingsEx() succeeded with %s (%d)", disp_change, status); +} + +/** * This function will attempt to apply the currently configured display settings * in the registry to the display driver. It will return TRUE if successful - * otherwise it returns FALSE. - * If mode is MIRROR_UNLOAD then the the driver will be asked to remove itself. - */ - -BOOL wf_mirror_driver_update(wfInfo* wfi, int mode) -{ - HDC dc; - BOOL status; - DWORD* extHdr; - WORD drvExtraSaved; - DEVMODE* deviceMode; - LONG disp_change_status; - DWORD dmf_devmodewext_magic_sig = 0xDF20C0DE; - + * otherwise it returns FALSE. + * If mode is MIRROR_UNLOAD then the the driver will be asked to remove itself. + */ + +BOOL wf_mirror_driver_update(wfInfo* wfi, int mode) +{ + HDC dc; + BOOL status; + DWORD* extHdr; + WORD drvExtraSaved; + DEVMODE* deviceMode; + LONG disp_change_status; + DWORD dmf_devmodewext_magic_sig = 0xDF20C0DE; + if ( (mode != MIRROR_LOAD) && (mode != MIRROR_UNLOAD) ) - { - DEBUG_WARN("Invalid mirror mode!\n"); - return FALSE; - } + { + WLog_DBG(TAG, "Invalid mirror mode!"); + return FALSE; + } - deviceMode = (DEVMODE*) malloc(sizeof(DEVMODE) + EXT_DEVMODE_SIZE_MAX); - deviceMode->dmDriverExtra = 2 * sizeof(DWORD); + deviceMode = (DEVMODE*) malloc(sizeof(DEVMODE) + EXT_DEVMODE_SIZE_MAX); + deviceMode->dmDriverExtra = 2 * sizeof(DWORD); extHdr = (DWORD*)((BYTE*) &deviceMode + sizeof(DEVMODE)); - extHdr[0] = dmf_devmodewext_magic_sig; - extHdr[1] = 0; + extHdr[0] = dmf_devmodewext_magic_sig; + extHdr[1] = 0; - drvExtraSaved = deviceMode->dmDriverExtra; - memset(deviceMode, 0, sizeof(DEVMODE) + EXT_DEVMODE_SIZE_MAX); - deviceMode->dmSize = sizeof(DEVMODE); - deviceMode->dmDriverExtra = drvExtraSaved; + drvExtraSaved = deviceMode->dmDriverExtra; + memset(deviceMode, 0, sizeof(DEVMODE) + EXT_DEVMODE_SIZE_MAX); + deviceMode->dmSize = sizeof(DEVMODE); + deviceMode->dmDriverExtra = drvExtraSaved; + + if (mode == MIRROR_LOAD) + { + wfi->virtscreen_width = GetSystemMetrics(SM_CXVIRTUALSCREEN); + wfi->virtscreen_height = GetSystemMetrics(SM_CYVIRTUALSCREEN); - if (mode == MIRROR_LOAD) - { - wfi->virtscreen_width = GetSystemMetrics(SM_CXVIRTUALSCREEN); - wfi->virtscreen_height = GetSystemMetrics(SM_CYVIRTUALSCREEN); + deviceMode->dmPelsWidth = wfi->virtscreen_width; + deviceMode->dmPelsHeight = wfi->virtscreen_height; + deviceMode->dmBitsPerPel = wfi->bitsPerPixel; + deviceMode->dmPosition.x = wfi->servscreen_xoffset; + deviceMode->dmPosition.y = wfi->servscreen_yoffset; + } + + deviceMode->dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_POSITION; - deviceMode->dmPelsWidth = wfi->virtscreen_width; - deviceMode->dmPelsHeight = wfi->virtscreen_height; - deviceMode->dmBitsPerPel = wfi->bitsPerPixel; - deviceMode->dmPosition.x = wfi->servscreen_xoffset; - deviceMode->dmPosition.y = wfi->servscreen_yoffset; - } + _tcsncpy_s(deviceMode->dmDeviceName, 32, wfi->deviceName, _tcslen(wfi->deviceName)); - deviceMode->dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_POSITION; + disp_change_status = ChangeDisplaySettingsEx(wfi->deviceName, deviceMode, NULL, CDS_UPDATEREGISTRY, NULL); - _tcsncpy_s(deviceMode->dmDeviceName, 32, wfi->deviceName, _tcslen(wfi->deviceName)); - - disp_change_status = ChangeDisplaySettingsEx(wfi->deviceName, deviceMode, NULL, CDS_UPDATEREGISTRY, NULL); - - status = (disp_change_status == DISP_CHANGE_SUCCESSFUL) ? TRUE : FALSE; - - if (!status) - wf_mirror_driver_print_display_change_status(disp_change_status); + status = (disp_change_status == DISP_CHANGE_SUCCESSFUL) ? TRUE : FALSE; + + if (!status) + wf_mirror_driver_print_display_change_status(disp_change_status); - return status; -} + return status; +} + +BOOL wf_mirror_driver_map_memory(wfInfo* wfi) +{ + int status; -BOOL wf_mirror_driver_map_memory(wfInfo* wfi) -{ - int status; - - wfi->driverDC = CreateDC(wfi->deviceName, NULL, NULL, NULL); - - if (wfi->driverDC == NULL) - { - _tprintf(_T("Could not create device driver context!\n")); - - { - LPVOID lpMsgBuf; + wfi->driverDC = CreateDC(wfi->deviceName, NULL, NULL, NULL); + + if (wfi->driverDC == NULL) + { + WLog_ERR(TAG, "Could not create device driver context!"); + { + LPVOID lpMsgBuf; DWORD dw = GetLastError(); - FormatMessage( + FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | - FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, - dw, - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (LPTSTR) &lpMsgBuf, + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + dw, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + (LPTSTR) &lpMsgBuf, 0, NULL ); - // Display the error message and exit the process + // Display the error message and exit the process + WLog_ERR(TAG, "CreateDC failed on device [%s] with error %d: %s", wfi->deviceName, dw, lpMsgBuf); + LocalFree(lpMsgBuf); + } - _tprintf(_T("CreateDC failed on device [%s] with error %d: %s\n"), wfi->deviceName, dw, lpMsgBuf); + return FALSE; + } + + wfi->changeBuffer = malloc(sizeof(GETCHANGESBUF)); + ZeroMemory(wfi->changeBuffer, sizeof(GETCHANGESBUF)); - LocalFree(lpMsgBuf); - } + status = ExtEscape(wfi->driverDC, dmf_esc_usm_pipe_map, 0, 0, sizeof(GETCHANGESBUF), (LPSTR) wfi->changeBuffer); + + if (status <= 0) + { + WLog_ERR(TAG, "Failed to map shared memory from the driver! code %d", status); + return FALSE; + } + + return TRUE; +} + +/* Unmap the shared memory and release the DC */ + +BOOL wf_mirror_driver_cleanup(wfInfo* wfi) +{ + int status; - return FALSE; - } - - wfi->changeBuffer = malloc(sizeof(GETCHANGESBUF)); - ZeroMemory(wfi->changeBuffer, sizeof(GETCHANGESBUF)); - - status = ExtEscape(wfi->driverDC, dmf_esc_usm_pipe_map, 0, 0, sizeof(GETCHANGESBUF), (LPSTR) wfi->changeBuffer); - - if (status <= 0) - { - _tprintf(_T("Failed to map shared memory from the driver! code %d\n"), status); - return FALSE; - } - - return TRUE; -} - -/* Unmap the shared memory and release the DC */ - -BOOL wf_mirror_driver_cleanup(wfInfo* wfi) -{ - int status; - - status = ExtEscape(wfi->driverDC, dmf_esc_usm_pipe_unmap, sizeof(GETCHANGESBUF), (LPSTR) wfi->changeBuffer, 0, 0); + status = ExtEscape(wfi->driverDC, dmf_esc_usm_pipe_unmap, sizeof(GETCHANGESBUF), (LPSTR) wfi->changeBuffer, 0, 0); - if (status <= 0) - { - _tprintf(_T("Failed to unmap shared memory from the driver! code %d\n"), status); - } + if (status <= 0) + { + WLog_ERR(TAG, "Failed to unmap shared memory from the driver! code %d", status); + } + + if (wfi->driverDC != NULL) + { + status = DeleteDC(wfi->driverDC); + + if (status == 0) + { + WLog_ERR(TAG, "Failed to release DC!")); + } + } + + free(wfi->changeBuffer); - if (wfi->driverDC != NULL) - { - status = DeleteDC(wfi->driverDC); - - if (status == 0) - { - _tprintf(_T("Failed to release DC!\n")); - } - } - - free(wfi->changeBuffer); - - return TRUE; -} - -BOOL wf_mirror_driver_activate(wfInfo* wfi) -{ - if (!wfi->mirrorDriverActive) - { - DEBUG_WARN("Activating Mirror Driver\n"); - - if (wf_mirror_driver_find_display_device(wfi) == FALSE) - { - DEBUG_WARN("Could not find dfmirage mirror driver! Is it installed?\n"); - return FALSE; - } - - if (wf_mirror_driver_display_device_attach(wfi, 1) == FALSE) - { - DEBUG_WARN("Could not attach display device!\n"); - return FALSE; - } - - if (wf_mirror_driver_update(wfi, MIRROR_LOAD) == FALSE) - { - DEBUG_WARN("could not update system with new display settings!\n"); - return FALSE; - } - - if (wf_mirror_driver_map_memory(wfi) == FALSE) - { - DEBUG_WARN("Unable to map memory for mirror driver!\n"); - return FALSE; - } - wfi->mirrorDriverActive = TRUE; - } - - return TRUE; -} - -void wf_mirror_driver_deactivate(wfInfo* wfi) -{ - if (wfi->mirrorDriverActive) - { - DEBUG_WARN("Deactivating Mirror Driver\n"); - - wf_mirror_driver_cleanup(wfi); - wf_mirror_driver_display_device_attach(wfi, 0); - wf_mirror_driver_update(wfi, MIRROR_UNLOAD); - wfi->mirrorDriverActive = FALSE; - } + return TRUE; +} + +BOOL wf_mirror_driver_activate(wfInfo* wfi) +{ + if (!wfi->mirrorDriverActive) + { + WLog_DBG(TAG, "Activating Mirror Driver"); + + if (wf_mirror_driver_find_display_device(wfi) == FALSE) + { + WLog_DBG(TAG, "Could not find dfmirage mirror driver! Is it installed?"); + return FALSE; + } + + if (wf_mirror_driver_display_device_attach(wfi, 1) == FALSE) + { + WLog_DBG(TAG, "Could not attach display device!"); + return FALSE; + } + + if (wf_mirror_driver_update(wfi, MIRROR_LOAD) == FALSE) + { + WLog_DBG(TAG, "could not update system with new display settings!"); + return FALSE; + } + + if (wf_mirror_driver_map_memory(wfi) == FALSE) + { + WLog_DBG(TAG, "Unable to map memory for mirror driver!"); + return FALSE; + } + wfi->mirrorDriverActive = TRUE; + } + + return TRUE; +} + +void wf_mirror_driver_deactivate(wfInfo* wfi) +{ + if (wfi->mirrorDriverActive) + { + WLog_DBG(TAG, "Deactivating Mirror Driver"); + wf_mirror_driver_cleanup(wfi); + wf_mirror_driver_display_device_attach(wfi, 0); + wf_mirror_driver_update(wfi, MIRROR_UNLOAD); + wfi->mirrorDriverActive = FALSE; + } } \ No newline at end of file diff --git a/server/Windows/wf_peer.c b/server/Windows/wf_peer.c index 4a03d1bf9..c8cb3847f 100644 --- a/server/Windows/wf_peer.c +++ b/server/Windows/wf_peer.c @@ -1,331 +1,329 @@ -/** -* FreeRDP: A Remote Desktop Protocol Client -* FreeRDP Windows Server -* -* Copyright 2012 Marc-Andre Moreau -* Copyright 2012 Corey Clayton -* -* 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. -*/ +/** +* FreeRDP: A Remote Desktop Protocol Client +* FreeRDP Windows Server +* +* Copyright 2012 Marc-Andre Moreau +* Copyright 2012 Corey Clayton +* +* 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 +#include +#include + +#include +#include + +#include "wf_info.h" +#include "wf_input.h" +#include "wf_mirage.h" +#include "wf_update.h" +#include "wf_settings.h" +#include "wf_rdpsnd.h" + +#include "wf_peer.h" + +void wf_peer_context_new(freerdp_peer* client, wfPeerContext* context) +{ + context->info = wf_info_get_instance(); + context->vcm = WTSOpenServerA((LPSTR) client->context); + wf_info_peer_register(context->info, context); +} + +void wf_peer_context_free(freerdp_peer* client, wfPeerContext* context) +{ + wf_info_peer_unregister(context->info, context); + + if (context->rdpsnd) + { + wf_rdpsnd_lock(); + context->info->snd_stop = TRUE; + rdpsnd_server_context_free(context->rdpsnd); + wf_rdpsnd_unlock(); + } + + WTSCloseServer(context->vcm); +} + +void wf_peer_init(freerdp_peer* client) +{ + client->ContextSize = sizeof(wfPeerContext); + client->ContextNew = (psPeerContextNew) wf_peer_context_new; + client->ContextFree = (psPeerContextFree) wf_peer_context_free; -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif + freerdp_peer_context_new(client); +} + +BOOL wf_peer_post_connect(freerdp_peer* client) +{ + int i; + wfInfo* wfi; + rdpSettings* settings; + wfPeerContext* context = (wfPeerContext*) client->context; -#include -#include -#include - -#include -#include - -#include "wf_info.h" -#include "wf_input.h" -#include "wf_mirage.h" -#include "wf_update.h" -#include "wf_settings.h" -#include "wf_rdpsnd.h" - -#include "wf_peer.h" - -void wf_peer_context_new(freerdp_peer* client, wfPeerContext* context) -{ - context->info = wf_info_get_instance(); - context->vcm = WTSOpenServerA((LPSTR) client->context); - wf_info_peer_register(context->info, context); -} - -void wf_peer_context_free(freerdp_peer* client, wfPeerContext* context) -{ - wf_info_peer_unregister(context->info, context); - - if (context->rdpsnd) - { - wf_rdpsnd_lock(); - context->info->snd_stop = TRUE; - rdpsnd_server_context_free(context->rdpsnd); - wf_rdpsnd_unlock(); - } - - WTSCloseServer(context->vcm); -} - -void wf_peer_init(freerdp_peer* client) -{ - client->ContextSize = sizeof(wfPeerContext); - client->ContextNew = (psPeerContextNew) wf_peer_context_new; - client->ContextFree = (psPeerContextFree) wf_peer_context_free; - - freerdp_peer_context_new(client); -} - -BOOL wf_peer_post_connect(freerdp_peer* client) -{ - int i; - wfInfo* wfi; - rdpSettings* settings; - wfPeerContext* context = (wfPeerContext*) client->context; - - wfi = context->info; - settings = client->settings; - - if ((get_screen_info(wfi->screenID, NULL, &wfi->servscreen_width, &wfi->servscreen_height, &wfi->bitsPerPixel) == 0) || + wfi = context->info; + settings = client->settings; + + if ((get_screen_info(wfi->screenID, NULL, &wfi->servscreen_width, &wfi->servscreen_height, &wfi->bitsPerPixel) == 0) || (wfi->servscreen_width == 0) || (wfi->servscreen_height == 0) || (wfi->bitsPerPixel == 0) ) - { - _tprintf(_T("postconnect: error getting screen info for screen %d\n"), wfi->screenID); - _tprintf(_T("\t%dx%dx%d\n"), wfi->servscreen_height, wfi->servscreen_width, wfi->bitsPerPixel); - return FALSE; - } + { + WLog_ERR(TAG, "postconnect: error getting screen info for screen %d", wfi->screenID); + WLog_ERR(TAG, "\t%dx%dx%d", wfi->servscreen_height, wfi->servscreen_width, wfi->bitsPerPixel); + return FALSE; + } + + if ((settings->DesktopWidth != wfi->servscreen_width) || (settings->DesktopHeight != wfi->servscreen_height)) + { + /* + WLog_DBG(TAG, "Client requested resolution %dx%d, but will resize to %dx%d", + settings->DesktopWidth, settings->DesktopHeight, wfi->servscreen_width, wfi->servscreen_height); + */ - if ((settings->DesktopWidth != wfi->servscreen_width) || (settings->DesktopHeight != wfi->servscreen_height)) - { - /* - DEBUG_WARN("Client requested resolution %dx%d, but will resize to %dx%d\n", - settings->DesktopWidth, settings->DesktopHeight, wfi->servscreen_width, wfi->servscreen_height); - */ + settings->DesktopWidth = wfi->servscreen_width; + settings->DesktopHeight = wfi->servscreen_height; + settings->ColorDepth = wfi->bitsPerPixel; - settings->DesktopWidth = wfi->servscreen_width; - settings->DesktopHeight = wfi->servscreen_height; - settings->ColorDepth = wfi->bitsPerPixel; + client->update->DesktopResize(client->update->context); + } + + if (WTSVirtualChannelManagerIsChannelJoined(context->vcm, "rdpsnd")) + { + wf_peer_rdpsnd_init(context); /* Audio Output */ + } + + return TRUE; +} + +BOOL wf_peer_activate(freerdp_peer* client) +{ + wfInfo* wfi; + wfPeerContext* context = (wfPeerContext*) client->context; - client->update->DesktopResize(client->update->context); - } + wfi = context->info; + client->activated = TRUE; + wf_update_peer_activate(wfi, context); - if (WTSVirtualChannelManagerIsChannelJoined(context->vcm, "rdpsnd")) - { - wf_peer_rdpsnd_init(context); /* Audio Output */ - } + wfreerdp_server_peer_callback_event(((rdpContext*) context)->peer->pId, WF_SRV_CALLBACK_EVENT_ACTIVATE); - return TRUE; -} + return TRUE; +} + +BOOL wf_peer_logon(freerdp_peer* client, SEC_WINNT_AUTH_IDENTITY* identity, BOOL automatic) +{ + wfreerdp_server_peer_callback_event(((rdpContext*) client->context)->peer->pId, WF_SRV_CALLBACK_EVENT_AUTH); + return TRUE; +} + +void wf_peer_synchronize_event(rdpInput* input, UINT32 flags) +{ -BOOL wf_peer_activate(freerdp_peer* client) -{ - wfInfo* wfi; - wfPeerContext* context = (wfPeerContext*) client->context; +} + +void wf_peer_accepted(freerdp_listener* instance, freerdp_peer* client) +{ + CreateThread(NULL, 0, wf_peer_main_loop, client, 0, NULL); +} + +DWORD WINAPI wf_peer_socket_listener(LPVOID lpParam) +{ + int i, fds; + int rcount; + int max_fds; + void* rfds[32]; + fd_set rfds_set; + wfPeerContext* context; + freerdp_peer* client = (freerdp_peer*) lpParam; - wfi = context->info; - client->activated = TRUE; - wf_update_peer_activate(wfi, context); + ZeroMemory(rfds, sizeof(rfds)); + context = (wfPeerContext*) client->context; + + while (1) + { + rcount = 0; + + if (client->GetFileDescriptor(client, rfds, &rcount) != TRUE) + { + WLog_ERR(TAG, "Failed to get peer file descriptor"); + break; + } + + max_fds = 0; + FD_ZERO(&rfds_set); + + for (i = 0; i < rcount; i++) + { + fds = (int)(long)(rfds[i]); + + if (fds > max_fds) + max_fds = fds; + + FD_SET(fds, &rfds_set); + } + + if (max_fds == 0) + break; + + select(max_fds + 1, &rfds_set, NULL, NULL, NULL); - wfreerdp_server_peer_callback_event(((rdpContext*) context)->peer->pId, WF_SRV_CALLBACK_EVENT_ACTIVATE); + SetEvent(context->socketEvent); + WaitForSingleObject(context->socketSemaphore, INFINITE); + + if (context->socketClose) + break; + } + + return 0; +} + +void wf_peer_read_settings(freerdp_peer* client) +{ + if (!wf_settings_read_string_ascii(HKEY_LOCAL_MACHINE, _T("Software\\FreeRDP\\Server"), _T("CertificateFile"), &(client->settings->CertificateFile))) + client->settings->CertificateFile = _strdup("server.crt"); + + if (!wf_settings_read_string_ascii(HKEY_LOCAL_MACHINE, _T("Software\\FreeRDP\\Server"), _T("PrivateKeyFile"), &(client->settings->PrivateKeyFile))) + client->settings->PrivateKeyFile = _strdup("server.key"); +} + +DWORD WINAPI wf_peer_main_loop(LPVOID lpParam) +{ + wfInfo* wfi; + DWORD nCount; + DWORD status; + HANDLE handles[32]; + rdpSettings* settings; + wfPeerContext* context; + freerdp_peer* client = (freerdp_peer*) lpParam; + + if (!getenv("HOME")) + { + char home[MAX_PATH * 2] = "HOME="; + strcat(home, getenv("HOMEDRIVE")); + strcat(home, getenv("HOMEPATH")); + _putenv(home); + } + + wf_peer_init(client); - return TRUE; -} + settings = client->settings; + settings->RemoteFxCodec = TRUE; + settings->ColorDepth = 32; + settings->NSCodec = FALSE; + settings->JpegCodec = FALSE; + wf_peer_read_settings(client); -BOOL wf_peer_logon(freerdp_peer* client, SEC_WINNT_AUTH_IDENTITY* identity, BOOL automatic) -{ - wfreerdp_server_peer_callback_event(((rdpContext*) client->context)->peer->pId, WF_SRV_CALLBACK_EVENT_AUTH); - return TRUE; -} + client->PostConnect = wf_peer_post_connect; + client->Activate = wf_peer_activate; + client->Logon = wf_peer_logon; -void wf_peer_synchronize_event(rdpInput* input, UINT32 flags) -{ + client->input->SynchronizeEvent = wf_peer_synchronize_event; + client->input->KeyboardEvent = wf_peer_keyboard_event; + client->input->UnicodeKeyboardEvent = wf_peer_unicode_keyboard_event; + client->input->MouseEvent = wf_peer_mouse_event; + client->input->ExtendedMouseEvent = wf_peer_extended_mouse_event; -} - -void wf_peer_accepted(freerdp_listener* instance, freerdp_peer* client) -{ - CreateThread(NULL, 0, wf_peer_main_loop, client, 0, NULL); -} - -DWORD WINAPI wf_peer_socket_listener(LPVOID lpParam) -{ - int i, fds; - int rcount; - int max_fds; - void* rfds[32]; - fd_set rfds_set; - wfPeerContext* context; - freerdp_peer* client = (freerdp_peer*) lpParam; - - ZeroMemory(rfds, sizeof(rfds)); - context = (wfPeerContext*) client->context; - - while (1) - { - rcount = 0; - - if (client->GetFileDescriptor(client, rfds, &rcount) != TRUE) - { - //printf("Failed to get peer 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; - - select(max_fds + 1, &rfds_set, NULL, NULL, NULL); - - SetEvent(context->socketEvent); - WaitForSingleObject(context->socketSemaphore, INFINITE); - - if (context->socketClose) - break; - } - - return 0; -} - -void wf_peer_read_settings(freerdp_peer* client) -{ - if (!wf_settings_read_string_ascii(HKEY_LOCAL_MACHINE, _T("Software\\FreeRDP\\Server"), _T("CertificateFile"), &(client->settings->CertificateFile))) - client->settings->CertificateFile = _strdup("server.crt"); - - if (!wf_settings_read_string_ascii(HKEY_LOCAL_MACHINE, _T("Software\\FreeRDP\\Server"), _T("PrivateKeyFile"), &(client->settings->PrivateKeyFile))) - client->settings->PrivateKeyFile = _strdup("server.key"); -} - -DWORD WINAPI wf_peer_main_loop(LPVOID lpParam) -{ - wfInfo* wfi; - DWORD nCount; - DWORD status; - HANDLE handles[32]; - rdpSettings* settings; - wfPeerContext* context; - freerdp_peer* client = (freerdp_peer*) lpParam; - - if (!getenv("HOME")) - { - char home[MAX_PATH * 2] = "HOME="; - strcat(home, getenv("HOMEDRIVE")); - strcat(home, getenv("HOMEPATH")); - _putenv(home); - } - - wf_peer_init(client); - - settings = client->settings; - settings->RemoteFxCodec = TRUE; - settings->ColorDepth = 32; - settings->NSCodec = FALSE; - settings->JpegCodec = FALSE; - wf_peer_read_settings(client); - - client->PostConnect = wf_peer_post_connect; - client->Activate = wf_peer_activate; - client->Logon = wf_peer_logon; - - client->input->SynchronizeEvent = wf_peer_synchronize_event; - client->input->KeyboardEvent = wf_peer_keyboard_event; - client->input->UnicodeKeyboardEvent = wf_peer_unicode_keyboard_event; - client->input->MouseEvent = wf_peer_mouse_event; - client->input->ExtendedMouseEvent = wf_peer_extended_mouse_event; - - client->Initialize(client); - context = (wfPeerContext*) client->context; - - if (context->socketClose) - return 0; - - wfi = context->info; - - if (wfi->input_disabled) - { - DEBUG_WARN("client input is disabled\n"); - client->input->KeyboardEvent = wf_peer_keyboard_event_dummy; - client->input->UnicodeKeyboardEvent = wf_peer_unicode_keyboard_event_dummy; - client->input->MouseEvent = wf_peer_mouse_event_dummy; - client->input->ExtendedMouseEvent = wf_peer_extended_mouse_event_dummy; - } - - context->socketEvent = CreateEvent(NULL, TRUE, FALSE, NULL); + client->Initialize(client); + context = (wfPeerContext*) client->context; + + if (context->socketClose) + return 0; + + wfi = context->info; + + if (wfi->input_disabled) + { + WLog_INFO(TAG, "client input is disabled"); + client->input->KeyboardEvent = wf_peer_keyboard_event_dummy; + client->input->UnicodeKeyboardEvent = wf_peer_unicode_keyboard_event_dummy; + client->input->MouseEvent = wf_peer_mouse_event_dummy; + client->input->ExtendedMouseEvent = wf_peer_extended_mouse_event_dummy; + } + + 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); + context->socketSemaphore = CreateSemaphore(NULL, 0, 1, NULL); + context->socketThread = CreateThread(NULL, 0, wf_peer_socket_listener, client, 0, NULL); + WLog_INFO(TAG, "We've got a client %s", client->local ? "(local)" : client->hostname); + nCount = 0; + handles[nCount++] = context->updateEvent; + handles[nCount++] = context->socketEvent; + + while (1) + { + status = WaitForMultipleObjects(nCount, handles, FALSE, INFINITE); + + if ((status == WAIT_FAILED) || (status == WAIT_TIMEOUT)) + { + WLog_ERR(TAG, "WaitForMultipleObjects failed"); + break; + } + + if (WaitForSingleObject(context->updateEvent, 0) == 0) + { + if (client->activated) + wf_update_peer_send(wfi, context); + + ResetEvent(context->updateEvent); + ReleaseSemaphore(wfi->updateSemaphore, 1, NULL); + } + + if (WaitForSingleObject(context->socketEvent, 0) == 0) + { + if (client->CheckFileDescriptor(client) != TRUE) + { + WLog_ERR(TAG, "Failed to check peer file descriptor"); + context->socketClose = TRUE; + } + + ResetEvent(context->socketEvent); + ReleaseSemaphore(context->socketSemaphore, 1, NULL); + + if (context->socketClose) + break; + } + + //force disconnect + if (wfi->force_all_disconnect == TRUE) + { + WLog_INFO(TAG, "Forcing Disconnect -> "); + break; + } + + /* FIXME: we should wait on this, instead of calling it every time */ + if (WTSVirtualChannelManagerCheckFileDescriptor(context->vcm) != TRUE) + break; + } + + WLog_INFO(TAG, "Client %s disconnected.", client->local ? "(local)" : client->hostname); + + if (WaitForSingleObject(context->updateEvent, 0) == 0) + { + ResetEvent(context->updateEvent); + ReleaseSemaphore(wfi->updateSemaphore, 1, NULL); + } + + wf_update_peer_deactivate(wfi, context); - DEBUG_WARN("We've got a client %s\n", client->local ? "(local)" : client->hostname); + client->Disconnect(client); - nCount = 0; - handles[nCount++] = context->updateEvent; - handles[nCount++] = context->socketEvent; + freerdp_peer_context_free(client); + freerdp_peer_free(client); - while (1) - { - status = WaitForMultipleObjects(nCount, handles, FALSE, INFINITE); - - if ((status == WAIT_FAILED) || (status == WAIT_TIMEOUT)) - { - DEBUG_WARN("WaitForMultipleObjects failed\n"); - break; - } - - if (WaitForSingleObject(context->updateEvent, 0) == 0) - { - if (client->activated) - wf_update_peer_send(wfi, context); - - ResetEvent(context->updateEvent); - ReleaseSemaphore(wfi->updateSemaphore, 1, NULL); - } - - 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; - } - - //force disconnect - if (wfi->force_all_disconnect == TRUE) - { - DEBUG_WARN("Forcing Disconnect -> "); - break; - } - - /* FIXME: we should wait on this, instead of calling it every time */ - if (WTSVirtualChannelManagerCheckFileDescriptor(context->vcm) != TRUE) - break; - } - - DEBUG_WARN("Client %s disconnected.\n", client->local ? "(local)" : client->hostname); - - if (WaitForSingleObject(context->updateEvent, 0) == 0) - { - ResetEvent(context->updateEvent); - ReleaseSemaphore(wfi->updateSemaphore, 1, NULL); - } - - wf_update_peer_deactivate(wfi, context); - - client->Disconnect(client); - - freerdp_peer_context_free(client); - freerdp_peer_free(client); - - return 0; -} + return 0; +} diff --git a/server/Windows/wf_rdpsnd.c b/server/Windows/wf_rdpsnd.c index 004de3e1e..d9d7f465a 100644 --- a/server/Windows/wf_rdpsnd.c +++ b/server/Windows/wf_rdpsnd.c @@ -54,8 +54,9 @@ static void wf_peer_rdpsnd_activated(RdpsndServerContext* context) wfi = wf_info_get_instance(); wfi->agreed_format = NULL; - DEBUG_WARN("Client supports the following %d formats: \n", context->num_client_formats); - for(i = 0; i < context->num_client_formats; i++) + WLog_DBG(TAG, "Client supports the following %d formats:", context->num_client_formats); + + for (i = 0; i < context->num_client_formats; i++) { //TODO: improve the way we agree on a format for (j = 0; j < context->num_server_formats; j++) @@ -64,7 +65,7 @@ static void wf_peer_rdpsnd_activated(RdpsndServerContext* context) (context->client_formats[i].nChannels == context->server_formats[j].nChannels) && (context->client_formats[i].nSamplesPerSec == context->server_formats[j].nSamplesPerSec)) { - DEBUG_WARN("agreed on format!\n"); + WLog_DBG(TAG, "agreed on format!"); wfi->agreed_format = (AUDIO_FORMAT*) &context->server_formats[j]; break; } @@ -76,7 +77,7 @@ static void wf_peer_rdpsnd_activated(RdpsndServerContext* context) if (wfi->agreed_format == NULL) { - DEBUG_WARN("Could not agree on a audio format with the server\n"); + WLog_ERR(TAG, "Could not agree on a audio format with the server"); return; } @@ -116,7 +117,7 @@ int wf_rdpsnd_lock() break; case WAIT_FAILED: - DEBUG_WARN("wf_rdpsnd_lock failed with 0x%08X\n", GetLastError()); + WLog_ERR(TAG, "wf_rdpsnd_lock failed with 0x%08X", GetLastError()); return -1; break; } @@ -132,7 +133,7 @@ int wf_rdpsnd_unlock() if (ReleaseMutex(wfi->snd_mutex) == 0) { - DEBUG_WARN("wf_rdpsnd_unlock failed with 0x%08X\n", GetLastError()); + WLog_DBG(TAG, "wf_rdpsnd_unlock failed with 0x%08X", GetLastError()); return -1; } diff --git a/server/Windows/wf_update.c b/server/Windows/wf_update.c index f03763150..0c7991773 100644 --- a/server/Windows/wf_update.c +++ b/server/Windows/wf_update.c @@ -62,8 +62,7 @@ DWORD WINAPI wf_update_thread(LPVOID lpParam) if (wf_info_have_updates(wfi)) { wf_update_encode(wfi); - - //printf("Start of parallel sending\n"); + //WLog_DBG(TAG, "Start of parallel sending"); index = 0; for (peerindex = 0; peerindex < wfi->peerCount; peerindex++) { @@ -71,7 +70,7 @@ DWORD WINAPI wf_update_thread(LPVOID lpParam) { if (wfi->peers[index] && wfi->peers[index]->activated) { - //printf("Setting event for %d of %d\n", index + 1, wfi->activePeerCount); + //WLog_DBG(TAG, "Setting event for %d of %d", index + 1, wfi->activePeerCount); SetEvent(((wfPeerContext*) wfi->peers[index]->context)->updateEvent); } } @@ -80,13 +79,12 @@ DWORD WINAPI wf_update_thread(LPVOID lpParam) for (index = 0; index < wfi->activePeerCount; index++) { - //printf("Waiting for %d of %d\n", index + 1, wfi->activePeerCount); + //WLog_DBG(TAG, "Waiting for %d of %d", index + 1, wfi->activePeerCount); //WaitForSingleObject(wfi->updateSemaphore, INFINITE); WaitForSingleObject(wfi->updateSemaphore, 1000); } - //printf("End of parallel sending\n"); - + //WLog_DBG(TAG, "End of parallel sending"); wf_info_clear_invalid_region(wfi); } } @@ -103,8 +101,7 @@ DWORD WINAPI wf_update_thread(LPVOID lpParam) } } - //printf("Exiting Update Thread\n"); - + //WLog_DBG(TAG, "Exiting Update Thread"); return 0; } @@ -129,9 +126,7 @@ void wf_update_encode(wfInfo* wfi) rect.y = 0; rect.width = (UINT16) width; rect.height = (UINT16) height; - - //printf("x:%d y:%d w:%d h:%d\n", wfi->invalid.left, wfi->invalid.top, width, height); - + //WLog_DBG(TAG, "x:%d y:%d w:%d h:%d", wfi->invalid.left, wfi->invalid.top, width, height); Stream_Clear(wfi->s); rfx_compose_message(wfi->rfx_context, wfi->s, &rect, 1, @@ -175,9 +170,8 @@ void wf_update_peer_send(wfInfo* wfi, wfPeerContext* context) return; /* This is an unexpected error condition */ - - DEBUG_WARN("Unexpected Frame Index: Actual: %d Expected: %d\n", - wfi->frame_idx, context->frame_idx + 1); + WLog_DBG(TAG, "Unexpected Frame Index: Actual: %d Expected: %d", + wfi->frame_idx, context->frame_idx + 1); } wfi->cmd.codecID = client->settings->RemoteFxCodecId; @@ -189,7 +183,7 @@ void wf_update_encoder_reset(wfInfo* wfi) { if (wf_info_lock(wfi) > 0) { - DEBUG_WARN("Resetting encoder\n"); + WLog_DBG(TAG, "Resetting encoder"); if (wfi->rfx_context) { @@ -225,9 +219,7 @@ void wf_update_peer_activate(wfInfo* wfi, wfPeerContext* context) wf_update_encoder_reset(wfi); wfi->activePeerCount++; - - DEBUG_WARN("Activating Peer Updates: %d\n", wfi->activePeerCount); - + WLog_DBG(TAG, "Activating Peer Updates: %d", wfi->activePeerCount); wf_info_unlock(wfi); } } @@ -247,8 +239,7 @@ void wf_update_peer_deactivate(wfInfo* wfi, wfPeerContext* context) client->activated = FALSE; wfi->activePeerCount--; - - DEBUG_WARN("Deactivating Peer Updates: %d\n", wfi->activePeerCount); + WLog_DBG(TAG, "Deactivating Peer Updates: %d", wfi->activePeerCount); } wf_info_unlock(wfi); diff --git a/server/Windows/wf_wasapi.c b/server/Windows/wf_wasapi.c index a0e1c0137..58275fd34 100644 --- a/server/Windows/wf_wasapi.c +++ b/server/Windows/wf_wasapi.c @@ -41,12 +41,11 @@ int wf_wasapi_activate(RdpsndServerContext* context) if (devStr == NULL) { - _tprintf(_T("Failed to match for output device! Disabling rdpsnd.\n")); + WLog_ERR(TAG, "Failed to match for output device! Disabling rdpsnd."); return 1; } - DEBUG_WARN("RDPSND (WASAPI) Activated\n"); - + WLog_DBG(TAG, "RDPSND (WASAPI) Activated"); CreateThread(NULL, 0, wf_rdpsnd_wasapi_thread, latestPeer, 0, NULL); return 0; @@ -66,23 +65,23 @@ int wf_wasapi_get_device_string(LPWSTR pattern, LPWSTR * deviceStr) hr = CoCreateInstance(&CLSID_MMDeviceEnumerator, NULL, CLSCTX_ALL, &IID_IMMDeviceEnumerator, (void **) &pEnumerator); if (FAILED(hr)) { - _tprintf(_T("Failed to cocreate device enumerator\n")); + WLog_ERR(TAG, "Failed to cocreate device enumerator"); exit(1); } hr = pEnumerator->lpVtbl->EnumAudioEndpoints(pEnumerator, eCapture, DEVICE_STATE_ACTIVE, &pCollection); if ( FAILED(hr) ) { - _tprintf(_T("Failed to create endpoint collection\n")); + WLog_ERR(TAG, "Failed to create endpoint collection"); exit(1); } pCollection->lpVtbl->GetCount(pCollection, &count); - _tprintf(_T("Num endpoints: %d\n"), count); + WLog_INFO(TAG, "Num endpoints: %d", count); if (count == 0) { - _tprintf(_T("No endpoints!\n")); + WLog_ERR(TAG, "No endpoints!"); exit(1); } @@ -94,28 +93,28 @@ int wf_wasapi_get_device_string(LPWSTR pattern, LPWSTR * deviceStr) hr = pCollection->lpVtbl->Item(pCollection, i, &pEndpoint); if ( FAILED(hr) ) { - _tprintf(_T("Failed to get endpoint %d\n"), i); + WLog_ERR(TAG, "Failed to get endpoint %d", i); exit(1); } hr = pEndpoint->lpVtbl->GetId(pEndpoint, &pwszID); if ( FAILED(hr) ) { - _tprintf(_T("Failed to get endpoint ID\n")); + WLog_ERR(TAG, "Failed to get endpoint ID"); exit(1); } hr = pEndpoint->lpVtbl->OpenPropertyStore(pEndpoint, STGM_READ, &pProps); if ( FAILED(hr) ) { - _tprintf(_T("Failed to open property store\n")); + WLog_ERR(TAG, "Failed to open property store"); exit(1); } hr = pProps->lpVtbl->GetValue(pProps, &PKEY_Device_FriendlyName, &nameVar); if ( FAILED(hr) ) { - _tprintf(_T("Failed to get device friendly name\n")); + WLog_ERR(TAG, "Failed to get device friendly name"); exit(1); } @@ -123,9 +122,8 @@ int wf_wasapi_get_device_string(LPWSTR pattern, LPWSTR * deviceStr) if (wcscmp(pattern, nameVar.pwszVal) < 0) { unsigned int devStrLen; - _tprintf(_T("Using sound ouput endpoint: [%s] (%s)\n"), nameVar.pwszVal, pwszID); - //_tprintf(_T("matched %d characters\n"), wcscmp(pattern, nameVar.pwszVal)); - + WLog_INFO(TAG, "Using sound ouput endpoint: [%s] (%s)", nameVar.pwszVal, pwszID); + //WLog_INFO(TAG, "matched %d characters", wcscmp(pattern, nameVar.pwszVal); devStrLen = wcslen(pwszID); *deviceStr = (LPWSTR) malloc((devStrLen * 2) + 2); ZeroMemory(*deviceStr, (devStrLen * 2) + 2); @@ -179,28 +177,28 @@ DWORD WINAPI wf_rdpsnd_wasapi_thread(LPVOID lpParam) hr = CoCreateInstance(&CLSID_MMDeviceEnumerator, NULL, CLSCTX_ALL, &IID_IMMDeviceEnumerator, (void **) &pEnumerator); if (FAILED(hr)) { - _tprintf(_T("Failed to cocreate device enumerator\n")); + WLog_ERR(TAG, "Failed to cocreate device enumerator"); exit(1); } hr = pEnumerator->lpVtbl->GetDevice(pEnumerator, devStr, &pDevice); if (FAILED(hr)) { - _tprintf(_T("Failed to cocreate get device\n")); + WLog_ERR(TAG, "Failed to cocreate get device"); exit(1); } hr = pDevice->lpVtbl->Activate(pDevice, &IID_IAudioClient, CLSCTX_ALL, NULL, (void **)&pAudioClient); if (FAILED(hr)) { - _tprintf(_T("Failed to activate audio client\n")); + WLog_ERR(TAG, "Failed to activate audio client"); exit(1); } hr = pAudioClient->lpVtbl->GetMixFormat(pAudioClient, &pwfx); if (FAILED(hr)) { - _tprintf(_T("Failed to get mix format\n")); + WLog_ERR(TAG, "Failed to get mix format"); exit(1); } @@ -218,21 +216,21 @@ DWORD WINAPI wf_rdpsnd_wasapi_thread(LPVOID lpParam) if (FAILED(hr)) { - _tprintf(_T("Failed to initialize the audio client\n")); + WLog_ERR(TAG, "Failed to initialize the audio client"); exit(1); } hr = pAudioClient->lpVtbl->GetBufferSize(pAudioClient, &bufferFrameCount); if (FAILED(hr)) { - _tprintf(_T("Failed to get buffer size\n")); + WLog_ERR(TAG, "Failed to get buffer size"); exit(1); } hr = pAudioClient->lpVtbl->GetService(pAudioClient, &IID_IAudioCaptureClient, (void **) &pCaptureClient); if (FAILED(hr)) { - _tprintf(_T("Failed to get the capture client\n")); + WLog_ERR(TAG, "Failed to get the capture client"); exit(1); } @@ -241,12 +239,13 @@ DWORD WINAPI wf_rdpsnd_wasapi_thread(LPVOID lpParam) hr = pAudioClient->lpVtbl->Start(pAudioClient); if (FAILED(hr)) { - _tprintf(_T("Failed to start capture\n")); + WLog_ERR(TAG, "Failed to start capture"); exit(1); } dCount = 0; - while(wfi->snd_stop == FALSE) + + while (wfi->snd_stop == FALSE) { DWORD flags; @@ -255,7 +254,7 @@ DWORD WINAPI wf_rdpsnd_wasapi_thread(LPVOID lpParam) hr = pCaptureClient->lpVtbl->GetNextPacketSize(pCaptureClient, &packetLength); if (FAILED(hr)) { - _tprintf(_T("Failed to get packet length\n")); + WLog_ERR(TAG, "Failed to get packet length"); exit(1); } @@ -264,7 +263,7 @@ DWORD WINAPI wf_rdpsnd_wasapi_thread(LPVOID lpParam) hr = pCaptureClient->lpVtbl->GetBuffer(pCaptureClient, &pData, &numFramesAvailable, &flags, NULL, NULL); if (FAILED(hr)) { - _tprintf(_T("Failed to get buffer\n")); + WLog_ERR(TAG, "Failed to get buffer"); exit(1); } @@ -276,14 +275,14 @@ DWORD WINAPI wf_rdpsnd_wasapi_thread(LPVOID lpParam) hr = pCaptureClient->lpVtbl->ReleaseBuffer(pCaptureClient, numFramesAvailable); if (FAILED(hr)) { - _tprintf(_T("Failed to release buffer\n")); + WLog_ERR(TAG, "Failed to release buffer"); exit(1); } hr = pCaptureClient->lpVtbl->GetNextPacketSize(pCaptureClient, &packetLength); if (FAILED(hr)) { - _tprintf(_T("Failed to get packet length\n")); + WLog_ERR(TAG, "Failed to get packet length"); exit(1); } } @@ -292,7 +291,7 @@ DWORD WINAPI wf_rdpsnd_wasapi_thread(LPVOID lpParam) pAudioClient->lpVtbl->Stop(pAudioClient); if (FAILED(hr)) { - _tprintf(_T("Failed to stop audio client\n")); + WLog_ERR(TAG, "Failed to stop audio client"); exit(1); } diff --git a/server/shadow/Win/win_dxgi.c b/server/shadow/Win/win_dxgi.c index bb4c71a99..bd2f5d62b 100644 --- a/server/shadow/Win/win_dxgi.c +++ b/server/shadow/Win/win_dxgi.c @@ -22,9 +22,12 @@ #include #include +#include #include "win_dxgi.h" +#define TAG SERVER_TAG("shadow.win") + #ifdef WITH_DXGI_1_2 static D3D_DRIVER_TYPE DriverTypes[] = @@ -247,7 +250,7 @@ int win_shadow_dxgi_init_duplication(winShadowSubsystem* subsystem) if (FAILED(hr)) { - fprintf(stderr, "ID3D11Device::QueryInterface(IDXGIDevice) failure: %s (0x%04X)\n", + WLog_ERR(TAG, "ID3D11Device::QueryInterface(IDXGIDevice) failure: %s (0x%04X)", GetDxgiErrorString(hr), hr); return -1; } @@ -262,7 +265,7 @@ int win_shadow_dxgi_init_duplication(winShadowSubsystem* subsystem) if (FAILED(hr)) { - fprintf(stderr, "IDXGIDevice::GetParent(IDXGIAdapter) failure: %s (0x%04X)\n", + WLog_ERR(TAG, "IDXGIDevice::GetParent(IDXGIAdapter) failure: %s (0x%04X)", GetDxgiErrorString(hr), hr); return -1; } @@ -278,7 +281,7 @@ int win_shadow_dxgi_init_duplication(winShadowSubsystem* subsystem) if (FAILED(hr)) { - fprintf(stderr, "IDXGIOutput::GetDesc failure: %s (0x%04X)\n", + WLog_ERR(TAG, "IDXGIOutput::GetDesc failure: %s (0x%04X)", GetDxgiErrorString(hr), hr); return -1; } @@ -302,7 +305,7 @@ int win_shadow_dxgi_init_duplication(winShadowSubsystem* subsystem) if (FAILED(hr)) { - fprintf(stderr, "IDXGIAdapter::EnumOutputs failure: %s (0x%04X)\n", + WLog_ERR(TAG, "IDXGIAdapter::EnumOutputs failure: %s (0x%04X)", GetDxgiErrorString(hr), hr); return -1; } @@ -317,7 +320,7 @@ int win_shadow_dxgi_init_duplication(winShadowSubsystem* subsystem) if (FAILED(hr)) { - fprintf(stderr, "IDXGIOutput::QueryInterface(IDXGIOutput1) failure: %s (0x%04X)\n", + WLog_ERR(TAG, "IDXGIOutput::QueryInterface(IDXGIOutput1) failure: %s (0x%04X)", GetDxgiErrorString(hr), hr); return -1; } @@ -333,7 +336,7 @@ int win_shadow_dxgi_init_duplication(winShadowSubsystem* subsystem) if (FAILED(hr)) { - fprintf(stderr, "IDXGIOutput1::DuplicateOutput failure: %s (0x%04X)\n", + WLog_ERR(TAG, "IDXGIOutput1::DuplicateOutput failure: %s (0x%04X)", GetDxgiErrorString(hr), hr); return -1; } @@ -355,7 +358,7 @@ int win_shadow_dxgi_init_duplication(winShadowSubsystem* subsystem) if (FAILED(hr)) { - fprintf(stderr, "ID3D11Device::CreateTexture2D failure: %s (0x%04X)\n", + WLog_ERR(TAG, "ID3D11Device::CreateTexture2D failure: %s (0x%04X)", GetDxgiErrorString(hr), hr); return -1; } @@ -391,7 +394,7 @@ int win_shadow_dxgi_init(winShadowSubsystem* subsystem) if (FAILED(hr)) { - fprintf(stderr, "D3D11CreateDevice failure: 0x%04X\n", hr); + WLog_ERR(TAG, "D3D11CreateDevice failure: 0x%04X", hr); return -1; } @@ -461,7 +464,7 @@ int win_shadow_dxgi_fetch_frame_data(winShadowSubsystem* subsystem, if (FAILED(hr)) { - fprintf(stderr, "ID3D11Texture2D::QueryInterface(IDXGISurface) failure: %s 0x%04X\n", + WLog_ERR(TAG, "ID3D11Texture2D::QueryInterface(IDXGISurface) failure: %s 0x%04X", GetDxgiErrorString(hr), hr); return -1; } @@ -470,7 +473,7 @@ int win_shadow_dxgi_fetch_frame_data(winShadowSubsystem* subsystem, if (FAILED(hr)) { - fprintf(stderr, "IDXGISurface::Map failure: %s 0x%04X\n", + WLog_ERR(TAG, "IDXGISurface::Map failure: %s 0x%04X", GetDxgiErrorString(hr), hr); if (hr == DXGI_ERROR_DEVICE_REMOVED) @@ -558,7 +561,7 @@ int win_shadow_dxgi_get_next_frame(winShadowSubsystem* subsystem) if (FAILED(hr)) { - fprintf(stderr, "IDXGIOutputDuplication::AcquireNextFrame failure: %s (0x%04X)\n", + WLog_ERR(TAG, "IDXGIOutputDuplication::AcquireNextFrame failure: %s (0x%04X)", GetDxgiErrorString(hr), hr); if (hr == DXGI_ERROR_ACCESS_LOST) @@ -610,7 +613,7 @@ int win_shadow_dxgi_get_next_frame(winShadowSubsystem* subsystem) if (FAILED(hr)) { - fprintf(stderr, "IDXGIResource::QueryInterface(ID3D11Texture2D) failure: %s (0x%04X)\n", + WLog_ERR(TAG, "IDXGIResource::QueryInterface(ID3D11Texture2D) failure: %s (0x%04X)", GetDxgiErrorString(hr), hr); return -1; } @@ -666,7 +669,7 @@ int win_shadow_dxgi_get_invalid_region(winShadowSubsystem* subsystem) if (FAILED(hr)) { - fprintf(stderr, "IDXGIOutputDuplication::GetFrameMoveRects failure: %s (0x%04X) Size: %d Total %d Used: %d\n", + WLog_ERR(TAG, "IDXGIOutputDuplication::GetFrameMoveRects failure: %s (0x%04X) Size: %d Total %d Used: %d", GetDxgiErrorString(hr), hr, MoveRectsBufferSize, MetadataBufferSize, UsedBufferSize); return -1; } @@ -683,7 +686,7 @@ int win_shadow_dxgi_get_invalid_region(winShadowSubsystem* subsystem) if (FAILED(hr)) { - fprintf(stderr, "IDXGIOutputDuplication::GetFrameDirtyRects failure: %s (0x%04X) Size: %d Total %d Used: %d\n", + WLog_ERR(TAG, "IDXGIOutputDuplication::GetFrameDirtyRects failure: %s (0x%04X) Size: %d Total %d Used: %d", GetDxgiErrorString(hr), hr, DirtyRectsBufferSize, MetadataBufferSize, UsedBufferSize); return -1; } diff --git a/server/shadow/Win/win_rdp.c b/server/shadow/Win/win_rdp.c index eef6fd724..55f7382f0 100644 --- a/server/shadow/Win/win_rdp.c +++ b/server/shadow/Win/win_rdp.c @@ -22,21 +22,24 @@ #include #include +#include #include "win_rdp.h" +#define TAG SERVER_TAG("shadow.win") + void shw_OnChannelConnectedEventHandler(rdpContext* context, ChannelConnectedEventArgs* e) { shwContext* shw = (shwContext*) context; - printf("OnChannelConnected: %s\n", e->name); + WLog_INFO(TAG, "OnChannelConnected: %s", e->name); } void shw_OnChannelDisconnectedEventHandler(rdpContext* context, ChannelDisconnectedEventArgs* e) { shwContext* shw = (shwContext*) context; - printf("OnChannelDisconnected: %s\n", e->name); + WLog_INFO(TAG, "OnChannelDisconnected: %s", e->name); } void shw_begin_paint(rdpContext* context) @@ -106,7 +109,7 @@ int shw_verify_x509_certificate(freerdp* instance, BYTE* data, int length, const void shw_OnConnectionResultEventHandler(rdpContext* context, ConnectionResultEventArgs* e) { shwContext* shw = (shwContext*) context; - printf("OnConnectionResult: %d\n", e->result); + WLog_INFO(TAG, "OnConnectionResult: %d", e->result); } BOOL shw_pre_connect(freerdp* instance) @@ -177,7 +180,7 @@ void* shw_client_thread(void* arg) bSuccess = freerdp_connect(instance); - printf("freerdp_connect: %d\n", bSuccess); + WLog_INFO(TAG, "freerdp_connect: %d", bSuccess); if (!bSuccess) { @@ -194,13 +197,13 @@ void* shw_client_thread(void* arg) if (!freerdp_get_fds(instance, rfds, &rcount, wfds, &wcount)) { - fprintf(stderr, "Failed to get FreeRDP file descriptor\n"); + WLog_ERR(TAG, "Failed to get FreeRDP file descriptor"); break; } if (!freerdp_channels_get_fds(channels, instance, rfds, &rcount, wfds, &wcount)) { - fprintf(stderr, "Failed to get channels file descriptor\n"); + WLog_ERR(TAG, "Failed to get channels file descriptor"); break; } @@ -214,13 +217,13 @@ void* shw_client_thread(void* arg) if (MsgWaitForMultipleObjects(fds_count, fds, FALSE, 1000, QS_ALLINPUT) == WAIT_FAILED) { - fprintf(stderr, "MsgWaitForMultipleObjects failure: 0x%08X", GetLastError()); + WLog_ERR(TAG, "MsgWaitForMultipleObjects failure: 0x%08X", GetLastError()); break; } if (!freerdp_check_fds(instance)) { - fprintf(stderr, "Failed to check FreeRDP file descriptor\n"); + WLog_ERR(TAG, "Failed to check FreeRDP file descriptor"); break; } @@ -231,7 +234,7 @@ void* shw_client_thread(void* arg) if (!freerdp_channels_check_fds(channels, instance)) { - fprintf(stderr, "Failed to check channels file descriptor\n"); + WLog_ERR(TAG, "Failed to check channels file descriptor"); break; } } diff --git a/server/shadow/Win/win_shadow.c b/server/shadow/Win/win_shadow.c index a2299d808..2d8138687 100644 --- a/server/shadow/Win/win_shadow.c +++ b/server/shadow/Win/win_shadow.c @@ -22,6 +22,7 @@ #include #include +#include #include "../shadow_screen.h" #include "../shadow_surface.h" @@ -29,6 +30,8 @@ #include "win_shadow.h" +#define TAG SERVER_TAG("shadow.win") + void win_shadow_input_synchronize_event(winShadowSubsystem* subsystem, UINT32 flags) { @@ -252,7 +255,7 @@ int win_shadow_surface_copy(winShadowSubsystem* subsystem) height = surface->height; } - printf("SurfaceCopy x: %d y: %d width: %d height: %d right: %d bottom: %d\n", + WLog_INFO(TAG, "SurfaceCopy x: %d y: %d width: %d height: %d right: %d bottom: %d", x, y, width, height, x + width, y + height); #if defined(WITH_WDS_API) @@ -441,7 +444,7 @@ int win_shadow_subsystem_init(winShadowSubsystem* subsystem) subsystem->monitors[0].flags = 1; } - printf("width: %d height: %d\n", subsystem->width, subsystem->height); + WLog_INFO(TAG, "width: %d height: %d", subsystem->width, subsystem->height); return 1; } diff --git a/server/shadow/Win/win_wds.c b/server/shadow/Win/win_wds.c index 52e2d1cec..f4b0ec956 100644 --- a/server/shadow/Win/win_wds.c +++ b/server/shadow/Win/win_wds.c @@ -22,6 +22,7 @@ #include #include +#include #include "win_rdp.h" @@ -46,6 +47,8 @@ #include +#define TAG SERVER_TAG("shadow.win") + DEFINE_GUID(CLSID_RDPSession,0x9B78F0E6,0x3E05,0x4A5B,0xB2,0xE8,0xE7,0x43,0xA8,0x95,0x6B,0x65); DEFINE_GUID(DIID__IRDPSessionEvents,0x98a97042,0x6698,0x40e9,0x8e,0xfd,0xb3,0x20,0x09,0x90,0x00,0x4b); DEFINE_GUID(IID_IRDPSRAPISharingSession,0xeeb20886,0xe470,0x4cf6,0x84,0x2b,0x27,0x39,0xc0,0xec,0x5c,0xfb); @@ -213,7 +216,7 @@ static HRESULT STDMETHODCALLTYPE Shadow_IRDPSessionEvents_GetTypeInfoCount( __RPC__in _IRDPSessionEvents * This, /* [out] */ __RPC__out UINT *pctinfo) { - printf("Shadow_IRDPSessionEvents_GetTypeInfoCount\n"); + WLog_INFO(TAG, "Shadow_IRDPSessionEvents_GetTypeInfoCount"); *pctinfo = 1; return S_OK; } @@ -224,7 +227,7 @@ static HRESULT STDMETHODCALLTYPE Shadow_IRDPSessionEvents_GetTypeInfo( /* [in] */ LCID lcid, /* [out] */ __RPC__deref_out_opt ITypeInfo **ppTInfo) { - printf("Shadow_IRDPSessionEvents_GetTypeInfo\n"); + WLog_INFO(TAG, "Shadow_IRDPSessionEvents_GetTypeInfo"); return E_NOTIMPL; } @@ -236,7 +239,7 @@ static HRESULT STDMETHODCALLTYPE Shadow_IRDPSessionEvents_GetIDsOfNames( /* [in] */ LCID lcid, /* [size_is][out] */ __RPC__out_ecount_full(cNames) DISPID *rgDispId) { - printf("Shadow_IRDPSessionEvents_GetIDsOfNames\n"); + WLog_INFO(TAG, "Shadow_IRDPSessionEvents_GetIDsOfNames"); return E_NOTIMPL; } @@ -263,7 +266,7 @@ static HRESULT STDMETHODCALLTYPE Shadow_IRDPSessionEvents_Invoke( VARIANT vr; UINT uArgErr; - printf("%s (%d)\n", GetRDPSessionEventString(dispIdMember), dispIdMember); + WLog_INFO(TAG, "%s (%d)", GetRDPSessionEventString(dispIdMember), dispIdMember); switch (dispIdMember) { @@ -280,7 +283,7 @@ static HRESULT STDMETHODCALLTYPE Shadow_IRDPSessionEvents_Invoke( if (FAILED(hr)) { - printf("%s DispGetParam(0, VT_DISPATCH) failure: 0x%08X\n", + WLog_INFO(TAG, "%s DispGetParam(0, VT_DISPATCH) failure: 0x%08X", GetRDPSessionEventString(dispIdMember), hr); return hr; } @@ -291,7 +294,7 @@ static HRESULT STDMETHODCALLTYPE Shadow_IRDPSessionEvents_Invoke( if (FAILED(hr)) { - printf("%s IDispatch::QueryInterface(IRDPSRAPIAttendee) failure: 0x%08X\n", + WLog_INFO(TAG, "%s IDispatch::QueryInterface(IRDPSRAPIAttendee) failure: 0x%08X", GetRDPSessionEventString(dispIdMember), hr); return hr; } @@ -303,7 +306,7 @@ static HRESULT STDMETHODCALLTYPE Shadow_IRDPSessionEvents_Invoke( if (FAILED(hr)) { - printf("%s IRDPSRAPIAttendee::put_ControlLevel() failure: 0x%08X\n", + WLog_INFO(TAG, "%s IRDPSRAPIAttendee::put_ControlLevel() failure: 0x%08X", GetRDPSessionEventString(dispIdMember), hr); return hr; } @@ -346,7 +349,7 @@ static HRESULT STDMETHODCALLTYPE Shadow_IRDPSessionEvents_Invoke( if (FAILED(hr)) { - printf("%s DispGetParam(1, VT_INT) failure: 0x%08X\n", + WLog_INFO(TAG, "%s DispGetParam(1, VT_INT) failure: 0x%08X", GetRDPSessionEventString(dispIdMember), hr); return hr; } @@ -360,7 +363,7 @@ static HRESULT STDMETHODCALLTYPE Shadow_IRDPSessionEvents_Invoke( if (FAILED(hr)) { - printf("%s DispGetParam(0, VT_DISPATCH) failure: 0x%08X\n", + WLog_INFO(TAG, "%s DispGetParam(0, VT_DISPATCH) failure: 0x%08X", GetRDPSessionEventString(dispIdMember), hr); return hr; } @@ -371,7 +374,7 @@ static HRESULT STDMETHODCALLTYPE Shadow_IRDPSessionEvents_Invoke( if (FAILED(hr)) { - printf("%s IDispatch::QueryInterface(IRDPSRAPIAttendee) failure: 0x%08X\n", + WLog_INFO(TAG, "%s IDispatch::QueryInterface(IRDPSRAPIAttendee) failure: 0x%08X", GetRDPSessionEventString(dispIdMember), hr); return hr; } @@ -380,7 +383,7 @@ static HRESULT STDMETHODCALLTYPE Shadow_IRDPSessionEvents_Invoke( if (FAILED(hr)) { - printf("%s IRDPSRAPIAttendee::put_ControlLevel() failure: 0x%08X\n", + WLog_INFO(TAG, "%s IRDPSRAPIAttendee::put_ControlLevel() failure: 0x%08X", GetRDPSessionEventString(dispIdMember), hr); return hr; } @@ -507,7 +510,7 @@ int win_shadow_wds_wnd_init(winShadowSubsystem* subsystem) if (!RegisterClassEx(&wndClassEx)) { - printf("RegisterClassEx failure\n"); + WLog_INFO(TAG, "RegisterClassEx failure"); return -1; } @@ -518,7 +521,7 @@ int win_shadow_wds_wnd_init(winShadowSubsystem* subsystem) if (!subsystem->hWnd) { - printf("CreateWindowEx failure\n"); + WLog_INFO(TAG, "CreateWindowEx failure"); return -1; } @@ -551,7 +554,7 @@ int win_shadow_wds_init(winShadowSubsystem* subsystem) if (FAILED(hr)) { - fprintf(stderr, "OleInitialize() failure\n"); + WLog_ERR(TAG, "OleInitialize() failure"); return -1; } @@ -559,7 +562,7 @@ int win_shadow_wds_init(winShadowSubsystem* subsystem) if (FAILED(hr)) { - fprintf(stderr, "CoInitialize() failure\n"); + WLog_ERR(TAG, "CoInitialize() failure"); return -1; } @@ -568,7 +571,7 @@ int win_shadow_wds_init(winShadowSubsystem* subsystem) if (FAILED(hr)) { - fprintf(stderr, "CoCreateInstance(IRDPSRAPISharingSession) failure: 0x%08X\n", hr); + WLog_ERR(TAG, "CoCreateInstance(IRDPSRAPISharingSession) failure: 0x%08X", hr); return -1; } @@ -577,7 +580,7 @@ int win_shadow_wds_init(winShadowSubsystem* subsystem) if (FAILED(hr)) { - fprintf(stderr, "QueryInterface(IID_IConnectionPointContainer) failure: 0x%08X\n", hr); + WLog_ERR(TAG, "QueryInterface(IID_IConnectionPointContainer) failure: 0x%08X", hr); return -1; } @@ -585,7 +588,7 @@ int win_shadow_wds_init(winShadowSubsystem* subsystem) if (FAILED(hr)) { - fprintf(stderr, "IConnectionPointContainer::FindConnectionPoint(_IRDPSessionEvents) failure: 0x%08X\n", hr); + WLog_ERR(TAG, "IConnectionPointContainer::FindConnectionPoint(_IRDPSessionEvents) failure: 0x%08X", hr); return -1; } @@ -597,7 +600,7 @@ int win_shadow_wds_init(winShadowSubsystem* subsystem) if (FAILED(hr)) { - fprintf(stderr, "IConnectionPoint::Advise(Shadow_IRDPSessionEvents) failure: 0x%08X\n", hr); + WLog_ERR(TAG, "IConnectionPoint::Advise(Shadow_IRDPSessionEvents) failure: 0x%08X", hr); return -1; } @@ -605,7 +608,7 @@ int win_shadow_wds_init(winShadowSubsystem* subsystem) if (FAILED(hr)) { - fprintf(stderr, "IRDPSRAPISharingSession::put_ColorDepth() failure: 0x%08X\n", hr); + WLog_ERR(TAG, "IRDPSRAPISharingSession::put_ColorDepth() failure: 0x%08X", hr); return -1; } @@ -614,14 +617,14 @@ int win_shadow_wds_init(winShadowSubsystem* subsystem) if (FAILED(hr)) { - fprintf(stderr, "IRDPSRAPISharingSession::GetDesktopSharedRect() failure: 0x%08X\n", hr); + WLog_ERR(TAG, "IRDPSRAPISharingSession::GetDesktopSharedRect() failure: 0x%08X", hr); return -1; } width = right - left; height = bottom - top; - printf("GetDesktopSharedRect(): left: %d top: %d right: %d bottom: %d width: %d height: %d\n", + WLog_INFO(TAG, "GetDesktopSharedRect(): left: %d top: %d right: %d bottom: %d width: %d height: %d", left, top, right, bottom, width, height); hr = subsystem->pSharingSession->lpVtbl->get_VirtualChannelManager(subsystem->pSharingSession, @@ -629,7 +632,7 @@ int win_shadow_wds_init(winShadowSubsystem* subsystem) if (FAILED(hr)) { - fprintf(stderr, "IRDPSRAPISharingSession::get_VirtualChannelManager() failure: 0x%08X\n", hr); + WLog_ERR(TAG, "IRDPSRAPISharingSession::get_VirtualChannelManager() failure: 0x%08X", hr); return -1; } @@ -638,7 +641,7 @@ int win_shadow_wds_init(winShadowSubsystem* subsystem) if (FAILED(hr)) { - fprintf(stderr, "IRDPSRAPISharingSession::get_ApplicationFilter() failure: 0x%08X\n", hr); + WLog_ERR(TAG, "IRDPSRAPISharingSession::get_ApplicationFilter() failure: 0x%08X", hr); return -1; } @@ -647,7 +650,7 @@ int win_shadow_wds_init(winShadowSubsystem* subsystem) if (FAILED(hr)) { - fprintf(stderr, "IRDPSRAPISharingSession::get_Attendees() failure: 0x%08X\n", hr); + WLog_ERR(TAG, "IRDPSRAPISharingSession::get_Attendees() failure: 0x%08X", hr); return -1; } @@ -655,7 +658,7 @@ int win_shadow_wds_init(winShadowSubsystem* subsystem) if (FAILED(hr)) { - fprintf(stderr, "IRDPSRAPISharingSession::get_Properties() failure: 0x%08X\n", hr); + WLog_ERR(TAG, "IRDPSRAPISharingSession::get_Properties() failure: 0x%08X", hr); return -1; } @@ -670,7 +673,7 @@ int win_shadow_wds_init(winShadowSubsystem* subsystem) if (FAILED(hr)) { - fprintf(stderr, "IRDPSRAPISessionProperties::put_Property(PortId) failure: 0x%08X\n", hr); + WLog_ERR(TAG, "IRDPSRAPISessionProperties::put_Property(PortId) failure: 0x%08X", hr); return -1; } @@ -685,7 +688,7 @@ int win_shadow_wds_init(winShadowSubsystem* subsystem) if (FAILED(hr)) { - fprintf(stderr, "IRDPSRAPISessionProperties::put_Property(DrvConAttach) failure: 0x%08X\n", hr); + WLog_ERR(TAG, "IRDPSRAPISessionProperties::put_Property(DrvConAttach) failure: 0x%08X", hr); return -1; } @@ -703,7 +706,7 @@ int win_shadow_wds_init(winShadowSubsystem* subsystem) if (FAILED(hr)) { - fprintf(stderr, "IRDPSRAPISessionProperties::put_Property(PortProtocol) failure: 0x%08X\n", hr); + WLog_ERR(TAG, "IRDPSRAPISessionProperties::put_Property(PortProtocol) failure: 0x%08X", hr); return -1; } @@ -711,7 +714,7 @@ int win_shadow_wds_init(winShadowSubsystem* subsystem) if (FAILED(hr)) { - fprintf(stderr, "IRDPSRAPISharingSession::Open() failure: 0x%08X\n", hr); + WLog_ERR(TAG, "IRDPSRAPISharingSession::Open() failure: 0x%08X", hr); return -1; } @@ -720,7 +723,7 @@ int win_shadow_wds_init(winShadowSubsystem* subsystem) if (FAILED(hr)) { - fprintf(stderr, "IRDPSRAPISharingSession::get_Invitations() failure\n"); + WLog_ERR(TAG, "IRDPSRAPISharingSession::get_Invitations() failure"); return -1; } @@ -737,7 +740,7 @@ int win_shadow_wds_init(winShadowSubsystem* subsystem) if (FAILED(hr)) { - fprintf(stderr, "IRDPSRAPIInvitationManager::CreateInvitation() failure: 0x%08X\n", hr); + WLog_ERR(TAG, "IRDPSRAPIInvitationManager::CreateInvitation() failure: 0x%08X", hr); return -1; } @@ -745,7 +748,7 @@ int win_shadow_wds_init(winShadowSubsystem* subsystem) if (FAILED(hr)) { - fprintf(stderr, "IRDPSRAPIInvitation::get_ConnectionString() failure: 0x%08X\n", hr); + WLog_ERR(TAG, "IRDPSRAPIInvitation::get_ConnectionString() failure: 0x%08X", hr); return -1; } @@ -759,7 +762,7 @@ int win_shadow_wds_init(winShadowSubsystem* subsystem) if (status < 0) return -1; - printf("ConnectionString: %s\n", file->ConnectionString2); + WLog_INFO(TAG, "ConnectionString: %s", file->ConnectionString2); if (0) { @@ -781,7 +784,7 @@ int win_shadow_wds_init(winShadowSubsystem* subsystem) if (status < 0) { - printf("win_shadow_rdp_init() failure: %d\n", status); + WLog_INFO(TAG, "win_shadow_rdp_init() failure: %d", status); return status; } @@ -808,7 +811,7 @@ int win_shadow_wds_init(winShadowSubsystem* subsystem) if (status < 0) { - printf("win_shadow_rdp_start() failure: %d\n", status); + WLog_INFO(TAG, "win_shadow_rdp_start() failure: %d", status); return status; } diff --git a/server/shadow/X11/x11_shadow.c b/server/shadow/X11/x11_shadow.c index ffd068e60..6594e7156 100644 --- a/server/shadow/X11/x11_shadow.c +++ b/server/shadow/X11/x11_shadow.c @@ -36,6 +36,7 @@ #include #include +#include #include "../shadow_screen.h" #include "../shadow_capture.h" @@ -43,6 +44,8 @@ #include "x11_shadow.h" +#define TAG SERVER_TAG("shadow.x11") + void x11_shadow_input_synchronize_event(x11ShadowSubsystem* subsystem, UINT32 flags) { @@ -474,7 +477,7 @@ int x11_shadow_xshm_init(x11ShadowSubsystem* subsystem) if (!subsystem->fb_image) { - fprintf(stderr, "XShmCreateImage failed\n"); + WLog_ERR(TAG, "XShmCreateImage failed"); return -1; } @@ -483,7 +486,7 @@ int x11_shadow_xshm_init(x11ShadowSubsystem* subsystem) if (subsystem->fb_shm_info.shmid == -1) { - fprintf(stderr, "shmget failed\n"); + WLog_ERR(TAG, "shmget failed"); return -1; } @@ -492,7 +495,7 @@ int x11_shadow_xshm_init(x11ShadowSubsystem* subsystem) if (subsystem->fb_shm_info.shmaddr == ((char*) -1)) { - fprintf(stderr, "shmat failed\n"); + WLog_ERR(TAG, "shmat failed"); return -1; } @@ -556,7 +559,7 @@ int x11_shadow_subsystem_init(x11ShadowSubsystem* subsystem) if (!subsystem->display) { - fprintf(stderr, "failed to open display: %s\n", XDisplayName(NULL)); + WLog_ERR(TAG, "failed to open display: %s", XDisplayName(NULL)); return -1; } @@ -591,7 +594,7 @@ int x11_shadow_subsystem_init(x11ShadowSubsystem* subsystem) if (!pfs) { - fprintf(stderr, "XListPixmapFormats failed\n"); + WLog_ERR(TAG, "XListPixmapFormats failed"); return -1; } @@ -616,7 +619,7 @@ int x11_shadow_subsystem_init(x11ShadowSubsystem* subsystem) if (!vis) { - fprintf(stderr, "XGetVisualInfo failed\n"); + WLog_ERR(TAG, "XGetVisualInfo failed"); return -1; } @@ -678,7 +681,7 @@ int x11_shadow_subsystem_init(x11ShadowSubsystem* subsystem) subsystem->monitors[0].flags = 1; } - printf("X11 Extensions: XFixes: %d Xinerama: %d XDamage: %d XShm: %d\n", + WLog_INFO(TAG, "X11 Extensions: XFixes: %d Xinerama: %d XDamage: %d XShm: %d", subsystem->use_xfixes, subsystem->use_xinerama, subsystem->use_xdamage, subsystem->use_xshm); return 1; diff --git a/server/shadow/shadow_capture.c b/server/shadow/shadow_capture.c index 9f07ac964..644ebdb86 100644 --- a/server/shadow/shadow_capture.c +++ b/server/shadow/shadow_capture.c @@ -23,10 +23,14 @@ #include #include +#include + #include "shadow_surface.h" #include "shadow_capture.h" +#define TAG SERVER_TAG("shadow") + int shadow_capture_align_clip_rect(RECTANGLE_16* rect, RECTANGLE_16* clip) { int dx, dy; @@ -177,31 +181,31 @@ int shadow_capture_compare(BYTE* pData1, int nStep1, int nWidth, int nHeight, BY if (0) { - printf("\n"); + WLog_INFO(TAG, ""); for (tx = 0; tx < ncol; tx++) - printf("-"); - printf("\n"); + WLog_INFO(TAG, "-"); + WLog_INFO(TAG, ""); for (tx = 0; tx < ncol; tx++) - printf("%s", cols[tx] ? "O" : "X"); - printf("\n"); + WLog_INFO(TAG, "%s", cols[tx] ? "O" : "X"); + WLog_INFO(TAG, ""); for (tx = 0; tx < ncol; tx++) - printf("-"); - printf("\n"); + WLog_INFO(TAG, "-"); + WLog_INFO(TAG, ""); for (ty = 0; ty < nrow; ty++) { for (tx = 0; tx < ncol; tx++) { - printf("%s", grid[ty][tx] ? "O" : "X"); + WLog_INFO(TAG, "%s", grid[ty][tx] ? "O" : "X"); } - printf("|%s|\n", rows[ty] ? "O" : "X"); + WLog_INFO(TAG, "|%s|", rows[ty] ? "O" : "X"); } - printf("left: %d top: %d right: %d bottom: %d ncol: %d nrow: %d\n", + WLog_INFO(TAG, "left: %d top: %d right: %d bottom: %d ncol: %d nrow: %d", l, t, r, b, ncol, nrow); } diff --git a/server/shadow/shadow_client.c b/server/shadow/shadow_client.c index 5098a35ea..42b17176d 100644 --- a/server/shadow/shadow_client.c +++ b/server/shadow/shadow_client.c @@ -27,8 +27,12 @@ #include #include +#include + #include "shadow.h" +#define TAG CLIENT_TAG("shadow") + void shadow_client_context_new(freerdp_peer* peer, rdpShadowClient* client) { rdpSettings* settings; @@ -121,7 +125,7 @@ BOOL shadow_client_post_connect(freerdp_peer* peer) if (settings->ColorDepth == 24) settings->ColorDepth = 16; /* disable 24bpp */ - fprintf(stderr, "Client from %s is activated (%dx%d@%d)\n", + WLog_ERR(TAG, "Client from %s is activated (%dx%d@%d)", peer->hostname, settings->DesktopWidth, settings->DesktopHeight, settings->ColorDepth); peer->update->DesktopResize(peer->update->context); @@ -570,7 +574,7 @@ int shadow_client_send_surface_update(rdpShadowClient* client) nWidth = extents->right - extents->left; nHeight = extents->bottom - extents->top; - //printf("shadow_client_send_surface_update: x: %d y: %d width: %d height: %d right: %d bottom: %d\n", + //WLog_INFO(TAG, "shadow_client_send_surface_update: x: %d y: %d width: %d height: %d right: %d bottom: %d", // nXSrc, nYSrc, nWidth, nHeight, nXSrc + nWidth, nYSrc + nHeight); if (settings->RemoteFxCodec || settings->NSCodec) @@ -702,7 +706,7 @@ void* shadow_client_thread(rdpShadowClient* client) { if (!peer->CheckFileDescriptor(peer)) { - fprintf(stderr, "Failed to check FreeRDP file descriptor\n"); + WLog_ERR(TAG, "Failed to check FreeRDP file descriptor"); break; } } @@ -711,7 +715,7 @@ void* shadow_client_thread(rdpShadowClient* client) { if (WTSVirtualChannelManagerCheckFileDescriptor(client->vcm) != TRUE) { - fprintf(stderr, "WTSVirtualChannelManagerCheckFileDescriptor failure\n"); + WLog_ERR(TAG, "WTSVirtualChannelManagerCheckFileDescriptor failure"); break; } } diff --git a/server/shadow/shadow_encomsp.c b/server/shadow/shadow_encomsp.c index f0b1d48e3..ad0be4870 100644 --- a/server/shadow/shadow_encomsp.c +++ b/server/shadow/shadow_encomsp.c @@ -20,10 +20,13 @@ #include "config.h" #endif +#include #include "shadow.h" #include "shadow_encomsp.h" +#define TAG SERVER_TAG("shadow") + static int encomsp_change_participant_control_level(EncomspServerContext* context, ENCOMSP_CHANGE_PARTICIPANT_CONTROL_LEVEL_PDU* pdu) { @@ -32,7 +35,7 @@ static int encomsp_change_participant_control_level(EncomspServerContext* contex BOOL mayInteract; rdpShadowClient* client = (rdpShadowClient*) context->custom; - printf("ChangeParticipantControlLevel: ParticipantId: %d Flags: 0x%04X\n", + WLog_INFO(TAG, "ChangeParticipantControlLevel: ParticipantId: %d Flags: 0x%04X", pdu->ParticipantId, pdu->Flags); mayView = (pdu->Flags & ENCOMSP_MAY_VIEW) ? TRUE : FALSE; diff --git a/server/shadow/shadow_server.c b/server/shadow/shadow_server.c index c990d1fcf..e2a3256e2 100644 --- a/server/shadow/shadow_server.c +++ b/server/shadow/shadow_server.c @@ -28,6 +28,7 @@ #include #include +#include #include @@ -42,6 +43,8 @@ #include "shadow.h" +#define TAG SERVER_TAG("shadow") + #ifdef _WIN32 static BOOL g_MessagePump = TRUE; #else @@ -78,14 +81,14 @@ int shadow_server_print_command_line_help(int argc, char** argv) int length; COMMAND_LINE_ARGUMENT_A* arg; - printf("Usage: %s [options]\n", argv[0]); - printf("\n"); + WLog_INFO(TAG, "Usage: %s [options]", argv[0]); + WLog_INFO(TAG, ""); - printf("Syntax:\n"); - printf(" /flag (enables flag)\n"); - printf(" /option: (specifies option with value)\n"); - printf(" +toggle -toggle (enables or disables toggle, where '/' is a synonym of '+')\n"); - printf("\n"); + WLog_INFO(TAG, "Syntax:"); + WLog_INFO(TAG, " /flag (enables flag)"); + WLog_INFO(TAG, " /option: (specifies option with value)"); + WLog_INFO(TAG, " +toggle -toggle (enables or disables toggle, where '/' is a synonym of '+')"); + WLog_INFO(TAG, ""); arg = shadow_args; @@ -93,28 +96,28 @@ int shadow_server_print_command_line_help(int argc, char** argv) { if (arg->Flags & COMMAND_LINE_VALUE_FLAG) { - printf(" %s", "/"); - printf("%-20s", arg->Name); - printf("\t%s\n", arg->Text); + WLog_INFO(TAG, " %s", "/"); + WLog_INFO(TAG, "%-20s", arg->Name); + WLog_INFO(TAG, "\t%s", arg->Text); } else if ((arg->Flags & COMMAND_LINE_VALUE_REQUIRED) || (arg->Flags & COMMAND_LINE_VALUE_OPTIONAL)) { - printf(" %s", "/"); + WLog_INFO(TAG, " %s", "/"); if (arg->Format) { length = (int) (strlen(arg->Name) + strlen(arg->Format) + 2); str = (char*) malloc(length + 1); sprintf_s(str, length + 1, "%s:%s", arg->Name, arg->Format); - printf("%-20s", str); + WLog_INFO(TAG, "%-20s", str); free(str); } else { - printf("%-20s", arg->Name); + WLog_INFO(TAG, "%-20s", arg->Name); } - printf("\t%s\n", arg->Text); + WLog_INFO(TAG, "\t%s", arg->Text); } else if (arg->Flags & COMMAND_LINE_VALUE_BOOL) { @@ -123,12 +126,12 @@ int shadow_server_print_command_line_help(int argc, char** argv) sprintf_s(str, length + 1, "%s (default:%s)", arg->Name, arg->Default ? "on" : "off"); - printf(" %s", arg->Default ? "-" : "+"); + WLog_INFO(TAG, " %s", arg->Default ? "-" : "+"); - printf("%-20s", str); + WLog_INFO(TAG, "%-20s", str); free(str); - printf("\t%s\n", arg->Text); + WLog_INFO(TAG, "\t%s", arg->Text); } } while ((arg = CommandLineFindNextArgumentA(arg)) != NULL); @@ -140,7 +143,7 @@ int shadow_server_command_line_status_print(rdpShadowServer* server, int argc, c { if (status == COMMAND_LINE_STATUS_PRINT_VERSION) { - printf("FreeRDP version %s (git %s)\n", FREERDP_VERSION_FULL, GIT_REVISION); + WLog_INFO(TAG, "FreeRDP version %s (git %s)", FREERDP_VERSION_FULL, GIT_REVISION); return COMMAND_LINE_STATUS_PRINT_VERSION; } else if (status == COMMAND_LINE_STATUS_PRINT) @@ -233,7 +236,7 @@ int shadow_server_parse_command_line(rdpShadowServer* server, int argc, char** a width = monitor->right - monitor->left; height = monitor->bottom - monitor->top; - printf(" %s [%d] %dx%d\t+%d+%d\n", + WLog_INFO(TAG, " %s [%d] %dx%d\t+%d+%d", (monitor->flags == 1) ? "*" : " ", index, width, height, monitor->left, monitor->top); } @@ -295,7 +298,7 @@ void* shadow_server_thread(rdpShadowServer* server) if (listener->GetEventHandles(listener, events, &nCount) < 0) { - fprintf(stderr, "Failed to get FreeRDP file descriptor\n"); + WLog_ERR(TAG, "Failed to get FreeRDP file descriptor"); break; } @@ -310,7 +313,7 @@ void* shadow_server_thread(rdpShadowServer* server) if (!listener->CheckFileDescriptor(listener)) { - fprintf(stderr, "Failed to check FreeRDP file descriptor\n"); + WLog_ERR(TAG, "Failed to check FreeRDP file descriptor"); break; } @@ -473,7 +476,7 @@ int shadow_server_init(rdpShadowServer* server) status = server->subsystem->Init(server->subsystem); if (status < 0) - fprintf(stderr, "subsystem init failure: %d\n", status); + WLog_ERR(TAG, "subsystem init failure: %d", status); } server->screen = shadow_screen_new(server);