Xext: xcmisc: 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-08 15:20:03 +02:00
parent 0bf0da7b90
commit 6f360d77bb

View File

@ -33,6 +33,7 @@ from The Open Group.
#include <X11/Xproto.h>
#include <X11/extensions/xcmiscproto.h>
#include "dix/request_priv.h"
#include "dix/resource_priv.h"
#include "misc.h"
@ -45,6 +46,11 @@ from The Open Group.
static int
ProcXCMiscGetVersion(ClientPtr client)
{
REQUEST_HEAD_STRUCT(xXCMiscGetVersionReq);
REQUEST_SIZE_MATCH(xXCMiscGetVersionReq);
REQUEST_FIELD_CARD16(majorVersion);
REQUEST_FIELD_CARD16(minorVersion);
xXCMiscGetVersionReply rep = {
.type = X_Reply,
.sequenceNumber = client->sequence,
@ -53,8 +59,6 @@ ProcXCMiscGetVersion(ClientPtr client)
.minorVersion = XCMiscMinorVersion
};
REQUEST_SIZE_MATCH(xXCMiscGetVersionReq);
if (client->swapped) {
swaps(&rep.sequenceNumber);
swaps(&rep.majorVersion);
@ -67,10 +71,10 @@ ProcXCMiscGetVersion(ClientPtr client)
static int
ProcXCMiscGetXIDRange(ClientPtr client)
{
REQUEST_HEAD_STRUCT(xXCMiscGetXIDRangeReq);
xXCMiscGetXIDRangeReply rep;
XID min_id, max_id;
REQUEST_SIZE_MATCH(xXCMiscGetXIDRangeReq);
GetXIDRange(client->index, FALSE, &min_id, &max_id);
rep = (xXCMiscGetXIDRangeReply) {
.type = X_Reply,
@ -91,13 +95,14 @@ ProcXCMiscGetXIDRange(ClientPtr client)
static int
ProcXCMiscGetXIDList(ClientPtr client)
{
REQUEST(xXCMiscGetXIDListReq);
REQUEST_HEAD_STRUCT(xXCMiscGetXIDListReq);
REQUEST_FIELD_CARD16(length);
REQUEST_FIELD_CARD32(count);
xXCMiscGetXIDListReply rep;
XID *pids;
unsigned int count;
REQUEST_SIZE_MATCH(xXCMiscGetXIDListReq);
if (stuff->count > UINT32_MAX / sizeof(XID))
return BadAlloc;
@ -142,46 +147,10 @@ ProcXCMiscDispatch(ClientPtr client)
}
}
static int _X_COLD
SProcXCMiscGetVersion(ClientPtr client)
{
REQUEST(xXCMiscGetVersionReq);
REQUEST_SIZE_MATCH(xXCMiscGetVersionReq);
swaps(&stuff->majorVersion);
swaps(&stuff->minorVersion);
return ProcXCMiscGetVersion(client);
}
static int _X_COLD
SProcXCMiscGetXIDList(ClientPtr client)
{
REQUEST(xXCMiscGetXIDListReq);
REQUEST_SIZE_MATCH(xXCMiscGetXIDListReq);
swapl(&stuff->count);
return ProcXCMiscGetXIDList(client);
}
static int _X_COLD
SProcXCMiscDispatch(ClientPtr client)
{
REQUEST(xReq);
switch (stuff->data) {
case X_XCMiscGetVersion:
return SProcXCMiscGetVersion(client);
case X_XCMiscGetXIDRange:
return ProcXCMiscGetXIDRange(client);
case X_XCMiscGetXIDList:
return SProcXCMiscGetXIDList(client);
default:
return BadRequest;
}
}
void
XCMiscExtensionInit(void)
{
AddExtension(XCMiscExtensionName, 0, 0,
ProcXCMiscDispatch, SProcXCMiscDispatch,
ProcXCMiscDispatch, ProcXCMiscDispatch,
NULL, StandardMinorOpcode);
}