[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdepimlibs/kimap
From: Andras Mantia <amantia () kde ! org>
Date: 2009-04-05 8:42:15
Message-ID: 1238920935.263884.16455.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 949395 by amantia:
Make TLS negotiation non-blocking. Add a UIProxy for the Session object used to show \
a warning dialog to the user in case the TLS handshake fails, so the user could \
choose to abort the connection or continue. Requires an up-to-date kdelibs/kdecore.
M +1 -1 CMakeLists.txt
M +2 -0 loginjob.cpp
M +1 -0 loginjob.h
M +21 -1 session.cpp
M +6 -0 session.h
M +2 -0 session_p.h
M +24 -9 sessionthread.cpp
M +3 -0 sessionthread_p.h
A sessionuiproxy.h [License: LGPL (v2+)]
M +1 -1 tests/CMakeLists.txt
M +17 -2 tests/testimapserver.cpp
--- trunk/KDE/kdepimlibs/kimap/CMakeLists.txt #949394:949395
@@ -43,4 +43,4 @@
########### install files ###############
-install( FILES kimap_export.h job.h appendjob.h capabilitiesjob.h fetchjob.h \
listjob.h loginjob.h logoutjob.h rfccodecs.h selectjob.h session.h statusjob.h \
storejob.h DESTINATION ${INCLUDE_INSTALL_DIR}/kimap COMPONENT Devel) +install( FILES \
kimap_export.h job.h appendjob.h capabilitiesjob.h fetchjob.h listjob.h loginjob.h \
logoutjob.h rfccodecs.h selectjob.h closejob.h expungejob.h deletejob.h createjob.h \
subscribejob.h unsubscribejob.h renamejob.h checkjob.h noopjob.h statusjob.h \
session.h sessionuiproxy.h storejob.h DESTINATION ${INCLUDE_INSTALL_DIR}/kimap \
COMPONENT Devel)
--- trunk/KDE/kdepimlibs/kimap/loginjob.cpp #949394:949395
@@ -1,5 +1,7 @@
/*
Copyright (c) 2009 Kevin Ottens <ervin@kde.org>
+ Copyright (c) 2009 Andras Mantia <amantia@kde.org>
+
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
--- trunk/KDE/kdepimlibs/kimap/loginjob.h #949394:949395
@@ -1,5 +1,6 @@
/*
Copyright (c) 2009 Kevin Ottens <ervin@kde.org>
+ Copyright (c) 2009 Andras Mantia <amantia@kde.org>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
--- trunk/KDE/kdepimlibs/kimap/session.cpp #949394:949395
@@ -19,10 +19,14 @@
#include "session.h"
#include "session_p.h"
+#include "sessionuiproxy.h"
#include <QtCore/QDebug>
#include <QtCore/QTimer>
+#include <KDE/KMessageBox>
+#include <KDE/KLocale>
+
#include "job.h"
#include "message_p.h"
#include "sessionthread_p.h"
@@ -37,6 +41,8 @@
d->thread = new SessionThread(hostName, port, this);
connect(d->thread, SIGNAL(tlsNegotiationResult(bool)), this, \
SIGNAL(tlsNegotiationResult(bool))); + connect(d->thread, SIGNAL(sslError(const \
QString&)), this, SLOT(handleSslError(const QString&))); + connect(this, \
SIGNAL(sslErrorHandlerResponse(bool)), d->thread, \
SLOT(sslErrorHandlerResponse(bool)));
d->thread->start();
}
@@ -46,6 +52,11 @@
delete d->thread;
}
+void Session::setUiProxy(SessionUiProxy *proxy)
+{
+ d->uiProxy = proxy;
+}
+
QString Session::hostName() const
{
return d->thread->hostName();
@@ -61,9 +72,18 @@
return d->state;
}
+void Session::handleSslError(const QString& error) {
+ if (d->uiProxy && d->uiProxy->ignoreSslError(error)) {
+ emit sslErrorHandlerResponse(true);
+ } else {
+ emit sslErrorHandlerResponse(false);
+ }
+}
+
SessionPrivate::SessionPrivate( Session *session )
: q(session),
- currentJob(0)
+ currentJob(0),
+ uiProxy(0)
{
}
--- trunk/KDE/kdepimlibs/kimap/session.h #949394:949395
@@ -26,6 +26,7 @@
namespace KIMAP {
+class SessionUiProxy;
class SessionPrivate;
class JobPrivate;
class Message;
@@ -46,10 +47,15 @@
QString hostName() const;
quint16 port() const;
State state() const;
+ void setUiProxy(SessionUiProxy *proxy);
Q_SIGNALS:
void tlsNegotiationResult(bool);
+ void sslErrorHandlerResponse(bool);
+ private Q_SLOTS:
+ void handleSslError(const QString& message);
+
private:
Q_PRIVATE_SLOT( d, void doStartNext() )
Q_PRIVATE_SLOT( d, void jobDone( KJob* ) )
--- trunk/KDE/kdepimlibs/kimap/session_p.h #949394:949395
@@ -31,6 +31,7 @@
class Job;
class Message;
class SessionThread;
+class SessionUiProxy;
class SessionPrivate
{
@@ -63,6 +64,7 @@
Session::State state;
SessionThread *thread;
+ SessionUiProxy *uiProxy;
bool jobRunning;
Job *currentJob;
--- trunk/KDE/kdepimlibs/kimap/sessionthread.cpp #949394:949395
@@ -157,23 +157,24 @@
QMutexLocker locker(&m_mutex);
m_socket->setAdvertisedSslVersion(KTcpSocket::TlsV1);
-// m_socket->ignoreSslErrors();
+ m_socket->ignoreSslErrors();
+ connect(m_socket, SIGNAL(encrypted()), this, SLOT(tlsConnected()));
m_socket->startClientEncryption();
- const bool encryptionStarted = m_socket->waitForEncrypted(-1);
+}
+
+void SessionThread::tlsConnected()
+{
+ QMutexLocker locker(&m_mutex);
KSslCipher cipher = m_socket->sessionCipher();
- if (!encryptionStarted || m_socket->encryptionMode() != KTcpSocket::SslClientMode
+ if ( m_socket->sslErrors().count() > 0 || m_socket->encryptionMode() != \
KTcpSocket::SslClientMode || cipher.isNull() || cipher.usedBits() == 0) {
- kDebug() << "Initial SSL handshake failed. encryptionStarted is"
- << encryptionStarted << ", cipher.isNull() is" << \
cipher.isNull() + kDebug() << "Initial SSL handshake failed. cipher.isNull() is" \
<< cipher.isNull() << ", cipher.usedBits() is" << cipher.usedBits()
<< ", the socket says:" << m_socket->errorString()
<< "and the list of SSL errors contains"
<< m_socket->sslErrors().count() << "items.";
- m_encryptedMode = false;
- //reconnect in unencrypted mode, so new commands can be issued
- m_socket->connectToHost(m_hostName, m_port);
- emit tlsNegotiationResult(false);
+ emit sslError(m_socket->errorString());
} else {
kDebug() << "TLS negotiation done.";
m_encryptedMode = true;
@@ -181,5 +182,19 @@
}
}
+void SessionThread::sslErrorHandlerResponse(bool response)
+{
+ if (response) {
+ m_encryptedMode = true;
+ emit tlsNegotiationResult(true);
+ } else {
+ m_encryptedMode = false;
+ //reconnect in unencrypted mode, so new commands can be issued
+ m_socket->disconnectFromHost();
+ m_socket->connectToHost(m_hostName, m_port);
+ emit tlsNegotiationResult(false);
+ }
+}
+
#include "sessionthread_p.moc"
--- trunk/KDE/kdepimlibs/kimap/sessionthread_p.h #949394:949395
@@ -56,10 +56,13 @@
signals:
void responseReceived(const KIMAP::Message &response);
void tlsNegotiationResult(bool);
+ void sslError(const QString&);
private slots:
void readMessage();
void writeDataQueue();
+ void tlsConnected();
+ void sslErrorHandlerResponse(bool result);
private:
QString m_hostName;
--- trunk/KDE/kdepimlibs/kimap/tests/CMakeLists.txt #949394:949395
@@ -14,7 +14,7 @@
FOREACH(_testname ${ARGN})
kde4_add_executable(${_testname} NOGUI TEST ${_testname}.cpp)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${KDE4_ENABLE_EXCEPTIONS}")
- target_link_libraries(${_testname} ${KDE4_KDECORE_LIBS} kimap kmime)
+ target_link_libraries(${_testname} ${KDE4_KDECORE_LIBS} ${KDE4_KDEUI_LIBS} kimap \
kmime) ENDFOREACH(_testname)
ENDMACRO(KIMAP_EXECUTABLE_TESTS)
--- trunk/KDE/kdepimlibs/kimap/tests/testimapserver.cpp #949394:949395
@@ -2,8 +2,9 @@
#include <kaboutdata.h>
#include <kdebug.h>
#include <qtcpsocket.h>
-#include <qcoreapplication.h>
+#include <qapplication.h>
#include <qsignalspy.h>
+#include <kmessagebox.h>
#include "kimap/session.h"
#include "kimap/appendjob.h"
@@ -21,9 +22,21 @@
#include "kimap/unsubscribejob.h"
#include "kimap/renamejob.h"
#include "kimap/storejob.h"
+#include "kimap/sessionuiproxy.h"
using namespace KIMAP;
+class UiProxy: public SessionUiProxy {
+ public:
+ bool ignoreSslError(const QString &error) {
+ if (KMessageBox::questionYesNo(0, i18n("Ssl error received: %1. \
Continue?").arg(error), i18n("SSL Error") ) == KMessageBox::Yes) { + return \
true; + } else {
+ return false;
+ }
+ }
+};
+
void dumpContentHelper(KMime::Content *part, const QString &partId = QString())
{
if (partId.isEmpty()) {
@@ -255,8 +268,10 @@
kDebug() << "Querying:" << server << port << user << password;
qDebug();
- QCoreApplication app(argc, argv);
+ QApplication app(argc, argv);
Session session(server, port);
+ UiProxy *proxy = new UiProxy();
+ session.setUiProxy(proxy);
kDebug() << "Logging in...";
LoginJob *login = new LoginJob(&session);
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic