initial commit
[profile/ivi/xorg-x11-server.git] / hw / xfree86 / dixmods / extmod / modinit.c
1 /*
2  * Copyright (c) 1997 Matthieu Herrb
3  *
4  * Permission to use, copy, modify, distribute, and sell this software and its
5  * documentation for any purpose is hereby granted without fee, provided that
6  * the above copyright notice appear in all copies and that both that
7  * copyright notice and this permission notice appear in supporting
8  * documentation, and that the name of Matthieu Herrb not be used in
9  * advertising or publicity pertaining to distribution of the software without
10  * specific, written prior permission.  Matthieu Herrb makes no
11  * representations about the suitability of this software for any purpose.
12  *  It is provided "as is" without express or implied warranty.
13  *
14  * MATTHIEU HERRB DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16  * EVENT SHALL MATTHIEU HERRB BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20  * PERFORMANCE OF THIS SOFTWARE.
21  */
22
23 #ifdef HAVE_XORG_CONFIG_H
24 #include <xorg-config.h>
25 #endif
26
27 #include "xf86Module.h"
28 #include "xf86Opt.h"
29
30 #include <X11/Xproto.h>
31
32 #include "modinit.h"
33 #include "globals.h"
34
35 static MODULESETUPPROTO(extmodSetup);
36
37 /*
38  * Array describing extensions to be initialized
39  */
40 static ExtensionModule extensionModules[] = {
41 #ifdef XSELINUX
42     {
43         SELinuxExtensionInit,
44         SELINUX_EXTENSION_NAME,
45         &noSELinuxExtension,
46         NULL,
47         NULL
48     },
49 #endif
50 #ifdef SCREENSAVER
51     {
52         ScreenSaverExtensionInit,
53         ScreenSaverName,
54         &noScreenSaverExtension,
55         NULL,
56         NULL
57     },
58 #endif
59 #ifdef XF86VIDMODE
60     {
61         XFree86VidModeExtensionInit,
62         XF86VIDMODENAME,
63         &noXFree86VidModeExtension,
64         NULL,
65         NULL
66     },
67 #endif
68 #ifdef XFreeXDGA
69     {
70         XFree86DGAExtensionInit,
71         XF86DGANAME,
72         &noXFree86DGAExtension,
73         XFree86DGARegister,
74         NULL
75     },
76 #endif
77 #ifdef DPMSExtension
78     {
79         DPMSExtensionInit,
80         DPMSExtensionName,
81         &noDPMSExtension,
82         NULL,
83         NULL
84     },
85 #endif
86 #ifdef XV
87     {
88         XvExtensionInit,
89         XvName,
90         &noXvExtension,
91         XvRegister,
92         NULL
93     },
94     {
95         XvMCExtensionInit,
96         XvMCName,
97         &noXvExtension,
98         NULL,
99         NULL
100     },
101 #endif
102 #ifdef RES
103     {
104         ResExtensionInit,
105         XRES_NAME, 
106         &noResExtension,
107         NULL,
108         NULL
109     },
110 #endif
111     {                           /* DON'T delete this entry ! */
112         NULL,
113         NULL,
114         NULL,
115         NULL,
116         NULL
117     }
118 };
119
120 static XF86ModuleVersionInfo VersRec =
121 {
122         "extmod",
123         MODULEVENDORSTRING,
124         MODINFOSTRING1,
125         MODINFOSTRING2,
126         XORG_VERSION_CURRENT,
127         1, 0, 0,
128         ABI_CLASS_EXTENSION,
129         ABI_EXTENSION_VERSION,
130         MOD_CLASS_EXTENSION,
131         {0,0,0,0}
132 };
133
134 /*
135  * Data for the loader
136  */
137 _X_EXPORT XF86ModuleData extmodModuleData = { &VersRec, extmodSetup, NULL };
138
139 static pointer
140 extmodSetup(pointer module, pointer opts, int *errmaj, int *errmin)
141 {
142     int i;
143
144     /* XXX the option stuff here is largely a sample/test case */
145
146     for (i = 0; extensionModules[i].name != NULL; i++) {
147         if (opts) {
148             char *s;
149             s = (char *)malloc(strlen(extensionModules[i].name) + 5);
150             if (s) {
151                 pointer o;
152                 strcpy(s, "omit");
153                 strcat(s, extensionModules[i].name);
154                 o = xf86FindOption(opts, s);
155                 free(s);
156                 if (o) {
157                     xf86MarkOptionUsed(o);
158                     continue;
159                 }
160             }
161         }
162
163 #ifdef XSELINUX
164         if (! strcmp(SELINUX_EXTENSION_NAME, extensionModules[i].name)) {
165             pointer o;
166             selinuxEnforcingState = SELINUX_MODE_DEFAULT;
167
168             if ((o = xf86FindOption(opts, "SELinux mode disabled"))) {
169                 xf86MarkOptionUsed(o);
170                 selinuxEnforcingState = SELINUX_MODE_DISABLED;
171             }
172             if ((o = xf86FindOption(opts, "SELinux mode permissive"))) {
173                 xf86MarkOptionUsed(o);
174                 selinuxEnforcingState = SELINUX_MODE_PERMISSIVE;
175             }
176             if ((o = xf86FindOption(opts, "SELinux mode enforcing"))) {
177                 xf86MarkOptionUsed(o);
178                 selinuxEnforcingState = SELINUX_MODE_ENFORCING;
179             }
180         }
181 #endif
182
183         LoadExtension(&extensionModules[i], FALSE);
184     }
185     /* Need a non-NULL return */
186     return (pointer)1;
187 }