2007-11-15 03:18:48 +00:00
|
|
|
#ifndef _RS_UPNP_IFACE_H
|
|
|
|
#define _RS_UPNP_IFACE_H
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
/* platform independent networking... */
|
|
|
|
#include "pqi/pqinetwork.h"
|
2008-01-25 07:25:05 +00:00
|
|
|
#include "pqi/p3upnpmgr.h"
|
2007-11-15 03:18:48 +00:00
|
|
|
|
|
|
|
class upnpentry
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
std::string name;
|
|
|
|
std::string id;
|
|
|
|
struct sockaddr_in addr;
|
|
|
|
unsigned int flags;
|
|
|
|
int status;
|
|
|
|
int lastTs;
|
|
|
|
};
|
|
|
|
|
|
|
|
class upnpforward
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
std::string name;
|
|
|
|
unsigned int flags;
|
|
|
|
struct sockaddr_in iaddr;
|
|
|
|
struct sockaddr_in eaddr;
|
|
|
|
int status;
|
|
|
|
int lastTs;
|
|
|
|
};
|
|
|
|
|
2008-01-25 07:25:05 +00:00
|
|
|
|
2007-11-15 03:18:48 +00:00
|
|
|
#define RS_UPNP_S_UNINITIALISED 0
|
|
|
|
#define RS_UPNP_S_UNAVAILABLE 1
|
|
|
|
#define RS_UPNP_S_READY 2
|
|
|
|
#define RS_UPNP_S_TCP_FAILED 3
|
|
|
|
#define RS_UPNP_S_UDP_FAILED 4
|
|
|
|
#define RS_UPNP_S_ACTIVE 5
|
|
|
|
|
|
|
|
class uPnPConfigData;
|
|
|
|
|
2008-01-25 07:25:05 +00:00
|
|
|
class upnphandler: public p3UpnpMgr
|
2007-11-15 03:18:48 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2008-01-25 07:25:05 +00:00
|
|
|
upnphandler();
|
|
|
|
virtual ~upnphandler();
|
2007-11-15 03:18:48 +00:00
|
|
|
|
2008-01-25 07:25:05 +00:00
|
|
|
/* External Interface */
|
|
|
|
virtual void enableUPnP(bool active);
|
|
|
|
virtual void shutdownUPnP();
|
2007-11-15 03:18:48 +00:00
|
|
|
|
2008-01-25 07:25:05 +00:00
|
|
|
virtual bool getUPnPEnabled();
|
|
|
|
virtual bool getUPnPActive();
|
2007-11-15 03:18:48 +00:00
|
|
|
|
2008-01-25 07:25:05 +00:00
|
|
|
virtual void setInternalPort(unsigned short iport_in);
|
|
|
|
virtual void setExternalPort(unsigned short eport_in);
|
|
|
|
virtual bool getInternalAddress(struct sockaddr_in &addr);
|
|
|
|
virtual bool getExternalAddress(struct sockaddr_in &addr);
|
2007-11-15 03:18:48 +00:00
|
|
|
|
|
|
|
/* must run thread */
|
|
|
|
virtual void run();
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
bool initUPnPState();
|
|
|
|
void checkUPnPState();
|
|
|
|
bool printUPnPState();
|
2008-02-27 15:43:02 +00:00
|
|
|
|
|
|
|
bool checkUPnPActive();
|
2007-11-15 03:18:48 +00:00
|
|
|
bool updateUPnP();
|
|
|
|
|
|
|
|
|
|
|
|
/* Mutex for data below */
|
|
|
|
RsMutex dataMtx;
|
|
|
|
|
|
|
|
/* requested from rs */
|
|
|
|
bool toShutdown; /* if set shuts down the thread. */
|
|
|
|
|
|
|
|
bool toEnable; /* overall on/off switch */
|
|
|
|
bool toStart; /* if set start forwarding */
|
|
|
|
bool toStop; /* if set stop forwarding */
|
|
|
|
|
2008-01-25 07:25:05 +00:00
|
|
|
unsigned short iport;
|
2007-11-15 03:18:48 +00:00
|
|
|
unsigned short eport; /* config */
|
|
|
|
unsigned short eport_curr; /* current forwarded */
|
|
|
|
|
|
|
|
/* info from upnp */
|
|
|
|
unsigned int upnpState;
|
|
|
|
uPnPConfigData *upnpConfig;
|
|
|
|
|
|
|
|
struct sockaddr_in upnp_iaddr;
|
|
|
|
struct sockaddr_in upnp_eaddr;
|
|
|
|
|
|
|
|
/* active port forwarding */
|
|
|
|
std::list<upnpforward> activeForwards;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* _RS_UPNP_IFACE_H */
|