1
/* $Xorg: dispatch.c,v 1.5 2001/02/09 02:04:40 xorgcvs Exp $ */
2
/************************************************************
4
Copyright 1987, 1989, 1998 The Open Group
6
Permission to use, copy, modify, distribute, and sell this software and its
7
documentation for any purpose is hereby granted without fee, provided that
8
the above copyright notice appear in all copies and that both that
9
copyright notice and this permission notice appear in supporting
12
The above copyright notice and this permission notice shall be included in
13
all copies or substantial portions of the Software.
15
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
19
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
Except as contained in this notice, the name of The Open Group shall not be
23
used in advertising or otherwise to promote the sale, use or other dealings
24
in this Software without prior written authorization from The Open Group.
27
Copyright 1987, 1989 by Digital Equipment Corporation, Maynard, Massachusetts.
31
Permission to use, copy, modify, and distribute this software and its
32
documentation for any purpose and without fee is hereby granted,
33
provided that the above copyright notice appear in all copies and that
34
both that copyright notice and this permission notice appear in
35
supporting documentation, and that the name of Digital not be
36
used in advertising or publicity pertaining to distribution of the
37
software without specific, written prior permission.
39
DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
40
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
41
DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
42
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
43
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
44
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
47
********************************************************/
49
/* The panoramix components contained the following notice */
50
/****************************************************************
52
* Copyright (c) Digital Equipment Corporation, 1991, 1997 *
54
* All Rights Reserved. Unpublished rights reserved under *
55
* the copyright laws of the United States. *
57
* The software contained on this media is proprietary to *
58
* and embodies the confidential technology of Digital *
59
* Equipment Corporation. Possession, use, duplication or *
60
* dissemination of the software and media is authorized only *
61
* pursuant to a valid written license from Digital Equipment *
64
* RESTRICTED RIGHTS LEGEND Use, duplication, or disclosure *
65
* by the U.S. Government is subject to restrictions as set *
66
* forth in Subparagraph (c)(1)(ii) of DFARS 252.227-7013, *
67
* or in FAR 52.227-19, as applicable. *
69
*****************************************************************/
71
/* $XFree86: xc/programs/Xserver/dix/dispatch.c,v 3.29 2003/01/12 02:44:26 dawes Exp $ */
73
#ifdef PANORAMIX_DEBUG
75
int ProcInitialConnection();
78
#include "windowstr.h"
79
#include "fontstruct.h"
80
#include "dixfontstr.h"
82
#include "selection.h"
83
#include "colormapst.h"
84
#include "cursorstr.h"
85
#include "scrnintstr.h"
89
#include "extnsionst.h"
95
#include "panoramiX.h"
96
#include "panoramiXsrv.h"
99
#define _SECURITY_SERVER
100
#include "security.h"
106
#define XKB_IN_SERVER
107
#include "inputstr.h"
111
#include "lbxserve.h"
114
#define mskcnt ((MAXCLIENTS + 31) / 32)
115
#define BITMASK(i) (1U << ((i) & 31))
116
#define MASKIDX(i) ((i) >> 5)
117
#define MASKWORD(buf, i) buf[MASKIDX(i)]
118
#define BITSET(buf, i) MASKWORD(buf, i) |= BITMASK(i)
119
#define BITCLEAR(buf, i) MASKWORD(buf, i) &= ~BITMASK(i)
120
#define GETBIT(buf, i) (MASKWORD(buf, i) & BITMASK(i))
122
extern xConnSetupPrefix connSetupPrefix;
123
extern char *ConnectionInfo;
125
Selection *CurrentSelections;
126
int NumCurrentSelections;
128
static ClientPtr grabClient;
131
#define GrabKickout 2
132
static int grabState = GrabNone;
133
static long grabWaiters[mskcnt];
134
CallbackListPtr ServerGrabCallback = NULL;
135
HWEventQueuePtr checkForInput[2];
136
extern int connBlockScreenStart;
138
static void KillAllClients(
139
#if NeedFunctionPrototypes
144
static void DeleteClientFromAnySelections(
145
#if NeedFunctionPrototypes
150
static int nextFreeClientID; /* always MIN free client ID */
152
static int nClients; /* number of authorized clients */
154
CallbackListPtr ClientStateCallback;
155
char dispatchException = 0;
156
char isItTimeToYield;
158
/* Various of the DIX function interfaces were not designed to allow
159
* the client->errorValue to be set on BadValue and other errors.
160
* Rather than changing interfaces and breaking untold code we introduce
161
* a new global that dispatch can use.
163
XID clientErrorValue; /* XXX this is a kludge */
165
#define SAME_SCREENS(a, b) (\
166
(a.pScreen == b.pScreen))
169
SetInputCheck(c0, c1)
170
HWEventQueuePtr c0, c1;
172
checkForInput[0] = c0;
173
checkForInput[1] = c1;
181
/* To avoid time running backwards, we must call GetTimeInMillis before
182
* calling ProcessInputEvents.
184
systime.months = currentTime.months;
185
systime.milliseconds = GetTimeInMillis();
186
if (systime.milliseconds < currentTime.milliseconds)
188
if (*checkForInput[0] != *checkForInput[1])
189
ProcessInputEvents();
190
if (CompareTimeStamps(systime, currentTime) == LATER)
191
currentTime = systime;
194
/* Like UpdateCurrentTime, but can't call ProcessInputEvents */
196
UpdateCurrentTimeIf()
200
systime.months = currentTime.months;
201
systime.milliseconds = GetTimeInMillis();
202
if (systime.milliseconds < currentTime.milliseconds)
204
if (*checkForInput[0] == *checkForInput[1])
205
currentTime = systime;
211
if (CurrentSelections)
212
xfree(CurrentSelections);
213
CurrentSelections = (Selection *)NULL;
214
NumCurrentSelections = 0;
218
FlushClientCaches(id)
222
register ClientPtr client;
224
client = clients[CLIENT_ID(id)];
225
if (client == NullClient)
227
for (i=0; i<currentMaxClients; i++)
230
if (client != NullClient)
232
if (client->lastDrawableID == id)
234
client->lastDrawableID = WindowTable[0]->drawable.id;
235
client->lastDrawable = (DrawablePtr)WindowTable[0];
237
else if (client->lastGCID == id)
239
client->lastGCID = INVALID;
240
client->lastGC = (GCPtr)NULL;
245
#ifdef SMART_SCHEDULE
249
#define SMART_SCHEDULE_DEFAULT_INTERVAL 20 /* ms */
250
#define SMART_SCHEDULE_MAX_SLICE 200 /* ms */
252
Bool SmartScheduleDisable;
253
long SmartScheduleSlice = SMART_SCHEDULE_DEFAULT_INTERVAL;
254
long SmartScheduleInterval = SMART_SCHEDULE_DEFAULT_INTERVAL;
255
long SmartScheduleMaxSlice = SMART_SCHEDULE_MAX_SLICE;
256
long SmartScheduleTime;
257
ClientPtr SmartLastClient;
258
int SmartLastIndex[SMART_MAX_PRIORITY-SMART_MIN_PRIORITY+1];
259
int SmartScheduleClient(int *clientReady, int nready);
266
void InitProcVectors(void);
269
SmartScheduleClient (int *clientReady, int nready)
274
int bestPrio, best = 0;
275
int bestRobin, robin;
276
long now = SmartScheduleTime;
279
bestPrio = -0x7fffffff;
281
idle = 2 * SmartScheduleSlice;
282
for (i = 0; i < nready; i++)
284
client = clientReady[i];
285
pClient = clients[client];
286
/* Praise clients which are idle */
287
if ((now - pClient->smart_check_tick) >= idle)
289
if (pClient->smart_priority < 0)
290
pClient->smart_priority++;
292
pClient->smart_check_tick = now;
294
/* check priority to select best client */
295
robin = (pClient->index - SmartLastIndex[pClient->smart_priority-SMART_MIN_PRIORITY]) & 0xff;
296
if (pClient->smart_priority > bestPrio ||
297
(pClient->smart_priority == bestPrio && robin > bestRobin))
299
bestPrio = pClient->smart_priority;
304
if ((now - SmartLastPrint) >= 5000)
305
fprintf (stderr, " %2d: %3d", client, pClient->smart_priority);
309
if ((now - SmartLastPrint) >= 5000)
311
fprintf (stderr, " use %2d\n", best);
312
SmartLastPrint = now;
315
pClient = clients[best];
316
SmartLastIndex[bestPrio-SMART_MIN_PRIORITY] = pClient->index;
318
* Set current client pointer
320
if (SmartLastClient != pClient)
322
pClient->smart_start_tick = now;
323
SmartLastClient = pClient;
331
* If it's been a long time since another client
332
* has run, bump the slice up to get maximal
333
* performance from a single client
335
if ((now - pClient->smart_start_tick) > 1000 &&
336
SmartScheduleSlice < SmartScheduleMaxSlice)
338
SmartScheduleSlice += SmartScheduleInterval;
343
SmartScheduleSlice = SmartScheduleInterval;
349
#define MAJOROP ((xReq *)client->requestBuffer)->reqType
354
register int *clientReady; /* array of request ready clients */
356
register ClientPtr client;
358
register HWEventQueuePtr* icheck = checkForInput;
359
#ifdef SMART_SCHEDULE
363
nextFreeClientID = 1;
367
clientReady = (int *) ALLOCATE_LOCAL(sizeof(int) * MaxClients);
371
while (!dispatchException)
373
if (*icheck[0] != *icheck[1])
375
ProcessInputEvents();
376
FlushIfCriticalOutputPending();
379
nready = WaitForSomething(clientReady);
381
#ifdef SMART_SCHEDULE
382
if (nready && !SmartScheduleDisable)
384
clientReady[0] = SmartScheduleClient (clientReady, nready);
389
* Handle events in round robin fashion, doing input between
393
while (!dispatchException && (--nready >= 0))
395
client = clients[clientReady[nready]];
398
/* KillClient can cause this to happen */
401
/* GrabServer activation can cause this to be true */
402
if (grabState == GrabKickout)
404
grabState = GrabActive;
407
isItTimeToYield = FALSE;
409
requestingClient = client;
410
#ifdef SMART_SCHEDULE
411
start_tick = SmartScheduleTime;
413
while (!isItTimeToYield)
415
if (*icheck[0] != *icheck[1])
417
ProcessInputEvents();
418
FlushIfCriticalOutputPending();
420
#ifdef SMART_SCHEDULE
421
if (!SmartScheduleDisable &&
422
(SmartScheduleTime - start_tick) >= SmartScheduleSlice)
424
/* Penalize clients which consume ticks */
425
if (client->smart_priority > SMART_MIN_PRIORITY)
426
client->smart_priority--;
430
/* now, finally, deal with client requests */
432
result = ReadRequestFromClient(client);
436
CloseDownClient(client);
442
if (client->requestLogIndex == MAX_REQUEST_LOG)
443
client->requestLogIndex = 0;
444
client->requestLog[client->requestLogIndex] = MAJOROP;
445
client->requestLogIndex++;
447
if (result > (MAX_BIG_REQUEST_SIZE << 2))
450
result = (* client->requestVector[MAJOROP])(client);
452
if (result != Success)
454
if (client->noClientException != Success)
455
CloseDownClient(client);
457
SendErrorToClient(client, MAJOROP,
458
MinorOpcodeOfRequest(client),
459
client->errorValue, result);
464
#ifdef SMART_SCHEDULE
465
client = clients[clientReady[nready]];
467
client->smart_stop_tick = SmartScheduleTime;
469
requestingClient = NULL;
471
dispatchException &= ~DE_PRIORITYCHANGE;
474
DEALLOCATE_LOCAL(clientReady);
475
dispatchException &= ~DE_RESET;
482
ProcBadRequest(client)
489
ProcCreateWindow(client)
490
register ClientPtr client;
492
register WindowPtr pParent, pWin;
493
REQUEST(xCreateWindowReq);
497
REQUEST_AT_LEAST_SIZE(xCreateWindowReq);
499
LEGAL_NEW_RESOURCE(stuff->wid, client);
500
if (!(pParent = (WindowPtr)SecurityLookupWindow(stuff->parent, client,
501
SecurityWriteAccess)))
503
len = client->req_len - (sizeof(xCreateWindowReq) >> 2);
504
if (Ones(stuff->mask) != len)
506
if (!stuff->width || !stuff->height)
508
client->errorValue = 0;
511
pWin = CreateWindow(stuff->wid, pParent, stuff->x,
512
stuff->y, stuff->width, stuff->height,
513
stuff->borderWidth, stuff->class,
514
stuff->mask, (XID *) &stuff[1],
516
client, stuff->visual, &result);
519
Mask mask = pWin->eventMask;
521
pWin->eventMask = 0; /* subterfuge in case AddResource fails */
522
if (!AddResource(stuff->wid, RT_WINDOW, (pointer)pWin))
524
pWin->eventMask = mask;
526
if (client->noClientException != Success)
527
return(client->noClientException);
533
ProcChangeWindowAttributes(client)
534
register ClientPtr client;
536
register WindowPtr pWin;
537
REQUEST(xChangeWindowAttributesReq);
541
REQUEST_AT_LEAST_SIZE(xChangeWindowAttributesReq);
542
pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client,
543
SecurityWriteAccess);
546
len = client->req_len - (sizeof(xChangeWindowAttributesReq) >> 2);
547
if (len != Ones(stuff->valueMask))
549
result = ChangeWindowAttributes(pWin,
553
if (client->noClientException != Success)
554
return(client->noClientException);
560
ProcGetWindowAttributes(client)
561
register ClientPtr client;
563
register WindowPtr pWin;
564
REQUEST(xResourceReq);
565
xGetWindowAttributesReply wa;
567
REQUEST_SIZE_MATCH(xResourceReq);
568
pWin = (WindowPtr)SecurityLookupWindow(stuff->id, client,
572
GetWindowAttributes(pWin, client, &wa);
573
WriteReplyToClient(client, sizeof(xGetWindowAttributesReply), &wa);
574
return(client->noClientException);
578
ProcDestroyWindow(client)
579
register ClientPtr client;
581
register WindowPtr pWin;
582
REQUEST(xResourceReq);
584
REQUEST_SIZE_MATCH(xResourceReq);
585
pWin = (WindowPtr)SecurityLookupWindow(stuff->id, client,
586
SecurityDestroyAccess);
590
FreeResource(stuff->id, RT_NONE);
591
return(client->noClientException);
595
ProcDestroySubwindows(client)
596
register ClientPtr client;
598
register WindowPtr pWin;
599
REQUEST(xResourceReq);
601
REQUEST_SIZE_MATCH(xResourceReq);
602
pWin = (WindowPtr)SecurityLookupWindow(stuff->id, client,
603
SecurityDestroyAccess);
606
DestroySubwindows(pWin, client);
607
return(client->noClientException);
611
ProcChangeSaveSet(client)
612
register ClientPtr client;
614
register WindowPtr pWin;
615
REQUEST(xChangeSaveSetReq);
618
REQUEST_SIZE_MATCH(xChangeSaveSetReq);
619
pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client,
623
if (client->clientAsMask == (CLIENT_BITS(pWin->drawable.id)))
625
if ((stuff->mode == SetModeInsert) || (stuff->mode == SetModeDelete))
627
result = AlterSaveSetForClient(client, pWin, stuff->mode);
628
if (client->noClientException != Success)
629
return(client->noClientException);
635
client->errorValue = stuff->mode;
641
ProcReparentWindow(client)
642
register ClientPtr client;
644
register WindowPtr pWin, pParent;
645
REQUEST(xReparentWindowReq);
648
REQUEST_SIZE_MATCH(xReparentWindowReq);
649
pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client,
650
SecurityWriteAccess);
653
pParent = (WindowPtr)SecurityLookupWindow(stuff->parent, client,
654
SecurityWriteAccess);
657
if (SAME_SCREENS(pWin->drawable, pParent->drawable))
659
if ((pWin->backgroundState == ParentRelative) &&
660
(pParent->drawable.depth != pWin->drawable.depth))
662
if ((pWin->drawable.class != InputOnly) &&
663
(pParent->drawable.class == InputOnly))
665
result = ReparentWindow(pWin, pParent,
666
(short)stuff->x, (short)stuff->y, client);
667
if (client->noClientException != Success)
668
return(client->noClientException);
677
ProcMapWindow(client)
678
register ClientPtr client;
680
register WindowPtr pWin;
681
REQUEST(xResourceReq);
683
REQUEST_SIZE_MATCH(xResourceReq);
684
pWin = (WindowPtr)SecurityLookupWindow(stuff->id, client,
688
MapWindow(pWin, client);
689
/* update cache to say it is mapped */
690
return(client->noClientException);
694
ProcMapSubwindows(client)
695
register ClientPtr client;
697
register WindowPtr pWin;
698
REQUEST(xResourceReq);
700
REQUEST_SIZE_MATCH(xResourceReq);
701
pWin = (WindowPtr)SecurityLookupWindow( stuff->id, client,
705
MapSubwindows(pWin, client);
706
/* update cache to say it is mapped */
707
return(client->noClientException);
711
ProcUnmapWindow(client)
712
register ClientPtr client;
714
register WindowPtr pWin;
715
REQUEST(xResourceReq);
717
REQUEST_SIZE_MATCH(xResourceReq);
718
pWin = (WindowPtr)SecurityLookupWindow( stuff->id, client,
722
UnmapWindow(pWin, FALSE);
723
/* update cache to say it is mapped */
724
return(client->noClientException);
728
ProcUnmapSubwindows(client)
729
register ClientPtr client;
731
register WindowPtr pWin;
732
REQUEST(xResourceReq);
734
REQUEST_SIZE_MATCH(xResourceReq);
735
pWin = (WindowPtr)SecurityLookupWindow( stuff->id, client,
739
UnmapSubwindows(pWin);
740
return(client->noClientException);
744
ProcConfigureWindow(client)
745
register ClientPtr client;
747
register WindowPtr pWin;
748
REQUEST(xConfigureWindowReq);
752
REQUEST_AT_LEAST_SIZE(xConfigureWindowReq);
753
pWin = (WindowPtr)SecurityLookupWindow( stuff->window, client,
754
SecurityWriteAccess);
757
len = client->req_len - (sizeof(xConfigureWindowReq) >> 2);
758
if (Ones((Mask)stuff->mask) != len)
760
result = ConfigureWindow(pWin, (Mask)stuff->mask, (XID *) &stuff[1],
762
if (client->noClientException != Success)
763
return(client->noClientException);
769
ProcCirculateWindow(client)
770
register ClientPtr client;
772
register WindowPtr pWin;
773
REQUEST(xCirculateWindowReq);
775
REQUEST_SIZE_MATCH(xCirculateWindowReq);
776
if ((stuff->direction != RaiseLowest) &&
777
(stuff->direction != LowerHighest))
779
client->errorValue = stuff->direction;
782
pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client,
783
SecurityWriteAccess);
786
CirculateWindow(pWin, (int)stuff->direction, client);
787
return(client->noClientException);
791
GetGeometry(client, rep)
792
register ClientPtr client;
793
xGetGeometryReply *rep;
795
register DrawablePtr pDraw;
796
REQUEST(xResourceReq);
798
REQUEST_SIZE_MATCH(xResourceReq);
799
SECURITY_VERIFY_GEOMETRABLE (pDraw, stuff->id, client, SecurityReadAccess);
802
rep->sequenceNumber = client->sequence;
803
rep->root = WindowTable[pDraw->pScreen->myNum]->drawable.id;
804
rep->depth = pDraw->depth;
805
rep->width = pDraw->width;
806
rep->height = pDraw->height;
808
/* XXX - Because the pixmap-implementation of the multibuffer extension
809
* may have the buffer-id's drawable resource value be a pointer
810
* to the buffer's window instead of the buffer itself
811
* (this happens if the buffer is the displayed buffer),
812
* we also have to check that the id matches before we can
813
* truly say that it is a DRAWABLE_WINDOW.
816
if ((pDraw->type == UNDRAWABLE_WINDOW) ||
817
((pDraw->type == DRAWABLE_WINDOW) && (stuff->id == pDraw->id)))
819
register WindowPtr pWin = (WindowPtr)pDraw;
820
rep->x = pWin->origin.x - wBorderWidth (pWin);
821
rep->y = pWin->origin.y - wBorderWidth (pWin);
822
rep->borderWidth = pWin->borderWidth;
824
else /* DRAWABLE_PIXMAP or DRAWABLE_BUFFER */
826
rep->x = rep->y = rep->borderWidth = 0;
834
ProcGetGeometry(client)
835
register ClientPtr client;
837
xGetGeometryReply rep;
840
if ((status = GetGeometry(client, &rep)) != Success)
843
WriteReplyToClient(client, sizeof(xGetGeometryReply), &rep);
844
return(client->noClientException);
849
ProcQueryTree(client)
850
register ClientPtr client;
852
xQueryTreeReply reply;
854
register WindowPtr pChild, pWin, pHead;
855
Window *childIDs = (Window *)NULL;
856
REQUEST(xResourceReq);
858
REQUEST_SIZE_MATCH(xResourceReq);
859
pWin = (WindowPtr)SecurityLookupWindow(stuff->id, client,
863
reply.type = X_Reply;
864
reply.root = WindowTable[pWin->drawable.pScreen->myNum]->drawable.id;
865
reply.sequenceNumber = client->sequence;
867
reply.parent = pWin->parent->drawable.id;
869
reply.parent = (Window)None;
870
pHead = RealChildHead(pWin);
871
for (pChild = pWin->lastChild; pChild != pHead; pChild = pChild->prevSib)
877
childIDs = (Window *) ALLOCATE_LOCAL(numChildren * sizeof(Window));
880
for (pChild = pWin->lastChild; pChild != pHead; pChild = pChild->prevSib)
881
childIDs[curChild++] = pChild->drawable.id;
884
reply.nChildren = numChildren;
885
reply.length = (numChildren * sizeof(Window)) >> 2;
887
WriteReplyToClient(client, sizeof(xQueryTreeReply), &reply);
890
client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write;
891
WriteSwappedDataToClient(client, numChildren * sizeof(Window), childIDs);
892
DEALLOCATE_LOCAL(childIDs);
895
return(client->noClientException);
899
ProcInternAtom(client)
900
register ClientPtr client;
904
REQUEST(xInternAtomReq);
906
REQUEST_FIXED_SIZE(xInternAtomReq, stuff->nbytes);
907
if ((stuff->onlyIfExists != xTrue) && (stuff->onlyIfExists != xFalse))
909
client->errorValue = stuff->onlyIfExists;
912
tchar = (char *) &stuff[1];
913
atom = MakeAtom(tchar, stuff->nbytes, !stuff->onlyIfExists);
914
if (atom != BAD_RESOURCE)
916
xInternAtomReply reply;
917
reply.type = X_Reply;
919
reply.sequenceNumber = client->sequence;
921
WriteReplyToClient(client, sizeof(xInternAtomReply), &reply);
922
return(client->noClientException);
929
ProcGetAtomName(client)
930
register ClientPtr client;
933
xGetAtomNameReply reply;
935
REQUEST(xResourceReq);
937
REQUEST_SIZE_MATCH(xResourceReq);
938
if ( (str = NameForAtom(stuff->id)) )
941
reply.type = X_Reply;
942
reply.length = (len + 3) >> 2;
943
reply.sequenceNumber = client->sequence;
944
reply.nameLength = len;
945
WriteReplyToClient(client, sizeof(xGetAtomNameReply), &reply);
946
(void)WriteToClient(client, len, str);
947
return(client->noClientException);
951
client->errorValue = stuff->id;
961
ProcSetSelectionOwner(client)
962
register ClientPtr client;
966
REQUEST(xSetSelectionOwnerReq);
968
REQUEST_SIZE_MATCH(xSetSelectionOwnerReq);
970
time = ClientTimeToServerTime(stuff->time);
972
/* If the client's time stamp is in the future relative to the server's
973
time stamp, do not set the selection, just return success. */
974
if (CompareTimeStamps(time, currentTime) == LATER)
976
if (stuff->window != None)
978
pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client,
984
pWin = (WindowPtr)None;
985
if (ValidAtom(stuff->selection))
990
* First, see if the selection is already set...
992
while ((i < NumCurrentSelections) &&
993
CurrentSelections[i].selection != stuff->selection)
995
if (i < NumCurrentSelections)
999
/* If the timestamp in client's request is in the past relative
1000
to the time stamp indicating the last time the owner of the
1001
selection was set, do not set the selection, just return
1003
if (CompareTimeStamps(time, CurrentSelections[i].lastTimeChanged)
1006
if (CurrentSelections[i].client &&
1007
(!pWin || (CurrentSelections[i].client != client)))
1009
event.u.u.type = SelectionClear;
1010
event.u.selectionClear.time = time.milliseconds;
1011
event.u.selectionClear.window = CurrentSelections[i].window;
1012
event.u.selectionClear.atom = CurrentSelections[i].selection;
1013
(void) TryClientEvents (CurrentSelections[i].client, &event, 1,
1014
NoEventMask, NoEventMask /* CantBeFiltered */,
1021
* It doesn't exist, so add it...
1026
newsels = (Selection *)xalloc(sizeof(Selection));
1028
newsels = (Selection *)xrealloc(CurrentSelections,
1029
(NumCurrentSelections + 1) * sizeof(Selection));
1032
NumCurrentSelections++;
1033
CurrentSelections = newsels;
1034
CurrentSelections[i].selection = stuff->selection;
1036
CurrentSelections[i].lastTimeChanged = time;
1037
CurrentSelections[i].window = stuff->window;
1038
CurrentSelections[i].pWin = pWin;
1039
CurrentSelections[i].client = (pWin ? client : NullClient);
1040
return (client->noClientException);
1044
client->errorValue = stuff->selection;
1050
ProcGetSelectionOwner(client)
1051
register ClientPtr client;
1053
REQUEST(xResourceReq);
1055
REQUEST_SIZE_MATCH(xResourceReq);
1056
if (ValidAtom(stuff->id))
1059
xGetSelectionOwnerReply reply;
1062
while ((i < NumCurrentSelections) &&
1063
CurrentSelections[i].selection != stuff->id) i++;
1064
reply.type = X_Reply;
1066
reply.sequenceNumber = client->sequence;
1067
if (i < NumCurrentSelections)
1068
reply.owner = CurrentSelections[i].window;
1071
WriteReplyToClient(client, sizeof(xGetSelectionOwnerReply), &reply);
1072
return(client->noClientException);
1076
client->errorValue = stuff->id;
1082
ProcConvertSelection(client)
1083
register ClientPtr client;
1088
REQUEST(xConvertSelectionReq);
1090
REQUEST_SIZE_MATCH(xConvertSelectionReq);
1091
pWin = (WindowPtr)SecurityLookupWindow(stuff->requestor, client,
1092
SecurityReadAccess);
1096
paramsOkay = (ValidAtom(stuff->selection) && ValidAtom(stuff->target));
1097
if (stuff->property != None)
1098
paramsOkay &= ValidAtom(stuff->property);
1104
while ((i < NumCurrentSelections) &&
1105
CurrentSelections[i].selection != stuff->selection) i++;
1106
if ((i < NumCurrentSelections) &&
1107
(CurrentSelections[i].window != None)
1109
&& (!client->CheckAccess ||
1110
(* client->CheckAccess)(client, CurrentSelections[i].window,
1111
RT_WINDOW, SecurityReadAccess,
1112
CurrentSelections[i].pWin))
1116
event.u.u.type = SelectionRequest;
1117
event.u.selectionRequest.time = stuff->time;
1118
event.u.selectionRequest.owner =
1119
CurrentSelections[i].window;
1120
event.u.selectionRequest.requestor = stuff->requestor;
1121
event.u.selectionRequest.selection = stuff->selection;
1122
event.u.selectionRequest.target = stuff->target;
1123
event.u.selectionRequest.property = stuff->property;
1124
if (TryClientEvents(
1125
CurrentSelections[i].client, &event, 1, NoEventMask,
1126
NoEventMask /* CantBeFiltered */, NullGrab))
1127
return (client->noClientException);
1129
event.u.u.type = SelectionNotify;
1130
event.u.selectionNotify.time = stuff->time;
1131
event.u.selectionNotify.requestor = stuff->requestor;
1132
event.u.selectionNotify.selection = stuff->selection;
1133
event.u.selectionNotify.target = stuff->target;
1134
event.u.selectionNotify.property = None;
1135
(void) TryClientEvents(client, &event, 1, NoEventMask,
1136
NoEventMask /* CantBeFiltered */, NullGrab);
1137
return (client->noClientException);
1141
client->errorValue = stuff->property;
1147
ProcGrabServer(client)
1148
register ClientPtr client;
1150
REQUEST_SIZE_MATCH(xReq);
1151
if (grabState != GrabNone && client != grabClient)
1153
ResetCurrentRequest(client);
1155
BITSET(grabWaiters, client->index);
1156
IgnoreClient(client);
1157
return(client->noClientException);
1159
OnlyListenToOneClient(client);
1160
grabState = GrabKickout;
1161
grabClient = client;
1163
if (ServerGrabCallback)
1165
ServerGrabInfoRec grabinfo;
1166
grabinfo.client = client;
1167
grabinfo.grabstate = SERVER_GRABBED;
1168
CallCallbacks(&ServerGrabCallback, (pointer)&grabinfo);
1171
return(client->noClientException);
1175
#if NeedFunctionPrototypes
1176
UngrabServer(ClientPtr client)
1178
UngrabServer(client)
1184
grabState = GrabNone;
1185
ListenToAllClients();
1186
for (i = mskcnt; --i >= 0 && !grabWaiters[i]; )
1191
while (!GETBIT(grabWaiters, i))
1193
BITCLEAR(grabWaiters, i);
1194
AttendClient(clients[i]);
1197
if (ServerGrabCallback)
1199
ServerGrabInfoRec grabinfo;
1200
grabinfo.client = client;
1201
grabinfo.grabstate = SERVER_UNGRABBED;
1202
CallCallbacks(&ServerGrabCallback, (pointer)&grabinfo);
1207
ProcUngrabServer(client)
1208
register ClientPtr client;
1210
REQUEST_SIZE_MATCH(xReq);
1211
UngrabServer(client);
1212
return(client->noClientException);
1216
ProcTranslateCoords(client)
1217
register ClientPtr client;
1219
REQUEST(xTranslateCoordsReq);
1221
register WindowPtr pWin, pDst;
1222
xTranslateCoordsReply rep;
1224
REQUEST_SIZE_MATCH(xTranslateCoordsReq);
1225
pWin = (WindowPtr)SecurityLookupWindow(stuff->srcWid, client,
1226
SecurityReadAccess);
1229
pDst = (WindowPtr)SecurityLookupWindow(stuff->dstWid, client,
1230
SecurityReadAccess);
1235
rep.sequenceNumber = client->sequence;
1236
if (!SAME_SCREENS(pWin->drawable, pDst->drawable))
1238
rep.sameScreen = xFalse;
1240
rep.dstX = rep.dstY = 0;
1245
rep.sameScreen = xTrue;
1247
/* computing absolute coordinates -- adjust to destination later */
1248
x = pWin->drawable.x + stuff->srcX;
1249
y = pWin->drawable.y + stuff->srcY;
1250
pWin = pDst->firstChild;
1256
if ((pWin->mapped) &&
1257
(x >= pWin->drawable.x - wBorderWidth (pWin)) &&
1258
(x < pWin->drawable.x + (int)pWin->drawable.width +
1259
wBorderWidth (pWin)) &&
1260
(y >= pWin->drawable.y - wBorderWidth (pWin)) &&
1261
(y < pWin->drawable.y + (int)pWin->drawable.height +
1262
wBorderWidth (pWin))
1264
/* When a window is shaped, a further check
1265
* is made to see if the point is inside
1268
&& (!wBoundingShape(pWin) ||
1269
POINT_IN_REGION(pWin->drawable.pScreen,
1270
&pWin->borderSize, x, y, &box))
1274
rep.child = pWin->drawable.id;
1275
pWin = (WindowPtr) NULL;
1278
pWin = pWin->nextSib;
1280
/* adjust to destination coordinates */
1281
rep.dstX = x - pDst->drawable.x;
1282
rep.dstY = y - pDst->drawable.y;
1284
WriteReplyToClient(client, sizeof(xTranslateCoordsReply), &rep);
1285
return(client->noClientException);
1289
ProcOpenFont(client)
1290
register ClientPtr client;
1293
REQUEST(xOpenFontReq);
1295
REQUEST_FIXED_SIZE(xOpenFontReq, stuff->nbytes);
1296
client->errorValue = stuff->fid;
1297
LEGAL_NEW_RESOURCE(stuff->fid, client);
1298
err = OpenFont(client, stuff->fid, (Mask) 0,
1299
stuff->nbytes, (char *)&stuff[1]);
1302
return(client->noClientException);
1309
ProcCloseFont(client)
1310
register ClientPtr client;
1313
REQUEST(xResourceReq);
1315
REQUEST_SIZE_MATCH(xResourceReq);
1316
pFont = (FontPtr)SecurityLookupIDByType(client, stuff->id, RT_FONT,
1317
SecurityDestroyAccess);
1318
if ( pFont != (FontPtr)NULL) /* id was valid */
1320
FreeResource(stuff->id, RT_NONE);
1321
return(client->noClientException);
1325
client->errorValue = stuff->id;
1331
ProcQueryFont(client)
1332
register ClientPtr client;
1334
xQueryFontReply *reply;
1337
REQUEST(xResourceReq);
1339
REQUEST_SIZE_MATCH(xResourceReq);
1340
client->errorValue = stuff->id; /* EITHER font or gc */
1341
pFont = (FontPtr)SecurityLookupIDByType(client, stuff->id, RT_FONT,
1342
SecurityReadAccess);
1345
/* can't use VERIFY_GC because it might return BadGC */
1346
pGC = (GC *) SecurityLookupIDByType(client, stuff->id, RT_GC,
1347
SecurityReadAccess);
1350
client->errorValue = stuff->id;
1351
return(BadFont); /* procotol spec says only error is BadFont */
1357
xCharInfo *pmax = FONTINKMAX(pFont);
1358
xCharInfo *pmin = FONTINKMIN(pFont);
1359
int nprotoxcistructs;
1362
nprotoxcistructs = (
1363
pmax->rightSideBearing == pmin->rightSideBearing &&
1364
pmax->leftSideBearing == pmin->leftSideBearing &&
1365
pmax->descent == pmin->descent &&
1366
pmax->ascent == pmin->ascent &&
1367
pmax->characterWidth == pmin->characterWidth) ?
1368
0 : N2dChars(pFont);
1370
rlength = sizeof(xQueryFontReply) +
1371
FONTINFONPROPS(FONTCHARSET(pFont)) * sizeof(xFontProp) +
1372
nprotoxcistructs * sizeof(xCharInfo);
1373
reply = (xQueryFontReply *)ALLOCATE_LOCAL(rlength);
1379
reply->type = X_Reply;
1380
reply->length = (rlength - sizeof(xGenericReply)) >> 2;
1381
reply->sequenceNumber = client->sequence;
1382
QueryFont( pFont, reply, nprotoxcistructs);
1384
WriteReplyToClient(client, rlength, reply);
1385
DEALLOCATE_LOCAL(reply);
1386
return(client->noClientException);
1391
ProcQueryTextExtents(client)
1392
register ClientPtr client;
1394
REQUEST(xQueryTextExtentsReq);
1395
xQueryTextExtentsReply reply;
1399
unsigned long length;
1401
REQUEST_AT_LEAST_SIZE(xQueryTextExtentsReq);
1403
pFont = (FontPtr)SecurityLookupIDByType(client, stuff->fid, RT_FONT,
1404
SecurityReadAccess);
1407
pGC = (GC *)SecurityLookupIDByType(client, stuff->fid, RT_GC,
1408
SecurityReadAccess);
1411
client->errorValue = stuff->fid;
1416
length = client->req_len - (sizeof(xQueryTextExtentsReq) >> 2);
1417
length = length << 1;
1418
if (stuff->oddLength)
1424
if (!QueryTextExtents(pFont, length, (unsigned char *)&stuff[1], &info))
1426
reply.type = X_Reply;
1428
reply.sequenceNumber = client->sequence;
1429
reply.drawDirection = info.drawDirection;
1430
reply.fontAscent = info.fontAscent;
1431
reply.fontDescent = info.fontDescent;
1432
reply.overallAscent = info.overallAscent;
1433
reply.overallDescent = info.overallDescent;
1434
reply.overallWidth = info.overallWidth;
1435
reply.overallLeft = info.overallLeft;
1436
reply.overallRight = info.overallRight;
1437
WriteReplyToClient(client, sizeof(xQueryTextExtentsReply), &reply);
1438
return(client->noClientException);
1442
ProcListFonts(client)
1443
register ClientPtr client;
1445
REQUEST(xListFontsReq);
1447
REQUEST_FIXED_SIZE(xListFontsReq, stuff->nbytes);
1449
return ListFonts(client, (unsigned char *) &stuff[1], stuff->nbytes,
1454
ProcListFontsWithInfo(client)
1455
register ClientPtr client;
1457
REQUEST(xListFontsWithInfoReq);
1459
REQUEST_FIXED_SIZE(xListFontsWithInfoReq, stuff->nbytes);
1461
return StartListFontsWithInfo(client, stuff->nbytes,
1462
(unsigned char *) &stuff[1], stuff->maxNames);
1467
dixDestroyPixmap(value, pid)
1468
pointer value; /* must conform to DeleteType */
1471
PixmapPtr pPixmap = (PixmapPtr)value;
1472
return (*pPixmap->drawable.pScreen->DestroyPixmap)(pPixmap);
1476
ProcCreatePixmap(client)
1477
register ClientPtr client;
1480
register DrawablePtr pDraw;
1481
REQUEST(xCreatePixmapReq);
1485
REQUEST_SIZE_MATCH(xCreatePixmapReq);
1486
client->errorValue = stuff->pid;
1487
LEGAL_NEW_RESOURCE(stuff->pid, client);
1488
SECURITY_VERIFY_GEOMETRABLE (pDraw, stuff->drawable, client,
1489
SecurityReadAccess);
1490
if (!stuff->width || !stuff->height)
1492
client->errorValue = 0;
1495
if (stuff->depth != 1)
1497
pDepth = pDraw->pScreen->allowedDepths;
1498
for (i=0; i<pDraw->pScreen->numDepths; i++, pDepth++)
1499
if (pDepth->depth == stuff->depth)
1501
client->errorValue = stuff->depth;
1505
pMap = (PixmapPtr)(*pDraw->pScreen->CreatePixmap)
1506
(pDraw->pScreen, stuff->width,
1507
stuff->height, stuff->depth);
1510
pMap->drawable.serialNumber = NEXT_SERIAL_NUMBER;
1511
pMap->drawable.id = stuff->pid;
1512
if (AddResource(stuff->pid, RT_PIXMAP, (pointer)pMap))
1513
return(client->noClientException);
1519
ProcFreePixmap(client)
1520
register ClientPtr client;
1524
REQUEST(xResourceReq);
1526
REQUEST_SIZE_MATCH(xResourceReq);
1527
pMap = (PixmapPtr)SecurityLookupIDByType(client, stuff->id, RT_PIXMAP,
1528
SecurityDestroyAccess);
1531
FreeResource(stuff->id, RT_NONE);
1532
return(client->noClientException);
1536
client->errorValue = stuff->id;
1542
ProcCreateGC(client)
1543
register ClientPtr client;
1547
register DrawablePtr pDraw;
1549
REQUEST(xCreateGCReq);
1551
REQUEST_AT_LEAST_SIZE(xCreateGCReq);
1552
client->errorValue = stuff->gc;
1553
LEGAL_NEW_RESOURCE(stuff->gc, client);
1554
SECURITY_VERIFY_DRAWABLE (pDraw, stuff->drawable, client,
1555
SecurityReadAccess);
1556
len = client->req_len - (sizeof(xCreateGCReq) >> 2);
1557
if (len != Ones(stuff->mask))
1559
pGC = (GC *)CreateGC(pDraw, stuff->mask,
1560
(XID *) &stuff[1], &error);
1561
if (error != Success)
1563
if (!AddResource(stuff->gc, RT_GC, (pointer)pGC))
1565
return(client->noClientException);
1569
ProcChangeGC(client)
1570
register ClientPtr client;
1573
REQUEST(xChangeGCReq);
1577
REQUEST_AT_LEAST_SIZE(xChangeGCReq);
1578
SECURITY_VERIFY_GC(pGC, stuff->gc, client, SecurityWriteAccess);
1579
len = client->req_len - (sizeof(xChangeGCReq) >> 2);
1580
if (len != Ones(stuff->mask))
1583
result = dixChangeGC(client, pGC, stuff->mask, (CARD32 *) &stuff[1], 0);
1584
if (client->noClientException != Success)
1585
return(client->noClientException);
1588
client->errorValue = clientErrorValue;
1595
register ClientPtr client;
1600
REQUEST(xCopyGCReq);
1602
REQUEST_SIZE_MATCH(xCopyGCReq);
1603
SECURITY_VERIFY_GC( pGC, stuff->srcGC, client, SecurityReadAccess);
1604
SECURITY_VERIFY_GC( dstGC, stuff->dstGC, client, SecurityWriteAccess);
1605
if ((dstGC->pScreen != pGC->pScreen) || (dstGC->depth != pGC->depth))
1607
result = CopyGC(pGC, dstGC, stuff->mask);
1608
if (client->noClientException != Success)
1609
return(client->noClientException);
1612
client->errorValue = clientErrorValue;
1618
ProcSetDashes(client)
1619
register ClientPtr client;
1623
REQUEST(xSetDashesReq);
1625
REQUEST_FIXED_SIZE(xSetDashesReq, stuff->nDashes);
1626
if (stuff->nDashes == 0)
1628
client->errorValue = 0;
1632
SECURITY_VERIFY_GC(pGC,stuff->gc, client, SecurityWriteAccess);
1634
result = SetDashes(pGC, stuff->dashOffset, stuff->nDashes,
1635
(unsigned char *)&stuff[1]);
1636
if (client->noClientException != Success)
1637
return(client->noClientException);
1640
client->errorValue = clientErrorValue;
1646
ProcSetClipRectangles(client)
1647
register ClientPtr client;
1652
REQUEST(xSetClipRectanglesReq);
1654
REQUEST_AT_LEAST_SIZE(xSetClipRectanglesReq);
1655
if ((stuff->ordering != Unsorted) && (stuff->ordering != YSorted) &&
1656
(stuff->ordering != YXSorted) && (stuff->ordering != YXBanded))
1658
client->errorValue = stuff->ordering;
1661
SECURITY_VERIFY_GC(pGC,stuff->gc, client, SecurityWriteAccess);
1663
nr = (client->req_len << 2) - sizeof(xSetClipRectanglesReq);
1667
result = SetClipRects(pGC, stuff->xOrigin, stuff->yOrigin,
1668
nr, (xRectangle *)&stuff[1], (int)stuff->ordering);
1669
if (client->noClientException != Success)
1670
return(client->noClientException);
1677
register ClientPtr client;
1680
REQUEST(xResourceReq);
1682
REQUEST_SIZE_MATCH(xResourceReq);
1683
SECURITY_VERIFY_GC(pGC, stuff->id, client, SecurityDestroyAccess);
1684
FreeResource(stuff->id, RT_NONE);
1685
return(client->noClientException);
1689
ProcClearToBackground(client)
1690
register ClientPtr client;
1692
REQUEST(xClearAreaReq);
1693
register WindowPtr pWin;
1695
REQUEST_SIZE_MATCH(xClearAreaReq);
1696
pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client,
1697
SecurityWriteAccess);
1700
if (pWin->drawable.class == InputOnly)
1702
client->errorValue = stuff->window;
1705
if ((stuff->exposures != xTrue) && (stuff->exposures != xFalse))
1707
client->errorValue = stuff->exposures;
1710
(*pWin->drawable.pScreen->ClearToBackground)(pWin, stuff->x, stuff->y,
1711
stuff->width, stuff->height,
1712
(Bool)stuff->exposures);
1713
return(client->noClientException);
1717
ProcCopyArea(client)
1718
register ClientPtr client;
1720
register DrawablePtr pDst;
1721
register DrawablePtr pSrc;
1723
REQUEST(xCopyAreaReq);
1726
REQUEST_SIZE_MATCH(xCopyAreaReq);
1728
VALIDATE_DRAWABLE_AND_GC(stuff->dstDrawable, pDst, pGC, client);
1729
if (stuff->dstDrawable != stuff->srcDrawable)
1731
SECURITY_VERIFY_DRAWABLE(pSrc, stuff->srcDrawable, client,
1732
SecurityReadAccess);
1733
if ((pDst->pScreen != pSrc->pScreen) || (pDst->depth != pSrc->depth))
1735
client->errorValue = stuff->dstDrawable;
1742
SET_DBE_SRCBUF(pSrc, stuff->srcDrawable);
1744
pRgn = (*pGC->ops->CopyArea)(pSrc, pDst, pGC, stuff->srcX, stuff->srcY,
1745
stuff->width, stuff->height,
1746
stuff->dstX, stuff->dstY);
1747
if (pGC->graphicsExposures)
1749
(*pDst->pScreen->SendGraphicsExpose)
1750
(client, pRgn, stuff->dstDrawable, X_CopyArea, 0);
1752
REGION_DESTROY(pDst->pScreen, pRgn);
1755
return(client->noClientException);
1759
ProcCopyPlane(client)
1760
register ClientPtr client;
1762
register DrawablePtr psrcDraw, pdstDraw;
1764
REQUEST(xCopyPlaneReq);
1767
REQUEST_SIZE_MATCH(xCopyPlaneReq);
1769
VALIDATE_DRAWABLE_AND_GC(stuff->dstDrawable, pdstDraw, pGC, client);
1770
if (stuff->dstDrawable != stuff->srcDrawable)
1772
SECURITY_VERIFY_DRAWABLE(psrcDraw, stuff->srcDrawable, client,
1773
SecurityReadAccess);
1774
if (pdstDraw->pScreen != psrcDraw->pScreen)
1776
client->errorValue = stuff->dstDrawable;
1781
psrcDraw = pdstDraw;
1783
SET_DBE_SRCBUF(psrcDraw, stuff->srcDrawable);
1785
/* Check to see if stuff->bitPlane has exactly ONE good bit set */
1786
if(stuff->bitPlane == 0 || (stuff->bitPlane & (stuff->bitPlane - 1)) ||
1787
(stuff->bitPlane > (1L << (psrcDraw->depth - 1))))
1789
client->errorValue = stuff->bitPlane;
1793
pRgn = (*pGC->ops->CopyPlane)(psrcDraw, pdstDraw, pGC, stuff->srcX, stuff->srcY,
1794
stuff->width, stuff->height,
1795
stuff->dstX, stuff->dstY, stuff->bitPlane);
1796
if (pGC->graphicsExposures)
1798
(*pdstDraw->pScreen->SendGraphicsExpose)
1799
(client, pRgn, stuff->dstDrawable, X_CopyPlane, 0);
1801
REGION_DESTROY(pdstDraw->pScreen, pRgn);
1803
return(client->noClientException);
1807
ProcPolyPoint(client)
1808
register ClientPtr client;
1812
register DrawablePtr pDraw;
1813
REQUEST(xPolyPointReq);
1815
REQUEST_AT_LEAST_SIZE(xPolyPointReq);
1816
if ((stuff->coordMode != CoordModeOrigin) &&
1817
(stuff->coordMode != CoordModePrevious))
1819
client->errorValue = stuff->coordMode;
1822
VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
1823
npoint = ((client->req_len << 2) - sizeof(xPolyPointReq)) >> 2;
1825
(*pGC->ops->PolyPoint)(pDraw, pGC, stuff->coordMode, npoint,
1826
(xPoint *) &stuff[1]);
1827
return (client->noClientException);
1831
ProcPolyLine(client)
1832
register ClientPtr client;
1836
register DrawablePtr pDraw;
1837
REQUEST(xPolyLineReq);
1839
REQUEST_AT_LEAST_SIZE(xPolyLineReq);
1840
if ((stuff->coordMode != CoordModeOrigin) &&
1841
(stuff->coordMode != CoordModePrevious))
1843
client->errorValue = stuff->coordMode;
1846
VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
1847
npoint = ((client->req_len << 2) - sizeof(xPolyLineReq)) >> 2;
1849
(*pGC->ops->Polylines)(pDraw, pGC, stuff->coordMode, npoint,
1850
(DDXPointPtr) &stuff[1]);
1851
return(client->noClientException);
1855
ProcPolySegment(client)
1856
register ClientPtr client;
1860
register DrawablePtr pDraw;
1861
REQUEST(xPolySegmentReq);
1863
REQUEST_AT_LEAST_SIZE(xPolySegmentReq);
1864
VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
1865
nsegs = (client->req_len << 2) - sizeof(xPolySegmentReq);
1870
(*pGC->ops->PolySegment)(pDraw, pGC, nsegs, (xSegment *) &stuff[1]);
1871
return (client->noClientException);
1875
ProcPolyRectangle (client)
1876
register ClientPtr client;
1880
register DrawablePtr pDraw;
1881
REQUEST(xPolyRectangleReq);
1883
REQUEST_AT_LEAST_SIZE(xPolyRectangleReq);
1884
VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
1885
nrects = (client->req_len << 2) - sizeof(xPolyRectangleReq);
1890
(*pGC->ops->PolyRectangle)(pDraw, pGC,
1891
nrects, (xRectangle *) &stuff[1]);
1892
return(client->noClientException);
1897
register ClientPtr client;
1901
register DrawablePtr pDraw;
1902
REQUEST(xPolyArcReq);
1904
REQUEST_AT_LEAST_SIZE(xPolyArcReq);
1905
VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
1906
narcs = (client->req_len << 2) - sizeof(xPolyArcReq);
1907
if (narcs % sizeof(xArc))
1909
narcs /= sizeof(xArc);
1911
(*pGC->ops->PolyArc)(pDraw, pGC, narcs, (xArc *) &stuff[1]);
1912
return (client->noClientException);
1916
ProcFillPoly(client)
1917
register ClientPtr client;
1921
register DrawablePtr pDraw;
1922
REQUEST(xFillPolyReq);
1924
REQUEST_AT_LEAST_SIZE(xFillPolyReq);
1925
if ((stuff->shape != Complex) && (stuff->shape != Nonconvex) &&
1926
(stuff->shape != Convex))
1928
client->errorValue = stuff->shape;
1931
if ((stuff->coordMode != CoordModeOrigin) &&
1932
(stuff->coordMode != CoordModePrevious))
1934
client->errorValue = stuff->coordMode;
1938
VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
1939
things = ((client->req_len << 2) - sizeof(xFillPolyReq)) >> 2;
1941
(*pGC->ops->FillPolygon) (pDraw, pGC, stuff->shape,
1942
stuff->coordMode, things,
1943
(DDXPointPtr) &stuff[1]);
1944
return(client->noClientException);
1948
ProcPolyFillRectangle(client)
1949
register ClientPtr client;
1953
register DrawablePtr pDraw;
1954
REQUEST(xPolyFillRectangleReq);
1956
REQUEST_AT_LEAST_SIZE(xPolyFillRectangleReq);
1957
VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
1958
things = (client->req_len << 2) - sizeof(xPolyFillRectangleReq);
1964
(*pGC->ops->PolyFillRect) (pDraw, pGC, things,
1965
(xRectangle *) &stuff[1]);
1966
return (client->noClientException);
1970
ProcPolyFillArc(client)
1971
register ClientPtr client;
1975
register DrawablePtr pDraw;
1976
REQUEST(xPolyFillArcReq);
1978
REQUEST_AT_LEAST_SIZE(xPolyFillArcReq);
1979
VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
1980
narcs = (client->req_len << 2) - sizeof(xPolyFillArcReq);
1981
if (narcs % sizeof(xArc))
1983
narcs /= sizeof(xArc);
1985
(*pGC->ops->PolyFillArc) (pDraw, pGC, narcs, (xArc *) &stuff[1]);
1986
return (client->noClientException);
1989
#ifdef MATCH_CLIENT_ENDIAN
1996
if (*((char *) &whichbyte))
2001
#define ClientOrder(client) ((client)->swapped ? !ServerOrder() : ServerOrder())
2004
ReformatImage (char *base, int nbytes, int bpp, int order)
2008
if (BITMAP_BIT_ORDER != order)
2009
BitOrderInvert ((unsigned char *) base, nbytes);
2010
#if IMAGE_BYTE_ORDER != BITMAP_BIT_ORDER && BITMAP_SCANLINE_UNIT != 8
2011
ReformatImage (base, nbytes, BITMAP_SCANLINE_UNIT, order);
2019
if (IMAGE_BYTE_ORDER != order)
2020
TwoByteSwap ((unsigned char *) base, nbytes);
2023
if (IMAGE_BYTE_ORDER != order)
2024
FourByteSwap ((unsigned char *) base, nbytes);
2029
#define ReformatImage(b,n,bpp,o)
2032
/* 64-bit server notes: the protocol restricts padding of images to
2033
* 8-, 16-, or 32-bits. We would like to have 64-bits for the server
2034
* to use internally. Removes need for internal alignment checking.
2035
* All of the PutImage functions could be changed individually, but
2036
* as currently written, they call other routines which require things
2037
* to be 64-bit padded on scanlines, so we changed things here.
2038
* If an image would be padded differently for 64- versus 32-, then
2039
* copy each scanline to a 64-bit padded scanline.
2040
* Also, we need to make sure that the image is aligned on a 64-bit
2041
* boundary, even if the scanlines are padded to our satisfaction.
2044
ProcPutImage(client)
2045
register ClientPtr client;
2048
register DrawablePtr pDraw;
2049
long length; /* length of scanline server padded */
2050
long lengthProto; /* length of scanline protocol padded */
2052
REQUEST(xPutImageReq);
2054
REQUEST_AT_LEAST_SIZE(xPutImageReq);
2055
VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
2056
if (stuff->format == XYBitmap)
2058
if ((stuff->depth != 1) ||
2059
(stuff->leftPad >= (unsigned int)screenInfo.bitmapScanlinePad))
2061
length = BitmapBytePad(stuff->width + stuff->leftPad);
2063
else if (stuff->format == XYPixmap)
2065
if ((pDraw->depth != stuff->depth) ||
2066
(stuff->leftPad >= (unsigned int)screenInfo.bitmapScanlinePad))
2068
length = BitmapBytePad(stuff->width + stuff->leftPad);
2069
length *= stuff->depth;
2071
else if (stuff->format == ZPixmap)
2073
if ((pDraw->depth != stuff->depth) || (stuff->leftPad != 0))
2075
length = PixmapBytePad(stuff->width, stuff->depth);
2079
client->errorValue = stuff->format;
2083
tmpImage = (char *)&stuff[1];
2084
lengthProto = length;
2086
if (((((lengthProto * stuff->height) + (unsigned)3) >> 2) +
2087
(sizeof(xPutImageReq) >> 2)) != client->req_len)
2090
ReformatImage (tmpImage, lengthProto * stuff->height,
2091
stuff->format == ZPixmap ? BitsPerPixel (stuff->depth) : 1,
2092
ClientOrder(client));
2094
(*pGC->ops->PutImage) (pDraw, pGC, stuff->depth, stuff->dstX, stuff->dstY,
2095
stuff->width, stuff->height,
2096
stuff->leftPad, stuff->format, tmpImage);
2098
return (client->noClientException);
2103
DoGetImage(client, format, drawable, x, y, width, height, planemask, im_return)
2104
register ClientPtr client;
2107
int x, y, width, height;
2109
xGetImageReply **im_return;
2111
register DrawablePtr pDraw;
2112
int nlines, linesPerBuf;
2113
register int linesDone;
2114
long widthBytesLine, length;
2118
RegionPtr pVisibleRegion = NULL;
2120
if ((format != XYPixmap) && (format != ZPixmap))
2122
client->errorValue = format;
2125
SECURITY_VERIFY_DRAWABLE(pDraw, drawable, client, SecurityReadAccess);
2126
if(pDraw->type == DRAWABLE_WINDOW)
2128
if( /* check for being viewable */
2129
!((WindowPtr) pDraw)->realized ||
2130
/* check for being on screen */
2132
pDraw->x + x + width > pDraw->pScreen->width ||
2134
pDraw->y + y + height > pDraw->pScreen->height ||
2135
/* check for being inside of border */
2136
x < - wBorderWidth((WindowPtr)pDraw) ||
2137
x + width > wBorderWidth((WindowPtr)pDraw) + (int)pDraw->width ||
2138
y < -wBorderWidth((WindowPtr)pDraw) ||
2139
y + height > wBorderWidth ((WindowPtr)pDraw) + (int)pDraw->height
2142
xgi.visual = wVisual (((WindowPtr) pDraw));
2147
x+width > (int)pDraw->width ||
2149
y+height > (int)pDraw->height
2155
SET_DBE_SRCBUF(pDraw, drawable);
2158
xgi.sequenceNumber = client->sequence;
2159
xgi.depth = pDraw->depth;
2160
if(format == ZPixmap)
2162
widthBytesLine = PixmapBytePad(width, pDraw->depth);
2163
length = widthBytesLine * height;
2168
widthBytesLine = BitmapBytePad(width);
2169
plane = ((Mask)1) << (pDraw->depth - 1);
2170
/* only planes asked for */
2171
length = widthBytesLine * height *
2172
Ones(planemask & (plane | (plane - 1)));
2176
xgi.length = length;
2179
pBuf = (char *)xalloc(sz_xGetImageReply + length);
2182
if (widthBytesLine == 0)
2185
linesPerBuf = height;
2186
*im_return = (xGetImageReply *)pBuf;
2187
*(xGetImageReply *)pBuf = xgi;
2188
pBuf += sz_xGetImageReply;
2190
xgi.length = (xgi.length + 3) >> 2;
2191
if (widthBytesLine == 0 || height == 0)
2193
else if (widthBytesLine >= IMAGE_BUFSIZE)
2197
linesPerBuf = IMAGE_BUFSIZE / widthBytesLine;
2198
if (linesPerBuf > height)
2199
linesPerBuf = height;
2201
length = linesPerBuf * widthBytesLine;
2202
if (linesPerBuf < height)
2204
/* we have to make sure intermediate buffers don't need padding */
2205
while ((linesPerBuf > 1) &&
2206
(length & ((1L << LOG2_BYTES_PER_SCANLINE_PAD)-1)))
2209
length -= widthBytesLine;
2211
while (length & ((1L << LOG2_BYTES_PER_SCANLINE_PAD)-1))
2214
length += widthBytesLine;
2217
if(!(pBuf = (char *) ALLOCATE_LOCAL(length)))
2219
WriteReplyToClient(client, sizeof (xGetImageReply), &xgi);
2223
if (client->trustLevel != XSecurityClientTrusted &&
2224
pDraw->type == DRAWABLE_WINDOW)
2226
pVisibleRegion = NotClippedByChildren((WindowPtr)pDraw);
2229
REGION_TRANSLATE(pScreen, pVisibleRegion, -pDraw->x, -pDraw->y);
2234
if (linesPerBuf == 0)
2238
else if (format == ZPixmap)
2241
while (height - linesDone > 0)
2243
nlines = min(linesPerBuf, height - linesDone);
2244
(*pDraw->pScreen->GetImage) (pDraw,
2254
SecurityCensorImage(client, pVisibleRegion, widthBytesLine,
2255
pDraw, x, y + linesDone, width,
2256
nlines, format, pBuf);
2259
/* Note that this is NOT a call to WriteSwappedDataToClient,
2260
as we do NOT byte swap */
2263
ReformatImage (pBuf, (int)(nlines * widthBytesLine),
2264
BitsPerPixel (pDraw->depth),
2265
ClientOrder(client));
2267
/* Don't split me, gcc pukes when you do */
2268
(void)WriteToClient(client,
2269
(int)(nlines * widthBytesLine),
2272
linesDone += nlines;
2277
for (; plane; plane >>= 1)
2279
if (planemask & plane)
2282
while (height - linesDone > 0)
2284
nlines = min(linesPerBuf, height - linesDone);
2285
(*pDraw->pScreen->GetImage) (pDraw,
2295
SecurityCensorImage(client, pVisibleRegion,
2297
pDraw, x, y + linesDone, width,
2298
nlines, format, pBuf);
2301
/* Note: NOT a call to WriteSwappedDataToClient,
2302
as we do NOT byte swap */
2304
pBuf += nlines * widthBytesLine;
2306
ReformatImage (pBuf,
2307
(int)(nlines * widthBytesLine),
2309
ClientOrder (client));
2311
/* Don't split me, gcc pukes when you do */
2312
(void)WriteToClient(client,
2313
(int)(nlines * widthBytesLine),
2316
linesDone += nlines;
2323
REGION_DESTROY(pScreen, pVisibleRegion);
2326
DEALLOCATE_LOCAL(pBuf);
2327
return (client->noClientException);
2331
ProcGetImage(client)
2332
register ClientPtr client;
2334
REQUEST(xGetImageReq);
2336
REQUEST_SIZE_MATCH(xGetImageReq);
2338
return DoGetImage(client, stuff->format, stuff->drawable,
2340
(int)stuff->width, (int)stuff->height,
2341
stuff->planeMask, (xGetImageReply **)NULL);
2345
ProcPolyText(client)
2346
register ClientPtr client;
2349
REQUEST(xPolyTextReq);
2353
REQUEST_AT_LEAST_SIZE(xPolyTextReq);
2354
VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
2356
err = PolyText(client,
2359
(unsigned char *)&stuff[1],
2360
((unsigned char *) stuff) + (client->req_len << 2),
2368
return(client->noClientException);
2375
ProcImageText8(client)
2376
register ClientPtr client;
2379
register DrawablePtr pDraw;
2382
REQUEST(xImageTextReq);
2384
REQUEST_FIXED_SIZE(xImageTextReq, stuff->nChars);
2385
VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
2387
err = ImageText(client,
2391
(unsigned char *)&stuff[1],
2399
return(client->noClientException);
2406
ProcImageText16(client)
2407
register ClientPtr client;
2410
register DrawablePtr pDraw;
2413
REQUEST(xImageTextReq);
2415
REQUEST_FIXED_SIZE(xImageTextReq, stuff->nChars << 1);
2416
VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
2418
err = ImageText(client,
2422
(unsigned char *)&stuff[1],
2430
return(client->noClientException);
2438
ProcCreateColormap(client)
2439
register ClientPtr client;
2444
register WindowPtr pWin;
2446
REQUEST(xCreateColormapReq);
2449
REQUEST_SIZE_MATCH(xCreateColormapReq);
2451
if ((stuff->alloc != AllocNone) && (stuff->alloc != AllocAll))
2453
client->errorValue = stuff->alloc;
2457
LEGAL_NEW_RESOURCE(mid, client);
2458
pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client,
2459
SecurityReadAccess);
2463
pScreen = pWin->drawable.pScreen;
2464
for (i = 0, pVisual = pScreen->visuals;
2465
i < pScreen->numVisuals;
2468
if (pVisual->vid != stuff->visual)
2470
result = CreateColormap(mid, pScreen, pVisual, &pmap,
2471
(int)stuff->alloc, client->index);
2472
if (client->noClientException != Success)
2473
return(client->noClientException);
2477
client->errorValue = stuff->visual;
2482
ProcFreeColormap(client)
2483
register ClientPtr client;
2486
REQUEST(xResourceReq);
2488
REQUEST_SIZE_MATCH(xResourceReq);
2489
pmap = (ColormapPtr )SecurityLookupIDByType(client, stuff->id, RT_COLORMAP,
2490
SecurityDestroyAccess);
2493
/* Freeing a default colormap is a no-op */
2494
if (!(pmap->flags & IsDefault))
2495
FreeResource(stuff->id, RT_NONE);
2496
return (client->noClientException);
2500
client->errorValue = stuff->id;
2507
ProcCopyColormapAndFree(client)
2508
register ClientPtr client;
2511
ColormapPtr pSrcMap;
2512
REQUEST(xCopyColormapAndFreeReq);
2515
REQUEST_SIZE_MATCH(xCopyColormapAndFreeReq);
2517
LEGAL_NEW_RESOURCE(mid, client);
2518
if( (pSrcMap = (ColormapPtr )SecurityLookupIDByType(client, stuff->srcCmap,
2519
RT_COLORMAP, SecurityReadAccess|SecurityWriteAccess)) )
2521
result = CopyColormapAndFree(mid, pSrcMap, client->index);
2522
if (client->noClientException != Success)
2523
return(client->noClientException);
2529
client->errorValue = stuff->srcCmap;
2535
ProcInstallColormap(client)
2536
register ClientPtr client;
2539
REQUEST(xResourceReq);
2541
REQUEST_SIZE_MATCH(xResourceReq);
2542
pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->id,
2543
RT_COLORMAP, SecurityReadAccess);
2546
(*(pcmp->pScreen->InstallColormap)) (pcmp);
2547
return (client->noClientException);
2551
client->errorValue = stuff->id;
2557
ProcUninstallColormap(client)
2558
register ClientPtr client;
2561
REQUEST(xResourceReq);
2563
REQUEST_SIZE_MATCH(xResourceReq);
2564
pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->id,
2565
RT_COLORMAP, SecurityReadAccess);
2568
if(pcmp->mid != pcmp->pScreen->defColormap)
2569
(*(pcmp->pScreen->UninstallColormap)) (pcmp);
2570
return (client->noClientException);
2574
client->errorValue = stuff->id;
2580
ProcListInstalledColormaps(client)
2581
register ClientPtr client;
2583
xListInstalledColormapsReply *preply;
2586
REQUEST(xResourceReq);
2588
REQUEST_SIZE_MATCH(xResourceReq);
2589
pWin = (WindowPtr)SecurityLookupWindow(stuff->id, client,
2590
SecurityReadAccess);
2595
preply = (xListInstalledColormapsReply *)
2596
ALLOCATE_LOCAL(sizeof(xListInstalledColormapsReply) +
2597
pWin->drawable.pScreen->maxInstalledCmaps *
2602
preply->type = X_Reply;
2603
preply->sequenceNumber = client->sequence;
2604
nummaps = (*pWin->drawable.pScreen->ListInstalledColormaps)
2605
(pWin->drawable.pScreen, (Colormap *)&preply[1]);
2606
preply->nColormaps = nummaps;
2607
preply->length = nummaps;
2608
WriteReplyToClient(client, sizeof (xListInstalledColormapsReply), preply);
2609
client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write;
2610
WriteSwappedDataToClient(client, nummaps * sizeof(Colormap), &preply[1]);
2611
DEALLOCATE_LOCAL(preply);
2612
return(client->noClientException);
2616
ProcAllocColor(client)
2617
register ClientPtr client;
2621
xAllocColorReply acr;
2622
REQUEST(xAllocColorReq);
2624
REQUEST_SIZE_MATCH(xAllocColorReq);
2625
pmap = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap,
2626
RT_COLORMAP, SecurityWriteAccess);
2631
* If the colormap is grabbed by a proxy, the server will have
2632
* to regain control over the colormap. This AllocColor request
2633
* will be handled after the server gets back the colormap control.
2635
if (LbxCheckColorRequest (client, pmap, (xReq *) stuff))
2640
acr.sequenceNumber = client->sequence;
2641
acr.red = stuff->red;
2642
acr.green = stuff->green;
2643
acr.blue = stuff->blue;
2645
if( (retval = AllocColor(pmap, &acr.red, &acr.green, &acr.blue,
2646
&acr.pixel, client->index)) )
2648
if (client->noClientException != Success)
2649
return(client->noClientException);
2654
if (noPanoramiXExtension || !pmap->pScreen->myNum)
2656
WriteReplyToClient(client, sizeof(xAllocColorReply), &acr);
2657
return (client->noClientException);
2662
client->errorValue = stuff->cmap;
2668
ProcAllocNamedColor (client)
2669
register ClientPtr client;
2672
REQUEST(xAllocNamedColorReq);
2674
REQUEST_FIXED_SIZE(xAllocNamedColorReq, stuff->nbytes);
2675
pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap,
2676
RT_COLORMAP, SecurityWriteAccess);
2681
xAllocNamedColorReply ancr;
2685
* If the colormap is grabbed by a proxy, the server will have
2686
* to regain control over the colormap. This AllocNamedColor request
2687
* will be handled after the server gets back the colormap control.
2689
if (LbxCheckColorRequest (client, pcmp, (xReq *) stuff))
2692
ancr.type = X_Reply;
2694
ancr.sequenceNumber = client->sequence;
2696
if(OsLookupColor(pcmp->pScreen->myNum, (char *)&stuff[1], stuff->nbytes,
2697
&ancr.exactRed, &ancr.exactGreen, &ancr.exactBlue))
2699
ancr.screenRed = ancr.exactRed;
2700
ancr.screenGreen = ancr.exactGreen;
2701
ancr.screenBlue = ancr.exactBlue;
2703
if( (retval = AllocColor(pcmp,
2704
&ancr.screenRed, &ancr.screenGreen, &ancr.screenBlue,
2705
&ancr.pixel, client->index)) )
2707
if (client->noClientException != Success)
2708
return(client->noClientException);
2713
if (noPanoramiXExtension || !pcmp->pScreen->myNum)
2715
WriteReplyToClient(client, sizeof (xAllocNamedColorReply), &ancr);
2716
return (client->noClientException);
2724
client->errorValue = stuff->cmap;
2730
ProcAllocColorCells (client)
2731
register ClientPtr client;
2734
REQUEST(xAllocColorCellsReq);
2736
REQUEST_SIZE_MATCH(xAllocColorCellsReq);
2737
pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap,
2738
RT_COLORMAP, SecurityWriteAccess);
2741
xAllocColorCellsReply accr;
2742
int npixels, nmasks, retval;
2744
Pixel *ppixels, *pmasks;
2748
* If the colormap is grabbed by a proxy, the server will have
2749
* to regain control over the colormap. This AllocColorCells request
2750
* will be handled after the server gets back the colormap control.
2752
if (LbxCheckColorRequest (client, pcmp, (xReq *) stuff))
2755
npixels = stuff->colors;
2758
client->errorValue = npixels;
2761
if (stuff->contiguous != xTrue && stuff->contiguous != xFalse)
2763
client->errorValue = stuff->contiguous;
2766
nmasks = stuff->planes;
2767
length = ((long)npixels + (long)nmasks) * sizeof(Pixel);
2768
ppixels = (Pixel *)ALLOCATE_LOCAL(length);
2771
pmasks = ppixels + npixels;
2773
if( (retval = AllocColorCells(client->index, pcmp, npixels, nmasks,
2774
(Bool)stuff->contiguous, ppixels, pmasks)) )
2776
DEALLOCATE_LOCAL(ppixels);
2777
if (client->noClientException != Success)
2778
return(client->noClientException);
2783
if (noPanoramiXExtension || !pcmp->pScreen->myNum)
2786
accr.type = X_Reply;
2787
accr.length = length >> 2;
2788
accr.sequenceNumber = client->sequence;
2789
accr.nPixels = npixels;
2790
accr.nMasks = nmasks;
2791
WriteReplyToClient(client, sizeof (xAllocColorCellsReply), &accr);
2792
client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write;
2793
WriteSwappedDataToClient(client, length, ppixels);
2795
DEALLOCATE_LOCAL(ppixels);
2796
return (client->noClientException);
2800
client->errorValue = stuff->cmap;
2806
ProcAllocColorPlanes(client)
2807
register ClientPtr client;
2810
REQUEST(xAllocColorPlanesReq);
2812
REQUEST_SIZE_MATCH(xAllocColorPlanesReq);
2813
pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap,
2814
RT_COLORMAP, SecurityWriteAccess);
2817
xAllocColorPlanesReply acpr;
2818
int npixels, retval;
2824
* If the colormap is grabbed by a proxy, the server will have
2825
* to regain control over the colormap. This AllocColorPlanes request
2826
* will be handled after the server gets back the colormap control.
2828
if (LbxCheckColorRequest (client, pcmp, (xReq *) stuff))
2831
npixels = stuff->colors;
2834
client->errorValue = npixels;
2837
if (stuff->contiguous != xTrue && stuff->contiguous != xFalse)
2839
client->errorValue = stuff->contiguous;
2842
acpr.type = X_Reply;
2843
acpr.sequenceNumber = client->sequence;
2844
acpr.nPixels = npixels;
2845
length = (long)npixels * sizeof(Pixel);
2846
ppixels = (Pixel *)ALLOCATE_LOCAL(length);
2849
if( (retval = AllocColorPlanes(client->index, pcmp, npixels,
2850
(int)stuff->red, (int)stuff->green, (int)stuff->blue,
2851
(Bool)stuff->contiguous, ppixels,
2852
&acpr.redMask, &acpr.greenMask, &acpr.blueMask)) )
2854
DEALLOCATE_LOCAL(ppixels);
2855
if (client->noClientException != Success)
2856
return(client->noClientException);
2860
acpr.length = length >> 2;
2862
if (noPanoramiXExtension || !pcmp->pScreen->myNum)
2865
WriteReplyToClient(client, sizeof(xAllocColorPlanesReply), &acpr);
2866
client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write;
2867
WriteSwappedDataToClient(client, length, ppixels);
2869
DEALLOCATE_LOCAL(ppixels);
2870
return (client->noClientException);
2874
client->errorValue = stuff->cmap;
2880
ProcFreeColors (client)
2881
register ClientPtr client;
2884
REQUEST(xFreeColorsReq);
2886
REQUEST_AT_LEAST_SIZE(xFreeColorsReq);
2887
pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap,
2888
RT_COLORMAP, SecurityWriteAccess);
2894
if(pcmp->flags & AllAllocated)
2896
count = ((client->req_len << 2)- sizeof(xFreeColorsReq)) >> 2;
2897
retval = FreeColors(pcmp, client->index, count,
2898
(Pixel *)&stuff[1], (Pixel)stuff->planeMask);
2899
if (client->noClientException != Success)
2900
return(client->noClientException);
2903
client->errorValue = clientErrorValue;
2910
client->errorValue = stuff->cmap;
2916
ProcStoreColors (client)
2917
register ClientPtr client;
2920
REQUEST(xStoreColorsReq);
2922
REQUEST_AT_LEAST_SIZE(xStoreColorsReq);
2923
pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap,
2924
RT_COLORMAP, SecurityWriteAccess);
2930
count = (client->req_len << 2) - sizeof(xStoreColorsReq);
2931
if (count % sizeof(xColorItem))
2933
count /= sizeof(xColorItem);
2934
retval = StoreColors(pcmp, count, (xColorItem *)&stuff[1]);
2935
if (client->noClientException != Success)
2936
return(client->noClientException);
2939
client->errorValue = clientErrorValue;
2945
client->errorValue = stuff->cmap;
2951
ProcStoreNamedColor (client)
2952
register ClientPtr client;
2955
REQUEST(xStoreNamedColorReq);
2957
REQUEST_FIXED_SIZE(xStoreNamedColorReq, stuff->nbytes);
2958
pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap,
2959
RT_COLORMAP, SecurityWriteAccess);
2965
if(OsLookupColor(pcmp->pScreen->myNum, (char *)&stuff[1],
2966
stuff->nbytes, &def.red, &def.green, &def.blue))
2968
def.flags = stuff->flags;
2969
def.pixel = stuff->pixel;
2970
retval = StoreColors(pcmp, 1, &def);
2971
if (client->noClientException != Success)
2972
return(client->noClientException);
2980
client->errorValue = stuff->cmap;
2986
ProcQueryColors(client)
2987
register ClientPtr client;
2990
REQUEST(xQueryColorsReq);
2992
REQUEST_AT_LEAST_SIZE(xQueryColorsReq);
2993
pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap,
2994
RT_COLORMAP, SecurityReadAccess);
2999
xQueryColorsReply qcr;
3001
count = ((client->req_len << 2) - sizeof(xQueryColorsReq)) >> 2;
3002
prgbs = (xrgb *)ALLOCATE_LOCAL(count * sizeof(xrgb));
3005
if( (retval = QueryColors(pcmp, count, (Pixel *)&stuff[1], prgbs)) )
3007
if (prgbs) DEALLOCATE_LOCAL(prgbs);
3008
if (client->noClientException != Success)
3009
return(client->noClientException);
3012
client->errorValue = clientErrorValue;
3017
qcr.length = (count * sizeof(xrgb)) >> 2;
3018
qcr.sequenceNumber = client->sequence;
3019
qcr.nColors = count;
3020
WriteReplyToClient(client, sizeof(xQueryColorsReply), &qcr);
3023
client->pSwapReplyFunc = (ReplySwapPtr) SQColorsExtend;
3024
WriteSwappedDataToClient(client, count * sizeof(xrgb), prgbs);
3026
if (prgbs) DEALLOCATE_LOCAL(prgbs);
3027
return(client->noClientException);
3032
client->errorValue = stuff->cmap;
3038
ProcLookupColor(client)
3039
register ClientPtr client;
3042
REQUEST(xLookupColorReq);
3044
REQUEST_FIXED_SIZE(xLookupColorReq, stuff->nbytes);
3045
pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap,
3046
RT_COLORMAP, SecurityReadAccess);
3049
xLookupColorReply lcr;
3051
if(OsLookupColor(pcmp->pScreen->myNum, (char *)&stuff[1], stuff->nbytes,
3052
&lcr.exactRed, &lcr.exactGreen, &lcr.exactBlue))
3056
lcr.sequenceNumber = client->sequence;
3057
lcr.screenRed = lcr.exactRed;
3058
lcr.screenGreen = lcr.exactGreen;
3059
lcr.screenBlue = lcr.exactBlue;
3060
(*pcmp->pScreen->ResolveColor)(&lcr.screenRed,
3064
WriteReplyToClient(client, sizeof(xLookupColorReply), &lcr);
3065
return(client->noClientException);
3071
client->errorValue = stuff->cmap;
3077
ProcCreateCursor( client)
3078
register ClientPtr client;
3082
register PixmapPtr src;
3083
register PixmapPtr msk;
3084
unsigned char * srcbits;
3085
unsigned char * mskbits;
3086
unsigned short width, height;
3091
REQUEST(xCreateCursorReq);
3093
REQUEST_SIZE_MATCH(xCreateCursorReq);
3094
LEGAL_NEW_RESOURCE(stuff->cid, client);
3096
src = (PixmapPtr)SecurityLookupIDByType(client, stuff->source,
3097
RT_PIXMAP, SecurityReadAccess);
3098
msk = (PixmapPtr)SecurityLookupIDByType(client, stuff->mask,
3099
RT_PIXMAP, SecurityReadAccess);
3100
if ( src == (PixmapPtr)NULL)
3102
client->errorValue = stuff->source;
3105
if ( msk == (PixmapPtr)NULL)
3107
if (stuff->mask != None)
3109
client->errorValue = stuff->mask;
3113
else if ( src->drawable.width != msk->drawable.width
3114
|| src->drawable.height != msk->drawable.height
3115
|| src->drawable.depth != 1
3116
|| msk->drawable.depth != 1)
3119
width = src->drawable.width;
3120
height = src->drawable.height;
3122
if ( stuff->x > width
3123
|| stuff->y > height )
3126
n = BitmapBytePad(width)*height;
3127
srcbits = (unsigned char *)xalloc(n);
3130
mskbits = (unsigned char *)xalloc(n);
3137
/* zeroing the (pad) bits helps some ddx cursor handling */
3138
bzero((char *)srcbits, n);
3139
(* src->drawable.pScreen->GetImage)( (DrawablePtr)src, 0, 0, width, height,
3140
XYPixmap, 1, (pointer)srcbits);
3141
if ( msk == (PixmapPtr)NULL)
3143
register unsigned char *bits = mskbits;
3149
/* zeroing the (pad) bits helps some ddx cursor handling */
3150
bzero((char *)mskbits, n);
3151
(* msk->drawable.pScreen->GetImage)( (DrawablePtr)msk, 0, 0, width,
3152
height, XYPixmap, 1, (pointer)mskbits);
3158
pCursor = AllocCursor( srcbits, mskbits, &cm,
3159
stuff->foreRed, stuff->foreGreen, stuff->foreBlue,
3160
stuff->backRed, stuff->backGreen, stuff->backBlue);
3162
if (pCursor && AddResource(stuff->cid, RT_CURSOR, (pointer)pCursor))
3163
return (client->noClientException);
3168
ProcCreateGlyphCursor( client)
3169
register ClientPtr client;
3174
REQUEST(xCreateGlyphCursorReq);
3176
REQUEST_SIZE_MATCH(xCreateGlyphCursorReq);
3177
LEGAL_NEW_RESOURCE(stuff->cid, client);
3179
res = AllocGlyphCursor(stuff->source, stuff->sourceChar,
3180
stuff->mask, stuff->maskChar,
3181
stuff->foreRed, stuff->foreGreen, stuff->foreBlue,
3182
stuff->backRed, stuff->backGreen, stuff->backBlue,
3186
if (AddResource(stuff->cid, RT_CURSOR, (pointer)pCursor))
3187
return client->noClientException;
3193
ProcFreeCursor(client)
3194
register ClientPtr client;
3197
REQUEST(xResourceReq);
3199
REQUEST_SIZE_MATCH(xResourceReq);
3200
pCursor = (CursorPtr)SecurityLookupIDByType(client, stuff->id,
3201
RT_CURSOR, SecurityDestroyAccess);
3204
FreeResource(stuff->id, RT_NONE);
3205
return (client->noClientException);
3209
client->errorValue = stuff->id;
3215
ProcQueryBestSize (client)
3216
register ClientPtr client;
3218
xQueryBestSizeReply reply;
3219
register DrawablePtr pDraw;
3221
REQUEST(xQueryBestSizeReq);
3223
REQUEST_SIZE_MATCH(xQueryBestSizeReq);
3224
if ((stuff->class != CursorShape) &&
3225
(stuff->class != TileShape) &&
3226
(stuff->class != StippleShape))
3228
client->errorValue = stuff->class;
3231
SECURITY_VERIFY_GEOMETRABLE (pDraw, stuff->drawable, client,
3232
SecurityReadAccess);
3233
if (stuff->class != CursorShape && pDraw->type == UNDRAWABLE_WINDOW)
3235
pScreen = pDraw->pScreen;
3236
(* pScreen->QueryBestSize)(stuff->class, &stuff->width,
3237
&stuff->height, pScreen);
3238
reply.type = X_Reply;
3240
reply.sequenceNumber = client->sequence;
3241
reply.width = stuff->width;
3242
reply.height = stuff->height;
3243
WriteReplyToClient(client, sizeof(xQueryBestSizeReply), &reply);
3244
return (client->noClientException);
3249
ProcSetScreenSaver (client)
3250
register ClientPtr client;
3252
int blankingOption, exposureOption;
3253
REQUEST(xSetScreenSaverReq);
3255
REQUEST_SIZE_MATCH(xSetScreenSaverReq);
3256
blankingOption = stuff->preferBlank;
3257
if ((blankingOption != DontPreferBlanking) &&
3258
(blankingOption != PreferBlanking) &&
3259
(blankingOption != DefaultBlanking))
3261
client->errorValue = blankingOption;
3264
exposureOption = stuff->allowExpose;
3265
if ((exposureOption != DontAllowExposures) &&
3266
(exposureOption != AllowExposures) &&
3267
(exposureOption != DefaultExposures))
3269
client->errorValue = exposureOption;
3272
if (stuff->timeout < -1)
3274
client->errorValue = stuff->timeout;
3277
if (stuff->interval < -1)
3279
client->errorValue = stuff->interval;
3283
if (blankingOption == DefaultBlanking)
3284
ScreenSaverBlanking = defaultScreenSaverBlanking;
3286
ScreenSaverBlanking = blankingOption;
3287
if (exposureOption == DefaultExposures)
3288
ScreenSaverAllowExposures = defaultScreenSaverAllowExposures;
3290
ScreenSaverAllowExposures = exposureOption;
3292
if (stuff->timeout >= 0)
3293
ScreenSaverTime = stuff->timeout * MILLI_PER_SECOND;
3295
ScreenSaverTime = defaultScreenSaverTime;
3296
if (stuff->interval >= 0)
3297
ScreenSaverInterval = stuff->interval * MILLI_PER_SECOND;
3299
ScreenSaverInterval = defaultScreenSaverInterval;
3300
return (client->noClientException);
3304
ProcGetScreenSaver(client)
3305
register ClientPtr client;
3307
xGetScreenSaverReply rep;
3309
REQUEST_SIZE_MATCH(xReq);
3312
rep.sequenceNumber = client->sequence;
3313
rep.timeout = ScreenSaverTime / MILLI_PER_SECOND;
3314
rep.interval = ScreenSaverInterval / MILLI_PER_SECOND;
3315
rep.preferBlanking = ScreenSaverBlanking;
3316
rep.allowExposures = ScreenSaverAllowExposures;
3317
WriteReplyToClient(client, sizeof(xGetScreenSaverReply), &rep);
3318
return (client->noClientException);
3322
ProcChangeHosts(client)
3323
register ClientPtr client;
3325
REQUEST(xChangeHostsReq);
3328
REQUEST_FIXED_SIZE(xChangeHostsReq, stuff->hostLength);
3330
if(stuff->mode == HostInsert)
3331
result = AddHost(client, (int)stuff->hostFamily,
3332
stuff->hostLength, (pointer)&stuff[1]);
3333
else if (stuff->mode == HostDelete)
3334
result = RemoveHost(client, (int)stuff->hostFamily,
3335
stuff->hostLength, (pointer)&stuff[1]);
3338
client->errorValue = stuff->mode;
3342
result = client->noClientException;
3347
ProcListHosts(client)
3348
register ClientPtr client;
3350
xListHostsReply reply;
3351
int len, nHosts, result;
3353
/* REQUEST(xListHostsReq); */
3355
REQUEST_SIZE_MATCH(xListHostsReq);
3357
/* untrusted clients can't list hosts */
3358
if (client->trustLevel != XSecurityClientTrusted)
3360
SecurityAudit("client %d attempted to list hosts\n", client->index);
3364
result = GetHosts(&pdata, &nHosts, &len, &reply.enabled);
3365
if (result != Success)
3367
reply.type = X_Reply;
3368
reply.sequenceNumber = client->sequence;
3369
reply.nHosts = nHosts;
3370
reply.length = len >> 2;
3371
WriteReplyToClient(client, sizeof(xListHostsReply), &reply);
3374
client->pSwapReplyFunc = (ReplySwapPtr) SLHostsExtend;
3375
WriteSwappedDataToClient(client, len, pdata);
3378
return (client->noClientException);
3382
ProcChangeAccessControl(client)
3383
register ClientPtr client;
3386
REQUEST(xSetAccessControlReq);
3388
REQUEST_SIZE_MATCH(xSetAccessControlReq);
3389
if ((stuff->mode != EnableAccess) && (stuff->mode != DisableAccess))
3391
client->errorValue = stuff->mode;
3394
result = ChangeAccessControl(client, stuff->mode == EnableAccess);
3396
result = client->noClientException;
3401
ProcKillClient(client)
3402
register ClientPtr client;
3404
REQUEST(xResourceReq);
3405
ClientPtr killclient;
3407
REQUEST_SIZE_MATCH(xResourceReq);
3408
if (stuff->id == AllTemporary)
3410
CloseDownRetainedResources();
3411
return (client->noClientException);
3414
if ((killclient = LookupClient(stuff->id, client)))
3416
CloseDownClient(killclient);
3417
/* if an LBX proxy gets killed, isItTimeToYield will be set */
3418
if (isItTimeToYield || (client == killclient))
3420
/* force yield and return Success, so that Dispatch()
3421
* doesn't try to touch client
3423
isItTimeToYield = TRUE;
3426
return (client->noClientException);
3430
client->errorValue = stuff->id;
3436
ProcSetFontPath(client)
3437
register ClientPtr client;
3440
unsigned long nbytes, total;
3444
REQUEST(xSetFontPathReq);
3446
REQUEST_AT_LEAST_SIZE(xSetFontPathReq);
3448
nbytes = (client->req_len << 2) - sizeof(xSetFontPathReq);
3450
ptr = (unsigned char *)&stuff[1];
3451
nfonts = stuff->nFonts;
3452
while (--nfonts >= 0)
3454
if ((total == 0) || (total < (n = (*ptr + 1))))
3461
result = SetFontPath(client, stuff->nFonts, (unsigned char *)&stuff[1],
3465
result = client->noClientException;
3466
client->errorValue = error;
3472
ProcGetFontPath(client)
3473
register ClientPtr client;
3475
xGetFontPathReply reply;
3476
int stringLens, numpaths;
3477
unsigned char *bufferStart;
3478
/* REQUEST (xReq); */
3480
REQUEST_SIZE_MATCH(xReq);
3481
bufferStart = GetFontPath(&numpaths, &stringLens);
3483
reply.type = X_Reply;
3484
reply.sequenceNumber = client->sequence;
3485
reply.length = (stringLens + numpaths + 3) >> 2;
3486
reply.nPaths = numpaths;
3488
WriteReplyToClient(client, sizeof(xGetFontPathReply), &reply);
3489
if (stringLens || numpaths)
3490
(void)WriteToClient(client, stringLens + numpaths, (char *)bufferStart);
3491
return(client->noClientException);
3495
ProcChangeCloseDownMode(client)
3496
register ClientPtr client;
3498
REQUEST(xSetCloseDownModeReq);
3500
REQUEST_SIZE_MATCH(xSetCloseDownModeReq);
3501
if ((stuff->mode == AllTemporary) ||
3502
(stuff->mode == RetainPermanent) ||
3503
(stuff->mode == RetainTemporary))
3505
client->closeDownMode = stuff->mode;
3506
return (client->noClientException);
3510
client->errorValue = stuff->mode;
3515
int ProcForceScreenSaver(client)
3516
register ClientPtr client;
3518
REQUEST(xForceScreenSaverReq);
3520
REQUEST_SIZE_MATCH(xForceScreenSaverReq);
3522
if ((stuff->mode != ScreenSaverReset) &&
3523
(stuff->mode != ScreenSaverActive))
3525
client->errorValue = stuff->mode;
3528
SaveScreens(SCREEN_SAVER_FORCER, (int)stuff->mode);
3529
return client->noClientException;
3532
int ProcNoOperation(client)
3533
register ClientPtr client;
3535
REQUEST_AT_LEAST_SIZE(xReq);
3537
/* noop -- don't do anything */
3538
return(client->noClientException);
3542
InitProcVectors(void)
3545
for (i = 0; i<256; i++)
3549
ProcVector[i] = SwappedProcVector[i] = ProcBadRequest;
3550
ReplySwapVector[i] = ReplyNotSwappd;
3555
k5_Vector[i] = k5_bad;
3559
for(i = LASTEvent; i < 128; i++)
3561
EventSwapVector[i] = NotImplemented;
3566
/**********************
3569
* Client can either mark his resources destroy or retain. If retained and
3570
* then killed again, the client is really destroyed.
3571
*********************/
3573
char dispatchExceptionAtReset = DE_RESET;
3576
CloseDownClient(client)
3577
register ClientPtr client;
3579
Bool really_close_down = client->clientGone ||
3580
client->closeDownMode == DestroyAll;
3582
if (!client->clientGone)
3584
/* ungrab server if grabbing client dies */
3585
if (grabState != GrabNone && grabClient == client)
3587
UngrabServer(client);
3589
BITCLEAR(grabWaiters, client->index);
3590
DeleteClientFromAnySelections(client);
3591
ReleaseActiveGrabs(client);
3592
DeleteClientFontStuff(client);
3593
if (!really_close_down)
3595
/* This frees resources that should never be retained
3596
* no matter what the close down mode is. Actually we
3597
* could do this unconditionally, but it's probably
3598
* better not to traverse all the client's resources
3599
* twice (once here, once a few lines down in
3600
* FreeClientResources) in the common case of
3601
* really_close_down == TRUE.
3603
FreeClientNeverRetainResources(client);
3604
client->clientState = ClientStateRetained;
3605
if (ClientStateCallback)
3607
NewClientInfoRec clientinfo;
3609
clientinfo.client = client;
3610
clientinfo.prefix = (xConnSetupPrefix *)NULL;
3611
clientinfo.setup = (xConnSetup *) NULL;
3612
CallCallbacks((&ClientStateCallback), (pointer)&clientinfo);
3615
client->clientGone = TRUE; /* so events aren't sent to client */
3616
if (ClientIsAsleep(client))
3617
ClientSignal (client);
3618
ProcessWorkQueueZombies();
3620
ProcessQTagZombies();
3622
CloseDownConnection(client);
3624
/* If the client made it to the Running stage, nClients has
3625
* been incremented on its behalf, so we need to decrement it
3626
* now. If it hasn't gotten to Running, nClients has *not*
3627
* been incremented, so *don't* decrement it.
3629
if (client->clientState != ClientStateInitial &&
3630
client->clientState != ClientStateAuthenticating )
3636
if (really_close_down)
3638
if (client->clientState == ClientStateRunning && nClients == 0)
3639
dispatchException |= dispatchExceptionAtReset;
3641
client->clientState = ClientStateGone;
3642
if (ClientStateCallback)
3644
NewClientInfoRec clientinfo;
3646
clientinfo.client = client;
3647
clientinfo.prefix = (xConnSetupPrefix *)NULL;
3648
clientinfo.setup = (xConnSetup *) NULL;
3649
CallCallbacks((&ClientStateCallback), (pointer)&clientinfo);
3651
FreeClientResources(client);
3652
if (client->index < nextFreeClientID)
3653
nextFreeClientID = client->index;
3654
clients[client->index] = NullClient;
3655
#ifdef SMART_SCHEDULE
3656
SmartLastClient = NullClient;
3660
while (!clients[currentMaxClients-1])
3661
currentMaxClients--;
3669
for (i=1; i<currentMaxClients; i++)
3671
/* Make sure Retained clients are released. */
3672
clients[i]->closeDownMode = DestroyAll;
3673
CloseDownClient(clients[i]);
3677
/*********************
3678
* CloseDownRetainedResources
3680
* Find all clients that are gone and have terminated in RetainTemporary
3681
* and destroy their resources.
3682
*********************/
3685
CloseDownRetainedResources()
3688
register ClientPtr client;
3690
for (i=1; i<currentMaxClients; i++)
3692
client = clients[i];
3693
if (client && (client->closeDownMode == RetainTemporary)
3694
&& (client->clientGone))
3695
CloseDownClient(client);
3699
void InitClient(client, i, ospriv)
3705
client->sequence = 0;
3706
client->clientAsMask = ((Mask)i) << CLIENTOFFSET;
3707
client->clientGone = FALSE;
3710
client->closeDownMode = DestroyAll;
3711
client->lastDrawable = (DrawablePtr)WindowTable[0];
3712
client->lastDrawableID = WindowTable[0]->drawable.id;
3716
client->closeDownMode = RetainPermanent;
3717
client->lastDrawable = (DrawablePtr)NULL;
3718
client->lastDrawableID = INVALID;
3720
client->lastGC = (GCPtr) NULL;
3721
client->lastGCID = INVALID;
3722
client->numSaved = 0;
3723
client->saveSet = (pointer *)NULL;
3724
client->noClientException = Success;
3726
client->requestLogIndex = 0;
3728
client->requestVector = InitialVector;
3729
client->osPrivate = ospriv;
3730
client->swapped = FALSE;
3731
client->big_requests = FALSE;
3732
client->priority = 0;
3733
client->clientState = ClientStateInitial;
3735
if (!noXkbExtension) {
3736
client->xkbClientFlags = 0;
3737
client->mapNotifyMask = 0;
3738
QueryMinMaxKeyCodes(&client->minKC,&client->maxKC);
3741
client->replyBytesRemaining = 0;
3743
client->readRequest = StandardReadRequestFromClient;
3746
client->trustLevel = XSecurityClientTrusted;
3747
client->CheckAccess = NULL;
3751
client->appgroup = NULL;
3753
client->fontResFunc = NULL;
3754
#ifdef SMART_SCHEDULE
3755
client->smart_priority = 0;
3756
client->smart_start_tick = SmartScheduleTime;
3757
client->smart_stop_tick = SmartScheduleTime;
3758
client->smart_check_tick = SmartScheduleTime;
3762
extern int clientPrivateLen;
3763
extern unsigned *clientPrivateSizes;
3764
extern unsigned totalClientSize;
3767
InitClientPrivates(client)
3772
register unsigned *sizes;
3773
register unsigned size;
3776
if (totalClientSize == sizeof(ClientRec))
3777
ppriv = (DevUnion *)NULL;
3778
else if (client->index)
3779
ppriv = (DevUnion *)(client + 1);
3782
ppriv = (DevUnion *)xalloc(totalClientSize - sizeof(ClientRec));
3786
client->devPrivates = ppriv;
3787
sizes = clientPrivateSizes;
3788
ptr = (char *)(ppriv + clientPrivateLen);
3789
for (i = clientPrivateLen; --i >= 0; ppriv++, sizes++)
3791
if ( (size = *sizes) )
3793
ppriv->ptr = (pointer)ptr;
3797
ppriv->ptr = (pointer)NULL;
3802
/************************
3803
* int NextAvailableClient(ospriv)
3805
* OS dependent portion can't assign client id's because of CloseDownModes.
3806
* Returns NULL if there are no free clients.
3807
*************************/
3810
NextAvailableClient(ospriv)
3814
register ClientPtr client;
3817
i = nextFreeClientID;
3818
if (i == MAXCLIENTS)
3819
return (ClientPtr)NULL;
3820
clients[i] = client = (ClientPtr)xalloc(totalClientSize);
3822
return (ClientPtr)NULL;
3823
InitClient(client, i, ospriv);
3824
InitClientPrivates(client);
3825
if (!InitClientResources(client))
3828
return (ClientPtr)NULL;
3831
data.length = (sz_xReq + sz_xConnClientPrefix) >> 2;
3832
if (!InsertFakeRequest(client, (char *)&data, sz_xReq))
3834
FreeClientResources(client);
3836
return (ClientPtr)NULL;
3838
if (i == currentMaxClients)
3839
currentMaxClients++;
3840
while ((nextFreeClientID < MAXCLIENTS) && clients[nextFreeClientID])
3842
if (ClientStateCallback)
3844
NewClientInfoRec clientinfo;
3846
clientinfo.client = client;
3847
clientinfo.prefix = (xConnSetupPrefix *)NULL;
3848
clientinfo.setup = (xConnSetup *) NULL;
3849
CallCallbacks((&ClientStateCallback), (pointer)&clientinfo);
3855
ProcInitialConnection(client)
3856
register ClientPtr client;
3859
register xConnClientPrefix *prefix;
3862
prefix = (xConnClientPrefix *)((char *)stuff + sz_xReq);
3863
if ((prefix->byteOrder != 'l') && (prefix->byteOrder != 'B'))
3864
return (client->noClientException = -1);
3865
if (((*(char *) &whichbyte) && (prefix->byteOrder == 'B')) ||
3866
(!(*(char *) &whichbyte) && (prefix->byteOrder == 'l')))
3868
client->swapped = TRUE;
3869
SwapConnClientPrefix(prefix);
3872
stuff->length += ((prefix->nbytesAuthProto + (unsigned)3) >> 2) +
3873
((prefix->nbytesAuthString + (unsigned)3) >> 2);
3874
if (client->swapped)
3876
swaps(&stuff->length, whichbyte);
3878
ResetCurrentRequest(client);
3879
return (client->noClientException);
3884
IncrementClientCount()
3891
SendConnSetup(client, reason)
3892
register ClientPtr client;
3895
register xWindowRoot *root;
3898
char* lConnectionInfo;
3899
xConnSetupPrefix* lconnSetupPrefix;
3903
xConnSetupPrefix csp;
3905
csp.success = xFalse;
3906
csp.lengthReason = strlen(reason);
3907
csp.length = (csp.lengthReason + (unsigned)3) >> 2;
3908
csp.majorVersion = X_PROTOCOL;
3909
csp.minorVersion = X_PROTOCOL_REVISION;
3910
if (client->swapped)
3911
WriteSConnSetupPrefix(client, &csp);
3913
(void)WriteToClient(client, sz_xConnSetupPrefix, (char *) &csp);
3914
(void)WriteToClient(client, (int)csp.lengthReason, reason);
3915
return (client->noClientException = -1);
3918
numScreens = screenInfo.numScreens;
3919
lConnectionInfo = ConnectionInfo;
3920
lconnSetupPrefix = &connSetupPrefix;
3922
/* We're about to start speaking X protocol back to the client by
3923
* sending the connection setup info. This means the authorization
3924
* step is complete, and we can count the client as an
3929
client->requestVector = client->swapped ? SwappedProcVector : ProcVector;
3930
client->sequence = 0;
3932
XagConnectionInfo (client, &lconnSetupPrefix, &lConnectionInfo, &numScreens);
3934
((xConnSetup *)lConnectionInfo)->ridBase = client->clientAsMask;
3935
((xConnSetup *)lConnectionInfo)->ridMask = RESOURCE_ID_MASK;
3936
#ifdef MATCH_CLIENT_ENDIAN
3937
((xConnSetup *)lConnectionInfo)->imageByteOrder = ClientOrder (client);
3938
((xConnSetup *)lConnectionInfo)->bitmapBitOrder = ClientOrder (client);
3940
/* fill in the "currentInputMask" */
3941
root = (xWindowRoot *)(lConnectionInfo + connBlockScreenStart);
3943
if (noPanoramiXExtension)
3944
numScreens = screenInfo.numScreens;
3946
numScreens = ((xConnSetup *)ConnectionInfo)->numRoots;
3949
for (i=0; i<numScreens; i++)
3951
register unsigned int j;
3952
register xDepth *pDepth;
3954
root->currentInputMask = WindowTable[i]->eventMask |
3955
wOtherEventMasks (WindowTable[i]);
3956
pDepth = (xDepth *)(root + 1);
3957
for (j = 0; j < root->nDepths; j++)
3959
pDepth = (xDepth *)(((char *)(pDepth + 1)) +
3960
pDepth->nVisuals * sizeof(xVisualType));
3962
root = (xWindowRoot *)pDepth;
3965
if (client->swapped)
3967
WriteSConnSetupPrefix(client, lconnSetupPrefix);
3968
WriteSConnectionInfo(client,
3969
(unsigned long)(lconnSetupPrefix->length << 2),
3974
(void)WriteToClient(client, sizeof(xConnSetupPrefix),
3975
(char *) lconnSetupPrefix);
3976
(void)WriteToClient(client, (int)(lconnSetupPrefix->length << 2),
3979
client->clientState = ClientStateRunning;
3980
if (ClientStateCallback)
3982
NewClientInfoRec clientinfo;
3984
clientinfo.client = client;
3985
clientinfo.prefix = lconnSetupPrefix;
3986
clientinfo.setup = (xConnSetup *)lConnectionInfo;
3987
CallCallbacks((&ClientStateCallback), (pointer)&clientinfo);
3989
return (client->noClientException);
3993
ProcEstablishConnection(client)
3994
register ClientPtr client;
3996
char *reason, *auth_proto, *auth_string;
3997
register xConnClientPrefix *prefix;
4000
prefix = (xConnClientPrefix *)((char *)stuff + sz_xReq);
4001
auth_proto = (char *)prefix + sz_xConnClientPrefix;
4002
auth_string = auth_proto + ((prefix->nbytesAuthProto + 3) & ~3);
4003
if ((prefix->majorVersion != X_PROTOCOL) ||
4004
(prefix->minorVersion != X_PROTOCOL_REVISION))
4005
reason = "Protocol version mismatch";
4007
reason = ClientAuthorized(client,
4008
(unsigned short)prefix->nbytesAuthProto,
4010
(unsigned short)prefix->nbytesAuthString,
4013
* If Kerberos is being used for this client, the clientState
4014
* will be set to ClientStateAuthenticating at this point.
4015
* More messages need to be exchanged among the X server, Kerberos
4016
* server, and client to figure out if everyone is authorized.
4017
* So we don't want to send the connection setup info yet, since
4018
* the auth step isn't really done.
4020
if (client->clientState == ClientStateCheckingSecurity)
4021
client->clientState = ClientStateCheckedSecurity;
4022
else if (client->clientState != ClientStateAuthenticating)
4023
return(SendConnSetup(client, reason));
4024
return(client->noClientException);
4028
SendErrorToClient(client, majorCode, minorCode, resId, errorCode)
4030
unsigned int majorCode;
4031
unsigned int minorCode;
4038
rep.sequenceNumber = client->sequence;
4039
rep.errorCode = errorCode;
4040
rep.majorCode = majorCode;
4041
rep.minorCode = minorCode;
4042
rep.resourceID = resId;
4044
WriteEventsToClient (client, 1, (xEvent *)&rep);
4048
DeleteWindowFromAnySelections(pWin)
4053
for (i = 0; i< NumCurrentSelections; i++)
4054
if (CurrentSelections[i].pWin == pWin)
4056
CurrentSelections[i].pWin = (WindowPtr)NULL;
4057
CurrentSelections[i].window = None;
4058
CurrentSelections[i].client = NullClient;
4063
DeleteClientFromAnySelections(client)
4068
for (i = 0; i< NumCurrentSelections; i++)
4069
if (CurrentSelections[i].client == client)
4071
CurrentSelections[i].pWin = (WindowPtr)NULL;
4072
CurrentSelections[i].window = None;
4073
CurrentSelections[i].client = NullClient;
4078
MarkClientException(client)
4081
client->noClientException = -1;