Added the leaseDuration parameter to the addportmapping python binding.

This parameter was already present in the C API but not exposed to the
python module.

For backward compatibility, leaseDuration was made optional with a
default value of 0 (unlimited duration).
This commit is contained in:
Nathan Richard 2019-05-17 15:01:54 +02:00
parent 9132003aa0
commit d457eacec6
1 changed files with 12 additions and 5 deletions

View File

@ -292,7 +292,7 @@ Py_END_ALLOW_THREADS
} }
/* AddPortMapping(externalPort, protocol, internalHost, internalPort, desc, /* AddPortMapping(externalPort, protocol, internalHost, internalPort, desc,
* remoteHost) * remoteHost, leaseDuration)
* protocol is 'UDP' or 'TCP' */ * protocol is 'UDP' or 'TCP' */
static PyObject * static PyObject *
UPnP_addportmapping(UPnPObject *self, PyObject *args) UPnP_addportmapping(UPnPObject *self, PyObject *args)
@ -305,17 +305,24 @@ UPnP_addportmapping(UPnPObject *self, PyObject *args)
const char * host; const char * host;
const char * desc; const char * desc;
const char * remoteHost; const char * remoteHost;
const char * leaseDuration = "0"; int intLeaseDuration = 0;
/*
* According to the IGD spec, the maximum lease is 604800 seconds, ie one week.
* char leaseDuration[7] is big enough to accommodate "604800\0".
* Cf. spec : http://upnp.org/specs/gw/UPnP-gw-WANIPConnection-v2-Service.pdf
*/
char strLeaseDuration[7];
int r; int r;
if (!PyArg_ParseTuple(args, "HssHzz", &ePort, &proto, if (!PyArg_ParseTuple(args, "HssHzz|i", &ePort, &proto,
&host, &iPort, &desc, &remoteHost)) &host, &iPort, &desc, &remoteHost, &intLeaseDuration))
return NULL; return NULL;
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
sprintf(extPort, "%hu", ePort); sprintf(extPort, "%hu", ePort);
sprintf(inPort, "%hu", iPort); sprintf(inPort, "%hu", iPort);
sprintf(strLeaseDuration, "%hu", intLeaseDuration);
r = UPNP_AddPortMapping(self->urls.controlURL, self->data.first.servicetype, r = UPNP_AddPortMapping(self->urls.controlURL, self->data.first.servicetype,
extPort, inPort, host, desc, proto, extPort, inPort, host, desc, proto,
remoteHost, leaseDuration); remoteHost, strLeaseDuration);
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
if(r==UPNPCOMMAND_SUCCESS) if(r==UPNPCOMMAND_SUCCESS)
{ {