IMThread
::IMThread(int socketDescriptor,
QObject *parent
) : QThread(parent
), socketDescriptor
(socketDescriptor
) {
qRegisterMetaType<QAbstractSocket::SocketState>();
qRegisterMetaType<QSslSocket::SslMode>();
}
IMThread::~IMThread()
{
}
void IMThread::run()
{
// Convert the socket to an SSL one
serverSocket = new QSslSocket();
serverSocket->ignoreSslErrors();
connect( serverSocket, SIGNAL(readyRead()), this, SLOT(readyRead()) );
connect( serverSocket, SIGNAL(encrypted()), this, SLOT(encrypted()) );
connect( serverSocket, SIGNAL(modeChanged(QSslSocket::SslMode)), this, SLOT(sslModeChanged(QSslSocket::SslMode)) );
connect( serverSocket, SIGNAL(sslErrors(const QList<QSslError>&)), this, SLOT(sslErrors(const QList<QSslError>&)) );
connect( serverSocket, SIGNAL(disconnected()), this, SLOT(disconnected()) );
connect( serverSocket, SIGNAL(connected()), this, SLOT(connected()) );
QSslCertificate myCert = QSslCertificate( "mycert.pem" );
qDebug("Null Cert: %i Valid: %i", myCert.isNull(), myCert.isValid() );
QSslKey myKey = QSslKey( "mykey.pem", QSsl::Rsa );
qDebug("Null Key: %i", myKey.isNull() );
serverSocket->setLocalCertificate( myCert );
serverSocket->setPrivateKey( myKey );
if (serverSocket->setSocketDescriptor(socketDescriptor)) {
serverSocket->startServerEncryption();
}
else {
delete serverSocket;
}
qDebug("State: %i Mode: %i Crypt: %i", serverSocket->state(), serverSocket->mode(), serverSocket->isEncrypted() );
}
IMThread::IMThread(int socketDescriptor, QObject *parent)
: QThread(parent), socketDescriptor(socketDescriptor)
{
qRegisterMetaType<QAbstractSocket::SocketState>();
qRegisterMetaType<QSslSocket::SslMode>();
}
IMThread::~IMThread()
{
}
void IMThread::run()
{
// Convert the socket to an SSL one
serverSocket = new QSslSocket();
serverSocket->ignoreSslErrors();
connect( serverSocket, SIGNAL(readyRead()), this, SLOT(readyRead()) );
connect( serverSocket, SIGNAL(encrypted()), this, SLOT(encrypted()) );
connect( serverSocket, SIGNAL(modeChanged(QSslSocket::SslMode)), this, SLOT(sslModeChanged(QSslSocket::SslMode)) );
connect( serverSocket, SIGNAL(sslErrors(const QList<QSslError>&)), this, SLOT(sslErrors(const QList<QSslError>&)) );
connect( serverSocket, SIGNAL(disconnected()), this, SLOT(disconnected()) );
connect( serverSocket, SIGNAL(connected()), this, SLOT(connected()) );
connect( serverSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(error(QAbstractSocket::SocketError)) );
connect( serverSocket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), this, SLOT(stateChanged(QAbstractSocket::SocketState)) );
QSslCertificate myCert = QSslCertificate( "mycert.pem" );
qDebug("Null Cert: %i Valid: %i", myCert.isNull(), myCert.isValid() );
QSslKey myKey = QSslKey( "mykey.pem", QSsl::Rsa );
qDebug("Null Key: %i", myKey.isNull() );
serverSocket->setLocalCertificate( myCert );
serverSocket->setPrivateKey( myKey );
if (serverSocket->setSocketDescriptor(socketDescriptor)) {
serverSocket->startServerEncryption();
}
else {
delete serverSocket;
}
qDebug("State: %i Mode: %i Crypt: %i", serverSocket->state(), serverSocket->mode(), serverSocket->isEncrypted() );
}
To copy to clipboard, switch view to plain text mode
Bookmarks