2006-03-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

* configure.in: Added gnutls support. Added several CPP macros.
	* m4/openssl.m4: Added.
	* src/SocketCore.{h,cc}: Drop const quarifier from writeData(),
	readData(), peekData(). Added gnutls support.
	* src/HttpDownloadCommand.cc: Removed SleepCommand.h
	* src/TrackerWatcherCommand.{h,cc}: Added. This command creates
	TrackerInitCommand periodicaly(TorrentMan::minInterval).
	* src/TorrentMan.cc: Remove downloadedSize == 0 check from 
save().
	Instead, added a check for whether setup method has executed
	successfully.
	* src/TorrentMan.h: Added member vaiable setupComplete. Updated
	DEFAULT_ANNOUNCE_INTERVAL and DEFAULT_ANNOUNCE_MIN_INTERVAL to 
300.
	* src/Makefile.am: Updated.
	* src/messageDigest.h: Added. This is a macro calculating SHA1 
digest
	using whether OpenSSL or gcrypt, depending on the result of 
configure
	script.
	* src/ShaVisitor.{h,cc}: Removed direct	dependency on OpenSSL by 
using
	messageDigest.h. 
	* src/TorrentAutoSaveCommand.h: Removed unused variable cuid.
	* src/PeerListenCommand.cc: Added log about port binded 
successfully.
	Fixed memory leak.
	* src/main.cc: Added gnutls support. Replaced LIB_SSL with
	ENABLE_BITTORRENT where they are not related to OpenSSL but 
BitTorrent.
	Removed instantiation of TrackerInitCommand. Instead,
	TrackerWatcherCommand is instantiated and pushed to the command 
queue.
	* src/InitiateConnectionCommandFactory.cc: Replaced HAVE_LIBSSL 
with
	ENABLE_SSL.
	* src/Request.cc: Replaced HAVE_LIBSSL with ENABLE_SSL.
	* src/RequestSlotMan.cc:
	(deleteCompletedRequestSlot)
	If a piece is already acquired by another command, delete the 
request
	slots for the piece.
	* src/TrackerUpdateCommand.cc:
	(execute)
	Changed log level of MSG_TRACKER_WARNING_MESSAGE from info to 
warn.
	Added a check whether peer list is null.
	Fixed the bug that causes sending completed event to the tracker
	several times.
	* src/TrackerInitCommand.cc:
	(execute)
	Fixed the bug that causes sending completed event to the tracker
	several times.
	* src/AbstractDiskWriter.{h,cc}: Removed direct dependency on 
OpenSSL
	by using messageDigest.h.
	
	
2006-03-26  Tatsuhiro Tsujikawa  <tujikawa at rednoah dot com>

	* PeerConnection.cc: Replaced log message "keep-alive" with
	"keep alive".
	* PeerInteractionCommand.{h,cc}: Close connection if peer is 
choking
	localhost long time.
	* TorrentMan.cc: When adding new peer with duplicate = true, if 
the
	number of peer list is equal to or grater than MAX_PEER_LIST, 
delete
	at most 100 failure entry from the list. If with duplicate = 
false,
	MAX_PEER_LIST is not checked.
	* PeerListenCommand.cc: Fixed the argument order of log message.

2006-03-25  Tatsuhiro Tsujikawa  <tujikawa at rednoah dot com>

	* Logger.h: Moved enum LEVEL from SimpleLogger.h to here.
	Added warn().
	* SimpleLogger.h: Moved enum LEVEL to Logger.h.
	Implemented warn().
	Defined 2 macros(WRITE_LOG, WRITE_LOG_EX) to avoid duplicated 
code.
pull/1/head
Tatsuhiro Tsujikawa 2006-03-27 14:47:26 +00:00
parent 2065b049ab
commit 40cb1ca9ce
38 changed files with 1717 additions and 1241 deletions

View File

@ -1,3 +1,71 @@
2006-03-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
* configure.in: Added gnutls support. Added several CPP macros.
* m4/openssl.m4: Added.
* src/SocketCore.{h,cc}: Drop const quarifier from writeData(),
readData(), peekData(). Added gnutls support.
* src/HttpDownloadCommand.cc: Removed SleepCommand.h
* src/TrackerWatcherCommand.{h,cc}: Added. This command creates
TrackerInitCommand periodicaly(TorrentMan::minInterval).
* src/TorrentMan.cc: Remove downloadedSize == 0 check from save().
Instead, added a check for whether setup method has executed
successfully.
* src/TorrentMan.h: Added member vaiable setupComplete. Updated
DEFAULT_ANNOUNCE_INTERVAL and DEFAULT_ANNOUNCE_MIN_INTERVAL to 300.
* src/Makefile.am: Updated.
* src/messageDigest.h: Added. This is a macro calculating SHA1 digest
using whether OpenSSL or gcrypt, depending on the result of configure
script.
* src/ShaVisitor.{h,cc}: Removed direct dependency on OpenSSL by using
messageDigest.h.
* src/TorrentAutoSaveCommand.h: Removed unused variable cuid.
* src/PeerListenCommand.cc: Added log about port binded successfully.
Fixed memory leak.
* src/main.cc: Added gnutls support. Replaced LIB_SSL with
ENABLE_BITTORRENT where they are not related to OpenSSL but BitTorrent.
Removed instantiation of TrackerInitCommand. Instead,
TrackerWatcherCommand is instantiated and pushed to the command queue.
* src/InitiateConnectionCommandFactory.cc: Replaced HAVE_LIBSSL with
ENABLE_SSL.
* src/Request.cc: Replaced HAVE_LIBSSL with ENABLE_SSL.
* src/RequestSlotMan.cc:
(deleteCompletedRequestSlot)
If a piece is already acquired by another command, delete the request
slots for the piece.
* src/TrackerUpdateCommand.cc:
(execute)
Changed log level of MSG_TRACKER_WARNING_MESSAGE from info to warn.
Added a check whether peer list is null.
Fixed the bug that causes sending completed event to the tracker
several times.
* src/TrackerInitCommand.cc:
(execute)
Fixed the bug that causes sending completed event to the tracker
several times.
* src/AbstractDiskWriter.{h,cc}: Removed direct dependency on OpenSSL
by using messageDigest.h.
2006-03-26 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
* PeerConnection.cc: Replaced log message "keep-alive" with
"keep alive".
* PeerInteractionCommand.{h,cc}: Close connection if peer is choking
localhost long time.
* TorrentMan.cc: When adding new peer with duplicate = true, if the
number of peer list is equal to or grater than MAX_PEER_LIST, delete
at most 100 failure entry from the list. If with duplicate = false,
MAX_PEER_LIST is not checked.
* PeerListenCommand.cc: Fixed the argument order of log message.
2006-03-25 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
* Logger.h: Moved enum LEVEL from SimpleLogger.h to here.
Added warn().
* SimpleLogger.h: Moved enum LEVEL to Logger.h.
Implemented warn().
Defined 2 macros(WRITE_LOG, WRITE_LOG_EX) to avoid duplicated code.
2006-03-24 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
* Request.h: Added AFTER_COMPLETED event.

View File

@ -50,9 +50,10 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/codeset.m4 \
$(top_srcdir)/m4/inttypes_h.m4 $(top_srcdir)/m4/lcmessage.m4 \
$(top_srcdir)/m4/lib-ld.m4 $(top_srcdir)/m4/lib-link.m4 \
$(top_srcdir)/m4/lib-prefix.m4 $(top_srcdir)/m4/nls.m4 \
$(top_srcdir)/m4/po.m4 $(top_srcdir)/m4/progtest.m4 \
$(top_srcdir)/m4/stdint_h.m4 $(top_srcdir)/m4/uintmax_t.m4 \
$(top_srcdir)/m4/ulonglong.m4 $(top_srcdir)/configure.in
$(top_srcdir)/m4/openssl.m4 $(top_srcdir)/m4/po.m4 \
$(top_srcdir)/m4/progtest.m4 $(top_srcdir)/m4/stdint_h.m4 \
$(top_srcdir)/m4/uintmax_t.m4 $(top_srcdir)/m4/ulonglong.m4 \
$(top_srcdir)/configure.in
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
am__CONFIG_DISTCLEAN_FILES = config.status config.cache config.log \
@ -126,6 +127,12 @@ INTLLIBS = @INTLLIBS@
INTLOBJS = @INTLOBJS@
INTL_LIBTOOL_SUFFIX_PREFIX = @INTL_LIBTOOL_SUFFIX_PREFIX@
LDFLAGS = @LDFLAGS@
LIBGCRYPT_CFLAGS = @LIBGCRYPT_CFLAGS@
LIBGCRYPT_CONFIG = @LIBGCRYPT_CONFIG@
LIBGCRYPT_LIBS = @LIBGCRYPT_LIBS@
LIBGNUTLS_CFLAGS = @LIBGNUTLS_CFLAGS@
LIBGNUTLS_CONFIG = @LIBGNUTLS_CONFIG@
LIBGNUTLS_LIBS = @LIBGNUTLS_LIBS@
LIBICONV = @LIBICONV@
LIBINTL = @LIBINTL@
LIBOBJS = @LIBOBJS@
@ -138,6 +145,8 @@ MKINSTALLDIRS = @MKINSTALLDIRS@
MSGFMT = @MSGFMT@
MSGMERGE = @MSGMERGE@
OBJEXT = @OBJEXT@
OPENSSL_CFLAGS = @OPENSSL_CFLAGS@
OPENSSL_LIBS = @OPENSSL_LIBS@
PACKAGE = @PACKAGE@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
PACKAGE_NAME = @PACKAGE_NAME@

13
README
View File

@ -29,10 +29,13 @@ $ make
The executable is aria2c in src directory.
4. SSL
------
You need OpenSSL library(0.9.7b or higher) to enable HTTPS and BitTorrent
support.
4. Dependency
-------------
In order to enable HTTPS support, you need GNUTLS or OpenSSL.
In order to enable BitTorrent support, you need GCRYPT(if you choose GNUTLS)
or OpenSSL.
GNUTLS has precedence over OpenSSL if both libraries are installed.
5. BitTorrrent
--------------
@ -57,4 +60,4 @@ Note:
* -o option is used to change the filename of downloaded .torrent file.
* This version only supports compact peers list format.
* The ports aria2c uses are 6881-6999.
* The maxmum number of peers are 55.
* The maximum number of peers is 55.

271
aclocal.m4 vendored
View File

