sslclient.h:
/****************************************************************************
**
** Copyright (C) 2003-2006 Trolltech ASA. All rights reserved.
**
** This file is part of a Qt Solutions component.
**
** Licensees holding valid Qt Solutions licenses may use this file in
** accordance with the Qt Solutions License Agreement provided with the
** Software.
**
** See http://www.trolltech.com/products/qt/addon/solutions/
** or email sales@trolltech.com for information about Qt Solutions
** License Agreements.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
****************************************************************************/
#ifndef SSLCLIENT_H
#define SSLCLIENT_H
#include <qwidget.h>
#include <qtsslsocket.h>
class QPushButton;
class QTextEdit;
class QLabel;
class QLineEdit;
class QtSslSocket;
class QSocket;
class SSLClient : public QWidget
{
Q_OBJECT
public:
SSLClient(QWidget *parent = 0);
QSize sizeHint() const;
private slots:
void doConnect();
void readData();
void sendData();
void connectionClosed();
void error(QAbstractSocket::SocketError err);
void connectToHost(const QString &host, int port);
void connectedToHost();
void checkCertError(QtSslSocket::VerifyResult, bool, const QString &str);
private:
QString host;
int port;
QPushButton *quitButton;
QTextEdit *terminal;
QLabel *statusLabel;
QLineEdit *userInput;
//QtSslSocket *sslsocket;
QtSslSocket *socket;
};
#endif
--------------------------------------------------------------------------------
sslclient.cpp:
/****************************************************************************
**
** Copyright (C) 2003-2006 Trolltech ASA. All rights reserved.
**
** This file is part of a Qt Solutions component.
**
** Licensees holding valid Qt Solutions licenses may use this file in
** accordance with the Qt Solutions License Agreement provided with the
** Software.
**
** See http://www.trolltech.com/products/qt/addon/solutions/
** or email sales@trolltech.com for information about Qt Solutions
** License Agreements.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
****************************************************************************/
#include <qtsslsocket.h>
#include <qdialog.h>
#include <qlabel.h>
#include <qlayout.h>
#include <qlineedit.h>
#include <qmap.h>
#include <qmessagebox.h>
#include <qpushbutton.h>
#include <qregexp.h>
#include <qtabwidget.h>
#include <qtextedit.h>
#include <qtimer.h>
#include <qtextcursor.h>
#include <qscrollbar.h>
#include "sslclient.h"
/*
A simple SSL client example.
This example demostrates the use of QtSslSocket in a client
application. The application connects to an SSL service on any
given host and port. If the connection succeeds, the user is given
a line edit for entering commands, and a text edit which displays
the response from the server.
Try this example by connection to your IMAP4 or POP3 server.
Chances are that these services are running SSL. The SSL service
IMAP4 runs on port 993, and POP3 is on port 995.
When communicating with an IMAP4 server, the command "X LOGOUT"
will close the connection. With POP3, use the command "QUIT".
*/
/*
This class provides a QDialog popup that is shown by SSLClient. It
has line edits for hostname and port number.
*/
class ConnectionDialog : public QDialog
{
Q_OBJECT
public:
ConnectionDialog(QWidget *parent = 0);
QString host() const;
int port() const;
private slots:
void abortDialog();
void checkInputAndConnect();
private:
QLineEdit *hl;
QLineEdit *pl;
QPushButton *conn;
QPushButton *abrt;
};
/*!
Constructs a ConnectionDialog, which is the initial dialog
that pops up when the user starts this program.
Its /a parent and /a name arguments are passed to QDialog's
constructor.
*/
ConnectionDialog::ConnectionDialog(QWidget *parent)
: QDialog(parent)
{
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Maximum);
setWindowTitle(tr("Connect to host"));
QGridLayout *layout = new QGridLayout(this);
// Create two labels
layout->addWidget(new QLabel(tr("Hostname"), this), 0, 1);
layout->addWidget(new QLabel(tr("Port"), this), 1, 1);
// Create the hostname and port line edits. Find an appropriate
// input mask for the port input.
hl = new QLineEdit(this);
pl = new QLineEdit(this);
pl->setInputMask("99999");
layout->addWidget(hl, 0, 2);
layout->addWidget(pl, 1, 2);
// Add two buttons: "Abort" and "Connect"
abrt = new QPushButton(tr("&Abort"), this);
conn = new QPushButton(tr("&Connect"), this);
conn->setDefault(true);
layout->addWidget(abrt, 2, 1);
layout->addWidget(conn, 2, 2);
connect(abrt, SIGNAL(clicked()), SLOT(abortDialog()));
connect(conn, SIGNAL(clicked()), SLOT(checkInputAndConnect()));
}
/*!
Checks that the hostname and port line edi