mirror of https://github.com/aria2/aria2
2010-09-11 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Use uri::parse instead of Request::setUri() where just URI parser is needed. * src/AbstractCommand.cc * src/AdaptiveURISelector.cc * src/DefaultBtAnnounce.cc * src/FeedbackURISelector.cc * src/FileEntry.cc * src/HttpResponseCommand.cc * src/ProtocolDetector.cc * src/Request.cc * src/RequestGroupMan.ccpull/1/head
parent
ec3bd81486
commit
80edde0205
14
ChangeLog
14
ChangeLog
|
@ -1,3 +1,17 @@
|
|||
2010-09-11 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||
|
||||
Use uri::parse instead of Request::setUri() where just URI parser
|
||||
is needed.
|
||||
* src/AbstractCommand.cc
|
||||
* src/AdaptiveURISelector.cc
|
||||
* src/DefaultBtAnnounce.cc
|
||||
* src/FeedbackURISelector.cc
|
||||
* src/FileEntry.cc
|
||||
* src/HttpResponseCommand.cc
|
||||
* src/ProtocolDetector.cc
|
||||
* src/Request.cc
|
||||
* src/RequestGroupMan.cc
|
||||
|
||||
2010-09-11 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||
|
||||
Moved URI parser code to uri.h, uri.cc to provide fast URI parser
|
||||
|
|
|
@ -68,6 +68,7 @@
|
|||
#include "NameResolver.h"
|
||||
#include "ServerStatMan.h"
|
||||
#include "FileAllocationEntry.h"
|
||||
#include "uri.h"
|
||||
#ifdef ENABLE_MESSAGE_DIGEST
|
||||
# include "ChecksumCheckIntegrityEntry.h"
|
||||
#endif // ENABLE_MESSAGE_DIGEST
|
||||
|
@ -556,7 +557,8 @@ static bool isProxyRequest
|
|||
(const std::string& protocol, const SharedHandle<Option>& option)
|
||||
{
|
||||
const std::string& proxyUri = getProxyUri(protocol, option);
|
||||
return !proxyUri.empty() && Request().setUri(proxyUri);
|
||||
uri::UriStruct us;
|
||||
return !proxyUri.empty() && uri::parse(us, proxyUri);
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
|
|
@ -51,6 +51,7 @@
|
|||
#include "SimpleRandomizer.h"
|
||||
#include "SocketCore.h"
|
||||
#include "FileEntry.h"
|
||||
#include "uri.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
|
@ -341,9 +342,12 @@ std::string AdaptiveURISelector::getFirstToTestUri
|
|||
SharedHandle<ServerStat> AdaptiveURISelector::getServerStats
|
||||
(const std::string& uri) const
|
||||
{
|
||||
Request r;
|
||||
r.setUri(uri);
|
||||
return serverStatMan_->find(r.getHost(), r.getProtocol());
|
||||
uri::UriStruct us;
|
||||
if(uri::parse(us, uri)) {
|
||||
return serverStatMan_->find(us.host, us.protocol);
|
||||
} else {
|
||||
return SharedHandle<ServerStat>();
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int AdaptiveURISelector::getNbTestedServers
|
||||
|
|
|
@ -48,10 +48,10 @@
|
|||
#include "Option.h"
|
||||
#include "StringFormat.h"
|
||||
#include "A2STR.h"
|
||||
#include "Request.h"
|
||||
#include "bencode2.h"
|
||||
#include "bittorrent_helper.h"
|
||||
#include "wallclock.h"
|
||||
#include "uri.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
|
@ -105,9 +105,12 @@ bool DefaultBtAnnounce::isAnnounceReady() {
|
|||
|
||||
static bool uriHasQuery(const std::string& uri)
|
||||
{
|
||||
Request req;
|
||||
req.setUri(uri);
|
||||
return !req.getQuery().empty();
|
||||
uri::UriStruct us;
|
||||
if(uri::parse(us, uri)) {
|
||||
return !us.query.empty();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
std::string DefaultBtAnnounce::getAnnounceUrl() {
|
||||
|
|
|
@ -39,12 +39,12 @@
|
|||
|
||||
#include "ServerStatMan.h"
|
||||
#include "ServerStat.h"
|
||||
#include "Request.h"
|
||||
#include "A2STR.h"
|
||||
#include "FileEntry.h"
|
||||
#include "Logger.h"
|
||||
#include "LogFactory.h"
|
||||
#include "a2algo.h"
|
||||
#include "uri.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
|
@ -109,19 +109,19 @@ std::string FeedbackURISelector::selectRarer
|
|||
std::vector<std::pair<std::string, std::string> > cands;
|
||||
for(std::deque<std::string>::const_iterator i = uris.begin(),
|
||||
eoi = uris.end(); i != eoi; ++i) {
|
||||
Request r;
|
||||
if(!r.setUri(*i)) {
|
||||
uri::UriStruct us;
|
||||
if(!uri::parse(us, *i)) {
|
||||
continue;
|
||||
}
|
||||
SharedHandle<ServerStat> ss =
|
||||
serverStatMan_->find(r.getHost(), r.getProtocol());
|
||||
serverStatMan_->find(us.host, us.protocol);
|
||||
if(!ss.isNull() && ss->isError()) {
|
||||
if(logger_->debug()) {
|
||||
logger_->debug("Error not considered: %s", (*i).c_str());
|
||||
}
|
||||
continue;
|
||||
}
|
||||
cands.push_back(std::make_pair(r.getHost(), *i));
|
||||
cands.push_back(std::make_pair(us.host, *i));
|
||||
}
|
||||
for(std::vector<std::pair<size_t, std::string> >::const_iterator i =
|
||||
usedHosts.begin(), eoi = usedHosts.end(); i != eoi; ++i) {
|
||||
|
@ -148,11 +148,11 @@ std::string FeedbackURISelector::selectFaster
|
|||
std::vector<std::string> normCands;
|
||||
for(std::deque<std::string>::const_iterator i = uris.begin(),
|
||||
eoi = uris.end(); i != eoi && fastCands.size() < NUM_URI; ++i) {
|
||||
Request r;
|
||||
if(!r.setUri(*i)) {
|
||||
uri::UriStruct us;
|
||||
if(!uri::parse(us, *i)) {
|
||||
continue;
|
||||
}
|
||||
if(findSecond(usedHosts.begin(), usedHosts.end(), r.getHost()) !=
|
||||
if(findSecond(usedHosts.begin(), usedHosts.end(), us.host) !=
|
||||
usedHosts.end()) {
|
||||
if(logger_->debug()) {
|
||||
logger_->debug("%s is in usedHosts, not considered", (*i).c_str());
|
||||
|
@ -160,7 +160,7 @@ std::string FeedbackURISelector::selectFaster
|
|||
continue;
|
||||
}
|
||||
SharedHandle<ServerStat> ss =
|
||||
serverStatMan_->find(r.getHost(), r.getProtocol());
|
||||
serverStatMan_->find(us.host, us.protocol);
|
||||
if(ss.isNull()) {
|
||||
normCands.push_back(*i);
|
||||
} else if(ss->isOK()) {
|
||||
|
|
|
@ -42,6 +42,7 @@
|
|||
#include "LogFactory.h"
|
||||
#include "wallclock.h"
|
||||
#include "a2algo.h"
|
||||
#include "uri.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
|
@ -108,10 +109,11 @@ static OutputIterator
|
|||
enumerateInFlightHosts
|
||||
(InputIterator first, InputIterator last, OutputIterator out)
|
||||
{
|
||||
Request r;
|
||||
for(; first != last; ++first) {
|
||||
r.setUri((*first)->getUri());
|
||||
*out++ = r.getHost();
|
||||
uri::UriStruct us;
|
||||
if(uri::parse(us, (*first)->getUri())) {
|
||||
*out++ = us.host;
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
@ -259,11 +261,13 @@ bool FileEntry::removeRequest(const SharedHandle<Request>& request)
|
|||
void FileEntry::removeURIWhoseHostnameIs(const std::string& hostname)
|
||||
{
|
||||
std::deque<std::string> newURIs;
|
||||
Request req;
|
||||
for(std::deque<std::string>::const_iterator itr = uris_.begin(),
|
||||
eoi = uris_.end(); itr != eoi; ++itr) {
|
||||
if(((*itr).find(hostname) == std::string::npos) ||
|
||||
(req.setUri(*itr) && (req.getHost() != hostname))) {
|
||||
uri::UriStruct us;
|
||||
if(!uri::parse(us, *itr)) {
|
||||
continue;
|
||||
}
|
||||
if(us.host != hostname) {
|
||||
newURIs.push_back(*itr);
|
||||
}
|
||||
}
|
||||
|
@ -271,7 +275,7 @@ void FileEntry::removeURIWhoseHostnameIs(const std::string& hostname)
|
|||
logger_->debug("Removed %d duplicate hostname URIs for path=%s",
|
||||
uris_.size()-newURIs.size(), getPath().c_str());
|
||||
}
|
||||
uris_ = newURIs;
|
||||
uris_.swap(newURIs);
|
||||
}
|
||||
|
||||
void FileEntry::removeIdenticalURI(const std::string& uri)
|
||||
|
@ -337,11 +341,11 @@ void FileEntry::reuseUri(const std::vector<std::string>& ignore)
|
|||
errorUris.begin(), errorUris.end(),
|
||||
std::back_inserter(reusableURIs));
|
||||
std::vector<std::string>::iterator insertionPoint = reusableURIs.begin();
|
||||
Request req;
|
||||
for(std::vector<std::string>::iterator i = reusableURIs.begin(),
|
||||
eoi = reusableURIs.end(); i != eoi; ++i) {
|
||||
req.setUri(*i);
|
||||
if(std::find(ignore.begin(), ignore.end(), req.getHost()) == ignore.end()) {
|
||||
uri::UriStruct us;
|
||||
if(uri::parse(us, *i) &&
|
||||
std::find(ignore.begin(), ignore.end(), us.host) == ignore.end()) {
|
||||
if(i != insertionPoint) {
|
||||
*insertionPoint = *i;
|
||||
}
|
||||
|
@ -429,7 +433,8 @@ size_t FileEntry::setUris(const std::vector<std::string>& uris)
|
|||
|
||||
bool FileEntry::addUri(const std::string& uri)
|
||||
{
|
||||
if(Request().setUri(uri)) {
|
||||
uri::UriStruct us;
|
||||
if(uri::parse(us, uri)) {
|
||||
uris_.push_back(uri);
|
||||
return true;
|
||||
} else {
|
||||
|
@ -439,7 +444,8 @@ bool FileEntry::addUri(const std::string& uri)
|
|||
|
||||
bool FileEntry::insertUri(const std::string& uri, size_t pos)
|
||||
{
|
||||
if(Request().setUri(uri)) {
|
||||
uri::UriStruct us;
|
||||
if(uri::parse(us, uri)) {
|
||||
pos = std::min(pos, uris_.size());
|
||||
uris_.insert(uris_.begin()+pos, uri);
|
||||
return true;
|
||||
|
|
|
@ -73,6 +73,7 @@
|
|||
#include "SinkStreamFilter.h"
|
||||
#include "ChunkedDecodingStreamFilter.h"
|
||||
#include "GZipDecodingStreamFilter.h"
|
||||
#include "uri.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
|
@ -155,9 +156,10 @@ bool HttpResponseCommand::executeInternal()
|
|||
if(getFileEntry()->isUniqueProtocol()) {
|
||||
// Redirection should be considered here. We need to parse
|
||||
// original URI to get hostname.
|
||||
Request req;
|
||||
req.setUri(getRequest()->getUri());
|
||||
getFileEntry()->removeURIWhoseHostnameIs(req.getHost());
|
||||
uri::UriStruct us;
|
||||
if(uri::parse(us, getRequest()->getUri())) {
|
||||
getFileEntry()->removeURIWhoseHostnameIs(us.host);
|
||||
}
|
||||
}
|
||||
if(getPieceStorage().isNull()) {
|
||||
uint64_t totalLength = httpResponse->getEntityLength();
|
||||
|
|
|
@ -42,6 +42,7 @@
|
|||
#include "File.h"
|
||||
#include "util.h"
|
||||
#include "RecoverableException.h"
|
||||
#include "uri.h"
|
||||
#ifdef ENABLE_BITTORRENT
|
||||
# include "bittorrent_helper.h"
|
||||
#endif // ENABLE_BITTORRENT
|
||||
|
@ -54,7 +55,8 @@ ProtocolDetector::~ProtocolDetector() {}
|
|||
|
||||
bool ProtocolDetector::isStreamProtocol(const std::string& uri) const
|
||||
{
|
||||
return Request().setUri(uri);
|
||||
uri::UriStruct us;
|
||||
return uri::parse(us, uri);
|
||||
}
|
||||
|
||||
bool ProtocolDetector::guessTorrentFile(const std::string& uri) const
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
/* copyright --> */
|
||||
#include "Request.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <utility>
|
||||
|
||||
#include "util.h"
|
||||
|
@ -181,9 +182,10 @@ const SharedHandle<PeerStat>& Request::initPeerStat()
|
|||
{
|
||||
// Use host and protocol in original URI, because URI selector
|
||||
// selects URI based on original URI, not redirected one.
|
||||
Request origReq;
|
||||
origReq.setUri(uri_);
|
||||
peerStat_.reset(new PeerStat(0, origReq.getHost(), origReq.getProtocol()));
|
||||
uri::UriStruct us;
|
||||
bool v = uri::parse(us, uri_);
|
||||
assert(v);
|
||||
peerStat_.reset(new PeerStat(0, us.host, us.protocol));
|
||||
return peerStat_;
|
||||
}
|
||||
|
||||
|
|
|
@ -71,6 +71,7 @@
|
|||
#include "CheckIntegrityEntry.h"
|
||||
#include "Segment.h"
|
||||
#include "DlAbortEx.h"
|
||||
#include "uri.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
|
@ -894,25 +895,25 @@ bool RequestGroupMan::doesOverallUploadSpeedExceed()
|
|||
void RequestGroupMan::getUsedHosts
|
||||
(std::vector<std::pair<size_t, std::string> >& usedHosts)
|
||||
{
|
||||
Request r;
|
||||
for(std::deque<SharedHandle<RequestGroup> >::const_iterator i =
|
||||
requestGroups_.begin(), eoi = requestGroups_.end(); i != eoi; ++i) {
|
||||
const std::deque<SharedHandle<Request> >& inFlightReqs =
|
||||
(*i)->getDownloadContext()->getFirstFileEntry()->getInFlightRequests();
|
||||
for(std::deque<SharedHandle<Request> >::const_iterator j =
|
||||
inFlightReqs.begin(), eoj = inFlightReqs.end(); j != eoj; ++j) {
|
||||
if(r.setUri((*j)->getUri())) {
|
||||
uri::UriStruct us;
|
||||
if(uri::parse(us, (*j)->getUri())) {
|
||||
std::vector<std::pair<size_t, std::string> >::iterator k;
|
||||
std::vector<std::pair<size_t, std::string> >::iterator eok =
|
||||
usedHosts.end();
|
||||
for(k = usedHosts.begin(); k != eok; ++k) {
|
||||
if((*k).second == r.getHost()) {
|
||||
if((*k).second == us.host) {
|
||||
++(*k).first;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(k == eok) {
|
||||
usedHosts.push_back(std::make_pair(1, r.getHost()));
|
||||
usedHosts.push_back(std::make_pair(1, us.host));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue