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.
25 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
29 Permission to use, copy, modify, and distribute this software and its
30 documentation for any purpose and without fee is hereby granted,
31 provided that the above copyright notice appear in all copies and that
32 both that copyright notice and this permission notice appear in
33 supporting documentation, and that the name of Digital not be
34 used in advertising or publicity pertaining to distribution of the
35 software without specific, written prior permission.
37 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
38 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
39 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
40 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
41 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
42 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
45 ******************************************************************/
47 #ifdef HAVE_DIX_CONFIG_H
48 #include <dix-config.h>
52 #include <X11/Xproto.h>
54 #include "dixstruct.h"
55 #include "extnsionst.h"
57 #include "scrnintstr.h"
63 #define LAST_ERROR 255
65 static ExtensionEntry
**extensions
= (ExtensionEntry
**) NULL
;
67 int lastEvent
= EXTENSION_EVENT_BASE
;
68 static int lastError
= FirstExtensionError
;
69 static unsigned int NumExtensions
= 0;
72 AddExtension(const char *name
, int NumEvents
, int NumErrors
,
73 int (*MainProc
) (ClientPtr c1
),
74 int (*SwappedMainProc
) (ClientPtr c2
),
75 void (*CloseDownProc
) (ExtensionEntry
* e
),
76 unsigned short (*MinorOpcodeProc
) (ClientPtr c3
))
79 ExtensionEntry
*ext
, **newexts
;
81 if (!MainProc
|| !SwappedMainProc
|| !MinorOpcodeProc
)
82 return ((ExtensionEntry
*) NULL
);
83 if ((lastEvent
+ NumEvents
> MAXEVENTS
) ||
84 (unsigned) (lastError
+ NumErrors
> LAST_ERROR
)) {
85 LogMessage(X_ERROR
, "Not enabling extension %s: maximum number of "
86 "events or errors exceeded.\n", name
);
87 return ((ExtensionEntry
*) NULL
);
90 ext
= calloc(sizeof(ExtensionEntry
), 1);
93 if (!dixAllocatePrivates(&ext
->devPrivates
, PRIVATE_EXTENSION
)) {
97 ext
->name
= strdup(name
);
99 ext
->aliases
= (char **) NULL
;
101 dixFreePrivates(ext
->devPrivates
, PRIVATE_EXTENSION
);
103 return ((ExtensionEntry
*) NULL
);
106 newexts
= (ExtensionEntry
**) realloc(extensions
,
107 (i
+ 1) * sizeof(ExtensionEntry
*));
110 dixFreePrivates(ext
->devPrivates
, PRIVATE_EXTENSION
);
112 return ((ExtensionEntry
*) NULL
);
115 extensions
= newexts
;
118 ext
->base
= i
+ EXTENSION_BASE
;
119 ext
->CloseDown
= CloseDownProc
;
120 ext
->MinorOpcode
= MinorOpcodeProc
;
121 ProcVector
[i
+ EXTENSION_BASE
] = MainProc
;
122 SwappedProcVector
[i
+ EXTENSION_BASE
] = SwappedMainProc
;
124 ext
->eventBase
= lastEvent
;
125 ext
->eventLast
= lastEvent
+ NumEvents
;
126 lastEvent
+= NumEvents
;
133 ext
->errorBase
= lastError
;
134 ext
->errorLast
= lastError
+ NumErrors
;
135 lastError
+= NumErrors
;
142 RegisterExtensionNames(ext
);
147 AddExtensionAlias(const char *alias
, ExtensionEntry
* ext
)
154 aliases
= (char **) realloc(ext
->aliases
,
155 (ext
->num_aliases
+ 1) * sizeof(char *));
158 ext
->aliases
= aliases
;
159 name
= strdup(alias
);
162 ext
->aliases
[ext
->num_aliases
] = name
;
168 FindExtension(const char *extname
, int len
)
172 for (i
= 0; i
< NumExtensions
; i
++) {
173 if ((strlen(extensions
[i
]->name
) == len
) &&
174 !strncmp(extname
, extensions
[i
]->name
, len
))
176 for (j
= extensions
[i
]->num_aliases
; --j
>= 0;) {
177 if ((strlen(extensions
[i
]->aliases
[j
]) == len
) &&
178 !strncmp(extname
, extensions
[i
]->aliases
[j
], len
))
184 return ((i
== NumExtensions
) ? -1 : i
);
188 * CheckExtension returns the extensions[] entry for the requested
189 * extension name. Maybe this could just return a Bool instead?
192 CheckExtension(const char *extname
)
196 n
= FindExtension(extname
, strlen(extname
));
198 return extensions
[n
];
204 * Added as part of Xace.
207 GetExtensionEntry(int major
)
209 if (major
< EXTENSION_BASE
)
211 major
-= EXTENSION_BASE
;
212 if (major
>= NumExtensions
)
214 return extensions
[major
];
218 StandardMinorOpcode(ClientPtr client
)
220 return ((xReq
*) client
->requestBuffer
)->data
;
224 CloseDownExtensions(void)
228 for (i
= NumExtensions
- 1; i
>= 0; i
--) {
229 if (extensions
[i
]->CloseDown
)
230 extensions
[i
]->CloseDown(extensions
[i
]);
232 free(extensions
[i
]->name
);
233 for (j
= extensions
[i
]->num_aliases
; --j
>= 0;)
234 free(extensions
[i
]->aliases
[j
]);
235 free(extensions
[i
]->aliases
);
236 dixFreePrivates(extensions
[i
]->devPrivates
, PRIVATE_EXTENSION
);
240 extensions
= (ExtensionEntry
**) NULL
;
241 lastEvent
= EXTENSION_EVENT_BASE
;
242 lastError
= FirstExtensionError
;
246 ProcQueryExtension(ClientPtr client
)
248 xQueryExtensionReply reply
;
251 REQUEST(xQueryExtensionReq
);
253 REQUEST_FIXED_SIZE(xQueryExtensionReq
, stuff
->nbytes
);
255 reply
= (xQueryExtensionReply
) {
257 .sequenceNumber
= client
->sequence
,
263 reply
.present
= xFalse
;
265 i
= FindExtension((char *) &stuff
[1], stuff
->nbytes
);
266 if (i
< 0 || XaceHook(XACE_EXT_ACCESS
, client
, extensions
[i
]))
267 reply
.present
= xFalse
;
269 reply
.present
= xTrue
;
270 reply
.major_opcode
= extensions
[i
]->base
;
271 reply
.first_event
= extensions
[i
]->eventBase
;
272 reply
.first_error
= extensions
[i
]->errorBase
;
275 WriteReplyToClient(client
, sizeof(xQueryExtensionReply
), &reply
);
280 ProcListExtensions(ClientPtr client
)
282 xListExtensionsReply reply
;
283 char *bufptr
, *buffer
;
284 int total_length
= 0;
286 REQUEST_SIZE_MATCH(xReq
);
288 reply
= (xListExtensionsReply
) {
291 .sequenceNumber
= client
->sequence
,
299 for (i
= 0; i
< NumExtensions
; i
++) {
300 /* call callbacks to find out whether to show extension */
301 if (XaceHook(XACE_EXT_ACCESS
, client
, extensions
[i
]) != Success
)
304 total_length
+= strlen(extensions
[i
]->name
) + 1;
305 reply
.nExtensions
+= 1 + extensions
[i
]->num_aliases
;
306 for (j
= extensions
[i
]->num_aliases
; --j
>= 0;)
307 total_length
+= strlen(extensions
[i
]->aliases
[j
]) + 1;
309 reply
.length
= bytes_to_int32(total_length
);
310 buffer
= bufptr
= malloc(total_length
);
313 for (i
= 0; i
< NumExtensions
; i
++) {
316 if (XaceHook(XACE_EXT_ACCESS
, client
, extensions
[i
]) != Success
)
319 *bufptr
++ = len
= strlen(extensions
[i
]->name
);
320 memmove(bufptr
, extensions
[i
]->name
, len
);
322 for (j
= extensions
[i
]->num_aliases
; --j
>= 0;) {
323 *bufptr
++ = len
= strlen(extensions
[i
]->aliases
[j
]);
324 memmove(bufptr
, extensions
[i
]->aliases
[j
], len
);
329 WriteReplyToClient(client
, sizeof(xListExtensionsReply
), &reply
);
331 WriteToClient(client
, total_length
, buffer
);