From 62687ea1c2d5231a8626a37d882f5b56f8837dad Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Fri, 4 Apr 2025 17:43:57 +0200 Subject: [PATCH] dix: write out X_ListHosts reply directly No need for using a complex callback machinery, if we just move the little pieces of byte-swapping directly into the request handler. Signed-off-by: Enrico Weigelt, metux IT consult --- dix/dispatch.c | 26 ++++++++++++++++++++------ dix/swaprep.c | 25 ------------------------- dix/tables.c | 2 +- include/swaprep.h | 8 -------- 4 files changed, 21 insertions(+), 40 deletions(-) diff --git a/dix/dispatch.c b/dix/dispatch.c index d7deddacc..f376e8f69 100644 --- a/dix/dispatch.c +++ b/dix/dispatch.c @@ -3349,7 +3349,6 @@ ProcChangeHosts(ClientPtr client) int ProcListHosts(ClientPtr client) { - xListHostsReply reply; int len, nHosts, result; BOOL enabled; void *pdata; @@ -3367,18 +3366,33 @@ ProcListHosts(ClientPtr client) if (result != Success) return result; - reply = (xListHostsReply) { + xListHostsReply rep = { .type = X_Reply, .enabled = enabled, .sequenceNumber = client->sequence, .length = bytes_to_int32(len), .nHosts = nHosts }; - WriteReplyToClient(client, sizeof(xListHostsReply), &reply); - if (nHosts) { - client->pSwapReplyFunc = (ReplySwapPtr) SLHostsExtend; - WriteSwappedDataToClient(client, len, pdata); + + if (client->swapped) { + char *bufT = pdata; + char *endbuf = bufT + len; + + while (bufT < endbuf) { + xHostEntry *host = (xHostEntry *) bufT; + int l1 = host->length; + swaps(&host->length); + bufT += sizeof(xHostEntry) + pad_to_int32(l1); + } + + swaps(&rep.sequenceNumber); + swapl(&rep.length); + swaps(&rep.nHosts); } + + WriteToClient(client, sizeof(rep), &rep); + WriteToClient(client, len, pdata); + free(pdata); return Success; } diff --git a/dix/swaprep.c b/dix/swaprep.c index 2e90b8aea..3290b19c3 100644 --- a/dix/swaprep.c +++ b/dix/swaprep.c @@ -318,31 +318,6 @@ SListExtensionsReply(ClientPtr pClient, int size, xListExtensionsReply * pRep) WriteToClient(pClient, size, pRep); } -void _X_COLD -SLHostsExtend(ClientPtr pClient, int size, char *buf) -{ - char *bufT = buf; - char *endbuf = buf + size; - - while (bufT < endbuf) { - xHostEntry *host = (xHostEntry *) bufT; - int len = host->length; - - swaps(&host->length); - bufT += sizeof(xHostEntry) + pad_to_int32(len); - } - WriteToClient(pClient, size, buf); -} - -void _X_COLD -SListHostsReply(ClientPtr pClient, int size, xListHostsReply * pRep) -{ - swaps(&pRep->sequenceNumber); - swapl(&pRep->length); - swaps(&pRep->nHosts); - WriteToClient(pClient, size, pRep); -} - void _X_COLD SErrorEvent(xError * from, xError * to) { diff --git a/dix/tables.c b/dix/tables.c index b91922e8c..fec7166a1 100644 --- a/dix/tables.c +++ b/dix/tables.c @@ -825,7 +825,7 @@ ReplySwapPtr ReplySwapVector[256] = { ReplyNotSwappd, ReplyNotSwappd, ReplyNotSwappd, - (ReplySwapPtr) SListHostsReply, /* 110 */ + ReplyNotSwappd, /* 110 */ ReplyNotSwappd, ReplyNotSwappd, ReplyNotSwappd, diff --git a/include/swaprep.h b/include/swaprep.h index 32aed61bc..58ce54cc5 100644 --- a/include/swaprep.h +++ b/include/swaprep.h @@ -72,14 +72,6 @@ extern void SListExtensionsReply(ClientPtr /* pClient */ , int /* size */ , xListExtensionsReply * /* pRep */ ); -extern void SLHostsExtend(ClientPtr /* pClient */ , - int /* size */ , - char * /* buf */ ); - -extern void SListHostsReply(ClientPtr /* pClient */ , - int /* size */ , - xListHostsReply * /* pRep */ ); - extern void SErrorEvent(xError * /* from */ , xError * /* to */ );