summaryrefslogtreecommitdiffstats
path: root/src/network
diff options
context:
space:
mode:
authorA-Team <ateam@pad.test.qt.nokia.com>2010-09-09 22:00:10 (GMT)
committerA-Team <ateam@pad.test.qt.nokia.com>2010-09-09 22:00:10 (GMT)
commit03c56248554b731356d283e467e1d31c54e78653 (patch)
tree5cfc5f5009f6534951f85257dddf1be1260b516f /src/network
parentdd387a0125b577fafc1a3363a4b8cd995053b7db (diff)
parent524379030503600bbca1a8e2b5889b91b0798203 (diff)
downloadQt-03c56248554b731356d283e467e1d31c54e78653.zip
Qt-03c56248554b731356d283e467e1d31c54e78653.tar.gz
Qt-03c56248554b731356d283e467e1d31c54e78653.tar.bz2
Merge branch '4.7-upstream' into 4.7-doc
Diffstat (limited to 'src/network')
-rw-r--r--src/network/access/qnetworkreply.cpp6
-rw-r--r--src/network/kernel/qhostinfo_win.cpp14
-rw-r--r--src/network/kernel/qnetworkinterface_win.cpp3
-rw-r--r--src/network/kernel/qnetworkproxy_win.cpp15
-rw-r--r--src/network/ssl/qsslsocket_openssl.cpp193
-rw-r--r--src/network/ssl/qsslsocket_openssl_p.h77
-rw-r--r--src/network/ssl/qsslsocket_openssl_symbols.cpp36
7 files changed, 180 insertions, 164 deletions
diff --git a/src/network/access/qnetworkreply.cpp b/src/network/access/qnetworkreply.cpp
index c8b8c1f..261ed20 100644
--- a/src/network/access/qnetworkreply.cpp
+++ b/src/network/access/qnetworkreply.cpp
@@ -283,9 +283,6 @@ QNetworkReplyPrivate::QNetworkReplyPrivate()
The upload is finished when \a bytesSent is equal to \a
bytesTotal. At that time, \a bytesTotal will not be -1.
- This signal is suitable to connecting to QProgressBar::setValue()
- to update the QProgressBar that provides user feedback.
-
\sa downloadProgress()
*/
@@ -306,9 +303,6 @@ QNetworkReplyPrivate::QNetworkReplyPrivate()
The download is finished when \a bytesReceived is equal to \a
bytesTotal. At that time, \a bytesTotal will not be -1.
- This signal is suitable to connecting to QProgressBar::setValue()
- to update the QProgressBar that provides user feedback.
-
Note that the values of both \a bytesReceived and \a bytesTotal
may be different from size(), the total number of bytes
obtained through read() or readAll(), or the value of the
diff --git a/src/network/kernel/qhostinfo_win.cpp b/src/network/kernel/qhostinfo_win.cpp
index b30204b..8241c84 100644
--- a/src/network/kernel/qhostinfo_win.cpp
+++ b/src/network/kernel/qhostinfo_win.cpp
@@ -49,7 +49,7 @@
#include "qhostinfo_p.h"
#include "private/qnativesocketengine_p.h"
#include <ws2tcpip.h>
-#include <qlibrary.h>
+#include <private/qsystemlibrary_p.h>
#include <qmutex.h>
#include <qurl.h>
#include <private/qmutexpool_p.h>
@@ -90,13 +90,13 @@ static void resolveLibrary()
// Attempt to resolve getaddrinfo(); without it we'll have to fall
// back to gethostbyname(), which has no IPv6 support.
#if !defined(Q_OS_WINCE)
- local_getaddrinfo = (getaddrinfoProto) QLibrary::resolve(QLatin1String("ws2_32.dll"), "getaddrinfo");
- local_freeaddrinfo = (freeaddrinfoProto) QLibrary::resolve(QLatin1String("ws2_32.dll"), "freeaddrinfo");
- local_getnameinfo = (getnameinfoProto) QLibrary::resolve(QLatin1String("ws2_32.dll"), "getnameinfo");
+ local_getaddrinfo = (getaddrinfoProto) QSystemLibrary::resolve(QLatin1String("ws2_32"), "getaddrinfo");
+ local_freeaddrinfo = (freeaddrinfoProto) QSystemLibrary::resolve(QLatin1String("ws2_32"), "freeaddrinfo");
+ local_getnameinfo = (getnameinfoProto) QSystemLibrary::resolve(QLatin1String("ws2_32"), "getnameinfo");
#else
- local_getaddrinfo = (getaddrinfoProto) QLibrary::resolve(QLatin1String("ws2.dll"), "getaddrinfo");
- local_freeaddrinfo = (freeaddrinfoProto) QLibrary::resolve(QLatin1String("ws2.dll"), "freeaddrinfo");
- local_getnameinfo = (getnameinfoProto) QLibrary::resolve(QLatin1String("ws2.dll"), "getnameinfo");
+ local_getaddrinfo = (getaddrinfoProto) QSystemLibrary::resolve(QLatin1String("ws2"), "getaddrinfo");
+ local_freeaddrinfo = (freeaddrinfoProto) QSystemLibrary::resolve(QLatin1String("ws2"), "freeaddrinfo");
+ local_getnameinfo = (getnameinfoProto) QSystemLibrary::resolve(QLatin1String("ws2"), "getnameinfo");
#endif
}
diff --git a/src/network/kernel/qnetworkinterface_win.cpp b/src/network/kernel/qnetworkinterface_win.cpp
index 056650d..a1d1df6 100644
--- a/src/network/kernel/qnetworkinterface_win.cpp
+++ b/src/network/kernel/qnetworkinterface_win.cpp
@@ -48,6 +48,7 @@
#include <qhostinfo.h>
#include <qhash.h>
#include <qurl.h>
+#include <private/qsystemlibrary_p.h>
QT_BEGIN_NAMESPACE
@@ -66,7 +67,7 @@ static void resolveLibs()
if (!done) {
done = true;
- HINSTANCE iphlpapiHnd = LoadLibrary(L"iphlpapi");
+ HINSTANCE iphlpapiHnd = QSystemLibrary::load(L"iphlpapi");
if (iphlpapiHnd == NULL)
return;
diff --git a/src/network/kernel/qnetworkproxy_win.cpp b/src/network/kernel/qnetworkproxy_win.cpp
index 537107e..a72ef38 100644
--- a/src/network/kernel/qnetworkproxy_win.cpp
+++ b/src/network/kernel/qnetworkproxy_win.cpp
@@ -51,6 +51,7 @@
#include <string.h>
#include <qt_windows.h>
#include <wininet.h>
+#include <private/qsystemlibrary_p.h>
/*
* Information on the WinHTTP DLL:
@@ -277,15 +278,15 @@ void QWindowsSystemProxy::init()
return;
#else
// load the winhttp.dll library
- HINSTANCE winhttpHnd = LoadLibrary(L"winhttp");
- if (!winhttpHnd)
+ QSystemLibrary lib(L"winhttp");
+ if (!lib.load())
return; // failed to load
- ptrWinHttpOpen = (PtrWinHttpOpen)GetProcAddress(winhttpHnd, "WinHttpOpen");
- ptrWinHttpCloseHandle = (PtrWinHttpCloseHandle)GetProcAddress(winhttpHnd, "WinHttpCloseHandle");
- ptrWinHttpGetProxyForUrl = (PtrWinHttpGetProxyForUrl)GetProcAddress(winhttpHnd, "WinHttpGetProxyForUrl");
- ptrWinHttpGetDefaultProxyConfiguration = (PtrWinHttpGetDefaultProxyConfiguration)GetProcAddress(winhttpHnd, "WinHttpGetDefaultProxyConfiguration");
- ptrWinHttpGetIEProxyConfigForCurrentUser = (PtrWinHttpGetIEProxyConfigForCurrentUser)GetProcAddress(winhttpHnd, "WinHttpGetIEProxyConfigForCurrentUser");
+ ptrWinHttpOpen = (PtrWinHttpOpen)lib.resolve("WinHttpOpen");
+ ptrWinHttpCloseHandle = (PtrWinHttpCloseHandle)lib.resolve("WinHttpCloseHandle");
+ ptrWinHttpGetProxyForUrl = (PtrWinHttpGetProxyForUrl)lib.resolve("WinHttpGetProxyForUrl");
+ ptrWinHttpGetDefaultProxyConfiguration = (PtrWinHttpGetDefaultProxyConfiguration)lib.resolve("WinHttpGetDefaultProxyConfiguration");
+ ptrWinHttpGetIEProxyConfigForCurrentUser = (PtrWinHttpGetIEProxyConfigForCurrentUser)lib.resolve("WinHttpGetIEProxyConfigForCurrentUser");
// Try to obtain the Internet Explorer configuration.
WINHTTP_CURRENT_USER_IE_PROXY_CONFIG ieProxyConfig;
diff --git a/src/network/ssl/qsslsocket_openssl.cpp b/src/network/ssl/qsslsocket_openssl.cpp
index 94b1568..5033393 100644
--- a/src/network/ssl/qsslsocket_openssl.cpp
+++ b/src/network/ssl/qsslsocket_openssl.cpp
@@ -71,6 +71,9 @@ QT_BEGIN_NAMESPACE
PtrCertFindCertificateInStore QSslSocketPrivate::ptrCertFindCertificateInStore = 0;
PtrCertCloseStore QSslSocketPrivate::ptrCertCloseStore = 0;
#elif defined(Q_OS_SYMBIAN)
+#include <e32base.h>
+#include <e32std.h>
+#include <e32debug.h>
#include <QtCore/private/qcore_symbian_p.h>
#endif
@@ -570,120 +573,138 @@ void QSslSocketPrivate::resetDefaultCiphers()
#if defined(Q_OS_SYMBIAN)
-QCertificateRetriever::QCertificateRetriever(QCertificateConsumer* parent)
- : CActive(EPriorityStandard)
- , certStore(0)
- , certFilter(0)
- , consumer(parent)
- , currentCertificateIndex(0)
- , certDescriptor(0, 0)
+CSymbianCertificateRetriever::CSymbianCertificateRetriever() : CActive(CActive::EPriorityStandard),
+ iSequenceError(KErrNone)
{
- CActiveScheduler::Add(this);
- QT_TRAP_THROWING(certStore = CUnifiedCertStore::NewL(qt_s60GetRFs(), EFalse));
- QT_TRAP_THROWING(certFilter = CCertAttributeFilter::NewL());
- certFilter->SetFormat(EX509Certificate);
}
-QCertificateRetriever::~QCertificateRetriever()
+CSymbianCertificateRetriever::~CSymbianCertificateRetriever()
{
- delete certFilter;
- delete certStore;
- Cancel();
+ iThread.Close();
}
-void QCertificateRetriever::fetch()
+CSymbianCertificateRetriever* CSymbianCertificateRetriever::NewL()
{
- certStore->Initialize(iStatus);
- state = Initializing;
- SetActive();
+ CSymbianCertificateRetriever* self = new (ELeave) CSymbianCertificateRetriever();
+ CleanupStack::PushL(self);
+ self->ConstructL();
+ CleanupStack::Pop();
+ return self;
}
-void QCertificateRetriever::list()
+int CSymbianCertificateRetriever::GetCertificates(QList<QByteArray> &certificates)
{
- certStore->List(certs, *certFilter, iStatus);
- state = Listing;
- SetActive();
+ iCertificates = &certificates;
+
+ TRequestStatus status;
+ iThread.Logon(status);
+ iThread.Resume();
+ User::WaitForRequest(status);
+ if (iThread.ExitType() == EExitKill)
+ return KErrDied;
+ else
+ return status.Int(); // Logon() completes with the thread's exit value
}
-void QCertificateRetriever::retrieveNextCertificate()
+void CSymbianCertificateRetriever::doThreadEntryL()
{
- CCTCertInfo* cert = certs[currentCertificateIndex];
- currentCertificate.resize(cert->Size());
- certDescriptor.Set((TUint8*)currentCertificate.data(), 0, currentCertificate.size());
- certStore->Retrieve(*cert, certDescriptor, iStatus);
- state = RetrievingCertificates;
+ CActiveScheduler* activeScheduler = new (ELeave) CActiveScheduler;
+ CleanupStack::PushL(activeScheduler);
+ CActiveScheduler::Install(activeScheduler);
+
+ CActiveScheduler::Add(this);
+
+ // These aren't deleted in the destructor so leaving the to CS is ok
+ iCertStore = CUnifiedCertStore::NewLC(qt_s60GetRFs(), EFalse);
+ iCertFilter = CCertAttributeFilter::NewLC();
+
+ // Kick off the sequence by initializing the cert store
+ iState = Initializing;
+ iCertStore->Initialize(iStatus);
SetActive();
-}
-void QCertificateRetriever::RunL()
-{
- QT_TRYCATCH_LEAVING(run());
+ CActiveScheduler::Start();
+
+ // Sequence complete, clean up
+
+ // These MUST be cleaned up before the installed CActiveScheduler is destroyed and can't be left to the
+ // destructor of CSymbianCertificateRetriever. Otherwise the destructor of CActiveScheduler will get
+ // stuck.
+ iCertInfos.Close();
+ CleanupStack::PopAndDestroy(3); // activeScheduler, iCertStore, iCertFilter
}
-void QCertificateRetriever::run()
+
+TInt CSymbianCertificateRetriever::ThreadEntryPoint(TAny* aParams)
{
- switch (state) {
- case Initializing:
- list();
- break;
- case Listing:
- currentCertificateIndex = 0;
- retrieveNextCertificate();
- break;
- case RetrievingCertificates:
- consumer->addEncodedCertificate(currentCertificate);
- currentCertificate = QByteArray();
+ CTrapCleanup* cleanupStack = CTrapCleanup::New();
- currentCertificateIndex++;
+ CSymbianCertificateRetriever* self = (CSymbianCertificateRetriever*) aParams;
+ TRAPD(err, self->doThreadEntryL());
+ delete cleanupStack;
- if (currentCertificateIndex < certs.Count())
- retrieveNextCertificate();
- else
- consumer->finish();
- break;
- }
+ // doThreadEntryL() can leave only before the retrieval sequence is started
+ if (err)
+ return err;
+ else
+ return self->iSequenceError; // return any error that occured during the retrieval
}
-void QCertificateRetriever::DoCancel()
+void CSymbianCertificateRetriever::ConstructL()
{
- switch (state) {
- case Initializing:
- certStore->CancelInitialize();
- break;
- case Listing:
- certStore->CancelList();
- break;
- case RetrievingCertificates:
- certStore->CancelRetrieve();
- break;
- }
+ User::LeaveIfError(iThread.Create(_L("CertWorkerThread"),
+ CSymbianCertificateRetriever::ThreadEntryPoint, 16384, NULL, this));
}
-QCertificateConsumer::QCertificateConsumer(QObject* parent)
- : QObject(parent)
- , retriever(0)
+void CSymbianCertificateRetriever::DoCancel()
{
+ // We never cancel the sequence
}
-QCertificateConsumer::~QCertificateConsumer()
+TInt CSymbianCertificateRetriever::RunError(TInt aError)
{
- delete retriever;
+ // If something goes wrong in the sequence, abort the sequence
+ iSequenceError = aError; // this gets reported to the client in the TRequestStatus
+ CActiveScheduler::Stop();
+ return KErrNone;
}
-void QCertificateConsumer::finish()
+void CSymbianCertificateRetriever::GetCertificateL()
{
- delete retriever;
- retriever = 0;
- emit finished();
+ CCTCertInfo* certInfo = iCertInfos[iCurrentCertIndex];
+ iCertificateData.resize(certInfo->Size());
+ TPtr8 des((TUint8*)iCertificateData.data(), 0, iCertificateData.size());
+ iCertStore->Retrieve(*certInfo, des, iStatus);
+ iState = RetrievingCertificates;
+ SetActive();
}
-void QCertificateConsumer::start()
+void CSymbianCertificateRetriever::RunL()
{
- retriever = new QCertificateRetriever(this);
- Q_CHECK_PTR(retriever);
- retriever->fetch();
-}
+ switch (iState) {
+ case Initializing:
+ iState = Listing;
+ iCertStore->List(iCertInfos, *iCertFilter, iStatus);
+ SetActive();
+ break;
+ case Listing:
+ iCurrentCertIndex = 0;
+ GetCertificateL();
+ break;
+
+ case RetrievingCertificates:
+ iCertificates->append(iCertificateData);
+ iCertificateData = QByteArray();
+ iCurrentCertIndex++;
+ if (iCurrentCertIndex < iCertInfos.Count())
+ GetCertificateL();
+ else
+ // Stop the scheduler to return to the thread entry function
+ CActiveScheduler::Stop();
+ break;
+ }
+}
#endif // defined(Q_OS_SYMBIAN)
QList<QSslCertificate> QSslSocketPrivate::systemCaCertificates()
@@ -760,23 +781,15 @@ QList<QSslCertificate> QSslSocketPrivate::systemCaCertificates()
systemCerts.append(QSslCertificate::fromPath(QLatin1String("/usr/share/ssl/*.pem"), QSsl::Pem, QRegExp::Wildcard)); // Centos, Redhat, SuSE
systemCerts.append(QSslCertificate::fromPath(QLatin1String("/usr/local/ssl/*.pem"), QSsl::Pem, QRegExp::Wildcard)); // Normal OpenSSL Tarball
#elif defined(Q_OS_SYMBIAN)
- QThread* certThread = new QThread;
+ QList<QByteArray> certs;
+ QScopedPointer<CSymbianCertificateRetriever> retriever(CSymbianCertificateRetriever::NewL());
- QCertificateConsumer *consumer = new QCertificateConsumer();
- consumer->moveToThread(certThread);
- QObject::connect(certThread, SIGNAL(started()), consumer, SLOT(start()));
- QObject::connect(consumer, SIGNAL(finished()), certThread, SLOT(quit()), Qt::DirectConnection);
-
- certThread->start();
- certThread->wait();
- foreach (const QByteArray &encodedCert, consumer->encodedCertificates()) {
+ retriever->GetCertificates(certs);
+ foreach (const QByteArray &encodedCert, certs) {
QSslCertificate cert(encodedCert, QSsl::Der);
if (!cert.isNull())
systemCerts.append(cert);
}
-
- delete consumer;
- delete certThread;
#endif
return systemCerts;
diff --git a/src/network/ssl/qsslsocket_openssl_p.h b/src/network/ssl/qsslsocket_openssl_p.h
index 7a4e6b6..dec98ae 100644
--- a/src/network/ssl/qsslsocket_openssl_p.h
+++ b/src/network/ssl/qsslsocket_openssl_p.h
@@ -120,67 +120,56 @@ public:
};
#if defined(Q_OS_SYMBIAN)
+
+#include <QByteArray>
+#include <e32base.h>
+#include <f32file.h>
#include <unifiedcertstore.h> // link against certstore.lib
#include <ccertattributefilter.h> // link against ctframework.lib
-class QCertificateRetriever;
+// The purpose of this class is to wrap the asynchronous API of Symbian certificate store to one
+// synchronizable call. The user of this class needs to provide a TRequestStatus object which can
+// be used with User::WaitForRequest() unlike with the calls of the certificate store API.
+// A thread is used instead of a CActiveSchedulerWait scheme, because that would make the call
+// asynchronous (other events might be processed during the call even though the call would be seemingly
+// synchronous).
-class QCertificateConsumer : public QObject
+class CSymbianCertificateRetriever : public CActive
{
- Q_OBJECT
public:
- QCertificateConsumer(QObject* parent = 0);
- ~QCertificateConsumer();
-
- void finish();
-
- void addEncodedCertificate(const QByteArray& certificate)
- { certificates.append(certificate); }
- QList<QByteArray> encodedCertificates() const { return certificates; }
-
-public slots:
- void start();
+ static CSymbianCertificateRetriever* NewL();
+ ~CSymbianCertificateRetriever();
-signals:
- void finished();
+ int GetCertificates(QList<QByteArray> &aCertificates);
private:
- QList<QByteArray> certificates;
- QCertificateRetriever *retriever;
-};
-
-
-class QCertificateRetriever : public CActive
-{
-public:
- QCertificateRetriever(QCertificateConsumer* consumer);
- ~QCertificateRetriever();
-
- void fetch();
+ void ConstructL();
+ CSymbianCertificateRetriever();
+ static TInt ThreadEntryPoint(TAny* aParams);
+ void doThreadEntryL();
+ void GetCertificateL();
+ void DoCancel();
+ void RunL();
+ TInt RunError(TInt aError);
private:
- virtual void RunL();
- virtual void DoCancel();
-
- void run();
- void list();
- void retrieveNextCertificate();
-
enum {
Initializing,
Listing,
RetrievingCertificates
- } state;
-
- CUnifiedCertStore* certStore;
- RMPointerArray<CCTCertInfo> certs;
- CCertAttributeFilter* certFilter;
- QCertificateConsumer* consumer;
- int currentCertificateIndex;
- QByteArray currentCertificate;
- TPtr8 certDescriptor;
+ } iState;
+
+ RThread iThread;
+ CUnifiedCertStore* iCertStore;
+ RMPointerArray<CCTCertInfo> iCertInfos;
+ CCertAttributeFilter* iCertFilter;
+ TInt iCurrentCertIndex;
+ QByteArray iCertificateData;
+ QList<QByteArray>* iCertificates;
+ TInt iSequenceError;
};
+
#endif
diff --git a/src/network/ssl/qsslsocket_openssl_symbols.cpp b/src/network/ssl/qsslsocket_openssl_symbols.cpp
index d1225c1..6affa36 100644
--- a/src/network/ssl/qsslsocket_openssl_symbols.cpp
+++ b/src/network/ssl/qsslsocket_openssl_symbols.cpp
@@ -42,7 +42,11 @@
#include "qsslsocket_openssl_symbols_p.h"
-#include <QtCore/qlibrary.h>
+#ifdef Q_OS_WIN
+# include <private/qsystemlibrary_p.h>
+#else
+# include <QtCore/qlibrary.h>
+#endif
#include <QtCore/qmutex.h>
#include <private/qmutexpool_p.h>
#include <QtCore/qdatetime.h>
@@ -345,22 +349,22 @@ static QStringList findAllLibSsl()
}
# endif
-static QPair<QLibrary*, QLibrary*> loadOpenSsl()
+#ifdef Q_OS_WIN
+static QPair<QSystemLibrary*, QSystemLibrary*> loadOpenSslWin32()
{
- QPair<QLibrary*,QLibrary*> pair;
+ QPair<QSystemLibrary*,QSystemLibrary*> pair;
pair.first = 0;
pair.second = 0;
-# ifdef Q_OS_WIN
- QLibrary *ssleay32 = new QLibrary(QLatin1String("ssleay32"));
- if (!ssleay32->load()) {
+ QSystemLibrary *ssleay32 = new QSystemLibrary(QLatin1String("ssleay32"));
+ if (!ssleay32->load(false)) {
// Cannot find ssleay32.dll
delete ssleay32;
return pair;
}
- QLibrary *libeay32 = new QLibrary(QLatin1String("libeay32"));
- if (!libeay32->load()) {
+ QSystemLibrary *libeay32 = new QSystemLibrary(QLatin1String("libeay32"));
+ if (!libeay32->load(false)) {
delete ssleay32;
delete libeay32;
return pair;
@@ -369,7 +373,16 @@ static QPair<QLibrary*, QLibrary*> loadOpenSsl()
pair.first = ssleay32;
pair.second = libeay32;
return pair;
-# elif defined(Q_OS_SYMBIAN)
+}
+#else
+
+static QPair<QLibrary*, QLibrary*> loadOpenSsl()
+{
+ QPair<QLibrary*,QLibrary*> pair;
+ pair.first = 0;
+ pair.second = 0;
+
+# if defined(Q_OS_SYMBIAN)
QLibrary *libssl = new QLibrary(QLatin1String("libssl"));
if (!libssl->load()) {
// Cannot find ssleay32.dll
@@ -469,6 +482,7 @@ static QPair<QLibrary*, QLibrary*> loadOpenSsl()
return pair;
# endif
}
+#endif
bool q_resolveOpenSslSymbols()
{
@@ -483,7 +497,11 @@ bool q_resolveOpenSslSymbols()
return false;
triedToResolveSymbols = true;
+#ifdef Q_OS_WIN
+ QPair<QSystemLibrary *, QSystemLibrary *> libs = loadOpenSslWin32();
+#else
QPair<QLibrary *, QLibrary *> libs = loadOpenSsl();
+#endif
if (!libs.first || !libs.second)
// failed to load them
return false;