forked from ArcticaProject/nx-libs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMisc.cpp
1893 lines (1734 loc) · 40.6 KB
/
Misc.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
/**************************************************************************/
/* */
/* Copyright (c) 2001, 2010 NoMachine, http://www.nomachine.com/. */
/* */
/* NXCOMP, NX protocol compression and NX extensions to this software */
/* are copyright of NoMachine. Redistribution and use of the present */
/* software is allowed according to terms specified in the file LICENSE */
/* which comes in the source distribution. */
/* */
/* Check http://www.nomachine.com/licensing.html for applicability. */
/* */
/* NX and NoMachine are trademarks of Medialogic S.p.A. */
/* */
/* All rights reserved. */
/* */
/**************************************************************************/
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <errno.h>
#include <string.h>
#include "NXproto.h"
#include "MD5.h"
#include "Misc.h"
#include "Proxy.h"
//
// Set the verbosity level.
//
#define PANIC
#define WARNING
#define OPCODES
#undef TEST
#undef DEBUG
//
// TCP port offset applied to any NX port specification.
//
const int DEFAULT_NX_PROXY_PORT_OFFSET = 4000;
//
// Default TCP port used by client proxy to listen to
// X clients and by server proxy to connect to remote.
//
const int DEFAULT_NX_PROXY_PORT = 8;
//
// Default X display number that client proxy imitates.
//
const int DEFAULT_NX_X_PORT = 8;
//
// Default ports used for listening for cups, samba, http,
// multimedia and auxiliary X connections. Arbitrary ports
// can be used by passing the service's port at the proxy
// startup. By default ports are determined by adding the
// offset below to the offset of the proxied display. For
// example, if the proxy is impersonating the display :8,
// SMB tunnels can be created by connecting to port 3008.
//
// Considering that the NX server uses to start the first
// session at display offset 1000, we must lower the CUPS
// and SMB ports to avoid interference with normal X ses-
// sions run on the server.
//
// Font server connections are used to let the X server on
// the client connect to a font server on the NX server.
//
// Slave channels can be originated by both sides so we need
// different offsets in the case the user runs both proxies
// on the same host.
//
const int DEFAULT_NX_CUPS_PORT_OFFSET = 2000;
const int DEFAULT_NX_SMB_PORT_OFFSET = 3000;
const int DEFAULT_NX_MEDIA_PORT_OFFSET = 7000;
const int DEFAULT_NX_AUX_PORT_OFFSET = 8000;
const int DEFAULT_NX_HTTP_PORT_OFFSET = 9000;
const int DEFAULT_NX_FONT_PORT_OFFSET = 10000;
const int DEFAULT_NX_SLAVE_PORT_CLIENT_OFFSET = 11000;
const int DEFAULT_NX_SLAVE_PORT_SERVER_OFFSET = 12000;
//
// Usage info and copyright.
//
static const char UsageInfo[] =
"\n\
Usage: nxproxy [OPTIONS] host:port\n\
\n\
-C Specify that nxproxy has to run on the 'X client'\n\
side, listening for connections and impersonating\n\
an X server.\n\
\n\
-S Specify that nxproxy has to run in 'X server' mode,\n\
thus forwarding the connections to daemons running\n\
on the client.\n\
\n\
-h Print this message.\n\
\n\
-v Print version information.\n\
\n\
host:port Put at the end, specifies the host and port of the\n\
listening proxy.\n\
\n\
name=value Set the NX option to the provided value.\n\
\n\
Multiple NX options can be specified in the DISPLAY environment\n\
or on the command line, by using the nx/nx,option=value notation.\n\
\n\
Options:\n\
\n\
link=s An indication of the link speed that is going to be\n\
used between the proxies. Usually the compression\n\
and the other link parameters depend on this setting.\n\
The value can be either 'modem', 'isdn', 'adsl',\n\
'wan', 'lan', 'local' or a bandwidth specification,\n\
like for example '56k', '1m', '100m', etc.\n\
\n\
type=s Type of session, for example 'windows', 'unix-kde'.\n\
'unix-application', etc.\n\
\n\
display=s Specify the real display where X connections have\n\
to be forwarded by the proxy running on the client.\n\
\n\
listen=n Local port used for accepting the proxy connection.\n\
\n\
accept=s Name or IP of host that can connect to the proxy.\n\
\n\
connect=s Name or IP of host that the proxy will connect to.\n\
\n\
port=n Remote port used for the connection.\n\
\n\
retry=n Number of connection atempts.\n\
\n\
root=s The root directory for the session. Usually is the\n\
C-* or S-* in the .nx directory in the user's home,\n\
with '*' being the virtual display.\n\
\n\
session=s Name of the session file. The default is the name\n\
'session' in the session directory.\n\
\n\
errors=s Name of the log file used by the proxy. The default\n\
is the name 'errors' in the session directory.\n\
\n\
stats=s Name of the file where are written the proxy stat-\n\
istics. The default is a file 'stats' in the session\n\
directory. The proxy replaces the data in the file\n\
whenever it receives a SIGUSR1 or SIGUSR2 signal:\n\
\n\
SIGUSR1 Gives total statistics, i.e. statistics\n\
collected since the beginning of the\n\
session.\n\
\n\
SIGUSR2 Gives partial statistics, i.e. statist-\n\
ics collected since the last time this\n\
signal was received.\n\
\n\
cookie=s Use the provided cookie for authenticating to the\n\
remote proxy. The same cookie is used as the fake\n\
value used for the X authorization. The fake cookie\n\
is replaced on the X server side with the real cookie\n\
to be used for the display, so that the real cookie\n\
doesn't have to travel over the net. When not using\n\
a proxy cookie, any host will be able to connect to\n\
the proxy. See also the 'accept' parameter.\n\
\n\
nodelay=b A boolean indicating if TCP_NODELAY has to be set\n\
on the proxy link. Old Linux kernels had problems\n\
with handling TCP_NODELAY on PPP links.\n\
\n\
policy=b Let or not the agent decide when it is the best time\n\
to flush the proxy link. If set to 0, the proxy will\n\
flush any encoded data immediately. The option has\n\
only effect on the X client side proxy.\n\
\n\
render=b Enable or disable use of the RENDER extension.\n\
\n\
taint=b Try to suppress trivial sources of X roundtrips by\n\
generating the reply on the X client side.\n\
\n\
delta=b Enable X differential compression.\n\
\n\
data=n Enable or disable the ZLIB data compression. It is\n\
possible to specify a value between 0 and 9. Usual-\n\
ly the value is chosen automatically based on the\n\
requested link setting.\n\
\n\
stream=n Enable or disable the ZLIB stream compression. The\n\
value, between 0 and 9, is usually determined accor-\n\
ding to the requested link setting.\n\
\n\
limit=n Specify a bitrate limit allowed for this session.\n\
\n\
memory=n Trigger memory optimizations used to keep small the\n\
size of X buffers. This is useful on embedded plat-\n\
forms, or where memory is scarce.\n\
\n\
cache=n Size of the in-memory X message cache. Setting the\n\
value to 0 will disable the memory cache as well\n\
as the NX differential compression.\n\
\n\
images=n Size of the persistent image cache.\n\
\n\
shseg=n Enable the use of the MIT-SHM extension between the\n\
NX client proxy and the real X server. A value greater\n\
than 1 is assumed to be the size of requested shared\n\
memory segment. By default, the size of the segment is\n\
determined based on the size of the in-memory cache.\n\
\n\
load=b Enable loading a persistent X message cache at the\n\
proxy startup.\n\
\n\
save=b Enable saving a persistent X message cache at the\n\
end of session.\n\
\n\
cups=n Enable or disable forwarding of CUPS connections,\n\
by listening on the optional port 'n'.\n\
\n\
aux=n Enable or disable forwarding of the auxiliary X chan-\n\
nel used for controlling the keyboard. The 'keybd=n'\n\
form is accepted for backward compatibility.\n\
\n\
smb=n Enable or disable forwarding of SMB connections. The\n\
'samba=n' form is accepted for backward compatibility.\n\
\n\
media=n Enable forwarding of audio connections.\n\
\n\
http=n Enable forwarding of HTTP connections.\n\
\n\
font=n Enable forwarding of reversed connections to a font\n\
server running on the NX server.\n\
\n\
file=n Enable forwarding of file transfer connections.\n\
\n\
mask=n Determine the distribution of channel ids between the\n\
proxies. By default, channels whose ids are multiple\n\
of 8 (starting from 0) are reserved for the NX client\n\
side. All the other channels can be allocated by the\n\
NX server side.\n\
\n\
timeout=t Specify the keep-alive timeout used by proxies to\n\
determine if there is a network problem preventing\n\
communication with the remote peer. A value of 0\n\
disables the check.\n\
\n\
cleanup=t Specify the number of seconds the proxy has to wait\n\
at session shutdown before closing all channels.\n\
The feature is used by the NX server to ensure that\n\
services are disconnected before shutting down the\n\
link.\n\
\n\
pack=s Determine the method used to compress images.\n\
\n\
product=s The product id of the client or server. The value is\n\
ignored by the proxy, but the client or server can\n\
provide it to facilitate the support.\n\
\n\
core=b Enable production of core dumps when aborting the\n\
proxy connection.\n\
\n\
options=s Specify an additional file containing options that\n\
has to be merged with option read from the command\n\
line or the environment.\n\
\n\
kill=n Add the given process to the list of daemons that\n\
must be terminated at session shutdown. Multiple\n\
'kill=n' options can be specified. The proxy will\n\
send them a SIGTERM signal just before exiting.\n\
\n\
strict=b Optimize for responsiveness, rather than for the best\n\
use of all the available bandwidth.\n\
\n\
encryption=b Should be set to 1 if the proxy is running as part of\n\
a program providing encryption of the point to point\n\
communication.\n\
\n\
rootless=b\n\
geometry=s\n\
resize=b\n\
fullscreen=b\n\
keyboard=s\n\
clipboard=n\n\
streaming=n\n\
backingstore=n\n\
composite=n\n\
shmem=b\n\
shpix=b\n\
kbtype=s\n\
client=s\n\
shadow=n\n\
shadowuid=n\n\
shadowmode=s\n\
defer=n\n\
tile=s\n\
menu=n These options are interpreted by the NX agent. They\n\
are ignored by the proxy.\n\
\n\
Environment:\n\
\n\
NX_ROOT The root NX directory is the place where the session\n\
directory and the cache files are created. This is\n\
usually overridden by passing the 'root=' option. By\n\
default, the root NX directory is assumed to be the\n\
directory '.nx' in the user's home.\n\
\n\
NX_SYSTEM The directory where NX programs and libraries reside.\n\
If not set, the value is assumed to be '/usr/NX'.\n\
Programs, libraries and data files are respectedly\n\
searched in the 'bin', 'lib' and 'share' subdirecto-\n\
ries.\n\
\n\
NX_HOME The NX user's home directory. If NX_ROOT is not set\n\
or invalid, the user's NX directory is created here.\n\
\n\
NX_TEMP The directory where the X11 Unix Domain Sockets and\n\
all temporary files are to be created.\n\
\n\
NX_CLIENT The full path to the nxclient executable. If the va-\n\
riable is not set, the nxclient executable will be\n\
run assuming that the program is in the system path.\n\
This can be useful on platforms like Windows and the\n\
Mac where nxclient is located in a different direct-\n\
ory compared to the other programs, to make easier\n\
for the user to execute the program from the shell.\n\
\n\
Shell environment:\n\
\n\
HOME The variable is checked in the case NX_HOME is not\n\
set, null or invalid.\n\
\n\
TEMP The variable is checked whenever the NX_TEMP direct-\n\
ory is not set, null or invalid.\n\
\n\
PATH The path where all executables are searched, except\n\
nxclient. If NX_CLIENT is not set, also the client\n\
executable is searched in the system path.\n\
\n\
LD_LIBRARY_PATH\n\
System-wide library search order. This should be set\n\
by the program invoking the proxy.\n\
\n\
DISPLAY On the X server side, the DISPLAY variable indicates\n\
the location of the X11 server. When nxcomp is used\n\
as a transport library, the DISPLAY may represent a\n\
NX transport specification and options can passed in\n\
the form nx/nx,option=value...\n\
\n\
XAUTHORITY This is the file containing the X11 authorization\n\
cookie. If not set, the file is assumed to be in\n\
the user's home (either NX_HOME or HOME).\n\
\n\
";
const char *GetUsageInfo()
{
return UsageInfo;
}
static const char CopyrightInfo[] =
"\
Copyright (c) 2001, 2010 NoMachine, http://www.nomachine.com/.\n\
\n\
NXCOMP, NX protocol compression and NX extensions to this software \n\
are copyright of NoMachine. Redistribution and use of the present\n\
software is allowed according to terms specified in the file LICENSE\n\
which comes in the source distribution.\n\
\n\
Check http://www.nomachine.com/licensing.html for applicability.\n\
\n\
NX and NoMachine are trademarks of NoMachine S.r.l.\n\
\n\
All rights reserved.\n\
";
const char *GetCopyrightInfo()
{
return CopyrightInfo;
}
static const char OtherCopyrightInfo[] =
"\
NX protocol compression is derived from DXPC project.\n\
\n\
Copyright (c) 1995,1996 Brian Pane\n\
Copyright (c) 1996,1997 Zachary Vonler and Brian Pane\n\
Copyright (c) 1999 Kevin Vigor and Brian Pane\n\
Copyright (c) 2000,2003 Gian Filippo Pinzari and Brian Pane\n\
\n\
All rights reserved.\n\
";
const char *GetOtherCopyrightInfo()
{
return OtherCopyrightInfo;
}
int _hostBigEndian = 0;
int _storeBigEndian = 0;
const unsigned int IntMask[33] =
{
0x00000000,
0x00000001,
0x00000003,
0x00000007,
0x0000000f,
0x0000001f,
0x0000003f,
0x0000007f,
0x000000ff,
0x000001ff,
0x000003ff,
0x000007ff,
0x00000fff,
0x00001fff,
0x00003fff,
0x00007fff,
0x0000ffff,
0x0001ffff,
0x0003ffff,
0x0007ffff,
0x000fffff,
0x001fffff,
0x003fffff,
0x007fffff,
0x00ffffff,
0x01ffffff,
0x03ffffff,
0x07ffffff,
0x0fffffff,
0x1fffffff,
0x3fffffff,
0x7fffffff,
0xffffffff
};
unsigned int GetUINT(unsigned const char *buffer, int bigEndian)
{
//
// It doesn't work on SPARCs if the buffer
// is not aligned to the word boundary. We
// should check the CPU, not the OS as this
// surely applies to other architectures.
//
#ifndef __sun
if (_hostBigEndian == bigEndian)
{
return *((unsigned short *) buffer);
}
#else
if (_hostBigEndian == bigEndian && ((unsigned int) buffer) & 0x1 == 0)
{
return *((unsigned short *) buffer);
}
#endif
unsigned int result;
if (bigEndian)
{
result = *buffer;
result <<= 8;
result += buffer[1];
}
else
{
result = buffer[1];
result <<= 8;
result += *buffer;
}
return result;
}
unsigned int GetULONG(unsigned const char *buffer, int bigEndian)
{
//
// It doesn't work on SPARCs if the buffer
// is not aligned to word the boundary.
//
#ifndef __sun
if (_hostBigEndian == bigEndian)
{
return *((unsigned int *) buffer);
}
#else
if (_hostBigEndian == bigEndian && ((unsigned int) buffer) & 0x3 == 0)
{
return *((unsigned int *) buffer);
}
#endif
const unsigned char *next = (bigEndian ? buffer : buffer + 3);
unsigned int result = 0;
for (int i = 0; i < 4; i++)
{
result <<= 8;
result += *next;
if (bigEndian)
{
next++;
}
else
{
next--;
}
}
return result;
}
void PutUINT(unsigned int value, unsigned char *buffer, int bigEndian)
{
if (_hostBigEndian == bigEndian)
{
*((unsigned short *) buffer) = value;
return;
}
if (bigEndian)
{
buffer[1] = (unsigned char) (value & 0xff);
value >>= 8;
*buffer = (unsigned char) value;
}
else
{
*buffer = (unsigned char) (value & 0xff);
value >>= 8;
buffer[1] = (unsigned char) value;
}
}
void PutULONG(unsigned int value, unsigned char *buffer, int bigEndian)
{
if (_hostBigEndian == bigEndian)
{
*((unsigned int *) buffer) = value;
return;
}
if (bigEndian)
{
buffer += 3;
for (int i = 4; i > 0; i--)
{
*buffer-- = (unsigned char) (value & 0xff);
value >>= 8;
}
}
else
{
for (int i = 4; i > 0; i--)
{
*buffer++ = (unsigned char) (value & 0xff);
value >>= 8;
}
}
}
int CheckData(istream *fs)
{
if (fs == NULL || fs -> fail())
{
return -1;
}
return 1;
}
int CheckData(ostream *fs)
{
if (fs == NULL || fs -> fail())
{
return -1;
}
return 1;
}
int PutData(ostream *fs, const unsigned char *buffer, int size)
{
fs -> write((char *) buffer, size);
#ifdef DEBUG
*logofs << "PutData: Written " << size << " bytes with eof "
<< fs -> eof() << " fail " << fs -> fail() << " and bad "
<< fs -> bad() << ".\n" << logofs_flush;
#endif
if (fs -> fail())
{
return -1;
}
return size;
}
int GetData(istream *fs, unsigned char *buffer, int size)
{
fs -> read((char *) buffer, size);
#ifdef DEBUG
*logofs << "GetData: Read " << size << " bytes with eof "
<< fs -> eof() << " fail " << fs -> fail()
<< " and bad " << fs -> bad() << ".\n"
<< logofs_flush;
#endif
#ifdef __APPLE__
if (fs -> bad())
{
return -1;
}
#else
if (fs -> fail())
{
return -1;
}
#endif
return size;
}
int FlushData(ostream *fs)
{
fs -> flush();
if (fs -> fail())
{
return -1;
}
return 1;
}
unsigned int RoundUp2(unsigned int x)
{
unsigned int y = x / 2;
y *= 2;
if (y != x)
{
y += 2;
}
return y;
}
unsigned int RoundUp4(unsigned int x)
{
unsigned int y = x / 4;
y *= 4;
if (y != x)
{
y += 4;
}
return y;
}
unsigned int RoundUp8(unsigned int x)
{
unsigned int y = x / 8;
y *= 8;
if (y != x)
{
y += 8;
}
return y;
}
const char *DumpSignal(int signal)
{
switch (signal)
{
case SIGCHLD:
{
return "SIGCHLD";
}
case SIGUSR1:
{
return "SIGUSR1";
}
case SIGUSR2:
{
return "SIGUSR2";
}
case SIGHUP:
{
return "SIGHUP";
}
case SIGINT:
{
return "SIGINT";
}
case SIGTERM:
{
return "SIGTERM";
}
case SIGPIPE:
{
return "SIGPIPE";
}
case SIGALRM:
{
return "SIGALRM";
}
case SIGVTALRM:
{
return "SIGVTALRM";
}
case SIGWINCH:
{
return "SIGWINCH";
}
case SIGIO:
{
return "SIGIO";
}
case SIGTSTP:
{
return "SIGTSTP";
}
case SIGTTIN:
{
return "SIGTTIN";
}
case SIGTTOU:
{
return "SIGTTOU";
}
case SIGSEGV:
{
return "SIGSEGV";
}
case SIGABRT:
{
return "SIGABRT";
}
default:
{
return "Unknown";
}
}
}
const char *DumpPolicy(int type)
{
switch ((T_flush_policy) type)
{
case policy_immediate:
{
return "immediate";
}
case policy_deferred:
{
return "deferred";
}
default:
{
#ifdef PANIC
*logofs << "Misc: PANIC! Unknown policy type '"
<< type << "'.\n" << logofs_flush;
#endif
cerr << "Error" << ": Unknown policy type '"
<< type << "'.\n";
HandleCleanup();
}
}
}
const char *DumpAction(int type)
{
T_store_action action = (T_store_action) type;
if (action == IS_HIT)
{
return "is_hit";
}
else if (action == IS_ADDED)
{
return "is_added";
}
else if (action == is_discarded)
{
return "is_discarded";
}
else if (action == is_removed)
{
return "is_removed";
}
else
{
#ifdef PANIC
*logofs << "Misc: PANIC! Unknown store action '"
<< type << "'.\n" << logofs_flush;
#endif
cerr << "Error" << ": Unknown store action '"
<< type << "'.\n";
HandleCleanup();
}
}
const char *DumpState(int type)
{
switch ((T_split_state) type)
{
case split_added:
{
return "split_added";
}
case split_missed:
{
return "split_missed";
}
case split_loaded:
{
return "split_loaded";
}
case split_aborted:
{
return "split_aborted";
}
case split_notified:
{
return "split_notified";
}
default:
{
#ifdef PANIC
*logofs << "Misc: PANIC! Unknown split state '"
<< type << "'.\n" << logofs_flush;
#endif
cerr << "Error" << ": Unknown split state '"
<< type << "'.\n";
HandleCleanup();
}
}
}
const char *DumpControl(int code)
{
switch ((T_proxy_code) code)
{
case code_new_x_connection:
{
return "code_new_x_connection";
}
case code_new_cups_connection:
{
return "code_new_cups_connection";
}
case code_new_aux_connection:
{
return "code_new_aux_connection";
}
case code_new_smb_connection:
{
return "code_new_smb_connection";
}
case code_new_media_connection:
{
return "code_new_media_connection";
}
case code_switch_connection:
{
return "code_switch_connection";
}
case code_drop_connection:
{
return "code_drop_connection";
}
case code_finish_connection:
{
return "code_finish_connection";
}
case code_begin_congestion:
{
return "code_begin_congestion";
}
case code_end_congestion:
{
return "code_end_congestion";
}
case code_alert_request:
{
return "code_alert_request";
}
case code_alert_reply:
{
return "code_alert_reply";
}
case code_reset_request:
{
return "code_reset_request";
}
case code_reset_reply:
{
return "code_reset_reply";
}
case code_load_request:
{
return "code_load_request";
}
case code_load_reply:
{
return "code_load_reply";
}
case code_save_request:
{
return "code_save_request";
}
case code_save_reply:
{
return "code_save_reply";
}
case code_shutdown_request:
{
return "code_shutdown_request";
}
case code_shutdown_reply:
{
return "code_shutdown_reply";
}
case code_control_token_request:
{
return "code_control_token_request";
}
case code_control_token_reply:
{
return "code_control_token_reply";
}
case code_configuration_request:
{
return "code_configuration_request";
}
case code_configuration_reply:
{
return "code_configuration_reply";
}
case code_statistics_request:
{
return "code_statistics_request";