mirror of
https://github.com/X11Libre/xserver.git
synced 2026-04-14 17:18:09 +00:00
xres: ProcXResQueryClients(): use x_rpcbuf_t
use x_rpcbuf_t for reply payload assembly and byte-swapping. Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
committed by
Enrico Weigelt
parent
96129e44bd
commit
c10baabc89
42
Xext/xres.c
42
Xext/xres.c
@@ -205,56 +205,34 @@ ProcXResQueryClients(ClientPtr client)
|
||||
{
|
||||
REQUEST_SIZE_MATCH(xXResQueryClientsReq);
|
||||
|
||||
int *current_clients = calloc(currentMaxClients, sizeof(int));
|
||||
if (!current_clients)
|
||||
return BadAlloc;
|
||||
x_rpcbuf_t rpcbuf = { .swapped = client->swapped, .err_clear = TRUE };
|
||||
|
||||
int num_clients = 0;
|
||||
for (int i = 0; i < currentMaxClients; i++) {
|
||||
if (clients[i]) {
|
||||
if (XaceHookClientAccess(client, clients[i], DixReadAccess) == Success) {
|
||||
current_clients[num_clients] = i;
|
||||
num_clients++;
|
||||
}
|
||||
ClientPtr walkClient = clients[i];
|
||||
if (walkClient &&
|
||||
(XaceHookClientAccess(client, walkClient, DixReadAccess) == Success)) {
|
||||
x_rpcbuf_write_CARD32(&rpcbuf, walkClient->clientAsMask); /* resource_base */
|
||||
x_rpcbuf_write_CARD32(&rpcbuf, RESOURCE_ID_MASK); /* resource_mask */
|
||||
num_clients++;
|
||||
}
|
||||
}
|
||||
|
||||
xXResQueryClientsReply rep = {
|
||||
.type = X_Reply,
|
||||
.sequenceNumber = client->sequence,
|
||||
.length = bytes_to_int32(num_clients * sz_xXResClient),
|
||||
.length = x_rpcbuf_wsize_units(&rpcbuf),
|
||||
.num_clients = num_clients
|
||||
};
|
||||
|
||||
if (client->swapped) {
|
||||
swaps(&rep.sequenceNumber);
|
||||
swapl(&rep.length);
|
||||
swapl(&rep.num_clients);
|
||||
}
|
||||
|
||||
xXResClient *scratch = NULL;
|
||||
|
||||
if (num_clients) {
|
||||
scratch = calloc(sizeof(xXResClient), num_clients);
|
||||
if (!scratch) {
|
||||
free(current_clients);
|
||||
return BadAlloc;
|
||||
}
|
||||
|
||||
for (int i = 0; i < num_clients; i++) {
|
||||
scratch[i].resource_base = clients[current_clients[i]]->clientAsMask;
|
||||
scratch[i].resource_mask = RESOURCE_ID_MASK;
|
||||
|
||||
if (client->swapped) {
|
||||
swapl(&scratch[i].resource_base);
|
||||
swapl(&scratch[i].resource_mask);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
WriteToClient(client, sizeof(xXResQueryClientsReply), &rep);
|
||||
WriteToClient(client, sizeof(xXResClient) * num_clients, scratch);
|
||||
free(current_clients);
|
||||
free(scratch);
|
||||
WriteRpcbufToClient(client, &rpcbuf);
|
||||
return Success;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user