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

« back to all changes in this revision

Viewing changes to FillPoly.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 "FillPoly.h"
 
19
 
 
20
#include "ClientCache.h"
 
21
 
 
22
#include "EncodeBuffer.h"
 
23
#include "DecodeBuffer.h"
 
24
 
 
25
//
 
26
// Set the verbosity level.
 
27
//
 
28
 
 
29
#define PANIC
 
30
#define WARNING
 
31
#undef  TEST
 
32
#undef  DEBUG
 
33
#undef  DUMP
 
34
 
 
35
//
 
36
// Here are the methods to handle messages' content.
 
37
//
 
38
 
 
39
int FillPolyStore::parseIdentity(Message *message, const unsigned char *buffer,
 
40
                                     unsigned int size, int bigEndian) const
 
41
{
 
42
  FillPolyMessage *fillPoly = (FillPolyMessage *) message;
 
43
 
 
44
  //
 
45
  // Here is the fingerprint.
 
46
  //
 
47
 
 
48
  fillPoly -> drawable = GetULONG(buffer + 4, bigEndian);
 
49
  fillPoly -> gcontext = GetULONG(buffer + 8, bigEndian);
 
50
 
 
51
  fillPoly -> shape = *(buffer + 12);
 
52
  fillPoly -> mode  = *(buffer + 13);
 
53
 
 
54
  if (control -> isProtoStep8() == 1 &&
 
55
          size >= (unsigned int) dataOffset)
 
56
  {
 
57
    fillPoly -> x_origin = GetUINT(buffer + 16, bigEndian);
 
58
    fillPoly -> y_origin = GetUINT(buffer + 18, bigEndian);
 
59
  }
 
60
  else
 
61
  {
 
62
    fillPoly -> x_origin = 0;
 
63
    fillPoly -> y_origin = 0;
 
64
  }
 
65
 
 
66
  #ifdef DEBUG
 
67
  *logofs << name() << ": Parsed Identity for message at " << this << ".\n" << logofs_flush;
 
68
  #endif
 
69
 
 
70
  return 1;
 
71
}
 
72
 
 
73
int FillPolyStore::unparseIdentity(const Message *message, unsigned char *buffer,
 
74
                                       unsigned int size, int bigEndian) const
 
75
{
 
76
  FillPolyMessage *fillPoly = (FillPolyMessage *) message;
 
77
 
 
78
  //
 
79
  // Fill all the message's fields.
 
80
  //
 
81
 
 
82
  PutULONG(fillPoly -> drawable, buffer + 4, bigEndian);
 
83
  PutULONG(fillPoly -> gcontext, buffer + 8, bigEndian);
 
84
 
 
85
  *(buffer + 12) = fillPoly -> shape;
 
86
  *(buffer + 13) = fillPoly -> mode;
 
87
 
 
88
  if (control -> isProtoStep8() == 1 &&
 
89
          size >= (unsigned int) dataOffset)
 
90
  {
 
91
    PutUINT(fillPoly -> x_origin, buffer + 16, bigEndian);
 
92
    PutUINT(fillPoly -> y_origin, buffer + 18, bigEndian);
 
93
  }
 
94
 
 
95
  #ifdef DEBUG
 
96
  *logofs << name() << ": Unparsed identity for message at " << this << ".\n" << logofs_flush;
 
97
  #endif
 
98
 
 
99
  return 1;
 
100
}
 
101
 
 
102
void FillPolyStore::dumpIdentity(const Message *message) const
 
103
{
 
104
  #ifdef DUMP
 
105
 
 
106
  FillPolyMessage *fillPoly = (FillPolyMessage *) message;
 
107
 
 
108
  *logofs << name() << ": Identity drawable " << fillPoly -> drawable
 
109
                    << ", gcontext " << fillPoly -> gcontext << ", shape "
 
110
                    << fillPoly -> shape << ", mode " << fillPoly -> mode
 
111
                    << fillPoly -> size_ << ", x_origin " << fillPoly -> x_origin
 
112
                    << ", y_origin " << fillPoly -> y_origin << ".\n"
 
113
                    << logofs_flush;
 
114
  #endif
 
115
}
 
116
 
 
117
void FillPolyStore::identityChecksum(const Message *message, const unsigned char *buffer,
 
118
                                         unsigned int size, int bigEndian) const
 
119
{
 
120
  //
 
121
  // Fields shape, mode.
 
122
  //
 
123
 
 
124
  md5_append(md5_state_, buffer + 12, 2);
 
125
}
 
126
 
 
127
void FillPolyStore::updateIdentity(EncodeBuffer &encodeBuffer, const Message *message,
 
128
                                       const Message *cachedMessage,
 
129
                                           ChannelCache *channelCache) const
 