@ -92,6 +92,276 @@ AC_ARG_WITH(cppunit-exec-prefix,[ --with-cppunit-exec-prefix=PFX Exec prefix w
dnl Autoconf macros for libgcrypt
dnl Copyright (C) 2002, 2004 Free Software Foundation, Inc.
dnl
dnl This file is free software; as a special exception the author gives
dnl unlimited permission to copy and/or distribute it, with or without
dnl modifications, as long as this notice is preserved.
dnl
dnl This file is distributed in the hope that it will be useful, but
dnl WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
dnl implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
dnl AM_PATH_LIBGCRYPT([MINIMUM-VERSION,
dnl [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]])
dnl Test for libgcrypt and define LIBGCRYPT_CFLAGS and LIBGCRYPT_LIBS.
dnl MINIMUN-VERSION is a string with the version number optionalliy prefixed
dnl with the API version to also check the API compatibility. Example:
dnl a MINIMUN-VERSION of 1:1.2.5 won't pass the test unless the installed
dnl version of libgcrypt is at least 1.2.5 *and* the API number is 1. Using
dnl this features allows to prevent build against newer versions of libgcrypt
dnl with a changed API.
dnl
AC_DEFUN([AM_PATH_LIBGCRYPT],
[ AC_ARG_WITH(libgcrypt-prefix,
AC_HELP_STRING([--with-libgcrypt-prefix=PFX],
[prefix where LIBGCRYPT is installed (optional)]),
libgcrypt_config_prefix="$withval", libgcrypt_config_prefix="")
if test x$libgcrypt_config_prefix != x ; then
if test x${LIBGCRYPT_CONFIG+set} != xset ; then
LIBGCRYPT_CONFIG=$libgcrypt_config_prefix/bin/libgcrypt-config
fi
fi
AC_PATH_PROG(LIBGCRYPT_CONFIG, libgcrypt-config, no)
tmp=ifelse([$1], ,1:1.2.0,$1)
if echo "$tmp" | grep ':' >/dev/null 2>/dev/null ; then
req_libgcrypt_api=`echo "$tmp" | sed 's/\(.*\):\(.*\)/\1/'`
min_libgcrypt_version=`echo "$tmp" | sed 's/\(.*\):\(.*\)/\2/'`
else
req_libgcrypt_api=0
min_libgcrypt_version="$tmp"
fi
AC_MSG_CHECKING(for LIBGCRYPT - version >= $min_libgcrypt_version)
ok=no
if test "$LIBGCRYPT_CONFIG" != "no" ; then
req_major=`echo $min_libgcrypt_version | \
sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
req_minor=`echo $min_libgcrypt_version | \
sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
req_micro=`echo $min_libgcrypt_version | \
sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\3/'`
libgcrypt_config_version=`$LIBGCRYPT_CONFIG --version`
major=`echo $libgcrypt_config_version | \
sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'`
minor=`echo $libgcrypt_config_version | \
sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\2/'`
micro=`echo $libgcrypt_config_version | \
sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\3/'`
if test "$major" -gt "$req_major"; then
ok=yes
else
if test "$major" -eq "$req_major"; then
if test "$minor" -gt "$req_minor"; then
ok=yes
else
if test "$minor" -eq "$req_minor"; then
if test "$micro" -ge "$req_micro"; then
ok=yes
fi
fi
fi
fi
fi
fi
if test $ok = yes; then
AC_MSG_RESULT(yes)
else
AC_MSG_RESULT(no)
fi
if test $ok = yes; then
# If we have a recent libgcrypt, we should also check that the
# API is compatible
if test "$req_libgcrypt_api" -gt 0 ; then
tmp=`$LIBGCRYPT_CONFIG --api-version 2>/dev/null || echo 0`
if test "$tmp" -gt 0 ; then
AC_MSG_CHECKING([LIBGCRYPT API version])
if test "$req_libgcrypt_api" -eq "$tmp" ; then
AC_MSG_RESULT(okay)
else
ok=no
AC_MSG_RESULT([does not match (want=$req_libgcrypt_api got=$tmp)])
fi
fi
fi
fi
if test $ok = yes; then
LIBGCRYPT_CFLAGS=`$LIBGCRYPT_CONFIG --cflags`
LIBGCRYPT_LIBS=`$LIBGCRYPT_CONFIG --libs`
ifelse([$2], , :, [$2])
else
LIBGCRYPT_CFLAGS=""
LIBGCRYPT_LIBS=""
ifelse([$3], , :, [$3])
fi
AC_SUBST(LIBGCRYPT_CFLAGS)
AC_SUBST(LIBGCRYPT_LIBS)
])
dnl Autoconf macros for libgnutls
dnl $id$
# Modified for LIBGNUTLS -- nmav
# Configure paths for LIBGCRYPT
# Shamelessly stolen from the one of XDELTA by Owen Taylor
# Werner Koch 99-12-09
dnl AM_PATH_LIBGNUTLS([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]])
dnl Test for libgnutls, and define LIBGNUTLS_CFLAGS and LIBGNUTLS_LIBS
dnl
AC_DEFUN([AM_PATH_LIBGNUTLS],
[dnl
dnl Get the cflags and libraries from the libgnutls-config script
dnl
AC_ARG_WITH(libgnutls-prefix,
[ --with-libgnutls-prefix=PFX Prefix where libgnutls is installed (optional)],
libgnutls_config_prefix="$withval", libgnutls_config_prefix="")
if test x$libgnutls_config_prefix != x ; then
if test x${LIBGNUTLS_CONFIG+set} != xset ; then
LIBGNUTLS_CONFIG=$libgnutls_config_prefix/bin/libgnutls-config
fi
fi
AC_PATH_PROG(LIBGNUTLS_CONFIG, libgnutls-config, no)
min_libgnutls_version=ifelse([$1], ,0.1.0,$1)
AC_MSG_CHECKING(for libgnutls - version >= $min_libgnutls_version)
no_libgnutls=""
if test "$LIBGNUTLS_CONFIG" = "no" ; then
no_libgnutls=yes
else
LIBGNUTLS_CFLAGS=`$LIBGNUTLS_CONFIG $libgnutls_config_args --cflags`
LIBGNUTLS_LIBS=`$LIBGNUTLS_CONFIG $libgnutls_config_args --libs`
libgnutls_config_version=`$LIBGNUTLS_CONFIG $libgnutls_config_args --version`
ac_save_CFLAGS="$CFLAGS"
ac_save_LIBS="$LIBS"
CFLAGS="$CFLAGS $LIBGNUTLS_CFLAGS"
LIBS="$LIBS $LIBGNUTLS_LIBS"
dnl
dnl Now check if the installed libgnutls is sufficiently new. Also sanity
dnl checks the results of libgnutls-config to some extent
dnl
rm -f conf.libgnutlstest
AC_TRY_RUN([
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <gnutls/gnutls.h>
int
main ()
{
system ("touch conf.libgnutlstest");
if( strcmp( gnutls_check_version(NULL), "$libgnutls_config_version" ) )
{
printf("\n*** 'libgnutls-config --version' returned %s, but LIBGNUTLS (%s)\n",
"$libgnutls_config_version", gnutls_check_version(NULL) );
printf("*** was found! If libgnutls-config was correct, then it is best\n");
printf("*** to remove the old version of LIBGNUTLS. You may also be able to fix the error\n");
printf("*** by modifying your LD_LIBRARY_PATH enviroment variable, or by editing\n");
printf("*** /etc/ld.so.conf. Make sure you have run ldconfig if that is\n");
printf("*** required on your system.\n");
printf("*** If libgnutls-config was wrong, set the environment variable LIBGNUTLS_CONFIG\n");
printf("*** to point to the correct copy of libgnutls-config, and remove the file config.cache\n");
printf("*** before re-running configure\n");
}
else if ( strcmp(gnutls_check_version(NULL), LIBGNUTLS_VERSION ) )
{
printf("\n*** LIBGNUTLS header file (version %s) does not match\n", LIBGNUTLS_VERSION);
printf("*** library (version %s)\n", gnutls_check_version(NULL) );
}
else
{
if ( gnutls_check_version( "$min_libgnutls_version" ) )
{
return 0;
}
else
{
printf("no\n*** An old version of LIBGNUTLS (%s) was found.\n",
gnutls_check_version(NULL) );
printf("*** You need a version of LIBGNUTLS newer than %s. The latest version of\n",
"$min_libgnutls_version" );
printf("*** LIBGNUTLS is always available from ftp://gnutls.hellug.gr/pub/gnutls.\n");
printf("*** \n");
printf("*** If you have already installed a sufficiently new version, this error\n");
printf("*** probably means that the wrong copy of the libgnutls-config shell script is\n");
printf("*** being found. The easiest way to fix this is to remove the old version\n");
printf("*** of LIBGNUTLS, but you can also set the LIBGNUTLS_CONFIG environment to point to the\n");
printf("*** correct copy of libgnutls-config. (In this case, you will have to\n");
printf("*** modify your LD_LIBRARY_PATH enviroment variable, or edit /etc/ld.so.conf\n");
printf("*** so that the correct libraries are found at run-time))\n");
}
}
return 1;
}
],, no_libgnutls=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
CFLAGS="$ac_save_CFLAGS"
LIBS="$ac_save_LIBS"
fi
if test "x$no_libgnutls" = x ; then
AC_MSG_RESULT(yes)
ifelse([$2], , :, [$2])
else
if test -f conf.libgnutlstest ; then
:
else
AC_MSG_RESULT(no)
fi
if test "$LIBGNUTLS_CONFIG" = "no" ; then
echo "*** The libgnutls-config script installed by LIBGNUTLS could not be found"
echo "*** If LIBGNUTLS was installed in PREFIX, make sure PREFIX/bin is in"
echo "*** your path, or set the LIBGNUTLS_CONFIG environment variable to the"
echo "*** full path to libgnutls-config."
else
if test -f conf.libgnutlstest ; then
:
else
echo "*** Could not run libgnutls test program, checking why..."
CFLAGS="$CFLAGS $LIBGNUTLS_CFLAGS"
LIBS="$LIBS $LIBGNUTLS_LIBS"
AC_TRY_LINK([
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <gnutls/gnutls.h>
], [ return !!gnutls_check_version(NULL); ],
[ echo "*** The test program compiled, but did not run. This usually means"
echo "*** that the run-time linker is not finding LIBGNUTLS or finding the wrong"
echo "*** version of LIBGNUTLS. If it is not finding LIBGNUTLS, you'll need to set your"
echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
echo "*** to the installed location Also, make sure you have run ldconfig if that"
echo "*** is required on your system"
echo "***"
echo "*** If you have an old version installed, it is best to remove it, although"
echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"
echo "***" ],
[ echo "*** The test program failed to compile or link. See the file config.log for the"
echo "*** exact error that occured. This usually means LIBGNUTLS was incorrectly installed"
echo "*** or that you have moved LIBGNUTLS since it was installed. In the latter case, you"
echo "*** may want to edit the libgnutls-config script: $LIBGNUTLS_CONFIG" ])
CFLAGS="$ac_save_CFLAGS"
LIBS="$ac_save_LIBS"
fi
fi
LIBGNUTLS_CFLAGS=""
LIBGNUTLS_LIBS=""
ifelse([$3], , :, [$3])
fi
rm -f conf.libgnutlstest
AC_SUBST(LIBGNUTLS_CFLAGS)
AC_SUBST(LIBGNUTLS_LIBS)
])
dnl *-*wedit:notab*-* Please keep this as the last line.
# Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
@ -942,6 +1212,7 @@ m4_include([m4/lib-ld.m4])
m4_include([m4/lib-link.m4])
m4_include([m4/lib-prefix.m4])
m4_include([m4/nls.m4])
m4_include([m4/openssl.m4])
m4_include([m4/po.m4])
m4_include([m4/progtest.m4])
m4_include([m4/stdint_h.m4])

View File

@ -8,10 +8,19 @@
/* Define to 1 if using `alloca.c'. */
#undef C_ALLOCA
/* Define to 1 if BitTorrent support is enabled. */
#undef ENABLE_BITTORRENT
/* Define to 1 if translation of program messages to the user's native
language is requested. */
#undef ENABLE_NLS
/* Define to 1 if SHA1 Digest support is enabled. */
#undef ENABLE_SHA1DIGEST
/* Define to 1 if ssl support is enabled. */
#undef ENABLE_SSL
/* Define to 1 if you have `alloca', as a function or macro. */
#undef HAVE_ALLOCA
@ -90,10 +99,16 @@
/* Define if your <locale.h> file defines LC_MESSAGES. */
#undef HAVE_LC_MESSAGES
/* Define to 1 if you have libgcrypt. */
#undef HAVE_LIBGCRYPT
/* Define to 1 if you have libgnutls. */
#undef HAVE_LIBGNUTLS
/* Define to 1 if you have the <libintl.h> header file. */
#undef HAVE_LIBINTL_H
/* Define to 1 if you have the `ssl' library (-lssl). */
/* Define to 1 if you have openssl. */
#undef HAVE_LIBSSL
/* Define to 1 if you have the <limits.h> header file. */

585
configure vendored
View File

@ -311,7 +311,7 @@ ac_includes_default="\
# include <unistd.h>
#endif"
ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA CYGPATH_W PACKAGE VERSION ACLOCAL AUTOCONF AUTOMAKE AUTOHEADER MAKEINFO install_sh STRIP ac_ct_STRIP INSTALL_STRIP_PROGRAM mkdir_p AWK SET_MAKE am__leading_dot AMTAR am__tar am__untar CPPUNIT_CONFIG CPPUNIT_CFLAGS CPPUNIT_LIBS localedir CXX CXXFLAGS LDFLAGS CPPFLAGS ac_ct_CXX EXEEXT OBJEXT DEPDIR am__include am__quote AMDEP_TRUE AMDEP_FALSE AMDEPBACKSLASH CXXDEPMODE am__fastdepCXX_TRUE am__fastdepCXX_FALSE CC CFLAGS ac_ct_CC CCDEPMODE am__fastdepCC_TRUE am__fastdepCC_FALSE RANLIB ac_ct_RANLIB YACC ALLOCA CPP EGREP MKINSTALLDIRS USE_NLS MSGFMT GMSGFMT XGETTEXT MSGMERGE build build_cpu build_vendor build_os host host_cpu host_vendor host_os GLIBC21 LIBICONV LTLIBICONV INTLBISON BUILD_INCLUDED_LIBINTL USE_INCLUDED_LIBINTL CATOBJEXT DATADIRNAME INSTOBJEXT GENCAT INTLOBJS INTL_LIBTOOL_SUFFIX_PREFIX INTLLIBS LIBINTL LTLIBINTL POSUB LIBOBJS LTLIBOBJS'
ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA CYGPATH_W PACKAGE VERSION ACLOCAL AUTOCONF AUTOMAKE AUTOHEADER MAKEINFO install_sh STRIP ac_ct_STRIP INSTALL_STRIP_PROGRAM mkdir_p AWK SET_MAKE am__leading_dot AMTAR am__tar am__untar CPPUNIT_CONFIG CPPUNIT_CFLAGS CPPUNIT_LIBS localedir CXX CXXFLAGS LDFLAGS CPPFLAGS ac_ct_CXX EXEEXT OBJEXT DEPDIR am__include am__quote AMDEP_TRUE AMDEP_FALSE AMDEPBACKSLASH CXXDEPMODE am__fastdepCXX_TRUE am__fastdepCXX_FALSE CC CFLAGS ac_ct_CC CCDEPMODE am__fastdepCC_TRUE am__fastdepCC_FALSE RANLIB ac_ct_RANLIB YACC LIBGNUTLS_CONFIG LIBGNUTLS_CFLAGS LIBGNUTLS_LIBS LIBGCRYPT_CONFIG LIBGCRYPT_CFLAGS LIBGCRYPT_LIBS OPENSSL_LIBS OPENSSL_CFLAGS ALLOCA CPP EGREP MKINSTALLDIRS USE_NLS MSGFMT GMSGFMT XGETTEXT MSGMERGE build build_cpu build_vendor build_os host host_cpu host_vendor host_os GLIBC21 LIBICONV LTLIBICONV INTLBISON BUILD_INCLUDED_LIBINTL USE_INCLUDED_LIBINTL CATOBJEXT DATADIRNAME INSTOBJEXT GENCAT INTLOBJS INTL_LIBTOOL_SUFFIX_PREFIX INTLLIBS LIBINTL LTLIBINTL POSUB LIBOBJS LTLIBOBJS'
ac_subst_files=''
# Initialize some variables set by options.
@ -861,7 +861,6 @@ if test -n "$ac_init_help"; then
Optional Features:
--disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no)
--enable-FEATURE[=ARG] include FEATURE [ARG=yes]
--enable-ssl enalbe SSL support if libssl is installed. Default: yes
--disable-dependency-tracking speeds up one-time build
--enable-dependency-tracking do not reject slow dependency extractors
--disable-nls do not use Native Language Support
@ -872,6 +871,12 @@ Optional Packages:
--without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no)
--with-cppunit-prefix=PFX Prefix where CppUnit is installed (optional)
--with-cppunit-exec-prefix=PFX Exec prefix where CppUnit is installed (optional)
--with-gnutls use gnutls library if installed. Default: yes
--with-openssl use openssl library if installed. Default: yes
--with-libgnutls-prefix=PFX Prefix where libgnutls is installed (optional)
--with-libgcrypt-prefix=PFX
prefix where LIBGCRYPT is installed (optional)
--with-openssl-prefix=PREFIX Prefix where OpenSSL installed (optional)
--with-gnu-ld assume the C compiler uses GNU ld default=no
--with-libiconv-prefix[=DIR] search for libiconv in DIR/include and DIR/lib
--without-libiconv-prefix don't search for libiconv in includedir and libdir
@ -1912,14 +1917,25 @@ localedir=${datadir}/locale
# Checks for arguments.
# Check whether --enable-ssl or --disable-ssl was given.
if test "${enable_ssl+set}" = set; then
enableval="$enable_ssl"
enable_ssl=$enableval
#AC_ARG_ENABLE([ssl], [ --enable-ssl enalbe SSL support if libssl is installed. Default: yes], [enable_ssl=$enableval], [enable_ssl=yes])
# Check whether --with-gnutls or --without-gnutls was given.
if test "${with_gnutls+set}" = set; then
withval="$with_gnutls"
with_gnutls=$enableval
else
enable_ssl=yes
with_gnutls=yes
fi;
# Check whether --with-openssl or --without-openssl was given.
if test "${with_openssl+set}" = set; then
withval="$with_openssl"
with_openssl=$enableval
else
with_openssl=yes
fi;
# Checks for programs.
ac_ext=cc
ac_cpp='$CXXCPP $CPPFLAGS'
@ -3681,9 +3697,453 @@ test -n "$YACC" || YACC="yacc"
# Checks for libraries.
if test "x$enable_ssl" = "xyes"; then
if test "x$with_gnutls" = "xyes"; then
# Check whether --with-libgnutls-prefix or --without-libgnutls-prefix was given.
if test "${with_libgnutls_prefix+set}" = set; then
withval="$with_libgnutls_prefix"
libgnutls_config_prefix="$withval"
else
libgnutls_config_prefix=""
fi;
if test x$libgnutls_config_prefix != x ; then
if test x${LIBGNUTLS_CONFIG+set} != xset ; then
LIBGNUTLS_CONFIG=$libgnutls_config_prefix/bin/libgnutls-config
fi
fi
# Extract the first word of "libgnutls-config", so it can be a program name with args.
set dummy libgnutls-config; ac_word=$2
echo "$as_me:$LINENO: checking for $ac_word" >&5
echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
if test "${ac_cv_path_LIBGNUTLS_CONFIG+set}" = set; then
echo $ECHO_N "(cached) $ECHO_C" >&6
else
case $LIBGNUTLS_CONFIG in
[\\/]* | ?:[\\/]*)
ac_cv_path_LIBGNUTLS_CONFIG="$LIBGNUTLS_CONFIG" # Let the user override the test with a path.
;;
*)
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
IFS=$as_save_IFS
test -z "$as_dir" && as_dir=.
for ac_exec_ext in '' $ac_executable_extensions; do
if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
ac_cv_path_LIBGNUTLS_CONFIG="$as_dir/$ac_word$ac_exec_ext"
echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
break 2
fi
done
done
test -z "$ac_cv_path_LIBGNUTLS_CONFIG" && ac_cv_path_LIBGNUTLS_CONFIG="no"
;;
esac
fi
LIBGNUTLS_CONFIG=$ac_cv_path_LIBGNUTLS_CONFIG
if test -n "$LIBGNUTLS_CONFIG"; then
echo "$as_me:$LINENO: result: $LIBGNUTLS_CONFIG" >&5
echo "${ECHO_T}$LIBGNUTLS_CONFIG" >&6
else
echo "$as_me:$LINENO: result: no" >&5
echo "${ECHO_T}no" >&6
fi
min_libgnutls_version=1.2.9
echo "$as_me:$LINENO: checking for libgnutls - version >= $min_libgnutls_version" >&5
echo $ECHO_N "checking for libgnutls - version >= $min_libgnutls_version... $ECHO_C" >&6
no_libgnutls=""
if test "$LIBGNUTLS_CONFIG" = "no" ; then
no_libgnutls=yes
else
LIBGNUTLS_CFLAGS=`$LIBGNUTLS_CONFIG $libgnutls_config_args --cflags`
LIBGNUTLS_LIBS=`$LIBGNUTLS_CONFIG $libgnutls_config_args --libs`
libgnutls_config_version=`$LIBGNUTLS_CONFIG $libgnutls_config_args --version`
ac_save_CFLAGS="$CFLAGS"
ac_save_LIBS="$LIBS"
CFLAGS="$CFLAGS $LIBGNUTLS_CFLAGS"
LIBS="$LIBS $LIBGNUTLS_LIBS"
rm -f conf.libgnutlstest
if test "$cross_compiling" = yes; then
echo $ac_n "cross compiling; assumed OK... $ac_c"
else
cat >conftest.$ac_ext <<_ACEOF
/* confdefs.h. */
_ACEOF
cat confdefs.h >>conftest.$ac_ext
cat >>conftest.$ac_ext <<_ACEOF
/* end confdefs.h. */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <gnutls/gnutls.h>
int
main ()
{
system ("touch conf.libgnutlstest");
if( strcmp( gnutls_check_version(NULL), "$libgnutls_config_version" ) )
{
printf("\n*** 'libgnutls-config --version' returned %s, but LIBGNUTLS (%s)\n",
"$libgnutls_config_version", gnutls_check_version(NULL) );
printf("*** was found! If libgnutls-config was correct, then it is best\n");
printf("*** to remove the old version of LIBGNUTLS. You may also be able to fix the error\n");
printf("*** by modifying your LD_LIBRARY_PATH enviroment variable, or by editing\n");
printf("*** /etc/ld.so.conf. Make sure you have run ldconfig if that is\n");
printf("*** required on your system.\n");
printf("*** If libgnutls-config was wrong, set the environment variable LIBGNUTLS_CONFIG\n");
printf("*** to point to the correct copy of libgnutls-config, and remove the file config.cache\n");
printf("*** before re-running configure\n");
}
else if ( strcmp(gnutls_check_version(NULL), LIBGNUTLS_VERSION ) )
{
printf("\n*** LIBGNUTLS header file (version %s) does not match\n", LIBGNUTLS_VERSION);
printf("*** library (version %s)\n", gnutls_check_version(NULL) );
}
else
{
if ( gnutls_check_version( "$min_libgnutls_version" ) )
{
return 0;
}
else
{
printf("no\n*** An old version of LIBGNUTLS (%s) was found.\n",
gnutls_check_version(NULL) );
printf("*** You need a version of LIBGNUTLS newer than %s. The latest version of\n",
"$min_libgnutls_version" );
printf("*** LIBGNUTLS is always available from ftp://gnutls.hellug.gr/pub/gnutls.\n");
printf("*** \n");
printf("*** If you have already installed a sufficiently new version, this error\n");
printf("*** probably means that the wrong copy of the libgnutls-config shell script is\n");
printf("*** being found. The easiest way to fix this is to remove the old version\n");
printf("*** of LIBGNUTLS, but you can also set the LIBGNUTLS_CONFIG environment to point to the\n");
printf("*** correct copy of libgnutls-config. (In this case, you will have to\n");
printf("*** modify your LD_LIBRARY_PATH enviroment variable, or edit /etc/ld.so.conf\n");
printf("*** so that the correct libraries are found at run-time))\n");
}
}
return 1;
}
_ACEOF
rm -f conftest$ac_exeext
if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
(eval $ac_link) 2>&5
ac_status=$?
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } && { ac_try='./conftest$ac_exeext'
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
(eval $ac_try) 2>&5
ac_status=$?
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); }; }; then
:
else
echo "$as_me: program exited with status $ac_status" >&5
echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5
( exit $ac_status )
no_libgnutls=yes
fi
rm -f core *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
fi
CFLAGS="$ac_save_CFLAGS"
LIBS="$ac_save_LIBS"
fi
if test "x$no_libgnutls" = x ; then
echo "$as_me:$LINENO: result: yes" >&5
echo "${ECHO_T}yes" >&6
have_libgnutls=yes
else
if test -f conf.libgnutlstest ; then
:
else
echo "$as_me:$LINENO: result: no" >&5
echo "${ECHO_T}no" >&6
fi
if test "$LIBGNUTLS_CONFIG" = "no" ; then
echo "*** The libgnutls-config script installed by LIBGNUTLS could not be found"
echo "*** If LIBGNUTLS was installed in PREFIX, make sure PREFIX/bin is in"
echo "*** your path, or set the LIBGNUTLS_CONFIG environment variable to the"
echo "*** full path to libgnutls-config."
else
if test -f conf.libgnutlstest ; then
:
else
echo "*** Could not run libgnutls test program, checking why..."
CFLAGS="$CFLAGS $LIBGNUTLS_CFLAGS"
LIBS="$LIBS $LIBGNUTLS_LIBS"
cat >conftest.$ac_ext <<_ACEOF
/* confdefs.h. */
_ACEOF
cat confdefs.h >>conftest.$ac_ext
cat >>conftest.$ac_ext <<_ACEOF
/* end confdefs.h. */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <gnutls/gnutls.h>
int
main ()
{
return !!gnutls_check_version(NULL);
;
return 0;
}
_ACEOF
rm -f conftest.$ac_objext conftest$ac_exeext
if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
(eval $ac_link) 2>conftest.er1
ac_status=$?
grep -v '^ *+' conftest.er1 >conftest.err
rm -f conftest.er1
cat conftest.err >&5
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } &&
{ ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
(eval $ac_try) 2>&5
ac_status=$?
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); }; } &&
{ ac_try='test -s conftest$ac_exeext'
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
(eval $ac_try) 2>&5
ac_status=$?
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); }; }; then
echo "*** The test program compiled, but did not run. This usually means"
echo "*** that the run-time linker is not finding LIBGNUTLS or finding the wrong"
echo "*** version of LIBGNUTLS. If it is not finding LIBGNUTLS, you'll need to set your"
echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
echo "*** to the installed location Also, make sure you have run ldconfig if that"
echo "*** is required on your system"
echo "***"
echo "*** If you have an old version installed, it is best to remove it, although"
echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"
echo "***"
else
echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5
echo "*** The test program failed to compile or link. See the file config.log for the"
echo "*** exact error that occured. This usually means LIBGNUTLS was incorrectly installed"
echo "*** or that you have moved LIBGNUTLS since it was installed. In the latter case, you"
echo "*** may want to edit the libgnutls-config script: $LIBGNUTLS_CONFIG"
fi
rm -f conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
CFLAGS="$ac_save_CFLAGS"
LIBS="$ac_save_LIBS"
fi
fi
LIBGNUTLS_CFLAGS=""
LIBGNUTLS_LIBS=""
:
fi
rm -f conf.libgnutlstest
if test "x$have_libgnutls" = "xyes"; then
cat >>confdefs.h <<\_ACEOF
#define HAVE_LIBGNUTLS 1
_ACEOF
fi
fi
if test "x$have_libgnutls" = "xyes"; then
# Check whether --with-libgcrypt-prefix or --without-libgcrypt-prefix was given.
if test "${with_libgcrypt_prefix+set}" = set; then
withval="$with_libgcrypt_prefix"
libgcrypt_config_prefix="$withval"
else
libgcrypt_config_prefix=""
fi;
if test x$libgcrypt_config_prefix != x ; then
if test x${LIBGCRYPT_CONFIG+set} != xset ; then
LIBGCRYPT_CONFIG=$libgcrypt_config_prefix/bin/libgcrypt-config
fi
fi
# Extract the first word of "libgcrypt-config", so it can be a program name with args.
set dummy libgcrypt-config; ac_word=$2
echo "$as_me:$LINENO: checking for $ac_word" >&5
echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
if test "${ac_cv_path_LIBGCRYPT_CONFIG+set}" = set; then
echo $ECHO_N "(cached) $ECHO_C" >&6
else
case $LIBGCRYPT_CONFIG in
[\\/]* | ?:[\\/]*)
ac_cv_path_LIBGCRYPT_CONFIG="$LIBGCRYPT_CONFIG" # Let the user override the test with a path.
;;
*)
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
IFS=$as_save_IFS
test -z "$as_dir" && as_dir=.
for ac_exec_ext in '' $ac_executable_extensions; do
if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
ac_cv_path_LIBGCRYPT_CONFIG="$as_dir/$ac_word$ac_exec_ext"
echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
break 2
fi
done
done
test -z "$ac_cv_path_LIBGCRYPT_CONFIG" && ac_cv_path_LIBGCRYPT_CONFIG="no"
;;
esac
fi
LIBGCRYPT_CONFIG=$ac_cv_path_LIBGCRYPT_CONFIG
if test -n "$LIBGCRYPT_CONFIG"; then
echo "$as_me:$LINENO: result: $LIBGCRYPT_CONFIG" >&5
echo "${ECHO_T}$LIBGCRYPT_CONFIG" >&6
else
echo "$as_me:$LINENO: result: no" >&5
echo "${ECHO_T}no" >&6
fi
tmp=1.2.2
if echo "$tmp" | grep ':' >/dev/null 2>/dev/null ; then
req_libgcrypt_api=`echo "$tmp" | sed 's/\(.*\):\(.*\)/\1/'`
min_libgcrypt_version=`echo "$tmp" | sed 's/\(.*\):\(.*\)/\2/'`
else
req_libgcrypt_api=0
min_libgcrypt_version="$tmp"
fi
echo "$as_me:$LINENO: checking for LIBGCRYPT - version >= $min_libgcrypt_version" >&5
echo $ECHO_N "checking for LIBGCRYPT - version >= $min_libgcrypt_version... $ECHO_C" >&6
ok=no
if test "$LIBGCRYPT_CONFIG" != "no" ; then
req_major=`echo $min_libgcrypt_version | \
sed 's/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)/\1/'`
req_minor=`echo $min_libgcrypt_version | \
sed 's/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)/\2/'`
req_micro=`echo $min_libgcrypt_version | \
sed 's/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)/\3/'`
libgcrypt_config_version=`$LIBGCRYPT_CONFIG --version`
major=`echo $libgcrypt_config_version | \
sed 's/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\1/'`
minor=`echo $libgcrypt_config_version | \
sed 's/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\2/'`
micro=`echo $libgcrypt_config_version | \
sed 's/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\3/'`
if test "$major" -gt "$req_major"; then
ok=yes
else
if test "$major" -eq "$req_major"; then
if test "$minor" -gt "$req_minor"; then
ok=yes
else
if test "$minor" -eq "$req_minor"; then
if test "$micro" -ge "$req_micro"; then
ok=yes
fi
fi
fi
fi
fi
fi
if test $ok = yes; then
echo "$as_me:$LINENO: result: yes" >&5
echo "${ECHO_T}yes" >&6
else
echo "$as_me:$LINENO: result: no" >&5
echo "${ECHO_T}no" >&6
fi
if test $ok = yes; then
# If we have a recent libgcrypt, we should also check that the
# API is compatible
if test "$req_libgcrypt_api" -gt 0 ; then
tmp=`$LIBGCRYPT_CONFIG --api-version 2>/dev/null || echo 0`
if test "$tmp" -gt 0 ; then
echo "$as_me:$LINENO: checking LIBGCRYPT API version" >&5
echo $ECHO_N "checking LIBGCRYPT API version... $ECHO_C" >&6
if test "$req_libgcrypt_api" -eq "$tmp" ; then
echo "$as_me:$LINENO: result: okay" >&5
echo "${ECHO_T}okay" >&6
else
ok=no
echo "$as_me:$LINENO: result: does not match (want=$req_libgcrypt_api got=$tmp)" >&5
echo "${ECHO_T}does not match (want=$req_libgcrypt_api got=$tmp)" >&6
fi
fi
fi
fi
if test $ok = yes; then
LIBGCRYPT_CFLAGS=`$LIBGCRYPT_CONFIG --cflags`
LIBGCRYPT_LIBS=`$LIBGCRYPT_CONFIG --libs`
have_libgcrypt=yes
else
LIBGCRYPT_CFLAGS=""
LIBGCRYPT_LIBS=""
:
fi
if test "x$have_libgcrypt" = "xyes"; then
cat >>confdefs.h <<\_ACEOF
#define HAVE_LIBGCRYPT 1
_ACEOF
fi
fi
if test "x$with_openssl" = "xyes" && test "x$have_libgnutls" != "xyes"; then
# AC_CHECK_LIB([ssl], [SSL_library_init], [have_openssl=yes])
# if test "x$have_openssl" = "xyes"; then
# AC_DEFINE([HAVE_LIBSSL], [1], [Define to 1 if you have openssl.])
# OPENSSL_LIBS="-lssl"
# OPENSSL_CFLAGS=""
# AC_SUBST(OPENSSL_LIBS)
# AC_SUBST(OPENSSL_CFLAGS)
# fi
# Check whether --with-openssl-prefix or --without-openssl-prefix was given.
if test "${with_openssl_prefix+set}" = set; then
withval="$with_openssl_prefix"
openssl_prefix=$withval
else
openssl_prefix=""
fi;
if test "x$openssl_prefix" = "x"; then
openssl_prefix=$prefix
fi
openssl_prefix_lib=$openssl_prefix/lib
openssl_prefix_include=$openssl_prefix/include
LIBS_save=$LIBS
CPPFLAGS_save=$CPPFLAGS
LIBS="-L$openssl_prefix_lib $LIBS"
CPPFLAGS="-I$openssl_prefix_include $CPPFLAGS"
echo "$as_me:$LINENO: checking for SSL_library_init in -lssl" >&5
echo $ECHO_N "checking for SSL_library_init in -lssl... $ECHO_C" >&6
if test "${ac_cv_lib_ssl_SSL_library_init+set}" = set; then
@ -3748,16 +4208,113 @@ fi
echo "$as_me:$LINENO: result: $ac_cv_lib_ssl_SSL_library_init" >&5
echo "${ECHO_T}$ac_cv_lib_ssl_SSL_library_init" >&6
if test $ac_cv_lib_ssl_SSL_library_init = yes; then
cat >>confdefs.h <<_ACEOF
have_openssl=yes
fi
if test "x$have_openssl" = "xyes"; then
have_openssl=no
echo "$as_me:$LINENO: checking for main in -lcrypto" >&5
echo $ECHO_N "checking for main in -lcrypto... $ECHO_C" >&6
if test "${ac_cv_lib_crypto_main+set}" = set; then
echo $ECHO_N "(cached) $ECHO_C" >&6
else
ac_check_lib_save_LIBS=$LIBS
LIBS="-lcrypto $LIBS"
cat >conftest.$ac_ext <<_ACEOF
/* confdefs.h. */
_ACEOF
cat confdefs.h >>conftest.$ac_ext
cat >>conftest.$ac_ext <<_ACEOF
/* end confdefs.h. */
int
main ()
{
main ();
;
return 0;
}
_ACEOF
rm -f conftest.$ac_objext conftest$ac_exeext
if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
(eval $ac_link) 2>conftest.er1
ac_status=$?
grep -v '^ *+' conftest.er1 >conftest.err
rm -f conftest.er1
cat conftest.err >&5
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } &&
{ ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
(eval $ac_try) 2>&5
ac_status=$?
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); }; } &&
{ ac_try='test -s conftest$ac_exeext'
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
(eval $ac_try) 2>&5
ac_status=$?
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); }; }; then
ac_cv_lib_crypto_main=yes
else
echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5
ac_cv_lib_crypto_main=no
fi
rm -f conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
fi
echo "$as_me:$LINENO: result: $ac_cv_lib_crypto_main" >&5
echo "${ECHO_T}$ac_cv_lib_crypto_main" >&6
if test $ac_cv_lib_crypto_main = yes; then
have_openssl=yes
fi
if test "x$have_openssl" = "xyes"; then
cat >>confdefs.h <<\_ACEOF
#define HAVE_LIBSSL 1
_ACEOF
LIBS="-lssl $LIBS"
OPENSSL_LIBS="-L$openssl_prefix_lib -lssl -lcrypto"
OPENSSL_CFLAGS="-I$openssl_prefix_include"
fi
fi
LIBS=$LIBS_save
CPPFLAGS=$CPPFLAGS_save
fi
if test "x$have_libgnutls" = "xyes" || test "x$have_openssl" = "xyes"; then
cat >>confdefs.h <<\_ACEOF
#define ENABLE_SSL 1
_ACEOF
fi
if test "x$have_libgcrypt" = "xyes" || test "x$have_openssl" = "xyes"; then
cat >>confdefs.h <<\_ACEOF
#define ENABLE_SHA1DIGEST 1
_ACEOF
cat >>confdefs.h <<\_ACEOF
#define ENABLE_BITTORRENT 1
_ACEOF
fi
# Checks for header files.
ac_ext=c
ac_cpp='$CPP $CPPFLAGS'
@ -11296,6 +11853,14 @@ s,@am__fastdepCC_FALSE@,$am__fastdepCC_FALSE,;t t
s,@RANLIB@,$RANLIB,;t t
s,@ac_ct_RANLIB@,$ac_ct_RANLIB,;t t
s,@YACC@,$YACC,;t t
s,@LIBGNUTLS_CONFIG@,$LIBGNUTLS_CONFIG,;t t
s,@LIBGNUTLS_CFLAGS@,$LIBGNUTLS_CFLAGS,;t t
s,@LIBGNUTLS_LIBS@,$LIBGNUTLS_LIBS,;t t
s,@LIBGCRYPT_CONFIG@,$LIBGCRYPT_CONFIG,;t t
s,@LIBGCRYPT_CFLAGS@,$LIBGCRYPT_CFLAGS,;t t
s,@LIBGCRYPT_LIBS@,$LIBGCRYPT_LIBS,;t t
s,@OPENSSL_LIBS@,$OPENSSL_LIBS,;t t
s,@OPENSSL_CFLAGS@,$OPENSSL_CFLAGS,;t t
s,@ALLOCA@,$ALLOCA,;t t
s,@CPP@,$CPP,;t t
s,@EGREP@,$EGREP,;t t

