if test "x$have_utp" = "xyes"; then
LIBUTP_CFLAGS="-I\$(top_srcdir)/third-party/"
LIBUTP_LIBS="\$(top_builddir)/third-party/libutp/libutp.a"
- if test "x$libutp_extra_libs" != "x" ; then
- LIBUTP_LIBS="$LIBUTP_LIBS $libutp_extra_libs"
- fi
+ if test "x$libutp_extra_libs" != "x" ; then
+ LIBUTP_LIBS="$LIBUTP_LIBS $libutp_extra_libs"
+ fi
AC_DEFINE([WITH_UTP],[1])
build_utp="yes"
else
AC_MSG_RESULT([$build_utp])
+dnl
+dnl look for preinstalled miniupnpc...
+dnl
+
+AC_MSG_CHECKING([supported miniupnp library])
+upnp_version="none"
+ac_save_LIBS="$LIBS"
+LIBS="-lminiupnpc"
+# See if the OS has its miniupnp 1.5 installed
+AC_TRY_LINK([
+ #include <stdlib.h>
+ #include <miniupnpc/miniupnpc.h>
+ #include <miniupnpc/upnpcommands.h>
+],[
+ 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])
+upnp_version="1.5"])
+
+# See if the OS has its miniupnp 1.6 installed
+AC_TRY_LINK([
+ #include <stdlib.h>
+ #include <errno.h>
+ #include <miniupnpc/miniupnpc.h>
+ #include <miniupnpc/upnpcommands.h>
+],[
+ 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])
+upnp_version="1.6"])
+
+# ... and the results of our tests
+LIBS="$ac_save_LIBS"
+AC_MSG_RESULT([$upnp_version])
+AM_CONDITIONAL([BUILD_MINIUPNP],[test "x$upnp_version" = "xnone"])
+if test "x$upnp_version" = "xnone" ; then
+ 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"
+ dnl because this is the version that we bundle...
+ AC_DEFINE(HAVE_MINIUPNP_16, 1, [Define to 1 if you have miniupnpc version 1.6])
+else
+ AC_DEFINE([SYSTEM_MINIUPNP])
+ LIBUPNP_CFLAGS=""
+ LIBUPNP_LIBS="-lminiupnpc"
+ LIBUPNP_LIBS_QT="-lminiupnpc"
+fi
+AC_SUBST(LIBUPNP_CFLAGS)
+AC_SUBST(LIBUPNP_LIBS)
+AC_SUBST(LIBUPNP_LIBS_QT)
+
+
dnl ----------------------------------------------------------------------------
dnl
dnl detection for the GTK+ client
libtransmission/Makefile
utils/Makefile
third-party/Makefile
- third-party/miniupnp/Makefile
third-party/libnatpmp/Makefile
third-party/dht/Makefile
macosx/Makefile
po/Makefile.in])
dnl Maybe build libutp...
-AM_CONDITIONAL([CONDITIONAL],[test "x$build_utp" = "xyes"])
-AM_COND_IF([CONDITIONAL],
+AM_CONDITIONAL([LIBUTP_CONDITIONAL],[test "x$build_utp" = "xyes"])
+AM_COND_IF([LIBUTP_CONDITIONAL],
[AC_CONFIG_FILES([third-party/libutp/Makefile])])
+dnl Maybe build miniupnpc...
+AM_CONDITIONAL([UPNP_CONDITIONAL],[test "x$upnp_version" = "xnone"])
+AM_COND_IF([UPNP_CONDITIONAL],
+ [AC_CONFIG_FILES([third-party/miniupnp/Makefile])])
+
AC_OUTPUT
echo "
#include <assert.h>
#include <errno.h>
-#include <miniupnp/miniupnpc.h>
-#include <miniupnp/upnpcommands.h>
+#ifdef SYSTEM_MINIUPNP
+ #include <miniupnpc/miniupnpc.h>
+ #include <miniupnpc/upnpcommands.h>
+#else
+ #include <miniupnp/miniupnpc.h>
+ #include <miniupnp/upnpcommands.h>
+#endif
#include "transmission.h"
#include "port-forwarding.h"
tr_free( handle );
}
+/**
+*** Wrappers for miniupnpc functions
+**/
+
+static struct UPNPDev *
+tr_upnpDiscover( int msec )
+{
+ int err = 0;
+ struct UPNPDev * ret = NULL;
+
+#if defined(HAVE_MINIUPNP_16)
+ ret = upnpDiscover( msec, NULL, NULL, 0, 0, &err );
+#elif defined(HAVE_MINIUPNP_15)
+ ret = upnpDiscover( msec, NULL, NULL, 0 );
+#else
+ ret = UPNPCOMMAND_UNKNOWN_ERROR;
+#endif
+
+ if( ret != UPNPCOMMAND_SUCCESS )
+ tr_ndbg( getKey( ), "upnpDiscover failed (errno %d - %s)", err, tr_strerror( err ) );
+
+ return ret;
+}
+
+static int
+tr_upnpGetSpecificPortMappingEntry( tr_upnp * handle, const char * proto )
+{
+ int err;
+ char intClient[16];
+ char intPort[16];
+ char portStr[16];
+
+ *intClient = '\0';
+ *intPort = '\0';
+
+ tr_snprintf( portStr, sizeof( portStr ), "%d", (int)handle->port );
+
+#if defined(HAVE_MINIUPNP_16)
+ err = UPNP_GetSpecificPortMappingEntry( handle->urls.controlURL, handle->data.first.servicetype, portStr, proto, intClient, intPort, NULL, NULL, NULL );
+#elif defined(HAVE_MINIUPNP_15)
+ err = UPNP_GetSpecificPortMappingEntry( handle->urls.controlURL, handle->data.first.servicetype, portStr, proto, intClient, intPort );
+#else
+ err = UPNPCOMMAND_UNKNOWN_ERROR;
+#endif
+
+ return err;
+}
+
+static int
+tr_upnpAddPortMapping( const tr_upnp * handle, const char * proto, tr_port port, const char * desc )
+{
+ int err;
+ const int old_errno = errno;
+ char portStr[16];
+ errno = 0;
+
+ tr_snprintf( portStr, sizeof( portStr ), "%d", (int)port );
+
+#if defined(HAVE_MINIUPNP_16)
+ err = UPNP_AddPortMapping( handle->urls.controlURL, handle->data.first.servicetype, portStr, portStr, handle->lanaddr, desc, proto, NULL, NULL );
+#elif defined(HAVE_MINIUPNP_15)
+ err = UPNP_AddPortMapping( handle->urls.controlURL, handle->data.first.servicetype, portStr, portStr, handle->lanaddr, desc, proto, NULL );
+#else
+ err = UPNPCOMMAND_UNKNOWN_ERROR;
+#endif
+
+ if( err )
+ tr_ndbg( getKey( ), "%s Port forwarding failed with error %d (errno %d - %s)", proto, err, errno, tr_strerror( errno ) );
+
+ errno = old_errno;
+ return err;
+}
+
+static void
+tr_upnpDeletePortMapping( const tr_upnp * handle, const char * proto, tr_port port )
+{
+ char portStr[16];
+
+ tr_snprintf( portStr, sizeof( portStr ), "%d", (int)port );
+
+ UPNP_DeletePortMapping( handle->urls.controlURL,
+ handle->data.first.servicetype,
+ portStr, proto, NULL );
+}
+
/**
***
**/
if( isEnabled && ( handle->state == TR_UPNP_DISCOVER ) )
{
struct UPNPDev * devlist;
- errno = 0;
- devlist = upnpDiscover( 2000, NULL, NULL, 0, 0, &errno );
- if( devlist == NULL )
- {
- tr_ndbg(
- getKey( ), "upnpDiscover failed (errno %d - %s)", errno,
- tr_strerror( errno ) );
- }
+
+ devlist = tr_upnpDiscover( 2000 );
+
errno = 0;
if( UPNP_GetValidIGD( devlist, &handle->urls, &handle->data,
handle->lanaddr, sizeof( handle->lanaddr ) ) == UPNP_IGD_VALID_CONNECTED )
if( isEnabled && handle->isMapped && doPortCheck )
{
- char portStr[8];
- char intPort[8];
- char intClient[16];
-
- tr_snprintf( portStr, sizeof( portStr ), "%d", handle->port );
- if( UPNP_GetSpecificPortMappingEntry( handle->urls.controlURL, handle->data.first.servicetype,
- portStr, "TCP", intClient, intPort, NULL, NULL, NULL ) != UPNPCOMMAND_SUCCESS ||
- UPNP_GetSpecificPortMappingEntry( handle->urls.controlURL, handle->data.first.servicetype,
- portStr, "UDP", intClient, intPort, NULL, NULL, NULL ) != UPNPCOMMAND_SUCCESS )
+ if( ( tr_upnpGetSpecificPortMappingEntry( handle, "TCP" ) != UPNPCOMMAND_SUCCESS ) ||
+ ( tr_upnpGetSpecificPortMappingEntry( handle, "UDP" ) != UPNPCOMMAND_SUCCESS ) )
{
tr_ninf( getKey( ), _( "Port %d isn't forwarded" ), handle->port );
handle->isMapped = false;
if( handle->state == TR_UPNP_UNMAP )
{
- char portStr[16];
- tr_snprintf( portStr, sizeof( portStr ), "%d", handle->port );
- UPNP_DeletePortMapping( handle->urls.controlURL,
- handle->data.first.servicetype,
- portStr, "TCP", NULL );
- UPNP_DeletePortMapping( handle->urls.controlURL,
- handle->data.first.servicetype,
- portStr, "UDP", NULL );
+ tr_upnpDeletePortMapping( handle, "TCP", handle->port );
+ tr_upnpDeletePortMapping( handle, "UDP", handle->port );
+
tr_ninf( getKey( ),
- _(
- "Stopping port forwarding through \"%s\", service \"%s\"" ),
+ _( "Stopping port forwarding through \"%s\", service \"%s\"" ),
handle->urls.controlURL, handle->data.first.servicetype );
+
handle->isMapped = 0;
handle->state = TR_UPNP_IDLE;
handle->port = -1;
handle->isMapped = 0;
else
{
- char portStr[16];
char desc[64];
- const int prev_errno = errno;
- tr_snprintf( portStr, sizeof( portStr ), "%d", port );
tr_snprintf( desc, sizeof( desc ), "%s at %d", TR_NAME, port );
- errno = 0;
- err_tcp = UPNP_AddPortMapping( handle->urls.controlURL,
- handle->data.first.servicetype,
- portStr, portStr, handle->lanaddr,
- desc, "TCP", NULL, NULL );
- if( err_tcp )
- tr_ndbg( getKey( ), "TCP Port forwarding failed with error %d (errno %d - %s)",
- err_tcp, errno, tr_strerror( errno ) );
-
- errno = 0;
- err_udp = UPNP_AddPortMapping( handle->urls.controlURL,
- handle->data.first.servicetype,
- portStr, portStr, handle->lanaddr,
- desc, "UDP", NULL, NULL );
- if( err_udp )
- tr_ndbg( getKey( ), "UDP Port forwarding failed with error %d (errno %d - %s)",
- err_udp, errno, tr_strerror( errno ) );
-
- errno = prev_errno;
+ err_tcp = tr_upnpAddPortMapping( handle, "TCP", port, desc );
+ err_udp = tr_upnpAddPortMapping( handle, "UDP", port, desc );
+
handle->isMapped = !err_tcp | !err_udp;
}
tr_ninf( getKey( ),