summaryrefslogblamecommitdiffstats
path: root/src/client/net/serverconnection.h
blob: f434f0b5d6e6b4a75ae050b9d41f6d0f668b3438 (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, quint16 port, const QByteArray& sessionName, const QByteArray& certHash, bool autoConnect);
	void disconnectFromServer();
	~ServerConnection() override;
	inline bool isConnected() const
	{
		return _socket != nullptr && _socket->state() == QAbstractSocket::ConnectedState;
	}

	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) override;

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, const QString &ropass, const QString &rwpass); // triggered if the local vnc server was started

public slots:
	void onVncViewerStartStop(bool started, 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