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
|
/**************************************************************************/
/* */
/* Copyright (c) 2001, 2009 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. */
/* */
/**************************************************************************/
#ifndef RenderExtension_H
#define RenderExtension_H
#include "Message.h"
//
// Set the verbosity level.
//
#define PANIC
#define WARNING
#undef TEST
#undef DEBUG
#undef DUMP
//
// Compression of data part is not enabled as
// most messages of this type are smaller than
// the current data size compression threshold.
//
#define RENDEREXTENSION_ENABLE_CACHE 1
#define RENDEREXTENSION_ENABLE_DATA 0
#define RENDEREXTENSION_ENABLE_SPLIT 0
#define RENDEREXTENSION_ENABLE_COMPRESS 0
#define RENDEREXTENSION_DATA_LIMIT 6144
#define RENDEREXTENSION_DATA_OFFSET 36
#define RENDEREXTENSION_CACHE_SLOTS 6000
#define RENDEREXTENSION_CACHE_THRESHOLD 20
#define RENDEREXTENSION_CACHE_LOWER_THRESHOLD 10
#define RENDEREXTENSION_CACHE_SLOTS_IF_PROTO_STEP_7 8000
//
// Used to build the table of minor opcodes.
//
#define RENDEREXTENSION_MINOR_OPCODE_LIMIT 256
//
// The message class.
//
class RenderMinorExtensionStore;
class RenderExtensionMessage : public Message
{
friend class RenderExtensionStore;
friend class RenderMinorExtensionStore;
friend class RenderGenericRequestStore;
friend class RenderCreatePictureStore;
friend class RenderChangePictureStore;
friend class RenderFreePictureStore;
friend class RenderPictureClipStore;
friend class RenderPictureTransformStore;
friend class RenderPictureFilterStore;
friend class RenderCreateGlyphSetStore;
friend class RenderFreeGlyphSetStore;
friend class RenderAddGlyphsStore;
friend class RenderCompositeStore;
friend class RenderCompositeGlyphsStore;
friend class RenderFillRectanglesStore;
friend class RenderTrapezoidsStore;
friend class RenderTrianglesStore;
friend class RenderCreatePictureCompatStore;
friend class RenderFreePictureCompatStore;
friend class RenderPictureClipCompatStore;
friend class RenderCreateGlyphSetCompatStore;
friend class RenderCompositeCompatStore;
friend class RenderCompositeGlyphsCompatStore;
public:
RenderExtensionMessage()
{
}
~RenderExtensionMessage()
{
}
//
// We consider for this message a data offset of 36,
// that is size of the biggest among all requests of
// this extension. The most common requests have a
// specific differential encoding, others are simply
// encoded through an array of int or char caches.
//
private:
union
{
struct
{
unsigned char type;
unsigned char char_data[32];
unsigned short short_data[16];
unsigned short long_data[8];
}
any;
struct
{
unsigned char type;
unsigned int src_id;
unsigned int dst_id;
unsigned int format;
unsigned int mask;
}
create_picture;
struct
{
unsigned char type;
unsigned int src_id;
}
change_picture;
struct
{
unsigned char type;
unsigned int src_id;
}
free_picture;
struct
{
unsigned char type;
unsigned int src_id;
unsigned short src_x;
unsigned short src_y;
}
picture_clip;
struct
{
unsigned char type;
unsigned int src_id;
}
picture_transform;
struct
{
unsigned char type;
unsigned int src_id;
unsigned int num_elm;
}
picture_filter;
struct
{
unsigned char type;
unsigned int set_id;
unsigned int format;
}
create_set;
struct
{
unsigned char type;
unsigned int set_id;
}
free_set;
struct
{
unsigned char type;
unsigned int set_id;
unsigned int num_elm;
}
add_glyphs;
struct
{
unsigned char type;
unsigned char op;
unsigned int src_id;
unsigned int msk_id;
unsigned int dst_id;
unsigned short src_x;
unsigned short src_y;
unsigned short msk_x;
unsigned short msk_y;
unsigned short dst_x;
unsigned short dst_y;
unsigned short width;
unsigned short height;
}
composite;
struct
{
unsigned char type;
unsigned char op;
unsigned char num_elm;
unsigned int src_id;
unsigned int dst_id;
unsigned int format;
unsigned int set_id;
unsigned short src_x;
unsigned short src_y;
unsigned short offset_x;
unsigned short offset_y;
}
composite_glyphs;
struct
{
unsigned char type;
unsigned char op;
unsigned int dst_id;
}
fill_rectangles;
struct
{
unsigned char type;
unsigned char op;
unsigned int src_id;
unsigned int dst_id;
unsigned int format;
unsigned short src_x;
unsigned short src_y;
}
trapezoids;
struct
{
unsigned char type;
unsigned char op;
unsigned int src_id;
unsigned int dst_id;
unsigned int format;
unsigned short src_x;
unsigned short src_y;
}
triangles;
struct
{
unsigned char type;
unsigned char op;
unsigned char num_elm;
unsigned int src_id;
unsigned int dst_id;
unsigned int format;
unsigned int set_id;
unsigned short src_x;
unsigned short src_y;
unsigned short delta_x;
unsigned short delta_y;
}
composite_glyphs_compat;
}
data;
};
class RenderExtensionStore : public MessageStore
{
public:
RenderExtensionStore(StaticCompressor *compressor);
virtual ~RenderExtensionStore();
virtual const char *name() const
{
return "RenderExtension";
}
virtual unsigned char opcode() const
{
return opcode_;
}
virtual unsigned int storage() const
{
return sizeof(RenderExtensionMessage);
}
//
// Message handling methods.
//
public:
virtual Message *create() const
{
return new RenderExtensionMessage();
}
virtual Message *create(const Message &message) const
{
return new RenderExtensionMessage((const RenderExtensionMessage &) message);
}
virtual void destroy(Message *message) const
{
delete (RenderExtensionMessage *) message;
}
//
// Determine if the message must be stored
// in the cache.
//
virtual int validateMessage(const unsigned char *buffer, int size);
//
// Since protocol step 5 these methods are
// specialized in their minor opcode stores.
//
virtual int identitySize(const unsigned char *buffer, unsigned int size);
virtual int encodeIdentity(EncodeBuffer &encodeBuffer, const unsigned char *buffer,
const unsigned int size, int bigEndian,
ChannelCache *channelCache) const;
virtual int decodeIdentity(DecodeBuffer &decodeBuffer, unsigned char *&buffer,
unsigned int &size, int bigEndian, WriteBuffer *writeBuffer,
ChannelCache *channelCache) const;
virtual int parseIdentity(Message *message, const unsigned char *buffer,
unsigned int size, int bigEndian) const;
virtual int unparseIdentity(const Message *message, unsigned char *buffer,
unsigned int size, int bigEndian) const;
virtual void updateIdentity(EncodeBuffer &encodeBuffer, const Message *message,
const Message *cachedMessage,
ChannelCache *channelCache) const;
virtual void updateIdentity(DecodeBuffer &decodeBuffer, const Message *message,
ChannelCache *channelCache) const;
virtual void identityChecksum(const Message *message, const unsigned char *buffer,
unsigned int size, int bigEndian) const;
virtual void dumpIdentity(const Message *message) const;
private:
unsigned char opcode_;
//
// Keep pointers to specialized classes.
//
RenderMinorExtensionStore *minors_[RENDEREXTENSION_MINOR_OPCODE_LIMIT];
RenderMinorExtensionStore *generic_;
};
class RenderMinorExtensionStore : public MinorMessageStore
{
public:
virtual const char *name() const = 0;
virtual int identitySize(const unsigned char *buffer, unsigned int size) = 0;
virtual int encodeMessage(EncodeBuffer &encodeBuffer, const unsigned char *buffer,
const unsigned int size, int bigEndian,
ChannelCache *channelCache) const = 0;
virtual int decodeMessage(DecodeBuffer &decodeBuffer, unsigned char *&buffer,
unsigned int &size, unsigned char type, int bigEndian,
WriteBuffer *writeBuffer, ChannelCache *channelCache) const = 0;
virtual int parseIdentity(Message *message, const unsigned char *buffer,
unsigned int size, int bigEndian) const = 0;
virtual int unparseIdentity(const Message *message, unsigned char *buffer,
unsigned int size, int bigEndian) const = 0;
virtual void updateIdentity(EncodeBuffer &encodeBuffer, const Message *message,
const Message *cachedMessage,
ChannelCache *channelCache) const = 0;
virtual void updateIdentity(DecodeBuffer &decodeBuffer, const Message *message,
ChannelCache *channelCache) const = 0;
virtual void identityChecksum(const Message *message, const unsigned char *buffer,
unsigned int size, md5_state_t *md5_state,
int bigEndian) const = 0;
//
// Internal encode and decode utilities.
//
protected:
void encodeLongData(EncodeBuffer &encodeBuffer, const unsigned char *buffer,
unsigned int offset, unsigned int size, int bigEndian,
ChannelCache *channelCache) const;
void encodeIntData(EncodeBuffer &encodeBuffer, const unsigned char *buffer,
unsigned int offset, unsigned int size, int bigEndian,
ChannelCache *channelCache) const;
void encodeCharData(EncodeBuffer &encodeBuffer, const unsigned char *buffer,
unsigned int offset, unsigned int size, int bigEndian,
ChannelCache *channelCache) const;
void decodeLongData(DecodeBuffer &decodeBuffer, unsigned char *buffer,
unsigned int offset, unsigned int size, int bigEndian,
ChannelCache *channelCache) const;
void decodeIntData(DecodeBuffer &decodeBuffer, unsigned char *buffer,
unsigned int offset, unsigned int size, int bigEndian,
ChannelCache *channelCache) const;
void decodeCharData(DecodeBuffer &decodeBuffer, unsigned char *buffer,
unsigned int offset, unsigned int size, int bigEndian,
ChannelCache *channelCache) const;
/*
* The following methods are only used in the
* encoding of the generic render request. To
* be removed in future.
*/
void parseIntData(const Message *message, const unsigned char *buffer,
unsigned int offset, unsigned int size,
int bigEndian) const;
void unparseIntData(const Message *message, unsigned char *buffer,
unsigned int offset, unsigned int size,
int bigEndian) const;
void updateIntData(EncodeBuffer &encodeBuffer, const Message *message,
const Message *cachedMessage, unsigned int offset,
unsigned int size, ChannelCache *channelCache) const;
void updateIntData(DecodeBuffer &decodeBuffer, const Message *message,
unsigned int offset, unsigned int size,
ChannelCache *channelCache) const;
};
#endif /* RenderExtension_H */
|