wiki:BuildingTransmissionQtWindows/transmission-2.03-Qt-build.diff

Version 2 (modified by rb07, 12 years ago) (diff)

--

diff -NaurwX /home/rberber/diff-excludes.txt transmission-2.03-orig/configure.ac transmission-2.03/configure.ac --- transmission-2.03-orig/configure.ac 2010-07-20 23:13:51.000000000 -0500 +++ transmission-2.03/configure.ac 2010-07-21 17:08:45.000000000 -0500 @@ -407,7 +407,7 @@

have_msw="yes" CXXFLAGS="$CXXFLAGS -mms-bitfields -mwin32 -mwindows" CPPFLAGS="$CPPFLAGS -DWIN32 -D_WIN32 -DWIN32_LEAN_AND_MEAN"

  • LIBS="$LIBS -lshell32 -lws2_32"

+ LIBS="$LIBS -liphlpapi -lshell32 -lws2_32"

transmissionlocaledir="locale" if test -z "$host_alias"; then

hostaliaswindres=

diff -NaurwX /home/rberber/diff-excludes.txt transmission-2.03-orig/libtransmission/JSON_parser.h transmission-2.03/libtransmission/JSON_parser.h --- transmission-2.03-orig/libtransmission/JSON_parser.h 2010-07-20 23:13:41.000000000 -0500 +++ transmission-2.03/libtransmission/JSON_parser.h 2010-07-21 17:03:08.000000000 -0500 @@ -11,7 +11,7 @@

#include <stddef.h>

/* Windows DLL stuff */

-#ifdef _WIN32 +#if defined(WIN32) && !defined(STATICLIB)

# ifdef JSON_PARSER_DLL_EXPORTS # define JSON_PARSER_DLL_API declspec(dllexport) # else

diff -NaurwX /home/rberber/diff-excludes.txt transmission-2.03-orig/libtransmission/bencode.c transmission-2.03/libtransmission/bencode.c --- transmission-2.03-orig/libtransmission/bencode.c 2010-07-20 23:13:41.000000000 -0500 +++ transmission-2.03/libtransmission/bencode.c 2010-07-21 18:58:21.000000000 -0500 @@ -18,6 +18,10 @@

#include <stdlib.h> /* realpath() */ #include <string.h>

+#ifdef WIN32 /* tr_mkstemp() */ + #include <fcntl.h> +#endif +

#include <sys/types.h> /* stat() */ #include <sys/stat.h> /* stat() */ #include <locale.h>

@@ -1615,6 +1619,31 @@

return ret;

}

