aboutsummaryrefslogtreecommitdiffstats
path: root/src/modules/upnp
diff options
context:
space:
mode:
authorGravatar Fabio Bas2008-08-15 14:02:42 +0000
committerGravatar Fabio Bas2008-08-15 14:02:42 +0000
commitefaced6c6c3f26592cbc4643e6f48b5523cd39fb (patch)
treeafe05ef1def717805f5dd773ed2713c3e92f652e /src/modules/upnp
parent(quite strange) compilation fix for linux (diff)
downloadKVIrc-efaced6c6c3f26592cbc4643e6f48b5523cd39fb.tar.gz
KVIrc-efaced6c6c3f26592cbc4643e6f48b5523cd39fb.tar.bz2
KVIrc-efaced6c6c3f26592cbc4643e6f48b5523cd39fb.zip
more work on upnp, quite working now (please test)
fixed inet stuff compilation, added proper rule to CMakeList.txt git-svn-id: https://svn.kvirc.de/svn/trunk/kvirc@2249 17fca916-40b9-46aa-a4ea-0a15b648b75c
Diffstat (limited to 'src/modules/upnp')
-rw-r--r--src/modules/upnp/igdcontrolpoint.cpp18
-rw-r--r--src/modules/upnp/igdcontrolpoint.h5
-rw-r--r--src/modules/upnp/libkviupnp.cpp109
-rw-r--r--src/modules/upnp/manager.cpp13
-rw-r--r--src/modules/upnp/manager.h5
-rw-r--r--src/modules/upnp/service.cpp32
-rw-r--r--src/modules/upnp/service.h9
-rw-r--r--src/modules/upnp/wanconnectionservice.cpp136
-rw-r--r--src/modules/upnp/wanconnectionservice.h66
9 files changed, 270 insertions, 123 deletions
diff --git a/src/modules/upnp/igdcontrolpoint.cpp b/src/modules/upnp/igdcontrolpoint.cpp
index e782f1370..5c0bb4d42 100644
--- a/src/modules/upnp/igdcontrolpoint.cpp
+++ b/src/modules/upnp/igdcontrolpoint.cpp
@@ -148,6 +148,24 @@ void IgdControlPoint::slotWanQueryFinished(bool error)
}
}
+// Return the external IP address
+void IgdControlPoint::addPortMapping(const QString &protocol, const QString &remoteHost, int externalPort,const QString &internalClient, int internalPort, const QString &description, bool enabled, int leaseDuration)
+{
+ // Do not expose wanConnectionService_;
+ if(m_pWanConnectionService != 0)
+ {
+ m_pWanConnectionService->addPortMapping(protocol, remoteHost, externalPort, internalClient, internalPort, description, enabled, leaseDuration);
+ }
+}
+// Delete a port mapping
+void IgdControlPoint::deletePortMapping(const QString &protocol, const QString &remoteHost, int externalPort)
+{
+ // Do not expose wanConnectionService_;
+ if(m_pWanConnectionService != 0)
+ {
+ m_pWanConnectionService->deletePortMapping(protocol, remoteHost, externalPort);
+ }
+}
} // End of namespace
diff --git a/src/modules/upnp/igdcontrolpoint.h b/src/modules/upnp/igdcontrolpoint.h
index 63932c45d..3d3d9dff8 100644
--- a/src/modules/upnp/igdcontrolpoint.h
+++ b/src/modules/upnp/igdcontrolpoint.h
@@ -70,6 +70,11 @@ public: // public methods
// Return true if a controlable gateway is available
bool isGatewayAvailable();
+ // Add a port mapping
+ void addPortMapping(const QString &protocol, const QString &remoteHost, int externalPort, const QString &internalClient, int internalPort, const QString &description, bool enabled = true, int leaseDuration = 0);
+ // Delete a port mapping
+ void deletePortMapping(const QString &protocol, const QString &remoteHost, int externalPort);
+
private slots:
// The IGD was queried for it's services
void slotDeviceQueried(bool error);
diff --git a/src/modules/upnp/libkviupnp.cpp b/src/modules/upnp/libkviupnp.cpp
index f75bbfb33..8faabb44c 100644
--- a/src/modules/upnp/libkviupnp.cpp
+++ b/src/modules/upnp/libkviupnp.cpp
@@ -25,6 +25,7 @@
#include "kvi_settings.h"
#include "kvi_module.h"
#include "kvi_string.h"
+#include "kvi_netutils.h"
#include "manager.h"
@@ -32,7 +33,24 @@
// Let's be so:)
UPnP::Manager* g_pManager = 0;
-
+/*
+ @doc: upnp.getExternalIpAddress
+ @type:
+ function
+ @title:
+ $upnp.getExternalIpAddress
+ @short:
+ Return the external ip address using UPnP
+ @syntax:
+ <string> $upnp.getExternalIpAddress()
+ @description:
+ During the loading of the UPnP module, KVIrc searches the gateway of your local network. If a gateway is found, KVIrc requests it the external Ip address associated to the router and caches it.[br]
+ Using this function you can get this cached value.[br]
+ Take care that if no gateway have been found or it returned no external Ip address (this can happens if its upstream (wan) link is not connected), this function returns an empty string.[br]
+ It's better to check is a gateway has been found using [fnc]$upnp.isGatewayAvailable[/fnc] before using this function.
+ @seealso:
+ [fnc]$upnp.isGatewayAvailable[/fnc]
+*/
static bool upnp_kvs_fnc_getExternalIpAddress(KviKvsModuleFunctionCall * c)
{
if(g_pManager)
@@ -42,6 +60,21 @@ static bool upnp_kvs_fnc_getExternalIpAddress(KviKvsModuleFunctionCall * c)
return true;
}
+
+/*
+ @doc: upnp.isGatewayAvailable
+ @type:
+ function
+ @title:
+ $upnp.isGatewayAvailable
+ @short:
+ Returns if a UPnP-capable gateway has been found on the local network
+ @syntax:
+ <bool> $upnp.isGatewayAvailable()
+ @description:
+ Returns if a UPnP-capable gateway has been found on the local network.[br]
+ If this function returns false (0), no other command or function from the upnp module will work.
+*/
static bool upnp_kvs_fnc_isGatewayAvailable(KviKvsModuleFunctionCall * c)
{
if (g_pManager)
@@ -51,8 +84,77 @@ static bool upnp_kvs_fnc_isGatewayAvailable(KviKvsModuleFunctionCall * c)
return true;
}
-static bool upnp_kvs_cmd_test(KviKvsModuleCommandCall * c)
+/*
+ @doc: upnp.addPortMapping
+ @type:
+ command
+ @title:
+ upnp.addPortMapping
+ @short:
+ Add a port mapping to gateway using UPnP
+ @syntax:
+ upnp.addPortMapping [-a=<fake address>] <port>
+ @switches:
+ !sw: -a=<fake address> | --fake-address=<fake address>
+ Send the <fake address> as target for the port mapping
+ If this switch is not given, the request will contain the real IP address of the listening
+ interface.[br]
+ @description:
+ Makes a request to the gateway of the local network using UPnP; the request asks the gateway to add an entry in its port mapping table.[br]
+ If the gateway accepts the request, it will forward packets received on <port> on its external (wan) ip address to the host KVIrc is running at, on the same <port>.
+ Depending on vendors, this is called with different names: Port forwarding, SUA, Virtual Server, PAT, ...
+ It's better to check is a gateway has been found using [fnc]$upnp.isGatewayAvailable[/fnc] before using this function.
+ @seealso:
+ [fnc]$upnp.isGatewayAvailable[/fnc], [cmd]upnp.delPortMapping[/cmd]
+*/
+static bool upnp_kvs_cmd_addPortMapping(KviKvsModuleCommandCall * c)
{
+ int iPort;
+ QString szLocalIp;
+ KviKvsVariant * pSw;
+
+ KVSM_PARAMETERS_BEGIN(c)
+ KVSM_PARAMETER("port",KVS_PT_INT,0,iPort)
+ KVSM_PARAMETERS_END(c)
+
+ if(pSw = c->switches()->find('a',"fake-address"))
+ {
+ pSw->asString(szLocalIp);
+ } else {
+ kvi_getLocalHostAddress(szLocalIp);
+ }
+
+ g_pManager->addPortMapping("TCP", "", iPort, szLocalIp, iPort, "KVIrc UPnP module", true, 0);
+ return true;
+}
+
+/*
+ @doc: upnp.delPortMapping
+ @type:
+ command
+ @title:
+ upnp.delPortMapping
+ @short:
+ Delete a port mapping on the gateway using UPnP
+ @syntax:
+ upnp.delPortMapping <port>
+ @description:
+ Makes a request to the gateway of the local network using UPnP; the request asks the gateway to delete an entry in its port mapping table.[br]
+ If the gateway accepts the request, it will stop forward packets received on <port>.
+ It's better to check is a gateway has been found using [fnc]$upnp.isGatewayAvailable[/fnc] before using this function.[br]
+ Of course, such a port mapping have to be added using [cmd]upnp.addPortMapping[/cmd] before it can be deleted.
+ @seealso:
+ [fnc]$upnp.isGatewayAvailable[/fnc], [cmd]upnp.addPortMapping[/cmd]
+*/
+static bool upnp_kvs_cmd_delPortMapping(KviKvsModuleCommandCall * c)
+{
+ int iPort;
+
+ KVSM_PARAMETERS_BEGIN(c)
+ KVSM_PARAMETER("port",KVS_PT_INT,0,iPort)
+ KVSM_PARAMETERS_END(c)
+
+ g_pManager->deletePortMapping("TCP", "", iPort);
return true;
}
@@ -63,7 +165,8 @@ static bool upnp_module_init(KviModule * m)
KVSM_REGISTER_FUNCTION(m,"isGatewayAvailable",upnp_kvs_fnc_isGatewayAvailable);
KVSM_REGISTER_FUNCTION(m,"getExternalIpAddress",upnp_kvs_fnc_getExternalIpAddress);
- KVSM_REGISTER_SIMPLE_COMMAND(m,"test",upnp_kvs_cmd_test);
+ KVSM_REGISTER_SIMPLE_COMMAND(m,"addPortMapping",upnp_kvs_cmd_addPortMapping);
+ KVSM_REGISTER_SIMPLE_COMMAND(m,"delPortMapping",upnp_kvs_cmd_delPortMapping);
return true;
}
diff --git a/src/modules/upnp/manager.cpp b/src/modules/upnp/manager.cpp
index 2684d5f18..0e8ede840 100644
--- a/src/modules/upnp/manager.cpp
+++ b/src/modules/upnp/manager.cpp
@@ -123,7 +123,19 @@ bool Manager::isGatewayAvailable()
return (m_pActiveIgdControlPoint != 0 && m_pActiveIgdControlPoint->isGatewayAvailable());
}
+ // Add a port mapping
+void Manager::addPortMapping(const QString &protocol, const QString &remoteHost, int externalPort, const QString &internalClient, int internalPort, const QString &description, bool enabled, int leaseDuration)
+{
+ if(m_pActiveIgdControlPoint != 0)
+ m_pActiveIgdControlPoint->addPortMapping(protocol, remoteHost, externalPort, internalClient, internalPort, description, enabled, leaseDuration);
+}
+// Delete a port mapping
+void Manager::deletePortMapping(const QString &protocol, const QString &remoteHost, int externalPort)
+{
+ if(m_pActiveIgdControlPoint != 0)
+ m_pActiveIgdControlPoint->deletePortMapping(protocol, remoteHost, externalPort);
+}
// The broadcast failed
void Manager::slotBroadcastTimeout()
@@ -131,6 +143,7 @@ void Manager::slotBroadcastTimeout()
if(!m_bBroadcastFoundIt)
{
qDebug() << "UPnP::Manager: Timeout, no broadcast response received!" << endl;
+
m_bBroadcastFailed = true;
}
}
diff --git a/src/modules/upnp/manager.h b/src/modules/upnp/manager.h
index db3763437..975162824 100644
--- a/src/modules/upnp/manager.h
+++ b/src/modules/upnp/manager.h
@@ -72,6 +72,11 @@ public: // public methods
// Return true if a controlable gateway is available
bool isGatewayAvailable();
+ // Add a port mapping
+ void addPortMapping(const QString &protocol, const QString &remoteHost, int externalPort, const QString &internalClient, int internalPort, const QString &description, bool enabled = true, int leaseDuration = 0);
+ // Delete a port mapping
+ void deletePortMapping(const QString &protocol, const QString &remoteHost, int externalPort);
+
private slots:
// The broadcast failed
void slotBroadcastTimeout();
diff --git a/src/modules/upnp/service.cpp b/src/modules/upnp/service.cpp
index 16dad1100..0d201d06f 100644
--- a/src/modules/upnp/service.cpp
+++ b/src/modules/upnp/service.cpp
@@ -54,6 +54,7 @@ Service::Service(const QString &hostname, int port, const QString &informationUr
, m_szHostname(hostname)
, m_iPort(port)
, m_iPendingRequests(0)
+, m_szBaseXmlPrefix("s")
{
m_pHttp = new QHttp(hostname, port);
connect(m_pHttp, SIGNAL( requestFinished(int,bool) ) , this, SLOT( slotRequestFinished(int,bool) ) );
@@ -71,6 +72,7 @@ Service::Service(const ServiceParameters &params)
, m_szServiceType(params.serviceType)
, m_szHostname(params.hostname)
, m_iPort(params.port)
+, m_szBaseXmlPrefix("s")
{
m_pHttp = new QHttp(params.hostname, params.port);
connect(m_pHttp, SIGNAL( requestFinished(int,bool) ) , this, SLOT( slotRequestFinished(int,bool) ) );
@@ -92,23 +94,23 @@ Service::~Service()
// Makes a UPnP action request
// TODO: rename to callMethod / callSoapMethod
-int Service::callAction(const QString &actionName)
+int Service::callAction(const QString &actionName, const QString &prefix)
{
- return callActionInternal(actionName, 0);
+ return callActionInternal(actionName, 0, prefix);
}
// Makes a UPnP action request
-int Service::callAction(const QString &actionName, const QMap<QString,QString> &arguments)
+int Service::callAction(const QString &actionName, const QMap<QString,QString> &arguments, const QString &prefix)
{
- return callActionInternal(actionName, &arguments);
+ return callActionInternal(actionName, &arguments, prefix);
}
// Makes a UPnP action request (keeps pointers from the external interface)
-int Service::callActionInternal(const QString &actionName, const QMap<QString,QString> *arguments)
+int Service::callActionInternal(const QString &actionName, const QMap<QString,QString> *arguments, const QString &prefix)
{
qDebug() << "UPnP::Service: calling remote procedure '" << actionName << "'." << endl;
@@ -127,10 +129,10 @@ int Service::callActionInternal(const QString &actionName, const QMap<QString,QS
// this router wants us to use servicetype in the following requests
QString soapMessage = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n"
- "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\""
- " s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\n"
- " <s:Body>\n"
- " <u:" + actionName + " xmlns:u=\"" + m_szServiceType + "\">\n";
+ "<" + m_szBaseXmlPrefix + ":Envelope xmlns:" + m_szBaseXmlPrefix + "=\"http://schemas.xmlsoap.org/soap/envelope/\""
+ " " + m_szBaseXmlPrefix + ":encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\n"
+ " <" + m_szBaseXmlPrefix + ":Body>\n"
+ " <" + prefix + ":" + actionName + " xmlns:" + prefix + "=\"" + m_szServiceType + "\">\n";
// Do we have any arguments?
if(arguments != 0)
@@ -145,7 +147,7 @@ int Service::callActionInternal(const QString &actionName, const QMap<QString,QS
}
// Add the closing tags
- soapMessage += " </u:" + actionName + ">\n </s:Body>\n</s:Envelope>\n";
+ soapMessage += " </" + prefix + ":" + actionName + ">\n </" + m_szBaseXmlPrefix + ":Body>\n</" + m_szBaseXmlPrefix + ":Envelope>\n";
// Get an utf8 encoding string
QByteArray content = soapMessage.toUtf8().data();
@@ -260,12 +262,12 @@ void Service::slotRequestFinished(int id, bool error)
{
baseNamespace.truncate(cutAt);
qDebug() << "Device is using " << baseNamespace << " as xml namespace" << endl;
- } else {
- baseNamespace = "s";
+ m_szBaseXmlPrefix = baseNamespace;
}
}
+
// Determine how to process the data
- if(xml.namedItem(baseNamespace + ":Envelope").isNull())
+ if(xml.namedItem(m_szBaseXmlPrefix + ":Envelope").isNull())
{
qDebug() << "UPnP::Service: Plain XML detected, calling gotInformationResponse()." << endl;
// No SOAP envelope found, this is a normal response to callService()
@@ -273,9 +275,9 @@ void Service::slotRequestFinished(int id, bool error)
} else {
qDebug() << xml.toString() << endl;
// Got a SOAP message response to callAction()
- QDomNode resultNode = XmlFunctions::getNode(xml, "/" + baseNamespace + ":Envelope/" + baseNamespace + ":Body").firstChild();
+ QDomNode resultNode = XmlFunctions::getNode(xml, "/" + m_szBaseXmlPrefix + ":Envelope/" + m_szBaseXmlPrefix + ":Body").firstChild();
- error = (resultNode.nodeName() == baseNamespace + ":Fault");
+ error = (resultNode.nodeName() == m_szBaseXmlPrefix + ":Fault");
if(! error)
{
diff --git a/src/modules/upnp/service.h b/src/modules/upnp/service.h
index 1cb728a49..ed8a3ea08 100644
--- a/src/modules/upnp/service.h
+++ b/src/modules/upnp/service.h
@@ -85,9 +85,9 @@ public: // public methods
protected: // Protected methods
// Makes a UPnP action request
- int callAction(const QString &actionName);
+ int callAction(const QString &actionName, const QString &prefix);
// Makes a UPnP action request
- int callAction(const QString &actionName, const QMap<QString,QString> &arguments);
+ int callAction(const QString &actionName, const QMap<QString,QString> &arguments, const QString &prefix);
// Makes a UPnP service request
int callInformationUrl();
@@ -104,7 +104,7 @@ private slots:
private:
// Makes a UPnP action request (keeps pointers from the external interface)
- int callActionInternal(const QString &actionName, const QMap<QString,QString> *arguments);
+ int callActionInternal(const QString &actionName, const QMap<QString,QString> *arguments, const QString &prefix);
private:
// The URL to control the service
@@ -119,7 +119,8 @@ private:
QString m_szServiceId;
// The Type of the service
QString m_szServiceType;
-
+ // The xml prefix used by the router
+ QString m_szBaseXmlPrefix;
// hostname
QString m_szHostname;
//port
diff --git a/src/modules/upnp/wanconnectionservice.cpp b/src/modules/upnp/wanconnectionservice.cpp
index fddbde34c..cb21350b8 100644
--- a/src/modules/upnp/wanconnectionservice.cpp
+++ b/src/modules/upnp/wanconnectionservice.cpp
@@ -39,8 +39,8 @@ namespace UPnP
// The constructor
WanConnectionService::WanConnectionService(const ServiceParameters &params)
- : Service(params)
- , m_bNatEnabled(false)
+: Service(params)
+, m_bNatEnabled(false)
{
}
@@ -56,20 +56,20 @@ WanConnectionService::~WanConnectionService()
// Add a port mapping
void WanConnectionService::addPortMapping(const QString &protocol, const QString &remoteHost, int externalPort,
- const QString &internalClient, int internalPort, const QString &description,
- bool enabled, int leaseDuration)
+ const QString &internalClient, int internalPort, const QString &description,
+ bool enabled, int leaseDuration)
{
- // TODO: this still needs to be tested
- QMap<QString,QString> arguments;
- arguments["NewProtocol"] = protocol;
- arguments["NewRemoteHost"] = remoteHost;
- arguments["NewExternalPort"] = QString::number(externalPort);
- arguments["NewInternalClient"] = internalClient;
- arguments["NewInternalPort"] = QString::number(internalPort);
- arguments["NewPortMappingDescription"] = description;
- arguments["NewEnabled"] = QString::number(enabled ? 1 : 0);
- arguments["NewLeaseDuration"] = QString::number(leaseDuration);
- callAction("AddPortMapping", arguments);
+ // TODO: this still needs to be tested
+ QMap<QString,QString> arguments;
+ arguments["NewProtocol"] = protocol;
+ arguments["NewRemoteHost"] = remoteHost;
+ arguments["NewExternalPort"] = QString::number(externalPort);
+ arguments["NewInternalClient"] = internalClient;
+ arguments["NewInternalPort"] = QString::number(internalPort);
+ arguments["NewPortMappingDescription"] = description;
+ arguments["NewEnabled"] = QString::number(enabled ? 1 : 0);
+ arguments["NewLeaseDuration"] = QString::number(leaseDuration);
+ callAction("AddPortMapping", arguments, "m");
}
@@ -77,12 +77,12 @@ void WanConnectionService::addPortMapping(const QString &protocol, const QString
// Delete a port mapping
void WanConnectionService::deletePortMapping(const QString &protocol, const QString &remoteHost, int externalPort)
{
- // TODO: this still needs to be tested
- QMap<QString,QString> arguments;
- arguments["NewProtocol"] = protocol;
- arguments["NewRemoteHost"] = remoteHost;
- arguments["NewExternalPort"] = QString::number(externalPort);
- callAction("DeletePortMapping", arguments);
+ // TODO: this still needs to be tested
+ QMap<QString,QString> arguments;
+ arguments["NewProtocol"] = protocol;
+ arguments["NewRemoteHost"] = remoteHost;
+ arguments["NewExternalPort"] = QString::number(externalPort);
+ callAction("DeletePortMapping", arguments, "m");
}
@@ -90,7 +90,7 @@ void WanConnectionService::deletePortMapping(const QString &protocol, const QStr
// Return the external IP address
QString WanConnectionService::getExternalIpAddress() const
{
- return m_szExternalIpAddress;
+ return m_szExternalIpAddress;
}
@@ -98,7 +98,7 @@ QString WanConnectionService::getExternalIpAddress() const
// Return true if NAT is enabled
bool WanConnectionService::getNatEnabled() const
{
- return m_bNatEnabled;
+ return m_bNatEnabled;
}
@@ -106,7 +106,7 @@ bool WanConnectionService::getNatEnabled() const
// Return the port mappings
const KviPointerList<PortMapping>& WanConnectionService::getPortMappings() const
{
- return m_lPortMappings;
+ return m_lPortMappings;
}
@@ -114,51 +114,51 @@ const KviPointerList<PortMapping>& WanConnectionService::getPortMappings() const
// The control point received a response to callAction()
void WanConnectionService::gotActionResponse(const QString &responseType, const QMap<QString,QString> &resultValues)
{
- qDebug() << "UPnP::WanConnectionService: Parsing action response:"
- << " type='" << responseType << "'." << endl;
+ qDebug() << "UPnP::WanConnectionService: Parsing action response:"
+ << " type='" << responseType << "'." << endl;
- // Check the message type
- if(responseType == "GetExternalIPAddressResponse")
- {
- // Get the external IP address from the response
- m_szExternalIpAddress = resultValues["NewExternalIPAddress"];
+ // Check the message type
+ if(responseType == "GetExternalIPAddressResponse")
+ {
+ // Get the external IP address from the response
+ m_szExternalIpAddress = resultValues["NewExternalIPAddress"];
- qDebug() << "UPnP::WanConnectionService: externalIp='" << m_szExternalIpAddress << "'." << endl;
- }
- else if(responseType == "GetNATRSIPStatusResponse")
- {
- // Get the nat status from the response
- m_bNatEnabled = (resultValues["NewNATEnabled"] == "1");
+ qDebug() << "UPnP::WanConnectionService: externalIp='" << m_szExternalIpAddress << "'." << endl;
+ }
+ else if(responseType == "GetNATRSIPStatusResponse")
+ {
+ // Get the nat status from the response
+ m_bNatEnabled = (resultValues["NewNATEnabled"] == "1");
- qDebug() << "UPnP::WanConnectionService: natEnabled=" << m_bNatEnabled << "." << endl;
- }
- else if(responseType == "GetGenericPortMappingEntryResponse")
- {
- // Find a place to store the data
- PortMapping *map = new PortMapping;
+ qDebug() << "UPnP::WanConnectionService: natEnabled=" << m_bNatEnabled << "." << endl;
+ }
+ else if(responseType == "GetGenericPortMappingEntryResponse" || responseType == "AddPortMappingResponse")
+ {
+ // Find a place to store the data
+ PortMapping *map = new PortMapping;
- // Get the port mapping data from the response
- map->enabled = (resultValues["NewEnabled"] == "1");
- map->externalPort = resultValues["NewExternalPort"].toInt();
- map->internalClient = resultValues["NewInternalClient"];
- map->internalPort = resultValues["NewInternalPort"].toInt();
- map->leaseDuration = resultValues["NewLeaseDuration"].toInt();
- map->description = resultValues["NewPortMappingDescription"];
- map->protocol = resultValues["NewProtocol"];
- map->remoteHost = resultValues["NewRemoteHost"];
+ // Get the port mapping data from the response
+ map->enabled = (resultValues["NewEnabled"] == "1");
+ map->externalPort = resultValues["NewExternalPort"].toInt();
+ map->internalClient = resultValues["NewInternalClient"];
+ map->internalPort = resultValues["NewInternalPort"].toInt();
+ map->leaseDuration = resultValues["NewLeaseDuration"].toInt();
+ map->description = resultValues["NewPortMappingDescription"];
+ map->protocol = resultValues["NewProtocol"];
+ map->remoteHost = resultValues["NewRemoteHost"];
- // Register the mapping
- m_lPortMappings.append(map);
+ // Register the mapping
+ m_lPortMappings.append(map);
- qDebug() << "UPnP::WanConnectionService - Got mapping: " << map->protocol << " " << map->remoteHost << ":" << map->externalPort
- << " to " << map->internalClient << ":" << map->internalPort
- << " max " << map->leaseDuration << "s '" << map->description << "' " << (map->enabled ? "enabled" : "disabled") << endl;
- }
- else
- {
- qDebug() << "UPnP::WanConnectionService - Unexpected response type"
- << " '" << responseType << "' encountered." << endl;
- }
+ qDebug() << "UPnP::WanConnectionService - Got mapping: " << map->protocol << " " << map->remoteHost << ":" << map->externalPort
+ << " to " << map->internalClient << ":" << map->internalPort
+ << " max " << map->leaseDuration << "s '" << map->description << "' " << (map->enabled ? "enabled" : "disabled") << endl;
+ }
+ else
+ {
+ qDebug() << "UPnP::WanConnectionService - Unexpected response type"
+ << " '" << responseType << "' encountered." << endl;
+ }
}
@@ -166,7 +166,7 @@ void WanConnectionService::gotActionResponse(const QString &responseType, const
// Query for the external IP address
void WanConnectionService::queryExternalIpAddress()
{
- callAction("GetExternalIPAddress");
+ callAction("GetExternalIPAddress", "u");
}
@@ -174,7 +174,7 @@ void WanConnectionService::queryExternalIpAddress()
// Query for the Nat status
void WanConnectionService::queryNatEnabled()
{
- callAction("GetNATRSIPStatus");
+ callAction("GetNATRSIPStatus", "u");
}
@@ -182,9 +182,9 @@ void WanConnectionService::queryNatEnabled()
// Query for a port mapping entry
void WanConnectionService::queryPortMappingEntry(int index)
{
- QMap<QString,QString> arguments;
- arguments["NewPortMappingIndex"] = QString::number(index);
- callAction("GetGenericPortMappingEntry", arguments);
+ QMap<QString,QString> arguments;
+ arguments["NewPortMappingIndex"] = QString::number(index);
+ callAction("GetGenericPortMappingEntry", arguments, "m");
}
diff --git a/src/modules/upnp/wanconnectionservice.h b/src/modules/upnp/wanconnectionservice.h
index db0fbf382..1e0855c2e 100644
--- a/src/modules/upnp/wanconnectionservice.h
+++ b/src/modules/upnp/wanconnectionservice.h
@@ -64,48 +64,48 @@ struct PortMapping
*/
class WanConnectionService : public Service
{
- public: // public methods
+public: // public methods
- // The constructor
- WanConnectionService(const ServiceParameters &params);
- // The destructor
- virtual ~WanConnectionService();
+ // The constructor
+ WanConnectionService(const ServiceParameters &params);
+ // The destructor
+ virtual ~WanConnectionService();
- // Add a port mapping
- void addPortMapping(const QString &protocol, const QString &remoteHost, int externalPort,
- const QString &internalClient, int internalPort, const QString &description,
- bool enabled = true, int leaseDuration = 0);
- // Delete a port mapping
- void deletePortMapping(const QString &protocol, const QString &remoteHost, int externalPort);
+ // Add a port mapping
+ void addPortMapping(const QString &protocol, const QString &remoteHost, int externalPort,
+ const QString &internalClient, int internalPort, const QString &description,
+ bool enabled = true, int leaseDuration = 0);
+ // Delete a port mapping
+ void deletePortMapping(const QString &protocol, const QString &remoteHost, int externalPort);
- // Return the external IP address
- QString getExternalIpAddress() const;
- // Return true if NAT is enabled
- bool getNatEnabled() const;
- // Return the port mappings
- const KviPointerList<PortMapping>& getPortMappings() const;
+ // Return the external IP address
+ QString getExternalIpAddress() const;
+ // Return true if NAT is enabled
+ bool getNatEnabled() const;
+ // Return the port mappings
+ const KviPointerList<PortMapping>& getPortMappings() const;
- // Query for the external IP address
- void queryExternalIpAddress();
- // Query for the Nat status
- void queryNatEnabled();
- // Query for a port mapping entry
- void queryPortMappingEntry(int index);
+ // Query for the external IP address
+ void queryExternalIpAddress();
+ // Query for the Nat status
+ void queryNatEnabled();
+ // Query for a port mapping entry
+ void queryPortMappingEntry(int index);
- protected: // protected methods
+protected: // protected methods
- // The control point received a response to callAction()
- virtual void gotActionResponse(const QString &responseType, const QMap<QString,QString> &resultValues);
+ // The control point received a response to callAction()
+ virtual void gotActionResponse(const QString &responseType, const QMap<QString,QString> &resultValues);
- private: // private attributes
- // The external IP address
- QString m_szExternalIpAddress;
- // True if NAT is enabled
- bool m_bNatEnabled;
- // The current port mappings
- KviPointerList<PortMapping> m_lPortMappings;
+private: // private attributes
+ // The external IP address
+ QString m_szExternalIpAddress;
+ // True if NAT is enabled
+ bool m_bNatEnabled;
+ // The current port mappings
+ KviPointerList<PortMapping> m_lPortMappings;
};
}