30
|
1 |
/*
|
|
2 |
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description: Secure connections test application
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include "tlsconnectionapp.h"
|
|
19 |
#include "tlsconnection.h"
|
|
20 |
#include <hbmainwindow.h>
|
|
21 |
#include <hbview.h>
|
|
22 |
#include <QDebug>
|
|
23 |
#include <QGraphicsLinearLayout>
|
|
24 |
#include <hbcombobox.h>
|
|
25 |
#include <hblineedit.h>
|
|
26 |
#include <hblabel.h>
|
|
27 |
#include <hbpushbutton.h>
|
|
28 |
#include <hbmessagebox.h>
|
|
29 |
|
|
30 |
|
|
31 |
TlsConnectionApplication::TlsConnectionApplication(int& aArgc, char* aArgv[])
|
|
32 |
: HbApplication(aArgc, aArgv), mMainWindow(0), mMainView(0), mHost(0),
|
|
33 |
mPort(0), mOpeningDelay(0), mStatusLabel(0), mConnection(0)
|
|
34 |
{
|
|
35 |
qDebug() << "TLStest TlsConnectionApplication begin";
|
|
36 |
|
|
37 |
mMainWindow = new HbMainWindow();
|
|
38 |
mMainView = new HbView();
|
|
39 |
mMainView->setTitle(tr("TLS Test"));
|
|
40 |
|
|
41 |
QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(Qt::Vertical);
|
|
42 |
|
|
43 |
mHost = new HbComboBox;
|
|
44 |
QStringList defaultHosts;
|
|
45 |
defaultHosts << "www.nokia.com"
|
|
46 |
<< "www.f-secure.com"
|
|
47 |
<< "www.google.fi"
|
|
48 |
<< "www.tut.fi";
|
|
49 |
mHost->addItems(defaultHosts);
|
|
50 |
connect(mHost, SIGNAL(editingFinished()), this, SLOT(addHostName()));
|
|
51 |
mHost->setEditable(true);
|
|
52 |
layout->addItem(mHost);
|
|
53 |
|
|
54 |
mPort = new HbLineEdit(tr("Port?"));
|
|
55 |
mPort->setText(tr("443"));
|
|
56 |
layout->addItem(mPort);
|
|
57 |
|
|
58 |
mOpeningDelay = new HbLineEdit(tr("Opening delay?"));
|
|
59 |
mOpeningDelay->setText(tr("0"));
|
|
60 |
layout->addItem(mOpeningDelay);
|
|
61 |
|
|
62 |
mStatusLabel = new HbLabel(tr("Inactive"));
|
|
63 |
layout->addItem(mStatusLabel);
|
|
64 |
|
|
65 |
HbPushButton *activateButton = new HbPushButton(tr("Run Test"));
|
|
66 |
connect(activateButton, SIGNAL(clicked()), this, SLOT(runTestPressed()));
|
|
67 |
layout->addItem(activateButton);
|
|
68 |
|
|
69 |
HbPushButton *closeButton = new HbPushButton("Close");
|
|
70 |
connect(closeButton, SIGNAL(clicked()), qApp, SLOT(quit()));
|
|
71 |
layout->addItem(closeButton);
|
|
72 |
|
|
73 |
mMainView->setLayout(layout);
|
|
74 |
mMainWindow->addView(mMainView);
|
|
75 |
mMainWindow->show();
|
|
76 |
|
|
77 |
qDebug() << "TLStest TlsConnectionApplication end";
|
|
78 |
}
|
|
79 |
|
|
80 |
TlsConnectionApplication::~TlsConnectionApplication()
|
|
81 |
{
|
|
82 |
qDebug() << "TLStest ~TlsConnectionApplication begin";
|
|
83 |
|
|
84 |
delete mConnection;
|
|
85 |
delete mMainView;
|
|
86 |
delete mMainWindow;
|
|
87 |
|
|
88 |
qDebug() << "TLStest ~TlsConnectionApplication end";
|
|
89 |
}
|
|
90 |
|
|
91 |
void TlsConnectionApplication::HandleNetworkEvent( TTlsConnectionState aEvent, TInt aError )
|
|
92 |
{
|
|
93 |
switch( aEvent ) {
|
|
94 |
case ENotInitialized:
|
|
95 |
showProgress( tr("NotInitialized"), aError );
|
|
96 |
break;
|
|
97 |
case EDisconnected:
|
|
98 |
showProgress( tr("Disconnected"), aError );
|
|
99 |
break;
|
|
100 |
case EIdle:
|
|
101 |
showProgress( tr("Idle"), aError );
|
|
102 |
break;
|
|
103 |
case EConnectingNetwork:
|
|
104 |
showProgress( tr("ConnectingNetwork"), aError );
|
|
105 |
break;
|
|
106 |
case EOpeningDelay:
|
|
107 |
showProgress( tr("OpeningDelay"), aError );
|
|
108 |
break;
|
|
109 |
case EResolvingHostName:
|
|
110 |
showProgress( tr("ResolvingHostName"), aError );
|
|
111 |
break;
|
|
112 |
case EConnectingServer:
|
|
113 |
showProgress( tr("ConnectingServer"), aError );
|
|
114 |
break;
|
|
115 |
case EHandshaking:
|
|
116 |
showProgress( tr("Handshaking"), aError );
|
|
117 |
break;
|
|
118 |
case EConnecting:
|
|
119 |
showProgress( tr("Connecting"), aError );
|
|
120 |
break;
|
|
121 |
case ESending:
|
|
122 |
showProgress( tr("Sending"), aError );
|
|
123 |
break;
|
|
124 |
case EReading:
|
|
125 |
showProgress( tr("Reading"), aError );
|
|
126 |
break;
|
|
127 |
case EAllDone:
|
|
128 |
showProgress( tr("AllDone"), aError );
|
|
129 |
break;
|
|
130 |
default:
|
|
131 |
showProgress( tr("unknown"), aError );
|
|
132 |
break;
|
|
133 |
}
|
|
134 |
}
|
|
135 |
|
|
136 |
void TlsConnectionApplication::HandleTransferData( const TDesC8& /*aData*/, TInt aLength )
|
|
137 |
{
|
|
138 |
qDebug() << "TLStest HandleTransferData, length:" << aLength;
|
|
139 |
}
|
|
140 |
|
|
141 |
void TlsConnectionApplication::runTestPressed()
|
|
142 |
{
|
|
143 |
qDebug() << "TLStest runTestPressed begin";
|
|
144 |
|
|
145 |
if (mConnection) {
|
|
146 |
delete mConnection;
|
|
147 |
mConnection = NULL;
|
|
148 |
}
|
|
149 |
|
|
150 |
TPtrC host( reinterpret_cast<const TText*>( mHost->currentText().constData() ));
|
|
151 |
TInt port = getInt(mPort->text(), 443);
|
|
152 |
TInt delay = getInt(mOpeningDelay->text(), 0);
|
|
153 |
qDebug() << "TLStest runTestPressed host:" << mHost->currentText() << "port" << port << "delay" << delay;
|
|
154 |
TRAPD( err, mConnection = CTlsConnection::NewL( *this ) );
|
|
155 |
qDebug() << "TLStest runTestPressed err:" << err;
|
|
156 |
if( !err ) {
|
|
157 |
qDebug() << "TLStest runTestPressed CTlsConnection created, connecting";
|
|
158 |
TRAP( err, mConnection->ConnectL( host, port, delay ) );
|
|
159 |
qDebug() << "TLStest runTestPressed err:" << err;
|
|
160 |
}
|
|
161 |
|
|
162 |
qDebug() << "TLStest runTestPressed end";
|
|
163 |
}
|
|
164 |
|
|
165 |
void TlsConnectionApplication::addHostName()
|
|
166 |
{
|
|
167 |
QString newHostName = mHost->currentText();
|
|
168 |
mHost->addItem(newHostName);
|
|
169 |
}
|
|
170 |
|
|
171 |
void TlsConnectionApplication::showProgress(const QString& aStep, int aError)
|
|
172 |
{
|
|
173 |
qDebug() << "TLStest showProgress step" << aStep << "error" << aError;
|
|
174 |
if (mStatusLabel) {
|
|
175 |
if (!aError) {
|
|
176 |
mStatusLabel->setPlainText(aStep);
|
|
177 |
} else {
|
|
178 |
QString msg(aStep);
|
|
179 |
msg.append(tr(" error %1").arg(aError));
|
|
180 |
mStatusLabel->setPlainText(msg);
|
|
181 |
}
|
|
182 |
}
|
|
183 |
}
|
|
184 |
|
|
185 |
TInt TlsConnectionApplication::getInt(const QString& aString, int defaultValue)
|
|
186 |
{
|
|
187 |
qDebug() << "TLStest getInt" << aString << "defaultValue" << defaultValue;
|
|
188 |
|
|
189 |
bool ok = false;
|
|
190 |
TInt value = aString.toInt(&ok, 10);
|
|
191 |
if (!ok) {
|
|
192 |
value = defaultValue;
|
|
193 |
}
|
|
194 |
|
|
195 |
qDebug() << "TLStest getInt returns " << value;
|
|
196 |
return value;
|
|
197 |
}
|