mirror of https://github.com/aria2/aria2
2007-03-21 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
* src/Request.h: Use AuthResolver to get authentication information. * src/main.cc: Made RequestFactory a singleton object. Netrc is now set to RequestFactory object. * src/AuthConfigItem.h, src/AuthConfigItem.cc: Removed. * src/AuthConfig.h, src/AuthConfig.cc: Rewritten. * src/TrackerWatcherComand.cc: Use RequestFactorySingletonHolder to create Request object.pull/1/head
parent
0f514b0db1
commit
5649cf6cda
10
ChangeLog
10
ChangeLog
|
@ -1,3 +1,13 @@
|
|||
2007-03-21 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||
|
||||
* src/Request.h: Use AuthResolver to get authentication information.
|
||||
* src/main.cc: Made RequestFactory a singleton object. Netrc is now
|
||||
set to RequestFactory object.
|
||||
* src/AuthConfigItem.h, src/AuthConfigItem.cc: Removed.
|
||||
* src/AuthConfig.h, src/AuthConfig.cc: Rewritten.
|
||||
* src/TrackerWatcherComand.cc: Use RequestFactorySingletonHolder to
|
||||
create Request object.
|
||||
|
||||
2007-03-19 Tatsuhiro Tsujikawa <tujikawa at valkyrie dot rednoah com>
|
||||
|
||||
To integrate Netrc into exsiting classes:
|
||||
|
|
6
TODO
6
TODO
|
@ -23,7 +23,9 @@
|
|||
* Fix DefaultBtProgressInfoFile.cc: save(), load()
|
||||
* remove blockIndex
|
||||
* Add an ability of seeding
|
||||
* Continue file allocation with existing file
|
||||
* Rewrite HttpConnection::receiveResponse() using {i,o}stringstream
|
||||
|
||||
* -c command line option to continue the download of existing file assuming
|
||||
that it was downloaded from the beginning.
|
||||
that it was downloaded from the beginning.
|
||||
* Continue file allocation with existing file
|
||||
* keep-alive
|
|
@ -0,0 +1,78 @@
|
|||
/* <!-- 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_ABSTRACT_AUTH_RESOLVER_H_
|
||||
#define _D_ABSTRACT_AUTH_RESOLVER_H_
|
||||
|
||||
#include "AuthResolver.h"
|
||||
|
||||
class AbstractAuthResolver : public AuthResolver {
|
||||
protected:
|
||||
|
||||
AuthConfigHandle _userDefinedAuthConfig;
|
||||
|
||||
AuthConfigHandle _defaultAuthConfig;
|
||||
|
||||
public:
|
||||
AbstractAuthResolver():_userDefinedAuthConfig(0),
|
||||
_defaultAuthConfig(new AuthConfig())
|
||||
{}
|
||||
|
||||
virtual ~AbstractAuthResolver() {}
|
||||
|
||||
void setUserDefinedAuthConfig(const AuthConfigHandle& authConfig)
|
||||
{
|
||||
_userDefinedAuthConfig = authConfig;
|
||||
}
|
||||
|
||||
AuthConfigHandle getUserDefinedAuthConfig() const
|
||||
{
|
||||
return _userDefinedAuthConfig;
|
||||
}
|
||||
|
||||
void setDefaultAuthConfig(const AuthConfigHandle& authConfig)
|
||||
{
|
||||
_defaultAuthConfig = authConfig;
|
||||
}
|
||||
|
||||
AuthConfigHandle getDefaultAuthConfig() const
|
||||
{
|
||||
return _defaultAuthConfig;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
typedef SharedHandle<AbstractAuthResolver> AbstractAuthResolverHandle;
|
||||
|
||||
#endif // _D_ABSTRACT_AUTH_RESOLVER_H_
|
|
@ -0,0 +1,42 @@
|
|||
/* <!-- 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 "AuthConfig.h"
|
||||
|
||||
ostream& operator<<(ostream& o, const AuthConfigHandle& authConfig)
|
||||
{
|
||||
o << authConfig->getAuthText();
|
||||
return o;
|
||||
}
|
||||
|
|
@ -32,20 +32,20 @@
|
|||
* files in the program, then also delete it here.
|
||||
*/
|
||||
/* copyright --> */
|
||||
#ifndef _D_AUTH_CONFIG_ITEM_H_
|
||||
#define _D_AUTH_CONFIG_ITEM_H_
|
||||
#ifndef _D_AUTH_CONFIG_H_
|
||||
#define _D_AUTH_CONFIG_H_
|
||||
|
||||
#include "common.h"
|
||||
|
||||
class AuthConfigItem {
|
||||
class AuthConfig {
|
||||
private:
|
||||
string _authScheme;
|
||||
string _user;
|
||||
string _password;
|
||||
public:
|
||||
|
||||
AuthConfigItem() {}
|
||||
AuthConfigItem(const string& user, const string& password):
|
||||
AuthConfig() {}
|
||||
AuthConfig(const string& user, const string& password):
|
||||
_user(user), _password(password) {}
|
||||
|
||||
string getAuthText() const
|
||||
|
@ -64,8 +64,8 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
typedef SharedHandle<AuthConfigItem> AuthConfigItemHandle;
|
||||
typedef SharedHandle<AuthConfig> AuthConfigHandle;
|
||||
|
||||
ostream& operator<<(ostream& o, const AuthConfigItemHandle& authConfigItem);
|
||||
ostream& operator<<(ostream& o, const AuthConfigHandle& authConfig);
|
||||
|
||||
#endif // _D_AUTH_CONFIG_ITEM_H_
|
||||
#endif // _D_AUTH_CONFIG_H_
|
|
@ -0,0 +1,50 @@
|
|||
/* <!-- 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_AUTH_RESOLVER_H_
|
||||
#define _D_AUTH_RESOLVER_H_
|
||||
|
||||
#include "common.h"
|
||||
#include "AuthConfig.h"
|
||||
|
||||
class AuthResolver {
|
||||
public:
|
||||
virtual ~AuthResolver() {}
|
||||
|
||||
virtual AuthConfigHandle resolveAuthConfig(const string& hostname) = 0;
|
||||
};
|
||||
|
||||
typedef SharedHandle<AuthResolver> AuthResolverHandle;
|
||||
|
||||
#endif // _D_AUTH_RESOLVER_H_
|
|
@ -0,0 +1,44 @@
|
|||
/* <!-- 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 "DefaultAuthResolver.h"
|
||||
|
||||
AuthConfigHandle DefaultAuthResolver::resolveAuthConfig(const string& hostname)
|
||||
{
|
||||
if(_userDefinedAuthConfig.isNull()) {
|
||||
return _defaultAuthConfig;
|
||||
} else {
|
||||
return _userDefinedAuthConfig;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
/* <!-- 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_DEFAULT_AUTH_RESOLVER_H_
|
||||
#define _D_DEFAULT_AUTH_RESOLVER_H_
|
||||
|
||||
#include "AbstractAuthResolver.h"
|
||||
|
||||
class DefaultAuthResolver : public AbstractAuthResolver {
|
||||
public:
|
||||
virtual ~DefaultAuthResolver() {}
|
||||
|
||||
virtual AuthConfigHandle resolveAuthConfig(const string& hostname);
|
||||
};
|
||||
|
||||
typedef SharedHandle<DefaultAuthResolver> DefaultAuthResolverHandle;
|
||||
|
||||
#endif // _D_DEFAULT_AUTH_RESOLVER_H_
|
|
@ -49,13 +49,13 @@ FtpConnection::FtpConnection(int cuid, const SocketHandle& socket,
|
|||
FtpConnection::~FtpConnection() {}
|
||||
|
||||
void FtpConnection::sendUser() const {
|
||||
string request = "USER "+req->resolveFtpAuthConfigItem()->getUser()+"\r\n";
|
||||
string request = "USER "+req->resolveFtpAuthConfig()->getUser()+"\r\n";
|
||||
logger->info(MSG_SENDING_REQUEST, cuid, request.c_str());
|
||||
socket->writeData(request);
|
||||
}
|
||||
|
||||
void FtpConnection::sendPass() const {
|
||||
string request = "PASS "+req->resolveFtpAuthConfigItem()->getPassword()+"\r\n";
|
||||
string request = "PASS "+req->resolveFtpAuthConfig()->getPassword()+"\r\n";
|
||||
logger->info(MSG_SENDING_REQUEST, cuid, "PASS ********");
|
||||
socket->writeData(request);
|
||||
}
|
||||
|
|
|
@ -107,7 +107,7 @@ string HttpRequest::createRequest() const
|
|||
}
|
||||
if(authEnabled) {
|
||||
requestLine += "Authorization: Basic "+
|
||||
Base64::encode(request->resolveHttpAuthConfigItem()->getAuthText())+"\r\n";
|
||||
Base64::encode(request->resolveHttpAuthConfig()->getAuthText())+"\r\n";
|
||||
}
|
||||
if(getPreviousURI().size()) {
|
||||
requestLine += "Referer: "+getPreviousURI()+"\r\n";
|
||||
|
@ -145,7 +145,7 @@ string HttpRequest::createProxyRequest() const
|
|||
|
||||
string HttpRequest::getProxyAuthString() const {
|
||||
return "Proxy-Authorization: Basic "+
|
||||
Base64::encode(request->resolveHttpProxyAuthConfigItem()->getAuthText())+"\r\n";
|
||||
Base64::encode(request->resolveHttpProxyAuthConfig()->getAuthText())+"\r\n";
|
||||
}
|
||||
|
||||
void HttpRequest::configure(const Option* option)
|
||||
|
|
|
@ -70,8 +70,13 @@ SRCS = Socket.h\
|
|||
Range.h\
|
||||
AbstractProxyRequestCommand.cc AbstractProxyRequestCommand.h\
|
||||
AbstractProxyResponseCommand.cc AbstractProxyResponseCommand.h\
|
||||
HttpAuthConfig.h\
|
||||
Netrc.cc Netrc.h
|
||||
Netrc.cc Netrc.h\
|
||||
AuthConfig.cc AuthConfig.h\
|
||||
AuthResolver.h\
|
||||
AbstractAuthResolver.h\
|
||||
DefaultAuthResolver.cc DefaultAuthResolver.h\
|
||||
NetrcAuthResolver.cc NetrcAuthResolver.h\
|
||||
RequestFactory.cc RequestFactory.h
|
||||
# debug_new.cpp
|
||||
|
||||
if ENABLE_ASYNC_DNS
|
||||
|
|
|
@ -217,9 +217,12 @@ am__libaria2c_a_SOURCES_DIST = Socket.h SocketCore.cc SocketCore.h \
|
|||
HttpResponse.cc HttpResponse.h HttpRequest.cc HttpRequest.h \
|
||||
Range.h AbstractProxyRequestCommand.cc \
|
||||
AbstractProxyRequestCommand.h AbstractProxyResponseCommand.cc \
|
||||
AbstractProxyResponseCommand.h HttpAuthConfig.h Netrc.cc \
|
||||
Netrc.h NameResolver.cc NameResolver.h MetaEntry.h Data.cc \
|
||||
Data.h Dictionary.cc Dictionary.h List.cc List.h \
|
||||
AbstractProxyResponseCommand.h Netrc.cc Netrc.h AuthConfig.cc \
|
||||
AuthConfig.h AuthResolver.h AbstractAuthResolver.h \
|
||||
DefaultAuthResolver.cc DefaultAuthResolver.h \
|
||||
NetrcAuthResolver.cc NetrcAuthResolver.h RequestFactory.cc \
|
||||
RequestFactory.h NameResolver.cc NameResolver.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 \
|
||||
|
@ -386,6 +389,8 @@ am__objects_4 = SocketCore.$(OBJEXT) Command.$(OBJEXT) \
|
|||
ChunkChecksumValidator.$(OBJEXT) HttpResponse.$(OBJEXT) \
|
||||
HttpRequest.$(OBJEXT) AbstractProxyRequestCommand.$(OBJEXT) \
|
||||
AbstractProxyResponseCommand.$(OBJEXT) Netrc.$(OBJEXT) \
|
||||
AuthConfig.$(OBJEXT) DefaultAuthResolver.$(OBJEXT) \
|
||||
NetrcAuthResolver.$(OBJEXT) RequestFactory.$(OBJEXT) \
|
||||
$(am__objects_1) $(am__objects_2) $(am__objects_3)
|
||||
am_libaria2c_a_OBJECTS = $(am__objects_4)
|
||||
libaria2c_a_OBJECTS = $(am_libaria2c_a_OBJECTS)
|
||||
|
@ -596,8 +601,12 @@ SRCS = Socket.h SocketCore.cc SocketCore.h Command.cc Command.h \
|
|||
HttpResponse.cc HttpResponse.h HttpRequest.cc HttpRequest.h \
|
||||
Range.h AbstractProxyRequestCommand.cc \
|
||||
AbstractProxyRequestCommand.h AbstractProxyResponseCommand.cc \
|
||||
AbstractProxyResponseCommand.h HttpAuthConfig.h Netrc.cc \
|
||||
Netrc.h $(am__append_1) $(am__append_2) $(am__append_3)
|
||||
AbstractProxyResponseCommand.h Netrc.cc Netrc.h AuthConfig.cc \
|
||||
AuthConfig.h AuthResolver.h AbstractAuthResolver.h \
|
||||
DefaultAuthResolver.cc DefaultAuthResolver.h \
|
||||
NetrcAuthResolver.cc NetrcAuthResolver.h RequestFactory.cc \
|
||||
RequestFactory.h $(am__append_1) $(am__append_2) \
|
||||
$(am__append_3)
|
||||
noinst_LIBRARIES = libaria2c.a
|
||||
libaria2c_a_SOURCES = $(SRCS)
|
||||
aria2c_LDADD = libaria2c.a @LIBINTL@ @ALLOCA@ @LIBGNUTLS_LIBS@\
|
||||
|
@ -691,6 +700,7 @@ distclean-compile:
|
|||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/AbstractProxyResponseCommand.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/AbstractSingleDiskAdaptor.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/AnnounceList.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/AuthConfig.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Base64.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BitfieldMan.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BitfieldManFactory.Po@am__quote@
|
||||
|
@ -723,6 +733,7 @@ distclean-compile:
|
|||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CookieBox.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@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DefaultBtAnnounce.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DefaultBtContext.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DefaultBtInteractive.Po@am__quote@
|
||||
|
@ -776,6 +787,7 @@ distclean-compile:
|
|||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/MultiDiskAdaptor.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/NameResolver.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Netrc.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/NetrcAuthResolver.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Option.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Peer.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/PeerAbstractCommand.Po@am__quote@
|
||||
|
@ -787,6 +799,7 @@ distclean-compile:
|
|||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/PeerMessageUtil.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Piece.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Request.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/RequestFactory.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/RequestSlot.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SeedCheckCommand.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Segment.Po@am__quote@
|
||||
|
|
|
@ -150,6 +150,6 @@ public:
|
|||
};
|
||||
|
||||
typedef SharedHandle<Netrc> NetrcHandle;
|
||||
typedef SingletonHolder<NetrcHandle> NetrcSingletonHolder;
|
||||
//typedef SingletonHolder<NetrcHandle> NetrcSingletonHolder;
|
||||
|
||||
#endif // _D_NETRC_H_
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
/* <!-- 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 "NetrcAuthResolver.h"
|
||||
|
||||
AuthConfigHandle NetrcAuthResolver::resolveAuthConfig(const string& hostname)
|
||||
{
|
||||
if(_userDefinedAuthConfig.isNull()) {
|
||||
return findNetrcAuthenticator(hostname);
|
||||
} else {
|
||||
return _userDefinedAuthConfig;
|
||||
}
|
||||
}
|
||||
|
||||
AuthConfigHandle NetrcAuthResolver::findNetrcAuthenticator(const string& hostname) const
|
||||
{
|
||||
if(_netrc.isNull()) {
|
||||
return _defaultAuthConfig;
|
||||
} else {
|
||||
AuthenticatorHandle auth = _netrc->findAuthenticator(hostname);
|
||||
if(auth.isNull()) {
|
||||
return _defaultAuthConfig;
|
||||
} else {
|
||||
return new AuthConfig(auth->getLogin(), auth->getPassword());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
/* <!-- 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_NETRC_AUTH_RESOLVER_H_
|
||||
#define _D_NETRC_AUTH_RESOLVER_H_
|
||||
|
||||
#include "AbstractAuthResolver.h"
|
||||
#include "Netrc.h"
|
||||
|
||||
class NetrcAuthResolver : public AbstractAuthResolver {
|
||||
private:
|
||||
NetrcHandle _netrc;
|
||||
|
||||
AuthConfigHandle findNetrcAuthenticator(const string& hostname) const;
|
||||
public:
|
||||
virtual ~NetrcAuthResolver() {}
|
||||
|
||||
virtual AuthConfigHandle resolveAuthConfig(const string& hostname);
|
||||
|
||||
void setNetrc(const NetrcHandle& netrc)
|
||||
{
|
||||
_netrc = netrc;
|
||||
}
|
||||
};
|
||||
|
||||
typedef SharedHandle<NetrcAuthResolver> NetrcAuthResolverHandle;
|
||||
|
||||
#endif // _D_NETRC_AUTH_RESOLVER_H_
|
|
@ -35,14 +35,15 @@
|
|||
#include "Request.h"
|
||||
#include "Util.h"
|
||||
#include "FeatureConfig.h"
|
||||
#include "Netrc.h"
|
||||
|
||||
const string Request::METHOD_GET = "get";
|
||||
|
||||
const string Request::METHOD_HEAD = "head";
|
||||
|
||||
Request::Request():port(0), tryCount(0), keepAlive(true), method(METHOD_GET),
|
||||
_userDefinedAuthConfig(0),
|
||||
_httpAuthResolver(0),
|
||||
_httpProxyAuthResolver(0),
|
||||
_ftpAuthResolver(0),
|
||||
isTorrent(false)
|
||||
{
|
||||
cookieBox = new CookieBox();
|
||||
|
@ -134,51 +135,17 @@ bool Request::parseUrl(const string& url) {
|
|||
return true;
|
||||
}
|
||||
|
||||
AuthConfigItemHandle Request::findNetrcAuthenticator() const
|
||||
AuthConfigHandle Request::resolveHttpAuthConfig()
|
||||
{
|
||||
if(!NetrcSingletonHolder::instance().isNull()) {
|
||||
AuthenticatorHandle auth = NetrcSingletonHolder::instance()->findAuthenticator(getHost());
|
||||
if(auth.isNull()) {
|
||||
return 0;
|
||||
} else {
|
||||
return new AuthConfigItem(auth->getLogin(), auth->getPassword());
|
||||
}
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
return _httpAuthResolver->resolveAuthConfig(getHost());
|
||||
}
|
||||
|
||||
AuthConfigItemHandle Request::resolveHttpAuthConfigItem() const
|
||||
AuthConfigHandle Request::resolveFtpAuthConfig()
|
||||
{
|
||||
if(!_userDefinedAuthConfig.isNull() &&
|
||||
!_userDefinedAuthConfig->getHttpAuthConfigItem().isNull()) {
|
||||
return _userDefinedAuthConfig->getHttpAuthConfigItem();
|
||||
} else {
|
||||
return findNetrcAuthenticator();
|
||||
}
|
||||
return _ftpAuthResolver->resolveAuthConfig(getHost());
|
||||
}
|
||||
|
||||
AuthConfigItemHandle Request::resolveFtpAuthConfigItem() const
|
||||
AuthConfigHandle Request::resolveHttpProxyAuthConfig()
|
||||
{
|
||||
if(!_userDefinedAuthConfig.isNull() &&
|
||||
!_userDefinedAuthConfig->getFtpAuthConfigItem().isNull()) {
|
||||
return _userDefinedAuthConfig->getFtpAuthConfigItem();
|
||||
} else {
|
||||
AuthConfigItemHandle authConfig = findNetrcAuthenticator();
|
||||
if(authConfig.isNull()) {
|
||||
return new AuthConfigItem("anonymous", "ARIA2USER@");
|
||||
} else {
|
||||
return authConfig;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AuthConfigItemHandle Request::resolveHttpProxyAuthConfigItem() const
|
||||
{
|
||||
if(!_userDefinedAuthConfig.isNull() &&
|
||||
!_userDefinedAuthConfig->getHttpProxyAuthConfigItem().isNull()) {
|
||||
return _userDefinedAuthConfig->getHttpProxyAuthConfigItem();
|
||||
} else {
|
||||
return findNetrcAuthenticator();
|
||||
}
|
||||
return _httpProxyAuthResolver->resolveAuthConfig(getHost());
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
#include "common.h"
|
||||
#include "CookieBox.h"
|
||||
#include "AuthConfig.h"
|
||||
#include "AuthResolver.h"
|
||||
|
||||
#define SAFE_CHARS "abcdefghijklmnopqrstuvwxyz"\
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"\
|
||||
|
@ -71,12 +72,13 @@ private:
|
|||
bool keepAlive;
|
||||
string method;
|
||||
|
||||
AuthConfigHandle _userDefinedAuthConfig;
|
||||
|
||||
AuthResolverHandle _httpAuthResolver;
|
||||
|
||||
AuthResolverHandle _httpProxyAuthResolver;
|
||||
|
||||
AuthResolverHandle _ftpAuthResolver;
|
||||
|
||||
bool parseUrl(const string& url);
|
||||
|
||||
AuthConfigItemHandle findNetrcAuthenticator() const;
|
||||
|
||||
public:
|
||||
CookieBox* cookieBox;
|
||||
bool isTorrent;
|
||||
|
@ -116,16 +118,26 @@ public:
|
|||
this->method = method;
|
||||
}
|
||||
|
||||
void setUserDefinedAuthConfig(const AuthConfigHandle& authConfig)
|
||||
void setHttpAuthResolver(const AuthResolverHandle& authResolver)
|
||||
{
|
||||
_userDefinedAuthConfig = authConfig;
|
||||
_httpAuthResolver = authResolver;
|
||||
}
|
||||
|
||||
AuthConfigItemHandle resolveHttpAuthConfigItem() const;
|
||||
void setHttpProxyAuthResolver(const AuthResolverHandle& authResolver)
|
||||
{
|
||||
_httpProxyAuthResolver = authResolver;
|
||||
}
|
||||
|
||||
AuthConfigItemHandle resolveFtpAuthConfigItem() const;
|
||||
void setFtpAuthResolver(const AuthResolverHandle& authResolver)
|
||||
{
|
||||
_ftpAuthResolver = authResolver;
|
||||
}
|
||||
|
||||
AuthConfigItemHandle resolveHttpProxyAuthConfigItem() const;
|
||||
AuthConfigHandle resolveHttpAuthConfig();
|
||||
|
||||
AuthConfigHandle resolveFtpAuthConfig();
|
||||
|
||||
AuthConfigHandle resolveHttpProxyAuthConfig();
|
||||
|
||||
const string& getMethod() const {
|
||||
return method;
|
||||
|
|
|
@ -0,0 +1,86 @@
|
|||
/* <!-- 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 "RequestFactory.h"
|
||||
#include "prefs.h"
|
||||
#include "NetrcAuthResolver.h"
|
||||
|
||||
RequestHandle RequestFactory::createRequest()
|
||||
{
|
||||
RequestHandle request = new Request();
|
||||
request->setMethod(_method);
|
||||
request->setReferer(_referer);
|
||||
request->setHttpAuthResolver(createHttpAuthResolver());
|
||||
request->setHttpProxyAuthResolver(createHttpProxyAuthResolver());
|
||||
request->setFtpAuthResolver(createFtpAuthResolver());
|
||||
return request;
|
||||
}
|
||||
|
||||
AuthConfigHandle RequestFactory::createAuthConfig(const string& user, const string& password) const
|
||||
{
|
||||
if(user.length() > 0) {
|
||||
return new AuthConfig(user, password);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
AuthResolverHandle RequestFactory::createHttpAuthResolver()
|
||||
{
|
||||
NetrcAuthResolverHandle authResolver = 0;
|
||||
authResolver = new NetrcAuthResolver();
|
||||
authResolver->setNetrc(_netrc);
|
||||
authResolver->setUserDefinedAuthConfig(createAuthConfig(_option->get(PREF_HTTP_USER), _option->get(PREF_HTTP_PASSWD)));
|
||||
return authResolver;
|
||||
}
|
||||
|
||||
AuthResolverHandle RequestFactory::createFtpAuthResolver()
|
||||
{
|
||||
NetrcAuthResolverHandle authResolver = 0;
|
||||
authResolver = new NetrcAuthResolver();
|
||||
authResolver->setNetrc(_netrc);
|
||||
authResolver->setUserDefinedAuthConfig(createAuthConfig(_option->get(PREF_FTP_USER), _option->get(PREF_FTP_PASSWD)));
|
||||
authResolver->setDefaultAuthConfig(new AuthConfig("anonymous",
|
||||
"ARIA2USER@"));
|
||||
return authResolver;
|
||||
}
|
||||
|
||||
AuthResolverHandle RequestFactory::createHttpProxyAuthResolver()
|
||||
{
|
||||
NetrcAuthResolverHandle authResolver = 0;
|
||||
authResolver = new NetrcAuthResolver();
|
||||
authResolver->setNetrc(_netrc);
|
||||
authResolver->setUserDefinedAuthConfig(createAuthConfig(_option->get(PREF_HTTP_PROXY_USER), _option->get(PREF_HTTP_PROXY_PASSWD)));
|
||||
return authResolver;
|
||||
}
|
|
@ -0,0 +1,90 @@
|
|||
/* <!-- 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_REQUEST_FACTORY_H_
|
||||
#define _D_REQUEST_FACTORY_H_
|
||||
|
||||
#include "common.h"
|
||||
#include "Request.h"
|
||||
#include "Option.h"
|
||||
#include "Netrc.h"
|
||||
|
||||
class RequestFactory {
|
||||
private:
|
||||
const Option* _option;
|
||||
NetrcHandle _netrc;
|
||||
string _method;
|
||||
string _referer;
|
||||
|
||||
AuthConfigHandle createAuthConfig(const string& user, const string& password) const;
|
||||
|
||||
public:
|
||||
RequestFactory():_option(0),
|
||||
_netrc(0),
|
||||
_method(Request::METHOD_GET)
|
||||
{}
|
||||
|
||||
RequestHandle createRequest();
|
||||
|
||||
AuthResolverHandle createHttpAuthResolver();
|
||||
|
||||
AuthResolverHandle createHttpProxyAuthResolver();
|
||||
|
||||
AuthResolverHandle createFtpAuthResolver();
|
||||
|
||||
void setOption(const Option* option)
|
||||
{
|
||||
_option = option;
|
||||
}
|
||||
|
||||
void setNetrc(const NetrcHandle& netrc)
|
||||
{
|
||||
_netrc = netrc;
|
||||
}
|
||||
|
||||
void setMethod(const string& method)
|
||||
{
|
||||
_method = method;
|
||||
}
|
||||
|
||||
void setReferer(const string& referer)
|
||||
{
|
||||
_referer = referer;
|
||||
}
|
||||
};
|
||||
|
||||
typedef SharedHandle<RequestFactory> RequestFactoryHandle;
|
||||
typedef SingletonHolder<RequestFactoryHandle> RequestFactorySingletonHolder;
|
||||
|
||||
#endif // _D_REQUEST_FACTORY_H_
|
|
@ -37,6 +37,7 @@
|
|||
#include "Util.h"
|
||||
#include "SleepCommand.h"
|
||||
#include "prefs.h"
|
||||
#include "RequestFactory.h"
|
||||
|
||||
TrackerWatcherCommand::TrackerWatcherCommand(int cuid,
|
||||
TorrentDownloadEngine* e,
|
||||
|
@ -80,12 +81,10 @@ Command* TrackerWatcherCommand::createCommand() {
|
|||
return command;
|
||||
}
|
||||
|
||||
Command* TrackerWatcherCommand::createRequestCommand(const string& url) {
|
||||
AuthConfigHandle authConfig = new AuthConfig();
|
||||
authConfig->configure(e->option);
|
||||
RequestHandle req;
|
||||
Command* TrackerWatcherCommand::createRequestCommand(const string& url)
|
||||
{
|
||||
RequestHandle req = RequestFactorySingletonHolder::instance()->createRequest();
|
||||
req->setUrl(url);
|
||||
req->setUserDefinedAuthConfig(authConfig);
|
||||
req->isTorrent = true;
|
||||
Command* command =
|
||||
InitiateConnectionCommandFactory::createInitiateConnectionCommand(btRuntime->getNewCuid(), req, e);
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
#include "RecoverableException.h"
|
||||
#include "FatalException.h"
|
||||
#include "message.h"
|
||||
#include "RequestFactory.h"
|
||||
|
||||
std::ostream& operator<<(std::ostream& o, const HeadResult& hr) {
|
||||
o << "filename = " << hr.filename << ", " << "totalLength = " << hr.totalLength;
|
||||
|
@ -88,26 +89,23 @@ private:
|
|||
Requests* requestsPtr;
|
||||
string referer;
|
||||
int split;
|
||||
AuthConfigHandle _userDefinedAuthConfig;
|
||||
string method;
|
||||
public:
|
||||
CreateRequest(Requests* requestsPtr,
|
||||
const string& referer,
|
||||
int split,
|
||||
const AuthConfigHandle& userDefinedAuthConfig,
|
||||
const string& method = Request::METHOD_GET)
|
||||
:requestsPtr(requestsPtr),
|
||||
referer(referer),
|
||||
split(split),
|
||||
_userDefinedAuthConfig(userDefinedAuthConfig),
|
||||
method(method) {}
|
||||
method(method)
|
||||
{}
|
||||
|
||||
void operator()(const string& url) {
|
||||
for(int s = 1; s <= split; s++) {
|
||||
RequestHandle req;
|
||||
RequestHandle req = RequestFactorySingletonHolder::instance()->createRequest();
|
||||
req->setReferer(referer);
|
||||
req->setMethod(method);
|
||||
req->setUserDefinedAuthConfig(_userDefinedAuthConfig);
|
||||
if(req->setUrl(url)) {
|
||||
requestsPtr->push_back(req);
|
||||
} else {
|
||||
|
@ -124,13 +122,12 @@ void UrlRequestInfo::printUrls(const Strings& urls) const {
|
|||
}
|
||||
}
|
||||
|
||||
HeadResultHandle UrlRequestInfo::getHeadResult(const AuthConfigHandle& authConfig) {
|
||||
HeadResultHandle UrlRequestInfo::getHeadResult() {
|
||||
Requests requests;
|
||||
for_each(urls.begin(), urls.end(),
|
||||
CreateRequest(&requests,
|
||||
op->get(PREF_REFERER),
|
||||
1,
|
||||
authConfig,
|
||||
Request::METHOD_HEAD));
|
||||
if(requests.size() == 0) {
|
||||
return 0;
|
||||
|
@ -159,16 +156,12 @@ RequestInfos UrlRequestInfo::execute() {
|
|||
Requests reserved;
|
||||
printUrls(urls);
|
||||
|
||||
AuthConfigHandle authConfig = new AuthConfig();
|
||||
authConfig->configure(op);
|
||||
|
||||
HeadResultHandle hr = getHeadResult(authConfig);
|
||||
HeadResultHandle hr = getHeadResult();
|
||||
|
||||
for_each(urls.begin(), urls.end(),
|
||||
CreateRequest(&requests,
|
||||
op->get(PREF_REFERER),
|
||||
op->getAsInt(PREF_SPLIT),
|
||||
authConfig));
|
||||
op->getAsInt(PREF_SPLIT)));
|
||||
|
||||
logger->info("Head result: filename=%s, total length=%s",
|
||||
hr->filename.c_str(), Util::ullitos(hr->totalLength, true).c_str());
|
||||
|
|
|
@ -64,7 +64,7 @@ private:
|
|||
Requests& reserved,
|
||||
int maxConnections) const;
|
||||
void printUrls(const Strings& urls) const;
|
||||
HeadResultHandle getHeadResult(const AuthConfigHandle& authConfig);
|
||||
HeadResultHandle getHeadResult();
|
||||
public:
|
||||
UrlRequestInfo(const Strings& urls, int maxConnections, Option* op):
|
||||
RequestInfo(op),
|
||||
|
|
15
src/main.cc
15
src/main.cc
|
@ -32,23 +32,18 @@
|
|||
* files in the program, then also delete it here.
|
||||
*/
|
||||
/* copyright --> */
|
||||
#include "HttpInitiateConnectionCommand.h"
|
||||
#include "ConsoleDownloadEngine.h"
|
||||
#include "SegmentMan.h"
|
||||
#include "LogFactory.h"
|
||||
#include "common.h"
|
||||
#include "DefaultDiskWriter.h"
|
||||
#include "LogFactory.h"
|
||||
#include "Util.h"
|
||||
#include "InitiateConnectionCommandFactory.h"
|
||||
#include "prefs.h"
|
||||
#include "FeatureConfig.h"
|
||||
#include "DownloadEngineFactory.h"
|
||||
#include "UrlRequestInfo.h"
|
||||
#include "TorrentRequestInfo.h"
|
||||
#include "BitfieldManFactory.h"
|
||||
#include "SimpleRandomizer.h"
|
||||
#include "ConsoleFileAllocationMonitor.h"
|
||||
#include "Netrc.h"
|
||||
#include "RequestFactory.h"
|
||||
#include <deque>
|
||||
#include <algorithm>
|
||||
#include <time.h>
|
||||
|
@ -775,7 +770,11 @@ int main(int argc, char* argv[]) {
|
|||
|
||||
NetrcHandle netrc = new Netrc();
|
||||
netrc->parse(op->get(PREF_NETRC_PATH));
|
||||
NetrcSingletonHolder::instance(netrc);
|
||||
|
||||
RequestFactoryHandle requestFactory = new RequestFactory();
|
||||
requestFactory->setOption(op);
|
||||
requestFactory->setNetrc(netrc);
|
||||
RequestFactorySingletonHolder::instance(requestFactory);
|
||||
|
||||
Util::setGlobalSignalHandler(SIGPIPE, SIG_IGN, 0);
|
||||
|
||||
|
|
|
@ -1,43 +0,0 @@
|
|||
#include "AuthConfig.h"
|
||||
#include "Option.h"
|
||||
#include "prefs.h"
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
|
||||
class AuthConfigTest:public CppUnit::TestFixture {
|
||||
|
||||
CPPUNIT_TEST_SUITE(AuthConfigTest);
|
||||
CPPUNIT_TEST(testGet);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
void testGet();
|
||||
};
|
||||
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION( AuthConfigTest );
|
||||
|
||||
void AuthConfigTest::testGet()
|
||||
{
|
||||
Option option;
|
||||
option.put(PREF_HTTP_USER, "httpUser");
|
||||
option.put(PREF_HTTP_PASSWD, "httpPassword");
|
||||
option.put(PREF_FTP_USER, "ftpUser");
|
||||
option.put(PREF_FTP_PASSWD, "ftpPassword");
|
||||
option.put(PREF_HTTP_PROXY_USER, "httpProxyUser");
|
||||
option.put(PREF_HTTP_PROXY_PASSWD, "httpProxyPassword");
|
||||
|
||||
AuthConfig authConfig;
|
||||
authConfig.configure(&option);
|
||||
|
||||
AuthConfigItemHandle httpAuth = authConfig.getHttpAuthConfigItem();
|
||||
CPPUNIT_ASSERT_EQUAL(string("httpUser"), httpAuth->getUser());
|
||||
CPPUNIT_ASSERT_EQUAL(string("httpPassword"), httpAuth->getPassword());
|
||||
|
||||
AuthConfigItemHandle ftpAuth = authConfig.getFtpAuthConfigItem();
|
||||
CPPUNIT_ASSERT_EQUAL(string("ftpUser"), ftpAuth->getUser());
|
||||
CPPUNIT_ASSERT_EQUAL(string("ftpPassword"), ftpAuth->getPassword());
|
||||
|
||||
AuthConfigItemHandle httpProxyAuth = authConfig.getHttpProxyAuthConfigItem();
|
||||
CPPUNIT_ASSERT_EQUAL(string("httpProxyUser"), httpProxyAuth->getUser());
|
||||
CPPUNIT_ASSERT_EQUAL(string("httpProxyPassword"), httpProxyAuth->getPassword());
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
#include "HttpRequest.h"
|
||||
#include "prefs.h"
|
||||
#include "RequestFactory.h"
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
|
||||
using namespace std;
|
||||
|
@ -18,8 +19,7 @@ class HttpRequestTest : public CppUnit::TestFixture {
|
|||
private:
|
||||
|
||||
public:
|
||||
void setUp() {
|
||||
}
|
||||
void setUp() {}
|
||||
|
||||
void testGetStartByte();
|
||||
void testGetEndByte();
|
||||
|
@ -79,10 +79,21 @@ void HttpRequestTest::testGetEndByte()
|
|||
|
||||
void HttpRequestTest::testCreateRequest()
|
||||
{
|
||||
RequestHandle request = new Request();
|
||||
SharedHandle<Option> option = new Option();
|
||||
option->put(PREF_HTTP_AUTH_ENABLED, V_FALSE);
|
||||
option->put(PREF_HTTP_PROXY_ENABLED, V_FALSE);
|
||||
option->put(PREF_HTTP_PROXY_METHOD, V_TUNNEL);
|
||||
option->put(PREF_HTTP_PROXY_AUTH_ENABLED, V_FALSE);
|
||||
option->put(PREF_HTTP_USER, "aria2user");
|
||||
option->put(PREF_HTTP_PASSWD, "aria2passwd");
|
||||
option->put(PREF_HTTP_PROXY_USER, "aria2proxyuser");
|
||||
option->put(PREF_HTTP_PROXY_PASSWD, "aria2proxypasswd");
|
||||
RequestFactory requestFactory;
|
||||
requestFactory.setOption(option.get());
|
||||
|
||||
RequestHandle request = requestFactory.createRequest();
|
||||
|
||||
request->setUrl("http://localhost:8080/archives/aria2-1.0.0.tar.bz2");
|
||||
AuthConfigHandle authConfig = new AuthConfig();
|
||||
request->setUserDefinedAuthConfig(authConfig);
|
||||
|
||||
SegmentHandle segment = new Segment();
|
||||
|
||||
|
@ -161,44 +172,7 @@ void HttpRequestTest::testCreateRequest()
|
|||
|
||||
request->resetUrl();
|
||||
|
||||
SharedHandle<Option> option = new Option();
|
||||
option->put(PREF_HTTP_AUTH_ENABLED, V_FALSE);
|
||||
option->put(PREF_HTTP_PROXY_ENABLED, V_FALSE);
|
||||
option->put(PREF_HTTP_PROXY_METHOD, V_TUNNEL);
|
||||
option->put(PREF_HTTP_PROXY_AUTH_ENABLED, V_FALSE);
|
||||
option->put(PREF_HTTP_USER, "aria2user");
|
||||
option->put(PREF_HTTP_PASSWD, "aria2passwd");
|
||||
option->put(PREF_HTTP_PROXY_USER, "aria2proxyuser");
|
||||
option->put(PREF_HTTP_PROXY_PASSWD, "aria2proxypasswd");
|
||||
|
||||
authConfig->configure(option.get());
|
||||
httpRequest.configure(option.get());
|
||||
|
||||
expectedText = "GET /archives/aria2-1.0.0.tar.bz2 HTTP/1.1\r\n"
|
||||
"User-Agent: aria2\r\n"
|
||||
"Accept: */*\r\n"
|
||||
"Host: localhost:8080\r\n"
|
||||
"Pragma: no-cache\r\n"
|
||||
"Cache-Control: no-cache\r\n"
|
||||
"\r\n";
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL(expectedText, httpRequest.createRequest());
|
||||
|
||||
option->put(PREF_HTTP_AUTH_ENABLED, V_TRUE);
|
||||
|
||||
httpRequest.configure(option.get());
|
||||
|
||||
expectedText = "GET /archives/aria2-1.0.0.tar.bz2 HTTP/1.1\r\n"
|
||||
"User-Agent: aria2\r\n"
|
||||
"Accept: */*\r\n"
|
||||
"Host: localhost:8080\r\n"
|
||||
"Pragma: no-cache\r\n"
|
||||
"Cache-Control: no-cache\r\n"
|
||||
"Authorization: Basic YXJpYTJ1c2VyOmFyaWEycGFzc3dk\r\n"
|
||||
"\r\n";
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL(expectedText, httpRequest.createRequest());
|
||||
|
||||
// enable http auth
|
||||
option->put(PREF_HTTP_AUTH_ENABLED, V_TRUE);
|
||||
|
||||
httpRequest.configure(option.get());
|
||||
|
@ -214,6 +188,7 @@ void HttpRequestTest::testCreateRequest()
|
|||
|
||||
CPPUNIT_ASSERT_EQUAL(expectedText, httpRequest.createRequest());
|
||||
|
||||
// enable http proxy auth
|
||||
option->put(PREF_HTTP_PROXY_AUTH_ENABLED, V_TRUE);
|
||||
|
||||
httpRequest.configure(option.get());
|
||||
|
@ -280,17 +255,6 @@ void HttpRequestTest::testCreateRequest()
|
|||
|
||||
void HttpRequestTest::testCreateRequest_ftp()
|
||||
{
|
||||
RequestHandle request = new Request();
|
||||
request->setUrl("ftp://localhost:8080/archives/aria2-1.0.0.tar.bz2");
|
||||
AuthConfigHandle authConfig = new AuthConfig();
|
||||
request->setUserDefinedAuthConfig(authConfig);
|
||||
SegmentHandle segment = new Segment();
|
||||
|
||||
HttpRequest httpRequest;
|
||||
|
||||
httpRequest.setRequest(request);
|
||||
httpRequest.setSegment(segment);
|
||||
|
||||
SharedHandle<Option> option = new Option();
|
||||
option->put(PREF_HTTP_AUTH_ENABLED, V_FALSE);
|
||||
option->put(PREF_HTTP_PROXY_ENABLED, V_FALSE);
|
||||
|
@ -301,8 +265,20 @@ void HttpRequestTest::testCreateRequest_ftp()
|
|||
option->put(PREF_HTTP_PROXY_USER, "aria2proxyuser");
|
||||
option->put(PREF_HTTP_PROXY_PASSWD, "aria2proxypasswd");
|
||||
|
||||
RequestFactory requestFactory;
|
||||
requestFactory.setOption(option.get());
|
||||
|
||||
RequestHandle request = requestFactory.createRequest();
|
||||
request->setUrl("ftp://localhost:8080/archives/aria2-1.0.0.tar.bz2");
|
||||
|
||||
SegmentHandle segment = new Segment();
|
||||
|
||||
HttpRequest httpRequest;
|
||||
|
||||
httpRequest.setRequest(request);
|
||||
httpRequest.setSegment(segment);
|
||||
|
||||
httpRequest.configure(option.get());
|
||||
authConfig->configure(option.get());
|
||||
|
||||
string expectedText = "GET ftp://localhost:8080/archives/aria2-1.0.0.tar.bz2 HTTP/1.1\r\n"
|
||||
"User-Agent: aria2\r\n"
|
||||
|
|
|
@ -1,15 +1,14 @@
|
|||
TESTS = aria2c
|
||||
check_PROGRAMS = $(TESTS)
|
||||
aria2c_SOURCES = AllTest.cc\
|
||||
NetrcTest.cc\
|
||||
RequestTest.cc\
|
||||
HttpRequestTest.cc\
|
||||
AuthConfigTest.cc\
|
||||
NetrcTest.cc\
|
||||
SingletonHolderTest.cc\
|
||||
HttpHeaderTest.cc\
|
||||
HttpResponseTest.cc\
|
||||
BitfieldManTest.cc\
|
||||
SharedHandleTest.cc\
|
||||
RequestTest.cc\
|
||||
ChunkedEncodingTest.cc\
|
||||
FileTest.cc\
|
||||
OptionTest.cc\
|
||||
|
|
|
@ -57,14 +57,13 @@ mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
|
|||
CONFIG_HEADER = $(top_builddir)/config.h
|
||||
CONFIG_CLEAN_FILES =
|
||||
am__EXEEXT_1 = aria2c$(EXEEXT)
|
||||
am_aria2c_OBJECTS = AllTest.$(OBJEXT) NetrcTest.$(OBJEXT) \
|
||||
HttpRequestTest.$(OBJEXT) AuthConfigTest.$(OBJEXT) \
|
||||
am_aria2c_OBJECTS = AllTest.$(OBJEXT) RequestTest.$(OBJEXT) \
|
||||
HttpRequestTest.$(OBJEXT) NetrcTest.$(OBJEXT) \
|
||||
SingletonHolderTest.$(OBJEXT) HttpHeaderTest.$(OBJEXT) \
|
||||
HttpResponseTest.$(OBJEXT) BitfieldManTest.$(OBJEXT) \
|
||||
SharedHandleTest.$(OBJEXT) RequestTest.$(OBJEXT) \
|
||||
ChunkedEncodingTest.$(OBJEXT) FileTest.$(OBJEXT) \
|
||||
OptionTest.$(OBJEXT) Base64Test.$(OBJEXT) UtilTest.$(OBJEXT) \
|
||||
CookieBoxTest.$(OBJEXT) DataTest.$(OBJEXT) \
|
||||
SharedHandleTest.$(OBJEXT) ChunkedEncodingTest.$(OBJEXT) \
|
||||
FileTest.$(OBJEXT) OptionTest.$(OBJEXT) Base64Test.$(OBJEXT) \
|
||||
UtilTest.$(OBJEXT) CookieBoxTest.$(OBJEXT) DataTest.$(OBJEXT) \
|
||||
DictionaryTest.$(OBJEXT) ListTest.$(OBJEXT) \
|
||||
MetaFileUtilTest.$(OBJEXT) ShaVisitorTest.$(OBJEXT) \
|
||||
PeerMessageUtilTest.$(OBJEXT) DefaultDiskWriterTest.$(OBJEXT) \
|
||||
|
@ -259,15 +258,14 @@ sysconfdir = @sysconfdir@
|
|||
target_alias = @target_alias@
|
||||
TESTS = aria2c
|
||||
aria2c_SOURCES = AllTest.cc\
|
||||
NetrcTest.cc\
|
||||
RequestTest.cc\
|
||||
HttpRequestTest.cc\
|
||||
AuthConfigTest.cc\
|
||||
NetrcTest.cc\
|
||||
SingletonHolderTest.cc\
|
||||
HttpHeaderTest.cc\
|
||||
HttpResponseTest.cc\
|
||||
BitfieldManTest.cc\
|
||||
SharedHandleTest.cc\
|
||||
RequestTest.cc\
|
||||
ChunkedEncodingTest.cc\
|
||||
FileTest.cc\
|
||||
OptionTest.cc\
|
||||
|
@ -389,7 +387,6 @@ distclean-compile:
|
|||
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/AllTest.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/AnnounceListTest.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/AuthConfigTest.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Base64Test.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BitfieldManTest.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BtAllowedFastMessageTest.Po@am__quote@
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#include "Request.h"
|
||||
#include "Netrc.h"
|
||||
#include "DefaultAuthResolver.h"
|
||||
#include "NetrcAuthResolver.h"
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
|
||||
class RequestTest:public CppUnit::TestFixture {
|
||||
|
@ -25,12 +27,10 @@ class RequestTest:public CppUnit::TestFixture {
|
|||
CPPUNIT_TEST(testSafeChar);
|
||||
CPPUNIT_TEST(testInnerLink);
|
||||
CPPUNIT_TEST(testMetalink);
|
||||
CPPUNIT_TEST(testResolveHttpAuthConfigItem);
|
||||
CPPUNIT_TEST(testResolveHttpAuthConfigItem_noCandidate);
|
||||
CPPUNIT_TEST(testResolveHttpProxyAuthConfigItem);
|
||||
CPPUNIT_TEST(testResolveHttpProxyAuthConfigItem_noCandidate);
|
||||
CPPUNIT_TEST(testResolveFtpAuthConfigItem);
|
||||
CPPUNIT_TEST(testResolveFtpAuthConfigItem_noCandidate);
|
||||
CPPUNIT_TEST(testResolveHttpAuthConfig);
|
||||
CPPUNIT_TEST(testResolveHttpAuthConfig_noCandidate);
|
||||
CPPUNIT_TEST(testResolveHttpProxyAuthConfig);
|
||||
CPPUNIT_TEST(testResolveFtpAuthConfig);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
|
@ -54,12 +54,10 @@ public:
|
|||
void testSafeChar();
|
||||
void testInnerLink();
|
||||
void testMetalink();
|
||||
void testResolveHttpAuthConfigItem();
|
||||
void testResolveHttpAuthConfigItem_noCandidate();
|
||||
void testResolveHttpProxyAuthConfigItem();
|
||||
void testResolveHttpProxyAuthConfigItem_noCandidate();
|
||||
void testResolveFtpAuthConfigItem();
|
||||
void testResolveFtpAuthConfigItem_noCandidate();
|
||||
void testResolveHttpAuthConfig();
|
||||
void testResolveHttpAuthConfig_noCandidate();
|
||||
void testResolveHttpProxyAuthConfig();
|
||||
void testResolveFtpAuthConfig();
|
||||
};
|
||||
|
||||
|
||||
|
@ -306,117 +304,77 @@ void RequestTest::testMetalink() {
|
|||
CPPUNIT_ASSERT(!v2);
|
||||
}
|
||||
|
||||
void RequestTest::testResolveHttpAuthConfigItem()
|
||||
void RequestTest::testResolveHttpAuthConfig()
|
||||
{
|
||||
Request req;
|
||||
req.setUrl("http://localhost/download/aria2-1.0.0.tar.bz2");
|
||||
// with no authConfig
|
||||
CPPUNIT_ASSERT(req.resolveHttpAuthConfigItem().isNull());
|
||||
// with DefaultAuthResolver
|
||||
DefaultAuthResolverHandle defaultAuthResolver = new DefaultAuthResolver();
|
||||
req.setHttpAuthResolver(defaultAuthResolver);
|
||||
CPPUNIT_ASSERT(!req.resolveHttpAuthConfig().isNull());
|
||||
CPPUNIT_ASSERT_EQUAL(string(":"),
|
||||
req.resolveHttpAuthConfig()->getAuthText());
|
||||
|
||||
// with Netrc
|
||||
NetrcHandle netrc = new Netrc();
|
||||
netrc->addAuthenticator(new DefaultAuthenticator("default", "defaultpassword", "defaultaccount"));
|
||||
NetrcSingletonHolder::instance(netrc);
|
||||
CPPUNIT_ASSERT(!req.resolveHttpAuthConfigItem().isNull());
|
||||
AuthConfigItemHandle authConfig1 = req.resolveHttpAuthConfigItem();
|
||||
CPPUNIT_ASSERT_EQUAL(string("default"), authConfig1->getUser());
|
||||
CPPUNIT_ASSERT_EQUAL(string("defaultpassword"), authConfig1->getPassword());
|
||||
NetrcAuthResolverHandle netrcAuthResolver = new NetrcAuthResolver();
|
||||
netrcAuthResolver->setNetrc(netrc);
|
||||
req.setHttpAuthResolver(netrcAuthResolver);
|
||||
AuthConfigHandle authConfig1 = req.resolveHttpAuthConfig();
|
||||
CPPUNIT_ASSERT(!authConfig1.isNull());
|
||||
CPPUNIT_ASSERT_EQUAL(string("default:defaultpassword"),
|
||||
authConfig1->getAuthText());
|
||||
|
||||
// with Netrc + user defined
|
||||
AuthConfigHandle authConfig = new AuthConfig();
|
||||
authConfig->setHttpAuthConfigItem("userDefinedUser", "userDefinedPassword");
|
||||
req.setUserDefinedAuthConfig(authConfig);
|
||||
CPPUNIT_ASSERT(!req.resolveHttpAuthConfigItem().isNull());
|
||||
AuthConfigItemHandle authConfig2 = req.resolveHttpAuthConfigItem();
|
||||
CPPUNIT_ASSERT_EQUAL(string("userDefinedUser"), authConfig2->getUser());
|
||||
CPPUNIT_ASSERT_EQUAL(string("userDefinedPassword"), authConfig2->getPassword());
|
||||
AuthConfigHandle authConfig =
|
||||
new AuthConfig("userDefinedUser", "userDefinedPassword");
|
||||
netrcAuthResolver->setUserDefinedAuthConfig(authConfig);
|
||||
AuthConfigHandle authConfig2 = req.resolveHttpAuthConfig();
|
||||
CPPUNIT_ASSERT(!authConfig2.isNull());
|
||||
CPPUNIT_ASSERT_EQUAL(string("userDefinedUser:userDefinedPassword"),
|
||||
authConfig2->getAuthText());
|
||||
}
|
||||
|
||||
void RequestTest::testResolveHttpAuthConfigItem_noCandidate()
|
||||
void RequestTest::testResolveHttpAuthConfig_noCandidate()
|
||||
{
|
||||
Request req;
|
||||
req.setUrl("http://localhost/download/aria2-1.0.0.tar.bz2");
|
||||
|
||||
NetrcHandle netrc = new Netrc();
|
||||
netrc->addAuthenticator(new Authenticator("localhost2", "default", "defaultpassword", "defaultaccount"));
|
||||
NetrcSingletonHolder::instance(netrc);
|
||||
CPPUNIT_ASSERT(req.resolveHttpAuthConfigItem().isNull());
|
||||
DefaultAuthResolverHandle defaultAuthResolver = new DefaultAuthResolver();
|
||||
req.setHttpAuthResolver(defaultAuthResolver);
|
||||
CPPUNIT_ASSERT_EQUAL(string(":"),
|
||||
req.resolveHttpAuthConfig()->getAuthText());
|
||||
}
|
||||
|
||||
void RequestTest::testResolveHttpProxyAuthConfigItem()
|
||||
void RequestTest::testResolveHttpProxyAuthConfig()
|
||||
{
|
||||
Request req;
|
||||
req.setUrl("http://localhost/download/aria2-1.0.0.tar.bz2");
|
||||
// with no authConfig
|
||||
CPPUNIT_ASSERT(req.resolveHttpProxyAuthConfigItem().isNull());
|
||||
|
||||
// with Netrc
|
||||
NetrcHandle netrc = new Netrc();
|
||||
netrc->addAuthenticator(new DefaultAuthenticator("default", "defaultpassword", "defaultaccount"));
|
||||
NetrcSingletonHolder::instance(netrc);
|
||||
CPPUNIT_ASSERT(!req.resolveHttpProxyAuthConfigItem().isNull());
|
||||
AuthConfigItemHandle authConfig1 = req.resolveHttpProxyAuthConfigItem();
|
||||
CPPUNIT_ASSERT_EQUAL(string("default"), authConfig1->getUser());
|
||||
CPPUNIT_ASSERT_EQUAL(string("defaultpassword"), authConfig1->getPassword());
|
||||
|
||||
// with Netrc + user defined
|
||||
AuthConfigHandle authConfig = new AuthConfig();
|
||||
authConfig->setHttpProxyAuthConfigItem("userDefinedUser", "userDefinedPassword");
|
||||
req.setUserDefinedAuthConfig(authConfig);
|
||||
CPPUNIT_ASSERT(!req.resolveHttpProxyAuthConfigItem().isNull());
|
||||
AuthConfigItemHandle authConfig2 = req.resolveHttpProxyAuthConfigItem();
|
||||
CPPUNIT_ASSERT_EQUAL(string("userDefinedUser"), authConfig2->getUser());
|
||||
CPPUNIT_ASSERT_EQUAL(string("userDefinedPassword"), authConfig2->getPassword());
|
||||
NetrcAuthResolverHandle netrcAuthResolver = new NetrcAuthResolver();
|
||||
netrcAuthResolver->setNetrc(netrc);
|
||||
req.setHttpProxyAuthResolver(netrcAuthResolver);
|
||||
AuthConfigHandle authConfig1 = req.resolveHttpProxyAuthConfig();
|
||||
CPPUNIT_ASSERT(!authConfig1.isNull());
|
||||
CPPUNIT_ASSERT_EQUAL(string("default:defaultpassword"),
|
||||
authConfig1->getAuthText());
|
||||
}
|
||||
|
||||
void RequestTest::testResolveHttpProxyAuthConfigItem_noCandidate()
|
||||
void RequestTest::testResolveFtpAuthConfig()
|
||||
{
|
||||
Request req;
|
||||
req.setUrl("http://localhost/download/aria2-1.0.0.tar.bz2");
|
||||
|
||||
NetrcHandle netrc = new Netrc();
|
||||
netrc->addAuthenticator(new Authenticator("localhost2", "default", "defaultpassword", "defaultaccount"));
|
||||
NetrcSingletonHolder::instance(netrc);
|
||||
CPPUNIT_ASSERT(req.resolveHttpProxyAuthConfigItem().isNull());
|
||||
}
|
||||
|
||||
void RequestTest::testResolveFtpAuthConfigItem()
|
||||
{
|
||||
Request req;
|
||||
req.setUrl("http://localhost/download/aria2-1.0.0.tar.bz2");
|
||||
// with no authConfig
|
||||
CPPUNIT_ASSERT(!req.resolveFtpAuthConfigItem().isNull());
|
||||
CPPUNIT_ASSERT_EQUAL(string("anonymous"), req.resolveFtpAuthConfigItem()->getUser());
|
||||
CPPUNIT_ASSERT_EQUAL(string("ARIA2USER@"), req.resolveFtpAuthConfigItem()->getPassword());
|
||||
|
||||
// with Netrc
|
||||
NetrcHandle netrc = new Netrc();
|
||||
netrc->addAuthenticator(new DefaultAuthenticator("default", "defaultpassword", "defaultaccount"));
|
||||
NetrcSingletonHolder::instance(netrc);
|
||||
CPPUNIT_ASSERT(!req.resolveFtpAuthConfigItem().isNull());
|
||||
AuthConfigItemHandle authConfig1 = req.resolveFtpAuthConfigItem();
|
||||
CPPUNIT_ASSERT_EQUAL(string("default"), authConfig1->getUser());
|
||||
CPPUNIT_ASSERT_EQUAL(string("defaultpassword"), authConfig1->getPassword());
|
||||
|
||||
// with Netrc + user defined
|
||||
AuthConfigHandle authConfig = new AuthConfig();
|
||||
authConfig->setFtpAuthConfigItem("userDefinedUser", "userDefinedPassword");
|
||||
req.setUserDefinedAuthConfig(authConfig);
|
||||
CPPUNIT_ASSERT(!req.resolveFtpAuthConfigItem().isNull());
|
||||
AuthConfigItemHandle authConfig2 = req.resolveFtpAuthConfigItem();
|
||||
CPPUNIT_ASSERT_EQUAL(string("userDefinedUser"), authConfig2->getUser());
|
||||
CPPUNIT_ASSERT_EQUAL(string("userDefinedPassword"), authConfig2->getPassword());
|
||||
}
|
||||
|
||||
void RequestTest::testResolveFtpAuthConfigItem_noCandidate()
|
||||
{
|
||||
Request req;
|
||||
req.setUrl("http://localhost/download/aria2-1.0.0.tar.bz2");
|
||||
|
||||
NetrcHandle netrc = new Netrc();
|
||||
netrc->addAuthenticator(new Authenticator("localhost2", "default", "defaultpassword", "defaultaccount"));
|
||||
NetrcSingletonHolder::instance(netrc);
|
||||
CPPUNIT_ASSERT(!req.resolveFtpAuthConfigItem().isNull());
|
||||
CPPUNIT_ASSERT_EQUAL(string("anonymous"), req.resolveFtpAuthConfigItem()->getUser());
|
||||
CPPUNIT_ASSERT_EQUAL(string("ARIA2USER@"), req.resolveFtpAuthConfigItem()->getPassword());
|
||||
NetrcAuthResolverHandle netrcAuthResolver = new NetrcAuthResolver();
|
||||
netrcAuthResolver->setNetrc(netrc);
|
||||
req.setFtpAuthResolver(netrcAuthResolver);
|
||||
AuthConfigHandle authConfig1 = req.resolveFtpAuthConfig();
|
||||
CPPUNIT_ASSERT(!authConfig1.isNull());
|
||||
CPPUNIT_ASSERT_EQUAL(string("default:defaultpassword"),
|
||||
authConfig1->getAuthText());
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include "DefaultPieceStorage.h"
|
||||
#include "DefaultPeerStorage.h"
|
||||
#include "BtRegistry.h"
|
||||
#include "RequestFactory.h"
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
|
||||
using namespace std;
|
||||
|
@ -20,11 +21,18 @@ class TrackerWatcherCommandTest:public CppUnit::TestFixture {
|
|||
CPPUNIT_TEST(testCreateCommand);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
private:
|
||||
|
||||
Option* op;
|
||||
public:
|
||||
void setUp() {
|
||||
TrackerWatcherCommandTest():op(new Option())
|
||||
{
|
||||
op->put(PREF_TRACKER_MAX_TRIES, "10");
|
||||
RequestFactoryHandle requestFactory = new RequestFactory();
|
||||
requestFactory->setOption(op);
|
||||
RequestFactorySingletonHolder::instance(requestFactory);
|
||||
}
|
||||
|
||||
void setUp() {}
|
||||
|
||||
void testCreateCommand();
|
||||
};
|
||||
|
||||
|
@ -33,8 +41,6 @@ CPPUNIT_TEST_SUITE_REGISTRATION( TrackerWatcherCommandTest );
|
|||
|
||||
void TrackerWatcherCommandTest::testCreateCommand() {
|
||||
try {
|
||||
Option* op = new Option();
|
||||
op->put(PREF_TRACKER_MAX_TRIES, "10");
|
||||
|
||||
BtContextHandle btContext(new DefaultBtContext());
|
||||
btContext->load("test.torrent");
|
||||
|
|
Loading…
Reference in New Issue