~freenx-team/nx-x11/nxcomp-upstream

« back to all changes in this revision

Viewing changes to Control.cpp

  • Committer: Marcelo Boveto Shima
  • Date: 2009-03-28 22:24:56 UTC
  • Revision ID: mshima@ufserv-20090328222456-rdtaq3oedfyq890c
Import nxcomp 3.3.0-3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**************************************************************************/
 
2
/*                                                                        */
 
3
/* Copyright (c) 2001, 2007 NoMachine, http://www.nomachine.com/.         */
 
4
/*                                                                        */
 
5
/* NXCOMP, NX protocol compression and NX extensions to this software     */
 
6
/* are copyright of NoMachine. Redistribution and use of the present      */
 
7
/* software is allowed according to terms specified in the file LICENSE   */
 
8
/* which comes in the source distribution.                                */
 
9
/*                                                                        */
 
10
/* Check http://www.nomachine.com/licensing.html for applicability.       */
 
11
/*                                                                        */
 
12
/* NX and NoMachine are trademarks of NoMachine S.r.l.                    */
 
13
/*                                                                        */
 
14
/* All rights reserved.                                                   */
 
15
/*                                                                        */
 
16
/**************************************************************************/
 
17
 
 
18
#include "NXpack.h"
 
19
 
 
20
#include "Control.h"
 
21
 
 
22
#define PANIC
 
23
#define WARNING
 
24
#undef  TEST
 
25
#undef  DEBUG
 
26
 
 
27
//
 
28
// Flush immediately on prioritized messages.
 
29
//
 
30
 
 
31
#define FLUSH_PRIORITY                           0
 
32
 
 
33
//
 
34
// Maximum number of bytes sent for each token.
 
35
//
 
36
 
 
37
#define TOKEN_SIZE                               1536
 
38
 
 
39
//
 
40
// Maximum number of tokens that can be spent
 
41
// by the client proxy before having to block
 
42
// waiting for a token reply.
 
43
//
 
44
 
 
45
#define TOKEN_LIMIT                              24
 
46
 
 
47
//
 
48
// By default assume the proxy is running as a
 
49
// standalone program.
 
50
//
 
51
 
 
52
#define LINK_ENCRYPTED                           0
 
53
 
 
54
//
 
55
// Maximum number of pids the proxy will record
 
56
// and kill at shutdown.
 
57
//
 
58
 
 
59
#define KILL_LIMIT                               16
 
60
 
 
61
//
 
62
// Allocate on the NX client side channels whose
 
63
// ids are a multiple of 8 (starting from 0). All
 
64
// the other ids can be used to allocate channels
 
65
// at the NX server side (X client side).
 
66
//
 
67
 
 
68
#define CHANNEL_MASK                             0x07
 
69
 
 
70
//
 
71
// Kill session if control parameters cannot be
 
72
// negotiated before this timeout.
 
73
//
 
74
 
 
75
#define INIT_TIMEOUT                             60000
 
76
 
 
77
//
 
78
// Enter the congestion state if the remote does
 
79
// not reply to a ping within the given amount
 
80
// of time.
 
81
//
 
82
 
 
83
#define PING_TIMEOUT                             5000
 
84
 
 
85
//
 
86
// Only send one motion event any N milliseconds.
 
87
//
 
88
 
 
89
#define MOTION_TIMEOUT                           0
 
90
 
 
91
 
 
92
//
 
93
// Force an update of the congestion counter if
 
94
// the proxy is idle for this time.
 
95
//
 
96
 
 
97
#define IDLE_TIMEOUT                             50
 
98
 
 
99
//
 
100
// Close X connection if can't write before this
 
101
// timeout.
 
102
//
 
103
 
 
104
#define CHANNEL_TIMEOUT                          10000
 
105
 
 
106
//
 
107
// Warn user (or close proxy connection) if don't
 
108
// receive any data before this timeout.
 
109
//
 
110
 
 
111
#define PROXY_TIMEOUT                            120000
 
112
 
 
113
//
 
114
// How many milliseconds to wait for the shared
 
115
// memory completion event to become available.
 
116
//
 
117
 
 
118
#define SHMEM_TIMEOUT                            200
 
119
//
 
120
// Before closing down the proxy, wait for the
 
121
// given amount of miliseconds to let all the
 
122
// running applications to close down their
 
123
// connections.
 
124
//
 
125
// A null timeout will cause the proxy to wait
 
126
// indefinitely, until the watchdog process is
 
127
// killed. This is usually the way the proxy is
 
128
// started by the NX server. If on the other
 
129
// hand a timeout is given and there no channel
 
130
// is remaining, the proxy will be closed down
 
131
// using a small timeout, presently of 500 ms.
 
132
//
 
