PageRenderTime 84ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/nx-3.5.0/nx-X11/programs/Xserver/hw/nxagent/NXdispatch.c

#
C | 4716 lines | 3825 code | 517 blank | 374 comment | 710 complexity | cf05a9dd59d7903f2fb8c4e7f7ac2411 MD5 | raw file
Possible License(s): BSD-3-Clause, GPL-2.0, LGPL-2.0
  1. #ifdef NXAGENT_UPGRADE
  2. #include "X/NXdispatch.c"
  3. #else
  4. /**************************************************************************/
  5. /* */
  6. /* Copyright (c) 2001, 2011 NoMachine, http://www.nomachine.com/. */
  7. /* */
  8. /* NXAGENT, NX protocol compression and NX extensions to this software */
  9. /* are copyright of NoMachine. Redistribution and use of the present */
  10. /* software is allowed according to terms specified in the file LICENSE */
  11. /* which comes in the source distribution. */
  12. /* */
  13. /* Check http://www.nomachine.com/licensing.html for applicability. */
  14. /* */
  15. /* NX and NoMachine are trademarks of Medialogic S.p.A. */
  16. /* */
  17. /* All rights reserved. */
  18. /* */
  19. /**************************************************************************/
  20. /* $Xorg: dispatch.c,v 1.5 2001/02/09 02:04:40 xorgcvs Exp $ */
  21. /************************************************************
  22. Copyright 1987, 1989, 1998 The Open Group
  23. Permission to use, copy, modify, distribute, and sell this software and its
  24. documentation for any purpose is hereby granted without fee, provided that
  25. the above copyright notice appear in all copies and that both that
  26. copyright notice and this permission notice appear in supporting
  27. documentation.
  28. The above copyright notice and this permission notice shall be included in
  29. all copies or substantial portions of the Software.
  30. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  31. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  32. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  33. OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  34. AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  35. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  36. Except as contained in this notice, the name of The Open Group shall not be
  37. used in advertising or otherwise to promote the sale, use or other dealings
  38. in this Software without prior written authorization from The Open Group.
  39. Copyright 1987, 1989 by Digital Equipment Corporation, Maynard, Massachusetts.
  40. All Rights Reserved
  41. Permission to use, copy, modify, and distribute this software and its
  42. documentation for any purpose and without fee is hereby granted,
  43. provided that the above copyright notice appear in all copies and that
  44. both that copyright notice and this permission notice appear in
  45. supporting documentation, and that the name of Digital not be
  46. used in advertising or publicity pertaining to distribution of the
  47. software without specific, written prior permission.
  48. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  49. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  50. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  51. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  52. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  53. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  54. SOFTWARE.
  55. ********************************************************/
  56. /* The panoramix components contained the following notice */
  57. /****************************************************************
  58. * *
  59. * Copyright (c) Digital Equipment Corporation, 1991, 1997 *
  60. * *
  61. * All Rights Reserved. Unpublished rights reserved under *
  62. * the copyright laws of the United States. *
  63. * *
  64. * The software contained on this media is proprietary to *
  65. * and embodies the confidential technology of Digital *
  66. * Equipment Corporation. Possession, use, duplication or *
  67. * dissemination of the software and media is authorized only *
  68. * pursuant to a valid written license from Digital Equipment *
  69. * Corporation. *
  70. * *
  71. * RESTRICTED RIGHTS LEGEND Use, duplication, or disclosure *
  72. * by the U.S. Government is subject to restrictions as set *
  73. * forth in Subparagraph (c)(1)(ii) of DFARS 252.227-7013, *
  74. * or in FAR 52.227-19, as applicable. *
  75. * *
  76. *****************************************************************/
  77. /* $XFree86: xc/programs/Xserver/dix/dispatch.c,v 3.29 2003/01/12 02:44:26 dawes Exp $ */
  78. #ifdef PANORAMIX_DEBUG
  79. #include <stdio.h>
  80. int ProcInitialConnection();
  81. #endif
  82. #ifdef __sun
  83. #define False 0
  84. #define True 1
  85. #endif
  86. #define GC XlibGC
  87. #include <X11/Xlib.h>
  88. #undef GC
  89. #include "windowstr.h"
  90. #include "fontstruct.h"
  91. #include "dixfontstr.h"
  92. #include "gcstruct.h"
  93. #include "selection.h"
  94. #include "colormapst.h"
  95. #include "cursorstr.h"
  96. #include "scrnintstr.h"
  97. #include "opaque.h"
  98. #include "input.h"
  99. #include "servermd.h"
  100. #include "extnsionst.h"
  101. #include "dixfont.h"
  102. #include "../../dix/dispatch.h"
  103. #include "swaprep.h"
  104. #include "swapreq.h"
  105. #ifdef PANORAMIX
  106. #include "panoramiX.h"
  107. #include "panoramiXsrv.h"
  108. #endif
  109. #ifdef XCSECURITY
  110. #define _SECURITY_SERVER
  111. #include "security.h"
  112. #endif
  113. #ifdef XAPPGROUP
  114. #include "Xagsrv.h"
  115. #endif
  116. #ifdef XKB
  117. #define XKB_IN_SERVER
  118. #include "inputstr.h"
  119. #include "XKBsrv.h"
  120. #endif
  121. #include "Atoms.h"
  122. #include "Splash.h"
  123. #include "Client.h"
  124. #include "Clipboard.h"
  125. #include "Reconnect.h"
  126. #include "Millis.h"
  127. #include "Font.h"
  128. #include "Shadow.h"
  129. #include "Handlers.h"
  130. const int nxagentMaxFontNames = 10000;
  131. char dispatchExceptionAtReset = DE_RESET;
  132. /*
  133. * This allows the agent to exit if no
  134. * client is connected within a timeout.
  135. */
  136. int nxagentClients = 0;
  137. void nxagentWaitDisplay(void);
  138. void nxagentListRemoteFonts(const char *, int);
  139. unsigned int nxagentWMtimeout = 0;
  140. Bool nxagentWMPassed = 0;
  141. /*
  142. * Timeouts based on screen saver time.
  143. */
  144. int nxagentAutoDisconnectTimeout = 0;
  145. #ifdef LBX
  146. #include "../../lbx/lbxserve.h"
  147. #endif
  148. #include "Xatom.h"
  149. /*
  150. * Set here the required log level.
  151. */
  152. #define PANIC
  153. #define WARNING
  154. #undef TEST
  155. #undef WATCH
  156. /*
  157. * Log begin and end of the important handlers.
  158. */
  159. #undef BLOCKS
  160. #ifdef WATCH
  161. #include "unistd.h"
  162. #endif
  163. #ifdef TEST
  164. #include "Literals.h"
  165. #endif
  166. #define mskcnt ((MAXCLIENTS + 31) / 32)
  167. #define BITMASK(i) (1U << ((i) & 31))
  168. #define MASKIDX(i) ((i) >> 5)
  169. #define MASKWORD(buf, i) buf[MASKIDX(i)]
  170. #define BITSET(buf, i) MASKWORD(buf, i) |= BITMASK(i)
  171. #define BITCLEAR(buf, i) MASKWORD(buf, i) &= ~BITMASK(i)
  172. #define GETBIT(buf, i) (MASKWORD(buf, i) & BITMASK(i))
  173. extern xConnSetupPrefix connSetupPrefix;
  174. extern char *ConnectionInfo;
  175. Selection *CurrentSelections;
  176. int NumCurrentSelections;
  177. extern WindowPtr nxagentViewportFrameLeft;
  178. extern WindowPtr nxagentViewportFrameRight;
  179. extern WindowPtr nxagentViewportFrameAbove;
  180. extern WindowPtr nxagentViewportFrameBelow;
  181. #define IsViewportFrame(pWin) ((pWin) == nxagentViewportFrameLeft || \
  182. (pWin) == nxagentViewportFrameRight || \
  183. (pWin) == nxagentViewportFrameAbove || \
  184. (pWin) == nxagentViewportFrameBelow)
  185. extern int nxagentMaxAllowedResets;
  186. extern int nxagentFindClientResource(int, RESTYPE, pointer);
  187. static ClientPtr grabClient;
  188. #define GrabNone 0
  189. #define GrabActive 1
  190. #define GrabKickout 2
  191. static int grabState = GrabNone;
  192. static long grabWaiters[mskcnt];
  193. CallbackListPtr ServerGrabCallback = NULL;
  194. HWEventQueuePtr checkForInput[2];
  195. extern int connBlockScreenStart;
  196. static void KillAllClients(
  197. #if NeedFunctionPrototypes
  198. void
  199. #endif
  200. );
  201. static void DeleteClientFromAnySelections(
  202. #if NeedFunctionPrototypes
  203. ClientPtr /*client*/
  204. #endif
  205. );
  206. static int nextFreeClientID; /* always MIN free client ID */
  207. static int nClients; /* number of authorized clients */
  208. CallbackListPtr ClientStateCallback;
  209. char dispatchException = 0;
  210. char isItTimeToYield;
  211. /* Various of the DIX function interfaces were not designed to allow
  212. * the client->errorValue to be set on BadValue and other errors.
  213. * Rather than changing interfaces and breaking untold code we introduce
  214. * a new global that dispatch can use.
  215. */
  216. XID clientErrorValue; /* XXX this is a kludge */
  217. #define SAME_SCREENS(a, b) (\
  218. (a.pScreen == b.pScreen))
  219. void
  220. SetInputCheck(c0, c1)
  221. HWEventQueuePtr c0, c1;
  222. {
  223. checkForInput[0] = c0;
  224. checkForInput[1] = c1;
  225. }
  226. void
  227. UpdateCurrentTime()
  228. {
  229. TimeStamp systime;
  230. /* To avoid time running backwards, we must call GetTimeInMillis before
  231. * calling ProcessInputEvents.
  232. */
  233. systime.months = currentTime.months;
  234. systime.milliseconds = GetTimeInMillis();
  235. if (systime.milliseconds < currentTime.milliseconds)
  236. systime.months++;
  237. if (*checkForInput[0] != *checkForInput[1])
  238. ProcessInputEvents();
  239. if (CompareTimeStamps(systime, currentTime) == LATER)
  240. currentTime = systime;
  241. }
  242. /* Like UpdateCurrentTime, but can't call ProcessInputEvents */
  243. void
  244. UpdateCurrentTimeIf()
  245. {
  246. TimeStamp systime;
  247. systime.months = currentTime.months;
  248. systime.milliseconds = GetTimeInMillis();
  249. if (systime.milliseconds < currentTime.milliseconds)
  250. systime.months++;
  251. if (*checkForInput[0] == *checkForInput[1])
  252. currentTime = systime;
  253. }
  254. void
  255. InitSelections()
  256. {
  257. if (CurrentSelections)
  258. xfree(CurrentSelections);
  259. CurrentSelections = (Selection *)NULL;
  260. NumCurrentSelections = 0;
  261. #ifdef NXAGENT_CLIPBOARD
  262. {
  263. Selection *newsels;
  264. newsels = (Selection *)xalloc(2 * sizeof(Selection));
  265. if (!newsels)
  266. return;
  267. NumCurrentSelections += 2;
  268. CurrentSelections = newsels;
  269. CurrentSelections[0].selection = XA_PRIMARY;
  270. CurrentSelections[0].lastTimeChanged = ClientTimeToServerTime(0);
  271. CurrentSelections[0].window = WindowTable[0]->drawable.id;
  272. CurrentSelections[0].pWin = NULL;
  273. CurrentSelections[0].client = NullClient;
  274. CurrentSelections[1].selection = MakeAtom("CLIPBOARD", 9, 1);
  275. CurrentSelections[1].lastTimeChanged = ClientTimeToServerTime(0);
  276. CurrentSelections[1].window = WindowTable[0]->drawable.id;
  277. CurrentSelections[1].pWin = NULL;
  278. CurrentSelections[1].client = NullClient;
  279. }
  280. #endif
  281. }
  282. void
  283. FlushClientCaches(id)
  284. XID id;
  285. {
  286. int i;
  287. register ClientPtr client;
  288. client = clients[CLIENT_ID(id)];
  289. if (client == NullClient)
  290. return ;
  291. for (i=0; i<currentMaxClients; i++)
  292. {
  293. client = clients[i];
  294. if (client != NullClient)
  295. {
  296. if (client->lastDrawableID == id)
  297. {
  298. client->lastDrawableID = WindowTable[0]->drawable.id;
  299. client->lastDrawable = (DrawablePtr)WindowTable[0];
  300. }
  301. else if (client->lastGCID == id)
  302. {
  303. client->lastGCID = INVALID;
  304. client->lastGC = (GCPtr)NULL;
  305. }
  306. }
  307. }
  308. }
  309. #ifdef SMART_SCHEDULE
  310. #undef SMART_DEBUG
  311. #define SMART_SCHEDULE_DEFAULT_INTERVAL 20 /* ms */
  312. #define SMART_SCHEDULE_MAX_SLICE 200 /* ms */
  313. /*
  314. * Disable the SmartScheduler as it doesn't
  315. * seem to work for us.
  316. */
  317. Bool SmartScheduleDisable = True;
  318. long SmartScheduleSlice = SMART_SCHEDULE_DEFAULT_INTERVAL;
  319. long SmartScheduleInterval = SMART_SCHEDULE_DEFAULT_INTERVAL;
  320. long SmartScheduleMaxSlice = SMART_SCHEDULE_MAX_SLICE;
  321. long SmartScheduleTime;
  322. ClientPtr SmartLastClient;
  323. int SmartLastIndex[SMART_MAX_PRIORITY-SMART_MIN_PRIORITY+1];
  324. int SmartScheduleClient(int *clientReady, int nready);
  325. #ifdef SMART_DEBUG
  326. long SmartLastPrint;
  327. #endif
  328. void Dispatch(void);
  329. void InitProcVectors(void);
  330. int
  331. SmartScheduleClient (int *clientReady, int nready)
  332. {
  333. ClientPtr pClient;
  334. int i;
  335. int client;
  336. int bestPrio, best = 0;
  337. int bestRobin, robin;
  338. long now = SmartScheduleTime;
  339. long idle;
  340. bestPrio = -0x7fffffff;
  341. bestRobin = 0;
  342. idle = 2 * SmartScheduleSlice;
  343. for (i = 0; i < nready; i++)
  344. {
  345. client = clientReady[i];
  346. pClient = clients[client];
  347. /* Praise clients which are idle */
  348. if ((now - pClient->smart_check_tick) >= idle)
  349. {
  350. if (pClient->smart_priority < 0)
  351. pClient->smart_priority++;
  352. }
  353. pClient->smart_check_tick = now;
  354. /* check priority to select best client */
  355. robin = (pClient->index - SmartLastIndex[pClient->smart_priority-SMART_MIN_PRIORITY]) & 0xff;
  356. if (pClient->smart_priority > bestPrio ||
  357. (pClient->smart_priority == bestPrio && robin > bestRobin))
  358. {
  359. bestPrio = pClient->smart_priority;
  360. bestRobin = robin;
  361. best = client;
  362. }
  363. #ifdef SMART_DEBUG
  364. if ((now - SmartLastPrint) >= 5000)
  365. fprintf (stderr, " %2d: %3d", client, pClient->smart_priority);
  366. #endif
  367. }
  368. #ifdef SMART_DEBUG
  369. if ((now - SmartLastPrint) >= 5000)
  370. {
  371. fprintf (stderr, " use %2d\n", best);
  372. SmartLastPrint = now;
  373. }
  374. #endif
  375. pClient = clients[best];
  376. SmartLastIndex[bestPrio-SMART_MIN_PRIORITY] = pClient->index;
  377. /*
  378. * Set current client pointer
  379. */
  380. if (SmartLastClient != pClient)
  381. {
  382. pClient->smart_start_tick = now;
  383. SmartLastClient = pClient;
  384. }
  385. /*
  386. * Adjust slice
  387. */
  388. if (nready == 1)
  389. {
  390. /*
  391. * If it's been a long time since another client
  392. * has run, bump the slice up to get maximal
  393. * performance from a single client
  394. */
  395. if ((now - pClient->smart_start_tick) > 1000 &&
  396. SmartScheduleSlice < SmartScheduleMaxSlice)
  397. {
  398. SmartScheduleSlice += SmartScheduleInterval;
  399. }
  400. }
  401. else
  402. {
  403. SmartScheduleSlice = SmartScheduleInterval;
  404. }
  405. return best;
  406. }
  407. #endif
  408. #define MAJOROP ((xReq *)client->requestBuffer)->reqType
  409. void
  410. Dispatch(void)
  411. {
  412. register int *clientReady; /* array of request ready clients */
  413. register int result;
  414. register ClientPtr client;
  415. register int nready;
  416. register HWEventQueuePtr* icheck = checkForInput;
  417. #ifdef SMART_SCHEDULE
  418. int start_tick;
  419. #endif
  420. unsigned long currentDispatch = 0;
  421. nextFreeClientID = 1;
  422. InitSelections();
  423. nClients = 0;
  424. /*
  425. * The agent initialization was successfully
  426. * completed. We can now handle our clients.
  427. */
  428. if (serverGeneration > nxagentMaxAllowedResets)
  429. {
  430. fprintf(stderr, "Session: Session started at '%s'.\n", GetTimeAsString());
  431. nxagentSessionState = SESSION_UP;
  432. }
  433. #ifdef NXAGENT_ONSTART
  434. /*
  435. * Set NX_WM property (used by NX client to identify
  436. * the agent's window) three seconds since the first
  437. * client connects.
  438. */
  439. nxagentWMtimeout = GetTimeInMillis() + 3000;
  440. #endif
  441. clientReady = (int *) ALLOCATE_LOCAL(sizeof(int) * MaxClients);
  442. if (!clientReady)
  443. return;
  444. #ifdef WATCH
  445. fprintf(stderr, "Dispatch: Watchpoint 12.\n");
  446. /*
  447. Reply Total Cached Bits In Bits Out Bits/Reply Ratio
  448. ------- ----- ------ ------- -------- ---------- -----
  449. #3 1 352 bits (0 KB) -> 236 bits (0 KB) -> 352/1 -> 236/1 = 1.492:1
  450. #14 1 256 bits (0 KB) -> 101 bits (0 KB) -> 256/1 -> 101/1 = 2.535:1
  451. #16 1 256 bits (0 KB) -> 26 bits (0 KB) -> 256/1 -> 26/1 = 9.846:1
  452. #20 2 2 12256 bits (1 KB) -> 56 bits (0 KB) -> 6128/1 -> 28/1 = 218.857:1
  453. #43 1 256 bits (0 KB) -> 45 bits (0 KB) -> 256/1 -> 45/1 = 5.689:1
  454. #47 2 2 42304 bits (5 KB) -> 49 bits (0 KB) -> 21152/1 -> 24/1 = 863.347:1
  455. #98 1 256 bits (0 KB) -> 34 bits (0 KB) -> 256/1 -> 34/1 = 7.529:1
  456. */
  457. sleep(30);
  458. #endif
  459. #ifdef TEST
  460. fprintf(stderr, "Dispatch: Value of dispatchException is [%x].\n",
  461. dispatchException);
  462. fprintf(stderr, "Dispatch: Value of dispatchExceptionAtReset is [%x].\n",
  463. dispatchExceptionAtReset);
  464. #endif
  465. if (!(dispatchException & DE_TERMINATE))
  466. dispatchException = 0;
  467. while (!dispatchException)
  468. {
  469. if (*icheck[0] != *icheck[1])
  470. {
  471. ProcessInputEvents();
  472. FlushIfCriticalOutputPending();
  473. }
  474. /*
  475. * Ensure we remove the splash after the timeout.
  476. * Initializing clientReady[0] to -1 will tell
  477. * WaitForSomething() to yield control after the
  478. * timeout set in clientReady[1].
  479. */
  480. clientReady[0] = 0;
  481. if (nxagentSplashWindow != None || (nxagentOption(Xdmcp) == 1 && nxagentXdmcpUp == 0))
  482. {
  483. #ifdef TEST
  484. fprintf(stderr, "******Dispatch: Requesting a timeout of [%d] Ms.\n",
  485. NXAGENT_WAKEUP);
  486. #endif
  487. clientReady[0] = -1;
  488. clientReady[1] = NXAGENT_WAKEUP;
  489. }
  490. #ifdef BLOCKS
  491. fprintf(stderr, "[End dispatch]\n");
  492. #endif
  493. nready = WaitForSomething(clientReady);
  494. #ifdef BLOCKS
  495. fprintf(stderr, "[Begin dispatch]\n");
  496. #endif
  497. #ifdef TEST
  498. fprintf(stderr, "******Dispatch: Running with [%d] clients ready.\n",
  499. nready);
  500. #endif
  501. #ifdef NXAGENT_ONSTART
  502. currentDispatch = GetTimeInMillis();
  503. /*
  504. * If the timeout is expired set the
  505. * selection informing the NX client
  506. * that the agent is ready.
  507. */
  508. if (!nxagentWMPassed && (nxagentWMtimeout < currentDispatch))
  509. {
  510. nxagentRemoveSplashWindow(NULL);
  511. }
  512. nxagentClients = nClients;
  513. #endif
  514. #ifdef SMART_SCHEDULE
  515. if (nready && !SmartScheduleDisable)
  516. {
  517. clientReady[0] = SmartScheduleClient (clientReady, nready);
  518. nready = 1;
  519. }
  520. #endif
  521. /*****************
  522. * Handle events in round robin fashion, doing input between
  523. * each round
  524. *****************/
  525. while (!dispatchException && (--nready >= 0))
  526. {
  527. client = clients[clientReady[nready]];
  528. if (! client)
  529. {
  530. /* KillClient can cause this to happen */
  531. continue;
  532. }
  533. /* GrabServer activation can cause this to be true */
  534. if (grabState == GrabKickout)
  535. {
  536. grabState = GrabActive;
  537. break;
  538. }
  539. isItTimeToYield = FALSE;
  540. requestingClient = client;
  541. #ifdef SMART_SCHEDULE
  542. start_tick = SmartScheduleTime;
  543. #endif
  544. while (!isItTimeToYield)
  545. {
  546. if (*icheck[0] != *icheck[1])
  547. {
  548. ProcessInputEvents();
  549. FlushIfCriticalOutputPending();
  550. }
  551. #ifdef SMART_SCHEDULE
  552. if (!SmartScheduleDisable &&
  553. (SmartScheduleTime - start_tick) >= SmartScheduleSlice)
  554. {
  555. /* Penalize clients which consume ticks */
  556. if (client->smart_priority > SMART_MIN_PRIORITY)
  557. client->smart_priority--;
  558. break;
  559. }
  560. #endif
  561. /* now, finally, deal with client requests */
  562. #ifdef TEST
  563. fprintf(stderr, "******Dispatch: Reading request from client [%d].\n",
  564. client->index);
  565. #endif
  566. result = ReadRequestFromClient(client);
  567. if (result <= 0)
  568. {
  569. if (result < 0)
  570. CloseDownClient(client);
  571. break;
  572. }
  573. #ifdef NXAGENT_SERVER
  574. #ifdef TEST
  575. else
  576. {
  577. if (MAJOROP > 127)
  578. {
  579. fprintf(stderr, "******Dispatch: Read [Extension] request OPCODE#%d MINOR#%d "
  580. "size [%d] client [%d].\n", MAJOROP, *((char *) client->requestBuffer + 1),
  581. client->req_len << 2, client->index);
  582. }
  583. else
  584. {
  585. fprintf(stderr, "******Dispatch: Read [%s] request OPCODE#%d size [%d] client [%d].\n",
  586. nxagentRequestLiteral[MAJOROP], MAJOROP, client->req_len << 2,
  587. client->index);
  588. }
  589. }
  590. #endif
  591. #endif
  592. client->sequence++;
  593. #ifdef DEBUG
  594. if (client->requestLogIndex == MAX_REQUEST_LOG)
  595. client->requestLogIndex = 0;
  596. client->requestLog[client->requestLogIndex] = MAJOROP;
  597. client->requestLogIndex++;
  598. #endif
  599. if (result > (MAX_BIG_REQUEST_SIZE << 2))
  600. result = BadLength;
  601. else
  602. #ifdef NXAGENT_SERVER
  603. {
  604. result = (* client->requestVector[MAJOROP])(client);
  605. #ifdef TEST
  606. if (MAJOROP > 127)
  607. {
  608. fprintf(stderr, "******Dispatch: Handled [Extension] request OPCODE#%d MINOR#%d "
  609. "size [%d] client [%d] result [%d].\n", MAJOROP,
  610. *((char *) client->requestBuffer + 1), client->req_len << 2,
  611. client->index, result);
  612. }
  613. else
  614. {
  615. fprintf(stderr, "******Dispatch: Handled [%s] request OPCODE#%d size [%d] client [%d] "
  616. "result [%d].\n", nxagentRequestLiteral[MAJOROP], MAJOROP,
  617. client->req_len << 2, client->index, result);
  618. }
  619. #endif
  620. /*
  621. * Can set isItTimeToYield to force
  622. * the dispatcher to pay attention
  623. * to another client.
  624. */
  625. nxagentDispatchHandler(client, client->req_len << 2, 0);
  626. }
  627. #else
  628. result = (* client->requestVector[MAJOROP])(client);
  629. #endif
  630. if (result != Success)
  631. {
  632. if (client->noClientException != Success)
  633. CloseDownClient(client);
  634. else
  635. SendErrorToClient(client, MAJOROP,
  636. MinorOpcodeOfRequest(client),
  637. client->errorValue, result);
  638. break;
  639. }
  640. }
  641. FlushAllOutput();
  642. #ifdef SMART_SCHEDULE
  643. client = clients[clientReady[nready]];
  644. if (client)
  645. client->smart_stop_tick = SmartScheduleTime;
  646. #endif
  647. requestingClient = NULL;
  648. }
  649. dispatchException &= ~DE_PRIORITYCHANGE;
  650. }
  651. if ((dispatchException & DE_RESET) &&
  652. (serverGeneration > nxagentMaxAllowedResets))
  653. {
  654. dispatchException &= ~DE_RESET;
  655. dispatchException |= DE_TERMINATE;
  656. fprintf(stderr, "Info: Reached threshold of maximum allowed resets.\n");
  657. }
  658. nxagentResetAtomMap();
  659. if (serverGeneration > nxagentMaxAllowedResets)
  660. {
  661. /*
  662. * The session is terminating. Force an I/O
  663. * error on the display and wait until the
  664. * NX transport is gone.
  665. */
  666. fprintf(stderr, "Session: Terminating session at '%s'.\n", GetTimeAsString());
  667. nxagentWaitDisplay();
  668. fprintf(stderr, "Session: Session terminated at '%s'.\n", GetTimeAsString());
  669. }
  670. if (nxagentOption(Shadow))
  671. {
  672. NXShadowDestroy();
  673. }
  674. KillAllClients();
  675. DEALLOCATE_LOCAL(clientReady);
  676. dispatchException &= ~DE_RESET;
  677. }
  678. #undef MAJOROP
  679. /*ARGSUSED*/
  680. int
  681. ProcBadRequest(client)
  682. ClientPtr client;
  683. {
  684. return (BadRequest);
  685. }
  686. int
  687. ProcCreateWindow(client)
  688. register ClientPtr client;
  689. {
  690. register WindowPtr pParent, pWin;
  691. REQUEST(xCreateWindowReq);
  692. int result;
  693. int len;
  694. REQUEST_AT_LEAST_SIZE(xCreateWindowReq);
  695. LEGAL_NEW_RESOURCE(stuff->wid, client);
  696. if (!(pParent = (WindowPtr)SecurityLookupWindow(stuff->parent, client,
  697. SecurityWriteAccess)))
  698. return BadWindow;
  699. len = client->req_len - (sizeof(xCreateWindowReq) >> 2);
  700. if (Ones(stuff->mask) != len)
  701. return BadLength;
  702. if (!stuff->width || !stuff->height)
  703. {
  704. client->errorValue = 0;
  705. return BadValue;
  706. }
  707. pWin = CreateWindow(stuff->wid, pParent, stuff->x,
  708. stuff->y, stuff->width, stuff->height,
  709. stuff->borderWidth, stuff->class,
  710. stuff->mask, (XID *) &stuff[1],
  711. (int)stuff->depth,
  712. client, stuff->visual, &result);
  713. if (pWin)
  714. {
  715. Mask mask = pWin->eventMask;
  716. pWin->eventMask = 0; /* subterfuge in case AddResource fails */
  717. if (!AddResource(stuff->wid, RT_WINDOW, (pointer)pWin))
  718. return BadAlloc;
  719. pWin->eventMask = mask;
  720. }
  721. if (client->noClientException != Success)
  722. return(client->noClientException);
  723. else
  724. return(result);
  725. }
  726. int
  727. ProcChangeWindowAttributes(client)
  728. register ClientPtr client;
  729. {
  730. register WindowPtr pWin;
  731. REQUEST(xChangeWindowAttributesReq);
  732. register int result;
  733. int len;
  734. REQUEST_AT_LEAST_SIZE(xChangeWindowAttributesReq);
  735. pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client,
  736. SecurityWriteAccess);
  737. if (!pWin)
  738. return(BadWindow);
  739. len = client->req_len - (sizeof(xChangeWindowAttributesReq) >> 2);
  740. if (len != Ones(stuff->valueMask))
  741. return BadLength;
  742. result = ChangeWindowAttributes(pWin,
  743. stuff->valueMask,
  744. (XID *) &stuff[1],
  745. client);
  746. if (client->noClientException != Success)
  747. return(client->noClientException);
  748. else
  749. return(result);
  750. }
  751. int
  752. ProcGetWindowAttributes(client)
  753. register ClientPtr client;
  754. {
  755. register WindowPtr pWin;
  756. REQUEST(xResourceReq);
  757. xGetWindowAttributesReply wa;
  758. REQUEST_SIZE_MATCH(xResourceReq);
  759. pWin = (WindowPtr)SecurityLookupWindow(stuff->id, client,
  760. SecurityReadAccess);
  761. if (!pWin)
  762. return(BadWindow);
  763. GetWindowAttributes(pWin, client, &wa);
  764. WriteReplyToClient(client, sizeof(xGetWindowAttributesReply), &wa);
  765. return(client->noClientException);
  766. }
  767. int
  768. ProcDestroyWindow(client)
  769. register ClientPtr client;
  770. {
  771. register WindowPtr pWin;
  772. REQUEST(xResourceReq);
  773. REQUEST_SIZE_MATCH(xResourceReq);
  774. pWin = (WindowPtr)SecurityLookupWindow(stuff->id, client,
  775. SecurityDestroyAccess);
  776. if (!pWin)
  777. return(BadWindow);
  778. if (pWin->parent)
  779. FreeResource(stuff->id, RT_NONE);
  780. return(client->noClientException);
  781. }
  782. int
  783. ProcDestroySubwindows(client)
  784. register ClientPtr client;
  785. {
  786. register WindowPtr pWin;
  787. REQUEST(xResourceReq);
  788. REQUEST_SIZE_MATCH(xResourceReq);
  789. pWin = (WindowPtr)SecurityLookupWindow(stuff->id, client,
  790. SecurityDestroyAccess);
  791. if (!pWin)
  792. return(BadWindow);
  793. DestroySubwindows(pWin, client);
  794. return(client->noClientException);
  795. }
  796. int
  797. ProcChangeSaveSet(client)
  798. register ClientPtr client;
  799. {
  800. register WindowPtr pWin;
  801. REQUEST(xChangeSaveSetReq);
  802. register int result;
  803. REQUEST_SIZE_MATCH(xChangeSaveSetReq);
  804. pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client,
  805. SecurityReadAccess);
  806. if (!pWin)
  807. return(BadWindow);
  808. if (client->clientAsMask == (CLIENT_BITS(pWin->drawable.id)))
  809. return BadMatch;
  810. if ((stuff->mode == SetModeInsert) || (stuff->mode == SetModeDelete))
  811. {
  812. result = AlterSaveSetForClient(client, pWin, stuff->mode);
  813. if (client->noClientException != Success)
  814. return(client->noClientException);
  815. else
  816. return(result);
  817. }
  818. else
  819. {
  820. client->errorValue = stuff->mode;
  821. return( BadValue );
  822. }
  823. }
  824. int
  825. ProcReparentWindow(client)
  826. register ClientPtr client;
  827. {
  828. register WindowPtr pWin, pParent;
  829. REQUEST(xReparentWindowReq);
  830. register int result;
  831. REQUEST_SIZE_MATCH(xReparentWindowReq);
  832. pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client,
  833. SecurityWriteAccess);
  834. if (!pWin)
  835. return(BadWindow);
  836. if (!nxagentWMPassed)
  837. {
  838. nxagentRemoveSplashWindow(pWin);
  839. }
  840. pParent = (WindowPtr)SecurityLookupWindow(stuff->parent, client,
  841. SecurityWriteAccess);
  842. if (!pParent)
  843. return(BadWindow);
  844. if (SAME_SCREENS(pWin->drawable, pParent->drawable))
  845. {
  846. if ((pWin->backgroundState == ParentRelative) &&
  847. (pParent->drawable.depth != pWin->drawable.depth))
  848. return BadMatch;
  849. if ((pWin->drawable.class != InputOnly) &&
  850. (pParent->drawable.class == InputOnly))
  851. return BadMatch;
  852. result = ReparentWindow(pWin, pParent,
  853. (short)stuff->x, (short)stuff->y, client);
  854. if (client->noClientException != Success)
  855. return(client->noClientException);
  856. else
  857. return(result);
  858. }
  859. else
  860. return (BadMatch);
  861. }
  862. int
  863. ProcMapWindow(client)
  864. register ClientPtr client;
  865. {
  866. register WindowPtr pWin;
  867. REQUEST(xResourceReq);
  868. REQUEST_SIZE_MATCH(xResourceReq);
  869. pWin = (WindowPtr)SecurityLookupWindow(stuff->id, client,
  870. SecurityReadAccess);
  871. if (!pWin)
  872. return(BadWindow);
  873. MapWindow(pWin, client);
  874. /* update cache to say it is mapped */
  875. return(client->noClientException);
  876. }
  877. int
  878. ProcMapSubwindows(client)
  879. register ClientPtr client;
  880. {
  881. register WindowPtr pWin;
  882. REQUEST(xResourceReq);
  883. REQUEST_SIZE_MATCH(xResourceReq);
  884. pWin = (WindowPtr)SecurityLookupWindow( stuff->id, client,
  885. SecurityReadAccess);
  886. if (!pWin)
  887. return(BadWindow);
  888. MapSubwindows(pWin, client);
  889. /* update cache to say it is mapped */
  890. return(client->noClientException);
  891. }
  892. int
  893. ProcUnmapWindow(client)
  894. register ClientPtr client;
  895. {
  896. register WindowPtr pWin;
  897. REQUEST(xResourceReq);
  898. REQUEST_SIZE_MATCH(xResourceReq);
  899. pWin = (WindowPtr)SecurityLookupWindow( stuff->id, client,
  900. SecurityReadAccess);
  901. if (!pWin)
  902. return(BadWindow);
  903. UnmapWindow(pWin, FALSE);
  904. /* update cache to say it is mapped */
  905. return(client->noClientException);
  906. }
  907. int
  908. ProcUnmapSubwindows(client)
  909. register ClientPtr client;
  910. {
  911. register WindowPtr pWin;
  912. REQUEST(xResourceReq);
  913. REQUEST_SIZE_MATCH(xResourceReq);
  914. pWin = (WindowPtr)SecurityLookupWindow( stuff->id, client,
  915. SecurityReadAccess);
  916. if (!pWin)
  917. return(BadWindow);
  918. UnmapSubwindows(pWin);
  919. return(client->noClientException);
  920. }
  921. int
  922. ProcConfigureWindow(client)
  923. register ClientPtr client;
  924. {
  925. register WindowPtr pWin;
  926. REQUEST(xConfigureWindowReq);
  927. register int result;
  928. int len;
  929. REQUEST_AT_LEAST_SIZE(xConfigureWindowReq);
  930. pWin = (WindowPtr)SecurityLookupWindow( stuff->window, client,
  931. SecurityWriteAccess);
  932. if (!pWin)
  933. return(BadWindow);
  934. len = client->req_len - (sizeof(xConfigureWindowReq) >> 2);
  935. if (Ones((Mask)stuff->mask) != len)
  936. return BadLength;
  937. result = ConfigureWindow(pWin, (Mask)stuff->mask, (XID *) &stuff[1],
  938. client);
  939. if (client->noClientException != Success)
  940. return(client->noClientException);
  941. else
  942. return(result);
  943. }
  944. int
  945. ProcCirculateWindow(client)
  946. register ClientPtr client;
  947. {
  948. register WindowPtr pWin;
  949. REQUEST(xCirculateWindowReq);
  950. REQUEST_SIZE_MATCH(xCirculateWindowReq);
  951. if ((stuff->direction != RaiseLowest) &&
  952. (stuff->direction != LowerHighest))
  953. {
  954. client->errorValue = stuff->direction;
  955. return BadValue;
  956. }
  957. pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client,
  958. SecurityWriteAccess);
  959. if (!pWin)
  960. return(BadWindow);
  961. CirculateWindow(pWin, (int)stuff->direction, client);
  962. return(client->noClientException);
  963. }
  964. int
  965. GetGeometry(client, rep)
  966. register ClientPtr client;
  967. xGetGeometryReply *rep;
  968. {
  969. register DrawablePtr pDraw;
  970. REQUEST(xResourceReq);
  971. REQUEST_SIZE_MATCH(xResourceReq);
  972. SECURITY_VERIFY_GEOMETRABLE (pDraw, stuff->id, client, SecurityReadAccess);
  973. rep->type = X_Reply;
  974. rep->length = 0;
  975. rep->sequenceNumber = client->sequence;
  976. rep->root = WindowTable[pDraw->pScreen->myNum]->drawable.id;
  977. rep->depth = pDraw->depth;
  978. rep->width = pDraw->width;
  979. rep->height = pDraw->height;
  980. /* XXX - Because the pixmap-implementation of the multibuffer extension
  981. * may have the buffer-id's drawable resource value be a pointer
  982. * to the buffer's window instead of the buffer itself
  983. * (this happens if the buffer is the displayed buffer),
  984. * we also have to check that the id matches before we can
  985. * truly say that it is a DRAWABLE_WINDOW.
  986. */
  987. if ((pDraw->type == UNDRAWABLE_WINDOW) ||
  988. ((pDraw->type == DRAWABLE_WINDOW) && (stuff->id == pDraw->id)))
  989. {
  990. register WindowPtr pWin = (WindowPtr)pDraw;
  991. rep->x = pWin->origin.x - wBorderWidth (pWin);
  992. rep->y = pWin->origin.y - wBorderWidth (pWin);
  993. rep->borderWidth = pWin->borderWidth;
  994. }
  995. else /* DRAWABLE_PIXMAP or DRAWABLE_BUFFER */
  996. {
  997. rep->x = rep->y = rep->borderWidth = 0;
  998. }
  999. return Success;
  1000. }
  1001. int
  1002. ProcGetGeometry(client)
  1003. register ClientPtr client;
  1004. {
  1005. xGetGeometryReply rep;
  1006. int status;
  1007. if ((status = GetGeometry(client, &rep)) != Success)
  1008. return status;
  1009. WriteReplyToClient(client, sizeof(xGetGeometryReply), &rep);
  1010. return(client->noClientException);
  1011. }
  1012. int
  1013. ProcQueryTree(client)
  1014. register ClientPtr client;
  1015. {
  1016. xQueryTreeReply reply;
  1017. int numChildren = 0;
  1018. register WindowPtr pChild, pWin, pHead;
  1019. Window *childIDs = (Window *)NULL;
  1020. REQUEST(xResourceReq);
  1021. REQUEST_SIZE_MATCH(xResourceReq);
  1022. pWin = (WindowPtr)SecurityLookupWindow(stuff->id, client,
  1023. SecurityReadAccess);
  1024. if (!pWin)
  1025. return(BadWindow);
  1026. reply.type = X_Reply;
  1027. reply.root = WindowTable[pWin->drawable.pScreen->myNum]->drawable.id;
  1028. reply.sequenceNumber = client->sequence;
  1029. if (pWin->parent)
  1030. reply.parent = pWin->parent->drawable.id;
  1031. else
  1032. reply.parent = (Window)None;
  1033. pHead = RealChildHead(pWin);
  1034. for (pChild = pWin->lastChild; pChild != pHead; pChild = pChild->prevSib)
  1035. {
  1036. if (!IsViewportFrame(pChild))
  1037. {
  1038. numChildren++;
  1039. }
  1040. }
  1041. if (numChildren)
  1042. {
  1043. int curChild = 0;
  1044. childIDs = (Window *) ALLOCATE_LOCAL(numChildren * sizeof(Window));
  1045. if (!childIDs)
  1046. return BadAlloc;
  1047. for (pChild = pWin->lastChild; pChild != pHead; pChild = pChild->prevSib)
  1048. {
  1049. if (!IsViewportFrame(pChild))
  1050. {
  1051. childIDs[curChild++] = pChild->drawable.id;
  1052. }
  1053. }
  1054. }
  1055. reply.nChildren = numChildren;
  1056. reply.length = (numChildren * sizeof(Window)) >> 2;
  1057. WriteReplyToClient(client, sizeof(xQueryTreeReply), &reply);
  1058. if (numChildren)
  1059. {
  1060. client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write;
  1061. WriteSwappedDataToClient(client, numChildren * sizeof(Window), childIDs);
  1062. DEALLOCATE_LOCAL(childIDs);
  1063. }
  1064. return(client->noClientException);
  1065. }
  1066. int
  1067. ProcInternAtom(client)
  1068. register ClientPtr client;
  1069. {
  1070. Atom atom;
  1071. char *tchar;
  1072. REQUEST(xInternAtomReq);
  1073. REQUEST_FIXED_SIZE(xInternAtomReq, stuff->nbytes);
  1074. if ((stuff->onlyIfExists != xTrue) && (stuff->onlyIfExists != xFalse))
  1075. {
  1076. client->errorValue = stuff->onlyIfExists;
  1077. return(BadValue);
  1078. }
  1079. tchar = (char *) &stuff[1];
  1080. atom = MakeAtom(tchar, stuff->nbytes, !stuff->onlyIfExists);
  1081. if (atom != BAD_RESOURCE)
  1082. {
  1083. xInternAtomReply reply;
  1084. reply.type = X_Reply;
  1085. reply.length = 0;
  1086. reply.sequenceNumber = client->sequence;
  1087. reply.atom = atom;
  1088. WriteReplyToClient(client, sizeof(xInternAtomReply), &reply);
  1089. return(client->noClientException);
  1090. }
  1091. else
  1092. return (BadAlloc);
  1093. }
  1094. int
  1095. ProcGetAtomName(client)
  1096. register ClientPtr client;
  1097. {
  1098. char *str;
  1099. xGetAtomNameReply reply;
  1100. int len;
  1101. REQUEST(xResourceReq);
  1102. REQUEST_SIZE_MATCH(xResourceReq);
  1103. if ( (str = NameForAtom(stuff->id)) )
  1104. {
  1105. len = strlen(str);
  1106. reply.type = X_Reply;
  1107. reply.length = (len + 3) >> 2;
  1108. reply.sequenceNumber = client->sequence;
  1109. reply.nameLength = len;
  1110. WriteReplyToClient(client, sizeof(xGetAtomNameReply), &reply);
  1111. (void)WriteToClient(client, len, str);
  1112. return(client->noClientException);
  1113. }
  1114. else
  1115. {
  1116. client->errorValue = stuff->id;
  1117. return (BadAtom);
  1118. }
  1119. }
  1120. #ifdef K5AUTH
  1121. extern int k5_bad();
  1122. #endif
  1123. int
  1124. ProcSetSelectionOwner(client)
  1125. register ClientPtr client;
  1126. {
  1127. WindowPtr pWin;
  1128. TimeStamp time;
  1129. REQUEST(xSetSelectionOwnerReq);
  1130. REQUEST_SIZE_MATCH(xSetSelectionOwnerReq);
  1131. UpdateCurrentTime();
  1132. time = ClientTimeToServerTime(stuff->time);
  1133. /* If the client's time stamp is in the future relative to the server's
  1134. time stamp, do not set the selection, just return success. */
  1135. if (CompareTimeStamps(time, currentTime) == LATER)
  1136. return Success;
  1137. if (stuff->window != None)
  1138. {
  1139. pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client,
  1140. SecurityReadAccess);
  1141. if (!pWin)
  1142. return(BadWindow);
  1143. }
  1144. else
  1145. pWin = (WindowPtr)None;
  1146. if (ValidAtom(stuff->selection))
  1147. {
  1148. int i = 0;
  1149. /*
  1150. * First, see if the selection is already set...
  1151. */
  1152. while ((i < NumCurrentSelections) &&
  1153. CurrentSelections[i].selection != stuff->selection)
  1154. i++;
  1155. if (i < NumCurrentSelections)
  1156. {
  1157. xEvent event;
  1158. /* If the timestamp in client's request is in the past relative
  1159. to the time stamp indicating the last time the owner of the
  1160. selection was set, do not set the selection, just return
  1161. success. */
  1162. if (CompareTimeStamps(time, CurrentSelections[i].lastTimeChanged)
  1163. == EARLIER)
  1164. return Success;
  1165. if (CurrentSelections[i].client &&
  1166. (!pWin || (CurrentSelections[i].client != client)))
  1167. {
  1168. event.u.u.type = SelectionClear;
  1169. event.u.selectionClear.time = time.milliseconds;
  1170. event.u.selectionClear.window = CurrentSelections[i].window;
  1171. event.u.selectionClear.atom = CurrentSelections[i].selection;
  1172. (void) TryClientEvents (CurrentSelections[i].client, &event, 1,
  1173. NoEventMask, NoEventMask /* CantBeFiltered */,
  1174. NullGrab);
  1175. }
  1176. }
  1177. else
  1178. {
  1179. /*
  1180. * It doesn't exist, so add it...
  1181. */
  1182. Selection *newsels;
  1183. if (i == 0)
  1184. newsels = (Selection *)xalloc(sizeof(Selection));
  1185. else
  1186. newsels = (Selection *)xrealloc(CurrentSelections,
  1187. (NumCurrentSelections + 1) * sizeof(Selection));
  1188. if (!newsels)
  1189. return BadAlloc;
  1190. NumCurrentSelections++;
  1191. CurrentSelections = newsels;
  1192. CurrentSelections[i].selection = stuff->selection;
  1193. }
  1194. CurrentSelections[i].lastTimeChanged = time;
  1195. CurrentSelections[i].window = stuff->window;
  1196. CurrentSelections[i].pWin = pWin;
  1197. CurrentSelections[i].client = (pWin ? client : NullClient);
  1198. #ifdef NXAGENT_CLIPBOARD
  1199. if ((CurrentSelections[i].pWin != NULL) &&
  1200. (nxagentOption(Clipboard) != ClipboardNone) &&
  1201. ((CurrentSelections[i].selection == XA_PRIMARY) ||
  1202. (CurrentSelections[i].selection == MakeAtom("CLIPBOARD", 9, 0))))
  1203. {
  1204. nxagentSetSelectionOwner(&CurrentSelections[i]);
  1205. }
  1206. #endif
  1207. return (client->noClientException);
  1208. }
  1209. else
  1210. {
  1211. client->errorValue = stuff->selection;
  1212. return (BadAtom);
  1213. }
  1214. }
  1215. int
  1216. ProcGetSelectionOwner(client)
  1217. register ClientPtr client;
  1218. {
  1219. REQUEST(xResourceReq);
  1220. REQUEST_SIZE_MATCH(xResourceReq);
  1221. if (ValidAtom(stuff->id))
  1222. {
  1223. int i;
  1224. xGetSelectionOwnerReply reply;
  1225. i = 0;
  1226. while ((i < NumCurrentSelections) &&
  1227. CurrentSelections[i].selection != stuff->id) i++;
  1228. reply.type = X_Reply;
  1229. reply.length = 0;
  1230. reply.sequenceNumber = client->sequence;
  1231. if (i < NumCurrentSelections)
  1232. reply.owner = CurrentSelections[i].window;
  1233. else
  1234. reply.owner = None;
  1235. WriteReplyToClient(client, sizeof(xGetSelectionOwnerReply), &reply);
  1236. return(client->noClientException);
  1237. }
  1238. else
  1239. {
  1240. client->errorValue = stuff->id;
  1241. return (BadAtom);
  1242. }
  1243. }
  1244. int
  1245. ProcConvertSelection(client)
  1246. register ClientPtr client;
  1247. {
  1248. Bool paramsOkay;
  1249. xEvent event;
  1250. WindowPtr pWin;
  1251. REQUEST(xConvertSelectionReq);
  1252. REQUEST_SIZE_MATCH(xConvertSelectionReq);
  1253. pWin = (WindowPtr)SecurityLookupWindow(stuff->requestor, client,
  1254. SecurityReadAccess);
  1255. if (!pWin)
  1256. return(BadWindow);
  1257. #ifdef NXAGENT_CLIPBOARD
  1258. if (((stuff->selection == XA_PRIMARY) ||
  1259. (stuff->selection == MakeAtom("CLIPBOARD", 9, 0))) &&
  1260. nxagentOption(Clipboard) != ClipboardNone)
  1261. {
  1262. int i = 0;
  1263. while ((i < NumCurrentSelections) &&
  1264. CurrentSelections[i].selection != stuff->selection) i++;
  1265. if ((i < NumCurrentSelections) && (CurrentSelections[i].window != None))
  1266. {
  1267. if (nxagentConvertSelection(client, pWin, stuff->selection, stuff->requestor,
  1268. stuff->property, stuff->target, stuff->time))
  1269. {
  1270. return (client->noClientException);
  1271. }
  1272. }
  1273. }
  1274. #endif
  1275. paramsOkay = (ValidAtom(stuff->selection) && ValidAtom(stuff->target));
  1276. if (stuff->property != None)
  1277. paramsOkay &= ValidAtom(stuff->property);
  1278. if (paramsOkay)
  1279. {
  1280. int i;
  1281. i = 0;
  1282. while ((i < NumCurrentSelections) &&
  1283. CurrentSelections[i].selection != stuff->selection) i++;
  1284. if ((i < NumCurrentSelections) &&
  1285. (CurrentSelections[i].window != None) && (CurrentSelections[i].client != NullClient)
  1286. #ifdef XCSECURITY
  1287. && (!client->CheckAccess ||
  1288. (* client->CheckAccess)(client, CurrentSelections[i].window,
  1289. RT_WINDOW, SecurityReadAccess,
  1290. CurrentSelections[i].pWin))
  1291. #endif
  1292. )
  1293. {
  1294. event.u.u.type = SelectionRequest;
  1295. event.u.selectionRequest.time = stuff->time;
  1296. event.u.selectionRequest.owner =
  1297. CurrentSelections[i].window;
  1298. event.u.selectionRequest.requestor = stuff->requestor;
  1299. event.u.selectionRequest.selection = stuff->selection;
  1300. event.u.selectionRequest.target = stuff->target;
  1301. event.u.selectionRequest.property = stuff->property;
  1302. if (TryClientEvents(
  1303. CurrentSelections[i].client, &event, 1, NoEventMask,
  1304. NoEventMask /* CantBeFiltered */, NullGrab))
  1305. return (client->noClientException);
  1306. }
  1307. event.u.u.type = SelectionNotify;
  1308. event.u.selectionNotify.time = stuff->time;
  1309. event.u.selectionNotify.requestor = stuff->requestor;
  1310. event.u.selectionNotify.selection = stuff->selection;
  1311. event.u.selectionNotify.target = stuff->target;
  1312. event.u.selectionNotify.property = None;
  1313. (void) TryClientEvents(client, &event, 1, NoEventMask,
  1314. NoEventMask /* CantBeFiltered */, NullGrab);
  1315. return (client->noClientException);
  1316. }
  1317. else
  1318. {
  1319. client->errorValue = stuff->property;
  1320. return (BadAtom);
  1321. }
  1322. }
  1323. int
  1324. ProcGrabServer(client)
  1325. register ClientPtr client;
  1326. {
  1327. REQUEST_SIZE_MATCH(xReq);
  1328. if (grabState != GrabNone && client != grabClient)
  1329. {
  1330. ResetCurrentRequest(client);
  1331. client->sequence--;
  1332. BITSET(grabWaiters, client->index);
  1333. IgnoreClient(client);
  1334. return(client->noClientException);
  1335. }
  1336. OnlyListenToOneClient(client);
  1337. grabState = GrabKickout;
  1338. grabClient = client;
  1339. if (ServerGrabCallback)
  1340. {
  1341. ServerGrabInfoRec grabinfo;
  1342. grabinfo.client = client;
  1343. grabinfo.grabstate = SERVER_GRABBED;
  1344. CallCallbacks(&ServerGrabCallback, (pointer)&grabinfo);
  1345. }
  1346. return(client->noClientException);
  1347. }
  1348. static void
  1349. #if NeedFunctionPrototypes
  1350. UngrabServer(ClientPtr client)
  1351. #else
  1352. UngrabServer(client)
  1353. ClientPtr client;
  1354. #endif
  1355. {
  1356. int i;
  1357. grabState = GrabNone;
  1358. ListenToAllClients();
  1359. for (i = mskcnt; --i >= 0 && !grabWaiters[i]; )
  1360. ;
  1361. if (i >= 0)
  1362. {
  1363. i <<= 5;
  1364. while (!GETBIT(grabWaiters, i))
  1365. i++;
  1366. BITCLEAR(grabWaiters, i);
  1367. AttendClient(clients[i]);
  1368. }
  1369. if (ServerGrabCallback)
  1370. {
  1371. ServerGrabInfoRec grabinfo;
  1372. grabinfo.client = client;
  1373. grabinfo.grabstate = SERVER_UNGRABBED;
  1374. CallCallbacks(&ServerGrabCallback, (pointer)&grabinfo);
  1375. }
  1376. }
  1377. int
  1378. ProcUngrabServer(client)
  1379. register ClientPtr client;
  1380. {
  1381. REQUEST_SIZE_MATCH(xReq);
  1382. UngrabServer(client);
  1383. return(client->noClientException);
  1384. }
  1385. int
  1386. ProcTranslateCoords(client)
  1387. register ClientPtr client;
  1388. {
  1389. REQUEST(xTranslateCoordsReq);
  1390. register WindowPtr pWin, pDst;
  1391. xTranslateCoordsReply rep;
  1392. REQUEST_SIZE_MATCH(xTranslateCoordsReq);
  1393. pWin = (WindowPtr)SecurityLookupWindow(stuff->srcWid, client,
  1394. SecurityReadAccess);
  1395. if (!pWin)
  1396. return(BadWindow);
  1397. pDst = (WindowPtr)SecurityLookupWindow(stuff->dstWid, client,
  1398. SecurityReadAccess);
  1399. if (!pDst)
  1400. return(BadWindow);
  1401. rep.type = X_Reply;
  1402. rep.length = 0;
  1403. rep.sequenceNumber = client->sequence;
  1404. if (!SAME_SCREENS(pWin->drawable, pDst->drawable))
  1405. {
  1406. rep.sameScreen = xFalse;
  1407. rep.child = None;
  1408. rep.dstX = rep.dstY = 0;
  1409. }
  1410. else
  1411. {
  1412. INT16 x, y;
  1413. rep.sameScreen = xTrue;
  1414. rep.child = None;
  1415. /* computing absolute coordinates -- adjust to destination later */
  1416. x = pWin->drawable.x + stuff->srcX;
  1417. y = pWin->drawable.y + stuff->srcY;
  1418. pWin = pDst->firstChild;
  1419. while (pWin)
  1420. {
  1421. #ifdef SHAPE
  1422. BoxRec box;
  1423. #endif
  1424. if ((pWin->mapped) &&
  1425. (x >= pWin->drawable.x - wBorderWidth (pWin)) &&
  1426. (x < pWin->drawable.x + (int)pWin->drawable.width +
  1427. wBorderWidth (pWin)) &&
  1428. (y >= pWin->drawable.y - wBorderWidth (pWin)) &&
  1429. (y < pWin->drawable.y + (int)pWin->drawable.height +
  1430. wBorderWidth (pWin))
  1431. #ifdef SHAPE
  1432. /* When a window is shaped, a further check
  1433. * is made to see if the point is inside
  1434. * borderSize
  1435. */
  1436. && (!wBoundingShape(pWin) ||
  1437. POINT_IN_REGION(pWin->drawable.pScreen,
  1438. &pWin->borderSize, x, y, &box))
  1439. #endif
  1440. )
  1441. {
  1442. rep.child = pWin->drawable.id;
  1443. pWin = (WindowPtr) NULL;
  1444. }
  1445. else
  1446. pWin = pWin->nextSib;
  1447. }
  1448. /* adjust to destination coordinates */
  1449. rep.dstX = x - pDst->drawable.x;
  1450. rep.dstY = y - pDst->drawable.y;
  1451. }
  1452. WriteReplyToClient(client, sizeof(xTranslateCoordsReply), &rep);
  1453. return(client->noClientException);
  1454. }
  1455. int
  1456. ProcOpenFont(client)
  1457. register ClientPtr client;
  1458. {
  1459. int err;
  1460. char fontReq[256];
  1461. REQUEST(xOpenFontReq);
  1462. REQUEST_FIXED_SIZE(xOpenFontReq, stuff->nbytes);
  1463. client->errorValue = stuff->fid;
  1464. LEGAL_NEW_RESOURCE(stuff->fid, client);
  1465. memcpy(fontReq,(char *)&stuff[1],(stuff->nbytes<256)?stuff->nbytes:255);
  1466. fontReq[stuff->nbytes]=0;
  1467. if (strchr(fontReq,'*') || strchr(fontReq,'?'))
  1468. {
  1469. extern int nxOpenFont(ClientPtr, XID, Mask, unsigned, char*);
  1470. #ifdef NXAGENT_FONTMATCH_DEBUG
  1471. fprintf(stderr, "Dispatch: ProcOpenFont try to find a common font with font pattern=%s\n",fontReq);
  1472. #endif
  1473. nxagentListRemoteFonts(fontReq, nxagentMaxFontNames);
  1474. err = nxOpenFont(client, stuff->fid, (Mask) 0,
  1475. stuff->nbytes, (char *)&stuff[1]);
  1476. }
  1477. else
  1478. err = OpenFont(client, stuff->fid, (Mask) 0,
  1479. stuff->nbytes, (char *)&stuff[1]);
  1480. if (err == Success)
  1481. {
  1482. return(client->noClientException);
  1483. }
  1484. else
  1485. return err;
  1486. }
  1487. int
  1488. ProcCloseFont(client)
  1489. register ClientPtr client;
  1490. {
  1491. FontPtr pFont;
  1492. REQUEST(xResourceReq);
  1493. REQUEST_SIZE_MATCH(xResourceReq);
  1494. pFont = (FontPtr)SecurityLookupIDByType(client, stuff->id, RT_FONT,
  1495. SecurityDestroyAccess);
  1496. if (pFont != (FontPtr)NULL)
  1497. {
  1498. #ifdef NXAGENT_SERVER
  1499. /*
  1500. * When a client closes a font the resource
  1501. * should not be lost if the reference counter
  1502. * is not 0, otherwise the server will not be
  1503. * able to find this font looping through the
  1504. * resources.
  1505. */
  1506. if (pFont -> refcnt > 0)
  1507. {
  1508. if (nxagentFindClientResource(serverClient -> index, RT_NX_FONT, pFont) == 0)
  1509. {
  1510. #ifdef TEST
  1511. fprintf(stderr, "ProcCloseFont: Switching resource for font at [%p].\n",
  1512. (void *) pFont);
  1513. #endif
  1514. nxagentFontPriv(pFont) -> mirrorID = FakeClientID(serverClient -> index);
  1515. AddResource(nxagentFontPriv(pFont) -> mirrorID, RT_NX_FONT, pFont);
  1516. }
  1517. #ifdef TEST
  1518. else
  1519. {
  1520. fprintf(stderr, "ProcCloseFont: Found duplicated font at [%p], "
  1521. "resource switching skipped.\n", (void *) pFont);
  1522. }
  1523. #endif
  1524. }
  1525. #endif
  1526. FreeResource(stuff->id, RT_NONE);
  1527. return(client->noClientException);
  1528. }
  1529. else
  1530. {
  1531. client->errorValue = stuff->id;
  1532. return (BadFont);
  1533. }
  1534. }
  1535. int
  1536. ProcQueryFont(client)
  1537. register ClientPtr client;
  1538. {
  1539. xQueryFontReply *reply;
  1540. FontPtr pFont;
  1541. register GC *pGC;
  1542. REQUEST(xResourceReq);
  1543. REQUEST_SIZE_MATCH(xResourceReq);
  1544. client->errorValue = stuff->id; /* EITHER font or gc */
  1545. pFont = NULL;
  1546. pFont = (FontPtr)SecurityLookupIDByType(client, stuff->id, RT_FONT,
  1547. SecurityReadAccess);
  1548. if (!pFont)
  1549. {
  1550. /* can't use VERIFY_GC because it might return BadGC */
  1551. pGC = (GC *) SecurityLookupIDByType(client, stuff->id, RT_GC,
  1552. SecurityReadAccess);
  1553. if (!pGC)
  1554. {
  1555. client->errorValue = stuff->id;
  1556. return(BadFont); /* procotol spec says only error is BadFont */
  1557. }
  1558. pFont = pGC->font;
  1559. }
  1560. /* test
  1561. {
  1562. Atom name_atom, value_atom;
  1563. int nprops;
  1564. FontPropPtr props;
  1565. int i;
  1566. char *name;
  1567. name_atom = MakeAtom("FONT", 4, True);
  1568. value_atom = 0L;
  1569. nprops = pFont->info.nprops;
  1570. props = pFont->info.props;
  1571. for (i = 0; i < nprops; i++)
  1572. if (props[i].name == name_atom) {
  1573. value_atom = props[i].value;
  1574. break;
  1575. }
  1576. if (!value_atom) return (BadFont);
  1577. name = (char *)NameForAtom(value_atom);
  1578. fprintf(stderr, "QueryFont: font name [%s]\n",name);
  1579. }
  1580. end test */
  1581. {
  1582. xCharInfo *pmax = FONTINKMAX(pFont);
  1583. xCharInfo *pmin = FONTINKMIN(pFont);
  1584. int nprotoxcistructs;
  1585. int rlength;
  1586. nprotoxcistructs = (
  1587. pmax->rightSideBearing == pmin->rightSideBearing &&
  1588. pmax->leftSideBearing == pmin->leftSideBearing &&
  1589. pmax->descent == pmin->descent &&
  1590. pmax->ascent == pmin->ascent &&
  1591. pmax->characterWidth == pmin->characterWidth) ?
  1592. 0 : N2dChars(pFont);
  1593. rlength = sizeof(xQueryFontReply) +
  1594. FONTINFONPROPS(FONTCHARSET(pFont)) * sizeof(xFontProp) +
  1595. nprotoxcistructs * sizeof(xCharInfo);
  1596. reply = NULL;
  1597. reply = (xQueryFontReply *)ALLOCATE_LOCAL(rlength);
  1598. if(!reply)
  1599. {
  1600. return(BadAlloc);
  1601. }
  1602. reply->type = X_Reply;
  1603. reply->length = (rlength - sizeof(xGenericReply)) >> 2;
  1604. reply->sequenceNumber = client->sequence;
  1605. QueryFont( pFont, reply, nprotoxcistructs);
  1606. WriteReplyToClient(client, rlength, reply);
  1607. DEALLOCATE_LOCAL(reply);
  1608. return(client->noClientException);
  1609. }
  1610. }
  1611. int
  1612. ProcQueryTextExtents(client)
  1613. register ClientPtr client;
  1614. {
  1615. REQUEST(xQueryTextExtentsReq);
  1616. xQueryTextExtentsReply reply;
  1617. FontPtr pFont;
  1618. GC *pGC;
  1619. ExtentInfoRec info;
  1620. unsigned long length;
  1621. REQUEST_AT_LEAST_SIZE(xQueryTextExtentsReq);
  1622. pFont = (FontPtr)SecurityLookupIDByType(client, stuff->fid, RT_FONT,
  1623. SecurityReadAccess);
  1624. if (!pFont)
  1625. {
  1626. pGC = (GC *)SecurityLookupIDByType(client, stuff->fid, RT_GC,
  1627. SecurityReadAccess);
  1628. if (!pGC)
  1629. {
  1630. client->errorValue = stuff->fid;
  1631. return(BadFont);
  1632. }
  1633. pFont = pGC->font;
  1634. }
  1635. length = client->req_len - (sizeof(xQueryTextExtentsReq) >> 2);
  1636. length = length << 1;
  1637. if (stuff->oddLength)
  1638. {
  1639. if (length == 0)
  1640. return(BadLength);
  1641. length--;
  1642. }
  1643. if (!QueryTextExtents(pFont, length, (unsigned char *)&stuff[1], &info))
  1644. return(BadAlloc);
  1645. reply.type = X_Reply;
  1646. reply.length = 0;
  1647. reply.sequenceNumber = client->sequence;
  1648. reply.drawDirection = info.drawDirection;
  1649. reply.fontAscent = info.fontAscent;
  1650. reply.fontDescent = info.fontDescent;
  1651. reply.overallAscent = info.overallAscent;
  1652. reply.overallDescent = info.overallDescent;
  1653. reply.overallWidth = info.overallWidth;
  1654. reply.overallLeft = info.overallLeft;
  1655. reply.overallRight = info.overallRight;
  1656. WriteReplyToClient(client, sizeof(xQueryTextExtentsReply), &reply);
  1657. return(client->noClientException);
  1658. }
  1659. int
  1660. ProcListFonts(client)
  1661. register ClientPtr client;
  1662. {
  1663. char tmp[256];
  1664. REQUEST(xListFontsReq);
  1665. REQUEST_FIXED_SIZE(xListFontsReq, stuff->nbytes);
  1666. memcpy(tmp,(unsigned char *) &stuff[1],(stuff->nbytes<256)?stuff->nbytes:255);
  1667. tmp[stuff->nbytes]=0;
  1668. #ifdef NXAGENT_FONTMATCH_DEBUG
  1669. fprintf(stderr, "Dispatch: ListFont request with pattern %s max_names=%d\n",tmp,stuff->maxNames);
  1670. #endif
  1671. nxagentListRemoteFonts(tmp, stuff -> maxNames < nxagentMaxFontNames ? nxagentMaxFontNames : stuff->maxNames);
  1672. return ListFonts(client, (unsigned char *) &stuff[1], stuff->nbytes,
  1673. stuff->maxNames);
  1674. }
  1675. int
  1676. ProcListFontsWithInfo(client)
  1677. register ClientPtr client;
  1678. {
  1679. char tmp[256];
  1680. REQUEST(xListFontsWithInfoReq);
  1681. REQUEST_FIXED_SIZE(xListFontsWithInfoReq, stuff->nbytes);
  1682. memcpy(tmp,(unsigned char *) &stuff[1],(stuff->nbytes<256)?stuff->nbytes:255);
  1683. tmp[stuff->nbytes]=0;
  1684. #ifdef NXAGENT_FONTMATCH_DEBUG
  1685. fprintf(stderr, "Dispatch: ListFont with info request with pattern %s max_names=%d\n",tmp,stuff->maxNames);
  1686. #endif
  1687. nxagentListRemoteFonts(tmp, stuff -> maxNames < nxagentMaxFontNames ? nxagentMaxFontNames :stuff->maxNames);
  1688. return StartListFontsWithInfo(client, stuff->nbytes,
  1689. (unsigned char *) &stuff[1], stuff->maxNames);
  1690. }
  1691. /*ARGSUSED*/
  1692. int
  1693. dixDestroyPixmap(value, pid)
  1694. pointer value; /* must conform to DeleteType */
  1695. XID pid;
  1696. {
  1697. PixmapPtr pPixmap = (PixmapPtr)value;
  1698. return (*pPixmap->drawable.pScreen->DestroyPixmap)(pPixmap);
  1699. }
  1700. int
  1701. ProcCreatePixmap(client)
  1702. register ClientPtr client;
  1703. {
  1704. PixmapPtr pMap;
  1705. register DrawablePtr pDraw;
  1706. REQUEST(xCreatePixmapReq);
  1707. DepthPtr pDepth;
  1708. register int i;
  1709. REQUEST_SIZE_MATCH(xCreatePixmapReq);
  1710. client->errorValue = stuff->pid;
  1711. LEGAL_NEW_RESOURCE(stuff->pid, client);
  1712. SECURITY_VERIFY_GEOMETRABLE (pDraw, stuff->drawable, client,
  1713. SecurityReadAccess);
  1714. if (!stuff->width || !stuff->height)
  1715. {
  1716. client->errorValue = 0;
  1717. return BadValue;
  1718. }
  1719. if (stuff->depth != 1)
  1720. {
  1721. pDepth = pDraw->pScreen->allowedDepths;
  1722. for (i=0; i<pDraw->pScreen->numDepths; i++, pDepth++)
  1723. if (pDepth->depth == stuff->depth)
  1724. goto CreatePmap;
  1725. client->errorValue = stuff->depth;
  1726. return BadValue;
  1727. }
  1728. CreatePmap:
  1729. pMap = (PixmapPtr)(*pDraw->pScreen->CreatePixmap)
  1730. (pDraw->pScreen, stuff->width,
  1731. stuff->height, stuff->depth);
  1732. if (pMap)
  1733. {
  1734. pMap->drawable.serialNumber = NEXT_SERIAL_NUMBER;
  1735. pMap->drawable.id = stuff->pid;
  1736. if (AddResource(stuff->pid, RT_PIXMAP, (pointer)pMap))
  1737. return(client->noClientException);
  1738. }
  1739. return (BadAlloc);
  1740. }
  1741. int
  1742. ProcFreePixmap(client)
  1743. register ClientPtr client;
  1744. {
  1745. PixmapPtr pMap;
  1746. REQUEST(xResourceReq);
  1747. REQUEST_SIZE_MATCH(xResourceReq);
  1748. pMap = (PixmapPtr)SecurityLookupIDByType(client, stuff->id, RT_PIXMAP,
  1749. SecurityDestroyAccess);
  1750. if (pMap)
  1751. {
  1752. #ifdef NXAGENT_SERVER
  1753. /*
  1754. * When a client releases a pixmap the resource
  1755. * should not be lost if the reference counter
  1756. * is not 0, otherwise the server will not be
  1757. * able to find this pixmap looping through the
  1758. * resources.
  1759. */
  1760. if (pMap -> refcnt > 0)
  1761. {
  1762. if (nxagentFindClientResource(serverClient -> index, RT_NX_PIXMAP, pMap) == 0)
  1763. {
  1764. #ifdef TEST
  1765. fprintf(stderr, "ProcFreePixmap: Switching resource for pixmap at [%p].\n",
  1766. (void *) pMap);
  1767. #endif
  1768. nxagentPixmapPriv(pMap) -> mid = FakeClientID(serverClient -> index);
  1769. AddResource(nxagentPixmapPriv(pMap) -> mid, RT_NX_PIXMAP, pMap);
  1770. }
  1771. #ifdef TEST
  1772. else
  1773. {
  1774. fprintf(stderr, "ProcFreePixmap: Found duplicated pixmap at [%p], "
  1775. "resource switching skipped.\n", (void *) pMap);
  1776. }
  1777. #endif
  1778. }
  1779. #endif
  1780. FreeResource(stuff->id, RT_NONE);
  1781. return(client->noClientException);
  1782. }
  1783. else
  1784. {
  1785. client->errorValue = stuff->id;
  1786. return (BadPixmap);
  1787. }
  1788. }
  1789. int
  1790. ProcCreateGC(client)
  1791. register ClientPtr client;
  1792. {
  1793. int error;
  1794. GC *pGC;
  1795. register DrawablePtr pDraw;
  1796. unsigned len;
  1797. REQUEST(xCreateGCReq);
  1798. REQUEST_AT_LEAST_SIZE(xCreateGCReq);
  1799. client->errorValue = stuff->gc;
  1800. LEGAL_NEW_RESOURCE(stuff->gc, client);
  1801. SECURITY_VERIFY_DRAWABLE (pDraw, stuff->drawable, client,
  1802. SecurityReadAccess);
  1803. len = client->req_len - (sizeof(xCreateGCReq) >> 2);
  1804. if (len != Ones(stuff->mask))
  1805. return BadLength;
  1806. pGC = (GC *)CreateGC(pDraw, stuff->mask,
  1807. (XID *) &stuff[1], &error);
  1808. if (error != Success)
  1809. return error;
  1810. if (!AddResource(stuff->gc, RT_GC, (pointer)pGC))
  1811. return (BadAlloc);
  1812. return(client->noClientException);
  1813. }
  1814. int
  1815. ProcChangeGC(client)
  1816. register ClientPtr client;
  1817. {
  1818. GC *pGC;
  1819. REQUEST(xChangeGCReq);
  1820. int result;
  1821. unsigned len;
  1822. REQUEST_AT_LEAST_SIZE(xChangeGCReq);
  1823. SECURITY_VERIFY_GC(pGC, stuff->gc, client, SecurityWriteAccess);
  1824. len = client->req_len - (sizeof(xChangeGCReq) >> 2);
  1825. if (len != Ones(stuff->mask))
  1826. return BadLength;
  1827. result = dixChangeGC(client, pGC, stuff->mask, (CARD32 *) &stuff[1], 0);
  1828. if (client->noClientException != Success)
  1829. return(client->noClientException);
  1830. else
  1831. {
  1832. client->errorValue = clientErrorValue;
  1833. return(result);
  1834. }
  1835. }
  1836. int
  1837. ProcCopyGC(client)
  1838. register ClientPtr client;
  1839. {
  1840. register GC *dstGC;
  1841. register GC *pGC;
  1842. int result;
  1843. REQUEST(xCopyGCReq);
  1844. REQUEST_SIZE_MATCH(xCopyGCReq);
  1845. SECURITY_VERIFY_GC( pGC, stuff->srcGC, client, SecurityReadAccess);
  1846. SECURITY_VERIFY_GC( dstGC, stuff->dstGC, client, SecurityWriteAccess);
  1847. if ((dstGC->pScreen != pGC->pScreen) || (dstGC->depth != pGC->depth))
  1848. return (BadMatch);
  1849. result = CopyGC(pGC, dstGC, stuff->mask);
  1850. if (client->noClientException != Success)
  1851. return(client->noClientException);
  1852. else
  1853. {
  1854. client->errorValue = clientErrorValue;
  1855. return(result);
  1856. }
  1857. }
  1858. int
  1859. ProcSetDashes(client)
  1860. register ClientPtr client;
  1861. {
  1862. register GC *pGC;
  1863. int result;
  1864. REQUEST(xSetDashesReq);
  1865. REQUEST_FIXED_SIZE(xSetDashesReq, stuff->nDashes);
  1866. if (stuff->nDashes == 0)
  1867. {
  1868. client->errorValue = 0;
  1869. return BadValue;
  1870. }
  1871. SECURITY_VERIFY_GC(pGC,stuff->gc, client, SecurityWriteAccess);
  1872. result = SetDashes(pGC, stuff->dashOffset, stuff->nDashes,
  1873. (unsigned char *)&stuff[1]);
  1874. if (client->noClientException != Success)
  1875. return(client->noClientException);
  1876. else
  1877. {
  1878. client->errorValue = clientErrorValue;
  1879. return(result);
  1880. }
  1881. }
  1882. int
  1883. ProcSetClipRectangles(client)
  1884. register ClientPtr client;
  1885. {
  1886. int nr;
  1887. int result;
  1888. register GC *pGC;
  1889. REQUEST(xSetClipRectanglesReq);
  1890. REQUEST_AT_LEAST_SIZE(xSetClipRectanglesReq);
  1891. if ((stuff->ordering != Unsorted) && (stuff->ordering != YSorted) &&
  1892. (stuff->ordering != YXSorted) && (stuff->ordering != YXBanded))
  1893. {
  1894. client->errorValue = stuff->ordering;
  1895. return BadValue;
  1896. }
  1897. SECURITY_VERIFY_GC(pGC,stuff->gc, client, SecurityWriteAccess);
  1898. nr = (client->req_len << 2) - sizeof(xSetClipRectanglesReq);
  1899. if (nr & 4)
  1900. return(BadLength);
  1901. nr >>= 3;
  1902. result = SetClipRects(pGC, stuff->xOrigin, stuff->yOrigin,
  1903. nr, (xRectangle *)&stuff[1], (int)stuff->ordering);
  1904. if (client->noClientException != Success)
  1905. return(client->noClientException);
  1906. else
  1907. return(result);
  1908. }
  1909. int
  1910. ProcFreeGC(client)
  1911. register ClientPtr client;
  1912. {
  1913. register GC *pGC;
  1914. REQUEST(xResourceReq);
  1915. REQUEST_SIZE_MATCH(xResourceReq);
  1916. SECURITY_VERIFY_GC(pGC, stuff->id, client, SecurityDestroyAccess);
  1917. FreeResource(stuff->id, RT_NONE);
  1918. return(client->noClientException);
  1919. }
  1920. int
  1921. ProcClearToBackground(client)
  1922. register ClientPtr client;
  1923. {
  1924. REQUEST(xClearAreaReq);
  1925. register WindowPtr pWin;
  1926. REQUEST_SIZE_MATCH(xClearAreaReq);
  1927. pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client,
  1928. SecurityWriteAccess);
  1929. if (!pWin)
  1930. return(BadWindow);
  1931. if (pWin->drawable.class == InputOnly)
  1932. {
  1933. client->errorValue = stuff->window;
  1934. return (BadMatch);
  1935. }
  1936. if ((stuff->exposures != xTrue) && (stuff->exposures != xFalse))
  1937. {
  1938. client->errorValue = stuff->exposures;
  1939. return(BadValue);
  1940. }
  1941. (*pWin->drawable.pScreen->ClearToBackground)(pWin, stuff->x, stuff->y,
  1942. stuff->width, stuff->height,
  1943. (Bool)stuff->exposures);
  1944. return(client->noClientException);
  1945. }
  1946. int
  1947. ProcCopyArea(client)
  1948. register ClientPtr client;
  1949. {
  1950. register DrawablePtr pDst;
  1951. register DrawablePtr pSrc;
  1952. register GC *pGC;
  1953. REQUEST(xCopyAreaReq);
  1954. RegionPtr pRgn;
  1955. REQUEST_SIZE_MATCH(xCopyAreaReq);
  1956. VALIDATE_DRAWABLE_AND_GC(stuff->dstDrawable, pDst, pGC, client);
  1957. if (stuff->dstDrawable != stuff->srcDrawable)
  1958. {
  1959. SECURITY_VERIFY_DRAWABLE(pSrc, stuff->srcDrawable, client,
  1960. SecurityReadAccess);
  1961. if ((pDst->pScreen != pSrc->pScreen) || (pDst->depth != pSrc->depth))
  1962. {
  1963. client->errorValue = stuff->dstDrawable;
  1964. return (BadMatch);
  1965. }
  1966. }
  1967. else
  1968. pSrc = pDst;
  1969. SET_DBE_SRCBUF(pSrc, stuff->srcDrawable);
  1970. pRgn = (*pGC->ops->CopyArea)(pSrc, pDst, pGC, stuff->srcX, stuff->srcY,
  1971. stuff->width, stuff->height,
  1972. stuff->dstX, stuff->dstY);
  1973. if (pGC->graphicsExposures)
  1974. {
  1975. (*pDst->pScreen->SendGraphicsExpose)
  1976. (client, pRgn, stuff->dstDrawable, X_CopyArea, 0);
  1977. if (pRgn)
  1978. REGION_DESTROY(pDst->pScreen, pRgn);
  1979. }
  1980. return(client->noClientException);
  1981. }
  1982. int
  1983. ProcCopyPlane(client)
  1984. register ClientPtr client;
  1985. {
  1986. register DrawablePtr psrcDraw, pdstDraw;
  1987. register GC *pGC;
  1988. REQUEST(xCopyPlaneReq);
  1989. RegionPtr pRgn;
  1990. REQUEST_SIZE_MATCH(xCopyPlaneReq);
  1991. VALIDATE_DRAWABLE_AND_GC(stuff->dstDrawable, pdstDraw, pGC, client);
  1992. if (stuff->dstDrawable != stuff->srcDrawable)
  1993. {
  1994. SECURITY_VERIFY_DRAWABLE(psrcDraw, stuff->srcDrawable, client,
  1995. SecurityReadAccess);
  1996. if (pdstDraw->pScreen != psrcDraw->pScreen)
  1997. {
  1998. client->errorValue = stuff->dstDrawable;
  1999. return (BadMatch);
  2000. }
  2001. }
  2002. else
  2003. psrcDraw = pdstDraw;
  2004. SET_DBE_SRCBUF(psrcDraw, stuff->srcDrawable);
  2005. /* Check to see if stuff->bitPlane has exactly ONE good bit set */
  2006. if(stuff->bitPlane == 0 || (stuff->bitPlane & (stuff->bitPlane - 1)) ||
  2007. (stuff->bitPlane > (1L << (psrcDraw->depth - 1))))
  2008. {
  2009. client->errorValue = stuff->bitPlane;
  2010. return(BadValue);
  2011. }
  2012. pRgn = (*pGC->ops->CopyPlane)(psrcDraw, pdstDraw, pGC, stuff->srcX, stuff->srcY,
  2013. stuff->width, stuff->height,
  2014. stuff->dstX, stuff->dstY, stuff->bitPlane);
  2015. if (pGC->graphicsExposures)
  2016. {
  2017. (*pdstDraw->pScreen->SendGraphicsExpose)
  2018. (client, pRgn, stuff->dstDrawable, X_CopyPlane, 0);
  2019. if (pRgn)
  2020. REGION_DESTROY(pdstDraw->pScreen, pRgn);
  2021. }
  2022. return(client->noClientException);
  2023. }
  2024. int
  2025. ProcPolyPoint(client)
  2026. register ClientPtr client;
  2027. {
  2028. int npoint;
  2029. register GC *pGC;
  2030. register DrawablePtr pDraw;
  2031. REQUEST(xPolyPointReq);
  2032. REQUEST_AT_LEAST_SIZE(xPolyPointReq);
  2033. if ((stuff->coordMode != CoordModeOrigin) &&
  2034. (stuff->coordMode != CoordModePrevious))
  2035. {
  2036. client->errorValue = stuff->coordMode;
  2037. return BadValue;
  2038. }
  2039. VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
  2040. npoint = ((client->req_len << 2) - sizeof(xPolyPointReq)) >> 2;
  2041. if (npoint)
  2042. {
  2043. (*pGC->ops->PolyPoint)(pDraw, pGC, stuff->coordMode, npoint,
  2044. (xPoint *) &stuff[1]);
  2045. }
  2046. return (client->noClientException);
  2047. }
  2048. int
  2049. ProcPolyLine(client)
  2050. register ClientPtr client;
  2051. {
  2052. int npoint;
  2053. register GC *pGC;
  2054. register DrawablePtr pDraw;
  2055. REQUEST(xPolyLineReq);
  2056. REQUEST_AT_LEAST_SIZE(xPolyLineReq);
  2057. if ((stuff->coordMode != CoordModeOrigin) &&
  2058. (stuff->coordMode != CoordModePrevious))
  2059. {
  2060. client->errorValue = stuff->coordMode;
  2061. return BadValue;
  2062. }
  2063. VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
  2064. npoint = ((client->req_len << 2) - sizeof(xPolyLineReq)) >> 2;
  2065. if (npoint > 1)
  2066. {
  2067. (*pGC->ops->Polylines)(pDraw, pGC, stuff->coordMode, npoint,
  2068. (DDXPointPtr) &stuff[1]);
  2069. }
  2070. return(client->noClientException);
  2071. }
  2072. int
  2073. ProcPolySegment(client)
  2074. register ClientPtr client;
  2075. {
  2076. int nsegs;
  2077. register GC *pGC;
  2078. register DrawablePtr pDraw;
  2079. REQUEST(xPolySegmentReq);
  2080. REQUEST_AT_LEAST_SIZE(xPolySegmentReq);
  2081. VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
  2082. nsegs = (client->req_len << 2) - sizeof(xPolySegmentReq);
  2083. if (nsegs & 4)
  2084. return(BadLength);
  2085. nsegs >>= 3;
  2086. if (nsegs)
  2087. {
  2088. (*pGC->ops->PolySegment)(pDraw, pGC, nsegs, (xSegment *) &stuff[1]);
  2089. }
  2090. return (client->noClientException);
  2091. }
  2092. int
  2093. ProcPolyRectangle (client)
  2094. register ClientPtr client;
  2095. {
  2096. int nrects;
  2097. register GC *pGC;
  2098. register DrawablePtr pDraw;
  2099. REQUEST(xPolyRectangleReq);
  2100. REQUEST_AT_LEAST_SIZE(xPolyRectangleReq);
  2101. VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
  2102. nrects = (client->req_len << 2) - sizeof(xPolyRectangleReq);
  2103. if (nrects & 4)
  2104. return(BadLength);
  2105. nrects >>= 3;
  2106. if (nrects)
  2107. {
  2108. (*pGC->ops->PolyRectangle)(pDraw, pGC,
  2109. nrects, (xRectangle *) &stuff[1]);
  2110. }
  2111. return(client->noClientException);
  2112. }
  2113. int
  2114. ProcPolyArc(client)
  2115. register ClientPtr client;
  2116. {
  2117. int narcs;
  2118. register GC *pGC;
  2119. register DrawablePtr pDraw;
  2120. REQUEST(xPolyArcReq);
  2121. REQUEST_AT_LEAST_SIZE(xPolyArcReq);
  2122. VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
  2123. narcs = (client->req_len << 2) - sizeof(xPolyArcReq);
  2124. if (narcs % sizeof(xArc))
  2125. return(BadLength);
  2126. narcs /= sizeof(xArc);
  2127. if (narcs)
  2128. {
  2129. (*pGC->ops->PolyArc)(pDraw, pGC, narcs, (xArc *) &stuff[1]);
  2130. }
  2131. return (client->noClientException);
  2132. }
  2133. int
  2134. ProcFillPoly(client)
  2135. register ClientPtr client;
  2136. {
  2137. int things;
  2138. register GC *pGC;
  2139. register DrawablePtr pDraw;
  2140. REQUEST(xFillPolyReq);
  2141. REQUEST_AT_LEAST_SIZE(xFillPolyReq);
  2142. if ((stuff->shape != Complex) && (stuff->shape != Nonconvex) &&
  2143. (stuff->shape != Convex))
  2144. {
  2145. client->errorValue = stuff->shape;
  2146. return BadValue;
  2147. }
  2148. if ((stuff->coordMode != CoordModeOrigin) &&
  2149. (stuff->coordMode != CoordModePrevious))
  2150. {
  2151. client->errorValue = stuff->coordMode;
  2152. return BadValue;
  2153. }
  2154. VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
  2155. things = ((client->req_len << 2) - sizeof(xFillPolyReq)) >> 2;
  2156. if (things)
  2157. {
  2158. (*pGC->ops->FillPolygon) (pDraw, pGC, stuff->shape,
  2159. stuff->coordMode, things,
  2160. (DDXPointPtr) &stuff[1]);
  2161. }
  2162. return(client->noClientException);
  2163. }
  2164. int
  2165. ProcPolyFillRectangle(client)
  2166. register ClientPtr client;
  2167. {
  2168. int things;
  2169. register GC *pGC;
  2170. register DrawablePtr pDraw;
  2171. REQUEST(xPolyFillRectangleReq);
  2172. REQUEST_AT_LEAST_SIZE(xPolyFillRectangleReq);
  2173. VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
  2174. things = (client->req_len << 2) - sizeof(xPolyFillRectangleReq);
  2175. if (things & 4)
  2176. return(BadLength);
  2177. things >>= 3;
  2178. if (things)
  2179. {
  2180. (*pGC->ops->PolyFillRect) (pDraw, pGC, things,
  2181. (xRectangle *) &stuff[1]);
  2182. }
  2183. return (client->noClientException);
  2184. }
  2185. int
  2186. ProcPolyFillArc(client)
  2187. register ClientPtr client;
  2188. {
  2189. int narcs;
  2190. register GC *pGC;
  2191. register DrawablePtr pDraw;
  2192. REQUEST(xPolyFillArcReq);
  2193. REQUEST_AT_LEAST_SIZE(xPolyFillArcReq);
  2194. VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
  2195. narcs = (client->req_len << 2) - sizeof(xPolyFillArcReq);
  2196. if (narcs % sizeof(xArc))
  2197. return(BadLength);
  2198. narcs /= sizeof(xArc);
  2199. if (narcs)
  2200. {
  2201. (*pGC->ops->PolyFillArc) (pDraw, pGC, narcs, (xArc *) &stuff[1]);
  2202. }
  2203. return (client->noClientException);
  2204. }
  2205. #ifdef MATCH_CLIENT_ENDIAN
  2206. int
  2207. ServerOrder (void)
  2208. {
  2209. int whichbyte = 1;
  2210. if (*((char *) &whichbyte))
  2211. return LSBFirst;
  2212. return MSBFirst;
  2213. }
  2214. #define ClientOrder(client) ((client)->swapped ? !ServerOrder() : ServerOrder())
  2215. void
  2216. ReformatImage (char *base, int nbytes, int bpp, int order)
  2217. {
  2218. switch (bpp) {
  2219. case 1: /* yuck */
  2220. if (BITMAP_BIT_ORDER != order)
  2221. BitOrderInvert ((unsigned char *) base, nbytes);
  2222. #if IMAGE_BYTE_ORDER != BITMAP_BIT_ORDER && BITMAP_SCANLINE_UNIT != 8
  2223. ReformatImage (base, nbytes, BITMAP_SCANLINE_UNIT, order);
  2224. #endif
  2225. break;
  2226. case 4:
  2227. break; /* yuck */
  2228. case 8:
  2229. break;
  2230. case 16:
  2231. if (IMAGE_BYTE_ORDER != order)
  2232. TwoByteSwap ((unsigned char *) base, nbytes);
  2233. break;
  2234. case 32:
  2235. if (IMAGE_BYTE_ORDER != order)
  2236. FourByteSwap ((unsigned char *) base, nbytes);
  2237. break;
  2238. }
  2239. }
  2240. #else
  2241. #define ReformatImage(b,n,bpp,o)
  2242. #endif
  2243. /* 64-bit server notes: the protocol restricts padding of images to
  2244. * 8-, 16-, or 32-bits. We would like to have 64-bits for the server
  2245. * to use internally. Removes need for internal alignment checking.
  2246. * All of the PutImage functions could be changed individually, but
  2247. * as currently written, they call other routines which require things
  2248. * to be 64-bit padded on scanlines, so we changed things here.
  2249. * If an image would be padded differently for 64- versus 32-, then
  2250. * copy each scanline to a 64-bit padded scanline.
  2251. * Also, we need to make sure that the image is aligned on a 64-bit
  2252. * boundary, even if the scanlines are padded to our satisfaction.
  2253. */
  2254. int
  2255. ProcPutImage(client)
  2256. register ClientPtr client;
  2257. {
  2258. register GC *pGC;
  2259. register DrawablePtr pDraw;
  2260. long length; /* length of scanline server padded */
  2261. long lengthProto; /* length of scanline protocol padded */
  2262. char *tmpImage;
  2263. REQUEST(xPutImageReq);
  2264. REQUEST_AT_LEAST_SIZE(xPutImageReq);
  2265. VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
  2266. if (stuff->format == XYBitmap)
  2267. {
  2268. if ((stuff->depth != 1) ||
  2269. (stuff->leftPad >= (unsigned int)screenInfo.bitmapScanlinePad))
  2270. return BadMatch;
  2271. length = BitmapBytePad(stuff->width + stuff->leftPad);
  2272. }
  2273. else if (stuff->format == XYPixmap)
  2274. {
  2275. if ((pDraw->depth != stuff->depth) ||
  2276. (stuff->leftPad >= (unsigned int)screenInfo.bitmapScanlinePad))
  2277. return BadMatch;
  2278. length = BitmapBytePad(stuff->width + stuff->leftPad);
  2279. length *= stuff->depth;
  2280. }
  2281. else if (stuff->format == ZPixmap)
  2282. {
  2283. if ((pDraw->depth != stuff->depth) || (stuff->leftPad != 0))
  2284. return BadMatch;
  2285. length = PixmapBytePad(stuff->width, stuff->depth);
  2286. }
  2287. else
  2288. {
  2289. client->errorValue = stuff->format;
  2290. return BadValue;
  2291. }
  2292. tmpImage = (char *)&stuff[1];
  2293. lengthProto = length;
  2294. if (((((lengthProto * stuff->height) + (unsigned)3) >> 2) +
  2295. (sizeof(xPutImageReq) >> 2)) != client->req_len)
  2296. return BadLength;
  2297. ReformatImage (tmpImage, lengthProto * stuff->height,
  2298. stuff->format == ZPixmap ? BitsPerPixel (stuff->depth) : 1,
  2299. ClientOrder(client));
  2300. (*pGC->ops->PutImage) (pDraw, pGC, stuff->depth, stuff->dstX, stuff->dstY,
  2301. stuff->width, stuff->height,
  2302. stuff->leftPad, stuff->format, tmpImage);
  2303. return (client->noClientException);
  2304. }
  2305. int
  2306. DoGetImage(client, format, drawable, x, y, width, height, planemask, im_return)
  2307. register ClientPtr client;
  2308. Drawable drawable;
  2309. int format;
  2310. int x, y, width, height;
  2311. Mask planemask;
  2312. xGetImageReply **im_return;
  2313. {
  2314. register DrawablePtr pDraw;
  2315. int nlines, linesPerBuf;
  2316. register int linesDone;
  2317. long widthBytesLine, length;
  2318. Mask plane = 0;
  2319. char *pBuf;
  2320. xGetImageReply xgi;
  2321. RegionPtr pVisibleRegion = NULL;
  2322. if ((format != XYPixmap) && (format != ZPixmap))
  2323. {
  2324. client->errorValue = format;
  2325. return(BadValue);
  2326. }
  2327. SECURITY_VERIFY_DRAWABLE(pDraw, drawable, client, SecurityReadAccess);
  2328. if(pDraw->type == DRAWABLE_WINDOW)
  2329. {
  2330. if( /* check for being viewable */
  2331. !((WindowPtr) pDraw)->realized ||
  2332. /* check for being on screen */
  2333. pDraw->x + x < 0 ||
  2334. pDraw->x + x + width > pDraw->pScreen->width ||
  2335. pDraw->y + y < 0 ||
  2336. pDraw->y + y + height > pDraw->pScreen->height ||
  2337. /* check for being inside of border */
  2338. x < - wBorderWidth((WindowPtr)pDraw) ||
  2339. x + width > wBorderWidth((WindowPtr)pDraw) + (int)pDraw->width ||
  2340. y < -wBorderWidth((WindowPtr)pDraw) ||
  2341. y + height > wBorderWidth ((WindowPtr)pDraw) + (int)pDraw->height
  2342. )
  2343. return(BadMatch);
  2344. xgi.visual = wVisual (((WindowPtr) pDraw));
  2345. }
  2346. else
  2347. {
  2348. if(x < 0 ||
  2349. x+width > (int)pDraw->width ||
  2350. y < 0 ||
  2351. y+height > (int)pDraw->height
  2352. )
  2353. return(BadMatch);
  2354. xgi.visual = None;
  2355. }
  2356. SET_DBE_SRCBUF(pDraw, drawable);
  2357. xgi.type = X_Reply;
  2358. xgi.sequenceNumber = client->sequence;
  2359. xgi.depth = pDraw->depth;
  2360. if(format == ZPixmap)
  2361. {
  2362. widthBytesLine = PixmapBytePad(width, pDraw->depth);
  2363. length = widthBytesLine * height;
  2364. }
  2365. else
  2366. {
  2367. widthBytesLine = BitmapBytePad(width);
  2368. plane = ((Mask)1) << (pDraw->depth - 1);
  2369. /* only planes asked for */
  2370. length = widthBytesLine * height *
  2371. Ones(planemask & (plane | (plane - 1)));
  2372. }
  2373. xgi.length = length;
  2374. if (im_return) {
  2375. pBuf = (char *)xalloc(sz_xGetImageReply + length);
  2376. if (!pBuf)
  2377. return (BadAlloc);
  2378. if (widthBytesLine == 0)
  2379. linesPerBuf = 0;
  2380. else
  2381. linesPerBuf = height;
  2382. *im_return = (xGetImageReply *)pBuf;
  2383. *(xGetImageReply *)pBuf = xgi;
  2384. pBuf += sz_xGetImageReply;
  2385. } else {
  2386. xgi.length = (xgi.length + 3) >> 2;
  2387. if (widthBytesLine == 0 || height == 0)
  2388. linesPerBuf = 0;
  2389. else if (widthBytesLine >= IMAGE_BUFSIZE)
  2390. linesPerBuf = 1;
  2391. else
  2392. {
  2393. linesPerBuf = IMAGE_BUFSIZE / widthBytesLine;
  2394. if (linesPerBuf > height)
  2395. linesPerBuf = height;
  2396. }
  2397. length = linesPerBuf * widthBytesLine;
  2398. if (linesPerBuf < height)
  2399. {
  2400. /* we have to make sure intermediate buffers don't need padding */
  2401. while ((linesPerBuf > 1) &&
  2402. (length & ((1L << LOG2_BYTES_PER_SCANLINE_PAD)-1)))
  2403. {
  2404. linesPerBuf--;
  2405. length -= widthBytesLine;
  2406. }
  2407. while (length & ((1L << LOG2_BYTES_PER_SCANLINE_PAD)-1))
  2408. {
  2409. linesPerBuf++;
  2410. length += widthBytesLine;
  2411. }
  2412. }
  2413. if(!(pBuf = (char *) ALLOCATE_LOCAL(length)))
  2414. return (BadAlloc);
  2415. WriteReplyToClient(client, sizeof (xGetImageReply), &xgi);
  2416. }
  2417. #ifdef XCSECURITY
  2418. if (client->trustLevel != XSecurityClientTrusted &&
  2419. pDraw->type == DRAWABLE_WINDOW)
  2420. {
  2421. pVisibleRegion = NotClippedByChildren((WindowPtr)pDraw);
  2422. if (pVisibleRegion)
  2423. {
  2424. REGION_TRANSLATE(pScreen, pVisibleRegion, -pDraw->x, -pDraw->y);
  2425. }
  2426. }
  2427. #endif
  2428. if (linesPerBuf == 0)
  2429. {
  2430. /* nothing to do */
  2431. }
  2432. else if (format == ZPixmap)
  2433. {
  2434. linesDone = 0;
  2435. while (height - linesDone > 0)
  2436. {
  2437. nlines = min(linesPerBuf, height - linesDone);
  2438. (*pDraw->pScreen->GetImage) (pDraw,
  2439. x,
  2440. y + linesDone,
  2441. width,
  2442. nlines,
  2443. format,
  2444. planemask,
  2445. (pointer) pBuf);
  2446. #ifdef XCSECURITY
  2447. if (pVisibleRegion)
  2448. SecurityCensorImage(client, pVisibleRegion, widthBytesLine,
  2449. pDraw, x, y + linesDone, width,
  2450. nlines, format, pBuf);
  2451. #endif
  2452. /* Note that this is NOT a call to WriteSwappedDataToClient,
  2453. as we do NOT byte swap */
  2454. if (!im_return)
  2455. {
  2456. ReformatImage (pBuf, (int)(nlines * widthBytesLine),
  2457. BitsPerPixel (pDraw->depth),
  2458. ClientOrder(client));
  2459. /* Don't split me, gcc pukes when you do */
  2460. (void)WriteToClient(client,
  2461. (int)(nlines * widthBytesLine),
  2462. pBuf);
  2463. }
  2464. linesDone += nlines;
  2465. }
  2466. }
  2467. else /* XYPixmap */
  2468. {
  2469. for (; plane; plane >>= 1)
  2470. {
  2471. if (planemask & plane)
  2472. {
  2473. linesDone = 0;
  2474. while (height - linesDone > 0)
  2475. {
  2476. nlines = min(linesPerBuf, height - linesDone);
  2477. (*pDraw->pScreen->GetImage) (pDraw,
  2478. x,
  2479. y + linesDone,
  2480. width,
  2481. nlines,
  2482. format,
  2483. plane,
  2484. (pointer)pBuf);
  2485. #ifdef XCSECURITY
  2486. if (pVisibleRegion)
  2487. SecurityCensorImage(client, pVisibleRegion,
  2488. widthBytesLine,
  2489. pDraw, x, y + linesDone, width,
  2490. nlines, format, pBuf);
  2491. #endif
  2492. /* Note: NOT a call to WriteSwappedDataToClient,
  2493. as we do NOT byte swap */
  2494. if (im_return) {
  2495. pBuf += nlines * widthBytesLine;
  2496. } else {
  2497. ReformatImage (pBuf,
  2498. (int)(nlines * widthBytesLine),
  2499. 1,
  2500. ClientOrder (client));
  2501. /* Don't split me, gcc pukes when you do */
  2502. (void)WriteToClient(client,
  2503. (int)(nlines * widthBytesLine),
  2504. pBuf);
  2505. }
  2506. linesDone += nlines;
  2507. }
  2508. }
  2509. }
  2510. }
  2511. #ifdef XCSECURITY
  2512. if (pVisibleRegion)
  2513. REGION_DESTROY(pScreen, pVisibleRegion);
  2514. #endif
  2515. if (!im_return)
  2516. DEALLOCATE_LOCAL(pBuf);
  2517. return (client->noClientException);
  2518. }
  2519. int
  2520. ProcGetImage(client)
  2521. register ClientPtr client;
  2522. {
  2523. REQUEST(xGetImageReq);
  2524. REQUEST_SIZE_MATCH(xGetImageReq);
  2525. return DoGetImage(client, stuff->format, stuff->drawable,
  2526. stuff->x, stuff->y,
  2527. (int)stuff->width, (int)stuff->height,
  2528. stuff->planeMask, (xGetImageReply **)NULL);
  2529. }
  2530. int
  2531. ProcPolyText(client)
  2532. register ClientPtr client;
  2533. {
  2534. int err;
  2535. REQUEST(xPolyTextReq);
  2536. DrawablePtr pDraw;
  2537. GC *pGC;
  2538. REQUEST_AT_LEAST_SIZE(xPolyTextReq);
  2539. VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
  2540. err = PolyText(client,
  2541. pDraw,
  2542. pGC,
  2543. (unsigned char *)&stuff[1],
  2544. ((unsigned char *) stuff) + (client->req_len << 2),
  2545. stuff->x,
  2546. stuff->y,
  2547. stuff->reqType,
  2548. stuff->drawable);
  2549. if (err == Success)
  2550. {
  2551. return(client->noClientException);
  2552. }
  2553. else
  2554. return err;
  2555. }
  2556. int
  2557. ProcImageText8(client)
  2558. register ClientPtr client;
  2559. {
  2560. int err;
  2561. register DrawablePtr pDraw;
  2562. register GC *pGC;
  2563. REQUEST(xImageTextReq);
  2564. REQUEST_FIXED_SIZE(xImageTextReq, stuff->nChars);
  2565. VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
  2566. err = ImageText(client,
  2567. pDraw,
  2568. pGC,
  2569. stuff->nChars,
  2570. (unsigned char *)&stuff[1],
  2571. stuff->x,
  2572. stuff->y,
  2573. stuff->reqType,
  2574. stuff->drawable);
  2575. if (err == Success)
  2576. {
  2577. return(client->noClientException);
  2578. }
  2579. else
  2580. return err;
  2581. }
  2582. int
  2583. ProcImageText16(client)
  2584. register ClientPtr client;
  2585. {
  2586. int err;
  2587. register DrawablePtr pDraw;
  2588. register GC *pGC;
  2589. REQUEST(xImageTextReq);
  2590. REQUEST_FIXED_SIZE(xImageTextReq, stuff->nChars << 1);
  2591. VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
  2592. err = ImageText(client,
  2593. pDraw,
  2594. pGC,
  2595. stuff->nChars,
  2596. (unsigned char *)&stuff[1],
  2597. stuff->x,
  2598. stuff->y,
  2599. stuff->reqType,
  2600. stuff->drawable);
  2601. if (err == Success)
  2602. {
  2603. return(client->noClientException);
  2604. }
  2605. else
  2606. return err;
  2607. }
  2608. int
  2609. ProcCreateColormap(client)
  2610. register ClientPtr client;
  2611. {
  2612. VisualPtr pVisual;
  2613. ColormapPtr pmap;
  2614. Colormap mid;
  2615. register WindowPtr pWin;
  2616. ScreenPtr pScreen;
  2617. REQUEST(xCreateColormapReq);
  2618. int i, result;
  2619. REQUEST_SIZE_MATCH(xCreateColormapReq);
  2620. if ((stuff->alloc != AllocNone) && (stuff->alloc != AllocAll))
  2621. {
  2622. client->errorValue = stuff->alloc;
  2623. return(BadValue);
  2624. }
  2625. mid = stuff->mid;
  2626. LEGAL_NEW_RESOURCE(mid, client);
  2627. pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client,
  2628. SecurityReadAccess);
  2629. if (!pWin)
  2630. return(BadWindow);
  2631. pScreen = pWin->drawable.pScreen;
  2632. for (i = 0, pVisual = pScreen->visuals;
  2633. i < pScreen->numVisuals;
  2634. i++, pVisual++)
  2635. {
  2636. if (pVisual->vid != stuff->visual)
  2637. continue;
  2638. result = CreateColormap(mid, pScreen, pVisual, &pmap,
  2639. (int)stuff->alloc, client->index);
  2640. if (client->noClientException != Success)
  2641. return(client->noClientException);
  2642. else
  2643. return(result);
  2644. }
  2645. client->errorValue = stuff->visual;
  2646. return(BadValue);
  2647. }
  2648. int
  2649. ProcFreeColormap(client)
  2650. register ClientPtr client;
  2651. {
  2652. ColormapPtr pmap;
  2653. REQUEST(xResourceReq);
  2654. REQUEST_SIZE_MATCH(xResourceReq);
  2655. pmap = (ColormapPtr )SecurityLookupIDByType(client, stuff->id, RT_COLORMAP,
  2656. SecurityDestroyAccess);
  2657. if (pmap)
  2658. {
  2659. /* Freeing a default colormap is a no-op */
  2660. if (!(pmap->flags & IsDefault))
  2661. FreeResource(stuff->id, RT_NONE);
  2662. return (client->noClientException);
  2663. }
  2664. else
  2665. {
  2666. client->errorValue = stuff->id;
  2667. return (BadColor);
  2668. }
  2669. }
  2670. int
  2671. ProcCopyColormapAndFree(client)
  2672. register ClientPtr client;
  2673. {
  2674. Colormap mid;
  2675. ColormapPtr pSrcMap;
  2676. REQUEST(xCopyColormapAndFreeReq);
  2677. int result;
  2678. REQUEST_SIZE_MATCH(xCopyColormapAndFreeReq);
  2679. mid = stuff->mid;
  2680. LEGAL_NEW_RESOURCE(mid, client);
  2681. if( (pSrcMap = (ColormapPtr )SecurityLookupIDByType(client, stuff->srcCmap,
  2682. RT_COLORMAP, SecurityReadAccess|SecurityWriteAccess)) )
  2683. {
  2684. result = CopyColormapAndFree(mid, pSrcMap, client->index);
  2685. if (client->noClientException != Success)
  2686. return(client->noClientException);
  2687. else
  2688. return(result);
  2689. }
  2690. else
  2691. {
  2692. client->errorValue = stuff->srcCmap;
  2693. return(BadColor);
  2694. }
  2695. }
  2696. int
  2697. ProcInstallColormap(client)
  2698. register ClientPtr client;
  2699. {
  2700. ColormapPtr pcmp;
  2701. REQUEST(xResourceReq);
  2702. REQUEST_SIZE_MATCH(xResourceReq);
  2703. pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->id,
  2704. RT_COLORMAP, SecurityReadAccess);
  2705. if (pcmp)
  2706. {
  2707. (*(pcmp->pScreen->InstallColormap)) (pcmp);
  2708. return (client->noClientException);
  2709. }
  2710. else
  2711. {
  2712. client->errorValue = stuff->id;
  2713. return (BadColor);
  2714. }
  2715. }
  2716. int
  2717. ProcUninstallColormap(client)
  2718. register ClientPtr client;
  2719. {
  2720. ColormapPtr pcmp;
  2721. REQUEST(xResourceReq);
  2722. REQUEST_SIZE_MATCH(xResourceReq);
  2723. pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->id,
  2724. RT_COLORMAP, SecurityReadAccess);
  2725. if (pcmp)
  2726. {
  2727. if(pcmp->mid != pcmp->pScreen->defColormap)
  2728. (*(pcmp->pScreen->UninstallColormap)) (pcmp);
  2729. return (client->noClientException);
  2730. }
  2731. else
  2732. {
  2733. client->errorValue = stuff->id;
  2734. return (BadColor);
  2735. }
  2736. }
  2737. int
  2738. ProcListInstalledColormaps(client)
  2739. register ClientPtr client;
  2740. {
  2741. xListInstalledColormapsReply *preply;
  2742. int nummaps;
  2743. WindowPtr pWin;
  2744. REQUEST(xResourceReq);
  2745. REQUEST_SIZE_MATCH(xResourceReq);
  2746. pWin = (WindowPtr)SecurityLookupWindow(stuff->id, client,
  2747. SecurityReadAccess);
  2748. if (!pWin)
  2749. return(BadWindow);
  2750. preply = (xListInstalledColormapsReply *)
  2751. ALLOCATE_LOCAL(sizeof(xListInstalledColormapsReply) +
  2752. pWin->drawable.pScreen->maxInstalledCmaps *
  2753. sizeof(Colormap));
  2754. if(!preply)
  2755. return(BadAlloc);
  2756. preply->type = X_Reply;
  2757. preply->sequenceNumber = client->sequence;
  2758. nummaps = (*pWin->drawable.pScreen->ListInstalledColormaps)
  2759. (pWin->drawable.pScreen, (Colormap *)&preply[1]);
  2760. preply->nColormaps = nummaps;
  2761. preply->length = nummaps;
  2762. WriteReplyToClient(client, sizeof (xListInstalledColormapsReply), preply);
  2763. client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write;
  2764. WriteSwappedDataToClient(client, nummaps * sizeof(Colormap), &preply[1]);
  2765. DEALLOCATE_LOCAL(preply);
  2766. return(client->noClientException);
  2767. }
  2768. int
  2769. ProcAllocColor(client)
  2770. register ClientPtr client;
  2771. {
  2772. ColormapPtr pmap;
  2773. int retval;
  2774. xAllocColorReply acr;
  2775. REQUEST(xAllocColorReq);
  2776. REQUEST_SIZE_MATCH(xAllocColorReq);
  2777. pmap = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap,
  2778. RT_COLORMAP, SecurityWriteAccess);
  2779. if (pmap)
  2780. {
  2781. #ifdef LBX
  2782. /*
  2783. * If the colormap is grabbed by a proxy, the server will have
  2784. * to regain control over the colormap. This AllocColor request
  2785. * will be handled after the server gets back the colormap control.
  2786. */
  2787. if (LbxCheckColorRequest (client, pmap, (xReq *) stuff))
  2788. return Success;
  2789. #endif
  2790. acr.type = X_Reply;
  2791. acr.length = 0;
  2792. acr.sequenceNumber = client->sequence;
  2793. acr.red = stuff->red;
  2794. acr.green = stuff->green;
  2795. acr.blue = stuff->blue;
  2796. acr.pixel = 0;
  2797. if( (retval = AllocColor(pmap, &acr.red, &acr.green, &acr.blue,
  2798. &acr.pixel, client->index)) )
  2799. {
  2800. if (client->noClientException != Success)
  2801. return(client->noClientException);
  2802. else
  2803. return (retval);
  2804. }
  2805. #ifdef PANORAMIX
  2806. if (noPanoramiXExtension || !pmap->pScreen->myNum)
  2807. #endif
  2808. WriteReplyToClient(client, sizeof(xAllocColorReply), &acr);
  2809. return (client->noClientException);
  2810. }
  2811. else
  2812. {
  2813. client->errorValue = stuff->cmap;
  2814. return (BadColor);
  2815. }
  2816. }
  2817. int
  2818. ProcAllocNamedColor (client)
  2819. register ClientPtr client;
  2820. {
  2821. ColormapPtr pcmp;
  2822. REQUEST(xAllocNamedColorReq);
  2823. REQUEST_FIXED_SIZE(xAllocNamedColorReq, stuff->nbytes);
  2824. pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap,
  2825. RT_COLORMAP, SecurityWriteAccess);
  2826. if (pcmp)
  2827. {
  2828. int retval;
  2829. xAllocNamedColorReply ancr;
  2830. #ifdef LBX
  2831. /*
  2832. * If the colormap is grabbed by a proxy, the server will have
  2833. * to regain control over the colormap. This AllocNamedColor request
  2834. * will be handled after the server gets back the colormap control.
  2835. */
  2836. if (LbxCheckColorRequest (client, pcmp, (xReq *) stuff))
  2837. return Success;
  2838. #endif
  2839. ancr.type = X_Reply;
  2840. ancr.length = 0;
  2841. ancr.sequenceNumber = client->sequence;
  2842. if(OsLookupColor(pcmp->pScreen->myNum, (char *)&stuff[1], stuff->nbytes,
  2843. &ancr.exactRed, &ancr.exactGreen, &ancr.exactBlue))
  2844. {
  2845. ancr.screenRed = ancr.exactRed;
  2846. ancr.screenGreen = ancr.exactGreen;
  2847. ancr.screenBlue = ancr.exactBlue;
  2848. ancr.pixel = 0;
  2849. if( (retval = AllocColor(pcmp,
  2850. &ancr.screenRed, &ancr.screenGreen, &ancr.screenBlue,
  2851. &ancr.pixel, client->index)) )
  2852. {
  2853. if (client->noClientException != Success)
  2854. return(client->noClientException);
  2855. else
  2856. return(retval);
  2857. }
  2858. #ifdef PANORAMIX
  2859. if (noPanoramiXExtension || !pcmp->pScreen->myNum)
  2860. #endif
  2861. WriteReplyToClient(client, sizeof (xAllocNamedColorReply), &ancr);
  2862. return (client->noClientException);
  2863. }
  2864. else
  2865. return(BadName);
  2866. }
  2867. else
  2868. {
  2869. client->errorValue = stuff->cmap;
  2870. return (BadColor);
  2871. }
  2872. }
  2873. int
  2874. ProcAllocColorCells (client)
  2875. register ClientPtr client;
  2876. {
  2877. ColormapPtr pcmp;
  2878. REQUEST(xAllocColorCellsReq);
  2879. REQUEST_SIZE_MATCH(xAllocColorCellsReq);
  2880. pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap,
  2881. RT_COLORMAP, SecurityWriteAccess);
  2882. if (pcmp)
  2883. {
  2884. xAllocColorCellsReply accr;
  2885. int npixels, nmasks, retval;
  2886. long length;
  2887. Pixel *ppixels, *pmasks;
  2888. #ifdef LBX
  2889. /*
  2890. * If the colormap is grabbed by a proxy, the server will have
  2891. * to regain control over the colormap. This AllocColorCells request
  2892. * will be handled after the server gets back the colormap control.
  2893. */
  2894. if (LbxCheckColorRequest (client, pcmp, (xReq *) stuff))
  2895. return Success;
  2896. #endif
  2897. npixels = stuff->colors;
  2898. if (!npixels)
  2899. {
  2900. client->errorValue = npixels;
  2901. return (BadValue);
  2902. }
  2903. if (stuff->contiguous != xTrue && stuff->contiguous != xFalse)
  2904. {
  2905. client->errorValue = stuff->contiguous;
  2906. return (BadValue);
  2907. }
  2908. nmasks = stuff->planes;
  2909. length = ((long)npixels + (long)nmasks) * sizeof(Pixel);
  2910. ppixels = (Pixel *)ALLOCATE_LOCAL(length);
  2911. if(!ppixels)
  2912. return(BadAlloc);
  2913. pmasks = ppixels + npixels;
  2914. if( (retval = AllocColorCells(client->index, pcmp, npixels, nmasks,
  2915. (Bool)stuff->contiguous, ppixels, pmasks)) )
  2916. {
  2917. DEALLOCATE_LOCAL(ppixels);
  2918. if (client->noClientException != Success)
  2919. return(client->noClientException);
  2920. else
  2921. return(retval);
  2922. }
  2923. #ifdef PANORAMIX
  2924. if (noPanoramiXExtension || !pcmp->pScreen->myNum)
  2925. #endif
  2926. {
  2927. accr.type = X_Reply;
  2928. accr.length = length >> 2;
  2929. accr.sequenceNumber = client->sequence;
  2930. accr.nPixels = npixels;
  2931. accr.nMasks = nmasks;
  2932. WriteReplyToClient(client, sizeof (xAllocColorCellsReply), &accr);
  2933. client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write;
  2934. WriteSwappedDataToClient(client, length, ppixels);
  2935. }
  2936. DEALLOCATE_LOCAL(ppixels);
  2937. return (client->noClientException);
  2938. }
  2939. else
  2940. {
  2941. client->errorValue = stuff->cmap;
  2942. return (BadColor);
  2943. }
  2944. }
  2945. int
  2946. ProcAllocColorPlanes(client)
  2947. register ClientPtr client;
  2948. {
  2949. ColormapPtr pcmp;
  2950. REQUEST(xAllocColorPlanesReq);
  2951. REQUEST_SIZE_MATCH(xAllocColorPlanesReq);
  2952. pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap,
  2953. RT_COLORMAP, SecurityWriteAccess);
  2954. if (pcmp)
  2955. {
  2956. xAllocColorPlanesReply acpr;
  2957. int npixels, retval;
  2958. long length;
  2959. Pixel *ppixels;
  2960. #ifdef LBX
  2961. /*
  2962. * If the colormap is grabbed by a proxy, the server will have
  2963. * to regain control over the colormap. This AllocColorPlanes request
  2964. * will be handled after the server gets back the colormap control.
  2965. */
  2966. if (LbxCheckColorRequest (client, pcmp, (xReq *) stuff))
  2967. return Success;
  2968. #endif
  2969. npixels = stuff->colors;
  2970. if (!npixels)
  2971. {
  2972. client->errorValue = npixels;
  2973. return (BadValue);
  2974. }
  2975. if (stuff->contiguous != xTrue && stuff->contiguous != xFalse)
  2976. {
  2977. client->errorValue = stuff->contiguous;
  2978. return (BadValue);
  2979. }
  2980. acpr.type = X_Reply;
  2981. acpr.sequenceNumber = client->sequence;
  2982. acpr.nPixels = npixels;
  2983. length = (long)npixels * sizeof(Pixel);
  2984. ppixels = (Pixel *)ALLOCATE_LOCAL(length);
  2985. if(!ppixels)
  2986. return(BadAlloc);
  2987. if( (retval = AllocColorPlanes(client->index, pcmp, npixels,
  2988. (int)stuff->red, (int)stuff->green, (int)stuff->blue,
  2989. (Bool)stuff->contiguous, ppixels,
  2990. &acpr.redMask, &acpr.greenMask, &acpr.blueMask)) )
  2991. {
  2992. DEALLOCATE_LOCAL(ppixels);
  2993. if (client->noClientException != Success)
  2994. return(client->noClientException);
  2995. else
  2996. return(retval);
  2997. }
  2998. acpr.length = length >> 2;
  2999. #ifdef PANORAMIX
  3000. if (noPanoramiXExtension || !pcmp->pScreen->myNum)
  3001. #endif
  3002. {
  3003. WriteReplyToClient(client, sizeof(xAllocColorPlanesReply), &acpr);
  3004. client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write;
  3005. WriteSwappedDataToClient(client, length, ppixels);
  3006. }
  3007. DEALLOCATE_LOCAL(ppixels);
  3008. return (client->noClientException);
  3009. }
  3010. else
  3011. {
  3012. client->errorValue = stuff->cmap;
  3013. return (BadColor);
  3014. }
  3015. }
  3016. int
  3017. ProcFreeColors (client)
  3018. register ClientPtr client;
  3019. {
  3020. ColormapPtr pcmp;
  3021. REQUEST(xFreeColorsReq);
  3022. REQUEST_AT_LEAST_SIZE(xFreeColorsReq);
  3023. pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap,
  3024. RT_COLORMAP, SecurityWriteAccess);
  3025. if (pcmp)
  3026. {
  3027. int count;
  3028. int retval;
  3029. if(pcmp->flags & AllAllocated)
  3030. return(BadAccess);
  3031. count = ((client->req_len << 2)- sizeof(xFreeColorsReq)) >> 2;
  3032. retval = FreeColors(pcmp, client->index, count,
  3033. (Pixel *)&stuff[1], (Pixel)stuff->planeMask);
  3034. if (client->noClientException != Success)
  3035. return(client->noClientException);
  3036. else
  3037. {
  3038. client->errorValue = clientErrorValue;
  3039. return(retval);
  3040. }
  3041. }
  3042. else
  3043. {
  3044. client->errorValue = stuff->cmap;
  3045. return (BadColor);
  3046. }
  3047. }
  3048. int
  3049. ProcStoreColors (client)
  3050. register ClientPtr client;
  3051. {
  3052. ColormapPtr pcmp;
  3053. REQUEST(xStoreColorsReq);
  3054. REQUEST_AT_LEAST_SIZE(xStoreColorsReq);
  3055. pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap,
  3056. RT_COLORMAP, SecurityWriteAccess);
  3057. if (pcmp)
  3058. {
  3059. int count;
  3060. int retval;
  3061. count = (client->req_len << 2) - sizeof(xStoreColorsReq);
  3062. if (count % sizeof(xColorItem))
  3063. return(BadLength);
  3064. count /= sizeof(xColorItem);
  3065. retval = StoreColors(pcmp, count, (xColorItem *)&stuff[1]);
  3066. if (client->noClientException != Success)
  3067. return(client->noClientException);
  3068. else
  3069. {
  3070. client->errorValue = clientErrorValue;
  3071. return(retval);
  3072. }
  3073. }
  3074. else
  3075. {
  3076. client->errorValue = stuff->cmap;
  3077. return (BadColor);
  3078. }
  3079. }
  3080. int
  3081. ProcStoreNamedColor (client)
  3082. register ClientPtr client;
  3083. {
  3084. ColormapPtr pcmp;
  3085. REQUEST(xStoreNamedColorReq);
  3086. REQUEST_FIXED_SIZE(xStoreNamedColorReq, stuff->nbytes);
  3087. pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap,
  3088. RT_COLORMAP, SecurityWriteAccess);
  3089. if (pcmp)
  3090. {
  3091. xColorItem def;
  3092. int retval;
  3093. if(OsLookupColor(pcmp->pScreen->myNum, (char *)&stuff[1],
  3094. stuff->nbytes, &def.red, &def.green, &def.blue))
  3095. {
  3096. def.flags = stuff->flags;
  3097. def.pixel = stuff->pixel;
  3098. retval = StoreColors(pcmp, 1, &def);
  3099. if (client->noClientException != Success)
  3100. return(client->noClientException);
  3101. else
  3102. return(retval);
  3103. }
  3104. return (BadName);
  3105. }
  3106. else
  3107. {
  3108. client->errorValue = stuff->cmap;
  3109. return (BadColor);
  3110. }
  3111. }
  3112. int
  3113. ProcQueryColors(client)
  3114. register ClientPtr client;
  3115. {
  3116. ColormapPtr pcmp;
  3117. REQUEST(xQueryColorsReq);
  3118. REQUEST_AT_LEAST_SIZE(xQueryColorsReq);
  3119. pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap,
  3120. RT_COLORMAP, SecurityReadAccess);
  3121. if (pcmp)
  3122. {
  3123. int count, retval;
  3124. xrgb *prgbs;
  3125. xQueryColorsReply qcr;
  3126. count = ((client->req_len << 2) - sizeof(xQueryColorsReq)) >> 2;
  3127. prgbs = (xrgb *)ALLOCATE_LOCAL(count * sizeof(xrgb));
  3128. if(!prgbs && count)
  3129. return(BadAlloc);
  3130. if( (retval = QueryColors(pcmp, count, (Pixel *)&stuff[1], prgbs)) )
  3131. {
  3132. if (prgbs) DEALLOCATE_LOCAL(prgbs);
  3133. if (client->noClientException != Success)
  3134. return(client->noClientException);
  3135. else
  3136. {
  3137. client->errorValue = clientErrorValue;
  3138. return (retval);
  3139. }
  3140. }
  3141. qcr.type = X_Reply;
  3142. qcr.length = (count * sizeof(xrgb)) >> 2;
  3143. qcr.sequenceNumber = client->sequence;
  3144. qcr.nColors = count;
  3145. WriteReplyToClient(client, sizeof(xQueryColorsReply), &qcr);
  3146. if (count)
  3147. {
  3148. client->pSwapReplyFunc = (ReplySwapPtr) SQColorsExtend;
  3149. WriteSwappedDataToClient(client, count * sizeof(xrgb), prgbs);
  3150. }
  3151. if (prgbs) DEALLOCATE_LOCAL(prgbs);
  3152. return(client->noClientException);
  3153. }
  3154. else
  3155. {
  3156. client->errorValue = stuff->cmap;
  3157. return (BadColor);
  3158. }
  3159. }
  3160. int
  3161. ProcLookupColor(client)
  3162. register ClientPtr client;
  3163. {
  3164. ColormapPtr pcmp;
  3165. REQUEST(xLookupColorReq);
  3166. REQUEST_FIXED_SIZE(xLookupColorReq, stuff->nbytes);
  3167. pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap,
  3168. RT_COLORMAP, SecurityReadAccess);
  3169. if (pcmp)
  3170. {
  3171. xLookupColorReply lcr;
  3172. if(OsLookupColor(pcmp->pScreen->myNum, (char *)&stuff[1], stuff->nbytes,
  3173. &lcr.exactRed, &lcr.exactGreen, &lcr.exactBlue))
  3174. {
  3175. lcr.type = X_Reply;
  3176. lcr.length = 0;
  3177. lcr.sequenceNumber = client->sequence;
  3178. lcr.screenRed = lcr.exactRed;
  3179. lcr.screenGreen = lcr.exactGreen;
  3180. lcr.screenBlue = lcr.exactBlue;
  3181. (*pcmp->pScreen->ResolveColor)(&lcr.screenRed,
  3182. &lcr.screenGreen,
  3183. &lcr.screenBlue,
  3184. pcmp->pVisual);
  3185. WriteReplyToClient(client, sizeof(xLookupColorReply), &lcr);
  3186. return(client->noClientException);
  3187. }
  3188. return (BadName);
  3189. }
  3190. else
  3191. {
  3192. client->errorValue = stuff->cmap;
  3193. return (BadColor);
  3194. }
  3195. }
  3196. int
  3197. ProcCreateCursor( client)
  3198. register ClientPtr client;
  3199. {
  3200. CursorPtr pCursor;
  3201. register PixmapPtr src;
  3202. register PixmapPtr msk;
  3203. unsigned char * srcbits;
  3204. unsigned char * mskbits;
  3205. unsigned short width, height;
  3206. long n;
  3207. CursorMetricRec cm;
  3208. REQUEST(xCreateCursorReq);
  3209. REQUEST_SIZE_MATCH(xCreateCursorReq);
  3210. LEGAL_NEW_RESOURCE(stuff->cid, client);
  3211. src = (PixmapPtr)SecurityLookupIDByType(client, stuff->source,
  3212. RT_PIXMAP, SecurityReadAccess);
  3213. msk = (PixmapPtr)SecurityLookupIDByType(client, stuff->mask,
  3214. RT_PIXMAP, SecurityReadAccess);
  3215. if ( src == (PixmapPtr)NULL)
  3216. {
  3217. client->errorValue = stuff->source;
  3218. return (BadPixmap);
  3219. }
  3220. if ( msk == (PixmapPtr)NULL)
  3221. {
  3222. if (stuff->mask != None)
  3223. {
  3224. client->errorValue = stuff->mask;
  3225. return (BadPixmap);
  3226. }
  3227. }
  3228. else if ( src->drawable.width != msk->drawable.width
  3229. || src->drawable.height != msk->drawable.height
  3230. || src->drawable.depth != 1
  3231. || msk->drawable.depth != 1)
  3232. return (BadMatch);
  3233. width = src->drawable.width;
  3234. height = src->drawable.height;
  3235. if ( stuff->x > width
  3236. || stuff->y > height )
  3237. return (BadMatch);
  3238. n = BitmapBytePad(width)*height;
  3239. srcbits = (unsigned char *)xalloc(n);
  3240. if (!srcbits)
  3241. return (BadAlloc);
  3242. mskbits = (unsigned char *)xalloc(n);
  3243. if (!mskbits)
  3244. {
  3245. xfree(srcbits);
  3246. return (BadAlloc);
  3247. }
  3248. /* zeroing the (pad) bits helps some ddx cursor handling */
  3249. bzero((char *)srcbits, n);
  3250. (* src->drawable.pScreen->GetImage)( (DrawablePtr)src, 0, 0, width, height,
  3251. XYPixmap, 1, (pointer)srcbits);
  3252. if ( msk == (PixmapPtr)NULL)
  3253. {
  3254. register unsigned char *bits = mskbits;
  3255. while (--n >= 0)
  3256. *bits++ = ~0;
  3257. }
  3258. else
  3259. {
  3260. /* zeroing the (pad) bits helps some ddx cursor handling */
  3261. bzero((char *)mskbits, n);
  3262. (* msk->drawable.pScreen->GetImage)( (DrawablePtr)msk, 0, 0, width,
  3263. height, XYPixmap, 1, (pointer)mskbits);
  3264. }
  3265. cm.width = width;
  3266. cm.height = height;
  3267. cm.xhot = stuff->x;
  3268. cm.yhot = stuff->y;
  3269. pCursor = AllocCursor( srcbits, mskbits, &cm,
  3270. stuff->foreRed, stuff->foreGreen, stuff->foreBlue,
  3271. stuff->backRed, stuff->backGreen, stuff->backBlue);
  3272. if (pCursor && AddResource(stuff->cid, RT_CURSOR, (pointer)pCursor))
  3273. {
  3274. #ifdef TEST
  3275. fprintf(stderr, "ProcCreateCursor: Created cursor at [%p].\n", (void *) pCursor);
  3276. #endif
  3277. return (client->noClientException);
  3278. }
  3279. return BadAlloc;
  3280. }
  3281. int
  3282. ProcCreateGlyphCursor( client)
  3283. register ClientPtr client;
  3284. {
  3285. CursorPtr pCursor;
  3286. int res;
  3287. REQUEST(xCreateGlyphCursorReq);
  3288. REQUEST_SIZE_MATCH(xCreateGlyphCursorReq);
  3289. LEGAL_NEW_RESOURCE(stuff->cid, client);
  3290. res = AllocGlyphCursor(stuff->source, stuff->sourceChar,
  3291. stuff->mask, stuff->maskChar,
  3292. stuff->foreRed, stuff->foreGreen, stuff->foreBlue,
  3293. stuff->backRed, stuff->backGreen, stuff->backBlue,
  3294. &pCursor, client);
  3295. if (res != Success)
  3296. return res;
  3297. if (AddResource(stuff->cid, RT_CURSOR, (pointer)pCursor))
  3298. return client->noClientException;
  3299. return BadAlloc;
  3300. }
  3301. int
  3302. ProcFreeCursor(client)
  3303. register ClientPtr client;
  3304. {
  3305. CursorPtr pCursor;
  3306. REQUEST(xResourceReq);
  3307. REQUEST_SIZE_MATCH(xResourceReq);
  3308. pCursor = (CursorPtr)SecurityLookupIDByType(client, stuff->id,
  3309. RT_CURSOR, SecurityDestroyAccess);
  3310. if (pCursor)
  3311. {
  3312. FreeResource(stuff->id, RT_NONE);
  3313. return (client->noClientException);
  3314. }
  3315. else
  3316. {
  3317. client->errorValue = stuff->id;
  3318. return (BadCursor);
  3319. }
  3320. }
  3321. int
  3322. ProcQueryBestSize (client)
  3323. register ClientPtr client;
  3324. {
  3325. xQueryBestSizeReply reply;
  3326. register DrawablePtr pDraw;
  3327. ScreenPtr pScreen;
  3328. REQUEST(xQueryBestSizeReq);
  3329. REQUEST_SIZE_MATCH(xQueryBestSizeReq);
  3330. if ((stuff->class != CursorShape) &&
  3331. (stuff->class != TileShape) &&
  3332. (stuff->class != StippleShape))
  3333. {
  3334. client->errorValue = stuff->class;
  3335. return(BadValue);
  3336. }
  3337. SECURITY_VERIFY_GEOMETRABLE (pDraw, stuff->drawable, client,
  3338. SecurityReadAccess);
  3339. if (stuff->class != CursorShape && pDraw->type == UNDRAWABLE_WINDOW)
  3340. return (BadMatch);
  3341. pScreen = pDraw->pScreen;
  3342. (* pScreen->QueryBestSize)(stuff->class, &stuff->width,
  3343. &stuff->height, pScreen);
  3344. reply.type = X_Reply;
  3345. reply.length = 0;
  3346. reply.sequenceNumber = client->sequence;
  3347. reply.width = stuff->width;
  3348. reply.height = stuff->height;
  3349. WriteReplyToClient(client, sizeof(xQueryBestSizeReply), &reply);
  3350. return (client->noClientException);
  3351. }
  3352. int
  3353. ProcSetScreenSaver (client)
  3354. register ClientPtr client;
  3355. {
  3356. int blankingOption, exposureOption;
  3357. REQUEST(xSetScreenSaverReq);
  3358. REQUEST_SIZE_MATCH(xSetScreenSaverReq);
  3359. blankingOption = stuff->preferBlank;
  3360. if ((blankingOption != DontPreferBlanking) &&
  3361. (blankingOption != PreferBlanking) &&
  3362. (blankingOption != DefaultBlanking))
  3363. {
  3364. client->errorValue = blankingOption;
  3365. return BadValue;
  3366. }
  3367. exposureOption = stuff->allowExpose;
  3368. if ((exposureOption != DontAllowExposures) &&
  3369. (exposureOption != AllowExposures) &&
  3370. (exposureOption != DefaultExposures))
  3371. {
  3372. client->errorValue = exposureOption;
  3373. return BadValue;
  3374. }
  3375. if (stuff->timeout < -1)
  3376. {
  3377. client->errorValue = stuff->timeout;
  3378. return BadValue;
  3379. }
  3380. if (stuff->interval < -1)
  3381. {
  3382. client->errorValue = stuff->interval;
  3383. return BadValue;
  3384. }
  3385. /*
  3386. * The NX agent uses the screen saver procedure
  3387. * to monitor the user activities and launch its
  3388. * handlers (like timeout feature), so we can't
  3389. * always allow the clients to change our values.
  3390. */
  3391. #ifdef TEST
  3392. fprintf(stderr, "ProcSetScreenSaver: Called with timeout [%d] interval [%d] Blanking [%d] Exposure [%d].\n",
  3393. stuff -> timeout, stuff -> interval, blankingOption, exposureOption);
  3394. #endif
  3395. if (nxagentOption(Timeout) == 0)
  3396. {
  3397. if (blankingOption == DefaultBlanking)
  3398. {
  3399. ScreenSaverBlanking = defaultScreenSaverBlanking;
  3400. }
  3401. else
  3402. {
  3403. ScreenSaverBlanking = blankingOption;
  3404. }
  3405. if (exposureOption == DefaultExposures)
  3406. {
  3407. ScreenSaverAllowExposures = defaultScreenSaverAllowExposures;
  3408. }
  3409. else
  3410. {
  3411. ScreenSaverAllowExposures = exposureOption;
  3412. }
  3413. if (stuff->timeout >= 0)
  3414. {
  3415. ScreenSaverTime = stuff->timeout * MILLI_PER_SECOND;
  3416. }
  3417. else
  3418. {
  3419. ScreenSaverTime = defaultScreenSaverTime;
  3420. }
  3421. if (stuff->interval >= 0)
  3422. {
  3423. ScreenSaverInterval = stuff->interval * MILLI_PER_SECOND;
  3424. }
  3425. else
  3426. {
  3427. ScreenSaverInterval = defaultScreenSaverInterval;
  3428. }
  3429. }
  3430. #ifdef TEST
  3431. else
  3432. {
  3433. fprintf(stderr, "ProcSetScreenSaver: Keeping auto-disconnect timeout set to [%d] seconds.\n",
  3434. nxagentOption(Timeout));
  3435. }
  3436. #endif
  3437. return (client->noClientException);
  3438. }
  3439. int
  3440. ProcGetScreenSaver(client)
  3441. register ClientPtr client;
  3442. {
  3443. xGetScreenSaverReply rep;
  3444. REQUEST_SIZE_MATCH(xReq);
  3445. rep.type = X_Reply;
  3446. rep.length = 0;
  3447. rep.sequenceNumber = client->sequence;
  3448. rep.timeout = ScreenSaverTime / MILLI_PER_SECOND;
  3449. rep.interval = ScreenSaverInterval / MILLI_PER_SECOND;
  3450. rep.preferBlanking = ScreenSaverBlanking;
  3451. rep.allowExposures = ScreenSaverAllowExposures;
  3452. WriteReplyToClient(client, sizeof(xGetScreenSaverReply), &rep);
  3453. return (client->noClientException);
  3454. }
  3455. int
  3456. ProcChangeHosts(client)
  3457. register ClientPtr client;
  3458. {
  3459. REQUEST(xChangeHostsReq);
  3460. int result;
  3461. REQUEST_FIXED_SIZE(xChangeHostsReq, stuff->hostLength);
  3462. if(stuff->mode == HostInsert)
  3463. result = AddHost(client, (int)stuff->hostFamily,
  3464. stuff->hostLength, (pointer)&stuff[1]);
  3465. else if (stuff->mode == HostDelete)
  3466. result = RemoveHost(client, (int)stuff->hostFamily,
  3467. stuff->hostLength, (pointer)&stuff[1]);
  3468. else
  3469. {
  3470. client->errorValue = stuff->mode;
  3471. return BadValue;
  3472. }
  3473. if (!result)
  3474. result = client->noClientException;
  3475. return (result);
  3476. }
  3477. int
  3478. ProcListHosts(client)
  3479. register ClientPtr client;
  3480. {
  3481. xListHostsReply reply;
  3482. int len, nHosts, result;
  3483. pointer pdata;
  3484. /* REQUEST(xListHostsReq); */
  3485. REQUEST_SIZE_MATCH(xListHostsReq);
  3486. #ifdef XCSECURITY
  3487. /* untrusted clients can't list hosts */
  3488. if (client->trustLevel != XSecurityClientTrusted)
  3489. {
  3490. SecurityAudit("client %d attempted to list hosts\n", client->index);
  3491. return BadAccess;
  3492. }
  3493. #endif
  3494. result = GetHosts(&pdata, &nHosts, &len, &reply.enabled);
  3495. if (result != Success)
  3496. return(result);
  3497. reply.type = X_Reply;
  3498. reply.sequenceNumber = client->sequence;
  3499. reply.nHosts = nHosts;
  3500. reply.length = len >> 2;
  3501. WriteReplyToClient(client, sizeof(xListHostsReply), &reply);
  3502. if (nHosts)
  3503. {
  3504. client->pSwapReplyFunc = (ReplySwapPtr) SLHostsExtend;
  3505. WriteSwappedDataToClient(client, len, pdata);
  3506. }
  3507. xfree(pdata);
  3508. return (client->noClientException);
  3509. }
  3510. int
  3511. ProcChangeAccessControl(client)
  3512. register ClientPtr client;
  3513. {
  3514. int result;
  3515. REQUEST(xSetAccessControlReq);
  3516. REQUEST_SIZE_MATCH(xSetAccessControlReq);
  3517. if ((stuff->mode != EnableAccess) && (stuff->mode != DisableAccess))
  3518. {
  3519. client->errorValue = stuff->mode;
  3520. return BadValue;
  3521. }
  3522. result = ChangeAccessControl(client, stuff->mode == EnableAccess);
  3523. if (!result)
  3524. result = client->noClientException;
  3525. return (result);
  3526. }
  3527. int
  3528. ProcKillClient(client)
  3529. register ClientPtr client;
  3530. {
  3531. REQUEST(xResourceReq);
  3532. ClientPtr killclient;
  3533. REQUEST_SIZE_MATCH(xResourceReq);
  3534. if (stuff->id == AllTemporary)
  3535. {
  3536. CloseDownRetainedResources();
  3537. return (client->noClientException);
  3538. }
  3539. if ((killclient = LookupClient(stuff->id, client)))
  3540. {
  3541. CloseDownClient(killclient);
  3542. /* if an LBX proxy gets killed, isItTimeToYield will be set */
  3543. if (isItTimeToYield || (client == killclient))
  3544. {
  3545. /* force yield and return Success, so that Dispatch()
  3546. * doesn't try to touch client
  3547. */
  3548. isItTimeToYield = TRUE;
  3549. return (Success);
  3550. }
  3551. return (client->noClientException);
  3552. }
  3553. else
  3554. {
  3555. client->errorValue = stuff->id;
  3556. return (BadValue);
  3557. }
  3558. }
  3559. int
  3560. ProcSetFontPath(client)
  3561. register ClientPtr client;
  3562. {
  3563. unsigned char *ptr;
  3564. unsigned long nbytes, total;
  3565. long nfonts;
  3566. int n, result;
  3567. int error;
  3568. REQUEST(xSetFontPathReq);
  3569. REQUEST_AT_LEAST_SIZE(xSetFontPathReq);
  3570. nbytes = (client->req_len << 2) - sizeof(xSetFontPathReq);
  3571. total = nbytes;
  3572. ptr = (unsigned char *)&stuff[1];
  3573. nfonts = stuff->nFonts;
  3574. while (--nfonts >= 0)
  3575. {
  3576. if ((total == 0) || (total < (n = (*ptr + 1))))
  3577. return(BadLength);
  3578. total -= n;
  3579. ptr += n;
  3580. }
  3581. if (total >= 4)
  3582. return(BadLength);
  3583. result = SetFontPath(client, stuff->nFonts, (unsigned char *)&stuff[1],
  3584. &error);
  3585. if (!result)
  3586. {
  3587. result = client->noClientException;
  3588. client->errorValue = error;
  3589. }
  3590. return (result);
  3591. }
  3592. int
  3593. ProcGetFontPath(client)
  3594. register ClientPtr client;
  3595. {
  3596. xGetFontPathReply reply;
  3597. int stringLens, numpaths;
  3598. unsigned char *bufferStart;
  3599. /* REQUEST (xReq); */
  3600. REQUEST_SIZE_MATCH(xReq);
  3601. bufferStart = GetFontPath(&numpaths, &stringLens);
  3602. reply.type = X_Reply;
  3603. reply.sequenceNumber = client->sequence;
  3604. reply.length = (stringLens + numpaths + 3) >> 2;
  3605. reply.nPaths = numpaths;
  3606. WriteReplyToClient(client, sizeof(xGetFontPathReply), &reply);
  3607. if (stringLens || numpaths)
  3608. (void)WriteToClient(client, stringLens + numpaths, (char *)bufferStart);
  3609. return(client->noClientException);
  3610. }
  3611. int
  3612. ProcChangeCloseDownMode(client)
  3613. register ClientPtr client;
  3614. {
  3615. REQUEST(xSetCloseDownModeReq);
  3616. REQUEST_SIZE_MATCH(xSetCloseDownModeReq);
  3617. if ((stuff->mode == AllTemporary) ||
  3618. (stuff->mode == RetainPermanent) ||
  3619. (stuff->mode == RetainTemporary))
  3620. {
  3621. client->closeDownMode = stuff->mode;
  3622. return (client->noClientException);
  3623. }
  3624. else
  3625. {
  3626. client->errorValue = stuff->mode;
  3627. return (BadValue);
  3628. }
  3629. }
  3630. int ProcForceScreenSaver(client)
  3631. register ClientPtr client;
  3632. {
  3633. REQUEST(xForceScreenSaverReq);
  3634. REQUEST_SIZE_MATCH(xForceScreenSaverReq);
  3635. if ((stuff->mode != ScreenSaverReset) &&
  3636. (stuff->mode != ScreenSaverActive))
  3637. {
  3638. client->errorValue = stuff->mode;
  3639. return BadValue;
  3640. }
  3641. /*
  3642. * The NX agent uses the screen saver procedure
  3643. * to monitor the user activities and launch its
  3644. * handlers (like timeout feature), so we can't
  3645. * always allow the clients to force the screen
  3646. * saver handler execution.
  3647. */
  3648. if (nxagentOption(Timeout) == 0)
  3649. {
  3650. SaveScreens(SCREEN_SAVER_FORCER, (int)stuff->mode);
  3651. }
  3652. #ifdef TEST
  3653. else
  3654. {
  3655. fprintf(stderr, "ProcForceScreenSaver: Ignoring the client request with mode [%d].\n",
  3656. stuff -> mode);
  3657. }
  3658. #endif
  3659. return client->noClientException;
  3660. }
  3661. int ProcNoOperation(client)
  3662. register ClientPtr client;
  3663. {
  3664. REQUEST_AT_LEAST_SIZE(xReq);
  3665. /* noop -- don't do anything */
  3666. return(client->noClientException);
  3667. }
  3668. void
  3669. InitProcVectors(void)
  3670. {
  3671. int i;
  3672. for (i = 0; i<256; i++)
  3673. {
  3674. if(!ProcVector[i])
  3675. {
  3676. ProcVector[i] = SwappedProcVector[i] = ProcBadRequest;
  3677. ReplySwapVector[i] = ReplyNotSwappd;
  3678. }
  3679. #ifdef K5AUTH
  3680. if (!k5_Vector[i])
  3681. {
  3682. k5_Vector[i] = k5_bad;
  3683. }
  3684. #endif
  3685. }
  3686. for(i = LASTEvent; i < 128; i++)
  3687. {
  3688. EventSwapVector[i] = NotImplemented;
  3689. }
  3690. }
  3691. /**********************
  3692. * CloseDownClient
  3693. *
  3694. * Client can either mark his resources destroy or retain. If retained and
  3695. * then killed again, the client is really destroyed.
  3696. *********************/
  3697. void
  3698. CloseDownClient(client)
  3699. register ClientPtr client;
  3700. {
  3701. Bool really_close_down = client->clientGone ||
  3702. client->closeDownMode == DestroyAll;
  3703. /*
  3704. * There must be a better way to hook a
  3705. * call-back function to be called any
  3706. * time a client is going to be closed.
  3707. */
  3708. nxagentClearClipboard(client, NULL);
  3709. /*
  3710. * Need to reset the karma counter and
  3711. * get rid of the pending sync replies.
  3712. */
  3713. nxagentWakeupByReset(client);
  3714. /*
  3715. * Check if the client
  3716. * is a shadow nxagent.
  3717. */
  3718. nxagentCheckIfShadowAgent(client);
  3719. if (!client->clientGone)
  3720. {
  3721. /* ungrab server if grabbing client dies */
  3722. if (grabState != GrabNone && grabClient == client)
  3723. {
  3724. UngrabServer(client);
  3725. }
  3726. BITCLEAR(grabWaiters, client->index);
  3727. DeleteClientFromAnySelections(client);
  3728. ReleaseActiveGrabs(client);
  3729. DeleteClientFontStuff(client);
  3730. if (!really_close_down)
  3731. {
  3732. /* This frees resources that should never be retained
  3733. * no matter what the close down mode is. Actually we
  3734. * could do this unconditionally, but it's probably
  3735. * better not to traverse all the client's resources
  3736. * twice (once here, once a few lines down in
  3737. * FreeClientResources) in the common case of
  3738. * really_close_down == TRUE.
  3739. */
  3740. FreeClientNeverRetainResources(client);
  3741. client->clientState = ClientStateRetained;
  3742. if (ClientStateCallback)
  3743. {
  3744. NewClientInfoRec clientinfo;
  3745. clientinfo.client = client;
  3746. clientinfo.prefix = (xConnSetupPrefix *)NULL;
  3747. clientinfo.setup = (xConnSetup *) NULL;
  3748. CallCallbacks((&ClientStateCallback), (pointer)&clientinfo);
  3749. }
  3750. }
  3751. client->clientGone = TRUE; /* so events aren't sent to client */
  3752. if (ClientIsAsleep(client))
  3753. ClientSignal (client);
  3754. ProcessWorkQueueZombies();
  3755. #ifdef LBX
  3756. ProcessQTagZombies();
  3757. #endif
  3758. CloseDownConnection(client);
  3759. /* If the client made it to the Running stage, nClients has
  3760. * been incremented on its behalf, so we need to decrement it
  3761. * now. If it hasn't gotten to Running, nClients has *not*
  3762. * been incremented, so *don't* decrement it.
  3763. */
  3764. if (client->clientState != ClientStateInitial &&
  3765. client->clientState != ClientStateAuthenticating )
  3766. {
  3767. --nClients;
  3768. }
  3769. }
  3770. if (really_close_down)
  3771. {
  3772. if (client->clientState == ClientStateRunning && nClients == 0)
  3773. dispatchException |= dispatchExceptionAtReset;
  3774. client->clientState = ClientStateGone;
  3775. if (ClientStateCallback)
  3776. {
  3777. NewClientInfoRec clientinfo;
  3778. clientinfo.client = client;
  3779. clientinfo.prefix = (xConnSetupPrefix *)NULL;
  3780. clientinfo.setup = (xConnSetup *) NULL;
  3781. CallCallbacks((&ClientStateCallback), (pointer)&clientinfo);
  3782. }
  3783. FreeClientResources(client);
  3784. if (client->index < nextFreeClientID)
  3785. nextFreeClientID = client->index;
  3786. clients[client->index] = NullClient;
  3787. #ifdef SMART_SCHEDULE
  3788. SmartLastClient = NullClient;
  3789. #endif
  3790. xfree(client);
  3791. while (!clients[currentMaxClients-1])
  3792. currentMaxClients--;
  3793. }
  3794. }
  3795. static void
  3796. KillAllClients()
  3797. {
  3798. int i;
  3799. for (i=1; i<currentMaxClients; i++)
  3800. if (clients[i]) {
  3801. /* Make sure Retained clients are released. */
  3802. clients[i]->closeDownMode = DestroyAll;
  3803. CloseDownClient(clients[i]);
  3804. }
  3805. }
  3806. /*********************
  3807. * CloseDownRetainedResources
  3808. *
  3809. * Find all clients that are gone and have terminated in RetainTemporary
  3810. * and destroy their resources.
  3811. *********************/
  3812. void
  3813. CloseDownRetainedResources()
  3814. {
  3815. register int i;
  3816. register ClientPtr client;
  3817. for (i=1; i<currentMaxClients; i++)
  3818. {
  3819. client = clients[i];
  3820. if (client && (client->closeDownMode == RetainTemporary)
  3821. && (client->clientGone))
  3822. CloseDownClient(client);
  3823. }
  3824. }
  3825. void InitClient(client, i, ospriv)
  3826. ClientPtr client;
  3827. int i;
  3828. pointer ospriv;
  3829. {
  3830. client->index = i;
  3831. client->sequence = 0;
  3832. client->clientAsMask = ((Mask)i) << CLIENTOFFSET;
  3833. client->clientGone = FALSE;
  3834. if (i)
  3835. {
  3836. client->closeDownMode = DestroyAll;
  3837. client->lastDrawable = (DrawablePtr)WindowTable[0];
  3838. client->lastDrawableID = WindowTable[0]->drawable.id;
  3839. }
  3840. else
  3841. {
  3842. client->closeDownMode = RetainPermanent;
  3843. client->lastDrawable = (DrawablePtr)NULL;
  3844. client->lastDrawableID = INVALID;
  3845. }
  3846. client->lastGC = (GCPtr) NULL;
  3847. client->lastGCID = INVALID;
  3848. client->numSaved = 0;
  3849. client->saveSet = (pointer *)NULL;
  3850. client->noClientException = Success;
  3851. #ifdef LOG_DEBUG
  3852. client->requestLogIndex = 0;
  3853. #endif
  3854. client->requestVector = InitialVector;
  3855. client->osPrivate = ospriv;
  3856. client->swapped = FALSE;
  3857. client->big_requests = FALSE;
  3858. client->priority = 0;
  3859. client->clientState = ClientStateInitial;
  3860. #ifdef XKB
  3861. if (!noXkbExtension) {
  3862. client->xkbClientFlags = 0;
  3863. client->mapNotifyMask = 0;
  3864. QueryMinMaxKeyCodes(&client->minKC,&client->maxKC);
  3865. }
  3866. #endif
  3867. client->replyBytesRemaining = 0;
  3868. #ifdef LBX
  3869. client->readRequest = StandardReadRequestFromClient;
  3870. #endif
  3871. #ifdef XCSECURITY
  3872. client->trustLevel = XSecurityClientTrusted;
  3873. client->CheckAccess = NULL;
  3874. client->authId = 0;
  3875. #endif
  3876. #ifdef XAPPGROUP
  3877. client->appgroup = NULL;
  3878. #endif
  3879. client->fontResFunc = NULL;
  3880. #ifdef SMART_SCHEDULE
  3881. client->smart_priority = 0;
  3882. client->smart_start_tick = SmartScheduleTime;
  3883. client->smart_stop_tick = SmartScheduleTime;
  3884. client->smart_check_tick = SmartScheduleTime;
  3885. #endif
  3886. }
  3887. extern int clientPrivateLen;
  3888. extern unsigned *clientPrivateSizes;
  3889. extern unsigned totalClientSize;
  3890. int
  3891. InitClientPrivates(client)
  3892. ClientPtr client;
  3893. {
  3894. register char *ptr;
  3895. DevUnion *ppriv;
  3896. register unsigned *sizes;
  3897. register unsigned size;
  3898. register int i;
  3899. if (totalClientSize == sizeof(ClientRec))
  3900. ppriv = (DevUnion *)NULL;
  3901. else if (client->index)
  3902. ppriv = (DevUnion *)(client + 1);
  3903. else
  3904. {
  3905. ppriv = (DevUnion *)xalloc(totalClientSize - sizeof(ClientRec));
  3906. if (!ppriv)
  3907. return 0;
  3908. }
  3909. client->devPrivates = ppriv;
  3910. sizes = clientPrivateSizes;
  3911. ptr = (char *)(ppriv + clientPrivateLen);
  3912. for (i = clientPrivateLen; --i >= 0; ppriv++, sizes++)
  3913. {
  3914. if ( (size = *sizes) )
  3915. {
  3916. ppriv->ptr = (pointer)ptr;
  3917. ptr += size;
  3918. }
  3919. else
  3920. ppriv->ptr = (pointer)NULL;
  3921. }
  3922. /*
  3923. * Initialize the private members.
  3924. */
  3925. nxagentInitClientPrivates(client);
  3926. return 1;
  3927. }
  3928. /************************
  3929. * int NextAvailableClient(ospriv)
  3930. *
  3931. * OS dependent portion can't assign client id's because of CloseDownModes.
  3932. * Returns NULL if there are no free clients.
  3933. *************************/
  3934. ClientPtr
  3935. NextAvailableClient(ospriv)
  3936. pointer ospriv;
  3937. {
  3938. register int i;
  3939. register ClientPtr client;
  3940. xReq data;
  3941. i = nextFreeClientID;
  3942. if (i == MAXCLIENTS)
  3943. return (ClientPtr)NULL;
  3944. clients[i] = client = (ClientPtr)xalloc(totalClientSize);
  3945. if (!client)
  3946. return (ClientPtr)NULL;
  3947. InitClient(client, i, ospriv);
  3948. InitClientPrivates(client);
  3949. if (!InitClientResources(client))
  3950. {
  3951. xfree(client);
  3952. return (ClientPtr)NULL;
  3953. }
  3954. data.reqType = 1;
  3955. data.length = (sz_xReq + sz_xConnClientPrefix) >> 2;
  3956. if (!InsertFakeRequest(client, (char *)&data, sz_xReq))
  3957. {
  3958. FreeClientResources(client);
  3959. xfree(client);
  3960. return (ClientPtr)NULL;
  3961. }
  3962. if (i == currentMaxClients)
  3963. currentMaxClients++;
  3964. while ((nextFreeClientID < MAXCLIENTS) && clients[nextFreeClientID])
  3965. nextFreeClientID++;
  3966. if (ClientStateCallback)
  3967. {
  3968. NewClientInfoRec clientinfo;
  3969. clientinfo.client = client;
  3970. clientinfo.prefix = (xConnSetupPrefix *)NULL;
  3971. clientinfo.setup = (xConnSetup *) NULL;
  3972. CallCallbacks((&ClientStateCallback), (pointer)&clientinfo);
  3973. }
  3974. return(client);
  3975. }
  3976. int
  3977. ProcInitialConnection(client)
  3978. register ClientPtr client;
  3979. {
  3980. REQUEST(xReq);
  3981. register xConnClientPrefix *prefix;
  3982. int whichbyte = 1;
  3983. prefix = (xConnClientPrefix *)((char *)stuff + sz_xReq);
  3984. if ((prefix->byteOrder != 'l') && (prefix->byteOrder != 'B'))
  3985. return (client->noClientException = -1);
  3986. if (((*(char *) &whichbyte) && (prefix->byteOrder == 'B')) ||
  3987. (!(*(char *) &whichbyte) && (prefix->byteOrder == 'l')))
  3988. {
  3989. client->swapped = TRUE;
  3990. SwapConnClientPrefix(prefix);
  3991. }
  3992. stuff->reqType = 2;
  3993. stuff->length += ((prefix->nbytesAuthProto + (unsigned)3) >> 2) +
  3994. ((prefix->nbytesAuthString + (unsigned)3) >> 2);
  3995. if (client->swapped)
  3996. {
  3997. swaps(&stuff->length, whichbyte);
  3998. }
  3999. ResetCurrentRequest(client);
  4000. return (client->noClientException);
  4001. }
  4002. #ifdef LBX
  4003. void
  4004. IncrementClientCount()
  4005. {
  4006. nClients++;
  4007. }
  4008. #endif
  4009. int
  4010. SendConnSetup(client, reason)
  4011. register ClientPtr client;
  4012. char *reason;
  4013. {
  4014. register xWindowRoot *root;
  4015. register int i;
  4016. int numScreens;
  4017. char* lConnectionInfo;
  4018. xConnSetupPrefix* lconnSetupPrefix;
  4019. if (reason)
  4020. {
  4021. xConnSetupPrefix csp;
  4022. csp.success = xFalse;
  4023. csp.lengthReason = strlen(reason);
  4024. csp.length = (csp.lengthReason + (unsigned)3) >> 2;
  4025. csp.majorVersion = X_PROTOCOL;
  4026. csp.minorVersion = X_PROTOCOL_REVISION;
  4027. if (client->swapped)
  4028. WriteSConnSetupPrefix(client, &csp);
  4029. else
  4030. (void)WriteToClient(client, sz_xConnSetupPrefix, (char *) &csp);
  4031. (void)WriteToClient(client, (int)csp.lengthReason, reason);
  4032. return (client->noClientException = -1);
  4033. }
  4034. numScreens = screenInfo.numScreens;
  4035. lConnectionInfo = ConnectionInfo;
  4036. lconnSetupPrefix = &connSetupPrefix;
  4037. /* We're about to start speaking X protocol back to the client by
  4038. * sending the connection setup info. This means the authorization
  4039. * step is complete, and we can count the client as an
  4040. * authorized one.
  4041. */
  4042. nClients++;
  4043. client->requestVector = client->swapped ? SwappedProcVector : ProcVector;
  4044. client->sequence = 0;
  4045. #ifdef XAPPGROUP
  4046. XagConnectionInfo (client, &lconnSetupPrefix, &lConnectionInfo, &numScreens);
  4047. #endif
  4048. ((xConnSetup *)lConnectionInfo)->ridBase = client->clientAsMask;
  4049. ((xConnSetup *)lConnectionInfo)->ridMask = RESOURCE_ID_MASK;
  4050. #ifdef MATCH_CLIENT_ENDIAN
  4051. ((xConnSetup *)lConnectionInfo)->imageByteOrder = ClientOrder (client);
  4052. ((xConnSetup *)lConnectionInfo)->bitmapBitOrder = ClientOrder (client);
  4053. #endif
  4054. /* fill in the "currentInputMask" */
  4055. root = (xWindowRoot *)(lConnectionInfo + connBlockScreenStart);
  4056. #ifdef PANORAMIX
  4057. if (noPanoramiXExtension)
  4058. numScreens = screenInfo.numScreens;
  4059. else
  4060. numScreens = ((xConnSetup *)ConnectionInfo)->numRoots;
  4061. #endif
  4062. for (i=0; i<numScreens; i++)
  4063. {
  4064. register unsigned int j;
  4065. register xDepth *pDepth;
  4066. root->currentInputMask = WindowTable[i]->eventMask |
  4067. wOtherEventMasks (WindowTable[i]);
  4068. pDepth = (xDepth *)(root + 1);
  4069. for (j = 0; j < root->nDepths; j++)
  4070. {
  4071. pDepth = (xDepth *)(((char *)(pDepth + 1)) +
  4072. pDepth->nVisuals * sizeof(xVisualType));
  4073. }
  4074. root = (xWindowRoot *)pDepth;
  4075. }
  4076. if (client->swapped)
  4077. {
  4078. WriteSConnSetupPrefix(client, lconnSetupPrefix);
  4079. WriteSConnectionInfo(client,
  4080. (unsigned long)(lconnSetupPrefix->length << 2),
  4081. lConnectionInfo);
  4082. }
  4083. else
  4084. {
  4085. (void)WriteToClient(client, sizeof(xConnSetupPrefix),
  4086. (char *) lconnSetupPrefix);
  4087. (void)WriteToClient(client, (int)(lconnSetupPrefix->length << 2),
  4088. lConnectionInfo);
  4089. }
  4090. client->clientState = ClientStateRunning;
  4091. if (ClientStateCallback)
  4092. {
  4093. NewClientInfoRec clientinfo;
  4094. clientinfo.client = client;
  4095. clientinfo.prefix = lconnSetupPrefix;
  4096. clientinfo.setup = (xConnSetup *)lConnectionInfo;
  4097. CallCallbacks((&ClientStateCallback), (pointer)&clientinfo);
  4098. }
  4099. return (client->noClientException);
  4100. }
  4101. int
  4102. ProcEstablishConnection(client)
  4103. register ClientPtr client;
  4104. {
  4105. char *reason, *auth_proto, *auth_string;
  4106. register xConnClientPrefix *prefix;
  4107. REQUEST(xReq);
  4108. prefix = (xConnClientPrefix *)((char *)stuff + sz_xReq);
  4109. auth_proto = (char *)prefix + sz_xConnClientPrefix;
  4110. auth_string = auth_proto + ((prefix->nbytesAuthProto + 3) & ~3);
  4111. if ((prefix->majorVersion != X_PROTOCOL) ||
  4112. (prefix->minorVersion != X_PROTOCOL_REVISION))
  4113. reason = "Protocol version mismatch";
  4114. else
  4115. reason = ClientAuthorized(client,
  4116. (unsigned short)prefix->nbytesAuthProto,
  4117. auth_proto,
  4118. (unsigned short)prefix->nbytesAuthString,
  4119. auth_string);
  4120. /*
  4121. * If Kerberos is being used for this client, the clientState
  4122. * will be set to ClientStateAuthenticating at this point.
  4123. * More messages need to be exchanged among the X server, Kerberos
  4124. * server, and client to figure out if everyone is authorized.
  4125. * So we don't want to send the connection setup info yet, since
  4126. * the auth step isn't really done.
  4127. */
  4128. if (client->clientState == ClientStateCheckingSecurity)
  4129. client->clientState = ClientStateCheckedSecurity;
  4130. else if (client->clientState != ClientStateAuthenticating)
  4131. return(SendConnSetup(client, reason));
  4132. return(client->noClientException);
  4133. }
  4134. void
  4135. SendErrorToClient(client, majorCode, minorCode, resId, errorCode)
  4136. ClientPtr client;
  4137. unsigned int majorCode;
  4138. unsigned int minorCode;
  4139. XID resId;
  4140. int errorCode;
  4141. {
  4142. xError rep;
  4143. rep.type = X_Error;
  4144. rep.sequenceNumber = client->sequence;
  4145. rep.errorCode = errorCode;
  4146. rep.majorCode = majorCode;
  4147. rep.minorCode = minorCode;
  4148. rep.resourceID = resId;
  4149. WriteEventsToClient (client, 1, (xEvent *)&rep);
  4150. }
  4151. void
  4152. DeleteWindowFromAnySelections(pWin)
  4153. WindowPtr pWin;
  4154. {
  4155. register int i;
  4156. for (i = 0; i< NumCurrentSelections; i++)
  4157. if (CurrentSelections[i].pWin == pWin)
  4158. {
  4159. CurrentSelections[i].pWin = (WindowPtr)NULL;
  4160. CurrentSelections[i].window = None;
  4161. CurrentSelections[i].client = NullClient;
  4162. }
  4163. }
  4164. static void
  4165. DeleteClientFromAnySelections(client)
  4166. ClientPtr client;
  4167. {
  4168. register int i;
  4169. for (i = 0; i< NumCurrentSelections; i++)
  4170. if (CurrentSelections[i].client == client)
  4171. {
  4172. CurrentSelections[i].pWin = (WindowPtr)NULL;
  4173. CurrentSelections[i].window = None;
  4174. CurrentSelections[i].client = NullClient;
  4175. }
  4176. }
  4177. void
  4178. MarkClientException(client)
  4179. ClientPtr client;
  4180. {
  4181. client->noClientException = -1;
  4182. }
  4183. #endif /* #ifdef NXAGENT_UPGRADE */