forked from neutrinolabs/xrdp
-
Notifications
You must be signed in to change notification settings - Fork 7
/
xrdp_mm.c
4621 lines (4133 loc) · 139 KB
/
xrdp_mm.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* xrdp: A Remote Desktop Protocol server.
*
* Copyright (C) Jay Sorg 2004-2014
*
* 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.
*
* module manager
*/
#if defined(HAVE_CONFIG_H)
#include <config_ac.h>
#endif
#include "xrdp.h"
#include "log.h"
#include "string_calls.h"
#include "guid.h"
#include "ms-rdpedisp.h"
#include "ms-rdpbcgr.h"
#include "scp.h"
#include <ctype.h>
#include "xrdp_encoder.h"
#include "xrdp_sockets.h"
#include "xrdp_egfx.h"
#include "libxrdp.h"
#include "xrdp_channel.h"
#include <limits.h>
/* Forward declarations */
static int
xrdp_mm_chansrv_connect(struct xrdp_mm *self, const char *port);
static void
xrdp_mm_connect_sm(struct xrdp_mm *self);
/*****************************************************************************/
struct xrdp_mm *
xrdp_mm_create(struct xrdp_wm *owner)
{
struct xrdp_mm *self;
self = (struct xrdp_mm *)g_malloc(sizeof(struct xrdp_mm), 1);
self->wm = owner;
self->login_names = list_create();
self->login_names->auto_free = 1;
self->login_values = list_create();
self->login_values->auto_free = 1;
LOG_DEVEL(LOG_LEVEL_INFO, "xrdp_mm_create: bpp %d mcs_connection_type %d "
"jpeg_codec_id %d v3_codec_id %d rfx_codec_id %d "
"h264_codec_id %d",
self->wm->client_info->bpp,
self->wm->client_info->mcs_connection_type,
self->wm->client_info->jpeg_codec_id,
self->wm->client_info->v3_codec_id,
self->wm->client_info->rfx_codec_id,
self->wm->client_info->h264_codec_id);
if ((self->wm->client_info->gfx == 0) &&
((self->wm->client_info->h264_codec_id != 0) ||
(self->wm->client_info->jpeg_codec_id != 0) ||
(self->wm->client_info->rfx_codec_id != 0)))
{
self->encoder = xrdp_encoder_create(self);
}
return self;
}
/*****************************************************************************/
/* called from main thread */
static long
xrdp_mm_sync_unload(long param1, long param2)
{
return g_free_library(param1);
}
/*****************************************************************************/
/* called from main thread */
static long
xrdp_mm_sync_load(long param1, long param2)
{
long rv;
char *libname;
libname = (char *)param1;
rv = g_load_library(libname);
return rv;
}
/*****************************************************************************/
static void
xrdp_mm_module_cleanup(struct xrdp_mm *self)
{
LOG(LOG_LEVEL_DEBUG, "xrdp_mm_module_cleanup");
if (self->mod != 0)
{
if (self->mod_exit != 0)
{
/* let the module cleanup */
self->mod_exit(self->mod);
}
}
if (self->mod_handle != 0)
{
/* Let the main thread unload the module.*/
g_xrdp_sync(xrdp_mm_sync_unload, self->mod_handle, 0);
}
trans_delete(self->chan_trans);
self->chan_trans = 0;
self->mod_init = 0;
self->mod_exit = 0;
self->mod = 0;
self->mod_handle = 0;
if (self->wm->hide_log_window)
{
/* make sure autologin is off */
self->wm->session->client_info->rdp_autologin = 0;
xrdp_wm_set_login_state(self->wm, WMLS_RESET); /* reset session */
}
}
/*****************************************************************************/
void
xrdp_mm_delete(struct xrdp_mm *self)
{
if (self == 0)
{
return;
}
/* free any module stuff */
xrdp_mm_module_cleanup(self);
/* shutdown thread */
xrdp_encoder_delete(self->encoder);
trans_delete(self->sesman_trans);
self->sesman_trans = 0;
list_delete(self->login_names);
list_delete(self->login_values);
list_delete(self->resize_queue);
g_free(self->resize_data);
g_delete_wait_obj(self->resize_ready);
xrdp_egfx_shutdown_full(self->egfx);
g_free(self);
}
/**************************************************************************//**
* Looks for a string value in the login_names/login_values array
*
* In the event of multiple matches, the LAST value matched is returned.
* This currently allows for values to be replaced by writing a new value
* to the end of the list
*
* Returned strings are valid until the module is destroyed.
*
* @param self This module
* @param aname Name to lookup (case-insensitive)
*
* @return pointer to value, or NULL if not found.
*/
static const char *
xrdp_mm_get_value(struct xrdp_mm *self, const char *aname)
{
const char *name;
const char *value = NULL;
unsigned int index = self->login_names->count;
while (index > 0 && value == NULL)
{
--index;
name = (const char *)list_get_item(self->login_names, index);
if (name != NULL && g_strcasecmp(name, aname) == 0)
{
value = (const char *)list_get_item(self->login_values, index);
}
}
return value;
}
/**************************************************************************//**
* Looks for a numeric value in the login_names/login_values array
*
* Returned strings are valid until the module is destroyed.
*
* @param self This module
* @param aname Name to lookup (case-insensitive)
* @param def Default to return if value not found.
*
* @return value from name, or the specified default.
*/
static int
xrdp_mm_get_value_int(struct xrdp_mm *self, const char *aname, int def)
{
const char *value = xrdp_mm_get_value(self, aname);
return (value == NULL) ? def : g_atoi(value);
}
/*****************************************************************************/
/* Send gateway login information to sesman */
static int
xrdp_mm_send_sys_login_request(struct xrdp_mm *self, const char *username,
const char *password)
{
xrdp_wm_log_msg(self->wm, LOG_LEVEL_DEBUG,
"sending login info to session manager, please wait...");
return scp_send_sys_login_request(
self->sesman_trans, username, password,
self->wm->client_info->client_ip);
}
/*****************************************************************************/
/* Send a create session request to sesman */
static int
xrdp_mm_create_session(struct xrdp_mm *self)
{
int rv = 0;
int xserverbpp;
enum scp_session_type type;
/* Map the session code to an SCP session type */
switch (self->code)
{
case XVNC_SESSION_CODE:
type = SCP_SESSION_TYPE_XVNC;
break;
case XORG_SESSION_CODE:
type = SCP_SESSION_TYPE_XORG;
break;
default:
xrdp_wm_log_msg(self->wm, LOG_LEVEL_ERROR,
"Unrecognised session code %d", self->code);
rv = 1;
}
if (rv == 0)
{
xserverbpp = xrdp_mm_get_value_int(self, "xserverbpp",
self->wm->screen->bpp);
xrdp_wm_log_msg(self->wm, LOG_LEVEL_DEBUG,
"sending create session request to session"
" manager. Please wait...");
rv = scp_send_create_session_request(
self->sesman_trans,
type,
self->wm->screen->width,
self->wm->screen->height,
xserverbpp,
self->wm->client_info->program,
self->wm->client_info->directory);
}
return rv;
}
/*****************************************************************************/
static int
xrdp_mm_setup_mod1(struct xrdp_mm *self)
{
void *func;
const char *lib;
char text[256];
if (self == 0)
{
return 1;
}
if ((lib = xrdp_mm_get_value(self, "lib")) == NULL)
{
xrdp_wm_log_msg(self->wm, LOG_LEVEL_ERROR,
"no library name specified in xrdp.ini, please add "
"lib=libxrdp-vnc.so or similar");
return 1;
}
if (lib[0] == 0)
{
xrdp_wm_log_msg(self->wm, LOG_LEVEL_ERROR,
"empty library name specified in xrdp.ini, please "
"add lib=libxrdp-vnc.so or similar");
return 1;
}
if (self->mod_handle == 0)
{
g_snprintf(text, sizeof(text), "%s/%s", XRDP_MODULE_PATH, lib);
/* Let the main thread load the lib,*/
self->mod_handle = g_xrdp_sync(xrdp_mm_sync_load, (tintptr)text, 0);
if (self->mod_handle != 0)
{
func = g_get_proc_address(self->mod_handle, "mod_init");
if (func == 0)
{
func = g_get_proc_address(self->mod_handle, "_mod_init");
}
if (func == 0)
{
xrdp_wm_log_msg(self->wm, LOG_LEVEL_ERROR,
"error finding proc mod_init in %s, "
"not a valid xrdp backend", lib);
}
self->mod_init = (struct xrdp_mod * ( *)(void))func;
func = g_get_proc_address(self->mod_handle, "mod_exit");
if (func == 0)
{
func = g_get_proc_address(self->mod_handle, "_mod_exit");
}
if (func == 0)
{
xrdp_wm_log_msg(self->wm, LOG_LEVEL_ERROR,
"error finding proc mod_exit in %s, "
"not a valid xrdp backend", lib);
}
self->mod_exit = (int ( *)(struct xrdp_mod *))func;
if ((self->mod_init != 0) && (self->mod_exit != 0))
{
self->mod = self->mod_init();
if (self->mod != 0)
{
LOG(LOG_LEVEL_INFO, "loaded module '%s' ok, interface size %d, version %d", lib,
self->mod->size, self->mod->version);
}
}
else
{
LOG(LOG_LEVEL_ERROR, "no mod_init or mod_exit address found");
}
}
else
{
xrdp_wm_log_msg(self->wm, LOG_LEVEL_ERROR,
"error loading %s specified in xrdp.ini, please "
"add a valid entry like lib=libxrdp-vnc.so or "
"similar", lib);
return 1;
}
if (self->mod != 0)
{
self->mod->wm = (long)(self->wm);
self->mod->server_begin_update = server_begin_update;
self->mod->server_end_update = server_end_update;
self->mod->server_bell_trigger = server_bell_trigger;
self->mod->server_chansrv_in_use = server_chansrv_in_use;
self->mod->server_fill_rect = server_fill_rect;
self->mod->server_screen_blt = server_screen_blt;
self->mod->server_paint_rect = server_paint_rect;
self->mod->server_set_pointer = server_set_pointer;
self->mod->server_set_pointer_ex = server_set_pointer_ex;
self->mod->server_palette = server_palette;
self->mod->server_msg = server_msg;
self->mod->server_is_term = g_is_term;
self->mod->server_set_clip = server_set_clip;
self->mod->server_reset_clip = server_reset_clip;
self->mod->server_set_fgcolor = server_set_fgcolor;
self->mod->server_set_bgcolor = server_set_bgcolor;
self->mod->server_set_opcode = server_set_opcode;
self->mod->server_set_mixmode = server_set_mixmode;
self->mod->server_set_brush = server_set_brush;
self->mod->server_set_pen = server_set_pen;
self->mod->server_draw_line = server_draw_line;
self->mod->server_add_char = server_add_char;
self->mod->server_draw_text = server_draw_text;
self->mod->server_reset = server_reset;
self->mod->server_get_channel_count = server_get_channel_count;
self->mod->server_query_channel = server_query_channel;
self->mod->server_get_channel_id = server_get_channel_id;
self->mod->server_send_to_channel = server_send_to_channel;
self->mod->server_create_os_surface = server_create_os_surface;
self->mod->server_switch_os_surface = server_switch_os_surface;
self->mod->server_delete_os_surface = server_delete_os_surface;
self->mod->server_paint_rect_os = server_paint_rect_os;
self->mod->server_set_hints = server_set_hints;
self->mod->server_window_new_update = server_window_new_update;
self->mod->server_window_delete = server_window_delete;
self->mod->server_window_icon = server_window_icon;
self->mod->server_window_cached_icon = server_window_cached_icon;
self->mod->server_notify_new_update = server_notify_new_update;
self->mod->server_notify_delete = server_notify_delete;
self->mod->server_monitored_desktop = server_monitored_desktop;
self->mod->server_add_char_alpha = server_add_char_alpha;
self->mod->server_create_os_surface_bpp = server_create_os_surface_bpp;
self->mod->server_paint_rect_bpp = server_paint_rect_bpp;
self->mod->server_composite = server_composite;
self->mod->server_paint_rects = server_paint_rects;
self->mod->server_session_info = server_session_info;
self->mod->server_set_pointer_large = server_set_pointer_large;
self->mod->si = &(self->wm->session->si);
}
}
/* id self->mod is null, there must be a problem */
if (self->mod == 0)
{
LOG(LOG_LEVEL_ERROR, "problem loading lib in xrdp_mm_setup_mod1");
return 1;
}
return 0;
}
/*****************************************************************************/
static int
xrdp_mm_setup_mod2(struct xrdp_mm *self)
{
char text[256];
const char *name;
const char *value;
int i;
int rv;
int key_flags;
int device_flags;
rv = 1; /* failure */
g_memset(text, 0, sizeof(text));
if (!g_is_wait_obj_set(self->wm->pro_layer->self_term_event))
{
if (self->mod->mod_start(self->mod, self->wm->screen->width,
self->wm->screen->height,
self->wm->screen->bpp) != 0)
{
g_set_wait_obj(self->wm->pro_layer->self_term_event); /* kill session */
}
}
if (!g_is_wait_obj_set(self->wm->pro_layer->self_term_event))
{
if (self->display > 0)
{
if (self->code == XVNC_SESSION_CODE)
{
g_snprintf(text, 255, "%d", 5900 + self->display);
}
else if (self->code == XORG_SESSION_CODE)
{
g_snprintf(text, 255, XRDP_X11RDP_STR, self->display);
}
else
{
g_set_wait_obj(self->wm->pro_layer->self_term_event); /* kill session */
}
}
}
if (!g_is_wait_obj_set(self->wm->pro_layer->self_term_event))
{
/* this adds the port to the end of the list, it will already be in
the list as -1
the module should use the last one */
if (g_strlen(text) > 0)
{
list_add_strdup(self->login_names, "port");
list_add_strdup(self->login_values, text);
}
/* always set these */
self->mod->mod_set_param(self->mod, "client_info",
(const char *) (self->wm->session->client_info));
name = self->wm->session->client_info->hostname;
self->mod->mod_set_param(self->mod, "hostname", name);
g_snprintf(text, 255, "%d", self->wm->session->client_info->keylayout);
self->mod->mod_set_param(self->mod, "keylayout", text);
if (guid_is_set(&self->guid))
{
self->mod->mod_set_param(self->mod, "guid", (char *) &self->guid);
}
for (i = 0; i < self->login_names->count; i++)
{
name = (const char *) list_get_item(self->login_names, i);
value = (const char *) list_get_item(self->login_values, i);
self->mod->mod_set_param(self->mod, name, value);
}
/* connect */
if (self->mod->mod_connect(self->mod) == 0)
{
rv = 0; /* connect success */
}
else
{
xrdp_wm_show_log(self->wm);
if (self->wm->hide_log_window)
{
rv = 1;
}
}
}
if (rv == 0)
{
/* sync modifiers */
key_flags = 0;
device_flags = 0;
if (self->wm->scroll_lock)
{
key_flags |= 1;
}
if (self->wm->num_lock)
{
key_flags |= 2;
}
if (self->wm->caps_lock)
{
key_flags |= 4;
}
if (self->mod != 0)
{
if (self->mod->mod_event != 0)
{
self->mod->mod_event(self->mod, 17, key_flags, device_flags,
key_flags, device_flags);
}
}
}
return rv;
}
/*****************************************************************************/
/* returns error
send a list of channels to the channel handler */
static int
xrdp_mm_trans_send_channel_setup(struct xrdp_mm *self, struct trans *trans)
{
int chan_count;
/* This value should be the same as chan_count, but we need to
* cater for a possible failure of libxrdp_query_channel() */
int output_chan_count;
int chan_id;
int chan_flags;
int size;
struct stream *s;
char chan_name[256];
g_memset(chan_name, 0, sizeof(char) * 256);
s = trans_get_out_s(trans, 8192);
if (s == 0)
{
return 1;
}
s_push_layer(s, iso_hdr, 8);
s_push_layer(s, mcs_hdr, 8);
s_push_layer(s, sec_hdr, 2);
chan_count = libxrdp_get_channel_count(self->wm->session);
output_chan_count = 0;
for (chan_id = 0 ; chan_id < chan_count; ++chan_id)
{
if (libxrdp_query_channel(self->wm->session, chan_id, chan_name,
&chan_flags) == 0)
{
out_uint8a(s, chan_name, 8);
out_uint16_le(s, chan_id);
out_uint16_le(s, chan_flags);
++output_chan_count;
}
}
s_mark_end(s);
s_pop_layer(s, sec_hdr);
out_uint16_le(s, output_chan_count);
s_pop_layer(s, mcs_hdr);
size = (int)(s->end - s->p);
out_uint32_le(s, 3); /* msg id */
out_uint32_le(s, size); /* msg size */
s_pop_layer(s, iso_hdr);
size = (int)(s->end - s->p);
out_uint32_le(s, 0); /* version */
out_uint32_le(s, size); /* block size */
return trans_force_write(trans);
}
/*****************************************************************************/
/* returns error
data coming in from the channel handler, send it to the client */
static int
xrdp_mm_trans_process_channel_data(struct xrdp_mm *self, struct stream *s)
{
unsigned int size;
unsigned int total_size;
int chan_id;
int chan_flags;
int rv = 0;
if (!s_check_rem_and_log(s, 10, "Reading channel data header"))
{
rv = 1;
}
else
{
in_uint16_le(s, chan_id);
in_uint16_le(s, chan_flags);
in_uint16_le(s, size);
in_uint32_le(s, total_size);
if (!s_check_rem_and_log(s, size, "Reading channel data data"))
{
rv = 1;
}
else
{
rv = libxrdp_send_to_channel(self->wm->session, chan_id,
s->p, size, total_size, chan_flags);
}
}
return rv;
}
/*****************************************************************************/
/* returns error
process rail create window order */
static int
xrdp_mm_process_rail_create_window(struct xrdp_mm *self, struct stream *s)
{
int flags;
int window_id;
int title_bytes;
int index;
int bytes;
int rv;
struct rail_window_state_order rwso;
g_memset(&rwso, 0, sizeof(rwso));
in_uint32_le(s, window_id);
LOG(LOG_LEVEL_DEBUG, "xrdp_mm_process_rail_create_window: 0x%8.8x", window_id);
in_uint32_le(s, rwso.owner_window_id);
in_uint32_le(s, rwso.style);
in_uint32_le(s, rwso.extended_style);
in_uint32_le(s, rwso.show_state);
in_uint16_le(s, title_bytes);
if (title_bytes > 0)
{
rwso.title_info = g_new(char, title_bytes + 1);
in_uint8a(s, rwso.title_info, title_bytes);
rwso.title_info[title_bytes] = 0;
}
in_uint32_le(s, rwso.client_offset_x);
in_uint32_le(s, rwso.client_offset_y);
in_uint32_le(s, rwso.client_area_width);
in_uint32_le(s, rwso.client_area_height);
in_uint32_le(s, rwso.rp_content);
in_uint32_le(s, rwso.root_parent_handle);
in_uint32_le(s, rwso.window_offset_x);
in_uint32_le(s, rwso.window_offset_y);
in_uint32_le(s, rwso.window_client_delta_x);
in_uint32_le(s, rwso.window_client_delta_y);
in_uint32_le(s, rwso.window_width);
in_uint32_le(s, rwso.window_height);
in_uint16_le(s, rwso.num_window_rects);
if (rwso.num_window_rects > 0)
{
bytes = sizeof(struct rail_window_rect) * rwso.num_window_rects;
rwso.window_rects = (struct rail_window_rect *)g_malloc(bytes, 0);
for (index = 0; index < rwso.num_window_rects; index++)
{
in_uint16_le(s, rwso.window_rects[index].left);
in_uint16_le(s, rwso.window_rects[index].top);
in_uint16_le(s, rwso.window_rects[index].right);
in_uint16_le(s, rwso.window_rects[index].bottom);
}
}
in_uint32_le(s, rwso.visible_offset_x);
in_uint32_le(s, rwso.visible_offset_y);
in_uint16_le(s, rwso.num_visibility_rects);
if (rwso.num_visibility_rects > 0)
{
bytes = sizeof(struct rail_window_rect) * rwso.num_visibility_rects;
rwso.visibility_rects = (struct rail_window_rect *)g_malloc(bytes, 0);
for (index = 0; index < rwso.num_visibility_rects; index++)
{
in_uint16_le(s, rwso.visibility_rects[index].left);
in_uint16_le(s, rwso.visibility_rects[index].top);
in_uint16_le(s, rwso.visibility_rects[index].right);
in_uint16_le(s, rwso.visibility_rects[index].bottom);
}
}
in_uint32_le(s, flags);
rv = libxrdp_orders_init(self->wm->session);
if (rv == 0)
{
rv = libxrdp_window_new_update(self->wm->session, window_id, &rwso, flags);
}
if (rv == 0)
{
rv = libxrdp_orders_send(self->wm->session);
}
g_free(rwso.title_info);
g_free(rwso.window_rects);
g_free(rwso.visibility_rects);
return rv;
}
#if 0
/*****************************************************************************/
/* returns error
process rail configure window order */
static int
xrdp_mm_process_rail_configure_window(struct xrdp_mm *self, struct stream *s)
{
int flags;
int window_id;
int index;
int bytes;
int rv;
struct rail_window_state_order rwso;
g_memset(&rwso, 0, sizeof(rwso));
in_uint32_le(s, window_id);
LOG(LOG_LEVEL_DEBUG, "xrdp_mm_process_rail_configure_window: 0x%8.8x", window_id);
in_uint32_le(s, rwso.client_offset_x);
in_uint32_le(s, rwso.client_offset_y);
in_uint32_le(s, rwso.client_area_width);
in_uint32_le(s, rwso.client_area_height);
in_uint32_le(s, rwso.rp_content);
in_uint32_le(s, rwso.root_parent_handle);
in_uint32_le(s, rwso.window_offset_x);
in_uint32_le(s, rwso.window_offset_y);
in_uint32_le(s, rwso.window_client_delta_x);
in_uint32_le(s, rwso.window_client_delta_y);
in_uint32_le(s, rwso.window_width);
in_uint32_le(s, rwso.window_height);
in_uint16_le(s, rwso.num_window_rects);
if (rwso.num_window_rects > 0)
{
bytes = sizeof(struct rail_window_rect) * rwso.num_window_rects;
rwso.window_rects = (struct rail_window_rect *)g_malloc(bytes, 0);
for (index = 0; index < rwso.num_window_rects; index++)
{
in_uint16_le(s, rwso.window_rects[index].left);
in_uint16_le(s, rwso.window_rects[index].top);
in_uint16_le(s, rwso.window_rects[index].right);
in_uint16_le(s, rwso.window_rects[index].bottom);
}
}
in_uint32_le(s, rwso.visible_offset_x);
in_uint32_le(s, rwso.visible_offset_y);
in_uint16_le(s, rwso.num_visibility_rects);
if (rwso.num_visibility_rects > 0)
{
bytes = sizeof(struct rail_window_rect) * rwso.num_visibility_rects;
rwso.visibility_rects = (struct rail_window_rect *)g_malloc(bytes, 0);
for (index = 0; index < rwso.num_visibility_rects; index++)
{
in_uint16_le(s, rwso.visibility_rects[index].left);
in_uint16_le(s, rwso.visibility_rects[index].top);
in_uint16_le(s, rwso.visibility_rects[index].right);
in_uint16_le(s, rwso.visibility_rects[index].bottom);
}
}
in_uint32_le(s, flags);
rv = libxrdp_orders_init(self->wm->session);
if (rv == 0)
{
rv = libxrdp_window_new_update(self->wm->session, window_id, &rwso, flags);
}
if (rv == 0)
{
rv = libxrdp_orders_send(self->wm->session);
}
g_free(rwso.window_rects);
g_free(rwso.visibility_rects);
return rv;
}
#endif
/*****************************************************************************/
/* returns error
process rail destroy window order */
static int
xrdp_mm_process_rail_destroy_window(struct xrdp_mm *self, struct stream *s)
{
int window_id;
int rv;
in_uint32_le(s, window_id);
LOG(LOG_LEVEL_DEBUG, "xrdp_mm_process_rail_destroy_window 0x%8.8x", window_id);
rv = libxrdp_orders_init(self->wm->session);
if (rv == 0)
{
rv = libxrdp_window_delete(self->wm->session, window_id);
}
if (rv == 0)
{
rv = libxrdp_orders_send(self->wm->session);
}
return rv;
}
/*****************************************************************************/
/* returns error
process rail update window (show state) order */
static int
xrdp_mm_process_rail_show_window(struct xrdp_mm *self, struct stream *s)
{
int window_id;
int rv;
int flags;
struct rail_window_state_order rwso;
g_memset(&rwso, 0, sizeof(rwso));
in_uint32_le(s, window_id);
in_uint32_le(s, flags);
in_uint32_le(s, rwso.show_state);
LOG(LOG_LEVEL_DEBUG, "xrdp_mm_process_rail_show_window 0x%8.8x %x", window_id,
rwso.show_state);
rv = libxrdp_orders_init(self->wm->session);
if (rv == 0)
{
rv = libxrdp_window_new_update(self->wm->session, window_id, &rwso, flags);
}
if (rv == 0)
{
rv = libxrdp_orders_send(self->wm->session);
}
return rv;
}
/*****************************************************************************/
/* returns error
process rail update window (title) order */
static int
xrdp_mm_process_rail_update_window_text(struct xrdp_mm *self, struct stream *s)
{
int size;
int flags;
int rv;
int window_id;
struct rail_window_state_order rwso;
LOG(LOG_LEVEL_DEBUG, "xrdp_mm_process_rail_update_window_text:");
in_uint32_le(s, window_id);
in_uint32_le(s, flags);
LOG(LOG_LEVEL_DEBUG, " update window title info: 0x%8.8x", window_id);
g_memset(&rwso, 0, sizeof(rwso));
in_uint32_le(s, size); /* title size */
if (size < 0 || !s_check_rem(s, size))
{
LOG(LOG_LEVEL_ERROR, "%s : invalid window text size %d",
__func__, size);
return 1;
}
rwso.title_info = g_new(char, size + 1);
in_uint8a(s, rwso.title_info, size);
rwso.title_info[size] = 0;
LOG(LOG_LEVEL_DEBUG, " set window title %s size %d 0x%8.8x", rwso.title_info, size, flags);
rv = libxrdp_orders_init(self->wm->session);
if (rv == 0)
{
rv = libxrdp_window_new_update(self->wm->session, window_id, &rwso, flags);
}
if (rv == 0)
{
rv = libxrdp_orders_send(self->wm->session);
}
LOG(LOG_LEVEL_DEBUG, " set window title %s %d", rwso.title_info, rv);
g_free(rwso.title_info);
return rv;
}
/*****************************************************************************/
/* returns error
process alternate secondary drawing orders for rail channel */
static int
xrdp_mm_process_rail_drawing_orders(struct xrdp_mm *self, struct stream *s)
{
int order_type;
int rv;
rv = 0;
in_uint32_le(s, order_type);
switch (order_type)
{
case 2: /* create_window */
xrdp_mm_process_rail_create_window(self, s);
break;
case 4: /* destroy_window */
xrdp_mm_process_rail_destroy_window(self, s);
break;
case 6: /* show_window */
rv = xrdp_mm_process_rail_show_window(self, s);
break;
case 8: /* update title info */
rv = xrdp_mm_process_rail_update_window_text(self, s);
break;
default:
break;
}
return rv;
}
#define GFX_PLANAR_BYTES (32 * 1024)
/******************************************************************************/
int
xrdp_mm_egfx_send_planar_bitmap(struct xrdp_mm *self,
struct xrdp_bitmap *bitmap,
struct xrdp_rect *rect)
{
struct xrdp_egfx_rect gfx_rect;
struct stream *comp_s;
struct stream *temp_s;
char *pixels;
char *src8;
char *dst8;
int index;
int lines;
int comp_bytes;
int xindex;
int yindex;
int bwidth;
int bheight;
int cx;
int cy;
LOG_DEVEL(LOG_LEVEL_TRACE, "xrdp_mm_egfx_send_planar_bitmap:");
bwidth = rect->right - rect->left;
bheight = rect->bottom - rect->top;
if ((bwidth < 1) || (bheight < 1))
{
return 0;
}
if (bwidth < 64)
{
cx = bwidth;
cy = 4096 / cx;
}
else if (bheight < 64)
{
cy = bheight;
cx = 4096 / cy;
}
else
{
cx = 64;
cy = 64;
}
while (cx * cy < 4096)
{
if (cx < cy)
{
cx++;
cy = 4096 / cx;
}
else
{
cy++;
cx = 4096 / cy;