]> git.sesse.net Git - rdpsrv/blob - Xserver/programs/Xserver/Xext/xcmisc.c
Import X server from vnc-3.3.7.
[rdpsrv] / Xserver / programs / Xserver / Xext / xcmisc.c
1 /* $XConsortium: xcmisc.c /main/5 1996/08/01 19:23:23 dpw $ */
2 /* $XFree86: xc/programs/Xserver/Xext/xcmisc.c,v 3.2 1996/12/23 06:29:03 dawes Exp $ */
3 /*
4
5 Copyright (c) 1993  X Consortium
6
7 Permission is hereby granted, free of charge, to any person obtaining
8 a copy of this software and associated documentation files (the
9 "Software"), to deal in the Software without restriction, including
10 without limitation the rights to use, copy, modify, merge, publish,
11 distribute, sublicense, and/or sell copies of the Software, and to
12 permit persons to whom the Software is furnished to do so, subject to
13 the following conditions:
14
15 The above copyright notice and this permission notice shall be included
16 in all copies or substantial portions of the Software.
17
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
22 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 OTHER DEALINGS IN THE SOFTWARE.
25
26 Except as contained in this notice, the name of the X Consortium shall
27 not be used in advertising or otherwise to promote the sale, use or
28 other dealings in this Software without prior written authorization
29 from the X Consortium.
30
31 */
32
33 #define NEED_EVENTS
34 #define NEED_REPLIES
35 #include "X.h"
36 #include "Xproto.h"
37 #include "misc.h"
38 #include "os.h"
39 #include "dixstruct.h"
40 #include "extnsionst.h"
41 #include "swaprep.h"
42 #include "xcmiscstr.h"
43
44 static unsigned char XCMiscCode;
45
46 static void XCMiscResetProc(
47 #if NeedFunctionPrototypes
48     ExtensionEntry * /* extEntry */
49 #endif
50 );
51
52 static DISPATCH_PROC(ProcXCMiscDispatch);
53 static DISPATCH_PROC(ProcXCMiscGetVersion);
54 static DISPATCH_PROC(ProcXCMiscGetXIDList);
55 static DISPATCH_PROC(ProcXCMiscGetXIDRange);
56 static DISPATCH_PROC(SProcXCMiscDispatch);
57 static DISPATCH_PROC(SProcXCMiscGetVersion);
58 static DISPATCH_PROC(SProcXCMiscGetXIDList);
59 static DISPATCH_PROC(SProcXCMiscGetXIDRange);
60
61 void
62 XCMiscExtensionInit()
63 {
64     ExtensionEntry *extEntry;
65
66     if ((extEntry = AddExtension(XCMiscExtensionName, 0, 0,
67                                 ProcXCMiscDispatch, SProcXCMiscDispatch,
68                                 XCMiscResetProc, StandardMinorOpcode)) != 0)
69         XCMiscCode = (unsigned char)extEntry->base;
70     DeclareExtensionSecurity(XCMiscExtensionName, TRUE);
71 }
72
73 /*ARGSUSED*/
74 static void
75 XCMiscResetProc (extEntry)
76     ExtensionEntry      *extEntry;
77 {
78 }
79
80 static int
81 ProcXCMiscGetVersion(client)
82     register ClientPtr client;
83 {
84     xXCMiscGetVersionReply rep;
85     register int n;
86
87     REQUEST_SIZE_MATCH(xXCMiscGetVersionReq);
88     rep.type = X_Reply;
89     rep.length = 0;
90     rep.sequenceNumber = client->sequence;
91     rep.majorVersion = XCMiscMajorVersion;
92     rep.minorVersion = XCMiscMinorVersion;
93     if (client->swapped) {
94         swaps(&rep.sequenceNumber, n);
95         swaps(&rep.majorVersion, n);
96         swaps(&rep.minorVersion, n);
97     }
98     WriteToClient(client, sizeof(xXCMiscGetVersionReply), (char *)&rep);
99     return(client->noClientException);
100 }
101
102 static int
103 ProcXCMiscGetXIDRange(client)
104     register ClientPtr client;
105 {
106     xXCMiscGetXIDRangeReply rep;
107     register int n;
108     XID min_id, max_id;
109
110     REQUEST_SIZE_MATCH(xXCMiscGetXIDRangeReq);
111     GetXIDRange(client->index, FALSE, &min_id, &max_id);
112     rep.type = X_Reply;
113     rep.length = 0;
114     rep.sequenceNumber = client->sequence;
115     rep.start_id = min_id;
116     rep.count = max_id - min_id + 1;
117     if (client->swapped) {
118         swaps(&rep.sequenceNumber, n);
119         swapl(&rep.start_id, n);
120         swapl(&rep.count, n);
121     }
122     WriteToClient(client, sizeof(xXCMiscGetXIDRangeReply), (char *)&rep);
123     return(client->noClientException);
124 }
125
126 static int
127 ProcXCMiscGetXIDList(client)
128     register ClientPtr client;
129 {
130     REQUEST(xXCMiscGetXIDListReq);
131     xXCMiscGetXIDListReply rep;
132     register int n;
133     XID *pids;
134     unsigned int count;
135
136     REQUEST_SIZE_MATCH(xXCMiscGetXIDListReq);
137
138     pids = (XID *)ALLOCATE_LOCAL(stuff->count * sizeof(XID));
139     if (!pids)
140     {
141         return BadAlloc;
142     }
143     count = GetXIDList(client, stuff->count, pids);
144     rep.type = X_Reply;
145     rep.sequenceNumber = client->sequence;
146     rep.length = count;
147     rep.count = count;
148     if (client->swapped) {
149         swaps(&rep.sequenceNumber, n);
150         swapl(&rep.length, n);
151         swapl(&rep.count, n);
152     }
153     WriteToClient(client, sizeof(xXCMiscGetXIDListReply), (char *)&rep);
154     if (count)
155     {
156         client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write;
157         WriteSwappedDataToClient(client, count * sizeof(XID), pids);
158     }
159     DEALLOCATE_LOCAL(pids);
160     return(client->noClientException);
161 }
162
163 static int
164 ProcXCMiscDispatch (client)
165     register ClientPtr  client;
166 {
167     REQUEST(xReq);
168     switch (stuff->data)
169     {
170     case X_XCMiscGetVersion:
171         return ProcXCMiscGetVersion(client);
172     case X_XCMiscGetXIDRange:
173         return ProcXCMiscGetXIDRange(client);
174     case X_XCMiscGetXIDList:
175         return ProcXCMiscGetXIDList(client);
176     default:
177         return BadRequest;
178     }
179 }
180
181 static int
182 SProcXCMiscGetVersion(client)
183     register ClientPtr  client;
184 {
185     register int n;
186     REQUEST(xXCMiscGetVersionReq);
187
188     swaps(&stuff->length, n);
189     REQUEST_SIZE_MATCH(xXCMiscGetVersionReq);
190     swaps(&stuff->majorVersion, n);
191     swaps(&stuff->minorVersion, n);
192     return ProcXCMiscGetVersion(client);
193 }
194
195 static int
196 SProcXCMiscGetXIDRange(client)
197     register ClientPtr  client;
198 {
199     register int n;
200     REQUEST(xReq);
201
202     swaps(&stuff->length, n);
203     return ProcXCMiscGetXIDRange(client);
204 }
205
206 static int
207 SProcXCMiscGetXIDList(client)
208     register ClientPtr  client;
209 {
210     register int n;
211     REQUEST(xXCMiscGetXIDListReq);
212
213     swaps(&stuff->length, n);
214     swapl(&stuff->count, n);
215     return ProcXCMiscGetXIDList(client);
216 }
217
218 static int
219 SProcXCMiscDispatch (client)
220     register ClientPtr  client;
221 {
222     REQUEST(xReq);
223     switch (stuff->data)
224     {
225     case X_XCMiscGetVersion:
226         return SProcXCMiscGetVersion(client);
227     case X_XCMiscGetXIDRange:
228         return SProcXCMiscGetXIDRange(client);
229     case X_XCMiscGetXIDList:
230         return SProcXCMiscGetXIDList(client);
231     default:
232         return BadRequest;
233     }
234 }