swapreq.c revision bbe1b32b
1bbe1b32bSmrg/* $Xorg: swapreq.c,v 1.4 2001/02/09 02:05:43 xorgcvs Exp $ */ 2bbe1b32bSmrg/* 3bbe1b32bSmrg * swapped requests 4bbe1b32bSmrg */ 5bbe1b32bSmrg/* 6bbe1b32bSmrg 7bbe1b32bSmrgCopyright 1990, 1991, 1998 The Open Group 8bbe1b32bSmrg 9bbe1b32bSmrgPermission to use, copy, modify, distribute, and sell this software and its 10bbe1b32bSmrgdocumentation for any purpose is hereby granted without fee, provided that 11bbe1b32bSmrgthe above copyright notice appear in all copies and that both that 12bbe1b32bSmrgcopyright notice and this permission notice appear in supporting 13bbe1b32bSmrgdocumentation. 14bbe1b32bSmrg 15bbe1b32bSmrgThe above copyright notice and this permission notice shall be included in 16bbe1b32bSmrgall copies or substantial portions of the Software. 17bbe1b32bSmrg 18bbe1b32bSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19bbe1b32bSmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20bbe1b32bSmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21bbe1b32bSmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 22bbe1b32bSmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23bbe1b32bSmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24bbe1b32bSmrg 25bbe1b32bSmrgExcept as contained in this notice, the name of The Open Group shall not be 26bbe1b32bSmrgused in advertising or otherwise to promote the sale, use or other dealings 27bbe1b32bSmrgin this Software without prior written authorization from The Open Group. 28bbe1b32bSmrg 29bbe1b32bSmrg * Copyright 1990, 1991 Network Computing Devices; 30bbe1b32bSmrg * Portions Copyright 1987 by Digital Equipment Corporation 31bbe1b32bSmrg * 32bbe1b32bSmrg * Permission to use, copy, modify, distribute, and sell this software and 33bbe1b32bSmrg * its documentation for any purpose is hereby granted without fee, provided 34bbe1b32bSmrg * that the above copyright notice appear in all copies and that both that 35bbe1b32bSmrg * copyright notice and this permission notice appear in supporting 36bbe1b32bSmrg * documentation, and that the names of Network Computing Devices, or Digital 37bbe1b32bSmrg * not be used in advertising or publicity pertaining to distribution 38bbe1b32bSmrg * of the software without specific, written prior permission. 39bbe1b32bSmrg * 40bbe1b32bSmrg * NETWORK COMPUTING DEVICES, AND DIGITAL DISCLAIM ALL WARRANTIES WITH 41bbe1b32bSmrg * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF 42bbe1b32bSmrg * MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL NETWORK COMPUTING DEVICES, 43bbe1b32bSmrg * OR DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL 44bbe1b32bSmrg * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 45bbe1b32bSmrg * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS 46bbe1b32bSmrg * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF 47bbe1b32bSmrg * THIS SOFTWARE. 48bbe1b32bSmrg */ 49bbe1b32bSmrg/* $XFree86: xc/programs/xfs/difs/swapreq.c,v 1.6 2001/06/25 20:40:17 paulo Exp $ */ 50bbe1b32bSmrg 51bbe1b32bSmrg#include <swapreq.h> 52bbe1b32bSmrg 53bbe1b32bSmrg#include <X11/fonts/FSproto.h> 54bbe1b32bSmrg#include "clientstr.h" 55bbe1b32bSmrg#include "globals.h" 56bbe1b32bSmrg#include "dispatch.h" 57bbe1b32bSmrg 58bbe1b32bSmrgvoid 59bbe1b32bSmrgSwapLongs(long *list, unsigned long count) 60bbe1b32bSmrg{ 61bbe1b32bSmrg int n; 62bbe1b32bSmrg register char *longs = (char *)list; 63bbe1b32bSmrg 64bbe1b32bSmrg while (count >= 8) { 65bbe1b32bSmrg swapl(longs + 0, n); 66bbe1b32bSmrg swapl(longs + 4, n); 67bbe1b32bSmrg swapl(longs + 8, n); 68bbe1b32bSmrg swapl(longs + 12, n); 69bbe1b32bSmrg swapl(longs + 16, n); 70bbe1b32bSmrg swapl(longs + 20, n); 71bbe1b32bSmrg swapl(longs + 24, n); 72bbe1b32bSmrg swapl(longs + 28, n); 73bbe1b32bSmrg longs += 32; 74bbe1b32bSmrg count -= 8; 75bbe1b32bSmrg } 76bbe1b32bSmrg if (count != 0) { 77bbe1b32bSmrg do { 78bbe1b32bSmrg swapl(longs, n); 79bbe1b32bSmrg longs += 4; 80bbe1b32bSmrg } while (--count != 0); 81bbe1b32bSmrg } 82bbe1b32bSmrg} 83bbe1b32bSmrg 84bbe1b32bSmrg/* Byte swap a list of shorts */ 85bbe1b32bSmrg 86bbe1b32bSmrgvoid 87bbe1b32bSmrgSwapShorts(short *list, unsigned long count) 88bbe1b32bSmrg{ 89bbe1b32bSmrg register char *shorts = (char *)list; 90bbe1b32bSmrg register int n; 91bbe1b32bSmrg 92bbe1b32bSmrg while (count >= 16) { 93bbe1b32bSmrg swaps(shorts + 0, n); 94bbe1b32bSmrg swaps(shorts + 2, n); 95bbe1b32bSmrg swaps(shorts + 4, n); 96bbe1b32bSmrg swaps(shorts + 6, n); 97bbe1b32bSmrg swaps(shorts + 8, n); 98bbe1b32bSmrg swaps(shorts + 10, n); 99bbe1b32bSmrg swaps(shorts + 12, n); 100bbe1b32bSmrg swaps(shorts + 14, n); 101bbe1b32bSmrg swaps(shorts + 16, n); 102bbe1b32bSmrg swaps(shorts + 18, n); 103bbe1b32bSmrg swaps(shorts + 20, n); 104bbe1b32bSmrg swaps(shorts + 22, n); 105bbe1b32bSmrg swaps(shorts + 24, n); 106bbe1b32bSmrg swaps(shorts + 26, n); 107bbe1b32bSmrg swaps(shorts + 28, n); 108bbe1b32bSmrg swaps(shorts + 30, n); 109bbe1b32bSmrg shorts += 32; 110bbe1b32bSmrg count -= 16; 111bbe1b32bSmrg } 112bbe1b32bSmrg if (count != 0) { 113bbe1b32bSmrg do { 114bbe1b32bSmrg swaps(shorts, n); 115bbe1b32bSmrg shorts += 2; 116bbe1b32bSmrg } while (--count != 0); 117bbe1b32bSmrg } 118bbe1b32bSmrg} 119bbe1b32bSmrg 120bbe1b32bSmrg/* 121bbe1b32bSmrg * used for all requests that have nothing but 'length' swapped 122bbe1b32bSmrg */ 123bbe1b32bSmrgint 124bbe1b32bSmrgSProcSimpleRequest(ClientPtr client) 125bbe1b32bSmrg{ 126bbe1b32bSmrg REQUEST(fsReq); 127bbe1b32bSmrg stuff->length = lswaps(stuff->length); 128bbe1b32bSmrg return ((*ProcVector[stuff->reqType]) (client)); 129bbe1b32bSmrg} 130bbe1b32bSmrg 131bbe1b32bSmrg/* 132bbe1b32bSmrg * used for all requests that have nothing but 'length' & a resource id swapped 133bbe1b32bSmrg */ 134bbe1b32bSmrgint 135bbe1b32bSmrgSProcResourceRequest(ClientPtr client) 136bbe1b32bSmrg{ 137bbe1b32bSmrg REQUEST(fsResourceReq); 138bbe1b32bSmrg stuff->length = lswaps(stuff->length); 139bbe1b32bSmrg stuff->id = lswapl(stuff->id); 140bbe1b32bSmrg return ((*ProcVector[stuff->reqType]) (client)); 141bbe1b32bSmrg} 142bbe1b32bSmrg 143bbe1b32bSmrgstatic int 144bbe1b32bSmrgswap_auth(ClientPtr client, pointer data, int num, int length) 145bbe1b32bSmrg{ 146bbe1b32bSmrg unsigned char *p; 147bbe1b32bSmrg unsigned char t; 148bbe1b32bSmrg CARD16 namelen, 149bbe1b32bSmrg datalen; 150bbe1b32bSmrg int i; 151bbe1b32bSmrg 152bbe1b32bSmrg p = data; 153bbe1b32bSmrg for (i = 0; i < num; i++) { 154bbe1b32bSmrg if (p - (unsigned char *)data > length - 4) { 155bbe1b32bSmrg int lengthword = length; 156bbe1b32bSmrg 157bbe1b32bSmrg SendErrToClient(client, FSBadLength, (pointer)&lengthword); 158bbe1b32bSmrg return (FSBadLength); 159bbe1b32bSmrg } 160bbe1b32bSmrg namelen = *(CARD16 *) p; 161bbe1b32bSmrg t = p[0]; 162bbe1b32bSmrg p[0] = p[1]; 163bbe1b32bSmrg p[1] = t; 164bbe1b32bSmrg p += 2; 165bbe1b32bSmrg datalen = *(CARD16 *) p; 166bbe1b32bSmrg t = p[0]; 167bbe1b32bSmrg p[0] = p[1]; 168bbe1b32bSmrg p[1] = t; 169bbe1b32bSmrg p += 2; 170bbe1b32bSmrg p += (namelen + 3) & ~3; 171bbe1b32bSmrg p += (datalen + 3) & ~3; 172bbe1b32bSmrg } 173bbe1b32bSmrg if (!num) 174bbe1b32bSmrg p += 4; 175bbe1b32bSmrg if (p - (unsigned char *)data != length) { 176bbe1b32bSmrg int lengthword = length; 177bbe1b32bSmrg 178bbe1b32bSmrg SendErrToClient(client, FSBadLength, (pointer)&lengthword); 179bbe1b32bSmrg return (FSBadLength); 180bbe1b32bSmrg } 181bbe1b32bSmrg 182bbe1b32bSmrg return (FSSuccess); 183bbe1b32bSmrg} 184bbe1b32bSmrg 185bbe1b32bSmrgint 186bbe1b32bSmrgSProcCreateAC(ClientPtr client) 187bbe1b32bSmrg{ 188bbe1b32bSmrg int status; 189bbe1b32bSmrg 190bbe1b32bSmrg REQUEST(fsCreateACReq); 191bbe1b32bSmrg stuff->length = lswaps(stuff->length); 192bbe1b32bSmrg stuff->acid = lswapl(stuff->acid); 193bbe1b32bSmrg status = swap_auth(client, (pointer) &stuff[1], 194bbe1b32bSmrg stuff->num_auths, stuff->length); 195bbe1b32bSmrg if (status != FSSuccess) 196bbe1b32bSmrg return (status); 197bbe1b32bSmrg return ((*ProcVector[stuff->reqType]) (client)); 198bbe1b32bSmrg} 199bbe1b32bSmrg 200bbe1b32bSmrgint 201bbe1b32bSmrgSProcSetResolution(ClientPtr client) 202bbe1b32bSmrg{ 203bbe1b32bSmrg REQUEST(fsSetResolutionReq); 204bbe1b32bSmrg stuff->length = lswaps(stuff->length); 205bbe1b32bSmrg stuff->num_resolutions = lswaps(stuff->num_resolutions); 206bbe1b32bSmrg if ((int)stuff->length - (&stuff[1] - &stuff[0]) != 207bbe1b32bSmrg stuff->num_resolutions * sizeof(fsResolution)) 208bbe1b32bSmrg return (FSBadLength); 209bbe1b32bSmrg SwapShorts((short *) &stuff[1], stuff->num_resolutions); 210bbe1b32bSmrg 211bbe1b32bSmrg return ((*ProcVector[stuff->reqType]) (client)); 212bbe1b32bSmrg} 213bbe1b32bSmrg 214bbe1b32bSmrg 215bbe1b32bSmrgint 216bbe1b32bSmrgSProcQueryExtension(ClientPtr client) 217bbe1b32bSmrg{ 218bbe1b32bSmrg REQUEST(fsQueryExtensionReq); 219bbe1b32bSmrg stuff->length = lswaps(stuff->length); 220bbe1b32bSmrg return ((*ProcVector[FS_QueryExtension]) (client)); 221bbe1b32bSmrg} 222bbe1b32bSmrg 223bbe1b32bSmrgint 224bbe1b32bSmrgSProcListCatalogues(ClientPtr client) 225bbe1b32bSmrg{ 226bbe1b32bSmrg REQUEST(fsListCataloguesReq); 227bbe1b32bSmrg stuff->length = lswaps(stuff->length); 228bbe1b32bSmrg stuff->maxNames = lswapl(stuff->maxNames); 229bbe1b32bSmrg stuff->nbytes = lswaps(stuff->nbytes); 230bbe1b32bSmrg return ((*ProcVector[FS_ListCatalogues]) (client)); 231bbe1b32bSmrg} 232bbe1b32bSmrg 233bbe1b32bSmrgint 234bbe1b32bSmrgSProcListFonts(ClientPtr client) 235bbe1b32bSmrg{ 236bbe1b32bSmrg REQUEST(fsListFontsReq); 237bbe1b32bSmrg stuff->length = lswaps(stuff->length); 238bbe1b32bSmrg stuff->maxNames = lswapl(stuff->maxNames); 239bbe1b32bSmrg stuff->nbytes = lswaps(stuff->nbytes); 240bbe1b32bSmrg return ((*ProcVector[FS_ListFonts]) (client)); 241bbe1b32bSmrg} 242bbe1b32bSmrg 243bbe1b32bSmrgint 244bbe1b32bSmrgSProcListFontsWithXInfo(ClientPtr client) 245bbe1b32bSmrg{ 246bbe1b32bSmrg REQUEST(fsListFontsWithXInfoReq); 247bbe1b32bSmrg stuff->length = lswaps(stuff->length); 248bbe1b32bSmrg stuff->maxNames = lswapl(stuff->maxNames); 249bbe1b32bSmrg stuff->nbytes = lswaps(stuff->nbytes); 250bbe1b32bSmrg return ((*ProcVector[FS_ListFontsWithXInfo]) (client)); 251bbe1b32bSmrg} 252bbe1b32bSmrg 253bbe1b32bSmrgint 254bbe1b32bSmrgSProcOpenBitmapFont(ClientPtr client) 255bbe1b32bSmrg{ 256bbe1b32bSmrg REQUEST(fsOpenBitmapFontReq); 257bbe1b32bSmrg stuff->length = lswaps(stuff->length); 258bbe1b32bSmrg stuff->fid = lswapl(stuff->fid); 259bbe1b32bSmrg stuff->format_hint = lswapl(stuff->format_hint); 260bbe1b32bSmrg stuff->format_mask = lswapl(stuff->format_mask); 261bbe1b32bSmrg return ((*ProcVector[FS_OpenBitmapFont]) (client)); 262bbe1b32bSmrg} 263bbe1b32bSmrg 264bbe1b32bSmrgint 265bbe1b32bSmrgSProcQueryXExtents(ClientPtr client) 266bbe1b32bSmrg{ 267bbe1b32bSmrg REQUEST(fsQueryXExtents8Req); /* 8 and 16 are the same here */ 268bbe1b32bSmrg stuff->length = lswaps(stuff->length); 269bbe1b32bSmrg stuff->fid = lswapl(stuff->fid); 270bbe1b32bSmrg stuff->num_ranges = lswapl(stuff->num_ranges); 271bbe1b32bSmrg 272bbe1b32bSmrg return ((*ProcVector[stuff->reqType]) (client)); 273bbe1b32bSmrg} 274bbe1b32bSmrg 275bbe1b32bSmrgint 276bbe1b32bSmrgSProcQueryXBitmaps(ClientPtr client) 277bbe1b32bSmrg{ 278bbe1b32bSmrg REQUEST(fsQueryXBitmaps8Req); /* 8 and 16 are the same here */ 279bbe1b32bSmrg stuff->length = lswaps(stuff->length); 280bbe1b32bSmrg stuff->fid = lswapl(stuff->fid); 281bbe1b32bSmrg stuff->format = lswapl(stuff->format); 282bbe1b32bSmrg stuff->num_ranges = lswapl(stuff->num_ranges); 283bbe1b32bSmrg 284bbe1b32bSmrg return ((*ProcVector[stuff->reqType]) (client)); 285bbe1b32bSmrg} 286bbe1b32bSmrg 287bbe1b32bSmrgint 288bbe1b32bSmrgSwapConnClientPrefix(ClientPtr client, fsConnClientPrefix *pCCP) 289bbe1b32bSmrg{ 290bbe1b32bSmrg REQUEST(fsFakeReq); 291bbe1b32bSmrg 292bbe1b32bSmrg pCCP->major_version = lswaps(pCCP->major_version); 293bbe1b32bSmrg pCCP->minor_version = lswaps(pCCP->minor_version); 294bbe1b32bSmrg pCCP->auth_len = lswaps(pCCP->auth_len); 295bbe1b32bSmrg return (swap_auth(client, (pointer) &pCCP[1], 296bbe1b32bSmrg pCCP->num_auths, stuff->length)); 297bbe1b32bSmrg} 298