133
 
 
134
#define CLEANUP_TIMEOUT                          3000
 
135
 
 
136
//
 
137
// Wait this amount of milliseconds after any
 
138
// iteration of the house-keeping process.
 
139
//
 
140
 
 
141
#define KEEPER_TIMEOUT                           60000
 
142
 
 
143
//
 
144
// In case of timeout, select can return control
 
145
// to program earlier or later of this amount of
 
146
// ms. Consider this when calculating if timeout
 
147
// is elapsed.
 
148
//
 
149
 
 
150
#define LATENCY_TIMEOUT                          1
 
151
 
 
152
//
 
153
// Control memory allocation in transport
 
154
// and other classes.
 
155
//
 
156
 
 
157
#define TRANSPORT_X_BUFFER_SIZE                  131072
 
158
#define TRANSPORT_PROXY_BUFFER_SIZE              65536
 
159
#define TRANSPORT_GENERIC_BUFFER_SIZE            16384
 
160
 
 
161
#define TRANSPORT_X_BUFFER_THRESHOLD             262144
 
162
#define TRANSPORT_PROXY_BUFFER_THRESHOLD         131072
 
163
#define TRANSPORT_GENERIC_BUFFER_THRESHOLD       32768
 
164
 
 
165
//
 
166
// Never allow buffers to exceed this limit.
 
167
//
 
168
 
 
169
#define TRANSPORT_MAXIMUM_BUFFER_SIZE            393216
 
170
 
 
171
//
 
172
// Immediately flush the accumulated data to
 
173
// the X server if the write buffer exceeds
 
174
// this size.
 
175
//
 
176
 
 
177
#define TRANSPORT_FLUSH_BUFFER_SIZE              16384
 
178
 
 
179
//
 
180
// Defaults used for socket options.
 
181
//
 
182
 
 
183
#define OPTION_PROXY_KEEP_ALIVE                  0
 
184
#define OPTION_PROXY_LOW_DELAY                   1
 
185
#define OPTION_PROXY_CLIENT_NO_DELAY             1
 
186
#define OPTION_PROXY_SERVER_NO_DELAY             1
 
187
#define OPTION_CLIENT_NO_DELAY                   1
 
188
#define OPTION_SERVER_NO_DELAY                   1
 
189
 
 
190
#define OPTION_PROXY_RECEIVE_BUFFER              -1
 
191
#define OPTION_CLIENT_RECEIVE_BUFFER             -1
 
192
#define OPTION_SERVER_RECEIVE_BUFFER             -1
 
193
 
 
194
#define OPTION_PROXY_SEND_BUFFER                 -1
 
195
#define OPTION_CLIENT_SEND_BUFFER                -1
 
196
#define OPTION_SERVER_SEND_BUFFER                -1
 
197
 
 
198
#define OPTION_PROXY_RETRY_CONNECT               30
 
199
#define OPTION_PROXY_RETRY_ACCEPT                3
 
200
#define OPTION_SERVER_RETRY_CONNECT              3
 
201
 
 
202
//
 
203
// Defaults used for cache persistence.
 
204
//
 
205
 
 
206
#define PERSISTENT_CACHE_THRESHOLD               102400
 
207
 
 
208
#define PERSISTENT_CACHE_ENABLE_LOAD             1
 
209
#define PERSISTENT_CACHE_ENABLE_SAVE             1
 
210
 
 
211
#define PERSISTENT_CACHE_CHECK_ON_SHUTDOWN       0
 
212
 
 
213
#define PERSISTENT_CACHE_LOAD_PACKED             1
 
214
#define PERSISTENT_CACHE_LOAD_RENDER             1
 
215
 
 
216
#define PERSISTENT_CACHE_DISK_LIMIT              33554432
 
217
 
 
218
//
 
219
// Defaults used for image cache.
 
220
//
 
221
 
 
222
#define IMAGE_CACHE_ENABLE_LOAD                  0
 
223
#define IMAGE_CACHE_ENABLE_SAVE                  0
 
224
 
 
225
#define IMAGE_CACHE_DISK_LIMIT                   33554432
 
226
 
 
227
//
 
228
// Suggested defaults for read length parameters
 
229
// used by read buffer classes.
 
230
//
 
231
 
 
232
#define CLIENT_INITIAL_READ_SIZE                 8192
 
233
#define CLIENT_MAXIMUM_BUFFER_SIZE               262144
 
234
 
 
235
#define SERVER_INITIAL_READ_SIZE                 8192
 
236
#define SERVER_MAXIMUM_BUFFER_SIZE               65536
 
237
 
 
238
#define PROXY_INITIAL_READ_SIZE                  65536
 
239
#define PROXY_MAXIMUM_BUFFER_SIZE                262144 + 1024
 
