summaryrefslogblamecommitdiffstats
path: root/src/client/net/serverconnection.h
blob: 9db9b0298a91d60fa1f5fd812e2d420e8f62ce70 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11










                                           
                



                            
                                                          

                         
                          
                               
                         









                                              

                                    
       
                                                                                                                                               

                                    
                                       



                                                                                              



                                                         







                                               
                                                  
                                    















                                                                                                                               
                                                                                                                                                                             

                                                               
                                                        
                                          


      
#ifndef _PVSSERVERCONNECTION_H_
#define _PVSSERVERCONNECTION_H_

#include <QSslSocket>
#include "../../shared/networkmessage.h"
#include "../connectwindow/connectwindow.h"

class BlankScreen;

class ServerConnection : public QObject
{
	Q_OBJECT

private:
	QSslSocket *_socket;
	BlankScreen *_blank;
	int _timerId, _timerDelete, _timerConnectionCheck;
	int _jpegQuality;
	int _authed;
	bool _autoConnect;
	int _isLocalConnection;
	qint64 _lastData;

	NetworkMessage _fromServer, _toServer;
	QByteArray _expectedFingerprint;
	QString _passwd;
	QByteArray _myChallenge;
	QByteArray _sessionName;
	QByteArray _certHash;

	void handleMsg();

	void checkLocalConnection();

public:
	ServerConnection(const QString& host, const quint16 port, const QByteArray& sessionName, const QByteArray& certHash, bool autoConnect);
	void disconnectFromServer();
	~ServerConnection();
	inline bool isConnected() const
	{
		return _socket != NULL && _socket->state() == QAbstractSocket::ConnectedState;
	}

	const inline QString getPeerAdress() const
	{
		return _socket->peerAddress().toString();
	}

	bool isLocalConnection() {
		if (_isLocalConnection == -1) {
			checkLocalConnection();
		}
		return _isLocalConnection == 1;
	}

	void sendMessage(NetworkMessage& message);
	void sendAttention(bool on);

protected:
	void timerEvent(QTimerEvent *event);

private slots:
	void sslErrors(const QList<QSslError> & errors); // triggered for errors that occur during SSL negotiation
	void sock_dataArrival(); // triggered if data is available for reading
	void sock_closed(); // triggered if the socket is closed
	void sock_error(QAbstractSocket::SocketError errcode); // triggered if an error occurs on the socket
	void sock_connected(); // triggered if the connection is established and ready to use

	void onVncServerStartStop(int port, QString& ropass, QString& rwpass); // triggered if the local vnc server was started

	void onVncViewerStartStop(const bool started, const int clientId);

signals:
	void openVnc(const QString& host, int port, const QString& passwd, bool ro, bool fullscreen, const QString& caption, const int clientId, const QByteArray& rawThumb);
	void closeVnc();
	void stateChange(ConnectWindow::ConnectionState state);
	void disconnected(ServerConnection* connection);
	void attentionChanged(bool state);
};

#endif