⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vncsconnectionst.cxx

📁 linux可以运行程序源码
💻 CXX
📖 第 1 页 / 共 2 页
字号:
/* Copyright (C) 2002-2005 RealVNC Ltd.  All Rights Reserved. *  * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. *  * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. *  * You should have received a copy of the GNU General Public License * along with this software; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, * USA. */#include <rfb/VNCSConnectionST.h>#include <rfb/LogWriter.h>#include <rfb/secTypes.h>#include <rfb/ServerCore.h>#include <rfb/ComparingUpdateTracker.h>#include <rfb/KeyRemapper.h>#define XK_MISCELLANY#define XK_XKB_KEYS#include <rfb/keysymdef.h>using namespace rfb;static LogWriter vlog("VNCSConnST");VNCSConnectionST::VNCSConnectionST(VNCServerST* server_, network::Socket *s,                                   bool reverse)  : SConnection(server_->securityFactory, reverse), sock(s), server(server_),    updates(false), image_getter(server->useEconomicTranslate),    drawRenderedCursor(false), removeRenderedCursor(false),    pointerEventTime(0), accessRights(AccessDefault){  setStreams(&sock->inStream(), &sock->outStream());  peerEndpoint.buf = sock->getPeerEndpoint();  VNCServerST::connectionsLog.write(1,"accepted: %s", peerEndpoint.buf);  // Configure the socket  setSocketTimeouts();  lastEventTime = time(0);  // Add this client to the VNCServerST  server->clients.push_front(this);}VNCSConnectionST::~VNCSConnectionST(){  // If we reach here then VNCServerST is deleting us!  VNCServerST::connectionsLog.write(1,"closed: %s (%s)",                                    peerEndpoint.buf,                                    (closeReason.buf) ? closeReason.buf : "");  // Release any keys the client still had pressed  std::set<rdr::U32>::iterator i;  for (i=pressedKeys.begin(); i!=pressedKeys.end(); i++)    server->desktop->keyEvent(*i, false);  if (server->pointerClient == this)    server->pointerClient = 0;  // Remove this client from the server  server->clients.remove(this);}// Methods called from VNCServerSTbool VNCSConnectionST::init(){  try {    initialiseProtocol();  } catch (rdr::Exception& e) {    close(e.str());    return false;  }  return true;}void VNCSConnectionST::close(const char* reason){  // Log the reason for the close  if (!closeReason.buf)    closeReason.buf = strDup(reason);  else    vlog.debug("second close: %s (%s)", peerEndpoint.buf, reason);  // Just shutdown the socket and mark our state as closing.  Eventually the  // calling code will call VNCServerST's removeSocket() method causing us to  // be deleted.  sock->shutdown();  setState(RFBSTATE_CLOSING);}void VNCSConnectionST::processMessages(){  if (state() == RFBSTATE_CLOSING) return;  try {    // - Now set appropriate socket timeouts and process data    setSocketTimeouts();    bool clientsReadyBefore = server->clientsReadyForUpdate();    while (getInStream()->checkNoWait(1)) {      processMsg();    }    if (!clientsReadyBefore && !requested.is_empty())      server->desktop->framebufferUpdateRequest();  } catch (rdr::EndOfStream&) {    close("Clean disconnection");  } catch (rdr::Exception &e) {    close(e.str());  }}void VNCSConnectionST::writeFramebufferUpdateOrClose(){  try {    writeFramebufferUpdate();  } catch(rdr::Exception &e) {    close(e.str());  }}void VNCSConnectionST::pixelBufferChange(){  try {    if (!authenticated()) return;    if (cp.width && cp.height && (server->pb->width() != cp.width ||                                  server->pb->height() != cp.height))    {      // We need to clip the next update to the new size, but also add any      // extra bits if it's bigger.  If we wanted to do this exactly, something      // like the code below would do it, but at the moment we just update the      // entire new size.  However, we do need to clip the renderedCursorRect      // because that might be added to updates in writeFramebufferUpdate().      //updates.intersect(server->pb->getRect());      //      //if (server->pb->width() > cp.width)      //  updates.add_changed(Rect(cp.width, 0, server->pb->width(),      //                           server->pb->height()));      //if (server->pb->height() > cp.height)      //  updates.add_changed(Rect(0, cp.height, cp.width,      //                           server->pb->height()));      renderedCursorRect = renderedCursorRect.intersect(server->pb->getRect());      cp.width = server->pb->width();      cp.height = server->pb->height();      if (state() == RFBSTATE_NORMAL) {        if (!writer()->writeSetDesktopSize()) {          close("Client does not support desktop resize");          return;        }      }    }    // Just update the whole screen at the moment because we're too lazy to    // work out what's actually changed.    updates.clear();    updates.add_changed(server->pb->getRect());    vlog.debug("pixel buffer changed - re-initialising image getter");    image_getter.init(server->pb, cp.pf(), writer());    if (writer()->needFakeUpdate())      writeFramebufferUpdate();  } catch(rdr::Exception &e) {    close(e.str());  }}void VNCSConnectionST::setColourMapEntriesOrClose(int firstColour,int nColours){  try {    setColourMapEntries(firstColour, nColours);  } catch(rdr::Exception& e) {    close(e.str());  }}void VNCSConnectionST::bell(){  try {    if (state() == RFBSTATE_NORMAL) writer()->writeBell();  } catch(rdr::Exception& e) {    close(e.str());  }}void VNCSConnectionST::serverCutText(const char *str, int len){  try {    if (!(accessRights & AccessCutText)) return;    if (!rfb::Server::sendCutText) return;    if (state() == RFBSTATE_NORMAL)      writer()->writeServerCutText(str, len);  } catch(rdr::Exception& e) {    close(e.str());  }}void VNCSConnectionST::setCursorOrClose(){  try {    setCursor();  } catch(rdr::Exception& e) {    close(e.str());  }}int VNCSConnectionST::checkIdleTimeout(){  int idleTimeout = rfb::Server::idleTimeout;  if (idleTimeout == 0) return 0;  if (state() != RFBSTATE_NORMAL && idleTimeout < 15)    idleTimeout = 15; // minimum of 15 seconds while authenticating  time_t now = time(0);  if (now < lastEventTime) {    // Someone must have set the time backwards.  Set lastEventTime so that the    // idleTimeout will count from now.    vlog.info("Time has gone backwards - resetting idle timeout");    lastEventTime = now;  }  int timeLeft = lastEventTime + idleTimeout - now;  if (timeLeft < -60) {    // Our callback is over a minute late - someone must have set the time    // forwards.  Set lastEventTime so that the idleTimeout will count from    // now.    vlog.info("Time has gone forwards - resetting idle timeout");    lastEventTime = now;    return secsToMillis(idleTimeout);  }  if (timeLeft <= 0) {    close("Idle timeout");    return 0;  }  return secsToMillis(timeLeft);}// renderedCursorChange() is called whenever the server-side rendered cursor// changes shape or position.  It ensures that the next update will clean up// the old rendered cursor and if necessary draw the new rendered cursor.void VNCSConnectionST::renderedCursorChange(){  if (state() != RFBSTATE_NORMAL) return;  removeRenderedCursor = true;  if (needRenderedCursor())    drawRenderedCursor = true;}// needRenderedCursor() returns true if this client needs the server-side// rendered cursor.  This may be because it does not support local cursor or// because the current cursor position has not been set by this client.// Unfortunately we can't know for sure when the current cursor position has// been set by this client.  We guess that this is the case when the current// cursor position is the same as the last pointer event from this client, or// if it is a very short time since this client's last pointer event (up to a// second).  [ Ideally we should do finer-grained timing here and make the time// configurable, but I don't think it's that important. ]bool VNCSConnectionST::needRenderedCursor(){  return (state() == RFBSTATE_NORMAL          && (!cp.supportsLocalCursor              || (!server->cursorPos.equals(pointerEventPos) &&                  (time(0) - pointerEventTime) > 0)));}void VNCSConnectionST::approveConnectionOrClose(bool accept,                                                const char* reason){  try {    approveConnection(accept, reason);  } catch (rdr::Exception& e) {    close(e.str());  }}// -=- Callbacks from SConnectionvoid VNCSConnectionST::authSuccess(){  lastEventTime = time(0);  server->startDesktop();  // - Set the connection parameters appropriately  cp.width = server->pb->width();  cp.height = server->pb->height();  cp.setName(server->getName());    // - Set the default pixel format  cp.setPF(server->pb->getPF());  char buffer[256];  cp.pf().print(buffer, 256);  vlog.info("Server default pixel format %s", buffer);  image_getter.init(server->pb, cp.pf(), 0);  // - Mark the entire display as "dirty"  updates.add_changed(server->pb->getRect());}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -