2006-02-17 13:35:04 +00:00
|
|
|
/* <!-- copyright */
|
|
|
|
/*
|
2006-09-21 15:31:24 +00:00
|
|
|
* aria2 - The high speed download utility
|
2006-02-17 13:35:04 +00:00
|
|
|
*
|
|
|
|
* 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
|
2006-09-21 15:31:24 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*
|
|
|
|
* In addition, as a special exception, the copyright holders give
|
|
|
|
* permission to link the code of portions of this program with the
|
|
|
|
* OpenSSL library under certain conditions as described in each
|
|
|
|
* individual source file, and distribute linked combinations
|
|
|
|
* including the two.
|
|
|
|
* You must obey the GNU General Public License in all respects
|
|
|
|
* for all of the code used other than OpenSSL. If you modify
|
|
|
|
* file(s) with this exception, you may extend this exception to your
|
|
|
|
* version of the file(s), but you are not obligated to do so. If you
|
|
|
|
* do not wish to do so, delete this exception statement from your
|
|
|
|
* version. If you delete this exception statement from all source
|
|
|
|
* files in the program, then also delete it here.
|
2006-02-17 13:35:04 +00:00
|
|
|
*/
|
|
|
|
/* copyright --> */
|
|
|
|
#include "common.h"
|
2008-02-08 15:53:45 +00:00
|
|
|
#include "SharedHandle.h"
|
2007-03-21 10:19:23 +00:00
|
|
|
#include "LogFactory.h"
|
2008-02-08 15:53:45 +00:00
|
|
|
#include "Logger.h"
|
2006-02-17 13:35:04 +00:00
|
|
|
#include "Util.h"
|
2008-02-08 15:53:45 +00:00
|
|
|
#include "BitfieldManFactory.h"
|
|
|
|
#include "AuthConfigFactory.h"
|
|
|
|
#include "CookieBoxFactory.h"
|
2006-07-30 12:58:27 +00:00
|
|
|
#include "FeatureConfig.h"
|
2007-05-20 13:51:52 +00:00
|
|
|
#include "MultiUrlRequestInfo.h"
|
2006-12-24 06:25:21 +00:00
|
|
|
#include "SimpleRandomizer.h"
|
2007-03-18 15:42:34 +00:00
|
|
|
#include "Netrc.h"
|
2007-03-26 12:16:57 +00:00
|
|
|
#include "FatalException.h"
|
|
|
|
#include "File.h"
|
2007-05-20 13:51:52 +00:00
|
|
|
#include "CUIDCounter.h"
|
2008-02-08 15:53:45 +00:00
|
|
|
#include "UriListParser.h"
|
2007-07-05 15:14:00 +00:00
|
|
|
#include "message.h"
|
2008-02-08 15:53:45 +00:00
|
|
|
#include "prefs.h"
|
|
|
|
#include "Option.h"
|
|
|
|
#include "a2algo.h"
|
2007-07-23 13:04:48 +00:00
|
|
|
#include "a2io.h"
|
2007-07-31 16:45:16 +00:00
|
|
|
#include "a2time.h"
|
2007-07-23 13:04:48 +00:00
|
|
|
#include "Platform.h"
|
2007-08-28 11:51:20 +00:00
|
|
|
#include "ParameterizedStringParser.h"
|
|
|
|
#include "PStringBuildVisitor.h"
|
2007-10-11 16:58:24 +00:00
|
|
|
#include "SingleFileDownloadContext.h"
|
|
|
|
#include "DefaultBtContext.h"
|
2008-02-08 15:53:45 +00:00
|
|
|
#include "FileEntry.h"
|
2007-10-11 16:58:24 +00:00
|
|
|
#include "RequestGroup.h"
|
2008-02-08 15:53:45 +00:00
|
|
|
#ifdef ENABLE_METALINK
|
|
|
|
# include "MetalinkHelper.h"
|
|
|
|
# include "Metalink2RequestGroup.h"
|
|
|
|
# include "MetalinkEntry.h"
|
|
|
|
#endif // ENABLE_METALINK
|
2006-03-22 16:21:11 +00:00
|
|
|
#include <deque>
|
2006-02-17 13:35:04 +00:00
|
|
|
#include <signal.h>
|
|
|
|
#include <unistd.h>
|
2007-03-26 12:16:57 +00:00
|
|
|
#include <fstream>
|
2008-02-08 15:53:45 +00:00
|
|
|
#include <iostream>
|
2006-02-17 13:35:04 +00:00
|
|
|
extern char* optarg;
|
|
|
|
extern int optind, opterr, optopt;
|
|
|
|
#include <getopt.h>
|
|
|
|
|
2006-02-17 18:51:12 +00:00
|
|
|
#ifdef HAVE_LIBSSL
|
|
|
|
// for SSL
|
|
|
|
# include <openssl/err.h>
|
|
|
|
# include <openssl/ssl.h>
|
|
|
|
#endif // HAVE_LIBSSL
|
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-27 14:47:26 +00:00
|
|
|
#ifdef HAVE_LIBGNUTLS
|
|
|
|
# include <gnutls/gnutls.h>
|
|
|
|
#endif // HAVE_LIBGNUTLS
|
2006-02-17 18:51:12 +00:00
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
namespace aria2 {
|
|
|
|
|
|
|
|
std::deque<std::string> unfoldURI(const std::deque<std::string>& args)
|
2007-08-28 11:51:20 +00:00
|
|
|
{
|
2008-02-08 15:53:45 +00:00
|
|
|
std::deque<std::string> nargs;
|
2007-08-28 11:51:20 +00:00
|
|
|
ParameterizedStringParser p;
|
2008-02-08 15:53:45 +00:00
|
|
|
PStringBuildVisitor v;
|
|
|
|
for(std::deque<std::string>::const_iterator itr = args.begin(); itr != args.end();
|
2007-08-28 11:51:20 +00:00
|
|
|
++itr) {
|
2008-02-08 15:53:45 +00:00
|
|
|
v.reset();
|
|
|
|
p.parse(*itr)->accept(&v);
|
|
|
|
nargs.insert(nargs.end(), v.getURIs().begin(), v.getURIs().end());
|
2007-08-28 11:51:20 +00:00
|
|
|
}
|
|
|
|
return nargs;
|
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
RequestGroupHandle createRequestGroup(const Option* op, const std::deque<std::string>& uris,
|
|
|
|
const std::string& ufilename = "")
|
2007-08-28 15:46:49 +00:00
|
|
|
{
|
2007-10-11 16:58:24 +00:00
|
|
|
RequestGroupHandle rg = new RequestGroup(op, uris);
|
|
|
|
SingleFileDownloadContextHandle dctx =
|
|
|
|
new SingleFileDownloadContext(op->getAsInt(PREF_SEGMENT_SIZE),
|
|
|
|
0,
|
|
|
|
"",
|
|
|
|
ufilename);
|
|
|
|
dctx->setDir(op->get(PREF_DIR));
|
|
|
|
rg->setDownloadContext(dctx);
|
|
|
|
return rg;
|
2007-08-28 15:46:49 +00:00
|
|
|
}
|
|
|
|
|
2007-10-11 16:58:24 +00:00
|
|
|
extern Option* option_processing(int argc, char* const argv[]);
|
|
|
|
|
2007-11-14 10:10:38 +00:00
|
|
|
#ifdef ENABLE_BITTORRENT
|
2008-02-20 16:46:56 +00:00
|
|
|
int32_t downloadBitTorrent(Option* op, const std::deque<std::string>& uri)
|
2007-11-03 08:58:45 +00:00
|
|
|
{
|
2008-02-08 15:53:45 +00:00
|
|
|
std::deque<std::string> nargs;
|
2007-11-03 08:58:45 +00:00
|
|
|
if(op->get(PREF_PARAMETERIZED_URI) == V_TRUE) {
|
|
|
|
nargs = unfoldURI(uri);
|
|
|
|
} else {
|
|
|
|
nargs = uri;
|
|
|
|
}
|
2008-02-08 15:53:45 +00:00
|
|
|
std::deque<std::string> xargs;
|
2007-11-03 08:58:45 +00:00
|
|
|
ncopy(nargs.begin(), nargs.end(), op->getAsInt(PREF_SPLIT),
|
2008-02-08 18:39:26 +00:00
|
|
|
std::back_inserter(xargs));
|
2007-11-03 08:58:45 +00:00
|
|
|
|
|
|
|
RequestGroupHandle rg = new RequestGroup(op, xargs);
|
|
|
|
DefaultBtContextHandle btContext = new DefaultBtContext();
|
|
|
|
btContext->load(op->get(PREF_TORRENT_FILE));
|
|
|
|
if(op->defined(PREF_PEER_ID_PREFIX)) {
|
|
|
|
btContext->setPeerIdPrefix(op->get(PREF_PEER_ID_PREFIX));
|
|
|
|
}
|
|
|
|
btContext->setDir(op->get(PREF_DIR));
|
|
|
|
rg->setDownloadContext(btContext);
|
|
|
|
btContext->setOwnerRequestGroup(rg.get());
|
|
|
|
|
|
|
|
RequestGroups groups;
|
|
|
|
groups.push_back(rg);
|
2008-02-20 16:46:56 +00:00
|
|
|
return MultiUrlRequestInfo(groups, op).execute();
|
2007-11-03 08:58:45 +00:00
|
|
|
}
|
2007-11-14 10:10:38 +00:00
|
|
|
#endif // ENABLE_BITTORRENT
|
2007-11-03 08:58:45 +00:00
|
|
|
|
2007-11-14 10:10:38 +00:00
|
|
|
#ifdef ENABLE_METALINK
|
2008-02-20 16:46:56 +00:00
|
|
|
int32_t downloadMetalink(Option* op)
|
2007-11-03 08:58:45 +00:00
|
|
|
{
|
|
|
|
RequestGroups groups = Metalink2RequestGroup(op).generate(op->get(PREF_METALINK_FILE));
|
|
|
|
if(groups.empty()) {
|
|
|
|
throw new FatalException("No files to download.");
|
|
|
|
}
|
2008-02-20 16:46:56 +00:00
|
|
|
return MultiUrlRequestInfo(groups, op).execute();
|
2007-11-03 08:58:45 +00:00
|
|
|
}
|
2007-11-14 10:10:38 +00:00
|
|
|
#endif // ENABLE_METALINK
|
2007-11-03 08:58:45 +00:00
|
|
|
|
2008-02-20 16:46:56 +00:00
|
|
|
int32_t downloadUriList(Option* op, std::istream& in)
|
2007-11-03 08:58:45 +00:00
|
|
|
{
|
2008-02-08 15:53:45 +00:00
|
|
|
UriListParser p;
|
2007-11-03 08:58:45 +00:00
|
|
|
RequestGroups groups;
|
2008-02-08 15:53:45 +00:00
|
|
|
while(in) {
|
|
|
|
std::deque<std::string> uris = p.parseNext(in);
|
2007-11-03 08:58:45 +00:00
|
|
|
if(uris.size() == 1 && op->get(PREF_PARAMETERIZED_URI) == V_TRUE) {
|
2008-02-08 15:53:45 +00:00
|
|
|
std::deque<std::string> unfoldedURIs = unfoldURI(uris);
|
|
|
|
for(std::deque<std::string>::const_iterator itr = unfoldedURIs.begin();
|
2007-11-03 08:58:45 +00:00
|
|
|
itr != unfoldedURIs.end(); ++itr) {
|
2008-02-08 15:53:45 +00:00
|
|
|
std::deque<std::string> xuris;
|
2008-02-08 18:39:26 +00:00
|
|
|
ncopy(itr, itr+1, op->getAsInt(PREF_SPLIT), std::back_inserter(xuris));
|
2008-02-08 15:53:45 +00:00
|
|
|
SharedHandle<RequestGroup> rg = createRequestGroup(op, xuris);
|
2007-11-03 08:58:45 +00:00
|
|
|
groups.push_back(rg);
|
|
|
|
}
|
|
|
|
} else if(uris.size() > 0) {
|
2008-02-08 15:53:45 +00:00
|
|
|
std::deque<std::string> xuris;
|
2007-11-03 08:58:45 +00:00
|
|
|
ncopy(uris.begin(), uris.end(), op->getAsInt(PREF_SPLIT),
|
2008-02-08 18:39:26 +00:00
|
|
|
std::back_inserter(xuris));
|
2008-02-08 15:53:45 +00:00
|
|
|
SharedHandle<RequestGroup> rg = createRequestGroup(op, xuris);
|
2007-11-03 08:58:45 +00:00
|
|
|
groups.push_back(rg);
|
|
|
|
}
|
|
|
|
}
|
2008-02-20 16:46:56 +00:00
|
|
|
return MultiUrlRequestInfo(groups, op).execute();
|
2007-11-03 08:58:45 +00:00
|
|
|
}
|
|
|
|
|
2008-02-20 16:46:56 +00:00
|
|
|
int32_t downloadUriList(Option* op)
|
2008-02-08 15:53:45 +00:00
|
|
|
{
|
|
|
|
if(op->get(PREF_INPUT_FILE) == "-") {
|
2008-02-20 16:46:56 +00:00
|
|
|
return downloadUriList(op, std::cin);
|
2008-02-08 15:53:45 +00:00
|
|
|
} else {
|
|
|
|
if(!File(op->get(PREF_INPUT_FILE)).isFile()) {
|
|
|
|
throw new FatalException(EX_FILE_OPEN, op->get(PREF_INPUT_FILE).c_str(), "No such file");
|
|
|
|
}
|
|
|
|
std::ifstream f(op->get(PREF_INPUT_FILE).c_str());
|
2008-02-20 16:46:56 +00:00
|
|
|
return downloadUriList(op, f);
|
2008-02-08 15:53:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-20 16:46:56 +00:00
|
|
|
int32_t downloadUri(Option* op, const std::deque<std::string>& uris)
|
2007-11-03 08:58:45 +00:00
|
|
|
{
|
2008-02-08 15:53:45 +00:00
|
|
|
std::deque<std::string> nargs;
|
2007-11-03 08:58:45 +00:00
|
|
|
if(op->get(PREF_PARAMETERIZED_URI) == V_TRUE) {
|
|
|
|
nargs = unfoldURI(uris);
|
|
|
|
} else {
|
|
|
|
nargs = uris;
|
|
|
|
}
|
|
|
|
RequestGroups groups;
|
|
|
|
if(op->get(PREF_FORCE_SEQUENTIAL) == V_TRUE) {
|
2008-02-08 15:53:45 +00:00
|
|
|
for(std::deque<std::string>::const_iterator itr = nargs.begin();
|
2007-11-03 08:58:45 +00:00
|
|
|
itr != nargs.end(); ++itr) {
|
2008-02-08 15:53:45 +00:00
|
|
|
std::deque<std::string> xuris;
|
2007-11-03 08:58:45 +00:00
|
|
|
ncopy(itr, itr+1, op->getAsInt(PREF_SPLIT),
|
2008-02-08 18:39:26 +00:00
|
|
|
std::back_inserter(xuris));
|
2007-11-03 08:58:45 +00:00
|
|
|
RequestGroupHandle rg = createRequestGroup(op, xuris);
|
|
|
|
groups.push_back(rg);
|
|
|
|
}
|
|
|
|
} else {
|
2008-02-08 15:53:45 +00:00
|
|
|
std::deque<std::string> xargs;
|
2007-11-03 08:58:45 +00:00
|
|
|
ncopy(nargs.begin(), nargs.end(), op->getAsInt(PREF_SPLIT),
|
2008-02-08 18:39:26 +00:00
|
|
|
std::back_inserter(xargs));
|
2007-11-03 08:58:45 +00:00
|
|
|
RequestGroupHandle rg = createRequestGroup(op, xargs, op->get(PREF_OUT));
|
|
|
|
groups.push_back(rg);
|
|
|
|
}
|
2008-02-20 16:46:56 +00:00
|
|
|
return MultiUrlRequestInfo(groups, op).execute();
|
2007-11-03 08:58:45 +00:00
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
2007-10-11 16:58:24 +00:00
|
|
|
Option* op = option_processing(argc, argv);
|
2008-02-08 15:53:45 +00:00
|
|
|
std::deque<std::string> args(argv+optind, argv+argc);
|
|
|
|
|
2006-12-24 06:25:21 +00:00
|
|
|
SimpleRandomizer::init();
|
|
|
|
BitfieldManFactory::setDefaultRandomizer(SimpleRandomizer::getInstance());
|
2006-08-03 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
* src/Option.h
(getAsBool): New function.
* src/Option.cc
(prefs.h): Included.
(defined): 0-length value is now recognized as undefined.
(getAsInt): Rewritten.
(getAsLLInt): Rewritten.
(getAsBool): New function.
* src/FeatureConfig.h: Rewritten.
* src/FeatureConfig.cc: Rewritten.
* src/prefs.h
(PREF_STDOUT_LOG): New definition.
(PREF_LOG): New definition.
(PREF_DIR): New definition.
(PREF_OUT): New definition.
(PREF_SPLIT): New definition.
(PREF_DAEMON): New definition.
(PREF_REFERER): New definition.
(PREF_TORRENT_FILE): New definition.
(PREF_LISTEN_PORT): New definition.
(PREF_METALINK_FILE): New definition.
(PREF_METALINK_VERSION): New definition.
(PREF_METALINK_LANGUAGE): New definition.
(PREF_METALINK_OS): New definition.
(PREF_METALINK_SERVERS): New definition.
* src/main.cc
(main): Following command-line parameters are now put into
Option
class: stdoutLog, logfile, dir, ufilename, split, daemonMode,
referer, torrentFile, metalinkFile, listenPort, metalinkVersion,
metalinkLanguage, metalinkOs, metalinkServers
To fix the bug that aria2 can not handle http response header
properly.
* src/HttpHeader.cc
(put): Made name lowercased.
(defined): Made name lowercased.
(getFirst): Made name lowercased.
(get): Made name lowercased.
(getFirstAsInt): Rewritten.
(getFirstAsLLInt): Rewritten.
2006-08-03 12:36:02 +00:00
|
|
|
if(op->getAsBool(PREF_STDOUT_LOG)) {
|
2007-07-23 13:04:48 +00:00
|
|
|
LogFactory::setLogFile(DEV_STDOUT);
|
2006-08-03 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
* src/Option.h
(getAsBool): New function.
* src/Option.cc
(prefs.h): Included.
(defined): 0-length value is now recognized as undefined.
(getAsInt): Rewritten.
(getAsLLInt): Rewritten.
(getAsBool): New function.
* src/FeatureConfig.h: Rewritten.
* src/FeatureConfig.cc: Rewritten.
* src/prefs.h
(PREF_STDOUT_LOG): New definition.
(PREF_LOG): New definition.
(PREF_DIR): New definition.
(PREF_OUT): New definition.
(PREF_SPLIT): New definition.
(PREF_DAEMON): New definition.
(PREF_REFERER): New definition.
(PREF_TORRENT_FILE): New definition.
(PREF_LISTEN_PORT): New definition.
(PREF_METALINK_FILE): New definition.
(PREF_METALINK_VERSION): New definition.
(PREF_METALINK_LANGUAGE): New definition.
(PREF_METALINK_OS): New definition.
(PREF_METALINK_SERVERS): New definition.
* src/main.cc
(main): Following command-line parameters are now put into
Option
class: stdoutLog, logfile, dir, ufilename, split, daemonMode,
referer, torrentFile, metalinkFile, listenPort, metalinkVersion,
metalinkLanguage, metalinkOs, metalinkServers
To fix the bug that aria2 can not handle http response header
properly.
* src/HttpHeader.cc
(put): Made name lowercased.
(defined): Made name lowercased.
(getFirst): Made name lowercased.
(get): Made name lowercased.
(getFirstAsInt): Rewritten.
(getFirstAsLLInt): Rewritten.
2006-08-03 12:36:02 +00:00
|
|
|
} else if(op->get(PREF_LOG).size()) {
|
|
|
|
LogFactory::setLogFile(op->get(PREF_LOG));
|
2006-08-27 12:49:17 +00:00
|
|
|
} else {
|
2007-07-23 13:04:48 +00:00
|
|
|
LogFactory::setLogFile(DEV_NULL);
|
2006-02-17 13:35:04 +00:00
|
|
|
}
|
2007-07-21 08:56:16 +00:00
|
|
|
int32_t exitStatus = EXIT_SUCCESS;
|
2006-04-19 17:23:58 +00:00
|
|
|
try {
|
2006-08-07 16:05:00 +00:00
|
|
|
Logger* logger = LogFactory::getInstance();
|
2007-11-14 10:10:38 +00:00
|
|
|
logger->info("%s %s %s", PACKAGE, PACKAGE_VERSION, TARGET);
|
2007-07-20 17:06:21 +00:00
|
|
|
logger->info(MSG_LOGGING_STARTED);
|
2006-04-19 17:23:58 +00:00
|
|
|
|
2007-10-30 12:48:01 +00:00
|
|
|
AuthConfigFactoryHandle authConfigFactory = new AuthConfigFactory(op);
|
2007-03-29 11:29:45 +00:00
|
|
|
File netrccf(op->get(PREF_NETRC_PATH));
|
|
|
|
if(!op->getAsBool(PREF_NO_NETRC) && netrccf.isFile()) {
|
|
|
|
mode_t mode = netrccf.mode();
|
|
|
|
if(mode&(S_IRWXG|S_IRWXO)) {
|
2007-07-20 17:06:21 +00:00
|
|
|
logger->notice(MSG_INCORRECT_NETRC_PERMISSION,
|
2007-03-29 11:29:45 +00:00
|
|
|
op->get(PREF_NETRC_PATH).c_str());
|
|
|
|
} else {
|
|
|
|
NetrcHandle netrc = new Netrc();
|
|
|
|
netrc->parse(op->get(PREF_NETRC_PATH));
|
2007-10-30 12:48:01 +00:00
|
|
|
authConfigFactory->setNetrc(netrc);
|
2007-03-29 11:29:45 +00:00
|
|
|
}
|
|
|
|
}
|
2007-06-10 07:55:43 +00:00
|
|
|
|
|
|
|
CookieBoxFactoryHandle cookieBoxFactory = new CookieBoxFactory();
|
|
|
|
CookieBoxFactorySingletonHolder::instance(cookieBoxFactory);
|
|
|
|
if(op->defined(PREF_LOAD_COOKIES)) {
|
|
|
|
File cookieFile(op->get(PREF_LOAD_COOKIES));
|
|
|
|
if(cookieFile.isFile()) {
|
2008-02-08 15:53:45 +00:00
|
|
|
std::ifstream in(op->get(PREF_LOAD_COOKIES).c_str());
|
2007-06-10 07:55:43 +00:00
|
|
|
CookieBoxFactorySingletonHolder::instance()->loadDefaultCookie(in);
|
|
|
|
} else {
|
2007-07-20 17:06:21 +00:00
|
|
|
logger->error(MSG_LOADING_COOKIE_FAILED, op->get(PREF_LOAD_COOKIES).c_str());
|
2007-06-10 07:55:43 +00:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-30 12:48:01 +00:00
|
|
|
AuthConfigFactorySingleton::instance(authConfigFactory);
|
2007-05-20 13:51:52 +00:00
|
|
|
CUIDCounterHandle cuidCounter = new CUIDCounter();
|
|
|
|
CUIDCounterSingletonHolder::instance(cuidCounter);
|
2007-07-23 13:04:48 +00:00
|
|
|
#ifdef SIGPIPE
|
2006-11-09 14:04:46 +00:00
|
|
|
Util::setGlobalSignalHandler(SIGPIPE, SIG_IGN, 0);
|
2007-07-23 13:04:48 +00:00
|
|
|
#endif
|
2008-02-20 16:46:56 +00:00
|
|
|
int32_t returnValue = 0;
|
2006-08-07 16:05:00 +00:00
|
|
|
#ifdef ENABLE_BITTORRENT
|
|
|
|
if(op->defined(PREF_TORRENT_FILE)) {
|
2007-11-03 08:58:45 +00:00
|
|
|
if(op->get(PREF_SHOW_FILES) == V_TRUE) {
|
|
|
|
DefaultBtContextHandle btContext = new DefaultBtContext();
|
|
|
|
btContext->load(op->get(PREF_TORRENT_FILE));
|
2008-02-08 15:53:45 +00:00
|
|
|
std::cout << btContext << std::endl;
|
2007-10-11 16:58:24 +00:00
|
|
|
} else {
|
2008-02-20 16:46:56 +00:00
|
|
|
returnValue = downloadBitTorrent(op, args);
|
2006-03-21 14:12:51 +00:00
|
|
|
}
|
2006-02-17 13:35:04 +00:00
|
|
|
}
|
2006-08-07 16:05:00 +00:00
|
|
|
else
|
|
|
|
#endif // ENABLE_BITTORRENT
|
2006-07-04 10:57:56 +00:00
|
|
|
#ifdef ENABLE_METALINK
|
2006-08-07 16:05:00 +00:00
|
|
|
if(op->defined(PREF_METALINK_FILE)) {
|
2007-11-03 12:03:53 +00:00
|
|
|
if(op->get(PREF_SHOW_FILES) == V_TRUE) {
|
2008-02-08 15:53:45 +00:00
|
|
|
Util::toStream(std::cout, MetalinkEntry::toFileEntry(MetalinkHelper::parseAndQuery(op->get(PREF_METALINK_FILE), op)));
|
2007-11-03 12:03:53 +00:00
|
|
|
} else {
|
2008-02-20 16:46:56 +00:00
|
|
|
returnValue = downloadMetalink(op);
|
2007-11-03 12:03:53 +00:00
|
|
|
}
|
2007-05-20 13:51:52 +00:00
|
|
|
}
|
|
|
|
else
|
2006-08-07 16:05:00 +00:00
|
|
|
#endif // ENABLE_METALINK
|
2007-05-20 13:51:52 +00:00
|
|
|
if(op->defined(PREF_INPUT_FILE)) {
|
2008-02-20 16:46:56 +00:00
|
|
|
returnValue = downloadUriList(op);
|
2007-11-03 08:58:45 +00:00
|
|
|
} else {
|
2008-02-20 16:46:56 +00:00
|
|
|
returnValue = downloadUri(op, args);
|
2006-08-07 16:05:00 +00:00
|
|
|
}
|
2008-02-20 16:46:56 +00:00
|
|
|
if(returnValue == 1) {
|
|
|
|
exitStatus = EXIT_FAILURE;
|
|
|
|
}
|
2006-08-07 16:05:00 +00:00
|
|
|
} catch(Exception* ex) {
|
2008-02-08 15:53:45 +00:00
|
|
|
std::cerr << EX_EXCEPTION_CAUGHT << "\n" << *ex << std::endl;
|
2006-08-07 16:05:00 +00:00
|
|
|
delete ex;
|
2008-02-20 16:46:56 +00:00
|
|
|
exitStatus = EXIT_FAILURE;
|
2006-03-02 02:54:49 +00:00
|
|
|
}
|
2006-05-09 15:54:14 +00:00
|
|
|
delete op;
|
|
|
|
LogFactory::release();
|
2008-02-08 15:53:45 +00:00
|
|
|
FeatureConfig::release();
|
|
|
|
return exitStatus;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace aria2
|
|
|
|
|
|
|
|
int main(int argc, char* argv[]) {
|
|
|
|
#ifdef HAVE_WINSOCK2_H
|
|
|
|
aria2::Platform platform;
|
|
|
|
#endif // HAVE_WINSOCK2_H
|
|
|
|
|
|
|
|
#ifdef ENABLE_NLS
|
|
|
|
setlocale (LC_CTYPE, "");
|
|
|
|
setlocale (LC_MESSAGES, "");
|
|
|
|
bindtextdomain (PACKAGE, LOCALEDIR);
|
|
|
|
textdomain (PACKAGE);
|
|
|
|
#endif // ENABLE_NLS
|
|
|
|
|
|
|
|
#ifdef HAVE_LIBSSL
|
|
|
|
// for SSL initialization
|
|
|
|
SSL_load_error_strings();
|
|
|
|
SSL_library_init();
|
|
|
|
#endif // HAVE_LIBSSL
|
|
|
|
#ifdef HAVE_LIBGNUTLS
|
|
|
|
gnutls_global_init();
|
|
|
|
#endif // HAVE_LIBGNUTLS
|
|
|
|
|
|
|
|
int r = aria2::main(argc, argv);
|
|
|
|
|
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-27 14:47:26 +00:00
|
|
|
#ifdef HAVE_LIBGNUTLS
|
|
|
|
gnutls_global_deinit();
|
|
|
|
#endif // HAVE_LIBGNUTLS
|
2008-02-08 15:53:45 +00:00
|
|
|
|
|
|
|
return r;
|
2006-02-17 13:35:04 +00:00
|
|
|
}
|