Changeset 12957


Ignore:
Timestamp:
Oct 9, 2011, 2:05:52 AM (10 years ago)
Author:
jordan
Message:

(trunk libT) #4323 "Allow usage of system miniupnpc" -- fixed.

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/cli/Makefile.am

    r11920 r12957  
    2020    $(top_builddir)/libtransmission/libtransmission.a \
    2121    $(top_builddir)/third-party/libnatpmp/libnatpmp.a \
    22     $(top_builddir)/third-party/miniupnp/libminiupnp.a \
     22    @LIBUPNP_LIBS@ \
    2323    @DHT_LIBS@ \
    2424    @LIBUTP_LIBS@ \
  • trunk/configure.ac

    r12954 r12957  
    220220        LIBUTP_CFLAGS="-I\$(top_srcdir)/third-party/"
    221221        LIBUTP_LIBS="\$(top_builddir)/third-party/libutp/libutp.a"
    222         if test "x$libutp_extra_libs" != "x" ; then
    223            LIBUTP_LIBS="$LIBUTP_LIBS $libutp_extra_libs"
    224         fi
     222        if test "x$libutp_extra_libs" != "x" ; then
     223            LIBUTP_LIBS="$LIBUTP_LIBS $libutp_extra_libs"
     224        fi
    225225        AC_DEFINE([WITH_UTP],[1])
    226226        build_utp="yes"
     
    233233AM_CONDITIONAL([BUILD_UTP],[test "x$build_utp" = "xyes"])
    234234AC_MSG_RESULT([$build_utp])
     235
     236
     237dnl
     238dnl  look for preinstalled miniupnpc...
     239dnl
     240
     241AC_MSG_CHECKING([supported miniupnp library])
     242upnp_version="none"
     243ac_save_LIBS="$LIBS"
     244LIBS="-lminiupnpc"
     245# See if the OS has its miniupnp 1.5 installed
     246AC_TRY_LINK([
     247    #include <stdlib.h>
     248    #include <miniupnpc/miniupnpc.h>
     249    #include <miniupnpc/upnpcommands.h>
     250],[
     251    struct UPNPDev * devlist;
     252    struct UPNPUrls    urls;
     253    struct IGDdatas    data;
     254    char lanaddr[16];
     255    char portStr[8];
     256    char intPort[8];
     257    char intClient[16];
     258    upnpDiscover( 2000, NULL, NULL, 0 );
     259    UPNP_GetValidIGD( devlist, &urls, &data, lanaddr, sizeof( lanaddr ) ); 
     260    UPNP_GetSpecificPortMappingEntry( urls.controlURL, data.first.servicetype,
     261                        portStr, "TCP", intClient, intPort );
     262],[
     263AC_DEFINE(HAVE_MINIUPNP_15, 1, [Define to 1 if you have miniupnpc version 1.5])
     264upnp_version="1.5"])
     265 
     266# See if the OS has its miniupnp 1.6 installed
     267AC_TRY_LINK([
     268    #include <stdlib.h>
     269    #include <errno.h>
     270    #include <miniupnpc/miniupnpc.h>
     271    #include <miniupnpc/upnpcommands.h>
     272],[
     273    struct UPNPDev * devlist;
     274    struct UPNPUrls    urls;
     275    struct IGDdatas    data;
     276    char lanaddr[16];
     277    char portStr[8];
     278    char intPort[8];
     279    char intClient[16];
     280    upnpDiscover( 2000, NULL, NULL, 0, 0, &errno );
     281    UPNP_GetValidIGD( devlist, &urls, &data, lanaddr, sizeof( lanaddr ) ); 
     282    UPNP_GetSpecificPortMappingEntry( urls.controlURL, data.first.servicetype,
     283                        portStr, "TCP", intClient, intPort, NULL, NULL, NULL );
     284],[
     285AC_DEFINE(HAVE_MINIUPNP_16, 1, [Define to 1 if you have miniupnpc version 1.6])
     286upnp_version="1.6"])
     287
     288# ... and the results of our tests
     289LIBS="$ac_save_LIBS"
     290AC_MSG_RESULT([$upnp_version])
     291AM_CONDITIONAL([BUILD_MINIUPNP],[test "x$upnp_version" = "xnone"])
     292if test "x$upnp_version" = "xnone" ; then
     293    LIBUPNP_CFLAGS="-I\$(top_srcdir)/third-party/"
     294    LIBUPNP_LIBS="\$(top_builddir)/third-party/miniupnp/libminiupnp.a"
     295    LIBUPNP_LIBS_QT="\$\${TRANSMISSION_TOP}/third-party/miniupnp/libminiupnp.a"
     296    dnl because this is the version that we bundle...
     297    AC_DEFINE(HAVE_MINIUPNP_16, 1, [Define to 1 if you have miniupnpc version 1.6])
     298else
     299    AC_DEFINE([SYSTEM_MINIUPNP])
     300    LIBUPNP_CFLAGS="" 
     301    LIBUPNP_LIBS="-lminiupnpc"
     302    LIBUPNP_LIBS_QT="-lminiupnpc"
     303fi
     304AC_SUBST(LIBUPNP_CFLAGS)
     305AC_SUBST(LIBUPNP_LIBS)
     306AC_SUBST(LIBUPNP_LIBS_QT)
    235307
    236308
     
    409481                 utils/Makefile
    410482                 third-party/Makefile
    411                  third-party/miniupnp/Makefile
    412483                 third-party/libnatpmp/Makefile
    413484                 third-party/dht/Makefile
     
    426497
    427498dnl Maybe build libutp...
    428 AM_CONDITIONAL([CONDITIONAL],[test "x$build_utp" = "xyes"])
    429 AM_COND_IF([CONDITIONAL],
     499AM_CONDITIONAL([LIBUTP_CONDITIONAL],[test "x$build_utp" = "xyes"])
     500AM_COND_IF([LIBUTP_CONDITIONAL],
    430501           [AC_CONFIG_FILES([third-party/libutp/Makefile])])
     502
     503dnl Maybe build miniupnpc...
     504AM_CONDITIONAL([UPNP_CONDITIONAL],[test "x$upnp_version" = "xnone"])
     505AM_COND_IF([UPNP_CONDITIONAL],
     506           [AC_CONFIG_FILES([third-party/miniupnp/Makefile])])
    431507
    432508AC_OUTPUT
  • trunk/daemon/Makefile.am

    r11920 r12957  
    2121LDADD = \
    2222    $(top_builddir)/libtransmission/libtransmission.a \
    23     $(top_builddir)/third-party/miniupnp/libminiupnp.a \
     23    @LIBUPNP_LIBS@ \
    2424    $(top_builddir)/third-party/libnatpmp/libnatpmp.a \
    2525    @DHT_LIBS@ \
  • trunk/gtk/Makefile.am

    r12662 r12957  
    8585transmission_gtk_LDADD = \
    8686    $(top_builddir)/libtransmission/libtransmission.a \
    87     $(top_builddir)/third-party/miniupnp/libminiupnp.a \
     87    @LIBUPNP_LIBS@ \
    8888    $(top_builddir)/third-party/libnatpmp/libnatpmp.a \
    8989    @DHT_LIBS@ \
  • trunk/libtransmission/Makefile.am

    r12248 r12957  
    99    @DHT_CFLAGS@ \
    1010    @LIBUTP_CFLAGS@ \
     11    @LIBUPNP_CFLAGS@ \
    1112    @LIBEVENT_CFLAGS@ \
    1213    @LIBCURL_CFLAGS@ \
     
    140141apps_ldadd = \
    141142    ./libtransmission.a  \
    142     $(top_builddir)/third-party/miniupnp/libminiupnp.a \
     143    @LIBUPNP_LIBS@ \
    143144    $(top_builddir)/third-party/libnatpmp/libnatpmp.a \
    144145    @INTLLIBS@ \
  • trunk/libtransmission/upnp.c

    r12593 r12957  
    1414#include <errno.h>
    1515
    16 #include <miniupnp/miniupnpc.h>
    17 #include <miniupnp/upnpcommands.h>
     16#ifdef SYSTEM_MINIUPNP
     17  #include <miniupnpc/miniupnpc.h>
     18  #include <miniupnpc/upnpcommands.h>
     19#else
     20  #include <miniupnp/miniupnpc.h>
     21  #include <miniupnp/upnpcommands.h>
     22#endif
    1823
    1924#include "transmission.h"
     
    7580
    7681/**
     82***  Wrappers for miniupnpc functions
     83**/
     84
     85static struct UPNPDev *
     86tr_upnpDiscover( int msec )
     87{
     88    int err = 0;
     89    struct UPNPDev * ret = NULL;
     90
     91#if defined(HAVE_MINIUPNP_16)
     92    ret = upnpDiscover( msec, NULL, NULL, 0, 0, &err );
     93#elif defined(HAVE_MINIUPNP_15)
     94    ret = upnpDiscover( msec, NULL, NULL, 0 );
     95#else
     96    ret = UPNPCOMMAND_UNKNOWN_ERROR;
     97#endif
     98
     99    if( ret != UPNPCOMMAND_SUCCESS )
     100        tr_ndbg( getKey( ), "upnpDiscover failed (errno %d - %s)", err, tr_strerror( err ) );
     101
     102    return ret;
     103}
     104
     105static int
     106tr_upnpGetSpecificPortMappingEntry( tr_upnp * handle, const char * proto )
     107{
     108    int err;
     109    char intClient[16];
     110    char intPort[16];
     111    char portStr[16];
     112
     113    *intClient = '\0';
     114    *intPort = '\0';
     115
     116    tr_snprintf( portStr, sizeof( portStr ), "%d", (int)handle->port );
     117
     118#if defined(HAVE_MINIUPNP_16)
     119    err = UPNP_GetSpecificPortMappingEntry( handle->urls.controlURL, handle->data.first.servicetype, portStr, proto, intClient, intPort, NULL, NULL, NULL );
     120#elif defined(HAVE_MINIUPNP_15)
     121    err = UPNP_GetSpecificPortMappingEntry( handle->urls.controlURL, handle->data.first.servicetype, portStr, proto, intClient, intPort );
     122#else
     123    err = UPNPCOMMAND_UNKNOWN_ERROR;
     124#endif
     125
     126    return err;
     127}
     128
     129static int
     130tr_upnpAddPortMapping( const tr_upnp * handle, const char * proto, tr_port port, const char * desc )
     131{
     132    int err;
     133    const int old_errno = errno;
     134    char portStr[16];
     135    errno = 0;
     136
     137    tr_snprintf( portStr, sizeof( portStr ), "%d", (int)port );
     138
     139#if defined(HAVE_MINIUPNP_16)
     140    err = UPNP_AddPortMapping( handle->urls.controlURL, handle->data.first.servicetype, portStr, portStr, handle->lanaddr, desc, proto, NULL, NULL );
     141#elif defined(HAVE_MINIUPNP_15)
     142    err = UPNP_AddPortMapping( handle->urls.controlURL, handle->data.first.servicetype, portStr, portStr, handle->lanaddr, desc, proto, NULL );
     143#else
     144    err = UPNPCOMMAND_UNKNOWN_ERROR;
     145#endif
     146
     147    if( err )
     148        tr_ndbg( getKey( ), "%s Port forwarding failed with error %d (errno %d - %s)", proto, err, errno, tr_strerror( errno ) );
     149
     150    errno = old_errno;
     151    return err;
     152}
     153
     154static void
     155tr_upnpDeletePortMapping( const tr_upnp * handle, const char * proto, tr_port port )
     156{
     157    char portStr[16];
     158
     159    tr_snprintf( portStr, sizeof( portStr ), "%d", (int)port );
     160
     161    UPNP_DeletePortMapping( handle->urls.controlURL,
     162                            handle->data.first.servicetype,
     163                            portStr, proto, NULL );
     164}
     165
     166/**
    77167***
    78168**/
     
    97187    {
    98188        struct UPNPDev * devlist;
    99         errno = 0;
    100         devlist = upnpDiscover( 2000, NULL, NULL, 0, 0, &errno );
    101         if( devlist == NULL )
    102         {
    103             tr_ndbg(
    104                  getKey( ), "upnpDiscover failed (errno %d - %s)", errno,
    105                 tr_strerror( errno ) );
    106         }
     189
     190        devlist = tr_upnpDiscover( 2000 );
     191
    107192        errno = 0;
    108193        if( UPNP_GetValidIGD( devlist, &handle->urls, &handle->data,
     
    139224    if( isEnabled && handle->isMapped && doPortCheck )
    140225    {
    141         char portStr[8];
    142         char intPort[8];
    143         char intClient[16];
    144 
    145         tr_snprintf( portStr, sizeof( portStr ), "%d", handle->port );
    146         if( UPNP_GetSpecificPortMappingEntry( handle->urls.controlURL, handle->data.first.servicetype,
    147             portStr, "TCP", intClient, intPort, NULL, NULL, NULL ) != UPNPCOMMAND_SUCCESS  ||
    148             UPNP_GetSpecificPortMappingEntry( handle->urls.controlURL, handle->data.first.servicetype,
    149             portStr, "UDP", intClient, intPort, NULL, NULL, NULL ) != UPNPCOMMAND_SUCCESS )
     226        if( ( tr_upnpGetSpecificPortMappingEntry( handle, "TCP" ) != UPNPCOMMAND_SUCCESS ) ||
     227            ( tr_upnpGetSpecificPortMappingEntry( handle, "UDP" ) != UPNPCOMMAND_SUCCESS ) )
    150228        {
    151229            tr_ninf( getKey( ), _( "Port %d isn't forwarded" ), handle->port );
     
    156234    if( handle->state == TR_UPNP_UNMAP )
    157235    {
    158         char portStr[16];
    159         tr_snprintf( portStr, sizeof( portStr ), "%d", handle->port );
    160         UPNP_DeletePortMapping( handle->urls.controlURL,
    161                                 handle->data.first.servicetype,
    162                                 portStr, "TCP", NULL );
    163         UPNP_DeletePortMapping( handle->urls.controlURL,
    164                                 handle->data.first.servicetype,
    165                                 portStr, "UDP", NULL );
     236        tr_upnpDeletePortMapping( handle, "TCP", handle->port );
     237        tr_upnpDeletePortMapping( handle, "UDP", handle->port );
     238
    166239        tr_ninf( getKey( ),
    167                  _(
    168                      "Stopping port forwarding through \"%s\", service \"%s\"" ),
     240                 _( "Stopping port forwarding through \"%s\", service \"%s\"" ),
    169241                 handle->urls.controlURL, handle->data.first.servicetype );
     242
    170243        handle->isMapped = 0;
    171244        handle->state = TR_UPNP_IDLE;
     
    189262        else
    190263        {
    191             char portStr[16];
    192264            char desc[64];
    193             const int prev_errno = errno;
    194             tr_snprintf( portStr, sizeof( portStr ), "%d", port );
    195265            tr_snprintf( desc, sizeof( desc ), "%s at %d", TR_NAME, port );
    196266
    197             errno = 0;
    198             err_tcp = UPNP_AddPortMapping( handle->urls.controlURL,
    199                                        handle->data.first.servicetype,
    200                                        portStr, portStr, handle->lanaddr,
    201                                        desc, "TCP", NULL, NULL );
    202             if( err_tcp )
    203                 tr_ndbg( getKey( ), "TCP Port forwarding failed with error %d (errno %d - %s)",
    204                          err_tcp, errno, tr_strerror( errno ) );
    205 
    206             errno = 0;
    207             err_udp = UPNP_AddPortMapping( handle->urls.controlURL,
    208                                        handle->data.first.servicetype,
    209                                        portStr, portStr, handle->lanaddr,
    210                                        desc, "UDP", NULL, NULL );
    211             if( err_udp )
    212                 tr_ndbg( getKey( ), "UDP Port forwarding failed with error %d (errno %d - %s)",
    213                          err_udp, errno, tr_strerror( errno ) );
    214 
    215             errno = prev_errno;
     267            err_tcp = tr_upnpAddPortMapping( handle, "TCP", port, desc );
     268            err_udp = tr_upnpAddPortMapping( handle, "UDP", port, desc );
     269
    216270            handle->isMapped = !err_tcp | !err_udp;
    217271        }
  • trunk/qt/qtr.pro

    r12954 r12957  
    2424}
    2525LIBS += $${TRANSMISSION_TOP}/third-party/dht/libdht.a
    26 LIBS += $${TRANSMISSION_TOP}/third-party/miniupnp/libminiupnp.a
     26exists( $${TRANSMISSION_TOP}/third-party/miniupnp/Makefile ) {
     27    LIBS += $${TRANSMISSION_TOP}/third-party/miniupnp/libminiupnp.a
     28}
    2729LIBS += $${TRANSMISSION_TOP}/third-party/libnatpmp/libnatpmp.a
    2830unix: LIBS += -L$${EVENT_TOP}/lib -lz -lrt
  • trunk/third-party/Makefile.am

    r11960 r12957  
    11if BUILD_UTP
    22  UTP_DIR = libutp
     3endif
     4if BUILD_MINIUPNP
     5  MINIUPNP_DIR = miniupnp
    36endif
    47
     
    69  dht \
    710  libnatpmp \
    8   miniupnp \
     11  $(MINIUPNP_DIR) \
    912  $(UTP_DIR)
    1013
  • trunk/utils/Makefile.am

    r11920 r12957  
    2727transmission_create_LDADD = \
    2828    $(top_builddir)/libtransmission/libtransmission.a \
    29     $(top_builddir)/third-party/miniupnp/libminiupnp.a \
     29    @LIBUPNP_LIBS@ \
    3030    $(top_builddir)/third-party/libnatpmp/libnatpmp.a \
    3131    @INTLLIBS@ \
Note: See TracChangeset for help on using the changeset viewer.