xcmisc.c revision 9ace9065
1/* 2 3Copyright 1993, 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 12in all copies or substantial portions of the Software. 13 14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR 18OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20OTHER DEALINGS IN THE SOFTWARE. 21 22Except as contained in this notice, the name of The Open Group shall 23not be used in advertising or otherwise to promote the sale, use or 24other dealings in this Software without prior written authorization 25from The Open Group. 26 27*/ 28 29#ifdef HAVE_DIX_CONFIG_H 30#include <dix-config.h> 31#endif 32 33#include <X11/X.h> 34#include <X11/Xproto.h> 35#include "misc.h" 36#include "os.h" 37#include "dixstruct.h" 38#include "extnsionst.h" 39#include "swaprep.h" 40#include <X11/extensions/xcmiscproto.h> 41#include "modinit.h" 42 43#if HAVE_STDINT_H 44#include <stdint.h> 45#elif !defined(UINT32_MAX) 46#define UINT32_MAX 0xffffffffU 47#endif 48 49 50static int 51ProcXCMiscGetVersion(ClientPtr client) 52{ 53 xXCMiscGetVersionReply rep; 54 int n; 55 56 REQUEST_SIZE_MATCH(xXCMiscGetVersionReq); 57 rep.type = X_Reply; 58 rep.length = 0; 59 rep.sequenceNumber = client->sequence; 60 rep.majorVersion = XCMiscMajorVersion; 61 rep.minorVersion = XCMiscMinorVersion; 62 if (client->swapped) { 63 swaps(&rep.sequenceNumber, n); 64 swaps(&rep.majorVersion, n); 65 swaps(&rep.minorVersion, n); 66 } 67 WriteToClient(client, sizeof(xXCMiscGetVersionReply), (char *)&rep); 68 return Success; 69} 70 71static int 72ProcXCMiscGetXIDRange(ClientPtr client) 73{ 74 xXCMiscGetXIDRangeReply rep; 75 int n; 76 XID min_id, max_id; 77 78 REQUEST_SIZE_MATCH(xXCMiscGetXIDRangeReq); 79 GetXIDRange(client->index, FALSE, &min_id, &max_id); 80 rep.type = X_Reply; 81 rep.length = 0; 82 rep.sequenceNumber = client->sequence; 83 rep.start_id = min_id; 84 rep.count = max_id - min_id + 1; 85 if (client->swapped) { 86 swaps(&rep.sequenceNumber, n); 87 swapl(&rep.start_id, n); 88 swapl(&rep.count, n); 89 } 90 WriteToClient(client, sizeof(xXCMiscGetXIDRangeReply), (char *)&rep); 91 return Success; 92} 93 94static int 95ProcXCMiscGetXIDList(ClientPtr client) 96{ 97 REQUEST(xXCMiscGetXIDListReq); 98 xXCMiscGetXIDListReply rep; 99 int n; 100 XID *pids; 101 unsigned int count; 102 103 REQUEST_SIZE_MATCH(xXCMiscGetXIDListReq); 104 105 if (stuff->count > UINT32_MAX / sizeof(XID)) 106 return BadAlloc; 107 108 pids = (XID *)malloc(stuff->count * sizeof(XID)); 109 if (!pids) 110 { 111 return BadAlloc; 112 } 113 count = GetXIDList(client, stuff->count, pids); 114 rep.type = X_Reply; 115 rep.sequenceNumber = client->sequence; 116 rep.length = count; 117 rep.count = count; 118 if (client->swapped) { 119 swaps(&rep.sequenceNumber, n); 120 swapl(&rep.length, n); 121 swapl(&rep.count, n); 122 } 123 WriteToClient(client, sizeof(xXCMiscGetXIDListReply), (char *)&rep); 124 if (count) 125 { 126 client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write; 127 WriteSwappedDataToClient(client, count * sizeof(XID), pids); 128 } 129 free(pids); 130 return Success; 131} 132 133static int 134ProcXCMiscDispatch (ClientPtr client) 135{ 136 REQUEST(xReq); 137 switch (stuff->data) 138 { 139 case X_XCMiscGetVersion: 140 return ProcXCMiscGetVersion(client); 141 case X_XCMiscGetXIDRange: 142 return ProcXCMiscGetXIDRange(client); 143 case X_XCMiscGetXIDList: 144 return ProcXCMiscGetXIDList(client); 145 default: 146 return BadRequest; 147 } 148} 149 150static int 151SProcXCMiscGetVersion(ClientPtr client) 152{ 153 int n; 154 REQUEST(xXCMiscGetVersionReq); 155 156 swaps(&stuff->length, n); 157 REQUEST_SIZE_MATCH(xXCMiscGetVersionReq); 158 swaps(&stuff->majorVersion, n); 159 swaps(&stuff->minorVersion, n); 160 return ProcXCMiscGetVersion(client); 161} 162 163static int 164SProcXCMiscGetXIDRange(ClientPtr client) 165{ 166 int n; 167 REQUEST(xReq); 168 169 swaps(&stuff->length, n); 170 return ProcXCMiscGetXIDRange(client); 171} 172 173static int 174SProcXCMiscGetXIDList(ClientPtr client) 175{ 176 int n; 177 REQUEST(xXCMiscGetXIDListReq); 178 179 swaps(&stuff->length, n); 180 swapl(&stuff->count, n); 181 return ProcXCMiscGetXIDList(client); 182} 183 184static int 185SProcXCMiscDispatch (ClientPtr client) 186{ 187 REQUEST(xReq); 188 switch (stuff->data) 189 { 190 case X_XCMiscGetVersion: 191 return SProcXCMiscGetVersion(client); 192 case X_XCMiscGetXIDRange: 193 return SProcXCMiscGetXIDRange(client); 194 case X_XCMiscGetXIDList: 195 return SProcXCMiscGetXIDList(client); 196 default: 197 return BadRequest; 198 } 199} 200 201void 202XCMiscExtensionInit(INITARGS) 203{ 204 AddExtension(XCMiscExtensionName, 0, 0, 205 ProcXCMiscDispatch, SProcXCMiscDispatch, 206 NULL, StandardMinorOpcode); 207} 208