View File

@ -13,7 +13,10 @@ localedir=${datadir}/locale
AC_SUBST(localedir)
# Checks for arguments.
AC_ARG_ENABLE([ssl], [ --enable-ssl enalbe SSL support if libssl is installed. Default: yes], [enable_ssl=$enableval], [enable_ssl=yes])
#AC_ARG_ENABLE([ssl], [ --enable-ssl enalbe SSL support if libssl is installed. Default: yes], [enable_ssl=$enableval], [enable_ssl=yes])
AC_ARG_WITH([gnutls], [ --with-gnutls use gnutls library if installed. Default: yes], [with_gnutls=$enableval], [with_gnutls=yes])
AC_ARG_WITH([openssl], [ --with-openssl use openssl library if installed. Default: yes], [with_openssl=$enableval], [with_openssl=yes])
# Checks for programs.
AC_PROG_CXX
@ -23,10 +26,42 @@ AC_PROG_RANLIB
AC_PROG_YACC
# Checks for libraries.
if test "x$enable_ssl" = "xyes"; then
AC_CHECK_LIB([ssl], [SSL_library_init])
if test "x$with_gnutls" = "xyes"; then
AM_PATH_LIBGNUTLS([1.2.9], [have_libgnutls=yes])
if test "x$have_libgnutls" = "xyes"; then
AC_DEFINE([HAVE_LIBGNUTLS], [1], [Define to 1 if you have libgnutls.])
fi
fi
if test "x$have_libgnutls" = "xyes"; then
AM_PATH_LIBGCRYPT([1.2.2], [have_libgcrypt=yes])
if test "x$have_libgcrypt" = "xyes"; then
AC_DEFINE([HAVE_LIBGCRYPT], [1], [Define to 1 if you have libgcrypt.])
fi
fi
if test "x$with_openssl" = "xyes" && test "x$have_libgnutls" != "xyes"; then
# AC_CHECK_LIB([ssl], [SSL_library_init], [have_openssl=yes])
# if test "x$have_openssl" = "xyes"; then
# AC_DEFINE([HAVE_LIBSSL], [1], [Define to 1 if you have openssl.])
# OPENSSL_LIBS="-lssl"
# OPENSSL_CFLAGS=""
# AC_SUBST(OPENSSL_LIBS)
# AC_SUBST(OPENSSL_CFLAGS)
# fi
AM_PATH_OPENSSL
fi
if test "x$have_libgnutls" = "xyes" || test "x$have_openssl" = "xyes"; then
AC_DEFINE([ENABLE_SSL], [1], [Define to 1 if ssl support is enabled.])
fi
if test "x$have_libgcrypt" = "xyes" || test "x$have_openssl" = "xyes"; then
AC_DEFINE([ENABLE_SHA1DIGEST], [1], [Define to 1 if SHA1 Digest support is enabled.])
AC_DEFINE([ENABLE_BITTORRENT], [1], [Define to 1 if BitTorrent support is enabled.])
fi
# Checks for header files.
AC_FUNC_ALLOCA
AC_HEADER_STDC

