Commit | Line | Data |
---|---|---|
a09e091a JB |
1 | /*********************************************************** |
2 | ||
3 | Copyright 1987, 1998 The Open Group | |
4 | ||
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 | |
9 | documentation. | |
10 | ||
11 | The above copyright notice and this permission notice shall be included in | |
12 | all copies or substantial portions of the Software. | |
13 | ||
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. | |
20 | ||
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. | |
24 | ||
25 | Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. | |
26 | ||
27 | All Rights Reserved | |
28 | ||
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. | |
36 | ||
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 | |
43 | SOFTWARE. | |
44 | ||
45 | ******************************************************************/ | |
46 | ||
47 | /* | |
48 | * Copyright (c) 2000 by The XFree86 Project, Inc. | |
49 | * | |
50 | * Permission is hereby granted, free of charge, to any person obtaining a | |
51 | * copy of this software and associated documentation files (the "Software"), | |
52 | * to deal in the Software without restriction, including without limitation | |
53 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | |
54 | * and/or sell copies of the Software, and to permit persons to whom the | |
55 | * Software is furnished to do so, subject to the following conditions: | |
56 | * | |
57 | * The above copyright notice and this permission notice shall be included in | |
58 | * all copies or substantial portions of the Software. | |
59 | * | |
60 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
61 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
62 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
63 | * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR | |
64 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | |
65 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | |
66 | * OTHER DEALINGS IN THE SOFTWARE. | |
67 | * | |
68 | * Except as contained in this notice, the name of the copyright holder(s) | |
69 | * and author(s) shall not be used in advertising or otherwise to promote | |
70 | * the sale, use or other dealings in this Software without prior written | |
71 | * authorization from the copyright holder(s) and author(s). | |
72 | */ | |
73 | ||
74 | #ifdef HAVE_DIX_CONFIG_H | |
75 | #include <dix-config.h> | |
76 | #endif | |
77 | ||
78 | #ifdef HAVE_XORG_CONFIG_H | |
79 | #include <xorg-config.h> | |
80 | #include "xf86Extensions.h" | |
81 | #endif | |
82 | ||
83 | #ifdef HAVE_DMX_CONFIG_H | |
84 | #include <dmx-config.h> | |
85 | #undef XV | |
86 | #undef DBE | |
87 | #undef SCREENSAVER | |
88 | #undef RANDR | |
89 | #undef DAMAGE | |
90 | #undef COMPOSITE | |
91 | #undef MITSHM | |
92 | #endif | |
93 | ||
94 | #ifdef HAVE_XNEST_CONFIG_H | |
95 | #include <xnest-config.h> | |
96 | #undef COMPOSITE | |
97 | #undef DPMSExtension | |
98 | #endif | |
99 | ||
100 | #ifdef HAVE_KDRIVE_CONFIG_H | |
101 | #include <kdrive-config.h> | |
102 | #endif | |
103 | ||
104 | #ifdef HAVE_XGL_CONFIG_H | |
105 | #include <xgl-config.h> | |
106 | #endif | |
107 | ||
108 | #include "misc.h" | |
109 | #include "extension.h" | |
110 | #include "extinit.h" | |
111 | #include "micmap.h" | |
112 | #include "globals.h" | |
113 | ||
114 | /* The following is only a small first step towards run-time | |
115 | * configurable extensions. | |
116 | */ | |
117 | typedef struct { | |
118 | const char *name; | |
119 | Bool *disablePtr; | |
120 | } ExtensionToggle; | |
121 | ||
122 | static ExtensionToggle ExtensionToggleList[] = { | |
123 | /* sort order is extension name string as shown in xdpyinfo */ | |
124 | {"Generic Events", &noGEExtension}, | |
125 | #ifdef COMPOSITE | |
126 | {"Composite", &noCompositeExtension}, | |
127 | #endif | |
128 | #ifdef DAMAGE | |
129 | {"DAMAGE", &noDamageExtension}, | |
130 | #endif | |
131 | #ifdef DBE | |
132 | {"DOUBLE-BUFFER", &noDbeExtension}, | |
133 | #endif | |
134 | #ifdef DPMSExtension | |
135 | {"DPMS", &noDPMSExtension}, | |
136 | #endif | |
137 | #ifdef GLXEXT | |
138 | {"GLX", &noGlxExtension}, | |
139 | #endif | |
140 | #ifdef SCREENSAVER | |
141 | {"MIT-SCREEN-SAVER", &noScreenSaverExtension}, | |
142 | #endif | |
143 | #ifdef MITSHM | |
144 | {SHMNAME, &noMITShmExtension}, | |
145 | #endif | |
146 | #ifdef RANDR | |
147 | {"RANDR", &noRRExtension}, | |
148 | #endif | |
149 | {"RENDER", &noRenderExtension}, | |
150 | #ifdef XCSECURITY | |
151 | {"SECURITY", &noSecurityExtension}, | |
152 | #endif | |
153 | #ifdef RES | |
154 | {"X-Resource", &noResExtension}, | |
155 | #endif | |
156 | #ifdef XF86BIGFONT | |
157 | {"XFree86-Bigfont", &noXFree86BigfontExtension}, | |
158 | #endif | |
159 | #ifdef XORGSERVER | |
160 | #ifdef XFreeXDGA | |
161 | {"XFree86-DGA", &noXFree86DGAExtension}, | |
162 | #endif | |
163 | #ifdef XF86DRI | |
164 | {"XFree86-DRI", &noXFree86DRIExtension}, | |
165 | #endif | |
166 | #ifdef XF86VIDMODE | |
167 | {"XFree86-VidModeExtension", &noXFree86VidModeExtension}, | |
168 | #endif | |
169 | #endif | |
170 | {"XFIXES", &noXFixesExtension}, | |
171 | #ifdef PANORAMIX | |
172 | {"XINERAMA", &noPanoramiXExtension}, | |
173 | #endif | |
174 | {"XInputExtension", NULL}, | |
175 | {"XKEYBOARD", NULL}, | |
176 | #ifdef XSELINUX | |
177 | {"SELinux", &noSELinuxExtension}, | |
178 | #endif | |
179 | {"XTEST", &noTestExtensions}, | |
180 | #ifdef XV | |
181 | {"XVideo", &noXvExtension}, | |
182 | #endif | |
183 | }; | |
184 | ||
185 | Bool | |
186 | EnableDisableExtension(const char *name, Bool enable) | |
187 | { | |
188 | ExtensionToggle *ext; | |
189 | int i; | |
190 | ||
191 | for (i = 0; i < ARRAY_SIZE(ExtensionToggleList); i++) { | |
192 | ext = &ExtensionToggleList[i]; | |
193 | if (strcmp(name, ext->name) == 0) { | |
194 | if (ext->disablePtr != NULL) { | |
195 | *ext->disablePtr = !enable; | |
196 | return TRUE; | |
197 | } | |
198 | else { | |
199 | /* Extension is always on, impossible to disable */ | |
200 | return enable; /* okay if they wanted to enable, | |
201 | fail if they tried to disable */ | |
202 | } | |
203 | } | |
204 | } | |
205 | ||
206 | return FALSE; | |
207 | } | |
208 | ||
209 | void | |
210 | EnableDisableExtensionError(const char *name, Bool enable) | |
211 | { | |
212 | ExtensionToggle *ext; | |
213 | int i; | |
214 | Bool found = FALSE; | |
215 | ||
216 | for (i = 0; i < ARRAY_SIZE(ExtensionToggleList); i++) { | |
217 | ext = &ExtensionToggleList[i]; | |
218 | if ((strcmp(name, ext->name) == 0) && (ext->disablePtr == NULL)) { | |
219 | ErrorF("[mi] Extension \"%s\" can not be disabled\n", name); | |
220 | found = TRUE; | |
221 | break; | |
222 | } | |
223 | } | |
224 | if (found == FALSE) | |
225 | ErrorF("[mi] Extension \"%s\" is not recognized\n", name); | |
226 | ErrorF("[mi] Only the following extensions can be run-time %s:\n", | |
227 | enable ? "enabled" : "disabled"); | |
228 | for (i = 0; i < ARRAY_SIZE(ExtensionToggleList); i++) { | |
229 | ext = &ExtensionToggleList[i]; | |
230 | if (ext->disablePtr != NULL) { | |
231 | ErrorF("[mi] %s\n", ext->name); | |
232 | } | |
233 | } | |
234 | } | |
235 | ||
236 | /* List of built-in (statically linked) extensions */ | |
237 | static ExtensionModule staticExtensions[] = { | |
238 | {GEExtensionInit, "Generic Event Extension", &noGEExtension}, | |
239 | {ShapeExtensionInit, "SHAPE", NULL}, | |
240 | #ifdef MITSHM | |
241 | {ShmExtensionInit, SHMNAME, &noMITShmExtension}, | |
242 | #endif | |
243 | {XInputExtensionInit, "XInputExtension", NULL}, | |
244 | #ifdef XTEST | |
245 | {XTestExtensionInit, XTestExtensionName, &noTestExtensions}, | |
246 | #endif | |
247 | {BigReqExtensionInit, "BIG-REQUESTS", NULL}, | |
248 | {SyncExtensionInit, "SYNC", NULL}, | |
249 | {XkbExtensionInit, XkbName, NULL}, | |
250 | {XCMiscExtensionInit, "XC-MISC", NULL}, | |
251 | #ifdef XCSECURITY | |
252 | {SecurityExtensionInit, SECURITY_EXTENSION_NAME, &noSecurityExtension}, | |
253 | #endif | |
254 | #ifdef PANORAMIX | |
255 | {PanoramiXExtensionInit, PANORAMIX_PROTOCOL_NAME, &noPanoramiXExtension}, | |
256 | #endif | |
257 | #ifdef INXQUARTZ | |
258 | /* PseudoramiXExtensionInit must be done before RRExtensionInit, or | |
259 | * XQuartz will render windows offscreen. | |
260 | */ | |
261 | {PseudoramiXExtensionInit, "PseudoramiX", &noPseudoramiXExtension}, | |
262 | #endif | |
263 | /* must be before Render to layer DisplayCursor correctly */ | |
264 | {XFixesExtensionInit, "XFIXES", &noXFixesExtension}, | |
265 | #ifdef XF86BIGFONT | |
266 | {XFree86BigfontExtensionInit, XF86BIGFONTNAME, &noXFree86BigfontExtension}, | |
267 | #endif | |
268 | {RenderExtensionInit, "RENDER", &noRenderExtension}, | |
269 | #ifdef RANDR | |
270 | {RRExtensionInit, "RANDR", &noRRExtension}, | |
271 | #endif | |
272 | #ifdef COMPOSITE | |
273 | {CompositeExtensionInit, "COMPOSITE", &noCompositeExtension}, | |
274 | #endif | |
275 | #ifdef DAMAGE | |
276 | {DamageExtensionInit, "DAMAGE", &noDamageExtension}, | |
277 | #endif | |
278 | #ifdef SCREENSAVER | |
279 | {ScreenSaverExtensionInit, ScreenSaverName, &noScreenSaverExtension}, | |
280 | #endif | |
281 | #ifdef DBE | |
282 | {DbeExtensionInit, "DOUBLE-BUFFER", &noDbeExtension}, | |
283 | #endif | |
284 | #ifdef XRECORD | |
285 | {RecordExtensionInit, "RECORD", &noTestExtensions}, | |
286 | #endif | |
287 | #ifdef DPMSExtension | |
288 | {DPMSExtensionInit, DPMSExtensionName, &noDPMSExtension}, | |
289 | #endif | |
290 | #ifdef PRESENT | |
291 | {present_extension_init, PRESENT_NAME, NULL}, | |
292 | #endif | |
293 | #ifdef DRI3 | |
294 | {dri3_extension_init, DRI3_NAME, NULL}, | |
295 | #endif | |
296 | #ifdef RES | |
297 | {ResExtensionInit, XRES_NAME, &noResExtension}, | |
298 | #endif | |
299 | #ifdef XV | |
300 | {XvExtensionInit, XvName, &noXvExtension}, | |
301 | {XvMCExtensionInit, XvMCName, &noXvExtension}, | |
302 | #endif | |
303 | #ifdef XSELINUX | |
304 | {SELinuxExtensionInit, SELINUX_EXTENSION_NAME, &noSELinuxExtension}, | |
305 | #endif | |
306 | }; | |
307 | ||
308 | static ExtensionModule *ExtensionModuleList = NULL; | |
309 | static int numExtensionModules = 0; | |
310 | ||
311 | static void | |
312 | AddStaticExtensions(void) | |
313 | { | |
314 | static Bool listInitialised = FALSE; | |
315 | int i; | |
316 | ||
317 | if (listInitialised) | |
318 | return; | |
319 | listInitialised = TRUE; | |
320 | ||
321 | /* Add built-in extensions to the list. */ | |
322 | for (i = 0; i < ARRAY_SIZE(staticExtensions); i++) | |
323 | LoadExtension(&staticExtensions[i], TRUE); | |
324 | } | |
325 | ||
326 | void | |
327 | InitExtensions(int argc, char *argv[]) | |
328 | { | |
329 | int i; | |
330 | ExtensionModule *ext; | |
331 | ||
332 | AddStaticExtensions(); | |
333 | ||
334 | for (i = 0; ExtensionModuleList[i].name != NULL; i++) { | |
335 | ext = &ExtensionModuleList[i]; | |
336 | if (ext->initFunc != NULL && | |
337 | (ext->disablePtr == NULL || !*ext->disablePtr)) { | |
338 | (ext->initFunc) (); | |
339 | } | |
340 | } | |
341 | } | |
342 | ||
343 | static ExtensionModule * | |
344 | NewExtensionModule(void) | |
345 | { | |
346 | ExtensionModule *save = ExtensionModuleList; | |
347 | int n; | |
348 | ||
349 | /* Make sure built-in extensions get added to the list before those | |
350 | * in modules. */ | |
351 | AddStaticExtensions(); | |
352 | ||
353 | /* Sanity check */ | |
354 | if (!ExtensionModuleList) | |
355 | numExtensionModules = 0; | |
356 | ||
357 | n = numExtensionModules + 1; | |
358 | ExtensionModuleList = realloc(ExtensionModuleList, | |
359 | (n + 1) * sizeof(ExtensionModule)); | |
360 | if (ExtensionModuleList == NULL) { | |
361 | ExtensionModuleList = save; | |
362 | return NULL; | |
363 | } | |
364 | else { | |
365 | numExtensionModules++; | |
366 | ExtensionModuleList[numExtensionModules].name = NULL; | |
367 | return ExtensionModuleList + (numExtensionModules - 1); | |
368 | } | |
369 | } | |
370 | ||
371 | void | |
372 | LoadExtension(const ExtensionModule * e, Bool builtin) | |
373 | { | |
374 | ExtensionModule *newext; | |
375 | ||
376 | if (e == NULL || e->name == NULL) | |
377 | return; | |
378 | ||
379 | if (!(newext = NewExtensionModule())) | |
380 | return; | |
381 | ||
382 | if (builtin) | |
383 | ErrorF("Initializing built-in extension %s\n", e->name); | |
384 | else | |
385 | ErrorF("Loading extension %s\n", e->name); | |
386 | ||
387 | newext->name = e->name; | |
388 | newext->initFunc = e->initFunc; | |
389 | newext->disablePtr = e->disablePtr; | |
390 | } |