1 /***********************************************************
3 Copyright 1987, 1998 The Open Group
5 Permission to use, copy, modify, distribute, and sell this software and its
6 documentation for any purpose is hereby granted without fee, provided that
7 the above copyright notice appear in all copies and that both that
8 copyright notice and this permission notice appear in supporting
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 Except as contained in this notice, the name of The Open Group shall not be
22 used in advertising or otherwise to promote the sale, use or other dealings
23 in this Software without prior written authorization from The Open Group.
26 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
30 Permission to use, copy, modify, and distribute this software and its
31 documentation for any purpose and without fee is hereby granted,
32 provided that the above copyright notice appear in all copies and that
33 both that copyright notice and this permission notice appear in
34 supporting documentation, and that the name of Digital not be
35 used in advertising or publicity pertaining to distribution of the
36 software without specific, written prior permission.
38 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
39 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
40 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
41 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
42 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
43 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
46 ******************************************************************/
48 #ifdef HAVE_DIX_CONFIG_H
49 #include <dix-config.h>
55 #include <X11/Xproto.h>
57 #include "dixstruct.h"
58 #include "extnsionst.h"
60 #include "scrnintstr.h"
64 #define EXTENSION_BASE 128
65 #define EXTENSION_EVENT_BASE 64
66 #define LAST_EVENT 128
67 #define LAST_ERROR 255
69 static ExtensionEntry
**extensions
= (ExtensionEntry
**)NULL
;
71 int lastEvent
= EXTENSION_EVENT_BASE
;
72 static int lastError
= FirstExtensionError
;
73 static unsigned int NumExtensions
= 0;
75 extern int extensionPrivateLen
;
76 extern unsigned *extensionPrivateSizes
;
77 extern unsigned totalExtensionSize
;
80 InitExtensionPrivates(ExtensionEntry
*ext
)
88 if (totalExtensionSize
== sizeof(ExtensionEntry
))
89 ppriv
= (DevUnion
*)NULL
;
91 ppriv
= (DevUnion
*)(ext
+ 1);
93 ext
->devPrivates
= ppriv
;
94 sizes
= extensionPrivateSizes
;
95 ptr
= (char *)(ppriv
+ extensionPrivateLen
);
96 for (i
= extensionPrivateLen
; --i
>= 0; ppriv
++, sizes
++)
98 if ( (size
= *sizes
) )
100 ppriv
->ptr
= (pointer
)ptr
;
104 ppriv
->ptr
= (pointer
)NULL
;
108 _X_EXPORT ExtensionEntry
*
109 AddExtension(char *name
, int NumEvents
, int NumErrors
,
110 int (*MainProc
)(ClientPtr c1
),
111 int (*SwappedMainProc
)(ClientPtr c2
),
112 void (*CloseDownProc
)(ExtensionEntry
*e
),
113 unsigned short (*MinorOpcodeProc
)(ClientPtr c3
))
116 ExtensionEntry
*ext
, **newexts
;
118 if (!MainProc
|| !SwappedMainProc
|| !CloseDownProc
|| !MinorOpcodeProc
)
119 return((ExtensionEntry
*) NULL
);
120 if ((lastEvent
+ NumEvents
> LAST_EVENT
) ||
121 (unsigned)(lastError
+ NumErrors
> LAST_ERROR
))
122 return((ExtensionEntry
*) NULL
);
124 ext
= (ExtensionEntry
*) xalloc(totalExtensionSize
);
126 return((ExtensionEntry
*) NULL
);
127 bzero(ext
, totalExtensionSize
);
128 InitExtensionPrivates(ext
);
129 ext
->name
= (char *)xalloc(strlen(name
) + 1);
130 ext
->num_aliases
= 0;
131 ext
->aliases
= (char **)NULL
;
135 return((ExtensionEntry
*) NULL
);
137 strcpy(ext
->name
, name
);
139 newexts
= (ExtensionEntry
**) xrealloc(extensions
,
140 (i
+ 1) * sizeof(ExtensionEntry
*));
145 return((ExtensionEntry
*) NULL
);
148 extensions
= newexts
;
151 ext
->base
= i
+ EXTENSION_BASE
;
152 ext
->CloseDown
= CloseDownProc
;
153 ext
->MinorOpcode
= MinorOpcodeProc
;
154 ProcVector
[i
+ EXTENSION_BASE
] = MainProc
;
155 SwappedProcVector
[i
+ EXTENSION_BASE
] = SwappedMainProc
;
158 ext
->eventBase
= lastEvent
;
159 ext
->eventLast
= lastEvent
+ NumEvents
;
160 lastEvent
+= NumEvents
;
169 ext
->errorBase
= lastError
;
170 ext
->errorLast
= lastError
+ NumErrors
;
171 lastError
+= NumErrors
;
182 _X_EXPORT Bool
AddExtensionAlias(char *alias
, ExtensionEntry
*ext
)
187 aliases
= (char **)xrealloc(ext
->aliases
,
188 (ext
->num_aliases
+ 1) * sizeof(char *));
191 ext
->aliases
= aliases
;
192 name
= (char *)xalloc(strlen(alias
) + 1);
196 ext
->aliases
[ext
->num_aliases
] = name
;
202 FindExtension(char *extname
, int len
)
206 for (i
=0; i
<NumExtensions
; i
++)
208 if ((strlen(extensions
[i
]->name
) == len
) &&
209 !strncmp(extname
, extensions
[i
]->name
, len
))
211 for (j
= extensions
[i
]->num_aliases
; --j
>= 0;)
213 if ((strlen(extensions
[i
]->aliases
[j
]) == len
) &&
214 !strncmp(extname
, extensions
[i
]->aliases
[j
], len
))
219 return ((i
== NumExtensions
) ? -1 : i
);
223 * CheckExtension returns the extensions[] entry for the requested
224 * extension name. Maybe this could just return a Bool instead?
226 _X_EXPORT ExtensionEntry
*
227 CheckExtension(const char *extname
)
231 n
= FindExtension((char*)extname
, strlen(extname
));
233 return extensions
[n
];
239 * Added as part of Xace.
242 GetExtensionEntry(int major
)
244 if (major
< EXTENSION_BASE
)
246 major
-= EXTENSION_BASE
;
247 if (major
>= NumExtensions
)
249 return extensions
[major
];
253 DeclareExtensionSecurity(char *extname
, Bool secure
)
255 int i
= FindExtension(extname
, strlen(extname
));
257 XaceHook(XACE_DECLARE_EXT_SECURE
, extensions
[i
], secure
);
260 _X_EXPORT
unsigned short
261 StandardMinorOpcode(ClientPtr client
)
263 return ((xReq
*)client
->requestBuffer
)->data
;
266 _X_EXPORT
unsigned short
267 MinorOpcodeOfRequest(ClientPtr client
)
271 major
= ((xReq
*)client
->requestBuffer
)->reqType
;
272 if (major
< EXTENSION_BASE
)
274 major
-= EXTENSION_BASE
;
275 if (major
>= NumExtensions
)
277 return (*extensions
[major
]->MinorOpcode
)(client
);
281 CloseDownExtensions(void)
285 for (i
= NumExtensions
- 1; i
>= 0; i
--)
287 (* extensions
[i
]->CloseDown
)(extensions
[i
]);
289 xfree(extensions
[i
]->name
);
290 for (j
= extensions
[i
]->num_aliases
; --j
>= 0;)
291 xfree(extensions
[i
]->aliases
[j
]);
292 xfree(extensions
[i
]->aliases
);
293 xfree(extensions
[i
]);
296 extensions
= (ExtensionEntry
**)NULL
;
297 lastEvent
= EXTENSION_EVENT_BASE
;
298 lastError
= FirstExtensionError
;
302 ProcQueryExtension(ClientPtr client
)
304 xQueryExtensionReply reply
;
306 REQUEST(xQueryExtensionReq
);
308 REQUEST_FIXED_SIZE(xQueryExtensionReq
, stuff
->nbytes
);
310 reply
.type
= X_Reply
;
312 reply
.major_opcode
= 0;
313 reply
.sequenceNumber
= client
->sequence
;
315 if ( ! NumExtensions
)
316 reply
.present
= xFalse
;
319 i
= FindExtension((char *)&stuff
[1], stuff
->nbytes
);
320 if (i
< 0 || !XaceHook(XACE_EXT_ACCESS
, client
, extensions
[i
]))
321 reply
.present
= xFalse
;
324 reply
.present
= xTrue
;
325 reply
.major_opcode
= extensions
[i
]->base
;
326 reply
.first_event
= extensions
[i
]->eventBase
;
327 reply
.first_error
= extensions
[i
]->errorBase
;
330 WriteReplyToClient(client
, sizeof(xQueryExtensionReply
), &reply
);
331 return(client
->noClientException
);
335 ProcListExtensions(ClientPtr client
)
337 xListExtensionsReply reply
;
338 char *bufptr
, *buffer
;
339 int total_length
= 0;
341 REQUEST_SIZE_MATCH(xReq
);
343 reply
.type
= X_Reply
;
344 reply
.nExtensions
= 0;
346 reply
.sequenceNumber
= client
->sequence
;
353 for (i
=0; i
<NumExtensions
; i
++)
355 /* call callbacks to find out whether to show extension */
356 if (!XaceHook(XACE_EXT_ACCESS
, client
, extensions
[i
]))
359 total_length
+= strlen(extensions
[i
]->name
) + 1;
360 reply
.nExtensions
+= 1 + extensions
[i
]->num_aliases
;
361 for (j
= extensions
[i
]->num_aliases
; --j
>= 0;)
362 total_length
+= strlen(extensions
[i
]->aliases
[j
]) + 1;
364 reply
.length
= (total_length
+ 3) >> 2;
365 buffer
= bufptr
= (char *)ALLOCATE_LOCAL(total_length
);
368 for (i
=0; i
<NumExtensions
; i
++)
371 if (!XaceHook(XACE_EXT_ACCESS
, client
, extensions
[i
]))
374 *bufptr
++ = len
= strlen(extensions
[i
]->name
);
375 memmove(bufptr
, extensions
[i
]->name
, len
);
377 for (j
= extensions
[i
]->num_aliases
; --j
>= 0;)
379 *bufptr
++ = len
= strlen(extensions
[i
]->aliases
[j
]);
380 memmove(bufptr
, extensions
[i
]->aliases
[j
], len
);
385 WriteReplyToClient(client
, sizeof(xListExtensionsReply
), &reply
);
388 WriteToClient(client
, total_length
, buffer
);
389 DEALLOCATE_LOCAL(buffer
);
391 return(client
->noClientException
);
394 #ifdef XSERVER_DTRACE
395 void LoadExtensionNames(char **RequestNames
) {
398 for (i
=0; i
<NumExtensions
; i
++) {
399 int r
= extensions
[i
]->base
;
401 if (RequestNames
[r
] == NULL
) {
402 RequestNames
[r
] = strdup(extensions
[i
]->name
);