From 153361bdc9b34c3af6b304d13901d0257283d95b Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Mon, 8 Jul 2024 17:23:43 +0200 Subject: [PATCH] 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 --- Xext/xres.c | 102 ++++++---------------------------------------------- 1 file changed, 11 insertions(+), 91 deletions(-) diff --git a/Xext/xres.c b/Xext/xres.c index d3973cc9f..f550c5f57 100644 --- a/Xext/xres.c +++ b/Xext/xres.c @@ -12,6 +12,7 @@ #include #include "dix/registry_priv.h" +#include "dix/request_priv.h" #include "dix/resource_priv.h" #include "os/client_priv.h" #include "Xext/xace.h" @@ -202,7 +203,7 @@ ProcXResQueryVersion(ClientPtr client) static int ProcXResQueryClients(ClientPtr client) { - REQUEST_SIZE_MATCH(xXResQueryClientsReq); + REQUEST_HEAD_STRUCT(xXResQueryClientsReq); int i, num_clients = 0; @@ -281,8 +282,8 @@ resourceTypeAtom(int i) static int ProcXResQueryClientResources(ClientPtr client) { - REQUEST(xXResQueryClientResourcesReq); - REQUEST_SIZE_MATCH(xXResQueryClientResourcesReq); + REQUEST_HEAD_STRUCT(xXResQueryClientResourcesReq); + REQUEST_FIELD_CARD32(xid); ClientPtr resClient = dixClientForXID(stuff->xid); @@ -361,8 +362,8 @@ ResFindResourcePixmaps(void *value, XID id, RESTYPE type, void *cdata) static int ProcXResQueryClientPixmapBytes(ClientPtr client) { - REQUEST(xXResQueryClientPixmapBytesReq); - REQUEST_SIZE_MATCH(xXResQueryClientPixmapBytesReq); + REQUEST_HEAD_STRUCT(xXResQueryClientPixmapBytesReq); + REQUEST_FIELD_CARD32(xid); ClientPtr owner = dixClientForXID(stuff->xid); if ((!owner) || @@ -553,7 +554,8 @@ ConstructClientIds(ClientPtr client, static int ProcXResQueryClientIds (ClientPtr client) { - REQUEST(xXResQueryClientIdsReq); + REQUEST_HEAD_AT_LEAST(xXResQueryClientIdsReq); + REQUEST_FIELD_CARD32(numSpecs); xXResClientIdSpec *specs = (void*) ((char*) stuff + sizeof(*stuff)); int rc; @@ -561,7 +563,6 @@ ProcXResQueryClientIds (ClientPtr client) InitConstructClientIdCtx(&ctx); - REQUEST_AT_LEAST_SIZE(xXResQueryClientIdsReq); REQUEST_FIXED_SIZE(xXResQueryClientIdsReq, stuff->numSpecs * sizeof(specs[0])); @@ -931,8 +932,8 @@ ConstructResourceBytes(XID aboutClient, static int ProcXResQueryResourceBytes (ClientPtr client) { - REQUEST(xXResQueryResourceBytesReq); - REQUEST_AT_LEAST_SIZE(xXResQueryResourceBytesReq); + REQUEST_HEAD_AT_LEAST(xXResQueryResourceBytesReq); + REQUEST_FIELD_CARD32(numSpecs); int rc; ConstructResourceBytesCtx ctx; @@ -1008,91 +1009,10 @@ ProcResDispatch(ClientPtr client) 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 ResExtensionInit(void) { (void) AddExtension(XRES_NAME, 0, 0, - ProcResDispatch, SProcResDispatch, + ProcResDispatch, ProcResDispatch, NULL, StandardMinorOpcode); }