diff options
author | Aaron McCarthy <aaron.mccarthy@nokia.com> | 2009-12-03 02:44:11 (GMT) |
---|---|---|
committer | Aaron McCarthy <aaron.mccarthy@nokia.com> | 2009-12-22 05:10:14 (GMT) |
commit | 2374a4209f9edcc865b18f63e07a50cdaddc70b7 (patch) | |
tree | 325f735e0b9ca4dc1fae7b25d4b436ea93ef7296 /src/network | |
parent | c2254fdcba61c0aceb89f2f5e6dc926a9493c1a2 (diff) | |
download | Qt-2374a4209f9edcc865b18f63e07a50cdaddc70b7.zip Qt-2374a4209f9edcc865b18f63e07a50cdaddc70b7.tar.gz Qt-2374a4209f9edcc865b18f63e07a50cdaddc70b7.tar.bz2 |
Convert NLA engine nito a plugin.
Diffstat (limited to 'src/network')
-rw-r--r-- | src/network/bearer/bearer.pri | 17 | ||||
-rw-r--r-- | src/network/bearer/qnetworkconfigmanager_p.cpp | 17 | ||||
-rw-r--r-- | src/network/bearer/qnetworkconfigmanager_p.h | 2 | ||||
-rw-r--r-- | src/network/bearer/qnetworksession_p.cpp | 11 | ||||
-rw-r--r-- | src/network/bearer/qnetworksessionengine_win_p.h | 145 | ||||
-rw-r--r-- | src/network/bearer/qnlaengine_win.cpp | 592 | ||||
-rw-r--r-- | src/network/bearer/qnlaengine_win_p.h | 104 |
7 files changed, 16 insertions, 872 deletions
diff --git a/src/network/bearer/bearer.pri b/src/network/bearer/bearer.pri index bed2597..2c2d255 100644 --- a/src/network/bearer/bearer.pri +++ b/src/network/bearer/bearer.pri @@ -82,21 +82,10 @@ symbian { contains(QT_CONFIG, networkmanager):DEFINES += BACKEND_NM - win32 { - HEADERS += bearer/qnlaengine_win_p.h \ - bearer/qnetworksessionengine_win_p.h + win32:!wince* { + HEADERS += bearer/qnativewifiengine_win_p.h - SOURCES += bearer/qnlaengine_win.cpp - - !wince* { - HEADERS += bearer/qnativewifiengine_win_p.h - - SOURCES += bearer/qnativewifiengine_win.cpp - - LIBS += -lWs2_32 - } else { - LIBS += -lWs2 - } + SOURCES += bearer/qnativewifiengine_win.cpp } macx { diff --git a/src/network/bearer/qnetworkconfigmanager_p.cpp b/src/network/bearer/qnetworkconfigmanager_p.cpp index 7b68394..c61bcd3 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.cpp +++ b/src/network/bearer/qnetworkconfigmanager_p.cpp @@ -41,9 +41,6 @@ #include "qnetworkconfigmanager_p.h" -#ifdef Q_OS_WIN -#include "qnlaengine_win_p.h" -#endif #ifdef Q_OS_WIN32 #include "qnativewifiengine_win_p.h" #endif @@ -269,11 +266,17 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations() #endif #ifdef Q_OS_WIN - nla = QNlaEngine::instance(); - if (nla) { - connect(nla, SIGNAL(configurationsChanged()), - this, SLOT(updateConfigurations())); + if (keys.contains(QLatin1String("nla"))) { + QBearerEnginePlugin *nlaPlugin = + qobject_cast<QBearerEnginePlugin *>(l->instance(QLatin1String("nla"))); + if (nlaPlugin) { + nla = nlaPlugin->create(QLatin1String("nla")); + if (nla) { + connect(nla, SIGNAL(configurationsChanged()), + this, SLOT(updateConfigurations())); + } } + } #endif #ifdef Q_OS_WIN32 diff --git a/src/network/bearer/qnetworkconfigmanager_p.h b/src/network/bearer/qnetworkconfigmanager_p.h index 6a61891..7b824f0 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.h +++ b/src/network/bearer/qnetworkconfigmanager_p.h @@ -137,7 +137,7 @@ private: #ifdef BEARER_ENGINE QNetworkSessionEngine *generic; #ifdef Q_OS_WIN - QNlaEngine *nla; + QNetworkSessionEngine *nla; #ifndef Q_OS_WINCE QNativeWifiEngine *nativeWifi; #endif diff --git a/src/network/bearer/qnetworksession_p.cpp b/src/network/bearer/qnetworksession_p.cpp index cb170e8..1ce94e2 100644 --- a/src/network/bearer/qnetworksession_p.cpp +++ b/src/network/bearer/qnetworksession_p.cpp @@ -44,9 +44,6 @@ #include "qnetworksessionengine_p.h" #include "qnetworkconfigmanager_p.h" -#ifdef Q_OS_WIN -#include "qnlaengine_win_p.h" -#endif #ifdef Q_OS_WIN32 #include "qnativewifiengine_win_p.h" #endif @@ -59,18 +56,14 @@ #include <QtNetwork/qnetworkinterface.h> +#undef interface + QT_BEGIN_NAMESPACE static QNetworkSessionEngine *getEngineFromId(const QString &id) { QNetworkConfigurationManagerPrivate *priv = qNetworkConfigurationManagerPrivate(); -#ifdef Q_OS_WIN - QNlaEngine *nla = QNlaEngine::instance(); - if (nla && nla->hasIdentifier(id)) - return nla; -#endif - #ifdef Q_OS_WIN32 QNativeWifiEngine *nativeWifi = QNativeWifiEngine::instance(); if (nativeWifi && nativeWifi->hasIdentifier(id)) diff --git a/src/network/bearer/qnetworksessionengine_win_p.h b/src/network/bearer/qnetworksessionengine_win_p.h deleted file mode 100644 index e68a35b..0000000 --- a/src/network/bearer/qnetworksessionengine_win_p.h +++ /dev/null @@ -1,145 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtNetwork module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QNETWORKSESSIONENGINE_WIN_P_H -#define QNETWORKSESSIONENGINE_WIN_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include <winsock2.h> -#include <mswsock.h> -#undef interface -#include <winioctl.h> - -#ifndef NS_NLA - -#define NS_NLA 15 - -enum NLA_BLOB_DATA_TYPE { - NLA_RAW_DATA = 0, - NLA_INTERFACE = 1, - NLA_802_1X_LOCATION = 2, - NLA_CONNECTIVITY = 3, - NLA_ICS = 4 -}; - -enum NLA_CONNECTIVITY_TYPE { - NLA_NETWORK_AD_HOC = 0, - NLA_NETWORK_MANAGED = 1, - NLA_NETWORK_UNMANAGED = 2, - NLA_NETWORK_UNKNOWN = 3 -}; - -enum NLA_INTERNET { - NLA_INTERNET_UNKNOWN = 0, - NLA_INTERNET_NO = 1, - NLA_INTERNET_YES = 2 -}; - -struct NLA_BLOB { - struct { - NLA_BLOB_DATA_TYPE type; - DWORD dwSize; - DWORD nextOffset; - } header; - - union { - // NLA_RAW_DATA - CHAR rawData[1]; - - // NLA_INTERFACE - struct { - DWORD dwType; - DWORD dwSpeed; - CHAR adapterName[1]; - } interfaceData; - - // NLA_802_1X_LOCATION - struct { - CHAR information[1]; - } locationData; - - // NLA_CONNECTIVITY - struct { - NLA_CONNECTIVITY_TYPE type; - NLA_INTERNET internet; - } connectivity; - - // NLA_ICS - struct { - struct { - DWORD speed; - DWORD type; - DWORD state; - WCHAR machineName[256]; - WCHAR sharedAdapterName[256]; - } remote; - } ICS; - } data; -}; -#endif - -enum NDIS_MEDIUM { - NdisMedium802_3 = 0, -}; - -enum NDIS_PHYSICAL_MEDIUM { - NdisPhysicalMediumWirelessLan = 1, - NdisPhysicalMediumBluetooth = 10, - NdisPhysicalMediumWiMax = 12, -}; - -#define OID_GEN_MEDIA_SUPPORTED 0x00010103 -#define OID_GEN_PHYSICAL_MEDIUM 0x00010202 - -#define IOCTL_NDIS_QUERY_GLOBAL_STATS \ - CTL_CODE(FILE_DEVICE_PHYSICAL_NETCARD, 0, METHOD_OUT_DIRECT, FILE_ANY_ACCESS) - -#endif // QNETWORKSESSIONENGINE_WIN_P_H diff --git a/src/network/bearer/qnlaengine_win.cpp b/src/network/bearer/qnlaengine_win.cpp deleted file mode 100644 index 579b0e1..0000000 --- a/src/network/bearer/qnlaengine_win.cpp +++ /dev/null @@ -1,592 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtNetwork module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qnlaengine_win_p.h" -#include "qnetworkconfiguration_p.h" - -#include <QtCore/qthread.h> -#include <QtCore/qmutex.h> -#include <QtCore/qcoreapplication.h> -#include <QtCore/qstringlist.h> - -#include <QtCore/qdebug.h> - -#include "qnetworksessionengine_win_p.h" - -QT_BEGIN_NAMESPACE - -Q_GLOBAL_STATIC(QNlaEngine, nlaEngine) - -QWindowsSockInit::QWindowsSockInit() -: version(0) -{ - //### should we try for 2.2 on all platforms ?? - WSAData wsadata; - - // IPv6 requires Winsock v2.0 or better. - if (WSAStartup(MAKEWORD(2,0), &wsadata) != 0) { - qWarning("QBearerManagementAPI: WinSock v2.0 initialization failed."); - } else { - version = 0x20; - } -} - -QWindowsSockInit::~QWindowsSockInit() -{ - WSACleanup(); -} - -#ifdef BEARER_MANAGEMENT_DEBUG -static void printBlob(NLA_BLOB *blob) -{ - qDebug() << "==== BEGIN NLA_BLOB ===="; - - qDebug() << "type:" << blob->header.type; - qDebug() << "size:" << blob->header.dwSize; - qDebug() << "next offset:" << blob->header.nextOffset; - - switch (blob->header.type) { - case NLA_RAW_DATA: - qDebug() << "Raw Data"; - qDebug() << '\t' << blob->data.rawData; - break; - case NLA_INTERFACE: - qDebug() << "Interface"; - qDebug() << "\ttype:" << blob->data.interfaceData.dwType; - qDebug() << "\tspeed:" << blob->data.interfaceData.dwSpeed; - qDebug() << "\tadapter:" << blob->data.interfaceData.adapterName; - break; - case NLA_802_1X_LOCATION: - qDebug() << "802.1x Location"; - qDebug() << '\t' << blob->data.locationData.information; - break; - case NLA_CONNECTIVITY: - qDebug() << "Connectivity"; - qDebug() << "\ttype:" << blob->data.connectivity.type; - qDebug() << "\tinternet:" << blob->data.connectivity.internet; - break; - case NLA_ICS: - qDebug() << "ICS"; - qDebug() << "\tspeed:" << blob->data.ICS.remote.speed; - qDebug() << "\ttype:" << blob->data.ICS.remote.type; - qDebug() << "\tstate:" << blob->data.ICS.remote.state; - qDebug() << "\tmachine name:" << blob->data.ICS.remote.machineName; - qDebug() << "\tshared adapter name:" << blob->data.ICS.remote.sharedAdapterName; - break; - default: - qDebug() << "UNKNOWN BLOB TYPE"; - } - - qDebug() << "===== END NLA_BLOB ====="; -} -#endif - -static QString qGetInterfaceType(const QString &interface) -{ -#ifdef Q_OS_WINCE - Q_UNUSED(interface) -#else - unsigned long oid; - DWORD bytesWritten; - - NDIS_MEDIUM medium; - NDIS_PHYSICAL_MEDIUM physicalMedium; - - HANDLE handle = CreateFile((TCHAR *)QString("\\\\.\\%1").arg(interface).utf16(), 0, - FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0); - if (handle == INVALID_HANDLE_VALUE) - return QString(); - - oid = OID_GEN_MEDIA_SUPPORTED; - bytesWritten = 0; - bool result = DeviceIoControl(handle, IOCTL_NDIS_QUERY_GLOBAL_STATS, &oid, sizeof(oid), - &medium, sizeof(medium), &bytesWritten, 0); - if (!result) { - CloseHandle(handle); - return QString(); - } - - oid = OID_GEN_PHYSICAL_MEDIUM; - bytesWritten = 0; - result = DeviceIoControl(handle, IOCTL_NDIS_QUERY_GLOBAL_STATS, &oid, sizeof(oid), - &physicalMedium, sizeof(physicalMedium), &bytesWritten, 0); - if (!result) { - CloseHandle(handle); - - if (medium == NdisMedium802_3) - return QLatin1String("Ethernet"); - else - return QString(); - } - - CloseHandle(handle); - - if (medium == NdisMedium802_3) { - switch (physicalMedium) { - case NdisPhysicalMediumWirelessLan: - return QLatin1String("WLAN"); - case NdisPhysicalMediumBluetooth: - return QLatin1String("Bluetooth"); - case NdisPhysicalMediumWiMax: - return QLatin1String("WiMAX"); - default: -#ifdef BEARER_MANAGEMENT_DEBUG - qDebug() << "Physical Medium" << physicalMedium; -#endif - return QLatin1String("Ethernet"); - } - } - -#ifdef BEARER_MANAGEMENT_DEBUG - qDebug() << medium << physicalMedium; -#endif - -#endif - - return QString(); -} - -class QNlaThread : public QThread -{ - Q_OBJECT - -public: - QNlaThread(QNlaEngine *parent = 0); - ~QNlaThread(); - - QList<QNetworkConfigurationPrivate *> getConfigurations(); - - void forceUpdate(); - -protected: - virtual void run(); - -private: - void updateConfigurations(QList<QNetworkConfigurationPrivate *> &configs); - DWORD parseBlob(NLA_BLOB *blob, QNetworkConfigurationPrivate *cpPriv) const; - QNetworkConfigurationPrivate *parseQuerySet(const WSAQUERYSET *querySet) const; - void fetchConfigurations(); - -signals: - void networksChanged(); - -private: - QMutex mutex; - HANDLE handle; - bool done; - QList<QNetworkConfigurationPrivate *> fetchedConfigurations; -}; - -QNlaThread::QNlaThread(QNlaEngine *parent) -: QThread(parent), handle(0), done(false) -{ -} - -QNlaThread::~QNlaThread() -{ - mutex.lock(); - - done = true; - - if (handle) { - /* cancel completion event */ - if (WSALookupServiceEnd(handle) == SOCKET_ERROR) - qWarning("WSALookupServiceEnd error %d", WSAGetLastError()); - } - mutex.unlock(); - - wait(); -} - -QList<QNetworkConfigurationPrivate *> QNlaThread::getConfigurations() -{ - QMutexLocker locker(&mutex); - - QList<QNetworkConfigurationPrivate *> foundConfigurations; - - for (int i = 0; i < fetchedConfigurations.count(); ++i) { - QNetworkConfigurationPrivate *config = new QNetworkConfigurationPrivate; - config->name = fetchedConfigurations.at(i)->name; - config->isValid = fetchedConfigurations.at(i)->isValid; - config->id = fetchedConfigurations.at(i)->id; - config->state = fetchedConfigurations.at(i)->state; - config->type = fetchedConfigurations.at(i)->type; - config->roamingSupported = fetchedConfigurations.at(i)->roamingSupported; - config->purpose = fetchedConfigurations.at(i)->purpose; - config->internet = fetchedConfigurations.at(i)->internet; - - foundConfigurations.append(config); - } - - return foundConfigurations; -} - -void QNlaThread::forceUpdate() -{ - mutex.lock(); - - if (handle) { - /* cancel completion event */ - if (WSALookupServiceEnd(handle) == SOCKET_ERROR) - qWarning("WSALookupServiceEnd error %d", WSAGetLastError()); - handle = 0; - } - mutex.unlock(); -} - -void QNlaThread::run() -{ - WSAEVENT changeEvent = WSACreateEvent(); - if (changeEvent == WSA_INVALID_EVENT) { - qWarning("WSACreateEvent error %d", WSAGetLastError()); - return; - } - - while (true) { - fetchConfigurations(); - - WSAQUERYSET qsRestrictions; - - memset(&qsRestrictions, 0, sizeof(qsRestrictions)); - qsRestrictions.dwSize = sizeof(qsRestrictions); - qsRestrictions.dwNameSpace = NS_NLA; - - mutex.lock(); - if (done) { - mutex.unlock(); - break; - } - int result = WSALookupServiceBegin(&qsRestrictions, LUP_RETURN_ALL, &handle); - mutex.unlock(); - - if (result == SOCKET_ERROR) { - qWarning("%s: WSALookupServiceBegin error %d", __FUNCTION__, WSAGetLastError()); - break; - } - - WSACOMPLETION completion; - WSAOVERLAPPED overlapped; - - memset(&overlapped, 0, sizeof(overlapped)); - overlapped.hEvent = changeEvent; - - memset(&completion, 0, sizeof(completion)); - completion.Type = NSP_NOTIFY_EVENT; - completion.Parameters.Event.lpOverlapped = &overlapped; - - DWORD bytesReturned = 0; - result = WSANSPIoctl(handle, SIO_NSP_NOTIFY_CHANGE, 0, 0, 0, 0, - &bytesReturned, &completion); - if (result == SOCKET_ERROR) { - int error = WSAGetLastError(); - if (error != WSA_IO_PENDING) { - qWarning("WSANSPIoctl error %d", error); - break; - } - } - -#ifndef Q_OS_WINCE - // Not interested in unrelated IO completion events - // although we also don't want to block them - while (WaitForSingleObjectEx(changeEvent, WSA_INFINITE, true) != WAIT_IO_COMPLETION) {} -#else - WaitForSingleObject(changeEvent, WSA_INFINITE); -#endif - - mutex.lock(); - if (handle) { - result = WSALookupServiceEnd(handle); - if (result == SOCKET_ERROR) { - qWarning("WSALookupServiceEnd error %d", WSAGetLastError()); - mutex.unlock(); - break; - } - handle = 0; - } - mutex.unlock(); - } - - WSACloseEvent(changeEvent); -} - -void QNlaThread::updateConfigurations(QList<QNetworkConfigurationPrivate *> &configs) -{ - mutex.lock(); - - while (!fetchedConfigurations.isEmpty()) - delete fetchedConfigurations.takeFirst(); - - fetchedConfigurations = configs; - - mutex.unlock(); - - emit networksChanged(); -} - -DWORD QNlaThread::parseBlob(NLA_BLOB *blob, QNetworkConfigurationPrivate *cpPriv) const -{ -#ifdef BEARER_MANAGEMENT_DEBUG - printBlob(blob); -#endif - - switch (blob->header.type) { - case NLA_RAW_DATA: -#ifdef BEARER_MANAGEMENT_DEBUG - qWarning("%s: unhandled header type NLA_RAW_DATA", __FUNCTION__); -#endif - break; - case NLA_INTERFACE: - cpPriv->state = QNetworkConfiguration::Active; - if (QNlaEngine *engine = qobject_cast<QNlaEngine *>(parent())) { - engine->configurationInterface[cpPriv->id.toUInt()] = - QString(blob->data.interfaceData.adapterName); - } - break; - case NLA_802_1X_LOCATION: -#ifdef BEARER_MANAGEMENT_DEBUG - qWarning("%s: unhandled header type NLA_802_1X_LOCATION", __FUNCTION__); -#endif - break; - case NLA_CONNECTIVITY: - if (blob->data.connectivity.internet == NLA_INTERNET_YES) - cpPriv->internet = true; - else - cpPriv->internet = false; -#ifdef BEARER_MANAGEMENT_DEBUG - qWarning("%s: unhandled header type NLA_CONNECTIVITY", __FUNCTION__); -#endif - break; - case NLA_ICS: -#ifdef BEARER_MANAGEMENT_DEBUG - qWarning("%s: unhandled header type NLA_ICS", __FUNCTION__); -#endif - break; - default: -#ifdef BEARER_MANAGEMENT_DEBUG - qWarning("%s: unhandled header type %d", __FUNCTION__, blob->header.type); -#endif - ; - } - - return blob->header.nextOffset; -} - -QNetworkConfigurationPrivate *QNlaThread::parseQuerySet(const WSAQUERYSET *querySet) const -{ - QNetworkConfigurationPrivate *cpPriv = new QNetworkConfigurationPrivate; - - cpPriv->name = QString::fromWCharArray(querySet->lpszServiceInstanceName); - cpPriv->isValid = true; - cpPriv->id = QString::number(qHash(QLatin1String("NLA:") + cpPriv->name)); - cpPriv->state = QNetworkConfiguration::Defined; - cpPriv->type = QNetworkConfiguration::InternetAccessPoint; - -#ifdef BEARER_MANAGEMENT_DEBUG - qDebug() << "size:" << querySet->dwSize; - qDebug() << "service instance name:" << QString::fromUtf16(querySet->lpszServiceInstanceName); - qDebug() << "service class id:" << querySet->lpServiceClassId; - qDebug() << "version:" << querySet->lpVersion; - qDebug() << "comment:" << QString::fromUtf16(querySet->lpszComment); - qDebug() << "namespace:" << querySet->dwNameSpace; - qDebug() << "namespace provider id:" << querySet->lpNSProviderId; - qDebug() << "context:" << QString::fromUtf16(querySet->lpszContext); - qDebug() << "number of protocols:" << querySet->dwNumberOfProtocols; - qDebug() << "protocols:" << querySet->lpafpProtocols; - qDebug() << "query string:" << QString::fromUtf16(querySet->lpszQueryString); - qDebug() << "number of cs addresses:" << querySet->dwNumberOfCsAddrs; - qDebug() << "cs addresses:" << querySet->lpcsaBuffer; - qDebug() << "output flags:" << querySet->dwOutputFlags; -#endif - - if (querySet->lpBlob) { -#ifdef BEARER_MANAGEMENT_DEBUG - qDebug() << "blob size:" << querySet->lpBlob->cbSize; - qDebug() << "blob data:" << querySet->lpBlob->pBlobData; -#endif - - DWORD offset = 0; - do { - NLA_BLOB *blob = reinterpret_cast<NLA_BLOB *>(querySet->lpBlob->pBlobData + offset); - DWORD nextOffset = parseBlob(blob, cpPriv); - if (nextOffset == offset) - break; - else - offset = nextOffset; - } while (offset != 0 && offset < querySet->lpBlob->cbSize); - } - - return cpPriv; -} - -void QNlaThread::fetchConfigurations() -{ - QList<QNetworkConfigurationPrivate *> foundConfigurations; - - WSAQUERYSET qsRestrictions; - HANDLE hLookup = 0; - - memset(&qsRestrictions, 0, sizeof(qsRestrictions)); - qsRestrictions.dwSize = sizeof(qsRestrictions); - qsRestrictions.dwNameSpace = NS_NLA; - - int result = WSALookupServiceBegin(&qsRestrictions, LUP_RETURN_ALL | LUP_DEEP, &hLookup); - if (result == SOCKET_ERROR) { - qWarning("%s: WSALookupServiceBegin error %d", __FUNCTION__, WSAGetLastError()); - mutex.lock(); - fetchedConfigurations.clear(); - mutex.unlock(); - } - - char buffer[0x10000]; - while (result == 0) { - DWORD bufferLength = sizeof(buffer); - result = WSALookupServiceNext(hLookup, LUP_RETURN_ALL, - &bufferLength, reinterpret_cast<WSAQUERYSET *>(buffer)); - - if (result == SOCKET_ERROR) { - int error = WSAGetLastError(); - - if (error == WSA_E_NO_MORE) - break; - - if (error == WSAEFAULT) { - qDebug() << "buffer not big enough" << bufferLength; - break; - } - - qWarning("WSALookupServiceNext error %d", WSAGetLastError()); - break; - } - - QNetworkConfigurationPrivate *cpPriv = - parseQuerySet(reinterpret_cast<WSAQUERYSET *>(buffer)); - - foundConfigurations.append(cpPriv); - } - - if (hLookup) { - result = WSALookupServiceEnd(hLookup); - if (result == SOCKET_ERROR) { - qWarning("WSALookupServiceEnd error %d", WSAGetLastError()); - } - } - - updateConfigurations(foundConfigurations); -} - -QNlaEngine::QNlaEngine(QObject *parent) -: QNetworkSessionEngine(parent), nlaThread(0) -{ - nlaThread = new QNlaThread(this); - connect(nlaThread, SIGNAL(networksChanged()), - this, SIGNAL(configurationsChanged())); - nlaThread->start(); - - qApp->processEvents(QEventLoop::ExcludeUserInputEvents); -} - -QNlaEngine::~QNlaEngine() -{ - delete nlaThread; -} - -QList<QNetworkConfigurationPrivate *> QNlaEngine::getConfigurations(bool *ok) -{ - if (ok) - *ok = true; - - return nlaThread->getConfigurations(); -} - -QString QNlaEngine::getInterfaceFromId(const QString &id) -{ - return configurationInterface.value(id.toUInt()); -} - -bool QNlaEngine::hasIdentifier(const QString &id) -{ - if (configurationInterface.contains(id.toUInt())) - return true; - - foreach (QNetworkConfigurationPrivate *cpPriv, nlaThread->getConfigurations()) { - if (cpPriv->id == id) - return true; - } - - return false; -} - -QString QNlaEngine::bearerName(const QString &id) -{ - QString interface = getInterfaceFromId(id); - - if (interface.isEmpty()) - return QString(); - - return qGetInterfaceType(interface); -} - -void QNlaEngine::connectToId(const QString &id) -{ - emit connectionError(id, OperationNotSupported); -} - -void QNlaEngine::disconnectFromId(const QString &id) -{ - emit connectionError(id, OperationNotSupported); -} - -void QNlaEngine::requestUpdate() -{ - nlaThread->forceUpdate(); -} - -QNlaEngine *QNlaEngine::instance() -{ - return nlaEngine(); -} - -#include "qnlaengine_win.moc" -#include "moc_qnlaengine_win_p.cpp" -QT_END_NAMESPACE - - - diff --git a/src/network/bearer/qnlaengine_win_p.h b/src/network/bearer/qnlaengine_win_p.h deleted file mode 100644 index 1e7d051..0000000 --- a/src/network/bearer/qnlaengine_win_p.h +++ /dev/null @@ -1,104 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtNetwork module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QNLAENGINE_P_H -#define QNLAENGINE_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include "qnetworksessionengine_p.h" - -#include <QMap> - -QT_BEGIN_NAMESPACE - -class QNetworkConfigurationPrivate; -class QNlaThread; - -class QWindowsSockInit -{ -public: - QWindowsSockInit(); - ~QWindowsSockInit(); - int version; -}; - -class QNlaEngine : public QNetworkSessionEngine -{ - Q_OBJECT - - friend class QNlaThread; - -public: - QNlaEngine(QObject *parent = 0); - ~QNlaEngine(); - - QList<QNetworkConfigurationPrivate *> getConfigurations(bool *ok = 0); - QString getInterfaceFromId(const QString &id); - bool hasIdentifier(const QString &id); - - QString bearerName(const QString &id); - - void connectToId(const QString &id); - void disconnectFromId(const QString &id); - - void requestUpdate(); - - static QNlaEngine *instance(); - -private: - QWindowsSockInit winSock; - QNlaThread *nlaThread; - QMap<uint, QString> configurationInterface; -}; - -QT_END_NAMESPACE - -#endif |