From f69247bd3ca045b87e5ecf5d1c454181b59ecf5b Mon Sep 17 00:00:00 2001 From: Peter Volkov Date: Tue, 28 Jun 2011 18:26:11 +0400 Subject: [PATCH 3/3] Allow usage of system miniupnp. --- cli/Makefile.am | 2 +- configure.ac | 73 ++++++++++++++++++++++++++++++++++++++++++- daemon/Makefile.am | 2 +- gtk/Makefile.am | 2 +- libtransmission/Makefile.am | 3 +- libtransmission/upnp.c | 25 +++++++++++++++ qt/config.in | 2 + qt/qtr.pro | 2 +- third-party/Makefile.am | 5 ++- utils/Makefile.am | 2 +- 10 files changed, 110 insertions(+), 8 deletions(-) diff --git a/cli/Makefile.am b/cli/Makefile.am index 9d618f2..8af71e6 100644 --- a/cli/Makefile.am +++ b/cli/Makefile.am @@ -18,8 +18,8 @@ transmission_cli_SOURCES = cli.c transmission_cli_LDADD = \ $(top_builddir)/libtransmission/libtransmission.a \ + @LIBUPNP_LIBS@ \ $(top_builddir)/third-party/libnatpmp/libnatpmp.a \ - $(top_builddir)/third-party/miniupnp/libminiupnp.a \ @DHT_LIBS@ \ @LIBUTP_LIBS@ \ @LIBEVENT_LIBS@ \ diff --git a/configure.ac b/configure.ac index 57acb9d..417b6ef 100644 --- a/configure.ac +++ b/configure.ac @@ -227,6 +227,77 @@ AC_MSG_RESULT([$build_utp]) dnl ---------------------------------------------------------------------------- dnl +dnl Allow usage of system miniupnp library +LIBUPNP_CFLAGS="-I\$(top_srcdir)/third-party/" +LIBUPNP_LIBS="\$(top_builddir)/third-party/miniupnp/libminiupnp.a" +LIBUPNP_LIBS_QT="\$\${TRANSMISSION_TOP}/third-party/miniupnp/libminiupnp.a" +build_bundled_miniupnp="yes" +AC_ARG_ENABLE([external-miniupnp], + AS_HELP_STRING([--enable-external-miniupnp],[Use system external-miniupnp]), + [want_external_miniupnp=${enableval}], + [want_external_miniupnp=no]) +if test "x$want_external_miniupnp" != "xno" ; then + AC_DEFINE([SYSTEM_MINIUPNP]) + ac_save_LIBS="$LIBS" + LIBS="-lminiupnpc" + # Check miniupnp 1.5 + AC_TRY_LINK([ + #include + #include + #include + ],[ + struct UPNPDev * devlist; + struct UPNPUrls urls; + struct IGDdatas data; + char lanaddr[16]; + char portStr[8]; + char intPort[8]; + char intClient[16]; + upnpDiscover( 2000, NULL, NULL, 0 ); + UPNP_GetValidIGD( devlist, &urls, &data, lanaddr, sizeof( lanaddr ) ); + UPNP_GetSpecificPortMappingEntry( urls.controlURL, data.first.servicetype, + portStr, "TCP", intClient, intPort ); + ],[ + AC_DEFINE(HAVE_MINIUPNP_15, 1, [Define to 1 if you have miniupnpc version 1.5]) + build_bundled_miniupnp="no"]) + + # Check miniupnp 1.6 + AC_TRY_LINK([ + #include + #include + #include + #include + ],[ + struct UPNPDev * devlist; + struct UPNPUrls urls; + struct IGDdatas data; + char lanaddr[16]; + char portStr[8]; + char intPort[8]; + char intClient[16]; + upnpDiscover( 2000, NULL, NULL, 0, 0, &errno ); + UPNP_GetValidIGD( devlist, &urls, &data, lanaddr, sizeof( lanaddr ) ); + UPNP_GetSpecificPortMappingEntry( urls.controlURL, data.first.servicetype, + portStr, "TCP", intClient, intPort, NULL, NULL, NULL ); + ],[ + AC_DEFINE(HAVE_MINIUPNP_16, 1, [Define to 1 if you have miniupnpc version 1.6]) + build_bundled_miniupnp="no"]) + + if test "x$build_bundled_miniupnp" = "xno" ; then + LIBUPNP_CFLAGS="" + LIBUPNP_LIBS="-lminiupnpc" + LIBUPNP_LIBS_QT="-lminiupnpc" + else + AC_MSG_ERROR("Requested system libminiupnp but it is not found") + fi + LIBS="$ac_save_LIBS" +fi +AM_CONDITIONAL([BUILD_MINIUPNP],[test "x$build_bundled_miniupnp" = "xyes"]) +AC_SUBST(LIBUPNP_CFLAGS) +AC_SUBST(LIBUPNP_LIBS) +AC_SUBST(LIBUPNP_LIBS_QT) +dnl ---------------------------------------------------------------------------- +dnl dnl detection for the GTK+ client PKG_CHECK_MODULES(GTK, diff --git a/daemon/Makefile.am b/daemon/Makefile.am index 9e2a10a..7a5e085 100644 --- a/daemon/Makefile.am +++ b/daemon/Makefile.am @@ -20,7 +20,7 @@ bin_PROGRAMS = \ LDADD = \ $(top_builddir)/libtransmission/libtransmission.a \ - $(top_builddir)/third-party/miniupnp/libminiupnp.a \ + @LIBUPNP_LIBS@ \ $(top_builddir)/third-party/libnatpmp/libnatpmp.a \ @DHT_LIBS@ \ @LIBUTP_LIBS@ \ diff --git a/gtk/Makefile.am b/gtk/Makefile.am index a86a440..abf3cd1 100644 --- a/gtk/Makefile.am +++ b/gtk/Makefile.am @@ -84,7 +84,7 @@ dist_man_MANS = transmission-gtk.1 transmission_gtk_LDADD = \ $(top_builddir)/libtransmission/libtransmission.a \ - $(top_builddir)/third-party/miniupnp/libminiupnp.a \ + @LIBUPNP_LIBS@ \ $(top_builddir)/third-party/libnatpmp/libnatpmp.a \ @LIBCANBERRA_LIBS@ \ @GCONF2_LIBS@ \ diff --git a/libtransmission/Makefile.am b/libtransmission/Makefile.am index 0dd244a..a68349b 100644 --- a/libtransmission/Makefile.am +++ b/libtransmission/Makefile.am @@ -8,6 +8,7 @@ AM_CPPFLAGS = \ AM_CFLAGS = \ @DHT_CFLAGS@ \ @LIBUTP_CFLAGS@ \ + @LIBUPNP_CFLAGS@ \ @LIBEVENT_CFLAGS@ \ @LIBCURL_CFLAGS@ \ @OPENSSL_CFLAGS@ \ @@ -139,7 +140,7 @@ apps_ldflags = \ apps_ldadd = \ ./libtransmission.a \ - $(top_builddir)/third-party/miniupnp/libminiupnp.a \ + @LIBUPNP_LIBS@ \ $(top_builddir)/third-party/libnatpmp/libnatpmp.a \ @INTLLIBS@ \ @DHT_LIBS@ \ diff --git a/libtransmission/upnp.c b/libtransmission/upnp.c index 2059864..a675b7c 100644 --- a/libtransmission/upnp.c +++ b/libtransmission/upnp.c @@ -13,8 +13,13 @@ #include #include +#ifdef SYSTEM_MINIUPNP +#include +#include +#else #include #include +#endif #include "transmission.h" #include "port-forwarding.h" @@ -97,7 +102,11 @@ tr_upnpPulse( tr_upnp * handle, { struct UPNPDev * devlist; errno = 0; +#ifdef HAVE_MINIUPNP_16 devlist = upnpDiscover( 2000, NULL, NULL, 0, 0, &errno ); +#else + devlist = upnpDiscover( 2000, NULL, NULL, 0 ); +#endif if( devlist == NULL ) { tr_ndbg( @@ -144,9 +153,17 @@ tr_upnpPulse( tr_upnp * handle, tr_snprintf( portStr, sizeof( portStr ), "%d", handle->port ); if( UPNP_GetSpecificPortMappingEntry( handle->urls.controlURL, handle->data.first.servicetype, +#ifdef HAVE_MINIUPNP_16 portStr, "TCP", intClient, intPort, NULL, NULL, NULL ) != UPNPCOMMAND_SUCCESS || +#else + portStr, "TCP", intClient, intPort ) != UPNPCOMMAND_SUCCESS || +#endif UPNP_GetSpecificPortMappingEntry( handle->urls.controlURL, handle->data.first.servicetype, +#ifdef HAVE_MINIUPNP_16 portStr, "UDP", intClient, intPort, NULL, NULL, NULL ) != UPNPCOMMAND_SUCCESS ) +#else + portStr, "UDP", intClient, intPort ) != UPNPCOMMAND_SUCCESS ) +#endif { tr_ninf( getKey( ), _( "Port %d isn't forwarded" ), handle->port ); handle->isMapped = false; @@ -198,7 +215,11 @@ tr_upnpPulse( tr_upnp * handle, err_tcp = UPNP_AddPortMapping( handle->urls.controlURL, handle->data.first.servicetype, portStr, portStr, handle->lanaddr, +#ifdef HAVE_MINIUPNP_16 desc, "TCP", NULL, NULL ); +#else + desc, "TCP", NULL ); +#endif if( err_tcp ) tr_ndbg( getKey( ), "TCP Port forwarding failed with error %d (errno %d - %s)", err_tcp, errno, tr_strerror( errno ) ); @@ -207,7 +228,11 @@ tr_upnpPulse( tr_upnp * handle, err_udp = UPNP_AddPortMapping( handle->urls.controlURL, handle->data.first.servicetype, portStr, portStr, handle->lanaddr, +#ifdef HAVE_MINIUPNP_16 desc, "UDP", NULL, NULL ); +#else + desc, "UDP", NULL ); +#endif if( err_udp ) tr_ndbg( getKey( ), "UDP Port forwarding failed with error %d (errno %d - %s)", err_udp, errno, tr_strerror( errno ) ); diff --git a/qt/config.in b/qt/config.in index 3340d1a..25851ea 100644 --- a/qt/config.in +++ b/qt/config.in @@ -1 +1,3 @@ LIBUTP_LIBS = @LIBUTP_LIBS_QT@ +MINIUPNP_LIBS = @LIBUPNP_LIBS_QT@ + diff --git a/qt/qtr.pro b/qt/qtr.pro index 4e28e98..8f6e659 100644 --- a/qt/qtr.pro +++ b/qt/qtr.pro @@ -23,7 +23,7 @@ INCLUDEPATH += $${TRANSMISSION_TOP} LIBS += $${TRANSMISSION_TOP}/libtransmission/libtransmission.a LIBS += $${LIBUTP_LIBS} LIBS += $${TRANSMISSION_TOP}/third-party/dht/libdht.a -LIBS += $${TRANSMISSION_TOP}/third-party/miniupnp/libminiupnp.a +LIBS += $${MINIUPNP_LIBS} LIBS += $${TRANSMISSION_TOP}/third-party/libnatpmp/libnatpmp.a unix: LIBS += -L$${EVENT_TOP}/lib -lz -lrt win32:DEFINES += QT_DBUS diff --git a/third-party/Makefile.am b/third-party/Makefile.am index 39eb5ee..fcf1369 100644 --- a/third-party/Makefile.am +++ b/third-party/Makefile.am @@ -1,11 +1,14 @@ if BUILD_UTP UTP_DIR = libutp endif +if BUILD_MINIUPNP + MINIUPNP_DIR = miniupnp +endif SUBDIRS = \ dht \ libnatpmp \ - miniupnp \ + $(MINIUPNP_DIR) \ $(UTP_DIR) EXTRA_DIST = \ diff --git a/utils/Makefile.am b/utils/Makefile.am index 896cb2b..1f687ed 100644 --- a/utils/Makefile.am +++ b/utils/Makefile.am @@ -26,7 +26,7 @@ dist_man_MANS = \ transmission_create_LDADD = \ $(top_builddir)/libtransmission/libtransmission.a \ - $(top_builddir)/third-party/miniupnp/libminiupnp.a \ + @LIBUPNP_LIBS@ \ $(top_builddir)/third-party/libnatpmp/libnatpmp.a \ @INTLLIBS@ \ @DHT_LIBS@ \ -- 1.7.3.4