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