aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar Fabio Bas2008-08-15 14:53:11 +0000
committerGravatar Fabio Bas2008-08-15 14:53:11 +0000
commitebaaef894304ea8e729f90d0e1a299e976f82263 (patch)
tree8700f3da70865bdde6eae3609e30e048854c2aed /src
parentrenamed ukrainian po files (Ukraine is ua, not uk) (diff)
downloadKVIrc-ebaaef894304ea8e729f90d0e1a299e976f82263.tar.gz
KVIrc-ebaaef894304ea8e729f90d0e1a299e976f82263.tar.bz2
KVIrc-ebaaef894304ea8e729f90d0e1a299e976f82263.zip
even more fixes to upnp module (added refresh command, forced it not to unload if a gateway has been found)
git-svn-id: https://svn.kvirc.de/svn/trunk/kvirc@2252 17fca916-40b9-46aa-a4ea-0a15b648b75c
Diffstat (limited to 'src')
-rw-r--r--src/modules/upnp/libkviupnp.cpp43
-rw-r--r--src/modules/upnp/wanconnectionservice.cpp2
2 files changed, 40 insertions, 5 deletions
diff --git a/src/modules/upnp/libkviupnp.cpp b/src/modules/upnp/libkviupnp.cpp
index 8faabb44c..74bcedfbb 100644
--- a/src/modules/upnp/libkviupnp.cpp
+++ b/src/modules/upnp/libkviupnp.cpp
@@ -44,7 +44,7 @@ UPnP::Manager* g_pManager = 0;
@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]
+ During the loading of the UPnP module (and during a [cmd]upnp.refresh[/cmd]), 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.
@@ -158,15 +158,46 @@ static bool upnp_kvs_cmd_delPortMapping(KviKvsModuleCommandCall * c)
return true;
}
+/*
+ @doc: upnp.refresh
+ @type:
+ command
+ @title:
+ upnp.refresh
+ @short:
+ Rescan the local network for a gateway using UPnP
+ @syntax:
+ upnp.refresh
+ @description:
+ Rescan the local network for a gateway using UPnP.[br]
+ This command is automatically executed when KVIrc loads the upnp module.
+ @seealso:
+ [fnc]$upnp.isGatewayAvailable[/fnc]
+*/
+static bool upnp_kvs_cmd_refresh(KviKvsModuleCommandCall * c)
+{
+ if(g_pManager)
+ delete g_pManager;
+ g_pManager = 0;
+
+ g_pManager = UPnP::Manager::instance();
+
+ return true;
+}
+
static bool upnp_module_init(KviModule * m)
{
+ if(g_pManager)
+ delete g_pManager;
+ g_pManager = 0;
+
g_pManager = UPnP::Manager::instance();
- //p_manager->initialize();
KVSM_REGISTER_FUNCTION(m,"isGatewayAvailable",upnp_kvs_fnc_isGatewayAvailable);
KVSM_REGISTER_FUNCTION(m,"getExternalIpAddress",upnp_kvs_fnc_getExternalIpAddress);
KVSM_REGISTER_SIMPLE_COMMAND(m,"addPortMapping",upnp_kvs_cmd_addPortMapping);
KVSM_REGISTER_SIMPLE_COMMAND(m,"delPortMapping",upnp_kvs_cmd_delPortMapping);
+ KVSM_REGISTER_SIMPLE_COMMAND(m,"refresh",upnp_kvs_cmd_refresh);
return true;
}
@@ -178,13 +209,19 @@ static bool upnp_module_cleanup(KviModule *m)
return true;
}
+static bool upnp_module_can_unload(KviModule *m)
+{
+ // if a gateway is available, don't unload me
+ return !g_pManager->isGatewayAvailable();
+}
+
KVIRC_MODULE(
"UPnP", // module name
"4.0.0", // module version
"Copyright (C) 2008 Fabio Bas (ctrlaltca at gmail dot com),",
"Universal Plug and Play",
upnp_module_init,
- 0,
+ upnp_module_can_unload,
0,
upnp_module_cleanup
)
diff --git a/src/modules/upnp/wanconnectionservice.cpp b/src/modules/upnp/wanconnectionservice.cpp
index cb21350b8..6d46e6d4b 100644
--- a/src/modules/upnp/wanconnectionservice.cpp
+++ b/src/modules/upnp/wanconnectionservice.cpp
@@ -59,7 +59,6 @@ void WanConnectionService::addPortMapping(const QString &protocol, const QString
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;
@@ -77,7 +76,6 @@ 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;