summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2008-11-03 10:06:25 +0000
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2008-11-03 10:06:25 +0000
commit8fab0ff2160399487fb0010d3b0c8b431dfe545f (patch)
treedd0e1fbe1b28176773dccc0fd71bbed77fdf89fb
parente6707208d1821d043b8d2b01551b5424a0768cd8 (diff)
2008-11-03 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
AuthConfigFactory is now part of DownloadEngine. * src/AbstractProxyRequestCommand.cc * src/AuthConfigFactory.h * src/DownloadEngine.cc * src/DownloadEngine.h * src/FtpConnection.cc * src/FtpConnection.h * src/FtpNegotiationCommand.cc * src/HttpConnection.cc * src/HttpRequest.cc * src/HttpRequest.h * src/HttpRequestCommand.cc * src/HttpResponse.cc * src/HttpResponseCommand.cc * src/HttpSkipResponseCommand.cc * src/MultiUrlRequestInfo.cc * src/main.cc * test/FtpConnectionTest.cc * test/HttpRequestTest.cc * test/HttpResponseTest.cc
-rw-r--r--ChangeLog23
-rw-r--r--src/AbstractProxyRequestCommand.cc5
-rw-r--r--src/AuthConfigFactory.h14
-rw-r--r--src/DownloadEngine.cc13
-rw-r--r--src/DownloadEngine.h8
-rw-r--r--src/FtpConnection.cc24
-rw-r--r--src/FtpConnection.h14
-rw-r--r--src/FtpNegotiationCommand.cc16
-rw-r--r--src/HttpConnection.cc1
-rw-r--r--src/HttpRequest.cc23
-rw-r--r--src/HttpRequest.h9
-rw-r--r--src/HttpRequestCommand.cc16
-rw-r--r--src/HttpResponse.cc1
-rw-r--r--src/HttpResponseCommand.cc1
-rw-r--r--src/HttpSkipResponseCommand.cc1
-rw-r--r--src/MultiUrlRequestInfo.cc33
-rw-r--r--src/main.cc17
-rw-r--r--test/FtpConnectionTest.cc21
-rw-r--r--test/HttpRequestTest.cc24
-rw-r--r--test/HttpResponseTest.cc1
20 files changed, 191 insertions, 74 deletions
diff --git a/ChangeLog b/ChangeLog
index 2aa2b299..3dc048d1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,28 @@
2008-11-03 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
+ AuthConfigFactory is now part of DownloadEngine.
+ * src/AbstractProxyRequestCommand.cc
+ * src/AuthConfigFactory.h
+ * src/DownloadEngine.cc
+ * src/DownloadEngine.h
+ * src/FtpConnection.cc
+ * src/FtpConnection.h
+ * src/FtpNegotiationCommand.cc
+ * src/HttpConnection.cc
+ * src/HttpRequest.cc
+ * src/HttpRequest.h
+ * src/HttpRequestCommand.cc
+ * src/HttpResponse.cc
+ * src/HttpResponseCommand.cc
+ * src/HttpSkipResponseCommand.cc
+ * src/MultiUrlRequestInfo.cc
+ * src/main.cc
+ * test/FtpConnectionTest.cc
+ * test/HttpRequestTest.cc
+ * test/HttpResponseTest.cc
+
+2008-11-03 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
+
Corrected catched exception type.
* src/ServerStatMan.cc
diff --git a/src/AbstractProxyRequestCommand.cc b/src/AbstractProxyRequestCommand.cc
index c9da63be..8ade62ea 100644
--- a/src/AbstractProxyRequestCommand.cc
+++ b/src/AbstractProxyRequestCommand.cc
@@ -43,6 +43,7 @@
#include "prefs.h"
#include "Socket.h"
#include "CookieStorage.h"
+#include "AuthConfigFactory.h"
namespace aria2 {
@@ -67,8 +68,10 @@ bool AbstractProxyRequestCommand::executeInternal() {
HttpRequestHandle httpRequest(new HttpRequest());
httpRequest->setUserAgent(e->option->get(PREF_USER_AGENT));
httpRequest->setRequest(req);
+ httpRequest->setAuthConfigFactory(e->getAuthConfigFactory());
+
httpRequest->configure(e->option);
-
+
httpConnection->sendProxyRequest(httpRequest);
} else {
httpConnection->sendPendingData();
diff --git a/src/AuthConfigFactory.h b/src/AuthConfigFactory.h
index 6635c610..9ec54140 100644
--- a/src/AuthConfigFactory.h
+++ b/src/AuthConfigFactory.h
@@ -36,9 +36,11 @@
#define _D_AUTH_CONFIG_FACTORY_H_
#include "common.h"
+
+#include <string>
+
#include "SharedHandle.h"
#include "SingletonHolder.h"
-#include <string>
namespace aria2 {
@@ -54,7 +56,8 @@ private:
SharedHandle<Netrc> _netrc;
- SharedHandle<AuthConfig> createAuthConfig(const std::string& user, const std::string& password) const;
+ SharedHandle<AuthConfig> createAuthConfig(const std::string& user,
+ const std::string& password) const;
SharedHandle<AuthResolver> createHttpAuthResolver() const;
@@ -68,9 +71,11 @@ public:
~AuthConfigFactory();
- SharedHandle<AuthConfig> createAuthConfig(const SharedHandle<Request>& request) const;
+ SharedHandle<AuthConfig> createAuthConfig
+ (const SharedHandle<Request>& request) const;
- SharedHandle<AuthConfig> createAuthConfigForHttpProxy(const SharedHandle<Request>& request) const;
+ SharedHandle<AuthConfig> createAuthConfigForHttpProxy
+ (const SharedHandle<Request>& request) const;
void setNetrc(const SharedHandle<Netrc>& netrc);
@@ -80,7 +85,6 @@ public:
};
typedef SharedHandle<AuthConfigFactory> AuthConfigFactoryHandle;
-typedef SingletonHolder<AuthConfigFactoryHandle> AuthConfigFactorySingleton;
} // namespace aria2
diff --git a/src/DownloadEngine.cc b/src/DownloadEngine.cc
index c64384c1..14a334c6 100644
--- a/src/DownloadEngine.cc
+++ b/src/DownloadEngine.cc
@@ -63,6 +63,8 @@
#include "CookieStorage.h"
#include "A2STR.h"
#include "DNSCache.h"
+#include "AuthConfigFactory.h"
+#include "AuthConfig.h"
#include "BtRegistry.h"
#include "BtContext.h"
@@ -1078,4 +1080,15 @@ void DownloadEngine::cacheIPAddress
_dnsCache->put(hostname, ipaddr);
}
+void DownloadEngine::setAuthConfigFactory
+(const SharedHandle<AuthConfigFactory>& factory)
+{
+ _authConfigFactory = factory;
+}
+
+SharedHandle<AuthConfigFactory> DownloadEngine::getAuthConfigFactory() const
+{
+ return _authConfigFactory;
+}
+
} // namespace aria2
diff --git a/src/DownloadEngine.h b/src/DownloadEngine.h
index 5e358929..bd9c10c3 100644
--- a/src/DownloadEngine.h
+++ b/src/DownloadEngine.h
@@ -67,6 +67,8 @@ class SocketCore;
class CookieStorage;
class BtRegistry;
class DNSCache;
+class AuthConfigFactory;
+class Request;
class CommandEvent
{
@@ -304,6 +306,8 @@ private:
SharedHandle<DNSCache> _dnsCache;
+ SharedHandle<AuthConfigFactory> _authConfigFactory;
+
void shortSleep() const;
/**
@@ -425,6 +429,10 @@ public:
const std::string& findCachedIPAddress(const std::string& hostname) const;
void cacheIPAddress(const std::string& hostname, const std::string& ipaddr);
+
+ void setAuthConfigFactory(const SharedHandle<AuthConfigFactory>& factory);
+
+ SharedHandle<AuthConfigFactory> getAuthConfigFactory() const;
};
typedef SharedHandle<DownloadEngine> DownloadEngineHandle;
diff --git a/src/FtpConnection.cc b/src/FtpConnection.cc
index fef343e4..916c3dfa 100644
--- a/src/FtpConnection.cc
+++ b/src/FtpConnection.cc
@@ -33,6 +33,11 @@
*/
/* copyright --> */
#include "FtpConnection.h"
+
+#include <cstring>
+#include <cstdio>
+#include <cassert>
+
#include "Request.h"
#include "Segment.h"
#include "Option.h"
@@ -48,9 +53,7 @@
#include "Socket.h"
#include "A2STR.h"
#include "StringFormat.h"
-#include <cstring>
-#include <cstdio>
-#include <cassert>
+#include "AuthConfig.h"
namespace aria2 {
@@ -59,8 +62,11 @@ const std::string FtpConnection::A("A");
const std::string FtpConnection::I("I");
FtpConnection::FtpConnection(int32_t cuid, const SocketHandle& socket,
- const RequestHandle& req, const Option* op):
- cuid(cuid), socket(socket), req(req), option(op),
+ const RequestHandle& req,
+ const SharedHandle<AuthConfig>& authConfig,
+ const Option* op):
+ cuid(cuid), socket(socket), req(req),
+ _authConfig(authConfig), option(op),
logger(LogFactory::getInstance()),
_socketBuffer(socket),
_baseWorkingDir("/") {}
@@ -70,9 +76,7 @@ FtpConnection::~FtpConnection() {}
bool FtpConnection::sendUser()
{
if(_socketBuffer.sendBufferIsEmpty()) {
- std::string request = "USER "+
- AuthConfigFactorySingleton::instance()->createAuthConfig(req)->
- getUser()+"\r\n";
+ std::string request = "USER "+_authConfig->getUser()+"\r\n";
logger->info(MSG_SENDING_REQUEST, cuid, "USER ********");
_socketBuffer.feedSendBuffer(request);
}
@@ -83,9 +87,7 @@ bool FtpConnection::sendUser()
bool FtpConnection::sendPass()
{
if(_socketBuffer.sendBufferIsEmpty()) {
- std::string request = "PASS "+
- AuthConfigFactorySingleton::instance()->createAuthConfig(req)->
- getPassword()+"\r\n";
+ std::string request = "PASS "+_authConfig->getPassword()+"\r\n";
logger->info(MSG_SENDING_REQUEST, cuid, "PASS ********");
_socketBuffer.feedSendBuffer(request);
}
diff --git a/src/FtpConnection.h b/src/FtpConnection.h
index 235a905f..17eeb52e 100644
--- a/src/FtpConnection.h
+++ b/src/FtpConnection.h
@@ -36,11 +36,13 @@
#define _D_FTP_CONNECTION_H_
#include "common.h"
+
+#include <utility>
+#include <string>
+
#include "SharedHandle.h"
#include "TimeA2.h"
#include "SocketBuffer.h"
-#include <utility>
-#include <string>
namespace aria2 {
@@ -49,12 +51,16 @@ class Logger;
class Segment;
class Request;
class SocketCore;
+class AuthConfig;
class FtpConnection {
private:
int32_t cuid;
SharedHandle<SocketCore> socket;
SharedHandle<Request> req;
+
+ SharedHandle<AuthConfig> _authConfig;
+
const Option* option;
Logger* logger;
@@ -76,7 +82,9 @@ private:
static const size_t MAX_RECV_BUFFER = 4096;
public:
FtpConnection(int32_t cuid, const SharedHandle<SocketCore>& socket,
- const SharedHandle<Request>& req, const Option* op);
+ const SharedHandle<Request>& req,
+ const SharedHandle<AuthConfig>& authConfig,
+ const Option* op);
~FtpConnection();
bool sendUser();
bool sendPass();
diff --git a/src/FtpNegotiationCommand.cc b/src/FtpNegotiationCommand.cc
index 8882173b..827cbb51 100644
--- a/src/FtpNegotiationCommand.cc
+++ b/src/FtpNegotiationCommand.cc
@@ -33,6 +33,12 @@
*/
/* copyright --> */
#include "FtpNegotiationCommand.h"
+
+#include <stdint.h>
+#include <cassert>
+#include <utility>
+#include <map>
+
#include "Request.h"
#include "DownloadEngine.h"
#include "FtpConnection.h"
@@ -56,10 +62,8 @@
#include "StringFormat.h"
#include "DiskAdaptor.h"
#include "SegmentMan.h"
-#include <stdint.h>
-#include <cassert>
-#include <utility>
-#include <map>
+#include "AuthConfigFactory.h"
+#include "AuthConfig.h"
namespace aria2 {
@@ -71,7 +75,9 @@ FtpNegotiationCommand::FtpNegotiationCommand(int32_t cuid,
Seq seq,
const std::string& baseWorkingDir):
AbstractCommand(cuid, req, requestGroup, e, s), sequence(seq),
- ftp(new FtpConnection(cuid, socket, req, e->option))
+ ftp(new FtpConnection(cuid, socket, req,
+ e->getAuthConfigFactory()->createAuthConfig(req),
+ e->option))
{
ftp->setBaseWorkingDir(baseWorkingDir);
if(seq == SEQ_RECV_GREETING) {
diff --git a/src/HttpConnection.cc b/src/HttpConnection.cc
index 833e6e6d..0d5c8833 100644
--- a/src/HttpConnection.cc
+++ b/src/HttpConnection.cc
@@ -52,6 +52,7 @@
#include "Socket.h"
#include "Option.h"
#include "CookieStorage.h"
+#include "AuthConfigFactory.h"
namespace aria2 {
diff --git a/src/HttpRequest.cc b/src/HttpRequest.cc
index a5dd0e59..9dd8e976 100644
--- a/src/HttpRequest.cc
+++ b/src/HttpRequest.cc
@@ -33,6 +33,10 @@
*/
/* copyright --> */
#include "HttpRequest.h"
+
+#include <cassert>
+#include <numeric>
+
#include "Request.h"
#include "Segment.h"
#include "Range.h"
@@ -45,8 +49,6 @@
#include "AuthConfig.h"
#include "a2functional.h"
#include "TimeA2.h"
-#include <numeric>
-#include <cassert>
namespace aria2 {
@@ -134,9 +136,8 @@ std::string HttpRequest::getHostText(const std::string& host, uint16_t port) con
std::string HttpRequest::createRequest() const
{
- SharedHandle<AuthConfig> authConfig = AuthConfigFactorySingleton::instance()
- ->createAuthConfig(request);
-
+ SharedHandle<AuthConfig> authConfig =
+ _authConfigFactory->createAuthConfig(request);
std::string requestLine = "GET ";
if(getProtocol() == Request::PROTO_FTP || proxyEnabled) {
if(getProtocol() == Request::PROTO_FTP &&
@@ -257,9 +258,11 @@ std::string HttpRequest::createProxyRequest() const
return requestLine;
}
-std::string HttpRequest::getProxyAuthString() const {
+std::string HttpRequest::getProxyAuthString() const
+{
return "Proxy-Authorization: Basic "+
- Base64::encode(AuthConfigFactorySingleton::instance()->createAuthConfigForHttpProxy(request)->getAuthText())+"\r\n";
+ Base64::encode(_authConfigFactory->createAuthConfigForHttpProxy(request)->
+ getAuthText())+"\r\n";
}
void HttpRequest::enableContentEncoding()
@@ -348,4 +351,10 @@ SharedHandle<CookieStorage> HttpRequest::getCookieStorage() const
return _cookieStorage;
}
+void HttpRequest::setAuthConfigFactory
+(const SharedHandle<AuthConfigFactory>& factory)
+{
+ _authConfigFactory = factory;
+}
+
} // namespace aria2
diff --git a/src/HttpRequest.h b/src/HttpRequest.h
index 9f364873..8069851c 100644
--- a/src/HttpRequest.h
+++ b/src/HttpRequest.h
@@ -36,10 +36,12 @@
#define _D_HTTP_REQUEST_H_
#include "common.h"
-#include "SharedHandle.h"
+
#include <string>
#include <deque>
+#include "SharedHandle.h"
+
namespace aria2 {
class Request;
@@ -47,6 +49,7 @@ class Segment;
class Range;
class Option;
class CookieStorage;
+class AuthConfigFactory;
class HttpRequest {
private:
@@ -73,6 +76,8 @@ private:
SharedHandle<CookieStorage> _cookieStorage;
+ SharedHandle<AuthConfigFactory> _authConfigFactory;
+
std::string getHostText(const std::string& host, uint16_t port) const;
std::string getProxyAuthString() const;
@@ -184,6 +189,8 @@ public:
void setCookieStorage(const SharedHandle<CookieStorage>& cookieStorage);
SharedHandle<CookieStorage> getCookieStorage() const;
+
+ void setAuthConfigFactory(const SharedHandle<AuthConfigFactory>& factory);
};
typedef SharedHandle<HttpRequest> HttpRequestHandle;
diff --git a/src/HttpRequestCommand.cc b/src/HttpRequestCommand.cc
index 7e65a4b0..6f8be74d 100644
--- a/src/HttpRequestCommand.cc
+++ b/src/HttpRequestCommand.cc
@@ -33,6 +33,9 @@
*/
/* copyright --> */
#include "HttpRequestCommand.h"
+
+#include <algorithm>
+
#include "Request.h"
#include "DownloadEngine.h"
#include "RequestGroup.h"
@@ -47,7 +50,8 @@
#include "a2functional.h"
#include "Util.h"
#include "CookieStorage.h"
-#include <algorithm>
+#include "AuthConfigFactory.h"
+#include "AuthConfig.h"
namespace aria2 {
@@ -74,7 +78,8 @@ createHttpRequest(const SharedHandle<Request>& req,
uint64_t totalLength,
const Option* option,
const RequestGroup* rg,
- const SharedHandle<CookieStorage>& cookieStorage)
+ const SharedHandle<CookieStorage>& cookieStorage,
+ const SharedHandle<AuthConfigFactory>& authConfigFactory)
{
HttpRequestHandle httpRequest(new HttpRequest());
httpRequest->setUserAgent(option->get(PREF_USER_AGENT));
@@ -83,6 +88,7 @@ createHttpRequest(const SharedHandle<Request>& req,
httpRequest->setEntityLength(totalLength);
httpRequest->addHeader(option->get(PREF_HEADER));
httpRequest->setCookieStorage(cookieStorage);
+ httpRequest->setAuthConfigFactory(authConfigFactory);
if(!rg->getAcceptFeatures().empty()) {
const std::deque<std::string>& acceptFeatures = rg->getAcceptFeatures();
std::string acceptFeaturesHeader = "Accept-Features: ";
@@ -116,7 +122,8 @@ bool HttpRequestCommand::executeInternal() {
(createHttpRequest(req, SharedHandle<Segment>(),
_requestGroup->getTotalLength(), e->option,
_requestGroup,
- e->getCookieStorage()));
+ e->getCookieStorage(),
+ e->getAuthConfigFactory()));
_httpConnection->sendRequest(httpRequest);
} else {
for(Segments::iterator itr = _segments.begin(); itr != _segments.end(); ++itr) {
@@ -126,7 +133,8 @@ bool HttpRequestCommand::executeInternal() {
(createHttpRequest(req, segment,
_requestGroup->getTotalLength(), e->option,
_requestGroup,
- e->getCookieStorage()));
+ e->getCookieStorage(),
+ e->getAuthConfigFactory()));
_httpConnection->sendRequest(httpRequest);
}
}
diff --git a/src/HttpResponse.cc b/src/HttpResponse.cc
index e77e696e..e3f76ec9 100644
--- a/src/HttpResponse.cc
+++ b/src/HttpResponse.cc
@@ -55,6 +55,7 @@
# include "GZipDecoder.h"
#endif // HAVE_LIBZ
#include "CookieStorage.h"
+#include "AuthConfigFactory.h"
namespace aria2 {
diff --git a/src/HttpResponseCommand.cc b/src/HttpResponseCommand.cc
index d7236ea7..3fe1c22a 100644
--- a/src/HttpResponseCommand.cc
+++ b/src/HttpResponseCommand.cc
@@ -63,6 +63,7 @@
#include "HttpHeader.h"
#include "LogFactory.h"
#include "CookieStorage.h"
+#include "AuthConfigFactory.h"
namespace aria2 {
diff --git a/src/HttpSkipResponseCommand.cc b/src/HttpSkipResponseCommand.cc
index e7ec9742..e2ada749 100644
--- a/src/HttpSkipResponseCommand.cc
+++ b/src/HttpSkipResponseCommand.cc
@@ -51,6 +51,7 @@
#include "prefs.h"
#include "Option.h"
#include "CookieStorage.h"
+#include "AuthConfigFactory.h"
namespace aria2 {
diff --git a/src/MultiUrlRequestInfo.cc b/src/MultiUrlRequestInfo.cc
index 01dccae1..369e9122 100644
--- a/src/MultiUrlRequestInfo.cc
+++ b/src/MultiUrlRequestInfo.cc
@@ -52,6 +52,8 @@
#include "StatCalc.h"
#include "CookieStorage.h"
#include "File.h"
+#include "Netrc.h"
+#include "AuthConfigFactory.h"
namespace aria2 {
@@ -95,7 +97,7 @@ void MultiUrlRequestInfo::printMessageForContinue()
int MultiUrlRequestInfo::execute()
{
- int returnValue = 0;
+ int returnValue = 1;
try {
DownloadEngineHandle e =
DownloadEngineFactory().newDownloadEngine(_option, _requestGroups);
@@ -114,6 +116,22 @@ int MultiUrlRequestInfo::execute()
_logger->error(EX_EXCEPTION_CAUGHT, e);
}
+ SharedHandle<AuthConfigFactory> authConfigFactory
+ (new AuthConfigFactory(_option));
+ File netrccf(_option->get(PREF_NETRC_PATH));
+ if(!_option->getAsBool(PREF_NO_NETRC) && netrccf.isFile()) {
+ mode_t mode = netrccf.mode();
+ if(mode&(S_IRWXG|S_IRWXO)) {
+ _logger->notice(MSG_INCORRECT_NETRC_PERMISSION,
+ _option->get(PREF_NETRC_PATH).c_str());
+ } else {
+ SharedHandle<Netrc> netrc(new Netrc());
+ netrc->parse(_option->get(PREF_NETRC_PATH));
+ authConfigFactory->setNetrc(netrc);
+ }
+ }
+ e->setAuthConfigFactory(authConfigFactory);
+
std::string serverStatIf = _option->get(PREF_SERVER_STAT_IF);
if(!serverStatIf.empty()) {
e->_requestGroupMan->loadServerStat(serverStatIf);
@@ -123,7 +141,8 @@ int MultiUrlRequestInfo::execute()
e->setStatCalc(_statCalc);
e->fillCommand();
- // The number of simultaneous download is specified by PREF_MAX_CONCURRENT_DOWNLOADS.
+ // The number of simultaneous download is specified by
+ // PREF_MAX_CONCURRENT_DOWNLOADS.
// The remaining urls are queued into FillRequestGroupCommand.
// It observes the number of simultaneous downloads and if it is under
// the limit, it adds RequestGroup object from its queue to DownloadEngine.
@@ -143,13 +162,13 @@ int MultiUrlRequestInfo::execute()
_summaryOut << std::flush;
RequestGroupMan::DownloadStat s = e->_requestGroupMan->getDownloadStat();
- if(!s.allCompleted()) {
+ if(s.allCompleted()) {
+ returnValue = 0;
+ } else {
printMessageForContinue();
- returnValue = 1;
}
- } catch(RecoverableException *ex) {
- _logger->error(EX_EXCEPTION_CAUGHT, ex);
- delete ex;
+ } catch(RecoverableException& e) {
+ _logger->error(EX_EXCEPTION_CAUGHT, e);
}
Util::setGlobalSignalHandler(SIGINT, SIG_DFL, 0);
Util::setGlobalSignalHandler(SIGTERM, SIG_DFL, 0);
diff --git a/src/main.cc b/src/main.cc
index 2faad8d4..a456bf37 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -48,11 +48,9 @@
#include "Logger.h"
#include "Util.h"
#include "BitfieldManFactory.h"
-#include "AuthConfigFactory.h"
#include "FeatureConfig.h"
#include "MultiUrlRequestInfo.h"
#include "SimpleRandomizer.h"
-#include "Netrc.h"
#include "FatalException.h"
#include "File.h"
#include "UriListParser.h"
@@ -371,21 +369,6 @@ int main(int argc, char* argv[])
logger->info("%s %s %s", PACKAGE, PACKAGE_VERSION, TARGET);
logger->info(MSG_LOGGING_STARTED);
- AuthConfigFactoryHandle authConfigFactory(new AuthConfigFactory(op));
- 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)) {
- logger->notice(MSG_INCORRECT_NETRC_PERMISSION,
- op->get(PREF_NETRC_PATH).c_str());
- } else {
- NetrcHandle netrc(new Netrc());
- netrc->parse(op->get(PREF_NETRC_PATH));
- authConfigFactory->setNetrc(netrc);
- }
- }
-
- AuthConfigFactorySingleton::instance(authConfigFactory);
#ifdef ENABLE_MESSAGE_DIGEST
MessageDigestHelper::staticSHA1DigestInit();
#endif // ENABLE_MESSAGE_DIGEST
diff --git a/test/FtpConnectionTest.cc b/test/FtpConnectionTest.cc
index d9143bd9..2a4e4812 100644
--- a/test/FtpConnectionTest.cc
+++ b/test/FtpConnectionTest.cc
@@ -1,4 +1,10 @@
#include "FtpConnection.h"
+
+#include <iostream>
+#include <cstring>
+
+#include <cppunit/extensions/HelperMacros.h>
+
#include "Exception.h"
#include "Util.h"
#include "SocketCore.h"
@@ -6,9 +12,8 @@
#include "Option.h"
#include "DlRetryEx.h"
#include "DlAbortEx.h"
-#include <iostream>
-#include <cstring>
-#include <cppunit/extensions/HelperMacros.h>
+#include "AuthConfigFactory.h"
+#include "AuthConfig.h"
namespace aria2 {
@@ -30,10 +35,14 @@ private:
SharedHandle<SocketCore> _serverSocket;
uint16_t _listenPort;
SharedHandle<FtpConnection> _ftp;
- Option _option;
+ SharedHandle<Option> _option;
+ SharedHandle<AuthConfigFactory> _authConfigFactory;
public:
void setUp()
{
+ _option.reset(new Option());
+ _authConfigFactory.reset(new AuthConfigFactory(_option.get()));
+
//_ftpServerSocket.reset(new SocketCore());
SharedHandle<SocketCore> listenSocket(new SocketCore());
listenSocket->bind(0);
@@ -52,7 +61,9 @@ public:
clientSocket->setBlockingMode();
_serverSocket.reset(listenSocket->acceptConnection());
- _ftp.reset(new FtpConnection(1, clientSocket, req, &_option));
+ _ftp.reset(new FtpConnection(1, clientSocket, req,
+ _authConfigFactory->createAuthConfig(req),
+ _option.get()));
}
void tearDown() {}
diff --git a/test/HttpRequestTest.cc b/test/HttpRequestTest.cc
index e4a8548b..120cb0d4 100644
--- a/test/HttpRequestTest.cc
+++ b/test/HttpRequestTest.cc
@@ -1,4 +1,7 @@
#include "HttpRequest.h"
+
+#include <cppunit/extensions/HelperMacros.h>
+
#include "prefs.h"
#include "AuthConfigFactory.h"
#include "PiecedSegment.h"
@@ -8,7 +11,6 @@
#include "Option.h"
#include "array_fun.h"
#include "CookieStorage.h"
-#include <cppunit/extensions/HelperMacros.h>
namespace aria2 {
@@ -30,15 +32,12 @@ class HttpRequestTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE_END();
private:
SharedHandle<Option> _option;
+ SharedHandle<AuthConfigFactory> _authConfigFactory;
public:
void setUp()
{
- _option.reset(new Option());
-
- SharedHandle<AuthConfigFactory> authConfigFactory
- (new AuthConfigFactory(_option.get()));
- SingletonHolder<SharedHandle<AuthConfigFactory> >::instance
- (authConfigFactory);
+ _option.reset(new Option());
+ _authConfigFactory.reset(new AuthConfigFactory(_option.get()));
}
void testGetStartByte();
@@ -125,6 +124,7 @@ void HttpRequestTest::testCreateRequest()
httpRequest.disableContentEncoding();
httpRequest.setRequest(request);
httpRequest.setSegment(segment);
+ httpRequest.setAuthConfigFactory(_authConfigFactory);
// remove "Connection: close" and add end byte range
request->setPipeliningHint(true);
@@ -346,6 +346,7 @@ void HttpRequestTest::testCreateRequest_ftp()
httpRequest.disableContentEncoding();
httpRequest.setRequest(request);
httpRequest.setSegment(segment);
+ httpRequest.setAuthConfigFactory(_authConfigFactory);
httpRequest.configure(_option.get());
@@ -413,6 +414,7 @@ void HttpRequestTest::testCreateRequest_with_cookie()
httpRequest.setRequest(request);
httpRequest.setSegment(segment);
httpRequest.setCookieStorage(st);
+ httpRequest.setAuthConfigFactory(_authConfigFactory);
std::string expectedText = "GET /archives/aria2-1.0.0.tar.bz2 HTTP/1.1\r\n"
"User-Agent: aria2\r\n"
@@ -478,6 +480,7 @@ void HttpRequestTest::testCreateRequest_query()
HttpRequest httpRequest;
httpRequest.disableContentEncoding();
httpRequest.setRequest(request);
+ httpRequest.setAuthConfigFactory(_authConfigFactory);
std::string expectedText =
"GET /wiki?id=9ad5109a-b8a5-4edf-9373-56a1c34ae138 HTTP/1.1\r\n"
@@ -605,6 +608,7 @@ void HttpRequestTest::testUserAgent()
httpRequest.setRequest(request);
httpRequest.setSegment(segment);
httpRequest.setUserAgent("aria2 (Linux)");
+ httpRequest.setAuthConfigFactory(_authConfigFactory);
std::string expectedText = "GET /archives/aria2-1.0.0.tar.bz2 HTTP/1.1\r\n"
"User-Agent: aria2 (Linux)\r\n"
@@ -634,6 +638,7 @@ void HttpRequestTest::testAddHeader()
HttpRequest httpRequest;
httpRequest.disableContentEncoding();
httpRequest.setRequest(request);
+ httpRequest.setAuthConfigFactory(_authConfigFactory);
httpRequest.addHeader("X-ARIA2: v0.13\nX-ARIA2-DISTRIBUTE: enabled\n");
std::string expectedText = "GET /archives/aria2-1.0.0.tar.bz2 HTTP/1.1\r\n"
@@ -661,7 +666,9 @@ void HttpRequestTest::testAddAcceptType()
HttpRequest httpRequest;
httpRequest.disableContentEncoding();
httpRequest.setRequest(request);
- httpRequest.addAcceptType(&acceptTypes[0], &acceptTypes[arrayLength(acceptTypes)]);
+ httpRequest.setAuthConfigFactory(_authConfigFactory);
+ httpRequest.addAcceptType(&acceptTypes[0],
+ &acceptTypes[arrayLength(acceptTypes)]);
std::string expectedText =
"GET /archives/aria2-1.0.0.tar.bz2 HTTP/1.1\r\n"
@@ -683,6 +690,7 @@ void HttpRequestTest::testEnableAcceptEncoding()
HttpRequest httpRequest;
httpRequest.setRequest(request);
+ httpRequest.setAuthConfigFactory(_authConfigFactory);
std::string acceptEncodings;
#ifdef HAVE_LIBZ
diff --git a/test/HttpResponseTest.cc b/test/HttpResponseTest.cc
index db1bcee4..4ced6997 100644
--- a/test/HttpResponseTest.cc
+++ b/test/HttpResponseTest.cc
@@ -14,6 +14,7 @@
#include "Decoder.h"
#include "DlRetryEx.h"
#include "CookieStorage.h"
+#include "AuthConfigFactory.h"
namespace aria2 {