130
{
 
131
  FillPolyMessage *fillPoly       = (FillPolyMessage *) message;
 
132
  FillPolyMessage *cachedFillPoly = (FillPolyMessage *) cachedMessage;
 
133
 
 
134
  ClientCache *clientCache = (ClientCache *) channelCache;
 
135
 
 
136
  #ifdef TEST
 
137
  *logofs << name() << ": Encoding value " << fillPoly -> drawable
 
138
          << " as drawable field.\n" << logofs_flush;
 
139
  #endif
 
140
 
 
141
  encodeBuffer.encodeXidValue(fillPoly -> drawable, clientCache -> drawableCache);
 
142
 
 
143
  cachedFillPoly -> drawable = fillPoly -> drawable;
 
144
 
 
145
  #ifdef TEST
 
146
  *logofs << name() << ": Encoding value " << fillPoly -> gcontext
 
147
          << " as gcontext field.\n" << logofs_flush;
 
148
  #endif
 
149
 
 
150
  encodeBuffer.encodeXidValue(fillPoly -> gcontext, clientCache -> gcCache);
 
151
 
 
152
  cachedFillPoly -> gcontext = fillPoly -> gcontext;
 
153
 
 
154
  if (control -> isProtoStep8() == 1 &&
 
155
          fillPoly -> size_ >= dataOffset)
 
156
  {
 
157
    #ifdef TEST
 
158
    *logofs << name() << ": Encoding value " << fillPoly -> x_origin
 
159
        << " as x_origin field.\n" << logofs_flush;
 
160
    #endif
 
161
 
 
162
    encodeBuffer.encodeCachedValue(fillPoly -> x_origin, 16,
 
163
                 *clientCache -> fillPolyXAbsCache[0], 8);
 
164
 
 
165
    cachedFillPoly -> x_origin = fillPoly -> x_origin;
 
166
 
 
167
    #ifdef TEST
 
168
    *logofs << name() << ": Encoding value " << fillPoly -> y_origin
 
169
            << " as y_origin field.\n" << logofs_flush;
 
170
    #endif
 
171
 
 
172
    encodeBuffer.encodeCachedValue(fillPoly -> y_origin, 16,
 
173
                 *clientCache -> fillPolyYAbsCache[0], 8);
 
174
 
 
175
    cachedFillPoly -> y_origin = fillPoly -> y_origin;
 
176
  }
 
177
}
 
178
 
 
179
void FillPolyStore::updateIdentity(DecodeBuffer &decodeBuffer, const Message *message,
 
180
                                       ChannelCache *channelCache) const
 
181
{
 
182
  FillPolyMessage *fillPoly = (FillPolyMessage *) message;
 
183
 
 
184
  ClientCache *clientCache = (ClientCache *) channelCache;
 
185
 
 
186
  decodeBuffer.decodeXidValue(fillPoly -> drawable, clientCache -> drawableCache);
 
187
 
 
188
  #ifdef TEST
 
189
  *logofs << name() << ": Decoded value " << fillPoly -> drawable
 
190
          << " as drawable field.\n" << logofs_flush;
 
191
  #endif
 
192
 
 
193
  decodeBuffer.decodeXidValue(fillPoly -> gcontext, clientCache -> gcCache);
 
194
 
 
195
  #ifdef TEST
 
196
  *logofs << name() << ": Decoded value " << fillPoly -> gcontext
 
197
          << " as gcontext field.\n" << logofs_flush;
 
198
  #endif
 
199
 
 
200
  if (control -> isProtoStep8() == 1 &&
 
201
          fillPoly -> size_ >= dataOffset)
 
202
  {
 
203
    unsigned int value;
 
204
 
 
205
    decodeBuffer.decodeCachedValue(value, 16,
 
206
                 *clientCache -> fillPolyXAbsCache[0], 8);
 
207
 
 
208
    fillPoly -> x_origin = value;
 
209
 
 
210
    #ifdef TEST
 
211
    *logofs << name() << ": Decoded value " << fillPoly -> x_origin
 
212
            << " as x_origin field.\n" << logofs_flush;
 
213
    #endif
 
214
 
 
215
    decodeBuffer.decodeCachedValue(value, 16,
 
216
                 *clientCache -> fillPolyYAbsCache[0], 8);
 
217
 
 
218
    fillPoly -> y_origin = value;
 
219
 
 
220
    #ifdef TEST
 
221
    *logofs << name() << ": Decoded value " << fillPoly -> y_origin
 
222
            << " as y_origin field.\n" << logofs_flush;
 
223
    #endif
 
224
  }
 
225
}
 
226
 
 
227