2006-11-26 11:13:41 -07:00
|
|
|
/***********************************************************
|
|
|
|
|
|
|
|
Copyright 1987, 1998 The Open Group
|
|
|
|
|
|
|
|
Permission to use, copy, modify, distribute, and sell this software and its
|
|
|
|
documentation for any purpose is hereby granted without fee, provided that
|
|
|
|
the above copyright notice appear in all copies and that both that
|
|
|
|
copyright notice and this permission notice appear in supporting
|
|
|
|
documentation.
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
|
|
|
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
|
|
|
Except as contained in this notice, the name of The Open Group shall not be
|
|
|
|
used in advertising or otherwise to promote the sale, use or other dealings
|
|
|
|
in this Software without prior written authorization from The Open Group.
|
|
|
|
|
|
|
|
|
|
|
|
Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
|
|
|
|
|
|
|
|
All Rights Reserved
|
|
|
|
|
|
|
|
Permission to use, copy, modify, and distribute this software and its
|
|
|
|
documentation for any purpose and without fee is hereby granted,
|
|
|
|
provided that the above copyright notice appear in all copies and that
|
|
|
|
both that copyright notice and this permission notice appear in
|
|
|
|
supporting documentation, and that the name of Digital not be
|
|
|
|
used in advertising or publicity pertaining to distribution of the
|
|
|
|
software without specific, written prior permission.
|
|
|
|
|
|
|
|
DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
|
|
|
|
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
|
|
|
|
DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
|
|
|
|
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
|
|
|
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
|
|
|
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
|
|
|
SOFTWARE.
|
|
|
|
|
|
|
|
******************************************************************/
|
|
|
|
|
|
|
|
#ifdef HAVE_DIX_CONFIG_H
|
|
|
|
#include <dix-config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <X11/X.h>
|
|
|
|
#include <X11/Xproto.h>
|
|
|
|
#include "misc.h"
|
|
|
|
#include "dixstruct.h"
|
|
|
|
#include "extnsionst.h"
|
|
|
|
#include "gcstruct.h"
|
|
|
|
#include "scrnintstr.h"
|
|
|
|
#include "dispatch.h"
|
2008-11-02 08:26:08 -07:00
|
|
|
#include "privates.h"
|
|
|
|
#include "registry.h"
|
2006-11-26 11:13:41 -07:00
|
|
|
#include "xace.h"
|
|
|
|
|
|
|
|
#define LAST_EVENT 128
|
|
|
|
#define LAST_ERROR 255
|
|
|
|
|
|
|
|
static ExtensionEntry **extensions = (ExtensionEntry **)NULL;
|
|
|
|
|
|
|
|
int lastEvent = EXTENSION_EVENT_BASE;
|
|
|
|
static int lastError = FirstExtensionError;
|
|
|
|
static unsigned int NumExtensions = 0;
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
ExtensionEntry *
|
2006-11-26 11:13:41 -07:00
|
|
|
AddExtension(char *name, int NumEvents, int NumErrors,
|
|
|
|
int (*MainProc)(ClientPtr c1),
|
|
|
|
int (*SwappedMainProc)(ClientPtr c2),
|
|
|
|
void (*CloseDownProc)(ExtensionEntry *e),
|
|
|
|
unsigned short (*MinorOpcodeProc)(ClientPtr c3))
|
|
|
|
{
|
|
|
|
int i;
|
2007-11-24 12:04:00 -07:00
|
|
|
ExtensionEntry *ext, **newexts;
|
2006-11-28 13:29:31 -07:00
|
|
|
size_t buflen;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
if (!MainProc || !SwappedMainProc || !MinorOpcodeProc)
|
2006-11-26 11:13:41 -07:00
|
|
|
return((ExtensionEntry *) NULL);
|
|
|
|
if ((lastEvent + NumEvents > LAST_EVENT) ||
|
2010-07-27 13:02:24 -06:00
|
|
|
(unsigned)(lastError + NumErrors > LAST_ERROR)) {
|
|
|
|
LogMessage(X_ERROR, "Not enabling extension %s: maximum number of "
|
|
|
|
"events or errors exceeded.\n", name);
|
2006-11-26 11:13:41 -07:00
|
|
|
return((ExtensionEntry *) NULL);
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
ext = calloc(sizeof (ExtensionEntry), 1);
|
2006-11-26 11:13:41 -07:00
|
|
|
if (!ext)
|
2010-12-05 08:36:02 -07:00
|
|
|
return NULL;
|
|
|
|
if (!dixAllocatePrivates(&ext->devPrivates, PRIVATE_EXTENSION)) {
|
|
|
|
free(ext);
|
|
|
|
return NULL;
|
|
|
|
}
|
2009-09-06 13:44:18 -06:00
|
|
|
buflen = strlen(name) + 1;
|
2010-12-05 08:36:02 -07:00
|
|
|
ext->name = malloc(buflen);
|
2006-11-26 11:13:41 -07:00
|
|
|
ext->num_aliases = 0;
|
|
|
|
ext->aliases = (char **)NULL;
|
|
|
|
if (!ext->name)
|
|
|
|
{
|
2010-12-05 08:36:02 -07:00
|
|
|
dixFreePrivates(ext->devPrivates, PRIVATE_EXTENSION);
|
|
|
|
free(ext);
|
2006-11-26 11:13:41 -07:00
|
|
|
return((ExtensionEntry *) NULL);
|
|
|
|
}
|
2006-11-28 13:29:31 -07:00
|
|
|
strlcpy(ext->name, name, buflen);
|
2006-11-26 11:13:41 -07:00
|
|
|
i = NumExtensions;
|
2010-12-05 08:36:02 -07:00
|
|
|
newexts = (ExtensionEntry **) realloc(extensions,
|
2006-11-26 11:13:41 -07:00
|
|
|
(i + 1) * sizeof(ExtensionEntry *));
|
|
|
|
if (!newexts)
|
|
|
|
{
|
2010-12-05 08:36:02 -07:00
|
|
|
free(ext->name);
|
|
|
|
dixFreePrivates(ext->devPrivates, PRIVATE_EXTENSION);
|
|
|
|
free(ext);
|
2006-11-26 11:13:41 -07:00
|
|
|
return((ExtensionEntry *) NULL);
|
|
|
|
}
|
|
|
|
NumExtensions++;
|
|
|
|
extensions = newexts;
|
|
|
|
extensions[i] = ext;
|
|
|
|
ext->index = i;
|
|
|
|
ext->base = i + EXTENSION_BASE;
|
|
|
|
ext->CloseDown = CloseDownProc;
|
|
|
|
ext->MinorOpcode = MinorOpcodeProc;
|
|
|
|
ProcVector[i + EXTENSION_BASE] = MainProc;
|
|
|
|
SwappedProcVector[i + EXTENSION_BASE] = SwappedMainProc;
|
|
|
|
if (NumEvents)
|
|
|
|
{
|
|
|
|
ext->eventBase = lastEvent;
|
|
|
|
ext->eventLast = lastEvent + NumEvents;
|
|
|
|
lastEvent += NumEvents;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ext->eventBase = 0;
|
|
|
|
ext->eventLast = 0;
|
|
|
|
}
|
|
|
|
if (NumErrors)
|
|
|
|
{
|
|
|
|
ext->errorBase = lastError;
|
|
|
|
ext->errorLast = lastError + NumErrors;
|
|
|
|
lastError += NumErrors;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ext->errorBase = 0;
|
|
|
|
ext->errorLast = 0;
|
|
|
|
}
|
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
RegisterExtensionNames(ext);
|
2010-12-05 08:36:02 -07:00
|
|
|
return ext;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
Bool AddExtensionAlias(char *alias, ExtensionEntry *ext)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
char *name;
|
|
|
|
char **aliases;
|
2006-11-28 13:29:31 -07:00
|
|
|
size_t buflen;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
if (!ext)
|
|
|
|
return FALSE ;
|
2010-12-05 08:36:02 -07:00
|
|
|
aliases = (char **)realloc(ext->aliases,
|
2006-11-26 11:13:41 -07:00
|
|
|
(ext->num_aliases + 1) * sizeof(char *));
|
|
|
|
if (!aliases)
|
|
|
|
return FALSE;
|
|
|
|
ext->aliases = aliases;
|
2006-11-28 13:29:31 -07:00
|
|
|
buflen = strlen(alias) + 1;
|
2010-12-05 08:36:02 -07:00
|
|
|
name = malloc(buflen);
|
2006-11-26 11:13:41 -07:00
|
|
|
if (!name)
|
|
|
|
return FALSE;
|
2006-11-28 13:29:31 -07:00
|
|
|
strlcpy(name, alias, buflen);
|
2006-11-26 11:13:41 -07:00
|
|
|
ext->aliases[ext->num_aliases] = name;
|
|
|
|
ext->num_aliases++;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
FindExtension(char *extname, int len)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
for (i=0; i<NumExtensions; i++)
|
|
|
|
{
|
|
|
|
if ((strlen(extensions[i]->name) == len) &&
|
|
|
|
!strncmp(extname, extensions[i]->name, len))
|
|
|
|
break;
|
|
|
|
for (j = extensions[i]->num_aliases; --j >= 0;)
|
|
|
|
{
|
|
|
|
if ((strlen(extensions[i]->aliases[j]) == len) &&
|
|
|
|
!strncmp(extname, extensions[i]->aliases[j], len))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (j >= 0) break;
|
|
|
|
}
|
|
|
|
return ((i == NumExtensions) ? -1 : i);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* CheckExtension returns the extensions[] entry for the requested
|
|
|
|
* extension name. Maybe this could just return a Bool instead?
|
|
|
|
*/
|
2010-07-27 13:02:24 -06:00
|
|
|
ExtensionEntry *
|
2006-11-26 11:13:41 -07:00
|
|
|
CheckExtension(const char *extname)
|
|
|
|
{
|
|
|
|
int n;
|
|
|
|
|
|
|
|
n = FindExtension((char*)extname, strlen(extname));
|
|
|
|
if (n != -1)
|
|
|
|
return extensions[n];
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Added as part of Xace.
|
|
|
|
*/
|
|
|
|
ExtensionEntry *
|
|
|
|
GetExtensionEntry(int major)
|
|
|
|
{
|
|
|
|
if (major < EXTENSION_BASE)
|
|
|
|
return NULL;
|
|
|
|
major -= EXTENSION_BASE;
|
|
|
|
if (major >= NumExtensions)
|
|
|
|
return NULL;
|
|
|
|
return extensions[major];
|
|
|
|
}
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
unsigned short
|
2006-11-26 11:13:41 -07:00
|
|
|
StandardMinorOpcode(ClientPtr client)
|
|
|
|
{
|
|
|
|
return ((xReq *)client->requestBuffer)->data;
|
|
|
|
}
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
unsigned short
|
2006-11-26 11:13:41 -07:00
|
|
|
MinorOpcodeOfRequest(ClientPtr client)
|
|
|
|
{
|
|
|
|
unsigned char major;
|
|
|
|
|
|
|
|
major = ((xReq *)client->requestBuffer)->reqType;
|
|
|
|
if (major < EXTENSION_BASE)
|
|
|
|
return 0;
|
|
|
|
major -= EXTENSION_BASE;
|
|
|
|
if (major >= NumExtensions)
|
|
|
|
return 0;
|
|
|
|
return (*extensions[major]->MinorOpcode)(client);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-11-24 12:04:00 -07:00
|
|
|
CloseDownExtensions(void)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2007-11-24 12:04:00 -07:00
|
|
|
int i,j;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
for (i = NumExtensions - 1; i >= 0; i--)
|
|
|
|
{
|
2009-09-06 13:44:18 -06:00
|
|
|
if (extensions[i]->CloseDown)
|
|
|
|
extensions[i]->CloseDown(extensions[i]);
|
2006-11-26 11:13:41 -07:00
|
|
|
NumExtensions = i;
|
2010-12-05 08:36:02 -07:00
|
|
|
free(extensions[i]->name);
|
2006-11-26 11:13:41 -07:00
|
|
|
for (j = extensions[i]->num_aliases; --j >= 0;)
|
2010-12-05 08:36:02 -07:00
|
|
|
free(extensions[i]->aliases[j]);
|
|
|
|
free(extensions[i]->aliases);
|
|
|
|
dixFreePrivates(extensions[i]->devPrivates, PRIVATE_EXTENSION);
|
|
|
|
free(extensions[i]);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2010-12-05 08:36:02 -07:00
|
|
|
free(extensions);
|
2006-11-26 11:13:41 -07:00
|
|
|
extensions = (ExtensionEntry **)NULL;
|
|
|
|
lastEvent = EXTENSION_EVENT_BASE;
|
|
|
|
lastError = FirstExtensionError;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ProcQueryExtension(ClientPtr client)
|
|
|
|
{
|
|
|
|
xQueryExtensionReply reply;
|
|
|
|
int i;
|
|
|
|
REQUEST(xQueryExtensionReq);
|
|
|
|
|
|
|
|
REQUEST_FIXED_SIZE(xQueryExtensionReq, stuff->nbytes);
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
memset(&reply, 0, sizeof(xQueryExtensionReply));
|
2006-11-26 11:13:41 -07:00
|
|
|
reply.type = X_Reply;
|
|
|
|
reply.length = 0;
|
|
|
|
reply.major_opcode = 0;
|
|
|
|
reply.sequenceNumber = client->sequence;
|
|
|
|
|
|
|
|
if ( ! NumExtensions )
|
|
|
|
reply.present = xFalse;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
i = FindExtension((char *)&stuff[1], stuff->nbytes);
|
2008-11-02 08:26:08 -07:00
|
|
|
if (i < 0 || XaceHook(XACE_EXT_ACCESS, client, extensions[i]))
|
2006-11-26 11:13:41 -07:00
|
|
|
reply.present = xFalse;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
reply.present = xTrue;
|
|
|
|
reply.major_opcode = extensions[i]->base;
|
|
|
|
reply.first_event = extensions[i]->eventBase;
|
|
|
|
reply.first_error = extensions[i]->errorBase;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
WriteReplyToClient(client, sizeof(xQueryExtensionReply), &reply);
|
2010-12-05 08:36:02 -07:00
|
|
|
return Success;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ProcListExtensions(ClientPtr client)
|
|
|
|
{
|
|
|
|
xListExtensionsReply reply;
|
|
|
|
char *bufptr, *buffer;
|
|
|
|
int total_length = 0;
|
|
|
|
|
|
|
|
REQUEST_SIZE_MATCH(xReq);
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
memset(&reply, 0, sizeof(xListExtensionsReply));
|
2006-11-26 11:13:41 -07:00
|
|
|
reply.type = X_Reply;
|
|
|
|
reply.nExtensions = 0;
|
|
|
|
reply.length = 0;
|
|
|
|
reply.sequenceNumber = client->sequence;
|
|
|
|
buffer = NULL;
|
|
|
|
|
|
|
|
if ( NumExtensions )
|
|
|
|
{
|
2007-11-24 12:04:00 -07:00
|
|
|
int i, j;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
for (i=0; i<NumExtensions; i++)
|
|
|
|
{
|
|
|
|
/* call callbacks to find out whether to show extension */
|
2008-11-02 08:26:08 -07:00
|
|
|
if (XaceHook(XACE_EXT_ACCESS, client, extensions[i]) != Success)
|
2006-11-26 11:13:41 -07:00
|
|
|
continue;
|
2007-11-24 12:04:00 -07:00
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
total_length += strlen(extensions[i]->name) + 1;
|
|
|
|
reply.nExtensions += 1 + extensions[i]->num_aliases;
|
|
|
|
for (j = extensions[i]->num_aliases; --j >= 0;)
|
|
|
|
total_length += strlen(extensions[i]->aliases[j]) + 1;
|
|
|
|
}
|
2010-07-27 13:02:24 -06:00
|
|
|
reply.length = bytes_to_int32(total_length);
|
2010-12-05 08:36:02 -07:00
|
|
|
buffer = bufptr = malloc(total_length);
|
2006-11-26 11:13:41 -07:00
|
|
|
if (!buffer)
|
2010-12-05 08:36:02 -07:00
|
|
|
return BadAlloc;
|
2006-11-26 11:13:41 -07:00
|
|
|
for (i=0; i<NumExtensions; i++)
|
|
|
|
{
|
|
|
|
int len;
|
2008-11-02 08:26:08 -07:00
|
|
|
if (XaceHook(XACE_EXT_ACCESS, client, extensions[i]) != Success)
|
2006-11-26 11:13:41 -07:00
|
|
|
continue;
|
2007-11-24 12:04:00 -07:00
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
*bufptr++ = len = strlen(extensions[i]->name);
|
|
|
|
memmove(bufptr, extensions[i]->name, len);
|
|
|
|
bufptr += len;
|
|
|
|
for (j = extensions[i]->num_aliases; --j >= 0;)
|
|
|
|
{
|
|
|
|
*bufptr++ = len = strlen(extensions[i]->aliases[j]);
|
|
|
|
memmove(bufptr, extensions[i]->aliases[j], len);
|
|
|
|
bufptr += len;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
WriteReplyToClient(client, sizeof(xListExtensionsReply), &reply);
|
|
|
|
if (reply.length)
|
|
|
|
{
|
|
|
|
WriteToClient(client, total_length, buffer);
|
2010-12-05 08:36:02 -07:00
|
|
|
free(buffer);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2010-12-05 08:36:02 -07:00
|
|
|
return Success;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|