Remove miniupnp and add libupnp code

Conflicts:

	libretroshare/src/libretroshare.pro

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1744 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
joss17 2009-10-30 00:33:40 +00:00
parent b6c2b6897a
commit 4fe1bd8801
8 changed files with 2426 additions and 620 deletions

View file

@ -1,24 +1,15 @@
TEMPLATE = lib TEMPLATE = lib
CONFIG += static CONFIG += static release
TARGET = retroshare TARGET = retroshare
CONFIG += release
DEFINES *= MINIUPNPC_VERSION=13
DEFINES -= PQI_USE_XPGP DEFINES -= PQI_USE_XPGP
DEFINES += RS_USE_PGPSSL DEFINES += RS_USE_PGPSSL
UPNPC_DIR = ../../../../miniupnpc-1.3
GPG_ERROR_DIR = ../../../../libgpg-error-1.7
GPGME_DIR = ../../../../gpgme-1.1.8
profiling { profiling {
QMAKE_CXXFLAGS -= -fomit-frame-pointer QMAKE_CXXFLAGS -= -fomit-frame-pointer
QMAKE_CXXFLAGS *= -pg -g -fno-omit-frame-pointer QMAKE_CXXFLAGS *= -pg -g -fno-omit-frame-pointer
} }
DEFINES -= PQI_USE_XPGP
DEFINES *= RS_USE_PGPSSL
################################# Linux ########################################## ################################# Linux ##########################################
debug { debug {
@ -32,23 +23,31 @@ debug {
linux-g++ { linux-g++ {
OBJECTS_DIR = temp/linux-g++/obj OBJECTS_DIR = temp/linux-g++/obj
DESTDIR = lib.linux-g++ DESTDIR = lib
QMAKE_CXXFLAGS *= -Wall QMAKE_CXXFLAGS *= -Wall
QMAKE_CC = g++ QMAKE_CC = g++
SSL_DIR = /usr/include/openssl SSL_DIR = /usr/include/openssl
UPNPC_DIR = ../../../../miniupnpc-1.3 UPNP_DIR = /usr/include/upnp
GPG_ERROR_DIR = ../../../../libgpg-error-1.7 HEADERS += usr/include/gpg-error.h
GPGME_DIR = ../../../../gpgme-1.1.8 HEADERS += usr/include/gpgme.h
INCLUDEPATH += . $${SSL_DIR} $${UPNP_DIR}
CONFIG += version_detail_bash_script CONFIG += version_detail_bash_script
} }
linux-g++-64 { linux-g++-64 {
OBJECTS_DIR = temp/linux-g++-64/obj OBJECTS_DIR = temp/linux-g++-64/obj
DESTDIR = lib.linux-g++-64 DESTDIR = lib
QMAKE_CXXFLAGS *= -Wall QMAKE_CXXFLAGS *= -Wall
QMAKE_CC = g++ QMAKE_CC = g++
SSL_DIR = /usr/include/openssl SSL_DIR = /usr/include/openssl
UPNP_DIR = /usr/include/upnp
HEADERS += usr/include/gpg-error.h
HEADERS += usr/include/gpgme.h
INCLUDEPATH += . $${SSL_DIR} $${UPNP_DIR}
CONFIG += version_detail_bash_script CONFIG += version_detail_bash_script
} }
@ -98,8 +97,6 @@ win32 {
} }
################################### COMMON stuff ################################## ################################### COMMON stuff ##################################
INCLUDEPATH += . $${SSL_DIR} $${UPNPC_DIR} $${GPGME_DIR}/src $${GPG_ERROR_DIR}/src
#DEPENDPATH += . \ #DEPENDPATH += . \
# util \ # util \
# tcponudp \ # tcponudp \
@ -252,8 +249,8 @@ HEADERS += dbase/cachestrapper.h \
tcponudp/udplayer.h \ tcponudp/udplayer.h \
tcponudp/udpsorter.h \ tcponudp/udpsorter.h \
upnp/upnphandler.h \ upnp/upnphandler.h \
upnp/upnputil.h \ upnp/UPnPBase.h \
util/rsdebug.h \ util/rsdebug.h \
util/rsdir.h \ util/rsdir.h \
util/rsnet.h \ util/rsnet.h \
util/rsprint.h \ util/rsprint.h \
@ -287,9 +284,9 @@ SOURCES = \
ft/ftdata.cc \ ft/ftdata.cc \
ft/ftfileprovider.cc \ ft/ftfileprovider.cc \
ft/ftdwlqueue.cc \ ft/ftdwlqueue.cc \
upnp/upnputil.c \
dht/opendhtmgr.cc \ dht/opendhtmgr.cc \
upnp/upnphandler.cc \ upnp/upnphandler.cc \
upnp/UPnPBase.cpp \
dht/opendht.cc \ dht/opendht.cc \
dht/opendhtstr.cc \ dht/opendhtstr.cc \
dht/b64.c \ dht/b64.c \

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,632 @@
//
// This file is part of the aMule Project.
//
// Copyright (c) 2004-2009 Marcelo Roberto Jimenez ( phoenix@amule.org )
// Copyright (c) 2006-2009 aMule Team ( admin@amule.org / http://www.amule.org )
//
// Any parts of this program derived from the xMule, lMule or eMule project,
// or contributed by third-party developers are copyrighted by their
// respective authors.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
//
#include <map>
#include <string>
#include <sstream>
#include <memory>
#include <vector>
#include "upnp.h"
#include "upnptools.h"
#include "upnpdebug.h"
#include "util/rsthreads.h"
#include <iostream>
#include <util/rsthreads.h>
#ifdef UPNP_C
std::string stdEmptyString;
#else // UPNP_C
extern std::string stdEmptyString;
#endif // UPNP_C
/**
* Case insensitive std::string comparison
*/
bool stdStringIsEqualCI(
const std::string &s1,
const std::string &s2);
class CUPnPPortMapping
{
private:
std::string m_ex_port;
std::string m_in_port;
std::string m_protocol;
std::string m_enabled;
std::string m_description;
std::string m_key;
public:
CUPnPPortMapping(
int in_port = 0,
int ex_port = 0,
const std::string &protocol = stdEmptyString,
bool enabled = false,
const std::string &description = stdEmptyString);
~CUPnPPortMapping() {}
const std::string &getExPort() const
{ return m_ex_port; }
const std::string &getInPort() const
{ return m_in_port; }
const std::string &getProtocol() const
{ return m_protocol; }
const std::string &getEnabled() const
{ return m_enabled; }
const std::string &getDescription() const
{ return m_description; }
const std::string &getKey() const
{ return m_key; }
};
class CUPnPControlPoint;
class CUPnPLib
{
public:
static const std::string &UPNP_ROOT_DEVICE;
static const std::string &UPNP_DEVICE_IGW;
static const std::string &UPNP_DEVICE_WAN;
static const std::string &UPNP_DEVICE_WAN_CONNECTION;
static const std::string &UPNP_DEVICE_LAN;
static const std::string &UPNP_SERVICE_LAYER3_FORWARDING;
static const std::string &UPNP_SERVICE_WAN_COMMON_INTERFACE_CONFIG;
static const std::string &UPNP_SERVICE_WAN_IP_CONNECTION;
static const std::string &UPNP_SERVICE_WAN_PPP_CONNECTION;
CUPnPControlPoint &m_ctrlPoint;
public:
CUPnPLib(CUPnPControlPoint &ctrlPoint);
~CUPnPLib() {}
// Convenience function so we don't have to write explicit calls
// to char2unicode every time
std::string GetUPnPErrorMessage(int code) const;
// Convenience function to avoid repetitive processing of error
// messages
std::string processUPnPErrorMessage(
const std::string &messsage,
int code,
const DOMString errorString,
IXML_Document *doc) const;
// Processing response to actions
void ProcessActionResponse(
IXML_Document *RespDoc,
const std::string &actionName) const;
// IXML_Element
IXML_Element *Element_GetRootElement(
IXML_Document *doc) const;
IXML_Element *Element_GetFirstChild(
IXML_Element *parent) const;
IXML_Element *Element_GetNextSibling(
IXML_Element *child) const;
const DOMString Element_GetTag(
IXML_Element *element) const;
const std::string Element_GetTextValue(
IXML_Element *element) const;
const std::string Element_GetChildValueByTag(
IXML_Element *element,
const DOMString tag) const;
IXML_Element *Element_GetFirstChildByTag(
IXML_Element *element,
const DOMString tag) const;
IXML_Element *Element_GetNextSiblingByTag(
IXML_Element *element,
const DOMString tag) const;
const std::string Element_GetAttributeByTag(
IXML_Element *element,
const DOMString tag) const;
};
class CUPnPControlPoint;
/*
* Even though we can retrieve the upnpLib handler from the upnpControlPoint,
* we must pass it separetly at this point, because the class CUPnPControlPoint
* must be declared after.
*
* CUPnPLib can only be removed from the constructor once we agree to link to
* UPnPLib explicitly, making this dlopen() stuff unnecessary.
*/
template <typename T, char const *XML_ELEMENT_NAME, char const *XML_LIST_NAME>
class CXML_List : public std::map<const std::string, T *>
{
public:
CXML_List(
const CUPnPControlPoint &upnpControlPoint,
CUPnPLib &upnpLib,
IXML_Element *parent,
const std::string &url);
~CXML_List();
};
template <typename T, char const *XML_ELEMENT_NAME, char const *XML_LIST_NAME>
CXML_List<T, XML_ELEMENT_NAME, XML_LIST_NAME>::CXML_List(
const CUPnPControlPoint &upnpControlPoint,
CUPnPLib &upnpLib,
IXML_Element *parent,
const std::string &url)
{
IXML_Element *elementList =
upnpLib.Element_GetFirstChildByTag(parent, XML_LIST_NAME);
unsigned int i = 0;
for ( IXML_Element *element = upnpLib.Element_GetFirstChildByTag(elementList, XML_ELEMENT_NAME);
element;
element = upnpLib.Element_GetNextSiblingByTag(element, XML_ELEMENT_NAME)) {
// Add a new element to the element list
T *upnpElement = new T(upnpControlPoint, upnpLib, element, url);
(*this)[upnpElement->GetKey()] = upnpElement;
++i;
}
std::ostringstream msg;
msg << "\n " << XML_LIST_NAME << ": " <<
i << " " << XML_ELEMENT_NAME << "s.";
std::cerr << msg;
}
template <typename T, char const *XML_ELEMENT_NAME, char const *XML_LIST_NAME>
CXML_List<T, XML_ELEMENT_NAME, XML_LIST_NAME>::~CXML_List()
{
typename CXML_List<T, XML_ELEMENT_NAME, XML_LIST_NAME>::iterator it;
for(it = this->begin(); it != this->end(); ++it) {
delete (*it).second;
}
}
extern const char s_argument[];
extern const char s_argumentList[];
extern const char s_action[];
extern const char s_actionList[];
extern const char s_allowedValue[];
extern const char s_allowedValueList[];
extern const char s_stateVariable[];
extern const char s_serviceStateTable[];
extern const char s_service[];
extern const char s_serviceList[];
extern const char s_device[];
extern const char s_deviceList[];
#ifdef UPNP_C
const char s_argument[] = "argument";
const char s_argumentList[] = "argumentList";
const char s_action[] = "action";
const char s_actionList[] = "actionList";
const char s_allowedValue[] = "allowedValue";
const char s_allowedValueList[] = "allowedValueList";
const char s_stateVariable[] = "stateVariable";
const char s_serviceStateTable[] = "serviceStateTable";
const char s_service[] = "service";
const char s_serviceList[] = "serviceList";
const char s_device[] = "device";
const char s_deviceList[] = "deviceList";
#endif // UPNP_C
class CUPnPArgument;
typedef CXML_List<CUPnPArgument, s_argument, s_argumentList> ArgumentList;
class CUPnPAction;
typedef CXML_List<CUPnPAction, s_action, s_actionList> ActionList;
class CUPnPStateVariable;
typedef CXML_List<CUPnPStateVariable, s_stateVariable, s_serviceStateTable> ServiceStateTable;
class CUPnPAllowedValue;
typedef CXML_List<CUPnPAllowedValue, s_allowedValue, s_allowedValueList> AllowedValueList;
class CUPnPService;
typedef CXML_List<CUPnPService, s_service, s_serviceList> ServiceList;
class CUPnPDevice;
typedef CXML_List<CUPnPDevice, s_device, s_deviceList> DeviceList;
class CUPnPError
{
private:
IXML_Element *m_root;
const std::string m_ErrorCode;
const std::string m_ErrorDescription;
public:
CUPnPError(
const CUPnPLib &upnpLib,
IXML_Document *errorDoc);
~CUPnPError() {}
const std::string &getErrorCode() const
{ return m_ErrorCode; }
const std::string &getErrorDescription() const
{ return m_ErrorDescription; }
};
class CUPnPArgument
{
private:
const CUPnPControlPoint &m_UPnPControlPoint;
const std::string m_name;
const std::string m_direction;
bool m_retval;
const std::string m_relatedStateVariable;
public:
CUPnPArgument(
const CUPnPControlPoint &upnpControlPoint,
CUPnPLib &upnpLib,
IXML_Element *argument,
const std::string &SCPDURL);
~CUPnPArgument() {}
const std::string &GetName() const
{ return m_name; }
const std::string &GetDirection() const
{ return m_direction; }
bool GetRetVal() const
{ return m_retval; }
const std::string &GetRelatedStateVariable() const
{ return m_relatedStateVariable; }
const std::string &GetKey() const
{ return m_name; }
};
class CUPnPAction
{
private:
const CUPnPControlPoint &m_UPnPControlPoint;
ArgumentList m_ArgumentList;
const std::string m_name;
public:
CUPnPAction(
const CUPnPControlPoint &upnpControlPoint,
CUPnPLib &upnpLib,
IXML_Element *action,
const std::string &SCPDURL);
~CUPnPAction() {}
const std::string &GetName() const
{ return m_name; }
const std::string &GetKey() const
{ return m_name; }
const ArgumentList &GetArgumentList() const
{ return m_ArgumentList; }
};
class CUPnPAllowedValue
{
private:
const CUPnPControlPoint &m_UPnPControlPoint;
const std::string m_allowedValue;
public:
CUPnPAllowedValue(
const CUPnPControlPoint &upnpControlPoint,
CUPnPLib &upnpLib,
IXML_Element *allowedValue,
const std::string &SCPDURL);
~CUPnPAllowedValue() {}
const std::string &GetAllowedValue() const
{ return m_allowedValue; }
const std::string &GetKey() const
{ return m_allowedValue; }
};
class CUPnPStateVariable
{
private:
const CUPnPControlPoint &m_UPnPControlPoint;
AllowedValueList m_AllowedValueList;
const std::string m_name;
const std::string m_dataType;
const std::string m_defaultValue;
const std::string m_sendEvents;
public:
CUPnPStateVariable(
const CUPnPControlPoint &upnpControlPoint,
CUPnPLib &upnpLib,
IXML_Element *stateVariable,
const std::string &URLBase);
~CUPnPStateVariable() {}
const std::string &GetNname() const
{ return m_name; }
const std::string &GetDataType() const
{ return m_dataType; }
const std::string &GetDefaultValue() const
{ return m_defaultValue; }
const std::string &GetKey() const
{ return m_name; }
const AllowedValueList &GetAllowedValueList() const
{ return m_AllowedValueList; }
};
class CUPnPSCPD
{
private:
const CUPnPControlPoint &m_UPnPControlPoint;
ActionList m_ActionList;
ServiceStateTable m_ServiceStateTable;
const std::string m_SCPDURL;
public:
CUPnPSCPD(
const CUPnPControlPoint &upnpControlPoint,
CUPnPLib &upnpLib,
IXML_Element *scpd,
const std::string &SCPDURL);
~CUPnPSCPD() {}
const ActionList &GetActionList() const
{ return m_ActionList; }
const ServiceStateTable &GetServiceStateTable() const
{ return m_ServiceStateTable; }
};
class CUPnPArgumentValue
{
private:
std::string m_argument;
std::string m_value;
public:
CUPnPArgumentValue();
CUPnPArgumentValue(const std::string &argument, const std::string &value);
~CUPnPArgumentValue() {}
const std::string &GetArgument() const { return m_argument; }
const std::string &GetValue() const { return m_value; }
const std::string &SetArgument(const std::string& argument) { return m_argument = argument; }
const std::string &SetValue(const std::string &value) { return m_value = value; }
};
class CUPnPService
{
private:
const CUPnPControlPoint &m_UPnPControlPoint;
CUPnPLib &m_upnpLib;
const std::string m_serviceType;
const std::string m_serviceId;
const std::string m_SCPDURL;
const std::string m_controlURL;
const std::string m_eventSubURL;
std::string m_absSCPDURL;
std::string m_absControlURL;
std::string m_absEventSubURL;
int m_timeout;
Upnp_SID m_SID;
std::auto_ptr<CUPnPSCPD> m_SCPD;
public:
CUPnPService(
const CUPnPControlPoint &upnpControlPoint,
CUPnPLib &upnpLib,
IXML_Element *service,
const std::string &URLBase);
~CUPnPService();
const std::string &GetServiceType() const
{ return m_serviceType; }
const std::string &GetServiceId() const
{ return m_serviceId; }
const std::string &GetSCPDURL() const
{ return m_SCPDURL; }
const std::string &GetAbsSCPDURL() const
{ return m_absSCPDURL; }
const std::string &GetControlURL() const
{ return m_controlURL; }
const std::string &GetEventSubURL() const
{ return m_eventSubURL; }
const std::string &GetAbsControlURL() const
{ return m_absControlURL; }
const std::string &GetAbsEventSubURL() const
{ return m_absEventSubURL; }
int GetTimeout() const
{ return m_timeout; }
void SetTimeout(int t)
{ m_timeout = t; }
int *GetTimeoutAddr()
{ return &m_timeout; }
char *GetSID()
{ return m_SID; }
void SetSID(const char *s)
{ memcpy(m_SID, s, sizeof(Upnp_SID)); }
const std::string &GetKey() const
{ return m_serviceId; }
bool IsSubscribed() const
{ return m_SCPD.get() != NULL; }
void SetSCPD(CUPnPSCPD *SCPD)
{ m_SCPD.reset(SCPD); }
bool Execute(
const std::string &ActionName,
const std::vector<CUPnPArgumentValue> &ArgValue) const;
const std::string GetStateVariable(
const std::string &stateVariableName);
//callback Function
static int GetServiceVarStatusAsyncCallback(
Upnp_EventType EventType,
void* Event,
void* Cookie);
};
class CUPnPDevice
{
private:
const CUPnPControlPoint &m_UPnPControlPoint;
// Please, lock these lists before use
DeviceList m_DeviceList;
ServiceList m_ServiceList;
const std::string m_deviceType;
const std::string m_friendlyName;
const std::string m_manufacturer;
const std::string m_manufacturerURL;
const std::string m_modelDescription;
const std::string m_modelName;
const std::string m_modelNumber;
const std::string m_modelURL;
const std::string m_serialNumber;
const std::string m_UDN;
const std::string m_UPC;
std::string m_presentationURL;
public:
CUPnPDevice(
const CUPnPControlPoint &upnpControlPoint,
CUPnPLib &upnpLib,
IXML_Element *device,
const std::string &URLBase);
~CUPnPDevice() {}
const std::string &GetUDN() const
{ return m_UDN; }
const std::string &GetDeviceType() const
{ return m_deviceType; }
const std::string &GetFriendlyName() const
{ return m_friendlyName; }
const std::string &GetPresentationURL() const
{ return m_presentationURL; }
const std::string &GetKey() const
{ return m_UDN; }
};
class CUPnPRootDevice : public CUPnPDevice
{
private:
const CUPnPControlPoint &m_UPnPControlPoint;
const std::string m_URLBase;
const std::string m_location;
int m_expires;
public:
CUPnPRootDevice(
const CUPnPControlPoint &upnpControlPoint,
CUPnPLib &upnpLib,
IXML_Element *rootDevice,
const std::string &OriginalURLBase,
const std::string &FixedURLBase,
const char *location,
int expires);
~CUPnPRootDevice() {}
const std::string &GetURLBase() const
{ return m_URLBase; }
const std::string &GetLocation() const
{ return m_location; }
int GetExpires() const
{ return m_expires; }
void SetExpires(int expires)
{ m_expires = expires; }
};
typedef std::map<const std::string, CUPnPRootDevice *> RootDeviceMap;
typedef std::map<const std::string, CUPnPService *> ServiceMap;
typedef std::map<const std::string, CUPnPPortMapping> PortMappingMap;
class CUPnPControlPoint
{
private:
// upnp stuff
CUPnPLib m_upnpLib;
UpnpClient_Handle m_UPnPClientHandle;
RootDeviceMap m_RootDeviceMap;
ServiceMap m_ServiceMap;
PortMappingMap m_ActivePortMappingsMap;
RsMutex m_RootDeviceListMutex;
bool m_IGWDeviceDetected;
CUPnPService *m_WanService;
RsMutex m_WaitForSearchTimeoutMutex;
public:
RsMutex m_getStateVariableMutex;
std::string m_getStateVariableLastResult;
static CUPnPControlPoint *s_CtrlPoint;
CUPnPControlPoint(unsigned short udpPort);
~CUPnPControlPoint();
char* getInternalIpAddress();
std::string getExternalAddress();
void Subscribe(CUPnPService &service);
void Unsubscribe(CUPnPService &service);
bool AddPortMappings(
std::vector<CUPnPPortMapping> &upnpPortMapping);
bool DeletePortMappings(
std::vector<CUPnPPortMapping> &upnpPortMapping);
UpnpClient_Handle GetUPnPClientHandle() const
{ return m_UPnPClientHandle; }
bool GetIGWDeviceDetected() const
{ return m_IGWDeviceDetected; }
void SetIGWDeviceDetected(bool b)
{ m_IGWDeviceDetected = b; }
bool WanServiceDetected() const
{ return !m_ServiceMap.empty(); }
void SetWanService(CUPnPService *service)
{ m_WanService = service; }
// Callback function
static int Callback(
Upnp_EventType EventType,
void* Event,
void* Cookie);
void OnEventReceived(
const std::string &Sid,
int EventKey,
IXML_Document *ChangedVariables);
private:
void AddRootDevice(
IXML_Element *rootDevice,
const std::string &urlBase,
const char *location,
int expires);
void RemoveRootDevice(
const char *udn);
void RefreshPortMappings();
bool PrivateAddPortMapping(
CUPnPPortMapping &upnpPortMapping);
bool PrivateDeletePortMapping(
CUPnPPortMapping &upnpPortMapping);
};
// File_checked_for_headers

View file

@ -13,183 +13,59 @@ extern "C" {
#include "upnp/upnphandler.h" #include "upnp/upnphandler.h"
#include "upnp/upnputil.h" #include "upnp/upnputil.h"
struct WanDevice {
char UDN[250];
char DescDocURL[250];
char FriendlyName[250];
char PresURL[250];
int AdvrTimeOut;
};
class uPnPConfigData class uPnPConfigData
{ {
public: public:
struct UPNPDev * devlist; struct WanDevice * WanDevice;
struct UPNPUrls urls; char lanaddr[16]; /* my ip address on the LAN */
struct IGDdatas data;
char lanaddr[16]; /* my ip address on the LAN */
}; };
#include <iostream>
#include <sstream>
#include "util/rsnet.h" #include "util/rsnet.h"
UpnpClient_Handle ctrlpt_handle = -1;
bool upnphandler::initUPnPState() bool upnphandler::initUPnPState()
{ {
/* allocate memory */ std::cerr << "upnphandler::initUPnPState" << std::endl;
uPnPConfigData *upcd = new uPnPConfigData; cUPnPControlPoint = new CUPnPControlPoint(2000);
#if MINIUPNPC_VERSION >= 11 bool IGWDetected = cUPnPControlPoint->GetIGWDeviceDetected();
/* Starting from version 1.1, miniupnpc api has a new parameter (int sameport) */
upcd->devlist = upnpDiscover(2000, NULL, NULL, 0);
#else
upcd->devlist = upnpDiscover(2000, NULL, NULL);
#endif
if(upcd->devlist)
{
struct UPNPDev * device;
printf("List of UPNP devices found on the network :\n");
for(device=upcd->devlist;device;device=device->pNext)
{
printf("\n desc: %s\n st: %s\n",
device->descURL, device->st);
}
putchar('\n');
if(UPNP_GetValidIGD(upcd->devlist, &(upcd->urls),
&(upcd->data), upcd->lanaddr,
sizeof(upcd->lanaddr)))
{
printf("Found valid IGD : %s\n",
upcd->urls.controlURL);
printf("Local LAN ip address : %s\n",
upcd->lanaddr);
/* MODIFY STATE */
dataMtx.lock(); /* LOCK MUTEX */
/* convert to ipaddress. */
inet_aton(upcd->lanaddr, &(upnp_iaddr.sin_addr));
upnp_iaddr.sin_port = htons(iport);
upnpState = RS_UPNP_S_READY;
if (upnpConfig)
{
delete upnpConfig;
}
upnpConfig = upcd; /* */
dataMtx.unlock(); /* UNLOCK MUTEX */
/* done -> READY */
return 1;
}
else
{
fprintf(stderr, "No valid UPNP Internet Gateway Device found.\n");
}
freeUPNPDevlist(upcd->devlist);
upcd->devlist = 0;
}
else
{
fprintf(stderr, "No IGD UPnP Device found on the network !\n");
}
/* MODIFY STATE */ /* MODIFY STATE */
dataMtx.lock(); /* LOCK MUTEX */ dataMtx.lock(); /* LOCK MUTEX */
std::cerr << "upnphandler::initUPnPState cUPnPControlPoint internal ip adress : ";
std::cerr << cUPnPControlPoint->getInternalIpAddress() << std::endl;
upnpState = RS_UPNP_S_UNAVAILABLE; //const char ipaddr = cUPnPControlPoint->getInternalIpAddress().c_str();
delete upcd; inet_aton(cUPnPControlPoint->getInternalIpAddress(), &(upnp_iaddr.sin_addr));
upnpConfig = NULL; upnp_iaddr.sin_port = htons(iport);
if (IGWDetected) {
upnpState = RS_UPNP_S_READY;
} else {
upnpState = RS_UPNP_S_UNAVAILABLE;
}
dataMtx.unlock(); /* UNLOCK MUTEX */ dataMtx.unlock(); /* UNLOCK MUTEX */
/* done, FAILED -> NOT AVAILABLE */ /* done, NOT AVAILABLE YET */
if (upnpState == RS_UPNP_S_READY) {
std::cerr << "upnphandler::initUPnPState READY" << std::endl;
} else {
std::cerr << "upnphandler::initUPnPState UNAVAILABLE" << std::endl;
}
return 0; return 0;
} }
bool upnphandler::printUPnPState()
{
std::cerr << "upnphandler::printUPnPState() ... locking";
std::cerr << std::endl;
RsStackMutex stack(dataMtx); /* LOCK STACK MUTEX */
std::cerr << "upnphandler::printUPnPState() ... locked";
std::cerr << std::endl;
uPnPConfigData *config = upnpConfig;
if ((upnpState >= RS_UPNP_S_READY) && (config))
{
DisplayInfos(&(config -> urls), &(config->data));
GetConnectionStatus(&(config -> urls), &(config->data));
ListRedirections(&(config -> urls), &(config->data));
}
else
{
std::cerr << "UPNP not Ready" << std::endl;
}
return 1;
}
bool upnphandler::checkUPnPActive()
{
RsStackMutex stack(dataMtx); /* LOCK STACK MUTEX */
uPnPConfigData *config = upnpConfig;
if ((upnpState > RS_UPNP_S_READY) && (config))
{
char eprot1[] = "TCP";
char eprot2[] = "UDP";
char in_addr[256];
char in_port1[256];
char in_port2[256];
char eport1[256];
char eport2[256];
struct sockaddr_in localAddr = upnp_iaddr;
uint32_t linaddr = ntohl(localAddr.sin_addr.s_addr);
snprintf(in_port1, 256, "%d", ntohs(localAddr.sin_port));
snprintf(in_port2, 256, "%d", ntohs(localAddr.sin_port));
snprintf(in_addr, 256, "%d.%d.%d.%d",
((linaddr >> 24) & 0xff),
((linaddr >> 16) & 0xff),
((linaddr >> 8) & 0xff),
((linaddr >> 0) & 0xff));
snprintf(eport1, 256, "%d", eport_curr);
snprintf(eport2, 256, "%d", eport_curr);
std::cerr << "upnphandler::checkUPnPState()";
std::cerr << " Checking Redirection: InAddr: " << in_addr;
std::cerr << " InPort: " << in_port1;
std::cerr << " ePort: " << eport1;
std::cerr << " eProt: " << eprot1;
std::cerr << std::endl;
bool tcpOk = TestRedirect(&(config -> urls), &(config->data),
in_addr, in_port1, eport1, eprot1);
bool udpOk = TestRedirect(&(config -> urls), &(config->data),
in_addr, in_port2, eport2, eprot2);
if ((!tcpOk) || (!udpOk))
{
std::cerr << "upnphandler::checkUPnPState() ... Redirect Expired, restarting";
std::cerr << std::endl;
toStop = true;
toStart = true;
}
}
return true;
}
class upnpThreadData class upnpThreadData
{ {
public: public:
@ -219,8 +95,6 @@ extern "C" void* doSetupUPnP(void* p)
data->handler->start_upnp(); data->handler->start_upnp();
} }
data->handler->printUPnPState();
delete data; delete data;
pthread_exit(NULL); pthread_exit(NULL);
@ -247,11 +121,9 @@ bool upnphandler::start_upnp()
{ {
RsStackMutex stack(dataMtx); /* LOCK STACK MUTEX */ RsStackMutex stack(dataMtx); /* LOCK STACK MUTEX */
uPnPConfigData *config = upnpConfig; if (!(upnpState >= RS_UPNP_S_READY))
if (!((upnpState >= RS_UPNP_S_READY) && (config)))
{ {
std::cerr << "upnphandler::start_upnp() Not Ready"; std::cerr << "upnphandler::start_upnp() Not Ready" << std::endl;
std::cerr << std::endl;
return false; return false;
} }
@ -280,16 +152,13 @@ bool upnphandler::start_upnp()
/* our port */ /* our port */
char in_addr[256]; char in_addr[256];
char in_port1[256]; char in_port1[256];
char in_port2[256];
char eport1[256]; char eport1[256];
char eport2[256];
upnp_iaddr.sin_port = htons(iport); upnp_iaddr.sin_port = htons(iport);
struct sockaddr_in localAddr = upnp_iaddr; struct sockaddr_in localAddr = upnp_iaddr;
uint32_t linaddr = ntohl(localAddr.sin_addr.s_addr); uint32_t linaddr = ntohl(localAddr.sin_addr.s_addr);
snprintf(in_port1, 256, "%d", ntohs(localAddr.sin_port)); snprintf(in_port1, 256, "%d", ntohs(localAddr.sin_port));
snprintf(in_port2, 256, "%d", ntohs(localAddr.sin_port));
snprintf(in_addr, 256, "%d.%d.%d.%d", snprintf(in_addr, 256, "%d.%d.%d.%d",
((linaddr >> 24) & 0xff), ((linaddr >> 24) & 0xff),
((linaddr >> 16) & 0xff), ((linaddr >> 16) & 0xff),
@ -297,7 +166,6 @@ bool upnphandler::start_upnp()
((linaddr >> 0) & 0xff)); ((linaddr >> 0) & 0xff));
snprintf(eport1, 256, "%d", eport_curr); snprintf(eport1, 256, "%d", eport_curr);
snprintf(eport2, 256, "%d", eport_curr);
std::cerr << "Attempting Redirection: InAddr: " << in_addr; std::cerr << "Attempting Redirection: InAddr: " << in_addr;
std::cerr << " InPort: " << in_port1; std::cerr << " InPort: " << in_port1;
@ -305,32 +173,35 @@ bool upnphandler::start_upnp()
std::cerr << " eProt: " << eprot1; std::cerr << " eProt: " << eprot1;
std::cerr << std::endl; std::cerr << std::endl;
if (!SetRedirectAndTest(&(config -> urls), &(config->data), //build port mapping config
in_addr, in_port1, eport1, eprot1)) std::vector<CUPnPPortMapping> upnpPortMapping1;
{ CUPnPPortMapping cUPnPPortMapping1 = CUPnPPortMapping(eport_curr, ntohs(localAddr.sin_port), "TCP", true, "tcp retroshare redirection");
upnpState = RS_UPNP_S_TCP_FAILED; upnpPortMapping1.push_back(cUPnPPortMapping1);
} bool res = cUPnPControlPoint->AddPortMappings(upnpPortMapping1);
else if (!SetRedirectAndTest(&(config -> urls), &(config->data),
in_addr, in_port2, eport2, eprot2))
{
upnpState = RS_UPNP_S_UDP_FAILED;
}
else
{
upnpState = RS_UPNP_S_ACTIVE;
}
if (res) {
upnpState = RS_UPNP_S_ACTIVE;
} else {
upnpState = RS_UPNP_S_TCP_FAILED;
std::vector<CUPnPPortMapping> upnpPortMapping2;
CUPnPPortMapping cUPnPPortMapping2 = CUPnPPortMapping(eport_curr, ntohs(localAddr.sin_port), "UDP", true, "udp retroshare redirection");
upnpPortMapping2.push_back(cUPnPPortMapping2);
bool res2 = cUPnPControlPoint->AddPortMappings(upnpPortMapping2);
if (res) {
upnpState = RS_UPNP_S_ACTIVE;
} else {
upnpState = RS_UPNP_S_UDP_FAILED;
}
}
/* now store the external address */ /* now store the external address */
char externalIPAddress[32]; std::string externalAdress = cUPnPControlPoint->getExternalAddress();
UPNP_GetExternalIPAddress(config -> urls.controlURL,
config->data.servicetype,
externalIPAddress);
sockaddr_clear(&upnp_eaddr); sockaddr_clear(&upnp_eaddr);
if(externalIPAddress[0]) if(!externalAdress.empty())
{ {
const char* externalIPAddress = externalAdress.c_str();
std::cerr << "Stored External address: " << externalIPAddress; std::cerr << "Stored External address: " << externalIPAddress;
std::cerr << ":" << eport_curr; std::cerr << ":" << eport_curr;
std::cerr << std::endl; std::cerr << std::endl;
@ -355,8 +226,7 @@ bool upnphandler::shutdown_upnp()
{ {
RsStackMutex stack(dataMtx); /* LOCK STACK MUTEX */ RsStackMutex stack(dataMtx); /* LOCK STACK MUTEX */
uPnPConfigData *config = upnpConfig; if (!(upnpState >= RS_UPNP_S_READY))
if (!((upnpState >= RS_UPNP_S_READY) && (config)))
{ {
return false; return false;
} }
@ -378,18 +248,23 @@ bool upnphandler::shutdown_upnp()
std::cerr << " Prot: " << eprot1; std::cerr << " Prot: " << eprot1;
std::cerr << std::endl; std::cerr << std::endl;
RemoveRedirect(&(config -> urls), &(config->data), std::vector<CUPnPPortMapping> upnpPortMapping1;
eport1, eprot1); CUPnPPortMapping *cUPnPPortMapping1 = &CUPnPPortMapping(eport_curr, 0, eprot1, true, "tcp redirection");
upnpPortMapping1.push_back(*cUPnPPortMapping1);
cUPnPControlPoint->DeletePortMappings(upnpPortMapping1);
std::cerr << "Attempting To Remove Redirection: port: " << eport2; std::cerr << "Attempting To Remove Redirection: port: " << eport2;
std::cerr << " Prot: " << eprot2; std::cerr << " Prot: " << eprot2;
std::cerr << std::endl; std::cerr << std::endl;
RemoveRedirect(&(config -> urls), &(config->data), std::vector<CUPnPPortMapping> upnpPortMapping2;
eport2, eprot2); CUPnPPortMapping *cUPnPPortMapping2 = &CUPnPPortMapping(eport_curr, 0, eprot2, true, "tcp redirection");
upnpPortMapping2.push_back(*cUPnPPortMapping2);
cUPnPControlPoint->DeletePortMappings(upnpPortMapping2);
upnpState = RS_UPNP_S_READY; //destroy the upnp object
cUPnPControlPoint->~CUPnPControlPoint();
upnpState = RS_UPNP_S_UNINITIALISED;
toStop = false; toStop = false;
} }
@ -405,11 +280,8 @@ bool upnphandler::shutdown_upnp()
upnphandler::upnphandler() upnphandler::upnphandler()
:toEnable(false), toStart(false), toStop(false), :toEnable(false), toStart(false), toStop(false),
eport(0), eport_curr(0), eport(0), eport_curr(0)
upnpState(RS_UPNP_S_UNINITIALISED),
upnpConfig(NULL)
{ {
return;
} }
upnphandler::~upnphandler() upnphandler::~upnphandler()
@ -444,8 +316,6 @@ void upnphandler::enable(bool active)
/* make background thread to startup UPnP */ /* make background thread to startup UPnP */
background_setup_upnp(true, false); background_setup_upnp(true, false);
} }
} }
@ -490,9 +360,9 @@ bool upnphandler::getActive()
/* the address that the listening port is on */ /* the address that the listening port is on */
void upnphandler::setInternalPort(unsigned short iport_in) void upnphandler::setInternalPort(unsigned short iport_in)
{ {
// std::cerr << "UPnPHandler::setInternalAddress() pre Lock!" << std::endl; std::cerr << "UPnPHandler::setInternalAddress() pre Lock!" << std::endl;
dataMtx.lock(); /*** LOCK MUTEX ***/ dataMtx.lock(); /*** LOCK MUTEX ***/
// std::cerr << "UPnPHandler::setInternalAddress() postLock!" << std::endl; std::cerr << "UPnPHandler::setInternalAddress() postLock!" << std::endl;
std::cerr << "UPnPHandler::setInternalPort(" << iport_in << ") current port: "; std::cerr << "UPnPHandler::setInternalPort(" << iport_in << ") current port: ";
std::cerr << iport << std::endl; std::cerr << iport << std::endl;
@ -512,9 +382,9 @@ void upnphandler::setInternalPort(unsigned short iport_in)
void upnphandler::setExternalPort(unsigned short eport_in) void upnphandler::setExternalPort(unsigned short eport_in)
{ {
// std::cerr << "UPnPHandler::getExternalPort() pre Lock!" << std::endl; std::cerr << "UPnPHandler::setExternalPort() pre Lock!" << std::endl;
dataMtx.lock(); /*** LOCK MUTEX ***/ dataMtx.lock(); /*** LOCK MUTEX ***/
// std::cerr << "UPnPHandler::getExternalPort() postLock!" << std::endl; std::cerr << "UPnPHandler::setExternalPort() postLock!" << std::endl;
std::cerr << "UPnPHandler::setExternalPort(" << eport_in << ") current port: "; std::cerr << "UPnPHandler::setExternalPort(" << eport_in << ") current port: ";
std::cerr << eport << std::endl; std::cerr << eport << std::endl;
@ -565,5 +435,3 @@ bool upnphandler::getExternalAddress(struct sockaddr_in &addr)
return valid; return valid;
} }

View file

@ -3,15 +3,15 @@
#include <string.h> #include <string.h>
#include <string>
#include <map>
/* platform independent networking... */ /* platform independent networking... */
#include "pqi/pqinetwork.h" #include "pqi/pqinetwork.h"
#include "pqi/pqiassist.h" #include "pqi/pqiassist.h"
#include "util/rsthreads.h" #include "util/rsthreads.h"
#include "upnp.h"
#include "upnp/UPnPBase.h"
class upnpentry class upnpentry
{ {
public: public:
@ -48,58 +48,60 @@ class upnphandler: public pqiNetAssistFirewall
{ {
public: public:
upnphandler(); upnphandler();
virtual ~upnphandler(); virtual ~upnphandler();
/* External Interface (pqiNetAssistFirewall) */ /* External Interface (pqiNetAssistFirewall) */
virtual void enable(bool active); virtual void enable(bool active);
virtual void shutdown(); virtual void shutdown();
virtual void restart(); virtual void restart();
virtual bool getEnabled(); virtual bool getEnabled();
virtual bool getActive(); virtual bool getActive();
virtual void setInternalPort(unsigned short iport_in); virtual void setInternalPort(unsigned short iport_in);
virtual void setExternalPort(unsigned short eport_in); virtual void setExternalPort(unsigned short eport_in);
virtual bool getInternalAddress(struct sockaddr_in &addr); virtual bool getInternalAddress(struct sockaddr_in &addr);
virtual bool getExternalAddress(struct sockaddr_in &addr); virtual bool getExternalAddress(struct sockaddr_in &addr);
/* Public functions - for background thread operation, /* Public functions - for background thread operation,
* but effectively private from rest of RS, as in derived class * but effectively private from rest of RS, as in derived class
*/ */
unsigned int upnpState;
bool start_upnp(); bool start_upnp();
bool shutdown_upnp(); bool shutdown_upnp();
bool initUPnPState(); bool initUPnPState();
bool printUPnPState();
/* Mutex for data below */
RsMutex dataMtx;
private: private:
bool background_setup_upnp(bool, bool); CUPnPControlPoint *cUPnPControlPoint;
bool checkUPnPActive();
/* Mutex for data below */ bool background_setup_upnp(bool, bool);
RsMutex dataMtx;
bool toEnable; /* overall on/off switch */
bool toStart; /* if set start forwarding */
bool toStop; /* if set stop forwarding */
unsigned short iport; bool toEnable; /* overall on/off switch */
unsigned short eport; /* config */ bool toStart; /* if set start forwarding */
unsigned short eport_curr; /* current forwarded */ bool toStop; /* if set stop forwarding */
/* info from upnp */ unsigned short iport;
unsigned int upnpState; unsigned short eport; /* config */
uPnPConfigData *upnpConfig; unsigned short eport_curr; /* current forwarded */
struct sockaddr_in upnp_iaddr; /* info from upnp */
struct sockaddr_in upnp_eaddr; struct sockaddr_in upnp_iaddr;
struct sockaddr_in upnp_eaddr;
/* active port forwarding */ /* active port forwarding */
std::list<upnpforward> activeForwards; std::list<upnpforward> activeForwards;
}; };
/* info from upnp */
int CtrlPointCallbackEventHandler(Upnp_EventType ,void* , void*);
#endif /* _RS_UPNP_IFACE_H */ #endif /* _RS_UPNP_IFACE_H */

View file

@ -1,290 +0,0 @@
#include "upnp/upnputil.h"
/* protofix() checks if protocol is "UDP" or "TCP"
* returns NULL if not */
const char * protofix(const char * proto)
{
static const char proto_tcp[4] = { 'T', 'C', 'P', 0};
static const char proto_udp[4] = { 'U', 'D', 'P', 0};
int i, b;
for(i=0, b=1; i<4; i++)
b = b && ( (proto[i] == proto_tcp[i])
|| (proto[i] == (proto_tcp[i] | 32)) );
if(b)
return proto_tcp;
for(i=0, b=1; i<4; i++)
b = b && ( (proto[i] == proto_udp[i])
|| (proto[i] == (proto_udp[i] | 32)) );
if(b)
return proto_udp;
return 0;
}
void DisplayInfos(struct UPNPUrls * urls,
struct IGDdatas * data)
{
char externalIPAddress[16];
char connectionType[64];
char status[64];
char lastconnerror[64];
unsigned int uptime;
unsigned int brUp, brDown;
UPNP_GetConnectionTypeInfo(urls->controlURL,
data->servicetype,
connectionType);
if(connectionType[0])
printf("Connection Type : %s\n", connectionType);
else
printf("GetConnectionTypeInfo failed.\n");
UPNP_GetStatusInfo(urls->controlURL, data->servicetype, status, &uptime, lastconnerror);
printf("Status : %s, uptime=%u LastConnError %s\n", status, uptime, lastconnerror);
UPNP_GetLinkLayerMaxBitRates(urls->controlURL_CIF, data->servicetype_CIF,
&brDown, &brUp);
printf("MaxBitRateDown : %u bps MaxBitRateUp %u bps\n", brDown, brUp);
UPNP_GetExternalIPAddress(urls->controlURL,
data->servicetype,
externalIPAddress);
if(externalIPAddress[0])
printf("ExternalIPAddress = %s\n", externalIPAddress);
else
printf("GetExternalIPAddress failed.\n");
}
void GetConnectionStatus(struct UPNPUrls * urls,
struct IGDdatas * data)
{
unsigned int bytessent, bytesreceived, packetsreceived, packetssent;
DisplayInfos(urls, data);
bytessent = UPNP_GetTotalBytesSent(urls->controlURL_CIF, data->servicetype_CIF);
bytesreceived = UPNP_GetTotalBytesReceived(urls->controlURL_CIF, data->servicetype_CIF);
packetssent = UPNP_GetTotalPacketsSent(urls->controlURL_CIF, data->servicetype_CIF);
packetsreceived = UPNP_GetTotalPacketsReceived(urls->controlURL_CIF, data->servicetype_CIF);
printf("Bytes: Sent: %8u\tRecv: %8u\n", bytessent, bytesreceived);
printf("Packets: Sent: %8u\tRecv: %8u\n", packetssent, packetsreceived);
}
void ListRedirections(struct UPNPUrls * urls,
struct IGDdatas * data)
{
int r;
int i = 0;
char index[6];
char intClient[16];
char intPort[6];
char extPort[6];
char protocol[4];
char desc[80];
char enabled[6];
char rHost[64];
char duration[16];
/*unsigned int num=0;
UPNP_GetPortMappingNumberOfEntries(urls->controlURL, data->servicetype, &num);
printf("PortMappingNumberOfEntries : %u\n", num);*/
do {
snprintf(index, 6, "%d", i);
rHost[0] = '\0'; enabled[0] = '\0';
duration[0] = '\0'; desc[0] = '\0';
extPort[0] = '\0'; intPort[0] = '\0'; intClient[0] = '\0';
r = UPNP_GetGenericPortMappingEntry(urls->controlURL, data->servicetype,
index,
extPort, intClient, intPort,
protocol, desc, enabled,
rHost, duration);
if(r==0)
printf("%02d - %s %s->%s:%s\tenabled=%s leaseDuration=%s\n"
" desc='%s' rHost='%s'\n",
i, protocol, extPort, intClient, intPort,
enabled, duration,
desc, rHost);
i++;
} while(r==0);
}
/* Test function
* 1 - get connection type
* 2 - get extenal ip address
* 3 - Add port mapping
* 4 - get this port mapping from the IGD */
bool SetRedirectAndTest(struct UPNPUrls * urls,
struct IGDdatas * data,
const char * iaddr,
const char * iport,
const char * eport,
const char * proto)
{
char externalIPAddress[16];
char intClient[16];
char intPort[6];
char leaseDuration[] = "3600"; /* 60 mins */
int r;
int ok = 1;
if(!iaddr || !iport || !eport || !proto)
{
fprintf(stderr, "Wrong arguments\n");
return 0;
}
proto = protofix(proto);
if(!proto)
{
fprintf(stderr, "invalid protocol\n");
return 0;
}
UPNP_GetExternalIPAddress(urls->controlURL,
data->servicetype,
externalIPAddress);
if(externalIPAddress[0])
printf("ExternalIPAddress = %s\n", externalIPAddress);
else
printf("GetExternalIPAddress failed.\n");
// Unix at the moment!
#if MINIUPNPC_VERSION >= 13
/* Starting from miniupnpc version 1.2, lease duration parameter is gone */
r = UPNP_AddPortMapping(urls->controlURL, data->servicetype,
eport, iport, iaddr, 0, proto, NULL);
#else
#if MINIUPNPC_VERSION >= 12
/* Starting from miniupnpc version 1.2, lease duration parameter is gone */
r = UPNP_AddPortMapping(urls->controlURL, data->servicetype,
eport, iport, iaddr, 0, proto);
#else
/* The lease parameter is also gone in minupnpc 1.0 */
r = UPNP_AddPortMapping(urls->controlURL, data->servicetype,
eport, iport, iaddr,0, 0, proto);
#endif
#endif
// r = UPNP_AddPortMapping(urls->controlURL, data->servicetype,
// eport, iport, iaddr, 0, leaseDuration, proto);
// r = UPNP_AddPortMapping(urls->controlURL, data->servicetype,
// eport, iport, iaddr, 0, proto);
if(r==0)
{
printf("AddPortMapping(%s, %s, %s) failed\n", eport, iport, iaddr);
//this seems to trigger for unknown reasons sometimes.
//rely on Checking it afterwards...
//should check IP address then!
//ok = 0;
}
UPNP_GetSpecificPortMappingEntry(urls->controlURL,
data->servicetype,
eport, proto,
intClient, intPort);
if(intClient[0])
printf("InternalIP:Port = %s:%s\n", intClient, intPort);
else
{
printf("GetSpecificPortMappingEntry failed.\n");
ok = 0;
}
if ((strcmp(iaddr, intClient) != 0) || (strcmp(iport, intPort) != 0))
{
printf("PortMappingEntry to wrong location! FAILED\n");
printf("IP1:\"%s\"\n", iaddr);
printf("IP2:\"%s\"\n", intClient);
printf("PORT1:\"%s\"\n", iport);
printf("PORT2:\"%s\"\n", intPort);
ok = 0;
}
printf("external %s:%s is redirected to internal %s:%s\n",
externalIPAddress, eport, intClient, intPort);
if (ok)
{
printf("uPnP Forward/Mapping Succeeded\n");
}
else
{
printf("uPnP Forward/Mapping Failed\n");
}
return ok;
}
bool TestRedirect(struct UPNPUrls * urls,
struct IGDdatas * data,
const char * iaddr,
const char * iport,
const char * eport,
const char * proto)
{
char intClient[16];
char intPort[6];
int ok = 1;
if(!iaddr || !iport || !eport || !proto)
{
fprintf(stderr, "Wrong arguments\n");
return 0;
}
proto = protofix(proto);
if(!proto)
{
fprintf(stderr, "invalid protocol\n");
return 0;
}
UPNP_GetSpecificPortMappingEntry(urls->controlURL,
data->servicetype,
eport, proto,
intClient, intPort);
if(intClient[0])
printf("uPnP Check: InternalIP:Port = %s:%s\n", intClient, intPort);
else
{
printf("GetSpecificPortMappingEntry failed.\n");
ok = 0;
}
printf("uPnP Check: External port %s is redirected to internal %s:%s\n",
eport, intClient, intPort);
if (ok)
{
printf("uPnP Check: uPnP Forward/Mapping still Active\n");
}
else
{
printf("uPnP Check: Forward/Mapping has been Dropped\n");
}
return ok;
}
bool
RemoveRedirect(struct UPNPUrls * urls,
struct IGDdatas * data,
const char * eport,
const char * proto)
{
if(!proto || !eport)
{
fprintf(stderr, "invalid arguments\n");
return 0;
}
proto = protofix(proto);
if(!proto)
{
fprintf(stderr, "protocol invalid\n");
return 0;
}
#if MINIUPNPC_VERSION >= 13
UPNP_DeletePortMapping(urls->controlURL, data->servicetype, eport, proto, NULL);
#else
UPNP_DeletePortMapping(urls->controlURL, data->servicetype, eport, proto);
#endif
return 1;
}
/* EOF */

View file

@ -1,55 +0,0 @@
#ifndef MINIUPNP_UTIL_H_
#define MINIUPNP_UTIL_H_
/* $Id: upnpc.c,v 1.50 2007/04/26 19:00:10 nanard Exp $ */
/* Project : miniupnp
* Author : Thomas Bernard
* Copyright (c) 2005 Thomas Bernard
* This software is subject to the conditions detailed in the
* LICENCE file provided in this distribution.
* */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef WIN32
#include <winsock2.h>
#define snprintf _snprintf
#endif
#include <miniwget.h>
#include <miniupnpc.h>
#include <upnpcommands.h>
/* protofix() checks if protocol is "UDP" or "TCP"
* returns NULL if not */
const char * protofix(const char * proto);
void DisplayInfos(struct UPNPUrls * urls,
struct IGDdatas * data);
void GetConnectionStatus(struct UPNPUrls * urls,
struct IGDdatas * data);
void ListRedirections(struct UPNPUrls * urls,
struct IGDdatas * data);
bool SetRedirectAndTest(struct UPNPUrls * urls,
struct IGDdatas * data,
const char * iaddr,
const char * iport,
const char * eport,
const char * proto);
bool TestRedirect(struct UPNPUrls * urls,
struct IGDdatas * data,
const char * iaddr,
const char * iport,
const char * eport,
const char * proto);
bool RemoveRedirect(struct UPNPUrls * urls,
struct IGDdatas * data,
const char * eport,
const char * proto);
/* EOF */
#endif

View file

@ -1,4 +1,4 @@
CONFIG += qt gui uic qrc resources uitools debug pluginmgr newsettings #release CONFIG += qt gui uic qrc resources uitools debug pluginmgr newsettings #release
QT += network xml script QT += network xml script
TEMPLATE = app TEMPLATE = app
TARGET = RetroShare TARGET = RetroShare
@ -13,15 +13,16 @@ MOC_DIR = temp/moc
# Put lib dir in QMAKE_LFLAGS so it appears before -L/usr/lib # Put lib dir in QMAKE_LFLAGS so it appears before -L/usr/lib
linux-g++ { linux-g++ {
OBJECTS_DIR = temp/linux-g++/obj OBJECTS_DIR = temp/linux-g++/obj
QMAKE_LFLAGS += -L"../../../../lib/linux-g++" CONFIG += version_detail_bash_script
CONFIG += version_detail_bash_script LIBS += ../../libretroshare/src/lib/libretroshare.a
LIBS += -L"../../../../lib" -lretroshare -lssl -lcrypto -lgpgme -lpthread -lminiupnpc -lz LIBS += -lssl -lcrypto -lgpgme -lpthread -lz -lupnp
} }
linux-g++-64 { linux-g++-64 {
OBJECTS_DIR = temp/linux-g++-64/obj OBJECTS_DIR = temp/linux-g++-64/obj
QMAKE_LFLAGS += -L"../../../../lib/linux-g++-64"
CONFIG += version_detail_bash_script CONFIG += version_detail_bash_script
LIBS += -L"../../../../lib" -lretroshare -lssl -lcrypto -lgpgme -lpthread -lminiupnpc -lz LIBS += ../../libretroshare/src/lib/libretroshare.a
LIBS += -lssl -lcrypto -lgpgme -lpthread -lz -lupnp
} }
version_detail_bash_script { version_detail_bash_script {