1 /*
2 * Type definitions and Connection State for the X11 protocol
3 *
4 * James Peterson, 1988
5 *
6 * Copyright (C) 1988 MCC
7 *
8 * Permission to use, copy, modify, distribute, and sell this software and its
9 * documentation for any purpose is hereby granted without fee, provided that
10 * the above copyright notice appear in all copies and that both that
11 * copyright notice and this permission notice appear in supporting
12 * documentation, and that the name of MCC not be used in
13 * advertising or publicity pertaining to distribution of the software without
14 * specific, written prior permission. MCC makes no
15 * representations about the suitability of this software for any purpose. It
16 * is provided "as is" without express or implied warranty.
17 *
18 * MCC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
19 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
20 * EVENT SHALL MCC BE LIABLE FOR ANY SPECIAL, INDIRECT OR
21 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
22 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
23 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
24 * PERFORMANCE OF THIS SOFTWARE.
25 *
26 */
27 /*
28 * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
29 *
30 * Permission is hereby granted, free of charge, to any person obtaining a
31 * copy of this software and associated documentation files (the "Software"),
32 * to deal in the Software without restriction, including without limitation
33 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
34 * and/or sell copies of the Software, and to permit persons to whom the
35 * Software is furnished to do so, subject to the following conditions:
36 *
37 * The above copyright notice and this permission notice (including the next
38 * paragraph) shall be included in all copies or substantial portions of the
39 * Software.
40 *
41 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
42 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
43 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
44 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
45 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
46 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
47 * DEALINGS IN THE SOFTWARE.
48 *
49 */
50
51 #ifndef XSCOPE_X11_H
52 #define XSCOPE_X11_H
53
54 #include <inttypes.h>
55
56 /* Some field contents are constants, not just types */
57
58 #define CONST1(n) CARD8
59 #define CONST2(n) CARD16
60 #define CONST4(n) CARD32
61
62 /* Some field contents define the components of an expression */
63
64 #define DVALUE1(expression) CARD8
65 #define DVALUE2(expression) CARD16
66 #define DVALUE4(expression) CARD32
67
68
69 /* ************************************************************ */
70 /* */
71 /* */
72 /* ************************************************************ */
73
74 /* Built-in Types */
75
76 #define BYTE 1 /* 8-bit value */
77 #define INT8 2 /* 8-bit signed integer */
78 #define INT16 3 /* 16-bit signed integer */
79 #define INT32 4 /* 32-bit signed integer */
80 #define CARD8 5 /* 8-bit unsigned integer */
81 #define CARD16 6 /* 16-bit unsigned integer */
82 #define CARD32 7 /* 32-bit unsigned integer */
83 #define STRING8 8 /* List of CARD8 */
84 #define STRING16 9 /* List of CHAR2B */
85 #define TEXTITEM8 10 /* STRING8 or Font shift */
86 #define TEXTITEM16 11 /* STRING16 or Font shift */
87
88 #define WINDOW 12 /* CARD32 plus 0 = None */
89 #define WINDOWD 13 /* CARD32 plus 0 = PointerWindow, 1 =
90 InputFocus */
91 #define WINDOWNR 14 /* CARD32 plus 0 = None, 1 = PointerRoot */
92
93 #define PIXMAP 15 /* CARD32 plus 0 = None */
94 #define PIXMAPNPR 16 /* CARD32 plus 0 = None, 1 = ParentRelative */
95 #define PIXMAPC 17 /* CARD32 plus 0 = CopyFromParent */
96
97 #define CURSOR 18 /* CARD32 plus 0 = None */
98
99 #define FONT 19 /* CARD32 plus 0 = None */
100
101 #define GCONTEXT 20 /* CARD32 */
102
103 #define COLORMAP 21 /* CARD32 plus 0 = None */
104 #define COLORMAPC 22 /* CARD32 plus 0 = CopyFromParent */
105
106 #define DRAWABLE 23 /* CARD32 */
107 #define FONTABLE 24 /* CARD32 */
108
109 #define ATOM 25 /* CARD32 plus 0 = None */
110 #define ATOMT 26 /* CARD32 plus 0 = AnyPropertyType */
111
112 #define VISUALID 27 /* CARD32 plus 0 = None */
113 #define VISUALIDC 28 /* CARD32 plus 0 = CopyFromParent */
114
115 #define TIMESTAMP 29 /* CARD32 plus 0 as the current time */
116
117 #define RESOURCEID 30 /* CARD32 plus 0 = AllTemporary */
118
119 #define KEYSYM 31 /* CARD32 */
120 #define KEYCODE 32 /* CARD8 */
121 #define KEYCODEA 33 /* CARD8 plus 0 = AnyKey */
122
123 #define BUTTON 34 /* CARD8 */
124 #define BUTTONA 35 /* CARD8 plus 0 = AnyButton */
125
126 #define EVENTFORM 36 /* event format */
127 #define CHAR8 37 /* CARD8 interpreted as a character */
128 #define STR 38 /* String of CHAR8 with preceding length */
129
130 /* ************************************************************ */
131 /* */
132 /* */
133 /* ************************************************************ */
134
135 /* Defined types */
136
137 #define BITGRAVITY 40
138 #define WINGRAVITY 41
139 #define BOOL 42
140 #define HOSTFAMILY 43
141 #define PK_MODE 44
142 #define NO_YES 45
143 #define WINDOWCLASS 46
144 #define BACKSTORE 47
145 #define MAPSTATE 48
146 #define STACKMODE 49
147 #define CIRMODE 50
148 #define CHANGEMODE 51
149 #define GRABSTAT 52
150 #define EVENTMODE 53
151 #define FOCUSAGENT 54
152 #define DIRECT 55
153 #define GCFUNC 56
154 #define LINESTYLE 57
155 #define CAPSTYLE 58
156 #define JOINSTYLE 59
157 #define FILLSTYLE 60
158 #define FILLRULE 61
159 #define SUBWINMODE 62
160 #define ARCMODE 63
161 #define RECTORDER 64
162 #define COORMODE 65
163 #define POLYSHAPE 66
164 #define IMAGEMODE 67
165 #define ALLORNONE 68
166 #define OBJECTCLASS 69
167 #define OFF_ON 70
168 #define INS_DEL 71
169 #define DIS_EN 72
170 #define CLOSEMODE 73
171 #define SAVEMODE 74
172 #define RSTATUS 75
173 #define MOTIONDETAIL 76
174 #define ENTERDETAIL 77
175 #define BUTTONMODE 78
176 #define SCREENFOCUS 79
177 #define VISIBLE 80
178 #define CIRSTAT 81
179 #define PROPCHANGE 82
180 #define CMAPCHANGE 83
181 #define MAPOBJECT 84
182 #define SETofEVENT 85
183 #define SETofPOINTEREVENT 86
184 #define SETofDEVICEEVENT 87
185 #define SETofKEYBUTMASK 88
186 #define SETofKEYMASK 89
187 #define WINDOW_BITMASK 90
188 #define CONFIGURE_BITMASK 91
189 #define GC_BITMASK 92
190 #define KEYBOARD_BITMASK 93
191 #define COLORMASK 94
192 #define CHAR2B 95
193 #define POINT 96
194 #define RECTANGLE 97
195 #define ARC 98
196 #define HOST 99
197 #define TIMECOORD 100
198 #define FONTPROP 101
199 #define CHARINFO 102
200 #define SEGMENT 103
201 #define COLORITEM 104
202 #define RGB 105
203 #define BYTEMODE 110
204 #define BYTEORDER 111
205 #define COLORCLASS 112
206 #define FORMAT 113
207 #define SCREEN 114
208 #define DEPTH 115
209 #define VISUALTYPE 116
210
211 #define REQUEST 117
212 #define REPLY 118
213 #define ERROR 119
214 #define EVENT 120
215
216 #define LBXREQUEST 121
217 #define LBXREPLY 122
218 #define LBXEVENT 123
219 #define LBXERROR 124
220
221 #define NASREQUEST 125
222 #define NASREPLY 126
223 #define NASEVENT 127
224 #define NASERROR 128
225
226 #define WCPREQUEST 129
227 #define WCPREPLY 130
228 #define WCPERROR 131
229
230 #define RENDERREQUEST 132
231 #define RENDERREPLY 133
232 #define RENDERERROR 134
233
234 #define PICTURE 135
235 #define PICTFORMAT 136
236 #define PICTURE_BITMASK 137
237 #define PICTOP 138
238 #define GLYPHSET 139
239 #define RENDERCOLOR 140
240 #define PICTFORMINFO 141
241 #define TRAPEZOID 142
242 #define TRIANGLE 143
243 #define POINTFIXED 144
244 #define FIXED 145
245 #define FILTERALIAS 146
246 #define RENDERTRANSFORM 147
247 #define SUBPIXEL 148
248
249 #define RANDRREQUEST 150
250 #define RANDRREPLY 151
251 #define RANDRERROR 152
252
253 #define MITSHMREQUEST 153
254 #define MITSHMREPLY 154
255 #define MITSHMEVENT 155
256 #define MITSHMERROR 156
257
258 #define BIGREQREQUEST 157
259 #define BIGREQREPLY 158
260
261 #define EXTENSION 159
262
263 #define GLXREQUEST 160
264 #define GLXREPLY 161
265 #define GLXEVENT 162
266 #define GLXERROR 163
267
268 /* More RandR */
269 #define SETofRREVENT 164
270 #define SETofROTATION 165
271 #define SCREENSIZE 166
272 #define REFRESH 167
273 #define SETofMODEFLAG 168
274 #define MODEINFO 169
275 #define MODE 170 /* XID/CARD32 plus 0 = None */
276 #define CRTC 171 /* XID/CARD32 plus 0 = None */
277 #define OUTPUT 172 /* XID/CARD32 plus 0 = None */
278 #define RANDREVENT 173 /* minor event code for RandR event base+1 */
279 #define CONNECTION 174
280 #define SETofPROVIDER_CAPS 175
281
282 #define MaxTypes 256
283
284 /* ************************************************************ */
285 /* */
286 /* */
287 /* ************************************************************ */
288
289 /* Type Definition Table
290
291 Each item in the X11 Protocol has a type. There are about 120
292 different types. We need to be able to print each item in a
293 format and interpretation which is appropriate for the type of
294 that item. To do so, we build a table describing each type.
295 Each type has a name, possibly a list of named values and a
296 procedure which knows how to print that type.
297 */
298
299 /* Types of Types */
300
301 #define BUILTIN 1
302 #define ENUMERATED 2
303 #define SET 3
304 #define RECORD 5
305
306
307 /* Enumerated and Set types need a list of Named Values */
308
309 struct ValueListEntry {
310 struct ValueListEntry *Next;
311 const char *Name;
312 short Type;
313 short Length;
314 long Value;
315 };
316
317 typedef int (*PrintProcType) (const unsigned char *);
318
319 struct TypeDef {
320 const char *Name;
321 short Type; /* BUILTIN, ENUMERATED, SET, or RECORD */
322 struct ValueListEntry *ValueList;
323 PrintProcType PrintProc;
324 };
325
326 typedef struct TypeDef *TYPE;
327
328 extern struct TypeDef TD[MaxTypes];
329
330 /* ************************************************************ */
331 /* */
332 /* */
333 /* ************************************************************ */
334
335 /* declaration of the existance of print routines for the basic types */
336
337 extern int PrintINT8(const unsigned char *buf);
338 extern int PrintINT16(const unsigned char *buf);
339 extern int PrintINT32(const unsigned char *buf);
340 extern int PrintCARD8(const unsigned char *buf);
341 extern int PrintCARD16(const unsigned char *buf);
342 extern int PrintCARD32(const unsigned char *buf);
343 extern int PrintBYTE(const unsigned char *buf);
344 extern int PrintCHAR8(const unsigned char *buf);
345 extern int PrintSTRING16(const unsigned char *buf);
346 extern int PrintTEXTITEM8(const unsigned char *buf);
347 extern int PrintTEXTITEM16(const unsigned char *buf);
348 extern int PrintSTR(const unsigned char *buf);
349 extern int PrintWINDOW(const unsigned char *buf);
350 extern int PrintWINDOWD(const unsigned char *buf);
351 extern int PrintWINDOWNR(const unsigned char *buf);
352 extern int PrintPIXMAP(const unsigned char *buf);
353 extern int PrintPIXMAPNPR(const unsigned char *buf);
354 extern int PrintPIXMAPC(const unsigned char *buf);
355 extern int PrintCURSOR(const unsigned char *buf);
356 extern int PrintFONT(const unsigned char *buf);
357 extern int PrintGCONTEXT(const unsigned char *buf);
358 extern int PrintCOLORMAP(const unsigned char *buf);
359 extern int PrintCOLORMAPC(const unsigned char *buf);
360 extern int PrintDRAWABLE(const unsigned char *buf);
361 extern int PrintFONTABLE(const unsigned char *buf);
362 extern int PrintATOM(const unsigned char *buf);
363 extern int PrintATOMT(const unsigned char *buf);
364 extern int PrintVISUALID(const unsigned char *buf);
365 extern int PrintVISUALIDC(const unsigned char *buf);
366 extern int PrintTIMESTAMP(const unsigned char *buf);
367 extern int PrintRESOURCEID(const unsigned char *buf);
368 extern int PrintKEYSYM(const unsigned char *buf);
369 extern int PrintKEYCODE(const unsigned char *buf);
370 extern int PrintKEYCODEA(const unsigned char *buf);
371 extern int PrintBUTTON(const unsigned char *buf);
372 extern int PrintBUTTONA(const unsigned char *buf);
373 extern int PrintEVENTFORM(const unsigned char *buf);
374 extern int PrintEVENT(const unsigned char *buf);
375 extern int PrintENUMERATED(const unsigned char *buf, short length,
376 struct ValueListEntry *ValueList);
377 extern int PrintSET(const unsigned char *buf, short length,
378 struct ValueListEntry *ValueList);
379
380 /* ************************************************************ */
381 /* */
382 /* */
383 /* ************************************************************ */
384
385 /* Reply Buffer: Pseudo-buffer used to provide the opcode for the
386 request to which this is a reply: Set by DecodeReply
387 and used in the PrintField of the Reply procedure */
388 extern unsigned char RBf[2];
389
390
391 /* Sequence Buffer: Pseudo-buffer used to provide the sequence number for a
392 request: Set by DecodeReply and used in a PrintField of
393 the Request procedure */
394 extern unsigned char SBf[4];
395
396
397 #define PRINTSERVER 5 /* indent output as if it comes from server */
398 #define PRINTCLIENT 1 /* indent output as if it comes from client */
399
400 /* ************************************************************ */
401 /* */
402 /* */
403 /* ************************************************************ */
404
405 /*
406 In general, we are called with a buffer of bytes and are supposed to
407 try to make sense of these bytes according to the X11 protocol. There
408 are two different types of communication: requests from the client to
409 the server and replies/errors/events from the server to the client.
410 We must interpret these two differently.
411
412 Also, we must consider that the bytes on the communication socket may
413 be sent asynchronously in any amount. This means that we must be prepared
414 to read in and save some bytes until we get enough to do something with
415 them. For example, suppose that we get a buffer from a client. We would
416 expect it to be a request. The request may be 24 bytes long. We may find,
417 however, that only 16 bytes have actually arrived -- the other 8 are stuck
418 in a buffer somewhere. We must be prepared to simply hold the 16 bytes we
419 have until more bytes arrive.
420
421 In general, we do two things: we wait for some number of bytes, and
422 then we interpret this set of bytes. To interpret this data we use
423 a modified state machine. We keep two pieces of information:
424
425 (1) the number of bytes that we need
426 (2) what to do with those bytes.
427
428 This last piece of information is the "state" of the interpretation.
429 We keep the state as a pointer to the procedure that is to be executed.
430
431
432 CLIENTS:
433
434 The data going from the client to the x11 server consists of a
435 set-up message followed by an infinite stream of variable length
436 requests.
437
438 Our overall flow is then:
439
440 (a) Wait for 12 bytes.
441 (b) Interpret these first 12 bytes of the set-up message to get the
442 length of the rest of the message.
443 (c) Wait for the rest of the set-up message.
444 (d) Interpret and print the set-up message.
445
446 *** end of set-up phase -- start normal request loop ***
447
448 (e) Wait for 4 bytes.
449 (f) Interpret these 4 bytes to get the length of the rest of the command.
450 (g) Wait for the rest of the command.
451 (h) Interpret and print the command.
452 (i) Go back to step (e).
453
454 SERVERS:
455
456 Again, we have a set-up reply followed by an infinite stream of variable
457 length replies/errors/events.
458
459 Our overall flow is then:
460
461 (a) Wait for 8 bytes.
462 (b) Interpret the 8 bytes to get the length of the rest of the set-up reply.
463 (c) Wait for the rest of the set-up reply.
464 (d) Interpret and print the set-up reply.
465
466 *** end of set-up phase -- start normal reply/error/event loop ***
467
468 We have the following properties of X11 replies, errors, and events:
469
470 Replies: 32 bytes plus a variable amount. Byte 0 is 1.
471 Bytes 2-3 are a sequence number; bytes 4-7 are length (n). The
472 complete length of the reply is 32 + 4 * n.
473
474 Errors: 32 bytes. Byte 0 is 0.
475 Byte 1 is an error code; bytes 2-3 are a sequence number.
476 Bytes 8-9 are a major opcode; byte 10 is a minor opcode.
477
478 Events: 32 bytes. Byte 0 is 2, 3, 4, ....
479
480 Looking at this we have two choices: wait for one byte and then separately
481 wait for replies, errors, and events, or wait for 32 bytes, then separately
482 process each type. We may have to wait for more, in the event of a reply.
483 This latter seems more effective. It appears reply/error/event formats
484 were selected to allow waiting for 32 bytes, and it will allow short packets
485 which are only 32 bytes long, to be processed completely in one step.
486
487 Thus, For normal reply/error/event processing we have
488
489 (e) Wait for 32 bytes.
490 (f) Interpret these 32 bytes. If possible, go back to step (e).
491 (g) If the packet is a reply with bytes 4-7 non-zero, wait for the
492 remainder of the the reply.
493 (h) Interpret and print the longer reply. Go back to step (e).
494
495
496 The similarity in approach to how both the client and server are handled
497 suggests we can use the same control structure to drive the interpretation
498 of both types of communication client->server and server->client.
499 Accordingly, we package up the relevant variables in a ConnState
500 record. The ConnState record contains the buffer of saved bytes (if any),
501 the size and length of this buffer, the number of bytes we are waiting for
502 and what to do when we get them. A separate ConnState record is kept
503 for the client and server.
504
505 In addition, we may have several different client or server connections.
506 Thus we need an array of all the necessary state for each client or server.
507 A client/server is identified with a file descriptor (fd), so we use the
508 fd to identify the client/server and use it as an index into an array of
509 state variables.
510 */
511
512 struct ConnState {
513 unsigned char *SavedBytes;
514 int littleEndian;
515 int bigreqEnabled;
516 long requestLen;
517 long SizeofSavedBytes;
518 long NumberofSavedBytes;
519
520 long NumberofBytesNeeded;
521 long NumberofBytesProcessed;
522 long (*ByteProcessing) (FD fd, const unsigned char *buf, long n);
523
524 long SequenceNumber;
525 };
526
527 #undef CS /* avoid conflicts with Solaris <sys/regset.h> #define of CS */
528 extern struct ConnState *CS;
529
530 typedef struct _Value {
531 struct _Value *next;
532 uint32_t key;
533 int size;
534 uint32_t *values;
535 } ValueRec, *ValuePtr;
536
537 extern ValuePtr GetValueRec(uint32_t key);
538 extern void CreateValueRec(uint32_t key, int size,
539 const uint32_t *def);
540 extern void DeleteValueRec(uint32_t key);
541 extern void SetValueRec(uint32_t key, const unsigned char *control,
542 short clength, short ctype,
543 const unsigned char *values);
544 extern void PrintValueRec(uint32_t key, uint32_t cmask, short ctype);
545
546 /* ************************************************************ */
547 /* */
548 /* */
549 /* ************************************************************ */
550
551 /* we will need to be able to interpret the values stored in the
552 requests as various built-in types. The following routines
553 support the types built into X11 */
554
555 static inline long
pad(long n)556 pad(long n)
557 {
558 /* round up to next multiple of 4 */
559 return ((n + 3) & ~0x3);
560 }
561
562 static inline uint32_t
ILong(const unsigned char buf[])563 ILong(const unsigned char buf[])
564 {
565 /* check for byte-swapping */
566 if (littleEndian)
567 return ((buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0]);
568 return ((buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]);
569 }
570
571 static inline uint16_t
IShort(const unsigned char buf[])572 IShort(const unsigned char buf[])
573 {
574 /* check for byte-swapping */
575 if (littleEndian)
576 return (buf[1] << 8) | buf[0];
577 return ((buf[0] << 8) | buf[1]);
578 }
579
580 static inline uint16_t
IChar2B(const unsigned char buf[])581 IChar2B(const unsigned char buf[])
582 {
583 /* CHAR2B is like an IShort, but not byte-swapped */
584 return ((buf[0] << 8) | buf[1]);
585 }
586
587 static inline uint8_t
IByte(const unsigned char buf[])588 IByte(const unsigned char buf[])
589 {
590 return (buf[0]);
591 }
592
593 static inline Boolean
IBool(const unsigned char buf[])594 IBool(const unsigned char buf[])
595 {
596 if (buf[0] != 0)
597 return (true);
598 else
599 return (false);
600 }
601
602 /* ************************************************************ */
603 /* */
604 /* */
605 /* ************************************************************ */
606
607 /* declaration of the types of some common functions */
608
609
610 extern int PrintString8(const unsigned char *buf, int number, const char *name);
611 extern int PrintString16(const unsigned char *buf, int number,
612 const char *name);
613 extern void PrintTString8(const unsigned char *buf, long number,
614 const char *name);
615 extern void PrintTString16(const unsigned char *buf, long number,
616 const char *name);
617
618 extern long PrintList(const unsigned char *buf, long number, short ListType,
619 const char *name);
620 extern long PrintListSTR(const unsigned char *buf, long number,
621 const char *name);
622
623 extern const char *REQUESTHEADER, *EVENTHEADER, *ERRORHEADER, *REPLYHEADER;
624
625 #define GC_function 0x00000001L
626 #define GC_plane_mask 0x00000002L
627 #define GC_foreground 0x00000004L
628 #define GC_background 0x00000008L
629 #define GC_line_width 0x00000010L
630 #define GC_line_style 0x00000020L
631 #define GC_cap_style 0x00000040L
632 #define GC_join_style 0x00000080L
633 #define GC_fill_style 0x00000100L
634 #define GC_fill_rule 0x00000200L
635 #define GC_tile 0x00000400L
636 #define GC_stipple 0x00000800L
637 #define GC_tile_stipple_x_origin 0x00001000L
638 #define GC_tile_stipple_y_origin 0x00002000L
639 #define GC_font 0x00004000L
640 #define GC_subwindow_mode 0x00008000L
641 #define GC_graphics_exposures 0x00010000L
642 #define GC_clip_x_origin 0x00020000L
643 #define GC_clip_y_origin 0x00040000L
644 #define GC_clip_mask 0x00080000L
645 #define GC_dash_offset 0x00100000L
646 #define GC_dashes 0x00200000L
647 #define GC_arc_mode 0x00400000L
648
649 /* must be called BEFORE printreqlen increments buf */
650 static inline
getreqlen(FD fd,const unsigned char * buf)651 uint32_t getreqlen(FD fd, const unsigned char *buf) {
652 uint32_t reqlen = IShort(&buf[2]);
653
654 /* Check for big request */
655 if (reqlen == 0 && CS[(fd)].bigreqEnabled)
656 reqlen = ILong(&buf[4]);
657
658 return reqlen;
659 }
660
661 /* prints request length, and if the request is a big request, adjusts
662 the buf pointer to skip over the extra large size field */
663 #define printreqlen(buf, fd, dvalue) \
664 do { \
665 if (IShort(&(buf)[2]) == 0 && CS[(fd)].bigreqEnabled) { \
666 printfield (buf, 4, 4, CARD32, "request length"); \
667 buf += 4; \
668 } else { \
669 printfield (buf, 2, 2, CARD16, "request length"); \
670 } \
671 } while (0)
672
673 /* Constant defined in Generic Event Protocol 1.0 for event type */
674 #define Event_Type_Generic 35
675
676 /* Routines for printing the two common forms of error responses */
677 extern void printErrorWithValue(const unsigned char *buf,
678 short FieldType, const char *desc);
679 extern void printErrorNoValue(const unsigned char *buf);
680
681 #endif /* XSCOPE_X11_H */
682