240
 
 
241
#define GENERIC_INITIAL_READ_SIZE                8192
 
242
#define GENERIC_MAXIMUM_BUFFER_SIZE              8192
 
243
 
 
244
//
 
245
// Calculate bitrate in given time frames.
 
246
// Values are in milliseconds.
 
247
//
 
248
 
 
249
#define SHORT_BITRATE_TIME_FRAME                 5000
 
250
#define LONG_BITRATE_TIME_FRAME                  30000
 
251
 
 
252
//
 
253
// Bandwidth control. A value of 0 means no
 
254
// limit. Values are stored internally in
 
255
// bytes per second.
 
256
//
 
257
 
 
258
#define CLIENT_BITRATE_LIMIT                     0
 
259
#define SERVER_BITRATE_LIMIT                     0
 
260
 
 
261
//
 
262
// Default values for cache control. We limit
 
263
// the maximum size of a request to 262144 but
 
264
// we need to consider the replies, whose size
 
265
// may be up to 4MB.
 
266
//
 
267
 
 
268
#define MINIMUM_MESSAGE_SIZE                     4
 
269
#define MAXIMUM_MESSAGE_SIZE                     4194304
 
270
#define MAXIMUM_REQUEST_SIZE                     262144
 
271
 
 
272
#define CLIENT_TOTAL_STORAGE_SIZE                8388608
 
273
#define SERVER_TOTAL_STORAGE_SIZE                8388608
 
274
 
 
275
#define STORE_TIME_LIMIT                         3600
 
276
 
 
277
#define STORE_HITS_LOAD_BONUS                    10
 
278
#define STORE_HITS_ADD_BONUS                     20
 
279
#define STORE_HITS_LIMIT                         100
 
280
 
 
281
#define STORE_HITS_TOUCH                         1
 
282
#define STORE_HITS_UNTOUCH                       2
 
283
 
 
284
//
 
285
// Default parameters for message splitting.
 
286
//
 
287
 
 
288
#define SPLIT_MODE                               1
 
289
#define SPLIT_TIMEOUT                            50
 
290
#define SPLIT_TOTAL_SIZE                         128
 
291
#define SPLIT_TOTAL_STORAGE_SIZE                 1048576
 
292
#define SPLIT_DATA_THRESHOLD                     65536
 
293
#define SPLIT_DATA_PACKET_LIMIT                  24576
 
294
 
 
295
//
 
296
// Agent related parameters.
 
297
//
 
298
 
 
299
#define PACK_METHOD                              63
 
300
#define PACK_QUALITY                             9
 
301
#define HIDE_RENDER                              0
 
302
#define TAINT_REPLIES                            1
 
303
#define TAINT_THRESHOLD                          8
 
304
 
 
305
//
 
306
// In current version only X server support is
 
307
// implemented. Note that use of shared memory
 
308
// is negotiated according to options provided
 
309
// by the user.
 
310
//
 
311
 
 
312
#define SHMEM_CLIENT                             0
 
313
#define SHMEM_SERVER                             1
 
314
 
 
315
//
 
316
// Default size of shared memory segments used
 
317
// in MIT-SHM support.
 
318
//
 
319
 
 
320
#define SHMEM_CLIENT_SIZE                        0
 
321
#define SHMEM_SERVER_SIZE                        2097152
 
322
 
 
323
//
 
324
// What do we do at the end of session? If this
 
325
// flag is set, we launch a new client letting
 
326
// the user run a new NX session.
 
327
//
 
328
 
 
329
#define ENABLE_RESTART_ON_SHUTDOWN               0
 
330
 
 
331
//
 
332
// Do we produce a core dump on fatal errors?
 
333
//
 
334
 
 
335
#define ENABLE_CORE_DUMP_ON_ABORT                0
 
336
 
 
337
//
 
338
// Reopen the log file if it exceeds this size.
 
339
//
 
340
 
 
341
#define FILE_SIZE_LIMIT                          60000000
 
342
 
 
343
//
 
344
// Check periodically if we need to truncate the
 
345
// log file. By default check every minute.
 
346
//
 
347
 
 
348
#define FILE_SIZE_CHECK_TIMEOUT                  60000
 
349
 
 
350
//
 
351
// Set defaults for control. They should be what
 
352
// you get in case of 'local' connection.
 
353
//
 
354
 
 
355
Control::Control()
 