View File

@ -45,9 +45,10 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/codeset.m4 \
$(top_srcdir)/m4/inttypes_h.m4 $(top_srcdir)/m4/lcmessage.m4 \
$(top_srcdir)/m4/lib-ld.m4 $(top_srcdir)/m4/lib-link.m4 \
$(top_srcdir)/m4/lib-prefix.m4 $(top_srcdir)/m4/nls.m4 \
$(top_srcdir)/m4/po.m4 $(top_srcdir)/m4/progtest.m4 \
$(top_srcdir)/m4/stdint_h.m4 $(top_srcdir)/m4/uintmax_t.m4 \
$(top_srcdir)/m4/ulonglong.m4 $(top_srcdir)/configure.in
$(top_srcdir)/m4/openssl.m4 $(top_srcdir)/m4/po.m4 \
$(top_srcdir)/m4/progtest.m4 $(top_srcdir)/m4/stdint_h.m4 \
$(top_srcdir)/m4/uintmax_t.m4 $(top_srcdir)/m4/ulonglong.m4 \
$(top_srcdir)/configure.in
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
@ -100,6 +101,12 @@ INTLLIBS = @INTLLIBS@
INTLOBJS = @INTLOBJS@
INTL_LIBTOOL_SUFFIX_PREFIX = @INTL_LIBTOOL_SUFFIX_PREFIX@
LDFLAGS = @LDFLAGS@
LIBGCRYPT_CFLAGS = @LIBGCRYPT_CFLAGS@
LIBGCRYPT_CONFIG = @LIBGCRYPT_CONFIG@
LIBGCRYPT_LIBS = @LIBGCRYPT_LIBS@
LIBGNUTLS_CFLAGS = @LIBGNUTLS_CFLAGS@
LIBGNUTLS_CONFIG = @LIBGNUTLS_CONFIG@
LIBGNUTLS_LIBS = @LIBGNUTLS_LIBS@
LIBICONV = @LIBICONV@
LIBINTL = @LIBINTL@
LIBOBJS = @LIBOBJS@
@ -112,6 +119,8 @@ MKINSTALLDIRS = @MKINSTALLDIRS@
MSGFMT = @MSGFMT@
MSGMERGE = @MSGMERGE@
OBJEXT = @OBJEXT@
OPENSSL_CFLAGS = @OPENSSL_CFLAGS@
OPENSSL_LIBS = @OPENSSL_LIBS@
PACKAGE = @PACKAGE@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
PACKAGE_NAME = @PACKAGE_NAME@

