xcmisc.c revision 4642e01f
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#define NEED_EVENTS 30#define NEED_REPLIES 31#ifdef HAVE_DIX_CONFIG_H 32#include <dix-config.h> 33#endif 34 35#include <X11/X.h> 36#include <X11/Xproto.h> 37#include "misc.h" 38#include "os.h" 39#include "dixstruct.h" 40#include "extnsionst.h" 41#include "swaprep.h" 42#include <X11/extensions/xcmiscstr.h> 43#include "modinit.h" 44 45#if HAVE_STDINT_H 46#include <stdint.h> 47#elif !defined(UINT32_MAX) 48#define UINT32_MAX 0xffffffffU 49#endif 50 51static DISPATCH_PROC(ProcXCMiscDispatch); 52static DISPATCH_PROC(ProcXCMiscGetVersion); 53static DISPATCH_PROC(ProcXCMiscGetXIDList); 54static DISPATCH_PROC(ProcXCMiscGetXIDRange); 55static DISPATCH_PROC(SProcXCMiscDispatch); 56static DISPATCH_PROC(SProcXCMiscGetVersion); 57static DISPATCH_PROC(SProcXCMiscGetXIDList); 58static DISPATCH_PROC(SProcXCMiscGetXIDRange); 59 60void 61XCMiscExtensionInit(INITARGS) 62{ 63 AddExtension(XCMiscExtensionName, 0, 0, 64 ProcXCMiscDispatch, SProcXCMiscDispatch, 65 NULL, StandardMinorOpcode); 66} 67 68static int 69ProcXCMiscGetVersion(client) 70 ClientPtr client; 71{ 72 xXCMiscGetVersionReply rep; 73 int n; 74 75 REQUEST_SIZE_MATCH(xXCMiscGetVersionReq); 76 rep.type = X_Reply; 77 rep.length = 0; 78 rep.sequenceNumber = client->sequence; 79 rep.majorVersion = XCMiscMajorVersion; 80 rep.minorVersion = XCMiscMinorVersion; 81 if (client->swapped) { 82 swaps(&rep.sequenceNumber, n); 83 swaps(&rep.majorVersion, n); 84 swaps(&rep.minorVersion, n); 85 } 86 WriteToClient(client, sizeof(xXCMiscGetVersionReply), (char *)&rep); 87 return(client->noClientException); 88} 89 90static int 91ProcXCMiscGetXIDRange(client) 92 ClientPtr client; 93{ 94 xXCMiscGetXIDRangeReply rep; 95 int n; 96 XID min_id, max_id; 97 98 REQUEST_SIZE_MATCH(xXCMiscGetXIDRangeReq); 99 GetXIDRange(client->index, FALSE, &min_id, &max_id); 100 rep.type = X_Reply; 101 rep.length = 0; 102 rep.sequenceNumber = client->sequence; 103 rep.start_id = min_id; 104 rep.count = max_id - min_id + 1; 105 if (client->swapped) { 106 swaps(&rep.sequenceNumber, n); 107 swapl(&rep.start_id, n); 108 swapl(&rep.count, n); 109 } 110 WriteToClient(client, sizeof(xXCMiscGetXIDRangeReply), (char *)&rep); 111 return(client->noClientException); 112} 113 114static int 115ProcXCMiscGetXIDList(client) 116 ClientPtr client; 117{ 118 REQUEST(xXCMiscGetXIDListReq); 119 xXCMiscGetXIDListReply rep; 120 int n; 121 XID *pids; 122 unsigned int count; 123 124 REQUEST_SIZE_MATCH(xXCMiscGetXIDListReq); 125 126 if (stuff->count > UINT32_MAX / sizeof(XID)) 127 return BadAlloc; 128 129 pids = (XID *)Xalloc(stuff->count * sizeof(XID)); 130 if (!pids) 131 { 132 return BadAlloc; 133 } 134 count = GetXIDList(client, stuff->count, pids); 135 rep.type = X_Reply; 136 rep.sequenceNumber = client->sequence; 137 rep.length = count; 138 rep.count = count; 139 if (client->swapped) { 140 swaps(&rep.sequenceNumber, n); 141 swapl(&rep.length, n); 142 swapl(&rep.count, n); 143 } 144 WriteToClient(client, sizeof(xXCMiscGetXIDListReply), (char *)&rep); 145 if (count) 146 { 147 client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write; 148 WriteSwappedDataToClient(client, count * sizeof(XID), pids); 149 } 150 Xfree(pids); 151 return(client->noClientException); 152} 153 154static int 155ProcXCMiscDispatch (client) 156 ClientPtr client; 157{ 158 REQUEST(xReq); 159 switch (stuff->data) 160 { 161 case X_XCMiscGetVersion: 162 return ProcXCMiscGetVersion(client); 163 case X_XCMiscGetXIDRange: 164 return ProcXCMiscGetXIDRange(client); 165 case X_XCMiscGetXIDList: 166 return ProcXCMiscGetXIDList(client); 167 default: 168 return BadRequest; 169 } 170} 171 172static int 173SProcXCMiscGetVersion(client) 174 ClientPtr client; 175{ 176 int n; 177 REQUEST(xXCMiscGetVersionReq); 178 179 swaps(&stuff->length, n); 180 REQUEST_SIZE_MATCH(xXCMiscGetVersionReq); 181 swaps(&stuff->majorVersion, n); 182 swaps(&stuff->minorVersion, n); 183 return ProcXCMiscGetVersion(client); 184} 185 186static int 187SProcXCMiscGetXIDRange(client) 188 ClientPtr client; 189{ 190 int n; 191 REQUEST(xReq); 192 193 swaps(&stuff->length, n); 194 return ProcXCMiscGetXIDRange(client); 195} 196 197static int 198SProcXCMiscGetXIDList(client) 199 ClientPtr client; 200{ 201 int n; 202 REQUEST(xXCMiscGetXIDListReq); 203 204 swaps(&stuff->length, n); 205 swapl(&stuff->count, n); 206 return ProcXCMiscGetXIDList(client); 207} 208 209static int 210SProcXCMiscDispatch (client) 211 ClientPtr client; 212{ 213 REQUEST(xReq); 214 switch (stuff->data) 215 { 216 case X_XCMiscGetVersion: 217 return SProcXCMiscGetVersion(client); 218 case X_XCMiscGetXIDRange: 219 return SProcXCMiscGetXIDRange(client); 220 case X_XCMiscGetXIDList: 221 return SProcXCMiscGetXIDList(client); 222 default: 223 return BadRequest; 224 } 225} 226