26#include <freerdp/config.h>
30#include <freerdp/types.h>
31#include <freerdp/constants.h>
32#include <freerdp/freerdp.h>
34#include "rail_orders.h"
37#include "../../../channels/client/addin.h"
39RailClientContext* rail_get_client_interface(
railPlugin* rail)
41 RailClientContext* pInterface =
nullptr;
46 pInterface = (RailClientContext*)rail->channelEntryPoints.pInterface;
62 return CHANNEL_RC_BAD_INIT_HANDLE;
65 status = rail->channelEntryPoints.pVirtualChannelWriteEx(
66 rail->InitHandle, rail->OpenHandle, Stream_Buffer(s), (UINT32)Stream_GetPosition(s), s);
68 if (status != CHANNEL_RC_OK)
71 WLog_ERR(TAG,
"pVirtualChannelWriteEx failed with %s [%08" PRIX32
"]",
72 WTSErrorToString(status), status);
87 Stream_Free(src, TRUE);
88 return ERROR_INVALID_PARAMETER;
91 return rail_send(rail, src);
103static UINT rail_client_execute(RailClientContext* context,
const RAIL_EXEC_ORDER* exec)
105 const char* exeOrFile =
nullptr;
113 if (!context || !exec)
114 return ERROR_INVALID_PARAMETER;
117 exeOrFile = exec->RemoteApplicationProgram;
121 return ERROR_INVALID_PARAMETER;
123 if (!utf8_string_to_rail_string(exec->RemoteApplicationProgram,
125 !utf8_string_to_rail_string(exec->RemoteApplicationWorkingDir,
127 !utf8_string_to_rail_string(exec->RemoteApplicationArguments,
129 error = ERROR_INTERNAL_ERROR;
131 error = rail_send_client_exec_order(rail, flags, &ruExeOrFile, &ruWorkingDir, &ruArguments);
133 free(ruExeOrFile.string);
134 free(ruWorkingDir.string);
135 free(ruArguments.string);
144static UINT rail_client_activate(RailClientContext* context,
const RAIL_ACTIVATE_ORDER* activate)
148 if (!context || !activate)
149 return ERROR_INVALID_PARAMETER;
152 return rail_send_client_activate_order(rail, activate);
160static UINT rail_send_client_sysparam(RailClientContext* context,
RAIL_SYSPARAM_ORDER* sysparam)
163 size_t length = RAIL_SYSPARAM_ORDER_LENGTH;
166 BOOL extendedSpiSupported = 0;
168 if (!context || !sysparam)
169 return ERROR_INVALID_PARAMETER;
173 switch (sysparam->param)
175 case SPI_SET_DRAG_FULL_WINDOWS:
176 case SPI_SET_KEYBOARD_CUES:
177 case SPI_SET_KEYBOARD_PREF:
178 case SPI_SET_MOUSE_BUTTON_SWAP:
182 case SPI_SET_WORK_AREA:
183 case SPI_DISPLAY_CHANGE:
184 case SPI_TASKBAR_POS:
188 case SPI_SET_HIGH_CONTRAST:
189 length += sysparam->highContrast.colorSchemeLength + 10;
192 case SPI_SETFILTERKEYS:
196 case SPI_SETSTICKYKEYS:
197 case SPI_SETCARETWIDTH:
198 case SPI_SETTOGGLEKEYS:
203 return ERROR_BAD_ARGUMENTS;
206 s = rail_pdu_init(length);
210 WLog_ERR(TAG,
"rail_pdu_init failed!");
211 return CHANNEL_RC_NO_MEMORY;
214 extendedSpiSupported = rail_is_extended_spi_supported(rail->channelFlags);
215 if ((error = rail_write_sysparam_order(s, sysparam, extendedSpiSupported)))
217 WLog_ERR(TAG,
"rail_write_client_sysparam_order failed with error %" PRIu32
"!", error);
218 Stream_Free(s, TRUE);
222 return rail_send_pdu(rail, s, TS_RAIL_ORDER_SYSPARAM);
230static UINT rail_client_system_param(RailClientContext* context,
233 UINT error = CHANNEL_RC_OK;
236 if (!context || !sysInParam)
237 return ERROR_INVALID_PARAMETER;
239 sysparam = *sysInParam;
241 if (sysparam.params & SPI_MASK_SET_HIGH_CONTRAST)
243 sysparam.param = SPI_SET_HIGH_CONTRAST;
245 if ((error = rail_send_client_sysparam(context, &sysparam)))
247 WLog_ERR(TAG,
"rail_send_client_sysparam failed with error %" PRIu32
"!", error);
252 if (sysparam.params & SPI_MASK_TASKBAR_POS)
254 sysparam.param = SPI_TASKBAR_POS;
256 if ((error = rail_send_client_sysparam(context, &sysparam)))
258 WLog_ERR(TAG,
"rail_send_client_sysparam failed with error %" PRIu32
"!", error);
263 if (sysparam.params & SPI_MASK_SET_MOUSE_BUTTON_SWAP)
265 sysparam.param = SPI_SET_MOUSE_BUTTON_SWAP;
267 if ((error = rail_send_client_sysparam(context, &sysparam)))
269 WLog_ERR(TAG,
"rail_send_client_sysparam failed with error %" PRIu32
"!", error);
274 if (sysparam.params & SPI_MASK_SET_KEYBOARD_PREF)
276 sysparam.param = SPI_SET_KEYBOARD_PREF;
278 if ((error = rail_send_client_sysparam(context, &sysparam)))
280 WLog_ERR(TAG,
"rail_send_client_sysparam failed with error %" PRIu32
"!", error);
285 if (sysparam.params & SPI_MASK_SET_DRAG_FULL_WINDOWS)
287 sysparam.param = SPI_SET_DRAG_FULL_WINDOWS;
289 if ((error = rail_send_client_sysparam(context, &sysparam)))
291 WLog_ERR(TAG,
"rail_send_client_sysparam failed with error %" PRIu32
"!", error);
296 if (sysparam.params & SPI_MASK_SET_KEYBOARD_CUES)
298 sysparam.param = SPI_SET_KEYBOARD_CUES;
300 if ((error = rail_send_client_sysparam(context, &sysparam)))
302 WLog_ERR(TAG,
"rail_send_client_sysparam failed with error %" PRIu32
"!", error);
307 if (sysparam.params & SPI_MASK_SET_WORK_AREA)
309 sysparam.param = SPI_SET_WORK_AREA;
311 if ((error = rail_send_client_sysparam(context, &sysparam)))
313 WLog_ERR(TAG,
"rail_send_client_sysparam failed with error %" PRIu32
"!", error);
326static UINT rail_client_system_command(RailClientContext* context,
331 if (!context || !syscommand)
332 return ERROR_INVALID_PARAMETER;
335 return rail_send_client_syscommand_order(rail, syscommand);
343static UINT rail_client_handshake(RailClientContext* context,
const RAIL_HANDSHAKE_ORDER* handshake)
345 if (!context || !handshake)
346 return ERROR_INVALID_PARAMETER;
350 WLog_Print(rail->log, WLOG_DEBUG,
"build=0x%08" PRIx32, handshake->buildNumber);
351 return rail_send_handshake_order(rail, handshake);
354static UINT rail_server_handshake(RailClientContext* context,
const RAIL_HANDSHAKE_ORDER* handshake)
356 WINPR_ASSERT(context);
357 WINPR_ASSERT(handshake);
362 WLog_Print(rail->log, WLOG_DEBUG,
"build=0x%08" PRIx32, handshake->buildNumber);
364 const UINT32 buildnumber =
367 return context->ClientHandshake(context, &clientHandshake);
370static UINT rail_server_handshake_ex(RailClientContext* context,
373 WINPR_ASSERT(context);
374 WINPR_ASSERT(handshakeEx);
381 char buffer[128] = WINPR_C_ARRAY_INIT;
383 rail->log, WLOG_DEBUG,
"build=0x%08" PRIx32
", flags=%s", handshakeEx->buildNumber,
384 rail_handshake_ex_flags_to_string(handshakeEx->railHandshakeFlags, buffer,
sizeof(buffer)));
385 return rail_server_handshake(context, &handshake);
393static UINT rail_client_notify_event(RailClientContext* context,
398 if (!context || !notifyEvent)
399 return ERROR_INVALID_PARAMETER;
402 return rail_send_client_notify_event_order(rail, notifyEvent);
410static UINT rail_client_window_move(RailClientContext* context,
415 if (!context || !windowMove)
416 return ERROR_INVALID_PARAMETER;
419 return rail_send_client_window_move_order(rail, windowMove);
427static UINT rail_client_information(RailClientContext* context,
432 if (!context || !clientStatus)
433 return ERROR_INVALID_PARAMETER;
436 return rail_send_client_status_order(rail, clientStatus);
444static UINT rail_client_system_menu(RailClientContext* context,
const RAIL_SYSMENU_ORDER* sysmenu)
448 if (!context || !sysmenu)
449 return ERROR_INVALID_PARAMETER;
452 return rail_send_client_sysmenu_order(rail, sysmenu);
460static UINT rail_client_language_bar_info(RailClientContext* context,
465 if (!context || !langBarInfo)
466 return ERROR_INVALID_PARAMETER;
469 return rail_send_client_langbar_info_order(rail, langBarInfo);
472static UINT rail_client_language_ime_info(RailClientContext* context,
477 if (!context || !langImeInfo)
478 return ERROR_INVALID_PARAMETER;
481 return rail_send_client_languageime_info_order(rail, langImeInfo);
489static UINT rail_client_get_appid_request(RailClientContext* context,
494 if (!context || !getAppIdReq || !context->handle)
495 return ERROR_INVALID_PARAMETER;
498 return rail_send_client_get_appid_req_order(rail, getAppIdReq);
501static UINT rail_client_compartment_info(RailClientContext* context,
506 if (!context || !compartmentInfo || !context->handle)
507 return ERROR_INVALID_PARAMETER;
510 return rail_send_client_compartment_info_order(rail, compartmentInfo);
513static UINT rail_client_cloak(RailClientContext* context,
const RAIL_CLOAK* cloak)
517 if (!context || !cloak || !context->handle)
518 return ERROR_INVALID_PARAMETER;
521 return rail_send_client_cloak_order(rail, cloak);
524static UINT rail_client_snap_arrange(RailClientContext* context,
const RAIL_SNAP_ARRANGE* snap)
528 if (!context || !snap || !context->handle)
529 return ERROR_INVALID_PARAMETER;
532 return rail_send_client_snap_arrange_order(rail, snap);
535static UINT rail_client_text_scale(RailClientContext* context, UINT32 textScale)
537 if (!context || !context->handle)
538 return ERROR_INVALID_PARAMETER;
541 return rail_send_client_text_scale_order(rail, textScale);
544static UINT rail_client_caret_blink_rate(RailClientContext* context, UINT32 rate)
546 if (!context || !context->handle)
547 return ERROR_INVALID_PARAMETER;
550 return rail_send_client_caret_blink_rate_order(rail, rate);
553static VOID VCAPITYPE rail_virtual_channel_open_event_ex(LPVOID lpUserParam, DWORD openHandle,
554 UINT event, LPVOID pData,
555 UINT32 dataLength, UINT32 totalLength,
558 UINT error = CHANNEL_RC_OK;
563 case CHANNEL_EVENT_DATA_RECEIVED:
564 if (!rail || (rail->OpenHandle != openHandle))
566 WLog_ERR(TAG,
"error no match");
570 if ((error = channel_client_post_message(rail->MsgsHandle, pData, dataLength,
571 totalLength, dataFlags)))
574 "rail_virtual_channel_event_data_received"
575 " failed with error %" PRIu32
"!",
581 case CHANNEL_EVENT_WRITE_CANCELLED:
582 case CHANNEL_EVENT_WRITE_COMPLETE:
585 Stream_Free(s, TRUE);
589 case CHANNEL_EVENT_USER:
595 if (error && rail && rail->rdpcontext)
596 setChannelError(rail->rdpcontext, error,
597 "rail_virtual_channel_open_event reported an error");
605static UINT rail_virtual_channel_event_connected(
railPlugin* rail, WINPR_ATTR_UNUSED LPVOID pData,
606 WINPR_ATTR_UNUSED UINT32 dataLength)
610 rail->MsgsHandle = channel_client_create_handler(rail->rdpcontext, rail, rail_order_recv,
611 RAIL_SVC_CHANNEL_NAME);
612 if (!rail->MsgsHandle)
613 return ERROR_INTERNAL_ERROR;
615 return rail->channelEntryPoints.pVirtualChannelOpenEx(rail->InitHandle, &rail->OpenHandle,
616 rail->channelDef.name,
617 rail_virtual_channel_open_event_ex);
625static UINT rail_virtual_channel_event_disconnected(
railPlugin* rail)
629 channel_client_quit_handler(rail->MsgsHandle);
630 if (rail->OpenHandle == 0)
631 return CHANNEL_RC_OK;
633 WINPR_ASSERT(rail->channelEntryPoints.pVirtualChannelCloseEx);
634 rc = rail->channelEntryPoints.pVirtualChannelCloseEx(rail->InitHandle, rail->OpenHandle);
636 if (CHANNEL_RC_OK != rc)
638 WLog_ERR(TAG,
"pVirtualChannelCloseEx failed with %s [%08" PRIX32
"]", WTSErrorToString(rc),
643 rail->OpenHandle = 0;
645 return CHANNEL_RC_OK;
648static void rail_virtual_channel_event_terminated(
railPlugin* rail)
650 rail->InitHandle =
nullptr;
655static VOID VCAPITYPE rail_virtual_channel_init_event_ex(LPVOID lpUserParam, LPVOID pInitHandle,
656 UINT event, LPVOID pData, UINT dataLength)
658 UINT error = CHANNEL_RC_OK;
661 if (!rail || (rail->InitHandle != pInitHandle))
663 WLog_ERR(TAG,
"error no match");
669 case CHANNEL_EVENT_CONNECTED:
670 if ((error = rail_virtual_channel_event_connected(rail, pData, dataLength)))
671 WLog_ERR(TAG,
"rail_virtual_channel_event_connected failed with error %" PRIu32
"!",
676 case CHANNEL_EVENT_DISCONNECTED:
677 if ((error = rail_virtual_channel_event_disconnected(rail)))
679 "rail_virtual_channel_event_disconnected failed with error %" PRIu32
"!",
684 case CHANNEL_EVENT_TERMINATED:
685 rail_virtual_channel_event_terminated(rail);
688 case CHANNEL_EVENT_ATTACHED:
689 case CHANNEL_EVENT_DETACHED:
694 if (error && rail->rdpcontext)
695 setChannelError(rail->rdpcontext, error,
696 "rail_virtual_channel_init_event_ex reported an error");
700#define VirtualChannelEntryEx rail_VirtualChannelEntryEx
702FREERDP_ENTRY_POINT(BOOL VCAPITYPE VirtualChannelEntryEx(PCHANNEL_ENTRY_POINTS_EX pEntryPoints,
707 RailClientContext* context =
nullptr;
709 BOOL isFreerdp = FALSE;
714 WLog_ERR(TAG,
"calloc failed!");
718 rail->channelDef.options = CHANNEL_OPTION_INITIALIZED | CHANNEL_OPTION_ENCRYPT_RDP |
719 CHANNEL_OPTION_COMPRESS_RDP | CHANNEL_OPTION_SHOW_PROTOCOL;
720 (void)sprintf_s(rail->channelDef.name, ARRAYSIZE(rail->channelDef.name), RAIL_SVC_CHANNEL_NAME);
724 (pEntryPointsEx->MagicNumber == FREERDP_CHANNEL_MAGIC_NUMBER))
726 context = (RailClientContext*)calloc(1,
sizeof(RailClientContext));
730 WLog_ERR(TAG,
"calloc failed!");
735 context->handle = (
void*)rail;
736 context->custom =
nullptr;
737 context->ClientExecute = rail_client_execute;
738 context->ClientActivate = rail_client_activate;
739 context->ClientSystemParam = rail_client_system_param;
740 context->ClientSystemCommand = rail_client_system_command;
741 context->ClientHandshake = rail_client_handshake;
742 context->ServerHandshake = rail_server_handshake;
743 context->ServerHandshakeEx = rail_server_handshake_ex;
744 context->ClientNotifyEvent = rail_client_notify_event;
745 context->ClientWindowMove = rail_client_window_move;
746 context->ClientInformation = rail_client_information;
747 context->ClientSystemMenu = rail_client_system_menu;
748 context->ClientLanguageBarInfo = rail_client_language_bar_info;
749 context->ClientLanguageIMEInfo = rail_client_language_ime_info;
750 context->ClientGetAppIdRequest = rail_client_get_appid_request;
751 context->ClientSnapArrange = rail_client_snap_arrange;
752 context->ClientCloak = rail_client_cloak;
753 context->ClientCompartmentInfo = rail_client_compartment_info;
754 context->ClientTextScale = rail_client_text_scale;
755 context->ClientCaretBlinkRate = rail_client_caret_blink_rate;
756 rail->rdpcontext = pEntryPointsEx->context;
757 rail->context = context;
761 rail->log = WLog_Get(
"com.freerdp.channels.rail.client");
762 WLog_Print(rail->log, WLOG_DEBUG,
"VirtualChannelEntryEx");
764 rail->InitHandle = pInitHandle;
765 rc = rail->channelEntryPoints.pVirtualChannelInitEx(
766 rail, context, pInitHandle, &rail->channelDef, 1, VIRTUAL_CHANNEL_VERSION_WIN2000,
767 rail_virtual_channel_init_event_ex);
769 if (CHANNEL_RC_OK != rc)
771 WLog_ERR(TAG,
"failed with %s [%08" PRIX32
"]", WTSErrorToString(rc), rc);
775 rail->channelEntryPoints.pInterface = context;
WINPR_ATTR_NODISCARD FREERDP_API UINT32 freerdp_settings_get_uint32(const rdpSettings *settings, FreeRDP_Settings_Keys_UInt32 id)
Returns a UINT32 settings value.