-
Notifications
You must be signed in to change notification settings - Fork 7
/
MyXmlConfig.cpp
2759 lines (2624 loc) · 106 KB
/
MyXmlConfig.cpp
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
// $Id: MyXmlConfig.cpp 704 2012-03-14 14:55:15Z felfert $
//
// Copyright (C) 2006 The OpenNX Team
// Author: Fritz Elfert
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU Library General Public License as
// published by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this program; if not, write to the
// Free Software Foundation, Inc.,
// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#if defined(__GNUG__) && !defined(__APPLE__)
#pragma implementation "MyXmlConfig.h"
#endif
// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
#include <wx/filename.h>
#include <wx/xml/xml.h>
#include <wx/arrimpl.cpp>
#include <wx/file.h>
#include <wx/mstream.h>
#include <wx/wfstream.h>
#include <wx/regex.h>
#include <wx/url.h>
#include <wx/config.h>
#include <wx/display.h>
class wxConfigBase;
#include "LibUSB.h"
#include "MyXmlConfig.h"
#include "WinShare.h"
#ifdef APP_OPENNX
# include "opennxApp.h"
#endif
#ifdef APP_WATCHUSBIP
# include "watchUsbIpApp.h"
#endif
#include "pwcrypt.h"
#include "osdep.h"
#ifdef APP_OPENNX
# ifdef HAVE_LIBCURL
# include <curl/curl.h>
# endif
#endif
#include "trace.h"
ENABLE_TRACE;
#define STR_TRUE wxT("true")
#define STR_FALSE wxT("false");
#define STR_ONE wxT("1")
#define STR_ZERO wxT("0")
// We use something the user cannot type here!
#define DUMMY_MD5_PASSWORD wxT("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b")
#define DUMMY_CLR_PASSWORD wxT("\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r")
#define DEFAULT_GUEST_USER wxT("NX guest user")
IMPLEMENT_DYNAMIC_CLASS(ShareGroup, wxObject);
IMPLEMENT_DYNAMIC_CLASS(SharedUsbDevice, wxObject);
WX_DEFINE_OBJARRAY(ArrayOfShareGroups);
WX_DEFINE_OBJARRAY(ArrayOfUsbForwards);
wxString ShareGroup::toString()
{
wxString ret = wxT("Name: '");
ret.Append(m_sGroupName);
ret.Append(wxT("', Type: "));
switch (m_eType) {
case SharedResource::SHARE_UNKNOWN:
ret.Append(wxT("unknown"));
break;
case SharedResource::SHARE_SMB_DISK:
ret.Append(wxT("SMBdisk, Share: '"));
ret.Append(m_sShareName);
ret.Append(wxT("', Alias: '"));
ret.Append(m_sAlias);
ret.Append(wxT("'"));
break;
case SharedResource::SHARE_SMB_PRINTER:
ret.Append(wxT("SMBprinter, Share: '"));
ret.Append(m_sShareName);
ret.Append(wxT("', Alias: '"));
ret.Append(m_sAlias);
ret.Append(wxT("'"));
break;
case SharedResource::SHARE_CUPS_PRINTER:
ret.Append(wxT("CUPSprinter, Share: '"));
ret.Append(m_sShareName);
ret.Append(wxT("', Driver: '"));
ret.Append(m_sDriver);
ret.Append(wxT("', Public: "));
ret.Append(m_bPublic ? wxT("true") : wxT("false"));
ret.Append(wxT(", Default: "));
ret.Append(m_bDefault ? wxT("true") : wxT("false"));
break;
}
return ret;
}
bool ShareGroup::operator ==(const ShareGroup &other)
{
if (m_eType != other.m_eType) return false;
if (m_sGroupName != other.m_sGroupName) return false;
if (m_sUsername != other.m_sUsername) return false;
if (m_sPassword != other.m_sPassword) return false;
if (m_sShareName != other.m_sShareName) return false;
switch (m_eType) {
case SharedResource::SHARE_UNKNOWN:
break;
case SharedResource::SHARE_SMB_DISK:
if (m_sAlias != other.m_sAlias) return false;
break;
case SharedResource::SHARE_SMB_PRINTER:
case SharedResource::SHARE_CUPS_PRINTER:
if (m_sDriver != other.m_sDriver) return false;
if (m_bPublic != other.m_bPublic) return false;
if (m_bDefault != other.m_bDefault) return false;
break;
}
return true;
}
bool ShareGroup::operator !=(const ShareGroup &other)
{
return (!(*this == other));
}
bool SharedUsbDevice::operator ==(const SharedUsbDevice &other)
{
if (m_eMode != other.m_eMode) return false;
if (m_sVendor != other.m_sVendor) return false;
if (m_sProduct != other.m_sProduct) return false;
if (m_sSerial != other.m_sSerial) return false;
if (m_iVendorID != other.m_iVendorID) return false;
if (m_iProductID != other.m_iProductID) return false;
if (m_iClass != other.m_iClass) return false;
return true;
}
bool SharedUsbDevice::cmpNoMode(const SharedUsbDevice &other)
{
if (m_sVendor != other.m_sVendor) return false;
if (m_sProduct != other.m_sProduct) return false;
if (m_sSerial != other.m_sSerial) return false;
if (m_iVendorID != other.m_iVendorID) return false;
if (m_iProductID != other.m_iProductID) return false;
if (m_iClass != other.m_iClass) return false;
return true;
}
bool SharedUsbDevice::operator !=(const SharedUsbDevice &other)
{
return (!(*this == other));
}
bool SharedUsbDevice::MatchHotplug(const USBDevice &udev)
{
if (m_iVendorID >= 0) {
if (m_iVendorID != udev.GetVendorID())
return false;
}
if (m_iProductID >= 0) {
if (m_iProductID != udev.GetProductID())
return false;
}
if (m_iClass >= 0) {
if (m_iClass != udev.GetDeviceClass())
return false;
}
if (!m_sVendor.IsEmpty()) {
if (!udev.GetVendor().StartsWith(m_sVendor))
return false;
}
if (!m_sProduct.IsEmpty()) {
if (!udev.GetProduct().StartsWith(m_sProduct))
return false;
}
if (!m_sSerial.IsEmpty()) {
if (!udev.GetSerial().StartsWith(m_sSerial))
return false;
}
return true;
}
wxString SharedUsbDevice::toShortString()
{
wxString ret = m_sVendor.Strip(wxString::both);
if ((!ret.IsEmpty()) && (!m_sProduct.IsEmpty()))
ret.Append(wxT(" "));
ret.Append(m_sProduct.Strip(wxString::both));
return ret;
}
void
MyXmlConfig::init()
{
saved = NULL;
m_bDisableBackingstore = false;
m_bDisableComposite = false;
m_bDisableRender = false;
m_bDisableShmem = false;
m_bDisableShpix = false;
m_bDisableTaint = false;
m_bDisableTcpNoDelay = false;
m_bDisableXagent = false;
m_bDisableZlibCompression = false;
m_bEnableMultimedia = false;
m_bEnableNativePA = true;
m_bEnableMonoPA = false;
m_bEnableSmbSharing = false;
m_bEnableSSL = true;
m_bEnableUSBIP = false;
m_bExternalProxy = false;
m_bGuestMode = false;
m_bKbdLayoutOther = false;
m_bOldConfig = false;
m_bProxyPassRemember = false;
m_bRdpCache = true;
m_bRdpRememberPassword = false;
m_bRdpRootless = true;
m_bRdpRunApplication = false;
m_bRememberPassword = false;
m_bRemoveOldSessionFiles = true;
m_bRunConsole = false;
m_bRunXclients = false;
m_bUseCups = false;
m_bUseCustomImageEncoding = false;
m_bUseProxy = false;
m_bUseSmartCard = false;
m_bValid = false;
m_bWritable = true;
m_bVirtualDesktop = false;
m_bVncRememberPassword = false;
m_bVncRootless = true;
m_bVncUseNxAuth = false;
m_bDisableDirectDraw = false;
m_bDisableDeferredUpdates = false;
m_bGrabKeyboard = false;
m_iClipFilter = 2;
m_iCupsPort = 631;
m_iDisplayHeight = 480;
m_iDisplayWidth = 640;
m_iImageEncoding = 3;
m_iJpegQuality = 6;
m_iProxyPort = 3128;
m_iRdpAuthType = 1;
m_iRdpColors = 8;
m_iRdpImageEncoding = 3;
m_iRdpJpegQuality = 6;
m_iServerPort = 22;
m_iSmbPort = 445;
m_iUsedShareGroups = 0;
m_iVncDisplayNumber = 0;
m_iVncImageEncoding = 3;
m_iVncJpegQuality = 6;
m_iXdmBroadcastPort = 177;
m_iXdmListPort = 177;
m_iXdmQueryPort = 177;
m_eCacheDisk = CACHEDISK_32MB;
m_eCacheMemory = CACHEMEM_8MB;
m_eConnectionSpeed = SPEED_ADSL;
m_eDesktopType = DTYPE_KDE;
m_eDisplayType = DPTYPE_AVAILABLE;
m_eSessionType = STYPE_UNIX;
m_eXdmMode = XDM_MODE_SERVER;
m_eRatePA = RATEPA_NORESAMPLE;
m_sCommandLine = wxEmptyString;
wxConfigBase::Get()->Read(wxT("Config/CupsPath"), &m_sCupsPath);
if (m_sCupsPath.IsEmpty())
m_sCupsPath = wxT(CUPS_DEFAULT_PATH);
m_sFileName = wxEmptyString;
m_sGuestUser = wxEmptyString;
m_sGuestPassword = wxEmptyString;
m_sKbdLayoutLanguage = wxString(wxConvLocal.cMB2WX(x11_keyboard_type)).AfterFirst(wxT('/')).BeforeFirst(wxT(','));
m_sName = wxEmptyString;
m_sPassword = wxEmptyString;
m_sProxyCommand = wxEmptyString;
m_sProxyHost = wxEmptyString;
m_sProxyPass = wxEmptyString;
m_sProxyUser = wxEmptyString;
m_sRdpApplication = wxEmptyString;
m_sRdpDomain = wxEmptyString;
m_sRdpHostName = wxEmptyString;
m_sRdpPassword = wxEmptyString;
m_sRdpUsername = wxEmptyString;
m_sServerHost = wxEmptyString;
m_sSshKey = wxEmptyString;
m_sUsername = wxEmptyString;
m_sVncHostName = wxEmptyString;
m_sVncPassword = wxEmptyString;
m_sXdmListHost = wxT("localhost");
m_sXdmQueryHost = wxT("localhost");
m_pMd5Password = NULL;
m_pClrPassword = NULL;
}
MyXmlConfig::MyXmlConfig()
{
init();
}
MyXmlConfig::MyXmlConfig(const wxString &filename)
{
init();
if (filename.StartsWith(wxT("http://")) ||
filename.StartsWith(wxT("https://")) ||
filename.StartsWith(wxT("ftp://")) ||
filename.StartsWith(wxT("file://")))
LoadFromURL(filename);
else
LoadFromFile(filename);
}
MyXmlConfig::~MyXmlConfig()
{
if (saved)
delete saved;
if (m_pMd5Password)
delete m_pMd5Password;
if (m_pClrPassword)
delete m_pClrPassword;
}
MyXmlConfig &
MyXmlConfig::operator =(const MyXmlConfig &other)
{
saved = NULL;
m_bDisableBackingstore = other.m_bDisableBackingstore;
m_bDisableComposite = other.m_bDisableComposite;
m_bDisableRender = other.m_bDisableRender;
m_bDisableShmem = other.m_bDisableShmem;
m_bDisableShpix = other.m_bDisableShpix;
m_bDisableTaint = other.m_bDisableTaint;
m_bDisableTcpNoDelay = other.m_bDisableTcpNoDelay;
m_bDisableXagent = other.m_bDisableXagent;
m_bDisableZlibCompression = other.m_bDisableZlibCompression;
m_bEnableMultimedia = other.m_bEnableMultimedia;
m_bEnableNativePA = other.m_bEnableNativePA;
m_bEnableMonoPA = other.m_bEnableMonoPA;
m_bEnableSmbSharing = other.m_bEnableSmbSharing;
m_bEnableSSL = other.m_bEnableSSL;
m_bEnableUSBIP = other.m_bEnableUSBIP;
m_bExternalProxy = other.m_bExternalProxy;
m_bGuestMode = other.m_bGuestMode;
m_bKbdLayoutOther = other.m_bKbdLayoutOther;
m_bProxyPassRemember = other.m_bProxyPassRemember;
m_bRdpCache = other.m_bRdpCache;
m_bRdpRememberPassword = other.m_bRdpRememberPassword;
m_bRdpRootless = other.m_bRdpRootless;
m_bRdpRunApplication = other.m_bRdpRunApplication;
m_bRememberPassword = other.m_bRememberPassword;
m_bRemoveOldSessionFiles = other.m_bRemoveOldSessionFiles;
m_bRunConsole = other.m_bRunConsole;
m_bRunXclients = other.m_bRunXclients;
m_bUseCups = other.m_bUseCups;
m_bUseCustomImageEncoding = other.m_bUseCustomImageEncoding;
m_bUseProxy = other.m_bUseProxy;
m_bUseSmartCard = other.m_bUseSmartCard;
m_bValid = other.m_bValid;
// Don't copy readonly flag
m_bVirtualDesktop = other.m_bVirtualDesktop;
m_bVncRememberPassword = other.m_bVncRememberPassword;
m_bVncRootless = other.m_bVncRootless;
m_bVncUseNxAuth = other.m_bVncUseNxAuth;
m_bDisableDirectDraw = other.m_bDisableDirectDraw;
m_bDisableDeferredUpdates = other.m_bDisableDeferredUpdates;
m_bGrabKeyboard = other.m_bGrabKeyboard;
m_iClipFilter = other.m_iClipFilter;
m_iCupsPort = other.m_iCupsPort;
m_iDisplayHeight = other.m_iDisplayHeight;
m_iDisplayWidth = other.m_iDisplayWidth;
m_iImageEncoding = other.m_iImageEncoding;
m_iJpegQuality = other.m_iJpegQuality;
m_sKbdLayoutLanguage = other.m_sKbdLayoutLanguage;
m_iProxyPort = other.m_iProxyPort;
m_iRdpAuthType = other.m_iRdpAuthType;
m_iRdpColors = other.m_iRdpColors;
m_iRdpImageEncoding = other.m_iRdpImageEncoding;
m_iRdpJpegQuality = other.m_iRdpJpegQuality;
m_iServerPort = other.m_iServerPort;
m_iSmbPort = other.m_iSmbPort;
m_iUsedShareGroups = other.m_iUsedShareGroups;
m_iVncDisplayNumber = other.m_iVncDisplayNumber;
m_iVncImageEncoding = other.m_iVncImageEncoding;
m_iVncJpegQuality = other.m_iVncJpegQuality;
m_iXdmBroadcastPort = other.m_iXdmBroadcastPort;
m_iXdmListPort = other.m_iXdmListPort;
m_iXdmQueryPort = other.m_iXdmQueryPort;
m_eCacheDisk = other.m_eCacheDisk;
m_eCacheMemory = other.m_eCacheMemory;
m_eConnectionSpeed = other.m_eConnectionSpeed;
m_eDesktopType = other.m_eDesktopType;
m_eDisplayType = other.m_eDisplayType;
m_eSessionType = other.m_eSessionType;
m_eXdmMode = other.m_eXdmMode;
m_eRatePA = other.m_eRatePA;
m_sCommandLine = other.m_sCommandLine;
m_sCupsPath = other.m_sCupsPath;
m_sGuestPassword = other.m_sGuestPassword;
m_sGuestUser = other.m_sGuestUser;
m_sName = other.m_sName;
m_sPassword = other.m_sPassword;
m_sProxyCommand = other.m_sProxyCommand;
m_sProxyHost = other.m_sProxyHost;
m_sProxyPass = other.m_sProxyPass;
m_sProxyUser = other.m_sProxyUser;
m_sRdpApplication = other.m_sRdpApplication;
m_sRdpDomain = other.m_sRdpDomain;
m_sRdpHostName = other.m_sRdpHostName;
m_sRdpPassword = other.m_sRdpPassword;
m_sRdpUsername = other.m_sRdpUsername;
m_sServerHost = other.m_sServerHost;
m_sSshKey = other.m_sSshKey;
m_sUsername = other.m_sUsername;
m_sVncHostName = other.m_sVncHostName;
m_sVncPassword = other.m_sVncPassword;
m_sXdmListHost = other.m_sXdmListHost;
m_sXdmQueryHost = other.m_sXdmQueryHost;
m_aShareGroups = other.m_aShareGroups;
m_aUsedShareGroups = other.m_aUsedShareGroups;
m_aUsbForwards = other.m_aUsbForwards;
if (other.m_pMd5Password) {
if (m_pMd5Password)
delete m_pMd5Password;
m_pMd5Password = new wxString(*other.m_pMd5Password);
}
if (other.m_pClrPassword) {
if (m_pClrPassword)
delete m_pClrPassword;
m_pClrPassword = new wxString(*other.m_pClrPassword);
}
return *this;
}
// Retrieve parameters for proxy otion file
wxString
MyXmlConfig::sGetProxyParams(const long protocolVersion)
{
wxUnusedVar(protocolVersion);
wxString ret = wxEmptyString;
ret << wxT(",shmem=") << (m_bDisableShmem ? 0 : 1)
<< wxT(",shpix=") << (m_bDisableShpix ? 0 : 1)
;
// FIXME: use real settings
ret << wxT(",font=1");
ret << wxT(",aux=1");
return ret;
}
// Retrieve parameters for listsession command
wxString
MyXmlConfig::sGetListParams(const long protocolVersion)
{
wxUnusedVar(protocolVersion);
wxString ret = wxT(" --user=\"");
if (m_eSessionType == STYPE_SHADOW) {
ret = wxT(" --type=\"shadow\"");
return ret;
}
if (m_bGuestMode) {
if (m_sGuestUser.IsEmpty())
ret << DEFAULT_GUEST_USER;
else
ret << m_sGuestUser;
} else
ret << m_sUsername;
if (protocolVersion >= 0x00040000)
ret << wxT("\" --status=\"disconnected,connected\"");
else
ret << wxT("\" --status=\"suspended,running\"");
ret << wxT(" --type=\"");
switch (m_eSessionType) {
case STYPE_SHADOW:
break;
case STYPE_UNIX:
ret << wxT("unix-");
switch (m_eDesktopType) {
case DTYPE_ANY:
case DTYPE_RDP:
case DTYPE_RFB:
break;
case DTYPE_KDE:
ret << wxT("kde\"");
break;
case DTYPE_GNOME:
ret << wxT("gnome\"");
break;
case DTYPE_CDE:
ret << wxT("cde\"");
break;
case DTYPE_XFCE:
ret << wxT("xfce\"");
break;
case DTYPE_XDM:
ret << wxT("xdm\"");
break;
case DTYPE_CUSTOM:
if (m_bRunConsole)
ret << wxT("console\"");
else if (m_bRunXclients)
ret << wxT("default\"");
else
ret << wxT("application\"");
break;
}
break;
case STYPE_WINDOWS:
ret << wxT("windows\"");
break;
case STYPE_VNC:
ret << wxT("vnc\"");
break;
}
int w, h;
::wxDisplaySize(&w, &h);
ret << wxT(" --geometry=\"") << w << wxT("x") << h << wxT("x")
<< ::wxDisplayDepth() << (m_bDisableRender ? wxEmptyString : wxT("+render"))
<< ((m_eDisplayType == DPTYPE_FULLSCREEN) ? wxT("+fullscreen") : wxEmptyString)
<< wxT("\"");
return ret;
}
wxString
MyXmlConfig::UrlEsc(const wxString &s)
{
size_t len = s.Length();
wxString ret;
for (size_t i = 0; i < len; i++) {
switch ((wchar_t)s[i]) {
case wxT(' '):
case wxT(':'):
case wxT('"'):
case wxT('&'):
case wxT('$'):
case wxT('`'):
case wxT('\''):
case wxT('\\'):
ret << wxString::Format(wxT("%%%02X"), s[i]);
break;
default:
ret << s[i];
}
}
return ret;
}
void
MyXmlConfig::getDesktopSize(int &dw, int &dh, int &ww, int &wh)
{
// Fetch the size of the display and the workarea
// (workarea == display size reduced by the size of the taskbar and window
// decorations) where our toplevel dialog are shown.
wxWindow *tlw = ::wxGetApp().GetTopWindow();
if (NULL == tlw) {
wxLogError(_("Could not find application window"));
return;
}
int dspidx = wxDisplay::GetFromWindow(tlw);
wxDisplay dsp(dspidx);
wxRect r = dsp.GetGeometry();
dw = r.GetWidth();
dh = r.GetHeight();
r = dsp.GetClientArea();
wxSize sz = tlw->GetSize();
wxSize clsz = tlw->GetClientSize();
#ifdef __WXMSW__
ww = r.GetWidth();
wh = r.GetHeight();
#else
ww = r.GetWidth() - (sz.GetWidth() - clsz.GetWidth());
wh = r.GetHeight() - (sz.GetHeight() - clsz.GetHeight());
#endif
myLogTrace(MYTRACETAG, wxT("Display: %dx%d, Workarea: %dx%d (netto: %d,%d)"),
dw, dh, (int)r.GetWidth(), (int)r.GetHeight(), ww, wh);
}
// Retrieve parameters for startsession command
wxString
MyXmlConfig::sGetSessionParams(const long protocolVersion, bool bNew, const wxString &clrpass)
{
wxUnusedVar(protocolVersion);
wxString ret = wxEmptyString;
bool bNeedGeometry = true;
int dspw, dsph, clientw, clienth, gw, gh;
getDesktopSize(dspw, dsph, clientw, clienth);
ret << wxString::Format(wxT(" --session=\"%s\""), VMB(m_sName));
ret << wxT(" --type=\"");
switch (m_eSessionType) {
case STYPE_SHADOW:
ret << wxT("shadow\"");
if (m_bUseCustomImageEncoding) {
ret << wxT(" --imagecompressionmethod=\"") << m_iImageEncoding << wxT("\"")
<< wxT(" --imagecompressionlevel=\"")
<< (((-1 == m_iImageEncoding) || (4 == m_iImageEncoding)) ? m_iJpegQuality : -1) << wxT("\"");
}
break;
case STYPE_UNIX:
ret << wxT("unix-");
switch (m_eDesktopType) {
case DTYPE_ANY:
case DTYPE_RDP:
case DTYPE_RFB:
break;
case DTYPE_KDE:
ret << wxT("kde\"");
break;
case DTYPE_GNOME:
ret << wxT("gnome\"");
break;
case DTYPE_CDE:
ret << wxT("cde\"");
break;
case DTYPE_XFCE:
ret << wxT("xfce\"");
break;
case DTYPE_XDM:
ret << wxT("xdm\"");
switch (m_eXdmMode) {
case XDM_MODE_SERVER:
ret << wxT(" --xdm_port=\"-1\"");
break;
case XDM_MODE_QUERY:
ret << wxT(" --xdm_type=\"query\"")
<< wxT(" --xdm_host=\"") << m_sXdmQueryHost << wxT("\"")
<< wxT(" --xdm_port=\"") << m_iXdmQueryPort << wxT("\"");
break;
case XDM_MODE_BROADCAST:
ret << wxT(" --xdm_type=\"broadcast\"")
<< wxT(" --xdm_port=\"") << m_iXdmBroadcastPort << wxT("\"");
break;
case XDM_MODE_LIST:
ret << wxT(" --xdm_type=\"list\"")
<< wxT(" --xdm_host=\"") << m_sXdmListHost << wxT("\"")
<< wxT(" --xdm_port=\"") << m_iXdmListPort << wxT("\"");
break;
}
break;
case DTYPE_CUSTOM:
if (m_bRunConsole)
ret << wxT("console\"");
else if (m_bRunXclients)
ret << wxT("default\"");
else {
// bNeedGeometry = false;
ret << wxT("application\"");
ret << wxT(" --application=\"")
<< UrlEsc(m_sCommandLine) << wxT("\"");
}
ret << wxT(" --rootless=\"") << (m_bVirtualDesktop ? 0 : 1)
<< wxT("\" --virtualdesktop=\"")
<< (m_bVirtualDesktop ? 1 : 0) << wxT("\"");
break;
}
if (DTYPE_CUSTOM != m_eDesktopType)
ret << wxT(" --rootless=\"0\" --virtualdesktop=\"1\"");
if (m_bUseCustomImageEncoding) {
ret << wxT(" --imagecompressionmethod=\"") << m_iImageEncoding << wxT("\"")
<< wxT(" --imagecompressionlevel=\"")
<< (((-1 == m_iImageEncoding) || (4 == m_iImageEncoding)) ? m_iJpegQuality : -1) << wxT("\"");
}
break;
case STYPE_WINDOWS:
ret << wxT("windows\"")
<< wxT(" --agent_server=\"") << UrlEsc(m_sRdpHostName)
<< wxT("\" --agent_domain=\"") << UrlEsc(m_sRdpDomain)
<< wxT("\"");
switch (m_iRdpAuthType) {
case 0:
// use specified user/passwd
ret << wxT(" --agent_user=\"") << UrlEsc(m_sRdpUsername)
<< wxT("\" --agent_password=\"") << UrlEsc(m_sRdpPassword)
<< wxT("\"");
break;
case 1:
// show winlogon (empty username and password)
break;
case 2:
// use NX credentials
ret << wxT(" --agent_user=\"") << UrlEsc(sGetSessionUser())
<< wxT("\" --agent_password=\"")
<< UrlEsc(m_bRememberPassword ? sGetSessionPassword() : clrpass)
<< wxT("\"");
break;
break;
}
if (m_bRdpRunApplication)
ret << wxT(" --application=\"") << UrlEsc(m_sRdpApplication) << wxT("\"");
if (m_bUseCustomImageEncoding) {
ret << wxT(" --rdpcolors=\"");
switch (m_iRdpColors) {
case 0:
ret << wxT("256\"");
break;
case 1:
ret << wxT("32K\"");
break;
case 2:
ret << wxT("64K\"");
break;
case 3:
ret << wxT("16M\"");
break;
}
ret << wxT(" --rdpcache=\"") << (m_bRdpCache ? 1 : 0) << wxT("\"")
<< wxT(" --imagecompressionmethod=\"") << m_iRdpImageEncoding << wxT("\"")
<< wxT(" --imagecompressionlevel=\"")
<< (((-1 == m_iRdpImageEncoding) || (4 == m_iRdpImageEncoding)) ? m_iRdpJpegQuality : -1)
<< wxT("\"");
}
if (m_bRdpRootless)
ret << wxT(" --rootless=\"1\" --virtualdesktop=\"0\"");
break;
break;
case STYPE_VNC:
ret << wxT("vnc\"")
<< wxT(" --agent_server=\"")
<< UrlEsc(m_sVncHostName) << wxT("%3A") << m_iVncDisplayNumber
<< wxT("\" --agent_password=\"") << UrlEsc(m_sVncPassword) << wxT("\"");
if (m_bUseCustomImageEncoding) {
ret << wxT(" --imagecompressionmethod=\"") << m_iVncImageEncoding << wxT("\"")
<< wxT(" --imagecompressionlevel=\"")
<< (((-1 == m_iVncImageEncoding) || (4 == m_iVncImageEncoding)) ? m_iVncJpegQuality : -1)
<< wxT("\"");
}
if (m_bVncRootless)
ret << wxT(" --rootless=\"1\" --virtualdesktop=\"0\"");
break;
}
ret << wxT(" --cache=\"");
switch (m_eCacheMemory) {
case CACHEMEM_0MB:
ret << wxT("0M\"");
break;
case CACHEMEM_1MB:
ret << wxT("1M\"");
break;
case CACHEMEM_2MB:
ret << wxT("2M\"");
break;
case CACHEMEM_4MB:
ret << wxT("4M\"");
break;
case CACHEMEM_8MB:
ret << wxT("8M\"");
break;
case CACHEMEM_16MB:
ret << wxT("16M\"");
break;
case CACHEMEM_32MB:
ret << wxT("32M\"");
break;
case CACHEMEM_64MB:
ret << wxT("64M\"");
break;
case CACHEMEM_128MB:
ret << wxT("128M\"");
break;
}
ret << wxT(" --images=\"");
switch (m_eCacheDisk) {
case CACHEDISK_0MB:
ret << wxT("0M\"");
break;
case CACHEDISK_4MB:
ret << wxT("4M\"");
break;
case CACHEDISK_8MB:
ret << wxT("8M\"");
break;
case CACHEDISK_16MB:
ret << wxT("16M\"");
break;
case CACHEDISK_32MB:
ret << wxT("32M\"");
break;
case CACHEDISK_64MB:
ret << wxT("64M\"");
break;
case CACHEDISK_128MB:
ret << wxT("128M\"");
break;
case CACHEDISK_256MB:
ret << wxT("256M\"");
break;
case CACHEDISK_512MB:
ret << wxT("512M\"");
break;
}
ret << wxT(" --link=\"");
switch (m_eConnectionSpeed) {
case SPEED_MODEM:
ret << wxT("modem\"");
break;
case SPEED_ISDN:
ret << wxT("isdn\"");
break;
case SPEED_ADSL:
ret << wxT("adsl\"");
break;
case SPEED_WAN:
ret << wxT("wan\"");
break;
case SPEED_LAN:
ret << wxT("lan\"");
break;
}
gw = clientw; gh = clienth;
if (bNeedGeometry) {
ret << wxT(" --geometry=\"");
switch (m_eDisplayType) {
case DPTYPE_640x480:
gw = 640; gh = 480;
break;
case DPTYPE_800x600:
gw = 800; gh = 600;
break;
case DPTYPE_1024x768:
gw = 1024; gh = 768;
break;
case DPTYPE_1280x1024:
gw = 1280; gh = 1024;
break;
case DPTYPE_1400x1050:
gw = 1400; gh = 1050;
break;
case DPTYPE_1440x900:
gw = 1440; gh = 900;
break;
case DPTYPE_1680x1050:
gw = 1680; gh = 1050;
break;
case DPTYPE_1920x1080:
gw = 1920; gh = 1080;
break;
case DPTYPE_AVAILABLE:
case DPTYPE_NODECORATION:
gw = clientw; gh = clienth;
break;
case DPTYPE_CUSTOM:
gw = m_iDisplayWidth; gh = m_iDisplayHeight;
break;
case DPTYPE_REMOTE:
case DPTYPE_FULLSCREEN:
gw = dspw; gh = dsph;
break;
}
ret << wxString::Format(wxT("%dx%d\""), gw, gh);
if (m_eDisplayType == DPTYPE_FULLSCREEN)
ret << wxT(" --fullscreen=\"1\"");
}
if (m_eSessionType != STYPE_SHADOW) {
int dspw2 = dspw, dsph2 = dsph;
if ((m_eDesktopType != DTYPE_CUSTOM) || (m_bVirtualDesktop)) {
dspw2 = gw; dsph2 =gh;
}
if ((m_eSessionType == STYPE_VNC) || (m_eSessionType == STYPE_WINDOWS))
{
dspw2 = clientw; dsph2 =clienth;
}
ret << wxT(" --screeninfo=\"") << dspw2 << wxT("x") << dsph2 << wxT("x")
<< ::wxDisplayDepth() << (m_bDisableRender ? wxEmptyString : wxT("+render"))
<< ((m_eDisplayType == DPTYPE_FULLSCREEN) ? wxT("+fullscreen") : wxEmptyString)
<< wxT("\"");
}
wxString kbdLocal = wxString(wxConvLocal.cMB2WX(x11_keyboard_type)).BeforeFirst(wxT(','));
ret << wxT(" --keyboard=\"");
if (m_bKbdLayoutOther) {
if (wxNOT_FOUND != kbdLocal.Find(wxT('/')))
ret << kbdLocal.BeforeFirst(wxT('/')) << wxT("/");
ret << m_sKbdLayoutLanguage;
} else {
if (kbdLocal.IsEmpty())
kbdLocal = wxT("query");
ret << kbdLocal;
}
ret << wxT("\"")
<< wxT(" --backingstore=\"") << (m_bDisableBackingstore ? 0 : 1) << wxT("\"")
<< wxT(" --encryption=\"") << (m_bEnableSSL ? 1 : 0) << wxT("\"");
if (bNew) {
ret << wxT(" --render=\"") << (m_bDisableRender ? 0 : 1) << wxT("\"");
}
ret << wxT(" --composite=\"") << (m_bDisableComposite ? 0 : 1) << wxT("\"")
<< wxT(" --shmem=\"") << (m_bDisableShmem ? 0 : 1) << wxT("\"")
<< wxT(" --shpix=\"") << (m_bDisableShpix ? 0 : 1) << wxT("\"");
// deprecated << wxT(" --streaming=\"") << (m_bDisableStreaming ? 0 : 1) << wxT("\"")
if (bNew) {
ret << wxT(" --samba=\"") << (m_bEnableSmbSharing ? 1 : 0) << wxT("\"")
<< wxT(" --cups=\"") << (m_bUseCups ? 1 : 0) << wxT("\"")
<< wxT(" --nodelay=\"") << (m_bDisableTcpNoDelay ? 0 : 1) << wxT("\"")
<< wxT(" --defer=\"") << (m_bDisableDeferredUpdates ? 1 : 0) << wxT("\"");
}
#ifdef __WXMAC__
ret << wxT(" --client=\"macosx\"");
#else
# ifdef __UNIX__
ret << wxT(" --client=\"linux\"");
# else
# ifdef __WXMSW__
ret << wxT(" --client=\"winnt\"");
# else
ret << wxT(" --client=\"linux\"");
# endif
# endif
#endif
ret << wxT(" --media=\"") << (m_bEnableMultimedia ? 1 : 0) << wxT("\"");
if (m_bEnableMultimedia) {
if (m_bEnableNativePA) {
ret << wxT(" --mediahelper=\"pa");
if (m_eRatePA != RATEPA_NORESAMPLE) {
switch (m_eRatePA) {
case RATEPA_48000:
ret << wxT("-48000"); break;
case RATEPA_44100:
ret << wxT("-44100"); break;
case RATEPA_32000:
ret << wxT("-32000"); break;
case RATEPA_16000:
ret << wxT("-16000"); break;
case RATEPA_8000:
ret << wxT("-8000"); break;
}
if (m_bEnableMonoPA)
ret << wxT("-1");
}
ret << wxT("\"");
} else
ret << wxT(" --mediahelper=\"esd\"");
}
// Original always uses those?!
ret << wxT(" --strict=\"0\"");
if (bNew) {
// With this parameter set, attaching to shadow sessions fails, if the server's display base is >= 10000
// so we simply leave it out for shadow sessions.
ret << wxT(" --aux=\"1\"");
}
return ret;
}
#ifdef __WXMSW__
wxString
MyXmlConfig::sGetXserverParams(bool forNXWin)
{
wxString ret;
int dspw, dsph, clientw, clienth;
getDesktopSize(dspw, dsph, clientw, clienth);
if (forNXWin) {
if ((m_eDesktopType == MyXmlConfig::DTYPE_CUSTOM) && !m_bVirtualDesktop)
ret << wxT(" -screen 0 640x480");
else
switch (m_eDisplayType) {
case MyXmlConfig::DPTYPE_640x480:
ret << wxT(" -screen 0 640x480");
break;
case MyXmlConfig::DPTYPE_1024x768:
ret << wxT(" -screen 0 1024x768");
break;
case MyXmlConfig::DPTYPE_1280x1024: