diff options
author | Sebastian | 2010-05-12 19:42:27 +0200 |
---|---|---|
committer | Sebastian | 2010-05-12 19:42:27 +0200 |
commit | ce3329047d378a14006ce74ec273ac59e3375303 (patch) | |
tree | 782430f270b4c7aca1b35d5b7813518e3797c555 /src/core | |
download | pvs-ce3329047d378a14006ce74ec273ac59e3375303.tar.gz pvs-ce3329047d378a14006ce74ec273ac59e3375303.tar.xz pvs-ce3329047d378a14006ce74ec273ac59e3375303.zip |
initial import of latest svn version
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/pvsChatClient.cpp | 151 | ||||
-rw-r--r-- | src/core/pvsChatClient.h | 71 | ||||
-rw-r--r-- | src/core/pvsChatMsg.cpp | 108 | ||||
-rw-r--r-- | src/core/pvsChatMsg.h | 48 | ||||
-rw-r--r-- | src/core/pvsClient.cpp | 301 | ||||
-rw-r--r-- | src/core/pvsClient.h | 129 | ||||
-rw-r--r-- | src/core/pvsConnectionManager.cpp | 483 | ||||
-rw-r--r-- | src/core/pvsConnectionManager.h | 118 | ||||
-rw-r--r-- | src/core/pvsServer.cpp | 22 | ||||
-rw-r--r-- | src/core/pvsServer.h | 24 | ||||
-rw-r--r-- | src/core/vncConnection.cpp | 261 | ||||
-rw-r--r-- | src/core/vncConnection.h | 99 |
12 files changed, 1815 insertions, 0 deletions
diff --git a/src/core/pvsChatClient.cpp b/src/core/pvsChatClient.cpp new file mode 100644 index 0000000..6717e34 --- /dev/null +++ b/src/core/pvsChatClient.cpp @@ -0,0 +1,151 @@ +/* +# Copyright (c) 2009,2010 - OpenSLX Project, Computer Center University of +# Freiburg +# +# This program is free software distributed under the GPL version 2. +# See http://openslx.org/COPYING +# +# If you have any feedback please consult http://openslx.org/feedback and +# send your suggestions, praise, or complaints to feedback@openslx.org +# +# General information about OpenSLX can be found at http://openslx.org/ +# ----------------------------------------------------------------------------- +# pvsChatClient.cpp +# - Methods of the chat service. +# ----------------------------------------------------------------------------- +*/ + +#include "pvsChatClient.h" + +using namespace std; + +// Constructor +PVSChatClient::PVSChatClient() +{ + _chatServerConnection = NULL; + _source = getFullUsername(); + _registered = true; +} + +PVSChatClient::~PVSChatClient() +{ + +} + +// Get Chat login name. +QString PVSChatClient::getSource() +{ + return _source; +} + +// Set (from server) assigned username. +void PVSChatClient::setSource(QString name) +{ + _source = name; + _registered = true; +} + +bool PVSChatClient::isRegistered() +{ + return _registered; +} + +// Set PVSServerConnection +void PVSChatClient::setServerConnection(PVSServerConnection* sc) +{ + if (sc) + { + _chatServerConnection = sc; + _chatServerConnection->addChatHandler("*", this, &PVSChatClient::receive); + } +} + +// Send a message to Server. +void PVSChatClient::send(QString tar, QString msg) +{ + // Append username to msg. + QString username = _source; + username.append(":"); + msg = username.append(msg) ; + + // Create a Msg. + PVSMsg myMsg(PVSMESSAGE, tar, msg, 0); + + // Send the message. + if (_chatServerConnection) + _chatServerConnection->sendMessage(myMsg); + else + ConsoleLog writeError("[CHAT] Chat get no server connection"); // no ServerConnection + +} + +// Handle messages from server. +void PVSChatClient::receive(PVSMsg recv) +{ + PVSChatMsg chatMsg(recv); + + if(chatMsg.isCommand()) // command message for update of the client list. + { + _chatCommandDispatcher.fire(chatMsg); + } + else // conversation message. + { + if(chatMsg.getMsg().size()) + _chatMessageDispatcher.fire(chatMsg); + } +} + +// Return the current list of logged Clients. +QStringList PVSChatClient::getClients() +{ + return _clients; +} + +// Return the ip of the username. +QString PVSChatClient::getIPFromUsername(QString username) +{ + if(_clientsData.contains(username)) + { + return _clientsData.value(username); + } + else + { + ConsoleLog writeError("[CHAT] Wanted key was not found in clients hash table."); + return QString("ip not found"); + } +} + +// Add the name and ip of a new client. +void PVSChatClient::addClient(QString name, QString ip) +{ + if(!_clients.contains(name)) + { + _clients.append(name); + _clientsData[name] = ip; + } + else + { + ConsoleLog writeError("[CHAT] The new client wasn't added, because exists allready."); + } +} + +// Remove the name and ip of a removed client. +void PVSChatClient::removeClient(QString name) +{ + if(_clients.contains(name)) + { + _clients.removeOne(name); + _clientsData.remove(name); + } + else + { + ConsoleLog writeError("[CHAT] The new client can not be removed, because doesn't exist."); + } +} + +// Delete all infomation about client. +void PVSChatClient::clearClients() +{ + _clients.clear(); + _clientsData.clear(); +} diff --git a/src/core/pvsChatClient.h b/src/core/pvsChatClient.h new file mode 100644 index 0000000..2cb5d9f --- /dev/null +++ b/src/core/pvsChatClient.h @@ -0,0 +1,71 @@ +/* +# Copyright (c) 2009 - OpenSLX Project, Computer Center University of Freiburg +# +# This program is free software distributed under the GPL version 2. +# See http://openslx.org/COPYING +# +# If you have any feedback please consult http://openslx.org/feedback and +# send your suggestions, praise, or complaints to feedback@openslx.org +# +# General information about OpenSLX can be found at http://openslx.org/ +*/ + +// pvsChatClient.h + +#ifndef PVSCHATCLIENT_H_ +#define PVSCHATCLIENT_H_ + +#include <iostream> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sstream> +#include <fstream> +#include <QStringList> +#include <QHash> +#include "src/net/pvsMsg.h" +#include "src/core/pvsChatMsg.h" +#include "src/net/pvsServerConnection.h" +#include "src/util/consoleLogger.h" +#include "src/util/util.h" + +class PVS; // forward declaration. + +class PVSChatClient +{ + +public: + + PVSChatClient(); + ~PVSChatClient(); + void setServerConnection(PVSServerConnection* sc); + void setSource(QString name); + QString getSource(); + QStringList getClients(); + QString getIPFromUsername(QString username); + void addClient(QString name, QString ip); + void removeClient(QString name); + void clearClients(); + void send(QString tar, QString msg); + void receive(PVSMsg recv); + bool isRegistered(); + EventDispatcher<PVSChatMsg>& getChatMsgHandler() + { + return _chatMessageDispatcher; + }; + EventDispatcher<PVSChatMsg>& getChatCommandHandler() + { + return _chatCommandDispatcher; + }; + +private: + + QString _source; + bool _registered; + QStringList _clients; + QHash<QString, QString> _clientsData; + PVSServerConnection *_chatServerConnection; + EventDispatcher<PVSChatMsg> _chatMessageDispatcher; + EventDispatcher<PVSChatMsg> _chatCommandDispatcher; +}; +#endif diff --git a/src/core/pvsChatMsg.cpp b/src/core/pvsChatMsg.cpp new file mode 100644 index 0000000..7a2d755 --- /dev/null +++ b/src/core/pvsChatMsg.cpp @@ -0,0 +1,108 @@ +/* +# Copyright (c) 2009 - OpenSLX Project, Computer Center University of Freiburg +# +# This program is free software distributed under the GPL version 2. +# See http://openslx.org/COPYING +# +# If you have any feedback please consult http://openslx.org/feedback and +# send your suggestions, praise, or complaints to feedback@openslx.org +# +# General information about OpenSLX can be found at http://openslx.org/ +*/ + +// pvsChatMsg.cpp + +#include "src/core/pvsChatMsg.h" +#include <QStringList> + +PVSChatMsg::PVSChatMsg(PVSMsg pvsMsg) +{ + QStringList l = pvsMsg.getMessage().split(":"); + + if(l[0] == "") + { + _command = pvsMsg.getIdent(); + _nickFrom = "unseted"; + _nickTo = "unseted"; + _msg = "unseted"; + + if(l[2] == "local") + { + _username = l[1]; + _ip = pvsMsg.getRemoteIp(); + } + else + { + _username = l[1]; + _ip = l[2]; + } + } + else + { + _nickFrom = l[0]; + _msg = pvsMsg.getMessage().remove(0, l[0].size()+1); + _nickTo = pvsMsg.getIdent(); + _command = "unseted"; + _username = "unseted"; + _ip = "unseted"; + } +} + +PVSChatMsg::~PVSChatMsg(){}; + +void PVSChatMsg::setNickFrom(QString nick) +{ + _nickFrom = nick; +} + +void PVSChatMsg::setNickTo(QString nick) +{ + _nickTo = nick; +} + +void PVSChatMsg::setMsg(QString msg) +{ + _msg = msg; +} + +QString PVSChatMsg::getNickFrom() +{ + return _nickFrom; +} + +QString PVSChatMsg::getNickTo() +{ + return _nickTo; +} + +QString PVSChatMsg::getMsg() +{ + return _msg; +} + +QString PVSChatMsg::getCommand() +{ + return _command; +} + +QString PVSChatMsg::getUsername() +{ + return _username; +} + +QString PVSChatMsg::getIp() +{ + return _ip; +} + +bool PVSChatMsg::isCommand() +{ + if(_command == "unseted") + { + return false; + } + else + { + return true; + } +} diff --git a/src/core/pvsChatMsg.h b/src/core/pvsChatMsg.h new file mode 100644 index 0000000..0a9793e --- /dev/null +++ b/src/core/pvsChatMsg.h @@ -0,0 +1,48 @@ +/* +# Copyright (c) 2009 - OpenSLX Project, Computer Center University of Freiburg +# +# This program is free software distributed under the GPL version 2. +# See http://openslx.org/COPYING +# +# If you have any feedback please consult http://openslx.org/feedback and +# send your suggestions, praise, or complaints to feedback@openslx.org +# +# General information about OpenSLX can be found at http://openslx.org/ +*/ + +// pvsChatMsg.h + +#include "src/net/pvsMsg.h" + +#ifndef PVSCHATMSG_H_ +#define PVSCHATMSG_H_ + +class PVSChatMsg +{ +public: + + PVSChatMsg(PVSMsg pvsMsg); + ~PVSChatMsg(); + + void setNickFrom(QString nick); + void setNickTo(QString nick); + void setMsg(QString msg); + QString getNickFrom(); + QString getNickTo(); + QString getMsg(); + QString getCommand(); + QString getUsername(); + QString getIp(); + bool isCommand(); + + +private: + QString _msg; + QString _nickFrom; + QString _nickTo; + QString _command; + QString _username; + QString _ip; +}; + +#endif /* PVSCHATMSG_H_ */ diff --git a/src/core/pvsClient.cpp b/src/core/pvsClient.cpp new file mode 100644 index 0000000..0d08b1d --- /dev/null +++ b/src/core/pvsClient.cpp @@ -0,0 +1,301 @@ +/* +# Copyright (c) 2009 - OpenSLX Project, Computer Center University of Freiburg +# +# This program is free software distributed under the GPL version 2. +# See http://openslx.org/COPYING +# +# If you have any feedback please consult http://openslx.org/feedback and +# send your suggestions, praise, or complaints to feedback@openslx.org +# +# General information about OpenSLX can be found at http://openslx.org/ +# ----------------------------------------------------------------------------- +# src/core/pvsConnection.cpp +# - ... +# ----------------------------------------------------------------------------- +*/ + +#include "pvsClient.h" +#include "pvsServer.h" +#include "pvsConnectionManager.h" +#include "src/util/consoleLogger.h" +#include "src/core/vncConnection.h" +#include "src/gui/mainWindow.h" + +#define CONST_PASS "" + +PVSClient::PVSClient(PVSClientConnection *newClient) +{ + newClient->setParent(this); // so the object will be deleted when this object dies + _pvsClientConnection = newClient; + _vncConnection = NULL; + _vncRwPasswordReceived = _vncPasswordReceived = _vncAllowed = false; + _vncInitMutex = false; + _hostString = newClient->getAddress(); + _hostName = _hostString; // for now + //_gotFrame = false; + _vncPort = -1; + _vncProject = false; + _connectionFrame = NULL; + _loginName = "unseted"; +} + +PVSClient::~PVSClient() +{ + if (_vncConnection) + { + disconnect(_vncConnection, SIGNAL(finished()), this, SLOT(vncFinished())); + _vncConnection->clear(); + delete _vncConnection; + _vncConnection = NULL; + } +} + +/* TODO: Call this method from an extra thread. + * Imo there should be one thread (probably in ConnectionManager) that does this job. + * Also, this function should just receive the data etc, but the actual drawing has to happen + * in the Qt main thread (the thread the window belongs to) + * Right now with GTK it would, but pay attention when switching to Qt + * */ + +void PVSClient::tick() +{ + if (_vncInitMutex) return; + if (_vncPasswordReceived && _vncAllowed && _vncRequested && _vncConnection == NULL) + { + vncProbe(); + } +} + +QString PVSClient::getIp() +{ + return _hostString; +} + +QString PVSClient::getDesktopName() +{ + if (_vncConnection) + { + return _vncConnection->getDesktopName(); + } + + return _hostName; +} + +QString PVSClient::getUserName() +{ + return _userName; +} + +QString PVSClient::getLoginName() +{ + return _loginName; +} + +//Returns Port +int PVSClient::getPort(){ + return _vncPort; +} + + +bool PVSClient::getVNCAllowed() +{ + return _vncAllowed; +} + +void PVSClient::requestVNCConnect() +{ + _vncRequested = true; + _pvsClientConnection->push_back_send(PVSMsg(PVSCOMMAND, "VNCREQUEST", "YES")); +} + +void PVSClient::setVncPassword(QString password) +{ + _vncPassword = password; + _vncPasswordReceived = true; +} + +void PVSClient::setVncRwPassword(QString password) +{ + _vncRwPassword = password; + _vncRwPasswordReceived = true; +} + +QString PVSClient::getPassword() +{ + return _vncPassword; +} + +QString PVSClient::getRWPassword() +{ + return _vncRwPassword; +} + +void PVSClient::setProject(bool value) +{ + _vncProject = value; + +} + +void PVSClient::setVncPort(int newPort) +{ + if (newPort < 1) + { + ConsoleLog writeNetwork("Client sent invalid vnc-port."); + return; + } + _vncPort = newPort; + ConsoleLog writeNetwork(QString("Received new vnc-port: ").append(int2String(newPort))); +} +void PVSClient::setAllowed(bool allow) +{ + _vncAllowed = allow; + + if (allow) + { + ConsoleLog writeLine(QString("VNCConnection was granted by the Client.")); + _vncRequested = true; + } + else + { + ConsoleLog writeLine(QString("VNCConnection was denied by the Client.")); + _vncPort = 0; + _vncPasswordReceived = false; + } + + if(_vncProject){ + if(allow){ + MainWindow::getConnectionWindow()->projectStations(_hostString); + } + else{ + _vncProject = false; + } + } +} + +void PVSClient::shutDownVNC() +{ + if (_vncConnection) + { + disconnect(_vncConnection, SIGNAL(finished()), this, SLOT(vncFinished())); + _vncConnection->clear(); + delete _vncConnection; + _vncConnection = NULL; + } +} + +void PVSClient::shutDownClient() +{ + if (_pvsClientConnection) + { + _pvsClientConnection->closeConnection(); + } +} + +void PVSClient::onClientDisconnected() +{ + _pvsClientConnection = NULL; + +} + +bool PVSClient::getLocked() +{ + // TODO: Implement! + // Previously "_pvsClientConnection->isLocked()" war returned, + // but that method always returned "false" and was removed now. + // It really didn't make any sense to put that there anyways, it has + // to be taken care of in this class. + return false; +} + + +bool PVSClient::sendMessage(PVSMsgType type, QString ident, QString message) +{ + if (_pvsClientConnection) + { + _pvsClientConnection->push_back_send(PVSMsg(type, (char*)ident.toUtf8().data(), message)); + return true; + } + return false; +} + +bool PVSClient::sendMessage(PVSMsg message) +{ + if (_pvsClientConnection) + { + _pvsClientConnection->push_back_send(message); + return true; + } + return false; +} + +void PVSClient::vncProbe() +{ + _vncInitMutex = true; + if (_vncPasswordReceived && _vncAllowed && _vncRequested) + { +#ifndef local_test + QString portString; + if (_vncPort > 0) + { + portString = int2String(_vncPort); + } + else + { + portString = int2String(5900); //std port + ConsoleLog writeError("WARNING: Using default vnc-port 5900"); + } +#else + QString portString; + portString = int2String(5900); +#endif + + if (_hostString.length() > 0) + { + char ** args = new char*[1]; + QString fullstring(_hostString); + fullstring.append(":"); + fullstring.append(portString); + args[0] = new char[fullstring.length()+1]; + std::cout << "[pvsC]connecting to: " << fullstring.toStdString() << std::endl; + ConsoleLog writeNetwork(QString("connecting to: ").append(fullstring)); + //strcpy(args[0], host); + strcpy(args[0], fullstring.toUtf8().data()); + VNCConnectInfo tmpInfo(1, args, _vncPassword); + + VNCConnection* newConnection = new VNCConnection(tmpInfo.getPassword()); + if (newConnection) + { + if (newConnection->initClient(&tmpInfo)) + { + _vncProject = false; + if (_vncConnection) _vncConnection->setDead(); + _vncConnection = newConnection; + connect(_vncConnection, SIGNAL(finished()), this, SLOT(vncFinished())); + //TODO: comment beachten !!!!! + //vncAllowed = false; // to make sure we recheck if the allowance wasnt revoked in the meantime to prevent + // another connection + ConsoleLog writeLine(QString("VNC connection attempt succeeded.")); + MainWindow::getWindow()->getConnectionWindow()->onVNCAdd(this); + } + else + { + delete newConnection; + // TODO: post on the log console + ConsoleLog writeError(QString("VNC connection attempt failed.")); + _vncRequested = false; // otherwise loop of death + } + } + } + } + _vncInitMutex = false; +} + +void PVSClient::vncFinished() +{ + disconnect(_vncConnection, SIGNAL(finished()), this, SLOT(vncFinished())); + delete _vncConnection; + _vncConnection = NULL; + _vncPort = 0; + _vncPasswordReceived = false; +} + diff --git a/src/core/pvsClient.h b/src/core/pvsClient.h new file mode 100644 index 0000000..180995a --- /dev/null +++ b/src/core/pvsClient.h @@ -0,0 +1,129 @@ +/** + * PVSConnection + * + * the representation of a connection from a PVSClient to the PVSServer + * it holds a pointer the PVSClientConnection we got from a PVS(Listen)Server + * and (if present) a pointer to a VNCConnection to the same host as the PVSClientConnection + */ + + + + +#ifndef _PVSCONNECTION_H_ +#define _PVSCONNECTION_H_ +#include "vncConnection.h" +#include "src/net/pvsClientConnection.h" +#include "src/gui/frame.h" +#include <QtCore/QThread> + +class PVSServer; +class VNCConnection; +class PVSClient; +class ConnectionFrame; +class Frame; + +class PVSClient : public QObject +{ + Q_OBJECT + friend class PVSServer; + friend class VNCConnection; + +public: + // C'Tor and D'Tor + PVSClient(PVSClientConnection *newClient); + ~PVSClient(); + + // heartbeat + void tick(); + + + //general stuff + char* getHost(); + QString getIp(); + QString getDesktopName(); + QString getUserName(); + QString getLoginName(); + bool getVNCAllowed(); + int getPort(); + void setUsername(QString name) + { + _userName = name; + }; + void setLoginName(QString ln) + { + _loginName = ln; + }; + + // methods for/from vnConnection + void requestVNCConnect(); + void setVncPassword(QString password); + void setVncRwPassword(QString password); + + QString getPassword(); + QString getRWPassword(); + + void setProject(bool value); + void setAllowed(bool allow); + void setVncPort(int newPort); + void shutDownVNC(); + void shutDownClient(); + /*bool gotFrame(){return _gotFrame;}; + void setFrame(bool gotFrame){_gotFrame = gotFrame;};*/ + ConnectionFrame* getConnectionFrame() + { + return _connectionFrame; + }; + void setConnectionFrame(ConnectionFrame* nFrame) + { + _connectionFrame = nFrame; + }; + void setFrame(Frame *f) + { + _vncFrame = f; + }; + Frame* getFrame() + { + return _vncFrame; + }; + VNCConnection* getVNCConnection() + { + return _vncConnection; + }; + PVSClientConnection* getPVSClientConnection() + { + return _pvsClientConnection; + }; + + // methods for/from PVSClientConnection + void onClientDisconnected(); + bool getLocked(); + bool sendMessage(PVSMsgType type, QString ident, QString message); + bool sendMessage(PVSMsg message); + + void setClientindex(int ind) { _clientIndex = ind; } + int getClientindex() { return _clientIndex; } + int getConnectionId() { return _pvsClientConnection->getID(); } + +private Q_SLOTS: + void vncFinished(); + +private: + + void vncProbe(); + Frame* _vncFrame; + VNCConnection* _vncConnection; + PVSClientConnection *_pvsClientConnection; + ConnectionFrame* _connectionFrame; + int _vncPort; + bool _gotFrame; + QString _hostString; + QString _hostName; + QString _userName; + QString _loginName; + QString _vncPassword; + QString _vncRwPassword; + int _clientIndex; + bool _vncAllowed, _vncRequested, _vncPasswordReceived, _vncRwPasswordReceived, _vncInitMutex, _vncProject; +}; + +#endif diff --git a/src/core/pvsConnectionManager.cpp b/src/core/pvsConnectionManager.cpp new file mode 100644 index 0000000..8a35ca9 --- /dev/null +++ b/src/core/pvsConnectionManager.cpp @@ -0,0 +1,483 @@ +/* +# Copyright (c) 2009 - OpenSLX Project, Computer Center University of Freiburg +# +# This program is free software distributed under the GPL version 2. +# See http://openslx.org/COPYING +# +# If you have any feedback please consult http://openslx.org/feedback and +# send your suggestions, praise, or complaints to feedback@openslx.org +# +# General information about OpenSLX can be found at http://openslx.org/ +# ----------------------------------------------------------------------------- +# src/core/pvsConnectionManager.cpp +# ----------------------------------------------------------------------------- +*/ + +#include "pvsConnectionManager.h" +#include "src/gui/mainWindow.h" +#include <QApplication> +#include "src/setup.h" +#include "src/util/CertManager.h" +#include "src/util/serviceDiscoveryUtil.h" + +PVSConnectionManager* PVSConnectionManager::singleCM; + + +PVSConnectionManager* PVSConnectionManager::getManager() +{ + if (!singleCM) + singleCM = new PVSConnectionManager(); + return singleCM; +} + +PVSConnectionManager::PVSConnectionManager() +{ + _busy = false; + _needPassword = false; + loadCommands(); + ConsoleLog writeLine(QString("Connection Manager created.")); + ConsoleLog writeChat("Log for chat is now running"); + + if (!(_pvsServer.startListen(SERVER_PORT_INT))) + ConsoleLog writeError(QString("Server listening failed!")); + setUpdateRate(500); + _sdBroadcaster.setFingerprint( + CertManager::getCertificate("manager").digest(QCryptographicHash::Sha1) + ); + _timerId = startTimer(1000); +} + +PVSConnectionManager::~PVSConnectionManager() +{ + killTimer(_timerId); +} + +void PVSConnectionManager::setUpdateRate(int newRate) +{ + // TODO: Iterate over list of clients and set the updateRate on each vncConnection + // Object. The timer does not influence the update rate of the thumbs, thus the code + // here was removed. +} + +void PVSConnectionManager::timerEvent(QTimerEvent *event) +{ + update(); +} + +void PVSConnectionManager::onClientNew(PVSClientConnection* newConnection) +{ + PVSClient* tmp = getClientFromConnection(newConnection); + if (tmp == NULL) + { + PVSClient* newCon = new PVSClient(newConnection); + _listClients.push_back(newCon); + sendEventToClients(QString("addedConnection"), newConnection, ""); + } + else + { + // already got that one... strange, eh? + } +} + +void PVSConnectionManager::onClientRemove(PVSClientConnection* removedConnection) +{ + PVSClient* tmp = getClientFromConnection(removedConnection); + if (tmp == NULL) return; + MainWindow::getWindow()->removeConnection(tmp); + removeConnection(tmp); + if(tmp->getUserName().length() > 0) + { + ConsoleLog writeChat(tmp->getUserName()+" has left the chat."); + sendEventToClients("removedClient", removedConnection , tmp->getUserName()+":"+tmp->getIp()); + } +} + +// Inform all chat clients about a new event. +void PVSConnectionManager::sendEventToClients(QString event, PVSClientConnection* connection, QString clientName) +{ + if(event.compare("addedConnection") == 0) + { + // send the client list to new Connection. + for (std::list<PVSClient*>::iterator it = _listClients.begin(); it != _listClients.end(); it++) + { + QString name = (**it).getUserName(); + QString ip = (**it).getIp(); + if (name.length() == 0) continue; + connection->push_back_send(PVSMsg(PVSMESSAGE, "clientToAdd", ":" + name + ":" + ip, 0)); + } + } + if(event.compare("addedClient") == 0) + { + // send name to everybody to all connected clients. + _pvsServer.sendToAll(PVSMsg(PVSMESSAGE, "clientToAdd", ":" + clientName, 0)); + connection->push_back_send(PVSMsg(PVSMESSAGE, "assignedName", ":" + clientName, 0)); + connection->push_back_send(PVSMsg(PVSMESSAGE, "clientToAdd", ":PVSMGR:local", 0)); + } + if(event.compare("removedClient") == 0) + { + // send name of removed client to connected clients. + _pvsServer.sendToAll(PVSMsg(PVSMESSAGE, "clientToRemove", ":"+ clientName, 0)); + } +} + +PVSClient* PVSConnectionManager::getClientFromConnection(PVSClientConnection* client) +{ + if (!_listClients.empty()) + { + + for (std::list<PVSClient*>::iterator it = _listClients.begin(); it != _listClients.end(); it++) + { + if ((*it)->getPVSClientConnection()) + { + if ((*it)->getPVSClientConnection() == client) + { + return (*it); + } + } + } + } + return NULL; +} + +PVSClient* PVSConnectionManager::getClientFromConnectionId(int id) +{ + if (_listClients.empty()) return NULL; + for (std::list<PVSClient*>::iterator it = _listClients.begin(); it != _listClients.end(); it++) + { + if ((*it)->getConnectionId() == id) return (*it); + } + return NULL; +} + +PVSClient* PVSConnectionManager::getClientFromVNCConnection(VNCConnection* client) +{ + if (!_listClients.empty()) + { + + for (std::list<PVSClient*>::iterator it = _listClients.begin(); it != _listClients.end(); it++) + { + if ((*it)->getVNCConnection()) + { + if ((*it)->getVNCConnection() == client) + { + return (*it); + } + } + } + } + return NULL; +} + +PVSClient* PVSConnectionManager::getClientFromIp(QString ip) +{ + if (!_listClients.empty()) + { + for (std::list<PVSClient*>::iterator it = _listClients.begin(); it != _listClients.end(); it++) + { + // ok, probably this could be handled better inside the PVSConnection itself + // but makeshift for now + if ((*it)->getPVSClientConnection()) + { + if ((*it)->getIp() == ip) + { + return (*it); + } + } + } + } + return NULL; +} + +void PVSConnectionManager::onCommand(PVSMsg command) +{ + QString message = command.getMessage(); + QString ident = command.getIdent(); + if (ident.compare("VNCSRVRESULT") == 0) + { + int e = string2Int(message); + QString id = int2String(command.getSndID()); + switch (e) + { + case 0: + ConsoleLog writeLine("[Client: " + id + ", VNCSRV] Server should be running"); + break; + case 1: + ConsoleLog writeError("[Client: " + id + ", VNCSRV] Server returned general error"); + break; + case 2: + ConsoleLog writeError("[Client: " + id + ", VNCSRV] ~/.pvs/vncpasswd not found"); + break; + case 3: + ConsoleLog writeError("[Client: " + id + ", VNCSRV] VNC-Script not found"); + break; + case 127: + ConsoleLog writeError("[Client: " + id + ", VNCSRV] command not found (vnc-server installed?)"); + break; + default: + ConsoleLog writeError("[Client: " + id + ", VNCSRV] unknown error"); + break; + } + } +} +void PVSConnectionManager::onChat(PVSMsg chatMsg) +{ + + QString nick_to = chatMsg.getIdent(); + int sndID = chatMsg.getSndID(); + PVSClientConnection* clientConnection = NULL; + PVSClient* client; + QStringList l = chatMsg.getMessage().split(":"); + QString nick_from = l[0]; + QString msg = chatMsg.getMessage().remove(0, l[0].size()+1); + + if (nick_to == "@all") // public message. + { + _pvsServer.sendToAll(chatMsg); + MainWindow::getWindow()->receiveChatMsg(nick_from, nick_to, msg);// get Msg on PVSMgr's Chat-GUI. + ConsoleLog writeChat(nick_from +" wrote '"+msg+"' in @all-Channel."); + } + else // private message. + { + if(nick_from == "PVSMGR") //Msg from Server + { + MainWindow::getWindow()->receiveChatMsg(nick_from, nick_to, msg); // get Msg on PVSMgr's Chat-GUI. + ConsoleLog writeChat(nick_from+" wrote '" + msg + "' to " + nick_to); // write the event to the chat log. + } + else + { + clientConnection = _pvsServer.getConnectionFromId(sndID); // become your own message. + if (clientConnection) + { + clientConnection->push_back_send(chatMsg); + } + else + { + ConsoleLog writeError("Got Chat Message from unknown ID"); + } + } + if(nick_to == "PVSMGR") //Msg to Server + { + MainWindow::getWindow()->receiveChatMsg(nick_from, nick_to, msg); // get Msg on PVSMgr's Chat-GUI. + ConsoleLog writeChat(nick_from+" wrote '" + msg + "' to " + nick_to);// write the event to the chat log. + } + else + { + client = getClientFromUsername(nick_to); // private receiver become the message. + if (client) + { + client->sendMessage(chatMsg); + ConsoleLog writeChat(nick_from+" wrote '" + msg + "' to " + nick_to);// write the event to the chat log. + } + else + { + ConsoleLog writeError("[CHAT] There is no client with username: " + nick_to); + } + } + + } +} + +PVSClient* PVSConnectionManager::getClientFromUsername(QString name) +{ + if (!(_listClients.empty())) + { + // Check for ping timeout + for (std::list<PVSClient*>::iterator it = _listClients.begin(); it!= _listClients.end(); it++) + { + PVSClient *client = *it; + if (client) + if (client->getUserName() == name) + return client; + } + } + return NULL; +} + +void PVSConnectionManager::onLoginPassword(PVSMsg command) +{ + if (!_needPassword) return; // No password required + if (_password == command.getMessage()) return; // No password set + PVSClient* tmp = getClientFromConnectionId(command.getSndID()); + tmp->sendMessage( + PVSMsg(PVSLOGIN, "FAILED", "Wrong password.") + ); + tmp->shutDownClient(); +} + +// Set usernamen and loginname a client. +void PVSConnectionManager::onLoginUsername(PVSMsg command) +{ + QStringList l = command.getMessage().split(","); + PVSClient* tmp = getClientFromConnectionId(command.getSndID()); + if (tmp->getUserName().length() > 0) return; + ConsoleLog writeError("(PVSConnectionManager::onUsername) was fired."); + if(l[0] == "PVSMGR") + { + l[0] = "fake_PVSMGR"; + } + int counter = 0; + QString uname = l[0]; + while (getClientFromUsername(uname) != NULL) + { + uname = l[0].append(QString::number(counter++, 16)); + } + if (tmp) + { + tmp->setUsername(uname); + tmp->setLoginName(l[1]); + MainWindow::getWindow()->addConnection(tmp); + ConsoleLog writeChat(tmp->getUserName()+" has joined the chat."); + sendEventToClients(QString("addedClient"), tmp->getPVSClientConnection(), tmp->getUserName() +":"+ tmp->getIp()); + } + else + ConsoleLog writeError("(PVSConnectionManager::onUsername) Couldnt find connection to user-id"); +} + +void PVSConnectionManager::onVncPassword(PVSMsg command) +{ + PVSClient* tmp = getClientFromConnectionId(command.getSndID()); + + if (tmp) + { + tmp->setVncPassword(command.getMessage()); + return; + } + else + ConsoleLog writeError("couldnt find matching connection to id!"); +} + +void PVSConnectionManager::onVncRwPassword(PVSMsg command) +{ + PVSClient* tmp = getClientFromConnectionId(command.getSndID()); + + if (tmp) + { + tmp->setVncRwPassword(command.getMessage()); + return; + } + else + ConsoleLog writeError("couldnt find matching connection to id!"); +} + +void PVSConnectionManager::onVncAllow(PVSMsg command) +{ + PVSClient* tmp = getClientFromConnectionId(command.getSndID()); + + if (tmp) + { + if (command.getMessage().compare("YES") == 0) + { + tmp->setAllowed(true); + return; + } + tmp->setAllowed(false); + } +} + +void PVSConnectionManager::onVncPort(PVSMsg command) +{ + PVSClient* tmp = getClientFromConnectionId(command.getSndID()); + if (tmp) + { + int port = string2Int(command.getMessage()); + if (port > 0) + tmp->setVncPort(port); + } + +} + +void PVSConnectionManager::onVncProjection(PVSMsg command) +{ + if (command.getMessage().compare(QString("YES")) == 0) + ConsoleLog writeLine("Client is watching.(connected via vnc)"); + if (command.getMessage().compare(QString("NO")) == 0) + ConsoleLog writeLine("Client failed to connect via vnc."); +} + +void PVSConnectionManager::removeConnection(PVSClient* newConnection) +{ + if (newConnection != NULL) + { + for (std::list<PVSClient*>::iterator it = _listClients.begin(); it != _listClients.end(); it++) + { + if (newConnection == (*it)) + { + // remove it from the list to keep this method from causing trouble when being called more than + // once in the process + _listClients.remove(newConnection); + + // it is important to tell the GUI that the vnc is gone (or ... will be) + // before we really shut it down, since the removal procedure of the + // frames shouldnt be messed with from here. + MainWindow::getWindow()->onConnectionRemoved(newConnection); // to kill vncConnection + + // now that the gui nows about it and does no longer call the vnc-stuff + newConnection->shutDownVNC(); + // and its gone... + + // clean up on the connection + newConnection->shutDownClient(); // just to be sure + newConnection->onClientDisconnected(); + + + newConnection->deleteLater(); + return; + } + } + } + else + { + // well, not our problem obviously + } +} + +bool PVSConnectionManager::update() +{ + if (_busy) return true; // already ongoing, so scrap that. + + _busy = true; // lock method + + if (!_listClients.empty()) + { + // now update the rest and check if they are alive + // otherwise mark dead connections + for (std::list<PVSClient*>::iterator it = _listClients.begin(); it != _listClients.end(); it++) + { + PVSClient* current = (*it); + current->tick(); + } + } + + //QApplication::processEvents(QEventLoop::AllEvents, 5); + + _busy = false; // we're done, so unlock + return true; +} + +void PVSConnectionManager::loadCommands() +{ + _pvsServer.addLoginHandler("USERNAME", this, &PVSConnectionManager::onLoginUsername); + _pvsServer.addLoginHandler("PASSWORD", this, &PVSConnectionManager::onLoginPassword); + _pvsServer.addCommandHandler("*", this, &PVSConnectionManager::onCommand); + _pvsServer.addCommandHandler("VNC", this, &PVSConnectionManager::onVncAllow); + _pvsServer.addCommandHandler("PORT", this, &PVSConnectionManager::onVncPort); + _pvsServer.addCommandHandler("PASSWORD", this, &PVSConnectionManager::onVncPassword); + _pvsServer.addCommandHandler("RWPASSWORD", this, &PVSConnectionManager::onVncRwPassword); + _pvsServer.addCommandHandler("PROJECTING", this, &PVSConnectionManager::onVncProjection); + _pvsServer.addChatHandler("*", this, &PVSConnectionManager::onChat); +} + +QString PVSConnectionManager::setNeedPassword(bool enabled) +{ + _needPassword = enabled; + if (enabled && _password.isEmpty()) + { + _password = QString::number(getRandom(1000, 9999), 10); + } + return _password; +} + +QString PVSConnectionManager::getSessionName() +{ + return sha1ToReadable(CertManager::getCertificate("manager").digest(QCryptographicHash::Sha1)); +} diff --git a/src/core/pvsConnectionManager.h b/src/core/pvsConnectionManager.h new file mode 100644 index 0000000..5f5fcca --- /dev/null +++ b/src/core/pvsConnectionManager.h @@ -0,0 +1,118 @@ +/** + * The PVSConnection Manager is the heart and core of the PVS. He creates, updates, delivers and deletes the connections. + * + */ + + + +// TODO: +// make it look good ;-) + + + +#include <QtGui> +#include <iostream> +#include <fstream> +#include <list> +#include <src/core/pvsClient.h> +#include <src/gui/mainWindow.h> +#include <src/core/pvsServer.h> +#ifndef _PVSCONNECTIONMANAGER_H_ +#define _PVSCONNECTIONMANAGER_H_ +#ifndef RFBCLIENT_H +extern "C" +{ +#include <rfb/rfbclient.h> +} +#endif + +#define PROFILE +#include <src/util/timeUtil.h> +#include <src/util/consoleLogger.h> +#include "src/net/pvsServiceBroadcast.h" + + + +class PVSConnectionManager; //forward declaration +class PVSClient; +class PVSListenSever; +class MainWindow; + +class PVSConnectionManager : public QObject +{ +public: + // singleton getter + static PVSConnectionManager* getManager(); + + ~PVSConnectionManager(); + + // PVSServer control/get/set methods + PVSServer* getServer() + { + return &_pvsServer; + }; + + // VNCConnection related static method + //static void onFBUpdate(rfbClient* client, int x, int y, int w, int h); + + + // gui update frequency + void setUpdateRate(int newRate); + + + // PVSConnection control/get/set methods + std::list<PVSClient*> getConnections() + { + return _listClients; + }; + void onClientNew(PVSClientConnection* newConnection); // called by the server when a new client connects + void onClientRemove(PVSClientConnection* removedConnection); // called by the server when a new client disconnects (on its own) + PVSClient* getClientFromConnection(PVSClientConnection* client); + PVSClient* getClientFromConnectionId(int id); + PVSClient* getClientFromVNCConnection(VNCConnection* client); + PVSClient* getClientFromIp(QString ip); // returns connection with hostname 'host' + PVSClient* getClientFromUsername(QString name); // returns connection with username 'name' + // these methods are called by the PVSServer which forwards the command/etc handling to the CM + void onCommand(PVSMsg command); + void onChat(PVSMsg chatMsg); + void onVncPassword(PVSMsg command); + void onVncRwPassword(PVSMsg command); + void onLoginUsername(PVSMsg command); + void onLoginPassword(PVSMsg command); + void onVncAllow(PVSMsg command); + void onVncPort(PVSMsg command); + void onVncProjection(PVSMsg command); + + void sendEventToClients(QString event, PVSClientConnection* newConnection, QString newClientName); // informs every connected clients about a new client or a removed client. + + void removeConnection(PVSClient* removedConnection); // removes and deletes the connection !DOES NOT DISCONNECT DIRECTLY! + PVSClient* getNewConnection(VNCConnectInfo* newConInfo); // returns a new connection object based on the VNCConnectInfo or NULL + + bool isBusy() { return _busy; } + + QString setNeedPassword(bool enabled); + QString getSessionName(); + +protected: + void timerEvent(QTimerEvent *event); + +private: + // C'Tor + PVSConnectionManager(); // private due to singleton pattern + // internal control methods + bool update(); // does the update and cleaning routines and makes sure the framebuffers in the connection objects are up to date + void loadCommands(); + + // Member + std::list<PVSClient*> _listClients; // list of all verified clients + PVSServer _pvsServer; // the server that handles the pvsConnections + static PVSConnectionManager* singleCM; // the CM itself + bool _busy; // to keep timed calls from starting another update before the old one is thru. + PVSServiceBroadcast _sdBroadcaster; ///< Service discovery handling + + QString _password; ///< Password required to connect (can be empty) + bool _needPassword; + int _timerId; +}; + +#endif diff --git a/src/core/pvsServer.cpp b/src/core/pvsServer.cpp new file mode 100644 index 0000000..916ad89 --- /dev/null +++ b/src/core/pvsServer.cpp @@ -0,0 +1,22 @@ +#include "pvsConnectionManager.h" +#undef Q_FOREACH +#include "pvsServer.h" + + +PVSServer::PVSServer(int port) + :PVSListenServer(port,0) +{ +} + + +void PVSServer::onClientConnected(PVSClientConnection* connected) +{ + PVSListenServer::onClientConnected(connected); + PVSConnectionManager::getManager()->onClientNew(connected); +} +void PVSServer::onClientDisconnected(PVSClientConnection* disconnected) +{ + PVSConnectionManager::getManager()->onClientRemove(disconnected); + PVSListenServer::onClientDisconnected(disconnected); +} + diff --git a/src/core/pvsServer.h b/src/core/pvsServer.h new file mode 100644 index 0000000..acd9c61 --- /dev/null +++ b/src/core/pvsServer.h @@ -0,0 +1,24 @@ +/** + * A derivate of PVSListenServer and used by the PVSConnectionManager to handle incoming connections + * which then return pointers to their PVSClientConnections to the manager to handle + * in and outgoing messsages/commands + * + */ + + + +#include <src/net/pvsListenServer.h> + +#ifndef _PVSSERVER_H_ +#define _PVSSERVER_H_ + +class PVSServer : public PVSListenServer +{ +public: + PVSServer(int port = 0); +private: + virtual void onClientConnected(PVSClientConnection* connected); + virtual void onClientDisconnected(PVSClientConnection* disconnected); +}; + +#endif diff --git a/src/core/vncConnection.cpp b/src/core/vncConnection.cpp new file mode 100644 index 0000000..1864e77 --- /dev/null +++ b/src/core/vncConnection.cpp @@ -0,0 +1,261 @@ +/* +# Copyright (c) 2009 - OpenSLX Project, Computer Center University of Freiburg +# +# This program is free software distributed under the GPL version 2. +# See http://openslx.org/COPYING +# +# If you have any feedback please consult http://openslx.org/feedback and +# send your suggestions, praise, or complaints to feedback@openslx.org +# +# General information about OpenSLX can be found at http://openslx.org/ +# ----------------------------------------------------------------------------- +# src/core/vncConnection.cpp +# ----------------------------------------------------------------------------- +*/ + + +#include "vncConnection.h" +#include <iostream> +#include <src/core/pvsConnectionManager.h> +#include <src/core/pvsClient.h> +#include <src/gui/connectionFrame.h> + + +//***********************************************************************************// +// VNCConnection // +//***********************************************************************************// + + + +VNCConnection::VNCConnection(QString newPass) +{ + thread = NULL; + pwSet = false; + if (newPass != "") + { + password = newPass; + pwSet = true; + } + else + password = ""; + first = true; + view_only = true; + locked = false; + myFrame = NULL; +} + +VNCConnection::~VNCConnection() +{ + setDead(); +} + +bool VNCConnection::initClient(VNCConnectInfo* newConInfo) +{ + int argc = newConInfo->getCount(); + char** argv = newConInfo->getArguments(); + + if (argc > 0) + { + + stringHost = QString(argv[0]); + + /*QString cropHost = colonSplitter(stringHost, true); + QString cropPort = colonSplitter(stringHost, false);*/ + _host = colonSplitter(stringHost, true); + _port = colonSplitter(stringHost, false); + /*if (!(cropHost.size())) + cropHost = stringHost; + if (!(cropPort.size())) + _port = 5900; + password = newConInfo->getPassword(); + _host = cropHost; + thread = new VNCClientThread(_host, 5900, password , 0, 500);*/ + if (!(_host.size())) + _host = stringHost; + if (!(_port.size())) + _port = QString("5900"); + thread = new VNCClientThread(_host, string2Int(_port), newConInfo->getPassword(), 0, 500); + connect(thread, SIGNAL(finished()), this, SIGNAL(finished())); + + return true; + } + + rfbClientLog("init failed\n"); + emit finished(); + return false; +} + +/* + * disconnect and terminate the current connection and set a new one. + */ +void VNCConnection::reInitClientWithQuality(int quality) +{ + disconnect(thread, SIGNAL(finished()), this, SIGNAL(finished())); + thread->terminate = true; + thread = new VNCClientThread(_host, string2Int(_port), password , quality, 500); + connect(thread, SIGNAL(finished()), this, SIGNAL(finished())); +} + +bool VNCConnection::isOK() +{ + return thread != NULL && thread->isRunning(); +} + +bool VNCConnection::viewOnly() +{ + return view_only; +} + +void VNCConnection::setDead() +{ + if (thread != NULL) + { + disconnect(thread, SIGNAL(finished()), this, SIGNAL(finished())); + if (thread->isRunning()) + { + thread->terminate = true; + thread->wait(2000); + } + delete thread; + thread = NULL; + } +} + +void VNCConnection::clear() +{ + setDead(); + + if (myFrame) + { + myFrame = NULL; + } +} + +void VNCConnection::setFrame(ConnectionFrame* newFrame) +{ + if (newFrame) + { + if (myFrame) + { + // TODO: Tell it that we left? + } + myFrame = newFrame; + if (thread != NULL) myFrame->setToolTip(thread->getDesktopName()); + myFrame->setRatio(ratio); + myFrame->setOversized(overSized); + } +} + +ConnectionFrame* VNCConnection::getFrame() +{ + return myFrame; +} + +char* VNCConnection::getPassword(rfbClient* myClient) +{ + // better off somewhere else? + + QString tmpPassword; + QString serverHost(myClient->serverHost); + QString cropHost = colonSplitter(serverHost, true); + if (!(cropHost.size())) + cropHost = serverHost; + if (PVSClient* selfConnection = PVSConnectionManager::getManager()->getClientFromIp(cropHost)) // no candidate means false call anyway + { + tmpPassword = selfConnection->getPassword(); + } + else + { + tmpPassword = ""; + ConsoleLog writeError("Couldn't find a matching connection to retrieve a password from!"); + } + if (tmpPassword.length() > 8) // shorten if pw is too long + { + std::cout << "VNCConnection::getPassword() given password too long, cutting it down to 8 chars!" << std::endl; + tmpPassword = tmpPassword.mid(0,8); + } + + + char* pw = new char[9]; + strcpy(pw, tmpPassword.toUtf8().data()); + return pw; +} + +QString VNCConnection::getPassword() +{ + return password; +} + +bool VNCConnection::getPWSet() +{ + return pwSet; +} + +QString VNCConnection::getDesktopName() +{ + if (_desktopName.isNull() && thread != NULL && thread->isRunning()) _desktopName = thread->getDesktopName(); + return _desktopName; +} + +VNCClientThread* VNCConnection::getVNCClientThread() +{ + if (thread) + return thread; + return NULL; +} + + + +//***********************************************************************************// +// VNCConnectInfo // +//***********************************************************************************// + + + +VNCConnectInfo::VNCConnectInfo() +{ + count = 0; + arguments = NULL; + password = ""; + passwordSupplied = false; +} + +VNCConnectInfo::VNCConnectInfo(int newCount, char** newArgs, QString pass) +{ + if (pass == "") + setArguments(newCount, newArgs); + else + setArguments(newCount, newArgs, pass); +} + +VNCConnectInfo::~VNCConnectInfo() +{ + if (arguments) + delete[] arguments; +} + +void VNCConnectInfo::setArguments(int newCount, char** newArgs, QString pass) +{ + count = newCount; + arguments = newArgs; + if (pass != "") + { + password = pass; + passwordSupplied = true; + } +} + +int VNCConnectInfo::getCount() +{ + return count; +} + +char** VNCConnectInfo::getArguments() +{ + return arguments; +} + +QString VNCConnectInfo::getPassword() +{ + return password; +} diff --git a/src/core/vncConnection.h b/src/core/vncConnection.h new file mode 100644 index 0000000..6893135 --- /dev/null +++ b/src/core/vncConnection.h @@ -0,0 +1,99 @@ +/** + * + * VNCConnection + * + * The VNCConnection and the VNCConnectInfo are the Classes containing the information about the vnc-connections. + * While the VNCConnectInfo just holds the information about the token and password / parameters given on + * create time of a new connection, the connection itself contains the C-Object from the vnc library and is + * maintained by the PVSConnectionManger. + */ + + +#ifndef _VNCCONNECTION_H_ +#define _VNCCONNECTION_H_ +extern "C" +{ +#include <rfb/rfbclient.h> +} + +#include <QtGui> +#include "../util/vncClientThread.h" +#include <src/gui/connectionFrame.h> +#include <iostream> +#include <QtCore/QObject> + +#define PROFILE +#include <src/util/timeUtil.h> + + +class VNCConnection; // forward declaration +class ConnectionFrame; +class PVSConnectionManager; +class VNCConnectInfo +{ + //Q_OBJECT +public: + VNCConnectInfo(); //Constructor + VNCConnectInfo(int newCount, char** newArgs, QString pass = ""); // Constructor with instant information feed + ~VNCConnectInfo(); + void setArguments(int newCount, char** newArgs, QString pass = ""); // (re)feed of information + int getCount(); // returns count + bool pwSet() + { + return passwordSupplied; + }; // returns wether a password was set or not + char ** getArguments(); // returns pointer to an array of char arrays holding the given arguments + QString getPassword(); // returns (if given) the password + +private: + char** arguments; + bool passwordSupplied; + QString password; + int count; +}; + +class VNCConnection : public QObject +{ + Q_OBJECT +public: + VNCConnection(QString newPass = ""); // Constructor + ~VNCConnection(); + bool initClient(VNCConnectInfo* newConInfo); // initiates the connection based on the information given with the VNCConnectInfo object + void reInitClientWithQuality(int quality); + bool isOK(); // returns true if not dead, false otherwise + bool viewOnly(); + void setDead(); // marks the connection for removal + void clear(); // does internal cleanup + void setFrame(ConnectionFrame* newFrame); // sets the given frame as its own + ConnectionFrame* getFrame(); // if present, returns the frame + static char* getPassword(rfbClient* client); // is called if a rfbclient-object asks for a password and starts the upward chain to ask for a password + QString getPassword(); // bad overload, since it returns the stored password (if any was given) + QString getHost() + { + return _host; + } + bool getPWSet(); // returns true if a password was given, false otherwise + //Glib::RefPtr<Gdk::Pixbuf> getBuffer(); + bool getBusy() { return busy; } + QString getDesktopName(); + VNCClientThread* getVNCClientThread(); + +Q_SIGNALS: + void finished(); + +private: + VNCClientThread *thread; + ConnectionFrame* myFrame; + QImage img; + QString password, stringHost, _host, _port; + bool pwSet; + bool first; + bool view_only; + bool overSized; + float ratio; + bool busy; + bool locked; + QString _desktopName; +}; + +#endif |