#include <swapreq.h>
#include "FSproto.h"
#include "clientstr.h"
#include "globals.h"
#include "dispatch.h"
void
SwapLongs(long *list, unsigned long count)
{
int n;
register char *longs = (char *)list;
while (count >= 8) {
swapl(longs + 0, n);
swapl(longs + 4, n);
swapl(longs + 8, n);
swapl(longs + 12, n);
swapl(longs + 16, n);
swapl(longs + 20, n);
swapl(longs + 24, n);
swapl(longs + 28, n);
longs += 32;
count -= 8;
}
if (count != 0) {
do {
swapl(longs, n);
longs += 4;
} while (--count != 0);
}
}
void
SwapShorts(short *list, unsigned long count)
{
register char *shorts = (char *)list;
register int n;
while (count >= 16) {
swaps(shorts + 0, n);
swaps(shorts + 2, n);
swaps(shorts + 4, n);
swaps(shorts + 6, n);
swaps(shorts + 8, n);
swaps(shorts + 10, n);
swaps(shorts + 12, n);
swaps(shorts + 14, n);
swaps(shorts + 16, n);
swaps(shorts + 18, n);
swaps(shorts + 20, n);
swaps(shorts + 22, n);
swaps(shorts + 24, n);
swaps(shorts + 26, n);
swaps(shorts + 28, n);
swaps(shorts + 30, n);
shorts += 32;
count -= 16;
}
if (count != 0) {
do {
swaps(shorts, n);
shorts += 2;
} while (--count != 0);
}
}
int
SProcSimpleRequest(ClientPtr client)
{
REQUEST(fsReq);
stuff->length = lswaps(stuff->length);
return ((*ProcVector[stuff->reqType]) (client));
}
int
SProcResourceRequest(ClientPtr client)
{
REQUEST(fsResourceReq);
stuff->length = lswaps(stuff->length);
stuff->id = lswapl(stuff->id);
return ((*ProcVector[stuff->reqType]) (client));
}
static int
swap_auth(ClientPtr client, pointer data, int num, int length)
{
unsigned char *p;
unsigned char t;
CARD16 namelen,
datalen;
int i;
p = data;
for (i = 0; i < num; i++) {
if (p - (unsigned char *)data > length - 4) {
int lengthword = length;
SendErrToClient(client, FSBadLength, (pointer)&lengthword);
return (FSBadLength);
}
namelen = *(CARD16 *) p;
t = p[0];
p[0] = p[1];
p[1] = t;
p += 2;
datalen = *(CARD16 *) p;
t = p[0];
p[0] = p[1];
p[1] = t;
p += 2;
p += (namelen + 3) & ~3;
p += (datalen + 3) & ~3;
}
if (!num)
p += 4;
if (p - (unsigned char *)data != length) {
int lengthword = length;
SendErrToClient(client, FSBadLength, (pointer)&lengthword);
return (FSBadLength);
}
return (FSSuccess);
}
int
SProcCreateAC(ClientPtr client)
{
int status;
REQUEST(fsCreateACReq);
stuff->length = lswaps(stuff->length);
stuff->acid = lswapl(stuff->acid);
status = swap_auth(client, (pointer) &stuff[1],
stuff->num_auths, stuff->length);
if (status != FSSuccess)
return (status);
return ((*ProcVector[stuff->reqType]) (client));
}
int
SProcSetResolution(ClientPtr client)
{
REQUEST(fsSetResolutionReq);
stuff->length = lswaps(stuff->length);
stuff->num_resolutions = lswaps(stuff->num_resolutions);
if ((int)stuff->length - (&stuff[1] - &stuff[0]) !=
stuff->num_resolutions * sizeof(fsResolution))
return (FSBadLength);
SwapShorts((short *) &stuff[1], stuff->num_resolutions);
return ((*ProcVector[stuff->reqType]) (client));
}
int
SProcQueryExtension(ClientPtr client)
{
REQUEST(fsQueryExtensionReq);
stuff->length = lswaps(stuff->length);
return ((*ProcVector[FS_QueryExtension]) (client));
}
int
SProcListCatalogues(ClientPtr client)
{
REQUEST(fsListCataloguesReq);
stuff->length = lswaps(stuff->length);
stuff->maxNames = lswapl(stuff->maxNames);
stuff->nbytes = lswaps(stuff->nbytes);
return ((*ProcVector[FS_ListCatalogues]) (client));
}
int
SProcListFonts(ClientPtr client)
{
REQUEST(fsListFontsReq);
stuff->length = lswaps(stuff->length);
stuff->maxNames = lswapl(stuff->maxNames);
stuff->nbytes = lswaps(stuff->nbytes);
return ((*ProcVector[FS_ListFonts]) (client));
}
int
SProcListFontsWithXInfo(ClientPtr client)
{
REQUEST(fsListFontsWithXInfoReq);
stuff->length = lswaps(stuff->length);
stuff->maxNames = lswapl(stuff->maxNames);
stuff->nbytes = lswaps(stuff->nbytes);
return ((*ProcVector[FS_ListFontsWithXInfo]) (client));
}
int
SProcOpenBitmapFont(ClientPtr client)
{
REQUEST(fsOpenBitmapFontReq);
stuff->length = lswaps(stuff->length);
stuff->fid = lswapl(stuff->fid);
stuff->format_hint = lswapl(stuff->format_hint);
stuff->format_mask = lswapl(stuff->format_mask);
return ((*ProcVector[FS_OpenBitmapFont]) (client));
}
int
SProcQueryXExtents(ClientPtr client)
{
REQUEST(fsQueryXExtents8Req);
stuff->length = lswaps(stuff->length);
stuff->fid = lswapl(stuff->fid);
stuff->num_ranges = lswapl(stuff->num_ranges);
return ((*ProcVector[stuff->reqType]) (client));
}
int
SProcQueryXBitmaps(ClientPtr client)
{
REQUEST(fsQueryXBitmaps8Req);
stuff->length = lswaps(stuff->length);
stuff->fid = lswapl(stuff->fid);
stuff->format = lswapl(stuff->format);
stuff->num_ranges = lswapl(stuff->num_ranges);
return ((*ProcVector[stuff->reqType]) (client));
}
int
SwapConnClientPrefix(ClientPtr client, fsConnClientPrefix *pCCP)
{
REQUEST(fsFakeReq);
pCCP->major_version = lswaps(pCCP->major_version);
pCCP->minor_version = lswaps(pCCP->minor_version);
pCCP->auth_len = lswaps(pCCP->auth_len);
return (swap_auth(client, (pointer) &pCCP[1],
pCCP->num_auths, stuff->length));
}