1 /**************************************************************************/
2 /* */
3 /* Copyright (c) 2001, 2011 NoMachine (http://www.nomachine.com) */
4 /* Copyright (c) 2008-2014 Oleksandr Shneyder <o.shneyder@phoca-gmbh.de> */
5 /* Copyright (c) 2014-2016 Ulrich Sibiller <uli42@gmx.de> */
6 /* Copyright (c) 2014-2016 Mihai Moldovan <ionic@ionic.de> */
7 /* Copyright (c) 2011-2016 Mike Gabriel <mike.gabriel@das-netzwerkteam.de>*/
8 /* Copyright (c) 2015-2016 Qindel Group (http://www.qindel.com) */
9 /* */
10 /* NXCOMP, NX protocol compression and NX extensions to this software */
11 /* are copyright of the aforementioned persons and companies. */
12 /* */
13 /* Redistribution and use of the present software is allowed according */
14 /* to terms specified in the file LICENSE.nxcomp which comes in the */
15 /* source distribution. */
16 /* */
17 /* All rights reserved. */
18 /* */
19 /* NOTE: This software has received contributions from various other */
20 /* contributors, only the core maintainers and supporters are listed as */
21 /* copyright holders. Please contact us, if you feel you should be listed */
22 /* as copyright holder, as well. */
23 /* */
24 /**************************************************************************/
25
26 #ifdef HAVE_CONFIG_H
27 #include "config.h"
28 #endif
29
30 #include "ConfigureWindow.h"
31
32 #include "ClientCache.h"
33
34 #include "EncodeBuffer.h"
35 #include "DecodeBuffer.h"
36
37 //
38 // Set the verbosity level.
39 //
40
41 #define PANIC
42 #define WARNING
43 #undef TEST
44 #undef DEBUG
45 #undef DUMP
46
47 //
48 // Here are the methods to handle messages' content.
49 //
50
parseIdentity(Message * message,const unsigned char * buffer,unsigned int size,int bigEndian) const51 int ConfigureWindowStore::parseIdentity(Message *message, const unsigned char *buffer,
52 unsigned int size, int bigEndian) const
53 {
54 ConfigureWindowMessage *configureWindow = (ConfigureWindowMessage *) message;
55
56 //
57 // Here is the fingerprint.
58 //
59
60 configureWindow -> window = GetULONG(buffer + 4, bigEndian);
61
62 configureWindow -> value_mask = GetUINT(buffer + 8, bigEndian);
63
64 //
65 // To increase effectiveness of the caching algorithm
66 // we remove the unused bytes carried in the data part.
67 //
68
69 if ((int) size > dataOffset)
70 {
71 #ifdef DEBUG
72 *logofs << name() << ": Removing unused bytes from the data payload.\n" << logofs_flush;
73 #endif
74
75 configureWindow -> value_mask &= (1 << 7) - 1;
76
77 unsigned int mask = 0x1;
78 unsigned char *source = (unsigned char *) buffer + CONFIGUREWINDOW_DATA_OFFSET;
79 unsigned long value = 0;
80
81 for (unsigned int i = 0; i < 7; i++)
82 {
83 if (configureWindow -> value_mask & mask)
84 {
85 value = GetULONG(source, bigEndian);
86
87 value &= (1 << CONFIGUREWINDOW_FIELD_WIDTH[i]) - 1;
88
89 PutULONG(value, source, bigEndian);
90
91 source += 4;
92 }
93 mask <<= 1;
94 }
95 }
96
97 #ifdef DEBUG
98 *logofs << name() << ": Parsed Identity for message at " << this << ".\n" << logofs_flush;
99 #endif
100
101 return 1;
102 }
103
unparseIdentity(const Message * message,unsigned char * buffer,unsigned int size,int bigEndian) const104 int ConfigureWindowStore::unparseIdentity(const Message *message, unsigned char *buffer,
105 unsigned int size, int bigEndian) const
106 {
107 ConfigureWindowMessage *configureWindow = (ConfigureWindowMessage *) message;
108
109 //
110 // Fill all the message's fields.
111 //
112
113 PutULONG(configureWindow -> window, buffer + 4, bigEndian);
114
115 PutUINT(configureWindow -> value_mask, buffer + 8, bigEndian);
116
117 #ifdef DEBUG
118 *logofs << name() << ": Unparsed identity for message at " << this << ".\n" << logofs_flush;
119 #endif
120
121 return 1;
122 }
123
dumpIdentity(const Message * message) const124 void ConfigureWindowStore::dumpIdentity(const Message *message) const
125 {
126 #ifdef DUMP
127
128 ConfigureWindowMessage *configureWindow = (ConfigureWindowMessage *) message;
129
130 *logofs << "ConfigureWindow: window " << configureWindow -> window
131 << ", value_mask " << configureWindow -> value_mask
132 << ", size " << configureWindow -> size_ << ".\n";
133
134 #endif
135 }
136
identityChecksum(const Message * message,const unsigned char * buffer,unsigned int size,int bigEndian) const137 void ConfigureWindowStore::identityChecksum(const Message *message, const unsigned char *buffer,
138 unsigned int size, int bigEndian) const
139 {
140 md5_append(md5_state_, buffer + 4, 4);
141 md5_append(md5_state_, buffer + 8, 2);
142 }
143