356
{
 
357
  ProxyMode   = proxy_undefined;
 
358
  ProxyStage  = stage_undefined;
 
359
  SessionMode = session_undefined;
 
360
  FlushPolicy = policy_undefined;
 
361
  LinkMode    = link_undefined;
 
362
 
 
363
  LinkEncrypted = LINK_ENCRYPTED;
 
364
  FlushPriority = FLUSH_PRIORITY;
 
365
 
 
366
  TokenSize  = TOKEN_SIZE;
 
367
  TokenLimit = TOKEN_LIMIT;
 
368
 
 
369
  ChannelMask = CHANNEL_MASK;
 
370
 
 
371
  InitTimeout   = INIT_TIMEOUT;
 
372
  PingTimeout   = PING_TIMEOUT;
 
373
  MotionTimeout = MOTION_TIMEOUT;
 
374
  IdleTimeout   = IDLE_TIMEOUT;
 
375
 
 
376
  ChannelTimeout = CHANNEL_TIMEOUT;
 
377
  ProxyTimeout   = PROXY_TIMEOUT;
 
378
  ShmemTimeout   = SHMEM_TIMEOUT;
 
379
 
 
380
  CleanupTimeout  = CLEANUP_TIMEOUT;
 
381
  KeeperTimeout   = KEEPER_TIMEOUT;
 
382
  LatencyTimeout  = LATENCY_TIMEOUT;
 
383
 
 
384
  FileSizeLimit        = FILE_SIZE_LIMIT;
 
385
  FileSizeCheckTimeout = FILE_SIZE_CHECK_TIMEOUT;
 
386
 
 
387
  EnableRestartOnShutdown = ENABLE_RESTART_ON_SHUTDOWN;
 
388
 
 
389
  KillDaemonOnShutdownLimit = KILL_LIMIT;
 
390
 
 
391
  KillDaemonOnShutdown = new int[KillDaemonOnShutdownLimit];
 
392
 
 
393
  for (int i = 0; i < KILL_LIMIT; i++)
 
394
  {
 
395
    KillDaemonOnShutdown[i] = -1;
 
396
  }
 
397
 
 
398
  KillDaemonOnShutdownNumber = 0;
 
399
 
 
400
  EnableCoreDumpOnAbort = ENABLE_CORE_DUMP_ON_ABORT;
 
401
 
 
402
  //
 
403
  // Collect statistics by default.
 
404
  //
 
405
 
 
406
  EnableStatistics = 1;
 
407
 
 
408
  //
 
409
  // Memory restrictions if any.
 
410
  //
 
411
 
 
412
  LocalMemoryLevel = -1;
 
413
 
 
414
  //
 
415
  // Compression must be negotiated between proxies.
 
416
  //
 
417
 
 
418
  LocalDeltaCompression   = -1;
 
419
  RemoteDeltaCompression  = -1;
 
420
 
 
421
  LocalDataCompression    = -1;
 
422
  LocalStreamCompression  = -1;
 
423
 
 
424
  RemoteDataCompression   = -1;
 
425
  RemoteStreamCompression = -1;
 
426
 
 
427
  LocalDataCompressionLevel     = -1;
 
428
  LocalDataCompressionThreshold = -1;
 
429
  LocalStreamCompressionLevel   = -1;
 
430
 
 
431
  RemoteDataCompressionLevel    = -1;
 
432
  RemoteStreamCompressionLevel  = -1;
 
433
 
 
434
  //
 
435
  // Transport buffers' allocation parameters.
 
436
  // 
 
437
 
 
438
  TransportXBufferSize            = TRANSPORT_X_BUFFER_SIZE;
 
439
  TransportProxyBufferSize        = TRANSPORT_PROXY_BUFFER_SIZE;
 
440
  TransportGenericBufferSize      = TRANSPORT_GENERIC_BUFFER_SIZE;
 
441
 
 
442
  TransportXBufferThreshold       = TRANSPORT_X_BUFFER_THRESHOLD;
 
443
  TransportProxyBufferThreshold   = TRANSPORT_PROXY_BUFFER_THRESHOLD;
 
444
  TransportGenericBufferThreshold = TRANSPORT_GENERIC_BUFFER_THRESHOLD;
 
445
 
 
446
  TransportMaximumBufferSize      = TRANSPORT_MAXIMUM_BUFFER_SIZE;
 
447
 
 
448
  //
 
449
  // Flush the write buffer if it exceeds
 
450
  // this size.
 
451
  //
 
452
 
 
453
  TransportFlushBufferSize = TRANSPORT_FLUSH_BUFFER_SIZE;
 
454
 
 
455
  //
 
456
  // Socket options.
 
457
  //
 
458
 
 
459
  OptionProxyKeepAlive      = OPTION_PROXY_KEEP_ALIVE;
 
460
  OptionProxyLowDelay       = OPTION_PROXY_LOW_DELAY;
 
461
  OptionProxyClientNoDelay  = OPTION_PROXY_CLIENT_NO_DELAY;
 
462
  OptionProxyServerNoDelay  = OPTION_PROXY_SERVER_NO_DELAY;
 
463
  OptionClientNoDelay       = OPTION_CLIENT_NO_DELAY;
 
464
  OptionServerNoDelay       = OPTION_SERVER_NO_DELAY;
 
465
 
 
466
  OptionProxyReceiveBuffer  = OPTION_PROXY_RECEIVE_BUFFER;
 
467
  OptionClientReceiveBuffer = OPTION_CLIENT_RECEIVE_BUFFER;
 
468
  OptionServerReceiveBuffer = OPTION_SERVER_RECEIVE_BUFFER;
 
469
 
 
470
  OptionProxySendBuffer     = OPTION_PROXY_SEND_BUFFER;
 
471
  OptionClientSendBuffer    = OPTION_CLIENT_SEND_BUFFER;
 
472
  OptionServerSendBuffer    = OPTION_SERVER_SEND_BUFFER;
 
473
 
 
474
  OptionProxyRetryAccept    = OPTION_PROXY_RETRY_ACCEPT;
 
475
  OptionProxyRetryConnect   = OPTION_PROXY_RETRY_CONNECT;
 
476
  OptionServerRetryConnect  = OPTION_SERVER_RETRY_CONNECT;
 
477
 
 
478
  //
 
479
  // Base NX directories.
 
480
  //
 
481
 
 
482
  HomePath   = NULL;
 
483
  RootPath   = NULL;
 
484
  SystemPath = NULL;
 
485
  TempPath   = NULL;
 
486
  ClientPath = NULL;
 
487
 
 
488
  //
 
489
  // Set defaults for handling persistent cache.
 
490
  //
 
491
 
 
492
  PersistentCachePath = NULL;
 
493
  PersistentCacheName = NULL;
 
494
 
 
495
  PersistentCacheThreshold = PERSISTENT_CACHE_THRESHOLD;
 
496
 
 
497
  PersistentCacheEnableLoad = PERSISTENT_CACHE_ENABLE_LOAD;
 
498
  PersistentCacheEnableSave = PERSISTENT_CACHE_ENABLE_SAVE;
 
499
 
 
500
  PersistentCacheCheckOnShutdown = PERSISTENT_CACHE_CHECK_ON_SHUTDOWN;
 
501
 
 
502
  PersistentCacheLoadPacked = PERSISTENT_CACHE_LOAD_PACKED;
 
503
  PersistentCacheLoadRender = PERSISTENT_CACHE_LOAD_RENDER;
 
504
 
 
505
  PersistentCacheDiskLimit = PERSISTENT_CACHE_DISK_LIMIT;
 
506
 
 
507
  //
 
508
  // Set defaults for image cache.
 
509
  //
 
510
 
 
511
  ImageCachePath = NULL;
 
512
 
 
513
  ImageCacheEnableLoad = IMAGE_CACHE_ENABLE_LOAD;
 
514
  ImageCacheEnableSave = IMAGE_CACHE_ENABLE_SAVE;
 
515
 
 
516
  ImageCacheDiskLimit = IMAGE_CACHE_DISK_LIMIT;
 
517
 
 
518
  //
 
519
  // Set defaults for the read buffers.
 
520
  //
 
521
 
 
522
  ClientInitialReadSize    = CLIENT_INITIAL_READ_SIZE;
 
523
  ClientMaximumBufferSize  = CLIENT_MAXIMUM_BUFFER_SIZE;
 
524
 
 
525
  ServerInitialReadSize    = SERVER_INITIAL_READ_SIZE;
 
526
  ServerMaximumBufferSize  = SERVER_MAXIMUM_BUFFER_SIZE;
 
527
 
 
528
  ProxyInitialReadSize     = PROXY_INITIAL_READ_SIZE;
 
529
  ProxyMaximumBufferSize   = PROXY_MAXIMUM_BUFFER_SIZE;
 
530
 
 
531
  GenericInitialReadSize   = GENERIC_INITIAL_READ_SIZE;
 
532
  GenericMaximumBufferSize = GENERIC_MAXIMUM_BUFFER_SIZE;
 
533
 
 
534
  ShortBitrateTimeFrame = SHORT_BITRATE_TIME_FRAME;
 
535
  LongBitrateTimeFrame  = LONG_BITRATE_TIME_FRAME;
 
536
 
 
537
  //
 
538
  // Bandwidth control.
 
539
  //
 
540
 
 
541
  LocalBitrateLimit   = -1;
 
542
 
 
543
  ClientBitrateLimit = CLIENT_BITRATE_LIMIT;
 
544
  ServerBitrateLimit = SERVER_BITRATE_LIMIT;
 
545
 
 
546
  //
 
547
  // Default parameters for message handling.
 
548
  //
 
549
 
 
550
  ClientTotalStorageSize = CLIENT_TOTAL_STORAGE_SIZE;
 
551
  ServerTotalStorageSize = SERVER_TOTAL_STORAGE_SIZE;
 
552
 
 
553
  LocalTotalStorageSize  = -1;
 
554
  RemoteTotalStorageSize = -1;
 
555
 
 
556
  StoreTimeLimit = STORE_TIME_LIMIT;
 
557
 
 
558
  StoreHitsLoadBonus = STORE_HITS_LOAD_BONUS;
 
559
  StoreHitsAddBonus  = STORE_HITS_ADD_BONUS;
 
560
  StoreHitsLimit     = STORE_HITS_LIMIT;
 
561
 
 
562
  StoreHitsTouch   = STORE_HITS_TOUCH;
 
563
  StoreHitsUntouch = STORE_HITS_UNTOUCH;
 
564
 
 
565
  MinimumMessageSize = MINIMUM_MESSAGE_SIZE;
 
566
  MaximumMessageSize = MAXIMUM_MESSAGE_SIZE;
 
567
  MaximumRequestSize = MAXIMUM_REQUEST_SIZE;
 
568
 
 
569
  SplitMode             = SPLIT_MODE;
 
570
  SplitTimeout          = SPLIT_TIMEOUT;
 
571
  SplitTotalSize        = SPLIT_TOTAL_SIZE;
 
572
  SplitTotalStorageSize = SPLIT_TOTAL_STORAGE_SIZE;
 
573
  SplitDataThreshold    = SPLIT_DATA_THRESHOLD;
 
574
  SplitDataPacketLimit  = SPLIT_DATA_PACKET_LIMIT;
 
575
 
 
576
  PackMethod     = PACK_METHOD;
 
577
  PackQuality    = PACK_QUALITY;
 
578
  HideRender     = HIDE_RENDER;
 
579
  TaintReplies   = TAINT_REPLIES;
 
580
  TaintThreshold = TAINT_THRESHOLD;
 
581
 
 
582
  ShmemClient = SHMEM_CLIENT;
 
583
  ShmemServer = SHMEM_SERVER;
 
584
 
 
585
  ShmemClientSize = SHMEM_CLIENT_SIZE;
 
586
  ShmemServerSize = SHMEM_SERVER_SIZE;
 
587
 
 
588
  //
 
589
  // Get local version number from compile time
 
590
  // settings. Version of remote proxy will be
 
591
  // checked at connection time.
 
592
  //
 
593
 
 
594
  RemoteVersionMajor = -1;
 
595
  RemoteVersionMinor = -1;
 
596
  RemoteVersionPatch = -1;
 
597
 
 
598
  CompatVersionMajor = -1;
 
599
  CompatVersionMinor = -1;
 
600
  CompatVersionPatch = -1;
 
601
 
 
602
  char version[32];
 
603
 
 
604
  strcpy(version, VERSION);
 
605
 
 
606
  char *value;
 
607
 
 
608
  value = strtok(version, ".");
 
609
 
 
610
  for (int i = 0; value != NULL && i < 3; i++)
 
611
  {
 
612
    switch (i)
 
613
    {
 
614
      case 0:
 
615
 
 
616
        LocalVersionMajor = atoi(value);
 
617
 
 
618
        break;
 
619
 
 
620
      case 1:
 
621
 
 
622
        LocalVersionMinor = atoi(value);
 
623
 
 
624
        break;
 
625
 
 
626
      case 2:
 
627
 
 
628
        LocalVersionPatch = atoi(value);
 
629
 
 
630
        break;
 
631
    }
 
632
 
 
633
    value = strtok(NULL, ".");
 
634
  }
 
635
 
 
636
  #ifdef TEST
 
637
  *logofs << "Control: Major version is " << LocalVersionMajor
 
638
          << " minor is " << LocalVersionMinor << " patch is "
 
639
          << LocalVersionPatch << ".\n" << logofs_flush;
 
640
  #endif
 
641
 
 
642
  //
 
643
  // Initialize local implemented methods later
 
644
  // and negotiate remote methods at connection
 
645
  // time.
 
646
  //
 
647
 
 
648
  LocalUnpackMethods  = NULL;
 
649
  RemoteUnpackMethods = NULL;
 
650
 
 
651
  //
 
652
  // Set to 1 those methods which are implemented.
 
653
  //
 
654
 
 
655
  setLocalUnpackMethods();
 
656
 
 
657
  //
 
658
  // Set the protocol version at the
 
659
  // time the session is negotiated.
 
660
  //
 
661
 
 
662
  protoStep6_  = 0;
 
663
  protoStep7_  = 0;
 
664
  protoStep8_  = 0;
 
665
  protoStep9_  = 0;
 
666
  protoStep10_ = 0;
 
667
}
 
