12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872 |
- /************************************************************
- Copyright 1987, 1989, 1998 The Open Group
- Permission to use, copy, modify, distribute, and sell this software and its
- documentation for any purpose is hereby granted without fee, provided that
- the above copyright notice appear in all copies and that both that
- copyright notice and this permission notice appear in supporting
- documentation.
- The above copyright notice and this permission notice shall be included in
- all copies or substantial portions of the Software.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- Except as contained in this notice, the name of The Open Group shall not be
- used in advertising or otherwise to promote the sale, use or other dealings
- in this Software without prior written authorization from The Open Group.
- Copyright 1987, 1989 by Digital Equipment Corporation, Maynard, Massachusetts.
- All Rights Reserved
- Permission to use, copy, modify, and distribute this software and its
- documentation for any purpose and without fee is hereby granted,
- provided that the above copyright notice appear in all copies and that
- both that copyright notice and this permission notice appear in
- supporting documentation, and that the name of Digital not be
- used in advertising or publicity pertaining to distribution of the
- software without specific, written prior permission.
- DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
- ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
- DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
- ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
- WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
- ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
- SOFTWARE.
- ********************************************************/
- /* The panoramix components contained the following notice */
- /*****************************************************************
- Copyright (c) 1991, 1997 Digital Equipment Corporation, Maynard, Massachusetts.
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software.
- The above copyright notice and this permission notice shall be included in
- all copies or substantial portions of the Software.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR ANY CLAIM, DAMAGES, INCLUDING,
- BUT NOT LIMITED TO CONSEQUENTIAL OR INCIDENTAL DAMAGES, OR OTHER LIABILITY,
- WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
- IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- Except as contained in this notice, the name of Digital Equipment Corporation
- shall not be used in advertising or otherwise to promote the sale, use or other
- dealings in this Software without prior written authorization from Digital
- Equipment Corporation.
- ******************************************************************/
- #ifdef HAVE_DIX_CONFIG_H
- #include <dix-config.h>
- #endif
- #include "windowstr.h"
- #include <X11/fonts/fontstruct.h>
- #include "dixfontstr.h"
- #include "gcstruct.h"
- #include "selection.h"
- #include "colormapst.h"
- #include "cursorstr.h"
- #include "scrnintstr.h"
- #include "opaque.h"
- #include "input.h"
- #include "servermd.h"
- #include "extnsionst.h"
- #include "dixfont.h"
- #include "dispatch.h"
- #include "swaprep.h"
- #include "swapreq.h"
- #define mskcnt ((MAXCLIENTS + 31) / 32)
- #define BITMASK(i) (1U << ((i) & 31))
- #define MASKIDX(i) ((i) >> 5)
- #define MASKWORD(buf, i) buf[MASKIDX(i)]
- #define BITSET(buf, i) MASKWORD(buf, i) |= BITMASK(i)
- #define BITCLEAR(buf, i) MASKWORD(buf, i) &= ~BITMASK(i)
- #define GETBIT(buf, i) (MASKWORD(buf, i) & BITMASK(i))
- extern xConnSetupPrefix connSetupPrefix;
- extern char *ConnectionInfo;
- _X_EXPORT Selection *CurrentSelections;
- _X_EXPORT int NumCurrentSelections;
- CallbackListPtr SelectionCallback = NULL;
- static ClientPtr grabClient;
- #define GrabNone 0
- #define GrabActive 1
- #define GrabKickout 2
- static int grabState = GrabNone;
- static long grabWaiters[mskcnt];
- _X_EXPORT CallbackListPtr ServerGrabCallback = NULL;
- HWEventQueuePtr checkForInput[2];
- extern int connBlockScreenStart;
- static void KillAllClients(void);
- static void DeleteClientFromAnySelections(ClientPtr client);
- static int nextFreeClientID; /* always MIN free client ID */
- static int nClients; /* number of authorized clients */
- _X_EXPORT CallbackListPtr ClientStateCallback;
- /* dispatchException & isItTimeToYield must be declared volatile since they
- * are modified by signal handlers - otherwise optimizer may assume it doesn't
- * need to actually check value in memory when used and may miss changes from
- * signal handlers.
- */
- _X_EXPORT volatile char dispatchException = 0;
- _X_EXPORT volatile char isItTimeToYield;
- /* Various of the DIX function interfaces were not designed to allow
- * the client->errorValue to be set on BadValue and other errors.
- * Rather than changing interfaces and breaking untold code we introduce
- * a new global that dispatch can use.
- */
- XID clientErrorValue; /* XXX this is a kludge */
- #define SAME_SCREENS(a, b) (\
- (a.pScreen == b.pScreen))
- _X_EXPORT void
- SetInputCheck(HWEventQueuePtr c0, HWEventQueuePtr c1)
- {
- checkForInput[0] = c0;
- checkForInput[1] = c1;
- }
- _X_EXPORT void
- UpdateCurrentTime()
- {
- TimeStamp systime;
- /* To avoid time running backwards, we must call GetTimeInMillis before
- * calling ProcessInputEvents.
- */
- systime.months = currentTime.months;
- systime.milliseconds = GetTimeInMillis();
- if (systime.milliseconds < currentTime.milliseconds)
- systime.months++;
- if (*checkForInput[0] != *checkForInput[1])
- ProcessInputEvents();
- if (CompareTimeStamps(systime, currentTime) == LATER)
- currentTime = systime;
- }
- /* Like UpdateCurrentTime, but can't call ProcessInputEvents */
- _X_EXPORT void
- UpdateCurrentTimeIf()
- {
- TimeStamp systime;
- systime.months = currentTime.months;
- systime.milliseconds = GetTimeInMillis();
- if (systime.milliseconds < currentTime.milliseconds)
- systime.months++;
- if (*checkForInput[0] == *checkForInput[1])
- currentTime = systime;
- }
- void
- InitSelections()
- {
- if (CurrentSelections)
- free(CurrentSelections);
- CurrentSelections = (Selection *) NULL;
- NumCurrentSelections = 0;
- }
- void
- FlushClientCaches(XID id)
- {
- int i;
- ClientPtr client;
- client = clients[CLIENT_ID(id)];
- if (client == NullClient)
- return;
- for (i = 0; i < currentMaxClients; i++) {
- client = clients[i];
- if (client != NullClient) {
- if (client->lastDrawableID == id) {
- client->lastDrawableID = WindowTable[0]->drawable.id;
- client->lastDrawable = (DrawablePtr) WindowTable[0];
- }
- else if (client->lastGCID == id) {
- client->lastGCID = INVALID;
- client->lastGC = (GCPtr) NULL;
- }
- }
- }
- }
- #ifdef SMART_SCHEDULE
- #undef SMART_DEBUG
- #define SMART_SCHEDULE_DEFAULT_INTERVAL 7 /* ms */
- #define SMART_SCHEDULE_MAX_SLICE 20 /* ms */
- Bool SmartScheduleDisable = FALSE;
- long SmartScheduleSlice = SMART_SCHEDULE_DEFAULT_INTERVAL;
- long SmartScheduleInterval = SMART_SCHEDULE_DEFAULT_INTERVAL;
- long SmartScheduleMaxSlice = SMART_SCHEDULE_MAX_SLICE;
- long SmartScheduleTime;
- ClientPtr SmartLastClient;
- int SmartLastIndex[SMART_MAX_PRIORITY - SMART_MIN_PRIORITY + 1];
- int SmartScheduleClient(int *clientReady, int nready);
- #ifdef SMART_DEBUG
- long SmartLastPrint;
- #endif
- void Dispatch(void);
- int
- SmartScheduleClient(int *clientReady, int nready)
- {
- ClientPtr pClient;
- int i;
- int client;
- int bestPrio, best = 0;
- int bestRobin, robin;
- long now = SmartScheduleTime;
- long idle;
- bestPrio = -0x7fffffff;
- bestRobin = 0;
- idle = 2 * SmartScheduleSlice;
- for (i = 0; i < nready; i++) {
- client = clientReady[i];
- pClient = clients[client];
- /* Praise clients which are idle */
- if ((now - pClient->smart_check_tick) >= idle) {
- if (pClient->smart_priority < 0)
- pClient->smart_priority++;
- }
- pClient->smart_check_tick = now;
- /* check priority to select best client */
- robin =
- (pClient->index -
- SmartLastIndex[pClient->smart_priority -
- SMART_MIN_PRIORITY]) & 0xff;
- if (pClient->smart_priority > bestPrio ||
- (pClient->smart_priority == bestPrio && robin > bestRobin)) {
- bestPrio = pClient->smart_priority;
- bestRobin = robin;
- best = client;
- }
- #ifdef SMART_DEBUG
- if ((now - SmartLastPrint) >= 5000)
- fprintf(stderr, " %2d: %3d", client, pClient->smart_priority);
- #endif
- }
- #ifdef SMART_DEBUG
- if ((now - SmartLastPrint) >= 5000) {
- fprintf(stderr, " use %2d\n", best);
- SmartLastPrint = now;
- }
- #endif
- pClient = clients[best];
- SmartLastIndex[bestPrio - SMART_MIN_PRIORITY] = pClient->index;
- /*
- * Set current client pointer
- */
- if (SmartLastClient != pClient) {
- pClient->smart_start_tick = now;
- SmartLastClient = pClient;
- }
- /*
- * Adjust slice
- */
- if (nready == 1) {
- /*
- * If it's been a long time since another client
- * has run, bump the slice up to get maximal
- * performance from a single client
- */
- if ((now - pClient->smart_start_tick) > 1000 &&
- SmartScheduleSlice < SmartScheduleMaxSlice) {
- SmartScheduleSlice += SmartScheduleInterval;
- }
- }
- else {
- SmartScheduleSlice = SmartScheduleInterval;
- }
- return best;
- }
- #endif
- #define MAJOROP ((xReq *)client->requestBuffer)->reqType
- void
- Dispatch(void)
- {
- int *clientReady; /* array of request ready clients */
- int result;
- ClientPtr client;
- int nready;
- HWEventQueuePtr *icheck = checkForInput;
- #ifdef SMART_SCHEDULE
- long start_tick;
- #endif
- nextFreeClientID = 1;
- InitSelections();
- nClients = 0;
- clientReady = (int *) ALLOCATE_LOCAL(sizeof(int) * MaxClients);
- if (!clientReady)
- return;
- while (!dispatchException) {
- if (*icheck[0] != *icheck[1]) {
- ProcessInputEvents();
- FlushIfCriticalOutputPending();
- }
- nready = WaitForSomething(clientReady);
- #ifdef SMART_SCHEDULE
- if (nready && !SmartScheduleDisable) {
- clientReady[0] = SmartScheduleClient(clientReady, nready);
- nready = 1;
- }
- #endif
- /*****************
- * Handle events in round robin fashion, doing input between
- * each round
- *****************/
- while (!dispatchException && (--nready >= 0)) {
- client = clients[clientReady[nready]];
- if (!client) {
- /* KillClient can cause this to happen */
- continue;
- }
- /* GrabServer activation can cause this to be true */
- if (grabState == GrabKickout) {
- grabState = GrabActive;
- break;
- }
- isItTimeToYield = FALSE;
- requestingClient = client;
- #ifdef SMART_SCHEDULE
- start_tick = SmartScheduleTime;
- #endif
- while (!isItTimeToYield) {
- if (*icheck[0] != *icheck[1]) {
- ProcessInputEvents();
- FlushIfCriticalOutputPending();
- }
- #ifdef SMART_SCHEDULE
- if (!SmartScheduleDisable &&
- (SmartScheduleTime - start_tick) >= SmartScheduleSlice) {
- /* Penalize clients which consume ticks */
- if (client->smart_priority > SMART_MIN_PRIORITY)
- client->smart_priority--;
- break;
- }
- #endif
- /* now, finally, deal with client requests */
- result = ReadRequestFromClient(client);
- if (result <= 0) {
- if (result < 0)
- CloseDownClient(client);
- break;
- }
- client->sequence++;
- #ifdef DEBUG
- if (client->requestLogIndex == MAX_REQUEST_LOG)
- client->requestLogIndex = 0;
- client->requestLog[client->requestLogIndex] = MAJOROP;
- client->requestLogIndex++;
- #endif
- if (result > (maxBigRequestSize << 2))
- result = BadLength;
- else
- result = (*client->requestVector[MAJOROP]) (client);
- if (result != Success) {
- if (client->noClientException != Success)
- CloseDownClient(client);
- else
- SendErrorToClient(client, MAJOROP,
- MinorOpcodeOfRequest(client),
- client->errorValue, result);
- break;
- }
- }
- FlushAllOutput();
- #ifdef SMART_SCHEDULE
- client = clients[clientReady[nready]];
- if (client)
- client->smart_stop_tick = SmartScheduleTime;
- #endif
- requestingClient = NULL;
- }
- dispatchException &= ~DE_PRIORITYCHANGE;
- }
- KillAllClients();
- DEALLOCATE_LOCAL(clientReady);
- dispatchException &= ~DE_RESET;
- ResetOsBuffers();
- }
- #undef MAJOROP
- _X_EXPORT int
- ProcBadRequest(ClientPtr client)
- {
- return (BadRequest);
- }
- int
- ProcCreateWindow(ClientPtr client)
- {
- WindowPtr pParent, pWin;
- REQUEST(xCreateWindowReq);
- int result;
- int len;
- REQUEST_AT_LEAST_SIZE(xCreateWindowReq);
- LEGAL_NEW_RESOURCE(stuff->wid, client);
- if (!(pParent = (WindowPtr) SecurityLookupWindow(stuff->parent, client,
- SecurityWriteAccess)))
- return BadWindow;
- len = client->req_len - (sizeof(xCreateWindowReq) >> 2);
- if (Ones(stuff->mask) != len)
- return BadLength;
- if (!stuff->width || !stuff->height) {
- client->errorValue = 0;
- return BadValue;
- }
- pWin = CreateWindow(stuff->wid, pParent, stuff->x,
- stuff->y, stuff->width, stuff->height,
- stuff->borderWidth, stuff->class,
- stuff->mask, (XID *) &stuff[1],
- (int) stuff->depth, client, stuff->visual, &result);
- if (pWin) {
- Mask mask = pWin->eventMask;
- pWin->eventMask = 0; /* subterfuge in case AddResource fails */
- if (!AddResource(stuff->wid, RT_WINDOW, (pointer) pWin))
- return BadAlloc;
- pWin->eventMask = mask;
- }
- if (client->noClientException != Success)
- return (client->noClientException);
- else
- return (result);
- }
- int
- ProcChangeWindowAttributes(register ClientPtr client)
- {
- WindowPtr pWin;
- REQUEST(xChangeWindowAttributesReq);
- int result;
- int len;
- REQUEST_AT_LEAST_SIZE(xChangeWindowAttributesReq);
- pWin = (WindowPtr) SecurityLookupWindow(stuff->window, client,
- SecurityWriteAccess);
- if (!pWin)
- return (BadWindow);
- len = client->req_len - (sizeof(xChangeWindowAttributesReq) >> 2);
- if (len != Ones(stuff->valueMask))
- return BadLength;
- result = ChangeWindowAttributes(pWin,
- stuff->valueMask,
- (XID *) &stuff[1], client);
- if (client->noClientException != Success)
- return (client->noClientException);
- else
- return (result);
- }
- int
- ProcGetWindowAttributes(register ClientPtr client)
- {
- WindowPtr pWin;
- REQUEST(xResourceReq);
- xGetWindowAttributesReply wa = {0};
- REQUEST_SIZE_MATCH(xResourceReq);
- pWin = (WindowPtr) SecurityLookupWindow(stuff->id, client,
- SecurityReadAccess);
- if (!pWin)
- return (BadWindow);
- memset(&wa, 0, sizeof(xGetWindowAttributesReply));
- GetWindowAttributes(pWin, client, &wa);
- WriteReplyToClient(client, sizeof(xGetWindowAttributesReply), &wa);
- return (client->noClientException);
- }
- int
- ProcDestroyWindow(register ClientPtr client)
- {
- WindowPtr pWin;
- REQUEST(xResourceReq);
- REQUEST_SIZE_MATCH(xResourceReq);
- pWin = (WindowPtr) SecurityLookupWindow(stuff->id, client,
- SecurityDestroyAccess);
- if (!pWin)
- return (BadWindow);
- if (pWin->parent)
- FreeResource(stuff->id, RT_NONE);
- return (client->noClientException);
- }
- int
- ProcDestroySubwindows(register ClientPtr client)
- {
- WindowPtr pWin;
- REQUEST(xResourceReq);
- REQUEST_SIZE_MATCH(xResourceReq);
- pWin = (WindowPtr) SecurityLookupWindow(stuff->id, client,
- SecurityDestroyAccess);
- if (!pWin)
- return (BadWindow);
- DestroySubwindows(pWin, client);
- return (client->noClientException);
- }
- int
- ProcChangeSaveSet(register ClientPtr client)
- {
- WindowPtr pWin;
- REQUEST(xChangeSaveSetReq);
- int result;
- REQUEST_SIZE_MATCH(xChangeSaveSetReq);
- pWin = (WindowPtr) SecurityLookupWindow(stuff->window, client,
- SecurityReadAccess);
- if (!pWin)
- return (BadWindow);
- if (client->clientAsMask == (CLIENT_BITS(pWin->drawable.id)))
- return BadMatch;
- if ((stuff->mode == SetModeInsert) || (stuff->mode == SetModeDelete)) {
- result = AlterSaveSetForClient(client, pWin, stuff->mode, FALSE, TRUE);
- if (client->noClientException != Success)
- return (client->noClientException);
- else
- return (result);
- }
- else {
- client->errorValue = stuff->mode;
- return (BadValue);
- }
- }
- int
- ProcReparentWindow(register ClientPtr client)
- {
- WindowPtr pWin, pParent;
- REQUEST(xReparentWindowReq);
- int result;
- REQUEST_SIZE_MATCH(xReparentWindowReq);
- pWin = (WindowPtr) SecurityLookupWindow(stuff->window, client,
- SecurityWriteAccess);
- if (!pWin)
- return (BadWindow);
- pParent = (WindowPtr) SecurityLookupWindow(stuff->parent, client,
- SecurityWriteAccess);
- if (!pParent)
- return (BadWindow);
- if (SAME_SCREENS(pWin->drawable, pParent->drawable)) {
- if ((pWin->backgroundState == ParentRelative) &&
- (pParent->drawable.depth != pWin->drawable.depth))
- return BadMatch;
- if ((pWin->drawable.class != InputOnly) &&
- (pParent->drawable.class == InputOnly))
- return BadMatch;
- result = ReparentWindow(pWin, pParent,
- (short) stuff->x, (short) stuff->y, client);
- if (client->noClientException != Success)
- return (client->noClientException);
- else
- return (result);
- }
- else
- return (BadMatch);
- }
- int
- ProcMapWindow(register ClientPtr client)
- {
- WindowPtr pWin;
- REQUEST(xResourceReq);
- REQUEST_SIZE_MATCH(xResourceReq);
- pWin = (WindowPtr) SecurityLookupWindow(stuff->id, client,
- SecurityReadAccess);
- if (!pWin)
- return (BadWindow);
- MapWindow(pWin, client);
- /* update cache to say it is mapped */
- return (client->noClientException);
- }
- int
- ProcMapSubwindows(register ClientPtr client)
- {
- WindowPtr pWin;
- REQUEST(xResourceReq);
- REQUEST_SIZE_MATCH(xResourceReq);
- pWin = (WindowPtr) SecurityLookupWindow(stuff->id, client,
- SecurityReadAccess);
- if (!pWin)
- return (BadWindow);
- MapSubwindows(pWin, client);
- /* update cache to say it is mapped */
- return (client->noClientException);
- }
- int
- ProcUnmapWindow(register ClientPtr client)
- {
- WindowPtr pWin;
- REQUEST(xResourceReq);
- REQUEST_SIZE_MATCH(xResourceReq);
- pWin = (WindowPtr) SecurityLookupWindow(stuff->id, client,
- SecurityReadAccess);
- if (!pWin)
- return (BadWindow);
- UnmapWindow(pWin, FALSE);
- /* update cache to say it is mapped */
- return (client->noClientException);
- }
- int
- ProcUnmapSubwindows(register ClientPtr client)
- {
- WindowPtr pWin;
- REQUEST(xResourceReq);
- REQUEST_SIZE_MATCH(xResourceReq);
- pWin = (WindowPtr) SecurityLookupWindow(stuff->id, client,
- SecurityReadAccess);
- if (!pWin)
- return (BadWindow);
- UnmapSubwindows(pWin);
- return (client->noClientException);
- }
- int
- ProcConfigureWindow(register ClientPtr client)
- {
- WindowPtr pWin;
- REQUEST(xConfigureWindowReq);
- int result;
- int len;
- REQUEST_AT_LEAST_SIZE(xConfigureWindowReq);
- pWin = (WindowPtr) SecurityLookupWindow(stuff->window, client,
- SecurityWriteAccess);
- if (!pWin)
- return (BadWindow);
- len = client->req_len - (sizeof(xConfigureWindowReq) >> 2);
- if (Ones((Mask) stuff->mask) != len)
- return BadLength;
- result = ConfigureWindow(pWin, (Mask) stuff->mask, (XID *) &stuff[1],
- client);
- if (client->noClientException != Success)
- return (client->noClientException);
- else
- return (result);
- }
- int
- ProcCirculateWindow(register ClientPtr client)
- {
- WindowPtr pWin;
- REQUEST(xCirculateWindowReq);
- REQUEST_SIZE_MATCH(xCirculateWindowReq);
- if ((stuff->direction != RaiseLowest) && (stuff->direction != LowerHighest)) {
- client->errorValue = stuff->direction;
- return BadValue;
- }
- pWin = (WindowPtr) SecurityLookupWindow(stuff->window, client,
- SecurityWriteAccess);
- if (!pWin)
- return (BadWindow);
- CirculateWindow(pWin, (int) stuff->direction, client);
- return (client->noClientException);
- }
- int
- GetGeometry(register ClientPtr client, xGetGeometryReply * rep)
- {
- DrawablePtr pDraw;
- REQUEST(xResourceReq);
- REQUEST_SIZE_MATCH(xResourceReq);
- SECURITY_VERIFY_GEOMETRABLE(pDraw, stuff->id, client, SecurityReadAccess);
- rep->type = X_Reply;
- rep->length = 0;
- rep->sequenceNumber = client->sequence;
- rep->root = WindowTable[pDraw->pScreen->myNum]->drawable.id;
- rep->depth = pDraw->depth;
- rep->width = pDraw->width;
- rep->height = pDraw->height;
- /* XXX - Because the pixmap-implementation of the multibuffer extension
- * may have the buffer-id's drawable resource value be a pointer
- * to the buffer's window instead of the buffer itself
- * (this happens if the buffer is the displayed buffer),
- * we also have to check that the id matches before we can
- * truly say that it is a DRAWABLE_WINDOW.
- */
- if ((pDraw->type == UNDRAWABLE_WINDOW) ||
- ((pDraw->type == DRAWABLE_WINDOW) && (stuff->id == pDraw->id))) {
- WindowPtr pWin = (WindowPtr) pDraw;
- rep->x = pWin->origin.x - wBorderWidth(pWin);
- rep->y = pWin->origin.y - wBorderWidth(pWin);
- rep->borderWidth = pWin->borderWidth;
- }
- else { /* DRAWABLE_PIXMAP or DRAWABLE_BUFFER */
- rep->x = rep->y = rep->borderWidth = 0;
- }
- return Success;
- }
- int
- ProcGetGeometry(register ClientPtr client)
- {
- xGetGeometryReply rep = {0};
- int status;
- memset(&rep, 0, sizeof(xGetGeometryReply));
- if ((status = GetGeometry(client, &rep)) != Success)
- return status;
- WriteReplyToClient(client, sizeof(xGetGeometryReply), &rep);
- return (client->noClientException);
- }
- int
- ProcQueryTree(register ClientPtr client)
- {
- xQueryTreeReply reply;
- int numChildren = 0;
- WindowPtr pChild, pWin, pHead;
- Window *childIDs = (Window *) NULL;
- REQUEST(xResourceReq);
- REQUEST_SIZE_MATCH(xResourceReq);
- pWin = (WindowPtr) SecurityLookupWindow(stuff->id, client,
- SecurityReadAccess);
- if (!pWin)
- return (BadWindow);
- memset(&reply, 0, sizeof(xQueryTreeReply));
- reply.type = X_Reply;
- reply.root = WindowTable[pWin->drawable.pScreen->myNum]->drawable.id;
- reply.sequenceNumber = client->sequence;
- if (pWin->parent)
- reply.parent = pWin->parent->drawable.id;
- else
- reply.parent = (Window) None;
- pHead = RealChildHead(pWin);
- for (pChild = pWin->lastChild; pChild != pHead; pChild = pChild->prevSib)
- numChildren++;
- if (numChildren) {
- int curChild = 0;
- childIDs = (Window *) ALLOCATE_LOCAL(numChildren * sizeof(Window));
- if (!childIDs)
- return BadAlloc;
- for (pChild = pWin->lastChild; pChild != pHead;
- pChild = pChild->prevSib)
- childIDs[curChild++] = pChild->drawable.id;
- }
- reply.nChildren = numChildren;
- reply.length = (numChildren * sizeof(Window)) >> 2;
- WriteReplyToClient(client, sizeof(xQueryTreeReply), &reply);
- if (numChildren) {
- client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write;
- WriteSwappedDataToClient(client, numChildren * sizeof(Window),
- childIDs);
- DEALLOCATE_LOCAL(childIDs);
- }
- return (client->noClientException);
- }
- int
- ProcInternAtom(register ClientPtr client)
- {
- Atom atom;
- char *tchar;
- REQUEST(xInternAtomReq);
- REQUEST_FIXED_SIZE(xInternAtomReq, stuff->nbytes);
- if ((stuff->onlyIfExists != xTrue) && (stuff->onlyIfExists != xFalse)) {
- client->errorValue = stuff->onlyIfExists;
- return (BadValue);
- }
- tchar = (char *) &stuff[1];
- atom = MakeAtom(tchar, stuff->nbytes, !stuff->onlyIfExists);
- if (atom != BAD_RESOURCE) {
- xInternAtomReply reply = {0};
- memset(&reply, 0, sizeof(xInternAtomReply));
- reply.type = X_Reply;
- reply.length = 0;
- reply.sequenceNumber = client->sequence;
- reply.atom = atom;
- WriteReplyToClient(client, sizeof(xInternAtomReply), &reply);
- return (client->noClientException);
- }
- else
- return (BadAlloc);
- }
- int
- ProcGetAtomName(register ClientPtr client)
- {
- char *str;
- xGetAtomNameReply reply;
- int len;
- REQUEST(xResourceReq);
- REQUEST_SIZE_MATCH(xResourceReq);
- if ((str = NameForAtom(stuff->id))) {
- len = strlen(str);
- memset(&reply, 0, sizeof(xGetAtomNameReply));
- reply.type = X_Reply;
- reply.length = (len + 3) >> 2;
- reply.sequenceNumber = client->sequence;
- reply.nameLength = len;
- WriteReplyToClient(client, sizeof(xGetAtomNameReply), &reply);
- (void) WriteToClient(client, len, str);
- return (client->noClientException);
- }
- else {
- client->errorValue = stuff->id;
- return (BadAtom);
- }
- }
- int
- ProcSetSelectionOwner(register ClientPtr client)
- {
- WindowPtr pWin;
- TimeStamp time;
- REQUEST(xSetSelectionOwnerReq);
- REQUEST_SIZE_MATCH(xSetSelectionOwnerReq);
- UpdateCurrentTime();
- time = ClientTimeToServerTime(stuff->time);
- /* If the client's time stamp is in the future relative to the server's
- time stamp, do not set the selection, just return success. */
- if (CompareTimeStamps(time, currentTime) == LATER)
- return Success;
- if (stuff->window != None) {
- pWin = (WindowPtr) SecurityLookupWindow(stuff->window, client,
- SecurityReadAccess);
- if (!pWin)
- return (BadWindow);
- }
- else
- pWin = (WindowPtr) None;
- if (ValidAtom(stuff->selection)) {
- int i = 0;
- /*
- * First, see if the selection is already set...
- */
- while ((i < NumCurrentSelections) &&
- CurrentSelections[i].selection != stuff->selection)
- i++;
- if (i < NumCurrentSelections) {
- xEvent event;
- /* If the timestamp in client's request is in the past relative
- to the time stamp indicating the last time the owner of the
- selection was set, do not set the selection, just return
- success. */
- if (CompareTimeStamps(time, CurrentSelections[i].lastTimeChanged)
- == EARLIER)
- return Success;
- if (CurrentSelections[i].client &&
- (!pWin || (CurrentSelections[i].client != client))) {
- event.u.u.type = SelectionClear;
- event.u.selectionClear.time = time.milliseconds;
- event.u.selectionClear.window = CurrentSelections[i].window;
- event.u.selectionClear.atom = CurrentSelections[i].selection;
- (void) TryClientEvents(CurrentSelections[i].client, &event, 1,
- NoEventMask,
- NoEventMask /* CantBeFiltered */ ,
- NullGrab);
- }
- }
- else {
- /*
- * It doesn't exist, so add it...
- */
- Selection *newsels;
- if (i == 0)
- newsels = malloc(sizeof(Selection));
- else
- newsels = (Selection *) realloc(CurrentSelections,
- (NumCurrentSelections +
- 1) * sizeof(Selection));
- if (!newsels)
- return BadAlloc;
- NumCurrentSelections++;
- CurrentSelections = newsels;
- CurrentSelections[i].selection = stuff->selection;
- }
- CurrentSelections[i].lastTimeChanged = time;
- CurrentSelections[i].window = stuff->window;
- CurrentSelections[i].pWin = pWin;
- CurrentSelections[i].client = (pWin ? client : NullClient);
- if (SelectionCallback) {
- SelectionInfoRec info;
- info.selection = &CurrentSelections[i];
- info.kind = SelectionSetOwner;
- CallCallbacks(&SelectionCallback, &info);
- }
- return (client->noClientException);
- }
- else {
- client->errorValue = stuff->selection;
- return (BadAtom);
- }
- }
- int
- ProcGetSelectionOwner(register ClientPtr client)
- {
- REQUEST(xResourceReq);
- REQUEST_SIZE_MATCH(xResourceReq);
- if (ValidAtom(stuff->id)) {
- int i;
- xGetSelectionOwnerReply reply;
- i = 0;
- while ((i < NumCurrentSelections) &&
- CurrentSelections[i].selection != stuff->id)
- i++;
- reply.type = X_Reply;
- reply.length = 0;
- reply.sequenceNumber = client->sequence;
- if (i < NumCurrentSelections)
- reply.owner = CurrentSelections[i].window;
- else
- reply.owner = None;
- WriteReplyToClient(client, sizeof(xGetSelectionOwnerReply), &reply);
- return (client->noClientException);
- }
- else {
- client->errorValue = stuff->id;
- return (BadAtom);
- }
- }
- int
- ProcConvertSelection(register ClientPtr client)
- {
- Bool paramsOkay;
- xEvent event;
- WindowPtr pWin;
- REQUEST(xConvertSelectionReq);
- REQUEST_SIZE_MATCH(xConvertSelectionReq);
- pWin = (WindowPtr) SecurityLookupWindow(stuff->requestor, client,
- SecurityReadAccess);
- if (!pWin)
- return (BadWindow);
- paramsOkay = (ValidAtom(stuff->selection) && ValidAtom(stuff->target));
- if (stuff->property != None)
- paramsOkay &= ValidAtom(stuff->property);
- if (paramsOkay) {
- int i;
- i = 0;
- while ((i < NumCurrentSelections) &&
- CurrentSelections[i].selection != stuff->selection)
- i++;
- if ((i < NumCurrentSelections) && (CurrentSelections[i].window != None)
- ) {
- event.u.u.type = SelectionRequest;
- event.u.selectionRequest.time = stuff->time;
- event.u.selectionRequest.owner = CurrentSelections[i].window;
- event.u.selectionRequest.requestor = stuff->requestor;
- event.u.selectionRequest.selection = stuff->selection;
- event.u.selectionRequest.target = stuff->target;
- event.u.selectionRequest.property = stuff->property;
- if (TryClientEvents
- (CurrentSelections[i].client, &event, 1, NoEventMask,
- NoEventMask /* CantBeFiltered */ , NullGrab))
- return (client->noClientException);
- }
- event.u.u.type = SelectionNotify;
- event.u.selectionNotify.time = stuff->time;
- event.u.selectionNotify.requestor = stuff->requestor;
- event.u.selectionNotify.selection = stuff->selection;
- event.u.selectionNotify.target = stuff->target;
- event.u.selectionNotify.property = None;
- (void) TryClientEvents(client, &event, 1, NoEventMask,
- NoEventMask /* CantBeFiltered */ , NullGrab);
- return (client->noClientException);
- }
- else {
- client->errorValue = stuff->property;
- return (BadAtom);
- }
- }
- int
- ProcGrabServer(register ClientPtr client)
- {
- REQUEST_SIZE_MATCH(xReq);
- if (grabState != GrabNone && client != grabClient) {
- ResetCurrentRequest(client);
- client->sequence--;
- BITSET(grabWaiters, client->index);
- IgnoreClient(client);
- return (client->noClientException);
- }
- OnlyListenToOneClient(client);
- grabState = GrabKickout;
- grabClient = client;
- if (ServerGrabCallback) {
- ServerGrabInfoRec grabinfo;
- grabinfo.client = client;
- grabinfo.grabstate = SERVER_GRABBED;
- CallCallbacks(&ServerGrabCallback, (pointer) &grabinfo);
- }
- return (client->noClientException);
- }
- static void
- UngrabServer(ClientPtr client)
- {
- int i;
- grabState = GrabNone;
- ListenToAllClients();
- for (i = mskcnt; --i >= 0 && !grabWaiters[i];);
- if (i >= 0) {
- i <<= 5;
- while (!GETBIT(grabWaiters, i))
- i++;
- BITCLEAR(grabWaiters, i);
- AttendClient(clients[i]);
- }
- if (ServerGrabCallback) {
- ServerGrabInfoRec grabinfo;
- grabinfo.client = client;
- grabinfo.grabstate = SERVER_UNGRABBED;
- CallCallbacks(&ServerGrabCallback, (pointer) &grabinfo);
- }
- }
- int
- ProcUngrabServer(register ClientPtr client)
- {
- REQUEST_SIZE_MATCH(xReq);
- UngrabServer(client);
- return (client->noClientException);
- }
- int
- ProcTranslateCoords(register ClientPtr client)
- {
- REQUEST(xTranslateCoordsReq);
- WindowPtr pWin, pDst;
- xTranslateCoordsReply rep;
- REQUEST_SIZE_MATCH(xTranslateCoordsReq);
- pWin = (WindowPtr) SecurityLookupWindow(stuff->srcWid, client,
- SecurityReadAccess);
- if (!pWin)
- return (BadWindow);
- pDst = (WindowPtr) SecurityLookupWindow(stuff->dstWid, client,
- SecurityReadAccess);
- if (!pDst)
- return (BadWindow);
- memset(&rep, 0, sizeof(xTranslateCoordsReply));
- rep.type = X_Reply;
- rep.length = 0;
- rep.sequenceNumber = client->sequence;
- if (!SAME_SCREENS(pWin->drawable, pDst->drawable)) {
- rep.sameScreen = xFalse;
- rep.child = None;
- rep.dstX = rep.dstY = 0;
- }
- else {
- INT16 x, y;
- rep.sameScreen = xTrue;
- rep.child = None;
- /* computing absolute coordinates -- adjust to destination later */
- x = pWin->drawable.x + stuff->srcX;
- y = pWin->drawable.y + stuff->srcY;
- pWin = pDst->firstChild;
- while (pWin) {
- BoxRec box;
- if ((pWin->mapped) &&
- (x >= pWin->drawable.x - wBorderWidth(pWin)) &&
- (x < pWin->drawable.x + (int) pWin->drawable.width +
- wBorderWidth(pWin)) &&
- (y >= pWin->drawable.y - wBorderWidth(pWin)) &&
- (y < pWin->drawable.y + (int) pWin->drawable.height +
- wBorderWidth(pWin))
- /* When a window is shaped, a further check
- * is made to see if the point is inside
- * borderSize
- */
- && (!wBoundingShape(pWin) ||
- POINT_IN_REGION(
- &pWin->borderSize, x, y, &box))
- && (!wInputShape(pWin) ||
- POINT_IN_REGION(
- wInputShape(pWin),
- x - pWin->drawable.x,
- y - pWin->drawable.y, &box))
- ) {
- rep.child = pWin->drawable.id;
- pWin = (WindowPtr) NULL;
- }
- else
- pWin = pWin->nextSib;
- }
- /* adjust to destination coordinates */
- rep.dstX = x - pDst->drawable.x;
- rep.dstY = y - pDst->drawable.y;
- }
- WriteReplyToClient(client, sizeof(xTranslateCoordsReply), &rep);
- return (client->noClientException);
- }
- int
- ProcOpenFont(register ClientPtr client)
- {
- int err;
- REQUEST(xOpenFontReq);
- REQUEST_FIXED_SIZE(xOpenFontReq, stuff->nbytes);
- client->errorValue = stuff->fid;
- LEGAL_NEW_RESOURCE(stuff->fid, client);
- err = OpenFont(client, stuff->fid, (Mask) 0,
- stuff->nbytes, (char *) &stuff[1]);
- if (err == Success) {
- return (client->noClientException);
- }
- else
- return err;
- }
- int
- ProcCloseFont(register ClientPtr client)
- {
- FontPtr pFont;
- REQUEST(xResourceReq);
- REQUEST_SIZE_MATCH(xResourceReq);
- pFont = (FontPtr) SecurityLookupIDByType(client, stuff->id, RT_FONT,
- SecurityDestroyAccess);
- if (pFont != (FontPtr) NULL) { /* id was valid */
- FreeResource(stuff->id, RT_NONE);
- return (client->noClientException);
- }
- else {
- client->errorValue = stuff->id;
- return (BadFont);
- }
- }
- int
- ProcQueryFont(register ClientPtr client)
- {
- xQueryFontReply *reply;
- FontPtr pFont;
- GC *pGC;
- REQUEST(xResourceReq);
- REQUEST_SIZE_MATCH(xResourceReq);
- client->errorValue = stuff->id; /* EITHER font or gc */
- pFont = (FontPtr) SecurityLookupIDByType(client, stuff->id, RT_FONT,
- SecurityReadAccess);
- if (!pFont) {
- /* can't use VERIFY_GC because it might return BadGC */
- pGC = (GC *) SecurityLookupIDByType(client, stuff->id, RT_GC,
- SecurityReadAccess);
- if (!pGC) {
- client->errorValue = stuff->id;
- return (BadFont); /* procotol spec says only error is BadFont */
- }
- pFont = pGC->font;
- }
- {
- xCharInfo *pmax = FONTINKMAX(pFont);
- xCharInfo *pmin = FONTINKMIN(pFont);
- int nprotoxcistructs;
- int rlength;
- nprotoxcistructs = (pmax->rightSideBearing == pmin->rightSideBearing &&
- pmax->leftSideBearing == pmin->leftSideBearing &&
- pmax->descent == pmin->descent &&
- pmax->ascent == pmin->ascent &&
- pmax->characterWidth == pmin->characterWidth) ?
- 0 : N2dChars(pFont);
- rlength = sizeof(xQueryFontReply) +
- FONTINFONPROPS(FONTCHARSET(pFont)) * sizeof(xFontProp) +
- nprotoxcistructs * sizeof(xCharInfo);
- reply = (xQueryFontReply *) calloc(1, rlength);
- if (!reply) {
- return (BadAlloc);
- }
- reply->type = X_Reply;
- reply->length = (rlength - sizeof(xGenericReply)) >> 2;
- reply->sequenceNumber = client->sequence;
- QueryFont(pFont, reply, nprotoxcistructs);
- WriteReplyToClient(client, rlength, reply);
- free(reply);
- return (client->noClientException);
- }
- }
- int
- ProcQueryTextExtents(register ClientPtr client)
- {
- REQUEST(xQueryTextExtentsReq);
- xQueryTextExtentsReply reply;
- FontPtr pFont;
- GC *pGC;
- ExtentInfoRec info;
- unsigned long length;
- REQUEST_AT_LEAST_SIZE(xQueryTextExtentsReq);
- pFont = (FontPtr) SecurityLookupIDByType(client, stuff->fid, RT_FONT,
- SecurityReadAccess);
- if (!pFont) {
- pGC = (GC *) SecurityLookupIDByType(client, stuff->fid, RT_GC,
- SecurityReadAccess);
- if (!pGC) {
- client->errorValue = stuff->fid;
- return (BadFont);
- }
- pFont = pGC->font;
- }
- length = client->req_len - (sizeof(xQueryTextExtentsReq) >> 2);
- length = length << 1;
- if (stuff->oddLength) {
- if (length == 0)
- return (BadLength);
- length--;
- }
- if (!QueryTextExtents(pFont, length, (unsigned char *) &stuff[1], &info))
- return (BadAlloc);
- reply.type = X_Reply;
- reply.length = 0;
- reply.sequenceNumber = client->sequence;
- reply.drawDirection = info.drawDirection;
- reply.fontAscent = info.fontAscent;
- reply.fontDescent = info.fontDescent;
- reply.overallAscent = info.overallAscent;
- reply.overallDescent = info.overallDescent;
- reply.overallWidth = info.overallWidth;
- reply.overallLeft = info.overallLeft;
- reply.overallRight = info.overallRight;
- WriteReplyToClient(client, sizeof(xQueryTextExtentsReply), &reply);
- return (client->noClientException);
- }
- int
- ProcListFonts(register ClientPtr client)
- {
- REQUEST(xListFontsReq);
- REQUEST_FIXED_SIZE(xListFontsReq, stuff->nbytes);
- return ListFonts(client, (unsigned char *) &stuff[1], stuff->nbytes,
- stuff->maxNames);
- }
- int
- ProcListFontsWithInfo(register ClientPtr client)
- {
- REQUEST(xListFontsWithInfoReq);
- REQUEST_FIXED_SIZE(xListFontsWithInfoReq, stuff->nbytes);
- return StartListFontsWithInfo(client, stuff->nbytes,
- (unsigned char *) &stuff[1], stuff->maxNames);
- }
- /**
- *
- * \param value must conform to DeleteType
- */
- int
- dixDestroyPixmap(pointer value, XID pid)
- {
- PixmapPtr pPixmap = (PixmapPtr) value;
- return (*pPixmap->drawable.pScreen->DestroyPixmap) (pPixmap);
- }
- int
- ProcCreatePixmap(register ClientPtr client)
- {
- PixmapPtr pMap;
- DrawablePtr pDraw;
- REQUEST(xCreatePixmapReq);
- DepthPtr pDepth;
- int i;
- REQUEST_SIZE_MATCH(xCreatePixmapReq);
- client->errorValue = stuff->pid;
- LEGAL_NEW_RESOURCE(stuff->pid, client);
- SECURITY_VERIFY_GEOMETRABLE(pDraw, stuff->drawable, client,
- SecurityReadAccess);
- if (!stuff->width || !stuff->height) {
- client->errorValue = 0;
- return BadValue;
- }
- if (stuff->width > 32767 || stuff->height > 32767) {
- /* It is allowed to try and allocate a pixmap which is larger than
- * 32767 in either dimension. However, all of the framebuffer code
- * is buggy and does not reliably draw to such big pixmaps, basically
- * because the Region data structure operates with signed shorts
- * for the rectangles in it.
- *
- * Furthermore, several places in the X server computes the
- * size in bytes of the pixmap and tries to store it in an
- * integer. This integer can overflow and cause the allocated size
- * to be much smaller.
- *
- * So, such big pixmaps are rejected here with a BadAlloc
- */
- return BadAlloc;
- }
- if (stuff->depth != 1) {
- pDepth = pDraw->pScreen->allowedDepths;
- for (i = 0; i < pDraw->pScreen->numDepths; i++, pDepth++)
- if (pDepth->depth == stuff->depth)
- goto CreatePmap;
- client->errorValue = stuff->depth;
- return BadValue;
- }
- CreatePmap:
- pMap = (PixmapPtr) (*pDraw->pScreen->CreatePixmap)
- (pDraw->pScreen, stuff->width, stuff->height, stuff->depth);
- if (pMap) {
- pMap->drawable.serialNumber = NEXT_SERIAL_NUMBER;
- pMap->drawable.id = stuff->pid;
- if (AddResource(stuff->pid, RT_PIXMAP, (pointer) pMap))
- return (client->noClientException);
- }
- return (BadAlloc);
- }
- int
- ProcFreePixmap(register ClientPtr client)
- {
- PixmapPtr pMap;
- REQUEST(xResourceReq);
- REQUEST_SIZE_MATCH(xResourceReq);
- pMap = (PixmapPtr) SecurityLookupIDByType(client, stuff->id, RT_PIXMAP,
- SecurityDestroyAccess);
- if (pMap) {
- FreeResource(stuff->id, RT_NONE);
- return (client->noClientException);
- }
- else {
- client->errorValue = stuff->id;
- return (BadPixmap);
- }
- }
- int
- ProcCreateGC(register ClientPtr client)
- {
- int error;
- GC *pGC;
- DrawablePtr pDraw;
- unsigned len;
- REQUEST(xCreateGCReq);
- REQUEST_AT_LEAST_SIZE(xCreateGCReq);
- client->errorValue = stuff->gc;
- LEGAL_NEW_RESOURCE(stuff->gc, client);
- SECURITY_VERIFY_DRAWABLE(pDraw, stuff->drawable, client,
- SecurityReadAccess);
- len = client->req_len - (sizeof(xCreateGCReq) >> 2);
- if (len != Ones(stuff->mask))
- return BadLength;
- pGC = (GC *) CreateGC(pDraw, stuff->mask, (XID *) &stuff[1], &error);
- if (error != Success)
- return error;
- if (!AddResource(stuff->gc, RT_GC, (pointer) pGC))
- return (BadAlloc);
- return (client->noClientException);
- }
- int
- ProcChangeGC(register ClientPtr client)
- {
- GC *pGC;
- REQUEST(xChangeGCReq);
- int result;
- unsigned len;
- REQUEST_AT_LEAST_SIZE(xChangeGCReq);
- SECURITY_VERIFY_GC(pGC, stuff->gc, client, SecurityWriteAccess);
- len = client->req_len - (sizeof(xChangeGCReq) >> 2);
- if (len != Ones(stuff->mask))
- return BadLength;
- result = dixChangeGC(client, pGC, stuff->mask, (CARD32 *) &stuff[1], 0);
- if (client->noClientException != Success)
- return (client->noClientException);
- else {
- client->errorValue = clientErrorValue;
- return (result);
- }
- }
- int
- ProcCopyGC(register ClientPtr client)
- {
- GC *dstGC;
- GC *pGC;
- int result;
- REQUEST(xCopyGCReq);
- REQUEST_SIZE_MATCH(xCopyGCReq);
- SECURITY_VERIFY_GC(pGC, stuff->srcGC, client, SecurityReadAccess);
- SECURITY_VERIFY_GC(dstGC, stuff->dstGC, client, SecurityWriteAccess);
- if ((dstGC->pScreen != pGC->pScreen) || (dstGC->depth != pGC->depth))
- return (BadMatch);
- result = CopyGC(pGC, dstGC, stuff->mask);
- if (client->noClientException != Success)
- return (client->noClientException);
- else {
- client->errorValue = clientErrorValue;
- return (result);
- }
- }
- int
- ProcSetDashes(register ClientPtr client)
- {
- GC *pGC;
- int result;
- REQUEST(xSetDashesReq);
- REQUEST_FIXED_SIZE(xSetDashesReq, stuff->nDashes);
- if (stuff->nDashes == 0) {
- client->errorValue = 0;
- return BadValue;
- }
- SECURITY_VERIFY_GC(pGC, stuff->gc, client, SecurityWriteAccess);
- result = SetDashes(pGC, stuff->dashOffset, stuff->nDashes,
- (unsigned char *) &stuff[1]);
- if (client->noClientException != Success)
- return (client->noClientException);
- else {
- client->errorValue = clientErrorValue;
- return (result);
- }
- }
- int
- ProcSetClipRectangles(register ClientPtr client)
- {
- int nr;
- int result;
- GC *pGC;
- REQUEST(xSetClipRectanglesReq);
- REQUEST_AT_LEAST_SIZE(xSetClipRectanglesReq);
- if ((stuff->ordering != Unsorted) && (stuff->ordering != YSorted) &&
- (stuff->ordering != YXSorted) && (stuff->ordering != YXBanded)) {
- client->errorValue = stuff->ordering;
- return BadValue;
- }
- SECURITY_VERIFY_GC(pGC, stuff->gc, client, SecurityWriteAccess);
- nr = (client->req_len << 2) - sizeof(xSetClipRectanglesReq);
- if (nr & 4)
- return (BadLength);
- nr >>= 3;
- result = SetClipRects(pGC, stuff->xOrigin, stuff->yOrigin,
- nr, (xRectangle *) &stuff[1], (int) stuff->ordering);
- if (client->noClientException != Success)
- return (client->noClientException);
- else
- return (result);
- }
- int
- ProcFreeGC(register ClientPtr client)
- {
- GC *pGC;
- REQUEST(xResourceReq);
- REQUEST_SIZE_MATCH(xResourceReq);
- SECURITY_VERIFY_GC(pGC, stuff->id, client, SecurityDestroyAccess);
- FreeResource(stuff->id, RT_NONE);
- return (client->noClientException);
- }
- int
- ProcClearToBackground(register ClientPtr client)
- {
- REQUEST(xClearAreaReq);
- WindowPtr pWin;
- REQUEST_SIZE_MATCH(xClearAreaReq);
- pWin = (WindowPtr) SecurityLookupWindow(stuff->window, client,
- SecurityWriteAccess);
- if (!pWin)
- return (BadWindow);
- if (pWin->drawable.class == InputOnly) {
- client->errorValue = stuff->window;
- return (BadMatch);
- }
- if ((stuff->exposures != xTrue) && (stuff->exposures != xFalse)) {
- client->errorValue = stuff->exposures;
- return (BadValue);
- }
- (*pWin->drawable.pScreen->ClearToBackground) (pWin, stuff->x, stuff->y,
- stuff->width, stuff->height,
- (Bool) stuff->exposures);
- return (client->noClientException);
- }
- int
- ProcCopyArea(register ClientPtr client)
- {
- DrawablePtr pDst;
- DrawablePtr pSrc;
- GC *pGC;
- REQUEST(xCopyAreaReq);
- RegionPtr pRgn;
- REQUEST_SIZE_MATCH(xCopyAreaReq);
- VALIDATE_DRAWABLE_AND_GC(stuff->dstDrawable, pDst, pGC, client);
- if (stuff->dstDrawable != stuff->srcDrawable) {
- SECURITY_VERIFY_DRAWABLE(pSrc, stuff->srcDrawable, client,
- SecurityReadAccess);
- if ((pDst->pScreen != pSrc->pScreen) || (pDst->depth != pSrc->depth)) {
- client->errorValue = stuff->dstDrawable;
- return (BadMatch);
- }
- }
- else
- pSrc = pDst;
- SET_DBE_SRCBUF(pSrc, stuff->srcDrawable);
- pRgn = (*pGC->ops->CopyArea) (pSrc, pDst, pGC, stuff->srcX, stuff->srcY,
- stuff->width, stuff->height,
- stuff->dstX, stuff->dstY);
- if (pGC->graphicsExposures) {
- (*pDst->pScreen->SendGraphicsExpose)
- (client, pRgn, stuff->dstDrawable, X_CopyArea, 0);
- if (pRgn)
- REGION_DESTROY(pRgn);
- }
- return (client->noClientException);
- }
- int
- ProcCopyPlane(register ClientPtr client)
- {
- DrawablePtr psrcDraw, pdstDraw;
- GC *pGC;
- REQUEST(xCopyPlaneReq);
- RegionPtr pRgn;
- REQUEST_SIZE_MATCH(xCopyPlaneReq);
- VALIDATE_DRAWABLE_AND_GC(stuff->dstDrawable, pdstDraw, pGC, client);
- if (stuff->dstDrawable != stuff->srcDrawable) {
- SECURITY_VERIFY_DRAWABLE(psrcDraw, stuff->srcDrawable, client,
- SecurityReadAccess);
- if (pdstDraw->pScreen != psrcDraw->pScreen) {
- client->errorValue = stuff->dstDrawable;
- return (BadMatch);
- }
- }
- else
- psrcDraw = pdstDraw;
- SET_DBE_SRCBUF(psrcDraw, stuff->srcDrawable);
- /* Check to see if stuff->bitPlane has exactly ONE good bit set */
- if (stuff->bitPlane == 0 || (stuff->bitPlane & (stuff->bitPlane - 1)) ||
- (stuff->bitPlane > (1L << (psrcDraw->depth - 1)))) {
- client->errorValue = stuff->bitPlane;
- return (BadValue);
- }
- pRgn =
- (*pGC->ops->CopyPlane) (psrcDraw, pdstDraw, pGC, stuff->srcX,
- stuff->srcY, stuff->width, stuff->height,
- stuff->dstX, stuff->dstY, stuff->bitPlane);
- if (pGC->graphicsExposures) {
- (*pdstDraw->pScreen->SendGraphicsExpose)
- (client, pRgn, stuff->dstDrawable, X_CopyPlane, 0);
- if (pRgn)
- REGION_DESTROY(pRgn);
- }
- return (client->noClientException);
- }
- int
- ProcPolyPoint(register ClientPtr client)
- {
- int npoint;
- GC *pGC;
- DrawablePtr pDraw;
- REQUEST(xPolyPointReq);
- REQUEST_AT_LEAST_SIZE(xPolyPointReq);
- if ((stuff->coordMode != CoordModeOrigin) &&
- (stuff->coordMode != CoordModePrevious)) {
- client->errorValue = stuff->coordMode;
- return BadValue;
- }
- VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
- npoint = ((client->req_len << 2) - sizeof(xPolyPointReq)) >> 2;
- if (npoint)
- (*pGC->ops->PolyPoint) (pDraw, pGC, stuff->coordMode, npoint,
- (xPoint *) & stuff[1]);
- return (client->noClientException);
- }
- int
- ProcPolyLine(register ClientPtr client)
- {
- int npoint;
- GC *pGC;
- DrawablePtr pDraw;
- REQUEST(xPolyLineReq);
- REQUEST_AT_LEAST_SIZE(xPolyLineReq);
- if ((stuff->coordMode != CoordModeOrigin) &&
- (stuff->coordMode != CoordModePrevious)) {
- client->errorValue = stuff->coordMode;
- return BadValue;
- }
- VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
- npoint = ((client->req_len << 2) - sizeof(xPolyLineReq)) >> 2;
- if (npoint > 1)
- (*pGC->ops->Polylines) (pDraw, pGC, stuff->coordMode, npoint,
- (DDXPointPtr) & stuff[1]);
- return (client->noClientException);
- }
- int
- ProcPolySegment(register ClientPtr client)
- {
- int nsegs;
- GC *pGC;
- DrawablePtr pDraw;
- REQUEST(xPolySegmentReq);
- REQUEST_AT_LEAST_SIZE(xPolySegmentReq);
- VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
- nsegs = (client->req_len << 2) - sizeof(xPolySegmentReq);
- if (nsegs & 4)
- return (BadLength);
- nsegs >>= 3;
- if (nsegs)
- (*pGC->ops->PolySegment) (pDraw, pGC, nsegs, (xSegment *) & stuff[1]);
- return (client->noClientException);
- }
- int
- ProcPolyRectangle(register ClientPtr client)
- {
- int nrects;
- GC *pGC;
- DrawablePtr pDraw;
- REQUEST(xPolyRectangleReq);
- REQUEST_AT_LEAST_SIZE(xPolyRectangleReq);
- VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
- nrects = (client->req_len << 2) - sizeof(xPolyRectangleReq);
- if (nrects & 4)
- return (BadLength);
- nrects >>= 3;
- if (nrects)
- (*pGC->ops->PolyRectangle) (pDraw, pGC,
- nrects, (xRectangle *) &stuff[1]);
- return (client->noClientException);
- }
- int
- ProcPolyArc(register ClientPtr client)
- {
- int narcs;
- GC *pGC;
- DrawablePtr pDraw;
- REQUEST(xPolyArcReq);
- REQUEST_AT_LEAST_SIZE(xPolyArcReq);
- VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
- narcs = (client->req_len << 2) - sizeof(xPolyArcReq);
- if (narcs % sizeof(xArc))
- return (BadLength);
- narcs /= sizeof(xArc);
- if (narcs)
- (*pGC->ops->PolyArc) (pDraw, pGC, narcs, (xArc *) & stuff[1]);
- return (client->noClientException);
- }
- int
- ProcFillPoly(register ClientPtr client)
- {
- int things;
- GC *pGC;
- DrawablePtr pDraw;
- REQUEST(xFillPolyReq);
- REQUEST_AT_LEAST_SIZE(xFillPolyReq);
- if ((stuff->shape != Complex) && (stuff->shape != Nonconvex) &&
- (stuff->shape != Convex)) {
- client->errorValue = stuff->shape;
- return BadValue;
- }
- if ((stuff->coordMode != CoordModeOrigin) &&
- (stuff->coordMode != CoordModePrevious)) {
- client->errorValue = stuff->coordMode;
- return BadValue;
- }
- VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
- things = ((client->req_len << 2) - sizeof(xFillPolyReq)) >> 2;
- if (things)
- (*pGC->ops->FillPolygon) (pDraw, pGC, stuff->shape,
- stuff->coordMode, things,
- (DDXPointPtr) & stuff[1]);
- return (client->noClientException);
- }
- int
- ProcPolyFillRectangle(register ClientPtr client)
- {
- int things;
- GC *pGC;
- DrawablePtr pDraw;
- REQUEST(xPolyFillRectangleReq);
- REQUEST_AT_LEAST_SIZE(xPolyFillRectangleReq);
- VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
- things = (client->req_len << 2) - sizeof(xPolyFillRectangleReq);
- if (things & 4)
- return (BadLength);
- things >>= 3;
- if (things)
- (*pGC->ops->PolyFillRect) (pDraw, pGC, things,
- (xRectangle *) &stuff[1]);
- return (client->noClientException);
- }
- int
- ProcPolyFillArc(register ClientPtr client)
- {
- int narcs;
- GC *pGC;
- DrawablePtr pDraw;
- REQUEST(xPolyFillArcReq);
- REQUEST_AT_LEAST_SIZE(xPolyFillArcReq);
- VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
- narcs = (client->req_len << 2) - sizeof(xPolyFillArcReq);
- if (narcs % sizeof(xArc))
- return (BadLength);
- narcs /= sizeof(xArc);
- if (narcs)
- (*pGC->ops->PolyFillArc) (pDraw, pGC, narcs, (xArc *) & stuff[1]);
- return (client->noClientException);
- }
- #ifdef MATCH_CLIENT_ENDIAN
- int
- ServerOrder(void)
- {
- int whichbyte = 1;
- if (*((char *) &whichbyte))
- return LSBFirst;
- return MSBFirst;
- }
- #define ClientOrder(client) ((client)->swapped ? !ServerOrder() : ServerOrder())
- void
- ReformatImage(char *base, int nbytes, int bpp, int order)
- {
- switch (bpp) {
- case 1: /* yuck */
- if (BITMAP_BIT_ORDER != order)
- BitOrderInvert((unsigned char *) base, nbytes);
- #if IMAGE_BYTE_ORDER != BITMAP_BIT_ORDER && BITMAP_SCANLINE_UNIT != 8
- ReformatImage(base, nbytes, BITMAP_SCANLINE_UNIT, order);
- #endif
- break;
- case 4:
- break; /* yuck */
- case 8:
- break;
- case 16:
- if (IMAGE_BYTE_ORDER != order)
- TwoByteSwap((unsigned char *) base, nbytes);
- break;
- case 32:
- if (IMAGE_BYTE_ORDER != order)
- FourByteSwap((unsigned char *) base, nbytes);
- break;
- }
- }
- #else
- #define ReformatImage(b,n,bpp,o)
- #endif
- /* 64-bit server notes: the protocol restricts padding of images to
- * 8-, 16-, or 32-bits. We would like to have 64-bits for the server
- * to use internally. Removes need for internal alignment checking.
- * All of the PutImage functions could be changed individually, but
- * as currently written, they call other routines which require things
- * to be 64-bit padded on scanlines, so we changed things here.
- * If an image would be padded differently for 64- versus 32-, then
- * copy each scanline to a 64-bit padded scanline.
- * Also, we need to make sure that the image is aligned on a 64-bit
- * boundary, even if the scanlines are padded to our satisfaction.
- */
- int
- ProcPutImage(register ClientPtr client)
- {
- GC *pGC;
- DrawablePtr pDraw;
- long length; /* length of scanline server padded */
- long lengthProto; /* length of scanline protocol padded */
- char *tmpImage;
- REQUEST(xPutImageReq);
- REQUEST_AT_LEAST_SIZE(xPutImageReq);
- VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
- if (stuff->format == XYBitmap) {
- if ((stuff->depth != 1) ||
- (stuff->leftPad >= (unsigned int) screenInfo.bitmapScanlinePad))
- return BadMatch;
- length = BitmapBytePad(stuff->width + stuff->leftPad);
- }
- else if (stuff->format == XYPixmap) {
- if ((pDraw->depth != stuff->depth) ||
- (stuff->leftPad >= (unsigned int) screenInfo.bitmapScanlinePad))
- return BadMatch;
- length = BitmapBytePad(stuff->width + stuff->leftPad);
- length *= stuff->depth;
- }
- else if (stuff->format == ZPixmap) {
- if ((pDraw->depth != stuff->depth) || (stuff->leftPad != 0))
- return BadMatch;
- length = PixmapBytePad(stuff->width, stuff->depth);
- }
- else {
- client->errorValue = stuff->format;
- return BadValue;
- }
- tmpImage = (char *) &stuff[1];
- lengthProto = length;
- if (((((lengthProto * stuff->height) + (unsigned) 3) >> 2) +
- (sizeof(xPutImageReq) >> 2)) != client->req_len)
- return BadLength;
- ReformatImage(tmpImage, lengthProto * stuff->height,
- stuff->format == ZPixmap ? BitsPerPixel(stuff->depth) : 1,
- ClientOrder(client));
- (*pGC->ops->PutImage) (pDraw, pGC, stuff->depth, stuff->dstX, stuff->dstY,
- stuff->width, stuff->height,
- stuff->leftPad, stuff->format, tmpImage);
- return (client->noClientException);
- }
- int
- DoGetImage(register ClientPtr client, int format, Drawable drawable,
- int x, int y, int width, int height,
- Mask planemask, xGetImageReply ** im_return)
- {
- DrawablePtr pDraw;
- int nlines, linesPerBuf;
- int linesDone;
- long widthBytesLine, length;
- Mask plane = 0;
- char *pBuf;
- xGetImageReply xgi;
- if ((format != XYPixmap) && (format != ZPixmap)) {
- client->errorValue = format;
- return (BadValue);
- }
- SECURITY_VERIFY_DRAWABLE(pDraw, drawable, client, SecurityReadAccess);
- memset(&xgi, 0, sizeof(xGetImageReply));
- if (pDraw->type == DRAWABLE_WINDOW) {
- if ( /* check for being viewable */
- !((WindowPtr) pDraw)->realized ||
- /* check for being on screen */
- pDraw->x + x < 0 ||
- pDraw->x + x + width > pDraw->pScreen->width ||
- pDraw->y + y < 0 ||
- pDraw->y + y + height > pDraw->pScreen->height ||
- /* check for being inside of border */
- x < -wBorderWidth((WindowPtr) pDraw) ||
- x + width > wBorderWidth((WindowPtr) pDraw) + (int) pDraw->width
- || y < -wBorderWidth((WindowPtr) pDraw) ||
- y + height >
- wBorderWidth((WindowPtr) pDraw) + (int) pDraw->height)
- return (BadMatch);
- xgi.visual = wVisual(((WindowPtr) pDraw));
- }
- else {
- if (x < 0 ||
- x + width > (int) pDraw->width ||
- y < 0 || y + height > (int) pDraw->height)
- return (BadMatch);
- xgi.visual = None;
- }
- SET_DBE_SRCBUF(pDraw, drawable);
- xgi.type = X_Reply;
- xgi.sequenceNumber = client->sequence;
- xgi.depth = pDraw->depth;
- if (format == ZPixmap) {
- widthBytesLine = PixmapBytePad(width, pDraw->depth);
- length = widthBytesLine * height;
- }
- else {
- widthBytesLine = BitmapBytePad(width);
- plane = ((Mask) 1) << (pDraw->depth - 1);
- /* only planes asked for */
- length = widthBytesLine * height *
- Ones(planemask & (plane | (plane - 1)));
- }
- xgi.length = length;
- if (im_return) {
- pBuf = malloc(sz_xGetImageReply + length);
- if (!pBuf)
- return (BadAlloc);
- if (widthBytesLine == 0)
- linesPerBuf = 0;
- else
- linesPerBuf = height;
- *im_return = (xGetImageReply *) pBuf;
- *(xGetImageReply *) pBuf = xgi;
- pBuf += sz_xGetImageReply;
- }
- else {
- xgi.length = (xgi.length + 3) >> 2;
- if (widthBytesLine == 0 || height == 0)
- linesPerBuf = 0;
- else if (widthBytesLine >= IMAGE_BUFSIZE)
- linesPerBuf = 1;
- else {
- linesPerBuf = IMAGE_BUFSIZE / widthBytesLine;
- if (linesPerBuf > height)
- linesPerBuf = height;
- }
- length = linesPerBuf * widthBytesLine;
- if (linesPerBuf < height) {
- /* we have to make sure intermediate buffers don't need padding */
- while ((linesPerBuf > 1) &&
- (length & ((1L << LOG2_BYTES_PER_SCANLINE_PAD) - 1))) {
- linesPerBuf--;
- length -= widthBytesLine;
- }
- while (length & ((1L << LOG2_BYTES_PER_SCANLINE_PAD) - 1)) {
- linesPerBuf++;
- length += widthBytesLine;
- }
- }
- if (!(pBuf = (char *) ALLOCATE_LOCAL(length)))
- return (BadAlloc);
- WriteReplyToClient(client, sizeof(xGetImageReply), &xgi);
- }
- if (linesPerBuf == 0) {
- /* nothing to do */
- }
- else if (format == ZPixmap) {
- linesDone = 0;
- while (height - linesDone > 0) {
- nlines = min(linesPerBuf, height - linesDone);
- (*pDraw->pScreen->GetImage) (pDraw,
- x,
- y + linesDone,
- width,
- nlines,
- format, planemask, (pointer) pBuf);
- /* Note that this is NOT a call to WriteSwappedDataToClient,
- as we do NOT byte swap */
- if (!im_return) {
- ReformatImage(pBuf, (int) (nlines * widthBytesLine),
- BitsPerPixel(pDraw->depth), ClientOrder(client));
- /* Don't split me, gcc pukes when you do */
- (void) WriteToClient(client,
- (int) (nlines * widthBytesLine), pBuf);
- }
- linesDone += nlines;
- }
- }
- else { /* XYPixmap */
- for (; plane; plane >>= 1) {
- if (planemask & plane) {
- linesDone = 0;
- while (height - linesDone > 0) {
- nlines = min(linesPerBuf, height - linesDone);
- (*pDraw->pScreen->GetImage) (pDraw,
- x,
- y + linesDone,
- width,
- nlines,
- format, plane, (pointer) pBuf);
- /* Note: NOT a call to WriteSwappedDataToClient,
- as we do NOT byte swap */
- if (im_return) {
- pBuf += nlines * widthBytesLine;
- }
- else {
- ReformatImage(pBuf,
- (int) (nlines * widthBytesLine),
- 1, ClientOrder(client));
- /* Don't split me, gcc pukes when you do */
- (void) WriteToClient(client,
- (int) (nlines * widthBytesLine),
- pBuf);
- }
- linesDone += nlines;
- }
- }
- }
- }
- if (!im_return)
- DEALLOCATE_LOCAL(pBuf);
- return (client->noClientException);
- }
- int
- ProcGetImage(register ClientPtr client)
- {
- REQUEST(xGetImageReq);
- REQUEST_SIZE_MATCH(xGetImageReq);
- return DoGetImage(client, stuff->format, stuff->drawable,
- stuff->x, stuff->y,
- (int) stuff->width, (int) stuff->height,
- stuff->planeMask, (xGetImageReply **) NULL);
- }
- int
- ProcPolyText(register ClientPtr client)
- {
- int err;
- REQUEST(xPolyTextReq);
- DrawablePtr pDraw;
- GC *pGC;
- REQUEST_AT_LEAST_SIZE(xPolyTextReq);
- VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
- err = PolyText(client,
- pDraw,
- pGC,
- (unsigned char *) &stuff[1],
- ((unsigned char *) stuff) + (client->req_len << 2),
- stuff->x, stuff->y, stuff->reqType, stuff->drawable);
- if (err == Success) {
- return (client->noClientException);
- }
- else
- return err;
- }
- int
- ProcImageText8(register ClientPtr client)
- {
- int err;
- DrawablePtr pDraw;
- GC *pGC;
- REQUEST(xImageTextReq);
- REQUEST_FIXED_SIZE(xImageTextReq, stuff->nChars);
- VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
- err = ImageText(client,
- pDraw,
- pGC,
- stuff->nChars,
- (unsigned char *) &stuff[1],
- stuff->x, stuff->y, stuff->reqType, stuff->drawable);
- if (err == Success) {
- return (client->noClientException);
- }
- else
- return err;
- }
- int
- ProcImageText16(register ClientPtr client)
- {
- int err;
- DrawablePtr pDraw;
- GC *pGC;
- REQUEST(xImageTextReq);
- REQUEST_FIXED_SIZE(xImageTextReq, stuff->nChars << 1);
- VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
- err = ImageText(client,
- pDraw,
- pGC,
- stuff->nChars,
- (unsigned char *) &stuff[1],
- stuff->x, stuff->y, stuff->reqType, stuff->drawable);
- if (err == Success) {
- return (client->noClientException);
- }
- else
- return err;
- }
- int
- ProcCreateColormap(register ClientPtr client)
- {
- VisualPtr pVisual;
- ColormapPtr pmap;
- Colormap mid;
- WindowPtr pWin;
- ScreenPtr pScreen;
- REQUEST(xCreateColormapReq);
- int i, result;
- REQUEST_SIZE_MATCH(xCreateColormapReq);
- if ((stuff->alloc != AllocNone) && (stuff->alloc != AllocAll)) {
- client->errorValue = stuff->alloc;
- return (BadValue);
- }
- mid = stuff->mid;
- LEGAL_NEW_RESOURCE(mid, client);
- pWin = (WindowPtr) SecurityLookupWindow(stuff->window, client,
- SecurityReadAccess);
- if (!pWin)
- return (BadWindow);
- pScreen = pWin->drawable.pScreen;
- for (i = 0, pVisual = pScreen->visuals;
- i < pScreen->numVisuals; i++, pVisual++) {
- if (pVisual->vid != stuff->visual)
- continue;
- result = CreateColormap(mid, pScreen, pVisual, &pmap,
- (int) stuff->alloc, client->index);
- if (client->noClientException != Success)
- return (client->noClientException);
- else
- return (result);
- }
- client->errorValue = stuff->visual;
- return (BadMatch);
- }
- int
- ProcFreeColormap(register ClientPtr client)
- {
- ColormapPtr pmap;
- REQUEST(xResourceReq);
- REQUEST_SIZE_MATCH(xResourceReq);
- pmap = (ColormapPtr) SecurityLookupIDByType(client, stuff->id, RT_COLORMAP,
- SecurityDestroyAccess);
- if (pmap) {
- /* Freeing a default colormap is a no-op */
- if (!(pmap->flags & IsDefault))
- FreeResource(stuff->id, RT_NONE);
- return (client->noClientException);
- }
- else {
- client->errorValue = stuff->id;
- return (BadColor);
- }
- }
- int
- ProcCopyColormapAndFree(register ClientPtr client)
- {
- Colormap mid;
- ColormapPtr pSrcMap;
- REQUEST(xCopyColormapAndFreeReq);
- int result;
- REQUEST_SIZE_MATCH(xCopyColormapAndFreeReq);
- mid = stuff->mid;
- LEGAL_NEW_RESOURCE(mid, client);
- if ((pSrcMap = (ColormapPtr) SecurityLookupIDByType(client, stuff->srcCmap,
- RT_COLORMAP,
- SecurityReadAccess |
- SecurityWriteAccess))) {
- result = CopyColormapAndFree(mid, pSrcMap, client->index);
- if (client->noClientException != Success)
- return (client->noClientException);
- else
- return (result);
- }
- else {
- client->errorValue = stuff->srcCmap;
- return (BadColor);
- }
- }
- int
- ProcInstallColormap(register ClientPtr client)
- {
- ColormapPtr pcmp;
- REQUEST(xResourceReq);
- REQUEST_SIZE_MATCH(xResourceReq);
- pcmp = (ColormapPtr) SecurityLookupIDByType(client, stuff->id,
- RT_COLORMAP,
- SecurityReadAccess);
- if (pcmp) {
- (*(pcmp->pScreen->InstallColormap)) (pcmp);
- return (client->noClientException);
- }
- else {
- client->errorValue = stuff->id;
- return (BadColor);
- }
- }
- int
- ProcUninstallColormap(register ClientPtr client)
- {
- ColormapPtr pcmp;
- REQUEST(xResourceReq);
- REQUEST_SIZE_MATCH(xResourceReq);
- pcmp = (ColormapPtr) SecurityLookupIDByType(client, stuff->id,
- RT_COLORMAP,
- SecurityReadAccess);
- if (pcmp) {
- if (pcmp->mid != pcmp->pScreen->defColormap)
- (*(pcmp->pScreen->UninstallColormap)) (pcmp);
- return (client->noClientException);
- }
- else {
- client->errorValue = stuff->id;
- return (BadColor);
- }
- }
- int
- ProcListInstalledColormaps(register ClientPtr client)
- {
- xListInstalledColormapsReply *preply;
- int nummaps;
- WindowPtr pWin;
- REQUEST(xResourceReq);
- REQUEST_SIZE_MATCH(xResourceReq);
- pWin = (WindowPtr) SecurityLookupWindow(stuff->id, client,
- SecurityReadAccess);
- if (!pWin)
- return (BadWindow);
- preply = (xListInstalledColormapsReply *)
- ALLOCATE_LOCAL(sizeof(xListInstalledColormapsReply) +
- pWin->drawable.pScreen->maxInstalledCmaps *
- sizeof(Colormap));
- if (!preply)
- return (BadAlloc);
- preply->type = X_Reply;
- preply->sequenceNumber = client->sequence;
- nummaps = (*pWin->drawable.pScreen->ListInstalledColormaps)
- (pWin->drawable.pScreen, (Colormap *) & preply[1]);
- preply->nColormaps = nummaps;
- preply->length = nummaps;
- WriteReplyToClient(client, sizeof(xListInstalledColormapsReply), preply);
- client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write;
- WriteSwappedDataToClient(client, nummaps * sizeof(Colormap), &preply[1]);
- DEALLOCATE_LOCAL(preply);
- return (client->noClientException);
- }
- int
- ProcAllocColor(register ClientPtr client)
- {
- ColormapPtr pmap;
- int retval;
- xAllocColorReply acr = {0};
- REQUEST(xAllocColorReq);
- REQUEST_SIZE_MATCH(xAllocColorReq);
- pmap = (ColormapPtr) SecurityLookupIDByType(client, stuff->cmap,
- RT_COLORMAP,
- SecurityWriteAccess);
- if (pmap) {
- acr.type = X_Reply;
- acr.length = 0;
- acr.sequenceNumber = client->sequence;
- acr.red = stuff->red;
- acr.green = stuff->green;
- acr.blue = stuff->blue;
- acr.pixel = 0;
- if ((retval = AllocColor(pmap, &acr.red, &acr.green, &acr.blue,
- &acr.pixel, client->index))) {
- if (client->noClientException != Success)
- return (client->noClientException);
- else
- return (retval);
- }
- WriteReplyToClient(client, sizeof(xAllocColorReply), &acr);
- return (client->noClientException);
- }
- else {
- client->errorValue = stuff->cmap;
- return (BadColor);
- }
- }
- int
- ProcAllocNamedColor(register ClientPtr client)
- {
- ColormapPtr pcmp;
- REQUEST(xAllocNamedColorReq);
- REQUEST_FIXED_SIZE(xAllocNamedColorReq, stuff->nbytes);
- pcmp = (ColormapPtr) SecurityLookupIDByType(client, stuff->cmap,
- RT_COLORMAP,
- SecurityWriteAccess);
- if (pcmp) {
- int retval;
- xAllocNamedColorReply ancr;
- ancr.type = X_Reply;
- ancr.length = 0;
- ancr.sequenceNumber = client->sequence;
- if (OsLookupColor
- (pcmp->pScreen->myNum, (char *) &stuff[1], stuff->nbytes,
- &ancr.exactRed, &ancr.exactGreen, &ancr.exactBlue)) {
- ancr.screenRed = ancr.exactRed;
- ancr.screenGreen = ancr.exactGreen;
- ancr.screenBlue = ancr.exactBlue;
- ancr.pixel = 0;
- if ((retval = AllocColor(pcmp,
- &ancr.screenRed, &ancr.screenGreen,
- &ancr.screenBlue, &ancr.pixel,
- client->index))) {
- if (client->noClientException != Success)
- return (client->noClientException);
- else
- return (retval);
- }
- WriteReplyToClient(client, sizeof(xAllocNamedColorReply),
- &ancr);
- return (client->noClientException);
- }
- else
- return (BadName);
- }
- else {
- client->errorValue = stuff->cmap;
- return (BadColor);
- }
- }
- int
- ProcAllocColorCells(register ClientPtr client)
- {
- ColormapPtr pcmp;
- REQUEST(xAllocColorCellsReq);
- REQUEST_SIZE_MATCH(xAllocColorCellsReq);
- pcmp = (ColormapPtr) SecurityLookupIDByType(client, stuff->cmap,
- RT_COLORMAP,
- SecurityWriteAccess);
- if (pcmp) {
- xAllocColorCellsReply accr;
- int npixels, nmasks, retval;
- long length;
- Pixel *ppixels, *pmasks;
- npixels = stuff->colors;
- if (!npixels) {
- client->errorValue = npixels;
- return (BadValue);
- }
- if (stuff->contiguous != xTrue && stuff->contiguous != xFalse) {
- client->errorValue = stuff->contiguous;
- return (BadValue);
- }
- nmasks = stuff->planes;
- length = ((long) npixels + (long) nmasks) * sizeof(Pixel);
- ppixels = (Pixel *) ALLOCATE_LOCAL(length);
- if (!ppixels)
- return (BadAlloc);
- pmasks = ppixels + npixels;
- if ((retval = AllocColorCells(client->index, pcmp, npixels, nmasks,
- (Bool) stuff->contiguous, ppixels,
- pmasks))) {
- DEALLOCATE_LOCAL(ppixels);
- if (client->noClientException != Success)
- return (client->noClientException);
- else
- return (retval);
- }
- {
- accr.type = X_Reply;
- accr.length = length >> 2;
- accr.sequenceNumber = client->sequence;
- accr.nPixels = npixels;
- accr.nMasks = nmasks;
- WriteReplyToClient(client, sizeof(xAllocColorCellsReply), &accr);
- client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write;
- WriteSwappedDataToClient(client, length, ppixels);
- }
- DEALLOCATE_LOCAL(ppixels);
- return (client->noClientException);
- }
- else {
- client->errorValue = stuff->cmap;
- return (BadColor);
- }
- }
- int
- ProcAllocColorPlanes(register ClientPtr client)
- {
- ColormapPtr pcmp;
- REQUEST(xAllocColorPlanesReq);
- REQUEST_SIZE_MATCH(xAllocColorPlanesReq);
- pcmp = (ColormapPtr) SecurityLookupIDByType(client, stuff->cmap,
- RT_COLORMAP,
- SecurityWriteAccess);
- if (pcmp) {
- xAllocColorPlanesReply acpr;
- int npixels, retval;
- long length;
- Pixel *ppixels;
- npixels = stuff->colors;
- if (!npixels) {
- client->errorValue = npixels;
- return (BadValue);
- }
- if (stuff->contiguous != xTrue && stuff->contiguous != xFalse) {
- client->errorValue = stuff->contiguous;
- return (BadValue);
- }
- acpr.type = X_Reply;
- acpr.sequenceNumber = client->sequence;
- acpr.nPixels = npixels;
- length = (long) npixels *sizeof(Pixel);
- ppixels = (Pixel *) ALLOCATE_LOCAL(length);
- if (!ppixels)
- return (BadAlloc);
- if ((retval = AllocColorPlanes(client->index, pcmp, npixels,
- (int) stuff->red, (int) stuff->green,
- (int) stuff->blue,
- (Bool) stuff->contiguous, ppixels,
- &acpr.redMask, &acpr.greenMask,
- &acpr.blueMask))) {
- DEALLOCATE_LOCAL(ppixels);
- if (client->noClientException != Success)
- return (client->noClientException);
- else
- return (retval);
- }
- acpr.length = length >> 2;
- {
- WriteReplyToClient(client, sizeof(xAllocColorPlanesReply), &acpr);
- client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write;
- WriteSwappedDataToClient(client, length, ppixels);
- }
- DEALLOCATE_LOCAL(ppixels);
- return (client->noClientException);
- }
- else {
- client->errorValue = stuff->cmap;
- return (BadColor);
- }
- }
- int
- ProcFreeColors(register ClientPtr client)
- {
- ColormapPtr pcmp;
- REQUEST(xFreeColorsReq);
- REQUEST_AT_LEAST_SIZE(xFreeColorsReq);
- pcmp = (ColormapPtr) SecurityLookupIDByType(client, stuff->cmap,
- RT_COLORMAP,
- SecurityWriteAccess);
- if (pcmp) {
- int count;
- int retval;
- if (pcmp->flags & AllAllocated)
- return (BadAccess);
- count = ((client->req_len << 2) - sizeof(xFreeColorsReq)) >> 2;
- retval = FreeColors(pcmp, client->index, count,
- (Pixel *) & stuff[1], (Pixel) stuff->planeMask);
- if (client->noClientException != Success)
- return (client->noClientException);
- else {
- client->errorValue = clientErrorValue;
- return (retval);
- }
- }
- else {
- client->errorValue = stuff->cmap;
- return (BadColor);
- }
- }
- int
- ProcStoreColors(ClientPtr client)
- {
- ColormapPtr pcmp;
- REQUEST(xStoreColorsReq);
- REQUEST_AT_LEAST_SIZE(xStoreColorsReq);
- pcmp = (ColormapPtr) SecurityLookupIDByType(client, stuff->cmap,
- RT_COLORMAP,
- SecurityWriteAccess);
- if (pcmp) {
- int count;
- int retval;
- count = (client->req_len << 2) - sizeof(xStoreColorsReq);
- if (count % sizeof(xColorItem))
- return (BadLength);
- count /= sizeof(xColorItem);
- retval = StoreColors(pcmp, count, (xColorItem *) & stuff[1]);
- if (client->noClientException != Success)
- return (client->noClientException);
- else {
- client->errorValue = clientErrorValue;
- return (retval);
- }
- }
- else {
- client->errorValue = stuff->cmap;
- return (BadColor);
- }
- }
- int
- ProcStoreNamedColor(register ClientPtr client)
- {
- ColormapPtr pcmp;
- REQUEST(xStoreNamedColorReq);
- REQUEST_FIXED_SIZE(xStoreNamedColorReq, stuff->nbytes);
- pcmp = (ColormapPtr) SecurityLookupIDByType(client, stuff->cmap,
- RT_COLORMAP,
- SecurityWriteAccess);
- if (pcmp) {
- xColorItem def;
- int retval;
- if (OsLookupColor(pcmp->pScreen->myNum, (char *) &stuff[1],
- stuff->nbytes, &def.red, &def.green, &def.blue)) {
- def.flags = stuff->flags;
- def.pixel = stuff->pixel;
- retval = StoreColors(pcmp, 1, &def);
- if (client->noClientException != Success)
- return (client->noClientException);
- else
- return (retval);
- }
- return (BadName);
- }
- else {
- client->errorValue = stuff->cmap;
- return (BadColor);
- }
- }
- int
- ProcQueryColors(register ClientPtr client)
- {
- ColormapPtr pcmp;
- REQUEST(xQueryColorsReq);
- REQUEST_AT_LEAST_SIZE(xQueryColorsReq);
- pcmp = (ColormapPtr) SecurityLookupIDByType(client, stuff->cmap,
- RT_COLORMAP,
- SecurityReadAccess);
- if (pcmp) {
- int count, retval;
- xrgb *prgbs;
- xQueryColorsReply qcr = {0};
- count = ((client->req_len << 2) - sizeof(xQueryColorsReq)) >> 2;
- prgbs = (xrgb *) ALLOCATE_LOCAL(count * sizeof(xrgb));
- memset(prgbs, 0, count * sizeof(xrgb));
- if (!prgbs && count)
- return (BadAlloc);
- if ((retval = QueryColors(pcmp, count, (Pixel *) & stuff[1], prgbs))) {
- if (prgbs)
- DEALLOCATE_LOCAL(prgbs);
- if (client->noClientException != Success)
- return (client->noClientException);
- else {
- client->errorValue = clientErrorValue;
- return (retval);
- }
- }
- qcr.type = X_Reply;
- qcr.length = (count * sizeof(xrgb)) >> 2;
- qcr.sequenceNumber = client->sequence;
- qcr.nColors = count;
- WriteReplyToClient(client, sizeof(xQueryColorsReply), &qcr);
- if (count) {
- client->pSwapReplyFunc = (ReplySwapPtr) SQColorsExtend;
- WriteSwappedDataToClient(client, count * sizeof(xrgb), prgbs);
- }
- if (prgbs)
- DEALLOCATE_LOCAL(prgbs);
- return (client->noClientException);
- }
- else {
- client->errorValue = stuff->cmap;
- return (BadColor);
- }
- }
- int
- ProcLookupColor(register ClientPtr client)
- {
- ColormapPtr pcmp;
- REQUEST(xLookupColorReq);
- REQUEST_FIXED_SIZE(xLookupColorReq, stuff->nbytes);
- pcmp = (ColormapPtr) SecurityLookupIDByType(client, stuff->cmap,
- RT_COLORMAP,
- SecurityReadAccess);
- if (pcmp) {
- xLookupColorReply lcr = {0};
- if (OsLookupColor
- (pcmp->pScreen->myNum, (char *) &stuff[1], stuff->nbytes,
- &lcr.exactRed, &lcr.exactGreen, &lcr.exactBlue)) {
- lcr.type = X_Reply;
- lcr.length = 0;
- lcr.sequenceNumber = client->sequence;
- lcr.screenRed = lcr.exactRed;
- lcr.screenGreen = lcr.exactGreen;
- lcr.screenBlue = lcr.exactBlue;
- (*pcmp->pScreen->ResolveColor) (&lcr.screenRed,
- &lcr.screenGreen,
- &lcr.screenBlue, pcmp->pVisual);
- WriteReplyToClient(client, sizeof(xLookupColorReply), &lcr);
- return (client->noClientException);
- }
- return (BadName);
- }
- else {
- client->errorValue = stuff->cmap;
- return (BadColor);
- }
- }
- int
- ProcCreateCursor(register ClientPtr client)
- {
- CursorPtr pCursor;
- PixmapPtr src;
- PixmapPtr msk;
- unsigned char *srcbits;
- unsigned char *mskbits;
- unsigned short width, height;
- long n;
- CursorMetricRec cm;
- REQUEST(xCreateCursorReq);
- REQUEST_SIZE_MATCH(xCreateCursorReq);
- LEGAL_NEW_RESOURCE(stuff->cid, client);
- src = (PixmapPtr) SecurityLookupIDByType(client, stuff->source,
- RT_PIXMAP, SecurityReadAccess);
- msk = (PixmapPtr) SecurityLookupIDByType(client, stuff->mask,
- RT_PIXMAP, SecurityReadAccess);
- if (src == (PixmapPtr) NULL) {
- client->errorValue = stuff->source;
- return (BadPixmap);
- }
- if (msk == (PixmapPtr) NULL) {
- if (stuff->mask != None) {
- client->errorValue = stuff->mask;
- return (BadPixmap);
- }
- }
- else if (src->drawable.width != msk->drawable.width
- || src->drawable.height != msk->drawable.height
- || src->drawable.depth != 1 || msk->drawable.depth != 1)
- return (BadMatch);
- width = src->drawable.width;
- height = src->drawable.height;
- if (stuff->x > width || stuff->y > height)
- return (BadMatch);
- n = BitmapBytePad(width) * height;
- srcbits = malloc(n);
- if (!srcbits)
- return (BadAlloc);
- mskbits = malloc(n);
- if (!mskbits) {
- free(srcbits);
- return (BadAlloc);
- }
- /* zeroing the (pad) bits helps some ddx cursor handling */
- bzero((char *) srcbits, n);
- (*src->drawable.pScreen->GetImage) ((DrawablePtr) src, 0, 0, width, height,
- XYPixmap, 1, (pointer) srcbits);
- if (msk == (PixmapPtr) NULL) {
- unsigned char *bits = mskbits;
- while (--n >= 0)
- *bits++ = ~0;
- }
- else {
- /* zeroing the (pad) bits helps some ddx cursor handling */
- bzero((char *) mskbits, n);
- (*msk->drawable.pScreen->GetImage) ((DrawablePtr) msk, 0, 0, width,
- height, XYPixmap, 1,
- (pointer) mskbits);
- }
- cm.width = width;
- cm.height = height;
- cm.xhot = stuff->x;
- cm.yhot = stuff->y;
- pCursor = AllocCursor(srcbits, mskbits, &cm,
- stuff->foreRed, stuff->foreGreen, stuff->foreBlue,
- stuff->backRed, stuff->backGreen, stuff->backBlue);
- if (pCursor && AddResource(stuff->cid, RT_CURSOR, (pointer) pCursor))
- return (client->noClientException);
- return BadAlloc;
- }
- int
- ProcCreateGlyphCursor(register ClientPtr client)
- {
- CursorPtr pCursor;
- int res;
- REQUEST(xCreateGlyphCursorReq);
- REQUEST_SIZE_MATCH(xCreateGlyphCursorReq);
- LEGAL_NEW_RESOURCE(stuff->cid, client);
- res = AllocGlyphCursor(stuff->source, stuff->sourceChar,
- stuff->mask, stuff->maskChar,
- stuff->foreRed, stuff->foreGreen, stuff->foreBlue,
- stuff->backRed, stuff->backGreen, stuff->backBlue,
- &pCursor, client);
- if (res != Success)
- return res;
- if (AddResource(stuff->cid, RT_CURSOR, (pointer) pCursor))
- return client->noClientException;
- return BadAlloc;
- }
- int
- ProcFreeCursor(register ClientPtr client)
- {
- CursorPtr pCursor;
- REQUEST(xResourceReq);
- REQUEST_SIZE_MATCH(xResourceReq);
- pCursor = (CursorPtr) SecurityLookupIDByType(client, stuff->id,
- RT_CURSOR,
- SecurityDestroyAccess);
- if (pCursor) {
- FreeResource(stuff->id, RT_NONE);
- return (client->noClientException);
- }
- else {
- client->errorValue = stuff->id;
- return (BadCursor);
- }
- }
- int
- ProcQueryBestSize(register ClientPtr client)
- {
- xQueryBestSizeReply reply = {0};
- DrawablePtr pDraw;
- ScreenPtr pScreen;
- REQUEST(xQueryBestSizeReq);
- REQUEST_SIZE_MATCH(xQueryBestSizeReq);
- if ((stuff->class != CursorShape) &&
- (stuff->class != TileShape) && (stuff->class != StippleShape)) {
- client->errorValue = stuff->class;
- return (BadValue);
- }
- SECURITY_VERIFY_GEOMETRABLE(pDraw, stuff->drawable, client,
- SecurityReadAccess);
- if (stuff->class != CursorShape && pDraw->type == UNDRAWABLE_WINDOW)
- return (BadMatch);
- pScreen = pDraw->pScreen;
- (*pScreen->QueryBestSize) (stuff->class, &stuff->width,
- &stuff->height, pScreen);
- reply.type = X_Reply;
- reply.length = 0;
- reply.sequenceNumber = client->sequence;
- reply.width = stuff->width;
- reply.height = stuff->height;
- WriteReplyToClient(client, sizeof(xQueryBestSizeReply), &reply);
- return (client->noClientException);
- }
- int
- ProcSetScreenSaver(register ClientPtr client)
- {
- int blankingOption, exposureOption;
- REQUEST(xSetScreenSaverReq);
- REQUEST_SIZE_MATCH(xSetScreenSaverReq);
- blankingOption = stuff->preferBlank;
- if ((blankingOption != DontPreferBlanking) &&
- (blankingOption != PreferBlanking) &&
- (blankingOption != DefaultBlanking)) {
- client->errorValue = blankingOption;
- return BadValue;
- }
- exposureOption = stuff->allowExpose;
- if ((exposureOption != DontAllowExposures) &&
- (exposureOption != AllowExposures) &&
- (exposureOption != DefaultExposures)) {
- client->errorValue = exposureOption;
- return BadValue;
- }
- if (stuff->timeout < -1) {
- client->errorValue = stuff->timeout;
- return BadValue;
- }
- if (stuff->interval < -1) {
- client->errorValue = stuff->interval;
- return BadValue;
- }
- if (blankingOption == DefaultBlanking)
- ScreenSaverBlanking = defaultScreenSaverBlanking;
- else
- ScreenSaverBlanking = blankingOption;
- if (exposureOption == DefaultExposures)
- ScreenSaverAllowExposures = defaultScreenSaverAllowExposures;
- else
- ScreenSaverAllowExposures = exposureOption;
- if (stuff->timeout >= 0)
- ScreenSaverTime = stuff->timeout * MILLI_PER_SECOND;
- else
- ScreenSaverTime = defaultScreenSaverTime;
- if (stuff->interval >= 0)
- ScreenSaverInterval = stuff->interval * MILLI_PER_SECOND;
- else
- ScreenSaverInterval = defaultScreenSaverInterval;
- SetScreenSaverTimer();
- return (client->noClientException);
- }
- int
- ProcGetScreenSaver(register ClientPtr client)
- {
- xGetScreenSaverReply rep;
- REQUEST_SIZE_MATCH(xReq);
- rep.type = X_Reply;
- rep.length = 0;
- rep.sequenceNumber = client->sequence;
- rep.timeout = ScreenSaverTime / MILLI_PER_SECOND;
- rep.interval = ScreenSaverInterval / MILLI_PER_SECOND;
- rep.preferBlanking = ScreenSaverBlanking;
- rep.allowExposures = ScreenSaverAllowExposures;
- WriteReplyToClient(client, sizeof(xGetScreenSaverReply), &rep);
- return (client->noClientException);
- }
- int
- ProcChangeHosts(register ClientPtr client)
- {
- REQUEST(xChangeHostsReq);
- int result;
- REQUEST_FIXED_SIZE(xChangeHostsReq, stuff->hostLength);
- if (stuff->mode == HostInsert)
- result = AddHost(client, (int) stuff->hostFamily,
- stuff->hostLength, (pointer) &stuff[1]);
- else if (stuff->mode == HostDelete)
- result = RemoveHost(client, (int) stuff->hostFamily,
- stuff->hostLength, (pointer) &stuff[1]);
- else {
- client->errorValue = stuff->mode;
- return BadValue;
- }
- if (!result)
- result = client->noClientException;
- return (result);
- }
- int
- ProcListHosts(register ClientPtr client)
- {
- xListHostsReply reply;
- int len, nHosts, result;
- pointer pdata;
- /* REQUEST(xListHostsReq); */
- REQUEST_SIZE_MATCH(xListHostsReq);
- result = GetHosts(&pdata, &nHosts, &len, &reply.enabled);
- if (result != Success)
- return (result);
- reply.type = X_Reply;
- reply.sequenceNumber = client->sequence;
- reply.nHosts = nHosts;
- reply.length = len >> 2;
- WriteReplyToClient(client, sizeof(xListHostsReply), &reply);
- if (nHosts) {
- client->pSwapReplyFunc = (ReplySwapPtr) SLHostsExtend;
- WriteSwappedDataToClient(client, len, pdata);
- }
- free(pdata);
- return (client->noClientException);
- }
- int
- ProcChangeAccessControl(register ClientPtr client)
- {
- int result;
- REQUEST(xSetAccessControlReq);
- REQUEST_SIZE_MATCH(xSetAccessControlReq);
- if ((stuff->mode != EnableAccess) && (stuff->mode != DisableAccess)) {
- client->errorValue = stuff->mode;
- return BadValue;
- }
- result = ChangeAccessControl(client, stuff->mode == EnableAccess);
- if (!result)
- result = client->noClientException;
- return (result);
- }
- int
- ProcKillClient(register ClientPtr client)
- {
- REQUEST(xResourceReq);
- ClientPtr killclient;
- REQUEST_SIZE_MATCH(xResourceReq);
- if (stuff->id == AllTemporary) {
- CloseDownRetainedResources();
- return (client->noClientException);
- }
- if ((killclient = LookupClient(stuff->id, client))) {
- CloseDownClient(killclient);
- /* if an LBX proxy gets killed, isItTimeToYield will be set */
- if (isItTimeToYield || (client == killclient)) {
- /* force yield and return Success, so that Dispatch()
- * doesn't try to touch client
- */
- isItTimeToYield = TRUE;
- return (Success);
- }
- return (client->noClientException);
- }
- else {
- client->errorValue = stuff->id;
- return (BadValue);
- }
- }
- int
- ProcSetFontPath(register ClientPtr client)
- {
- unsigned char *ptr;
- unsigned long nbytes, total;
- long nfonts;
- int n, result;
- int error;
- REQUEST(xSetFontPathReq);
- REQUEST_AT_LEAST_SIZE(xSetFontPathReq);
- nbytes = (client->req_len << 2) - sizeof(xSetFontPathReq);
- total = nbytes;
- ptr = (unsigned char *) &stuff[1];
- nfonts = stuff->nFonts;
- while (--nfonts >= 0) {
- if ((total == 0) || (total < (n = (*ptr + 1))))
- return (BadLength);
- total -= n;
- ptr += n;
- }
- if (total >= 4)
- return (BadLength);
- result = SetFontPath(client, stuff->nFonts, (unsigned char *) &stuff[1],
- &error);
- if (!result) {
- result = client->noClientException;
- client->errorValue = error;
- }
- return (result);
- }
- int
- ProcGetFontPath(register ClientPtr client)
- {
- xGetFontPathReply reply;
- int stringLens, numpaths;
- unsigned char *bufferStart;
- /* REQUEST (xReq); */
- REQUEST_SIZE_MATCH(xReq);
- bufferStart = GetFontPath(&numpaths, &stringLens);
- reply.type = X_Reply;
- reply.sequenceNumber = client->sequence;
- reply.length = (stringLens + numpaths + 3) >> 2;
- reply.nPaths = numpaths;
- WriteReplyToClient(client, sizeof(xGetFontPathReply), &reply);
- if (stringLens || numpaths)
- (void) WriteToClient(client, stringLens + numpaths,
- (char *) bufferStart);
- return (client->noClientException);
- }
- int
- ProcChangeCloseDownMode(register ClientPtr client)
- {
- REQUEST(xSetCloseDownModeReq);
- REQUEST_SIZE_MATCH(xSetCloseDownModeReq);
- if ((stuff->mode == AllTemporary) ||
- (stuff->mode == RetainPermanent) || (stuff->mode == RetainTemporary)) {
- client->closeDownMode = stuff->mode;
- return (client->noClientException);
- }
- else {
- client->errorValue = stuff->mode;
- return (BadValue);
- }
- }
- int
- ProcForceScreenSaver(register ClientPtr client)
- {
- REQUEST(xForceScreenSaverReq);
- REQUEST_SIZE_MATCH(xForceScreenSaverReq);
- if ((stuff->mode != ScreenSaverReset) && (stuff->mode != ScreenSaverActive)) {
- client->errorValue = stuff->mode;
- return BadValue;
- }
- SaveScreens(SCREEN_SAVER_FORCER, (int) stuff->mode);
- return client->noClientException;
- }
- int
- ProcNoOperation(register ClientPtr client)
- {
- REQUEST_AT_LEAST_SIZE(xReq);
- /* noop -- don't do anything */
- return (client->noClientException);
- }
- /**********************
- * CloseDownClient
- *
- * Client can either mark his resources destroy or retain. If retained and
- * then killed again, the client is really destroyed.
- *********************/
- char dispatchExceptionAtReset = 0;
- void
- CloseDownClient(register ClientPtr client)
- {
- Bool really_close_down = client->clientGone ||
- client->closeDownMode == DestroyAll;
- if (!client->clientGone) {
- /* ungrab server if grabbing client dies */
- if (grabState != GrabNone && grabClient == client) {
- UngrabServer(client);
- }
- BITCLEAR(grabWaiters, client->index);
- DeleteClientFromAnySelections(client);
- ReleaseActiveGrabs(client);
- DeleteClientFontStuff(client);
- if (!really_close_down) {
- /* This frees resources that should never be retained
- * no matter what the close down mode is. Actually we
- * could do this unconditionally, but it's probably
- * better not to traverse all the client's resources
- * twice (once here, once a few lines down in
- * FreeClientResources) in the common case of
- * really_close_down == TRUE.
- */
- FreeClientNeverRetainResources(client);
- client->clientState = ClientStateRetained;
- if (ClientStateCallback) {
- NewClientInfoRec clientinfo;
- clientinfo.client = client;
- clientinfo.prefix = (xConnSetupPrefix *) NULL;
- clientinfo.setup = (xConnSetup *) NULL;
- CallCallbacks((&ClientStateCallback), (pointer) &clientinfo);
- }
- }
- client->clientGone = TRUE; /* so events aren't sent to client */
- if (ClientIsAsleep(client))
- ClientSignal(client);
- ProcessWorkQueueZombies();
- CloseDownConnection(client);
- /* If the client made it to the Running stage, nClients has
- * been incremented on its behalf, so we need to decrement it
- * now. If it hasn't gotten to Running, nClients has *not*
- * been incremented, so *don't* decrement it.
- */
- if (client->clientState != ClientStateInitial &&
- client->clientState != ClientStateAuthenticating) {
- --nClients;
- }
- }
- if (really_close_down) {
- if (client->clientState == ClientStateRunning && nClients == 0)
- dispatchException |= dispatchExceptionAtReset;
- client->clientState = ClientStateGone;
- if (ClientStateCallback) {
- NewClientInfoRec clientinfo;
- clientinfo.client = client;
- clientinfo.prefix = (xConnSetupPrefix *) NULL;
- clientinfo.setup = (xConnSetup *) NULL;
- CallCallbacks((&ClientStateCallback), (pointer) &clientinfo);
- }
- FreeClientResources(client);
- if (client->index < nextFreeClientID)
- nextFreeClientID = client->index;
- clients[client->index] = NullClient;
- #ifdef SMART_SCHEDULE
- SmartLastClient = NullClient;
- #endif
- free(client);
- while (!clients[currentMaxClients - 1])
- currentMaxClients--;
- }
- }
- static void
- KillAllClients()
- {
- int i;
- for (i = 1; i < currentMaxClients; i++)
- if (clients[i]) {
- /* Make sure Retained clients are released. */
- clients[i]->closeDownMode = DestroyAll;
- CloseDownClient(clients[i]);
- }
- }
- /*********************
- * CloseDownRetainedResources
- *
- * Find all clients that are gone and have terminated in RetainTemporary
- * and destroy their resources.
- *********************/
- void
- CloseDownRetainedResources()
- {
- int i;
- ClientPtr client;
- for (i = 1; i < currentMaxClients; i++) {
- client = clients[i];
- if (client && (client->closeDownMode == RetainTemporary)
- && (client->clientGone))
- CloseDownClient(client);
- }
- }
- extern int clientPrivateLen;
- extern unsigned *clientPrivateSizes;
- extern unsigned totalClientSize;
- void
- InitClient(ClientPtr client, int i, pointer ospriv)
- {
- client->index = i;
- client->sequence = 0;
- client->clientAsMask = ((Mask) i) << CLIENTOFFSET;
- client->clientGone = FALSE;
- if (i) {
- client->closeDownMode = DestroyAll;
- client->lastDrawable = (DrawablePtr) WindowTable[0];
- client->lastDrawableID = WindowTable[0]->drawable.id;
- }
- else {
- client->closeDownMode = RetainPermanent;
- client->lastDrawable = (DrawablePtr) NULL;
- client->lastDrawableID = INVALID;
- }
- client->lastGC = (GCPtr) NULL;
- client->lastGCID = INVALID;
- client->numSaved = 0;
- client->saveSet = (SaveSetElt *) NULL;
- client->noClientException = Success;
- #ifdef DEBUG
- client->requestLogIndex = 0;
- #endif
- client->requestVector = InitialVector;
- client->osPrivate = ospriv;
- client->swapped = FALSE;
- client->big_requests = FALSE;
- client->priority = 0;
- client->clientState = ClientStateInitial;
- client->replyBytesRemaining = 0;
- client->fontResFunc = NULL;
- #ifdef SMART_SCHEDULE
- client->smart_priority = 0;
- client->smart_start_tick = SmartScheduleTime;
- client->smart_stop_tick = SmartScheduleTime;
- client->smart_check_tick = SmartScheduleTime;
- #endif
- }
- int
- InitClientPrivates(ClientPtr client)
- {
- char *ptr;
- DevUnion *ppriv;
- unsigned *sizes;
- unsigned size;
- int i;
- if (totalClientSize == sizeof(ClientRec))
- ppriv = (DevUnion *) NULL;
- else if (client->index)
- ppriv = (DevUnion *) (client + 1);
- else {
- ppriv = malloc(totalClientSize - sizeof(ClientRec));
- if (!ppriv)
- return 0;
- }
- client->devPrivates = ppriv;
- sizes = clientPrivateSizes;
- ptr = (char *) (ppriv + clientPrivateLen);
- for (i = clientPrivateLen; --i >= 0; ppriv++, sizes++) {
- if ((size = *sizes)) {
- ppriv->ptr = (pointer) ptr;
- ptr += size;
- }
- else
- ppriv->ptr = (pointer) NULL;
- }
- /* Allow registrants to initialize the serverClient devPrivates */
- if (!client->index && ClientStateCallback) {
- NewClientInfoRec clientinfo;
- clientinfo.client = client;
- clientinfo.prefix = (xConnSetupPrefix *) NULL;
- clientinfo.setup = (xConnSetup *) NULL;
- CallCallbacks((&ClientStateCallback), (pointer) &clientinfo);
- }
- return 1;
- }
- /************************
- * int NextAvailableClient(ospriv)
- *
- * OS dependent portion can't assign client id's because of CloseDownModes.
- * Returns NULL if there are no free clients.
- *************************/
- ClientPtr
- NextAvailableClient(pointer ospriv)
- {
- int i;
- ClientPtr client;
- xReq data;
- i = nextFreeClientID;
- if (i == MAXCLIENTS)
- return (ClientPtr) NULL;
- clients[i] = client = malloc(totalClientSize);
- if (!client)
- return (ClientPtr) NULL;
- InitClient(client, i, ospriv);
- InitClientPrivates(client);
- if (!InitClientResources(client)) {
- free(client);
- return (ClientPtr) NULL;
- }
- data.reqType = 1;
- data.length = (sz_xReq + sz_xConnClientPrefix) >> 2;
- if (!InsertFakeRequest(client, (char *) &data, sz_xReq)) {
- FreeClientResources(client);
- free(client);
- return (ClientPtr) NULL;
- }
- if (i == currentMaxClients)
- currentMaxClients++;
- while ((nextFreeClientID < MAXCLIENTS) && clients[nextFreeClientID])
- nextFreeClientID++;
- if (ClientStateCallback) {
- NewClientInfoRec clientinfo;
- clientinfo.client = client;
- clientinfo.prefix = (xConnSetupPrefix *) NULL;
- clientinfo.setup = (xConnSetup *) NULL;
- CallCallbacks((&ClientStateCallback), (pointer) &clientinfo);
- }
- return (client);
- }
- int
- ProcInitialConnection(register ClientPtr client)
- {
- REQUEST(xReq);
- xConnClientPrefix *prefix;
- int whichbyte = 1;
- prefix = (xConnClientPrefix *) ((char *) stuff + sz_xReq);
- if ((prefix->byteOrder != 'l') && (prefix->byteOrder != 'B'))
- return (client->noClientException = -1);
- if (((*(char *) &whichbyte) && (prefix->byteOrder == 'B')) ||
- (!(*(char *) &whichbyte) && (prefix->byteOrder == 'l'))) {
- client->swapped = TRUE;
- SwapConnClientPrefix(prefix);
- }
- stuff->reqType = 2;
- stuff->length += ((prefix->nbytesAuthProto + (unsigned) 3) >> 2) +
- ((prefix->nbytesAuthString + (unsigned) 3) >> 2);
- if (client->swapped) {
- swaps(&stuff->length);
- }
- ResetCurrentRequest(client);
- return (client->noClientException);
- }
- int
- SendConnSetup(register ClientPtr client, const char *reason)
- {
- xWindowRoot *root;
- int i;
- int numScreens;
- char *lConnectionInfo;
- xConnSetupPrefix *lconnSetupPrefix;
- if (reason) {
- xConnSetupPrefix csp;
- csp.success = xFalse;
- csp.lengthReason = strlen(reason);
- csp.length = (csp.lengthReason + (unsigned) 3) >> 2;
- csp.majorVersion = X_PROTOCOL;
- csp.minorVersion = X_PROTOCOL_REVISION;
- if (client->swapped)
- WriteSConnSetupPrefix(client, &csp);
- else
- (void) WriteToClient(client, sz_xConnSetupPrefix, (char *) &csp);
- (void) WriteToClient(client, (int) csp.lengthReason, reason);
- return (client->noClientException = -1);
- }
- numScreens = screenInfo.numScreens;
- lConnectionInfo = ConnectionInfo;
- lconnSetupPrefix = &connSetupPrefix;
- /* We're about to start speaking X protocol back to the client by
- * sending the connection setup info. This means the authorization
- * step is complete, and we can count the client as an
- * authorized one.
- */
- nClients++;
- client->requestVector = client->swapped ? SwappedProcVector : ProcVector;
- client->sequence = 0;
- ((xConnSetup *) lConnectionInfo)->ridBase = client->clientAsMask;
- ((xConnSetup *) lConnectionInfo)->ridMask = RESOURCE_ID_MASK;
- #ifdef MATCH_CLIENT_ENDIAN
- ((xConnSetup *) lConnectionInfo)->imageByteOrder = ClientOrder(client);
- ((xConnSetup *) lConnectionInfo)->bitmapBitOrder = ClientOrder(client);
- #endif
- /* fill in the "currentInputMask" */
- root = (xWindowRoot *) (lConnectionInfo + connBlockScreenStart);
- for (i = 0; i < numScreens; i++) {
- unsigned int j;
- xDepth *pDepth;
- root->currentInputMask = WindowTable[i]->eventMask |
- wOtherEventMasks(WindowTable[i]);
- pDepth = (xDepth *) (root + 1);
- for (j = 0; j < root->nDepths; j++) {
- pDepth = (xDepth *) (((char *) (pDepth + 1)) +
- pDepth->nVisuals * sizeof(xVisualType));
- }
- root = (xWindowRoot *) pDepth;
- }
- if (client->swapped) {
- WriteSConnSetupPrefix(client, lconnSetupPrefix);
- WriteSConnectionInfo(client,
- (unsigned long) (lconnSetupPrefix->length << 2),
- lConnectionInfo);
- }
- else {
- (void) WriteToClient(client, sizeof(xConnSetupPrefix),
- (char *) lconnSetupPrefix);
- (void) WriteToClient(client, (int) (lconnSetupPrefix->length << 2),
- lConnectionInfo);
- }
- client->clientState = ClientStateRunning;
- if (ClientStateCallback) {
- NewClientInfoRec clientinfo;
- clientinfo.client = client;
- clientinfo.prefix = lconnSetupPrefix;
- clientinfo.setup = (xConnSetup *) lConnectionInfo;
- CallCallbacks((&ClientStateCallback), (pointer) &clientinfo);
- }
- return (client->noClientException);
- }
- int
- ProcEstablishConnection(register ClientPtr client)
- {
- const char *reason;
- char *auth_proto, *auth_string;
- xConnClientPrefix *prefix;
- REQUEST(xReq);
- prefix = (xConnClientPrefix *) ((char *) stuff + sz_xReq);
- auth_proto = (char *) prefix + sz_xConnClientPrefix;
- auth_string = auth_proto + ((prefix->nbytesAuthProto + 3) & ~3);
- if ((prefix->majorVersion != X_PROTOCOL) ||
- (prefix->minorVersion != X_PROTOCOL_REVISION))
- reason = "Protocol version mismatch";
- else
- reason = ClientAuthorized(client,
- (unsigned short) prefix->nbytesAuthProto,
- auth_proto,
- (unsigned short) prefix->nbytesAuthString,
- auth_string);
- /*
- * If Kerberos is being used for this client, the clientState
- * will be set to ClientStateAuthenticating at this point.
- * More messages need to be exchanged among the X server, Kerberos
- * server, and client to figure out if everyone is authorized.
- * So we don't want to send the connection setup info yet, since
- * the auth step isn't really done.
- */
- if (client->clientState == ClientStateCheckingSecurity)
- client->clientState = ClientStateCheckedSecurity;
- else if (client->clientState != ClientStateAuthenticating)
- return (SendConnSetup(client, reason));
- return (client->noClientException);
- }
- _X_EXPORT void
- SendErrorToClient(ClientPtr client, unsigned majorCode, unsigned minorCode,
- XID resId, int errorCode)
- {
- xError rep;
- rep.type = X_Error;
- rep.errorCode = errorCode;
- rep.majorCode = majorCode;
- rep.minorCode = minorCode;
- rep.resourceID = resId;
- WriteEventsToClient(client, 1, (xEvent *) &rep);
- }
- void
- DeleteWindowFromAnySelections(WindowPtr pWin)
- {
- int i;
- for (i = 0; i < NumCurrentSelections; i++)
- if (CurrentSelections[i].pWin == pWin) {
- if (SelectionCallback) {
- SelectionInfoRec info;
- info.selection = &CurrentSelections[i];
- info.kind = SelectionWindowDestroy;
- CallCallbacks(&SelectionCallback, &info);
- }
- CurrentSelections[i].pWin = (WindowPtr) NULL;
- CurrentSelections[i].window = None;
- CurrentSelections[i].client = NullClient;
- }
- }
- static void
- DeleteClientFromAnySelections(ClientPtr client)
- {
- int i;
- for (i = 0; i < NumCurrentSelections; i++)
- if (CurrentSelections[i].client == client) {
- if (SelectionCallback) {
- SelectionInfoRec info;
- info.selection = &CurrentSelections[i];
- info.kind = SelectionWindowDestroy;
- CallCallbacks(&SelectionCallback, &info);
- }
- CurrentSelections[i].pWin = (WindowPtr) NULL;
- CurrentSelections[i].window = None;
- CurrentSelections[i].client = NullClient;
- }
- }
- void
- MarkClientException(ClientPtr client)
- {
- client->noClientException = -1;
- }
|