main.cc 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968
  1. /* <!-- copyright */
  2. /*
  3. * aria2 - The high speed download utility
  4. *
  5. * Copyright (C) 2006 Tatsuhiro Tsujikawa
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. *
  21. * In addition, as a special exception, the copyright holders give
  22. * permission to link the code of portions of this program with the
  23. * OpenSSL library under certain conditions as described in each
  24. * individual source file, and distribute linked combinations
  25. * including the two.
  26. * You must obey the GNU General Public License in all respects
  27. * for all of the code used other than OpenSSL. If you modify
  28. * file(s) with this exception, you may extend this exception to your
  29. * version of the file(s), but you are not obligated to do so. If you
  30. * do not wish to do so, delete this exception statement from your
  31. * version. If you delete this exception statement from all source
  32. * files in the program, then also delete it here.
  33. */
  34. /* copyright --> */
  35. #include "common.h"
  36. #include "LogFactory.h"
  37. #include "Util.h"
  38. #include "FeatureConfig.h"
  39. #include "MultiUrlRequestInfo.h"
  40. #include "TorrentRequestInfo.h"
  41. #include "BitfieldManFactory.h"
  42. #include "SimpleRandomizer.h"
  43. #include "ConsoleFileAllocationMonitor.h"
  44. #include "Netrc.h"
  45. #include "RequestFactory.h"
  46. #include "OptionParser.h"
  47. #include "OptionHandlerFactory.h"
  48. #include "FatalException.h"
  49. #include "File.h"
  50. #include "CUIDCounter.h"
  51. #include "FileUriListParser.h"
  52. #include "StreamUriListParser.h"
  53. #include "CookieBoxFactory.h"
  54. #include "a2algo.h"
  55. #include "message.h"
  56. #include "a2io.h"
  57. #include "a2time.h"
  58. #include "Platform.h"
  59. #include "prefs.h"
  60. #include "ParameterizedStringParser.h"
  61. #include "PStringBuildVisitor.h"
  62. #include <deque>
  63. #include <algorithm>
  64. #include <signal.h>
  65. #include <unistd.h>
  66. #include <libgen.h>
  67. #include <utility>
  68. #include <fstream>
  69. #include <sstream>
  70. extern char* optarg;
  71. extern int optind, opterr, optopt;
  72. #include <getopt.h>
  73. #ifdef ENABLE_METALINK
  74. #include "MetalinkRequestInfo.h"
  75. #include "Xml2MetalinkProcessor.h"
  76. #endif
  77. #ifdef HAVE_LIBSSL
  78. // for SSL
  79. # include <openssl/err.h>
  80. # include <openssl/ssl.h>
  81. #endif // HAVE_LIBSSL
  82. #ifdef HAVE_LIBGNUTLS
  83. # include <gnutls/gnutls.h>
  84. #endif // HAVE_LIBGNUTLS
  85. using namespace std;
  86. void showVersion() {
  87. cout << PACKAGE << _(" version ") << PACKAGE_VERSION << endl;
  88. cout << "**Configuration**" << endl;
  89. cout << FeatureConfig::getInstance()->getConfigurationSummary();
  90. #ifdef ENABLE_MESSAGE_DIGEST
  91. cout << "message digest algorithms: " << MessageDigestContext::getSupportedAlgoString() << endl;
  92. #endif // ENABLE_MESSAGE_DIGEST
  93. cout << endl;
  94. cout << "Copyright (C) 2006, 2007 Tatsuhiro Tsujikawa" << endl;
  95. cout << endl;
  96. cout <<
  97. _("This program is free software; you can redistribute it and/or modify\n"
  98. "it under the terms of the GNU General Public License as published by\n"
  99. "the Free Software Foundation; either version 2 of the License, or\n"
  100. "(at your option) any later version.\n"
  101. "\n"
  102. "This program is distributed in the hope that it will be useful,\n"
  103. "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
  104. "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
  105. "GNU General Public License for more details.\n"
  106. "\n"
  107. "You should have received a copy of the GNU General Public License\n"
  108. "along with this program; if not, write to the Free Software\n"
  109. "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n");
  110. cout << endl;
  111. cout << _("Contact Info:") << endl;
  112. cout << "Tatsuhiro Tsujikawa <tujikawa at users dot sourceforge dot net>" << endl;
  113. cout << endl;
  114. }
  115. void showUsage() {
  116. printf(_("Usage: %s [options] URL ...\n"), PACKAGE_NAME);
  117. #ifdef ENABLE_BITTORRENT
  118. printf(_(" %s [options] -T TORRENT_FILE FILE ...\n"), PACKAGE_NAME);
  119. #endif // ENABLE_BITTORRENT
  120. #ifdef ENABLE_METALINK
  121. printf(_(" %s [options] -M METALINK_FILE\n"), PACKAGE_NAME);
  122. #endif // ENABLE_METALINK
  123. cout << endl;
  124. cout << _("Options:") << endl;
  125. cout << _(" -d, --dir=DIR The directory to store the downloaded file.") << endl;
  126. cout << _(" -o, --out=FILE The file name of the downloaded file.") << endl;
  127. cout << _(" -l, --log=LOG The file name of the log file. If '-' is\n"
  128. " specified, log is written to stdout.") << endl;
  129. #ifdef HAVE_DAEMON
  130. cout << _(" -D, --daemon Run as daemon.") << endl;
  131. #endif // HAVE_DAEMON
  132. cout << _(" -s, --split=N Download a file using N connections. N must be\n"
  133. " between 1 and 5. This option affects all URLs.\n"
  134. " Thus, aria2 connects to each URL with\n"
  135. " N connections.\n"
  136. " Default: 1") << endl;
  137. cout << _(" --retry-wait=SEC Set the seconds to wait to retry after an error\n"
  138. " has occured. Specify a value between 0 and 60.\n"
  139. " Default: 5") << endl;
  140. cout << _(" -t, --timeout=SEC Set timeout in seconds. Default: 60") << endl;
  141. cout << _(" -m, --max-tries=N Set number of tries. 0 means unlimited.\n"
  142. " Default: 5") << endl;
  143. /*
  144. cout << _(" --min-segment-size=SIZE[K|M] Set minimum segment size. You can append\n"
  145. " K or M(1K = 1024, 1M = 1024K). This\n"
  146. " value must be greater than or equal to\n"
  147. " 1024. Default: 1M") << endl;
  148. */
  149. cout << _(" --http-proxy=HOST:PORT Use HTTP proxy server. This affects all URLs.") << endl;
  150. cout << _(" --http-user=USER Set HTTP user. This affects all URLs.") << endl;
  151. cout << _(" --http-passwd=PASSWD Set HTTP password. This affects all URLs.") << endl;
  152. cout << _(" --http-proxy-user=USER Set HTTP proxy user. This affects all URLs.") << endl;
  153. cout << _(" --http-proxy-passwd=PASSWD Set HTTP proxy password. This affects all URLs.") << endl;
  154. cout << _(" --http-proxy-method=METHOD Set the method to use in proxy request.\n"
  155. " METHOD is either 'get' or 'tunnel'.\n"
  156. " Default: tunnel") << endl;
  157. cout << _(" --http-auth-scheme=SCHEME Set HTTP authentication scheme. Currently, basic\n"
  158. " is the only supported scheme.\n"
  159. " Default: basic") << endl;
  160. cout << _(" --referer=REFERER Set Referer. This affects all URLs.") << endl;
  161. cout << _(" --ftp-user=USER Set FTP user. This affects all URLs.\n"
  162. " Default: anonymous") << endl;
  163. cout << _(" --ftp-passwd=PASSWD Set FTP password. This affects all URLs.\n"
  164. " Default: ARIA2USER@") << endl;
  165. cout << _(" --ftp-type=TYPE Set FTP transfer type. TYPE is either 'binary'\n"
  166. " or 'ascii'.\n"
  167. " Default: binary") << endl;
  168. cout << _(" -p, --ftp-pasv Use passive mode in FTP.") << endl;
  169. cout << _(" --ftp-via-http-proxy=METHOD Use HTTP proxy in FTP. METHOD is either 'get' or\n"
  170. " 'tunnel'.\n"
  171. " Default: tunnel") << endl;
  172. cout << _(" --lowest-speed-limit=SPEED Close connection if download speed is lower than\n"
  173. " or equal to this value(bytes per sec).\n"
  174. " 0 means aria2 does not have a lowest speed limit.\n"
  175. " You can append K or M(1K = 1024, 1M = 1024K).\n"
  176. " This option does not affect BitTorrent downloads.\n"
  177. " Default: 0") << endl;
  178. cout << _(" --max-download-limit=SPEED Set max download speed in bytes per sec.\n"
  179. " 0 means unrestricted.\n"
  180. " You can append K or M(1K = 1024, 1M = 1024K).\n"
  181. " Default: 0") << endl;
  182. cout << _(" --file-allocation=METHOD Specify file allocation method. METHOD is either\n"
  183. " 'none' or 'prealloc'. 'none' doesn't pre-allocate\n"
  184. " file space. 'prealloc' pre-allocates file space\n"
  185. " before download begins. This may take some time\n"
  186. " depending on the size of the file.\n"
  187. " Default: prealloc") << endl;
  188. cout << _(" --no-file-allocation-limit=SIZE No file allocation is made for files whose\n"
  189. " size is smaller than SIZE.\n"
  190. " You can append K or M(1K = 1024, 1M = 1024K).\n"
  191. " BitTorrent downloads ignore this option.\n"
  192. " Default: 5M") << endl;
  193. cout << _(" --allow-overwrite=true|false If false, aria2 doesn't download a file which\n"
  194. " already exists but the corresponding .aria2 file\n"
  195. " doesn't exist.\n"
  196. " Default: false") << endl;
  197. cout << _(" -Z, --force-sequential[=true|false] Fetch URIs in the command-line sequentially\n"
  198. " and download each URI in a separate session, like\n"
  199. " the usual command-line download utilities.\n"
  200. " Default: false") << endl;
  201. cout << _(" --auto-file-renaming[=true|false] Rename file name if the same file already\n"
  202. " exists. This option works only in http(s)/ftp\n"
  203. " download.\n"
  204. " The new file name has a dot and a number(1..9999)\n"
  205. " appended.\n"
  206. " Default: true") << endl;
  207. cout << _(" -P, --parameterized-uri[=true|false] Enable parameterized URI support.\n"
  208. " You can specify set of parts:\n"
  209. " http://{sv1,sv2,sv3}/foo.iso\n"
  210. " Also you can specify numeric sequences with step\n"
  211. " counter:\n"
  212. " http://host/image[000-100:2].img\n"
  213. " A step counter can be omitted.\n"
  214. " If all URIs do not point to the same file, such\n"
  215. " as the second example above, -Z option is\n"
  216. " required.\n"
  217. " Default: false") << endl;
  218. #ifdef ENABLE_MESSAGE_DIGEST
  219. cout << _(" --check-integrity=true|false Check file integrity by validating piece hash.\n"
  220. " This option only affects in BitTorrent downloads\n"
  221. " and Metalink downloads with chunk checksums.\n"
  222. " Use this option to re-download a damaged portion\n"
  223. " of a file.\n"
  224. " You may need to specify --allow-overwrite=true\n"
  225. " if the .aria2 file doesn't exist.\n"
  226. " Default: false") << endl;
  227. cout << _(" --realtime-chunk-checksum=true|false Validate chunk checksum while\n"
  228. " downloading a file in Metalink mode. This option\n"
  229. " on affects Metalink mode with chunk checksums.\n"
  230. " Default: true") << endl;
  231. #endif // ENABLE_MESSAGE_DIGEST
  232. cout << _(" -c, --continue Continue downloading a partially downloaded\n"
  233. " file. Use this option to resume a download\n"
  234. " started by a web browser or another program\n"
  235. " which downloads files sequentially from the\n"
  236. " beginning. Currently this option is only\n"
  237. " applicable to http(s)/ftp downloads.") << endl;
  238. cout << _(" -U, --user-agent=USER_AGENT Set user agent for http(s) downloads.") << endl;
  239. cout << _(" -n, --no-netrc Disables netrc support.") << endl;
  240. cout << _(" -i, --input-file=FILE Downloads URIs found in FILE. You can specify\n"
  241. " multiple URIs for a single entity: separate\n"
  242. " URIs on a single line using the TAB character.\n"
  243. " Reads input from stdin when '-' is specified.") << endl;
  244. cout << _(" -j, --max-concurrent-downloads=N Set maximum number of concurrent downloads.\n"
  245. " It should be used with the -i option.\n"
  246. " Default: 5") << endl;
  247. cout << _(" --load-cookies=FILE Load cookies from FILE. The format of FILE is\n"
  248. " the same used by Netscape and Mozilla.") << endl;
  249. #if defined ENABLE_BITTORRENT || ENABLE_METALINK
  250. cout << _(" -S, --show-files Print file listing of .torrent or .metalink file\n"
  251. " and exit.") << endl;
  252. cout << _(" --select-file=INDEX... Set file to download by specifing its index.\n"
  253. " You can find the file index using the\n"
  254. " --show-files option. Multiple indexes can be\n"
  255. " specified by using ',', for example: \"3,6\".\n"
  256. " You can also use '-' to specify a range: \"1-5\".\n"
  257. " ',' and '-' can be used together.\n"
  258. " When used with the -M option, index may vary\n"
  259. " depending on the query(see --metalink-* options).") << endl;
  260. #endif // ENABLE_BITTORRENT || ENABLE_METALINK
  261. #ifdef ENABLE_BITTORRENT
  262. cout << _(" -T, --torrent-file=TORRENT_FILE The path to the .torrent file.") << endl;
  263. cout << _(" --follow-torrent=true|false Set to false to prevent aria2 from\n"
  264. " entering BitTorrent mode even if the filename of\n"
  265. " the downloaded file ends with .torrent.\n"
  266. " Default: true") << endl;
  267. cout << _(" --direct-file-mapping=true|false Directly read from and write to each file\n"
  268. " mentioned in .torrent file.\n"
  269. " Default: true") << endl;
  270. cout << _(" --listen-port=PORT Set TCP port number for BitTorrent downloads.\n"
  271. " Default: 6881-6999") << endl;
  272. cout << _(" --max-upload-limit=SPEED Set max upload speed in bytes per sec.\n"
  273. " 0 means unrestricted.\n"
  274. " You can append K or M(1K = 1024, 1M = 1024K).\n"
  275. " Default: 0") << endl;
  276. cout << _(" --seed-time=MINUTES Specify seeding time in minutes. Also see the\n"
  277. " --seed-ratio option.") << endl;
  278. cout << _(" --seed-ratio=RATIO Specify share ratio. Seed completed torrents\n"
  279. " until share ratio reaches RATIO. 1.0 is\n"
  280. " encouraged. If --seed-time option is specified\n"
  281. " along with this option, seeding ends when at\n"
  282. " least one of the conditions is satisfied.") << endl;
  283. cout << _(" --peer-id-prefix=PEERI_ID_PREFIX Specify the prefix of peer ID. The peer ID in\n"
  284. " in BitTorrent is 20 byte length. If more than 20\n"
  285. " bytes are specified, only first 20\n"
  286. " bytes are used. If less than 20 bytes are\n"
  287. " specified, the random alphabet characters are\n"
  288. " added to make it's length 20 bytes.\n"
  289. " Default: -aria2-") << endl;
  290. #endif // ENABLE_BITTORRENT
  291. #ifdef ENABLE_METALINK
  292. cout << _(" -M, --metalink-file=METALINK_FILE The file path to the .metalink file.") << endl;
  293. cout << _(" -C, --metalink-servers=NUM_SERVERS The number of servers to connect to\n"
  294. " simultaneously.\n"
  295. " Default: 5") << endl;
  296. cout << _(" --metalink-version=VERSION The version of the file to download.") << endl;
  297. cout << _(" --metalink-language=LANGUAGE The language of the file to download.") << endl;
  298. cout << _(" --metalink-os=OS The operating system of the file to download.") << endl;
  299. cout << _(" --metalink-location=LOCATION The location of the prefered server.") << endl;
  300. cout << _(" --follow-metalink=true|false Set to false to prevent aria2 from\n"
  301. " entering Metalink mode even if the filename of\n"
  302. " the downloaded file ends with .metalink.\n"
  303. " Default: true") << endl;
  304. #endif // ENABLE_METALINK
  305. cout << _(" -v, --version Print the version number and exit.") << endl;
  306. cout << _(" -h, --help Print this message and exit.") << endl;
  307. cout << endl;
  308. cout << "URL:" << endl;
  309. cout << _(" You can specify multiple URLs. All URLs must point to the same file\n"
  310. " or downloading will fail.") << endl;
  311. cout << endl;
  312. #ifdef ENABLE_BITTORRENT
  313. cout << "FILE:" << endl;
  314. cout << _(" Specify files in multi-file torrent to download. Use in conjunction with the\n"
  315. " -T option. This argument is ignored if you specify the --select-file option.") << endl;
  316. cout << endl;
  317. #endif // ENABLE_BITTORRENT
  318. cout << _("Examples:") << endl;
  319. cout << _(" Download a file using 1 connection:") << endl;
  320. cout << " aria2c http://AAA.BBB.CCC/file.zip" << endl;
  321. cout << _(" Download a file using 2 connections:") << endl;
  322. cout << " aria2c -s 2 http://AAA.BBB.CCC/file.zip" << endl;
  323. cout << _(" Download a file using 2 connections, each connects to a different server:") << endl;
  324. cout << " aria2c http://AAA.BBB.CCC/file.zip http://DDD.EEE.FFF/GGG/file.zip" << endl;
  325. cout << _(" You can mix up different protocols:") << endl;
  326. cout << " aria2c http://AAA.BBB.CCC/file.zip ftp://DDD.EEE.FFF/GGG/file.zip" << endl;
  327. cout << _(" Parameterized URI:") << endl;
  328. cout << " aria2c -P http://{server1,server2,server3}/file.iso" << endl;
  329. cout << _(" Parameterized URI. -Z option is required in this case:") << endl;
  330. cout << " aria2c -P -Z http://host/file[001-100:2].img" << endl;
  331. #ifdef ENABLE_BITTORRENT
  332. cout << endl;
  333. cout << _(" Download a torrent:") << endl;
  334. cout << " aria2c -o test.torrent http://AAA.BBB.CCC/file.torrent" << endl;
  335. cout << _(" Download a torrent using a local .torrent file:") << endl;
  336. cout << " aria2c -T test.torrent" << endl;
  337. cout << _(" Download only selected files:") << endl;
  338. cout << " aria2c -T test.torrent dir/file1.zip dir/file2.zip" << endl;
  339. cout << _(" Print file listing of .torrent file:") << endl;
  340. cout << " aria2c -T test.torrent -S" << endl;
  341. #endif // ENABLE_BITTORRENT
  342. #ifdef ENABLE_METALINK
  343. cout << endl;
  344. cout << _(" Metalink downloading:") << endl;
  345. cout << " aria2c http://AAA.BBB.CCC/file.metalink" << endl;
  346. cout << _(" Download a file using local .metalink file:") << endl;
  347. cout << " aria2c -M test.metalink" << endl;
  348. cout << _(" Metalink downloading with preferences:") << endl;
  349. cout << " aria2c -M test.metalink --metalink-version=1.1.1 --metalink-language=en-US" << endl;
  350. cout << _(" Download only selected files:") << endl;
  351. cout << " aria2c -M test.metalink --metalink-language=en-US dir/file1.zip dir/file2.zip" << endl;
  352. cout << _(" Download only selected files using index:") << endl;
  353. cout << " aria2c -M test.metalink --metalink-language=en-US --select-file 1,3-5" << endl;
  354. cout << _(" Print file listing of .metalink file:") << endl;
  355. cout << " aria2c -M test.metalink -S --metalink-language=en-US" << endl;
  356. #endif // ENABLE_METALINK
  357. cout << endl;
  358. printf(_("Report bugs to %s"), "<tujikawa at users dot sourceforge dot net>");
  359. cout << endl;
  360. }
  361. Strings unfoldURI(const Strings& args)
  362. {
  363. Strings nargs;
  364. ParameterizedStringParser p;
  365. PStringBuildVisitorHandle v = new PStringBuildVisitor();
  366. for(Strings::const_iterator itr = args.begin(); itr != args.end();
  367. ++itr) {
  368. v->reset();
  369. p.parse(*itr)->accept(v);
  370. nargs.insert(nargs.end(), v->getURIs().begin(), v->getURIs().end());
  371. }
  372. return nargs;
  373. }
  374. string toBoolArg(const char* optarg)
  375. {
  376. string arg;
  377. if(!optarg || string(optarg) == "") {
  378. arg = V_TRUE;
  379. } else {
  380. arg = optarg;
  381. }
  382. return arg;
  383. }
  384. int main(int argc, char* argv[]) {
  385. #ifdef HAVE_WINSOCK2_H
  386. Platform platform;
  387. #endif // HAVE_WINSOCK2_H
  388. #ifdef ENABLE_NLS
  389. setlocale (LC_CTYPE, "");
  390. setlocale (LC_MESSAGES, "");
  391. bindtextdomain (PACKAGE, LOCALEDIR);
  392. textdomain (PACKAGE);
  393. #endif // ENABLE_NLS
  394. stringstream cmdstream;
  395. int32_t c;
  396. Option* op = new Option();
  397. op->put(PREF_STDOUT_LOG, V_FALSE);
  398. op->put(PREF_DIR, ".");
  399. op->put(PREF_SPLIT, "1");
  400. op->put(PREF_DAEMON, V_FALSE);
  401. op->put(PREF_SEGMENT_SIZE, Util::itos((int32_t)(1024*1024)));
  402. op->put(PREF_HTTP_KEEP_ALIVE, V_FALSE);
  403. op->put(PREF_LISTEN_PORT, "-1");
  404. op->put(PREF_METALINK_SERVERS, "5");
  405. op->put(PREF_FOLLOW_TORRENT,
  406. #ifdef ENABLE_BITTORRENT
  407. V_TRUE
  408. #else
  409. V_FALSE
  410. #endif // ENABLE_BITTORRENT
  411. );
  412. op->put(PREF_FOLLOW_METALINK,
  413. #ifdef ENABLE_METALINK
  414. V_TRUE
  415. #else
  416. V_FALSE
  417. #endif // ENABLE_METALINK
  418. );
  419. op->put(PREF_RETRY_WAIT, "5");
  420. op->put(PREF_TIMEOUT, "60");
  421. op->put(PREF_DNS_TIMEOUT, "10");
  422. op->put(PREF_PEER_CONNECTION_TIMEOUT, "60");
  423. op->put(PREF_BT_TIMEOUT, "180");
  424. op->put(PREF_BT_REQUEST_TIMEOUT, "60");
  425. op->put(PREF_BT_KEEP_ALIVE_INTERVAL, "120");
  426. op->put(PREF_MIN_SEGMENT_SIZE, "1048576");// 1M
  427. op->put(PREF_MAX_TRIES, "5");
  428. op->put(PREF_HTTP_AUTH_SCHEME, V_BASIC);
  429. op->put(PREF_HTTP_PROXY_METHOD, V_TUNNEL);
  430. op->put(PREF_FTP_TYPE, V_BINARY);
  431. op->put(PREF_FTP_VIA_HTTP_PROXY, V_TUNNEL);
  432. op->put(PREF_AUTO_SAVE_INTERVAL, "60");
  433. op->put(PREF_DIRECT_FILE_MAPPING, V_TRUE);
  434. op->put(PREF_LOWEST_SPEED_LIMIT, "0");
  435. op->put(PREF_MAX_DOWNLOAD_LIMIT, "0");
  436. op->put(PREF_MAX_UPLOAD_LIMIT, "0");
  437. op->put(PREF_STARTUP_IDLE_TIME, "10");
  438. op->put(PREF_TRACKER_MAX_TRIES, "10");
  439. op->put(PREF_FILE_ALLOCATION, V_PREALLOC);
  440. op->put(PREF_NO_FILE_ALLOCATION_LIMIT, "5242880"); // 5MiB
  441. op->put(PREF_ALLOW_OVERWRITE, V_FALSE);
  442. op->put(PREF_REALTIME_CHUNK_CHECKSUM, V_TRUE);
  443. op->put(PREF_CHECK_INTEGRITY, V_FALSE);
  444. op->put(PREF_NETRC_PATH, Util::getHomeDir()+"/.netrc");
  445. op->put(PREF_CONTINUE, V_FALSE);
  446. op->put(PREF_USER_AGENT, "aria2");
  447. op->put(PREF_NO_NETRC, V_FALSE);
  448. op->put(PREF_MAX_CONCURRENT_DOWNLOADS, "5");
  449. op->put(PREF_DIRECT_DOWNLOAD_TIMEOUT, "15");
  450. op->put(PREF_FORCE_SEQUENTIAL, V_FALSE);
  451. op->put(PREF_AUTO_FILE_RENAMING, V_TRUE);
  452. op->put(PREF_PARAMETERIZED_URI, V_FALSE);
  453. while(1) {
  454. int optIndex = 0;
  455. int lopt;
  456. static struct option longOpts[] = {
  457. #ifdef HAVE_DAEMON
  458. { "daemon", no_argument, NULL, 'D' },
  459. #endif // HAVE_DAEMON
  460. { "dir", required_argument, NULL, 'd' },
  461. { "out", required_argument, NULL, 'o' },
  462. { "log", required_argument, NULL, 'l' },
  463. { "split", required_argument, NULL, 's' },
  464. { "timeout", required_argument, NULL, 't' },
  465. { "max-tries", required_argument, NULL, 'm' },
  466. { "http-proxy", required_argument, &lopt, 1 },
  467. { "http-user", required_argument, &lopt, 2 },
  468. { "http-passwd", required_argument, &lopt, 3 },
  469. { "http-proxy-user", required_argument, &lopt, 4 },
  470. { "http-proxy-passwd", required_argument, &lopt, 5 },
  471. { "http-auth-scheme", required_argument, &lopt, 6 },
  472. { "referer", required_argument, &lopt, 7 },
  473. { "retry-wait", required_argument, &lopt, 8 },
  474. { "ftp-user", required_argument, &lopt, 9 },
  475. { "ftp-passwd", required_argument, &lopt, 10 },
  476. { "ftp-type", required_argument, &lopt, 11 },
  477. { "ftp-pasv", no_argument, NULL, 'p' },
  478. { "ftp-via-http-proxy", required_argument, &lopt, 12 },
  479. //{ "min-segment-size", required_argument, &lopt, 13 },
  480. { "http-proxy-method", required_argument, &lopt, 14 },
  481. { "lowest-speed-limit", required_argument, &lopt, 200 },
  482. { "max-download-limit", required_argument, &lopt, 201 },
  483. { "file-allocation", required_argument, 0, 'a' },
  484. { "allow-overwrite", required_argument, &lopt, 202 },
  485. #ifdef ENABLE_MESSAGE_DIGEST
  486. { "check-integrity", required_argument, &lopt, 203 },
  487. { "realtime-chunk-checksum", required_argument, &lopt, 204 },
  488. #endif // ENABLE_MESSAGE_DIGEST
  489. { "continue", no_argument, 0, 'c' },
  490. { "user-agent", required_argument, 0, 'U' },
  491. { "no-netrc", no_argument, 0, 'n' },
  492. { "input-file", required_argument, 0, 'i' },
  493. { "max-concurrent-downloads", required_argument, 0, 'j' },
  494. { "load-cookies", required_argument, &lopt, 205 },
  495. { "force-sequential", optional_argument, 0, 'Z' },
  496. { "auto-file-renaming", optional_argument, &lopt, 206 },
  497. { "parameterized-uri", optional_argument, 0, 'P' },
  498. { "no-file-allocation-limit", required_argument, &lopt, 207 },
  499. #if defined ENABLE_BITTORRENT || ENABLE_METALINK
  500. { "show-files", no_argument, NULL, 'S' },
  501. { "select-file", required_argument, &lopt, 21 },
  502. #endif // ENABLE_BITTORRENT || ENABLE_METALINK
  503. #ifdef ENABLE_BITTORRENT
  504. { "torrent-file", required_argument, NULL, 'T' },
  505. { "listen-port", required_argument, &lopt, 15 },
  506. { "follow-torrent", required_argument, &lopt, 16 },
  507. { "no-preallocation", no_argument, &lopt, 18 },
  508. { "direct-file-mapping", required_argument, &lopt, 19 },
  509. // TODO remove upload-limit.
  510. //{ "upload-limit", required_argument, &lopt, 20 },
  511. { "seed-time", required_argument, &lopt, 22 },
  512. { "seed-ratio", required_argument, &lopt, 23 },
  513. { "max-upload-limit", required_argument, &lopt, 24 },
  514. { "peer-id-prefix", required_argument, &lopt, 25 },
  515. #endif // ENABLE_BITTORRENT
  516. #ifdef ENABLE_METALINK
  517. { "metalink-file", required_argument, NULL, 'M' },
  518. { "metalink-servers", required_argument, NULL, 'C' },
  519. { "metalink-version", required_argument, &lopt, 100 },
  520. { "metalink-language", required_argument, &lopt, 101 },
  521. { "metalink-os", required_argument, &lopt, 102 },
  522. { "follow-metalink", required_argument, &lopt, 103 },
  523. { "metalink-location", required_argument, &lopt, 104 },
  524. #endif // ENABLE_METALINK
  525. { "version", no_argument, NULL, 'v' },
  526. { "help", no_argument, NULL, 'h' },
  527. { 0, 0, 0, 0 }
  528. };
  529. c = getopt_long(argc, argv, "Dd:o:l:s:pt:m:vhST:M:C:a:cU:ni:j:Z::P::", longOpts, &optIndex);
  530. if(c == -1) {
  531. break;
  532. }
  533. switch(c) {
  534. case 0:{
  535. switch(lopt) {
  536. case 1:
  537. cmdstream << PREF_HTTP_PROXY << "=" << optarg << "\n";
  538. break;
  539. case 2:
  540. cmdstream << PREF_HTTP_USER << "=" << optarg << "\n";
  541. break;
  542. case 3:
  543. cmdstream << PREF_HTTP_PASSWD << "=" << optarg << "\n";
  544. break;
  545. case 4:
  546. cmdstream << PREF_HTTP_PROXY_USER << "=" << optarg << "\n";
  547. break;
  548. case 5:
  549. cmdstream << PREF_HTTP_PROXY_PASSWD << "=" << optarg << "\n";
  550. break;
  551. case 6:
  552. cmdstream << PREF_HTTP_AUTH_SCHEME << "=" << optarg << "\n";
  553. break;
  554. case 7:
  555. cmdstream << PREF_REFERER << "=" << optarg << "\n";
  556. break;
  557. case 8:
  558. cmdstream << PREF_RETRY_WAIT << "=" << optarg << "\n";
  559. break;
  560. case 9:
  561. cmdstream << PREF_FTP_USER << "=" << optarg << "\n";
  562. break;
  563. case 10:
  564. cmdstream << PREF_FTP_PASSWD << "=" << optarg << "\n";
  565. break;
  566. case 11:
  567. cmdstream << PREF_FTP_TYPE << "=" << optarg << "\n";
  568. break;
  569. case 12:
  570. cmdstream << PREF_FTP_VIA_HTTP_PROXY << "=" << optarg << "\n";
  571. break;
  572. case 13:
  573. cmdstream << PREF_MIN_SEGMENT_SIZE << "=" << optarg << "\n";
  574. break;
  575. case 14:
  576. cmdstream << PREF_HTTP_PROXY_METHOD << "=" << optarg << "\n";
  577. break;
  578. case 15:
  579. cmdstream << PREF_LISTEN_PORT << "=" << optarg << "\n";
  580. break;
  581. case 16:
  582. cmdstream << PREF_FOLLOW_TORRENT << "=" << optarg << "\n";
  583. break;
  584. case 18:
  585. cmdstream << PREF_NO_PREALLOCATION << "=" << V_TRUE << "\n";
  586. break;
  587. case 19:
  588. cmdstream << PREF_DIRECT_FILE_MAPPING << "=" << optarg << "\n";
  589. break;
  590. case 21:
  591. cmdstream << PREF_SELECT_FILE << "=" << optarg << "\n";
  592. break;
  593. case 22:
  594. cmdstream << PREF_SEED_TIME << "=" << optarg << "\n";
  595. break;
  596. case 23:
  597. cmdstream << PREF_SEED_RATIO << "=" << optarg << "\n";
  598. break;
  599. case 24:
  600. cmdstream << PREF_MAX_UPLOAD_LIMIT << "=" << optarg << "\n";
  601. break;
  602. case 25:
  603. cmdstream << PREF_PEER_ID_PREFIX << "=" << optarg << "\n";
  604. case 100:
  605. cmdstream << PREF_METALINK_VERSION << "=" << optarg << "\n";
  606. break;
  607. case 101:
  608. cmdstream << PREF_METALINK_LANGUAGE << "=" << optarg << "\n";
  609. break;
  610. case 102:
  611. cmdstream << PREF_METALINK_OS << "=" << optarg << "\n";
  612. break;
  613. case 103:
  614. cmdstream << PREF_FOLLOW_METALINK << "=" << optarg << "\n";
  615. break;
  616. case 104:
  617. cmdstream << PREF_METALINK_LOCATION << "=" << optarg << "\n";
  618. break;
  619. case 200:
  620. cmdstream << PREF_LOWEST_SPEED_LIMIT << "=" << optarg << "\n";
  621. break;
  622. case 201:
  623. cmdstream << PREF_MAX_DOWNLOAD_LIMIT << "=" << optarg << "\n";
  624. break;
  625. case 202:
  626. cmdstream << PREF_ALLOW_OVERWRITE << "=" << optarg << "\n";
  627. break;
  628. case 203:
  629. cmdstream << PREF_CHECK_INTEGRITY << "=" << optarg << "\n";
  630. break;
  631. case 204:
  632. cmdstream << PREF_REALTIME_CHUNK_CHECKSUM << "=" << optarg << "\n";
  633. break;
  634. case 205:
  635. cmdstream << PREF_LOAD_COOKIES << "=" << optarg << "\n";
  636. break;
  637. case 206:
  638. cmdstream << PREF_AUTO_FILE_RENAMING << "=" << toBoolArg(optarg) << "\n";
  639. break;
  640. case 207:
  641. cmdstream << PREF_NO_FILE_ALLOCATION_LIMIT << "=" << optarg << "\n";
  642. break;
  643. }
  644. break;
  645. }
  646. #ifdef HAVE_DAEMON
  647. case 'D':
  648. cmdstream << PREF_DAEMON << "=" << V_TRUE << "\n";
  649. break;
  650. #endif // HAVE_DAEMON
  651. case 'd':
  652. cmdstream << PREF_DIR << "=" << optarg << "\n";
  653. break;
  654. case 'o':
  655. cmdstream << PREF_OUT << "=" << optarg << "\n";
  656. break;
  657. case 'l':
  658. cmdstream << PREF_LOG << "=" << optarg << "\n";
  659. break;
  660. case 's':
  661. cmdstream << PREF_SPLIT << "=" << optarg << "\n";
  662. break;
  663. case 't':
  664. cmdstream << PREF_TIMEOUT << "=" << optarg << "\n";
  665. break;
  666. case 'm':
  667. cmdstream << PREF_MAX_TRIES << "=" << optarg << "\n";
  668. break;
  669. case 'p':
  670. cmdstream << PREF_FTP_PASV << "=" << V_TRUE << "\n";
  671. break;
  672. case 'S':
  673. cmdstream << PREF_SHOW_FILES << "=" << V_TRUE << "\n";
  674. break;
  675. case 'T':
  676. cmdstream << PREF_TORRENT_FILE << "=" << optarg << "\n";
  677. break;
  678. case 'M':
  679. cmdstream << PREF_METALINK_FILE << "=" << optarg << "\n";
  680. break;
  681. case 'C':
  682. cmdstream << PREF_METALINK_SERVERS << "=" << optarg << "\n";
  683. break;
  684. case 'a':
  685. cmdstream << PREF_FILE_ALLOCATION << "=" << optarg << "\n";
  686. break;
  687. case 'c':
  688. cmdstream << PREF_CONTINUE << "=" << V_TRUE << "\n";
  689. break;
  690. case 'U':
  691. cmdstream << PREF_USER_AGENT << "=" << optarg << "\n";
  692. break;
  693. case 'n':
  694. cmdstream << PREF_NO_NETRC << "=" << V_TRUE << "\n";
  695. break;
  696. case 'i':
  697. cmdstream << PREF_INPUT_FILE << "=" << optarg << "\n";
  698. break;
  699. case 'j':
  700. cmdstream << PREF_MAX_CONCURRENT_DOWNLOADS << "=" << optarg << "\n";
  701. break;
  702. case 'Z':
  703. cmdstream << PREF_FORCE_SEQUENTIAL << "=" << toBoolArg(optarg) << "\n";
  704. break;
  705. case 'P':
  706. cmdstream << PREF_PARAMETERIZED_URI << "=" << toBoolArg(optarg) << "\n";
  707. break;
  708. case 'v':
  709. showVersion();
  710. exit(EXIT_SUCCESS);
  711. case 'h':
  712. showUsage();
  713. exit(EXIT_SUCCESS);
  714. default:
  715. exit(EXIT_FAILURE);
  716. }
  717. }
  718. {
  719. OptionParser oparser;
  720. oparser.setOptionHandlers(OptionHandlerFactory::createOptionHandlers());
  721. string cfname = Util::getHomeDir()+"/.aria2/aria2.conf";
  722. ifstream cfstream(cfname.c_str());
  723. try {
  724. oparser.parse(op, cfstream);
  725. } catch(Exception* e) {
  726. cerr << "Parse error in " << cfname << endl;
  727. cerr << e->getMsg() << endl;
  728. delete e;
  729. exit(EXIT_FAILURE);
  730. }
  731. try {
  732. oparser.parse(op, cmdstream);
  733. } catch(Exception* e) {
  734. cerr << e->getMsg() << endl;
  735. delete e;
  736. exit(EXIT_FAILURE);
  737. }
  738. }
  739. if(op->defined(PREF_HTTP_USER)) {
  740. op->put(PREF_HTTP_AUTH_ENABLED, V_TRUE);
  741. }
  742. if(op->defined(PREF_HTTP_PROXY_USER)) {
  743. op->put(PREF_HTTP_PROXY_AUTH_ENABLED, V_TRUE);
  744. }
  745. if(
  746. #ifdef ENABLE_BITTORRENT
  747. !op->defined(PREF_TORRENT_FILE) &&
  748. #endif // ENABLE_BITTORRENT
  749. #ifdef ENABLE_METALINK
  750. !op->defined(PREF_METALINK_FILE) &&
  751. #endif // ENABLE_METALINK
  752. !op->defined(PREF_INPUT_FILE)) {
  753. if(optind == argc) {
  754. cerr << MSG_URI_REQUIRED << endl;
  755. exit(EXIT_FAILURE);
  756. }
  757. }
  758. #ifdef HAVE_DAEMON
  759. if(op->getAsBool(PREF_DAEMON)) {
  760. if(daemon(1, 1) < 0) {
  761. perror(MSG_DAEMON_FAILED);
  762. exit(EXIT_FAILURE);
  763. }
  764. }
  765. #endif // HAVE_DAEMON
  766. Strings args(argv+optind, argv+argc);
  767. #ifdef HAVE_LIBSSL
  768. // for SSL initialization
  769. SSL_load_error_strings();
  770. SSL_library_init();
  771. #endif // HAVE_LIBSSL
  772. #ifdef HAVE_LIBGNUTLS
  773. gnutls_global_init();
  774. #endif // HAVE_LIBGNUTLS
  775. #ifdef ENABLE_METALINK
  776. xmlInitParser();
  777. #endif // ENABLE_METALINK
  778. SimpleRandomizer::init();
  779. BitfieldManFactory::setDefaultRandomizer(SimpleRandomizer::getInstance());
  780. FileAllocationMonitorFactory::setFactory(new ConsoleFileAllocationMonitorFactory());
  781. if(op->getAsBool(PREF_STDOUT_LOG)) {
  782. LogFactory::setLogFile(DEV_STDOUT);
  783. } else if(op->get(PREF_LOG).size()) {
  784. LogFactory::setLogFile(op->get(PREF_LOG));
  785. } else {
  786. LogFactory::setLogFile(DEV_NULL);
  787. }
  788. int32_t exitStatus = EXIT_SUCCESS;
  789. try {
  790. Logger* logger = LogFactory::getInstance();
  791. logger->info("%s %s", PACKAGE, PACKAGE_VERSION);
  792. logger->info(MSG_LOGGING_STARTED);
  793. RequestFactoryHandle requestFactory = new RequestFactory();
  794. requestFactory->setOption(op);
  795. File netrccf(op->get(PREF_NETRC_PATH));
  796. if(!op->getAsBool(PREF_NO_NETRC) && netrccf.isFile()) {
  797. mode_t mode = netrccf.mode();
  798. if(mode&(S_IRWXG|S_IRWXO)) {
  799. logger->notice(MSG_INCORRECT_NETRC_PERMISSION,
  800. op->get(PREF_NETRC_PATH).c_str());
  801. } else {
  802. NetrcHandle netrc = new Netrc();
  803. netrc->parse(op->get(PREF_NETRC_PATH));
  804. requestFactory->setNetrc(netrc);
  805. }
  806. }
  807. CookieBoxFactoryHandle cookieBoxFactory = new CookieBoxFactory();
  808. CookieBoxFactorySingletonHolder::instance(cookieBoxFactory);
  809. if(op->defined(PREF_LOAD_COOKIES)) {
  810. File cookieFile(op->get(PREF_LOAD_COOKIES));
  811. if(cookieFile.isFile()) {
  812. ifstream in(op->get(PREF_LOAD_COOKIES).c_str());
  813. CookieBoxFactorySingletonHolder::instance()->loadDefaultCookie(in);
  814. } else {
  815. logger->error(MSG_LOADING_COOKIE_FAILED, op->get(PREF_LOAD_COOKIES).c_str());
  816. exit(EXIT_FAILURE);
  817. }
  818. }
  819. RequestFactorySingletonHolder::instance(requestFactory);
  820. CUIDCounterHandle cuidCounter = new CUIDCounter();
  821. CUIDCounterSingletonHolder::instance(cuidCounter);
  822. #ifdef SIGPIPE
  823. Util::setGlobalSignalHandler(SIGPIPE, SIG_IGN, 0);
  824. #endif
  825. RequestInfo* firstReqInfo;
  826. #ifdef ENABLE_BITTORRENT
  827. if(op->defined(PREF_TORRENT_FILE)) {
  828. firstReqInfo = new TorrentRequestInfo(op->get(PREF_TORRENT_FILE),
  829. op);
  830. Strings targetFiles;
  831. if(op->defined(PREF_TORRENT_FILE) && !args.empty()) {
  832. targetFiles = args;
  833. }
  834. ((TorrentRequestInfo*)firstReqInfo)->setTargetFiles(targetFiles);
  835. }
  836. else
  837. #endif // ENABLE_BITTORRENT
  838. #ifdef ENABLE_METALINK
  839. if(op->defined(PREF_METALINK_FILE)) {
  840. firstReqInfo = new MetalinkRequestInfo(op->get(PREF_METALINK_FILE),
  841. op);
  842. Strings targetFiles;
  843. if(op->defined(PREF_METALINK_FILE) && !args.empty()) {
  844. targetFiles = args;
  845. }
  846. ((MetalinkRequestInfo*)firstReqInfo)->setTargetFiles(targetFiles);
  847. }
  848. else
  849. #endif // ENABLE_METALINK
  850. if(op->defined(PREF_INPUT_FILE)) {
  851. SharedHandle<UriListParser> flparser(0);
  852. if(op->get(PREF_INPUT_FILE) == "-") {
  853. flparser = new StreamUriListParser(cin);
  854. } else {
  855. if(!File(op->get(PREF_INPUT_FILE)).isFile()) {
  856. throw new FatalException(EX_FILE_OPEN, op->get(PREF_INPUT_FILE).c_str(), "No such file");
  857. }
  858. flparser = new FileUriListParser(op->get(PREF_INPUT_FILE));
  859. }
  860. RequestGroups groups;
  861. while(flparser->hasNext()) {
  862. Strings uris = flparser->next();
  863. if(uris.size() == 1 && op->get(PREF_PARAMETERIZED_URI) == V_TRUE) {
  864. Strings unfoldedURIs = unfoldURI(uris);
  865. for(Strings::const_iterator itr = unfoldedURIs.begin();
  866. itr != unfoldedURIs.end(); ++itr) {
  867. Strings xuris;
  868. ncopy(itr, itr+1, op->getAsInt(PREF_SPLIT),
  869. back_inserter(xuris));
  870. RequestGroupHandle rg = new RequestGroup(xuris, op);
  871. groups.push_back(rg);
  872. }
  873. } else if(uris.size() > 0) {
  874. Strings xuris;
  875. ncopy(uris.begin(), uris.end(), op->getAsInt(PREF_SPLIT),
  876. back_inserter(xuris));
  877. RequestGroupHandle rg = new RequestGroup(xuris, op);
  878. groups.push_back(rg);
  879. }
  880. }
  881. firstReqInfo = new MultiUrlRequestInfo(groups, op);
  882. }
  883. else
  884. {
  885. Strings nargs;
  886. if(op->get(PREF_PARAMETERIZED_URI) == V_TRUE) {
  887. nargs = unfoldURI(args);
  888. } else {
  889. nargs = args;
  890. }
  891. if(op->get(PREF_FORCE_SEQUENTIAL) == V_TRUE) {
  892. RequestGroups groups;
  893. for(Strings::const_iterator itr = nargs.begin();
  894. itr != nargs.end(); ++itr) {
  895. Strings xuris;
  896. ncopy(itr, itr+1, op->getAsInt(PREF_SPLIT),
  897. back_inserter(xuris));
  898. RequestGroupHandle rg = new RequestGroup(xuris, op);
  899. groups.push_back(rg);
  900. }
  901. firstReqInfo = new MultiUrlRequestInfo(groups, op);
  902. } else {
  903. Strings xargs;
  904. ncopy(nargs.begin(), nargs.end(), op->getAsInt(PREF_SPLIT),
  905. back_inserter(xargs));
  906. firstReqInfo = new MultiUrlRequestInfo(xargs, op);
  907. }
  908. }
  909. RequestInfos reqInfos;
  910. if(firstReqInfo) {
  911. reqInfos.push_front(firstReqInfo);
  912. }
  913. while(reqInfos.size()) {
  914. RequestInfoHandle reqInfo = reqInfos.front();
  915. reqInfos.pop_front();
  916. RequestInfos nextReqInfos = reqInfo->execute();
  917. copy(nextReqInfos.begin(), nextReqInfos.end(), front_inserter(reqInfos));
  918. /*
  919. if(reqInfo->isFail()) {
  920. exitStatus = EXIT_FAILURE;
  921. } else if(reqInfo->getFileInfo().checkReady()) {
  922. cout << _("Now verifying checksum.\n"
  923. "This may take some time depending on your PC environment"
  924. " and the size of file.") << endl;
  925. if(reqInfo->getFileInfo().check()) {
  926. cout << _("checksum OK.") << endl;
  927. } else {
  928. // TODO
  929. cout << _("checksum ERROR.") << endl;
  930. exitStatus = EXIT_FAILURE;
  931. }
  932. }
  933. */
  934. }
  935. } catch(Exception* ex) {
  936. cerr << EX_EXCEPTION_CAUGHT << "\n" << ex->getMsg() << endl;
  937. delete ex;
  938. exit(EXIT_FAILURE);
  939. }
  940. delete op;
  941. LogFactory::release();
  942. #ifdef HAVE_LIBGNUTLS
  943. gnutls_global_deinit();
  944. #endif // HAVE_LIBGNUTLS
  945. #ifdef ENABLE_METALINK
  946. xmlCleanupParser();
  947. #endif // ENABLE_METALINK
  948. FeatureConfig::release();
  949. return exitStatus;
  950. }