37
m4/openssl.m4 Normal file
View File

@ -0,0 +1,37 @@
AC_DEFUN([AM_PATH_OPENSSL],
[
AC_ARG_WITH([openssl-prefix],
[ --with-openssl-prefix=PREFIX Prefix where OpenSSL installed (optional)],
[openssl_prefix=$withval],
[openssl_prefix=""])
if test "x$openssl_prefix" = "x"; then
openssl_prefix=$prefix
fi
openssl_prefix_lib=$openssl_prefix/lib
openssl_prefix_include=$openssl_prefix/include
LIBS_save=$LIBS
CPPFLAGS_save=$CPPFLAGS
LIBS="-L$openssl_prefix_lib $LIBS"
CPPFLAGS="-I$openssl_prefix_include $CPPFLAGS"
AC_CHECK_LIB([ssl], [SSL_library_init], [have_openssl=yes])
if test "x$have_openssl" = "xyes"; then
have_openssl=no
AC_CHECK_LIB([crypto], [main], [have_openssl=yes])
if test "x$have_openssl" = "xyes"; then
AC_DEFINE([HAVE_LIBSSL], [1], [Define to 1 if you have openssl.])
OPENSSL_LIBS="-L$openssl_prefix_lib -lssl -lcrypto"
OPENSSL_CFLAGS="-I$openssl_prefix_include"
AC_SUBST(OPENSSL_LIBS)
AC_SUBST(OPENSSL_CFLAGS)
fi
fi
LIBS=$LIBS_save
CPPFLAGS=$CPPFLAGS_save
])

View File