668
 
 
669
Control::~Control()
 
670
{
 
671
  if (KillDaemonOnShutdown != NULL)
 
672
  {
 
673
    delete [] KillDaemonOnShutdown;
 
674
  }
 
675
 
 
676
  if (HomePath != NULL)
 
677
  {
 
678
    delete [] HomePath;
 
679
  }
 
680
 
 
681
  if (RootPath != NULL)
 
682
  {
 
683
    delete [] RootPath;
 
684
  }
 
685
 
 
686
  if (SystemPath != NULL)
 
687
  {
 
688
    delete [] SystemPath;
 
689
  }
 
690
 
 
691
  if (TempPath != NULL)
 
692
  {
 
693
    delete [] TempPath;
 
694
  }
 
695
 
 
696
  if (ClientPath != NULL)
 
697
  {
 
698
    delete [] ClientPath;
 
699
  }
 
700
 
 
701
  if (PersistentCachePath != NULL)
 
702
  {
 
703
    delete [] PersistentCachePath;
 
704
  }
 
705
 
 
706
  if (PersistentCacheName != NULL)
 
707
  {
 
708
    delete [] PersistentCacheName;
 
709
  }
 
710
 
 
711
  if (LocalUnpackMethods != NULL)
 
712
  {
 
713
    delete [] LocalUnpackMethods;
 
714
  }
 
715
 
 
716
  if (RemoteUnpackMethods != NULL)
 
717
  {
 
718
    delete [] RemoteUnpackMethods;
 
719
  }
 
720
 
 
721
  if (ImageCachePath != NULL)
 
722
  {
 
723
    delete [] ImageCachePath;
 
724
  }
 
725
}
 
