From fb4f206427f03b92c5b985cd22810777a927bdbf Mon Sep 17 00:00:00 2001 From: Gioacchino Mazzurco Date: Wed, 24 Apr 2019 18:08:35 +0200 Subject: [PATCH] Attempt to detect best UPnP library available Because we don't support libupnp-1.8.x yet avoid using that library If libupnp-1.6.x is available use that, if not try to use miniupnc if if unavailble print a warning and disable RetroShare UPnP support --- libretroshare/src/libretroshare.pro | 12 ++++--- libretroshare/src/rsserver/rsinit.cc | 2 ++ retroshare.pri | 51 +++++++++++++++++++++++++--- 3 files changed, 56 insertions(+), 9 deletions(-) diff --git a/libretroshare/src/libretroshare.pro b/libretroshare/src/libretroshare.pro index 8dce4c050..4a2b4e452 100644 --- a/libretroshare/src/libretroshare.pro +++ b/libretroshare/src/libretroshare.pro @@ -653,10 +653,14 @@ SOURCES += util/folderiterator.cc \ equals(RS_UPNP_LIB, miniupnpc) { HEADERS += upnp/upnputil.h upnp/upnphandler_miniupnp.h SOURCES += upnp/upnputil.c upnp/upnphandler_miniupnp.cc -} else { - HEADERS += upnp/UPnPBase.h upnp/upnphandler_linux.h - SOURCES += upnp/UPnPBase.cpp upnp/upnphandler_linux.cc - DEFINES *= RS_USE_LIBUPNP +} +equals(RS_UPNP_LIB, "upnp ixml") { ## libupnp-1.8.x + # Not supported yet +} +equals(RS_UPNP_LIB, "upnp ixml threadutil") { ## libupnp-1.6.x + HEADERS += upnp/UPnPBase.h upnp/upnphandler_linux.h + SOURCES += upnp/UPnPBase.cpp upnp/upnphandler_linux.cc + DEFINES *= RS_USE_LIBUPNP } # new gxs cache system diff --git a/libretroshare/src/rsserver/rsinit.cc b/libretroshare/src/rsserver/rsinit.cc index 250d404af..29c9b38aa 100644 --- a/libretroshare/src/rsserver/rsinit.cc +++ b/libretroshare/src/rsserver/rsinit.cc @@ -1586,9 +1586,11 @@ int RsServer::StartupRetroShare() mNetMgr->addNetListener(mProxyStack); #endif +#if defined(RS_USE_LIBMINIUPNPC) || defined(RS_USE_LIBUPNP) // Original UPnP Interface. pqiNetAssistFirewall *mUpnpMgr = new upnphandler(); mNetMgr->addNetAssistFirewall(1, mUpnpMgr); +#endif // defined(RS_USE_LIBMINIUPNPC) || defined(RS_USE_LIBUPNP) } /**************************************************************************/ diff --git a/retroshare.pri b/retroshare.pri index 62aeff63b..f38505652 100644 --- a/retroshare.pri +++ b/retroshare.pri @@ -203,10 +203,17 @@ no_rs_broadcast_discovery:CONFIG -= rs_broadcast_discovery # use (pthread, "") usually depends on platform. isEmpty(RS_THREAD_LIB):RS_THREAD_LIB = pthread -# Specify UPnP library to use appending the following assignation to qmake -# command line 'RS_UPNP_LIB=miniupnpc' the name of the UPNP library to use -# (miniupnpc, "upnp ixml threadutil") usually depends on platform. -isEmpty(RS_UPNP_LIB):RS_UPNP_LIB = upnp ixml threadutil +# Specify UPnP library to use, appending the following assignation to qmake +# command line +# 'RS_UPNP_LIB=none' do not compile UPnP support +# 'RS_UPNP_LIB=miniupnpc' to use miniupnpc +# 'RS_UPNP_LIB="upnp ixml threadutil"' to use libupnp-1.6.x +# 'RS_UPNP_LIB="upnp ixml"' to use libupnp-1.8.x +# Which library is better suited usually depends on the platform. +# See http://miniupnp.free.fr/ and http://pupnp.sourceforge.net/ for more +# information about the libraries. Autodetection is attempted by default. +#RS_UPNP_LIB= + ########################################################################################################################################################### # @@ -302,7 +309,7 @@ defineReplace(linkStaticLibs) { return($$retSlib) } -## This function return pretarget deps for the static the libraries contained in +## This function return pretarget deps for the static libraries contained in ## the variable given as paramether. defineReplace(pretargetStaticLibs) { libsVarName = $$1 @@ -705,6 +712,40 @@ macx-* { QT += macextras } +# If not yet defined attempt UPnP library autodetection should works at least +# for miniupnc libupnp-1.6.x and libupnp-1.8.x +isEmpty(RS_UPNP_LIB) { + __TEMP_UPNP_LIBS = upnp ixml threadutil + for(mLib, __TEMP_UPNP_LIBS) { + attemptPath=$$findFileInPath(lib$${mLib}.a, QMAKE_LIBDIR) + isEmpty(attemptPath):attemptPath=$$findFileInPath(lib$${mLib}.so, QMAKE_LIBDIR) + !isEmpty(attemptPath):RS_UPNP_LIB += $${mLib} + } + + ## Workaround as libupnp-1.8.x is not supported yet + equals(RS_UPNP_LIB, "upnp ixml"):RS_UPNP_LIB= + ## END Workaround as libupnp-1.8.x is not supported yet + + isEmpty(RS_UPNP_LIB) { + __TEMP_UPNP_LIBS=$$findFileInPath(libminiupnpc.a, QMAKE_LIBDIR) + !isEmpty(__TEMP_UPNP_LIBS):RS_UPNP_LIB=miniupnpc + __TEMP_UPNP_LIBS=$$findFileInPath(libminiupnpc.so, QMAKE_LIBDIR) + !isEmpty(__TEMP_UPNP_LIBS):RS_UPNP_LIB=miniupnpc + } + + isEmpty(RS_UPNP_LIB) { + warning("RS_UPNP_LIB detection failed, UPnP support disabled!") + } else { + message("Autodetected RS_UPNP_LIB=$$RS_UPNP_LIB") + } +} + +equals(RS_UPNP_LIB, none):RS_UPNP_LIB= +equals(RS_UPNP_LIB, miniupnpc):DEFINES*=RS_USE_LIBMINIUPNPC +equals(RS_UPNP_LIB, "upnp ixml"):DEFINES*=RS_USE_LIBUPNP_1_8_X +## libupnp-1.6.x +equals(RS_UPNP_LIB, "upnp ixml threadutil"):DEFINES*=RS_USE_LIBUPNP + ## Retrocompatibility assignations, get rid of this ASAP isEmpty(BIN_DIR) : BIN_DIR = $${RS_BIN_DIR}