Imported Upstream version 1.15.1
[deb_xorg-server.git] / dix / swaprep.c
CommitLineData
a09e091a
JB
1/************************************************************
2
3Copyright 1987, 1998 The Open Group
4
5Permission to use, copy, modify, distribute, and sell this software and its
6documentation for any purpose is hereby granted without fee, provided that
7the above copyright notice appear in all copies and that both that
8copyright notice and this permission notice appear in supporting
9documentation.
10
11The above copyright notice and this permission notice shall be included in
12all copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
21Except as contained in this notice, the name of The Open Group shall not be
22used in advertising or otherwise to promote the sale, use or other dealings
23in this Software without prior written authorization from The Open Group.
24
25Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
26
27 All Rights Reserved
28
29Permission to use, copy, modify, and distribute this software and its
30documentation for any purpose and without fee is hereby granted,
31provided that the above copyright notice appear in all copies and that
32both that copyright notice and this permission notice appear in
33supporting documentation, and that the name of Digital not be
34used in advertising or publicity pertaining to distribution of the
35software without specific, written prior permission.
36
37DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
38ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
39DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
40ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
41WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
42ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
43SOFTWARE.
44
45********************************************************/
46
47#ifdef HAVE_DIX_CONFIG_H
48#include <dix-config.h>
49#endif
50
51#include <X11/X.h>
52#include <X11/Xproto.h>
53#include "misc.h"
54#include "dixstruct.h"
55#include <X11/fonts/fontstruct.h>
56#include "scrnintstr.h"
57#include "swaprep.h"
58#include "globals.h"
59
60static void SwapFontInfo(xQueryFontReply * pr);
61
62static void SwapCharInfo(xCharInfo * pInfo);
63
64static void SwapFont(xQueryFontReply * pr, Bool hasGlyphs);
65
66/**
67 * Thanks to Jack Palevich for testing and subsequently rewriting all this
68 *
69 * \param size size in bytes
70 */
71void
72Swap32Write(ClientPtr pClient, int size, CARD32 *pbuf)
73{
74 int i;
75
76 size >>= 2;
77 for (i = 0; i < size; i++)
78 /* brackets are mandatory here, because "swapl" macro expands
79 to several statements */
80 {
81 swapl(&pbuf[i]);
82 }
83 WriteToClient(pClient, size << 2, pbuf);
84}
85
86/**
87 *
88 * \param size size in bytes
89 */
90void
91CopySwap32Write(ClientPtr pClient, int size, CARD32 *pbuf)
92{
93 int bufsize = size;
94 CARD32 *pbufT;
95 CARD32 *from, *to, *fromLast, *toLast;
96 CARD32 tmpbuf[1];
97
98 /* Allocate as big a buffer as we can... */
99 while (!(pbufT = malloc(bufsize))) {
100 bufsize >>= 1;
101 if (bufsize == 4) {
102 pbufT = tmpbuf;
103 break;
104 }
105 }
106
107 /* convert lengths from # of bytes to # of longs */
108 size >>= 2;
109 bufsize >>= 2;
110
111 from = pbuf;
112 fromLast = from + size;
113 while (from < fromLast) {
114 int nbytes;
115
116 to = pbufT;
117 toLast = to + min(bufsize, fromLast - from);
118 nbytes = (toLast - to) << 2;
119 while (to < toLast) {
120 /* can't write "cpswapl(*from++, *to++)" because cpswapl is a macro
121 that evaulates its args more than once */
122 cpswapl(*from, *to);
123 from++;
124 to++;
125 }
126 WriteToClient(pClient, nbytes, pbufT);
127 }
128
129 if (pbufT != tmpbuf)
130 free(pbufT);
131}
132
133/**
134 *
135 * \param size size in bytes
136 */
137void
138CopySwap16Write(ClientPtr pClient, int size, short *pbuf)
139{
140 int bufsize = size;
141 short *pbufT;
142 short *from, *to, *fromLast, *toLast;
143 short tmpbuf[2];
144
145 /* Allocate as big a buffer as we can... */
146 while (!(pbufT = malloc(bufsize))) {
147 bufsize >>= 1;
148 if (bufsize == 4) {
149 pbufT = tmpbuf;
150 break;
151 }
152 }
153
154 /* convert lengths from # of bytes to # of shorts */
155 size >>= 1;
156 bufsize >>= 1;
157
158 from = pbuf;
159 fromLast = from + size;
160 while (from < fromLast) {
161 int nbytes;
162
163 to = pbufT;
164 toLast = to + min(bufsize, fromLast - from);
165 nbytes = (toLast - to) << 1;
166 while (to < toLast) {
167 /* can't write "cpswaps(*from++, *to++)" because cpswaps is a macro
168 that evaulates its args more than once */
169 cpswaps(*from, *to);
170 from++;
171 to++;
172 }
173 WriteToClient(pClient, nbytes, pbufT);
174 }
175
176 if (pbufT != tmpbuf)
177 free(pbufT);
178}
179
180/* Extra-small reply */
181void
182SGenericReply(ClientPtr pClient, int size, xGenericReply * pRep)
183{
184 swaps(&pRep->sequenceNumber);
185 WriteToClient(pClient, size, pRep);
186}
187
188/* Extra-large reply */
189void
190SGetWindowAttributesReply(ClientPtr pClient, int size,
191 xGetWindowAttributesReply * pRep)
192{
193 swaps(&pRep->sequenceNumber);
194 swapl(&pRep->length);
195 swapl(&pRep->visualID);
196 swaps(&pRep->class);
197 swapl(&pRep->backingBitPlanes);
198 swapl(&pRep->backingPixel);
199 swapl(&pRep->colormap);
200 swapl(&pRep->allEventMasks);
201 swapl(&pRep->yourEventMask);
202 swaps(&pRep->doNotPropagateMask);
203 WriteToClient(pClient, size, pRep);
204}
205
206void
207SGetGeometryReply(ClientPtr pClient, int size, xGetGeometryReply * pRep)
208{
209 swaps(&pRep->sequenceNumber);
210 swapl(&pRep->root);
211 swaps(&pRep->x);
212 swaps(&pRep->y);
213 swaps(&pRep->width);
214 swaps(&pRep->height);
215 swaps(&pRep->borderWidth);
216 WriteToClient(pClient, size, pRep);
217}
218
219void
220SQueryTreeReply(ClientPtr pClient, int size, xQueryTreeReply * pRep)
221{
222 swaps(&pRep->sequenceNumber);
223 swapl(&pRep->length);
224 swapl(&pRep->root);
225 swapl(&pRep->parent);
226 swaps(&pRep->nChildren);
227 WriteToClient(pClient, size, pRep);
228}
229
230void
231SInternAtomReply(ClientPtr pClient, int size, xInternAtomReply * pRep)
232{
233 swaps(&pRep->sequenceNumber);
234 swapl(&pRep->atom);
235 WriteToClient(pClient, size, pRep);
236}
237
238void
239SGetAtomNameReply(ClientPtr pClient, int size, xGetAtomNameReply * pRep)
240{
241 swaps(&pRep->sequenceNumber);
242 swapl(&pRep->length);
243 swaps(&pRep->nameLength);
244 WriteToClient(pClient, size, pRep);
245}
246
247void
248SGetPropertyReply(ClientPtr pClient, int size, xGetPropertyReply * pRep)
249{
250 swaps(&pRep->sequenceNumber);
251 swapl(&pRep->length);
252 swapl(&pRep->propertyType);
253 swapl(&pRep->bytesAfter);
254 swapl(&pRep->nItems);
255 WriteToClient(pClient, size, pRep);
256}
257
258void
259SListPropertiesReply(ClientPtr pClient, int size, xListPropertiesReply * pRep)
260{
261 swaps(&pRep->sequenceNumber);
262 swapl(&pRep->length);
263 swaps(&pRep->nProperties);
264 WriteToClient(pClient, size, pRep);
265}
266
267void
268SGetSelectionOwnerReply(ClientPtr pClient, int size,
269 xGetSelectionOwnerReply * pRep)
270{
271 swaps(&pRep->sequenceNumber);
272 swapl(&pRep->owner);
273 WriteToClient(pClient, size, pRep);
274}
275
276void
277SQueryPointerReply(ClientPtr pClient, int size, xQueryPointerReply * pRep)
278{
279 swaps(&pRep->sequenceNumber);
280 swapl(&pRep->root);
281 swapl(&pRep->child);
282 swaps(&pRep->rootX);
283 swaps(&pRep->rootY);
284 swaps(&pRep->winX);
285 swaps(&pRep->winY);
286 swaps(&pRep->mask);
287 WriteToClient(pClient, size, pRep);
288}
289
290static void
291SwapTimecoord(xTimecoord * pCoord)
292{
293 swapl(&pCoord->time);
294 swaps(&pCoord->x);
295 swaps(&pCoord->y);
296}
297
298void
299SwapTimeCoordWrite(ClientPtr pClient, int size, xTimecoord * pRep)
300{
301 int i, n;
302 xTimecoord *pRepT;
303
304 n = size / sizeof(xTimecoord);
305 pRepT = pRep;
306 for (i = 0; i < n; i++) {
307 SwapTimecoord(pRepT);
308 pRepT++;
309 }
310 WriteToClient(pClient, size, pRep);
311
312}
313
314void
315SGetMotionEventsReply(ClientPtr pClient, int size, xGetMotionEventsReply * pRep)
316{
317 swaps(&pRep->sequenceNumber);
318 swapl(&pRep->length);
319 swapl(&pRep->nEvents);
320 WriteToClient(pClient, size, pRep);
321}
322
323void
324STranslateCoordsReply(ClientPtr pClient, int size, xTranslateCoordsReply * pRep)
325{
326 swaps(&pRep->sequenceNumber);
327 swapl(&pRep->child);
328 swaps(&pRep->dstX);
329 swaps(&pRep->dstY);
330 WriteToClient(pClient, size, pRep);
331}
332
333void
334SGetInputFocusReply(ClientPtr pClient, int size, xGetInputFocusReply * pRep)
335{
336 swaps(&pRep->sequenceNumber);
337 swapl(&pRep->focus);
338 WriteToClient(pClient, size, pRep);
339}
340
341/* extra long reply */
342void
343SQueryKeymapReply(ClientPtr pClient, int size, xQueryKeymapReply * pRep)
344{
345 swaps(&pRep->sequenceNumber);
346 swapl(&pRep->length);
347 WriteToClient(pClient, size, pRep);
348}
349
350static void
351SwapCharInfo(xCharInfo * pInfo)
352{
353 swaps(&pInfo->leftSideBearing);
354 swaps(&pInfo->rightSideBearing);
355 swaps(&pInfo->characterWidth);
356 swaps(&pInfo->ascent);
357 swaps(&pInfo->descent);
358 swaps(&pInfo->attributes);
359}
360
361static void
362SwapFontInfo(xQueryFontReply * pr)
363{
364 swaps(&pr->minCharOrByte2);
365 swaps(&pr->maxCharOrByte2);
366 swaps(&pr->defaultChar);
367 swaps(&pr->nFontProps);
368 swaps(&pr->fontAscent);
369 swaps(&pr->fontDescent);
370 SwapCharInfo(&pr->minBounds);
371 SwapCharInfo(&pr->maxBounds);
372 swapl(&pr->nCharInfos);
373}
374
375static void
376SwapFont(xQueryFontReply * pr, Bool hasGlyphs)
377{
378 unsigned i;
379 xCharInfo *pxci;
380 unsigned nchars, nprops;
381 char *pby;
382
383 swaps(&pr->sequenceNumber);
384 swapl(&pr->length);
385 nchars = pr->nCharInfos;
386 nprops = pr->nFontProps;
387 SwapFontInfo(pr);
388 pby = (char *) &pr[1];
389 /* Font properties are an atom and either an int32 or a CARD32, so
390 * they are always 2 4 byte values */
391 for (i = 0; i < nprops; i++) {
392 swapl((int *) pby);
393 pby += 4;
394 swapl((int *) pby);
395 pby += 4;
396 }
397 if (hasGlyphs) {
398 pxci = (xCharInfo *) pby;
399 for (i = 0; i < nchars; i++, pxci++)
400 SwapCharInfo(pxci);
401 }
402}
403
404void
405SQueryFontReply(ClientPtr pClient, int size, xQueryFontReply * pRep)
406{
407 SwapFont(pRep, TRUE);
408 WriteToClient(pClient, size, pRep);
409}
410
411void
412SQueryTextExtentsReply(ClientPtr pClient, int size,
413 xQueryTextExtentsReply * pRep)
414{
415 swaps(&pRep->sequenceNumber);
416 swaps(&pRep->fontAscent);
417 swaps(&pRep->fontDescent);
418 swaps(&pRep->overallAscent);
419 swaps(&pRep->overallDescent);
420 swapl(&pRep->overallWidth);
421 swapl(&pRep->overallLeft);
422 swapl(&pRep->overallRight);
423 WriteToClient(pClient, size, pRep);
424}
425
426void
427SListFontsReply(ClientPtr pClient, int size, xListFontsReply * pRep)
428{
429 swaps(&pRep->sequenceNumber);
430 swapl(&pRep->length);
431 swaps(&pRep->nFonts);
432 WriteToClient(pClient, size, pRep);
433}
434
435void
436SListFontsWithInfoReply(ClientPtr pClient, int size,
437 xListFontsWithInfoReply * pRep)
438{
439 SwapFont((xQueryFontReply *) pRep, FALSE);
440 WriteToClient(pClient, size, pRep);
441}
442
443void
444SGetFontPathReply(ClientPtr pClient, int size, xGetFontPathReply * pRep)
445{
446 swaps(&pRep->sequenceNumber);
447 swapl(&pRep->length);
448 swaps(&pRep->nPaths);
449 WriteToClient(pClient, size, pRep);
450}
451
452void
453SGetImageReply(ClientPtr pClient, int size, xGetImageReply * pRep)
454{
455 swaps(&pRep->sequenceNumber);
456 swapl(&pRep->length);
457 swapl(&pRep->visual);
458 WriteToClient(pClient, size, pRep);
459 /* Fortunately, image doesn't need swapping */
460}
461
462void
463SListInstalledColormapsReply(ClientPtr pClient, int size,
464 xListInstalledColormapsReply * pRep)
465{
466 swaps(&pRep->sequenceNumber);
467 swapl(&pRep->length);
468 swaps(&pRep->nColormaps);
469 WriteToClient(pClient, size, pRep);
470}
471
472void
473SAllocColorReply(ClientPtr pClient, int size, xAllocColorReply * pRep)
474{
475 swaps(&pRep->sequenceNumber);
476 swaps(&pRep->red);
477 swaps(&pRep->green);
478 swaps(&pRep->blue);
479 swapl(&pRep->pixel);
480 WriteToClient(pClient, size, pRep);
481}
482
483void
484SAllocNamedColorReply(ClientPtr pClient, int size, xAllocNamedColorReply * pRep)
485{
486 swaps(&pRep->sequenceNumber);
487 swapl(&pRep->pixel);
488 swaps(&pRep->exactRed);
489 swaps(&pRep->exactGreen);
490 swaps(&pRep->exactBlue);
491 swaps(&pRep->screenRed);
492 swaps(&pRep->screenGreen);
493 swaps(&pRep->screenBlue);
494 WriteToClient(pClient, size, pRep);
495}
496
497void
498SAllocColorCellsReply(ClientPtr pClient, int size, xAllocColorCellsReply * pRep)
499{
500 swaps(&pRep->sequenceNumber);
501 swapl(&pRep->length);
502 swaps(&pRep->nPixels);
503 swaps(&pRep->nMasks);
504 WriteToClient(pClient, size, pRep);
505}
506
507void
508SAllocColorPlanesReply(ClientPtr pClient, int size,
509 xAllocColorPlanesReply * pRep)
510{
511 swaps(&pRep->sequenceNumber);
512 swapl(&pRep->length);
513 swaps(&pRep->nPixels);
514 swapl(&pRep->redMask);
515 swapl(&pRep->greenMask);
516 swapl(&pRep->blueMask);
517 WriteToClient(pClient, size, pRep);
518}
519
520static void
521SwapRGB(xrgb * prgb)
522{
523 swaps(&prgb->red);
524 swaps(&prgb->green);
525 swaps(&prgb->blue);
526}
527
528void
529SQColorsExtend(ClientPtr pClient, int size, xrgb * prgb)
530{
531 int i, n;
532 xrgb *prgbT;
533
534 n = size / sizeof(xrgb);
535 prgbT = prgb;
536 for (i = 0; i < n; i++) {
537 SwapRGB(prgbT);
538 prgbT++;
539 }
540 WriteToClient(pClient, size, prgb);
541}
542
543void
544SQueryColorsReply(ClientPtr pClient, int size, xQueryColorsReply * pRep)
545{
546 swaps(&pRep->sequenceNumber);
547 swapl(&pRep->length);
548 swaps(&pRep->nColors);
549 WriteToClient(pClient, size, pRep);
550}
551
552void
553SLookupColorReply(ClientPtr pClient, int size, xLookupColorReply * pRep)
554{
555 swaps(&pRep->sequenceNumber);
556 swaps(&pRep->exactRed);
557 swaps(&pRep->exactGreen);
558 swaps(&pRep->exactBlue);
559 swaps(&pRep->screenRed);
560 swaps(&pRep->screenGreen);
561 swaps(&pRep->screenBlue);
562 WriteToClient(pClient, size, pRep);
563}
564
565void
566SQueryBestSizeReply(ClientPtr pClient, int size, xQueryBestSizeReply * pRep)
567{
568 swaps(&pRep->sequenceNumber);
569 swaps(&pRep->width);
570 swaps(&pRep->height);
571 WriteToClient(pClient, size, pRep);
572}
573
574void
575SListExtensionsReply(ClientPtr pClient, int size, xListExtensionsReply * pRep)
576{
577 swaps(&pRep->sequenceNumber);
578 swapl(&pRep->length);
579 WriteToClient(pClient, size, pRep);
580}
581
582void
583SGetKeyboardMappingReply(ClientPtr pClient, int size,
584 xGetKeyboardMappingReply * pRep)
585{
586 swaps(&pRep->sequenceNumber);
587 swapl(&pRep->length);
588 WriteToClient(pClient, size, pRep);
589}
590
591void
592SGetPointerMappingReply(ClientPtr pClient, int size,
593 xGetPointerMappingReply * pRep)
594{
595 swaps(&pRep->sequenceNumber);
596 swapl(&pRep->length);
597 WriteToClient(pClient, size, pRep);
598}
599
600void
601SGetModifierMappingReply(ClientPtr pClient, int size,
602 xGetModifierMappingReply * pRep)
603{
604 swaps(&pRep->sequenceNumber);
605 swapl(&pRep->length);
606 WriteToClient(pClient, size, pRep);
607}
608
609void
610SGetKeyboardControlReply(ClientPtr pClient, int size,
611 xGetKeyboardControlReply * pRep)
612{
613 swaps(&pRep->sequenceNumber);
614 swapl(&pRep->length);
615 swapl(&pRep->ledMask);
616 swaps(&pRep->bellPitch);
617 swaps(&pRep->bellDuration);
618 WriteToClient(pClient, size, pRep);
619}
620
621void
622SGetPointerControlReply(ClientPtr pClient, int size,
623 xGetPointerControlReply * pRep)
624{
625 swaps(&pRep->sequenceNumber);
626 swaps(&pRep->accelNumerator);
627 swaps(&pRep->accelDenominator);
628 swaps(&pRep->threshold);
629 WriteToClient(pClient, size, pRep);
630}
631
632void
633SGetScreenSaverReply(ClientPtr pClient, int size, xGetScreenSaverReply * pRep)
634{
635 swaps(&pRep->sequenceNumber);
636 swaps(&pRep->timeout);
637 swaps(&pRep->interval);
638 WriteToClient(pClient, size, pRep);
639}
640
641void
642SLHostsExtend(ClientPtr pClient, int size, char *buf)
643{
644 char *bufT = buf;
645 char *endbuf = buf + size;
646
647 while (bufT < endbuf) {
648 xHostEntry *host = (xHostEntry *) bufT;
649 int len = host->length;
650
651 swaps(&host->length);
652 bufT += sizeof(xHostEntry) + pad_to_int32(len);
653 }
654 WriteToClient(pClient, size, buf);
655}
656
657void
658SListHostsReply(ClientPtr pClient, int size, xListHostsReply * pRep)
659{
660 swaps(&pRep->sequenceNumber);
661 swapl(&pRep->length);
662 swaps(&pRep->nHosts);
663 WriteToClient(pClient, size, pRep);
664}
665
666void
667SErrorEvent(xError * from, xError * to)
668{
669 to->type = X_Error;
670 to->errorCode = from->errorCode;
671 cpswaps(from->sequenceNumber, to->sequenceNumber);
672 cpswapl(from->resourceID, to->resourceID);
673 cpswaps(from->minorCode, to->minorCode);
674 to->majorCode = from->majorCode;
675}
676
677void
678SKeyButtonPtrEvent(xEvent *from, xEvent *to)
679{
680 to->u.u.type = from->u.u.type;
681 to->u.u.detail = from->u.u.detail;
682 cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
683 cpswapl(from->u.keyButtonPointer.time, to->u.keyButtonPointer.time);
684 cpswapl(from->u.keyButtonPointer.root, to->u.keyButtonPointer.root);
685 cpswapl(from->u.keyButtonPointer.event, to->u.keyButtonPointer.event);
686 cpswapl(from->u.keyButtonPointer.child, to->u.keyButtonPointer.child);
687 cpswaps(from->u.keyButtonPointer.rootX, to->u.keyButtonPointer.rootX);
688 cpswaps(from->u.keyButtonPointer.rootY, to->u.keyButtonPointer.rootY);
689 cpswaps(from->u.keyButtonPointer.eventX, to->u.keyButtonPointer.eventX);
690 cpswaps(from->u.keyButtonPointer.eventY, to->u.keyButtonPointer.eventY);
691 cpswaps(from->u.keyButtonPointer.state, to->u.keyButtonPointer.state);
692 to->u.keyButtonPointer.sameScreen = from->u.keyButtonPointer.sameScreen;
693}
694
695void
696SEnterLeaveEvent(xEvent *from, xEvent *to)
697{
698 to->u.u.type = from->u.u.type;
699 to->u.u.detail = from->u.u.detail;
700 cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
701 cpswapl(from->u.enterLeave.time, to->u.enterLeave.time);
702 cpswapl(from->u.enterLeave.root, to->u.enterLeave.root);
703 cpswapl(from->u.enterLeave.event, to->u.enterLeave.event);
704 cpswapl(from->u.enterLeave.child, to->u.enterLeave.child);
705 cpswaps(from->u.enterLeave.rootX, to->u.enterLeave.rootX);
706 cpswaps(from->u.enterLeave.rootY, to->u.enterLeave.rootY);
707 cpswaps(from->u.enterLeave.eventX, to->u.enterLeave.eventX);
708 cpswaps(from->u.enterLeave.eventY, to->u.enterLeave.eventY);
709 cpswaps(from->u.enterLeave.state, to->u.enterLeave.state);
710 to->u.enterLeave.mode = from->u.enterLeave.mode;
711 to->u.enterLeave.flags = from->u.enterLeave.flags;
712}
713
714void
715SFocusEvent(xEvent *from, xEvent *to)
716{
717 to->u.u.type = from->u.u.type;
718 to->u.u.detail = from->u.u.detail;
719 cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
720 cpswapl(from->u.focus.window, to->u.focus.window);
721 to->u.focus.mode = from->u.focus.mode;
722}
723
724void
725SExposeEvent(xEvent *from, xEvent *to)
726{
727 to->u.u.type = from->u.u.type;
728 cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
729 cpswapl(from->u.expose.window, to->u.expose.window);
730 cpswaps(from->u.expose.x, to->u.expose.x);
731 cpswaps(from->u.expose.y, to->u.expose.y);
732 cpswaps(from->u.expose.width, to->u.expose.width);
733 cpswaps(from->u.expose.height, to->u.expose.height);
734 cpswaps(from->u.expose.count, to->u.expose.count);
735}
736
737void
738SGraphicsExposureEvent(xEvent *from, xEvent *to)
739{
740 to->u.u.type = from->u.u.type;
741 cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
742 cpswapl(from->u.graphicsExposure.drawable, to->u.graphicsExposure.drawable);
743 cpswaps(from->u.graphicsExposure.x, to->u.graphicsExposure.x);
744 cpswaps(from->u.graphicsExposure.y, to->u.graphicsExposure.y);
745 cpswaps(from->u.graphicsExposure.width, to->u.graphicsExposure.width);
746 cpswaps(from->u.graphicsExposure.height, to->u.graphicsExposure.height);
747 cpswaps(from->u.graphicsExposure.minorEvent,
748 to->u.graphicsExposure.minorEvent);
749 cpswaps(from->u.graphicsExposure.count, to->u.graphicsExposure.count);
750 to->u.graphicsExposure.majorEvent = from->u.graphicsExposure.majorEvent;
751}
752
753void
754SNoExposureEvent(xEvent *from, xEvent *to)
755{
756 to->u.u.type = from->u.u.type;
757 cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
758 cpswapl(from->u.noExposure.drawable, to->u.noExposure.drawable);
759 cpswaps(from->u.noExposure.minorEvent, to->u.noExposure.minorEvent);
760 to->u.noExposure.majorEvent = from->u.noExposure.majorEvent;
761}
762
763void
764SVisibilityEvent(xEvent *from, xEvent *to)
765{
766 to->u.u.type = from->u.u.type;
767 cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
768 cpswapl(from->u.visibility.window, to->u.visibility.window);
769 to->u.visibility.state = from->u.visibility.state;
770}
771
772void
773SCreateNotifyEvent(xEvent *from, xEvent *to)
774{
775 to->u.u.type = from->u.u.type;
776 cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
777 cpswapl(from->u.createNotify.window, to->u.createNotify.window);
778 cpswapl(from->u.createNotify.parent, to->u.createNotify.parent);
779 cpswaps(from->u.createNotify.x, to->u.createNotify.x);
780 cpswaps(from->u.createNotify.y, to->u.createNotify.y);
781 cpswaps(from->u.createNotify.width, to->u.createNotify.width);
782 cpswaps(from->u.createNotify.height, to->u.createNotify.height);
783 cpswaps(from->u.createNotify.borderWidth, to->u.createNotify.borderWidth);
784 to->u.createNotify.override = from->u.createNotify.override;
785}
786
787void
788SDestroyNotifyEvent(xEvent *from, xEvent *to)
789{
790 to->u.u.type = from->u.u.type;
791 cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
792 cpswapl(from->u.destroyNotify.event, to->u.destroyNotify.event);
793 cpswapl(from->u.destroyNotify.window, to->u.destroyNotify.window);
794}
795
796void
797SUnmapNotifyEvent(xEvent *from, xEvent *to)
798{
799 to->u.u.type = from->u.u.type;
800 cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
801 cpswapl(from->u.unmapNotify.event, to->u.unmapNotify.event);
802 cpswapl(from->u.unmapNotify.window, to->u.unmapNotify.window);
803 to->u.unmapNotify.fromConfigure = from->u.unmapNotify.fromConfigure;
804}
805
806void
807SMapNotifyEvent(xEvent *from, xEvent *to)
808{
809 to->u.u.type = from->u.u.type;
810 cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
811 cpswapl(from->u.mapNotify.event, to->u.mapNotify.event);
812 cpswapl(from->u.mapNotify.window, to->u.mapNotify.window);
813 to->u.mapNotify.override = from->u.mapNotify.override;
814}
815
816void
817SMapRequestEvent(xEvent *from, xEvent *to)
818{
819 to->u.u.type = from->u.u.type;
820 cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
821 cpswapl(from->u.mapRequest.parent, to->u.mapRequest.parent);
822 cpswapl(from->u.mapRequest.window, to->u.mapRequest.window);
823}
824
825void
826SReparentEvent(xEvent *from, xEvent *to)
827{
828 to->u.u.type = from->u.u.type;
829 cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
830 cpswapl(from->u.reparent.event, to->u.reparent.event);
831 cpswapl(from->u.reparent.window, to->u.reparent.window);
832 cpswapl(from->u.reparent.parent, to->u.reparent.parent);
833 cpswaps(from->u.reparent.x, to->u.reparent.x);
834 cpswaps(from->u.reparent.y, to->u.reparent.y);
835 to->u.reparent.override = from->u.reparent.override;
836}
837
838void
839SConfigureNotifyEvent(xEvent *from, xEvent *to)
840{
841 to->u.u.type = from->u.u.type;
842 cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
843 cpswapl(from->u.configureNotify.event, to->u.configureNotify.event);
844 cpswapl(from->u.configureNotify.window, to->u.configureNotify.window);
845 cpswapl(from->u.configureNotify.aboveSibling,
846 to->u.configureNotify.aboveSibling);
847 cpswaps(from->u.configureNotify.x, to->u.configureNotify.x);
848 cpswaps(from->u.configureNotify.y, to->u.configureNotify.y);
849 cpswaps(from->u.configureNotify.width, to->u.configureNotify.width);
850 cpswaps(from->u.configureNotify.height, to->u.configureNotify.height);
851 cpswaps(from->u.configureNotify.borderWidth,
852 to->u.configureNotify.borderWidth);
853 to->u.configureNotify.override = from->u.configureNotify.override;
854}
855
856void
857SConfigureRequestEvent(xEvent *from, xEvent *to)
858{
859 to->u.u.type = from->u.u.type;
860 to->u.u.detail = from->u.u.detail; /* actually stack-mode */
861 cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
862 cpswapl(from->u.configureRequest.parent, to->u.configureRequest.parent);
863 cpswapl(from->u.configureRequest.window, to->u.configureRequest.window);
864 cpswapl(from->u.configureRequest.sibling, to->u.configureRequest.sibling);
865 cpswaps(from->u.configureRequest.x, to->u.configureRequest.x);
866 cpswaps(from->u.configureRequest.y, to->u.configureRequest.y);
867 cpswaps(from->u.configureRequest.width, to->u.configureRequest.width);
868 cpswaps(from->u.configureRequest.height, to->u.configureRequest.height);
869 cpswaps(from->u.configureRequest.borderWidth,
870 to->u.configureRequest.borderWidth);
871 cpswaps(from->u.configureRequest.valueMask,
872 to->u.configureRequest.valueMask);
873}
874
875void
876SGravityEvent(xEvent *from, xEvent *to)
877{
878 to->u.u.type = from->u.u.type;
879 cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
880 cpswapl(from->u.gravity.event, to->u.gravity.event);
881 cpswapl(from->u.gravity.window, to->u.gravity.window);
882 cpswaps(from->u.gravity.x, to->u.gravity.x);
883 cpswaps(from->u.gravity.y, to->u.gravity.y);
884}
885
886void
887SResizeRequestEvent(xEvent *from, xEvent *to)
888{
889 to->u.u.type = from->u.u.type;
890 cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
891 cpswapl(from->u.resizeRequest.window, to->u.resizeRequest.window);
892 cpswaps(from->u.resizeRequest.width, to->u.resizeRequest.width);
893 cpswaps(from->u.resizeRequest.height, to->u.resizeRequest.height);
894}
895
896void
897SCirculateEvent(xEvent *from, xEvent *to)
898{
899 to->u.u.type = from->u.u.type;
900 to->u.u.detail = from->u.u.detail;
901 cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
902 cpswapl(from->u.circulate.event, to->u.circulate.event);
903 cpswapl(from->u.circulate.window, to->u.circulate.window);
904 cpswapl(from->u.circulate.parent, to->u.circulate.parent);
905 to->u.circulate.place = from->u.circulate.place;
906}
907
908void
909SPropertyEvent(xEvent *from, xEvent *to)
910{
911 to->u.u.type = from->u.u.type;
912 cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
913 cpswapl(from->u.property.window, to->u.property.window);
914 cpswapl(from->u.property.atom, to->u.property.atom);
915 cpswapl(from->u.property.time, to->u.property.time);
916 to->u.property.state = from->u.property.state;
917}
918
919void
920SSelectionClearEvent(xEvent *from, xEvent *to)
921{
922 to->u.u.type = from->u.u.type;
923 cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
924 cpswapl(from->u.selectionClear.time, to->u.selectionClear.time);
925 cpswapl(from->u.selectionClear.window, to->u.selectionClear.window);
926 cpswapl(from->u.selectionClear.atom, to->u.selectionClear.atom);
927}
928
929void
930SSelectionRequestEvent(xEvent *from, xEvent *to)
931{
932 to->u.u.type = from->u.u.type;
933 cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
934 cpswapl(from->u.selectionRequest.time, to->u.selectionRequest.time);
935 cpswapl(from->u.selectionRequest.owner, to->u.selectionRequest.owner);
936 cpswapl(from->u.selectionRequest.requestor,
937 to->u.selectionRequest.requestor);
938 cpswapl(from->u.selectionRequest.selection,
939 to->u.selectionRequest.selection);
940 cpswapl(from->u.selectionRequest.target, to->u.selectionRequest.target);
941 cpswapl(from->u.selectionRequest.property, to->u.selectionRequest.property);
942}
943
944void
945SSelectionNotifyEvent(xEvent *from, xEvent *to)
946{
947 to->u.u.type = from->u.u.type;
948 cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
949 cpswapl(from->u.selectionNotify.time, to->u.selectionNotify.time);
950 cpswapl(from->u.selectionNotify.requestor, to->u.selectionNotify.requestor);
951 cpswapl(from->u.selectionNotify.selection, to->u.selectionNotify.selection);
952 cpswapl(from->u.selectionNotify.target, to->u.selectionNotify.target);
953 cpswapl(from->u.selectionNotify.property, to->u.selectionNotify.property);
954}
955
956void
957SColormapEvent(xEvent *from, xEvent *to)
958{
959 to->u.u.type = from->u.u.type;
960 cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
961 cpswapl(from->u.colormap.window, to->u.colormap.window);
962 cpswapl(from->u.colormap.colormap, to->u.colormap.colormap);
963 to->u.colormap.new = from->u.colormap.new;
964 to->u.colormap.state = from->u.colormap.state;
965}
966
967void
968SMappingEvent(xEvent *from, xEvent *to)
969{
970 to->u.u.type = from->u.u.type;
971 cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
972 to->u.mappingNotify.request = from->u.mappingNotify.request;
973 to->u.mappingNotify.firstKeyCode = from->u.mappingNotify.firstKeyCode;
974 to->u.mappingNotify.count = from->u.mappingNotify.count;
975}
976
977void
978SClientMessageEvent(xEvent *from, xEvent *to)
979{
980 to->u.u.type = from->u.u.type;
981 to->u.u.detail = from->u.u.detail; /* actually format */
982 cpswaps(from->u.u.sequenceNumber, to->u.u.sequenceNumber);
983 cpswapl(from->u.clientMessage.window, to->u.clientMessage.window);
984 cpswapl(from->u.clientMessage.u.l.type, to->u.clientMessage.u.l.type);
985 switch (from->u.u.detail) {
986 case 8:
987 memmove(to->u.clientMessage.u.b.bytes,
988 from->u.clientMessage.u.b.bytes, 20);
989 break;
990 case 16:
991 cpswaps(from->u.clientMessage.u.s.shorts0,
992 to->u.clientMessage.u.s.shorts0);
993 cpswaps(from->u.clientMessage.u.s.shorts1,
994 to->u.clientMessage.u.s.shorts1);
995 cpswaps(from->u.clientMessage.u.s.shorts2,
996 to->u.clientMessage.u.s.shorts2);
997 cpswaps(from->u.clientMessage.u.s.shorts3,
998 to->u.clientMessage.u.s.shorts3);
999 cpswaps(from->u.clientMessage.u.s.shorts4,
1000 to->u.clientMessage.u.s.shorts4);
1001 cpswaps(from->u.clientMessage.u.s.shorts5,
1002 to->u.clientMessage.u.s.shorts5);
1003 cpswaps(from->u.clientMessage.u.s.shorts6,
1004 to->u.clientMessage.u.s.shorts6);
1005 cpswaps(from->u.clientMessage.u.s.shorts7,
1006 to->u.clientMessage.u.s.shorts7);
1007 cpswaps(from->u.clientMessage.u.s.shorts8,
1008 to->u.clientMessage.u.s.shorts8);
1009 cpswaps(from->u.clientMessage.u.s.shorts9,
1010 to->u.clientMessage.u.s.shorts9);
1011 break;
1012 case 32:
1013 cpswapl(from->u.clientMessage.u.l.longs0,
1014 to->u.clientMessage.u.l.longs0);
1015 cpswapl(from->u.clientMessage.u.l.longs1,
1016 to->u.clientMessage.u.l.longs1);
1017 cpswapl(from->u.clientMessage.u.l.longs2,
1018 to->u.clientMessage.u.l.longs2);
1019 cpswapl(from->u.clientMessage.u.l.longs3,
1020 to->u.clientMessage.u.l.longs3);
1021 cpswapl(from->u.clientMessage.u.l.longs4,
1022 to->u.clientMessage.u.l.longs4);
1023 break;
1024 }
1025}
1026
1027void
1028SKeymapNotifyEvent(xEvent *from, xEvent *to)
1029{
1030 /* Keymap notify events are special; they have no
1031 sequence number field, and contain entirely 8-bit data */
1032 *to = *from;
1033}
1034
1035static void
1036SwapConnSetup(xConnSetup * pConnSetup, xConnSetup * pConnSetupT)
1037{
1038 cpswapl(pConnSetup->release, pConnSetupT->release);
1039 cpswapl(pConnSetup->ridBase, pConnSetupT->ridBase);
1040 cpswapl(pConnSetup->ridMask, pConnSetupT->ridMask);
1041 cpswapl(pConnSetup->motionBufferSize, pConnSetupT->motionBufferSize);
1042 cpswaps(pConnSetup->nbytesVendor, pConnSetupT->nbytesVendor);
1043 cpswaps(pConnSetup->maxRequestSize, pConnSetupT->maxRequestSize);
1044 pConnSetupT->minKeyCode = pConnSetup->minKeyCode;
1045 pConnSetupT->maxKeyCode = pConnSetup->maxKeyCode;
1046 pConnSetupT->numRoots = pConnSetup->numRoots;
1047 pConnSetupT->numFormats = pConnSetup->numFormats;
1048 pConnSetupT->imageByteOrder = pConnSetup->imageByteOrder;
1049 pConnSetupT->bitmapBitOrder = pConnSetup->bitmapBitOrder;
1050 pConnSetupT->bitmapScanlineUnit = pConnSetup->bitmapScanlineUnit;
1051 pConnSetupT->bitmapScanlinePad = pConnSetup->bitmapScanlinePad;
1052}
1053
1054static void
1055SwapWinRoot(xWindowRoot * pRoot, xWindowRoot * pRootT)
1056{
1057 cpswapl(pRoot->windowId, pRootT->windowId);
1058 cpswapl(pRoot->defaultColormap, pRootT->defaultColormap);
1059 cpswapl(pRoot->whitePixel, pRootT->whitePixel);
1060 cpswapl(pRoot->blackPixel, pRootT->blackPixel);
1061 cpswapl(pRoot->currentInputMask, pRootT->currentInputMask);
1062 cpswaps(pRoot->pixWidth, pRootT->pixWidth);
1063 cpswaps(pRoot->pixHeight, pRootT->pixHeight);
1064 cpswaps(pRoot->mmWidth, pRootT->mmWidth);
1065 cpswaps(pRoot->mmHeight, pRootT->mmHeight);
1066 cpswaps(pRoot->minInstalledMaps, pRootT->minInstalledMaps);
1067 cpswaps(pRoot->maxInstalledMaps, pRootT->maxInstalledMaps);
1068 cpswapl(pRoot->rootVisualID, pRootT->rootVisualID);
1069 pRootT->backingStore = pRoot->backingStore;
1070 pRootT->saveUnders = pRoot->saveUnders;
1071 pRootT->rootDepth = pRoot->rootDepth;
1072 pRootT->nDepths = pRoot->nDepths;
1073}
1074
1075static void
1076SwapVisual(xVisualType * pVis, xVisualType * pVisT)
1077{
1078 cpswapl(pVis->visualID, pVisT->visualID);
1079 pVisT->class = pVis->class;
1080 pVisT->bitsPerRGB = pVis->bitsPerRGB;
1081 cpswaps(pVis->colormapEntries, pVisT->colormapEntries);
1082 cpswapl(pVis->redMask, pVisT->redMask);
1083 cpswapl(pVis->greenMask, pVisT->greenMask);
1084 cpswapl(pVis->blueMask, pVisT->blueMask);
1085}
1086
1087void
1088SwapConnSetupInfo(char *pInfo, char *pInfoT)
1089{
1090 int i, j, k;
1091 xConnSetup *pConnSetup = (xConnSetup *) pInfo;
1092 xDepth *depth;
1093 xWindowRoot *root;
1094
1095 SwapConnSetup(pConnSetup, (xConnSetup *) pInfoT);
1096 pInfo += sizeof(xConnSetup);
1097 pInfoT += sizeof(xConnSetup);
1098
1099 /* Copy the vendor string */
1100 i = pad_to_int32(pConnSetup->nbytesVendor);
1101 memcpy(pInfoT, pInfo, i);
1102 pInfo += i;
1103 pInfoT += i;
1104
1105 /* The Pixmap formats don't need to be swapped, just copied. */
1106 i = sizeof(xPixmapFormat) * pConnSetup->numFormats;
1107 memcpy(pInfoT, pInfo, i);
1108 pInfo += i;
1109 pInfoT += i;
1110
1111 for (i = 0; i < pConnSetup->numRoots; i++) {
1112 root = (xWindowRoot *) pInfo;
1113 SwapWinRoot(root, (xWindowRoot *) pInfoT);
1114 pInfo += sizeof(xWindowRoot);
1115 pInfoT += sizeof(xWindowRoot);
1116
1117 for (j = 0; j < root->nDepths; j++) {
1118 depth = (xDepth *) pInfo;
1119 ((xDepth *) pInfoT)->depth = depth->depth;
1120 cpswaps(depth->nVisuals, ((xDepth *) pInfoT)->nVisuals);
1121 pInfo += sizeof(xDepth);
1122 pInfoT += sizeof(xDepth);
1123 for (k = 0; k < depth->nVisuals; k++) {
1124 SwapVisual((xVisualType *) pInfo, (xVisualType *) pInfoT);
1125 pInfo += sizeof(xVisualType);
1126 pInfoT += sizeof(xVisualType);
1127 }
1128 }
1129 }
1130}
1131
1132void
1133WriteSConnectionInfo(ClientPtr pClient, unsigned long size, char *pInfo)
1134{
1135 char *pInfoTBase;
1136
1137 pInfoTBase = malloc(size);
1138 if (!pInfoTBase) {
1139 pClient->noClientException = -1;
1140 return;
1141 }
1142 SwapConnSetupInfo(pInfo, pInfoTBase);
1143 WriteToClient(pClient, (int) size, pInfoTBase);
1144 free(pInfoTBase);
1145}
1146
1147void
1148SwapConnSetupPrefix(xConnSetupPrefix * pcspFrom, xConnSetupPrefix * pcspTo)
1149{
1150 pcspTo->success = pcspFrom->success;
1151 pcspTo->lengthReason = pcspFrom->lengthReason;
1152 cpswaps(pcspFrom->majorVersion, pcspTo->majorVersion);
1153 cpswaps(pcspFrom->minorVersion, pcspTo->minorVersion);
1154 cpswaps(pcspFrom->length, pcspTo->length);
1155}
1156
1157void
1158WriteSConnSetupPrefix(ClientPtr pClient, xConnSetupPrefix * pcsp)
1159{
1160 xConnSetupPrefix cspT;
1161
1162 SwapConnSetupPrefix(pcsp, &cspT);
1163 WriteToClient(pClient, sizeof(cspT), &cspT);
1164}
1165
1166/*
1167 * Dummy entry for ReplySwapVector[]
1168 */
1169
1170void
1171ReplyNotSwappd(ClientPtr pClient, int size, void *pbuf)
1172{
1173 FatalError("Not implemented");
1174}