mirror of https://github.com/aria2/aria2
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.ccpull/1/head
parent
e6707208d1
commit
8fab0ff216
23
ChangeLog
23
ChangeLog
|
@ -1,3 +1,26 @@
|
|||
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.
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -52,6 +52,7 @@
|
|||
#include "Socket.h"
|
||||
#include "Option.h"
|
||||
#include "CookieStorage.h"
|
||||
#include "AuthConfigFactory.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,6 +55,7 @@
|
|||
# include "GZipDecoder.h"
|
||||
#endif // HAVE_LIBZ
|
||||
#include "CookieStorage.h"
|
||||
#include "AuthConfigFactory.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
|
|
|
@ -63,6 +63,7 @@
|
|||
#include "HttpHeader.h"
|
||||
#include "LogFactory.h"
|
||||
#include "CookieStorage.h"
|
||||
#include "AuthConfigFactory.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
|
|
|
@ -51,6 +51,7 @@
|
|||
#include "prefs.h"
|
||||
#include "Option.h"
|
||||
#include "CookieStorage.h"
|
||||
#include "AuthConfigFactory.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
17
src/main.cc
17
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
|
||||
|
|
|
@ -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() {}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include "Decoder.h"
|
||||
#include "DlRetryEx.h"
|
||||
#include "CookieStorage.h"
|
||||
#include "AuthConfigFactory.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
|
|
Loading…
Reference in New Issue