UPnP classes usage

The main class is the UPnP; an example of a minimal usage is the following:

UPnP *upnp=new UPnP(NULL, 61495, 61496, TRUE, TRUE);

if(!upnp)
    return OpStatus::ERR_NO_MEMORY;

RETURN_IF_ERROR(upnp->StartUPnPDiscovery());

return OpStatus::OK;

In this case you are unable to know if the UPnP process has been terminated successfully, because it is done asynchronously, via several callbacks. In any case, you should not rely on the fact that if UPnP is not enabled, will not be enabled during the session, because it is possible that the user will power on the router only after starting Opera. As a general rule, the UPnP object must live during the whole session, so that it can be notified about every change that can happens in the network topology.

The mappings enabled in the router are static, so they can lasts through several sessions of Opera Unite, even years. This can be seen as a little security problem, because the port can be opened even if Opera Unite has been closed (and if the client usually change the IP address, the mappings can multiply), but this is also the behavior of Skype. According to the UPnP specifications, the support for dynamic mappings (where you can ask to open a port only for a limited amount of time) is limited, but we can think about adding it.

In a real case scenario, you probably want to receive notifications about ports opening; to do so, you neeed to call the AddListener() method, supplying a UPnPListener.
Remember to call RemoveListener() before destroying the listener.