2010-02-16 17:25:58 -05:00
|
|
|
//Linux only...
|
|
|
|
#if !defined(WINDOWS_SYS) && !defined(__APPLE__)
|
2009-10-29 20:46:36 -04:00
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
#ifndef _RS_UPNP_IFACE_H
|
|
|
|
#define _RS_UPNP_IFACE_H
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
/* platform independent networking... */
|
|
|
|
#include "pqi/pqinetwork.h"
|
2008-08-16 11:02:24 -04:00
|
|
|
#include "pqi/pqiassist.h"
|
|
|
|
|
|
|
|
#include "util/rsthreads.h"
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2010-07-04 06:42:17 -04:00
|
|
|
#include <upnp/upnp.h>
|
2009-10-29 20:33:40 -04:00
|
|
|
#include "upnp/UPnPBase.h"
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
#define RS_UPNP_S_UNINITIALISED 0
|
|
|
|
#define RS_UPNP_S_UNAVAILABLE 1
|
|
|
|
#define RS_UPNP_S_READY 2
|
2009-10-29 20:42:31 -04:00
|
|
|
#define RS_UPNP_S_TCP_AND_FAILED 3
|
|
|
|
//#define RS_UPNP_S_UDP_FAILED 4
|
2007-11-14 22:18:48 -05:00
|
|
|
#define RS_UPNP_S_ACTIVE 5
|
|
|
|
|
2008-08-16 11:02:24 -04:00
|
|
|
class upnphandler: public pqiNetAssistFirewall
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2009-10-29 20:33:40 -04:00
|
|
|
upnphandler();
|
|
|
|
virtual ~upnphandler();
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-10-29 20:33:40 -04:00
|
|
|
/* External Interface (pqiNetAssistFirewall) */
|
|
|
|
virtual void enable(bool active);
|
|
|
|
virtual void shutdown();
|
|
|
|
virtual void restart();
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-10-29 20:33:40 -04:00
|
|
|
virtual bool getEnabled();
|
|
|
|
virtual bool getActive();
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-10-29 20:33:40 -04: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-14 22:18:48 -05:00
|
|
|
|
2009-10-29 20:33:40 -04:00
|
|
|
/* Public functions - for background thread operation,
|
|
|
|
* but effectively private from rest of RS, as in derived class
|
|
|
|
*/
|
|
|
|
unsigned int upnpState;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-10-29 20:33:40 -04:00
|
|
|
bool start_upnp();
|
|
|
|
bool shutdown_upnp();
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-10-29 20:33:40 -04:00
|
|
|
bool initUPnPState();
|
|
|
|
|
|
|
|
/* Mutex for data below */
|
|
|
|
RsMutex dataMtx;
|
2008-02-27 10:43:02 -05:00
|
|
|
|
2008-04-09 08:54:15 -04:00
|
|
|
private:
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-10-29 20:33:40 -04:00
|
|
|
CUPnPControlPoint *cUPnPControlPoint;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-10-29 20:33:40 -04:00
|
|
|
bool background_setup_upnp(bool, bool);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
|
2009-10-29 20:33:40 -04:00
|
|
|
bool toEnable; /* overall on/off switch */
|
|
|
|
bool toStart; /* if set start forwarding */
|
|
|
|
bool toStop; /* if set stop forwarding */
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-10-29 20:33:40 -04:00
|
|
|
unsigned short iport;
|
|
|
|
unsigned short eport; /* config */
|
|
|
|
unsigned short eport_curr; /* current forwarded */
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-10-29 20:33:40 -04:00
|
|
|
/* info from upnp */
|
|
|
|
struct sockaddr_in upnp_iaddr;
|
|
|
|
struct sockaddr_in upnp_eaddr;
|
2007-11-14 22:18:48 -05:00
|
|
|
};
|
|
|
|
|
2009-10-29 20:33:40 -04:00
|
|
|
/* info from upnp */
|
|
|
|
int CtrlPointCallbackEventHandler(Upnp_EventType ,void* , void*);
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
#endif /* _RS_UPNP_IFACE_H */
|
2009-10-29 20:46:36 -04:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-02-16 17:25:58 -05:00
|
|
|
#if defined(WINDOWS_SYS) || defined(__APPLE__)
|
2009-10-29 20:46:36 -04:00
|
|
|
|
|
|
|
//windows implementation
|
|
|
|
#ifndef _RS_UPNP_IFACE_H
|
|
|
|
#define _RS_UPNP_IFACE_H
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
/* platform independent networking... */
|
|
|
|
#include "pqi/pqinetwork.h"
|
|
|
|
#include "pqi/pqiassist.h"
|
|
|
|
|
|
|
|
#include "util/rsthreads.h"
|
|
|
|
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#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;
|
|
|
|
|
|
|
|
class upnphandler: public pqiNetAssistFirewall
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
upnphandler();
|
|
|
|
virtual ~upnphandler();
|
|
|
|
|
|
|
|
/* External Interface (pqiNetAssistFirewall) */
|
|
|
|
virtual void enable(bool active);
|
|
|
|
virtual void shutdown();
|
|
|
|
virtual void restart();
|
|
|
|
|
|
|
|
virtual bool getEnabled();
|
|
|
|
virtual bool getActive();
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
/* Public functions - for background thread operation,
|
|
|
|
* but effectively private from rest of RS, as in derived class
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool start_upnp();
|
|
|
|
bool shutdown_upnp();
|
|
|
|
|
|
|
|
bool initUPnPState();
|
|
|
|
bool printUPnPState();
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
bool background_setup_upnp(bool, bool);
|
|
|
|
bool checkUPnPActive();
|
|
|
|
|
|
|
|
/* Mutex for data below */
|
|
|
|
RsMutex dataMtx;
|
|
|
|
|
|
|
|
bool toEnable; /* overall on/off switch */
|
|
|
|
bool toStart; /* if set start forwarding */
|
|
|
|
bool toStop; /* if set stop forwarding */
|
|
|
|
|
|
|
|
unsigned short iport;
|
|
|
|
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 */
|
|
|
|
#endif
|