disconnect.c revision ed6184df
1/* 2 * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved. 3 * Copyright 2010 Red Hat, Inc. 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining a 6 * copy of this software and associated documentation files (the "Software"), 7 * to deal in the Software without restriction, including without limitation 8 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 * and/or sell copies of the Software, and to permit persons to whom the 10 * Software is furnished to do so, subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice (including the next 13 * paragraph) shall be included in all copies or substantial portions of the 14 * Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 * DEALINGS IN THE SOFTWARE. 23 * 24 * Copyright © 2002 Keith Packard 25 * 26 * Permission to use, copy, modify, distribute, and sell this software and its 27 * documentation for any purpose is hereby granted without fee, provided that 28 * the above copyright notice appear in all copies and that both that 29 * copyright notice and this permission notice appear in supporting 30 * documentation, and that the name of Keith Packard not be used in 31 * advertising or publicity pertaining to distribution of the software without 32 * specific, written prior permission. Keith Packard makes no 33 * representations about the suitability of this software for any purpose. It 34 * is provided "as is" without express or implied warranty. 35 * 36 * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 37 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO 38 * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR 39 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 40 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 41 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 42 * PERFORMANCE OF THIS SOFTWARE. 43 */ 44 45#ifdef HAVE_DIX_CONFIG_H 46#include <dix-config.h> 47#endif 48 49#include "xfixesint.h" 50#include "opaque.h" 51 52static DevPrivateKeyRec ClientDisconnectPrivateKeyRec; 53 54#define ClientDisconnectPrivateKey (&ClientDisconnectPrivateKeyRec) 55 56typedef struct _ClientDisconnect { 57 int disconnect_mode; 58} ClientDisconnectRec, *ClientDisconnectPtr; 59 60#define GetClientDisconnect(s) \ 61 ((ClientDisconnectPtr) dixLookupPrivate(&(s)->devPrivates, \ 62 ClientDisconnectPrivateKey)) 63 64int 65ProcXFixesSetClientDisconnectMode(ClientPtr client) 66{ 67 ClientDisconnectPtr pDisconnect = GetClientDisconnect(client); 68 69 REQUEST(xXFixesSetClientDisconnectModeReq); 70 71 pDisconnect->disconnect_mode = stuff->disconnect_mode; 72 73 return Success; 74} 75 76int _X_COLD 77SProcXFixesSetClientDisconnectMode(ClientPtr client) 78{ 79 REQUEST(xXFixesSetClientDisconnectModeReq); 80 81 swaps(&stuff->length); 82 83 REQUEST_AT_LEAST_SIZE(xXFixesSetClientDisconnectModeReq); 84 85 swapl(&stuff->disconnect_mode); 86 87 return (*ProcXFixesVector[stuff->xfixesReqType]) (client); 88} 89 90int 91ProcXFixesGetClientDisconnectMode(ClientPtr client) 92{ 93 ClientDisconnectPtr pDisconnect = GetClientDisconnect(client); 94 xXFixesGetClientDisconnectModeReply reply; 95 96 REQUEST_SIZE_MATCH(xXFixesGetClientDisconnectModeReq); 97 98 reply = (xXFixesGetClientDisconnectModeReply) { 99 .type = X_Reply, 100 .sequenceNumber = client->sequence, 101 .length = 0, 102 .disconnect_mode = pDisconnect->disconnect_mode, 103 }; 104 if (client->swapped) { 105 swaps(&reply.sequenceNumber); 106 swapl(&reply.disconnect_mode); 107 } 108 WriteToClient(client, sizeof(xXFixesGetClientDisconnectModeReply), &reply); 109 110 return Success; 111} 112 113int _X_COLD 114SProcXFixesGetClientDisconnectMode(ClientPtr client) 115{ 116 REQUEST(xXFixesGetClientDisconnectModeReq); 117 118 swaps(&stuff->length); 119 120 REQUEST_SIZE_MATCH(xXFixesGetClientDisconnectModeReq); 121 122 return (*ProcXFixesVector[stuff->xfixesReqType]) (client); 123} 124 125Bool 126XFixesShouldDisconnectClient(ClientPtr client) 127{ 128 ClientDisconnectPtr pDisconnect = GetClientDisconnect(client); 129 130 if (!pDisconnect) 131 return FALSE; 132 133 if (dispatchExceptionAtReset & DE_TERMINATE) 134 return (pDisconnect->disconnect_mode & XFixesClientDisconnectFlagTerminate); 135 136 return FALSE; 137} 138 139Bool 140XFixesClientDisconnectInit(void) 141{ 142 if (!dixRegisterPrivateKey(&ClientDisconnectPrivateKeyRec, 143 PRIVATE_CLIENT, sizeof(ClientDisconnectRec))) 144 return FALSE; 145 146 return TRUE; 147} 148