+/* portability wrapper for mkstemp(). */ +static int +tr_mkstemp( char * template ) +{ +#ifdef WIN32 + const int flags = O_RDWR | O_BINARY | O_CREAT | O_EXCL | _O_SHORT_LIVED; + const mode_t mode = _S_IREAD | _S_IWRITE; + mktemp( template ); + return open( template, flags, mode ); +#else + return mkstemp( template ); +#endif +} + +/* portability wrapper for fsync(). */ +static void +tr_fsync( int fd ) +{ +#ifdef WIN32 + _commit( fd ); +#else + fsync( fd ); +#endif +} +

int tr_bencToFile( const tr_benc * top, tr_fmt_mode mode, const char * filename ) {

@@ -1625,12 +1654,12 @@

/* follow symlinks to find the "real" file, to make sure the temporary

  • we build with mkstemp() is created on the right partition */
  • if( realpath( filename, buf ) != NULL )

+ if( tr_realpath( filename, buf ) != NULL )

filename = buf;

/* if the file already exists, try to move it out of the way & keep it as a backup */

  • tmp = tr_strdup_printf( "%s.tmp.XXXXXX", filename );
  • fd = mkstemp( tmp );

+ tmp = tr_strdup_printf( "%s_tmp.XXXXXX", filename ); + fd = tr_mkstemp( tmp );

if( fd >= 0 ) {

int len;

@@ -1639,7 +1668,7 @@

if( write( fd, str, len ) == (ssize_t)len ) {

  • fsync( fd );

+ tr_fsync( fd );

close( fd );

if( !unlink( filename )
( errno == ENOENT ) )

diff -NaurwX /home/rberber/diff-excludes.txt transmission-2.03-orig/libtransmission/blocklist.c transmission-2.03/libtransmission/blocklist.c --- transmission-2.03-orig/libtransmission/blocklist.c 2010-07-20 23:13:41.000000000 -0500 +++ transmission-2.03/libtransmission/blocklist.c 2010-07-21 19:04:45.000000000 -0500 @@ -15,7 +15,11 @@

#include <string.h>

#ifdef WIN32

+ #include <w32api.h> + #define WINVER WindowsXP

#include <windows.h>

+ #define PROT_READ PAGE_READONLY + #define MAP_PRIVATE FILE_MAP_COPY

#endif

#ifndef WIN32

@@ -80,18 +84,14 @@

if( stat( b->filename, &st ) == -1 )

return;

  • fd = open( b->filename, O_RDONLY );

+ fd = open( b->filename, O_RDONLY | O_BINARY );

if( fd == -1 ) {

tr_err( err_fmt, b->filename, tr_strerror( errno ) ); return;

}

-#ifndef WIN32

b->rules = mmap( NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0 );

-#else

  • b->rules = mmap( NULL, st.st_size, 0, 0, fd, 0 );

-#endif

if( !b->rules ) {

tr_err( err_fmt, b->filename, tr_strerror( errno ) );

@@ -315,7 +315,7 @@

return 0;

}

  • in = fopen( filename, "r" );

+ in = fopen( filename, "rb" );

if( !in ) {

tr_err( err_fmt, filename, tr_strerror( errno ) );

diff -NaurwX /home/rberber/diff-excludes.txt transmission-2.03-orig/libtransmission/fdlimit.c transmission-2.03/libtransmission/fdlimit.c --- transmission-2.03-orig/libtransmission/fdlimit.c 2010-07-20 23:13:41.000000000 -0500 +++ transmission-2.03/libtransmission/fdlimit.c 2010-07-21 19:06:47.000000000 -0500 @@ -125,7 +125,7 @@

#ifdef WIN32

  • HANDLE hFile = CreateFile?( filename, GENERIC_WRITE, 0, 0, CREATE_NEW, 0, 0 );

+ HANDLE hFile = CreateFile?( filename, GENERIC_WRITE, 0, 0, CREATE_NEW, FILE_FLAG_RANDOM_ACCESS, 0 );

if( hFile != INVALID_HANDLE_VALUE ) {

LARGE_INTEGER li;

diff -NaurwX /home/rberber/diff-excludes.txt transmission-2.03-orig/libtransmission/net.c transmission-2.03/libtransmission/net.c --- transmission-2.03-orig/libtransmission/net.c 2010-07-20 23:13:41.000000000 -0500 +++ transmission-2.03/libtransmission/net.c 2010-07-21 19:28:31.000000000 -0500 @@ -32,8 +32,8 @@

#include <sys/types.h>

#ifdef WIN32

  • #include <winsock2.h> /* inet_addr */
  • #include <WS2tcpip.h>

+ #define _WIN32_WINNT 0x0501 + #include <ws2tcpip.h>

#else

#include <sys/socket.h> #include <netinet/in.h>

@@ -64,7 +64,7 @@

const tr_address tr_inaddr_any = { TR_AF_INET, { { { { INADDR_ANY, 0x00, 0x00, 0x00 } } } } };

#ifdef WIN32

-static const char * +const char *

inet_ntop( int af, const void *src, char *dst, socklen_t cnt ) {

if (af == AF_INET)

@@ -90,29 +90,45 @@

return NULL;

}

-static int +int

inet_pton(int af, const char *src, void *dst) {

  • struct addrinfo hints;
  • struct addrinfo *res;
  • struct addrinfo *ressave;

+ struct addrinfo hints, *res, *ressave; + struct sockaddr_in * s4; + struct sockaddr_in6 * s6;

memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_family = af;

+ hints.ai_flags = AI_NUMERICHOST;

  • if (getaddrinfo(src, NULL, &hints, &res) != 0)

+ if( getaddrinfo( src, NULL, &hints, &res ) ) { + if( WSAGetLastError() == WSAHOST_NOT_FOUND ) + return 0; + else { + errno = EAFNOSUPPORT;

return -1;

+ } + }

ressave = res;

-

  • while (res)
  • {
  • memcpy(dst, res->ai_addr, res->ai_addrlen);

+ while( res ) { + switch (res->ai_family) { + case AF_INET: + s4 = (struct sockaddr_in *) res->ai_addr; + memcpy( dst, &s4->sin_addr, sizeof( struct in_addr ) ); + break; + case AF_INET6: + s6 = (struct sockaddr_in6 *) res->ai_addr; + memcpy( dst, &s6->sin6_addr, sizeof( struct in6_addr ) ); + break; + default: /* AF_UNSPEC, AF_NETBIOS */ + break; + }

res = res->ai_next;

}

freeaddrinfo(ressave);

  • return 0;

+ return 1;

}

#endif

@@ -133,6 +149,18 @@

}

}

+char * +tr_net_strerror( char * buf, size_t buflen, int err ) +{ + *buf = '\0'; +#ifdef WIN32 + FormatMessage?( FORMAT_MESSAGE_FROM_SYSTEM, NULL, err, 0, buf, buflen, NULL ); +#else + tr_strlcpy( buf, tr_strerror( err ), buflen ); +#endif + return buf; +} +

const char * tr_ntop( const tr_address * src, char * dst, int size ) {

diff -NaurwX /home/rberber/diff-excludes.txt transmission-2.03-orig/libtransmission/net.h transmission-2.03/libtransmission/net.h --- transmission-2.03-orig/libtransmission/net.h 2010-07-20 23:13:41.000000000 -0500 +++ transmission-2.03/libtransmission/net.h 2010-07-21 19:27:10.000000000 -0500 @@ -31,9 +31,7 @@

#ifdef WIN32

#include <inttypes.h>

  • #include <winsock2.h>
  • #include <WS2tcpip.h>
  • typedef int socklen_t;

+ #include <ws2tcpip.h>

#else

#include <sys/types.h> #include <sys/socket.h>

@@ -42,6 +40,7 @@

#endif

#ifdef WIN32

+ #define EADDRINUSE WSAEADDRINUSE

#define ECONNREFUSED WSAECONNREFUSED #define ECONNRESET WSAECONNRESET #define EHOSTUNREACH WSAEHOSTUNREACH

@@ -123,7 +122,21 @@

void tr_netInit( void );

+/ + * @brief get a human-representable string representing the network error. + * @param err an errno on Unix/Linux? and an WSAError on win32) + */ +char* tr_net_strerror( char * buf, size_t buflen, int err ); +

const unsigned char *tr_globalIPv6( void );

+#if defined( WIN32) && !defined(QT_DLL) +/* The QT exclusion is because something clashes whith the next include */ +#include <ws2tcpip.h> /* socklen_t */ + +/ @brief Missing in Windows and Mingw */ +const char *inet_ntop( int af, const void *src, char *dst, socklen_t cnt ); +int inet_pton(int af, const char *src, void *dst); +#endif

#endif /* _TR_NET_H_ */

diff -NaurwX /home/rberber/diff-excludes.txt transmission-2.03-orig/libtransmission/peer-io.c transmission-2.03/libtransmission/peer-io.c --- transmission-2.03-orig/libtransmission/peer-io.c 2010-07-20 23:13:41.000000000 -0500 +++ transmission-2.03/libtransmission/peer-io.c 2010-07-21 21:30:33.000000000 -0500 @@ -38,6 +38,14 @@

#define MAGIC_NUMBER 206745

+#ifdef WIN32 + #define EAGAIN WSAEWOULDBLOCK + #define EINTR WSAEINTR + #define EINPROGRESS WSAEINPROGRESS + #define EPIPE WSAECONNRESET + #define ENOTCONN WSAENOTCONN +#endif +

static size_t guessPacketOverhead( size_t d ) {

@@ -221,9 +229,9 @@

return;

}

  • errno = 0;

+ EVUTIL_SET_SOCKET_ERROR( 0 );

res = evbuffer_read( io->inbuf, fd, howmuch );

  • e = errno;

+ e = EVUTIL_SOCKET_ERROR( );

if( res > 0 ) {

@@ -234,6 +242,7 @@

} else {

+ char errstr[512];

short what = EVBUFFER_READ;

if( res == 0 ) /* EOF */

@@ -246,7 +255,8 @@

what |= EVBUFFER_ERROR;

}

  • dbgmsg( io, "event_read_cb got an error. res is %d, what is %hd, errno is %d (%s)", res, what, e, strerror( e ) );

+ tr_net_strerror( errstr, sizeof( errstr ), e ); + dbgmsg( io, "event_read_cb got an error. res is %d, what is %hd, errno is %d (%s)", res, what, e, errstr );

if( io->gotError != NULL )

io->gotError( io, what, io->userData );

@@ -258,18 +268,19 @@

{

int e; int n;

+ char errstr[256];

struct evbuffer * buffer = io->outbuf;

howmuch = MIN( EVBUFFER_LENGTH( buffer ), howmuch );

  • errno = 0;

+ EVUTIL_SET_SOCKET_ERROR( 0 );

#ifdef WIN32

n = (int) send(fd, buffer->buffer, howmuch, 0 );

#else

n = (int) write(fd, buffer->buffer, howmuch );

#endif

  • e = errno;
  • dbgmsg( io, "wrote %d to peer (%s)", n, (n==-1?strerror(e):"") );

+ e = EVUTIL_SOCKET_ERROR( ); + dbgmsg( io, "wrote %d to peer (%s)", n, (n==-1?tr_net_strerror(errstr,sizeof(errstr),e):"") );

if( n > 0 )

evbuffer_drain( buffer, n );

@@ -310,23 +321,15 @@

return;

}

  • errno = 0;

+ EVUTIL_SET_SOCKET_ERROR( 0 );

res = tr_evbuffer_write( io, fd, howmuch );

  • e = errno;

+ e = EVUTIL_SOCKET_ERROR( );

if (res == -1) {

-#ifndef WIN32 -/*todo. evbuffer uses WriteFile? when WIN32 is set. WIN32 system calls do not

  • * *set errno. thus this error checking is not portable*/
if (e == EAGAIN
e == EINTR e == EINPROGRESS)

goto reschedule;

/* error case */ what |= EVBUFFER_ERROR;

- -#else

  • goto reschedule;

-#endif -

} else if (res == 0) {

/* eof case */ what |= EVBUFFER_EOF;

@@ -879,9 +882,10 @@

if(( howmuch = tr_bandwidthClamp( &io->bandwidth, TR_DOWN, howmuch ))) {

int e;

  • errno = 0;

+ + EVUTIL_SET_SOCKET_ERROR( 0 );

res = evbuffer_read( io->inbuf, io->socket, howmuch );

  • e = errno;

+ e = EVUTIL_SOCKET_ERROR( );

dbgmsg( io, "read %d from peer (%s)", res, (res==-1?strerror(e):"") );

@@ -890,10 +894,12 @@

if( ( res <= 0 ) && ( io->gotError ) && ( e != EAGAIN ) && ( e != EINTR ) && ( e != EINPROGRESS ) ) {

+ char errstr[512];

short what = EVBUFFER_READ | EVBUFFER_ERROR; if( res == 0 )

what |= EVBUFFER_EOF;

  • dbgmsg( io, "tr_peerIoTryRead got an error. res is %d, what is %hd, errno is %d (%s)", res, what, e, strerror( e ) );

+ tr_net_strerror( errstr, sizeof( errstr ), e ); + dbgmsg( io, "tr_peerIoTryRead got an error. res is %d, what is %hd, errno is %d (%s)", res, what, e, errstr );

io->gotError( io, what, io->userData );

}

}

@@ -909,17 +915,20 @@

if(( howmuch = tr_bandwidthClamp( &io->bandwidth, TR_UP, howmuch ))) {

int e;

  • errno = 0;

+ EVUTIL_SET_SOCKET_ERROR( 0 );

n = tr_evbuffer_write( io, io->socket, howmuch );

  • e = errno;

+ e = EVUTIL_SOCKET_ERROR( );

if( n > 0 )

didWriteWrapper( io, n );

  • if( ( n < 0 ) && ( io->gotError ) && ( e != EPIPE ) && ( e != EAGAIN ) && ( e != EINTR ) && ( e != EINPROGRESS ) )

+ if( ( n < 0 ) && ( io->gotError ) && ( e != EPIPE ) && ( e != EAGAIN ) && ( e != EINTR ) && ( e != EINPROGRESS ) && ( e != ENOTCONN ) )

{

+ char errstr[512];

const short what = EVBUFFER_WRITE | EVBUFFER_ERROR;

  • dbgmsg( io, "tr_peerIoTryWrite got an error. res is %d, what is %hd, errno is %d (%s)", n, what, e, strerror( e ) );

+ + tr_net_strerror( errstr, sizeof( errstr ), e ); + dbgmsg( io, "tr_peerIoTryWrite got an error. res is %d, what is %hd, errno is %d (%s)", n, what, e, errstr );

if( io->gotError != NULL )

io->gotError( io, what, io->userData );

diff -NaurwX /home/rberber/diff-excludes.txt transmission-2.03-orig/libtransmission/peer-mgr.c transmission-2.03/libtransmission/peer-mgr.c --- transmission-2.03-orig/libtransmission/peer-mgr.c 2010-07-20 23:13:41.000000000 -0500 +++ transmission-2.03/libtransmission/peer-mgr.c 2010-07-21 19:34:34.000000000 -0500 @@ -11,6 +11,7 @@

*/

#include <assert.h>

+#include <errno.h> /* error codes ERANGE, ... */

#include <limits.h> /* INT_MAX */ #include <string.h> /* memcpy, memcmp, strstr */ #include <stdlib.h> /* qsort */

diff -NaurwX /home/rberber/diff-excludes.txt transmission-2.03-orig/libtransmission/platform.c transmission-2.03/libtransmission/platform.c --- transmission-2.03-orig/libtransmission/platform.c 2010-07-20 23:13:41.000000000 -0500 +++ transmission-2.03/libtransmission/platform.c 2010-07-21 19:36:08.000000000 -0500 @@ -11,6 +11,8 @@

*/

#ifdef WIN32

+ #include <w32api.h> + #define WINVER WindowsXP

#include <windows.h> #include <shlobj.h> /* for CSIDL_APPDATA, CSIDL_MYDOCUMENTS */

#else

@@ -436,7 +438,7 @@

s = tr_buildPath( getHomeDir( ), "Library", "Application Support",

appname, NULL );

#elif defined( WIN32 )

  • char appdata[TR_MAX_PATH]; /* SHGetFolderPath() requires MAX_PATH */

+ char appdata[TR_PATH_MAX]; /* SHGetFolderPath() requires MAX_PATH */

SHGetFolderPath( NULL, CSIDL_APPDATA, NULL, 0, appdata ); s = tr_buildPath( appdata, appname, NULL );

#elif defined( HAIKU )

diff -NaurwX /home/rberber/diff-excludes.txt transmission-2.03-orig/libtransmission/platform.h transmission-2.03/libtransmission/platform.h --- transmission-2.03-orig/libtransmission/platform.h 2010-07-20 23:13:41.000000000 -0500 +++ transmission-2.03/libtransmission/platform.h 2010-07-21 19:37:11.000000000 -0500 @@ -26,8 +26,8 @@

#endif

#ifdef WIN32

  • #include <windows.h> /* MAX_PATH */
  • #define TR_PATH_MAX MAX_PATH

+ #include <windef.h> /* MAX_PATH */ + #define TR_PATH_MAX (MAX_PATH + 1)

#else

#include <limits.h> /* PATH_MAX */ #ifdef PATH_MAX

diff -NaurwX /home/rberber/diff-excludes.txt transmission-2.03-orig/libtransmission/rpcimpl.c transmission-2.03/libtransmission/rpcimpl.c --- transmission-2.03-orig/libtransmission/rpcimpl.c 2010-07-20 23:13:41.000000000 -0500 +++ transmission-2.03/libtransmission/rpcimpl.c 2010-07-21 19:40:12.000000000 -0500 @@ -909,7 +909,7 @@

{

const char * configDir = tr_sessionGetConfigDir( session ); char * filename = tr_buildPath( configDir, "blocklist.tmp", NULL );

  • FILE * fp = fopen( filename, "w+" );

+ FILE * fp = fopen( filename, "wb+" );

if( fp == NULL ) {

diff -NaurwX /home/rberber/diff-excludes.txt transmission-2.03-orig/libtransmission/torrent.c transmission-2.03/libtransmission/torrent.c --- transmission-2.03-orig/libtransmission/torrent.c 2010-07-20 23:13:41.000000000 -0500 +++ transmission-2.03/libtransmission/torrent.c 2010-07-21 19:43:56.000000000 -0500 @@ -1667,6 +1667,15 @@

tr_torrentSetRatioLimitHitCallback( torrent, NULL, NULL );

}

+static void +tr_setenv( const char * name, const char * value, tr_bool override ) +{ +#ifdef WIN32 + putenv( tr_strdup_printf( "%s=%s", name, value ) ); /* leaks memory... */ +#else + setenv( name, value, override ); +#endif +}

static void torrentCallScript( tr_torrent * tor, const char * script )

@@ -1682,16 +1691,16 @@

clearenv( );

#endif

  • setenv( "TR_APP_VERSION", SHORT_VERSION_STRING, 1 );

+ tr_setenv( "TR_APP_VERSION", SHORT_VERSION_STRING, 1 );

tr_snprintf( buf, sizeof( buf ), "%d", tr_torrentId( tor ) );

  • setenv( "TR_TORRENT_ID", buf, 1 );
  • setenv( "TR_TORRENT_NAME", tr_torrentName( tor ), 1 );
  • setenv( "TR_TORRENT_DIR", tor->currentDir, 1 );
  • setenv( "TR_TORRENT_HASH", tor->info.hashString, 1 );

+ tr_setenv( "TR_TORRENT_ID", buf, 1 ); + tr_setenv( "TR_TORRENT_NAME", tr_torrentName( tor ), 1 ); + tr_setenv( "TR_TORRENT_DIR", tor->currentDir, 1 ); + tr_setenv( "TR_TORRENT_HASH", tor->info.hashString, 1 );

tr_strlcpy( buf, ctime( &now ), sizeof( buf ) ); *strchr( buf,'\n' ) = '\0';

  • setenv( "TR_TIME_LOCALTIME", buf, 1 );

+ tr_setenv( "TR_TIME_LOCALTIME", buf, 1 );

tr_torinf( tor, "Calling script \"%s\"", script ); system( script );

}

diff -NaurwX /home/rberber/diff-excludes.txt transmission-2.03-orig/libtransmission/tr-dht.c transmission-2.03/libtransmission/tr-dht.c --- transmission-2.03-orig/libtransmission/tr-dht.c 2010-07-20 23:13:41.000000000 -0500 +++ transmission-2.03/libtransmission/tr-dht.c 2010-07-21 19:48:36.000000000 -0500 @@ -25,13 +25,19 @@

#include <stdio.h>

/* posix */

-#include <netinet/in.h> /* sockaddr_in */

#include <signal.h> /* sig_atomic_t */ #include <sys/time.h>

+#include <unistd.h> /* close() */ +#ifdef WIN32 + #include <inttypes.h> + #define _WIN32_WINNT 0x0501 /* freeaddrinfo(),getaddrinfo(),getnameinfo() */ + #include <ws2tcpip.h> +#else

#include <sys/types.h> #include <sys/socket.h> /* socket(), bind() */ #include <netdb.h>

-#include <unistd.h> /* close() */ + #include <netinet/in.h> /* sockaddr_in */ +#endif

/* third party */ #include <event.h>

@@ -81,12 +87,11 @@

}

static void

-nap( int roughly ) +nap( int roughly_sec )

{

  • struct timeval tv;
  • tv.tv_sec = roughly / 2 + tr_cryptoWeakRandInt( roughly );
  • tv.tv_usec = tr_cryptoWeakRandInt( 1000000 );
  • select( 0, NULL, NULL, NULL, &tv );

+ const int roughly_msec = roughly_sec * 1000; + const int msec = roughly_msec/2 + tr_cryptoWeakRandInt(roughly_msec); + tr_wait_msec( msec );

}

static int

@@ -193,7 +198,7 @@

tr_buildPath(cl->session->configDir, "dht.bootstrap", NULL);

if(bootstrap_file)

  • f = fopen(bootstrap_file, "r");

+ f = fopen(bootstrap_file, "rb");

if(f != NULL) {

tr_ninf("DHT", "Attempting manual bootstrap"); for(;;) {

diff -NaurwX /home/rberber/diff-excludes.txt transmission-2.03-orig/libtransmission/tr-lpd.c transmission-2.03/libtransmission/tr-lpd.c --- transmission-2.03-orig/libtransmission/tr-lpd.c 2010-07-20 23:13:41.000000000 -0500 +++ transmission-2.03/libtransmission/tr-lpd.c 2010-07-21 19:52:40.000000000 -0500 @@ -25,14 +25,24 @@

#include <stdio.h>

/* posix */

-#include <netinet/in.h> /* sockaddr_in */

#include <signal.h> /* sig_atomic_t */ #include <sys/time.h>

-#include <sys/types.h> -#include <sys/socket.h> /* socket(), bind() */

#include <unistd.h> /* close() */ #include <fcntl.h> /* fcntl(), O_NONBLOCK */ #include <ctype.h> /* toupper() */

+#ifdef WIN32 + #include <w32api.h> + #define WINDOWS WindowsXP /* freeaddrinfo(),getaddrinfo(),getnameinfo() */ + #include <inttypes.h> + #include <ws2tcpip.h> + typedef uint16_t in_port_t; /* all missing */ + extern int fcntl (int fd, int cmd, ...); + #define O_NONBLOCK 04000 +#else + #include <sys/types.h> + #include <sys/socket.h> /* socket(), bind() */ + #include <netinet/in.h> /* sockaddr_in */ +#endif

/* third party */ #include <event.h>

@@ -246,6 +256,14 @@

  • @brief Configures additional capabilities for a socket */ static inline int lpd_configureSocket( int sock, int add ) {

+#ifdef WIN32 + unsigned long flags = 1; + + if (add != O_NONBLOCK) + return -1; /* not supported */ + if (ioctlsocket(sock, FIONBIO, &flags) == SOCKET_ERROR) + return -1; +#else

/* read-modify-write socket flags */ int flags = fcntl( sock, F_GETFL );

@@ -254,6 +272,7 @@

if( fcntl( sock, F_SETFL, add | flags ) == -1 )

return -1;

+#endif

return add;

}

diff -NaurwX /home/rberber/diff-excludes.txt transmission-2.03-orig/libtransmission/trevent.c transmission-2.03/libtransmission/trevent.c --- transmission-2.03-orig/libtransmission/trevent.c 2010-07-20 23:13:41.000000000 -0500 +++ transmission-2.03/libtransmission/trevent.c 2010-07-21 19:57:12.000000000 -0500 @@ -26,7 +26,8 @@

#ifdef WIN32

-#include <WinSock2.h> +#include "utils.h" +#include <winsock2.h>

static int pgpipe( int handles[2] )

@@ -39,7 +40,7 @@

if ( ( s = socket( AF_INET, SOCK_STREAM, 0 ) ) == INVALID_SOCKET ) {

-/* ereport(LOG, (errmsg_internal("pgpipe failed to create socket: %ui", WSAGetLastError()))); */ + tr_dbg("pgpipe failed to create socket: %ui", WSAGetLastError());

return -1;

}

@@ -49,38 +50,38 @@

serv_addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); if (bind(s, (SOCKADDR *) & serv_addr, len) == SOCKET_ERROR) {

-/* ereport(LOG, (errmsg_internal("pgpipe failed to bind: %ui", WSAGetLastError()))); */ + tr_dbg("pgpipe failed to bind: %ui", WSAGetLastError());

closesocket(s); return -1;

} if (listen(s, 1) == SOCKET_ERROR) {

-/* ereport(LOG, (errmsg_internal("pgpipe failed to listen: %ui", WSAGetLastError()))); */ + tr_ndbg("event","pgpipe failed to listen: %ui", WSAGetLastError());

closesocket(s); return -1;

} if (getsockname(s, (SOCKADDR *) & serv_addr, &len) == SOCKET_ERROR) {

-/* ereport(LOG, (errmsg_internal("pgpipe failed to getsockname: %ui", WSAGetLastError()))); */ + tr_dbg("pgpipe failed to getsockname: %ui", WSAGetLastError());

closesocket(s); return -1;

} if ((handles[1] = socket(PF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) {

-/* ereport(LOG, (errmsg_internal("pgpipe failed to create socket 2: %ui", WSAGetLastError()))); */ + tr_dbg("pgpipe failed to create socket 2: %ui", WSAGetLastError());

closesocket(s); return -1;

}

if (connect(handles[1], (SOCKADDR *) & serv_addr, len) == SOCKET_ERROR) {

-/* ereport(LOG, (errmsg_internal("pgpipe failed to connect socket: %ui", WSAGetLastError()))); */ + tr_dbg("pgpipe failed to connect socket: %ui", WSAGetLastError());

closesocket(s); return -1;

} if ((handles[0] = accept(s, (SOCKADDR *) & serv_addr, &len)) == INVALID_SOCKET) {

-/* ereport(LOG, (errmsg_internal("pgpipe failed to accept socket: %ui", WSAGetLastError()))); */ + tr_dbg("pgpipe failed to accept socket: %ui", WSAGetLastError());

closesocket(handles[1]); handles[1] = INVALID_SOCKET; closesocket(s);

@@ -95,9 +96,23 @@

{

int ret = recv(s, buf, len, 0);

  • if (ret < 0 && WSAGetLastError() == WSAECONNRESET)

+ if (ret < 0) { + const int werror= WSAGetLastError(); + switch(werror) { + /* simplified error mapping (not valid for connect) */ + case WSAEWOULDBLOCK: + errno = EAGAIN; + break; + case WSAECONNRESET:

/* EOF on the pipe! (win32 socket based implementation) */ ret = 0;

+ /* fall through */ + default: + errno = werror; + break; + } + } else + errno = 0;

return ret;

}

diff -NaurwX /home/rberber/diff-excludes.txt transmission-2.03-orig/libtransmission/utils.c transmission-2.03/libtransmission/utils.c --- transmission-2.03-orig/libtransmission/utils.c 2010-07-20 23:13:41.000000000 -0500 +++ transmission-2.03/libtransmission/utils.c 2010-07-21 20:12:12.000000000 -0500 @@ -43,8 +43,10 @@

#include "event.h"

#ifdef WIN32

  • #include <direct.h> /* _getcwd */
  • #include <windows.h> /* Sleep */

+ #include <w32api.h> + #define WINVER WindowsXP /* freeaddrinfo(), getaddrinfo(), getnameinfo() */ + #include <direct.h> /* _getcwd() */ + #include <windows.h> /* Sleep() */

#endif

#include "transmission.h"

@@ -892,9 +894,9 @@

{

double ratio;

  • if( denominator )

+ if( fabs(denominator) > 0.01 )

ratio = numerator / denominator;

  • else if( numerator )

+ else if( fabs(numerator) > 0.01 )

ratio = TR_RATIO_INF;

else

ratio = TR_RATIO_NA;

@@ -1533,3 +1535,17 @@

tr_dbg( "tr_valloc(%zu) allocating %zu bytes", bufLen, allocLen ); return buf;

}

+ +char *tr_realpath(const char *path, char *resolved_path) +{ +#ifdef WIN32 +/* From a message to the Mingw-msys list, circa Jun 2, 2005 + * by Mark Junker. + */ + if (GetFullPathNameA(path, TR_PATH_MAX, resolved_path, NULL) == 0) + return NULL; + return resolved_path; +#else + return realpath(path, resolved_path); +#endif +} diff -NaurwX /home/rberber/diff-excludes.txt transmission-2.03-orig/libtransmission/utils.h transmission-2.03/libtransmission/utils.h --- transmission-2.03-orig/libtransmission/utils.h 2010-07-20 23:13:41.000000000 -0500 +++ transmission-2.03/libtransmission/utils.h 2010-07-21 21:05:40.000000000 -0500 @@ -98,9 +98,11 @@

#endif

/* #define DISABLE_GETTEXT */

-#if defined(TR_EMBEDDED) && !defined(DISABLE_GETTEXT) +#ifndef DISABLE_GETTEXT

+ #if defined(WIN32)
defined(TR_EMBEDDED)

#define DISABLE_GETTEXT

#endif

+#endif

#ifdef DISABLE_GETTEXT

const char * tr_strip_positional_args( const char * fmt ); #undef _

@@ -545,9 +547,8 @@

/ @brief Private libtransmission function to update tr_time()'s counter */ static inline void tr_timeUpdate( time_t now ) { transmission_now = now; }

-/* - -*/ +/ @brief Portability wrapper for realpath() that uses the system implementation if available */ +char* tr_realpath( const char *path, char * resolved_path );

#ifdef cplusplus }

diff -NaurwX /home/rberber/diff-excludes.txt transmission-2.03-orig/libtransmission/web.c transmission-2.03/libtransmission/web.c --- transmission-2.03-orig/libtransmission/web.c 2010-07-20 23:13:41.000000000 -0500 +++ transmission-2.03/libtransmission/web.c 2010-07-21 20:22:21.000000000 -0500 @@ -10,7 +10,11 @@

  • $Id: web.c 10535 2010-04-28 00:32:43Z charles $ */

+#ifdef WIN32 + #include <ws2tcpip.h> +#else

#include <sys/select.h>

+#endif

#include <curl/curl.h> #include <event.h>

@@ -236,6 +240,38 @@

}

}

+/ + * Portability wrapper for select(). + * + * http://msdn.microsoft.com/en-us/library/ms740141%28VS.85%29.aspx + * On win32, any two of the parameters, readfds, writefds, or exceptfds, + * can be given as null. At least one must be non-null, and any non-null + * descriptor set must contain at least one handle to a socket. + */ +static void +tr_select( int nfds, + fd_set * r_fd_set, fd_set * w_fd_set, fd_set * c_fd_set, + struct timeval * t ) +{ +#ifdef WIN32 + if( !r_fd_set->fd_count && !w_fd_set->fd_count && !c_fd_set->fd_count ) + { + tr_wait_msec( 1000 * t->tv_sec + t->tv_usec / 1000 ); + } + else if( select( 0, r_fd_set->fd_count ? r_fd_set : NULL, + w_fd_set->fd_count ? w_fd_set : NULL, + c_fd_set->fd_count ? c_fd_set : NULL, t ) < 0 ) + { + char errstr[512]; + const int e = EVUTIL_SOCKET_ERROR( ); + tr_net_strerror( errstr, sizeof( errstr ), e ); + dbgmsg( "Error: select (%d) %s", e, errstr ); + } +#else + select( nfds, r_fd_set, w_fd_set, c_fd_set, t ); +#endif +} +

static void tr_webThreadFunc( void * vsession ) {

@@ -304,7 +340,7 @@

t.tv_sec = usec / 1000000; t.tv_usec = usec % 1000000;

  • select( max_fd+1, &r_fd_set, &w_fd_set, &c_fd_set, &t );

+ tr_select( max_fd+1, &r_fd_set, &w_fd_set, &c_fd_set, &t );

}

/* call curl_multi_perform() */

diff -NaurwX /home/rberber/diff-excludes.txt transmission-2.03-orig/qt/about.cc transmission-2.03/qt/about.cc --- transmission-2.03-orig/qt/about.cc 2010-07-20 23:13:42.000000000 -0500 +++ transmission-2.03/qt/about.cc 2010-07-24 12:46:29.000000000 -0500 @@ -55,7 +55,7 @@

l->setAlignment( Qt::AlignCenter? ); v->addWidget( l );

  • l = new QLabel( tr( "Copyright 2005-2009 The Transmission Project" ) );

+ l = new QLabel( tr( "Copyright 2005-2010 The Transmission Project" ) );

l->setAlignment( Qt::AlignCenter? ); v->addWidget( l );

diff -NaurwX /home/rberber/diff-excludes.txt transmission-2.03-orig/qt/dbus-adaptor.cc transmission-2.03/qt/dbus-adaptor.cc --- transmission-2.03-orig/qt/dbus-adaptor.cc 2010-07-20 23:13:42.000000000 -0500 +++ transmission-2.03/qt/dbus-adaptor.cc 2010-07-24 12:35:00.000000000 -0500 @@ -28,8 +28,9 @@

}

bool

-TrDBusAdaptor :: AddMetainfo?( const QString& payload, const QString& filename ) +TrDBusAdaptor :: AddMetainfo?( const QString& filename )

{

  • myApp->addTorrent( QFile(filename).exists() ? filename : payload );

+ if ( QFile(filename).exists() ) + myApp->addTorrent( filename );

return true;

}

diff -NaurwX /home/rberber/diff-excludes.txt transmission-2.03-orig/qt/dbus-adaptor.h transmission-2.03/qt/dbus-adaptor.h --- transmission-2.03-orig/qt/dbus-adaptor.h 2010-07-20 23:13:42.000000000 -0500 +++ transmission-2.03/qt/dbus-adaptor.h 2010-07-24 11:40:11.000000000 -0500 @@ -31,7 +31,7 @@

public slots:

bool PresentWindow?();

  • bool AddMetainfo?( const QString& payload, const QString& filename );

+ bool AddMetainfo?( const QString& );

};

#endif

diff -NaurwX /home/rberber/diff-excludes.txt transmission-2.03-orig/qt/qtr.pro transmission-2.03/qt/qtr.pro --- transmission-2.03-orig/qt/qtr.pro 2010-07-20 23:13:42.000000000 -0500 +++ transmission-2.03/qt/qtr.pro 2010-07-21 20:26:21.000000000 -0500 @@ -1,7 +1,7 @@

TARGET = qtr NAME = "Transmission" DESCRIPTION = "Transmission: a fast, easy, and free BitTorrent? client"

-VERSION = 1.60 +VERSION = 2.03

LICENSE = "GPL"

target.path = /bin

@@ -9,7 +9,7 @@

CONFIG += qt qdbus thread debug link_pkgconfig QT += network

-PKGCONFIG = fontconfig libcurl openssl +PKGCONFIG = fontconfig libcurl openssl dbus-1

TRANSMISSION_TOP = .. INCLUDEPATH += $${TRANSMISSION_TOP}

@@ -17,7 +17,10 @@

LIBS += $${TRANSMISSION_TOP}/third-party/dht/libdht.a LIBS += $${TRANSMISSION_TOP}/third-party/miniupnp/libminiupnp.a LIBS += $${TRANSMISSION_TOP}/third-party/libnatpmp/libnatpmp.a

-LIBS += -levent +unix: LIBS += -levent +win32:DEFINES += QT_DBUS +win32:LIBS += -levent -lws2_32 -lintl +win32:LIBS += -lidn -liconv -lwldap32 -liphlpapi

TRANSLATIONS += transmission_en.ts transmission_ru.ts

@@ -32,3 +35,4 @@

HEADERS += $$replace(SOURCES, .cc, .h) HEADERS += speed.h types.h

+win32:RC_FILE = qtr.rc diff -NaurwX /home/rberber/diff-excludes.txt transmission-2.03-orig/qt/qtr.rc transmission-2.03/qt/qtr.rc --- transmission-2.03-orig/qt/qtr.rc 1969-12-31 18:00:00.000000000 -0600 +++ transmission-2.03/qt/qtr.rc 2010-07-21 20:27:10.000000000 -0500 @@ -0,0 +1 @@ +IDI_ICON1 ICON DISCARDABLE "qtr.ico" diff -NaurwX /home/rberber/diff-excludes.txt transmission-2.03-orig/qt/utils.cc transmission-2.03/qt/utils.cc --- transmission-2.03-orig/qt/utils.cc 2010-07-20 23:13:42.000000000 -0500 +++ transmission-2.03/qt/utils.cc 2010-07-21 20:31:45.000000000 -0500 @@ -76,12 +76,12 @@

else if( size < (int64_t)GIGABYTE_FACTOR ) {

displayed_size = (double)size / MEGABYTE_FACTOR;

  • str = tr( "%L1 MiB" ).arg( displayed_size, 0, 'f', 1 );

+ str = tr( "%L1 MiB" ).arg( displayed_size, 0, 'f', 2 );

} else {

displayed_size = (double) size / GIGABYTE_FACTOR;

  • str = tr( "%L1 GiB" ).arg( displayed_size, 0, 'f', 1 );

+ str = tr( "%L1 GiB" ).arg( displayed_size, 0, 'f', 3 );

}

}

diff -NaurwX /home/rberber/diff-excludes.txt transmission-2.03-orig/third-party/dht/dht.c transmission-2.03/third-party/dht/dht.c --- transmission-2.03-orig/third-party/dht/dht.c 2010-07-20 23:13:48.000000000 -0500 +++ transmission-2.03/third-party/dht/dht.c 2010-07-21 16:49:36.000000000 -0500 @@ -39,10 +39,17 @@

#include <unistd.h> #include <fcntl.h> #include <sys/time.h>

+ +#ifndef WIN32

#include <arpa/inet.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h>

+#else +#include <w32api.h> +#define WINVER WindowsXP +#include <ws2tcpip.h> +#endif

#include "dht.h"

@@ -56,6 +63,48 @@

#define MSG_CONFIRM 0 #endif

+#ifdef WIN32 + +#define EAFNOSUPPORT WSAEAFNOSUPPORT +#define EAGAIN WSAEWOULDBLOCK +static int +set_nonblocking(int fd, int nonblocking) +{ + int rc; + + unsigned long mode = !!nonblocking; + rc = ioctlsocket(fd, FIONBIO, &mode); + if(rc != 0) + errno = WSAGetLastError(); + return (rc == 0 ? 0 : -1); +} + +static int +random(void) +{ + return rand(); +} +extern const char *inet_ntop(int, const void *, char *, socklen_t); + +#else + +static int +set_nonblocking(int fd, int nonblocking) +{ + int rc; + rc = fcntl(fd, F_GETFL, 0); + if(rc < 0) + return -1; + + rc = fcntl(fd, F_SETFL, nonblocking?(rc | O_NONBLOCK):(rc & ~O_NONBLOCK)); + if(rc < 0) + return -1; + + return 0; +} + +#endif +

/* We set sin_family to 0 to mark unused slots. */

#if AF_INET == 0
AF_INET6 == 0

#error You lose

@@ -1548,11 +1597,7 @@

return -1;

buckets->af = AF_INET;

  • rc = fcntl(s, F_GETFL, 0);
  • if(rc < 0)
  • goto fail;

-

  • rc = fcntl(s, F_SETFL, (rc | O_NONBLOCK));

+ rc = set_nonblocking(s, 1);

if(rc < 0)

goto fail;

}

@@ -1563,11 +1608,7 @@

return -1;

buckets6->af = AF_INET6;

  • rc = fcntl(s6, F_GETFL, 0);
  • if(rc < 0)
  • goto fail;

-

  • rc = fcntl(s6, F_SETFL, (rc | O_NONBLOCK));

+ rc = set_nonblocking(s6, 1);

if(rc < 0)

goto fail;

}

diff -NaurwX /home/rberber/diff-excludes.txt transmission-2.03-orig/third-party/miniupnp/miniupnpc.c transmission-2.03/third-party/miniupnp/miniupnpc.c --- transmission-2.03-orig/third-party/miniupnp/miniupnpc.c 2010-07-20 23:13:48.000000000 -0500 +++ transmission-2.03/third-party/miniupnp/miniupnpc.c 2010-07-21 20:34:19.000000000 -0500 @@ -24,7 +24,7 @@

#include <winsock2.h> #include <ws2tcpip.h> #include <io.h>

-#include <IPHlpApi.h> +#include <iphlpapi.h>

#define snprintf _snprintf #if defined(_MSC_VER) && (_MSC_VER >= 1400) #define strncasecmp _memicmp