Xext: saver: 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-02 21:55:36 +02:00
parent 428855b0df
commit 0fde105e38

View File

@ -36,6 +36,7 @@ in this Software without prior written authorization from the X Consortium.
#include "dix/colormap_priv.h" #include "dix/colormap_priv.h"
#include "dix/cursor_priv.h" #include "dix/cursor_priv.h"
#include "dix/dix_priv.h" #include "dix/dix_priv.h"
#include "dix/request_priv.h"
#include "dix/window_priv.h" #include "dix/window_priv.h"
#include "os/osdep.h" #include "os/osdep.h"
#include "os/screensaver.h" #include "os/screensaver.h"
@ -591,6 +592,8 @@ ScreenSaverHandle(ScreenPtr pScreen, int xstate, Bool force)
static int static int
ProcScreenSaverQueryVersion(ClientPtr client) ProcScreenSaverQueryVersion(ClientPtr client)
{ {
REQUEST_HEAD_STRUCT(xScreenSaverQueryVersionReq);
xScreenSaverQueryVersionReply rep = { xScreenSaverQueryVersionReply rep = {
.type = X_Reply, .type = X_Reply,
.sequenceNumber = client->sequence, .sequenceNumber = client->sequence,
@ -598,8 +601,6 @@ ProcScreenSaverQueryVersion(ClientPtr client)
.minorVersion = SERVER_SAVER_MINOR_VERSION .minorVersion = SERVER_SAVER_MINOR_VERSION
}; };
REQUEST_SIZE_MATCH(xScreenSaverQueryVersionReq);
if (client->swapped) { if (client->swapped) {
swaps(&rep.sequenceNumber); swaps(&rep.sequenceNumber);
swaps(&rep.majorVersion); swaps(&rep.majorVersion);
@ -612,14 +613,15 @@ ProcScreenSaverQueryVersion(ClientPtr client)
static int static int
ProcScreenSaverQueryInfo(ClientPtr client) ProcScreenSaverQueryInfo(ClientPtr client)
{ {
REQUEST(xScreenSaverQueryInfoReq); REQUEST_HEAD_STRUCT(xScreenSaverQueryInfoReq);
REQUEST_FIELD_CARD32(drawable);
int rc; int rc;
ScreenSaverStuffPtr pSaver; ScreenSaverStuffPtr pSaver;
DrawablePtr pDraw; DrawablePtr pDraw;
CARD32 lastInput; CARD32 lastInput;
ScreenSaverScreenPrivatePtr pPriv; ScreenSaverScreenPrivatePtr pPriv;
REQUEST_SIZE_MATCH(xScreenSaverQueryInfoReq);
rc = dixLookupDrawable(&pDraw, stuff->drawable, client, 0, rc = dixLookupDrawable(&pDraw, stuff->drawable, client, 0,
DixGetAttrAccess); DixGetAttrAccess);
if (rc != Success) if (rc != Success)
@ -676,11 +678,12 @@ ProcScreenSaverQueryInfo(ClientPtr client)
static int static int
ProcScreenSaverSelectInput(ClientPtr client) ProcScreenSaverSelectInput(ClientPtr client)
{ {
REQUEST(xScreenSaverSelectInputReq); REQUEST_HEAD_STRUCT(xScreenSaverSelectInputReq);
REQUEST_FIELD_CARD32(drawable);
REQUEST_FIELD_CARD32(eventMask);
DrawablePtr pDraw; DrawablePtr pDraw;
int rc; int rc;
REQUEST_SIZE_MATCH(xScreenSaverSelectInputReq);
rc = dixLookupDrawable(&pDraw, stuff->drawable, client, 0, rc = dixLookupDrawable(&pDraw, stuff->drawable, client, 0,
DixGetAttrAccess); DixGetAttrAccess);
if (rc != Success) if (rc != Success)
@ -1058,8 +1061,16 @@ ScreenSaverUnsetAttributes(ClientPtr client, Drawable drawable)
static int static int
ProcScreenSaverSetAttributes(ClientPtr client) ProcScreenSaverSetAttributes(ClientPtr client)
{ {
REQUEST(xScreenSaverSetAttributesReq); REQUEST_HEAD_AT_LEAST(xScreenSaverSetAttributesReq);
REQUEST_AT_LEAST_SIZE(xScreenSaverSetAttributesReq); REQUEST_FIELD_CARD32(drawable);
REQUEST_FIELD_CARD16(x);
REQUEST_FIELD_CARD16(y);
REQUEST_FIELD_CARD16(width);
REQUEST_FIELD_CARD16(height);
REQUEST_FIELD_CARD16(borderWidth);
REQUEST_FIELD_CARD32(visualID);
REQUEST_FIELD_CARD32(mask);
REQUEST_REST_CARD32();
#ifdef XINERAMA #ifdef XINERAMA
if (!noPanoramiXExtension) { if (!noPanoramiXExtension) {
@ -1145,8 +1156,8 @@ ProcScreenSaverSetAttributes(ClientPtr client)
static int static int
ProcScreenSaverUnsetAttributes(ClientPtr client) ProcScreenSaverUnsetAttributes(ClientPtr client)
{ {
REQUEST(xScreenSaverUnsetAttributesReq); REQUEST_HEAD_STRUCT(xScreenSaverUnsetAttributesReq);
REQUEST_SIZE_MATCH(xScreenSaverUnsetAttributesReq); REQUEST_FIELD_CARD32(drawable);
#ifdef XINERAMA #ifdef XINERAMA
if (!noPanoramiXExtension) { if (!noPanoramiXExtension) {
@ -1173,12 +1184,11 @@ ProcScreenSaverUnsetAttributes(ClientPtr client)
static int static int
ProcScreenSaverSuspend(ClientPtr client) ProcScreenSaverSuspend(ClientPtr client)
{ {
REQUEST_HEAD_STRUCT(xScreenSaverSuspendReq);
REQUEST_FIELD_CARD32(suspend);
ScreenSaverSuspensionPtr *prev, this; ScreenSaverSuspensionPtr *prev, this;
BOOL suspend; BOOL suspend;
REQUEST(xScreenSaverSuspendReq);
REQUEST_SIZE_MATCH(xScreenSaverSuspendReq);
/* /*
* Old versions of XCB encode suspend as 1 byte followed by three * Old versions of XCB encode suspend as 1 byte followed by three
* pad bytes (which are always cleared), instead of a 4 byte * pad bytes (which are always cleared), instead of a 4 byte
@ -1257,82 +1267,6 @@ ProcScreenSaverDispatch(ClientPtr client)
} }
} }
static int _X_COLD
SProcScreenSaverQueryInfo(ClientPtr client)
{
REQUEST(xScreenSaverQueryInfoReq);
REQUEST_SIZE_MATCH(xScreenSaverQueryInfoReq);
swapl(&stuff->drawable);
return ProcScreenSaverQueryInfo(client);
}
static int _X_COLD
SProcScreenSaverSelectInput(ClientPtr client)
{
REQUEST(xScreenSaverSelectInputReq);
REQUEST_SIZE_MATCH(xScreenSaverSelectInputReq);
swapl(&stuff->drawable);
swapl(&stuff->eventMask);
return ProcScreenSaverSelectInput(client);
}
static int _X_COLD
SProcScreenSaverSetAttributes(ClientPtr client)
{
REQUEST(xScreenSaverSetAttributesReq);
REQUEST_AT_LEAST_SIZE(xScreenSaverSetAttributesReq);
swapl(&stuff->drawable);
swaps(&stuff->x);
swaps(&stuff->y);
swaps(&stuff->width);
swaps(&stuff->height);
swaps(&stuff->borderWidth);
swapl(&stuff->visualID);
swapl(&stuff->mask);
SwapRestL(stuff);
return ProcScreenSaverSetAttributes(client);
}
static int _X_COLD
SProcScreenSaverUnsetAttributes(ClientPtr client)
{
REQUEST(xScreenSaverUnsetAttributesReq);
REQUEST_SIZE_MATCH(xScreenSaverUnsetAttributesReq);
swapl(&stuff->drawable);
return ProcScreenSaverUnsetAttributes(client);
}
static int _X_COLD
SProcScreenSaverSuspend(ClientPtr client)
{
REQUEST(xScreenSaverSuspendReq);
REQUEST_SIZE_MATCH(xScreenSaverSuspendReq);
swapl(&stuff->suspend);
return ProcScreenSaverSuspend(client);
}
static int _X_COLD
SProcScreenSaverDispatch(ClientPtr client)
{
REQUEST(xReq);
switch (stuff->data) {
case X_ScreenSaverQueryVersion:
return ProcScreenSaverQueryVersion(client);
case X_ScreenSaverQueryInfo:
return SProcScreenSaverQueryInfo(client);
case X_ScreenSaverSelectInput:
return SProcScreenSaverSelectInput(client);
case X_ScreenSaverSetAttributes:
return SProcScreenSaverSetAttributes(client);
case X_ScreenSaverUnsetAttributes:
return SProcScreenSaverUnsetAttributes(client);
case X_ScreenSaverSuspend:
return SProcScreenSaverSuspend(client);
default:
return BadRequest;
}
}
void void
ScreenSaverExtensionInit(void) ScreenSaverExtensionInit(void)
{ {
@ -1354,7 +1288,7 @@ ScreenSaverExtensionInit(void)
if (AttrType && SaverEventType && SuspendType && if (AttrType && SaverEventType && SuspendType &&
(extEntry = AddExtension(ScreenSaverName, ScreenSaverNumberEvents, 0, (extEntry = AddExtension(ScreenSaverName, ScreenSaverNumberEvents, 0,
ProcScreenSaverDispatch, ProcScreenSaverDispatch,
SProcScreenSaverDispatch, NULL, ProcScreenSaverDispatch, NULL,
StandardMinorOpcode))) { StandardMinorOpcode))) {
ScreenSaverEventBase = extEntry->eventBase; ScreenSaverEventBase = extEntry->eventBase;
EventSwapVector[ScreenSaverEventBase] = EventSwapVector[ScreenSaverEventBase] =