summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2007-06-10 07:55:43 +0000
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2007-06-10 07:55:43 +0000
commitd5bb035642ed1402eea53ecc5a4a1fd4d104c08f (patch)
treeaac92bd775fe648d7ae9597cabcc7eeb2ee1a1ed /src
parentaa7cbf60ba1a76877366c977b24fdaf6657a883a (diff)
2007-06-10 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
* src/AbstractCommand.cc (execute): Changed log level of MSG_RESTARTING_DOWNLOAD and MSG_MAX_TRY from error to info. Added MSG_DOWNLOAD_ABORTED after MSG_MAX_TRY. * src/message.h (MSG_TORRENT_DOWNLOAD_ABORTED): New definition. (MSG_DOWNLOAD_ABORTED): Added %s. (MSG_RESTARTING_DOWNLOAD): Added %s. (MSG_DOWNLOAD_ALREADY_COMPLETED): Updated. * src/PeerAbstractCommand.cc (execute): MSG_DOWNLOAD_ABORTED -> MSG_TORRENT_DOWNLOAD_ABORTED * src/Request.h (cookieBox): Made ShardHandle. * src/RequestGroup.h, src/RequestGroup.cc (createNextCommandWithAdj): New function. * src/FileAllocationCommand.cc (executeInternal): Use createNextCommandWithAdj(). * src/CheckIntegrityCommand.cc (executeInternal): Use createNextCommandWithAdj(). Added --load-cookies command-option. * src/OptionHandlerFactory.cc (createOptionHandlers): Added PREF_LOAD_COOKIES. * src/CookieBox.h, src/CookieBox.cc: Rwritten using CookieParser. Now aria2 can handle cookie's expiration date. * src/Cookie.h (expires): Changed its type to time_t. * src/main.cc: Added --load-cookies command-line option. * src/prefs.h (PREF_LOAD_COOKIES): New definition. * src/Util.h, src/Util.cc (httpGMT): New function. * src/Request.cc (Request): Initialize cookieBox using CookieBoxFactory. * src/CookieBoxFactory.h, src/CookieBoxFactory.cc: New class. * src/CookieParser.h, src/CookieParser.cc: New class. * src/main.cc: Chagned the default value of --metalink-servers to 5. * src/HttpResponseCommand.cc (handleOtherEncoding): Call RequestGroup::shouldCancelDownloadForSafety
Diffstat (limited to 'src')
-rw-r--r--src/AbstractCommand.cc12
-rw-r--r--src/CheckIntegrityCommand.cc2
-rw-r--r--src/Cookie.cc48
-rw-r--r--src/Cookie.h98
-rw-r--r--src/CookieBox.cc41
-rw-r--r--src/CookieBox.h35
-rw-r--r--src/CookieBoxFactory.cc77
-rw-r--r--src/CookieBoxFactory.h66
-rw-r--r--src/CookieParser.cc85
-rw-r--r--src/CookieParser.h57
-rw-r--r--src/FileAllocationCommand.cc2
-rw-r--r--src/HttpRequest.cc1
-rw-r--r--src/HttpResponse.cc4
-rw-r--r--src/HttpResponseCommand.cc5
-rw-r--r--src/Makefile.am5
-rw-r--r--src/Makefile.in26
-rw-r--r--src/OptionHandlerFactory.cc1
-rw-r--r--src/PeerAbstractCommand.cc2
-rw-r--r--src/Request.cc11
-rw-r--r--src/Request.h2
-rw-r--r--src/RequestGroup.cc8
-rw-r--r--src/RequestGroup.h2
-rw-r--r--src/Util.cc9
-rw-r--r--src/Util.h2
-rw-r--r--src/main.cc28
-rw-r--r--src/message.h7
-rw-r--r--src/prefs.h2
27 files changed, 533 insertions, 105 deletions
diff --git a/src/AbstractCommand.cc b/src/AbstractCommand.cc
index 250cc230..ef03bc31 100644
--- a/src/AbstractCommand.cc
+++ b/src/AbstractCommand.cc
@@ -106,14 +106,14 @@ bool AbstractCommand::execute() {
return false;
}
} catch(FatalException* err) {
- logger->error(MSG_DOWNLOAD_ABORTED, err, cuid);
+ logger->error(MSG_DOWNLOAD_ABORTED, err, cuid, req->getUrl().c_str());
onAbort(err);
delete(err);
req->resetUrl();
_requestGroup->getSegmentMan()->errors++;
return true;
} catch(DlAbortEx* err) {
- logger->error(MSG_DOWNLOAD_ABORTED, err, cuid);
+ logger->error(MSG_DOWNLOAD_ABORTED, err, cuid, req->getUrl().c_str());
onAbort(err);
delete(err);
req->resetUrl();
@@ -121,20 +121,22 @@ bool AbstractCommand::execute() {
tryReserved();
return true;
} catch(DlRetryEx* err) {
- logger->error(MSG_RESTARTING_DOWNLOAD, err, cuid);
+ logger->info(MSG_RESTARTING_DOWNLOAD, err, cuid, req->getUrl().c_str());
req->addTryCount();
bool isAbort = e->option->getAsInt(PREF_MAX_TRIES) != 0 &&
req->getTryCount() >= e->option->getAsInt(PREF_MAX_TRIES);
if(isAbort) {
onAbort(err);
}
- delete(err);
if(isAbort) {
- logger->error(MSG_MAX_TRY, cuid, req->getTryCount());
+ logger->info(MSG_MAX_TRY, cuid, req->getTryCount());
+ logger->error(MSG_DOWNLOAD_ABORTED, err, cuid, req->getUrl().c_str());
+ delete(err);
_requestGroup->getSegmentMan()->errors++;
tryReserved();
return true;
} else {
+ delete(err);
return prepareForRetry(e->option->getAsInt(PREF_RETRY_WAIT));
}
}
diff --git a/src/CheckIntegrityCommand.cc b/src/CheckIntegrityCommand.cc
index 70188129..c2e225b0 100644
--- a/src/CheckIntegrityCommand.cc
+++ b/src/CheckIntegrityCommand.cc
@@ -69,7 +69,7 @@ bool CheckIntegrityCommand::executeInternal()
_entry->getNextDownloadCommand()) {
_e->commands.push_back(_entry->popNextDownloadCommand());
} else {
- Commands commands = _requestGroup->createNextCommand(_e);
+ Commands commands = _requestGroup->createNextCommandWithAdj(_e, -1);
Command* command = InitiateConnectionCommandFactory::createInitiateConnectionCommand(cuid, _entry->getCurrentRequest(), _requestGroup, _e);
commands.push_front(command);
_e->addCommand(commands);
diff --git a/src/Cookie.cc b/src/Cookie.cc
new file mode 100644
index 00000000..0e86f41a
--- /dev/null
+++ b/src/Cookie.cc
@@ -0,0 +1,48 @@
+/* <!-- copyright */
+/*
+ * aria2 - The high speed download utility
+ *
+ * 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., 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.
+ */
+/* copyright --> */
+#include "Cookie.h"
+#include "Util.h"
+
+bool Cookie::match(const string& host, const string& dir, time_t date, bool secure) const
+{
+ if((secure || !this->secure && !secure) &&
+ Util::endsWith(host, this->domain) &&
+ Util::startsWith(dir, this->path) &&
+ (this->onetime || date < this->expires)) {
+ return true;
+ } else {
+ return false;
+ }
+}
diff --git a/src/Cookie.h b/src/Cookie.h
new file mode 100644
index 00000000..f33d048b
--- /dev/null
+++ b/src/Cookie.h
@@ -0,0 +1,98 @@
+/* <!-- copyright */
+/*
+ * aria2 - The high speed download utility
+ *
+ * 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., 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.
+ */
+/* copyright --> */
+#ifndef _D_COOKIE_H_
+#define _D_COOKIE_H_
+
+#include "common.h"
+
+class Cookie {
+public:
+ string name;
+ string value;
+ time_t expires;
+ string path;
+ string domain;
+ bool secure;
+ bool onetime; // if true, this cookie will expire when the user's session ends.
+public:
+ Cookie(const string& name,
+ const string& value,
+ time_t expires,
+ const string& path,
+ const string& domain,
+ bool secure):
+ name(name),
+ value(value),
+ expires(expires),
+ path(path),
+ domain(domain),
+ secure(secure),
+ onetime(false) {}
+
+ Cookie(const string& name,
+ const string& value,
+ const string& path,
+ const string& domain,
+ bool secure):
+ name(name),
+ value(value),
+ path(path),
+ domain(domain),
+ secure(secure),
+ onetime(true) {}
+
+ Cookie():expires(0), secure(false), onetime(true) {}
+
+ ~Cookie() {}
+ string toString() const {
+ return name+"="+value;
+ }
+ void clear() {
+ name = value = path = domain = "";
+ expires = 0;
+ secure = false;
+ }
+
+ bool good() const
+ {
+ return !name.empty();
+ }
+
+ bool match(const string& host, const string& dir, time_t date, bool secure) const;
+};
+
+typedef deque<Cookie> Cookies;
+
+#endif // _D_COOKIE_H_
diff --git a/src/CookieBox.cc b/src/CookieBox.cc
index 42010121..63a5eaec 100644
--- a/src/CookieBox.cc
+++ b/src/CookieBox.cc
@@ -34,6 +34,7 @@
/* copyright --> */
#include "CookieBox.h"
#include "Util.h"
+#include "CookieParser.h"
CookieBox::CookieBox() {}
@@ -44,46 +45,22 @@ void CookieBox::add(const Cookie& cookie) {
}
void CookieBox::add(const string& cookieStr) {
- Cookie c;
- parse(c, cookieStr);
- cookies.push_back(c);
-}
-
-void CookieBox::setField(Cookie& cookie, const string& name, const string& value) const {
- if(name.size() == string("secure").size() &&
- strcasecmp(name.c_str(), "secure") == 0) {
- cookie.secure = true;
- } else if(name.size() == string("domain").size() && strcasecmp(name.c_str(), "domain") == 0) {
- cookie.domain = value;
- } else if(name.size() == string("path").size() && strcasecmp(name.c_str(), "path") == 0) {
- cookie.path = value;
- } else if(name.size() == string("expires").size() && strcasecmp(name.c_str(), "expires") == 0) {
- cookie.expires = value;
- } else {
- cookie.name = name;
- cookie.value = value;
+ Cookie c = CookieParser().parse(cookieStr);
+ if(c.good()) {
+ cookies.push_back(c);
}
}
-void CookieBox::parse(Cookie& cookie, const string& cookieStr) const {
- cookie.clear();
- Strings terms;
- Util::slice(terms, cookieStr, ';', true);
- for(Strings::iterator itr = terms.begin(); itr != terms.end(); itr++) {
- pair<string, string> nv;
- Util::split(nv, *itr, '=');
- setField(cookie, nv.first, nv.second);
- }
+void CookieBox::add(const Cookies& cookies)
+{
+ this->cookies.insert(this->cookies.end(), cookies.begin(), cookies.end());
}
-Cookies CookieBox::criteriaFind(const string& host, const string& dir, bool secure) const {
+Cookies CookieBox::criteriaFind(const string& host, const string& dir, time_t date, bool secure) const {
Cookies result;
for(Cookies::const_iterator itr = cookies.begin(); itr != cookies.end(); itr++) {
const Cookie& c = *itr;
- if((secure || !c.secure && !secure) &&
- Util::endsWith(host, c.domain) &&
- Util::startsWith(dir, c.path)) {
- // TODO we currently ignore expire date.
+ if(c.match(host, dir, date, secure)) {
result.push_back(c);
}
}
diff --git a/src/CookieBox.h b/src/CookieBox.h
index 52ddcd31..a734508f 100644
--- a/src/CookieBox.h
+++ b/src/CookieBox.h
@@ -36,46 +36,21 @@
#define _D_COOKIE_BOX_H_
#include "common.h"
-#include <string>
-#include <deque>
-
-using namespace std;
-
-class Cookie {
-public:
- string name;
- string value;
- string expires;
- string path;
- string domain;
- bool secure;
-public:
- Cookie(const string& name, const string& value, const string& expires, const string& path, const string& domain, bool secure):name(name), value(value), expires(expires), path(path), domain(domain), secure(secure) {}
- Cookie():secure(false) {}
- ~Cookie() {}
- string toString() const {
- return name+"="+value;
- }
- void clear() {
- name = value = expires = path = domain = "";
- secure = false;
- }
-};
-
-typedef deque<Cookie> Cookies;
+#include "Cookie.h"
class CookieBox {
private:
Cookies cookies;
- void setField(Cookie& cookie, const string& name, const string& value) const;
public:
CookieBox();
~CookieBox();
void clear();
void add(const Cookie& cookie);
void add(const string& cookieStr);
- void parse(Cookie& cookie, const string& cookieStr) const;
- Cookies criteriaFind(const string& host, const string& dir, bool secure) const;
+ void add(const Cookies& cookies);
+ Cookies criteriaFind(const string& host, const string& dir, time_t date, bool secure) const;
};
+typedef SharedHandle<CookieBox> CookieBoxHandle;
+
#endif // _D_COOKIE_BOX_H_
diff --git a/src/CookieBoxFactory.cc b/src/CookieBoxFactory.cc
new file mode 100644
index 00000000..1d231510
--- /dev/null
+++ b/src/CookieBoxFactory.cc
@@ -0,0 +1,77 @@
+/* <!-- copyright */
+/*
+ * aria2 - The high speed download utility
+ *
+ * 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., 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.
+ */
+/* copyright --> */
+#include "CookieBoxFactory.h"
+#include "CookieParser.h"
+#include "Util.h"
+
+CookieBoxHandle CookieBoxFactory::createNewInstance()
+{
+ CookieBoxHandle box = new CookieBox();
+ box->add(defaultCookies);
+ return box;
+}
+
+void CookieBoxFactory::loadDefaultCookie(istream& s)
+{
+ string line;
+ while(getline(s, line)) {
+ if(Util::startsWith(line, "#")) {
+ continue;
+ }
+ Cookie c = parseNsCookie(line);
+ if(c.good()) {
+ defaultCookies.push_back(c);
+ }
+ }
+}
+
+Cookie CookieBoxFactory::parseNsCookie(const string& nsCookieStr) const
+{
+ Strings vs;
+ Util::slice(vs, nsCookieStr, '\t', true);
+ Cookie c;
+ if(vs.size() < 6 ) {
+ return c;
+ }
+ c.domain = vs[0];
+ c.path = vs[2];
+ c.secure = vs[3] == "TRUE" ? true : false;
+ c.expires = strtol(vs[4].c_str(), NULL, 10);
+ c.name = vs[5];
+ if(vs.size() >= 7) {
+ c.value = vs[6];
+ }
+ return c;
+}
diff --git a/src/CookieBoxFactory.h b/src/CookieBoxFactory.h
new file mode 100644
index 00000000..c60f83c7
--- /dev/null
+++ b/src/CookieBoxFactory.h
@@ -0,0 +1,66 @@
+/* <!-- copyright */
+/*
+ * aria2 - The high speed download utility
+ *
+ * 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., 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.
+ */
+/* copyright --> */
+#ifndef _D_COOKIE_BOX_FACTORY_H_
+#define _D_COOKIE_BOX_FACTORY_H_
+
+#include "common.h"
+#include "CookieBox.h"
+#include <istream>
+
+class CookieBoxFactory {
+private:
+ Cookies defaultCookies;
+
+public:
+ CookieBoxFactory() {}
+
+ ~CookieBoxFactory() {}
+
+ CookieBoxHandle createNewInstance();
+
+ void loadDefaultCookie(istream& s);
+
+ Cookie parseNsCookie(const string& nsCookieStr) const;
+
+ const Cookies& getDefaultCookies() const
+ {
+ return defaultCookies;
+ }
+};
+
+typedef SharedHandle<CookieBoxFactory> CookieBoxFactoryHandle;
+typedef SingletonHolder<CookieBoxFactoryHandle> CookieBoxFactorySingletonHolder;
+
+#endif // _D_COOKIE_BOX_FACTORY_H_
diff --git a/src/CookieParser.cc b/src/CookieParser.cc
new file mode 100644
index 00000000..c7702eba
--- /dev/null
+++ b/src/CookieParser.cc
@@ -0,0 +1,85 @@
+/* <!-- copyright */
+/*
+ * aria2 - The high speed download utility
+ *
+ * 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., 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.
+ */
+/* copyright --> */
+#include "CookieParser.h"
+#include "Util.h"
+
+void CookieParser::setField(Cookie& cookie, const string& name, const string& value) const
+{
+ if(name.size() == string("secure").size() &&
+ strcasecmp(name.c_str(), "secure") == 0) {
+ cookie.secure = true;
+ } else if(name.size() == string("domain").size() && strcasecmp(name.c_str(), "domain") == 0) {
+ cookie.domain = value;
+ } else if(name.size() == string("path").size() && strcasecmp(name.c_str(), "path") == 0) {
+ cookie.path = value;
+ } else if(name.size() == string("expires").size() && strcasecmp(name.c_str(), "expires") == 0) {
+ cookie.expires = Util::httpGMT(value);
+ cookie.onetime = false;
+ } else {
+ cookie.name = name;
+ cookie.value = value;
+ }
+}
+
+Cookie CookieParser::parse(const string& cookieStr) const
+{
+ Cookie cookie;
+ Strings terms;
+ Util::slice(terms, Util::trim(cookieStr), ';', true);
+ for(Strings::iterator itr = terms.begin(); itr != terms.end(); itr++) {
+ pair<string, string> nv;
+ Util::split(nv, *itr, '=');
+ setField(cookie, nv.first, nv.second);
+ }
+ return cookie;
+}
+
+
+Cookies CookieParser::parse(istream& s) const
+{
+ Cookies cookies;
+ string line;
+ while(getline(s, line)) {
+ if(Util::trim(line) == "" || Util::startsWith(line, "#")) {
+ continue;
+ }
+ Cookie cookie = parse(line);
+ if(cookie.good()) {
+ cookies.push_back(cookie);
+ }
+ }
+ return cookies;
+}
+
diff --git a/src/CookieParser.h b/src/CookieParser.h
new file mode 100644
index 00000000..8974971a
--- /dev/null
+++ b/src/CookieParser.h
@@ -0,0 +1,57 @@
+/* <!-- copyright */
+/*
+ * aria2 - The high speed download utility
+ *
+ * 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., 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.
+ */
+/* copyright --> */
+#ifndef _D_COOKIE_PARSER_H_
+#define _D_COOKIE_PARSER_H_
+
+#include "common.h"
+#include "Cookie.h"
+#include <istream>
+
+class CookieParser {
+private:
+ void setField(Cookie& cookie, const string& name, const string& value) const;
+public:
+ CookieParser() {}
+
+ ~CookieParser() {}
+
+ Cookie parse(const string& cookieStr) const;
+
+ Cookies parse(istream& s) const;
+};
+
+typedef SharedHandle<CookieParser> CookieParserHandle;
+
+#endif // _D_COOKIE_PARSER_H_
diff --git a/src/FileAllocationCommand.cc b/src/FileAllocationCommand.cc
index f593c6ef..6634165f 100644
--- a/src/FileAllocationCommand.cc
+++ b/src/FileAllocationCommand.cc
@@ -52,7 +52,7 @@ bool FileAllocationCommand::executeInternal()
_fileAllocationEntry->getNextDownloadCommand()) {
_e->commands.push_back(_fileAllocationEntry->popNextDownloadCommand());
} else {
- Commands commands = _requestGroup->createNextCommand(_e);
+ Commands commands = _requestGroup->createNextCommandWithAdj(_e, -1);
Command* command = InitiateConnectionCommandFactory::createInitiateConnectionCommand(cuid, _fileAllocationEntry->getCurrentRequest(), _requestGroup, _e);
commands.push_front(command);
diff --git a/src/HttpRequest.cc b/src/HttpRequest.cc
index c64cc35c..851ebdc5 100644
--- a/src/HttpRequest.cc
+++ b/src/HttpRequest.cc
@@ -116,6 +116,7 @@ string HttpRequest::createRequest() const
string cookiesValue;
Cookies cookies = request->cookieBox->criteriaFind(getHost(),
getDir(),
+ time(0),
getProtocol() == "https" ?
true : false);
for(Cookies::const_iterator itr = cookies.begin(); itr != cookies.end(); itr++) {
diff --git a/src/HttpResponse.cc b/src/HttpResponse.cc
index 72b28916..e11c108c 100644
--- a/src/HttpResponse.cc
+++ b/src/HttpResponse.cc
@@ -86,9 +86,7 @@ void HttpResponse::retrieveCookie()
{
Strings v = httpHeader->get("Set-Cookie");
for(Strings::const_iterator itr = v.begin(); itr != v.end(); itr++) {
- Cookie c;
- httpRequest->getRequest()->cookieBox->parse(c, *itr);
- httpRequest->getRequest()->cookieBox->add(c);
+ httpRequest->getRequest()->cookieBox->add(*itr);
}
}
diff --git a/src/HttpResponseCommand.cc b/src/HttpResponseCommand.cc
index 87abc5a9..5bdf4349 100644
--- a/src/HttpResponseCommand.cc
+++ b/src/HttpResponseCommand.cc
@@ -88,14 +88,14 @@ bool HttpResponseCommand::executeInternal()
return prepareForRetry(0);
}
if(_requestGroup->getSegmentMan()->downloadStarted) {
- // TODO validate totalsize
+ // validate totalsize
_requestGroup->validateFilename(httpResponse->determinFilename());
_requestGroup->validateTotalLength(httpResponse->getEntityLength());
e->commands.push_back(createHttpDownloadCommand(httpResponse));
return true;
} else {
- // TODO validate totalsize against hintTotalSize if it is provided.
+ // validate totalsize against hintTotalSize if it is provided.
_requestGroup->validateFilenameByHint(httpResponse->determinFilename());
_requestGroup->validateTotalLengthByHint(httpResponse->getEntityLength());
@@ -165,6 +165,7 @@ bool HttpResponseCommand::handleOtherEncoding(const HttpResponseHandle& httpResp
// disable keep-alive
req->setKeepAlive(false);
segment = _requestGroup->getSegmentMan()->getSegment(cuid);
+ _requestGroup->shouldCancelDownloadForSafety();
_requestGroup->getSegmentMan()->diskWriter->initAndOpenFile(_requestGroup->getSegmentMan()->getFilePath());
e->commands.push_back(createHttpDownloadCommand(httpResponse));
return true;
diff --git a/src/Makefile.am b/src/Makefile.am
index 3bac86d1..67c47874 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -100,7 +100,10 @@ SRCS = Socket.h\
CheckIntegrityEntry.cc CheckIntegrityEntry.h\
CheckIntegrityMan.h\
ProgressAwareEntry.h\
- RequestGroupEntry.cc RequestGroupEntry.h
+ RequestGroupEntry.cc RequestGroupEntry.h\
+ Cookie.cc Cookie.h\
+ CookieParser.cc CookieParser.h\
+ CookieBoxFactory.cc CookieBoxFactory.h
# debug_new.cpp
if ENABLE_BITTORRENT
diff --git a/src/Makefile.in b/src/Makefile.in
index a39b06db..9c7c2697 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -240,12 +240,14 @@ am__libaria2c_a_SOURCES_DIST = Socket.h SocketCore.cc SocketCore.h \
IteratableChecksumValidator.cc IteratableChecksumValidator.h \
ChecksumCommand.cc ChecksumCommand.h CheckIntegrityEntry.cc \
CheckIntegrityEntry.h CheckIntegrityMan.h ProgressAwareEntry.h \
- RequestGroupEntry.cc RequestGroupEntry.h MetaEntry.h Data.cc \
- Data.h Dictionary.cc Dictionary.h List.cc List.h \
- MetaFileUtil.cc MetaFileUtil.h MetaEntryVisitor.h \
- ShaVisitor.cc ShaVisitor.h PeerConnection.cc PeerConnection.h \
- PeerMessageUtil.cc PeerMessageUtil.h PeerAbstractCommand.cc \
- PeerAbstractCommand.h PeerInitiateConnectionCommand.cc \
+ RequestGroupEntry.cc RequestGroupEntry.h Cookie.cc Cookie.h \
+ CookieParser.cc CookieParser.h CookieBoxFactory.cc \
+ CookieBoxFactory.h MetaEntry.h Data.cc Data.h Dictionary.cc \
+ Dictionary.h List.cc List.h MetaFileUtil.cc MetaFileUtil.h \
+ MetaEntryVisitor.h ShaVisitor.cc ShaVisitor.h \
+ PeerConnection.cc PeerConnection.h PeerMessageUtil.cc \
+ PeerMessageUtil.h PeerAbstractCommand.cc PeerAbstractCommand.h \
+ PeerInitiateConnectionCommand.cc \
PeerInitiateConnectionCommand.h PeerInteractionCommand.cc \
PeerInteractionCommand.h Peer.cc Peer.h \
TorrentDownloadEngine.cc TorrentDownloadEngine.h \
@@ -425,7 +427,9 @@ am__objects_3 = SocketCore.$(OBJEXT) Command.$(OBJEXT) \
RealtimeCommand.$(OBJEXT) \
IteratableChecksumValidator.$(OBJEXT) \
ChecksumCommand.$(OBJEXT) CheckIntegrityEntry.$(OBJEXT) \
- RequestGroupEntry.$(OBJEXT) $(am__objects_1) $(am__objects_2)
+ RequestGroupEntry.$(OBJEXT) Cookie.$(OBJEXT) \
+ CookieParser.$(OBJEXT) CookieBoxFactory.$(OBJEXT) \
+ $(am__objects_1) $(am__objects_2)
am_libaria2c_a_OBJECTS = $(am__objects_3)
libaria2c_a_OBJECTS = $(am_libaria2c_a_OBJECTS)
am__installdirs = "$(DESTDIR)$(bindir)"
@@ -657,8 +661,9 @@ SRCS = Socket.h SocketCore.cc SocketCore.h Command.cc Command.h \
IteratableChecksumValidator.cc IteratableChecksumValidator.h \
ChecksumCommand.cc ChecksumCommand.h CheckIntegrityEntry.cc \
CheckIntegrityEntry.h CheckIntegrityMan.h ProgressAwareEntry.h \
- RequestGroupEntry.cc RequestGroupEntry.h $(am__append_1) \
- $(am__append_2)
+ RequestGroupEntry.cc RequestGroupEntry.h Cookie.cc Cookie.h \
+ CookieParser.cc CookieParser.h CookieBoxFactory.cc \
+ CookieBoxFactory.h $(am__append_1) $(am__append_2)
noinst_LIBRARIES = libaria2c.a
libaria2c_a_SOURCES = $(SRCS)
aria2c_LDADD = libaria2c.a @LIBINTL@ @ALLOCA@ @LIBGNUTLS_LIBS@\
@@ -786,7 +791,10 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CompactPeerListProcessor.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ConsoleDownloadEngine.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ConsoleFileAllocationMonitor.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Cookie.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CookieBox.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CookieBoxFactory.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CookieParser.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CopyDiskAdaptor.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Data.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DefaultAuthResolver.Po@am__quote@
diff --git a/src/OptionHandlerFactory.cc b/src/OptionHandlerFactory.cc
index c9d99770..e6726ae3 100644
--- a/src/OptionHandlerFactory.cc
+++ b/src/OptionHandlerFactory.cc
@@ -92,6 +92,7 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers()
handlers.push_back(new BooleanOptionHandler(PREF_NO_NETRC));
handlers.push_back(new DefaultOptionHandler(PREF_INPUT_FILE));
handlers.push_back(new NumberOptionHandler(PREF_MAX_CONCURRENT_DOWNLOADS, 1, 15));
+ handlers.push_back(new DefaultOptionHandler(PREF_LOAD_COOKIES));
return handlers;
}
diff --git a/src/PeerAbstractCommand.cc b/src/PeerAbstractCommand.cc
index 545b65d7..8acd1985 100644
--- a/src/PeerAbstractCommand.cc
+++ b/src/PeerAbstractCommand.cc
@@ -78,7 +78,7 @@ bool PeerAbstractCommand::execute() {
}
return executeInternal();
} catch(RecoverableException* err) {
- logger->debug(MSG_DOWNLOAD_ABORTED, err, cuid);
+ logger->debug(MSG_TORRENT_DOWNLOAD_ABORTED, err, cuid);
logger->debug("CUID#%d - Peer %s:%d banned.",
cuid, peer->ipaddr.c_str(), peer->port);
onAbort(err);
diff --git a/src/Request.cc b/src/Request.cc
index bfe2ab81..ffc9455e 100644
--- a/src/Request.cc
+++ b/src/Request.cc
@@ -35,6 +35,7 @@
#include "Request.h"
#include "Util.h"
#include "FeatureConfig.h"
+#include "CookieBoxFactory.h"
const string Request::METHOD_GET = "get";
@@ -43,14 +44,10 @@ const string Request::METHOD_HEAD = "head";
Request::Request():port(0), tryCount(0), keepAlive(true), method(METHOD_GET),
_httpAuthResolver(0),
_httpProxyAuthResolver(0),
- _ftpAuthResolver(0)
-{
- cookieBox = new CookieBox();
-}
+ _ftpAuthResolver(0),
+ cookieBox(CookieBoxFactorySingletonHolder::instance()->createNewInstance()) {}
-Request::~Request() {
- delete cookieBox;
-}
+Request::~Request() {}
bool Request::setUrl(const string& url) {
this->url = url;
diff --git a/src/Request.h b/src/Request.h
index 8afa1ea9..0b4f71c7 100644
--- a/src/Request.h
+++ b/src/Request.h
@@ -80,7 +80,7 @@ private:
bool parseUrl(const string& url);
public:
- CookieBox* cookieBox;
+ CookieBoxHandle cookieBox;
public:
Request();
virtual ~Request();
diff --git a/src/RequestGroup.cc b/src/RequestGroup.cc
index a38aa4e2..a908f794 100644
--- a/src/RequestGroup.cc
+++ b/src/RequestGroup.cc
@@ -56,10 +56,10 @@ SegmentManHandle RequestGroup::initSegmentMan()
return _segmentMan;
}
-Commands RequestGroup::createNextCommand(DownloadEngine* e, const string& method)
+Commands RequestGroup::createNextCommandWithAdj(DownloadEngine* e, int32_t numAdj)
{
- int32_t numCommand = _numConcurrentCommand == 0 ? _uris.size() : _numConcurrentCommand;
- return createNextCommand(e, numCommand, method);
+ int32_t numCommand = _numConcurrentCommand == 0 ? _uris.size() : _numConcurrentCommand+numAdj;
+ return createNextCommand(e, numCommand, "GET");
}
Commands RequestGroup::createNextCommand(DownloadEngine* e, int32_t numCommand, const string& method)
@@ -212,7 +212,7 @@ void RequestGroup::prepareForNextAction(int cuid, const RequestHandle& req, Down
if(downloadCommand) {
e->commands.push_back(downloadCommand);
} else {
- Commands commands = createNextCommand(e);
+ Commands commands = createNextCommandWithAdj(e, -1);
Command* command = InitiateConnectionCommandFactory::createInitiateConnectionCommand(cuid, req, this, e);
commands.push_front(command);
e->addCommand(commands);
diff --git a/src/RequestGroup.h b/src/RequestGroup.h
index c00d77bc..b4c7df21 100644
--- a/src/RequestGroup.h
+++ b/src/RequestGroup.h
@@ -113,7 +113,7 @@ public:
return _segmentMan;
}
- Commands createNextCommand(DownloadEngine* e, const string& method = "GET");
+ Commands createNextCommandWithAdj(DownloadEngine* e, int32_t numAdj);
Commands createNextCommand(DownloadEngine* e, int32_t numCommand, const string& method = "GET");
diff --git a/src/Util.cc b/src/Util.cc
index d11805cb..5a6342ce 100644
--- a/src/Util.cc
+++ b/src/Util.cc
@@ -706,3 +706,12 @@ string Util::abbrevSize(int64_t size)
}
return Util::llitos(size, true)+units[i];
}
+
+time_t Util::httpGMT(const string& httpStdTime)
+{
+ struct tm tm;
+ memset(&tm, 0, sizeof(tm));
+ strptime(httpStdTime.c_str(), "%a, %Y-%m-%d %H:%M:%S GMT", &tm);
+ time_t thetime = timegm(&tm);
+ return thetime;
+}
diff --git a/src/Util.h b/src/Util.h
index 638a2527..7748dbfe 100644
--- a/src/Util.h
+++ b/src/Util.h
@@ -150,6 +150,8 @@ public:
static int64_t getRealSize(const string& sizeWithUnit);
static string abbrevSize(int64_t size);
+
+ static time_t httpGMT(const string& httpTimeFormat);
};
#endif // _D_UTIL_H_
diff --git a/src/main.cc b/src/main.cc
index c211b551..4ab57210 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -51,6 +51,7 @@
#include "File.h"
#include "CUIDCounter.h"
#include "UriFileListParser.h"
+#include "CookieBoxFactory.h"
#include <deque>
#include <algorithm>
#include <time.h>
@@ -211,6 +212,8 @@ void showUsage() {
" URIs by Tab in a single line.") << endl;
cout << _(" -j, --max-concurrent-downloads=N Set maximum number of concurrent downloads.\n"
" Default: 5") << endl;
+ cout << _(" --load-cookies=FILE Load cookies from FILE. The format of FILE is\n"
+ " one used by Netscape and Mozilla.") << endl;
#ifdef ENABLE_BITTORRENT
cout << _(" -T, --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"
@@ -243,9 +246,8 @@ void showUsage() {
#ifdef ENABLE_METALINK
cout << _(" -M, --metalink-file=METALINK_FILE The file path to .metalink file.") << endl;
cout << _(" -C, --metalink-servers=NUM_SERVERS The number of servers to connect to\n"
- " simultaneously. If more than one connection per\n"
- " server is required, use -s option.\n"
- " Default: 15") << endl;
+ " simultaneously.\n"
+ " Default: 5") << endl;
cout << _(" --metalink-version=VERSION The version of file to download.") << endl;
cout << _(" --metalink-language=LANGUAGE The language of file to download.") << endl;
cout << _(" --metalink-os=OS The operating system the file is targeted.") << endl;
@@ -319,7 +321,7 @@ int main(int argc, char* argv[]) {
op->put(PREF_SEGMENT_SIZE, Util::itos(1024*1024));
op->put(PREF_HTTP_KEEP_ALIVE, V_FALSE);
op->put(PREF_LISTEN_PORT, "-1");
- op->put(PREF_METALINK_SERVERS, "15");
+ op->put(PREF_METALINK_SERVERS, "5");
op->put(PREF_FOLLOW_TORRENT,
#ifdef ENABLE_BITTORRENT
V_TRUE
@@ -401,6 +403,7 @@ int main(int argc, char* argv[]) {
{ "no-netrc", no_argument, 0, 'n' },
{ "input-file", required_argument, 0, 'i' },
{ "max-concurrent-downloads", required_argument, 0, 'j' },
+ { "load-cookies", required_argument, &lopt, 205 },
#ifdef ENABLE_BITTORRENT
{ "torrent-file", required_argument, NULL, 'T' },
{ "listen-port", required_argument, &lopt, 15 },
@@ -531,6 +534,9 @@ int main(int argc, char* argv[]) {
case 204:
cmdstream << PREF_REALTIME_CHUNK_CHECKSUM << "=" << optarg << "\n";
break;
+ case 205:
+ cmdstream << PREF_LOAD_COOKIES << "=" << optarg << "\n";
+ break;
}
break;
}
@@ -682,6 +688,20 @@ int main(int argc, char* argv[]) {
requestFactory->setNetrc(netrc);
}
}
+
+ CookieBoxFactoryHandle cookieBoxFactory = new CookieBoxFactory();
+ CookieBoxFactorySingletonHolder::instance(cookieBoxFactory);
+ if(op->defined(PREF_LOAD_COOKIES)) {
+ File cookieFile(op->get(PREF_LOAD_COOKIES));
+ if(cookieFile.isFile()) {
+ ifstream in(op->get(PREF_LOAD_COOKIES).c_str());
+ CookieBoxFactorySingletonHolder::instance()->loadDefaultCookie(in);
+ } else {
+ logger->error("Failed to load cookies from %s", op->get(PREF_LOAD_COOKIES).c_str());
+ exit(EXIT_FAILURE);
+ }
+ }
+
RequestFactorySingletonHolder::instance(requestFactory);
CUIDCounterHandle cuidCounter = new CUIDCounter();
CUIDCounterSingletonHolder::instance(cuidCounter);
diff --git a/src/message.h b/src/message.h
index 61b381ad..19d79e0f 100644
--- a/src/message.h
+++ b/src/message.h
@@ -44,8 +44,9 @@
#define MSG_REDIRECT _("CUID#%d - Redirecting to %s")
#define MSG_SENDING_REQUEST _("CUID#%d - Requesting:\n%s")
#define MSG_RECEIVE_RESPONSE _("CUID#%d - Response received:\n%s")
-#define MSG_DOWNLOAD_ABORTED _("CUID#%d - Download aborted.")
-#define MSG_RESTARTING_DOWNLOAD _("CUID#%d - Restarting the download.")
+#define MSG_DOWNLOAD_ABORTED _("CUID#%d - Download aborted. URI=%s")
+#define MSG_RESTARTING_DOWNLOAD _("CUID#%d - Restarting the download. URI=%s")
+#define MSG_TORRENT_DOWNLOAD_ABORTED _("CUID#%d - Download aborted.")
#define MSG_MAX_TRY _("CUID#%d - %d times attempted, but no success. Download aborted.")
#define MSG_UNREGISTER_CUID _("CUID#%d - Unregistering cuid from segmentManager.")
#define MSG_SEND_PEER_MESSAGE "CUID#%d - To: %s:%d %s"
@@ -56,7 +57,7 @@
#define MSG_GOT_NEW_PIECE _("CUID#%d - we got new piece. index=%d")
#define MSG_GOT_WRONG_PIECE _("CUID#%d - we got wrong piece. index=%d")
#define MSG_DOWNLOAD_NOT_COMPLETE _("CUID#%d - Download not complete: %s")
-#define MSG_DOWNLOAD_ALREADY_COMPLETED _("CUID#%d - Download already completed: %s")
+#define MSG_DOWNLOAD_ALREADY_COMPLETED _("CUID#%d - Download has already completed: %s")
#define MSG_GOOD_CHECKSUM _("CUID#%d - Good checksum: %s")
#define MSG_BAD_CHECKSUM _("CUID#%d - Bad checksum: %s")
diff --git a/src/prefs.h b/src/prefs.h
index a9ce5d3b..b1f7d1a8 100644
--- a/src/prefs.h
+++ b/src/prefs.h
@@ -135,6 +135,8 @@
#define PREF_HTTP_KEEP_ALIVE "http-keep-alive"
// values: string
#define PREF_USER_AGENT "user-agent"
+// value: string that your file system recognizes as a file name.
+#define PREF_LOAD_COOKIES "load-cookies"
/**
* HTTP proxy related preferences