PageRenderTime 32ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

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

#
C | 4679 lines | 3756 code | 525 blank | 398 comment | 720 complexity | ed6231dd082c7ab6b203d5d589fe6790 MD5 | raw file
Possible License(s): BSD-3-Clause, GPL-2.0, LGPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. /**************************************************************************/
  2. /* */
  3. /* Copyright (c) 2001, 2011 NoMachine, http://www.nomachine.com/. */
  4. /* */
  5. /* NXAGENT, NX protocol compression and NX extensions to this software */
  6. /* are copyright of NoMachine. Redistribution and use of the present */
  7. /* software is allowed according to terms specified in the file LICENSE */
  8. /* which comes in the source distribution. */
  9. /* */
  10. /* Check http://www.nomachine.com/licensing.html for applicability. */
  11. /* */
  12. /* NX and NoMachine are trademarks of Medialogic S.p.A. */
  13. /* */
  14. /* All rights reserved. */
  15. /* */
  16. /**************************************************************************/
  17. /* $XdotOrg: xc/programs/Xserver/dix/dispatch.c,v 1.13 2005/09/13 01:33:19 daniels Exp $ */
  18. /* $Xorg: dispatch.c,v 1.5 2001/02/09 02:04:40 xorgcvs Exp $ */
  19. /************************************************************
  20. Copyright 1987, 1989, 1998 The Open Group
  21. Permission to use, copy, modify, distribute, and sell this software and its
  22. documentation for any purpose is hereby granted without fee, provided that
  23. the above copyright notice appear in all copies and that both that
  24. copyright notice and this permission notice appear in supporting
  25. documentation.
  26. The above copyright notice and this permission notice shall be included in
  27. all copies or substantial portions of the Software.
  28. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  29. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  30. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  31. OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  32. AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  33. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  34. Except as contained in this notice, the name of The Open Group shall not be
  35. used in advertising or otherwise to promote the sale, use or other dealings
  36. in this Software without prior written authorization from The Open Group.
  37. Copyright 1987, 1989 by Digital Equipment Corporation, Maynard, Massachusetts.
  38. All Rights Reserved
  39. Permission to use, copy, modify, and distribute this software and its
  40. documentation for any purpose and without fee is hereby granted,
  41. provided that the above copyright notice appear in all copies and that
  42. both that copyright notice and this permission notice appear in
  43. supporting documentation, and that the name of Digital not be
  44. used in advertising or publicity pertaining to distribution of the
  45. software without specific, written prior permission.
  46. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  47. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  48. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  49. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  50. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  51. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  52. SOFTWARE.
  53. ********************************************************/
  54. /* The panoramix components contained the following notice */
  55. /*****************************************************************
  56. Copyright (c) 1991, 1997 Digital Equipment Corporation, Maynard, Massachusetts.
  57. Permission is hereby granted, free of charge, to any person obtaining a copy
  58. of this software and associated documentation files (the "Software"), to deal
  59. in the Software without restriction, including without limitation the rights
  60. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  61. copies of the Software.
  62. The above copyright notice and this permission notice shall be included in
  63. all copies or substantial portions of the Software.
  64. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  65. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  66. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  67. DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR ANY CLAIM, DAMAGES, INCLUDING,
  68. BUT NOT LIMITED TO CONSEQUENTIAL OR INCIDENTAL DAMAGES, OR OTHER LIABILITY,
  69. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
  70. IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  71. Except as contained in this notice, the name of Digital Equipment Corporation
  72. shall not be used in advertising or otherwise to promote the sale, use or other
  73. dealings in this Software without prior written authorization from Digital
  74. Equipment Corporation.
  75. ******************************************************************/
  76. /* $XFree86: xc/programs/Xserver/dix/dispatch.c,v 3.32 2003/11/10 18:21:45 tsi Exp $ */
  77. #ifdef HAVE_DIX_CONFIG_H
  78. #include <dix-config.h>
  79. #endif
  80. #ifdef PANORAMIX_DEBUG
  81. #include <stdio.h>
  82. int ProcInitialConnection();
  83. #endif
  84. #ifdef __sun
  85. #define False 0
  86. #define True 1
  87. #endif
  88. #define GC XlibGC
  89. #include <X11/Xlib.h>
  90. #undef GC
  91. #include "windowstr.h"
  92. #include <X11/fonts/fontstruct.h>
  93. #include "dixfontstr.h"
  94. #include "gcstruct.h"
  95. #include "selection.h"
  96. #include "colormapst.h"
  97. #include "cursorstr.h"
  98. #include "scrnintstr.h"
  99. #include "opaque.h"
  100. #include "input.h"
  101. #include "servermd.h"
  102. #include "extnsionst.h"
  103. #include "dixfont.h"
  104. #include "../../dix/dispatch.h"
  105. #include "swaprep.h"
  106. #include "swapreq.h"
  107. #ifdef PANORAMIX
  108. #include "panoramiX.h"
  109. #include "panoramiXsrv.h"
  110. #endif
  111. #ifdef XCSECURITY
  112. #define _SECURITY_SERVER
  113. #include <X11/extensions/security.h>
  114. #endif
  115. #ifdef XAPPGROUP
  116. #include <X11/extensions/Xagsrv.h>
  117. #endif
  118. #ifdef XKB
  119. #define XKB_IN_SERVER
  120. #include "inputstr.h"
  121. #include <X11/extensions/XKBsrv.h>
  122. #endif
  123. #include "Atoms.h"
  124. #include "Splash.h"
  125. #include "Client.h"
  126. #include "Clipboard.h"
  127. #include "Reconnect.h"
  128. #include "Millis.h"
  129. #include "Font.h"
  130. #include "Shadow.h"
  131. #include "Handlers.h"
  132. #include "Keyboard.h"
  133. const int nxagentMaxFontNames = 10000;
  134. char dispatchExceptionAtReset = DE_RESET;
  135. /*
  136. * This allows the agent to exit if no
  137. * client is connected within a timeout.
  138. */
  139. int nxagentClients = 0;
  140. void nxagentWaitDisplay(void);
  141. void nxagentListRemoteFonts(const char *, int);
  142. unsigned int nxagentWMtimeout = 0;
  143. Bool nxagentWMPassed = 0;
  144. /*
  145. * Timeouts based on screen saver time.
  146. */
  147. int nxagentAutoDisconnectTimeout = 0;
  148. #ifdef LBX
  149. #include "../../lbx/lbxserve.h"
  150. #endif
  151. #include "Xatom.h"
  152. /*
  153. * Set here the required log level.
  154. */
  155. #define PANIC
  156. #define WARNING
  157. #undef TEST
  158. #undef WATCH
  159. /*
  160. * Log begin and end of the important handlers.
  161. */
  162. #undef BLOCKS
  163. #ifdef WATCH
  164. #include "unistd.h"
  165. #endif
  166. #ifdef TEST
  167. #include "Literals.h"
  168. #endif
  169. #define mskcnt ((MAXCLIENTS + 31) / 32)
  170. #define BITMASK(i) (1U << ((i) & 31))
  171. #define MASKIDX(i) ((i) >> 5)
  172. #define MASKWORD(buf, i) buf[MASKIDX(i)]
  173. #define BITSET(buf, i) MASKWORD(buf, i) |= BITMASK(i)
  174. #define BITCLEAR(buf, i) MASKWORD(buf, i) &= ~BITMASK(i)
  175. #define GETBIT(buf, i) (MASKWORD(buf, i) & BITMASK(i))
  176. extern xConnSetupPrefix connSetupPrefix;
  177. extern char *ConnectionInfo;
  178. Selection *CurrentSelections;
  179. int NumCurrentSelections;
  180. CallbackListPtr SelectionCallback = NULL;
  181. #ifdef VIEWPORT_FRAME
  182. extern WindowPtr nxagentViewportFrameLeft;
  183. extern WindowPtr nxagentViewportFrameRight;
  184. extern WindowPtr nxagentViewportFrameAbove;
  185. extern WindowPtr nxagentViewportFrameBelow;
  186. #define IsViewportFrame(pWin) ((pWin) == nxagentViewportFrameLeft || \
  187. (pWin) == nxagentViewportFrameRight || \
  188. (pWin) == nxagentViewportFrameAbove || \
  189. (pWin) == nxagentViewportFrameBelow)
  190. #else
  191. #define IsViewportFrame(pWin) (0)
  192. #endif /* #ifdef VIEWPORT_FRAME */
  193. extern int nxagentMaxAllowedResets;
  194. extern int nxagentFindClientResource(int, RESTYPE, pointer);
  195. static ClientPtr grabClient;
  196. #define GrabNone 0
  197. #define GrabActive 1
  198. #define GrabKickout 2
  199. static int grabState = GrabNone;
  200. static long grabWaiters[mskcnt];
  201. CallbackListPtr ServerGrabCallback = NULL;
  202. HWEventQueuePtr checkForInput[2];
  203. extern int connBlockScreenStart;
  204. static void KillAllClients(void);
  205. static void DeleteClientFromAnySelections(ClientPtr client);
  206. static int nextFreeClientID; /* always MIN free client ID */
  207. static int nClients; /* number of authorized clients */
  208. CallbackListPtr ClientStateCallback;
  209. /* dispatchException & isItTimeToYield must be declared volatile since they
  210. * are modified by signal handlers - otherwise optimizer may assume it doesn't
  211. * need to actually check value in memory when used and may miss changes from
  212. * signal handlers.
  213. */
  214. volatile char dispatchException = 0;
  215. volatile char isItTimeToYield;
  216. /* Various of the DIX function interfaces were not designed to allow
  217. * the client->errorValue to be set on BadValue and other errors.
  218. * Rather than changing interfaces and breaking untold code we introduce
  219. * a new global that dispatch can use.
  220. */
  221. XID clientErrorValue; /* XXX this is a kludge */
  222. #define SAME_SCREENS(a, b) (\
  223. (a.pScreen == b.pScreen))
  224. void
  225. SetInputCheck(HWEventQueuePtr c0, HWEventQueuePtr c1)
  226. {
  227. checkForInput[0] = c0;
  228. checkForInput[1] = c1;
  229. }
  230. void
  231. UpdateCurrentTime()
  232. {
  233. TimeStamp systime;
  234. /* To avoid time running backwards, we must call GetTimeInMillis before
  235. * calling ProcessInputEvents.
  236. */
  237. systime.months = currentTime.months;
  238. systime.milliseconds = GetTimeInMillis();
  239. if (systime.milliseconds < currentTime.milliseconds)
  240. systime.months++;
  241. if (*checkForInput[0] != *checkForInput[1])
  242. ProcessInputEvents();
  243. if (CompareTimeStamps(systime, currentTime) == LATER)
  244. currentTime = systime;
  245. }
  246. /* Like UpdateCurrentTime, but can't call ProcessInputEvents */
  247. void
  248. UpdateCurrentTimeIf()
  249. {
  250. TimeStamp systime;
  251. systime.months = currentTime.months;
  252. systime.milliseconds = GetTimeInMillis();
  253. if (systime.milliseconds < currentTime.milliseconds)
  254. systime.months++;
  255. if (*checkForInput[0] == *checkForInput[1])
  256. currentTime = systime;
  257. }
  258. void
  259. InitSelections()
  260. {
  261. if (CurrentSelections)
  262. xfree(CurrentSelections);
  263. CurrentSelections = (Selection *)NULL;
  264. NumCurrentSelections = 0;
  265. #ifdef NXAGENT_CLIPBOARD
  266. {
  267. Selection *newsels;
  268. newsels = (Selection *)xalloc(2 * sizeof(Selection));
  269. if (!newsels)
  270. return;
  271. NumCurrentSelections += 2;
  272. CurrentSelections = newsels;
  273. CurrentSelections[0].selection = XA_PRIMARY;
  274. CurrentSelections[0].lastTimeChanged = ClientTimeToServerTime(0);
  275. CurrentSelections[0].window = WindowTable[0]->drawable.id;
  276. CurrentSelections[0].pWin = NULL;
  277. CurrentSelections[0].client = NullClient;
  278. CurrentSelections[1].selection = MakeAtom("CLIPBOARD", 9, 1);
  279. CurrentSelections[1].lastTimeChanged = ClientTimeToServerTime(0);
  280. CurrentSelections[1].window = WindowTable[0]->drawable.id;
  281. CurrentSelections[1].pWin = NULL;
  282. CurrentSelections[1].client = NullClient;
  283. }
  284. #endif
  285. }
  286. void
  287. FlushClientCaches(XID id)
  288. {
  289. int i;
  290. register ClientPtr client;
  291. client = clients[CLIENT_ID(id)];
  292. if (client == NullClient)
  293. return ;
  294. for (i=0; i<currentMaxClients; i++)
  295. {
  296. client = clients[i];
  297. if (client != NullClient)
  298. {
  299. if (client->lastDrawableID == id)
  300. {
  301. client->lastDrawableID = WindowTable[0]->drawable.id;
  302. client->lastDrawable = (DrawablePtr)WindowTable[0];
  303. }
  304. else if (client->lastGCID == id)
  305. {
  306. client->lastGCID = INVALID;
  307. client->lastGC = (GCPtr)NULL;
  308. }
  309. }
  310. }
  311. }
  312. #ifdef SMART_SCHEDULE
  313. #undef SMART_DEBUG
  314. #define SMART_SCHEDULE_DEFAULT_INTERVAL 20 /* ms */
  315. #define SMART_SCHEDULE_MAX_SLICE 200 /* ms */
  316. Bool SmartScheduleDisable = FALSE;
  317. long SmartScheduleSlice = SMART_SCHEDULE_DEFAULT_INTERVAL;
  318. long SmartScheduleInterval = SMART_SCHEDULE_DEFAULT_INTERVAL;
  319. long SmartScheduleMaxSlice = SMART_SCHEDULE_MAX_SLICE;
  320. long SmartScheduleTime;
  321. ClientPtr SmartLastClient;
  322. int SmartLastIndex[SMART_MAX_PRIORITY-SMART_MIN_PRIORITY+1];
  323. int SmartScheduleClient(int *clientReady, int nready);
  324. #ifdef SMART_DEBUG
  325. long SmartLastPrint;
  326. #endif
  327. void Dispatch(void);
  328. void InitProcVectors(void);
  329. int
  330. SmartScheduleClient (int *clientReady, int nready)
  331. {
  332. ClientPtr pClient;
  333. int i;
  334. int client;
  335. int bestPrio, best = 0;
  336. int bestRobin, robin;
  337. long now = SmartScheduleTime;
  338. long idle;
  339. bestPrio = -0x7fffffff;
  340. bestRobin = 0;
  341. idle = 2 * SmartScheduleSlice;
  342. for (i = 0; i < nready; i++)
  343. {
  344. client = clientReady[i];
  345. pClient = clients[client];
  346. /* Praise clients which are idle */
  347. if ((now - pClient->smart_check_tick) >= idle)
  348. {
  349. if (pClient->smart_priority < 0)
  350. pClient->smart_priority++;
  351. }
  352. pClient->smart_check_tick = now;
  353. /* check priority to select best client */
  354. robin = (pClient->index - SmartLastIndex[pClient->smart_priority-SMART_MIN_PRIORITY]) & 0xff;
  355. if (pClient->smart_priority > bestPrio ||
  356. (pClient->smart_priority == bestPrio && robin > bestRobin))
  357. {
  358. bestPrio = pClient->smart_priority;
  359. bestRobin = robin;
  360. best = client;
  361. }
  362. #ifdef SMART_DEBUG
  363. if ((now - SmartLastPrint) >= 5000)
  364. fprintf (stderr, " %2d: %3d", client, pClient->smart_priority);
  365. #endif
  366. }
  367. #ifdef SMART_DEBUG
  368. if ((now - SmartLastPrint) >= 5000)
  369. {
  370. fprintf (stderr, " use %2d\n", best);
  371. SmartLastPrint = now;
  372. }
  373. #endif
  374. pClient = clients[best];
  375. SmartLastIndex[bestPrio-SMART_MIN_PRIORITY] = pClient->index;
  376. /*
  377. * Set current client pointer
  378. */
  379. if (SmartLastClient != pClient)
  380. {
  381. pClient->smart_start_tick = now;
  382. SmartLastClient = pClient;
  383. }
  384. /*
  385. * Adjust slice
  386. */
  387. if (nready == 1)
  388. {
  389. /*
  390. * If it's been a long time since another client
  391. * has run, bump the slice up to get maximal
  392. * performance from a single client
  393. */
  394. if ((now - pClient->smart_start_tick) > 1000 &&
  395. SmartScheduleSlice < SmartScheduleMaxSlice)
  396. {
  397. SmartScheduleSlice += SmartScheduleInterval;
  398. }
  399. }
  400. else
  401. {
  402. SmartScheduleSlice = SmartScheduleInterval;
  403. }
  404. return best;
  405. }
  406. #endif
  407. #define MAJOROP ((xReq *)client->requestBuffer)->reqType
  408. void
  409. Dispatch(void)
  410. {
  411. register int *clientReady; /* array of request ready clients */
  412. register int result;
  413. register ClientPtr client;
  414. register int nready;
  415. register HWEventQueuePtr* icheck = checkForInput;
  416. #ifdef SMART_SCHEDULE
  417. long start_tick;
  418. #endif
  419. unsigned long currentDispatch = 0;
  420. nextFreeClientID = 1;
  421. InitSelections();
  422. nClients = 0;
  423. /*
  424. * The agent initialization was successfully
  425. * completed. We can now handle our clients.
  426. */
  427. #ifdef XKB
  428. nxagentInitXkbWrapper();
  429. nxagentTuneXkbWrapper();
  430. #endif
  431. #ifdef NXAGENT_ONSTART
  432. /*
  433. * Set NX_WM property (used by NX client to identify
  434. * the agent's window) three seconds since the first
  435. * client connects.
  436. */
  437. nxagentWMtimeout = GetTimeInMillis() + 3000;
  438. #endif
  439. clientReady = (int *) ALLOCATE_LOCAL(sizeof(int) * MaxClients);
  440. if (!clientReady)
  441. return;
  442. #ifdef WATCH
  443. fprintf(stderr, "Dispatch: Watchpoint 12.\n");
  444. /*
  445. Reply Total Cached Bits In Bits Out Bits/Reply Ratio
  446. ------- ----- ------ ------- -------- ---------- -----
  447. #3 1 352 bits (0 KB) -> 236 bits (0 KB) -> 352/1 -> 236/1 = 1.492:1
  448. #14 1 256 bits (0 KB) -> 101 bits (0 KB) -> 256/1 -> 101/1 = 2.535:1
  449. #16 1 256 bits (0 KB) -> 26 bits (0 KB) -> 256/1 -> 26/1 = 9.846:1
  450. #20 2 2 12256 bits (1 KB) -> 56 bits (0 KB) -> 6128/1 -> 28/1 = 218.857:1
  451. #43 1 256 bits (0 KB) -> 45 bits (0 KB) -> 256/1 -> 45/1 = 5.689:1
  452. #47 2 2 42304 bits (5 KB) -> 49 bits (0 KB) -> 21152/1 -> 24/1 = 863.347:1
  453. #98 1 256 bits (0 KB) -> 34 bits (0 KB) -> 256/1 -> 34/1 = 7.529:1
  454. */
  455. sleep(30);
  456. #endif
  457. #ifdef TEST
  458. fprintf(stderr, "Dispatch: Value of dispatchException is [%x].\n",
  459. dispatchException);
  460. fprintf(stderr, "Dispatch: Value of dispatchExceptionAtReset is [%x].\n",
  461. dispatchExceptionAtReset);
  462. #endif
  463. if (!(dispatchException & DE_TERMINATE))
  464. dispatchException = 0;
  465. while (!dispatchException)
  466. {
  467. if (*icheck[0] != *icheck[1])
  468. {
  469. ProcessInputEvents();
  470. FlushIfCriticalOutputPending();
  471. }
  472. /*
  473. * Ensure we remove the splash after the timeout.
  474. * Initializing clientReady[0] to -1 will tell
  475. * WaitForSomething() to yield control after the
  476. * timeout set in clientReady[1].
  477. */
  478. clientReady[0] = 0;
  479. if (nxagentSplashWindow != None || (nxagentOption(Xdmcp) == 1 && nxagentXdmcpUp == 0))
  480. {
  481. #ifdef TEST
  482. fprintf(stderr, "******Dispatch: Requesting a timeout of [%d] Ms.\n",
  483. NXAGENT_WAKEUP);
  484. #endif
  485. clientReady[0] = -1;
  486. clientReady[1] = NXAGENT_WAKEUP;
  487. }
  488. if (serverGeneration > nxagentMaxAllowedResets &&
  489. nxagentSessionState == SESSION_STARTING &&
  490. (nxagentOption(Xdmcp) == 0 || nxagentXdmcpUp == 1))
  491. {
  492. #ifdef NX_DEBUG_INPUT
  493. fprintf(stderr, "Session: Session started at '%s' timestamp [%lu].\n",
  494. GetTimeAsString(), GetTimeInMillis());
  495. #else
  496. fprintf(stderr, "Session: Session started at '%s'.\n",
  497. GetTimeAsString());
  498. #endif
  499. nxagentSessionState = SESSION_UP;
  500. }
  501. #ifdef BLOCKS
  502. fprintf(stderr, "[End dispatch]\n");
  503. #endif
  504. nready = WaitForSomething(clientReady);
  505. #ifdef BLOCKS
  506. fprintf(stderr, "[Begin dispatch]\n");
  507. #endif
  508. #ifdef TEST
  509. fprintf(stderr, "******Dispatch: Running with [%d] clients ready.\n",
  510. nready);
  511. #endif
  512. #ifdef NXAGENT_ONSTART
  513. currentDispatch = GetTimeInMillis();
  514. /*
  515. * If the timeout is expired set the
  516. * selection informing the NX client
  517. * that the agent is ready.
  518. */
  519. if (!nxagentWMPassed && (nxagentWMtimeout < currentDispatch))
  520. {
  521. nxagentRemoveSplashWindow(NULL);
  522. }
  523. nxagentClients = nClients;
  524. #endif
  525. #ifdef SMART_SCHEDULE
  526. if (nready && !SmartScheduleDisable)
  527. {
  528. clientReady[0] = SmartScheduleClient (clientReady, nready);
  529. nready = 1;
  530. }
  531. #endif
  532. /*****************
  533. * Handle events in round robin fashion, doing input between
  534. * each round
  535. *****************/
  536. while (!dispatchException && (--nready >= 0))
  537. {
  538. client = clients[clientReady[nready]];
  539. if (! client)
  540. {
  541. /* KillClient can cause this to happen */
  542. continue;
  543. }
  544. /* GrabServer activation can cause this to be true */
  545. if (grabState == GrabKickout)
  546. {
  547. grabState = GrabActive;
  548. break;
  549. }
  550. isItTimeToYield = FALSE;
  551. requestingClient = client;
  552. #ifdef SMART_SCHEDULE
  553. start_tick = SmartScheduleTime;
  554. #endif
  555. while (!isItTimeToYield)
  556. {
  557. if (*icheck[0] != *icheck[1])
  558. {
  559. ProcessInputEvents();
  560. FlushIfCriticalOutputPending();
  561. }
  562. #ifdef SMART_SCHEDULE
  563. if (!SmartScheduleDisable &&
  564. (SmartScheduleTime - start_tick) >= SmartScheduleSlice)
  565. {
  566. /* Penalize clients which consume ticks */
  567. if (client->smart_priority > SMART_MIN_PRIORITY)
  568. client->smart_priority--;
  569. break;
  570. }
  571. #endif
  572. /* now, finally, deal with client requests */
  573. #ifdef TEST
  574. fprintf(stderr, "******Dispatch: Reading request from client [%d].\n",
  575. client->index);
  576. #endif
  577. result = ReadRequestFromClient(client);
  578. if (result <= 0)
  579. {
  580. if (result < 0)
  581. CloseDownClient(client);
  582. break;
  583. }
  584. #ifdef NXAGENT_SERVER
  585. #ifdef TEST
  586. else
  587. {
  588. if (MAJOROP > 127)
  589. {
  590. fprintf(stderr, "******Dispatch: Read [Extension] request OPCODE#%d MINOR#%d "
  591. "size [%d] client [%d].\n", MAJOROP, *((char *) client->requestBuffer + 1),
  592. client->req_len << 2, client->index);
  593. }
  594. else
  595. {
  596. fprintf(stderr, "******Dispatch: Read [%s] request OPCODE#%d size [%d] client [%d].\n",
  597. nxagentRequestLiteral[MAJOROP], MAJOROP, client->req_len << 2,
  598. client->index);
  599. }
  600. }
  601. #endif
  602. #endif
  603. client->sequence++;
  604. #ifdef DEBUG
  605. if (client->requestLogIndex == MAX_REQUEST_LOG)
  606. client->requestLogIndex = 0;
  607. client->requestLog[client->requestLogIndex] = MAJOROP;
  608. client->requestLogIndex++;
  609. #endif
  610. if (result > (maxBigRequestSize << 2))
  611. result = BadLength;
  612. else
  613. #ifdef NXAGENT_SERVER
  614. {
  615. result = (* client->requestVector[MAJOROP])(client);
  616. #ifdef TEST
  617. if (MAJOROP > 127)
  618. {
  619. fprintf(stderr, "******Dispatch: Handled [Extension] request OPCODE#%d MINOR#%d "
  620. "size [%d] client [%d] result [%d].\n", MAJOROP,
  621. *((char *) client->requestBuffer + 1), client->req_len << 2,
  622. client->index, result);
  623. }
  624. else
  625. {
  626. fprintf(stderr, "******Dispatch: Handled [%s] request OPCODE#%d size [%d] client [%d] "
  627. "result [%d].\n", nxagentRequestLiteral[MAJOROP], MAJOROP,
  628. client->req_len << 2, client->index, result);
  629. }
  630. #endif
  631. /*
  632. * Can set isItTimeToYield to force
  633. * the dispatcher to pay attention
  634. * to another client.
  635. */
  636. nxagentDispatchHandler(client, client->req_len << 2, 0);
  637. }
  638. #else
  639. result = (* client->requestVector[MAJOROP])(client);
  640. #endif
  641. if (result != Success)
  642. {
  643. if (client->noClientException != Success)
  644. CloseDownClient(client);
  645. else
  646. SendErrorToClient(client, MAJOROP,
  647. MinorOpcodeOfRequest(client),
  648. client->errorValue, result);
  649. break;
  650. }
  651. #ifdef DAMAGEEXT
  652. FlushIfCriticalOutputPending ();
  653. #endif
  654. }
  655. FlushAllOutput();
  656. #ifdef SMART_SCHEDULE
  657. client = clients[clientReady[nready]];
  658. if (client)
  659. client->smart_stop_tick = SmartScheduleTime;
  660. #endif
  661. requestingClient = NULL;
  662. }
  663. dispatchException &= ~DE_PRIORITYCHANGE;
  664. }
  665. #if defined(DDXBEFORERESET)
  666. ddxBeforeReset ();
  667. #endif
  668. if ((dispatchException & DE_RESET) &&
  669. (serverGeneration > nxagentMaxAllowedResets))
  670. {
  671. dispatchException &= ~DE_RESET;
  672. dispatchException |= DE_TERMINATE;
  673. fprintf(stderr, "Info: Reached threshold of maximum allowed resets.\n");
  674. }
  675. nxagentResetAtomMap();
  676. if (serverGeneration > nxagentMaxAllowedResets)
  677. {
  678. /*
  679. * The session is terminating. Force an I/O
  680. * error on the display and wait until the
  681. * NX transport is gone.
  682. */
  683. fprintf(stderr, "Session: Terminating session at '%s'.\n", GetTimeAsString());
  684. nxagentWaitDisplay();
  685. fprintf(stderr, "Session: Session terminated at '%s'.\n", GetTimeAsString());
  686. }
  687. if (nxagentOption(Shadow) == 1)
  688. {
  689. NXShadowDestroy();
  690. }
  691. KillAllClients();
  692. DEALLOCATE_LOCAL(clientReady);
  693. dispatchException &= ~DE_RESET;
  694. }
  695. #undef MAJOROP
  696. int
  697. ProcBadRequest(ClientPtr client)
  698. {
  699. return (BadRequest);
  700. }
  701. int
  702. ProcCreateWindow(ClientPtr client)
  703. {
  704. register WindowPtr pParent, pWin;
  705. REQUEST(xCreateWindowReq);
  706. int result;
  707. int len;
  708. REQUEST_AT_LEAST_SIZE(xCreateWindowReq);
  709. LEGAL_NEW_RESOURCE(stuff->wid, client);
  710. if (!(pParent = (WindowPtr)SecurityLookupWindow(stuff->parent, client,
  711. SecurityWriteAccess)))
  712. return BadWindow;
  713. len = client->req_len - (sizeof(xCreateWindowReq) >> 2);
  714. if (Ones(stuff->mask) != len)
  715. return BadLength;
  716. if (!stuff->width || !stuff->height)
  717. {
  718. client->errorValue = 0;
  719. return BadValue;
  720. }
  721. pWin = CreateWindow(stuff->wid, pParent, stuff->x,
  722. stuff->y, stuff->width, stuff->height,
  723. stuff->borderWidth, stuff->class,
  724. stuff->mask, (XID *) &stuff[1],
  725. (int)stuff->depth,
  726. client, stuff->visual, &result);
  727. if (pWin)
  728. {
  729. Mask mask = pWin->eventMask;
  730. pWin->eventMask = 0; /* subterfuge in case AddResource fails */
  731. if (!AddResource(stuff->wid, RT_WINDOW, (pointer)pWin))
  732. return BadAlloc;
  733. pWin->eventMask = mask;
  734. }
  735. if (client->noClientException != Success)
  736. return(client->noClientException);
  737. else
  738. return(result);
  739. }
  740. int
  741. ProcChangeWindowAttributes(register ClientPtr client)
  742. {
  743. register WindowPtr pWin;
  744. REQUEST(xChangeWindowAttributesReq);
  745. register int result;
  746. int len;
  747. REQUEST_AT_LEAST_SIZE(xChangeWindowAttributesReq);
  748. pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client,
  749. SecurityWriteAccess);
  750. if (!pWin)
  751. return(BadWindow);
  752. len = client->req_len - (sizeof(xChangeWindowAttributesReq) >> 2);
  753. if (len != Ones(stuff->valueMask))
  754. return BadLength;
  755. result = ChangeWindowAttributes(pWin,
  756. stuff->valueMask,
  757. (XID *) &stuff[1],
  758. client);
  759. if (client->noClientException != Success)
  760. return(client->noClientException);
  761. else
  762. return(result);
  763. }
  764. int
  765. ProcGetWindowAttributes(register ClientPtr client)
  766. {
  767. register WindowPtr pWin;
  768. REQUEST(xResourceReq);
  769. xGetWindowAttributesReply wa;
  770. REQUEST_SIZE_MATCH(xResourceReq);
  771. pWin = (WindowPtr)SecurityLookupWindow(stuff->id, client,
  772. SecurityReadAccess);
  773. if (!pWin)
  774. return(BadWindow);
  775. GetWindowAttributes(pWin, client, &wa);
  776. WriteReplyToClient(client, sizeof(xGetWindowAttributesReply), &wa);
  777. return(client->noClientException);
  778. }
  779. int
  780. ProcDestroyWindow(register ClientPtr client)
  781. {
  782. register WindowPtr pWin;
  783. REQUEST(xResourceReq);
  784. REQUEST_SIZE_MATCH(xResourceReq);
  785. pWin = (WindowPtr)SecurityLookupWindow(stuff->id, client,
  786. SecurityDestroyAccess);
  787. if (!pWin)
  788. return(BadWindow);
  789. if (pWin->parent)
  790. FreeResource(stuff->id, RT_NONE);
  791. return(client->noClientException);
  792. }
  793. int
  794. ProcDestroySubwindows(register ClientPtr client)
  795. {
  796. register WindowPtr pWin;
  797. REQUEST(xResourceReq);
  798. REQUEST_SIZE_MATCH(xResourceReq);
  799. pWin = (WindowPtr)SecurityLookupWindow(stuff->id, client,
  800. SecurityDestroyAccess);
  801. if (!pWin)
  802. return(BadWindow);
  803. DestroySubwindows(pWin, client);
  804. return(client->noClientException);
  805. }
  806. int
  807. ProcChangeSaveSet(register ClientPtr client)
  808. {
  809. register WindowPtr pWin;
  810. REQUEST(xChangeSaveSetReq);
  811. register int result;
  812. REQUEST_SIZE_MATCH(xChangeSaveSetReq);
  813. pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client,
  814. SecurityReadAccess);
  815. if (!pWin)
  816. return(BadWindow);
  817. if (client->clientAsMask == (CLIENT_BITS(pWin->drawable.id)))
  818. return BadMatch;
  819. if ((stuff->mode == SetModeInsert) || (stuff->mode == SetModeDelete))
  820. {
  821. result = AlterSaveSetForClient(client, pWin, stuff->mode, FALSE, TRUE);
  822. if (client->noClientException != Success)
  823. return(client->noClientException);
  824. else
  825. return(result);
  826. }
  827. else
  828. {
  829. client->errorValue = stuff->mode;
  830. return( BadValue );
  831. }
  832. }
  833. int
  834. ProcReparentWindow(register ClientPtr client)
  835. {
  836. register WindowPtr pWin, pParent;
  837. REQUEST(xReparentWindowReq);
  838. register int result;
  839. REQUEST_SIZE_MATCH(xReparentWindowReq);
  840. pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client,
  841. SecurityWriteAccess);
  842. if (!pWin)
  843. return(BadWindow);
  844. if (!nxagentWMPassed)
  845. {
  846. nxagentRemoveSplashWindow(pWin);
  847. }
  848. pParent = (WindowPtr)SecurityLookupWindow(stuff->parent, client,
  849. SecurityWriteAccess);
  850. if (!pParent)
  851. return(BadWindow);
  852. if (SAME_SCREENS(pWin->drawable, pParent->drawable))
  853. {
  854. if ((pWin->backgroundState == ParentRelative) &&
  855. (pParent->drawable.depth != pWin->drawable.depth))
  856. return BadMatch;
  857. if ((pWin->drawable.class != InputOnly) &&
  858. (pParent->drawable.class == InputOnly))
  859. return BadMatch;
  860. result = ReparentWindow(pWin, pParent,
  861. (short)stuff->x, (short)stuff->y, client);
  862. if (client->noClientException != Success)
  863. return(client->noClientException);
  864. else
  865. return(result);
  866. }
  867. else
  868. return (BadMatch);
  869. }
  870. int
  871. ProcMapWindow(register ClientPtr client)
  872. {
  873. register WindowPtr pWin;
  874. REQUEST(xResourceReq);
  875. REQUEST_SIZE_MATCH(xResourceReq);
  876. pWin = (WindowPtr)SecurityLookupWindow(stuff->id, client,
  877. SecurityReadAccess);
  878. if (!pWin)
  879. return(BadWindow);
  880. MapWindow(pWin, client);
  881. /* update cache to say it is mapped */
  882. return(client->noClientException);
  883. }
  884. int
  885. ProcMapSubwindows(register ClientPtr client)
  886. {
  887. register WindowPtr pWin;
  888. REQUEST(xResourceReq);
  889. REQUEST_SIZE_MATCH(xResourceReq);
  890. pWin = (WindowPtr)SecurityLookupWindow( stuff->id, client,
  891. SecurityReadAccess);
  892. if (!pWin)
  893. return(BadWindow);
  894. MapSubwindows(pWin, client);
  895. /* update cache to say it is mapped */
  896. return(client->noClientException);
  897. }
  898. int
  899. ProcUnmapWindow(register ClientPtr client)
  900. {
  901. register WindowPtr pWin;
  902. REQUEST(xResourceReq);
  903. REQUEST_SIZE_MATCH(xResourceReq);
  904. pWin = (WindowPtr)SecurityLookupWindow( stuff->id, client,
  905. SecurityReadAccess);
  906. if (!pWin)
  907. return(BadWindow);
  908. UnmapWindow(pWin, FALSE);
  909. /* update cache to say it is mapped */
  910. return(client->noClientException);
  911. }
  912. int
  913. ProcUnmapSubwindows(register ClientPtr client)
  914. {
  915. register WindowPtr pWin;
  916. REQUEST(xResourceReq);
  917. REQUEST_SIZE_MATCH(xResourceReq);
  918. pWin = (WindowPtr)SecurityLookupWindow( stuff->id, client,
  919. SecurityReadAccess);
  920. if (!pWin)
  921. return(BadWindow);
  922. UnmapSubwindows(pWin);
  923. return(client->noClientException);
  924. }
  925. int
  926. ProcConfigureWindow(register ClientPtr client)
  927. {
  928. register WindowPtr pWin;
  929. REQUEST(xConfigureWindowReq);
  930. register int result;
  931. int len;
  932. REQUEST_AT_LEAST_SIZE(xConfigureWindowReq);
  933. pWin = (WindowPtr)SecurityLookupWindow( stuff->window, client,
  934. SecurityWriteAccess);
  935. if (!pWin)
  936. return(BadWindow);
  937. len = client->req_len - (sizeof(xConfigureWindowReq) >> 2);
  938. if (Ones((Mask)stuff->mask) != len)
  939. return BadLength;
  940. result = ConfigureWindow(pWin, (Mask)stuff->mask, (XID *) &stuff[1],
  941. client);
  942. if (client->noClientException != Success)
  943. return(client->noClientException);
  944. else
  945. return(result);
  946. }
  947. int
  948. ProcCirculateWindow(register ClientPtr client)
  949. {
  950. register WindowPtr pWin;
  951. REQUEST(xCirculateWindowReq);
  952. REQUEST_SIZE_MATCH(xCirculateWindowReq);
  953. if ((stuff->direction != RaiseLowest) &&
  954. (stuff->direction != LowerHighest))
  955. {
  956. client->errorValue = stuff->direction;
  957. return BadValue;
  958. }
  959. pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client,
  960. SecurityWriteAccess);
  961. if (!pWin)
  962. return(BadWindow);
  963. CirculateWindow(pWin, (int)stuff->direction, client);
  964. return(client->noClientException);
  965. }
  966. int
  967. GetGeometry(register ClientPtr client, 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(register ClientPtr client)
  1003. {
  1004. xGetGeometryReply rep;
  1005. int status;
  1006. if ((status = GetGeometry(client, &rep)) != Success)
  1007. return status;
  1008. WriteReplyToClient(client, sizeof(xGetGeometryReply), &rep);
  1009. return(client->noClientException);
  1010. }
  1011. int
  1012. ProcQueryTree(register ClientPtr client)
  1013. {
  1014. xQueryTreeReply reply;
  1015. int numChildren = 0;
  1016. register WindowPtr pChild, pWin, pHead;
  1017. Window *childIDs = (Window *)NULL;
  1018. REQUEST(xResourceReq);
  1019. REQUEST_SIZE_MATCH(xResourceReq);
  1020. pWin = (WindowPtr)SecurityLookupWindow(stuff->id, client,
  1021. SecurityReadAccess);
  1022. if (!pWin)
  1023. return(BadWindow);
  1024. reply.type = X_Reply;
  1025. reply.root = WindowTable[pWin->drawable.pScreen->myNum]->drawable.id;
  1026. reply.sequenceNumber = client->sequence;
  1027. if (pWin->parent)
  1028. reply.parent = pWin->parent->drawable.id;
  1029. else
  1030. reply.parent = (Window)None;
  1031. pHead = RealChildHead(pWin);
  1032. for (pChild = pWin->lastChild; pChild != pHead; pChild = pChild->prevSib)
  1033. {
  1034. if (!IsViewportFrame(pChild))
  1035. {
  1036. numChildren++;
  1037. }
  1038. }
  1039. if (numChildren)
  1040. {
  1041. int curChild = 0;
  1042. childIDs = (Window *) ALLOCATE_LOCAL(numChildren * sizeof(Window));
  1043. if (!childIDs)
  1044. return BadAlloc;
  1045. for (pChild = pWin->lastChild; pChild != pHead; pChild = pChild->prevSib)
  1046. {
  1047. if (!IsViewportFrame(pChild))
  1048. {
  1049. childIDs[curChild++] = pChild->drawable.id;
  1050. }
  1051. }
  1052. }
  1053. reply.nChildren = numChildren;
  1054. reply.length = (numChildren * sizeof(Window)) >> 2;
  1055. WriteReplyToClient(client, sizeof(xQueryTreeReply), &reply);
  1056. if (numChildren)
  1057. {
  1058. client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write;
  1059. WriteSwappedDataToClient(client, numChildren * sizeof(Window), childIDs);
  1060. DEALLOCATE_LOCAL(childIDs);
  1061. }
  1062. return(client->noClientException);
  1063. }
  1064. int
  1065. ProcInternAtom(register ClientPtr client)
  1066. {
  1067. Atom atom;
  1068. char *tchar;
  1069. REQUEST(xInternAtomReq);
  1070. REQUEST_FIXED_SIZE(xInternAtomReq, stuff->nbytes);
  1071. if ((stuff->onlyIfExists != xTrue) && (stuff->onlyIfExists != xFalse))
  1072. {
  1073. client->errorValue = stuff->onlyIfExists;
  1074. return(BadValue);
  1075. }
  1076. tchar = (char *) &stuff[1];
  1077. atom = MakeAtom(tchar, stuff->nbytes, !stuff->onlyIfExists);
  1078. if (atom != BAD_RESOURCE)
  1079. {
  1080. xInternAtomReply reply;
  1081. reply.type = X_Reply;
  1082. reply.length = 0;
  1083. reply.sequenceNumber = client->sequence;
  1084. reply.atom = atom;
  1085. WriteReplyToClient(client, sizeof(xInternAtomReply), &reply);
  1086. return(client->noClientException);
  1087. }
  1088. else
  1089. return (BadAlloc);
  1090. }
  1091. int
  1092. ProcGetAtomName(register ClientPtr client)
  1093. {
  1094. char *str;
  1095. xGetAtomNameReply reply;
  1096. int len;
  1097. REQUEST(xResourceReq);
  1098. REQUEST_SIZE_MATCH(xResourceReq);
  1099. if ( (str = NameForAtom(stuff->id)) )
  1100. {
  1101. len = strlen(str);
  1102. reply.type = X_Reply;
  1103. reply.length = (len + 3) >> 2;
  1104. reply.sequenceNumber = client->sequence;
  1105. reply.nameLength = len;
  1106. WriteReplyToClient(client, sizeof(xGetAtomNameReply), &reply);
  1107. (void)WriteToClient(client, len, str);
  1108. return(client->noClientException);
  1109. }
  1110. else
  1111. {
  1112. client->errorValue = stuff->id;
  1113. return (BadAtom);
  1114. }
  1115. }
  1116. #ifdef K5AUTH
  1117. extern int k5_bad();
  1118. #endif
  1119. int
  1120. ProcSetSelectionOwner(register ClientPtr client)
  1121. {
  1122. WindowPtr pWin;
  1123. TimeStamp time;
  1124. REQUEST(xSetSelectionOwnerReq);
  1125. REQUEST_SIZE_MATCH(xSetSelectionOwnerReq);
  1126. UpdateCurrentTime();
  1127. time = ClientTimeToServerTime(stuff->time);
  1128. /* If the client's time stamp is in the future relative to the server's
  1129. time stamp, do not set the selection, just return success. */
  1130. if (CompareTimeStamps(time, currentTime) == LATER)
  1131. return Success;
  1132. if (stuff->window != None)
  1133. {
  1134. pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client,
  1135. SecurityReadAccess);
  1136. if (!pWin)
  1137. return(BadWindow);
  1138. }
  1139. else
  1140. pWin = (WindowPtr)None;
  1141. if (ValidAtom(stuff->selection))
  1142. {
  1143. int i = 0;
  1144. /*
  1145. * First, see if the selection is already set...
  1146. */
  1147. while ((i < NumCurrentSelections) &&
  1148. CurrentSelections[i].selection != stuff->selection)
  1149. i++;
  1150. if (i < NumCurrentSelections)
  1151. {
  1152. xEvent event;
  1153. /* If the timestamp in client's request is in the past relative
  1154. to the time stamp indicating the last time the owner of the
  1155. selection was set, do not set the selection, just return
  1156. success. */
  1157. if (CompareTimeStamps(time, CurrentSelections[i].lastTimeChanged)
  1158. == EARLIER)
  1159. return Success;
  1160. if (CurrentSelections[i].client &&
  1161. (!pWin || (CurrentSelections[i].client != client)))
  1162. {
  1163. event.u.u.type = SelectionClear;
  1164. event.u.selectionClear.time = time.milliseconds;
  1165. event.u.selectionClear.window = CurrentSelections[i].window;
  1166. event.u.selectionClear.atom = CurrentSelections[i].selection;
  1167. (void) TryClientEvents (CurrentSelections[i].client, &event, 1,
  1168. NoEventMask, NoEventMask /* CantBeFiltered */,
  1169. NullGrab);
  1170. }
  1171. }
  1172. else
  1173. {
  1174. /*
  1175. * It doesn't exist, so add it...
  1176. */
  1177. Selection *newsels;
  1178. if (i == 0)
  1179. newsels = (Selection *)xalloc(sizeof(Selection));
  1180. else
  1181. newsels = (Selection *)xrealloc(CurrentSelections,
  1182. (NumCurrentSelections + 1) * sizeof(Selection));
  1183. if (!newsels)
  1184. return BadAlloc;
  1185. NumCurrentSelections++;
  1186. CurrentSelections = newsels;
  1187. CurrentSelections[i].selection = stuff->selection;
  1188. }
  1189. CurrentSelections[i].lastTimeChanged = time;
  1190. CurrentSelections[i].window = stuff->window;
  1191. CurrentSelections[i].pWin = pWin;
  1192. CurrentSelections[i].client = (pWin ? client : NullClient);
  1193. if (SelectionCallback)
  1194. {
  1195. SelectionInfoRec info;
  1196. info.selection = &CurrentSelections[i];
  1197. info.kind= SelectionSetOwner;
  1198. CallCallbacks(&SelectionCallback, &info);
  1199. }
  1200. #ifdef NXAGENT_CLIPBOARD
  1201. if ((CurrentSelections[i].pWin != NULL) &&
  1202. (nxagentOption(Clipboard) != ClipboardNone) &&
  1203. ((CurrentSelections[i].selection == XA_PRIMARY) ||
  1204. (CurrentSelections[i].selection == MakeAtom("CLIPBOARD", 9, 0))))
  1205. {
  1206. nxagentSetSelectionOwner(&CurrentSelections[i]);
  1207. }
  1208. #endif
  1209. return (client->noClientException);
  1210. }
  1211. else
  1212. {
  1213. client->errorValue = stuff->selection;
  1214. return (BadAtom);
  1215. }
  1216. }
  1217. int
  1218. ProcGetSelectionOwner(register ClientPtr client)
  1219. {
  1220. REQUEST(xResourceReq);
  1221. REQUEST_SIZE_MATCH(xResourceReq);
  1222. if (ValidAtom(stuff->id))
  1223. {
  1224. int i;
  1225. xGetSelectionOwnerReply reply;
  1226. i = 0;
  1227. while ((i < NumCurrentSelections) &&
  1228. CurrentSelections[i].selection != stuff->id) i++;
  1229. reply.type = X_Reply;
  1230. reply.length = 0;
  1231. reply.sequenceNumber = client->sequence;
  1232. if (i < NumCurrentSelections)
  1233. reply.owner = CurrentSelections[i].window;
  1234. else
  1235. reply.owner = None;
  1236. WriteReplyToClient(client, sizeof(xGetSelectionOwnerReply), &reply);
  1237. return(client->noClientException);
  1238. }
  1239. else
  1240. {
  1241. client->errorValue = stuff->id;
  1242. return (BadAtom);
  1243. }
  1244. }
  1245. int
  1246. ProcConvertSelection(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(register ClientPtr client)
  1325. {
  1326. REQUEST_SIZE_MATCH(xReq);
  1327. if (grabState != GrabNone && client != grabClient)
  1328. {
  1329. ResetCurrentRequest(client);
  1330. client->sequence--;
  1331. BITSET(grabWaiters, client->index);
  1332. IgnoreClient(client);
  1333. return(client->noClientException);
  1334. }
  1335. OnlyListenToOneClient(client);
  1336. grabState = GrabKickout;
  1337. grabClient = client;
  1338. if (ServerGrabCallback)
  1339. {
  1340. ServerGrabInfoRec grabinfo;
  1341. grabinfo.client = client;
  1342. grabinfo.grabstate = SERVER_GRABBED;
  1343. CallCallbacks(&ServerGrabCallback, (pointer)&grabinfo);
  1344. }
  1345. return(client->noClientException);
  1346. }
  1347. static void
  1348. UngrabServer(ClientPtr client)
  1349. {
  1350. int i;
  1351. grabState = GrabNone;
  1352. ListenToAllClients();
  1353. for (i = mskcnt; --i >= 0 && !grabWaiters[i]; )
  1354. ;
  1355. if (i >= 0)
  1356. {
  1357. i <<= 5;
  1358. while (!GETBIT(grabWaiters, i))
  1359. i++;
  1360. BITCLEAR(grabWaiters, i);
  1361. AttendClient(clients[i]);
  1362. }
  1363. if (ServerGrabCallback)
  1364. {
  1365. ServerGrabInfoRec grabinfo;
  1366. grabinfo.client = client;
  1367. grabinfo.grabstate = SERVER_UNGRABBED;
  1368. CallCallbacks(&ServerGrabCallback, (pointer)&grabinfo);
  1369. }
  1370. }
  1371. int
  1372. ProcUngrabServer(register ClientPtr client)
  1373. {
  1374. REQUEST_SIZE_MATCH(xReq);
  1375. UngrabServer(client);
  1376. return(client->noClientException);
  1377. }
  1378. int
  1379. ProcTranslateCoords(register ClientPtr client)
  1380. {
  1381. REQUEST(xTranslateCoordsReq);
  1382. register WindowPtr pWin, pDst;
  1383. xTranslateCoordsReply rep;
  1384. REQUEST_SIZE_MATCH(xTranslateCoordsReq);
  1385. pWin = (WindowPtr)SecurityLookupWindow(stuff->srcWid, client,
  1386. SecurityReadAccess);
  1387. if (!pWin)
  1388. return(BadWindow);
  1389. pDst = (WindowPtr)SecurityLookupWindow(stuff->dstWid, client,
  1390. SecurityReadAccess);
  1391. if (!pDst)
  1392. return(BadWindow);
  1393. rep.type = X_Reply;
  1394. rep.length = 0;
  1395. rep.sequenceNumber = client->sequence;
  1396. if (!SAME_SCREENS(pWin->drawable, pDst->drawable))
  1397. {
  1398. rep.sameScreen = xFalse;
  1399. rep.child = None;
  1400. rep.dstX = rep.dstY = 0;
  1401. }
  1402. else
  1403. {
  1404. INT16 x, y;
  1405. rep.sameScreen = xTrue;
  1406. rep.child = None;
  1407. /* computing absolute coordinates -- adjust to destination later */
  1408. x = pWin->drawable.x + stuff->srcX;
  1409. y = pWin->drawable.y + stuff->srcY;
  1410. pWin = pDst->firstChild;
  1411. while (pWin)
  1412. {
  1413. #ifdef SHAPE
  1414. BoxRec box;
  1415. #endif
  1416. if ((pWin->mapped) &&
  1417. (x >= pWin->drawable.x - wBorderWidth (pWin)) &&
  1418. (x < pWin->drawable.x + (int)pWin->drawable.width +
  1419. wBorderWidth (pWin)) &&
  1420. (y >= pWin->drawable.y - wBorderWidth (pWin)) &&
  1421. (y < pWin->drawable.y + (int)pWin->drawable.height +
  1422. wBorderWidth (pWin))
  1423. #ifdef SHAPE
  1424. /* When a window is shaped, a further check
  1425. * is made to see if the point is inside
  1426. * borderSize
  1427. */
  1428. && (!wBoundingShape(pWin) ||
  1429. POINT_IN_REGION(pWin->drawable.pScreen,
  1430. &pWin->borderSize, x, y, &box))
  1431. && (!wInputShape(pWin) ||
  1432. POINT_IN_REGION(pWin->drawable.pScreen,
  1433. wInputShape(pWin),
  1434. x - pWin->drawable.x,
  1435. y - pWin->drawable.y, &box))
  1436. #endif
  1437. )
  1438. {
  1439. rep.child = pWin->drawable.id;
  1440. pWin = (WindowPtr) NULL;
  1441. }
  1442. else
  1443. pWin = pWin->nextSib;
  1444. }
  1445. /* adjust to destination coordinates */
  1446. rep.dstX = x - pDst->drawable.x;
  1447. rep.dstY = y - pDst->drawable.y;
  1448. }
  1449. WriteReplyToClient(client, sizeof(xTranslateCoordsReply), &rep);
  1450. return(client->noClientException);
  1451. }
  1452. int
  1453. ProcOpenFont(register ClientPtr client)
  1454. {
  1455. int err;
  1456. char fontReq[256];
  1457. REQUEST(xOpenFontReq);
  1458. REQUEST_FIXED_SIZE(xOpenFontReq, stuff->nbytes);
  1459. client->errorValue = stuff->fid;
  1460. LEGAL_NEW_RESOURCE(stuff->fid, client);
  1461. memcpy(fontReq,(char *)&stuff[1],(stuff->nbytes<256)?stuff->nbytes:255);
  1462. fontReq[stuff->nbytes]=0;
  1463. if (strchr(fontReq,'*') || strchr(fontReq,'?'))
  1464. {
  1465. extern int nxOpenFont(ClientPtr, XID, Mask, unsigned, char*);
  1466. #ifdef NXAGENT_FONTMATCH_DEBUG
  1467. fprintf(stderr, "Dispatch: ProcOpenFont try to find a common font with font pattern=%s\n",fontReq);
  1468. #endif
  1469. nxagentListRemoteFonts(fontReq, nxagentMaxFontNames);
  1470. err = nxOpenFont(client, stuff->fid, (Mask) 0,
  1471. stuff->nbytes, (char *)&stuff[1]);
  1472. }
  1473. else
  1474. err = OpenFont(client, stuff->fid, (Mask) 0,
  1475. stuff->nbytes, (char *)&stuff[1]);
  1476. if (err == Success)
  1477. {
  1478. return(client->noClientException);
  1479. }
  1480. else
  1481. return err;
  1482. }
  1483. int
  1484. ProcCloseFont(register ClientPtr client)
  1485. {
  1486. FontPtr pFont;
  1487. REQUEST(xResourceReq);
  1488. REQUEST_SIZE_MATCH(xResourceReq);
  1489. pFont = (FontPtr)SecurityLookupIDByType(client, stuff->id, RT_FONT,
  1490. SecurityDestroyAccess);
  1491. if (pFont != (FontPtr)NULL)
  1492. {
  1493. #ifdef NXAGENT_SERVER
  1494. /*
  1495. * When a client closes a font the resource
  1496. * should not be lost if the reference counter
  1497. * is not 0, otherwise the server will not be
  1498. * able to find this font looping through the
  1499. * resources.
  1500. */
  1501. if (pFont -> refcnt > 0)
  1502. {
  1503. if (nxagentFindClientResource(serverClient -> index, RT_NX_FONT, pFont) == 0)
  1504. {
  1505. #ifdef TEST
  1506. fprintf(stderr, "ProcCloseFont: Switching resource for font at [%p].\n",
  1507. (void *) pFont);
  1508. #endif
  1509. nxagentFontPriv(pFont) -> mirrorID = FakeClientID(serverClient -> index);
  1510. AddResource(nxagentFontPriv(pFont) -> mirrorID, RT_NX_FONT, pFont);
  1511. }
  1512. #ifdef TEST
  1513. else
  1514. {
  1515. fprintf(stderr, "ProcCloseFont: Found duplicated font at [%p], "
  1516. "resource switching skipped.\n", (void *) pFont);
  1517. }
  1518. #endif
  1519. }
  1520. #endif
  1521. FreeResource(stuff->id, RT_NONE);
  1522. return(client->noClientException);
  1523. }
  1524. else
  1525. {
  1526. client->errorValue = stuff->id;
  1527. return (BadFont);
  1528. }
  1529. }
  1530. int
  1531. ProcQueryFont(register ClientPtr client)
  1532. {
  1533. xQueryFontReply *reply;
  1534. FontPtr pFont;
  1535. register GC *pGC;
  1536. REQUEST(xResourceReq);
  1537. REQUEST_SIZE_MATCH(xResourceReq);
  1538. client->errorValue = stuff->id; /* EITHER font or gc */
  1539. pFont = NULL;
  1540. pFont = (FontPtr)SecurityLookupIDByType(client, stuff->id, RT_FONT,
  1541. SecurityReadAccess);
  1542. if (!pFont)
  1543. {
  1544. /* can't use VERIFY_GC because it might return BadGC */
  1545. pGC = (GC *) SecurityLookupIDByType(client, stuff->id, RT_GC,
  1546. SecurityReadAccess);
  1547. if (!pGC)
  1548. {
  1549. client->errorValue = stuff->id;
  1550. return(BadFont); /* procotol…

Large files files are truncated, but you can click here to view the full file