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
|
/**************************************************************************/
/* */
/* Copyright (c) 2001, 2007 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 NoMachine S.r.l. */
/* */
/* All rights reserved. */
/* */
/**************************************************************************/
//
// Include the template for
// this message class.
//
#include "RenderCompositeGlyphsCompat.h"
//
// Set the verbosity level.
//
#define PANIC
#define WARNING
#undef TEST
#undef DEBUG
#include MESSAGE_TAGS
//
// Message handling methods.
//
MESSAGE_BEGIN_ENCODE_SIZE
{
ClientCache *clientCache = (ClientCache *) channelCache;
//
// The offset points 8 bytes after
// the beginning of the data part.
//
#ifdef DEBUG
*logofs << name() << ": Encoding value "
<< ((size - (MESSAGE_OFFSET - 8)) >> 2)
<< ".\n" << logofs_flush;
#endif
encodeBuffer.encodeCachedValue((size - (MESSAGE_OFFSET - 8)) >> 2, 16,
clientCache -> renderLengthCache, 5);
#ifdef TEST
*logofs << name() << ": Encoded size with value "
<< size << ".\n" << logofs_flush;
#endif
}
MESSAGE_END_ENCODE_SIZE
MESSAGE_BEGIN_DECODE_SIZE
{
ClientCache *clientCache = (ClientCache *) channelCache;
decodeBuffer.decodeCachedValue(size, 16,
clientCache -> renderLengthCache, 5);
#ifdef DEBUG
*logofs << name() << ": Decoded value " << size
<< ".\n" << logofs_flush;
#endif
size = (MESSAGE_OFFSET - 8) + (size << 2);
buffer = writeBuffer -> addMessage(size);
#ifdef TEST
*logofs << name() << ": Decoded size with value "
<< size << ".\n" << logofs_flush;
#endif
}
MESSAGE_END_DECODE_SIZE
MESSAGE_BEGIN_ENCODE_MESSAGE
{
ClientCache *clientCache = (ClientCache *) channelCache;
encodeBuffer.encodeCachedValue(*(buffer + 4), 8,
clientCache -> renderOpCache);
encodeBuffer.encodeXidValue(GetULONG(buffer + 8, bigEndian),
clientCache -> renderSrcPictureCache);
encodeBuffer.encodeXidValue(GetULONG(buffer + 12, bigEndian),
clientCache -> renderSrcPictureCache);
encodeBuffer.encodeCachedValue(GetULONG(buffer + 16, bigEndian), 32,
clientCache -> renderFormatCache);
encodeBuffer.encodeCachedValue(GetULONG(buffer + 20, bigEndian), 29,
clientCache -> renderGlyphSetCache);
encodeBuffer.encodeDiffCachedValue(GetUINT(buffer + 24, bigEndian),
clientCache -> renderLastX, 16,
clientCache -> renderXCache, 11);
encodeBuffer.encodeDiffCachedValue(GetUINT(buffer + 26, bigEndian),
clientCache -> renderLastY, 16,
clientCache -> renderYCache, 11);
//
// Try to save as many bits as possible by
// encoding the information about the first
// set of glyphs.
//
if (size >= MESSAGE_OFFSET)
{
unsigned int numGlyphs = *(buffer + 28);
encodeBuffer.encodeCachedValue(numGlyphs, 8,
clientCache -> renderNumGlyphsCache);
encodeBuffer.encodeCachedValue(GetUINT(buffer + 32, bigEndian), 16,
clientCache -> renderWidthCache, 11);
encodeBuffer.encodeCachedValue(GetUINT(buffer + 34, bigEndian), 16,
clientCache -> renderHeightCache, 11);
//
// Only manage the first set of glyphs,
// that is in most cases the only one.
//
switch (*(buffer + 1))
{
case X_RenderCompositeGlyphs8:
{
if (numGlyphs & 0x03)
{
memset((unsigned char *) buffer + MESSAGE_OFFSET + numGlyphs, '\0',
RoundUp4(numGlyphs) - numGlyphs);
}
break;
}
case X_RenderCompositeGlyphs16:
{
if (numGlyphs & 0x01)
{
memset((unsigned char *) buffer + MESSAGE_OFFSET + (numGlyphs * 2), '\0',
RoundUp4(numGlyphs * 2) - numGlyphs * 2);
}
break;
}
}
#ifdef TEST
if (*(buffer + (size - 1)) != '\0')
{
*logofs << name() << ": WARNING! Final byte is non-zero with size "
<< size << " and " << (unsigned int) *(buffer + 28)
<< " glyphs.\n" << logofs_flush;
}
else
{
*logofs << name() << ": Final byte is zero with size "
<< size << " and " << (unsigned int) *(buffer + 28)
<< " glyphs.\n" << logofs_flush;
}
#endif
}
#ifdef TEST
*logofs << name() << ": Encoded message. Type is "
<< (unsigned int) *(buffer + 1) << " size is "
<< size << ".\n" << logofs_flush;
#endif
}
MESSAGE_END_ENCODE_MESSAGE
MESSAGE_BEGIN_DECODE_MESSAGE
{
ClientCache *clientCache = (ClientCache *) channelCache;
unsigned int value;
*(buffer + 1) = type;
decodeBuffer.decodeCachedValue(*(buffer + 4), 8,
clientCache -> renderOpCache);
decodeBuffer.decodeXidValue(value,
clientCache -> renderSrcPictureCache);
PutULONG(value, buffer + 8, bigEndian);
decodeBuffer.decodeXidValue(value,
clientCache -> renderSrcPictureCache);
PutULONG(value, buffer + 12, bigEndian);
decodeBuffer.decodeCachedValue(value, 32,
clientCache -> renderFormatCache);
PutULONG(value, buffer + 16, bigEndian);
decodeBuffer.decodeCachedValue(value, 29,
clientCache -> renderGlyphSetCache);
PutULONG(value, buffer + 20, bigEndian);
decodeBuffer.decodeDiffCachedValue(value,
clientCache -> renderLastX, 16,
clientCache -> renderXCache, 11);
PutUINT(clientCache -> renderLastX, buffer + 24, bigEndian);
decodeBuffer.decodeDiffCachedValue(value,
clientCache -> renderLastY, 16,
clientCache -> renderYCache, 11);
PutUINT(clientCache -> renderLastY, buffer + 26, bigEndian);
if (size >= MESSAGE_OFFSET)
{
decodeBuffer.decodeCachedValue(value, 8,
clientCache -> renderNumGlyphsCache);
*(buffer + 28) = value;
decodeBuffer.decodeCachedValue(value, 16,
clientCache -> renderWidthCache, 11);
PutUINT(value, buffer + 32, bigEndian);
decodeBuffer.decodeCachedValue(value, 16,
clientCache -> renderHeightCache, 11);
PutUINT(value, buffer + 34, bigEndian);
}
#ifdef TEST
*logofs << name() << ": Decoded message. Type is "
<< (unsigned int) type << " size is " << size
<< ".\n" << logofs_flush;
#endif
}
MESSAGE_END_DECODE_MESSAGE
MESSAGE_BEGIN_ENCODE_DATA
{
ClientCache *clientCache = (ClientCache *) channelCache;
unsigned int value;
switch (*(buffer + 1))
{
case X_RenderCompositeGlyphs8:
{
clientCache -> renderTextCompressor.reset();
const unsigned char *next = buffer + MESSAGE_OFFSET;
for (unsigned int i = MESSAGE_OFFSET; i < size; i++)
{
#ifdef DEBUG
*logofs << name() << ": Encoding char with i = " << i
<< ".\n" << logofs_flush;
#endif
clientCache -> renderTextCompressor.
encodeChar(*next++, encodeBuffer);
}
break;
}
case X_RenderCompositeGlyphs16:
{
for (unsigned int i = MESSAGE_OFFSET; i < size; i += 2)
{
value = GetUINT(buffer + i, bigEndian);
#ifdef DEBUG
*logofs << name() << ": Encoding short with i = " << i
<< ".\n" << logofs_flush;
#endif
encodeBuffer.encodeCachedValue(value, 16,
*clientCache -> renderCompositeGlyphsDataCache[clientCache ->
renderLastCompositeGlyphsData]);
clientCache -> renderLastCompositeGlyphsData = value % 16;
}
break;
}
default:
{
for (unsigned int i = MESSAGE_OFFSET; i < size; i += 4)
{
value = GetULONG(buffer + i, bigEndian);
#ifdef DEBUG
*logofs << name() << ": Encoding long with i = " << i
<< ".\n" << logofs_flush;
#endif
encodeBuffer.encodeCachedValue(value, 32,
*clientCache -> renderCompositeGlyphsDataCache[clientCache ->
renderLastCompositeGlyphsData]);
clientCache -> renderLastCompositeGlyphsData = value % 16;
}
break;
}
}
#ifdef TEST
*logofs << name() << ": Encoded " << size - MESSAGE_OFFSET
<< " bytes of data.\n" << logofs_flush;
#endif
}
MESSAGE_END_ENCODE_DATA
MESSAGE_BEGIN_DECODE_DATA
{
ClientCache *clientCache = (ClientCache *) channelCache;
unsigned int value;
switch (*(buffer + 1))
{
case X_RenderCompositeGlyphs8:
{
clientCache -> renderTextCompressor.reset();
unsigned char *next = buffer + MESSAGE_OFFSET;
for (unsigned int i = MESSAGE_OFFSET; i < size; i++)
{
#ifdef DEBUG
*logofs << name() << ": Decoding char with i = " << i
<< ".\n" << logofs_flush;
#endif
*next++ = clientCache -> renderTextCompressor.
decodeChar(decodeBuffer);
}
break;
}
case X_RenderCompositeGlyphs16:
{
for (unsigned int i = MESSAGE_OFFSET; i < size; i += 2)
{
#ifdef DEBUG
*logofs << name() << ": Decoding short with i = " << i
<< ".\n" << logofs_flush;
#endif
decodeBuffer.decodeCachedValue(value, 16,
*clientCache -> renderCompositeGlyphsDataCache[clientCache ->
renderLastCompositeGlyphsData]);
PutUINT(value, buffer + i, bigEndian);
clientCache -> renderLastCompositeGlyphsData = value % 16;
}
break;
}
default:
{
for (unsigned int i = MESSAGE_OFFSET; i < size; i += 4)
{
#ifdef DEBUG
*logofs << name() << ": Decoding long with i = " << i
<< ".\n" << logofs_flush;
#endif
decodeBuffer.decodeCachedValue(value, 32,
*clientCache -> renderCompositeGlyphsDataCache[clientCache ->
renderLastCompositeGlyphsData]);
PutULONG(value, buffer + i, bigEndian);
clientCache -> renderLastCompositeGlyphsData = value % 16;
}
break;
}
}
#ifdef TEST
*logofs << name() << ": Decoded " << size - MESSAGE_OFFSET
<< " bytes of data.\n" << logofs_flush;
#endif
}
MESSAGE_END_DECODE_DATA
MESSAGE_BEGIN_PARSE_IDENTITY
{
RenderExtensionMessage *renderExtension = (RenderExtensionMessage *) message;
renderExtension -> data.composite_glyphs_compat.type = *(buffer + 1);
renderExtension -> data.composite_glyphs_compat.op = *(buffer + 4);
renderExtension -> data.composite_glyphs_compat.src_id = GetULONG(buffer + 8, bigEndian);
renderExtension -> data.composite_glyphs_compat.dst_id = GetULONG(buffer + 12, bigEndian);
renderExtension -> data.composite_glyphs_compat.format = GetULONG(buffer + 16, bigEndian);
renderExtension -> data.composite_glyphs_compat.set_id = GetULONG(buffer + 20, bigEndian);
renderExtension -> data.composite_glyphs_compat.src_x = GetUINT(buffer + 24, bigEndian);
renderExtension -> data.composite_glyphs_compat.src_y = GetUINT(buffer + 26, bigEndian);
if (size >= MESSAGE_OFFSET)
{
renderExtension -> data.composite_glyphs_compat.num_elm = *(buffer + 28);
renderExtension -> data.composite_glyphs_compat.delta_x = GetUINT(buffer + 32, bigEndian);
renderExtension -> data.composite_glyphs_compat.delta_y = GetUINT(buffer + 34, bigEndian);
}
#ifdef TEST
*logofs << name() << ": Parsed identity. Type is "
<< (unsigned int) renderExtension -> data.composite_glyphs_compat.type
<< " size is " << renderExtension -> size_ << " identity size "
<< renderExtension -> i_size_ << ".\n"
<< logofs_flush;
#endif
}
MESSAGE_END_PARSE_IDENTITY
MESSAGE_BEGIN_UNPARSE_IDENTITY
{
RenderExtensionMessage *renderExtension = (RenderExtensionMessage *) message;
*(buffer + 1) = renderExtension -> data.composite_glyphs_compat.type;
*(buffer + 4) = renderExtension -> data.composite_glyphs_compat.op;
PutULONG(renderExtension -> data.composite_glyphs_compat.src_id, buffer + 8, bigEndian);
PutULONG(renderExtension -> data.composite_glyphs_compat.dst_id, buffer + 12, bigEndian);
PutULONG(renderExtension -> data.composite_glyphs_compat.format, buffer + 16, bigEndian);
PutULONG(renderExtension -> data.composite_glyphs_compat.set_id, buffer + 20, bigEndian);
PutUINT(renderExtension -> data.composite_glyphs_compat.src_x, buffer + 24, bigEndian);
PutUINT(renderExtension -> data.composite_glyphs_compat.src_y, buffer + 26, bigEndian);
if (size >= MESSAGE_OFFSET)
{
*(buffer + 28) = renderExtension -> data.composite_glyphs_compat.num_elm;
PutUINT(renderExtension -> data.composite_glyphs_compat.delta_x, buffer + 32, bigEndian);
PutUINT(renderExtension -> data.composite_glyphs_compat.delta_y, buffer + 34, bigEndian);
#ifdef DEBUG
*logofs << name() << ": Len is " << (unsigned int) *(buffer + 28)
<< " delta X is " << GetUINT(buffer + 32, bigEndian)
<< " delta Y is " << GetUINT(buffer + 34, bigEndian)
<< ".\n" << logofs_flush;
*logofs << name() << ": Pad 1 is " << (unsigned int) *(buffer + 29)
<< " pad 2 and 3 are " << GetUINT(buffer + 30, bigEndian)
<< ".\n" << logofs_flush;
#endif
}
#ifdef TEST
*logofs << name() << ": Unparsed identity. Type is "
<< (unsigned int) renderExtension -> data.composite_glyphs_compat.type
<< " size is " << renderExtension -> size_ << " identity size "
<< renderExtension -> i_size_ << ".\n" << ".\n"
<< logofs_flush;
#endif
}
MESSAGE_END_UNPARSE_IDENTITY
MESSAGE_BEGIN_IDENTITY_CHECKSUM
{
//
// Include minor opcode, size and
// the composite operator in the
// identity.
//
md5_append(md5_state, buffer + 1, 4);
//
// Include the format and the source
// x and y fields.
//
md5_append(md5_state, buffer + 16, 4);
md5_append(md5_state, buffer + 24, 4);
//
// Include the number of glyphs.
//
if (size >= MESSAGE_OFFSET)
{
md5_append(md5_state, buffer + 28, 1);
}
}
MESSAGE_END_IDENTITY_CHECKSUM
MESSAGE_BEGIN_ENCODE_UPDATE
{
RenderExtensionMessage *renderExtension = (RenderExtensionMessage *) message;
RenderExtensionMessage *cachedRenderExtension = (RenderExtensionMessage *) cachedMessage;
ClientCache *clientCache = (ClientCache *) channelCache;
encodeBuffer.encodeXidValue(renderExtension -> data.composite_glyphs_compat.src_id,
clientCache -> renderSrcPictureCache);
cachedRenderExtension -> data.composite_glyphs_compat.src_id =
renderExtension -> data.composite_glyphs_compat.src_id;
encodeBuffer.encodeXidValue(renderExtension -> data.composite_glyphs_compat.dst_id,
clientCache -> renderSrcPictureCache);
cachedRenderExtension -> data.composite_glyphs_compat.dst_id =
renderExtension -> data.composite_glyphs_compat.dst_id;
encodeBuffer.encodeCachedValue(renderExtension -> data.composite_glyphs_compat.set_id, 29,
clientCache -> renderGlyphSetCache);
cachedRenderExtension -> data.composite_glyphs_compat.set_id =
renderExtension -> data.composite_glyphs_compat.set_id;
if (renderExtension -> size_ >= MESSAGE_OFFSET)
{
encodeBuffer.encodeCachedValue(renderExtension -> data.composite_glyphs_compat.delta_x, 16,
clientCache -> renderWidthCache, 11);
cachedRenderExtension -> data.composite_glyphs_compat.delta_x =
renderExtension -> data.composite_glyphs_compat.delta_x;
encodeBuffer.encodeCachedValue(renderExtension -> data.composite_glyphs_compat.delta_y, 16,
clientCache -> renderHeightCache, 11);
cachedRenderExtension -> data.composite_glyphs_compat.delta_y =
renderExtension -> data.composite_glyphs_compat.delta_y;
}
#ifdef TEST
*logofs << name() << ": Encoded update. Type is "
<< (unsigned int) renderExtension -> data.composite_glyphs_compat.type
<< " size is " << renderExtension -> size_ << ".\n"
<< logofs_flush;
#endif
}
MESSAGE_END_ENCODE_UPDATE
MESSAGE_BEGIN_DECODE_UPDATE
{
RenderExtensionMessage *renderExtension = (RenderExtensionMessage *) message;
ClientCache *clientCache = (ClientCache *) channelCache;
decodeBuffer.decodeXidValue(renderExtension -> data.composite_glyphs_compat.src_id,
clientCache -> renderSrcPictureCache);
decodeBuffer.decodeXidValue(renderExtension -> data.composite_glyphs_compat.dst_id,
clientCache -> renderSrcPictureCache);
decodeBuffer.decodeCachedValue(renderExtension -> data.composite_glyphs_compat.set_id, 29,
clientCache -> renderGlyphSetCache);
if (renderExtension -> size_ >= MESSAGE_OFFSET)
{
unsigned int value;
decodeBuffer.decodeCachedValue(value, 16,
clientCache -> renderWidthCache, 11);
renderExtension -> data.composite_glyphs_compat.delta_x = value;
decodeBuffer.decodeCachedValue(value, 16,
clientCache -> renderHeightCache, 11);
renderExtension -> data.composite_glyphs_compat.delta_y = value;
}
#ifdef TEST
*logofs << name() << ": Decoded update. Type is "
<< (unsigned int) renderExtension -> data.composite_glyphs_compat.type
<< " size is " << renderExtension -> size_ << ".\n"
<< logofs_flush;
#endif
}
MESSAGE_END_DECODE_UPDATE
|