@ -30,18 +30,18 @@
#include "Util.h"
AbstractDiskWriter::AbstractDiskWriter():fd(0) {
#ifdef HAVE_LIBSSL
EVP_MD_CTX_init(&ctx);
#endif // HAVE_LIBSSL
#ifdef ENABLE_SHA1DIGEST
sha1DigestInit(ctx);
#endif // ENABLE_SHA1DIGEST
}
AbstractDiskWriter::~AbstractDiskWriter() {
if(fd != 0) {
close(fd);
}
#ifdef HAVE_LIBSSL
EVP_MD_CTX_cleanup(&ctx);
#endif // HAVE_LIBSSL
#ifdef ENABLE_SHA1DIGEST
sha1DigestFree(ctx);
#endif // ENABLE_SHA1DIGEST
}
void AbstractDiskWriter::closeFile() {
@ -88,8 +88,8 @@ int AbstractDiskWriter::readDataInternal(char* data, int len) {
}
string AbstractDiskWriter::sha1Sum(long long int offset, long long int length) {
#ifdef HAVE_LIBSSL
EVP_DigestInit_ex(&ctx, EVP_sha1(), NULL);
#ifdef ENABLE_SHA1DIGEST
sha1DigestReset(ctx);
try {
int BUFSIZE = 16*1024;
char buf[BUFSIZE];
@ -97,7 +97,7 @@ string AbstractDiskWriter::sha1Sum(long long int offset, long long int length) {
if(BUFSIZE != readData(buf, BUFSIZE, offset)) {
throw "error";
}
EVP_DigestUpdate(&ctx, buf, BUFSIZE);
sha1DigestUpdate(ctx, buf, BUFSIZE);
offset += BUFSIZE;
}
int r = length%BUFSIZE;
@ -105,18 +105,17 @@ string AbstractDiskWriter::sha1Sum(long long int offset, long long int length) {
if(r != readData(buf, r, offset)) {
throw "error";
}
EVP_DigestUpdate(&ctx, buf, r);
sha1DigestUpdate(ctx, buf, r);
}
unsigned char hashValue[20];
int len;
EVP_DigestFinal_ex(&ctx, hashValue, (unsigned int*)&len);
sha1DigestFinal(ctx, hashValue);
return Util::toHex(hashValue, 20);
} catch(string ex) {
throw new DlAbortEx(strerror(errno));
}
#else
return "";
#endif // HASHVALUE
#endif // ENABLE_SHA1DIGEST
}
void AbstractDiskWriter::seek(long long int offset) {

View File

@ -23,17 +23,17 @@
#define _D_ABSTRACT_DISK_WRITER_H_
#include "DiskWriter.h"
#ifdef HAVE_LIBSSL
#include <openssl/evp.h>
#endif // HAVE_LIBSSL
#ifdef ENABLE_SHA1DIGEST
#include "messageDigest.h"
#endif // ENABLE_SHA1DIGEST
class AbstractDiskWriter:public DiskWriter {
protected:
int fd;
#ifdef HAVE_LIBSSL
EVP_MD_CTX ctx;
#endif // HAVE_LIBSSL
#ifdef ENABLE_SHA1DIGEST
MessageDigestContext ctx;
#endif // ENABLE_SHA1DIGEST
void createFile(string filename, int addFlags = 0);

View File

@ -26,7 +26,6 @@
#include <algorithm>
#include "DlRetryEx.h"
#include "HttpRequestCommand.h"
#include "SleepCommand.h"
#include "Util.h"
#include "ChunkedEncoding.h"

View File

@ -25,10 +25,10 @@
Command* InitiateConnectionCommandFactory::createInitiateConnectionCommand(int cuid, Request* req, DownloadEngine* e) {
if(req->getProtocol() == "http"
#ifdef HAVE_LIBSSL
#ifdef ENABLE_SSL
// for SSL
|| req->getProtocol() == "https"
#endif // HAVE_LIBSSL
#endif // ENABLE_SSL
) {
return new HttpInitiateConnectionCommand(cuid, req, e);
} else if(req->getProtocol() == "ftp") {

View File

@ -35,8 +35,17 @@ public:
virtual void debug(const char* msg, Exception* ex, ...) const = 0;
virtual void info(const char* msg, ...) const = 0;
virtual void info(const char* msg, Exception* ex, ...) const = 0;
virtual void warn(const char* msg, ...) const = 0;
virtual void warn(const char* msg, Exception* ex, ...) const = 0;
virtual void error(const char* msg, ...) const = 0;
virtual void error(const char* msg, Exception* ex, ...) const = 0;
enum LEVEL {
DEBUG,
INFO,
WARN,
ERROR
};
};
#endif // _D_LOGGER_H_

View File

@ -75,12 +75,14 @@ SRCS = Socket.cc Socket.h\
RequestSlot.cc RequestSlot.h\
RequestSlotMan.cc RequestSlotMan.h\
TorrentAutoSaveCommand.cc TorrentAutoSaveCommand.h\
Directory.cc Directory.h
Directory.cc Directory.h\
TrackerWatcherCommand.cc TrackerWatcherCommand.h\
messageDigest.h
noinst_LIBRARIES = libaria2c.a
libaria2c_a_SOURCES = $(SRCS)
aria2c_LDADD = libaria2c.a @LIBINTL@ @ALLOCA@
FLAGS = -Wall
INCLUDES = -I../lib -I../intl -I$(top_srcdir)/intl
DEFS = -D_FILE_OFFSET_BITS=64 -DLOCALEDIR=\"$(localedir)\" @DEFS@
libaria2c_a_CXXFLAGS = $(FLAGS)
aria2c_CXXFLAGS = $(FLAGS)
aria2c_LDADD = libaria2c.a @LIBINTL@ @ALLOCA@ @LIBGNUTLS_LIBS@\
@LIBGCRYPT_LIBS@ @OPENSSL_LIBS@
AM_CPPFLAGS = -Wall\
-I../lib -I../intl -I$(top_srcdir)/intl\
@LIBGNUTLS_CFLAGS@ @LIBGCRYPT_CFLAGS@ @OPENSSL_CFLAGS@\
-D_FILE_OFFSET_BITS=64 -DLOCALEDIR=\"$(localedir)\" @DEFS@

File diff suppressed because it is too large Load Diff

View File

@ -61,7 +61,7 @@ void PeerConnection::sendKeepAlive() const {
*/
char msg[4];
memset(msg, 0, sizeof(msg));
writeOutgoingMessageLog("keep-alive");
writeOutgoingMessageLog("keep alive");
socket->writeData(msg, sizeof(msg));
}

View File

@ -41,6 +41,8 @@ PeerInteractionCommand::PeerInteractionCommand(int cuid, Peer* peer,
piece = Piece::nullPiece;
keepAliveCheckPoint.tv_sec = 0;
keepAliveCheckPoint.tv_usec = 0;
chokeCheckPoint.tv_sec = 0;
chokeCheckPoint.tv_usec = 0;
}
PeerInteractionCommand::~PeerInteractionCommand() {
@ -95,6 +97,7 @@ bool PeerInteractionCommand::executeInternal() {
break;
}
case WIRED:
checkLongTimePeerChoking();
syncPiece();
decideChoking();
for(int i = 0; i < 10; i++) {
@ -116,6 +119,28 @@ bool PeerInteractionCommand::executeInternal() {
return false;
}
void PeerInteractionCommand::checkLongTimePeerChoking() {
if(e->torrentMan->downloadComplete()) {
return;
}
struct timeval now;
gettimeofday(&now, NULL);
if(chokeCheckPoint.tv_sec == 0 && chokeCheckPoint.tv_usec == 0) {
if(peer->amInterested && peer->peerChoking) {
chokeCheckPoint = now;
}
} else {
if(peer->amInterested && peer->peerChoking) {
if(Util::difftv(now, chokeCheckPoint) >= 5*60*1000000) {
throw new DlAbortEx("too long choking");
}
} else {
chokeCheckPoint.tv_sec = 0;
chokeCheckPoint.tv_usec = 0;
}
}
}
void PeerInteractionCommand::syncPiece() {
if(Piece::isNull(piece)) {
return;

View File

@ -37,7 +37,9 @@ private:
PendingMessages pendingMessages;
Piece piece;
struct timeval keepAliveCheckPoint;
struct timeval chokeCheckPoint;
void receiveMessage();
void checkLongTimePeerChoking();
void syncPiece();
void detectTimeoutAndDuplicateBlock();
void decideChoking();

View File

@ -40,10 +40,13 @@ int PeerListenCommand::bindPort(int portRangeStart, int portRangeEnd) {
try {
socket = new Socket();
socket->beginListen(port);
e->logger->info("CUID#%d - using port %d for accepting new connections",
cuid, port);
return port;
} catch(Exception* ex) {
e->logger->error("CUID#%d - an error occurred while binding port=%d",
cuid, port);
ex, cuid, port);
delete ex;
delete socket;
socket = NULL;
}
@ -76,7 +79,7 @@ bool PeerListenCommand::execute() {
}
delete peerSocket;
} catch(Exception* ex) {
e->logger->error("CUID#%d - error in accepting connection", cuid, ex);
e->logger->error("CUID#%d - error in accepting connection", ex, cuid);
delete ex;
if(peerSocket != NULL) {
delete peerSocket;

View File

@ -24,10 +24,10 @@
Request::Request():port(0), tryCount(0), isTorrent(false) {
defaultPorts["http"] = 80;
#ifdef HAVE_LIBSSL
#ifdef ENABLE_SSL
// for SSL
defaultPorts["https"] = 443;
#endif // HAVE_LIBSSL
#endif // ENABLE_SSL
defaultPorts["ftp"] = 21;
seg.sp = 0;
seg.ep = 0;

View File

@ -68,7 +68,8 @@ void RequestSlotMan::deleteTimedoutRequestSlot(Piece& piece) {
void RequestSlotMan::deleteCompletedRequestSlot(const Piece& piece) {
for(RequestSlots::iterator itr = requestSlots.begin();
itr != requestSlots.end();) {
if(Piece::isNull(piece) || piece.hasBlock(itr->getBlockIndex())) {
if(Piece::isNull(piece) || piece.hasBlock(itr->getBlockIndex()) ||
torrentMan->hasPiece(piece.getIndex())) {
logger->debug("CUID#%d - deleting requestslot blockIndex %d because the block is already acquired.", cuid,
itr->getBlockIndex());
PendingMessage pendingMessage =

View File

@ -23,58 +23,58 @@
#include "Util.h"
ShaVisitor::ShaVisitor() {
#ifdef HAVE_LIBSSL
EVP_MD_CTX_init(&ctx);
EVP_DigestInit_ex(&ctx, EVP_sha1(), NULL);
#endif // HAVE_LIBSSL
#ifdef ENABLE_SHA1DIGEST
sha1DigestInit(ctx);
sha1DigestReset(ctx);
#endif // ENABLE_SHA1DIGEST
}
ShaVisitor::~ShaVisitor() {
#ifdef HAVE_LIBSSL
EVP_MD_CTX_cleanup(&ctx);
#endif // HAVE_LIBSSL
#ifdef ENABLE_SHA1DIGEST
sha1DigestFree(ctx);
#endif // ENABLE_SHA1DIGEST
}
void ShaVisitor::visit(const Data* d) {
#ifdef HAVE_LIBSSL
#ifdef ENABLE_SHA1DIGEST
if(d->isNumber()) {
EVP_DigestUpdate(&ctx, "i", 1);
sha1DigestUpdate(ctx, "i", 1);
} else {
string lenStr = Util::llitos(d->getLen());
EVP_DigestUpdate(&ctx, lenStr.c_str(), lenStr.size());
EVP_DigestUpdate(&ctx, ":", 1);
sha1DigestUpdate(ctx, lenStr.c_str(), lenStr.size());
sha1DigestUpdate(ctx, ":", 1);
}
EVP_DigestUpdate(&ctx, d->getData(), d->getLen());
sha1DigestUpdate(ctx, d->getData(), d->getLen());
if(d->isNumber()) {
EVP_DigestUpdate(&ctx, "e", 1);
sha1DigestUpdate(ctx, "e", 1);
}
#endif // HAVE_LIBSSL
#endif // ENABLE_SHA1DIGEST
}
void ShaVisitor::visit(const Dictionary* d) {
#ifdef HAVE_LIBSSL
EVP_DigestUpdate(&ctx, "d", 1);
#ifdef ENABLE_SHA1DIGEST
sha1DigestUpdate(ctx, "d", 1);
const Order& v = d->getOrder();
for(Order::const_iterator itr = v.begin(); itr != v.end(); itr++) {
string lenStr = Util::llitos(itr->size());
EVP_DigestUpdate(&ctx, lenStr.c_str(), lenStr.size());
EVP_DigestUpdate(&ctx, ":", 1);
EVP_DigestUpdate(&ctx, itr->c_str(), itr->size());
sha1DigestUpdate(ctx, lenStr.c_str(), lenStr.size());
sha1DigestUpdate(ctx, ":", 1);
sha1DigestUpdate(ctx, itr->c_str(), itr->size());
const MetaEntry* e = d->get(*itr);
this->visit(e);
}
EVP_DigestUpdate(&ctx, "e", 1);
#endif // HAVE_LIBSSL
sha1DigestUpdate(ctx, "e", 1);
#endif // ENABLE_SHA1DIGEST
}
void ShaVisitor::visit(const List* l) {
#ifdef HAVE_LIBSSL
EVP_DigestUpdate(&ctx, "l", 1);
#ifdef ENABLE_SHA1DIGEST
sha1DigestUpdate(ctx, "l", 1);
for(MetaList::const_iterator itr = l->getList().begin(); itr != l->getList().end(); itr++) {
this->visit(*itr);
}
EVP_DigestUpdate(&ctx, "e", 1);
#endif // HAVE_LIBSSL
sha1DigestUpdate(ctx, "e", 1);
#endif // ENABLE_SHA1DIGEST
}
void ShaVisitor::visit(const MetaEntry* e) {
@ -88,7 +88,8 @@ void ShaVisitor::visit(const MetaEntry* e) {
}
void ShaVisitor::getHash(unsigned char* hashValue, int& len) {
#ifdef HAVE_LIBSSL
EVP_DigestFinal_ex(&ctx, hashValue, (unsigned int*)&len);
#endif // HAVE_LIBSSL
#ifdef ENABLE_SHA1DIGEST
sha1DigestFinal(ctx, hashValue);
len = 20;
#endif // ENABLE_SHA1DIGEST
}

View File

@ -27,15 +27,15 @@
#include "Dictionary.h"
#include "List.h"
#include "common.h"
#ifdef HAVE_LIBSSL
#include <openssl/evp.h>
#endif // HAVE_LIBSSL
#ifdef ENABLE_SHA1DIGEST
#include "messageDigest.h"
#endif // ENABLE_SHA1DIGEST
class ShaVisitor : public MetaEntryVisitor {
private:
#ifdef HAVE_LIBSSL
EVP_MD_CTX ctx;
#endif // HAVE_LIBSSL
#ifdef ENABLE_SHA1DIGEST
MessageDigestContext ctx;
#endif // ENABLE_SHA1DIGEST
public:
ShaVisitor();
~ShaVisitor();

View File

@ -25,6 +25,18 @@
#include <stdarg.h>
#include <stdio.h>
#define WRITE_LOG(LEVEL, MSG) \
va_list ap;\
va_start(ap, MSG);\
writeLog(Logger::LEVEL, MSG, ap);\
va_end(ap);
#define WRITE_LOG_EX(LEVEL, MSG, EX) \
va_list ap;\
va_start(ap, EX);\
writeLog(Logger::LEVEL, MSG, ap, EX);\
va_end(ap);
SimpleLogger::SimpleLogger(string filename) {
file = fopen(filename.c_str(), "a");
}
@ -43,13 +55,16 @@ void SimpleLogger::writeLog(int level, const char* msg, va_list ap, Exception* e
{
string levelStr;
switch(level) {
case DEBUG:
case Logger::DEBUG:
levelStr = "DEBUG";
break;
case ERROR:
case Logger::WARN:
levelStr = "WARN";
break;
case Logger::ERROR:
levelStr = "ERROR";
break;
case INFO:
case Logger::INFO:
default:
levelStr = "INFO";
}
@ -65,47 +80,35 @@ void SimpleLogger::writeLog(int level, const char* msg, va_list ap, Exception* e
}
void SimpleLogger::debug(const char* msg, ...) const {
va_list ap;
va_start(ap, msg);
writeLog(DEBUG, msg, ap);
va_end(ap);
WRITE_LOG(DEBUG, msg);
}
void SimpleLogger::debug(const char* msg, Exception* e, ...) const {
va_list ap;
va_start(ap, e);
writeLog(DEBUG, msg, ap, e);
va_end(ap);
WRITE_LOG_EX(DEBUG, msg, e);
}
void SimpleLogger::info(const char* msg, ...) const {
va_list ap;
va_start(ap, msg);
writeLog(INFO, msg, ap);
va_end(ap);
WRITE_LOG(INFO, msg);
}
void SimpleLogger::info(const char* msg, Exception* e, ...) const {
va_list ap;
va_start(ap, e);
writeLog(INFO, msg, ap, e);
va_end(ap);
WRITE_LOG_EX(INFO, msg, e);
}
void SimpleLogger::warn(const char* msg, ...) const {
WRITE_LOG(WARN, msg);
}
void SimpleLogger::warn(const char* msg, Exception* e, ...) const {
WRITE_LOG_EX(WARN, msg, e);
}
void SimpleLogger::error(const char* msg, ...) const {
va_list ap;
va_start(ap, msg);
writeLog(ERROR, msg, ap);
va_end(ap);
WRITE_LOG(ERROR, msg);
}
void SimpleLogger::error(const char* msg, Exception* e, ...) const {
va_list ap;
va_start(ap, e);
writeLog(ERROR, msg, ap, e);
va_end(ap);
WRITE_LOG_EX(ERROR, msg, e);
}

View File

@ -26,10 +26,6 @@
class SimpleLogger:public Logger {
private:
enum LEVEL {
DEBUG,
INFO,
ERROR};
void writeLog(int level, const char* msg, va_list ap, Exception* e = NULL) const;
FILE* file;
public:
@ -41,6 +37,8 @@ public:
void debug(const char* msg, Exception* ex, ...) const;
void info(const char* msg, ...) const;
void info(const char* msg, Exception* ex, ...) const;
void warn(const char* msg, ...) const;
void warn(const char* msg, Exception* ex, ...) const;
void error(const char* msg, ...) const;
void error(const char* msg, Exception* ex, ...) const;
};

View File

@ -50,10 +50,20 @@ void SocketCore::init() {
sslCtx = NULL;
ssl = NULL;
#endif // HAVE_LIBSSL
#ifdef HAVE_LIBGNUTLS
sslSession = NULL;
sslXcred = NULL;
peekBufMax = 4096;
peekBuf = new char[peekBufMax];
peekBufLength = 0;
#endif //HAVE_LIBGNUTLS
}
SocketCore::~SocketCore() {
closeConnection();
#ifdef HAVE_LIBGNUTLS
delete [] peekBuf;
#endif // HAVE_LIBGNUTLS
}
void SocketCore::beginListen(int port) {
@ -170,23 +180,32 @@ void SocketCore::setBlockingMode() const {
void SocketCore::closeConnection() {
#ifdef HAVE_LIBSSL
// for SSL
if(secure && ssl != NULL) {
if(secure) {
SSL_shutdown(ssl);
}
#endif // HAVE_LIBSSL
#ifdef HAVE_LIBGNUTLS
if(secure) {
gnutls_bye(sslSession, GNUTLS_SHUT_RDWR);
}
#endif // HAVE_LIBGNUTLS
if(sockfd != -1) {
close(sockfd);
sockfd = -1;
}
#ifdef HAVE_LIBSSL
// for SSL
if(secure && ssl != NULL) {
if(secure) {
SSL_free(ssl);
SSL_CTX_free(sslCtx);
ssl = NULL;
sslCtx = NULL;
}
#endif // HAVE_LIBSSL
#ifdef HAVE_LIBGNUTLS
if(secure) {
gnutls_deinit(sslSession);
gnutls_certificate_free_credentials(sslXcred);
}
#endif // HAVE_LIBGNUTLS
}
bool SocketCore::isWritable(int timeout) const {
@ -214,6 +233,11 @@ bool SocketCore::isWritable(int timeout) const {
}
bool SocketCore::isReadable(int timeout) const {
#ifdef HAVE_LIBGNUTLS
if(peekBufLength > 0) {
return true;
}
#endif // HAVE_LIBGNUTLS
fd_set fds;
FD_ZERO(&fds);
FD_SET(sockfd, &fds);
@ -237,41 +261,145 @@ bool SocketCore::isReadable(int timeout) const {
}
}
void SocketCore::writeData(const char* data, int len, int timeout) const {
if(!secure && send(sockfd, data, (size_t)len, 0) != len
void SocketCore::writeData(const char* data, int len, int timeout) {
int ret = 0;
if(!secure && (ret = send(sockfd, data, (size_t)len, 0)) != len
#ifdef HAVE_LIBSSL
// for SSL
// TODO handling len == 0 case required
|| secure && SSL_write(ssl, data, len) != len
|| secure && (ret = SSL_write(ssl, data, len)) != len
#endif // HAVE_LIBSSL
#ifdef HAVE_LIBGNUTLS
|| secure && (ret = gnutls_record_send(sslSession, data, len)) != len
#endif // HAVE_LIBGNUTLS
) {
throw new DlRetryEx(strerror(errno));
const char* errorMsg;
#ifdef HAVE_LIBGNUTLS
if(secure) {
errorMsg = gnutls_strerror(ret);
} else {
errorMsg = strerror(errno);
}
#else // HAVE_LIBGNUTLS
errorMsg = strerror(errno);
#endif
throw new DlRetryEx(errorMsg);
}
}
void SocketCore::readData(char* data, int& len, int timeout) const {
if(!secure && (len = recv(sockfd, data, (size_t)len, 0)) < 0
void SocketCore::readData(char* data, int& len, int timeout) {
int ret = 0;
if(!secure && (ret = recv(sockfd, data, (size_t)len, 0)) < 0
#ifdef HAVE_LIBSSL
// for SSL
// TODO handling len == 0 case required
|| secure && (len = SSL_read(ssl, data, len)) < 0
|| secure && (ret = SSL_read(ssl, data, len)) < 0
#endif // HAVE_LIBSSL
#ifdef HAVE_LIBGNUTLS
|| secure && (ret = gnutlsRecv(data, len)) < 0
#endif // HAVE_LIBGNUTLS
) {
throw new DlRetryEx(strerror(errno));
const char* errorMsg;
#ifdef HAVE_LIBGNUTLS
if(secure) {
errorMsg = gnutls_strerror(ret);
} else {
errorMsg = strerror(errno);
}
#else // HAVE_LIBGNUTLS
errorMsg = strerror(errno);
#endif
throw new DlRetryEx(errorMsg);
}
len = ret;
}
void SocketCore::peekData(char* data, int& len, int timeout) {
int ret = 0;
if(!secure && (ret = recv(sockfd, data, (size_t)len, MSG_PEEK)) < 0
#ifdef HAVE_LIBSSL
// for SSL
// TODO handling len == 0 case required
|| secure && (ret = SSL_peek(ssl, data, len)) < 0
#endif // HAVE_LIBSSL
#ifdef HAVE_LIBGNUTLS
|| secure && (ret = gnutlsPeek(data, len)) < 0
#endif // HAVE_LIBGNUTLS
) {
const char* errorMsg;
#ifdef HAVE_LIBGNUTLS
if(secure) {
errorMsg = gnutls_strerror(ret);
} else {
errorMsg = strerror(errno);
}
#else // HAVE_LIBGNUTLS
errorMsg = strerror(errno);
#endif
throw new DlRetryEx(errorMsg);
}
len = ret;
}
#ifdef HAVE_LIBGNUTLS
int SocketCore::shiftPeekData(char* data, int len) {
if(peekBufLength <= len) {
memcpy(data, peekBuf, peekBufLength);
int ret = peekBufLength;
peekBufLength = 0;
return ret;
} else {
memcpy(data, peekBuf, len);
char* temp = new char[peekBufMax];
memcpy(temp, peekBuf+len, peekBufLength-len);
delete [] peekBuf;
peekBuf = temp;
peekBufLength -= len;
return len;
}
}
void SocketCore::addPeekData(char* data, int len) {
if(peekBufLength+len > peekBufMax) {
char* temp = new char[peekBufMax+len];
memcpy(temp, peekBuf, peekBufLength);
delete [] peekBuf;
peekBuf = temp;
peekBufMax = peekBufLength+len;
}
memcpy(peekBuf+peekBufLength, data, len);
peekBufLength += len;
}
int SocketCore::gnutlsRecv(char* data, int len) {
int plen = shiftPeekData(data, len);
if(plen < len) {
int ret = gnutls_record_recv(sslSession, data+plen, len-plen);
if(ret < 0) {
throw new DlRetryEx(gnutls_strerror(ret));
}
return plen+ret;
} else {
return plen;
}
}
void SocketCore::peekData(char* data, int& len, int timeout) const {
if(!secure && (len = recv(sockfd, data, (size_t)len, MSG_PEEK)) < 0
#ifdef HAVE_LIBSSL
// for SSL
// TODO handling len == 0 case required
|| secure && (len == SSL_peek(ssl, data, len)) < 0
#endif // HAVE_LIBSSL
) {
throw new DlRetryEx(strerror(errno));
int SocketCore::gnutlsPeek(char* data, int len) {
if(peekBufLength >= len) {
memcpy(data, peekBuf, len);
return len;
} else {
memcpy(data, peekBuf, peekBufLength);
int ret = gnutls_record_recv(sslSession, data+peekBufLength, len-peekBufLength);
if(ret < 0) {
throw new DlRetryEx(gnutls_strerror(ret));
}
addPeekData(data+peekBufLength, ret);
return peekBufLength;
}
}
#endif // HAVE_LIBGNUTLS
void SocketCore::initiateSecureConnection() {
#ifdef HAVE_LIBSSL
@ -296,5 +424,26 @@ void SocketCore::initiateSecureConnection() {
secure = true;
}
#endif // HAVE_LIBSSL
#ifdef HAVE_LIBGNUTLS
if(!secure) {
const int cert_type_priority[3] = { GNUTLS_CRT_X509,
GNUTLS_CRT_OPENPGP, 0
};
// while we do not support X509 certificate, most web servers require
// X509 stuff.
gnutls_certificate_allocate_credentials (&sslXcred);
gnutls_init(&sslSession, GNUTLS_CLIENT);
gnutls_set_default_priority(sslSession);
gnutls_kx_set_priority(sslSession, cert_type_priority);
// put the x509 credentials to the current session
gnutls_credentials_set(sslSession, GNUTLS_CRD_CERTIFICATE, sslXcred);
gnutls_transport_set_ptr(sslSession, (gnutls_transport_ptr_t)sockfd);
int ret = gnutls_handshake(sslSession);
if(ret < 0) {
throw new DlAbortEx(gnutls_strerror(ret));
}
secure = true;
}
#endif // HAVE_LIBGNUTLS
}

View File

@ -30,6 +30,9 @@
// for SSL
# include <openssl/ssl.h>
#endif // HAVE_LIBSSL
#ifdef HAVE_LIBGNUTLS
# include <gnutls/gnutls.h>
#endif // HAVE_LIBGNUTLS
using namespace std;
@ -46,6 +49,19 @@ private:
SSL_CTX* sslCtx;
SSL* ssl;
#endif // HAVE_LIBSSL
#ifdef HAVE_LIBGNUTLS
gnutls_session_t sslSession;
gnutls_certificate_credentials_t sslXcred;
char* peekBuf;
int peekBufLength;
int peekBufMax;
int shiftPeekData(char* data, int len);
void addPeekData(char* data, int len);
int gnutlsRecv(char* data, int len);
int gnutlsPeek(char* data, int len);
#endif // HAVE_LIBGNUTLS
void init();
SocketCore(int sockfd);
public:
@ -126,7 +142,7 @@ public:
* @param timeout the amount of time elapsed before isWritable()
* are timed out.
*/
void writeData(const char* data, int len, int timeout = 0) const;
void writeData(const char* data, int len, int timeout = 0);
/**
* Reads up to len bytes from this socket.
@ -142,7 +158,7 @@ public:
* @param timeout the amount of time elapsed before isReadable() are timed
* out.
*/
void readData(char* data, int& len, int timeout = 0) const;
void readData(char* data, int& len, int timeout = 0);
/**
* Reads up to len bytes from this socket, but bytes are not removed from
@ -155,7 +171,7 @@ public:
* @param timeout the amount of time elapsed before isReadable() are timed
* out.
*/
void peekData(char* data, int& len, int timeout = 0) const;
void peekData(char* data, int& len, int timeout = 0);
/**
* Makes this socket secure.

View File

@ -27,7 +27,6 @@
class TorrentAutoSaveCommand : public Command {
private:
int cuid;
TorrentDownloadEngine* e;
int interval;
public:

View File

@ -39,6 +39,7 @@ TorrentMan::TorrentMan():bitfield(NULL),
deltaDownload(0), deltaUpload(0),
storeDir("."),
multiFileTopDir(NULL),
setupComplete(false),
interval(DEFAULT_ANNOUNCE_INTERVAL),
minInterval(DEFAULT_ANNOUNCE_MIN_INTERVAL),
complete(0), incomplete(0),
@ -65,9 +66,6 @@ void TorrentMan::updatePeers(const Peers& peers) {
}
bool TorrentMan::addPeer(Peer* peer, bool duplicate) {
if(peers.size() >= MAX_PEER_LIST_SIZE) {
return false;
}
if(duplicate) {
for(Peers::iterator itr = peers.begin(); itr != peers.end(); itr++) {
Peer* p = *itr;
@ -76,6 +74,12 @@ bool TorrentMan::addPeer(Peer* peer, bool duplicate) {
}
}
} else {
if(peers.size() >= MAX_PEER_LIST_SIZE) {
deleteOldErrorPeers(100);
if(peers.size() >= MAX_PEER_LIST_SIZE) {
return false;
}
}
for(Peers::iterator itr = peers.begin(); itr != peers.end(); itr++) {
Peer* p = *itr;
if(p->ipaddr == peer->ipaddr && p->port == peer->port) {
@ -378,6 +382,7 @@ void TorrentMan::setup(string metaInfoFile) {
} else {
diskWriter->initAndOpenFile(getTempFilePath());
}
setupComplete = true;
}
bool TorrentMan::hasPiece(int index) const {
@ -458,7 +463,7 @@ void TorrentMan::read(FILE* file) {
}
void TorrentMan::save() const {
if(downloadedSize == 0) {
if(!setupComplete) {
return;
}
string segFilename = getSegmentFilePath();

View File

@ -42,8 +42,8 @@ using namespace std;
#define IS_NULL_PIECE(X) (X.index == 0 && X.length == 0)
#define DEFAULT_ANNOUNCE_INTERVAL 120
#define DEFAULT_ANNOUNCE_MIN_INTERVAL 120
#define DEFAULT_ANNOUNCE_INTERVAL 300
#define DEFAULT_ANNOUNCE_MIN_INTERVAL 300
#define MAX_PEERS 55
#define MAX_PEER_UPDATE 15
@ -83,6 +83,7 @@ private:
UsedPieces usedPieces;
Directory* multiFileTopDir;
MultiFileEntries multiFileEntries;
bool setupComplete;
FILE* openSegFile(string segFilename, string mode) const;
void read(FILE* file);

View File

@ -34,7 +34,11 @@ bool TrackerInitCommand::execute() {
if(req->getTrackerEvent() == Request::COMPLETED) {
req->setTrackerEvent(Request::AFTER_COMPLETED);
} else {
req->setTrackerEvent(Request::COMPLETED);
if(req->getTrackerEvent() == Request::STARTED) {
req->setTrackerEvent(Request::AFTER_COMPLETED);
} else if(req->getTrackerEvent() != Request::AFTER_COMPLETED) {
req->setTrackerEvent(Request::COMPLETED);
}
}
}
string event;

View File

@ -20,10 +20,8 @@
*/
/* copyright --> */
#include "TrackerUpdateCommand.h"
#include "TrackerInitCommand.h"
#include "PeerInitiateConnectionCommand.h"
#include "PeerListenCommand.h"
#include "SleepCommand.h"
#include "Dictionary.h"
#include "Data.h"
#include "DlAbortEx.h"
@ -40,8 +38,6 @@ TrackerUpdateCommand::~TrackerUpdateCommand() {
}
bool TrackerUpdateCommand::execute() {
//e->torrentMan->deleteOldErrorPeers(25);
Dictionary* response = (Dictionary*)trackerResponse;
Data* failureReason = (Data*)response->get("failure reason");
if(failureReason != NULL) {
@ -49,7 +45,7 @@ bool TrackerUpdateCommand::execute() {
}
Data* warningMessage = (Data*)response->get("warning message");
if(warningMessage != NULL) {
e->logger->info(MSG_TRACKER_WARNING_MESSAGE, cuid, warningMessage->toString().c_str());
e->logger->warn(MSG_TRACKER_WARNING_MESSAGE, cuid, warningMessage->toString().c_str());
}
Data* trackerId = (Data*)response->get("tracker id");
if(trackerId != NULL) {
@ -77,35 +73,29 @@ bool TrackerUpdateCommand::execute() {
e->logger->debug("CUID#%d - incomplete:%d", cuid, e->torrentMan->incomplete);
}
Data* peers = (Data*)response->get("peers");
for(int i = 0; i < peers->getLen(); i += 6) {
unsigned int ipaddr1 = (unsigned char)*(peers->getData()+i);
unsigned int ipaddr2 = (unsigned char)*(peers->getData()+i+1);
unsigned int ipaddr3 = (unsigned char)*(peers->getData()+i+2);
unsigned int ipaddr4 = (unsigned char)*(peers->getData()+i+3);
//unsigned short int nPort = 0;
//memcpy(&nPort, peers->getData()+i+4, 2);
unsigned int port = ntohs(*(unsigned short int*)(peers->getData()+i+4));
//unsigned int port = ntohs(nPort);
char ipaddr[16];
if(peers != NULL) {
for(int i = 0; i < peers->getLen(); i += 6) {
unsigned int ipaddr1 = (unsigned char)*(peers->getData()+i);
unsigned int ipaddr2 = (unsigned char)*(peers->getData()+i+1);
unsigned int ipaddr3 = (unsigned char)*(peers->getData()+i+2);
unsigned int ipaddr4 = (unsigned char)*(peers->getData()+i+3);
unsigned int port = ntohs(*(unsigned short int*)(peers->getData()+i+4));
char ipaddr[16];
snprintf(ipaddr, sizeof(ipaddr), "%d.%d.%d.%d",
ipaddr1, ipaddr2, ipaddr3, ipaddr4);
Peer* peer = new Peer(ipaddr, port, e->torrentMan->pieceLength,
e->torrentMan->totalSize);
if(e->torrentMan->addPeer(peer)) {
e->logger->debug("CUID#%d - adding peer %s:%d", cuid,
peer->ipaddr.c_str(), peer->port);
} else {
delete peer;
snprintf(ipaddr, sizeof(ipaddr), "%d.%d.%d.%d",
ipaddr1, ipaddr2, ipaddr3, ipaddr4);
Peer* peer = new Peer(ipaddr, port, e->torrentMan->pieceLength,
e->torrentMan->totalSize);
if(e->torrentMan->addPeer(peer)) {
e->logger->debug("CUID#%d - adding peer %s:%d", cuid,
peer->ipaddr.c_str(), peer->port);
} else {
delete peer;
}
}
} else {
e->logger->info("CUID#%d - no peer list received.", cuid);
}
/*
if(req->getTrackerEvent() == Request::STARTED) {
PeerListenCommand* command = new PeerListenCommand(e->torrentMan->getNewCuid(), e);
e->commands.push(command);
e->logger->debug("CUID#%d - adding listen command", cuid);
}
*/
while(e->torrentMan->isPeerAvailable() &&
e->torrentMan->connections < MAX_PEER_UPDATE) {
Peer* peer = e->torrentMan->getPeer();
@ -115,9 +105,8 @@ bool TrackerUpdateCommand::execute() {
e->commands.push(command);
e->logger->debug("CUID#%d - adding new command CUID#%d", cuid, newCuid);
}
req->setTrackerEvent(Request::AUTO);
TrackerInitCommand* command = new TrackerInitCommand(cuid, req, e);
SleepCommand* slpCommand = new SleepCommand(cuid, e, command, e->torrentMan->minInterval);
e->commands.push(slpCommand);
if(req->getTrackerEvent() == Request::STARTED) {
req->setTrackerEvent(Request::AUTO);
}
return true;
}

View File

@ -0,0 +1,44 @@
/* <!-- copyright */
/*
* aria2 - a simple utility for downloading files faster
*
* Copyright (C) 2006 Tatsuhiro Tsujikawa
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* copyright --> */
#include "TrackerWatcherCommand.h"
#include "SleepCommand.h"
#include "TrackerInitCommand.h"
TrackerWatcherCommand::TrackerWatcherCommand(int cuid, Request* req,
TorrentDownloadEngine* e):
Command(cuid), req(req), e(e) {}
TrackerWatcherCommand::~TrackerWatcherCommand() {}
bool TrackerWatcherCommand::execute() {
Command* command = new TrackerInitCommand(e->torrentMan->getNewCuid(),
req,
e);
e->logger->info("CUID#%d - creating new tracker request command #%d", cuid,
command->getCuid());
e->commands.push(command);
SleepCommand* slpCommand = new SleepCommand(cuid, e, this,
e->torrentMan->minInterval);
e->commands.push(slpCommand);
return false;
}

View File

@ -0,0 +1,40 @@
/* <!-- copyright */
/*
* aria2 - a simple utility for downloading files faster
*
* Copyright (C) 2006 Tatsuhiro Tsujikawa
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* copyright --> */
#ifndef _D_TRACKER_WATCHER_COMMAND_H_
#define _D_TRACKER_WATCHER_COMMAND_H_
#include "Command.h"
#include "TorrentDownloadEngine.h"
#include "Request.h"
class TrackerWatcherCommand : public Command {
private:
Request* req;
TorrentDownloadEngine* e;
public:
TrackerWatcherCommand(int cuid, Request* req, TorrentDownloadEngine* e);
~TrackerWatcherCommand();
bool execute();
};
#endif // _D_TRACKER_WATCHER_COMMAND_H_

View File

@ -34,7 +34,7 @@
#include "TrackerInitCommand.h"
#include "PeerListenCommand.h"
#include "TorrentAutoSaveCommand.h"
#include "SleepCommand.h"
#include "TrackerWatcherCommand.h"
#include <deque>
#include <algorithm>
#include <time.h>
@ -51,6 +51,9 @@ extern int optind, opterr, optopt;
# include <openssl/err.h>
# include <openssl/ssl.h>
#endif // HAVE_LIBSSL
#ifdef HAVE_LIBGNUTLS
# include <gnutls/gnutls.h>
#endif // HAVE_LIBGNUTLS
using namespace std;
@ -180,13 +183,13 @@ void showUsage() {
cout << _(" --ftp-via-http-proxy=METHOD Use HTTP proxy in FTP. METHOD is either 'get' or\n"
" 'tunnel'.\n"
" Default: tunnel") << endl;
#ifdef HAVE_LIBSSL
#ifdef ENABLE_BITTORRENT
cout << _(" --torrent-file=TORRENT_FILE The file path to .torrent file.") << endl;
cout << _(" --follow-torrent=true|false Setting this option to false prevents aria2 to\n"
" enter BitTorrent mode even if the filename of\n"
" downloaded file ends with .torrent.\n"
" Default: true") << endl;
#endif // HAVE_LIBSSL
#endif // ENABLE_BITTORRENT
cout << _(" -v, --version Print the version number and exit.") << endl;
cout << _(" -h, --help Print this message and exit.") << endl;
cout << endl;
@ -203,13 +206,13 @@ void showUsage() {
cout << " aria2c http://AAA.BBB.CCC/file.zip http://DDD.EEE.FFF/GGG/file.zip" << endl;
cout << _(" You can mix up different protocols:") << endl;
cout << " aria2c http://AAA.BBB.CCC/file.zip ftp://DDD.EEE.FFF/GGG/file.zip" << endl;
#ifdef HAVE_LIBSSL
#ifdef ENABLE_BITTORRENT
cout << _(" Download a torrent:") << endl;
cout << " aria2c -o test.torrent http://AAA.BBB.CCC/file.torrent" << endl;
cout << _(" Download a torrent using local .torrent file:") << endl;
cout << " aria2c --torrent-file test.torrent" << endl;
cout << endl;
#endif // HAVE_LIBSSL
#endif // ENABLE_BITTORRENT
printf(_("Reports bugs to %s"), "<tujikawa at users dot sourceforge dot net>");
cout << endl;
}
@ -229,11 +232,11 @@ int main(int argc, char* argv[]) {
bool daemonMode = false;
string referer;
string torrentFile;
#ifdef HAVE_LIBSSL
#ifdef ENABLE_BITTORRENT
bool followTorrent = true;
#else
bool followTorrent = false;
#endif // HAVE_LIBSSL
#endif // ENABLE_BITTORRENT
int c;
Option* op = new Option();
@ -274,10 +277,10 @@ int main(int argc, char* argv[]) {
{ "ftp-via-http-proxy", required_argument, &lopt, 12 },
{ "min-segment-size", required_argument, &lopt, 13 },
{ "http-proxy-method", required_argument, &lopt, 14 },
#ifdef HAVE_LIBSSL
#ifdef ENABLE_BITTORRENT
{ "torrent-file", required_argument, &lopt, 15 },
{ "follow-torrent", required_argument, &lopt, 16 },
#endif // HAVE_LIBSSL
#endif // ENABLE_BITTORRENT
{ "version", no_argument, NULL, 'v' },
{ "help", no_argument, NULL, 'h' },
{ 0, 0, 0, 0 }
@ -483,6 +486,9 @@ int main(int argc, char* argv[]) {
SSL_load_error_strings();
SSL_library_init();
#endif // HAVE_LIBSSL
#ifdef HAVE_LIBGNUTLS
gnutls_global_init();
#endif // HAVE_LIBGNUTLS
srandom(time(NULL));
SimpleLogger* logger;
if(stdoutLog) {
@ -548,7 +554,7 @@ int main(int argc, char* argv[]) {
}
if(!torrentFile.empty() || followTorrent && readyToTorrentMode) {
try {
op->put(PREF_MAX_TRIES, "0");
//op->put(PREF_MAX_TRIES, "0");
struct sigaction sigact;
sigact.sa_handler = torrentHandler;
sigact.sa_flags = 0;
@ -580,12 +586,11 @@ int main(int argc, char* argv[]) {
}
te->torrentMan->setPort(port);
te->commands.push(listenCommand);
te->commands.push(new TrackerInitCommand(te->torrentMan->getNewCuid(),
req, te));
int autoSaveCommandCuid = te->torrentMan->getNewCuid();
te->commands.push(new SleepCommand(autoSaveCommandCuid, te,
new TorrentAutoSaveCommand(autoSaveCommandCuid, te, op->getAsInt(PREF_AUTO_SAVE_INTERVAL)),
op->getAsInt(PREF_AUTO_SAVE_INTERVAL)));
te->commands.push(new TrackerWatcherCommand(te->torrentMan->getNewCuid(),
req, te));
te->commands.push(new TorrentAutoSaveCommand(te->torrentMan->getNewCuid(),
te,
op->getAsInt(PREF_AUTO_SAVE_INTERVAL)));
te->run();
if(te->torrentMan->downloadComplete()) {
@ -609,5 +614,8 @@ int main(int argc, char* argv[]) {
delete(op);
delete(splitter);
#ifdef HAVE_LIBGNUTLS
gnutls_global_deinit();
#endif // HAVE_LIBGNUTLS
return 0;
}

59
src/messageDigest.h Normal file
View File

@ -0,0 +1,59 @@
/* <!-- copyright */
/*
* aria2 - a simple utility for downloading files faster
*
* Copyright (C) 2006 Tatsuhiro Tsujikawa
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* copyright --> */
#ifndef _D_MESSAGE_DIGEST_H_
#define _D_MESSAGE_DIGEST_H_
#include "common.h"
#ifdef ENABLE_BITTORRENT
#ifdef HAVE_LIBSSL
#include <openssl/evp.h>
#define MessageDigestContext EVP_MD_CTX
#define sha1DigestInit(CTX) EVP_MD_CTX_init(&CTX)
#define sha1DigestReset(CTX) EVP_DigestInit_ex(&CTX, EVP_sha1(), NULL)
#define sha1DigestUpdate(CTX, DATA, LENGTH) EVP_DigestUpdate(&CTX, DATA, LENGTH)
#define sha1DigestFinal(CTX, HASH) \
{\
int len;\
EVP_DigestFinal_ex(&CTX, HASH, (unsigned int*)&len);\
}
#define sha1DigestFree(CTX) EVP_MD_CTX_cleanup(&CTX)
#endif // HAVE_LIBSSL
#ifdef HAVE_LIBGCRYPT
#include <gcrypt.h>
#define MessageDigestContext gcry_md_hd_t
#define sha1DigestInit(CTX) gcry_md_open(&CTX, GCRY_MD_SHA1, 0)
#define sha1DigestReset(CTX) gcry_md_reset(CTX)
#define sha1DigestUpdate(CTX, DATA, LENGTH) gcry_md_write(CTX, DATA, LENGTH)
#define sha1DigestFinal(CTX, HASH) \
{\
gcry_md_final(CTX);\
memcpy(HASH, gcry_md_read(CTX, 0), 20);\
}
#define sha1DigestFree(CTX) gcry_md_close(CTX)
#endif // HAVE_LIBGCRYPT
#endif // ENABLE_BITTORRENT
#endif // _D_MESSAGE_DIGEST_H_

View File

@ -46,9 +46,10 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/codeset.m4 \
$(top_srcdir)/m4/inttypes_h.m4 $(top_srcdir)/m4/lcmessage.m4 \
$(top_srcdir)/m4/lib-ld.m4 $(top_srcdir)/m4/lib-link.m4 \
$(top_srcdir)/m4/lib-prefix.m4 $(top_srcdir)/m4/nls.m4 \
$(top_srcdir)/m4/po.m4 $(top_srcdir)/m4/progtest.m4 \
$(top_srcdir)/m4/stdint_h.m4 $(top_srcdir)/m4/uintmax_t.m4 \
$(top_srcdir)/m4/ulonglong.m4 $(top_srcdir)/configure.in
$(top_srcdir)/m4/openssl.m4 $(top_srcdir)/m4/po.m4 \
$(top_srcdir)/m4/progtest.m4 $(top_srcdir)/m4/stdint_h.m4 \
$(top_srcdir)/m4/uintmax_t.m4 $(top_srcdir)/m4/ulonglong.m4 \
$(top_srcdir)/configure.in
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
@ -126,6 +127,12 @@ INTLLIBS = @INTLLIBS@
INTLOBJS = @INTLOBJS@
INTL_LIBTOOL_SUFFIX_PREFIX = @INTL_LIBTOOL_SUFFIX_PREFIX@
LDFLAGS = @LDFLAGS@
LIBGCRYPT_CFLAGS = @LIBGCRYPT_CFLAGS@
LIBGCRYPT_CONFIG = @LIBGCRYPT_CONFIG@
LIBGCRYPT_LIBS = @LIBGCRYPT_LIBS@
LIBGNUTLS_CFLAGS = @LIBGNUTLS_CFLAGS@
LIBGNUTLS_CONFIG = @LIBGNUTLS_CONFIG@
LIBGNUTLS_LIBS = @LIBGNUTLS_LIBS@
LIBICONV = @LIBICONV@
LIBINTL = @LIBINTL@
LIBOBJS = @LIBOBJS@
@ -138,6 +145,8 @@ MKINSTALLDIRS = @MKINSTALLDIRS@
MSGFMT = @MSGFMT@
MSGMERGE = @MSGMERGE@
OBJEXT = @OBJEXT@
OPENSSL_CFLAGS = @OPENSSL_CFLAGS@
OPENSSL_LIBS = @OPENSSL_LIBS@
PACKAGE = @PACKAGE@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
PACKAGE_NAME = @PACKAGE_NAME@