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> |
Pierre Ossman | 1bb8b6c | 2011-10-25 15:20:05 +0000 | [diff] [blame^] | 35 | #include <rfb/Timer.h> |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 36 | |
| 37 | namespace rfb { |
| 38 | class VNCSConnectionST : public SConnection, |
Pierre Ossman | 1bb8b6c | 2011-10-25 15:20:05 +0000 | [diff] [blame^] | 39 | public WriteSetCursorCallback, |
| 40 | public Timer::Callback { |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 41 | public: |
| 42 | VNCSConnectionST(VNCServerST* server_, network::Socket* s, bool reverse); |
| 43 | virtual ~VNCSConnectionST(); |
| 44 | |
| 45 | // Methods called from VNCServerST. None of these methods ever knowingly |
| 46 | // throw an exception. |
| 47 | |
| 48 | // Unless otherwise stated, the SConnectionST may not be valid after any of |
| 49 | // these methods are called, since they catch exceptions and may have |
| 50 | // called close() which deletes the object. |
| 51 | |
| 52 | // init() must be called to initialise the protocol. If it fails it |
| 53 | // returns false, and close() will have been called. |
| 54 | bool init(); |
| 55 | |
| 56 | // close() shuts down the socket to the client and deletes the |
| 57 | // SConnectionST object. |
| 58 | void close(const char* reason); |
| 59 | |
| 60 | // processMessages() processes incoming messages from the client, invoking |
| 61 | // various callbacks as a result. It continues to process messages until |
| 62 | // reading might block. shutdown() will be called on the connection's |
| 63 | // Socket if an error occurs, via the close() call. |
| 64 | void processMessages(); |
| 65 | |
| 66 | void writeFramebufferUpdateOrClose(); |
| 67 | void pixelBufferChange(); |
Pierre Ossman | 04e62db | 2009-03-23 16:57:07 +0000 | [diff] [blame] | 68 | void screenLayoutChange(rdr::U16 reason); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 69 | void setColourMapEntriesOrClose(int firstColour, int nColours); |
| 70 | void bell(); |
| 71 | void serverCutText(const char *str, int len); |
Peter Åstrand | c39e078 | 2009-01-15 12:21:42 +0000 | [diff] [blame] | 72 | void setDesktopName(const char *name); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 73 | void setCursorOrClose(); |
| 74 | |
| 75 | // checkIdleTimeout() returns the number of milliseconds left until the |
| 76 | // idle timeout expires. If it has expired, the connection is closed and |
| 77 | // zero is returned. Zero is also returned if there is no idle timeout. |
| 78 | int checkIdleTimeout(); |
| 79 | |
| 80 | // The following methods never throw exceptions nor do they ever delete the |
| 81 | // SConnectionST object. |
| 82 | |
| 83 | // renderedCursorChange() is called whenever the server-side rendered |
| 84 | // cursor changes shape or position. It ensures that the next update will |
| 85 | // clean up the old rendered cursor and if necessary draw the new rendered |
| 86 | // cursor. |
| 87 | void renderedCursorChange(); |
| 88 | |
| 89 | // needRenderedCursor() returns true if this client needs the server-side |
| 90 | // rendered cursor. This may be because it does not support local cursor |
| 91 | // or because the current cursor position has not been set by this client. |
| 92 | bool needRenderedCursor(); |
| 93 | |
| 94 | network::Socket* getSock() { return sock; } |
| 95 | bool readyForUpdate() { return !requested.is_empty(); } |
| 96 | void add_changed(const Region& region) { updates.add_changed(region); } |
| 97 | void add_copied(const Region& dest, const Point& delta) { |
| 98 | updates.add_copied(dest, delta); |
| 99 | } |
| 100 | |
| 101 | const char* getPeerEndpoint() const {return peerEndpoint.buf;} |
| 102 | |
| 103 | // approveConnectionOrClose() is called some time after |
| 104 | // VNCServerST::queryConnection() has returned with PENDING to accept or |
| 105 | // reject the connection. The accept argument should be true for |
| 106 | // acceptance, or false for rejection, in which case a string reason may |
| 107 | // also be given. |
| 108 | |
| 109 | void approveConnectionOrClose(bool accept, const char* reason); |
| 110 | |
| 111 | char* getStartTime(); |
| 112 | |
| 113 | void setStatus(int status); |
| 114 | int getStatus(); |
| 115 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 116 | private: |
| 117 | // SConnection callbacks |
| 118 | |
| 119 | // These methods are invoked as callbacks from processMsg(). Note that |
| 120 | // none of these methods should call any of the above methods which may |
| 121 | // delete the SConnectionST object. |
| 122 | |
| 123 | virtual void authSuccess(); |
| 124 | virtual void queryConnection(const char* userName); |
| 125 | virtual void clientInit(bool shared); |
| 126 | virtual void setPixelFormat(const PixelFormat& pf); |
| 127 | virtual void pointerEvent(const Point& pos, int buttonMask); |
| 128 | virtual void keyEvent(rdr::U32 key, bool down); |
| 129 | virtual void clientCutText(const char* str, int len); |
| 130 | virtual void framebufferUpdateRequest(const Rect& r, bool incremental); |
Pierre Ossman | 34bb061 | 2009-03-21 21:16:14 +0000 | [diff] [blame] | 131 | virtual void setDesktopSize(int fb_width, int fb_height, |
| 132 | const ScreenSet& layout); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 133 | virtual void setInitialColourMap(); |
| 134 | virtual void supportsLocalCursor(); |
| 135 | |
| 136 | // setAccessRights() allows a security package to limit the access rights |
| 137 | // of a VNCSConnectioST to the server. These access rights are applied |
| 138 | // such that the actual rights granted are the minimum of the server's |
| 139 | // default access settings and the connection's access settings. |
| 140 | virtual void setAccessRights(AccessRights ar) {accessRights=ar;} |
| 141 | |
| 142 | // WriteSetCursorCallback |
| 143 | virtual void writeSetCursorCallback(); |
| 144 | |
Pierre Ossman | 1bb8b6c | 2011-10-25 15:20:05 +0000 | [diff] [blame^] | 145 | // Timer callbacks |
| 146 | virtual bool handleTimeout(Timer* t); |
| 147 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 148 | // Internal methods |
| 149 | |
Pierre Ossman | 1bb8b6c | 2011-10-25 15:20:05 +0000 | [diff] [blame^] | 150 | bool isCongested(); |
| 151 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 152 | // writeFramebufferUpdate() attempts to write a framebuffer update to the |
| 153 | // client. |
| 154 | |
| 155 | void writeFramebufferUpdate(); |
| 156 | |
| 157 | void writeRenderedCursorRect(); |
| 158 | void setColourMapEntries(int firstColour, int nColours); |
| 159 | void setCursor(); |
| 160 | void setSocketTimeouts(); |
| 161 | |
| 162 | network::Socket* sock; |
| 163 | CharArray peerEndpoint; |
| 164 | VNCServerST* server; |
| 165 | SimpleUpdateTracker updates; |
| 166 | TransImageGetter image_getter; |
| 167 | Region requested; |
| 168 | bool drawRenderedCursor, removeRenderedCursor; |
| 169 | Rect renderedCursorRect; |
| 170 | |
Pierre Ossman | 1bb8b6c | 2011-10-25 15:20:05 +0000 | [diff] [blame^] | 171 | Timer updateTimer; |
| 172 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 173 | std::set<rdr::U32> pressedKeys; |
| 174 | |
| 175 | time_t lastEventTime; |
| 176 | time_t pointerEventTime; |
| 177 | Point pointerEventPos; |
| 178 | |
| 179 | AccessRights accessRights; |
| 180 | |
| 181 | CharArray closeReason; |
| 182 | time_t startTime; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 183 | }; |
| 184 | } |
| 185 | #endif |