xcmisc.c revision 05b261ec
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
51#if 0
52static unsigned char XCMiscCode;
53#endif
54
55static void XCMiscResetProc(
56    ExtensionEntry * /* extEntry */
57);
58
59static DISPATCH_PROC(ProcXCMiscDispatch);
60static DISPATCH_PROC(ProcXCMiscGetVersion);
61static DISPATCH_PROC(ProcXCMiscGetXIDList);
62static DISPATCH_PROC(ProcXCMiscGetXIDRange);
63static DISPATCH_PROC(SProcXCMiscDispatch);
64static DISPATCH_PROC(SProcXCMiscGetVersion);
65static DISPATCH_PROC(SProcXCMiscGetXIDList);
66static DISPATCH_PROC(SProcXCMiscGetXIDRange);
67
68void
69XCMiscExtensionInit(INITARGS)
70{
71#if 0
72    ExtensionEntry *extEntry;
73
74    if ((extEntry = AddExtension(XCMiscExtensionName, 0, 0,
75				ProcXCMiscDispatch, SProcXCMiscDispatch,
76				XCMiscResetProc, StandardMinorOpcode)) != 0)
77	XCMiscCode = (unsigned char)extEntry->base;
78#else
79    (void) AddExtension(XCMiscExtensionName, 0, 0,
80			ProcXCMiscDispatch, SProcXCMiscDispatch,
81			XCMiscResetProc, StandardMinorOpcode);
82#endif
83
84    DeclareExtensionSecurity(XCMiscExtensionName, TRUE);
85}
86
87/*ARGSUSED*/
88static void
89XCMiscResetProc (extEntry)
90    ExtensionEntry	*extEntry;
91{
92}
93
94static int
95ProcXCMiscGetVersion(client)
96    register ClientPtr client;
97{
98    xXCMiscGetVersionReply rep;
99    register int n;
100
101    REQUEST_SIZE_MATCH(xXCMiscGetVersionReq);
102    rep.type = X_Reply;
103    rep.length = 0;
104    rep.sequenceNumber = client->sequence;
105    rep.majorVersion = XCMiscMajorVersion;
106    rep.minorVersion = XCMiscMinorVersion;
107    if (client->swapped) {
108    	swaps(&rep.sequenceNumber, n);
109	swaps(&rep.majorVersion, n);
110	swaps(&rep.minorVersion, n);
111    }
112    WriteToClient(client, sizeof(xXCMiscGetVersionReply), (char *)&rep);
113    return(client->noClientException);
114}
115
116static int
117ProcXCMiscGetXIDRange(client)
118    register ClientPtr client;
119{
120    xXCMiscGetXIDRangeReply rep;
121    register int n;
122    XID min_id, max_id;
123
124    REQUEST_SIZE_MATCH(xXCMiscGetXIDRangeReq);
125    GetXIDRange(client->index, FALSE, &min_id, &max_id);
126    rep.type = X_Reply;
127    rep.length = 0;
128    rep.sequenceNumber = client->sequence;
129    rep.start_id = min_id;
130    rep.count = max_id - min_id + 1;
131    if (client->swapped) {
132    	swaps(&rep.sequenceNumber, n);
133	swapl(&rep.start_id, n);
134	swapl(&rep.count, n);
135    }
136    WriteToClient(client, sizeof(xXCMiscGetXIDRangeReply), (char *)&rep);
137    return(client->noClientException);
138}
139
140static int
141ProcXCMiscGetXIDList(client)
142    register ClientPtr client;
143{
144    REQUEST(xXCMiscGetXIDListReq);
145    xXCMiscGetXIDListReply rep;
146    register int n;
147    XID *pids;
148    unsigned int count;
149
150    REQUEST_SIZE_MATCH(xXCMiscGetXIDListReq);
151
152    if (stuff->count > UINT32_MAX / sizeof(XID))
153	    return BadAlloc;
154
155    pids = (XID *)Xalloc(stuff->count * sizeof(XID));
156    if (!pids)
157    {
158	return BadAlloc;
159    }
160    count = GetXIDList(client, stuff->count, pids);
161    rep.type = X_Reply;
162    rep.sequenceNumber = client->sequence;
163    rep.length = count;
164    rep.count = count;
165    if (client->swapped) {
166    	swaps(&rep.sequenceNumber, n);
167	swapl(&rep.length, n);
168	swapl(&rep.count, n);
169    }
170    WriteToClient(client, sizeof(xXCMiscGetXIDListReply), (char *)&rep);
171    if (count)
172    {
173    	client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write;
174	WriteSwappedDataToClient(client, count * sizeof(XID), pids);
175    }
176    Xfree(pids);
177    return(client->noClientException);
178}
179
180static int
181ProcXCMiscDispatch (client)
182    register ClientPtr	client;
183{
184    REQUEST(xReq);
185    switch (stuff->data)
186    {
187    case X_XCMiscGetVersion:
188	return ProcXCMiscGetVersion(client);
189    case X_XCMiscGetXIDRange:
190	return ProcXCMiscGetXIDRange(client);
191    case X_XCMiscGetXIDList:
192	return ProcXCMiscGetXIDList(client);
193    default:
194	return BadRequest;
195    }
196}
197
198static int
199SProcXCMiscGetVersion(client)
200    register ClientPtr	client;
201{
202    register int n;
203    REQUEST(xXCMiscGetVersionReq);
204
205    swaps(&stuff->length, n);
206    REQUEST_SIZE_MATCH(xXCMiscGetVersionReq);
207    swaps(&stuff->majorVersion, n);
208    swaps(&stuff->minorVersion, n);
209    return ProcXCMiscGetVersion(client);
210}
211
212static int
213SProcXCMiscGetXIDRange(client)
214    register ClientPtr	client;
215{
216    register int n;
217    REQUEST(xReq);
218
219    swaps(&stuff->length, n);
220    return ProcXCMiscGetXIDRange(client);
221}
222
223static int
224SProcXCMiscGetXIDList(client)
225    register ClientPtr	client;
226{
227    register int n;
228    REQUEST(xXCMiscGetXIDListReq);
229
230    swaps(&stuff->length, n);
231    swapl(&stuff->count, n);
232    return ProcXCMiscGetXIDList(client);
233}
234
235static int
236SProcXCMiscDispatch (client)
237    register ClientPtr	client;
238{
239    REQUEST(xReq);
240    switch (stuff->data)
241    {
242    case X_XCMiscGetVersion:
243	return SProcXCMiscGetVersion(client);
244    case X_XCMiscGetXIDRange:
245	return SProcXCMiscGetXIDRange(client);
246    case X_XCMiscGetXIDList:
247	return SProcXCMiscGetXIDList(client);
248    default:
249	return BadRequest;
250    }
251}
252