xfixes: 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-12 12:45:55 +02:00
parent f3b783ec3d
commit d5e3eaeba2
6 changed files with 136 additions and 261 deletions

View File

@@ -259,17 +259,13 @@ XFixesSelectCursorInput(ClientPtr pClient, WindowPtr pWindow, CARD32 eventMask)
int
ProcXFixesSelectCursorInput(ClientPtr client)
{
REQUEST(xXFixesSelectCursorInputReq);
X_REQUEST_HEAD_STRUCT(xXFixesSelectCursorInputReq);
X_REQUEST_FIELD_CARD32(window);
X_REQUEST_FIELD_CARD32(eventMask);
WindowPtr pWin;
int rc;
REQUEST_SIZE_MATCH(xXFixesSelectCursorInputReq);
if (client->swapped) {
swapl(&stuff->window);
swapl(&stuff->eventMask);
}
rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess);
if (rc != Success)
return rc;
@@ -351,11 +347,11 @@ CopyCursorToImage(CursorPtr pCursor, CARD32 *image)
int
ProcXFixesGetCursorImage(ClientPtr client)
{
/* REQUEST(xXFixesGetCursorImageReq); */
X_REQUEST_HEAD_STRUCT(xXFixesGetCursorImageReq);
CursorPtr pCursor;
int npixels, width, height, rc, x, y;
REQUEST_SIZE_MATCH(xXFixesGetCursorImageReq);
pCursor = CursorForClient(client);
if (!pCursor)
return BadCursor;
@@ -406,17 +402,13 @@ ProcXFixesSetCursorName(ClientPtr client)
{
CursorPtr pCursor;
char *tchar;
REQUEST(xXFixesSetCursorNameReq);
Atom atom;
X_REQUEST_HEAD_AT_LEAST(xXFixesSetCursorNameReq);
X_REQUEST_FIELD_CARD32(cursor);
X_REQUEST_FIELD_CARD16(nbytes);
REQUEST_FIXED_SIZE(xXFixesSetCursorNameReq, stuff->nbytes);
if (client->swapped) {
swapl(&stuff->cursor);
swaps(&stuff->nbytes);
}
VERIFY_CURSOR(pCursor, stuff->cursor, client, DixSetAttrAccess);
tchar = (char *) &stuff[1];
atom = MakeAtom(tchar, stuff->nbytes, TRUE);
@@ -430,16 +422,12 @@ ProcXFixesSetCursorName(ClientPtr client)
int
ProcXFixesGetCursorName(ClientPtr client)
{
REQUEST(xXFixesGetCursorNameReq);
X_REQUEST_HEAD_STRUCT(xXFixesGetCursorNameReq);
X_REQUEST_FIELD_CARD32(cursor);
CursorPtr pCursor;
const char *str;
REQUEST_SIZE_MATCH(xXFixesGetCursorNameReq);
if (client->swapped)
swapl(&stuff->cursor);
VERIFY_CURSOR(pCursor, stuff->cursor, client, DixGetAttrAccess);
if (pCursor->name)
str = NameForAtom(pCursor->name);
@@ -464,14 +452,14 @@ ProcXFixesGetCursorName(ClientPtr client)
int
ProcXFixesGetCursorImageAndName(ClientPtr client)
{
/* REQUEST(xXFixesGetCursorImageAndNameReq); */
X_REQUEST_HEAD_STRUCT(xXFixesGetCursorImageAndNameReq);
CursorPtr pCursor;
int npixels;
const char *name;
int width, height;
int rc, x, y;
REQUEST_SIZE_MATCH(xXFixesGetCursorImageAndNameReq);
pCursor = CursorForClient(client);
if (!pCursor)
return BadCursor;
@@ -634,13 +622,9 @@ ProcXFixesChangeCursor(ClientPtr client)
{
CursorPtr pSource, pDestination;
REQUEST(xXFixesChangeCursorReq);
REQUEST_SIZE_MATCH(xXFixesChangeCursorReq);
if (client->swapped) {
swapl(&stuff->source);
swapl(&stuff->destination);
}
X_REQUEST_HEAD_STRUCT(xXFixesChangeCursorReq);
X_REQUEST_FIELD_CARD32(source);
X_REQUEST_FIELD_CARD32(destination);
VERIFY_CURSOR(pSource, stuff->source, client,
DixReadAccess | DixGetAttrAccess);
@@ -662,18 +646,15 @@ TestForCursorName(CursorPtr pCursor, void *closure)
int
ProcXFixesChangeCursorByName(ClientPtr client)
{
X_REQUEST_HEAD_AT_LEAST(xXFixesChangeCursorByNameReq);
X_REQUEST_FIELD_CARD32(source);
X_REQUEST_FIELD_CARD16(nbytes);
REQUEST_FIXED_SIZE(xXFixesChangeCursorByNameReq, stuff->nbytes);
CursorPtr pSource;
Atom name;
char *tchar;
REQUEST(xXFixesChangeCursorByNameReq);
REQUEST_FIXED_SIZE(xXFixesChangeCursorByNameReq, stuff->nbytes);
if (client->swapped) {
swapl(&stuff->source);
swaps(&stuff->nbytes);
}
VERIFY_CURSOR(pSource, stuff->source, client,
DixReadAccess | DixGetAttrAccess);
tchar = (char *) &stuff[1];
@@ -779,17 +760,13 @@ deleteCursorHideCountsForScreen(ScreenPtr pScreen)
int
ProcXFixesHideCursor(ClientPtr client)
{
X_REQUEST_HEAD_STRUCT(xXFixesHideCursorReq);
X_REQUEST_FIELD_CARD32(window);
WindowPtr pWin;
CursorHideCountPtr pChc;
REQUEST(xXFixesHideCursorReq);
int ret;
REQUEST_SIZE_MATCH(xXFixesHideCursorReq);
if (client->swapped)
swapl(&stuff->window);
ret = dixLookupResourceByType((void **) &pWin, stuff->window, X11_RESTYPE_WINDOW,
client, DixGetAttrAccess);
if (ret != Success) {
@@ -834,16 +811,13 @@ ProcXFixesHideCursor(ClientPtr client)
int
ProcXFixesShowCursor(ClientPtr client)
{
X_REQUEST_HEAD_STRUCT(xXFixesShowCursorReq);
X_REQUEST_FIELD_CARD32(window);
WindowPtr pWin;
CursorHideCountPtr pChc;
int rc;
REQUEST(xXFixesShowCursorReq);
REQUEST_SIZE_MATCH(xXFixesShowCursorReq);
if (client->swapped)
swapl(&stuff->window);
rc = dixLookupResourceByType((void **) &pWin, stuff->window, X11_RESTYPE_WINDOW,
client, DixGetAttrAccess);
if (rc != Success) {
@@ -922,31 +896,17 @@ CursorFreeWindow(void *data, XID id)
int
ProcXFixesCreatePointerBarrier(ClientPtr client)
{
REQUEST(xXFixesCreatePointerBarrierReq);
X_REQUEST_HEAD_AT_LEAST(xXFixesCreatePointerBarrierReq);
if (client->swapped) {
REQUEST_AT_LEAST_SIZE(xXFixesCreatePointerBarrierReq);
swaps(&stuff->num_devices);
REQUEST_FIXED_SIZE(xXFixesCreatePointerBarrierReq,
pad_to_int32(stuff->num_devices * sizeof(CARD16)));
swapl(&stuff->barrier);
swapl(&stuff->window);
swaps(&stuff->x1);
swaps(&stuff->y1);
swaps(&stuff->x2);
swaps(&stuff->y2);
swapl(&stuff->directions);
CARD16 *in_devices = (CARD16 *) &stuff[1];
for (int i = 0; i < stuff->num_devices; i++) {
swaps(in_devices + i);
}
}
REQUEST_FIXED_SIZE(xXFixesCreatePointerBarrierReq,
pad_to_int32(stuff->num_devices * sizeof(CARD16)));
X_REQUEST_FIELD_CARD16(num_devices);
X_REQUEST_FIELD_CARD32(barrier);
X_REQUEST_FIELD_CARD32(window);
X_REQUEST_FIELD_CARD16(x1);
X_REQUEST_FIELD_CARD16(y1);
X_REQUEST_FIELD_CARD16(x2);
X_REQUEST_FIELD_CARD16(y2);
X_REQUEST_FIELD_CARD32(directions);
X_REQUEST_REST_COUNT_CARD16(stuff->num_devices);
LEGAL_NEW_RESOURCE(stuff->barrier, client);
@@ -956,12 +916,8 @@ ProcXFixesCreatePointerBarrier(ClientPtr client)
int
ProcXFixesDestroyPointerBarrier(ClientPtr client)
{
REQUEST(xXFixesDestroyPointerBarrierReq);
REQUEST_SIZE_MATCH(xXFixesDestroyPointerBarrierReq);
if (client->swapped)
swapl(&stuff->barrier);
X_REQUEST_HEAD_STRUCT(xXFixesDestroyPointerBarrierReq);
X_REQUEST_FIELD_CARD32(barrier);
return XIDestroyPointerBarrier(client, stuff);
}