-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcap.c
More file actions
392 lines (362 loc) · 8.4 KB
/
cap.c
File metadata and controls
392 lines (362 loc) · 8.4 KB
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
#include <u.h>
#include <libc.h>
#include "dat.h"
#include "fns.h"
enum /* 2.2.7 Capability Sets; T.128 */
{
CapGeneral= 1,
CapBitmap= 2,
CapOrder= 3,
CapPointer= 8,
CapSound= 12,
CapInput= 13,
CapGlyph= 16,
CapBitcache2= 19,
CapVChan= 20,
/* 2.2.7.1.1 General Capability Set (TS_GENERAL_CAPABILITYSET) */
CanFastpath= 0x0001,
NoBitcomphdr= 0x0400,
CanLongcred= 0x0004,
};
static int putncap(uchar*,uint,Caps*);
static int putbitcaps(uchar*,uint,Caps*);
static int putgencaps(uchar*,uint,Caps*);
static int putordcaps(uchar*,uint,Caps*);
static int putbc2caps(uchar*,uint,Caps*);
static int putptrcaps(uchar*,uint,Caps*);
static int putinpcaps(uchar*,uint,Caps*);
static int putsndcaps(uchar*,uint,Caps*);
static int putglycaps(uchar*,uint,Caps*);
static int putvccaps(uchar*,uint,Caps*);
static
struct {
int size;
int (*putcap)(uchar*,uint,Caps*);
} ctab[]=
{
{ 4, putncap },
{ 24, putgencaps },
{ 30, putbitcaps },
{ 88, putordcaps },
{ 40, putbc2caps },
{ 8, putptrcaps },
{ 88, putinpcaps },
{ 8, putsndcaps },
{ 8, putvccaps },
{ 52, putglycaps },
};
int
getcaps(Caps* caps, uchar* a, uint nb)
{
int ncap, type, len;
uchar *p, *ep;
int extraFlags;
p = a;
ep = p+nb;
memset(caps, 0, sizeof(*caps));
ncap = GSHORT(p);
p += 4;
for(; ncap>0 && p+4<ep; ncap--){
type = GSHORT(p+0);
len = GSHORT(p+2);
if(p+len > ep){
werrstr("bad length in server's capability set");
return -1;
}
switch(type){
case CapGeneral:
/* 2.2.7.1.1 General Capability Set (TS_GENERAL_CAPABILITYSET) */
if(len < 24){
werrstr(Eshort);
return -1;
}
caps->general = 1;
extraFlags = GSHORT(p+14);
caps->canrefresh = p[22];
caps->cansupress = p[23];
USED(extraFlags);
break;
case CapBitmap:
/* 2.2.7.1.2 Bitmap Capability Set (TS_BITMAP_CAPABILITYSET) */
if(len < 16){
werrstr(Eshort);
return -1;
}
caps->bitmap = 1;
caps->depth = GSHORT(p+4);
caps->xsz = GSHORT(p+12);
caps->ysz = GSHORT(p+14);
break;
}
p += len;
}
return p-a;
}
int
sizecaps(Caps* caps)
{
int i, n;
USED(caps);
n = 0;
for(i = 0; i < nelem(ctab); i++)
n += ctab[i].size;
return n;
}
int
putcaps(uchar* a, uint nb, Caps* caps)
{
uchar *p, *ep;
int i, n;
p = a;
ep = a+nb;
for(i = 0; i < nelem(ctab); i++){
n = ctab[i].putcap(p, ep-p, caps);
if(n < 0)
return -1;
p += n;
}
return p-a;
}
static int
putncap(uchar *p, uint nb, Caps* caps)
{
int ncap;
USED(caps);
ncap = 8;
if(nb<4){
werrstr(Eshort);
return -1;
}
PSHORT(p, ncap);
PSHORT(p+2, 0);
return 4;
}
/* 2.2.7.1.1 General Capability Set (TS_GENERAL_CAPABILITYSET) */
static int
putgencaps(uchar *p, uint nb, Caps* caps)
{
int extraFlags;
USED(caps);
extraFlags = 0
| CanFastpath
| NoBitcomphdr
| CanLongcred
;
if(nb<24){
werrstr(Eshort);
return -1;
}
PSHORT(p+0, CapGeneral);
PSHORT(p+2, 24); // size
PSHORT(p+4, 0); // OSMAJORTYPE_UNSPECIFIED
PSHORT(p+6, 0); // OSMINORTYPE_UNSPECIFIED
PSHORT(p+8, 0x200); // TS_CAPS_PROTOCOLVERSION
PSHORT(p+10, 0); // pad2octetsA
PSHORT(p+12, 0); // generalCompressionTypes
PSHORT(p+14, extraFlags);
PSHORT(p+16, 0); // updateCapabilityFlag
PSHORT(p+18, 0); // remoteUnshareFlag
PSHORT(p+20, 0); // generalCompressionLevel
p[22] = 0; // refreshRectSupport - server only
p[23] = 0; // suppressOutputSupport - server only
return 24;
}
/* 2.2.7.1.2 Bitmap Capability Set (TS_BITMAP_CAPABILITYSET) */
static int
putbitcaps(uchar *p, uint nb, Caps* caps)
{
if(nb < 30){
werrstr(Eshort);
return -1;
}
PSHORT(p+0, CapBitmap);
PSHORT(p+2, 30); // size
PSHORT(p+4, caps->depth); // preferredBitsPerPixel
PSHORT(p+6, 1); // receive1BitPerPixel
PSHORT(p+8, 1); // receive4BitsPerPixel
PSHORT(p+10, 1); // receive8BitsPerPixel
PSHORT(p+12, caps->xsz); // desktopWidth
PSHORT(p+14, caps->ysz); // desktopHeight
PSHORT(p+16, 0); // pad2octets
PSHORT(p+18, 1); // desktopResizeFlag
PSHORT(p+20, 1); // bitmapCompressionFlag
PSHORT(p+22, 0); // highColorFlags
PSHORT(p+24, 1); // drawingFlags
PSHORT(p+26, 1); // multipleRectangleSupport
PSHORT(p+28, 0); // pad2octetsB
return 30;
}
/* 2.2.7.1.3 Order Capability Set (TS_ORDER_CAPABILITYSET) */
static int
putordcaps(uchar *p, uint nb, Caps* caps)
{
ushort orderFlags;
enum
{
NEGOTIATEORDERSUPPORT= 0x02,
ZEROBOUNDSDELTASSUPPORT= 0x08,
COLORINDEXSUPPORT= 0x20,
SOLIDPATTERNBRUSHONLY= 0x40,
};
USED(caps);
orderFlags = 0
| NEGOTIATEORDERSUPPORT
| ZEROBOUNDSDELTASSUPPORT
| COLORINDEXSUPPORT
| SOLIDPATTERNBRUSHONLY
;
if(nb<88){
werrstr(Eshort);
return -1;
}
PSHORT(p+0, CapOrder);
PSHORT(p+2, 88); // size
memset(p+4, 0, 16); // terminalDescriptor
PLONG(p+20, 0); // pad4octetsA
PSHORT(p+24, 1); // desktopSaveXGranularity
PSHORT(p+26, 20); // desktopSaveYGranularity
PSHORT(p+28, 0); // pad2octetsA
PSHORT(p+30, 1); // maximumOrderLevel
PSHORT(p+32, 0); // numberFonts
PSHORT(p+34, orderFlags);
memcpy(p+36, orderSupport, 32);
PSHORT(p+68, 0x6a1); // textFlags
PSHORT(p+70, 0); // orderSupportExFlags
PLONG(p+72, 0); // pad4octetsB
PLONG(p+76, 480*480); // desktopSaveSize
PSHORT(p+80, 0); // pad2octetsC
PSHORT(p+82, 0); // pad2octetsD
PSHORT(p+84, 0xe4); // textANSICodePage
PSHORT(p+86, 0x04); // pad2octetsE
return 88;
}
/* 2.2.7.1.4 Bitmap Cache Capability Set (TS_BITMAPCACHE_CAPABILITYSET) */
/* 2.2.7.1.4.2 Revision 2 (TS_BITMAPCACHE_CAPABILITYSET_REV2) */
static int
putbc2caps(uchar *p, uint nb, Caps* caps)
{
USED(caps);
if(nb<40){
werrstr(Eshort);
return -1;
}
PSHORT(p+0, CapBitcache2);
PSHORT(p+2, 40); // size
PSHORT(p+4, 0); // CacheFlags (2 bytes):
p[6] = 0; // pad2
p[7] = 3; // NumCellCaches
PLONG(p+8, 120); // BitmapCache0CellInfo
PLONG(p+12, 120); // BitmapCache1CellInfo
PLONG(p+16, 336); // BitmapCache2CellInfo
PLONG(p+20, 0); // BitmapCache3CellInfo
PLONG(p+24, 0); // BitmapCache4CellInfo
memset(p+28, 0, 12); // Pad3
return 40;
}
/* 2.2.7.1.5 Pointer Capability Set (TS_POINTER_CAPABILITYSET) */
static int
putptrcaps(uchar *p, uint nb, Caps* caps)
{
USED(caps);
if(nb<8){
werrstr(Eshort);
return -1;
}
PSHORT(p+0, CapPointer);
PSHORT(p+2, 8); // size
PSHORT(p+4, 0); // colorPointerFlag
PSHORT(p+6, 20); // colorPointerCacheSize
return 8;
}
/* 2.2.7.1.6 Input Capability Set (TS_INPUT_CAPABILITYSET) */
static int
putinpcaps(uchar *p, uint nb, Caps* caps)
{
long inputFlags;
USED(caps);
enum
{
INPUT_FLAG_SCANCODES= 0x0001,
INPUT_FLAG_MOUSEX= 0x0004,
INPUT_FLAG_FASTPATH_INPUT= 0x0008,
INPUT_FLAG_UNICODE= 0x0010,
INPUT_FLAG_FASTPATH_INPUT2= 0x0020,
};
inputFlags = 0
| INPUT_FLAG_SCANCODES
| INPUT_FLAG_UNICODE
;
if(nb<88){
werrstr(Eshort);
return -1;
}
PSHORT(p+0, CapInput);
PSHORT(p+2, 88); // size
PSHORT(p+4, inputFlags); // inputFlags
PSHORT(p+6, 0); // pad2octetsA
// the below SHOULD be the same as in the Client Core Data (section 2.2.1.3.2).
PLONG(p+8, 0x409); // keyboardLayout
PLONG(p+12, 4); // keyboardType: IBM enhanced (101- or 102-key)
PLONG(p+16, 0); // keyboardSubType
PLONG(p+20, 12); // keyboardFunctionKey
memset(p+24, 0, 64); // imeFileName
return 88;
}
/* 2.2.7.1.8 Glyph Cache Capability Set (TS_GLYPHCACHE_CAPABILITYSET) */
static int
putglycaps(uchar *p, uint nb, Caps* caps)
{
enum {
GLYPH_SUPPORT_NONE= 0,
};
USED(caps);
if(nb<52){
werrstr(Eshort);
return -1;
}
PSHORT(p+0, CapGlyph);
PSHORT(p+2, 52); // size
PLONG(p+4, 0x0400fe); // GlyphCache 0
PLONG(p+8, 0x0400fe); // GlyphCache 1
PLONG(p+12, 0x0800fe); // GlyphCache 2
PLONG(p+16, 0x0800fe); // GlyphCache 3
PLONG(p+20, 0x1000fe); // GlyphCache 4
PLONG(p+24, 0x2000fe); // GlyphCache 5
PLONG(p+28, 0x4000fe); // GlyphCache 6
PLONG(p+32, 0x8000fe); // GlyphCache 7
PLONG(p+36, 0x10000fe); // GlyphCache 8
PLONG(p+40, 0x8000040); // GlyphCache 9
PLONG(p+44, 0x01000100); // FragCache
PSHORT(p+48, GLYPH_SUPPORT_NONE); // GlyphSupportLevel
PSHORT(p+50, 0); // pad2octets
return 52;
}
/* 2.2.7.1.11 Sound Capability Set (TS_SOUND_CAPABILITYSET) */
static int
putsndcaps(uchar *p, uint nb, Caps* caps)
{
USED(caps);
if(nb<8){
werrstr(Eshort);
return -1;
}
PSHORT(p+0, CapSound);
PSHORT(p+2, 8); // size
PSHORT(p+4, 0); // soundFlags
PSHORT(p+6, 0); // pad2octetsA
return 8;
}
/* 2.2.7.1.10 Virtual Channel Capability Set (TS_VIRTUALCHANNEL_CAPABILITYSET) */
static int
putvccaps(uchar *p, uint nb, Caps* caps)
{
USED(caps);
if(nb<8){
werrstr(Eshort);
return -1;
}
PSHORT(p+0, CapVChan);
PSHORT(p+2, 8); // size
PLONG(p+4, 0); // flags: 0=vchan compression not supported
return 8;
}