FreeRDP
Loading...
Searching...
No Matches
rail_orders.c
1
24
25#include <freerdp/config.h>
26
27#include <winpr/crt.h>
28#include <winpr/cast.h>
29
30#include <freerdp/channels/log.h>
31#include <freerdp/freerdp.h>
32
33#include "rail_orders.h"
34
35static BOOL rail_is_feature_supported(const rdpContext* context, UINT32 featureMask);
36
42UINT rail_send_pdu(railPlugin* rail, wStream* s, UINT16 orderType)
43{
44 char buffer[128] = WINPR_C_ARRAY_INIT;
45
46 if (!rail || !s)
47 {
48 Stream_Free(s, TRUE);
49 return ERROR_INVALID_PARAMETER;
50 }
51
52 const UINT16 orderLength = (UINT16)Stream_GetPosition(s);
53 Stream_ResetPosition(s);
54 if (!rail_write_pdu_header(s, orderType, orderLength))
55 goto fail;
56 if (!Stream_SetPosition(s, orderLength))
57 goto fail;
58 WLog_Print(rail->log, WLOG_DEBUG, "Sending %s PDU, length: %" PRIu16 "",
59 rail_get_order_type_string_full(orderType, buffer, sizeof(buffer)), orderLength);
60 return rail_send_channel_data(rail, s);
61
62fail:
63 Stream_Free(s, TRUE);
64 return ERROR_INVALID_DATA;
65}
66
72static UINT rail_read_server_exec_result_order(wStream* s, RAIL_EXEC_RESULT_ORDER* execResult)
73{
74 if (!s || !execResult)
75 return ERROR_INVALID_PARAMETER;
76
77 if (!Stream_CheckAndLogRequiredLength(TAG, s, RAIL_EXEC_RESULT_ORDER_LENGTH))
78 return ERROR_INVALID_DATA;
79
80 Stream_Read_UINT16(s, execResult->flags); /* flags (2 bytes) */
81 Stream_Read_UINT16(s, execResult->execResult); /* execResult (2 bytes) */
82 Stream_Read_UINT32(s, execResult->rawResult); /* rawResult (4 bytes) */
83 Stream_Seek_UINT16(s); /* padding (2 bytes) */
84 return rail_read_unicode_string(s, &execResult->exeOrFile)
85 ? CHANNEL_RC_OK
86 : ERROR_INTERNAL_ERROR; /* exeOrFile */
87}
88
94static UINT rail_read_server_minmaxinfo_order(wStream* s, RAIL_MINMAXINFO_ORDER* minmaxinfo)
95{
96 if (!s || !minmaxinfo)
97 return ERROR_INVALID_PARAMETER;
98
99 if (!Stream_CheckAndLogRequiredLength(TAG, s, RAIL_MINMAXINFO_ORDER_LENGTH))
100 return ERROR_INVALID_DATA;
101
102 Stream_Read_UINT32(s, minmaxinfo->windowId); /* windowId (4 bytes) */
103 Stream_Read_INT16(s, minmaxinfo->maxWidth); /* maxWidth (2 bytes) */
104 Stream_Read_INT16(s, minmaxinfo->maxHeight); /* maxHeight (2 bytes) */
105 Stream_Read_INT16(s, minmaxinfo->maxPosX); /* maxPosX (2 bytes) */
106 Stream_Read_INT16(s, minmaxinfo->maxPosY); /* maxPosY (2 bytes) */
107 Stream_Read_INT16(s, minmaxinfo->minTrackWidth); /* minTrackWidth (2 bytes) */
108 Stream_Read_INT16(s, minmaxinfo->minTrackHeight); /* minTrackHeight (2 bytes) */
109 Stream_Read_INT16(s, minmaxinfo->maxTrackWidth); /* maxTrackWidth (2 bytes) */
110 Stream_Read_INT16(s, minmaxinfo->maxTrackHeight); /* maxTrackHeight (2 bytes) */
111 return CHANNEL_RC_OK;
112}
113
119static UINT rail_read_server_localmovesize_order(wStream* s,
120 RAIL_LOCALMOVESIZE_ORDER* localMoveSize)
121{
122 UINT16 isMoveSizeStart = 0;
123
124 if (!s || !localMoveSize)
125 return ERROR_INVALID_PARAMETER;
126
127 if (!Stream_CheckAndLogRequiredLength(TAG, s, RAIL_LOCALMOVESIZE_ORDER_LENGTH))
128 return ERROR_INVALID_DATA;
129
130 Stream_Read_UINT32(s, localMoveSize->windowId); /* windowId (4 bytes) */
131 Stream_Read_UINT16(s, isMoveSizeStart); /* isMoveSizeStart (2 bytes) */
132 localMoveSize->isMoveSizeStart = (isMoveSizeStart != 0);
133 Stream_Read_UINT16(s, localMoveSize->moveSizeType); /* moveSizeType (2 bytes) */
134 Stream_Read_INT16(s, localMoveSize->posX); /* posX (2 bytes) */
135 Stream_Read_INT16(s, localMoveSize->posY); /* posY (2 bytes) */
136 return CHANNEL_RC_OK;
137}
138
144static UINT rail_read_server_get_appid_resp_order(wStream* s,
145 RAIL_GET_APPID_RESP_ORDER* getAppidResp)
146{
147 if (!s || !getAppidResp)
148 return ERROR_INVALID_PARAMETER;
149
150 if (!Stream_CheckAndLogRequiredLength(TAG, s, RAIL_GET_APPID_RESP_ORDER_LENGTH))
151 return ERROR_INVALID_DATA;
152
153 Stream_Read_UINT32(s, getAppidResp->windowId); /* windowId (4 bytes) */
154 if (!Stream_Read_UTF16_String(
155 s, getAppidResp->applicationId,
156 ARRAYSIZE(getAppidResp->applicationId))) /* applicationId (260 UNICODE chars) */
157 return ERROR_INVALID_DATA;
158
159 if (_wcsnlen(getAppidResp->applicationId, ARRAYSIZE(getAppidResp->applicationId)) >=
160 ARRAYSIZE(getAppidResp->applicationId))
161 return ERROR_INVALID_DATA;
162
163 return CHANNEL_RC_OK;
164}
165
171static UINT rail_read_langbar_info_order(wStream* s, RAIL_LANGBAR_INFO_ORDER* langbarInfo)
172{
173 if (!s || !langbarInfo)
174 return ERROR_INVALID_PARAMETER;
175
176 if (!Stream_CheckAndLogRequiredLength(TAG, s, RAIL_LANGBAR_INFO_ORDER_LENGTH))
177 return ERROR_INVALID_DATA;
178
179 Stream_Read_UINT32(s, langbarInfo->languageBarStatus); /* languageBarStatus (4 bytes) */
180 return CHANNEL_RC_OK;
181}
182
183static UINT rail_write_client_status_order(wStream* s, const RAIL_CLIENT_STATUS_ORDER* clientStatus)
184{
185 if (!s || !clientStatus)
186 return ERROR_INVALID_PARAMETER;
187
188 Stream_Write_UINT32(s, clientStatus->flags); /* flags (4 bytes) */
189 return ERROR_SUCCESS;
190}
191
197static UINT rail_write_client_exec_order(wStream* s, UINT16 flags,
198 const RAIL_UNICODE_STRING* exeOrFile,
199 const RAIL_UNICODE_STRING* workingDir,
200 const RAIL_UNICODE_STRING* arguments)
201{
202 UINT error = 0;
203
204 if (!s || !exeOrFile || !workingDir || !arguments)
205 return ERROR_INVALID_PARAMETER;
206
207 /* [MS-RDPERP] 2.2.2.3.1 Client Execute PDU (TS_RAIL_ORDER_EXEC)
208 * Check argument limits */
209 if ((exeOrFile->length > 520) || (workingDir->length > 520) || (arguments->length > 16000))
210 {
211 WLog_ERR(TAG,
212 "TS_RAIL_ORDER_EXEC argument limits exceeded: ExeOrFile=%" PRIu16
213 " [max=520], WorkingDir=%" PRIu16 " [max=520], Arguments=%" PRIu16 " [max=16000]",
214 exeOrFile->length, workingDir->length, arguments->length);
215 return ERROR_BAD_ARGUMENTS;
216 }
217
218 Stream_Write_UINT16(s, flags); /* flags (2 bytes) */
219 Stream_Write_UINT16(s, exeOrFile->length); /* exeOrFileLength (2 bytes) */
220 Stream_Write_UINT16(s, workingDir->length); /* workingDirLength (2 bytes) */
221 Stream_Write_UINT16(s, arguments->length); /* argumentsLength (2 bytes) */
222
223 if ((error = rail_write_unicode_string_value(s, exeOrFile)))
224 {
225 WLog_ERR(TAG, "rail_write_unicode_string_value failed with error %" PRIu32 "", error);
226 return error;
227 }
228
229 if ((error = rail_write_unicode_string_value(s, workingDir)))
230 {
231 WLog_ERR(TAG, "rail_write_unicode_string_value failed with error %" PRIu32 "", error);
232 return error;
233 }
234
235 if ((error = rail_write_unicode_string_value(s, arguments)))
236 {
237 WLog_ERR(TAG, "rail_write_unicode_string_value failed with error %" PRIu32 "", error);
238 return error;
239 }
240
241 return error;
242}
243
244static UINT rail_write_client_activate_order(wStream* s, const RAIL_ACTIVATE_ORDER* activate)
245{
246 BYTE enabled = 0;
247
248 if (!s || !activate)
249 return ERROR_INVALID_PARAMETER;
250
251 Stream_Write_UINT32(s, activate->windowId); /* windowId (4 bytes) */
252 enabled = activate->enabled ? 1 : 0;
253 Stream_Write_UINT8(s, enabled); /* enabled (1 byte) */
254 return ERROR_SUCCESS;
255}
256
257static UINT rail_write_client_sysmenu_order(wStream* s, const RAIL_SYSMENU_ORDER* sysmenu)
258{
259 if (!s || !sysmenu)
260 return ERROR_INVALID_PARAMETER;
261
262 Stream_Write_UINT32(s, sysmenu->windowId); /* windowId (4 bytes) */
263 Stream_Write_INT16(s, sysmenu->left); /* left (2 bytes) */
264 Stream_Write_INT16(s, sysmenu->top); /* top (2 bytes) */
265 return ERROR_SUCCESS;
266}
267
268static UINT rail_write_client_syscommand_order(wStream* s, const RAIL_SYSCOMMAND_ORDER* syscommand)
269{
270 if (!s || !syscommand)
271 return ERROR_INVALID_PARAMETER;
272
273 Stream_Write_UINT32(s, syscommand->windowId); /* windowId (4 bytes) */
274 Stream_Write_UINT16(s, syscommand->command); /* command (2 bytes) */
275 return ERROR_SUCCESS;
276}
277
278static UINT rail_write_client_notify_event_order(wStream* s,
279 const RAIL_NOTIFY_EVENT_ORDER* notifyEvent)
280{
281 if (!s || !notifyEvent)
282 return ERROR_INVALID_PARAMETER;
283
284 Stream_Write_UINT32(s, notifyEvent->windowId); /* windowId (4 bytes) */
285 Stream_Write_UINT32(s, notifyEvent->notifyIconId); /* notifyIconId (4 bytes) */
286 Stream_Write_UINT32(s, notifyEvent->message); /* notifyIconId (4 bytes) */
287 return ERROR_SUCCESS;
288}
289
290static UINT rail_write_client_window_move_order(wStream* s,
291 const RAIL_WINDOW_MOVE_ORDER* windowMove)
292{
293 if (!s || !windowMove)
294 return ERROR_INVALID_PARAMETER;
295
296 Stream_Write_UINT32(s, windowMove->windowId); /* windowId (4 bytes) */
297 Stream_Write_INT16(s, windowMove->left); /* left (2 bytes) */
298 Stream_Write_INT16(s, windowMove->top); /* top (2 bytes) */
299 Stream_Write_INT16(s, windowMove->right); /* right (2 bytes) */
300 Stream_Write_INT16(s, windowMove->bottom); /* bottom (2 bytes) */
301 return ERROR_SUCCESS;
302}
303
304static UINT rail_write_client_get_appid_req_order(wStream* s,
305 const RAIL_GET_APPID_REQ_ORDER* getAppidReq)
306{
307 if (!s || !getAppidReq)
308 return ERROR_INVALID_PARAMETER;
309
310 Stream_Write_UINT32(s, getAppidReq->windowId); /* windowId (4 bytes) */
311 return ERROR_SUCCESS;
312}
313
314static UINT rail_write_langbar_info_order(wStream* s, const RAIL_LANGBAR_INFO_ORDER* langbarInfo)
315{
316 if (!s || !langbarInfo)
317 return ERROR_INVALID_PARAMETER;
318
319 Stream_Write_UINT32(s, langbarInfo->languageBarStatus); /* languageBarStatus (4 bytes) */
320 return ERROR_SUCCESS;
321}
322
323static UINT rail_write_languageime_info_order(wStream* s,
324 const RAIL_LANGUAGEIME_INFO_ORDER* langImeInfo)
325{
326 if (!s || !langImeInfo)
327 return ERROR_INVALID_PARAMETER;
328
329 Stream_Write_UINT32(s, langImeInfo->ProfileType);
330 Stream_Write_UINT16(s, WINPR_ASSERTING_INT_CAST(UINT16, langImeInfo->LanguageID));
331 Stream_Write(s, &langImeInfo->LanguageProfileCLSID, sizeof(langImeInfo->LanguageProfileCLSID));
332 Stream_Write(s, &langImeInfo->ProfileGUID, sizeof(langImeInfo->ProfileGUID));
333 Stream_Write_UINT32(s, langImeInfo->KeyboardLayout);
334 return ERROR_SUCCESS;
335}
336
337static UINT rail_write_compartment_info_order(wStream* s,
338 const RAIL_COMPARTMENT_INFO_ORDER* compartmentInfo)
339{
340 if (!s || !compartmentInfo)
341 return ERROR_INVALID_PARAMETER;
342
343 Stream_Write_UINT32(s, compartmentInfo->ImeState);
344 Stream_Write_UINT32(s, compartmentInfo->ImeConvMode);
345 Stream_Write_UINT32(s, compartmentInfo->ImeSentenceMode);
346 Stream_Write_UINT32(s, compartmentInfo->KanaMode);
347 return ERROR_SUCCESS;
348}
349
355static UINT rail_recv_handshake_order(railPlugin* rail, wStream* s)
356{
357 RailClientContext* context = rail_get_client_interface(rail);
358 RAIL_HANDSHAKE_ORDER serverHandshake = WINPR_C_ARRAY_INIT;
359 UINT error = 0;
360
361 if (!context || !s)
362 return ERROR_INVALID_PARAMETER;
363
364 if ((error = rail_read_handshake_order(s, &serverHandshake)))
365 {
366 WLog_ERR(TAG, "rail_read_handshake_order failed with error %" PRIu32 "!", error);
367 return error;
368 }
369
370 rail->channelBuildNumber = serverHandshake.buildNumber;
371
372 if (context->custom)
373 {
374 IFCALLRET(context->ServerHandshake, error, context, &serverHandshake);
375
376 if (error)
377 WLog_ERR(TAG, "context.ServerHandshake failed with error %" PRIu32 "", error);
378 }
379
380 return error;
381}
382
383static UINT rail_read_compartment_info_order(wStream* s,
384 RAIL_COMPARTMENT_INFO_ORDER* compartmentInfo)
385{
386 if (!Stream_CheckAndLogRequiredLength(TAG, s, RAIL_COMPARTMENT_INFO_ORDER_LENGTH))
387 return ERROR_INVALID_DATA;
388
389 Stream_Read_UINT32(s, compartmentInfo->ImeState); /* ImeState (4 bytes) */
390 Stream_Read_UINT32(s, compartmentInfo->ImeConvMode); /* ImeConvMode (4 bytes) */
391 Stream_Read_UINT32(s, compartmentInfo->ImeSentenceMode); /* ImeSentenceMode (4 bytes) */
392 Stream_Read_UINT32(s, compartmentInfo->KanaMode); /* KANAMode (4 bytes) */
393 return CHANNEL_RC_OK;
394}
395
396static UINT rail_recv_compartmentinfo_order(railPlugin* rail, wStream* s)
397{
398 RailClientContext* context = rail_get_client_interface(rail);
399 RAIL_COMPARTMENT_INFO_ORDER pdu = WINPR_C_ARRAY_INIT;
400 UINT error = 0;
401
402 if (!context || !s)
403 return ERROR_INVALID_PARAMETER;
404
405 if (!rail_is_feature_supported(rail->rdpcontext,
406 RAIL_LEVEL_LANGUAGE_IME_SYNC_SUPPORTED |
407 RAIL_LEVEL_SERVER_TO_CLIENT_IME_SYNC_SUPPORTED))
408 return ERROR_BAD_CONFIGURATION;
409
410 if ((error = rail_read_compartment_info_order(s, &pdu)))
411 return error;
412
413 if (context->custom)
414 {
415 IFCALLRET(context->ServerCompartmentInfo, error, context, &pdu);
416
417 if (error)
418 WLog_ERR(TAG, "context.ServerCompartmentInfo failed with error %" PRIu32 "", error);
419 }
420
421 return error;
422}
423
424BOOL rail_is_feature_supported(const rdpContext* context, UINT32 featureMask)
425{
426 UINT32 supported = 0;
427 UINT32 masked = 0;
428
429 if (!context || !context->settings)
430 return FALSE;
431
432 const UINT32 level =
433 freerdp_settings_get_uint32(context->settings, FreeRDP_RemoteApplicationSupportLevel);
434 const UINT32 mask =
435 freerdp_settings_get_uint32(context->settings, FreeRDP_RemoteApplicationSupportMask);
436 supported = level & mask;
437 masked = (supported & featureMask);
438
439 if (masked != featureMask)
440 {
441 char maskstr[256] = WINPR_C_ARRAY_INIT;
442 char actualstr[256] = WINPR_C_ARRAY_INIT;
443
444 WLog_WARN(TAG, "have %s, require %s",
445 freerdp_rail_support_flags_to_string(supported, actualstr, sizeof(actualstr)),
446 freerdp_rail_support_flags_to_string(featureMask, maskstr, sizeof(maskstr)));
447 return FALSE;
448 }
449
450 return TRUE;
451}
452
458static UINT rail_recv_handshake_ex_order(railPlugin* rail, wStream* s)
459{
460 RailClientContext* context = rail_get_client_interface(rail);
461 RAIL_HANDSHAKE_EX_ORDER serverHandshake = WINPR_C_ARRAY_INIT;
462 UINT error = 0;
463
464 if (!rail || !context || !s)
465 return ERROR_INVALID_PARAMETER;
466
467 if (!rail_is_feature_supported(rail->rdpcontext, RAIL_LEVEL_HANDSHAKE_EX_SUPPORTED))
468 return ERROR_BAD_CONFIGURATION;
469
470 if ((error = rail_read_handshake_ex_order(s, &serverHandshake)))
471 {
472 WLog_ERR(TAG, "rail_read_handshake_ex_order failed with error %" PRIu32 "!", error);
473 return error;
474 }
475
476 rail->channelBuildNumber = serverHandshake.buildNumber;
477 rail->channelFlags = serverHandshake.railHandshakeFlags;
478
479 {
480 char buffer[192] = WINPR_C_ARRAY_INIT;
481 WLog_DBG(TAG, "HandshakeFlags=%s [buildNumber=0x%08" PRIx32 "]",
482 rail_handshake_ex_flags_to_string(rail->channelFlags, buffer, sizeof(buffer)),
483 rail->channelBuildNumber);
484 }
485
486 if (context->custom)
487 {
488 IFCALLRET(context->ServerHandshakeEx, error, context, &serverHandshake);
489
490 if (error)
491 WLog_ERR(TAG, "context.ServerHandshakeEx failed with error %" PRIu32 "", error);
492 }
493
494 return error;
495}
496
502static UINT rail_recv_exec_result_order(railPlugin* rail, wStream* s)
503{
504 RailClientContext* context = rail_get_client_interface(rail);
505 RAIL_EXEC_RESULT_ORDER execResult = WINPR_C_ARRAY_INIT;
506 UINT error = 0;
507
508 if (!context || !s)
509 return ERROR_INVALID_PARAMETER;
510
511 if ((error = rail_read_server_exec_result_order(s, &execResult)))
512 {
513 WLog_ERR(TAG, "rail_read_server_exec_result_order failed with error %" PRIu32 "!", error);
514 goto fail;
515 }
516
517 if (context->custom)
518 {
519 IFCALLRET(context->ServerExecuteResult, error, context, &execResult);
520
521 if (error)
522 WLog_ERR(TAG, "context.ServerExecuteResult failed with error %" PRIu32 "", error);
523 }
524
525fail:
526 rail_unicode_string_free(&execResult.exeOrFile);
527 return error;
528}
529
535static UINT rail_recv_server_sysparam_order(railPlugin* rail, wStream* s)
536{
537 RailClientContext* context = rail_get_client_interface(rail);
538
539 if (!context || !s)
540 return ERROR_INVALID_PARAMETER;
541
542 const BOOL extendedSpiSupported = rail_is_extended_spi_supported(rail->channelFlags);
543 RAIL_SYSPARAM_ORDER sysparam = WINPR_C_ARRAY_INIT;
544 UINT error = rail_read_sysparam_order(s, &sysparam, extendedSpiSupported);
545 if (error)
546 {
547 WLog_ERR(TAG, "rail_read_sysparam_order failed with error %" PRIu32 "!", error);
548 goto fail;
549 }
550
551 if (context->custom)
552 {
553 IFCALLRET(context->ServerSystemParam, error, context, &sysparam);
554
555 if (error)
556 WLog_ERR(TAG, "context.ServerSystemParam failed with error %" PRIu32 "", error);
557 }
558fail:
559 rail_unicode_string_free(&sysparam.highContrast.colorScheme);
560
561 return error;
562}
563
569static UINT rail_recv_server_minmaxinfo_order(railPlugin* rail, wStream* s)
570{
571 RailClientContext* context = rail_get_client_interface(rail);
572 RAIL_MINMAXINFO_ORDER minMaxInfo = WINPR_C_ARRAY_INIT;
573 UINT error = 0;
574
575 if (!context || !s)
576 return ERROR_INVALID_PARAMETER;
577
578 if ((error = rail_read_server_minmaxinfo_order(s, &minMaxInfo)))
579 {
580 WLog_ERR(TAG, "rail_read_server_minmaxinfo_order failed with error %" PRIu32 "!", error);
581 return error;
582 }
583
584 if (context->custom)
585 {
586 IFCALLRET(context->ServerMinMaxInfo, error, context, &minMaxInfo);
587
588 if (error)
589 WLog_ERR(TAG, "context.ServerMinMaxInfo failed with error %" PRIu32 "", error);
590 }
591
592 return error;
593}
594
600static UINT rail_recv_server_localmovesize_order(railPlugin* rail, wStream* s)
601{
602 RailClientContext* context = rail_get_client_interface(rail);
603 RAIL_LOCALMOVESIZE_ORDER localMoveSize = WINPR_C_ARRAY_INIT;
604 UINT error = 0;
605
606 if (!context || !s)
607 return ERROR_INVALID_PARAMETER;
608
609 if ((error = rail_read_server_localmovesize_order(s, &localMoveSize)))
610 {
611 WLog_ERR(TAG, "rail_read_server_localmovesize_order failed with error %" PRIu32 "!", error);
612 return error;
613 }
614
615 if (context->custom)
616 {
617 IFCALLRET(context->ServerLocalMoveSize, error, context, &localMoveSize);
618
619 if (error)
620 WLog_ERR(TAG, "context.ServerLocalMoveSize failed with error %" PRIu32 "", error);
621 }
622
623 return error;
624}
625
631static UINT rail_recv_server_get_appid_resp_order(railPlugin* rail, wStream* s)
632{
633 RailClientContext* context = rail_get_client_interface(rail);
634 RAIL_GET_APPID_RESP_ORDER getAppIdResp = WINPR_C_ARRAY_INIT;
635 UINT error = 0;
636
637 if (!context || !s)
638 return ERROR_INVALID_PARAMETER;
639
640 if ((error = rail_read_server_get_appid_resp_order(s, &getAppIdResp)))
641 {
642 WLog_ERR(TAG, "rail_read_server_get_appid_resp_order failed with error %" PRIu32 "!",
643 error);
644 return error;
645 }
646
647 if (context->custom)
648 {
649 IFCALLRET(context->ServerGetAppIdResponse, error, context, &getAppIdResp);
650
651 if (error)
652 WLog_ERR(TAG, "context.ServerGetAppIdResponse failed with error %" PRIu32 "", error);
653 }
654
655 return error;
656}
657
663static UINT rail_recv_langbar_info_order(railPlugin* rail, wStream* s)
664{
665 RailClientContext* context = rail_get_client_interface(rail);
666 RAIL_LANGBAR_INFO_ORDER langBarInfo = WINPR_C_ARRAY_INIT;
667 UINT error = 0;
668
669 if (!context)
670 return ERROR_INVALID_PARAMETER;
671
672 if (!rail_is_feature_supported(rail->rdpcontext, RAIL_LEVEL_DOCKED_LANGBAR_SUPPORTED))
673 return ERROR_BAD_CONFIGURATION;
674
675 if ((error = rail_read_langbar_info_order(s, &langBarInfo)))
676 {
677 WLog_ERR(TAG, "rail_read_langbar_info_order failed with error %" PRIu32 "!", error);
678 return error;
679 }
680
681 if (context->custom)
682 {
683 IFCALLRET(context->ServerLanguageBarInfo, error, context, &langBarInfo);
684
685 if (error)
686 WLog_ERR(TAG, "context.ServerLanguageBarInfo failed with error %" PRIu32 "", error);
687 }
688
689 return error;
690}
691
692static UINT rail_read_taskbar_info_order(wStream* s, RAIL_TASKBAR_INFO_ORDER* taskbarInfo)
693{
694 if (!s || !taskbarInfo)
695 return ERROR_INVALID_PARAMETER;
696
697 if (!Stream_CheckAndLogRequiredLength(TAG, s, RAIL_TASKBAR_INFO_ORDER_LENGTH))
698 return ERROR_INVALID_DATA;
699
700 Stream_Read_UINT32(s, taskbarInfo->TaskbarMessage);
701 Stream_Read_UINT32(s, taskbarInfo->WindowIdTab);
702 Stream_Read_UINT32(s, taskbarInfo->Body);
703 return CHANNEL_RC_OK;
704}
705
706static UINT rail_recv_taskbar_info_order(railPlugin* rail, wStream* s)
707{
708 RailClientContext* context = rail_get_client_interface(rail);
709 RAIL_TASKBAR_INFO_ORDER taskBarInfo = WINPR_C_ARRAY_INIT;
710 UINT error = 0;
711
712 if (!context)
713 return ERROR_INVALID_PARAMETER;
714
715 /* 2.2.2.14.1 Taskbar Tab Info PDU (TS_RAIL_ORDER_TASKBARINFO)
716 * server -> client message only supported if announced. */
717 if (!rail_is_feature_supported(rail->rdpcontext, RAIL_LEVEL_SHELL_INTEGRATION_SUPPORTED))
718 return ERROR_BAD_CONFIGURATION;
719
720 if ((error = rail_read_taskbar_info_order(s, &taskBarInfo)))
721 {
722 WLog_ERR(TAG, "rail_read_langbar_info_order failed with error %" PRIu32 "!", error);
723 return error;
724 }
725
726 if (context->custom)
727 {
728 IFCALLRET(context->ServerTaskBarInfo, error, context, &taskBarInfo);
729
730 if (error)
731 WLog_ERR(TAG, "context.ServerTaskBarInfo failed with error %" PRIu32 "", error);
732 }
733
734 return error;
735}
736
737static UINT rail_read_zorder_sync_order(wStream* s, RAIL_ZORDER_SYNC* zorder)
738{
739 if (!s || !zorder)
740 return ERROR_INVALID_PARAMETER;
741
742 if (!Stream_CheckAndLogRequiredLength(TAG, s, RAIL_Z_ORDER_SYNC_ORDER_LENGTH))
743 return ERROR_INVALID_DATA;
744
745 Stream_Read_UINT32(s, zorder->windowIdMarker);
746 return CHANNEL_RC_OK;
747}
748
749static UINT rail_recv_zorder_sync_order(railPlugin* rail, wStream* s)
750{
751 RailClientContext* context = rail_get_client_interface(rail);
752 RAIL_ZORDER_SYNC zorder = WINPR_C_ARRAY_INIT;
753 UINT error = 0;
754
755 if (!context)
756 return ERROR_INVALID_PARAMETER;
757
758 if ((rail->clientStatus.flags & TS_RAIL_CLIENTSTATUS_ZORDER_SYNC) == 0)
759 return ERROR_BAD_CONFIGURATION;
760
761 if ((error = rail_read_zorder_sync_order(s, &zorder)))
762 {
763 WLog_ERR(TAG, "rail_read_zorder_sync_order failed with error %" PRIu32 "!", error);
764 return error;
765 }
766
767 if (context->custom)
768 {
769 IFCALLRET(context->ServerZOrderSync, error, context, &zorder);
770
771 if (error)
772 WLog_ERR(TAG, "context.ServerZOrderSync failed with error %" PRIu32 "", error);
773 }
774
775 return error;
776}
777
778static UINT rail_read_cloak_order(wStream* s, RAIL_CLOAK* cloak)
779{
780 BYTE cloaked = 0;
781
782 if (!Stream_CheckAndLogRequiredLength(TAG, s, RAIL_CLOAK_ORDER_LENGTH))
783 return ERROR_INVALID_DATA;
784
785 Stream_Read_UINT32(s, cloak->windowId); /* WindowId (4 bytes) */
786 Stream_Read_UINT8(s, cloaked); /* Cloaked (1 byte) */
787 cloak->cloak = (cloaked != 0);
788 return CHANNEL_RC_OK;
789}
790
791static UINT rail_recv_cloak_order(railPlugin* rail, wStream* s)
792{
793 RailClientContext* context = rail_get_client_interface(rail);
794 RAIL_CLOAK cloak = WINPR_C_ARRAY_INIT;
795 UINT error = 0;
796
797 if (!context)
798 return ERROR_INVALID_PARAMETER;
799
800 /* 2.2.2.12.1 Window Cloak State Change PDU (TS_RAIL_ORDER_CLOAK)
801 * server -> client message only supported if announced. */
802 if ((rail->clientStatus.flags & TS_RAIL_CLIENTSTATUS_BIDIRECTIONAL_CLOAK_SUPPORTED) == 0)
803 return ERROR_INVALID_DATA;
804
805 if ((error = rail_read_cloak_order(s, &cloak)))
806 {
807 WLog_ERR(TAG, "rail_read_zorder_sync_order failed with error %" PRIu32 "!", error);
808 return error;
809 }
810
811 if (context->custom)
812 {
813 IFCALLRET(context->ServerCloak, error, context, &cloak);
814
815 if (error)
816 WLog_ERR(TAG, "context.ServerZOrderSync failed with error %" PRIu32 "", error);
817 }
818
819 return error;
820}
821
822static UINT rail_read_power_display_request_order(wStream* s, RAIL_POWER_DISPLAY_REQUEST* power)
823{
824 UINT32 active = 0;
825
826 if (!s || !power)
827 return ERROR_INVALID_PARAMETER;
828
829 if (!Stream_CheckAndLogRequiredLength(TAG, s, RAIL_POWER_DISPLAY_REQUEST_ORDER_LENGTH))
830 return ERROR_INVALID_DATA;
831
832 Stream_Read_UINT32(s, active);
833 power->active = active != 0;
834 return CHANNEL_RC_OK;
835}
836
837static UINT rail_recv_power_display_request_order(railPlugin* rail, wStream* s)
838{
839 RailClientContext* context = rail_get_client_interface(rail);
840 RAIL_POWER_DISPLAY_REQUEST power = WINPR_C_ARRAY_INIT;
841 UINT error = 0;
842
843 if (!context)
844 return ERROR_INVALID_PARAMETER;
845
846 /* 2.2.2.13.1 Power Display Request PDU(TS_RAIL_ORDER_POWER_DISPLAY_REQUEST)
847 */
848 if ((rail->clientStatus.flags & TS_RAIL_CLIENTSTATUS_POWER_DISPLAY_REQUEST_SUPPORTED) == 0)
849 return ERROR_BAD_CONFIGURATION;
850
851 if ((error = rail_read_power_display_request_order(s, &power)))
852 {
853 WLog_ERR(TAG, "rail_read_zorder_sync_order failed with error %" PRIu32 "!", error);
854 return error;
855 }
856
857 if (context->custom)
858 {
859 IFCALLRET(context->ServerPowerDisplayRequest, error, context, &power);
860
861 if (error)
862 WLog_ERR(TAG, "context.ServerPowerDisplayRequest failed with error %" PRIu32 "", error);
863 }
864
865 return error;
866}
867
868static UINT rail_read_get_application_id_extended_response_order(wStream* s,
870{
871 if (!s || !id)
872 return ERROR_INVALID_PARAMETER;
873
874 if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
875 return ERROR_INVALID_DATA;
876
877 Stream_Read_UINT32(s, id->windowID);
878
879 if (!Stream_Read_UTF16_String(s, id->applicationID, ARRAYSIZE(id->applicationID)))
880 return ERROR_INVALID_DATA;
881
882 if (_wcsnlen(id->applicationID, ARRAYSIZE(id->applicationID)) >= ARRAYSIZE(id->applicationID))
883 return ERROR_INVALID_DATA;
884
885 if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
886 return ERROR_INVALID_DATA;
887
888 Stream_Read_UINT32(s, id->processId);
889
890 if (!Stream_Read_UTF16_String(s, id->processImageName, ARRAYSIZE(id->processImageName)))
891 return ERROR_INVALID_DATA;
892
893 if (_wcsnlen(id->processImageName, ARRAYSIZE(id->processImageName)) >=
894 ARRAYSIZE(id->processImageName))
895 return ERROR_INVALID_DATA;
896
897 return CHANNEL_RC_OK;
898}
899
900static UINT rail_recv_get_application_id_extended_response_order(railPlugin* rail, wStream* s)
901{
902 RailClientContext* context = rail_get_client_interface(rail);
903 RAIL_GET_APPID_RESP_EX id = WINPR_C_ARRAY_INIT;
904 UINT error = 0;
905
906 if (!context)
907 return ERROR_INVALID_PARAMETER;
908
909 if ((error = rail_read_get_application_id_extended_response_order(s, &id)))
910 {
911 WLog_ERR(TAG,
912 "rail_read_get_application_id_extended_response_order failed with error %" PRIu32
913 "!",
914 error);
915 return error;
916 }
917
918 if (context->custom)
919 {
920 IFCALLRET(context->ServerGetAppidResponseExtended, error, context, &id);
921
922 if (error)
923 WLog_ERR(TAG, "context.ServerGetAppidResponseExtended failed with error %" PRIu32 "",
924 error);
925 }
926
927 return error;
928}
929
930static UINT rail_read_textscaleinfo_order(wStream* s, UINT32* pTextScaleFactor)
931{
932 WINPR_ASSERT(pTextScaleFactor);
933
934 if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
935 return ERROR_INVALID_DATA;
936
937 Stream_Read_UINT32(s, *pTextScaleFactor);
938 return CHANNEL_RC_OK;
939}
940
941static UINT rail_recv_textscaleinfo_order(railPlugin* rail, wStream* s)
942{
943 RailClientContext* context = rail_get_client_interface(rail);
944 UINT32 TextScaleFactor = 0;
945 UINT error = 0;
946
947 if (!context)
948 return ERROR_INVALID_PARAMETER;
949
950 if ((error = rail_read_textscaleinfo_order(s, &TextScaleFactor)))
951 return error;
952
953 if (context->custom)
954 {
955 IFCALLRET(context->ClientTextScale, error, context, TextScaleFactor);
956
957 if (error)
958 WLog_ERR(TAG, "context.ClientTextScale failed with error %" PRIu32 "", error);
959 }
960
961 return error;
962}
963
964static UINT rail_read_caretblinkinfo_order(wStream* s, UINT32* pCaretBlinkRate)
965{
966 WINPR_ASSERT(pCaretBlinkRate);
967
968 if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
969 return ERROR_INVALID_DATA;
970
971 Stream_Read_UINT32(s, *pCaretBlinkRate);
972 return CHANNEL_RC_OK;
973}
974
975static UINT rail_recv_caretblinkinfo_order(railPlugin* rail, wStream* s)
976{
977 RailClientContext* context = rail_get_client_interface(rail);
978 UINT32 CaretBlinkRate = 0;
979 UINT error = 0;
980
981 if (!context)
982 return ERROR_INVALID_PARAMETER;
983 if ((error = rail_read_caretblinkinfo_order(s, &CaretBlinkRate)))
984 return error;
985
986 if (context->custom)
987 {
988 IFCALLRET(context->ClientCaretBlinkRate, error, context, CaretBlinkRate);
989
990 if (error)
991 WLog_ERR(TAG, "context.ClientCaretBlinkRate failed with error %" PRIu32 "", error);
992 }
993
994 return error;
995}
996
1002UINT rail_order_recv(LPVOID userdata, wStream* s)
1003{
1004 char buffer[128] = WINPR_C_ARRAY_INIT;
1005 railPlugin* rail = userdata;
1006 UINT16 orderType = 0;
1007 UINT16 orderLength = 0;
1008 UINT error = CHANNEL_RC_OK;
1009
1010 if (!rail || !s)
1011 {
1012 error = ERROR_INVALID_PARAMETER;
1013 goto fail;
1014 }
1015
1016 if ((error = rail_read_pdu_header(s, &orderType, &orderLength)))
1017 {
1018 WLog_ERR(TAG, "rail_read_pdu_header failed with error %" PRIu32 "!", error);
1019 error = ERROR_INVALID_DATA;
1020 goto fail;
1021 }
1022
1023 WLog_Print(rail->log, WLOG_DEBUG, "Received %s PDU, length:%" PRIu16 "",
1024 rail_get_order_type_string_full(orderType, buffer, sizeof(buffer)), orderLength);
1025
1026 switch (orderType)
1027 {
1028 case TS_RAIL_ORDER_HANDSHAKE:
1029 error = rail_recv_handshake_order(rail, s);
1030 break;
1031
1032 case TS_RAIL_ORDER_COMPARTMENTINFO:
1033 error = rail_recv_compartmentinfo_order(rail, s);
1034 break;
1035
1036 case TS_RAIL_ORDER_HANDSHAKE_EX:
1037 error = rail_recv_handshake_ex_order(rail, s);
1038 break;
1039
1040 case TS_RAIL_ORDER_EXEC_RESULT:
1041 error = rail_recv_exec_result_order(rail, s);
1042 break;
1043
1044 case TS_RAIL_ORDER_SYSPARAM:
1045 error = rail_recv_server_sysparam_order(rail, s);
1046 break;
1047
1048 case TS_RAIL_ORDER_MINMAXINFO:
1049 error = rail_recv_server_minmaxinfo_order(rail, s);
1050 break;
1051
1052 case TS_RAIL_ORDER_LOCALMOVESIZE:
1053 error = rail_recv_server_localmovesize_order(rail, s);
1054 break;
1055
1056 case TS_RAIL_ORDER_GET_APPID_RESP:
1057 error = rail_recv_server_get_appid_resp_order(rail, s);
1058 break;
1059
1060 case TS_RAIL_ORDER_LANGBARINFO:
1061 error = rail_recv_langbar_info_order(rail, s);
1062 break;
1063
1064 case TS_RAIL_ORDER_TASKBARINFO:
1065 error = rail_recv_taskbar_info_order(rail, s);
1066 break;
1067
1068 case TS_RAIL_ORDER_ZORDER_SYNC:
1069 error = rail_recv_zorder_sync_order(rail, s);
1070 break;
1071
1072 case TS_RAIL_ORDER_CLOAK:
1073 error = rail_recv_cloak_order(rail, s);
1074 break;
1075
1076 case TS_RAIL_ORDER_POWER_DISPLAY_REQUEST:
1077 error = rail_recv_power_display_request_order(rail, s);
1078 break;
1079
1080 case TS_RAIL_ORDER_GET_APPID_RESP_EX:
1081 error = rail_recv_get_application_id_extended_response_order(rail, s);
1082 break;
1083
1084 case TS_RAIL_ORDER_TEXTSCALEINFO:
1085 error = rail_recv_textscaleinfo_order(rail, s);
1086 break;
1087
1088 case TS_RAIL_ORDER_CARETBLINKINFO:
1089 error = rail_recv_caretblinkinfo_order(rail, s);
1090 break;
1091
1092 default:
1093 WLog_ERR(TAG, "Unknown RAIL PDU %s received.",
1094 rail_get_order_type_string_full(orderType, buffer, sizeof(buffer)));
1095 error = ERROR_INVALID_DATA;
1096 goto fail;
1097 }
1098
1099 if (error == ERROR_BAD_CONFIGURATION)
1100 {
1101 char ebuffer[128] = WINPR_C_ARRAY_INIT;
1102 WLog_Print(rail->log, WLOG_WARN,
1103 "%s - SERVER BUG: The support for this feature was not announced!",
1104 rail_get_order_type_string_full(orderType, ebuffer, sizeof(ebuffer)));
1105
1106 if (freerdp_settings_get_bool(rail->rdpcontext->settings,
1107 FreeRDP_AllowUnanouncedOrdersFromServer))
1108 error = CHANNEL_RC_OK;
1109 }
1110 if (error != CHANNEL_RC_OK)
1111 {
1112 char ebuffer[128] = WINPR_C_ARRAY_INIT;
1113 WLog_Print(rail->log, WLOG_ERROR, "Failed to process rail %s PDU, length:%" PRIu16 "",
1114 rail_get_order_type_string_full(orderType, ebuffer, sizeof(ebuffer)),
1115 orderLength);
1116 }
1117
1118fail:
1119 Stream_Free(s, TRUE);
1120 return error;
1121}
1122
1128UINT rail_send_handshake_order(railPlugin* rail, const RAIL_HANDSHAKE_ORDER* handshake)
1129{
1130 if (!rail || !handshake)
1131 return ERROR_INVALID_PARAMETER;
1132
1133 wStream* s = rail_pdu_init(RAIL_HANDSHAKE_ORDER_LENGTH);
1134
1135 if (!s)
1136 {
1137 WLog_ERR(TAG, "rail_pdu_init failed!");
1138 return CHANNEL_RC_NO_MEMORY;
1139 }
1140
1141 rail_write_handshake_order(s, handshake);
1142 return rail_send_pdu(rail, s, TS_RAIL_ORDER_HANDSHAKE);
1143}
1144
1150UINT rail_send_handshake_ex_order(railPlugin* rail, const RAIL_HANDSHAKE_EX_ORDER* handshakeEx)
1151{
1152 if (!rail || !handshakeEx)
1153 return ERROR_INVALID_PARAMETER;
1154
1155 wStream* s = rail_pdu_init(RAIL_HANDSHAKE_EX_ORDER_LENGTH);
1156
1157 if (!s)
1158 {
1159 WLog_ERR(TAG, "rail_pdu_init failed!");
1160 return CHANNEL_RC_NO_MEMORY;
1161 }
1162
1163 rail_write_handshake_ex_order(s, handshakeEx);
1164 return rail_send_pdu(rail, s, TS_RAIL_ORDER_HANDSHAKE_EX);
1165}
1166
1172UINT rail_send_client_status_order(railPlugin* rail, const RAIL_CLIENT_STATUS_ORDER* clientStatus)
1173{
1174 wStream* s = nullptr;
1175 UINT error = 0;
1176
1177 if (!rail || !clientStatus)
1178 return ERROR_INVALID_PARAMETER;
1179
1180 rail->clientStatus = *clientStatus;
1181 s = rail_pdu_init(RAIL_CLIENT_STATUS_ORDER_LENGTH);
1182
1183 if (!s)
1184 {
1185 WLog_ERR(TAG, "rail_pdu_init failed!");
1186 return CHANNEL_RC_NO_MEMORY;
1187 }
1188
1189 error = rail_write_client_status_order(s, clientStatus);
1190
1191 if (ERROR_SUCCESS != error)
1192 {
1193
1194 Stream_Free(s, TRUE);
1195 return error;
1196 }
1197
1198 return rail_send_pdu(rail, s, TS_RAIL_ORDER_CLIENTSTATUS);
1199}
1200
1206UINT rail_send_client_exec_order(railPlugin* rail, UINT16 flags,
1207 const RAIL_UNICODE_STRING* exeOrFile,
1208 const RAIL_UNICODE_STRING* workingDir,
1209 const RAIL_UNICODE_STRING* arguments)
1210{
1211 wStream* s = nullptr;
1212 UINT error = 0;
1213 size_t length = 0;
1214
1215 if (!rail || !exeOrFile || !workingDir || !arguments)
1216 return ERROR_INVALID_PARAMETER;
1217
1218 length = RAIL_EXEC_ORDER_LENGTH + exeOrFile->length + workingDir->length + arguments->length;
1219 s = rail_pdu_init(length);
1220
1221 if (!s)
1222 {
1223 WLog_ERR(TAG, "rail_pdu_init failed!");
1224 return CHANNEL_RC_NO_MEMORY;
1225 }
1226
1227 if ((error = rail_write_client_exec_order(s, flags, exeOrFile, workingDir, arguments)))
1228 {
1229 WLog_ERR(TAG, "rail_write_client_exec_order failed with error %" PRIu32 "!", error);
1230 goto out;
1231 }
1232
1233 return rail_send_pdu(rail, s, TS_RAIL_ORDER_EXEC);
1234
1235out:
1236 Stream_Free(s, TRUE);
1237 return error;
1238}
1239
1245UINT rail_send_client_activate_order(railPlugin* rail, const RAIL_ACTIVATE_ORDER* activate)
1246{
1247 wStream* s = nullptr;
1248 UINT error = 0;
1249
1250 if (!rail || !activate)
1251 return ERROR_INVALID_PARAMETER;
1252
1253 s = rail_pdu_init(RAIL_ACTIVATE_ORDER_LENGTH);
1254
1255 if (!s)
1256 {
1257 WLog_ERR(TAG, "rail_pdu_init failed!");
1258 return CHANNEL_RC_NO_MEMORY;
1259 }
1260
1261 error = rail_write_client_activate_order(s, activate);
1262
1263 if (ERROR_SUCCESS != error)
1264 {
1265
1266 Stream_Free(s, TRUE);
1267 return error;
1268 }
1269
1270 return rail_send_pdu(rail, s, TS_RAIL_ORDER_ACTIVATE);
1271}
1272
1278UINT rail_send_client_sysmenu_order(railPlugin* rail, const RAIL_SYSMENU_ORDER* sysmenu)
1279{
1280 wStream* s = nullptr;
1281 UINT error = 0;
1282
1283 if (!rail || !sysmenu)
1284 return ERROR_INVALID_PARAMETER;
1285
1286 s = rail_pdu_init(RAIL_SYSMENU_ORDER_LENGTH);
1287
1288 if (!s)
1289 {
1290 WLog_ERR(TAG, "rail_pdu_init failed!");
1291 return CHANNEL_RC_NO_MEMORY;
1292 }
1293
1294 error = rail_write_client_sysmenu_order(s, sysmenu);
1295
1296 if (ERROR_SUCCESS != error)
1297 {
1298
1299 Stream_Free(s, TRUE);
1300 return error;
1301 }
1302
1303 return rail_send_pdu(rail, s, TS_RAIL_ORDER_SYSMENU);
1304}
1305
1311UINT rail_send_client_syscommand_order(railPlugin* rail, const RAIL_SYSCOMMAND_ORDER* syscommand)
1312{
1313 wStream* s = nullptr;
1314 UINT error = 0;
1315
1316 if (!rail || !syscommand)
1317 return ERROR_INVALID_PARAMETER;
1318
1319 s = rail_pdu_init(RAIL_SYSCOMMAND_ORDER_LENGTH);
1320
1321 if (!s)
1322 {
1323 WLog_ERR(TAG, "rail_pdu_init failed!");
1324 return CHANNEL_RC_NO_MEMORY;
1325 }
1326
1327 error = rail_write_client_syscommand_order(s, syscommand);
1328
1329 if (ERROR_SUCCESS != error)
1330 {
1331
1332 Stream_Free(s, TRUE);
1333 return error;
1334 }
1335
1336 return rail_send_pdu(rail, s, TS_RAIL_ORDER_SYSCOMMAND);
1337}
1338
1344UINT rail_send_client_notify_event_order(railPlugin* rail,
1345 const RAIL_NOTIFY_EVENT_ORDER* notifyEvent)
1346{
1347 wStream* s = nullptr;
1348 UINT error = 0;
1349
1350 if (!rail || !notifyEvent)
1351 return ERROR_INVALID_PARAMETER;
1352
1353 s = rail_pdu_init(RAIL_NOTIFY_EVENT_ORDER_LENGTH);
1354
1355 if (!s)
1356 {
1357 WLog_ERR(TAG, "rail_pdu_init failed!");
1358 return CHANNEL_RC_NO_MEMORY;
1359 }
1360
1361 error = rail_write_client_notify_event_order(s, notifyEvent);
1362
1363 if (ERROR_SUCCESS != error)
1364 {
1365
1366 Stream_Free(s, TRUE);
1367 return error;
1368 }
1369
1370 return rail_send_pdu(rail, s, TS_RAIL_ORDER_NOTIFY_EVENT);
1371}
1372
1378UINT rail_send_client_window_move_order(railPlugin* rail, const RAIL_WINDOW_MOVE_ORDER* windowMove)
1379{
1380 wStream* s = nullptr;
1381 UINT error = 0;
1382
1383 if (!rail || !windowMove)
1384 return ERROR_INVALID_PARAMETER;
1385
1386 s = rail_pdu_init(RAIL_WINDOW_MOVE_ORDER_LENGTH);
1387
1388 if (!s)
1389 {
1390 WLog_ERR(TAG, "rail_pdu_init failed!");
1391 return CHANNEL_RC_NO_MEMORY;
1392 }
1393
1394 error = rail_write_client_window_move_order(s, windowMove);
1395
1396 if (ERROR_SUCCESS != error)
1397 {
1398
1399 Stream_Free(s, TRUE);
1400 return error;
1401 }
1402
1403 return rail_send_pdu(rail, s, TS_RAIL_ORDER_WINDOWMOVE);
1404}
1405
1411UINT rail_send_client_get_appid_req_order(railPlugin* rail,
1412 const RAIL_GET_APPID_REQ_ORDER* getAppIdReq)
1413{
1414 wStream* s = nullptr;
1415 UINT error = 0;
1416
1417 if (!rail || !getAppIdReq)
1418 return ERROR_INVALID_PARAMETER;
1419
1420 s = rail_pdu_init(RAIL_GET_APPID_REQ_ORDER_LENGTH);
1421
1422 if (!s)
1423 {
1424 WLog_ERR(TAG, "rail_pdu_init failed!");
1425 return CHANNEL_RC_NO_MEMORY;
1426 }
1427
1428 error = rail_write_client_get_appid_req_order(s, getAppIdReq);
1429
1430 if (ERROR_SUCCESS != error)
1431 {
1432
1433 Stream_Free(s, TRUE);
1434 return error;
1435 }
1436 return rail_send_pdu(rail, s, TS_RAIL_ORDER_GET_APPID_REQ);
1437}
1438
1444UINT rail_send_client_langbar_info_order(railPlugin* rail,
1445 const RAIL_LANGBAR_INFO_ORDER* langBarInfo)
1446{
1447 wStream* s = nullptr;
1448 UINT error = 0;
1449
1450 if (!rail || !langBarInfo)
1451 return ERROR_INVALID_PARAMETER;
1452
1453 if (!rail_is_feature_supported(rail->rdpcontext, RAIL_LEVEL_DOCKED_LANGBAR_SUPPORTED))
1454 return ERROR_BAD_CONFIGURATION;
1455
1456 s = rail_pdu_init(RAIL_LANGBAR_INFO_ORDER_LENGTH);
1457
1458 if (!s)
1459 {
1460 WLog_ERR(TAG, "rail_pdu_init failed!");
1461 return CHANNEL_RC_NO_MEMORY;
1462 }
1463
1464 error = rail_write_langbar_info_order(s, langBarInfo);
1465
1466 if (ERROR_SUCCESS != error)
1467 {
1468
1469 Stream_Free(s, TRUE);
1470 return error;
1471 }
1472 return rail_send_pdu(rail, s, TS_RAIL_ORDER_LANGBARINFO);
1473}
1474
1475UINT rail_send_client_languageime_info_order(railPlugin* rail,
1476 const RAIL_LANGUAGEIME_INFO_ORDER* langImeInfo)
1477{
1478 wStream* s = nullptr;
1479 UINT error = 0;
1480
1481 if (!rail || !langImeInfo)
1482 return ERROR_INVALID_PARAMETER;
1483
1484 if (!rail_is_feature_supported(rail->rdpcontext, RAIL_LEVEL_LANGUAGE_IME_SYNC_SUPPORTED))
1485 return ERROR_BAD_CONFIGURATION;
1486
1487 s = rail_pdu_init(RAIL_LANGUAGEIME_INFO_ORDER_LENGTH);
1488
1489 if (!s)
1490 {
1491 WLog_ERR(TAG, "rail_pdu_init failed!");
1492 return CHANNEL_RC_NO_MEMORY;
1493 }
1494
1495 error = rail_write_languageime_info_order(s, langImeInfo);
1496
1497 if (ERROR_SUCCESS != error)
1498 {
1499
1500 Stream_Free(s, TRUE);
1501 return error;
1502 }
1503 return rail_send_pdu(rail, s, TS_RAIL_ORDER_LANGUAGEIMEINFO);
1504}
1505
1506UINT rail_send_client_compartment_info_order(railPlugin* rail,
1507 const RAIL_COMPARTMENT_INFO_ORDER* compartmentInfo)
1508{
1509 wStream* s = nullptr;
1510 UINT error = 0;
1511
1512 if (!rail || !compartmentInfo)
1513 return ERROR_INVALID_PARAMETER;
1514
1515 if (!rail_is_feature_supported(rail->rdpcontext, RAIL_LEVEL_LANGUAGE_IME_SYNC_SUPPORTED))
1516 return ERROR_BAD_CONFIGURATION;
1517
1518 s = rail_pdu_init(RAIL_COMPARTMENT_INFO_ORDER_LENGTH);
1519
1520 if (!s)
1521 {
1522 WLog_ERR(TAG, "rail_pdu_init failed!");
1523 return CHANNEL_RC_NO_MEMORY;
1524 }
1525
1526 error = rail_write_compartment_info_order(s, compartmentInfo);
1527
1528 if (ERROR_SUCCESS != error)
1529 {
1530 Stream_Free(s, TRUE);
1531 return error;
1532 }
1533 return rail_send_pdu(rail, s, TS_RAIL_ORDER_COMPARTMENTINFO);
1534}
1535
1536UINT rail_send_client_cloak_order(railPlugin* rail, const RAIL_CLOAK* cloak)
1537{
1538 if (!rail || !cloak)
1539 return ERROR_INVALID_PARAMETER;
1540
1541 wStream* s = rail_pdu_init(5);
1542
1543 if (!s)
1544 {
1545 WLog_ERR(TAG, "rail_pdu_init failed!");
1546 return CHANNEL_RC_NO_MEMORY;
1547 }
1548
1549 Stream_Write_UINT32(s, cloak->windowId);
1550 Stream_Write_UINT8(s, cloak->cloak ? 1 : 0);
1551 return rail_send_pdu(rail, s, TS_RAIL_ORDER_CLOAK);
1552}
1553
1554UINT rail_send_client_snap_arrange_order(railPlugin* rail, const RAIL_SNAP_ARRANGE* snap)
1555{
1556 if (!rail)
1557 return ERROR_INVALID_PARAMETER;
1558
1559 /* 2.2.2.7.5 Client Window Snap PDU (TS_RAIL_ORDER_SNAP_ARRANGE) */
1560 if ((rail->channelFlags & TS_RAIL_ORDER_HANDSHAKE_EX_FLAGS_SNAP_ARRANGE_SUPPORTED) == 0)
1561 {
1562 RAIL_WINDOW_MOVE_ORDER move = WINPR_C_ARRAY_INIT;
1563 move.top = snap->top;
1564 move.left = snap->left;
1565 move.right = snap->right;
1566 move.bottom = snap->bottom;
1567 move.windowId = snap->windowId;
1568 return rail_send_client_window_move_order(rail, &move);
1569 }
1570
1571 wStream* s = rail_pdu_init(12);
1572
1573 if (!s)
1574 {
1575 WLog_ERR(TAG, "rail_pdu_init failed!");
1576 return CHANNEL_RC_NO_MEMORY;
1577 }
1578
1579 Stream_Write_UINT32(s, snap->windowId);
1580 Stream_Write_INT16(s, snap->left);
1581 Stream_Write_INT16(s, snap->top);
1582 Stream_Write_INT16(s, snap->right);
1583 Stream_Write_INT16(s, snap->bottom);
1584 return rail_send_pdu(rail, s, TS_RAIL_ORDER_SNAP_ARRANGE);
1585}
1586
1587UINT rail_send_client_text_scale_order(railPlugin* rail, UINT32 textScale)
1588{
1589 if (!rail)
1590 return ERROR_INVALID_PARAMETER;
1591
1592 wStream* s = rail_pdu_init(4);
1593
1594 if (!s)
1595 {
1596 WLog_ERR(TAG, "rail_pdu_init failed!");
1597 return CHANNEL_RC_NO_MEMORY;
1598 }
1599
1600 Stream_Write_UINT32(s, textScale);
1601 return rail_send_pdu(rail, s, TS_RAIL_ORDER_TEXTSCALEINFO);
1602}
1603
1604UINT rail_send_client_caret_blink_rate_order(railPlugin* rail, UINT32 rate)
1605{
1606 if (!rail)
1607 return ERROR_INVALID_PARAMETER;
1608
1609 wStream* s = rail_pdu_init(4);
1610
1611 if (!s)
1612 {
1613 WLog_ERR(TAG, "rail_pdu_init failed!");
1614 return CHANNEL_RC_NO_MEMORY;
1615 }
1616
1617 Stream_Write_UINT32(s, rate);
1618 return rail_send_pdu(rail, s, TS_RAIL_ORDER_CARETBLINKINFO);
1619}
WINPR_ATTR_NODISCARD FREERDP_API UINT32 freerdp_settings_get_uint32(const rdpSettings *settings, FreeRDP_Settings_Keys_UInt32 id)
Returns a UINT32 settings value.
WINPR_ATTR_NODISCARD FREERDP_API const char * freerdp_rail_support_flags_to_string(UINT32 flags, char *buffer, size_t length)
Returns a stringified representation of RAIL support flags.
WINPR_ATTR_NODISCARD FREERDP_API BOOL freerdp_settings_get_bool(const rdpSettings *settings, FreeRDP_Settings_Keys_Bool id)
Returns a boolean settings value.