/*
    Copyright (C) 2010 Eduardo Robles Elvira

    This program 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 3 of the License, or
    (at your option) any later version.

    This program 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 program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef SECURESERVER_H
#define SECURESERVER_H

#include <QtNetwork/QTcpServer>
#include <QtNetwork/QSslSocket>
#include <QtCore/QThread>

class QSslError;

class SecureServer : public QTcpServer
{
    Q_OBJECT
public:
    SecureServer();
    virtual ~SecureServer();

protected:
    virtual void incomingConnection( int socketDescriptor );

};

class SecureServerConnectionThread : public QThread
{
    Q_OBJECT
public:
    SecureServerConnectionThread(int socketDescriptor, SecureServer *parent);
    void run();

private:
    int m_socketDescriptor;
};

class SecureServerConnection : public QSslSocket
{
    Q_OBJECT
public:
    SecureServerConnection(int socketDescriptor, QObject* parent);
    virtual ~SecureServerConnection();

private Q_SLOTS:
    void readyRead();
    void encrypted();
    void sslModeChanged(QSslSocket::SslMode sslMode);
    void sslErrors(const QList<QSslError>& errorList);
    void disconnected();
    void connected();
    void error(QAbstractSocket::SocketError socketError);
    void stateChanged( QAbstractSocket::SocketState socketState);
};

#endif // SECURESERVER_H
