Xext: shape: use REQUEST_HEAD_STRUCT and REQUEST_FIELD_* macros

Use the new macros to make request struct parsing / field swapping
much easier.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
Enrico Weigelt, metux IT consult 2024-07-03 02:45:34 +02:00
parent 6f6379ff54
commit 7c92bf3937

View File

@ -33,6 +33,7 @@ in this Software without prior written authorization from The Open Group.
#include "dix/dix_priv.h" #include "dix/dix_priv.h"
#include "dix/gc_priv.h" #include "dix/gc_priv.h"
#include "dix/request_priv.h"
#include "Xext/panoramiX.h" #include "Xext/panoramiX.h"
#include "Xext/panoramiXsrv.h" #include "Xext/panoramiXsrv.h"
@ -204,24 +205,16 @@ CreateClipShape(WindowPtr pWin)
static int static int
ProcShapeQueryVersion(ClientPtr client) ProcShapeQueryVersion(ClientPtr client)
{ {
REQUEST_HEAD_STRUCT(xShapeQueryVersionReq);
xShapeQueryVersionReply rep = { xShapeQueryVersionReply rep = {
.type = X_Reply,
.sequenceNumber = client->sequence,
.length = 0,
.majorVersion = SERVER_SHAPE_MAJOR_VERSION, .majorVersion = SERVER_SHAPE_MAJOR_VERSION,
.minorVersion = SERVER_SHAPE_MINOR_VERSION .minorVersion = SERVER_SHAPE_MINOR_VERSION
}; };
REQUEST_SIZE_MATCH(xShapeQueryVersionReq); REPLY_FIELD_CARD16(majorVersion);
REPLY_FIELD_CARD16(minorVersion);
if (client->swapped) { REPLY_SEND_RET_SUCCESS();
swaps(&rep.sequenceNumber);
swapl(&rep.length);
swaps(&rep.majorVersion);
swaps(&rep.minorVersion);
}
WriteToClient(client, sizeof(xShapeQueryVersionReply), &rep);
return Success;
} }
static int static int
@ -291,8 +284,11 @@ ShapeRectangles(ClientPtr client, xShapeRectanglesReq *stuff)
static int static int
ProcShapeRectangles(ClientPtr client) ProcShapeRectangles(ClientPtr client)
{ {
REQUEST(xShapeRectanglesReq); REQUEST_HEAD_AT_LEAST(xShapeRectanglesReq);
REQUEST_AT_LEAST_SIZE(xShapeRectanglesReq); REQUEST_FIELD_CARD32(dest);
REQUEST_FIELD_CARD16(xOff);
REQUEST_FIELD_CARD16(yOff);
REQUEST_REST_CARD16();
#ifdef XINERAMA #ifdef XINERAMA
if (noPanoramiXExtension) if (noPanoramiXExtension)
@ -387,8 +383,11 @@ ShapeMask(ClientPtr client, xShapeMaskReq *stuff)
static int static int
ProcShapeMask(ClientPtr client) ProcShapeMask(ClientPtr client)
{ {
REQUEST(xShapeMaskReq); REQUEST_HEAD_STRUCT(xShapeMaskReq);
REQUEST_SIZE_MATCH(xShapeMaskReq); REQUEST_FIELD_CARD32(dest);
REQUEST_FIELD_CARD16(xOff);
REQUEST_FIELD_CARD16(yOff);
REQUEST_FIELD_CARD32(src);
#ifdef XINERAMA #ifdef XINERAMA
if (noPanoramiXExtension) if (noPanoramiXExtension)
@ -513,8 +512,11 @@ ShapeCombine(ClientPtr client, xShapeCombineReq *stuff)
static int static int
ProcShapeCombine(ClientPtr client) ProcShapeCombine(ClientPtr client)
{ {
REQUEST(xShapeCombineReq); REQUEST_HEAD_STRUCT(xShapeCombineReq);
REQUEST_AT_LEAST_SIZE(xShapeCombineReq); REQUEST_FIELD_CARD32(dest);
REQUEST_FIELD_CARD16(xOff);
REQUEST_FIELD_CARD16(yOff);
REQUEST_FIELD_CARD32(src);
#ifdef XINERAMA #ifdef XINERAMA
if (noPanoramiXExtension) if (noPanoramiXExtension)
@ -582,8 +584,10 @@ ShapeOffset(ClientPtr client, xShapeOffsetReq *stuff)
static int static int
ProcShapeOffset(ClientPtr client) ProcShapeOffset(ClientPtr client)
{ {
REQUEST(xShapeOffsetReq); REQUEST_HEAD_AT_LEAST(xShapeOffsetReq);
REQUEST_AT_LEAST_SIZE(xShapeOffsetReq); REQUEST_FIELD_CARD32(dest);
REQUEST_FIELD_CARD16(yOff);
REQUEST_FIELD_CARD16(yOff);
#ifdef XINERAMA #ifdef XINERAMA
PanoramiXRes *win; PanoramiXRes *win;
@ -612,14 +616,15 @@ ProcShapeOffset(ClientPtr client)
static int static int
ProcShapeQueryExtents(ClientPtr client) ProcShapeQueryExtents(ClientPtr client)
{ {
REQUEST(xShapeQueryExtentsReq); REQUEST_HEAD_STRUCT(xShapeQueryExtentsReq);
REQUEST_FIELD_CARD32(window);
WindowPtr pWin; WindowPtr pWin;
xShapeQueryExtentsReply rep; xShapeQueryExtentsReply rep;
BoxRec extents, *pExtents; BoxRec extents, *pExtents;
int rc; int rc;
RegionPtr region; RegionPtr region;
REQUEST_SIZE_MATCH(xShapeQueryExtentsReq);
rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess); rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess);
if (rc != Success) if (rc != Success)
return rc; return rc;
@ -721,13 +726,14 @@ ShapeFreeEvents(void *data, XID id)
static int static int
ProcShapeSelectInput(ClientPtr client) ProcShapeSelectInput(ClientPtr client)
{ {
REQUEST(xShapeSelectInputReq); REQUEST_HEAD_STRUCT(xShapeSelectInputReq);
REQUEST_FIELD_CARD32(window);
WindowPtr pWin; WindowPtr pWin;
ShapeEventPtr pShapeEvent, pNewShapeEvent, *pHead; ShapeEventPtr pShapeEvent, pNewShapeEvent, *pHead;
XID clientResource; XID clientResource;
int rc; int rc;
REQUEST_SIZE_MATCH(xShapeSelectInputReq);
rc = dixLookupWindow(&pWin, stuff->window, client, DixReceiveAccess); rc = dixLookupWindow(&pWin, stuff->window, client, DixReceiveAccess);
if (rc != Success) if (rc != Success)
return rc; return rc;
@ -892,13 +898,14 @@ SendShapeNotify(WindowPtr pWin, int which)
static int static int
ProcShapeInputSelected(ClientPtr client) ProcShapeInputSelected(ClientPtr client)
{ {
REQUEST(xShapeInputSelectedReq); REQUEST_HEAD_STRUCT(xShapeInputSelectedReq);
REQUEST_FIELD_CARD32(window);
WindowPtr pWin; WindowPtr pWin;
ShapeEventPtr pShapeEvent, *pHead; ShapeEventPtr pShapeEvent, *pHead;
int enabled, rc; int enabled, rc;
xShapeInputSelectedReply rep; xShapeInputSelectedReply rep;
REQUEST_SIZE_MATCH(xShapeInputSelectedReq);
rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess); rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess);
if (rc != Success) if (rc != Success)
return rc; return rc;
@ -932,14 +939,15 @@ ProcShapeInputSelected(ClientPtr client)
static int static int
ProcShapeGetRectangles(ClientPtr client) ProcShapeGetRectangles(ClientPtr client)
{ {
REQUEST(xShapeGetRectanglesReq); REQUEST_HEAD_STRUCT(xShapeGetRectanglesReq);
REQUEST_FIELD_CARD32(window);
WindowPtr pWin; WindowPtr pWin;
xShapeGetRectanglesReply rep; xShapeGetRectanglesReply rep;
xRectangle *rects = NULL; xRectangle *rects = NULL;
int nrects, i, rc; int nrects, i, rc;
RegionPtr region; RegionPtr region;
REQUEST_SIZE_MATCH(xShapeGetRectanglesReq);
rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess); rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess);
if (rc != Success) if (rc != Success)
return rc; return rc;
@ -1062,117 +1070,6 @@ SShapeNotifyEvent(xShapeNotifyEvent * from, xShapeNotifyEvent * to)
to->shaped = from->shaped; to->shaped = from->shaped;
} }
static int _X_COLD
SProcShapeRectangles(ClientPtr client)
{
REQUEST(xShapeRectanglesReq);
REQUEST_AT_LEAST_SIZE(xShapeRectanglesReq);
swapl(&stuff->dest);
swaps(&stuff->xOff);
swaps(&stuff->yOff);
SwapRestS(stuff);
return ProcShapeRectangles(client);
}
static int _X_COLD
SProcShapeMask(ClientPtr client)
{
REQUEST(xShapeMaskReq);
REQUEST_SIZE_MATCH(xShapeMaskReq);
swapl(&stuff->dest);
swaps(&stuff->xOff);
swaps(&stuff->yOff);
swapl(&stuff->src);
return ProcShapeMask(client);
}
static int _X_COLD
SProcShapeCombine(ClientPtr client)
{
REQUEST(xShapeCombineReq);
REQUEST_SIZE_MATCH(xShapeCombineReq);
swapl(&stuff->dest);
swaps(&stuff->xOff);
swaps(&stuff->yOff);
swapl(&stuff->src);
return ProcShapeCombine(client);
}
static int _X_COLD
SProcShapeOffset(ClientPtr client)
{
REQUEST(xShapeOffsetReq);
REQUEST_SIZE_MATCH(xShapeOffsetReq);
swapl(&stuff->dest);
swaps(&stuff->xOff);
swaps(&stuff->yOff);
return ProcShapeOffset(client);
}
static int _X_COLD
SProcShapeQueryExtents(ClientPtr client)
{
REQUEST(xShapeQueryExtentsReq);
REQUEST_SIZE_MATCH(xShapeQueryExtentsReq);
swapl(&stuff->window);
return ProcShapeQueryExtents(client);
}
static int _X_COLD
SProcShapeSelectInput(ClientPtr client)
{
REQUEST(xShapeSelectInputReq);
REQUEST_SIZE_MATCH(xShapeSelectInputReq);
swapl(&stuff->window);
return ProcShapeSelectInput(client);
}
static int _X_COLD
SProcShapeInputSelected(ClientPtr client)
{
REQUEST(xShapeInputSelectedReq);
REQUEST_SIZE_MATCH(xShapeInputSelectedReq);
swapl(&stuff->window);
return ProcShapeInputSelected(client);
}
static int _X_COLD
SProcShapeGetRectangles(ClientPtr client)
{
REQUEST(xShapeGetRectanglesReq);
REQUEST_SIZE_MATCH(xShapeGetRectanglesReq);
swapl(&stuff->window);
return ProcShapeGetRectangles(client);
}
static int _X_COLD
SProcShapeDispatch(ClientPtr client)
{
REQUEST(xReq);
switch (stuff->data) {
case X_ShapeQueryVersion:
return ProcShapeQueryVersion(client);
case X_ShapeRectangles:
return SProcShapeRectangles(client);
case X_ShapeMask:
return SProcShapeMask(client);
case X_ShapeCombine:
return SProcShapeCombine(client);
case X_ShapeOffset:
return SProcShapeOffset(client);
case X_ShapeQueryExtents:
return SProcShapeQueryExtents(client);
case X_ShapeSelectInput:
return SProcShapeSelectInput(client);
case X_ShapeInputSelected:
return SProcShapeInputSelected(client);
case X_ShapeGetRectangles:
return SProcShapeGetRectangles(client);
default:
return BadRequest;
}
}
void void
ShapeExtensionInit(void) ShapeExtensionInit(void)
{ {
@ -1182,7 +1079,7 @@ ShapeExtensionInit(void)
ShapeEventType = CreateNewResourceType(ShapeFreeEvents, "ShapeEvent"); ShapeEventType = CreateNewResourceType(ShapeFreeEvents, "ShapeEvent");
if (ClientType && ShapeEventType && if (ClientType && ShapeEventType &&
(extEntry = AddExtension(SHAPENAME, ShapeNumberEvents, 0, (extEntry = AddExtension(SHAPENAME, ShapeNumberEvents, 0,
ProcShapeDispatch, SProcShapeDispatch, ProcShapeDispatch, ProcShapeDispatch,
NULL, StandardMinorOpcode))) { NULL, StandardMinorOpcode))) {
ShapeEventBase = extEntry->eventBase; ShapeEventBase = extEntry->eventBase;
EventSwapVector[ShapeEventBase] = (EventSwapPtr) SShapeNotifyEvent; EventSwapVector[ShapeEventBase] = (EventSwapPtr) SShapeNotifyEvent;