22 #include <freerdp/config.h>
28 #include <freerdp/freerdp.h>
29 #include <freerdp/constants.h>
30 #include <freerdp/gdi/gdi.h>
31 #include <freerdp/streamdump.h>
32 #include <freerdp/utils/signal.h>
34 #include <freerdp/client/file.h>
35 #include <freerdp/client/cmdline.h>
36 #include <freerdp/client/cliprdr.h>
37 #include <freerdp/client/channels.h>
38 #include <freerdp/channels/channels.h>
40 #include <winpr/crt.h>
41 #include <winpr/assert.h>
42 #include <winpr/synch.h>
43 #include <freerdp/log.h>
45 #include "tf_channels.h"
46 #include "tf_freerdp.h"
48 #define TAG CLIENT_TAG("sample")
52 static BOOL tf_begin_paint(rdpContext* context)
56 WINPR_ASSERT(context);
60 WINPR_ASSERT(gdi->primary);
61 WINPR_ASSERT(gdi->primary->hdc);
62 WINPR_ASSERT(gdi->primary->hdc->hwnd);
63 WINPR_ASSERT(gdi->primary->hdc->hwnd->invalid);
64 gdi->primary->hdc->hwnd->invalid->null = TRUE;
72 static BOOL tf_end_paint(rdpContext* context)
76 WINPR_ASSERT(context);
80 WINPR_ASSERT(gdi->primary);
81 WINPR_ASSERT(gdi->primary->hdc);
82 WINPR_ASSERT(gdi->primary->hdc->hwnd);
83 WINPR_ASSERT(gdi->primary->hdc->hwnd->invalid);
85 if (gdi->primary->hdc->hwnd->invalid->null)
91 static BOOL tf_desktop_resize(rdpContext* context)
94 rdpSettings* settings = NULL;
96 WINPR_ASSERT(context);
98 settings = context->settings;
99 WINPR_ASSERT(settings);
107 static BOOL tf_play_sound(rdpContext* context,
const PLAY_SOUND_UPDATE* play_sound)
110 WINPR_UNUSED(context);
111 WINPR_UNUSED(play_sound);
116 static BOOL tf_keyboard_set_indicators(rdpContext* context, UINT16 led_flags)
119 WINPR_UNUSED(context);
120 WINPR_UNUSED(led_flags);
125 static BOOL tf_keyboard_set_ime_status(rdpContext* context, UINT16 imeId, UINT32 imeState,
132 "KeyboardSetImeStatus(unitId=%04" PRIx16
", imeState=%08" PRIx32
133 ", imeConvMode=%08" PRIx32
") ignored",
134 imeId, imeState, imeConvMode);
140 static BOOL tf_pre_connect(freerdp* instance)
142 rdpSettings* settings = NULL;
144 WINPR_ASSERT(instance);
145 WINPR_ASSERT(instance->context);
147 settings = instance->context->settings;
148 WINPR_ASSERT(settings);
165 PubSub_SubscribeChannelConnected(instance->context->pubSub, tf_OnChannelConnectedEventHandler);
166 PubSub_SubscribeChannelDisconnected(instance->context->pubSub,
167 tf_OnChannelDisconnectedEventHandler);
181 static BOOL tf_post_connect(freerdp* instance)
183 rdpContext* context = NULL;
185 if (!gdi_init(instance, PIXEL_FORMAT_XRGB32))
188 context = instance->context;
189 WINPR_ASSERT(context);
190 WINPR_ASSERT(context->update);
199 context->update->BeginPaint = tf_begin_paint;
200 context->update->EndPaint = tf_end_paint;
201 context->update->PlaySound = tf_play_sound;
202 context->update->DesktopResize = tf_desktop_resize;
203 context->update->SetKeyboardIndicators = tf_keyboard_set_indicators;
204 context->update->SetKeyboardImeStatus = tf_keyboard_set_ime_status;
211 static void tf_post_disconnect(freerdp* instance)
218 if (!instance->context)
222 PubSub_UnsubscribeChannelConnected(instance->context->pubSub,
223 tf_OnChannelConnectedEventHandler);
224 PubSub_UnsubscribeChannelDisconnected(instance->context->pubSub,
225 tf_OnChannelDisconnectedEventHandler);
228 WINPR_UNUSED(context);
234 static DWORD WINAPI tf_client_thread_proc(LPVOID arg)
236 freerdp* instance = (freerdp*)arg;
240 HANDLE handles[MAXIMUM_WAIT_OBJECTS] = { 0 };
241 BOOL rc = freerdp_connect(instance);
243 WINPR_ASSERT(instance->context);
244 WINPR_ASSERT(instance->context->settings);
247 result = freerdp_get_last_error(instance->context);
248 freerdp_abort_connect_context(instance->context);
249 WLog_ERR(TAG,
"Authentication only, exit status 0x%08" PRIx32
"", result);
255 result = freerdp_get_last_error(instance->context);
256 WLog_ERR(TAG,
"connection failure 0x%08" PRIx32, result);
260 while (!freerdp_shall_disconnect_context(instance->context))
262 nCount = freerdp_get_event_handles(instance->context, handles, ARRAYSIZE(handles));
266 WLog_ERR(TAG,
"freerdp_get_event_handles failed");
270 status = WaitForMultipleObjects(nCount, handles, FALSE, 100);
272 if (status == WAIT_FAILED)
274 WLog_ERR(TAG,
"WaitForMultipleObjects failed with %" PRIu32
"", status);
278 if (!freerdp_check_event_handles(instance->context))
280 if (freerdp_get_last_error(instance->context) == FREERDP_ERROR_SUCCESS)
281 WLog_ERR(TAG,
"Failed to check FreeRDP event handles");
288 freerdp_disconnect(instance);
295 static BOOL tf_client_global_init(
void)
297 if (freerdp_handle_signals() != 0)
304 static void tf_client_global_uninit(
void)
308 static int tf_logon_error_info(freerdp* instance, UINT32 data, UINT32 type)
311 const char* str_data = freerdp_get_logon_error_info_data(data);
312 const char* str_type = freerdp_get_logon_error_info_type(type);
314 if (!instance || !instance->context)
318 WLog_INFO(TAG,
"Logon Error Info %s [%s]", str_data, str_type);
324 static BOOL tf_client_new(freerdp* instance, rdpContext* context)
328 if (!instance || !context)
331 instance->PreConnect = tf_pre_connect;
332 instance->PostConnect = tf_post_connect;
333 instance->PostDisconnect = tf_post_disconnect;
334 instance->LogonErrorInfo = tf_logon_error_info;
340 static void tf_client_free(freerdp* instance, rdpContext* context)
351 static int tf_client_start(rdpContext* context)
354 WINPR_UNUSED(context);
358 static int tf_client_stop(rdpContext* context)
361 WINPR_UNUSED(context);
365 static int RdpClientEntry(RDP_CLIENT_ENTRY_POINTS* pEntryPoints)
367 WINPR_ASSERT(pEntryPoints);
369 ZeroMemory(pEntryPoints,
sizeof(RDP_CLIENT_ENTRY_POINTS));
370 pEntryPoints->Version = RDP_CLIENT_INTERFACE_VERSION;
371 pEntryPoints->Size =
sizeof(RDP_CLIENT_ENTRY_POINTS_V1);
372 pEntryPoints->GlobalInit = tf_client_global_init;
373 pEntryPoints->GlobalUninit = tf_client_global_uninit;
374 pEntryPoints->ContextSize =
sizeof(
tfContext);
375 pEntryPoints->ClientNew = tf_client_new;
376 pEntryPoints->ClientFree = tf_client_free;
377 pEntryPoints->ClientStart = tf_client_start;
378 pEntryPoints->ClientStop = tf_client_stop;
382 int main(
int argc,
char* argv[])
385 RDP_CLIENT_ENTRY_POINTS clientEntryPoints = { 0 };
387 RdpClientEntry(&clientEntryPoints);
388 rdpContext* context = freerdp_client_context_new(&clientEntryPoints);
394 freerdp_client_settings_parse_command_line(context->settings, argc, argv, FALSE);
397 rc = freerdp_client_settings_command_line_status_print(context->settings, status, argc,
402 if (!stream_dump_register_handlers(context, CONNECTION_STATE_MCS_CREATE_REQUEST, FALSE))
405 if (freerdp_client_start(context) != 0)
408 const DWORD res = tf_client_thread_proc(context->instance);
411 if (freerdp_client_stop(context) != 0)
415 freerdp_client_context_free(context);
FREERDP_API UINT32 freerdp_settings_get_uint32(const rdpSettings *settings, FreeRDP_Settings_Keys_UInt32 id)
Returns a UINT32 settings value.
FREERDP_API BOOL freerdp_settings_get_bool(const rdpSettings *settings, FreeRDP_Settings_Keys_Bool id)
Returns a boolean settings value.
FREERDP_API BOOL freerdp_settings_set_uint32(rdpSettings *settings, FreeRDP_Settings_Keys_UInt32 id, UINT32 param)
Sets a UINT32 settings value.
FREERDP_API BOOL freerdp_settings_set_bool(rdpSettings *settings, FreeRDP_Settings_Keys_Bool id, BOOL param)
Sets a BOOL settings value.