Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 1 | /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved. |
Pierre Ossman | c5e2560 | 2009-03-20 12:59:05 +0000 | [diff] [blame] | 2 | * Copyright 2009 Pierre Ossman for Cendio AB |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 3 | * |
| 4 | * This is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; either version 2 of the License, or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * This software is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this software; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
| 17 | * USA. |
| 18 | */ |
| 19 | |
| 20 | // |
| 21 | // VNCSConnectionST is our derived class of SConnection for VNCServerST - there |
| 22 | // is one for each connected client. We think of VNCSConnectionST as part of |
| 23 | // the VNCServerST implementation, so its methods are allowed full access to |
| 24 | // members of VNCServerST. |
| 25 | // |
| 26 | |
| 27 | #ifndef __RFB_VNCSCONNECTIONST_H__ |
| 28 | #define __RFB_VNCSCONNECTIONST_H__ |
| 29 | |
| 30 | #include <set> |
| 31 | #include <rfb/SConnection.h> |
| 32 | #include <rfb/SMsgWriter.h> |
| 33 | #include <rfb/TransImageGetter.h> |
| 34 | #include <rfb/VNCServerST.h> |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 35 | |
| 36 | namespace rfb { |
| 37 | class VNCSConnectionST : public SConnection, |
| 38 | public WriteSetCursorCallback { |
| 39 | public: |
| 40 | VNCSConnectionST(VNCServerST* server_, network::Socket* s, bool reverse); |
| 41 | virtual ~VNCSConnectionST(); |
| 42 | |
| 43 | // Methods called from VNCServerST. None of these methods ever knowingly |
| 44 | // throw an exception. |
| 45 | |
| 46 | // Unless otherwise stated, the SConnectionST may not be valid after any of |
| 47 | // these methods are called, since they catch exceptions and may have |
| 48 | // called close() which deletes the object. |
| 49 | |
| 50 | // init() must be called to initialise the protocol. If it fails it |
| 51 | // returns false, and close() will have been called. |
| 52 | bool init(); |
| 53 | |
| 54 | // close() shuts down the socket to the client and deletes the |
| 55 | // SConnectionST object. |
| 56 | void close(const char* reason); |
| 57 | |
| 58 | // processMessages() processes incoming messages from the client, invoking |
| 59 | // various callbacks as a result. It continues to process messages until |
| 60 | // reading might block. shutdown() will be called on the connection's |
| 61 | // Socket if an error occurs, via the close() call. |
| 62 | void processMessages(); |
| 63 | |
| 64 | void writeFramebufferUpdateOrClose(); |
| 65 | void pixelBufferChange(); |
| 66 | void setColourMapEntriesOrClose(int firstColour, int nColours); |
| 67 | void bell(); |
| 68 | void serverCutText(const char *str, int len); |
Peter Åstrand | c39e078 | 2009-01-15 12:21:42 +0000 | [diff] [blame] | 69 | void setDesktopName(const char *name); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 70 | void setCursorOrClose(); |
| 71 | |
| 72 | // checkIdleTimeout() returns the number of milliseconds left until the |
| 73 | // idle timeout expires. If it has expired, the connection is closed and |
| 74 | // zero is returned. Zero is also returned if there is no idle timeout. |
| 75 | int checkIdleTimeout(); |
| 76 | |
| 77 | // The following methods never throw exceptions nor do they ever delete the |
| 78 | // SConnectionST object. |
| 79 | |
| 80 | // renderedCursorChange() is called whenever the server-side rendered |
| 81 | // cursor changes shape or position. It ensures that the next update will |
| 82 | // clean up the old rendered cursor and if necessary draw the new rendered |
| 83 | // cursor. |
| 84 | void renderedCursorChange(); |
| 85 | |
| 86 | // needRenderedCursor() returns true if this client needs the server-side |
| 87 | // rendered cursor. This may be because it does not support local cursor |
| 88 | // or because the current cursor position has not been set by this client. |
| 89 | bool needRenderedCursor(); |
| 90 | |
| 91 | network::Socket* getSock() { return sock; } |
| 92 | bool readyForUpdate() { return !requested.is_empty(); } |
| 93 | void add_changed(const Region& region) { updates.add_changed(region); } |
| 94 | void add_copied(const Region& dest, const Point& delta) { |
| 95 | updates.add_copied(dest, delta); |
| 96 | } |
| 97 | |
| 98 | const char* getPeerEndpoint() const {return peerEndpoint.buf;} |
| 99 | |
| 100 | // approveConnectionOrClose() is called some time after |
| 101 | // VNCServerST::queryConnection() has returned with PENDING to accept or |
| 102 | // reject the connection. The accept argument should be true for |
| 103 | // acceptance, or false for rejection, in which case a string reason may |
| 104 | // also be given. |
| 105 | |
| 106 | void approveConnectionOrClose(bool accept, const char* reason); |
| 107 | |
| 108 | char* getStartTime(); |
| 109 | |
| 110 | void setStatus(int status); |
| 111 | int getStatus(); |
| 112 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 113 | private: |
| 114 | // SConnection callbacks |
| 115 | |
| 116 | // These methods are invoked as callbacks from processMsg(). Note that |
| 117 | // none of these methods should call any of the above methods which may |
| 118 | // delete the SConnectionST object. |
| 119 | |
| 120 | virtual void authSuccess(); |
| 121 | virtual void queryConnection(const char* userName); |
| 122 | virtual void clientInit(bool shared); |
| 123 | virtual void setPixelFormat(const PixelFormat& pf); |
| 124 | virtual void pointerEvent(const Point& pos, int buttonMask); |
| 125 | virtual void keyEvent(rdr::U32 key, bool down); |
| 126 | virtual void clientCutText(const char* str, int len); |
| 127 | virtual void framebufferUpdateRequest(const Rect& r, bool incremental); |
Pierre Ossman | c5e2560 | 2009-03-20 12:59:05 +0000 | [diff] [blame] | 128 | virtual void setDesktopSize(int fb_width, int fb_height); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 129 | virtual void setInitialColourMap(); |
| 130 | virtual void supportsLocalCursor(); |
| 131 | |
| 132 | // setAccessRights() allows a security package to limit the access rights |
| 133 | // of a VNCSConnectioST to the server. These access rights are applied |
| 134 | // such that the actual rights granted are the minimum of the server's |
| 135 | // default access settings and the connection's access settings. |
| 136 | virtual void setAccessRights(AccessRights ar) {accessRights=ar;} |
| 137 | |
| 138 | // WriteSetCursorCallback |
| 139 | virtual void writeSetCursorCallback(); |
| 140 | |
| 141 | // Internal methods |
| 142 | |
| 143 | // writeFramebufferUpdate() attempts to write a framebuffer update to the |
| 144 | // client. |
| 145 | |
| 146 | void writeFramebufferUpdate(); |
| 147 | |
| 148 | void writeRenderedCursorRect(); |
| 149 | void setColourMapEntries(int firstColour, int nColours); |
| 150 | void setCursor(); |
| 151 | void setSocketTimeouts(); |
| 152 | |
| 153 | network::Socket* sock; |
| 154 | CharArray peerEndpoint; |
| 155 | VNCServerST* server; |
| 156 | SimpleUpdateTracker updates; |
| 157 | TransImageGetter image_getter; |
| 158 | Region requested; |
| 159 | bool drawRenderedCursor, removeRenderedCursor; |
| 160 | Rect renderedCursorRect; |
| 161 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 162 | std::set<rdr::U32> pressedKeys; |
| 163 | |
| 164 | time_t lastEventTime; |
| 165 | time_t pointerEventTime; |
| 166 | Point pointerEventPos; |
| 167 | |
| 168 | AccessRights accessRights; |
| 169 | |
| 170 | CharArray closeReason; |
| 171 | time_t startTime; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 172 | }; |
| 173 | } |
| 174 | #endif |