726
 
 
727
//
 
728
// Set the protocol step based on the
 
729
// remote version.
 
730
//
 
731
 
 
732
void Control::setProtoStep(int step)
 
733
{
 
734
  switch (step)
 
735
  {
 
736
    case 6:
 
737
    {
 
738
      protoStep6_  = 1;
 
739
      protoStep7_  = 0;
 
740
      protoStep8_  = 0;
 
741
      protoStep9_  = 0;
 
742
      protoStep10_ = 0;
 
743
 
 
744
      break;
 
745
    }
 
746
    case 7:
 
747
    {
 
748
      protoStep6_  = 1;
 
749
      protoStep7_  = 1;
 
750
      protoStep8_  = 0;
 
751
      protoStep9_  = 0;
 
752
      protoStep10_ = 0;
 
753
 
 
754
      break;
 
755
    }
 
756
    case 8:
 
757
    {
 
758
      protoStep6_  = 1;
 
759
      protoStep7_  = 1;
 
760
      protoStep8_  = 1;
 
761
      protoStep9_  = 0;
 
762
      protoStep10_ = 0;
 
763
 
 
764
      break;
 
765
    }
 
766
    case 9:
 
767
    {
 
768
      protoStep6_  = 1;
 
769
      protoStep7_  = 1;
 
770
      protoStep8_  = 1;
 
771
      protoStep9_  = 1;
 
772
      protoStep10_ = 0;
 
773
 
 
774
      break;
 
775
    }
 
776
    case 10:
 
777
    {
 
778
      protoStep6_  = 1;
 
779
      protoStep7_  = 1;
 
780
      protoStep8_  = 1;
 
781
      protoStep9_  = 1;
 
782
      protoStep10_ = 1;
 
783
 
 
784
      break;
 
785
    }
 
786
    default:
 
787
    {
 
788
      #ifdef PANIC
 
789
      *logofs << "Control: PANIC! Invalid protocol step "
 
790
              << "with value " << step << ".\n"
 
791
              << logofs_flush;
 
792
      #endif
 
793
 
 
794
      HandleCleanup();
 
795
    }
 
796
  }
 
797
}
 
