Xext: xres: 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 17:23:43 +02:00
parent fcb1bac94c
commit 153361bdc9

View File

@ -12,6 +12,7 @@
#include <X11/extensions/XResproto.h> #include <X11/extensions/XResproto.h>
#include "dix/registry_priv.h" #include "dix/registry_priv.h"
#include "dix/request_priv.h"
#include "dix/resource_priv.h" #include "dix/resource_priv.h"
#include "os/client_priv.h" #include "os/client_priv.h"
#include "Xext/xace.h" #include "Xext/xace.h"
@ -202,7 +203,7 @@ ProcXResQueryVersion(ClientPtr client)
static int static int
ProcXResQueryClients(ClientPtr client) ProcXResQueryClients(ClientPtr client)
{ {
REQUEST_SIZE_MATCH(xXResQueryClientsReq); REQUEST_HEAD_STRUCT(xXResQueryClientsReq);
int i, num_clients = 0; int i, num_clients = 0;
@ -281,8 +282,8 @@ resourceTypeAtom(int i)
static int static int
ProcXResQueryClientResources(ClientPtr client) ProcXResQueryClientResources(ClientPtr client)
{ {
REQUEST(xXResQueryClientResourcesReq); REQUEST_HEAD_STRUCT(xXResQueryClientResourcesReq);
REQUEST_SIZE_MATCH(xXResQueryClientResourcesReq); REQUEST_FIELD_CARD32(xid);
ClientPtr resClient = dixClientForXID(stuff->xid); ClientPtr resClient = dixClientForXID(stuff->xid);
@ -361,8 +362,8 @@ ResFindResourcePixmaps(void *value, XID id, RESTYPE type, void *cdata)
static int static int
ProcXResQueryClientPixmapBytes(ClientPtr client) ProcXResQueryClientPixmapBytes(ClientPtr client)
{ {
REQUEST(xXResQueryClientPixmapBytesReq); REQUEST_HEAD_STRUCT(xXResQueryClientPixmapBytesReq);
REQUEST_SIZE_MATCH(xXResQueryClientPixmapBytesReq); REQUEST_FIELD_CARD32(xid);
ClientPtr owner = dixClientForXID(stuff->xid); ClientPtr owner = dixClientForXID(stuff->xid);
if ((!owner) || if ((!owner) ||
@ -553,7 +554,8 @@ ConstructClientIds(ClientPtr client,
static int static int
ProcXResQueryClientIds (ClientPtr client) ProcXResQueryClientIds (ClientPtr client)
{ {
REQUEST(xXResQueryClientIdsReq); REQUEST_HEAD_AT_LEAST(xXResQueryClientIdsReq);
REQUEST_FIELD_CARD32(numSpecs);
xXResClientIdSpec *specs = (void*) ((char*) stuff + sizeof(*stuff)); xXResClientIdSpec *specs = (void*) ((char*) stuff + sizeof(*stuff));
int rc; int rc;
@ -561,7 +563,6 @@ ProcXResQueryClientIds (ClientPtr client)
InitConstructClientIdCtx(&ctx); InitConstructClientIdCtx(&ctx);
REQUEST_AT_LEAST_SIZE(xXResQueryClientIdsReq);
REQUEST_FIXED_SIZE(xXResQueryClientIdsReq, REQUEST_FIXED_SIZE(xXResQueryClientIdsReq,
stuff->numSpecs * sizeof(specs[0])); stuff->numSpecs * sizeof(specs[0]));
@ -931,8 +932,8 @@ ConstructResourceBytes(XID aboutClient,
static int static int
ProcXResQueryResourceBytes (ClientPtr client) ProcXResQueryResourceBytes (ClientPtr client)
{ {
REQUEST(xXResQueryResourceBytesReq); REQUEST_HEAD_AT_LEAST(xXResQueryResourceBytesReq);
REQUEST_AT_LEAST_SIZE(xXResQueryResourceBytesReq); REQUEST_FIELD_CARD32(numSpecs);
int rc; int rc;
ConstructResourceBytesCtx ctx; ConstructResourceBytesCtx ctx;
@ -1008,91 +1009,10 @@ ProcResDispatch(ClientPtr client)
return BadRequest; return BadRequest;
} }
static int _X_COLD
SProcXResQueryVersion(ClientPtr client)
{
REQUEST_SIZE_MATCH(xXResQueryVersionReq);
return ProcXResQueryVersion(client);
}
static int _X_COLD
SProcXResQueryClientResources(ClientPtr client)
{
REQUEST(xXResQueryClientResourcesReq);
REQUEST_SIZE_MATCH(xXResQueryClientResourcesReq);
swapl(&stuff->xid);
return ProcXResQueryClientResources(client);
}
static int _X_COLD
SProcXResQueryClientPixmapBytes(ClientPtr client)
{
REQUEST(xXResQueryClientPixmapBytesReq);
REQUEST_SIZE_MATCH(xXResQueryClientPixmapBytesReq);
swapl(&stuff->xid);
return ProcXResQueryClientPixmapBytes(client);
}
static int _X_COLD
SProcXResQueryClientIds (ClientPtr client)
{
REQUEST(xXResQueryClientIdsReq);
REQUEST_AT_LEAST_SIZE (xXResQueryClientIdsReq);
swapl(&stuff->numSpecs);
return ProcXResQueryClientIds(client);
}
/** @brief Implements the XResQueryResourceBytes of XResProto v1.2.
This variant byteswaps request contents before issuing the
rest of the work to ProcXResQueryResourceBytes */
static int _X_COLD
SProcXResQueryResourceBytes (ClientPtr client)
{
REQUEST(xXResQueryResourceBytesReq);
int c;
xXResResourceIdSpec *specs = (void*) ((char*) stuff + sizeof(*stuff));
REQUEST_AT_LEAST_SIZE(xXResQueryResourceBytesReq);
swapl(&stuff->numSpecs);
REQUEST_FIXED_SIZE(xXResQueryResourceBytesReq,
stuff->numSpecs * sizeof(specs[0]));
for (c = 0; c < stuff->numSpecs; ++c) {
SwapXResResourceIdSpec(specs + c);
}
return ProcXResQueryResourceBytes(client);
}
static int _X_COLD
SProcResDispatch (ClientPtr client)
{
REQUEST(xReq);
switch (stuff->data) {
case X_XResQueryVersion:
return SProcXResQueryVersion(client);
case X_XResQueryClients: /* nothing to swap */
return ProcXResQueryClients(client);
case X_XResQueryClientResources:
return SProcXResQueryClientResources(client);
case X_XResQueryClientPixmapBytes:
return SProcXResQueryClientPixmapBytes(client);
case X_XResQueryClientIds:
return SProcXResQueryClientIds(client);
case X_XResQueryResourceBytes:
return SProcXResQueryResourceBytes(client);
default: break;
}
return BadRequest;
}
void void
ResExtensionInit(void) ResExtensionInit(void)
{ {
(void) AddExtension(XRES_NAME, 0, 0, (void) AddExtension(XRES_NAME, 0, 0,
ProcResDispatch, SProcResDispatch, ProcResDispatch, ProcResDispatch,
NULL, StandardMinorOpcode); NULL, StandardMinorOpcode);
} }