PageRenderTime 47ms CodeModel.GetById 10ms 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

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

  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) +

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