798
 
 
799
int Control::getProtoStep()
 
800
{
 
801
  if (protoStep10_ == 1)
 
802
  {
 
803
    return 10;
 
804
  }
 
805
  else if (protoStep9_ == 1)
 
806
  {
 
807
    return 9;
 
808
  }
 
809
  else if (protoStep8_ == 1)
 
810
  {
 
811
    return 8;
 
812
  }
 
813
  else if (protoStep7_ == 1)
 
814
  {
 
815
    return 7;
 
816
  }
 
817
  else if (protoStep6_ == 1)
 
818
  {
 
819
    return 6;
 
820
  }
 
821
  else
 
822
  {
 
823
    #ifdef PANIC
 
824
    *logofs << "Control: PANIC! Can't identify the "
 
825
            << "protocol step.\n" << logofs_flush;
 
826
    #endif
 
827
 
 
828
    HandleCleanup();
 
829
  }
 
830
}
 
831
 
 
832
//
 
833
// Set here the pack/unpack methods that are
 
834
// implemented by this NX proxy.
 
835
//
 
836
 
 
837
void Control::setLocalUnpackMethods()
 
838
{
 
839
  LocalUnpackMethods  = new unsigned char[PACK_METHOD_LIMIT];
 
840
  RemoteUnpackMethods = new unsigned char[PACK_METHOD_LIMIT];
 
841
 
 
842
  for (int i = 0; i < PACK_METHOD_LIMIT; i++)
 
843
  {
 
844
    LocalUnpackMethods[i]  = 0;
 
845
    RemoteUnpackMethods[i] = 0;
 
846
  }
 
847
 
 
848
  LocalUnpackMethods[NO_PACK]                         = 1;
 
849
 
 
850
  LocalUnpackMethods[PACK_MASKED_8_COLORS]            = 1;
 
851
  LocalUnpackMethods[PACK_MASKED_64_COLORS]           = 1;
 
852
  LocalUnpackMethods[PACK_MASKED_256_COLORS]          = 1;
 
853
  LocalUnpackMethods[PACK_MASKED_512_COLORS]          = 1;
 
854
  LocalUnpackMethods[PACK_MASKED_4K_COLORS]           = 1;
 
855
  LocalUnpackMethods[PACK_MASKED_32K_COLORS]          = 1;
 
856
  LocalUnpackMethods[PACK_MASKED_64K_COLORS]          = 1;
 
857
  LocalUnpackMethods[PACK_MASKED_256K_COLORS]         = 1;
 
858
  LocalUnpackMethods[PACK_MASKED_2M_COLORS]           = 1;
 
859
  LocalUnpackMethods[PACK_MASKED_16M_COLORS]          = 1;
 
860
 
 
861
  LocalUnpackMethods[PACK_RAW_8_BITS]                 = 1;
 
862
  LocalUnpackMethods[PACK_RAW_16_BITS]                = 1;
 
863
  LocalUnpackMethods[PACK_RAW_24_BITS]                = 1;
 
864
 
 
865
  LocalUnpackMethods[PACK_COLORMAP_256_COLORS]        = 1;
 
866
 
 
867
  LocalUnpackMethods[PACK_JPEG_8_COLORS]              = 1;
 
868
  LocalUnpackMethods[PACK_JPEG_64_COLORS]             = 1;
 
869
  LocalUnpackMethods[PACK_JPEG_256_COLORS]            = 1;
 
870
  LocalUnpackMethods[PACK_JPEG_512_COLORS]            = 1;
 
871
  LocalUnpackMethods[PACK_JPEG_4K_COLORS]             = 1;
 
872
  LocalUnpackMethods[PACK_JPEG_32K_COLORS]            = 1;
 
873
  LocalUnpackMethods[PACK_JPEG_64K_COLORS]            = 1;
 
874
  LocalUnpackMethods[PACK_JPEG_256K_COLORS]           = 1;
 
875
  LocalUnpackMethods[PACK_JPEG_2M_COLORS]             = 1;
 
876
  LocalUnpackMethods[PACK_JPEG_16M_COLORS]            = 1;
 
877
 
 
878
  LocalUnpackMethods[PACK_PNG_8_COLORS]               = 1;
 
879
  LocalUnpackMethods[PACK_PNG_64_COLORS]              = 1;
 
880
  LocalUnpackMethods[PACK_PNG_256_COLORS]             = 1;
 
881
  LocalUnpackMethods[PACK_PNG_512_COLORS]             = 1;
 
882
  LocalUnpackMethods[PACK_PNG_4K_COLORS]              = 1;
 
883
  LocalUnpackMethods[PACK_PNG_32K_COLORS]             = 1;
 
884
  LocalUnpackMethods[PACK_PNG_64K_COLORS]             = 1;
 
885
  LocalUnpackMethods[PACK_PNG_256K_COLORS]            = 1;
 
886
  LocalUnpackMethods[PACK_PNG_2M_COLORS]              = 1;
 
887
  LocalUnpackMethods[PACK_PNG_16M_COLORS]             = 1;
 
888
 
 
889
  LocalUnpackMethods[PACK_RGB_16M_COLORS]             = 1;
 
890
  LocalUnpackMethods[PACK_RLE_16M_COLORS]             = 1;
 
891
 
 
892
  LocalUnpackMethods[PACK_ALPHA]                      = 1;
 
893
  LocalUnpackMethods[PACK_COLORMAP]                   = 1;
 
894
 
 
895
  LocalUnpackMethods[PACK_BITMAP_16M_COLORS]          = 1;
 
896
}